2014-03-03 19:18:39 +00:00
|
|
|
/*
|
|
|
|
* 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"
|
2018-06-13 13:59:02 +00:00
|
|
|
#include "SkFontDescriptor.h"
|
2014-03-03 19:18:39 +00:00
|
|
|
#include "SkPicture.h"
|
2018-06-13 13:42:32 +00:00
|
|
|
#include "SkPictureCommon.h"
|
2018-06-13 13:59:02 +00:00
|
|
|
#include "SkPictureData.h"
|
2014-03-03 19:18:39 +00:00
|
|
|
#include "SkStream.h"
|
2018-06-13 13:59:02 +00:00
|
|
|
#include "SkTo.h"
|
2014-03-03 19:18:39 +00:00
|
|
|
|
|
|
|
DEFINE_string2(input, i, "", "skp on which to report");
|
|
|
|
DEFINE_bool2(version, v, true, "version");
|
2014-08-29 15:03:56 +00:00
|
|
|
DEFINE_bool2(cullRect, c, true, "cullRect");
|
2014-04-24 21:53:13 +00:00
|
|
|
DEFINE_bool2(flags, f, true, "flags");
|
2014-03-03 19:18:39 +00:00
|
|
|
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;
|
|
|
|
|
2017-02-06 17:46:20 +00:00
|
|
|
int main(int argc, char** argv) {
|
2014-03-03 19:18:39 +00:00
|
|
|
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;
|
2017-12-20 19:09:20 +00:00
|
|
|
if (!SkPicture_StreamIsSKP(&stream, &info)) {
|
2014-03-03 19:18:39 +00:00
|
|
|
return kNotAnSKP;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FLAGS_version && !FLAGS_quiet) {
|
2016-10-04 19:12:01 +00:00
|
|
|
SkDebugf("Version: %d\n", info.getVersion());
|
2014-03-03 19:18:39 +00:00
|
|
|
}
|
2014-08-29 15:03:56 +00:00
|
|
|
if (FLAGS_cullRect && !FLAGS_quiet) {
|
2014-12-01 14:56:38 +00:00
|
|
|
SkDebugf("Cull Rect: %f,%f,%f,%f\n",
|
|
|
|
info.fCullRect.fLeft, info.fCullRect.fTop,
|
2014-08-29 15:03:56 +00:00
|
|
|
info.fCullRect.fRight, info.fCullRect.fBottom);
|
2014-03-03 19:18:39 +00:00
|
|
|
}
|
|
|
|
|
2016-10-07 19:50:53 +00:00
|
|
|
bool hasData;
|
|
|
|
if (!stream.readBool(&hasData)) { return kTruncatedFile; }
|
|
|
|
if (!hasData) {
|
2014-03-04 03:02:32 +00:00
|
|
|
// 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
|
2014-03-03 19:18:39 +00:00
|
|
|
// reading the file.
|
|
|
|
return kSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
2016-10-07 19:50:53 +00:00
|
|
|
uint32_t tag;
|
|
|
|
if (!stream.readU32(&tag)) { return kTruncatedFile; }
|
2014-03-03 19:18:39 +00:00
|
|
|
if (SK_PICT_EOF_TAG == tag) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-10-07 19:50:53 +00:00
|
|
|
uint32_t chunkSize;
|
|
|
|
if (!stream.readU32(&chunkSize)) { return kTruncatedFile; }
|
2014-03-03 19:18:39 +00:00
|
|
|
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) {
|
2014-03-04 03:02:32 +00:00
|
|
|
case SK_PICT_READER_TAG:
|
2014-03-03 19:18:39 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
break;
|
2016-02-25 18:58:49 +00:00
|
|
|
case SK_PICT_TYPEFACE_TAG: {
|
2014-03-03 19:18:39 +00:00
|
|
|
if (FLAGS_tags && !FLAGS_quiet) {
|
|
|
|
SkDebugf("SK_PICT_TYPEFACE_TAG %d\n", chunkSize);
|
|
|
|
}
|
2016-02-25 18:58:49 +00:00
|
|
|
|
|
|
|
const int count = SkToInt(chunkSize);
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
SkFontDescriptor desc;
|
|
|
|
if (!SkFontDescriptor::Deserialize(&stream, &desc)) {
|
|
|
|
if (!FLAGS_quiet) {
|
|
|
|
SkDebugf("File corruption in SkFontDescriptor\n");
|
|
|
|
}
|
|
|
|
return kInvalidTag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// clear this since we've consumed all the typefaces
|
|
|
|
chunkSize = 0;
|
2014-03-03 19:18:39 +00:00
|
|
|
break;
|
2016-02-25 18:58:49 +00:00
|
|
|
}
|
2014-03-03 19:18:39 +00:00
|
|
|
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;
|
|
|
|
}
|