RecordingBench.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright 2014 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/RecordingBench.h"
  8. #include "include/core/SkBBHFactory.h"
  9. #include "include/core/SkPictureRecorder.h"
  10. PictureCentricBench::PictureCentricBench(const char* name, const SkPicture* pic) : fName(name) {
  11. // Flatten the source picture in case it's trivially nested (useless for timing).
  12. SkPictureRecorder rec;
  13. pic->playback(rec.beginRecording(pic->cullRect(), nullptr,
  14. SkPictureRecorder::kPlaybackDrawPicture_RecordFlag));
  15. fSrc = rec.finishRecordingAsPicture();
  16. }
  17. const char* PictureCentricBench::onGetName() {
  18. return fName.c_str();
  19. }
  20. bool PictureCentricBench::isSuitableFor(Backend backend) {
  21. return backend == kNonRendering_Backend;
  22. }
  23. SkIPoint PictureCentricBench::onGetSize() {
  24. return SkIPoint::Make(SkScalarCeilToInt(fSrc->cullRect().width()),
  25. SkScalarCeilToInt(fSrc->cullRect().height()));
  26. }
  27. ///////////////////////////////////////////////////////////////////////////////////////////////////
  28. RecordingBench::RecordingBench(const char* name, const SkPicture* pic, bool useBBH)
  29. : INHERITED(name, pic)
  30. , fUseBBH(useBBH)
  31. {}
  32. void RecordingBench::onDraw(int loops, SkCanvas*) {
  33. SkRTreeFactory factory;
  34. SkPictureRecorder recorder;
  35. while (loops --> 0) {
  36. fSrc->playback(recorder.beginRecording(fSrc->cullRect(), fUseBBH ? &factory : nullptr));
  37. (void)recorder.finishRecordingAsPicture();
  38. }
  39. }
  40. ///////////////////////////////////////////////////////////////////////////////////////////////////
  41. #include "include/core/SkSerialProcs.h"
  42. DeserializePictureBench::DeserializePictureBench(const char* name, sk_sp<SkData> data)
  43. : fName(name)
  44. , fEncodedPicture(std::move(data))
  45. {}
  46. const char* DeserializePictureBench::onGetName() {
  47. return fName.c_str();
  48. }
  49. bool DeserializePictureBench::isSuitableFor(Backend backend) {
  50. return backend == kNonRendering_Backend;
  51. }
  52. SkIPoint DeserializePictureBench::onGetSize() {
  53. return SkIPoint::Make(128, 128);
  54. }
  55. void DeserializePictureBench::onDraw(int loops, SkCanvas*) {
  56. for (int i = 0; i < loops; ++i) {
  57. SkPicture::MakeFromData(fEncodedPicture.get());
  58. }
  59. }