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 
8 #include "SkBitmap.h"
9 #include "SkCanvas.h"
10 #include "SkGraphics.h"
11 #include "SkOSFile.h"
12 #include "SkPicture.h"
13 #include "SkStream.h"
14 #include "SkString.h"
15 #include "SkDumpCanvas.h"
16 
17 static sk_sp<SkPicture> inspect(const char path[]) {
18     SkFILEStream stream(path);
19     if (!stream.isValid()) {
20         printf("-- Can't open '%s'\n", path);
21         return nullptr;
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");
30             return nullptr;
31         }
32         printf("version:%d width:%d height:%d\n", header[0], header[1], header[2]);
33     }
34 
35     stream.rewind();
36     auto pic = SkPicture::MakeFromStream(&stream);
37     if (nullptr == pic) {
38         SkDebugf("Could not create SkPicture: %s\n", path);
39         return nullptr;
40     }
41     printf("picture cullRect: [%f %f %f %f]\n",
42            pic->cullRect().fLeft, pic->cullRect().fTop,
43            pic->cullRect().fRight, pic->cullRect().fBottom);
44     return pic;
45 }
46 
47 static void dumpOps(SkPicture* pic) {
48 #ifdef SK_DEBUG
49     SkDebugfDumper dumper;
50     SkDumpCanvas canvas(&dumper);
51     canvas.drawPicture(pic);
52 #else
53     printf("SK_DEBUG mode not enabled\n");
54 #endif
55 }
56 
57 int main(int argc, char** argv) {
58     SkAutoGraphics ag;
59     if (argc < 2) {
60         printf("Usage: pinspect [--dump-ops] filename [filename ...]\n");
61         return 1;
62     }
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) {
73         auto pic(inspect(argv[index]));
74         if (doDumpOps) {
75             dumpOps(pic.get());
76         }
77         if (index < argc - 1) {
78             printf("\n");
79         }
80     }
81     return 0;
82 }
83