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" |
| 12 | |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 13 | #include "DMCpuGMTask.h" |
| 14 | #include "DMGpuGMTask.h" |
commit-bot@chromium.org | 787227d | 2014-03-26 21:26:15 +0000 | [diff] [blame] | 15 | #include "DMGpuSupport.h" |
mtklein | 30bf3e2 | 2014-06-03 13:57:14 -0700 | [diff] [blame] | 16 | #include "DMPDFTask.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 17 | #include "DMReporter.h" |
commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 18 | #include "DMSKPTask.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 19 | #include "DMTask.h" |
| 20 | #include "DMTaskRunner.h" |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 21 | #include "DMTestTask.h" |
commit-bot@chromium.org | 99589af | 2013-12-10 14:53:16 +0000 | [diff] [blame] | 22 | #include "DMWriteTask.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 23 | |
mtklein | 30bf3e2 | 2014-06-03 13:57:14 -0700 | [diff] [blame] | 24 | #ifdef SK_BUILD_POPPLER |
| 25 | # include "SkPDFRasterizer.h" |
| 26 | # define RASTERIZE_PDF_PROC SkPopplerRasterizePDF |
| 27 | #else |
| 28 | # define RASTERIZE_PDF_PROC NULL |
| 29 | #endif |
| 30 | |
commit-bot@chromium.org | 120c999 | 2014-05-16 18:11:51 +0000 | [diff] [blame] | 31 | #include <ctype.h> |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 32 | |
| 33 | using skiagm::GM; |
| 34 | using skiagm::GMRegistry; |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 35 | using skiatest::Test; |
| 36 | using skiatest::TestRegistry; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 37 | |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 38 | static const char kGpuAPINameGL[] = "gl"; |
| 39 | static const char kGpuAPINameGLES[] = "gles"; |
| 40 | |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 41 | DEFINE_int32(gpuThreads, 1, "Threads for GPU work."); |
commit-bot@chromium.org | 99589af | 2013-12-10 14:53:16 +0000 | [diff] [blame] | 42 | DEFINE_string2(expectations, r, "", |
| 43 | "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] | 44 | "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] | 45 | ); |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 46 | |
commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 47 | DEFINE_string(skps, "", "Directory to read skps from."); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 48 | |
| 49 | DEFINE_bool(gms, true, "Run GMs?"); |
| 50 | DEFINE_bool(tests, true, "Run tests?"); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 51 | |
| 52 | __SK_FORCE_IMAGE_DECODER_LINKING; |
| 53 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 54 | // "FooBar" -> "foobar". Obviously, ASCII only. |
| 55 | static SkString lowercase(SkString s) { |
| 56 | for (size_t i = 0; i < s.size(); i++) { |
| 57 | s[i] = tolower(s[i]); |
| 58 | } |
| 59 | return s; |
| 60 | } |
| 61 | |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 62 | static const GrContextFactory::GLContextType native = GrContextFactory::kNative_GLContextType; |
commit-bot@chromium.org | b640186 | 2014-03-12 14:46:31 +0000 | [diff] [blame] | 63 | static const GrContextFactory::GLContextType nvpr = GrContextFactory::kNVPR_GLContextType; |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 64 | static const GrContextFactory::GLContextType null = GrContextFactory::kNull_GLContextType; |
| 65 | static const GrContextFactory::GLContextType debug = GrContextFactory::kDebug_GLContextType; |
| 66 | static const GrContextFactory::GLContextType angle = |
| 67 | #if SK_ANGLE |
| 68 | GrContextFactory::kANGLE_GLContextType; |
| 69 | #else |
| 70 | native; |
| 71 | #endif |
| 72 | static const GrContextFactory::GLContextType mesa = |
| 73 | #if SK_MESA |
bsalomon@google.com | 9dccafa | 2014-05-02 14:43:12 +0000 | [diff] [blame] | 74 | GrContextFactory::kMESA_GLContextType; |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 75 | #else |
| 76 | native; |
| 77 | #endif |
| 78 | |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 79 | static void kick_off_gms(const SkTDArray<GMRegistry::Factory>& gms, |
| 80 | const SkTArray<SkString>& configs, |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 81 | GrGLStandard gpuAPI, |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 82 | const DM::Expectations& expectations, |
| 83 | DM::Reporter* reporter, |
| 84 | DM::TaskRunner* tasks) { |
mtklein | e4d3e60 | 2014-06-06 09:28:43 -0700 | [diff] [blame] | 85 | #define START(name, type, ...) \ |
| 86 | if (lowercase(configs[j]).equals(name)) { \ |
| 87 | 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] | 88 | } |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 89 | for (int i = 0; i < gms.count(); i++) { |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 90 | for (int j = 0; j < configs.count(); j++) { |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 91 | |
mtklein | e4d3e60 | 2014-06-06 09:28:43 -0700 | [diff] [blame] | 92 | START("565", CpuGMTask, expectations, kRGB_565_SkColorType); |
| 93 | START("8888", CpuGMTask, expectations, kN32_SkColorType); |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 94 | START("gpu", GpuGMTask, expectations, native, gpuAPI, 0); |
| 95 | START("msaa4", GpuGMTask, expectations, native, gpuAPI, 4); |
| 96 | START("msaa16", GpuGMTask, expectations, native, gpuAPI, 16); |
| 97 | START("nvprmsaa4", GpuGMTask, expectations, nvpr, gpuAPI, 4); |
| 98 | START("nvprmsaa16", GpuGMTask, expectations, nvpr, gpuAPI, 16); |
| 99 | START("gpunull", GpuGMTask, expectations, null, gpuAPI, 0); |
| 100 | START("gpudebug", GpuGMTask, expectations, debug, gpuAPI, 0); |
| 101 | START("angle", GpuGMTask, expectations, angle, gpuAPI, 0); |
| 102 | START("mesa", GpuGMTask, expectations, mesa, gpuAPI, 0); |
mtklein | 30bf3e2 | 2014-06-03 13:57:14 -0700 | [diff] [blame] | 103 | START("pdf", PDFTask, RASTERIZE_PDF_PROC); |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | #undef START |
| 107 | } |
| 108 | |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 109 | static 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.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 113 | 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.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 119 | } |
| 120 | } |
| 121 | |
halcanary | a98683b | 2014-07-28 07:21:24 -0700 | [diff] [blame^] | 122 | static void find_skps(SkTArray<SkString>* skps) { |
commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 123 | if (FLAGS_skps.isEmpty()) { |
| 124 | return; |
| 125 | } |
| 126 | |
| 127 | SkOSFile::Iter it(FLAGS_skps[0], ".skp"); |
| 128 | SkString filename; |
| 129 | while (it.next(&filename)) { |
halcanary | a98683b | 2014-07-28 07:21:24 -0700 | [diff] [blame^] | 130 | if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, filename.c_str())) { |
| 131 | skps->push_back( |
| 132 | SkOSPath::SkPathJoin(FLAGS_skps[0], filename.c_str())); |
commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 133 | } |
halcanary | a98683b | 2014-07-28 07:21:24 -0700 | [diff] [blame^] | 134 | } |
| 135 | } |
commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 136 | |
halcanary | a98683b | 2014-07-28 07:21:24 -0700 | [diff] [blame^] | 137 | static void kick_off_skps(const SkTArray<SkString>& skps, |
| 138 | DM::Reporter* reporter, DM::TaskRunner* tasks) { |
| 139 | for (int i = 0; i < skps.count(); ++i) { |
| 140 | SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(skps[i].c_str())); |
commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 141 | if (stream.get() == NULL) { |
halcanary | a98683b | 2014-07-28 07:21:24 -0700 | [diff] [blame^] | 142 | SkDebugf("Could not read %s.\n", skps[i].c_str()); |
commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 143 | exit(1); |
| 144 | } |
| 145 | SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream.get())); |
| 146 | if (pic.get() == NULL) { |
halcanary | a98683b | 2014-07-28 07:21:24 -0700 | [diff] [blame^] | 147 | 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] | 148 | exit(1); |
| 149 | } |
| 150 | |
halcanary | a98683b | 2014-07-28 07:21:24 -0700 | [diff] [blame^] | 151 | SkString filename = SkOSPath::SkBasename(skps[i].c_str()); |
mtklein | d3e474e | 2014-06-27 12:34:44 -0700 | [diff] [blame] | 152 | tasks->add(SkNEW_ARGS(DM::SKPTask, (reporter, tasks, pic, filename))); |
| 153 | tasks->add(SkNEW_ARGS(DM::PDFTask, (reporter, tasks, pic, filename, |
mtklein | e4d3e60 | 2014-06-06 09:28:43 -0700 | [diff] [blame] | 154 | RASTERIZE_PDF_PROC))); |
commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 155 | } |
| 156 | } |
| 157 | |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 158 | static void report_failures(const SkTArray<SkString>& failures) { |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 159 | 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.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 167 | SkDebugf("%d failures.\n", failures.count()); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 168 | } |
| 169 | |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 170 | static 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.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 180 | template <typename T, typename Registry> |
| 181 | static 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 | |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 190 | int dm_main(); |
| 191 | int dm_main() { |
mtklein | 30e6e2a | 2014-06-18 11:44:15 -0700 | [diff] [blame] | 192 | SetupCrashHandler(); |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 193 | SkAutoGraphics ag; |
commit-bot@chromium.org | a65e2fd | 2014-05-30 17:23:31 +0000 | [diff] [blame] | 194 | |
| 195 | if (FLAGS_dryRun) { |
| 196 | FLAGS_verbose = true; |
| 197 | } |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 198 | #if SK_ENABLE_INST_COUNT |
| 199 | gPrintInstCount = FLAGS_leaks; |
| 200 | #endif |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 201 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 202 | SkTArray<SkString> configs; |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 203 | for (int i = 0; i < FLAGS_config.count(); i++) { |
| 204 | SkStrSplit(FLAGS_config[i], ", ", &configs); |
| 205 | } |
| 206 | |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 207 | GrGLStandard gpuAPI = get_gl_standard(); |
| 208 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 209 | SkTDArray<GMRegistry::Factory> gms; |
commit-bot@chromium.org | 99589af | 2013-12-10 14:53:16 +0000 | [diff] [blame] | 210 | SkAutoTDelete<DM::Expectations> expectations(SkNEW(DM::NoExpectations)); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 211 | if (FLAGS_gms) { |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 212 | append_matching_factories<GM>(GMRegistry::Head(), &gms); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 213 | |
| 214 | if (FLAGS_expectations.count() > 0) { |
| 215 | const char* path = FLAGS_expectations[0]; |
| 216 | if (sk_isdir(path)) { |
| 217 | expectations.reset(SkNEW_ARGS(DM::WriteTask::Expectations, (path))); |
| 218 | } else { |
| 219 | expectations.reset(SkNEW_ARGS(DM::JsonExpectations, (path))); |
| 220 | } |
commit-bot@chromium.org | 99589af | 2013-12-10 14:53:16 +0000 | [diff] [blame] | 221 | } |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 222 | } |
| 223 | |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 224 | SkTDArray<TestRegistry::Factory> tests; |
| 225 | if (FLAGS_tests) { |
| 226 | append_matching_factories<Test>(TestRegistry::Head(), &tests); |
| 227 | } |
| 228 | |
halcanary | a98683b | 2014-07-28 07:21:24 -0700 | [diff] [blame^] | 229 | SkTArray<SkString> skps; |
| 230 | find_skps(&skps); |
| 231 | |
| 232 | SkDebugf("%d GMs x %d configs, %d tests, %d pictures\n", |
| 233 | gms.count(), configs.count(), tests.count(), skps.count()); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 234 | DM::Reporter reporter; |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 235 | DM::TaskRunner tasks(FLAGS_threads, FLAGS_gpuThreads); |
kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 236 | kick_off_gms(gms, configs, gpuAPI, *expectations, &reporter, &tasks); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 237 | kick_off_tests(tests, &reporter, &tasks); |
halcanary | a98683b | 2014-07-28 07:21:24 -0700 | [diff] [blame^] | 238 | kick_off_skps(skps, &reporter, &tasks); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 239 | tasks.wait(); |
| 240 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 241 | SkDebugf("\n"); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 242 | |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 243 | SkTArray<SkString> failures; |
| 244 | reporter.getFailures(&failures); |
| 245 | report_failures(failures); |
| 246 | return failures.count() > 0; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 247 | } |
commit-bot@chromium.org | 846872f | 2013-10-16 18:21:03 +0000 | [diff] [blame] | 248 | |
| 249 | #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
| 250 | int main(int argc, char** argv) { |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 251 | SkCommandLineFlags::Parse(argc, argv); |
| 252 | return dm_main(); |
commit-bot@chromium.org | 846872f | 2013-10-16 18:21:03 +0000 | [diff] [blame] | 253 | } |
| 254 | #endif |