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 #ifndef SkCachedData_DEFINED | 8 #ifndef SkCachedData_DEFINED |
9 #define SkCachedData_DEFINED | 9 #define SkCachedData_DEFINED |
10 | 10 |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 int testing_only_getRefCnt() const { return fRefCnt; } | 30 int testing_only_getRefCnt() const { return fRefCnt; } |
31 bool testing_only_isLocked() const { return fIsLocked; } | 31 bool testing_only_isLocked() const { return fIsLocked; } |
32 bool testing_only_isInCache() const { return fInCache; } | 32 bool testing_only_isInCache() const { return fInCache; } |
33 | 33 |
34 SkDiscardableMemory* diagnostic_only_getDiscardable() const { | 34 SkDiscardableMemory* diagnostic_only_getDiscardable() const { |
35 return kDiscardableMemory_StorageType == fStorageType ? fStorage.fDM : n
ullptr; | 35 return kDiscardableMemory_StorageType == fStorageType ? fStorage.fDM : n
ullptr; |
36 } | 36 } |
37 | 37 |
38 protected: | 38 protected: |
39 // called when fData changes. could be NULL. | 39 // called when fData changes. could be nullptr. |
40 virtual void onDataChange(void* oldData, void* newData) {} | 40 virtual void onDataChange(void* oldData, void* newData) {} |
41 | 41 |
42 private: | 42 private: |
43 SkMutex fMutex; // could use a pool of these... | 43 SkMutex fMutex; // could use a pool of these... |
44 | 44 |
45 enum StorageType { | 45 enum StorageType { |
46 kDiscardableMemory_StorageType, | 46 kDiscardableMemory_StorageType, |
47 kMalloc_StorageType | 47 kMalloc_StorageType |
48 }; | 48 }; |
49 | 49 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 86 |
87 /* | 87 /* |
88 * Attaching a data to to a SkResourceCache (only one at a time) enables th
e data to be | 88 * Attaching a data to to a SkResourceCache (only one at a time) enables th
e data to be |
89 * unlocked when the cache is the only owner, thus freeing it to be purged
(assuming the | 89 * unlocked when the cache is the only owner, thus freeing it to be purged
(assuming the |
90 * data is backed by a SkDiscardableMemory). | 90 * data is backed by a SkDiscardableMemory). |
91 * | 91 * |
92 * When attached, it also automatically attempts to "lock" the data when th
e first client | 92 * When attached, it also automatically attempts to "lock" the data when th
e first client |
93 * ref's the data (typically from a find(key, visitor) call). | 93 * ref's the data (typically from a find(key, visitor) call). |
94 * | 94 * |
95 * Thus the data will always be "locked" when a non-cache has a ref on it (
whether or not | 95 * Thus the data will always be "locked" when a non-cache has a ref on it (
whether or not |
96 * the lock succeeded to recover the memory -- check data() to see if it is
NULL). | 96 * the lock succeeded to recover the memory -- check data() to see if it is
nullptr). |
97 */ | 97 */ |
98 | 98 |
99 /* | 99 /* |
100 * Call when adding this instance to a SkResourceCache::Rec subclass | 100 * Call when adding this instance to a SkResourceCache::Rec subclass |
101 * (typically in the Rec's constructor). | 101 * (typically in the Rec's constructor). |
102 */ | 102 */ |
103 void attachToCacheAndRef() const { this->internalRef(true); } | 103 void attachToCacheAndRef() const { this->internalRef(true); } |
104 | 104 |
105 /* | 105 /* |
106 * Call when removing this instance from a SkResourceCache::Rec subclass | 106 * Call when removing this instance from a SkResourceCache::Rec subclass |
107 * (typically in the Rec's destructor). | 107 * (typically in the Rec's destructor). |
108 */ | 108 */ |
109 void detachFromCacheAndUnref() const { this->internalUnref(true); } | 109 void detachFromCacheAndUnref() const { this->internalUnref(true); } |
110 }; | 110 }; |
111 | 111 |
112 #endif | 112 #endif |
OLD | NEW |