blob: bf37d20a80d53d92cc29e965f7e05ce59e744148 [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.org0dc5bd12014-02-26 16:31:22 +000015#include "DMCpuTask.h"
16#include "DMGpuTask.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.org99589af2013-12-10 14:53:16 +000031DEFINE_string2(expectations, r, "",
32 "If a directory, compare generated images against images under this path. "
33 "If a file, compare generated images against JSON expectations at this path.");
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000034DEFINE_string2(resources, i, "resources", "Path to resources directory.");
mtklein@google.comd36522d2013-10-16 13:02:15 +000035DEFINE_string(match, "", "[~][^]substring[$] [...] of GM name to run.\n"
36 "Multiple matches may be separated by spaces.\n"
37 "~ causes a matching GM to always be skipped\n"
38 "^ requires the start of the GM to match\n"
39 "$ requires the end of the GM to match\n"
40 "^ and $ requires an exact match\n"
41 "If a GM does not match any list entry,\n"
42 "it is skipped unless some list entry starts with ~");
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000043DEFINE_string(config, "565 8888 gpu nonrendering",
44 "Options: 565 8888 gpu nonrendering msaa4 msaa16 gpunull gpudebug angle mesa");
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000045DEFINE_bool(leaks, false, "Print leaked instance-counted objects at exit?");
46
47DEFINE_bool(gms, true, "Run GMs?");
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000048DEFINE_bool(benches, true, "Run benches? Does not run GMs-as-benches.");
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000049DEFINE_bool(tests, true, "Run tests?");
mtklein@google.comd36522d2013-10-16 13:02:15 +000050
51__SK_FORCE_IMAGE_DECODER_LINKING;
52
mtklein@google.comd36522d2013-10-16 13:02:15 +000053// "FooBar" -> "foobar". Obviously, ASCII only.
54static SkString lowercase(SkString s) {
55 for (size_t i = 0; i < s.size(); i++) {
56 s[i] = tolower(s[i]);
57 }
58 return s;
59}
60
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000061static const GrContextFactory::GLContextType native = GrContextFactory::kNative_GLContextType;
62static const GrContextFactory::GLContextType null = GrContextFactory::kNull_GLContextType;
63static const GrContextFactory::GLContextType debug = GrContextFactory::kDebug_GLContextType;
64static const GrContextFactory::GLContextType angle =
65#if SK_ANGLE
66GrContextFactory::kANGLE_GLContextType;
67#else
68native;
69#endif
70static const GrContextFactory::GLContextType mesa =
71#if SK_MESA
72GLContextFactory::kMESA_GLContextType;
73#else
74native;
75#endif
76
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000077static void kick_off_gms(const SkTDArray<GMRegistry::Factory>& gms,
78 const SkTArray<SkString>& configs,
79 const DM::Expectations& expectations,
80 DM::Reporter* reporter,
81 DM::TaskRunner* tasks) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000082#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__))); \
mtklein@google.comd36522d2013-10-16 13:02:15 +000086 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000087 for (int i = 0; i < gms.count(); i++) {
mtklein@google.comd36522d2013-10-16 13:02:15 +000088 for (int j = 0; j < configs.count(); j++) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000089 START("565", CpuTask, kRGB_565_SkColorType);
90 START("8888", CpuTask, kPMColor_SkColorType);
91 START("gpu", GpuTask, native, 0);
92 START("msaa4", GpuTask, native, 4);
93 START("msaa16", GpuTask, native, 16);
94 START("gpunull", GpuTask, null, 0);
95 START("gpudebug", GpuTask, debug, 0);
96 START("angle", GpuTask, angle, 0);
97 START("mesa", GpuTask, mesa, 0);
98 }
99 }
100#undef START
101}
102
103static 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);
mtklein@google.comd36522d2013-10-16 13:02:15 +0000123 }
124 }
125#undef START
126}
127
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000128static void kick_off_tests(const SkTDArray<TestRegistry::Factory>& tests,
129 DM::Reporter* reporter,
130 DM::TaskRunner* tasks) {
131 for (int i = 0; i < tests.count(); i++) {
132 tasks->add(SkNEW_ARGS(DM::TestTask, (reporter, tasks, tests[i])));
133 }
134}
135
mtklein@google.comd36522d2013-10-16 13:02:15 +0000136static void report_failures(const DM::Reporter& reporter) {
137 SkTArray<SkString> failures;
138 reporter.getFailures(&failures);
139
140 if (failures.count() == 0) {
141 return;
142 }
143
144 SkDebugf("Failures:\n");
145 for (int i = 0; i < failures.count(); i++) {
146 SkDebugf(" %s\n", failures[i].c_str());
147 }
148}
149
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000150template <typename T, typename Registry>
151static void append_matching_factories(Registry* head, SkTDArray<typename Registry::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
commit-bot@chromium.org846872f2013-10-16 18:21:03 +0000160int tool_main(int argc, char** argv);
161int tool_main(int argc, char** argv) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000162 SkGraphics::Init();
163 SkCommandLineFlags::Parse(argc, argv);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000164#if SK_ENABLE_INST_COUNT
165 gPrintInstCount = FLAGS_leaks;
166#endif
mtklein@google.comd36522d2013-10-16 13:02:15 +0000167 GM::SetResourcePath(FLAGS_resources[0]);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000168 SkBenchmark::SetResourcePath(FLAGS_resources[0]);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000169 Test::SetResourcePath(FLAGS_resources[0]);
170
mtklein@google.comd36522d2013-10-16 13:02:15 +0000171 SkTArray<SkString> configs;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000172 for (int i = 0; i < FLAGS_config.count(); i++) {
173 SkStrSplit(FLAGS_config[i], ", ", &configs);
174 }
175
mtklein@google.comd36522d2013-10-16 13:02:15 +0000176 SkTDArray<GMRegistry::Factory> gms;
commit-bot@chromium.org99589af2013-12-10 14:53:16 +0000177 SkAutoTDelete<DM::Expectations> expectations(SkNEW(DM::NoExpectations));
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000178 if (FLAGS_gms) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000179 append_matching_factories<GM>(GMRegistry::Head(), &gms);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000180
181 if (FLAGS_expectations.count() > 0) {
182 const char* path = FLAGS_expectations[0];
183 if (sk_isdir(path)) {
184 expectations.reset(SkNEW_ARGS(DM::WriteTask::Expectations, (path)));
185 } else {
186 expectations.reset(SkNEW_ARGS(DM::JsonExpectations, (path)));
187 }
commit-bot@chromium.org99589af2013-12-10 14:53:16 +0000188 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000189 }
190
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000191 SkTDArray<BenchRegistry::Factory> benches;
192 if (FLAGS_benches) {
193 append_matching_factories<SkBenchmark>(BenchRegistry::Head(), &benches);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000194 }
195
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000196 SkTDArray<TestRegistry::Factory> tests;
197 if (FLAGS_tests) {
198 append_matching_factories<Test>(TestRegistry::Head(), &tests);
199 }
200
201 SkDebugf("(%d GMs, %d benches) x %d configs, %d tests\n",
202 gms.count(), benches.count(), configs.count(), tests.count());
mtklein@google.comd36522d2013-10-16 13:02:15 +0000203 DM::Reporter reporter;
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000204 DM::TaskRunner tasks(FLAGS_threads);
205 kick_off_gms(gms, configs, *expectations, &reporter, &tasks);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000206 kick_off_benches(benches, configs, &reporter, &tasks);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000207 kick_off_tests(tests, &reporter, &tasks);
mtklein@google.comd36522d2013-10-16 13:02:15 +0000208 tasks.wait();
209
mtklein@google.comd36522d2013-10-16 13:02:15 +0000210 SkDebugf("\n");
211 report_failures(reporter);
212
213 SkGraphics::Term();
214
215 return reporter.failed() > 0;
216}
commit-bot@chromium.org846872f2013-10-16 18:21:03 +0000217
218#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
219int main(int argc, char** argv) {
220 return tool_main(argc, argv);
221}
222#endif