blob: 003145b92187a92743051a57bd1e5724612d5b2e [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
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000122static void kick_off_skps(DM::Reporter* reporter, DM::TaskRunner* tasks) {
123 if (FLAGS_skps.isEmpty()) {
124 return;
125 }
126
127 SkOSFile::Iter it(FLAGS_skps[0], ".skp");
128 SkString filename;
129 while (it.next(&filename)) {
130 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, filename.c_str())) {
131 continue;
132 }
133
134 const SkString path = SkOSPath::SkPathJoin(FLAGS_skps[0], filename.c_str());
135
136 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path.c_str()));
137 if (stream.get() == NULL) {
138 SkDebugf("Could not read %s.\n", path.c_str());
139 exit(1);
140 }
141 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream.get()));
142 if (pic.get() == NULL) {
143 SkDebugf("Could not read %s as an SkPicture.\n", path.c_str());
144 exit(1);
145 }
146
mtkleind3e474e2014-06-27 12:34:44 -0700147 tasks->add(SkNEW_ARGS(DM::SKPTask, (reporter, tasks, pic, filename)));
148 tasks->add(SkNEW_ARGS(DM::PDFTask, (reporter, tasks, pic, filename,
mtkleine4d3e602014-06-06 09:28:43 -0700149 RASTERIZE_PDF_PROC)));
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000150 }
151}
152
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000153static void report_failures(const SkTArray<SkString>& failures) {
mtklein@google.comd36522d2013-10-16 13:02:15 +0000154 if (failures.count() == 0) {
155 return;
156 }
157
158 SkDebugf("Failures:\n");
159 for (int i = 0; i < failures.count(); i++) {
160 SkDebugf(" %s\n", failures[i].c_str());
161 }
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000162 SkDebugf("%d failures.\n", failures.count());
mtklein@google.comd36522d2013-10-16 13:02:15 +0000163}
164
kkinnunen80549fc2014-06-30 06:36:31 -0700165static GrGLStandard get_gl_standard() {
166 if (FLAGS_gpuAPI.contains(kGpuAPINameGL)) {
167 return kGL_GrGLStandard;
168 }
169 if (FLAGS_gpuAPI.contains(kGpuAPINameGLES)) {
170 return kGLES_GrGLStandard;
171 }
172 return kNone_GrGLStandard;
173}
174
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000175template <typename T, typename Registry>
176static void append_matching_factories(Registry* head, SkTDArray<typename Registry::Factory>* out) {
177 for (const Registry* reg = head; reg != NULL; reg = reg->next()) {
178 SkAutoTDelete<T> forName(reg->factory()(NULL));
179 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, forName->getName())) {
180 *out->append() = reg->factory();
181 }
182 }
183}
184
caryclark17f0b6d2014-07-22 10:15:34 -0700185int dm_main();
186int dm_main() {
mtklein30e6e2a2014-06-18 11:44:15 -0700187 SetupCrashHandler();
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000188 SkAutoGraphics ag;
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +0000189
190 if (FLAGS_dryRun) {
191 FLAGS_verbose = true;
192 }
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000193#if SK_ENABLE_INST_COUNT
194 gPrintInstCount = FLAGS_leaks;
195#endif
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000196
mtklein@google.comd36522d2013-10-16 13:02:15 +0000197 SkTArray<SkString> configs;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000198 for (int i = 0; i < FLAGS_config.count(); i++) {
199 SkStrSplit(FLAGS_config[i], ", ", &configs);
200 }
201
kkinnunen80549fc2014-06-30 06:36:31 -0700202 GrGLStandard gpuAPI = get_gl_standard();
203
mtklein@google.comd36522d2013-10-16 13:02:15 +0000204 SkTDArray<GMRegistry::Factory> gms;
commit-bot@chromium.org99589af2013-12-10 14:53:16 +0000205 SkAutoTDelete<DM::Expectations> expectations(SkNEW(DM::NoExpectations));
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000206 if (FLAGS_gms) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000207 append_matching_factories<GM>(GMRegistry::Head(), &gms);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000208
209 if (FLAGS_expectations.count() > 0) {
210 const char* path = FLAGS_expectations[0];
211 if (sk_isdir(path)) {
212 expectations.reset(SkNEW_ARGS(DM::WriteTask::Expectations, (path)));
213 } else {
214 expectations.reset(SkNEW_ARGS(DM::JsonExpectations, (path)));
215 }
commit-bot@chromium.org99589af2013-12-10 14:53:16 +0000216 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000217 }
218
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000219 SkTDArray<TestRegistry::Factory> tests;
220 if (FLAGS_tests) {
221 append_matching_factories<Test>(TestRegistry::Head(), &tests);
222 }
223
mtklein103ae712014-07-16 14:29:53 -0700224 SkDebugf("%d GMs x %d configs, %d tests\n",
225 gms.count(), configs.count(), tests.count());
mtklein@google.comd36522d2013-10-16 13:02:15 +0000226 DM::Reporter reporter;
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +0000227 DM::TaskRunner tasks(FLAGS_threads, FLAGS_gpuThreads);
kkinnunen80549fc2014-06-30 06:36:31 -0700228 kick_off_gms(gms, configs, gpuAPI, *expectations, &reporter, &tasks);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000229 kick_off_tests(tests, &reporter, &tasks);
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000230 kick_off_skps(&reporter, &tasks);
mtklein@google.comd36522d2013-10-16 13:02:15 +0000231 tasks.wait();
232
mtklein@google.comd36522d2013-10-16 13:02:15 +0000233 SkDebugf("\n");
mtklein@google.comd36522d2013-10-16 13:02:15 +0000234
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000235 SkTArray<SkString> failures;
236 reporter.getFailures(&failures);
237 report_failures(failures);
238 return failures.count() > 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000239}
commit-bot@chromium.org846872f2013-10-16 18:21:03 +0000240
241#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
242int main(int argc, char** argv) {
caryclark17f0b6d2014-07-22 10:15:34 -0700243 SkCommandLineFlags::Parse(argc, argv);
244 return dm_main();
commit-bot@chromium.org846872f2013-10-16 18:21:03 +0000245}
246#endif