2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "Benchmark.h"
|
2013-09-06 14:16:12 +00:00
|
|
|
#include "SkBlurMask.h"
|
2011-07-14 19:03:58 +00:00
|
|
|
#include "SkCanvas.h"
|
2018-03-14 17:01:17 +00:00
|
|
|
#include "SkMaskFilter.h"
|
2011-07-14 19:03:58 +00:00
|
|
|
#include "SkPaint.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkShader.h"
|
|
|
|
#include "SkString.h"
|
|
|
|
|
2018-08-20 18:22:16 +00:00
|
|
|
#define MINI 0.01f
|
2011-07-14 19:03:58 +00:00
|
|
|
#define SMALL SkIntToScalar(2)
|
2017-11-16 21:43:26 +00:00
|
|
|
#define REAL 0.5f
|
2011-07-14 19:03:58 +00:00
|
|
|
#define BIG SkIntToScalar(10)
|
2013-11-25 19:44:07 +00:00
|
|
|
#define REALBIG 100.5f
|
2017-11-16 21:43:26 +00:00
|
|
|
// The value that produces a sigma of just over 2.
|
|
|
|
#define CUTOVER 2.6f
|
2011-07-14 19:03:58 +00:00
|
|
|
|
|
|
|
static const char* gStyleName[] = {
|
|
|
|
"normal",
|
|
|
|
"solid",
|
|
|
|
"outer",
|
|
|
|
"inner"
|
|
|
|
};
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class BlurBench : public Benchmark {
|
2011-07-14 19:03:58 +00:00
|
|
|
SkScalar fRadius;
|
2014-04-28 16:25:35 +00:00
|
|
|
SkBlurStyle fStyle;
|
2011-07-14 19:03:58 +00:00
|
|
|
SkString fName;
|
|
|
|
|
|
|
|
public:
|
2018-03-14 17:01:17 +00:00
|
|
|
BlurBench(SkScalar rad, SkBlurStyle bs) {
|
2011-07-14 19:03:58 +00:00
|
|
|
fRadius = rad;
|
|
|
|
fStyle = bs;
|
|
|
|
const char* name = rad > 0 ? gStyleName[bs] : "none";
|
2018-03-14 17:01:17 +00:00
|
|
|
const char* quality = "high_quality";
|
2011-11-22 15:58:06 +00:00
|
|
|
if (SkScalarFraction(rad) != 0) {
|
2012-11-29 17:09:27 +00:00
|
|
|
fName.printf("blur_%.2f_%s_%s", SkScalarToFloat(rad), name, quality);
|
2011-11-22 15:58:06 +00:00
|
|
|
} else {
|
2013-12-17 19:22:07 +00:00
|
|
|
fName.printf("blur_%d_%s_%s", SkScalarRoundToInt(rad), name, quality);
|
2011-11-22 15:58:06 +00:00
|
|
|
}
|
2011-07-14 19:03:58 +00:00
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2011-07-14 19:03:58 +00:00
|
|
|
protected:
|
2018-08-20 18:22:16 +00:00
|
|
|
const char* onGetName() override {
|
2011-07-14 19:03:58 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2018-08-20 18:22:16 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2011-07-14 19:03:58 +00:00
|
|
|
SkPaint paint;
|
|
|
|
this->setupPaint(&paint);
|
|
|
|
|
|
|
|
paint.setAntiAlias(true);
|
|
|
|
|
2013-09-09 20:09:12 +00:00
|
|
|
SkRandom rand;
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2011-07-14 19:03:58 +00:00
|
|
|
SkRect r = SkRect::MakeWH(rand.nextUScalar1() * 400,
|
|
|
|
rand.nextUScalar1() * 400);
|
|
|
|
r.offset(fRadius, fRadius);
|
|
|
|
|
|
|
|
if (fRadius > 0) {
|
2018-03-14 17:01:17 +00:00
|
|
|
paint.setMaskFilter(SkMaskFilter::MakeBlur(fStyle,
|
|
|
|
SkBlurMask::ConvertRadiusToSigma(fRadius)));
|
2011-07-14 19:03:58 +00:00
|
|
|
}
|
|
|
|
canvas->drawOval(r, paint);
|
|
|
|
}
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2011-07-14 19:03:58 +00:00
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2011-07-14 19:03:58 +00:00
|
|
|
};
|
|
|
|
|
2014-08-11 20:55:34 +00:00
|
|
|
DEF_BENCH(return new BlurBench(MINI, kNormal_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(MINI, kSolid_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(MINI, kOuter_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(MINI, kInner_SkBlurStyle);)
|
|
|
|
|
2014-04-28 16:25:35 +00:00
|
|
|
DEF_BENCH(return new BlurBench(SMALL, kNormal_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(SMALL, kSolid_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(SMALL, kOuter_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(SMALL, kInner_SkBlurStyle);)
|
2012-11-08 20:51:57 +00:00
|
|
|
|
2014-04-28 16:25:35 +00:00
|
|
|
DEF_BENCH(return new BlurBench(BIG, kNormal_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(BIG, kSolid_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(BIG, kOuter_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(BIG, kInner_SkBlurStyle);)
|
2012-11-08 20:51:57 +00:00
|
|
|
|
2014-04-28 16:25:35 +00:00
|
|
|
DEF_BENCH(return new BlurBench(REALBIG, kNormal_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(REALBIG, kSolid_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(REALBIG, kOuter_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(REALBIG, kInner_SkBlurStyle);)
|
2012-11-29 17:09:27 +00:00
|
|
|
|
2014-04-28 16:25:35 +00:00
|
|
|
DEF_BENCH(return new BlurBench(REAL, kNormal_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(REAL, kSolid_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(REAL, kOuter_SkBlurStyle);)
|
|
|
|
DEF_BENCH(return new BlurBench(REAL, kInner_SkBlurStyle);)
|
2012-11-08 20:51:57 +00:00
|
|
|
|
2014-04-28 16:25:35 +00:00
|
|
|
DEF_BENCH(return new BlurBench(0, kNormal_SkBlurStyle);)
|