16 , fStorageType(kMalloc_StorageType)
20 fStorage.fMalloc =
data;
27 , fStorageType(kDiscardableMemory_StorageType)
35 switch (fStorageType) {
36 case kMalloc_StorageType:
39 case kDiscardableMemory_StorageType:
48 fCD->fMutex.acquire();
53 fCD->fMutex.release();
63void SkCachedData::internalRef(
bool fromCache)
const {
64 AutoMutexWritable(
this)->inMutexRef(fromCache);
67void SkCachedData::internalUnref(
bool fromCache)
const {
68 if (AutoMutexWritable(
this)->inMutexUnref(fromCache)) {
76void SkCachedData::inMutexRef(
bool fromCache) {
77 if ((1 == fRefCnt) && fInCache) {
88bool SkCachedData::inMutexUnref(
bool fromCache) {
93 this->inMutexUnlock();
97 if (fInCache && !fromCache) {
101 this->inMutexUnlock();
117void SkCachedData::inMutexLock() {
123 switch (fStorageType) {
124 case kMalloc_StorageType:
125 this->setData(fStorage.fMalloc);
127 case kDiscardableMemory_StorageType:
128 if (fStorage.fDM->lock()) {
129 void* ptr = fStorage.fDM->data();
133 this->setData(
nullptr);
139void SkCachedData::inMutexUnlock() {
145 switch (fStorageType) {
146 case kMalloc_StorageType:
149 case kDiscardableMemory_StorageType:
151 fStorage.fDM->unlock();
155 this->setData(
nullptr);
163 SkASSERT((fInCache && fRefCnt > 1) || !fInCache);
164 switch (fStorageType) {
165 case kMalloc_StorageType:
166 SkASSERT(fData == fStorage.fMalloc);
168 case kDiscardableMemory_StorageType:
173 SkASSERT((fInCache && 1 == fRefCnt) || (0 == fRefCnt));
SK_API void sk_free(void *)
AutoMutexWritable(const SkCachedData *cd)
SkCachedData * operator->()
SkCachedData(void *mallocData, size_t size)
const void * data() const