blob: 52c86d5f6880dc6f79f0e759808ec1d021a84f07 [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
jcgregorio3b27ade2014-11-13 08:06:40 -08004#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);
jvanverth4736e142014-11-07 07:12:46 -080089 START("gpu", GpuGMTask, native, gpuAPI, 0, false);
90 START("msaa4", GpuGMTask, native, gpuAPI, 4, false);
91 START("msaa16", GpuGMTask, native, gpuAPI, 16, false);
92 START("nvprmsaa4", GpuGMTask, nvpr, gpuAPI, 4, false);
93 START("nvprmsaa16", GpuGMTask, nvpr, gpuAPI, 16, false);
94 START("gpudft", GpuGMTask, native, gpuAPI, 0, true);
95 START("gpunull", GpuGMTask, null, gpuAPI, 0, false);
96 START("gpudebug", GpuGMTask, debug, gpuAPI, 0, false);
mtklein60c77072014-08-14 10:36:55 -070097#if SK_ANGLE
jvanverth4736e142014-11-07 07:12:46 -080098 START("angle", GpuGMTask, angle, gpuAPI, 0, false);
mtklein60c77072014-08-14 10:36:55 -070099#endif
100#if SK_MESA
jvanverth4736e142014-11-07 07:12:46 -0800101 START("mesa", GpuGMTask, mesa, gpuAPI, 0, false);
mtklein60c77072014-08-14 10:36:55 -0700102#endif
mtklein30bf3e22014-06-03 13:57:14 -0700103 START("pdf", PDFTask, RASTERIZE_PDF_PROC);
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000104 }
105 }
106#undef START
107}
108
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000109static void kick_off_tests(const SkTDArray<TestRegistry::Factory>& tests,
110 DM::Reporter* reporter,
111 DM::TaskRunner* tasks) {
112 for (int i = 0; i < tests.count(); i++) {
commit-bot@chromium.orgef57b7e2014-02-28 20:31:31 +0000113 SkAutoTDelete<Test> test(tests[i](NULL));
114 if (test->isGPUTest()) {
115 tasks->add(SkNEW_ARGS(DM::GpuTestTask, (reporter, tasks, tests[i])));
116 } else {
117 tasks->add(SkNEW_ARGS(DM::CpuTestTask, (reporter, tasks, tests[i])));
118 }
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000119 }
120}
121
halcanarya98683b2014-07-28 07:21:24 -0700122static void find_skps(SkTArray<SkString>* skps) {
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000123 if (FLAGS_skps.isEmpty()) {
124 return;
125 }
126
127 SkOSFile::Iter it(FLAGS_skps[0], ".skp");
128 SkString filename;
129 while (it.next(&filename)) {
halcanarya98683b2014-07-28 07:21:24 -0700130 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, filename.c_str())) {
tfarinaa8e2e152014-07-28 19:26:58 -0700131 skps->push_back(SkOSPath::Join(FLAGS_skps[0], filename.c_str()));
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000132 }
halcanarya98683b2014-07-28 07:21:24 -0700133 }
134}
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000135
halcanarya98683b2014-07-28 07:21:24 -0700136static void kick_off_skps(const SkTArray<SkString>& skps,
mtklein23c94f02014-09-08 09:12:28 -0700137 DM::Reporter* reporter,
138 DM::TaskRunner* tasks) {
halcanarya98683b2014-07-28 07:21:24 -0700139 for (int i = 0; i < skps.count(); ++i) {
140 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(skps[i].c_str()));
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000141 if (stream.get() == NULL) {
halcanarya98683b2014-07-28 07:21:24 -0700142 SkDebugf("Could not read %s.\n", skps[i].c_str());
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000143 exit(1);
144 }
mtklein72ebb9f2014-08-07 14:27:03 -0700145 SkAutoTUnref<SkPicture> pic(
146 SkPicture::CreateFromStream(stream.get(), &sk_tools::LazyDecodeBitmap));
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000147 if (pic.get() == NULL) {
halcanarya98683b2014-07-28 07:21:24 -0700148 SkDebugf("Could not read %s as an SkPicture.\n", skps[i].c_str());
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000149 exit(1);
150 }
151
tfarinaa8e2e152014-07-28 19:26:58 -0700152 SkString filename = SkOSPath::Basename(skps[i].c_str());
mtklein197ceda2014-09-09 07:36:57 -0700153 tasks->add(SkNEW_ARGS(DM::SKPTask, (reporter, tasks, pic, filename)));
154 tasks->add(SkNEW_ARGS(DM::PDFTask, (reporter, tasks, pic, filename, RASTERIZE_PDF_PROC)));
commit-bot@chromium.org90b5a2a2014-05-14 17:55:32 +0000155 }
156}
157
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000158static void report_failures(const SkTArray<SkString>& failures) {
mtklein@google.comd36522d2013-10-16 13:02:15 +0000159 if (failures.count() == 0) {
160 return;
161 }
162
163 SkDebugf("Failures:\n");
164 for (int i = 0; i < failures.count(); i++) {
165 SkDebugf(" %s\n", failures[i].c_str());
166 }
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000167 SkDebugf("%d failures.\n", failures.count());
mtklein@google.comd36522d2013-10-16 13:02:15 +0000168}
169
kkinnunen80549fc2014-06-30 06:36:31 -0700170static GrGLStandard get_gl_standard() {
171 if (FLAGS_gpuAPI.contains(kGpuAPINameGL)) {
172 return kGL_GrGLStandard;
173 }
174 if (FLAGS_gpuAPI.contains(kGpuAPINameGLES)) {
175 return kGLES_GrGLStandard;
176 }
177 return kNone_GrGLStandard;
178}
179
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000180template <typename T, typename Registry>
181static void append_matching_factories(Registry* head, SkTDArray<typename Registry::Factory>* out) {
182 for (const Registry* reg = head; reg != NULL; reg = reg->next()) {
183 SkAutoTDelete<T> forName(reg->factory()(NULL));
184 if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, forName->getName())) {
185 *out->append() = reg->factory();
186 }
187 }
188}
189
jcgregorio3b27ade2014-11-13 08:06:40 -0800190int dm_main();
caryclark17f0b6d2014-07-22 10:15:34 -0700191int dm_main() {
jcgregorio3b27ade2014-11-13 08:06:40 -0800192 SetupCrashHandler();
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000193 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -0700194 SkTaskGroup::Enabler enabled(FLAGS_threads);
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +0000195
bsalomon06cddec2014-10-24 10:40:50 -0700196 if (FLAGS_dryRun || FLAGS_veryVerbose) {
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +0000197 FLAGS_verbose = true;
198 }
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000199#if SK_ENABLE_INST_COUNT
200 gPrintInstCount = FLAGS_leaks;
201#endif
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000202
mtklein@google.comd36522d2013-10-16 13:02:15 +0000203 SkTArray<SkString> configs;
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000204 for (int i = 0; i < FLAGS_config.count(); i++) {
205 SkStrSplit(FLAGS_config[i], ", ", &configs);
206 }
207
kkinnunen80549fc2014-06-30 06:36:31 -0700208 GrGLStandard gpuAPI = get_gl_standard();
209
mtklein@google.comd36522d2013-10-16 13:02:15 +0000210 SkTDArray<GMRegistry::Factory> gms;
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000211 if (FLAGS_gms) {
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000212 append_matching_factories<GM>(GMRegistry::Head(), &gms);
mtklein@google.comd36522d2013-10-16 13:02:15 +0000213 }
214
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000215 SkTDArray<TestRegistry::Factory> tests;
216 if (FLAGS_tests) {
217 append_matching_factories<Test>(TestRegistry::Head(), &tests);
218 }
219
halcanarya98683b2014-07-28 07:21:24 -0700220 SkTArray<SkString> skps;
221 find_skps(&skps);
222
223 SkDebugf("%d GMs x %d configs, %d tests, %d pictures\n",
224 gms.count(), configs.count(), tests.count(), skps.count());
mtklein@google.comd36522d2013-10-16 13:02:15 +0000225 DM::Reporter reporter;
mtklein406654b2014-09-03 15:34:37 -0700226
227 DM::TaskRunner tasks;
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000228 kick_off_tests(tests, &reporter, &tasks);
mtklein197ceda2014-09-09 07:36:57 -0700229 kick_off_gms(gms, configs, gpuAPI, &reporter, &tasks);
230 kick_off_skps(skps, &reporter, &tasks);
mtklein@google.comd36522d2013-10-16 13:02:15 +0000231 tasks.wait();
232
scroggo7a10fb62014-11-04 07:21:10 -0800233 DM::JsonWriter::DumpJson();
mtklein1d0f1642014-09-08 08:05:18 -0700234
mtklein@google.comd36522d2013-10-16 13:02:15 +0000235 SkDebugf("\n");
Cary Clark992c7b02014-07-31 08:58:44 -0400236#ifdef SK_DEBUG
237 if (FLAGS_portableFonts && FLAGS_reportUsedChars) {
238 sk_tool_utils::report_used_chars();
239 }
240#endif
mtklein92007582014-08-01 07:46:52 -0700241
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000242 SkTArray<SkString> failures;
243 reporter.getFailures(&failures);
244 report_failures(failures);
245 return failures.count() > 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000246}
jcgregorio3b27ade2014-11-13 08:06:40 -0800247
248#if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
249int main(int argc, char** argv) {
250 SkCommandLineFlags::Parse(argc, argv);
251 return dm_main();
252}
253#endif