blob: 885046a1d1871076794880cf15285bb1947743fe [file] [log] [blame]
commit-bot@chromium.org545a21a2014-05-06 19:45:18 +00001/*
2 * Copyright 2014 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 <stdio.h>
9
commit-bot@chromium.org545a21a2014-05-06 19:45:18 +000010#include "SkCommandLineFlags.h"
11#include "SkGraphics.h"
commit-bot@chromium.org545a21a2014-05-06 19:45:18 +000012#include "SkPicture.h"
commit-bot@chromium.org545a21a2014-05-06 19:45:18 +000013#include "SkRecordOpts.h"
14#include "SkRecorder.h"
15#include "SkStream.h"
16
commit-bot@chromium.org85fd1932014-05-15 16:10:37 +000017#include "DumpRecord.h"
18#include "LazyDecodeBitmap.h"
19
commit-bot@chromium.org545a21a2014-05-06 19:45:18 +000020DEFINE_string2(skps, r, "", ".SKPs to dump.");
21DEFINE_string(match, "", "The usual filters on file names to dump.");
22DEFINE_bool2(optimize, O, false, "Run SkRecordOptimize before dumping.");
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000023DEFINE_int32(tile, 1000000000, "Simulated tile size.");
24DEFINE_bool(timeWithCommand, false, "If true, print time next to command, else in first column.");
commit-bot@chromium.org545a21a2014-05-06 19:45:18 +000025
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000026static void dump(const char* name, int w, int h, const SkRecord& record) {
27 SkBitmap bitmap;
28 bitmap.allocN32Pixels(w, h);
29 SkCanvas canvas(bitmap);
commit-bot@chromium.org85fd1932014-05-15 16:10:37 +000030 canvas.clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile),
31 SkIntToScalar(FLAGS_tile)));
commit-bot@chromium.org545a21a2014-05-06 19:45:18 +000032
33 printf("%s %s\n", FLAGS_optimize ? "optimized" : "not-optimized", name);
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000034
commit-bot@chromium.org85fd1932014-05-15 16:10:37 +000035 DumpRecord(record, &canvas, FLAGS_timeWithCommand);
commit-bot@chromium.org545a21a2014-05-06 19:45:18 +000036}
37
commit-bot@chromium.org85fd1932014-05-15 16:10:37 +000038
commit-bot@chromium.org545a21a2014-05-06 19:45:18 +000039int tool_main(int argc, char** argv);
40int tool_main(int argc, char** argv) {
41 SkCommandLineFlags::Parse(argc, argv);
42 SkAutoGraphics ag;
43
44 for (int i = 0; i < FLAGS_skps.count(); i++) {
45 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, FLAGS_skps[i])) {
46 continue;
47 }
48
scroggoa1193e42015-01-21 12:09:53 -080049 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(FLAGS_skps[i]));
commit-bot@chromium.org545a21a2014-05-06 19:45:18 +000050 if (!stream) {
51 SkDebugf("Could not read %s.\n", FLAGS_skps[i]);
52 exit(1);
53 }
54 SkAutoTUnref<SkPicture> src(
55 SkPicture::CreateFromStream(stream, sk_tools::LazyDecodeBitmap));
56 if (!src) {
57 SkDebugf("Could not read %s as an SkPicture.\n", FLAGS_skps[i]);
58 exit(1);
59 }
robertphillipsa8d7f0b2014-08-29 08:03:56 -070060 const int w = SkScalarCeilToInt(src->cullRect().width());
61 const int h = SkScalarCeilToInt(src->cullRect().height());
commit-bot@chromium.org545a21a2014-05-06 19:45:18 +000062
63 SkRecord record;
commit-bot@chromium.orga0950412014-05-29 16:52:40 +000064 SkRecorder canvas(&record, w, h);
robertphillipsc5ba71d2014-09-04 08:42:50 -070065 src->playback(&canvas);
commit-bot@chromium.org545a21a2014-05-06 19:45:18 +000066
67 if (FLAGS_optimize) {
68 SkRecordOptimize(&record);
69 }
70
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000071 dump(FLAGS_skps[i], w, h, record);
commit-bot@chromium.org545a21a2014-05-06 19:45:18 +000072 }
73
74 return 0;
75}
76
77#if !defined SK_BUILD_FOR_IOS
78int main(int argc, char * const argv[]) {
79 return tool_main(argc, (char**) argv);
80}
81#endif