blob: f71a614ad780ad5051439cb0608804ecf6586009 [file] [log] [blame]
mtklein@google.comd36522d2013-10-16 13:02:15 +00001// Main binary for DM.
2// For a high-level overview, please see dm/README.
3
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00004#include "SkBenchmark.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +00005#include "SkCommandLineFlags.h"
6#include "SkForceLinking.h"
7#include "SkGraphics.h"
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +00008#include "SkPicture.h"
rmistry@google.comd6bab022013-12-02 13:50:38 +00009#include "SkString.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000010#include "Test.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000011#include "gm.h"
12
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000013#include "DMBenchTask.h"
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000014#include "DMCpuGMTask.h"
15#include "DMGpuGMTask.h"
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000016#include "DMGpuSupport.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000017#include "DMReporter.h"
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +000018#include "DMSKPTask.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000019#include "DMTask.h"
20#include "DMTaskRunner.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000021#include "DMTestTask.h"
commit-bot@chromium.org99589af2013-12-10 14:53:16 +000022#include "DMWriteTask.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000023
commit-bot@chromium.org120c9992014-05-16 18:11:51 +000024#include <ctype.h>
mtklein@google.comd36522d2013-10-16 13:02:15 +000025
26using skiagm::GM;
27using skiagm::GMRegistry;
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000028using skiatest::Test;
29using skiatest::TestRegistry;
mtklein@google.comd36522d2013-10-16 13:02:15 +000030
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000031DEFINE_int32(threads, -1, "Threads for CPU work. Default NUM_CPUS.");
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000032DEFINE_int32(gpuThreads, 1, "Threads for GPU work.");
commit-bot@chromium.orga267d412014-05-16 18:27:11 +000033#ifdef SK_BUILD_JSON_WRITER
commit-bot@chromium.org99589af2013-12-10 14:53:16 +000034DEFINE_string2(expectations, r, "",
35 "If a directory, compare generated images against images under this path. "
commit-bot@chromium.org120c9992014-05-16 18:11:51 +000036 "If a file, compare generated images against JSON expectations at this path."
commit-bot@chromium.org120c9992014-05-16 18:11:51 +000037);
commit-bot@chromium.orga267d412014-05-16 18:27:11 +000038#else
39DEFINE_string2(expectations, r, "",
40 "If a directory, compare generated images against images under this path. "
41);
42#endif
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000043DEFINE_string2(resources, i, "resources", "Path to resources directory.");
mtklein@google.comd36522d2013-10-16 13:02:15 +000044DEFINE_string(match, "", "[~][^]substring[$] [...] of GM name to run.\n"
45 "Multiple matches may be separated by spaces.\n"
46 "~ causes a matching GM to always be skipped\n"
47 "^ requires the start of the GM to match\n"
48 "$ requires the end of the GM to match\n"
49 "^ and $ requires an exact match\n"
50 "If a GM does not match any list entry,\n"
51 "it is skipped unless some list entry starts with ~");
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000052DEFINE_string(config, "565 8888 gpu nonrendering",
commit-bot@chromium.orgb6401862014-03-12 14:46:31 +000053 "Options: 565 8888 gpu nonrendering msaa4 msaa16 nvprmsaa4 nvprmsaa16 gpunull gpudebug angle mesa");
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000054DEFINE_bool(leaks, false, "Print leaked instance-counted objects at exit?");
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +000055DEFINE_string(skps, "", "Directory to read skps from.");
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000056
57DEFINE_bool(gms, true, "Run GMs?");
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000058DEFINE_bool(benches, true, "Run benches? Does not run GMs-as-benches.");
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000059DEFINE_bool(tests, true, "Run tests?");
mtklein@google.comd36522d2013-10-16 13:02:15 +000060
61__SK_FORCE_IMAGE_DECODER_LINKING;
62
mtklein@google.comd36522d2013-10-16 13:02:15 +000063// "FooBar" -> "foobar". Obviously, ASCII only.
64static SkString lowercase(SkString s) {
65 for (size_t i = 0; i < s.size(); i++) {
66 s[i] = tolower(s[i]);
67 }
68 return s;
69}
70
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000071static const GrContextFactory::GLContextType native = GrContextFactory::kNative_GLContextType;
commit-bot@chromium.orgb6401862014-03-12 14:46:31 +000072static const GrContextFactory::GLContextType nvpr = GrContextFactory::kNVPR_GLContextType;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000073static const GrContextFactory::GLContextType null = GrContextFactory::kNull_GLContextType;
74static const GrContextFactory::GLContextType debug = GrContextFactory::kDebug_GLContextType;
75static const GrContextFactory::GLContextType angle =
76#if SK_ANGLE
77GrContextFactory::kANGLE_GLContextType;
78#else
79native;
80#endif
81static const GrContextFactory::GLContextType mesa =
82#if SK_MESA
bsalomon@google.com9dccafa2014-05-02 14:43:12 +000083GrContextFactory::kMESA_GLContextType;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000084#else
85native;
86#endif
87
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000088static void kick_off_gms(const SkTDArray<GMRegistry::Factory>& gms,
89 const SkTArray<SkString>& configs,
90 const DM::Expectations& expectations,
91 DM::Reporter* reporter,
92 DM::TaskRunner* tasks) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000093#define START(name, type, ...) \
94 if (lowercase(configs[j]).equals(name)) { \
95 tasks->add(SkNEW_ARGS(DM::type, \
96 (name, reporter, tasks, expectations, gms[i], ## __VA_ARGS__))); \
mtklein@google.comd36522d2013-10-16 13:02:15 +000097 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000098 for (int i = 0; i < gms.count(); i++) {
mtklein@google.comd36522d2013-10-16 13:02:15 +000099 for (int j = 0; j < configs.count(); j++) {
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +0000100 START("565", CpuGMTask, kRGB_565_SkColorType);
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +0000101 START("8888", CpuGMTask, kN32_SkColorType);
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +0000102 START("gpu", GpuGMTask, native, 0);
103 START("msaa4", GpuGMTask, native, 4);
104 START("msaa16", GpuGMTask, native, 16);
commit-bot@chromium.orgb6401862014-03-12 14:46:31 +0000105 START("nvprmsaa4", GpuGMTask, nvpr, 4);
106 START("nvprmsaa16", GpuGMTask, nvpr, 16);
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +0000107 START("gpunull", GpuGMTask, null, 0);
108 START("gpudebug", GpuGMTask, debug, 0);
109 START("angle", GpuGMTask, angle, 0);
110 START("mesa", GpuGMTask, mesa, 0);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000111 }
112 }
113#undef START
114}
115
116static void kick_off_benches(const SkTDArray<BenchRegistry::Factory>& benches,
117 const SkTArray<SkString>& configs,
118 DM::Reporter* reporter,
119 DM::TaskRunner* tasks) {
120#define START(name, type, ...) \
121 if (lowercase(configs[j]).equals(name)) { \
122 tasks->add(SkNEW_ARGS(DM::type, (name, reporter, tasks, benches[i], ## __VA_ARGS__))); \
123 }
124 for (int i = 0; i < benches.count(); i++) {
125 for (int j = 0; j < configs.count(); j++) {
126 START("nonrendering", NonRenderingBenchTask);
127 START("565", CpuBenchTask, kRGB_565_SkColorType);
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +0000128 START("8888", CpuBenchTask, kN32_SkColorType);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000129 START("gpu", GpuBenchTask, native, 0);
130 START("msaa4", GpuBenchTask, native, 4);
131 START("msaa16", GpuBenchTask, native, 16);
commit-bot@chromium.orgb6401862014-03-12 14:46:31 +0000132 START("nvprmsaa4", GpuBenchTask, nvpr, 4);
133 START("nvprmsaa16", GpuBenchTask, nvpr, 16);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000134 START("gpunull", GpuBenchTask, null, 0);
135 START("gpudebug", GpuBenchTask, debug, 0);
136 START("angle", GpuBenchTask, angle, 0);
137 START("mesa", GpuBenchTask, mesa, 0);
mtklein@google.comd36522d2013-10-16 13:02:15 +0000138 }
139 }
140#undef START
141}
142
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000143static void kick_off_tests(const SkTDArray<TestRegistry::Factory>& tests,
144 DM::Reporter* reporter,
145 DM::TaskRunner* tasks) {
146 for (int i = 0; i < tests.count(); i++) {
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +0000147 SkAutoTDelete<Test> test(tests[i](NULL));
148 if (test->isGPUTest()) {
149 tasks->add(SkNEW_ARGS(DM::GpuTestTask, (reporter, tasks, tests[i])));
150 } else {
151 tasks->add(SkNEW_ARGS(DM::CpuTestTask, (reporter, tasks, tests[i])));
152 }
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000153 }
154}
155
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000156static void kick_off_skps(DM::Reporter* reporter, DM::TaskRunner* tasks) {
157 if (FLAGS_skps.isEmpty()) {
158 return;
159 }
160
161 SkOSFile::Iter it(FLAGS_skps[0], ".skp");
162 SkString filename;
163 while (it.next(&filename)) {
164 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, filename.c_str())) {
165 continue;
166 }
167
168 const SkString path = SkOSPath::SkPathJoin(FLAGS_skps[0], filename.c_str());
169
170 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path.c_str()));
171 if (stream.get() == NULL) {
172 SkDebugf("Could not read %s.\n", path.c_str());
173 exit(1);
174 }
175 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream.get()));
176 if (pic.get() == NULL) {
177 SkDebugf("Could not read %s as an SkPicture.\n", path.c_str());
178 exit(1);
179 }
180
181 tasks->add(SkNEW_ARGS(DM::SKPTask, (reporter, tasks, pic.detach(), filename)));
182 }
183}
184
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000185static void report_failures(const SkTArray<SkString>& failures) {
mtklein@google.comd36522d2013-10-16 13:02:15 +0000186 if (failures.count() == 0) {
187 return;
188 }
189
190 SkDebugf("Failures:\n");
191 for (int i = 0; i < failures.count(); i++) {
192 SkDebugf(" %s\n", failures[i].c_str());
193 }
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000194 SkDebugf("%d failures.\n", failures.count());
mtklein@google.comd36522d2013-10-16 13:02:15 +0000195}
196
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000197template <typename T, typename Registry>
198static void append_matching_factories(Registry* head, SkTDArray<typename Registry::Factory>* out) {
199 for (const Registry* reg = head; reg != NULL; reg = reg->next()) {
200 SkAutoTDelete<T> forName(reg->factory()(NULL));
201 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, forName->getName())) {
202 *out->append() = reg->factory();
203 }
204 }
205}
206
commit-bot@chromium.org846872f2013-10-16 18:21:03 +0000207int tool_main(int argc, char** argv);
208int tool_main(int argc, char** argv) {
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000209 SkAutoGraphics ag;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000210 SkCommandLineFlags::Parse(argc, argv);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000211#if SK_ENABLE_INST_COUNT
212 gPrintInstCount = FLAGS_leaks;
213#endif
mtklein@google.comd36522d2013-10-16 13:02:15 +0000214 GM::SetResourcePath(FLAGS_resources[0]);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000215 SkBenchmark::SetResourcePath(FLAGS_resources[0]);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000216 Test::SetResourcePath(FLAGS_resources[0]);
217
mtklein@google.comd36522d2013-10-16 13:02:15 +0000218 SkTArray<SkString> configs;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000219 for (int i = 0; i < FLAGS_config.count(); i++) {
220 SkStrSplit(FLAGS_config[i], ", ", &configs);
221 }
222
mtklein@google.comd36522d2013-10-16 13:02:15 +0000223 SkTDArray<GMRegistry::Factory> gms;
commit-bot@chromium.org99589af2013-12-10 14:53:16 +0000224 SkAutoTDelete<DM::Expectations> expectations(SkNEW(DM::NoExpectations));
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000225 if (FLAGS_gms) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000226 append_matching_factories<GM>(GMRegistry::Head(), &gms);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000227
228 if (FLAGS_expectations.count() > 0) {
229 const char* path = FLAGS_expectations[0];
230 if (sk_isdir(path)) {
231 expectations.reset(SkNEW_ARGS(DM::WriteTask::Expectations, (path)));
232 } else {
commit-bot@chromium.org120c9992014-05-16 18:11:51 +0000233#ifdef SK_BUILD_JSON_WRITER
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000234 expectations.reset(SkNEW_ARGS(DM::JsonExpectations, (path)));
commit-bot@chromium.org120c9992014-05-16 18:11:51 +0000235#endif
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000236 }
commit-bot@chromium.org99589af2013-12-10 14:53:16 +0000237 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000238 }
239
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000240 SkTDArray<BenchRegistry::Factory> benches;
241 if (FLAGS_benches) {
242 append_matching_factories<SkBenchmark>(BenchRegistry::Head(), &benches);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000243 }
244
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000245 SkTDArray<TestRegistry::Factory> tests;
246 if (FLAGS_tests) {
247 append_matching_factories<Test>(TestRegistry::Head(), &tests);
248 }
249
250 SkDebugf("(%d GMs, %d benches) x %d configs, %d tests\n",
251 gms.count(), benches.count(), configs.count(), tests.count());
mtklein@google.comd36522d2013-10-16 13:02:15 +0000252 DM::Reporter reporter;
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +0000253 DM::TaskRunner tasks(FLAGS_threads, FLAGS_gpuThreads);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000254 kick_off_gms(gms, configs, *expectations, &reporter, &tasks);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000255 kick_off_benches(benches, configs, &reporter, &tasks);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000256 kick_off_tests(tests, &reporter, &tasks);
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000257 kick_off_skps(&reporter, &tasks);
mtklein@google.comd36522d2013-10-16 13:02:15 +0000258 tasks.wait();
259
mtklein@google.comd36522d2013-10-16 13:02:15 +0000260 SkDebugf("\n");
mtklein@google.comd36522d2013-10-16 13:02:15 +0000261
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000262 SkTArray<SkString> failures;
263 reporter.getFailures(&failures);
264 report_failures(failures);
265 return failures.count() > 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000266}
commit-bot@chromium.org846872f2013-10-16 18:21:03 +0000267
268#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
269int main(int argc, char** argv) {
270 return tool_main(argc, argv);
271}
272#endif