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" |
| 6 | #include "SkCommandLineFlags.h" |
| 7 | #include "SkForceLinking.h" |
| 8 | #include "SkGraphics.h" |
| 9 | #include "gm.h" |
| 10 | |
| 11 | #include "DMReporter.h" |
| 12 | #include "DMTask.h" |
| 13 | #include "DMTaskRunner.h" |
| 14 | #include "DMCpuTask.h" |
| 15 | #include "DMGpuTask.h" |
| 16 | |
| 17 | #include <string.h> |
| 18 | |
| 19 | using skiagm::GM; |
| 20 | using skiagm::GMRegistry; |
| 21 | using skiagm::Expectations; |
| 22 | using skiagm::ExpectationsSource; |
| 23 | using skiagm::JsonExpectationsSource; |
| 24 | |
| 25 | DEFINE_int32(cpuThreads, -1, "Threads for CPU work. Default NUM_CPUS."); |
| 26 | DEFINE_int32(gpuThreads, 1, "Threads for GPU work."); |
| 27 | DEFINE_string(expectations, "", "Compare generated images against JSON expectations at this path."); |
| 28 | DEFINE_string(resources, "resources", "Path to resources directory."); |
| 29 | DEFINE_string(match, "", "[~][^]substring[$] [...] of GM name to run.\n" |
| 30 | "Multiple matches may be separated by spaces.\n" |
| 31 | "~ causes a matching GM to always be skipped\n" |
| 32 | "^ requires the start of the GM to match\n" |
| 33 | "$ requires the end of the GM to match\n" |
| 34 | "^ and $ requires an exact match\n" |
| 35 | "If a GM does not match any list entry,\n" |
| 36 | "it is skipped unless some list entry starts with ~"); |
| 37 | DEFINE_string(config, "8888 gpu", |
| 38 | "Options: 565 8888 gpu msaa4 msaa16 gpunull gpudebug angle mesa"); // TODO(mtklein): pdf |
| 39 | |
| 40 | __SK_FORCE_IMAGE_DECODER_LINKING; |
| 41 | |
| 42 | // Split str on any characters in delimiters into out. (Think, strtok with a sane API.) |
| 43 | static void split(const char* str, const char* delimiters, SkTArray<SkString>* out) { |
| 44 | const char* end = str + strlen(str); |
| 45 | while (str != end) { |
| 46 | // Find a token. |
| 47 | const size_t len = strcspn(str, delimiters); |
| 48 | out->push_back().set(str, len); |
| 49 | str += len; |
| 50 | // Skip any delimiters. |
| 51 | str += strspn(str, delimiters); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | // "FooBar" -> "foobar". Obviously, ASCII only. |
| 56 | static SkString lowercase(SkString s) { |
| 57 | for (size_t i = 0; i < s.size(); i++) { |
| 58 | s[i] = tolower(s[i]); |
| 59 | } |
| 60 | return s; |
| 61 | } |
| 62 | |
| 63 | static void kick_off_tasks(const SkTDArray<GMRegistry::Factory>& gms, |
| 64 | const SkTArray<SkString>& configs, |
| 65 | const ExpectationsSource& expectations, |
| 66 | DM::Reporter* reporter, |
| 67 | DM::TaskRunner* tasks) { |
| 68 | const SkBitmap::Config _565 = SkBitmap::kRGB_565_Config; |
| 69 | const SkBitmap::Config _8888 = SkBitmap::kARGB_8888_Config; |
| 70 | const GrContextFactory::GLContextType native = GrContextFactory::kNative_GLContextType; |
| 71 | const GrContextFactory::GLContextType null = GrContextFactory::kNull_GLContextType; |
| 72 | const GrContextFactory::GLContextType debug = GrContextFactory::kDebug_GLContextType; |
| 73 | const GrContextFactory::GLContextType angle = |
| 74 | #if SK_ANGLE |
| 75 | GrContextFactory::kANGLE_GLContextType; |
| 76 | #else |
| 77 | native; |
| 78 | #endif |
| 79 | const GrContextFactory::GLContextType mesa = |
| 80 | #if SK_MESA |
| 81 | GLContextFactory::kMESA_GLContextType; |
| 82 | #else |
| 83 | native; |
| 84 | #endif |
| 85 | |
| 86 | for (int i = 0; i < gms.count(); i++) { |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 87 | #define START(name, type, ...) \ |
| 88 | if (lowercase(configs[j]).equals(name)) { \ |
| 89 | tasks->add(SkNEW_ARGS(DM::type, \ |
| 90 | (name, reporter, tasks, expectations, gms[i], __VA_ARGS__))); \ |
| 91 | } |
| 92 | for (int j = 0; j < configs.count(); j++) { |
| 93 | START("565", CpuTask, _565); |
| 94 | START("8888", CpuTask, _8888); |
| 95 | START("gpu", GpuTask, _8888, native, 0); |
| 96 | START("msaa4", GpuTask, _8888, native, 4); |
| 97 | START("msaa16", GpuTask, _8888, native, 16); |
| 98 | START("gpunull", GpuTask, _8888, null, 0); |
| 99 | START("gpudebug", GpuTask, _8888, debug, 0); |
| 100 | START("angle", GpuTask, _8888, angle, 0); |
| 101 | START("mesa", GpuTask, _8888, mesa, 0); |
| 102 | //START("pdf", PdfTask, _8888); |
| 103 | } |
| 104 | } |
| 105 | #undef START |
| 106 | } |
| 107 | |
| 108 | static void report_failures(const DM::Reporter& reporter) { |
| 109 | SkTArray<SkString> failures; |
| 110 | reporter.getFailures(&failures); |
| 111 | |
| 112 | if (failures.count() == 0) { |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | SkDebugf("Failures:\n"); |
| 117 | for (int i = 0; i < failures.count(); i++) { |
| 118 | SkDebugf(" %s\n", failures[i].c_str()); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | class NoExpectations : public ExpectationsSource { |
| 123 | public: |
| 124 | Expectations get(const char* /*testName*/) const SK_OVERRIDE { |
| 125 | return Expectations(); |
| 126 | } |
| 127 | }; |
| 128 | |
commit-bot@chromium.org | 846872f | 2013-10-16 18:21:03 +0000 | [diff] [blame] | 129 | int tool_main(int argc, char** argv); |
| 130 | int tool_main(int argc, char** argv) { |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 131 | SkGraphics::Init(); |
| 132 | |
| 133 | SkCommandLineFlags::Parse(argc, argv); |
| 134 | GM::SetResourcePath(FLAGS_resources[0]); |
| 135 | SkTArray<SkString> configs; |
| 136 | for (int i = 0; i < FLAGS_config.count(); i++) { |
| 137 | split(FLAGS_config[i], ", ", &configs); |
| 138 | } |
| 139 | |
| 140 | SkTDArray<GMRegistry::Factory> gms; |
| 141 | for (const GMRegistry* reg = GMRegistry::Head(); reg != NULL; reg = reg->next()) { |
commit-bot@chromium.org | cdd3620 | 2013-10-25 15:02:57 +0000 | [diff] [blame] | 142 | SkAutoTDelete<GM> gmForName(reg->factory()(NULL)); |
| 143 | if (!SkCommandLineFlags::ShouldSkip(FLAGS_match, gmForName->shortName())) { |
| 144 | *gms.append() = reg->factory(); |
| 145 | } |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 146 | } |
| 147 | SkDebugf("%d GMs x %d configs\n", gms.count(), configs.count()); |
| 148 | |
| 149 | SkAutoTUnref<ExpectationsSource> expectations(SkNEW(NoExpectations)); |
| 150 | if (FLAGS_expectations.count() > 0) { |
| 151 | expectations.reset(SkNEW_ARGS(JsonExpectationsSource, (FLAGS_expectations[0]))); |
| 152 | } |
| 153 | |
| 154 | DM::Reporter reporter; |
| 155 | DM::TaskRunner tasks(FLAGS_cpuThreads, FLAGS_gpuThreads); |
| 156 | kick_off_tasks(gms, configs, *expectations, &reporter, &tasks); |
| 157 | tasks.wait(); |
| 158 | |
| 159 | reporter.updateStatusLine(); |
| 160 | SkDebugf("\n"); |
| 161 | report_failures(reporter); |
| 162 | |
| 163 | SkGraphics::Term(); |
| 164 | |
| 165 | return reporter.failed() > 0; |
| 166 | } |
commit-bot@chromium.org | 846872f | 2013-10-16 18:21:03 +0000 | [diff] [blame] | 167 | |
| 168 | #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
| 169 | int main(int argc, char** argv) { |
| 170 | return tool_main(argc, argv); |
| 171 | } |
| 172 | #endif |