add new gms for shallow_gradient, in preparation for improving their quality
authorreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 4 Feb 2013 16:56:15 +0000 (16:56 +0000)
committerreed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 4 Feb 2013 16:56:15 +0000 (16:56 +0000)
git-svn-id: http://skia.googlecode.com/svn/trunk@7544 2bbb7eff-a529-9590-31e7-b0007b416f81

gm/aaclip.cpp
gm/shallowgradient.cpp [new file with mode: 0644]
gyp/gmslides.gypi

index 88e1cd4..f9cecf4 100644 (file)
@@ -9,6 +9,19 @@
 #include "SkCanvas.h"
 #include "SkPath.h"
 
+#include "SkGradientShader.h"
+static void test_shallow_gradient(SkCanvas* canvas, SkScalar width, SkScalar height) {
+    SkColor colors[] = { 0xFF7F7F7F, 0xFF7F7F7F, 0xFF000000 };
+    SkScalar pos[] = { 0, 0.35f, SK_Scalar1 };
+    SkPoint pts[] = { { 0, 0 }, { width, height } };
+    SkShader* s = SkGradientShader::CreateLinear(pts, colors, pos,
+                                                 SK_ARRAY_COUNT(colors),
+                                                 SkShader::kClamp_TileMode);
+    SkPaint paint;
+    paint.setShader(s)->unref();
+    canvas->drawPaint(paint);
+}
+
 #include "SkDashPathEffect.h"
 static void test_giant_dash(SkCanvas* canvas) {
     SkPaint paint;
@@ -37,6 +50,8 @@ static void test_giant_dash(SkCanvas* canvas) {
     }
 }
 
+
+
 // Reproduces bug found here: http://jsfiddle.net/R8Cu5/1/
 //
 #include "SkGradientShader.h"
@@ -207,6 +222,11 @@ protected:
 
     virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
         if (false) {
+            SkRect bounds;
+            canvas->getClipBounds(&bounds);
+            test_shallow_gradient(canvas, bounds.width(), bounds.height()); return;
+        }
+        if (false) {
             test_giant_dash(canvas); return;
         }
         if (false) {
diff --git a/gm/shallowgradient.cpp b/gm/shallowgradient.cpp
new file mode 100644 (file)
index 0000000..672193d
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * 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"
+
+typedef SkShader* (*MakeShaderProc)(const SkColor[], int count, const SkSize&);
+
+static SkShader* shader_linear(const SkColor colors[], int count, const SkSize& size) {
+    SkPoint pts[] = { { 0, 0 }, { size.width(), size.height() } };
+    return SkGradientShader::CreateLinear(pts, colors, NULL, count,
+                                          SkShader::kClamp_TileMode);
+}
+
+static SkShader* shader_radial(const SkColor colors[], int count, const SkSize& size) {
+    SkPoint center = { size.width()/2, size.height()/2 };
+    return SkGradientShader::CreateRadial(center, size.width()/2, colors, NULL, count,
+                                          SkShader::kClamp_TileMode);
+}
+
+static SkShader* shader_conical(const SkColor colors[], int count, const SkSize& size) {
+    SkPoint center = { size.width()/2, size.height()/2 };
+    return SkGradientShader::CreateTwoPointConical(center, size.width()/64,
+                                                   center, size.width()/2,
+                                                   colors, NULL, count,
+                                                   SkShader::kClamp_TileMode);
+}
+
+static SkShader* shader_sweep(const SkColor colors[], int count, const SkSize& size) {
+    return SkGradientShader::CreateSweep(size.width()/2, size.height()/2,
+                                         colors, NULL, count);
+}
+
+class ShallowGradientGM : public skiagm::GM {
+public:
+    ShallowGradientGM(MakeShaderProc proc, const char name[]) : fProc(proc) {
+        fName.printf("shallow_gradient_%s", name);
+    }
+
+protected:
+    virtual SkString onShortName() SK_OVERRIDE {
+        return fName;
+    }
+
+    virtual SkISize onISize() SK_OVERRIDE {
+        return SkISize::Make(800, 800);
+    }
+
+    virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+        const SkColor colors[] = { 0xFF555555, 0xFF444444 };
+        const int colorCount = SK_ARRAY_COUNT(colors);
+
+        SkRect r = { 0, 0, this->width(), this->height() };
+        SkSize size = SkSize::Make(r.width(), r.height());
+
+        SkPaint paint;
+        paint.setShader(fProc(colors, colorCount, size));
+        canvas->drawRect(r, paint);
+    }
+
+private:
+    MakeShaderProc fProc;
+    SkString fName;
+
+    typedef skiagm::GM INHERITED;
+};
+
+///////////////////////////////////////////////////////////////////////////////
+
+DEF_GM( return new ShallowGradientGM(shader_linear, "linear"); )
+DEF_GM( return new ShallowGradientGM(shader_radial, "radial"); )
+DEF_GM( return new ShallowGradientGM(shader_conical, "conical"); )
+DEF_GM( return new ShallowGradientGM(shader_sweep, "sweep"); )
index 8d772f3..70a77d2 100644 (file)
@@ -72,6 +72,7 @@
     '../gm/shadertext2.cpp',
     '../gm/shadertext3.cpp',
     '../gm/shadows.cpp',
+    '../gm/shallowgradient.cpp',
     '../gm/simpleaaclip.cpp',
     '../gm/spritebitmap.cpp',
     '../gm/srcmode.cpp',