blob: 9c5c25371c05056d9dbf8e0238c4068f74739428 [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
4#include "GrContext.h"
5#include "GrContextFactory.h"
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00006#include "SkBenchmark.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +00007#include "SkCommandLineFlags.h"
8#include "SkForceLinking.h"
9#include "SkGraphics.h"
rmistry@google.comd6bab022013-12-02 13:50:38 +000010#include "SkString.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000011#include "Test.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000012#include "gm.h"
13
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000014#include "DMBenchTask.h"
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000015#include "DMCpuGMTask.h"
16#include "DMGpuGMTask.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000017#include "DMReporter.h"
18#include "DMTask.h"
19#include "DMTaskRunner.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000020#include "DMTestTask.h"
commit-bot@chromium.org99589af2013-12-10 14:53:16 +000021#include "DMWriteTask.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000022
23#include <string.h>
24
25using skiagm::GM;
26using skiagm::GMRegistry;
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000027using skiatest::Test;
28using skiatest::TestRegistry;
mtklein@google.comd36522d2013-10-16 13:02:15 +000029
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000030DEFINE_int32(threads, -1, "Threads for CPU work. Default NUM_CPUS.");
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000031DEFINE_int32(gpuThreads, 1, "Threads for GPU work.");
commit-bot@chromium.org99589af2013-12-10 14:53:16 +000032DEFINE_string2(expectations, r, "",
33 "If a directory, compare generated images against images under this path. "
34 "If a file, compare generated images against JSON expectations at this path.");
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000035DEFINE_string2(resources, i, "resources", "Path to resources directory.");
mtklein@google.comd36522d2013-10-16 13:02:15 +000036DEFINE_string(match, "", "[~][^]substring[$] [...] of GM name to run.\n"
37 "Multiple matches may be separated by spaces.\n"
38 "~ causes a matching GM to always be skipped\n"
39 "^ requires the start of the GM to match\n"
40 "$ requires the end of the GM to match\n"
41 "^ and $ requires an exact match\n"
42 "If a GM does not match any list entry,\n"
43 "it is skipped unless some list entry starts with ~");
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000044DEFINE_string(config, "565 8888 gpu nonrendering",
45 "Options: 565 8888 gpu nonrendering msaa4 msaa16 gpunull gpudebug angle mesa");
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000046DEFINE_bool(leaks, false, "Print leaked instance-counted objects at exit?");
47
48DEFINE_bool(gms, true, "Run GMs?");
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000049DEFINE_bool(benches, true, "Run benches? Does not run GMs-as-benches.");
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000050DEFINE_bool(tests, true, "Run tests?");
mtklein@google.comd36522d2013-10-16 13:02:15 +000051
52__SK_FORCE_IMAGE_DECODER_LINKING;
53
mtklein@google.comd36522d2013-10-16 13:02:15 +000054// "FooBar" -> "foobar". Obviously, ASCII only.
55static SkString lowercase(SkString s) {
56 for (size_t i = 0; i < s.size(); i++) {
57 s[i] = tolower(s[i]);
58 }
59 return s;
60}
61
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000062static const GrContextFactory::GLContextType native = GrContextFactory::kNative_GLContextType;
63static const GrContextFactory::GLContextType null = GrContextFactory::kNull_GLContextType;
64static const GrContextFactory::GLContextType debug = GrContextFactory::kDebug_GLContextType;
65static const GrContextFactory::GLContextType angle =
66#if SK_ANGLE
67GrContextFactory::kANGLE_GLContextType;
68#else
69native;
70#endif
71static const GrContextFactory::GLContextType mesa =
72#if SK_MESA
73GLContextFactory::kMESA_GLContextType;
74#else
75native;
76#endif
77
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000078static void kick_off_gms(const SkTDArray<GMRegistry::Factory>& gms,
79 const SkTArray<SkString>& configs,
80 const DM::Expectations& expectations,
81 DM::Reporter* reporter,
82 DM::TaskRunner* tasks) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000083#define START(name, type, ...) \
84 if (lowercase(configs[j]).equals(name)) { \
85 tasks->add(SkNEW_ARGS(DM::type, \
86 (name, reporter, tasks, expectations, gms[i], ## __VA_ARGS__))); \
mtklein@google.comd36522d2013-10-16 13:02:15 +000087 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000088 for (int i = 0; i < gms.count(); i++) {
mtklein@google.comd36522d2013-10-16 13:02:15 +000089 for (int j = 0; j < configs.count(); j++) {
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000090 START("565", CpuGMTask, kRGB_565_SkColorType);
91 START("8888", CpuGMTask, kPMColor_SkColorType);
92 START("gpu", GpuGMTask, native, 0);
93 START("msaa4", GpuGMTask, native, 4);
94 START("msaa16", GpuGMTask, native, 16);
95 START("gpunull", GpuGMTask, null, 0);
96 START("gpudebug", GpuGMTask, debug, 0);
97 START("angle", GpuGMTask, angle, 0);
98 START("mesa", GpuGMTask, mesa, 0);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000099 }
100 }
101#undef START
102}
103
104static void kick_off_benches(const SkTDArray<BenchRegistry::Factory>& benches,
105 const SkTArray<SkString>& configs,
106 DM::Reporter* reporter,
107 DM::TaskRunner* tasks) {
108#define START(name, type, ...) \
109 if (lowercase(configs[j]).equals(name)) { \
110 tasks->add(SkNEW_ARGS(DM::type, (name, reporter, tasks, benches[i], ## __VA_ARGS__))); \
111 }
112 for (int i = 0; i < benches.count(); i++) {
113 for (int j = 0; j < configs.count(); j++) {
114 START("nonrendering", NonRenderingBenchTask);
115 START("565", CpuBenchTask, kRGB_565_SkColorType);
116 START("8888", CpuBenchTask, kPMColor_SkColorType);
117 START("gpu", GpuBenchTask, native, 0);
118 START("msaa4", GpuBenchTask, native, 4);
119 START("msaa16", GpuBenchTask, native, 16);
120 START("gpunull", GpuBenchTask, null, 0);
121 START("gpudebug", GpuBenchTask, debug, 0);
122 START("angle", GpuBenchTask, angle, 0);
123 START("mesa", GpuBenchTask, mesa, 0);
mtklein@google.comd36522d2013-10-16 13:02:15 +0000124 }
125 }
126#undef START
127}
128
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000129static void kick_off_tests(const SkTDArray<TestRegistry::Factory>& tests,
130 DM::Reporter* reporter,
131 DM::TaskRunner* tasks) {
132 for (int i = 0; i < tests.count(); i++) {
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +0000133 SkAutoTDelete<Test> test(tests[i](NULL));
134 if (test->isGPUTest()) {
135 tasks->add(SkNEW_ARGS(DM::GpuTestTask, (reporter, tasks, tests[i])));
136 } else {
137 tasks->add(SkNEW_ARGS(DM::CpuTestTask, (reporter, tasks, tests[i])));
138 }
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000139 }
140}
141
mtklein@google.comd36522d2013-10-16 13:02:15 +0000142static void report_failures(const DM::Reporter& reporter) {
143 SkTArray<SkString> failures;
144 reporter.getFailures(&failures);
145
146 if (failures.count() == 0) {
147 return;
148 }
149
150 SkDebugf("Failures:\n");
151 for (int i = 0; i < failures.count(); i++) {
152 SkDebugf(" %s\n", failures[i].c_str());
153 }
154}
155
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000156template <typename T, typename Registry>
157static void append_matching_factories(Registry* head, SkTDArray<typename Registry::Factory>* out) {
158 for (const Registry* reg = head; reg != NULL; reg = reg->next()) {
159 SkAutoTDelete<T> forName(reg->factory()(NULL));
160 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, forName->getName())) {
161 *out->append() = reg->factory();
162 }
163 }
164}
165
commit-bot@chromium.org846872f2013-10-16 18:21:03 +0000166int tool_main(int argc, char** argv);
167int tool_main(int argc, char** argv) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000168 SkGraphics::Init();
169 SkCommandLineFlags::Parse(argc, argv);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000170#if SK_ENABLE_INST_COUNT
171 gPrintInstCount = FLAGS_leaks;
172#endif
mtklein@google.comd36522d2013-10-16 13:02:15 +0000173 GM::SetResourcePath(FLAGS_resources[0]);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000174 SkBenchmark::SetResourcePath(FLAGS_resources[0]);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000175 Test::SetResourcePath(FLAGS_resources[0]);
176
mtklein@google.comd36522d2013-10-16 13:02:15 +0000177 SkTArray<SkString> configs;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000178 for (int i = 0; i < FLAGS_config.count(); i++) {
179 SkStrSplit(FLAGS_config[i], ", ", &configs);
180 }
181
mtklein@google.comd36522d2013-10-16 13:02:15 +0000182 SkTDArray<GMRegistry::Factory> gms;
commit-bot@chromium.org99589af2013-12-10 14:53:16 +0000183 SkAutoTDelete<DM::Expectations> expectations(SkNEW(DM::NoExpectations));
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000184 if (FLAGS_gms) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000185 append_matching_factories<GM>(GMRegistry::Head(), &gms);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000186
187 if (FLAGS_expectations.count() > 0) {
188 const char* path = FLAGS_expectations[0];
189 if (sk_isdir(path)) {
190 expectations.reset(SkNEW_ARGS(DM::WriteTask::Expectations, (path)));
191 } else {
192 expectations.reset(SkNEW_ARGS(DM::JsonExpectations, (path)));
193 }
commit-bot@chromium.org99589af2013-12-10 14:53:16 +0000194 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000195 }
196
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000197 SkTDArray<BenchRegistry::Factory> benches;
198 if (FLAGS_benches) {
199 append_matching_factories<SkBenchmark>(BenchRegistry::Head(), &benches);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000200 }
201
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000202 SkTDArray<TestRegistry::Factory> tests;
203 if (FLAGS_tests) {
204 append_matching_factories<Test>(TestRegistry::Head(), &tests);
205 }
206
207 SkDebugf("(%d GMs, %d benches) x %d configs, %d tests\n",
208 gms.count(), benches.count(), configs.count(), tests.count());
mtklein@google.comd36522d2013-10-16 13:02:15 +0000209 DM::Reporter reporter;
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +0000210 DM::TaskRunner tasks(FLAGS_threads, FLAGS_gpuThreads);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000211 kick_off_gms(gms, configs, *expectations, &reporter, &tasks);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000212 kick_off_benches(benches, configs, &reporter, &tasks);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000213 kick_off_tests(tests, &reporter, &tasks);
mtklein@google.comd36522d2013-10-16 13:02:15 +0000214 tasks.wait();
215
mtklein@google.comd36522d2013-10-16 13:02:15 +0000216 SkDebugf("\n");
217 report_failures(reporter);
218
219 SkGraphics::Term();
220
221 return reporter.failed() > 0;
222}
commit-bot@chromium.org846872f2013-10-16 18:21:03 +0000223
224#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
225int main(int argc, char** argv) {
226 return tool_main(argc, argv);
227}
228#endif