blob: c0715dfce032955e90e3e8c4db44d702031dd7fe [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",
commit-bot@chromium.orgb6401862014-03-12 14:46:31 +000045 "Options: 565 8888 gpu nonrendering msaa4 msaa16 nvprmsaa4 nvprmsaa16 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;
commit-bot@chromium.orgb6401862014-03-12 14:46:31 +000063static const GrContextFactory::GLContextType nvpr = GrContextFactory::kNVPR_GLContextType;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000064static const GrContextFactory::GLContextType null = GrContextFactory::kNull_GLContextType;
65static const GrContextFactory::GLContextType debug = GrContextFactory::kDebug_GLContextType;
66static const GrContextFactory::GLContextType angle =
67#if SK_ANGLE
68GrContextFactory::kANGLE_GLContextType;
69#else
70native;
71#endif
72static const GrContextFactory::GLContextType mesa =
73#if SK_MESA
74GLContextFactory::kMESA_GLContextType;
75#else
76native;
77#endif
78
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000079static void kick_off_gms(const SkTDArray<GMRegistry::Factory>& gms,
80 const SkTArray<SkString>& configs,
81 const DM::Expectations& expectations,
82 DM::Reporter* reporter,
83 DM::TaskRunner* tasks) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000084#define START(name, type, ...) \
85 if (lowercase(configs[j]).equals(name)) { \
86 tasks->add(SkNEW_ARGS(DM::type, \
87 (name, reporter, tasks, expectations, gms[i], ## __VA_ARGS__))); \
mtklein@google.comd36522d2013-10-16 13:02:15 +000088 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000089 for (int i = 0; i < gms.count(); i++) {
mtklein@google.comd36522d2013-10-16 13:02:15 +000090 for (int j = 0; j < configs.count(); j++) {
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000091 START("565", CpuGMTask, kRGB_565_SkColorType);
92 START("8888", CpuGMTask, kPMColor_SkColorType);
93 START("gpu", GpuGMTask, native, 0);
94 START("msaa4", GpuGMTask, native, 4);
95 START("msaa16", GpuGMTask, native, 16);
commit-bot@chromium.orgb6401862014-03-12 14:46:31 +000096 START("nvprmsaa4", GpuGMTask, nvpr, 4);
97 START("nvprmsaa16", GpuGMTask, nvpr, 16);
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000098 START("gpunull", GpuGMTask, null, 0);
99 START("gpudebug", GpuGMTask, debug, 0);
100 START("angle", GpuGMTask, angle, 0);
101 START("mesa", GpuGMTask, mesa, 0);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000102 }
103 }
104#undef START
105}
106
107static void kick_off_benches(const SkTDArray<BenchRegistry::Factory>& benches,
108 const SkTArray<SkString>& configs,
109 DM::Reporter* reporter,
110 DM::TaskRunner* tasks) {
111#define START(name, type, ...) \
112 if (lowercase(configs[j]).equals(name)) { \
113 tasks->add(SkNEW_ARGS(DM::type, (name, reporter, tasks, benches[i], ## __VA_ARGS__))); \
114 }
115 for (int i = 0; i < benches.count(); i++) {
116 for (int j = 0; j < configs.count(); j++) {
117 START("nonrendering", NonRenderingBenchTask);
118 START("565", CpuBenchTask, kRGB_565_SkColorType);
119 START("8888", CpuBenchTask, kPMColor_SkColorType);
120 START("gpu", GpuBenchTask, native, 0);
121 START("msaa4", GpuBenchTask, native, 4);
122 START("msaa16", GpuBenchTask, native, 16);
commit-bot@chromium.orgb6401862014-03-12 14:46:31 +0000123 START("nvprmsaa4", GpuBenchTask, nvpr, 4);
124 START("nvprmsaa16", GpuBenchTask, nvpr, 16);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000125 START("gpunull", GpuBenchTask, null, 0);
126 START("gpudebug", GpuBenchTask, debug, 0);
127 START("angle", GpuBenchTask, angle, 0);
128 START("mesa", GpuBenchTask, mesa, 0);
mtklein@google.comd36522d2013-10-16 13:02:15 +0000129 }
130 }
131#undef START
132}
133
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000134static void kick_off_tests(const SkTDArray<TestRegistry::Factory>& tests,
135 DM::Reporter* reporter,
136 DM::TaskRunner* tasks) {
137 for (int i = 0; i < tests.count(); i++) {
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +0000138 SkAutoTDelete<Test> test(tests[i](NULL));
139 if (test->isGPUTest()) {
140 tasks->add(SkNEW_ARGS(DM::GpuTestTask, (reporter, tasks, tests[i])));
141 } else {
142 tasks->add(SkNEW_ARGS(DM::CpuTestTask, (reporter, tasks, tests[i])));
143 }
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000144 }
145}
146
mtklein@google.comd36522d2013-10-16 13:02:15 +0000147static void report_failures(const DM::Reporter& reporter) {
148 SkTArray<SkString> failures;
149 reporter.getFailures(&failures);
150
151 if (failures.count() == 0) {
152 return;
153 }
154
155 SkDebugf("Failures:\n");
156 for (int i = 0; i < failures.count(); i++) {
157 SkDebugf(" %s\n", failures[i].c_str());
158 }
159}
160
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000161template <typename T, typename Registry>
162static void append_matching_factories(Registry* head, SkTDArray<typename Registry::Factory>* out) {
163 for (const Registry* reg = head; reg != NULL; reg = reg->next()) {
164 SkAutoTDelete<T> forName(reg->factory()(NULL));
165 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, forName->getName())) {
166 *out->append() = reg->factory();
167 }
168 }
169}
170
commit-bot@chromium.org846872f2013-10-16 18:21:03 +0000171int tool_main(int argc, char** argv);
172int tool_main(int argc, char** argv) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000173 SkGraphics::Init();
174 SkCommandLineFlags::Parse(argc, argv);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000175#if SK_ENABLE_INST_COUNT
176 gPrintInstCount = FLAGS_leaks;
177#endif
mtklein@google.comd36522d2013-10-16 13:02:15 +0000178 GM::SetResourcePath(FLAGS_resources[0]);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000179 SkBenchmark::SetResourcePath(FLAGS_resources[0]);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000180 Test::SetResourcePath(FLAGS_resources[0]);
181
mtklein@google.comd36522d2013-10-16 13:02:15 +0000182 SkTArray<SkString> configs;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000183 for (int i = 0; i < FLAGS_config.count(); i++) {
184 SkStrSplit(FLAGS_config[i], ", ", &configs);
185 }
186
mtklein@google.comd36522d2013-10-16 13:02:15 +0000187 SkTDArray<GMRegistry::Factory> gms;
commit-bot@chromium.org99589af2013-12-10 14:53:16 +0000188 SkAutoTDelete<DM::Expectations> expectations(SkNEW(DM::NoExpectations));
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000189 if (FLAGS_gms) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000190 append_matching_factories<GM>(GMRegistry::Head(), &gms);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000191
192 if (FLAGS_expectations.count() > 0) {
193 const char* path = FLAGS_expectations[0];
194 if (sk_isdir(path)) {
195 expectations.reset(SkNEW_ARGS(DM::WriteTask::Expectations, (path)));
196 } else {
197 expectations.reset(SkNEW_ARGS(DM::JsonExpectations, (path)));
198 }
commit-bot@chromium.org99589af2013-12-10 14:53:16 +0000199 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000200 }
201
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000202 SkTDArray<BenchRegistry::Factory> benches;
203 if (FLAGS_benches) {
204 append_matching_factories<SkBenchmark>(BenchRegistry::Head(), &benches);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000205 }
206
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000207 SkTDArray<TestRegistry::Factory> tests;
208 if (FLAGS_tests) {
209 append_matching_factories<Test>(TestRegistry::Head(), &tests);
210 }
211
212 SkDebugf("(%d GMs, %d benches) x %d configs, %d tests\n",
213 gms.count(), benches.count(), configs.count(), tests.count());
mtklein@google.comd36522d2013-10-16 13:02:15 +0000214 DM::Reporter reporter;
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +0000215 DM::TaskRunner tasks(FLAGS_threads, FLAGS_gpuThreads);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000216 kick_off_gms(gms, configs, *expectations, &reporter, &tasks);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000217 kick_off_benches(benches, configs, &reporter, &tasks);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000218 kick_off_tests(tests, &reporter, &tasks);
mtklein@google.comd36522d2013-10-16 13:02:15 +0000219 tasks.wait();
220
mtklein@google.comd36522d2013-10-16 13:02:15 +0000221 SkDebugf("\n");
222 report_failures(reporter);
223
224 SkGraphics::Term();
225
226 return reporter.failed() > 0;
227}
commit-bot@chromium.org846872f2013-10-16 18:21:03 +0000228
229#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
230int main(int argc, char** argv) {
231 return tool_main(argc, argv);
232}
233#endif