Adding virtual method to SkDeferredCanvas::NotificationClient for signaling when commands are skipped due to the skip on clear optimization.
TEST=DeferredCanvas unit test
BUG=http://code.google.com/p/chromium/issues/detail?id=116840
Review URL: https://codereview.appspot.com/6590050
git-svn-id: http://skia.googlecode.com/svn/trunk@5747 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/utils/SkDeferredCanvas.h b/include/utils/SkDeferredCanvas.h
index f5674d1..97848f1 100644
--- a/include/utils/SkDeferredCanvas.h
+++ b/include/utils/SkDeferredCanvas.h
@@ -203,6 +203,13 @@
*/
virtual void flushedDrawCommands() {}
+ /**
+ * Called after pending draw commands have been skipped, meaning
+ * that they were optimized-out because the canvas is cleared
+ * or completely overwritten by the command currently being recorded.
+ */
+ virtual void skippedPendingDrawCommands() {}
+
private:
typedef SkRefCnt INHERITED;
};
diff --git a/src/utils/SkDeferredCanvas.cpp b/src/utils/SkDeferredCanvas.cpp
index a854d8c..eaba503 100644
--- a/src/utils/SkDeferredCanvas.cpp
+++ b/src/utils/SkDeferredCanvas.cpp
@@ -381,6 +381,9 @@
if (!fRecordingCanvas->isDrawingToLayer() && fPipeController.hasPendingCommands()) {
fFreshFrame = true;
flushPendingCommands(kSilent_PlaybackMode);
+ if (fNotificationClient) {
+ fNotificationClient->skippedPendingDrawCommands();
+ }
}
}
diff --git a/tests/DeferredCanvasTest.cpp b/tests/DeferredCanvasTest.cpp
index 95b3f73..f0b4ad2 100644
--- a/tests/DeferredCanvasTest.cpp
+++ b/tests/DeferredCanvasTest.cpp
@@ -217,7 +217,8 @@
class NotificationCounter : public SkDeferredCanvas::NotificationClient {
public:
NotificationCounter() {
- fPrepareForDrawCount = fStorageAllocatedChangedCount = fFlushedDrawCommandsCount = 0;
+ fPrepareForDrawCount = fStorageAllocatedChangedCount =
+ fFlushedDrawCommandsCount = fSkippedPendingDrawCommandsCount = 0;
}
virtual void prepareForDraw() SK_OVERRIDE {
@@ -229,10 +230,14 @@
virtual void flushedDrawCommands() SK_OVERRIDE {
fFlushedDrawCommandsCount++;
}
+ virtual void skippedPendingDrawCommands() SK_OVERRIDE {
+ fSkippedPendingDrawCommandsCount++;
+ }
int fPrepareForDrawCount;
int fStorageAllocatedChangedCount;
int fFlushedDrawCommandsCount;
+ int fSkippedPendingDrawCommandsCount;
};
static void TestDeferredCanvasBitmapCaching(skiatest::Reporter* reporter) {
@@ -313,6 +318,26 @@
sourceImages[1].notifyPixelsChanged();
canvas.drawBitmap(sourceImages[1], 0, 0, NULL);
REPORTER_ASSERT(reporter, canvas.storageAllocatedForRecording() > 2*bitmapSize);
+
+ // Verify that nothing in this test caused commands to be skipped
+ REPORTER_ASSERT(reporter, 0 == notificationCounter.fSkippedPendingDrawCommandsCount);
+}
+
+static void TestDeferredCanvasSkip(skiatest::Reporter* reporter) {
+ SkBitmap store;
+ store.setConfig(SkBitmap::kARGB_8888_Config, 100, 100);
+ store.allocPixels();
+ SkDevice device(store);
+ NotificationCounter notificationCounter;
+ SkDeferredCanvas canvas(&device);
+ canvas.setNotificationClient(¬ificationCounter);
+ canvas.clear(0x0);
+ REPORTER_ASSERT(reporter, 1 == notificationCounter.fSkippedPendingDrawCommandsCount);
+ REPORTER_ASSERT(reporter, 0 == notificationCounter.fFlushedDrawCommandsCount);
+ canvas.flush();
+ REPORTER_ASSERT(reporter, 1 == notificationCounter.fSkippedPendingDrawCommandsCount);
+ REPORTER_ASSERT(reporter, 1 == notificationCounter.fFlushedDrawCommandsCount);
+
}
static void TestDeferredCanvas(skiatest::Reporter* reporter) {
@@ -321,6 +346,7 @@
TestDeferredCanvasFreshFrame(reporter);
TestDeferredCanvasMemoryLimit(reporter);
TestDeferredCanvasBitmapCaching(reporter);
+ TestDeferredCanvasSkip(reporter);
}
#include "TestClassDef.h"