blob: 83847713eecd0b16049afcf6aa89790a22aeb737 [file] [log] [blame]
qiankun.miaoe18a5302014-12-09 17:47:05 -08001/*
2* Copyright 2014 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
8#include "Benchmark.h"
9#include "SkBlurMaskFilter.h"
10#include "SkCanvas.h"
11#include "SkPaint.h"
12#include "SkPath.h"
13#include "SkRect.h"
14#include "SkString.h"
15
16class BlurRectsBench : public Benchmark {
17public:
18 BlurRectsBench(SkRect outer, SkRect inner, SkScalar radius) {
19 fRadius = radius;
20 fOuter = outer;
21 fInner = inner;
22 }
23
mtklein36352bf2015-03-25 18:17:31 -070024 const char* onGetName() override {
qiankun.miaoe18a5302014-12-09 17:47:05 -080025 return fName.c_str();
26 }
27
28 void setName(const SkString& name) {
29 fName = name;
30 }
31
mtklein36352bf2015-03-25 18:17:31 -070032 void onDraw(const int loops, SkCanvas* canvas) override {
qiankun.miaoe18a5302014-12-09 17:47:05 -080033 SkPaint paint;
34 paint.setMaskFilter(SkBlurMaskFilter::Create(kNormal_SkBlurStyle, fRadius))->unref();
35
36 SkPath path;
37 path.addRect(fOuter, SkPath::kCW_Direction);
38 path.addRect(fInner, SkPath::kCW_Direction);
39
40 for (int i = 0; i < loops; i++) {
41 canvas->drawPath(path, paint);
42 }
43 }
44
45private:
46 SkString fName;
47 SkRect fOuter;
48 SkRect fInner;
49 SkScalar fRadius;
50
51 typedef Benchmark INHERITED;
52};
53
54class BlurRectsNinePatchBench: public BlurRectsBench {
55public:
56 BlurRectsNinePatchBench(SkRect outer, SkRect inner, SkScalar radius)
57 : INHERITED(outer, inner, radius) {
58 this->setName(SkString("blurrectsninepatch"));
59 }
60private:
61 typedef BlurRectsBench INHERITED;
62};
63
64class BlurRectsNonNinePatchBench: public BlurRectsBench {
65public:
66 BlurRectsNonNinePatchBench(SkRect outer, SkRect inner, SkScalar radius)
67 : INHERITED(outer, inner, radius) {
68 SkString name;
69 this->setName(SkString("blurrectsnonninepatch"));
70 }
71private:
72 typedef BlurRectsBench INHERITED;
73};
74
75DEF_BENCH(return new BlurRectsNinePatchBench(SkRect::MakeXYWH(10, 10, 100, 100),
76 SkRect::MakeXYWH(20, 20, 60, 60),
77 2.3f);)
78DEF_BENCH(return new BlurRectsNonNinePatchBench(SkRect::MakeXYWH(10, 10, 100, 100),
79 SkRect::MakeXYWH(50, 50, 10, 10),
80 4.3f);)