From 36f054ace3d8726cb4f9f46f38340bcffc830336 Mon Sep 17 00:00:00 2001 From: Florin Malita Date: Thu, 3 Aug 2017 12:55:41 -0400 Subject: GrGradientEffect::onIsEqual() must also consider tiling Without this fix, the newly added GM draws incorrectly. Change-Id: Ic159ab3201c10369ad5f8151186245d8d076cc25 Reviewed-on: https://skia-review.googlesource.com/30484 Reviewed-by: Brian Osman Commit-Queue: Florin Malita --- gm/gradients.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'gm/gradients.cpp') 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); + } +} -- cgit v1.2.3