blob: df4cd8f5c48548aceabae6962d0da8b62479cc50 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
Mike Kleinc0bd9f92019-04-23 12:05:21 -05007#include "bench/Benchmark.h"
8#include "include/core/SkCanvas.h"
9#include "include/core/SkMaskFilter.h"
10#include "include/core/SkPaint.h"
11#include "include/core/SkShader.h"
12#include "include/core/SkString.h"
13#include "include/utils/SkRandom.h"
14#include "src/core/SkBlurMask.h"
reed@google.com25df8882011-07-14 19:03:58 +000015
Robert Phillips15e60a42018-08-20 14:22:16 -040016#define MINI 0.01f
reed@google.com25df8882011-07-14 19:03:58 +000017#define SMALL SkIntToScalar(2)
Herb Derby35c556f2017-11-16 21:43:26 +000018#define REAL 0.5f
reed@google.com25df8882011-07-14 19:03:58 +000019#define BIG SkIntToScalar(10)
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +000020#define REALBIG 100.5f
Herb Derby35c556f2017-11-16 21:43:26 +000021// The value that produces a sigma of just over 2.
22#define CUTOVER 2.6f
reed@google.com25df8882011-07-14 19:03:58 +000023
24static const char* gStyleName[] = {
25 "normal",
26 "solid",
27 "outer",
28 "inner"
29};
30
tfarinaf168b862014-06-19 12:32:29 -070031class BlurBench : public Benchmark {
reed@google.com25df8882011-07-14 19:03:58 +000032 SkScalar fRadius;
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000033 SkBlurStyle fStyle;
reed@google.com25df8882011-07-14 19:03:58 +000034 SkString fName;
35
36public:
Mike Reed1be1f8d2018-03-14 13:01:17 -040037 BlurBench(SkScalar rad, SkBlurStyle bs) {
reed@google.com25df8882011-07-14 19:03:58 +000038 fRadius = rad;
39 fStyle = bs;
40 const char* name = rad > 0 ? gStyleName[bs] : "none";
Mike Reed1be1f8d2018-03-14 13:01:17 -040041 const char* quality = "high_quality";
tomhudson@google.com8caac642011-11-22 15:58:06 +000042 if (SkScalarFraction(rad) != 0) {
senorblanco@chromium.org91f489a2012-11-29 17:09:27 +000043 fName.printf("blur_%.2f_%s_%s", SkScalarToFloat(rad), name, quality);
tomhudson@google.com8caac642011-11-22 15:58:06 +000044 } else {
reed@google.come1ca7052013-12-17 19:22:07 +000045 fName.printf("blur_%d_%s_%s", SkScalarRoundToInt(rad), name, quality);
tomhudson@google.com8caac642011-11-22 15:58:06 +000046 }
reed@google.com25df8882011-07-14 19:03:58 +000047 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000048
reed@google.com25df8882011-07-14 19:03:58 +000049protected:
Robert Phillips15e60a42018-08-20 14:22:16 -040050 const char* onGetName() override {
reed@google.com25df8882011-07-14 19:03:58 +000051 return fName.c_str();
52 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000053
Robert Phillips15e60a42018-08-20 14:22:16 -040054 void onDraw(int loops, SkCanvas* canvas) override {
reed@google.com25df8882011-07-14 19:03:58 +000055 SkPaint paint;
56 this->setupPaint(&paint);
57
58 paint.setAntiAlias(true);
59
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +000060 SkRandom rand;
commit-bot@chromium.org33614712013-12-03 18:17:16 +000061 for (int i = 0; i < loops; i++) {
reed@google.com25df8882011-07-14 19:03:58 +000062 SkRect r = SkRect::MakeWH(rand.nextUScalar1() * 400,
63 rand.nextUScalar1() * 400);
64 r.offset(fRadius, fRadius);
65
66 if (fRadius > 0) {
Mike Reed1be1f8d2018-03-14 13:01:17 -040067 paint.setMaskFilter(SkMaskFilter::MakeBlur(fStyle,
68 SkBlurMask::ConvertRadiusToSigma(fRadius)));
reed@google.com25df8882011-07-14 19:03:58 +000069 }
70 canvas->drawOval(r, paint);
71 }
72 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000073
reed@google.com25df8882011-07-14 19:03:58 +000074private:
John Stiles7571f9e2020-09-02 22:42:33 -040075 using INHERITED = Benchmark;
reed@google.com25df8882011-07-14 19:03:58 +000076};
77
joshualitt5acfea72014-08-11 13:55:34 -070078DEF_BENCH(return new BlurBench(MINI, kNormal_SkBlurStyle);)
79DEF_BENCH(return new BlurBench(MINI, kSolid_SkBlurStyle);)
80DEF_BENCH(return new BlurBench(MINI, kOuter_SkBlurStyle);)
81DEF_BENCH(return new BlurBench(MINI, kInner_SkBlurStyle);)
82
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000083DEF_BENCH(return new BlurBench(SMALL, kNormal_SkBlurStyle);)
84DEF_BENCH(return new BlurBench(SMALL, kSolid_SkBlurStyle);)
85DEF_BENCH(return new BlurBench(SMALL, kOuter_SkBlurStyle);)
86DEF_BENCH(return new BlurBench(SMALL, kInner_SkBlurStyle);)
reed@google.com25df8882011-07-14 19:03:58 +000087
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000088DEF_BENCH(return new BlurBench(BIG, kNormal_SkBlurStyle);)
89DEF_BENCH(return new BlurBench(BIG, kSolid_SkBlurStyle);)
90DEF_BENCH(return new BlurBench(BIG, kOuter_SkBlurStyle);)
91DEF_BENCH(return new BlurBench(BIG, kInner_SkBlurStyle);)
reed@google.com25df8882011-07-14 19:03:58 +000092
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000093DEF_BENCH(return new BlurBench(REALBIG, kNormal_SkBlurStyle);)
94DEF_BENCH(return new BlurBench(REALBIG, kSolid_SkBlurStyle);)
95DEF_BENCH(return new BlurBench(REALBIG, kOuter_SkBlurStyle);)
96DEF_BENCH(return new BlurBench(REALBIG, kInner_SkBlurStyle);)
senorblanco@chromium.org91f489a2012-11-29 17:09:27 +000097
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000098DEF_BENCH(return new BlurBench(REAL, kNormal_SkBlurStyle);)
99DEF_BENCH(return new BlurBench(REAL, kSolid_SkBlurStyle);)
100DEF_BENCH(return new BlurBench(REAL, kOuter_SkBlurStyle);)
101DEF_BENCH(return new BlurBench(REAL, kInner_SkBlurStyle);)
tomhudson@google.com8caac642011-11-22 15:58:06 +0000102
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000103DEF_BENCH(return new BlurBench(0, kNormal_SkBlurStyle);)