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 GrResourceCache_DEFINED | 9 #ifndef GrResourceCache_DEFINED |
10 #define GrResourceCache_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 "GrGpuResourcePriv.h" | 14 #include "GrGpuResourcePriv.h" |
15 #include "GrResourceKey.h" | 15 #include "GrResourceKey.h" |
16 #include "SkMessageBus.h" | 16 #include "SkMessageBus.h" |
17 #include "SkRefCnt.h" | 17 #include "SkRefCnt.h" |
18 #include "SkTArray.h" | 18 #include "SkTArray.h" |
19 #include "SkTDPQueue.h" | 19 #include "SkTDPQueue.h" |
20 #include "SkTInternalLList.h" | 20 #include "SkTInternalLList.h" |
21 #include "SkTMultiMap.h" | 21 #include "SkTMultiMap.h" |
22 | 22 |
| 23 class GrCaps; |
23 class SkString; | 24 class SkString; |
24 | 25 |
25 /** | 26 /** |
26 * Manages the lifetime of all GrGpuResource instances. | 27 * Manages the lifetime of all GrGpuResource instances. |
27 * | 28 * |
28 * Resources may have optionally have two types of keys: | 29 * 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. | 30 * 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 | 31 * 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 | 32 * 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 | 33 * 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. | 34 * 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 | 35 * 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, clea
red, or changed | 36 * resource may have a given unique key. The unique key can be set, clea
red, or changed |
36 * anytime after resource creation. | 37 * anytime after resource creation. |
37 * | 38 * |
38 * A unique key always takes precedence over a scratch key when a resource has b
oth types of keys. | 39 * 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 | 40 * If a resource has neither key type then it will be deleted as soon as the las
t reference to it |
40 * is dropped. | 41 * is dropped. |
41 * | 42 * |
42 * When proactive purging is enabled, on every flush, the timestamp of that flus
h is stored in a | 43 * When proactive purging is enabled, on every flush, the timestamp of that flus
h is stored in a |
43 * n-sized ring buffer. When purging occurs each purgeable resource's timestamp
is compared to the | 44 * n-sized ring buffer. When purging occurs each purgeable resource's timestamp
is compared to the |
44 * timestamp of the n-th prior flush. If the resource's last use timestamp is ol
der than the old | 45 * timestamp of the n-th prior flush. If the resource's last use timestamp is ol
der than the old |
45 * flush then the resource is proactively purged even when the cache is under bu
dget. By default | 46 * flush then the resource is proactively purged even when the cache is under bu
dget. By default |
46 * this feature is disabled, though it can be enabled by calling GrResourceCache
::setLimits. | 47 * this feature is disabled, though it can be enabled by calling GrResourceCache
::setLimits. |
47 */ | 48 */ |
48 class GrResourceCache { | 49 class GrResourceCache { |
49 public: | 50 public: |
50 GrResourceCache(); | 51 GrResourceCache(const GrCaps* caps); |
51 ~GrResourceCache(); | 52 ~GrResourceCache(); |
52 | 53 |
53 // Default maximum number of budgeted resources in the cache. | 54 // Default maximum number of budgeted resources in the cache. |
54 static const int kDefaultMaxCount = 2 * (1 << 12); | 55 static const int kDefaultMaxCount = 2 * (1 << 12); |
55 // Default maximum number of bytes of gpu memory of budgeted resources in th
e cache. | 56 // Default maximum number of bytes of gpu memory of budgeted resources in th
e cache. |
56 static const size_t kDefaultMaxSize = 96 * (1 << 20); | 57 static const size_t kDefaultMaxSize = 96 * (1 << 20); |
57 // Default number of flushes a budgeted resources can go unused in the cache
before it is | 58 // Default number of flushes a budgeted resources can go unused in the cache
before it is |
58 // purged. Large values disable the feature (as the ring buffer of flush tim
estamps would be | 59 // purged. Large values disable the feature (as the ring buffer of flush tim
estamps would be |
59 // large). This is currently the default until we decide to enable this feat
ure | 60 // large). This is currently the default until we decide to enable this feat
ure |
60 // of the cache by default. | 61 // of the cache by default. |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 // We keep track of the "timestamps" of the last n flushes. If a resource ha
sn't been used in | 292 // We keep track of the "timestamps" of the last n flushes. If a resource ha
sn't been used in |
292 // that time then we well preemptively purge it to reduce memory usage. | 293 // that time then we well preemptively purge it to reduce memory usage. |
293 uint32_t* fFlushTimestamps; | 294 uint32_t* fFlushTimestamps; |
294 int fLastFlushTimestampIndex; | 295 int fLastFlushTimestampIndex; |
295 | 296 |
296 InvalidUniqueKeyInbox fInvalidUniqueKeyInbox; | 297 InvalidUniqueKeyInbox fInvalidUniqueKeyInbox; |
297 | 298 |
298 // This resource is allowed to be in the nonpurgeable array for the sake of
validate() because | 299 // This resource is allowed to be in the nonpurgeable array for the sake of
validate() because |
299 // we're in the midst of converting it to purgeable status. | 300 // we're in the midst of converting it to purgeable status. |
300 SkDEBUGCODE(GrGpuResource* fNewlyPurgeableResourceForValidation;) | 301 SkDEBUGCODE(GrGpuResource* fNewlyPurgeableResourceForValidation;) |
| 302 |
| 303 bool fPreferVRAMUseOverFlushes; |
301 }; | 304 }; |
302 | 305 |
303 class GrResourceCache::ResourceAccess { | 306 class GrResourceCache::ResourceAccess { |
304 private: | 307 private: |
305 ResourceAccess(GrResourceCache* cache) : fCache(cache) { } | 308 ResourceAccess(GrResourceCache* cache) : fCache(cache) { } |
306 ResourceAccess(const ResourceAccess& that) : fCache(that.fCache) { } | 309 ResourceAccess(const ResourceAccess& that) : fCache(that.fCache) { } |
307 ResourceAccess& operator=(const ResourceAccess&); // unimpl | 310 ResourceAccess& operator=(const ResourceAccess&); // unimpl |
308 | 311 |
309 /** | 312 /** |
310 * Insert a resource into the cache. | 313 * Insert a resource into the cache. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 | 380 |
378 friend class GrGpuResource; // To access all the proxy inline methods. | 381 friend class GrGpuResource; // To access all the proxy inline methods. |
379 friend class GrResourceCache; // To create this type. | 382 friend class GrResourceCache; // To create this type. |
380 }; | 383 }; |
381 | 384 |
382 inline GrResourceCache::ResourceAccess GrResourceCache::resourceAccess() { | 385 inline GrResourceCache::ResourceAccess GrResourceCache::resourceAccess() { |
383 return ResourceAccess(this); | 386 return ResourceAccess(this); |
384 } | 387 } |
385 | 388 |
386 #endif | 389 #endif |
OLD | NEW |