blob: 6ebc641fd93250fc24a7c54e82a183167d5575e6 [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"
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);
reedefdfd512016-04-04 10:02:58 -070051 paint->setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle,
52 SkBlurMask::ConvertRadiusToSigma(0.5),
53 SkBlurMaskFilter::kHighQuality_BlurFlag));
reedd053ce92016-03-22 10:17:23 -070054 paint->setColorFilter(SkColorFilter::MakeModeFilter(SK_ColorLTGRAY,
Mike Reed7d954ad2016-10-28 15:42:34 -040055 SkBlendMode::kSrcIn));
scroggo@google.com8610d2c2013-11-05 21:10:58 +000056 paint->setColor(SK_ColorGRAY);
57 }
58 {
59 SkLayerDrawLooper::LayerInfo info;
commit-bot@chromium.org73cb1532014-04-15 15:48:36 +000060 looperBuilder.addLayerOnTop(info);
scroggo@google.com8610d2c2013-11-05 21:10:58 +000061 }
62 SkPaint dullPaint;
63 dullPaint.setAntiAlias(true);
64
65 SkPaint loopedPaint;
reed7b380d02016-03-21 13:25:16 -070066 loopedPaint.setLooper(looperBuilder.detach());
scroggo@google.com8610d2c2013-11-05 21:10:58 +000067 loopedPaint.setAntiAlias(true);
68 loopedPaint.setColor(SK_ColorCYAN);
69
commit-bot@chromium.org33614712013-12-03 18:17:16 +000070 for (int i = 0; i < loops; i++) {
scroggo@google.com8610d2c2013-11-05 21:10:58 +000071 canvas->drawRect(fRRect.rect(), dullPaint);
72 canvas->drawRRect(fRRect, loopedPaint);
scroggo@google.com7b056592013-11-05 15:57:21 +000073 }
74 }
75
76private:
scroggo@google.com8610d2c2013-11-05 21:10:58 +000077 SkString fName;
78 SkRRect fRRect;
79
tfarinaf168b862014-06-19 12:32:29 -070080 typedef Benchmark INHERITED;
scroggo@google.com7b056592013-11-05 15:57:21 +000081};
82
83// Create one with dimensions/rounded corners based on the skp
scroggo@google.com8610d2c2013-11-05 21:10:58 +000084DEF_BENCH(return new BlurRoundRectBench(600, 5514, 6);)
scroggo@google.com7b056592013-11-05 15:57:21 +000085// Same radii, much smaller rectangle
scroggo@google.com8610d2c2013-11-05 21:10:58 +000086DEF_BENCH(return new BlurRoundRectBench(100, 100, 6);)
87// Other radii options
88DEF_BENCH(return new BlurRoundRectBench(100, 100, 30);)
89DEF_BENCH(return new BlurRoundRectBench(100, 100, 90);)