blob: 64a4bc5a231a50f9e41251880b4d255a6b7cdd99 [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
tfarinaf168b862014-06-19 12:32:29 -07004#include "Benchmark.h"
5#include "CrashHandler.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +00006#include "SkCommandLineFlags.h"
7#include "SkForceLinking.h"
8#include "SkGraphics.h"
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +00009#include "SkPicture.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"
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000017#include "DMGpuSupport.h"
mtklein30bf3e22014-06-03 13:57:14 -070018#include "DMPDFTask.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000019#include "DMReporter.h"
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +000020#include "DMSKPTask.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000021#include "DMTask.h"
22#include "DMTaskRunner.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000023#include "DMTestTask.h"
commit-bot@chromium.org99589af2013-12-10 14:53:16 +000024#include "DMWriteTask.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000025
mtklein30bf3e22014-06-03 13:57:14 -070026#ifdef SK_BUILD_POPPLER
27# include "SkPDFRasterizer.h"
28# define RASTERIZE_PDF_PROC SkPopplerRasterizePDF
29#else
30# define RASTERIZE_PDF_PROC NULL
31#endif
32
commit-bot@chromium.org120c9992014-05-16 18:11:51 +000033#include <ctype.h>
mtklein@google.comd36522d2013-10-16 13:02:15 +000034
35using skiagm::GM;
36using skiagm::GMRegistry;
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000037using skiatest::Test;
38using skiatest::TestRegistry;
mtklein@google.comd36522d2013-10-16 13:02:15 +000039
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000040DEFINE_int32(threads, -1, "Threads for CPU work. Default NUM_CPUS.");
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000041DEFINE_int32(gpuThreads, 1, "Threads for GPU work.");
commit-bot@chromium.org99589af2013-12-10 14:53:16 +000042DEFINE_string2(expectations, r, "",
43 "If a directory, compare generated images against images under this path. "
commit-bot@chromium.org120c9992014-05-16 18:11:51 +000044 "If a file, compare generated images against JSON expectations at this path."
commit-bot@chromium.org120c9992014-05-16 18:11:51 +000045);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000046DEFINE_string2(resources, i, "resources", "Path to resources directory.");
mtklein@google.comd36522d2013-10-16 13:02:15 +000047DEFINE_string(match, "", "[~][^]substring[$] [...] of GM name to run.\n"
48 "Multiple matches may be separated by spaces.\n"
49 "~ causes a matching GM to always be skipped\n"
50 "^ requires the start of the GM to match\n"
51 "$ requires the end of the GM to match\n"
52 "^ and $ requires an exact match\n"
53 "If a GM does not match any list entry,\n"
54 "it is skipped unless some list entry starts with ~");
mtklein30bf3e22014-06-03 13:57:14 -070055DEFINE_string(config, "565 8888 pdf gpu nonrendering",
56 "Options: 565 8888 pdf gpu nonrendering msaa4 msaa16 nvprmsaa4 nvprmsaa16 "
57 "gpunull gpudebug angle mesa");
58DEFINE_bool(dryRun, false,
59 "Just print the tests that would be run, without actually running them.");
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000060DEFINE_bool(leaks, false, "Print leaked instance-counted objects at exit?");
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +000061DEFINE_string(skps, "", "Directory to read skps from.");
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000062
63DEFINE_bool(gms, true, "Run GMs?");
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000064DEFINE_bool(benches, true, "Run benches? Does not run GMs-as-benches.");
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000065DEFINE_bool(tests, true, "Run tests?");
mtklein@google.comd36522d2013-10-16 13:02:15 +000066
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +000067DECLARE_bool(verbose);
68
mtklein@google.comd36522d2013-10-16 13:02:15 +000069__SK_FORCE_IMAGE_DECODER_LINKING;
70
mtklein@google.comd36522d2013-10-16 13:02:15 +000071// "FooBar" -> "foobar". Obviously, ASCII only.
72static SkString lowercase(SkString s) {
73 for (size_t i = 0; i < s.size(); i++) {
74 s[i] = tolower(s[i]);
75 }
76 return s;
77}
78
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000079static const GrContextFactory::GLContextType native = GrContextFactory::kNative_GLContextType;
commit-bot@chromium.orgb6401862014-03-12 14:46:31 +000080static const GrContextFactory::GLContextType nvpr = GrContextFactory::kNVPR_GLContextType;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000081static const GrContextFactory::GLContextType null = GrContextFactory::kNull_GLContextType;
82static const GrContextFactory::GLContextType debug = GrContextFactory::kDebug_GLContextType;
83static const GrContextFactory::GLContextType angle =
84#if SK_ANGLE
85GrContextFactory::kANGLE_GLContextType;
86#else
87native;
88#endif
89static const GrContextFactory::GLContextType mesa =
90#if SK_MESA
bsalomon@google.com9dccafa2014-05-02 14:43:12 +000091GrContextFactory::kMESA_GLContextType;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000092#else
93native;
94#endif
95
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000096static void kick_off_gms(const SkTDArray<GMRegistry::Factory>& gms,
97 const SkTArray<SkString>& configs,
98 const DM::Expectations& expectations,
99 DM::Reporter* reporter,
100 DM::TaskRunner* tasks) {
mtkleine4d3e602014-06-06 09:28:43 -0700101#define START(name, type, ...) \
102 if (lowercase(configs[j]).equals(name)) { \
103 tasks->add(SkNEW_ARGS(DM::type, (name, reporter, tasks, gms[i], ## __VA_ARGS__))); \
mtklein@google.comd36522d2013-10-16 13:02:15 +0000104 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000105 for (int i = 0; i < gms.count(); i++) {
mtklein@google.comd36522d2013-10-16 13:02:15 +0000106 for (int j = 0; j < configs.count(); j++) {
mtkleine4d3e602014-06-06 09:28:43 -0700107 START("565", CpuGMTask, expectations, kRGB_565_SkColorType);
108 START("8888", CpuGMTask, expectations, kN32_SkColorType);
rmistry05ead8a2014-06-23 06:13:46 -0700109 START("gpu", GpuGMTask, expectations, native, 0);
110 START("msaa4", GpuGMTask, expectations, native, 4);
111 START("msaa16", GpuGMTask, expectations, native, 16);
112 START("nvprmsaa4", GpuGMTask, expectations, nvpr, 4);
113 START("nvprmsaa16", GpuGMTask, expectations, nvpr, 16);
114 START("gpunull", GpuGMTask, expectations, null, 0);
115 START("gpudebug", GpuGMTask, expectations, debug, 0);
116 START("angle", GpuGMTask, expectations, angle, 0);
117 START("mesa", GpuGMTask, expectations, mesa, 0);
mtklein30bf3e22014-06-03 13:57:14 -0700118 START("pdf", PDFTask, RASTERIZE_PDF_PROC);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000119 }
120 }
121#undef START
122}
123
124static void kick_off_benches(const SkTDArray<BenchRegistry::Factory>& benches,
125 const SkTArray<SkString>& configs,
126 DM::Reporter* reporter,
127 DM::TaskRunner* tasks) {
128#define START(name, type, ...) \
129 if (lowercase(configs[j]).equals(name)) { \
130 tasks->add(SkNEW_ARGS(DM::type, (name, reporter, tasks, benches[i], ## __VA_ARGS__))); \
131 }
132 for (int i = 0; i < benches.count(); i++) {
133 for (int j = 0; j < configs.count(); j++) {
134 START("nonrendering", NonRenderingBenchTask);
135 START("565", CpuBenchTask, kRGB_565_SkColorType);
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +0000136 START("8888", CpuBenchTask, kN32_SkColorType);
rmistry05ead8a2014-06-23 06:13:46 -0700137 START("gpu", GpuBenchTask, native, 0);
138 START("msaa4", GpuBenchTask, native, 4);
139 START("msaa16", GpuBenchTask, native, 16);
140 START("nvprmsaa4", GpuBenchTask, nvpr, 4);
141 START("nvprmsaa16", GpuBenchTask, nvpr, 16);
142 START("gpunull", GpuBenchTask, null, 0);
143 START("gpudebug", GpuBenchTask, debug, 0);
144 START("angle", GpuBenchTask, angle, 0);
145 START("mesa", GpuBenchTask, mesa, 0);
mtklein@google.comd36522d2013-10-16 13:02:15 +0000146 }
147 }
148#undef START
149}
150
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000151static void kick_off_tests(const SkTDArray<TestRegistry::Factory>& tests,
152 DM::Reporter* reporter,
153 DM::TaskRunner* tasks) {
154 for (int i = 0; i < tests.count(); i++) {
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +0000155 SkAutoTDelete<Test> test(tests[i](NULL));
156 if (test->isGPUTest()) {
157 tasks->add(SkNEW_ARGS(DM::GpuTestTask, (reporter, tasks, tests[i])));
158 } else {
159 tasks->add(SkNEW_ARGS(DM::CpuTestTask, (reporter, tasks, tests[i])));
160 }
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000161 }
162}
163
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000164static void kick_off_skps(DM::Reporter* reporter, DM::TaskRunner* tasks) {
165 if (FLAGS_skps.isEmpty()) {
166 return;
167 }
168
169 SkOSFile::Iter it(FLAGS_skps[0], ".skp");
170 SkString filename;
171 while (it.next(&filename)) {
172 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, filename.c_str())) {
173 continue;
174 }
175
176 const SkString path = SkOSPath::SkPathJoin(FLAGS_skps[0], filename.c_str());
177
178 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path.c_str()));
179 if (stream.get() == NULL) {
180 SkDebugf("Could not read %s.\n", path.c_str());
181 exit(1);
182 }
183 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream.get()));
184 if (pic.get() == NULL) {
185 SkDebugf("Could not read %s as an SkPicture.\n", path.c_str());
186 exit(1);
187 }
188
mtkleind3e474e2014-06-27 12:34:44 -0700189 tasks->add(SkNEW_ARGS(DM::SKPTask, (reporter, tasks, pic, filename)));
190 tasks->add(SkNEW_ARGS(DM::PDFTask, (reporter, tasks, pic, filename,
mtkleine4d3e602014-06-06 09:28:43 -0700191 RASTERIZE_PDF_PROC)));
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000192 }
193}
194
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000195static void report_failures(const SkTArray<SkString>& failures) {
mtklein@google.comd36522d2013-10-16 13:02:15 +0000196 if (failures.count() == 0) {
197 return;
198 }
199
200 SkDebugf("Failures:\n");
201 for (int i = 0; i < failures.count(); i++) {
202 SkDebugf(" %s\n", failures[i].c_str());
203 }
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000204 SkDebugf("%d failures.\n", failures.count());
mtklein@google.comd36522d2013-10-16 13:02:15 +0000205}
206
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000207template <typename T, typename Registry>
208static void append_matching_factories(Registry* head, SkTDArray<typename Registry::Factory>* out) {
209 for (const Registry* reg = head; reg != NULL; reg = reg->next()) {
210 SkAutoTDelete<T> forName(reg->factory()(NULL));
211 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, forName->getName())) {
212 *out->append() = reg->factory();
213 }
214 }
215}
216
commit-bot@chromium.org846872f2013-10-16 18:21:03 +0000217int tool_main(int argc, char** argv);
218int tool_main(int argc, char** argv) {
mtklein30e6e2a2014-06-18 11:44:15 -0700219 SetupCrashHandler();
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000220 SkAutoGraphics ag;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000221 SkCommandLineFlags::Parse(argc, argv);
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +0000222
223 if (FLAGS_dryRun) {
224 FLAGS_verbose = true;
225 }
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000226#if SK_ENABLE_INST_COUNT
227 gPrintInstCount = FLAGS_leaks;
228#endif
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000229
mtklein@google.comd36522d2013-10-16 13:02:15 +0000230 SkTArray<SkString> configs;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000231 for (int i = 0; i < FLAGS_config.count(); i++) {
232 SkStrSplit(FLAGS_config[i], ", ", &configs);
233 }
234
mtklein@google.comd36522d2013-10-16 13:02:15 +0000235 SkTDArray<GMRegistry::Factory> gms;
commit-bot@chromium.org99589af2013-12-10 14:53:16 +0000236 SkAutoTDelete<DM::Expectations> expectations(SkNEW(DM::NoExpectations));
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000237 if (FLAGS_gms) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000238 append_matching_factories<GM>(GMRegistry::Head(), &gms);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000239
240 if (FLAGS_expectations.count() > 0) {
241 const char* path = FLAGS_expectations[0];
242 if (sk_isdir(path)) {
243 expectations.reset(SkNEW_ARGS(DM::WriteTask::Expectations, (path)));
244 } else {
245 expectations.reset(SkNEW_ARGS(DM::JsonExpectations, (path)));
246 }
commit-bot@chromium.org99589af2013-12-10 14:53:16 +0000247 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000248 }
249
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000250 SkTDArray<BenchRegistry::Factory> benches;
251 if (FLAGS_benches) {
tfarinaf168b862014-06-19 12:32:29 -0700252 append_matching_factories<Benchmark>(BenchRegistry::Head(), &benches);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000253 }
254
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000255 SkTDArray<TestRegistry::Factory> tests;
256 if (FLAGS_tests) {
257 append_matching_factories<Test>(TestRegistry::Head(), &tests);
258 }
259
260 SkDebugf("(%d GMs, %d benches) x %d configs, %d tests\n",
261 gms.count(), benches.count(), configs.count(), tests.count());
mtklein@google.comd36522d2013-10-16 13:02:15 +0000262 DM::Reporter reporter;
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +0000263 DM::TaskRunner tasks(FLAGS_threads, FLAGS_gpuThreads);
rmistry05ead8a2014-06-23 06:13:46 -0700264 kick_off_gms(gms, configs, *expectations, &reporter, &tasks);
265 kick_off_benches(benches, configs, &reporter, &tasks);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000266 kick_off_tests(tests, &reporter, &tasks);
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000267 kick_off_skps(&reporter, &tasks);
mtklein@google.comd36522d2013-10-16 13:02:15 +0000268 tasks.wait();
269
mtklein@google.comd36522d2013-10-16 13:02:15 +0000270 SkDebugf("\n");
mtklein@google.comd36522d2013-10-16 13:02:15 +0000271
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000272 SkTArray<SkString> failures;
273 reporter.getFailures(&failures);
274 report_failures(failures);
275 return failures.count() > 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000276}
commit-bot@chromium.org846872f2013-10-16 18:21:03 +0000277
278#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
279int main(int argc, char** argv) {
280 return tool_main(argc, argv);
281}
282#endif