blob: 5c27c450ba52c9a3bda1537bc7ece6d747409e66 [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 "ProcStats.h"
halcanary7d571242016-02-24 17:59:16 -080013#include "Resources.h"
mtklein748ca3b2015-01-15 10:56:12 -080014#include "SkBBHFactory.h"
mtklein62bd1a62015-01-27 14:46:26 -080015#include "SkChecksum.h"
scroggocc2feb12015-08-14 08:32:46 -070016#include "SkCodec.h"
caryclark17f0b6d2014-07-22 10:15:34 -070017#include "SkCommonFlags.h"
kkinnunen3e980c32015-12-23 01:33:00 -080018#include "SkCommonFlagsConfig.h"
caryclark83ca6282015-06-10 09:31:09 -070019#include "SkFontMgr.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000020#include "SkForceLinking.h"
21#include "SkGraphics.h"
mtklein748ca3b2015-01-15 10:56:12 -080022#include "SkMD5.h"
mtklein1b249332015-07-07 12:21:21 -070023#include "SkMutex.h"
mtklein1d0f1642014-09-08 08:05:18 -070024#include "SkOSFile.h"
mtklein246ba3a2016-02-23 10:39:36 -080025#include "SkSpinlock.h"
mtkleina82f5622015-02-20 12:30:19 -080026#include "SkTHash.h"
mtklein406654b2014-09-03 15:34:37 -070027#include "SkTaskGroup.h"
mtkleinde6fc2b2015-03-12 06:28:54 -070028#include "SkThreadUtils.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000029#include "Test.h"
mtklein748ca3b2015-01-15 10:56:12 -080030#include "Timer.h"
caryclark83ca6282015-06-10 09:31:09 -070031#include "sk_tool_utils.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000032
halcanary7a14b312015-10-01 07:28:13 -070033#ifdef SK_PDF_IMAGE_STATS
34extern void SkPDFImageDumpStats();
35#endif
36
mtkleina5114d72015-08-24 13:27:01 -070037#include "png.h"
38
bungeman60e0fee2015-08-26 05:15:46 -070039#include <stdlib.h>
40
scroggo27a58342015-10-28 08:56:41 -070041#ifndef SK_BUILD_FOR_WIN32
42 #include <unistd.h>
43#endif
44
djsollen54416de2015-04-03 07:24:48 -070045DEFINE_string(src, "tests gm skp image", "Source types to test.");
mtklein748ca3b2015-01-15 10:56:12 -080046DEFINE_bool(nameByHash, false,
47 "If true, write to FLAGS_writePath[0]/<hash>.png instead of "
djsollen54416de2015-04-03 07:24:48 -070048 "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.png");
mtklein748ca3b2015-01-15 10:56:12 -080049DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests.");
mtkleind603b222015-02-17 11:13:33 -080050DEFINE_string(matrix, "1 0 0 1",
51 "2x2 scale+skew matrix to apply or upright when using "
52 "'matrix' or 'upright' in config.");
mtklein82d28432015-01-15 12:46:02 -080053DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?");
mtklein@google.comd36522d2013-10-16 13:02:15 +000054
mtkleina2ef6422015-01-15 13:44:22 -080055DEFINE_string(blacklist, "",
djsollen54416de2015-04-03 07:24:48 -070056 "Space-separated config/src/srcOptions/name quadruples to blacklist. '_' matches anything. E.g. \n"
57 "'--blacklist gpu skp _ _' will blacklist all SKPs drawn into the gpu config.\n"
58 "'--blacklist gpu skp _ _ 8888 gm _ aarects' will also blacklist the aarects GM on 8888.");
mtkleina2ef6422015-01-15 13:44:22 -080059
mtklein62bd1a62015-01-27 14:46:26 -080060DEFINE_string2(readPath, r, "", "If set check for equality with golden results in this directory.");
61
borenet09ed4802015-04-03 14:15:33 -070062DEFINE_string(uninterestingHashesFile, "",
63 "File containing a list of uninteresting hashes. If a result hashes to something in "
64 "this list, no image is written for that result.");
65
mtklein6393c062015-04-27 08:45:01 -070066DEFINE_int32(shards, 1, "We're splitting source data into this many shards.");
67DEFINE_int32(shard, 0, "Which shard do I run?");
68
mtklein@google.comd36522d2013-10-16 13:02:15 +000069__SK_FORCE_IMAGE_DECODER_LINKING;
mtklein748ca3b2015-01-15 10:56:12 -080070using namespace DM;
mtklein@google.comd36522d2013-10-16 13:02:15 +000071
mtklein748ca3b2015-01-15 10:56:12 -080072/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
73
mtkleinf27f08b2015-11-03 06:54:24 -080074static double now_ms() { return SkTime::GetNSecs() * 1e-6; }
75
mtklein748ca3b2015-01-15 10:56:12 -080076SK_DECLARE_STATIC_MUTEX(gFailuresMutex);
77static SkTArray<SkString> gFailures;
78
79static void fail(ImplicitString err) {
80 SkAutoMutexAcquire lock(gFailuresMutex);
81 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str());
82 gFailures.push_back(err);
halcanary9e398f72015-01-10 11:18:04 -080083}
84
mtkleinb37cb412015-03-18 05:27:14 -070085
mtklein246ba3a2016-02-23 10:39:36 -080086// We use a spinlock to make locking this in a signal handler _somewhat_ safe.
mtkleinafae30a2016-02-24 12:28:32 -080087SK_DECLARE_STATIC_SPINLOCK(gMutex);
88static int32_t gPending;
mtkleinbc4e0032015-12-09 08:37:35 -080089static SkTArray<SkString> gRunning;
90static SkTHashMap<SkString, int> gNoteTally;
mtklein748ca3b2015-01-15 10:56:12 -080091
mtkleinb9eb4ac2015-02-02 18:26:03 -080092static void done(double ms,
djsollen54416de2015-04-03 07:24:48 -070093 ImplicitString config, ImplicitString src, ImplicitString srcOptions,
94 ImplicitString name, ImplicitString note, ImplicitString log) {
95 SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(),
96 srcOptions.c_str(), name.c_str());
mtkleinafae30a2016-02-24 12:28:32 -080097 int pending;
mtkleinb37cb412015-03-18 05:27:14 -070098 {
mtkleinafae30a2016-02-24 12:28:32 -080099 SkAutoTAcquire<SkPODSpinlock> lock(gMutex);
mtkleinb37cb412015-03-18 05:27:14 -0700100 for (int i = 0; i < gRunning.count(); i++) {
101 if (gRunning[i] == id) {
102 gRunning.removeShuffle(i);
103 break;
104 }
105 }
mtkleinbc4e0032015-12-09 08:37:35 -0800106 if (!note.isEmpty()) {
107 if (int* tally = gNoteTally.find(note)) {
108 *tally += 1;
109 } else {
110 gNoteTally.set(note, 1);
111 }
112 }
mtkleinafae30a2016-02-24 12:28:32 -0800113 pending = --gPending;
reed50bc0512015-05-19 14:13:31 -0700114 }
mtkleina17241b2015-01-23 05:48:00 -0800115 // We write our dm.json file every once in a while in case we crash.
116 // Notice this also handles the final dm.json when pending == 0.
117 if (pending % 500 == 0) {
118 JsonWriter::DumpJson();
119 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000120}
121
djsollen54416de2015-04-03 07:24:48 -0700122static void start(ImplicitString config, ImplicitString src,
123 ImplicitString srcOptions, ImplicitString name) {
124 SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(),
125 srcOptions.c_str(), name.c_str());
mtkleinafae30a2016-02-24 12:28:32 -0800126 SkAutoTAcquire<SkPODSpinlock> lock(gMutex);
mtkleinb37cb412015-03-18 05:27:14 -0700127 gRunning.push_back(id);
128}
129
mtkleinafae30a2016-02-24 12:28:32 -0800130static void print_status() {
131 static SkMSec start_ms = SkTime::GetMSecs();
132
133 int curr = sk_tools::getCurrResidentSetSizeMB(),
134 peak = sk_tools::getMaxResidentSetSizeMB();
135 SkString elapsed = HumanizeMs(SkTime::GetMSecs() - start_ms);
136
137 SkAutoTAcquire<SkPODSpinlock> lock(gMutex);
138 SkDebugf("\n%s elapsed, %d active, %d queued, %dMB RAM, %dMB peak\n",
139 elapsed.c_str(), gRunning.count(), gPending - gRunning.count(), curr, peak);
140 for (auto& task : gRunning) {
141 SkDebugf("\t%s\n", task.c_str());
142 }
143}
144
mtklein246ba3a2016-02-23 10:39:36 -0800145#if defined(SK_BUILD_FOR_WIN32)
146 static void setup_crash_handler() {
147 // TODO: custom crash handler like below to print out what was running
148 SetupCrashHandler();
149 }
150
151#else
152 #include <signal.h>
153 static void setup_crash_handler() {
154 const int kSignals[] = { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV };
155 for (int sig : kSignals) {
156 signal(sig, [](int sig) {
mtkleinafae30a2016-02-24 12:28:32 -0800157 SkDebugf("\nCaught signal %d [%s].\n", sig, strsignal(sig));
158 print_status();
mtklein246ba3a2016-02-23 10:39:36 -0800159 });
160 }
161 }
162#endif
163
mtklein748ca3b2015-01-15 10:56:12 -0800164/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
mtklein114c3cd2015-01-15 10:15:02 -0800165
mtklein62bd1a62015-01-27 14:46:26 -0800166struct Gold : public SkString {
mtkleina82f5622015-02-20 12:30:19 -0800167 Gold() : SkString("") {}
djsollen54416de2015-04-03 07:24:48 -0700168 Gold(ImplicitString sink, ImplicitString src, ImplicitString srcOptions,
169 ImplicitString name, ImplicitString md5)
mtklein62bd1a62015-01-27 14:46:26 -0800170 : SkString("") {
171 this->append(sink);
172 this->append(src);
djsollen54416de2015-04-03 07:24:48 -0700173 this->append(srcOptions);
mtklein62bd1a62015-01-27 14:46:26 -0800174 this->append(name);
175 this->append(md5);
mtklein62bd1a62015-01-27 14:46:26 -0800176 }
mtkleinc8d1dd42015-10-15 12:23:01 -0700177 struct Hash {
178 uint32_t operator()(const Gold& g) const {
179 return SkGoodHash()((const SkString&)g);
180 }
181 };
mtklein62bd1a62015-01-27 14:46:26 -0800182};
mtkleina82f5622015-02-20 12:30:19 -0800183static SkTHashSet<Gold, Gold::Hash> gGold;
mtklein62bd1a62015-01-27 14:46:26 -0800184
185static void add_gold(JsonWriter::BitmapResult r) {
djsollen54416de2015-04-03 07:24:48 -0700186 gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5));
mtklein62bd1a62015-01-27 14:46:26 -0800187}
188
189static void gather_gold() {
190 if (!FLAGS_readPath.isEmpty()) {
191 SkString path(FLAGS_readPath[0]);
192 path.append("/dm.json");
193 if (!JsonWriter::ReadJson(path.c_str(), add_gold)) {
194 fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str()));
195 }
196 }
197}
198
199/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
200
borenet09ed4802015-04-03 14:15:33 -0700201static SkTHashSet<SkString> gUninterestingHashes;
202
203static void gather_uninteresting_hashes() {
204 if (!FLAGS_uninterestingHashesFile.isEmpty()) {
205 SkAutoTUnref<SkData> data(SkData::NewFromFileName(FLAGS_uninterestingHashesFile[0]));
mtkleincc334b32015-09-22 11:43:53 -0700206 if (!data) {
207 SkDebugf("WARNING: unable to read uninteresting hashes from %s\n",
208 FLAGS_uninterestingHashesFile[0]);
209 return;
210 }
borenet09ed4802015-04-03 14:15:33 -0700211 SkTArray<SkString> hashes;
212 SkStrSplit((const char*)data->data(), "\n", &hashes);
213 for (const SkString& hash : hashes) {
214 gUninterestingHashes.add(hash);
215 }
mtklein136baaa2016-02-03 11:21:45 -0800216 SkDebugf("FYI: loaded %d distinct uninteresting hashes from %d lines\n",
217 gUninterestingHashes.count(), hashes.count());
borenet09ed4802015-04-03 14:15:33 -0700218 }
219}
220
221/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
222
mtkleine0effd62015-07-29 06:37:28 -0700223struct TaggedSrc : public SkAutoTDelete<Src> {
msarett9e707a02015-09-01 14:57:57 -0700224 ImplicitString tag;
225 ImplicitString options;
mtkleine0effd62015-07-29 06:37:28 -0700226};
227
228struct TaggedSink : public SkAutoTDelete<Sink> {
kkinnunen3e980c32015-12-23 01:33:00 -0800229 SkString tag;
djsollen54416de2015-04-03 07:24:48 -0700230};
mtklein748ca3b2015-01-15 10:56:12 -0800231
232static const bool kMemcpyOK = true;
233
mtkleine0effd62015-07-29 06:37:28 -0700234static SkTArray<TaggedSrc, kMemcpyOK> gSrcs;
235static SkTArray<TaggedSink, kMemcpyOK> gSinks;
mtklein748ca3b2015-01-15 10:56:12 -0800236
mtklein6393c062015-04-27 08:45:01 -0700237static bool in_shard() {
238 static int N = 0;
239 return N++ % FLAGS_shards == FLAGS_shard;
240}
241
msarett9e707a02015-09-01 14:57:57 -0700242static void push_src(ImplicitString tag, ImplicitString options, Src* s) {
mtklein748ca3b2015-01-15 10:56:12 -0800243 SkAutoTDelete<Src> src(s);
mtklein6393c062015-04-27 08:45:01 -0700244 if (in_shard() &&
msarett9e707a02015-09-01 14:57:57 -0700245 FLAGS_src.contains(tag.c_str()) &&
mtklein748ca3b2015-01-15 10:56:12 -0800246 !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) {
mtkleine0effd62015-07-29 06:37:28 -0700247 TaggedSrc& s = gSrcs.push_back();
mtklein748ca3b2015-01-15 10:56:12 -0800248 s.reset(src.detach());
249 s.tag = tag;
djsollen54416de2015-04-03 07:24:48 -0700250 s.options = options;
mtklein114c3cd2015-01-15 10:15:02 -0800251 }
mtklein748ca3b2015-01-15 10:56:12 -0800252}
mtklein114c3cd2015-01-15 10:15:02 -0800253
msarett9e707a02015-09-01 14:57:57 -0700254static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorType dstColorType,
scroggoc5560be2016-02-03 09:42:42 -0800255 SkAlphaType dstAlphaType, float scale) {
msarett9e707a02015-09-01 14:57:57 -0700256 SkString folder;
257 switch (mode) {
258 case CodecSrc::kCodec_Mode:
259 folder.append("codec");
260 break;
msarettbb25b532016-01-13 09:31:39 -0800261 case CodecSrc::kCodecZeroInit_Mode:
262 folder.append("codec_zero_init");
263 break;
msarett9e707a02015-09-01 14:57:57 -0700264 case CodecSrc::kScanline_Mode:
265 folder.append("scanline");
266 break;
msarett9e707a02015-09-01 14:57:57 -0700267 case CodecSrc::kStripe_Mode:
268 folder.append("stripe");
269 break;
msarett91c22b22016-02-22 12:27:46 -0800270 case CodecSrc::kCroppedScanline_Mode:
271 folder.append("crop");
272 break;
msarett9e707a02015-09-01 14:57:57 -0700273 case CodecSrc::kSubset_Mode:
msarett36c37962015-09-02 13:20:52 -0700274 folder.append("codec_subset");
msarett9e707a02015-09-01 14:57:57 -0700275 break;
msarettb714fb02016-01-22 14:46:42 -0800276 case CodecSrc::kGen_Mode:
277 folder.append("gen");
278 break;
msarett9e707a02015-09-01 14:57:57 -0700279 }
280
281 switch (dstColorType) {
282 case CodecSrc::kGrayscale_Always_DstColorType:
283 folder.append("_kGray8");
284 break;
285 case CodecSrc::kIndex8_Always_DstColorType:
286 folder.append("_kIndex8");
287 break;
288 default:
289 break;
290 }
291
scroggoc5560be2016-02-03 09:42:42 -0800292 switch (dstAlphaType) {
293 case kOpaque_SkAlphaType:
294 folder.append("_opaque");
295 break;
296 case kPremul_SkAlphaType:
297 folder.append("_premul");
298 break;
299 case kUnpremul_SkAlphaType:
300 folder.append("_unpremul");
301 break;
302 default:
303 break;
304 }
305
msarett9e707a02015-09-01 14:57:57 -0700306 if (1.0f != scale) {
307 folder.appendf("_%.3f", scale);
308 }
309
scroggoc5560be2016-02-03 09:42:42 -0800310 CodecSrc* src = new CodecSrc(path, mode, dstColorType, dstAlphaType, scale);
msarett9e707a02015-09-01 14:57:57 -0700311 push_src("image", folder, src);
312}
313
msarett3d9d7a72015-10-21 10:27:10 -0700314static void push_android_codec_src(Path path, AndroidCodecSrc::Mode mode,
scroggoc5560be2016-02-03 09:42:42 -0800315 CodecSrc::DstColorType dstColorType, SkAlphaType dstAlphaType, int sampleSize) {
msarett3d9d7a72015-10-21 10:27:10 -0700316 SkString folder;
317 switch (mode) {
318 case AndroidCodecSrc::kFullImage_Mode:
319 folder.append("scaled_codec");
320 break;
321 case AndroidCodecSrc::kDivisor_Mode:
322 folder.append("scaled_codec_divisor");
323 break;
324 }
325
326 switch (dstColorType) {
327 case CodecSrc::kGrayscale_Always_DstColorType:
328 folder.append("_kGray8");
329 break;
330 case CodecSrc::kIndex8_Always_DstColorType:
331 folder.append("_kIndex8");
332 break;
333 default:
334 break;
335 }
336
scroggoc5560be2016-02-03 09:42:42 -0800337 switch (dstAlphaType) {
338 case kOpaque_SkAlphaType:
339 folder.append("_opaque");
340 break;
341 case kPremul_SkAlphaType:
342 folder.append("_premul");
343 break;
msarett9e9444c2016-02-03 12:39:10 -0800344 case kUnpremul_SkAlphaType:
345 folder.append("_unpremul");
346 break;
scroggoc5560be2016-02-03 09:42:42 -0800347 default:
348 break;
349 }
350
msarett3d9d7a72015-10-21 10:27:10 -0700351 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -0800352 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700353 }
354
scroggoc5560be2016-02-03 09:42:42 -0800355 AndroidCodecSrc* src = new AndroidCodecSrc(path, mode, dstColorType, dstAlphaType, sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700356 push_src("image", folder, src);
357}
358
msarett438b2ad2015-04-09 12:43:10 -0700359static void push_codec_srcs(Path path) {
360 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
361 if (!encoded) {
362 SkDebugf("Couldn't read %s.", path.c_str());
363 return;
364 }
365 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
halcanary96fcdcc2015-08-27 07:41:13 -0700366 if (nullptr == codec.get()) {
msarett438b2ad2015-04-09 12:43:10 -0700367 SkDebugf("Couldn't create codec for %s.", path.c_str());
368 return;
369 }
370
msarett36c37962015-09-02 13:20:52 -0700371 // Native Scales
msarett0a242972015-06-11 14:27:27 -0700372 // TODO (msarett): Implement scaling tests for SkImageDecoder in order to compare with these
373 // tests. SkImageDecoder supports downscales by integer factors.
emmaleer8f4ba762015-08-14 07:44:46 -0700374 // SkJpegCodec natively supports scaling to: 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875
msarett36c37962015-09-02 13:20:52 -0700375 const float nativeScales[] = { 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.750f, 0.875f, 1.0f };
msarett438b2ad2015-04-09 12:43:10 -0700376
msarett91c22b22016-02-22 12:27:46 -0800377 SkTArray<CodecSrc::Mode> nativeModes;
378 nativeModes.push_back(CodecSrc::kCodec_Mode);
379 nativeModes.push_back(CodecSrc::kCodecZeroInit_Mode);
380 nativeModes.push_back(CodecSrc::kGen_Mode);
381 switch (codec->getEncodedFormat()) {
382 case SkEncodedFormat::kJPEG_SkEncodedFormat:
383 nativeModes.push_back(CodecSrc::kScanline_Mode);
384 nativeModes.push_back(CodecSrc::kStripe_Mode);
385 nativeModes.push_back(CodecSrc::kCroppedScanline_Mode);
386 break;
387 case SkEncodedFormat::kWEBP_SkEncodedFormat:
388 nativeModes.push_back(CodecSrc::kSubset_Mode);
389 break;
msarettb65e6042016-02-23 05:37:25 -0800390 case SkEncodedFormat::kRAW_SkEncodedFormat:
391 break;
msarett91c22b22016-02-22 12:27:46 -0800392 default:
393 nativeModes.push_back(CodecSrc::kScanline_Mode);
394 nativeModes.push_back(CodecSrc::kStripe_Mode);
395 break;
396 }
msarett9e707a02015-09-01 14:57:57 -0700397
msarett91c22b22016-02-22 12:27:46 -0800398 SkTArray<CodecSrc::DstColorType> colorTypes;
399 colorTypes.push_back(CodecSrc::kGetFromCanvas_DstColorType);
msarett36c37962015-09-02 13:20:52 -0700400 switch (codec->getInfo().colorType()) {
401 case kGray_8_SkColorType:
msarett91c22b22016-02-22 12:27:46 -0800402 colorTypes.push_back(CodecSrc::kGrayscale_Always_DstColorType);
msarett55f7bdd2016-02-16 13:24:54 -0800403 if (kWBMP_SkEncodedFormat == codec->getEncodedFormat()) {
msarett91c22b22016-02-22 12:27:46 -0800404 colorTypes.push_back(CodecSrc::kIndex8_Always_DstColorType);
msarett55f7bdd2016-02-16 13:24:54 -0800405 }
msarett36c37962015-09-02 13:20:52 -0700406 break;
407 case kIndex_8_SkColorType:
msarett91c22b22016-02-22 12:27:46 -0800408 colorTypes.push_back(CodecSrc::kIndex8_Always_DstColorType);
msarett36c37962015-09-02 13:20:52 -0700409 break;
410 default:
msarett36c37962015-09-02 13:20:52 -0700411 break;
412 }
msarett9e707a02015-09-01 14:57:57 -0700413
scroggoc5560be2016-02-03 09:42:42 -0800414 SkTArray<SkAlphaType> alphaModes;
415 alphaModes.push_back(kPremul_SkAlphaType);
msarett9e9444c2016-02-03 12:39:10 -0800416 alphaModes.push_back(kUnpremul_SkAlphaType);
scroggoc5560be2016-02-03 09:42:42 -0800417 if (codec->getInfo().alphaType() == kOpaque_SkAlphaType) {
418 alphaModes.push_back(kOpaque_SkAlphaType);
419 }
msarettb714fb02016-01-22 14:46:42 -0800420
421 for (CodecSrc::Mode mode : nativeModes) {
422 // SkCodecImageGenerator only runs for the default colorType
423 // recommended by SkCodec. There is no need to generate multiple
424 // tests for different colorTypes.
425 // TODO (msarett): Add scaling support to SkCodecImageGenerator.
426 if (CodecSrc::kGen_Mode == mode) {
427 // FIXME: The gpu backend does not draw kGray sources correctly. (skbug.com/4822)
428 if (kGray_8_SkColorType != codec->getInfo().colorType()) {
scroggoc5560be2016-02-03 09:42:42 -0800429 push_codec_src(path, mode, CodecSrc::kGetFromCanvas_DstColorType,
430 codec->getInfo().alphaType(), 1.0f);
msarettb714fb02016-01-22 14:46:42 -0800431 }
432 continue;
433 }
434
435 for (float scale : nativeScales) {
msarett91c22b22016-02-22 12:27:46 -0800436 for (CodecSrc::DstColorType colorType : colorTypes) {
scroggoc5560be2016-02-03 09:42:42 -0800437 for (SkAlphaType alphaType : alphaModes) {
msarett91c22b22016-02-22 12:27:46 -0800438 // Only test kCroppedScanline_Mode when the alpha type is opaque. The test is
439 // slow and won't be interestingly different with different alpha types.
440 if (CodecSrc::kCroppedScanline_Mode == mode &&
441 kOpaque_SkAlphaType != alphaType) {
442 continue;
443 }
444
445 push_codec_src(path, mode, colorType, alphaType, scale);
scroggoc5560be2016-02-03 09:42:42 -0800446 }
msarett9e707a02015-09-01 14:57:57 -0700447 }
448 }
msarett0a242972015-06-11 14:27:27 -0700449 }
msarett36c37962015-09-02 13:20:52 -0700450
halcanary6950de62015-11-07 05:29:00 -0800451 // https://bug.skia.org/4428
msarett33c76232015-11-16 13:43:40 -0800452 bool subset = false;
453 // The following image types are supported by BitmapRegionDecoder,
454 // so we will test full image decodes and subset decodes.
msarettbe8216a2015-12-04 08:00:50 -0800455 static const char* const exts[] = {
msarett3d9d7a72015-10-21 10:27:10 -0700456 "jpg", "jpeg", "png", "webp",
457 "JPG", "JPEG", "PNG", "WEBP",
458 };
msarettbe8216a2015-12-04 08:00:50 -0800459 for (const char* ext : exts) {
msarett3d9d7a72015-10-21 10:27:10 -0700460 if (path.endsWith(ext)) {
msarett33c76232015-11-16 13:43:40 -0800461 subset = true;
msarett3d9d7a72015-10-21 10:27:10 -0700462 break;
463 }
464 }
msarett33c76232015-11-16 13:43:40 -0800465
msarett3d9d7a72015-10-21 10:27:10 -0700466 const int sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
msarett36c37962015-09-02 13:20:52 -0700467
msarett3d9d7a72015-10-21 10:27:10 -0700468 for (int sampleSize : sampleSizes) {
msarett91c22b22016-02-22 12:27:46 -0800469 for (CodecSrc::DstColorType colorType : colorTypes) {
scroggoc5560be2016-02-03 09:42:42 -0800470 for (SkAlphaType alphaType : alphaModes) {
msarett91c22b22016-02-22 12:27:46 -0800471 push_android_codec_src(path, AndroidCodecSrc::kFullImage_Mode, colorType,
scroggoc5560be2016-02-03 09:42:42 -0800472 alphaType, sampleSize);
473 if (subset) {
msarett91c22b22016-02-22 12:27:46 -0800474 push_android_codec_src(path, AndroidCodecSrc::kDivisor_Mode, colorType,
scroggoc5560be2016-02-03 09:42:42 -0800475 alphaType, sampleSize);
476 }
msarett3d9d7a72015-10-21 10:27:10 -0700477 }
msarett36c37962015-09-02 13:20:52 -0700478 }
479 }
msarett438b2ad2015-04-09 12:43:10 -0700480}
481
msarett5cb48852015-11-06 08:56:32 -0800482static bool brd_color_type_supported(SkBitmapRegionDecoder::Strategy strategy,
msaretta5783ae2015-09-08 15:35:32 -0700483 CodecSrc::DstColorType dstColorType) {
484 switch (strategy) {
msarett5cb48852015-11-06 08:56:32 -0800485 case SkBitmapRegionDecoder::kCanvas_Strategy:
msaretta5783ae2015-09-08 15:35:32 -0700486 if (CodecSrc::kGetFromCanvas_DstColorType == dstColorType) {
487 return true;
488 }
489 return false;
msarett5cb48852015-11-06 08:56:32 -0800490 case SkBitmapRegionDecoder::kAndroidCodec_Strategy:
msarett26ad17b2015-10-22 07:29:19 -0700491 switch (dstColorType) {
492 case CodecSrc::kGetFromCanvas_DstColorType:
493 case CodecSrc::kIndex8_Always_DstColorType:
494 case CodecSrc::kGrayscale_Always_DstColorType:
495 return true;
496 default:
497 return false;
498 }
msaretta5783ae2015-09-08 15:35:32 -0700499 default:
500 SkASSERT(false);
501 return false;
502 }
503}
504
msarett5cb48852015-11-06 08:56:32 -0800505static void push_brd_src(Path path, SkBitmapRegionDecoder::Strategy strategy,
msaretta5783ae2015-09-08 15:35:32 -0700506 CodecSrc::DstColorType dstColorType, BRDSrc::Mode mode, uint32_t sampleSize) {
507 SkString folder;
508 switch (strategy) {
msarett5cb48852015-11-06 08:56:32 -0800509 case SkBitmapRegionDecoder::kCanvas_Strategy:
msaretta5783ae2015-09-08 15:35:32 -0700510 folder.append("brd_canvas");
511 break;
msarett5cb48852015-11-06 08:56:32 -0800512 case SkBitmapRegionDecoder::kAndroidCodec_Strategy:
msarett26ad17b2015-10-22 07:29:19 -0700513 folder.append("brd_android_codec");
514 break;
msaretta5783ae2015-09-08 15:35:32 -0700515 default:
516 SkASSERT(false);
517 return;
518 }
519
520 switch (mode) {
521 case BRDSrc::kFullImage_Mode:
522 break;
523 case BRDSrc::kDivisor_Mode:
524 folder.append("_divisor");
525 break;
526 default:
527 SkASSERT(false);
528 return;
529 }
530
531 switch (dstColorType) {
532 case CodecSrc::kGetFromCanvas_DstColorType:
533 break;
534 case CodecSrc::kIndex8_Always_DstColorType:
535 folder.append("_kIndex");
536 break;
537 case CodecSrc::kGrayscale_Always_DstColorType:
538 folder.append("_kGray");
539 break;
540 default:
541 SkASSERT(false);
542 return;
543 }
544
545 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -0800546 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
msaretta5783ae2015-09-08 15:35:32 -0700547 }
548
549 BRDSrc* src = new BRDSrc(path, strategy, mode, dstColorType, sampleSize);
550 push_src("image", folder, src);
551}
552
553static void push_brd_srcs(Path path) {
554
msarett5cb48852015-11-06 08:56:32 -0800555 const SkBitmapRegionDecoder::Strategy strategies[] = {
556 SkBitmapRegionDecoder::kCanvas_Strategy,
msarett5cb48852015-11-06 08:56:32 -0800557 SkBitmapRegionDecoder::kAndroidCodec_Strategy,
msaretta5783ae2015-09-08 15:35:32 -0700558 };
559
scroggo501b7342015-11-03 07:55:11 -0800560 // Test on a variety of sampleSizes, making sure to include:
561 // - 2, 4, and 8, which are natively supported by jpeg
562 // - multiples of 2 which are not divisible by 4 (analogous for 4)
563 // - larger powers of two, since BRD clients generally use powers of 2
564 // We will only produce output for the larger sizes on large images.
565 const uint32_t sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 64 };
msarett6efbe052015-09-11 09:01:16 -0700566
msaretta5783ae2015-09-08 15:35:32 -0700567 // We will only test to one backend (8888), but we will test all of the
568 // color types that we need to decode to on this backend.
569 const CodecSrc::DstColorType dstColorTypes[] = {
msarett26ad17b2015-10-22 07:29:19 -0700570 CodecSrc::kGetFromCanvas_DstColorType,
571 CodecSrc::kIndex8_Always_DstColorType,
572 CodecSrc::kGrayscale_Always_DstColorType,
msaretta5783ae2015-09-08 15:35:32 -0700573 };
574
575 const BRDSrc::Mode modes[] = {
msarett26ad17b2015-10-22 07:29:19 -0700576 BRDSrc::kFullImage_Mode,
577 BRDSrc::kDivisor_Mode,
msaretta5783ae2015-09-08 15:35:32 -0700578 };
579
msarett5cb48852015-11-06 08:56:32 -0800580 for (SkBitmapRegionDecoder::Strategy strategy : strategies) {
msarett6efbe052015-09-11 09:01:16 -0700581 for (uint32_t sampleSize : sampleSizes) {
msarett6efbe052015-09-11 09:01:16 -0700582 for (CodecSrc::DstColorType dstColorType : dstColorTypes) {
583 if (brd_color_type_supported(strategy, dstColorType)) {
584 for (BRDSrc::Mode mode : modes) {
msaretta5783ae2015-09-08 15:35:32 -0700585 push_brd_src(path, strategy, dstColorType, mode, sampleSize);
586 }
587 }
588 }
589 }
590 }
591}
592
593static bool brd_supported(const char* ext) {
msarett8c8f22a2015-04-01 06:58:48 -0700594 static const char* const exts[] = {
msaretta5783ae2015-09-08 15:35:32 -0700595 "jpg", "jpeg", "png", "webp",
596 "JPG", "JPEG", "PNG", "WEBP",
msarett8c8f22a2015-04-01 06:58:48 -0700597 };
598
599 for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) {
600 if (0 == strcmp(exts[i], ext)) {
601 return true;
602 }
603 }
604 return false;
scroggo9b77ddd2015-03-19 06:03:39 -0700605}
606
scroggo86737142016-02-03 12:19:11 -0800607static bool gather_srcs() {
mtklein748ca3b2015-01-15 10:56:12 -0800608 for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) {
djsollen54416de2015-04-03 07:24:48 -0700609 push_src("gm", "", new GMSrc(r->factory()));
mtklein748ca3b2015-01-15 10:56:12 -0800610 }
halcanaryfc37ad12015-01-30 07:31:19 -0800611 for (int i = 0; i < FLAGS_skps.count(); i++) {
612 const char* path = FLAGS_skps[i];
613 if (sk_isdir(path)) {
614 SkOSFile::Iter it(path, "skp");
615 for (SkString file; it.next(&file); ) {
djsollen54416de2015-04-03 07:24:48 -0700616 push_src("skp", "", new SKPSrc(SkOSPath::Join(path, file.c_str())));
halcanaryfc37ad12015-01-30 07:31:19 -0800617 }
618 } else {
djsollen54416de2015-04-03 07:24:48 -0700619 push_src("skp", "", new SKPSrc(path));
mtklein114c3cd2015-01-15 10:15:02 -0800620 }
621 }
scroggo86737142016-02-03 12:19:11 -0800622
623 SkTArray<SkString> images;
624 if (!CollectImages(&images)) {
625 return false;
626 }
627
628 for (auto image : images) {
629 push_codec_srcs(image);
mtklein21eaf3b2016-02-08 12:39:59 -0800630 const char* ext = strrchr(image.c_str(), '.');
631 if (ext && brd_supported(ext+1)) {
scroggo86737142016-02-03 12:19:11 -0800632 push_brd_srcs(image);
mtklein709d2c32015-01-15 08:30:25 -0800633 }
mtklein709d2c32015-01-15 08:30:25 -0800634 }
scroggo86737142016-02-03 12:19:11 -0800635
636 return true;
mtklein709d2c32015-01-15 08:30:25 -0800637}
638
kkinnunen3e980c32015-12-23 01:33:00 -0800639static void push_sink(const SkCommandLineConfig& config, Sink* s) {
rmistry0f515bd2015-12-22 10:22:26 -0800640 SkAutoTDelete<Sink> sink(s);
kkinnunen3e980c32015-12-23 01:33:00 -0800641
mtkleine0effd62015-07-29 06:37:28 -0700642 // Try a simple Src as a canary. If it fails, skip this sink.
mtklein748ca3b2015-01-15 10:56:12 -0800643 struct : public Src {
mtkleine0effd62015-07-29 06:37:28 -0700644 Error draw(SkCanvas* c) const override {
645 c->drawRect(SkRect::MakeWH(1,1), SkPaint());
646 return "";
647 }
mtklein36352bf2015-03-25 18:17:31 -0700648 SkISize size() const override { return SkISize::Make(16, 16); }
mtkleine0effd62015-07-29 06:37:28 -0700649 Name name() const override { return "justOneRect"; }
650 } justOneRect;
mtklein114c3cd2015-01-15 10:15:02 -0800651
mtklein748ca3b2015-01-15 10:56:12 -0800652 SkBitmap bitmap;
653 SkDynamicMemoryWStream stream;
mtkleinb9eb4ac2015-02-02 18:26:03 -0800654 SkString log;
mtkleine0effd62015-07-29 06:37:28 -0700655 Error err = sink->draw(justOneRect, &bitmap, &stream, &log);
mtklein4089ef72015-03-05 08:40:28 -0800656 if (err.isFatal()) {
kkinnunen3e980c32015-12-23 01:33:00 -0800657 SkDebugf("Could not run %s: %s\n", config.getTag().c_str(), err.c_str());
mtklein05641a52015-04-21 10:49:13 -0700658 exit(1);
mtklein114c3cd2015-01-15 10:15:02 -0800659 }
660
mtkleine0effd62015-07-29 06:37:28 -0700661 TaggedSink& ts = gSinks.push_back();
mtklein748ca3b2015-01-15 10:56:12 -0800662 ts.reset(sink.detach());
kkinnunen3e980c32015-12-23 01:33:00 -0800663 ts.tag = config.getTag();
mtklein748ca3b2015-01-15 10:56:12 -0800664}
665
666static bool gpu_supported() {
667#if SK_SUPPORT_GPU
668 return FLAGS_gpu;
669#else
670 return false;
671#endif
672}
kkinnunen9ebc3f02015-12-21 23:48:13 -0800673
kkinnunen3e980c32015-12-23 01:33:00 -0800674static Sink* create_sink(const SkCommandLineConfig* config) {
675#if SK_SUPPORT_GPU
676 if (gpu_supported()) {
677 if (const SkCommandLineConfigGpu* gpuConfig = config->asConfigGpu()) {
678 GrContextFactory::GLContextType contextType = gpuConfig->getContextType();
679 GrContextFactory::GLContextOptions contextOptions =
680 GrContextFactory::kNone_GLContextOptions;
681 if (gpuConfig->getUseNVPR()) {
682 contextOptions = static_cast<GrContextFactory::GLContextOptions>(
683 contextOptions | GrContextFactory::kEnableNVPR_GLContextOptions);
684 }
685 GrContextFactory testFactory;
686 if (!testFactory.get(contextType, contextOptions)) {
687 SkDebugf("WARNING: can not create GPU context for config '%s'. "
688 "GM tests will be skipped.\n", gpuConfig->getTag().c_str());
689 return nullptr;
690 }
691 return new GPUSink(contextType, contextOptions, gpuConfig->getSamples(),
692 gpuConfig->getUseDIText(), FLAGS_gpu_threading);
693 }
694 }
695#endif
696
697#define SINK(t, sink, ...) if (config->getBackend().equals(t)) { return new sink(__VA_ARGS__); }
698
tomhudsoneebc39a2015-02-23 12:18:05 -0800699#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
700 SINK("hwui", HWUISink);
701#endif
702
mtklein748ca3b2015-01-15 10:56:12 -0800703 if (FLAGS_cpu) {
704 SINK("565", RasterSink, kRGB_565_SkColorType);
705 SINK("8888", RasterSink, kN32_SkColorType);
halcanaryc11c62f2015-09-28 11:51:54 -0700706 SINK("pdf", PDFSink, "Pdfium");
707 SINK("pdf_poppler", PDFSink, "Poppler");
mtklein9c3f17d2015-01-28 11:35:18 -0800708 SINK("skp", SKPSink);
mtklein8a4527e2015-01-31 20:00:58 -0800709 SINK("svg", SVGSink);
710 SINK("null", NullSink);
halcanary47ef4d52015-03-03 09:13:09 -0800711 SINK("xps", XPSSink);
mtklein748ca3b2015-01-15 10:56:12 -0800712 }
713#undef SINK
halcanary96fcdcc2015-08-27 07:41:13 -0700714 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800715}
716
kkinnunen3e980c32015-12-23 01:33:00 -0800717static Sink* create_via(const SkString& tag, Sink* wrapped) {
718#define VIA(t, via, ...) if (tag.equals(t)) { return new via(__VA_ARGS__); }
halcanary96fcdcc2015-08-27 07:41:13 -0700719 VIA("twice", ViaTwice, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700720 VIA("serialize", ViaSerialization, wrapped);
mtklein4a34ecb2016-01-08 10:19:35 -0800721 VIA("pic", ViaPicture, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700722 VIA("2ndpic", ViaSecondPicture, wrapped);
mtkleind31c13d2015-05-05 12:59:56 -0700723 VIA("sp", ViaSingletonPictures, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700724 VIA("tiles", ViaTiles, 256, 256, nullptr, wrapped);
mtklein7edca212015-01-21 13:18:51 -0800725 VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped);
mtklein2e2ea382015-10-16 10:29:41 -0700726 VIA("remote", ViaRemote, false, wrapped);
727 VIA("remote_cache", ViaRemote, true, wrapped);
halcanary7a76f9c2016-02-03 11:53:18 -0800728 VIA("mojo", ViaMojo, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800729
mtkleind603b222015-02-17 11:13:33 -0800730 if (FLAGS_matrix.count() == 4) {
mtklein748ca3b2015-01-15 10:56:12 -0800731 SkMatrix m;
mtkleind603b222015-02-17 11:13:33 -0800732 m.reset();
733 m.setScaleX((SkScalar)atof(FLAGS_matrix[0]));
734 m.setSkewX ((SkScalar)atof(FLAGS_matrix[1]));
735 m.setSkewY ((SkScalar)atof(FLAGS_matrix[2]));
736 m.setScaleY((SkScalar)atof(FLAGS_matrix[3]));
737 VIA("matrix", ViaMatrix, m, wrapped);
738 VIA("upright", ViaUpright, m, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800739 }
tomhudson64de1e12015-03-05 08:01:07 -0800740
741#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
742 VIA("androidsdk", ViaAndroidSDK, wrapped);
743#endif
744
mtklein748ca3b2015-01-15 10:56:12 -0800745#undef VIA
halcanary96fcdcc2015-08-27 07:41:13 -0700746 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800747}
748
mtklein748ca3b2015-01-15 10:56:12 -0800749static void gather_sinks() {
kkinnunen3e980c32015-12-23 01:33:00 -0800750 SkCommandLineConfigArray configs;
751 ParseConfigs(FLAGS_config, &configs);
752 for (int i = 0; i < configs.count(); i++) {
753 const SkCommandLineConfig& config = *configs[i];
754 Sink* sink = create_sink(&config);
755 if (sink == nullptr) {
756 SkDebugf("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
757 config.getTag().c_str());
758 continue;
759 }
mtklein748ca3b2015-01-15 10:56:12 -0800760
kkinnunen3e980c32015-12-23 01:33:00 -0800761 const SkTArray<SkString>& parts = config.getViaParts();
762 for (int j = parts.count(); j-- > 0;) {
763 const SkString& part = parts[j];
764 Sink* next = create_via(part, sink);
halcanary96fcdcc2015-08-27 07:41:13 -0700765 if (next == nullptr) {
kkinnunen3e980c32015-12-23 01:33:00 -0800766 SkDebugf("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(),
767 part.c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800768 delete sink;
halcanary96fcdcc2015-08-27 07:41:13 -0700769 sink = nullptr;
mtklein748ca3b2015-01-15 10:56:12 -0800770 break;
771 }
772 sink = next;
773 }
774 if (sink) {
775 push_sink(config, sink);
mtklein114c3cd2015-01-15 10:15:02 -0800776 }
777 }
778}
mtklein709d2c32015-01-15 08:30:25 -0800779
mtkleina5114d72015-08-24 13:27:01 -0700780static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) {
781 const int w = bitmap.width(),
782 h = bitmap.height();
783
784 // First get the bitmap into N32 color format. The next step will work only there.
785 if (bitmap.colorType() != kN32_SkColorType) {
786 SkBitmap n32;
787 if (!bitmap.copyTo(&n32, kN32_SkColorType)) {
788 return false;
789 }
790 bitmap = n32;
791 }
792
793 // Convert our N32 bitmap into unpremul RGBA for libpng.
794 SkAutoTMalloc<uint32_t> rgba(w*h);
795 if (!bitmap.readPixels(SkImageInfo::Make(w,h, kRGBA_8888_SkColorType, kUnpremul_SkAlphaType),
796 rgba, 4*w, 0,0)) {
797 return false;
798 }
799
800 // We don't need bitmap anymore. Might as well drop our ref.
mtkleinfccb77d2015-08-24 14:13:29 -0700801 bitmap.reset();
mtkleina5114d72015-08-24 13:27:01 -0700802
mtkleinc64137c2015-08-25 10:56:08 -0700803 FILE* f = fopen(path, "wb");
mtkleina5114d72015-08-24 13:27:01 -0700804 if (!f) { return false; }
805
806 png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
807 if (!png) {
808 fclose(f);
809 return false;
810 }
811
812 png_infop info = png_create_info_struct(png);
813 if (!info) {
814 png_destroy_write_struct(&png, &info);
815 fclose(f);
816 return false;
817 }
818
mtkleind69ece62015-09-10 10:37:44 -0700819 SkString description;
820 description.append("Key: ");
821 for (int i = 0; i < FLAGS_key.count(); i++) {
822 description.appendf("%s ", FLAGS_key[i]);
823 }
824 description.append("Properties: ");
825 for (int i = 0; i < FLAGS_properties.count(); i++) {
826 description.appendf("%s ", FLAGS_properties[i]);
827 }
828 description.appendf("MD5: %s", md5);
829
mtkleina5114d72015-08-24 13:27:01 -0700830 png_text text[2];
831 text[0].key = (png_charp)"Author";
832 text[0].text = (png_charp)"DM dump_png()";
833 text[0].compression = PNG_TEXT_COMPRESSION_NONE;
834 text[1].key = (png_charp)"Description";
mtkleind69ece62015-09-10 10:37:44 -0700835 text[1].text = (png_charp)description.c_str();
mtkleina5114d72015-08-24 13:27:01 -0700836 text[1].compression = PNG_TEXT_COMPRESSION_NONE;
837 png_set_text(png, info, text, 2);
838
839 png_init_io(png, f);
840 png_set_IHDR(png, info, (png_uint_32)w, (png_uint_32)h, 8,
841 PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
842 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
843 png_write_info(png, info);
844 for (int j = 0; j < h; j++) {
845 png_bytep row = (png_bytep)(rgba.get() + w*j);
846 png_write_rows(png, &row, 1);
847 }
848 png_write_end(png, info);
849
850 png_destroy_write_struct(&png, &info);
851 fclose(f);
852 return true;
853}
854
mtkleina2ef6422015-01-15 13:44:22 -0800855static bool match(const char* needle, const char* haystack) {
halcanary96fcdcc2015-08-27 07:41:13 -0700856 return 0 == strcmp("_", needle) || nullptr != strstr(haystack, needle);
mtkleina2ef6422015-01-15 13:44:22 -0800857}
858
djsollen54416de2015-04-03 07:24:48 -0700859static ImplicitString is_blacklisted(const char* sink, const char* src,
860 const char* srcOptions, const char* name) {
mtklein0d243ff2015-04-03 07:51:00 -0700861 for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) {
mtkleina2ef6422015-01-15 13:44:22 -0800862 if (match(FLAGS_blacklist[i+0], sink) &&
djsollen54416de2015-04-03 07:24:48 -0700863 match(FLAGS_blacklist[i+1], src) &&
864 match(FLAGS_blacklist[i+2], srcOptions) &&
865 match(FLAGS_blacklist[i+3], name)) {
866 return SkStringPrintf("%s %s %s %s",
867 FLAGS_blacklist[i+0], FLAGS_blacklist[i+1],
868 FLAGS_blacklist[i+2], FLAGS_blacklist[i+3]);
mtkleina2ef6422015-01-15 13:44:22 -0800869 }
870 }
871 return "";
872}
873
mtkleincd50bca2016-01-05 06:20:20 -0800874// Even when a Task Sink reports to be non-threadsafe (e.g. GPU), we know things like
875// .png encoding are definitely thread safe. This lets us offload that work to CPU threads.
876static SkTaskGroup gDefinitelyThreadSafeWork;
877
mtklein748ca3b2015-01-15 10:56:12 -0800878// The finest-grained unit of work we can run: draw a single Src into a single Sink,
879// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
880struct Task {
mtkleine0effd62015-07-29 06:37:28 -0700881 Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {}
882 const TaggedSrc& src;
883 const TaggedSink& sink;
mtklein748ca3b2015-01-15 10:56:12 -0800884
mtklein21eaf3b2016-02-08 12:39:59 -0800885 static void Run(const Task& task) {
886 SkString name = task.src->name();
mtkleine0effd62015-07-29 06:37:28 -0700887
888 // We'll skip drawing this Src/Sink pair if:
889 // - the Src vetoes the Sink;
890 // - this Src / Sink combination is on the blacklist;
891 // - it's a dry run.
mtklein21eaf3b2016-02-08 12:39:59 -0800892 SkString note(task.src->veto(task.sink->flags()) ? " (veto)" : "");
893 SkString whyBlacklisted = is_blacklisted(task.sink.tag.c_str(), task.src.tag.c_str(),
894 task.src.options.c_str(), name.c_str());
mtkleinb37cb412015-03-18 05:27:14 -0700895 if (!whyBlacklisted.isEmpty()) {
896 note.appendf(" (--blacklist %s)", whyBlacklisted.c_str());
897 }
mtkleine0effd62015-07-29 06:37:28 -0700898
mtkleinb9eb4ac2015-02-02 18:26:03 -0800899 SkString log;
mtkleinf27f08b2015-11-03 06:54:24 -0800900 auto timerStart = now_ms();
mtkleine0effd62015-07-29 06:37:28 -0700901 if (!FLAGS_dryRun && note.isEmpty()) {
mtklein748ca3b2015-01-15 10:56:12 -0800902 SkBitmap bitmap;
903 SkDynamicMemoryWStream stream;
mtklein21eaf3b2016-02-08 12:39:59 -0800904 start(task.sink.tag.c_str(), task.src.tag, task.src.options, name.c_str());
905 Error err = task.sink->draw(*task.src, &bitmap, &stream, &log);
mtklein748ca3b2015-01-15 10:56:12 -0800906 if (!err.isEmpty()) {
mtklein4089ef72015-03-05 08:40:28 -0800907 if (err.isFatal()) {
djsollen54416de2015-04-03 07:24:48 -0700908 fail(SkStringPrintf("%s %s %s %s: %s",
mtklein21eaf3b2016-02-08 12:39:59 -0800909 task.sink.tag.c_str(),
910 task.src.tag.c_str(),
911 task.src.options.c_str(),
mtklein4089ef72015-03-05 08:40:28 -0800912 name.c_str(),
913 err.c_str()));
mtkleinb37cb412015-03-18 05:27:14 -0700914 } else {
915 note.appendf(" (skipped: %s)", err.c_str());
mtkleinba6ada72016-01-21 09:39:35 -0800916 auto elapsed = now_ms() - timerStart;
mtklein21eaf3b2016-02-08 12:39:59 -0800917 done(elapsed, task.sink.tag.c_str(), task.src.tag, task.src.options,
mtkleinba6ada72016-01-21 09:39:35 -0800918 name, note, log);
919 return;
mtklein4089ef72015-03-05 08:40:28 -0800920 }
mtklein748ca3b2015-01-15 10:56:12 -0800921 }
mtklein62bd1a62015-01-27 14:46:26 -0800922
mtkleincd50bca2016-01-05 06:20:20 -0800923 // We're likely switching threads here, so we must capture by value, [=] or [foo,bar].
924 SkStreamAsset* data = stream.detachAsStream();
925 gDefinitelyThreadSafeWork.add([task,name,bitmap,data]{
926 SkAutoTDelete<SkStreamAsset> ownedData(data);
927
928 // Why doesn't the copy constructor do this when we have pre-locked pixels?
929 bitmap.lockPixels();
930
931 SkString md5;
932 if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
933 SkMD5 hash;
934 if (data->getLength()) {
935 hash.writeStream(data, data->getLength());
936 data->rewind();
mtklein38408462015-07-08 07:25:27 -0700937 } else {
mtkleincd50bca2016-01-05 06:20:20 -0800938 // If we're BGRA (Linux, Windows), swizzle over to RGBA (Mac, Android).
939 // This helps eliminate multiple 0-pixel-diff hashes on gold.skia.org.
940 // (Android's general slow speed breaks the tie arbitrarily in RGBA's favor.)
941 // We might consider promoting 565 to RGBA too.
942 if (bitmap.colorType() == kBGRA_8888_SkColorType) {
943 SkBitmap swizzle;
944 SkAssertResult(bitmap.copyTo(&swizzle, kRGBA_8888_SkColorType));
945 hash.write(swizzle.getPixels(), swizzle.getSize());
946 } else {
947 hash.write(bitmap.getPixels(), bitmap.getSize());
948 }
949 }
950 SkMD5::Digest digest;
951 hash.finish(digest);
952 for (int i = 0; i < 16; i++) {
953 md5.appendf("%02x", digest.data[i]);
mtklein38408462015-07-08 07:25:27 -0700954 }
mtklein62bd1a62015-01-27 14:46:26 -0800955 }
mtklein62bd1a62015-01-27 14:46:26 -0800956
mtkleincd50bca2016-01-05 06:20:20 -0800957 if (!FLAGS_readPath.isEmpty() &&
mtklein21eaf3b2016-02-08 12:39:59 -0800958 !gGold.contains(Gold(task.sink.tag.c_str(), task.src.tag.c_str(),
959 task.src.options.c_str(), name, md5))) {
mtkleincd50bca2016-01-05 06:20:20 -0800960 fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
961 md5.c_str(),
mtklein21eaf3b2016-02-08 12:39:59 -0800962 task.sink.tag.c_str(),
963 task.src.tag.c_str(),
964 task.src.options.c_str(),
mtkleincd50bca2016-01-05 06:20:20 -0800965 name.c_str(),
966 FLAGS_readPath[0]));
mtklein748ca3b2015-01-15 10:56:12 -0800967 }
mtkleincd50bca2016-01-05 06:20:20 -0800968
969 if (!FLAGS_writePath.isEmpty()) {
mtklein21eaf3b2016-02-08 12:39:59 -0800970 const char* ext = task.sink->fileExtension();
mtkleincd50bca2016-01-05 06:20:20 -0800971 if (data->getLength()) {
mtklein21eaf3b2016-02-08 12:39:59 -0800972 WriteToDisk(task, md5, ext, data, data->getLength(), nullptr);
mtkleincd50bca2016-01-05 06:20:20 -0800973 SkASSERT(bitmap.drawsNothing());
974 } else if (!bitmap.drawsNothing()) {
mtklein21eaf3b2016-02-08 12:39:59 -0800975 WriteToDisk(task, md5, ext, nullptr, 0, &bitmap);
mtkleincd50bca2016-01-05 06:20:20 -0800976 }
977 }
978 });
mtklein748ca3b2015-01-15 10:56:12 -0800979 }
mtkleinba6ada72016-01-21 09:39:35 -0800980 auto elapsed = now_ms() - timerStart;
mtklein21eaf3b2016-02-08 12:39:59 -0800981 done(elapsed, task.sink.tag.c_str(), task.src.tag.c_str(), task.src.options.c_str(),
mtkleinf27f08b2015-11-03 06:54:24 -0800982 name, note, log);
mtklein748ca3b2015-01-15 10:56:12 -0800983 }
984
985 static void WriteToDisk(const Task& task,
mtklein62bd1a62015-01-27 14:46:26 -0800986 SkString md5,
987 const char* ext,
mtklein748ca3b2015-01-15 10:56:12 -0800988 SkStream* data, size_t len,
mtklein62bd1a62015-01-27 14:46:26 -0800989 const SkBitmap* bitmap) {
mtklein748ca3b2015-01-15 10:56:12 -0800990 JsonWriter::BitmapResult result;
djsollen54416de2015-04-03 07:24:48 -0700991 result.name = task.src->name();
kkinnunen3e980c32015-12-23 01:33:00 -0800992 result.config = task.sink.tag.c_str();
djsollen54416de2015-04-03 07:24:48 -0700993 result.sourceType = task.src.tag;
994 result.sourceOptions = task.src.options;
995 result.ext = ext;
996 result.md5 = md5;
mtklein748ca3b2015-01-15 10:56:12 -0800997 JsonWriter::AddBitmapResult(result);
998
mtkleinb0531a72015-04-07 13:38:48 -0700999 // If an MD5 is uninteresting, we want it noted in the JSON file,
1000 // but don't want to dump it out as a .png (or whatever ext is).
1001 if (gUninterestingHashes.contains(md5)) {
1002 return;
1003 }
1004
mtklein748ca3b2015-01-15 10:56:12 -08001005 const char* dir = FLAGS_writePath[0];
1006 if (0 == strcmp(dir, "@")) { // Needed for iOS.
1007 dir = FLAGS_resourcePath[0];
1008 }
1009 sk_mkdir(dir);
1010
1011 SkString path;
1012 if (FLAGS_nameByHash) {
1013 path = SkOSPath::Join(dir, result.md5.c_str());
1014 path.append(".");
1015 path.append(ext);
1016 if (sk_exists(path.c_str())) {
1017 return; // Content-addressed. If it exists already, we're done.
1018 }
1019 } else {
kkinnunen3e980c32015-12-23 01:33:00 -08001020 path = SkOSPath::Join(dir, task.sink.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001021 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -07001022 path = SkOSPath::Join(path.c_str(), task.src.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001023 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -07001024 if (strcmp(task.src.options.c_str(), "") != 0) {
1025 path = SkOSPath::Join(path.c_str(), task.src.options.c_str());
djsollen54416de2015-04-03 07:24:48 -07001026 sk_mkdir(path.c_str());
1027 }
mtklein748ca3b2015-01-15 10:56:12 -08001028 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
1029 path.append(".");
1030 path.append(ext);
1031 }
1032
mtklein748ca3b2015-01-15 10:56:12 -08001033 if (bitmap) {
mtkleina5114d72015-08-24 13:27:01 -07001034 if (!dump_png(*bitmap, path.c_str(), result.md5.c_str())) {
mtklein748ca3b2015-01-15 10:56:12 -08001035 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
1036 return;
1037 }
1038 } else {
mtkleina5114d72015-08-24 13:27:01 -07001039 SkFILEWStream file(path.c_str());
1040 if (!file.isValid()) {
1041 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
1042 return;
1043 }
mtklein748ca3b2015-01-15 10:56:12 -08001044 if (!file.writeStream(data, len)) {
1045 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
1046 return;
1047 }
1048 }
1049 }
1050};
1051
mtklein748ca3b2015-01-15 10:56:12 -08001052/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1053
1054// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
1055
mtklein21eaf3b2016-02-08 12:39:59 -08001056static SkTDArray<skiatest::Test> gParallelTests, gSerialTests;
mtklein748ca3b2015-01-15 10:56:12 -08001057
1058static void gather_tests() {
mtklein6c5fed22015-01-20 13:47:23 -08001059 if (!FLAGS_src.contains("tests")) {
mtklein748ca3b2015-01-15 10:56:12 -08001060 return;
1061 }
mtklein6393c062015-04-27 08:45:01 -07001062 for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; r = r->next()) {
1063 if (!in_shard()) {
1064 continue;
1065 }
halcanary87f3ba42015-01-20 09:30:20 -08001066 // Despite its name, factory() is returning a reference to
1067 // link-time static const POD data.
1068 const skiatest::Test& test = r->factory();
1069 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -08001070 continue;
1071 }
halcanary87f3ba42015-01-20 09:30:20 -08001072 if (test.needsGpu && gpu_supported()) {
mtklein21eaf3b2016-02-08 12:39:59 -08001073 (FLAGS_gpu_threading ? gParallelTests : gSerialTests).push(test);
halcanary87f3ba42015-01-20 09:30:20 -08001074 } else if (!test.needsGpu && FLAGS_cpu) {
mtklein21eaf3b2016-02-08 12:39:59 -08001075 gParallelTests.push(test);
mtklein82d28432015-01-15 12:46:02 -08001076 }
mtklein748ca3b2015-01-15 10:56:12 -08001077 }
1078}
1079
mtklein21eaf3b2016-02-08 12:39:59 -08001080static void run_test(skiatest::Test test) {
halcanary87f3ba42015-01-20 09:30:20 -08001081 struct : public skiatest::Reporter {
mtklein36352bf2015-03-25 18:17:31 -07001082 void reportFailed(const skiatest::Failure& failure) override {
halcanary87f3ba42015-01-20 09:30:20 -08001083 fail(failure.toString());
1084 JsonWriter::AddTestFailure(failure);
1085 }
mtklein36352bf2015-03-25 18:17:31 -07001086 bool allowExtendedTest() const override {
halcanary87f3ba42015-01-20 09:30:20 -08001087 return FLAGS_pathOpsExtended;
1088 }
mtklein36352bf2015-03-25 18:17:31 -07001089 bool verbose() const override { return FLAGS_veryVerbose; }
halcanary87f3ba42015-01-20 09:30:20 -08001090 } reporter;
djsollen824996a2015-06-12 12:06:22 -07001091
1092 SkString note;
mtklein21eaf3b2016-02-08 12:39:59 -08001093 SkString whyBlacklisted = is_blacklisted("_", "tests", "_", test.name);
djsollen824996a2015-06-12 12:06:22 -07001094 if (!whyBlacklisted.isEmpty()) {
1095 note.appendf(" (--blacklist %s)", whyBlacklisted.c_str());
1096 }
1097
mtkleinf27f08b2015-11-03 06:54:24 -08001098 auto timerStart = now_ms();
djsollen824996a2015-06-12 12:06:22 -07001099 if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) {
mtklein21eaf3b2016-02-08 12:39:59 -08001100 start("unit", "test", "", test.name);
mtklein55e88b22015-01-21 15:50:13 -08001101 GrContextFactory factory;
mtklein21eaf3b2016-02-08 12:39:59 -08001102 test.proc(&reporter, &factory);
mtklein748ca3b2015-01-15 10:56:12 -08001103 }
mtklein21eaf3b2016-02-08 12:39:59 -08001104 done(now_ms()-timerStart, "unit", "test", "", test.name, note, "");
mtklein748ca3b2015-01-15 10:56:12 -08001105}
1106
1107/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1108
mtkleinafae30a2016-02-24 12:28:32 -08001109DEFINE_int32(status_sec, 15, "Print status this often (and if we crash).");
1110
1111SkThread* start_status_thread() {
1112 auto thread = new SkThread([] (void*) {
1113 for (;;) {
1114 print_status();
1115 #if defined(SK_BUILD_FOR_WIN)
1116 Sleep(FLAGS_status_sec * 1000);
1117 #else
1118 sleep(FLAGS_status_sec);
1119 #endif
mtklein2e1c47e2015-03-12 07:16:56 -07001120 }
mtkleinafae30a2016-02-24 12:28:32 -08001121 });
1122 thread->start();
1123 return thread;
mtkleinde6fc2b2015-03-12 06:28:54 -07001124}
1125
caryclark83ca6282015-06-10 09:31:09 -07001126#define PORTABLE_FONT_PREFIX "Toy Liberation "
1127
1128static SkTypeface* create_from_name(const char familyName[], SkTypeface::Style style) {
1129 if (familyName && strlen(familyName) > sizeof(PORTABLE_FONT_PREFIX)
1130 && !strncmp(familyName, PORTABLE_FONT_PREFIX, sizeof(PORTABLE_FONT_PREFIX) - 1)) {
caryclark1818acb2015-07-24 12:09:25 -07001131 return sk_tool_utils::create_portable_typeface(familyName, style);
caryclark83ca6282015-06-10 09:31:09 -07001132 }
halcanary96fcdcc2015-08-27 07:41:13 -07001133 return nullptr;
caryclark83ca6282015-06-10 09:31:09 -07001134}
1135
1136#undef PORTABLE_FONT_PREFIX
1137
1138extern SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style );
1139
jcgregorio3b27ade2014-11-13 08:06:40 -08001140int dm_main();
caryclark17f0b6d2014-07-22 10:15:34 -07001141int dm_main() {
mtklein246ba3a2016-02-23 10:39:36 -08001142 setup_crash_handler();
mtkleinafae30a2016-02-24 12:28:32 -08001143
mtklein5286f022016-01-22 08:18:14 -08001144 JsonWriter::DumpJson(); // It's handy for the bots to assume this is ~never missing.
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +00001145 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -07001146 SkTaskGroup::Enabler enabled(FLAGS_threads);
caryclark83ca6282015-06-10 09:31:09 -07001147 gCreateTypefaceDelegate = &create_from_name;
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +00001148
halcanary7d571242016-02-24 17:59:16 -08001149 {
1150 SkString testResourcePath = GetResourcePath("color_wheel.png");
1151 SkFILEStream testResource(testResourcePath.c_str());
1152 if (!testResource.isValid()) {
1153 SkDebugf("Some resources are missing. Do you need to set --resourcePath?\n");
1154 }
1155 }
mtklein62bd1a62015-01-27 14:46:26 -08001156 gather_gold();
borenet09ed4802015-04-03 14:15:33 -07001157 gather_uninteresting_hashes();
mtklein62bd1a62015-01-27 14:46:26 -08001158
scroggo86737142016-02-03 12:19:11 -08001159 if (!gather_srcs()) {
1160 return 1;
1161 }
mtklein748ca3b2015-01-15 10:56:12 -08001162 gather_sinks();
1163 gather_tests();
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +00001164
mtklein21eaf3b2016-02-08 12:39:59 -08001165 gPending = gSrcs.count() * gSinks.count() + gParallelTests.count() + gSerialTests.count();
mtkleinafae30a2016-02-24 12:28:32 -08001166 SkDebugf("%d srcs * %d sinks + %d tests == %d tasks",
mtklein21eaf3b2016-02-08 12:39:59 -08001167 gSrcs.count(), gSinks.count(), gParallelTests.count() + gSerialTests.count(), gPending);
mtkleinafae30a2016-02-24 12:28:32 -08001168 SkAutoTDelete<SkThread> statusThread(start_status_thread());
mtklein748ca3b2015-01-15 10:56:12 -08001169
mtklein21eaf3b2016-02-08 12:39:59 -08001170 // Kick off as much parallel work as we can, making note of any serial work we'll need to do.
1171 SkTaskGroup parallel;
1172 SkTArray<Task> serial;
1173
1174 for (auto& sink : gSinks)
1175 for (auto& src : gSrcs) {
1176 Task task(src, sink);
1177 if (src->serial() || sink->serial()) {
1178 serial.push_back(task);
1179 } else {
1180 parallel.add([task] { Task::Run(task); });
mtklein748ca3b2015-01-15 10:56:12 -08001181 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001182 }
mtklein21eaf3b2016-02-08 12:39:59 -08001183 for (auto test : gParallelTests) {
1184 parallel.add([test] { run_test(test); });
mtklein55e88b22015-01-21 15:50:13 -08001185 }
mtklein21eaf3b2016-02-08 12:39:59 -08001186
1187 // With the parallel work running, run serial tasks and tests here on main thread.
1188 for (auto task : serial) { Task::Run(task); }
1189 for (auto test : gSerialTests) { run_test(test); }
1190
1191 // Wait for any remaining parallel work to complete (including any spun off of serial tasks).
1192 parallel.wait();
mtkleincd50bca2016-01-05 06:20:20 -08001193 gDefinitelyThreadSafeWork.wait();
1194
mtkleinda884c42016-02-24 18:00:23 -08001195 // We'd better have run everything.
1196 SkASSERT(gPending == 0);
1197
mtklein748ca3b2015-01-15 10:56:12 -08001198 // At this point we're back in single-threaded land.
caryclarkf53ce802015-06-15 06:48:30 -07001199 sk_tool_utils::release_portable_typefaces();
mtklein@google.comd36522d2013-10-16 13:02:15 +00001200
mtkleinbc4e0032015-12-09 08:37:35 -08001201 if (FLAGS_verbose && gNoteTally.count() > 0) {
1202 SkDebugf("\nNote tally:\n");
1203 gNoteTally.foreach([](const SkString& note, int* tally) {
1204 SkDebugf("%dx\t%s\n", *tally, note.c_str());
1205 });
1206 }
1207
mtklein2f64eec2015-01-15 14:20:41 -08001208 SkDebugf("\n");
mtklein748ca3b2015-01-15 10:56:12 -08001209 if (gFailures.count() > 0) {
1210 SkDebugf("Failures:\n");
1211 for (int i = 0; i < gFailures.count(); i++) {
mtklein9dc09102015-01-15 15:47:33 -08001212 SkDebugf("\t%s\n", gFailures[i].c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001213 }
1214 SkDebugf("%d failures\n", gFailures.count());
1215 return 1;
mtklein114c3cd2015-01-15 10:15:02 -08001216 }
mtkleinafae30a2016-02-24 12:28:32 -08001217
1218#ifdef SK_PDF_IMAGE_STATS
halcanary7a14b312015-10-01 07:28:13 -07001219 SkPDFImageDumpStats();
mtkleinafae30a2016-02-24 12:28:32 -08001220#endif // SK_PDF_IMAGE_STATS
1221
1222 print_status();
scroggo4d9eaea2016-01-29 07:48:33 -08001223 SkDebugf("Finished!\n");
mtklein748ca3b2015-01-15 10:56:12 -08001224 return 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +00001225}
jcgregorio3b27ade2014-11-13 08:06:40 -08001226
kkinnunen179a8f52015-11-20 13:32:24 -08001227// TODO: currently many GPU tests are declared outside SK_SUPPORT_GPU guards.
1228// Thus we export the empty RunWithGPUTestContexts when SK_SUPPORT_GPU=0.
1229namespace skiatest {
1230namespace {
1231typedef void(*TestWithGrContext)(skiatest::Reporter*, GrContext*);
1232typedef void(*TestWithGrContextAndGLContext)(skiatest::Reporter*, GrContext*, SkGLContext*);
1233#if SK_SUPPORT_GPU
1234template<typename T>
kkinnunen34058002016-01-06 23:49:30 -08001235void call_test(T test, skiatest::Reporter* reporter, const GrContextFactory::ContextInfo& context);
kkinnunen179a8f52015-11-20 13:32:24 -08001236template<>
1237void call_test(TestWithGrContext test, skiatest::Reporter* reporter,
kkinnunen34058002016-01-06 23:49:30 -08001238 const GrContextFactory::ContextInfo& context) {
1239 test(reporter, context.fGrContext);
kkinnunen179a8f52015-11-20 13:32:24 -08001240}
1241template<>
1242void call_test(TestWithGrContextAndGLContext test, skiatest::Reporter* reporter,
kkinnunen34058002016-01-06 23:49:30 -08001243 const GrContextFactory::ContextInfo& context) {
1244 test(reporter, context.fGrContext, context.fGLContext);
kkinnunen179a8f52015-11-20 13:32:24 -08001245}
1246#endif
1247} // namespace
1248
kkinnunen179a8f52015-11-20 13:32:24 -08001249template<typename T>
1250void RunWithGPUTestContexts(T test, GPUTestContexts testContexts, Reporter* reporter,
1251 GrContextFactory* factory) {
1252#if SK_SUPPORT_GPU
kkinnunen3e980c32015-12-23 01:33:00 -08001253 // Iterate over context types, except use "native" instead of explicitly trying OpenGL and
1254 // OpenGL ES. Do not use GLES on desktop, since tests do not account for not fixing
1255 // http://skbug.com/2809
1256 GrContextFactory::GLContextType contextTypes[] = {
1257 GrContextFactory::kNative_GLContextType,
1258#if SK_ANGLE
1259#ifdef SK_BUILD_FOR_WIN
1260 GrContextFactory::kANGLE_GLContextType,
1261#endif
1262 GrContextFactory::kANGLE_GL_GLContextType,
1263#endif
1264#if SK_COMMAND_BUFFER
1265 GrContextFactory::kCommandBuffer_GLContextType,
1266#endif
1267#if SK_MESA
1268 GrContextFactory::kMESA_GLContextType,
1269#endif
1270 GrContextFactory::kNull_GLContextType,
1271 GrContextFactory::kDebug_GLContextType,
1272 };
1273 static_assert(SK_ARRAY_COUNT(contextTypes) == GrContextFactory::kGLContextTypeCnt - 2,
1274 "Skipping unexpected GLContextType for GPU tests");
1275
1276 for (auto& contextType : contextTypes) {
kkinnunen179a8f52015-11-20 13:32:24 -08001277 int contextSelector = kNone_GPUTestContexts;
kkinnunen3e980c32015-12-23 01:33:00 -08001278 if (GrContextFactory::IsRenderingGLContext(contextType)) {
kkinnunen179a8f52015-11-20 13:32:24 -08001279 contextSelector |= kAllRendering_GPUTestContexts;
kkinnunen3e980c32015-12-23 01:33:00 -08001280 } else if (contextType == GrContextFactory::kNative_GLContextType) {
kkinnunen179a8f52015-11-20 13:32:24 -08001281 contextSelector |= kNative_GPUTestContexts;
kkinnunen3e980c32015-12-23 01:33:00 -08001282 } else if (contextType == GrContextFactory::kNull_GLContextType) {
kkinnunen179a8f52015-11-20 13:32:24 -08001283 contextSelector |= kNull_GPUTestContexts;
kkinnunen3e980c32015-12-23 01:33:00 -08001284 } else if (contextType == GrContextFactory::kDebug_GLContextType) {
kkinnunen55eeae92015-12-10 23:19:29 -08001285 contextSelector |= kDebug_GPUTestContexts;
kkinnunen179a8f52015-11-20 13:32:24 -08001286 }
1287 if ((testContexts & contextSelector) == 0) {
1288 continue;
1289 }
kkinnunen34058002016-01-06 23:49:30 -08001290 GrContextFactory::ContextInfo context = factory->getContextInfo(contextType);
1291 if (context.fGrContext) {
kkinnunen5219fd92015-12-10 06:28:13 -08001292 call_test(test, reporter, context);
1293 }
kkinnunen34058002016-01-06 23:49:30 -08001294 context = factory->getContextInfo(contextType,
1295 GrContextFactory::kEnableNVPR_GLContextOptions);
1296 if (context.fGrContext) {
kkinnunen179a8f52015-11-20 13:32:24 -08001297 call_test(test, reporter, context);
1298 }
1299 }
1300#endif
1301}
1302
1303template
1304void RunWithGPUTestContexts<TestWithGrContext>(TestWithGrContext test,
1305 GPUTestContexts testContexts,
1306 Reporter* reporter,
1307 GrContextFactory* factory);
1308template
1309void RunWithGPUTestContexts<TestWithGrContextAndGLContext>(TestWithGrContextAndGLContext test,
1310 GPUTestContexts testContexts,
1311 Reporter* reporter,
1312 GrContextFactory* factory);
1313} // namespace skiatest
1314
borenet48087572015-04-02 12:16:36 -07001315#if !defined(SK_BUILD_FOR_IOS)
jcgregorio3b27ade2014-11-13 08:06:40 -08001316int main(int argc, char** argv) {
1317 SkCommandLineFlags::Parse(argc, argv);
1318 return dm_main();
1319}
1320#endif