| 1 |
/* |
| 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 "bench/Benchmark.h" |
| 9 |
#include "include/core/SkBlurTypes.h" |
| 10 |
#include "include/core/SkCanvas.h" |
| 11 |
#include "include/core/SkMaskFilter.h" |
| 12 |
#include "include/core/SkPaint.h" |
| 13 |
#include "include/core/SkPath.h" |
| 14 |
#include "include/core/SkPathBuilder.h" |
| 15 |
#include "include/core/SkRect.h" |
| 16 |
#include "include/core/SkString.h" |
| 17 |
|
| 18 |
class BlurRectsBench : public Benchmark { |
| 19 |
public: |
| 20 |
BlurRectsBench(SkRect outer, SkRect inner, SkScalar radius) { |
| 21 |
fRadius = radius; |
| 22 |
fOuter = outer; |
| 23 |
fInner = inner; |
| 24 |
} |
| 25 |
|
| 26 |
const char* onGetName() override { |
| 27 |
return fName.c_str(); |
| 28 |
} |
| 29 |
|
| 30 |
void setName(const SkString& name) { |
| 31 |
fName = name; |
| 32 |
} |
| 33 |
|
| 34 |
void onDraw(int loops, SkCanvas* canvas) override { |
| 35 |
SkPaint paint; |
| 36 |
paint.setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle, fRadius)); |
| 37 |
|
| 38 |
SkPath path = SkPathBuilder() |
| 39 |
.addRect(fOuter, SkPathDirection::kCW) |
| 40 |
.addRect(fInner, SkPathDirection::kCW) |
| 41 |
.detach(); |
| 42 |
|
| 43 |
for (int i = 0; i < loops; i++) { |
| 44 |
canvas->drawPath(path, paint); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
private: |
| 49 |
SkString fName; |
| 50 |
SkRect fOuter; |
| 51 |
SkRect fInner; |
| 52 |
SkScalar fRadius; |
| 53 |
|
| 54 |
using INHERITED = Benchmark; |
| 55 |
}; |
| 56 |
|
| 57 |
class BlurRectsNinePatchBench: public BlurRectsBench { |
| 58 |
public: |
| 59 |
BlurRectsNinePatchBench(SkRect outer, SkRect inner, SkScalar radius) |
| 60 |
: INHERITED(outer, inner, radius) { |
| 61 |
this->setName(SkString("blurrectsninepatch")); |
| 62 |
} |
| 63 |
private: |
| 64 |
using INHERITED = BlurRectsBench; |
| 65 |
}; |
| 66 |
|
| 67 |
class BlurRectsNonNinePatchBench: public BlurRectsBench { |
| 68 |
public: |
| 69 |
BlurRectsNonNinePatchBench(SkRect outer, SkRect inner, SkScalar radius) |
| 70 |
: INHERITED(outer, inner, radius) { |
| 71 |
SkString name; |
| 72 |
this->setName(SkString("blurrectsnonninepatch")); |
| 73 |
} |
| 74 |
private: |
| 75 |
using INHERITED = BlurRectsBench; |
| 76 |
}; |
| 77 |
|
| 78 |
DEF_BENCH(return new BlurRectsNinePatchBench(SkRect::MakeXYWH(10, 10, 100, 100), |
| 79 |
SkRect::MakeXYWH(20, 20, 60, 60), |
| 80 |
2.3f);) |
| 81 |
DEF_BENCH(return new BlurRectsNonNinePatchBench(SkRect::MakeXYWH(10, 10, 100, 100), |
| 82 |
SkRect::MakeXYWH(50, 50, 10, 10), |
| 83 |
4.3f);) |