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

Side by Side Diff: tools/skpinfo.cpp

Issue 176863004: Add new skpinfo tool (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Addressed code review comments Created 6 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« include/core/SkPicture.h ('K') | « src/core/SkPicturePlayback.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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
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 static const int kIOError = 5;
30
31 int tool_main(int argc, char** argv);
32 int tool_main(int argc, char** argv) {
33 SkCommandLineFlags::SetUsage("Prints information about an skp file");
34 SkCommandLineFlags::Parse(argc, argv);
35
36 if (FLAGS_input.count() != 1) {
37 if (!FLAGS_quiet) {
38 SkDebugf("Missing input file\n");
39 }
40 return kMissingInput;
41 }
42
43 SkFILEStream* stream = SkNEW_ARGS(SkFILEStream, (FLAGS_input[0]));
mtklein 2014/03/03 16:27:37 Sorry if I wasn't clear, I think you really do wan
robertphillips 2014/03/03 18:44:24 Done.
44 if (!stream->isValid()) {
45 if (!FLAGS_quiet) {
46 SkDebugf("Couldn't open file\n");
47 }
48 return kIOError;
49 }
50
51 size_t totStreamSize = stream->getLength();
52
53 SkPictInfo info;
54 if (!SkPicture::StreamIsSKP(stream, &info)) {
55 return kNotAnSKP;
56 }
57
58 if (FLAGS_version && !FLAGS_quiet) {
59 SkDebugf("Version: %d\n", info.fVersion);
60 }
61 if (FLAGS_width && !FLAGS_quiet) {
62 SkDebugf("Width: %d\n", info.fWidth);
63 }
64 if (FLAGS_height && !FLAGS_quiet) {
65 SkDebugf("Height: %d\n", info.fHeight);
66 }
67
68 if (!stream->readBool()) {
69 // If the read bool is false then we're done reading the file.
mtklein 2014/03/03 16:27:37 I'm not really sure this comment says anything the
robertphillips 2014/03/03 18:44:24 Done.
70 return kSuccess;
71 }
72
73 for (;;) {
74 uint32_t tag = stream->readU32();
75 if (SK_PICT_EOF_TAG == tag) {
76 break;
77 }
78
79 uint32_t chunkSize = stream->readU32();
80 size_t curPos = stream->getPosition();
81
82 // "move" doesn't error out when seeking beyond the end of file
83 // so we need a preemptive check here.
84 if (curPos+chunkSize > totStreamSize) {
85 if (!FLAGS_quiet) {
86 SkDebugf("truncated file\n");
87 }
88 return kTruncatedFile;
89 }
90
91 switch (tag) {
92 case SK_PICT_READER_TAG:
93 if (FLAGS_tags && !FLAGS_quiet) {
94 SkDebugf("SK_PICT_READER_TAG %d\n", chunkSize);
95 }
96 break;
97 case SK_PICT_FACTORY_TAG:
98 if (FLAGS_tags && !FLAGS_quiet) {
99 SkDebugf("SK_PICT_FACTORY_TAG %d\n", chunkSize);
100 SkDebugf("Exiting early due to format limitations\n");
101 }
102 return kSuccess; // TODO: need to store size in bytes
103 break;
104 case SK_PICT_TYPEFACE_TAG:
105 if (FLAGS_tags && !FLAGS_quiet) {
106 SkDebugf("SK_PICT_TYPEFACE_TAG %d\n", chunkSize);
107 SkDebugf("Exiting early due to format limitations\n");
108 }
109 return kSuccess; // TODO: need to store size in bytes
110 break;
111 case SK_PICT_PICTURE_TAG:
112 if (FLAGS_tags && !FLAGS_quiet) {
113 SkDebugf("SK_PICT_PICTURE_TAG %d\n", chunkSize);
114 SkDebugf("Exiting early due to format limitations\n");
115 }
116 return kSuccess; // TODO: need to store size in bytes
117 break;
118 case SK_PICT_BUFFER_SIZE_TAG:
119 if (FLAGS_tags && !FLAGS_quiet) {
120 SkDebugf("SK_PICT_BUFFER_SIZE_TAG %d\n", chunkSize);
121 }
122 break;
123 default:
124 if (!FLAGS_quiet) {
125 SkDebugf("Unknown tag %d\n", chunkSize);
126 }
127 return kInvalidTag;
128 }
129
130 if (!stream->move(chunkSize)) {
131 if (!FLAGS_quiet) {
132 SkDebugf("seek error\n");
133 }
134 return kTruncatedFile;
135 }
136 }
137
138 return kSuccess;
139 }
140
141 #if !defined SK_BUILD_FOR_IOS
142 int main(int argc, char * const argv[]) {
143 return tool_main(argc, (char**) argv);
144 }
145 #endif
OLDNEW
« include/core/SkPicture.h ('K') | « src/core/SkPicturePlayback.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698