Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: src/core/SkResourceCache.h

Issue 825263005: notify resource caches when pixelref genID goes stale (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 17 matching lines...) Expand all
28 public: 28 public:
29 struct Key { 29 struct Key {
30 // Call this to access your private contents. Must not use the address a fter calling init() 30 // Call this to access your private contents. Must not use the address a fter calling init()
31 void* writableContents() { return this + 1; } 31 void* writableContents() { return this + 1; }
32 32
33 // must call this after your private data has been written. 33 // must call this after your private data has been written.
34 // nameSpace must be unique per Key subclass. 34 // nameSpace must be unique per Key subclass.
35 // length must be a multiple of 4 35 // length must be a multiple of 4
36 void init(void* nameSpace, size_t length); 36 void init(void* nameSpace, size_t length);
37 37
38 void* getNamespace() const { return fNamespace; }
39
38 // This is only valid after having called init(). 40 // This is only valid after having called init().
39 uint32_t hash() const { return fHash; } 41 uint32_t hash() const { return fHash; }
40 42
41 bool operator==(const Key& other) const { 43 bool operator==(const Key& other) const {
42 const uint32_t* a = this->as32(); 44 const uint32_t* a = this->as32();
43 const uint32_t* b = other.as32(); 45 const uint32_t* b = other.as32();
44 for (int i = 0; i < fCount32; ++i) { // (This checks fCount == othe r.fCount first.) 46 for (int i = 0; i < fCount32; ++i) { // (This checks fCount == othe r.fCount first.)
45 if (a[i] != b[i]) { 47 if (a[i] != b[i]) {
46 return false; 48 return false;
47 } 49 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 static bool Find(const Key& key, VisitorProc, void* context); 119 static bool Find(const Key& key, VisitorProc, void* context);
118 static void Add(Rec*); 120 static void Add(Rec*);
119 121
120 static size_t GetTotalBytesUsed(); 122 static size_t GetTotalBytesUsed();
121 static size_t GetTotalByteLimit(); 123 static size_t GetTotalByteLimit();
122 static size_t SetTotalByteLimit(size_t newLimit); 124 static size_t SetTotalByteLimit(size_t newLimit);
123 125
124 static size_t SetSingleAllocationByteLimit(size_t); 126 static size_t SetSingleAllocationByteLimit(size_t);
125 static size_t GetSingleAllocationByteLimit(); 127 static size_t GetSingleAllocationByteLimit();
126 128
129 /**
130 * Visit all Rec that match the specified namespace:
131 * true : Rec is valid
mtklein 2015/01/07 21:52:43 I think everything might read more clearly if we h
reed1 2015/01/07 22:20:41 I agree 0.499999, but Find uses the same VisitorPr
mtklein 2015/01/08 14:11:12 Do you think we'll ever want to pass the same func
reed1 2015/02/18 17:30:32 Changed to new signature.
132 * false : Rec is "stale" -- the cache will purge it.
133 */
134 static void PurgeVisitor(const void* nameSpace, VisitorProc, void* context);
135
127 static void PurgeAll(); 136 static void PurgeAll();
128 137
129 /** 138 /**
130 * Returns the DiscardableFactory used by the global cache, or NULL. 139 * Returns the DiscardableFactory used by the global cache, or NULL.
131 */ 140 */
132 static DiscardableFactory GetDiscardableFactory(); 141 static DiscardableFactory GetDiscardableFactory();
133 142
134 /** 143 /**
135 * Use this allocator for bitmaps, so they can use ashmem when available. 144 * Use this allocator for bitmaps, so they can use ashmem when available.
136 * Returns NULL if the ResourceCache has not been initialized with a Discard ableFactory. 145 * Returns NULL if the ResourceCache has not been initialized with a Discard ableFactory.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 */ 195 */
187 size_t setSingleAllocationByteLimit(size_t maximumAllocationSize); 196 size_t setSingleAllocationByteLimit(size_t maximumAllocationSize);
188 size_t getSingleAllocationByteLimit() const; 197 size_t getSingleAllocationByteLimit() const;
189 /** 198 /**
190 * Set the maximum number of bytes available to this cache. If the current 199 * Set the maximum number of bytes available to this cache. If the current
191 * cache exceeds this new value, it will be purged to try to fit within 200 * cache exceeds this new value, it will be purged to try to fit within
192 * this new limit. 201 * this new limit.
193 */ 202 */
194 size_t setTotalByteLimit(size_t newLimit); 203 size_t setTotalByteLimit(size_t newLimit);
195 204
205 void purgeVisitor(const void* nameSpace, VisitorProc, void* context);
206
196 void purgeAll() { 207 void purgeAll() {
197 this->purgeAsNeeded(true); 208 this->purgeAsNeeded(true);
198 } 209 }
199 210
200 DiscardableFactory discardableFactory() const { return fDiscardableFactory; } 211 DiscardableFactory discardableFactory() const { return fDiscardableFactory; }
201 SkBitmap::Allocator* allocator() const { return fAllocator; }; 212 SkBitmap::Allocator* allocator() const { return fAllocator; };
202 213
203 SkCachedData* newCachedData(size_t bytes); 214 SkCachedData* newCachedData(size_t bytes);
204 215
205 /** 216 /**
(...skipping 27 matching lines...) Expand all
233 244
234 void init(); // called by constructors 245 void init(); // called by constructors
235 246
236 #ifdef SK_DEBUG 247 #ifdef SK_DEBUG
237 void validate() const; 248 void validate() const;
238 #else 249 #else
239 void validate() const {} 250 void validate() const {}
240 #endif 251 #endif
241 }; 252 };
242 #endif 253 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698