| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkSurface_Base.h" | 8 #include "SkSurface_Base.h" |
| 9 #include "SkImagePriv.h" | 9 #include "SkImagePriv.h" |
| 10 #include "SkCanvas.h" | 10 #include "SkCanvas.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 void SkSurface_Raster::onCopyOnWrite(ContentChangeMode mode) { | 118 void SkSurface_Raster::onCopyOnWrite(ContentChangeMode mode) { |
| 119 // are we sharing pixelrefs with the image? | 119 // are we sharing pixelrefs with the image? |
| 120 SkASSERT(NULL != this->getCachedImage()); | 120 SkASSERT(NULL != this->getCachedImage()); |
| 121 if (SkBitmapImageGetPixelRef(this->getCachedImage()) == fBitmap.pixelRef())
{ | 121 if (SkBitmapImageGetPixelRef(this->getCachedImage()) == fBitmap.pixelRef())
{ |
| 122 SkASSERT(fWeOwnThePixels); | 122 SkASSERT(fWeOwnThePixels); |
| 123 if (kDiscard_ContentChangeMode == mode) { | 123 if (kDiscard_ContentChangeMode == mode) { |
| 124 fBitmap.setPixelRef(NULL); | 124 fBitmap.setPixelRef(NULL); |
| 125 fBitmap.allocPixels(); | 125 fBitmap.allocPixels(); |
| 126 } else { | 126 } else { |
| 127 SkBitmap prev(fBitmap); | 127 SkBitmap prev(fBitmap); |
| 128 prev.deepCopyTo(&fBitmap, prev.config()); | 128 prev.deepCopyTo(&fBitmap); |
| 129 } | 129 } |
| 130 // Now fBitmap is a deep copy of itself (and therefore different from | 130 // Now fBitmap is a deep copy of itself (and therefore different from |
| 131 // what is being used by the image. Next we update the canvas to use | 131 // what is being used by the image. Next we update the canvas to use |
| 132 // this as its backend, so we can't modify the image's pixels anymore. | 132 // this as its backend, so we can't modify the image's pixels anymore. |
| 133 SkASSERT(NULL != this->getCachedCanvas()); | 133 SkASSERT(NULL != this->getCachedCanvas()); |
| 134 this->getCachedCanvas()->getDevice()->replaceBitmapBackendForRasterSurfa
ce(fBitmap); | 134 this->getCachedCanvas()->getDevice()->replaceBitmapBackendForRasterSurfa
ce(fBitmap); |
| 135 } | 135 } |
| 136 } | 136 } |
| 137 | 137 |
| 138 /////////////////////////////////////////////////////////////////////////////// | 138 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 13 matching lines...) Expand all Loading... |
| 152 if (!SkSurface_Raster::Valid(info)) { | 152 if (!SkSurface_Raster::Valid(info)) { |
| 153 return NULL; | 153 return NULL; |
| 154 } | 154 } |
| 155 | 155 |
| 156 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewAllocate(info, 0, NULL)); | 156 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewAllocate(info, 0, NULL)); |
| 157 if (NULL == pr.get()) { | 157 if (NULL == pr.get()) { |
| 158 return NULL; | 158 return NULL; |
| 159 } | 159 } |
| 160 return SkNEW_ARGS(SkSurface_Raster, (pr)); | 160 return SkNEW_ARGS(SkSurface_Raster, (pr)); |
| 161 } | 161 } |
| OLD | NEW |