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" |
| 4 | #include "OverwriteLine.h" |
| 5 | #include "ProcStats.h" |
| 6 | #include "SkBBHFactory.h" |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 7 | #include "SkCommonFlags.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 8 | #include "SkForceLinking.h" |
| 9 | #include "SkGraphics.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 10 | #include "SkMD5.h" |
mtklein | 1d0f164 | 2014-09-08 08:05:18 -0700 | [diff] [blame] | 11 | #include "SkOSFile.h" |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 12 | #include "SkTaskGroup.h" |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 13 | #include "Test.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 14 | #include "Timer.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 15 | |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 16 | DEFINE_bool(tests, true, "Run tests?"); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 17 | DEFINE_string(images, "resources", "Images to decode."); |
mtklein | e131552 | 2015-01-15 13:58:56 -0800 | [diff] [blame] | 18 | DEFINE_string(src, "gm skp image subset", "Source types to test."); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 19 | DEFINE_bool(nameByHash, false, |
| 20 | "If true, write to FLAGS_writePath[0]/<hash>.png instead of " |
| 21 | "to FLAGS_writePath[0]/<config>/<sourceType>/<name>.png"); |
| 22 | DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests."); |
| 23 | DEFINE_string(matrix, "1 0 0 0 1 0 0 0 1", |
| 24 | "Matrix to apply when using 'matrix' in config."); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 25 | 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] | 26 | |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 27 | DEFINE_string(blacklist, "", |
| 28 | "Space-separated config/src/name triples to blacklist. '_' matches anything. E.g. \n" |
| 29 | "'--blacklist gpu skp _' will blacklist all SKPs drawn into the gpu config.\n" |
| 30 | "'--blacklist gpu skp _ 8888 gm aarects' will also blacklist the aarects GM on 8888."); |
| 31 | |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 32 | __SK_FORCE_IMAGE_DECODER_LINKING; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 33 | using namespace DM; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 34 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 35 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 36 | |
| 37 | SK_DECLARE_STATIC_MUTEX(gFailuresMutex); |
| 38 | static SkTArray<SkString> gFailures; |
| 39 | |
| 40 | static void fail(ImplicitString err) { |
| 41 | SkAutoMutexAcquire lock(gFailuresMutex); |
| 42 | SkDebugf("\n\nFAILURE: %s\n\n", err.c_str()); |
| 43 | gFailures.push_back(err); |
halcanary | 9e398f7 | 2015-01-10 11:18:04 -0800 | [diff] [blame] | 44 | } |
| 45 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 46 | static int32_t gPending = 0; // Atomic. |
| 47 | |
| 48 | static void done(double ms, ImplicitString config, ImplicitString src, ImplicitString name) { |
| 49 | SkDebugf("%s(%4dMB %5d) %s\t%s %s %s ", FLAGS_verbose ? "\n" : kSkOverwriteLine |
| 50 | , sk_tools::getMaxResidentSetSizeMB() |
| 51 | , sk_atomic_dec(&gPending)-1 |
| 52 | , HumanizeMs(ms).c_str() |
| 53 | , config.c_str() |
| 54 | , src.c_str() |
| 55 | , name.c_str()); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 56 | } |
| 57 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 58 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 59 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 60 | template <typename T> |
| 61 | struct Tagged : public SkAutoTDelete<T> { const char* tag; }; |
| 62 | |
| 63 | static const bool kMemcpyOK = true; |
| 64 | |
| 65 | static SkTArray<Tagged<Src>, kMemcpyOK> gSrcs; |
| 66 | static SkTArray<Tagged<Sink>, kMemcpyOK> gSinks; |
| 67 | |
| 68 | static void push_src(const char* tag, Src* s) { |
| 69 | SkAutoTDelete<Src> src(s); |
| 70 | if (FLAGS_src.contains(tag) && |
| 71 | !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) { |
| 72 | Tagged<Src>& s = gSrcs.push_back(); |
| 73 | s.reset(src.detach()); |
| 74 | s.tag = tag; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 75 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 76 | } |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 77 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 78 | static void gather_srcs() { |
| 79 | for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) { |
| 80 | push_src("gm", new GMSrc(r->factory())); |
| 81 | } |
| 82 | if (!FLAGS_skps.isEmpty()) { |
| 83 | SkOSFile::Iter it(FLAGS_skps[0], "skp"); |
| 84 | for (SkString file; it.next(&file); ) { |
| 85 | push_src("skp", new SKPSrc(SkOSPath::Join(FLAGS_skps[0], file.c_str()))); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 86 | } |
| 87 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 88 | if (!FLAGS_images.isEmpty()) { |
| 89 | const char* exts[] = { |
| 90 | "bmp", "gif", "jpg", "jpeg", "png", "webp", "ktx", "astc", "wbmp", "ico", |
| 91 | "BMP", "GIF", "JPG", "JPEG", "PNG", "WEBP", "KTX", "ASTC", "WBMP", "ICO", |
| 92 | }; |
| 93 | for (size_t i = 0; i < SK_ARRAY_COUNT(exts); i++) { |
| 94 | SkOSFile::Iter it(FLAGS_images[0], exts[i]); |
| 95 | for (SkString file; it.next(&file); ) { |
| 96 | SkString path = SkOSPath::Join(FLAGS_images[0], file.c_str()); |
| 97 | push_src("image", new ImageSrc(path)); // Decode entire image. |
| 98 | push_src("subset", new ImageSrc(path, 5)); // Decode 5 random subsets. |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 99 | } |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 100 | } |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 101 | } |
| 102 | } |
| 103 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 104 | static GrGLStandard get_gpu_api() { |
| 105 | if (FLAGS_gpuAPI.contains("gl")) { return kGL_GrGLStandard; } |
| 106 | if (FLAGS_gpuAPI.contains("gles")) { return kGLES_GrGLStandard; } |
| 107 | return kNone_GrGLStandard; |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 108 | } |
| 109 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 110 | static void push_sink(const char* tag, Sink* s) { |
| 111 | SkAutoTDelete<Sink> sink(s); |
| 112 | if (!FLAGS_config.contains(tag)) { |
| 113 | return; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 114 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 115 | // Try a noop Src as a canary. If it fails, skip this sink. |
| 116 | struct : public Src { |
| 117 | Error draw(SkCanvas*) const SK_OVERRIDE { return ""; } |
| 118 | SkISize size() const SK_OVERRIDE { return SkISize::Make(16, 16); } |
| 119 | Name name() const SK_OVERRIDE { return "noop"; } |
| 120 | } noop; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 121 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 122 | SkBitmap bitmap; |
| 123 | SkDynamicMemoryWStream stream; |
| 124 | Error err = sink->draw(noop, &bitmap, &stream); |
| 125 | if (!err.isEmpty()) { |
| 126 | SkDebugf("Skipping %s: %s\n", tag, err.c_str()); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 127 | return; |
| 128 | } |
| 129 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 130 | Tagged<Sink>& ts = gSinks.push_back(); |
| 131 | ts.reset(sink.detach()); |
| 132 | ts.tag = tag; |
| 133 | } |
| 134 | |
| 135 | static bool gpu_supported() { |
| 136 | #if SK_SUPPORT_GPU |
| 137 | return FLAGS_gpu; |
| 138 | #else |
| 139 | return false; |
| 140 | #endif |
| 141 | } |
| 142 | |
| 143 | static Sink* create_sink(const char* tag) { |
| 144 | #define SINK(t, sink, ...) if (0 == strcmp(t, tag)) { return new sink(__VA_ARGS__); } |
| 145 | if (gpu_supported()) { |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 146 | typedef GrContextFactory Gr; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 147 | const GrGLStandard api = get_gpu_api(); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 148 | SINK("gpunull", GPUSink, Gr::kNull_GLContextType, api, 0, false, FLAGS_gpu_threading); |
| 149 | SINK("gpudebug", GPUSink, Gr::kDebug_GLContextType, api, 0, false, FLAGS_gpu_threading); |
| 150 | SINK("gpu", GPUSink, Gr::kNative_GLContextType, api, 0, false, FLAGS_gpu_threading); |
| 151 | SINK("gpudft", GPUSink, Gr::kNative_GLContextType, api, 0, true, FLAGS_gpu_threading); |
| 152 | SINK("msaa4", GPUSink, Gr::kNative_GLContextType, api, 4, false, FLAGS_gpu_threading); |
| 153 | SINK("msaa16", GPUSink, Gr::kNative_GLContextType, api, 16, false, FLAGS_gpu_threading); |
| 154 | SINK("nvprmsaa4", GPUSink, Gr::kNVPR_GLContextType, api, 4, false, FLAGS_gpu_threading); |
| 155 | SINK("nvprmsaa16", GPUSink, Gr::kNVPR_GLContextType, api, 16, false, FLAGS_gpu_threading); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 156 | #if SK_ANGLE |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 157 | SINK("angle", GPUSink, Gr::kANGLE_GLContextType, api, 0, false, FLAGS_gpu_threading); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 158 | #endif |
| 159 | #if SK_MESA |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 160 | SINK("mesa", GPUSink, Gr::kMESA_GLContextType, api, 0, false, FLAGS_gpu_threading); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 161 | #endif |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 162 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 163 | |
| 164 | if (FLAGS_cpu) { |
| 165 | SINK("565", RasterSink, kRGB_565_SkColorType); |
| 166 | SINK("8888", RasterSink, kN32_SkColorType); |
| 167 | // TODO(mtklein): reenable once skiagold can handle .pdf uploads. |
| 168 | //SINK("pdf", PDFSink); |
| 169 | } |
| 170 | #undef SINK |
| 171 | return NULL; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 172 | } |
| 173 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 174 | static Sink* create_via(const char* tag, Sink* wrapped) { |
| 175 | #define VIA(t, via, ...) if (0 == strcmp(t, tag)) { return new via(__VA_ARGS__); } |
| 176 | VIA("serialize", ViaSerialization, wrapped); |
| 177 | |
| 178 | VIA("tiles", ViaTiles, 256, 256, NULL, wrapped); |
| 179 | VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped); |
| 180 | |
| 181 | const int xp = SkGPipeWriter::kCrossProcess_Flag, |
| 182 | sa = xp | SkGPipeWriter::kSharedAddressSpace_Flag; |
| 183 | VIA("pipe", ViaPipe, 0, wrapped); |
| 184 | VIA("pipe_xp", ViaPipe, xp, wrapped); |
| 185 | VIA("pipe_sa", ViaPipe, sa, wrapped); |
| 186 | |
| 187 | if (FLAGS_matrix.count() == 9) { |
| 188 | SkMatrix m; |
| 189 | for (int i = 0; i < 9; i++) { |
| 190 | m[i] = (SkScalar)atof(FLAGS_matrix[i]); |
| 191 | } |
| 192 | VIA("matrix", ViaMatrix, m, wrapped); |
| 193 | } |
| 194 | #undef VIA |
| 195 | return NULL; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 196 | } |
| 197 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 198 | static void gather_sinks() { |
| 199 | for (int i = 0; i < FLAGS_config.count(); i++) { |
| 200 | const char* config = FLAGS_config[i]; |
| 201 | SkTArray<SkString> parts; |
| 202 | SkStrSplit(config, "-", &parts); |
| 203 | |
| 204 | Sink* sink = NULL; |
| 205 | for (int i = parts.count(); i-- > 0;) { |
| 206 | const char* part = parts[i].c_str(); |
| 207 | Sink* next = (sink == NULL) ? create_sink(part) : create_via(part, sink); |
| 208 | if (next == NULL) { |
| 209 | SkDebugf("Skipping %s: Don't understand '%s'.\n", config, part); |
| 210 | delete sink; |
| 211 | sink = NULL; |
| 212 | break; |
| 213 | } |
| 214 | sink = next; |
| 215 | } |
| 216 | if (sink) { |
| 217 | push_sink(config, sink); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 218 | } |
| 219 | } |
| 220 | } |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 221 | |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 222 | static bool match(const char* needle, const char* haystack) { |
| 223 | return 0 == strcmp("_", needle) || NULL != strstr(haystack, needle); |
| 224 | } |
| 225 | |
| 226 | static ImplicitString is_blacklisted(const char* sink, const char* src, const char* name) { |
| 227 | for (int i = 0; i < FLAGS_blacklist.count() - 2; i += 3) { |
| 228 | if (match(FLAGS_blacklist[i+0], sink) && |
| 229 | match(FLAGS_blacklist[i+1], src) && |
| 230 | match(FLAGS_blacklist[i+2], name)) { |
| 231 | return SkStringPrintf("%s %s %s", |
| 232 | FLAGS_blacklist[i+0], FLAGS_blacklist[i+1], FLAGS_blacklist[i+2]); |
| 233 | } |
| 234 | } |
| 235 | return ""; |
| 236 | } |
| 237 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 238 | // The finest-grained unit of work we can run: draw a single Src into a single Sink, |
| 239 | // report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream. |
| 240 | struct Task { |
| 241 | Task(const Tagged<Src>& src, const Tagged<Sink>& sink) : src(src), sink(sink) {} |
| 242 | const Tagged<Src>& src; |
| 243 | const Tagged<Sink>& sink; |
| 244 | |
| 245 | static void Run(Task* task) { |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 246 | SkString name = task->src->name(); |
| 247 | SkString whyBlacklisted = is_blacklisted(task->sink.tag, task->src.tag, name.c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 248 | WallTimer timer; |
| 249 | timer.start(); |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 250 | if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 251 | SkBitmap bitmap; |
| 252 | SkDynamicMemoryWStream stream; |
| 253 | Error err = task->sink->draw(*task->src, &bitmap, &stream); |
| 254 | if (!err.isEmpty()) { |
| 255 | fail(SkStringPrintf("%s %s %s: %s", |
| 256 | task->sink.tag, |
| 257 | task->src.tag, |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 258 | name.c_str(), |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 259 | err.c_str())); |
| 260 | } |
| 261 | if (!FLAGS_writePath.isEmpty()) { |
| 262 | const char* ext = task->sink->fileExtension(); |
| 263 | if (stream.bytesWritten() == 0) { |
| 264 | SkMemoryStream pixels(bitmap.getPixels(), bitmap.getSize()); |
| 265 | WriteToDisk(*task, &pixels, bitmap.getSize(), &bitmap, ext); |
| 266 | } else { |
| 267 | SkAutoTDelete<SkStreamAsset> data(stream.detachAsStream()); |
| 268 | WriteToDisk(*task, data, data->getLength(), NULL, ext); |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | timer.end(); |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 273 | if (!whyBlacklisted.isEmpty()) { |
| 274 | name.appendf(" (--blacklist, %s)", whyBlacklisted.c_str()); |
| 275 | } |
| 276 | done(timer.fWall, task->sink.tag, task->src.tag, name); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | static void WriteToDisk(const Task& task, |
| 280 | SkStream* data, size_t len, |
| 281 | const SkBitmap* bitmap, |
| 282 | const char* ext) { |
| 283 | SkMD5 hash; |
| 284 | hash.writeStream(data, len); |
| 285 | SkMD5::Digest digest; |
| 286 | hash.finish(digest); |
| 287 | |
| 288 | JsonWriter::BitmapResult result; |
| 289 | result.name = task.src->name(); |
| 290 | result.config = task.sink.tag; |
| 291 | result.sourceType = task.src.tag; |
| 292 | result.ext = ext; |
| 293 | for (int i = 0; i < 16; i++) { |
| 294 | result.md5.appendf("%02x", digest.data[i]); |
| 295 | } |
| 296 | JsonWriter::AddBitmapResult(result); |
| 297 | |
| 298 | const char* dir = FLAGS_writePath[0]; |
| 299 | if (0 == strcmp(dir, "@")) { // Needed for iOS. |
| 300 | dir = FLAGS_resourcePath[0]; |
| 301 | } |
| 302 | sk_mkdir(dir); |
| 303 | |
| 304 | SkString path; |
| 305 | if (FLAGS_nameByHash) { |
| 306 | path = SkOSPath::Join(dir, result.md5.c_str()); |
| 307 | path.append("."); |
| 308 | path.append(ext); |
| 309 | if (sk_exists(path.c_str())) { |
| 310 | return; // Content-addressed. If it exists already, we're done. |
| 311 | } |
| 312 | } else { |
| 313 | path = SkOSPath::Join(dir, task.sink.tag); |
| 314 | sk_mkdir(path.c_str()); |
| 315 | path = SkOSPath::Join(path.c_str(), task.src.tag); |
| 316 | sk_mkdir(path.c_str()); |
| 317 | path = SkOSPath::Join(path.c_str(), task.src->name().c_str()); |
| 318 | path.append("."); |
| 319 | path.append(ext); |
| 320 | } |
| 321 | |
| 322 | SkFILEWStream file(path.c_str()); |
| 323 | if (!file.isValid()) { |
| 324 | fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str())); |
| 325 | return; |
| 326 | } |
| 327 | |
| 328 | data->rewind(); |
| 329 | if (bitmap) { |
| 330 | // We can't encode A8 bitmaps as PNGs. Convert them to 8888 first. |
| 331 | SkBitmap converted; |
| 332 | if (bitmap->info().colorType() == kAlpha_8_SkColorType) { |
| 333 | if (!bitmap->copyTo(&converted, kN32_SkColorType)) { |
| 334 | fail("Can't convert A8 to 8888.\n"); |
| 335 | return; |
| 336 | } |
| 337 | bitmap = &converted; |
| 338 | } |
| 339 | if (!SkImageEncoder::EncodeStream(&file, *bitmap, SkImageEncoder::kPNG_Type, 100)) { |
| 340 | fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str())); |
| 341 | return; |
| 342 | } |
| 343 | } else { |
| 344 | if (!file.writeStream(data, len)) { |
| 345 | fail(SkStringPrintf("Can't write to %s.\n", path.c_str())); |
| 346 | return; |
| 347 | } |
| 348 | } |
| 349 | } |
| 350 | }; |
| 351 | |
| 352 | // Run all tasks in the same enclave serially on the same thread. |
| 353 | // They can't possibly run concurrently with each other. |
| 354 | static void run_enclave(SkTArray<Task>* tasks) { |
| 355 | for (int i = 0; i < tasks->count(); i++) { |
| 356 | Task::Run(tasks->begin() + i); |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 361 | |
| 362 | // Unit tests don't fit so well into the Src/Sink model, so we give them special treatment. |
| 363 | |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame^] | 364 | static SkTDArray<skiatest::Test> gCPUTests, gGPUTests; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 365 | |
| 366 | static void gather_tests() { |
| 367 | if (!FLAGS_tests) { |
| 368 | return; |
| 369 | } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame^] | 370 | for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; |
| 371 | r = r->next()) { |
| 372 | // Despite its name, factory() is returning a reference to |
| 373 | // link-time static const POD data. |
| 374 | const skiatest::Test& test = r->factory(); |
| 375 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 376 | continue; |
| 377 | } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame^] | 378 | if (test.needsGpu && gpu_supported()) { |
| 379 | gGPUTests.push(test); |
| 380 | } else if (!test.needsGpu && FLAGS_cpu) { |
| 381 | gCPUTests.push(test); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 382 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 383 | } |
| 384 | } |
| 385 | |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame^] | 386 | static void run_test(skiatest::Test* test) { |
| 387 | struct : public skiatest::Reporter { |
| 388 | void reportFailed(const skiatest::Failure& failure) SK_OVERRIDE { |
| 389 | fail(failure.toString()); |
| 390 | JsonWriter::AddTestFailure(failure); |
| 391 | } |
| 392 | bool allowExtendedTest() const SK_OVERRIDE { |
| 393 | return FLAGS_pathOpsExtended; |
| 394 | } |
| 395 | bool verbose() const SK_OVERRIDE { return FLAGS_veryVerbose; } |
| 396 | } reporter; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 397 | WallTimer timer; |
| 398 | timer.start(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 399 | if (!FLAGS_dryRun) { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame^] | 400 | test->proc(&reporter, GetThreadLocalGrContextFactory()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 401 | } |
| 402 | timer.end(); |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame^] | 403 | done(timer.fWall, "unit", "test", test->name); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 407 | |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 408 | int dm_main(); |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 409 | int dm_main() { |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 410 | SetupCrashHandler(); |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 411 | SkAutoGraphics ag; |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 412 | SkTaskGroup::Enabler enabled(FLAGS_threads); |
commit-bot@chromium.org | a65e2fd | 2014-05-30 17:23:31 +0000 | [diff] [blame] | 413 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 414 | gather_srcs(); |
| 415 | gather_sinks(); |
| 416 | gather_tests(); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 417 | |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 418 | gPending = gSrcs.count() * gSinks.count() + gCPUTests.count() + gGPUTests.count(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 419 | SkDebugf("%d srcs * %d sinks + %d tests == %d tasks\n", |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 420 | gSrcs.count(), gSinks.count(), gCPUTests.count() + gGPUTests.count(), gPending); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 421 | |
| 422 | // We try to exploit as much parallelism as is safe. Most Src/Sink pairs run on any thread, |
| 423 | // 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] | 424 | // CPU tests run on any thread. GPU tests depend on --gpu_threading. |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 425 | SkTArray<Task> enclaves[kNumEnclaves]; |
| 426 | for (int j = 0; j < gSinks.count(); j++) { |
| 427 | SkTArray<Task>& tasks = enclaves[gSinks[j]->enclave()]; |
| 428 | for (int i = 0; i < gSrcs.count(); i++) { |
| 429 | tasks.push_back(Task(gSrcs[i], gSinks[j])); |
| 430 | } |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 431 | } |
| 432 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 433 | SK_COMPILE_ASSERT(kAnyThread_Enclave == 0, AnyThreadZero); |
| 434 | SkTaskGroup tg; |
| 435 | tg.batch( Task::Run, enclaves[0].begin(), enclaves[0].count()); |
| 436 | tg.batch(run_enclave, enclaves+1, kNumEnclaves-1); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 437 | tg.batch( run_test, gCPUTests.begin(), gCPUTests.count()); |
| 438 | if (FLAGS_gpu_threading) { |
| 439 | tg.batch(run_test, gGPUTests.begin(), gGPUTests.count()); |
mtklein | 2f64eec | 2015-01-15 14:20:41 -0800 | [diff] [blame] | 440 | #if !defined(SK_BUILD_FOR_WIN32) |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 441 | } else { |
| 442 | for (int i = 0; i < gGPUTests.count(); i++) { |
| 443 | run_test(&gGPUTests[i]); |
| 444 | } |
mtklein | 2f64eec | 2015-01-15 14:20:41 -0800 | [diff] [blame] | 445 | #endif |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 446 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 447 | tg.wait(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 448 | // At this point we're back in single-threaded land. |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 449 | |
mtklein | 2f64eec | 2015-01-15 14:20:41 -0800 | [diff] [blame] | 450 | // This is not ideal for parallelism, but Windows seems crash-prone if we run |
| 451 | // these GPU tests in parallel with any GPU Src/Sink work. Everyone else seems fine. |
| 452 | #if defined(SK_BUILD_FOR_WIN32) |
| 453 | for (int i = 0; i < gGPUTests.count(); i++) { |
| 454 | run_test(&gGPUTests[i]); |
| 455 | } |
| 456 | #endif |
| 457 | |
| 458 | SkDebugf("\n"); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 459 | JsonWriter::DumpJson(); |
| 460 | |
| 461 | if (gFailures.count() > 0) { |
| 462 | SkDebugf("Failures:\n"); |
| 463 | for (int i = 0; i < gFailures.count(); i++) { |
mtklein | 9dc0910 | 2015-01-15 15:47:33 -0800 | [diff] [blame] | 464 | SkDebugf("\t%s\n", gFailures[i].c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 465 | } |
| 466 | SkDebugf("%d failures\n", gFailures.count()); |
| 467 | return 1; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 468 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 469 | if (gPending > 0) { |
| 470 | SkDebugf("Hrm, we didn't seem to run everything we intended to! Please file a bug.\n"); |
| 471 | return 1; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 472 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 473 | return 0; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 474 | } |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 475 | |
| 476 | #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
| 477 | int main(int argc, char** argv) { |
| 478 | SkCommandLineFlags::Parse(argc, argv); |
| 479 | return dm_main(); |
| 480 | } |
| 481 | #endif |