2015-03-06 14:15:20 +00:00
|
|
|
/*
|
|
|
|
* 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"
|
|
|
|
|
2016-01-22 17:45:14 +00:00
|
|
|
#ifdef SK_SUPPORT_LEGACY_DRAWFILTER
|
|
|
|
|
2015-03-06 14:15:20 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2015-04-12 02:29:31 +00:00
|
|
|
namespace {
|
2015-03-06 14:15:20 +00:00
|
|
|
class TestFilter : public SkDrawFilter {
|
|
|
|
public:
|
2015-03-26 01:17:31 +00:00
|
|
|
bool filter(SkPaint* p, Type) override {
|
2015-03-06 14:15:20 +00:00
|
|
|
p->setColor(SK_ColorRED);
|
2015-08-27 14:41:13 +00:00
|
|
|
p->setMaskFilter(nullptr);
|
2015-03-06 14:15:20 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
2015-04-12 02:29:31 +00:00
|
|
|
}
|
2015-03-06 14:15:20 +00:00
|
|
|
|
|
|
|
class DrawFilterGM : public skiagm::GM {
|
2016-04-04 17:02:58 +00:00
|
|
|
sk_sp<SkMaskFilter> fBlur;
|
2015-03-06 14:15:20 +00:00
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2015-03-06 14:15:20 +00:00
|
|
|
return SkISize::Make(320, 240);
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2015-03-06 14:15:20 +00:00
|
|
|
return SkString("drawfilter");
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
2016-04-04 17:02:58 +00:00
|
|
|
fBlur = SkBlurMaskFilter::Make(kNormal_SkBlurStyle,
|
2016-12-19 16:37:37 +00:00
|
|
|
SkBlurMask::ConvertRadiusToSigma(10.0f),
|
|
|
|
kLow_SkBlurQuality);
|
2015-03-06 14:15:20 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2015-03-06 14:15:20 +00:00
|
|
|
SkPaint p;
|
|
|
|
p.setColor(SK_ColorBLUE);
|
2016-04-04 17:02:58 +00:00
|
|
|
p.setMaskFilter(fBlur);
|
2015-03-06 14:15:20 +00:00
|
|
|
SkRect r = { 20, 20, 100, 100 };
|
2015-08-27 14:41:13 +00:00
|
|
|
canvas->setDrawFilter(nullptr);
|
2015-03-06 14:15:20 +00:00
|
|
|
canvas->drawRect(r, p);
|
2016-09-02 11:56:53 +00:00
|
|
|
canvas->setDrawFilter(new TestFilter)->unref();
|
2015-03-06 14:15:20 +00:00
|
|
|
canvas->translate(120.0f, 40.0f);
|
|
|
|
canvas->drawRect(r, p);
|
2015-08-27 14:41:13 +00:00
|
|
|
canvas->setDrawFilter(nullptr);
|
2015-03-06 14:15:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef GM INHERITED;
|
|
|
|
};
|
|
|
|
|
2015-12-10 21:31:59 +00:00
|
|
|
DEF_GM( return new DrawFilterGM; )
|
2015-03-06 14:15:20 +00:00
|
|
|
|
2016-01-22 17:45:14 +00:00
|
|
|
#endif
|