| 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);
|
| }
|
| }
|
|
|