blob: c71450c23fd96681d0cd1a0a9f60486fc1ee0112 [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"
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.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.org0dc5bd12014-02-26 16:31:22 +000041DEFINE_int32(threads, -1, "Threads for CPU work. Default NUM_CPUS.");
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000042DEFINE_int32(gpuThreads, 1, "Threads for GPU work.");
kkinnunen80549fc2014-06-30 06:36:31 -070043DEFINE_string(gpuAPI, "", "Force use of specific gpu API. Using \"gl\" "
44 "forces OpenGL API. Using \"gles\" forces OpenGL ES API. "
45 "Defaults to empty string, which selects the API native to the "
46 "system.");
commit-bot@chromium.org99589af2013-12-10 14:53:16 +000047DEFINE_string2(expectations, r, "",
48 "If a directory, compare generated images against images under this path. "
commit-bot@chromium.org120c9992014-05-16 18:11:51 +000049 "If a file, compare generated images against JSON expectations at this path."
commit-bot@chromium.org120c9992014-05-16 18:11:51 +000050);
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?");
69DEFINE_bool(tests, true, "Run tests?");
mtklein@google.comd36522d2013-10-16 13:02:15 +000070
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +000071DECLARE_bool(verbose);
72
mtklein@google.comd36522d2013-10-16 13:02:15 +000073__SK_FORCE_IMAGE_DECODER_LINKING;
74
mtklein@google.comd36522d2013-10-16 13:02:15 +000075// "FooBar" -> "foobar". Obviously, ASCII only.
76static SkString lowercase(SkString s) {
77 for (size_t i = 0; i < s.size(); i++) {
78 s[i] = tolower(s[i]);
79 }
80 return s;
81}
82
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000083static const GrContextFactory::GLContextType native = GrContextFactory::kNative_GLContextType;
commit-bot@chromium.orgb6401862014-03-12 14:46:31 +000084static const GrContextFactory::GLContextType nvpr = GrContextFactory::kNVPR_GLContextType;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000085static const GrContextFactory::GLContextType null = GrContextFactory::kNull_GLContextType;
86static const GrContextFactory::GLContextType debug = GrContextFactory::kDebug_GLContextType;
87static const GrContextFactory::GLContextType angle =
88#if SK_ANGLE
89GrContextFactory::kANGLE_GLContextType;
90#else
91native;
92#endif
93static const GrContextFactory::GLContextType mesa =
94#if SK_MESA
bsalomon@google.com9dccafa2014-05-02 14:43:12 +000095GrContextFactory::kMESA_GLContextType;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000096#else
97native;
98#endif
99
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000100static void kick_off_gms(const SkTDArray<GMRegistry::Factory>& gms,
101 const SkTArray<SkString>& configs,
kkinnunen80549fc2014-06-30 06:36:31 -0700102 GrGLStandard gpuAPI,
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000103 const DM::Expectations& expectations,
104 DM::Reporter* reporter,
105 DM::TaskRunner* tasks) {
mtkleine4d3e602014-06-06 09:28:43 -0700106#define START(name, type, ...) \
107 if (lowercase(configs[j]).equals(name)) { \
108 tasks->add(SkNEW_ARGS(DM::type, (name, reporter, tasks, gms[i], ## __VA_ARGS__))); \
mtklein@google.comd36522d2013-10-16 13:02:15 +0000109 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000110 for (int i = 0; i < gms.count(); i++) {
mtklein@google.comd36522d2013-10-16 13:02:15 +0000111 for (int j = 0; j < configs.count(); j++) {
kkinnunen80549fc2014-06-30 06:36:31 -0700112
mtkleine4d3e602014-06-06 09:28:43 -0700113 START("565", CpuGMTask, expectations, kRGB_565_SkColorType);
114 START("8888", CpuGMTask, expectations, kN32_SkColorType);
kkinnunen80549fc2014-06-30 06:36:31 -0700115 START("gpu", GpuGMTask, expectations, native, gpuAPI, 0);
116 START("msaa4", GpuGMTask, expectations, native, gpuAPI, 4);
117 START("msaa16", GpuGMTask, expectations, native, gpuAPI, 16);
118 START("nvprmsaa4", GpuGMTask, expectations, nvpr, gpuAPI, 4);
119 START("nvprmsaa16", GpuGMTask, expectations, nvpr, gpuAPI, 16);
120 START("gpunull", GpuGMTask, expectations, null, gpuAPI, 0);
121 START("gpudebug", GpuGMTask, expectations, debug, gpuAPI, 0);
122 START("angle", GpuGMTask, expectations, angle, gpuAPI, 0);
123 START("mesa", GpuGMTask, expectations, mesa, gpuAPI, 0);
mtklein30bf3e22014-06-03 13:57:14 -0700124 START("pdf", PDFTask, RASTERIZE_PDF_PROC);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000125 }
126 }
127#undef START
128}
129
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000130static void kick_off_tests(const SkTDArray<TestRegistry::Factory>& tests,
131 DM::Reporter* reporter,
132 DM::TaskRunner* tasks) {
133 for (int i = 0; i < tests.count(); i++) {
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +0000134 SkAutoTDelete<Test> test(tests[i](NULL));
135 if (test->isGPUTest()) {
136 tasks->add(SkNEW_ARGS(DM::GpuTestTask, (reporter, tasks, tests[i])));
137 } else {
138 tasks->add(SkNEW_ARGS(DM::CpuTestTask, (reporter, tasks, tests[i])));
139 }
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000140 }
141}
142
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000143static void kick_off_skps(DM::Reporter* reporter, DM::TaskRunner* tasks) {
144 if (FLAGS_skps.isEmpty()) {
145 return;
146 }
147
148 SkOSFile::Iter it(FLAGS_skps[0], ".skp");
149 SkString filename;
150 while (it.next(&filename)) {
151 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, filename.c_str())) {
152 continue;
153 }
154
155 const SkString path = SkOSPath::SkPathJoin(FLAGS_skps[0], filename.c_str());
156
157 SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path.c_str()));
158 if (stream.get() == NULL) {
159 SkDebugf("Could not read %s.\n", path.c_str());
160 exit(1);
161 }
162 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream.get()));
163 if (pic.get() == NULL) {
164 SkDebugf("Could not read %s as an SkPicture.\n", path.c_str());
165 exit(1);
166 }
167
mtkleind3e474e2014-06-27 12:34:44 -0700168 tasks->add(SkNEW_ARGS(DM::SKPTask, (reporter, tasks, pic, filename)));
169 tasks->add(SkNEW_ARGS(DM::PDFTask, (reporter, tasks, pic, filename,
mtkleine4d3e602014-06-06 09:28:43 -0700170 RASTERIZE_PDF_PROC)));
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000171 }
172}
173
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000174static void report_failures(const SkTArray<SkString>& failures) {
mtklein@google.comd36522d2013-10-16 13:02:15 +0000175 if (failures.count() == 0) {
176 return;
177 }
178
179 SkDebugf("Failures:\n");
180 for (int i = 0; i < failures.count(); i++) {
181 SkDebugf(" %s\n", failures[i].c_str());
182 }
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000183 SkDebugf("%d failures.\n", failures.count());
mtklein@google.comd36522d2013-10-16 13:02:15 +0000184}
185
kkinnunen80549fc2014-06-30 06:36:31 -0700186static GrGLStandard get_gl_standard() {
187 if (FLAGS_gpuAPI.contains(kGpuAPINameGL)) {
188 return kGL_GrGLStandard;
189 }
190 if (FLAGS_gpuAPI.contains(kGpuAPINameGLES)) {
191 return kGLES_GrGLStandard;
192 }
193 return kNone_GrGLStandard;
194}
195
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000196template <typename T, typename Registry>
197static void append_matching_factories(Registry* head, SkTDArray<typename Registry::Factory>* out) {
198 for (const Registry* reg = head; reg != NULL; reg = reg->next()) {
199 SkAutoTDelete<T> forName(reg->factory()(NULL));
200 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, forName->getName())) {
201 *out->append() = reg->factory();
202 }
203 }
204}
205
commit-bot@chromium.org846872f2013-10-16 18:21:03 +0000206int tool_main(int argc, char** argv);
207int tool_main(int argc, char** argv) {
mtklein30e6e2a2014-06-18 11:44:15 -0700208 SetupCrashHandler();
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000209 SkAutoGraphics ag;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000210 SkCommandLineFlags::Parse(argc, argv);
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +0000211
212 if (FLAGS_dryRun) {
213 FLAGS_verbose = true;
214 }
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000215#if SK_ENABLE_INST_COUNT
216 gPrintInstCount = FLAGS_leaks;
217#endif
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000218
mtklein@google.comd36522d2013-10-16 13:02:15 +0000219 SkTArray<SkString> configs;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000220 for (int i = 0; i < FLAGS_config.count(); i++) {
221 SkStrSplit(FLAGS_config[i], ", ", &configs);
222 }
223
kkinnunen80549fc2014-06-30 06:36:31 -0700224 GrGLStandard gpuAPI = get_gl_standard();
225
mtklein@google.comd36522d2013-10-16 13:02:15 +0000226 SkTDArray<GMRegistry::Factory> gms;
commit-bot@chromium.org99589af2013-12-10 14:53:16 +0000227 SkAutoTDelete<DM::Expectations> expectations(SkNEW(DM::NoExpectations));
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000228 if (FLAGS_gms) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000229 append_matching_factories<GM>(GMRegistry::Head(), &gms);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000230
231 if (FLAGS_expectations.count() > 0) {
232 const char* path = FLAGS_expectations[0];
233 if (sk_isdir(path)) {
234 expectations.reset(SkNEW_ARGS(DM::WriteTask::Expectations, (path)));
235 } else {
236 expectations.reset(SkNEW_ARGS(DM::JsonExpectations, (path)));
237 }
commit-bot@chromium.org99589af2013-12-10 14:53:16 +0000238 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000239 }
240
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000241 SkTDArray<TestRegistry::Factory> tests;
242 if (FLAGS_tests) {
243 append_matching_factories<Test>(TestRegistry::Head(), &tests);
244 }
245
mtklein103ae712014-07-16 14:29:53 -0700246 SkDebugf("%d GMs x %d configs, %d tests\n",
247 gms.count(), configs.count(), tests.count());
mtklein@google.comd36522d2013-10-16 13:02:15 +0000248 DM::Reporter reporter;
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +0000249 DM::TaskRunner tasks(FLAGS_threads, FLAGS_gpuThreads);
kkinnunen80549fc2014-06-30 06:36:31 -0700250 kick_off_gms(gms, configs, gpuAPI, *expectations, &reporter, &tasks);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000251 kick_off_tests(tests, &reporter, &tasks);
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000252 kick_off_skps(&reporter, &tasks);
mtklein@google.comd36522d2013-10-16 13:02:15 +0000253 tasks.wait();
254
mtklein@google.comd36522d2013-10-16 13:02:15 +0000255 SkDebugf("\n");
mtklein@google.comd36522d2013-10-16 13:02:15 +0000256
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000257 SkTArray<SkString> failures;
258 reporter.getFailures(&failures);
259 report_failures(failures);
260 return failures.count() > 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000261}
commit-bot@chromium.org846872f2013-10-16 18:21:03 +0000262
263#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
264int main(int argc, char** argv) {
265 return tool_main(argc, argv);
266}
267#endif