2013-11-05 15:57:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/Benchmark.h"
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkColorFilter.h"
|
|
|
|
#include "include/core/SkMaskFilter.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPath.h"
|
|
|
|
#include "include/core/SkPoint.h"
|
|
|
|
#include "include/core/SkRRect.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "include/effects/SkLayerDrawLooper.h"
|
|
|
|
#include "src/core/SkBlurMask.h"
|
2013-11-05 15:57:21 +00:00
|
|
|
|
2013-11-05 21:10:58 +00:00
|
|
|
// Large blurred RR appear frequently on web pages. This benchmark measures our
|
|
|
|
// performance in this case.
|
2014-06-19 19:32:29 +00:00
|
|
|
class BlurRoundRectBench : public Benchmark {
|
2013-11-05 15:57:21 +00:00
|
|
|
public:
|
2013-11-05 21:10:58 +00:00
|
|
|
BlurRoundRectBench(int width, int height, int cornerRadius)
|
|
|
|
: fName("blurroundrect") {
|
2016-08-29 20:33:04 +00:00
|
|
|
fName.appendf("_WH_%ix%i_cr_%i", width, height, cornerRadius);
|
2013-11-05 21:10:58 +00:00
|
|
|
SkRect r = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height));
|
|
|
|
fRRect.setRectXY(r, SkIntToScalar(cornerRadius), SkIntToScalar(cornerRadius));
|
2013-11-05 15:57:21 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2013-11-05 15:57:21 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkIPoint onGetSize() override {
|
2013-11-05 21:10:58 +00:00
|
|
|
return SkIPoint::Make(SkScalarCeilToInt(fRRect.rect().width()),
|
|
|
|
SkScalarCeilToInt(fRRect.rect().height()));
|
2013-11-05 15:57:21 +00:00
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2014-04-15 15:48:36 +00:00
|
|
|
SkLayerDrawLooper::Builder looperBuilder;
|
2013-11-05 21:10:58 +00:00
|
|
|
{
|
|
|
|
SkLayerDrawLooper::LayerInfo info;
|
|
|
|
info.fPaintBits = SkLayerDrawLooper::kMaskFilter_Bit
|
|
|
|
| SkLayerDrawLooper::kColorFilter_Bit;
|
2016-11-03 18:45:31 +00:00
|
|
|
info.fColorMode = SkBlendMode::kSrc;
|
2013-11-05 21:10:58 +00:00
|
|
|
info.fOffset = SkPoint::Make(SkIntToScalar(-1), SkIntToScalar(0));
|
|
|
|
info.fPostTranslate = false;
|
2014-04-15 15:48:36 +00:00
|
|
|
SkPaint* paint = looperBuilder.addLayerOnTop(info);
|
2018-03-14 17:01:17 +00:00
|
|
|
paint->setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle,
|
|
|
|
SkBlurMask::ConvertRadiusToSigma(0.5)));
|
2019-04-08 20:23:20 +00:00
|
|
|
paint->setColorFilter(SkColorFilters::Blend(SK_ColorLTGRAY, SkBlendMode::kSrcIn));
|
2013-11-05 21:10:58 +00:00
|
|
|
paint->setColor(SK_ColorGRAY);
|
|
|
|
}
|
|
|
|
{
|
|
|
|
SkLayerDrawLooper::LayerInfo info;
|
2014-04-15 15:48:36 +00:00
|
|
|
looperBuilder.addLayerOnTop(info);
|
2013-11-05 21:10:58 +00:00
|
|
|
}
|
|
|
|
SkPaint dullPaint;
|
|
|
|
dullPaint.setAntiAlias(true);
|
2013-11-05 15:57:21 +00:00
|
|
|
|
2013-11-05 21:10:58 +00:00
|
|
|
SkPaint loopedPaint;
|
2016-03-21 20:25:16 +00:00
|
|
|
loopedPaint.setLooper(looperBuilder.detach());
|
2013-11-05 21:10:58 +00:00
|
|
|
loopedPaint.setAntiAlias(true);
|
|
|
|
loopedPaint.setColor(SK_ColorCYAN);
|
2013-11-05 15:57:21 +00:00
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2013-11-05 21:10:58 +00:00
|
|
|
canvas->drawRect(fRRect.rect(), dullPaint);
|
|
|
|
canvas->drawRRect(fRRect, loopedPaint);
|
2013-11-05 15:57:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-11-05 21:10:58 +00:00
|
|
|
SkString fName;
|
|
|
|
SkRRect fRRect;
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2013-11-05 15:57:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Create one with dimensions/rounded corners based on the skp
|
2013-11-05 21:10:58 +00:00
|
|
|
DEF_BENCH(return new BlurRoundRectBench(600, 5514, 6);)
|
2013-11-05 15:57:21 +00:00
|
|
|
// Same radii, much smaller rectangle
|
2013-11-05 21:10:58 +00:00
|
|
|
DEF_BENCH(return new BlurRoundRectBench(100, 100, 6);)
|
|
|
|
// Other radii options
|
|
|
|
DEF_BENCH(return new BlurRoundRectBench(100, 100, 30);)
|
|
|
|
DEF_BENCH(return new BlurRoundRectBench(100, 100, 90);)
|