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.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "gm/gm.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "include/core/SkBlurTypes.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "include/core/SkColor.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkMaskFilter.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "include/core/SkRefCnt.h"
|
|
|
|
#include "include/core/SkScalar.h"
|
|
|
|
#include "include/core/SkSize.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkString.h"
|
2019-05-01 14:59:30 +00:00
|
|
|
#include "include/core/SkTypes.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkBlurMask.h"
|
2014-05-07 17:50:03 +00:00
|
|
|
|
|
|
|
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) {
|
2018-03-14 17:01:17 +00:00
|
|
|
fBlurFilters[i] = SkMaskFilter::MakeBlur(
|
2015-09-15 17:20:55 +00:00
|
|
|
kNormal_SkBlurStyle,
|
2018-03-14 17:01:17 +00:00
|
|
|
SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(blurRadii[i])));
|
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:
|
2016-09-01 18:24:54 +00:00
|
|
|
static constexpr int kNumBlurs = 4;
|
2015-09-15 17:20:55 +00:00
|
|
|
|
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();)
|