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.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/RecordingBench.h"
|
|
|
|
#include "include/core/SkBBHFactory.h"
|
|
|
|
#include "include/core/SkPictureRecorder.h"
|
2014-09-10 19:19:30 +00:00
|
|
|
|
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
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2019-05-14 17:33:40 +00:00
|
|
|
RecordingBench::RecordingBench(const char* name, const SkPicture* pic, bool useBBH)
|
2016-10-21 14:43:36 +00:00
|
|
|
: INHERITED(name, pic)
|
|
|
|
, fUseBBH(useBBH)
|
2019-05-14 17:33:40 +00:00
|
|
|
{}
|
2016-10-21 14:43:36 +00:00
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void RecordingBench::onDraw(int loops, SkCanvas*) {
|
2019-05-14 17:33:40 +00:00
|
|
|
SkRTreeFactory factory;
|
|
|
|
SkPictureRecorder recorder;
|
|
|
|
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
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkSerialProcs.h"
|
2017-12-06 15:47:03 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|