aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/gradients.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'gm/gradients.cpp')
-rw-r--r--gm/gradients.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/gm/gradients.cpp b/gm/gradients.cpp
index 00dbb8f42f..2a1f9031bb 100644
--- a/gm/gradients.cpp
+++ b/gm/gradients.cpp
@@ -1072,3 +1072,49 @@ DEF_SIMPLE_GM(sweep_tiling, canvas, 690, 512) {
canvas->translate(0, size * 1.1f);
}
}
+
+// Exercises the special-case Ganesh gradient effects.
+DEF_SIMPLE_GM(gradients_interesting, canvas, 640, 1080) {
+ static const SkColor colors2[] = { SK_ColorRED, SK_ColorBLUE };
+ static const SkColor colors3[] = { SK_ColorRED, SK_ColorYELLOW, SK_ColorBLUE };
+ static const SkColor colors4[] = { SK_ColorRED, SK_ColorYELLOW, SK_ColorYELLOW, SK_ColorBLUE };
+
+ static const SkScalar hardLeft[] = { 0, 0, 1 };
+ static const SkScalar hardRight[] = { 0, 1, 1 };
+ static const SkScalar hardCenter[] = { 0, .5f, .5f, 1 };
+
+ static const struct {
+ const SkColor* colors;
+ const SkScalar* pos;
+ int count;
+ } configs[] = {
+ { colors2, nullptr, 2 }, // kTwo_ColorType
+ { colors3, nullptr, 3 }, // kThree_ColorType
+ { colors3, hardLeft, 3 }, // kHardStopLeftEdged_ColorType
+ { colors3, hardRight, 3 }, // kHardStopRightEdged_ColorType
+ { colors4, hardCenter, 4 }, // kSingleHardStop_ColorType
+ };
+
+ static const SkShader::TileMode modes[] = {
+ SkShader::kClamp_TileMode,
+ SkShader::kRepeat_TileMode,
+ SkShader::kMirror_TileMode,
+ };
+
+ static constexpr SkScalar size = 200;
+ static const SkPoint pts[] = { { size / 3, size / 3 }, { size * 2 / 3, size * 2 / 3} };
+
+ SkPaint p;
+ for (const auto& cfg : configs) {
+ {
+ SkAutoCanvasRestore acr(canvas, true);
+ for (auto mode : modes) {
+ p.setShader(SkGradientShader::MakeLinear(pts, cfg.colors, cfg.pos, cfg.count,
+ mode));
+ canvas->drawRect(SkRect::MakeWH(size, size), p);
+ canvas->translate(size * 1.1f, 0);
+ }
+ }
+ canvas->translate(0, size * 1.1f);
+ }
+}