| 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" |
| 11 #include "SkTraceEvent.h" | 11 #include "SkTraceEvent.h" |
| 12 | 12 |
| 13 //#define SK_TRACE_PIXELREF_LIFETIME |
| 14 |
| 13 #ifdef SK_BUILD_FOR_WIN32 | 15 #ifdef SK_BUILD_FOR_WIN32 |
| 14 // We don't have SK_BASE_MUTEX_INIT on Windows. | 16 // We don't have SK_BASE_MUTEX_INIT on Windows. |
| 15 | 17 |
| 16 // must be a power-of-2. undef to just use 1 mutex | 18 // must be a power-of-2. undef to just use 1 mutex |
| 17 #define PIXELREF_MUTEX_RING_COUNT 32 | 19 #define PIXELREF_MUTEX_RING_COUNT 32 |
| 18 static SkBaseMutex gPixelRefMutexRing[PIXELREF_MUTEX_RING_COUNT]; | 20 static SkBaseMutex gPixelRefMutexRing[PIXELREF_MUTEX_RING_COUNT]; |
| 19 | 21 |
| 20 #else | 22 #else |
| 21 static SkBaseMutex gPixelRefMutexRing[] = { | 23 static SkBaseMutex gPixelRefMutexRing[] = { |
| 22 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, | 24 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 | 80 |
| 79 // just need a > 0 value, so pick a funny one to aid in debugging | 81 // just need a > 0 value, so pick a funny one to aid in debugging |
| 80 #define SKPIXELREF_PRELOCKED_LOCKCOUNT 123456789 | 82 #define SKPIXELREF_PRELOCKED_LOCKCOUNT 123456789 |
| 81 | 83 |
| 82 static SkImageInfo validate_info(const SkImageInfo& info) { | 84 static SkImageInfo validate_info(const SkImageInfo& info) { |
| 83 SkAlphaType newAlphaType = info.alphaType(); | 85 SkAlphaType newAlphaType = info.alphaType(); |
| 84 SkAssertResult(SkColorTypeValidateAlphaType(info.colorType(), info.alphaType
(), &newAlphaType)); | 86 SkAssertResult(SkColorTypeValidateAlphaType(info.colorType(), info.alphaType
(), &newAlphaType)); |
| 85 return info.makeAlphaType(newAlphaType); | 87 return info.makeAlphaType(newAlphaType); |
| 86 } | 88 } |
| 87 | 89 |
| 90 #ifdef SK_TRACE_PIXELREF_LIFETIME |
| 91 static int32_t gInstCounter; |
| 92 #endif |
| 93 |
| 88 SkPixelRef::SkPixelRef(const SkImageInfo& info) | 94 SkPixelRef::SkPixelRef(const SkImageInfo& info) |
| 89 : fInfo(validate_info(info)) | 95 : fInfo(validate_info(info)) |
| 90 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK | 96 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 91 , fStableID(next_gen_id()) | 97 , fStableID(next_gen_id()) |
| 92 #endif | 98 #endif |
| 93 | 99 |
| 94 { | 100 { |
| 101 #ifdef SK_TRACE_PIXELREF_LIFETIME |
| 102 SkDebugf(" pixelref %d\n", sk_atomic_inc(&gInstCounter)); |
| 103 #endif |
| 95 this->setMutex(NULL); | 104 this->setMutex(NULL); |
| 96 fRec.zero(); | 105 fRec.zero(); |
| 97 fLockCount = 0; | 106 fLockCount = 0; |
| 98 this->needsNewGenID(); | 107 this->needsNewGenID(); |
| 99 fIsImmutable = false; | 108 fIsImmutable = false; |
| 100 fPreLocked = false; | 109 fPreLocked = false; |
| 101 fAddedToCache.store(false); | 110 fAddedToCache.store(false); |
| 102 } | 111 } |
| 103 | 112 |
| 104 | 113 |
| 105 SkPixelRef::SkPixelRef(const SkImageInfo& info, SkBaseMutex* mutex) | 114 SkPixelRef::SkPixelRef(const SkImageInfo& info, SkBaseMutex* mutex) |
| 106 : fInfo(validate_info(info)) | 115 : fInfo(validate_info(info)) |
| 107 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK | 116 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 108 , fStableID(next_gen_id()) | 117 , fStableID(next_gen_id()) |
| 109 #endif | 118 #endif |
| 110 { | 119 { |
| 120 #ifdef SK_TRACE_PIXELREF_LIFETIME |
| 121 SkDebugf(" pixelref %d\n", sk_atomic_inc(&gInstCounter)); |
| 122 #endif |
| 111 this->setMutex(mutex); | 123 this->setMutex(mutex); |
| 112 fRec.zero(); | 124 fRec.zero(); |
| 113 fLockCount = 0; | 125 fLockCount = 0; |
| 114 this->needsNewGenID(); | 126 this->needsNewGenID(); |
| 115 fIsImmutable = false; | 127 fIsImmutable = false; |
| 116 fPreLocked = false; | 128 fPreLocked = false; |
| 117 fAddedToCache.store(false); | 129 fAddedToCache.store(false); |
| 118 } | 130 } |
| 119 | 131 |
| 120 SkPixelRef::~SkPixelRef() { | 132 SkPixelRef::~SkPixelRef() { |
| 133 #ifdef SK_TRACE_PIXELREF_LIFETIME |
| 134 SkDebugf("~pixelref %d\n", sk_atomic_dec(&gInstCounter) - 1); |
| 135 #endif |
| 121 this->callGenIDChangeListeners(); | 136 this->callGenIDChangeListeners(); |
| 122 } | 137 } |
| 123 | 138 |
| 124 void SkPixelRef::needsNewGenID() { | 139 void SkPixelRef::needsNewGenID() { |
| 125 fTaggedGenID.store(0); | 140 fTaggedGenID.store(0); |
| 126 SkASSERT(!this->genIDIsUnique()); // This method isn't threadsafe, so the as
sert should be fine. | 141 SkASSERT(!this->genIDIsUnique()); // This method isn't threadsafe, so the as
sert should be fine. |
| 127 } | 142 } |
| 128 | 143 |
| 129 void SkPixelRef::cloneGenID(const SkPixelRef& that) { | 144 void SkPixelRef::cloneGenID(const SkPixelRef& that) { |
| 130 // This is subtle. We must call that.getGenerationID() to make sure its gen
ID isn't 0. | 145 // This is subtle. We must call that.getGenerationID() to make sure its gen
ID isn't 0. |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 | 296 |
| 282 bool SkPixelRef::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3], | 297 bool SkPixelRef::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBy
tes[3], |
| 283 SkYUVColorSpace* colorSpace) { | 298 SkYUVColorSpace* colorSpace) { |
| 284 return false; | 299 return false; |
| 285 } | 300 } |
| 286 | 301 |
| 287 size_t SkPixelRef::getAllocatedSizeInBytes() const { | 302 size_t SkPixelRef::getAllocatedSizeInBytes() const { |
| 288 return 0; | 303 return 0; |
| 289 } | 304 } |
| 290 | 305 |
| OLD | NEW |