blob: 887c50d18254701bacb9e073f3c156e4c8846b60 [file] [log] [blame]
halcanarya73d76a2016-10-17 13:19:02 -07001/*
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
8#include <iostream>
9
10#include "SkDebugCanvas.h"
11#include "SkNullCanvas.h"
12#include "SkStream.h"
13
14#ifdef SK_BUILD_FOR_WIN
15#include <fcntl.h>
16#include <io.h>
17#endif
18
19int main(int argc, char** argv) {
20 if (argc < 2) {
21 SkDebugf("Usage:\n %s SKP_FILE [DATA_URL]\n", argv[0]);
22 return 1;
23 }
24 SkFILEStream input(argv[1]);
25 if (!input.isValid()) {
26 SkDebugf("Bad file: '%s'\n", argv[1]);
27 return 2;
28 }
29 sk_sp<SkPicture> pic = SkPicture::MakeFromStream(&input);
30 if (!pic) {
31 SkDebugf("Bad skp: '%s'\n", argv[1]);
32 return 3;
33 }
34 SkISize size = pic->cullRect().roundOut().size();
35 SkDebugCanvas debugCanvas(size.width(), size.height());
36 pic->playback(&debugCanvas);
Mike Reed5df49342016-11-12 08:06:55 -060037 std::unique_ptr<SkCanvas> nullCanvas = SkMakeNullCanvas();
halcanarya73d76a2016-10-17 13:19:02 -070038 UrlDataManager dataManager(SkString("data"));
39 Json::Value json = debugCanvas.toJSON(
40 dataManager, debugCanvas.getSize(), nullCanvas.get());
41 if (argc > 2) {
42 if (UrlDataManager::UrlData* data =
43 dataManager.getDataFromUrl(SkString(argv[2]))) {
44 SkData* skdata = data->fData.get();
45 SkASSERT(skdata);
46 #ifdef SK_BUILD_FOR_WIN
47 fflush(stdout);
48 (void)_setmode(_fileno(stdout), _O_BINARY);
49 #endif
50 fwrite(skdata->data(), skdata->size(), 1, stdout);
51 } else {
52 SkDebugf("Bad data url.\n");
53 return 4;
54 }
55 } else {
56 Json::StyledStreamWriter(" ").write(std::cout, json);
57 }
58 return 0;
59}