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 {
|
2020-09-23 15:37:13 +00:00
|
|
|
const float blurRadii[kNumBlurs] = {1.f, 5.f, 10.f, 20.f};
|
2015-09-15 17:20:55 +00:00
|
|
|
|
|
|
|
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,
|
2020-09-23 15:37:13 +00:00
|
|
|
SkBlurMask::ConvertRadiusToSigma(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);
|
|
|
|
|
2020-09-23 15:37:13 +00:00
|
|
|
const float circleRadii[] = {5.f, 10.f, 25.f, 50.f};
|
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);
|
2020-09-23 15:37:13 +00:00
|
|
|
canvas->translate(0, 150.f*i);
|
2014-05-07 17:50:03 +00:00
|
|
|
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
|
|
|
|
2020-09-23 15:37:13 +00:00
|
|
|
static constexpr SkPoint kCenter = {50.f, 50.f};
|
|
|
|
// Throw a rotation in the mix to make sure GPU fast path handles it correctly.
|
|
|
|
canvas->save();
|
|
|
|
canvas->rotate(j*22.f, kCenter.fX, kCenter.fY);
|
|
|
|
canvas->drawCircle(kCenter, circleRadii[j], paint);
|
|
|
|
canvas->restore();
|
|
|
|
canvas->translate(150.f, 0.f);
|
2014-05-07 17:50:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
2021-10-08 22:48:26 +00:00
|
|
|
inline 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
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = skiagm::GM;
|
2014-05-07 17:50:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DEF_GM(return new BlurCirclesGM();)
|