2014-01-13 12:03:47 +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.
|
|
|
|
*/
|
|
|
|
|
2014-04-28 15:30:02 +00:00
|
|
|
#include "BenchTimer.h"
|
2014-01-13 12:03:47 +00:00
|
|
|
#include "SkCommandLineFlags.h"
|
|
|
|
#include "SkForceLinking.h"
|
|
|
|
#include "SkGraphics.h"
|
|
|
|
#include "SkOSFile.h"
|
|
|
|
#include "SkPicture.h"
|
2014-04-18 18:04:41 +00:00
|
|
|
#include "SkPictureRecorder.h"
|
2014-04-14 20:33:05 +00:00
|
|
|
#include "SkRecording.h"
|
2014-01-13 12:03:47 +00:00
|
|
|
#include "SkStream.h"
|
|
|
|
#include "SkString.h"
|
2014-03-28 16:08:18 +00:00
|
|
|
#include "LazyDecodeBitmap.h"
|
2014-01-13 12:03:47 +00:00
|
|
|
|
|
|
|
__SK_FORCE_IMAGE_DECODER_LINKING;
|
|
|
|
|
|
|
|
// Just reading all the SKPs takes about 2 seconds for me, which is the same as about 100 loops of
|
|
|
|
// rerecording all the SKPs. So we default to --loops=900, which makes ~90% of our time spent in
|
|
|
|
// recording, and this should take ~20 seconds to run.
|
|
|
|
|
|
|
|
DEFINE_string2(skps, r, "skps", "Directory containing SKPs to read and re-record.");
|
|
|
|
DEFINE_int32(loops, 900, "Number of times to re-record each SKP.");
|
|
|
|
DEFINE_int32(flags, SkPicture::kUsePathBoundsForClip_RecordingFlag, "RecordingFlags to use.");
|
|
|
|
DEFINE_bool(endRecording, true, "If false, don't time SkPicture::endRecording()");
|
2014-01-13 19:09:36 +00:00
|
|
|
DEFINE_int32(nullSize, 1000, "Pretend dimension of null source picture.");
|
2014-03-03 17:51:12 +00:00
|
|
|
DEFINE_int32(tileGridSize, 512, "Set the tile grid size. Has no effect if bbh is not set to tilegrid.");
|
|
|
|
DEFINE_string(bbh, "", "Turn on the bbh and select the type, one of rtree, tilegrid, quadtree");
|
2014-04-01 16:24:06 +00:00
|
|
|
DEFINE_bool(skr, false, "Record SKR instead of SKP.");
|
2014-04-21 14:59:59 +00:00
|
|
|
DEFINE_string(match, "", "The usual filters on file names of SKPs to bench.");
|
2014-04-28 19:41:17 +00:00
|
|
|
DEFINE_string(timescale, "us", "Print times in ms, us, or ns");
|
|
|
|
|
|
|
|
static double scale_time(double ms) {
|
|
|
|
if (FLAGS_timescale.contains("us")) ms *= 1000;
|
|
|
|
if (FLAGS_timescale.contains("ns")) ms *= 1000000;
|
|
|
|
return ms;
|
|
|
|
}
|
2014-01-13 19:09:36 +00:00
|
|
|
|
2014-04-17 23:35:06 +00:00
|
|
|
static SkBBHFactory* parse_FLAGS_bbh() {
|
2014-04-14 03:04:57 +00:00
|
|
|
if (FLAGS_bbh.isEmpty()) {
|
2014-03-03 17:51:12 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2014-04-17 23:35:06 +00:00
|
|
|
|
2014-04-14 03:04:57 +00:00
|
|
|
if (FLAGS_bbh.contains("rtree")) {
|
2014-04-17 23:35:06 +00:00
|
|
|
return SkNEW(SkRTreeFactory);
|
2014-04-13 19:09:42 +00:00
|
|
|
}
|
2014-04-14 03:04:57 +00:00
|
|
|
if (FLAGS_bbh.contains("tilegrid")) {
|
2014-04-17 23:35:06 +00:00
|
|
|
SkTileGridFactory::TileGridInfo info;
|
|
|
|
info.fTileInterval.set(FLAGS_tileGridSize, FLAGS_tileGridSize);
|
|
|
|
info.fMargin.setEmpty();
|
|
|
|
info.fOffset.setZero();
|
|
|
|
return SkNEW_ARGS(SkTileGridFactory, (info));
|
2014-04-13 19:09:42 +00:00
|
|
|
}
|
2014-04-14 03:04:57 +00:00
|
|
|
if (FLAGS_bbh.contains("quadtree")) {
|
2014-04-17 23:35:06 +00:00
|
|
|
return SkNEW(SkQuadTreeFactory);
|
2014-04-13 19:09:42 +00:00
|
|
|
}
|
2014-03-03 17:51:12 +00:00
|
|
|
SkDebugf("Invalid bbh type %s, must be one of rtree, tilegrid, quadtree.\n", FLAGS_bbh[0]);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-04-17 23:35:06 +00:00
|
|
|
static void bench_record(SkPicture* src, const char* name, SkBBHFactory* bbhFactory) {
|
2014-04-28 15:30:02 +00:00
|
|
|
BenchTimer timer;
|
|
|
|
timer.start();
|
2014-01-13 19:09:36 +00:00
|
|
|
const int width = src ? src->width() : FLAGS_nullSize;
|
|
|
|
const int height = src ? src->height() : FLAGS_nullSize;
|
|
|
|
|
|
|
|
for (int i = 0; i < FLAGS_loops; i++) {
|
2014-04-01 16:24:06 +00:00
|
|
|
if (FLAGS_skr) {
|
2014-04-24 15:22:55 +00:00
|
|
|
EXPERIMENTAL::SkRecording recording(width, height);
|
2014-04-01 16:24:06 +00:00
|
|
|
if (NULL != src) {
|
2014-04-24 15:22:55 +00:00
|
|
|
src->draw(recording.canvas());
|
2014-04-01 16:24:06 +00:00
|
|
|
}
|
2014-04-24 15:22:55 +00:00
|
|
|
// Release and delete the SkPlayback so that recording optimizes its SkRecord.
|
|
|
|
SkDELETE(recording.releasePlayback());
|
2014-04-01 16:24:06 +00:00
|
|
|
} else {
|
2014-04-17 23:35:06 +00:00
|
|
|
SkPictureRecorder recorder;
|
|
|
|
SkCanvas* canvas = recorder.beginRecording(width, height, bbhFactory, FLAGS_flags);
|
2014-04-01 16:24:06 +00:00
|
|
|
if (NULL != src) {
|
|
|
|
src->draw(canvas);
|
|
|
|
}
|
|
|
|
if (FLAGS_endRecording) {
|
2014-04-13 19:09:42 +00:00
|
|
|
SkAutoTUnref<SkPicture> dst(recorder.endRecording());
|
2014-04-01 16:24:06 +00:00
|
|
|
}
|
2014-03-18 17:45:32 +00:00
|
|
|
}
|
2014-01-13 19:09:36 +00:00
|
|
|
}
|
2014-04-28 15:30:02 +00:00
|
|
|
timer.end();
|
2014-01-13 19:09:36 +00:00
|
|
|
|
2014-04-28 15:30:02 +00:00
|
|
|
const double msPerLoop = timer.fCpu / (double)FLAGS_loops;
|
2014-04-28 19:41:17 +00:00
|
|
|
printf("%f\t%s\n", scale_time(msPerLoop), name);
|
2014-01-13 19:09:36 +00:00
|
|
|
}
|
2014-01-13 12:03:47 +00:00
|
|
|
|
|
|
|
int tool_main(int argc, char** argv);
|
|
|
|
int tool_main(int argc, char** argv) {
|
|
|
|
SkCommandLineFlags::Parse(argc, argv);
|
|
|
|
SkAutoGraphics autoGraphics;
|
|
|
|
|
2014-04-17 23:35:06 +00:00
|
|
|
if (FLAGS_bbh.count() > 1) {
|
|
|
|
SkDebugf("Multiple bbh arguments supplied.\n");
|
2014-03-03 17:51:12 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2014-04-17 23:35:06 +00:00
|
|
|
|
|
|
|
SkAutoTDelete<SkBBHFactory> bbhFactory(parse_FLAGS_bbh());
|
|
|
|
bench_record(NULL, "NULL", bbhFactory.get());
|
2014-03-18 17:45:32 +00:00
|
|
|
if (FLAGS_skps.isEmpty()) {
|
|
|
|
return 0;
|
|
|
|
}
|
2014-01-13 19:09:36 +00:00
|
|
|
|
2014-01-13 12:03:47 +00:00
|
|
|
SkOSFile::Iter it(FLAGS_skps[0], ".skp");
|
|
|
|
SkString filename;
|
2014-01-13 19:09:36 +00:00
|
|
|
bool failed = false;
|
2014-01-13 12:03:47 +00:00
|
|
|
while (it.next(&filename)) {
|
2014-04-21 14:59:59 +00:00
|
|
|
if (SkCommandLineFlags::ShouldSkip(FLAGS_match, filename.c_str())) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-01-13 12:03:47 +00:00
|
|
|
const SkString path = SkOSPath::SkPathJoin(FLAGS_skps[0], filename.c_str());
|
|
|
|
|
|
|
|
SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path.c_str()));
|
|
|
|
if (!stream) {
|
|
|
|
SkDebugf("Could not read %s.\n", path.c_str());
|
2014-01-13 19:09:36 +00:00
|
|
|
failed = true;
|
2014-01-13 12:03:47 +00:00
|
|
|
continue;
|
|
|
|
}
|
2014-03-28 16:08:18 +00:00
|
|
|
SkAutoTUnref<SkPicture> src(
|
|
|
|
SkPicture::CreateFromStream(stream, sk_tools::LazyDecodeBitmap));
|
2014-01-13 12:03:47 +00:00
|
|
|
if (!src) {
|
|
|
|
SkDebugf("Could not read %s as an SkPicture.\n", path.c_str());
|
2014-01-13 19:09:36 +00:00
|
|
|
failed = true;
|
2014-01-13 12:03:47 +00:00
|
|
|
continue;
|
|
|
|
}
|
2014-04-17 23:35:06 +00:00
|
|
|
bench_record(src, filename.c_str(), bbhFactory.get());
|
2014-01-13 12:03:47 +00:00
|
|
|
}
|
2014-01-13 19:09:36 +00:00
|
|
|
return failed ? 1 : 0;
|
2014-01-13 12:03:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if !defined SK_BUILD_FOR_IOS
|
|
|
|
int main(int argc, char * const argv[]) {
|
|
|
|
return tool_main(argc, (char**) argv);
|
|
|
|
}
|
|
|
|
#endif
|