mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame^] | 8 | #include "bench/RecordingBench.h" |
| 9 | #include "include/core/SkBBHFactory.h" |
| 10 | #include "include/core/SkPictureRecorder.h" |
| 11 | #include "src/core/SkLiteDL.h" |
| 12 | #include "src/core/SkLiteRecorder.h" |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 13 | |
Mike Reed | 9cdd2ab | 2016-10-21 10:43:36 -0400 | [diff] [blame] | 14 | PictureCentricBench::PictureCentricBench(const char* name, const SkPicture* pic) : fName(name) { |
mtklein | 8c1a4f8 | 2016-08-08 06:56:22 -0700 | [diff] [blame] | 15 | // Flatten the source picture in case it's trivially nested (useless for timing). |
| 16 | SkPictureRecorder rec; |
| 17 | pic->playback(rec.beginRecording(pic->cullRect(), nullptr, |
| 18 | SkPictureRecorder::kPlaybackDrawPicture_RecordFlag)); |
| 19 | fSrc = rec.finishRecordingAsPicture(); |
Mike Reed | 9cdd2ab | 2016-10-21 10:43:36 -0400 | [diff] [blame] | 20 | } |
mtklein | 1d65fe2 | 2016-08-10 12:09:34 -0700 | [diff] [blame] | 21 | |
Mike Reed | 9cdd2ab | 2016-10-21 10:43:36 -0400 | [diff] [blame] | 22 | const char* PictureCentricBench::onGetName() { |
| 23 | return fName.c_str(); |
| 24 | } |
| 25 | |
| 26 | bool PictureCentricBench::isSuitableFor(Backend backend) { |
| 27 | return backend == kNonRendering_Backend; |
| 28 | } |
| 29 | |
| 30 | SkIPoint PictureCentricBench::onGetSize() { |
| 31 | return SkIPoint::Make(SkScalarCeilToInt(fSrc->cullRect().width()), |
| 32 | SkScalarCeilToInt(fSrc->cullRect().height())); |
| 33 | } |
| 34 | |
| 35 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 36 | |
| 37 | RecordingBench::RecordingBench(const char* name, const SkPicture* pic, bool useBBH, bool lite) |
| 38 | : INHERITED(name, pic) |
| 39 | , fUseBBH(useBBH) |
| 40 | { |
mtklein | 1d65fe2 | 2016-08-10 12:09:34 -0700 | [diff] [blame] | 41 | // If we're recording into an SkLiteDL, also record _from_ one. |
| 42 | if (lite) { |
Derek Sollenberger | d7875f5 | 2017-03-01 15:33:23 -0500 | [diff] [blame] | 43 | fDL.reset(new SkLiteDL()); |
mtklein | 1d65fe2 | 2016-08-10 12:09:34 -0700 | [diff] [blame] | 44 | SkLiteRecorder r; |
Derek Sollenberger | d7875f5 | 2017-03-01 15:33:23 -0500 | [diff] [blame] | 45 | r.reset(fDL.get(), fSrc->cullRect().roundOut()); |
mtklein | 1d65fe2 | 2016-08-10 12:09:34 -0700 | [diff] [blame] | 46 | fSrc->playback(&r); |
| 47 | } |
mtklein | 8c1a4f8 | 2016-08-08 06:56:22 -0700 | [diff] [blame] | 48 | } |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 49 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 50 | void RecordingBench::onDraw(int loops, SkCanvas*) { |
mtklein | 1d65fe2 | 2016-08-10 12:09:34 -0700 | [diff] [blame] | 51 | if (fDL) { |
mtklein | 8c1a4f8 | 2016-08-08 06:56:22 -0700 | [diff] [blame] | 52 | SkLiteRecorder rec; |
| 53 | while (loops --> 0) { |
Derek Sollenberger | d7875f5 | 2017-03-01 15:33:23 -0500 | [diff] [blame] | 54 | SkLiteDL dl; |
| 55 | rec.reset(&dl, fSrc->cullRect().roundOut()); |
mtklein | 1d65fe2 | 2016-08-10 12:09:34 -0700 | [diff] [blame] | 56 | fDL->draw(&rec); |
mtklein | 8c1a4f8 | 2016-08-08 06:56:22 -0700 | [diff] [blame] | 57 | } |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 58 | |
mtklein | 8c1a4f8 | 2016-08-08 06:56:22 -0700 | [diff] [blame] | 59 | } else { |
| 60 | SkRTreeFactory factory; |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 61 | SkPictureRecorder recorder; |
mtklein | 8c1a4f8 | 2016-08-08 06:56:22 -0700 | [diff] [blame] | 62 | while (loops --> 0) { |
| 63 | fSrc->playback(recorder.beginRecording(fSrc->cullRect(), fUseBBH ? &factory : nullptr)); |
| 64 | (void)recorder.finishRecordingAsPicture(); |
| 65 | } |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 66 | } |
| 67 | } |
Mike Reed | 9cdd2ab | 2016-10-21 10:43:36 -0400 | [diff] [blame] | 68 | |
| 69 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame^] | 70 | #include "include/core/SkSerialProcs.h" |
Mike Reed | e45ff46 | 2017-12-06 10:47:03 -0500 | [diff] [blame] | 71 | |
| 72 | DeserializePictureBench::DeserializePictureBench(const char* name, sk_sp<SkData> data) |
| 73 | : fName(name) |
| 74 | , fEncodedPicture(std::move(data)) |
| 75 | {} |
| 76 | |
| 77 | const char* DeserializePictureBench::onGetName() { |
| 78 | return fName.c_str(); |
| 79 | } |
| 80 | |
| 81 | bool DeserializePictureBench::isSuitableFor(Backend backend) { |
| 82 | return backend == kNonRendering_Backend; |
| 83 | } |
| 84 | |
| 85 | SkIPoint DeserializePictureBench::onGetSize() { |
| 86 | return SkIPoint::Make(128, 128); |
| 87 | } |
| 88 | |
| 89 | void DeserializePictureBench::onDraw(int loops, SkCanvas*) { |
Mike Reed | e45ff46 | 2017-12-06 10:47:03 -0500 | [diff] [blame] | 90 | for (int i = 0; i < loops; ++i) { |
Mike Reed | 47fdf6c | 2017-12-20 14:12:07 -0500 | [diff] [blame] | 91 | SkPicture::MakeFromData(fEncodedPicture.get()); |
Mike Reed | e45ff46 | 2017-12-06 10:47:03 -0500 | [diff] [blame] | 92 | } |
| 93 | } |