2 * Copyright 2015 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #include "SkBlurMask.h"
10 #include "SkBlurMaskFilter.h"
12 #include "SkDrawFilter.h"
15 #ifdef SK_SUPPORT_LEGACY_DRAWFILTER
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.
25 class TestFilter : public SkDrawFilter {
27 bool filter(SkPaint* p, Type) override {
28 p->setColor(SK_ColorRED);
29 p->setMaskFilter(nullptr);
35 class DrawFilterGM : public skiagm::GM {
36 sk_sp<SkMaskFilter> fBlur;
39 SkISize onISize() override {
40 return SkISize::Make(320, 240);
43 SkString onShortName() override {
44 return SkString("drawfilter");
47 void onOnceBeforeDraw() override {
48 fBlur = SkBlurMaskFilter::Make(kNormal_SkBlurStyle,
49 SkBlurMask::ConvertRadiusToSigma(10.0f),
53 void onDraw(SkCanvas* canvas) override {
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);
70 DEF_GM( return new DrawFilterGM; )