blob: aba65236ff2dfba04e124cc36aca31decfc16f53 [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"
mtklein72ebb9f2014-08-07 14:27:03 -07005#include "LazyDecodeBitmap.h"
caryclark17f0b6d2014-07-22 10:15:34 -07006#include "SkCommonFlags.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +00007#include "SkForceLinking.h"
8#include "SkGraphics.h"
mtklein1d0f1642014-09-08 08:05:18 -07009#include "SkOSFile.h"
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +000010#include "SkPicture.h"
rmistry@google.comd6bab022013-12-02 13:50:38 +000011#include "SkString.h"
mtklein406654b2014-09-03 15:34:37 -070012#include "SkTaskGroup.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000013#include "Test.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000014#include "gm.h"
Cary Clark992c7b02014-07-31 08:58:44 -040015#include "sk_tool_utils.h"
16#include "sk_tool_utils_flags.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000017
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000018#include "DMCpuGMTask.h"
19#include "DMGpuGMTask.h"
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000020#include "DMGpuSupport.h"
mtklein30bf3e22014-06-03 13:57:14 -070021#include "DMPDFTask.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000022#include "DMReporter.h"
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +000023#include "DMSKPTask.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000024#include "DMTask.h"
25#include "DMTaskRunner.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000026#include "DMTestTask.h"
commit-bot@chromium.org99589af2013-12-10 14:53:16 +000027#include "DMWriteTask.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000028
mtklein30bf3e22014-06-03 13:57:14 -070029#ifdef SK_BUILD_POPPLER
30# include "SkPDFRasterizer.h"
31# define RASTERIZE_PDF_PROC SkPopplerRasterizePDF
32#else
33# define RASTERIZE_PDF_PROC NULL
34#endif
35
commit-bot@chromium.org120c9992014-05-16 18:11:51 +000036#include <ctype.h>
mtklein@google.comd36522d2013-10-16 13:02:15 +000037
38using skiagm::GM;
39using skiagm::GMRegistry;
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000040using skiatest::Test;
41using skiatest::TestRegistry;
mtklein@google.comd36522d2013-10-16 13:02:15 +000042
kkinnunen80549fc2014-06-30 06:36:31 -070043static const char kGpuAPINameGL[] = "gl";
44static const char kGpuAPINameGLES[] = "gles";
45
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000046DEFINE_bool(gms, true, "Run GMs?");
47DEFINE_bool(tests, true, "Run tests?");
Cary Clark992c7b02014-07-31 08:58:44 -040048DEFINE_bool(reportUsedChars, false, "Output test font construction data to be pasted into"
49 " create_test_font.cpp.");
mtklein@google.comd36522d2013-10-16 13:02:15 +000050
51__SK_FORCE_IMAGE_DECODER_LINKING;
52
mtklein@google.comd36522d2013-10-16 13:02:15 +000053// "FooBar" -> "foobar". Obviously, ASCII only.
54static SkString lowercase(SkString s) {
55 for (size_t i = 0; i < s.size(); i++) {
56 s[i] = tolower(s[i]);
57 }
58 return s;
59}
60
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000061static const GrContextFactory::GLContextType native = GrContextFactory::kNative_GLContextType;
mtklein60c77072014-08-14 10:36:55 -070062static const GrContextFactory::GLContextType nvpr = GrContextFactory::kNVPR_GLContextType;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000063static const GrContextFactory::GLContextType null = GrContextFactory::kNull_GLContextType;
64static const GrContextFactory::GLContextType debug = GrContextFactory::kDebug_GLContextType;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000065#if SK_ANGLE
mtklein60c77072014-08-14 10:36:55 -070066static const GrContextFactory::GLContextType angle = GrContextFactory::kANGLE_GLContextType;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000067#endif
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000068#if SK_MESA
mtklein60c77072014-08-14 10:36:55 -070069static const GrContextFactory::GLContextType mesa = GrContextFactory::kMESA_GLContextType;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000070#endif
71
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000072static void kick_off_gms(const SkTDArray<GMRegistry::Factory>& gms,
73 const SkTArray<SkString>& configs,
kkinnunen80549fc2014-06-30 06:36:31 -070074 GrGLStandard gpuAPI,
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000075 DM::Reporter* reporter,
76 DM::TaskRunner* tasks) {
mtkleine4d3e602014-06-06 09:28:43 -070077#define START(name, type, ...) \
78 if (lowercase(configs[j]).equals(name)) { \
79 tasks->add(SkNEW_ARGS(DM::type, (name, reporter, tasks, gms[i], ## __VA_ARGS__))); \
mtklein@google.comd36522d2013-10-16 13:02:15 +000080 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000081 for (int i = 0; i < gms.count(); i++) {
mtklein@google.comd36522d2013-10-16 13:02:15 +000082 for (int j = 0; j < configs.count(); j++) {
kkinnunen80549fc2014-06-30 06:36:31 -070083
mtklein197ceda2014-09-09 07:36:57 -070084 START("565", CpuGMTask, kRGB_565_SkColorType);
85 START("8888", CpuGMTask, kN32_SkColorType);
86 START("gpu", GpuGMTask, native, gpuAPI, 0);
87 START("msaa4", GpuGMTask, native, gpuAPI, 4);
88 START("msaa16", GpuGMTask, native, gpuAPI, 16);
89 START("nvprmsaa4", GpuGMTask, nvpr, gpuAPI, 4);
90 START("nvprmsaa16", GpuGMTask, nvpr, gpuAPI, 16);
91 START("gpunull", GpuGMTask, null, gpuAPI, 0);
92 START("gpudebug", GpuGMTask, debug, gpuAPI, 0);
mtklein60c77072014-08-14 10:36:55 -070093#if SK_ANGLE
mtklein197ceda2014-09-09 07:36:57 -070094 START("angle", GpuGMTask, angle, gpuAPI, 0);
mtklein60c77072014-08-14 10:36:55 -070095#endif
96#if SK_MESA
mtklein197ceda2014-09-09 07:36:57 -070097 START("mesa", GpuGMTask, mesa, gpuAPI, 0);
mtklein60c77072014-08-14 10:36:55 -070098#endif
mtklein30bf3e22014-06-03 13:57:14 -070099 START("pdf", PDFTask, RASTERIZE_PDF_PROC);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000100 }
101 }
102#undef START
103}
104
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000105static void kick_off_tests(const SkTDArray<TestRegistry::Factory>& tests,
106 DM::Reporter* reporter,
107 DM::TaskRunner* tasks) {
108 for (int i = 0; i < tests.count(); i++) {
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +0000109 SkAutoTDelete<Test> test(tests[i](NULL));
110 if (test->isGPUTest()) {
111 tasks->add(SkNEW_ARGS(DM::GpuTestTask, (reporter, tasks, tests[i])));
112 } else {
113 tasks->add(SkNEW_ARGS(DM::CpuTestTask, (reporter, tasks, tests[i])));
114 }
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000115 }
116}
117
halcanarya98683b2014-07-28 07:21:24 -0700118static void find_skps(SkTArray<SkString>* skps) {
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000119 if (FLAGS_skps.isEmpty()) {
120 return;
121 }
122
123 SkOSFile::Iter it(FLAGS_skps[0], ".skp");
124 SkString filename;
125 while (it.next(&filename)) {
halcanarya98683b2014-07-28 07:21:24 -0700126 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, filename.c_str())) {
tfarinaa8e2e152014-07-28 19:26:58 -0700127 skps->push_back(SkOSPath::Join(FLAGS_skps[0], filename.c_str()));
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000128 }
halcanarya98683b2014-07-28 07:21:24 -0700129 }
130}
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000131
halcanarya98683b2014-07-28 07:21:24 -0700132static void kick_off_skps(const SkTArray<SkString>& skps,
mtklein23c94f02014-09-08 09:12:28 -0700133 DM::Reporter* reporter,
134 DM::TaskRunner* tasks) {
halcanarya98683b2014-07-28 07:21:24 -0700135 for (int i = 0; i < skps.count(); ++i) {
136 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(skps[i].c_str()));
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000137 if (stream.get() == NULL) {
halcanarya98683b2014-07-28 07:21:24 -0700138 SkDebugf("Could not read %s.\n", skps[i].c_str());
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000139 exit(1);
140 }
mtklein72ebb9f2014-08-07 14:27:03 -0700141 SkAutoTUnref<SkPicture> pic(
142 SkPicture::CreateFromStream(stream.get(), &sk_tools::LazyDecodeBitmap));
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000143 if (pic.get() == NULL) {
halcanarya98683b2014-07-28 07:21:24 -0700144 SkDebugf("Could not read %s as an SkPicture.\n", skps[i].c_str());
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000145 exit(1);
146 }
147
tfarinaa8e2e152014-07-28 19:26:58 -0700148 SkString filename = SkOSPath::Basename(skps[i].c_str());
mtklein197ceda2014-09-09 07:36:57 -0700149 tasks->add(SkNEW_ARGS(DM::SKPTask, (reporter, tasks, pic, filename)));
150 tasks->add(SkNEW_ARGS(DM::PDFTask, (reporter, tasks, pic, filename, RASTERIZE_PDF_PROC)));
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000151 }
152}
153
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000154static void report_failures(const SkTArray<SkString>& failures) {
mtklein@google.comd36522d2013-10-16 13:02:15 +0000155 if (failures.count() == 0) {
156 return;
157 }
158
159 SkDebugf("Failures:\n");
160 for (int i = 0; i < failures.count(); i++) {
161 SkDebugf(" %s\n", failures[i].c_str());
162 }
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000163 SkDebugf("%d failures.\n", failures.count());
mtklein@google.comd36522d2013-10-16 13:02:15 +0000164}
165
kkinnunen80549fc2014-06-30 06:36:31 -0700166static GrGLStandard get_gl_standard() {
167 if (FLAGS_gpuAPI.contains(kGpuAPINameGL)) {
168 return kGL_GrGLStandard;
169 }
170 if (FLAGS_gpuAPI.contains(kGpuAPINameGLES)) {
171 return kGLES_GrGLStandard;
172 }
173 return kNone_GrGLStandard;
174}
175
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000176template <typename T, typename Registry>
177static void append_matching_factories(Registry* head, SkTDArray<typename Registry::Factory>* out) {
178 for (const Registry* reg = head; reg != NULL; reg = reg->next()) {
179 SkAutoTDelete<T> forName(reg->factory()(NULL));
180 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, forName->getName())) {
181 *out->append() = reg->factory();
182 }
183 }
184}
185
caryclark17f0b6d2014-07-22 10:15:34 -0700186int dm_main();
187int dm_main() {
mtklein30e6e2a2014-06-18 11:44:15 -0700188 SetupCrashHandler();
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000189 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -0700190 SkTaskGroup::Enabler enabled(FLAGS_threads);
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +0000191
192 if (FLAGS_dryRun) {
193 FLAGS_verbose = true;
194 }
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000195#if SK_ENABLE_INST_COUNT
196 gPrintInstCount = FLAGS_leaks;
197#endif
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000198
mtklein@google.comd36522d2013-10-16 13:02:15 +0000199 SkTArray<SkString> configs;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000200 for (int i = 0; i < FLAGS_config.count(); i++) {
201 SkStrSplit(FLAGS_config[i], ", ", &configs);
202 }
203
kkinnunen80549fc2014-06-30 06:36:31 -0700204 GrGLStandard gpuAPI = get_gl_standard();
205
mtklein@google.comd36522d2013-10-16 13:02:15 +0000206 SkTDArray<GMRegistry::Factory> gms;
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000207 if (FLAGS_gms) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000208 append_matching_factories<GM>(GMRegistry::Head(), &gms);
mtklein@google.comd36522d2013-10-16 13:02:15 +0000209 }
210
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000211 SkTDArray<TestRegistry::Factory> tests;
212 if (FLAGS_tests) {
213 append_matching_factories<Test>(TestRegistry::Head(), &tests);
214 }
215
halcanarya98683b2014-07-28 07:21:24 -0700216 SkTArray<SkString> skps;
217 find_skps(&skps);
218
219 SkDebugf("%d GMs x %d configs, %d tests, %d pictures\n",
220 gms.count(), configs.count(), tests.count(), skps.count());
mtklein@google.comd36522d2013-10-16 13:02:15 +0000221 DM::Reporter reporter;
mtklein406654b2014-09-03 15:34:37 -0700222
223 DM::TaskRunner tasks;
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000224 kick_off_tests(tests, &reporter, &tasks);
mtklein197ceda2014-09-09 07:36:57 -0700225 kick_off_gms(gms, configs, gpuAPI, &reporter, &tasks);
226 kick_off_skps(skps, &reporter, &tasks);
mtklein@google.comd36522d2013-10-16 13:02:15 +0000227 tasks.wait();
228
mtklein1d0f1642014-09-08 08:05:18 -0700229 DM::WriteTask::DumpJson();
230
mtklein@google.comd36522d2013-10-16 13:02:15 +0000231 SkDebugf("\n");
Cary Clark992c7b02014-07-31 08:58:44 -0400232#ifdef SK_DEBUG
233 if (FLAGS_portableFonts && FLAGS_reportUsedChars) {
234 sk_tool_utils::report_used_chars();
235 }
236#endif
mtklein92007582014-08-01 07:46:52 -0700237
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000238 SkTArray<SkString> failures;
239 reporter.getFailures(&failures);
240 report_failures(failures);
241 return failures.count() > 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000242}
commit-bot@chromium.org846872f2013-10-16 18:21:03 +0000243
244#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
245int main(int argc, char** argv) {
caryclark17f0b6d2014-07-22 10:15:34 -0700246 SkCommandLineFlags::Parse(argc, argv);
247 return dm_main();
commit-bot@chromium.org846872f2013-10-16 18:21:03 +0000248}
249#endif