Index: gm/gradient_matrix.cpp |
diff --git a/gm/gradient_matrix.cpp b/gm/gradient_matrix.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8915b1699c709c2cc2afe36897c47801ba77eddf |
--- /dev/null |
+++ b/gm/gradient_matrix.cpp |
@@ -0,0 +1,111 @@ |
+/* |
+ * Copyright 2013 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+#include "gm.h" |
+#include "SkGradientShader.h" |
+ |
+static const SkColor gColors[] = { |
+ SK_ColorRED, SK_ColorYELLOW |
+}; |
+static const SkScalar gPosAll[] = { |
+ 0, SK_Scalar1 |
+}; |
+ |
+static SkShader* SimpleGradient(const SkPoint pts[2]) { |
vandebo (ex-Chrome)
2013/06/11 05:15:10
static helper functions are named in hacker case:
ducky
2013/06/11 21:35:32
Done.
|
+ return SkGradientShader::CreateLinear(pts, gColors, gPosAll, |
+ 2, SkShader::kClamp_TileMode, NULL); |
vandebo (ex-Chrome)
2013/06/11 05:15:10
nit: put "2" on the previous line.
ducky
2013/06/11 21:35:32
Done.
|
+} |
+ |
+namespace skiagm { |
+ |
+class GradientMatrixGM : public GM { |
+public: |
+ GradientMatrixGM() { |
+ this->setBGColor(0xFFDDDDDD); |
+ } |
+ |
+protected: |
+ SkString onShortName() { |
+ return SkString("gradient_matrix"); |
+ } |
+ |
+ virtual SkISize onISize() { return make_isize(800, 400); } |
vandebo (ex-Chrome)
2013/06/11 05:15:10
line wrap.
ducky
2013/06/11 21:35:32
Done.
|
+ |
+ virtual void onDraw(SkCanvas* canvas) { |
+ const int TESTGRID_X = 200; |
vandebo (ex-Chrome)
2013/06/11 05:15:10
Should be SkScalar instead of int (applies in mult
ducky
2013/06/11 21:35:32
Done.
|
+ const int TESTGRID_Y = 200; |
+ |
+ canvas->save(); |
+ |
+ testGrad(canvas, 0, 0, 1, 0); |
+ canvas->translate(TESTGRID_X, 0); |
+ testGrad(canvas, 0, 0, 0, 1); |
+ canvas->translate(TESTGRID_X, 0); |
+ testGrad(canvas, 1, 0, 0, 0); |
+ canvas->translate(TESTGRID_X, 0); |
+ testGrad(canvas, 0, 1, 0, 0); |
+ |
+ canvas->restore(); |
+ canvas->translate(0, TESTGRID_Y); |
+ canvas->save(); |
+ |
+ testGrad(canvas, 0, 0, 1, 1); |
+ canvas->translate(TESTGRID_X, 0); |
+ testGrad(canvas, 1, 1, 0, 0); |
+ canvas->translate(TESTGRID_X, 0); |
+ testGrad(canvas, 1, 0, 0, 1); |
+ canvas->translate(TESTGRID_X, 0); |
+ testGrad(canvas, 0, 1, 1, 0); |
+ } |
+ |
+ virtual void simpleGrad(SkCanvas* canvas) { |
vandebo (ex-Chrome)
2013/06/11 05:15:10
This method is unused, remove.
ducky
2013/06/11 21:35:32
Done.
|
+ SkPoint pts[2] = { |
+ { 100, 0 }, |
+ { 0, 0 } |
+ }; |
+ SkMatrix shaderMat = SkMatrix(); |
+ shaderMat.setAll(1, 0, 0, |
+ 0, 1, 0, |
+ 0, 0, 1); |
+ SkRect rectGrad = { 0, 0, 100, 100 }; // very simple numbers |
+ |
+ SkShader* shader = SimpleGradient(pts); |
+ shader->setLocalMatrix(shaderMat); |
+ SkPaint paint; |
+ paint.setAntiAlias(true); |
+ paint.setShader(shader); |
+ canvas->drawRect(rectGrad, paint); |
+ shader->unref(); |
+ } |
+ |
+ virtual void testGrad(SkCanvas* canvas, int x1, int y1, int x2, int y2) { |
vandebo (ex-Chrome)
2013/06/11 05:15:10
not virtual. In fact, it can be a static helper f
ducky
2013/06/11 21:35:32
Done.
|
+ SkPoint pts[2] = { |
vandebo (ex-Chrome)
2013/06/11 05:15:10
why not just pass SkPoints[2] ?
ducky
2013/06/11 21:35:32
Done.
|
+ { x1, y1 }, |
+ { x2, y2 } |
+ }; |
+ SkMatrix shaderMat = SkMatrix(); |
+ shaderMat.setAll(138, 0, 43, |
+ 0, 106, 61, |
+ 0, 0, 1); |
+ SkRect rectGrad = { 43, 61, 181, 167 }; // some nice prime numbers |
+ |
+ SkShader* shader = SimpleGradient(pts); |
+ shader->setLocalMatrix(shaderMat); |
+ SkPaint paint; |
+ paint.setAntiAlias(true); |
vandebo (ex-Chrome)
2013/06/11 05:15:10
remove - not needed for this test.
ducky
2013/06/11 21:35:32
Done.
|
+ paint.setShader(shader); |
+ canvas->drawRect(rectGrad, paint); |
+ shader->unref(); |
+ } |
+ |
+private: |
+ typedef GM INHERITED; |
+}; |
+ |
+static GM* MyFactory(void*) { return new GradientMatrixGM; } |
+static GMRegistry reg(MyFactory); |
+ |
+} |