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

Side by Side Diff: gm/gradients.cpp

Issue 1061753009: add GM to show bad banding in raster for radial gradients (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 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
« 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
2 /* 1 /*
3 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
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 */
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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 canvas->translate(0, SkIntToScalar(120)); 142 canvas->translate(0, SkIntToScalar(120));
143 } 143 }
144 canvas->restore(); 144 canvas->restore();
145 canvas->translate(SkIntToScalar(120), 0); 145 canvas->translate(SkIntToScalar(120), 0);
146 } 146 }
147 } 147 }
148 148
149 private: 149 private:
150 typedef GM INHERITED; 150 typedef GM INHERITED;
151 }; 151 };
152 DEF_GM( return new GradientsGM; )
152 153
153 // Based on the original gradient slide, but with perspective applied to the 154 // Based on the original gradient slide, but with perspective applied to the
154 // gradient shaders' local matrices 155 // gradient shaders' local matrices
155 class GradientsLocalPerspectiveGM : public GM { 156 class GradientsLocalPerspectiveGM : public GM {
156 public: 157 public:
157 GradientsLocalPerspectiveGM() { 158 GradientsLocalPerspectiveGM() {
158 this->setBGColor(0xFFDDDDDD); 159 this->setBGColor(0xFFDDDDDD);
159 } 160 }
160 161
161 protected: 162 protected:
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 canvas->translate(0, SkIntToScalar(120)); 198 canvas->translate(0, SkIntToScalar(120));
198 } 199 }
199 canvas->restore(); 200 canvas->restore();
200 canvas->translate(SkIntToScalar(120), 0); 201 canvas->translate(SkIntToScalar(120), 0);
201 } 202 }
202 } 203 }
203 204
204 private: 205 private:
205 typedef GM INHERITED; 206 typedef GM INHERITED;
206 }; 207 };
208 DEF_GM( return new GradientsLocalPerspectiveGM; )
207 209
208 // Based on the original gradient slide, but with perspective applied to 210 // Based on the original gradient slide, but with perspective applied to
209 // the view matrix 211 // the view matrix
210 class GradientsViewPerspectiveGM : public GradientsGM { 212 class GradientsViewPerspectiveGM : public GradientsGM {
211 protected: 213 protected:
212 SkString onShortName() { 214 SkString onShortName() {
213 return SkString("gradients_view_perspective"); 215 return SkString("gradients_view_perspective");
214 } 216 }
215 217
216 virtual SkISize onISize() { return SkISize::Make(840, 500); } 218 virtual SkISize onISize() { return SkISize::Make(840, 500); }
217 219
218 virtual void onDraw(SkCanvas* canvas) { 220 virtual void onDraw(SkCanvas* canvas) {
219 SkMatrix perspective; 221 SkMatrix perspective;
220 perspective.setIdentity(); 222 perspective.setIdentity();
221 perspective.setPerspY(SkScalarDiv(SK_Scalar1, SkIntToScalar(1000))); 223 perspective.setPerspY(SkScalarDiv(SK_Scalar1, SkIntToScalar(1000)));
222 perspective.setSkewX(SkScalarDiv(SkIntToScalar(8), SkIntToScalar(25))); 224 perspective.setSkewX(SkScalarDiv(SkIntToScalar(8), SkIntToScalar(25)));
223 canvas->concat(perspective); 225 canvas->concat(perspective);
224 INHERITED::onDraw(canvas); 226 INHERITED::onDraw(canvas);
225 } 227 }
226 228
227 private: 229 private:
228 typedef GradientsGM INHERITED; 230 typedef GradientsGM INHERITED;
229 }; 231 };
232 DEF_GM( return new GradientsViewPerspectiveGM; )
230 233
231 /* 234 /*
232 Inspired by this <canvas> javascript, where we need to detect that we are not 235 Inspired by this <canvas> javascript, where we need to detect that we are not
233 solving a quadratic equation, but must instead solve a linear (since our X^2 236 solving a quadratic equation, but must instead solve a linear (since our X^2
234 coefficient is 0) 237 coefficient is 0)
235 238
236 ctx.fillStyle = '#f00'; 239 ctx.fillStyle = '#f00';
237 ctx.fillRect(0, 0, 100, 50); 240 ctx.fillRect(0, 0, 100, 50);
238 241
239 var g = ctx.createRadialGradient(-80, 25, 70, 0, 25, 150); 242 var g = ctx.createRadialGradient(-80, 25, 70, 0, 25, 150);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 pos, SK_ARRAY_COUNT (pos), 277 pos, SK_ARRAY_COUNT (pos),
275 SkShader::kClamp_Ti leMode); 278 SkShader::kClamp_Ti leMode);
276 SkPaint paint; 279 SkPaint paint;
277 paint.setShader(s)->unref(); 280 paint.setShader(s)->unref();
278 canvas->drawPaint(paint); 281 canvas->drawPaint(paint);
279 } 282 }
280 283
281 private: 284 private:
282 typedef GM INHERITED; 285 typedef GM INHERITED;
283 }; 286 };
287 DEF_GM( return new GradientsDegenrate2PointGM; )
284 288
285 /// Tests correctness of *optimized* codepaths in gradients. 289 /// Tests correctness of *optimized* codepaths in gradients.
286 290
287 class ClampedGradientsGM : public GM { 291 class ClampedGradientsGM : public GM {
288 public: 292 public:
289 ClampedGradientsGM() {} 293 ClampedGradientsGM() {}
290 294
291 protected: 295 protected:
292 SkString onShortName() { return SkString("clamped_gradients"); } 296 SkString onShortName() { return SkString("clamped_gradients"); }
293 297
(...skipping 18 matching lines...) Expand all
312 SkIntToScalar(200), gColors, NULL, 5, 316 SkIntToScalar(200), gColors, NULL, 5,
313 SkShader::kClamp_TileMode); 317 SkShader::kClamp_TileMode);
314 paint.setShader(shader); 318 paint.setShader(shader);
315 canvas->drawRect(r, paint); 319 canvas->drawRect(r, paint);
316 shader->unref(); 320 shader->unref();
317 } 321 }
318 322
319 private: 323 private:
320 typedef GM INHERITED; 324 typedef GM INHERITED;
321 }; 325 };
326 DEF_GM( return new ClampedGradientsGM; )
322 327
323 /// Checks quality of large radial gradients, which may display 328 /// Checks quality of large radial gradients, which may display
324 /// some banding. 329 /// some banding.
325 330
326 class RadialGradientGM : public GM { 331 class RadialGradientGM : public GM {
327 public: 332 public:
328 RadialGradientGM() {} 333 RadialGradientGM() {}
329 334
330 protected: 335 protected:
331 336
(...skipping 22 matching lines...) Expand all
354 SkShader::kClamp_TileMode); 359 SkShader::kClamp_TileMode);
355 paint.setShader(shader)->unref(); 360 paint.setShader(shader)->unref();
356 SkRect r = { 361 SkRect r = {
357 0, 0, SkIntToScalar(dim.width()), SkIntToScalar(dim.height()) 362 0, 0, SkIntToScalar(dim.width()), SkIntToScalar(dim.height())
358 }; 363 };
359 canvas->drawRect(r, paint); 364 canvas->drawRect(r, paint);
360 } 365 }
361 private: 366 private:
362 typedef GM INHERITED; 367 typedef GM INHERITED;
363 }; 368 };
364 369 DEF_GM( return new RadialGradientGM; )
365 370
366 class RadialGradient2GM : public GM { 371 class RadialGradient2GM : public GM {
367 public: 372 public:
368 RadialGradient2GM() {} 373 RadialGradient2GM() {}
369 374
370 protected: 375 protected:
371 376
372 SkString onShortName() override { return SkString("radial_gradient2"); } 377 SkString onShortName() override { return SkString("radial_gradient2"); }
373 SkISize onISize() override { return SkISize::Make(800, 400); } 378 SkISize onISize() override { return SkISize::Make(800, 400); }
374 void drawBG(SkCanvas* canvas) { 379 void drawBG(SkCanvas* canvas) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 canvas->drawCircle(cx, cy, radius, paint3); 423 canvas->drawCircle(cx, cy, radius, paint3);
419 canvas->drawCircle(cx, cy, radius, paint2); 424 canvas->drawCircle(cx, cy, radius, paint2);
420 425
421 canvas->translate(400, 0); 426 canvas->translate(400, 0);
422 } 427 }
423 } 428 }
424 429
425 private: 430 private:
426 typedef GM INHERITED; 431 typedef GM INHERITED;
427 }; 432 };
433 DEF_GM( return new RadialGradient2GM; )
428 434
429 /////////////////////////////////////////////////////////////////////////////// 435 // Shallow radial (shows banding on raster)
436 class RadialGradient3GM : public GM {
437 SkAutoTUnref<SkShader> fShader;
430 438
431 static GM* MyFactory(void*) { return new GradientsGM; } 439 protected:
432 static GMRegistry reg(MyFactory); 440 SkString onShortName() override { return SkString("radial_gradient3"); }
433 441
434 static GM* MyFactory2(void*) { return new GradientsDegenrate2PointGM; } 442 SkISize onISize() override { return SkISize::Make(500, 500); }
435 static GMRegistry reg2(MyFactory2);
436 443
437 static GM* MyFactory3(void*) { return new ClampedGradientsGM; } 444 bool runAsBench() const override { return true; }
438 static GMRegistry reg3(MyFactory3);
439 445
440 static GM* MyFactory4(void*) { return new RadialGradientGM; } 446 void onOnceBeforeDraw() override {
441 static GMRegistry reg4(MyFactory4); 447 const SkPoint center = { 0, 0 };
448 const SkScalar kRadius = 3000;
449 const SkColor gColors[] = { 0xFFFFFFFF, 0xFF000000 };
450 fShader.reset(SkGradientShader::CreateRadial(center, kRadius, gColors, N ULL, 2,
robertphillips 2015/04/23 18:48:18 missing space ?
451 SkShader::kClamp_TileMode));
452 }
442 453
443 static GM* MyFactory5(void*) { return new GradientsLocalPerspectiveGM; } 454 void onDraw(SkCanvas* canvas) override {
444 static GMRegistry reg5(MyFactory5); 455 SkPaint paint;
456 paint.setShader(fShader);
457 canvas->drawRect(SkRect::MakeWH(500, 500), paint);
458 }
459
460 private:
461 typedef GM INHERITED;
462 };
463 DEF_GM( return new RadialGradient3GM; )
445 464
446 static GM* MyFactory6(void*) { return new GradientsViewPerspectiveGM; }
447 static GMRegistry reg6(MyFactory6);
448
449 static GM* MyFactory7(void*) { return new RadialGradient2GM; }
450 static GMRegistry reg7(MyFactory7);
451 } 465 }
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