2014-12-10 01:47:05 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 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/SkMaskFilter.h"
|
|
|
|
#include "include/core/SkPaint.h"
|
|
|
|
#include "include/core/SkPath.h"
|
|
|
|
#include "include/core/SkRect.h"
|
|
|
|
#include "include/core/SkString.h"
|
2014-12-10 01:47:05 +00:00
|
|
|
|
|
|
|
class BlurRectsBench : public Benchmark {
|
|
|
|
public:
|
|
|
|
BlurRectsBench(SkRect outer, SkRect inner, SkScalar radius) {
|
|
|
|
fRadius = radius;
|
|
|
|
fOuter = outer;
|
|
|
|
fInner = inner;
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2014-12-10 01:47:05 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setName(const SkString& name) {
|
|
|
|
fName = name;
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2014-12-10 01:47:05 +00:00
|
|
|
SkPaint paint;
|
2018-03-14 17:01:17 +00:00
|
|
|
paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, fRadius));
|
2014-12-10 01:47:05 +00:00
|
|
|
|
|
|
|
SkPath path;
|
2019-09-14 19:13:23 +00:00
|
|
|
path.addRect(fOuter, SkPath::kCW_Direction);
|
|
|
|
path.addRect(fInner, SkPath::kCW_Direction);
|
2014-12-10 01:47:05 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < loops; i++) {
|
|
|
|
canvas->drawPath(path, paint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkString fName;
|
|
|
|
SkRect fOuter;
|
|
|
|
SkRect fInner;
|
|
|
|
SkScalar fRadius;
|
|
|
|
|
|
|
|
typedef Benchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class BlurRectsNinePatchBench: public BlurRectsBench {
|
|
|
|
public:
|
|
|
|
BlurRectsNinePatchBench(SkRect outer, SkRect inner, SkScalar radius)
|
|
|
|
: INHERITED(outer, inner, radius) {
|
|
|
|
this->setName(SkString("blurrectsninepatch"));
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef BlurRectsBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class BlurRectsNonNinePatchBench: public BlurRectsBench {
|
|
|
|
public:
|
|
|
|
BlurRectsNonNinePatchBench(SkRect outer, SkRect inner, SkScalar radius)
|
|
|
|
: INHERITED(outer, inner, radius) {
|
|
|
|
SkString name;
|
|
|
|
this->setName(SkString("blurrectsnonninepatch"));
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef BlurRectsBench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_BENCH(return new BlurRectsNinePatchBench(SkRect::MakeXYWH(10, 10, 100, 100),
|
|
|
|
SkRect::MakeXYWH(20, 20, 60, 60),
|
|
|
|
2.3f);)
|
|
|
|
DEF_BENCH(return new BlurRectsNonNinePatchBench(SkRect::MakeXYWH(10, 10, 100, 100),
|
|
|
|
SkRect::MakeXYWH(50, 50, 10, 10),
|
|
|
|
4.3f);)
|