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) { |
Mike Reed | 9cdd2ab | 2016-10-21 10:43:36 -0400 | [diff] [blame] | 43 | fDL = SkLiteDL::New(fSrc->cullRect()); |
mtklein | 1d65fe2 | 2016-08-10 12:09:34 -0700 | [diff] [blame] | 44 | SkLiteRecorder r; |
| 45 | r.reset(fDL.get()); |
| 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) { |
| 54 | sk_sp<SkLiteDL> dl = SkLiteDL::New(fSrc->cullRect()); |
| 55 | rec.reset(dl.get()); |
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 | dl->makeThreadsafe(); |
| 58 | } |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 59 | |
mtklein | 8c1a4f8 | 2016-08-08 06:56:22 -0700 | [diff] [blame] | 60 | } else { |
| 61 | SkRTreeFactory factory; |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 62 | SkPictureRecorder recorder; |
mtklein | 8c1a4f8 | 2016-08-08 06:56:22 -0700 | [diff] [blame] | 63 | while (loops --> 0) { |
| 64 | fSrc->playback(recorder.beginRecording(fSrc->cullRect(), fUseBBH ? &factory : nullptr)); |
| 65 | (void)recorder.finishRecordingAsPicture(); |
| 66 | } |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 67 | } |
| 68 | } |
Mike Reed | 9cdd2ab | 2016-10-21 10:43:36 -0400 | [diff] [blame] | 69 | |
| 70 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 71 | |
| 72 | #include "SkPipe.h" |
| 73 | #include "SkStream.h" |
| 74 | |
| 75 | PipingBench::PipingBench(const char* name, const SkPicture* pic) : INHERITED(name, pic) { |
| 76 | fName.prepend("pipe_"); |
| 77 | } |
| 78 | |
| 79 | void PipingBench::onDraw(int loops, SkCanvas*) { |
| 80 | SkDynamicMemoryWStream stream; |
| 81 | SkPipeSerializer serializer; |
| 82 | |
| 83 | while (loops --> 0) { |
| 84 | fSrc->playback(serializer.beginWrite(fSrc->cullRect(), &stream)); |
| 85 | serializer.endWrite(); |
| 86 | stream.reset(); |
| 87 | } |
| 88 | } |