Flutter Engine
The Flutter Engine
|
#include <SkResourceCache.h>
Classes | |
class | Hash |
struct | Key |
struct | PurgeSharedIDMessage |
struct | Rec |
Public Types | |
typedef const Rec * | ID |
typedef bool(* | FindVisitor) (const Rec &, void *context) |
typedef SkDiscardableMemory *(* | DiscardableFactory) (size_t bytes) |
typedef void(* | Visitor) (const Rec &, void *context) |
Public Member Functions | |
SkResourceCache (DiscardableFactory) | |
SkResourceCache (size_t byteLimit) | |
~SkResourceCache () | |
bool | find (const Key &, FindVisitor, void *context) |
void | add (Rec *, void *payload=nullptr) |
void | visitAll (Visitor, void *context) |
size_t | getTotalBytesUsed () const |
size_t | getTotalByteLimit () const |
size_t | setSingleAllocationByteLimit (size_t maximumAllocationSize) |
size_t | getSingleAllocationByteLimit () const |
size_t | getEffectiveSingleAllocationByteLimit () const |
size_t | setTotalByteLimit (size_t newLimit) |
void | purgeSharedID (uint64_t sharedID) |
void | purgeAll () |
DiscardableFactory | discardableFactory () const |
SkCachedData * | newCachedData (size_t bytes) |
void | dump () const |
Static Public Member Functions | |
static bool | Find (const Key &key, FindVisitor, void *context) |
static void | Add (Rec *, void *payload=nullptr) |
static void | VisitAll (Visitor, void *context) |
static size_t | GetTotalBytesUsed () |
static size_t | GetTotalByteLimit () |
static size_t | SetTotalByteLimit (size_t newLimit) |
static size_t | SetSingleAllocationByteLimit (size_t) |
static size_t | GetSingleAllocationByteLimit () |
static size_t | GetEffectiveSingleAllocationByteLimit () |
static void | PurgeAll () |
static void | CheckMessages () |
static void | TestDumpMemoryStatistics () |
static void | DumpMemoryStatistics (SkTraceMemoryDump *dump) |
static DiscardableFactory | GetDiscardableFactory () |
static SkCachedData * | NewCachedData (size_t bytes) |
static void | PostPurgeSharedID (uint64_t sharedID) |
static void | Dump () |
Cache object for bitmaps (with possible scale in X Y as part of the key).
Multiple caches can be instantiated, but each instance is not implicitly thread-safe, so if a given instance is to be shared across threads, the caller must manage the access itself (e.g. via a mutex).
As a convenience, a global instance is also defined, which can be safely access across threads via the static methods (e.g. FindAndLock, etc.).
Definition at line 31 of file SkResourceCache.h.
typedef SkDiscardableMemory *(* SkResourceCache::DiscardableFactory) (size_t bytes) |
Returns a locked/pinned SkDiscardableMemory instance for the specified number of bytes, or nullptr on failure.
Definition at line 138 of file SkResourceCache.h.
typedef bool(* SkResourceCache::FindVisitor) (const Rec &, void *context) |
Callback function for find(). If called, the cache will have found a match for the specified Key, and will pass in the corresponding Rec, along with a caller-specified context. The function can read the data in Rec, and copy whatever it likes into context (casting context to whatever it really is).
The return value determines what the cache will do with the Rec. If the function returns true, then the Rec is considered "valid". If false is returned, the Rec will be considered "stale" and will be purged from the cache.
Definition at line 132 of file SkResourceCache.h.
typedef const Rec* SkResourceCache::ID |
Definition at line 120 of file SkResourceCache.h.
typedef void(* SkResourceCache::Visitor) (const Rec &, void *context) |
Definition at line 157 of file SkResourceCache.h.
SkResourceCache::SkResourceCache | ( | DiscardableFactory | factory | ) |
Construct the cache to call DiscardableFactory when it allocates memory for the pixels. In this mode, the cache has not explicit budget, and so methods like getTotalBytesUsed() and getTotalByteLimit() will return 0, and setTotalByteLimit will ignore its argument and return 0.
Definition at line 105 of file SkResourceCache.cpp.
|
explicit |
Construct the cache, allocating memory with malloc, and respect the byteLimit, purging automatically when a new image is added to the cache that pushes the total bytesUsed over the limit. Note: The limit can be changed at runtime with setTotalByteLimit.
Definition at line 111 of file SkResourceCache.cpp.
SkResourceCache::~SkResourceCache | ( | ) |
Definition at line 117 of file SkResourceCache.cpp.
|
static |
Definition at line 546 of file SkResourceCache.cpp.
void SkResourceCache::add | ( | Rec * | rec, |
void * | payload = nullptr |
||
) |
Definition at line 157 of file SkResourceCache.cpp.
|
static |
Definition at line 536 of file SkResourceCache.cpp.
|
inline |
Definition at line 253 of file SkResourceCache.h.
|
static |
Call SkDebugf() with diagnostic information about the state of the cache
Definition at line 511 of file SkResourceCache.cpp.
void SkResourceCache::dump | ( | ) | const |
Call SkDebugf() with diagnostic information about the state of the cache
Definition at line 423 of file SkResourceCache.cpp.
|
static |
Dump memory usage statistics of every Rec in the cache using the SkTraceMemoryDump interface.
Definition at line 616 of file SkResourceCache.cpp.
bool SkResourceCache::find | ( | const Key & | key, |
FindVisitor | visitor, | ||
void * | context | ||
) |
Returns true if the visitor was called on a matching Key, and the visitor returned true.
find() will search the cache for the specified Key. If no match is found, return false and do not call the FindVisitor. If a match is found, return whatever the visitor returns. Its return value is interpreted to mean: true : Rec is valid false : Rec is "stale" – the cache will purge it.
Definition at line 129 of file SkResourceCache.cpp.
|
static |
Returns true if the visitor was called on a matching Key, and the visitor returned true.
Find() will search the cache for the specified Key. If no match is found, return false and do not call the FindVisitor. If a match is found, return whatever the visitor returns. Its return value is interpreted to mean: true : Rec is valid false : Rec is "stale" – the cache will purge it.
Definition at line 541 of file SkResourceCache.cpp.
|
static |
Returns the DiscardableFactory used by the global cache, or nullptr.
Definition at line 501 of file SkResourceCache.cpp.
|
static |
Definition at line 526 of file SkResourceCache.cpp.
size_t SkResourceCache::getEffectiveSingleAllocationByteLimit | ( | ) | const |
Definition at line 440 of file SkResourceCache.cpp.
|
static |
Definition at line 521 of file SkResourceCache.cpp.
size_t SkResourceCache::getSingleAllocationByteLimit | ( | ) | const |
Definition at line 436 of file SkResourceCache.cpp.
|
static |
Definition at line 491 of file SkResourceCache.cpp.
|
inline |
Definition at line 227 of file SkResourceCache.h.
|
static |
Definition at line 486 of file SkResourceCache.cpp.
|
inline |
Definition at line 226 of file SkResourceCache.h.
|
static |
Definition at line 506 of file SkResourceCache.cpp.
SkCachedData * SkResourceCache::newCachedData | ( | size_t | bytes | ) |
Definition at line 306 of file SkResourceCache.cpp.
|
static |
Definition at line 556 of file SkResourceCache.cpp.
|
static |
Definition at line 531 of file SkResourceCache.cpp.
|
inline |
Definition at line 249 of file SkResourceCache.h.
void SkResourceCache::purgeSharedID | ( | uint64_t | sharedID | ) |
Definition at line 248 of file SkResourceCache.cpp.
size_t SkResourceCache::setSingleAllocationByteLimit | ( | size_t | maximumAllocationSize | ) |
This is respected by SkBitmapProcState::possiblyScaleImage. 0 is no maximum at all; this is the default. setSingleAllocationByteLimit() returns the previous value.
Definition at line 430 of file SkResourceCache.cpp.
|
static |
Definition at line 516 of file SkResourceCache.cpp.
|
static |
Definition at line 496 of file SkResourceCache.cpp.
size_t SkResourceCache::setTotalByteLimit | ( | size_t | newLimit | ) |
Set the maximum number of bytes available to this cache. If the current cache exceeds this new value, it will be purged to try to fit within this new limit.
Definition at line 297 of file SkResourceCache.cpp.
|
static |
Definition at line 596 of file SkResourceCache.cpp.
|
static |
Definition at line 551 of file SkResourceCache.cpp.
void SkResourceCache::visitAll | ( | Visitor | visitor, |
void * | context | ||
) |
Definition at line 285 of file SkResourceCache.cpp.