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