mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 1 | // Main binary for DM. |
| 2 | // For a high-level overview, please see dm/README. |
| 3 | |
tfarina | f168b86 | 2014-06-19 12:32:29 -0700 | [diff] [blame] | 4 | #include "CrashHandler.h" |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 5 | #include "SkCommonFlags.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 6 | #include "SkForceLinking.h" |
| 7 | #include "SkGraphics.h" |
commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 8 | #include "SkPicture.h" |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 9 | #include "SkString.h" |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 10 | #include "Test.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 11 | #include "gm.h" |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 12 | #include "sk_tool_utils.h" |
| 13 | #include "sk_tool_utils_flags.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 14 | |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 15 | #include "DMCpuGMTask.h" |
| 16 | #include "DMGpuGMTask.h" |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 17 | #include "DMGpuSupport.h" |
mtklein | 30bf3e2 | 2014-06-03 13:57:14 -0700 | [diff] [blame] | 18 | #include "DMPDFTask.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 19 | #include "DMReporter.h" |
commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 20 | #include "DMSKPTask.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 21 | #include "DMTask.h" |
| 22 | #include "DMTaskRunner.h" |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 23 | #include "DMTestTask.h" |
commit-bot@chromium.org | 99589af | 2013-12-10 14:53:16 +0000 | [diff] [blame] | 24 | #include "DMWriteTask.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 25 | |
mtklein | 30bf3e2 | 2014-06-03 13:57:14 -0700 | [diff] [blame] | 26 | #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.org | 120c999 | 2014-05-16 18:11:51 +0000 | [diff] [blame] | 33 | #include <ctype.h> |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 34 | |
| 35 | using skiagm::GM; |
| 36 | using skiagm::GMRegistry; |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 37 | using skiatest::Test; |
| 38 | using skiatest::TestRegistry; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 39 | |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 40 | static const char kGpuAPINameGL[] = "gl"; |
| 41 | static const char kGpuAPINameGLES[] = "gles"; |
| 42 | |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 43 | DEFINE_int32(gpuThreads, 1, "Threads for GPU work."); |
commit-bot@chromium.org | 99589af | 2013-12-10 14:53:16 +0000 | [diff] [blame] | 44 | DEFINE_string2(expectations, r, "", |
| 45 | "If a directory, compare generated images against images under this path. " |
commit-bot@chromium.org | 120c999 | 2014-05-16 18:11:51 +0000 | [diff] [blame] | 46 | "If a file, compare generated images against JSON expectations at this path." |
commit-bot@chromium.org | 120c999 | 2014-05-16 18:11:51 +0000 | [diff] [blame] | 47 | ); |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 48 | |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 49 | DEFINE_bool(gms, true, "Run GMs?"); |
| 50 | DEFINE_bool(tests, true, "Run tests?"); |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 51 | DEFINE_bool(reportUsedChars, false, "Output test font construction data to be pasted into" |
| 52 | " create_test_font.cpp."); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 53 | |
| 54 | __SK_FORCE_IMAGE_DECODER_LINKING; |
| 55 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 56 | // "FooBar" -> "foobar". Obviously, ASCII only. |
| 57 | static 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.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 64 | static const GrContextFactory::GLContextType native = GrContextFactory::kNative_GLContextType; |
commit-bot@chromium.org | b640186 | 2014-03-12 14:46:31 +0000 | [diff] [blame] | 65 | static const GrContextFactory::GLContextType nvpr = GrContextFactory::kNVPR_GLContextType; |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 66 | static const GrContextFactory::GLContextType null = GrContextFactory::kNull_GLContextType; |
| 67 | static const GrContextFactory::GLContextType debug = GrContextFactory::kDebug_GLContextType; |
| 68 | static const GrContextFactory::GLContextType angle = |
| 69 | #if SK_ANGLE |
| 70 | GrContextFactory::kANGLE_GLContextType; |
| 71 | #else |
| 72 | native; |
| 73 | #endif |
| 74 | static const GrContextFactory::GLContextType mesa = |
| 75 | #if SK_MESA |
bsalomon@google.com | 9dccafa | 2014-05-02 14:43:12 +0000 | [diff] [blame] | 76 | GrContextFactory::kMESA_GLContextType; |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 77 | #else |
| 78 | native; |
| 79 | #endif |
| 80 | |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 81 | static void kick_off_gms(const SkTDArray<GMRegistry::Factory>& gms, |
| 82 | const SkTArray<SkString>& configs, |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 83 | GrGLStandard gpuAPI, |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 84 | const DM::Expectations& expectations, |
| 85 | DM::Reporter* reporter, |
| 86 | DM::TaskRunner* tasks) { |
mtklein | e4d3e60 | 2014-06-06 09:28:43 -0700 | [diff] [blame] | 87 | #define START(name, type, ...) \ |
| 88 | if (lowercase(configs[j]).equals(name)) { \ |
| 89 | tasks->add(SkNEW_ARGS(DM::type, (name, reporter, tasks, gms[i], ## __VA_ARGS__))); \ |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 90 | } |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 91 | for (int i = 0; i < gms.count(); i++) { |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 92 | for (int j = 0; j < configs.count(); j++) { |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 93 | |
mtklein | e4d3e60 | 2014-06-06 09:28:43 -0700 | [diff] [blame] | 94 | START("565", CpuGMTask, expectations, kRGB_565_SkColorType); |
| 95 | START("8888", CpuGMTask, expectations, kN32_SkColorType); |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 96 | START("gpu", GpuGMTask, expectations, native, gpuAPI, 0); |
| 97 | START("msaa4", GpuGMTask, expectations, native, gpuAPI, 4); |
| 98 | START("msaa16", GpuGMTask, expectations, native, gpuAPI, 16); |
| 99 | START("nvprmsaa4", GpuGMTask, expectations, nvpr, gpuAPI, 4); |
| 100 | START("nvprmsaa16", GpuGMTask, expectations, nvpr, gpuAPI, 16); |
| 101 | START("gpunull", GpuGMTask, expectations, null, gpuAPI, 0); |
| 102 | START("gpudebug", GpuGMTask, expectations, debug, gpuAPI, 0); |
| 103 | START("angle", GpuGMTask, expectations, angle, gpuAPI, 0); |
| 104 | START("mesa", GpuGMTask, expectations, mesa, gpuAPI, 0); |
mtklein | 30bf3e2 | 2014-06-03 13:57:14 -0700 | [diff] [blame] | 105 | START("pdf", PDFTask, RASTERIZE_PDF_PROC); |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | #undef START |
| 109 | } |
| 110 | |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 111 | static void kick_off_tests(const SkTDArray<TestRegistry::Factory>& tests, |
| 112 | DM::Reporter* reporter, |
| 113 | DM::TaskRunner* tasks) { |
| 114 | for (int i = 0; i < tests.count(); i++) { |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 115 | SkAutoTDelete<Test> test(tests[i](NULL)); |
| 116 | if (test->isGPUTest()) { |
| 117 | tasks->add(SkNEW_ARGS(DM::GpuTestTask, (reporter, tasks, tests[i]))); |
| 118 | } else { |
| 119 | tasks->add(SkNEW_ARGS(DM::CpuTestTask, (reporter, tasks, tests[i]))); |
| 120 | } |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 121 | } |
| 122 | } |
| 123 | |
halcanary | a98683b | 2014-07-28 07:21:24 -0700 | [diff] [blame] | 124 | static void find_skps(SkTArray<SkString>* skps) { |
commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 125 | if (FLAGS_skps.isEmpty()) { |
| 126 | return; |
| 127 | } |
| 128 | |
| 129 | SkOSFile::Iter it(FLAGS_skps[0], ".skp"); |
| 130 | SkString filename; |
| 131 | while (it.next(&filename)) { |
halcanary | a98683b | 2014-07-28 07:21:24 -0700 | [diff] [blame] | 132 | if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, filename.c_str())) { |
tfarina | a8e2e15 | 2014-07-28 19:26:58 -0700 | [diff] [blame] | 133 | skps->push_back(SkOSPath::Join(FLAGS_skps[0], filename.c_str())); |
commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 134 | } |
halcanary | a98683b | 2014-07-28 07:21:24 -0700 | [diff] [blame] | 135 | } |
| 136 | } |
commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 137 | |
halcanary | a98683b | 2014-07-28 07:21:24 -0700 | [diff] [blame] | 138 | static void kick_off_skps(const SkTArray<SkString>& skps, |
| 139 | DM::Reporter* reporter, DM::TaskRunner* tasks) { |
| 140 | for (int i = 0; i < skps.count(); ++i) { |
| 141 | SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(skps[i].c_str())); |
commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 142 | if (stream.get() == NULL) { |
halcanary | a98683b | 2014-07-28 07:21:24 -0700 | [diff] [blame] | 143 | SkDebugf("Could not read %s.\n", skps[i].c_str()); |
commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 144 | exit(1); |
| 145 | } |
| 146 | SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream.get())); |
| 147 | if (pic.get() == NULL) { |
halcanary | a98683b | 2014-07-28 07:21:24 -0700 | [diff] [blame] | 148 | SkDebugf("Could not read %s as an SkPicture.\n", skps[i].c_str()); |
commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 149 | exit(1); |
| 150 | } |
| 151 | |
tfarina | a8e2e15 | 2014-07-28 19:26:58 -0700 | [diff] [blame] | 152 | SkString filename = SkOSPath::Basename(skps[i].c_str()); |
mtklein | d3e474e | 2014-06-27 12:34:44 -0700 | [diff] [blame] | 153 | tasks->add(SkNEW_ARGS(DM::SKPTask, (reporter, tasks, pic, filename))); |
| 154 | tasks->add(SkNEW_ARGS(DM::PDFTask, (reporter, tasks, pic, filename, |
mtklein | e4d3e60 | 2014-06-06 09:28:43 -0700 | [diff] [blame] | 155 | RASTERIZE_PDF_PROC))); |
commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 156 | } |
| 157 | } |
| 158 | |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 159 | static void report_failures(const SkTArray<SkString>& failures) { |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 160 | if (failures.count() == 0) { |
| 161 | return; |
| 162 | } |
| 163 | |
| 164 | SkDebugf("Failures:\n"); |
| 165 | for (int i = 0; i < failures.count(); i++) { |
| 166 | SkDebugf(" %s\n", failures[i].c_str()); |
| 167 | } |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 168 | SkDebugf("%d failures.\n", failures.count()); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 169 | } |
| 170 | |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 171 | static GrGLStandard get_gl_standard() { |
| 172 | if (FLAGS_gpuAPI.contains(kGpuAPINameGL)) { |
| 173 | return kGL_GrGLStandard; |
| 174 | } |
| 175 | if (FLAGS_gpuAPI.contains(kGpuAPINameGLES)) { |
| 176 | return kGLES_GrGLStandard; |
| 177 | } |
| 178 | return kNone_GrGLStandard; |
| 179 | } |
| 180 | |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 181 | template <typename T, typename Registry> |
| 182 | static void append_matching_factories(Registry* head, SkTDArray<typename Registry::Factory>* out) { |
| 183 | for (const Registry* reg = head; reg != NULL; reg = reg->next()) { |
| 184 | SkAutoTDelete<T> forName(reg->factory()(NULL)); |
| 185 | if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, forName->getName())) { |
| 186 | *out->append() = reg->factory(); |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 191 | int dm_main(); |
| 192 | int dm_main() { |
mtklein | 30e6e2a | 2014-06-18 11:44:15 -0700 | [diff] [blame] | 193 | SetupCrashHandler(); |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 194 | SkAutoGraphics ag; |
commit-bot@chromium.org | a65e2fd | 2014-05-30 17:23:31 +0000 | [diff] [blame] | 195 | |
| 196 | if (FLAGS_dryRun) { |
| 197 | FLAGS_verbose = true; |
| 198 | } |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 199 | #if SK_ENABLE_INST_COUNT |
| 200 | gPrintInstCount = FLAGS_leaks; |
| 201 | #endif |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 202 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 203 | SkTArray<SkString> configs; |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 204 | for (int i = 0; i < FLAGS_config.count(); i++) { |
| 205 | SkStrSplit(FLAGS_config[i], ", ", &configs); |
| 206 | } |
| 207 | |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 208 | GrGLStandard gpuAPI = get_gl_standard(); |
| 209 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 210 | SkTDArray<GMRegistry::Factory> gms; |
commit-bot@chromium.org | 99589af | 2013-12-10 14:53:16 +0000 | [diff] [blame] | 211 | SkAutoTDelete<DM::Expectations> expectations(SkNEW(DM::NoExpectations)); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 212 | if (FLAGS_gms) { |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 213 | append_matching_factories<GM>(GMRegistry::Head(), &gms); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 214 | |
| 215 | if (FLAGS_expectations.count() > 0) { |
| 216 | const char* path = FLAGS_expectations[0]; |
| 217 | if (sk_isdir(path)) { |
| 218 | expectations.reset(SkNEW_ARGS(DM::WriteTask::Expectations, (path))); |
| 219 | } else { |
| 220 | expectations.reset(SkNEW_ARGS(DM::JsonExpectations, (path))); |
| 221 | } |
commit-bot@chromium.org | 99589af | 2013-12-10 14:53:16 +0000 | [diff] [blame] | 222 | } |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 223 | } |
| 224 | |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 225 | SkTDArray<TestRegistry::Factory> tests; |
| 226 | if (FLAGS_tests) { |
| 227 | append_matching_factories<Test>(TestRegistry::Head(), &tests); |
| 228 | } |
| 229 | |
halcanary | a98683b | 2014-07-28 07:21:24 -0700 | [diff] [blame] | 230 | SkTArray<SkString> skps; |
| 231 | find_skps(&skps); |
| 232 | |
| 233 | SkDebugf("%d GMs x %d configs, %d tests, %d pictures\n", |
| 234 | gms.count(), configs.count(), tests.count(), skps.count()); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 235 | DM::Reporter reporter; |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 236 | DM::TaskRunner tasks(FLAGS_threads, FLAGS_gpuThreads); |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 237 | kick_off_gms(gms, configs, gpuAPI, *expectations, &reporter, &tasks); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 238 | kick_off_tests(tests, &reporter, &tasks); |
halcanary | a98683b | 2014-07-28 07:21:24 -0700 | [diff] [blame] | 239 | kick_off_skps(skps, &reporter, &tasks); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 240 | tasks.wait(); |
| 241 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 242 | SkDebugf("\n"); |
Cary Clark | 992c7b0 | 2014-07-31 08:58:44 -0400 | [diff] [blame] | 243 | #ifdef SK_DEBUG |
| 244 | if (FLAGS_portableFonts && FLAGS_reportUsedChars) { |
| 245 | sk_tool_utils::report_used_chars(); |
| 246 | } |
| 247 | #endif |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame^] | 248 | |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 249 | SkTArray<SkString> failures; |
| 250 | reporter.getFailures(&failures); |
| 251 | report_failures(failures); |
| 252 | return failures.count() > 0; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 253 | } |
commit-bot@chromium.org | 846872f | 2013-10-16 18:21:03 +0000 | [diff] [blame] | 254 | |
| 255 | #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
| 256 | int main(int argc, char** argv) { |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 257 | SkCommandLineFlags::Parse(argc, argv); |
| 258 | return dm_main(); |
commit-bot@chromium.org | 846872f | 2013-10-16 18:21:03 +0000 | [diff] [blame] | 259 | } |
| 260 | #endif |