Flutter Engine
The Flutter Engine
Classes | Functions | Variables
get_images_from_skps.cpp File Reference
#include "include/codec/SkCodec.h"
#include "include/codec/SkEncodedImageFormat.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkData.h"
#include "include/core/SkImage.h"
#include "include/core/SkPicture.h"
#include "include/core/SkSerialProcs.h"
#include "include/core/SkStream.h"
#include "src/core/SkMD5.h"
#include "src/core/SkOSFile.h"
#include "src/core/SkTHash.h"
#include "src/utils/SkJSONWriter.h"
#include "src/utils/SkOSPath.h"
#include "tools/flags/CommandLineFlags.h"
#include <iostream>
#include <map>

Go to the source code of this file.

Classes

struct  Sniffer
 

Functions

static DEFINE_string2 (skps, s, "skps", "A path to a directory of skps or a single skp.")
 
static DEFINE_string2 (out, o, "img-out", "A path to an output directory.")
 
static DEFINE_bool (testDecode, false, "Indicates if we want to test that the images decode successfully.")
 
static DEFINE_bool (writeImages, true, "Indicates if we want to write out supported/decoded images.")
 
static DEFINE_bool (writeFailedImages, false, "Indicates if we want to write out unsupported/failed to decode images.")
 
static DEFINE_string2 (failuresJsonPath, j, "", "Dump SKP and count of unknown images to the specified JSON file. Will not be " "written anywhere if empty.")
 
static bool get_images_from_file (const SkString &file)
 
int main (int argc, char **argv)
 

Variables

static int gKnown
 
static const char * gOutputDir
 
static std::map< std::string, unsigned intgSkpToUnknownCount = {}
 
static std::map< std::string, unsigned intgSkpToUnsupportedCount
 
static THashSet< SkMD5::DigestgSeen
 

Function Documentation

◆ DEFINE_bool() [1/3]

static DEFINE_bool ( testDecode  ,
false  ,
"Indicates if we want to test that the images decode successfully."   
)
static

◆ DEFINE_bool() [2/3]

static DEFINE_bool ( writeFailedImages  ,
false  ,
"Indicates if we want to write out unsupported/failed to decode images."   
)
static

◆ DEFINE_bool() [3/3]

static DEFINE_bool ( writeImages  ,
true  ,
"Indicates if we want to write out supported/decoded images."   
)
static

◆ DEFINE_string2() [1/3]

static DEFINE_string2 ( failuresJsonPath  ,
,
""  ,
"Dump SKP and count of unknown images to the specified JSON file. Will not be " "written anywhere if empty."   
)
static

◆ DEFINE_string2() [2/3]

static DEFINE_string2 ( out  ,
,
"img-out"  ,
"A path to an output directory."   
)
static

◆ DEFINE_string2() [3/3]

static DEFINE_string2 ( skps  ,
s  ,
"skps"  ,
"A path to a directory of skps or a single skp."   
)
static

◆ get_images_from_file()

static bool get_images_from_file ( const SkString file)
static

Definition at line 130 of file get_images_from_skps.cpp.

130 {
131 Sniffer sniff(file.c_str());
132 auto stream = SkStream::MakeFromFile(file.c_str());
133
134 SkDeserialProcs procs;
135 procs.fImageProc = [](const void* data, size_t size, void* ctx) -> sk_sp<SkImage> {
136 ((Sniffer*)ctx)->sniff(data, size);
137 return nullptr;
138 };
139 procs.fImageCtx = &sniff;
140 return SkPicture::MakeFromStream(stream.get(), &procs) != nullptr;
141}
static sk_sp< SkPicture > MakeFromStream(SkStream *stream, const SkDeserialProcs *procs=nullptr)
Definition: SkPicture.cpp:147
static std::unique_ptr< SkStreamAsset > MakeFromFile(const char path[])
Definition: SkStream.cpp:922
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
SkDeserialImageProc fImageProc
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ main()

int main ( int  argc,
char **  argv 
)

JSON results are written out in the following format: { "failures": { "skp1": 12, "skp4": 2, ... }, "unsupported": { "skp9": 13, "skp17": 3, ... } "totalFailures": 32, "totalUnsupported": 9, "totalSuccesses": 21, }

Definition at line 143 of file get_images_from_skps.cpp.

143 {
145 "Usage: get_images_from_skps -s <dir of skps> -o <dir for output images> --testDecode "
146 "-j <output JSON path> --writeImages, --writeFailedImages\n");
147
149 const char* inputs = FLAGS_skps[0];
150 gOutputDir = FLAGS_out[0];
151
152 if (!sk_isdir(gOutputDir)) {
154 return 1;
155 }
156
157 if (sk_isdir(inputs)) {
158 SkOSFile::Iter iter(inputs, "skp");
159 for (SkString file; iter.next(&file); ) {
161 return 2;
162 }
163 }
164 } else {
166 return 2;
167 }
168 }
169 /**
170 JSON results are written out in the following format:
171 {
172 "failures": {
173 "skp1": 12,
174 "skp4": 2,
175 ...
176 },
177 "unsupported": {
178 "skp9": 13,
179 "skp17": 3,
180 ...
181 }
182 "totalFailures": 32,
183 "totalUnsupported": 9,
184 "totalSuccesses": 21,
185 }
186 */
187
188 unsigned int totalFailures = 0,
189 totalUnsupported = 0;
190 SkDynamicMemoryWStream memStream;
191 SkJSONWriter writer(&memStream, SkJSONWriter::Mode::kPretty);
192 writer.beginObject();
193 {
194 writer.beginObject("failures");
195 {
196 for (const auto& failure : gSkpToUnknownCount) {
197 SkDebugf("%s %u\n", failure.first.c_str(), failure.second);
198 totalFailures += failure.second;
199 writer.appendU32(failure.first.c_str(), failure.second);
200 }
201 }
202 writer.endObject();
203 writer.appendU32("totalFailures", totalFailures);
204
205#ifdef SK_DEBUG
206 writer.beginObject("unsupported");
207 {
208 for (const auto& unsupported : gSkpToUnsupportedCount) {
209 SkDebugf("%s %u\n", unsupported.first.c_str(), unsupported.second);
210 totalUnsupported += unsupported.second;
211 writer.appendHexU32(unsupported.first.c_str(), unsupported.second);
212 }
213 }
214 writer.endObject();
215 writer.appendU32("totalUnsupported", totalUnsupported);
216#endif
217
218 writer.appendS32("totalSuccesses", gKnown);
219 SkDebugf("%d known, %u failures, %u unsupported\n",
220 gKnown, totalFailures, totalUnsupported);
221 }
222 writer.endObject();
223 writer.flush();
224
225 if (totalFailures > 0 || totalUnsupported > 0) {
226 if (!FLAGS_failuresJsonPath.isEmpty()) {
227 SkDebugf("Writing failures to %s\n", FLAGS_failuresJsonPath[0]);
228 SkFILEWStream stream(FLAGS_failuresJsonPath[0]);
229 auto jsonStream = memStream.detachAsStream();
230 stream.writeStream(jsonStream.get(), jsonStream->getLength());
231 }
232 }
233
234 return 0;
235}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
bool sk_isdir(const char *path)
static void PrintUsage()
static void Parse(int argc, const char *const *argv)
static void SetUsage(const char *usage)
std::unique_ptr< SkStreamAsset > detachAsStream()
Definition: SkStream.cpp:876
static SkString Join(const char *rootPath, const char *relativePath)
Definition: SkOSPath.cpp:14
static bool get_images_from_file(const SkString &file)
static std::map< std::string, unsigned int > gSkpToUnsupportedCount
static std::map< std::string, unsigned int > gSkpToUnknownCount
static int gKnown
static const char * gOutputDir
char ** argv
Definition: library.h:9

Variable Documentation

◆ gKnown

int gKnown
static

Definition at line 41 of file get_images_from_skps.cpp.

◆ gOutputDir

const char* gOutputDir
static

Definition at line 42 of file get_images_from_skps.cpp.

◆ gSeen

THashSet<SkMD5::Digest> gSeen
static

Definition at line 46 of file get_images_from_skps.cpp.

◆ gSkpToUnknownCount

std::map<std::string, unsigned int> gSkpToUnknownCount = {}
static

Definition at line 43 of file get_images_from_skps.cpp.

◆ gSkpToUnsupportedCount

std::map<std::string, unsigned int> gSkpToUnsupportedCount
static

Definition at line 44 of file get_images_from_skps.cpp.