Flutter Engine
The Flutter Engine
Public Types | Static Public Member Functions | List of all members
SkPaintPriv Class Reference

#include <SkPaintPriv.h>

Public Types

enum  ShaderOverrideOpacity { kNone_ShaderOverrideOpacity , kOpaque_ShaderOverrideOpacity , kNotOpaque_ShaderOverrideOpacity }
 

Static Public Member Functions

static bool Overwrites (const SkPaint *paint, ShaderOverrideOpacity)
 
static bool ShouldDither (const SkPaint &, SkColorType)
 
static SkColor ComputeLuminanceColor (const SkPaint &)
 
static void Flatten (const SkPaint &paint, SkWriteBuffer &buffer)
 
static SkPaint Unflatten (SkReadBuffer &buffer)
 
static void RemoveColorFilter (SkPaint *, SkColorSpace *dstCS)
 

Detailed Description

Definition at line 19 of file SkPaintPriv.h.

Member Enumeration Documentation

◆ ShaderOverrideOpacity

Enumerator
kNone_ShaderOverrideOpacity 

there is no overriding shader (bitmap or image)

kOpaque_ShaderOverrideOpacity 

the overriding shader is opaque

kNotOpaque_ShaderOverrideOpacity 

the overriding shader may not be opaque

Definition at line 21 of file SkPaintPriv.h.

21 {
22 kNone_ShaderOverrideOpacity, //!< there is no overriding shader (bitmap or image)
23 kOpaque_ShaderOverrideOpacity, //!< the overriding shader is opaque
24 kNotOpaque_ShaderOverrideOpacity, //!< the overriding shader may not be opaque
25 };
@ kNone_ShaderOverrideOpacity
there is no overriding shader (bitmap or image)
Definition: SkPaintPriv.h:22
@ kOpaque_ShaderOverrideOpacity
the overriding shader is opaque
Definition: SkPaintPriv.h:23
@ kNotOpaque_ShaderOverrideOpacity
the overriding shader may not be opaque
Definition: SkPaintPriv.h:24

Member Function Documentation

◆ ComputeLuminanceColor()

SkColor SkPaintPriv::ComputeLuminanceColor ( const SkPaint paint)
static

Definition at line 153 of file SkPaintPriv.cpp.

153 {
154 SkColor4f c;
155 if (!just_a_color(paint, &c)) {
156 c = { 0.5f, 0.5f, 0.5f, 1.0f};
157 }
158 return c.toSkColor();
159}
static bool just_a_color(const SkPaint &paint, SkColor4f *color)
const Paint & paint
Definition: color_source.cc:38

◆ Flatten()

void SkPaintPriv::Flatten ( const SkPaint paint,
SkWriteBuffer buffer 
)
static

Serializes SkPaint into a buffer. A companion unflatten() call can reconstitute the paint at a later time.

Parameters
bufferSkWriteBuffer receiving the flattened SkPaint data

Definition at line 261 of file SkPaintPriv.cpp.

261 {
262 uint8_t flatFlags = 0;
263
264 if (paint.getPathEffect() ||
265 paint.getShader() ||
266 paint.getMaskFilter() ||
267 paint.getColorFilter() ||
268 paint.getImageFilter() ||
269 !paint.asBlendMode()) {
270 flatFlags |= kHasEffects_FlatFlag;
271 }
272
273 buffer.writeScalar(paint.getStrokeWidth());
274 buffer.writeScalar(paint.getStrokeMiter());
275 buffer.writeColor4f(paint.getColor4f());
276
277 buffer.write32(pack_v68(paint, flatFlags));
278
279 if (flatFlags & kHasEffects_FlatFlag) {
280 buffer.writeFlattenable(paint.getPathEffect());
281 buffer.writeFlattenable(paint.getShader());
282 buffer.writeFlattenable(paint.getMaskFilter());
283 buffer.writeFlattenable(paint.getColorFilter());
284 buffer.writeFlattenable(paint.getImageFilter());
285 buffer.writeFlattenable(paint.getBlender());
286 }
287}
static uint32_t pack_v68(const SkPaint &paint, unsigned flatFlags)
@ kHasEffects_FlatFlag
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126

◆ Overwrites()

bool SkPaintPriv::Overwrites ( const SkPaint paint,
ShaderOverrideOpacity  overrideOpacity 
)
static

Returns true if drawing with this paint (or nullptr) will ovewrite all affected pixels.

Note: returns conservative true, meaning it may return false even though the paint might in fact overwrite its pixels.

Definition at line 83 of file SkPaintPriv.cpp.

83 {
84 if (!paint) {
85 // No paint means we default to SRC_OVER, so we overwrite iff our shader-override
86 // is opaque, or we don't have one.
87 return overrideOpacity != kNotOpaque_ShaderOverrideOpacity;
88 }
89
91
92 if (!changes_alpha(*paint)) {
93 const unsigned paintAlpha = paint->getAlpha();
94 if (0xff == paintAlpha && overrideOpacity != kNotOpaque_ShaderOverrideOpacity &&
95 (!paint->getShader() || paint->getShader()->isOpaque())) {
96 opacityType = kOpaque_SrcColorOpacity;
97 } else if (0 == paintAlpha) {
98 if (overrideOpacity == kNone_ShaderOverrideOpacity && !paint->getShader()) {
100 } else {
102 }
103 }
104 }
105
106 const auto bm = paint->asBlendMode();
107 if (!bm) {
108 return false; // don't know for sure, so we play it safe and return false.
109 }
110 return blend_mode_is_opaque(bm.value(), opacityType);
111}
static bool blend_mode_is_opaque(SkBlendMode mode, SrcColorOpacity opacityType)
Definition: SkPaintPriv.cpp:52
SrcColorOpacity
Definition: SkPaintPriv.cpp:41
@ kTransparentBlack_SrcColorOpacity
Definition: SkPaintPriv.cpp:45
@ kTransparentAlpha_SrcColorOpacity
Definition: SkPaintPriv.cpp:47
@ kUnknown_SrcColorOpacity
Definition: SkPaintPriv.cpp:49
@ kOpaque_SrcColorOpacity
Definition: SkPaintPriv.cpp:43
static bool changes_alpha(const SkPaint &paint)
Definition: SkPaintPriv.cpp:36

◆ RemoveColorFilter()

void SkPaintPriv::RemoveColorFilter ( SkPaint p,
SkColorSpace dstCS 
)
static

Definition at line 161 of file SkPaintPriv.cpp.

161 {
162 if (SkColorFilter* filter = p->getColorFilter()) {
163 if (SkShader* shader = p->getShader()) {
164 // SkColorFilterShader will modulate the shader color by paint alpha
165 // before applying the filter, so we'll reset it to opaque.
166 p->setShader(sk_make_sp<SkColorFilterShader>(sk_ref_sp(shader),
167 p->getAlphaf(),
168 sk_ref_sp(filter)));
169 p->setAlphaf(1.0f);
170 } else {
171 p->setColor(filter->filterColor4f(p->getColor4f(), sk_srgb_singleton(), dstCS), dstCS);
172 }
173 p->setColorFilter(nullptr);
174 }
175}
SkColorSpace * sk_srgb_singleton()
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381

◆ ShouldDither()

bool SkPaintPriv::ShouldDither ( const SkPaint p,
SkColorType  dstCT 
)
static

Definition at line 113 of file SkPaintPriv.cpp.

113 {
114 // The paint dither flag can veto.
115 if (!p.isDither()) {
116 return false;
117 }
118
119 if (dstCT == kUnknown_SkColorType) {
120 return false;
121 }
122
123 // We always dither 565 or 4444 when requested.
124 if (dstCT == kRGB_565_SkColorType || dstCT == kARGB_4444_SkColorType) {
125 return true;
126 }
127
128 // Otherwise, dither is only needed for non-const paints.
129 return p.getImageFilter() || p.getMaskFilter() ||
130 (p.getShader() && !as_SB(p.getShader())->isConstant());
131}
@ kARGB_4444_SkColorType
pixel with 4 bits for alpha, red, green, blue; in 16-bit word
Definition: SkColorType.h:23
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
Definition: SkColorType.h:22
@ kUnknown_SkColorType
uninitialized
Definition: SkColorType.h:20
SkShaderBase * as_SB(SkShader *shader)
Definition: SkShaderBase.h:412
virtual bool isConstant() const
Definition: SkShaderBase.h:197

◆ Unflatten()

SkPaint SkPaintPriv::Unflatten ( SkReadBuffer buffer)
static

Populates SkPaint, typically from a serialized stream, created by calling flatten() at an earlier time.

Definition at line 289 of file SkPaintPriv.cpp.

289 {
291
292 paint.setStrokeWidth(buffer.readScalar());
293 paint.setStrokeMiter(buffer.readScalar());
294 {
296 buffer.readColor4f(&color);
297 paint.setColor(color, sk_srgb_singleton());
298 }
299
300 SkSafeRange safe;
301 unsigned flatFlags = unpack_v68(&paint, buffer.readUInt(), safe);
302
303 if (!(flatFlags & kHasEffects_FlatFlag)) {
304 // This is a simple SkPaint without any effects, so clear all the effect-related fields.
305 paint.setPathEffect(nullptr);
306 paint.setShader(nullptr);
307 paint.setMaskFilter(nullptr);
308 paint.setColorFilter(nullptr);
309 paint.setImageFilter(nullptr);
310 } else if (buffer.isVersionLT(SkPicturePriv::kSkBlenderInSkPaint)) {
311 // This paint predates the introduction of user blend functions (via SkBlender).
312 paint.setPathEffect(buffer.readPathEffect());
313 paint.setShader(buffer.readShader());
314 paint.setMaskFilter(buffer.readMaskFilter());
315 paint.setColorFilter(buffer.readColorFilter());
316 (void)buffer.read32(); // was drawLooper (now deprecated)
317 paint.setImageFilter(buffer.readImageFilter());
318 } else {
319 paint.setPathEffect(buffer.readPathEffect());
320 paint.setShader(buffer.readShader());
321 paint.setMaskFilter(buffer.readMaskFilter());
322 paint.setColorFilter(buffer.readColorFilter());
323 paint.setImageFilter(buffer.readImageFilter());
324 paint.setBlender(buffer.readBlender());
325 }
326
327 if (!buffer.validate(safe.ok())) {
328 paint.reset();
329 }
330 return paint;
331}
static uint32_t unpack_v68(SkPaint *paint, uint32_t packed, SkSafeRange &safe)
bool ok() const
Definition: SkSafeRange.h:23
DlColor color

The documentation for this class was generated from the following files: