diff --git a/include/gpu/GrGpuResource.h b/include/gpu/GrGpuResource.h index d2054955c9..4ea206ff5c 100644 --- a/include/gpu/GrGpuResource.h +++ b/include/gpu/GrGpuResource.h @@ -264,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(GrWrapCacheable = GrWrapCacheable::kYes); + void registerWithCacheWrapped(GrWrapCacheable); GrGpuResource(GrGpu*); virtual ~GrGpuResource(); @@ -350,7 +350,7 @@ private: GrGpu* fGpu; mutable size_t fGpuMemorySize = kInvalidGpuMemorySize; - GrBudgetedType fBudgetedType = GrBudgetedType::kUnbudgetedCacheable; + GrBudgetedType fBudgetedType = GrBudgetedType::kUnbudgetedUncacheable; bool fRefsWrappedObjects = false; const UniqueID fUniqueID; diff --git a/src/gpu/GrAHardwareBufferImageGenerator.cpp b/src/gpu/GrAHardwareBufferImageGenerator.cpp index 6ed48fb487..55eab91c6e 100644 --- a/src/gpu/GrAHardwareBufferImageGenerator.cpp +++ b/src/gpu/GrAHardwareBufferImageGenerator.cpp @@ -600,8 +600,11 @@ sk_sp GrAHardwareBufferImageGenerator::makeProxy(GrContext* cont SkASSERT(deleteImageProc && deleteImageCtx); backendTex.fConfig = pixelConfig; + // We make this texture cacheable to avoid recreating a GrTexture every time this + // is invoked. We know the owning SkIamge will send an invalidation message when the + // image is destroyed, so the texture will be removed at that time. sk_sp tex = resourceProvider->wrapBackendTexture( - backendTex, kBorrow_GrWrapOwnership, kRead_GrIOType); + backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kYes, kRead_GrIOType); if (!tex) { deleteImageProc(deleteImageCtx); return sk_sp(); diff --git a/src/gpu/GrBackendTextureImageGenerator.cpp b/src/gpu/GrBackendTextureImageGenerator.cpp index 291f013ac1..674ca05854 100644 --- a/src/gpu/GrBackendTextureImageGenerator.cpp +++ b/src/gpu/GrBackendTextureImageGenerator.cpp @@ -169,8 +169,8 @@ sk_sp GrBackendTextureImageGenerator::onGenerateTexture( // 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, - GrWrapCacheable::kNo); + backendTexture, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, + kRead_GrIOType); if (!tex) { return sk_sp(); } diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index b0ff64b238..449fe606df 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -947,7 +947,7 @@ sk_sp GrContextPriv::makeBackendTextureContext(const GrBackend ASSERT_SINGLE_OWNER_PRIV sk_sp proxy = this->proxyProvider()->wrapBackendTexture( - tex, origin, kBorrow_GrWrapOwnership, kRW_GrIOType); + tex, origin, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType); if (!proxy) { return nullptr; } @@ -964,8 +964,8 @@ sk_sp GrContextPriv::makeBackendTextureRenderTargetContex ASSERT_SINGLE_OWNER_PRIV SkASSERT(sampleCnt > 0); - sk_sp proxy( - this->proxyProvider()->wrapRenderableBackendTexture(tex, origin, sampleCnt)); + sk_sp proxy(this->proxyProvider()->wrapRenderableBackendTexture( + tex, origin, sampleCnt, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo)); if (!proxy) { return nullptr; } diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp index d291c04a43..260ba29ac2 100644 --- a/src/gpu/GrGpu.cpp +++ b/src/gpu/GrGpu.cpp @@ -164,7 +164,8 @@ sk_sp GrGpu::wrapBackendTexture(const GrBackendTexture& backendTex, } sk_sp GrGpu::wrapRenderableBackendTexture(const GrBackendTexture& backendTex, - int sampleCnt, GrWrapOwnership ownership) { + int sampleCnt, GrWrapOwnership ownership, + GrWrapCacheable cacheable) { this->handleDirtyContext(); if (sampleCnt < 1) { return nullptr; @@ -178,7 +179,8 @@ sk_sp GrGpu::wrapRenderableBackendTexture(const GrBackendTexture& bac backendTex.height() > this->caps()->maxRenderTargetSize()) { return nullptr; } - sk_sp tex = this->onWrapRenderableBackendTexture(backendTex, sampleCnt, ownership); + sk_sp tex = + this->onWrapRenderableBackendTexture(backendTex, sampleCnt, ownership, cacheable); SkASSERT(!tex || tex->asRenderTarget()); return tex; } diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h index 34e21c4cf9..04a34f728f 100644 --- a/src/gpu/GrGpu.h +++ b/src/gpu/GrGpu.h @@ -110,8 +110,8 @@ public: /** * Implements GrResourceProvider::wrapRenderableBackendTexture */ - sk_sp wrapRenderableBackendTexture(const GrBackendTexture&, - int sampleCnt, GrWrapOwnership); + sk_sp wrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt, + GrWrapOwnership, GrWrapCacheable); /** * Implements GrResourceProvider::wrapBackendRenderTarget @@ -459,9 +459,8 @@ private: virtual sk_sp onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrWrapCacheable, GrIOType) = 0; - virtual sk_sp onWrapRenderableBackendTexture(const GrBackendTexture&, - int sampleCnt, - GrWrapOwnership) = 0; + virtual sk_sp onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt, + GrWrapOwnership, GrWrapCacheable) = 0; virtual sk_sp onWrapBackendRenderTarget(const GrBackendRenderTarget&) = 0; virtual sk_sp onWrapBackendTextureAsRenderTarget(const GrBackendTexture&, int sampleCnt) = 0; diff --git a/src/gpu/GrGpuResource.cpp b/src/gpu/GrGpuResource.cpp index b3d3b1ddde..c9224be09c 100644 --- a/src/gpu/GrGpuResource.cpp +++ b/src/gpu/GrGpuResource.cpp @@ -26,15 +26,15 @@ GrGpuResource::GrGpuResource(GrGpu* gpu) : fGpu(gpu), fUniqueID(CreateUniqueID() } void GrGpuResource::registerWithCache(SkBudgeted budgeted) { - SkASSERT(fBudgetedType == GrBudgetedType::kUnbudgetedCacheable); + SkASSERT(fBudgetedType == GrBudgetedType::kUnbudgetedUncacheable); fBudgetedType = budgeted == SkBudgeted::kYes ? GrBudgetedType::kBudgeted - : GrBudgetedType::kUnbudgetedCacheable; + : GrBudgetedType::kUnbudgetedUncacheable; this->computeScratchKey(&fScratchKey); get_resource_cache(fGpu)->resourceAccess().insertResource(this); } void GrGpuResource::registerWithCacheWrapped(GrWrapCacheable wrapType) { - SkASSERT(fBudgetedType == GrBudgetedType::kUnbudgetedCacheable); + SkASSERT(fBudgetedType == GrBudgetedType::kUnbudgetedUncacheable); // Resources referencing wrapped objects are never budgeted. They may be cached or uncached. fBudgetedType = wrapType == GrWrapCacheable::kNo ? GrBudgetedType::kUnbudgetedUncacheable : GrBudgetedType::kUnbudgetedCacheable; @@ -188,9 +188,9 @@ void GrGpuResource::removeScratchKey() { void GrGpuResource::makeBudgeted() { // 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) { + // Only wrapped resources can be in the kUnbudgetedCacheable state. + SkASSERT(fBudgetedType != GrBudgetedType::kUnbudgetedCacheable); + if (!this->wasDestroyed() && fBudgetedType == GrBudgetedType::kUnbudgetedUncacheable) { // Currently resources referencing wrapped objects are not budgeted. fBudgetedType = GrBudgetedType::kBudgeted; get_resource_cache(fGpu)->resourceAccess().didChangeBudgetStatus(this); @@ -200,7 +200,7 @@ void GrGpuResource::makeBudgeted() { void GrGpuResource::makeUnbudgeted() { if (!this->wasDestroyed() && fBudgetedType == GrBudgetedType::kBudgeted && !fUniqueKey.isValid()) { - fBudgetedType = GrBudgetedType::kUnbudgetedCacheable; + fBudgetedType = GrBudgetedType::kUnbudgetedUncacheable; get_resource_cache(fGpu)->resourceAccess().didChangeBudgetStatus(this); } } diff --git a/src/gpu/GrProxyProvider.cpp b/src/gpu/GrProxyProvider.cpp index 978da53caf..f13cf7c0ac 100644 --- a/src/gpu/GrProxyProvider.cpp +++ b/src/gpu/GrProxyProvider.cpp @@ -451,6 +451,7 @@ sk_sp GrProxyProvider::createProxy(sk_sp data, const GrS sk_sp GrProxyProvider::wrapBackendTexture(const GrBackendTexture& backendTex, GrSurfaceOrigin origin, GrWrapOwnership ownership, + GrWrapCacheable cacheable, GrIOType ioType, ReleaseProc releaseProc, ReleaseContext releaseCtx) { @@ -464,8 +465,8 @@ sk_sp GrProxyProvider::wrapBackendTexture(const GrBackendTexture return nullptr; } - sk_sp tex = fResourceProvider->wrapBackendTexture(backendTex, ownership, ioType, - GrWrapCacheable::kYes); + sk_sp tex = + fResourceProvider->wrapBackendTexture(backendTex, ownership, cacheable, ioType); if (!tex) { return nullptr; } @@ -486,7 +487,7 @@ sk_sp GrProxyProvider::wrapBackendTexture(const GrBackendTexture sk_sp GrProxyProvider::wrapRenderableBackendTexture( const GrBackendTexture& backendTex, GrSurfaceOrigin origin, int sampleCnt, - GrWrapOwnership ownership) { + GrWrapOwnership ownership, GrWrapCacheable cacheable) { if (this->isAbandoned()) { return nullptr; } @@ -501,8 +502,8 @@ sk_sp GrProxyProvider::wrapRenderableBackendTexture( return nullptr; } - sk_sp tex = - fResourceProvider->wrapRenderableBackendTexture(backendTex, sampleCnt, ownership); + sk_sp tex = fResourceProvider->wrapRenderableBackendTexture(backendTex, sampleCnt, + ownership, cacheable); if (!tex) { return nullptr; } diff --git a/src/gpu/GrProxyProvider.h b/src/gpu/GrProxyProvider.h index 1abb49fd3c..f84cdfc40b 100644 --- a/src/gpu/GrProxyProvider.h +++ b/src/gpu/GrProxyProvider.h @@ -113,16 +113,15 @@ public: * kRead or kRW. */ sk_sp wrapBackendTexture(const GrBackendTexture&, GrSurfaceOrigin, - GrWrapOwnership, GrIOType, ReleaseProc = nullptr, - ReleaseContext = nullptr); + GrWrapOwnership, GrWrapCacheable, GrIOType, + ReleaseProc = nullptr, ReleaseContext = nullptr); /* * Create a texture proxy that wraps a backend texture and is both texture-able and renderable */ - sk_sp wrapRenderableBackendTexture(const GrBackendTexture&, - GrSurfaceOrigin, - int sampleCnt, - GrWrapOwnership = kBorrow_GrWrapOwnership); + sk_sp wrapRenderableBackendTexture(const GrBackendTexture&, GrSurfaceOrigin, + int sampleCnt, GrWrapOwnership, + GrWrapCacheable); /* * Create a render target proxy that wraps a backend render target diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp index c996494f55..3e7d2c7142 100644 --- a/src/gpu/GrResourceProvider.cpp +++ b/src/gpu/GrResourceProvider.cpp @@ -235,8 +235,8 @@ sk_sp GrResourceProvider::refScratchTexture(const GrSurfaceDesc& desc sk_sp GrResourceProvider::wrapBackendTexture(const GrBackendTexture& tex, GrWrapOwnership ownership, - GrIOType ioType, - GrWrapCacheable cacheable) { + GrWrapCacheable cacheable, + GrIOType ioType) { ASSERT_SINGLE_OWNER if (this->isAbandoned()) { return nullptr; @@ -246,12 +246,13 @@ sk_sp GrResourceProvider::wrapBackendTexture(const GrBackendTexture& sk_sp GrResourceProvider::wrapRenderableBackendTexture(const GrBackendTexture& tex, int sampleCnt, - GrWrapOwnership ownership) { + GrWrapOwnership ownership, + GrWrapCacheable cacheable) { ASSERT_SINGLE_OWNER if (this->isAbandoned()) { return nullptr; } - return fGpu->wrapRenderableBackendTexture(tex, sampleCnt, ownership); + return fGpu->wrapRenderableBackendTexture(tex, sampleCnt, ownership, cacheable); } sk_sp GrResourceProvider::wrapBackendRenderTarget( diff --git a/src/gpu/GrResourceProvider.h b/src/gpu/GrResourceProvider.h index 83640496e7..37d094c9cf 100644 --- a/src/gpu/GrResourceProvider.h +++ b/src/gpu/GrResourceProvider.h @@ -106,10 +106,8 @@ public: * * @return GrTexture object or NULL on failure. */ - sk_sp wrapBackendTexture(const GrBackendTexture& tex, - GrWrapOwnership /* = kBorrow_GrWrapOwnership*/, - GrIOType, - GrWrapCacheable = GrWrapCacheable::kYes); + sk_sp wrapBackendTexture(const GrBackendTexture& tex, GrWrapOwnership, + GrWrapCacheable, GrIOType); /** * This makes the backend texture be renderable. If sampleCnt is > 1 and the underlying API @@ -118,14 +116,15 @@ public: */ sk_sp wrapRenderableBackendTexture(const GrBackendTexture& tex, int sampleCnt, - GrWrapOwnership = kBorrow_GrWrapOwnership); + GrWrapOwnership, + GrWrapCacheable); /** * Wraps an existing render target with a GrRenderTarget object. It is * similar to wrapBackendTexture but can be used to draw into surfaces * that are not also textures (e.g. FBO 0 in OpenGL, or an MSAA buffer that * the client will resolve to a texture). Currently wrapped render targets - * always use the kBorrow_GrWrapOwnership semantics. + * always use the kBorrow_GrWrapOwnership and GrWrapCacheable::kNo semantics. * * @return GrRenderTarget object or NULL on failure. */ diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index 5cca23a248..34b27d2136 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -687,7 +687,8 @@ sk_sp GrGLGpu::onWrapBackendTexture(const GrBackendTexture& backendTe sk_sp GrGLGpu::onWrapRenderableBackendTexture(const GrBackendTexture& backendTex, int sampleCnt, - GrWrapOwnership ownership) { + GrWrapOwnership ownership, + GrWrapCacheable cacheable) { GrGLTexture::IDDesc idDesc; if (!check_backend_texture(backendTex, this->glCaps(), &idDesc)) { return nullptr; @@ -725,8 +726,8 @@ sk_sp GrGLGpu::onWrapRenderableBackendTexture(const GrBackendTexture& GrMipMapsStatus mipMapsStatus = backendTex.hasMipMaps() ? GrMipMapsStatus::kDirty : GrMipMapsStatus::kNotAllocated; - sk_sp texRT( - GrGLTextureRenderTarget::MakeWrapped(this, surfDesc, idDesc, rtIDDesc, mipMapsStatus)); + sk_sp texRT(GrGLTextureRenderTarget::MakeWrapped( + this, surfDesc, idDesc, rtIDDesc, cacheable, mipMapsStatus)); texRT->baseLevelWasBoundToFBO(); // We don't know what parameters are already set on wrapped textures. texRT->textureParamsModified(); diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h index 1987a28445..e9c840d3e3 100644 --- a/src/gpu/gl/GrGLGpu.h +++ b/src/gpu/gl/GrGLGpu.h @@ -191,9 +191,8 @@ private: sk_sp onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrWrapCacheable, GrIOType) override; - sk_sp onWrapRenderableBackendTexture(const GrBackendTexture&, - int sampleCnt, - GrWrapOwnership) override; + sk_sp onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt, + GrWrapOwnership, GrWrapCacheable) override; sk_sp onWrapBackendRenderTarget(const GrBackendRenderTarget&) override; sk_sp onWrapBackendTextureAsRenderTarget(const GrBackendTexture&, int sampleCnt) override; diff --git a/src/gpu/gl/GrGLRenderTarget.cpp b/src/gpu/gl/GrGLRenderTarget.cpp index 5e0a2fbd5f..f2913f3b18 100644 --- a/src/gpu/gl/GrGLRenderTarget.cpp +++ b/src/gpu/gl/GrGLRenderTarget.cpp @@ -28,7 +28,7 @@ GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, , INHERITED(gpu, desc, stencil) { this->setFlags(gpu->glCaps(), idDesc); this->init(desc, format, idDesc); - this->registerWithCacheWrapped(); + this->registerWithCacheWrapped(GrWrapCacheable::kNo); } GrGLRenderTarget::GrGLRenderTarget(GrGLGpu* gpu, const GrSurfaceDesc& desc, GrGLenum format, diff --git a/src/gpu/gl/GrGLSemaphore.cpp b/src/gpu/gl/GrGLSemaphore.cpp index b557efb127..d594dc8df6 100644 --- a/src/gpu/gl/GrGLSemaphore.cpp +++ b/src/gpu/gl/GrGLSemaphore.cpp @@ -11,7 +11,8 @@ GrGLSemaphore::GrGLSemaphore(GrGLGpu* gpu, bool isOwned) : INHERITED(gpu), fSync(0), fIsOwned(isOwned) { - isOwned ? this->registerWithCache(SkBudgeted::kNo) : this->registerWithCacheWrapped(); + isOwned ? this->registerWithCache(SkBudgeted::kNo) + : this->registerWithCacheWrapped(GrWrapCacheable::kNo); } void GrGLSemaphore::onRelease() { diff --git a/src/gpu/gl/GrGLTextureRenderTarget.cpp b/src/gpu/gl/GrGLTextureRenderTarget.cpp index 04f8ffc1f1..17dc56220b 100644 --- a/src/gpu/gl/GrGLTextureRenderTarget.cpp +++ b/src/gpu/gl/GrGLTextureRenderTarget.cpp @@ -28,11 +28,12 @@ GrGLTextureRenderTarget::GrGLTextureRenderTarget(GrGLGpu* gpu, const GrSurfaceDesc& desc, const GrGLTexture::IDDesc& texIDDesc, const GrGLRenderTarget::IDDesc& rtIDDesc, + GrWrapCacheable cacheable, GrMipMapsStatus mipMapsStatus) : GrSurface(gpu, desc) , GrGLTexture(gpu, desc, texIDDesc, mipMapsStatus) , GrGLRenderTarget(gpu, desc, texIDDesc.fInfo.fFormat, rtIDDesc) { - this->registerWithCacheWrapped(); + this->registerWithCacheWrapped(cacheable); } void GrGLTextureRenderTarget::dumpMemoryStatistics( @@ -56,11 +57,11 @@ bool GrGLTextureRenderTarget::canAttemptStencilAttachment() const { } sk_sp GrGLTextureRenderTarget::MakeWrapped( - GrGLGpu* gpu, const GrSurfaceDesc& desc, const GrGLTexture::IDDesc& texIDDesc, - const GrGLRenderTarget::IDDesc& rtIDDesc, GrMipMapsStatus mipMapsStatus) -{ + GrGLGpu* gpu, const GrSurfaceDesc& desc, const GrGLTexture::IDDesc& texIDDesc, + const GrGLRenderTarget::IDDesc& rtIDDesc, GrWrapCacheable cacheable, + GrMipMapsStatus mipMapsStatus) { return sk_sp( - new GrGLTextureRenderTarget(gpu, desc, texIDDesc, rtIDDesc, mipMapsStatus)); + new GrGLTextureRenderTarget(gpu, desc, texIDDesc, rtIDDesc, cacheable, mipMapsStatus)); } size_t GrGLTextureRenderTarget::onGpuMemorySize() const { diff --git a/src/gpu/gl/GrGLTextureRenderTarget.h b/src/gpu/gl/GrGLTextureRenderTarget.h index f33ff2838a..ffb5643449 100644 --- a/src/gpu/gl/GrGLTextureRenderTarget.h +++ b/src/gpu/gl/GrGLTextureRenderTarget.h @@ -38,7 +38,7 @@ public: static sk_sp MakeWrapped(GrGLGpu* gpu, const GrSurfaceDesc& desc, const GrGLTexture::IDDesc& texIDDesc, const GrGLRenderTarget::IDDesc& rtIDDesc, - GrMipMapsStatus); + GrWrapCacheable cacheble, GrMipMapsStatus); GrBackendFormat backendFormat() const override { // It doesn't matter if we take the texture or render target path, so just pick texture. @@ -62,6 +62,7 @@ private: const GrSurfaceDesc& desc, const GrGLTexture::IDDesc& texIDDesc, const GrGLRenderTarget::IDDesc& rtIDDesc, + GrWrapCacheable, GrMipMapsStatus); size_t onGpuMemorySize() const override; diff --git a/src/gpu/mock/GrMockGpu.cpp b/src/gpu/mock/GrMockGpu.cpp index a2955f5181..8ac7684657 100644 --- a/src/gpu/mock/GrMockGpu.cpp +++ b/src/gpu/mock/GrMockGpu.cpp @@ -125,7 +125,8 @@ sk_sp GrMockGpu::onWrapBackendTexture(const GrBackendTexture& tex, sk_sp GrMockGpu::onWrapRenderableBackendTexture(const GrBackendTexture& tex, int sampleCnt, - GrWrapOwnership ownership) { + GrWrapOwnership ownership, + GrWrapCacheable cacheable) { GrSurfaceDesc desc; desc.fFlags = kRenderTarget_GrSurfaceFlag; desc.fWidth = tex.width(); @@ -144,7 +145,7 @@ sk_sp GrMockGpu::onWrapRenderableBackendTexture(const GrBackendTextur rtInfo.fID = NextInternalRenderTargetID(); return sk_sp( - new GrMockTextureRenderTarget(this, desc, mipMapsStatus, texInfo, rtInfo)); + new GrMockTextureRenderTarget(this, desc, mipMapsStatus, texInfo, rtInfo, cacheable)); } sk_sp GrMockGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& rt) { diff --git a/src/gpu/mock/GrMockGpu.h b/src/gpu/mock/GrMockGpu.h index 77090ea5a0..2a79eb05a3 100644 --- a/src/gpu/mock/GrMockGpu.h +++ b/src/gpu/mock/GrMockGpu.h @@ -64,7 +64,8 @@ private: sk_sp onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt, - GrWrapOwnership) override; + GrWrapOwnership, + GrWrapCacheable) override; sk_sp onWrapBackendRenderTarget(const GrBackendRenderTarget&) override; diff --git a/src/gpu/mock/GrMockTexture.h b/src/gpu/mock/GrMockTexture.h index e9e35af660..26741be1d9 100644 --- a/src/gpu/mock/GrMockTexture.h +++ b/src/gpu/mock/GrMockTexture.h @@ -112,7 +112,7 @@ public: GrMockRenderTarget(GrMockGpu* gpu, Wrapped, const GrSurfaceDesc& desc, const GrMockRenderTargetInfo& info) : GrSurface(gpu, desc), INHERITED(gpu, desc), fInfo(info) { - this->registerWithCacheWrapped(); + this->registerWithCacheWrapped(GrWrapCacheable::kNo); } ResolveType getResolveType() const override { return kCanResolve_ResolveType; } @@ -168,11 +168,11 @@ public: // Renderable wrapped backend texture. GrMockTextureRenderTarget(GrMockGpu* gpu, const GrSurfaceDesc& desc, GrMipMapsStatus mipMapsStatus, const GrMockTextureInfo& texInfo, - const GrMockRenderTargetInfo& rtInfo) + const GrMockRenderTargetInfo& rtInfo, GrWrapCacheable cacheble) : GrSurface(gpu, desc) , GrMockTexture(gpu, desc, mipMapsStatus, texInfo) , GrMockRenderTarget(gpu, desc, rtInfo) { - this->registerWithCacheWrapped(); + this->registerWithCacheWrapped(cacheble); } GrTexture* asTexture() override { return this; } diff --git a/src/gpu/mtl/GrMtlGpu.h b/src/gpu/mtl/GrMtlGpu.h index bab666c41a..8ab60b7c19 100644 --- a/src/gpu/mtl/GrMtlGpu.h +++ b/src/gpu/mtl/GrMtlGpu.h @@ -135,9 +135,8 @@ private: sk_sp onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrWrapCacheable, GrIOType) override; - sk_sp onWrapRenderableBackendTexture(const GrBackendTexture&, - int sampleCnt, - GrWrapOwnership) override; + sk_sp onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt, + GrWrapOwnership, GrWrapCacheable) override; sk_sp onWrapBackendRenderTarget(const GrBackendRenderTarget&) override; diff --git a/src/gpu/mtl/GrMtlGpu.mm b/src/gpu/mtl/GrMtlGpu.mm index a74ac52908..c0273e4ef1 100644 --- a/src/gpu/mtl/GrMtlGpu.mm +++ b/src/gpu/mtl/GrMtlGpu.mm @@ -357,7 +357,8 @@ sk_sp GrMtlGpu::onWrapBackendTexture(const GrBackendTexture& backendT sk_sp GrMtlGpu::onWrapRenderableBackendTexture(const GrBackendTexture& backendTex, int sampleCnt, - GrWrapOwnership ownership) { + GrWrapOwnership ownership, + GrWrapCacheable cacheable) { id mtlTexture = get_texture_from_backend(backendTex, ownership); if (!mtlTexture) { return nullptr; @@ -370,7 +371,8 @@ sk_sp GrMtlGpu::onWrapRenderableBackendTexture(const GrBackendTexture return nullptr; } - return GrMtlTextureRenderTarget::MakeWrappedTextureRenderTarget(this, surfDesc, mtlTexture); + return GrMtlTextureRenderTarget::MakeWrappedTextureRenderTarget(this, surfDesc, mtlTexture, + cacheable); } sk_sp GrMtlGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& backendRT) { diff --git a/src/gpu/mtl/GrMtlRenderTarget.h b/src/gpu/mtl/GrMtlRenderTarget.h index 98fa8e086d..199532c007 100644 --- a/src/gpu/mtl/GrMtlRenderTarget.h +++ b/src/gpu/mtl/GrMtlRenderTarget.h @@ -46,11 +46,6 @@ public: GrBackendFormat backendFormat() const override; protected: - GrMtlRenderTarget(GrMtlGpu* gpu, - const GrSurfaceDesc& desc, - id renderTexture, - id resolveTexture); - GrMtlRenderTarget(GrMtlGpu* gpu, const GrSurfaceDesc& desc, id renderTexture); @@ -77,22 +72,12 @@ protected: id fResolveTexture; private: + // Extra param to disambiguate from constructor used by subclasses. + enum Wrapped { kWrapped }; GrMtlRenderTarget(GrMtlGpu* gpu, - SkBudgeted, const GrSurfaceDesc& desc, id renderTexture, - id resolveTexture); - - GrMtlRenderTarget(GrMtlGpu* gpu, - SkBudgeted, - const GrSurfaceDesc& desc, - id renderTexture); - - static sk_sp Make(GrMtlGpu*, - SkBudgeted, - const GrSurfaceDesc&, - id renderTexture, - bool isWrapped); + Wrapped); bool completeStencilAttachment() override; }; diff --git a/src/gpu/mtl/GrMtlRenderTarget.mm b/src/gpu/mtl/GrMtlRenderTarget.mm index 59fd4798cd..07e5639294 100644 --- a/src/gpu/mtl/GrMtlRenderTarget.mm +++ b/src/gpu/mtl/GrMtlRenderTarget.mm @@ -10,18 +10,20 @@ #include "GrMtlGpu.h" #include "GrMtlUtil.h" +// Called for wrapped non-texture render targets. GrMtlRenderTarget::GrMtlRenderTarget(GrMtlGpu* gpu, - SkBudgeted budgeted, const GrSurfaceDesc& desc, - id renderTexture) + id renderTexture, + Wrapped) : GrSurface(gpu, desc) , GrRenderTarget(gpu, desc) , fRenderTexture(renderTexture) , fResolveTexture(nil) { SkASSERT(1 == desc.fSampleCnt); - this->registerWithCache(budgeted); + this->registerWithCacheWrapped(GrWrapCacheable::kNo); } +// Called by subclass constructors. GrMtlRenderTarget::GrMtlRenderTarget(GrMtlGpu* gpu, const GrSurfaceDesc& desc, id renderTexture) @@ -38,8 +40,7 @@ GrMtlRenderTarget::MakeWrappedRenderTarget(GrMtlGpu* gpu, const GrSurfaceDesc& d SkASSERT(nil != renderTexture); SkASSERT(1 == renderTexture.mipmapLevelCount); SkASSERT(MTLTextureUsageRenderTarget & renderTexture.usage); - return sk_sp(new GrMtlRenderTarget(gpu, SkBudgeted::kNo, - desc, renderTexture)); + return sk_sp(new GrMtlRenderTarget(gpu, desc, renderTexture, kWrapped)); } GrMtlRenderTarget::~GrMtlRenderTarget() { @@ -47,7 +48,6 @@ GrMtlRenderTarget::~GrMtlRenderTarget() { SkASSERT(nil == fResolveTexture); } - GrBackendRenderTarget GrMtlRenderTarget::getBackendRenderTarget() const { GrMtlTextureInfo info; info.fTexture = GrGetPtrFromId(fRenderTexture); diff --git a/src/gpu/mtl/GrMtlTextureRenderTarget.h b/src/gpu/mtl/GrMtlTextureRenderTarget.h index 412af7bf2e..50a4e8e1b2 100644 --- a/src/gpu/mtl/GrMtlTextureRenderTarget.h +++ b/src/gpu/mtl/GrMtlTextureRenderTarget.h @@ -21,7 +21,8 @@ public: static sk_sp MakeWrappedTextureRenderTarget(GrMtlGpu*, const GrSurfaceDesc&, - id); + id, + GrWrapCacheable); GrBackendFormat backendFormat() const override { return GrMtlTexture::backendFormat(); } @@ -60,14 +61,8 @@ private: GrMtlTextureRenderTarget(GrMtlGpu* gpu, const GrSurfaceDesc& desc, id renderTexture, - GrMipMapsStatus); - - static sk_sp Make(GrMtlGpu*, - const GrSurfaceDesc&, - id resolveTexture, - GrMipMapsStatus, - SkBudgeted budgeted, - bool isWrapped); + GrMipMapsStatus, + GrWrapCacheable cacheable); size_t onGpuMemorySize() const override { // TODO: When used as render targets certain formats may actually have a larger size than diff --git a/src/gpu/mtl/GrMtlTextureRenderTarget.mm b/src/gpu/mtl/GrMtlTextureRenderTarget.mm index 62fd2abf12..7bd53e1a7f 100644 --- a/src/gpu/mtl/GrMtlTextureRenderTarget.mm +++ b/src/gpu/mtl/GrMtlTextureRenderTarget.mm @@ -23,58 +23,43 @@ GrMtlTextureRenderTarget::GrMtlTextureRenderTarget(GrMtlGpu* gpu, GrMtlTextureRenderTarget::GrMtlTextureRenderTarget(GrMtlGpu* gpu, const GrSurfaceDesc& desc, id renderTexture, - GrMipMapsStatus mipMapsStatus) + GrMipMapsStatus mipMapsStatus, + GrWrapCacheable cacheable) : GrSurface(gpu, desc) , GrMtlTexture(gpu, desc, renderTexture, mipMapsStatus) , GrMtlRenderTarget(gpu, desc, renderTexture) { - this->registerWithCacheWrapped(); + this->registerWithCacheWrapped(cacheable); } -sk_sp -GrMtlTextureRenderTarget::Make(GrMtlGpu* gpu, - const GrSurfaceDesc& desc, - id renderTexture, - GrMipMapsStatus mipMapsStatus, - SkBudgeted budgeted, - bool isWrapped) { - SkASSERT(nil != renderTexture); - if (desc.fSampleCnt > 1) { - return nullptr; - } - SkASSERT((MTLTextureUsageShaderRead | MTLTextureUsageRenderTarget) & renderTexture.usage); - if (!isWrapped) { - return sk_sp(new GrMtlTextureRenderTarget(gpu, - budgeted, - desc, - renderTexture, - mipMapsStatus)); - } else { - return sk_sp(new GrMtlTextureRenderTarget(gpu, - desc, - renderTexture, - mipMapsStatus)); - } -} - - sk_sp GrMtlTextureRenderTarget::CreateNewTextureRenderTarget(GrMtlGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc& desc, MTLTextureDescriptor* texDesc, GrMipMapsStatus mipMapsStatus) { - id texture = [gpu->device() newTextureWithDescriptor:texDesc]; - return Make(gpu, desc, texture, mipMapsStatus, budgeted, false); + id renderTexture = [gpu->device() newTextureWithDescriptor:texDesc]; + SkASSERT(nil != renderTexture); + if (desc.fSampleCnt > 1) { + return nullptr; + } + SkASSERT((MTLTextureUsageShaderRead | MTLTextureUsageRenderTarget) & renderTexture.usage); + return sk_sp( + new GrMtlTextureRenderTarget(gpu, budgeted, desc, renderTexture, mipMapsStatus)); } -sk_sp -GrMtlTextureRenderTarget::MakeWrappedTextureRenderTarget(GrMtlGpu* gpu, - const GrSurfaceDesc& desc, - id texture) { - - SkASSERT(nil != texture); - GrMipMapsStatus mipMapsStatus = texture.mipmapLevelCount > 1 ? GrMipMapsStatus::kDirty - : GrMipMapsStatus::kNotAllocated; - return Make(gpu, desc, texture, mipMapsStatus, SkBudgeted::kNo, true); +sk_sp GrMtlTextureRenderTarget::MakeWrappedTextureRenderTarget( + GrMtlGpu* gpu, + const GrSurfaceDesc& desc, + id renderTexture, + GrWrapCacheable cacheable) { + SkASSERT(nil != renderTexture); + GrMipMapsStatus mipMapsStatus = renderTexture.mipmapLevelCount > 1 + ? GrMipMapsStatus::kDirty + : GrMipMapsStatus::kNotAllocated; + if (desc.fSampleCnt > 1) { + return nullptr; + } + SkASSERT((MTLTextureUsageShaderRead | MTLTextureUsageRenderTarget) & renderTexture.usage); + return sk_sp( + new GrMtlTextureRenderTarget(gpu, desc, renderTexture, mipMapsStatus, cacheable)); } - diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp index b85d6030e8..142c1c77a2 100644 --- a/src/gpu/vk/GrVkGpu.cpp +++ b/src/gpu/vk/GrVkGpu.cpp @@ -1048,7 +1048,8 @@ sk_sp GrVkGpu::onWrapBackendTexture(const GrBackendTexture& backendTe sk_sp GrVkGpu::onWrapRenderableBackendTexture(const GrBackendTexture& backendTex, int sampleCnt, - GrWrapOwnership ownership) { + GrWrapOwnership ownership, + GrWrapCacheable cacheable) { GrVkImageInfo imageInfo; if (!backendTex.getVkImageInfo(&imageInfo)) { return nullptr; @@ -1068,8 +1069,8 @@ sk_sp GrVkGpu::onWrapRenderableBackendTexture(const GrBackendTexture& sk_sp layout = backendTex.getGrVkImageLayout(); SkASSERT(layout); - return GrVkTextureRenderTarget::MakeWrappedTextureRenderTarget(this, surfDesc, ownership, - imageInfo, std::move(layout)); + return GrVkTextureRenderTarget::MakeWrappedTextureRenderTarget( + this, surfDesc, ownership, cacheable, imageInfo, std::move(layout)); } sk_sp GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& backendRT){ diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h index 8200b6fd5c..671549e4d4 100644 --- a/src/gpu/vk/GrVkGpu.h +++ b/src/gpu/vk/GrVkGpu.h @@ -188,7 +188,8 @@ private: GrIOType) override; sk_sp onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt, - GrWrapOwnership) override; + GrWrapOwnership, + GrWrapCacheable) override; sk_sp onWrapBackendRenderTarget(const GrBackendRenderTarget&) override; sk_sp onWrapBackendTextureAsRenderTarget(const GrBackendTexture&, diff --git a/src/gpu/vk/GrVkRenderTarget.cpp b/src/gpu/vk/GrVkRenderTarget.cpp index 36dcb60b3b..ab611509bc 100644 --- a/src/gpu/vk/GrVkRenderTarget.cpp +++ b/src/gpu/vk/GrVkRenderTarget.cpp @@ -42,7 +42,7 @@ GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu, , fCachedSimpleRenderPass(nullptr) { SkASSERT(desc.fSampleCnt > 1); this->createFramebuffer(gpu); - this->registerWithCacheWrapped(); + this->registerWithCacheWrapped(GrWrapCacheable::kNo); } // We're virtually derived from GrSurface (via GrRenderTarget) so its @@ -87,7 +87,7 @@ GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu, , fCachedSimpleRenderPass(nullptr) { SkASSERT(1 == desc.fSampleCnt); this->createFramebuffer(gpu); - this->registerWithCacheWrapped(); + this->registerWithCacheWrapped(GrWrapCacheable::kNo); } // We're virtually derived from GrSurface (via GrRenderTarget) so its @@ -125,7 +125,7 @@ GrVkRenderTarget::GrVkRenderTarget(GrVkGpu* gpu, , fFramebuffer(nullptr) , fCachedSimpleRenderPass(renderPass) , fSecondaryCommandBuffer(secondaryCommandBuffer) { - this->registerWithCacheWrapped(); + this->registerWithCacheWrapped(GrWrapCacheable::kNo); } sk_sp GrVkRenderTarget::MakeWrappedRenderTarget( diff --git a/src/gpu/vk/GrVkSemaphore.cpp b/src/gpu/vk/GrVkSemaphore.cpp index 8491782641..dde435fca6 100644 --- a/src/gpu/vk/GrVkSemaphore.cpp +++ b/src/gpu/vk/GrVkSemaphore.cpp @@ -46,7 +46,8 @@ GrVkSemaphore::GrVkSemaphore(GrVkGpu* gpu, VkSemaphore semaphore, bool prohibitS bool prohibitWait, bool isOwned) : INHERITED(gpu) { fResource = new Resource(semaphore, prohibitSignal, prohibitWait, isOwned); - isOwned ? this->registerWithCache(SkBudgeted::kNo) : this->registerWithCacheWrapped(); + isOwned ? this->registerWithCache(SkBudgeted::kNo) + : this->registerWithCacheWrapped(GrWrapCacheable::kNo); } void GrVkSemaphore::onRelease() { diff --git a/src/gpu/vk/GrVkTextureRenderTarget.cpp b/src/gpu/vk/GrVkTextureRenderTarget.cpp index 3656c82d11..234c4d1f3e 100644 --- a/src/gpu/vk/GrVkTextureRenderTarget.cpp +++ b/src/gpu/vk/GrVkTextureRenderTarget.cpp @@ -28,11 +28,11 @@ GrVkTextureRenderTarget::GrVkTextureRenderTarget(GrVkGpu* gpu, sk_sp msaaLayout, const GrVkImageView* colorAttachmentView, const GrVkImageView* resolveAttachmentView, - GrMipMapsStatus mipMapsStatus, - GrBackendObjectOwnership ownership) + GrMipMapsStatus mipMapsStatus) : GrSurface(gpu, desc) - , GrVkImage(info, layout, ownership) - , GrVkTexture(gpu, desc, info, layout, texView, mipMapsStatus, ownership) + , GrVkImage(info, layout, GrBackendObjectOwnership::kOwned) + , GrVkTexture(gpu, desc, info, layout, texView, mipMapsStatus, + GrBackendObjectOwnership::kOwned) , GrVkRenderTarget(gpu, desc, info, layout, msaaInfo, std::move(msaaLayout), colorAttachmentView, resolveAttachmentView, GrBackendObjectOwnership::kOwned) { @@ -46,11 +46,11 @@ GrVkTextureRenderTarget::GrVkTextureRenderTarget(GrVkGpu* gpu, sk_sp layout, const GrVkImageView* texView, const GrVkImageView* colorAttachmentView, - GrMipMapsStatus mipMapsStatus, - GrBackendObjectOwnership ownership) + GrMipMapsStatus mipMapsStatus) : GrSurface(gpu, desc) - , GrVkImage(info, layout, ownership) - , GrVkTexture(gpu, desc, info, layout, texView, mipMapsStatus, ownership) + , GrVkImage(info, layout, GrBackendObjectOwnership::kOwned) + , GrVkTexture(gpu, desc, info, layout, texView, mipMapsStatus, + GrBackendObjectOwnership::kOwned) , GrVkRenderTarget(gpu, desc, info, layout, colorAttachmentView, GrBackendObjectOwnership::kOwned) { this->registerWithCache(budgeted); @@ -66,13 +66,14 @@ GrVkTextureRenderTarget::GrVkTextureRenderTarget(GrVkGpu* gpu, const GrVkImageView* colorAttachmentView, const GrVkImageView* resolveAttachmentView, GrMipMapsStatus mipMapsStatus, - GrBackendObjectOwnership ownership) + GrBackendObjectOwnership ownership, + GrWrapCacheable cacheable) : GrSurface(gpu, desc) , GrVkImage(info, layout, ownership) , GrVkTexture(gpu, desc, info, layout, texView, mipMapsStatus, ownership) , GrVkRenderTarget(gpu, desc, info, layout, msaaInfo, std::move(msaaLayout), colorAttachmentView, resolveAttachmentView, ownership) { - this->registerWithCacheWrapped(); + this->registerWithCacheWrapped(cacheable); } GrVkTextureRenderTarget::GrVkTextureRenderTarget(GrVkGpu* gpu, @@ -82,29 +83,33 @@ GrVkTextureRenderTarget::GrVkTextureRenderTarget(GrVkGpu* gpu, const GrVkImageView* texView, const GrVkImageView* colorAttachmentView, GrMipMapsStatus mipMapsStatus, - GrBackendObjectOwnership ownership) + GrBackendObjectOwnership ownership, + GrWrapCacheable cacheable) : GrSurface(gpu, desc) , GrVkImage(info, layout, ownership) , GrVkTexture(gpu, desc, info, layout, texView, mipMapsStatus, ownership) , GrVkRenderTarget(gpu, desc, info, layout, colorAttachmentView, ownership) { - this->registerWithCacheWrapped(); + this->registerWithCacheWrapped(cacheable); } -sk_sp GrVkTextureRenderTarget::Make(GrVkGpu* gpu, - const GrSurfaceDesc& desc, - const GrVkImageInfo& info, - sk_sp layout, - GrMipMapsStatus mipMapsStatus, - SkBudgeted budgeted, - GrBackendObjectOwnership ownership, - bool isWrapped) { +namespace { +struct Views { + const GrVkImageView* imageView = nullptr; + const GrVkImageView* colorAttachmentView = nullptr; + const GrVkImageView* resolveAttachmentView = nullptr; + GrVkImageInfo msInfo; + sk_sp msLayout; +}; +} // anonymous namespace + +static Views create_views(GrVkGpu* gpu, const GrSurfaceDesc& desc, const GrVkImageInfo& info) { VkImage image = info.fImage; // Create the texture ImageView - const GrVkImageView* imageView = GrVkImageView::Create( - gpu, image, info.fFormat, GrVkImageView::kColor_Type, info.fLevelCount, - info.fYcbcrConversionInfo); - if (!imageView) { - return nullptr; + Views views; + views.imageView = GrVkImageView::Create(gpu, image, info.fFormat, GrVkImageView::kColor_Type, + info.fLevelCount, info.fYcbcrConversionInfo); + if (!views.imageView) { + return {}; } VkFormat pixelFormat; @@ -113,9 +118,6 @@ sk_sp GrVkTextureRenderTarget::Make(GrVkGpu* gpu, VkImage colorImage; // create msaa surface if necessary - GrVkImageInfo msInfo; - sk_sp msLayout; - const GrVkImageView* resolveAttachmentView = nullptr; if (desc.fSampleCnt > 1) { GrVkImage::ImageDesc msImageDesc; msImageDesc.fImageType = VK_IMAGE_TYPE_2D; @@ -130,74 +132,40 @@ sk_sp GrVkTextureRenderTarget::Make(GrVkGpu* gpu, VK_IMAGE_USAGE_TRANSFER_SRC_BIT; msImageDesc.fMemProps = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT; - if (!GrVkImage::InitImageInfo(gpu, msImageDesc, &msInfo)) { - imageView->unref(gpu); - return nullptr; + if (!GrVkImage::InitImageInfo(gpu, msImageDesc, &views.msInfo)) { + views.imageView->unref(gpu); + return {}; } // Set color attachment image - colorImage = msInfo.fImage; + colorImage = views.msInfo.fImage; // Create resolve attachment view. - resolveAttachmentView = GrVkImageView::Create(gpu, image, pixelFormat, - GrVkImageView::kColor_Type, - info.fLevelCount, GrVkYcbcrConversionInfo()); - if (!resolveAttachmentView) { - GrVkImage::DestroyImageInfo(gpu, &msInfo); - imageView->unref(gpu); - return nullptr; + views.resolveAttachmentView = + GrVkImageView::Create(gpu, image, pixelFormat, GrVkImageView::kColor_Type, + info.fLevelCount, GrVkYcbcrConversionInfo()); + if (!views.resolveAttachmentView) { + GrVkImage::DestroyImageInfo(gpu, &views.msInfo); + views.imageView->unref(gpu); + return {}; } - msLayout.reset(new GrVkImageLayout(msInfo.fImageLayout)); + views.msLayout.reset(new GrVkImageLayout(views.msInfo.fImageLayout)); } else { // Set color attachment image colorImage = info.fImage; } - const GrVkImageView* colorAttachmentView = GrVkImageView::Create(gpu, colorImage, pixelFormat, - GrVkImageView::kColor_Type, 1, - GrVkYcbcrConversionInfo()); - if (!colorAttachmentView) { + views.colorAttachmentView = GrVkImageView::Create( + gpu, colorImage, pixelFormat, GrVkImageView::kColor_Type, 1, GrVkYcbcrConversionInfo()); + if (!views.colorAttachmentView) { if (desc.fSampleCnt > 1) { - resolveAttachmentView->unref(gpu); - GrVkImage::DestroyImageInfo(gpu, &msInfo); + views.resolveAttachmentView->unref(gpu); + GrVkImage::DestroyImageInfo(gpu, &views.msInfo); } - imageView->unref(gpu); - return nullptr; + views.imageView->unref(gpu); + return {}; } - - sk_sp texRT; - if (desc.fSampleCnt > 1) { - if (!isWrapped) { - texRT = sk_sp(new GrVkTextureRenderTarget( - gpu, budgeted, desc, - info, std::move(layout), imageView, msInfo, - std::move(msLayout), colorAttachmentView, - resolveAttachmentView, mipMapsStatus, - ownership)); - } else { - texRT = sk_sp(new GrVkTextureRenderTarget( - gpu, desc, - info, std::move(layout), imageView, msInfo, - std::move(msLayout), colorAttachmentView, - resolveAttachmentView, mipMapsStatus, - ownership)); - } - } else { - if (!isWrapped) { - texRT = sk_sp(new GrVkTextureRenderTarget( - gpu, budgeted, desc, - info, std::move(layout), imageView, - colorAttachmentView, mipMapsStatus, - ownership)); - } else { - texRT = sk_sp(new GrVkTextureRenderTarget( - gpu, desc, - info, std::move(layout), imageView, - colorAttachmentView, mipMapsStatus, - ownership)); - } - } - return texRT; + return views; } sk_sp @@ -215,21 +183,30 @@ GrVkTextureRenderTarget::MakeNewTextureRenderTarget(GrVkGpu* gpu, } sk_sp layout(new GrVkImageLayout(info.fImageLayout)); - sk_sp trt = Make(gpu, desc, info, std::move(layout), mipMapsStatus, - budgeted, GrBackendObjectOwnership::kOwned, false); - if (!trt) { + Views views = create_views(gpu, desc, info); + if (!views.colorAttachmentView) { GrVkImage::DestroyImageInfo(gpu, &info); + return nullptr; + } + if (desc.fSampleCnt > 1) { + return sk_sp(new GrVkTextureRenderTarget( + gpu, budgeted, desc, info, std::move(layout), views.imageView, views.msInfo, + std::move(views.msLayout), views.colorAttachmentView, views.resolveAttachmentView, + mipMapsStatus)); + } else { + return sk_sp(new GrVkTextureRenderTarget( + gpu, budgeted, desc, info, std::move(layout), views.imageView, + views.colorAttachmentView, mipMapsStatus)); } - - return trt; } -sk_sp -GrVkTextureRenderTarget::MakeWrappedTextureRenderTarget(GrVkGpu* gpu, - const GrSurfaceDesc& desc, - GrWrapOwnership wrapOwnership, - const GrVkImageInfo& info, - sk_sp layout) { +sk_sp GrVkTextureRenderTarget::MakeWrappedTextureRenderTarget( + GrVkGpu* gpu, + const GrSurfaceDesc& desc, + GrWrapOwnership wrapOwnership, + GrWrapCacheable cacheable, + const GrVkImageInfo& info, + sk_sp layout) { // Wrapped textures require both image and allocation (because they can be mapped) SkASSERT(VK_NULL_HANDLE != info.fImage && VK_NULL_HANDLE != info.fAlloc.fMemory); @@ -238,43 +215,20 @@ GrVkTextureRenderTarget::MakeWrappedTextureRenderTarget(GrVkGpu* gpu, GrBackendObjectOwnership ownership = kBorrow_GrWrapOwnership == wrapOwnership ? GrBackendObjectOwnership::kBorrowed : GrBackendObjectOwnership::kOwned; - - return Make(gpu, desc, info, std::move(layout), mipMapsStatus, SkBudgeted::kNo, ownership, - true); -} - -bool GrVkTextureRenderTarget::updateForMipmap(GrVkGpu* gpu, const GrVkImageInfo& newInfo) { - VkFormat pixelFormat; - GrPixelConfigToVkFormat(this->config(), &pixelFormat); - if (this->numStencilSamples() > 1) { - const GrVkImageView* resolveAttachmentView = - GrVkImageView::Create(gpu, - newInfo.fImage, - pixelFormat, - GrVkImageView::kColor_Type, - newInfo.fLevelCount, - GrVkYcbcrConversionInfo()); - if (!resolveAttachmentView) { - return false; - } - fResolveAttachmentView->unref(gpu); - fResolveAttachmentView = resolveAttachmentView; - } else { - const GrVkImageView* colorAttachmentView = GrVkImageView::Create(gpu, - newInfo.fImage, - pixelFormat, - GrVkImageView::kColor_Type, - 1, - GrVkYcbcrConversionInfo()); - if (!colorAttachmentView) { - return false; - } - fColorAttachmentView->unref(gpu); - fColorAttachmentView = colorAttachmentView; + Views views = create_views(gpu, desc, info); + if (!views.colorAttachmentView) { + return nullptr; + } + if (desc.fSampleCnt > 1) { + return sk_sp(new GrVkTextureRenderTarget( + gpu, desc, info, std::move(layout), views.imageView, views.msInfo, + std::move(views.msLayout), views.colorAttachmentView, views.resolveAttachmentView, + mipMapsStatus, ownership, cacheable)); + } else { + return sk_sp(new GrVkTextureRenderTarget( + gpu, desc, info, std::move(layout), views.imageView, views.colorAttachmentView, + mipMapsStatus, ownership, cacheable)); } - - this->createFramebuffer(gpu); - return true; } size_t GrVkTextureRenderTarget::onGpuMemorySize() const { diff --git a/src/gpu/vk/GrVkTextureRenderTarget.h b/src/gpu/vk/GrVkTextureRenderTarget.h index 5026213afa..1538287883 100644 --- a/src/gpu/vk/GrVkTextureRenderTarget.h +++ b/src/gpu/vk/GrVkTextureRenderTarget.h @@ -34,11 +34,10 @@ public: static sk_sp MakeWrappedTextureRenderTarget(GrVkGpu*, const GrSurfaceDesc&, GrWrapOwnership, + GrWrapCacheable, const GrVkImageInfo&, sk_sp); - bool updateForMipmap(GrVkGpu* gpu, const GrVkImageInfo& newInfo); - GrBackendFormat backendFormat() const override { return this->getBackendFormat(); } protected: @@ -53,6 +52,7 @@ protected: } private: + // MSAA, not-wrapped GrVkTextureRenderTarget(GrVkGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc& desc, @@ -63,9 +63,9 @@ private: sk_sp msaaLayout, const GrVkImageView* colorAttachmentView, const GrVkImageView* resolveAttachmentView, - GrMipMapsStatus, - GrBackendObjectOwnership); + GrMipMapsStatus); + // non-MSAA, not-wrapped GrVkTextureRenderTarget(GrVkGpu* gpu, SkBudgeted budgeted, const GrSurfaceDesc& desc, @@ -73,9 +73,9 @@ private: sk_sp layout, const GrVkImageView* texView, const GrVkImageView* colorAttachmentView, - GrMipMapsStatus, - GrBackendObjectOwnership); + GrMipMapsStatus); + // MSAA, wrapped GrVkTextureRenderTarget(GrVkGpu* gpu, const GrSurfaceDesc& desc, const GrVkImageInfo& info, @@ -86,8 +86,10 @@ private: const GrVkImageView* colorAttachmentView, const GrVkImageView* resolveAttachmentView, GrMipMapsStatus, - GrBackendObjectOwnership); + GrBackendObjectOwnership, + GrWrapCacheable); + // non-MSAA, wrapped GrVkTextureRenderTarget(GrVkGpu* gpu, const GrSurfaceDesc& desc, const GrVkImageInfo& info, @@ -95,16 +97,8 @@ private: const GrVkImageView* texView, const GrVkImageView* colorAttachmentView, GrMipMapsStatus, - GrBackendObjectOwnership); - - static sk_sp Make(GrVkGpu*, - const GrSurfaceDesc&, - const GrVkImageInfo&, - sk_sp, - GrMipMapsStatus, - SkBudgeted budgeted, - GrBackendObjectOwnership, - bool isWrapped); + GrBackendObjectOwnership, + GrWrapCacheable); // GrGLRenderTarget accounts for the texture's memory and any MSAA renderbuffer's memory. size_t onGpuMemorySize() const override; diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index a2a203ef6d..96dd8415b9 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -113,8 +113,9 @@ static sk_sp new_wrapped_texture_common(GrContext* ctx, } GrProxyProvider* proxyProvider = ctx->contextPriv().proxyProvider(); - sk_sp proxy = proxyProvider->wrapBackendTexture( - backendTex, origin, ownership, kRead_GrIOType, releaseProc, releaseCtx); + sk_sp proxy = + proxyProvider->wrapBackendTexture(backendTex, origin, ownership, GrWrapCacheable::kNo, + kRead_GrIOType, releaseProc, releaseCtx); if (!proxy) { return nullptr; } diff --git a/src/image/SkImage_GpuBase.cpp b/src/image/SkImage_GpuBase.cpp index 0e74923f2e..330808222b 100644 --- a/src/image/SkImage_GpuBase.cpp +++ b/src/image/SkImage_GpuBase.cpp @@ -292,9 +292,9 @@ bool SkImage_GpuBase::MakeTempTextureProxies(GrContext* ctx, const GrBackendText } SkASSERT(yuvaTexturesCopy[textureIndex].isValid()); - tempTextureProxies[textureIndex] = - proxyProvider->wrapBackendTexture(yuvaTexturesCopy[textureIndex], imageOrigin, - kBorrow_GrWrapOwnership, kRead_GrIOType); + tempTextureProxies[textureIndex] = proxyProvider->wrapBackendTexture( + yuvaTexturesCopy[textureIndex], imageOrigin, kBorrow_GrWrapOwnership, + GrWrapCacheable::kNo, kRead_GrIOType); if (!tempTextureProxies[textureIndex]) { return false; } @@ -460,7 +460,7 @@ sk_sp SkImage_GpuBase::MakePromiseImageLazyProxy( } auto tex = resourceProvider->wrapBackendTexture(backendTexture, kBorrow_GrWrapOwnership, - kRead_GrIOType); + GrWrapCacheable::kYes, kRead_GrIOType); if (!tex) { // Even though we failed to wrap the backend texture, we must call the release // proc to keep our contract of always calling Fulfill and Release in pairs. diff --git a/tests/GrPorterDuffTest.cpp b/tests/GrPorterDuffTest.cpp index 6005be57a4..6873fe8b68 100644 --- a/tests/GrPorterDuffTest.cpp +++ b/tests/GrPorterDuffTest.cpp @@ -997,7 +997,8 @@ DEF_GPUTEST(PorterDuffNoDualSourceBlending, reporter, options) { GrXferProcessor::DstProxy fakeDstProxy; { sk_sp proxy = proxyProvider->wrapBackendTexture( - backendTex, kTopLeft_GrSurfaceOrigin, kBorrow_GrWrapOwnership, kRead_GrIOType); + backendTex, kTopLeft_GrSurfaceOrigin, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, + kRead_GrIOType); fakeDstProxy.setProxy(std::move(proxy)); } diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp index 752533bb74..89917d6733 100644 --- a/tests/GrSurfaceTest.cpp +++ b/tests/GrSurfaceTest.cpp @@ -53,8 +53,8 @@ DEF_GPUTEST_FOR_NULLGL_CONTEXT(GrSurface, reporter, ctxInfo) { GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture( nullptr, 256, 256, GrColorType::kRGBA_8888, false, GrMipMapped::kNo); - sk_sp texRT2 = - resourceProvider->wrapRenderableBackendTexture(backendTex, 1, kBorrow_GrWrapOwnership); + sk_sp texRT2 = resourceProvider->wrapRenderableBackendTexture( + backendTex, 1, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo); REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asRenderTarget()); REPORTER_ASSERT(reporter, texRT2.get() == texRT2->asTexture()); @@ -279,7 +279,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadOnlyTexture, reporter, context_info) { auto backendTex = context->contextPriv().getGpu()->createTestingOnlyBackendTexture( pixels.addr(), kSize, kSize, kRGBA_8888_SkColorType, true, GrMipMapped::kNo); auto proxy = proxyProvider->wrapBackendTexture(backendTex, kTopLeft_GrSurfaceOrigin, - kBorrow_GrWrapOwnership, ioType); + kBorrow_GrWrapOwnership, + GrWrapCacheable::kNo, ioType); auto surfContext = context->contextPriv().makeWrappedSurfaceContext(proxy); // Read pixels should work with a read-only texture. @@ -323,7 +324,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadOnlyTexture, reporter, context_info) { backendTex = context->contextPriv().getGpu()->createTestingOnlyBackendTexture( nullptr, kSize, kSize, kRGBA_8888_SkColorType, true, GrMipMapped::kYes); proxy = proxyProvider->wrapBackendTexture(backendTex, kTopLeft_GrSurfaceOrigin, - kBorrow_GrWrapOwnership, ioType); + kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, + ioType); context->flush(); proxy->peekTexture()->texturePriv().markMipMapsDirty(); // avoids assert in GrGpu. auto regenResult = @@ -363,7 +365,7 @@ DEF_GPUTEST(TextureIdleProcTest, reporter, options) { auto backendTexture = context->contextPriv().getGpu()->createTestingOnlyBackendTexture( nullptr, kS, kS, GrColorType::kRGBA_8888, false, GrMipMapped::kNo); auto texture = context->contextPriv().resourceProvider()->wrapBackendTexture( - backendTexture, kBorrow_GrWrapOwnership, kRW_GrIOType); + backendTexture, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType); installBackendTextureReleaseProc(texture.get()); return texture; }; @@ -372,7 +374,7 @@ DEF_GPUTEST(TextureIdleProcTest, reporter, options) { auto backendTexture = context->contextPriv().getGpu()->createTestingOnlyBackendTexture( nullptr, kS, kS, GrColorType::kRGBA_8888, true, GrMipMapped::kNo); auto texture = context->contextPriv().resourceProvider()->wrapRenderableBackendTexture( - backendTexture, 1, kBorrow_GrWrapOwnership); + backendTexture, 1, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo); installBackendTextureReleaseProc(texture.get()); return texture; }; diff --git a/tests/GrTestingBackendTextureUploadTest.cpp b/tests/GrTestingBackendTextureUploadTest.cpp index 5709e26a13..5b272c96f6 100644 --- a/tests/GrTestingBackendTextureUploadTest.cpp +++ b/tests/GrTestingBackendTextureUploadTest.cpp @@ -47,11 +47,11 @@ void testing_only_texture_test(skiatest::Reporter* reporter, GrContext* context, sk_sp wrappedTex; if (renderTarget) { - wrappedTex = gpu->wrapRenderableBackendTexture(backendTex, 1, - GrWrapOwnership::kAdopt_GrWrapOwnership); + wrappedTex = gpu->wrapRenderableBackendTexture( + backendTex, 1, GrWrapOwnership::kAdopt_GrWrapOwnership, GrWrapCacheable::kNo); } else { wrappedTex = gpu->wrapBackendTexture(backendTex, GrWrapOwnership::kAdopt_GrWrapOwnership, - GrWrapCacheable::kYes, kRead_GrIOType); + GrWrapCacheable::kNo, kRead_GrIOType); } REPORTER_ASSERT(reporter, wrappedTex); diff --git a/tests/LazyProxyTest.cpp b/tests/LazyProxyTest.cpp index 479d2cbe1e..ecc639c51a 100644 --- a/tests/LazyProxyTest.cpp +++ b/tests/LazyProxyTest.cpp @@ -468,7 +468,7 @@ DEF_GPUTEST(LazyProxyDeinstantiateTest, reporter, /* options */) { sk_sp texture = rp->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership, - kRead_GrIOType, GrWrapCacheable::kYes); + GrWrapCacheable::kNo, kRead_GrIOType); if (!texture) { return sk_sp(); } diff --git a/tests/ProxyTest.cpp b/tests/ProxyTest.cpp index 02b483e8ee..7419feec14 100644 --- a/tests/ProxyTest.cpp +++ b/tests/ProxyTest.cpp @@ -297,7 +297,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) { true, GrMipMapped::kNo); sk_sp sProxy = proxyProvider->wrapRenderableBackendTexture( - backendTex, origin, supportedNumSamples); + backendTex, origin, supportedNumSamples, kBorrow_GrWrapOwnership, + GrWrapCacheable::kNo); if (!sProxy) { gpu->deleteTestingOnlyBackendTexture(backendTex); continue; // This can fail on Mesa @@ -323,7 +324,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WrappedProxyTest, reporter, ctxInfo) { false, GrMipMapped::kNo); sk_sp sProxy = proxyProvider->wrapBackendTexture( - backendTex, origin, kBorrow_GrWrapOwnership, kRead_GrIOType); + backendTex, origin, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, + kRead_GrIOType); if (!sProxy) { gpu->deleteTestingOnlyBackendTexture(backendTex); continue; diff --git a/tests/RectangleTextureTest.cpp b/tests/RectangleTextureTest.cpp index dc1d3b7dd6..7ca72fc200 100644 --- a/tests/RectangleTextureTest.cpp +++ b/tests/RectangleTextureTest.cpp @@ -136,7 +136,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(RectangleTexture, reporter, ctxInfo) { } sk_sp rectProxy = proxyProvider->wrapBackendTexture( - rectangleTex, origin, kBorrow_GrWrapOwnership, kRW_GrIOType); + rectangleTex, origin, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType); if (!rectProxy) { ERRORF(reporter, "Error creating proxy for rectangle texture."); diff --git a/tests/ResourceAllocatorTest.cpp b/tests/ResourceAllocatorTest.cpp index ab24b00643..f711691010 100644 --- a/tests/ResourceAllocatorTest.cpp +++ b/tests/ResourceAllocatorTest.cpp @@ -70,7 +70,7 @@ static GrSurfaceProxy* make_backend(GrContext* context, const ProxyParams& p, } auto tmp = proxyProvider->wrapBackendTexture(*backendTex, p.fOrigin, kBorrow_GrWrapOwnership, - kRead_GrIOType); + GrWrapCacheable::kNo, kRead_GrIOType); if (!tmp) { return nullptr; } diff --git a/tests/ResourceCacheTest.cpp b/tests/ResourceCacheTest.cpp index 96a0b2f07f..532cb660fc 100644 --- a/tests/ResourceCacheTest.cpp +++ b/tests/ResourceCacheTest.cpp @@ -223,10 +223,10 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceCacheWrappedResources, reporter, ctxI context->resetContext(); sk_sp borrowed(resourceProvider->wrapBackendTexture( - backendTextures[0], kBorrow_GrWrapOwnership, kRead_GrIOType)); + backendTextures[0], kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType)); sk_sp adopted(resourceProvider->wrapBackendTexture( - backendTextures[1], kAdopt_GrWrapOwnership, kRead_GrIOType)); + backendTextures[1], kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType)); REPORTER_ASSERT(reporter, borrowed != nullptr && adopted != nullptr); if (!borrowed || !adopted) { @@ -277,8 +277,9 @@ public: SimulatedProperty property, size_t size = kDefaultSize) { return new TestResource(gpu, budgeted, property, kScratchConstructor, size); } - static TestResource* CreateWrapped(GrGpu* gpu, size_t size = kDefaultSize) { - return new TestResource(gpu, size); + static TestResource* CreateWrapped(GrGpu* gpu, GrWrapCacheable cacheable, + size_t size = kDefaultSize) { + return new TestResource(gpu, cacheable, size); } ~TestResource() override { @@ -317,14 +318,14 @@ private: } // Constructor for simulating resources that wrap backend objects. - TestResource(GrGpu* gpu, size_t size) - : INHERITED(gpu) - , fToDelete(nullptr) - , fSize(size) - , fProperty(kA_SimulatedProperty) - , fIsScratch(false) { + TestResource(GrGpu* gpu, GrWrapCacheable cacheable, size_t size) + : INHERITED(gpu) + , fToDelete(nullptr) + , fSize(size) + , fProperty(kA_SimulatedProperty) + , fIsScratch(false) { ++fNumAlive; - this->registerWithCacheWrapped(); + this->registerWithCacheWrapped(cacheable); } void computeScratchKey(GrScratchKey* key) const override { @@ -501,24 +502,33 @@ static void test_budgeting(skiatest::Reporter* reporter) { 10); TestResource* unique = new TestResource(gpu, SkBudgeted::kYes, 11); unique->resourcePriv().setUniqueKey(uniqueKey); - TestResource* wrapped = TestResource::CreateWrapped(gpu, 12); - TestResource* unbudgeted = new TestResource(gpu, SkBudgeted::kNo, 13); + TestResource* wrappedCacheable = TestResource::CreateWrapped(gpu, GrWrapCacheable::kYes, 12); + TestResource* wrappedUncacheable = TestResource::CreateWrapped(gpu, GrWrapCacheable::kNo, 13); + TestResource* unbudgeted = new TestResource(gpu, SkBudgeted::kNo, 14); - // Make sure we can add a unique key to the wrapped resource + // Make sure we can add a unique key to the wrapped resources GrUniqueKey uniqueKey2; make_unique_key<0>(&uniqueKey2, 1); - wrapped->resourcePriv().setUniqueKey(uniqueKey2); - GrGpuResource* wrappedViaKey = cache->findAndRefUniqueResource(uniqueKey2); - REPORTER_ASSERT(reporter, wrappedViaKey != nullptr); + GrUniqueKey uniqueKey3; + make_unique_key<0>(&uniqueKey3, 2); + wrappedCacheable->resourcePriv().setUniqueKey(uniqueKey2); + wrappedUncacheable->resourcePriv().setUniqueKey(uniqueKey3); + GrGpuResource* wrappedCacheableViaKey = cache->findAndRefUniqueResource(uniqueKey2); + REPORTER_ASSERT(reporter, wrappedCacheableViaKey); + GrGpuResource* wrappedUncacheableViaKey = cache->findAndRefUniqueResource(uniqueKey3); + REPORTER_ASSERT(reporter, wrappedUncacheableViaKey); - // Remove the extra ref we just added. - wrappedViaKey->unref(); + // Remove the extra refs we just added. + SkSafeUnref(wrappedCacheableViaKey); + SkSafeUnref(wrappedUncacheableViaKey); // Make sure sizes are as we expect - REPORTER_ASSERT(reporter, 4 == cache->getResourceCount()); + REPORTER_ASSERT(reporter, 5 == cache->getResourceCount()); REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() + - wrapped->gpuMemorySize() + unbudgeted->gpuMemorySize() == - cache->getResourceBytes()); + wrappedCacheable->gpuMemorySize() + + wrappedUncacheable->gpuMemorySize() + + unbudgeted->gpuMemorySize() == + cache->getResourceBytes()); REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() == cache->getBudgetedResourceBytes()); @@ -526,31 +536,39 @@ static void test_budgeting(skiatest::Reporter* reporter) { // Our refs mean that the resources are non purgeable. cache->purgeAllUnlocked(); - REPORTER_ASSERT(reporter, 4 == cache->getResourceCount()); + REPORTER_ASSERT(reporter, 5 == cache->getResourceCount()); REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() + - wrapped->gpuMemorySize() + unbudgeted->gpuMemorySize() == - cache->getResourceBytes()); + wrappedCacheable->gpuMemorySize() + + wrappedUncacheable->gpuMemorySize() + + unbudgeted->gpuMemorySize() == + cache->getResourceBytes()); REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() == cache->getBudgetedResourceBytes()); REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); - // Unreffing the wrapped resource with a unique key shouldn't free it right away. - wrapped->unref(); + // Unreffing the cacheable wrapped resource with a unique key shouldn't free it right away. + // However, unreffing the uncacheable wrapped resource should free it. + wrappedCacheable->unref(); + wrappedUncacheable->unref(); REPORTER_ASSERT(reporter, 4 == cache->getResourceCount()); REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + unique->gpuMemorySize() + - wrapped->gpuMemorySize() + unbudgeted->gpuMemorySize() == - cache->getResourceBytes()); + wrappedCacheable->gpuMemorySize() + + unbudgeted->gpuMemorySize() == + cache->getResourceBytes()); REPORTER_ASSERT(reporter, 12 == cache->getPurgeableBytes()); // Now try freeing the budgeted resources first - wrapped = TestResource::CreateWrapped(gpu); + wrappedCacheable = TestResource::CreateWrapped(gpu, GrWrapCacheable::kYes); + wrappedUncacheable = TestResource::CreateWrapped(gpu, GrWrapCacheable::kNo); unique->unref(); REPORTER_ASSERT(reporter, 23 == cache->getPurgeableBytes()); cache->purgeAllUnlocked(); - REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); - REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + wrapped->gpuMemorySize() + - unbudgeted->gpuMemorySize() == cache->getResourceBytes()); + REPORTER_ASSERT(reporter, 4 == cache->getResourceCount()); + REPORTER_ASSERT(reporter, scratch->gpuMemorySize() + wrappedCacheable->gpuMemorySize() + + wrappedUncacheable->gpuMemorySize() + + unbudgeted->gpuMemorySize() == + cache->getResourceBytes()); REPORTER_ASSERT(reporter, 1 == cache->getBudgetedResourceCount()); REPORTER_ASSERT(reporter, scratch->gpuMemorySize() == cache->getBudgetedResourceBytes()); REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); @@ -558,15 +576,17 @@ static void test_budgeting(skiatest::Reporter* reporter) { scratch->unref(); REPORTER_ASSERT(reporter, 10 == cache->getPurgeableBytes()); cache->purgeAllUnlocked(); - REPORTER_ASSERT(reporter, 2 == cache->getResourceCount()); - REPORTER_ASSERT(reporter, unbudgeted->gpuMemorySize() + wrapped->gpuMemorySize() == - cache->getResourceBytes()); + REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); + REPORTER_ASSERT(reporter, unbudgeted->gpuMemorySize() + wrappedCacheable->gpuMemorySize() + + wrappedUncacheable->gpuMemorySize() == + cache->getResourceBytes()); REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceBytes()); REPORTER_ASSERT(reporter, 0 == cache->getPurgeableBytes()); - // Unreffing the wrapped resource (with no unique key) should free it right away. - wrapped->unref(); + // Unreffing the wrapped resources (with no unique key) should free them right away. + wrappedUncacheable->unref(); + wrappedCacheable->unref(); REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); REPORTER_ASSERT(reporter, unbudgeted->gpuMemorySize() == cache->getResourceBytes()); REPORTER_ASSERT(reporter, 0 == cache->getBudgetedResourceCount()); @@ -630,7 +650,7 @@ static void test_unbudgeted(skiatest::Reporter* reporter) { REPORTER_ASSERT(reporter, 21 == cache->getBudgetedResourceBytes()); REPORTER_ASSERT(reporter, 21 == cache->getPurgeableBytes()); - wrapped = TestResource::CreateWrapped(gpu, large); + wrapped = TestResource::CreateWrapped(gpu, GrWrapCacheable::kYes, large); REPORTER_ASSERT(reporter, 3 == cache->getResourceCount()); REPORTER_ASSERT(reporter, 21 + large == cache->getResourceBytes()); REPORTER_ASSERT(reporter, 2 == cache->getBudgetedResourceCount()); @@ -670,7 +690,7 @@ 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, GrBudgetedType::kUnbudgetedCacheable == + REPORTER_ASSERT(reporter, GrBudgetedType::kUnbudgetedUncacheable == resource->resourcePriv().budgetedType()); REPORTER_ASSERT(reporter, nullptr == cache->findAndRefScratchResource(key, TestResource::kDefaultSize, GrResourceCache::ScratchFlags::kNone)); REPORTER_ASSERT(reporter, 1 == cache->getResourceCount()); @@ -1512,28 +1532,41 @@ static void test_free_resource_messages(skiatest::Reporter* reporter) { GrResourceCache* cache = mock.cache(); GrGpu* gpu = context->contextPriv().getGpu(); - TestResource* wrapped1 = TestResource::CreateWrapped(gpu, 12); + TestResource* wrapped1 = TestResource::CreateWrapped(gpu, GrWrapCacheable::kYes); cache->insertCrossContextGpuResource(wrapped1); REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); - TestResource* wrapped2 = TestResource::CreateWrapped(gpu, 12); + TestResource* wrapped2 = TestResource::CreateWrapped(gpu, GrWrapCacheable::kYes); cache->insertCrossContextGpuResource(wrapped2); - REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); + // An uncacheable cross-context should not be purged as soon as we drop our ref. This + // is because inserting it as a cross-context resource actually holds a ref until the + // message is received. + TestResource* wrapped3 = TestResource::CreateWrapped(gpu, GrWrapCacheable::kNo); + cache->insertCrossContextGpuResource(wrapped3); + + REPORTER_ASSERT(reporter, 3 == TestResource::NumAlive()); // Have only ref waiting on message. wrapped1->unref(); wrapped2->unref(); + wrapped3->unref(); - REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); + REPORTER_ASSERT(reporter, 3 == TestResource::NumAlive()); // This should free nothing since no messages were sent. cache->purgeAsNeeded(); // Send message to free the first resource - GrGpuResourceFreedMessage msg { wrapped1, context->uniqueID() }; - SkMessageBus::Post(msg); + GrGpuResourceFreedMessage msg1{wrapped1, context->uniqueID()}; + SkMessageBus::Post(msg1); + cache->purgeAsNeeded(); + + REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive()); + + GrGpuResourceFreedMessage msg2{wrapped3, context->uniqueID()}; + SkMessageBus::Post(msg2); cache->purgeAsNeeded(); REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive()); diff --git a/tests/TextureProxyTest.cpp b/tests/TextureProxyTest.cpp index 5260a0e987..2c1847f5e1 100644 --- a/tests/TextureProxyTest.cpp +++ b/tests/TextureProxyTest.cpp @@ -113,7 +113,8 @@ static sk_sp create_wrapped_backend(GrContext* context, SkBackin backendTex.setPixelConfig(desc.fConfig); return proxyProvider->wrapBackendTexture(backendTex, kBottomLeft_GrSurfaceOrigin, - kBorrow_GrWrapOwnership, kRead_GrIOType); + kBorrow_GrWrapOwnership, GrWrapCacheable::kYes, + kRead_GrIOType); } diff --git a/tests/TraceMemoryDumpTest.cpp b/tests/TraceMemoryDumpTest.cpp index 59f7b0f26c..0a532492db 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, - GrWrapCacheable::kYes, kRead_GrIOType); + GrWrapCacheable::kNo, kRead_GrIOType); ValidateMemoryDumps(reporter, context, texture->gpuMemorySize(), false /* isOwned */); } diff --git a/tests/VkWrapTests.cpp b/tests/VkWrapTests.cpp index 84fdc25ee4..a10efb2ba7 100644 --- a/tests/VkWrapTests.cpp +++ b/tests/VkWrapTests.cpp @@ -43,7 +43,7 @@ void wrap_tex_test(skiatest::Reporter* reporter, GrContext* context) { SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo)); sk_sp tex = gpu->wrapBackendTexture(origBackendTex, kBorrow_GrWrapOwnership, - GrWrapCacheable::kYes, kRead_GrIOType); + GrWrapCacheable::kNo, kRead_GrIOType); REPORTER_ASSERT(reporter, tex); // image is null @@ -52,10 +52,10 @@ 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, GrWrapCacheable::kYes, + tex = gpu->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType); REPORTER_ASSERT(reporter, !tex); - tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kYes, + tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType); REPORTER_ASSERT(reporter, !tex); } @@ -66,10 +66,10 @@ 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, GrWrapCacheable::kYes, + tex = gpu->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType); REPORTER_ASSERT(reporter, !tex); - tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kYes, + tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType); REPORTER_ASSERT(reporter, !tex); } @@ -79,7 +79,7 @@ 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, GrWrapCacheable::kYes, + tex = gpu->wrapBackendTexture(backendTex, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType); REPORTER_ASSERT(reporter, tex); @@ -137,8 +137,8 @@ void wrap_trt_test(skiatest::Reporter* reporter, GrContext* context) { GrVkImageInfo imageInfo; SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo)); - sk_sp tex = - gpu->wrapRenderableBackendTexture(origBackendTex, 1, kBorrow_GrWrapOwnership); + sk_sp tex = gpu->wrapRenderableBackendTexture( + origBackendTex, 1, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo); REPORTER_ASSERT(reporter, tex); // image is null @@ -147,9 +147,11 @@ void wrap_trt_test(skiatest::Reporter* reporter, GrContext* context) { backendCopy.fImage = VK_NULL_HANDLE; GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); backendTex.setPixelConfig(kPixelConfig); - tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kBorrow_GrWrapOwnership); + tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kBorrow_GrWrapOwnership, + GrWrapCacheable::kNo); REPORTER_ASSERT(reporter, !tex); - tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership); + tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership, + GrWrapCacheable::kNo); REPORTER_ASSERT(reporter, !tex); } @@ -159,9 +161,11 @@ void wrap_trt_test(skiatest::Reporter* reporter, GrContext* context) { backendCopy.fAlloc = GrVkAlloc(); GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); backendTex.setPixelConfig(kPixelConfig); - tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kBorrow_GrWrapOwnership); + tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kBorrow_GrWrapOwnership, + GrWrapCacheable::kNo); REPORTER_ASSERT(reporter, !tex); - tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership); + tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership, + GrWrapCacheable::kNo); REPORTER_ASSERT(reporter, !tex); } @@ -170,7 +174,8 @@ void wrap_trt_test(skiatest::Reporter* reporter, GrContext* context) { GrVkImageInfo backendCopy = imageInfo; GrBackendTexture backendTex = GrBackendTexture(kW, kH, backendCopy); backendTex.setPixelConfig(kPixelConfig); - tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership); + tex = gpu->wrapRenderableBackendTexture(backendTex, 1, kAdopt_GrWrapOwnership, + GrWrapCacheable::kNo); REPORTER_ASSERT(reporter, tex); } } diff --git a/tools/gpu/ProxyUtils.cpp b/tools/gpu/ProxyUtils.cpp index a1f4df6cdb..c3fca8400b 100644 --- a/tools/gpu/ProxyUtils.cpp +++ b/tools/gpu/ProxyUtils.cpp @@ -33,10 +33,10 @@ sk_sp MakeTextureProxyFromData(GrContext* context, bool isRT, in // Adopt ownership so our caller doesn't have to worry about deleting the backend texture. if (isRT) { proxy = context->contextPriv().proxyProvider()->wrapRenderableBackendTexture( - backendTex, origin, 1, kAdopt_GrWrapOwnership); + backendTex, origin, 1, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo); } else { proxy = context->contextPriv().proxyProvider()->wrapBackendTexture( - backendTex, origin, kAdopt_GrWrapOwnership, kRW_GrIOType); + backendTex, origin, kAdopt_GrWrapOwnership, GrWrapCacheable::kNo, kRW_GrIOType); } if (!proxy) {