• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
PictureCentricBench(const char * name,const SkPicture * pic)12 PictureCentricBench::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 
onGetName()20 const char* PictureCentricBench::onGetName() {
21     return fName.c_str();
22 }
23 
isSuitableFor(Backend backend)24 bool PictureCentricBench::isSuitableFor(Backend backend) {
25     return backend == kNonRendering_Backend;
26 }
27 
onGetSize()28 SkIPoint PictureCentricBench::onGetSize() {
29     return SkIPoint::Make(SkScalarCeilToInt(fSrc->cullRect().width()),
30                           SkScalarCeilToInt(fSrc->cullRect().height()));
31 }
32 
33 ///////////////////////////////////////////////////////////////////////////////////////////////////
34 
RecordingBench(const char * name,const SkPicture * pic,bool useBBH)35 RecordingBench::RecordingBench(const char* name, const SkPicture* pic, bool useBBH)
36     : INHERITED(name, pic)
37     , fUseBBH(useBBH)
38 {}
39 
onDraw(int loops,SkCanvas *)40 void 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 
DeserializePictureBench(const char * name,sk_sp<SkData> data)52 DeserializePictureBench::DeserializePictureBench(const char* name, sk_sp<SkData> data)
53     : fName(name)
54     , fEncodedPicture(std::move(data))
55 {}
56 
onGetName()57 const char* DeserializePictureBench::onGetName() {
58     return fName.c_str();
59 }
60 
isSuitableFor(Backend backend)61 bool DeserializePictureBench::isSuitableFor(Backend backend) {
62     return backend == kNonRendering_Backend;
63 }
64 
onGetSize()65 SkIPoint DeserializePictureBench::onGetSize() {
66     return SkIPoint::Make(128, 128);
67 }
68 
onDraw(int loops,SkCanvas *)69 void DeserializePictureBench::onDraw(int loops, SkCanvas*) {
70     for (int i = 0; i < loops; ++i) {
71         SkPicture::MakeFromData(fEncodedPicture.get());
72     }
73 }
74