staticinlinebool SkShouldPostMessageToBus( const SkResourceCache::PurgeSharedIDMessage&, uint32_t) { // SkResourceCache is typically used as a singleton and we don't label Inboxes so all messages // go to all inboxes. returntrue;
}
// This can be defined by the caller's build system //#define SK_USE_DISCARDABLE_SCALEDIMAGECACHE
SkASSERT(rec); // See if we already have this key (racy inserts, etc.) if (Rec** preexisting = fHash->find(rec->getKey())) {
Rec* prev = *preexisting; if (prev->canBePurged()) { // if it can be purged, the install may fail, so we have to remove it
this->remove(prev);
} else { // if it cannot be purged, we reuse it and delete the new one
prev->postAddInstall(payload); delete rec; return;
}
}
void SkResourceCache::purgeAsNeeded(bool forcePurge) {
size_t byteLimit; int countLimit;
if (fDiscardableFactory) {
countLimit = SK_DISCARDABLEMEMORY_SCALEDIMAGECACHE_COUNT_LIMIT;
byteLimit = UINT32_MAX; // no limit based on bytes
} else {
countLimit = SK_MaxS32; // no limit based on count
byteLimit = fTotalByteLimit;
}
Rec* rec = fTail; while (rec) { if (!forcePurge && fTotalBytesUsed < byteLimit && fCount < countLimit) { break;
}
#ifdef SK_TRACK_PURGE_SHAREDID_HITRATE
gPurgeCallCounter += 1; bool found = false; #endif // go backwards, just like purgeAsNeeded, just to make the code similar. // could iterate either direction and still be correct.
Rec* rec = fTail; while (rec) {
Rec* prev = rec->fPrev; if (rec->getKey().getSharedID() == sharedID) { // even though the "src" is now dead, caches could still be in-flight, so // we have to check if it can be removed. if (rec->canBePurged()) {
this->remove(rec);
} #ifdef SK_TRACK_PURGE_SHAREDID_HITRATE
found = true; #endif
}
rec = prev;
}
#ifdef SK_TRACK_PURGE_SHAREDID_HITRATE if (found) {
gPurgeHitCounter += 1;
}
void SkResourceCache::visitAll(Visitor visitor, void* context) { // go backwards, just like purgeAsNeeded, just to make the code similar. // could iterate either direction and still be correct.
Rec* rec = fTail; while (rec) {
visitor(*rec, context);
rec = rec->fPrev;
}
}
size_t SkResourceCache::getEffectiveSingleAllocationByteLimit() const { // fSingleAllocationByteLimit == 0 means the caller is asking for our default
size_t limit = fSingleAllocationByteLimit;
// if we're not discardable (i.e. we are fixed-budget) then cap the single-limit // to our budget. if (nullptr == fDiscardableFactory) { if (0 == limit) {
limit = fTotalByteLimit;
} else {
limit = std::min(limit, fTotalByteLimit);
}
} return limit;
}
void SkResourceCache::checkMessages() {
TArray<PurgeSharedIDMessage> msgs;
fPurgeSharedIDInbox.poll(&msgs); for (int i = 0; i < msgs.size(); ++i) {
this->purgeSharedID(msgs[i].fSharedID);
}
}
/** Must hold resource_cache_mutex() when calling. */ static SkResourceCache* get_cache() { // resource_cache_mutex() is always held when this is called, so we don't need to be fancy in here.
resource_cache_mutex().assertHeld(); if (nullptr == gResourceCache) { #ifdef SK_USE_DISCARDABLE_SCALEDIMAGECACHE
gResourceCache = new SkResourceCache(SkDiscardableMemory::Create); #else
gResourceCache = new SkResourceCache(SK_DEFAULT_IMAGE_CACHE_LIMIT); #endif
} return gResourceCache;
}
// The discardable memory size will be calculated by dumper, but we also dump what we think // the size of object in memory is irrespective of whether object is live or dead.
dump->dumpNumericValue(dumpName.c_str(), "discardable_size", "bytes", rec.bytesUsed());
} else {
dump->dumpNumericValue(dumpName.c_str(), "size", "bytes", rec.bytesUsed());
dump->setMemoryBacking(dumpName.c_str(), "malloc", nullptr);
}
}
void SkResourceCache::DumpMemoryStatistics(SkTraceMemoryDump* dump) { // Since resource could be backed by malloc or discardable, the cache always dumps detailed // stats to be accurate.
VisitAll(sk_trace_dump_visitor, dump);
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.2 Sekunden
(vorverarbeitet)
¤
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.