Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions | Variables
skpinfo.cpp File Reference
#include "include/core/SkPicture.h"
#include "include/core/SkStream.h"
#include "include/private/base/SkTo.h"
#include "src/core/SkFontDescriptor.h"
#include "src/core/SkPictureData.h"
#include "src/core/SkPicturePriv.h"
#include "tools/flags/CommandLineFlags.h"

Go to the source code of this file.

Functions

static DEFINE_string2 (input, i, "", "skp on which to report")
 
static DEFINE_bool2 (version, v, true, "version")
 
static DEFINE_bool2 (cullRect, c, true, "cullRect")
 
static DEFINE_bool2 (flags, f, true, "flags")
 
static DEFINE_bool2 (tags, t, true, "tags")
 
static DEFINE_bool2 (quiet, q, false, "quiet")
 
int main (int argc, char **argv)
 

Variables

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
 

Function Documentation

◆ DEFINE_bool2() [1/5]

static DEFINE_bool2 ( cullRect  ,
,
true  ,
"cullRect"   
)
static

◆ DEFINE_bool2() [2/5]

static DEFINE_bool2 ( flags  ,
,
true  ,
"flags"   
)
static

◆ DEFINE_bool2() [3/5]

static DEFINE_bool2 ( quiet  ,
,
false  ,
"quiet"   
)
static

◆ DEFINE_bool2() [4/5]

static DEFINE_bool2 ( tags  ,
,
true  ,
"tags"   
)
static

◆ DEFINE_bool2() [5/5]

static DEFINE_bool2 ( version  ,
,
true  ,
"version"   
)
static

◆ DEFINE_string2()

static DEFINE_string2 ( input  ,
,
""  ,
"skp on which to report"   
)
static

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 34 of file skpinfo.cpp.

34 {
35 CommandLineFlags::SetUsage("Prints information about an skp file");
36 CommandLineFlags::Parse(argc, argv);
37
38 if (FLAGS_input.size() != 1) {
39 if (!FLAGS_quiet) {
40 SkDebugf("Missing input file\n");
41 }
42 return kMissingInput;
43 }
44
45 SkFILEStream stream(FLAGS_input[0]);
46 if (!stream.isValid()) {
47 if (!FLAGS_quiet) {
48 SkDebugf("Couldn't open file\n");
49 }
50 return kIOError;
51 }
52
53 size_t totStreamSize = stream.getLength();
54
56 if (!SkPicture_StreamIsSKP(&stream, &info)) {
57 SkDebugf("Unsupported version %u\n", info.getVersion());
58 return kNotAnSKP;
59 }
60
61 if (FLAGS_version && !FLAGS_quiet) {
62 SkDebugf("Version: %u\n", info.getVersion());
63 }
64 if (FLAGS_cullRect && !FLAGS_quiet) {
65 SkDebugf("Cull Rect: %f,%f,%f,%f\n",
66 info.fCullRect.fLeft, info.fCullRect.fTop,
67 info.fCullRect.fRight, info.fCullRect.fBottom);
68 }
69
70 bool hasData;
71 if (!stream.readBool(&hasData)) { return kTruncatedFile; }
72 if (!hasData) {
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
75 // reading the file.
76 return kSuccess;
77 }
78
79 for (;;) {
80 uint32_t tag;
81 if (!stream.readU32(&tag)) { return kTruncatedFile; }
82 if (SK_PICT_EOF_TAG == tag) {
83 break;
84 }
85
86 uint32_t chunkSize;
87 if (!stream.readU32(&chunkSize)) { return kTruncatedFile; }
88 size_t curPos = stream.getPosition();
89
90 // "move" doesn't error out when seeking beyond the end of file
91 // so we need a preemptive check here.
92 if (curPos+chunkSize > totStreamSize) {
93 if (!FLAGS_quiet) {
94 SkDebugf("truncated file\n");
95 }
96 return kTruncatedFile;
97 }
98
99 // Not all the tags store the chunk size (in bytes). Three
100 // of them store tag-specific size information (e.g., number of
101 // fonts) instead. This forces us to early exit when those
102 // chunks are encountered.
103 switch (tag) {
105 if (FLAGS_tags && !FLAGS_quiet) {
106 SkDebugf("SK_PICT_READER_TAG %u\n", chunkSize);
107 }
108 break;
110 if (FLAGS_tags && !FLAGS_quiet) {
111 SkDebugf("SK_PICT_FACTORY_TAG %u\n", chunkSize);
112 }
113 break;
115 if (FLAGS_tags && !FLAGS_quiet) {
116 SkDebugf("SK_PICT_TYPEFACE_TAG %u\n", chunkSize);
117 }
118
119 const int count = SkToInt(chunkSize);
120 for (int i = 0; i < count; i++) {
122 if (!SkFontDescriptor::Deserialize(&stream, &desc)) {
123 if (!FLAGS_quiet) {
124 SkDebugf("File corruption in SkFontDescriptor\n");
125 }
126 return kInvalidTag;
127 }
128 }
129
130 // clear this since we've consumed all the typefaces
131 chunkSize = 0;
132 break;
133 }
135 if (FLAGS_tags && !FLAGS_quiet) {
136 SkDebugf("SK_PICT_PICTURE_TAG %u\n", chunkSize);
137 SkDebugf("Exiting early due to format limitations\n");
138 }
139 return kSuccess; // TODO: need to store size in bytes
141 if (FLAGS_tags && !FLAGS_quiet) {
142 SkDebugf("SK_PICT_BUFFER_SIZE_TAG %u\n", chunkSize);
143 }
144 break;
145 default:
146 if (!FLAGS_quiet) {
147 SkDebugf("Unknown tag %u\n", chunkSize);
148 }
149 return kInvalidTag;
150 }
151
152 if (!stream.move(chunkSize)) {
153 if (!FLAGS_quiet) {
154 SkDebugf("seek error\n");
155 }
156 return kTruncatedFile;
157 }
158 }
159
160 return kSuccess;
161}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
int count
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
#define SK_PICT_PICTURE_TAG
#define SK_PICT_EOF_TAG
#define SK_PICT_FACTORY_TAG
#define SK_PICT_BUFFER_SIZE_TAG
#define SK_PICT_READER_TAG
#define SK_PICT_TYPEFACE_TAG
bool SkPicture_StreamIsSKP(SkStream *stream, SkPictInfo *pInfo)
constexpr int SkToInt(S x)
Definition SkTo.h:29
static void Parse(int argc, const char *const *argv)
static void SetUsage(const char *usage)
static bool Deserialize(SkStream *, SkFontDescriptor *result)
static const int kMissingInput
Definition skpinfo.cpp:31
static const int kNotAnSKP
Definition skpinfo.cpp:29
static const int kIOError
Definition skpinfo.cpp:32
static const int kSuccess
Definition skpinfo.cpp:27
static const int kInvalidTag
Definition skpinfo.cpp:30
static const int kTruncatedFile
Definition skpinfo.cpp:28

Variable Documentation

◆ kInvalidTag

const int kInvalidTag = 3
static

Definition at line 30 of file skpinfo.cpp.

◆ kIOError

const int kIOError = 5
static

Definition at line 32 of file skpinfo.cpp.

◆ kMissingInput

const int kMissingInput = 4
static

Definition at line 31 of file skpinfo.cpp.

◆ kNotAnSKP

const int kNotAnSKP = 2
static

Definition at line 29 of file skpinfo.cpp.

◆ kSuccess

const int kSuccess = 0
static

Definition at line 27 of file skpinfo.cpp.

◆ kTruncatedFile

const int kTruncatedFile = 1
static

Definition at line 28 of file skpinfo.cpp.