blob: d23d4f494759c7bea24c8c373db76c7a748f5b9a [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"
mtkleinfd731ce2014-09-10 12:19:30 -07009#include "SkBBHFactory.h"
mtklein8c1a4f82016-08-08 06:56:22 -070010#include "SkLiteDL.h"
11#include "SkLiteRecorder.h"
mtkleinfd731ce2014-09-10 12:19:30 -070012#include "SkPictureRecorder.h"
13
Mike Reed9cdd2ab2016-10-21 10:43:36 -040014PictureCentricBench::PictureCentricBench(const char* name, const SkPicture* pic) : fName(name) {
mtklein8c1a4f82016-08-08 06:56:22 -070015 // 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 Reed9cdd2ab2016-10-21 10:43:36 -040020}
mtklein1d65fe22016-08-10 12:09:34 -070021
Mike Reed9cdd2ab2016-10-21 10:43:36 -040022const char* PictureCentricBench::onGetName() {
23 return fName.c_str();
24}
25
26bool PictureCentricBench::isSuitableFor(Backend backend) {
27 return backend == kNonRendering_Backend;
28}
29
30SkIPoint PictureCentricBench::onGetSize() {
31 return SkIPoint::Make(SkScalarCeilToInt(fSrc->cullRect().width()),
32 SkScalarCeilToInt(fSrc->cullRect().height()));
33}
34
35///////////////////////////////////////////////////////////////////////////////////////////////////
36
37RecordingBench::RecordingBench(const char* name, const SkPicture* pic, bool useBBH, bool lite)
38 : INHERITED(name, pic)
39 , fUseBBH(useBBH)
40{
mtklein1d65fe22016-08-10 12:09:34 -070041 // If we're recording into an SkLiteDL, also record _from_ one.
42 if (lite) {
Derek Sollenbergerd7875f52017-03-01 15:33:23 -050043 fDL.reset(new SkLiteDL());
mtklein1d65fe22016-08-10 12:09:34 -070044 SkLiteRecorder r;
Derek Sollenbergerd7875f52017-03-01 15:33:23 -050045 r.reset(fDL.get(), fSrc->cullRect().roundOut());
mtklein1d65fe22016-08-10 12:09:34 -070046 fSrc->playback(&r);
47 }
mtklein8c1a4f82016-08-08 06:56:22 -070048}
mtkleinfd731ce2014-09-10 12:19:30 -070049
mtkleina1ebeb22015-10-01 09:43:39 -070050void RecordingBench::onDraw(int loops, SkCanvas*) {
mtklein1d65fe22016-08-10 12:09:34 -070051 if (fDL) {
mtklein8c1a4f82016-08-08 06:56:22 -070052 SkLiteRecorder rec;
53 while (loops --> 0) {
Derek Sollenbergerd7875f52017-03-01 15:33:23 -050054 SkLiteDL dl;
55 rec.reset(&dl, fSrc->cullRect().roundOut());
mtklein1d65fe22016-08-10 12:09:34 -070056 fDL->draw(&rec);
mtklein8c1a4f82016-08-08 06:56:22 -070057 }
mtkleinfd731ce2014-09-10 12:19:30 -070058
mtklein8c1a4f82016-08-08 06:56:22 -070059 } else {
60 SkRTreeFactory factory;
mtkleinfd731ce2014-09-10 12:19:30 -070061 SkPictureRecorder recorder;
mtklein8c1a4f82016-08-08 06:56:22 -070062 while (loops --> 0) {
63 fSrc->playback(recorder.beginRecording(fSrc->cullRect(), fUseBBH ? &factory : nullptr));
64 (void)recorder.finishRecordingAsPicture();
65 }
mtkleinfd731ce2014-09-10 12:19:30 -070066 }
67}
Mike Reed9cdd2ab2016-10-21 10:43:36 -040068
69///////////////////////////////////////////////////////////////////////////////////////////////////
70
71#include "SkPipe.h"
72#include "SkStream.h"
73
74PipingBench::PipingBench(const char* name, const SkPicture* pic) : INHERITED(name, pic) {
75 fName.prepend("pipe_");
76}
77
78void PipingBench::onDraw(int loops, SkCanvas*) {
79 SkDynamicMemoryWStream stream;
80 SkPipeSerializer serializer;
81
82 while (loops --> 0) {
83 fSrc->playback(serializer.beginWrite(fSrc->cullRect(), &stream));
84 serializer.endWrite();
85 stream.reset();
86 }
87}
Mike Reede45ff462017-12-06 10:47:03 -050088
89///////////////////////////////////////////////////////////////////////////////////////////////////
90#include "SkSerialProcs.h"
91
92DeserializePictureBench::DeserializePictureBench(const char* name, sk_sp<SkData> data)
93 : fName(name)
94 , fEncodedPicture(std::move(data))
95{}
96
97const char* DeserializePictureBench::onGetName() {
98 return fName.c_str();
99}
100
101bool DeserializePictureBench::isSuitableFor(Backend backend) {
102 return backend == kNonRendering_Backend;
103}
104
105SkIPoint DeserializePictureBench::onGetSize() {
106 return SkIPoint::Make(128, 128);
107}
108
109void DeserializePictureBench::onDraw(int loops, SkCanvas*) {
Mike Reede45ff462017-12-06 10:47:03 -0500110 for (int i = 0; i < loops; ++i) {
Mike Reed47fdf6c2017-12-20 14:12:07 -0500111 SkPicture::MakeFromData(fEncodedPicture.get());
Mike Reede45ff462017-12-06 10:47:03 -0500112 }
113}