Add support for using ANGLE in bench_pictures.

BUG=https://code.google.com/p/skia/issues/detail?id=1012

Other cleanups:
Remove setDeviceType from PictureBenchmark, since it is unnecessary.
Dereference PictureRenderer::fGrContext when done with it.
Make PictureRenderer::fGrContext and PictureRenderer::fGrContextFactory private, since they are not used by subclasses.

Review URL: https://codereview.appspot.com/7314063

git-svn-id: http://skia.googlecode.com/svn/trunk@7677 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tools/PictureRenderer.h b/tools/PictureRenderer.h
index df38faa..b4b28f0 100644
--- a/tools/PictureRenderer.h
+++ b/tools/PictureRenderer.h
@@ -39,9 +39,12 @@
 
 public:
     enum SkDeviceTypes {
+#if SK_ANGLE
+        kAngle_DeviceType,
+#endif
         kBitmap_DeviceType,
 #if SK_SUPPORT_GPU
-        kGPU_DeviceType
+        kGPU_DeviceType,
 #endif
     };
 
@@ -117,8 +120,44 @@
      */
     void resetState(bool callFinish);
 
-    void setDeviceType(SkDeviceTypes deviceType) {
+    /**
+     * Set the backend type. Returns true on success and false on failure.
+     */
+    bool setDeviceType(SkDeviceTypes deviceType) {
         fDeviceType = deviceType;
+#if SK_SUPPORT_GPU
+        // In case this function is called more than once
+        SkSafeUnref(fGrContext);
+        fGrContext = NULL;
+        // Set to Native so it will have an initial value.
+        GrContextFactory::GLContextType glContextType = GrContextFactory::kNative_GLContextType;
+#endif
+        switch(deviceType) {
+            case kBitmap_DeviceType:
+                return true;
+#if SK_SUPPORT_GPU
+            case kGPU_DeviceType:
+                // Already set to GrContextFactory::kNative_GLContextType, above.
+                break;
+#if SK_ANGLE
+            case kAngle_DeviceType:
+                glContextType = GrContextFactory::kANGLE_GLContextType;
+                break;
+#endif
+#endif
+            default:
+                // Invalid device type.
+                return false;
+        }
+#if SK_SUPPORT_GPU
+        fGrContext = fGrContextFactory.get(glContextType);
+        if (NULL == fGrContext) {
+            return false;
+        } else {
+            fGrContext->ref();
+            return true;
+        }
+#endif
     }
 
     void setDrawFilters(DrawFilterFlags const * const filters, const SkString& configName) {
@@ -156,26 +195,55 @@
         } else if (kTileGrid_BBoxHierarchyType == fBBoxHierarchyType) {
             config.append("_grid");
         }
+        switch (fDeviceType) {
 #if SK_SUPPORT_GPU
-        if (this->isUsingGpuDevice()) {
-            config.append("_gpu");
-        }
+            case kGPU_DeviceType:
+                config.append("_gpu");
+                break;
+#if SK_ANGLE
+            case kAngle_DeviceType:
+                config.append("_angle");
+                break;
 #endif
+#endif
+            default:
+                // Assume that no extra info means bitmap.
+                break;
+        }
         config.append(fDrawFiltersConfig.c_str());
         return config;
     }
 
 #if SK_SUPPORT_GPU
     bool isUsingGpuDevice() {
-        return kGPU_DeviceType == fDeviceType;
+        switch (fDeviceType) {
+            case kGPU_DeviceType:
+                // fall through
+#if SK_ANGLE
+            case kAngle_DeviceType:
+#endif
+                return true;
+            default:
+                return false;
+        }
     }
 
     SkGLContext* getGLContext() {
-        if (this->isUsingGpuDevice()) {
-            return fGrContextFactory.getGLContext(GrContextFactory::kNative_GLContextType);
-        } else {
-            return NULL;
+        GrContextFactory::GLContextType glContextType
+                = GrContextFactory::kNull_GLContextType;
+        switch(fDeviceType) {
+            case kGPU_DeviceType:
+                glContextType = GrContextFactory::kNative_GLContextType;
+                break;
+#if SK_ANGLE
+            case kAngle_DeviceType:
+                glContextType = GrContextFactory::kANGLE_GLContextType;
+                break;
+#endif
+            default:
+                return NULL;
         }
+        return fGrContextFactory.getGLContext(glContextType);
     }
 
     GrContext* getGrContext() {
@@ -190,7 +258,7 @@
         , fGridWidth(0)
         , fGridHeight(0)
 #if SK_SUPPORT_GPU
-        , fGrContext(fGrContextFactory.get(GrContextFactory::kNative_GLContextType))
+        , fGrContext(NULL)
 #endif
         , fScaleFactor(SK_Scalar1)
         {
@@ -198,6 +266,12 @@
             fViewport.set(0, 0);
         }
 
+#if SK_SUPPORT_GPU
+    virtual ~PictureRenderer() {
+        SkSafeUnref(fGrContext);
+    }
+#endif
+
 protected:
     SkAutoTUnref<SkCanvas> fCanvas;
     SkPicture*             fPicture;
@@ -207,11 +281,6 @@
     SkString               fDrawFiltersConfig;
     int                    fGridWidth, fGridHeight; // used when fBBoxHierarchyType is TileGrid
 
-#if SK_SUPPORT_GPU
-    GrContextFactory fGrContextFactory;
-    GrContext* fGrContext;
-#endif
-
     void buildBBoxHierarchy();
 
     /**
@@ -239,6 +308,10 @@
 private:
     SkISize                fViewport;
     SkScalar               fScaleFactor;
+#if SK_SUPPORT_GPU
+    GrContextFactory       fGrContextFactory;
+    GrContext*             fGrContext;
+#endif
 
     virtual SkString getConfigNameInternal() = 0;