Flutter Engine
The Flutter Engine
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 "include/private/base/SkDebug.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 185 of file SkPaintPriv.cpp.

Enumeration Type Documentation

◆ FlatFlags

enum FlatFlags
Enumerator
kHasTypeface_FlatFlag 
kHasEffects_FlatFlag 
kFlatFlagMask 

Definition at line 188 of file SkPaintPriv.cpp.

188 {
191
192 kFlatFlagMask = 0x3,
193};
@ kHasTypeface_FlatFlag
@ kHasEffects_FlatFlag
@ kFlatFlagMask

◆ SrcColorOpacity

Enumerator
kOpaque_SrcColorOpacity 
kTransparentBlack_SrcColorOpacity 
kTransparentAlpha_SrcColorOpacity 
kUnknown_SrcColorOpacity 

Definition at line 41 of file SkPaintPriv.cpp.

41 {
42 // The src color is known to be opaque (alpha == 255)
44 // The src color is known to be fully transparent (color == 0)
46 // The src alpha is known to be fully transparent (alpha == 0)
48 // The src color opacity is unknown
50};
@ kTransparentBlack_SrcColorOpacity
Definition: SkPaintPriv.cpp:45
@ kTransparentAlpha_SrcColorOpacity
Definition: SkPaintPriv.cpp:47
@ kUnknown_SrcColorOpacity
Definition: SkPaintPriv.cpp:49
@ kOpaque_SrcColorOpacity
Definition: SkPaintPriv.cpp:43

Function Documentation

◆ blend_mode_is_opaque()

static bool blend_mode_is_opaque ( SkBlendMode  mode,
SrcColorOpacity  opacityType 
)
static

Definition at line 52 of file SkPaintPriv.cpp.

52 {
54 if (!SkBlendMode_AsCoeff(mode, &src, &dst)) {
55 return false;
56 }
57
58 switch (src) {
63 return false;
64 default:
65 break;
66 }
67
68 switch (dst) {
70 return true;
72 return kOpaque_SrcColorOpacity == opacityType;
74 return kTransparentBlack_SrcColorOpacity == opacityType ||
77 return kTransparentBlack_SrcColorOpacity == opacityType;
78 default:
79 return false;
80 }
81}
SK_API bool SkBlendMode_AsCoeff(SkBlendMode mode, SkBlendModeCoeff *src, SkBlendModeCoeff *dst)
Definition: SkBlendMode.cpp:57
SkBlendModeCoeff
Definition: SkBlendMode.h:84
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
dst
Definition: cp.py:12

◆ changes_alpha()

static bool changes_alpha ( const SkPaint paint)
static

Definition at line 36 of file SkPaintPriv.cpp.

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

◆ just_a_color()

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

Definition at line 135 of file SkPaintPriv.cpp.

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

◆ pack_v68()

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

Definition at line 217 of file SkPaintPriv.cpp.

217 {
218 uint32_t packed = 0;
219 const auto bm = paint.asBlendMode();
220 const unsigned mode = bm ? static_cast<unsigned>(bm.value())
222
223 packed |= shift_bits(((unsigned)paint.isDither() << 1) |
224 (unsigned)paint.isAntiAlias(), 0, 8);
225 packed |= shift_bits(mode, 8, 8);
226 packed |= shift_bits(paint.getStrokeCap(), 16, 2);
227 packed |= shift_bits(paint.getStrokeJoin(), 18, 2);
228 packed |= shift_bits(paint.getStyle(), 20, 2);
229 packed |= shift_bits(0, 22, 2); // was filterquality
230 packed |= shift_bits(flatFlags, 24, 8);
231 return packed;
232}
constexpr uint8_t CUSTOM_BLEND_MODE_SENTINEL
uint32_t shift_bits(T value, unsigned shift, unsigned bits)

◆ shift_bits()

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

Definition at line 198 of file SkPaintPriv.cpp.

198 {
199 SkASSERT(shift + bits <= 32);
200 uint32_t v = static_cast<uint32_t>(value);
202 return v << shift;
203}
#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 234 of file SkPaintPriv.cpp.

234 {
235 paint->setAntiAlias((packed & 1) != 0);
236 paint->setDither((packed & 2) != 0);
237 packed >>= 8;
238 {
239 unsigned mode = packed & 0xFF;
240 if (mode != CUSTOM_BLEND_MODE_SENTINEL) { // sentinel for custom blender
241 paint->setBlendMode(safe.checkLE(mode, SkBlendMode::kLastMode));
242 }
243 // else we will unflatten the custom blender
244 }
245 packed >>= 8;
246 paint->setStrokeCap(safe.checkLE(packed & 0x3, SkPaint::kLast_Cap));
247 packed >>= 2;
248 paint->setStrokeJoin(safe.checkLE(packed & 0x3, SkPaint::kLast_Join));
249 packed >>= 2;
250 paint->setStyle(safe.checkLE(packed & 0x3, SkPaint::kStrokeAndFill_Style));
251 packed >>= 2;
252 // skip the (now ignored) filterquality bits
253 packed >>= 2;
254
255 return packed;
256}
@ 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 205 of file SkPaintPriv.cpp.