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

Side by Side Diff: gm/imagefiltersbase.cpp

Issue 1858813002: Update SkColorFilterImageFilter 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/imagefilters.cpp ('k') | gm/imagefilterscropexpand.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"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 99
100 #ifndef SK_IGNORE_TO_STRING 100 #ifndef SK_IGNORE_TO_STRING
101 void IdentityImageFilter::toString(SkString* str) const { 101 void IdentityImageFilter::toString(SkString* str) const {
102 str->appendf("IdentityImageFilter: ("); 102 str->appendf("IdentityImageFilter: (");
103 str->append(")"); 103 str->append(")");
104 } 104 }
105 #endif 105 #endif
106 106
107 /////////////////////////////////////////////////////////////////////////////// 107 ///////////////////////////////////////////////////////////////////////////////
108 108
109 static void draw_paint(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { 109 static void draw_paint(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> i mf) {
110 SkPaint paint; 110 SkPaint paint;
111 paint.setImageFilter(imf); 111 paint.setImageFilter(std::move(imf));
112 paint.setColor(SK_ColorGREEN); 112 paint.setColor(SK_ColorGREEN);
113 canvas->save(); 113 canvas->save();
114 canvas->clipRect(r); 114 canvas->clipRect(r);
115 canvas->drawPaint(paint); 115 canvas->drawPaint(paint);
116 canvas->restore(); 116 canvas->restore();
117 } 117 }
118 118
119 static void draw_line(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { 119 static void draw_line(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> im f) {
120 SkPaint paint; 120 SkPaint paint;
121 paint.setColor(SK_ColorBLUE); 121 paint.setColor(SK_ColorBLUE);
122 paint.setImageFilter(imf); 122 paint.setImageFilter(imf);
123 paint.setStrokeWidth(r.width()/10); 123 paint.setStrokeWidth(r.width()/10);
124 canvas->drawLine(r.fLeft, r.fTop, r.fRight, r.fBottom, paint); 124 canvas->drawLine(r.fLeft, r.fTop, r.fRight, r.fBottom, paint);
125 } 125 }
126 126
127 static void draw_rect(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { 127 static void draw_rect(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> im f) {
128 SkPaint paint; 128 SkPaint paint;
129 paint.setColor(SK_ColorYELLOW); 129 paint.setColor(SK_ColorYELLOW);
130 paint.setImageFilter(imf); 130 paint.setImageFilter(imf);
131 SkRect rr(r); 131 SkRect rr(r);
132 rr.inset(r.width()/10, r.height()/10); 132 rr.inset(r.width()/10, r.height()/10);
133 canvas->drawRect(rr, paint); 133 canvas->drawRect(rr, paint);
134 } 134 }
135 135
136 static void draw_path(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { 136 static void draw_path(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> im f) {
137 SkPaint paint; 137 SkPaint paint;
138 paint.setColor(SK_ColorMAGENTA); 138 paint.setColor(SK_ColorMAGENTA);
139 paint.setImageFilter(imf); 139 paint.setImageFilter(imf);
140 paint.setAntiAlias(true); 140 paint.setAntiAlias(true);
141 canvas->drawCircle(r.centerX(), r.centerY(), r.width()*2/5, paint); 141 canvas->drawCircle(r.centerX(), r.centerY(), r.width()*2/5, paint);
142 } 142 }
143 143
144 static void draw_text(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { 144 static void draw_text(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> im f) {
145 SkPaint paint; 145 SkPaint paint;
146 paint.setImageFilter(imf); 146 paint.setImageFilter(imf);
147 paint.setColor(SK_ColorCYAN); 147 paint.setColor(SK_ColorCYAN);
148 paint.setAntiAlias(true); 148 paint.setAntiAlias(true);
149 sk_tool_utils::set_portable_typeface(&paint); 149 sk_tool_utils::set_portable_typeface(&paint);
150 paint.setTextSize(r.height()/2); 150 paint.setTextSize(r.height()/2);
151 paint.setTextAlign(SkPaint::kCenter_Align); 151 paint.setTextAlign(SkPaint::kCenter_Align);
152 canvas->drawText("Text", 4, r.centerX(), r.centerY(), paint); 152 canvas->drawText("Text", 4, r.centerX(), r.centerY(), paint);
153 } 153 }
154 154
155 static void draw_bitmap(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) { 155 static void draw_bitmap(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) {
156 SkPaint paint; 156 SkPaint paint;
157 paint.setImageFilter(imf); 157 paint.setImageFilter(std::move(imf));
158 158
159 SkIRect bounds; 159 SkIRect bounds;
160 r.roundOut(&bounds); 160 r.roundOut(&bounds);
161 161
162 SkBitmap bm; 162 SkBitmap bm;
163 bm.allocN32Pixels(bounds.width(), bounds.height()); 163 bm.allocN32Pixels(bounds.width(), bounds.height());
164 bm.eraseColor(SK_ColorTRANSPARENT); 164 bm.eraseColor(SK_ColorTRANSPARENT);
165 SkCanvas c(bm); 165 SkCanvas c(bm);
166 draw_path(&c, r, nullptr); 166 draw_path(&c, r, nullptr);
167 167
(...skipping 14 matching lines...) Expand all
182 SkISize onISize() override { return SkISize::Make(700, 500); } 182 SkISize onISize() override { return SkISize::Make(700, 500); }
183 183
184 void draw_frame(SkCanvas* canvas, const SkRect& r) { 184 void draw_frame(SkCanvas* canvas, const SkRect& r) {
185 SkPaint paint; 185 SkPaint paint;
186 paint.setStyle(SkPaint::kStroke_Style); 186 paint.setStyle(SkPaint::kStroke_Style);
187 paint.setColor(SK_ColorRED); 187 paint.setColor(SK_ColorRED);
188 canvas->drawRect(r, paint); 188 canvas->drawRect(r, paint);
189 } 189 }
190 190
191 void onDraw(SkCanvas* canvas) override { 191 void onDraw(SkCanvas* canvas) override {
192 void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = { 192 void (*drawProc[])(SkCanvas*, const SkRect&, sk_sp<SkImageFilter>) = {
193 draw_paint, 193 draw_paint,
194 draw_line, draw_rect, draw_path, draw_text, 194 draw_line, draw_rect, draw_path, draw_text,
195 draw_bitmap, 195 draw_bitmap,
196 }; 196 };
197 197
198 auto cf = SkColorFilter::MakeModeFilter(SK_ColorRED, SkXfermode::kSrcIn_ Mode); 198 auto cf = SkColorFilter::MakeModeFilter(SK_ColorRED, SkXfermode::kSrcIn_ Mode);
199 SkImageFilter* filters[] = { 199 sk_sp<SkImageFilter> filters[] = {
200 nullptr, 200 nullptr,
201 IdentityImageFilter::Make(nullptr).release(), 201 IdentityImageFilter::Make(nullptr),
202 FailImageFilter::Make().release(), 202 FailImageFilter::Make(),
203 SkColorFilterImageFilter::Create(cf.get()), 203 SkColorFilterImageFilter::Make(std::move(cf), nullptr),
204 SkBlurImageFilter::Make(12.0f, 0.0f, nullptr).release(), 204 SkBlurImageFilter::Make(12.0f, 0.0f, nullptr),
205 SkDropShadowImageFilter::Create(10.0f, 5.0f, 3.0f, 3.0f, SK_ColorBLU E, 205 sk_sp<SkImageFilter>(SkDropShadowImageFilter::Create(
206 SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode), 206 10.0f, 5.0f, 3.0f, 3.0f, SK_ColorBLUE,
207 SkDropShadowImageFilter::kDrawShadowAndForeg round_ShadowMode)),
207 }; 208 };
208 209
209 SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64)); 210 SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64));
210 SkScalar MARGIN = SkIntToScalar(16); 211 SkScalar MARGIN = SkIntToScalar(16);
211 SkScalar DX = r.width() + MARGIN; 212 SkScalar DX = r.width() + MARGIN;
212 SkScalar DY = r.height() + MARGIN; 213 SkScalar DY = r.height() + MARGIN;
213 214
214 canvas->translate(MARGIN, MARGIN); 215 canvas->translate(MARGIN, MARGIN);
215 for (size_t i = 0; i < SK_ARRAY_COUNT(drawProc); ++i) { 216 for (size_t i = 0; i < SK_ARRAY_COUNT(drawProc); ++i) {
216 canvas->save(); 217 canvas->save();
217 for (size_t j = 0; j < SK_ARRAY_COUNT(filters); ++j) { 218 for (size_t j = 0; j < SK_ARRAY_COUNT(filters); ++j) {
218 drawProc[i](canvas, r, filters[j]); 219 drawProc[i](canvas, r, filters[j]);
219 220
220 draw_frame(canvas, r); 221 draw_frame(canvas, r);
221 canvas->translate(0, DY); 222 canvas->translate(0, DY);
222 } 223 }
223 canvas->restore(); 224 canvas->restore();
224 canvas->translate(DX, 0); 225 canvas->translate(DX, 0);
225 } 226 }
226
227 for(size_t j = 0; j < SK_ARRAY_COUNT(filters); ++j) {
228 SkSafeUnref(filters[j]);
229 }
230 } 227 }
231 228
232 private: 229 private:
233 typedef GM INHERITED; 230 typedef GM INHERITED;
234 }; 231 };
235 DEF_GM( return new ImageFiltersBaseGM; ) 232 DEF_GM( return new ImageFiltersBaseGM; )
236 233
237 /////////////////////////////////////////////////////////////////////////////// 234 ///////////////////////////////////////////////////////////////////////////////
238 235
239 /* 236 /*
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 315
319 class ImageFiltersText_CF : public ImageFiltersTextBaseGM { 316 class ImageFiltersText_CF : public ImageFiltersTextBaseGM {
320 public: 317 public:
321 ImageFiltersText_CF() : ImageFiltersTextBaseGM("color") {} 318 ImageFiltersText_CF() : ImageFiltersTextBaseGM("color") {}
322 319
323 void installFilter(SkPaint* paint) override { 320 void installFilter(SkPaint* paint) override {
324 paint->setColorFilter(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfer mode::kSrcIn_Mode)); 321 paint->setColorFilter(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfer mode::kSrcIn_Mode));
325 } 322 }
326 }; 323 };
327 DEF_GM( return new ImageFiltersText_CF; ) 324 DEF_GM( return new ImageFiltersText_CF; )
OLDNEW
« no previous file with comments | « gm/imagefilters.cpp ('k') | gm/imagefilterscropexpand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698