OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 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 SkGradientShader_DEFINED | 8 #ifndef SkGradientShader_DEFINED |
9 #define SkGradientShader_DEFINED | 9 #define SkGradientShader_DEFINED |
10 | 10 |
11 #include "SkShader.h" | 11 #include "SkShader.h" |
12 | 12 |
| 13 class SkUnitMapper; |
| 14 |
13 /** \class SkGradientShader | 15 /** \class SkGradientShader |
14 | 16 |
15 SkGradientShader hosts factories for creating subclasses of SkShader that | 17 SkGradientShader hosts factories for creating subclasses of SkShader that |
16 render linear and radial gradients. | 18 render linear and radial gradients. |
17 */ | 19 */ |
18 class SK_API SkGradientShader { | 20 class SK_API SkGradientShader { |
19 public: | 21 public: |
20 enum Flags { | 22 enum Flags { |
21 /** By default gradients will interpolate their colors in unpremul space | 23 /** By default gradients will interpolate their colors in unpremul space |
22 * and then premultiply each of the results. By setting this flag, the | 24 * and then premultiply each of the results. By setting this flag, the |
(...skipping 11 matching lines...) Expand all Loading... |
34 It is an error for count to be < 2. | 36 It is an error for count to be < 2. |
35 @param pts The start and end points for the gradient. | 37 @param pts The start and end points for the gradient. |
36 @param colors The array[count] of colors, to be distributed between th
e two points | 38 @param colors The array[count] of colors, to be distributed between th
e two points |
37 @param pos May be NULL. array[count] of SkScalars, or NULL, of the
relative position of | 39 @param pos May be NULL. array[count] of SkScalars, or NULL, of the
relative position of |
38 each corresponding color in the colors array. If this is
NULL, | 40 each corresponding color in the colors array. If this is
NULL, |
39 the the colors are distributed evenly between the start
and end point. | 41 the the colors are distributed evenly between the start
and end point. |
40 If this is not null, the values must begin with 0, end w
ith 1.0, and | 42 If this is not null, the values must begin with 0, end w
ith 1.0, and |
41 intermediate values must be strictly increasing. | 43 intermediate values must be strictly increasing. |
42 @param count Must be >=2. The number of colors (and pos if not NULL)
entries. | 44 @param count Must be >=2. The number of colors (and pos if not NULL)
entries. |
43 @param mode The tiling mode | 45 @param mode The tiling mode |
| 46 @param mapper May be NULL. Callback to modify the spread of the colors
. |
44 */ | 47 */ |
45 static SkShader* CreateLinear(const SkPoint pts[2], | 48 static SkShader* CreateLinear(const SkPoint pts[2], |
46 const SkColor colors[], const SkScalar pos[],
int count, | 49 const SkColor colors[], const SkScalar pos[],
int count, |
47 SkShader::TileMode mode, | 50 SkShader::TileMode mode, |
48 uint32_t flags, const SkMatrix* localMatrix); | 51 SkUnitMapper* mapper = NULL, |
49 | 52 uint32_t flags = 0, |
50 static SkShader* CreateLinear(const SkPoint pts[2], | 53 const SkMatrix* localMatrix = NULL); |
51 const SkColor colors[], const SkScalar pos[],
int count, | |
52 SkShader::TileMode mode) { | |
53 return CreateLinear(pts, colors, pos, count, mode, 0, NULL); | |
54 } | |
55 | |
56 #ifdef SK_SUPPORT_LEGACY_DEADUNITMAPPERTYPE | |
57 static SkShader* CreateLinear(const SkPoint pts[2], | |
58 const SkColor colors[], const SkScalar pos[],
int count, | |
59 SkShader::TileMode mode, | |
60 SkDeadUnitMapperType*, // this type is now go
ne | |
61 uint32_t flags, | |
62 const SkMatrix* localMatrix) { | |
63 return CreateLinear(pts, colors, pos, count, mode, flags, localMatrix); | |
64 } | |
65 #endif | |
66 | 54 |
67 /** Returns a shader that generates a radial gradient given the center and r
adius. | 55 /** Returns a shader that generates a radial gradient given the center and r
adius. |
68 <p /> | 56 <p /> |
69 CreateRadial returns a shader with a reference count of 1. | 57 CreateRadial returns a shader with a reference count of 1. |
70 The caller should decrement the shader's reference count when done with
the shader. | 58 The caller should decrement the shader's reference count when done with
the shader. |
71 It is an error for colorCount to be < 2, or for radius to be <= 0. | 59 It is an error for colorCount to be < 2, or for radius to be <= 0. |
72 @param center The center of the circle for this gradient | 60 @param center The center of the circle for this gradient |
73 @param radius Must be positive. The radius of the circle for this grad
ient | 61 @param radius Must be positive. The radius of the circle for this grad
ient |
74 @param colors The array[count] of colors, to be distributed between th
e center and edge of the circle | 62 @param colors The array[count] of colors, to be distributed between th
e center and edge of the circle |
75 @param pos May be NULL. The array[count] of SkScalars, or NULL, of
the relative position of | 63 @param pos May be NULL. The array[count] of SkScalars, or NULL, of
the relative position of |
76 each corresponding color in the colors array. If this is
NULL, | 64 each corresponding color in the colors array. If this is
NULL, |
77 the the colors are distributed evenly between the center
and edge of the circle. | 65 the the colors are distributed evenly between the center
and edge of the circle. |
78 If this is not null, the values must begin with 0, end w
ith 1.0, and | 66 If this is not null, the values must begin with 0, end w
ith 1.0, and |
79 intermediate values must be strictly increasing. | 67 intermediate values must be strictly increasing. |
80 @param count Must be >= 2. The number of colors (and pos if not NULL)
entries | 68 @param count Must be >= 2. The number of colors (and pos if not NULL)
entries |
81 @param mode The tiling mode | 69 @param mode The tiling mode |
| 70 @param mapper May be NULL. Callback to modify the spread of the colors
. |
82 */ | 71 */ |
83 static SkShader* CreateRadial(const SkPoint& center, SkScalar radius, | 72 static SkShader* CreateRadial(const SkPoint& center, SkScalar radius, |
84 const SkColor colors[], const SkScalar pos[],
int count, | 73 const SkColor colors[], const SkScalar pos[],
int count, |
85 SkShader::TileMode mode, | 74 SkShader::TileMode mode, |
86 uint32_t flags, const SkMatrix* localMatrix); | 75 SkUnitMapper* mapper = NULL, |
87 | 76 uint32_t flags = 0, |
88 static SkShader* CreateRadial(const SkPoint& center, SkScalar radius, | 77 const SkMatrix* localMatrix = NULL); |
89 const SkColor colors[], const SkScalar pos[],
int count, | |
90 SkShader::TileMode mode) { | |
91 return CreateRadial(center, radius, colors, pos, count, mode, 0, NULL); | |
92 } | |
93 | |
94 #ifdef SK_SUPPORT_LEGACY_DEADUNITMAPPERTYPE | |
95 static SkShader* CreateRadial(const SkPoint& center, SkScalar radius, | |
96 const SkColor colors[], const SkScalar pos[],
int count, | |
97 SkShader::TileMode mode, | |
98 SkDeadUnitMapperType*, | |
99 uint32_t flags, const SkMatrix* localMatrix) { | |
100 return CreateRadial(center, radius, colors, pos, count, mode, flags, loc
alMatrix); | |
101 } | |
102 #endif | |
103 | 78 |
104 /** Returns a shader that generates a radial gradient given the start positi
on, start radius, end position and end radius. | 79 /** Returns a shader that generates a radial gradient given the start positi
on, start radius, end position and end radius. |
105 <p /> | 80 <p /> |
106 CreateTwoPointRadial returns a shader with a reference count of 1. | 81 CreateTwoPointRadial returns a shader with a reference count of 1. |
107 The caller should decrement the shader's reference count when done with
the shader. | 82 The caller should decrement the shader's reference count when done with
the shader. |
108 It is an error for colorCount to be < 2, for startRadius or endRadius to
be < 0, or for | 83 It is an error for colorCount to be < 2, for startRadius or endRadius to
be < 0, or for |
109 startRadius to be equal to endRadius. | 84 startRadius to be equal to endRadius. |
110 @param start The center of the start circle for this gradient | 85 @param start The center of the start circle for this gradient |
111 @param startRadius Must be positive. The radius of the start circle f
or this gradient. | 86 @param startRadius Must be positive. The radius of the start circle f
or this gradient. |
112 @param end The center of the end circle for this gradient | 87 @param end The center of the end circle for this gradient |
113 @param endRadius Must be positive. The radius of the end circle for th
is gradient. | 88 @param endRadius Must be positive. The radius of the end circle for th
is gradient. |
114 @param colors The array[count] of colors, to be distributed between th
e center and edge of the circle | 89 @param colors The array[count] of colors, to be distributed between th
e center and edge of the circle |
115 @param pos May be NULL. The array[count] of SkScalars, or NULL, of
the relative position of | 90 @param pos May be NULL. The array[count] of SkScalars, or NULL, of
the relative position of |
116 each corresponding color in the colors array. If this is
NULL, | 91 each corresponding color in the colors array. If this is
NULL, |
117 the the colors are distributed evenly between the center
and edge of the circle. | 92 the the colors are distributed evenly between the center
and edge of the circle. |
118 If this is not null, the values must begin with 0, end w
ith 1.0, and | 93 If this is not null, the values must begin with 0, end w
ith 1.0, and |
119 intermediate values must be strictly increasing. | 94 intermediate values must be strictly increasing. |
120 @param count Must be >= 2. The number of colors (and pos if not NULL)
entries | 95 @param count Must be >= 2. The number of colors (and pos if not NULL)
entries |
121 @param mode The tiling mode | 96 @param mode The tiling mode |
| 97 @param mapper May be NULL. Callback to modify the spread of the colors
. |
122 */ | 98 */ |
123 static SkShader* CreateTwoPointRadial(const SkPoint& start, SkScalar startRa
dius, | 99 static SkShader* CreateTwoPointRadial(const SkPoint& start, |
124 const SkPoint& end, SkScalar endRadius
, | 100 SkScalar startRadius, |
125 const SkColor colors[], const SkScalar
pos[], int count, | 101 const SkPoint& end, |
| 102 SkScalar endRadius, |
| 103 const SkColor colors[], |
| 104 const SkScalar pos[], int count, |
126 SkShader::TileMode mode, | 105 SkShader::TileMode mode, |
127 uint32_t flags, const SkMatrix* localM
atrix); | 106 SkUnitMapper* mapper = NULL, |
128 | 107 uint32_t flags = 0, |
129 static SkShader* CreateTwoPointRadial(const SkPoint& start, SkScalar startRa
dius, | 108 const SkMatrix* localMatrix = NULL); |
130 const SkPoint& end, SkScalar endRadius
, | |
131 const SkColor colors[], const SkScalar
pos[], int count, | |
132 SkShader::TileMode mode) { | |
133 return CreateTwoPointRadial(start, startRadius, end, endRadius, colors,
pos, count, mode, | |
134 0, NULL); | |
135 } | |
136 | |
137 #ifdef SK_SUPPORT_LEGACY_DEADUNITMAPPERTYPE | |
138 static SkShader* CreateTwoPointRadial(const SkPoint& start, SkScalar startRa
dius, | |
139 const SkPoint& end, SkScalar endRadius
, | |
140 const SkColor colors[], const SkScalar
pos[], int count, | |
141 SkShader::TileMode mode, | |
142 SkDeadUnitMapperType*, | |
143 uint32_t flags, const SkMatrix* localM
atrix) { | |
144 return CreateTwoPointRadial(start, startRadius, end, endRadius, colors,
pos, count, mode, | |
145 flags, localMatrix); | |
146 } | |
147 #endif | |
148 | 109 |
149 /** | 110 /** |
150 * Returns a shader that generates a conical gradient given two circles, or | 111 * Returns a shader that generates a conical gradient given two circles, or |
151 * returns NULL if the inputs are invalid. The gradient interprets the | 112 * returns NULL if the inputs are invalid. The gradient interprets the |
152 * two circles according to the following HTML spec. | 113 * two circles according to the following HTML spec. |
153 * http://dev.w3.org/html5/2dcontext/#dom-context-2d-createradialgradient | 114 * http://dev.w3.org/html5/2dcontext/#dom-context-2d-createradialgradient |
154 */ | 115 */ |
155 static SkShader* CreateTwoPointConical(const SkPoint& start, SkScalar startR
adius, | 116 static SkShader* CreateTwoPointConical(const SkPoint& start, |
156 const SkPoint& end, SkScalar endRadiu
s, | 117 SkScalar startRadius, |
157 const SkColor colors[], const SkScala
r pos[], int count, | 118 const SkPoint& end, |
| 119 SkScalar endRadius, |
| 120 const SkColor colors[], |
| 121 const SkScalar pos[], int count, |
158 SkShader::TileMode mode, | 122 SkShader::TileMode mode, |
159 uint32_t flags, const SkMatrix* local
Matrix); | 123 SkUnitMapper* mapper = NULL, |
160 | 124 uint32_t flags = 0, |
161 static SkShader* CreateTwoPointConical(const SkPoint& start, SkScalar startR
adius, | 125 const SkMatrix* localMatrix = NULL); |
162 const SkPoint& end, SkScalar endRadiu
s, | |
163 const SkColor colors[], const SkScala
r pos[], int count, | |
164 SkShader::TileMode mode) { | |
165 return CreateTwoPointConical(start, startRadius, end, endRadius, colors,
pos, count, mode, | |
166 0, NULL); | |
167 } | |
168 | |
169 #ifdef SK_SUPPORT_LEGACY_DEADUNITMAPPERTYPE | |
170 static SkShader* CreateTwoPointConical(const SkPoint& start, SkScalar startR
adius, | |
171 const SkPoint& end, SkScalar endRadiu
s, | |
172 const SkColor colors[], const SkScala
r pos[], int count, | |
173 SkShader::TileMode mode, | |
174 SkDeadUnitMapperType*, | |
175 uint32_t flags, const SkMatrix* local
Matrix) { | |
176 return CreateTwoPointConical(start, startRadius, end, endRadius, colors,
pos, count, mode, | |
177 flags, localMatrix); | |
178 } | |
179 #endif | |
180 | 126 |
181 /** Returns a shader that generates a sweep gradient given a center. | 127 /** Returns a shader that generates a sweep gradient given a center. |
182 <p /> | 128 <p /> |
183 CreateSweep returns a shader with a reference count of 1. | 129 CreateSweep returns a shader with a reference count of 1. |
184 The caller should decrement the shader's reference count when done with
the shader. | 130 The caller should decrement the shader's reference count when done with
the shader. |
185 It is an error for colorCount to be < 2. | 131 It is an error for colorCount to be < 2. |
186 @param cx The X coordinate of the center of the sweep | 132 @param cx The X coordinate of the center of the sweep |
187 @param cx The Y coordinate of the center of the sweep | 133 @param cx The Y coordinate of the center of the sweep |
188 @param colors The array[count] of colors, to be distributed around the
center. | 134 @param colors The array[count] of colors, to be distributed around the
center. |
189 @param pos May be NULL. The array[count] of SkScalars, or NULL, of
the relative position of | 135 @param pos May be NULL. The array[count] of SkScalars, or NULL, of
the relative position of |
190 each corresponding color in the colors array. If this is
NULL, | 136 each corresponding color in the colors array. If this is
NULL, |
191 the the colors are distributed evenly between the center
and edge of the circle. | 137 the the colors are distributed evenly between the center
and edge of the circle. |
192 If this is not null, the values must begin with 0, end w
ith 1.0, and | 138 If this is not null, the values must begin with 0, end w
ith 1.0, and |
193 intermediate values must be strictly increasing. | 139 intermediate values must be strictly increasing. |
194 @param count Must be >= 2. The number of colors (and pos if not NULL)
entries | 140 @param count Must be >= 2. The number of colors (and pos if not NULL)
entries |
| 141 @param mapper May be NULL. Callback to modify the spread of the colors
. |
195 */ | 142 */ |
196 static SkShader* CreateSweep(SkScalar cx, SkScalar cy, | 143 static SkShader* CreateSweep(SkScalar cx, SkScalar cy, |
197 const SkColor colors[], const SkScalar pos[], i
nt count, | 144 const SkColor colors[], const SkScalar pos[], |
198 uint32_t flags, const SkMatrix* localMatrix); | 145 int count, SkUnitMapper* mapper = NULL, |
199 | 146 uint32_t flags = 0, |
200 static SkShader* CreateSweep(SkScalar cx, SkScalar cy, | 147 const SkMatrix* localMatrix = NULL); |
201 const SkColor colors[], const SkScalar pos[], i
nt count) { | |
202 return CreateSweep(cx, cy, colors, pos, count, 0, NULL); | |
203 } | |
204 | |
205 #ifdef SK_SUPPORT_LEGACY_DEADUNITMAPPERTYPE | |
206 static SkShader* CreateSweep(SkScalar cx, SkScalar cy, | |
207 const SkColor colors[], const SkScalar pos[], i
nt count, | |
208 SkDeadUnitMapperType*, | |
209 uint32_t flags, const SkMatrix* localMatrix) { | |
210 return CreateSweep(cx, cy, colors, pos, count, flags, localMatrix); | |
211 } | |
212 #endif | |
213 | 148 |
214 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() | 149 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() |
215 }; | 150 }; |
216 | 151 |
217 #endif | 152 #endif |
OLD | NEW |