OLD | NEW |
1 // Main binary for DM. | 1 // Main binary for DM. |
2 // For a high-level overview, please see dm/README. | 2 // For a high-level overview, please see dm/README. |
3 | 3 |
4 #include "GrContext.h" | 4 #include "GrContext.h" |
5 #include "GrContextFactory.h" | 5 #include "GrContextFactory.h" |
| 6 #include "SkBenchmark.h" |
6 #include "SkCommandLineFlags.h" | 7 #include "SkCommandLineFlags.h" |
7 #include "SkForceLinking.h" | 8 #include "SkForceLinking.h" |
8 #include "SkGraphics.h" | 9 #include "SkGraphics.h" |
9 #include "SkString.h" | 10 #include "SkString.h" |
10 #include "Test.h" | 11 #include "Test.h" |
11 #include "gm.h" | 12 #include "gm.h" |
12 | 13 |
| 14 #include "DMBenchTask.h" |
13 #include "DMCpuTask.h" | 15 #include "DMCpuTask.h" |
14 #include "DMGpuTask.h" | 16 #include "DMGpuTask.h" |
15 #include "DMReporter.h" | 17 #include "DMReporter.h" |
16 #include "DMTask.h" | 18 #include "DMTask.h" |
17 #include "DMTaskRunner.h" | 19 #include "DMTaskRunner.h" |
18 #include "DMTestTask.h" | 20 #include "DMTestTask.h" |
19 #include "DMWriteTask.h" | 21 #include "DMWriteTask.h" |
20 | 22 |
21 #include <string.h> | 23 #include <string.h> |
22 | 24 |
23 using skiagm::GM; | 25 using skiagm::GM; |
24 using skiagm::GMRegistry; | 26 using skiagm::GMRegistry; |
25 using skiatest::Test; | 27 using skiatest::Test; |
26 using skiatest::TestRegistry; | 28 using skiatest::TestRegistry; |
27 | 29 |
28 DEFINE_int32(threads, -1, "Threads for CPU work. Default NUM_CPUS."); | 30 DEFINE_int32(threads, -1, "Threads for CPU work. Default NUM_CPUS."); |
29 DEFINE_string2(expectations, r, "", | 31 DEFINE_string2(expectations, r, "", |
30 "If a directory, compare generated images against images under th
is path. " | 32 "If a directory, compare generated images against images under th
is path. " |
31 "If a file, compare generated images against JSON expectations at
this path."); | 33 "If a file, compare generated images against JSON expectations at
this path."); |
32 DEFINE_string2(resources, i, "resources", "Path to resources directory."); | 34 DEFINE_string2(resources, i, "resources", "Path to resources directory."); |
33 DEFINE_string(match, "", "[~][^]substring[$] [...] of GM name to run.\n" | 35 DEFINE_string(match, "", "[~][^]substring[$] [...] of GM name to run.\n" |
34 "Multiple matches may be separated by spaces.\n" | 36 "Multiple matches may be separated by spaces.\n" |
35 "~ causes a matching GM to always be skipped\n" | 37 "~ causes a matching GM to always be skipped\n" |
36 "^ requires the start of the GM to match\n" | 38 "^ requires the start of the GM to match\n" |
37 "$ requires the end of the GM to match\n" | 39 "$ requires the end of the GM to match\n" |
38 "^ and $ requires an exact match\n" | 40 "^ and $ requires an exact match\n" |
39 "If a GM does not match any list entry,\n" | 41 "If a GM does not match any list entry,\n" |
40 "it is skipped unless some list entry starts with ~"); | 42 "it is skipped unless some list entry starts with ~"); |
41 DEFINE_string(config, "565 8888 gpu", | 43 DEFINE_string(config, "565 8888 gpu nonrendering", |
42 "Options: 565 8888 gpu msaa4 msaa16 gpunull gpudebug angle mesa"); // TO
DO(mtklein): pdf | 44 "Options: 565 8888 gpu nonrendering msaa4 msaa16 gpunull gpudebug
angle mesa"); |
43 DEFINE_bool(leaks, false, "Print leaked instance-counted objects at exit?"); | 45 DEFINE_bool(leaks, false, "Print leaked instance-counted objects at exit?"); |
44 | 46 |
45 DEFINE_bool(gms, true, "Run GMs?"); | 47 DEFINE_bool(gms, true, "Run GMs?"); |
| 48 DEFINE_bool(benches, true, "Run benches? Does not run GMs-as-benches."); |
46 DEFINE_bool(tests, true, "Run tests?"); | 49 DEFINE_bool(tests, true, "Run tests?"); |
47 | 50 |
48 __SK_FORCE_IMAGE_DECODER_LINKING; | 51 __SK_FORCE_IMAGE_DECODER_LINKING; |
49 | 52 |
50 // "FooBar" -> "foobar". Obviously, ASCII only. | 53 // "FooBar" -> "foobar". Obviously, ASCII only. |
51 static SkString lowercase(SkString s) { | 54 static SkString lowercase(SkString s) { |
52 for (size_t i = 0; i < s.size(); i++) { | 55 for (size_t i = 0; i < s.size(); i++) { |
53 s[i] = tolower(s[i]); | 56 s[i] = tolower(s[i]); |
54 } | 57 } |
55 return s; | 58 return s; |
56 } | 59 } |
57 | 60 |
| 61 static const GrContextFactory::GLContextType native = GrContextFactory::kNative_
GLContextType; |
| 62 static const GrContextFactory::GLContextType null = GrContextFactory::kNull_GL
ContextType; |
| 63 static const GrContextFactory::GLContextType debug = GrContextFactory::kDebug_G
LContextType; |
| 64 static const GrContextFactory::GLContextType angle = |
| 65 #if SK_ANGLE |
| 66 GrContextFactory::kANGLE_GLContextType; |
| 67 #else |
| 68 native; |
| 69 #endif |
| 70 static const GrContextFactory::GLContextType mesa = |
| 71 #if SK_MESA |
| 72 GLContextFactory::kMESA_GLContextType; |
| 73 #else |
| 74 native; |
| 75 #endif |
| 76 |
58 static void kick_off_gms(const SkTDArray<GMRegistry::Factory>& gms, | 77 static void kick_off_gms(const SkTDArray<GMRegistry::Factory>& gms, |
59 const SkTArray<SkString>& configs, | 78 const SkTArray<SkString>& configs, |
60 const DM::Expectations& expectations, | 79 const DM::Expectations& expectations, |
61 DM::Reporter* reporter, | 80 DM::Reporter* reporter, |
62 DM::TaskRunner* tasks) { | 81 DM::TaskRunner* tasks) { |
63 const SkColorType _565 = kRGB_565_SkColorType; | 82 #define START(name, type, ...)
\ |
64 const SkColorType _8888 = kPMColor_SkColorType; | 83 if (lowercase(configs[j]).equals(name)) {
\ |
65 const GrContextFactory::GLContextType native = GrContextFactory::kNative_GLC
ontextType; | 84 tasks->add(SkNEW_ARGS(DM::type,
\ |
66 const GrContextFactory::GLContextType null = GrContextFactory::kNull_GLCon
textType; | 85 (name, reporter, tasks, expectations, gms[i], ## __VA_ARGS__
))); \ |
67 const GrContextFactory::GLContextType debug = GrContextFactory::kDebug_GLCo
ntextType; | 86 } |
68 const GrContextFactory::GLContextType angle = | |
69 #if SK_ANGLE | |
70 GrContextFactory::kANGLE_GLContextType; | |
71 #else | |
72 native; | |
73 #endif | |
74 const GrContextFactory::GLContextType mesa = | |
75 #if SK_MESA | |
76 GLContextFactory::kMESA_GLContextType; | |
77 #else | |
78 native; | |
79 #endif | |
80 | |
81 for (int i = 0; i < gms.count(); i++) { | 87 for (int i = 0; i < gms.count(); i++) { |
82 #define START(name, type, ...)
\ | |
83 if (lowercase(configs[j]).equals(name)) {
\ | |
84 tasks->add(SkNEW_ARGS(DM::type,
\ | |
85 (name, reporter, tasks, expectations, gms[i], __VA_ARGS__)))
; \ | |
86 } | |
87 for (int j = 0; j < configs.count(); j++) { | 88 for (int j = 0; j < configs.count(); j++) { |
88 START("565", CpuTask, _565); | 89 START("565", CpuTask, kRGB_565_SkColorType); |
89 START("8888", CpuTask, _8888); | 90 START("8888", CpuTask, kPMColor_SkColorType); |
90 START("gpu", GpuTask, _8888, native, 0); | 91 START("gpu", GpuTask, native, 0); |
91 START("msaa4", GpuTask, _8888, native, 4); | 92 START("msaa4", GpuTask, native, 4); |
92 START("msaa16", GpuTask, _8888, native, 16); | 93 START("msaa16", GpuTask, native, 16); |
93 START("gpunull", GpuTask, _8888, null, 0); | 94 START("gpunull", GpuTask, null, 0); |
94 START("gpudebug", GpuTask, _8888, debug, 0); | 95 START("gpudebug", GpuTask, debug, 0); |
95 START("angle", GpuTask, _8888, angle, 0); | 96 START("angle", GpuTask, angle, 0); |
96 START("mesa", GpuTask, _8888, mesa, 0); | 97 START("mesa", GpuTask, mesa, 0); |
97 //START("pdf", PdfTask, _8888); | |
98 } | 98 } |
99 } | 99 } |
100 #undef START | 100 #undef START |
| 101 } |
| 102 |
| 103 static void kick_off_benches(const SkTDArray<BenchRegistry::Factory>& benches, |
| 104 const SkTArray<SkString>& configs, |
| 105 DM::Reporter* reporter, |
| 106 DM::TaskRunner* tasks) { |
| 107 #define START(name, type, ...)
\ |
| 108 if (lowercase(configs[j]).equals(name)) {
\ |
| 109 tasks->add(SkNEW_ARGS(DM::type, (name, reporter, tasks, benches[i], ## _
_VA_ARGS__))); \ |
| 110 } |
| 111 for (int i = 0; i < benches.count(); i++) { |
| 112 for (int j = 0; j < configs.count(); j++) { |
| 113 START("nonrendering", NonRenderingBenchTask); |
| 114 START("565", CpuBenchTask, kRGB_565_SkColorType); |
| 115 START("8888", CpuBenchTask, kPMColor_SkColorType); |
| 116 START("gpu", GpuBenchTask, native, 0); |
| 117 START("msaa4", GpuBenchTask, native, 4); |
| 118 START("msaa16", GpuBenchTask, native, 16); |
| 119 START("gpunull", GpuBenchTask, null, 0); |
| 120 START("gpudebug", GpuBenchTask, debug, 0); |
| 121 START("angle", GpuBenchTask, angle, 0); |
| 122 START("mesa", GpuBenchTask, mesa, 0); |
| 123 } |
| 124 } |
| 125 #undef START |
101 } | 126 } |
102 | 127 |
103 static void kick_off_tests(const SkTDArray<TestRegistry::Factory>& tests, | 128 static void kick_off_tests(const SkTDArray<TestRegistry::Factory>& tests, |
104 DM::Reporter* reporter, | 129 DM::Reporter* reporter, |
105 DM::TaskRunner* tasks) { | 130 DM::TaskRunner* tasks) { |
106 for (int i = 0; i < tests.count(); i++) { | 131 for (int i = 0; i < tests.count(); i++) { |
107 tasks->add(SkNEW_ARGS(DM::TestTask, (reporter, tasks, tests[i]))); | 132 tasks->add(SkNEW_ARGS(DM::TestTask, (reporter, tasks, tests[i]))); |
108 } | 133 } |
109 } | 134 } |
110 | 135 |
111 static void report_failures(const DM::Reporter& reporter) { | 136 static void report_failures(const DM::Reporter& reporter) { |
112 SkTArray<SkString> failures; | 137 SkTArray<SkString> failures; |
113 reporter.getFailures(&failures); | 138 reporter.getFailures(&failures); |
114 | 139 |
115 if (failures.count() == 0) { | 140 if (failures.count() == 0) { |
116 return; | 141 return; |
117 } | 142 } |
118 | 143 |
119 SkDebugf("Failures:\n"); | 144 SkDebugf("Failures:\n"); |
120 for (int i = 0; i < failures.count(); i++) { | 145 for (int i = 0; i < failures.count(); i++) { |
121 SkDebugf(" %s\n", failures[i].c_str()); | 146 SkDebugf(" %s\n", failures[i].c_str()); |
122 } | 147 } |
123 } | 148 } |
124 | 149 |
| 150 template <typename T, typename Registry> |
| 151 static void append_matching_factories(Registry* head, SkTDArray<typename Registr
y::Factory>* out) { |
| 152 for (const Registry* reg = head; reg != NULL; reg = reg->next()) { |
| 153 SkAutoTDelete<T> forName(reg->factory()(NULL)); |
| 154 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, forName->getName())) { |
| 155 *out->append() = reg->factory(); |
| 156 } |
| 157 } |
| 158 } |
| 159 |
125 int tool_main(int argc, char** argv); | 160 int tool_main(int argc, char** argv); |
126 int tool_main(int argc, char** argv) { | 161 int tool_main(int argc, char** argv) { |
| 162 SkGraphics::Init(); |
| 163 SkCommandLineFlags::Parse(argc, argv); |
127 #if SK_ENABLE_INST_COUNT | 164 #if SK_ENABLE_INST_COUNT |
128 gPrintInstCount = FLAGS_leaks; | 165 gPrintInstCount = FLAGS_leaks; |
129 #endif | 166 #endif |
130 SkGraphics::Init(); | |
131 SkCommandLineFlags::Parse(argc, argv); | |
132 GM::SetResourcePath(FLAGS_resources[0]); | 167 GM::SetResourcePath(FLAGS_resources[0]); |
| 168 SkBenchmark::SetResourcePath(FLAGS_resources[0]); |
133 Test::SetResourcePath(FLAGS_resources[0]); | 169 Test::SetResourcePath(FLAGS_resources[0]); |
134 | 170 |
135 SkTArray<SkString> configs; | 171 SkTArray<SkString> configs; |
| 172 for (int i = 0; i < FLAGS_config.count(); i++) { |
| 173 SkStrSplit(FLAGS_config[i], ", ", &configs); |
| 174 } |
| 175 |
136 SkTDArray<GMRegistry::Factory> gms; | 176 SkTDArray<GMRegistry::Factory> gms; |
137 SkAutoTDelete<DM::Expectations> expectations(SkNEW(DM::NoExpectations)); | 177 SkAutoTDelete<DM::Expectations> expectations(SkNEW(DM::NoExpectations)); |
138 | |
139 if (FLAGS_gms) { | 178 if (FLAGS_gms) { |
140 for (int i = 0; i < FLAGS_config.count(); i++) { | 179 append_matching_factories<GM>(GMRegistry::Head(), &gms); |
141 SkStrSplit(FLAGS_config[i], ", ", &configs); | |
142 } | |
143 | |
144 for (const GMRegistry* reg = GMRegistry::Head(); reg != NULL; reg = reg-
>next()) { | |
145 SkAutoTDelete<GM> gmForName(reg->factory()(NULL)); | |
146 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, gmForName->shortNam
e())) { | |
147 *gms.append() = reg->factory(); | |
148 } | |
149 } | |
150 | 180 |
151 if (FLAGS_expectations.count() > 0) { | 181 if (FLAGS_expectations.count() > 0) { |
152 const char* path = FLAGS_expectations[0]; | 182 const char* path = FLAGS_expectations[0]; |
153 if (sk_isdir(path)) { | 183 if (sk_isdir(path)) { |
154 expectations.reset(SkNEW_ARGS(DM::WriteTask::Expectations, (path
))); | 184 expectations.reset(SkNEW_ARGS(DM::WriteTask::Expectations, (path
))); |
155 } else { | 185 } else { |
156 expectations.reset(SkNEW_ARGS(DM::JsonExpectations, (path))); | 186 expectations.reset(SkNEW_ARGS(DM::JsonExpectations, (path))); |
157 } | 187 } |
158 } | 188 } |
159 } | 189 } |
160 | 190 |
| 191 SkTDArray<BenchRegistry::Factory> benches; |
| 192 if (FLAGS_benches) { |
| 193 append_matching_factories<SkBenchmark>(BenchRegistry::Head(), &benches); |
| 194 } |
| 195 |
161 SkTDArray<TestRegistry::Factory> tests; | 196 SkTDArray<TestRegistry::Factory> tests; |
162 if (FLAGS_tests) { | 197 if (FLAGS_tests) { |
163 for (const TestRegistry* reg = TestRegistry::Head(); reg != NULL; reg =
reg->next()) { | 198 append_matching_factories<Test>(TestRegistry::Head(), &tests); |
164 SkAutoTDelete<Test> testForName(reg->factory()(NULL)); | |
165 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, testForName->getNam
e())) { | |
166 *tests.append() = reg->factory(); | |
167 } | |
168 } | |
169 } | 199 } |
170 | 200 |
171 SkDebugf("%d GMs x %d configs, %d tests\n", gms.count(), configs.count(), te
sts.count()); | 201 SkDebugf("(%d GMs, %d benches) x %d configs, %d tests\n", |
| 202 gms.count(), benches.count(), configs.count(), tests.count()); |
172 DM::Reporter reporter; | 203 DM::Reporter reporter; |
173 DM::TaskRunner tasks(FLAGS_threads); | 204 DM::TaskRunner tasks(FLAGS_threads); |
174 kick_off_gms(gms, configs, *expectations, &reporter, &tasks); | 205 kick_off_gms(gms, configs, *expectations, &reporter, &tasks); |
| 206 kick_off_benches(benches, configs, &reporter, &tasks); |
175 kick_off_tests(tests, &reporter, &tasks); | 207 kick_off_tests(tests, &reporter, &tasks); |
176 tasks.wait(); | 208 tasks.wait(); |
177 | 209 |
178 SkDebugf("\n"); | 210 SkDebugf("\n"); |
179 report_failures(reporter); | 211 report_failures(reporter); |
180 | 212 |
181 SkGraphics::Term(); | 213 SkGraphics::Term(); |
182 | 214 |
183 return reporter.failed() > 0; | 215 return reporter.failed() > 0; |
184 } | 216 } |
185 | 217 |
186 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) | 218 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
187 int main(int argc, char** argv) { | 219 int main(int argc, char** argv) { |
188 return tool_main(argc, argv); | 220 return tool_main(argc, argv); |
189 } | 221 } |
190 #endif | 222 #endif |
OLD | NEW |