blob: 03ef93e58167eb1cd81a0fff39651cbe57198287 [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"
mtklein2f2903d2015-11-18 11:06:37 -08009#include "SkCommandLineFlags.h"
reedbabc3de2016-07-08 08:43:27 -070010#include "SkDeferredCanvas.h"
mtklein2f2903d2015-11-18 11:06:37 -080011#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.");
reedbabc3de2016-07-08 08:43:27 -070026DEFINE_bool(defer, false, "Defer clips and translates");
mtklein2f2903d2015-11-18 11:06:37 -080027
28static void dump(const char* name, int w, int h, const SkRecord& record) {
29 SkBitmap bitmap;
30 bitmap.allocN32Pixels(w, h);
31 SkCanvas canvas(bitmap);
32 canvas.clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile),
33 SkIntToScalar(FLAGS_tile)));
34
35 printf("%s %s\n", FLAGS_optimize ? "optimized" : "not-optimized", name);
36
37 DumpRecord(record, &canvas, FLAGS_timeWithCommand);
38}
39
mtklein2f2903d2015-11-18 11:06:37 -080040int tool_main(int argc, char** argv);
41int tool_main(int argc, char** argv) {
42 SkCommandLineFlags::Parse(argc, argv);
43
44 for (int i = 0; i < FLAGS_skps.count(); i++) {
45 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, FLAGS_skps[i])) {
46 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 }
reedbabc3de2016-07-08 08:43:27 -070059 if (FLAGS_defer) {
60 SkPictureRecorder recorder;
61 SkDeferredCanvas deferred(recorder.beginRecording(src->cullRect()));
62 src->playback(&deferred);
63 src = recorder.finishRecordingAsPicture();
64 }
mtklein2f2903d2015-11-18 11:06:37 -080065 const int w = SkScalarCeilToInt(src->cullRect().width());
66 const int h = SkScalarCeilToInt(src->cullRect().height());
67
68 SkRecord record;
69 SkRecorder canvas(&record, w, h);
70 src->playback(&canvas);
71
72 if (FLAGS_optimize) {
73 SkRecordOptimize(&record);
74 }
reedf38b0d82015-11-19 10:31:08 -080075 if (FLAGS_optimize2) {
76 SkRecordOptimize2(&record);
77 }
mtklein2f2903d2015-11-18 11:06:37 -080078
79 dump(FLAGS_skps[i], w, h, record);
reedff53af82015-11-19 08:18:04 -080080
81 if (FLAGS_write.count() > 0) {
82 SkPictureRecorder r;
83 SkRecordDraw(record,
84 r.beginRecording(SkRect::MakeIWH(w, h)),
85 nullptr,
86 nullptr,
87 0,
88 nullptr,
89 nullptr);
reedca2622b2016-03-18 07:25:55 -070090 sk_sp<SkPicture> dst(r.finishRecordingAsPicture());
reedff53af82015-11-19 08:18:04 -080091 SkFILEWStream ostream(FLAGS_write[0]);
92 dst->serialize(&ostream);
93 }
mtklein2f2903d2015-11-18 11:06:37 -080094 }
95
96 return 0;
97}
98
99#if !defined SK_BUILD_FOR_IOS
100int main(int argc, char * const argv[]) {
101 return tool_main(argc, (char**) argv);
102}
103#endif