reed@google.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 1 | /* |
| 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.com | b1d47e2 | 2012-08-31 15:41:37 +0000 | [diff] [blame] | 15 | #include "SkDumpCanvas.h" |
reed@google.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 16 | |
reed@google.com | b1d47e2 | 2012-08-31 15:41:37 +0000 | [diff] [blame] | 17 | static SkPicture* inspect(const char path[]) { |
reed@google.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 18 | SkFILEStream stream(path); |
| 19 | if (!stream.isValid()) { |
| 20 | printf("-- Can't open '%s'\n", path); |
reed@google.com | b1d47e2 | 2012-08-31 15:41:37 +0000 | [diff] [blame] | 21 | return NULL; |
reed@google.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 22 | } |
| 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.com | b1d47e2 | 2012-08-31 15:41:37 +0000 | [diff] [blame] | 30 | return NULL; |
reed@google.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 31 | } |
| 32 | printf("version:%d width:%d height:%d\n", header[0], header[1], header[2]); |
| 33 | } |
| 34 | |
| 35 | stream.rewind(); |
reed@google.com | b1d47e2 | 2012-08-31 15:41:37 +0000 | [diff] [blame] | 36 | SkPicture* pic = SkNEW_ARGS(SkPicture, (&stream)); |
| 37 | printf("picture size:[%d %d]\n", pic->width(), pic->height()); |
| 38 | return pic; |
| 39 | } |
| 40 | |
| 41 | static void dumpOps(SkPicture* pic) { |
| 42 | SkDebugfDumper dumper; |
| 43 | SkDumpCanvas canvas(&dumper); |
| 44 | canvas.drawPicture(*pic); |
reed@google.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 45 | } |
| 46 | |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 47 | int tool_main(int argc, char** argv); |
| 48 | int tool_main(int argc, char** argv) { |
reed@google.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 49 | if (argc < 2) { |
fmalita@google.com | c6157be | 2012-09-27 13:09:58 +0000 | [diff] [blame] | 50 | printf("Usage: pinspect [--dump-ops] filename [filename ...]\n"); |
| 51 | return 1; |
reed@google.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 52 | } |
reed@google.com | b1d47e2 | 2012-08-31 15:41:37 +0000 | [diff] [blame] | 53 | |
| 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.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 68 | printf("\n"); |
| 69 | } |
| 70 | } |
| 71 | return 0; |
| 72 | } |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 73 | |
| 74 | #if !defined SK_BUILD_FOR_IOS |
| 75 | int main(int argc, char * const argv[]) { |
| 76 | return tool_main(argc, (char**) argv); |
| 77 | } |
| 78 | #endif |