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

Side by Side Diff: samplecode/SampleFilterQuality.cpp

Issue 1817383002: switch surface to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 | « samplecode/SampleFatBits.cpp ('k') | samplecode/SampleQuadStroker.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 9
10 #include "Resources.h" 10 #include "Resources.h"
11 #include "SampleCode.h" 11 #include "SampleCode.h"
12 #include "SkAnimTimer.h" 12 #include "SkAnimTimer.h"
13 #include "SkCanvas.h" 13 #include "SkCanvas.h"
14 #include "SkInterpolator.h" 14 #include "SkInterpolator.h"
15 #include "SkGradientShader.h" 15 #include "SkGradientShader.h"
16 #include "SkData.h" 16 #include "SkData.h"
17 #include "SkPath.h" 17 #include "SkPath.h"
18 #include "SkSurface.h" 18 #include "SkSurface.h"
19 #include "SkRandom.h" 19 #include "SkRandom.h"
20 #include "SkTime.h" 20 #include "SkTime.h"
21 21
22 static SkSurface* make_surface(SkCanvas* canvas, const SkImageInfo& info) { 22 static sk_sp<SkSurface> make_surface(SkCanvas* canvas, const SkImageInfo& info) {
23 SkSurface* surface = canvas->newSurface(info); 23 auto surface = canvas->makeSurface(info);
24 if (!surface) { 24 if (!surface) {
25 surface = SkSurface::NewRaster(info); 25 surface = SkSurface::MakeRaster(info);
26 } 26 }
27 return surface; 27 return surface;
28 } 28 }
29 29
30 static sk_sp<SkShader> make_shader(const SkRect& bounds) { 30 static sk_sp<SkShader> make_shader(const SkRect& bounds) {
31 sk_sp<SkImage> image(GetResourceAsImage("mandrill_128.png")); 31 sk_sp<SkImage> image(GetResourceAsImage("mandrill_128.png"));
32 if (!image) { 32 if (!image) {
33 return nullptr; 33 return nullptr;
34 } 34 }
35 return image->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMod e); 35 return image->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMod e);
36 } 36 }
37 37
38 #define N 128 38 #define N 128
39 #define ANGLE_DELTA 3 39 #define ANGLE_DELTA 3
40 #define SCALE_DELTA (SK_Scalar1 / 32) 40 #define SCALE_DELTA (SK_Scalar1 / 32)
41 41
42 static sk_sp<SkImage> make_image() { 42 static sk_sp<SkImage> make_image() {
43 SkImageInfo info = SkImageInfo::MakeN32(N, N, kOpaque_SkAlphaType); 43 SkImageInfo info = SkImageInfo::MakeN32(N, N, kOpaque_SkAlphaType);
44 SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); 44 auto surface(SkSurface::MakeRaster(info));
45 SkCanvas* canvas = surface->getCanvas(); 45 SkCanvas* canvas = surface->getCanvas();
46 canvas->drawColor(SK_ColorWHITE); 46 canvas->drawColor(SK_ColorWHITE);
47 47
48 SkPath path; 48 SkPath path;
49 path.setFillType(SkPath::kEvenOdd_FillType); 49 path.setFillType(SkPath::kEvenOdd_FillType);
50 50
51 path.addRect(SkRect::MakeWH(N/2, N)); 51 path.addRect(SkRect::MakeWH(N/2, N));
52 path.addRect(SkRect::MakeWH(N, N/2)); 52 path.addRect(SkRect::MakeWH(N, N/2));
53 path.moveTo(0, 0); path.lineTo(N, 0); path.lineTo(0, N); path.close(); 53 path.moveTo(0, 0); path.lineTo(N, 0); path.lineTo(0, N); path.close();
54 54
55 SkPaint paint; 55 SkPaint paint;
56 paint.setShader(make_shader(SkRect::MakeWH(N, N))); 56 paint.setShader(make_shader(SkRect::MakeWH(N, N)));
57 57
58 canvas->drawPath(path, paint); 58 canvas->drawPath(path, paint);
59 return surface->makeImageSnapshot(); 59 return surface->makeImageSnapshot();
60 } 60 }
61 61
62 static sk_sp<SkImage> zoom_up(SkSurface* origSurf, SkImage* orig) { 62 static sk_sp<SkImage> zoom_up(SkSurface* origSurf, SkImage* orig) {
63 const SkScalar S = 16; // amount to scale up 63 const SkScalar S = 16; // amount to scale up
64 const int D = 2; // dimension scaling for the offscreen 64 const int D = 2; // dimension scaling for the offscreen
65 // since we only view the center, don't need to produce the entire thing 65 // since we only view the center, don't need to produce the entire thing
66 66
67 SkImageInfo info = SkImageInfo::MakeN32(orig->width() * D, orig->height() * D, 67 SkImageInfo info = SkImageInfo::MakeN32(orig->width() * D, orig->height() * D,
68 kOpaque_SkAlphaType); 68 kOpaque_SkAlphaType);
69 SkAutoTUnref<SkSurface> surface(origSurf->newSurface(info)); 69 auto surface(origSurf->makeSurface(info));
70 SkCanvas* canvas = surface->getCanvas(); 70 SkCanvas* canvas = surface->getCanvas();
71 canvas->drawColor(SK_ColorWHITE); 71 canvas->drawColor(SK_ColorWHITE);
72 canvas->scale(S, S); 72 canvas->scale(S, S);
73 canvas->translate(-SkScalarHalf(orig->width()) * (S - D) / S, 73 canvas->translate(-SkScalarHalf(orig->width()) * (S - D) / S,
74 -SkScalarHalf(orig->height()) * (S - D) / S); 74 -SkScalarHalf(orig->height()) * (S - D) / S);
75 canvas->drawImage(orig, 0, 0, nullptr); 75 canvas->drawImage(orig, 0, 0, nullptr);
76 76
77 if (S > 3) { 77 if (S > 3) {
78 SkPaint paint; 78 SkPaint paint;
79 paint.setColor(SK_ColorWHITE); 79 paint.setColor(SK_ColorWHITE);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 draw_box_frame(canvas, size.width(), size.height()); 210 draw_box_frame(canvas, size.width(), size.height());
211 } 211 }
212 } 212 }
213 213
214 void drawHere(SkCanvas* canvas, SkFilterQuality filter, SkScalar dx, SkScala r dy) { 214 void drawHere(SkCanvas* canvas, SkFilterQuality filter, SkScalar dx, SkScala r dy) {
215 SkCanvas* origCanvas = canvas; 215 SkCanvas* origCanvas = canvas;
216 SkAutoCanvasRestore acr(canvas, true); 216 SkAutoCanvasRestore acr(canvas, true);
217 217
218 SkISize size = SkISize::Make(fImage->width(), fImage->height()); 218 SkISize size = SkISize::Make(fImage->width(), fImage->height());
219 219
220 SkAutoTUnref<SkSurface> surface; 220 sk_sp<SkSurface> surface;
221 if (fShowFatBits) { 221 if (fShowFatBits) {
222 // scale up so we don't clip rotations 222 // scale up so we don't clip rotations
223 SkImageInfo info = SkImageInfo::MakeN32(fImage->width() * 2, fImage- >height() * 2, 223 SkImageInfo info = SkImageInfo::MakeN32(fImage->width() * 2, fImage- >height() * 2,
224 kOpaque_SkAlphaType); 224 kOpaque_SkAlphaType);
225 surface.reset(make_surface(canvas, info)); 225 surface = make_surface(canvas, info);
226 canvas = surface->getCanvas(); 226 canvas = surface->getCanvas();
227 canvas->drawColor(SK_ColorWHITE); 227 canvas->drawColor(SK_ColorWHITE);
228 size.set(info.width(), info.height()); 228 size.set(info.width(), info.height());
229 } else { 229 } else {
230 canvas->translate(SkScalarHalf(fCell.width() - fImage->width()), 230 canvas->translate(SkScalarHalf(fCell.width() - fImage->width()),
231 SkScalarHalf(fCell.height() - fImage->height())); 231 SkScalarHalf(fCell.height() - fImage->height()));
232 } 232 }
233 this->drawTheImage(canvas, size, filter, dx, dy); 233 this->drawTheImage(canvas, size, filter, dx, dy);
234 234
235 if (surface) { 235 if (surface) {
236 sk_sp<SkImage> orig(surface->makeImageSnapshot()); 236 sk_sp<SkImage> orig(surface->makeImageSnapshot());
237 sk_sp<SkImage> zoomed(zoom_up(surface, orig.get())); 237 sk_sp<SkImage> zoomed(zoom_up(surface.get(), orig.get()));
238 origCanvas->drawImage(zoomed.get(), 238 origCanvas->drawImage(zoomed.get(),
239 SkScalarHalf(fCell.width() - zoomed->width()), 239 SkScalarHalf(fCell.width() - zoomed->width()),
240 SkScalarHalf(fCell.height() - zoomed->height() )); 240 SkScalarHalf(fCell.height() - zoomed->height() ));
241 } 241 }
242 } 242 }
243 243
244 void drawBorders(SkCanvas* canvas) { 244 void drawBorders(SkCanvas* canvas) {
245 SkPaint p; 245 SkPaint p;
246 p.setStyle(SkPaint::kStroke_Style); 246 p.setStyle(SkPaint::kStroke_Style);
247 p.setColor(SK_ColorBLUE); 247 p.setColor(SK_ColorBLUE);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 } 301 }
302 302
303 private: 303 private:
304 typedef SampleView INHERITED; 304 typedef SampleView INHERITED;
305 }; 305 };
306 306
307 ////////////////////////////////////////////////////////////////////////////// 307 //////////////////////////////////////////////////////////////////////////////
308 308
309 static SkView* MyFactory() { return new FilterQualityView; } 309 static SkView* MyFactory() { return new FilterQualityView; }
310 static SkViewRegister reg(MyFactory); 310 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « samplecode/SampleFatBits.cpp ('k') | samplecode/SampleQuadStroker.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698