CoverageBench.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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/SkBitmap.h"
  9. #include "include/core/SkCanvas.h"
  10. #include "include/core/SkColorPriv.h"
  11. #include "include/core/SkMatrix.h"
  12. #include "include/core/SkPath.h"
  13. #include "src/core/SkAutoPixmapStorage.h"
  14. #include "src/core/SkDraw.h"
  15. #include "src/core/SkRasterClip.h"
  16. class DrawPathBench : public Benchmark {
  17. SkPaint fPaint;
  18. SkString fName;
  19. SkPath fPath;
  20. SkRasterClip fRC;
  21. SkAutoPixmapStorage fPixmap;
  22. SkMatrix fIdentity;
  23. SkDraw fDraw;
  24. bool fDrawCoverage;
  25. public:
  26. DrawPathBench(bool drawCoverage) : fDrawCoverage(drawCoverage) {
  27. fPaint.setAntiAlias(true);
  28. fName.printf("draw_coverage_%s", drawCoverage ? "true" : "false");
  29. fPath.moveTo(0, 0);
  30. fPath.quadTo(500, 0, 500, 500);
  31. fPath.quadTo(250, 0, 0, 500);
  32. fPixmap.alloc(SkImageInfo::MakeA8(500, 500));
  33. if (!drawCoverage) {
  34. // drawPathCoverage() goes out of its way to work fine with an uninitialized
  35. // dst buffer, even in "SrcOver" mode, but ordinary drawing sure doesn't.
  36. fPixmap.erase(0);
  37. }
  38. fIdentity.setIdentity();
  39. fRC.setRect(fPath.getBounds().round());
  40. fDraw.fDst = fPixmap;
  41. fDraw.fMatrix = &fIdentity;
  42. fDraw.fRC = &fRC;
  43. }
  44. protected:
  45. const char* onGetName() override {
  46. return fName.c_str();
  47. }
  48. void onDraw(int loops, SkCanvas* canvas) override {
  49. if (fDrawCoverage) {
  50. for (int i = 0; i < loops; ++i) {
  51. fDraw.drawPathCoverage(fPath, fPaint);
  52. }
  53. } else {
  54. for (int i = 0; i < loops; ++i) {
  55. fDraw.drawPath(fPath, fPaint);
  56. }
  57. }
  58. }
  59. private:
  60. typedef Benchmark INHERITED;
  61. };
  62. ///////////////////////////////////////////////////////////////////////////////
  63. DEF_BENCH( return new DrawPathBench(false) )
  64. DEF_BENCH( return new DrawPathBench(true) )