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 | |
| 8 | #include "RecordingBench.h" |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 9 | #include "SkBBHFactory.h" |
mtklein | 8c1a4f8 | 2016-08-08 06:56:22 -0700 | [diff] [blame] | 10 | #include "SkLiteDL.h" |
| 11 | #include "SkLiteRecorder.h" |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 12 | #include "SkPictureRecorder.h" |
| 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 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 70 | |
| 71 | #include "SkPipe.h" |
| 72 | #include "SkStream.h" |
| 73 | |
| 74 | PipingBench::PipingBench(const char* name, const SkPicture* pic) : INHERITED(name, pic) { |
| 75 | fName.prepend("pipe_"); |
| 76 | } |
| 77 | |
| 78 | void PipingBench::onDraw(int loops, SkCanvas*) { |
| 79 | SkDynamicMemoryWStream stream; |
| 80 | SkPipeSerializer serializer; |
| 81 | |
| 82 | while (loops --> 0) { |
| 83 | fSrc->playback(serializer.beginWrite(fSrc->cullRect(), &stream)); |
| 84 | serializer.endWrite(); |
| 85 | stream.reset(); |
| 86 | } |
| 87 | } |
Mike Reed | e45ff46 | 2017-12-06 10:47:03 -0500 | [diff] [blame] | 88 | |
| 89 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 90 | #include "SkSerialProcs.h" |
| 91 | |
| 92 | DeserializePictureBench::DeserializePictureBench(const char* name, sk_sp<SkData> data) |
| 93 | : fName(name) |
| 94 | , fEncodedPicture(std::move(data)) |
| 95 | {} |
| 96 | |
| 97 | const char* DeserializePictureBench::onGetName() { |
| 98 | return fName.c_str(); |
| 99 | } |
| 100 | |
| 101 | bool DeserializePictureBench::isSuitableFor(Backend backend) { |
| 102 | return backend == kNonRendering_Backend; |
| 103 | } |
| 104 | |
| 105 | SkIPoint DeserializePictureBench::onGetSize() { |
| 106 | return SkIPoint::Make(128, 128); |
| 107 | } |
| 108 | |
| 109 | void DeserializePictureBench::onDraw(int loops, SkCanvas*) { |
Mike Reed | e45ff46 | 2017-12-06 10:47:03 -0500 | [diff] [blame] | 110 | for (int i = 0; i < loops; ++i) { |
Mike Reed | 47fdf6c | 2017-12-20 14:12:07 -0500 | [diff] [blame] | 111 | SkPicture::MakeFromData(fEncodedPicture.get()); |
Mike Reed | e45ff46 | 2017-12-06 10:47:03 -0500 | [diff] [blame] | 112 | } |
| 113 | } |