blob: 4dfabcdca48c57c27619fd2678db1974d2205d1c [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
reed@google.com1bdf7fe2012-06-14 18:58:40 +00008#include "SkBitmap.h"
9#include "SkCanvas.h"
commit-bot@chromium.org826ec812013-06-12 18:28:36 +000010#include "SkGraphics.h"
reed@google.com1bdf7fe2012-06-14 18:58:40 +000011#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
reedca2622b2016-03-18 07:25:55 -070017static sk_sp<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);
halcanary96fcdcc2015-08-27 07:41:13 -070021 return nullptr;
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");
halcanary96fcdcc2015-08-27 07:41:13 -070030 return nullptr;
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();
reedca2622b2016-03-18 07:25:55 -070036 auto pic = SkPicture::MakeFromStream(&stream);
halcanary96fcdcc2015-08-27 07:41:13 -070037 if (nullptr == pic) {
commit-bot@chromium.org826ec812013-06-12 18:28:36 +000038 SkDebugf("Could not create SkPicture: %s\n", path);
halcanary96fcdcc2015-08-27 07:41:13 -070039 return nullptr;
commit-bot@chromium.org826ec812013-06-12 18:28:36 +000040 }
halcanary9d524f22016-03-29 09:03:52 -070041 printf("picture cullRect: [%f %f %f %f]\n",
robertphillipsa8d7f0b2014-08-29 08:03:56 -070042 pic->cullRect().fLeft, pic->cullRect().fTop,
43 pic->cullRect().fRight, pic->cullRect().fBottom);
reed@google.comb1d47e22012-08-31 15:41:37 +000044 return pic;
45}
46
47static void dumpOps(SkPicture* pic) {
djsollenefe46d22016-04-29 06:41:35 -070048#ifdef SK_DEBUG
reed@google.comb1d47e22012-08-31 15:41:37 +000049 SkDebugfDumper dumper;
50 SkDumpCanvas canvas(&dumper);
robertphillips9b14f262014-06-04 05:40:44 -070051 canvas.drawPicture(pic);
robertphillips@google.com76f9e932013-01-15 20:17:47 +000052#else
djsollenefe46d22016-04-29 06:41:35 -070053 printf("SK_DEBUG mode not enabled\n");
robertphillips@google.com76f9e932013-01-15 20:17:47 +000054#endif
reed@google.com1bdf7fe2012-06-14 18:58:40 +000055}
56
caryclark@google.com5987f582012-10-02 18:33:14 +000057int tool_main(int argc, char** argv);
58int tool_main(int argc, char** argv) {
commit-bot@chromium.org826ec812013-06-12 18:28:36 +000059 SkAutoGraphics ag;
reed@google.com1bdf7fe2012-06-14 18:58:40 +000060 if (argc < 2) {
fmalita@google.comc6157be2012-09-27 13:09:58 +000061 printf("Usage: pinspect [--dump-ops] filename [filename ...]\n");
62 return 1;
reed@google.com1bdf7fe2012-06-14 18:58:40 +000063 }
reed@google.comb1d47e22012-08-31 15:41:37 +000064
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) {
reedca2622b2016-03-18 07:25:55 -070074 auto pic(inspect(argv[index]));
reed@google.comb1d47e22012-08-31 15:41:37 +000075 if (doDumpOps) {
reedca2622b2016-03-18 07:25:55 -070076 dumpOps(pic.get());
reed@google.comb1d47e22012-08-31 15:41:37 +000077 }
78 if (index < argc - 1) {
reed@google.com1bdf7fe2012-06-14 18:58:40 +000079 printf("\n");
80 }
81 }
82 return 0;
83}
caryclark@google.com5987f582012-10-02 18:33:14 +000084
85#if !defined SK_BUILD_FOR_IOS
86int main(int argc, char * const argv[]) {
87 return tool_main(argc, (char**) argv);
88}
89#endif