Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1600)

Unified Diff: gm/gradients.cpp

Issue 1259983009: linear gradient with stops discretized gm (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix sign compare Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/gradients.cpp
diff --git a/gm/gradients.cpp b/gm/gradients.cpp
index 02217c9d6587c8644f51b1c6a94a17cd885e149f..ea2b8eae6b90d9b01498dd23392968f618566274 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; )
+
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698