BlurRectsBench.cpp 2.3 KB

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