| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkCachedData.h" | 8 #include "SkCachedData.h" |
| 9 #include "SkDiscardableMemory.h" | 9 #include "SkDiscardableMemory.h" |
| 10 | 10 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 fStorage.fDM = dm; | 50 fStorage.fDM = dm; |
| 51 inc(); | 51 inc(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 SkCachedData::~SkCachedData() { | 54 SkCachedData::~SkCachedData() { |
| 55 switch (fStorageType) { | 55 switch (fStorageType) { |
| 56 case kMalloc_StorageType: | 56 case kMalloc_StorageType: |
| 57 sk_free(fStorage.fMalloc); | 57 sk_free(fStorage.fMalloc); |
| 58 break; | 58 break; |
| 59 case kDiscardableMemory_StorageType: | 59 case kDiscardableMemory_StorageType: |
| 60 SkDELETE(fStorage.fDM); | 60 delete fStorage.fDM; |
| 61 break; | 61 break; |
| 62 } | 62 } |
| 63 dec(); | 63 dec(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 class SkCachedData::AutoMutexWritable { | 66 class SkCachedData::AutoMutexWritable { |
| 67 public: | 67 public: |
| 68 AutoMutexWritable(const SkCachedData* cd) : fCD(const_cast<SkCachedData*>(cd
)) { | 68 AutoMutexWritable(const SkCachedData* cd) : fCD(const_cast<SkCachedData*>(cd
)) { |
| 69 fCD->fMutex.acquire(); | 69 fCD->fMutex.acquire(); |
| 70 fCD->validate(); | 70 fCD->validate(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 81 SkCachedData* fCD; | 81 SkCachedData* fCD; |
| 82 }; | 82 }; |
| 83 | 83 |
| 84 void SkCachedData::internalRef(bool fromCache) const { | 84 void SkCachedData::internalRef(bool fromCache) const { |
| 85 AutoMutexWritable(this)->inMutexRef(fromCache); | 85 AutoMutexWritable(this)->inMutexRef(fromCache); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void SkCachedData::internalUnref(bool fromCache) const { | 88 void SkCachedData::internalUnref(bool fromCache) const { |
| 89 if (AutoMutexWritable(this)->inMutexUnref(fromCache)) { | 89 if (AutoMutexWritable(this)->inMutexUnref(fromCache)) { |
| 90 // can't delete inside doInternalUnref, since it is locking a mutex (whi
ch we own) | 90 // can't delete inside doInternalUnref, since it is locking a mutex (whi
ch we own) |
| 91 SkDELETE(this); | 91 delete this; |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 95 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 96 | 96 |
| 97 void SkCachedData::inMutexRef(bool fromCache) { | 97 void SkCachedData::inMutexRef(bool fromCache) { |
| 98 if ((1 == fRefCnt) && fInCache) { | 98 if ((1 == fRefCnt) && fInCache) { |
| 99 this->inMutexLock(); | 99 this->inMutexLock(); |
| 100 } | 100 } |
| 101 | 101 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 case kDiscardableMemory_StorageType: | 189 case kDiscardableMemory_StorageType: |
| 190 // fData can be null or the actual value, depending if DM's lock
succeeded | 190 // fData can be null or the actual value, depending if DM's lock
succeeded |
| 191 break; | 191 break; |
| 192 } | 192 } |
| 193 } else { | 193 } else { |
| 194 SkASSERT((fInCache && 1 == fRefCnt) || (0 == fRefCnt)); | 194 SkASSERT((fInCache && 1 == fRefCnt) || (0 == fRefCnt)); |
| 195 SkASSERT(NULL == fData); | 195 SkASSERT(NULL == fData); |
| 196 } | 196 } |
| 197 } | 197 } |
| 198 #endif | 198 #endif |
| OLD | NEW |