OLD | NEW |
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 GrResourceCache2_DEFINED | 9 #ifndef GrResourceCache_DEFINED |
10 #define GrResourceCache2_DEFINED | 10 #define GrResourceCache_DEFINED |
11 | 11 |
12 #include "GrGpuResource.h" | 12 #include "GrGpuResource.h" |
13 #include "GrGpuResourceCacheAccess.h" | 13 #include "GrGpuResourceCacheAccess.h" |
14 #include "GrResourceKey.h" | 14 #include "GrResourceKey.h" |
15 #include "SkMessageBus.h" | 15 #include "SkMessageBus.h" |
16 #include "SkRefCnt.h" | 16 #include "SkRefCnt.h" |
17 #include "SkTArray.h" | 17 #include "SkTArray.h" |
18 #include "SkTInternalLList.h" | 18 #include "SkTInternalLList.h" |
19 #include "SkTMultiMap.h" | 19 #include "SkTMultiMap.h" |
20 | 20 |
21 class SkString; | 21 class SkString; |
22 | 22 |
23 /** | 23 /** |
24 * Manages the lifetime of all GrGpuResource instances. | 24 * Manages the lifetime of all GrGpuResource instances. |
25 * | 25 * |
26 * Resources may have optionally have two types of keys: | 26 * Resources may have optionally have two types of keys: |
27 * 1) A scratch key. This is for resources whose allocations are cached but
not their contents. | 27 * 1) A scratch key. This is for resources whose allocations are cached but
not their contents. |
28 * Multiple resources can share the same scratch key. This is so a calle
r can have two | 28 * Multiple resources can share the same scratch key. This is so a calle
r can have two |
29 * resource instances with the same properties (e.g. multipass rendering
that ping-pongs | 29 * resource instances with the same properties (e.g. multipass rendering
that ping-pongs |
30 * between two temporary surfaces. The scratch key is set at resource cr
eation time and | 30 * between two temporary surfaces. The scratch key is set at resource cr
eation time and |
31 * should never change. Resources need not have a scratch key. | 31 * should never change. Resources need not have a scratch key. |
32 * 2) A content key. This key represents the contents of the resource rathe
r than just its | 32 * 2) A content key. This key represents the contents of the resource rathe
r than just its |
33 * allocation properties. They may not collide. The content key can be s
et after resource | 33 * allocation properties. They may not collide. The content key can be s
et after resource |
34 * creation. Currently it may only be set once and cannot be cleared. Th
is restriction will | 34 * creation. Currently it may only be set once and cannot be cleared. Th
is restriction will |
35 * be removed. | 35 * be removed. |
36 * If a resource has neither key type then it will be deleted as soon as the las
t reference to it | 36 * If a resource has neither key type then it will be deleted as soon as the las
t reference to it |
37 * is dropped. If a key has both keys the content key takes precedence. | 37 * is dropped. If a key has both keys the content key takes precedence. |
38 */ | 38 */ |
39 class GrResourceCache2 { | 39 class GrResourceCache { |
40 public: | 40 public: |
41 GrResourceCache2(); | 41 GrResourceCache(); |
42 ~GrResourceCache2(); | 42 ~GrResourceCache(); |
43 | 43 |
44 /** Used to access functionality needed by GrGpuResource for lifetime manage
ment. */ | 44 /** Used to access functionality needed by GrGpuResource for lifetime manage
ment. */ |
45 class ResourceAccess; | 45 class ResourceAccess; |
46 ResourceAccess resourceAccess(); | 46 ResourceAccess resourceAccess(); |
47 | 47 |
48 /** | 48 /** |
49 * Sets the cache limits in terms of number of resources and max gpu memory
byte size. | 49 * Sets the cache limits in terms of number of resources and max gpu memory
byte size. |
50 */ | 50 */ |
51 void setLimits(int count, size_t bytes); | 51 void setLimits(int count, size_t bytes); |
52 | 52 |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 bool fPurging; | 247 bool fPurging; |
248 bool fNewlyPurgeableResourceWhilePurging; | 248 bool fNewlyPurgeableResourceWhilePurging; |
249 | 249 |
250 PFOverBudgetCB fOverBudgetCB; | 250 PFOverBudgetCB fOverBudgetCB; |
251 void* fOverBudgetData; | 251 void* fOverBudgetData; |
252 | 252 |
253 InvalidContentKeyInbox fInvalidContentKeyInbox; | 253 InvalidContentKeyInbox fInvalidContentKeyInbox; |
254 | 254 |
255 }; | 255 }; |
256 | 256 |
257 class GrResourceCache2::ResourceAccess { | 257 class GrResourceCache::ResourceAccess { |
258 private: | 258 private: |
259 ResourceAccess(GrResourceCache2* cache) : fCache(cache) { } | 259 ResourceAccess(GrResourceCache* cache) : fCache(cache) { } |
260 ResourceAccess(const ResourceAccess& that) : fCache(that.fCache) { } | 260 ResourceAccess(const ResourceAccess& that) : fCache(that.fCache) { } |
261 ResourceAccess& operator=(const ResourceAccess&); // unimpl | 261 ResourceAccess& operator=(const ResourceAccess&); // unimpl |
262 | 262 |
263 /** | 263 /** |
264 * Insert a resource into the cache. | 264 * Insert a resource into the cache. |
265 */ | 265 */ |
266 void insertResource(GrGpuResource* resource) { fCache->insertResource(resour
ce); } | 266 void insertResource(GrGpuResource* resource) { fCache->insertResource(resour
ce); } |
267 | 267 |
268 /** | 268 /** |
269 * Removes a resource from the cache. | 269 * Removes a resource from the cache. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 | 308 |
309 /** | 309 /** |
310 * Called by GrGpuResources when they change from budgeted to unbudgeted or
vice versa. | 310 * Called by GrGpuResources when they change from budgeted to unbudgeted or
vice versa. |
311 */ | 311 */ |
312 void didChangeBudgetStatus(GrGpuResource* resource) { fCache->didChangeBudge
tStatus(resource); } | 312 void didChangeBudgetStatus(GrGpuResource* resource) { fCache->didChangeBudge
tStatus(resource); } |
313 | 313 |
314 // No taking addresses of this type. | 314 // No taking addresses of this type. |
315 const ResourceAccess* operator&() const; | 315 const ResourceAccess* operator&() const; |
316 ResourceAccess* operator&(); | 316 ResourceAccess* operator&(); |
317 | 317 |
318 GrResourceCache2* fCache; | 318 GrResourceCache* fCache; |
319 | 319 |
320 friend class GrGpuResource; // To access all the proxy inline methods. | 320 friend class GrGpuResource; // To access all the proxy inline methods. |
321 friend class GrResourceCache2; // To create this type. | 321 friend class GrResourceCache; // To create this type. |
322 }; | 322 }; |
323 | 323 |
324 inline GrResourceCache2::ResourceAccess GrResourceCache2::resourceAccess() { | 324 inline GrResourceCache::ResourceAccess GrResourceCache::resourceAccess() { |
325 return ResourceAccess(this); | 325 return ResourceAccess(this); |
326 } | 326 } |
327 | 327 |
328 #endif | 328 #endif |
OLD | NEW |