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 "SkMutex.h" | 9 #include "SkMutex.h" |
10 #include "SkPixelRef.h" | 10 #include "SkPixelRef.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 SkASSERT(!that. genIDIsUnique()); | 88 SkASSERT(!that. genIDIsUnique()); |
89 } | 89 } |
90 | 90 |
91 static void validate_pixels_ctable(const SkImageInfo& info, const SkColorTable*
ctable) { | 91 static void validate_pixels_ctable(const SkImageInfo& info, const SkColorTable*
ctable) { |
92 if (info.isEmpty()) { | 92 if (info.isEmpty()) { |
93 return; // can't require ctable if the dimensions are empty | 93 return; // can't require ctable if the dimensions are empty |
94 } | 94 } |
95 if (kIndex_8_SkColorType == info.colorType()) { | 95 if (kIndex_8_SkColorType == info.colorType()) { |
96 SkASSERT(ctable); | 96 SkASSERT(ctable); |
97 } else { | 97 } else { |
98 SkASSERT(NULL == ctable); | 98 SkASSERT(nullptr == ctable); |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 void SkPixelRef::setPreLocked(void* pixels, size_t rowBytes, SkColorTable* ctabl
e) { | 102 void SkPixelRef::setPreLocked(void* pixels, size_t rowBytes, SkColorTable* ctabl
e) { |
103 SkASSERT(pixels); | 103 SkASSERT(pixels); |
104 validate_pixels_ctable(fInfo, ctable); | 104 validate_pixels_ctable(fInfo, ctable); |
105 // only call me in your constructor, otherwise fLockCount tracking can get | 105 // only call me in your constructor, otherwise fLockCount tracking can get |
106 // out of sync. | 106 // out of sync. |
107 fRec.fPixels = pixels; | 107 fRec.fPixels = pixels; |
108 fRec.fColorTable = ctable; | 108 fRec.fColorTable = ctable; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 SkASSERT(result); | 191 SkASSERT(result); |
192 if (request.fSize.isEmpty()) { | 192 if (request.fSize.isEmpty()) { |
193 return false; | 193 return false; |
194 } | 194 } |
195 // until we support subsets, we have to check this... | 195 // until we support subsets, we have to check this... |
196 if (request.fSize.width() != fInfo.width() || request.fSize.height() != fInf
o.height()) { | 196 if (request.fSize.width() != fInfo.width() || request.fSize.height() != fInf
o.height()) { |
197 return false; | 197 return false; |
198 } | 198 } |
199 | 199 |
200 if (fPreLocked) { | 200 if (fPreLocked) { |
201 result->fUnlockProc = NULL; | 201 result->fUnlockProc = nullptr; |
202 result->fUnlockContext = NULL; | 202 result->fUnlockContext = nullptr; |
203 result->fCTable = fRec.fColorTable; | 203 result->fCTable = fRec.fColorTable; |
204 result->fPixels = fRec.fPixels; | 204 result->fPixels = fRec.fPixels; |
205 result->fRowBytes = fRec.fRowBytes; | 205 result->fRowBytes = fRec.fRowBytes; |
206 result->fSize.set(fInfo.width(), fInfo.height()); | 206 result->fSize.set(fInfo.width(), fInfo.height()); |
207 } else { | 207 } else { |
208 SkAutoMutexAcquire ac(fMutex); | 208 SkAutoMutexAcquire ac(fMutex); |
209 if (!this->onRequestLock(request, result)) { | 209 if (!this->onRequestLock(request, result)) { |
210 return false; | 210 return false; |
211 } | 211 } |
212 } | 212 } |
(...skipping 21 matching lines...) Expand all Loading... |
234 } else { | 234 } else { |
235 // We lost a race to set fTaggedGenID. compare_exchange() filled id
with the winner. | 235 // We lost a race to set fTaggedGenID. compare_exchange() filled id
with the winner. |
236 } | 236 } |
237 // We can't quite SkASSERT(this->genIDIsUnique()). It could be non-uniqu
e | 237 // We can't quite SkASSERT(this->genIDIsUnique()). It could be non-uniqu
e |
238 // if we got here via the else path (pretty unlikely, but possible). | 238 // if we got here via the else path (pretty unlikely, but possible). |
239 } | 239 } |
240 return id & ~1u; // Mask off bottom unique bit. | 240 return id & ~1u; // Mask off bottom unique bit. |
241 } | 241 } |
242 | 242 |
243 void SkPixelRef::addGenIDChangeListener(GenIDChangeListener* listener) { | 243 void SkPixelRef::addGenIDChangeListener(GenIDChangeListener* listener) { |
244 if (NULL == listener || !this->genIDIsUnique()) { | 244 if (nullptr == listener || !this->genIDIsUnique()) { |
245 // No point in tracking this if we're not going to call it. | 245 // No point in tracking this if we're not going to call it. |
246 delete listener; | 246 delete listener; |
247 return; | 247 return; |
248 } | 248 } |
249 *fGenIDChangeListeners.append() = listener; | 249 *fGenIDChangeListeners.append() = listener; |
250 } | 250 } |
251 | 251 |
252 // we need to be called *before* the genID gets changed or zerod | 252 // we need to be called *before* the genID gets changed or zerod |
253 void SkPixelRef::callGenIDChangeListeners() { | 253 void SkPixelRef::callGenIDChangeListeners() { |
254 // We don't invalidate ourselves if we think another SkPixelRef is sharing o
ur genID. | 254 // We don't invalidate ourselves if we think another SkPixelRef is sharing o
ur genID. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 | 313 |
314 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 314 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
315 | 315 |
316 bool SkPixelRef::onReadPixels(SkBitmap* dst, const SkIRect* subset) { | 316 bool SkPixelRef::onReadPixels(SkBitmap* dst, const SkIRect* subset) { |
317 return false; | 317 return false; |
318 } | 318 } |
319 | 319 |
320 void SkPixelRef::onNotifyPixelsChanged() { } | 320 void SkPixelRef::onNotifyPixelsChanged() { } |
321 | 321 |
322 SkData* SkPixelRef::onRefEncodedData() { | 322 SkData* SkPixelRef::onRefEncodedData() { |
323 return NULL; | 323 return nullptr; |
324 } | 324 } |
325 | 325 |
326 bool SkPixelRef::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3], | 326 bool SkPixelRef::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3], |
327 SkYUVColorSpace* colorSpace) { | 327 SkYUVColorSpace* colorSpace) { |
328 return false; | 328 return false; |
329 } | 329 } |
330 | 330 |
331 size_t SkPixelRef::getAllocatedSizeInBytes() const { | 331 size_t SkPixelRef::getAllocatedSizeInBytes() const { |
332 return 0; | 332 return 0; |
333 } | 333 } |
(...skipping 10 matching lines...) Expand all Loading... |
344 } | 344 } |
345 | 345 |
346 result->fUnlockProc = unlock_legacy_result; | 346 result->fUnlockProc = unlock_legacy_result; |
347 result->fUnlockContext = SkRef(this); // this is balanced in our fUnlockPr
oc | 347 result->fUnlockContext = SkRef(this); // this is balanced in our fUnlockPr
oc |
348 result->fCTable = fRec.fColorTable; | 348 result->fCTable = fRec.fColorTable; |
349 result->fPixels = fRec.fPixels; | 349 result->fPixels = fRec.fPixels; |
350 result->fRowBytes = fRec.fRowBytes; | 350 result->fRowBytes = fRec.fRowBytes; |
351 result->fSize.set(fInfo.width(), fInfo.height()); | 351 result->fSize.set(fInfo.width(), fInfo.height()); |
352 return true; | 352 return true; |
353 } | 353 } |
OLD | NEW |