add DeferredCanvas mode to SampleApp
authorreed <reed@google.com>
Tue, 5 May 2015 19:14:45 +0000 (12:14 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 5 May 2015 19:14:45 +0000 (12:14 -0700)
BUG=skia:

Review URL: https://codereview.chromium.org/1129603002

samplecode/SampleApp.cpp
samplecode/SampleApp.h

index 9b5a972ec835346e713a6669b71761db3f8582a7..82d42fdfc45d94ed7d80ec52729ef578f41ad98a 100644 (file)
@@ -15,6 +15,7 @@
 #include "SkCanvas.h"
 #include "SkCommandLineFlags.h"
 #include "SkData.h"
+#include "SkDeferredCanvas.h"
 #include "SkDevice.h"
 #include "SkDocument.h"
 #include "SkGPipe.h"
@@ -181,10 +182,9 @@ public:
 
 #if SK_SUPPORT_GPU
         switch (win->getDeviceType()) {
-            case kRaster_DeviceType:
-                // fallthrough
-            case kPicture_DeviceType:
-                // fallthrough
+            case kRaster_DeviceType:    // fallthrough
+            case kPicture_DeviceType:    // fallthrough
+            case kDeferred_DeviceType:    // fallthrough
             case kGPU_DeviceType:
                 // all these guys use the native backend
                 fBackend = kNativeGL_BackEndType;
@@ -210,10 +210,9 @@ public:
         SkASSERT(NULL == fCurIntf);
         SkAutoTUnref<const GrGLInterface> glInterface;
         switch (win->getDeviceType()) {
-            case kRaster_DeviceType:
-                // fallthrough
-            case kPicture_DeviceType:
-                // fallthrough
+            case kRaster_DeviceType:    // fallthrough
+            case kPicture_DeviceType:   // fallthrough
+            case kDeferred_DeviceType:  // fallthrough
             case kGPU_DeviceType:
                 // all these guys use the native interface
                 glInterface.reset(GrGLCreateNativeInterface());
@@ -673,7 +672,8 @@ static inline SampleWindow::DeviceType cycle_devicetype(SampleWindow::DeviceType
         SampleWindow::kANGLE_DeviceType,
 #endif // SK_ANGLE
 #endif // SK_SUPPORT_GPU
-        SampleWindow::kRaster_DeviceType
+        SampleWindow::kDeferred_DeviceType,
+        SampleWindow::kRaster_DeviceType,
     };
     SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gCT) == SampleWindow::kDeviceTypeCnt, array_size_mismatch);
     return gCT[ct];
@@ -829,7 +829,7 @@ SampleWindow::SampleWindow(void* hwnd, int argc, char** argv, DeviceManager* dev
     int itemID;
 
     itemID =fAppMenu->appendList("Device Type", "Device Type", sinkID, 0,
-                                "Raster", "Picture", "OpenGL",
+                                "Raster", "Picture", "OpenGL", "Deferred",
 #if SK_ANGLE
                                 "ANGLE",
 #endif
@@ -1196,6 +1196,12 @@ SkCanvas* SampleWindow::beforeChildren(SkCanvas* canvas) {
         canvas = fPDFDocument->beginPage(this->width(), this->height());
     } else if (kPicture_DeviceType == fDeviceType) {
         canvas = fRecorder.beginRecording(9999, 9999, NULL, 0);
+    } else if (kDeferred_DeviceType == fDeviceType) {
+        fDeferredSurface.reset(canvas->newSurface(canvas->imageInfo()));
+        if (fDeferredSurface.get()) {
+            fDeferredCanvas.reset(SkDeferredCanvas::Create(fDeferredSurface));
+            canvas = fDeferredCanvas;
+        }
     } else {
         canvas = this->INHERITED::beforeChildren(canvas);
     }
@@ -1284,6 +1290,13 @@ void SampleWindow::afterChildren(SkCanvas* orig) {
         } else {
             picture->playback(orig);
         }
+    } else if (kDeferred_DeviceType == fDeviceType) {
+        SkAutoTUnref<SkImage> image(fDeferredCanvas->newImageSnapshot());
+        if (image) {
+            orig->drawImage(image, 0, 0, NULL);
+        }
+        fDeferredCanvas.reset(NULL);
+        fDeferredSurface.reset(NULL);
     }
 
     // Do this after presentGL and other finishing, rather than in afterChild
@@ -1858,6 +1871,7 @@ static const char* gDeviceTypePrefix[] = {
     "angle: ",
 #endif // SK_ANGLE
 #endif // SK_SUPPORT_GPU
+    "deferred: ",
 };
 SK_COMPILE_ASSERT(SK_ARRAY_COUNT(gDeviceTypePrefix) == SampleWindow::kDeviceTypeCnt,
                   array_size_mismatch);
index 55e3f555a30c15c8f26bb3f7315457ae3b7ea0b8..8fc1a905b1b7cba185fb8ed6148811af97aa4abd 100644 (file)
@@ -22,6 +22,7 @@ class GrRenderTarget;
 
 class SkCanvas;
 class SkData;
+class SkDeferredCanvas;
 class SkDocument;
 class SkEvent;
 class SkTypeface;
@@ -39,7 +40,7 @@ public:
         kANGLE_DeviceType,
 #endif // SK_ANGLE
 #endif // SK_SUPPORT_GPU
-
+        kDeferred_DeviceType,
         kDeviceTypeCnt
     };
 
@@ -161,6 +162,8 @@ private:
     int fCurrIndex;
 
     SkPictureRecorder fRecorder;
+    SkAutoTDelete<SkSurface> fDeferredSurface;
+    SkAutoTDelete<SkDeferredCanvas> fDeferredCanvas;
     SkPath fClipPath;
 
     SkTouchGesture fGesture;