Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / bench / RecordingBench.cpp
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 "RecordingBench.h"
9
10 #include "SkBBHFactory.h"
11 #include "SkPictureRecorder.h"
12
13 RecordingBench::RecordingBench(const char* name, const SkPicture* pic, bool useBBH)
14     : fSrc(SkRef(pic))
15     , fName(name)
16     , fUseBBH(useBBH) {}
17
18 const char* RecordingBench::onGetName() {
19     return fName.c_str();
20 }
21
22 bool RecordingBench::isSuitableFor(Backend backend) {
23     return backend == kNonRendering_Backend;
24 }
25
26 SkIPoint RecordingBench::onGetSize() {
27     return SkIPoint::Make(SkScalarCeilToInt(fSrc->cullRect().width()),
28                           SkScalarCeilToInt(fSrc->cullRect().height()));
29 }
30
31 void RecordingBench::onDraw(const int loops, SkCanvas*) {
32     SkRTreeFactory factory;
33     const SkScalar w = fSrc->cullRect().width(),
34                    h = fSrc->cullRect().height();
35
36     for (int i = 0; i < loops; i++) {
37         SkPictureRecorder recorder;
38         fSrc->playback(recorder.beginRecording(w, h, fUseBBH ? &factory : NULL));
39         SkDELETE(recorder.endRecording());
40     }
41 }