blob: b82bd332c794111847ff5e8505ce22a00d31e431 [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
8
9#include "SkBitmap.h"
10#include "SkCanvas.h"
11#include "SkOSFile.h"
12#include "SkPicture.h"
13#include "SkStream.h"
14#include "SkString.h"
reed@google.comb1d47e22012-08-31 15:41:37 +000015#include "SkDumpCanvas.h"
reed@google.com1bdf7fe2012-06-14 18:58:40 +000016
reed@google.comb1d47e22012-08-31 15:41:37 +000017static SkPicture* inspect(const char path[]) {
reed@google.com1bdf7fe2012-06-14 18:58:40 +000018 SkFILEStream stream(path);
19 if (!stream.isValid()) {
20 printf("-- Can't open '%s'\n", path);
reed@google.comb1d47e22012-08-31 15:41:37 +000021 return NULL;
reed@google.com1bdf7fe2012-06-14 18:58:40 +000022 }
23
24 printf("Opening '%s'...\n", path);
25
26 {
27 int32_t header[3];
28 if (stream.read(header, sizeof(header)) != sizeof(header)) {
29 printf("-- Failed to read header (12 bytes)\n");
reed@google.comb1d47e22012-08-31 15:41:37 +000030 return NULL;
reed@google.com1bdf7fe2012-06-14 18:58:40 +000031 }
32 printf("version:%d width:%d height:%d\n", header[0], header[1], header[2]);
33 }
34
35 stream.rewind();
reed@google.comb1d47e22012-08-31 15:41:37 +000036 SkPicture* pic = SkNEW_ARGS(SkPicture, (&stream));
37 printf("picture size:[%d %d]\n", pic->width(), pic->height());
38 return pic;
39}
40
41static void dumpOps(SkPicture* pic) {
42 SkDebugfDumper dumper;
43 SkDumpCanvas canvas(&dumper);
44 canvas.drawPicture(*pic);
reed@google.com1bdf7fe2012-06-14 18:58:40 +000045}
46
caryclark@google.com5987f582012-10-02 18:33:14 +000047int tool_main(int argc, char** argv);
48int tool_main(int argc, char** argv) {
reed@google.com1bdf7fe2012-06-14 18:58:40 +000049 if (argc < 2) {
fmalita@google.comc6157be2012-09-27 13:09:58 +000050 printf("Usage: pinspect [--dump-ops] filename [filename ...]\n");
51 return 1;
reed@google.com1bdf7fe2012-06-14 18:58:40 +000052 }
reed@google.comb1d47e22012-08-31 15:41:37 +000053
54 bool doDumpOps = false;
55
56 int index = 1;
57 if (!strcmp(argv[index], "--dump-ops")) {
58 index += 1;
59 doDumpOps = true;
60 }
61
62 for (; index < argc; ++index) {
63 SkAutoTUnref<SkPicture> pic(inspect(argv[index]));
64 if (doDumpOps) {
65 dumpOps(pic);
66 }
67 if (index < argc - 1) {
reed@google.com1bdf7fe2012-06-14 18:58:40 +000068 printf("\n");
69 }
70 }
71 return 0;
72}
caryclark@google.com5987f582012-10-02 18:33:14 +000073
74#if !defined SK_BUILD_FOR_IOS
75int main(int argc, char * const argv[]) {
76 return tool_main(argc, (char**) argv);
77}
78#endif