xref: /third_party/skia/bench/RecordingBench.cpp (revision cb93a386)
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 "bench/RecordingBench.h"
9#include "include/core/SkBBHFactory.h"
10#include "include/core/SkPictureRecorder.h"
11
12PictureCentricBench::PictureCentricBench(const char* name, const SkPicture* pic) : fName(name) {
13    // 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();
18}
19
20const 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
35RecordingBench::RecordingBench(const char* name, const SkPicture* pic, bool useBBH)
36    : INHERITED(name, pic)
37    , fUseBBH(useBBH)
38{}
39
40void RecordingBench::onDraw(int loops, SkCanvas*) {
41    SkRTreeFactory factory;
42    SkPictureRecorder recorder;
43    while (loops --> 0) {
44        fSrc->playback(recorder.beginRecording(fSrc->cullRect(), fUseBBH ? &factory : nullptr));
45        (void)recorder.finishRecordingAsPicture();
46    }
47}
48
49///////////////////////////////////////////////////////////////////////////////////////////////////
50#include "include/core/SkSerialProcs.h"
51
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*) {
70    for (int i = 0; i < loops; ++i) {
71        SkPicture::MakeFromData(fEncodedPicture.get());
72    }
73}
74