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

Side by Side Diff: gm/image.cpp

Issue 1811703002: return pictures as sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rely on RVO in picturerecorder Created 4 years, 9 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/filterfastbounds.cpp ('k') | gm/image_pict.cpp » ('j') | 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 2011 Google Inc. 2 * Copyright 2011 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 <functional> 8 #include <functional>
9 #include "gm.h" 9 #include "gm.h"
10 #include "SkAutoPixmapStorage.h" 10 #include "SkAutoPixmapStorage.h"
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 239
240 static sk_sp<SkImage> make_raster(const SkImageInfo& info, GrContext*, void (*dr aw)(SkCanvas*)) { 240 static sk_sp<SkImage> make_raster(const SkImageInfo& info, GrContext*, void (*dr aw)(SkCanvas*)) {
241 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); 241 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info));
242 draw(surface->getCanvas()); 242 draw(surface->getCanvas());
243 return surface->makeImageSnapshot(); 243 return surface->makeImageSnapshot();
244 } 244 }
245 245
246 static sk_sp<SkImage> make_picture(const SkImageInfo& info, GrContext*, void (*d raw)(SkCanvas*)) { 246 static sk_sp<SkImage> make_picture(const SkImageInfo& info, GrContext*, void (*d raw)(SkCanvas*)) {
247 SkPictureRecorder recorder; 247 SkPictureRecorder recorder;
248 draw(recorder.beginRecording(SkRect::MakeIWH(info.width(), info.height()))); 248 draw(recorder.beginRecording(SkRect::MakeIWH(info.width(), info.height())));
249 SkAutoTUnref<SkPicture> pict(recorder.endRecording()); 249 return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(),
250 return SkImage::MakeFromPicture(sk_ref_sp(pict.get()), info.dimensions(), nu llptr, nullptr); 250 info.dimensions(), nullptr, nullptr);
251 } 251 }
252 252
253 static sk_sp<SkImage> make_codec(const SkImageInfo& info, GrContext*, void (*dra w)(SkCanvas*)) { 253 static sk_sp<SkImage> make_codec(const SkImageInfo& info, GrContext*, void (*dra w)(SkCanvas*)) {
254 sk_sp<SkImage> image(make_raster(info, nullptr, draw)); 254 sk_sp<SkImage> image(make_raster(info, nullptr, draw));
255 sk_sp<SkData> data(image->encode()); 255 sk_sp<SkData> data(image->encode());
256 return SkImage::MakeFromEncoded(data); 256 return SkImage::MakeFromEncoded(data);
257 } 257 }
258 258
259 static sk_sp<SkImage> make_gpu(const SkImageInfo& info, GrContext* ctx, void (*d raw)(SkCanvas*)) { 259 static sk_sp<SkImage> make_gpu(const SkImageInfo& info, GrContext* ctx, void (*d raw)(SkCanvas*)) {
260 if (!ctx) { return nullptr; } 260 if (!ctx) { return nullptr; }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 336
337 static SkImageGenerator* gen_raster(const SkImageInfo& info) { 337 static SkImageGenerator* gen_raster(const SkImageInfo& info) {
338 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); 338 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info));
339 draw_opaque_contents(surface->getCanvas()); 339 draw_opaque_contents(surface->getCanvas());
340 return new ImageGeneratorFromImage(surface->makeImageSnapshot().get()); 340 return new ImageGeneratorFromImage(surface->makeImageSnapshot().get());
341 } 341 }
342 342
343 static SkImageGenerator* gen_picture(const SkImageInfo& info) { 343 static SkImageGenerator* gen_picture(const SkImageInfo& info) {
344 SkPictureRecorder recorder; 344 SkPictureRecorder recorder;
345 draw_opaque_contents(recorder.beginRecording(SkRect::MakeIWH(info.width(), i nfo.height()))); 345 draw_opaque_contents(recorder.beginRecording(SkRect::MakeIWH(info.width(), i nfo.height())));
346 SkAutoTUnref<SkPicture> pict(recorder.endRecording()); 346 sk_sp<SkPicture> pict(recorder.finishRecordingAsPicture());
347 return SkImageGenerator::NewFromPicture(info.dimensions(), pict, nullptr, nu llptr); 347 return SkImageGenerator::NewFromPicture(info.dimensions(), pict.get(), nullp tr, nullptr);
348 } 348 }
349 349
350 static SkImageGenerator* gen_png(const SkImageInfo& info) { 350 static SkImageGenerator* gen_png(const SkImageInfo& info) {
351 sk_sp<SkImage> image(make_raster(info, nullptr, draw_opaque_contents)); 351 sk_sp<SkImage> image(make_raster(info, nullptr, draw_opaque_contents));
352 SkAutoTUnref<SkData> data(image->encode(SkImageEncoder::kPNG_Type, 100)); 352 SkAutoTUnref<SkData> data(image->encode(SkImageEncoder::kPNG_Type, 100));
353 return SkImageGenerator::NewFromEncoded(data); 353 return SkImageGenerator::NewFromEncoded(data);
354 } 354 }
355 355
356 static SkImageGenerator* gen_jpg(const SkImageInfo& info) { 356 static SkImageGenerator* gen_jpg(const SkImageInfo& info) {
357 sk_sp<SkImage> image(make_raster(info, nullptr, draw_opaque_contents)); 357 sk_sp<SkImage> image(make_raster(info, nullptr, draw_opaque_contents));
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 [bmp] { 469 [bmp] {
470 sk_sp<SkData> src( 470 sk_sp<SkData> src(
471 SkImageEncoder::EncodeData(bmp, SkImageEncoder::kPNG_Type, 100)) ; 471 SkImageEncoder::EncodeData(bmp, SkImageEncoder::kPNG_Type, 100)) ;
472 return SkImage::MakeFromEncoded(std::move(src)); 472 return SkImage::MakeFromEncoded(std::move(src));
473 }, 473 },
474 // Create a picture image. 474 // Create a picture image.
475 [render_image] { 475 [render_image] {
476 SkPictureRecorder recorder; 476 SkPictureRecorder recorder;
477 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kSize), SkI ntToScalar(kSize)); 477 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kSize), SkI ntToScalar(kSize));
478 render_image(canvas); 478 render_image(canvas);
479 SkAutoTUnref<SkPicture> picture(recorder.endRecording()); 479 return SkImage::MakeFromPicture(recorder.finishRecordingAsPicture(),
480 return SkImage::MakeFromPicture(sk_ref_sp(picture.get()), SkISize::M ake(kSize, kSize), 480 SkISize::Make(kSize, kSize), nullptr, nullptr);
481 nullptr, nullptr);
482 }, 481 },
483 // Create a texture image 482 // Create a texture image
484 [context, render_image]() -> sk_sp<SkImage> { 483 [context, render_image]() -> sk_sp<SkImage> {
485 SkAutoTUnref<SkSurface> surface( 484 SkAutoTUnref<SkSurface> surface(
486 SkSurface::NewRenderTarget(context, SkBudgeted::kYes, 485 SkSurface::NewRenderTarget(context, SkBudgeted::kYes,
487 SkImageInfo::MakeN32Premul(kSize, kSi ze))); 486 SkImageInfo::MakeN32Premul(kSize, kSi ze)));
488 if (!surface) { 487 if (!surface) {
489 return nullptr; 488 return nullptr;
490 } 489 }
491 render_image(surface->getCanvas()); 490 render_image(surface->getCanvas());
(...skipping 10 matching lines...) Expand all
502 } 501 }
503 if (context) { 502 if (context) {
504 sk_sp<SkImage> texImage(image->makeTextureImage(context)); 503 sk_sp<SkImage> texImage(image->makeTextureImage(context));
505 if (texImage) { 504 if (texImage) {
506 canvas->drawImage(texImage, 0, 0); 505 canvas->drawImage(texImage, 0, 0);
507 } 506 }
508 } 507 }
509 canvas->translate(image->width() + kPad, 0); 508 canvas->translate(image->width() + kPad, 0);
510 } 509 }
511 } 510 }
OLDNEW
« no previous file with comments | « gm/filterfastbounds.cpp ('k') | gm/image_pict.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698