Require explicit GrWrapCacheable specification in more places.
Make all wrapped resources be kUnbudgetedUncacheable except those
created by AHardwareBuffer image generators and as backings for promise
images.
Make all non-wrapped unbudgeted resources be kUnbudgetedUncacheable.
Update unit tests to mostly use GrWrapCacheable::kNo except where they
are testing the distinction.
Update unit tests for new expectations.
Bug: chromium:922851
Change-Id: I4d3bdaa161ffc76390f26334bcb7e2b47dd9319d
Reviewed-on: https://skia-review.googlesource.com/c/185004
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/include/gpu/GrGpuResource.h b/include/gpu/GrGpuResource.h
index d205495..4ea206f 100644
--- a/include/gpu/GrGpuResource.h
+++ b/include/gpu/GrGpuResource.h
@@ -264,7 +264,7 @@
// 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 @@
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 6ed48fb..55eab91 100644
--- a/src/gpu/GrAHardwareBufferImageGenerator.cpp
+++ b/src/gpu/GrAHardwareBufferImageGenerator.cpp
@@ -600,8 +600,11 @@
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<GrTexture> tex = resourceProvider->wrapBackendTexture(
- backendTex, kBorrow_GrWrapOwnership, kRead_GrIOType);
+ backendTex, kBorrow_GrWrapOwnership, GrWrapCacheable::kYes, kRead_GrIOType);
if (!tex) {
deleteImageProc(deleteImageCtx);
return sk_sp<GrTexture>();
diff --git a/src/gpu/GrBackendTextureImageGenerator.cpp b/src/gpu/GrBackendTextureImageGenerator.cpp
index 291f013..674ca05 100644
--- a/src/gpu/GrBackendTextureImageGenerator.cpp
+++ b/src/gpu/GrBackendTextureImageGenerator.cpp
@@ -169,8 +169,8 @@
// 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<GrTexture>();
}
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index b0ff64b..449fe60 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -947,7 +947,7 @@
ASSERT_SINGLE_OWNER_PRIV
sk_sp<GrSurfaceProxy> 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 @@
ASSERT_SINGLE_OWNER_PRIV
SkASSERT(sampleCnt > 0);
- sk_sp<GrTextureProxy> proxy(
- this->proxyProvider()->wrapRenderableBackendTexture(tex, origin, sampleCnt));
+ sk_sp<GrTextureProxy> 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 d291c04..260ba29 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -164,7 +164,8 @@
}
sk_sp<GrTexture> 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 @@
backendTex.height() > this->caps()->maxRenderTargetSize()) {
return nullptr;
}
- sk_sp<GrTexture> tex = this->onWrapRenderableBackendTexture(backendTex, sampleCnt, ownership);
+ sk_sp<GrTexture> 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 34e21c4..04a34f7 100644
--- a/src/gpu/GrGpu.h
+++ b/src/gpu/GrGpu.h
@@ -110,8 +110,8 @@
/**
* Implements GrResourceProvider::wrapRenderableBackendTexture
*/
- sk_sp<GrTexture> wrapRenderableBackendTexture(const GrBackendTexture&,
- int sampleCnt, GrWrapOwnership);
+ sk_sp<GrTexture> wrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt,
+ GrWrapOwnership, GrWrapCacheable);
/**
* Implements GrResourceProvider::wrapBackendRenderTarget
@@ -459,9 +459,8 @@
virtual sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership,
GrWrapCacheable, GrIOType) = 0;
- virtual sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
- int sampleCnt,
- GrWrapOwnership) = 0;
+ virtual sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt,
+ GrWrapOwnership, GrWrapCacheable) = 0;
virtual sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) = 0;
virtual sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
int sampleCnt) = 0;
diff --git a/src/gpu/GrGpuResource.cpp b/src/gpu/GrGpuResource.cpp
index b3d3b1d..c9224be 100644
--- a/src/gpu/GrGpuResource.cpp
+++ b/src/gpu/GrGpuResource.cpp
@@ -26,15 +26,15 @@
}
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::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::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 978da53..f13cf7c 100644
--- a/src/gpu/GrProxyProvider.cpp
+++ b/src/gpu/GrProxyProvider.cpp
@@ -451,6 +451,7 @@
sk_sp<GrTextureProxy> GrProxyProvider::wrapBackendTexture(const GrBackendTexture& backendTex,
GrSurfaceOrigin origin,
GrWrapOwnership ownership,
+ GrWrapCacheable cacheable,
GrIOType ioType,
ReleaseProc releaseProc,
ReleaseContext releaseCtx) {
@@ -464,8 +465,8 @@
return nullptr;
}
- sk_sp<GrTexture> tex = fResourceProvider->wrapBackendTexture(backendTex, ownership, ioType,
- GrWrapCacheable::kYes);
+ sk_sp<GrTexture> tex =
+ fResourceProvider->wrapBackendTexture(backendTex, ownership, cacheable, ioType);
if (!tex) {
return nullptr;
}
@@ -486,7 +487,7 @@
sk_sp<GrTextureProxy> GrProxyProvider::wrapRenderableBackendTexture(
const GrBackendTexture& backendTex, GrSurfaceOrigin origin, int sampleCnt,
- GrWrapOwnership ownership) {
+ GrWrapOwnership ownership, GrWrapCacheable cacheable) {
if (this->isAbandoned()) {
return nullptr;
}
@@ -501,8 +502,8 @@
return nullptr;
}
- sk_sp<GrTexture> tex =
- fResourceProvider->wrapRenderableBackendTexture(backendTex, sampleCnt, ownership);
+ sk_sp<GrTexture> tex = fResourceProvider->wrapRenderableBackendTexture(backendTex, sampleCnt,
+ ownership, cacheable);
if (!tex) {
return nullptr;
}
diff --git a/src/gpu/GrProxyProvider.h b/src/gpu/GrProxyProvider.h
index 1abb49f..f84cdfc 100644
--- a/src/gpu/GrProxyProvider.h
+++ b/src/gpu/GrProxyProvider.h
@@ -113,16 +113,15 @@
* kRead or kRW.
*/
sk_sp<GrTextureProxy> 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<GrTextureProxy> wrapRenderableBackendTexture(const GrBackendTexture&,
- GrSurfaceOrigin,
- int sampleCnt,
- GrWrapOwnership = kBorrow_GrWrapOwnership);
+ sk_sp<GrTextureProxy> 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 c996494..3e7d2c7 100644
--- a/src/gpu/GrResourceProvider.cpp
+++ b/src/gpu/GrResourceProvider.cpp
@@ -235,8 +235,8 @@
sk_sp<GrTexture> 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<GrTexture> 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<GrRenderTarget> GrResourceProvider::wrapBackendRenderTarget(
diff --git a/src/gpu/GrResourceProvider.h b/src/gpu/GrResourceProvider.h
index 8364049..37d094c 100644
--- a/src/gpu/GrResourceProvider.h
+++ b/src/gpu/GrResourceProvider.h
@@ -106,10 +106,8 @@
*
* @return GrTexture object or NULL on failure.
*/
- sk_sp<GrTexture> wrapBackendTexture(const GrBackendTexture& tex,
- GrWrapOwnership /* = kBorrow_GrWrapOwnership*/,
- GrIOType,
- GrWrapCacheable = GrWrapCacheable::kYes);
+ sk_sp<GrTexture> 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 @@
*/
sk_sp<GrTexture> 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 5cca23a..34b27d2 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -687,7 +687,8 @@
sk_sp<GrTexture> 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 @@
GrMipMapsStatus mipMapsStatus = backendTex.hasMipMaps() ? GrMipMapsStatus::kDirty
: GrMipMapsStatus::kNotAllocated;
- sk_sp<GrGLTextureRenderTarget> texRT(
- GrGLTextureRenderTarget::MakeWrapped(this, surfDesc, idDesc, rtIDDesc, mipMapsStatus));
+ sk_sp<GrGLTextureRenderTarget> 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 1987a28..e9c840d 100644
--- a/src/gpu/gl/GrGLGpu.h
+++ b/src/gpu/gl/GrGLGpu.h
@@ -191,9 +191,8 @@
sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrWrapCacheable,
GrIOType) override;
- sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
- int sampleCnt,
- GrWrapOwnership) override;
+ sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt,
+ GrWrapOwnership, GrWrapCacheable) override;
sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
int sampleCnt) override;
diff --git a/src/gpu/gl/GrGLRenderTarget.cpp b/src/gpu/gl/GrGLRenderTarget.cpp
index 5e0a2fb..f2913f3 100644
--- a/src/gpu/gl/GrGLRenderTarget.cpp
+++ b/src/gpu/gl/GrGLRenderTarget.cpp
@@ -28,7 +28,7 @@
, 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 b557efb..d594dc8 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 04f8ffc..17dc562 100644
--- a/src/gpu/gl/GrGLTextureRenderTarget.cpp
+++ b/src/gpu/gl/GrGLTextureRenderTarget.cpp
@@ -28,11 +28,12 @@
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 @@
}
sk_sp<GrGLTextureRenderTarget> 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<GrGLTextureRenderTarget>(
- 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 f33ff28..ffb5643 100644
--- a/src/gpu/gl/GrGLTextureRenderTarget.h
+++ b/src/gpu/gl/GrGLTextureRenderTarget.h
@@ -38,7 +38,7 @@
static sk_sp<GrGLTextureRenderTarget> 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 @@
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 a2955f5..8ac7684 100644
--- a/src/gpu/mock/GrMockGpu.cpp
+++ b/src/gpu/mock/GrMockGpu.cpp
@@ -125,7 +125,8 @@
sk_sp<GrTexture> 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 @@
rtInfo.fID = NextInternalRenderTargetID();
return sk_sp<GrTexture>(
- new GrMockTextureRenderTarget(this, desc, mipMapsStatus, texInfo, rtInfo));
+ new GrMockTextureRenderTarget(this, desc, mipMapsStatus, texInfo, rtInfo, cacheable));
}
sk_sp<GrRenderTarget> GrMockGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& rt) {
diff --git a/src/gpu/mock/GrMockGpu.h b/src/gpu/mock/GrMockGpu.h
index 77090ea..2a79eb0 100644
--- a/src/gpu/mock/GrMockGpu.h
+++ b/src/gpu/mock/GrMockGpu.h
@@ -64,7 +64,8 @@
sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
int sampleCnt,
- GrWrapOwnership) override;
+ GrWrapOwnership,
+ GrWrapCacheable) override;
sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
diff --git a/src/gpu/mock/GrMockTexture.h b/src/gpu/mock/GrMockTexture.h
index e9e35af..26741be 100644
--- a/src/gpu/mock/GrMockTexture.h
+++ b/src/gpu/mock/GrMockTexture.h
@@ -112,7 +112,7 @@
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 @@
// 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 bab666c..8ab60b7 100644
--- a/src/gpu/mtl/GrMtlGpu.h
+++ b/src/gpu/mtl/GrMtlGpu.h
@@ -135,9 +135,8 @@
sk_sp<GrTexture> onWrapBackendTexture(const GrBackendTexture&, GrWrapOwnership, GrWrapCacheable,
GrIOType) override;
- sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
- int sampleCnt,
- GrWrapOwnership) override;
+ sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&, int sampleCnt,
+ GrWrapOwnership, GrWrapCacheable) override;
sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
diff --git a/src/gpu/mtl/GrMtlGpu.mm b/src/gpu/mtl/GrMtlGpu.mm
index a74ac52..c0273e4 100644
--- a/src/gpu/mtl/GrMtlGpu.mm
+++ b/src/gpu/mtl/GrMtlGpu.mm
@@ -357,7 +357,8 @@
sk_sp<GrTexture> GrMtlGpu::onWrapRenderableBackendTexture(const GrBackendTexture& backendTex,
int sampleCnt,
- GrWrapOwnership ownership) {
+ GrWrapOwnership ownership,
+ GrWrapCacheable cacheable) {
id<MTLTexture> mtlTexture = get_texture_from_backend(backendTex, ownership);
if (!mtlTexture) {
return nullptr;
@@ -370,7 +371,8 @@
return nullptr;
}
- return GrMtlTextureRenderTarget::MakeWrappedTextureRenderTarget(this, surfDesc, mtlTexture);
+ return GrMtlTextureRenderTarget::MakeWrappedTextureRenderTarget(this, surfDesc, mtlTexture,
+ cacheable);
}
sk_sp<GrRenderTarget> GrMtlGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& backendRT) {
diff --git a/src/gpu/mtl/GrMtlRenderTarget.h b/src/gpu/mtl/GrMtlRenderTarget.h
index 98fa8e0..199532c 100644
--- a/src/gpu/mtl/GrMtlRenderTarget.h
+++ b/src/gpu/mtl/GrMtlRenderTarget.h
@@ -48,11 +48,6 @@
protected:
GrMtlRenderTarget(GrMtlGpu* gpu,
const GrSurfaceDesc& desc,
- id<MTLTexture> renderTexture,
- id<MTLTexture> resolveTexture);
-
- GrMtlRenderTarget(GrMtlGpu* gpu,
- const GrSurfaceDesc& desc,
id<MTLTexture> renderTexture);
GrMtlGpu* getMtlGpu() const;
@@ -77,22 +72,12 @@
id<MTLTexture> fResolveTexture;
private:
+ // Extra param to disambiguate from constructor used by subclasses.
+ enum Wrapped { kWrapped };
GrMtlRenderTarget(GrMtlGpu* gpu,
- SkBudgeted,
const GrSurfaceDesc& desc,
id<MTLTexture> renderTexture,
- id<MTLTexture> resolveTexture);
-
- GrMtlRenderTarget(GrMtlGpu* gpu,
- SkBudgeted,
- const GrSurfaceDesc& desc,
- id<MTLTexture> renderTexture);
-
- static sk_sp<GrMtlRenderTarget> Make(GrMtlGpu*,
- SkBudgeted,
- const GrSurfaceDesc&,
- id<MTLTexture> renderTexture,
- bool isWrapped);
+ Wrapped);
bool completeStencilAttachment() override;
};
diff --git a/src/gpu/mtl/GrMtlRenderTarget.mm b/src/gpu/mtl/GrMtlRenderTarget.mm
index 59fd479..07e5639 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<MTLTexture> renderTexture)
+ id<MTLTexture> 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<MTLTexture> renderTexture)
@@ -38,8 +40,7 @@
SkASSERT(nil != renderTexture);
SkASSERT(1 == renderTexture.mipmapLevelCount);
SkASSERT(MTLTextureUsageRenderTarget & renderTexture.usage);
- return sk_sp<GrMtlRenderTarget>(new GrMtlRenderTarget(gpu, SkBudgeted::kNo,
- desc, renderTexture));
+ return sk_sp<GrMtlRenderTarget>(new GrMtlRenderTarget(gpu, desc, renderTexture, kWrapped));
}
GrMtlRenderTarget::~GrMtlRenderTarget() {
@@ -47,7 +48,6 @@
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 412af7b..50a4e8e 100644
--- a/src/gpu/mtl/GrMtlTextureRenderTarget.h
+++ b/src/gpu/mtl/GrMtlTextureRenderTarget.h
@@ -21,7 +21,8 @@
static sk_sp<GrMtlTextureRenderTarget> MakeWrappedTextureRenderTarget(GrMtlGpu*,
const GrSurfaceDesc&,
- id<MTLTexture>);
+ id<MTLTexture>,
+ GrWrapCacheable);
GrBackendFormat backendFormat() const override {
return GrMtlTexture::backendFormat();
}
@@ -60,14 +61,8 @@
GrMtlTextureRenderTarget(GrMtlGpu* gpu,
const GrSurfaceDesc& desc,
id<MTLTexture> renderTexture,
- GrMipMapsStatus);
-
- static sk_sp<GrMtlTextureRenderTarget> Make(GrMtlGpu*,
- const GrSurfaceDesc&,
- id<MTLTexture> 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 62fd2ab..7bd53e1 100644
--- a/src/gpu/mtl/GrMtlTextureRenderTarget.mm
+++ b/src/gpu/mtl/GrMtlTextureRenderTarget.mm
@@ -23,58 +23,43 @@
GrMtlTextureRenderTarget::GrMtlTextureRenderTarget(GrMtlGpu* gpu,
const GrSurfaceDesc& desc,
id<MTLTexture> 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>
-GrMtlTextureRenderTarget::Make(GrMtlGpu* gpu,
- const GrSurfaceDesc& desc,
- id<MTLTexture> 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<GrMtlTextureRenderTarget>(new GrMtlTextureRenderTarget(gpu,
- budgeted,
- desc,
- renderTexture,
- mipMapsStatus));
- } else {
- return sk_sp<GrMtlTextureRenderTarget>(new GrMtlTextureRenderTarget(gpu,
- desc,
- renderTexture,
- mipMapsStatus));
- }
-}
-
-
-sk_sp<GrMtlTextureRenderTarget>
GrMtlTextureRenderTarget::CreateNewTextureRenderTarget(GrMtlGpu* gpu,
SkBudgeted budgeted,
const GrSurfaceDesc& desc,
MTLTextureDescriptor* texDesc,
GrMipMapsStatus mipMapsStatus) {
- id<MTLTexture> texture = [gpu->device() newTextureWithDescriptor:texDesc];
- return Make(gpu, desc, texture, mipMapsStatus, budgeted, false);
+ id<MTLTexture> renderTexture = [gpu->device() newTextureWithDescriptor:texDesc];
+ SkASSERT(nil != renderTexture);
+ if (desc.fSampleCnt > 1) {
+ return nullptr;
+ }
+ SkASSERT((MTLTextureUsageShaderRead | MTLTextureUsageRenderTarget) & renderTexture.usage);
+ return sk_sp<GrMtlTextureRenderTarget>(
+ new GrMtlTextureRenderTarget(gpu, budgeted, desc, renderTexture, mipMapsStatus));
}
-sk_sp<GrMtlTextureRenderTarget>
-GrMtlTextureRenderTarget::MakeWrappedTextureRenderTarget(GrMtlGpu* gpu,
- const GrSurfaceDesc& desc,
- id<MTLTexture> 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> GrMtlTextureRenderTarget::MakeWrappedTextureRenderTarget(
+ GrMtlGpu* gpu,
+ const GrSurfaceDesc& desc,
+ id<MTLTexture> 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<GrMtlTextureRenderTarget>(
+ new GrMtlTextureRenderTarget(gpu, desc, renderTexture, mipMapsStatus, cacheable));
}
-
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index b85d603..142c1c7 100644
--- a/src/gpu/vk/GrVkGpu.cpp
+++ b/src/gpu/vk/GrVkGpu.cpp
@@ -1048,7 +1048,8 @@
sk_sp<GrTexture> 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<GrVkImageLayout> 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<GrRenderTarget> GrVkGpu::onWrapBackendRenderTarget(const GrBackendRenderTarget& backendRT){
diff --git a/src/gpu/vk/GrVkGpu.h b/src/gpu/vk/GrVkGpu.h
index 8200b6f..671549e 100644
--- a/src/gpu/vk/GrVkGpu.h
+++ b/src/gpu/vk/GrVkGpu.h
@@ -188,7 +188,8 @@
GrIOType) override;
sk_sp<GrTexture> onWrapRenderableBackendTexture(const GrBackendTexture&,
int sampleCnt,
- GrWrapOwnership) override;
+ GrWrapOwnership,
+ GrWrapCacheable) override;
sk_sp<GrRenderTarget> onWrapBackendRenderTarget(const GrBackendRenderTarget&) override;
sk_sp<GrRenderTarget> onWrapBackendTextureAsRenderTarget(const GrBackendTexture&,
diff --git a/src/gpu/vk/GrVkRenderTarget.cpp b/src/gpu/vk/GrVkRenderTarget.cpp
index 36dcb60..ab61150 100644
--- a/src/gpu/vk/GrVkRenderTarget.cpp
+++ b/src/gpu/vk/GrVkRenderTarget.cpp
@@ -42,7 +42,7 @@
, 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 @@
, 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 @@
, fFramebuffer(nullptr)
, fCachedSimpleRenderPass(renderPass)
, fSecondaryCommandBuffer(secondaryCommandBuffer) {
- this->registerWithCacheWrapped();
+ this->registerWithCacheWrapped(GrWrapCacheable::kNo);
}
sk_sp<GrVkRenderTarget> GrVkRenderTarget::MakeWrappedRenderTarget(
diff --git a/src/gpu/vk/GrVkSemaphore.cpp b/src/gpu/vk/GrVkSemaphore.cpp
index 8491782..dde435f 100644
--- a/src/gpu/vk/GrVkSemaphore.cpp
+++ b/src/gpu/vk/GrVkSemaphore.cpp
@@ -46,7 +46,8 @@
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 3656c82..234c4d1 100644
--- a/src/gpu/vk/GrVkTextureRenderTarget.cpp
+++ b/src/gpu/vk/GrVkTextureRenderTarget.cpp
@@ -28,11 +28,11 @@
sk_sp<GrVkImageLayout> 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 @@
sk_sp<GrVkImageLayout> 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 @@
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 @@
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> GrVkTextureRenderTarget::Make(GrVkGpu* gpu,
- const GrSurfaceDesc& desc,
- const GrVkImageInfo& info,
- sk_sp<GrVkImageLayout> 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<GrVkImageLayout> 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 @@
VkImage colorImage;
// create msaa surface if necessary
- GrVkImageInfo msInfo;
- sk_sp<GrVkImageLayout> msLayout;
- const GrVkImageView* resolveAttachmentView = nullptr;
if (desc.fSampleCnt > 1) {
GrVkImage::ImageDesc msImageDesc;
msImageDesc.fImageType = VK_IMAGE_TYPE_2D;
@@ -130,74 +132,40 @@
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<GrVkTextureRenderTarget> texRT;
- if (desc.fSampleCnt > 1) {
- if (!isWrapped) {
- texRT = sk_sp<GrVkTextureRenderTarget>(new GrVkTextureRenderTarget(
- gpu, budgeted, desc,
- info, std::move(layout), imageView, msInfo,
- std::move(msLayout), colorAttachmentView,
- resolveAttachmentView, mipMapsStatus,
- ownership));
- } else {
- texRT = sk_sp<GrVkTextureRenderTarget>(new GrVkTextureRenderTarget(
- gpu, desc,
- info, std::move(layout), imageView, msInfo,
- std::move(msLayout), colorAttachmentView,
- resolveAttachmentView, mipMapsStatus,
- ownership));
- }
- } else {
- if (!isWrapped) {
- texRT = sk_sp<GrVkTextureRenderTarget>(new GrVkTextureRenderTarget(
- gpu, budgeted, desc,
- info, std::move(layout), imageView,
- colorAttachmentView, mipMapsStatus,
- ownership));
- } else {
- texRT = sk_sp<GrVkTextureRenderTarget>(new GrVkTextureRenderTarget(
- gpu, desc,
- info, std::move(layout), imageView,
- colorAttachmentView, mipMapsStatus,
- ownership));
- }
- }
- return texRT;
+ return views;
}
sk_sp<GrVkTextureRenderTarget>
@@ -215,21 +183,30 @@
}
sk_sp<GrVkImageLayout> layout(new GrVkImageLayout(info.fImageLayout));
- sk_sp<GrVkTextureRenderTarget> 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;
}
-
- return trt;
+ if (desc.fSampleCnt > 1) {
+ return sk_sp<GrVkTextureRenderTarget>(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<GrVkTextureRenderTarget>(new GrVkTextureRenderTarget(
+ gpu, budgeted, desc, info, std::move(layout), views.imageView,
+ views.colorAttachmentView, mipMapsStatus));
+ }
}
-sk_sp<GrVkTextureRenderTarget>
-GrVkTextureRenderTarget::MakeWrappedTextureRenderTarget(GrVkGpu* gpu,
- const GrSurfaceDesc& desc,
- GrWrapOwnership wrapOwnership,
- const GrVkImageInfo& info,
- sk_sp<GrVkImageLayout> layout) {
+sk_sp<GrVkTextureRenderTarget> GrVkTextureRenderTarget::MakeWrappedTextureRenderTarget(
+ GrVkGpu* gpu,
+ const GrSurfaceDesc& desc,
+ GrWrapOwnership wrapOwnership,
+ GrWrapCacheable cacheable,
+ const GrVkImageInfo& info,
+ sk_sp<GrVkImageLayout> 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 @@
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;
}
-
- this->createFramebuffer(gpu);
- return true;
+ if (desc.fSampleCnt > 1) {
+ return sk_sp<GrVkTextureRenderTarget>(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<GrVkTextureRenderTarget>(new GrVkTextureRenderTarget(
+ gpu, desc, info, std::move(layout), views.imageView, views.colorAttachmentView,
+ mipMapsStatus, ownership, cacheable));
+ }
}
size_t GrVkTextureRenderTarget::onGpuMemorySize() const {
diff --git a/src/gpu/vk/GrVkTextureRenderTarget.h b/src/gpu/vk/GrVkTextureRenderTarget.h
index 5026213..1538287 100644
--- a/src/gpu/vk/GrVkTextureRenderTarget.h
+++ b/src/gpu/vk/GrVkTextureRenderTarget.h
@@ -34,11 +34,10 @@
static sk_sp<GrVkTextureRenderTarget> MakeWrappedTextureRenderTarget(GrVkGpu*,
const GrSurfaceDesc&,
GrWrapOwnership,
+ GrWrapCacheable,
const GrVkImageInfo&,
sk_sp<GrVkImageLayout>);
- bool updateForMipmap(GrVkGpu* gpu, const GrVkImageInfo& newInfo);
-
GrBackendFormat backendFormat() const override { return this->getBackendFormat(); }
protected:
@@ -53,6 +52,7 @@
}
private:
+ // MSAA, not-wrapped
GrVkTextureRenderTarget(GrVkGpu* gpu,
SkBudgeted budgeted,
const GrSurfaceDesc& desc,
@@ -63,9 +63,9 @@
sk_sp<GrVkImageLayout> 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 @@
sk_sp<GrVkImageLayout> 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 @@
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 @@
const GrVkImageView* texView,
const GrVkImageView* colorAttachmentView,
GrMipMapsStatus,
- GrBackendObjectOwnership);
-
- static sk_sp<GrVkTextureRenderTarget> Make(GrVkGpu*,
- const GrSurfaceDesc&,
- const GrVkImageInfo&,
- sk_sp<GrVkImageLayout>,
- 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 a2a203e..96dd841 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -113,8 +113,9 @@
}
GrProxyProvider* proxyProvider = ctx->contextPriv().proxyProvider();
- sk_sp<GrTextureProxy> proxy = proxyProvider->wrapBackendTexture(
- backendTex, origin, ownership, kRead_GrIOType, releaseProc, releaseCtx);
+ sk_sp<GrTextureProxy> 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 0e74923..3308082 100644
--- a/src/image/SkImage_GpuBase.cpp
+++ b/src/image/SkImage_GpuBase.cpp
@@ -292,9 +292,9 @@
}
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 @@
}
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 6005be5..6873fe8 100644
--- a/tests/GrPorterDuffTest.cpp
+++ b/tests/GrPorterDuffTest.cpp
@@ -997,7 +997,8 @@
GrXferProcessor::DstProxy fakeDstProxy;
{
sk_sp<GrTextureProxy> 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 752533b..89917d6 100644
--- a/tests/GrSurfaceTest.cpp
+++ b/tests/GrSurfaceTest.cpp
@@ -53,8 +53,8 @@
GrBackendTexture backendTex = gpu->createTestingOnlyBackendTexture(
nullptr, 256, 256, GrColorType::kRGBA_8888, false, GrMipMapped::kNo);
- sk_sp<GrSurface> texRT2 =
- resourceProvider->wrapRenderableBackendTexture(backendTex, 1, kBorrow_GrWrapOwnership);
+ sk_sp<GrSurface> 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 @@
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 @@
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 @@
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 @@
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 5709e26..5b272c9 100644
--- a/tests/GrTestingBackendTextureUploadTest.cpp
+++ b/tests/GrTestingBackendTextureUploadTest.cpp
@@ -47,11 +47,11 @@
sk_sp<GrTexture> 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 479d2cb..ecc639c 100644
--- a/tests/LazyProxyTest.cpp
+++ b/tests/LazyProxyTest.cpp
@@ -468,7 +468,7 @@
sk_sp<GrTexture> texture =
rp->wrapBackendTexture(backendTex, kBorrow_GrWrapOwnership,
- kRead_GrIOType, GrWrapCacheable::kYes);
+ GrWrapCacheable::kNo, kRead_GrIOType);
if (!texture) {
return sk_sp<GrTexture>();
}
diff --git a/tests/ProxyTest.cpp b/tests/ProxyTest.cpp
index 02b483e..7419fee 100644
--- a/tests/ProxyTest.cpp
+++ b/tests/ProxyTest.cpp
@@ -297,7 +297,8 @@
true, GrMipMapped::kNo);
sk_sp<GrSurfaceProxy> 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 @@
false, GrMipMapped::kNo);
sk_sp<GrSurfaceProxy> 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 dc1d3b7..7ca72fc 100644
--- a/tests/RectangleTextureTest.cpp
+++ b/tests/RectangleTextureTest.cpp
@@ -136,7 +136,7 @@
}
sk_sp<GrTextureProxy> 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 ab24b00..f711691 100644
--- a/tests/ResourceAllocatorTest.cpp
+++ b/tests/ResourceAllocatorTest.cpp
@@ -70,7 +70,7 @@
}
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 96a0b2f..532cb66 100644
--- a/tests/ResourceCacheTest.cpp
+++ b/tests/ResourceCacheTest.cpp
@@ -223,10 +223,10 @@
context->resetContext();
sk_sp<GrTexture> borrowed(resourceProvider->wrapBackendTexture(
- backendTextures[0], kBorrow_GrWrapOwnership, kRead_GrIOType));
+ backendTextures[0], kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, kRead_GrIOType));
sk_sp<GrTexture> 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 @@
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 @@
}
// 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 @@
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 @@
// 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 @@
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 @@
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 @@
// 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 @@
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<GrGpuResourceFreedMessage>::Post(msg);
+ GrGpuResourceFreedMessage msg1{wrapped1, context->uniqueID()};
+ SkMessageBus<GrGpuResourceFreedMessage>::Post(msg1);
+ cache->purgeAsNeeded();
+
+ REPORTER_ASSERT(reporter, 2 == TestResource::NumAlive());
+
+ GrGpuResourceFreedMessage msg2{wrapped3, context->uniqueID()};
+ SkMessageBus<GrGpuResourceFreedMessage>::Post(msg2);
cache->purgeAsNeeded();
REPORTER_ASSERT(reporter, 1 == TestResource::NumAlive());
diff --git a/tests/TextureProxyTest.cpp b/tests/TextureProxyTest.cpp
index 5260a0e..2c1847f 100644
--- a/tests/TextureProxyTest.cpp
+++ b/tests/TextureProxyTest.cpp
@@ -113,7 +113,8 @@
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 59f7b0f..0a53249 100644
--- a/tests/TraceMemoryDumpTest.cpp
+++ b/tests/TraceMemoryDumpTest.cpp
@@ -128,7 +128,7 @@
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 84fdc25..a10efb2 100644
--- a/tests/VkWrapTests.cpp
+++ b/tests/VkWrapTests.cpp
@@ -43,7 +43,7 @@
SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo));
sk_sp<GrTexture> 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 @@
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 @@
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 @@
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 @@
GrVkImageInfo imageInfo;
SkAssertResult(origBackendTex.getVkImageInfo(&imageInfo));
- sk_sp<GrTexture> tex =
- gpu->wrapRenderableBackendTexture(origBackendTex, 1, kBorrow_GrWrapOwnership);
+ sk_sp<GrTexture> tex = gpu->wrapRenderableBackendTexture(
+ origBackendTex, 1, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo);
REPORTER_ASSERT(reporter, tex);
// image is null
@@ -147,9 +147,11 @@
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 @@
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 @@
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 a1f4df6..c3fca84 100644
--- a/tools/gpu/ProxyUtils.cpp
+++ b/tools/gpu/ProxyUtils.cpp
@@ -33,10 +33,10 @@
// 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) {