flag the GM if we're in deferred-canvas mode, to work-around bug trying to
get the context from its device.



git-svn-id: http://skia.googlecode.com/svn/trunk@6452 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gm/gm.cpp b/gm/gm.cpp
index 2992b7d..1ccec9f 100644
--- a/gm/gm.cpp
+++ b/gm/gm.cpp
@@ -12,6 +12,7 @@
 
 GM::GM() {
     fBGColor = SK_ColorWHITE;
+    fCanvasIsDeferred = false;
 }
 GM::~GM() {}
 
diff --git a/gm/gm.h b/gm/gm.h
index e98dda5..057325e 100644
--- a/gm/gm.h
+++ b/gm/gm.h
@@ -71,6 +71,11 @@
             gResourcePath = resourcePath;
         }
 
+        bool isCanvasDeferred() const { return fCanvasIsDeferred; }
+        void setCanvasIsDeferred(bool isDeferred) {
+            fCanvasIsDeferred = isDeferred;
+        }
+
     protected:
         static SkString gResourcePath;
 
@@ -84,6 +89,7 @@
     private:
         SkString fShortName;
         SkColor  fBGColor;
+        bool     fCanvasIsDeferred; // work-around problem in srcmode.cpp
     };
 
     typedef SkTRegistry<GM*, void*> GMRegistry;
diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp
index 39b8b17..d4d2154 100644
--- a/gm/gmmain.cpp
+++ b/gm/gmmain.cpp
@@ -379,13 +379,14 @@
         }
     }
 
-    static void invokeGM(GM* gm, SkCanvas* canvas, bool isPDF = false) {
+    static void invokeGM(GM* gm, SkCanvas* canvas, bool isPDF, bool isDeferred) {
         SkAutoCanvasRestore acr(canvas, true);
 
         if (!isPDF) {
             canvas->concat(gm->getInitialTransform());
         }
         installFilter(canvas);
+        gm->setCanvasIsDeferred(isDeferred);
         gm->draw(canvas);
         canvas->setDrawFilter(NULL);
     }
@@ -407,7 +408,7 @@
             } else {
                 canvas.reset(new SkCanvas(device));
             }
-            invokeGM(gm, canvas);
+            invokeGM(gm, canvas, false, deferred);
             canvas->flush();
         }
 #if SK_SUPPORT_GPU
@@ -421,7 +422,7 @@
             } else {
                 canvas.reset(new SkCanvas(device));
             }
-            invokeGM(gm, canvas);
+            invokeGM(gm, canvas, false, deferred);
             // the device is as large as the current rendertarget, so
             // we explicitly only readback the amount we expect (in
             // size) overwrite our previous allocation
@@ -463,7 +464,7 @@
         SkAutoUnref aur(dev);
 
         SkCanvas c(dev);
-        invokeGM(gm, &c, true);
+        invokeGM(gm, &c, true, false);
 
         SkPDFDocument doc;
         doc.appendPage(dev);
@@ -489,7 +490,7 @@
         SkCanvas c(dev);
         dev->beginPortfolio(&xps);
         dev->beginSheet(unitsPerMeter, pixelsPerMeter, trimSize);
-        invokeGM(gm, &c);
+        invokeGM(gm, &c, false, false);
         dev->endSheet();
         dev->endPortfolio();
 
@@ -621,7 +622,7 @@
         SkPicture* pict = new SkPicture;
         SkISize size = gm->getISize();
         SkCanvas* cv = pict->beginRecording(size.width(), size.height());
-        invokeGM(gm, cv);
+        invokeGM(gm, cv, false, false);
         pict->endRecording();
 
         return pict;
@@ -722,7 +723,7 @@
             SkGPipeWriter writer;
             SkCanvas* pipeCanvas = writer.startRecording(
               &pipeController, gPipeWritingFlagCombos[i].flags);
-            invokeGM(gm, pipeCanvas);
+            invokeGM(gm, pipeCanvas, false, false);
             writer.endRecording();
             SkString string("-pipe");
             string.append(gPipeWritingFlagCombos[i].name);
@@ -749,7 +750,7 @@
             SkGPipeWriter writer;
             SkCanvas* pipeCanvas = writer.startRecording(
               &pipeController, gPipeWritingFlagCombos[i].flags);
-            invokeGM(gm, pipeCanvas);
+            invokeGM(gm, pipeCanvas, false, false);
             writer.endRecording();
             SkString string("-tiled pipe");
             string.append(gPipeWritingFlagCombos[i].name);
diff --git a/gm/srcmode.cpp b/gm/srcmode.cpp
index 6eba098..c99a6b2 100644
--- a/gm/srcmode.cpp
+++ b/gm/srcmode.cpp
@@ -115,7 +115,8 @@
         }
     }
 
-    static SkSurface* compat_surface(SkCanvas* canvas, const SkISize& size) {
+    static SkSurface* compat_surface(SkCanvas* canvas, const SkISize& size,
+                                     bool skipGPU) {
         SkImage::Info info = {
             size.width(),
             size.height(),
@@ -124,7 +125,7 @@
         };
 #if SK_SUPPORT_GPU
         SkDevice* dev = canvas->getDevice();
-        if (dev->accessRenderTarget()) {
+        if (!skipGPU && dev->accessRenderTarget()) {
             SkGpuDevice* gd = (SkGpuDevice*)dev;
             GrContext* ctx = gd->context();
             return SkSurface::NewRenderTarget(ctx, info, 0);
@@ -134,7 +135,8 @@
     }
 
     virtual void onDraw(SkCanvas* canvas) {
-        SkAutoTUnref<SkSurface> surf(compat_surface(canvas, this->getISize()));
+        SkAutoTUnref<SkSurface> surf(compat_surface(canvas, this->getISize(),
+                                                    this->isCanvasDeferred()));
         surf->getCanvas()->drawColor(SK_ColorWHITE);
         this->drawContent(surf->getCanvas());
         surf->draw(canvas, 0, 0, NULL);