aboutsummaryrefslogtreecommitdiffhomepage
path: root/gm/gradients.cpp
diff options
context:
space:
mode:
authorGravatar caryclark <caryclark@google.com>2015-07-30 12:35:48 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-07-30 12:35:48 -0700
commit159fa572c45cba98d32832c2b59f630063fbb201 (patch)
tree5e01ea9edff4642862cf477b15422189ff8a96bd /gm/gradients.cpp
parent6d901da0ec4b10010eca05114ab8f9564bd04af3 (diff)
linear gradient with stops discretized gm
TBR=reed@google.com BUG=skia:517 Review URL: https://codereview.chromium.org/1259983009
Diffstat (limited to 'gm/gradients.cpp')
-rw-r--r--gm/gradients.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/gm/gradients.cpp b/gm/gradients.cpp
index 02217c9d65..ea2b8eae6b 100644
--- a/gm/gradients.cpp
+++ b/gm/gradients.cpp
@@ -490,4 +490,47 @@ private:
};
DEF_GM( return new RadialGradient4GM; )
+class LinearGradientGM : public GM {
+ SkAutoTUnref<SkShader> fShader[100];
+
+protected:
+ SkString onShortName() override { return SkString("linear_gradient"); }
+ const SkScalar kWidthBump = 30.f;
+ const SkScalar kHeight = 5.f;
+ const SkScalar kMinWidth = 540.f;
+
+ SkISize onISize() override { return SkISize::Make(500, 500); }
+
+ void onOnceBeforeDraw() override {
+ SkPoint pts[2] = { {0, 0}, {0, 0} };
+ const SkColor colors[] = { SK_ColorWHITE, SK_ColorWHITE, 0xFF008200, 0xFF008200,
+ SK_ColorWHITE, SK_ColorWHITE };
+ const SkScalar unitPos[] = { 0, 50, 70, 500, 540 };
+ SkScalar pos[6];
+ pos[5] = 1;
+ for (int index = 0; index < (int) SK_ARRAY_COUNT(fShader); ++index) {
+ pts[1].fX = 500.f + index * kWidthBump;
+ for (int inner = 0; inner < (int) SK_ARRAY_COUNT(unitPos); ++inner) {
+ pos[inner] = unitPos[inner] / (kMinWidth + index * kWidthBump);
+ }
+ fShader[index].reset(SkGradientShader::CreateLinear(pts, colors, pos,
+ SK_ARRAY_COUNT(gColors), SkShader::kClamp_TileMode));
+ }
+ }
+
+ void onDraw(SkCanvas* canvas) override {
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ for (int index = 0; index < (int) SK_ARRAY_COUNT(fShader); ++index) {
+ paint.setShader(fShader[index]);
+ canvas->drawRect(SkRect::MakeLTRB(0, index * kHeight, kMinWidth + index * kWidthBump,
+ (index + 1) * kHeight), paint);
+ }
+ }
+
+private:
+ typedef GM INHERITED;
+};
+DEF_GM( return new LinearGradientGM; )
+
}