|
OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2014 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include "SkCommandLineFlags.h" | |
9 #include "SkPicture.h" | |
10 #include "SkPicturePlayback.h" | |
11 #include "SkStream.h" | |
12 | |
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(tags, t, true, "tags"); | |
18 DEFINE_bool2(quiet, q, false, "quiet"); | |
19 | |
20 // This tool can print simple information about an SKP but its main use | |
21 // is just to check if an SKP has been truncated during the recording | |
mtklein
2014/03/03 15:48:48
Just curious: do you suspect they're truncated dur
robertphillips
2014/03/03 16:13:18
I suspect they are being truncated during writing.
| |
22 // process. | |
23 // return codes: | |
24 static const int kSuccess = 0; | |
25 static const int kTruncatedFile = 1; | |
26 static const int kNotAnSKP = 2; | |
27 static const int kInvalidTag = 3; | |
28 static const int kMissingInput = 4; | |
29 | |
30 int tool_main(int argc, char** argv); | |
31 int tool_main(int argc, char** argv) { | |
32 SkCommandLineFlags::SetUsage("Prints information about an skp file"); | |
33 SkCommandLineFlags::Parse(argc, argv); | |
34 | |
35 if (FLAGS_input.count() != 1) { | |
36 return kMissingInput; | |
mtklein
2014/03/03 15:48:48
Seems like it'd be nice to SkDebugf some message o
robertphillips
2014/03/03 16:13:18
Done.
| |
37 } | |
38 | |
39 const char* fileName = FLAGS_input[0]; | |
40 | |
41 SkStream* stream = SkNEW_ARGS(SkFILEStream, (fileName)); | |
mtklein
2014/03/03 15:48:48
SkFILEStream stream(FLAGS_input[0]); ?
Might also
robertphillips
2014/03/03 16:13:18
Done. Somewhat surprised isValid isn't virtual.
| |
42 | |
43 size_t len = stream->getLength(); | |
44 | |
45 SkPictInfo info; | |
46 if (!SkPicture::StreamIsSKP(stream, &info)) { | |
47 return kNotAnSKP; | |
48 } | |
49 | |
50 if (FLAGS_version && !FLAGS_quiet) { | |
51 SkDebugf("Version: %d\n", info.fVersion); | |
52 } | |
53 if (FLAGS_width && !FLAGS_quiet) { | |
54 SkDebugf("Width: %d\n", info.fWidth); | |
55 } | |
56 if (FLAGS_height && !FLAGS_quiet) { | |
57 SkDebugf("Height: %d\n", info.fHeight); | |
58 } | |
59 | |
60 if (!stream->readBool()) { | |
mtklein
2014/03/03 15:48:48
Got confused here. Clearer as this?
if (stream->
robertphillips
2014/03/03 16:13:18
Here we're getting into the oddities of the pictur
| |
61 return kSuccess; | |
62 } | |
63 | |
64 for (;;) { | |
65 uint32_t tag = stream->readU32(); | |
66 if (SK_PICT_EOF_TAG == tag) { | |
67 break; | |
68 } | |
69 | |
70 uint32_t size = stream->readU32(); | |
mtklein
2014/03/03 15:48:48
tableSize? I'm sometimes getting a bit tripped up
robertphillips
2014/03/03 16:13:18
Done. I renamed these to chunkSize & totStreamSize
| |
71 size_t curPos = stream->getPosition(); | |
72 | |
73 // "move" doesn't error out when seeking beyond the end of file | |
74 // so we need a preemptive check here. | |
75 if (curPos+size > len) { | |
76 if (!FLAGS_quiet) { | |
77 SkDebugf("truncated file\n"); | |
78 } | |
79 return kTruncatedFile; | |
80 } | |
81 | |
82 switch (tag) { | |
83 case SK_PICT_READER_TAG: | |
84 if (FLAGS_tags && !FLAGS_quiet) { | |
85 SkDebugf("SK_PICT_READER_TAG %d\n", size); | |
86 } | |
87 break; | |
88 case SK_PICT_FACTORY_TAG: | |
89 if (FLAGS_tags && !FLAGS_quiet) { | |
90 SkDebugf("SK_PICT_FACTORY_TAG %d\n", size); | |
91 SkDebugf("Exiting early due to format limitations\n"); | |
mtklein
2014/03/03 15:48:48
What's the deal with these early exits and TODOs?
robertphillips
2014/03/03 16:13:18
The size stored with each tag isn't always the siz
mtklein
2014/03/03 16:27:37
Ah! Right. I even knew this. Thanks for the rem
robertphillips
2014/03/03 18:44:24
Done.
| |
92 } | |
93 return kSuccess; // TODO: need to store size in bytes | |
94 break; | |
95 case SK_PICT_TYPEFACE_TAG: | |
96 if (FLAGS_tags && !FLAGS_quiet) { | |
97 SkDebugf("SK_PICT_TYPEFACE_TAG %d\n", size); | |
98 SkDebugf("Exiting early due to format limitations\n"); | |
99 } | |
100 return kSuccess; // TODO: need to store size in bytes | |
101 break; | |
102 case SK_PICT_PICTURE_TAG: | |
103 if (FLAGS_tags && !FLAGS_quiet) { | |
104 SkDebugf("SK_PICT_PICTURE_TAG %d\n", size); | |
105 SkDebugf("Exiting early due to format limitations\n"); | |
106 } | |
107 return kSuccess; // TODO: need to store size in bytes | |
108 break; | |
109 case SK_PICT_BUFFER_SIZE_TAG: | |
110 if (FLAGS_tags && !FLAGS_quiet) { | |
111 SkDebugf("SK_PICT_BUFFER_SIZE_TAG %d\n", size); | |
112 } | |
113 break; | |
114 default: | |
115 if (!FLAGS_quiet) { | |
116 SkDebugf("Unknown tag %d\n", size); | |
117 } | |
118 return kInvalidTag; | |
119 } | |
120 | |
121 if (!stream->move(size)) { | |
122 if (!FLAGS_quiet) { | |
123 SkDebugf("seek error\n"); | |
124 } | |
125 return kTruncatedFile; | |
126 } | |
127 } | |
128 | |
129 return kSuccess; | |
130 } | |
131 | |
132 #if !defined SK_BUILD_FOR_IOS | |
133 int main(int argc, char * const argv[]) { | |
mtklein
2014/03/03 15:48:48
I'm always puzzled why we don't just write int mai
robertphillips
2014/03/03 16:13:18
I think iOS will reject that.
mtklein
2014/03/03 16:27:37
This code is ifdef'd out on iOS? Anyway, not impo
| |
134 return tool_main(argc, (char**) argv); | |
135 } | |
136 #endif | |
OLD | NEW |