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