blob: 20afd4a2e571667d237c50feca7dbe32f6532c62 [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 */
tfarinaf168b862014-06-19 12:32:29 -07007#include "Benchmark.h"
robertphillips@google.comb7061172013-09-06 14:16:12 +00008#include "SkBlurMask.h"
tfarinaf168b862014-06-19 12:32:29 -07009#include "SkBlurMaskFilter.h"
reed@google.com25df8882011-07-14 19:03:58 +000010#include "SkCanvas.h"
11#include "SkPaint.h"
12#include "SkRandom.h"
13#include "SkShader.h"
14#include "SkString.h"
reed@google.com25df8882011-07-14 19:03:58 +000015
joshualitt5acfea72014-08-11 13:55:34 -070016#define MINI 0.01f
reed@google.com25df8882011-07-14 19:03:58 +000017#define SMALL SkIntToScalar(2)
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +000018#define REAL 1.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
reed@google.com25df8882011-07-14 19:03:58 +000021
22static const char* gStyleName[] = {
23 "normal",
24 "solid",
25 "outer",
26 "inner"
27};
28
tfarinaf168b862014-06-19 12:32:29 -070029class BlurBench : public Benchmark {
reed@google.com25df8882011-07-14 19:03:58 +000030 SkScalar fRadius;
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000031 SkBlurStyle fStyle;
32 uint32_t fFlags;
reed@google.com25df8882011-07-14 19:03:58 +000033 SkString fName;
34
35public:
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000036 BlurBench(SkScalar rad, SkBlurStyle bs, uint32_t flags = 0) {
reed@google.com25df8882011-07-14 19:03:58 +000037 fRadius = rad;
38 fStyle = bs;
senorblanco@chromium.org91f489a2012-11-29 17:09:27 +000039 fFlags = flags;
reed@google.com25df8882011-07-14 19:03:58 +000040 const char* name = rad > 0 ? gStyleName[bs] : "none";
skia.committer@gmail.comb3ec29d2013-09-07 07:01:16 +000041 const char* quality = flags & SkBlurMaskFilter::kHighQuality_BlurFlag ? "high_quality"
robertphillips@google.comb7061172013-09-06 14:16:12 +000042 : "low_quality";
tomhudson@google.com8caac642011-11-22 15:58:06 +000043 if (SkScalarFraction(rad) != 0) {
senorblanco@chromium.org91f489a2012-11-29 17:09:27 +000044 fName.printf("blur_%.2f_%s_%s", SkScalarToFloat(rad), name, quality);
tomhudson@google.com8caac642011-11-22 15:58:06 +000045 } else {
reed@google.come1ca7052013-12-17 19:22:07 +000046 fName.printf("blur_%d_%s_%s", SkScalarRoundToInt(rad), name, quality);
tomhudson@google.com8caac642011-11-22 15:58:06 +000047 }
reed@google.com25df8882011-07-14 19:03:58 +000048 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000049
reed@google.com25df8882011-07-14 19:03:58 +000050protected:
51 virtual const char* onGetName() {
52 return fName.c_str();
53 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000054
mtkleina1ebeb22015-10-01 09:43:39 -070055 virtual void onDraw(int loops, SkCanvas* canvas) {
reed@google.com25df8882011-07-14 19:03:58 +000056 SkPaint paint;
57 this->setupPaint(&paint);
58
59 paint.setAntiAlias(true);
60
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +000061 SkRandom rand;
commit-bot@chromium.org33614712013-12-03 18:17:16 +000062 for (int i = 0; i < loops; i++) {
reed@google.com25df8882011-07-14 19:03:58 +000063 SkRect r = SkRect::MakeWH(rand.nextUScalar1() * 400,
64 rand.nextUScalar1() * 400);
65 r.offset(fRadius, fRadius);
66
67 if (fRadius > 0) {
reedefdfd512016-04-04 10:02:58 -070068 paint.setMaskFilter(SkBlurMaskFilter::Make(fStyle,
69 SkBlurMask::ConvertRadiusToSigma(fRadius),
70 fFlags));
reed@google.com25df8882011-07-14 19:03:58 +000071 }
72 canvas->drawOval(r, paint);
73 }
74 }
rmistry@google.comfbfcd562012-08-23 18:09:54 +000075
reed@google.com25df8882011-07-14 19:03:58 +000076private:
tfarinaf168b862014-06-19 12:32:29 -070077 typedef Benchmark INHERITED;
reed@google.com25df8882011-07-14 19:03:58 +000078};
79
joshualitt5acfea72014-08-11 13:55:34 -070080DEF_BENCH(return new BlurBench(MINI, kNormal_SkBlurStyle);)
81DEF_BENCH(return new BlurBench(MINI, kSolid_SkBlurStyle);)
82DEF_BENCH(return new BlurBench(MINI, kOuter_SkBlurStyle);)
83DEF_BENCH(return new BlurBench(MINI, kInner_SkBlurStyle);)
84
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000085DEF_BENCH(return new BlurBench(SMALL, kNormal_SkBlurStyle);)
86DEF_BENCH(return new BlurBench(SMALL, kSolid_SkBlurStyle);)
87DEF_BENCH(return new BlurBench(SMALL, kOuter_SkBlurStyle);)
88DEF_BENCH(return new BlurBench(SMALL, kInner_SkBlurStyle);)
reed@google.com25df8882011-07-14 19:03:58 +000089
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000090DEF_BENCH(return new BlurBench(BIG, kNormal_SkBlurStyle);)
91DEF_BENCH(return new BlurBench(BIG, kSolid_SkBlurStyle);)
92DEF_BENCH(return new BlurBench(BIG, kOuter_SkBlurStyle);)
93DEF_BENCH(return new BlurBench(BIG, kInner_SkBlurStyle);)
reed@google.com25df8882011-07-14 19:03:58 +000094
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000095DEF_BENCH(return new BlurBench(REALBIG, kNormal_SkBlurStyle);)
96DEF_BENCH(return new BlurBench(REALBIG, kSolid_SkBlurStyle);)
97DEF_BENCH(return new BlurBench(REALBIG, kOuter_SkBlurStyle);)
98DEF_BENCH(return new BlurBench(REALBIG, kInner_SkBlurStyle);)
senorblanco@chromium.org91f489a2012-11-29 17:09:27 +000099
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000100DEF_BENCH(return new BlurBench(REAL, kNormal_SkBlurStyle);)
101DEF_BENCH(return new BlurBench(REAL, kSolid_SkBlurStyle);)
102DEF_BENCH(return new BlurBench(REAL, kOuter_SkBlurStyle);)
103DEF_BENCH(return new BlurBench(REAL, kInner_SkBlurStyle);)
tomhudson@google.com8caac642011-11-22 15:58:06 +0000104
joshualitt5acfea72014-08-11 13:55:34 -0700105DEF_BENCH(return new BlurBench(MINI, kNormal_SkBlurStyle, SkBlurMaskFilter::kHighQuality_BlurFlag);)
106
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000107DEF_BENCH(return new BlurBench(SMALL, kNormal_SkBlurStyle, SkBlurMaskFilter::kHighQuality_BlurFlag);)
senorblanco@chromium.org91f489a2012-11-29 17:09:27 +0000108
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000109DEF_BENCH(return new BlurBench(BIG, kNormal_SkBlurStyle, SkBlurMaskFilter::kHighQuality_BlurFlag);)
senorblanco@chromium.org91f489a2012-11-29 17:09:27 +0000110
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000111DEF_BENCH(return new BlurBench(REALBIG, kNormal_SkBlurStyle, SkBlurMaskFilter::kHighQuality_BlurFlag);)
senorblanco@chromium.org91f489a2012-11-29 17:09:27 +0000112
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000113DEF_BENCH(return new BlurBench(REAL, kNormal_SkBlurStyle, SkBlurMaskFilter::kHighQuality_BlurFlag);)
senorblanco@chromium.org91f489a2012-11-29 17:09:27 +0000114
commit-bot@chromium.orge3964552014-04-28 16:25:35 +0000115DEF_BENCH(return new BlurBench(0, kNormal_SkBlurStyle);)