blob: 2a0c636f618f50cb0119a31b4fb5f17554d4e2b0 [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"
scroggo7a10fb62014-11-04 07:21:10 -080021#include "DMJsonWriter.h"
mtklein30bf3e22014-06-03 13:57:14 -070022#include "DMPDFTask.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000023#include "DMReporter.h"
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +000024#include "DMSKPTask.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000025#include "DMTask.h"
26#include "DMTaskRunner.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000027#include "DMTestTask.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
halcanary3dc5d702014-10-27 06:24:11 -070032#elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
33# include "SkCGUtils.h"
34# define RASTERIZE_PDF_PROC SkPDFDocumentToBitmap
mtklein30bf3e22014-06-03 13:57:14 -070035#else
36# define RASTERIZE_PDF_PROC NULL
37#endif
38
commit-bot@chromium.org120c9992014-05-16 18:11:51 +000039#include <ctype.h>
mtklein@google.comd36522d2013-10-16 13:02:15 +000040
41using skiagm::GM;
42using skiagm::GMRegistry;
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000043using skiatest::Test;
44using skiatest::TestRegistry;
mtklein@google.comd36522d2013-10-16 13:02:15 +000045
kkinnunen80549fc2014-06-30 06:36:31 -070046static const char kGpuAPINameGL[] = "gl";
47static const char kGpuAPINameGLES[] = "gles";
48
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000049DEFINE_bool(gms, true, "Run GMs?");
50DEFINE_bool(tests, true, "Run tests?");
Cary Clark992c7b02014-07-31 08:58:44 -040051DEFINE_bool(reportUsedChars, false, "Output test font construction data to be pasted into"
52 " create_test_font.cpp.");
mtklein@google.comd36522d2013-10-16 13:02:15 +000053
54__SK_FORCE_IMAGE_DECODER_LINKING;
55
mtklein@google.comd36522d2013-10-16 13:02:15 +000056// "FooBar" -> "foobar". Obviously, ASCII only.
57static SkString lowercase(SkString s) {
58 for (size_t i = 0; i < s.size(); i++) {
59 s[i] = tolower(s[i]);
60 }
61 return s;
62}
63
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000064static const GrContextFactory::GLContextType native = GrContextFactory::kNative_GLContextType;
mtklein60c77072014-08-14 10:36:55 -070065static const GrContextFactory::GLContextType nvpr = GrContextFactory::kNVPR_GLContextType;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000066static const GrContextFactory::GLContextType null = GrContextFactory::kNull_GLContextType;
67static const GrContextFactory::GLContextType debug = GrContextFactory::kDebug_GLContextType;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000068#if SK_ANGLE
mtklein60c77072014-08-14 10:36:55 -070069static const GrContextFactory::GLContextType angle = GrContextFactory::kANGLE_GLContextType;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000070#endif
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000071#if SK_MESA
mtklein60c77072014-08-14 10:36:55 -070072static const GrContextFactory::GLContextType mesa = GrContextFactory::kMESA_GLContextType;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000073#endif
74
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000075static void kick_off_gms(const SkTDArray<GMRegistry::Factory>& gms,
76 const SkTArray<SkString>& configs,
kkinnunen80549fc2014-06-30 06:36:31 -070077 GrGLStandard gpuAPI,
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000078 DM::Reporter* reporter,
79 DM::TaskRunner* tasks) {
mtkleine4d3e602014-06-06 09:28:43 -070080#define START(name, type, ...) \
81 if (lowercase(configs[j]).equals(name)) { \
82 tasks->add(SkNEW_ARGS(DM::type, (name, reporter, tasks, gms[i], ## __VA_ARGS__))); \
mtklein@google.comd36522d2013-10-16 13:02:15 +000083 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +000084 for (int i = 0; i < gms.count(); i++) {
mtklein@google.comd36522d2013-10-16 13:02:15 +000085 for (int j = 0; j < configs.count(); j++) {
kkinnunen80549fc2014-06-30 06:36:31 -070086
mtklein197ceda2014-09-09 07:36:57 -070087 START("565", CpuGMTask, kRGB_565_SkColorType);
88 START("8888", CpuGMTask, kN32_SkColorType);
89 START("gpu", GpuGMTask, native, gpuAPI, 0);
90 START("msaa4", GpuGMTask, native, gpuAPI, 4);
91 START("msaa16", GpuGMTask, native, gpuAPI, 16);
92 START("nvprmsaa4", GpuGMTask, nvpr, gpuAPI, 4);
93 START("nvprmsaa16", GpuGMTask, nvpr, gpuAPI, 16);
94 START("gpunull", GpuGMTask, null, gpuAPI, 0);
95 START("gpudebug", GpuGMTask, debug, gpuAPI, 0);
mtklein60c77072014-08-14 10:36:55 -070096#if SK_ANGLE
mtklein197ceda2014-09-09 07:36:57 -070097 START("angle", GpuGMTask, angle, gpuAPI, 0);
mtklein60c77072014-08-14 10:36:55 -070098#endif
99#if SK_MESA
mtklein197ceda2014-09-09 07:36:57 -0700100 START("mesa", GpuGMTask, mesa, gpuAPI, 0);
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();
190int dm_main() {
mtklein30e6e2a2014-06-18 11:44:15 -0700191 SetupCrashHandler();
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000192 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -0700193 SkTaskGroup::Enabler enabled(FLAGS_threads);
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +0000194
bsalomon06cddec2014-10-24 10:40:50 -0700195 if (FLAGS_dryRun || FLAGS_veryVerbose) {
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +0000196 FLAGS_verbose = true;
197 }
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000198#if SK_ENABLE_INST_COUNT
199 gPrintInstCount = FLAGS_leaks;
200#endif
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000201
mtklein@google.comd36522d2013-10-16 13:02:15 +0000202 SkTArray<SkString> configs;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000203 for (int i = 0; i < FLAGS_config.count(); i++) {
204 SkStrSplit(FLAGS_config[i], ", ", &configs);
205 }
206
kkinnunen80549fc2014-06-30 06:36:31 -0700207 GrGLStandard gpuAPI = get_gl_standard();
208
mtklein@google.comd36522d2013-10-16 13:02:15 +0000209 SkTDArray<GMRegistry::Factory> gms;
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000210 if (FLAGS_gms) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000211 append_matching_factories<GM>(GMRegistry::Head(), &gms);
mtklein@google.comd36522d2013-10-16 13:02:15 +0000212 }
213
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000214 SkTDArray<TestRegistry::Factory> tests;
215 if (FLAGS_tests) {
216 append_matching_factories<Test>(TestRegistry::Head(), &tests);
217 }
218
halcanarya98683b2014-07-28 07:21:24 -0700219 SkTArray<SkString> skps;
220 find_skps(&skps);
221
222 SkDebugf("%d GMs x %d configs, %d tests, %d pictures\n",
223 gms.count(), configs.count(), tests.count(), skps.count());
mtklein@google.comd36522d2013-10-16 13:02:15 +0000224 DM::Reporter reporter;
mtklein406654b2014-09-03 15:34:37 -0700225
226 DM::TaskRunner tasks;
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000227 kick_off_tests(tests, &reporter, &tasks);
mtklein197ceda2014-09-09 07:36:57 -0700228 kick_off_gms(gms, configs, gpuAPI, &reporter, &tasks);
229 kick_off_skps(skps, &reporter, &tasks);
mtklein@google.comd36522d2013-10-16 13:02:15 +0000230 tasks.wait();
231
scroggo7a10fb62014-11-04 07:21:10 -0800232 DM::JsonWriter::DumpJson();
mtklein1d0f1642014-09-08 08:05:18 -0700233
mtklein@google.comd36522d2013-10-16 13:02:15 +0000234 SkDebugf("\n");
Cary Clark992c7b02014-07-31 08:58:44 -0400235#ifdef SK_DEBUG
236 if (FLAGS_portableFonts && FLAGS_reportUsedChars) {
237 sk_tool_utils::report_used_chars();
238 }
239#endif
mtklein92007582014-08-01 07:46:52 -0700240
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000241 SkTArray<SkString> failures;
242 reporter.getFailures(&failures);
243 report_failures(failures);
244 return failures.count() > 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000245}
commit-bot@chromium.org846872f2013-10-16 18:21:03 +0000246
247#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
248int main(int argc, char** argv) {
caryclark17f0b6d2014-07-22 10:15:34 -0700249 SkCommandLineFlags::Parse(argc, argv);
250 return dm_main();
commit-bot@chromium.org846872f2013-10-16 18:21:03 +0000251}
252#endif