blob: f194304ecf39a1e6e050a2014d8663308d884d41 [file] [log] [blame]
scroggo478652e2015-03-25 07:11:02 -07001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
jcgregorio3b27ade2014-11-13 08:06:40 -08008#include "CrashHandler.h"
mtklein748ca3b2015-01-15 10:56:12 -08009#include "DMJsonWriter.h"
10#include "DMSrcSink.h"
tomhudsoneebc39a2015-02-23 12:18:05 -080011#include "DMSrcSinkAndroid.h"
mtklein748ca3b2015-01-15 10:56:12 -080012#include "OverwriteLine.h"
13#include "ProcStats.h"
14#include "SkBBHFactory.h"
mtklein62bd1a62015-01-27 14:46:26 -080015#include "SkChecksum.h"
caryclark17f0b6d2014-07-22 10:15:34 -070016#include "SkCommonFlags.h"
caryclark83ca6282015-06-10 09:31:09 -070017#include "SkFontMgr.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000018#include "SkForceLinking.h"
19#include "SkGraphics.h"
mtklein748ca3b2015-01-15 10:56:12 -080020#include "SkMD5.h"
mtklein1b249332015-07-07 12:21:21 -070021#include "SkMutex.h"
mtklein1d0f1642014-09-08 08:05:18 -070022#include "SkOSFile.h"
mtkleina82f5622015-02-20 12:30:19 -080023#include "SkTHash.h"
mtklein406654b2014-09-03 15:34:37 -070024#include "SkTaskGroup.h"
mtkleinde6fc2b2015-03-12 06:28:54 -070025#include "SkThreadUtils.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000026#include "Test.h"
mtklein748ca3b2015-01-15 10:56:12 -080027#include "Timer.h"
caryclark83ca6282015-06-10 09:31:09 -070028#include "sk_tool_utils.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000029
djsollen54416de2015-04-03 07:24:48 -070030DEFINE_string(src, "tests gm skp image", "Source types to test.");
mtklein748ca3b2015-01-15 10:56:12 -080031DEFINE_bool(nameByHash, false,
32 "If true, write to FLAGS_writePath[0]/<hash>.png instead of "
djsollen54416de2015-04-03 07:24:48 -070033 "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.png");
mtklein748ca3b2015-01-15 10:56:12 -080034DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests.");
mtkleind603b222015-02-17 11:13:33 -080035DEFINE_string(matrix, "1 0 0 1",
36 "2x2 scale+skew matrix to apply or upright when using "
37 "'matrix' or 'upright' in config.");
mtklein82d28432015-01-15 12:46:02 -080038DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?");
mtklein@google.comd36522d2013-10-16 13:02:15 +000039
mtkleina2ef6422015-01-15 13:44:22 -080040DEFINE_string(blacklist, "",
djsollen54416de2015-04-03 07:24:48 -070041 "Space-separated config/src/srcOptions/name quadruples to blacklist. '_' matches anything. E.g. \n"
42 "'--blacklist gpu skp _ _' will blacklist all SKPs drawn into the gpu config.\n"
43 "'--blacklist gpu skp _ _ 8888 gm _ aarects' will also blacklist the aarects GM on 8888.");
mtkleina2ef6422015-01-15 13:44:22 -080044
mtklein62bd1a62015-01-27 14:46:26 -080045DEFINE_string2(readPath, r, "", "If set check for equality with golden results in this directory.");
46
borenet09ed4802015-04-03 14:15:33 -070047DEFINE_string(uninterestingHashesFile, "",
48 "File containing a list of uninteresting hashes. If a result hashes to something in "
49 "this list, no image is written for that result.");
50
mtklein6393c062015-04-27 08:45:01 -070051DEFINE_int32(shards, 1, "We're splitting source data into this many shards.");
52DEFINE_int32(shard, 0, "Which shard do I run?");
bsalomon821e10e2015-06-04 14:15:33 -070053DEFINE_bool2(pre_log, p, false, "Log before running each test. May be incomprehensible when threading");
mtklein6393c062015-04-27 08:45:01 -070054
mtklein@google.comd36522d2013-10-16 13:02:15 +000055__SK_FORCE_IMAGE_DECODER_LINKING;
mtklein748ca3b2015-01-15 10:56:12 -080056using namespace DM;
mtklein@google.comd36522d2013-10-16 13:02:15 +000057
mtklein748ca3b2015-01-15 10:56:12 -080058/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
59
60SK_DECLARE_STATIC_MUTEX(gFailuresMutex);
61static SkTArray<SkString> gFailures;
62
63static void fail(ImplicitString err) {
64 SkAutoMutexAcquire lock(gFailuresMutex);
65 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str());
66 gFailures.push_back(err);
halcanary9e398f72015-01-10 11:18:04 -080067}
68
mtkleinb37cb412015-03-18 05:27:14 -070069static int32_t gPending = 0; // Atomic. Total number of running and queued tasks.
70
71SK_DECLARE_STATIC_MUTEX(gRunningMutex);
72static SkTArray<SkString> gRunning;
mtklein748ca3b2015-01-15 10:56:12 -080073
mtkleinb9eb4ac2015-02-02 18:26:03 -080074static void done(double ms,
djsollen54416de2015-04-03 07:24:48 -070075 ImplicitString config, ImplicitString src, ImplicitString srcOptions,
76 ImplicitString name, ImplicitString note, ImplicitString log) {
77 SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(),
78 srcOptions.c_str(), name.c_str());
mtkleinb37cb412015-03-18 05:27:14 -070079 {
80 SkAutoMutexAcquire lock(gRunningMutex);
81 for (int i = 0; i < gRunning.count(); i++) {
82 if (gRunning[i] == id) {
83 gRunning.removeShuffle(i);
84 break;
85 }
86 }
87 }
88 if (!FLAGS_verbose) {
89 note = "";
90 }
mtkleinb9eb4ac2015-02-02 18:26:03 -080091 if (!log.isEmpty()) {
92 log.prepend("\n");
93 }
mtklein6dee2ad2015-02-05 09:53:44 -080094 auto pending = sk_atomic_dec(&gPending)-1;
reed50bc0512015-05-19 14:13:31 -070095 if (!FLAGS_quiet) {
mtklein711a2452015-07-08 08:49:20 -070096 SkDebugf("%s(%4d/%-4dMB %6d) %s\t%s%s%s", FLAGS_verbose ? "\n" : kSkOverwriteLine
reed50bc0512015-05-19 14:13:31 -070097 , sk_tools::getCurrResidentSetSizeMB()
98 , sk_tools::getMaxResidentSetSizeMB()
99 , pending
100 , HumanizeMs(ms).c_str()
101 , id.c_str()
102 , note.c_str()
103 , log.c_str());
104 }
mtkleina17241b2015-01-23 05:48:00 -0800105 // We write our dm.json file every once in a while in case we crash.
106 // Notice this also handles the final dm.json when pending == 0.
107 if (pending % 500 == 0) {
108 JsonWriter::DumpJson();
109 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000110}
111
djsollen54416de2015-04-03 07:24:48 -0700112static void start(ImplicitString config, ImplicitString src,
113 ImplicitString srcOptions, ImplicitString name) {
114 SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(),
115 srcOptions.c_str(), name.c_str());
mtkleinb37cb412015-03-18 05:27:14 -0700116 SkAutoMutexAcquire lock(gRunningMutex);
117 gRunning.push_back(id);
118}
119
mtklein748ca3b2015-01-15 10:56:12 -0800120/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
mtklein114c3cd2015-01-15 10:15:02 -0800121
mtklein62bd1a62015-01-27 14:46:26 -0800122struct Gold : public SkString {
mtkleina82f5622015-02-20 12:30:19 -0800123 Gold() : SkString("") {}
djsollen54416de2015-04-03 07:24:48 -0700124 Gold(ImplicitString sink, ImplicitString src, ImplicitString srcOptions,
125 ImplicitString name, ImplicitString md5)
mtklein62bd1a62015-01-27 14:46:26 -0800126 : SkString("") {
127 this->append(sink);
128 this->append(src);
djsollen54416de2015-04-03 07:24:48 -0700129 this->append(srcOptions);
mtklein62bd1a62015-01-27 14:46:26 -0800130 this->append(name);
131 this->append(md5);
mtklein62bd1a62015-01-27 14:46:26 -0800132 }
mtklein02f46cf2015-03-20 13:48:42 -0700133 static uint32_t Hash(const Gold& g) { return SkGoodHash((const SkString&)g); }
mtklein62bd1a62015-01-27 14:46:26 -0800134};
mtkleina82f5622015-02-20 12:30:19 -0800135static SkTHashSet<Gold, Gold::Hash> gGold;
mtklein62bd1a62015-01-27 14:46:26 -0800136
137static void add_gold(JsonWriter::BitmapResult r) {
djsollen54416de2015-04-03 07:24:48 -0700138 gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5));
mtklein62bd1a62015-01-27 14:46:26 -0800139}
140
141static void gather_gold() {
142 if (!FLAGS_readPath.isEmpty()) {
143 SkString path(FLAGS_readPath[0]);
144 path.append("/dm.json");
145 if (!JsonWriter::ReadJson(path.c_str(), add_gold)) {
146 fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str()));
147 }
148 }
149}
150
151/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
152
borenet09ed4802015-04-03 14:15:33 -0700153static SkTHashSet<SkString> gUninterestingHashes;
154
155static void gather_uninteresting_hashes() {
156 if (!FLAGS_uninterestingHashesFile.isEmpty()) {
157 SkAutoTUnref<SkData> data(SkData::NewFromFileName(FLAGS_uninterestingHashesFile[0]));
158 SkTArray<SkString> hashes;
159 SkStrSplit((const char*)data->data(), "\n", &hashes);
160 for (const SkString& hash : hashes) {
161 gUninterestingHashes.add(hash);
162 }
163 }
164}
165
166/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
167
mtkleine0effd62015-07-29 06:37:28 -0700168struct TaggedSrc : public SkAutoTDelete<Src> {
169 const char* tag;
170 const char* options;
171};
172
173struct TaggedSink : public SkAutoTDelete<Sink> {
174 const char* tag;
175 const char* options;
176 SinkType type;
djsollen54416de2015-04-03 07:24:48 -0700177};
mtklein748ca3b2015-01-15 10:56:12 -0800178
179static const bool kMemcpyOK = true;
180
mtkleine0effd62015-07-29 06:37:28 -0700181static SkTArray<TaggedSrc, kMemcpyOK> gSrcs;
182static SkTArray<TaggedSink, kMemcpyOK> gSinks;
mtklein748ca3b2015-01-15 10:56:12 -0800183
mtklein6393c062015-04-27 08:45:01 -0700184static bool in_shard() {
185 static int N = 0;
186 return N++ % FLAGS_shards == FLAGS_shard;
187}
188
djsollen54416de2015-04-03 07:24:48 -0700189static void push_src(const char* tag, const char* options, Src* s) {
mtklein748ca3b2015-01-15 10:56:12 -0800190 SkAutoTDelete<Src> src(s);
mtklein6393c062015-04-27 08:45:01 -0700191 if (in_shard() &&
192 FLAGS_src.contains(tag) &&
mtklein748ca3b2015-01-15 10:56:12 -0800193 !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) {
mtkleine0effd62015-07-29 06:37:28 -0700194 TaggedSrc& s = gSrcs.push_back();
mtklein748ca3b2015-01-15 10:56:12 -0800195 s.reset(src.detach());
196 s.tag = tag;
djsollen54416de2015-04-03 07:24:48 -0700197 s.options = options;
mtklein114c3cd2015-01-15 10:15:02 -0800198 }
mtklein748ca3b2015-01-15 10:56:12 -0800199}
mtklein114c3cd2015-01-15 10:15:02 -0800200
msarett438b2ad2015-04-09 12:43:10 -0700201static void push_codec_srcs(Path path) {
202 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
203 if (!encoded) {
204 SkDebugf("Couldn't read %s.", path.c_str());
205 return;
206 }
207 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
208 if (NULL == codec.get()) {
209 SkDebugf("Couldn't create codec for %s.", path.c_str());
210 return;
211 }
212
msarett0a242972015-06-11 14:27:27 -0700213 // Choose scales for scaling tests.
214 // TODO (msarett): Add more scaling tests as we implement more flexible scaling.
215 // TODO (msarett): Implement scaling tests for SkImageDecoder in order to compare with these
216 // tests. SkImageDecoder supports downscales by integer factors.
msarett1c8a5872015-07-07 08:50:01 -0700217 const float scales[] = { 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.750f, 0.875f, 1.0f };
msarett438b2ad2015-04-09 12:43:10 -0700218
msarett0a242972015-06-11 14:27:27 -0700219 for (float scale : scales) {
scroggo6f818b32015-07-13 08:17:00 -0700220 if (scale != 1.0f && (path.endsWith(".webp") || path.endsWith(".WEBP"))) {
221 // FIXME: skbug.com/4038 Scaling webp seems to leave some pixels uninitialized/
222 // compute their colors based on uninitialized values.
223 continue;
224 }
msarett0a242972015-06-11 14:27:27 -0700225 // Build additional test cases for images that decode natively to non-canvas types
226 switch(codec->getInfo().colorType()) {
227 case kGray_8_SkColorType:
228 push_src("image", "codec_kGray8", new CodecSrc(path, CodecSrc::kNormal_Mode,
229 CodecSrc::kGrayscale_Always_DstColorType, scale));
230 push_src("image", "scanline_kGray8", new CodecSrc(path, CodecSrc::kScanline_Mode,
231 CodecSrc::kGrayscale_Always_DstColorType, scale));
232 push_src("image", "scanline_subset_kGray8", new CodecSrc(path,
233 CodecSrc::kScanline_Subset_Mode, CodecSrc::kGrayscale_Always_DstColorType,
234 scale));
235 push_src("image", "stripe_kGray8", new CodecSrc(path, CodecSrc::kStripe_Mode,
236 CodecSrc::kGrayscale_Always_DstColorType, scale));
237 // Intentional fall through
238 // FIXME: Is this a long term solution for testing wbmps decodes to kIndex8?
239 // Further discussion on this topic is at skbug.com/3683
240 case kIndex_8_SkColorType:
241 push_src("image", "codec_kIndex8", new CodecSrc(path, CodecSrc::kNormal_Mode,
242 CodecSrc::kIndex8_Always_DstColorType, scale));
243 push_src("image", "scanline_kIndex8", new CodecSrc(path, CodecSrc::kScanline_Mode,
244 CodecSrc::kIndex8_Always_DstColorType, scale));
245 push_src("image", "scanline_subset_kIndex8", new CodecSrc(path,
246 CodecSrc::kScanline_Subset_Mode, CodecSrc::kIndex8_Always_DstColorType,
247 scale));
248 push_src("image", "stripe_kIndex8", new CodecSrc(path, CodecSrc::kStripe_Mode,
249 CodecSrc::kIndex8_Always_DstColorType, scale));
250 break;
251 default:
252 // Do nothing
253 break;
254 }
255
256 // Decode all images to the canvas color type
257 push_src("image", "codec", new CodecSrc(path, CodecSrc::kNormal_Mode,
258 CodecSrc::kGetFromCanvas_DstColorType, scale));
259 push_src("image", "scanline", new CodecSrc(path, CodecSrc::kScanline_Mode,
260 CodecSrc::kGetFromCanvas_DstColorType, scale));
261 push_src("image", "scanline_subset", new CodecSrc(path, CodecSrc::kScanline_Subset_Mode,
262 CodecSrc::kGetFromCanvas_DstColorType, scale));
263 push_src("image", "stripe", new CodecSrc(path, CodecSrc::kStripe_Mode,
264 CodecSrc::kGetFromCanvas_DstColorType, scale));
scroggob636b452015-07-22 07:16:20 -0700265 // Note: The only codec which supports subsets natively is SkWebpCodec, which will never
266 // report kIndex_8 or kGray_8, so there is no need to test kSubset_mode with those color
267 // types specifically requested.
268 push_src("image", "codec_subset", new CodecSrc(path, CodecSrc::kSubset_Mode,
269 CodecSrc::kGetFromCanvas_DstColorType, scale));
msarett0a242972015-06-11 14:27:27 -0700270 }
msarett438b2ad2015-04-09 12:43:10 -0700271}
272
scroggo9b77ddd2015-03-19 06:03:39 -0700273static bool codec_supported(const char* ext) {
274 // FIXME: Once other versions of SkCodec are available, we can add them to this
275 // list (and eventually we can remove this check once they are all supported).
msarett8c8f22a2015-04-01 06:58:48 -0700276 static const char* const exts[] = {
scroggo6f5e6192015-06-18 12:53:43 -0700277 "bmp", "gif", "jpg", "jpeg", "png", "ico", "wbmp", "webp",
278 "BMP", "GIF", "JPG", "JPEG", "PNG", "ICO", "WBMP", "WEBP",
msarett8c8f22a2015-04-01 06:58:48 -0700279 };
280
281 for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) {
282 if (0 == strcmp(exts[i], ext)) {
283 return true;
284 }
285 }
286 return false;
scroggo9b77ddd2015-03-19 06:03:39 -0700287}
288
mtklein748ca3b2015-01-15 10:56:12 -0800289static void gather_srcs() {
290 for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) {
djsollen54416de2015-04-03 07:24:48 -0700291 push_src("gm", "", new GMSrc(r->factory()));
mtklein748ca3b2015-01-15 10:56:12 -0800292 }
halcanaryfc37ad12015-01-30 07:31:19 -0800293 for (int i = 0; i < FLAGS_skps.count(); i++) {
294 const char* path = FLAGS_skps[i];
295 if (sk_isdir(path)) {
296 SkOSFile::Iter it(path, "skp");
297 for (SkString file; it.next(&file); ) {
djsollen54416de2015-04-03 07:24:48 -0700298 push_src("skp", "", new SKPSrc(SkOSPath::Join(path, file.c_str())));
halcanaryfc37ad12015-01-30 07:31:19 -0800299 }
300 } else {
djsollen54416de2015-04-03 07:24:48 -0700301 push_src("skp", "", new SKPSrc(path));
mtklein114c3cd2015-01-15 10:15:02 -0800302 }
303 }
halcanary23b03c32015-01-30 09:58:58 -0800304 static const char* const exts[] = {
305 "bmp", "gif", "jpg", "jpeg", "png", "webp", "ktx", "astc", "wbmp", "ico",
306 "BMP", "GIF", "JPG", "JPEG", "PNG", "WEBP", "KTX", "ASTC", "WBMP", "ICO",
307 };
308 for (int i = 0; i < FLAGS_images.count(); i++) {
309 const char* flag = FLAGS_images[i];
310 if (sk_isdir(flag)) {
311 for (size_t j = 0; j < SK_ARRAY_COUNT(exts); j++) {
312 SkOSFile::Iter it(flag, exts[j]);
313 for (SkString file; it.next(&file); ) {
314 SkString path = SkOSPath::Join(flag, file.c_str());
djsollen54416de2015-04-03 07:24:48 -0700315 push_src("image", "decode", new ImageSrc(path)); // Decode entire image
316 push_src("image", "subset", new ImageSrc(path, 2)); // Decode into 2x2 subsets
scroggo9b77ddd2015-03-19 06:03:39 -0700317 if (codec_supported(exts[j])) {
msarett438b2ad2015-04-09 12:43:10 -0700318 push_codec_srcs(path);
scroggo9b77ddd2015-03-19 06:03:39 -0700319 }
halcanary23b03c32015-01-30 09:58:58 -0800320 }
mtklein114c3cd2015-01-15 10:15:02 -0800321 }
halcanary23b03c32015-01-30 09:58:58 -0800322 } else if (sk_exists(flag)) {
323 // assume that FLAGS_images[i] is a valid image if it is a file.
djsollen54416de2015-04-03 07:24:48 -0700324 push_src("image", "decode", new ImageSrc(flag)); // Decode entire image.
325 push_src("image", "subset", new ImageSrc(flag, 2)); // Decode into 2 x 2 subsets
msarett438b2ad2015-04-09 12:43:10 -0700326 push_codec_srcs(flag);
mtklein709d2c32015-01-15 08:30:25 -0800327 }
mtklein709d2c32015-01-15 08:30:25 -0800328 }
329}
330
mtklein748ca3b2015-01-15 10:56:12 -0800331static GrGLStandard get_gpu_api() {
332 if (FLAGS_gpuAPI.contains("gl")) { return kGL_GrGLStandard; }
333 if (FLAGS_gpuAPI.contains("gles")) { return kGLES_GrGLStandard; }
334 return kNone_GrGLStandard;
mtklein709d2c32015-01-15 08:30:25 -0800335}
336
mtklein748ca3b2015-01-15 10:56:12 -0800337static void push_sink(const char* tag, Sink* s) {
338 SkAutoTDelete<Sink> sink(s);
339 if (!FLAGS_config.contains(tag)) {
340 return;
mtklein114c3cd2015-01-15 10:15:02 -0800341 }
mtkleine0effd62015-07-29 06:37:28 -0700342 // Try a simple Src as a canary. If it fails, skip this sink.
mtklein748ca3b2015-01-15 10:56:12 -0800343 struct : public Src {
mtkleine0effd62015-07-29 06:37:28 -0700344 Error draw(SkCanvas* c) const override {
345 c->drawRect(SkRect::MakeWH(1,1), SkPaint());
346 return "";
347 }
mtklein36352bf2015-03-25 18:17:31 -0700348 SkISize size() const override { return SkISize::Make(16, 16); }
mtkleine0effd62015-07-29 06:37:28 -0700349 Name name() const override { return "justOneRect"; }
350 } justOneRect;
mtklein114c3cd2015-01-15 10:15:02 -0800351
mtklein748ca3b2015-01-15 10:56:12 -0800352 SkBitmap bitmap;
353 SkDynamicMemoryWStream stream;
mtkleinb9eb4ac2015-02-02 18:26:03 -0800354 SkString log;
mtkleine0effd62015-07-29 06:37:28 -0700355 Error err = sink->draw(justOneRect, &bitmap, &stream, &log);
mtklein4089ef72015-03-05 08:40:28 -0800356 if (err.isFatal()) {
mtklein05641a52015-04-21 10:49:13 -0700357 SkDebugf("Could not run %s: %s\n", tag, err.c_str());
358 exit(1);
mtklein114c3cd2015-01-15 10:15:02 -0800359 }
360
mtkleine0effd62015-07-29 06:37:28 -0700361 SinkType type = kRaster_SinkType;
362 if (sink->enclave() == kGPU_Enclave) { type = kGPU_SinkType; }
363 if (stream.bytesWritten() > 0) { type = kVector_SinkType; }
364
365 TaggedSink& ts = gSinks.push_back();
mtklein748ca3b2015-01-15 10:56:12 -0800366 ts.reset(sink.detach());
367 ts.tag = tag;
mtkleine0effd62015-07-29 06:37:28 -0700368 ts.type = type;
mtklein748ca3b2015-01-15 10:56:12 -0800369}
370
371static bool gpu_supported() {
372#if SK_SUPPORT_GPU
373 return FLAGS_gpu;
374#else
375 return false;
376#endif
377}
378
379static Sink* create_sink(const char* tag) {
380#define SINK(t, sink, ...) if (0 == strcmp(t, tag)) { return new sink(__VA_ARGS__); }
381 if (gpu_supported()) {
mtklein82d28432015-01-15 12:46:02 -0800382 typedef GrContextFactory Gr;
mtklein748ca3b2015-01-15 10:56:12 -0800383 const GrGLStandard api = get_gpu_api();
mtklein82d28432015-01-15 12:46:02 -0800384 SINK("gpunull", GPUSink, Gr::kNull_GLContextType, api, 0, false, FLAGS_gpu_threading);
385 SINK("gpudebug", GPUSink, Gr::kDebug_GLContextType, api, 0, false, FLAGS_gpu_threading);
386 SINK("gpu", GPUSink, Gr::kNative_GLContextType, api, 0, false, FLAGS_gpu_threading);
387 SINK("gpudft", GPUSink, Gr::kNative_GLContextType, api, 0, true, FLAGS_gpu_threading);
388 SINK("msaa4", GPUSink, Gr::kNative_GLContextType, api, 4, false, FLAGS_gpu_threading);
389 SINK("msaa16", GPUSink, Gr::kNative_GLContextType, api, 16, false, FLAGS_gpu_threading);
390 SINK("nvprmsaa4", GPUSink, Gr::kNVPR_GLContextType, api, 4, false, FLAGS_gpu_threading);
391 SINK("nvprmsaa16", GPUSink, Gr::kNVPR_GLContextType, api, 16, false, FLAGS_gpu_threading);
mtklein748ca3b2015-01-15 10:56:12 -0800392 #if SK_ANGLE
mtklein82d28432015-01-15 12:46:02 -0800393 SINK("angle", GPUSink, Gr::kANGLE_GLContextType, api, 0, false, FLAGS_gpu_threading);
mtklein748ca3b2015-01-15 10:56:12 -0800394 #endif
395 #if SK_MESA
mtklein82d28432015-01-15 12:46:02 -0800396 SINK("mesa", GPUSink, Gr::kMESA_GLContextType, api, 0, false, FLAGS_gpu_threading);
mtklein748ca3b2015-01-15 10:56:12 -0800397 #endif
mtklein114c3cd2015-01-15 10:15:02 -0800398 }
mtklein748ca3b2015-01-15 10:56:12 -0800399
tomhudsoneebc39a2015-02-23 12:18:05 -0800400#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
401 SINK("hwui", HWUISink);
402#endif
403
mtklein748ca3b2015-01-15 10:56:12 -0800404 if (FLAGS_cpu) {
405 SINK("565", RasterSink, kRGB_565_SkColorType);
406 SINK("8888", RasterSink, kN32_SkColorType);
mtklein19f30602015-01-20 13:34:39 -0800407 SINK("pdf", PDFSink);
mtklein9c3f17d2015-01-28 11:35:18 -0800408 SINK("skp", SKPSink);
mtklein8a4527e2015-01-31 20:00:58 -0800409 SINK("svg", SVGSink);
410 SINK("null", NullSink);
halcanary47ef4d52015-03-03 09:13:09 -0800411 SINK("xps", XPSSink);
mtklein748ca3b2015-01-15 10:56:12 -0800412 }
413#undef SINK
414 return NULL;
mtklein114c3cd2015-01-15 10:15:02 -0800415}
416
mtklein748ca3b2015-01-15 10:56:12 -0800417static Sink* create_via(const char* tag, Sink* wrapped) {
418#define VIA(t, via, ...) if (0 == strcmp(t, tag)) { return new via(__VA_ARGS__); }
mtklein6fbf4b32015-05-06 11:35:40 -0700419 VIA("twice", ViaTwice, wrapped);
mtklein7edca212015-01-21 13:18:51 -0800420 VIA("pipe", ViaPipe, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800421 VIA("serialize", ViaSerialization, wrapped);
reed06a22f62015-05-05 08:11:33 -0700422 VIA("deferred", ViaDeferred, wrapped);
mtkleinb7e8d692015-04-07 08:30:32 -0700423 VIA("2ndpic", ViaSecondPicture, wrapped);
mtkleind31c13d2015-05-05 12:59:56 -0700424 VIA("sp", ViaSingletonPictures, wrapped);
mtklein7edca212015-01-21 13:18:51 -0800425 VIA("tiles", ViaTiles, 256, 256, NULL, wrapped);
426 VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800427
mtkleind603b222015-02-17 11:13:33 -0800428 if (FLAGS_matrix.count() == 4) {
mtklein748ca3b2015-01-15 10:56:12 -0800429 SkMatrix m;
mtkleind603b222015-02-17 11:13:33 -0800430 m.reset();
431 m.setScaleX((SkScalar)atof(FLAGS_matrix[0]));
432 m.setSkewX ((SkScalar)atof(FLAGS_matrix[1]));
433 m.setSkewY ((SkScalar)atof(FLAGS_matrix[2]));
434 m.setScaleY((SkScalar)atof(FLAGS_matrix[3]));
435 VIA("matrix", ViaMatrix, m, wrapped);
436 VIA("upright", ViaUpright, m, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800437 }
tomhudson64de1e12015-03-05 08:01:07 -0800438
439#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
440 VIA("androidsdk", ViaAndroidSDK, wrapped);
441#endif
442
mtklein748ca3b2015-01-15 10:56:12 -0800443#undef VIA
444 return NULL;
mtklein114c3cd2015-01-15 10:15:02 -0800445}
446
mtklein748ca3b2015-01-15 10:56:12 -0800447static void gather_sinks() {
448 for (int i = 0; i < FLAGS_config.count(); i++) {
449 const char* config = FLAGS_config[i];
450 SkTArray<SkString> parts;
451 SkStrSplit(config, "-", &parts);
452
453 Sink* sink = NULL;
454 for (int i = parts.count(); i-- > 0;) {
455 const char* part = parts[i].c_str();
456 Sink* next = (sink == NULL) ? create_sink(part) : create_via(part, sink);
457 if (next == NULL) {
458 SkDebugf("Skipping %s: Don't understand '%s'.\n", config, part);
459 delete sink;
460 sink = NULL;
461 break;
462 }
463 sink = next;
464 }
465 if (sink) {
466 push_sink(config, sink);
mtklein114c3cd2015-01-15 10:15:02 -0800467 }
468 }
469}
mtklein709d2c32015-01-15 08:30:25 -0800470
mtkleina2ef6422015-01-15 13:44:22 -0800471static bool match(const char* needle, const char* haystack) {
472 return 0 == strcmp("_", needle) || NULL != strstr(haystack, needle);
473}
474
djsollen54416de2015-04-03 07:24:48 -0700475static ImplicitString is_blacklisted(const char* sink, const char* src,
476 const char* srcOptions, const char* name) {
mtklein0d243ff2015-04-03 07:51:00 -0700477 for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) {
mtkleina2ef6422015-01-15 13:44:22 -0800478 if (match(FLAGS_blacklist[i+0], sink) &&
djsollen54416de2015-04-03 07:24:48 -0700479 match(FLAGS_blacklist[i+1], src) &&
480 match(FLAGS_blacklist[i+2], srcOptions) &&
481 match(FLAGS_blacklist[i+3], name)) {
482 return SkStringPrintf("%s %s %s %s",
483 FLAGS_blacklist[i+0], FLAGS_blacklist[i+1],
484 FLAGS_blacklist[i+2], FLAGS_blacklist[i+3]);
mtkleina2ef6422015-01-15 13:44:22 -0800485 }
486 }
487 return "";
488}
489
mtklein748ca3b2015-01-15 10:56:12 -0800490// The finest-grained unit of work we can run: draw a single Src into a single Sink,
491// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
492struct Task {
mtkleine0effd62015-07-29 06:37:28 -0700493 Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {}
494 const TaggedSrc& src;
495 const TaggedSink& sink;
mtklein748ca3b2015-01-15 10:56:12 -0800496
497 static void Run(Task* task) {
mtkleina2ef6422015-01-15 13:44:22 -0800498 SkString name = task->src->name();
mtkleine0effd62015-07-29 06:37:28 -0700499
500 // We'll skip drawing this Src/Sink pair if:
501 // - the Src vetoes the Sink;
502 // - this Src / Sink combination is on the blacklist;
503 // - it's a dry run.
504 SkString note(task->src->veto(task->sink.type) ? " (veto)" : "");
djsollen54416de2015-04-03 07:24:48 -0700505 SkString whyBlacklisted = is_blacklisted(task->sink.tag, task->src.tag,
506 task->src.options, name.c_str());
mtkleinb37cb412015-03-18 05:27:14 -0700507 if (!whyBlacklisted.isEmpty()) {
508 note.appendf(" (--blacklist %s)", whyBlacklisted.c_str());
509 }
mtkleine0effd62015-07-29 06:37:28 -0700510
mtkleinb9eb4ac2015-02-02 18:26:03 -0800511 SkString log;
mtklein748ca3b2015-01-15 10:56:12 -0800512 WallTimer timer;
513 timer.start();
mtkleine0effd62015-07-29 06:37:28 -0700514 if (!FLAGS_dryRun && note.isEmpty()) {
mtklein748ca3b2015-01-15 10:56:12 -0800515 SkBitmap bitmap;
516 SkDynamicMemoryWStream stream;
bsalomon821e10e2015-06-04 14:15:33 -0700517 if (FLAGS_pre_log) {
518 SkDebugf("\nRunning %s->%s", name.c_str(), task->sink.tag);
519 }
djsollen54416de2015-04-03 07:24:48 -0700520 start(task->sink.tag, task->src.tag, task->src.options, name.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800521 Error err = task->sink->draw(*task->src, &bitmap, &stream, &log);
mtklein748ca3b2015-01-15 10:56:12 -0800522 if (!err.isEmpty()) {
mtklein4089ef72015-03-05 08:40:28 -0800523 timer.end();
524 if (err.isFatal()) {
djsollen54416de2015-04-03 07:24:48 -0700525 fail(SkStringPrintf("%s %s %s %s: %s",
mtklein4089ef72015-03-05 08:40:28 -0800526 task->sink.tag,
527 task->src.tag,
djsollen54416de2015-04-03 07:24:48 -0700528 task->src.options,
mtklein4089ef72015-03-05 08:40:28 -0800529 name.c_str(),
530 err.c_str()));
mtkleinb37cb412015-03-18 05:27:14 -0700531 } else {
532 note.appendf(" (skipped: %s)", err.c_str());
mtklein4089ef72015-03-05 08:40:28 -0800533 }
djsollen54416de2015-04-03 07:24:48 -0700534 done(timer.fWall, task->sink.tag, task->src.tag, task->src.options,
535 name, note, log);
mtklein4089ef72015-03-05 08:40:28 -0800536 return;
mtklein748ca3b2015-01-15 10:56:12 -0800537 }
mtklein62bd1a62015-01-27 14:46:26 -0800538 SkAutoTDelete<SkStreamAsset> data(stream.detachAsStream());
539
540 SkString md5;
541 if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
542 SkMD5 hash;
543 if (data->getLength()) {
544 hash.writeStream(data, data->getLength());
545 data->rewind();
546 } else {
mtklein38408462015-07-08 07:25:27 -0700547 // If we're BGRA (Linux, Windows), swizzle over to RGBA (Mac, Android).
548 // This helps eliminate multiple 0-pixel-diff hashes on gold.skia.org.
549 // (Android's general slow speed breaks the tie arbitrarily in RGBA's favor.)
550 // We might consider promoting 565 to RGBA too.
551 if (bitmap.colorType() == kBGRA_8888_SkColorType) {
552 SkBitmap swizzle;
553 SkAssertResult(bitmap.copyTo(&swizzle, kRGBA_8888_SkColorType));
554 hash.write(swizzle.getPixels(), swizzle.getSize());
555 } else {
556 hash.write(bitmap.getPixels(), bitmap.getSize());
557 }
mtklein62bd1a62015-01-27 14:46:26 -0800558 }
559 SkMD5::Digest digest;
560 hash.finish(digest);
561 for (int i = 0; i < 16; i++) {
562 md5.appendf("%02x", digest.data[i]);
563 }
564 }
565
566 if (!FLAGS_readPath.isEmpty() &&
djsollen54416de2015-04-03 07:24:48 -0700567 !gGold.contains(Gold(task->sink.tag, task->src.tag,
568 task->src.options, name, md5))) {
569 fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
mtklein62bd1a62015-01-27 14:46:26 -0800570 md5.c_str(),
571 task->sink.tag,
572 task->src.tag,
djsollen54416de2015-04-03 07:24:48 -0700573 task->src.options,
mtklein62bd1a62015-01-27 14:46:26 -0800574 name.c_str(),
575 FLAGS_readPath[0]));
576 }
577
mtkleinb0531a72015-04-07 13:38:48 -0700578 if (!FLAGS_writePath.isEmpty()) {
mtklein748ca3b2015-01-15 10:56:12 -0800579 const char* ext = task->sink->fileExtension();
mtklein62bd1a62015-01-27 14:46:26 -0800580 if (data->getLength()) {
581 WriteToDisk(*task, md5, ext, data, data->getLength(), NULL);
halcanary022afb82015-01-30 11:00:12 -0800582 SkASSERT(bitmap.drawsNothing());
583 } else if (!bitmap.drawsNothing()) {
mtklein62bd1a62015-01-27 14:46:26 -0800584 WriteToDisk(*task, md5, ext, NULL, 0, &bitmap);
mtklein748ca3b2015-01-15 10:56:12 -0800585 }
586 }
587 }
588 timer.end();
djsollen54416de2015-04-03 07:24:48 -0700589 done(timer.fWall, task->sink.tag, task->src.tag, task->src.options, name, note, log);
mtklein748ca3b2015-01-15 10:56:12 -0800590 }
591
592 static void WriteToDisk(const Task& task,
mtklein62bd1a62015-01-27 14:46:26 -0800593 SkString md5,
594 const char* ext,
mtklein748ca3b2015-01-15 10:56:12 -0800595 SkStream* data, size_t len,
mtklein62bd1a62015-01-27 14:46:26 -0800596 const SkBitmap* bitmap) {
mtklein748ca3b2015-01-15 10:56:12 -0800597 JsonWriter::BitmapResult result;
djsollen54416de2015-04-03 07:24:48 -0700598 result.name = task.src->name();
599 result.config = task.sink.tag;
600 result.sourceType = task.src.tag;
601 result.sourceOptions = task.src.options;
602 result.ext = ext;
603 result.md5 = md5;
mtklein748ca3b2015-01-15 10:56:12 -0800604 JsonWriter::AddBitmapResult(result);
605
mtkleinb0531a72015-04-07 13:38:48 -0700606 // If an MD5 is uninteresting, we want it noted in the JSON file,
607 // but don't want to dump it out as a .png (or whatever ext is).
608 if (gUninterestingHashes.contains(md5)) {
609 return;
610 }
611
mtklein748ca3b2015-01-15 10:56:12 -0800612 const char* dir = FLAGS_writePath[0];
613 if (0 == strcmp(dir, "@")) { // Needed for iOS.
614 dir = FLAGS_resourcePath[0];
615 }
616 sk_mkdir(dir);
617
618 SkString path;
619 if (FLAGS_nameByHash) {
620 path = SkOSPath::Join(dir, result.md5.c_str());
621 path.append(".");
622 path.append(ext);
623 if (sk_exists(path.c_str())) {
624 return; // Content-addressed. If it exists already, we're done.
625 }
626 } else {
627 path = SkOSPath::Join(dir, task.sink.tag);
628 sk_mkdir(path.c_str());
629 path = SkOSPath::Join(path.c_str(), task.src.tag);
630 sk_mkdir(path.c_str());
djsollen54416de2015-04-03 07:24:48 -0700631 if (strcmp(task.src.options, "") != 0) {
632 path = SkOSPath::Join(path.c_str(), task.src.options);
633 sk_mkdir(path.c_str());
634 }
mtklein748ca3b2015-01-15 10:56:12 -0800635 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
636 path.append(".");
637 path.append(ext);
638 }
639
640 SkFILEWStream file(path.c_str());
641 if (!file.isValid()) {
642 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
643 return;
644 }
645
mtklein748ca3b2015-01-15 10:56:12 -0800646 if (bitmap) {
647 // We can't encode A8 bitmaps as PNGs. Convert them to 8888 first.
648 SkBitmap converted;
649 if (bitmap->info().colorType() == kAlpha_8_SkColorType) {
650 if (!bitmap->copyTo(&converted, kN32_SkColorType)) {
651 fail("Can't convert A8 to 8888.\n");
652 return;
653 }
654 bitmap = &converted;
655 }
656 if (!SkImageEncoder::EncodeStream(&file, *bitmap, SkImageEncoder::kPNG_Type, 100)) {
657 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
658 return;
659 }
660 } else {
661 if (!file.writeStream(data, len)) {
662 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
663 return;
664 }
665 }
666 }
667};
668
669// Run all tasks in the same enclave serially on the same thread.
670// They can't possibly run concurrently with each other.
671static void run_enclave(SkTArray<Task>* tasks) {
672 for (int i = 0; i < tasks->count(); i++) {
673 Task::Run(tasks->begin() + i);
674 }
675}
676
677/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
678
679// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
680
mtklein55e88b22015-01-21 15:50:13 -0800681static SkTDArray<skiatest::Test> gThreadedTests, gGPUTests;
mtklein748ca3b2015-01-15 10:56:12 -0800682
683static void gather_tests() {
mtklein6c5fed22015-01-20 13:47:23 -0800684 if (!FLAGS_src.contains("tests")) {
mtklein748ca3b2015-01-15 10:56:12 -0800685 return;
686 }
mtklein6393c062015-04-27 08:45:01 -0700687 for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; r = r->next()) {
688 if (!in_shard()) {
689 continue;
690 }
halcanary87f3ba42015-01-20 09:30:20 -0800691 // Despite its name, factory() is returning a reference to
692 // link-time static const POD data.
693 const skiatest::Test& test = r->factory();
694 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -0800695 continue;
696 }
halcanary87f3ba42015-01-20 09:30:20 -0800697 if (test.needsGpu && gpu_supported()) {
mtklein55e88b22015-01-21 15:50:13 -0800698 (FLAGS_gpu_threading ? gThreadedTests : gGPUTests).push(test);
halcanary87f3ba42015-01-20 09:30:20 -0800699 } else if (!test.needsGpu && FLAGS_cpu) {
mtklein55e88b22015-01-21 15:50:13 -0800700 gThreadedTests.push(test);
mtklein82d28432015-01-15 12:46:02 -0800701 }
mtklein748ca3b2015-01-15 10:56:12 -0800702 }
703}
704
halcanary87f3ba42015-01-20 09:30:20 -0800705static void run_test(skiatest::Test* test) {
706 struct : public skiatest::Reporter {
mtklein36352bf2015-03-25 18:17:31 -0700707 void reportFailed(const skiatest::Failure& failure) override {
halcanary87f3ba42015-01-20 09:30:20 -0800708 fail(failure.toString());
709 JsonWriter::AddTestFailure(failure);
710 }
mtklein36352bf2015-03-25 18:17:31 -0700711 bool allowExtendedTest() const override {
halcanary87f3ba42015-01-20 09:30:20 -0800712 return FLAGS_pathOpsExtended;
713 }
mtklein36352bf2015-03-25 18:17:31 -0700714 bool verbose() const override { return FLAGS_veryVerbose; }
halcanary87f3ba42015-01-20 09:30:20 -0800715 } reporter;
djsollen824996a2015-06-12 12:06:22 -0700716
717 SkString note;
718 SkString whyBlacklisted = is_blacklisted("_", "tests", "_", test->name);
719 if (!whyBlacklisted.isEmpty()) {
720 note.appendf(" (--blacklist %s)", whyBlacklisted.c_str());
721 }
722
mtklein748ca3b2015-01-15 10:56:12 -0800723 WallTimer timer;
724 timer.start();
djsollen824996a2015-06-12 12:06:22 -0700725 if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) {
djsollen54416de2015-04-03 07:24:48 -0700726 start("unit", "test", "", test->name);
mtklein55e88b22015-01-21 15:50:13 -0800727 GrContextFactory factory;
bsalomon821e10e2015-06-04 14:15:33 -0700728 if (FLAGS_pre_log) {
729 SkDebugf("\nRunning test %s", test->name);
730 }
mtklein55e88b22015-01-21 15:50:13 -0800731 test->proc(&reporter, &factory);
mtklein748ca3b2015-01-15 10:56:12 -0800732 }
733 timer.end();
djsollen824996a2015-06-12 12:06:22 -0700734 done(timer.fWall, "unit", "test", "", test->name, note, "");
mtklein748ca3b2015-01-15 10:56:12 -0800735}
736
737/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
738
mtklein55e88b22015-01-21 15:50:13 -0800739// If we're isolating all GPU-bound work to one thread (the default), this function runs all that.
740static void run_enclave_and_gpu_tests(SkTArray<Task>* tasks) {
741 run_enclave(tasks);
742 for (int i = 0; i < gGPUTests.count(); i++) {
743 run_test(&gGPUTests[i]);
744 }
745}
746
mtkleinde6fc2b2015-03-12 06:28:54 -0700747// Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've hung.
748// This prints something every once in a while so that it knows we're still working.
mtklein2e1c47e2015-03-12 07:16:56 -0700749static void start_keepalive() {
750 struct Loop {
751 static void forever(void*) {
752 for (;;) {
753 static const int kSec = 300;
754 #if defined(SK_BUILD_FOR_WIN)
755 Sleep(kSec * 1000);
756 #else
757 sleep(kSec);
758 #endif
mtkleinb37cb412015-03-18 05:27:14 -0700759 SkString running;
760 {
761 SkAutoMutexAcquire lock(gRunningMutex);
762 for (int i = 0; i < gRunning.count(); i++) {
763 running.appendf("\n\t%s", gRunning[i].c_str());
764 }
765 }
766 SkDebugf("\nCurrently running:%s\n", running.c_str());
mtklein2e1c47e2015-03-12 07:16:56 -0700767 }
768 }
769 };
770 static SkThread* intentionallyLeaked = new SkThread(Loop::forever);
771 intentionallyLeaked->start();
mtkleinde6fc2b2015-03-12 06:28:54 -0700772}
773
caryclark83ca6282015-06-10 09:31:09 -0700774#define PORTABLE_FONT_PREFIX "Toy Liberation "
775
776static SkTypeface* create_from_name(const char familyName[], SkTypeface::Style style) {
777 if (familyName && strlen(familyName) > sizeof(PORTABLE_FONT_PREFIX)
778 && !strncmp(familyName, PORTABLE_FONT_PREFIX, sizeof(PORTABLE_FONT_PREFIX) - 1)) {
caryclark1818acb2015-07-24 12:09:25 -0700779 return sk_tool_utils::create_portable_typeface(familyName, style);
caryclark83ca6282015-06-10 09:31:09 -0700780 }
781 return NULL;
782}
783
784#undef PORTABLE_FONT_PREFIX
785
786extern SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style );
787
jcgregorio3b27ade2014-11-13 08:06:40 -0800788int dm_main();
caryclark17f0b6d2014-07-22 10:15:34 -0700789int dm_main() {
jcgregorio3b27ade2014-11-13 08:06:40 -0800790 SetupCrashHandler();
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +0000791 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -0700792 SkTaskGroup::Enabler enabled(FLAGS_threads);
caryclark83ca6282015-06-10 09:31:09 -0700793 gCreateTypefaceDelegate = &create_from_name;
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +0000794
mtklein2e1c47e2015-03-12 07:16:56 -0700795 start_keepalive();
mtkleinde6fc2b2015-03-12 06:28:54 -0700796
mtklein62bd1a62015-01-27 14:46:26 -0800797 gather_gold();
borenet09ed4802015-04-03 14:15:33 -0700798 gather_uninteresting_hashes();
mtklein62bd1a62015-01-27 14:46:26 -0800799
mtklein748ca3b2015-01-15 10:56:12 -0800800 gather_srcs();
801 gather_sinks();
802 gather_tests();
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +0000803
mtklein55e88b22015-01-21 15:50:13 -0800804 gPending = gSrcs.count() * gSinks.count() + gThreadedTests.count() + gGPUTests.count();
mtklein748ca3b2015-01-15 10:56:12 -0800805 SkDebugf("%d srcs * %d sinks + %d tests == %d tasks\n",
mtklein55e88b22015-01-21 15:50:13 -0800806 gSrcs.count(), gSinks.count(), gThreadedTests.count() + gGPUTests.count(), gPending);
mtklein748ca3b2015-01-15 10:56:12 -0800807
808 // We try to exploit as much parallelism as is safe. Most Src/Sink pairs run on any thread,
809 // but Sinks that identify as part of a particular enclave run serially on a single thread.
mtklein82d28432015-01-15 12:46:02 -0800810 // CPU tests run on any thread. GPU tests depend on --gpu_threading.
mtklein748ca3b2015-01-15 10:56:12 -0800811 SkTArray<Task> enclaves[kNumEnclaves];
812 for (int j = 0; j < gSinks.count(); j++) {
813 SkTArray<Task>& tasks = enclaves[gSinks[j]->enclave()];
814 for (int i = 0; i < gSrcs.count(); i++) {
815 tasks.push_back(Task(gSrcs[i], gSinks[j]));
816 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +0000817 }
818
mtklein748ca3b2015-01-15 10:56:12 -0800819 SkTaskGroup tg;
mtklein55e88b22015-01-21 15:50:13 -0800820 tg.batch(run_test, gThreadedTests.begin(), gThreadedTests.count());
821 for (int i = 0; i < kNumEnclaves; i++) {
822 switch(i) {
823 case kAnyThread_Enclave:
824 tg.batch(Task::Run, enclaves[i].begin(), enclaves[i].count());
825 break;
826 case kGPU_Enclave:
827 tg.add(run_enclave_and_gpu_tests, &enclaves[i]);
828 break;
829 default:
830 tg.add(run_enclave, &enclaves[i]);
831 break;
mtklein82d28432015-01-15 12:46:02 -0800832 }
mtklein55e88b22015-01-21 15:50:13 -0800833 }
mtklein748ca3b2015-01-15 10:56:12 -0800834 tg.wait();
mtklein748ca3b2015-01-15 10:56:12 -0800835 // At this point we're back in single-threaded land.
caryclarkf53ce802015-06-15 06:48:30 -0700836 sk_tool_utils::release_portable_typefaces();
mtklein@google.comd36522d2013-10-16 13:02:15 +0000837
mtklein2f64eec2015-01-15 14:20:41 -0800838 SkDebugf("\n");
mtklein748ca3b2015-01-15 10:56:12 -0800839 if (gFailures.count() > 0) {
840 SkDebugf("Failures:\n");
841 for (int i = 0; i < gFailures.count(); i++) {
mtklein9dc09102015-01-15 15:47:33 -0800842 SkDebugf("\t%s\n", gFailures[i].c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800843 }
844 SkDebugf("%d failures\n", gFailures.count());
845 return 1;
mtklein114c3cd2015-01-15 10:15:02 -0800846 }
mtklein748ca3b2015-01-15 10:56:12 -0800847 if (gPending > 0) {
848 SkDebugf("Hrm, we didn't seem to run everything we intended to! Please file a bug.\n");
849 return 1;
mtklein114c3cd2015-01-15 10:15:02 -0800850 }
mtklein748ca3b2015-01-15 10:56:12 -0800851 return 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +0000852}
jcgregorio3b27ade2014-11-13 08:06:40 -0800853
borenet48087572015-04-02 12:16:36 -0700854#if !defined(SK_BUILD_FOR_IOS)
jcgregorio3b27ade2014-11-13 08:06:40 -0800855int main(int argc, char** argv) {
856 SkCommandLineFlags::Parse(argc, argv);
857 return dm_main();
858}
859#endif