Making SkDeferredCanvas::silentFlush trigger a skippedPendingDrawCommands callback
authorcommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 27 Mar 2014 15:48:52 +0000 (15:48 +0000)
committercommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Thu, 27 Mar 2014 15:48:52 +0000 (15:48 +0000)
The bug was preventing Canvas2DLayerBridge from properly tracking changes
in memory consumption that were triggered by calls to silentFlush.

BUG=344666
TEST=DeferredCanvas unit test
R=senorblanco@google.com, senorblanco@chromium.org

Author: junov@chromium.org

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

git-svn-id: http://skia.googlecode.com/svn/trunk@13965 2bbb7eff-a529-9590-31e7-b0007b416f81

src/utils/SkDeferredCanvas.cpp
tests/DeferredCanvasTest.cpp

index 2c5e530..4836cd7 100644 (file)
@@ -324,9 +324,6 @@ void SkDeferredDevice::skipPendingCommands() {
         if (fPipeController.hasPendingCommands()) {
             fFreshFrame = true;
             flushPendingCommands(kSilent_PlaybackMode);
-            if (fNotificationClient) {
-                fNotificationClient->skippedPendingDrawCommands();
-            }
         }
     }
 }
@@ -363,9 +360,14 @@ void SkDeferredDevice::flushPendingCommands(PlaybackMode playbackMode) {
     }
     fPipeWriter.flushRecording(true);
     fPipeController.playback(kSilent_PlaybackMode == playbackMode);
-    if (playbackMode == kNormal_PlaybackMode && fNotificationClient) {
-        fNotificationClient->flushedDrawCommands();
+    if (fNotificationClient) {
+        if (playbackMode == kSilent_PlaybackMode) {
+            fNotificationClient->skippedPendingDrawCommands();
+        } else {
+            fNotificationClient->flushedDrawCommands();
+        }
     }
+
     fPreviousStorageAllocated = storageAllocatedForRecording();
 }
 
index 0af0c51..13758a7 100644 (file)
@@ -496,6 +496,19 @@ static void TestDeferredCanvasMemoryLimit(skiatest::Reporter* reporter) {
     REPORTER_ASSERT(reporter, 1 == notificationCounter.fFlushedDrawCommandsCount);
 }
 
+static void TestDeferredCanvasSilentFlush(skiatest::Reporter* reporter) {
+    SkAutoTUnref<SkSurface> surface(createSurface(0));
+    SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()));
+
+    NotificationCounter notificationCounter;
+    canvas->setNotificationClient(&notificationCounter);
+
+    canvas->silentFlush(); // will skip the initial clear that was recorded in createSurface
+
+    REPORTER_ASSERT(reporter, 0 == notificationCounter.fFlushedDrawCommandsCount);
+    REPORTER_ASSERT(reporter, 1 == notificationCounter.fSkippedPendingDrawCommandsCount);
+}
+
 static void TestDeferredCanvasBitmapCaching(skiatest::Reporter* reporter) {
     SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(100, 100));
     SkAutoTUnref<SkDeferredCanvas> canvas(SkDeferredCanvas::Create(surface.get()));
@@ -806,6 +819,7 @@ static void TestDeferredCanvasCreateCompatibleDevice(skiatest::Reporter* reporte
 DEF_GPUTEST(DeferredCanvas, reporter, factory) {
     TestDeferredCanvasBitmapAccess(reporter);
     TestDeferredCanvasFlush(reporter);
+    TestDeferredCanvasSilentFlush(reporter);
     TestDeferredCanvasFreshFrame(reporter);
     TestDeferredCanvasMemoryLimit(reporter);
     TestDeferredCanvasBitmapCaching(reporter);