• 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 "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 
71 #include "SkPipe.h"
72 #include "SkStream.h"
73 
PipingBench(const char * name,const SkPicture * pic)74 PipingBench::PipingBench(const char* name, const SkPicture* pic) : INHERITED(name, pic) {
75     fName.prepend("pipe_");
76 }
77 
onDraw(int loops,SkCanvas *)78 void PipingBench::onDraw(int loops, SkCanvas*) {
79     SkDynamicMemoryWStream stream;
80     SkPipeSerializer serializer;
81 
82     while (loops --> 0) {
83         fSrc->playback(serializer.beginWrite(fSrc->cullRect(), &stream));
84         serializer.endWrite();
85         stream.reset();
86     }
87 }
88