blob: 1733f1b12b29f3f7b749c4e47cc2fec3c5fa170c [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "bench/Benchmark.h"
9#include "include/core/SkCanvas.h"
10#include "include/core/SkColorFilter.h"
11#include "include/core/SkMaskFilter.h"
12#include "include/core/SkPaint.h"
13#include "include/core/SkPath.h"
14#include "include/core/SkPoint.h"
15#include "include/core/SkRRect.h"
16#include "include/core/SkRect.h"
17#include "include/core/SkString.h"
18#include "include/effects/SkLayerDrawLooper.h"
19#include "src/core/SkBlurMask.h"
scroggo@google.com7b056592013-11-05 15:57:21 +000020
scroggo@google.com8610d2c2013-11-05 21:10:58 +000021// Large blurred RR appear frequently on web pages. This benchmark measures our
22// performance in this case.
tfarinaf168b862014-06-19 12:32:29 -070023class BlurRoundRectBench : public Benchmark {
scroggo@google.com7b056592013-11-05 15:57:21 +000024public:
scroggo@google.com8610d2c2013-11-05 21:10:58 +000025 BlurRoundRectBench(int width, int height, int cornerRadius)
26 : fName("blurroundrect") {
jcgregorio1703bd12016-08-29 13:33:04 -070027 fName.appendf("_WH_%ix%i_cr_%i", width, height, cornerRadius);
scroggo@google.com8610d2c2013-11-05 21:10:58 +000028 SkRect r = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height));
29 fRRect.setRectXY(r, SkIntToScalar(cornerRadius), SkIntToScalar(cornerRadius));
scroggo@google.com7b056592013-11-05 15:57:21 +000030 }
31
mtklein36352bf2015-03-25 18:17:31 -070032 const char* onGetName() override {
scroggo@google.com7b056592013-11-05 15:57:21 +000033 return fName.c_str();
34 }
35
mtklein36352bf2015-03-25 18:17:31 -070036 SkIPoint onGetSize() override {
scroggo@google.com8610d2c2013-11-05 21:10:58 +000037 return SkIPoint::Make(SkScalarCeilToInt(fRRect.rect().width()),
38 SkScalarCeilToInt(fRRect.rect().height()));
scroggo@google.com7b056592013-11-05 15:57:21 +000039 }
40
mtkleina1ebeb22015-10-01 09:43:39 -070041 void onDraw(int loops, SkCanvas* canvas) override {
commit-bot@chromium.org73cb1532014-04-15 15:48:36 +000042 SkLayerDrawLooper::Builder looperBuilder;
scroggo@google.com8610d2c2013-11-05 21:10:58 +000043 {
44 SkLayerDrawLooper::LayerInfo info;
scroggo@google.com8610d2c2013-11-05 21:10:58 +000045 info.fPaintBits = SkLayerDrawLooper::kMaskFilter_Bit
46 | SkLayerDrawLooper::kColorFilter_Bit;
Mike Reedfaba3712016-11-03 14:45:31 -040047 info.fColorMode = SkBlendMode::kSrc;
scroggo@google.com8610d2c2013-11-05 21:10:58 +000048 info.fOffset = SkPoint::Make(SkIntToScalar(-1), SkIntToScalar(0));
49 info.fPostTranslate = false;
commit-bot@chromium.org73cb1532014-04-15 15:48:36 +000050 SkPaint* paint = looperBuilder.addLayerOnTop(info);
Mike Reed1be1f8d2018-03-14 13:01:17 -040051 paint->setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle,
52 SkBlurMask::ConvertRadiusToSigma(0.5)));
Mike Reedb286bc22019-04-08 16:23:20 -040053 paint->setColorFilter(SkColorFilters::Blend(SK_ColorLTGRAY, SkBlendMode::kSrcIn));
scroggo@google.com8610d2c2013-11-05 21:10:58 +000054 paint->setColor(SK_ColorGRAY);
55 }
56 {
57 SkLayerDrawLooper::LayerInfo info;
commit-bot@chromium.org73cb1532014-04-15 15:48:36 +000058 looperBuilder.addLayerOnTop(info);
scroggo@google.com8610d2c2013-11-05 21:10:58 +000059 }
60 SkPaint dullPaint;
61 dullPaint.setAntiAlias(true);
62
63 SkPaint loopedPaint;
reed7b380d02016-03-21 13:25:16 -070064 loopedPaint.setLooper(looperBuilder.detach());
scroggo@google.com8610d2c2013-11-05 21:10:58 +000065 loopedPaint.setAntiAlias(true);
66 loopedPaint.setColor(SK_ColorCYAN);
67
commit-bot@chromium.org33614712013-12-03 18:17:16 +000068 for (int i = 0; i < loops; i++) {
scroggo@google.com8610d2c2013-11-05 21:10:58 +000069 canvas->drawRect(fRRect.rect(), dullPaint);
70 canvas->drawRRect(fRRect, loopedPaint);
scroggo@google.com7b056592013-11-05 15:57:21 +000071 }
72 }
73
74private:
scroggo@google.com8610d2c2013-11-05 21:10:58 +000075 SkString fName;
76 SkRRect fRRect;
77
tfarinaf168b862014-06-19 12:32:29 -070078 typedef Benchmark INHERITED;
scroggo@google.com7b056592013-11-05 15:57:21 +000079};
80
81// Create one with dimensions/rounded corners based on the skp
scroggo@google.com8610d2c2013-11-05 21:10:58 +000082DEF_BENCH(return new BlurRoundRectBench(600, 5514, 6);)
scroggo@google.com7b056592013-11-05 15:57:21 +000083// Same radii, much smaller rectangle
scroggo@google.com8610d2c2013-11-05 21:10:58 +000084DEF_BENCH(return new BlurRoundRectBench(100, 100, 6);)
85// Other radii options
86DEF_BENCH(return new BlurRoundRectBench(100, 100, 30);)
87DEF_BENCH(return new BlurRoundRectBench(100, 100, 90);)