Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 152 of file SkPaintPriv.cpp.

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

◆ 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 260 of file SkPaintPriv.cpp.

260 {
261 uint8_t flatFlags = 0;
262
263 if (paint.getPathEffect() ||
264 paint.getShader() ||
265 paint.getMaskFilter() ||
266 paint.getColorFilter() ||
267 paint.getImageFilter() ||
268 !paint.asBlendMode()) {
269 flatFlags |= kHasEffects_FlatFlag;
270 }
271
272 buffer.writeScalar(paint.getStrokeWidth());
273 buffer.writeScalar(paint.getStrokeMiter());
274 buffer.writeColor4f(paint.getColor4f());
275
276 buffer.write32(pack_v68(paint, flatFlags));
277
278 if (flatFlags & kHasEffects_FlatFlag) {
279 buffer.writeFlattenable(paint.getPathEffect());
280 buffer.writeFlattenable(paint.getShader());
281 buffer.writeFlattenable(paint.getMaskFilter());
282 buffer.writeFlattenable(paint.getColorFilter());
283 buffer.writeFlattenable(paint.getImageFilter());
284 buffer.writeFlattenable(paint.getBlender());
285 }
286}
static uint32_t pack_v68(const SkPaint &paint, unsigned flatFlags)
@ kHasEffects_FlatFlag
static const uint8_t buffer[]

◆ 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 82 of file SkPaintPriv.cpp.

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

◆ RemoveColorFilter()

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

Definition at line 160 of file SkPaintPriv.cpp.

160 {
161 if (SkColorFilter* filter = p->getColorFilter()) {
162 if (SkShader* shader = p->getShader()) {
163 // SkColorFilterShader will modulate the shader color by paint alpha
164 // before applying the filter, so we'll reset it to opaque.
165 p->setShader(sk_make_sp<SkColorFilterShader>(sk_ref_sp(shader),
166 p->getAlphaf(),
167 sk_ref_sp(filter)));
168 p->setAlphaf(1.0f);
169 } else {
170 p->setColor(filter->filterColor4f(p->getColor4f(), sk_srgb_singleton(), dstCS), dstCS);
171 }
172 p->setColorFilter(nullptr);
173 }
174}
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 112 of file SkPaintPriv.cpp.

112 {
113 // The paint dither flag can veto.
114 if (!p.isDither()) {
115 return false;
116 }
117
118 if (dstCT == kUnknown_SkColorType) {
119 return false;
120 }
121
122 // We always dither 565 or 4444 when requested.
123 if (dstCT == kRGB_565_SkColorType || dstCT == kARGB_4444_SkColorType) {
124 return true;
125 }
126
127 // Otherwise, dither is only needed for non-const paints.
128 return p.getImageFilter() || p.getMaskFilter() ||
129 (p.getShader() && !as_SB(p.getShader())->isConstant());
130}
@ 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)
virtual bool isConstant() const

◆ 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 288 of file SkPaintPriv.cpp.

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

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