blob: a6ca1175ae0f19776cb4d11e61e3d9a5e54fddb2 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "bench/RecordingBench.h"
9#include "include/core/SkBBHFactory.h"
10#include "include/core/SkPictureRecorder.h"
mtkleinfd731ce2014-09-10 12:19:30 -070011
Mike Reed9cdd2ab2016-10-21 10:43:36 -040012PictureCentricBench::PictureCentricBench(const char* name, const SkPicture* pic) : fName(name) {
mtklein8c1a4f82016-08-08 06:56:22 -070013 // 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 Reed9cdd2ab2016-10-21 10:43:36 -040018}
mtklein1d65fe22016-08-10 12:09:34 -070019
Mike Reed9cdd2ab2016-10-21 10:43:36 -040020const char* PictureCentricBench::onGetName() {
21 return fName.c_str();
22}
23
24bool PictureCentricBench::isSuitableFor(Backend backend) {
25 return backend == kNonRendering_Backend;
26}
27
28SkIPoint PictureCentricBench::onGetSize() {
29 return SkIPoint::Make(SkScalarCeilToInt(fSrc->cullRect().width()),
30 SkScalarCeilToInt(fSrc->cullRect().height()));
31}
32
33///////////////////////////////////////////////////////////////////////////////////////////////////
34
Mike Kleina705cb92019-05-14 12:33:40 -050035RecordingBench::RecordingBench(const char* name, const SkPicture* pic, bool useBBH)
Mike Reed9cdd2ab2016-10-21 10:43:36 -040036 : INHERITED(name, pic)
37 , fUseBBH(useBBH)
Mike Kleina705cb92019-05-14 12:33:40 -050038{}
mtkleinfd731ce2014-09-10 12:19:30 -070039
mtkleina1ebeb22015-10-01 09:43:39 -070040void RecordingBench::onDraw(int loops, SkCanvas*) {
Mike Kleina705cb92019-05-14 12:33:40 -050041 SkRTreeFactory factory;
42 SkPictureRecorder recorder;
43 while (loops --> 0) {
44 fSrc->playback(recorder.beginRecording(fSrc->cullRect(), fUseBBH ? &factory : nullptr));
45 (void)recorder.finishRecordingAsPicture();
mtkleinfd731ce2014-09-10 12:19:30 -070046 }
47}
Mike Reed9cdd2ab2016-10-21 10:43:36 -040048
49///////////////////////////////////////////////////////////////////////////////////////////////////
Mike Kleinc0bd9f92019-04-23 12:05:21 -050050#include "include/core/SkSerialProcs.h"
Mike Reede45ff462017-12-06 10:47:03 -050051
52DeserializePictureBench::DeserializePictureBench(const char* name, sk_sp<SkData> data)
53 : fName(name)
54 , fEncodedPicture(std::move(data))
55{}
56
57const char* DeserializePictureBench::onGetName() {
58 return fName.c_str();
59}
60
61bool DeserializePictureBench::isSuitableFor(Backend backend) {
62 return backend == kNonRendering_Backend;
63}
64
65SkIPoint DeserializePictureBench::onGetSize() {
66 return SkIPoint::Make(128, 128);
67}
68
69void DeserializePictureBench::onDraw(int loops, SkCanvas*) {
Mike Reede45ff462017-12-06 10:47:03 -050070 for (int i = 0; i < loops; ++i) {
Mike Reed47fdf6c2017-12-20 14:12:07 -050071 SkPicture::MakeFromData(fEncodedPicture.get());
Mike Reede45ff462017-12-06 10:47:03 -050072 }
73}