OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2007 The Android Open Source Project | 2 * Copyright 2007 The Android Open Source Project |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SkColorShader_DEFINED | 8 #ifndef SkColorShader_DEFINED |
9 #define SkColorShader_DEFINED | 9 #define SkColorShader_DEFINED |
10 | 10 |
11 #include "SkShader.h" | 11 #include "SkShader.h" |
12 #include "SkPM4f.h" | 12 #include "SkPM4f.h" |
13 | 13 |
14 /** \class SkColorShader | 14 /** \class SkColorShader |
15 A Shader that represents a single color. In general, this effect can be | 15 A Shader that represents a single color. In general, this effect can be |
16 accomplished by just using the color field on the paint, but if an | 16 accomplished by just using the color field on the paint, but if an |
17 actual shader object is needed, this provides that feature. | 17 actual shader object is needed, this provides that feature. |
18 */ | 18 */ |
19 class SK_API SkColorShader : public SkShader { | 19 class SK_API SkColorShader : public SkShader { |
20 public: | 20 public: |
21 /** Create a ColorShader that ignores the color in the paint, and uses the | 21 /** Create a ColorShader that ignores the color in the paint, and uses the |
22 specified color. Note: like all shaders, at draw time the paint's alpha | 22 specified color. Note: like all shaders, at draw time the paint's alpha |
23 will be respected, and is applied to the specified color. | 23 will be respected, and is applied to the specified color. |
24 */ | 24 */ |
25 explicit SkColorShader(SkColor c); | 25 explicit SkColorShader(SkColor c); |
26 | 26 |
27 bool isOpaque() const override; | 27 bool isOpaque() const override; |
28 | 28 |
| 29 size_t contextSize(const ContextRec&) const override { |
| 30 return sizeof(ColorShaderContext); |
| 31 } |
| 32 |
29 class ColorShaderContext : public SkShader::Context { | 33 class ColorShaderContext : public SkShader::Context { |
30 public: | 34 public: |
31 ColorShaderContext(const SkColorShader& shader, const ContextRec&); | 35 ColorShaderContext(const SkColorShader& shader, const ContextRec&); |
32 | 36 |
33 uint32_t getFlags() const override; | 37 uint32_t getFlags() const override; |
34 void shadeSpan(int x, int y, SkPMColor span[], int count) override; | 38 void shadeSpan(int x, int y, SkPMColor span[], int count) override; |
35 void shadeSpanAlpha(int x, int y, uint8_t alpha[], int count) override; | 39 void shadeSpanAlpha(int x, int y, uint8_t alpha[], int count) override; |
36 void shadeSpan4f(int x, int y, SkPM4f[], int count) override; | 40 void shadeSpan4f(int x, int y, SkPM4f[], int count) override; |
37 | 41 |
38 private: | 42 private: |
(...skipping 11 matching lines...) Expand all Loading... |
50 const SkMatrix*, SkFilterQual
ity) const override; | 54 const SkMatrix*, SkFilterQual
ity) const override; |
51 #endif | 55 #endif |
52 | 56 |
53 SK_TO_STRING_OVERRIDE() | 57 SK_TO_STRING_OVERRIDE() |
54 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorShader) | 58 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorShader) |
55 | 59 |
56 protected: | 60 protected: |
57 SkColorShader(SkReadBuffer&); | 61 SkColorShader(SkReadBuffer&); |
58 void flatten(SkWriteBuffer&) const override; | 62 void flatten(SkWriteBuffer&) const override; |
59 Context* onCreateContext(const ContextRec&, void* storage) const override; | 63 Context* onCreateContext(const ContextRec&, void* storage) const override; |
60 size_t onContextSize(const ContextRec&) const override { | |
61 return sizeof(ColorShaderContext); | |
62 } | |
63 bool onAsLuminanceColor(SkColor* lum) const override { | 64 bool onAsLuminanceColor(SkColor* lum) const override { |
64 *lum = fColor; | 65 *lum = fColor; |
65 return true; | 66 return true; |
66 } | 67 } |
67 | 68 |
68 private: | 69 private: |
69 SkColor fColor; | 70 SkColor fColor; |
70 | 71 |
71 typedef SkShader INHERITED; | 72 typedef SkShader INHERITED; |
72 }; | 73 }; |
73 | 74 |
74 #endif | 75 #endif |
OLD | NEW |