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

Side by Side Diff: gm/testimagefilters.cpp

Issue 1842193002: Update SkOffsetImageFilter to sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: update to ToT Created 4 years, 8 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/offsetimagefilter.cpp ('k') | gm/xfermodeimagefilter.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 "gm.h" 8 #include "gm.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkColorFilter.h" 10 #include "SkColorFilter.h"
11 #include "SkColorPriv.h" 11 #include "SkColorPriv.h"
12 #include "SkShader.h" 12 #include "SkShader.h"
13 13
14 #include "SkBlurImageFilter.h" 14 #include "SkBlurImageFilter.h"
15 #include "SkColorFilterImageFilter.h" 15 #include "SkColorFilterImageFilter.h"
16 #include "SkComposeImageFilter.h" 16 #include "SkComposeImageFilter.h"
17 #include "SkMergeImageFilter.h" 17 #include "SkMergeImageFilter.h"
18 #include "SkOffsetImageFilter.h" 18 #include "SkOffsetImageFilter.h"
19 #include "SkTestImageFilters.h" 19 #include "SkTestImageFilters.h"
20 20
21 #define FILTER_WIDTH SkIntToScalar(150) 21 #define FILTER_WIDTH SkIntToScalar(150)
22 #define FILTER_HEIGHT SkIntToScalar(200) 22 #define FILTER_HEIGHT SkIntToScalar(200)
23 23
24 static SkImageFilter* make0() { 24 static sk_sp<SkImageFilter> make0() {
25 return SkDownSampleImageFilter::Create(SK_Scalar1 / 5); 25 return sk_sp<SkImageFilter>(SkDownSampleImageFilter::Create(SK_Scalar1 / 5)) ;
26 } 26 }
27 27
28 static SkImageFilter* make1() { 28 static sk_sp<SkImageFilter> make1() {
29 return SkOffsetImageFilter::Create(SkIntToScalar(16), SkIntToScalar(16)); 29 return SkOffsetImageFilter::Make(SkIntToScalar(16), SkIntToScalar(16), nullp tr);
30 } 30 }
31 31
32 static SkImageFilter* make2() { 32 static sk_sp<SkImageFilter> make2() {
33 sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermo de::kSrcIn_Mode)); 33 sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermo de::kSrcIn_Mode));
34 return SkColorFilterImageFilter::Create(cf.get()); 34 return sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf.get()));
35 } 35 }
36 36
37 static SkImageFilter* make3() { 37 static sk_sp<SkImageFilter> make3() {
38 return SkBlurImageFilter::Create(8, 0); 38 return sk_sp<SkImageFilter>(SkBlurImageFilter::Create(8, 0));
39 } 39 }
40 40
41 static SkImageFilter* make4() { 41 static sk_sp<SkImageFilter> make4() {
42 sk_sp<SkImageFilter> outer(SkOffsetImageFilter::Create(SkIntToScalar(16), Sk IntToScalar(16))); 42 sk_sp<SkImageFilter> outer(SkOffsetImageFilter::Make(SkIntToScalar(16),
43 SkIntToScalar(16),
44 nullptr));
43 sk_sp<SkImageFilter> inner(SkDownSampleImageFilter::Create(SK_Scalar1 / 5)); 45 sk_sp<SkImageFilter> inner(SkDownSampleImageFilter::Create(SK_Scalar1 / 5));
44 return SkComposeImageFilter::Make(std::move(outer), std::move(inner)).releas e(); 46 return SkComposeImageFilter::Make(std::move(outer), std::move(inner));
45 } 47 }
46 48
47 static SkImageFilter* make5() { 49 static sk_sp<SkImageFilter> make5() {
48 sk_sp<SkImageFilter> first(SkOffsetImageFilter::Create(SkIntToScalar(16), Sk IntToScalar(16))); 50 sk_sp<SkImageFilter> first(SkOffsetImageFilter::Make(SkIntToScalar(16),
51 SkIntToScalar(16),
52 nullptr));
49 sk_sp<SkImageFilter> second(SkDownSampleImageFilter::Create(SK_Scalar1 / 5)) ; 53 sk_sp<SkImageFilter> second(SkDownSampleImageFilter::Create(SK_Scalar1 / 5)) ;
50 return SkMergeImageFilter::Make(std::move(first), std::move(second)).release (); 54 return SkMergeImageFilter::Make(std::move(first), std::move(second));
51 } 55 }
52 56
53 static SkImageFilter* make6() { 57 static sk_sp<SkImageFilter> make6() {
54 sk_sp<SkImageFilter> outer(SkOffsetImageFilter::Create(SkIntToScalar(16), Sk IntToScalar(16))); 58 sk_sp<SkImageFilter> outer(SkOffsetImageFilter::Make(SkIntToScalar(16),
59 SkIntToScalar(16),
60 nullptr));
55 sk_sp<SkImageFilter> inner(SkDownSampleImageFilter::Create(SK_Scalar1 / 5)); 61 sk_sp<SkImageFilter> inner(SkDownSampleImageFilter::Create(SK_Scalar1 / 5));
56 sk_sp<SkImageFilter> compose(SkComposeImageFilter::Make(std::move(outer), st d::move(inner))); 62 sk_sp<SkImageFilter> compose(SkComposeImageFilter::Make(std::move(outer), st d::move(inner)));
57 63
58 sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(0x880000FF, SkXfermode ::kSrcIn_Mode)); 64 sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(0x880000FF, SkXfermode ::kSrcIn_Mode));
59 sk_sp<SkImageFilter> blue(SkColorFilterImageFilter::Create(cf.get())); 65 sk_sp<SkImageFilter> blue(SkColorFilterImageFilter::Create(cf.get()));
60 66
61 return SkMergeImageFilter::Make(std::move(compose), std::move(blue)).release (); 67 return SkMergeImageFilter::Make(std::move(compose), std::move(blue));
62 } 68 }
63 69
64 static SkImageFilter* make7() { 70 static sk_sp<SkImageFilter> make7() {
65 sk_sp<SkImageFilter> outer(SkOffsetImageFilter::Create(SkIntToScalar(16), Sk IntToScalar(16))); 71 sk_sp<SkImageFilter> outer(SkOffsetImageFilter::Make(SkIntToScalar(16),
72 SkIntToScalar(16),
73 nullptr));
66 sk_sp<SkImageFilter> inner(make3()); 74 sk_sp<SkImageFilter> inner(make3());
67 sk_sp<SkImageFilter> compose(SkComposeImageFilter::Make(std::move(outer), st d::move(inner))); 75 sk_sp<SkImageFilter> compose(SkComposeImageFilter::Make(std::move(outer), st d::move(inner)));
68 76
69 sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(0x880000FF, SkXfermode ::kSrcIn_Mode)); 77 sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(0x880000FF, SkXfermode ::kSrcIn_Mode));
70 sk_sp<SkImageFilter> blue(SkColorFilterImageFilter::Create(cf.get())); 78 sk_sp<SkImageFilter> blue(SkColorFilterImageFilter::Create(cf.get()));
71 79
72 return SkMergeImageFilter::Make(std::move(compose), std::move(blue)).release (); 80 return SkMergeImageFilter::Make(std::move(compose), std::move(blue));
73 } 81 }
74 82
75 static void draw0(SkCanvas* canvas) { 83 static void draw0(SkCanvas* canvas) {
76 SkPaint p; 84 SkPaint p;
77 p.setAntiAlias(true); 85 p.setAntiAlias(true);
78 SkRect r = SkRect::MakeWH(FILTER_WIDTH, FILTER_HEIGHT); 86 SkRect r = SkRect::MakeWH(FILTER_WIDTH, FILTER_HEIGHT);
79 r.inset(SK_Scalar1 * 12, SK_Scalar1 * 12); 87 r.inset(SK_Scalar1 * 12, SK_Scalar1 * 12);
80 p.setColor(SK_ColorRED); 88 p.setColor(SK_ColorRED);
81 canvas->drawOval(r, p); 89 canvas->drawOval(r, p);
82 } 90 }
83 91
84 class TestImageFiltersGM : public skiagm::GM { 92 class TestImageFiltersGM : public skiagm::GM {
85 public: 93 public:
86 TestImageFiltersGM () {} 94 TestImageFiltersGM () {}
87 95
88 protected: 96 protected:
89 97
90 SkString onShortName() override { 98 SkString onShortName() override {
91 return SkString("testimagefilters"); 99 return SkString("testimagefilters");
92 } 100 }
93 101
94 SkISize onISize() override { return SkISize::Make(700, 460); } 102 SkISize onISize() override { return SkISize::Make(700, 460); }
95 103
96 void onDraw(SkCanvas* canvas) override { 104 void onDraw(SkCanvas* canvas) override {
97 // this->drawSizeBounds(canvas, 0xFFCCCCCC); 105 // this->drawSizeBounds(canvas, 0xFFCCCCCC);
98 106
99 static SkImageFilter* (*gFilterProc[])() = { 107 static sk_sp<SkImageFilter> (*gFilterProc[])() = {
100 make0, make1, make2, make3, make4, make5, make6, make7 108 make0, make1, make2, make3, make4, make5, make6, make7
101 }; 109 };
102 110
103 const SkRect bounds = SkRect::MakeWH(FILTER_WIDTH, FILTER_HEIGHT); 111 const SkRect bounds = SkRect::MakeWH(FILTER_WIDTH, FILTER_HEIGHT);
104 112
105 const SkScalar dx = bounds.width() * 8 / 7; 113 const SkScalar dx = bounds.width() * 8 / 7;
106 const SkScalar dy = bounds.height() * 8 / 7; 114 const SkScalar dy = bounds.height() * 8 / 7;
107 115
108 canvas->translate(SkIntToScalar(8), SkIntToScalar(8)); 116 canvas->translate(SkIntToScalar(8), SkIntToScalar(8));
109 117
110 for (int i = 0; i < (int)SK_ARRAY_COUNT(gFilterProc); ++i) { 118 for (int i = 0; i < (int)SK_ARRAY_COUNT(gFilterProc); ++i) {
111 int ix = i % 4; 119 int ix = i % 4;
112 int iy = i / 4; 120 int iy = i / 4;
113 121
114 SkAutoCanvasRestore acr(canvas, true); 122 SkAutoCanvasRestore acr(canvas, true);
115 canvas->translate(ix * dx, iy * dy); 123 canvas->translate(ix * dx, iy * dy);
116 124
117 SkPaint p; 125 SkPaint p;
118 p.setStyle(SkPaint::kStroke_Style); 126 p.setStyle(SkPaint::kStroke_Style);
119 canvas->drawRect(bounds, p); 127 canvas->drawRect(bounds, p);
120 128
121 SkPaint paint; 129 SkPaint paint;
122 paint.setImageFilter(gFilterProc[i]())->unref(); 130 paint.setImageFilter(gFilterProc[i]());
123 canvas->saveLayer(&bounds, &paint); 131 canvas->saveLayer(&bounds, &paint);
124 draw0(canvas); 132 draw0(canvas);
125 } 133 }
126 } 134 }
127 135
128 private: 136 private:
129 typedef GM INHERITED; 137 typedef GM INHERITED;
130 }; 138 };
131 139
132 ////////////////////////////////////////////////////////////////////////////// 140 //////////////////////////////////////////////////////////////////////////////
133 141
134 DEF_GM( return new TestImageFiltersGM; ) 142 DEF_GM( return new TestImageFiltersGM; )
OLDNEW
« no previous file with comments | « gm/offsetimagefilter.cpp ('k') | gm/xfermodeimagefilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698