2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #include "SkCommandLineFlags.h"
10 #include "SkPictureData.h"
13 DEFINE_string2(input, i, "", "skp on which to report");
14 DEFINE_bool2(version, v, true, "version");
15 DEFINE_bool2(width, w, true, "width");
16 DEFINE_bool2(height, h, true, "height");
17 DEFINE_bool2(flags, f, true, "flags");
18 DEFINE_bool2(tags, t, true, "tags");
19 DEFINE_bool2(quiet, q, false, "quiet");
21 // This tool can print simple information about an SKP but its main use
22 // is just to check if an SKP has been truncated during the recording
25 static const int kSuccess = 0;
26 static const int kTruncatedFile = 1;
27 static const int kNotAnSKP = 2;
28 static const int kInvalidTag = 3;
29 static const int kMissingInput = 4;
30 static const int kIOError = 5;
32 int tool_main(int argc, char** argv);
33 int tool_main(int argc, char** argv) {
34 SkCommandLineFlags::SetUsage("Prints information about an skp file");
35 SkCommandLineFlags::Parse(argc, argv);
37 if (FLAGS_input.count() != 1) {
39 SkDebugf("Missing input file\n");
44 SkFILEStream stream(FLAGS_input[0]);
45 if (!stream.isValid()) {
47 SkDebugf("Couldn't open file\n");
52 size_t totStreamSize = stream.getLength();
55 if (!SkPicture::InternalOnly_StreamIsSKP(&stream, &info)) {
59 if (FLAGS_version && !FLAGS_quiet) {
60 SkDebugf("Version: %d\n", info.fVersion);
62 if (FLAGS_width && !FLAGS_quiet) {
63 SkDebugf("Width: %d\n", info.fWidth);
65 if (FLAGS_height && !FLAGS_quiet) {
66 SkDebugf("Height: %d\n", info.fHeight);
68 if (FLAGS_flags && !FLAGS_quiet) {
69 SkDebugf("Flags: 0x%x\n", info.fFlags);
72 if (!stream.readBool()) {
73 // If we read true there's a picture playback object flattened
74 // in the file; if false, there isn't a playback, so we're done
80 uint32_t tag = stream.readU32();
81 if (SK_PICT_EOF_TAG == tag) {
85 uint32_t chunkSize = stream.readU32();
86 size_t curPos = stream.getPosition();
88 // "move" doesn't error out when seeking beyond the end of file
89 // so we need a preemptive check here.
90 if (curPos+chunkSize > totStreamSize) {
92 SkDebugf("truncated file\n");
94 return kTruncatedFile;
97 // Not all the tags store the chunk size (in bytes). Three
98 // of them store tag-specific size information (e.g., number of
99 // fonts) instead. This forces us to early exit when those
100 // chunks are encountered.
102 case SK_PICT_READER_TAG:
103 if (FLAGS_tags && !FLAGS_quiet) {
104 SkDebugf("SK_PICT_READER_TAG %d\n", chunkSize);
107 case SK_PICT_FACTORY_TAG:
108 if (FLAGS_tags && !FLAGS_quiet) {
109 SkDebugf("SK_PICT_FACTORY_TAG %d\n", chunkSize);
111 // Remove this code when v21 and below are no longer supported
112 #ifndef DISABLE_V21_COMPATIBILITY_CODE
113 if (info.fVersion < 22) {
115 SkDebugf("Exiting early due to format limitations\n");
117 return kSuccess; // TODO: need to store size in bytes
121 case SK_PICT_TYPEFACE_TAG:
122 if (FLAGS_tags && !FLAGS_quiet) {
123 SkDebugf("SK_PICT_TYPEFACE_TAG %d\n", chunkSize);
124 SkDebugf("Exiting early due to format limitations\n");
126 return kSuccess; // TODO: need to store size in bytes
128 case SK_PICT_PICTURE_TAG:
129 if (FLAGS_tags && !FLAGS_quiet) {
130 SkDebugf("SK_PICT_PICTURE_TAG %d\n", chunkSize);
131 SkDebugf("Exiting early due to format limitations\n");
133 return kSuccess; // TODO: need to store size in bytes
135 case SK_PICT_BUFFER_SIZE_TAG:
136 if (FLAGS_tags && !FLAGS_quiet) {
137 SkDebugf("SK_PICT_BUFFER_SIZE_TAG %d\n", chunkSize);
142 SkDebugf("Unknown tag %d\n", chunkSize);
147 if (!stream.move(chunkSize)) {
149 SkDebugf("seek error\n");
151 return kTruncatedFile;
158 #if !defined SK_BUILD_FOR_IOS
159 int main(int argc, char * const argv[]) {
160 return tool_main(argc, (char**) argv);