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 | |
commit-bot@chromium.org | 56799e2 | 2013-07-16 18:21:46 +0000 | [diff] [blame] | 8 | #include "LazyDecodeBitmap.h" |
reed@google.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 9 | #include "SkBitmap.h" |
| 10 | #include "SkCanvas.h" |
commit-bot@chromium.org | 826ec81 | 2013-06-12 18:28:36 +0000 | [diff] [blame] | 11 | #include "SkGraphics.h" |
reed@google.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 12 | #include "SkOSFile.h" |
commit-bot@chromium.org | 826ec81 | 2013-06-12 18:28:36 +0000 | [diff] [blame] | 13 | #include "SkImageDecoder.h" |
reed@google.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 14 | #include "SkPicture.h" |
| 15 | #include "SkStream.h" |
| 16 | #include "SkString.h" |
reed@google.com | b1d47e2 | 2012-08-31 15:41:37 +0000 | [diff] [blame] | 17 | #include "SkDumpCanvas.h" |
reed@google.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 18 | |
reed@google.com | b1d47e2 | 2012-08-31 15:41:37 +0000 | [diff] [blame] | 19 | static SkPicture* inspect(const char path[]) { |
reed@google.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 20 | SkFILEStream stream(path); |
| 21 | if (!stream.isValid()) { |
| 22 | printf("-- Can't open '%s'\n", path); |
reed@google.com | b1d47e2 | 2012-08-31 15:41:37 +0000 | [diff] [blame] | 23 | return NULL; |
reed@google.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | printf("Opening '%s'...\n", path); |
| 27 | |
| 28 | { |
| 29 | int32_t header[3]; |
| 30 | if (stream.read(header, sizeof(header)) != sizeof(header)) { |
| 31 | printf("-- Failed to read header (12 bytes)\n"); |
reed@google.com | b1d47e2 | 2012-08-31 15:41:37 +0000 | [diff] [blame] | 32 | return NULL; |
reed@google.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 33 | } |
| 34 | printf("version:%d width:%d height:%d\n", header[0], header[1], header[2]); |
| 35 | } |
| 36 | |
| 37 | stream.rewind(); |
commit-bot@chromium.org | 56799e2 | 2013-07-16 18:21:46 +0000 | [diff] [blame] | 38 | SkPicture* pic = SkPicture::CreateFromStream(&stream, &sk_tools::LazyDecodeBitmap); |
scroggo@google.com | f1754ec | 2013-06-28 21:32:00 +0000 | [diff] [blame] | 39 | if (NULL == pic) { |
commit-bot@chromium.org | 826ec81 | 2013-06-12 18:28:36 +0000 | [diff] [blame] | 40 | SkDebugf("Could not create SkPicture: %s\n", path); |
scroggo@google.com | f1754ec | 2013-06-28 21:32:00 +0000 | [diff] [blame] | 41 | return NULL; |
commit-bot@chromium.org | 826ec81 | 2013-06-12 18:28:36 +0000 | [diff] [blame] | 42 | } |
robertphillips | a8d7f0b | 2014-08-29 08:03:56 -0700 | [diff] [blame] | 43 | printf("picture cullRect: [%f %f %f %f]\n", |
| 44 | pic->cullRect().fLeft, pic->cullRect().fTop, |
| 45 | pic->cullRect().fRight, pic->cullRect().fBottom); |
reed@google.com | b1d47e2 | 2012-08-31 15:41:37 +0000 | [diff] [blame] | 46 | return pic; |
| 47 | } |
| 48 | |
| 49 | static void dumpOps(SkPicture* pic) { |
robertphillips@google.com | 76f9e93 | 2013-01-15 20:17:47 +0000 | [diff] [blame] | 50 | #ifdef SK_DEVELOPER |
reed@google.com | b1d47e2 | 2012-08-31 15:41:37 +0000 | [diff] [blame] | 51 | SkDebugfDumper dumper; |
| 52 | SkDumpCanvas canvas(&dumper); |
robertphillips | 9b14f26 | 2014-06-04 05:40:44 -0700 | [diff] [blame] | 53 | canvas.drawPicture(pic); |
robertphillips@google.com | 76f9e93 | 2013-01-15 20:17:47 +0000 | [diff] [blame] | 54 | #else |
| 55 | printf("SK_DEVELOPER mode not enabled\n"); |
| 56 | #endif |
reed@google.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 57 | } |
| 58 | |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 59 | int tool_main(int argc, char** argv); |
| 60 | int tool_main(int argc, char** argv) { |
commit-bot@chromium.org | 826ec81 | 2013-06-12 18:28:36 +0000 | [diff] [blame] | 61 | SkAutoGraphics ag; |
reed@google.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 62 | if (argc < 2) { |
fmalita@google.com | c6157be | 2012-09-27 13:09:58 +0000 | [diff] [blame] | 63 | printf("Usage: pinspect [--dump-ops] filename [filename ...]\n"); |
| 64 | return 1; |
reed@google.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 65 | } |
reed@google.com | b1d47e2 | 2012-08-31 15:41:37 +0000 | [diff] [blame] | 66 | |
| 67 | bool doDumpOps = false; |
| 68 | |
| 69 | int index = 1; |
| 70 | if (!strcmp(argv[index], "--dump-ops")) { |
| 71 | index += 1; |
| 72 | doDumpOps = true; |
| 73 | } |
| 74 | |
| 75 | for (; index < argc; ++index) { |
| 76 | SkAutoTUnref<SkPicture> pic(inspect(argv[index])); |
| 77 | if (doDumpOps) { |
| 78 | dumpOps(pic); |
| 79 | } |
| 80 | if (index < argc - 1) { |
reed@google.com | 1bdf7fe | 2012-06-14 18:58:40 +0000 | [diff] [blame] | 81 | printf("\n"); |
| 82 | } |
| 83 | } |
| 84 | return 0; |
| 85 | } |
caryclark@google.com | 5987f58 | 2012-10-02 18:33:14 +0000 | [diff] [blame] | 86 | |
| 87 | #if !defined SK_BUILD_FOR_IOS |
| 88 | int main(int argc, char * const argv[]) { |
| 89 | return tool_main(argc, (char**) argv); |
| 90 | } |
| 91 | #endif |