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

Side by Side Diff: gm/localmatriximagefilter.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/imagetoyuvplanes.cpp ('k') | gm/mipmap.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 "SkBlurImageFilter.h" 10 #include "SkBlurImageFilter.h"
11 #include "SkColorFilterImageFilter.h" 11 #include "SkColorFilterImageFilter.h"
12 #include "SkModeColorFilter.h" 12 #include "SkModeColorFilter.h"
13 #include "SkMorphologyImageFilter.h" 13 #include "SkMorphologyImageFilter.h"
14 #include "SkOffsetImageFilter.h" 14 #include "SkOffsetImageFilter.h"
15 #include "SkSurface.h" 15 #include "SkSurface.h"
16 16
17 static SkImage* make_image(SkCanvas* rootCanvas) { 17 static sk_sp<SkImage> make_image(SkCanvas* rootCanvas) {
18 SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); 18 SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100);
19 SkAutoTUnref<SkSurface> surface(rootCanvas->newSurface(info)); 19 SkAutoTUnref<SkSurface> surface(rootCanvas->newSurface(info));
20 if (!surface) { 20 if (!surface) {
21 surface.reset(SkSurface::NewRaster(info)); 21 surface.reset(SkSurface::NewRaster(info));
22 } 22 }
23 23
24 SkPaint paint; 24 SkPaint paint;
25 paint.setAntiAlias(true); 25 paint.setAntiAlias(true);
26 paint.setColor(SK_ColorRED); 26 paint.setColor(SK_ColorRED);
27 surface->getCanvas()->drawCircle(50, 50, 50, paint); 27 surface->getCanvas()->drawCircle(50, 50, 50, paint);
28 return surface->newImageSnapshot(); 28 return surface->makeImageSnapshot();
29 } 29 }
30 30
31 typedef SkImageFilter* (*ImageFilterFactory)(); 31 typedef SkImageFilter* (*ImageFilterFactory)();
32 32
33 // +[]{...} did not work on windows (VS) 33 // +[]{...} did not work on windows (VS)
34 // (ImageFilterFactory)[]{...} did not work on linux (gcc) 34 // (ImageFilterFactory)[]{...} did not work on linux (gcc)
35 // hence this cast function 35 // hence this cast function
36 template <typename T> ImageFilterFactory IFCCast(T arg) { return arg; } 36 template <typename T> ImageFilterFactory IFCCast(T arg) { return arg; }
37 37
38 // Show the effect of localmatriximagefilter with various matrices, on various f ilters 38 // Show the effect of localmatriximagefilter with various matrices, on various f ilters
(...skipping 16 matching lines...) Expand all
55 SkRect r = SkRect::MakeIWH(image->width(), image->height()).makeOutset(S K_ScalarHalf, 55 SkRect r = SkRect::MakeIWH(image->width(), image->height()).makeOutset(S K_ScalarHalf,
56 S K_ScalarHalf); 56 S K_ScalarHalf);
57 canvas->drawRect(r, paint); 57 canvas->drawRect(r, paint);
58 58
59 paint.setStyle(SkPaint::kFill_Style); 59 paint.setStyle(SkPaint::kFill_Style);
60 paint.setImageFilter(filter); 60 paint.setImageFilter(filter);
61 canvas->drawImage(image, 0, 0, &paint); 61 canvas->drawImage(image, 0, 0, &paint);
62 } 62 }
63 63
64 void onDraw(SkCanvas* canvas) override { 64 void onDraw(SkCanvas* canvas) override {
65 SkAutoTUnref<SkImage> image0(make_image(canvas)); 65 sk_sp<SkImage> image0(make_image(canvas));
66 66
67 const ImageFilterFactory factories[] = { 67 const ImageFilterFactory factories[] = {
68 IFCCast([]{ return SkBlurImageFilter::Create(8, 8); }), 68 IFCCast([]{ return SkBlurImageFilter::Create(8, 8); }),
69 IFCCast([]{ return SkDilateImageFilter::Create(8, 8); }), 69 IFCCast([]{ return SkDilateImageFilter::Create(8, 8); }),
70 IFCCast([]{ return SkErodeImageFilter::Create(8, 8); }), 70 IFCCast([]{ return SkErodeImageFilter::Create(8, 8); }),
71 IFCCast([]{ return SkOffsetImageFilter::Create(8, 8); }), 71 IFCCast([]{ return SkOffsetImageFilter::Create(8, 8); }),
72 }; 72 };
73 73
74 const SkMatrix matrices[] = { 74 const SkMatrix matrices[] = {
75 SkMatrix::MakeScale(SK_ScalarHalf, SK_ScalarHalf), 75 SkMatrix::MakeScale(SK_ScalarHalf, SK_ScalarHalf),
76 SkMatrix::MakeScale(2, 2), 76 SkMatrix::MakeScale(2, 2),
77 SkMatrix::MakeTrans(10, 10) 77 SkMatrix::MakeTrans(10, 10)
78 }; 78 };
79 79
80 const SkScalar spacer = image0->width() * 3.0f / 2; 80 const SkScalar spacer = image0->width() * 3.0f / 2;
81 81
82 canvas->translate(40, 40); 82 canvas->translate(40, 40);
83 for (auto&& factory : factories) { 83 for (auto&& factory : factories) {
84 SkAutoTUnref<SkImageFilter> filter(factory()); 84 SkAutoTUnref<SkImageFilter> filter(factory());
85 85
86 canvas->save(); 86 canvas->save();
87 show_image(canvas, image0, filter); 87 show_image(canvas, image0.get(), filter);
88 for (const auto& matrix : matrices) { 88 for (const auto& matrix : matrices) {
89 SkAutoTUnref<SkImageFilter> localFilter(filter->newWithLocalMatr ix(matrix)); 89 SkAutoTUnref<SkImageFilter> localFilter(filter->newWithLocalMatr ix(matrix));
90 canvas->translate(spacer, 0); 90 canvas->translate(spacer, 0);
91 show_image(canvas, image0, localFilter); 91 show_image(canvas, image0.get(), localFilter);
92 } 92 }
93 canvas->restore(); 93 canvas->restore();
94 canvas->translate(0, spacer); 94 canvas->translate(0, spacer);
95 } 95 }
96 } 96 }
97 97
98 private: 98 private:
99 typedef GM INHERITED; 99 typedef GM INHERITED;
100 }; 100 };
101 DEF_GM( return new LocalMatrixImageFilterGM; ) 101 DEF_GM( return new LocalMatrixImageFilterGM; )
102 102
OLDNEW
« no previous file with comments | « gm/imagetoyuvplanes.cpp ('k') | gm/mipmap.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698