Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * 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 |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 #include "gm.h" | 8 #include "gm.h" |
| 9 #include "SkGradientShader.h" | 9 #include "SkGradientShader.h" |
| 10 | 10 |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 }; | 356 }; |
| 357 canvas->drawRect(r, paint); | 357 canvas->drawRect(r, paint); |
| 358 } | 358 } |
| 359 private: | 359 private: |
| 360 typedef GM INHERITED; | 360 typedef GM INHERITED; |
| 361 }; | 361 }; |
| 362 | 362 |
| 363 | 363 |
| 364 class RadialGradient2GM : public GM { | 364 class RadialGradient2GM : public GM { |
| 365 public: | 365 public: |
| 366 RadialGradient2GM() {} | 366 explicit RadialGradient2GM(bool premulFirst) : fPremulFirst(premulFirst) {} |
| 367 | 367 |
| 368 protected: | 368 protected: |
| 369 SkString onShortName() { return SkString("radial_gradient2"); } | 369 SkString onShortName() { |
| 370 return SkString(fPremulFirst ? "radial_gradient2_premul_then_interp" | |
| 371 : "radial_gradient2_interp_then_premul"); | |
| 372 } | |
| 370 virtual SkISize onISize() { return make_isize(400, 400); } | 373 virtual SkISize onISize() { return make_isize(400, 400); } |
| 371 void drawBG(SkCanvas* canvas) { | 374 void drawBG(SkCanvas* canvas) { |
| 372 canvas->drawColor(0xFF000000); | 375 canvas->drawColor(0xFF000000); |
| 373 } | 376 } |
| 374 | 377 |
| 375 // Reproduces the example given in bug 7671058. | 378 // Reproduces the example given in bug 7671058. |
| 376 virtual void onDraw(SkCanvas* canvas) { | 379 virtual void onDraw(SkCanvas* canvas) { |
| 377 SkPaint paint1, paint2, paint3; | 380 SkPaint paint1, paint2, paint3; |
| 378 paint1.setStyle(SkPaint::kFill_Style); | 381 paint1.setStyle(SkPaint::kFill_Style); |
| 379 paint2.setStyle(SkPaint::kFill_Style); | 382 paint2.setStyle(SkPaint::kFill_Style); |
| 380 paint3.setStyle(SkPaint::kFill_Style); | 383 paint3.setStyle(SkPaint::kFill_Style); |
| 381 | 384 |
| 382 const SkColor sweep_colors[] = | 385 const SkColor sweep_colors[] = |
| 383 { 0xFFFF0000, 0xFFFFFF00, 0xFF00FF00, 0xFF00FFFF, 0xFF0000FF, 0xFFFF 00FF, 0xFFFF0000 }; | 386 { 0xFFFF0000, 0xFFFFFF00, 0xFF00FF00, 0xFF00FFFF, 0xFF0000FF, 0xFFFF 00FF, 0xFFFF0000 }; |
| 384 const SkColor colors1[] = { 0xFFFFFFFF, 0x00000000 }; | 387 const SkColor colors1[] = { 0xFFFFFFFF, 0x00000000 }; |
| 385 const SkColor colors2[] = { 0xFF000000, 0x00000000 }; | 388 const SkColor colors2[] = { 0xFF000000, 0x00000000 }; |
| 386 | 389 |
| 387 const SkScalar cx = 200, cy = 200, radius = 150; | 390 const SkScalar cx = 200, cy = 200, radius = 150; |
| 388 SkPoint center; | 391 SkPoint center; |
| 389 center.set(cx, cy); | 392 center.set(cx, cy); |
| 390 | 393 |
| 394 // We can either interpolate endpoints and premultiply each point (defau lt, more precision), | |
| 395 // or premultiply the endpoints first, avoiding the need to premultiply each point (cheap). | |
| 396 const uint32_t flags = fPremulFirst ? SkGradientShader::kInterpolateColo rsInPremul_Flag : 0; | |
| 397 | |
| 391 SkAutoTUnref<SkShader> sweep( | 398 SkAutoTUnref<SkShader> sweep( |
| 392 SkGradientShader::CreateSweep(cx, cy, sweep_colors, | 399 SkGradientShader::CreateSweep(cx, cy, sweep_colors, |
| 393 NULL, SK_ARRAY_COUNT(sweep_colors) )); | 400 NULL, SK_ARRAY_COUNT(sweep_colors) , |
| 401 NULL, flags)); | |
| 394 SkAutoTUnref<SkShader> radial1( | 402 SkAutoTUnref<SkShader> radial1( |
| 395 SkGradientShader::CreateRadial(center, radius, colors1, | 403 SkGradientShader::CreateRadial(center, radius, colors1, |
| 396 NULL, SK_ARRAY_COUNT(colors1), | 404 NULL, SK_ARRAY_COUNT(colors1), |
| 397 SkShader::kClamp_TileMode)); | 405 SkShader::kClamp_TileMode, |
| 406 NULL, flags)); | |
| 398 SkAutoTUnref<SkShader> radial2( | 407 SkAutoTUnref<SkShader> radial2( |
| 399 SkGradientShader::CreateRadial(center, radius, colors2, | 408 SkGradientShader::CreateRadial(center, radius, colors2, |
| 400 NULL, SK_ARRAY_COUNT(colors2), | 409 NULL, SK_ARRAY_COUNT(colors2), |
| 401 SkShader::kClamp_TileMode)); | 410 SkShader::kClamp_TileMode, |
| 411 NULL, flags)); | |
| 402 paint1.setShader(sweep); | 412 paint1.setShader(sweep); |
| 403 paint2.setShader(radial1); | 413 paint2.setShader(radial1); |
| 404 paint3.setShader(radial2); | 414 paint3.setShader(radial2); |
| 405 | 415 |
| 406 canvas->drawCircle(cx, cy, radius, paint1); | 416 canvas->drawCircle(cx, cy, radius, paint1); |
| 407 canvas->drawCircle(cx, cy, radius, paint3); | 417 canvas->drawCircle(cx, cy, radius, paint3); |
| 408 canvas->drawCircle(cx, cy, radius, paint2); | 418 canvas->drawCircle(cx, cy, radius, paint2); |
| 409 } | 419 } |
| 410 | 420 |
| 411 private: | 421 private: |
| 422 bool fPremulFirst; | |
| 412 typedef GM INHERITED; | 423 typedef GM INHERITED; |
| 413 }; | 424 }; |
| 414 | 425 |
| 415 /////////////////////////////////////////////////////////////////////////////// | 426 /////////////////////////////////////////////////////////////////////////////// |
| 416 | 427 |
| 417 static GM* MyFactory(void*) { return new GradientsGM; } | 428 static GM* MyFactory(void*) { return new GradientsGM; } |
| 418 static GMRegistry reg(MyFactory); | 429 static GMRegistry reg(MyFactory); |
| 419 | 430 |
| 420 static GM* MyFactory2(void*) { return new GradientsDegenrate2PointGM; } | 431 static GM* MyFactory2(void*) { return new GradientsDegenrate2PointGM; } |
| 421 static GMRegistry reg2(MyFactory2); | 432 static GMRegistry reg2(MyFactory2); |
| 422 | 433 |
| 423 static GM* MyFactory3(void*) { return new ClampedGradientsGM; } | 434 static GM* MyFactory3(void*) { return new ClampedGradientsGM; } |
| 424 static GMRegistry reg3(MyFactory3); | 435 static GMRegistry reg3(MyFactory3); |
| 425 | 436 |
| 426 static GM* MyFactory4(void*) { return new RadialGradientGM; } | 437 static GM* MyFactory4(void*) { return new RadialGradientGM; } |
| 427 static GMRegistry reg4(MyFactory4); | 438 static GMRegistry reg4(MyFactory4); |
| 428 | 439 |
| 429 static GM* MyFactory5(void*) { return new GradientsLocalPerspectiveGM; } | 440 static GM* MyFactory5(void*) { return new GradientsLocalPerspectiveGM; } |
| 430 static GMRegistry reg5(MyFactory5); | 441 static GMRegistry reg5(MyFactory5); |
| 431 | 442 |
| 432 static GM* MyFactory6(void*) { return new GradientsViewPerspectiveGM; } | 443 static GM* MyFactory6(void*) { return new GradientsViewPerspectiveGM; } |
| 433 static GMRegistry reg6(MyFactory6); | 444 static GMRegistry reg6(MyFactory6); |
| 434 | 445 |
| 435 static GM* MyFactory7(void*) { return new RadialGradient2GM; } | 446 static GM* MyFactory7(void*) { return new RadialGradient2GM(true); } |
|
reed1
2013/09/11 14:33:27
nitties:
1. If we're going to have 2 gms, might b
| |
| 436 static GMRegistry reg7(MyFactory7); | 447 static GMRegistry reg7(MyFactory7); |
| 448 | |
| 449 static GM* MyFactory8(void*) { return new RadialGradient2GM(false); } | |
| 450 static GMRegistry reg8(MyFactory8); | |
| 437 } | 451 } |
| OLD | NEW |