Get rid of createRenderTargetFrom3DAPIState and associated glGets necessary to support it.

Review URL: http://codereview.appspot.com/4928041/



git-svn-id: http://skia.googlecode.com/svn/trunk@2144 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp
index 5252e80..6f7f67b 100644
--- a/gm/gmmain.cpp
+++ b/gm/gmmain.cpp
@@ -6,8 +6,16 @@
  * found in the LICENSE file.
  */
 #include "gm.h"
+
+#include "GrContext.h"
+#include "GrRenderTarget.h"
+
 #include "SkColorPriv.h"
 #include "SkData.h"
+#include "SkDevice.h"
+#include "SkEGLContext.h"
+#include "SkGpuCanvas.h"
+#include "SkGpuDevice.h"
 #include "SkGraphics.h"
 #include "SkImageDecoder.h"
 #include "SkImageEncoder.h"
@@ -15,12 +23,6 @@
 #include "SkStream.h"
 #include "SkRefCnt.h"
 
-#include "GrContext.h"
-#include "SkGpuCanvas.h"
-#include "SkGpuDevice.h"
-#include "SkEGLContext.h"
-#include "SkDevice.h"
-
 #ifdef SK_SUPPORT_PDF
     #include "SkPDFDevice.h"
     #include "SkPDFDocument.h"
@@ -228,6 +230,7 @@
 // halt.
 static bool generate_image(GM* gm, const ConfigData& gRec,
                            GrContext* context,
+                           GrRenderTarget* rt,
                            SkBitmap* bitmap) {
     SkISize size (gm->getISize());
     setup_bitmap(gRec, size, bitmap);
@@ -239,8 +242,6 @@
         if (NULL == context) {
             return false;
         }
-        // not a real object, so don't unref it
-        GrRenderTarget* rt = SkGpuDevice::Current3DApiRenderTarget();
         SkGpuCanvas gc(context, rt);
         gc.setDevice(new SkGpuDevice(context, rt))->unref();
         gm->draw(&gc);
@@ -406,14 +407,15 @@
                          const char readPath [],
                          const char diffPath [],
                          GrContext* context,
+                         GrRenderTarget* rt,
                          SkBitmap* bitmap) {
     SkDynamicMemoryWStream pdf;
 
     if (gRec.fBackend == kRaster_Backend ||
-            gRec.fBackend == kGPU_Backend) {
+        gRec.fBackend == kGPU_Backend) {
         // Early exit if we can't generate the image, but this is
         // expected in some cases, so don't report a test failure.
-        if (!generate_image(gm, gRec, context, bitmap)) {
+        if (!generate_image(gm, gRec, context, rt, bitmap)) {
             return true;
         }
     } else if (gRec.fBackend == kPDF_Backend) {
@@ -555,11 +557,26 @@
     }
     // setup a GL context for drawing offscreen
     SkEGLContext eglContext;
+    GrRenderTarget* rt = NULL;
     if (eglContext.init(maxW, maxH)) {
         gGrContext = GrContext::CreateGLShaderContext();
+        if (NULL != gGrContext) {
+            GrPlatformSurfaceDesc desc;
+            desc.reset();
+            desc.fConfig = kRGBA_8888_GrPixelConfig;
+            desc.fWidth = maxW;
+            desc.fHeight = maxH;
+            desc.fStencilBits = 8;
+            desc.fPlatformRenderTarget = eglContext.getFBOID();
+            desc.fSurfaceType = kRenderTarget_GrPlatformSurfaceType;
+            rt = static_cast<GrRenderTarget*>(gGrContext->createPlatformSurface(desc));
+            if (NULL == rt) {
+                gGrContext->unref();
+                gGrContext = NULL;
+            }
+        }
     }
 
-
     if (readPath) {
         fprintf(stderr, "reading from %s\n", readPath);
     } else if (writePath) {
@@ -585,7 +602,7 @@
         for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); i++) {
             bool testSuccess = test_drawing(gm, gRec[i],
                          writePath, readPath, diffPath, gGrContext,
-                         &forwardRenderedBitmap);
+                         rt, &forwardRenderedBitmap);
             overallSuccess &= testSuccess;
 
             if (doReplay && testSuccess) {