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