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" |
| 9 | |
| 10 | #include "SkBBHFactory.h" |
| 11 | #include "SkPictureRecorder.h" |
| 12 | |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 13 | RecordingBench::RecordingBench(const char* name, const SkPicture* pic, bool useBBH) |
| 14 | : fSrc(SkRef(pic)) |
| 15 | , fName(name) |
| 16 | , fUseBBH(useBBH) {} |
| 17 | |
| 18 | const char* RecordingBench::onGetName() { |
| 19 | return fName.c_str(); |
| 20 | } |
| 21 | |
| 22 | bool RecordingBench::isSuitableFor(Backend backend) { |
| 23 | return backend == kNonRendering_Backend; |
| 24 | } |
| 25 | |
| 26 | SkIPoint RecordingBench::onGetSize() { |
| 27 | return SkIPoint::Make(SkScalarCeilToInt(fSrc->cullRect().width()), |
| 28 | SkScalarCeilToInt(fSrc->cullRect().height())); |
| 29 | } |
| 30 | |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 31 | void RecordingBench::onDraw(int loops, SkCanvas*) { |
mtklein | 6838d85 | 2014-10-29 14:15:10 -0700 | [diff] [blame] | 32 | SkRTreeFactory factory; |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 33 | const SkScalar w = fSrc->cullRect().width(), |
| 34 | h = fSrc->cullRect().height(); |
| 35 | |
robertphillips | dda5445 | 2016-07-13 13:27:16 -0700 | [diff] [blame] | 36 | uint32_t flags = SkPictureRecorder::kPlaybackDrawPicture_RecordFlag; |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 37 | for (int i = 0; i < loops; i++) { |
| 38 | SkPictureRecorder recorder; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 39 | fSrc->playback(recorder.beginRecording(w, h, fUseBBH ? &factory : nullptr, flags)); |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 40 | (void)recorder.finishRecordingAsPicture(); |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 41 | } |
| 42 | } |