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

Side by Side Diff: gm/gradients_no_texture.cpp

Issue 243133005: gradient_many gm to test banding and precision (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 8 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 | « no previous file | no next file » | 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 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
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 #include "gm.h" 7 #include "gm.h"
8 #include "SkGradientShader.h" 8 #include "SkGradientShader.h"
9 9
10 using namespace skiagm; 10 using namespace skiagm;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 } 120 }
121 } 121 }
122 } 122 }
123 123
124 private: 124 private:
125 typedef GM INHERITED; 125 typedef GM INHERITED;
126 }; 126 };
127 127
128 /////////////////////////////////////////////////////////////////////////////// 128 ///////////////////////////////////////////////////////////////////////////////
129 129
130 struct ColorPos {
131 SkColor* fColors;
132 SkScalar* fPos;
133 int fCount;
134
135 ColorPos() : fColors(NULL), fPos(NULL), fCount(0) {}
136 ~ColorPos() {
137 SkDELETE(fColors);
138 SkDELETE(fPos);
139 }
140
141 void construct(const SkColor colors[], const SkScalar pos[], int count) {
142 fColors = SkNEW_ARRAY(SkColor, count);
143 memcpy(fColors, colors, count * sizeof(SkColor));
144 if (pos) {
145 fPos = SkNEW_ARRAY(SkScalar, count);
146 memcpy(fPos, pos, count * sizeof(SkScalar));
147 fPos[0] = 0;
148 fPos[count - 1] = 1;
149 }
150 fCount = count;
151 }
152 };
153
154 static void make0(ColorPos* rec) {
155 #if 0
156 From http://jsfiddle.net/3fe2a/
157
158 background-image: -webkit-linear-gradient(left, #22d1cd 1%, #22d1cd 0.9510157507 590116%, #df4b37 2.9510157507590113%, #df4b37 23.695886056604927%, #22d1cd 25.69 5886056604927%, #22d1cd 25.39321881940624%, #e6de36 27.39321881940624%, #e6de36 31.849399922570655%, #3267ff 33.849399922570655%, #3267ff 44.57735802921938%, #9 d47d1 46.57735802921938%, #9d47d1 53.27185850805876%, #3267ff 55.27185850805876% , #3267ff 61.95718972227316%, #5cdd9d 63.95718972227316%, #5cdd9d 69.89166004442 %, #3267ff 71.89166004442%, #3267ff 74.45795382765857%, #9d47d1 76.4579538276585 7%, #9d47d1 82.78364610713776%, #3267ff 84.78364610713776%, #3267ff 94.527436477 37229%, #e3d082 96.52743647737229%, #e3d082 96.03934633331295%);
159 height: 30px;
160 #endif
161
162 const SkColor colors[] = {
163 0xFF22d1cd, 0xFF22d1cd, 0xFFdf4b37, 0xFFdf4b37, 0xFF22d1cd, 0xFF22d1cd, 0xFFe6de36, 0xFFe6de36,
164 0xFF3267ff, 0xFF3267ff, 0xFF9d47d1, 0xFF9d47d1, 0xFF3267ff, 0xFF3267ff, 0xFF5cdd9d, 0xFF5cdd9d,
165 0xFF3267ff, 0xFF3267ff, 0xFF9d47d1, 0xFF9d47d1, 0xFF3267ff, 0xFF3267ff, 0xFFe3d082, 0xFFe3d082
166 };
167 const double percent[] = {
168 1, 0.9510157507590116, 2.9510157507590113, 23.695886056604927,
169 25.695886056604927, 25.39321881940624, 27.39321881940624, 31.84939992257 0655,
170 33.849399922570655, 44.57735802921938, 46.57735802921938, 53.27185850805 876,
171 55.27185850805876, 61.95718972227316, 63.95718972227316, 69.89166004442,
172 71.89166004442, 74.45795382765857, 76.45795382765857, 82.78364610713776,
173 84.78364610713776, 94.52743647737229, 96.52743647737229, 96.039346333312 95,
174 };
175 const int N = SK_ARRAY_COUNT(percent);
176 SkScalar pos[N];
177 for (int i = 0; i < N; ++i) {
178 pos[i] = SkDoubleToScalar(percent[i] / 100);
179 }
180 rec->construct(colors, pos, N);
181 }
182
183 static void make1(ColorPos* rec) {
184 const SkColor colors[] = {
185 SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLACK, SK_ColorWHITE,
186 SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLACK, SK_ColorWHITE,
187 SK_ColorBLACK,
188 };
189 rec->construct(colors, NULL, SK_ARRAY_COUNT(colors));
190 }
191
192 static void make2(ColorPos* rec) {
193 const SkColor colors[] = {
194 SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLACK, SK_ColorWHITE,
195 SK_ColorBLACK, SK_ColorWHITE, SK_ColorBLACK, SK_ColorWHITE,
196 SK_ColorBLACK,
197 };
198 const int N = SK_ARRAY_COUNT(colors);
199 SkScalar pos[N];
200 for (int i = 0; i < N; ++i) {
201 pos[i] = SK_Scalar1 * i / (N - 1);
202 }
203 rec->construct(colors, pos, N);
204 }
205
206 class GradientsManyColorsGM : public GM {
207 enum {
208 W = 800,
209 };
210 SkAutoTUnref<SkShader> fShader;
211
212 typedef void (*Proc)(ColorPos*);
213 public:
214 GradientsManyColorsGM() {}
215
216 protected:
217 SkString onShortName() SK_OVERRIDE { return SkString("gradients_many"); }
218 virtual SkISize onISize() SK_OVERRIDE { return SkISize::Make(850, 100); }
219
220 virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
221 const Proc procs[] = {
222 make0, make1, make2,
223 };
224 const SkPoint pts[] = {
225 { 0, 0 },
226 { SkIntToScalar(W), 0 },
227 };
228 const SkRect r = SkRect::MakeWH(SkIntToScalar(W), 30);
229
230 SkPaint paint;
231
232 canvas->translate(20, 20);
233
234 for (int i = 0; i <= 8; ++i) {
235 SkScalar x = r.width() * i / 8;
236 canvas->drawLine(x, 0, x, 10000, paint);
237 }
238
239 for (size_t i = 0; i < SK_ARRAY_COUNT(procs); ++i) {
240 ColorPos rec;
241 procs[i](&rec);
242 SkShader* s = SkGradientShader::CreateLinear(pts, rec.fColors, rec.f Pos, rec.fCount,
243 SkShader::kClamp_TileMo de);
244 paint.setShader(s)->unref();
245 canvas->drawRect(r, paint);
246 canvas->translate(0, r.height() + 20);
247 }
248 }
249
250 private:
251 typedef GM INHERITED;
252 };
253
254 ///////////////////////////////////////////////////////////////////////////////
255
130 DEF_GM( return SkNEW(GradientsNoTextureGM)); 256 DEF_GM( return SkNEW(GradientsNoTextureGM));
257 DEF_GM( return SkNEW(GradientsManyColorsGM));
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698