blob: 4fb1cf502f895be3c9e116ac24a4bf2bec93c16b [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
49 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(FLAGS_skps[i]));
50 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 }
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000060 const int w = src->width(), h = src->height();
commit-bot@chromium.org545a21a2014-05-06 19:45:18 +000061
62 SkRecord record;
commit-bot@chromium.orga0950412014-05-29 16:52:40 +000063 SkRecorder canvas(&record, w, h);
commit-bot@chromium.org545a21a2014-05-06 19:45:18 +000064 src->draw(&canvas);
65
66 if (FLAGS_optimize) {
67 SkRecordOptimize(&record);
68 }
69
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000070 dump(FLAGS_skps[i], w, h, record);
commit-bot@chromium.org545a21a2014-05-06 19:45:18 +000071 }
72
73 return 0;
74}
75
76#if !defined SK_BUILD_FOR_IOS
77int main(int argc, char * const argv[]) {
78 return tool_main(argc, (char**) argv);
79}
80#endif