Flutter Engine
The Flutter Engine
|
#include <GrResourceCache.h>
Classes | |
class | ResourceAccess |
class | UnrefResourceMessage |
Static Public Member Functions | |
template<typename T > | |
static std::enable_if_t< std::is_base_of_v< GrGpuResource, T >, void > | ReturnResourceFromThread (sk_sp< T > &&resource, GrDirectContext::DirectContextID id) |
Static Public Attributes | |
static const size_t | kDefaultMaxSize = 256 * (1 << 20) |
Private Member Functions | |
SkDEBUGCODE (int fCount=0;) size_t fBytes=0 | |
Methods accessible via ResourceAccess | |
/ |
Manages the lifetime of all GrGpuResource instances.
Resources may have optionally have two types of keys: 1) A scratch key. This is for resources whose allocations are cached but not their contents. Multiple resources can share the same scratch key. This is so a caller can have two resource instances with the same properties (e.g. multipass rendering that ping-pongs between two temporary surfaces). The scratch key is set at resource creation time and should never change. Resources need not have a scratch key. 2) A unique key. This key's meaning is specific to the domain that created the key. Only one resource may have a given unique key. The unique key can be set, cleared, or changed anytime after resource creation.
A unique key always takes precedence over a scratch key when a resource has both types of keys. If a resource has neither key type then it will be deleted as soon as the last reference to it is dropped.
Definition at line 53 of file GrResourceCache.h.
GrResourceCache::GrResourceCache | ( | skgpu::SingleOwner * | owner, |
GrDirectContext::DirectContextID | owningContextID, | ||
uint32_t | familyID | ||
) |
GrResourceCache::~GrResourceCache | ( | ) |
Definition at line 62 of file GrResourceCache.cpp.
void GrResourceCache::abandonAll | ( | ) |
Abandons the backend API resources owned by all GrGpuResource objects and removes them from the cache.
Definition at line 136 of file GrResourceCache.cpp.
|
inline |
Unique ID of the owning GrContext.
Definition at line 87 of file GrResourceCache.h.
void GrResourceCache::dumpMemoryStatistics | ( | SkTraceMemoryDump * | traceMemoryDump | ) | const |
Definition at line 723 of file GrResourceCache.cpp.
GrGpuResource * GrResourceCache::findAndRefScratchResource | ( | const skgpu::ScratchKey & | scratchKey | ) |
Find a resource that matches a scratch key.
Definition at line 210 of file GrResourceCache.cpp.
|
inline |
Find a resource that matches a unique key.
Definition at line 151 of file GrResourceCache.h.
|
inline |
Returns the number of bytes consumed by budgeted resources.
Definition at line 117 of file GrResourceCache.h.
|
inline |
Returns the number of resources that count against the budget.
Definition at line 102 of file GrResourceCache.h.
|
inline |
Returns the number of bytes consumed by cached resources.
Definition at line 122 of file GrResourceCache.h.
|
inline |
Returns the number of bytes held by unlocked resources which are available for purging.
Definition at line 112 of file GrResourceCache.h.
|
inline |
Returns the number of bytes consumed by resources.
Definition at line 107 of file GrResourceCache.h.
|
inline |
Returns the number of resources.
Definition at line 95 of file GrResourceCache.h.
|
inline |
|
inline |
Definition at line 190 of file GrResourceCache.h.
void GrResourceCache::purgeAsNeeded | ( | ) |
Purges resources to become under budget and processes resources with invalidated unique keys.
Definition at line 441 of file GrResourceCache.cpp.
|
inline |
Definition at line 180 of file GrResourceCache.h.
bool GrResourceCache::purgeToMakeHeadroom | ( | size_t | desiredHeadroomBytes | ) |
If it's possible to purge enough resources to get the provided amount of budget headroom, do so and return true. If it's not possible, do nothing and return false.
Definition at line 552 of file GrResourceCache.cpp.
|
inline |
Definition at line 173 of file GrResourceCache.h.
void GrResourceCache::purgeUnlockedResources | ( | size_t | bytesToPurge, |
bool | preferScratchResources | ||
) |
Purge unlocked resources from the cache until the the provided byte count has been reached or we have purged all unlocked resources. The default policy is to purge in LRU order, but can be overridden to prefer purging scratch resources (in LRU order) prior to purging other resource types.
maxBytesToPurge | the desired number of bytes to be purged. |
preferScratchResources | If true scratch resources will be purged prior to other resource types. |
Definition at line 591 of file GrResourceCache.cpp.
void GrResourceCache::releaseAll | ( | ) |
Releases the backend API resources owned by all GrGpuResource objects and removes them from the cache.
Definition at line 163 of file GrResourceCache.cpp.
bool GrResourceCache::requestsFlush | ( | ) | const |
Returns true if the cache would like a flush to occur in order to make more resources purgeable.
Definition at line 632 of file GrResourceCache.cpp.
|
inline |
Definition at line 487 of file GrResourceCache.h.
|
inlinestatic |
This is used to safely return a resource to the cache when the owner may be on another thread from GrDirectContext. If the context still exists then using this method ensures that the resource is received by the cache for processing (recycling or destruction) on the context's thread.
This is templated as it is rather than simply taking sk_sp<GrGpuResource> in order to enforce that the caller passes an rvalue. If the caller doesn't move its ref into this function then it will retain ownership, defeating the purpose. (Note that sk_sp<GrGpuResource>&& doesn't work either because calling with sk_sp<GrSpecificResource> will create a temporary sk_sp<GrGpuResource> which is an rvalue).
Definition at line 74 of file GrResourceCache.h.
void GrResourceCache::setLimit | ( | size_t | bytes | ) |
Sets the max gpu memory byte size of the cache.
Definition at line 66 of file GrResourceCache.cpp.
|
inline |
Definition at line 264 of file GrResourceCache.h.
|
inline |
Definition at line 265 of file GrResourceCache.h.
|
privatepure virtual |
|
static |
Definition at line 80 of file GrResourceCache.h.