Home | History | Annotate | Download | only in bench
      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 
     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 
     22 const char* PictureCentricBench::onGetName() {
     23     return fName.c_str();
     24 }
     25 
     26 bool PictureCentricBench::isSuitableFor(Backend backend) {
     27     return backend == kNonRendering_Backend;
     28 }
     29 
     30 SkIPoint PictureCentricBench::onGetSize() {
     31     return SkIPoint::Make(SkScalarCeilToInt(fSrc->cullRect().width()),
     32                           SkScalarCeilToInt(fSrc->cullRect().height()));
     33 }
     34 
     35 ///////////////////////////////////////////////////////////////////////////////////////////////////
     36 
     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 
     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 
     74 PipingBench::PipingBench(const char* name, const SkPicture* pic) : INHERITED(name, pic) {
     75     fName.prepend("pipe_");
     76 }
     77 
     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 
     89 ///////////////////////////////////////////////////////////////////////////////////////////////////
     90 #include "SkSerialProcs.h"
     91 
     92 DeserializePictureBench::DeserializePictureBench(const char* name, sk_sp<SkData> data)
     93     : fName(name)
     94     , fEncodedPicture(std::move(data))
     95 {}
     96 
     97 const char* DeserializePictureBench::onGetName() {
     98     return fName.c_str();
     99 }
    100 
    101 bool DeserializePictureBench::isSuitableFor(Backend backend) {
    102     return backend == kNonRendering_Backend;
    103 }
    104 
    105 SkIPoint DeserializePictureBench::onGetSize() {
    106     return SkIPoint::Make(128, 128);
    107 }
    108 
    109 void DeserializePictureBench::onDraw(int loops, SkCanvas*) {
    110     for (int i = 0; i < loops; ++i) {
    111         SkPicture::MakeFromData(fEncodedPicture.get());
    112     }
    113 }
    114