blob: a8a2b6dd82a7095689ed09e23d8882523d683de3 [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"
rmistry@google.comd6bab022013-12-02 13:50:38 +00008#include "SkString.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +00009#include "Test.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000010#include "gm.h"
11
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000012#include "DMBenchTask.h"
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000013#include "DMCpuGMTask.h"
14#include "DMGpuGMTask.h"
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000015#include "DMGpuSupport.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000016#include "DMReporter.h"
17#include "DMTask.h"
18#include "DMTaskRunner.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000019#include "DMTestTask.h"
commit-bot@chromium.org99589af2013-12-10 14:53:16 +000020#include "DMWriteTask.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000021
22#include <string.h>
23
24using skiagm::GM;
25using skiagm::GMRegistry;
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000026using skiatest::Test;
27using skiatest::TestRegistry;
mtklein@google.comd36522d2013-10-16 13:02:15 +000028
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000029DEFINE_int32(threads, -1, "Threads for CPU work. Default NUM_CPUS.");
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000030DEFINE_int32(gpuThreads, 1, "Threads for GPU work.");
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",
commit-bot@chromium.orgb6401862014-03-12 14:46:31 +000044 "Options: 565 8888 gpu nonrendering msaa4 msaa16 nvprmsaa4 nvprmsaa16 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;
commit-bot@chromium.orgb6401862014-03-12 14:46:31 +000062static const GrContextFactory::GLContextType nvpr = GrContextFactory::kNVPR_GLContextType;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000063static 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);
commit-bot@chromium.org757ebd22014-04-10 22:36:34 +000091 START("8888", CpuGMTask, kPMColor_SkColorType);
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000092 START("gpu", GpuGMTask, native, 0);
93 START("msaa4", GpuGMTask, native, 4);
94 START("msaa16", GpuGMTask, native, 16);
commit-bot@chromium.orgb6401862014-03-12 14:46:31 +000095 START("nvprmsaa4", GpuGMTask, nvpr, 4);
96 START("nvprmsaa16", GpuGMTask, nvpr, 16);
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000097 START("gpunull", GpuGMTask, null, 0);
98 START("gpudebug", GpuGMTask, debug, 0);
99 START("angle", GpuGMTask, angle, 0);
100 START("mesa", GpuGMTask, mesa, 0);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000101 }
102 }
103#undef START
104}
105
106static void kick_off_benches(const SkTDArray<BenchRegistry::Factory>& benches,
107 const SkTArray<SkString>& configs,
108 DM::Reporter* reporter,
109 DM::TaskRunner* tasks) {
110#define START(name, type, ...) \
111 if (lowercase(configs[j]).equals(name)) { \
112 tasks->add(SkNEW_ARGS(DM::type, (name, reporter, tasks, benches[i], ## __VA_ARGS__))); \
113 }
114 for (int i = 0; i < benches.count(); i++) {
115 for (int j = 0; j < configs.count(); j++) {
116 START("nonrendering", NonRenderingBenchTask);
117 START("565", CpuBenchTask, kRGB_565_SkColorType);
commit-bot@chromium.org757ebd22014-04-10 22:36:34 +0000118 START("8888", CpuBenchTask, kPMColor_SkColorType);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000119 START("gpu", GpuBenchTask, native, 0);
120 START("msaa4", GpuBenchTask, native, 4);
121 START("msaa16", GpuBenchTask, native, 16);
commit-bot@chromium.orgb6401862014-03-12 14:46:31 +0000122 START("nvprmsaa4", GpuBenchTask, nvpr, 4);
123 START("nvprmsaa16", GpuBenchTask, nvpr, 16);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000124 START("gpunull", GpuBenchTask, null, 0);
125 START("gpudebug", GpuBenchTask, debug, 0);
126 START("angle", GpuBenchTask, angle, 0);
127 START("mesa", GpuBenchTask, mesa, 0);
mtklein@google.comd36522d2013-10-16 13:02:15 +0000128 }
129 }
130#undef START
131}
132
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000133static void kick_off_tests(const SkTDArray<TestRegistry::Factory>& tests,
134 DM::Reporter* reporter,
135 DM::TaskRunner* tasks) {
136 for (int i = 0; i < tests.count(); i++) {
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +0000137 SkAutoTDelete<Test> test(tests[i](NULL));
138 if (test->isGPUTest()) {
139 tasks->add(SkNEW_ARGS(DM::GpuTestTask, (reporter, tasks, tests[i])));
140 } else {
141 tasks->add(SkNEW_ARGS(DM::CpuTestTask, (reporter, tasks, tests[i])));
142 }
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000143 }
144}
145
mtklein@google.comd36522d2013-10-16 13:02:15 +0000146static void report_failures(const DM::Reporter& reporter) {
147 SkTArray<SkString> failures;
148 reporter.getFailures(&failures);
149
150 if (failures.count() == 0) {
151 return;
152 }
153
154 SkDebugf("Failures:\n");
155 for (int i = 0; i < failures.count(); i++) {
156 SkDebugf(" %s\n", failures[i].c_str());
157 }
158}
159
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000160template <typename T, typename Registry>
161static void append_matching_factories(Registry* head, SkTDArray<typename Registry::Factory>* out) {
162 for (const Registry* reg = head; reg != NULL; reg = reg->next()) {
163 SkAutoTDelete<T> forName(reg->factory()(NULL));
164 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, forName->getName())) {
165 *out->append() = reg->factory();
166 }
167 }
168}
169
commit-bot@chromium.org846872f2013-10-16 18:21:03 +0000170int tool_main(int argc, char** argv);
171int tool_main(int argc, char** argv) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000172 SkGraphics::Init();
173 SkCommandLineFlags::Parse(argc, argv);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000174#if SK_ENABLE_INST_COUNT
175 gPrintInstCount = FLAGS_leaks;
176#endif
mtklein@google.comd36522d2013-10-16 13:02:15 +0000177 GM::SetResourcePath(FLAGS_resources[0]);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000178 SkBenchmark::SetResourcePath(FLAGS_resources[0]);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000179 Test::SetResourcePath(FLAGS_resources[0]);
180
mtklein@google.comd36522d2013-10-16 13:02:15 +0000181 SkTArray<SkString> configs;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000182 for (int i = 0; i < FLAGS_config.count(); i++) {
183 SkStrSplit(FLAGS_config[i], ", ", &configs);
184 }
185
mtklein@google.comd36522d2013-10-16 13:02:15 +0000186 SkTDArray<GMRegistry::Factory> gms;
commit-bot@chromium.org99589af2013-12-10 14:53:16 +0000187 SkAutoTDelete<DM::Expectations> expectations(SkNEW(DM::NoExpectations));
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000188 if (FLAGS_gms) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000189 append_matching_factories<GM>(GMRegistry::Head(), &gms);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000190
191 if (FLAGS_expectations.count() > 0) {
192 const char* path = FLAGS_expectations[0];
193 if (sk_isdir(path)) {
194 expectations.reset(SkNEW_ARGS(DM::WriteTask::Expectations, (path)));
195 } else {
196 expectations.reset(SkNEW_ARGS(DM::JsonExpectations, (path)));
197 }
commit-bot@chromium.org99589af2013-12-10 14:53:16 +0000198 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000199 }
200
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000201 SkTDArray<BenchRegistry::Factory> benches;
202 if (FLAGS_benches) {
203 append_matching_factories<SkBenchmark>(BenchRegistry::Head(), &benches);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000204 }
205
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000206 SkTDArray<TestRegistry::Factory> tests;
207 if (FLAGS_tests) {
208 append_matching_factories<Test>(TestRegistry::Head(), &tests);
209 }
210
211 SkDebugf("(%d GMs, %d benches) x %d configs, %d tests\n",
212 gms.count(), benches.count(), configs.count(), tests.count());
mtklein@google.comd36522d2013-10-16 13:02:15 +0000213 DM::Reporter reporter;
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +0000214 DM::TaskRunner tasks(FLAGS_threads, FLAGS_gpuThreads);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000215 kick_off_gms(gms, configs, *expectations, &reporter, &tasks);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000216 kick_off_benches(benches, configs, &reporter, &tasks);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000217 kick_off_tests(tests, &reporter, &tasks);
mtklein@google.comd36522d2013-10-16 13:02:15 +0000218 tasks.wait();
219
mtklein@google.comd36522d2013-10-16 13:02:15 +0000220 SkDebugf("\n");
221 report_failures(reporter);
222
223 SkGraphics::Term();
224
225 return reporter.failed() > 0;
226}
commit-bot@chromium.org846872f2013-10-16 18:21:03 +0000227
228#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
229int main(int argc, char** argv) {
230 return tool_main(argc, argv);
231}
232#endif