blob: 1b7c1d84724c5a724e3180256761bc0e2329b08c [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"
mtklein30bf3e22014-06-03 13:57:14 -070017#include "DMPDFTask.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000018#include "DMReporter.h"
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +000019#include "DMSKPTask.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000020#include "DMTask.h"
21#include "DMTaskRunner.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000022#include "DMTestTask.h"
commit-bot@chromium.org99589af2013-12-10 14:53:16 +000023#include "DMWriteTask.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000024
mtklein30bf3e22014-06-03 13:57:14 -070025#ifdef SK_BUILD_POPPLER
26# include "SkPDFRasterizer.h"
27# define RASTERIZE_PDF_PROC SkPopplerRasterizePDF
28#else
29# define RASTERIZE_PDF_PROC NULL
30#endif
31
commit-bot@chromium.org120c9992014-05-16 18:11:51 +000032#include <ctype.h>
mtklein@google.comd36522d2013-10-16 13:02:15 +000033
34using skiagm::GM;
35using skiagm::GMRegistry;
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000036using skiatest::Test;
37using skiatest::TestRegistry;
mtklein@google.comd36522d2013-10-16 13:02:15 +000038
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000039DEFINE_int32(threads, -1, "Threads for CPU work. Default NUM_CPUS.");
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000040DEFINE_int32(gpuThreads, 1, "Threads for GPU work.");
commit-bot@chromium.orga267d412014-05-16 18:27:11 +000041#ifdef SK_BUILD_JSON_WRITER
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.orga267d412014-05-16 18:27:11 +000046#else
47DEFINE_string2(expectations, r, "",
48 "If a directory, compare generated images against images under this path. "
49);
50#endif
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000051DEFINE_string2(resources, i, "resources", "Path to resources directory.");
mtklein@google.comd36522d2013-10-16 13:02:15 +000052DEFINE_string(match, "", "[~][^]substring[$] [...] of GM name to run.\n"
53 "Multiple matches may be separated by spaces.\n"
54 "~ causes a matching GM to always be skipped\n"
55 "^ requires the start of the GM to match\n"
56 "$ requires the end of the GM to match\n"
57 "^ and $ requires an exact match\n"
58 "If a GM does not match any list entry,\n"
59 "it is skipped unless some list entry starts with ~");
mtklein30bf3e22014-06-03 13:57:14 -070060DEFINE_string(config, "565 8888 pdf gpu nonrendering",
61 "Options: 565 8888 pdf gpu nonrendering msaa4 msaa16 nvprmsaa4 nvprmsaa16 "
62 "gpunull gpudebug angle mesa");
63DEFINE_bool(dryRun, false,
64 "Just print the tests that would be run, without actually running them.");
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000065DEFINE_bool(leaks, false, "Print leaked instance-counted objects at exit?");
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +000066DEFINE_string(skps, "", "Directory to read skps from.");
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000067
68DEFINE_bool(gms, true, "Run GMs?");
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000069DEFINE_bool(benches, true, "Run benches? Does not run GMs-as-benches.");
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000070DEFINE_bool(tests, true, "Run tests?");
mtklein@google.comd36522d2013-10-16 13:02:15 +000071
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +000072DECLARE_bool(verbose);
73
mtklein@google.comd36522d2013-10-16 13:02:15 +000074__SK_FORCE_IMAGE_DECODER_LINKING;
75
mtklein@google.comd36522d2013-10-16 13:02:15 +000076// "FooBar" -> "foobar". Obviously, ASCII only.
77static SkString lowercase(SkString s) {
78 for (size_t i = 0; i < s.size(); i++) {
79 s[i] = tolower(s[i]);
80 }
81 return s;
82}
83
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000084static const GrContextFactory::GLContextType native = GrContextFactory::kNative_GLContextType;
commit-bot@chromium.orgb6401862014-03-12 14:46:31 +000085static const GrContextFactory::GLContextType nvpr = GrContextFactory::kNVPR_GLContextType;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000086static const GrContextFactory::GLContextType null = GrContextFactory::kNull_GLContextType;
87static const GrContextFactory::GLContextType debug = GrContextFactory::kDebug_GLContextType;
88static const GrContextFactory::GLContextType angle =
89#if SK_ANGLE
90GrContextFactory::kANGLE_GLContextType;
91#else
92native;
93#endif
94static const GrContextFactory::GLContextType mesa =
95#if SK_MESA
bsalomon@google.com9dccafa2014-05-02 14:43:12 +000096GrContextFactory::kMESA_GLContextType;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000097#else
98native;
99#endif
100
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000101static void kick_off_gms(const SkTDArray<GMRegistry::Factory>& gms,
102 const SkTArray<SkString>& configs,
103 const DM::Expectations& expectations,
104 DM::Reporter* reporter,
105 DM::TaskRunner* tasks) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000106#define START(name, type, ...) \
107 if (lowercase(configs[j]).equals(name)) { \
108 tasks->add(SkNEW_ARGS(DM::type, \
109 (name, reporter, tasks, expectations, gms[i], ## __VA_ARGS__))); \
mtklein@google.comd36522d2013-10-16 13:02:15 +0000110 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000111 for (int i = 0; i < gms.count(); i++) {
mtklein@google.comd36522d2013-10-16 13:02:15 +0000112 for (int j = 0; j < configs.count(); j++) {
mtklein30bf3e22014-06-03 13:57:14 -0700113 START("565", CpuGMTask, kRGB_565_SkColorType);
114 START("8888", CpuGMTask, kN32_SkColorType);
115 START("gpu", GpuGMTask, native, 0);
116 START("msaa4", GpuGMTask, native, 4);
117 START("msaa16", GpuGMTask, native, 16);
118 START("nvprmsaa4", GpuGMTask, nvpr, 4);
commit-bot@chromium.orgb6401862014-03-12 14:46:31 +0000119 START("nvprmsaa16", GpuGMTask, nvpr, 16);
mtklein30bf3e22014-06-03 13:57:14 -0700120 START("gpunull", GpuGMTask, null, 0);
121 START("gpudebug", GpuGMTask, debug, 0);
122 START("angle", GpuGMTask, angle, 0);
123 START("mesa", GpuGMTask, mesa, 0);
124 START("pdf", PDFTask, RASTERIZE_PDF_PROC);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000125 }
126 }
127#undef START
128}
129
130static void kick_off_benches(const SkTDArray<BenchRegistry::Factory>& benches,
131 const SkTArray<SkString>& configs,
132 DM::Reporter* reporter,
133 DM::TaskRunner* tasks) {
134#define START(name, type, ...) \
135 if (lowercase(configs[j]).equals(name)) { \
136 tasks->add(SkNEW_ARGS(DM::type, (name, reporter, tasks, benches[i], ## __VA_ARGS__))); \
137 }
138 for (int i = 0; i < benches.count(); i++) {
139 for (int j = 0; j < configs.count(); j++) {
140 START("nonrendering", NonRenderingBenchTask);
141 START("565", CpuBenchTask, kRGB_565_SkColorType);
commit-bot@chromium.org28fcae22014-04-11 17:15:40 +0000142 START("8888", CpuBenchTask, kN32_SkColorType);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000143 START("gpu", GpuBenchTask, native, 0);
144 START("msaa4", GpuBenchTask, native, 4);
145 START("msaa16", GpuBenchTask, native, 16);
commit-bot@chromium.orgb6401862014-03-12 14:46:31 +0000146 START("nvprmsaa4", GpuBenchTask, nvpr, 4);
147 START("nvprmsaa16", GpuBenchTask, nvpr, 16);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000148 START("gpunull", GpuBenchTask, null, 0);
149 START("gpudebug", GpuBenchTask, debug, 0);
150 START("angle", GpuBenchTask, angle, 0);
151 START("mesa", GpuBenchTask, mesa, 0);
mtklein@google.comd36522d2013-10-16 13:02:15 +0000152 }
153 }
154#undef START
155}
156
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000157static void kick_off_tests(const SkTDArray<TestRegistry::Factory>& tests,
158 DM::Reporter* reporter,
159 DM::TaskRunner* tasks) {
160 for (int i = 0; i < tests.count(); i++) {
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +0000161 SkAutoTDelete<Test> test(tests[i](NULL));
162 if (test->isGPUTest()) {
163 tasks->add(SkNEW_ARGS(DM::GpuTestTask, (reporter, tasks, tests[i])));
164 } else {
165 tasks->add(SkNEW_ARGS(DM::CpuTestTask, (reporter, tasks, tests[i])));
166 }
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000167 }
168}
169
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000170static void kick_off_skps(DM::Reporter* reporter, DM::TaskRunner* tasks) {
171 if (FLAGS_skps.isEmpty()) {
172 return;
173 }
174
175 SkOSFile::Iter it(FLAGS_skps[0], ".skp");
176 SkString filename;
177 while (it.next(&filename)) {
178 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, filename.c_str())) {
179 continue;
180 }
181
182 const SkString path = SkOSPath::SkPathJoin(FLAGS_skps[0], filename.c_str());
183
184 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path.c_str()));
185 if (stream.get() == NULL) {
186 SkDebugf("Could not read %s.\n", path.c_str());
187 exit(1);
188 }
189 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream.get()));
190 if (pic.get() == NULL) {
191 SkDebugf("Could not read %s as an SkPicture.\n", path.c_str());
192 exit(1);
193 }
194
195 tasks->add(SkNEW_ARGS(DM::SKPTask, (reporter, tasks, pic.detach(), filename)));
196 }
197}
198
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000199static void report_failures(const SkTArray<SkString>& failures) {
mtklein@google.comd36522d2013-10-16 13:02:15 +0000200 if (failures.count() == 0) {
201 return;
202 }
203
204 SkDebugf("Failures:\n");
205 for (int i = 0; i < failures.count(); i++) {
206 SkDebugf(" %s\n", failures[i].c_str());
207 }
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000208 SkDebugf("%d failures.\n", failures.count());
mtklein@google.comd36522d2013-10-16 13:02:15 +0000209}
210
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000211template <typename T, typename Registry>
212static void append_matching_factories(Registry* head, SkTDArray<typename Registry::Factory>* out) {
213 for (const Registry* reg = head; reg != NULL; reg = reg->next()) {
214 SkAutoTDelete<T> forName(reg->factory()(NULL));
215 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, forName->getName())) {
216 *out->append() = reg->factory();
217 }
218 }
219}
220
commit-bot@chromium.org846872f2013-10-16 18:21:03 +0000221int tool_main(int argc, char** argv);
222int tool_main(int argc, char** argv) {
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000223 SkAutoGraphics ag;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000224 SkCommandLineFlags::Parse(argc, argv);
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +0000225
226 if (FLAGS_dryRun) {
227 FLAGS_verbose = true;
228 }
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000229#if SK_ENABLE_INST_COUNT
230 gPrintInstCount = FLAGS_leaks;
231#endif
mtklein@google.comd36522d2013-10-16 13:02:15 +0000232 GM::SetResourcePath(FLAGS_resources[0]);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000233 SkBenchmark::SetResourcePath(FLAGS_resources[0]);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000234 Test::SetResourcePath(FLAGS_resources[0]);
235
mtklein@google.comd36522d2013-10-16 13:02:15 +0000236 SkTArray<SkString> configs;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000237 for (int i = 0; i < FLAGS_config.count(); i++) {
238 SkStrSplit(FLAGS_config[i], ", ", &configs);
239 }
240
mtklein@google.comd36522d2013-10-16 13:02:15 +0000241 SkTDArray<GMRegistry::Factory> gms;
commit-bot@chromium.org99589af2013-12-10 14:53:16 +0000242 SkAutoTDelete<DM::Expectations> expectations(SkNEW(DM::NoExpectations));
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000243 if (FLAGS_gms) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000244 append_matching_factories<GM>(GMRegistry::Head(), &gms);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000245
246 if (FLAGS_expectations.count() > 0) {
247 const char* path = FLAGS_expectations[0];
248 if (sk_isdir(path)) {
249 expectations.reset(SkNEW_ARGS(DM::WriteTask::Expectations, (path)));
250 } else {
commit-bot@chromium.org120c9992014-05-16 18:11:51 +0000251#ifdef SK_BUILD_JSON_WRITER
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000252 expectations.reset(SkNEW_ARGS(DM::JsonExpectations, (path)));
commit-bot@chromium.org120c9992014-05-16 18:11:51 +0000253#endif
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000254 }
commit-bot@chromium.org99589af2013-12-10 14:53:16 +0000255 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000256 }
257
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000258 SkTDArray<BenchRegistry::Factory> benches;
259 if (FLAGS_benches) {
260 append_matching_factories<SkBenchmark>(BenchRegistry::Head(), &benches);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000261 }
262
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000263 SkTDArray<TestRegistry::Factory> tests;
264 if (FLAGS_tests) {
265 append_matching_factories<Test>(TestRegistry::Head(), &tests);
266 }
267
268 SkDebugf("(%d GMs, %d benches) x %d configs, %d tests\n",
269 gms.count(), benches.count(), configs.count(), tests.count());
mtklein@google.comd36522d2013-10-16 13:02:15 +0000270 DM::Reporter reporter;
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +0000271 DM::TaskRunner tasks(FLAGS_threads, FLAGS_gpuThreads);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000272 kick_off_gms(gms, configs, *expectations, &reporter, &tasks);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000273 kick_off_benches(benches, configs, &reporter, &tasks);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000274 kick_off_tests(tests, &reporter, &tasks);
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000275 kick_off_skps(&reporter, &tasks);
mtklein@google.comd36522d2013-10-16 13:02:15 +0000276 tasks.wait();
277
mtklein@google.comd36522d2013-10-16 13:02:15 +0000278 SkDebugf("\n");
mtklein@google.comd36522d2013-10-16 13:02:15 +0000279
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000280 SkTArray<SkString> failures;
281 reporter.getFailures(&failures);
282 report_failures(failures);
283 return failures.count() > 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000284}
commit-bot@chromium.org846872f2013-10-16 18:21:03 +0000285
286#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
287int main(int argc, char** argv) {
288 return tool_main(argc, argv);
289}
290#endif