GMs: fail gracefully for null surface
authorscroggo <scroggo@chromium.org>
Fri, 13 May 2016 14:25:44 +0000 (07:25 -0700)
committerCommit bot <commit-bot@chromium.org>
Fri, 13 May 2016 14:25:44 +0000 (07:25 -0700)
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

gm/image.cpp
gm/image_pict.cpp

index a84e19b3f7758bc8c0017b183a37ca6b6b7b39aa..b57ec3a687e4b93c75ef3c27b2b97220945374e1 100644 (file)
@@ -258,6 +258,7 @@ static sk_sp<SkImage> make_codec(const SkImageInfo& info, GrContext*, void (*dra
 static sk_sp<SkImage> make_gpu(const SkImageInfo& info, GrContext* ctx, void (*draw)(SkCanvas*)) {
     if (!ctx) { return nullptr; }
     auto surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info));
+    if (!surface) { return nullptr; }
     draw(surface->getCanvas());
     return surface->makeImageSnapshot();
 }
index fd7ac2adb12089efffa2b6619a8c4b5ae6f8d6c4..9d1dc513a8cbd74eba522595d90cc5937f12a2a8 100644 (file)
@@ -212,11 +212,13 @@ public:
         , 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 @@ protected:
             SkASSERT(ctx == fCtx.get());
         }
 
+        if (!fTexture) {
+            return nullptr;
+        }
+
         if (!subset) {
             return SkRef(fTexture.get());
         }