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

Side by Side Diff: src/gpu/GrResourceCache.h

Issue 938943002: Allow GrGpuResources' unique keys to be changed. (Closed) Base URL: https://skia.googlesource.com/skia.git@rename
Patch Set: Address comments Created 5 years, 10 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
« no previous file with comments | « src/gpu/GrGpuResourcePriv.h ('k') | src/gpu/GrResourceCache.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2014 Google Inc. 3 * Copyright 2014 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #ifndef GrResourceCache_DEFINED 9 #ifndef GrResourceCache_DEFINED
10 #define GrResourceCache_DEFINED 10 #define GrResourceCache_DEFINED
(...skipping 14 matching lines...) Expand all
25 /** 25 /**
26 * Manages the lifetime of all GrGpuResource instances. 26 * Manages the lifetime of all GrGpuResource instances.
27 * 27 *
28 * Resources may have optionally have two types of keys: 28 * Resources may have optionally have two types of keys:
29 * 1) A scratch key. This is for resources whose allocations are cached but not their contents. 29 * 1) A scratch key. This is for resources whose allocations are cached but not their contents.
30 * Multiple resources can share the same scratch key. This is so a calle r can have two 30 * Multiple resources can share the same scratch key. This is so a calle r can have two
31 * resource instances with the same properties (e.g. multipass rendering that ping-pongs 31 * resource instances with the same properties (e.g. multipass rendering that ping-pongs
32 * between two temporary surfaces). The scratch key is set at resource c reation time and 32 * between two temporary surfaces). The scratch key is set at resource c reation time and
33 * should never change. Resources need not have a scratch key. 33 * should never change. Resources need not have a scratch key.
34 * 2) A unique key. This key's meaning is specific to the domain that creat ed the key. Only one 34 * 2) A unique key. This key's meaning is specific to the domain that creat ed the key. Only one
35 * resource may have a given unique key. The unique key can be set after resource creation 35 * resource may have a given unique key. The unique key can be set, clea red, or changed
36 * creation. Currently it may only be set once and cannot be cleared. Th is restriction will 36 * anytime after resource creation.
37 * be removed. 37 *
38 * A unique key always takes precedence over a scratch key when a resource has b oth types of keys. 38 * A unique key always takes precedence over a scratch key when a resource has b oth types of keys.
39 * If a resource has neither key type then it will be deleted as soon as the las t reference to it 39 * If a resource has neither key type then it will be deleted as soon as the las t reference to it
40 * is dropped. 40 * is dropped.
41 */ 41 */
42 class GrResourceCache { 42 class GrResourceCache {
43 public: 43 public:
44 GrResourceCache(); 44 GrResourceCache();
45 ~GrResourceCache(); 45 ~GrResourceCache();
46 46
47 /** Used to access functionality needed by GrGpuResource for lifetime manage ment. */ 47 /** Used to access functionality needed by GrGpuResource for lifetime manage ment. */
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 #endif 172 #endif
173 173
174 private: 174 private:
175 /////////////////////////////////////////////////////////////////////////// 175 ///////////////////////////////////////////////////////////////////////////
176 /// @name Methods accessible via ResourceAccess 176 /// @name Methods accessible via ResourceAccess
177 //// 177 ////
178 void insertResource(GrGpuResource*); 178 void insertResource(GrGpuResource*);
179 void removeResource(GrGpuResource*); 179 void removeResource(GrGpuResource*);
180 void notifyPurgeable(GrGpuResource*); 180 void notifyPurgeable(GrGpuResource*);
181 void didChangeGpuMemorySize(const GrGpuResource*, size_t oldSize); 181 void didChangeGpuMemorySize(const GrGpuResource*, size_t oldSize);
182 bool didSetUniqueKey(GrGpuResource*); 182 void changeUniqueKey(GrGpuResource*, const GrUniqueKey&);
183 void removeUniqueKey(GrGpuResource*);
183 void willRemoveScratchKey(const GrGpuResource*); 184 void willRemoveScratchKey(const GrGpuResource*);
184 void willRemoveUniqueKey(const GrGpuResource*);
185 void didChangeBudgetStatus(GrGpuResource*); 185 void didChangeBudgetStatus(GrGpuResource*);
186 void refAndMakeResourceMRU(GrGpuResource*); 186 void refAndMakeResourceMRU(GrGpuResource*);
187 /// @} 187 /// @}
188 188
189 void internalPurgeAsNeeded(); 189 void internalPurgeAsNeeded();
190 void processInvalidUniqueKeys(const SkTArray<GrUniqueKeyInvalidatedMessage>& ); 190 void processInvalidUniqueKeys(const SkTArray<GrUniqueKeyInvalidatedMessage>& );
191 void addToNonpurgeableArray(GrGpuResource*); 191 void addToNonpurgeableArray(GrGpuResource*);
192 void removeFromNonpurgeableArray(GrGpuResource*); 192 void removeFromNonpurgeableArray(GrGpuResource*);
193 bool overBudget() const { return fBudgetedBytes > fMaxBytes || fBudgetedCoun t > fMaxCount; } 193 bool overBudget() const { return fBudgetedBytes > fMaxBytes || fBudgetedCoun t > fMaxCount; }
194 194
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 void notifyPurgeable(GrGpuResource* resource) { fCache->notifyPurgeable(reso urce); } 290 void notifyPurgeable(GrGpuResource* resource) { fCache->notifyPurgeable(reso urce); }
291 291
292 /** 292 /**
293 * Called by GrGpuResources when their sizes change. 293 * Called by GrGpuResources when their sizes change.
294 */ 294 */
295 void didChangeGpuMemorySize(const GrGpuResource* resource, size_t oldSize) { 295 void didChangeGpuMemorySize(const GrGpuResource* resource, size_t oldSize) {
296 fCache->didChangeGpuMemorySize(resource, oldSize); 296 fCache->didChangeGpuMemorySize(resource, oldSize);
297 } 297 }
298 298
299 /** 299 /**
300 * Called by GrGpuResources when their unique keys change. 300 * Called by GrGpuResources to change their unique keys.
301 *
302 * This currently returns a bool and fails when an existing resource has a k ey that collides
303 * with the new key. In the future it will null out the unique key for the e xisting resource.
304 * The failure is a temporary measure which will be fixed soon.
305 */ 301 */
306 bool didSetUniqueKey(GrGpuResource* resource) { return fCache->didSetUniqueK ey(resource); } 302 void changeUniqueKey(GrGpuResource* resource, const GrUniqueKey& newKey) {
307 303 fCache->changeUniqueKey(resource, newKey);
308 /**
309 * Called by a GrGpuResource when it removes its unique key.
310 */
311 void willRemoveUniqueKey(GrGpuResource* resource) {
312 return fCache->willRemoveUniqueKey(resource);
313 } 304 }
314 305
315 /** 306 /**
307 * Called by a GrGpuResource to remove its unique key.
308 */
309 void removeUniqueKey(GrGpuResource* resource) { fCache->removeUniqueKey(reso urce); }
310
311 /**
316 * Called by a GrGpuResource when it removes its scratch key. 312 * Called by a GrGpuResource when it removes its scratch key.
317 */ 313 */
318 void willRemoveScratchKey(const GrGpuResource* resource) { 314 void willRemoveScratchKey(const GrGpuResource* resource) {
319 fCache->willRemoveScratchKey(resource); 315 fCache->willRemoveScratchKey(resource);
320 } 316 }
321 317
322 /** 318 /**
323 * Called by GrGpuResources when they change from budgeted to unbudgeted or vice versa. 319 * Called by GrGpuResources when they change from budgeted to unbudgeted or vice versa.
324 */ 320 */
325 void didChangeBudgetStatus(GrGpuResource* resource) { fCache->didChangeBudge tStatus(resource); } 321 void didChangeBudgetStatus(GrGpuResource* resource) { fCache->didChangeBudge tStatus(resource); }
326 322
327 // No taking addresses of this type. 323 // No taking addresses of this type.
328 const ResourceAccess* operator&() const; 324 const ResourceAccess* operator&() const;
329 ResourceAccess* operator&(); 325 ResourceAccess* operator&();
330 326
331 GrResourceCache* fCache; 327 GrResourceCache* fCache;
332 328
333 friend class GrGpuResource; // To access all the proxy inline methods. 329 friend class GrGpuResource; // To access all the proxy inline methods.
334 friend class GrResourceCache; // To create this type. 330 friend class GrResourceCache; // To create this type.
335 }; 331 };
336 332
337 inline GrResourceCache::ResourceAccess GrResourceCache::resourceAccess() { 333 inline GrResourceCache::ResourceAccess GrResourceCache::resourceAccess() {
338 return ResourceAccess(this); 334 return ResourceAccess(this);
339 } 335 }
340 336
341 #endif 337 #endif
OLDNEW
« no previous file with comments | « src/gpu/GrGpuResourcePriv.h ('k') | src/gpu/GrResourceCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698