PictureOverheadBench.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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/SkCanvas.h"
  9. #include "include/core/SkPictureRecorder.h"
  10. #include "include/core/SkRRect.h"
  11. class ClipOverheadRecordingBench : public Benchmark {
  12. public:
  13. ClipOverheadRecordingBench() {}
  14. private:
  15. const char* onGetName() override { return "clip_overhead_recording"; }
  16. bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
  17. void onDraw(int loops, SkCanvas*) override {
  18. SkPictureRecorder rec;
  19. for (int i = 0; i < loops; i++) {
  20. SkCanvas* canvas = rec.beginRecording({0,0, 2000,3000});
  21. SkPaint paint;
  22. SkRRect rrect;
  23. rrect.setOval({0, 0, 1000, 1000});
  24. for (int i = 0; i < 1000; i++) {
  25. canvas->save();
  26. canvas->translate(10, 10);
  27. canvas->clipRect({10,10, 1000, 1000});
  28. canvas->drawRRect(rrect, paint);
  29. canvas->restore();
  30. }
  31. (void)rec.finishRecordingAsPicture();
  32. }
  33. }
  34. };
  35. DEF_BENCH( return new ClipOverheadRecordingBench; )