Flutter Engine
The Flutter Engine
skp_parser.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 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
14
15#include <iostream>
16
17#ifdef SK_BUILD_FOR_WIN
18#include <fcntl.h>
19#include <io.h>
20#endif
21
22/*
23If you execute skp_parser with one argument, it spits out a json representation
24of the skp, but that's incomplete since it's missing many binary blobs (these
25could represent images or typefaces or just anything that doesn't currently
26have a json representation). Each unique blob is labeled with a string in the
27form "data/%d". So for example:
28
29 tools/git-sync-deps
30 bin/gn gen out/debug
31 ninja -C out/debug dm skp_parser
32 out/debug/dm -m grayscale -w /tmp/dm --config skp
33 out/debug/skp_parser /tmp/dm/skp/gm/grayscalejpg.skp | less
34 out/debug/skp_parser /tmp/dm/skp/gm/grayscalejpg.skp | grep data
35 out/debug/skp_parser /tmp/dm/skp/gm/grayscalejpg.skp data/0 | file -
36 out/debug/skp_parser /tmp/dm/skp/gm/grayscalejpg.skp data/0 > /tmp/data0.png
37
38"data/0" is an image that the SKP serializer has encoded as PNG.
39*/
40int main(int argc, char** argv) {
41 if (argc < 2) {
42 SkDebugf("Usage:\n %s SKP_FILE [DATA_URL]\n", argv[0]);
43 return 1;
44 }
45 SkFILEStream input(argv[1]);
46 if (!input.isValid()) {
47 SkDebugf("Bad file: '%s'\n", argv[1]);
48 return 2;
49 }
51 if (!pic) {
52 SkDebugf("Bad skp: '%s'\n", argv[1]);
53 return 3;
54 }
55 SkISize size = pic->cullRect().roundOut().size();
56 DebugCanvas debugCanvas(size.width(), size.height());
57 pic->playback(&debugCanvas);
58 std::unique_ptr<SkCanvas> nullCanvas = SkMakeNullCanvas();
59 UrlDataManager dataManager(SkString("data"));
62 writer.beginObject(); // root
63 debugCanvas.toJSON(writer, dataManager, nullCanvas.get());
64 writer.endObject(); // root
65 writer.flush();
66 if (argc > 2) {
68 dataManager.getDataFromUrl(SkString(argv[2]))) {
69 SkData* skdata = data->fData.get();
70 SkASSERT(skdata);
71 #ifdef SK_BUILD_FOR_WIN
72 fflush(stdout);
73 (void)_setmode(_fileno(stdout), _O_BINARY);
74 #endif
75 fwrite(skdata->data(), skdata->size(), 1, stdout);
76 } else {
77 SkDebugf("Bad data url.\n");
78 return 4;
79 }
80 } else {
81 sk_sp<SkData> data = stream.detachAsData();
82 fwrite(data->data(), data->size(), 1, stdout);
83 }
84 return 0;
85}
#define SkASSERT(cond)
Definition: SkAssert.h:116
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
SK_API std::unique_ptr< SkCanvas > SkMakeNullCanvas()
void toJSON(SkJSONWriter &writer, UrlDataManager &urlDataManager, SkCanvas *)
Definition: SkData.h:25
const void * data() const
Definition: SkData.h:37
size_t size() const
Definition: SkData.h:30
bool isValid() const
Definition: SkStream.h:320
void beginObject(const char *name=nullptr, bool multiline=true)
Definition: SkJSONWriter.h:114
void endObject()
Definition: SkJSONWriter.h:126
void flush()
Definition: SkJSONWriter.h:78
virtual SkRect cullRect() const =0
virtual void playback(SkCanvas *canvas, AbortCallback *callback=nullptr) const =0
static sk_sp< SkPicture > MakeFromStream(SkStream *stream, const SkDeserialProcs *procs=nullptr)
Definition: SkPicture.cpp:147
UrlData * getDataFromUrl(const SkString &url)
char ** argv
Definition: library.h:9
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
int main(int argc, char **argv)
Definition: skp_parser.cpp:40
Definition: SkSize.h:16
void roundOut(SkIRect *dst) const
Definition: SkRect.h:1241
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63