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

Unified Diff: gm/gradient_matrix.cpp

Issue 16094020: Fixed a bug with linear gradient PDF matrices and added test cases (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 6 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 | gyp/gmslides.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
+
+}
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698