Make ManagedBackendTexture fail on invalid GrBackendTexture
Makes it more sensible.
A bunch of call sites we're already written to expect this. Update
some others.
Change-Id: I77c28045ebf01e6aa9d92d2ebc37287604ec10c9
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/332544
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/tests/GrMipMappedTest.cpp b/tests/GrMipMappedTest.cpp
index 104449c..35e038a 100644
--- a/tests/GrMipMappedTest.cpp
+++ b/tests/GrMipMappedTest.cpp
@@ -55,6 +55,10 @@
mipMapped,
renderable,
GrProtected::kNo);
+ if (!mbet) {
+ ERRORF(reporter, "Could not make texture.");
+ return;
+ }
sk_sp<GrTextureProxy> proxy;
sk_sp<SkImage> image;
diff --git a/tests/GrPorterDuffTest.cpp b/tests/GrPorterDuffTest.cpp
index c7f2a44..0adb595 100644
--- a/tests/GrPorterDuffTest.cpp
+++ b/tests/GrPorterDuffTest.cpp
@@ -1001,6 +1001,10 @@
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(
ctx, 100, 100, kRGBA_8888_SkColorType, GrMipmapped::kNo, GrRenderable::kNo);
+ if (!mbet) {
+ ERRORF(reporter, "Could not make texture.");
+ return;
+ }
GrXferProcessor::DstProxyView fakeDstProxyView;
{
sk_sp<GrTextureProxy> proxy = proxyProvider->wrapBackendTexture(
diff --git a/tests/GrSurfaceTest.cpp b/tests/GrSurfaceTest.cpp
index 49078e1..41ef478 100644
--- a/tests/GrSurfaceTest.cpp
+++ b/tests/GrSurfaceTest.cpp
@@ -361,6 +361,10 @@
for (auto ioType : {kRead_GrIOType, kRW_GrIOType}) {
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithData(
dContext, srcPixmap, GrRenderable::kNo, GrProtected::kNo);
+ if (!mbet) {
+ ERRORF(reporter, "Could not make texture.");
+ return;
+ }
auto proxy = proxyProvider->wrapBackendTexture(mbet->texture(), kBorrow_GrWrapOwnership,
GrWrapCacheable::kNo, ioType,
mbet->refCountedCallback());
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp
index a9b0482..a77bd47 100644
--- a/tests/ImageTest.cpp
+++ b/tests/ImageTest.cpp
@@ -489,12 +489,11 @@
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(
dContext, kSize, kSize, colorType, GrMipmapped::kNo, GrRenderable::kNo);
- if (!mbet) {
- ERRORF(reporter, "Could not create texture with color type %d.", colorType);
- continue;
+ sk_sp<SkImage> img;
+ if (mbet) {
+ img = SkImage::MakeFromTexture(dContext, mbet->texture(), kTopLeft_GrSurfaceOrigin,
+ colorType, kOpaque_SkAlphaType, nullptr);
}
- auto img = SkImage::MakeFromTexture(dContext, mbet->texture(), kTopLeft_GrSurfaceOrigin,
- colorType, kOpaque_SkAlphaType, nullptr);
REPORTER_ASSERT(reporter, can == SkToBool(img),
"colorTypeSupportedAsImage:%d, actual:%d, ct:%d", can, SkToBool(img),
colorType);
@@ -839,6 +838,7 @@
GrProtected::kNo);
if (!mbet) {
ERRORF(reporter, "couldn't create backend texture\n");
+ return;
}
TextureReleaseChecker releaseChecker;
diff --git a/tools/gpu/BackendTextureImageFactory.cpp b/tools/gpu/BackendTextureImageFactory.cpp
index e2950af..700f64f5 100644
--- a/tools/gpu/BackendTextureImageFactory.cpp
+++ b/tools/gpu/BackendTextureImageFactory.cpp
@@ -31,6 +31,9 @@
src = &temp;
}
auto mbet = ManagedBackendTexture::MakeWithData(dContext, src, 1, renderable, GrProtected::kNo);
+ if (!mbet) {
+ return nullptr;
+ }
return SkImage::MakeFromTexture(dContext,
mbet->texture(),
origin,
@@ -61,7 +64,9 @@
mipmapped,
renderable,
GrProtected::kNo);
-
+ if (!mbet) {
+ return nullptr;
+ }
return SkImage::MakeFromTexture(dContext,
mbet->texture(),
origin,
diff --git a/tools/gpu/ManagedBackendTexture.h b/tools/gpu/ManagedBackendTexture.h
index 7c65d54..602db34 100644
--- a/tools/gpu/ManagedBackendTexture.h
+++ b/tools/gpu/ManagedBackendTexture.h
@@ -98,6 +98,9 @@
mbet->fTexture = dContext->createBackendTexture(std::forward<Args>(args)...,
ReleaseProc,
mbet->releaseContext());
+ if (!mbet->fTexture.isValid()) {
+ return nullptr;
+ }
return mbet;
}
@@ -105,9 +108,14 @@
inline sk_sp<ManagedBackendTexture> ManagedBackendTexture::MakeWithoutData(
GrDirectContext* dContext,
Args&&... args) {
+ GrBackendTexture texture =
+ dContext->createBackendTexture(std::forward<Args>(args)...);
+ if (!texture.isValid()) {
+ return nullptr;
+ }
sk_sp<ManagedBackendTexture> mbet(new ManagedBackendTexture);
mbet->fDContext = sk_ref_sp(dContext);
- mbet->fTexture = dContext->createBackendTexture(std::forward<Args>(args)...);
+ mbet->fTexture = std::move(texture);
return mbet;
}