blob: 783c378f447dafd3e8459459b55535b78e25a7d6 [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"
Florin Malitaab244f02017-05-03 19:16:58 +00009#include "SkBitmap.h"
mtklein2f2903d2015-11-18 11:06:37 -080010#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
Mike Kleinbe28ee22017-02-06 12:46:20 -050039int main(int argc, char** argv) {
mtklein2f2903d2015-11-18 11:06:37 -080040 SkCommandLineFlags::Parse(argc, argv);
41
42 for (int i = 0; i < FLAGS_skps.count(); i++) {
43 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, FLAGS_skps[i])) {
44 continue;
45 }
46
bungemanf93d7112016-09-16 06:24:20 -070047 std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(FLAGS_skps[i]);
mtklein2f2903d2015-11-18 11:06:37 -080048 if (!stream) {
49 SkDebugf("Could not read %s.\n", FLAGS_skps[i]);
50 return 1;
51 }
bungemanf93d7112016-09-16 06:24:20 -070052 sk_sp<SkPicture> src(SkPicture::MakeFromStream(stream.get()));
mtklein2f2903d2015-11-18 11:06:37 -080053 if (!src) {
54 SkDebugf("Could not read %s as an SkPicture.\n", FLAGS_skps[i]);
55 return 1;
56 }
57 const int w = SkScalarCeilToInt(src->cullRect().width());
58 const int h = SkScalarCeilToInt(src->cullRect().height());
59
60 SkRecord record;
61 SkRecorder canvas(&record, w, h);
62 src->playback(&canvas);
63
64 if (FLAGS_optimize) {
65 SkRecordOptimize(&record);
66 }
reedf38b0d82015-11-19 10:31:08 -080067 if (FLAGS_optimize2) {
68 SkRecordOptimize2(&record);
69 }
mtklein2f2903d2015-11-18 11:06:37 -080070
71 dump(FLAGS_skps[i], w, h, record);
reedff53af82015-11-19 08:18:04 -080072
73 if (FLAGS_write.count() > 0) {
74 SkPictureRecorder r;
75 SkRecordDraw(record,
76 r.beginRecording(SkRect::MakeIWH(w, h)),
77 nullptr,
78 nullptr,
79 0,
80 nullptr,
81 nullptr);
reedca2622b2016-03-18 07:25:55 -070082 sk_sp<SkPicture> dst(r.finishRecordingAsPicture());
reedff53af82015-11-19 08:18:04 -080083 SkFILEWStream ostream(FLAGS_write[0]);
84 dst->serialize(&ostream);
85 }
mtklein2f2903d2015-11-18 11:06:37 -080086 }
87
88 return 0;
89}