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