| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkCanvas.h" |
| 8 #include "SkCommandLineFlags.h" | 9 #include "SkCommandLineFlags.h" |
| 9 #include "SkForceLinking.h" | 10 #include "SkForceLinking.h" |
| 10 #include "SkGraphics.h" | 11 #include "SkGraphics.h" |
| 11 #include "SkOSFile.h" | 12 #include "SkOSFile.h" |
| 12 #include "SkPicture.h" | 13 #include "SkPicture.h" |
| 13 #include "SkPictureRecorder.h" | 14 #include "SkPictureRecorder.h" |
| 14 #include "SkStream.h" | 15 #include "SkStream.h" |
| 15 #include "SkString.h" | 16 #include "SkString.h" |
| 16 | 17 |
| 17 #include "../include/record/SkRecording.h" | |
| 18 | |
| 19 #include "Stats.h" | 18 #include "Stats.h" |
| 20 #include "Timer.h" | 19 #include "Timer.h" |
| 21 | 20 |
| 22 __SK_FORCE_IMAGE_DECODER_LINKING; | 21 __SK_FORCE_IMAGE_DECODER_LINKING; |
| 23 | 22 |
| 24 DEFINE_string2(skps, r, "skps", "Directory containing SKPs to playback."); | 23 DEFINE_string2(skps, r, "skps", "Directory containing SKPs to playback."); |
| 25 DEFINE_int32(samples, 10, "Gather this many samples of each picture playback."); | 24 DEFINE_int32(samples, 10, "Gather this many samples of each picture playback."); |
| 26 DEFINE_bool(skr, false, "Play via SkRecord instead of SkPicture."); | 25 DEFINE_bool(skr, false, "Play via SkRecord instead of SkPicture."); |
| 27 DEFINE_int32(tile, 1000000000, "Simulated tile size."); | 26 DEFINE_int32(tile, 1000000000, "Simulated tile size."); |
| 28 DEFINE_string(match, "", "The usual filters on file names of SKPs to bench."); | 27 DEFINE_string(match, "", "The usual filters on file names of SKPs to bench."); |
| 29 DEFINE_string(timescale, "ms", "Print times in ms, us, or ns"); | 28 DEFINE_string(timescale, "ms", "Print times in ms, us, or ns"); |
| 30 DEFINE_int32(verbose, 0, "0: print min sample; " | 29 DEFINE_int32(verbose, 0, "0: print min sample; " |
| 31 "1: print min, mean, max and noise indication " | 30 "1: print min, mean, max and noise indication " |
| 32 "2: print all samples"); | 31 "2: print all samples"); |
| 33 | 32 |
| 34 static double timescale() { | 33 static double timescale() { |
| 35 if (FLAGS_timescale.contains("us")) return 1000; | 34 if (FLAGS_timescale.contains("us")) return 1000; |
| 36 if (FLAGS_timescale.contains("ns")) return 1000000; | 35 if (FLAGS_timescale.contains("ns")) return 1000000; |
| 37 return 1; | 36 return 1; |
| 38 } | 37 } |
| 39 | 38 |
| 40 static SkPicture* rerecord_with_tilegrid(SkPicture& src) { | 39 static SkPicture* rerecord(const SkPicture& src, bool skr) { |
| 41 SkTileGridFactory::TileGridInfo info; | 40 SkTileGridFactory::TileGridInfo info; |
| 42 info.fTileInterval.set(FLAGS_tile, FLAGS_tile); | 41 info.fTileInterval.set(FLAGS_tile, FLAGS_tile); |
| 43 info.fMargin.setEmpty(); | 42 info.fMargin.setEmpty(); |
| 44 info.fOffset.setZero(); | 43 info.fOffset.setZero(); |
| 45 SkTileGridFactory factory(info); | 44 SkTileGridFactory factory(info); |
| 46 | 45 |
| 47 SkPictureRecorder recorder; | 46 SkPictureRecorder recorder; |
| 48 src.draw(recorder.beginRecording(src.width(), src.height(), &factory)); | 47 src.draw(skr ? recorder.EXPERIMENTAL_beginRecording(src.width(), src.height(
), &factory) |
| 48 : recorder. beginRecording(src.width(), src.height(
), &factory)); |
| 49 return recorder.endRecording(); | 49 return recorder.endRecording(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 static EXPERIMENTAL::SkPlayback* rerecord_with_skr(SkPicture& src) { | 52 static void bench(SkPMColor* scratch, const SkPicture& src, const char* name) { |
| 53 EXPERIMENTAL::SkRecording recording(src.width(), src.height()); | 53 SkAutoTUnref<const SkPicture> picture(rerecord(src, FLAGS_skr)); |
| 54 src.draw(recording.canvas()); | |
| 55 return recording.releasePlayback(); | |
| 56 } | |
| 57 | |
| 58 static void draw(const EXPERIMENTAL::SkPlayback& skr, const SkPicture& skp, SkCa
nvas* canvas) { | |
| 59 if (FLAGS_skr) { | |
| 60 skr.draw(canvas); | |
| 61 } else { | |
| 62 skp.draw(canvas); | |
| 63 } | |
| 64 } | |
| 65 | |
| 66 static void bench(SkPMColor* scratch, SkPicture& src, const char* name) { | |
| 67 SkAutoTUnref<SkPicture> picture(rerecord_with_tilegrid(src)); | |
| 68 SkAutoTDelete<EXPERIMENTAL::SkPlayback> record(rerecord_with_skr(src)); | |
| 69 | 54 |
| 70 SkAutoTDelete<SkCanvas> canvas(SkCanvas::NewRasterDirectN32(src.width(), | 55 SkAutoTDelete<SkCanvas> canvas(SkCanvas::NewRasterDirectN32(src.width(), |
| 71 src.height(), | 56 src.height(), |
| 72 scratch, | 57 scratch, |
| 73 src.width() * si
zeof(SkPMColor))); | 58 src.width() * si
zeof(SkPMColor))); |
| 74 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile), SkIntToScalar(FLA
GS_tile))); | 59 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile), SkIntToScalar(FLA
GS_tile))); |
| 75 | 60 |
| 76 // Draw once to warm any caches. The first sample otherwise can be very noi
sy. | 61 // Draw once to warm any caches. The first sample otherwise can be very noi
sy. |
| 77 draw(*record, *picture, canvas.get()); | 62 picture->draw(canvas.get()); |
| 78 | 63 |
| 79 WallTimer timer; | 64 WallTimer timer; |
| 80 const double scale = timescale(); | 65 const double scale = timescale(); |
| 81 SkAutoTMalloc<double> samples(FLAGS_samples); | 66 SkAutoTMalloc<double> samples(FLAGS_samples); |
| 82 for (int i = 0; i < FLAGS_samples; i++) { | 67 for (int i = 0; i < FLAGS_samples; i++) { |
| 83 // We assume timer overhead (typically, ~30ns) is insignificant | 68 // We assume timer overhead (typically, ~30ns) is insignificant |
| 84 // compared to draw runtime (at least ~100us, usually several ms). | 69 // compared to draw runtime (at least ~100us, usually several ms). |
| 85 timer.start(); | 70 timer.start(); |
| 86 draw(*record, *picture, canvas.get()); | 71 picture->draw(canvas.get()); |
| 87 timer.end(); | 72 timer.end(); |
| 88 samples[i] = timer.fWall * scale; | 73 samples[i] = timer.fWall * scale; |
| 89 } | 74 } |
| 90 | 75 |
| 91 Stats stats(samples.get(), FLAGS_samples); | 76 Stats stats(samples.get(), FLAGS_samples); |
| 92 if (FLAGS_verbose == 0) { | 77 if (FLAGS_verbose == 0) { |
| 93 printf("%g\t%s\n", stats.min, name); | 78 printf("%g\t%s\n", stats.min, name); |
| 94 } else if (FLAGS_verbose == 1) { | 79 } else if (FLAGS_verbose == 1) { |
| 95 // Get a rough idea of how noisy the measurements were. | 80 // Get a rough idea of how noisy the measurements were. |
| 96 const double noisePercent = 100 * sqrt(stats.var) / stats.mean; | 81 const double noisePercent = 100 * sqrt(stats.var) / stats.mean; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 122 } | 107 } |
| 123 | 108 |
| 124 const SkString path = SkOSPath::SkPathJoin(FLAGS_skps[0], filename.c_str
()); | 109 const SkString path = SkOSPath::SkPathJoin(FLAGS_skps[0], filename.c_str
()); |
| 125 | 110 |
| 126 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path.c_str())); | 111 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path.c_str())); |
| 127 if (!stream) { | 112 if (!stream) { |
| 128 SkDebugf("Could not read %s.\n", path.c_str()); | 113 SkDebugf("Could not read %s.\n", path.c_str()); |
| 129 failed = true; | 114 failed = true; |
| 130 continue; | 115 continue; |
| 131 } | 116 } |
| 132 SkAutoTUnref<SkPicture> src(SkPicture::CreateFromStream(stream)); | 117 SkAutoTUnref<const SkPicture> src(SkPicture::CreateFromStream(stream)); |
| 133 if (!src) { | 118 if (!src) { |
| 134 SkDebugf("Could not read %s as an SkPicture.\n", path.c_str()); | 119 SkDebugf("Could not read %s as an SkPicture.\n", path.c_str()); |
| 135 failed = true; | 120 failed = true; |
| 136 continue; | 121 continue; |
| 137 } | 122 } |
| 138 | 123 |
| 139 if (src->width() * src->height() > kMaxArea) { | 124 if (src->width() * src->height() > kMaxArea) { |
| 140 SkDebugf("%s (%dx%d) is larger than hardcoded scratch bitmap (%dpx).
\n", | 125 SkDebugf("%s (%dx%d) is larger than hardcoded scratch bitmap (%dpx).
\n", |
| 141 path.c_str(), src->width(), src->height(), kMaxArea); | 126 path.c_str(), src->width(), src->height(), kMaxArea); |
| 142 failed = true; | 127 failed = true; |
| 143 continue; | 128 continue; |
| 144 } | 129 } |
| 145 | 130 |
| 146 bench(scratch.get(), *src, filename.c_str()); | 131 bench(scratch.get(), *src, filename.c_str()); |
| 147 } | 132 } |
| 148 return failed ? 1 : 0; | 133 return failed ? 1 : 0; |
| 149 } | 134 } |
| 150 | 135 |
| 151 #if !defined SK_BUILD_FOR_IOS | 136 #if !defined SK_BUILD_FOR_IOS |
| 152 int main(int argc, char * const argv[]) { | 137 int main(int argc, char * const argv[]) { |
| 153 return tool_main(argc, (char**) argv); | 138 return tool_main(argc, (char**) argv); |
| 154 } | 139 } |
| 155 #endif | 140 #endif |
| OLD | NEW |