blob: 69be9114674e5b084e338abe79614f2485ea882b [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) {
Mike Reed9cdd2ab2016-10-21 10:43:36 -040043 fDL = SkLiteDL::New(fSrc->cullRect());
mtklein1d65fe22016-08-10 12:09:34 -070044 SkLiteRecorder r;
45 r.reset(fDL.get());
46 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) {
54 sk_sp<SkLiteDL> dl = SkLiteDL::New(fSrc->cullRect());
55 rec.reset(dl.get());
mtklein1d65fe22016-08-10 12:09:34 -070056 fDL->draw(&rec);
mtklein8c1a4f82016-08-08 06:56:22 -070057 dl->makeThreadsafe();
58 }
mtkleinfd731ce2014-09-10 12:19:30 -070059
mtklein8c1a4f82016-08-08 06:56:22 -070060 } else {
61 SkRTreeFactory factory;
mtkleinfd731ce2014-09-10 12:19:30 -070062 SkPictureRecorder recorder;
mtklein8c1a4f82016-08-08 06:56:22 -070063 while (loops --> 0) {
64 fSrc->playback(recorder.beginRecording(fSrc->cullRect(), fUseBBH ? &factory : nullptr));
65 (void)recorder.finishRecordingAsPicture();
66 }
mtkleinfd731ce2014-09-10 12:19:30 -070067 }
68}
Mike Reed9cdd2ab2016-10-21 10:43:36 -040069
70///////////////////////////////////////////////////////////////////////////////////////////////////
71
72#include "SkPipe.h"
73#include "SkStream.h"
74
75PipingBench::PipingBench(const char* name, const SkPicture* pic) : INHERITED(name, pic) {
76 fName.prepend("pipe_");
77}
78
79void PipingBench::onDraw(int loops, SkCanvas*) {
80 SkDynamicMemoryWStream stream;
81 SkPipeSerializer serializer;
82
83 while (loops --> 0) {
84 fSrc->playback(serializer.beginWrite(fSrc->cullRect(), &stream));
85 serializer.endWrite();
86 stream.reset();
87 }
88}