| 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 |
| 11 #include "SkThread.h" | 11 #include "SkMutex.h" |
| 12 | 12 |
| 13 class SkDiscardableMemory; | 13 class SkDiscardableMemory; |
| 14 | 14 |
| 15 class SkCachedData : ::SkNoncopyable { | 15 class SkCachedData : ::SkNoncopyable { |
| 16 public: | 16 public: |
| 17 SkCachedData(void* mallocData, size_t size); | 17 SkCachedData(void* mallocData, size_t size); |
| 18 SkCachedData(size_t size, SkDiscardableMemory*); | 18 SkCachedData(size_t size, SkDiscardableMemory*); |
| 19 virtual ~SkCachedData(); | 19 virtual ~SkCachedData(); |
| 20 | 20 |
| 21 size_t size() const { return fSize; } | 21 size_t size() const { return fSize; } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 } | 71 } |
| 72 | 72 |
| 73 class AutoMutexWritable; | 73 class AutoMutexWritable; |
| 74 | 74 |
| 75 public: | 75 public: |
| 76 #ifdef SK_DEBUG | 76 #ifdef SK_DEBUG |
| 77 void validate() const; | 77 void validate() const; |
| 78 #else | 78 #else |
| 79 void validate() const {} | 79 void validate() const {} |
| 80 #endif | 80 #endif |
| 81 | 81 |
| 82 /* | 82 /* |
| 83 * Attaching a data to to a SkResourceCache (only one at a time) enables th
e data to be | 83 * Attaching a data to to a SkResourceCache (only one at a time) enables th
e data to be |
| 84 * unlocked when the cache is the only owner, thus freeing it to be purged
(assuming the | 84 * unlocked when the cache is the only owner, thus freeing it to be purged
(assuming the |
| 85 * data is backed by a SkDiscardableMemory). | 85 * data is backed by a SkDiscardableMemory). |
| 86 * | 86 * |
| 87 * When attached, it also automatically attempts to "lock" the data when th
e first client | 87 * When attached, it also automatically attempts to "lock" the data when th
e first client |
| 88 * ref's the data (typically from a find(key, visitor) call). | 88 * ref's the data (typically from a find(key, visitor) call). |
| 89 * | 89 * |
| 90 * Thus the data will always be "locked" when a non-cache has a ref on it (
whether or not | 90 * Thus the data will always be "locked" when a non-cache has a ref on it (
whether or not |
| 91 * the lock succeeded to recover the memory -- check data() to see if it is
NULL). | 91 * the lock succeeded to recover the memory -- check data() to see if it is
NULL). |
| 92 */ | 92 */ |
| 93 | 93 |
| 94 /* | 94 /* |
| 95 * Call when adding this instance to a SkResourceCache::Rec subclass | 95 * Call when adding this instance to a SkResourceCache::Rec subclass |
| 96 * (typically in the Rec's constructor). | 96 * (typically in the Rec's constructor). |
| 97 */ | 97 */ |
| 98 void attachToCacheAndRef() const { this->internalRef(true); } | 98 void attachToCacheAndRef() const { this->internalRef(true); } |
| 99 | 99 |
| 100 /* | 100 /* |
| 101 * Call when removing this instance from a SkResourceCache::Rec subclass | 101 * Call when removing this instance from a SkResourceCache::Rec subclass |
| 102 * (typically in the Rec's destructor). | 102 * (typically in the Rec's destructor). |
| 103 */ | 103 */ |
| 104 void detachFromCacheAndUnref() const { this->internalUnref(true); } | 104 void detachFromCacheAndUnref() const { this->internalUnref(true); } |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 #endif | 107 #endif |
| OLD | NEW |