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