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();
}
, 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 {
SkASSERT(ctx == fCtx.get());
}
+ if (!fTexture) {
+ return nullptr;
+ }
+
if (!subset) {
return SkRef(fTexture.get());
}