GMs: fail gracefully for null surface
A couple more instances where MakeRenderTarget returns nullptr
due to --preAbandonGpuContext.
BUG=skia5282
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1976163002
Review-Url: https://codereview.chromium.org/1976163002
diff --git a/gm/image_pict.cpp b/gm/image_pict.cpp
index fd7ac2a..9d1dc51 100644
--- a/gm/image_pict.cpp
+++ b/gm/image_pict.cpp
@@ -212,11 +212,13 @@
, fCtx(SkRef(ctx))
{
auto surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info));
- surface->getCanvas()->clear(0);
- surface->getCanvas()->translate(-100, -100);
- surface->getCanvas()->drawPicture(pic);
- sk_sp<SkImage> image(surface->makeImageSnapshot());
- fTexture.reset(SkRef(as_IB(image)->peekTexture()));
+ if (surface) {
+ surface->getCanvas()->clear(0);
+ surface->getCanvas()->translate(-100, -100);
+ surface->getCanvas()->drawPicture(pic);
+ sk_sp<SkImage> image(surface->makeImageSnapshot());
+ fTexture.reset(SkRef(as_IB(image)->peekTexture()));
+ }
}
protected:
GrTexture* onGenerateTexture(GrContext* ctx, const SkIRect* subset) override {
@@ -224,6 +226,10 @@
SkASSERT(ctx == fCtx.get());
}
+ if (!fTexture) {
+ return nullptr;
+ }
+
if (!subset) {
return SkRef(fTexture.get());
}