blob: fd15eef9edcd31707046890927f3b720e12041d7 [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"
Cary Clark992c7b02014-07-31 08:58:44 -040012#include "sk_tool_utils.h"
13#include "sk_tool_utils_flags.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000014
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
kkinnunen80549fc2014-06-30 06:36:31 -070040static const char kGpuAPINameGL[] = "gl";
41static const char kGpuAPINameGLES[] = "gles";
42
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000043DEFINE_int32(gpuThreads, 1, "Threads for GPU work.");
commit-bot@chromium.org99589af2013-12-10 14:53:16 +000044DEFINE_string2(expectations, r, "",
45 "If a directory, compare generated images against images under this path. "
commit-bot@chromium.org120c9992014-05-16 18:11:51 +000046 "If a file, compare generated images against JSON expectations at this path."
commit-bot@chromium.org120c9992014-05-16 18:11:51 +000047);
caryclark17f0b6d2014-07-22 10:15:34 -070048
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +000049DEFINE_string(skps, "", "Directory to read skps from.");
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000050
51DEFINE_bool(gms, true, "Run GMs?");
52DEFINE_bool(tests, true, "Run tests?");
Cary Clark992c7b02014-07-31 08:58:44 -040053DEFINE_bool(reportUsedChars, false, "Output test font construction data to be pasted into"
54 " create_test_font.cpp.");
mtklein@google.comd36522d2013-10-16 13:02:15 +000055
56__SK_FORCE_IMAGE_DECODER_LINKING;
57
mtklein@google.comd36522d2013-10-16 13:02:15 +000058// "FooBar" -> "foobar". Obviously, ASCII only.
59static SkString lowercase(SkString s) {
60 for (size_t i = 0; i < s.size(); i++) {
61 s[i] = tolower(s[i]);
62 }
63 return s;
64}
65
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000066static const GrContextFactory::GLContextType native = GrContextFactory::kNative_GLContextType;
commit-bot@chromium.orgb6401862014-03-12 14:46:31 +000067static const GrContextFactory::GLContextType nvpr = GrContextFactory::kNVPR_GLContextType;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000068static const GrContextFactory::GLContextType null = GrContextFactory::kNull_GLContextType;
69static const GrContextFactory::GLContextType debug = GrContextFactory::kDebug_GLContextType;
70static const GrContextFactory::GLContextType angle =
71#if SK_ANGLE
72GrContextFactory::kANGLE_GLContextType;
73#else
74native;
75#endif
76static const GrContextFactory::GLContextType mesa =
77#if SK_MESA
bsalomon@google.com9dccafa2014-05-02 14:43:12 +000078GrContextFactory::kMESA_GLContextType;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000079#else
80native;
81#endif
82
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000083static void kick_off_gms(const SkTDArray<GMRegistry::Factory>& gms,
84 const SkTArray<SkString>& configs,
kkinnunen80549fc2014-06-30 06:36:31 -070085 GrGLStandard gpuAPI,
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000086 const DM::Expectations& expectations,
87 DM::Reporter* reporter,
88 DM::TaskRunner* tasks) {
mtkleine4d3e602014-06-06 09:28:43 -070089#define START(name, type, ...) \
90 if (lowercase(configs[j]).equals(name)) { \
91 tasks->add(SkNEW_ARGS(DM::type, (name, reporter, tasks, gms[i], ## __VA_ARGS__))); \
mtklein@google.comd36522d2013-10-16 13:02:15 +000092 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000093 for (int i = 0; i < gms.count(); i++) {
mtklein@google.comd36522d2013-10-16 13:02:15 +000094 for (int j = 0; j < configs.count(); j++) {
kkinnunen80549fc2014-06-30 06:36:31 -070095
mtkleine4d3e602014-06-06 09:28:43 -070096 START("565", CpuGMTask, expectations, kRGB_565_SkColorType);
97 START("8888", CpuGMTask, expectations, kN32_SkColorType);
kkinnunen80549fc2014-06-30 06:36:31 -070098 START("gpu", GpuGMTask, expectations, native, gpuAPI, 0);
99 START("msaa4", GpuGMTask, expectations, native, gpuAPI, 4);
100 START("msaa16", GpuGMTask, expectations, native, gpuAPI, 16);
101 START("nvprmsaa4", GpuGMTask, expectations, nvpr, gpuAPI, 4);
102 START("nvprmsaa16", GpuGMTask, expectations, nvpr, gpuAPI, 16);
103 START("gpunull", GpuGMTask, expectations, null, gpuAPI, 0);
104 START("gpudebug", GpuGMTask, expectations, debug, gpuAPI, 0);
105 START("angle", GpuGMTask, expectations, angle, gpuAPI, 0);
106 START("mesa", GpuGMTask, expectations, mesa, gpuAPI, 0);
mtklein30bf3e22014-06-03 13:57:14 -0700107 START("pdf", PDFTask, RASTERIZE_PDF_PROC);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000108 }
109 }
110#undef START
111}
112
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000113static void kick_off_tests(const SkTDArray<TestRegistry::Factory>& tests,
114 DM::Reporter* reporter,
115 DM::TaskRunner* tasks) {
116 for (int i = 0; i < tests.count(); i++) {
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +0000117 SkAutoTDelete<Test> test(tests[i](NULL));
118 if (test->isGPUTest()) {
119 tasks->add(SkNEW_ARGS(DM::GpuTestTask, (reporter, tasks, tests[i])));
120 } else {
121 tasks->add(SkNEW_ARGS(DM::CpuTestTask, (reporter, tasks, tests[i])));
122 }
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000123 }
124}
125
halcanarya98683b2014-07-28 07:21:24 -0700126static void find_skps(SkTArray<SkString>* skps) {
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000127 if (FLAGS_skps.isEmpty()) {
128 return;
129 }
130
131 SkOSFile::Iter it(FLAGS_skps[0], ".skp");
132 SkString filename;
133 while (it.next(&filename)) {
halcanarya98683b2014-07-28 07:21:24 -0700134 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, filename.c_str())) {
tfarinaa8e2e152014-07-28 19:26:58 -0700135 skps->push_back(SkOSPath::Join(FLAGS_skps[0], filename.c_str()));
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000136 }
halcanarya98683b2014-07-28 07:21:24 -0700137 }
138}
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000139
halcanarya98683b2014-07-28 07:21:24 -0700140static void kick_off_skps(const SkTArray<SkString>& skps,
141 DM::Reporter* reporter, DM::TaskRunner* tasks) {
142 for (int i = 0; i < skps.count(); ++i) {
143 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(skps[i].c_str()));
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000144 if (stream.get() == NULL) {
halcanarya98683b2014-07-28 07:21:24 -0700145 SkDebugf("Could not read %s.\n", skps[i].c_str());
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000146 exit(1);
147 }
148 SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream.get()));
149 if (pic.get() == NULL) {
halcanarya98683b2014-07-28 07:21:24 -0700150 SkDebugf("Could not read %s as an SkPicture.\n", skps[i].c_str());
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000151 exit(1);
152 }
153
tfarinaa8e2e152014-07-28 19:26:58 -0700154 SkString filename = SkOSPath::Basename(skps[i].c_str());
mtkleind3e474e2014-06-27 12:34:44 -0700155 tasks->add(SkNEW_ARGS(DM::SKPTask, (reporter, tasks, pic, filename)));
156 tasks->add(SkNEW_ARGS(DM::PDFTask, (reporter, tasks, pic, filename,
mtkleine4d3e602014-06-06 09:28:43 -0700157 RASTERIZE_PDF_PROC)));
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000158 }
159}
160
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000161static void report_failures(const SkTArray<SkString>& failures) {
mtklein@google.comd36522d2013-10-16 13:02:15 +0000162 if (failures.count() == 0) {
163 return;
164 }
165
166 SkDebugf("Failures:\n");
167 for (int i = 0; i < failures.count(); i++) {
168 SkDebugf(" %s\n", failures[i].c_str());
169 }
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000170 SkDebugf("%d failures.\n", failures.count());
mtklein@google.comd36522d2013-10-16 13:02:15 +0000171}
172
kkinnunen80549fc2014-06-30 06:36:31 -0700173static GrGLStandard get_gl_standard() {
174 if (FLAGS_gpuAPI.contains(kGpuAPINameGL)) {
175 return kGL_GrGLStandard;
176 }
177 if (FLAGS_gpuAPI.contains(kGpuAPINameGLES)) {
178 return kGLES_GrGLStandard;
179 }
180 return kNone_GrGLStandard;
181}
182
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000183template <typename T, typename Registry>
184static void append_matching_factories(Registry* head, SkTDArray<typename Registry::Factory>* out) {
185 for (const Registry* reg = head; reg != NULL; reg = reg->next()) {
186 SkAutoTDelete<T> forName(reg->factory()(NULL));
187 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, forName->getName())) {
188 *out->append() = reg->factory();
189 }
190 }
191}
192
caryclark17f0b6d2014-07-22 10:15:34 -0700193int dm_main();
194int dm_main() {
mtklein30e6e2a2014-06-18 11:44:15 -0700195 SetupCrashHandler();
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000196 SkAutoGraphics ag;
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +0000197
198 if (FLAGS_dryRun) {
199 FLAGS_verbose = true;
200 }
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000201#if SK_ENABLE_INST_COUNT
202 gPrintInstCount = FLAGS_leaks;
203#endif
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000204
mtklein@google.comd36522d2013-10-16 13:02:15 +0000205 SkTArray<SkString> configs;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000206 for (int i = 0; i < FLAGS_config.count(); i++) {
207 SkStrSplit(FLAGS_config[i], ", ", &configs);
208 }
209
kkinnunen80549fc2014-06-30 06:36:31 -0700210 GrGLStandard gpuAPI = get_gl_standard();
211
mtklein@google.comd36522d2013-10-16 13:02:15 +0000212 SkTDArray<GMRegistry::Factory> gms;
commit-bot@chromium.org99589af2013-12-10 14:53:16 +0000213 SkAutoTDelete<DM::Expectations> expectations(SkNEW(DM::NoExpectations));
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000214 if (FLAGS_gms) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000215 append_matching_factories<GM>(GMRegistry::Head(), &gms);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000216
217 if (FLAGS_expectations.count() > 0) {
218 const char* path = FLAGS_expectations[0];
219 if (sk_isdir(path)) {
220 expectations.reset(SkNEW_ARGS(DM::WriteTask::Expectations, (path)));
221 } else {
222 expectations.reset(SkNEW_ARGS(DM::JsonExpectations, (path)));
223 }
commit-bot@chromium.org99589af2013-12-10 14:53:16 +0000224 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000225 }
226
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000227 SkTDArray<TestRegistry::Factory> tests;
228 if (FLAGS_tests) {
229 append_matching_factories<Test>(TestRegistry::Head(), &tests);
230 }
231
halcanarya98683b2014-07-28 07:21:24 -0700232 SkTArray<SkString> skps;
233 find_skps(&skps);
234
235 SkDebugf("%d GMs x %d configs, %d tests, %d pictures\n",
236 gms.count(), configs.count(), tests.count(), skps.count());
mtklein@google.comd36522d2013-10-16 13:02:15 +0000237 DM::Reporter reporter;
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +0000238 DM::TaskRunner tasks(FLAGS_threads, FLAGS_gpuThreads);
kkinnunen80549fc2014-06-30 06:36:31 -0700239 kick_off_gms(gms, configs, gpuAPI, *expectations, &reporter, &tasks);
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000240 kick_off_tests(tests, &reporter, &tasks);
halcanarya98683b2014-07-28 07:21:24 -0700241 kick_off_skps(skps, &reporter, &tasks);
mtklein@google.comd36522d2013-10-16 13:02:15 +0000242 tasks.wait();
243
mtklein@google.comd36522d2013-10-16 13:02:15 +0000244 SkDebugf("\n");
Cary Clark992c7b02014-07-31 08:58:44 -0400245#ifdef SK_DEBUG
246 if (FLAGS_portableFonts && FLAGS_reportUsedChars) {
247 sk_tool_utils::report_used_chars();
248 }
249#endif
250
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000251 SkTArray<SkString> failures;
252 reporter.getFailures(&failures);
253 report_failures(failures);
254 return failures.count() > 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000255}
commit-bot@chromium.org846872f2013-10-16 18:21:03 +0000256
257#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
258int main(int argc, char** argv) {
caryclark17f0b6d2014-07-22 10:15:34 -0700259 SkCommandLineFlags::Parse(argc, argv);
260 return dm_main();
commit-bot@chromium.org846872f2013-10-16 18:21:03 +0000261}
262#endif