Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Macros | Enumerations | Functions | Variables
SkPaintPriv.cpp File Reference
#include "src/core/SkPaintPriv.h"
#include "include/core/SkBlendMode.h"
#include "include/core/SkBlender.h"
#include "include/core/SkColorFilter.h"
#include "include/core/SkColorType.h"
#include "include/core/SkImageFilter.h"
#include "include/core/SkMaskFilter.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPathEffect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkShader.h"
#include "include/private/base/SkAssert.h"
#include "src/core/SkColorSpacePriv.h"
#include "src/core/SkPicturePriv.h"
#include "src/core/SkReadBuffer.h"
#include "src/core/SkSafeRange.h"
#include "src/core/SkWriteBuffer.h"
#include "src/effects/colorfilters/SkColorFilterBase.h"
#include "src/shaders/SkColorFilterShader.h"
#include "src/shaders/SkShaderBase.h"
#include <cstdint>
#include <optional>

Go to the source code of this file.

Macros

#define ASSERT_FITS_IN(value, bitcount)
 

Enumerations

enum  SrcColorOpacity { kOpaque_SrcColorOpacity = 0 , kTransparentBlack_SrcColorOpacity = 1 , kTransparentAlpha_SrcColorOpacity = 2 , kUnknown_SrcColorOpacity = 3 }
 
enum  FlatFlags { kHasTypeface_FlatFlag = 0x1 , kHasEffects_FlatFlag = 0x2 , kFlatFlagMask = 0x3 }
 

Functions

static bool changes_alpha (const SkPaint &paint)
 
static bool blend_mode_is_opaque (SkBlendMode mode, SrcColorOpacity opacityType)
 
static bool just_a_color (const SkPaint &paint, SkColor4f *color)
 
template<typename T >
uint32_t shift_bits (T value, unsigned shift, unsigned bits)
 
static uint32_t pack_v68 (const SkPaint &paint, unsigned flatFlags)
 
static uint32_t unpack_v68 (SkPaint *paint, uint32_t packed, SkSafeRange &safe)
 

Variables

constexpr uint8_t CUSTOM_BLEND_MODE_SENTINEL = 0xFF
 

Macro Definition Documentation

◆ ASSERT_FITS_IN

#define ASSERT_FITS_IN (   value,
  bitcount 
)

Definition at line 184 of file SkPaintPriv.cpp.

Enumeration Type Documentation

◆ FlatFlags

enum FlatFlags
Enumerator
kHasTypeface_FlatFlag 
kHasEffects_FlatFlag 
kFlatFlagMask 

Definition at line 187 of file SkPaintPriv.cpp.

187 {
190
191 kFlatFlagMask = 0x3,
192};
@ kHasTypeface_FlatFlag
@ kHasEffects_FlatFlag
@ kFlatFlagMask

◆ SrcColorOpacity

Enumerator
kOpaque_SrcColorOpacity 
kTransparentBlack_SrcColorOpacity 
kTransparentAlpha_SrcColorOpacity 
kUnknown_SrcColorOpacity 

Definition at line 40 of file SkPaintPriv.cpp.

40 {
41 // The src color is known to be opaque (alpha == 255)
43 // The src color is known to be fully transparent (color == 0)
45 // The src alpha is known to be fully transparent (alpha == 0)
47 // The src color opacity is unknown
49};
@ kTransparentBlack_SrcColorOpacity
@ kTransparentAlpha_SrcColorOpacity
@ kUnknown_SrcColorOpacity
@ kOpaque_SrcColorOpacity

Function Documentation

◆ blend_mode_is_opaque()

static bool blend_mode_is_opaque ( SkBlendMode  mode,
SrcColorOpacity  opacityType 
)
static

Definition at line 51 of file SkPaintPriv.cpp.

51 {
53 if (!SkBlendMode_AsCoeff(mode, &src, &dst)) {
54 return false;
55 }
56
57 switch (src) {
62 return false;
63 default:
64 break;
65 }
66
67 switch (dst) {
69 return true;
71 return kOpaque_SrcColorOpacity == opacityType;
73 return kTransparentBlack_SrcColorOpacity == opacityType ||
76 return kTransparentBlack_SrcColorOpacity == opacityType;
77 default:
78 return false;
79 }
80}
SK_API bool SkBlendMode_AsCoeff(SkBlendMode mode, SkBlendModeCoeff *src, SkBlendModeCoeff *dst)
SkBlendModeCoeff
Definition SkBlendMode.h:84
dst
Definition cp.py:12

◆ changes_alpha()

static bool changes_alpha ( const SkPaint paint)
static

Definition at line 35 of file SkPaintPriv.cpp.

35 {
36 SkColorFilter* cf = paint.getColorFilter();
37 return cf && !as_CFB(cf)->isAlphaUnchanged();
38}
static SkColorFilterBase * as_CFB(SkColorFilter *filter)
bool isAlphaUnchanged() const
const Paint & paint

◆ just_a_color()

static bool just_a_color ( const SkPaint paint,
SkColor4f color 
)
static

Definition at line 134 of file SkPaintPriv.cpp.

134 {
135 SkColor4f c = paint.getColor4f();
136
137 const auto* shader = as_SB(paint.getShader());
138 if (shader && !shader->asLuminanceColor(&c)) {
139 return false;
140 }
141 if (paint.getColorFilter()) {
142 // TODO: This colorspace is meaningless, replace it with something else
143 SkColorSpace* cs = nullptr;
144 c = paint.getColorFilter()->filterColor4f(c, cs, cs);
145 }
146 if (color) {
147 *color = c;
148 }
149 return true;
150}
SkColor4f color
SkShaderBase * as_SB(SkShader *shader)

◆ pack_v68()

static uint32_t pack_v68 ( const SkPaint paint,
unsigned  flatFlags 
)
static

Definition at line 216 of file SkPaintPriv.cpp.

216 {
217 uint32_t packed = 0;
218 const auto bm = paint.asBlendMode();
219 const unsigned mode = bm ? static_cast<unsigned>(bm.value())
221
222 packed |= shift_bits(((unsigned)paint.isDither() << 1) |
223 (unsigned)paint.isAntiAlias(), 0, 8);
224 packed |= shift_bits(mode, 8, 8);
225 packed |= shift_bits(paint.getStrokeCap(), 16, 2);
226 packed |= shift_bits(paint.getStrokeJoin(), 18, 2);
227 packed |= shift_bits(paint.getStyle(), 20, 2);
228 packed |= shift_bits(0, 22, 2); // was filterquality
229 packed |= shift_bits(flatFlags, 24, 8);
230 return packed;
231}
constexpr uint8_t CUSTOM_BLEND_MODE_SENTINEL
uint32_t shift_bits(T value, unsigned shift, unsigned bits)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition switches.h:228

◆ shift_bits()

template<typename T >
uint32_t shift_bits ( T  value,
unsigned  shift,
unsigned  bits 
)

Definition at line 197 of file SkPaintPriv.cpp.

197 {
198 SkASSERT(shift + bits <= 32);
199 uint32_t v = static_cast<uint32_t>(value);
200 ASSERT_FITS_IN(v, bits);
201 return v << shift;
202}
#define SkASSERT(cond)
Definition SkAssert.h:116
#define ASSERT_FITS_IN(value, bitcount)
uint8_t value

◆ unpack_v68()

static uint32_t unpack_v68 ( SkPaint paint,
uint32_t  packed,
SkSafeRange safe 
)
static

Definition at line 233 of file SkPaintPriv.cpp.

233 {
234 paint->setAntiAlias((packed & 1) != 0);
235 paint->setDither((packed & 2) != 0);
236 packed >>= 8;
237 {
238 unsigned mode = packed & 0xFF;
239 if (mode != CUSTOM_BLEND_MODE_SENTINEL) { // sentinel for custom blender
240 paint->setBlendMode(safe.checkLE(mode, SkBlendMode::kLastMode));
241 }
242 // else we will unflatten the custom blender
243 }
244 packed >>= 8;
245 paint->setStrokeCap(safe.checkLE(packed & 0x3, SkPaint::kLast_Cap));
246 packed >>= 2;
247 paint->setStrokeJoin(safe.checkLE(packed & 0x3, SkPaint::kLast_Join));
248 packed >>= 2;
249 paint->setStyle(safe.checkLE(packed & 0x3, SkPaint::kStrokeAndFill_Style));
250 packed >>= 2;
251 // skip the (now ignored) filterquality bits
252 packed >>= 2;
253
254 return packed;
255}
@ kLastMode
last valid value
@ kLast_Cap
largest Cap value
Definition SkPaint.h:337
@ kStrokeAndFill_Style
sets to stroke and fill geometry
Definition SkPaint.h:195
@ kLast_Join
equivalent to the largest value for Join
Definition SkPaint.h:362
T checkLE(uint64_t value, T max)
Definition SkSafeRange.h:28

Variable Documentation

◆ CUSTOM_BLEND_MODE_SENTINEL

constexpr uint8_t CUSTOM_BLEND_MODE_SENTINEL = 0xFF
constexpr

Definition at line 204 of file SkPaintPriv.cpp.