| 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 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 } | 603 } |
| 604 | 604 |
| 605 void onDraw(SkCanvas* canvas) override { | 605 void onDraw(SkCanvas* canvas) override { |
| 606 const SkScalar kRectSize = 100; | 606 const SkScalar kRectSize = 100; |
| 607 const unsigned kStopCount = 3; | 607 const unsigned kStopCount = 3; |
| 608 const SkColor colors[kStopCount] = { SK_ColorGREEN, SK_ColorRED, SK_Colo
rGREEN }; | 608 const SkColor colors[kStopCount] = { SK_ColorGREEN, SK_ColorRED, SK_Colo
rGREEN }; |
| 609 const struct { | 609 const struct { |
| 610 SkPoint pts[2]; | 610 SkPoint pts[2]; |
| 611 SkScalar pos[kStopCount]; | 611 SkScalar pos[kStopCount]; |
| 612 } configs[] = { | 612 } configs[] = { |
| 613 { { SkPoint::Make(0, 0), SkPoint::Make(10, 0) }, { 0, 0.999999f,
1 }}, | 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 }}, | 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 }}, | 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 }}, | 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 | 617 |
| 622 { { SkPoint::Make(0, 0), SkPoint::Make(0.00001f, 0) } , { 0, 0.5f, 1
}}, | 618 { { SkPoint::Make(0, 0), SkPoint::Make(0, 10) }, { 0, 0
.999999f, 1 }}, |
| 623 { { SkPoint::Make(9.99999f, 0), SkPoint::Make(10, 0) }, { 0, 0.5f, 1
}}, | 619 { { SkPoint::Make(0, 0), SkPoint::Make(0, 10) }, { 0, 0
.000001f, 1 }}, |
| 624 { { SkPoint::Make(0, 0), SkPoint::Make(0, 0.00001f) }, { 0, 0.5f, 1
}}, | 620 { { SkPoint::Make(0, 0), SkPoint::Make(0, 10) }, { 0, 0
.999999999f, 1 }}, |
| 625 { { SkPoint::Make(0, 9.99999f), SkPoint::Make(0, 10) }, { 0, 0.5f, 1
}}, | 621 { { SkPoint::Make(0, 0), SkPoint::Make(0, 10) }, { 0, 0
.000000001f, 1 }}, |
| 622 |
| 623 { { SkPoint::Make(0, 0), SkPoint::Make(0.00001f, 0) }, { 0, 0
.5f, 1 }}, |
| 624 { { SkPoint::Make(9.99999f, 0), SkPoint::Make(10, 0) }, { 0, 0
.5f, 1 }}, |
| 625 { { SkPoint::Make(0, 0), SkPoint::Make(0, 0.00001f) }, { 0, 0
.5f, 1 }}, |
| 626 { { SkPoint::Make(0, 9.99999f), SkPoint::Make(0, 10) }, { 0, 0
.5f, 1 }}, |
| 626 }; | 627 }; |
| 627 | 628 |
| 628 SkPaint paint; | 629 SkPaint paint; |
| 629 for (unsigned i = 0; i < SK_ARRAY_COUNT(configs); ++i) { | 630 for (unsigned i = 0; i < SK_ARRAY_COUNT(configs); ++i) { |
| 630 SkAutoCanvasRestore acr(canvas, true); | 631 SkAutoCanvasRestore acr(canvas, true); |
| 631 SkAutoTUnref<SkShader> gradient( | 632 SkAutoTUnref<SkShader> gradient( |
| 632 SkGradientShader::CreateLinear(configs[i].pts, colors, configs[i
].pos, kStopCount, | 633 SkGradientShader::CreateLinear(configs[i].pts, colors, configs[i
].pos, kStopCount, |
| 633 SkShader::kClamp_TileMode)); | 634 SkShader::kClamp_TileMode)); |
| 634 canvas->translate(kRectSize * ((i % 4) * 1.5f + 0.25f), | 635 canvas->translate(kRectSize * ((i % 4) * 1.5f + 0.25f), |
| 635 kRectSize * ((i / 4) * 1.5f + 0.25f)); | 636 kRectSize * ((i / 4) * 1.5f + 0.25f)); |
| 636 | 637 |
| 637 paint.setShader(gradient); | 638 paint.setShader(gradient); |
| 638 canvas->drawRect(SkRect::MakeWH(kRectSize, kRectSize), paint); | 639 canvas->drawRect(SkRect::MakeWH(kRectSize, kRectSize), paint); |
| 639 } | 640 } |
| 640 } | 641 } |
| 641 | 642 |
| 642 private: | 643 private: |
| 643 typedef GM INHERITED; | 644 typedef GM INHERITED; |
| 644 }; | 645 }; |
| 645 DEF_GM( return new LinearGradientTinyGM(); ) | 646 DEF_GM( return new LinearGradientTinyGM(); ) |
| 646 | 647 |
| 647 } | 648 } |
| OLD | NEW |