blob: c7e0934008f3b5a8b2d8dd982976d169b1c923e0 [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"
scroggocc2feb12015-08-14 08:32:46 -070016#include "SkCodec.h"
caryclark17f0b6d2014-07-22 10:15:34 -070017#include "SkCommonFlags.h"
caryclark83ca6282015-06-10 09:31:09 -070018#include "SkFontMgr.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000019#include "SkForceLinking.h"
20#include "SkGraphics.h"
mtklein748ca3b2015-01-15 10:56:12 -080021#include "SkMD5.h"
mtklein1b249332015-07-07 12:21:21 -070022#include "SkMutex.h"
mtklein1d0f1642014-09-08 08:05:18 -070023#include "SkOSFile.h"
mtkleina82f5622015-02-20 12:30:19 -080024#include "SkTHash.h"
mtklein406654b2014-09-03 15:34:37 -070025#include "SkTaskGroup.h"
mtkleinde6fc2b2015-03-12 06:28:54 -070026#include "SkThreadUtils.h"
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +000027#include "Test.h"
mtklein748ca3b2015-01-15 10:56:12 -080028#include "Timer.h"
caryclark83ca6282015-06-10 09:31:09 -070029#include "sk_tool_utils.h"
mtklein@google.comd36522d2013-10-16 13:02:15 +000030
halcanary7a14b312015-10-01 07:28:13 -070031#ifdef SK_PDF_IMAGE_STATS
32extern void SkPDFImageDumpStats();
33#endif
34
mtkleina5114d72015-08-24 13:27:01 -070035#include "png.h"
36
bungeman60e0fee2015-08-26 05:15:46 -070037#include <stdlib.h>
38
scroggo27a58342015-10-28 08:56:41 -070039#ifndef SK_BUILD_FOR_WIN32
40 #include <unistd.h>
41#endif
42
djsollen54416de2015-04-03 07:24:48 -070043DEFINE_string(src, "tests gm skp image", "Source types to test.");
mtklein748ca3b2015-01-15 10:56:12 -080044DEFINE_bool(nameByHash, false,
45 "If true, write to FLAGS_writePath[0]/<hash>.png instead of "
djsollen54416de2015-04-03 07:24:48 -070046 "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.png");
mtklein748ca3b2015-01-15 10:56:12 -080047DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests.");
mtkleind603b222015-02-17 11:13:33 -080048DEFINE_string(matrix, "1 0 0 1",
49 "2x2 scale+skew matrix to apply or upright when using "
50 "'matrix' or 'upright' in config.");
mtklein82d28432015-01-15 12:46:02 -080051DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?");
mtklein@google.comd36522d2013-10-16 13:02:15 +000052
mtkleina2ef6422015-01-15 13:44:22 -080053DEFINE_string(blacklist, "",
djsollen54416de2015-04-03 07:24:48 -070054 "Space-separated config/src/srcOptions/name quadruples to blacklist. '_' matches anything. E.g. \n"
55 "'--blacklist gpu skp _ _' will blacklist all SKPs drawn into the gpu config.\n"
56 "'--blacklist gpu skp _ _ 8888 gm _ aarects' will also blacklist the aarects GM on 8888.");
mtkleina2ef6422015-01-15 13:44:22 -080057
mtklein62bd1a62015-01-27 14:46:26 -080058DEFINE_string2(readPath, r, "", "If set check for equality with golden results in this directory.");
59
borenet09ed4802015-04-03 14:15:33 -070060DEFINE_string(uninterestingHashesFile, "",
61 "File containing a list of uninteresting hashes. If a result hashes to something in "
62 "this list, no image is written for that result.");
63
mtklein6393c062015-04-27 08:45:01 -070064DEFINE_int32(shards, 1, "We're splitting source data into this many shards.");
65DEFINE_int32(shard, 0, "Which shard do I run?");
bsalomon821e10e2015-06-04 14:15:33 -070066DEFINE_bool2(pre_log, p, false, "Log before running each test. May be incomprehensible when threading");
mtklein6393c062015-04-27 08:45:01 -070067
mtklein@google.comd36522d2013-10-16 13:02:15 +000068__SK_FORCE_IMAGE_DECODER_LINKING;
mtklein748ca3b2015-01-15 10:56:12 -080069using namespace DM;
mtklein@google.comd36522d2013-10-16 13:02:15 +000070
mtklein748ca3b2015-01-15 10:56:12 -080071/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
72
mtkleinf27f08b2015-11-03 06:54:24 -080073static double now_ms() { return SkTime::GetNSecs() * 1e-6; }
74
mtklein748ca3b2015-01-15 10:56:12 -080075SK_DECLARE_STATIC_MUTEX(gFailuresMutex);
76static SkTArray<SkString> gFailures;
77
78static void fail(ImplicitString err) {
79 SkAutoMutexAcquire lock(gFailuresMutex);
80 SkDebugf("\n\nFAILURE: %s\n\n", err.c_str());
81 gFailures.push_back(err);
halcanary9e398f72015-01-10 11:18:04 -080082}
83
mtkleinb37cb412015-03-18 05:27:14 -070084static int32_t gPending = 0; // Atomic. Total number of running and queued tasks.
85
mtkleinbc4e0032015-12-09 08:37:35 -080086SK_DECLARE_STATIC_MUTEX(gRunningAndTallyMutex);
87static SkTArray<SkString> gRunning;
88static SkTHashMap<SkString, int> gNoteTally;
mtklein748ca3b2015-01-15 10:56:12 -080089
mtkleinb9eb4ac2015-02-02 18:26:03 -080090static void done(double ms,
djsollen54416de2015-04-03 07:24:48 -070091 ImplicitString config, ImplicitString src, ImplicitString srcOptions,
92 ImplicitString name, ImplicitString note, ImplicitString log) {
93 SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(),
94 srcOptions.c_str(), name.c_str());
mtkleinb37cb412015-03-18 05:27:14 -070095 {
mtkleinbc4e0032015-12-09 08:37:35 -080096 SkAutoMutexAcquire lock(gRunningAndTallyMutex);
mtkleinb37cb412015-03-18 05:27:14 -070097 for (int i = 0; i < gRunning.count(); i++) {
98 if (gRunning[i] == id) {
99 gRunning.removeShuffle(i);
100 break;
101 }
102 }
mtkleinbc4e0032015-12-09 08:37:35 -0800103 if (!note.isEmpty()) {
104 if (int* tally = gNoteTally.find(note)) {
105 *tally += 1;
106 } else {
107 gNoteTally.set(note, 1);
108 }
109 }
mtkleinb37cb412015-03-18 05:27:14 -0700110 }
mtkleinb9eb4ac2015-02-02 18:26:03 -0800111 if (!log.isEmpty()) {
112 log.prepend("\n");
113 }
mtklein6dee2ad2015-02-05 09:53:44 -0800114 auto pending = sk_atomic_dec(&gPending)-1;
mtkleinbc4e0032015-12-09 08:37:35 -0800115 if (!FLAGS_quiet && note.isEmpty()) {
116 SkDebugf("%s(%4d/%-4dMB %6d) %s\t%s%s", FLAGS_verbose ? "\n" : kSkOverwriteLine
reed50bc0512015-05-19 14:13:31 -0700117 , sk_tools::getCurrResidentSetSizeMB()
118 , sk_tools::getMaxResidentSetSizeMB()
119 , pending
120 , HumanizeMs(ms).c_str()
121 , id.c_str()
reed50bc0512015-05-19 14:13:31 -0700122 , log.c_str());
123 }
mtkleina17241b2015-01-23 05:48:00 -0800124 // We write our dm.json file every once in a while in case we crash.
125 // Notice this also handles the final dm.json when pending == 0.
126 if (pending % 500 == 0) {
127 JsonWriter::DumpJson();
128 }
mtklein@google.comd36522d2013-10-16 13:02:15 +0000129}
130
djsollen54416de2015-04-03 07:24:48 -0700131static void start(ImplicitString config, ImplicitString src,
132 ImplicitString srcOptions, ImplicitString name) {
133 SkString id = SkStringPrintf("%s %s %s %s", config.c_str(), src.c_str(),
134 srcOptions.c_str(), name.c_str());
mtkleinbc4e0032015-12-09 08:37:35 -0800135 SkAutoMutexAcquire lock(gRunningAndTallyMutex);
mtkleinb37cb412015-03-18 05:27:14 -0700136 gRunning.push_back(id);
137}
138
mtklein748ca3b2015-01-15 10:56:12 -0800139/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
mtklein114c3cd2015-01-15 10:15:02 -0800140
mtklein62bd1a62015-01-27 14:46:26 -0800141struct Gold : public SkString {
mtkleina82f5622015-02-20 12:30:19 -0800142 Gold() : SkString("") {}
djsollen54416de2015-04-03 07:24:48 -0700143 Gold(ImplicitString sink, ImplicitString src, ImplicitString srcOptions,
144 ImplicitString name, ImplicitString md5)
mtklein62bd1a62015-01-27 14:46:26 -0800145 : SkString("") {
146 this->append(sink);
147 this->append(src);
djsollen54416de2015-04-03 07:24:48 -0700148 this->append(srcOptions);
mtklein62bd1a62015-01-27 14:46:26 -0800149 this->append(name);
150 this->append(md5);
mtklein62bd1a62015-01-27 14:46:26 -0800151 }
mtkleinc8d1dd42015-10-15 12:23:01 -0700152 struct Hash {
153 uint32_t operator()(const Gold& g) const {
154 return SkGoodHash()((const SkString&)g);
155 }
156 };
mtklein62bd1a62015-01-27 14:46:26 -0800157};
mtkleina82f5622015-02-20 12:30:19 -0800158static SkTHashSet<Gold, Gold::Hash> gGold;
mtklein62bd1a62015-01-27 14:46:26 -0800159
160static void add_gold(JsonWriter::BitmapResult r) {
djsollen54416de2015-04-03 07:24:48 -0700161 gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5));
mtklein62bd1a62015-01-27 14:46:26 -0800162}
163
164static void gather_gold() {
165 if (!FLAGS_readPath.isEmpty()) {
166 SkString path(FLAGS_readPath[0]);
167 path.append("/dm.json");
168 if (!JsonWriter::ReadJson(path.c_str(), add_gold)) {
169 fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str()));
170 }
171 }
172}
173
174/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
175
borenet09ed4802015-04-03 14:15:33 -0700176static SkTHashSet<SkString> gUninterestingHashes;
177
178static void gather_uninteresting_hashes() {
179 if (!FLAGS_uninterestingHashesFile.isEmpty()) {
180 SkAutoTUnref<SkData> data(SkData::NewFromFileName(FLAGS_uninterestingHashesFile[0]));
mtkleincc334b32015-09-22 11:43:53 -0700181 if (!data) {
182 SkDebugf("WARNING: unable to read uninteresting hashes from %s\n",
183 FLAGS_uninterestingHashesFile[0]);
184 return;
185 }
borenet09ed4802015-04-03 14:15:33 -0700186 SkTArray<SkString> hashes;
187 SkStrSplit((const char*)data->data(), "\n", &hashes);
188 for (const SkString& hash : hashes) {
189 gUninterestingHashes.add(hash);
190 }
191 }
192}
193
194/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
195
mtkleine0effd62015-07-29 06:37:28 -0700196struct TaggedSrc : public SkAutoTDelete<Src> {
msarett9e707a02015-09-01 14:57:57 -0700197 ImplicitString tag;
198 ImplicitString options;
mtkleine0effd62015-07-29 06:37:28 -0700199};
200
201struct TaggedSink : public SkAutoTDelete<Sink> {
rmistry0f515bd2015-12-22 10:22:26 -0800202 const char* tag;
djsollen54416de2015-04-03 07:24:48 -0700203};
mtklein748ca3b2015-01-15 10:56:12 -0800204
205static const bool kMemcpyOK = true;
206
mtkleine0effd62015-07-29 06:37:28 -0700207static SkTArray<TaggedSrc, kMemcpyOK> gSrcs;
208static SkTArray<TaggedSink, kMemcpyOK> gSinks;
mtklein748ca3b2015-01-15 10:56:12 -0800209
mtklein6393c062015-04-27 08:45:01 -0700210static bool in_shard() {
211 static int N = 0;
212 return N++ % FLAGS_shards == FLAGS_shard;
213}
214
msarett9e707a02015-09-01 14:57:57 -0700215static void push_src(ImplicitString tag, ImplicitString options, Src* s) {
mtklein748ca3b2015-01-15 10:56:12 -0800216 SkAutoTDelete<Src> src(s);
mtklein6393c062015-04-27 08:45:01 -0700217 if (in_shard() &&
msarett9e707a02015-09-01 14:57:57 -0700218 FLAGS_src.contains(tag.c_str()) &&
mtklein748ca3b2015-01-15 10:56:12 -0800219 !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) {
mtkleine0effd62015-07-29 06:37:28 -0700220 TaggedSrc& s = gSrcs.push_back();
mtklein748ca3b2015-01-15 10:56:12 -0800221 s.reset(src.detach());
222 s.tag = tag;
djsollen54416de2015-04-03 07:24:48 -0700223 s.options = options;
mtklein114c3cd2015-01-15 10:15:02 -0800224 }
mtklein748ca3b2015-01-15 10:56:12 -0800225}
mtklein114c3cd2015-01-15 10:15:02 -0800226
msarett9e707a02015-09-01 14:57:57 -0700227static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorType dstColorType,
228 float scale) {
229 SkString folder;
230 switch (mode) {
231 case CodecSrc::kCodec_Mode:
232 folder.append("codec");
233 break;
msarett9e707a02015-09-01 14:57:57 -0700234 case CodecSrc::kScanline_Mode:
235 folder.append("scanline");
236 break;
msarett9e707a02015-09-01 14:57:57 -0700237 case CodecSrc::kStripe_Mode:
238 folder.append("stripe");
239 break;
240 case CodecSrc::kSubset_Mode:
msarett36c37962015-09-02 13:20:52 -0700241 folder.append("codec_subset");
msarett9e707a02015-09-01 14:57:57 -0700242 break;
243 }
244
245 switch (dstColorType) {
246 case CodecSrc::kGrayscale_Always_DstColorType:
247 folder.append("_kGray8");
248 break;
249 case CodecSrc::kIndex8_Always_DstColorType:
250 folder.append("_kIndex8");
251 break;
252 default:
253 break;
254 }
255
256 if (1.0f != scale) {
257 folder.appendf("_%.3f", scale);
258 }
259
260 CodecSrc* src = new CodecSrc(path, mode, dstColorType, scale);
261 push_src("image", folder, src);
262}
263
msarett3d9d7a72015-10-21 10:27:10 -0700264static void push_android_codec_src(Path path, AndroidCodecSrc::Mode mode,
265 CodecSrc::DstColorType dstColorType, int sampleSize) {
266 SkString folder;
267 switch (mode) {
268 case AndroidCodecSrc::kFullImage_Mode:
269 folder.append("scaled_codec");
270 break;
271 case AndroidCodecSrc::kDivisor_Mode:
272 folder.append("scaled_codec_divisor");
273 break;
274 }
275
276 switch (dstColorType) {
277 case CodecSrc::kGrayscale_Always_DstColorType:
278 folder.append("_kGray8");
279 break;
280 case CodecSrc::kIndex8_Always_DstColorType:
281 folder.append("_kIndex8");
282 break;
283 default:
284 break;
285 }
286
287 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -0800288 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700289 }
290
291 AndroidCodecSrc* src = new AndroidCodecSrc(path, mode, dstColorType, sampleSize);
292 push_src("image", folder, src);
293}
294
msarett438b2ad2015-04-09 12:43:10 -0700295static void push_codec_srcs(Path path) {
296 SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
297 if (!encoded) {
298 SkDebugf("Couldn't read %s.", path.c_str());
299 return;
300 }
301 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
halcanary96fcdcc2015-08-27 07:41:13 -0700302 if (nullptr == codec.get()) {
msarett438b2ad2015-04-09 12:43:10 -0700303 SkDebugf("Couldn't create codec for %s.", path.c_str());
304 return;
305 }
306
msarett36c37962015-09-02 13:20:52 -0700307 // Native Scales
msarett0a242972015-06-11 14:27:27 -0700308 // TODO (msarett): Implement scaling tests for SkImageDecoder in order to compare with these
309 // tests. SkImageDecoder supports downscales by integer factors.
emmaleer8f4ba762015-08-14 07:44:46 -0700310 // 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 -0700311 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 -0700312
msarett36c37962015-09-02 13:20:52 -0700313 const CodecSrc::Mode nativeModes[] = { CodecSrc::kCodec_Mode, CodecSrc::kScanline_Mode,
msarett5af4e0b2015-11-17 11:18:03 -0800314 CodecSrc::kStripe_Mode, CodecSrc::kSubset_Mode };
msarett9e707a02015-09-01 14:57:57 -0700315
msarett36c37962015-09-02 13:20:52 -0700316 CodecSrc::DstColorType colorTypes[3];
317 uint32_t numColorTypes;
318 switch (codec->getInfo().colorType()) {
319 case kGray_8_SkColorType:
320 // FIXME: Is this a long term solution for testing wbmps decodes to kIndex8?
halcanary6950de62015-11-07 05:29:00 -0800321 // Further discussion on this topic is at https://bug.skia.org/3683 .
msarett3d9d7a72015-10-21 10:27:10 -0700322 // This causes us to try to convert grayscale jpegs to kIndex8. We currently
323 // fail non-fatally in this case.
msarett36c37962015-09-02 13:20:52 -0700324 colorTypes[0] = CodecSrc::kGetFromCanvas_DstColorType;
325 colorTypes[1] = CodecSrc::kGrayscale_Always_DstColorType;
326 colorTypes[2] = CodecSrc::kIndex8_Always_DstColorType;
327 numColorTypes = 3;
328 break;
329 case kIndex_8_SkColorType:
330 colorTypes[0] = CodecSrc::kGetFromCanvas_DstColorType;
331 colorTypes[1] = CodecSrc::kIndex8_Always_DstColorType;
332 numColorTypes = 2;
333 break;
334 default:
335 colorTypes[0] = CodecSrc::kGetFromCanvas_DstColorType;
336 numColorTypes = 1;
337 break;
338 }
msarett9e707a02015-09-01 14:57:57 -0700339
msarett36c37962015-09-02 13:20:52 -0700340 for (float scale : nativeScales) {
msarett36c37962015-09-02 13:20:52 -0700341 for (CodecSrc::Mode mode : nativeModes) {
342 for (uint32_t i = 0; i < numColorTypes; i++) {
343 push_codec_src(path, mode, colorTypes[i], scale);
msarett9e707a02015-09-01 14:57:57 -0700344 }
345 }
msarett0a242972015-06-11 14:27:27 -0700346 }
msarett36c37962015-09-02 13:20:52 -0700347
halcanary6950de62015-11-07 05:29:00 -0800348 // https://bug.skia.org/4428
msarett33c76232015-11-16 13:43:40 -0800349 bool subset = false;
350 // The following image types are supported by BitmapRegionDecoder,
351 // so we will test full image decodes and subset decodes.
msarettbe8216a2015-12-04 08:00:50 -0800352 static const char* const exts[] = {
msarett3d9d7a72015-10-21 10:27:10 -0700353 "jpg", "jpeg", "png", "webp",
354 "JPG", "JPEG", "PNG", "WEBP",
355 };
msarettbe8216a2015-12-04 08:00:50 -0800356 for (const char* ext : exts) {
msarett3d9d7a72015-10-21 10:27:10 -0700357 if (path.endsWith(ext)) {
msarett33c76232015-11-16 13:43:40 -0800358 subset = true;
msarett3d9d7a72015-10-21 10:27:10 -0700359 break;
360 }
361 }
msarett33c76232015-11-16 13:43:40 -0800362
msarett3d9d7a72015-10-21 10:27:10 -0700363 const int sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
msarett36c37962015-09-02 13:20:52 -0700364
msarett3d9d7a72015-10-21 10:27:10 -0700365 for (int sampleSize : sampleSizes) {
msarett33c76232015-11-16 13:43:40 -0800366 for (uint32_t i = 0; i < numColorTypes; i++) {
367 push_android_codec_src(path, AndroidCodecSrc::kFullImage_Mode, colorTypes[i],
368 sampleSize);
369 if (subset) {
370 push_android_codec_src(path, AndroidCodecSrc::kDivisor_Mode, colorTypes[i],
371 sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700372 }
msarett36c37962015-09-02 13:20:52 -0700373 }
374 }
msarett438b2ad2015-04-09 12:43:10 -0700375}
376
msarett5cb48852015-11-06 08:56:32 -0800377static bool brd_color_type_supported(SkBitmapRegionDecoder::Strategy strategy,
msaretta5783ae2015-09-08 15:35:32 -0700378 CodecSrc::DstColorType dstColorType) {
379 switch (strategy) {
msarett5cb48852015-11-06 08:56:32 -0800380 case SkBitmapRegionDecoder::kCanvas_Strategy:
msaretta5783ae2015-09-08 15:35:32 -0700381 if (CodecSrc::kGetFromCanvas_DstColorType == dstColorType) {
382 return true;
383 }
384 return false;
msarett5cb48852015-11-06 08:56:32 -0800385 case SkBitmapRegionDecoder::kAndroidCodec_Strategy:
msarett26ad17b2015-10-22 07:29:19 -0700386 switch (dstColorType) {
387 case CodecSrc::kGetFromCanvas_DstColorType:
388 case CodecSrc::kIndex8_Always_DstColorType:
389 case CodecSrc::kGrayscale_Always_DstColorType:
390 return true;
391 default:
392 return false;
393 }
msaretta5783ae2015-09-08 15:35:32 -0700394 default:
395 SkASSERT(false);
396 return false;
397 }
398}
399
msarett5cb48852015-11-06 08:56:32 -0800400static void push_brd_src(Path path, SkBitmapRegionDecoder::Strategy strategy,
msaretta5783ae2015-09-08 15:35:32 -0700401 CodecSrc::DstColorType dstColorType, BRDSrc::Mode mode, uint32_t sampleSize) {
402 SkString folder;
403 switch (strategy) {
msarett5cb48852015-11-06 08:56:32 -0800404 case SkBitmapRegionDecoder::kCanvas_Strategy:
msaretta5783ae2015-09-08 15:35:32 -0700405 folder.append("brd_canvas");
406 break;
msarett5cb48852015-11-06 08:56:32 -0800407 case SkBitmapRegionDecoder::kAndroidCodec_Strategy:
msarett26ad17b2015-10-22 07:29:19 -0700408 folder.append("brd_android_codec");
409 break;
msaretta5783ae2015-09-08 15:35:32 -0700410 default:
411 SkASSERT(false);
412 return;
413 }
414
415 switch (mode) {
416 case BRDSrc::kFullImage_Mode:
417 break;
418 case BRDSrc::kDivisor_Mode:
419 folder.append("_divisor");
420 break;
421 default:
422 SkASSERT(false);
423 return;
424 }
425
426 switch (dstColorType) {
427 case CodecSrc::kGetFromCanvas_DstColorType:
428 break;
429 case CodecSrc::kIndex8_Always_DstColorType:
430 folder.append("_kIndex");
431 break;
432 case CodecSrc::kGrayscale_Always_DstColorType:
433 folder.append("_kGray");
434 break;
435 default:
436 SkASSERT(false);
437 return;
438 }
439
440 if (1 != sampleSize) {
msarett4b0778e2015-11-13 09:59:11 -0800441 folder.appendf("_%.3f", 1.0f / (float) sampleSize);
msaretta5783ae2015-09-08 15:35:32 -0700442 }
443
444 BRDSrc* src = new BRDSrc(path, strategy, mode, dstColorType, sampleSize);
445 push_src("image", folder, src);
446}
447
448static void push_brd_srcs(Path path) {
449
msarett5cb48852015-11-06 08:56:32 -0800450 const SkBitmapRegionDecoder::Strategy strategies[] = {
451 SkBitmapRegionDecoder::kCanvas_Strategy,
msarett5cb48852015-11-06 08:56:32 -0800452 SkBitmapRegionDecoder::kAndroidCodec_Strategy,
msaretta5783ae2015-09-08 15:35:32 -0700453 };
454
scroggo501b7342015-11-03 07:55:11 -0800455 // Test on a variety of sampleSizes, making sure to include:
456 // - 2, 4, and 8, which are natively supported by jpeg
457 // - multiples of 2 which are not divisible by 4 (analogous for 4)
458 // - larger powers of two, since BRD clients generally use powers of 2
459 // We will only produce output for the larger sizes on large images.
460 const uint32_t sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 64 };
msarett6efbe052015-09-11 09:01:16 -0700461
msaretta5783ae2015-09-08 15:35:32 -0700462 // We will only test to one backend (8888), but we will test all of the
463 // color types that we need to decode to on this backend.
464 const CodecSrc::DstColorType dstColorTypes[] = {
msarett26ad17b2015-10-22 07:29:19 -0700465 CodecSrc::kGetFromCanvas_DstColorType,
466 CodecSrc::kIndex8_Always_DstColorType,
467 CodecSrc::kGrayscale_Always_DstColorType,
msaretta5783ae2015-09-08 15:35:32 -0700468 };
469
470 const BRDSrc::Mode modes[] = {
msarett26ad17b2015-10-22 07:29:19 -0700471 BRDSrc::kFullImage_Mode,
472 BRDSrc::kDivisor_Mode,
msaretta5783ae2015-09-08 15:35:32 -0700473 };
474
msarett5cb48852015-11-06 08:56:32 -0800475 for (SkBitmapRegionDecoder::Strategy strategy : strategies) {
msarett6efbe052015-09-11 09:01:16 -0700476 for (uint32_t sampleSize : sampleSizes) {
msarett6efbe052015-09-11 09:01:16 -0700477 for (CodecSrc::DstColorType dstColorType : dstColorTypes) {
478 if (brd_color_type_supported(strategy, dstColorType)) {
479 for (BRDSrc::Mode mode : modes) {
msaretta5783ae2015-09-08 15:35:32 -0700480 push_brd_src(path, strategy, dstColorType, mode, sampleSize);
481 }
482 }
483 }
484 }
485 }
486}
487
488static bool brd_supported(const char* ext) {
msarett8c8f22a2015-04-01 06:58:48 -0700489 static const char* const exts[] = {
msaretta5783ae2015-09-08 15:35:32 -0700490 "jpg", "jpeg", "png", "webp",
491 "JPG", "JPEG", "PNG", "WEBP",
msarett8c8f22a2015-04-01 06:58:48 -0700492 };
493
494 for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) {
495 if (0 == strcmp(exts[i], ext)) {
496 return true;
497 }
498 }
499 return false;
scroggo9b77ddd2015-03-19 06:03:39 -0700500}
501
mtklein748ca3b2015-01-15 10:56:12 -0800502static void gather_srcs() {
503 for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) {
djsollen54416de2015-04-03 07:24:48 -0700504 push_src("gm", "", new GMSrc(r->factory()));
mtklein748ca3b2015-01-15 10:56:12 -0800505 }
halcanaryfc37ad12015-01-30 07:31:19 -0800506 for (int i = 0; i < FLAGS_skps.count(); i++) {
507 const char* path = FLAGS_skps[i];
508 if (sk_isdir(path)) {
509 SkOSFile::Iter it(path, "skp");
510 for (SkString file; it.next(&file); ) {
djsollen54416de2015-04-03 07:24:48 -0700511 push_src("skp", "", new SKPSrc(SkOSPath::Join(path, file.c_str())));
halcanaryfc37ad12015-01-30 07:31:19 -0800512 }
513 } else {
djsollen54416de2015-04-03 07:24:48 -0700514 push_src("skp", "", new SKPSrc(path));
mtklein114c3cd2015-01-15 10:15:02 -0800515 }
516 }
halcanary23b03c32015-01-30 09:58:58 -0800517 static const char* const exts[] = {
518 "bmp", "gif", "jpg", "jpeg", "png", "webp", "ktx", "astc", "wbmp", "ico",
519 "BMP", "GIF", "JPG", "JPEG", "PNG", "WEBP", "KTX", "ASTC", "WBMP", "ICO",
520 };
521 for (int i = 0; i < FLAGS_images.count(); i++) {
522 const char* flag = FLAGS_images[i];
523 if (sk_isdir(flag)) {
524 for (size_t j = 0; j < SK_ARRAY_COUNT(exts); j++) {
525 SkOSFile::Iter it(flag, exts[j]);
526 for (SkString file; it.next(&file); ) {
527 SkString path = SkOSPath::Join(flag, file.c_str());
djsollen54416de2015-04-03 07:24:48 -0700528 push_src("image", "decode", new ImageSrc(path)); // Decode entire image
msaretta5783ae2015-09-08 15:35:32 -0700529 push_codec_srcs(path);
530 if (brd_supported(exts[j])) {
531 push_brd_srcs(path);
scroggo9b77ddd2015-03-19 06:03:39 -0700532 }
halcanary23b03c32015-01-30 09:58:58 -0800533 }
mtklein114c3cd2015-01-15 10:15:02 -0800534 }
halcanary23b03c32015-01-30 09:58:58 -0800535 } else if (sk_exists(flag)) {
536 // assume that FLAGS_images[i] is a valid image if it is a file.
djsollen54416de2015-04-03 07:24:48 -0700537 push_src("image", "decode", new ImageSrc(flag)); // Decode entire image.
msarett438b2ad2015-04-09 12:43:10 -0700538 push_codec_srcs(flag);
msaretta5783ae2015-09-08 15:35:32 -0700539 push_brd_srcs(flag);
mtklein709d2c32015-01-15 08:30:25 -0800540 }
mtklein709d2c32015-01-15 08:30:25 -0800541 }
542}
543
rmistry0f515bd2015-12-22 10:22:26 -0800544#if SK_SUPPORT_GPU
545static GrGLStandard get_gpu_api() {
546 if (FLAGS_gpuAPI.contains("gl")) { return kGL_GrGLStandard; }
547 if (FLAGS_gpuAPI.contains("gles")) { return kGLES_GrGLStandard; }
548 return kNone_GrGLStandard;
549}
550#endif
kkinnunen9ebc3f02015-12-21 23:48:13 -0800551
rmistry0f515bd2015-12-22 10:22:26 -0800552static void push_sink(const char* tag, Sink* s) {
553 SkAutoTDelete<Sink> sink(s);
554 if (!FLAGS_config.contains(tag)) {
555 return;
556 }
mtkleine0effd62015-07-29 06:37:28 -0700557 // Try a simple Src as a canary. If it fails, skip this sink.
mtklein748ca3b2015-01-15 10:56:12 -0800558 struct : public Src {
mtkleine0effd62015-07-29 06:37:28 -0700559 Error draw(SkCanvas* c) const override {
560 c->drawRect(SkRect::MakeWH(1,1), SkPaint());
561 return "";
562 }
mtklein36352bf2015-03-25 18:17:31 -0700563 SkISize size() const override { return SkISize::Make(16, 16); }
mtkleine0effd62015-07-29 06:37:28 -0700564 Name name() const override { return "justOneRect"; }
565 } justOneRect;
mtklein114c3cd2015-01-15 10:15:02 -0800566
mtklein748ca3b2015-01-15 10:56:12 -0800567 SkBitmap bitmap;
568 SkDynamicMemoryWStream stream;
mtkleinb9eb4ac2015-02-02 18:26:03 -0800569 SkString log;
mtkleine0effd62015-07-29 06:37:28 -0700570 Error err = sink->draw(justOneRect, &bitmap, &stream, &log);
mtklein4089ef72015-03-05 08:40:28 -0800571 if (err.isFatal()) {
rmistry0f515bd2015-12-22 10:22:26 -0800572 SkDebugf("Could not run %s: %s\n", tag, err.c_str());
mtklein05641a52015-04-21 10:49:13 -0700573 exit(1);
mtklein114c3cd2015-01-15 10:15:02 -0800574 }
575
mtkleine0effd62015-07-29 06:37:28 -0700576 TaggedSink& ts = gSinks.push_back();
mtklein748ca3b2015-01-15 10:56:12 -0800577 ts.reset(sink.detach());
rmistry0f515bd2015-12-22 10:22:26 -0800578 ts.tag = tag;
mtklein748ca3b2015-01-15 10:56:12 -0800579}
580
581static bool gpu_supported() {
582#if SK_SUPPORT_GPU
583 return FLAGS_gpu;
584#else
585 return false;
586#endif
587}
rmistry0f515bd2015-12-22 10:22:26 -0800588static Sink* create_gpu_sink(const char* tag, GrContextFactory::GLContextType contextType,
589 GrContextFactory::GLContextOptions contextOptions, int samples,
590 bool diText, bool threaded) {
kkinnunen9ebc3f02015-12-21 23:48:13 -0800591#if SK_SUPPORT_GPU
rmistry0f515bd2015-12-22 10:22:26 -0800592 GrContextFactory testFactory;
593 const GrGLStandard api = get_gpu_api();
594 if (testFactory.get(contextType, api, contextOptions)) {
595 return new GPUSink(contextType, contextOptions, api, samples, diText, threaded);
kkinnunen9ebc3f02015-12-21 23:48:13 -0800596 }
rmistry0f515bd2015-12-22 10:22:26 -0800597 SkDebugf("WARNING: can not create GPU context for config '%s'. GM tests will be skipped.\n", tag);
kkinnunen9ebc3f02015-12-21 23:48:13 -0800598#endif
rmistry0f515bd2015-12-22 10:22:26 -0800599 return nullptr;
600}
601static Sink* create_sink(const char* tag) {
602#define GPU_SINK(t, ...) if (0 == strcmp(t, tag)) { return create_gpu_sink(tag, __VA_ARGS__); }
603 if (gpu_supported()) {
604 typedef GrContextFactory Gr;
605 GPU_SINK("gpunull", Gr::kNull_GLContextType, Gr::kNone_GLContextOptions, 0, false, FLAGS_gpu_threading);
606 GPU_SINK("gpudebug", Gr::kDebug_GLContextType, Gr::kNone_GLContextOptions, 0, false, FLAGS_gpu_threading);
607 GPU_SINK("gpu", Gr::kNative_GLContextType, Gr::kNone_GLContextOptions, 0, false, FLAGS_gpu_threading);
608 GPU_SINK("gpudft", Gr::kNative_GLContextType, Gr::kNone_GLContextOptions, 0, true, FLAGS_gpu_threading);
609 GPU_SINK("msaa4", Gr::kNative_GLContextType, Gr::kNone_GLContextOptions, 4, false, FLAGS_gpu_threading);
610 GPU_SINK("msaa16", Gr::kNative_GLContextType, Gr::kNone_GLContextOptions, 16, false, FLAGS_gpu_threading);
611 GPU_SINK("nvprmsaa4", Gr::kNative_GLContextType, Gr::kEnableNVPR_GLContextOptions, 4, true, FLAGS_gpu_threading);
612 GPU_SINK("nvprmsaa16", Gr::kNative_GLContextType, Gr::kEnableNVPR_GLContextOptions, 16, true, FLAGS_gpu_threading);
613#if SK_ANGLE
614 GPU_SINK("angle", Gr::kANGLE_GLContextType, Gr::kNone_GLContextOptions, 0, false, FLAGS_gpu_threading);
615 GPU_SINK("angle-gl", Gr::kANGLE_GL_GLContextType, Gr::kNone_GLContextOptions, 0, false, FLAGS_gpu_threading);
616#endif
617#if SK_COMMAND_BUFFER
618 GPU_SINK("commandbuffer", Gr::kCommandBuffer_GLContextType, Gr::kNone_GLContextOptions, 0, false, FLAGS_gpu_threading);
619#endif
620#if SK_MESA
621 GPU_SINK("mesa", Gr::kMESA_GLContextType, Gr::kNone_GLContextOptions, 0, false, FLAGS_gpu_threading);
622#endif
623 }
624#undef GPU_SINK
kkinnunen9ebc3f02015-12-21 23:48:13 -0800625
rmistry0f515bd2015-12-22 10:22:26 -0800626#define SINK(t, sink, ...) if (0 == strcmp(t, tag)) { return new sink(__VA_ARGS__); }
tomhudsoneebc39a2015-02-23 12:18:05 -0800627#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
628 SINK("hwui", HWUISink);
629#endif
630
mtklein748ca3b2015-01-15 10:56:12 -0800631 if (FLAGS_cpu) {
632 SINK("565", RasterSink, kRGB_565_SkColorType);
633 SINK("8888", RasterSink, kN32_SkColorType);
halcanaryc11c62f2015-09-28 11:51:54 -0700634 SINK("pdf", PDFSink, "Pdfium");
635 SINK("pdf_poppler", PDFSink, "Poppler");
mtklein9c3f17d2015-01-28 11:35:18 -0800636 SINK("skp", SKPSink);
mtklein8a4527e2015-01-31 20:00:58 -0800637 SINK("svg", SVGSink);
638 SINK("null", NullSink);
halcanary47ef4d52015-03-03 09:13:09 -0800639 SINK("xps", XPSSink);
mtklein748ca3b2015-01-15 10:56:12 -0800640 }
641#undef SINK
halcanary96fcdcc2015-08-27 07:41:13 -0700642 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800643}
644
rmistry0f515bd2015-12-22 10:22:26 -0800645static Sink* create_via(const char* tag, Sink* wrapped) {
646#define VIA(t, via, ...) if (0 == strcmp(t, tag)) { return new via(__VA_ARGS__); }
halcanary96fcdcc2015-08-27 07:41:13 -0700647 VIA("twice", ViaTwice, wrapped);
648 VIA("pipe", ViaPipe, wrapped);
649 VIA("serialize", ViaSerialization, wrapped);
650 VIA("2ndpic", ViaSecondPicture, wrapped);
mtkleind31c13d2015-05-05 12:59:56 -0700651 VIA("sp", ViaSingletonPictures, wrapped);
halcanary96fcdcc2015-08-27 07:41:13 -0700652 VIA("tiles", ViaTiles, 256, 256, nullptr, wrapped);
mtklein7edca212015-01-21 13:18:51 -0800653 VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped);
mtklein2e2ea382015-10-16 10:29:41 -0700654 VIA("remote", ViaRemote, false, wrapped);
655 VIA("remote_cache", ViaRemote, true, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800656
mtkleind603b222015-02-17 11:13:33 -0800657 if (FLAGS_matrix.count() == 4) {
mtklein748ca3b2015-01-15 10:56:12 -0800658 SkMatrix m;
mtkleind603b222015-02-17 11:13:33 -0800659 m.reset();
660 m.setScaleX((SkScalar)atof(FLAGS_matrix[0]));
661 m.setSkewX ((SkScalar)atof(FLAGS_matrix[1]));
662 m.setSkewY ((SkScalar)atof(FLAGS_matrix[2]));
663 m.setScaleY((SkScalar)atof(FLAGS_matrix[3]));
664 VIA("matrix", ViaMatrix, m, wrapped);
665 VIA("upright", ViaUpright, m, wrapped);
mtklein748ca3b2015-01-15 10:56:12 -0800666 }
tomhudson64de1e12015-03-05 08:01:07 -0800667
668#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
669 VIA("androidsdk", ViaAndroidSDK, wrapped);
670#endif
671
mtklein748ca3b2015-01-15 10:56:12 -0800672#undef VIA
halcanary96fcdcc2015-08-27 07:41:13 -0700673 return nullptr;
mtklein114c3cd2015-01-15 10:15:02 -0800674}
675
mtklein748ca3b2015-01-15 10:56:12 -0800676static void gather_sinks() {
rmistry0f515bd2015-12-22 10:22:26 -0800677 for (int i = 0; i < FLAGS_config.count(); i++) {
678 const char* config = FLAGS_config[i];
679 SkTArray<SkString> parts;
680 SkStrSplit(config, "-", &parts);
mtklein748ca3b2015-01-15 10:56:12 -0800681
rmistry0f515bd2015-12-22 10:22:26 -0800682 Sink* sink = nullptr;
683 for (int i = parts.count(); i-- > 0;) {
684 const char* part = parts[i].c_str();
685 Sink* next = (sink == nullptr) ? create_sink(part) : create_via(part, sink);
halcanary96fcdcc2015-08-27 07:41:13 -0700686 if (next == nullptr) {
rmistry0f515bd2015-12-22 10:22:26 -0800687 SkDebugf("Skipping %s: Don't understand '%s'.\n", config, part);
mtklein748ca3b2015-01-15 10:56:12 -0800688 delete sink;
halcanary96fcdcc2015-08-27 07:41:13 -0700689 sink = nullptr;
mtklein748ca3b2015-01-15 10:56:12 -0800690 break;
691 }
692 sink = next;
693 }
694 if (sink) {
695 push_sink(config, sink);
mtklein114c3cd2015-01-15 10:15:02 -0800696 }
697 }
698}
mtklein709d2c32015-01-15 08:30:25 -0800699
mtkleina5114d72015-08-24 13:27:01 -0700700static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) {
701 const int w = bitmap.width(),
702 h = bitmap.height();
703
704 // First get the bitmap into N32 color format. The next step will work only there.
705 if (bitmap.colorType() != kN32_SkColorType) {
706 SkBitmap n32;
707 if (!bitmap.copyTo(&n32, kN32_SkColorType)) {
708 return false;
709 }
710 bitmap = n32;
711 }
712
713 // Convert our N32 bitmap into unpremul RGBA for libpng.
714 SkAutoTMalloc<uint32_t> rgba(w*h);
715 if (!bitmap.readPixels(SkImageInfo::Make(w,h, kRGBA_8888_SkColorType, kUnpremul_SkAlphaType),
716 rgba, 4*w, 0,0)) {
717 return false;
718 }
719
720 // We don't need bitmap anymore. Might as well drop our ref.
mtkleinfccb77d2015-08-24 14:13:29 -0700721 bitmap.reset();
mtkleina5114d72015-08-24 13:27:01 -0700722
mtkleinc64137c2015-08-25 10:56:08 -0700723 FILE* f = fopen(path, "wb");
mtkleina5114d72015-08-24 13:27:01 -0700724 if (!f) { return false; }
725
726 png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr);
727 if (!png) {
728 fclose(f);
729 return false;
730 }
731
732 png_infop info = png_create_info_struct(png);
733 if (!info) {
734 png_destroy_write_struct(&png, &info);
735 fclose(f);
736 return false;
737 }
738
mtkleind69ece62015-09-10 10:37:44 -0700739 SkString description;
740 description.append("Key: ");
741 for (int i = 0; i < FLAGS_key.count(); i++) {
742 description.appendf("%s ", FLAGS_key[i]);
743 }
744 description.append("Properties: ");
745 for (int i = 0; i < FLAGS_properties.count(); i++) {
746 description.appendf("%s ", FLAGS_properties[i]);
747 }
748 description.appendf("MD5: %s", md5);
749
mtkleina5114d72015-08-24 13:27:01 -0700750 png_text text[2];
751 text[0].key = (png_charp)"Author";
752 text[0].text = (png_charp)"DM dump_png()";
753 text[0].compression = PNG_TEXT_COMPRESSION_NONE;
754 text[1].key = (png_charp)"Description";
mtkleind69ece62015-09-10 10:37:44 -0700755 text[1].text = (png_charp)description.c_str();
mtkleina5114d72015-08-24 13:27:01 -0700756 text[1].compression = PNG_TEXT_COMPRESSION_NONE;
757 png_set_text(png, info, text, 2);
758
759 png_init_io(png, f);
760 png_set_IHDR(png, info, (png_uint_32)w, (png_uint_32)h, 8,
761 PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
762 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
763 png_write_info(png, info);
764 for (int j = 0; j < h; j++) {
765 png_bytep row = (png_bytep)(rgba.get() + w*j);
766 png_write_rows(png, &row, 1);
767 }
768 png_write_end(png, info);
769
770 png_destroy_write_struct(&png, &info);
771 fclose(f);
772 return true;
773}
774
mtkleina2ef6422015-01-15 13:44:22 -0800775static bool match(const char* needle, const char* haystack) {
halcanary96fcdcc2015-08-27 07:41:13 -0700776 return 0 == strcmp("_", needle) || nullptr != strstr(haystack, needle);
mtkleina2ef6422015-01-15 13:44:22 -0800777}
778
djsollen54416de2015-04-03 07:24:48 -0700779static ImplicitString is_blacklisted(const char* sink, const char* src,
780 const char* srcOptions, const char* name) {
mtklein0d243ff2015-04-03 07:51:00 -0700781 for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) {
mtkleina2ef6422015-01-15 13:44:22 -0800782 if (match(FLAGS_blacklist[i+0], sink) &&
djsollen54416de2015-04-03 07:24:48 -0700783 match(FLAGS_blacklist[i+1], src) &&
784 match(FLAGS_blacklist[i+2], srcOptions) &&
785 match(FLAGS_blacklist[i+3], name)) {
786 return SkStringPrintf("%s %s %s %s",
787 FLAGS_blacklist[i+0], FLAGS_blacklist[i+1],
788 FLAGS_blacklist[i+2], FLAGS_blacklist[i+3]);
mtkleina2ef6422015-01-15 13:44:22 -0800789 }
790 }
791 return "";
792}
793
mtklein748ca3b2015-01-15 10:56:12 -0800794// The finest-grained unit of work we can run: draw a single Src into a single Sink,
795// report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream.
796struct Task {
mtkleine0effd62015-07-29 06:37:28 -0700797 Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {}
798 const TaggedSrc& src;
799 const TaggedSink& sink;
mtklein748ca3b2015-01-15 10:56:12 -0800800
801 static void Run(Task* task) {
mtkleina2ef6422015-01-15 13:44:22 -0800802 SkString name = task->src->name();
mtkleine0effd62015-07-29 06:37:28 -0700803
804 // We'll skip drawing this Src/Sink pair if:
805 // - the Src vetoes the Sink;
806 // - this Src / Sink combination is on the blacklist;
807 // - it's a dry run.
mtklein99cab4e2015-07-31 06:43:04 -0700808 SkString note(task->src->veto(task->sink->flags()) ? " (veto)" : "");
rmistry0f515bd2015-12-22 10:22:26 -0800809 SkString whyBlacklisted = is_blacklisted(task->sink.tag, task->src.tag.c_str(),
msarett9e707a02015-09-01 14:57:57 -0700810 task->src.options.c_str(), name.c_str());
mtkleinb37cb412015-03-18 05:27:14 -0700811 if (!whyBlacklisted.isEmpty()) {
812 note.appendf(" (--blacklist %s)", whyBlacklisted.c_str());
813 }
mtkleine0effd62015-07-29 06:37:28 -0700814
mtkleinb9eb4ac2015-02-02 18:26:03 -0800815 SkString log;
mtkleinf27f08b2015-11-03 06:54:24 -0800816 auto timerStart = now_ms();
mtkleine0effd62015-07-29 06:37:28 -0700817 if (!FLAGS_dryRun && note.isEmpty()) {
mtklein748ca3b2015-01-15 10:56:12 -0800818 SkBitmap bitmap;
819 SkDynamicMemoryWStream stream;
bsalomon821e10e2015-06-04 14:15:33 -0700820 if (FLAGS_pre_log) {
rmistry0f515bd2015-12-22 10:22:26 -0800821 SkDebugf("\nRunning %s->%s", name.c_str(), task->sink.tag);
bsalomon821e10e2015-06-04 14:15:33 -0700822 }
rmistry0f515bd2015-12-22 10:22:26 -0800823 start(task->sink.tag, task->src.tag, task->src.options, name.c_str());
mtkleinb9eb4ac2015-02-02 18:26:03 -0800824 Error err = task->sink->draw(*task->src, &bitmap, &stream, &log);
mtklein748ca3b2015-01-15 10:56:12 -0800825 if (!err.isEmpty()) {
mtkleinf27f08b2015-11-03 06:54:24 -0800826 auto elapsed = now_ms() - timerStart;
mtklein4089ef72015-03-05 08:40:28 -0800827 if (err.isFatal()) {
djsollen54416de2015-04-03 07:24:48 -0700828 fail(SkStringPrintf("%s %s %s %s: %s",
rmistry0f515bd2015-12-22 10:22:26 -0800829 task->sink.tag,
msarett9e707a02015-09-01 14:57:57 -0700830 task->src.tag.c_str(),
831 task->src.options.c_str(),
mtklein4089ef72015-03-05 08:40:28 -0800832 name.c_str(),
833 err.c_str()));
mtkleinb37cb412015-03-18 05:27:14 -0700834 } else {
835 note.appendf(" (skipped: %s)", err.c_str());
mtklein4089ef72015-03-05 08:40:28 -0800836 }
rmistry0f515bd2015-12-22 10:22:26 -0800837 done(elapsed, task->sink.tag, task->src.tag, task->src.options,
djsollen54416de2015-04-03 07:24:48 -0700838 name, note, log);
mtklein4089ef72015-03-05 08:40:28 -0800839 return;
mtklein748ca3b2015-01-15 10:56:12 -0800840 }
mtklein62bd1a62015-01-27 14:46:26 -0800841 SkAutoTDelete<SkStreamAsset> data(stream.detachAsStream());
842
843 SkString md5;
844 if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) {
845 SkMD5 hash;
846 if (data->getLength()) {
847 hash.writeStream(data, data->getLength());
848 data->rewind();
849 } else {
mtklein38408462015-07-08 07:25:27 -0700850 // If we're BGRA (Linux, Windows), swizzle over to RGBA (Mac, Android).
851 // This helps eliminate multiple 0-pixel-diff hashes on gold.skia.org.
852 // (Android's general slow speed breaks the tie arbitrarily in RGBA's favor.)
853 // We might consider promoting 565 to RGBA too.
854 if (bitmap.colorType() == kBGRA_8888_SkColorType) {
855 SkBitmap swizzle;
856 SkAssertResult(bitmap.copyTo(&swizzle, kRGBA_8888_SkColorType));
857 hash.write(swizzle.getPixels(), swizzle.getSize());
858 } else {
859 hash.write(bitmap.getPixels(), bitmap.getSize());
860 }
mtklein62bd1a62015-01-27 14:46:26 -0800861 }
862 SkMD5::Digest digest;
863 hash.finish(digest);
864 for (int i = 0; i < 16; i++) {
865 md5.appendf("%02x", digest.data[i]);
866 }
867 }
868
869 if (!FLAGS_readPath.isEmpty() &&
rmistry0f515bd2015-12-22 10:22:26 -0800870 !gGold.contains(Gold(task->sink.tag, task->src.tag.c_str(),
msarett9e707a02015-09-01 14:57:57 -0700871 task->src.options.c_str(), name, md5))) {
djsollen54416de2015-04-03 07:24:48 -0700872 fail(SkStringPrintf("%s not found for %s %s %s %s in %s",
mtklein62bd1a62015-01-27 14:46:26 -0800873 md5.c_str(),
rmistry0f515bd2015-12-22 10:22:26 -0800874 task->sink.tag,
msarett9e707a02015-09-01 14:57:57 -0700875 task->src.tag.c_str(),
876 task->src.options.c_str(),
mtklein62bd1a62015-01-27 14:46:26 -0800877 name.c_str(),
878 FLAGS_readPath[0]));
879 }
880
mtkleinb0531a72015-04-07 13:38:48 -0700881 if (!FLAGS_writePath.isEmpty()) {
mtklein748ca3b2015-01-15 10:56:12 -0800882 const char* ext = task->sink->fileExtension();
mtklein62bd1a62015-01-27 14:46:26 -0800883 if (data->getLength()) {
halcanary96fcdcc2015-08-27 07:41:13 -0700884 WriteToDisk(*task, md5, ext, data, data->getLength(), nullptr);
halcanary022afb82015-01-30 11:00:12 -0800885 SkASSERT(bitmap.drawsNothing());
886 } else if (!bitmap.drawsNothing()) {
halcanary96fcdcc2015-08-27 07:41:13 -0700887 WriteToDisk(*task, md5, ext, nullptr, 0, &bitmap);
mtklein748ca3b2015-01-15 10:56:12 -0800888 }
889 }
890 }
rmistry0f515bd2015-12-22 10:22:26 -0800891 done(now_ms()-timerStart, task->sink.tag, task->src.tag.c_str(), task->src.options.c_str(),
mtkleinf27f08b2015-11-03 06:54:24 -0800892 name, note, log);
mtklein748ca3b2015-01-15 10:56:12 -0800893 }
894
895 static void WriteToDisk(const Task& task,
mtklein62bd1a62015-01-27 14:46:26 -0800896 SkString md5,
897 const char* ext,
mtklein748ca3b2015-01-15 10:56:12 -0800898 SkStream* data, size_t len,
mtklein62bd1a62015-01-27 14:46:26 -0800899 const SkBitmap* bitmap) {
mtklein748ca3b2015-01-15 10:56:12 -0800900 JsonWriter::BitmapResult result;
djsollen54416de2015-04-03 07:24:48 -0700901 result.name = task.src->name();
rmistry0f515bd2015-12-22 10:22:26 -0800902 result.config = task.sink.tag;
djsollen54416de2015-04-03 07:24:48 -0700903 result.sourceType = task.src.tag;
904 result.sourceOptions = task.src.options;
905 result.ext = ext;
906 result.md5 = md5;
mtklein748ca3b2015-01-15 10:56:12 -0800907 JsonWriter::AddBitmapResult(result);
908
mtkleinb0531a72015-04-07 13:38:48 -0700909 // If an MD5 is uninteresting, we want it noted in the JSON file,
910 // but don't want to dump it out as a .png (or whatever ext is).
911 if (gUninterestingHashes.contains(md5)) {
912 return;
913 }
914
mtklein748ca3b2015-01-15 10:56:12 -0800915 const char* dir = FLAGS_writePath[0];
916 if (0 == strcmp(dir, "@")) { // Needed for iOS.
917 dir = FLAGS_resourcePath[0];
918 }
919 sk_mkdir(dir);
920
921 SkString path;
922 if (FLAGS_nameByHash) {
923 path = SkOSPath::Join(dir, result.md5.c_str());
924 path.append(".");
925 path.append(ext);
926 if (sk_exists(path.c_str())) {
927 return; // Content-addressed. If it exists already, we're done.
928 }
929 } else {
rmistry0f515bd2015-12-22 10:22:26 -0800930 path = SkOSPath::Join(dir, task.sink.tag);
mtklein748ca3b2015-01-15 10:56:12 -0800931 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -0700932 path = SkOSPath::Join(path.c_str(), task.src.tag.c_str());
mtklein748ca3b2015-01-15 10:56:12 -0800933 sk_mkdir(path.c_str());
msarett9e707a02015-09-01 14:57:57 -0700934 if (strcmp(task.src.options.c_str(), "") != 0) {
935 path = SkOSPath::Join(path.c_str(), task.src.options.c_str());
djsollen54416de2015-04-03 07:24:48 -0700936 sk_mkdir(path.c_str());
937 }
mtklein748ca3b2015-01-15 10:56:12 -0800938 path = SkOSPath::Join(path.c_str(), task.src->name().c_str());
939 path.append(".");
940 path.append(ext);
941 }
942
mtklein748ca3b2015-01-15 10:56:12 -0800943 if (bitmap) {
mtkleina5114d72015-08-24 13:27:01 -0700944 if (!dump_png(*bitmap, path.c_str(), result.md5.c_str())) {
mtklein748ca3b2015-01-15 10:56:12 -0800945 fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str()));
946 return;
947 }
948 } else {
mtkleina5114d72015-08-24 13:27:01 -0700949 SkFILEWStream file(path.c_str());
950 if (!file.isValid()) {
951 fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str()));
952 return;
953 }
mtklein748ca3b2015-01-15 10:56:12 -0800954 if (!file.writeStream(data, len)) {
955 fail(SkStringPrintf("Can't write to %s.\n", path.c_str()));
956 return;
957 }
958 }
959 }
960};
961
962// Run all tasks in the same enclave serially on the same thread.
963// They can't possibly run concurrently with each other.
964static void run_enclave(SkTArray<Task>* tasks) {
965 for (int i = 0; i < tasks->count(); i++) {
966 Task::Run(tasks->begin() + i);
967 }
968}
969
970/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
971
972// Unit tests don't fit so well into the Src/Sink model, so we give them special treatment.
973
mtklein55e88b22015-01-21 15:50:13 -0800974static SkTDArray<skiatest::Test> gThreadedTests, gGPUTests;
mtklein748ca3b2015-01-15 10:56:12 -0800975
976static void gather_tests() {
mtklein6c5fed22015-01-20 13:47:23 -0800977 if (!FLAGS_src.contains("tests")) {
mtklein748ca3b2015-01-15 10:56:12 -0800978 return;
979 }
mtklein6393c062015-04-27 08:45:01 -0700980 for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; r = r->next()) {
981 if (!in_shard()) {
982 continue;
983 }
halcanary87f3ba42015-01-20 09:30:20 -0800984 // Despite its name, factory() is returning a reference to
985 // link-time static const POD data.
986 const skiatest::Test& test = r->factory();
987 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) {
mtklein748ca3b2015-01-15 10:56:12 -0800988 continue;
989 }
halcanary87f3ba42015-01-20 09:30:20 -0800990 if (test.needsGpu && gpu_supported()) {
mtklein55e88b22015-01-21 15:50:13 -0800991 (FLAGS_gpu_threading ? gThreadedTests : gGPUTests).push(test);
halcanary87f3ba42015-01-20 09:30:20 -0800992 } else if (!test.needsGpu && FLAGS_cpu) {
mtklein55e88b22015-01-21 15:50:13 -0800993 gThreadedTests.push(test);
mtklein82d28432015-01-15 12:46:02 -0800994 }
mtklein748ca3b2015-01-15 10:56:12 -0800995 }
996}
997
halcanary87f3ba42015-01-20 09:30:20 -0800998static void run_test(skiatest::Test* test) {
999 struct : public skiatest::Reporter {
mtklein36352bf2015-03-25 18:17:31 -07001000 void reportFailed(const skiatest::Failure& failure) override {
halcanary87f3ba42015-01-20 09:30:20 -08001001 fail(failure.toString());
1002 JsonWriter::AddTestFailure(failure);
1003 }
mtklein36352bf2015-03-25 18:17:31 -07001004 bool allowExtendedTest() const override {
halcanary87f3ba42015-01-20 09:30:20 -08001005 return FLAGS_pathOpsExtended;
1006 }
mtklein36352bf2015-03-25 18:17:31 -07001007 bool verbose() const override { return FLAGS_veryVerbose; }
halcanary87f3ba42015-01-20 09:30:20 -08001008 } reporter;
djsollen824996a2015-06-12 12:06:22 -07001009
1010 SkString note;
1011 SkString whyBlacklisted = is_blacklisted("_", "tests", "_", test->name);
1012 if (!whyBlacklisted.isEmpty()) {
1013 note.appendf(" (--blacklist %s)", whyBlacklisted.c_str());
1014 }
1015
mtkleinf27f08b2015-11-03 06:54:24 -08001016 auto timerStart = now_ms();
djsollen824996a2015-06-12 12:06:22 -07001017 if (!FLAGS_dryRun && whyBlacklisted.isEmpty()) {
djsollen54416de2015-04-03 07:24:48 -07001018 start("unit", "test", "", test->name);
mtklein55e88b22015-01-21 15:50:13 -08001019 GrContextFactory factory;
bsalomon821e10e2015-06-04 14:15:33 -07001020 if (FLAGS_pre_log) {
1021 SkDebugf("\nRunning test %s", test->name);
1022 }
mtklein55e88b22015-01-21 15:50:13 -08001023 test->proc(&reporter, &factory);
mtklein748ca3b2015-01-15 10:56:12 -08001024 }
mtkleinf27f08b2015-11-03 06:54:24 -08001025 done(now_ms()-timerStart, "unit", "test", "", test->name, note, "");
mtklein748ca3b2015-01-15 10:56:12 -08001026}
1027
1028/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
1029
mtklein55e88b22015-01-21 15:50:13 -08001030// If we're isolating all GPU-bound work to one thread (the default), this function runs all that.
1031static void run_enclave_and_gpu_tests(SkTArray<Task>* tasks) {
1032 run_enclave(tasks);
1033 for (int i = 0; i < gGPUTests.count(); i++) {
1034 run_test(&gGPUTests[i]);
1035 }
1036}
1037
mtkleinde6fc2b2015-03-12 06:28:54 -07001038// Some runs (mostly, Valgrind) are so slow that the bot framework thinks we've hung.
1039// This prints something every once in a while so that it knows we're still working.
mtklein2e1c47e2015-03-12 07:16:56 -07001040static void start_keepalive() {
1041 struct Loop {
1042 static void forever(void*) {
1043 for (;;) {
1044 static const int kSec = 300;
1045 #if defined(SK_BUILD_FOR_WIN)
1046 Sleep(kSec * 1000);
1047 #else
1048 sleep(kSec);
1049 #endif
mtkleinb37cb412015-03-18 05:27:14 -07001050 SkString running;
1051 {
mtkleinbc4e0032015-12-09 08:37:35 -08001052 SkAutoMutexAcquire lock(gRunningAndTallyMutex);
mtkleinb37cb412015-03-18 05:27:14 -07001053 for (int i = 0; i < gRunning.count(); i++) {
1054 running.appendf("\n\t%s", gRunning[i].c_str());
1055 }
1056 }
1057 SkDebugf("\nCurrently running:%s\n", running.c_str());
mtklein2e1c47e2015-03-12 07:16:56 -07001058 }
1059 }
1060 };
1061 static SkThread* intentionallyLeaked = new SkThread(Loop::forever);
1062 intentionallyLeaked->start();
mtkleinde6fc2b2015-03-12 06:28:54 -07001063}
1064
caryclark83ca6282015-06-10 09:31:09 -07001065#define PORTABLE_FONT_PREFIX "Toy Liberation "
1066
1067static SkTypeface* create_from_name(const char familyName[], SkTypeface::Style style) {
1068 if (familyName && strlen(familyName) > sizeof(PORTABLE_FONT_PREFIX)
1069 && !strncmp(familyName, PORTABLE_FONT_PREFIX, sizeof(PORTABLE_FONT_PREFIX) - 1)) {
caryclark1818acb2015-07-24 12:09:25 -07001070 return sk_tool_utils::create_portable_typeface(familyName, style);
caryclark83ca6282015-06-10 09:31:09 -07001071 }
halcanary96fcdcc2015-08-27 07:41:13 -07001072 return nullptr;
caryclark83ca6282015-06-10 09:31:09 -07001073}
1074
1075#undef PORTABLE_FONT_PREFIX
1076
1077extern SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style );
1078
jcgregorio3b27ade2014-11-13 08:06:40 -08001079int dm_main();
caryclark17f0b6d2014-07-22 10:15:34 -07001080int dm_main() {
jcgregorio3b27ade2014-11-13 08:06:40 -08001081 SetupCrashHandler();
commit-bot@chromium.org39e8d932014-05-29 20:14:48 +00001082 SkAutoGraphics ag;
mtklein406654b2014-09-03 15:34:37 -07001083 SkTaskGroup::Enabler enabled(FLAGS_threads);
caryclark83ca6282015-06-10 09:31:09 -07001084 gCreateTypefaceDelegate = &create_from_name;
commit-bot@chromium.orga65e2fd2014-05-30 17:23:31 +00001085
mtklein2e1c47e2015-03-12 07:16:56 -07001086 start_keepalive();
mtkleinde6fc2b2015-03-12 06:28:54 -07001087
mtklein62bd1a62015-01-27 14:46:26 -08001088 gather_gold();
borenet09ed4802015-04-03 14:15:33 -07001089 gather_uninteresting_hashes();
mtklein62bd1a62015-01-27 14:46:26 -08001090
mtklein748ca3b2015-01-15 10:56:12 -08001091 gather_srcs();
1092 gather_sinks();
1093 gather_tests();
commit-bot@chromium.org0dc5bd12014-02-26 16:31:22 +00001094
mtklein55e88b22015-01-21 15:50:13 -08001095 gPending = gSrcs.count() * gSinks.count() + gThreadedTests.count() + gGPUTests.count();
mtklein748ca3b2015-01-15 10:56:12 -08001096 SkDebugf("%d srcs * %d sinks + %d tests == %d tasks\n",
mtklein55e88b22015-01-21 15:50:13 -08001097 gSrcs.count(), gSinks.count(), gThreadedTests.count() + gGPUTests.count(), gPending);
mtklein748ca3b2015-01-15 10:56:12 -08001098
1099 // We try to exploit as much parallelism as is safe. Most Src/Sink pairs run on any thread,
1100 // but Sinks that identify as part of a particular enclave run serially on a single thread.
mtklein82d28432015-01-15 12:46:02 -08001101 // CPU tests run on any thread. GPU tests depend on --gpu_threading.
mtklein748ca3b2015-01-15 10:56:12 -08001102 SkTArray<Task> enclaves[kNumEnclaves];
1103 for (int j = 0; j < gSinks.count(); j++) {
1104 SkTArray<Task>& tasks = enclaves[gSinks[j]->enclave()];
1105 for (int i = 0; i < gSrcs.count(); i++) {
1106 tasks.push_back(Task(gSrcs[i], gSinks[j]));
1107 }
commit-bot@chromium.org38aeb0f2014-02-26 23:01:57 +00001108 }
1109
mtklein748ca3b2015-01-15 10:56:12 -08001110 SkTaskGroup tg;
herb30da5f72015-12-10 14:12:33 -08001111 tg.batch([](int i){ run_test(&gThreadedTests[i]); }, gThreadedTests.count());
mtklein55e88b22015-01-21 15:50:13 -08001112 for (int i = 0; i < kNumEnclaves; i++) {
herb30da5f72015-12-10 14:12:33 -08001113 SkTArray<Task>* currentEnclave = &enclaves[i];
mtklein55e88b22015-01-21 15:50:13 -08001114 switch(i) {
1115 case kAnyThread_Enclave:
herb30da5f72015-12-10 14:12:33 -08001116 tg.batch([currentEnclave](int j) { Task::Run(&(*currentEnclave)[j]); }, currentEnclave->count());
mtklein55e88b22015-01-21 15:50:13 -08001117 break;
1118 case kGPU_Enclave:
herb30da5f72015-12-10 14:12:33 -08001119 tg.add([currentEnclave](){ run_enclave_and_gpu_tests(currentEnclave); });
mtklein55e88b22015-01-21 15:50:13 -08001120 break;
1121 default:
herb30da5f72015-12-10 14:12:33 -08001122 tg.add([currentEnclave](){ run_enclave(currentEnclave); });
mtklein55e88b22015-01-21 15:50:13 -08001123 break;
mtklein82d28432015-01-15 12:46:02 -08001124 }
mtklein55e88b22015-01-21 15:50:13 -08001125 }
mtklein748ca3b2015-01-15 10:56:12 -08001126 tg.wait();
mtklein748ca3b2015-01-15 10:56:12 -08001127 // At this point we're back in single-threaded land.
caryclarkf53ce802015-06-15 06:48:30 -07001128 sk_tool_utils::release_portable_typefaces();
mtklein@google.comd36522d2013-10-16 13:02:15 +00001129
mtkleinbc4e0032015-12-09 08:37:35 -08001130 if (FLAGS_verbose && gNoteTally.count() > 0) {
1131 SkDebugf("\nNote tally:\n");
1132 gNoteTally.foreach([](const SkString& note, int* tally) {
1133 SkDebugf("%dx\t%s\n", *tally, note.c_str());
1134 });
1135 }
1136
mtklein2f64eec2015-01-15 14:20:41 -08001137 SkDebugf("\n");
mtklein748ca3b2015-01-15 10:56:12 -08001138 if (gFailures.count() > 0) {
1139 SkDebugf("Failures:\n");
1140 for (int i = 0; i < gFailures.count(); i++) {
mtklein9dc09102015-01-15 15:47:33 -08001141 SkDebugf("\t%s\n", gFailures[i].c_str());
mtklein748ca3b2015-01-15 10:56:12 -08001142 }
1143 SkDebugf("%d failures\n", gFailures.count());
1144 return 1;
mtklein114c3cd2015-01-15 10:15:02 -08001145 }
mtklein748ca3b2015-01-15 10:56:12 -08001146 if (gPending > 0) {
1147 SkDebugf("Hrm, we didn't seem to run everything we intended to! Please file a bug.\n");
1148 return 1;
mtklein114c3cd2015-01-15 10:15:02 -08001149 }
halcanary7a14b312015-10-01 07:28:13 -07001150 #ifdef SK_PDF_IMAGE_STATS
1151 SkPDFImageDumpStats();
1152 #endif // SK_PDF_IMAGE_STATS
mtklein748ca3b2015-01-15 10:56:12 -08001153 return 0;
mtklein@google.comd36522d2013-10-16 13:02:15 +00001154}
jcgregorio3b27ade2014-11-13 08:06:40 -08001155
kkinnunen179a8f52015-11-20 13:32:24 -08001156// TODO: currently many GPU tests are declared outside SK_SUPPORT_GPU guards.
1157// Thus we export the empty RunWithGPUTestContexts when SK_SUPPORT_GPU=0.
1158namespace skiatest {
1159namespace {
1160typedef void(*TestWithGrContext)(skiatest::Reporter*, GrContext*);
1161typedef void(*TestWithGrContextAndGLContext)(skiatest::Reporter*, GrContext*, SkGLContext*);
1162#if SK_SUPPORT_GPU
1163template<typename T>
1164void call_test(T test, skiatest::Reporter* reporter, GrContextFactory::ContextInfo* context);
1165template<>
1166void call_test(TestWithGrContext test, skiatest::Reporter* reporter,
1167 GrContextFactory::ContextInfo* context) {
1168 test(reporter, context->fGrContext);
1169}
1170template<>
1171void call_test(TestWithGrContextAndGLContext test, skiatest::Reporter* reporter,
1172 GrContextFactory::ContextInfo* context) {
1173 test(reporter, context->fGrContext, context->fGLContext);
1174}
1175#endif
1176} // namespace
1177
kkinnunen179a8f52015-11-20 13:32:24 -08001178template<typename T>
1179void RunWithGPUTestContexts(T test, GPUTestContexts testContexts, Reporter* reporter,
1180 GrContextFactory* factory) {
1181#if SK_SUPPORT_GPU
rmistry0f515bd2015-12-22 10:22:26 -08001182 const GrGLStandard api = get_gpu_api();
1183 for (int i = 0; i < GrContextFactory::kGLContextTypeCnt; ++i) {
1184 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContextType) i;
kkinnunen179a8f52015-11-20 13:32:24 -08001185 int contextSelector = kNone_GPUTestContexts;
rmistry0f515bd2015-12-22 10:22:26 -08001186 if (GrContextFactory::IsRenderingGLContext(glCtxType)) {
kkinnunen179a8f52015-11-20 13:32:24 -08001187 contextSelector |= kAllRendering_GPUTestContexts;
rmistry0f515bd2015-12-22 10:22:26 -08001188 } else if (glCtxType == GrContextFactory::kNative_GLContextType) {
kkinnunen179a8f52015-11-20 13:32:24 -08001189 contextSelector |= kNative_GPUTestContexts;
rmistry0f515bd2015-12-22 10:22:26 -08001190 } else if (glCtxType == GrContextFactory::kNull_GLContextType) {
kkinnunen179a8f52015-11-20 13:32:24 -08001191 contextSelector |= kNull_GPUTestContexts;
rmistry0f515bd2015-12-22 10:22:26 -08001192 } else if (glCtxType == GrContextFactory::kDebug_GLContextType) {
kkinnunen55eeae92015-12-10 23:19:29 -08001193 contextSelector |= kDebug_GPUTestContexts;
kkinnunen179a8f52015-11-20 13:32:24 -08001194 }
1195 if ((testContexts & contextSelector) == 0) {
1196 continue;
1197 }
rmistry0f515bd2015-12-22 10:22:26 -08001198 if (GrContextFactory::ContextInfo* context = factory->getContextInfo(glCtxType, api)) {
kkinnunen5219fd92015-12-10 06:28:13 -08001199 call_test(test, reporter, context);
1200 }
1201 if (GrContextFactory::ContextInfo* context =
rmistry0f515bd2015-12-22 10:22:26 -08001202 factory->getContextInfo(glCtxType, api,
1203 GrContextFactory::kEnableNVPR_GLContextOptions)) {
kkinnunen179a8f52015-11-20 13:32:24 -08001204 call_test(test, reporter, context);
1205 }
1206 }
1207#endif
1208}
1209
1210template
1211void RunWithGPUTestContexts<TestWithGrContext>(TestWithGrContext test,
1212 GPUTestContexts testContexts,
1213 Reporter* reporter,
1214 GrContextFactory* factory);
1215template
1216void RunWithGPUTestContexts<TestWithGrContextAndGLContext>(TestWithGrContextAndGLContext test,
1217 GPUTestContexts testContexts,
1218 Reporter* reporter,
1219 GrContextFactory* factory);
1220} // namespace skiatest
1221
borenet48087572015-04-02 12:16:36 -07001222#if !defined(SK_BUILD_FOR_IOS)
jcgregorio3b27ade2014-11-13 08:06:40 -08001223int main(int argc, char** argv) {
1224 SkCommandLineFlags::Parse(argc, argv);
1225 return dm_main();
1226}
1227#endif