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" |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 11 | |
Mike Reed | 9cdd2ab | 2016-10-21 10:43:36 -0400 | [diff] [blame] | 12 | PictureCentricBench::PictureCentricBench(const char* name, const SkPicture* pic) : fName(name) { |
mtklein | 8c1a4f8 | 2016-08-08 06:56:22 -0700 | [diff] [blame] | 13 | // Flatten the source picture in case it's trivially nested (useless for timing). |
| 14 | SkPictureRecorder rec; |
| 15 | pic->playback(rec.beginRecording(pic->cullRect(), nullptr, |
| 16 | SkPictureRecorder::kPlaybackDrawPicture_RecordFlag)); |
| 17 | fSrc = rec.finishRecordingAsPicture(); |
Mike Reed | 9cdd2ab | 2016-10-21 10:43:36 -0400 | [diff] [blame] | 18 | } |
mtklein | 1d65fe2 | 2016-08-10 12:09:34 -0700 | [diff] [blame] | 19 | |
Mike Reed | 9cdd2ab | 2016-10-21 10:43:36 -0400 | [diff] [blame] | 20 | const char* PictureCentricBench::onGetName() { |
| 21 | return fName.c_str(); |
| 22 | } |
| 23 | |
| 24 | bool PictureCentricBench::isSuitableFor(Backend backend) { |
| 25 | return backend == kNonRendering_Backend; |
| 26 | } |
| 27 | |
| 28 | SkIPoint PictureCentricBench::onGetSize() { |
| 29 | return SkIPoint::Make(SkScalarCeilToInt(fSrc->cullRect().width()), |
| 30 | SkScalarCeilToInt(fSrc->cullRect().height())); |
| 31 | } |
| 32 | |
| 33 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 34 | |
Mike Klein | a705cb9 | 2019-05-14 12:33:40 -0500 | [diff] [blame] | 35 | RecordingBench::RecordingBench(const char* name, const SkPicture* pic, bool useBBH) |
Mike Reed | 9cdd2ab | 2016-10-21 10:43:36 -0400 | [diff] [blame] | 36 | : INHERITED(name, pic) |
| 37 | , fUseBBH(useBBH) |
Mike Klein | a705cb9 | 2019-05-14 12:33:40 -0500 | [diff] [blame] | 38 | {} |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 39 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 40 | void RecordingBench::onDraw(int loops, SkCanvas*) { |
Mike Klein | a705cb9 | 2019-05-14 12:33:40 -0500 | [diff] [blame] | 41 | SkRTreeFactory factory; |
| 42 | SkPictureRecorder recorder; |
| 43 | while (loops --> 0) { |
| 44 | fSrc->playback(recorder.beginRecording(fSrc->cullRect(), fUseBBH ? &factory : nullptr)); |
| 45 | (void)recorder.finishRecordingAsPicture(); |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 46 | } |
| 47 | } |
Mike Reed | 9cdd2ab | 2016-10-21 10:43:36 -0400 | [diff] [blame] | 48 | |
| 49 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 50 | #include "include/core/SkSerialProcs.h" |
Mike Reed | e45ff46 | 2017-12-06 10:47:03 -0500 | [diff] [blame] | 51 | |
| 52 | DeserializePictureBench::DeserializePictureBench(const char* name, sk_sp<SkData> data) |
| 53 | : fName(name) |
| 54 | , fEncodedPicture(std::move(data)) |
| 55 | {} |
| 56 | |
| 57 | const char* DeserializePictureBench::onGetName() { |
| 58 | return fName.c_str(); |
| 59 | } |
| 60 | |
| 61 | bool DeserializePictureBench::isSuitableFor(Backend backend) { |
| 62 | return backend == kNonRendering_Backend; |
| 63 | } |
| 64 | |
| 65 | SkIPoint DeserializePictureBench::onGetSize() { |
| 66 | return SkIPoint::Make(128, 128); |
| 67 | } |
| 68 | |
| 69 | void DeserializePictureBench::onDraw(int loops, SkCanvas*) { |
Mike Reed | e45ff46 | 2017-12-06 10:47:03 -0500 | [diff] [blame] | 70 | for (int i = 0; i < loops; ++i) { |
Mike Reed | 47fdf6c | 2017-12-20 14:12:07 -0500 | [diff] [blame] | 71 | SkPicture::MakeFromData(fEncodedPicture.get()); |
Mike Reed | e45ff46 | 2017-12-06 10:47:03 -0500 | [diff] [blame] | 72 | } |
| 73 | } |