Chromium Code Reviews| Index: tools/skpinfo.cpp |
| =================================================================== |
| --- tools/skpinfo.cpp (revision 0) |
| +++ tools/skpinfo.cpp (revision 0) |
| @@ -0,0 +1,136 @@ |
| +/* |
| + * 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 |
|
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.
|
| +// 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; |
| + |
| +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) { |
| + 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.
|
| + } |
| + |
| + const char* fileName = FLAGS_input[0]; |
| + |
| + 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.
|
| + |
| + size_t len = stream->getLength(); |
| + |
| + SkPictInfo info; |
| + if (!SkPicture::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()) { |
|
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
|
| + return kSuccess; |
| + } |
| + |
| + for (;;) { |
| + uint32_t tag = stream->readU32(); |
| + if (SK_PICT_EOF_TAG == tag) { |
| + break; |
| + } |
| + |
| + 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
|
| + 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+size > len) { |
| + if (!FLAGS_quiet) { |
| + SkDebugf("truncated file\n"); |
| + } |
| + return kTruncatedFile; |
| + } |
| + |
| + switch (tag) { |
| + case SK_PICT_READER_TAG: |
| + if (FLAGS_tags && !FLAGS_quiet) { |
| + SkDebugf("SK_PICT_READER_TAG %d\n", size); |
| + } |
| + break; |
| + case SK_PICT_FACTORY_TAG: |
| + if (FLAGS_tags && !FLAGS_quiet) { |
| + SkDebugf("SK_PICT_FACTORY_TAG %d\n", size); |
| + 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.
|
| + } |
| + 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", size); |
| + 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", size); |
| + 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", size); |
| + } |
| + break; |
| + default: |
| + if (!FLAGS_quiet) { |
| + SkDebugf("Unknown tag %d\n", size); |
| + } |
| + return kInvalidTag; |
| + } |
| + |
| + if (!stream->move(size)) { |
| + if (!FLAGS_quiet) { |
| + SkDebugf("seek error\n"); |
| + } |
| + return kTruncatedFile; |
| + } |
| + } |
| + |
| + return kSuccess; |
| +} |
| + |
| +#if !defined SK_BUILD_FOR_IOS |
| +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
|
| + return tool_main(argc, (char**) argv); |
| +} |
| +#endif |
| Property changes on: tools\skpinfo.cpp |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |