blob: ef88422e3cffa617f994f45e38bb994a62acd25c [file] [log] [blame]
scroggo@google.com7b056592013-11-05 15:57:21 +00001/*
2* Copyright 2013 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*/
7
tfarinaf168b862014-06-19 12:32:29 -07008#include "Benchmark.h"
scroggo@google.com7b056592013-11-05 15:57:21 +00009#include "SkBlurMask.h"
10#include "SkBlurMaskFilter.h"
11#include "SkCanvas.h"
12#include "SkColorFilter.h"
13#include "SkLayerDrawLooper.h"
14#include "SkPaint.h"
15#include "SkPath.h"
16#include "SkPoint.h"
scroggo@google.com7b056592013-11-05 15:57:21 +000017#include "SkRRect.h"
tfarinaf168b862014-06-19 12:32:29 -070018#include "SkRect.h"
scroggo@google.com7b056592013-11-05 15:57:21 +000019#include "SkString.h"
20#include "SkXfermode.h"
21
scroggo@google.com8610d2c2013-11-05 21:10:58 +000022// Large blurred RR appear frequently on web pages. This benchmark measures our
23// performance in this case.
tfarinaf168b862014-06-19 12:32:29 -070024class BlurRoundRectBench : public Benchmark {
scroggo@google.com7b056592013-11-05 15:57:21 +000025public:
scroggo@google.com8610d2c2013-11-05 21:10:58 +000026 BlurRoundRectBench(int width, int height, int cornerRadius)
27 : fName("blurroundrect") {
28 fName.appendf("_WH[%ix%i]_cr[%i]", width, height, cornerRadius);
29 SkRect r = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height));
30 fRRect.setRectXY(r, SkIntToScalar(cornerRadius), SkIntToScalar(cornerRadius));
scroggo@google.com7b056592013-11-05 15:57:21 +000031 }
32
mtklein36352bf2015-03-25 18:17:31 -070033 const char* onGetName() override {
scroggo@google.com7b056592013-11-05 15:57:21 +000034 return fName.c_str();
35 }
36
mtklein36352bf2015-03-25 18:17:31 -070037 SkIPoint onGetSize() override {
scroggo@google.com8610d2c2013-11-05 21:10:58 +000038 return SkIPoint::Make(SkScalarCeilToInt(fRRect.rect().width()),
39 SkScalarCeilToInt(fRRect.rect().height()));
scroggo@google.com7b056592013-11-05 15:57:21 +000040 }
41
mtkleina1ebeb22015-10-01 09:43:39 -070042 void onDraw(int loops, SkCanvas* canvas) override {
commit-bot@chromium.org73cb1532014-04-15 15:48:36 +000043 SkLayerDrawLooper::Builder looperBuilder;
scroggo@google.com8610d2c2013-11-05 21:10:58 +000044 {
45 SkLayerDrawLooper::LayerInfo info;
scroggo@google.com8610d2c2013-11-05 21:10:58 +000046 info.fPaintBits = SkLayerDrawLooper::kMaskFilter_Bit
47 | SkLayerDrawLooper::kColorFilter_Bit;
48 info.fColorMode = SkXfermode::kSrc_Mode;
49 info.fOffset = SkPoint::Make(SkIntToScalar(-1), SkIntToScalar(0));
50 info.fPostTranslate = false;
commit-bot@chromium.org73cb1532014-04-15 15:48:36 +000051 SkPaint* paint = looperBuilder.addLayerOnTop(info);
reedefdfd512016-04-04 10:02:58 -070052 paint->setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle,
53 SkBlurMask::ConvertRadiusToSigma(0.5),
54 SkBlurMaskFilter::kHighQuality_BlurFlag));
reedd053ce92016-03-22 10:17:23 -070055 paint->setColorFilter(SkColorFilter::MakeModeFilter(SK_ColorLTGRAY,
56 SkXfermode::kSrcIn_Mode));
scroggo@google.com8610d2c2013-11-05 21:10:58 +000057 paint->setColor(SK_ColorGRAY);
58 }
59 {
60 SkLayerDrawLooper::LayerInfo info;
commit-bot@chromium.org73cb1532014-04-15 15:48:36 +000061 looperBuilder.addLayerOnTop(info);
scroggo@google.com8610d2c2013-11-05 21:10:58 +000062 }
63 SkPaint dullPaint;
64 dullPaint.setAntiAlias(true);
65
66 SkPaint loopedPaint;
reed7b380d02016-03-21 13:25:16 -070067 loopedPaint.setLooper(looperBuilder.detach());
scroggo@google.com8610d2c2013-11-05 21:10:58 +000068 loopedPaint.setAntiAlias(true);
69 loopedPaint.setColor(SK_ColorCYAN);
70
commit-bot@chromium.org33614712013-12-03 18:17:16 +000071 for (int i = 0; i < loops; i++) {
scroggo@google.com8610d2c2013-11-05 21:10:58 +000072 canvas->drawRect(fRRect.rect(), dullPaint);
73 canvas->drawRRect(fRRect, loopedPaint);
scroggo@google.com7b056592013-11-05 15:57:21 +000074 }
75 }
76
77private:
scroggo@google.com8610d2c2013-11-05 21:10:58 +000078 SkString fName;
79 SkRRect fRRect;
80
tfarinaf168b862014-06-19 12:32:29 -070081 typedef Benchmark INHERITED;
scroggo@google.com7b056592013-11-05 15:57:21 +000082};
83
84// Create one with dimensions/rounded corners based on the skp
scroggo@google.com8610d2c2013-11-05 21:10:58 +000085DEF_BENCH(return new BlurRoundRectBench(600, 5514, 6);)
scroggo@google.com7b056592013-11-05 15:57:21 +000086// Same radii, much smaller rectangle
scroggo@google.com8610d2c2013-11-05 21:10:58 +000087DEF_BENCH(return new BlurRoundRectBench(100, 100, 6);)
88// Other radii options
89DEF_BENCH(return new BlurRoundRectBench(100, 100, 30);)
90DEF_BENCH(return new BlurRoundRectBench(100, 100, 90);)