OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 #include "SkGradientShader.h" | 9 #include "SkGradientShader.h" |
10 | 10 |
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 | 585 |
586 private: | 586 private: |
587 SkAutoTUnref<SkShader> fShader[100]; | 587 SkAutoTUnref<SkShader> fShader[100]; |
588 bool fDither; | 588 bool fDither; |
589 | 589 |
590 typedef GM INHERITED; | 590 typedef GM INHERITED; |
591 }; | 591 }; |
592 DEF_GM( return new LinearGradientGM(true); ) | 592 DEF_GM( return new LinearGradientGM(true); ) |
593 DEF_GM( return new LinearGradientGM(false); ) | 593 DEF_GM( return new LinearGradientGM(false); ) |
594 | 594 |
| 595 class LinearGradientTinyGM : public GM { |
| 596 protected: |
| 597 SkString onShortName() override { |
| 598 return SkString("linear_gradient_tiny"); |
| 599 } |
| 600 |
| 601 SkISize onISize() override { |
| 602 return SkISize::Make(600, 500); |
| 603 } |
| 604 |
| 605 void onDraw(SkCanvas* canvas) override { |
| 606 const SkScalar kRectSize = 100; |
| 607 const unsigned kStopCount = 3; |
| 608 const SkColor colors[kStopCount] = { SK_ColorGREEN, SK_ColorRED, SK_Colo
rGREEN }; |
| 609 const struct { |
| 610 SkPoint pts[2]; |
| 611 SkScalar pos[kStopCount]; |
| 612 } configs[] = { |
| 613 { { SkPoint::Make(0, 0), SkPoint::Make(10, 0) }, { 0, 0.999999f,
1 }}, |
| 614 { { SkPoint::Make(0, 0), SkPoint::Make(10, 0) }, { 0, 0.000001f,
1 }}, |
| 615 { { SkPoint::Make(0, 0), SkPoint::Make(10, 0) }, { 0, 0.999999999f,
1 }}, |
| 616 { { SkPoint::Make(0, 0), SkPoint::Make(10, 0) }, { 0, 0.000000001f,
1 }}, |
| 617 { { SkPoint::Make(0, 0), SkPoint::Make(0, 10) }, { 0, 0.999999f,
1 }}, |
| 618 { { SkPoint::Make(0, 0), SkPoint::Make(0, 10) }, { 0, 0.000001f,
1 }}, |
| 619 { { SkPoint::Make(0, 0), SkPoint::Make(0, 10) }, { 0, 0.999999999f,
1 }}, |
| 620 { { SkPoint::Make(0, 0), SkPoint::Make(0, 10) }, { 0, 0.000000001f,
1 }}, |
| 621 |
| 622 { { SkPoint::Make(0, 0), SkPoint::Make(0.00001f, 0) } , { 0, 0.5f, 1
}}, |
| 623 { { SkPoint::Make(9.99999f, 0), SkPoint::Make(10, 0) }, { 0, 0.5f, 1
}}, |
| 624 { { SkPoint::Make(0, 0), SkPoint::Make(0, 0.00001f) }, { 0, 0.5f, 1
}}, |
| 625 { { SkPoint::Make(0, 9.99999f), SkPoint::Make(0, 10) }, { 0, 0.5f, 1
}}, |
| 626 }; |
| 627 |
| 628 SkPaint paint; |
| 629 for (unsigned i = 0; i < SK_ARRAY_COUNT(configs); ++i) { |
| 630 SkAutoCanvasRestore acr(canvas, true); |
| 631 SkAutoTUnref<SkShader> gradient( |
| 632 SkGradientShader::CreateLinear(configs[i].pts, colors, configs[i
].pos, kStopCount, |
| 633 SkShader::kClamp_TileMode)); |
| 634 canvas->translate(kRectSize * ((i % 4) * 1.5f + 0.25f), |
| 635 kRectSize * ((i / 4) * 1.5f + 0.25f)); |
| 636 |
| 637 paint.setShader(gradient); |
| 638 canvas->drawRect(SkRect::MakeWH(kRectSize, kRectSize), paint); |
| 639 } |
| 640 } |
| 641 |
| 642 private: |
| 643 typedef GM INHERITED; |
| 644 }; |
| 645 DEF_GM( return new LinearGradientTinyGM(); ) |
| 646 |
595 } | 647 } |
OLD | NEW |