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