OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkBitmapCache.h" | 8 #include "SkBitmapCache.h" |
9 #include "SkPixelRef.h" | 9 #include "SkPixelRef.h" |
10 #include "SkThread.h" | 10 #include "SkThread.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 | 192 |
193 if (1 == ++fLockCount) { | 193 if (1 == ++fLockCount) { |
194 SkASSERT(fRec.isZero()); | 194 SkASSERT(fRec.isZero()); |
195 if (!this->onNewLockPixels(&fRec)) { | 195 if (!this->onNewLockPixels(&fRec)) { |
196 fRec.zero(); | 196 fRec.zero(); |
197 fLockCount -= 1; // we return fLockCount unchanged if we fail. | 197 fLockCount -= 1; // we return fLockCount unchanged if we fail. |
198 return false; | 198 return false; |
199 } | 199 } |
200 } | 200 } |
201 validate_pixels_ctable(fInfo, fRec.fPixels, fRec.fColorTable); | 201 validate_pixels_ctable(fInfo, fRec.fPixels, fRec.fColorTable); |
202 return true; | 202 return fRec.fPixels != NULL; |
203 } | 203 } |
204 | 204 |
205 // For historical reasons, we always inc fLockCount, even if we return false. | 205 // For historical reasons, we always inc fLockCount, even if we return false. |
206 // It would be nice to change this (it seems), and only inc if we actually succe
ed... | 206 // It would be nice to change this (it seems), and only inc if we actually succe
ed... |
207 bool SkPixelRef::lockPixels() { | 207 bool SkPixelRef::lockPixels() { |
208 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount); | 208 SkASSERT(!fPreLocked || SKPIXELREF_PRELOCKED_LOCKCOUNT == fLockCount); |
209 | 209 |
210 if (!fPreLocked) { | 210 if (!fPreLocked) { |
211 TRACE_EVENT_BEGIN0("skia", "SkPixelRef::lockPixelsMutex"); | 211 TRACE_EVENT_BEGIN0("skia", "SkPixelRef::lockPixelsMutex"); |
212 SkAutoMutexAcquire ac(*fMutex); | 212 SkAutoMutexAcquire ac(*fMutex); |
213 TRACE_EVENT_END0("skia", "SkPixelRef::lockPixelsMutex"); | 213 TRACE_EVENT_END0("skia", "SkPixelRef::lockPixelsMutex"); |
214 SkDEBUGCODE(int oldCount = fLockCount;) | 214 SkDEBUGCODE(int oldCount = fLockCount;) |
215 bool success = this->lockPixelsInsideMutex(); | 215 bool success = this->lockPixelsInsideMutex(); |
216 // lockPixelsInsideMutex only increments the count if it succeeds. | 216 // lockPixelsInsideMutex only increments the count if it succeeds. |
217 SkASSERT(oldCount + (int)success == fLockCount); | 217 SkASSERT(oldCount + (int)success == fLockCount); |
218 | 218 |
219 if (!success) { | 219 if (!success) { |
220 // For compatibility with SkBitmap calling lockPixels, we still want
to increment | 220 // For compatibility with SkBitmap calling lockPixels, we still want
to increment |
221 // fLockCount even if we failed. If we updated SkBitmap we could rem
ove this oddity. | 221 // fLockCount even if we failed. If we updated SkBitmap we could rem
ove this oddity. |
222 fLockCount += 1; | 222 fLockCount += 1; |
223 return false; | 223 return false; |
224 } | 224 } |
225 } | 225 } |
226 validate_pixels_ctable(fInfo, fRec.fPixels, fRec.fColorTable); | 226 validate_pixels_ctable(fInfo, fRec.fPixels, fRec.fColorTable); |
227 return true; | 227 return fRec.fPixels != NULL; |
228 } | 228 } |
229 | 229 |
230 bool SkPixelRef::lockPixels(LockRec* rec) { | 230 bool SkPixelRef::lockPixels(LockRec* rec) { |
231 if (this->lockPixels()) { | 231 if (this->lockPixels()) { |
232 *rec = fRec; | 232 *rec = fRec; |
233 return true; | 233 return true; |
234 } | 234 } |
235 return false; | 235 return false; |
236 } | 236 } |
237 | 237 |
(...skipping 29 matching lines...) Expand all Loading... |
267 result->fPixels = fRec.fPixels; | 267 result->fPixels = fRec.fPixels; |
268 result->fRowBytes = fRec.fRowBytes; | 268 result->fRowBytes = fRec.fRowBytes; |
269 result->fSize.set(fInfo.width(), fInfo.height()); | 269 result->fSize.set(fInfo.width(), fInfo.height()); |
270 } else { | 270 } else { |
271 SkAutoMutexAcquire ac(*fMutex); | 271 SkAutoMutexAcquire ac(*fMutex); |
272 if (!this->onRequestLock(request, result)) { | 272 if (!this->onRequestLock(request, result)) { |
273 return false; | 273 return false; |
274 } | 274 } |
275 } | 275 } |
276 validate_pixels_ctable(fInfo, result->fPixels, result->fCTable); | 276 validate_pixels_ctable(fInfo, result->fPixels, result->fCTable); |
277 return true; | 277 return result->fPixels != NULL; |
278 } | 278 } |
279 | 279 |
280 bool SkPixelRef::lockPixelsAreWritable() const { | 280 bool SkPixelRef::lockPixelsAreWritable() const { |
281 return this->onLockPixelsAreWritable(); | 281 return this->onLockPixelsAreWritable(); |
282 } | 282 } |
283 | 283 |
284 bool SkPixelRef::onLockPixelsAreWritable() const { | 284 bool SkPixelRef::onLockPixelsAreWritable() const { |
285 return true; | 285 return true; |
286 } | 286 } |
287 | 287 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 } | 380 } |
381 | 381 |
382 result->fUnlockProc = unlock_legacy_result; | 382 result->fUnlockProc = unlock_legacy_result; |
383 result->fUnlockContext = SkRef(this); // this is balanced in our fUnlockPr
oc | 383 result->fUnlockContext = SkRef(this); // this is balanced in our fUnlockPr
oc |
384 result->fCTable = fRec.fColorTable; | 384 result->fCTable = fRec.fColorTable; |
385 result->fPixels = fRec.fPixels; | 385 result->fPixels = fRec.fPixels; |
386 result->fRowBytes = fRec.fRowBytes; | 386 result->fRowBytes = fRec.fRowBytes; |
387 result->fSize.set(fInfo.width(), fInfo.height()); | 387 result->fSize.set(fInfo.width(), fInfo.height()); |
388 return true; | 388 return true; |
389 } | 389 } |
OLD | NEW |