blob: abfb12f6451134c84f1df38bc36bf848d20b623c [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "include/core/SkBitmap.h"
9#include "include/core/SkPicture.h"
10#include "include/core/SkPictureRecorder.h"
11#include "include/core/SkStream.h"
12#include "src/core/SkRecordDraw.h"
13#include "src/core/SkRecordOpts.h"
14#include "src/core/SkRecorder.h"
15#include "tools/DumpRecord.h"
16#include "tools/flags/CommandLineFlags.h"
Hal Canary8a001442018-09-19 11:31:27 -040017
mtklein2f2903d2015-11-18 11:06:37 -080018#include <stdio.h>
19
Mike Klein84836b72019-03-21 11:31:36 -050020static DEFINE_string2(skps, r, "", ".SKPs to dump.");
21static DEFINE_string(match, "", "The usual filters on file names to dump.");
22static DEFINE_bool2(optimize, O, false, "Run SkRecordOptimize before dumping.");
23static DEFINE_bool(optimize2, false, "Run SkRecordOptimize2 before dumping.");
Mike Klein5b3f3432019-03-21 11:42:21 -050024static DEFINE_int(tile, 1000000000, "Simulated tile size.");
Mike Klein84836b72019-03-21 11:31:36 -050025static DEFINE_bool(timeWithCommand, false,
26 "If true, print time next to command, else in first column.");
27static DEFINE_string2(write, w, "", "Write the (optimized) picture to the named file.");
mtklein2f2903d2015-11-18 11:06:37 -080028
29static void dump(const char* name, int w, int h, const SkRecord& record) {
30 SkBitmap bitmap;
31 bitmap.allocN32Pixels(w, h);
32 SkCanvas canvas(bitmap);
33 canvas.clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile),
34 SkIntToScalar(FLAGS_tile)));
35
36 printf("%s %s\n", FLAGS_optimize ? "optimized" : "not-optimized", name);
37
38 DumpRecord(record, &canvas, FLAGS_timeWithCommand);
39}
40
Mike Kleinbe28ee22017-02-06 12:46:20 -050041int main(int argc, char** argv) {
Mike Klein88544fb2019-03-20 10:50:33 -050042 CommandLineFlags::Parse(argc, argv);
mtklein2f2903d2015-11-18 11:06:37 -080043
44 for (int i = 0; i < FLAGS_skps.count(); i++) {
Mike Klein88544fb2019-03-20 10:50:33 -050045 if (CommandLineFlags::ShouldSkip(FLAGS_match, FLAGS_skps[i])) {
mtklein2f2903d2015-11-18 11:06:37 -080046 continue;
47 }
48
bungemanf93d7112016-09-16 06:24:20 -070049 std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(FLAGS_skps[i]);
mtklein2f2903d2015-11-18 11:06:37 -080050 if (!stream) {
51 SkDebugf("Could not read %s.\n", FLAGS_skps[i]);
52 return 1;
53 }
bungemanf93d7112016-09-16 06:24:20 -070054 sk_sp<SkPicture> src(SkPicture::MakeFromStream(stream.get()));
mtklein2f2903d2015-11-18 11:06:37 -080055 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);
reedca2622b2016-03-18 07:25:55 -070084 sk_sp<SkPicture> dst(r.finishRecordingAsPicture());
reedff53af82015-11-19 08:18:04 -080085 SkFILEWStream ostream(FLAGS_write[0]);
86 dst->serialize(&ostream);
87 }
mtklein2f2903d2015-11-18 11:06:37 -080088 }
89
90 return 0;
91}