blob: f4eefa685cda8296f28c9338d59885136a4928ce [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
24#include <string.h>
25
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.org99589af2013-12-10 14:53:16 +000033DEFINE_string2(expectations, r, "",
34 "If a directory, compare generated images against images under this path. "
35 "If a file, compare generated images against JSON expectations at this path.");
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000036DEFINE_string2(resources, i, "resources", "Path to resources directory.");
mtklein@google.comd36522d2013-10-16 13:02:15 +000037DEFINE_string(match, "", "[~][^]substring[$] [...] of GM name to run.\n"
38 "Multiple matches may be separated by spaces.\n"
39 "~ causes a matching GM to always be skipped\n"
40 "^ requires the start of the GM to match\n"
41 "$ requires the end of the GM to match\n"
42 "^ and $ requires an exact match\n"
43 "If a GM does not match any list entry,\n"
44 "it is skipped unless some list entry starts with ~");
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000045DEFINE_string(config, "565 8888 gpu nonrendering",
commit-bot@chromium.orgb6401862014-03-12 14:46:31 +000046 "Options: 565 8888 gpu nonrendering msaa4 msaa16 nvprmsaa4 nvprmsaa16 gpunull gpudebug angle mesa");
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000047DEFINE_bool(leaks, false, "Print leaked instance-counted objects at exit?");
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +000048DEFINE_string(skps, "", "Directory to read skps from.");
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000049
50DEFINE_bool(gms, true, "Run GMs?");
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000051DEFINE_bool(benches, true, "Run benches? Does not run GMs-as-benches.");
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000052DEFINE_bool(tests, true, "Run tests?");
mtklein@google.comd36522d2013-10-16 13:02:15 +000053
54__SK_FORCE_IMAGE_DECODER_LINKING;
55
mtklein@google.comd36522d2013-10-16 13:02:15 +000056// "FooBar" -> "foobar". Obviously, ASCII only.
57static SkString lowercase(SkString s) {
58 for (size_t i = 0; i < s.size(); i++) {
59 s[i] = tolower(s[i]);
60 }
61 return s;
62}
63
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000064static const GrContextFactory::GLContextType native = GrContextFactory::kNative_GLContextType;
commit-bot@chromium.orgb6401862014-03-12 14:46:31 +000065static const GrContextFactory::GLContextType nvpr = GrContextFactory::kNVPR_GLContextType;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000066static const GrContextFactory::GLContextType null = GrContextFactory::kNull_GLContextType;
67static const GrContextFactory::GLContextType debug = GrContextFactory::kDebug_GLContextType;
68static const GrContextFactory::GLContextType angle =
69#if SK_ANGLE
70GrContextFactory::kANGLE_GLContextType;
71#else
72native;
73#endif
74static const GrContextFactory::GLContextType mesa =
75#if SK_MESA
bsalomon@google.com9dccafa2014-05-02 14:43:12 +000076GrContextFactory::kMESA_GLContextType;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000077#else
78native;
79#endif
80
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000081static void kick_off_gms(const SkTDArray<GMRegistry::Factory>& gms,
82 const SkTArray<SkString>& configs,
83 const DM::Expectations& expectations,
84 DM::Reporter* reporter,
85 DM::TaskRunner* tasks) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000086#define START(name, type, ...) \
87 if (lowercase(configs[j]).equals(name)) { \
88 tasks->add(SkNEW_ARGS(DM::type, \
89 (name, reporter, tasks, expectations, gms[i], ## __VA_ARGS__))); \
mtklein@google.comd36522d2013-10-16 13:02:15 +000090 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000091 for (int i = 0; i < gms.count(); i++) {
mtklein@google.comd36522d2013-10-16 13:02:15 +000092 for (int j = 0; j < configs.count(); j++) {
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000093 START("565", CpuGMTask, kRGB_565_SkColorType);
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +000094 START("8888", CpuGMTask, kN32_SkColorType);
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000095 START("gpu", GpuGMTask, native, 0);
96 START("msaa4", GpuGMTask, native, 4);
97 START("msaa16", GpuGMTask, native, 16);
commit-bot@chromium.orgb6401862014-03-12 14:46:31 +000098 START("nvprmsaa4", GpuGMTask, nvpr, 4);
99 START("nvprmsaa16", GpuGMTask, nvpr, 16);
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +0000100 START("gpunull", GpuGMTask, null, 0);
101 START("gpudebug", GpuGMTask, debug, 0);
102 START("angle", GpuGMTask, angle, 0);
103 START("mesa", GpuGMTask, mesa, 0);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000104 }
105 }
106#undef START
107}
108
109static void kick_off_benches(const SkTDArray<BenchRegistry::Factory>& benches,
110 const SkTArray<SkString>& configs,
111 DM::Reporter* reporter,
112 DM::TaskRunner* tasks) {
113#define START(name, type, ...) \
114 if (lowercase(configs[j]).equals(name)) { \
115 tasks->add(SkNEW_ARGS(DM::type, (name, reporter, tasks, benches[i], ## __VA_ARGS__))); \
116 }
117 for (int i = 0; i < benches.count(); i++) {
118 for (int j = 0; j < configs.count(); j++) {
119 START("nonrendering", NonRenderingBenchTask);
120 START("565", CpuBenchTask, kRGB_565_SkColorType);
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +0000121 START("8888", CpuBenchTask, kN32_SkColorType);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000122 START("gpu", GpuBenchTask, native, 0);
123 START("msaa4", GpuBenchTask, native, 4);
124 START("msaa16", GpuBenchTask, native, 16);
commit-bot@chromium.orgb6401862014-03-12 14:46:31 +0000125 START("nvprmsaa4", GpuBenchTask, nvpr, 4);
126 START("nvprmsaa16", GpuBenchTask, nvpr, 16);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000127 START("gpunull", GpuBenchTask, null, 0);
128 START("gpudebug", GpuBenchTask, debug, 0);
129 START("angle", GpuBenchTask, angle, 0);
130 START("mesa", GpuBenchTask, mesa, 0);
mtklein@google.comd36522d2013-10-16 13:02:15 +0000131 }
132 }
133#undef START
134}
135
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000136static void kick_off_tests(const SkTDArray<TestRegistry::Factory>& tests,
137 DM::Reporter* reporter,
138 DM::TaskRunner* tasks) {
139 for (int i = 0; i < tests.count(); i++) {
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +0000140 SkAutoTDelete<Test> test(tests[i](NULL));
141 if (test->isGPUTest()) {
142 tasks->add(SkNEW_ARGS(DM::GpuTestTask, (reporter, tasks, tests[i])));
143 } else {
144 tasks->add(SkNEW_ARGS(DM::CpuTestTask, (reporter, tasks, tests[i])));
145 }
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000146 }
147}
148
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000149static void kick_off_skps(DM::Reporter* reporter, DM::TaskRunner* tasks) {
150 if (FLAGS_skps.isEmpty()) {
151 return;
152 }
153
154 SkOSFile::Iter it(FLAGS_skps[0], ".skp");
155 SkString filename;
156 while (it.next(&filename)) {
157 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, filename.c_str())) {
158 continue;
159 }
160
161 const SkString path = SkOSPath::SkPathJoin(FLAGS_skps[0], filename.c_str());
162
163 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path.c_str()));
164 if (stream.get() == NULL) {
165 SkDebugf("Could not read %s.\n", path.c_str());
166 exit(1);
167 }
168 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream.get()));
169 if (pic.get() == NULL) {
170 SkDebugf("Could not read %s as an SkPicture.\n", path.c_str());
171 exit(1);
172 }
173
174 tasks->add(SkNEW_ARGS(DM::SKPTask, (reporter, tasks, pic.detach(), filename)));
175 }
176}
177
mtklein@google.comd36522d2013-10-16 13:02:15 +0000178static void report_failures(const DM::Reporter& reporter) {
179 SkTArray<SkString> failures;
180 reporter.getFailures(&failures);
181
182 if (failures.count() == 0) {
183 return;
184 }
185
186 SkDebugf("Failures:\n");
187 for (int i = 0; i < failures.count(); i++) {
188 SkDebugf(" %s\n", failures[i].c_str());
189 }
190}
191
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000192template <typename T, typename Registry>
193static void append_matching_factories(Registry* head, SkTDArray<typename Registry::Factory>* out) {
194 for (const Registry* reg = head; reg != NULL; reg = reg->next()) {
195 SkAutoTDelete<T> forName(reg->factory()(NULL));
196 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, forName->getName())) {
197 *out->append() = reg->factory();
198 }
199 }
200}
201
commit-bot@chromium.org846872f2013-10-16 18:21:03 +0000202int tool_main(int argc, char** argv);
203int tool_main(int argc, char** argv) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000204 SkGraphics::Init();
205 SkCommandLineFlags::Parse(argc, argv);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000206#if SK_ENABLE_INST_COUNT
207 gPrintInstCount = FLAGS_leaks;
208#endif
mtklein@google.comd36522d2013-10-16 13:02:15 +0000209 GM::SetResourcePath(FLAGS_resources[0]);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000210 SkBenchmark::SetResourcePath(FLAGS_resources[0]);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000211 Test::SetResourcePath(FLAGS_resources[0]);
212
mtklein@google.comd36522d2013-10-16 13:02:15 +0000213 SkTArray<SkString> configs;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000214 for (int i = 0; i < FLAGS_config.count(); i++) {
215 SkStrSplit(FLAGS_config[i], ", ", &configs);
216 }
217
mtklein@google.comd36522d2013-10-16 13:02:15 +0000218 SkTDArray<GMRegistry::Factory> gms;
commit-bot@chromium.org99589af2013-12-10 14:53:16 +0000219 SkAutoTDelete<DM::Expectations> expectations(SkNEW(DM::NoExpectations));
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000220 if (FLAGS_gms) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000221 append_matching_factories<GM>(GMRegistry::Head(), &gms);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000222
223 if (FLAGS_expectations.count() > 0) {
224 const char* path = FLAGS_expectations[0];
225 if (sk_isdir(path)) {
226 expectations.reset(SkNEW_ARGS(DM::WriteTask::Expectations, (path)));
227 } else {
228 expectations.reset(SkNEW_ARGS(DM::JsonExpectations, (path)));
229 }
commit-bot@chromium.org99589af2013-12-10 14:53:16 +0000230 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000231 }
232
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000233 SkTDArray<BenchRegistry::Factory> benches;
234 if (FLAGS_benches) {
235 append_matching_factories<SkBenchmark>(BenchRegistry::Head(), &benches);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000236 }
237
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000238 SkTDArray<TestRegistry::Factory> tests;
239 if (FLAGS_tests) {
240 append_matching_factories<Test>(TestRegistry::Head(), &tests);
241 }
242
243 SkDebugf("(%d GMs, %d benches) x %d configs, %d tests\n",
244 gms.count(), benches.count(), configs.count(), tests.count());
mtklein@google.comd36522d2013-10-16 13:02:15 +0000245 DM::Reporter reporter;
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +0000246 DM::TaskRunner tasks(FLAGS_threads, FLAGS_gpuThreads);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000247 kick_off_gms(gms, configs, *expectations, &reporter, &tasks);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000248 kick_off_benches(benches, configs, &reporter, &tasks);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000249 kick_off_tests(tests, &reporter, &tasks);
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000250 kick_off_skps(&reporter, &tasks);
mtklein@google.comd36522d2013-10-16 13:02:15 +0000251 tasks.wait();
252
mtklein@google.comd36522d2013-10-16 13:02:15 +0000253 SkDebugf("\n");
254 report_failures(reporter);
255
256 SkGraphics::Term();
257
258 return reporter.failed() > 0;
259}
commit-bot@chromium.org846872f2013-10-16 18:21:03 +0000260
261#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
262int main(int argc, char** argv) {
263 return tool_main(argc, argv);
264}
265#endif