From cdf34cdfb930a876910cffd96f080fce55f003bd Mon Sep 17 00:00:00 2001 From: tomhudson Date: Fri, 6 Mar 2015 06:15:20 -0800 Subject: [PATCH] We had zero coverage for SkDrawFilter. This new GM draws two rectangles. If SkDrawFilter is working, they will not match (have different colors and one will be blurred). If SkDrawFilter is broken, they will match. R=scroggo@google.com Review URL: https://codereview.chromium.org/984883003 --- gm/drawfilter.cpp | 71 +++++++++++++++++++++++++++++++++++++++++++++++ gyp/gmslides.gypi | 1 + 2 files changed, 72 insertions(+) create mode 100644 gm/drawfilter.cpp diff --git a/gm/drawfilter.cpp b/gm/drawfilter.cpp new file mode 100644 index 0000000000..85bec15130 --- /dev/null +++ b/gm/drawfilter.cpp @@ -0,0 +1,71 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "gm.h" +#include "SkBlurMask.h" +#include "SkBlurMaskFilter.h" +#include "SkCanvas.h" +#include "SkDrawFilter.h" +#include "SkPaint.h" + +/** + * Initial test coverage for SkDrawFilter. + * Draws two rectangles; if draw filters are broken, they will match. + * If draw filters are working correctly, the first will be blue and blurred, + * the second red and sharp. + */ + +class TestFilter : public SkDrawFilter { +public: + bool filter(SkPaint* p, Type) SK_OVERRIDE { + p->setColor(SK_ColorRED); + p->setMaskFilter(NULL); + return true; + } +}; + +class DrawFilterGM : public skiagm::GM { + SkAutoTUnref fBlur; + +protected: + SkISize onISize() SK_OVERRIDE { + return SkISize::Make(320, 240); + } + + SkString onShortName() SK_OVERRIDE { + return SkString("drawfilter"); + } + + void onOnceBeforeDraw() SK_OVERRIDE { + fBlur.reset(SkBlurMaskFilter::Create(kNormal_SkBlurStyle, + SkBlurMask::ConvertRadiusToSigma(10.0f), + kLow_SkBlurQuality)); + } + + void onDraw(SkCanvas* canvas) SK_OVERRIDE { + SkPaint p; + p.setColor(SK_ColorBLUE); + p.setMaskFilter(fBlur.get()); + SkRect r = { 20, 20, 100, 100 }; + canvas->setDrawFilter(NULL); + canvas->drawRect(r, p); + TestFilter redNoBlur; + canvas->setDrawFilter(&redNoBlur); + canvas->translate(120.0f, 40.0f); + canvas->drawRect(r, p); + + // Must unset if the DrawFilter is from the stack to avoid refcount errors! + canvas->setDrawFilter(NULL); + } + +private: + typedef GM INHERITED; +}; + +static skiagm::GM* MyFactory(void*) { return new DrawFilterGM; } +static skiagm::GMRegistry reg(MyFactory); + diff --git a/gyp/gmslides.gypi b/gyp/gmslides.gypi index 739f8feaef..6ebfe30289 100644 --- a/gyp/gmslides.gypi +++ b/gyp/gmslides.gypi @@ -77,6 +77,7 @@ '../gm/displacement.cpp', '../gm/downsamplebitmap.cpp', '../gm/drawbitmaprect.cpp', + '../gm/drawfilter.cpp', '../gm/drawlooper.cpp', '../gm/dropshadowimagefilter.cpp', '../gm/drrect.cpp',