blob: b8deba707a0f6e51a5f870a9a7fe52119a4da22f [file] [log] [blame]
reed@google.com1bdf7fe2012-06-14 18:58:40 +00001/*
2 * Copyright 2012 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
reed@google.com1bdf7fe2012-06-14 18:58:40 +00008#include "SkBitmap.h"
9#include "SkCanvas.h"
commit-bot@chromium.org826ec812013-06-12 18:28:36 +000010#include "SkGraphics.h"
reed@google.com1bdf7fe2012-06-14 18:58:40 +000011#include "SkOSFile.h"
commit-bot@chromium.org826ec812013-06-12 18:28:36 +000012#include "SkImageDecoder.h"
reed@google.com1bdf7fe2012-06-14 18:58:40 +000013#include "SkPicture.h"
14#include "SkStream.h"
15#include "SkString.h"
reed@google.comb1d47e22012-08-31 15:41:37 +000016#include "SkDumpCanvas.h"
reed@google.com1bdf7fe2012-06-14 18:58:40 +000017
reed@google.comb1d47e22012-08-31 15:41:37 +000018static SkPicture* inspect(const char path[]) {
reed@google.com1bdf7fe2012-06-14 18:58:40 +000019 SkFILEStream stream(path);
20 if (!stream.isValid()) {
21 printf("-- Can't open '%s'\n", path);
halcanary96fcdcc2015-08-27 07:41:13 -070022 return nullptr;
reed@google.com1bdf7fe2012-06-14 18:58:40 +000023 }
24
25 printf("Opening '%s'...\n", path);
26
27 {
28 int32_t header[3];
29 if (stream.read(header, sizeof(header)) != sizeof(header)) {
30 printf("-- Failed to read header (12 bytes)\n");
halcanary96fcdcc2015-08-27 07:41:13 -070031 return nullptr;
reed@google.com1bdf7fe2012-06-14 18:58:40 +000032 }
33 printf("version:%d width:%d height:%d\n", header[0], header[1], header[2]);
34 }
35
36 stream.rewind();
msarett8715d472016-02-17 10:02:29 -080037 SkPicture* pic = SkPicture::CreateFromStream(&stream);
halcanary96fcdcc2015-08-27 07:41:13 -070038 if (nullptr == pic) {
commit-bot@chromium.org826ec812013-06-12 18:28:36 +000039 SkDebugf("Could not create SkPicture: %s\n", path);
halcanary96fcdcc2015-08-27 07:41:13 -070040 return nullptr;
commit-bot@chromium.org826ec812013-06-12 18:28:36 +000041 }
robertphillipsa8d7f0b2014-08-29 08:03:56 -070042 printf("picture cullRect: [%f %f %f %f]\n",
43 pic->cullRect().fLeft, pic->cullRect().fTop,
44 pic->cullRect().fRight, pic->cullRect().fBottom);
reed@google.comb1d47e22012-08-31 15:41:37 +000045 return pic;
46}
47
48static void dumpOps(SkPicture* pic) {
robertphillips@google.com76f9e932013-01-15 20:17:47 +000049#ifdef SK_DEVELOPER
reed@google.comb1d47e22012-08-31 15:41:37 +000050 SkDebugfDumper dumper;
51 SkDumpCanvas canvas(&dumper);
robertphillips9b14f262014-06-04 05:40:44 -070052 canvas.drawPicture(pic);
robertphillips@google.com76f9e932013-01-15 20:17:47 +000053#else
54 printf("SK_DEVELOPER mode not enabled\n");
55#endif
reed@google.com1bdf7fe2012-06-14 18:58:40 +000056}
57
caryclark@google.com5987f582012-10-02 18:33:14 +000058int tool_main(int argc, char** argv);
59int tool_main(int argc, char** argv) {
commit-bot@chromium.org826ec812013-06-12 18:28:36 +000060 SkAutoGraphics ag;
reed@google.com1bdf7fe2012-06-14 18:58:40 +000061 if (argc < 2) {
fmalita@google.comc6157be2012-09-27 13:09:58 +000062 printf("Usage: pinspect [--dump-ops] filename [filename ...]\n");
63 return 1;
reed@google.com1bdf7fe2012-06-14 18:58:40 +000064 }
reed@google.comb1d47e22012-08-31 15:41:37 +000065
66 bool doDumpOps = false;
67
68 int index = 1;
69 if (!strcmp(argv[index], "--dump-ops")) {
70 index += 1;
71 doDumpOps = true;
72 }
73
74 for (; index < argc; ++index) {
75 SkAutoTUnref<SkPicture> pic(inspect(argv[index]));
76 if (doDumpOps) {
77 dumpOps(pic);
78 }
79 if (index < argc - 1) {
reed@google.com1bdf7fe2012-06-14 18:58:40 +000080 printf("\n");
81 }
82 }
83 return 0;
84}
caryclark@google.com5987f582012-10-02 18:33:14 +000085
86#if !defined SK_BUILD_FOR_IOS
87int main(int argc, char * const argv[]) {
88 return tool_main(argc, (char**) argv);
89}
90#endif