Fixing a deferred canvas optimization that purges pending draws when the canvas is cleared
It appears that the recording canvas returns a save count of 1 when the save stack is empty.
In order to pass Canvas unit tests when a clear occurs, changes to SkGPipe were necessary
to allow SkDeferredCanvas to set the device bounds on the SkGPipeCanvas. A positive
side effect of this change is that graphics primitives that fall outside of the device
bounds will now always be culled at the recording stage (as opposed playback).
BUG=http://code.google.com/p/skia/issues/detail?id=782
TEST=deferred_canvas_record bench test
Review URL: https://codereview.appspot.com/6454157
git-svn-id: http://skia.googlecode.com/svn/trunk@5117 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/utils/SkDeferredCanvas.cpp b/src/utils/SkDeferredCanvas.cpp
index bf3ce16..c66e09c 100644
--- a/src/utils/SkDeferredCanvas.cpp
+++ b/src/utils/SkDeferredCanvas.cpp
@@ -348,6 +348,7 @@
SkDevice* immediateDevice, SkDeferredCanvas::NotificationClient* notificationClient) :
SkDevice(SkBitmap::kNo_Config, immediateDevice->width(),
immediateDevice->height(), immediateDevice->isOpaque())
+ , fRecordingCanvas(NULL)
, fFreshFrame(true)
, fPreviousStorageAllocated(0){
@@ -378,7 +379,9 @@
}
void DeferredDevice::beginRecording() {
- fRecordingCanvas = fPipeWriter.startRecording(&fPipeController, 0);
+ SkASSERT(NULL == fRecordingCanvas);
+ fRecordingCanvas = fPipeWriter.startRecording(&fPipeController, 0,
+ fImmediateDevice->width(), fImmediateDevice->height());
}
void DeferredDevice::setNotificationClient(
@@ -392,8 +395,9 @@
// TODO: find a way to transfer the state stack and layers
// to the new recording canvas. For now, purging only works
- // with an empty stack.
- if (fRecordingCanvas->getSaveCount() == 0) {
+ // with an empty stack. A save count of 1 means an empty stack.
+ SkASSERT(fRecordingCanvas->getSaveCount() >= 1);
+ if (fRecordingCanvas->getSaveCount() == 1) {
// Save state that is trashed by the purge
SkDrawFilter* drawFilter = fRecordingCanvas->getDrawFilter();