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 "SkPaint.h" 12 13 class SkFont; 14 class SkReadBuffer; 15 class SkWriteBuffer; 16 17 enum SkReadPaintResult { 18 kFailed_ReadPaint, 19 kSuccess_JustPaint, 20 kSuccess_PaintAndFont, 21 }; 22 23 class SkPaintPriv { 24 public: 25 enum ShaderOverrideOpacity { 26 kNone_ShaderOverrideOpacity, //!< there is no overriding shader (bitmap or image) 27 kOpaque_ShaderOverrideOpacity, //!< the overriding shader is opaque 28 kNotOpaque_ShaderOverrideOpacity, //!< the overriding shader may not be opaque 29 }; 30 31 /** 32 * Returns true if drawing with this paint (or nullptr) will ovewrite all affected pixels. 33 * 34 * Note: returns conservative true, meaning it may return false even though the paint might 35 * in fact overwrite its pixels. 36 */ 37 static bool Overwrites(const SkPaint* paint, ShaderOverrideOpacity); 38 39 static bool ShouldDither(const SkPaint&, SkColorType); 40 41 /* 42 * The luminance color is used to determine which Gamma Canonical color to map to. This is 43 * really only used by backends which want to cache glyph masks, and need some way to know if 44 * they need to generate new masks based off a given color. 45 */ 46 static SkColor ComputeLuminanceColor(const SkPaint&); 47 48 /** Serializes SkPaint into a buffer. A companion unflatten() call 49 can reconstitute the paint at a later time. 50 51 @param buffer SkWriteBuffer receiving the flattened SkPaint data 52 */ 53 static void Flatten(const SkPaint& paint, SkWriteBuffer& buffer); 54 55 /** Populates SkPaint, typically from a serialized stream, created by calling 56 flatten() at an earlier time. 57 58 SkReadBuffer class is not public, so unflatten() cannot be meaningfully called 59 by the client. 60 61 Older formats also stored font info in the serialized data. On success, this 62 returns if it deserialized just a paint, or both a font and paint. The font 63 param is optional. 64 65 @param buffer serialized data describing SkPaint content 66 @return false if the buffer contains invalid data 67 */ 68 static SkReadPaintResult Unflatten(SkPaint* paint, SkReadBuffer& buffer, SkFont* font); 69 70 private: 71 static SkReadPaintResult Unflatten_PreV68(SkPaint* paint, SkReadBuffer& buffer, SkFont*); 72 }; 73 74 #endif 75