void SkSurface_Raster::onCopyOnWrite(ContentChangeMode mode) { // are we sharing pixelrefs with the image? sk_sp<SkImage> cached(this->refCachedImage(SkBudgeted::kNo, kNo_ForceUnique)); SkASSERT(cached); if (SkBitmapImageGetPixelRef(cached.get()) == fBitmap.pixelRef()) { SkASSERT(fWeOwnThePixels); if (kDiscard_ContentChangeMode == mode) { fBitmap.allocPixels(); } else { SkBitmap prev(fBitmap); fBitmap.allocPixels(); prev.lockPixels(); SkASSERT(prev.info() == fBitmap.info()); SkASSERT(prev.rowBytes() == fBitmap.rowBytes()); memcpy(fBitmap.getPixels(), prev.getPixels(), fBitmap.getSafeSize()); } SkASSERT(fBitmap.rowBytes() == fRowBytes); // be sure we always use the same value // 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. SkASSERT(this->getCachedCanvas()); this->getCachedCanvas()->getDevice()->replaceBitmapBackendForRasterSurface(fBitmap); } }
void SkSurface_Raster::onCopyOnWrite(ContentChangeMode mode) { // are we sharing pixelrefs with the image? SkASSERT(this->getCachedImage(kNo_Budgeted)); if (SkBitmapImageGetPixelRef(this->getCachedImage(kNo_Budgeted)) == fBitmap.pixelRef()) { SkASSERT(fWeOwnThePixels); if (kDiscard_ContentChangeMode == mode) { fBitmap.setPixelRef(NULL); fBitmap.allocPixels(); } else { SkBitmap prev(fBitmap); prev.deepCopyTo(&fBitmap); } // 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. SkASSERT(this->getCachedCanvas()); this->getCachedCanvas()->getDevice()->replaceBitmapBackendForRasterSurface(fBitmap); } }