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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 SkImage* SkSurface_Raster::onNewImageSnapshot() { | 116 SkImage* SkSurface_Raster::onNewImageSnapshot() { |
117 return SkNewImageFromBitmap(fBitmap, fWeOwnThePixels); | 117 return SkNewImageFromBitmap(fBitmap, fWeOwnThePixels); |
118 } | 118 } |
119 | 119 |
120 void SkSurface_Raster::onCopyOnWrite(ContentChangeMode mode) { | 120 void SkSurface_Raster::onCopyOnWrite(ContentChangeMode mode) { |
121 // are we sharing pixelrefs with the image? | 121 // are we sharing pixelrefs with the image? |
122 SkASSERT(NULL != this->getCachedImage()); | 122 SkASSERT(NULL != this->getCachedImage()); |
123 if (SkBitmapImageGetPixelRef(this->getCachedImage()) == fBitmap.pixelRef())
{ | 123 if (SkBitmapImageGetPixelRef(this->getCachedImage()) == fBitmap.pixelRef())
{ |
124 SkASSERT(fWeOwnThePixels); | 124 SkASSERT(fWeOwnThePixels); |
125 if (kDiscard_ContentChangeMode == mode) { | 125 if (kDiscard_ContentChangeMode == mode) { |
126 fBitmap.setPixelRef(NULL, 0); | 126 fBitmap.setPixelRef(NULL); |
127 fBitmap.allocPixels(); | 127 fBitmap.allocPixels(); |
128 } else { | 128 } else { |
129 SkBitmap prev(fBitmap); | 129 SkBitmap prev(fBitmap); |
130 prev.deepCopyTo(&fBitmap, prev.config()); | 130 prev.deepCopyTo(&fBitmap, prev.config()); |
131 } | 131 } |
132 // Now fBitmap is a deep copy of itself (and therefore different from | 132 // Now fBitmap is a deep copy of itself (and therefore different from |
133 // what is being used by the image. Next we update the canvas to use | 133 // what is being used by the image. Next we update the canvas to use |
134 // this as its backend, so we can't modify the image's pixels anymore. | 134 // this as its backend, so we can't modify the image's pixels anymore. |
135 SkASSERT(NULL != this->getCachedCanvas()); | 135 SkASSERT(NULL != this->getCachedCanvas()); |
136 this->getCachedCanvas()->getDevice()->replaceBitmapBackendForRasterSurfa
ce(fBitmap); | 136 this->getCachedCanvas()->getDevice()->replaceBitmapBackendForRasterSurfa
ce(fBitmap); |
(...skipping 17 matching lines...) Expand all Loading... |
154 if (!SkSurface_Raster::Valid(info)) { | 154 if (!SkSurface_Raster::Valid(info)) { |
155 return NULL; | 155 return NULL; |
156 } | 156 } |
157 | 157 |
158 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewAllocate(info, 0, NULL)); | 158 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewAllocate(info, 0, NULL)); |
159 if (NULL == pr.get()) { | 159 if (NULL == pr.get()) { |
160 return NULL; | 160 return NULL; |
161 } | 161 } |
162 return SkNEW_ARGS(SkSurface_Raster, (info, pr, info.minRowBytes())); | 162 return SkNEW_ARGS(SkSurface_Raster, (info, pr, info.minRowBytes())); |
163 } | 163 } |
OLD | NEW |