Always create an approx-size texture for approx-fit proxies
Bug: chromium:1003415
Change-Id: I699a22aaca36b6ec9f78076732eb810a90154337
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/241356
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
Auto-Submit: Michael Ludwig <michaelludwig@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp
index 29a616f..6d6352f 100644
--- a/src/gpu/GrResourceProvider.cpp
+++ b/src/gpu/GrResourceProvider.cpp
@@ -281,26 +281,17 @@
return nullptr;
}
- if (auto tex = this->refScratchTexture(desc, format, renderable, renderTargetSampleCnt,
- isProtected)) {
- return tex;
- }
-
- SkTCopyOnFirstWrite<GrSurfaceDesc> copyDesc(desc);
-
// bin by some multiple or power of 2 with a reasonable min
- if (fGpu->caps()->reuseScratchTextures() || renderable == GrRenderable::kYes) {
- GrSurfaceDesc* wdesc = copyDesc.writable();
- wdesc->fWidth = MakeApprox(wdesc->fWidth);
- wdesc->fHeight = MakeApprox(wdesc->fHeight);
- }
+ GrSurfaceDesc copyDesc(desc);
+ copyDesc.fWidth = MakeApprox(desc.fWidth);
+ copyDesc.fHeight = MakeApprox(desc.fHeight);
- if (auto tex = this->refScratchTexture(*copyDesc, format, renderable, renderTargetSampleCnt,
+ if (auto tex = this->refScratchTexture(copyDesc, format, renderable, renderTargetSampleCnt,
isProtected)) {
return tex;
}
- return fGpu->createTexture(*copyDesc, format, renderable, renderTargetSampleCnt,
+ return fGpu->createTexture(copyDesc, format, renderable, renderTargetSampleCnt,
SkBudgeted::kYes, isProtected);
}
diff --git a/tests/ProxyTest.cpp b/tests/ProxyTest.cpp
index f209ed3..80e77c6 100644
--- a/tests/ProxyTest.cpp
+++ b/tests/ProxyTest.cpp
@@ -83,6 +83,17 @@
GrSurfaceProxy::UniqueID idBefore = texProxy->uniqueID();
bool preinstantiated = texProxy->isInstantiated();
+ // The instantiated texture should have these dimensions. If the fit is kExact, then
+ // 'worst-case' reports the original WxH. If it is kApprox, make sure that the texture
+ // is that size and didn't reuse one of the kExact surfaces in the provider. This is important
+ // because upstream usage (e.g. SkImage) reports size based on the worst case dimensions and
+ // client code may rely on that if they are creating backend resources.
+ // NOTE: we store these before instantiating, since after instantiation worstCaseWH() just
+ // return the target's dimensions. In this instance, we want to ensure the target's dimensions
+ // are no different from the original approximate (or exact) dimensions.
+ int expectedWidth = texProxy->worstCaseWidth();
+ int expectedHeight = texProxy->worstCaseHeight();
+
REPORTER_ASSERT(reporter, texProxy->instantiate(provider));
GrTexture* tex = texProxy->peekTexture();
@@ -94,13 +105,9 @@
REPORTER_ASSERT(reporter, texProxy->uniqueID().asUInt() != tex->uniqueID().asUInt());
}
- if (SkBackingFit::kExact == fit) {
- REPORTER_ASSERT(reporter, tex->width() == texProxy->width());
- REPORTER_ASSERT(reporter, tex->height() == texProxy->height());
- } else {
- REPORTER_ASSERT(reporter, tex->width() >= texProxy->width());
- REPORTER_ASSERT(reporter, tex->height() >= texProxy->height());
- }
+ REPORTER_ASSERT(reporter, tex->width() == expectedWidth);
+ REPORTER_ASSERT(reporter, tex->height() == expectedHeight);
+
REPORTER_ASSERT(reporter, tex->config() == texProxy->config());
}