blob: 08a458756f876eab57f9a037f2c10bd1dddda673 [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
mtklein72ebb9f2014-08-07 14:27:03 -07004#include "LazyDecodeBitmap.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"
mtklein1d0f1642014-09-08 08:05:18 -07008#include "SkOSFile.h"
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +00009#include "SkPicture.h"
rmistry@google.comd6bab022013-12-02 13:50:38 +000010#include "SkString.h"
mtklein406654b2014-09-03 15:34:37 -070011#include "SkTaskGroup.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000012#include "Test.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000013#include "gm.h"
Cary Clark992c7b02014-07-31 08:58:44 -040014#include "sk_tool_utils.h"
15#include "sk_tool_utils_flags.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000016
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +000017#include "DMCpuGMTask.h"
18#include "DMGpuGMTask.h"
commit-bot@chromium.org787227d2014-03-26 21:26:15 +000019#include "DMGpuSupport.h"
scroggo7a10fb62014-11-04 07:21:10 -080020#include "DMJsonWriter.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"
mtklein@google.comd36522d2013-10-16 13:02:15 +000027
mtklein30bf3e22014-06-03 13:57:14 -070028#ifdef SK_BUILD_POPPLER
29# include "SkPDFRasterizer.h"
30# define RASTERIZE_PDF_PROC SkPopplerRasterizePDF
halcanary3dc5d702014-10-27 06:24:11 -070031#elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
32# include "SkCGUtils.h"
33# define RASTERIZE_PDF_PROC SkPDFDocumentToBitmap
mtklein30bf3e22014-06-03 13:57:14 -070034#else
35# define RASTERIZE_PDF_PROC NULL
36#endif
37
commit-bot@chromium.org120c9992014-05-16 18:11:51 +000038#include <ctype.h>
mtklein@google.comd36522d2013-10-16 13:02:15 +000039
40using skiagm::GM;
41using skiagm::GMRegistry;
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000042using skiatest::Test;
43using skiatest::TestRegistry;
mtklein@google.comd36522d2013-10-16 13:02:15 +000044
kkinnunen80549fc2014-06-30 06:36:31 -070045static const char kGpuAPINameGL[] = "gl";
46static const char kGpuAPINameGLES[] = "gles";
47
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000048DEFINE_bool(gms, true, "Run GMs?");
49DEFINE_bool(tests, true, "Run tests?");
Cary Clark992c7b02014-07-31 08:58:44 -040050DEFINE_bool(reportUsedChars, false, "Output test font construction data to be pasted into"
51 " create_test_font.cpp.");
mtklein@google.comd36522d2013-10-16 13:02:15 +000052
53__SK_FORCE_IMAGE_DECODER_LINKING;
54
mtklein@google.comd36522d2013-10-16 13:02:15 +000055// "FooBar" -> "foobar". Obviously, ASCII only.
56static SkString lowercase(SkString s) {
57 for (size_t i = 0; i < s.size(); i++) {
58 s[i] = tolower(s[i]);
59 }
60 return s;
61}
62
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000063static const GrContextFactory::GLContextType native = GrContextFactory::kNative_GLContextType;
mtklein60c77072014-08-14 10:36:55 -070064static const GrContextFactory::GLContextType nvpr = GrContextFactory::kNVPR_GLContextType;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000065static const GrContextFactory::GLContextType null = GrContextFactory::kNull_GLContextType;
66static const GrContextFactory::GLContextType debug = GrContextFactory::kDebug_GLContextType;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000067#if SK_ANGLE
mtklein60c77072014-08-14 10:36:55 -070068static const GrContextFactory::GLContextType angle = GrContextFactory::kANGLE_GLContextType;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000069#endif
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000070#if SK_MESA
mtklein60c77072014-08-14 10:36:55 -070071static const GrContextFactory::GLContextType mesa = GrContextFactory::kMESA_GLContextType;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000072#endif
73
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000074static void kick_off_gms(const SkTDArray<GMRegistry::Factory>& gms,
75 const SkTArray<SkString>& configs,
kkinnunen80549fc2014-06-30 06:36:31 -070076 GrGLStandard gpuAPI,
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000077 DM::Reporter* reporter,
78 DM::TaskRunner* tasks) {
mtkleine4d3e602014-06-06 09:28:43 -070079#define START(name, type, ...) \
80 if (lowercase(configs[j]).equals(name)) { \
81 tasks->add(SkNEW_ARGS(DM::type, (name, reporter, tasks, gms[i], ## __VA_ARGS__))); \
mtklein@google.comd36522d2013-10-16 13:02:15 +000082 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000083 for (int i = 0; i < gms.count(); i++) {
mtklein@google.comd36522d2013-10-16 13:02:15 +000084 for (int j = 0; j < configs.count(); j++) {
kkinnunen80549fc2014-06-30 06:36:31 -070085
mtklein197ceda2014-09-09 07:36:57 -070086 START("565", CpuGMTask, kRGB_565_SkColorType);
87 START("8888", CpuGMTask, kN32_SkColorType);
jvanverth4736e142014-11-07 07:12:46 -080088 START("gpu", GpuGMTask, native, gpuAPI, 0, false);
89 START("msaa4", GpuGMTask, native, gpuAPI, 4, false);
90 START("msaa16", GpuGMTask, native, gpuAPI, 16, false);
91 START("nvprmsaa4", GpuGMTask, nvpr, gpuAPI, 4, false);
92 START("nvprmsaa16", GpuGMTask, nvpr, gpuAPI, 16, false);
93 START("gpudft", GpuGMTask, native, gpuAPI, 0, true);
94 START("gpunull", GpuGMTask, null, gpuAPI, 0, false);
95 START("gpudebug", GpuGMTask, debug, gpuAPI, 0, false);
mtklein60c77072014-08-14 10:36:55 -070096#if SK_ANGLE
jvanverth4736e142014-11-07 07:12:46 -080097 START("angle", GpuGMTask, angle, gpuAPI, 0, false);
mtklein60c77072014-08-14 10:36:55 -070098#endif
99#if SK_MESA
jvanverth4736e142014-11-07 07:12:46 -0800100 START("mesa", GpuGMTask, mesa, gpuAPI, 0, false);
mtklein60c77072014-08-14 10:36:55 -0700101#endif
mtklein30bf3e22014-06-03 13:57:14 -0700102 START("pdf", PDFTask, RASTERIZE_PDF_PROC);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000103 }
104 }
105#undef START
106}
107
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000108static void kick_off_tests(const SkTDArray<TestRegistry::Factory>& tests,
109 DM::Reporter* reporter,
110 DM::TaskRunner* tasks) {
111 for (int i = 0; i < tests.count(); i++) {
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +0000112 SkAutoTDelete<Test> test(tests[i](NULL));
113 if (test->isGPUTest()) {
114 tasks->add(SkNEW_ARGS(DM::GpuTestTask, (reporter, tasks, tests[i])));
115 } else {
116 tasks->add(SkNEW_ARGS(DM::CpuTestTask, (reporter, tasks, tests[i])));
117 }
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000118 }
119}
120
halcanarya98683b2014-07-28 07:21:24 -0700121static void find_skps(SkTArray<SkString>* skps) {
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000122 if (FLAGS_skps.isEmpty()) {
123 return;
124 }
125
126 SkOSFile::Iter it(FLAGS_skps[0], ".skp");
127 SkString filename;
128 while (it.next(&filename)) {
halcanarya98683b2014-07-28 07:21:24 -0700129 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, filename.c_str())) {
tfarinaa8e2e152014-07-28 19:26:58 -0700130 skps->push_back(SkOSPath::Join(FLAGS_skps[0], filename.c_str()));
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000131 }
halcanarya98683b2014-07-28 07:21:24 -0700132 }
133}
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000134
halcanarya98683b2014-07-28 07:21:24 -0700135static void kick_off_skps(const SkTArray<SkString>& skps,
mtklein23c94f02014-09-08 09:12:28 -0700136 DM::Reporter* reporter,
137 DM::TaskRunner* tasks) {
halcanarya98683b2014-07-28 07:21:24 -0700138 for (int i = 0; i < skps.count(); ++i) {
139 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(skps[i].c_str()));
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000140 if (stream.get() == NULL) {
halcanarya98683b2014-07-28 07:21:24 -0700141 SkDebugf("Could not read %s.\n", skps[i].c_str());
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000142 exit(1);
143 }
mtklein72ebb9f2014-08-07 14:27:03 -0700144 SkAutoTUnref<SkPicture> pic(
145 SkPicture::CreateFromStream(stream.get(), &sk_tools::LazyDecodeBitmap));
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000146 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
tfarinaa8e2e152014-07-28 19:26:58 -0700151 SkString filename = SkOSPath::Basename(skps[i].c_str());
mtklein197ceda2014-09-09 07:36:57 -0700152 tasks->add(SkNEW_ARGS(DM::SKPTask, (reporter, tasks, pic, filename)));
153 tasks->add(SkNEW_ARGS(DM::PDFTask, (reporter, tasks, pic, filename, RASTERIZE_PDF_PROC)));
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000154 }
155}
156
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000157static void report_failures(const SkTArray<SkString>& failures) {
mtklein@google.comd36522d2013-10-16 13:02:15 +0000158 if (failures.count() == 0) {
159 return;
160 }
161
162 SkDebugf("Failures:\n");
163 for (int i = 0; i < failures.count(); i++) {
164 SkDebugf(" %s\n", failures[i].c_str());
165 }
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000166 SkDebugf("%d failures.\n", failures.count());
mtklein@google.comd36522d2013-10-16 13:02:15 +0000167}
168
kkinnunen80549fc2014-06-30 06:36:31 -0700169static GrGLStandard get_gl_standard() {
170 if (FLAGS_gpuAPI.contains(kGpuAPINameGL)) {
171 return kGL_GrGLStandard;
172 }
173 if (FLAGS_gpuAPI.contains(kGpuAPINameGLES)) {
174 return kGLES_GrGLStandard;
175 }
176 return kNone_GrGLStandard;
177}
178
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000179template <typename T, typename Registry>
180static void append_matching_factories(Registry* head, SkTDArray<typename Registry::Factory>* out) {
181 for (const Registry* reg = head; reg != NULL; reg = reg->next()) {
182 SkAutoTDelete<T> forName(reg->factory()(NULL));
183 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, forName->getName())) {
184 *out->append() = reg->factory();
185 }
186 }
187}
188
caryclark17f0b6d2014-07-22 10:15:34 -0700189int dm_main() {
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000190 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -0700191 SkTaskGroup::Enabler enabled(FLAGS_threads);
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +0000192
bsalomon06cddec2014-10-24 10:40:50 -0700193 if (FLAGS_dryRun || FLAGS_veryVerbose) {
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +0000194 FLAGS_verbose = true;
195 }
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000196#if SK_ENABLE_INST_COUNT
197 gPrintInstCount = FLAGS_leaks;
198#endif
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000199
mtklein@google.comd36522d2013-10-16 13:02:15 +0000200 SkTArray<SkString> configs;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000201 for (int i = 0; i < FLAGS_config.count(); i++) {
202 SkStrSplit(FLAGS_config[i], ", ", &configs);
203 }
204
kkinnunen80549fc2014-06-30 06:36:31 -0700205 GrGLStandard gpuAPI = get_gl_standard();
206
mtklein@google.comd36522d2013-10-16 13:02:15 +0000207 SkTDArray<GMRegistry::Factory> gms;
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000208 if (FLAGS_gms) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000209 append_matching_factories<GM>(GMRegistry::Head(), &gms);
mtklein@google.comd36522d2013-10-16 13:02:15 +0000210 }
211
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000212 SkTDArray<TestRegistry::Factory> tests;
213 if (FLAGS_tests) {
214 append_matching_factories<Test>(TestRegistry::Head(), &tests);
215 }
216
halcanarya98683b2014-07-28 07:21:24 -0700217 SkTArray<SkString> skps;
218 find_skps(&skps);
219
220 SkDebugf("%d GMs x %d configs, %d tests, %d pictures\n",
221 gms.count(), configs.count(), tests.count(), skps.count());
mtklein@google.comd36522d2013-10-16 13:02:15 +0000222 DM::Reporter reporter;
mtklein406654b2014-09-03 15:34:37 -0700223
224 DM::TaskRunner tasks;
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000225 kick_off_tests(tests, &reporter, &tasks);
mtklein197ceda2014-09-09 07:36:57 -0700226 kick_off_gms(gms, configs, gpuAPI, &reporter, &tasks);
227 kick_off_skps(skps, &reporter, &tasks);
mtklein@google.comd36522d2013-10-16 13:02:15 +0000228 tasks.wait();
229
scroggo7a10fb62014-11-04 07:21:10 -0800230 DM::JsonWriter::DumpJson();
mtklein1d0f1642014-09-08 08:05:18 -0700231
mtklein@google.comd36522d2013-10-16 13:02:15 +0000232 SkDebugf("\n");
Cary Clark992c7b02014-07-31 08:58:44 -0400233#ifdef SK_DEBUG
234 if (FLAGS_portableFonts && FLAGS_reportUsedChars) {
235 sk_tool_utils::report_used_chars();
236 }
237#endif
mtklein92007582014-08-01 07:46:52 -0700238
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000239 SkTArray<SkString> failures;
240 reporter.getFailures(&failures);
241 report_failures(failures);
242 return failures.count() > 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000243}