Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Unified Diff: tools/bench_playback.cpp

Issue 233833002: Add bench_playback, for quick profiling of SKR playback. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: move in Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gyp/tools.gyp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/bench_playback.cpp
diff --git a/tools/bench_playback.cpp b/tools/bench_playback.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..0d00d0a09d3a97f9d2d494de7b6dc105691c12ad
--- /dev/null
+++ b/tools/bench_playback.cpp
@@ -0,0 +1,93 @@
+/*
+ * 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 "SkCommandLineFlags.h"
+#include "SkForceLinking.h"
+#include "SkGraphics.h"
+#include "SkOSFile.h"
+#include "SkPicture.h"
+#include "SkRecordDraw.h"
+#include "SkRecorder.h"
+#include "SkStream.h"
+#include "SkString.h"
+#include "SkTime.h"
+
+__SK_FORCE_IMAGE_DECODER_LINKING;
+
+DEFINE_string2(skps, r, "skps", "Directory containing SKPs to read and re-record.");
+DEFINE_int32(loops, 10, "Number of times to play back each SKP.");
+DEFINE_bool(skr, false, "Play via SkRecord instead of SkPicture.");
+DEFINE_int32(tile, 1000000000, "Simulated tile size.");
+
+static void bench(SkPMColor* scratch, SkPicture& src, const char* name) {
+ SkRecord record;
+ SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, src.width(), src.height());
+ src.draw(&recorder);
+
+ SkAutoTDelete<SkCanvas> canvas(
+ SkCanvas::NewRasterDirectN32(src.width(), src.height(), scratch, 0));
+ canvas->clipRect(SkRect::MakeWH(FLAGS_tile, FLAGS_tile));
+
+ const SkMSec start = SkTime::GetMSecs();
+ for (int i = 0; i < FLAGS_loops; i++) {
+ if (FLAGS_skr) {
+ SkRecordDraw(record, canvas.get());
+ } else {
+ src.draw(canvas.get());
+ }
+ }
+
+ const SkMSec elapsed = SkTime::GetMSecs() - start;
+ const double msPerLoop = elapsed / (double)FLAGS_loops;
+ printf("%5.1f\t%s\n", msPerLoop, name);
+}
+
+int tool_main(int argc, char** argv);
f(malita) 2014/04/10 23:27:37 Is this needed?
mtklein 2014/04/11 01:22:35 Oh, I just realized you might have just meant, is
+int tool_main(int argc, char** argv) {
+ SkCommandLineFlags::Parse(argc, argv);
+ SkAutoGraphics autoGraphics;
+
+ // We share a single scratch bitmap among benches to reduce the profile noise from allocation.
+ static const int kMaxArea = 209825221; // tabl_mozilla is this big.
+ SkAutoTMalloc<SkPMColor> scratch(kMaxArea);
+
+ SkOSFile::Iter it(FLAGS_skps[0], ".skp");
+ SkString filename;
+ bool failed = false;
+ while (it.next(&filename)) {
+ 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());
+ failed = true;
+ continue;
+ }
+ SkAutoTUnref<SkPicture> src(SkPicture::CreateFromStream(stream));
+ if (!src) {
+ SkDebugf("Could not read %s as an SkPicture.\n", path.c_str());
+ failed = true;
+ continue;
+ }
+
+ if (src->width() * src->height() > kMaxArea) {
+ SkDebugf("%s (%dx%d) is larger than hardcoded scratch bitmap (%dpx).\n",
+ path.c_str(), src->width(), src->height(), kMaxArea);
+ failed = true;
+ continue;
+ }
+
+ bench(scratch.get(), *src, filename.c_str());
+ }
+ return failed ? 1 : 0;
+}
+
+#if !defined SK_BUILD_FOR_IOS
+int main(int argc, char * const argv[]) {
+ return tool_main(argc, (char**) argv);
+}
+#endif
« no previous file with comments | « gyp/tools.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698