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