blob: 0077d5ac1b2a18415509954c342a455616b82e38 [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 "CrashHandler.h"
caryclark17f0b6d2014-07-22 10:15:34 -07005#include "SkCommonFlags.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +00006#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.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"
mtklein30bf3e22014-06-03 13:57:14 -070016#include "DMPDFTask.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
mtklein30bf3e22014-06-03 13:57:14 -070024#ifdef SK_BUILD_POPPLER
25# include "SkPDFRasterizer.h"
26# define RASTERIZE_PDF_PROC SkPopplerRasterizePDF
27#else
28# define RASTERIZE_PDF_PROC NULL
29#endif
30
commit-bot@chromium.org120c9992014-05-16 18:11:51 +000031#include <ctype.h>
mtklein@google.comd36522d2013-10-16 13:02:15 +000032
33using skiagm::GM;
34using skiagm::GMRegistry;
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000035using skiatest::Test;
36using skiatest::TestRegistry;
mtklein@google.comd36522d2013-10-16 13:02:15 +000037
kkinnunen80549fc2014-06-30 06:36:31 -070038static const char kGpuAPINameGL[] = "gl";
39static const char kGpuAPINameGLES[] = "gles";
40
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);
caryclark17f0b6d2014-07-22 10:15:34 -070046
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +000047DEFINE_string(skps, "", "Directory to read skps from.");
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000048
49DEFINE_bool(gms, true, "Run GMs?");
50DEFINE_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
bsalomon@google.com9dccafa2014-05-02 14:43:12 +000074GrContextFactory::kMESA_GLContextType;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000075#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,
kkinnunen80549fc2014-06-30 06:36:31 -070081 GrGLStandard gpuAPI,
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000082 const DM::Expectations& expectations,
83 DM::Reporter* reporter,
84 DM::TaskRunner* tasks) {
mtkleine4d3e602014-06-06 09:28:43 -070085#define START(name, type, ...) \
86 if (lowercase(configs[j]).equals(name)) { \
87 tasks->add(SkNEW_ARGS(DM::type, (name, reporter, tasks, 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++) {
kkinnunen80549fc2014-06-30 06:36:31 -070091
mtkleine4d3e602014-06-06 09:28:43 -070092 START("565", CpuGMTask, expectations, kRGB_565_SkColorType);
93 START("8888", CpuGMTask, expectations, kN32_SkColorType);
kkinnunen80549fc2014-06-30 06:36:31 -070094 START("gpu", GpuGMTask, expectations, native, gpuAPI, 0);
95 START("msaa4", GpuGMTask, expectations, native, gpuAPI, 4);
96 START("msaa16", GpuGMTask, expectations, native, gpuAPI, 16);
97 START("nvprmsaa4", GpuGMTask, expectations, nvpr, gpuAPI, 4);
98 START("nvprmsaa16", GpuGMTask, expectations, nvpr, gpuAPI, 16);
99 START("gpunull", GpuGMTask, expectations, null, gpuAPI, 0);
100 START("gpudebug", GpuGMTask, expectations, debug, gpuAPI, 0);
101 START("angle", GpuGMTask, expectations, angle, gpuAPI, 0);
102 START("mesa", GpuGMTask, expectations, mesa, gpuAPI, 0);
mtklein30bf3e22014-06-03 13:57:14 -0700103 START("pdf", PDFTask, RASTERIZE_PDF_PROC);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000104 }
105 }
106#undef START
107}
108
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000109static void kick_off_tests(const SkTDArray<TestRegistry::Factory>& tests,
110 DM::Reporter* reporter,
111 DM::TaskRunner* tasks) {
112 for (int i = 0; i < tests.count(); i++) {
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +0000113 SkAutoTDelete<Test> test(tests[i](NULL));
114 if (test->isGPUTest()) {
115 tasks->add(SkNEW_ARGS(DM::GpuTestTask, (reporter, tasks, tests[i])));
116 } else {
117 tasks->add(SkNEW_ARGS(DM::CpuTestTask, (reporter, tasks, tests[i])));
118 }
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000119 }
120}
121
halcanarya98683b2014-07-28 07:21:24 -0700122static void find_skps(SkTArray<SkString>* skps) {
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000123 if (FLAGS_skps.isEmpty()) {
124 return;
125 }
126
127 SkOSFile::Iter it(FLAGS_skps[0], ".skp");
128 SkString filename;
129 while (it.next(&filename)) {
halcanarya98683b2014-07-28 07:21:24 -0700130 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, filename.c_str())) {
131 skps->push_back(
132 SkOSPath::SkPathJoin(FLAGS_skps[0], filename.c_str()));
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000133 }
halcanarya98683b2014-07-28 07:21:24 -0700134 }
135}
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000136
halcanarya98683b2014-07-28 07:21:24 -0700137static void kick_off_skps(const SkTArray<SkString>& skps,
138 DM::Reporter* reporter, DM::TaskRunner* tasks) {
139 for (int i = 0; i < skps.count(); ++i) {
140 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(skps[i].c_str()));
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000141 if (stream.get() == NULL) {
halcanarya98683b2014-07-28 07:21:24 -0700142 SkDebugf("Could not read %s.\n", skps[i].c_str());
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000143 exit(1);
144 }
145 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream.get()));
146 if (pic.get() == NULL) {
halcanarya98683b2014-07-28 07:21:24 -0700147 SkDebugf("Could not read %s as an SkPicture.\n", skps[i].c_str());
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000148 exit(1);
149 }
150
halcanarya98683b2014-07-28 07:21:24 -0700151 SkString filename = SkOSPath::SkBasename(skps[i].c_str());
mtkleind3e474e2014-06-27 12:34:44 -0700152 tasks->add(SkNEW_ARGS(DM::SKPTask, (reporter, tasks, pic, filename)));
153 tasks->add(SkNEW_ARGS(DM::PDFTask, (reporter, tasks, pic, filename,
mtkleine4d3e602014-06-06 09:28:43 -0700154 RASTERIZE_PDF_PROC)));
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000155 }
156}
157
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000158static void report_failures(const SkTArray<SkString>& failures) {
mtklein@google.comd36522d2013-10-16 13:02:15 +0000159 if (failures.count() == 0) {
160 return;
161 }
162
163 SkDebugf("Failures:\n");
164 for (int i = 0; i < failures.count(); i++) {
165 SkDebugf(" %s\n", failures[i].c_str());
166 }
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000167 SkDebugf("%d failures.\n", failures.count());
mtklein@google.comd36522d2013-10-16 13:02:15 +0000168}
169
kkinnunen80549fc2014-06-30 06:36:31 -0700170static GrGLStandard get_gl_standard() {
171 if (FLAGS_gpuAPI.contains(kGpuAPINameGL)) {
172 return kGL_GrGLStandard;
173 }
174 if (FLAGS_gpuAPI.contains(kGpuAPINameGLES)) {
175 return kGLES_GrGLStandard;
176 }
177 return kNone_GrGLStandard;
178}
179
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000180template <typename T, typename Registry>
181static void append_matching_factories(Registry* head, SkTDArray<typename Registry::Factory>* out) {
182 for (const Registry* reg = head; reg != NULL; reg = reg->next()) {
183 SkAutoTDelete<T> forName(reg->factory()(NULL));
184 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, forName->getName())) {
185 *out->append() = reg->factory();
186 }
187 }
188}
189
caryclark17f0b6d2014-07-22 10:15:34 -0700190int dm_main();
191int dm_main() {
mtklein30e6e2a2014-06-18 11:44:15 -0700192 SetupCrashHandler();
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000193 SkAutoGraphics ag;
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +0000194
195 if (FLAGS_dryRun) {
196 FLAGS_verbose = true;
197 }
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000198#if SK_ENABLE_INST_COUNT
199 gPrintInstCount = FLAGS_leaks;
200#endif
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000201
mtklein@google.comd36522d2013-10-16 13:02:15 +0000202 SkTArray<SkString> configs;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000203 for (int i = 0; i < FLAGS_config.count(); i++) {
204 SkStrSplit(FLAGS_config[i], ", ", &configs);
205 }
206
kkinnunen80549fc2014-06-30 06:36:31 -0700207 GrGLStandard gpuAPI = get_gl_standard();
208
mtklein@google.comd36522d2013-10-16 13:02:15 +0000209 SkTDArray<GMRegistry::Factory> gms;
commit-bot@chromium.org99589af2013-12-10 14:53:16 +0000210 SkAutoTDelete<DM::Expectations> expectations(SkNEW(DM::NoExpectations));
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000211 if (FLAGS_gms) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000212 append_matching_factories<GM>(GMRegistry::Head(), &gms);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000213
214 if (FLAGS_expectations.count() > 0) {
215 const char* path = FLAGS_expectations[0];
216 if (sk_isdir(path)) {
217 expectations.reset(SkNEW_ARGS(DM::WriteTask::Expectations, (path)));
218 } else {
219 expectations.reset(SkNEW_ARGS(DM::JsonExpectations, (path)));
220 }
commit-bot@chromium.org99589af2013-12-10 14:53:16 +0000221 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000222 }
223
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000224 SkTDArray<TestRegistry::Factory> tests;
225 if (FLAGS_tests) {
226 append_matching_factories<Test>(TestRegistry::Head(), &tests);
227 }
228
halcanarya98683b2014-07-28 07:21:24 -0700229 SkTArray<SkString> skps;
230 find_skps(&skps);
231
232 SkDebugf("%d GMs x %d configs, %d tests, %d pictures\n",
233 gms.count(), configs.count(), tests.count(), skps.count());
mtklein@google.comd36522d2013-10-16 13:02:15 +0000234 DM::Reporter reporter;
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +0000235 DM::TaskRunner tasks(FLAGS_threads, FLAGS_gpuThreads);
kkinnunen80549fc2014-06-30 06:36:31 -0700236 kick_off_gms(gms, configs, gpuAPI, *expectations, &reporter, &tasks);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000237 kick_off_tests(tests, &reporter, &tasks);
halcanarya98683b2014-07-28 07:21:24 -0700238 kick_off_skps(skps, &reporter, &tasks);
mtklein@google.comd36522d2013-10-16 13:02:15 +0000239 tasks.wait();
240
mtklein@google.comd36522d2013-10-16 13:02:15 +0000241 SkDebugf("\n");
mtklein@google.comd36522d2013-10-16 13:02:15 +0000242
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000243 SkTArray<SkString> failures;
244 reporter.getFailures(&failures);
245 report_failures(failures);
246 return failures.count() > 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000247}
commit-bot@chromium.org846872f2013-10-16 18:21:03 +0000248
249#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
250int main(int argc, char** argv) {
caryclark17f0b6d2014-07-22 10:15:34 -0700251 SkCommandLineFlags::Parse(argc, argv);
252 return dm_main();
commit-bot@chromium.org846872f2013-10-16 18:21:03 +0000253}
254#endif