aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-03-03 19:18:39 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-03-03 19:18:39 +0000
commit6f4fb0f1296422a44d5d0dac155d82595dc5ebec (patch)
tree4901983c0553090f68884a15b3b82c2649f94ef9 /tools
parent1b94819fcbe766039a488ad3975db2e1a8a25e28 (diff)
Generating the 1M skps frequently yields truncated skps. This tool is intended to help automate weeding these out.
Please see skbug:1057 rmistry for tools, gyp mtklein for src\core & include\core BUG=skia:1057 R=rmistry@google.com, mtklein@google.com, reed@google.com Author: robertphillips@google.com Review URL: https://codereview.chromium.org/176863004 git-svn-id: http://skia.googlecode.com/svn/trunk@13643 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tools')
-rw-r--r--tools/skpinfo.cpp151
1 files changed, 151 insertions, 0 deletions
diff --git a/tools/skpinfo.cpp b/tools/skpinfo.cpp
new file mode 100644
index 0000000000..e14abd430b
--- /dev/null
+++ b/tools/skpinfo.cpp
@@ -0,0 +1,151 @@
+/*
+ * 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 "SkPicture.h"
+#include "SkPicturePlayback.h"
+#include "SkStream.h"
+
+DEFINE_string2(input, i, "", "skp on which to report");
+DEFINE_bool2(version, v, true, "version");
+DEFINE_bool2(width, w, true, "width");
+DEFINE_bool2(height, h, true, "height");
+DEFINE_bool2(tags, t, true, "tags");
+DEFINE_bool2(quiet, q, false, "quiet");
+
+// This tool can print simple information about an SKP but its main use
+// is just to check if an SKP has been truncated during the recording
+// process.
+// return codes:
+static const int kSuccess = 0;
+static const int kTruncatedFile = 1;
+static const int kNotAnSKP = 2;
+static const int kInvalidTag = 3;
+static const int kMissingInput = 4;
+static const int kIOError = 5;
+
+int tool_main(int argc, char** argv);
+int tool_main(int argc, char** argv) {
+ SkCommandLineFlags::SetUsage("Prints information about an skp file");
+ SkCommandLineFlags::Parse(argc, argv);
+
+ if (FLAGS_input.count() != 1) {
+ if (!FLAGS_quiet) {
+ SkDebugf("Missing input file\n");
+ }
+ return kMissingInput;
+ }
+
+ SkFILEStream stream(FLAGS_input[0]);
+ if (!stream.isValid()) {
+ if (!FLAGS_quiet) {
+ SkDebugf("Couldn't open file\n");
+ }
+ return kIOError;
+ }
+
+ size_t totStreamSize = stream.getLength();
+
+ SkPictInfo info;
+ if (!SkPicture::InternalOnly_StreamIsSKP(&stream, &info)) {
+ return kNotAnSKP;
+ }
+
+ if (FLAGS_version && !FLAGS_quiet) {
+ SkDebugf("Version: %d\n", info.fVersion);
+ }
+ if (FLAGS_width && !FLAGS_quiet) {
+ SkDebugf("Width: %d\n", info.fWidth);
+ }
+ if (FLAGS_height && !FLAGS_quiet) {
+ SkDebugf("Height: %d\n", info.fHeight);
+ }
+
+ if (!stream.readBool()) {
+ // If we read true there's a picture playback object flattened
+ // in the file; if false, there isn't a playback, so we're done
+ // reading the file.
+ return kSuccess;
+ }
+
+ for (;;) {
+ uint32_t tag = stream.readU32();
+ if (SK_PICT_EOF_TAG == tag) {
+ break;
+ }
+
+ uint32_t chunkSize = stream.readU32();
+ size_t curPos = stream.getPosition();
+
+ // "move" doesn't error out when seeking beyond the end of file
+ // so we need a preemptive check here.
+ if (curPos+chunkSize > totStreamSize) {
+ if (!FLAGS_quiet) {
+ SkDebugf("truncated file\n");
+ }
+ return kTruncatedFile;
+ }
+
+ // Not all the tags store the chunk size (in bytes). Three
+ // of them store tag-specific size information (e.g., number of
+ // fonts) instead. This forces us to early exit when those
+ // chunks are encountered.
+ switch (tag) {
+ case SK_PICT_READER_TAG:
+ if (FLAGS_tags && !FLAGS_quiet) {
+ SkDebugf("SK_PICT_READER_TAG %d\n", chunkSize);
+ }
+ break;
+ case SK_PICT_FACTORY_TAG:
+ if (FLAGS_tags && !FLAGS_quiet) {
+ SkDebugf("SK_PICT_FACTORY_TAG %d\n", chunkSize);
+ SkDebugf("Exiting early due to format limitations\n");
+ }
+ return kSuccess; // TODO: need to store size in bytes
+ break;
+ case SK_PICT_TYPEFACE_TAG:
+ if (FLAGS_tags && !FLAGS_quiet) {
+ SkDebugf("SK_PICT_TYPEFACE_TAG %d\n", chunkSize);
+ SkDebugf("Exiting early due to format limitations\n");
+ }
+ return kSuccess; // TODO: need to store size in bytes
+ break;
+ case SK_PICT_PICTURE_TAG:
+ if (FLAGS_tags && !FLAGS_quiet) {
+ SkDebugf("SK_PICT_PICTURE_TAG %d\n", chunkSize);
+ SkDebugf("Exiting early due to format limitations\n");
+ }
+ return kSuccess; // TODO: need to store size in bytes
+ break;
+ case SK_PICT_BUFFER_SIZE_TAG:
+ if (FLAGS_tags && !FLAGS_quiet) {
+ SkDebugf("SK_PICT_BUFFER_SIZE_TAG %d\n", chunkSize);
+ }
+ break;
+ default:
+ if (!FLAGS_quiet) {
+ SkDebugf("Unknown tag %d\n", chunkSize);
+ }
+ return kInvalidTag;
+ }
+
+ if (!stream.move(chunkSize)) {
+ if (!FLAGS_quiet) {
+ SkDebugf("seek error\n");
+ }
+ return kTruncatedFile;
+ }
+ }
+
+ return kSuccess;
+}
+
+#if !defined SK_BUILD_FOR_IOS
+int main(int argc, char * const argv[]) {
+ return tool_main(argc, (char**) argv);
+}
+#endif