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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 SkRect r = { | 354 SkRect r = { |
355 0, 0, SkIntToScalar(dim.width()), SkIntToScalar(dim.height()) | 355 0, 0, SkIntToScalar(dim.width()), SkIntToScalar(dim.height()) |
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 { |
| 365 public: |
| 366 RadialGradient2GM() {} |
| 367 |
| 368 protected: |
| 369 SkString onShortName() { return SkString("radial_gradient2"); } |
| 370 virtual SkISize onISize() { return make_isize(400, 400); } |
| 371 void drawBG(SkCanvas* canvas) { |
| 372 canvas->drawColor(0xFF000000); |
| 373 } |
| 374 |
| 375 // Reproduces the example given in bug 7671058. |
| 376 virtual void onDraw(SkCanvas* canvas) { |
| 377 SkPaint paint1, paint2, paint3; |
| 378 paint1.setStyle(SkPaint::kFill_Style); |
| 379 paint2.setStyle(SkPaint::kFill_Style); |
| 380 paint3.setStyle(SkPaint::kFill_Style); |
| 381 |
| 382 const SkColor sweep_colors[] = |
| 383 { 0xFFFF0000, 0xFFFFFF00, 0xFF00FF00, 0xFF00FFFF, 0xFF0000FF, 0xFFFF
00FF, 0xFFFF0000 }; |
| 384 const SkColor colors1[] = { 0xFFFFFFFF, 0x00000000 }; |
| 385 const SkColor colors2[] = { 0xFF000000, 0x00000000 }; |
| 386 |
| 387 const SkScalar cx = 200, cy = 200, radius = 150; |
| 388 SkPoint center; |
| 389 center.set(cx, cy); |
| 390 |
| 391 SkAutoTUnref<SkShader> sweep( |
| 392 SkGradientShader::CreateSweep(cx, cy, sweep_colors, |
| 393 NULL, SK_ARRAY_COUNT(sweep_colors)
)); |
| 394 SkAutoTUnref<SkShader> radial1( |
| 395 SkGradientShader::CreateRadial(center, radius, colors1, |
| 396 NULL, SK_ARRAY_COUNT(colors1), |
| 397 SkShader::kClamp_TileMode)); |
| 398 SkAutoTUnref<SkShader> radial2( |
| 399 SkGradientShader::CreateRadial(center, radius, colors2, |
| 400 NULL, SK_ARRAY_COUNT(colors2), |
| 401 SkShader::kClamp_TileMode)); |
| 402 paint1.setShader(sweep); |
| 403 paint2.setShader(radial1); |
| 404 paint3.setShader(radial2); |
| 405 |
| 406 canvas->drawCircle(cx, cy, radius, paint1); |
| 407 canvas->drawCircle(cx, cy, radius, paint3); |
| 408 canvas->drawCircle(cx, cy, radius, paint2); |
| 409 } |
| 410 |
| 411 private: |
| 412 typedef GM INHERITED; |
| 413 }; |
364 | 414 |
365 /////////////////////////////////////////////////////////////////////////////// | 415 /////////////////////////////////////////////////////////////////////////////// |
366 | 416 |
367 static GM* MyFactory(void*) { return new GradientsGM; } | 417 static GM* MyFactory(void*) { return new GradientsGM; } |
368 static GMRegistry reg(MyFactory); | 418 static GMRegistry reg(MyFactory); |
369 | 419 |
370 static GM* MyFactory2(void*) { return new GradientsDegenrate2PointGM; } | 420 static GM* MyFactory2(void*) { return new GradientsDegenrate2PointGM; } |
371 static GMRegistry reg2(MyFactory2); | 421 static GMRegistry reg2(MyFactory2); |
372 | 422 |
373 static GM* MyFactory3(void*) { return new ClampedGradientsGM; } | 423 static GM* MyFactory3(void*) { return new ClampedGradientsGM; } |
374 static GMRegistry reg3(MyFactory3); | 424 static GMRegistry reg3(MyFactory3); |
375 | 425 |
376 static GM* MyFactory4(void*) { return new RadialGradientGM; } | 426 static GM* MyFactory4(void*) { return new RadialGradientGM; } |
377 static GMRegistry reg4(MyFactory4); | 427 static GMRegistry reg4(MyFactory4); |
378 | 428 |
379 static GM* MyFactory5(void*) { return new GradientsLocalPerspectiveGM; } | 429 static GM* MyFactory5(void*) { return new GradientsLocalPerspectiveGM; } |
380 static GMRegistry reg5(MyFactory5); | 430 static GMRegistry reg5(MyFactory5); |
381 | 431 |
382 static GM* MyFactory6(void*) { return new GradientsViewPerspectiveGM; } | 432 static GM* MyFactory6(void*) { return new GradientsViewPerspectiveGM; } |
383 static GMRegistry reg6(MyFactory6); | 433 static GMRegistry reg6(MyFactory6); |
| 434 |
| 435 static GM* MyFactory7(void*) { return new RadialGradient2GM; } |
| 436 static GMRegistry reg7(MyFactory7); |
384 } | 437 } |
OLD | NEW |