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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 SkImage* SkSurface_Raster::onNewImageSnapshot(Budgeted) { | 121 SkImage* SkSurface_Raster::onNewImageSnapshot(Budgeted) { |
122 if (fWeOwnThePixels) { | 122 if (fWeOwnThePixels) { |
123 // SkImage_raster requires these pixels are immutable for its full lifet
ime. | 123 // SkImage_raster requires these pixels are immutable for its full lifet
ime. |
124 // We'll undo this via onRestoreBackingMutability() if we can avoid the
COW. | 124 // We'll undo this via onRestoreBackingMutability() if we can avoid the
COW. |
125 if (SkPixelRef* pr = fBitmap.pixelRef()) { | 125 if (SkPixelRef* pr = fBitmap.pixelRef()) { |
126 pr->setTemporarilyImmutable(); | 126 pr->setTemporarilyImmutable(); |
127 } | 127 } |
128 } | 128 } |
129 // Our pixels are in memory, so read access on the snapshot SkImage could be
cheap. | 129 // Our pixels are in memory, so read access on the snapshot SkImage could be
cheap. |
130 // Lock the shared pixel ref to ensure peekPixels() is usable. | 130 // Lock the shared pixel ref to ensure peekPixels() is usable. |
131 return SkNewImageFromRasterBitmap(fBitmap, &this->props(), kLocked_SharedPix
elRefMode, | 131 return SkNewImageFromRasterBitmap(fBitmap, &this->props(), |
132 fWeOwnThePixels ? kNo_ForceCopyMode : kYes
_ForceCopyMode); | 132 fWeOwnThePixels ? kNo_ForceCopyMode : kYes
_ForceCopyMode); |
133 } | 133 } |
134 | 134 |
135 void SkSurface_Raster::onRestoreBackingMutability() { | 135 void SkSurface_Raster::onRestoreBackingMutability() { |
136 SkASSERT(!this->hasCachedImage()); // Shouldn't be any snapshots out there. | 136 SkASSERT(!this->hasCachedImage()); // Shouldn't be any snapshots out there. |
137 if (SkPixelRef* pr = fBitmap.pixelRef()) { | 137 if (SkPixelRef* pr = fBitmap.pixelRef()) { |
138 pr->restoreMutability(); | 138 pr->restoreMutability(); |
139 } | 139 } |
140 } | 140 } |
141 | 141 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 if (!SkSurface_Raster::Valid(info)) { | 186 if (!SkSurface_Raster::Valid(info)) { |
187 return NULL; | 187 return NULL; |
188 } | 188 } |
189 | 189 |
190 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewAllocate(info, 0, NULL)); | 190 SkAutoTUnref<SkPixelRef> pr(SkMallocPixelRef::NewAllocate(info, 0, NULL)); |
191 if (NULL == pr.get()) { | 191 if (NULL == pr.get()) { |
192 return NULL; | 192 return NULL; |
193 } | 193 } |
194 return SkNEW_ARGS(SkSurface_Raster, (pr, props)); | 194 return SkNEW_ARGS(SkSurface_Raster, (pr, props)); |
195 } | 195 } |
OLD | NEW |