Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: gm/image_pict.cpp

Issue 1976163002: GMs: fail gracefully for null surface (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix another GM Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « gm/image.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "gm.h" 8 #include "gm.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkImage.h" 10 #include "SkImage.h"
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 }; 205 };
206 206
207 #if SK_SUPPORT_GPU 207 #if SK_SUPPORT_GPU
208 class TextureGenerator : public SkImageGenerator { 208 class TextureGenerator : public SkImageGenerator {
209 public: 209 public:
210 TextureGenerator(GrContext* ctx, const SkImageInfo& info, SkPicture* pic) 210 TextureGenerator(GrContext* ctx, const SkImageInfo& info, SkPicture* pic)
211 : SkImageGenerator(info) 211 : SkImageGenerator(info)
212 , fCtx(SkRef(ctx)) 212 , fCtx(SkRef(ctx))
213 { 213 {
214 auto surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info)); 214 auto surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info));
215 surface->getCanvas()->clear(0); 215 if (surface) {
216 surface->getCanvas()->translate(-100, -100); 216 surface->getCanvas()->clear(0);
217 surface->getCanvas()->drawPicture(pic); 217 surface->getCanvas()->translate(-100, -100);
218 sk_sp<SkImage> image(surface->makeImageSnapshot()); 218 surface->getCanvas()->drawPicture(pic);
219 fTexture.reset(SkRef(as_IB(image)->peekTexture())); 219 sk_sp<SkImage> image(surface->makeImageSnapshot());
220 fTexture.reset(SkRef(as_IB(image)->peekTexture()));
221 }
220 } 222 }
221 protected: 223 protected:
222 GrTexture* onGenerateTexture(GrContext* ctx, const SkIRect* subset) override { 224 GrTexture* onGenerateTexture(GrContext* ctx, const SkIRect* subset) override {
223 if (ctx) { 225 if (ctx) {
224 SkASSERT(ctx == fCtx.get()); 226 SkASSERT(ctx == fCtx.get());
225 } 227 }
226 228
229 if (!fTexture) {
230 return nullptr;
231 }
232
227 if (!subset) { 233 if (!subset) {
228 return SkRef(fTexture.get()); 234 return SkRef(fTexture.get());
229 } 235 }
230 // need to copy the subset into a new texture 236 // need to copy the subset into a new texture
231 GrSurfaceDesc desc = fTexture->desc(); 237 GrSurfaceDesc desc = fTexture->desc();
232 desc.fWidth = subset->width(); 238 desc.fWidth = subset->width();
233 desc.fHeight = subset->height(); 239 desc.fHeight = subset->height();
234 240
235 GrTexture* dst = fCtx->textureProvider()->createTexture(desc, SkBudgeted ::kNo); 241 GrTexture* dst = fCtx->textureProvider()->createTexture(desc, SkBudgeted ::kNo);
236 fCtx->copySurface(dst, fTexture, *subset, SkIPoint::Make(0, 0)); 242 fCtx->copySurface(dst, fTexture, *subset, SkIPoint::Make(0, 0));
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 372
367 private: 373 private:
368 typedef skiagm::GM INHERITED; 374 typedef skiagm::GM INHERITED;
369 }; 375 };
370 DEF_GM( return new ImageCacheratorGM("picture", make_pic_generator); ) 376 DEF_GM( return new ImageCacheratorGM("picture", make_pic_generator); )
371 DEF_GM( return new ImageCacheratorGM("raster", make_ras_generator); ) 377 DEF_GM( return new ImageCacheratorGM("raster", make_ras_generator); )
372 DEF_GM( return new ImageCacheratorGM("ctable", make_ctable_generator); ) 378 DEF_GM( return new ImageCacheratorGM("ctable", make_ctable_generator); )
373 #if SK_SUPPORT_GPU 379 #if SK_SUPPORT_GPU
374 DEF_GM( return new ImageCacheratorGM("texture", make_tex_generator); ) 380 DEF_GM( return new ImageCacheratorGM("texture", make_tex_generator); )
375 #endif 381 #endif
OLDNEW
« no previous file with comments | « gm/image.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698