blob: 29a422257d0d6e1a2c0279760cf494dc3cf814e6 [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
Mike Kleinbe28ee22017-02-06 12:46:20 -050057int main(int argc, char** argv) {
commit-bot@chromium.org826ec812013-06-12 18:28:36 +000058 SkAutoGraphics ag;
reed@google.com1bdf7fe2012-06-14 18:58:40 +000059 if (argc < 2) {
fmalita@google.comc6157be2012-09-27 13:09:58 +000060 printf("Usage: pinspect [--dump-ops] filename [filename ...]\n");
61 return 1;
reed@google.com1bdf7fe2012-06-14 18:58:40 +000062 }
reed@google.comb1d47e22012-08-31 15:41:37 +000063
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) {
reedca2622b2016-03-18 07:25:55 -070073 auto pic(inspect(argv[index]));
reed@google.comb1d47e22012-08-31 15:41:37 +000074 if (doDumpOps) {
reedca2622b2016-03-18 07:25:55 -070075 dumpOps(pic.get());
reed@google.comb1d47e22012-08-31 15:41:37 +000076 }
77 if (index < argc - 1) {
reed@google.com1bdf7fe2012-06-14 18:58:40 +000078 printf("\n");
79 }
80 }
81 return 0;
82}