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

Unified Diff: src/image/SkSurface_Raster.cpp

Issue 12567025: Integrating SkSurface with SkDeferredCanvas (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 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
Index: src/image/SkSurface_Raster.cpp
===================================================================
--- src/image/SkSurface_Raster.cpp (revision 8402)
+++ src/image/SkSurface_Raster.cpp (working copy)
@@ -25,7 +25,7 @@
virtual SkImage* onNewImageShapshot() SK_OVERRIDE;
virtual void onDraw(SkCanvas*, SkScalar x, SkScalar y,
const SkPaint*) SK_OVERRIDE;
- virtual void onCopyOnWrite(SkImage*, SkCanvas*) SK_OVERRIDE;
+ virtual void onCopyOnWrite(SkImage*, SkCanvas*, bool canDiscardContents) SK_OVERRIDE;
private:
SkBitmap fBitmap;
@@ -124,15 +124,23 @@
return SkNewImageFromBitmap(fBitmap, fWeOwnThePixels);
}
-void SkSurface_Raster::onCopyOnWrite(SkImage* image, SkCanvas* canvas) {
+void SkSurface_Raster::onCopyOnWrite(SkImage* image, SkCanvas* canvas, bool canDiscardContents) {
// are we sharing pixelrefs with the image?
if (SkBitmapImageGetPixelRef(image) == fBitmap.pixelRef()) {
SkASSERT(fWeOwnThePixels);
- SkBitmap prev(fBitmap);
- prev.deepCopyTo(&fBitmap, prev.config());
- // Now fBitmap is a deep copy of itself (and therefore different from
- // what is being used by the image. Next we update the canvas to use
- // this as its backend, so we can't modify the image's pixels anymore.
+ if (canDiscardContents) {
+ SkBitmap newBitmap;
+ newBitmap.setConfig(fBitmap.getConfig(), fBitmap.width(), fBitmap.height(),
+ fBitmap.rowBytes());
+ newBitmap.allocPixels();
+ fBitmap.swap(newBitmap);
+ } else {
+ SkBitmap prev(fBitmap);
+ prev.deepCopyTo(&fBitmap, prev.config());
+ }
+ // Now fBitmap is different from what is being used by the image.
+ // Next we update the canvas to use this as its backing store,
+ // so we can't modify the image's pixels anymore.
canvas->getDevice()->replaceBitmapBackendForRasterSurface(fBitmap);
}
}

Powered by Google App Engine
This is Rietveld 408576698