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

Side by Side Diff: gm/image_shader.cpp

Issue 1810813003: update callsites for Make image factories (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: start to take advantage of sk_sp drawImage 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/image_pict.cpp ('k') | gm/imagealphathreshold.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 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 "SkData.h" 10 #include "SkData.h"
11 #include "SkImage.h" 11 #include "SkImage.h"
12 #include "SkPictureRecorder.h" 12 #include "SkPictureRecorder.h"
13 #include "SkSurface.h" 13 #include "SkSurface.h"
14 14
15 static void draw_something(SkCanvas* canvas, const SkRect& bounds) { 15 static void draw_something(SkCanvas* canvas, const SkRect& bounds) {
16 SkPaint paint; 16 SkPaint paint;
17 paint.setAntiAlias(true); 17 paint.setAntiAlias(true);
18 paint.setColor(SK_ColorRED); 18 paint.setColor(SK_ColorRED);
19 paint.setStyle(SkPaint::kStroke_Style); 19 paint.setStyle(SkPaint::kStroke_Style);
20 paint.setStrokeWidth(10); 20 paint.setStrokeWidth(10);
21 canvas->drawRect(bounds, paint); 21 canvas->drawRect(bounds, paint);
22 paint.setStyle(SkPaint::kFill_Style); 22 paint.setStyle(SkPaint::kFill_Style);
23 paint.setColor(SK_ColorBLUE); 23 paint.setColor(SK_ColorBLUE);
24 canvas->drawOval(bounds, paint); 24 canvas->drawOval(bounds, paint);
25 } 25 }
26 26
27 typedef SkImage* (*ImageMakerProc)(GrContext*, const SkPicture*, const SkImageIn fo&); 27 typedef sk_sp<SkImage> (*ImageMakerProc)(GrContext*, SkPicture*, const SkImageIn fo&);
28 28
29 static SkImage* make_raster(GrContext*, const SkPicture* pic, const SkImageInfo& info) { 29 static sk_sp<SkImage> make_raster(GrContext*, SkPicture* pic, const SkImageInfo& info) {
30 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); 30 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info));
31 surface->getCanvas()->clear(0); 31 surface->getCanvas()->clear(0);
32 surface->getCanvas()->drawPicture(pic); 32 surface->getCanvas()->drawPicture(pic);
33 return surface->newImageSnapshot(); 33 return surface->makeImageSnapshot();
34 } 34 }
35 35
36 static SkImage* make_texture(GrContext* ctx, const SkPicture* pic, const SkImage Info& info) { 36 static sk_sp<SkImage> make_texture(GrContext* ctx, SkPicture* pic, const SkImage Info& info) {
37 if (!ctx) { 37 if (!ctx) {
38 return nullptr; 38 return nullptr;
39 } 39 }
40 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkBudgeted:: kNo, 40 SkAutoTUnref<SkSurface> surface(SkSurface::NewRenderTarget(ctx, SkBudgeted:: kNo,
41 info, 0)); 41 info, 0));
42 surface->getCanvas()->clear(0); 42 surface->getCanvas()->clear(0);
43 surface->getCanvas()->drawPicture(pic); 43 surface->getCanvas()->drawPicture(pic);
44 return surface->newImageSnapshot(); 44 return surface->makeImageSnapshot();
45 } 45 }
46 46
47 static SkImage* make_pict_gen(GrContext*, const SkPicture* pic, const SkImageInf o& info) { 47 static sk_sp<SkImage> make_pict_gen(GrContext*, SkPicture* pic, const SkImageInf o& info) {
48 return SkImage::NewFromPicture(pic, info.dimensions(), nullptr, nullptr); 48 return SkImage::MakeFromPicture(sk_ref_sp(pic), info.dimensions(), nullptr, nullptr);
49 } 49 }
50 50
51 static SkImage* make_encode_gen(GrContext* ctx, const SkPicture* pic, const SkIm ageInfo& info) { 51 static sk_sp<SkImage> make_encode_gen(GrContext* ctx, SkPicture* pic, const SkIm ageInfo& info) {
52 SkAutoTUnref<SkImage> src(make_raster(ctx, pic, info)); 52 sk_sp<SkImage> src(make_raster(ctx, pic, info));
53 if (!src) { 53 if (!src) {
54 return nullptr; 54 return nullptr;
55 } 55 }
56 SkAutoTUnref<SkData> encoded(src->encode(SkImageEncoder::kPNG_Type, 100)); 56 sk_sp<SkData> encoded(src->encode(SkImageEncoder::kPNG_Type, 100));
57 if (!encoded) { 57 if (!encoded) {
58 return nullptr; 58 return nullptr;
59 } 59 }
60 return SkImage::NewFromEncoded(encoded); 60 return SkImage::MakeFromEncoded(std::move(encoded));
61 } 61 }
62 62
63 const ImageMakerProc gProcs[] = { 63 const ImageMakerProc gProcs[] = {
64 make_raster, 64 make_raster,
65 make_texture, 65 make_texture,
66 make_pict_gen, 66 make_pict_gen,
67 make_encode_gen, 67 make_encode_gen,
68 }; 68 };
69 69
70 /* 70 /*
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 paint.setAntiAlias(true); 106 paint.setAntiAlias(true);
107 canvas->drawCircle(50, 50, 50, paint); 107 canvas->drawCircle(50, 50, 50, paint);
108 } 108 }
109 109
110 void onDraw(SkCanvas* canvas) override { 110 void onDraw(SkCanvas* canvas) override {
111 canvas->translate(20, 20); 111 canvas->translate(20, 20);
112 112
113 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); 113 const SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
114 114
115 for (size_t i = 0; i < SK_ARRAY_COUNT(gProcs); ++i) { 115 for (size_t i = 0; i < SK_ARRAY_COUNT(gProcs); ++i) {
116 SkAutoTUnref<SkImage> image(gProcs[i](canvas->getGrContext(), fPictu re, info)); 116 sk_sp<SkImage> image(gProcs[i](canvas->getGrContext(), fPicture, inf o));
117 if (image) { 117 if (image) {
118 this->testImage(canvas, image); 118 this->testImage(canvas, image.get());
119 } 119 }
120 canvas->translate(120, 0); 120 canvas->translate(120, 0);
121 } 121 }
122 } 122 }
123 123
124 private: 124 private:
125 typedef skiagm::GM INHERITED; 125 typedef skiagm::GM INHERITED;
126 }; 126 };
127 DEF_GM( return new ImageShaderGM; ) 127 DEF_GM( return new ImageShaderGM; )
128 128
OLDNEW
« no previous file with comments | « gm/image_pict.cpp ('k') | gm/imagealphathreshold.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698