Added tests for radial gradients with shader matrices


Fixed a bug with linear gradient PDF matrices and added test cases

R=vandebo@chromium.org, reed@google.com

Author: richardlin@chromium.org

Review URL: https://chromiumcodereview.appspot.com/16467002

git-svn-id: http://skia.googlecode.com/svn/trunk@9554 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gm/gradient_matrix.cpp b/gm/gradient_matrix.cpp
index cc1683e..c1ff65e 100644
--- a/gm/gradient_matrix.cpp
+++ b/gm/gradient_matrix.cpp
@@ -37,6 +37,19 @@
     {{0, 1}, {1, 0}}
 };
 
+static const SkPoint radialPts[][2] = {
+    {{0,   0.5}, {1,   0.5}},
+    {{0.5, 0  }, {0.5, 1  }},
+    {{1,   0.5}, {0,   0.5}},
+    {{0.5, 1  }, {0.5, 0  }},
+
+    {{0, 0}, {1, 1}},
+    {{1, 1}, {0, 0}},
+    {{1, 0}, {0, 1}},
+    {{0, 1}, {1, 0}}
+};
+
+
 static const SkScalar TESTGRID_X = 200;    // pixels allocated to each image in x dimension
 static const SkScalar TESTGRID_Y = 200;    // pixels allocated to each image in y dimension
 
@@ -47,8 +60,17 @@
                                           SkShader::kClamp_TileMode, NULL);
 }
 
+static SkShader* make_radial_gradient(const SkPoint pts[2]) {
+    SkPoint center;
+    center.set(SkScalarAve(pts[0].fX, pts[1].fX),
+               SkScalarAve(pts[0].fY, pts[1].fY));
+    float radius = (center - pts[0]).length();
+    return SkGradientShader::CreateRadial(center, radius, gColors, NULL, SK_ARRAY_COUNT(gColors),
+                                          SkShader::kClamp_TileMode, NULL);
+}
+
 static void draw_gradients(SkCanvas* canvas, SkShader* (*makeShader)(const SkPoint[2]),
-                    const SkPoint ptsArray[][2], int numImages) {
+                           const SkPoint ptsArray[][2], int numImages) {
     // Use some nice prime numbers for the rectangle and matrix with
     // different scaling along the x and y axes (which is the bug this
     // test addresses, where incorrect order of operations mixed up the axes)
@@ -101,6 +123,11 @@
     virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
         draw_gradients(canvas, &make_linear_gradient,
                       linearPts, SK_ARRAY_COUNT(linearPts));
+
+        canvas->translate(0, TESTGRID_Y);
+
+        draw_gradients(canvas, &make_radial_gradient,
+                      radialPts, SK_ARRAY_COUNT(radialPts));
     }
 
 private: