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