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