jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1 | #include "CrashHandler.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 2 | #include "DMJsonWriter.h" |
| 3 | #include "DMSrcSink.h" |
tomhudson | eebc39a | 2015-02-23 12:18:05 -0800 | [diff] [blame] | 4 | #include "DMSrcSinkAndroid.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 5 | #include "OverwriteLine.h" |
| 6 | #include "ProcStats.h" |
| 7 | #include "SkBBHFactory.h" |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 8 | #include "SkChecksum.h" |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 9 | #include "SkCommonFlags.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 10 | #include "SkForceLinking.h" |
| 11 | #include "SkGraphics.h" |
mtklein | e67164d | 2015-02-02 13:24:37 -0800 | [diff] [blame] | 12 | #include "SkInstCnt.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 13 | #include "SkMD5.h" |
mtklein | 1d0f164 | 2014-09-08 08:05:18 -0700 | [diff] [blame] | 14 | #include "SkOSFile.h" |
mtklein | a82f562 | 2015-02-20 12:30:19 -0800 | [diff] [blame] | 15 | #include "SkTHash.h" |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 16 | #include "SkTaskGroup.h" |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 17 | #include "Test.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 18 | #include "Timer.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 19 | |
mtklein | edc93bc | 2015-01-30 13:22:23 -0800 | [diff] [blame] | 20 | DEFINE_string(src, "tests gm skp image subset", "Source types to test."); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 21 | DEFINE_bool(nameByHash, false, |
| 22 | "If true, write to FLAGS_writePath[0]/<hash>.png instead of " |
| 23 | "to FLAGS_writePath[0]/<config>/<sourceType>/<name>.png"); |
| 24 | DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests."); |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 25 | DEFINE_string(matrix, "1 0 0 1", |
| 26 | "2x2 scale+skew matrix to apply or upright when using " |
| 27 | "'matrix' or 'upright' in config."); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 28 | DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?"); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 29 | |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 30 | DEFINE_string(blacklist, "", |
| 31 | "Space-separated config/src/name triples to blacklist. '_' matches anything. E.g. \n" |
| 32 | "'--blacklist gpu skp _' will blacklist all SKPs drawn into the gpu config.\n" |
| 33 | "'--blacklist gpu skp _ 8888 gm aarects' will also blacklist the aarects GM on 8888."); |
| 34 | |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 35 | DEFINE_string2(readPath, r, "", "If set check for equality with golden results in this directory."); |
| 36 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 37 | __SK_FORCE_IMAGE_DECODER_LINKING; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 38 | using namespace DM; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 39 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 40 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 41 | |
| 42 | SK_DECLARE_STATIC_MUTEX(gFailuresMutex); |
| 43 | static SkTArray<SkString> gFailures; |
| 44 | |
| 45 | static void fail(ImplicitString err) { |
| 46 | SkAutoMutexAcquire lock(gFailuresMutex); |
| 47 | SkDebugf("\n\nFAILURE: %s\n\n", err.c_str()); |
| 48 | gFailures.push_back(err); |
halcanary | 9e398f7 | 2015-01-10 11:18:04 -0800 | [diff] [blame] | 49 | } |
| 50 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 51 | static int32_t gPending = 0; // Atomic. |
| 52 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 53 | static void done(double ms, |
| 54 | ImplicitString config, ImplicitString src, ImplicitString name, |
| 55 | ImplicitString log) { |
| 56 | if (!log.isEmpty()) { |
| 57 | log.prepend("\n"); |
| 58 | } |
mtklein | 6dee2ad | 2015-02-05 09:53:44 -0800 | [diff] [blame] | 59 | auto pending = sk_atomic_dec(&gPending)-1; |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 60 | SkDebugf("%s(%4dMB %5d) %s\t%s %s %s%s", FLAGS_verbose ? "\n" : kSkOverwriteLine |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 61 | , sk_tools::getMaxResidentSetSizeMB() |
mtklein | a17241b | 2015-01-23 05:48:00 -0800 | [diff] [blame] | 62 | , pending |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 63 | , HumanizeMs(ms).c_str() |
| 64 | , config.c_str() |
| 65 | , src.c_str() |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 66 | , name.c_str() |
| 67 | , log.c_str()); |
mtklein | a17241b | 2015-01-23 05:48:00 -0800 | [diff] [blame] | 68 | // We write our dm.json file every once in a while in case we crash. |
| 69 | // Notice this also handles the final dm.json when pending == 0. |
| 70 | if (pending % 500 == 0) { |
| 71 | JsonWriter::DumpJson(); |
| 72 | } |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 73 | } |
| 74 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 75 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 76 | |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 77 | struct Gold : public SkString { |
mtklein | a82f562 | 2015-02-20 12:30:19 -0800 | [diff] [blame] | 78 | Gold() : SkString("") {} |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 79 | Gold(ImplicitString sink, ImplicitString src, ImplicitString name, ImplicitString md5) |
| 80 | : SkString("") { |
| 81 | this->append(sink); |
| 82 | this->append(src); |
| 83 | this->append(name); |
| 84 | this->append(md5); |
| 85 | while (this->size() % 4) { |
| 86 | this->append("!"); // Pad out if needed so we can pass this to Murmur3. |
| 87 | } |
| 88 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 89 | static uint32_t Hash(const Gold& g) { |
| 90 | return SkChecksum::Murmur3((const uint32_t*)g.c_str(), g.size()); |
| 91 | } |
| 92 | }; |
mtklein | a82f562 | 2015-02-20 12:30:19 -0800 | [diff] [blame] | 93 | static SkTHashSet<Gold, Gold::Hash> gGold; |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 94 | |
| 95 | static void add_gold(JsonWriter::BitmapResult r) { |
mtklein | a82f562 | 2015-02-20 12:30:19 -0800 | [diff] [blame] | 96 | gGold.add(Gold(r.config, r.sourceType, r.name, r.md5)); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | static void gather_gold() { |
| 100 | if (!FLAGS_readPath.isEmpty()) { |
| 101 | SkString path(FLAGS_readPath[0]); |
| 102 | path.append("/dm.json"); |
| 103 | if (!JsonWriter::ReadJson(path.c_str(), add_gold)) { |
| 104 | fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str())); |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 110 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 111 | template <typename T> |
| 112 | struct Tagged : public SkAutoTDelete<T> { const char* tag; }; |
| 113 | |
| 114 | static const bool kMemcpyOK = true; |
| 115 | |
| 116 | static SkTArray<Tagged<Src>, kMemcpyOK> gSrcs; |
| 117 | static SkTArray<Tagged<Sink>, kMemcpyOK> gSinks; |
| 118 | |
| 119 | static void push_src(const char* tag, Src* s) { |
| 120 | SkAutoTDelete<Src> src(s); |
| 121 | if (FLAGS_src.contains(tag) && |
| 122 | !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) { |
| 123 | Tagged<Src>& s = gSrcs.push_back(); |
| 124 | s.reset(src.detach()); |
| 125 | s.tag = tag; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 126 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 127 | } |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 128 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 129 | static void gather_srcs() { |
| 130 | for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) { |
| 131 | push_src("gm", new GMSrc(r->factory())); |
| 132 | } |
halcanary | fc37ad1 | 2015-01-30 07:31:19 -0800 | [diff] [blame] | 133 | for (int i = 0; i < FLAGS_skps.count(); i++) { |
| 134 | const char* path = FLAGS_skps[i]; |
| 135 | if (sk_isdir(path)) { |
| 136 | SkOSFile::Iter it(path, "skp"); |
| 137 | for (SkString file; it.next(&file); ) { |
| 138 | push_src("skp", new SKPSrc(SkOSPath::Join(path, file.c_str()))); |
| 139 | } |
| 140 | } else { |
mtklein | 8d17a13 | 2015-01-30 11:42:31 -0800 | [diff] [blame] | 141 | push_src("skp", new SKPSrc(path)); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 142 | } |
| 143 | } |
halcanary | 23b03c3 | 2015-01-30 09:58:58 -0800 | [diff] [blame] | 144 | static const char* const exts[] = { |
| 145 | "bmp", "gif", "jpg", "jpeg", "png", "webp", "ktx", "astc", "wbmp", "ico", |
| 146 | "BMP", "GIF", "JPG", "JPEG", "PNG", "WEBP", "KTX", "ASTC", "WBMP", "ICO", |
| 147 | }; |
| 148 | for (int i = 0; i < FLAGS_images.count(); i++) { |
| 149 | const char* flag = FLAGS_images[i]; |
| 150 | if (sk_isdir(flag)) { |
| 151 | for (size_t j = 0; j < SK_ARRAY_COUNT(exts); j++) { |
| 152 | SkOSFile::Iter it(flag, exts[j]); |
| 153 | for (SkString file; it.next(&file); ) { |
| 154 | SkString path = SkOSPath::Join(flag, file.c_str()); |
| 155 | push_src("image", new ImageSrc(path)); // Decode entire image. |
mtklein | edc93bc | 2015-01-30 13:22:23 -0800 | [diff] [blame] | 156 | push_src("subset", new ImageSrc(path, 2)); // Decode into 2 x 2 subsets |
halcanary | 23b03c3 | 2015-01-30 09:58:58 -0800 | [diff] [blame] | 157 | } |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 158 | } |
halcanary | 23b03c3 | 2015-01-30 09:58:58 -0800 | [diff] [blame] | 159 | } else if (sk_exists(flag)) { |
| 160 | // assume that FLAGS_images[i] is a valid image if it is a file. |
mtklein | 8d17a13 | 2015-01-30 11:42:31 -0800 | [diff] [blame] | 161 | push_src("image", new ImageSrc(flag)); // Decode entire image. |
mtklein | edc93bc | 2015-01-30 13:22:23 -0800 | [diff] [blame] | 162 | push_src("subset", new ImageSrc(flag, 2)); // Decode into 2 x 2 subsets |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 163 | } |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 164 | } |
| 165 | } |
| 166 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 167 | static GrGLStandard get_gpu_api() { |
| 168 | if (FLAGS_gpuAPI.contains("gl")) { return kGL_GrGLStandard; } |
| 169 | if (FLAGS_gpuAPI.contains("gles")) { return kGLES_GrGLStandard; } |
| 170 | return kNone_GrGLStandard; |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 171 | } |
| 172 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 173 | static void push_sink(const char* tag, Sink* s) { |
| 174 | SkAutoTDelete<Sink> sink(s); |
| 175 | if (!FLAGS_config.contains(tag)) { |
| 176 | return; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 177 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 178 | // Try a noop Src as a canary. If it fails, skip this sink. |
| 179 | struct : public Src { |
| 180 | Error draw(SkCanvas*) const SK_OVERRIDE { return ""; } |
| 181 | SkISize size() const SK_OVERRIDE { return SkISize::Make(16, 16); } |
| 182 | Name name() const SK_OVERRIDE { return "noop"; } |
| 183 | } noop; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 184 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 185 | SkBitmap bitmap; |
| 186 | SkDynamicMemoryWStream stream; |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 187 | SkString log; |
| 188 | Error err = sink->draw(noop, &bitmap, &stream, &log); |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame^] | 189 | if (err.isFatal()) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 190 | SkDebugf("Skipping %s: %s\n", tag, err.c_str()); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 191 | return; |
| 192 | } |
| 193 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 194 | Tagged<Sink>& ts = gSinks.push_back(); |
| 195 | ts.reset(sink.detach()); |
| 196 | ts.tag = tag; |
| 197 | } |
| 198 | |
| 199 | static bool gpu_supported() { |
| 200 | #if SK_SUPPORT_GPU |
| 201 | return FLAGS_gpu; |
| 202 | #else |
| 203 | return false; |
| 204 | #endif |
| 205 | } |
| 206 | |
| 207 | static Sink* create_sink(const char* tag) { |
| 208 | #define SINK(t, sink, ...) if (0 == strcmp(t, tag)) { return new sink(__VA_ARGS__); } |
| 209 | if (gpu_supported()) { |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 210 | typedef GrContextFactory Gr; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 211 | const GrGLStandard api = get_gpu_api(); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 212 | SINK("gpunull", GPUSink, Gr::kNull_GLContextType, api, 0, false, FLAGS_gpu_threading); |
| 213 | SINK("gpudebug", GPUSink, Gr::kDebug_GLContextType, api, 0, false, FLAGS_gpu_threading); |
| 214 | SINK("gpu", GPUSink, Gr::kNative_GLContextType, api, 0, false, FLAGS_gpu_threading); |
| 215 | SINK("gpudft", GPUSink, Gr::kNative_GLContextType, api, 0, true, FLAGS_gpu_threading); |
| 216 | SINK("msaa4", GPUSink, Gr::kNative_GLContextType, api, 4, false, FLAGS_gpu_threading); |
| 217 | SINK("msaa16", GPUSink, Gr::kNative_GLContextType, api, 16, false, FLAGS_gpu_threading); |
| 218 | SINK("nvprmsaa4", GPUSink, Gr::kNVPR_GLContextType, api, 4, false, FLAGS_gpu_threading); |
| 219 | SINK("nvprmsaa16", GPUSink, Gr::kNVPR_GLContextType, api, 16, false, FLAGS_gpu_threading); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 220 | #if SK_ANGLE |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 221 | SINK("angle", GPUSink, Gr::kANGLE_GLContextType, api, 0, false, FLAGS_gpu_threading); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 222 | #endif |
| 223 | #if SK_MESA |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 224 | SINK("mesa", GPUSink, Gr::kMESA_GLContextType, api, 0, false, FLAGS_gpu_threading); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 225 | #endif |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 226 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 227 | |
tomhudson | eebc39a | 2015-02-23 12:18:05 -0800 | [diff] [blame] | 228 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 229 | SINK("hwui", HWUISink); |
| 230 | #endif |
| 231 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 232 | if (FLAGS_cpu) { |
| 233 | SINK("565", RasterSink, kRGB_565_SkColorType); |
| 234 | SINK("8888", RasterSink, kN32_SkColorType); |
mtklein | 19f3060 | 2015-01-20 13:34:39 -0800 | [diff] [blame] | 235 | SINK("pdf", PDFSink); |
mtklein | 9c3f17d | 2015-01-28 11:35:18 -0800 | [diff] [blame] | 236 | SINK("skp", SKPSink); |
mtklein | 8a4527e | 2015-01-31 20:00:58 -0800 | [diff] [blame] | 237 | SINK("svg", SVGSink); |
| 238 | SINK("null", NullSink); |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 239 | SINK("xps", XPSSink); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 240 | } |
| 241 | #undef SINK |
| 242 | return NULL; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 243 | } |
| 244 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 245 | static Sink* create_via(const char* tag, Sink* wrapped) { |
| 246 | #define VIA(t, via, ...) if (0 == strcmp(t, tag)) { return new via(__VA_ARGS__); } |
mtklein | 7edca21 | 2015-01-21 13:18:51 -0800 | [diff] [blame] | 247 | VIA("pipe", ViaPipe, wrapped); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 248 | VIA("serialize", ViaSerialization, wrapped); |
mtklein | 7edca21 | 2015-01-21 13:18:51 -0800 | [diff] [blame] | 249 | VIA("tiles", ViaTiles, 256, 256, NULL, wrapped); |
| 250 | VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 251 | |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 252 | if (FLAGS_matrix.count() == 4) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 253 | SkMatrix m; |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 254 | m.reset(); |
| 255 | m.setScaleX((SkScalar)atof(FLAGS_matrix[0])); |
| 256 | m.setSkewX ((SkScalar)atof(FLAGS_matrix[1])); |
| 257 | m.setSkewY ((SkScalar)atof(FLAGS_matrix[2])); |
| 258 | m.setScaleY((SkScalar)atof(FLAGS_matrix[3])); |
| 259 | VIA("matrix", ViaMatrix, m, wrapped); |
| 260 | VIA("upright", ViaUpright, m, wrapped); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 261 | } |
tomhudson | 64de1e1 | 2015-03-05 08:01:07 -0800 | [diff] [blame] | 262 | |
| 263 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 264 | VIA("androidsdk", ViaAndroidSDK, wrapped); |
| 265 | #endif |
| 266 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 267 | #undef VIA |
| 268 | return NULL; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 269 | } |
| 270 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 271 | static void gather_sinks() { |
| 272 | for (int i = 0; i < FLAGS_config.count(); i++) { |
| 273 | const char* config = FLAGS_config[i]; |
| 274 | SkTArray<SkString> parts; |
| 275 | SkStrSplit(config, "-", &parts); |
| 276 | |
| 277 | Sink* sink = NULL; |
| 278 | for (int i = parts.count(); i-- > 0;) { |
| 279 | const char* part = parts[i].c_str(); |
| 280 | Sink* next = (sink == NULL) ? create_sink(part) : create_via(part, sink); |
| 281 | if (next == NULL) { |
| 282 | SkDebugf("Skipping %s: Don't understand '%s'.\n", config, part); |
| 283 | delete sink; |
| 284 | sink = NULL; |
| 285 | break; |
| 286 | } |
| 287 | sink = next; |
| 288 | } |
| 289 | if (sink) { |
| 290 | push_sink(config, sink); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 291 | } |
| 292 | } |
| 293 | } |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 294 | |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 295 | static bool match(const char* needle, const char* haystack) { |
| 296 | return 0 == strcmp("_", needle) || NULL != strstr(haystack, needle); |
| 297 | } |
| 298 | |
| 299 | static ImplicitString is_blacklisted(const char* sink, const char* src, const char* name) { |
| 300 | for (int i = 0; i < FLAGS_blacklist.count() - 2; i += 3) { |
| 301 | if (match(FLAGS_blacklist[i+0], sink) && |
| 302 | match(FLAGS_blacklist[i+1], src) && |
| 303 | match(FLAGS_blacklist[i+2], name)) { |
| 304 | return SkStringPrintf("%s %s %s", |
| 305 | FLAGS_blacklist[i+0], FLAGS_blacklist[i+1], FLAGS_blacklist[i+2]); |
| 306 | } |
| 307 | } |
| 308 | return ""; |
| 309 | } |
| 310 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 311 | // The finest-grained unit of work we can run: draw a single Src into a single Sink, |
| 312 | // report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream. |
| 313 | struct Task { |
| 314 | Task(const Tagged<Src>& src, const Tagged<Sink>& sink) : src(src), sink(sink) {} |
| 315 | const Tagged<Src>& src; |
| 316 | const Tagged<Sink>& sink; |
| 317 | |
| 318 | static void Run(Task* task) { |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 319 | SkString name = task->src->name(); |
| 320 | SkString whyBlacklisted = is_blacklisted(task->sink.tag, task->src.tag, name.c_str()); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 321 | SkString log; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 322 | WallTimer timer; |
| 323 | timer.start(); |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 324 | if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 325 | SkBitmap bitmap; |
| 326 | SkDynamicMemoryWStream stream; |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 327 | Error err = task->sink->draw(*task->src, &bitmap, &stream, &log); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 328 | if (!err.isEmpty()) { |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame^] | 329 | timer.end(); |
| 330 | if (err.isFatal()) { |
| 331 | fail(SkStringPrintf("%s %s %s: %s", |
| 332 | task->sink.tag, |
| 333 | task->src.tag, |
| 334 | name.c_str(), |
| 335 | err.c_str())); |
| 336 | } else { |
| 337 | name.appendf(" (skipped: %s)", err.c_str()); |
| 338 | } |
| 339 | done(timer.fWall, task->sink.tag, task->src.tag, name, log); |
| 340 | return; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 341 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 342 | SkAutoTDelete<SkStreamAsset> data(stream.detachAsStream()); |
| 343 | |
| 344 | SkString md5; |
| 345 | if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) { |
| 346 | SkMD5 hash; |
| 347 | if (data->getLength()) { |
| 348 | hash.writeStream(data, data->getLength()); |
| 349 | data->rewind(); |
| 350 | } else { |
| 351 | hash.write(bitmap.getPixels(), bitmap.getSize()); |
| 352 | } |
| 353 | SkMD5::Digest digest; |
| 354 | hash.finish(digest); |
| 355 | for (int i = 0; i < 16; i++) { |
| 356 | md5.appendf("%02x", digest.data[i]); |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | if (!FLAGS_readPath.isEmpty() && |
mtklein | a82f562 | 2015-02-20 12:30:19 -0800 | [diff] [blame] | 361 | !gGold.contains(Gold(task->sink.tag, task->src.tag, name, md5))) { |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 362 | fail(SkStringPrintf("%s not found for %s %s %s in %s", |
| 363 | md5.c_str(), |
| 364 | task->sink.tag, |
| 365 | task->src.tag, |
| 366 | name.c_str(), |
| 367 | FLAGS_readPath[0])); |
| 368 | } |
| 369 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 370 | if (!FLAGS_writePath.isEmpty()) { |
| 371 | const char* ext = task->sink->fileExtension(); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 372 | if (data->getLength()) { |
| 373 | WriteToDisk(*task, md5, ext, data, data->getLength(), NULL); |
halcanary | 022afb8 | 2015-01-30 11:00:12 -0800 | [diff] [blame] | 374 | SkASSERT(bitmap.drawsNothing()); |
| 375 | } else if (!bitmap.drawsNothing()) { |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 376 | WriteToDisk(*task, md5, ext, NULL, 0, &bitmap); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 377 | } |
| 378 | } |
| 379 | } |
| 380 | timer.end(); |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 381 | if (!whyBlacklisted.isEmpty()) { |
| 382 | name.appendf(" (--blacklist, %s)", whyBlacklisted.c_str()); |
| 383 | } |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 384 | done(timer.fWall, task->sink.tag, task->src.tag, name, log); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | static void WriteToDisk(const Task& task, |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 388 | SkString md5, |
| 389 | const char* ext, |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 390 | SkStream* data, size_t len, |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 391 | const SkBitmap* bitmap) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 392 | JsonWriter::BitmapResult result; |
| 393 | result.name = task.src->name(); |
| 394 | result.config = task.sink.tag; |
| 395 | result.sourceType = task.src.tag; |
| 396 | result.ext = ext; |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 397 | result.md5 = md5; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 398 | JsonWriter::AddBitmapResult(result); |
| 399 | |
| 400 | const char* dir = FLAGS_writePath[0]; |
| 401 | if (0 == strcmp(dir, "@")) { // Needed for iOS. |
| 402 | dir = FLAGS_resourcePath[0]; |
| 403 | } |
| 404 | sk_mkdir(dir); |
| 405 | |
| 406 | SkString path; |
| 407 | if (FLAGS_nameByHash) { |
| 408 | path = SkOSPath::Join(dir, result.md5.c_str()); |
| 409 | path.append("."); |
| 410 | path.append(ext); |
| 411 | if (sk_exists(path.c_str())) { |
| 412 | return; // Content-addressed. If it exists already, we're done. |
| 413 | } |
| 414 | } else { |
| 415 | path = SkOSPath::Join(dir, task.sink.tag); |
| 416 | sk_mkdir(path.c_str()); |
| 417 | path = SkOSPath::Join(path.c_str(), task.src.tag); |
| 418 | sk_mkdir(path.c_str()); |
| 419 | path = SkOSPath::Join(path.c_str(), task.src->name().c_str()); |
| 420 | path.append("."); |
| 421 | path.append(ext); |
| 422 | } |
| 423 | |
| 424 | SkFILEWStream file(path.c_str()); |
| 425 | if (!file.isValid()) { |
| 426 | fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str())); |
| 427 | return; |
| 428 | } |
| 429 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 430 | if (bitmap) { |
| 431 | // We can't encode A8 bitmaps as PNGs. Convert them to 8888 first. |
| 432 | SkBitmap converted; |
| 433 | if (bitmap->info().colorType() == kAlpha_8_SkColorType) { |
| 434 | if (!bitmap->copyTo(&converted, kN32_SkColorType)) { |
| 435 | fail("Can't convert A8 to 8888.\n"); |
| 436 | return; |
| 437 | } |
| 438 | bitmap = &converted; |
| 439 | } |
| 440 | if (!SkImageEncoder::EncodeStream(&file, *bitmap, SkImageEncoder::kPNG_Type, 100)) { |
| 441 | fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str())); |
| 442 | return; |
| 443 | } |
| 444 | } else { |
| 445 | if (!file.writeStream(data, len)) { |
| 446 | fail(SkStringPrintf("Can't write to %s.\n", path.c_str())); |
| 447 | return; |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | }; |
| 452 | |
| 453 | // Run all tasks in the same enclave serially on the same thread. |
| 454 | // They can't possibly run concurrently with each other. |
| 455 | static void run_enclave(SkTArray<Task>* tasks) { |
| 456 | for (int i = 0; i < tasks->count(); i++) { |
| 457 | Task::Run(tasks->begin() + i); |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 462 | |
| 463 | // Unit tests don't fit so well into the Src/Sink model, so we give them special treatment. |
| 464 | |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 465 | static SkTDArray<skiatest::Test> gThreadedTests, gGPUTests; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 466 | |
| 467 | static void gather_tests() { |
mtklein | 6c5fed2 | 2015-01-20 13:47:23 -0800 | [diff] [blame] | 468 | if (!FLAGS_src.contains("tests")) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 469 | return; |
| 470 | } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 471 | for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; |
| 472 | r = r->next()) { |
| 473 | // Despite its name, factory() is returning a reference to |
| 474 | // link-time static const POD data. |
| 475 | const skiatest::Test& test = r->factory(); |
| 476 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 477 | continue; |
| 478 | } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 479 | if (test.needsGpu && gpu_supported()) { |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 480 | (FLAGS_gpu_threading ? gThreadedTests : gGPUTests).push(test); |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 481 | } else if (!test.needsGpu && FLAGS_cpu) { |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 482 | gThreadedTests.push(test); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 483 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 484 | } |
| 485 | } |
| 486 | |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 487 | static void run_test(skiatest::Test* test) { |
| 488 | struct : public skiatest::Reporter { |
| 489 | void reportFailed(const skiatest::Failure& failure) SK_OVERRIDE { |
| 490 | fail(failure.toString()); |
| 491 | JsonWriter::AddTestFailure(failure); |
| 492 | } |
| 493 | bool allowExtendedTest() const SK_OVERRIDE { |
| 494 | return FLAGS_pathOpsExtended; |
| 495 | } |
| 496 | bool verbose() const SK_OVERRIDE { return FLAGS_veryVerbose; } |
| 497 | } reporter; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 498 | WallTimer timer; |
| 499 | timer.start(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 500 | if (!FLAGS_dryRun) { |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 501 | GrContextFactory factory; |
| 502 | test->proc(&reporter, &factory); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 503 | } |
| 504 | timer.end(); |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 505 | done(timer.fWall, "unit", "test", test->name, ""); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 509 | |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 510 | // If we're isolating all GPU-bound work to one thread (the default), this function runs all that. |
| 511 | static void run_enclave_and_gpu_tests(SkTArray<Task>* tasks) { |
| 512 | run_enclave(tasks); |
| 513 | for (int i = 0; i < gGPUTests.count(); i++) { |
| 514 | run_test(&gGPUTests[i]); |
| 515 | } |
| 516 | } |
| 517 | |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 518 | int dm_main(); |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 519 | int dm_main() { |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 520 | SetupCrashHandler(); |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 521 | SkAutoGraphics ag; |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 522 | SkTaskGroup::Enabler enabled(FLAGS_threads); |
mtklein | e67164d | 2015-02-02 13:24:37 -0800 | [diff] [blame] | 523 | if (FLAGS_leaks) { |
| 524 | SkInstCountPrintLeaksOnExit(); |
| 525 | } |
commit-bot@chromium.org | a65e2fd | 2014-05-30 17:23:31 +0000 | [diff] [blame] | 526 | |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 527 | gather_gold(); |
| 528 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 529 | gather_srcs(); |
| 530 | gather_sinks(); |
| 531 | gather_tests(); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 532 | |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 533 | gPending = gSrcs.count() * gSinks.count() + gThreadedTests.count() + gGPUTests.count(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 534 | SkDebugf("%d srcs * %d sinks + %d tests == %d tasks\n", |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 535 | gSrcs.count(), gSinks.count(), gThreadedTests.count() + gGPUTests.count(), gPending); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 536 | |
| 537 | // We try to exploit as much parallelism as is safe. Most Src/Sink pairs run on any thread, |
| 538 | // but Sinks that identify as part of a particular enclave run serially on a single thread. |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 539 | // CPU tests run on any thread. GPU tests depend on --gpu_threading. |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 540 | SkTArray<Task> enclaves[kNumEnclaves]; |
| 541 | for (int j = 0; j < gSinks.count(); j++) { |
| 542 | SkTArray<Task>& tasks = enclaves[gSinks[j]->enclave()]; |
| 543 | for (int i = 0; i < gSrcs.count(); i++) { |
| 544 | tasks.push_back(Task(gSrcs[i], gSinks[j])); |
| 545 | } |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 546 | } |
| 547 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 548 | SkTaskGroup tg; |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 549 | tg.batch(run_test, gThreadedTests.begin(), gThreadedTests.count()); |
| 550 | for (int i = 0; i < kNumEnclaves; i++) { |
| 551 | switch(i) { |
| 552 | case kAnyThread_Enclave: |
| 553 | tg.batch(Task::Run, enclaves[i].begin(), enclaves[i].count()); |
| 554 | break; |
| 555 | case kGPU_Enclave: |
| 556 | tg.add(run_enclave_and_gpu_tests, &enclaves[i]); |
| 557 | break; |
| 558 | default: |
| 559 | tg.add(run_enclave, &enclaves[i]); |
| 560 | break; |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 561 | } |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 562 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 563 | tg.wait(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 564 | // At this point we're back in single-threaded land. |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 565 | |
mtklein | 2f64eec | 2015-01-15 14:20:41 -0800 | [diff] [blame] | 566 | SkDebugf("\n"); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 567 | if (gFailures.count() > 0) { |
| 568 | SkDebugf("Failures:\n"); |
| 569 | for (int i = 0; i < gFailures.count(); i++) { |
mtklein | 9dc0910 | 2015-01-15 15:47:33 -0800 | [diff] [blame] | 570 | SkDebugf("\t%s\n", gFailures[i].c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 571 | } |
| 572 | SkDebugf("%d failures\n", gFailures.count()); |
| 573 | return 1; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 574 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 575 | if (gPending > 0) { |
| 576 | SkDebugf("Hrm, we didn't seem to run everything we intended to! Please file a bug.\n"); |
| 577 | return 1; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 578 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 579 | return 0; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 580 | } |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 581 | |
| 582 | #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
| 583 | int main(int argc, char** argv) { |
| 584 | SkCommandLineFlags::Parse(argc, argv); |
| 585 | return dm_main(); |
| 586 | } |
| 587 | #endif |