blob: 029638efb100d523ac8ab1c8916af25cccc8a2b6 [file] [log] [blame]
mtklein2f2903d2015-11-18 11:06:37 -08001/*
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 "DumpRecord.h"
9#include "LazyDecodeBitmap.h"
10#include "SkCommandLineFlags.h"
11#include "SkPicture.h"
reedff53af82015-11-19 08:18:04 -080012#include "SkPictureRecorder.h"
13#include "SkRecordDraw.h"
mtklein2f2903d2015-11-18 11:06:37 -080014#include "SkRecordOpts.h"
15#include "SkRecorder.h"
16#include "SkStream.h"
17#include <stdio.h>
18
19DEFINE_string2(skps, r, "", ".SKPs to dump.");
20DEFINE_string(match, "", "The usual filters on file names to dump.");
21DEFINE_bool2(optimize, O, false, "Run SkRecordOptimize before dumping.");
reedf38b0d82015-11-19 10:31:08 -080022DEFINE_bool(optimize2, false, "Run SkRecordOptimize2 before dumping.");
mtklein2f2903d2015-11-18 11:06:37 -080023DEFINE_int32(tile, 1000000000, "Simulated tile size.");
24DEFINE_bool(timeWithCommand, false, "If true, print time next to command, else in first column.");
reedff53af82015-11-19 08:18:04 -080025DEFINE_string2(write, w, "", "Write the (optimized) picture to the named file.");
mtklein2f2903d2015-11-18 11:06:37 -080026
27static void dump(const char* name, int w, int h, const SkRecord& record) {
28 SkBitmap bitmap;
29 bitmap.allocN32Pixels(w, h);
30 SkCanvas canvas(bitmap);
31 canvas.clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile),
32 SkIntToScalar(FLAGS_tile)));
33
34 printf("%s %s\n", FLAGS_optimize ? "optimized" : "not-optimized", name);
35
36 DumpRecord(record, &canvas, FLAGS_timeWithCommand);
37}
38
mtklein2f2903d2015-11-18 11:06:37 -080039int tool_main(int argc, char** argv);
40int tool_main(int argc, char** argv) {
41 SkCommandLineFlags::Parse(argc, argv);
42
43 for (int i = 0; i < FLAGS_skps.count(); i++) {
44 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, FLAGS_skps[i])) {
45 continue;
46 }
47
48 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(FLAGS_skps[i]));
49 if (!stream) {
50 SkDebugf("Could not read %s.\n", FLAGS_skps[i]);
51 return 1;
52 }
53 SkAutoTUnref<SkPicture> src(
54 SkPicture::CreateFromStream(stream, sk_tools::LazyDecodeBitmap));
55 if (!src) {
56 SkDebugf("Could not read %s as an SkPicture.\n", FLAGS_skps[i]);
57 return 1;
58 }
59 const int w = SkScalarCeilToInt(src->cullRect().width());
60 const int h = SkScalarCeilToInt(src->cullRect().height());
61
62 SkRecord record;
63 SkRecorder canvas(&record, w, h);
64 src->playback(&canvas);
65
66 if (FLAGS_optimize) {
67 SkRecordOptimize(&record);
68 }
reedf38b0d82015-11-19 10:31:08 -080069 if (FLAGS_optimize2) {
70 SkRecordOptimize2(&record);
71 }
mtklein2f2903d2015-11-18 11:06:37 -080072
73 dump(FLAGS_skps[i], w, h, record);
reedff53af82015-11-19 08:18:04 -080074
75 if (FLAGS_write.count() > 0) {
76 SkPictureRecorder r;
77 SkRecordDraw(record,
78 r.beginRecording(SkRect::MakeIWH(w, h)),
79 nullptr,
80 nullptr,
81 0,
82 nullptr,
83 nullptr);
84 SkAutoTUnref<SkPicture> dst(r.endRecording());
85 SkFILEWStream ostream(FLAGS_write[0]);
86 dst->serialize(&ostream);
87 }
mtklein2f2903d2015-11-18 11:06:37 -080088 }
89
90 return 0;
91}
92
93#if !defined SK_BUILD_FOR_IOS
94int main(int argc, char * const argv[]) {
95 return tool_main(argc, (char**) argv);
96}
97#endif