DrawBitmapAABench.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright 2015 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/SkBitmap.h"
  9. #include "include/core/SkCanvas.h"
  10. #include "include/core/SkMatrix.h"
  11. #include "include/core/SkPaint.h"
  12. #include "include/core/SkString.h"
  13. /**
  14. * This bench measures the rendering time of SkCanvas::drawBitmap with different anti-aliasing /
  15. * matrix combinations.
  16. */
  17. class DrawBitmapAABench : public Benchmark {
  18. public:
  19. DrawBitmapAABench(bool doAA, const SkMatrix& matrix, const char name[])
  20. : fMatrix(matrix)
  21. , fName("draw_bitmap_") {
  22. fPaint.setAntiAlias(doAA);
  23. // Most clients use filtering, so let's focus on this for now.
  24. fPaint.setFilterQuality(kLow_SkFilterQuality);
  25. fName.appendf("%s_%s", doAA ? "aa" : "noaa", name);
  26. }
  27. protected:
  28. const char* onGetName() override {
  29. return fName.c_str();
  30. }
  31. void onDelayedSetup() override {
  32. fBitmap.allocN32Pixels(200, 200);
  33. fBitmap.eraseARGB(255, 0, 255, 0);
  34. }
  35. void onDraw(int loops, SkCanvas* canvas) override {
  36. canvas->concat(fMatrix);
  37. for (int i = 0; i < loops; i++) {
  38. canvas->drawBitmap(fBitmap, 0, 0, &fPaint);
  39. }
  40. }
  41. private:
  42. SkPaint fPaint;
  43. SkMatrix fMatrix;
  44. SkString fName;
  45. SkBitmap fBitmap;
  46. typedef Benchmark INHERITED;
  47. };
  48. DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::MakeScale(1), "ident"); )
  49. DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::MakeScale(1.17f), "scale"); )
  50. DEF_BENCH( return new DrawBitmapAABench(false, SkMatrix::MakeTrans(17.5f, 17.5f), "translate"); )
  51. DEF_BENCH(
  52. SkMatrix m;
  53. m.reset();
  54. m.preRotate(15);
  55. return new DrawBitmapAABench(false, m, "rotate");
  56. )
  57. DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::MakeScale(1), "ident"); )
  58. DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::MakeScale(1.17f), "scale"); )
  59. DEF_BENCH( return new DrawBitmapAABench(true, SkMatrix::MakeTrans(17.5f, 17.5f), "translate"); )
  60. DEF_BENCH(
  61. SkMatrix m;
  62. m.reset();
  63. m.preRotate(15);
  64. return new DrawBitmapAABench(true, m, "rotate");
  65. )