2014-09-10 19:19:30 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "RecordingBench.h"
|
|
|
|
#include "SkBBHFactory.h"
|
2016-08-08 13:56:22 +00:00
|
|
|
#include "SkLiteDL.h"
|
|
|
|
#include "SkLiteRecorder.h"
|
2014-09-10 19:19:30 +00:00
|
|
|
#include "SkPictureRecorder.h"
|
|
|
|
|
2016-10-21 14:43:36 +00:00
|
|
|
PictureCentricBench::PictureCentricBench(const char* name, const SkPicture* pic) : fName(name) {
|
2016-08-08 13:56:22 +00:00
|
|
|
// Flatten the source picture in case it's trivially nested (useless for timing).
|
|
|
|
SkPictureRecorder rec;
|
|
|
|
pic->playback(rec.beginRecording(pic->cullRect(), nullptr,
|
|
|
|
SkPictureRecorder::kPlaybackDrawPicture_RecordFlag));
|
|
|
|
fSrc = rec.finishRecordingAsPicture();
|
|
|
|
}
|
2014-09-10 19:19:30 +00:00
|
|
|
|
2016-10-21 14:43:36 +00:00
|
|
|
const char* PictureCentricBench::onGetName() {
|
2014-09-10 19:19:30 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2016-10-21 14:43:36 +00:00
|
|
|
bool PictureCentricBench::isSuitableFor(Backend backend) {
|
2014-09-10 19:19:30 +00:00
|
|
|
return backend == kNonRendering_Backend;
|
|
|
|
}
|
|
|
|
|
2016-10-21 14:43:36 +00:00
|
|
|
SkIPoint PictureCentricBench::onGetSize() {
|
2014-09-10 19:19:30 +00:00
|
|
|
return SkIPoint::Make(SkScalarCeilToInt(fSrc->cullRect().width()),
|
|
|
|
SkScalarCeilToInt(fSrc->cullRect().height()));
|
|
|
|
}
|
|
|
|
|
2016-10-21 14:43:36 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
RecordingBench::RecordingBench(const char* name, const SkPicture* pic, bool useBBH, bool lite)
|
|
|
|
: INHERITED(name, pic)
|
|
|
|
, fUseBBH(useBBH)
|
|
|
|
{
|
|
|
|
// If we're recording into an SkLiteDL, also record _from_ one.
|
|
|
|
if (lite) {
|
|
|
|
fDL = SkLiteDL::New(fSrc->cullRect());
|
|
|
|
SkLiteRecorder r;
|
|
|
|
r.reset(fDL.get());
|
|
|
|
fSrc->playback(&r);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void RecordingBench::onDraw(int loops, SkCanvas*) {
|
2016-08-10 19:09:34 +00:00
|
|
|
if (fDL) {
|
2016-08-08 13:56:22 +00:00
|
|
|
SkLiteRecorder rec;
|
|
|
|
while (loops --> 0) {
|
|
|
|
sk_sp<SkLiteDL> dl = SkLiteDL::New(fSrc->cullRect());
|
|
|
|
rec.reset(dl.get());
|
2016-08-10 19:09:34 +00:00
|
|
|
fDL->draw(&rec);
|
2016-08-08 13:56:22 +00:00
|
|
|
dl->makeThreadsafe();
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
SkRTreeFactory factory;
|
2014-09-10 19:19:30 +00:00
|
|
|
SkPictureRecorder recorder;
|
2016-08-08 13:56:22 +00:00
|
|
|
while (loops --> 0) {
|
|
|
|
fSrc->playback(recorder.beginRecording(fSrc->cullRect(), fUseBBH ? &factory : nullptr));
|
|
|
|
(void)recorder.finishRecordingAsPicture();
|
|
|
|
}
|
2014-09-10 19:19:30 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-21 14:43:36 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "SkPipe.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
|
|
|
|
PipingBench::PipingBench(const char* name, const SkPicture* pic) : INHERITED(name, pic) {
|
|
|
|
fName.prepend("pipe_");
|
|
|
|
}
|
|
|
|
|
|
|
|
void PipingBench::onDraw(int loops, SkCanvas*) {
|
|
|
|
SkDynamicMemoryWStream stream;
|
|
|
|
SkPipeSerializer serializer;
|
|
|
|
|
|
|
|
while (loops --> 0) {
|
|
|
|
fSrc->playback(serializer.beginWrite(fSrc->cullRect(), &stream));
|
|
|
|
serializer.endWrite();
|
|
|
|
stream.reset();
|
|
|
|
}
|
|
|
|
}
|