Dirty commit so Brian can see changes.
authorkeyar@chromium.org <keyar@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 20 Aug 2012 15:03:29 +0000 (15:03 +0000)
committerkeyar@chromium.org <keyar@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 20 Aug 2012 15:03:29 +0000 (15:03 +0000)
git-svn-id: http://skia.googlecode.com/svn/trunk@5171 2bbb7eff-a529-9590-31e7-b0007b416f81

gyp/tools.gyp
tools/PictureRenderer.cpp
tools/PictureRenderer.h
tools/render_pictures_main.cpp

index 3910b70..799c960 100644 (file)
       ],
      'dependencies': [
         'core.gyp:core',
+        'gpu.gyp:gr',
+        'gpu.gyp:skgr',
         'tools.gyp:picture_utils',
      ],
     },
index f0aba9f..e9e14de 100644 (file)
@@ -8,6 +8,13 @@
 #include "SkTypes.h"
 #include "picture_utils.h"
 
+#if SK_SUPPORT_GPU
+#include "gl/GrGLInterface.h"
+#include "GrContext.h"
+#include "SkGpuDevice.h"
+#include "GrContextFactory.h"
+#endif
+
 namespace sk_tools {
 
 enum {
@@ -28,9 +35,32 @@ void PictureRenderer::init(SkPicture* pict) {
     }
 
     fPicture = pict;
-    SkBitmap bitmap;
-    sk_tools::setup_bitmap(&bitmap, fPicture->width(), fPicture->height());
-    fCanvas.reset(SkNEW_ARGS(SkCanvas, (bitmap)));
+    switch(fDeviceType) {
+        case kBitmap_DeviceType: {
+            SkBitmap bitmap;
+            sk_tools::setup_bitmap(&bitmap, fPicture->width(), fPicture->height());
+            fCanvas.reset(SkNEW_ARGS(SkCanvas, (bitmap)));
+            break;
+        }
+#if SK_SUPPORT_GPU
+        case kGPU_DeviceType: {
+//            const GrGLInterface* interface = GrGLCreateNativeInterface();
+//            GrContext* context = GrContext::Create(kOpenGL_Shaders_GrEngine,
+//                                                   (GrPlatform3DContext) interface);
+            fGLContext = new SkNativeGLContext();
+            SkASSERT(fGLContext->init(pict->width(), pict->height()));
+            GrContextFactory factory;
+            GrContext* context = factory.get(GrContextFactory::kNative_GLContextType);
+            SkAutoTUnref<SkGpuDevice> device(SkNEW_ARGS(SkGpuDevice,
+                                                    (context, SkBitmap::kARGB_8888_Config,
+                                                    pict->width(), pict->height())));
+            fCanvas.reset(SkNEW_ARGS(SkCanvas, (device.get())));
+            break;
+        }
+#endif
+        default:
+            SkASSERT(0);
+    }
 }
 
 void PictureRenderer::end() {
index f9b4c26..a8975bf 100644 (file)
@@ -13,6 +13,7 @@
 
 class SkBitmap;
 class SkCanvas;
+class SkGLContext;
 class SkPicture;
 
 namespace sk_tools {
@@ -27,10 +28,29 @@ public:
         return fCanvas.get();
     }
 
-    PictureRenderer() : fPicture(NULL){}
+    void setUseBitmapDevice() {
+        fDeviceType=kBitmap_DeviceType;
+    }
+
+#if SK_SUPPORT_GPU
+    void setUseGpuDevice() {
+        fDeviceType = kGPU_DeviceType;
+    }
+#endif
+
+    PictureRenderer() : fPicture(NULL), fDeviceType(kBitmap_DeviceType){}
 protected:
+    enum SkDeviceTypes {
+        kBitmap_DeviceType,
+#if SK_SUPPORT_GPU
+        kGPU_DeviceType
+#endif
+    };
+
     SkAutoTUnref<SkCanvas> fCanvas;
     SkPicture* fPicture;
+    SkDeviceTypes fDeviceType;
+    SkGLContext* fGLContext;
 
 private:
     typedef SkRefCnt INHERITED;
index 86de9ba..e1a1eff 100644 (file)
@@ -220,6 +220,8 @@ static void parse_commandline(int argc, char* const argv[], SkTArray<SkString>*
     if (NULL == renderer) {
         renderer = SkNEW(sk_tools::SimplePictureRenderer);
     }
+
+    renderer->setUseGpuDevice();
 }
 
 int main(int argc, char* const argv[]) {