class SkCachedData; class SkDiscardableMemory; class SkTraceMemoryDump;
/** *Cacheobjectforbitmaps(withpossiblescaleinXYaspartofthekey). * *Multiplecachescanbeinstantiated,buteachinstanceisnotimplicitly *thread-safe,soifagiveninstanceistobesharedacrossthreads,the *callermustmanagetheaccessitself(e.g.viaamutex). * *Asaconvenience,aglobalinstanceisalsodefined,whichcanbesafely *accessacrossthreadsviathestaticmethods(e.g.FindAndLock,etc.).
*/ class SkResourceCache {
public: struct Key { /** Key subclasses must call this after their own fields and data are initialized. *Allfieldsanddatamustbetightlypacked. *@paramnameSpacemustbeuniqueperKeysubclass. *@paramsharedID==0meansignorethisfield,doesnotsupportgrouppurging. *@paramdataSizeissizeoffieldsanddataofthesubclass,mustbeamultipleof4.
*/ void init(void* nameSpace, uint64_t sharedID, size_t dataSize);
/** Returns the size of this key. */
size_t size() const { return fCount32 << 2;
}
// This is only valid after having called init().
uint32_t hash() const { return fHash; }
booloperator==(const Key& other) const { const uint32_t* a = this->as32(); const uint32_t* b = other.as32(); for (int i = 0; i < fCount32; ++i) { // (This checks fCount == other.fCount first.) if (a[i] != b[i]) { returnfalse;
}
} return true;
}
private:
int32_t fCount32; // local + user contents count32
uint32_t fHash; // split uint64_t into hi and lo so we don't force ourselves to pad on 32bit machines.
uint32_t fSharedID_lo;
uint32_t fSharedID_hi; void* fNamespace; // A unique namespace tag. This is hashed. /* uint32_t fContents32[] */
// Called if the cache needs to purge/remove/delete the Rec. Default returns true. // Subclass may return false if there are outstanding references to it (e.g. bitmaps). // Will only be deleted/removed-from-the-cache when this returns true.
virtual bool canBePurged() { return true; }
// A rec is first created/initialized, and then added to the cache. As part of the add(), // the cache will callback into the rec with postAddInstall, passing in whatever payload // was passed to add/Add. // // This late-install callback exists because the process of add-ing might end up deleting // the new rec (if an existing rec in the cache has the same key and cannot be purged). // If the new rec will be deleted during add, the pre-existing one (with the same key) // will have postAddInstall() called on it instead, so that either way an "install" will // happen during the add.
virtual void postAddInstall(void*) {}
/** Dump memory usage statistics of every Rec in the cache using the SkTraceMemoryDumpinterface.
*/ staticvoid DumpMemoryStatistics(SkTraceMemoryDump* dump);
/** *ThisisrespectedbySkBitmapProcState::possiblyScaleImage. *0isnomaximumatall;thisisthedefault. *setSingleAllocationByteLimit()returnsthepreviousvalue.
*/
virtual size_t setSingleAllocationByteLimit(size_t maximumAllocationSize);
virtual size_t getSingleAllocationByteLimit() const; // returns the logical single allocation size (pinning against the budget when the cache // is not backed by discardable memory.
virtual size_t getEffectiveSingleAllocationByteLimit() const;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.