• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifdef SK_SUPPORT_LEGACY_DRAWFILTER
16 
17 /**
18  * Initial test coverage for SkDrawFilter.
19  * Draws two rectangles; if draw filters are broken, they will match.
20  * If draw filters are working correctly, the first will be blue and blurred,
21  * the second red and sharp.
22  */
23 
24 namespace {
25 class TestFilter : public SkDrawFilter {
26 public:
filter(SkPaint * p,Type)27     bool filter(SkPaint* p, Type) override {
28         p->setColor(SK_ColorRED);
29         p->setMaskFilter(nullptr);
30         return true;
31     }
32 };
33 }
34 
35 class DrawFilterGM : public skiagm::GM {
36     sk_sp<SkMaskFilter> fBlur;
37 
38 protected:
onISize()39     SkISize onISize() override {
40         return SkISize::Make(320, 240);
41     }
42 
onShortName()43     SkString onShortName() override {
44         return SkString("drawfilter");
45     }
46 
onOnceBeforeDraw()47     void onOnceBeforeDraw() override {
48         fBlur = SkBlurMaskFilter::Make(kNormal_SkBlurStyle,
49                                        SkBlurMask::ConvertRadiusToSigma(10.0f),
50                                        kLow_SkBlurQuality);
51     }
52 
onDraw(SkCanvas * canvas)53     void onDraw(SkCanvas* canvas) override {
54         SkPaint p;
55         p.setColor(SK_ColorBLUE);
56         p.setMaskFilter(fBlur);
57         SkRect r = { 20, 20, 100, 100 };
58         canvas->setDrawFilter(nullptr);
59         canvas->drawRect(r, p);
60         canvas->setDrawFilter(new TestFilter)->unref();
61         canvas->translate(120.0f, 40.0f);
62         canvas->drawRect(r, p);
63         canvas->setDrawFilter(nullptr);
64     }
65 
66 private:
67     typedef GM INHERITED;
68 };
69 
70 DEF_GM( return new DrawFilterGM; )
71 
72 #endif
73