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