blob: 085a8eb0e69b33e6bc11b8984393d123baf9a048 [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"
scroggo@google.com7b056592013-11-05 15:57:21 +000010#include "SkCanvas.h"
11#include "SkColorFilter.h"
12#include "SkLayerDrawLooper.h"
Mike Reed1be1f8d2018-03-14 13:01:17 -040013#include "SkMaskFilter.h"
scroggo@google.com7b056592013-11-05 15:57:21 +000014#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);
Mike Reed1be1f8d2018-03-14 13:01:17 -040051 paint->setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle,
52 SkBlurMask::ConvertRadiusToSigma(0.5)));
reedd053ce92016-03-22 10:17:23 -070053 paint->setColorFilter(SkColorFilter::MakeModeFilter(SK_ColorLTGRAY,
Mike Reed7d954ad2016-10-28 15:42:34 -040054 SkBlendMode::kSrcIn));
scroggo@google.com8610d2c2013-11-05 21:10:58 +000055 paint->setColor(SK_ColorGRAY);
56 }
57 {
58 SkLayerDrawLooper::LayerInfo info;
commit-bot@chromium.org73cb1532014-04-15 15:48:36 +000059 looperBuilder.addLayerOnTop(info);
scroggo@google.com8610d2c2013-11-05 21:10:58 +000060 }
61 SkPaint dullPaint;
62 dullPaint.setAntiAlias(true);
63
64 SkPaint loopedPaint;
reed7b380d02016-03-21 13:25:16 -070065 loopedPaint.setLooper(looperBuilder.detach());
scroggo@google.com8610d2c2013-11-05 21:10:58 +000066 loopedPaint.setAntiAlias(true);
67 loopedPaint.setColor(SK_ColorCYAN);
68
commit-bot@chromium.org33614712013-12-03 18:17:16 +000069 for (int i = 0; i < loops; i++) {
scroggo@google.com8610d2c2013-11-05 21:10:58 +000070 canvas->drawRect(fRRect.rect(), dullPaint);
71 canvas->drawRRect(fRRect, loopedPaint);
scroggo@google.com7b056592013-11-05 15:57:21 +000072 }
73 }
74
75private:
scroggo@google.com8610d2c2013-11-05 21:10:58 +000076 SkString fName;
77 SkRRect fRRect;
78
tfarinaf168b862014-06-19 12:32:29 -070079 typedef Benchmark INHERITED;
scroggo@google.com7b056592013-11-05 15:57:21 +000080};
81
82// Create one with dimensions/rounded corners based on the skp
scroggo@google.com8610d2c2013-11-05 21:10:58 +000083DEF_BENCH(return new BlurRoundRectBench(600, 5514, 6);)
scroggo@google.com7b056592013-11-05 15:57:21 +000084// Same radii, much smaller rectangle
scroggo@google.com8610d2c2013-11-05 21:10:58 +000085DEF_BENCH(return new BlurRoundRectBench(100, 100, 6);)
86// Other radii options
87DEF_BENCH(return new BlurRoundRectBench(100, 100, 30);)
88DEF_BENCH(return new BlurRoundRectBench(100, 100, 90);)