OLD | NEW |
1 | |
2 /* | 1 /* |
3 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
4 * | 3 * |
5 * 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 |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
8 | 7 |
9 | |
10 #ifndef SkGradientShader_DEFINED | 8 #ifndef SkGradientShader_DEFINED |
11 #define SkGradientShader_DEFINED | 9 #define SkGradientShader_DEFINED |
12 | 10 |
13 #include "SkShader.h" | 11 #include "SkShader.h" |
14 | 12 |
15 class SkUnitMapper; | 13 class SkUnitMapper; |
16 | 14 |
17 /** \class SkGradientShader | 15 /** \class SkGradientShader |
18 | 16 |
19 SkGradientShader hosts factories for creating subclasses of SkShader that | 17 SkGradientShader hosts factories for creating subclasses of SkShader that |
20 render linear and radial gradients. | 18 render linear and radial gradients. |
21 */ | 19 */ |
22 class SK_API SkGradientShader { | 20 class SK_API SkGradientShader { |
23 public: | 21 public: |
| 22 enum Flags { |
| 23 /** By default gradients will interpolate their colors in unpremul space |
| 24 * and then premultiply each of the results. By setting this flag, the |
| 25 * gradients will premultiply their colors first, and then interpolate |
| 26 * between them. |
| 27 */ |
| 28 kInterpolateColorsInPremul_Flag = 1 << 0, |
| 29 }; |
| 30 |
24 /** Returns a shader that generates a linear gradient between the two | 31 /** Returns a shader that generates a linear gradient between the two |
25 specified points. | 32 specified points. |
26 <p /> | 33 <p /> |
27 CreateLinear returns a shader with a reference count of 1. | 34 CreateLinear returns a shader with a reference count of 1. |
28 The caller should decrement the shader's reference count when done with
the shader. | 35 The caller should decrement the shader's reference count when done with
the shader. |
29 It is an error for count to be < 2. | 36 It is an error for count to be < 2. |
30 @param pts The start and end points for the gradient. | 37 @param pts The start and end points for the gradient. |
31 @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 |
32 @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 |
33 each corresponding color in the colors array. If this is
NULL, | 40 each corresponding color in the colors array. If this is
NULL, |
34 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. |
35 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 |
36 intermediate values must be strictly increasing. | 43 intermediate values must be strictly increasing. |
37 @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. |
38 @param mode The tiling mode | 45 @param mode The tiling mode |
39 @param mapper May be NULL. Callback to modify the spread of the colors
. | 46 @param mapper May be NULL. Callback to modify the spread of the colors
. |
40 */ | 47 */ |
41 static SkShader* CreateLinear( const SkPoint pts[2], | 48 static SkShader* CreateLinear(const SkPoint pts[2], |
42 const SkColor colors[], const SkScalar pos[]
, int count, | 49 const SkColor colors[], const SkScalar pos[],
int count, |
43 SkShader::TileMode mode, | 50 SkShader::TileMode mode, |
44 SkUnitMapper* mapper = NULL); | 51 SkUnitMapper* mapper = NULL, |
| 52 uint32_t flags = 0); |
45 | 53 |
46 /** Returns a shader that generates a radial gradient given the center and r
adius. | 54 /** Returns a shader that generates a radial gradient given the center and r
adius. |
47 <p /> | 55 <p /> |
48 CreateRadial returns a shader with a reference count of 1. | 56 CreateRadial returns a shader with a reference count of 1. |
49 The caller should decrement the shader's reference count when done with
the shader. | 57 The caller should decrement the shader's reference count when done with
the shader. |
50 It is an error for colorCount to be < 2, or for radius to be <= 0. | 58 It is an error for colorCount to be < 2, or for radius to be <= 0. |
51 @param center The center of the circle for this gradient | 59 @param center The center of the circle for this gradient |
52 @param radius Must be positive. The radius of the circle for this grad
ient | 60 @param radius Must be positive. The radius of the circle for this grad
ient |
53 @param colors The array[count] of colors, to be distributed between th
e center and edge of the circle | 61 @param colors The array[count] of colors, to be distributed between th
e center and edge of the circle |
54 @param pos May be NULL. The array[count] of SkScalars, or NULL, of
the relative position of | 62 @param pos May be NULL. The array[count] of SkScalars, or NULL, of
the relative position of |
55 each corresponding color in the colors array. If this is
NULL, | 63 each corresponding color in the colors array. If this is
NULL, |
56 the the colors are distributed evenly between the center
and edge of the circle. | 64 the the colors are distributed evenly between the center
and edge of the circle. |
57 If this is not null, the values must begin with 0, end w
ith 1.0, and | 65 If this is not null, the values must begin with 0, end w
ith 1.0, and |
58 intermediate values must be strictly increasing. | 66 intermediate values must be strictly increasing. |
59 @param count Must be >= 2. The number of colors (and pos if not NULL)
entries | 67 @param count Must be >= 2. The number of colors (and pos if not NULL)
entries |
60 @param mode The tiling mode | 68 @param mode The tiling mode |
61 @param mapper May be NULL. Callback to modify the spread of the colors
. | 69 @param mapper May be NULL. Callback to modify the spread of the colors
. |
62 */ | 70 */ |
63 static SkShader* CreateRadial( const SkPoint& center, SkScalar radius, | 71 static SkShader* CreateRadial(const SkPoint& center, SkScalar radius, |
64 const SkColor colors[], const SkScalar pos[]
, int count, | 72 const SkColor colors[], const SkScalar pos[],
int count, |
65 SkShader::TileMode mode, | 73 SkShader::TileMode mode, |
66 SkUnitMapper* mapper = NULL); | 74 SkUnitMapper* mapper = NULL, |
| 75 uint32_t flags = 0); |
67 | 76 |
68 /** Returns a shader that generates a radial gradient given the start positi
on, start radius, end position and end radius. | 77 /** Returns a shader that generates a radial gradient given the start positi
on, start radius, end position and end radius. |
69 <p /> | 78 <p /> |
70 CreateTwoPointRadial returns a shader with a reference count of 1. | 79 CreateTwoPointRadial returns a shader with a reference count of 1. |
71 The caller should decrement the shader's reference count when done with
the shader. | 80 The caller should decrement the shader's reference count when done with
the shader. |
72 It is an error for colorCount to be < 2, for startRadius or endRadius to
be < 0, or for | 81 It is an error for colorCount to be < 2, for startRadius or endRadius to
be < 0, or for |
73 startRadius to be equal to endRadius. | 82 startRadius to be equal to endRadius. |
74 @param start The center of the start circle for this gradient | 83 @param start The center of the start circle for this gradient |
75 @param startRadius Must be positive. The radius of the start circle f
or this gradient. | 84 @param startRadius Must be positive. The radius of the start circle f
or this gradient. |
76 @param end The center of the end circle for this gradient | 85 @param end The center of the end circle for this gradient |
77 @param endRadius Must be positive. The radius of the end circle for th
is gradient. | 86 @param endRadius Must be positive. The radius of the end circle for th
is gradient. |
78 @param colors The array[count] of colors, to be distributed between th
e center and edge of the circle | 87 @param colors The array[count] of colors, to be distributed between th
e center and edge of the circle |
79 @param pos May be NULL. The array[count] of SkScalars, or NULL, of
the relative position of | 88 @param pos May be NULL. The array[count] of SkScalars, or NULL, of
the relative position of |
80 each corresponding color in the colors array. If this is
NULL, | 89 each corresponding color in the colors array. If this is
NULL, |
81 the the colors are distributed evenly between the center
and edge of the circle. | 90 the the colors are distributed evenly between the center
and edge of the circle. |
82 If this is not null, the values must begin with 0, end w
ith 1.0, and | 91 If this is not null, the values must begin with 0, end w
ith 1.0, and |
83 intermediate values must be strictly increasing. | 92 intermediate values must be strictly increasing. |
84 @param count Must be >= 2. The number of colors (and pos if not NULL)
entries | 93 @param count Must be >= 2. The number of colors (and pos if not NULL)
entries |
85 @param mode The tiling mode | 94 @param mode The tiling mode |
86 @param mapper May be NULL. Callback to modify the spread of the colors
. | 95 @param mapper May be NULL. Callback to modify the spread of the colors
. |
87 */ | 96 */ |
88 static SkShader* CreateTwoPointRadial(const SkPoint& start, | 97 static SkShader* CreateTwoPointRadial(const SkPoint& start, |
89 SkScalar startRadius, | 98 SkScalar startRadius, |
90 const SkPoint& end, | 99 const SkPoint& end, |
91 SkScalar endRadius, | 100 SkScalar endRadius, |
92 const SkColor colors[], | 101 const SkColor colors[], |
93 const SkScalar pos[], int count, | 102 const SkScalar pos[], int count, |
94 SkShader::TileMode mode, | 103 SkShader::TileMode mode, |
95 SkUnitMapper* mapper = NULL); | 104 SkUnitMapper* mapper = NULL, |
| 105 uint32_t flags = 0); |
96 | 106 |
97 /** | 107 /** |
98 * Returns a shader that generates a conical gradient given two circles, or | 108 * Returns a shader that generates a conical gradient given two circles, or |
99 * returns NULL if the inputs are invalid. The gradient interprets the | 109 * returns NULL if the inputs are invalid. The gradient interprets the |
100 * two circles according to the following HTML spec. | 110 * two circles according to the following HTML spec. |
101 * http://dev.w3.org/html5/2dcontext/#dom-context-2d-createradialgradient | 111 * http://dev.w3.org/html5/2dcontext/#dom-context-2d-createradialgradient |
102 */ | 112 */ |
103 static SkShader* CreateTwoPointConical(const SkPoint& start, | 113 static SkShader* CreateTwoPointConical(const SkPoint& start, |
104 SkScalar startRadius, | 114 SkScalar startRadius, |
105 const SkPoint& end, | 115 const SkPoint& end, |
106 SkScalar endRadius, | 116 SkScalar endRadius, |
107 const SkColor colors[], | 117 const SkColor colors[], |
108 const SkScalar pos[], int count, | 118 const SkScalar pos[], int count, |
109 SkShader::TileMode mode, | 119 SkShader::TileMode mode, |
110 SkUnitMapper* mapper = NULL); | 120 SkUnitMapper* mapper = NULL, |
| 121 uint32_t flags = 0); |
111 | 122 |
112 /** Returns a shader that generates a sweep gradient given a center. | 123 /** Returns a shader that generates a sweep gradient given a center. |
113 <p /> | 124 <p /> |
114 CreateSweep returns a shader with a reference count of 1. | 125 CreateSweep returns a shader with a reference count of 1. |
115 The caller should decrement the shader's reference count when done with
the shader. | 126 The caller should decrement the shader's reference count when done with
the shader. |
116 It is an error for colorCount to be < 2. | 127 It is an error for colorCount to be < 2. |
117 @param cx The X coordinate of the center of the sweep | 128 @param cx The X coordinate of the center of the sweep |
118 @param cx The Y coordinate of the center of the sweep | 129 @param cx The Y coordinate of the center of the sweep |
119 @param colors The array[count] of colors, to be distributed around the
center. | 130 @param colors The array[count] of colors, to be distributed around the
center. |
120 @param pos May be NULL. The array[count] of SkScalars, or NULL, of
the relative position of | 131 @param pos May be NULL. The array[count] of SkScalars, or NULL, of
the relative position of |
121 each corresponding color in the colors array. If this is
NULL, | 132 each corresponding color in the colors array. If this is
NULL, |
122 the the colors are distributed evenly between the center
and edge of the circle. | 133 the the colors are distributed evenly between the center
and edge of the circle. |
123 If this is not null, the values must begin with 0, end w
ith 1.0, and | 134 If this is not null, the values must begin with 0, end w
ith 1.0, and |
124 intermediate values must be strictly increasing. | 135 intermediate values must be strictly increasing. |
125 @param count Must be >= 2. The number of colors (and pos if not NULL)
entries | 136 @param count Must be >= 2. The number of colors (and pos if not NULL)
entries |
126 @param mapper May be NULL. Callback to modify the spread of the colors
. | 137 @param mapper May be NULL. Callback to modify the spread of the colors
. |
127 */ | 138 */ |
128 static SkShader* CreateSweep(SkScalar cx, SkScalar cy, | 139 static SkShader* CreateSweep(SkScalar cx, SkScalar cy, |
129 const SkColor colors[], const SkScalar pos[], | 140 const SkColor colors[], const SkScalar pos[], |
130 int count, SkUnitMapper* mapper = NULL); | 141 int count, SkUnitMapper* mapper = NULL, |
| 142 uint32_t flags = 0); |
131 | 143 |
132 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() | 144 SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() |
133 }; | 145 }; |
134 | 146 |
135 #endif | 147 #endif |
OLD | NEW |