| 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" |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 5 | #include "SkCommandLineFlags.h" |
| 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 | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 41 | DEFINE_int32(threads, -1, "Threads for CPU work. Default NUM_CPUS."); |
| commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 42 | DEFINE_int32(gpuThreads, 1, "Threads for GPU work."); |
| kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 43 | DEFINE_string(gpuAPI, "", "Force use of specific gpu API. Using \"gl\" " |
| 44 | "forces OpenGL API. Using \"gles\" forces OpenGL ES API. " |
| 45 | "Defaults to empty string, which selects the API native to the " |
| 46 | "system."); |
| commit-bot@chromium.org | 99589af | 2013-12-10 14:53:16 +0000 | [diff] [blame] | 47 | DEFINE_string2(expectations, r, "", |
| 48 | "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] | 49 | "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] | 50 | ); |
| commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 51 | DEFINE_string2(resources, i, "resources", "Path to resources directory."); |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 52 | DEFINE_string(match, "", "[~][^]substring[$] [...] of GM name to run.\n" |
| 53 | "Multiple matches may be separated by spaces.\n" |
| 54 | "~ causes a matching GM to always be skipped\n" |
| 55 | "^ requires the start of the GM to match\n" |
| 56 | "$ requires the end of the GM to match\n" |
| 57 | "^ and $ requires an exact match\n" |
| 58 | "If a GM does not match any list entry,\n" |
| 59 | "it is skipped unless some list entry starts with ~"); |
| mtklein | 30bf3e2 | 2014-06-03 13:57:14 -0700 | [diff] [blame] | 60 | DEFINE_string(config, "565 8888 pdf gpu nonrendering", |
| 61 | "Options: 565 8888 pdf gpu nonrendering msaa4 msaa16 nvprmsaa4 nvprmsaa16 " |
| 62 | "gpunull gpudebug angle mesa"); |
| 63 | DEFINE_bool(dryRun, false, |
| 64 | "Just print the tests that would be run, without actually running them."); |
| commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 65 | DEFINE_bool(leaks, false, "Print leaked instance-counted objects at exit?"); |
| commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 66 | DEFINE_string(skps, "", "Directory to read skps from."); |
| commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 67 | |
| 68 | DEFINE_bool(gms, true, "Run GMs?"); |
| 69 | DEFINE_bool(tests, true, "Run tests?"); |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 70 | |
| commit-bot@chromium.org | a65e2fd | 2014-05-30 17:23:31 +0000 | [diff] [blame] | 71 | DECLARE_bool(verbose); |
| 72 | |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 73 | __SK_FORCE_IMAGE_DECODER_LINKING; |
| 74 | |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 75 | // "FooBar" -> "foobar". Obviously, ASCII only. |
| 76 | static SkString lowercase(SkString s) { |
| 77 | for (size_t i = 0; i < s.size(); i++) { |
| 78 | s[i] = tolower(s[i]); |
| 79 | } |
| 80 | return s; |
| 81 | } |
| 82 | |
| commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 83 | static const GrContextFactory::GLContextType native = GrContextFactory::kNative_GLContextType; |
| commit-bot@chromium.org | b640186 | 2014-03-12 14:46:31 +0000 | [diff] [blame] | 84 | static const GrContextFactory::GLContextType nvpr = GrContextFactory::kNVPR_GLContextType; |
| commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 85 | static const GrContextFactory::GLContextType null = GrContextFactory::kNull_GLContextType; |
| 86 | static const GrContextFactory::GLContextType debug = GrContextFactory::kDebug_GLContextType; |
| 87 | static const GrContextFactory::GLContextType angle = |
| 88 | #if SK_ANGLE |
| 89 | GrContextFactory::kANGLE_GLContextType; |
| 90 | #else |
| 91 | native; |
| 92 | #endif |
| 93 | static const GrContextFactory::GLContextType mesa = |
| 94 | #if SK_MESA |
| bsalomon@google.com | 9dccafa | 2014-05-02 14:43:12 +0000 | [diff] [blame] | 95 | GrContextFactory::kMESA_GLContextType; |
| commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 96 | #else |
| 97 | native; |
| 98 | #endif |
| 99 | |
| commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 100 | static void kick_off_gms(const SkTDArray<GMRegistry::Factory>& gms, |
| 101 | const SkTArray<SkString>& configs, |
| kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 102 | GrGLStandard gpuAPI, |
| commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 103 | const DM::Expectations& expectations, |
| 104 | DM::Reporter* reporter, |
| 105 | DM::TaskRunner* tasks) { |
| mtklein | e4d3e60 | 2014-06-06 09:28:43 -0700 | [diff] [blame] | 106 | #define START(name, type, ...) \ |
| 107 | if (lowercase(configs[j]).equals(name)) { \ |
| 108 | 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] | 109 | } |
| commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 110 | for (int i = 0; i < gms.count(); i++) { |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 111 | for (int j = 0; j < configs.count(); j++) { |
| kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 112 | |
| mtklein | e4d3e60 | 2014-06-06 09:28:43 -0700 | [diff] [blame] | 113 | START("565", CpuGMTask, expectations, kRGB_565_SkColorType); |
| 114 | START("8888", CpuGMTask, expectations, kN32_SkColorType); |
| kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 115 | START("gpu", GpuGMTask, expectations, native, gpuAPI, 0); |
| 116 | START("msaa4", GpuGMTask, expectations, native, gpuAPI, 4); |
| 117 | START("msaa16", GpuGMTask, expectations, native, gpuAPI, 16); |
| 118 | START("nvprmsaa4", GpuGMTask, expectations, nvpr, gpuAPI, 4); |
| 119 | START("nvprmsaa16", GpuGMTask, expectations, nvpr, gpuAPI, 16); |
| 120 | START("gpunull", GpuGMTask, expectations, null, gpuAPI, 0); |
| 121 | START("gpudebug", GpuGMTask, expectations, debug, gpuAPI, 0); |
| 122 | START("angle", GpuGMTask, expectations, angle, gpuAPI, 0); |
| 123 | START("mesa", GpuGMTask, expectations, mesa, gpuAPI, 0); |
| mtklein | 30bf3e2 | 2014-06-03 13:57:14 -0700 | [diff] [blame] | 124 | START("pdf", PDFTask, RASTERIZE_PDF_PROC); |
| commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | #undef START |
| 128 | } |
| 129 | |
| commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 130 | static void kick_off_tests(const SkTDArray<TestRegistry::Factory>& tests, |
| 131 | DM::Reporter* reporter, |
| 132 | DM::TaskRunner* tasks) { |
| 133 | for (int i = 0; i < tests.count(); i++) { |
| commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 134 | SkAutoTDelete<Test> test(tests[i](NULL)); |
| 135 | if (test->isGPUTest()) { |
| 136 | tasks->add(SkNEW_ARGS(DM::GpuTestTask, (reporter, tasks, tests[i]))); |
| 137 | } else { |
| 138 | tasks->add(SkNEW_ARGS(DM::CpuTestTask, (reporter, tasks, tests[i]))); |
| 139 | } |
| commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 140 | } |
| 141 | } |
| 142 | |
| commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 143 | static void kick_off_skps(DM::Reporter* reporter, DM::TaskRunner* tasks) { |
| 144 | if (FLAGS_skps.isEmpty()) { |
| 145 | return; |
| 146 | } |
| 147 | |
| 148 | SkOSFile::Iter it(FLAGS_skps[0], ".skp"); |
| 149 | SkString filename; |
| 150 | while (it.next(&filename)) { |
| 151 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, filename.c_str())) { |
| 152 | continue; |
| 153 | } |
| 154 | |
| 155 | const SkString path = SkOSPath::SkPathJoin(FLAGS_skps[0], filename.c_str()); |
| 156 | |
| 157 | SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path.c_str())); |
| 158 | if (stream.get() == NULL) { |
| 159 | SkDebugf("Could not read %s.\n", path.c_str()); |
| 160 | exit(1); |
| 161 | } |
| 162 | SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream.get())); |
| 163 | if (pic.get() == NULL) { |
| 164 | SkDebugf("Could not read %s as an SkPicture.\n", path.c_str()); |
| 165 | exit(1); |
| 166 | } |
| 167 | |
| mtklein | d3e474e | 2014-06-27 12:34:44 -0700 | [diff] [blame] | 168 | tasks->add(SkNEW_ARGS(DM::SKPTask, (reporter, tasks, pic, filename))); |
| 169 | tasks->add(SkNEW_ARGS(DM::PDFTask, (reporter, tasks, pic, filename, |
| mtklein | e4d3e60 | 2014-06-06 09:28:43 -0700 | [diff] [blame] | 170 | RASTERIZE_PDF_PROC))); |
| commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 171 | } |
| 172 | } |
| 173 | |
| commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 174 | static void report_failures(const SkTArray<SkString>& failures) { |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 175 | if (failures.count() == 0) { |
| 176 | return; |
| 177 | } |
| 178 | |
| 179 | SkDebugf("Failures:\n"); |
| 180 | for (int i = 0; i < failures.count(); i++) { |
| 181 | SkDebugf(" %s\n", failures[i].c_str()); |
| 182 | } |
| commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 183 | SkDebugf("%d failures.\n", failures.count()); |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 184 | } |
| 185 | |
| kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 186 | static GrGLStandard get_gl_standard() { |
| 187 | if (FLAGS_gpuAPI.contains(kGpuAPINameGL)) { |
| 188 | return kGL_GrGLStandard; |
| 189 | } |
| 190 | if (FLAGS_gpuAPI.contains(kGpuAPINameGLES)) { |
| 191 | return kGLES_GrGLStandard; |
| 192 | } |
| 193 | return kNone_GrGLStandard; |
| 194 | } |
| 195 | |
| commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 196 | template <typename T, typename Registry> |
| 197 | static void append_matching_factories(Registry* head, SkTDArray<typename Registry::Factory>* out) { |
| 198 | for (const Registry* reg = head; reg != NULL; reg = reg->next()) { |
| 199 | SkAutoTDelete<T> forName(reg->factory()(NULL)); |
| 200 | if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, forName->getName())) { |
| 201 | *out->append() = reg->factory(); |
| 202 | } |
| 203 | } |
| 204 | } |
| 205 | |
| commit-bot@chromium.org | 846872f | 2013-10-16 18:21:03 +0000 | [diff] [blame] | 206 | int tool_main(int argc, char** argv); |
| 207 | int tool_main(int argc, char** argv) { |
| mtklein | 30e6e2a | 2014-06-18 11:44:15 -0700 | [diff] [blame] | 208 | SetupCrashHandler(); |
| commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 209 | SkAutoGraphics ag; |
| commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 210 | SkCommandLineFlags::Parse(argc, argv); |
| commit-bot@chromium.org | a65e2fd | 2014-05-30 17:23:31 +0000 | [diff] [blame] | 211 | |
| 212 | if (FLAGS_dryRun) { |
| 213 | FLAGS_verbose = true; |
| 214 | } |
| commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 215 | #if SK_ENABLE_INST_COUNT |
| 216 | gPrintInstCount = FLAGS_leaks; |
| 217 | #endif |
| commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 218 | |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 219 | SkTArray<SkString> configs; |
| commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 220 | for (int i = 0; i < FLAGS_config.count(); i++) { |
| 221 | SkStrSplit(FLAGS_config[i], ", ", &configs); |
| 222 | } |
| 223 | |
| kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 224 | GrGLStandard gpuAPI = get_gl_standard(); |
| 225 | |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 226 | SkTDArray<GMRegistry::Factory> gms; |
| commit-bot@chromium.org | 99589af | 2013-12-10 14:53:16 +0000 | [diff] [blame] | 227 | SkAutoTDelete<DM::Expectations> expectations(SkNEW(DM::NoExpectations)); |
| commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 228 | if (FLAGS_gms) { |
| commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 229 | append_matching_factories<GM>(GMRegistry::Head(), &gms); |
| commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 230 | |
| 231 | if (FLAGS_expectations.count() > 0) { |
| 232 | const char* path = FLAGS_expectations[0]; |
| 233 | if (sk_isdir(path)) { |
| 234 | expectations.reset(SkNEW_ARGS(DM::WriteTask::Expectations, (path))); |
| 235 | } else { |
| 236 | expectations.reset(SkNEW_ARGS(DM::JsonExpectations, (path))); |
| 237 | } |
| commit-bot@chromium.org | 99589af | 2013-12-10 14:53:16 +0000 | [diff] [blame] | 238 | } |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 239 | } |
| 240 | |
| commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 241 | SkTDArray<TestRegistry::Factory> tests; |
| 242 | if (FLAGS_tests) { |
| 243 | append_matching_factories<Test>(TestRegistry::Head(), &tests); |
| 244 | } |
| 245 | |
| mtklein | 103ae71 | 2014-07-16 14:29:53 -0700 | [diff] [blame] | 246 | SkDebugf("%d GMs x %d configs, %d tests\n", |
| 247 | gms.count(), configs.count(), tests.count()); |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 248 | DM::Reporter reporter; |
| commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 249 | DM::TaskRunner tasks(FLAGS_threads, FLAGS_gpuThreads); |
| kkinnunen | 80549fc | 2014-06-30 06:36:31 -0700 | [diff] [blame] | 250 | kick_off_gms(gms, configs, gpuAPI, *expectations, &reporter, &tasks); |
| commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 251 | kick_off_tests(tests, &reporter, &tasks); |
| commit-bot@chromium.org | 90b5a2a | 2014-05-14 17:55:32 +0000 | [diff] [blame] | 252 | kick_off_skps(&reporter, &tasks); |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 253 | tasks.wait(); |
| 254 | |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 255 | SkDebugf("\n"); |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 256 | |
| commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 257 | SkTArray<SkString> failures; |
| 258 | reporter.getFailures(&failures); |
| 259 | report_failures(failures); |
| 260 | return failures.count() > 0; |
| mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 261 | } |
| commit-bot@chromium.org | 846872f | 2013-10-16 18:21:03 +0000 | [diff] [blame] | 262 | |
| 263 | #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
| 264 | int main(int argc, char** argv) { |
| 265 | return tool_main(argc, argv); |
| 266 | } |
| 267 | #endif |