blob: 833bb229cc7ea9a5effae9e30c31584e3c7ef0d6 [file] [log] [blame]
mtkleinfd731ce2014-09-10 12:19:30 -07001/*
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
mtkleinfd731ce2014-09-10 12:19:30 -070013RecordingBench::RecordingBench(const char* name, const SkPicture* pic, bool useBBH)
14 : fSrc(SkRef(pic))
15 , fName(name)
16 , fUseBBH(useBBH) {}
17
18const char* RecordingBench::onGetName() {
19 return fName.c_str();
20}
21
22bool RecordingBench::isSuitableFor(Backend backend) {
23 return backend == kNonRendering_Backend;
24}
25
26SkIPoint RecordingBench::onGetSize() {
27 return SkIPoint::Make(SkScalarCeilToInt(fSrc->cullRect().width()),
28 SkScalarCeilToInt(fSrc->cullRect().height()));
29}
30
mtkleina1ebeb22015-10-01 09:43:39 -070031void RecordingBench::onDraw(int loops, SkCanvas*) {
mtklein6838d852014-10-29 14:15:10 -070032 SkRTreeFactory factory;
mtkleinfd731ce2014-09-10 12:19:30 -070033 const SkScalar w = fSrc->cullRect().width(),
34 h = fSrc->cullRect().height();
35
robertphillipsdda54452016-07-13 13:27:16 -070036 uint32_t flags = SkPictureRecorder::kPlaybackDrawPicture_RecordFlag;
mtkleinfd731ce2014-09-10 12:19:30 -070037 for (int i = 0; i < loops; i++) {
38 SkPictureRecorder recorder;
halcanary96fcdcc2015-08-27 07:41:13 -070039 fSrc->playback(recorder.beginRecording(w, h, fUseBBH ? &factory : nullptr, flags));
reedca2622b2016-03-18 07:25:55 -070040 (void)recorder.finishRecordingAsPicture();
mtkleinfd731ce2014-09-10 12:19:30 -070041 }
42}