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

Side by Side Diff: samplecode/SampleLayers.cpp

Issue 1860573002: Update SkMorphology ImageFilters 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 | « samplecode/SampleFilterFuzz.cpp ('k') | src/effects/SkMorphologyImageFilter.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 "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkView.h" 9 #include "SkView.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 #include "SkMatrixConvolutionImageFilter.h" 238 #include "SkMatrixConvolutionImageFilter.h"
239 #include "SkMorphologyImageFilter.h" 239 #include "SkMorphologyImageFilter.h"
240 240
241 #include "Resources.h" 241 #include "Resources.h"
242 #include "SkAnimTimer.h" 242 #include "SkAnimTimer.h"
243 243
244 class BackdropView : public SampleView { 244 class BackdropView : public SampleView {
245 SkPoint fCenter; 245 SkPoint fCenter;
246 SkScalar fAngle; 246 SkScalar fAngle;
247 sk_sp<SkImage> fImage; 247 sk_sp<SkImage> fImage;
248 SkAutoTUnref<SkImageFilter> fFilter; 248 sk_sp<SkImageFilter> fFilter;
249 public: 249 public:
250 BackdropView() { 250 BackdropView() {
251 fCenter.set(200, 150); 251 fCenter.set(200, 150);
252 fAngle = 0; 252 fAngle = 0;
253 fImage = GetResourceAsImage("mandrill_512.png"); 253 fImage = GetResourceAsImage("mandrill_512.png");
254 fFilter.reset(SkDilateImageFilter::Create(8, 8)); 254 fFilter = SkDilateImageFilter::Make(8, 8, nullptr);
255 } 255 }
256 256
257 protected: 257 protected:
258 // overrides from SkEventSink 258 // overrides from SkEventSink
259 bool onQuery(SkEvent* evt) override { 259 bool onQuery(SkEvent* evt) override {
260 if (SampleCode::TitleQ(*evt)) { 260 if (SampleCode::TitleQ(*evt)) {
261 SampleCode::TitleR(evt, "Backdrop"); 261 SampleCode::TitleR(evt, "Backdrop");
262 return true; 262 return true;
263 } 263 }
264 return this->INHERITED::onQuery(evt); 264 return this->INHERITED::onQuery(evt);
265 } 265 }
266 266
267 void onDrawContent(SkCanvas* canvas) override { 267 void onDrawContent(SkCanvas* canvas) override {
268 canvas->drawImage(fImage.get(), 0, 0, nullptr); 268 canvas->drawImage(fImage.get(), 0, 0, nullptr);
269 269
270 const SkScalar w = 250; 270 const SkScalar w = 250;
271 const SkScalar h = 150; 271 const SkScalar h = 150;
272 SkPath path; 272 SkPath path;
273 path.addOval(SkRect::MakeXYWH(-w/2, -h/2, w, h)); 273 path.addOval(SkRect::MakeXYWH(-w/2, -h/2, w, h));
274 SkMatrix m; 274 SkMatrix m;
275 m.setRotate(fAngle); 275 m.setRotate(fAngle);
276 m.postTranslate(fCenter.x(), fCenter.y()); 276 m.postTranslate(fCenter.x(), fCenter.y());
277 path.transform(m); 277 path.transform(m);
278 278
279 canvas->clipPath(path, SkRegion::kIntersect_Op, true); 279 canvas->clipPath(path, SkRegion::kIntersect_Op, true);
280 const SkRect bounds = path.getBounds(); 280 const SkRect bounds = path.getBounds();
281 281
282 SkPaint paint; 282 SkPaint paint;
283 paint.setAlpha(0xCC); 283 paint.setAlpha(0xCC);
284 canvas->saveLayer({ &bounds, &paint, fFilter, 0 }); 284 canvas->saveLayer({ &bounds, &paint, fFilter.get(), 0 });
285 285
286 canvas->restore(); 286 canvas->restore();
287 } 287 }
288 288
289 bool onAnimate(const SkAnimTimer& timer) override { 289 bool onAnimate(const SkAnimTimer& timer) override {
290 fAngle = SkDoubleToScalar(fmod(timer.secs() * 360 / 5, 360)); 290 fAngle = SkDoubleToScalar(fmod(timer.secs() * 360 / 5, 360));
291 return true; 291 return true;
292 } 292 }
293 293
294 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove rride { 294 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove rride {
295 this->inval(nullptr); 295 this->inval(nullptr);
296 return new Click(this); 296 return new Click(this);
297 } 297 }
298 298
299 bool onClick(Click* click) override { 299 bool onClick(Click* click) override {
300 this->inval(nullptr); 300 this->inval(nullptr);
301 fCenter = click->fCurr; 301 fCenter = click->fCurr;
302 return this->INHERITED::onClick(click); 302 return this->INHERITED::onClick(click);
303 } 303 }
304 304
305 private: 305 private:
306 typedef SampleView INHERITED; 306 typedef SampleView INHERITED;
307 }; 307 };
308 DEF_SAMPLE( return new BackdropView; ) 308 DEF_SAMPLE( return new BackdropView; )
OLDNEW
« no previous file with comments | « samplecode/SampleFilterFuzz.cpp ('k') | src/effects/SkMorphologyImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698