Chromium Code Reviews| 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 "SkCommandLineFlags.h" | |
| 9 #include "SkForceLinking.h" | |
| 10 #include "SkGraphics.h" | |
| 11 #include "SkOSFile.h" | |
| 12 #include "SkPicture.h" | |
| 13 #include "SkRecordDraw.h" | |
| 14 #include "SkRecorder.h" | |
| 15 #include "SkStream.h" | |
| 16 #include "SkString.h" | |
| 17 #include "SkTime.h" | |
| 18 | |
| 19 __SK_FORCE_IMAGE_DECODER_LINKING; | |
| 20 | |
| 21 DEFINE_string2(skps, r, "skps", "Directory containing SKPs to read and re-record ."); | |
| 22 DEFINE_int32(loops, 10, "Number of times to play back each SKP."); | |
| 23 DEFINE_bool(skr, false, "Play via SkRecord instead of SkPicture."); | |
| 24 DEFINE_int32(tile, 1000000000, "Simulated tile size."); | |
| 25 | |
| 26 static void bench(SkPMColor* scratch, SkPicture& src, const char* name) { | |
| 27 SkRecord record; | |
| 28 SkRecorder recorder(SkRecorder::kWriteOnly_Mode, &record, src.width(), src.h eight()); | |
| 29 src.draw(&recorder); | |
| 30 | |
| 31 SkAutoTDelete<SkCanvas> canvas( | |
| 32 SkCanvas::NewRasterDirectN32(src.width(), src.height(), scratch, 0)); | |
| 33 canvas->clipRect(SkRect::MakeWH(FLAGS_tile, FLAGS_tile)); | |
| 34 | |
| 35 const SkMSec start = SkTime::GetMSecs(); | |
| 36 for (int i = 0; i < FLAGS_loops; i++) { | |
| 37 if (FLAGS_skr) { | |
| 38 SkRecordDraw(record, canvas.get()); | |
| 39 } else { | |
| 40 src.draw(canvas.get()); | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 const SkMSec elapsed = SkTime::GetMSecs() - start; | |
| 45 const double msPerLoop = elapsed / (double)FLAGS_loops; | |
| 46 printf("%5.1f\t%s\n", msPerLoop, name); | |
| 47 } | |
| 48 | |
| 49 int tool_main(int argc, char** argv); | |
|
f(malita)
2014/04/10 23:27:37
Is this needed?
mtklein
2014/04/11 01:22:35
Oh, I just realized you might have just meant, is
| |
| 50 int tool_main(int argc, char** argv) { | |
| 51 SkCommandLineFlags::Parse(argc, argv); | |
| 52 SkAutoGraphics autoGraphics; | |
| 53 | |
| 54 // We share a single scratch bitmap among benches to reduce the profile nois e from allocation. | |
| 55 static const int kMaxArea = 209825221; // tabl_mozilla is this big. | |
| 56 SkAutoTMalloc<SkPMColor> scratch(kMaxArea); | |
| 57 | |
| 58 SkOSFile::Iter it(FLAGS_skps[0], ".skp"); | |
| 59 SkString filename; | |
| 60 bool failed = false; | |
| 61 while (it.next(&filename)) { | |
| 62 const SkString path = SkOSPath::SkPathJoin(FLAGS_skps[0], filename.c_str ()); | |
| 63 | |
| 64 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path.c_str())); | |
| 65 if (!stream) { | |
| 66 SkDebugf("Could not read %s.\n", path.c_str()); | |
| 67 failed = true; | |
| 68 continue; | |
| 69 } | |
| 70 SkAutoTUnref<SkPicture> src(SkPicture::CreateFromStream(stream)); | |
| 71 if (!src) { | |
| 72 SkDebugf("Could not read %s as an SkPicture.\n", path.c_str()); | |
| 73 failed = true; | |
| 74 continue; | |
| 75 } | |
| 76 | |
| 77 if (src->width() * src->height() > kMaxArea) { | |
| 78 SkDebugf("%s (%dx%d) is larger than hardcoded scratch bitmap (%dpx). \n", | |
| 79 path.c_str(), src->width(), src->height(), kMaxArea); | |
| 80 failed = true; | |
| 81 continue; | |
| 82 } | |
| 83 | |
| 84 bench(scratch.get(), *src, filename.c_str()); | |
| 85 } | |
| 86 return failed ? 1 : 0; | |
| 87 } | |
| 88 | |
| 89 #if !defined SK_BUILD_FOR_IOS | |
| 90 int main(int argc, char * const argv[]) { | |
| 91 return tool_main(argc, (char**) argv); | |
| 92 } | |
| 93 #endif | |
| OLD | NEW |