OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 SkResourceCache_DEFINED | 8 #ifndef SkResourceCache_DEFINED |
9 #define SkResourceCache_DEFINED | 9 #define SkResourceCache_DEFINED |
10 | 10 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 const uint32_t* as32SkipCount() const { return this->as32() + 1; } | 57 const uint32_t* as32SkipCount() const { return this->as32() + 1; } |
58 }; | 58 }; |
59 | 59 |
60 struct Rec { | 60 struct Rec { |
61 typedef SkResourceCache::Key Key; | 61 typedef SkResourceCache::Key Key; |
62 | 62 |
63 Rec() : fLockCount(1) {} | 63 Rec() : fLockCount(1) {} |
64 virtual ~Rec() {} | 64 virtual ~Rec() {} |
65 | 65 |
66 uint32_t getHash() const { return this->getKey().hash(); } | 66 uint32_t getHash() const { return this->getKey().hash(); } |
67 | 67 |
68 virtual const Key& getKey() const = 0; | 68 virtual const Key& getKey() const = 0; |
69 virtual size_t bytesUsed() const = 0; | 69 virtual size_t bytesUsed() const = 0; |
70 | 70 |
71 // for SkTDynamicHash::Traits | 71 // for SkTDynamicHash::Traits |
72 static uint32_t Hash(const Key& key) { return key.hash(); } | 72 static uint32_t Hash(const Key& key) { return key.hash(); } |
73 static const Key& GetKey(const Rec& rec) { return rec.getKey(); } | 73 static const Key& GetKey(const Rec& rec) { return rec.getKey(); } |
74 | 74 |
75 private: | 75 private: |
76 Rec* fNext; | 76 Rec* fNext; |
77 Rec* fPrev; | 77 Rec* fPrev; |
78 int32_t fLockCount; | 78 int32_t fLockCount; |
79 int32_t fPad; | 79 int32_t fPad; |
80 | 80 |
81 friend class SkResourceCache; | 81 friend class SkResourceCache; |
82 }; | 82 }; |
83 | 83 |
84 typedef const Rec* ID; | 84 typedef const Rec* ID; |
85 | 85 |
86 /** | 86 /** |
87 * Returns a locked/pinned SkDiscardableMemory instance for the specified | 87 * Returns a locked/pinned SkDiscardableMemory instance for the specified |
88 * number of bytes, or NULL on failure. | 88 * number of bytes, or NULL on failure. |
89 */ | 89 */ |
90 typedef SkDiscardableMemory* (*DiscardableFactory)(size_t bytes); | 90 typedef SkDiscardableMemory* (*DiscardableFactory)(size_t bytes); |
91 | 91 |
92 /* | 92 /* |
93 * The following static methods are thread-safe wrappers around a global | 93 * The following static methods are thread-safe wrappers around a global |
94 * instance of this cache. | 94 * instance of this cache. |
95 */ | 95 */ |
96 | 96 |
97 static const Rec* FindAndLock(const Key& key); | 97 static const Rec* FindAndLock(const Key& key); |
98 static const Rec* AddAndLock(Rec*); | 98 static const Rec* AddAndLock(Rec*); |
99 static void Add(Rec*); | 99 static void Add(Rec*); |
100 static void Unlock(ID); | 100 static void Unlock(ID); |
101 | 101 |
102 static size_t GetTotalBytesUsed(); | 102 static size_t GetTotalBytesUsed(); |
103 static size_t GetTotalByteLimit(); | 103 static size_t GetTotalByteLimit(); |
104 static size_t SetTotalByteLimit(size_t newLimit); | 104 static size_t SetTotalByteLimit(size_t newLimit); |
105 | 105 |
106 static size_t SetSingleAllocationByteLimit(size_t); | 106 static size_t SetSingleAllocationByteLimit(size_t); |
107 static size_t GetSingleAllocationByteLimit(); | 107 static size_t GetSingleAllocationByteLimit(); |
108 | 108 |
| 109 /** |
| 110 * Use this allocator for bitmaps, so they can use ashmem when available. |
| 111 * Returns NULL if the ResourceCache has not been initialized with a Discard
ableFactory. |
| 112 */ |
109 static SkBitmap::Allocator* GetAllocator(); | 113 static SkBitmap::Allocator* GetAllocator(); |
110 | 114 |
111 /** | 115 /** |
112 * Call SkDebugf() with diagnostic information about the state of the cache | 116 * Call SkDebugf() with diagnostic information about the state of the cache |
113 */ | 117 */ |
114 static void Dump(); | 118 static void Dump(); |
115 | 119 |
116 /////////////////////////////////////////////////////////////////////////// | 120 /////////////////////////////////////////////////////////////////////////// |
117 | 121 |
118 /** | 122 /** |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 199 |
196 void init(); // called by constructors | 200 void init(); // called by constructors |
197 | 201 |
198 #ifdef SK_DEBUG | 202 #ifdef SK_DEBUG |
199 void validate() const; | 203 void validate() const; |
200 #else | 204 #else |
201 void validate() const {} | 205 void validate() const {} |
202 #endif | 206 #endif |
203 }; | 207 }; |
204 #endif | 208 #endif |
OLD | NEW |