| OLD | NEW |
| 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 } | 171 } |
| 172 | 172 |
| 173 void SkPixelRef::lockPixels() { | 173 void SkPixelRef::lockPixels() { |
| 174 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount); | 174 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount); |
| 175 | 175 |
| 176 if (!fPreLocked) { | 176 if (!fPreLocked) { |
| 177 SkAutoMutexAcquire ac(*fMutex); | 177 SkAutoMutexAcquire ac(*fMutex); |
| 178 | 178 |
| 179 if (1 == ++fLockCount) { | 179 if (1 == ++fLockCount) { |
| 180 fPixels = this->onLockPixels(&fColorTable); | 180 fPixels = this->onLockPixels(&fColorTable); |
| 181 // If onLockPixels failed, it will return NULL |
| 182 if (NULL == fPixels) { |
| 183 fColorTable = NULL; |
| 184 } |
| 181 } | 185 } |
| 182 } | 186 } |
| 183 } | 187 } |
| 184 | 188 |
| 185 void SkPixelRef::unlockPixels() { | 189 void SkPixelRef::unlockPixels() { |
| 186 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount); | 190 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount); |
| 187 | 191 |
| 188 if (!fPreLocked) { | 192 if (!fPreLocked) { |
| 189 SkAutoMutexAcquire ac(*fMutex); | 193 SkAutoMutexAcquire ac(*fMutex); |
| 190 | 194 |
| 191 SkASSERT(fLockCount > 0); | 195 SkASSERT(fLockCount > 0); |
| 192 if (0 == --fLockCount) { | 196 if (0 == --fLockCount) { |
| 193 this->onUnlockPixels(); | 197 // don't call onUnlockPixels unless onLockPixels succeeded |
| 194 fPixels = NULL; | 198 if (fPixels) { |
| 195 fColorTable = NULL; | 199 this->onUnlockPixels(); |
| 200 fPixels = NULL; |
| 201 fColorTable = NULL; |
| 202 } else { |
| 203 SkASSERT(NULL == fColorTable); |
| 204 } |
| 196 } | 205 } |
| 197 } | 206 } |
| 198 } | 207 } |
| 199 | 208 |
| 200 bool SkPixelRef::lockPixelsAreWritable() const { | 209 bool SkPixelRef::lockPixelsAreWritable() const { |
| 201 return this->onLockPixelsAreWritable(); | 210 return this->onLockPixelsAreWritable(); |
| 202 } | 211 } |
| 203 | 212 |
| 204 bool SkPixelRef::onLockPixelsAreWritable() const { | 213 bool SkPixelRef::onLockPixelsAreWritable() const { |
| 205 return true; | 214 return true; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 | 284 |
| 276 #ifdef SK_BUILD_FOR_ANDROID | 285 #ifdef SK_BUILD_FOR_ANDROID |
| 277 void SkPixelRef::globalRef(void* data) { | 286 void SkPixelRef::globalRef(void* data) { |
| 278 this->ref(); | 287 this->ref(); |
| 279 } | 288 } |
| 280 | 289 |
| 281 void SkPixelRef::globalUnref() { | 290 void SkPixelRef::globalUnref() { |
| 282 this->unref(); | 291 this->unref(); |
| 283 } | 292 } |
| 284 #endif | 293 #endif |
| OLD | NEW |