Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(599)

Side by Side Diff: src/core/SkPixelRef.cpp

Issue 108613005: Ensure we call onUnlock only if onLock succeeded (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « include/core/SkPixelRef.h ('k') | src/core/SkScaledImageCache.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SkPixelRef.h" 8 #include "SkPixelRef.h"
9 #include "SkFlattenableBuffers.h" 9 #include "SkFlattenableBuffers.h"
10 #include "SkThread.h" 10 #include "SkThread.h"
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 } 175 }
176 176
177 void SkPixelRef::lockPixels() { 177 void SkPixelRef::lockPixels() {
178 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount); 178 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount);
179 179
180 if (!fPreLocked) { 180 if (!fPreLocked) {
181 SkAutoMutexAcquire ac(*fMutex); 181 SkAutoMutexAcquire ac(*fMutex);
182 182
183 if (1 == ++fLockCount) { 183 if (1 == ++fLockCount) {
184 fPixels = this->onLockPixels(&fColorTable); 184 fPixels = this->onLockPixels(&fColorTable);
185 // If onLockPixels failed, it will return NULL
186 if (NULL == fPixels) {
187 fColorTable = NULL;
188 }
185 } 189 }
186 } 190 }
187 } 191 }
188 192
189 void SkPixelRef::unlockPixels() { 193 void SkPixelRef::unlockPixels() {
190 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount); 194 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount);
191 195
192 if (!fPreLocked) { 196 if (!fPreLocked) {
193 SkAutoMutexAcquire ac(*fMutex); 197 SkAutoMutexAcquire ac(*fMutex);
194 198
195 SkASSERT(fLockCount > 0); 199 SkASSERT(fLockCount > 0);
196 if (0 == --fLockCount) { 200 if (0 == --fLockCount) {
197 this->onUnlockPixels(); 201 // don't call onUnlockPixels unless onLockPixels succeeded
198 fPixels = NULL; 202 if (fPixels) {
199 fColorTable = NULL; 203 this->onUnlockPixels();
204 fPixels = NULL;
205 fColorTable = NULL;
206 } else {
207 SkASSERT(NULL == fColorTable);
208 }
200 } 209 }
201 } 210 }
202 } 211 }
203 212
204 bool SkPixelRef::lockPixelsAreWritable() const { 213 bool SkPixelRef::lockPixelsAreWritable() const {
205 return this->onLockPixelsAreWritable(); 214 return this->onLockPixelsAreWritable();
206 } 215 }
207 216
208 bool SkPixelRef::onLockPixelsAreWritable() const { 217 bool SkPixelRef::onLockPixelsAreWritable() const {
209 return true; 218 return true;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 288
280 #ifdef SK_BUILD_FOR_ANDROID 289 #ifdef SK_BUILD_FOR_ANDROID
281 void SkPixelRef::globalRef(void* data) { 290 void SkPixelRef::globalRef(void* data) {
282 this->ref(); 291 this->ref();
283 } 292 }
284 293
285 void SkPixelRef::globalUnref() { 294 void SkPixelRef::globalUnref() {
286 this->unref(); 295 this->unref();
287 } 296 }
288 #endif 297 #endif
OLDNEW
« no previous file with comments | « include/core/SkPixelRef.h ('k') | src/core/SkScaledImageCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698