mtklein | 2f2903d | 2015-11-18 11:06:37 -0800 | [diff] [blame^] | 1 | /* |
| 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" |
| 12 | #include "SkRecordOpts.h" |
| 13 | #include "SkRecorder.h" |
| 14 | #include "SkStream.h" |
| 15 | #include <stdio.h> |
| 16 | |
| 17 | DEFINE_string2(skps, r, "", ".SKPs to dump."); |
| 18 | DEFINE_string(match, "", "The usual filters on file names to dump."); |
| 19 | DEFINE_bool2(optimize, O, false, "Run SkRecordOptimize before dumping."); |
| 20 | DEFINE_int32(tile, 1000000000, "Simulated tile size."); |
| 21 | DEFINE_bool(timeWithCommand, false, "If true, print time next to command, else in first column."); |
| 22 | |
| 23 | static void dump(const char* name, int w, int h, const SkRecord& record) { |
| 24 | SkBitmap bitmap; |
| 25 | bitmap.allocN32Pixels(w, h); |
| 26 | SkCanvas canvas(bitmap); |
| 27 | canvas.clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile), |
| 28 | SkIntToScalar(FLAGS_tile))); |
| 29 | |
| 30 | printf("%s %s\n", FLAGS_optimize ? "optimized" : "not-optimized", name); |
| 31 | |
| 32 | DumpRecord(record, &canvas, FLAGS_timeWithCommand); |
| 33 | } |
| 34 | |
| 35 | |
| 36 | int tool_main(int argc, char** argv); |
| 37 | int tool_main(int argc, char** argv) { |
| 38 | SkCommandLineFlags::Parse(argc, argv); |
| 39 | |
| 40 | for (int i = 0; i < FLAGS_skps.count(); i++) { |
| 41 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, FLAGS_skps[i])) { |
| 42 | continue; |
| 43 | } |
| 44 | |
| 45 | SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(FLAGS_skps[i])); |
| 46 | if (!stream) { |
| 47 | SkDebugf("Could not read %s.\n", FLAGS_skps[i]); |
| 48 | return 1; |
| 49 | } |
| 50 | SkAutoTUnref<SkPicture> src( |
| 51 | SkPicture::CreateFromStream(stream, sk_tools::LazyDecodeBitmap)); |
| 52 | if (!src) { |
| 53 | SkDebugf("Could not read %s as an SkPicture.\n", FLAGS_skps[i]); |
| 54 | return 1; |
| 55 | } |
| 56 | const int w = SkScalarCeilToInt(src->cullRect().width()); |
| 57 | const int h = SkScalarCeilToInt(src->cullRect().height()); |
| 58 | |
| 59 | SkRecord record; |
| 60 | SkRecorder canvas(&record, w, h); |
| 61 | src->playback(&canvas); |
| 62 | |
| 63 | if (FLAGS_optimize) { |
| 64 | SkRecordOptimize(&record); |
| 65 | } |
| 66 | |
| 67 | dump(FLAGS_skps[i], w, h, record); |
| 68 | } |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | #if !defined SK_BUILD_FOR_IOS |
| 74 | int main(int argc, char * const argv[]) { |
| 75 | return tool_main(argc, (char**) argv); |
| 76 | } |
| 77 | #endif |