Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(519)

Unified Diff: tools/skp_parser.cpp

Issue 2281733003: tools: skp_parser (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: skpparser->skp_parser Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/skiaserve/Request.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/skp_parser.cpp
diff --git a/tools/skp_parser.cpp b/tools/skp_parser.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..d242524566f9c834e1a7fccf500ffafec0e16551
--- /dev/null
+++ b/tools/skp_parser.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <iostream>
+
+#include "SkDebugCanvas.h"
+#include "SkNullCanvas.h"
+#include "SkStream.h"
+
+#ifdef SK_BUILD_FOR_WIN
+#include <fcntl.h>
+#include <io.h>
+#endif
+
+int main(int argc, char** argv) {
+ if (argc < 2) {
+ SkDebugf("Usage:\n %s SKP_FILE [DATA_URL]\n", argv[0]);
+ return 1;
+ }
+ SkFILEStream input(argv[1]);
+ if (!input.isValid()) {
+ SkDebugf("Bad file: '%s'\n", argv[1]);
+ return 2;
+ }
+ sk_sp<SkPicture> pic = SkPicture::MakeFromStream(&input);
+ if (!pic) {
+ SkDebugf("Bad skp: '%s'\n", argv[1]);
+ return 3;
+ }
+ SkISize size = pic->cullRect().roundOut().size();
+ SkDebugCanvas debugCanvas(size.width(), size.height());
+ pic->playback(&debugCanvas);
+ sk_sp<SkCanvas> nullCanvas(SkCreateNullCanvas());
+ UrlDataManager dataManager(SkString("data"));
+ Json::Value json = debugCanvas.toJSON(
+ dataManager, debugCanvas.getSize(), nullCanvas.get());
+ if (argc > 2) {
+ if (UrlDataManager::UrlData* data =
+ dataManager.getDataFromUrl(SkString(argv[2]))) {
+ SkData* skdata = data->fData.get();
+ SkASSERT(skdata);
+ #ifdef SK_BUILD_FOR_WIN
+ fflush(stdout);
+ (void)_setmode(_fileno(stdout), _O_BINARY);
+ #endif
+ fwrite(skdata->data(), skdata->size(), 1, stdout);
+ } else {
+ SkDebugf("Bad data url.\n");
+ return 4;
+ }
+ } else {
+ Json::StyledStreamWriter(" ").write(std::cout, json);
+ }
+ return 0;
+}
« no previous file with comments | « tools/skiaserve/Request.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698