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 | |
| 4 | #include "GrContext.h" |
| 5 | #include "GrContextFactory.h" |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 6 | #include "SkBenchmark.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 7 | #include "SkCommandLineFlags.h" |
| 8 | #include "SkForceLinking.h" |
| 9 | #include "SkGraphics.h" |
rmistry@google.com | d6bab02 | 2013-12-02 13:50:38 +0000 | [diff] [blame] | 10 | #include "SkString.h" |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 11 | #include "Test.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 12 | #include "gm.h" |
| 13 | |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 14 | #include "DMBenchTask.h" |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 15 | #include "DMCpuGMTask.h" |
| 16 | #include "DMGpuGMTask.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 17 | #include "DMReporter.h" |
| 18 | #include "DMTask.h" |
| 19 | #include "DMTaskRunner.h" |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 20 | #include "DMTestTask.h" |
commit-bot@chromium.org | 99589af | 2013-12-10 14:53:16 +0000 | [diff] [blame] | 21 | #include "DMWriteTask.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 22 | |
| 23 | #include <string.h> |
| 24 | |
| 25 | using skiagm::GM; |
| 26 | using skiagm::GMRegistry; |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 27 | using skiatest::Test; |
| 28 | using skiatest::TestRegistry; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 29 | |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 30 | 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] | 31 | DEFINE_int32(gpuThreads, 1, "Threads for GPU work."); |
commit-bot@chromium.org | 99589af | 2013-12-10 14:53:16 +0000 | [diff] [blame] | 32 | DEFINE_string2(expectations, r, "", |
| 33 | "If a directory, compare generated images against images under this path. " |
| 34 | "If a file, compare generated images against JSON expectations at this path."); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 35 | DEFINE_string2(resources, i, "resources", "Path to resources directory."); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 36 | DEFINE_string(match, "", "[~][^]substring[$] [...] of GM name to run.\n" |
| 37 | "Multiple matches may be separated by spaces.\n" |
| 38 | "~ causes a matching GM to always be skipped\n" |
| 39 | "^ requires the start of the GM to match\n" |
| 40 | "$ requires the end of the GM to match\n" |
| 41 | "^ and $ requires an exact match\n" |
| 42 | "If a GM does not match any list entry,\n" |
| 43 | "it is skipped unless some list entry starts with ~"); |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 44 | DEFINE_string(config, "565 8888 gpu nonrendering", |
commit-bot@chromium.org | b640186 | 2014-03-12 14:46:31 +0000 | [diff] [blame] | 45 | "Options: 565 8888 gpu nonrendering msaa4 msaa16 nvprmsaa4 nvprmsaa16 gpunull gpudebug angle mesa"); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 46 | DEFINE_bool(leaks, false, "Print leaked instance-counted objects at exit?"); |
| 47 | |
| 48 | DEFINE_bool(gms, true, "Run GMs?"); |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 49 | DEFINE_bool(benches, true, "Run benches? Does not run GMs-as-benches."); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 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 |
| 74 | GLContextFactory::kMESA_GLContextType; |
| 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, |
| 81 | const DM::Expectations& expectations, |
| 82 | DM::Reporter* reporter, |
| 83 | DM::TaskRunner* tasks) { |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 84 | #define START(name, type, ...) \ |
| 85 | if (lowercase(configs[j]).equals(name)) { \ |
| 86 | tasks->add(SkNEW_ARGS(DM::type, \ |
| 87 | (name, reporter, tasks, expectations, 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++) { |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 91 | START("565", CpuGMTask, kRGB_565_SkColorType); |
| 92 | START("8888", CpuGMTask, kPMColor_SkColorType); |
| 93 | START("gpu", GpuGMTask, native, 0); |
| 94 | START("msaa4", GpuGMTask, native, 4); |
| 95 | START("msaa16", GpuGMTask, native, 16); |
commit-bot@chromium.org | b640186 | 2014-03-12 14:46:31 +0000 | [diff] [blame] | 96 | START("nvprmsaa4", GpuGMTask, nvpr, 4); |
| 97 | START("nvprmsaa16", GpuGMTask, nvpr, 16); |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 98 | START("gpunull", GpuGMTask, null, 0); |
| 99 | START("gpudebug", GpuGMTask, debug, 0); |
| 100 | START("angle", GpuGMTask, angle, 0); |
| 101 | START("mesa", GpuGMTask, mesa, 0); |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | #undef START |
| 105 | } |
| 106 | |
| 107 | static void kick_off_benches(const SkTDArray<BenchRegistry::Factory>& benches, |
| 108 | const SkTArray<SkString>& configs, |
| 109 | DM::Reporter* reporter, |
| 110 | DM::TaskRunner* tasks) { |
| 111 | #define START(name, type, ...) \ |
| 112 | if (lowercase(configs[j]).equals(name)) { \ |
| 113 | tasks->add(SkNEW_ARGS(DM::type, (name, reporter, tasks, benches[i], ## __VA_ARGS__))); \ |
| 114 | } |
| 115 | for (int i = 0; i < benches.count(); i++) { |
| 116 | for (int j = 0; j < configs.count(); j++) { |
| 117 | START("nonrendering", NonRenderingBenchTask); |
| 118 | START("565", CpuBenchTask, kRGB_565_SkColorType); |
| 119 | START("8888", CpuBenchTask, kPMColor_SkColorType); |
| 120 | START("gpu", GpuBenchTask, native, 0); |
| 121 | START("msaa4", GpuBenchTask, native, 4); |
| 122 | START("msaa16", GpuBenchTask, native, 16); |
commit-bot@chromium.org | b640186 | 2014-03-12 14:46:31 +0000 | [diff] [blame] | 123 | START("nvprmsaa4", GpuBenchTask, nvpr, 4); |
| 124 | START("nvprmsaa16", GpuBenchTask, nvpr, 16); |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 125 | START("gpunull", GpuBenchTask, null, 0); |
| 126 | START("gpudebug", GpuBenchTask, debug, 0); |
| 127 | START("angle", GpuBenchTask, angle, 0); |
| 128 | START("mesa", GpuBenchTask, mesa, 0); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | #undef START |
| 132 | } |
| 133 | |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 134 | static void kick_off_tests(const SkTDArray<TestRegistry::Factory>& tests, |
| 135 | DM::Reporter* reporter, |
| 136 | DM::TaskRunner* tasks) { |
| 137 | for (int i = 0; i < tests.count(); i++) { |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 138 | SkAutoTDelete<Test> test(tests[i](NULL)); |
| 139 | if (test->isGPUTest()) { |
| 140 | tasks->add(SkNEW_ARGS(DM::GpuTestTask, (reporter, tasks, tests[i]))); |
| 141 | } else { |
| 142 | tasks->add(SkNEW_ARGS(DM::CpuTestTask, (reporter, tasks, tests[i]))); |
| 143 | } |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 147 | static void report_failures(const DM::Reporter& reporter) { |
| 148 | SkTArray<SkString> failures; |
| 149 | reporter.getFailures(&failures); |
| 150 | |
| 151 | if (failures.count() == 0) { |
| 152 | return; |
| 153 | } |
| 154 | |
| 155 | SkDebugf("Failures:\n"); |
| 156 | for (int i = 0; i < failures.count(); i++) { |
| 157 | SkDebugf(" %s\n", failures[i].c_str()); |
| 158 | } |
| 159 | } |
| 160 | |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 161 | template <typename T, typename Registry> |
| 162 | static void append_matching_factories(Registry* head, SkTDArray<typename Registry::Factory>* out) { |
| 163 | for (const Registry* reg = head; reg != NULL; reg = reg->next()) { |
| 164 | SkAutoTDelete<T> forName(reg->factory()(NULL)); |
| 165 | if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, forName->getName())) { |
| 166 | *out->append() = reg->factory(); |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
commit-bot@chromium.org | 846872f | 2013-10-16 18:21:03 +0000 | [diff] [blame] | 171 | int tool_main(int argc, char** argv); |
| 172 | int tool_main(int argc, char** argv) { |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 173 | SkGraphics::Init(); |
| 174 | SkCommandLineFlags::Parse(argc, argv); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 175 | #if SK_ENABLE_INST_COUNT |
| 176 | gPrintInstCount = FLAGS_leaks; |
| 177 | #endif |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 178 | GM::SetResourcePath(FLAGS_resources[0]); |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 179 | SkBenchmark::SetResourcePath(FLAGS_resources[0]); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 180 | Test::SetResourcePath(FLAGS_resources[0]); |
| 181 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 182 | SkTArray<SkString> configs; |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 183 | for (int i = 0; i < FLAGS_config.count(); i++) { |
| 184 | SkStrSplit(FLAGS_config[i], ", ", &configs); |
| 185 | } |
| 186 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 187 | SkTDArray<GMRegistry::Factory> gms; |
commit-bot@chromium.org | 99589af | 2013-12-10 14:53:16 +0000 | [diff] [blame] | 188 | SkAutoTDelete<DM::Expectations> expectations(SkNEW(DM::NoExpectations)); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 189 | if (FLAGS_gms) { |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 190 | append_matching_factories<GM>(GMRegistry::Head(), &gms); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 191 | |
| 192 | if (FLAGS_expectations.count() > 0) { |
| 193 | const char* path = FLAGS_expectations[0]; |
| 194 | if (sk_isdir(path)) { |
| 195 | expectations.reset(SkNEW_ARGS(DM::WriteTask::Expectations, (path))); |
| 196 | } else { |
| 197 | expectations.reset(SkNEW_ARGS(DM::JsonExpectations, (path))); |
| 198 | } |
commit-bot@chromium.org | 99589af | 2013-12-10 14:53:16 +0000 | [diff] [blame] | 199 | } |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 200 | } |
| 201 | |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 202 | SkTDArray<BenchRegistry::Factory> benches; |
| 203 | if (FLAGS_benches) { |
| 204 | append_matching_factories<SkBenchmark>(BenchRegistry::Head(), &benches); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 205 | } |
| 206 | |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 207 | SkTDArray<TestRegistry::Factory> tests; |
| 208 | if (FLAGS_tests) { |
| 209 | append_matching_factories<Test>(TestRegistry::Head(), &tests); |
| 210 | } |
| 211 | |
| 212 | SkDebugf("(%d GMs, %d benches) x %d configs, %d tests\n", |
| 213 | gms.count(), benches.count(), configs.count(), tests.count()); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 214 | DM::Reporter reporter; |
commit-bot@chromium.org | ef57b7e | 2014-02-28 20:31:31 +0000 | [diff] [blame] | 215 | DM::TaskRunner tasks(FLAGS_threads, FLAGS_gpuThreads); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 216 | kick_off_gms(gms, configs, *expectations, &reporter, &tasks); |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 217 | kick_off_benches(benches, configs, &reporter, &tasks); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 218 | kick_off_tests(tests, &reporter, &tasks); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 219 | tasks.wait(); |
| 220 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 221 | SkDebugf("\n"); |
| 222 | report_failures(reporter); |
| 223 | |
| 224 | SkGraphics::Term(); |
| 225 | |
| 226 | return reporter.failed() > 0; |
| 227 | } |
commit-bot@chromium.org | 846872f | 2013-10-16 18:21:03 +0000 | [diff] [blame] | 228 | |
| 229 | #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
| 230 | int main(int argc, char** argv) { |
| 231 | return tool_main(argc, argv); |
| 232 | } |
| 233 | #endif |