1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
/*
* Copyright 2014 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "Benchmark.h"
#include "SkBlurMaskFilter.h"
#include "SkCanvas.h"
#include "SkPaint.h"
#include "SkPath.h"
#include "SkRect.h"
#include "SkString.h"
class BlurRectsBench : public Benchmark {
public:
BlurRectsBench(SkRect outer, SkRect inner, SkScalar radius) {
fRadius = radius;
fOuter = outer;
fInner = inner;
}
const char* onGetName() override {
return fName.c_str();
}
void setName(const SkString& name) {
fName = name;
}
void onDraw(int loops, SkCanvas* canvas) override {
SkPaint paint;
paint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, fRadius));
SkPath path;
path.addRect(fOuter, SkPath::kCW_Direction);
path.addRect(fInner, SkPath::kCW_Direction);
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);)
|