#include "src/gpu/graphite/ResourceCache.h"
#include "include/private/base/SingleOwner.h"
#include "src/base/SkRandom.h"
#include "src/core/SkTMultiMap.h"
#include "src/core/SkTraceEvent.h"
#include "src/gpu/graphite/GraphiteResourceKey.h"
#include "src/gpu/graphite/ProxyCache.h"
#include "src/gpu/graphite/Resource.h"
#if defined(GPU_TEST_UTILS)
#include "src/gpu/graphite/Texture.h"
#endif
namespace skgpu::graphite {
#define ASSERT_SINGLE_OWNER …
sk_sp<ResourceCache> ResourceCache::Make(SingleOwner* singleOwner,
uint32_t recorderID,
size_t maxBytes) { … }
ResourceCache::ResourceCache(SingleOwner* singleOwner, uint32_t recorderID, size_t maxBytes)
: … { … }
ResourceCache::~ResourceCache() { … }
void ResourceCache::shutdown() { … }
void ResourceCache::insertResource(Resource* resource) { … }
Resource* ResourceCache::findAndRefResource(const GraphiteResourceKey& key,
skgpu::Budgeted budgeted) { … }
void ResourceCache::refAndMakeResourceMRU(Resource* resource) { … }
bool ResourceCache::returnResource(Resource* resource, LastRemovedRef removedRef) { … }
bool ResourceCache::processReturnedResources() { … }
void ResourceCache::returnResourceToCache(Resource* resource, LastRemovedRef removedRef) { … }
void ResourceCache::addToNonpurgeableArray(Resource* resource) { … }
void ResourceCache::removeFromNonpurgeableArray(Resource* resource) { … }
void ResourceCache::removeFromPurgeableQueue(Resource* resource) { … }
bool ResourceCache::inPurgeableQueue(Resource* resource) const { … }
void ResourceCache::purgeResource(Resource* resource) { … }
void ResourceCache::purgeAsNeeded() { … }
void ResourceCache::purgeResourcesNotUsedSince(StdSteadyClock::time_point purgeTime) { … }
void ResourceCache::purgeResources() { … }
void ResourceCache::purgeResources(const StdSteadyClock::time_point* purgeTime) { … }
uint32_t ResourceCache::getNextTimestamp() { … }
void ResourceCache::setResourceTimestamp(Resource* resource, uint32_t timestamp) { … }
void ResourceCache::dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const { … }
const GraphiteResourceKey& ResourceCache::MapTraits::GetKey(const Resource& r) { … }
uint32_t ResourceCache::MapTraits::Hash(const GraphiteResourceKey& key) { … }
bool ResourceCache::CompareTimestamp(Resource* const& a, Resource* const& b) { … }
int* ResourceCache::AccessResourceIndex(Resource* const& res) { … }
#ifdef SK_DEBUG
void ResourceCache::validate() const { … }
bool ResourceCache::isInCache(const Resource* resource) const { … }
#endif
#if defined(GPU_TEST_UTILS)
int ResourceCache::numFindableResources() const {
return fResourceMap.count();
}
void ResourceCache::setMaxBudget(size_t bytes) {
fMaxBytes = bytes;
this->processReturnedResources();
this->purgeAsNeeded();
}
Resource* ResourceCache::topOfPurgeableQueue() {
if (!fPurgeableQueue.count()) {
return nullptr;
}
return fPurgeableQueue.peek();
}
void ResourceCache::visitTextures(
const std::function<void(const Texture*, bool purgeable)>& func) const {
for (int i = 0; i < fNonpurgeableResources.size(); ++i) {
if (const Texture* tex = fNonpurgeableResources[i]->asTexture()) {
func(tex, false);
}
}
for (int i = 0; i < fPurgeableQueue.count(); ++i) {
if (const Texture* tex = fPurgeableQueue.at(i)->asTexture()) {
func(tex, true);
}
}
}
#endif
}