2015-06-30 14:43:14 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <VisualBench/VisualBenchmarkStream.h>
|
|
|
|
#include "GMBench.h"
|
|
|
|
#include "SkOSFile.h"
|
|
|
|
#include "SkPictureRecorder.h"
|
|
|
|
#include "SkStream.h"
|
|
|
|
#include "VisualSKPBench.h"
|
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
DEFINE_string2(match, m, nullptr,
|
2015-06-30 14:43:14 +00:00
|
|
|
"[~][^]substring[$] [...] of bench name to run.\n"
|
|
|
|
"Multiple matches may be separated by spaces.\n"
|
|
|
|
"~ causes a matching bench to always be skipped\n"
|
|
|
|
"^ requires the start of the bench to match\n"
|
|
|
|
"$ requires the end of the bench to match\n"
|
|
|
|
"^ and $ requires an exact match\n"
|
|
|
|
"If a bench does not match any list entry,\n"
|
|
|
|
"it is skipped unless some list entry starts with ~");
|
|
|
|
DEFINE_string(skps, "skps", "Directory to read skps from.");
|
|
|
|
|
|
|
|
VisualBenchmarkStream::VisualBenchmarkStream()
|
|
|
|
: fBenches(BenchRegistry::Head())
|
|
|
|
, fGMs(skiagm::GMRegistry::Head())
|
2015-08-27 14:41:13 +00:00
|
|
|
, fSourceType(nullptr)
|
|
|
|
, fBenchType(nullptr)
|
2015-06-30 14:43:14 +00:00
|
|
|
, fCurrentSKP(0) {
|
|
|
|
for (int i = 0; i < FLAGS_skps.count(); i++) {
|
|
|
|
if (SkStrEndsWith(FLAGS_skps[i], ".skp")) {
|
|
|
|
fSKPs.push_back() = FLAGS_skps[i];
|
|
|
|
} else {
|
|
|
|
SkOSFile::Iter it(FLAGS_skps[i], ".skp");
|
|
|
|
SkString path;
|
|
|
|
while (it.next(&path)) {
|
|
|
|
fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool VisualBenchmarkStream::ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) {
|
|
|
|
// Not strictly necessary, as it will be checked again later,
|
|
|
|
// but helps to avoid a lot of pointless work if we're going to skip it.
|
|
|
|
if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path));
|
2015-08-27 14:41:13 +00:00
|
|
|
if (stream.get() == nullptr) {
|
2015-06-30 14:43:14 +00:00
|
|
|
SkDebugf("Could not read %s.\n", path);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
pic->reset(SkPicture::CreateFromStream(stream.get()));
|
2015-08-27 14:41:13 +00:00
|
|
|
if (pic->get() == nullptr) {
|
2015-06-30 14:43:14 +00:00
|
|
|
SkDebugf("Could not read %s as an SkPicture.\n", path);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Benchmark* VisualBenchmarkStream::next() {
|
2015-07-15 15:38:02 +00:00
|
|
|
Benchmark* bench;
|
|
|
|
// skips non matching benches
|
|
|
|
while ((bench = this->innerNext()) &&
|
2015-07-16 21:23:22 +00:00
|
|
|
(SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName()) ||
|
|
|
|
!bench->isSuitableFor(Benchmark::kGPU_Backend))) {
|
|
|
|
bench->unref();
|
2015-07-15 15:38:02 +00:00
|
|
|
}
|
|
|
|
return bench;
|
|
|
|
}
|
|
|
|
|
|
|
|
Benchmark* VisualBenchmarkStream::innerNext() {
|
2015-06-30 14:43:14 +00:00
|
|
|
while (fBenches) {
|
2015-08-27 14:41:13 +00:00
|
|
|
Benchmark* bench = fBenches->factory()(nullptr);
|
2015-06-30 14:43:14 +00:00
|
|
|
fBenches = fBenches->next();
|
|
|
|
if (bench->isVisual()) {
|
|
|
|
fSourceType = "bench";
|
|
|
|
fBenchType = "micro";
|
|
|
|
return bench;
|
|
|
|
}
|
2015-07-16 21:23:22 +00:00
|
|
|
bench->unref();
|
2015-06-30 14:43:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while (fGMs) {
|
2015-08-27 14:41:13 +00:00
|
|
|
SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(nullptr));
|
2015-06-30 14:43:14 +00:00
|
|
|
fGMs = fGMs->next();
|
|
|
|
if (gm->runAsBench()) {
|
|
|
|
fSourceType = "gm";
|
|
|
|
fBenchType = "micro";
|
2015-08-26 20:07:48 +00:00
|
|
|
return new GMBench(gm.detach());
|
2015-06-30 14:43:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Render skps
|
|
|
|
while (fCurrentSKP < fSKPs.count()) {
|
|
|
|
const SkString& path = fSKPs[fCurrentSKP++];
|
|
|
|
SkAutoTUnref<SkPicture> pic;
|
|
|
|
if (!ReadPicture(path.c_str(), &pic)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkString name = SkOSPath::Basename(path.c_str());
|
|
|
|
fSourceType = "skp";
|
|
|
|
fBenchType = "playback";
|
2015-08-26 20:07:48 +00:00
|
|
|
return new VisualSKPBench(name.c_str(), pic.get());
|
2015-06-30 14:43:14 +00:00
|
|
|
}
|
|
|
|
|
2015-08-27 14:41:13 +00:00
|
|
|
return nullptr;
|
2015-06-30 14:43:14 +00:00
|
|
|
}
|