1 /* 2 * Copyright 2013 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkPaintPriv_DEFINED 9 #define SkPaintPriv_DEFINED 10 11 #include "include/core/SkPaint.h" 12 13 class SkReadBuffer; 14 class SkWriteBuffer; 15 enum SkColorType : int; 16 17 class SkPaintPriv { 18 public: 19 enum ShaderOverrideOpacity { 20 kNone_ShaderOverrideOpacity, //!< there is no overriding shader (bitmap or image) 21 kOpaque_ShaderOverrideOpacity, //!< the overriding shader is opaque 22 kNotOpaque_ShaderOverrideOpacity, //!< the overriding shader may not be opaque 23 }; 24 25 /** 26 * Returns true if drawing with this paint (or nullptr) will ovewrite all affected pixels. 27 * 28 * Note: returns conservative true, meaning it may return false even though the paint might 29 * in fact overwrite its pixels. 30 */ 31 static bool Overwrites(const SkPaint* paint, ShaderOverrideOpacity); 32 33 static bool ShouldDither(const SkPaint&, SkColorType); 34 35 /* 36 * The luminance color is used to determine which Gamma Canonical color to map to. This is 37 * really only used by backends which want to cache glyph masks, and need some way to know if 38 * they need to generate new masks based off a given color. 39 */ 40 static SkColor ComputeLuminanceColor(const SkPaint&); 41 42 /** Serializes SkPaint into a buffer. A companion unflatten() call 43 can reconstitute the paint at a later time. 44 45 @param buffer SkWriteBuffer receiving the flattened SkPaint data 46 */ 47 static void Flatten(const SkPaint& paint, SkWriteBuffer& buffer); 48 49 /** Populates SkPaint, typically from a serialized stream, created by calling 50 flatten() at an earlier time. 51 */ 52 static SkPaint Unflatten(SkReadBuffer& buffer); 53 54 // If this paint has any color filter, fold it into the shader and/or paint color 55 // so that it draws the same but getColorFilter() returns nullptr. 56 // 57 // Since we may be filtering now, we need to know what color space to filter in, 58 // typically the color space of the device we're drawing into. 59 static void RemoveColorFilter(SkPaint*, SkColorSpace* dstCS); 60 61 }; 62 63 #endif 64