2014-05-07 17:50:03 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 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 "SkPaint.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
|
|
|
|
class BlurCirclesGM : public skiagm::GM {
|
|
|
|
public:
|
2015-09-15 17:20:55 +00:00
|
|
|
BlurCirclesGM() { }
|
2014-05-07 17:50:03 +00:00
|
|
|
|
|
|
|
protected:
|
2015-09-15 17:20:55 +00:00
|
|
|
bool runAsBench() const override { return true; }
|
2014-05-07 17:50:03 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkString onShortName() override {
|
2015-09-15 17:20:55 +00:00
|
|
|
return SkString("blurcircles");
|
2014-05-07 17:50:03 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkISize onISize() override {
|
2014-05-07 17:50:03 +00:00
|
|
|
return SkISize::Make(950, 950);
|
|
|
|
}
|
|
|
|
|
2015-09-15 17:20:55 +00:00
|
|
|
void onOnceBeforeDraw() override {
|
|
|
|
const float blurRadii[kNumBlurs] = { 1,5,10,20 };
|
|
|
|
|
|
|
|
for (int i = 0; i < kNumBlurs; ++i) {
|
2016-04-04 17:02:58 +00:00
|
|
|
fBlurFilters[i] = SkBlurMaskFilter::Make(
|
2015-09-15 17:20:55 +00:00
|
|
|
kNormal_SkBlurStyle,
|
|
|
|
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(blurRadii[i])),
|
2016-04-04 17:02:58 +00:00
|
|
|
SkBlurMaskFilter::kHighQuality_BlurFlag);
|
2015-09-15 17:20:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void onDraw(SkCanvas* canvas) override {
|
2014-05-07 17:50:03 +00:00
|
|
|
canvas->scale(1.5f, 1.5f);
|
|
|
|
canvas->translate(50,50);
|
|
|
|
|
|
|
|
const int circleRadii[] = { 5,10,25,50 };
|
2015-09-15 17:20:55 +00:00
|
|
|
|
|
|
|
for (size_t i = 0; i < kNumBlurs; ++i) {
|
2014-05-07 17:50:03 +00:00
|
|
|
SkAutoCanvasRestore autoRestore(canvas, true);
|
|
|
|
canvas->translate(0, SkIntToScalar(150*i));
|
|
|
|
for (size_t j = 0; j < SK_ARRAY_COUNT(circleRadii); ++j) {
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setColor(SK_ColorBLACK);
|
2015-09-15 17:20:55 +00:00
|
|
|
paint.setMaskFilter(fBlurFilters[i]);
|
2014-05-07 17:50:03 +00:00
|
|
|
|
|
|
|
canvas->drawCircle(SkIntToScalar(50),SkIntToScalar(50),SkIntToScalar(circleRadii[j]),paint);
|
|
|
|
canvas->translate(SkIntToScalar(150), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
2015-09-15 17:20:55 +00:00
|
|
|
static const int kNumBlurs = 4;
|
|
|
|
|
2016-04-04 17:02:58 +00:00
|
|
|
sk_sp<SkMaskFilter> fBlurFilters[kNumBlurs];
|
2014-05-07 17:50:03 +00:00
|
|
|
|
|
|
|
typedef skiagm::GM INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_GM(return new BlurCirclesGM();)
|