Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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) {
67 if (UrlDataManager::UrlData* data =
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 *)
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)
static sk_sp< SkPicture > MakeFromStream(SkStream *stream, const SkDeserialProcs *procs=nullptr)
UrlData * getDataFromUrl(const SkString &url)
char ** argv
Definition library.h:9
Definition main.py:1