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

Side by Side Diff: samplecode/SampleLayers.cpp

Issue 1565203002: Revert of add backdrop option to SaveLayerRec (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 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/SampleApp.cpp ('k') | src/core/SkCanvas.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 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 } 225 }
226 226
227 virtual bool handleKey(SkKey) { 227 virtual bool handleKey(SkKey) {
228 this->inval(nullptr); 228 this->inval(nullptr);
229 return true; 229 return true;
230 } 230 }
231 231
232 private: 232 private:
233 typedef SkView INHERITED; 233 typedef SkView INHERITED;
234 }; 234 };
235 DEF_SAMPLE( return new LayersView; )
236 235
237 ////////////////////////////////////////////////////////////////////////////// 236 //////////////////////////////////////////////////////////////////////////////
238 237
239 #include "SkBlurImageFilter.h" 238 static SkView* MyFactory() { return new LayersView; }
240 #include "SkMatrixConvolutionImageFilter.h" 239 static SkViewRegister reg(MyFactory);
241 #include "SkMorphologyImageFilter.h"
242
243 #include "Resources.h"
244 #include "SkAnimTimer.h"
245
246 class BackdropView : public SampleView {
247 SkPoint fCenter;
248 SkScalar fAngle;
249 SkAutoTUnref<SkImage> fImage;
250 SkAutoTUnref<SkImageFilter> fFilter;
251 public:
252 BackdropView() {
253 fCenter.set(200, 150);
254 fAngle = 0;
255 fImage.reset(GetResourceAsImage("mandrill_512.png"));
256 fFilter.reset(SkDilateImageFilter::Create(8, 8));
257 }
258
259 protected:
260 // overrides from SkEventSink
261 bool onQuery(SkEvent* evt) override {
262 if (SampleCode::TitleQ(*evt)) {
263 SampleCode::TitleR(evt, "Backdrop");
264 return true;
265 }
266 return this->INHERITED::onQuery(evt);
267 }
268
269 void onDrawContent(SkCanvas* canvas) override {
270 canvas->drawImage(fImage, 0, 0, nullptr);
271
272 const SkScalar w = 250;
273 const SkScalar h = 150;
274 SkPath path;
275 path.addOval(SkRect::MakeXYWH(-w/2, -h/2, w, h));
276 SkMatrix m;
277 m.setRotate(fAngle);
278 m.postTranslate(fCenter.x(), fCenter.y());
279 path.transform(m);
280
281 canvas->clipPath(path, SkRegion::kIntersect_Op, true);
282 const SkRect bounds = path.getBounds();
283
284 SkPaint paint;
285 paint.setAlpha(0xCC);
286 canvas->saveLayer({ &bounds, &paint, fFilter, 0 });
287
288 canvas->restore();
289 }
290
291 bool onAnimate(const SkAnimTimer& timer) override {
292 fAngle = SkDoubleToScalar(fmod(timer.secs() * 360 / 5, 360));
293 return true;
294 }
295
296 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove rride {
297 this->inval(nullptr);
298 return new Click(this);
299 }
300
301 bool onClick(Click* click) override {
302 this->inval(nullptr);
303 fCenter = click->fCurr;
304 return this->INHERITED::onClick(click);
305 }
306
307 private:
308 typedef SampleView INHERITED;
309 };
310 DEF_SAMPLE( return new BackdropView; )
311
OLDNEW
« no previous file with comments | « samplecode/SampleApp.cpp ('k') | src/core/SkCanvas.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698