skia2/gm/drawfilter.cpp
Robert Phillips 98624d249d "Fix" some ImageFilter fuzzer issues
SkClipOp.h & SkPictureFlat.h
   Invalid SkClipOps were getting through - the question here is where (for a class enum) is a good place to put the k*Mask definition.

SkPath1DPathEffect
   NaNs were getting past.

SkBlurMaskFilter
   Assert wasn't necessary since we whacked the flag on the next line.

Change-Id: I87f95ad39f4760284f881d7c4500eb82fcdba282
Reviewed-on: https://skia-review.googlesource.com/6194
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Herb Derby <herb@google.com>
2016-12-19 17:14:10 +00:00

73 lines
1.7 KiB
C++

/*
* 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"
#ifdef SK_SUPPORT_LEGACY_DRAWFILTER
/**
* 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.
*/
namespace {
class TestFilter : public SkDrawFilter {
public:
bool filter(SkPaint* p, Type) override {
p->setColor(SK_ColorRED);
p->setMaskFilter(nullptr);
return true;
}
};
}
class DrawFilterGM : public skiagm::GM {
sk_sp<SkMaskFilter> fBlur;
protected:
SkISize onISize() override {
return SkISize::Make(320, 240);
}
SkString onShortName() override {
return SkString("drawfilter");
}
void onOnceBeforeDraw() override {
fBlur = SkBlurMaskFilter::Make(kNormal_SkBlurStyle,
SkBlurMask::ConvertRadiusToSigma(10.0f),
kLow_SkBlurQuality);
}
void onDraw(SkCanvas* canvas) override {
SkPaint p;
p.setColor(SK_ColorBLUE);
p.setMaskFilter(fBlur);
SkRect r = { 20, 20, 100, 100 };
canvas->setDrawFilter(nullptr);
canvas->drawRect(r, p);
canvas->setDrawFilter(new TestFilter)->unref();
canvas->translate(120.0f, 40.0f);
canvas->drawRect(r, p);
canvas->setDrawFilter(nullptr);
}
private:
typedef GM INHERITED;
};
DEF_GM( return new DrawFilterGM; )
#endif