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 | |
reed@google.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 8 | #include "SkBitmap.h" |
| 9 | #include "SkCanvas.h" |
commit-bot@chromium.org | 826ec81 | 2013-06-12 18:28:36 +0000 | [diff] [blame] | 10 | #include "SkGraphics.h" |
reed@google.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 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 | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 17 | static sk_sp<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); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 21 | return nullptr; |
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"); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 30 | return nullptr; |
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 | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 36 | auto pic = SkPicture::MakeFromStream(&stream); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 37 | if (nullptr == pic) { |
commit-bot@chromium.org | 826ec81 | 2013-06-12 18:28:36 +0000 | [diff] [blame] | 38 | SkDebugf("Could not create SkPicture: %s\n", path); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 39 | return nullptr; |
commit-bot@chromium.org | 826ec81 | 2013-06-12 18:28:36 +0000 | [diff] [blame] | 40 | } |
halcanary | 9d524f2 | 2016-03-29 09:03:52 -0700 | [diff] [blame] | 41 | printf("picture cullRect: [%f %f %f %f]\n", |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 42 | pic->cullRect().fLeft, pic->cullRect().fTop, |
| 43 | pic->cullRect().fRight, pic->cullRect().fBottom); |
reed@google.com | b1d47e2 | 2012-08-31 15:41:37 +0000 | [diff] [blame] | 44 | return pic; |
| 45 | } |
| 46 | |
| 47 | static void dumpOps(SkPicture* pic) { |
djsollen | efe46d2 | 2016-04-29 06:41:35 -0700 | [diff] [blame] | 48 | #ifdef SK_DEBUG |
reed@google.com | b1d47e2 | 2012-08-31 15:41:37 +0000 | [diff] [blame] | 49 | SkDebugfDumper dumper; |
| 50 | SkDumpCanvas canvas(&dumper); |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 51 | canvas.drawPicture(pic); |
robertphillips@google.com | 76f9e93 | 2013-01-15 20:17:47 +0000 | [diff] [blame] | 52 | #else |
djsollen | efe46d2 | 2016-04-29 06:41:35 -0700 | [diff] [blame] | 53 | printf("SK_DEBUG mode not enabled\n"); |
robertphillips@google.com | 76f9e93 | 2013-01-15 20:17:47 +0000 | [diff] [blame] | 54 | #endif |
reed@google.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 55 | } |
| 56 | |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 57 | int tool_main(int argc, char** argv); |
| 58 | int tool_main(int argc, char** argv) { |
commit-bot@chromium.org | 826ec81 | 2013-06-12 18:28:36 +0000 | [diff] [blame] | 59 | SkAutoGraphics ag; |
reed@google.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 60 | if (argc < 2) { |
fmalita@google.com | c6157be | 2012-09-27 13:09:58 +0000 | [diff] [blame] | 61 | printf("Usage: pinspect [--dump-ops] filename [filename ...]\n"); |
| 62 | return 1; |
reed@google.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 63 | } |
reed@google.com | b1d47e2 | 2012-08-31 15:41:37 +0000 | [diff] [blame] | 64 | |
| 65 | bool doDumpOps = false; |
| 66 | |
| 67 | int index = 1; |
| 68 | if (!strcmp(argv[index], "--dump-ops")) { |
| 69 | index += 1; |
| 70 | doDumpOps = true; |
| 71 | } |
| 72 | |
| 73 | for (; index < argc; ++index) { |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 74 | auto pic(inspect(argv[index])); |
reed@google.com | b1d47e2 | 2012-08-31 15:41:37 +0000 | [diff] [blame] | 75 | if (doDumpOps) { |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 76 | dumpOps(pic.get()); |
reed@google.com | b1d47e2 | 2012-08-31 15:41:37 +0000 | [diff] [blame] | 77 | } |
| 78 | if (index < argc - 1) { |
reed@google.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 79 | printf("\n"); |
| 80 | } |
| 81 | } |
| 82 | return 0; |
| 83 | } |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 84 | |
| 85 | #if !defined SK_BUILD_FOR_IOS |
| 86 | int main(int argc, char * const argv[]) { |
| 87 | return tool_main(argc, (char**) argv); |
| 88 | } |
| 89 | #endif |