• Home
  • History
  • Annotate
  • 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 /**
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 namespace {
23 class TestFilter : public SkDrawFilter {
24 public:
filter(SkPaint * p,Type)25     bool filter(SkPaint* p, Type) override {
26         p->setColor(SK_ColorRED);
27         p->setMaskFilter(NULL);
28         return true;
29     }
30 };
31 }
32 
33 class DrawFilterGM : public skiagm::GM {
34     SkAutoTUnref<SkMaskFilter> fBlur;
35 
36 protected:
onISize()37     SkISize onISize() override {
38         return SkISize::Make(320, 240);
39     }
40 
onShortName()41     SkString onShortName() override {
42         return SkString("drawfilter");
43     }
44 
onOnceBeforeDraw()45     void onOnceBeforeDraw() override {
46         fBlur.reset(SkBlurMaskFilter::Create(kNormal_SkBlurStyle,
47                     SkBlurMask::ConvertRadiusToSigma(10.0f),
48                     kLow_SkBlurQuality));
49     }
50 
onDraw(SkCanvas * canvas)51     void onDraw(SkCanvas* canvas) override {
52         SkPaint p;
53         p.setColor(SK_ColorBLUE);
54         p.setMaskFilter(fBlur.get());
55         SkRect r = { 20, 20, 100, 100 };
56         canvas->setDrawFilter(NULL);
57         canvas->drawRect(r, p);
58         TestFilter redNoBlur;
59         canvas->setDrawFilter(&redNoBlur);
60         canvas->translate(120.0f, 40.0f);
61         canvas->drawRect(r, p);
62 
63         // Must unset if the DrawFilter is from the stack to avoid refcount errors!
64         canvas->setDrawFilter(NULL);
65     }
66 
67 private:
68     typedef GM INHERITED;
69 };
70 
MyFactory(void *)71 static skiagm::GM* MyFactory(void*) { return new DrawFilterGM; }
72 static skiagm::GMRegistry reg(MyFactory);
73 
74