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

Side by Side Diff: gm/drawfilter.cpp

Issue 984883003: New GM to test SkDrawFilter (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Leon's review Created 5 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 | « no previous file | gyp/gmslides.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "gm.h"
9 #include "SkBlurMask.h"
10 #include "SkBlurMaskFilter.h"
11 #include "SkCanvas.h"
12 #include "SkDrawFilter.h"
13 #include "SkPaint.h"
14
15 /**
16 * Initial test coverage for SkDrawFilter.
17 * Draws two rectangles; if draw filters are broken, they will match.
18 * If draw filters are working correctly, the first will be blue and blurred,
19 * the second red and sharp.
20 */
21
22 class TestFilter : public SkDrawFilter {
23 public:
24 bool filter(SkPaint* p, Type) SK_OVERRIDE {
25 p->setColor(SK_ColorRED);
26 p->setMaskFilter(NULL);
27 return true;
28 }
29 };
30
31 class DrawFilterGM : public skiagm::GM {
32 SkAutoTUnref<SkMaskFilter> fBlur;
33
34 protected:
35 SkISize onISize() SK_OVERRIDE {
36 return SkISize::Make(320, 240);
37 }
38
39 SkString onShortName() SK_OVERRIDE {
40 return SkString("drawfilter");
41 }
42
43 void onOnceBeforeDraw() SK_OVERRIDE {
44 fBlur.reset(SkBlurMaskFilter::Create(kNormal_SkBlurStyle,
45 SkBlurMask::ConvertRadiusToSigma(10.0f),
46 kLow_SkBlurQuality));
47 }
48
49 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
50 SkPaint p;
51 p.setColor(SK_ColorBLUE);
52 p.setMaskFilter(fBlur.get());
53 SkRect r = { 20, 20, 100, 100 };
54 canvas->setDrawFilter(NULL);
55 canvas->drawRect(r, p);
56 TestFilter redNoBlur;
57 canvas->setDrawFilter(&redNoBlur);
58 canvas->translate(120.0f, 40.0f);
59 canvas->drawRect(r, p);
60
61 // Must unset if the DrawFilter is from the stack to avoid refcount erro rs!
62 canvas->setDrawFilter(NULL);
63 }
64
65 private:
66 typedef GM INHERITED;
67 };
68
69 static skiagm::GM* MyFactory(void*) { return new DrawFilterGM; }
70 static skiagm::GMRegistry reg(MyFactory);
71
OLDNEW
« no previous file with comments | « no previous file | gyp/gmslides.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698