• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <vector>
14 
15 enum class SkBackend : uint8_t;
16 class SkPaintParamsKey;
17 class SkReadBuffer;
18 class SkShaderCodeDictionary;
19 class SkWriteBuffer;
20 
21 class SkPaintPriv {
22 public:
23     enum ShaderOverrideOpacity {
24         kNone_ShaderOverrideOpacity,        //!< there is no overriding shader (bitmap or image)
25         kOpaque_ShaderOverrideOpacity,      //!< the overriding shader is opaque
26         kNotOpaque_ShaderOverrideOpacity,   //!< the overriding shader may not be opaque
27     };
28 
29     /**
30      *  Returns true if drawing with this paint (or nullptr) will ovewrite all affected pixels.
31      *
32      *  Note: returns conservative true, meaning it may return false even though the paint might
33      *        in fact overwrite its pixels.
34      */
35     static bool Overwrites(const SkPaint* paint, ShaderOverrideOpacity);
36 
37     static bool ShouldDither(const SkPaint&, SkColorType);
38 
39     /*
40      * The luminance color is used to determine which Gamma Canonical color to map to.  This is
41      * really only used by backends which want to cache glyph masks, and need some way to know if
42      * they need to generate new masks based off a given color.
43      */
44     static SkColor ComputeLuminanceColor(const SkPaint&);
45 
46     /** Serializes SkPaint into a buffer. A companion unflatten() call
47     can reconstitute the paint at a later time.
48 
49     @param buffer  SkWriteBuffer receiving the flattened SkPaint data
50     */
51     static void Flatten(const SkPaint& paint, SkWriteBuffer& buffer);
52 
53     /** Populates SkPaint, typically from a serialized stream, created by calling
54         flatten() at an earlier time.
55     */
56     static SkPaint Unflatten(SkReadBuffer& buffer);
57 
58     // If this paint has any color filter, fold it into the shader and/or paint color
59     // so that it draws the same but getColorFilter() returns nullptr.
60     //
61     // Since we may be filtering now, we need to know what color space to filter in,
62     // typically the color space of the device we're drawing into.
63     static void RemoveColorFilter(SkPaint*, SkColorSpace* dstCS);
64 
65     static SkScalar ComputeResScaleForStroking(const SkMatrix&);
66 
67     /**
68         Return the SkPaintParamsKeys that would be needed to draw the provided paint.
69 
70         @param paint      the paint to be decomposed
71         @param dictionary dictionary of code fragments available to be used in the SkPaintParamKeys
72         @param backend    the backend that would be carrying out the drawing
73         @return           the SkPaintParamsKeys that would be needed to draw this paint
74     */
75     static std::vector<std::unique_ptr<SkPaintParamsKey>> ToKeys(const SkPaint& paint,
76                                                                  SkShaderCodeDictionary* dictionary,
77                                                                  SkBackend backend);
78 };
79 
80 #endif
81