scroggo | 478652e | 2015-03-25 07:11:02 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 8 | #include "CrashHandler.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 9 | #include "DMJsonWriter.h" |
| 10 | #include "DMSrcSink.h" |
tomhudson | eebc39a | 2015-02-23 12:18:05 -0800 | [diff] [blame] | 11 | #include "DMSrcSinkAndroid.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 12 | #include "ProcStats.h" |
halcanary | 7d57124 | 2016-02-24 17:59:16 -0800 | [diff] [blame] | 13 | #include "Resources.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 14 | #include "SkBBHFactory.h" |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 15 | #include "SkChecksum.h" |
scroggo | cc2feb1 | 2015-08-14 08:32:46 -0700 | [diff] [blame] | 16 | #include "SkCodec.h" |
mtklein | 27c3fdd | 2016-02-26 14:43:21 -0800 | [diff] [blame] | 17 | #include "SkColorPriv.h" |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 18 | #include "SkCommonFlags.h" |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 19 | #include "SkCommonFlagsConfig.h" |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 20 | #include "SkFontMgr.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 21 | #include "SkGraphics.h" |
mtklein | 27c3fdd | 2016-02-26 14:43:21 -0800 | [diff] [blame] | 22 | #include "SkHalf.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 23 | #include "SkMD5.h" |
mtklein | 1b24933 | 2015-07-07 12:21:21 -0700 | [diff] [blame] | 24 | #include "SkMutex.h" |
mtklein | 1d0f164 | 2014-09-08 08:05:18 -0700 | [diff] [blame] | 25 | #include "SkOSFile.h" |
mtklein | 27c3fdd | 2016-02-26 14:43:21 -0800 | [diff] [blame] | 26 | #include "SkPM4fPriv.h" |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 27 | #include "SkSpinlock.h" |
mtklein | a82f562 | 2015-02-20 12:30:19 -0800 | [diff] [blame] | 28 | #include "SkTHash.h" |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 29 | #include "SkTaskGroup.h" |
mtklein | de6fc2b | 2015-03-12 06:28:54 -0700 | [diff] [blame] | 30 | #include "SkThreadUtils.h" |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 31 | #include "Test.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 32 | #include "Timer.h" |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 33 | #include "sk_tool_utils.h" |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 34 | |
halcanary | 7a14b31 | 2015-10-01 07:28:13 -0700 | [diff] [blame] | 35 | #ifdef SK_PDF_IMAGE_STATS |
| 36 | extern void SkPDFImageDumpStats(); |
| 37 | #endif |
| 38 | |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 39 | #include "png.h" |
| 40 | |
bungeman | 60e0fee | 2015-08-26 05:15:46 -0700 | [diff] [blame] | 41 | #include <stdlib.h> |
| 42 | |
scroggo | 27a5834 | 2015-10-28 08:56:41 -0700 | [diff] [blame] | 43 | #ifndef SK_BUILD_FOR_WIN32 |
| 44 | #include <unistd.h> |
| 45 | #endif |
| 46 | |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 47 | DEFINE_string(src, "tests gm skp image", "Source types to test."); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 48 | DEFINE_bool(nameByHash, false, |
| 49 | "If true, write to FLAGS_writePath[0]/<hash>.png instead of " |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 50 | "to FLAGS_writePath[0]/<config>/<sourceType>/<sourceOptions>/<name>.png"); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 51 | DEFINE_bool2(pathOpsExtended, x, false, "Run extended pathOps tests."); |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 52 | DEFINE_string(matrix, "1 0 0 1", |
| 53 | "2x2 scale+skew matrix to apply or upright when using " |
| 54 | "'matrix' or 'upright' in config."); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 55 | DEFINE_bool(gpu_threading, false, "Allow GPU work to run on multiple threads?"); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 56 | |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 57 | DEFINE_string(blacklist, "", |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 58 | "Space-separated config/src/srcOptions/name quadruples to blacklist. '_' matches anything. E.g. \n" |
| 59 | "'--blacklist gpu skp _ _' will blacklist all SKPs drawn into the gpu config.\n" |
| 60 | "'--blacklist gpu skp _ _ 8888 gm _ aarects' will also blacklist the aarects GM on 8888."); |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 61 | |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 62 | DEFINE_string2(readPath, r, "", "If set check for equality with golden results in this directory."); |
| 63 | |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 64 | DEFINE_string(uninterestingHashesFile, "", |
| 65 | "File containing a list of uninteresting hashes. If a result hashes to something in " |
| 66 | "this list, no image is written for that result."); |
| 67 | |
mtklein | 6393c06 | 2015-04-27 08:45:01 -0700 | [diff] [blame] | 68 | DEFINE_int32(shards, 1, "We're splitting source data into this many shards."); |
| 69 | DEFINE_int32(shard, 0, "Which shard do I run?"); |
scroggo | e449984 | 2016-02-25 11:03:47 -0800 | [diff] [blame] | 70 | DEFINE_bool(simpleCodec, false, "Only decode images to native scale"); |
mtklein | 6393c06 | 2015-04-27 08:45:01 -0700 | [diff] [blame] | 71 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 72 | using namespace DM; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 73 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 74 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 75 | |
| 76 | SK_DECLARE_STATIC_MUTEX(gFailuresMutex); |
| 77 | static SkTArray<SkString> gFailures; |
| 78 | |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 79 | static void fail(const SkString& err) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 80 | SkAutoMutexAcquire lock(gFailuresMutex); |
| 81 | SkDebugf("\n\nFAILURE: %s\n\n", err.c_str()); |
| 82 | gFailures.push_back(err); |
halcanary | 9e398f7 | 2015-01-10 11:18:04 -0800 | [diff] [blame] | 83 | } |
| 84 | |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 85 | |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 86 | // We use a spinlock to make locking this in a signal handler _somewhat_ safe. |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 87 | SK_DECLARE_STATIC_SPINLOCK(gMutex); |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 88 | static int32_t gPending; |
| 89 | static SkTArray<SkString> gRunning; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 90 | |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 91 | static void done(const char* config, const char* src, const char* srcOptions, const char* name) { |
| 92 | SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name); |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 93 | int pending; |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 94 | { |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 95 | SkAutoTAcquire<SkPODSpinlock> lock(gMutex); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 96 | for (int i = 0; i < gRunning.count(); i++) { |
| 97 | if (gRunning[i] == id) { |
| 98 | gRunning.removeShuffle(i); |
| 99 | break; |
| 100 | } |
| 101 | } |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 102 | pending = --gPending; |
reed | 50bc051 | 2015-05-19 14:13:31 -0700 | [diff] [blame] | 103 | } |
mtklein | a17241b | 2015-01-23 05:48:00 -0800 | [diff] [blame] | 104 | // We write our dm.json file every once in a while in case we crash. |
| 105 | // Notice this also handles the final dm.json when pending == 0. |
| 106 | if (pending % 500 == 0) { |
| 107 | JsonWriter::DumpJson(); |
| 108 | } |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 109 | } |
| 110 | |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 111 | static void start(const char* config, const char* src, const char* srcOptions, const char* name) { |
| 112 | SkString id = SkStringPrintf("%s %s %s %s", config, src, srcOptions, name); |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 113 | SkAutoTAcquire<SkPODSpinlock> lock(gMutex); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 114 | gRunning.push_back(id); |
| 115 | } |
| 116 | |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 117 | static void print_status() { |
| 118 | static SkMSec start_ms = SkTime::GetMSecs(); |
| 119 | |
| 120 | int curr = sk_tools::getCurrResidentSetSizeMB(), |
| 121 | peak = sk_tools::getMaxResidentSetSizeMB(); |
| 122 | SkString elapsed = HumanizeMs(SkTime::GetMSecs() - start_ms); |
| 123 | |
| 124 | SkAutoTAcquire<SkPODSpinlock> lock(gMutex); |
| 125 | SkDebugf("\n%s elapsed, %d active, %d queued, %dMB RAM, %dMB peak\n", |
| 126 | elapsed.c_str(), gRunning.count(), gPending - gRunning.count(), curr, peak); |
| 127 | for (auto& task : gRunning) { |
| 128 | SkDebugf("\t%s\n", task.c_str()); |
| 129 | } |
| 130 | } |
| 131 | |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 132 | #if defined(SK_BUILD_FOR_WIN32) |
| 133 | static void setup_crash_handler() { |
| 134 | // TODO: custom crash handler like below to print out what was running |
| 135 | SetupCrashHandler(); |
| 136 | } |
| 137 | |
| 138 | #else |
| 139 | #include <signal.h> |
| 140 | static void setup_crash_handler() { |
| 141 | const int kSignals[] = { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV }; |
| 142 | for (int sig : kSignals) { |
| 143 | signal(sig, [](int sig) { |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 144 | SkDebugf("\nCaught signal %d [%s].\n", sig, strsignal(sig)); |
| 145 | print_status(); |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 146 | }); |
| 147 | } |
| 148 | } |
| 149 | #endif |
| 150 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 151 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 152 | |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 153 | struct Gold : public SkString { |
mtklein | a82f562 | 2015-02-20 12:30:19 -0800 | [diff] [blame] | 154 | Gold() : SkString("") {} |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 155 | Gold(const SkString& sink, const SkString& src, |
| 156 | const SkString& srcOptions, const SkString& name, |
| 157 | const SkString& md5) |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 158 | : SkString("") { |
| 159 | this->append(sink); |
| 160 | this->append(src); |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 161 | this->append(srcOptions); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 162 | this->append(name); |
| 163 | this->append(md5); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 164 | } |
mtklein | c8d1dd4 | 2015-10-15 12:23:01 -0700 | [diff] [blame] | 165 | struct Hash { |
| 166 | uint32_t operator()(const Gold& g) const { |
| 167 | return SkGoodHash()((const SkString&)g); |
| 168 | } |
| 169 | }; |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 170 | }; |
mtklein | a82f562 | 2015-02-20 12:30:19 -0800 | [diff] [blame] | 171 | static SkTHashSet<Gold, Gold::Hash> gGold; |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 172 | |
| 173 | static void add_gold(JsonWriter::BitmapResult r) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 174 | gGold.add(Gold(r.config, r.sourceType, r.sourceOptions, r.name, r.md5)); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | static void gather_gold() { |
| 178 | if (!FLAGS_readPath.isEmpty()) { |
| 179 | SkString path(FLAGS_readPath[0]); |
| 180 | path.append("/dm.json"); |
| 181 | if (!JsonWriter::ReadJson(path.c_str(), add_gold)) { |
| 182 | fail(SkStringPrintf("Couldn't read %s for golden results.", path.c_str())); |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 188 | |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 189 | static SkTHashSet<SkString> gUninterestingHashes; |
| 190 | |
| 191 | static void gather_uninteresting_hashes() { |
| 192 | if (!FLAGS_uninterestingHashesFile.isEmpty()) { |
| 193 | SkAutoTUnref<SkData> data(SkData::NewFromFileName(FLAGS_uninterestingHashesFile[0])); |
mtklein | cc334b3 | 2015-09-22 11:43:53 -0700 | [diff] [blame] | 194 | if (!data) { |
| 195 | SkDebugf("WARNING: unable to read uninteresting hashes from %s\n", |
| 196 | FLAGS_uninterestingHashesFile[0]); |
| 197 | return; |
| 198 | } |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 199 | SkTArray<SkString> hashes; |
| 200 | SkStrSplit((const char*)data->data(), "\n", &hashes); |
| 201 | for (const SkString& hash : hashes) { |
| 202 | gUninterestingHashes.add(hash); |
| 203 | } |
mtklein | 136baaa | 2016-02-03 11:21:45 -0800 | [diff] [blame] | 204 | SkDebugf("FYI: loaded %d distinct uninteresting hashes from %d lines\n", |
| 205 | gUninterestingHashes.count(), hashes.count()); |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 206 | } |
| 207 | } |
| 208 | |
| 209 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 210 | |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 211 | struct TaggedSrc : public SkAutoTDelete<Src> { |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 212 | SkString tag; |
| 213 | SkString options; |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 214 | }; |
| 215 | |
| 216 | struct TaggedSink : public SkAutoTDelete<Sink> { |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 217 | SkString tag; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 218 | }; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 219 | |
| 220 | static const bool kMemcpyOK = true; |
| 221 | |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 222 | static SkTArray<TaggedSrc, kMemcpyOK> gSrcs; |
| 223 | static SkTArray<TaggedSink, kMemcpyOK> gSinks; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 224 | |
mtklein | 6393c06 | 2015-04-27 08:45:01 -0700 | [diff] [blame] | 225 | static bool in_shard() { |
| 226 | static int N = 0; |
| 227 | return N++ % FLAGS_shards == FLAGS_shard; |
| 228 | } |
| 229 | |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 230 | static void push_src(const char* tag, ImplicitString options, Src* s) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 231 | SkAutoTDelete<Src> src(s); |
mtklein | 6393c06 | 2015-04-27 08:45:01 -0700 | [diff] [blame] | 232 | if (in_shard() && |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 233 | FLAGS_src.contains(tag) && |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 234 | !SkCommandLineFlags::ShouldSkip(FLAGS_match, src->name().c_str())) { |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 235 | TaggedSrc& s = gSrcs.push_back(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 236 | s.reset(src.detach()); |
| 237 | s.tag = tag; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 238 | s.options = options; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 239 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 240 | } |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 241 | |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 242 | static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorType dstColorType, |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 243 | SkAlphaType dstAlphaType, float scale) { |
scroggo | e449984 | 2016-02-25 11:03:47 -0800 | [diff] [blame] | 244 | if (FLAGS_simpleCodec) { |
| 245 | if (mode != CodecSrc::kCodec_Mode || dstColorType != CodecSrc::kGetFromCanvas_DstColorType |
| 246 | || scale != 1.0f) |
| 247 | // Only decode in the simple case. |
| 248 | return; |
| 249 | } |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 250 | SkString folder; |
| 251 | switch (mode) { |
| 252 | case CodecSrc::kCodec_Mode: |
| 253 | folder.append("codec"); |
| 254 | break; |
msarett | bb25b53 | 2016-01-13 09:31:39 -0800 | [diff] [blame] | 255 | case CodecSrc::kCodecZeroInit_Mode: |
| 256 | folder.append("codec_zero_init"); |
| 257 | break; |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 258 | case CodecSrc::kScanline_Mode: |
| 259 | folder.append("scanline"); |
| 260 | break; |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 261 | case CodecSrc::kStripe_Mode: |
| 262 | folder.append("stripe"); |
| 263 | break; |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 264 | case CodecSrc::kCroppedScanline_Mode: |
| 265 | folder.append("crop"); |
| 266 | break; |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 267 | case CodecSrc::kSubset_Mode: |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 268 | folder.append("codec_subset"); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 269 | break; |
msarett | b714fb0 | 2016-01-22 14:46:42 -0800 | [diff] [blame] | 270 | case CodecSrc::kGen_Mode: |
| 271 | folder.append("gen"); |
| 272 | break; |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | switch (dstColorType) { |
| 276 | case CodecSrc::kGrayscale_Always_DstColorType: |
| 277 | folder.append("_kGray8"); |
| 278 | break; |
| 279 | case CodecSrc::kIndex8_Always_DstColorType: |
| 280 | folder.append("_kIndex8"); |
| 281 | break; |
| 282 | default: |
| 283 | break; |
| 284 | } |
| 285 | |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 286 | switch (dstAlphaType) { |
| 287 | case kOpaque_SkAlphaType: |
| 288 | folder.append("_opaque"); |
| 289 | break; |
| 290 | case kPremul_SkAlphaType: |
| 291 | folder.append("_premul"); |
| 292 | break; |
| 293 | case kUnpremul_SkAlphaType: |
| 294 | folder.append("_unpremul"); |
| 295 | break; |
| 296 | default: |
| 297 | break; |
| 298 | } |
| 299 | |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 300 | if (1.0f != scale) { |
| 301 | folder.appendf("_%.3f", scale); |
| 302 | } |
| 303 | |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 304 | CodecSrc* src = new CodecSrc(path, mode, dstColorType, dstAlphaType, scale); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 305 | push_src("image", folder, src); |
| 306 | } |
| 307 | |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 308 | static void push_android_codec_src(Path path, AndroidCodecSrc::Mode mode, |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 309 | CodecSrc::DstColorType dstColorType, SkAlphaType dstAlphaType, int sampleSize) { |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 310 | SkString folder; |
| 311 | switch (mode) { |
| 312 | case AndroidCodecSrc::kFullImage_Mode: |
| 313 | folder.append("scaled_codec"); |
| 314 | break; |
| 315 | case AndroidCodecSrc::kDivisor_Mode: |
| 316 | folder.append("scaled_codec_divisor"); |
| 317 | break; |
| 318 | } |
| 319 | |
| 320 | switch (dstColorType) { |
| 321 | case CodecSrc::kGrayscale_Always_DstColorType: |
| 322 | folder.append("_kGray8"); |
| 323 | break; |
| 324 | case CodecSrc::kIndex8_Always_DstColorType: |
| 325 | folder.append("_kIndex8"); |
| 326 | break; |
| 327 | default: |
| 328 | break; |
| 329 | } |
| 330 | |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 331 | switch (dstAlphaType) { |
| 332 | case kOpaque_SkAlphaType: |
| 333 | folder.append("_opaque"); |
| 334 | break; |
| 335 | case kPremul_SkAlphaType: |
| 336 | folder.append("_premul"); |
| 337 | break; |
msarett | 9e9444c | 2016-02-03 12:39:10 -0800 | [diff] [blame] | 338 | case kUnpremul_SkAlphaType: |
| 339 | folder.append("_unpremul"); |
| 340 | break; |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 341 | default: |
| 342 | break; |
| 343 | } |
| 344 | |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 345 | if (1 != sampleSize) { |
msarett | 4b0778e | 2015-11-13 09:59:11 -0800 | [diff] [blame] | 346 | folder.appendf("_%.3f", 1.0f / (float) sampleSize); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 347 | } |
| 348 | |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 349 | AndroidCodecSrc* src = new AndroidCodecSrc(path, mode, dstColorType, dstAlphaType, sampleSize); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 350 | push_src("image", folder, src); |
| 351 | } |
| 352 | |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 353 | static void push_codec_srcs(Path path) { |
| 354 | SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); |
| 355 | if (!encoded) { |
| 356 | SkDebugf("Couldn't read %s.", path.c_str()); |
| 357 | return; |
| 358 | } |
| 359 | SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 360 | if (nullptr == codec.get()) { |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 361 | SkDebugf("Couldn't create codec for %s.", path.c_str()); |
| 362 | return; |
| 363 | } |
| 364 | |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 365 | // Native Scales |
emmaleer | 8f4ba76 | 2015-08-14 07:44:46 -0700 | [diff] [blame] | 366 | // SkJpegCodec natively supports scaling to: 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875 |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 367 | const float nativeScales[] = { 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.750f, 0.875f, 1.0f }; |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 368 | |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 369 | SkTArray<CodecSrc::Mode> nativeModes; |
| 370 | nativeModes.push_back(CodecSrc::kCodec_Mode); |
| 371 | nativeModes.push_back(CodecSrc::kCodecZeroInit_Mode); |
| 372 | nativeModes.push_back(CodecSrc::kGen_Mode); |
| 373 | switch (codec->getEncodedFormat()) { |
| 374 | case SkEncodedFormat::kJPEG_SkEncodedFormat: |
| 375 | nativeModes.push_back(CodecSrc::kScanline_Mode); |
| 376 | nativeModes.push_back(CodecSrc::kStripe_Mode); |
| 377 | nativeModes.push_back(CodecSrc::kCroppedScanline_Mode); |
| 378 | break; |
| 379 | case SkEncodedFormat::kWEBP_SkEncodedFormat: |
| 380 | nativeModes.push_back(CodecSrc::kSubset_Mode); |
| 381 | break; |
msarett | b65e604 | 2016-02-23 05:37:25 -0800 | [diff] [blame] | 382 | case SkEncodedFormat::kRAW_SkEncodedFormat: |
| 383 | break; |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 384 | default: |
| 385 | nativeModes.push_back(CodecSrc::kScanline_Mode); |
| 386 | nativeModes.push_back(CodecSrc::kStripe_Mode); |
| 387 | break; |
| 388 | } |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 389 | |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 390 | SkTArray<CodecSrc::DstColorType> colorTypes; |
| 391 | colorTypes.push_back(CodecSrc::kGetFromCanvas_DstColorType); |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 392 | switch (codec->getInfo().colorType()) { |
| 393 | case kGray_8_SkColorType: |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 394 | colorTypes.push_back(CodecSrc::kGrayscale_Always_DstColorType); |
msarett | 55f7bdd | 2016-02-16 13:24:54 -0800 | [diff] [blame] | 395 | if (kWBMP_SkEncodedFormat == codec->getEncodedFormat()) { |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 396 | colorTypes.push_back(CodecSrc::kIndex8_Always_DstColorType); |
msarett | 55f7bdd | 2016-02-16 13:24:54 -0800 | [diff] [blame] | 397 | } |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 398 | break; |
| 399 | case kIndex_8_SkColorType: |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 400 | colorTypes.push_back(CodecSrc::kIndex8_Always_DstColorType); |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 401 | break; |
| 402 | default: |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 403 | break; |
| 404 | } |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 405 | |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 406 | SkTArray<SkAlphaType> alphaModes; |
| 407 | alphaModes.push_back(kPremul_SkAlphaType); |
msarett | 9e9444c | 2016-02-03 12:39:10 -0800 | [diff] [blame] | 408 | alphaModes.push_back(kUnpremul_SkAlphaType); |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 409 | if (codec->getInfo().alphaType() == kOpaque_SkAlphaType) { |
| 410 | alphaModes.push_back(kOpaque_SkAlphaType); |
| 411 | } |
msarett | b714fb0 | 2016-01-22 14:46:42 -0800 | [diff] [blame] | 412 | |
| 413 | for (CodecSrc::Mode mode : nativeModes) { |
| 414 | // SkCodecImageGenerator only runs for the default colorType |
| 415 | // recommended by SkCodec. There is no need to generate multiple |
| 416 | // tests for different colorTypes. |
| 417 | // TODO (msarett): Add scaling support to SkCodecImageGenerator. |
| 418 | if (CodecSrc::kGen_Mode == mode) { |
| 419 | // FIXME: The gpu backend does not draw kGray sources correctly. (skbug.com/4822) |
| 420 | if (kGray_8_SkColorType != codec->getInfo().colorType()) { |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 421 | push_codec_src(path, mode, CodecSrc::kGetFromCanvas_DstColorType, |
| 422 | codec->getInfo().alphaType(), 1.0f); |
msarett | b714fb0 | 2016-01-22 14:46:42 -0800 | [diff] [blame] | 423 | } |
| 424 | continue; |
| 425 | } |
| 426 | |
| 427 | for (float scale : nativeScales) { |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 428 | for (CodecSrc::DstColorType colorType : colorTypes) { |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 429 | for (SkAlphaType alphaType : alphaModes) { |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 430 | // Only test kCroppedScanline_Mode when the alpha type is opaque. The test is |
| 431 | // slow and won't be interestingly different with different alpha types. |
| 432 | if (CodecSrc::kCroppedScanline_Mode == mode && |
| 433 | kOpaque_SkAlphaType != alphaType) { |
| 434 | continue; |
| 435 | } |
| 436 | |
| 437 | push_codec_src(path, mode, colorType, alphaType, scale); |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 438 | } |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 439 | } |
| 440 | } |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 441 | } |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 442 | |
scroggo | e449984 | 2016-02-25 11:03:47 -0800 | [diff] [blame] | 443 | if (FLAGS_simpleCodec) { |
| 444 | return; |
| 445 | } |
| 446 | |
halcanary | 6950de6 | 2015-11-07 05:29:00 -0800 | [diff] [blame] | 447 | // https://bug.skia.org/4428 |
msarett | 33c7623 | 2015-11-16 13:43:40 -0800 | [diff] [blame] | 448 | bool subset = false; |
| 449 | // The following image types are supported by BitmapRegionDecoder, |
| 450 | // so we will test full image decodes and subset decodes. |
msarett | be8216a | 2015-12-04 08:00:50 -0800 | [diff] [blame] | 451 | static const char* const exts[] = { |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 452 | "jpg", "jpeg", "png", "webp", |
| 453 | "JPG", "JPEG", "PNG", "WEBP", |
| 454 | }; |
msarett | be8216a | 2015-12-04 08:00:50 -0800 | [diff] [blame] | 455 | for (const char* ext : exts) { |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 456 | if (path.endsWith(ext)) { |
msarett | 33c7623 | 2015-11-16 13:43:40 -0800 | [diff] [blame] | 457 | subset = true; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 458 | break; |
| 459 | } |
| 460 | } |
msarett | 33c7623 | 2015-11-16 13:43:40 -0800 | [diff] [blame] | 461 | |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 462 | const int sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 463 | |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 464 | for (int sampleSize : sampleSizes) { |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 465 | for (CodecSrc::DstColorType colorType : colorTypes) { |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 466 | for (SkAlphaType alphaType : alphaModes) { |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 467 | push_android_codec_src(path, AndroidCodecSrc::kFullImage_Mode, colorType, |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 468 | alphaType, sampleSize); |
| 469 | if (subset) { |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 470 | push_android_codec_src(path, AndroidCodecSrc::kDivisor_Mode, colorType, |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 471 | alphaType, sampleSize); |
| 472 | } |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 473 | } |
msarett | 36c3796 | 2015-09-02 13:20:52 -0700 | [diff] [blame] | 474 | } |
| 475 | } |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 476 | } |
| 477 | |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 478 | static bool brd_color_type_supported(SkBitmapRegionDecoder::Strategy strategy, |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 479 | CodecSrc::DstColorType dstColorType) { |
| 480 | switch (strategy) { |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 481 | case SkBitmapRegionDecoder::kCanvas_Strategy: |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 482 | if (CodecSrc::kGetFromCanvas_DstColorType == dstColorType) { |
| 483 | return true; |
| 484 | } |
| 485 | return false; |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 486 | case SkBitmapRegionDecoder::kAndroidCodec_Strategy: |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 487 | switch (dstColorType) { |
| 488 | case CodecSrc::kGetFromCanvas_DstColorType: |
| 489 | case CodecSrc::kIndex8_Always_DstColorType: |
| 490 | case CodecSrc::kGrayscale_Always_DstColorType: |
| 491 | return true; |
| 492 | default: |
| 493 | return false; |
| 494 | } |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 495 | default: |
| 496 | SkASSERT(false); |
| 497 | return false; |
| 498 | } |
| 499 | } |
| 500 | |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 501 | static void push_brd_src(Path path, SkBitmapRegionDecoder::Strategy strategy, |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 502 | CodecSrc::DstColorType dstColorType, BRDSrc::Mode mode, uint32_t sampleSize) { |
| 503 | SkString folder; |
| 504 | switch (strategy) { |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 505 | case SkBitmapRegionDecoder::kCanvas_Strategy: |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 506 | folder.append("brd_canvas"); |
| 507 | break; |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 508 | case SkBitmapRegionDecoder::kAndroidCodec_Strategy: |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 509 | folder.append("brd_android_codec"); |
| 510 | break; |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 511 | default: |
| 512 | SkASSERT(false); |
| 513 | return; |
| 514 | } |
| 515 | |
| 516 | switch (mode) { |
| 517 | case BRDSrc::kFullImage_Mode: |
| 518 | break; |
| 519 | case BRDSrc::kDivisor_Mode: |
| 520 | folder.append("_divisor"); |
| 521 | break; |
| 522 | default: |
| 523 | SkASSERT(false); |
| 524 | return; |
| 525 | } |
| 526 | |
| 527 | switch (dstColorType) { |
| 528 | case CodecSrc::kGetFromCanvas_DstColorType: |
| 529 | break; |
| 530 | case CodecSrc::kIndex8_Always_DstColorType: |
| 531 | folder.append("_kIndex"); |
| 532 | break; |
| 533 | case CodecSrc::kGrayscale_Always_DstColorType: |
| 534 | folder.append("_kGray"); |
| 535 | break; |
| 536 | default: |
| 537 | SkASSERT(false); |
| 538 | return; |
| 539 | } |
| 540 | |
| 541 | if (1 != sampleSize) { |
msarett | 4b0778e | 2015-11-13 09:59:11 -0800 | [diff] [blame] | 542 | folder.appendf("_%.3f", 1.0f / (float) sampleSize); |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | BRDSrc* src = new BRDSrc(path, strategy, mode, dstColorType, sampleSize); |
| 546 | push_src("image", folder, src); |
| 547 | } |
| 548 | |
| 549 | static void push_brd_srcs(Path path) { |
| 550 | |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 551 | const SkBitmapRegionDecoder::Strategy strategies[] = { |
| 552 | SkBitmapRegionDecoder::kCanvas_Strategy, |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 553 | SkBitmapRegionDecoder::kAndroidCodec_Strategy, |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 554 | }; |
| 555 | |
scroggo | 501b734 | 2015-11-03 07:55:11 -0800 | [diff] [blame] | 556 | // Test on a variety of sampleSizes, making sure to include: |
| 557 | // - 2, 4, and 8, which are natively supported by jpeg |
| 558 | // - multiples of 2 which are not divisible by 4 (analogous for 4) |
| 559 | // - larger powers of two, since BRD clients generally use powers of 2 |
| 560 | // We will only produce output for the larger sizes on large images. |
| 561 | const uint32_t sampleSizes[] = { 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 24, 32, 64 }; |
msarett | 6efbe05 | 2015-09-11 09:01:16 -0700 | [diff] [blame] | 562 | |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 563 | // We will only test to one backend (8888), but we will test all of the |
| 564 | // color types that we need to decode to on this backend. |
| 565 | const CodecSrc::DstColorType dstColorTypes[] = { |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 566 | CodecSrc::kGetFromCanvas_DstColorType, |
| 567 | CodecSrc::kIndex8_Always_DstColorType, |
| 568 | CodecSrc::kGrayscale_Always_DstColorType, |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 569 | }; |
| 570 | |
| 571 | const BRDSrc::Mode modes[] = { |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 572 | BRDSrc::kFullImage_Mode, |
| 573 | BRDSrc::kDivisor_Mode, |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 574 | }; |
| 575 | |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 576 | for (SkBitmapRegionDecoder::Strategy strategy : strategies) { |
msarett | 6efbe05 | 2015-09-11 09:01:16 -0700 | [diff] [blame] | 577 | for (uint32_t sampleSize : sampleSizes) { |
msarett | 6efbe05 | 2015-09-11 09:01:16 -0700 | [diff] [blame] | 578 | for (CodecSrc::DstColorType dstColorType : dstColorTypes) { |
| 579 | if (brd_color_type_supported(strategy, dstColorType)) { |
| 580 | for (BRDSrc::Mode mode : modes) { |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 581 | push_brd_src(path, strategy, dstColorType, mode, sampleSize); |
| 582 | } |
| 583 | } |
| 584 | } |
| 585 | } |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | static bool brd_supported(const char* ext) { |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 590 | static const char* const exts[] = { |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 591 | "jpg", "jpeg", "png", "webp", |
| 592 | "JPG", "JPEG", "PNG", "WEBP", |
msarett | 8c8f22a | 2015-04-01 06:58:48 -0700 | [diff] [blame] | 593 | }; |
| 594 | |
| 595 | for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) { |
| 596 | if (0 == strcmp(exts[i], ext)) { |
| 597 | return true; |
| 598 | } |
| 599 | } |
| 600 | return false; |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 601 | } |
| 602 | |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 603 | static bool gather_srcs() { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 604 | for (const skiagm::GMRegistry* r = skiagm::GMRegistry::Head(); r; r = r->next()) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 605 | push_src("gm", "", new GMSrc(r->factory())); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 606 | } |
halcanary | fc37ad1 | 2015-01-30 07:31:19 -0800 | [diff] [blame] | 607 | for (int i = 0; i < FLAGS_skps.count(); i++) { |
| 608 | const char* path = FLAGS_skps[i]; |
| 609 | if (sk_isdir(path)) { |
| 610 | SkOSFile::Iter it(path, "skp"); |
| 611 | for (SkString file; it.next(&file); ) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 612 | push_src("skp", "", new SKPSrc(SkOSPath::Join(path, file.c_str()))); |
halcanary | fc37ad1 | 2015-01-30 07:31:19 -0800 | [diff] [blame] | 613 | } |
| 614 | } else { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 615 | push_src("skp", "", new SKPSrc(path)); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 616 | } |
| 617 | } |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 618 | |
| 619 | SkTArray<SkString> images; |
| 620 | if (!CollectImages(&images)) { |
| 621 | return false; |
| 622 | } |
| 623 | |
| 624 | for (auto image : images) { |
| 625 | push_codec_srcs(image); |
scroggo | e449984 | 2016-02-25 11:03:47 -0800 | [diff] [blame] | 626 | if (FLAGS_simpleCodec) { |
| 627 | continue; |
| 628 | } |
| 629 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 630 | const char* ext = strrchr(image.c_str(), '.'); |
| 631 | if (ext && brd_supported(ext+1)) { |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 632 | push_brd_srcs(image); |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 633 | } |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 634 | } |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 635 | |
| 636 | return true; |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 637 | } |
| 638 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 639 | static void push_sink(const SkCommandLineConfig& config, Sink* s) { |
rmistry | 0f515bd | 2015-12-22 10:22:26 -0800 | [diff] [blame] | 640 | SkAutoTDelete<Sink> sink(s); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 641 | |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 642 | // Try a simple Src as a canary. If it fails, skip this sink. |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 643 | struct : public Src { |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 644 | Error draw(SkCanvas* c) const override { |
| 645 | c->drawRect(SkRect::MakeWH(1,1), SkPaint()); |
| 646 | return ""; |
| 647 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 648 | SkISize size() const override { return SkISize::Make(16, 16); } |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 649 | Name name() const override { return "justOneRect"; } |
| 650 | } justOneRect; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 651 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 652 | SkBitmap bitmap; |
| 653 | SkDynamicMemoryWStream stream; |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 654 | SkString log; |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 655 | Error err = sink->draw(justOneRect, &bitmap, &stream, &log); |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 656 | if (err.isFatal()) { |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 657 | SkDebugf("Could not run %s: %s\n", config.getTag().c_str(), err.c_str()); |
mtklein | 05641a5 | 2015-04-21 10:49:13 -0700 | [diff] [blame] | 658 | exit(1); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 659 | } |
| 660 | |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 661 | TaggedSink& ts = gSinks.push_back(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 662 | ts.reset(sink.detach()); |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 663 | ts.tag = config.getTag(); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | static bool gpu_supported() { |
| 667 | #if SK_SUPPORT_GPU |
| 668 | return FLAGS_gpu; |
| 669 | #else |
| 670 | return false; |
| 671 | #endif |
| 672 | } |
kkinnunen | 9ebc3f0 | 2015-12-21 23:48:13 -0800 | [diff] [blame] | 673 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 674 | static 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 | |
tomhudson | eebc39a | 2015-02-23 12:18:05 -0800 | [diff] [blame] | 699 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 700 | SINK("hwui", HWUISink); |
| 701 | #endif |
| 702 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 703 | if (FLAGS_cpu) { |
| 704 | SINK("565", RasterSink, kRGB_565_SkColorType); |
| 705 | SINK("8888", RasterSink, kN32_SkColorType); |
mtklein | 27c3fdd | 2016-02-26 14:43:21 -0800 | [diff] [blame] | 706 | SINK("srgb", RasterSink, kN32_SkColorType, kSRGB_SkColorProfileType); |
| 707 | SINK("f16", RasterSink, kRGBA_F16_SkColorType); |
halcanary | c11c62f | 2015-09-28 11:51:54 -0700 | [diff] [blame] | 708 | SINK("pdf", PDFSink, "Pdfium"); |
| 709 | SINK("pdf_poppler", PDFSink, "Poppler"); |
mtklein | 9c3f17d | 2015-01-28 11:35:18 -0800 | [diff] [blame] | 710 | SINK("skp", SKPSink); |
mtklein | 8a4527e | 2015-01-31 20:00:58 -0800 | [diff] [blame] | 711 | SINK("svg", SVGSink); |
| 712 | SINK("null", NullSink); |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 713 | SINK("xps", XPSSink); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 714 | } |
| 715 | #undef SINK |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 716 | return nullptr; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 717 | } |
| 718 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 719 | static Sink* create_via(const SkString& tag, Sink* wrapped) { |
| 720 | #define VIA(t, via, ...) if (tag.equals(t)) { return new via(__VA_ARGS__); } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 721 | VIA("twice", ViaTwice, wrapped); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 722 | VIA("serialize", ViaSerialization, wrapped); |
mtklein | 4a34ecb | 2016-01-08 10:19:35 -0800 | [diff] [blame] | 723 | VIA("pic", ViaPicture, wrapped); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 724 | VIA("2ndpic", ViaSecondPicture, wrapped); |
mtklein | d31c13d | 2015-05-05 12:59:56 -0700 | [diff] [blame] | 725 | VIA("sp", ViaSingletonPictures, wrapped); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 726 | VIA("tiles", ViaTiles, 256, 256, nullptr, wrapped); |
mtklein | 7edca21 | 2015-01-21 13:18:51 -0800 | [diff] [blame] | 727 | VIA("tiles_rt", ViaTiles, 256, 256, new SkRTreeFactory, wrapped); |
mtklein | 2e2ea38 | 2015-10-16 10:29:41 -0700 | [diff] [blame] | 728 | VIA("remote", ViaRemote, false, wrapped); |
| 729 | VIA("remote_cache", ViaRemote, true, wrapped); |
halcanary | 7a76f9c | 2016-02-03 11:53:18 -0800 | [diff] [blame] | 730 | VIA("mojo", ViaMojo, wrapped); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 731 | |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 732 | if (FLAGS_matrix.count() == 4) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 733 | SkMatrix m; |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 734 | m.reset(); |
| 735 | m.setScaleX((SkScalar)atof(FLAGS_matrix[0])); |
| 736 | m.setSkewX ((SkScalar)atof(FLAGS_matrix[1])); |
| 737 | m.setSkewY ((SkScalar)atof(FLAGS_matrix[2])); |
| 738 | m.setScaleY((SkScalar)atof(FLAGS_matrix[3])); |
| 739 | VIA("matrix", ViaMatrix, m, wrapped); |
| 740 | VIA("upright", ViaUpright, m, wrapped); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 741 | } |
tomhudson | 64de1e1 | 2015-03-05 08:01:07 -0800 | [diff] [blame] | 742 | |
| 743 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 744 | VIA("androidsdk", ViaAndroidSDK, wrapped); |
| 745 | #endif |
| 746 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 747 | #undef VIA |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 748 | return nullptr; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 749 | } |
| 750 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 751 | static void gather_sinks() { |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 752 | SkCommandLineConfigArray configs; |
| 753 | ParseConfigs(FLAGS_config, &configs); |
| 754 | for (int i = 0; i < configs.count(); i++) { |
| 755 | const SkCommandLineConfig& config = *configs[i]; |
| 756 | Sink* sink = create_sink(&config); |
| 757 | if (sink == nullptr) { |
| 758 | SkDebugf("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(), |
| 759 | config.getTag().c_str()); |
| 760 | continue; |
| 761 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 762 | |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 763 | const SkTArray<SkString>& parts = config.getViaParts(); |
| 764 | for (int j = parts.count(); j-- > 0;) { |
| 765 | const SkString& part = parts[j]; |
| 766 | Sink* next = create_via(part, sink); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 767 | if (next == nullptr) { |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 768 | SkDebugf("Skipping config %s: Don't understand '%s'.\n", config.getTag().c_str(), |
| 769 | part.c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 770 | delete sink; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 771 | sink = nullptr; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 772 | break; |
| 773 | } |
| 774 | sink = next; |
| 775 | } |
| 776 | if (sink) { |
| 777 | push_sink(config, sink); |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 778 | } |
| 779 | } |
| 780 | } |
mtklein | 709d2c3 | 2015-01-15 08:30:25 -0800 | [diff] [blame] | 781 | |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 782 | static bool dump_png(SkBitmap bitmap, const char* path, const char* md5) { |
| 783 | const int w = bitmap.width(), |
| 784 | h = bitmap.height(); |
mtklein | 27c3fdd | 2016-02-26 14:43:21 -0800 | [diff] [blame] | 785 | // PNG wants unpremultiplied 8-bit RGBA pixels (16-bit could work fine too). |
| 786 | // We leave the gamma of these bytes unspecified, to continue the status quo, |
| 787 | // which we think generally is to interpret them as sRGB. |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 788 | |
mtklein | 27c3fdd | 2016-02-26 14:43:21 -0800 | [diff] [blame] | 789 | SkAutoTMalloc<uint32_t> rgba(w*h); |
| 790 | |
| 791 | if (bitmap. colorType() == kN32_SkColorType && |
| 792 | bitmap.profileType() == kSRGB_SkColorProfileType) { |
| 793 | // These are premul sRGB 8-bit pixels in SkPMColor order. |
| 794 | // We want unpremul sRGB 8-bit pixels in RGBA order. We'll get there via floats. |
| 795 | bitmap.lockPixels(); |
| 796 | auto px = (const uint32_t*)bitmap.getPixels(); |
| 797 | if (!px) { |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 798 | return false; |
| 799 | } |
mtklein | 27c3fdd | 2016-02-26 14:43:21 -0800 | [diff] [blame] | 800 | for (int i = 0; i < w*h; i++) { |
| 801 | Sk4f fs = Sk4f_fromS32(px[i]); // Convert up to linear floats. |
| 802 | #if defined(SK_PMCOLOR_IS_BGRA) |
| 803 | fs = SkNx_shuffle<2,1,0,3>(fs); // Shuffle to RGBA, if not there already. |
| 804 | #endif |
| 805 | float invA = 1.0f / fs[3]; |
| 806 | fs = fs * Sk4f(invA, invA, invA, 1); // Unpremultiply. |
| 807 | rgba[i] = Sk4f_toS32(fs); // Pack down to sRGB bytes. |
| 808 | } |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 809 | |
mtklein | 27c3fdd | 2016-02-26 14:43:21 -0800 | [diff] [blame] | 810 | } else if (bitmap.colorType() == kRGBA_F16_SkColorType) { |
| 811 | // These are premul linear half-float pixels in RGBA order. |
| 812 | // We want unpremul sRGB 8-bit pixels in RGBA order. We'll get there via floats. |
| 813 | bitmap.lockPixels(); |
| 814 | auto px = (const uint64_t*)bitmap.getPixels(); |
| 815 | if (!px) { |
| 816 | return false; |
| 817 | } |
| 818 | for (int i = 0; i < w*h; i++) { |
| 819 | Sk4f fs = SkHalfToFloat_01(px[i]); // Convert up to linear floats. |
| 820 | float invA = 1.0f / fs[3]; |
| 821 | fs = fs * Sk4f(invA, invA, invA, 1); // Unpremultiply. |
| 822 | rgba[i] = Sk4f_toS32(fs); // Pack down to sRGB bytes. |
| 823 | } |
| 824 | |
| 825 | |
| 826 | } else { |
| 827 | // We "should" gamma correct in here but we don't. |
| 828 | // We want Gold to show exactly what our clients are seeing, broken gamma. |
| 829 | |
| 830 | // Convert smaller formats up to premul linear 8-bit (in SkPMColor order). |
| 831 | if (bitmap.colorType() != kN32_SkColorType) { |
| 832 | SkBitmap n32; |
| 833 | if (!bitmap.copyTo(&n32, kN32_SkColorType)) { |
| 834 | return false; |
| 835 | } |
| 836 | bitmap = n32; |
| 837 | } |
| 838 | |
| 839 | // Convert premul linear 8-bit to unpremul linear 8-bit RGBA. |
| 840 | if (!bitmap.readPixels(SkImageInfo::Make(w,h, kRGBA_8888_SkColorType, |
| 841 | kUnpremul_SkAlphaType), |
| 842 | rgba, 4*w, 0,0)) { |
| 843 | return false; |
| 844 | } |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | // We don't need bitmap anymore. Might as well drop our ref. |
mtklein | fccb77d | 2015-08-24 14:13:29 -0700 | [diff] [blame] | 848 | bitmap.reset(); |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 849 | |
mtklein | c64137c | 2015-08-25 10:56:08 -0700 | [diff] [blame] | 850 | FILE* f = fopen(path, "wb"); |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 851 | if (!f) { return false; } |
| 852 | |
| 853 | png_structp png = png_create_write_struct(PNG_LIBPNG_VER_STRING, nullptr, nullptr, nullptr); |
| 854 | if (!png) { |
| 855 | fclose(f); |
| 856 | return false; |
| 857 | } |
| 858 | |
| 859 | png_infop info = png_create_info_struct(png); |
| 860 | if (!info) { |
| 861 | png_destroy_write_struct(&png, &info); |
| 862 | fclose(f); |
| 863 | return false; |
| 864 | } |
| 865 | |
mtklein | d69ece6 | 2015-09-10 10:37:44 -0700 | [diff] [blame] | 866 | SkString description; |
| 867 | description.append("Key: "); |
| 868 | for (int i = 0; i < FLAGS_key.count(); i++) { |
| 869 | description.appendf("%s ", FLAGS_key[i]); |
| 870 | } |
| 871 | description.append("Properties: "); |
| 872 | for (int i = 0; i < FLAGS_properties.count(); i++) { |
| 873 | description.appendf("%s ", FLAGS_properties[i]); |
| 874 | } |
| 875 | description.appendf("MD5: %s", md5); |
| 876 | |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 877 | png_text text[2]; |
| 878 | text[0].key = (png_charp)"Author"; |
| 879 | text[0].text = (png_charp)"DM dump_png()"; |
| 880 | text[0].compression = PNG_TEXT_COMPRESSION_NONE; |
| 881 | text[1].key = (png_charp)"Description"; |
mtklein | d69ece6 | 2015-09-10 10:37:44 -0700 | [diff] [blame] | 882 | text[1].text = (png_charp)description.c_str(); |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 883 | text[1].compression = PNG_TEXT_COMPRESSION_NONE; |
| 884 | png_set_text(png, info, text, 2); |
| 885 | |
| 886 | png_init_io(png, f); |
| 887 | png_set_IHDR(png, info, (png_uint_32)w, (png_uint_32)h, 8, |
| 888 | PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE, |
| 889 | PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); |
| 890 | png_write_info(png, info); |
| 891 | for (int j = 0; j < h; j++) { |
| 892 | png_bytep row = (png_bytep)(rgba.get() + w*j); |
| 893 | png_write_rows(png, &row, 1); |
| 894 | } |
| 895 | png_write_end(png, info); |
| 896 | |
| 897 | png_destroy_write_struct(&png, &info); |
| 898 | fclose(f); |
| 899 | return true; |
| 900 | } |
| 901 | |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 902 | static bool match(const char* needle, const char* haystack) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 903 | return 0 == strcmp("_", needle) || nullptr != strstr(haystack, needle); |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 904 | } |
| 905 | |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 906 | static bool is_blacklisted(const char* sink, const char* src, |
| 907 | const char* srcOptions, const char* name) { |
mtklein | 0d243ff | 2015-04-03 07:51:00 -0700 | [diff] [blame] | 908 | for (int i = 0; i < FLAGS_blacklist.count() - 3; i += 4) { |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 909 | if (match(FLAGS_blacklist[i+0], sink) && |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 910 | match(FLAGS_blacklist[i+1], src) && |
| 911 | match(FLAGS_blacklist[i+2], srcOptions) && |
| 912 | match(FLAGS_blacklist[i+3], name)) { |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 913 | return true; |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 914 | } |
| 915 | } |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 916 | return false; |
mtklein | a2ef642 | 2015-01-15 13:44:22 -0800 | [diff] [blame] | 917 | } |
| 918 | |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 919 | // Even when a Task Sink reports to be non-threadsafe (e.g. GPU), we know things like |
| 920 | // .png encoding are definitely thread safe. This lets us offload that work to CPU threads. |
| 921 | static SkTaskGroup gDefinitelyThreadSafeWork; |
| 922 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 923 | // The finest-grained unit of work we can run: draw a single Src into a single Sink, |
| 924 | // report any errors, and perhaps write out the output: a .png of the bitmap, or a raw stream. |
| 925 | struct Task { |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 926 | Task(const TaggedSrc& src, const TaggedSink& sink) : src(src), sink(sink) {} |
| 927 | const TaggedSrc& src; |
| 928 | const TaggedSink& sink; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 929 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 930 | static void Run(const Task& task) { |
| 931 | SkString name = task.src->name(); |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 932 | |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 933 | SkString log; |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 934 | if (!FLAGS_dryRun) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 935 | SkBitmap bitmap; |
| 936 | SkDynamicMemoryWStream stream; |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 937 | start(task.sink.tag.c_str(), task.src.tag.c_str(), |
| 938 | task.src.options.c_str(), name.c_str()); |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 939 | Error err = task.sink->draw(*task.src, &bitmap, &stream, &log); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 940 | if (!err.isEmpty()) { |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 941 | if (err.isFatal()) { |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 942 | fail(SkStringPrintf("%s %s %s %s: %s", |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 943 | task.sink.tag.c_str(), |
| 944 | task.src.tag.c_str(), |
| 945 | task.src.options.c_str(), |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 946 | name.c_str(), |
| 947 | err.c_str())); |
mtklein | b37cb41 | 2015-03-18 05:27:14 -0700 | [diff] [blame] | 948 | } else { |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 949 | done(task.sink.tag.c_str(), task.src.tag.c_str(), |
| 950 | task.src.options.c_str(), name.c_str()); |
mtklein | ba6ada7 | 2016-01-21 09:39:35 -0800 | [diff] [blame] | 951 | return; |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 952 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 953 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 954 | |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 955 | // We're likely switching threads here, so we must capture by value, [=] or [foo,bar]. |
| 956 | SkStreamAsset* data = stream.detachAsStream(); |
| 957 | gDefinitelyThreadSafeWork.add([task,name,bitmap,data]{ |
| 958 | SkAutoTDelete<SkStreamAsset> ownedData(data); |
| 959 | |
| 960 | // Why doesn't the copy constructor do this when we have pre-locked pixels? |
| 961 | bitmap.lockPixels(); |
| 962 | |
| 963 | SkString md5; |
| 964 | if (!FLAGS_writePath.isEmpty() || !FLAGS_readPath.isEmpty()) { |
| 965 | SkMD5 hash; |
| 966 | if (data->getLength()) { |
| 967 | hash.writeStream(data, data->getLength()); |
| 968 | data->rewind(); |
mtklein | 3840846 | 2015-07-08 07:25:27 -0700 | [diff] [blame] | 969 | } else { |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 970 | // If we're BGRA (Linux, Windows), swizzle over to RGBA (Mac, Android). |
| 971 | // This helps eliminate multiple 0-pixel-diff hashes on gold.skia.org. |
| 972 | // (Android's general slow speed breaks the tie arbitrarily in RGBA's favor.) |
| 973 | // We might consider promoting 565 to RGBA too. |
| 974 | if (bitmap.colorType() == kBGRA_8888_SkColorType) { |
| 975 | SkBitmap swizzle; |
| 976 | SkAssertResult(bitmap.copyTo(&swizzle, kRGBA_8888_SkColorType)); |
| 977 | hash.write(swizzle.getPixels(), swizzle.getSize()); |
| 978 | } else { |
| 979 | hash.write(bitmap.getPixels(), bitmap.getSize()); |
| 980 | } |
| 981 | } |
| 982 | SkMD5::Digest digest; |
| 983 | hash.finish(digest); |
| 984 | for (int i = 0; i < 16; i++) { |
| 985 | md5.appendf("%02x", digest.data[i]); |
mtklein | 3840846 | 2015-07-08 07:25:27 -0700 | [diff] [blame] | 986 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 987 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 988 | |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 989 | if (!FLAGS_readPath.isEmpty() && |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 990 | !gGold.contains(Gold(task.sink.tag, task.src.tag, |
| 991 | task.src.options, name, md5))) { |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 992 | fail(SkStringPrintf("%s not found for %s %s %s %s in %s", |
| 993 | md5.c_str(), |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 994 | task.sink.tag.c_str(), |
| 995 | task.src.tag.c_str(), |
| 996 | task.src.options.c_str(), |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 997 | name.c_str(), |
| 998 | FLAGS_readPath[0])); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 999 | } |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1000 | |
| 1001 | if (!FLAGS_writePath.isEmpty()) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1002 | const char* ext = task.sink->fileExtension(); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1003 | if (data->getLength()) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1004 | WriteToDisk(task, md5, ext, data, data->getLength(), nullptr); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1005 | SkASSERT(bitmap.drawsNothing()); |
| 1006 | } else if (!bitmap.drawsNothing()) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1007 | WriteToDisk(task, md5, ext, nullptr, 0, &bitmap); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1008 | } |
| 1009 | } |
| 1010 | }); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1011 | } |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1012 | done(task.sink.tag.c_str(), task.src.tag.c_str(), task.src.options.c_str(), name.c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | static void WriteToDisk(const Task& task, |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1016 | SkString md5, |
| 1017 | const char* ext, |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1018 | SkStream* data, size_t len, |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1019 | const SkBitmap* bitmap) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1020 | JsonWriter::BitmapResult result; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 1021 | result.name = task.src->name(); |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1022 | result.config = task.sink.tag; |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 1023 | result.sourceType = task.src.tag; |
| 1024 | result.sourceOptions = task.src.options; |
| 1025 | result.ext = ext; |
| 1026 | result.md5 = md5; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1027 | JsonWriter::AddBitmapResult(result); |
| 1028 | |
mtklein | b0531a7 | 2015-04-07 13:38:48 -0700 | [diff] [blame] | 1029 | // If an MD5 is uninteresting, we want it noted in the JSON file, |
| 1030 | // but don't want to dump it out as a .png (or whatever ext is). |
| 1031 | if (gUninterestingHashes.contains(md5)) { |
| 1032 | return; |
| 1033 | } |
| 1034 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1035 | const char* dir = FLAGS_writePath[0]; |
| 1036 | if (0 == strcmp(dir, "@")) { // Needed for iOS. |
| 1037 | dir = FLAGS_resourcePath[0]; |
| 1038 | } |
| 1039 | sk_mkdir(dir); |
| 1040 | |
| 1041 | SkString path; |
| 1042 | if (FLAGS_nameByHash) { |
| 1043 | path = SkOSPath::Join(dir, result.md5.c_str()); |
| 1044 | path.append("."); |
| 1045 | path.append(ext); |
| 1046 | if (sk_exists(path.c_str())) { |
| 1047 | return; // Content-addressed. If it exists already, we're done. |
| 1048 | } |
| 1049 | } else { |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1050 | path = SkOSPath::Join(dir, task.sink.tag.c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1051 | sk_mkdir(path.c_str()); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 1052 | path = SkOSPath::Join(path.c_str(), task.src.tag.c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1053 | sk_mkdir(path.c_str()); |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 1054 | if (strcmp(task.src.options.c_str(), "") != 0) { |
| 1055 | path = SkOSPath::Join(path.c_str(), task.src.options.c_str()); |
djsollen | 54416de | 2015-04-03 07:24:48 -0700 | [diff] [blame] | 1056 | sk_mkdir(path.c_str()); |
| 1057 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1058 | path = SkOSPath::Join(path.c_str(), task.src->name().c_str()); |
| 1059 | path.append("."); |
| 1060 | path.append(ext); |
| 1061 | } |
| 1062 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1063 | if (bitmap) { |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 1064 | if (!dump_png(*bitmap, path.c_str(), result.md5.c_str())) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1065 | fail(SkStringPrintf("Can't encode PNG to %s.\n", path.c_str())); |
| 1066 | return; |
| 1067 | } |
| 1068 | } else { |
mtklein | a5114d7 | 2015-08-24 13:27:01 -0700 | [diff] [blame] | 1069 | SkFILEWStream file(path.c_str()); |
| 1070 | if (!file.isValid()) { |
| 1071 | fail(SkStringPrintf("Can't open %s for writing.\n", path.c_str())); |
| 1072 | return; |
| 1073 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1074 | if (!file.writeStream(data, len)) { |
| 1075 | fail(SkStringPrintf("Can't write to %s.\n", path.c_str())); |
| 1076 | return; |
| 1077 | } |
| 1078 | } |
| 1079 | } |
| 1080 | }; |
| 1081 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1082 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 1083 | |
| 1084 | // Unit tests don't fit so well into the Src/Sink model, so we give them special treatment. |
| 1085 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1086 | static SkTDArray<skiatest::Test> gParallelTests, gSerialTests; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1087 | |
| 1088 | static void gather_tests() { |
mtklein | 6c5fed2 | 2015-01-20 13:47:23 -0800 | [diff] [blame] | 1089 | if (!FLAGS_src.contains("tests")) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1090 | return; |
| 1091 | } |
mtklein | 6393c06 | 2015-04-27 08:45:01 -0700 | [diff] [blame] | 1092 | for (const skiatest::TestRegistry* r = skiatest::TestRegistry::Head(); r; r = r->next()) { |
| 1093 | if (!in_shard()) { |
| 1094 | continue; |
| 1095 | } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1096 | // Despite its name, factory() is returning a reference to |
| 1097 | // link-time static const POD data. |
| 1098 | const skiatest::Test& test = r->factory(); |
| 1099 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, test.name)) { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1100 | continue; |
| 1101 | } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1102 | if (test.needsGpu && gpu_supported()) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1103 | (FLAGS_gpu_threading ? gParallelTests : gSerialTests).push(test); |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1104 | } else if (!test.needsGpu && FLAGS_cpu) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1105 | gParallelTests.push(test); |
mtklein | 82d2843 | 2015-01-15 12:46:02 -0800 | [diff] [blame] | 1106 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1107 | } |
| 1108 | } |
| 1109 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1110 | static void run_test(skiatest::Test test) { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1111 | struct : public skiatest::Reporter { |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1112 | void reportFailed(const skiatest::Failure& failure) override { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1113 | fail(failure.toString()); |
| 1114 | JsonWriter::AddTestFailure(failure); |
| 1115 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1116 | bool allowExtendedTest() const override { |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1117 | return FLAGS_pathOpsExtended; |
| 1118 | } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 1119 | bool verbose() const override { return FLAGS_veryVerbose; } |
halcanary | 87f3ba4 | 2015-01-20 09:30:20 -0800 | [diff] [blame] | 1120 | } reporter; |
djsollen | 824996a | 2015-06-12 12:06:22 -0700 | [diff] [blame] | 1121 | |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1122 | if (!FLAGS_dryRun && !is_blacklisted("_", "tests", "_", test.name)) { |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1123 | start("unit", "test", "", test.name); |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 1124 | GrContextFactory factory; |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1125 | test.proc(&reporter, &factory); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1126 | } |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1127 | done("unit", "test", "", test.name); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 1131 | |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1132 | DEFINE_int32(status_sec, 15, "Print status this often (and if we crash)."); |
| 1133 | |
| 1134 | SkThread* start_status_thread() { |
| 1135 | auto thread = new SkThread([] (void*) { |
| 1136 | for (;;) { |
| 1137 | print_status(); |
| 1138 | #if defined(SK_BUILD_FOR_WIN) |
| 1139 | Sleep(FLAGS_status_sec * 1000); |
| 1140 | #else |
| 1141 | sleep(FLAGS_status_sec); |
| 1142 | #endif |
mtklein | 2e1c47e | 2015-03-12 07:16:56 -0700 | [diff] [blame] | 1143 | } |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1144 | }); |
| 1145 | thread->start(); |
| 1146 | return thread; |
mtklein | de6fc2b | 2015-03-12 06:28:54 -0700 | [diff] [blame] | 1147 | } |
| 1148 | |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1149 | #define PORTABLE_FONT_PREFIX "Toy Liberation " |
| 1150 | |
| 1151 | static SkTypeface* create_from_name(const char familyName[], SkTypeface::Style style) { |
| 1152 | if (familyName && strlen(familyName) > sizeof(PORTABLE_FONT_PREFIX) |
| 1153 | && !strncmp(familyName, PORTABLE_FONT_PREFIX, sizeof(PORTABLE_FONT_PREFIX) - 1)) { |
caryclark | 1818acb | 2015-07-24 12:09:25 -0700 | [diff] [blame] | 1154 | return sk_tool_utils::create_portable_typeface(familyName, style); |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1155 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1156 | return nullptr; |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | #undef PORTABLE_FONT_PREFIX |
| 1160 | |
| 1161 | extern SkTypeface* (*gCreateTypefaceDelegate)(const char [], SkTypeface::Style ); |
| 1162 | |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1163 | int dm_main(); |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 1164 | int dm_main() { |
mtklein | 246ba3a | 2016-02-23 10:39:36 -0800 | [diff] [blame] | 1165 | setup_crash_handler(); |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1166 | |
mtklein | 5286f02 | 2016-01-22 08:18:14 -0800 | [diff] [blame] | 1167 | JsonWriter::DumpJson(); // It's handy for the bots to assume this is ~never missing. |
commit-bot@chromium.org | 39e8d93 | 2014-05-29 20:14:48 +0000 | [diff] [blame] | 1168 | SkAutoGraphics ag; |
mtklein | 406654b | 2014-09-03 15:34:37 -0700 | [diff] [blame] | 1169 | SkTaskGroup::Enabler enabled(FLAGS_threads); |
caryclark | 83ca628 | 2015-06-10 09:31:09 -0700 | [diff] [blame] | 1170 | gCreateTypefaceDelegate = &create_from_name; |
commit-bot@chromium.org | a65e2fd | 2014-05-30 17:23:31 +0000 | [diff] [blame] | 1171 | |
halcanary | 7d57124 | 2016-02-24 17:59:16 -0800 | [diff] [blame] | 1172 | { |
| 1173 | SkString testResourcePath = GetResourcePath("color_wheel.png"); |
| 1174 | SkFILEStream testResource(testResourcePath.c_str()); |
| 1175 | if (!testResource.isValid()) { |
| 1176 | SkDebugf("Some resources are missing. Do you need to set --resourcePath?\n"); |
| 1177 | } |
| 1178 | } |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1179 | gather_gold(); |
borenet | 09ed480 | 2015-04-03 14:15:33 -0700 | [diff] [blame] | 1180 | gather_uninteresting_hashes(); |
mtklein | 62bd1a6 | 2015-01-27 14:46:26 -0800 | [diff] [blame] | 1181 | |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 1182 | if (!gather_srcs()) { |
| 1183 | return 1; |
| 1184 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1185 | gather_sinks(); |
| 1186 | gather_tests(); |
commit-bot@chromium.org | 0dc5bd1 | 2014-02-26 16:31:22 +0000 | [diff] [blame] | 1187 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1188 | gPending = gSrcs.count() * gSinks.count() + gParallelTests.count() + gSerialTests.count(); |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1189 | SkDebugf("%d srcs * %d sinks + %d tests == %d tasks", |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1190 | gSrcs.count(), gSinks.count(), gParallelTests.count() + gSerialTests.count(), gPending); |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1191 | SkAutoTDelete<SkThread> statusThread(start_status_thread()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1192 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1193 | // Kick off as much parallel work as we can, making note of any serial work we'll need to do. |
| 1194 | SkTaskGroup parallel; |
| 1195 | SkTArray<Task> serial; |
| 1196 | |
| 1197 | for (auto& sink : gSinks) |
| 1198 | for (auto& src : gSrcs) { |
mtklein | 3eed7dd | 2016-02-24 19:07:07 -0800 | [diff] [blame] | 1199 | if (src->veto(sink->flags()) || |
| 1200 | is_blacklisted(sink.tag.c_str(), src.tag.c_str(), |
| 1201 | src.options.c_str(), src->name().c_str())) { |
| 1202 | SkAutoTAcquire<SkPODSpinlock> lock(gMutex); |
| 1203 | gPending--; |
| 1204 | continue; |
| 1205 | } |
| 1206 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1207 | Task task(src, sink); |
| 1208 | if (src->serial() || sink->serial()) { |
| 1209 | serial.push_back(task); |
| 1210 | } else { |
| 1211 | parallel.add([task] { Task::Run(task); }); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1212 | } |
commit-bot@chromium.org | 38aeb0f | 2014-02-26 23:01:57 +0000 | [diff] [blame] | 1213 | } |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1214 | for (auto test : gParallelTests) { |
| 1215 | parallel.add([test] { run_test(test); }); |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 1216 | } |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 1217 | |
| 1218 | // With the parallel work running, run serial tasks and tests here on main thread. |
| 1219 | for (auto task : serial) { Task::Run(task); } |
| 1220 | for (auto test : gSerialTests) { run_test(test); } |
| 1221 | |
| 1222 | // Wait for any remaining parallel work to complete (including any spun off of serial tasks). |
| 1223 | parallel.wait(); |
mtklein | cd50bca | 2016-01-05 06:20:20 -0800 | [diff] [blame] | 1224 | gDefinitelyThreadSafeWork.wait(); |
| 1225 | |
mtklein | da884c4 | 2016-02-24 18:00:23 -0800 | [diff] [blame] | 1226 | // We'd better have run everything. |
| 1227 | SkASSERT(gPending == 0); |
mtklein | e027f17 | 2016-02-26 15:53:06 -0800 | [diff] [blame] | 1228 | // Make sure we've flushed all our results to disk. |
| 1229 | JsonWriter::DumpJson(); |
mtklein | da884c4 | 2016-02-24 18:00:23 -0800 | [diff] [blame] | 1230 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1231 | // At this point we're back in single-threaded land. |
caryclark | f53ce80 | 2015-06-15 06:48:30 -0700 | [diff] [blame] | 1232 | sk_tool_utils::release_portable_typefaces(); |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 1233 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1234 | if (gFailures.count() > 0) { |
| 1235 | SkDebugf("Failures:\n"); |
| 1236 | for (int i = 0; i < gFailures.count(); i++) { |
mtklein | 9dc0910 | 2015-01-15 15:47:33 -0800 | [diff] [blame] | 1237 | SkDebugf("\t%s\n", gFailures[i].c_str()); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1238 | } |
| 1239 | SkDebugf("%d failures\n", gFailures.count()); |
| 1240 | return 1; |
mtklein | 114c3cd | 2015-01-15 10:15:02 -0800 | [diff] [blame] | 1241 | } |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1242 | |
| 1243 | #ifdef SK_PDF_IMAGE_STATS |
halcanary | 7a14b31 | 2015-10-01 07:28:13 -0700 | [diff] [blame] | 1244 | SkPDFImageDumpStats(); |
mtklein | afae30a | 2016-02-24 12:28:32 -0800 | [diff] [blame] | 1245 | #endif // SK_PDF_IMAGE_STATS |
| 1246 | |
| 1247 | print_status(); |
scroggo | 4d9eaea | 2016-01-29 07:48:33 -0800 | [diff] [blame] | 1248 | SkDebugf("Finished!\n"); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 1249 | return 0; |
mtklein@google.com | d36522d | 2013-10-16 13:02:15 +0000 | [diff] [blame] | 1250 | } |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1251 | |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1252 | // TODO: currently many GPU tests are declared outside SK_SUPPORT_GPU guards. |
| 1253 | // Thus we export the empty RunWithGPUTestContexts when SK_SUPPORT_GPU=0. |
| 1254 | namespace skiatest { |
| 1255 | namespace { |
| 1256 | typedef void(*TestWithGrContext)(skiatest::Reporter*, GrContext*); |
| 1257 | typedef void(*TestWithGrContextAndGLContext)(skiatest::Reporter*, GrContext*, SkGLContext*); |
| 1258 | #if SK_SUPPORT_GPU |
| 1259 | template<typename T> |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 1260 | void call_test(T test, skiatest::Reporter* reporter, const GrContextFactory::ContextInfo& context); |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1261 | template<> |
| 1262 | void call_test(TestWithGrContext test, skiatest::Reporter* reporter, |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 1263 | const GrContextFactory::ContextInfo& context) { |
| 1264 | test(reporter, context.fGrContext); |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1265 | } |
| 1266 | template<> |
| 1267 | void call_test(TestWithGrContextAndGLContext test, skiatest::Reporter* reporter, |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 1268 | const GrContextFactory::ContextInfo& context) { |
| 1269 | test(reporter, context.fGrContext, context.fGLContext); |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1270 | } |
| 1271 | #endif |
| 1272 | } // namespace |
| 1273 | |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1274 | template<typename T> |
| 1275 | void RunWithGPUTestContexts(T test, GPUTestContexts testContexts, Reporter* reporter, |
| 1276 | GrContextFactory* factory) { |
| 1277 | #if SK_SUPPORT_GPU |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1278 | // Iterate over context types, except use "native" instead of explicitly trying OpenGL and |
| 1279 | // OpenGL ES. Do not use GLES on desktop, since tests do not account for not fixing |
| 1280 | // http://skbug.com/2809 |
| 1281 | GrContextFactory::GLContextType contextTypes[] = { |
| 1282 | GrContextFactory::kNative_GLContextType, |
| 1283 | #if SK_ANGLE |
| 1284 | #ifdef SK_BUILD_FOR_WIN |
| 1285 | GrContextFactory::kANGLE_GLContextType, |
| 1286 | #endif |
| 1287 | GrContextFactory::kANGLE_GL_GLContextType, |
| 1288 | #endif |
| 1289 | #if SK_COMMAND_BUFFER |
kkinnunen | 45c2c81 | 2016-02-25 02:03:43 -0800 | [diff] [blame] | 1290 | GrContextFactory::kCommandBufferES2_GLContextType, |
| 1291 | GrContextFactory::kCommandBufferES3_GLContextType, |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1292 | #endif |
| 1293 | #if SK_MESA |
| 1294 | GrContextFactory::kMESA_GLContextType, |
| 1295 | #endif |
| 1296 | GrContextFactory::kNull_GLContextType, |
| 1297 | GrContextFactory::kDebug_GLContextType, |
| 1298 | }; |
| 1299 | static_assert(SK_ARRAY_COUNT(contextTypes) == GrContextFactory::kGLContextTypeCnt - 2, |
| 1300 | "Skipping unexpected GLContextType for GPU tests"); |
| 1301 | |
| 1302 | for (auto& contextType : contextTypes) { |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1303 | int contextSelector = kNone_GPUTestContexts; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1304 | if (GrContextFactory::IsRenderingGLContext(contextType)) { |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1305 | contextSelector |= kAllRendering_GPUTestContexts; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1306 | } else if (contextType == GrContextFactory::kNative_GLContextType) { |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1307 | contextSelector |= kNative_GPUTestContexts; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1308 | } else if (contextType == GrContextFactory::kNull_GLContextType) { |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1309 | contextSelector |= kNull_GPUTestContexts; |
kkinnunen | 3e980c3 | 2015-12-23 01:33:00 -0800 | [diff] [blame] | 1310 | } else if (contextType == GrContextFactory::kDebug_GLContextType) { |
kkinnunen | 55eeae9 | 2015-12-10 23:19:29 -0800 | [diff] [blame] | 1311 | contextSelector |= kDebug_GPUTestContexts; |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1312 | } |
| 1313 | if ((testContexts & contextSelector) == 0) { |
| 1314 | continue; |
| 1315 | } |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 1316 | GrContextFactory::ContextInfo context = factory->getContextInfo(contextType); |
| 1317 | if (context.fGrContext) { |
kkinnunen | 5219fd9 | 2015-12-10 06:28:13 -0800 | [diff] [blame] | 1318 | call_test(test, reporter, context); |
| 1319 | } |
kkinnunen | 3405800 | 2016-01-06 23:49:30 -0800 | [diff] [blame] | 1320 | context = factory->getContextInfo(contextType, |
| 1321 | GrContextFactory::kEnableNVPR_GLContextOptions); |
| 1322 | if (context.fGrContext) { |
kkinnunen | 179a8f5 | 2015-11-20 13:32:24 -0800 | [diff] [blame] | 1323 | call_test(test, reporter, context); |
| 1324 | } |
| 1325 | } |
| 1326 | #endif |
| 1327 | } |
| 1328 | |
| 1329 | template |
| 1330 | void RunWithGPUTestContexts<TestWithGrContext>(TestWithGrContext test, |
| 1331 | GPUTestContexts testContexts, |
| 1332 | Reporter* reporter, |
| 1333 | GrContextFactory* factory); |
| 1334 | template |
| 1335 | void RunWithGPUTestContexts<TestWithGrContextAndGLContext>(TestWithGrContextAndGLContext test, |
| 1336 | GPUTestContexts testContexts, |
| 1337 | Reporter* reporter, |
| 1338 | GrContextFactory* factory); |
| 1339 | } // namespace skiatest |
| 1340 | |
borenet | 4808757 | 2015-04-02 12:16:36 -0700 | [diff] [blame] | 1341 | #if !defined(SK_BUILD_FOR_IOS) |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1342 | int main(int argc, char** argv) { |
| 1343 | SkCommandLineFlags::Parse(argc, argv); |
| 1344 | return dm_main(); |
| 1345 | } |
| 1346 | #endif |