diff --git a/src/gpu/GrGpuResource.cpp b/src/gpu/GrGpuResource.cpp index 97bf078262afa2a722a64f4452fd6b978e15818f..1e5eb7e99e0c4e62ae75925e4773f3a60ab21a34 100644 --- a/src/gpu/GrGpuResource.cpp +++ b/src/gpu/GrGpuResource.cpp @@ -53,11 +53,6 @@ GrGpuResource::~GrGpuResource() { void GrGpuResource::release() { SkASSERT(fGpu); - std::lock_guard lock(mutex_); - if (!fGpu) { - SkDebugf("OHOS GrGpuResource::release(), fGpu == nullptr"); - return; - } this->onRelease(); get_resource_cache(fGpu)->resourceAccess().removeResource(this); fGpu = nullptr; diff --git a/src/gpu/GrGpuResource.h b/src/gpu/GrGpuResource.h index 03611aa8faf7a1960d97f9983526e4d7c52a89af..063b0f69e6a31caff74e045d9bddfaea369ac94d 100644 --- a/src/gpu/GrGpuResource.h +++ b/src/gpu/GrGpuResource.h @@ -11,7 +11,6 @@ #include "include/private/GrResourceKey.h" #include "include/private/GrTypesPriv.h" #include "include/private/SkNoncopyable.h" -#include class GrGpu; class GrResourceCache; @@ -398,7 +397,7 @@ private: // An index into a heap when this resource is purgeable or an array when not. This is maintained // by the cache. - int fCacheArrayIndex = -1; + int fCacheArrayIndex; // This value reflects how recently this resource was accessed in the cache. This is maintained // by the cache. uint32_t fTimestamp; @@ -421,7 +420,6 @@ private: using INHERITED = GrIORef; friend class GrIORef; // to access notifyRefCntWillBeZero and // notifyARefCntIsZero. - std::mutex mutex_; // The gpu cache is released abnormally due to multi threads. bool fRealAlloc = false; // OH ISSUE: real alloc flag size_t fRealAllocSize = 0; // OH ISSUE: real alloc size diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp index 69617cd34c07d6800cdc80ba19caad6f514e9c44..ab315d1301eda392655c5afb9aa1e8aed59b54db 100644 --- a/src/gpu/GrResourceCache.cpp +++ b/src/gpu/GrResourceCache.cpp @@ -630,10 +630,7 @@ void GrResourceCache::insertResource(GrGpuResource* resource) SkASSERT(!this->isInCache(resource)); SkASSERT(!resource->wasDestroyed()); SkASSERT(!resource->resourcePriv().isPurgeable()); - if (!resource || this->isInCache(resource) || resource->wasDestroyed() || resource->resourcePriv().isPurgeable()) { - SkDebugf("OHOS GrResourceCache::insertResource resource is invalid!!!"); - return; - } + // We must set the timestamp before adding to the array in case the timestamp wraps and we wind // up iterating over all the resources that already have timestamps. resource->cacheAccess().setTimestamp(this->getNextTimestamp()); @@ -701,10 +698,10 @@ void GrResourceCache::removeResource(GrGpuResource* resource) { SkASSERT(this->isInCache(resource)); size_t size = resource->gpuMemorySize(); - if (resource->resourcePriv().isPurgeable() && this->isInPurgeableCache(resource)) { + if (resource->resourcePriv().isPurgeable()) { fPurgeableQueue.remove(resource); fPurgeableBytes -= size; - } else if (this->isInNonpurgeableCache(resource)) { + } else { this->removeFromNonpurgeableArray(resource); } @@ -944,10 +941,6 @@ GrGpuResource* GrResourceCache::findAndRefScratchResource(const GrScratchKey& sc GrGpuResource* resource = fScratchMap.find(scratchKey, AvailableForScratchUse()); if (resource) { fScratchMap.remove(scratchKey, resource); - if (!this->isInCache(resource)) { - SkDebugf("OHOS GrResourceCache::findAndRefScratchResource not in cache, return!!!"); - return nullptr; - } this->refAndMakeResourceMRU(resource); this->validate(); } @@ -1031,15 +1024,9 @@ void GrResourceCache::refAndMakeResourceMRU(GrGpuResource* resource) { if (resource->resourcePriv().isPurgeable()) { // It's about to become unpurgeable. - if (this->isInPurgeableCache(resource)) { - fPurgeableBytes -= resource->gpuMemorySize(); - fPurgeableQueue.remove(resource); - } - if (!this->isInNonpurgeableCache(resource)) { - this->addToNonpurgeableArray(resource); - } else { - SkDebugf("OHOS resource in isInNonpurgeableCache, do not add again!"); - } + fPurgeableBytes -= resource->gpuMemorySize(); + fPurgeableQueue.remove(resource); + this->addToNonpurgeableArray(resource); } else if (!resource->cacheAccess().hasRefOrCommandBufferUsage() && resource->resourcePriv().budgetedType() == GrBudgetedType::kBudgeted) { SkASSERT(fNumBudgetedResourcesFlushWillMakePurgeable > 0); @@ -1060,11 +1047,7 @@ void GrResourceCache::notifyARefCntReachedZero(GrGpuResource* resource, // This resource should always be in the nonpurgeable array when this function is called. It // will be moved to the queue if it is newly purgeable. SkASSERT(fNonpurgeableResources[*resource->cacheAccess().accessCacheIndex()] == resource); - if (!resource || resource->wasDestroyed() || this->isInPurgeableCache(resource) || - !this->isInNonpurgeableCache(resource)) { - SkDebugf("OHOS GrResourceCache::notifyARefCntReachedZero return!"); - return; - } + if (removedRef == GrGpuResource::LastRemovedRef::kMainRef) { if (resource->cacheAccess().isUsableAsScratch()) { fScratchMap.insert(resource->resourcePriv().getScratchKey(), resource); @@ -1240,10 +1223,6 @@ void GrResourceCache::purgeAsNeeded(const std::function& nextFrameHa bool stillOverbudget = this->overBudget(nextFrameHasArrived); while (stillOverbudget && fPurgeableQueue.count() && this->allowToPurge(nextFrameHasArrived)) { GrGpuResource* resource = fPurgeableQueue.peek(); - if (!resource->resourcePriv().isPurgeable()) { - SkDebugf("OHOS GrResourceCache::purgeAsNeeded() resource is nonPurgeable"); - continue; - } SkASSERT(resource->resourcePriv().isPurgeable()); resource->cacheAccess().release(); stillOverbudget = this->overBudget(nextFrameHasArrived); @@ -1255,10 +1234,6 @@ void GrResourceCache::purgeAsNeeded(const std::function& nextFrameHa stillOverbudget = this->overBudget(nextFrameHasArrived); while (stillOverbudget && fPurgeableQueue.count() && this->allowToPurge(nextFrameHasArrived)) { GrGpuResource* resource = fPurgeableQueue.peek(); - if (!resource->resourcePriv().isPurgeable()) { - SkDebugf("OHOS GrResourceCache::purgeAsNeeded() resource is nonPurgeable after dropUniqueRefs"); - continue; - } SkASSERT(resource->resourcePriv().isPurgeable()); resource->cacheAccess().release(); stillOverbudget = this->overBudget(nextFrameHasArrived); @@ -1887,7 +1862,6 @@ void GrResourceCache::validate() const { // bool overBudget = budgetedBytes > fMaxBytes || budgetedCount > fMaxCount; // SkASSERT(!overBudget || locked == count || fPurging); } -#endif // SK_DEBUG bool GrResourceCache::isInCache(const GrGpuResource* resource) const { int index = *resource->cacheAccess().accessCacheIndex(); @@ -1904,29 +1878,7 @@ bool GrResourceCache::isInCache(const GrGpuResource* resource) const { return false; } -bool GrResourceCache::isInPurgeableCache(const GrGpuResource* resource) const { - int index = *resource->cacheAccess().accessCacheIndex(); - if (index < 0) { - return false; - } - if (index < fPurgeableQueue.count() && fPurgeableQueue.at(index) == resource) { - return true; - } - SkDEBUGFAIL("OHOS Resource index should be -1 or the resource should be in the cache."); - return false; -} - -bool GrResourceCache::isInNonpurgeableCache(const GrGpuResource* resource) const { - int index = *resource->cacheAccess().accessCacheIndex(); - if (index < 0) { - return false; - } - if (index < fNonpurgeableResources.count() && fNonpurgeableResources[index] == resource) { - return true; - } - SkDEBUGFAIL("OHOS Resource index should be -1 or the resource should be in the cache."); - return false; -} +#endif // SK_DEBUG #if GR_TEST_UTILS diff --git a/src/gpu/GrResourceCache.h b/src/gpu/GrResourceCache.h index fb3924a9109a0c533db9034abdb48107a3180dbd..4c348596c1ba600e150d68f70779f53fb11ad2dc 100644 --- a/src/gpu/GrResourceCache.h +++ b/src/gpu/GrResourceCache.h @@ -175,12 +175,10 @@ public: */ GrGpuResource* findAndRefUniqueResource(const GrUniqueKey& key) { GrGpuResource* resource = fUniqueHash.find(key); - if (resource && this->isInCache(resource)) { + if (resource) { this->refAndMakeResourceMRU(resource); - return resource; } - SK_LOGD("OHOS resource is not in cache, return nullptr!"); - return nullptr; + return resource; } /** @@ -385,10 +383,8 @@ private: void purgeUnlockedResources(const GrStdSteadyClock::time_point* purgeTime, bool scratchResourcesOnly); - bool isInCache(const GrGpuResource* r) const; - bool isInPurgeableCache(const GrGpuResource* r) const; - bool isInNonpurgeableCache(const GrGpuResource* r) const; #ifdef SK_DEBUG + bool isInCache(const GrGpuResource* r) const; void validate() const; #else void validate() const {}