aboutsummaryrefslogtreecommitdiffhomepage
path: root/bench/RecordingBench.cpp
blob: cd029ddf14eeb0c1242455fac6c064a08065d2bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
 * Copyright 2014 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "RecordingBench.h"

#include "SkBBHFactory.h"
#include "SkPictureRecorder.h"

RecordingBench::RecordingBench(const char* name, const SkPicture* pic, bool useBBH)
    : fSrc(SkRef(pic))
    , fName(name)
    , fUseBBH(useBBH) {}

const char* RecordingBench::onGetName() {
    return fName.c_str();
}

bool RecordingBench::isSuitableFor(Backend backend) {
    return backend == kNonRendering_Backend;
}

SkIPoint RecordingBench::onGetSize() {
    return SkIPoint::Make(SkScalarCeilToInt(fSrc->cullRect().width()),
                          SkScalarCeilToInt(fSrc->cullRect().height()));
}

void RecordingBench::onDraw(const int loops, SkCanvas*) {
    SkRTreeFactory factory;
    const SkScalar w = fSrc->cullRect().width(),
                   h = fSrc->cullRect().height();

    for (int i = 0; i < loops; i++) {
        SkPictureRecorder recorder;
        fSrc->playback(recorder.beginRecording(w, h, fUseBBH ? &factory : NULL,
                                               SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag));
        SkSafeUnref(recorder.endRecording());
    }
}