Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(465)

Unified Diff: src/utils/SkDeferredCanvas.cpp

Issue 15896005: Adding setSurface public API method to SkDeferredCanvas (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/utils/SkDeferredCanvas.h ('k') | tests/DeferredCanvasTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils/SkDeferredCanvas.cpp
===================================================================
--- src/utils/SkDeferredCanvas.cpp (revision 9270)
+++ src/utils/SkDeferredCanvas.cpp (working copy)
@@ -148,6 +148,7 @@
SkCanvas* immediateCanvas() const {return fImmediateCanvas;}
SkDevice* immediateDevice() const {return fImmediateCanvas->getTopDevice();}
SkImage* newImageSnapshot();
+ void setSurface(SkSurface* surface);
bool isFreshFrame();
bool hasPendingCommands();
size_t storageAllocatedForRecording() const;
@@ -261,6 +262,7 @@
immediateDevice->getDeviceProperties()) {
fSurface = NULL;
fImmediateCanvas = SkNEW_ARGS(SkCanvas, (immediateDevice));
+ fPipeController.setPlaybackCanvas(fImmediateCanvas);
this->init();
}
@@ -272,13 +274,18 @@
surface->getCanvas()->getDevice()->getDeviceProperties()) {
fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes;
fNotificationClient = NULL;
- fImmediateCanvas = surface->getCanvas();
- SkSafeRef(fImmediateCanvas);
- fSurface = surface;
- SkSafeRef(fSurface);
+ fImmediateCanvas = NULL;
+ fSurface = NULL;
+ this->setSurface(surface);
this->init();
}
+void DeferredDevice::setSurface(SkSurface* surface) {
+ SkRefCnt_SafeAssign(fImmediateCanvas, surface->getCanvas());
+ SkRefCnt_SafeAssign(fSurface, surface);
+ fPipeController.setPlaybackCanvas(fImmediateCanvas);
+}
+
void DeferredDevice::init() {
fRecordingCanvas = NULL;
fFreshFrame = true;
@@ -287,7 +294,6 @@
fBitmapSizeThreshold = kDeferredCanvasBitmapSizeThreshold;
fMaxRecordingStorageBytes = kDefaultMaxRecordingStorageBytes;
fNotificationClient = NULL;
- fPipeController.setPlaybackCanvas(fImmediateCanvas);
this->beginRecording();
}
@@ -620,6 +626,19 @@
return device;
}
+SkSurface* SkDeferredCanvas::setSurface(SkSurface* surface) {
+ DeferredDevice* deferredDevice = this->getDeferredDevice();
+ if (NULL != deferredDevice) {
+ // By swapping the surface into the existing device, we preserve
+ // all pending commands, which can help to seamlessly recover from
+ // a lost accelerated graphics context.
+ deferredDevice->setSurface(surface);
+ } else {
+ this->INHERITED::setDevice(SkNEW_ARGS(DeferredDevice, (surface)))->unref();
+ }
+ return surface;
+}
+
SkDeferredCanvas::NotificationClient* SkDeferredCanvas::setNotificationClient(
NotificationClient* notificationClient) {
« no previous file with comments | « include/utils/SkDeferredCanvas.h ('k') | tests/DeferredCanvasTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698