Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(500)

Side by Side Diff: gm/gradients_2pt_conical.cpp

Issue 296823008: Revert of Remove unused (by clients) SkUnitMapper (https://codereview.chromium.org/283273002/) (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gm/gradients.cpp ('k') | gm/gradients_no_texture.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1
1 /* 2 /*
2 * Copyright 2014 Google Inc. 3 * Copyright 2014 Google Inc.
3 * 4 *
4 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 6 * found in the LICENSE file.
6 */ 7 */
7
8 #include "gm.h" 8 #include "gm.h"
9 #include "SkGradientShader.h" 9 #include "SkGradientShader.h"
10 10
11 namespace skiagm { 11 namespace skiagm {
12 12
13 struct GradData { 13 struct GradData {
14 int fCount; 14 int fCount;
15 const SkColor* fColors; 15 const SkColor* fColors;
16 const SkScalar* fPos; 16 const SkScalar* fPos;
17 }; 17 };
(...skipping 13 matching lines...) Expand all
31 }; 31 };
32 32
33 static const GradData gGradData[] = { 33 static const GradData gGradData[] = {
34 { 2, gColors, gPos0 }, 34 { 2, gColors, gPos0 },
35 { 2, gColors, gPos1 }, 35 { 2, gColors, gPos1 },
36 { 5, gColors, gPos2 }, 36 { 5, gColors, gPos2 },
37 { 4, gColorClamp, gPosClamp } 37 { 4, gColorClamp, gPosClamp }
38 }; 38 };
39 39
40 static SkShader* Make2ConicalOutside(const SkPoint pts[2], const GradData& data, 40 static SkShader* Make2ConicalOutside(const SkPoint pts[2], const GradData& data,
41 SkShader::TileMode tm, const SkMatrix& loca lMatrix) { 41 SkShader::TileMode tm, SkUnitMapper* mapper,
42 const SkMatrix& localMatrix) {
42 SkPoint center0, center1; 43 SkPoint center0, center1;
43 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10); 44 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10);
44 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); 45 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
45 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); 46 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
46 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); 47 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
47 return SkGradientShader::CreateTwoPointConical(center0, radius0, 48 return SkGradientShader::CreateTwoPointConical(center0, radius0,
48 center1, radius1, 49 center1, radius1,
49 data.fColors, data.fPos, 50 data.fColors, data.fPos,
50 data.fCount, tm, 0, &localMat rix); 51 data.fCount, tm, mapper,
52 0, &localMatrix);
51 } 53 }
52 54
53 static SkShader* Make2ConicalOutsideFlip(const SkPoint pts[2], const GradData& d ata, 55 static SkShader* Make2ConicalOutsideFlip(const SkPoint pts[2], const GradData& d ata,
54 SkShader::TileMode tm, const SkMatrix& localMatrix) { 56 SkShader::TileMode tm, SkUnitMapper* mapper,
57 const SkMatrix& localMatrix) {
55 SkPoint center0, center1; 58 SkPoint center0, center1;
56 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10); 59 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10);
57 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); 60 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
58 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); 61 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
59 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); 62 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
60 return SkGradientShader::CreateTwoPointConical(center1, radius1, 63 return SkGradientShader::CreateTwoPointConical(center1, radius1,
61 center0, radius0, 64 center0, radius0,
62 data.fColors, data.fPos, 65 data.fColors, data.fPos,
63 data.fCount, tm, 0, &localMat rix); 66 data.fCount, tm, mapper,
67 0, &localMatrix);
64 } 68 }
65 69
66 static SkShader* Make2ConicalInside(const SkPoint pts[2], const GradData& data, 70 static SkShader* Make2ConicalInside(const SkPoint pts[2], const GradData& data,
67 SkShader::TileMode tm, const SkMatrix& localMatrix) { 71 SkShader::TileMode tm, SkUnitMapper* mapper,
72 const SkMatrix& localMatrix) {
68 SkPoint center0, center1; 73 SkPoint center0, center1;
69 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), 74 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
70 SkScalarAve(pts[0].fY, pts[1].fY)); 75 SkScalarAve(pts[0].fY, pts[1].fY));
71 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), 76 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
72 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); 77 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
73 return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0]. fX) / 7, 78 return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0]. fX) / 7,
74 center0, (pts[1].fX - pts[0]. fX) / 2, 79 center0, (pts[1].fX - pts[0]. fX) / 2,
75 data.fColors, data.fPos, data .fCount, tm, 80 data.fColors, data.fPos, data .fCount, tm, mapper,
76 0, &localMatrix); 81 0, &localMatrix);
77 } 82 }
78 83
79 static SkShader* Make2ConicalInsideFlip(const SkPoint pts[2], const GradData& da ta, 84 static SkShader* Make2ConicalInsideFlip(const SkPoint pts[2], const GradData& da ta,
80 SkShader::TileMode tm, const SkMatrix& localMatrix) { 85 SkShader::TileMode tm, SkUnitMapper* mapper,
86 const SkMatrix& localMatrix) {
81 SkPoint center0, center1; 87 SkPoint center0, center1;
82 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), 88 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
83 SkScalarAve(pts[0].fY, pts[1].fY)); 89 SkScalarAve(pts[0].fY, pts[1].fY));
84 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), 90 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
85 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); 91 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
86 return SkGradientShader::CreateTwoPointConical(center0, (pts[1].fX - pts[0]. fX) / 2, 92 return SkGradientShader::CreateTwoPointConical(center0, (pts[1].fX - pts[0]. fX) / 2,
87 center1, (pts[1].fX - pts[0]. fX) / 7, 93 center1, (pts[1].fX - pts[0]. fX) / 7,
88 data.fColors, data.fPos, data .fCount, tm, 94 data.fColors, data.fPos, data .fCount, tm, mapper,
89 0, &localMatrix); 95 0, &localMatrix);
90 } 96 }
91 97
92 static SkShader* Make2ConicalInsideCenter(const SkPoint pts[2], const GradData& data, 98 static SkShader* Make2ConicalInsideCenter(const SkPoint pts[2], const GradData& data,
93 SkShader::TileMode tm, const SkMatrix& localMatrix) { 99 SkShader::TileMode tm, SkUnitMapper* mapper,
100 const SkMatrix& localMatrix) {
94 SkPoint center0, center1; 101 SkPoint center0, center1;
95 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), 102 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
96 SkScalarAve(pts[0].fY, pts[1].fY)); 103 SkScalarAve(pts[0].fY, pts[1].fY));
97 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), 104 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
98 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); 105 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
99 return SkGradientShader::CreateTwoPointConical(center0, (pts[1].fX - pts[0]. fX) / 7, 106 return SkGradientShader::CreateTwoPointConical(center0, (pts[1].fX - pts[0]. fX) / 7,
100 center0, (pts[1].fX - pts[0]. fX) / 2, 107 center0, (pts[1].fX - pts[0]. fX) / 2,
101 data.fColors, data.fPos, data .fCount, tm, 108 data.fColors, data.fPos, data .fCount, tm, mapper,
102 0, &localMatrix); 109 0, &localMatrix);
103 } 110 }
104 111
105 static SkShader* Make2ConicalZeroRad(const SkPoint pts[2], const GradData& data, 112 static SkShader* Make2ConicalZeroRad(const SkPoint pts[2], const GradData& data,
106 SkShader::TileMode tm, const SkMatrix& localMatrix) { 113 SkShader::TileMode tm, SkUnitMapper* mapper,
114 const SkMatrix& localMatrix) {
107 SkPoint center0, center1; 115 SkPoint center0, center1;
108 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), 116 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
109 SkScalarAve(pts[0].fY, pts[1].fY)); 117 SkScalarAve(pts[0].fY, pts[1].fY));
110 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), 118 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
111 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); 119 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
112 return SkGradientShader::CreateTwoPointConical(center1, 0.f, 120 return SkGradientShader::CreateTwoPointConical(center1, 0.f,
113 center0, (pts[1].fX - pts[0]. fX) / 2, 121 center0, (pts[1].fX - pts[0]. fX) / 2,
114 data.fColors, data.fPos, data .fCount, tm, 122 data.fColors, data.fPos, data .fCount, tm, mapper,
115 0, &localMatrix); 123 0, &localMatrix);
116 } 124 }
117 125
118 static SkShader* Make2ConicalZeroRadFlip(const SkPoint pts[2], const GradData& d ata, 126 static SkShader* Make2ConicalZeroRadFlip(const SkPoint pts[2], const GradData& d ata,
119 SkShader::TileMode tm, const SkMatrix& localMatrix) { 127 SkShader::TileMode tm, SkUnitMapper* mapper,
128 const SkMatrix& localMatrix) {
120 SkPoint center0, center1; 129 SkPoint center0, center1;
121 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), 130 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
122 SkScalarAve(pts[0].fY, pts[1].fY)); 131 SkScalarAve(pts[0].fY, pts[1].fY));
123 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), 132 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
124 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); 133 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
125 return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0]. fX) / 2, 134 return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0]. fX) / 2,
126 center0, 0.f, 135 center0, 0.f,
127 data.fColors, data.fPos, data .fCount, tm, 136 data.fColors, data.fPos, data .fCount, tm, mapper,
128 0, &localMatrix); 137 0, &localMatrix);
129 } 138 }
130 139
131 static SkShader* Make2ConicalZeroRadCenter(const SkPoint pts[2], const GradData& data, 140 static SkShader* Make2ConicalZeroRadCenter(const SkPoint pts[2], const GradData& data,
132 SkShader::TileMode tm, const SkMatrix& localMatrix) { 141 SkShader::TileMode tm, SkUnitMapper* mapper,
142 const SkMatrix& localMatrix) {
133 SkPoint center0, center1; 143 SkPoint center0, center1;
134 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), 144 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
135 SkScalarAve(pts[0].fY, pts[1].fY)); 145 SkScalarAve(pts[0].fY, pts[1].fY));
136 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), 146 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
137 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); 147 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
138 return SkGradientShader::CreateTwoPointConical(center0, 0.f, 148 return SkGradientShader::CreateTwoPointConical(center0, 0.f,
139 center0, (pts[1].fX - pts[0]. fX) / 2, 149 center0, (pts[1].fX - pts[0]. fX) / 2,
140 data.fColors, data.fPos, data .fCount, tm, 150 data.fColors, data.fPos, data .fCount, tm, mapper,
141 0, &localMatrix); 151 0, &localMatrix);
142 } 152 }
143 153
144 static SkShader* Make2ConicalZeroRadOutside(const SkPoint pts[2], const GradData & data, 154 static SkShader* Make2ConicalZeroRadOutside(const SkPoint pts[2], const GradData & data,
145 SkShader::TileMode tm, const SkMatrix& localMatrix) { 155 SkShader::TileMode tm, SkUnitMapper* mapper,
156 const SkMatrix& localMatrix) {
146 SkPoint center0, center1; 157 SkPoint center0, center1;
147 SkScalar radius0 = 0.f; 158 SkScalar radius0 = 0.f;
148 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); 159 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
149 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); 160 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
150 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); 161 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
151 return SkGradientShader::CreateTwoPointConical(center0, radius0, 162 return SkGradientShader::CreateTwoPointConical(center0, radius0,
152 center1, radius1, 163 center1, radius1,
153 data.fColors, data.fPos, 164 data.fColors, data.fPos,
154 data.fCount, tm, 0, &localMat rix); 165 data.fCount, tm, mapper,
166 0, &localMatrix);
155 } 167 }
156 168
157 static SkShader* Make2ConicalZeroRadFlipOutside(const SkPoint pts[2], const Grad Data& data, 169 static SkShader* Make2ConicalZeroRadFlipOutside(const SkPoint pts[2], const Grad Data& data,
158 SkShader::TileMode tm, const SkMatrix& localMatrix) { 170 SkShader::TileMode tm, SkUnitMapper* mapper,
171 const SkMatrix& localMatrix) {
159 SkPoint center0, center1; 172 SkPoint center0, center1;
160 SkScalar radius0 = 0.f; 173 SkScalar radius0 = 0.f;
161 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); 174 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
162 center0.set(pts[0].fX + radius0, pts[0].fY + radius0); 175 center0.set(pts[0].fX + radius0, pts[0].fY + radius0);
163 center1.set(pts[1].fX - radius1, pts[1].fY - radius1); 176 center1.set(pts[1].fX - radius1, pts[1].fY - radius1);
164 return SkGradientShader::CreateTwoPointConical(center1, radius1, 177 return SkGradientShader::CreateTwoPointConical(center1, radius1,
165 center0, radius0, 178 center0, radius0,
166 data.fColors, data.fPos, 179 data.fColors, data.fPos,
167 data.fCount, tm, 0, &localMat rix); 180 data.fCount, tm, mapper,
181 0, &localMatrix);
168 } 182 }
169 183
170 static SkShader* Make2ConicalEdgeX(const SkPoint pts[2], const GradData& data, 184 static SkShader* Make2ConicalEdgeX(const SkPoint pts[2], const GradData& data,
171 SkShader::TileMode tm, const SkMatrix& localMatrix) { 185 SkShader::TileMode tm, SkUnitMapper* mapper,
186 const SkMatrix& localMatrix) {
172 SkPoint center0, center1; 187 SkPoint center0, center1;
173 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7); 188 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7);
174 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); 189 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
175 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), 190 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
176 SkScalarAve(pts[0].fY, pts[1].fY)); 191 SkScalarAve(pts[0].fY, pts[1].fY));
177 center0.set(center1.fX + radius1, center1.fY); 192 center0.set(center1.fX + radius1, center1.fY);
178 return SkGradientShader::CreateTwoPointConical(center0, radius0, 193 return SkGradientShader::CreateTwoPointConical(center0, radius0,
179 center1, radius1, 194 center1, radius1,
180 data.fColors, data.fPos, 195 data.fColors, data.fPos,
181 data.fCount, tm, 0, &localMat rix); 196 data.fCount, tm, mapper,
197 0, &localMatrix);
182 } 198 }
183 199
184 static SkShader* Make2ConicalEdgeY(const SkPoint pts[2], const GradData& data, 200 static SkShader* Make2ConicalEdgeY(const SkPoint pts[2], const GradData& data,
185 SkShader::TileMode tm, const SkMatrix& localMatrix) { 201 SkShader::TileMode tm, SkUnitMapper* mapper,
202 const SkMatrix& localMatrix) {
186 SkPoint center0, center1; 203 SkPoint center0, center1;
187 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7); 204 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7);
188 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); 205 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
189 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), 206 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
190 SkScalarAve(pts[0].fY, pts[1].fY)); 207 SkScalarAve(pts[0].fY, pts[1].fY));
191 center0.set(center1.fX, center1.fY + radius1); 208 center0.set(center1.fX, center1.fY + radius1);
192 return SkGradientShader::CreateTwoPointConical(center0, radius0, 209 return SkGradientShader::CreateTwoPointConical(center0, radius0,
193 center1, radius1, 210 center1, radius1,
194 data.fColors, data.fPos, 211 data.fColors, data.fPos,
195 data.fCount, tm, 0, &localMat rix); 212 data.fCount, tm, mapper,
213 0, &localMatrix);
196 } 214 }
197 static SkShader* Make2ConicalZeroRadEdgeX(const SkPoint pts[2], const GradData& data, 215 static SkShader* Make2ConicalZeroRadEdgeX(const SkPoint pts[2], const GradData& data,
198 SkShader::TileMode tm, const SkMatrix& localMatrix) { 216 SkShader::TileMode tm, SkUnitMapper* mapper,
217 const SkMatrix& localMatrix) {
199 SkPoint center0, center1; 218 SkPoint center0, center1;
200 SkScalar radius0 = 0.f; 219 SkScalar radius0 = 0.f;
201 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); 220 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
202 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), 221 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
203 SkScalarAve(pts[0].fY, pts[1].fY)); 222 SkScalarAve(pts[0].fY, pts[1].fY));
204 center0.set(center1.fX + radius1, center1.fY); 223 center0.set(center1.fX + radius1, center1.fY);
205 return SkGradientShader::CreateTwoPointConical(center0, radius0, 224 return SkGradientShader::CreateTwoPointConical(center0, radius0,
206 center1, radius1, 225 center1, radius1,
207 data.fColors, data.fPos, 226 data.fColors, data.fPos,
208 data.fCount, tm, 0, &localMat rix); 227 data.fCount, tm, mapper,
228 0, &localMatrix);
209 } 229 }
210 230
211 static SkShader* Make2ConicalZeroRadEdgeY(const SkPoint pts[2], const GradData& data, 231 static SkShader* Make2ConicalZeroRadEdgeY(const SkPoint pts[2], const GradData& data,
212 SkShader::TileMode tm, const SkMatrix& localMatrix) { 232 SkShader::TileMode tm, SkUnitMapper* mapper,
233 const SkMatrix& localMatrix) {
213 SkPoint center0, center1; 234 SkPoint center0, center1;
214 SkScalar radius0 = 0.f; 235 SkScalar radius0 = 0.f;
215 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); 236 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
216 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), 237 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
217 SkScalarAve(pts[0].fY, pts[1].fY)); 238 SkScalarAve(pts[0].fY, pts[1].fY));
218 center0.set(center1.fX, center1.fY + radius1); 239 center0.set(center1.fX, center1.fY + radius1);
219 return SkGradientShader::CreateTwoPointConical(center0, radius0, 240 return SkGradientShader::CreateTwoPointConical(center0, radius0,
220 center1, radius1, 241 center1, radius1,
221 data.fColors, data.fPos, 242 data.fColors, data.fPos,
222 data.fCount, tm, 0, &localMat rix); 243 data.fCount, tm, mapper,
244 0, &localMatrix);
223 } 245 }
224 246
225 static SkShader* Make2ConicalTouchX(const SkPoint pts[2], const GradData& data, 247 static SkShader* Make2ConicalTouchX(const SkPoint pts[2], const GradData& data,
226 SkShader::TileMode tm, const SkMatrix& localMatrix) { 248 SkShader::TileMode tm, SkUnitMapper* mapper,
249 const SkMatrix& localMatrix) {
227 SkPoint center0, center1; 250 SkPoint center0, center1;
228 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7); 251 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7);
229 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); 252 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
230 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), 253 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
231 SkScalarAve(pts[0].fY, pts[1].fY)); 254 SkScalarAve(pts[0].fY, pts[1].fY));
232 center0.set(center1.fX - radius1 + radius0, center1.fY); 255 center0.set(center1.fX - radius1 + radius0, center1.fY);
233 return SkGradientShader::CreateTwoPointConical(center0, radius0, 256 return SkGradientShader::CreateTwoPointConical(center0, radius0,
234 center1, radius1, 257 center1, radius1,
235 data.fColors, data.fPos, 258 data.fColors, data.fPos,
236 data.fCount, tm, 0, &localMat rix); 259 data.fCount, tm, mapper,
260 0, &localMatrix);
237 } 261 }
238 262
239 static SkShader* Make2ConicalTouchY(const SkPoint pts[2], const GradData& data, 263 static SkShader* Make2ConicalTouchY(const SkPoint pts[2], const GradData& data,
240 SkShader::TileMode tm, const SkMatrix& localMatrix) { 264 SkShader::TileMode tm, SkUnitMapper* mapper,
265 const SkMatrix& localMatrix) {
241 SkPoint center0, center1; 266 SkPoint center0, center1;
242 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7); 267 SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7);
243 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3); 268 SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
244 center1.set(SkScalarAve(pts[0].fX, pts[1].fX), 269 center1.set(SkScalarAve(pts[0].fX, pts[1].fX),
245 SkScalarAve(pts[0].fY, pts[1].fY)); 270 SkScalarAve(pts[0].fY, pts[1].fY));
246 center0.set(center1.fX, center1.fY + radius1 - radius0); 271 center0.set(center1.fX, center1.fY + radius1 - radius0);
247 return SkGradientShader::CreateTwoPointConical(center0, radius0, 272 return SkGradientShader::CreateTwoPointConical(center0, radius0,
248 center1, radius1, 273 center1, radius1,
249 data.fColors, data.fPos, 274 data.fColors, data.fPos,
250 data.fCount, tm, 0, &localMat rix); 275 data.fCount, tm, mapper,
276 0, &localMatrix);
251 } 277 }
252 278
253 static SkShader* Make2ConicalInsideSmallRad(const SkPoint pts[2], const GradData & data, 279 static SkShader* Make2ConicalInsideSmallRad(const SkPoint pts[2], const GradData & data,
254 SkShader::TileMode tm, const SkMatrix& localMatrix) { 280 SkShader::TileMode tm, SkUnitMapper* mapper,
281 const SkMatrix& localMatrix) {
255 SkPoint center0, center1; 282 SkPoint center0, center1;
256 center0.set(SkScalarAve(pts[0].fX, pts[1].fX), 283 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
257 SkScalarAve(pts[0].fY, pts[1].fY)); 284 SkScalarAve(pts[0].fY, pts[1].fY));
258 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), 285 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
259 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); 286 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
260 return SkGradientShader::CreateTwoPointConical(center0, 0.000000000000000000 1f, 287 return SkGradientShader::CreateTwoPointConical(center0, 0.000000000000000000 1f,
261 center0, (pts[1].fX - pts[0]. fX) / 2, 288 center0, (pts[1].fX - pts[0]. fX) / 2,
262 data.fColors, data.fPos, data .fCount, tm, 289 data.fColors, data.fPos, data .fCount, tm, mapper,
263 0, &localMatrix); 290 0, &localMatrix);
264 } 291 }
265 292
266 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, 293 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data,
267 SkShader::TileMode tm, const SkMatrix& localMatri x); 294 SkShader::TileMode tm, SkUnitMapper* mapper,
295 const SkMatrix& localMatrix);
268 296
269 static const GradMaker gGradMakersOutside[] = { 297 static const GradMaker gGradMakersOutside[] = {
270 Make2ConicalOutside, Make2ConicalOutsideFlip, 298 Make2ConicalOutside, Make2ConicalOutsideFlip,
271 Make2ConicalZeroRadOutside, Make2ConicalZeroRadFlipOutside 299 Make2ConicalZeroRadOutside, Make2ConicalZeroRadFlipOutside
272 }; 300 };
273 301
274 static const GradMaker gGradMakersInside[] = { 302 static const GradMaker gGradMakersInside[] = {
275 Make2ConicalInside, Make2ConicalInsideFlip, Make2ConicalInsideCenter, 303 Make2ConicalInside, Make2ConicalInsideFlip, Make2ConicalInsideCenter,
276 Make2ConicalZeroRad, Make2ConicalZeroRadFlip, Make2ConicalZeroRadCenter, 304 Make2ConicalZeroRad, Make2ConicalZeroRadFlip, Make2ConicalZeroRadCenter,
277 }; 305 };
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) { 371 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) {
344 canvas->save(); 372 canvas->save();
345 for (int j = 0; j < count; j++) { 373 for (int j = 0; j < count; j++) {
346 SkMatrix scale = SkMatrix::I(); 374 SkMatrix scale = SkMatrix::I();
347 375
348 if (i == 3) { // if the clamp case 376 if (i == 3) { // if the clamp case
349 scale.setScale(0.5f, 0.5f); 377 scale.setScale(0.5f, 0.5f);
350 scale.postTranslate(25.f, 25.f); 378 scale.postTranslate(25.f, 25.f);
351 } 379 }
352 380
353 SkShader* shader = gradMaker[j](pts, gGradData[i], tm, scale); 381 SkShader* shader = gradMaker[j](pts, gGradData[i], tm, NULL, sca le);
354 paint.setShader(shader); 382 paint.setShader(shader);
355 canvas->drawRect(r, paint); 383 canvas->drawRect(r, paint);
356 shader->unref(); 384 shader->unref();
357 canvas->translate(0, SkIntToScalar(120)); 385 canvas->translate(0, SkIntToScalar(120));
358 } 386 }
359 canvas->restore(); 387 canvas->restore();
360 canvas->translate(SkIntToScalar(120), 0); 388 canvas->translate(SkIntToScalar(120), 0);
361 } 389 }
362 } 390 }
363 391
364 private: 392 private:
365 typedef GM INHERITED; 393 typedef GM INHERITED;
366 394
367 GradCaseType fGradCaseType; 395 GradCaseType fGradCaseType;
368 SkString fName; 396 SkString fName;
369 }; 397 };
370 /////////////////////////////////////////////////////////////////////////////// 398 ///////////////////////////////////////////////////////////////////////////////
371 399
372 static GM* MyFactory1(void*) { return new ConicalGradientsGM(kInside_GradCaseTyp e); } 400 static GM* MyFactory1(void*) { return new ConicalGradientsGM(kInside_GradCaseTyp e); }
373 static GMRegistry reg1(MyFactory1); 401 static GMRegistry reg1(MyFactory1);
374 402
375 static GM* MyFactory2(void*) { return new ConicalGradientsGM(kOutside_GradCaseTy pe); } 403 static GM* MyFactory2(void*) { return new ConicalGradientsGM(kOutside_GradCaseTy pe); }
376 static GMRegistry reg2(MyFactory2); 404 static GMRegistry reg2(MyFactory2);
377 405
378 static GM* MyFactory3(void*) { return new ConicalGradientsGM(kEdge_GradCaseType) ; } 406 static GM* MyFactory3(void*) { return new ConicalGradientsGM(kEdge_GradCaseType) ; }
379 static GMRegistry reg3(MyFactory3); 407 static GMRegistry reg3(MyFactory3);
380 } 408 }
OLDNEW
« no previous file with comments | « gm/gradients.cpp ('k') | gm/gradients_no_texture.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698