LineBench.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright 2012 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/SkPaint.h"
  12. #include "include/core/SkShader.h"
  13. #include "include/core/SkString.h"
  14. #include "include/private/SkTArray.h"
  15. #include "include/utils/SkRandom.h"
  16. class LineBench : public Benchmark {
  17. SkScalar fStrokeWidth;
  18. bool fDoAA;
  19. SkString fName;
  20. enum {
  21. PTS = 500,
  22. };
  23. SkPoint fPts[PTS];
  24. public:
  25. LineBench(SkScalar width, bool doAA) {
  26. fStrokeWidth = width;
  27. fDoAA = doAA;
  28. fName.printf("lines_%g_%s", width, doAA ? "AA" : "BW");
  29. SkRandom rand;
  30. for (int i = 0; i < PTS; ++i) {
  31. fPts[i].set(rand.nextUScalar1() * 640, rand.nextUScalar1() * 480);
  32. }
  33. }
  34. protected:
  35. const char* onGetName() override {
  36. return fName.c_str();
  37. }
  38. void onDraw(int loops, SkCanvas* canvas) override {
  39. SkPaint paint;
  40. this->setupPaint(&paint);
  41. paint.setStyle(SkPaint::kStroke_Style);
  42. paint.setAntiAlias(fDoAA);
  43. paint.setStrokeWidth(fStrokeWidth);
  44. for (int i = 0; i < loops; i++) {
  45. canvas->drawPoints(SkCanvas::kLines_PointMode, PTS, fPts, paint);
  46. }
  47. }
  48. private:
  49. typedef Benchmark INHERITED;
  50. };
  51. DEF_BENCH(return new LineBench(0, false);)
  52. DEF_BENCH(return new LineBench(SK_Scalar1, false);)
  53. DEF_BENCH(return new LineBench(0, true);)
  54. DEF_BENCH(return new LineBench(SK_Scalar1/2, true);)
  55. DEF_BENCH(return new LineBench(SK_Scalar1, true);)