caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | |
| 8 | #include "SkCommonFlags.h" |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 9 | #include "SkExecutor.h" |
| 10 | #include "SkOnce.h" |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 11 | #include "SkOSFile.h" |
Ben Wagner | bf111d7 | 2016-11-07 18:05:29 -0500 | [diff] [blame] | 12 | #include "SkOSPath.h" |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 13 | |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 14 | DEFINE_bool(cpu, true, "master switch for running CPU-bound work."); |
| 15 | |
| 16 | DEFINE_bool(dryRun, false, |
| 17 | "just print the tests that would be run, without actually running them."); |
| 18 | |
| 19 | DEFINE_bool(gpu, true, "master switch for running GPU-bound work."); |
| 20 | |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 21 | DEFINE_string(images, "", "List of images and/or directories to decode. A directory with no images" |
| 22 | " is treated as a fatal error."); |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 23 | |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 24 | DEFINE_string(colorImages, "", "List of images and/or directories to decode with color correction. " |
| 25 | "A directory with no images is treated as a fatal error."); |
| 26 | |
msarett | db197a5 | 2016-06-21 09:44:29 -0700 | [diff] [blame] | 27 | DEFINE_bool(simpleCodec, false, "Runs of a subset of the codec tests. " |
| 28 | "For DM, this means no scaling or subsetting, always using the " |
| 29 | "canvas color type. " |
| 30 | "For nanobench, this means always N32, Premul or Opaque."); |
| 31 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 32 | DEFINE_string2(match, m, nullptr, |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 33 | "[~][^]substring[$] [...] of GM name to run.\n" |
| 34 | "Multiple matches may be separated by spaces.\n" |
| 35 | "~ causes a matching GM to always be skipped\n" |
| 36 | "^ requires the start of the GM to match\n" |
| 37 | "$ requires the end of the GM to match\n" |
| 38 | "^ and $ requires an exact match\n" |
| 39 | "If a GM does not match any list entry,\n" |
| 40 | "it is skipped unless some list entry starts with ~"); |
| 41 | |
| 42 | DEFINE_bool2(quiet, q, false, "if true, don't print status updates."); |
| 43 | |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 44 | DEFINE_bool(preAbandonGpuContext, false, "Test abandoning the GrContext before running the test."); |
joshualitt | 5f5a8d7 | 2015-02-25 14:09:45 -0800 | [diff] [blame] | 45 | |
bsalomon | 6e2aad4 | 2016-04-01 11:54:31 -0700 | [diff] [blame] | 46 | DEFINE_bool(abandonGpuContext, false, "Test abandoning the GrContext after running each test."); |
| 47 | |
| 48 | DEFINE_bool(releaseAndAbandonGpuContext, false, |
| 49 | "Test releasing all gpu resources and abandoning the GrContext after running each " |
| 50 | "test"); |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 51 | |
mtklein | 34580f7 | 2014-08-07 12:46:29 -0700 | [diff] [blame] | 52 | DEFINE_string(skps, "skps", "Directory to read skps from."); |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 53 | |
fmalita | 95573e4 | 2016-09-14 09:05:43 -0700 | [diff] [blame] | 54 | DEFINE_string(svgs, "", "Directory to read SVGs from, or a single SVG file."); |
| 55 | |
Mike Klein | 08c8963 | 2016-11-08 14:16:01 -0500 | [diff] [blame] | 56 | DEFINE_int32_2(threads, j, -1, "Run threadsafe tests on a threadpool with this many extra threads, " |
| 57 | "defaulting to one extra thread per core."); |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 58 | |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 59 | DEFINE_int32(gpuThreads, 0, "Create this many extra threads to assist with GPU work, " |
| 60 | "including software path rendering."); |
| 61 | |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 62 | DEFINE_bool2(verbose, v, false, "enable verbose output from the test driver."); |
| 63 | |
| 64 | DEFINE_bool2(veryVerbose, V, false, "tell individual tests to be verbose."); |
mtklein | b511042 | 2014-08-07 15:20:02 -0700 | [diff] [blame] | 65 | |
| 66 | DEFINE_string2(writePath, w, "", "If set, write bitmaps here as .pngs."); |
mtklein | ea65bfa | 2014-09-09 07:59:46 -0700 | [diff] [blame] | 67 | |
| 68 | DEFINE_string(key, "", |
| 69 | "Space-separated key/value pairs to add to JSON identifying this builder."); |
| 70 | DEFINE_string(properties, "", |
| 71 | "Space-separated key/value pairs to add to JSON identifying this run."); |
benjaminwagner | 8d61f0d | 2016-01-25 13:02:40 -0800 | [diff] [blame] | 72 | DEFINE_bool2(pre_log, p, false, "Log before running each test. May be incomprehensible when threading"); |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 73 | |
Yuqian Li | ba62b4a | 2016-12-14 13:46:53 -0500 | [diff] [blame] | 74 | DEFINE_bool(analyticAA, true, "If false, disable analytic anti-aliasing"); |
liyuqian | 38911a7 | 2016-10-04 11:23:22 -0700 | [diff] [blame] | 75 | |
Yuqian Li | 550148b | 2017-01-13 10:13:13 -0500 | [diff] [blame] | 76 | DEFINE_bool(forceAnalyticAA, false, "Force analytic anti-aliasing even if the path is complicated: " |
| 77 | "whether it's concave or convex, we consider a path complicated" |
| 78 | "if its number of points is comparable to its resolution."); |
| 79 | |
Yuqian Li | 49fd5d5 | 2017-08-03 13:03:03 -0400 | [diff] [blame] | 80 | #if defined(SK_SUPPORT_LEGACY_DELTA_AA) || (defined(_MSC_VER) && !defined(__clang__)) |
Yuqian Li | 93fe0cc | 2017-07-29 13:41:52 -0400 | [diff] [blame] | 81 | constexpr bool kDefaultDeltaAA = false; |
| 82 | #else |
| 83 | constexpr bool kDefaultDeltaAA = true; |
| 84 | #endif |
| 85 | DEFINE_bool(deltaAA, kDefaultDeltaAA, |
Yuqian Li | df60e36 | 2017-07-25 11:26:31 -0400 | [diff] [blame] | 86 | "If true, use delta anti-aliasing in suitable cases (it overrides forceAnalyticAA."); |
| 87 | |
| 88 | DEFINE_bool(forceDeltaAA, false, "Force delta anti-aliasing for all paths."); |
| 89 | |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 90 | bool CollectImages(SkCommandLineFlags::StringArray images, SkTArray<SkString>* output) { |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 91 | SkASSERT(output); |
| 92 | |
| 93 | static const char* const exts[] = { |
Leon Scroggins | 427da6f | 2016-12-16 13:51:59 +0000 | [diff] [blame] | 94 | "bmp", "gif", "jpg", "jpeg", "png", "webp", "ktx", "astc", "wbmp", "ico", |
| 95 | "BMP", "GIF", "JPG", "JPEG", "PNG", "WEBP", "KTX", "ASTC", "WBMP", "ICO", |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 96 | #ifdef SK_CODEC_DECODES_RAW |
| 97 | "arw", "cr2", "dng", "nef", "nrw", "orf", "raf", "rw2", "pef", "srw", |
| 98 | "ARW", "CR2", "DNG", "NEF", "NRW", "ORF", "RAF", "RW2", "PEF", "SRW", |
| 99 | #endif |
| 100 | }; |
| 101 | |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 102 | for (int i = 0; i < images.count(); ++i) { |
| 103 | const char* flag = images[i]; |
scroggo | 8673714 | 2016-02-03 12:19:11 -0800 | [diff] [blame] | 104 | if (!sk_exists(flag)) { |
| 105 | SkDebugf("%s does not exist!\n", flag); |
| 106 | return false; |
| 107 | } |
| 108 | |
| 109 | if (sk_isdir(flag)) { |
| 110 | // If the value passed in is a directory, add all the images |
| 111 | bool foundAnImage = false; |
| 112 | for (const char* ext : exts) { |
| 113 | SkOSFile::Iter it(flag, ext); |
| 114 | SkString file; |
| 115 | while (it.next(&file)) { |
| 116 | foundAnImage = true; |
| 117 | output->push_back() = SkOSPath::Join(flag, file.c_str()); |
| 118 | } |
| 119 | } |
| 120 | if (!foundAnImage) { |
| 121 | SkDebugf("No supported images found in %s!\n", flag); |
| 122 | return false; |
| 123 | } |
| 124 | } else { |
| 125 | // Also add the value if it is a single image |
| 126 | output->push_back() = flag; |
| 127 | } |
| 128 | } |
| 129 | return true; |
| 130 | } |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 131 | |
| 132 | SkExecutor* GpuExecutorForTools() { |
| 133 | static std::unique_ptr<SkExecutor> gGpuExecutor = (0 != FLAGS_gpuThreads) |
Mike Klein | 022cfa2 | 2017-09-01 11:53:16 -0400 | [diff] [blame^] | 134 | ? SkExecutor::MakeFIFOThreadPool(FLAGS_gpuThreads) : nullptr; |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 135 | return gGpuExecutor.get(); |
| 136 | } |