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 #include "SkBBHFactory.h"
10 #include "SkLiteDL.h"
11 #include "SkLiteRecorder.h"
12 #include "SkPictureRecorder.h"
13
PictureCentricBench(const char * name,const SkPicture * pic)14 PictureCentricBench::PictureCentricBench(const char* name, const SkPicture* pic) : fName(name) {
15 // 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();
20 }
21
onGetName()22 const char* PictureCentricBench::onGetName() {
23 return fName.c_str();
24 }
25
isSuitableFor(Backend backend)26 bool PictureCentricBench::isSuitableFor(Backend backend) {
27 return backend == kNonRendering_Backend;
28 }
29
onGetSize()30 SkIPoint PictureCentricBench::onGetSize() {
31 return SkIPoint::Make(SkScalarCeilToInt(fSrc->cullRect().width()),
32 SkScalarCeilToInt(fSrc->cullRect().height()));
33 }
34
35 ///////////////////////////////////////////////////////////////////////////////////////////////////
36
RecordingBench(const char * name,const SkPicture * pic,bool useBBH,bool lite)37 RecordingBench::RecordingBench(const char* name, const SkPicture* pic, bool useBBH, bool lite)
38 : INHERITED(name, pic)
39 , fUseBBH(useBBH)
40 {
41 // If we're recording into an SkLiteDL, also record _from_ one.
42 if (lite) {
43 fDL.reset(new SkLiteDL());
44 SkLiteRecorder r;
45 r.reset(fDL.get(), fSrc->cullRect().roundOut());
46 fSrc->playback(&r);
47 }
48 }
49
onDraw(int loops,SkCanvas *)50 void RecordingBench::onDraw(int loops, SkCanvas*) {
51 if (fDL) {
52 SkLiteRecorder rec;
53 while (loops --> 0) {
54 SkLiteDL dl;
55 rec.reset(&dl, fSrc->cullRect().roundOut());
56 fDL->draw(&rec);
57 }
58
59 } else {
60 SkRTreeFactory factory;
61 SkPictureRecorder recorder;
62 while (loops --> 0) {
63 fSrc->playback(recorder.beginRecording(fSrc->cullRect(), fUseBBH ? &factory : nullptr));
64 (void)recorder.finishRecordingAsPicture();
65 }
66 }
67 }
68
69 ///////////////////////////////////////////////////////////////////////////////////////////////////
70 #include "SkSerialProcs.h"
71
DeserializePictureBench(const char * name,sk_sp<SkData> data)72 DeserializePictureBench::DeserializePictureBench(const char* name, sk_sp<SkData> data)
73 : fName(name)
74 , fEncodedPicture(std::move(data))
75 {}
76
onGetName()77 const char* DeserializePictureBench::onGetName() {
78 return fName.c_str();
79 }
80
isSuitableFor(Backend backend)81 bool DeserializePictureBench::isSuitableFor(Backend backend) {
82 return backend == kNonRendering_Backend;
83 }
84
onGetSize()85 SkIPoint DeserializePictureBench::onGetSize() {
86 return SkIPoint::Make(128, 128);
87 }
88
onDraw(int loops,SkCanvas *)89 void DeserializePictureBench::onDraw(int loops, SkCanvas*) {
90 for (int i = 0; i < loops; ++i) {
91 SkPicture::MakeFromData(fEncodedPicture.get());
92 }
93 }
94