From fa2ebeaf33e1f1c330c18b676e3fe60db52d5ac2 Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Thu, 24 Jan 2019 15:58:58 -0500 Subject: [PATCH] Replace bool purgeImmediately with enum GrWrapCacheable. Store budgeted status as a tri-state enum on GrGpuResource: kBudgeted kUnbudgetedCacheable kUnbudgetedUncacheable Uncacheable vs. Cacheable captures the current distinction between wrapped resources created with purgeImmediately or !purgeImmediately. Non-wrapped and unbudgeted resources are all kUnbudgetedCacheable to match current behavior. This change just introduces the new types. No behavior is changed. Bug: chromium:922851 Change-Id: Ic2387bf321cf9b56b4c9ffd9dbef8ade60f9cb98 Reviewed-on: https://skia-review.googlesource.com/c/185003 Commit-Queue: Brian Salomon Reviewed-by: Robert Phillips --- include/gpu/GrGpuResource.h | 10 +++--- include/private/GrTypesPriv.h | 30 ++++++++++++++++ src/gpu/GrBackendTextureImageGenerator.cpp | 4 ++- src/gpu/GrGpu.cpp | 7 ++-- src/gpu/GrGpu.h | 6 ++-- src/gpu/GrGpuResource.cpp | 39 ++++++++++----------- src/gpu/GrGpuResourceCacheAccess.h | 7 +--- src/gpu/GrGpuResourcePriv.h | 11 +++--- src/gpu/GrProxyProvider.cpp | 13 +++---- src/gpu/GrResourceAllocator.cpp | 4 +-- src/gpu/GrResourceCache.cpp | 31 ++++++++-------- src/gpu/GrResourceCache.h | 2 +- src/gpu/GrResourceProvider.cpp | 4 +-- src/gpu/GrResourceProvider.h | 2 +- src/gpu/GrSurfaceProxy.cpp | 4 ++- src/gpu/gl/GrGLGpu.cpp | 8 ++--- src/gpu/gl/GrGLGpu.h | 4 +-- src/gpu/gl/GrGLTexture.cpp | 12 +++---- src/gpu/gl/GrGLTexture.h | 7 ++-- src/gpu/mock/GrMockGpu.cpp | 7 ++-- src/gpu/mock/GrMockGpu.h | 4 +-- src/gpu/mock/GrMockTexture.h | 7 ++-- src/gpu/mtl/GrMtlGpu.h | 4 +-- src/gpu/mtl/GrMtlGpu.mm | 6 ++-- src/gpu/mtl/GrMtlTexture.h | 4 +-- src/gpu/mtl/GrMtlTexture.mm | 14 ++++---- src/gpu/vk/GrVkGpu.cpp | 8 ++--- src/gpu/vk/GrVkGpu.h | 4 +-- src/gpu/vk/GrVkTexture.cpp | 27 +++++--------- src/gpu/vk/GrVkTexture.h | 11 +++--- tests/GrSurfaceTest.cpp | 7 +++- tests/GrTestingBackendTextureUploadTest.cpp | 2 +- tests/LazyProxyTest.cpp | 5 +-- tests/ResourceCacheTest.cpp | 11 +++--- tests/TraceMemoryDumpTest.cpp | 2 +- tests/VkWrapTests.cpp | 19 ++++++---- 36 files changed, 187 insertions(+), 160 deletions(-) diff --git a/include/gpu/GrGpuResource.h b/include/gpu/GrGpuResource.h index 6271db8649..d2054955c9 100644 --- a/include/gpu/GrGpuResource.h +++ b/include/gpu/GrGpuResource.h @@ -141,7 +141,6 @@ private: */ class SK_API GrGpuResource : public GrIORef { public: - /** * Tests whether a object has been abandoned or released. All objects will * be in this state after their creating GrContext is destroyed or has @@ -265,7 +264,7 @@ protected: // This must be called by every GrGpuObject that references any wrapped backend objects. It // should be called once the object is fully initialized (i.e. only from the constructors of the // final class). - void registerWithCacheWrapped(bool purgeImmediately = false); + void registerWithCacheWrapped(GrWrapCacheable = GrWrapCacheable::kYes); GrGpuResource(GrGpu*); virtual ~GrGpuResource(); @@ -349,11 +348,10 @@ private: // This is not ref'ed but abandon() or release() will be called before the GrGpu object // is destroyed. Those calls set will this to NULL. GrGpu* fGpu; - mutable size_t fGpuMemorySize; + mutable size_t fGpuMemorySize = kInvalidGpuMemorySize; - SkBudgeted fBudgeted; - bool fShouldPurgeImmediately; - bool fRefsWrappedObjects; + GrBudgetedType fBudgetedType = GrBudgetedType::kUnbudgetedCacheable; + bool fRefsWrappedObjects = false; const UniqueID fUniqueID; typedef GrIORef INHERITED; diff --git a/include/private/GrTypesPriv.h b/include/private/GrTypesPriv.h index 55d0c40789..73cde77a80 100644 --- a/include/private/GrTypesPriv.h +++ b/include/private/GrTypesPriv.h @@ -197,6 +197,36 @@ enum GrWrapOwnership { kAdopt_GrWrapOwnership, }; +enum class GrWrapCacheable : bool { + /** + * The wrapped resource will be removed from the cache as soon as it becomes purgeable. It may + * still be assigned and found by a unique key, but the presence of the key will not be used to + * keep the resource alive when it has no references. + */ + kNo = false, + /** + * The wrapped resource is allowed to remain in the GrResourceCache when it has no references + * but has a unique key. Such resources should only be given unique keys when it is known that + * the key will eventually be removed from the resource or invalidated via the message bus. + */ + kYes = true +}; + +enum class GrBudgetedType : uint8_t { + /** The resource is budgeted and is subject to purging under budget pressure. */ + kBudgeted, + /** + * The resource is unbudgeted and is purged as soon as it has no refs regardless of whether + * it has a unique or scratch key. + */ + kUnbudgetedUncacheable, + /** + * The resource is unbudgeted and is allowed to remain in the cache with no refs if it + * has a unique key. Scratch keys are ignored. + */ + kUnbudgetedCacheable, +}; + /** * Clips are composed from these objects. */ diff --git a/src/gpu/GrBackendTextureImageGenerator.cpp b/src/gpu/GrBackendTextureImageGenerator.cpp index f191174f66..291f013ac1 100644 --- a/src/gpu/GrBackendTextureImageGenerator.cpp +++ b/src/gpu/GrBackendTextureImageGenerator.cpp @@ -167,8 +167,10 @@ sk_sp GrBackendTextureImageGenerator::onGenerateTexture( // informs us that the context is done with it. This is unfortunate - we'll have // two texture objects referencing the same GPU object. However, no client can // ever see the original texture, so this should be safe. + // We make the texture uncacheable so that the release proc is called ASAP. tex = resourceProvider->wrapBackendTexture( - backendTexture, kBorrow_GrWrapOwnership, kRead_GrIOType, true); + backendTexture, kBorrow_GrWrapOwnership, kRead_GrIOType, + GrWrapCacheable::kNo); if (!tex) { return sk_sp(); } diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp index 0e520d820e..d291c04a43 100644 --- a/src/gpu/GrGpu.cpp +++ b/src/gpu/GrGpu.cpp @@ -148,9 +148,8 @@ sk_sp GrGpu::createTexture(const GrSurfaceDesc& desc, SkBudgeted budg } sk_sp GrGpu::wrapBackendTexture(const GrBackendTexture& backendTex, - GrWrapOwnership ownership, - GrIOType ioType, - bool purgeImmediately) { + GrWrapOwnership ownership, GrWrapCacheable cacheable, + GrIOType ioType) { SkASSERT(ioType != kWrite_GrIOType); this->handleDirtyContext(); SkASSERT(this->caps()); @@ -161,7 +160,7 @@ sk_sp GrGpu::wrapBackendTexture(const GrBackendTexture& backendTex, backendTex.height() > this->caps()->maxTextureSize()) { return nullptr; } - return this->onWrapBackendTexture(backendTex, ownership, ioType, purgeImmediately); + return this->onWrapBackendTexture(backendTex, ownership, cacheable, ioType); } sk_sp GrGpu::wrapRenderableBackendTexture(const GrBackendTexture& backendTex, diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h index c99733d279..34e21c4cf9 100644 --- a/src/gpu/GrGpu.h +++ b/src/gpu/GrGpu.h @@ -104,8 +104,8 @@ public: /** * Implements GrResourceProvider::wrapBackendTexture */ - sk_sp wrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrIOType, - bool purgeImmediately); + sk_sp wrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrWrapCacheable, + GrIOType); /** * Implements GrResourceProvider::wrapRenderableBackendTexture @@ -458,7 +458,7 @@ private: const GrMipLevel texels[], int mipLevelCount) = 0; virtual sk_sp onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, - GrIOType, bool purgeImmediately) = 0; + GrWrapCacheable, GrIOType) = 0; virtual sk_sp onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt, GrWrapOwnership) = 0; diff --git a/src/gpu/GrGpuResource.cpp b/src/gpu/GrGpuResource.cpp index a4e0f54e79..b3d3b1ddde 100644 --- a/src/gpu/GrGpuResource.cpp +++ b/src/gpu/GrGpuResource.cpp @@ -21,28 +21,23 @@ static inline GrResourceCache* get_resource_cache(GrGpu* gpu) { return gpu->getContext()->contextPriv().getResourceCache(); } -GrGpuResource::GrGpuResource(GrGpu* gpu) - : fGpu(gpu) - , fGpuMemorySize(kInvalidGpuMemorySize) - , fBudgeted(SkBudgeted::kNo) - , fShouldPurgeImmediately(false) - , fRefsWrappedObjects(false) - , fUniqueID(CreateUniqueID()) { +GrGpuResource::GrGpuResource(GrGpu* gpu) : fGpu(gpu), fUniqueID(CreateUniqueID()) { SkDEBUGCODE(fCacheArrayIndex = -1); } void GrGpuResource::registerWithCache(SkBudgeted budgeted) { - SkASSERT(fBudgeted == SkBudgeted::kNo); - SkASSERT(!fShouldPurgeImmediately); - fBudgeted = budgeted; + SkASSERT(fBudgetedType == GrBudgetedType::kUnbudgetedCacheable); + fBudgetedType = budgeted == SkBudgeted::kYes ? GrBudgetedType::kBudgeted + : GrBudgetedType::kUnbudgetedCacheable; this->computeScratchKey(&fScratchKey); get_resource_cache(fGpu)->resourceAccess().insertResource(this); } -void GrGpuResource::registerWithCacheWrapped(bool purgeImmediately) { - SkASSERT(fBudgeted == SkBudgeted::kNo); - // Currently resources referencing wrapped objects are not budgeted. - fShouldPurgeImmediately = purgeImmediately; +void GrGpuResource::registerWithCacheWrapped(GrWrapCacheable wrapType) { + SkASSERT(fBudgetedType == GrBudgetedType::kUnbudgetedCacheable); + // Resources referencing wrapped objects are never budgeted. They may be cached or uncached. + fBudgetedType = wrapType == GrWrapCacheable::kNo ? GrBudgetedType::kUnbudgetedUncacheable + : GrBudgetedType::kUnbudgetedCacheable; fRefsWrappedObjects = true; get_resource_cache(fGpu)->resourceAccess().insertResource(this); } @@ -137,7 +132,8 @@ void GrGpuResource::setUniqueKey(const GrUniqueKey& key) { // resources are a special case: the unique keys give us a weak ref so that we can reuse the // same resource (rather than re-wrapping). When a wrapped resource is no longer referenced, // it will always be released - it is never converted to a scratch resource. - if (SkBudgeted::kNo == this->resourcePriv().isBudgeted() && !this->fRefsWrappedObjects) { + if (this->resourcePriv().budgetedType() != GrBudgetedType::kBudgeted && + !this->fRefsWrappedObjects) { return; } @@ -190,18 +186,21 @@ void GrGpuResource::removeScratchKey() { } void GrGpuResource::makeBudgeted() { - if (!this->wasDestroyed() && SkBudgeted::kNo == fBudgeted) { + // We should never make a wrapped resource budgeted. + SkASSERT(!fRefsWrappedObjects); + // Only wrapped resources can be in the kUnbudgetedUncacheable state. + SkASSERT(fBudgetedType != GrBudgetedType::kUnbudgetedUncacheable); + if (!this->wasDestroyed() && fBudgetedType == GrBudgetedType::kUnbudgetedCacheable) { // Currently resources referencing wrapped objects are not budgeted. - SkASSERT(!fRefsWrappedObjects); - fBudgeted = SkBudgeted::kYes; + fBudgetedType = GrBudgetedType::kBudgeted; get_resource_cache(fGpu)->resourceAccess().didChangeBudgetStatus(this); } } void GrGpuResource::makeUnbudgeted() { - if (!this->wasDestroyed() && SkBudgeted::kYes == fBudgeted && + if (!this->wasDestroyed() && fBudgetedType == GrBudgetedType::kBudgeted && !fUniqueKey.isValid()) { - fBudgeted = SkBudgeted::kNo; + fBudgetedType = GrBudgetedType::kUnbudgetedCacheable; get_resource_cache(fGpu)->resourceAccess().didChangeBudgetStatus(this); } } diff --git a/src/gpu/GrGpuResourceCacheAccess.h b/src/gpu/GrGpuResourceCacheAccess.h index ce3b597184..3765c6e82e 100644 --- a/src/gpu/GrGpuResourceCacheAccess.h +++ b/src/gpu/GrGpuResourceCacheAccess.h @@ -26,14 +26,9 @@ private: */ bool isScratch() const { return !fResource->getUniqueKey().isValid() && fResource->fScratchKey.isValid() && - SkBudgeted::kYes == fResource->resourcePriv().isBudgeted(); + GrBudgetedType::kBudgeted == fResource->resourcePriv().budgetedType(); } - /** - * Even if the resource has a unique key should we still try to purge it as soon as possible. - */ - bool shouldPurgeImmediately() const { return fResource->fShouldPurgeImmediately; } - /** * Called by GrResourceCache when a resource becomes purgeable regardless of whether the cache * has decided to keep the resource ot purge it immediately. diff --git a/src/gpu/GrGpuResourcePriv.h b/src/gpu/GrGpuResourcePriv.h index 9537ffb517..75b3531b7f 100644 --- a/src/gpu/GrGpuResourcePriv.h +++ b/src/gpu/GrGpuResourcePriv.h @@ -43,12 +43,13 @@ public: void makeUnbudgeted() { fResource->makeUnbudgeted(); } /** - * Does the resource count against the resource budget? + * Get the resource's budgeted-type which indicates whether it counts against the resource cache + * budget and if not whether it is allowed to be cached. */ - SkBudgeted isBudgeted() const { - bool ret = SkBudgeted::kYes == fResource->fBudgeted; - SkASSERT(ret || !fResource->getUniqueKey().isValid() || fResource->fRefsWrappedObjects); - return SkBudgeted(ret); + GrBudgetedType budgetedType() const { + SkASSERT(GrBudgetedType::kBudgeted == fResource->fBudgetedType || + !fResource->getUniqueKey().isValid() || fResource->fRefsWrappedObjects); + return fResource->fBudgetedType; } /** diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp index 3aa6262095..978da53caf 100644 --- a/src/gpu/GrProxyProvider.cpp +++ b/src/gpu/GrProxyProvider.cpp @@ -464,7 +464,8 @@ sk_sp GrProxyProvider::wrapBackendTexture(const GrBackendTexture return nullptr; } - sk_sp tex = fResourceProvider->wrapBackendTexture(backendTex, ownership, ioType); + sk_sp tex = fResourceProvider->wrapBackendTexture(backendTex, ownership, ioType, + GrWrapCacheable::kYes); if (!tex) { return nullptr; } @@ -478,7 +479,7 @@ sk_sp GrProxyProvider::wrapBackendTexture(const GrBackendTexture SkASSERT(!tex->asRenderTarget()); // Strictly a GrTexture // Make sure we match how we created the proxy with SkBudgeted::kNo - SkASSERT(SkBudgeted::kNo == tex->resourcePriv().isBudgeted()); + SkASSERT(GrBudgetedType::kBudgeted != tex->resourcePriv().budgetedType()); return sk_sp(new GrTextureProxy(std::move(tex), origin)); } @@ -508,7 +509,7 @@ sk_sp GrProxyProvider::wrapRenderableBackendTexture( SkASSERT(tex->asRenderTarget()); // A GrTextureRenderTarget // Make sure we match how we created the proxy with SkBudgeted::kNo - SkASSERT(SkBudgeted::kNo == tex->resourcePriv().isBudgeted()); + SkASSERT(GrBudgetedType::kBudgeted != tex->resourcePriv().budgetedType()); return sk_sp(new GrTextureRenderTargetProxy(std::move(tex), origin)); } @@ -531,7 +532,7 @@ sk_sp GrProxyProvider::wrapBackendRenderTarget( SkASSERT(!rt->asTexture()); // A GrRenderTarget that's not textureable SkASSERT(!rt->getUniqueKey().isValid()); // Make sure we match how we created the proxy with SkBudgeted::kNo - SkASSERT(SkBudgeted::kNo == rt->resourcePriv().isBudgeted()); + SkASSERT(GrBudgetedType::kBudgeted != rt->resourcePriv().budgetedType()); return sk_sp(new GrRenderTargetProxy(std::move(rt), origin)); } @@ -555,7 +556,7 @@ sk_sp GrProxyProvider::wrapBackendTextureAsRenderTarget( SkASSERT(!rt->asTexture()); // A GrRenderTarget that's not textureable SkASSERT(!rt->getUniqueKey().isValid()); // This proxy should be unbudgeted because we're just wrapping an external resource - SkASSERT(SkBudgeted::kNo == rt->resourcePriv().isBudgeted()); + SkASSERT(GrBudgetedType::kBudgeted != rt->resourcePriv().budgetedType()); return sk_sp(new GrRenderTargetProxy(std::move(rt), origin)); } @@ -580,7 +581,7 @@ sk_sp GrProxyProvider::wrapVulkanSecondaryCBAsRenderTarget( SkASSERT(!rt->asTexture()); // A GrRenderTarget that's not textureable SkASSERT(!rt->getUniqueKey().isValid()); // This proxy should be unbudgeted because we're just wrapping an external resource - SkASSERT(SkBudgeted::kNo == rt->resourcePriv().isBudgeted()); + SkASSERT(GrBudgetedType::kBudgeted != rt->resourcePriv().budgetedType()); // All Vulkan surfaces uses top left origins. return sk_sp( diff --git a/src/gpu/GrResourceAllocator.cpp b/src/gpu/GrResourceAllocator.cpp index 0f7089465d..0d3c34e0ea 100644 --- a/src/gpu/GrResourceAllocator.cpp +++ b/src/gpu/GrResourceAllocator.cpp @@ -266,9 +266,9 @@ sk_sp GrResourceAllocator::findSurfaceFor(const GrSurfaceProxy* proxy sk_sp surface(fFreePool.findAndRemove(key, filter)); if (surface) { if (SkBudgeted::kYes == proxy->isBudgeted() && - SkBudgeted::kNo == surface->resourcePriv().isBudgeted()) { + GrBudgetedType::kBudgeted != surface->resourcePriv().budgetedType()) { // This gets the job done but isn't quite correct. It would be better to try to - // match budgeted proxies w/ budgeted surface and unbudgeted w/ unbudgeted. + // match budgeted proxies w/ budgeted surfaces and unbudgeted w/ unbudgeted. surface->resourcePriv().makeBudgeted(); } diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp index 53dfe9b58d..634dac7d2e 100644 --- a/src/gpu/GrResourceCache.cpp +++ b/src/gpu/GrResourceCache.cpp @@ -125,7 +125,7 @@ void GrResourceCache::insertResource(GrGpuResource* resource) { fHighWaterCount = SkTMax(this->getResourceCount(), fHighWaterCount); fHighWaterBytes = SkTMax(fBytes, fHighWaterBytes); #endif - if (SkBudgeted::kYes == resource->resourcePriv().isBudgeted()) { + if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) { ++fBudgetedCount; fBudgetedBytes += size; TRACE_COUNTER2("skia.gpu.cache", "skia budget", "used", @@ -159,7 +159,7 @@ void GrResourceCache::removeResource(GrGpuResource* resource) { SkDEBUGCODE(--fCount;) fBytes -= size; - if (SkBudgeted::kYes == resource->resourcePriv().isBudgeted()) { + if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) { --fBudgetedCount; fBudgetedBytes -= size; TRACE_COUNTER2("skia.gpu.cache", "skia budget", "used", @@ -423,10 +423,18 @@ void GrResourceCache::notifyCntReachedZero(GrGpuResource* resource, uint32_t fla { SkScopeExit notifyPurgeable([resource] { resource->cacheAccess().becamePurgeable(); }); - if (SkBudgeted::kNo == resource->resourcePriv().isBudgeted()) { + auto budgetedType = resource->resourcePriv().budgetedType(); + if (budgetedType == GrBudgetedType::kBudgeted) { + // Purge the resource immediately if we're over budget + // Also purge if the resource has neither a valid scratch key nor a unique key. + bool hasKey = resource->resourcePriv().getScratchKey().isValid() || hasUniqueKey; + if (!this->overBudget() && hasKey) { + return; + } + } else { // We keep unbudgeted resources with a unique key in the purgable queue of the cache so // they can be reused again by the image connected to the unique key. - if (hasUniqueKey && !resource->cacheAccess().shouldPurgeImmediately()) { + if (hasUniqueKey && budgetedType == GrBudgetedType::kUnbudgetedCacheable) { return; } // Check whether this resource could still be used as a scratch resource. @@ -439,13 +447,6 @@ void GrResourceCache::notifyCntReachedZero(GrGpuResource* resource, uint32_t fla return; } } - } else { - // Purge the resource immediately if we're over budget - // Also purge if the resource has neither a valid scratch key nor a unique key. - bool hasKey = resource->resourcePriv().getScratchKey().isValid() || hasUniqueKey; - if (!this->overBudget() && hasKey) { - return; - } } } SkDEBUGCODE(int beforeCount = this->getResourceCount();) @@ -462,7 +463,7 @@ void GrResourceCache::didChangeBudgetStatus(GrGpuResource* resource) { size_t size = resource->gpuMemorySize(); - if (SkBudgeted::kYes == resource->resourcePriv().isBudgeted()) { + if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) { ++fBudgetedCount; fBudgetedBytes += size; #if GR_CACHE_STATS @@ -752,7 +753,7 @@ void GrResourceCache::validate() const { SkASSERT(fScratchMap->countForKey(scratchKey)); SkASSERT(!resource->resourcePriv().refsWrappedObjects()); } else if (scratchKey.isValid()) { - SkASSERT(SkBudgeted::kNo == resource->resourcePriv().isBudgeted() || + SkASSERT(GrBudgetedType::kBudgeted != resource->resourcePriv().budgetedType() || uniqueKey.isValid()); if (!uniqueKey.isValid()) { ++fCouldBeScratch; @@ -763,7 +764,7 @@ void GrResourceCache::validate() const { if (uniqueKey.isValid()) { ++fContent; SkASSERT(fUniqueHash->find(uniqueKey) == resource); - SkASSERT(SkBudgeted::kYes == resource->resourcePriv().isBudgeted() || + SkASSERT(GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType() || resource->resourcePriv().refsWrappedObjects()); if (scratchKey.isValid()) { @@ -771,7 +772,7 @@ void GrResourceCache::validate() const { } } - if (SkBudgeted::kYes == resource->resourcePriv().isBudgeted()) { + if (GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()) { ++fBudgetedCount; fBudgetedBytes += resource->gpuMemorySize(); } diff --git a/src/gpu/GrResourceCache.h b/src/gpu/GrResourceCache.h index 7730ebd283..59141ad4aa 100644 --- a/src/gpu/GrResourceCache.h +++ b/src/gpu/GrResourceCache.h @@ -225,7 +225,7 @@ public: if (resource->resourcePriv().refsWrappedObjects()) { ++fWrapped; } - if (SkBudgeted::kNo == resource->resourcePriv().isBudgeted()) { + if (GrBudgetedType::kBudgeted != resource->resourcePriv().budgetedType()) { fUnbudgetedSize += resource->gpuMemorySize(); } } diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp index 6b5ff4f1e5..c996494f55 100644 --- a/src/gpu/GrResourceProvider.cpp +++ b/src/gpu/GrResourceProvider.cpp @@ -236,12 +236,12 @@ sk_sp GrResourceProvider::refScratchTexture(const GrSurfaceDesc& desc sk_sp GrResourceProvider::wrapBackendTexture(const GrBackendTexture& tex, GrWrapOwnership ownership, GrIOType ioType, - bool purgeImmediately) { + GrWrapCacheable cacheable) { ASSERT_SINGLE_OWNER if (this->isAbandoned()) { return nullptr; } - return fGpu->wrapBackendTexture(tex, ownership, ioType, purgeImmediately); + return fGpu->wrapBackendTexture(tex, ownership, cacheable, ioType); } sk_sp GrResourceProvider::wrapRenderableBackendTexture(const GrBackendTexture& tex, diff --git a/src/gpu/GrResourceProvider.h b/src/gpu/GrResourceProvider.h index 84a97a1808..83640496e7 100644 --- a/src/gpu/GrResourceProvider.h +++ b/src/gpu/GrResourceProvider.h @@ -109,7 +109,7 @@ public: sk_sp wrapBackendTexture(const GrBackendTexture& tex, GrWrapOwnership /* = kBorrow_GrWrapOwnership*/, GrIOType, - bool purgeImmediately = false); + GrWrapCacheable = GrWrapCacheable::kYes); /** * This makes the backend texture be renderable. If sampleCnt is > 1 and the underlying API diff --git a/src/gpu/GrSurfaceProxy.cpp b/src/gpu/GrSurfaceProxy.cpp index 3da6aaa99c..8b1bce4320 100644 --- a/src/gpu/GrSurfaceProxy.cpp +++ b/src/gpu/GrSurfaceProxy.cpp @@ -89,7 +89,9 @@ GrSurfaceProxy::GrSurfaceProxy(sk_sp surface, GrSurfaceOrigin origin, , fHeight(fTarget->height()) , fOrigin(origin) , fFit(fit) - , fBudgeted(fTarget->resourcePriv().isBudgeted()) + , fBudgeted(fTarget->resourcePriv().budgetedType() == GrBudgetedType::kBudgeted + ? SkBudgeted::kYes + : SkBudgeted::kNo) , fUniqueID(fTarget->uniqueID()) // Note: converting from unique resource ID to a proxy ID! , fNeedsClear(false) , fGpuMemorySize(kInvalidGpuMemorySize) diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index 2c8b602776..5cca23a248 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -653,8 +653,8 @@ static bool check_backend_texture(const GrBackendTexture& backendTex, const GrGL } sk_sp GrGLGpu::onWrapBackendTexture(const GrBackendTexture& backendTex, - GrWrapOwnership ownership, GrIOType ioType, - bool purgeImmediately) { + GrWrapOwnership ownership, GrWrapCacheable cacheable, + GrIOType ioType) { GrGLTexture::IDDesc idDesc; if (!check_backend_texture(backendTex, this->glCaps(), &idDesc)) { return nullptr; @@ -678,8 +678,8 @@ sk_sp GrGLGpu::onWrapBackendTexture(const GrBackendTexture& backendTe GrMipMapsStatus mipMapsStatus = backendTex.hasMipMaps() ? GrMipMapsStatus::kValid : GrMipMapsStatus::kNotAllocated; - auto texture = GrGLTexture::MakeWrapped(this, surfDesc, mipMapsStatus, idDesc, ioType, - purgeImmediately); + auto texture = + GrGLTexture::MakeWrapped(this, surfDesc, mipMapsStatus, idDesc, cacheable, ioType); // We don't know what parameters are already set on wrapped textures. texture->textureParamsModified(); return std::move(texture); diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h index 75466cf97a..1987a28445 100644 --- a/src/gpu/gl/GrGLGpu.h +++ b/src/gpu/gl/GrGLGpu.h @@ -189,8 +189,8 @@ private: GrBuffer* onCreateBuffer(size_t size, GrBufferType intendedType, GrAccessPattern, const void* data) override; - sk_sp onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrIOType, - bool purgeImmediately) override; + sk_sp onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrWrapCacheable, + GrIOType) override; sk_sp onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt, GrWrapOwnership) override; diff --git a/src/gpu/gl/GrGLTexture.cpp b/src/gpu/gl/GrGLTexture.cpp index cbb6b5a75e..a94c87bbec 100644 --- a/src/gpu/gl/GrGLTexture.cpp +++ b/src/gpu/gl/GrGLTexture.cpp @@ -53,13 +53,12 @@ GrGLTexture::GrGLTexture(GrGLGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc& } } -GrGLTexture::GrGLTexture(GrGLGpu* gpu, Wrapped, const GrSurfaceDesc& desc, - GrMipMapsStatus mipMapsStatus, const IDDesc& idDesc, GrIOType ioType, - bool purgeImmediately) +GrGLTexture::GrGLTexture(GrGLGpu* gpu, const GrSurfaceDesc& desc, GrMipMapsStatus mipMapsStatus, + const IDDesc& idDesc, GrWrapCacheable cacheable, GrIOType ioType) : GrSurface(gpu, desc) , INHERITED(gpu, desc, TextureTypeFromTarget(idDesc.fInfo.fTarget), mipMapsStatus) { this->init(desc, idDesc); - this->registerWithCacheWrapped(purgeImmediately); + this->registerWithCacheWrapped(cacheable); if (ioType == kRead_GrIOType) { this->setReadOnly(); } @@ -117,9 +116,8 @@ GrBackendFormat GrGLTexture::backendFormat() const { sk_sp GrGLTexture::MakeWrapped(GrGLGpu* gpu, const GrSurfaceDesc& desc, GrMipMapsStatus mipMapsStatus, const IDDesc& idDesc, - GrIOType ioType, bool purgeImmediately) { - return sk_sp( - new GrGLTexture(gpu, kWrapped, desc, mipMapsStatus, idDesc, ioType, purgeImmediately)); + GrWrapCacheable cacheable, GrIOType ioType) { + return sk_sp(new GrGLTexture(gpu, desc, mipMapsStatus, idDesc, cacheable, ioType)); } bool GrGLTexture::onStealBackendTexture(GrBackendTexture* backendTexture, diff --git a/src/gpu/gl/GrGLTexture.h b/src/gpu/gl/GrGLTexture.h index f9d4acd147..e8ca83cee2 100644 --- a/src/gpu/gl/GrGLTexture.h +++ b/src/gpu/gl/GrGLTexture.h @@ -111,7 +111,7 @@ public: void baseLevelWasBoundToFBO() { fBaseLevelHasBeenBoundToFBO = true; } static sk_sp MakeWrapped(GrGLGpu*, const GrSurfaceDesc&, GrMipMapsStatus, - const IDDesc&, GrIOType, bool purgeImmediately); + const IDDesc&, GrWrapCacheable, GrIOType); void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const override; @@ -119,10 +119,9 @@ protected: // Constructor for subclasses. GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, const IDDesc&, GrMipMapsStatus); - enum Wrapped { kWrapped }; // Constructor for instances wrapping backend objects. - GrGLTexture(GrGLGpu*, Wrapped, const GrSurfaceDesc&, GrMipMapsStatus, const IDDesc&, GrIOType, - bool purgeImmediately); + GrGLTexture(GrGLGpu*, const GrSurfaceDesc&, GrMipMapsStatus, const IDDesc&, GrWrapCacheable, + GrIOType); void init(const GrSurfaceDesc&, const IDDesc&); diff --git a/src/gpu/mock/GrMockGpu.cpp b/src/gpu/mock/GrMockGpu.cpp index b98af8089b..a2955f5181 100644 --- a/src/gpu/mock/GrMockGpu.cpp +++ b/src/gpu/mock/GrMockGpu.cpp @@ -107,8 +107,8 @@ sk_sp GrMockGpu::onCreateTexture(const GrSurfaceDesc& desc, SkBudgete } sk_sp GrMockGpu::onWrapBackendTexture(const GrBackendTexture& tex, - GrWrapOwnership ownership, GrIOType ioType, - bool purgeImmediately) { + GrWrapOwnership ownership, + GrWrapCacheable wrapType, GrIOType ioType) { GrSurfaceDesc desc; desc.fWidth = tex.width(); desc.fHeight = tex.height(); @@ -120,8 +120,7 @@ sk_sp GrMockGpu::onWrapBackendTexture(const GrBackendTexture& tex, GrMipMapsStatus mipMapsStatus = tex.hasMipMaps() ? GrMipMapsStatus::kValid : GrMipMapsStatus::kNotAllocated; - return sk_sp(new GrMockTexture(this, GrMockTexture::kWrapped, desc, mipMapsStatus, - info, ioType, purgeImmediately)); + return sk_sp(new GrMockTexture(this, desc, mipMapsStatus, info, wrapType, ioType)); } sk_sp GrMockGpu::onWrapRenderableBackendTexture(const GrBackendTexture& tex, diff --git a/src/gpu/mock/GrMockGpu.h b/src/gpu/mock/GrMockGpu.h index d3584b5170..77090ea5a0 100644 --- a/src/gpu/mock/GrMockGpu.h +++ b/src/gpu/mock/GrMockGpu.h @@ -59,8 +59,8 @@ private: sk_sp onCreateTexture(const GrSurfaceDesc&, SkBudgeted, const GrMipLevel[], int mipLevelCount) override; - sk_sp onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrIOType, - bool purgeImmediately) override; + sk_sp onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrWrapCacheable, + GrIOType) override; sk_sp onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt, diff --git a/src/gpu/mock/GrMockTexture.h b/src/gpu/mock/GrMockTexture.h index 3674de65d7..e9e35af660 100644 --- a/src/gpu/mock/GrMockTexture.h +++ b/src/gpu/mock/GrMockTexture.h @@ -22,14 +22,13 @@ public: this->registerWithCache(budgeted); } - enum Wrapped { kWrapped }; - GrMockTexture(GrMockGpu* gpu, Wrapped, const GrSurfaceDesc& desc, GrMipMapsStatus mipMapsStatus, - const GrMockTextureInfo& info, GrIOType ioType, bool purgeImmediately) + GrMockTexture(GrMockGpu* gpu, const GrSurfaceDesc& desc, GrMipMapsStatus mipMapsStatus, + const GrMockTextureInfo& info, GrWrapCacheable cacheable, GrIOType ioType) : GrMockTexture(gpu, desc, mipMapsStatus, info) { if (ioType == kRead_GrIOType) { this->setReadOnly(); } - this->registerWithCacheWrapped(purgeImmediately); + this->registerWithCacheWrapped(cacheable); } ~GrMockTexture() override {} diff --git a/src/gpu/mtl/GrMtlGpu.h b/src/gpu/mtl/GrMtlGpu.h index cc1364574e..bab666c41a 100644 --- a/src/gpu/mtl/GrMtlGpu.h +++ b/src/gpu/mtl/GrMtlGpu.h @@ -132,8 +132,8 @@ private: sk_sp onCreateTexture(const GrSurfaceDesc& desc, SkBudgeted budgeted, const GrMipLevel texels[], int mipLevelCount) override; - sk_sp onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrIOType, - bool purgeImmediately) override; + sk_sp onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrWrapCacheable, + GrIOType) override; sk_sp onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt, diff --git a/src/gpu/mtl/GrMtlGpu.mm b/src/gpu/mtl/GrMtlGpu.mm index 68693b10d1..a74ac52908 100644 --- a/src/gpu/mtl/GrMtlGpu.mm +++ b/src/gpu/mtl/GrMtlGpu.mm @@ -342,8 +342,8 @@ static inline void init_surface_desc(GrSurfaceDesc* surfaceDesc, id } sk_sp GrMtlGpu::onWrapBackendTexture(const GrBackendTexture& backendTex, - GrWrapOwnership ownership, GrIOType ioType, - bool purgeImmediately) { + GrWrapOwnership ownership, + GrWrapCacheable cacheable, GrIOType ioType) { id mtlTexture = get_texture_from_backend(backendTex, ownership); if (!mtlTexture) { return nullptr; @@ -352,7 +352,7 @@ sk_sp GrMtlGpu::onWrapBackendTexture(const GrBackendTexture& backendT GrSurfaceDesc surfDesc; init_surface_desc(&surfDesc, mtlTexture, false, backendTex.config()); - return GrMtlTexture::MakeWrappedTexture(this, surfDesc, mtlTexture, ioType, purgeImmediately); + return GrMtlTexture::MakeWrappedTexture(this, surfDesc, mtlTexture, cacheable, ioType); } sk_sp GrMtlGpu::onWrapRenderableBackendTexture(const GrBackendTexture& backendTex, diff --git a/src/gpu/mtl/GrMtlTexture.h b/src/gpu/mtl/GrMtlTexture.h index 2cdb92b838..87599eab15 100644 --- a/src/gpu/mtl/GrMtlTexture.h +++ b/src/gpu/mtl/GrMtlTexture.h @@ -22,7 +22,7 @@ public: GrMipMapsStatus); static sk_sp MakeWrappedTexture(GrMtlGpu*, const GrSurfaceDesc&, id, - GrIOType, bool purgeImmediately); + GrWrapCacheable, GrIOType); ~GrMtlTexture() override; @@ -88,7 +88,7 @@ private: GrMipMapsStatus); GrMtlTexture(GrMtlGpu*, Wrapped, const GrSurfaceDesc&, id, GrMipMapsStatus, - GrIOType, bool purgeImmediately); + GrWrapCacheable, GrIOType); id fTexture; sk_sp fReleaseHelper; diff --git a/src/gpu/mtl/GrMtlTexture.mm b/src/gpu/mtl/GrMtlTexture.mm index 5e91746f5b..87829a3882 100644 --- a/src/gpu/mtl/GrMtlTexture.mm +++ b/src/gpu/mtl/GrMtlTexture.mm @@ -28,8 +28,8 @@ GrMtlTexture::GrMtlTexture(GrMtlGpu* gpu, const GrSurfaceDesc& desc, id texture, GrMipMapsStatus mipMapsStatus, - GrIOType ioType, - bool purgeImmediately) + GrWrapCacheable cacheable, + GrIOType ioType) : GrSurface(gpu, desc) , INHERITED(gpu, desc, GrTextureType::k2D, mipMapsStatus) , fTexture(texture) { @@ -37,7 +37,7 @@ GrMtlTexture::GrMtlTexture(GrMtlGpu* gpu, if (ioType == kRead_GrIOType) { this->setReadOnly(); } - this->registerWithCacheWrapped(purgeImmediately); + this->registerWithCacheWrapped(cacheable); } GrMtlTexture::GrMtlTexture(GrMtlGpu* gpu, @@ -67,8 +67,8 @@ sk_sp GrMtlTexture::CreateNewTexture(GrMtlGpu* gpu, SkBudgeted bud sk_sp GrMtlTexture::MakeWrappedTexture(GrMtlGpu* gpu, const GrSurfaceDesc& desc, id texture, - GrIOType ioType, - bool purgeImmediately) { + GrWrapCacheable cacheable, + GrIOType ioType) { if (desc.fSampleCnt > 1) { SkASSERT(false); // Currently we don't support msaa return nullptr; @@ -77,8 +77,8 @@ sk_sp GrMtlTexture::MakeWrappedTexture(GrMtlGpu* gpu, SkASSERT(MTLTextureUsageShaderRead & texture.usage); GrMipMapsStatus mipMapsStatus = texture.mipmapLevelCount > 1 ? GrMipMapsStatus::kValid : GrMipMapsStatus::kNotAllocated; - return sk_sp(new GrMtlTexture(gpu, kWrapped, desc, texture, mipMapsStatus, ioType, - purgeImmediately)); + return sk_sp(new GrMtlTexture(gpu, kWrapped, desc, texture, mipMapsStatus, + cacheable, ioType)); } GrMtlTexture::~GrMtlTexture() { diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp index 619394ded4..b85d6030e8 100644 --- a/src/gpu/vk/GrVkGpu.cpp +++ b/src/gpu/vk/GrVkGpu.cpp @@ -1022,8 +1022,8 @@ static bool check_image_info(const GrVkCaps& caps, } sk_sp GrVkGpu::onWrapBackendTexture(const GrBackendTexture& backendTex, - GrWrapOwnership ownership, GrIOType ioType, - bool purgeImmediately) { + GrWrapOwnership ownership, GrWrapCacheable cacheable, + GrIOType ioType) { GrVkImageInfo imageInfo; if (!backendTex.getVkImageInfo(&imageInfo)) { return nullptr; @@ -1042,8 +1042,8 @@ sk_sp GrVkGpu::onWrapBackendTexture(const GrBackendTexture& backendTe sk_sp layout = backendTex.getGrVkImageLayout(); SkASSERT(layout); - return GrVkTexture::MakeWrappedTexture(this, surfDesc, ownership, ioType, purgeImmediately, - imageInfo, std::move(layout)); + return GrVkTexture::MakeWrappedTexture(this, surfDesc, ownership, cacheable, ioType, imageInfo, + std::move(layout)); } sk_sp GrVkGpu::onWrapRenderableBackendTexture(const GrBackendTexture& backendTex, diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h index 6358560141..8200b6fd5c 100644 --- a/src/gpu/vk/GrVkGpu.h +++ b/src/gpu/vk/GrVkGpu.h @@ -184,8 +184,8 @@ private: sk_sp onCreateTexture(const GrSurfaceDesc&, SkBudgeted, const GrMipLevel[], int mipLevelCount) override; - sk_sp onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrIOType, - bool purgeImmediately) override; + sk_sp onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrWrapCacheable, + GrIOType) override; sk_sp onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt, GrWrapOwnership) override; diff --git a/src/gpu/vk/GrVkTexture.cpp b/src/gpu/vk/GrVkTexture.cpp index 802bbcd6fc..bdd8db4325 100644 --- a/src/gpu/vk/GrVkTexture.cpp +++ b/src/gpu/vk/GrVkTexture.cpp @@ -36,16 +36,10 @@ GrVkTexture::GrVkTexture(GrVkGpu* gpu, } } -GrVkTexture::GrVkTexture(GrVkGpu* gpu, - Wrapped, - const GrSurfaceDesc& desc, - const GrVkImageInfo& info, - sk_sp layout, - const GrVkImageView* view, - GrMipMapsStatus mipMapsStatus, - GrBackendObjectOwnership ownership, - GrIOType ioType, - bool purgeImmediately) +GrVkTexture::GrVkTexture(GrVkGpu* gpu, const GrSurfaceDesc& desc, const GrVkImageInfo& info, + sk_sp layout, const GrVkImageView* view, + GrMipMapsStatus mipMapsStatus, GrBackendObjectOwnership ownership, + GrWrapCacheable cacheable, GrIOType ioType) : GrSurface(gpu, desc) , GrVkImage(info, std::move(layout), ownership) , INHERITED(gpu, desc, GrTextureType::k2D, mipMapsStatus) @@ -54,7 +48,7 @@ GrVkTexture::GrVkTexture(GrVkGpu* gpu, if (ioType == kRead_GrIOType) { this->setReadOnly(); } - this->registerWithCacheWrapped(purgeImmediately); + this->registerWithCacheWrapped(cacheable); } // Because this class is virtually derived from GrSurface we must explicitly call its constructor. @@ -96,11 +90,9 @@ sk_sp GrVkTexture::MakeNewTexture(GrVkGpu* gpu, SkBudgeted budgeted imageView, mipMapsStatus)); } -sk_sp GrVkTexture::MakeWrappedTexture(GrVkGpu* gpu, - const GrSurfaceDesc& desc, +sk_sp GrVkTexture::MakeWrappedTexture(GrVkGpu* gpu, const GrSurfaceDesc& desc, GrWrapOwnership wrapOwnership, - GrIOType ioType, - bool purgeImmediately, + GrWrapCacheable cacheable, GrIOType ioType, const GrVkImageInfo& info, sk_sp layout) { // Wrapped textures require both image and allocation (because they can be mapped) @@ -118,9 +110,8 @@ sk_sp GrVkTexture::MakeWrappedTexture(GrVkGpu* gpu, GrBackendObjectOwnership ownership = kBorrow_GrWrapOwnership == wrapOwnership ? GrBackendObjectOwnership::kBorrowed : GrBackendObjectOwnership::kOwned; - return sk_sp(new GrVkTexture(gpu, kWrapped, desc, info, std::move(layout), - imageView, mipMapsStatus, ownership, ioType, - purgeImmediately)); + return sk_sp(new GrVkTexture(gpu, desc, info, std::move(layout), imageView, + mipMapsStatus, ownership, cacheable, ioType)); } GrVkTexture::~GrVkTexture() { diff --git a/src/gpu/vk/GrVkTexture.h b/src/gpu/vk/GrVkTexture.h index 0592fc885c..9005b42356 100644 --- a/src/gpu/vk/GrVkTexture.h +++ b/src/gpu/vk/GrVkTexture.h @@ -25,8 +25,8 @@ public: GrMipMapsStatus); static sk_sp MakeWrappedTexture(GrVkGpu*, const GrSurfaceDesc&, GrWrapOwnership, - GrIOType, bool purgeImmediately, - const GrVkImageInfo&, sk_sp); + GrWrapCacheable, GrIOType, const GrVkImageInfo&, + sk_sp); ~GrVkTexture() override; @@ -62,13 +62,12 @@ protected: } private: - enum Wrapped { kWrapped }; GrVkTexture(GrVkGpu*, SkBudgeted, const GrSurfaceDesc&, const GrVkImageInfo&, sk_sp layout, const GrVkImageView* imageView, GrMipMapsStatus); - GrVkTexture(GrVkGpu*, Wrapped, const GrSurfaceDesc&, const GrVkImageInfo&, - sk_sp layout, const GrVkImageView* imageView, GrMipMapsStatus, - GrBackendObjectOwnership, GrIOType ioType, bool purgeImmediately); + GrVkTexture(GrVkGpu*, const GrSurfaceDesc&, const GrVkImageInfo&, sk_sp, + const GrVkImageView*, GrMipMapsStatus, GrBackendObjectOwnership, GrWrapCacheable, + GrIOType); void becamePurgeable() override; diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp index 901c05dd7b..752533bb74 100644 --- a/tests/GrSurfaceTest.cpp +++ b/tests/GrSurfaceTest.cpp @@ -459,7 +459,12 @@ DEF_GPUTEST(TextureIdleProcTest, reporter, options) { if (isRT) { desc.fFlags = kRenderTarget_GrSurfaceFlag; } - SkBudgeted budgeted(texture->resourcePriv().isBudgeted()); + SkBudgeted budgeted; + if (texture->resourcePriv().budgetedType() == GrBudgetedType::kBudgeted) { + budgeted = SkBudgeted::kYes; + } else { + budgeted = SkBudgeted::kNo; + } auto proxy = context->contextPriv().proxyProvider()->createLazyProxy( singleUseLazyCB, backendFormat, desc, GrSurfaceOrigin::kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, diff --git a/tests/GrTestingBackendTextureUploadTest.cpp b/tests/GrTestingBackendTextureUploadTest.cpp index 9ff0e50fd2..5709e26a13 100644 --- a/tests/GrTestingBackendTextureUploadTest.cpp +++ b/tests/GrTestingBackendTextureUploadTest.cpp @@ -51,7 +51,7 @@ void testing_only_texture_test(skiatest::Reporter* reporter, GrContext* context, GrWrapOwnership::kAdopt_GrWrapOwnership); } else { wrappedTex = gpu->wrapBackendTexture(backendTex, GrWrapOwnership::kAdopt_GrWrapOwnership, - kRead_GrIOType, false); + GrWrapCacheable::kYes, kRead_GrIOType); } REPORTER_ASSERT(reporter, wrappedTex); diff --git a/tests/LazyProxyTest.cpp b/tests/LazyProxyTest.cpp index 88bfd9a695..479d2cbe1e 100644 --- a/tests/LazyProxyTest.cpp +++ b/tests/LazyProxyTest.cpp @@ -466,8 +466,9 @@ DEF_GPUTEST(LazyProxyDeinstantiateTest, reporter, /* options */) { return sk_sp(); } - sk_sp texture = rp->wrapBackendTexture( - backendTex, kBorrow_GrWrapOwnership, kRead_GrIOType); + sk_sp texture = + rp->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership, + kRead_GrIOType, GrWrapCacheable::kYes); if (!texture) { return sk_sp(); } diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp index 17481250f8..96a0b2f07f 100644 --- a/tests/ResourceCacheTest.cpp +++ b/tests/ResourceCacheTest.cpp @@ -670,7 +670,8 @@ void test_unbudgeted_to_scratch(skiatest::Reporter* reporter); // Since this resource is unbudgeted, it should not be reachable as scratch. REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == key); REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch()); - REPORTER_ASSERT(reporter, SkBudgeted::kNo == resource->resourcePriv().isBudgeted()); + REPORTER_ASSERT(reporter, GrBudgetedType::kUnbudgetedCacheable == + resource->resourcePriv().budgetedType()); REPORTER_ASSERT(reporter, nullptr == cache->findAndRefScratchResource(key, TestResource::kDefaultSize, GrResourceCache::ScratchFlags::kNone)); REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); REPORTER_ASSERT(reporter, size == cache->getResourceBytes()); @@ -689,7 +690,8 @@ void test_unbudgeted_to_scratch(skiatest::Reporter* reporter); REPORTER_ASSERT(reporter, resource); REPORTER_ASSERT(reporter, resource->resourcePriv().getScratchKey() == key); REPORTER_ASSERT(reporter, resource->cacheAccess().isScratch()); - REPORTER_ASSERT(reporter, SkBudgeted::kYes == resource->resourcePriv().isBudgeted()); + REPORTER_ASSERT(reporter, + GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()); if (0 == i) { // If made unbudgeted, it should return to original state: ref'ed and unbudgeted. Try @@ -705,7 +707,8 @@ void test_unbudgeted_to_scratch(skiatest::Reporter* reporter); REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); REPORTER_ASSERT(reporter, !resource->resourcePriv().getScratchKey().isValid()); REPORTER_ASSERT(reporter, !resource->cacheAccess().isScratch()); - REPORTER_ASSERT(reporter, SkBudgeted::kYes == resource->resourcePriv().isBudgeted()); + REPORTER_ASSERT(reporter, + GrBudgetedType::kBudgeted == resource->resourcePriv().budgetedType()); // now when it is unrefed it should die since it has no key. resource->unref(); @@ -1451,7 +1454,7 @@ static void test_abandoned(skiatest::Reporter* reporter) { resource->abandon(); resource->resourcePriv().getScratchKey(); - resource->resourcePriv().isBudgeted(); + resource->resourcePriv().budgetedType(); resource->resourcePriv().makeBudgeted(); resource->resourcePriv().makeUnbudgeted(); resource->resourcePriv().removeScratchKey(); diff --git a/tests/TraceMemoryDumpTest.cpp b/tests/TraceMemoryDumpTest.cpp index c58e915a98..59f7b0f26c 100644 --- a/tests/TraceMemoryDumpTest.cpp +++ b/tests/TraceMemoryDumpTest.cpp @@ -128,7 +128,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkTraceMemoryDump_unownedGLTexture, report idDesc.fOwnership = GrBackendObjectOwnership::kBorrowed; auto texture = GrGLTexture::MakeWrapped(gpu, desc, GrMipMapsStatus::kNotAllocated, idDesc, - kRead_GrIOType, false); + GrWrapCacheable::kYes, kRead_GrIOType); ValidateMemoryDumps(reporter, context, texture->gpuMemorySize(), false /* isOwned */); } diff --git a/tests/VkWrapTests.cpp b/tests/VkWrapTests.cpp index 7c846adb7c..84fdc25ee4 100644 --- a/tests/VkWrapTests.cpp +++ b/tests/VkWrapTests.cpp @@ -42,8 +42,8 @@ void wrap_tex_test(skiatest::Reporter* reporter, GrContext* context) { GrVkImageInfo imageInfo; SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo)); - sk_sp tex = - gpu->wrapBackendTexture(origBackendTex, kBorrow_GrWrapOwnership, kRead_GrIOType, false); + sk_sp tex = gpu->wrapBackendTexture(origBackendTex, kBorrow_GrWrapOwnership, + GrWrapCacheable::kYes, kRead_GrIOType); REPORTER_ASSERT(reporter, tex); // image is null @@ -52,9 +52,11 @@ void wrap_tex_test(skiatest::Reporter* reporter, GrContext* context) { backendCopy.fImage = VK_NULL_HANDLE; GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); backendTex.setPixelConfig(kPixelConfig); - tex = gpu->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership, kRead_GrIOType, false); + tex = gpu->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kYes, + kRead_GrIOType); REPORTER_ASSERT(reporter, !tex); - tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership, kRead_GrIOType, false); + tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kYes, + kRead_GrIOType); REPORTER_ASSERT(reporter, !tex); } @@ -64,9 +66,11 @@ void wrap_tex_test(skiatest::Reporter* reporter, GrContext* context) { backendCopy.fAlloc = GrVkAlloc(); GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); backendTex.setPixelConfig(kPixelConfig); - tex = gpu->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership, kRead_GrIOType, false); + tex = gpu->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kYes, + kRead_GrIOType); REPORTER_ASSERT(reporter, !tex); - tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership, kRead_GrIOType, false); + tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kYes, + kRead_GrIOType); REPORTER_ASSERT(reporter, !tex); } @@ -75,7 +79,8 @@ void wrap_tex_test(skiatest::Reporter* reporter, GrContext* context) { GrVkImageInfo backendCopy = imageInfo; GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); backendTex.setPixelConfig(kPixelConfig); - tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership, kRead_GrIOType, false); + tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kYes, + kRead_GrIOType); REPORTER_ASSERT(reporter, tex); }