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 | |
Mike Klein | be28ee2 | 2017-02-06 12:46:20 -0500 | [diff] [blame] | 57 | int main(int argc, char** argv) { |
commit-bot@chromium.org | 826ec81 | 2013-06-12 18:28:36 +0000 | [diff] [blame] | 58 | SkAutoGraphics ag; |
reed@google.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 59 | if (argc < 2) { |
fmalita@google.com | c6157be | 2012-09-27 13:09:58 +0000 | [diff] [blame] | 60 | printf("Usage: pinspect [--dump-ops] filename [filename ...]\n"); |
| 61 | return 1; |
reed@google.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 62 | } |
reed@google.com | b1d47e2 | 2012-08-31 15:41:37 +0000 | [diff] [blame] | 63 | |
| 64 | bool doDumpOps = false; |
| 65 | |
| 66 | int index = 1; |
| 67 | if (!strcmp(argv[index], "--dump-ops")) { |
| 68 | index += 1; |
| 69 | doDumpOps = true; |
| 70 | } |
| 71 | |
| 72 | for (; index < argc; ++index) { |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 73 | auto pic(inspect(argv[index])); |
reed@google.com | b1d47e2 | 2012-08-31 15:41:37 +0000 | [diff] [blame] | 74 | if (doDumpOps) { |
reed | ca2622b | 2016-03-18 07:25:55 -0700 | [diff] [blame] | 75 | dumpOps(pic.get()); |
reed@google.com | b1d47e2 | 2012-08-31 15:41:37 +0000 | [diff] [blame] | 76 | } |
| 77 | if (index < argc - 1) { |
reed@google.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 78 | printf("\n"); |
| 79 | } |
| 80 | } |
| 81 | return 0; |
| 82 | } |