BlurRoundRectBench.cpp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright 2013 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/SkColorFilter.h"
  10. #include "include/core/SkMaskFilter.h"
  11. #include "include/core/SkPaint.h"
  12. #include "include/core/SkPath.h"
  13. #include "include/core/SkPoint.h"
  14. #include "include/core/SkRRect.h"
  15. #include "include/core/SkRect.h"
  16. #include "include/core/SkString.h"
  17. #include "include/effects/SkLayerDrawLooper.h"
  18. #include "src/core/SkBlurMask.h"
  19. #ifdef SK_SUPPORT_LEGACY_DRAWLOOPER
  20. // Large blurred RR appear frequently on web pages. This benchmark measures our
  21. // performance in this case.
  22. class BlurRoundRectBench : public Benchmark {
  23. public:
  24. BlurRoundRectBench(int width, int height, int cornerRadius)
  25. : fName("blurroundrect") {
  26. fName.appendf("_WH_%ix%i_cr_%i", width, height, cornerRadius);
  27. SkRect r = SkRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height));
  28. fRRect.setRectXY(r, SkIntToScalar(cornerRadius), SkIntToScalar(cornerRadius));
  29. }
  30. const char* onGetName() override {
  31. return fName.c_str();
  32. }
  33. SkIPoint onGetSize() override {
  34. return SkIPoint::Make(SkScalarCeilToInt(fRRect.rect().width()),
  35. SkScalarCeilToInt(fRRect.rect().height()));
  36. }
  37. void onDraw(int loops, SkCanvas* canvas) override {
  38. SkLayerDrawLooper::Builder looperBuilder;
  39. {
  40. SkLayerDrawLooper::LayerInfo info;
  41. info.fPaintBits = SkLayerDrawLooper::kMaskFilter_Bit
  42. | SkLayerDrawLooper::kColorFilter_Bit;
  43. info.fColorMode = SkBlendMode::kSrc;
  44. info.fOffset = SkPoint::Make(SkIntToScalar(-1), SkIntToScalar(0));
  45. info.fPostTranslate = false;
  46. SkPaint* paint = looperBuilder.addLayerOnTop(info);
  47. paint->setMaskFilter(SkMaskFilter::MakeBlur(kNormal_SkBlurStyle,
  48. SkBlurMask::ConvertRadiusToSigma(0.5)));
  49. paint->setColorFilter(SkColorFilters::Blend(SK_ColorLTGRAY, SkBlendMode::kSrcIn));
  50. paint->setColor(SK_ColorGRAY);
  51. }
  52. {
  53. SkLayerDrawLooper::LayerInfo info;
  54. looperBuilder.addLayerOnTop(info);
  55. }
  56. SkPaint dullPaint;
  57. dullPaint.setAntiAlias(true);
  58. SkPaint loopedPaint;
  59. loopedPaint.setLooper(looperBuilder.detach());
  60. loopedPaint.setAntiAlias(true);
  61. loopedPaint.setColor(SK_ColorCYAN);
  62. for (int i = 0; i < loops; i++) {
  63. canvas->drawRect(fRRect.rect(), dullPaint);
  64. canvas->drawRRect(fRRect, loopedPaint);
  65. }
  66. }
  67. private:
  68. SkString fName;
  69. SkRRect fRRect;
  70. typedef Benchmark INHERITED;
  71. };
  72. // Create one with dimensions/rounded corners based on the skp
  73. DEF_BENCH(return new BlurRoundRectBench(600, 5514, 6);)
  74. // Same radii, much smaller rectangle
  75. DEF_BENCH(return new BlurRoundRectBench(100, 100, 6);)
  76. // Other radii options
  77. DEF_BENCH(return new BlurRoundRectBench(100, 100, 30);)
  78. DEF_BENCH(return new BlurRoundRectBench(100, 100, 90);)
  79. #endif