add test for degenerate 2point gradients (needs pdf and gpu fixes)



git-svn-id: http://skia.googlecode.com/svn/trunk@1727 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp
index 0827ae6..ca49d19 100644
--- a/gm/gmmain.cpp
+++ b/gm/gmmain.cpp
@@ -316,6 +316,11 @@
                                              renderModeDescriptor);
     } else {
         fprintf(stderr, "FAILED to read %s\n", path.c_str());
+        // we lie here, and report succes, since we're just missing a master
+        // image. This way we can check in new tests, and not report failure.
+        // A real failure is to draw *differently* from the master image, but
+        // that's not the case here.
+        success = true;
     }
     return success;
 }
diff --git a/gm/gradients.cpp b/gm/gradients.cpp
index 26eee9d..1cab7bc 100644
--- a/gm/gradients.cpp
+++ b/gm/gradients.cpp
@@ -80,7 +80,7 @@
         return SkString("gradients");
     }
     
-	SkISize onISize() { return make_isize(640, 510); }
+    virtual SkISize onISize() { return make_isize(640, 510); }
     
     void drawBG(SkCanvas* canvas) {
         canvas->drawColor(0xFFDDDDDD);
@@ -117,10 +117,65 @@
     typedef GM INHERITED;
 };
 
+/*
+ Inspired by this <canvas> javascript, where we need to detect that we are not
+ solving a quadratic equation, but must instead solve a linear (since our X^2
+ coefficient is 0)
+
+ ctx.fillStyle = '#f00';
+ ctx.fillRect(0, 0, 100, 50);
+ 
+ var g = ctx.createRadialGradient(-80, 25, 70, 0, 25, 150);
+ g.addColorStop(0, '#f00');
+ g.addColorStop(0.01, '#0f0');
+ g.addColorStop(0.99, '#0f0');
+ g.addColorStop(1, '#f00');
+ ctx.fillStyle = g;
+ ctx.fillRect(0, 0, 100, 50);
+ */
+class GradientsDegenrate2PointGM : public GM {
+public:
+    GradientsDegenrate2PointGM() {}
+    
+protected:
+    SkString onShortName() {
+        return SkString("gradients_degenerate_2pt");
+    }
+    
+	virtual SkISize onISize() { return make_isize(320, 320); }
+    
+    void drawBG(SkCanvas* canvas) {
+        canvas->drawColor(SK_ColorBLUE);
+    }
+    
+    virtual void onDraw(SkCanvas* canvas) {
+        this->drawBG(canvas);
+        
+        SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorGREEN, SK_ColorRED };
+        SkScalar pos[] = { 0, SkFloatToScalar(0.01f), SkFloatToScalar(0.99f), SK_Scalar1 };
+        SkPoint c0 = { -80, 25 };
+        SkScalar r0 = 70;
+        SkPoint c1 = { 0, 25 };
+        SkScalar r1 = 150;
+        SkShader* s = SkGradientShader::CreateTwoPointRadial(c0, r0, c1, r1, colors,
+                                                             pos, SK_ARRAY_COUNT(pos),
+                                                             SkShader::kClamp_TileMode);
+        SkPaint paint;
+        paint.setShader(s)->unref();
+        canvas->drawPaint(paint);
+    }
+    
+private:
+    typedef GM INHERITED;
+};
+
 ///////////////////////////////////////////////////////////////////////////////
 
 static GM* MyFactory(void*) { return new GradientsGM; }
 static GMRegistry reg(MyFactory);
 
+static GM* MyFactory2(void*) { return new GradientsDegenrate2PointGM; }
+static GMRegistry reg2(MyFactory2);
+
 }