OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 | 8 |
9 #include <VisualBench/VisualBenchmarkStream.h> | 9 #include <VisualBench/VisualBenchmarkStream.h> |
10 #include "CpuWrappedBenchmark.h" | 10 #include "CpuWrappedBenchmark.h" |
11 #include "GMBench.h" | 11 #include "GMBench.h" |
12 #include "SkOSFile.h" | 12 #include "SkOSFile.h" |
| 13 #include "SkPath.h" |
13 #include "SkPictureRecorder.h" | 14 #include "SkPictureRecorder.h" |
14 #include "SkStream.h" | 15 #include "SkStream.h" |
| 16 #include "sk_tool_utils.h" |
15 #include "VisualSKPBench.h" | 17 #include "VisualSKPBench.h" |
16 | 18 |
17 DEFINE_bool(cpu, false, "Run in CPU mode?"); | 19 DEFINE_bool(cpu, false, "Run in CPU mode?"); |
18 DEFINE_string2(match, m, nullptr, | 20 DEFINE_string2(match, m, nullptr, |
19 "[~][^]substring[$] [...] of bench name to run.\n" | 21 "[~][^]substring[$] [...] of bench name to run.\n" |
20 "Multiple matches may be separated by spaces.\n" | 22 "Multiple matches may be separated by spaces.\n" |
21 "~ causes a matching bench to always be skipped\n" | 23 "~ causes a matching bench to always be skipped\n" |
22 "^ requires the start of the bench to match\n" | 24 "^ requires the start of the bench to match\n" |
23 "$ requires the end of the bench to match\n" | 25 "$ requires the end of the bench to match\n" |
24 "^ and $ requires an exact match\n" | 26 "^ and $ requires an exact match\n" |
25 "If a bench does not match any list entry,\n" | 27 "If a bench does not match any list entry,\n" |
26 "it is skipped unless some list entry starts with ~"); | 28 "it is skipped unless some list entry starts with ~"); |
27 DEFINE_string(skps, "skps", "Directory to read skps from."); | 29 DEFINE_string(skps, "skps", "Directory to read skps from."); |
28 | 30 |
| 31 // We draw a big nonAA path to warmup the gpu / cpu |
| 32 #include "SkPerlinNoiseShader.h" |
| 33 class WarmupBench : public Benchmark { |
| 34 public: |
| 35 WarmupBench() { |
| 36 sk_tool_utils::make_big_path(fPath); |
| 37 } |
| 38 private: |
| 39 const char* onGetName() override { return "warmupbench"; } |
| 40 void onDraw(int loops, SkCanvas* canvas) override { |
| 41 // We draw a big path to warm up the cpu, and then use perlin noise shad
er to warm up the |
| 42 // gpu |
| 43 SkPaint paint; |
| 44 paint.setStyle(SkPaint::kStroke_Style); |
| 45 paint.setStrokeWidth(2); |
| 46 |
| 47 SkPaint perlinPaint; |
| 48 perlinPaint.setShader(SkPerlinNoiseShader::CreateTurbulence(0.1f, 0.1f,
1, 0, |
| 49 nullptr))->u
nref(); |
| 50 SkRect rect = SkRect::MakeLTRB(0., 0., 400., 400.); |
| 51 for (int i = 0; i < loops; i++) { |
| 52 canvas->drawPath(fPath, paint); |
| 53 canvas->drawRect(rect, perlinPaint); |
| 54 } |
| 55 } |
| 56 SkPath fPath; |
| 57 }; |
| 58 |
29 VisualBenchmarkStream::VisualBenchmarkStream() | 59 VisualBenchmarkStream::VisualBenchmarkStream() |
30 : fBenches(BenchRegistry::Head()) | 60 : fBenches(BenchRegistry::Head()) |
31 , fGMs(skiagm::GMRegistry::Head()) | 61 , fGMs(skiagm::GMRegistry::Head()) |
32 , fSourceType(nullptr) | 62 , fSourceType(nullptr) |
33 , fBenchType(nullptr) | 63 , fBenchType(nullptr) |
34 , fCurrentSKP(0) { | 64 , fCurrentSKP(0) |
| 65 , fIsWarmedUp(false) { |
35 for (int i = 0; i < FLAGS_skps.count(); i++) { | 66 for (int i = 0; i < FLAGS_skps.count(); i++) { |
36 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { | 67 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { |
37 fSKPs.push_back() = FLAGS_skps[i]; | 68 fSKPs.push_back() = FLAGS_skps[i]; |
38 } else { | 69 } else { |
39 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); | 70 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); |
40 SkString path; | 71 SkString path; |
41 while (it.next(&path)) { | 72 while (it.next(&path)) { |
42 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str()); | 73 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str()); |
43 } | 74 } |
44 } | 75 } |
(...skipping 15 matching lines...) Expand all Loading... |
60 | 91 |
61 pic->reset(SkPicture::CreateFromStream(stream.get())); | 92 pic->reset(SkPicture::CreateFromStream(stream.get())); |
62 if (pic->get() == nullptr) { | 93 if (pic->get() == nullptr) { |
63 SkDebugf("Could not read %s as an SkPicture.\n", path); | 94 SkDebugf("Could not read %s as an SkPicture.\n", path); |
64 return false; | 95 return false; |
65 } | 96 } |
66 return true; | 97 return true; |
67 } | 98 } |
68 | 99 |
69 Benchmark* VisualBenchmarkStream::next() { | 100 Benchmark* VisualBenchmarkStream::next() { |
| 101 if (!fIsWarmedUp) { |
| 102 fIsWarmedUp = true; |
| 103 return new WarmupBench; |
| 104 } |
| 105 |
70 Benchmark* bench; | 106 Benchmark* bench; |
| 107 |
71 // skips non matching benches | 108 // skips non matching benches |
72 while ((bench = this->innerNext()) && | 109 while ((bench = this->innerNext()) && |
73 (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())
|| | 110 (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())
|| |
74 !bench->isSuitableFor(Benchmark::kGPU_Backend))) { | 111 !bench->isSuitableFor(Benchmark::kGPU_Backend))) { |
75 bench->unref(); | 112 bench->unref(); |
76 } | 113 } |
77 if (FLAGS_cpu) { | 114 if (FLAGS_cpu) { |
78 return new CpuWrappedBenchmark(bench); | 115 return new CpuWrappedBenchmark(bench); |
79 } | 116 } |
80 return bench; | 117 return bench; |
(...skipping 30 matching lines...) Expand all Loading... |
111 } | 148 } |
112 | 149 |
113 SkString name = SkOSPath::Basename(path.c_str()); | 150 SkString name = SkOSPath::Basename(path.c_str()); |
114 fSourceType = "skp"; | 151 fSourceType = "skp"; |
115 fBenchType = "playback"; | 152 fBenchType = "playback"; |
116 return new VisualSKPBench(name.c_str(), pic.get()); | 153 return new VisualSKPBench(name.c_str(), pic.get()); |
117 } | 154 } |
118 | 155 |
119 return nullptr; | 156 return nullptr; |
120 } | 157 } |
OLD | NEW |