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) {
|
2017-03-01 20:33:23 +00:00
|
|
|
fDL.reset(new SkLiteDL());
|
2016-10-21 14:43:36 +00:00
|
|
|
SkLiteRecorder r;
|
2017-03-01 20:33:23 +00:00
|
|
|
r.reset(fDL.get(), fSrc->cullRect().roundOut());
|
2016-10-21 14:43:36 +00:00
|
|
|
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) {
|
2017-03-01 20:33:23 +00:00
|
|
|
SkLiteDL dl;
|
|
|
|
rec.reset(&dl, fSrc->cullRect().roundOut());
|
2016-08-10 19:09:34 +00:00
|
|
|
fDL->draw(&rec);
|
2016-08-08 13:56:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} 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
|
|
|
|
2017-12-06 15:47:03 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "SkSerialProcs.h"
|
|
|
|
|
|
|
|
DeserializePictureBench::DeserializePictureBench(const char* name, sk_sp<SkData> data)
|
|
|
|
: fName(name)
|
|
|
|
, fEncodedPicture(std::move(data))
|
|
|
|
{}
|
|
|
|
|
|
|
|
const char* DeserializePictureBench::onGetName() {
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DeserializePictureBench::isSuitableFor(Backend backend) {
|
|
|
|
return backend == kNonRendering_Backend;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkIPoint DeserializePictureBench::onGetSize() {
|
|
|
|
return SkIPoint::Make(128, 128);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeserializePictureBench::onDraw(int loops, SkCanvas*) {
|
|
|
|
for (int i = 0; i < loops; ++i) {
|
2017-12-20 19:12:07 +00:00
|
|
|
SkPicture::MakeFromData(fEncodedPicture.get());
|
2017-12-06 15:47:03 +00:00
|
|
|
}
|
|
|
|
}
|