| OLD | NEW |
| (Empty) |
| 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 "SkCanvas.h" | |
| 9 #include "SkCommandLineFlags.h" | |
| 10 #include "SkForceLinking.h" | |
| 11 #include "SkGraphics.h" | |
| 12 #include "SkOSFile.h" | |
| 13 #include "SkPicture.h" | |
| 14 #include "SkPictureRecorder.h" | |
| 15 #include "SkStream.h" | |
| 16 #include "SkString.h" | |
| 17 | |
| 18 #include "Stats.h" | |
| 19 #include "Timer.h" | |
| 20 | |
| 21 __SK_FORCE_IMAGE_DECODER_LINKING; | |
| 22 | |
| 23 DEFINE_string2(skps, r, "skps", "Directory containing SKPs to playback."); | |
| 24 DEFINE_int32(samples, 10, "Gather this many samples of each picture playback."); | |
| 25 DEFINE_bool(skr, false, "Play via SkRecord instead of SkPicture."); | |
| 26 DEFINE_int32(tile, 1000000000, "Simulated tile size."); | |
| 27 DEFINE_string(match, "", "The usual filters on file names of SKPs to bench."); | |
| 28 DEFINE_string(timescale, "ms", "Print times in ms, us, or ns"); | |
| 29 DEFINE_int32(verbose, 0, "0: print min sample; " | |
| 30 "1: print min, mean, max and noise indication " | |
| 31 "2: print all samples"); | |
| 32 | |
| 33 static double timescale() { | |
| 34 if (FLAGS_timescale.contains("us")) return 1000; | |
| 35 if (FLAGS_timescale.contains("ns")) return 1000000; | |
| 36 return 1; | |
| 37 } | |
| 38 | |
| 39 static SkPicture* rerecord(const SkPicture& src, bool skr) { | |
| 40 SkTileGridFactory::TileGridInfo info; | |
| 41 info.fTileInterval.set(FLAGS_tile, FLAGS_tile); | |
| 42 info.fMargin.setEmpty(); | |
| 43 info.fOffset.setZero(); | |
| 44 SkTileGridFactory factory(info); | |
| 45 | |
| 46 SkPictureRecorder recorder; | |
| 47 src.playback(skr ? recorder.EXPERIMENTAL_beginRecording(src.cullRect().width
(), | |
| 48 src.cullRect().heigh
t(), | |
| 49 &factory) | |
| 50 : recorder. DEPRECATED_beginRecording(src.cullRect().width
(), | |
| 51 src.cullRect().heigh
t(), | |
| 52 &factory)); | |
| 53 return recorder.endRecording(); | |
| 54 } | |
| 55 | |
| 56 static void bench(SkPMColor* scratch, const SkPicture& src, const char* name) { | |
| 57 SkAutoTUnref<const SkPicture> picture(rerecord(src, FLAGS_skr)); | |
| 58 | |
| 59 SkAutoTDelete<SkCanvas> canvas( | |
| 60 SkCanvas::NewRasterDirectN32(SkScalarCeilToInt(src.cullRect().width()), | |
| 61 SkScalarCeilToInt(src.cullRect().height()), | |
| 62 scratch, | |
| 63 SkScalarCeilToInt(src.cullRect().width()) *
sizeof(SkPMColor))); | |
| 64 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(FLAGS_tile), SkIntToScalar(FLA
GS_tile))); | |
| 65 | |
| 66 // Draw once to warm any caches. The first sample otherwise can be very noi
sy. | |
| 67 picture->playback(canvas.get()); | |
| 68 | |
| 69 WallTimer timer; | |
| 70 const double scale = timescale(); | |
| 71 SkAutoTMalloc<double> samples(FLAGS_samples); | |
| 72 for (int i = 0; i < FLAGS_samples; i++) { | |
| 73 // We assume timer overhead (typically, ~30ns) is insignificant | |
| 74 // compared to draw runtime (at least ~100us, usually several ms). | |
| 75 timer.start(); | |
| 76 picture->playback(canvas.get()); | |
| 77 timer.end(); | |
| 78 samples[i] = timer.fWall * scale; | |
| 79 } | |
| 80 | |
| 81 Stats stats(samples.get(), FLAGS_samples); | |
| 82 if (FLAGS_verbose == 0) { | |
| 83 printf("%g\t%s\n", stats.min, name); | |
| 84 } else if (FLAGS_verbose == 1) { | |
| 85 // Get a rough idea of how noisy the measurements were. | |
| 86 const double noisePercent = 100 * sqrt(stats.var) / stats.mean; | |
| 87 printf("%g\t%g\t%g\t±%.0f%%\t%s\n", stats.min, stats.mean, stats.max, no
isePercent, name); | |
| 88 } else if (FLAGS_verbose == 2) { | |
| 89 printf("%s", name); | |
| 90 for (int i = 0; i < FLAGS_samples; i++) { | |
| 91 printf("\t%g", samples[i]); | |
| 92 } | |
| 93 printf("\n"); | |
| 94 } | |
| 95 } | |
| 96 | |
| 97 int tool_main(int argc, char** argv); | |
| 98 int tool_main(int argc, char** argv) { | |
| 99 SkCommandLineFlags::Parse(argc, argv); | |
| 100 SkAutoGraphics autoGraphics; | |
| 101 | |
| 102 // We share a single scratch bitmap among benches to reduce the profile nois
e from allocation. | |
| 103 static const int kMaxArea = 209825221; // tabl_mozilla is this big. | |
| 104 SkAutoTMalloc<SkPMColor> scratch(kMaxArea); | |
| 105 | |
| 106 SkOSFile::Iter it(FLAGS_skps[0], ".skp"); | |
| 107 SkString filename; | |
| 108 bool failed = false; | |
| 109 while (it.next(&filename)) { | |
| 110 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, filename.c_str())) { | |
| 111 continue; | |
| 112 } | |
| 113 | |
| 114 const SkString path = SkOSPath::Join(FLAGS_skps[0], filename.c_str()); | |
| 115 | |
| 116 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path.c_str())); | |
| 117 if (!stream) { | |
| 118 SkDebugf("Could not read %s.\n", path.c_str()); | |
| 119 failed = true; | |
| 120 continue; | |
| 121 } | |
| 122 SkAutoTUnref<const SkPicture> src(SkPicture::CreateFromStream(stream)); | |
| 123 if (!src) { | |
| 124 SkDebugf("Could not read %s as an SkPicture.\n", path.c_str()); | |
| 125 failed = true; | |
| 126 continue; | |
| 127 } | |
| 128 | |
| 129 if (SkScalarCeilToInt(src->cullRect().width()) * | |
| 130 SkScalarCeilToInt(src->cullRect().height()) > kMaxArea) { | |
| 131 SkDebugf("%s (%f,%f,%f,%f) is larger than hardcoded scratch bitmap (
%dpx).\n", | |
| 132 path.c_str(), | |
| 133 src->cullRect().fLeft, src->cullRect().fTop, | |
| 134 src->cullRect().fRight, src->cullRect().fBottom, | |
| 135 kMaxArea); | |
| 136 failed = true; | |
| 137 continue; | |
| 138 } | |
| 139 | |
| 140 bench(scratch.get(), *src, filename.c_str()); | |
| 141 } | |
| 142 return failed ? 1 : 0; | |
| 143 } | |
| 144 | |
| 145 #if !defined SK_BUILD_FOR_IOS | |
| 146 int main(int argc, char * const argv[]) { | |
| 147 return tool_main(argc, (char**) argv); | |
| 148 } | |
| 149 #endif | |
| OLD | NEW |