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 "GrContextOptions.h" 9 #include "SkCommonFlags.h" 10 #include "SkExecutor.h" 11 #include "SkOnce.h" 12 #include "SkOSFile.h" 13 #include "SkOSPath.h" 14 15 DEFINE_bool(cpu, true, "master switch for running CPU-bound work."); 16 17 DEFINE_bool(dryRun, false, 18 "just print the tests that would be run, without actually running them."); 19 20 DEFINE_bool(gpu, true, "master switch for running GPU-bound work."); 21 22 DEFINE_string(images, "", "List of images and/or directories to decode. A directory with no images" 23 " is treated as a fatal error."); 24 25 DEFINE_string(colorImages, "", "List of images and/or directories to decode with color correction. " 26 "A directory with no images is treated as a fatal error."); 27 28 DEFINE_bool(simpleCodec, false, "Runs of a subset of the codec tests. " 29 "For DM, this means no scaling or subsetting, always using the " 30 "canvas color type. " 31 "For nanobench, this means always N32, Premul or Opaque."); 32 33 DEFINE_string2(match, m, nullptr, 34 "[~][^]substring[$] [...] of name to run.\n" 35 "Multiple matches may be separated by spaces.\n" 36 "~ causes a matching name to always be skipped\n" 37 "^ requires the start of the name to match\n" 38 "$ requires the end of the name to match\n" 39 "^ and $ requires an exact match\n" 40 "If a name does not match any list entry,\n" 41 "it is skipped unless some list entry starts with ~"); 42 43 DEFINE_bool2(quiet, q, false, "if true, don't print status updates."); 44 45 DEFINE_bool(preAbandonGpuContext, false, "Test abandoning the GrContext before running the test."); 46 47 DEFINE_bool(abandonGpuContext, false, "Test abandoning the GrContext after running each test."); 48 49 DEFINE_bool(releaseAndAbandonGpuContext, false, 50 "Test releasing all gpu resources and abandoning the GrContext after running each " 51 "test"); 52 53 DEFINE_bool(disableDriverCorrectnessWorkarounds, false, "Disables all GPU driver correctness " 54 "workarounds"); 55 56 #ifdef SK_BUILD_FOR_ANDROID 57 DEFINE_string(skps, "/data/local/tmp/skps", "Directory to read skps from."); 58 DEFINE_string(jpgs, "/data/local/tmp/resources", "Directory to read jpgs from."); 59 DEFINE_string(lotties, "/data/local/tmp/lotties", "Directory to read (Bodymovin) jsons from."); 60 DEFINE_string(nimas, "/data/local/tmp/nimas", "Directory to read NIMA animations from."); 61 #else 62 DEFINE_string(skps, "skps", "Directory to read skps from."); 63 DEFINE_string(jpgs, "jpgs", "Directory to read jpgs from."); 64 DEFINE_string(lotties, "lotties", "Directory to read (Bodymovin) jsons from."); 65 DEFINE_string(nimas, "nimas", "Directory to read NIMA animations from."); 66 #endif 67 68 DEFINE_int32(skpViewportSize, 1000, "Width & height of the viewport used to crop skp rendering."); 69 70 DEFINE_bool(nativeFonts, true, "If true, use native font manager and rendering. " 71 "If false, fonts will draw as portably as possible."); 72 73 DEFINE_string(svgs, "", "Directory to read SVGs from, or a single SVG file."); 74 75 DEFINE_int32_2(threads, j, -1, "Run threadsafe tests on a threadpool with this many extra threads, " 76 "defaulting to one extra thread per core."); 77 78 DEFINE_bool2(verbose, v, false, "enable verbose output from the test driver."); 79 80 DEFINE_bool2(veryVerbose, V, false, "tell individual tests to be verbose."); 81 82 DEFINE_string2(writePath, w, "", "If set, write bitmaps here as .pngs."); 83 84 DEFINE_string(key, "", 85 "Space-separated key/value pairs to add to JSON identifying this builder."); 86 DEFINE_string(properties, "", 87 "Space-separated key/value pairs to add to JSON identifying this run."); 88 DEFINE_bool2(pre_log, p, false, "Log before running each test. May be incomprehensible when threading"); 89 90 DEFINE_bool(analyticAA, true, "If false, disable analytic anti-aliasing"); 91 92 DEFINE_bool(forceAnalyticAA, false, "Force analytic anti-aliasing even if the path is complicated: " 93 "whether it's concave or convex, we consider a path complicated" 94 "if its number of points is comparable to its resolution."); 95 96 #if (defined(_MSC_VER) && !defined(__clang__)) 97 constexpr bool kDefaultDeltaAA = false; 98 #else 99 constexpr bool kDefaultDeltaAA = true; 100 #endif 101 DEFINE_bool(deltaAA, kDefaultDeltaAA, 102 "If true, use delta anti-aliasing in suitable cases (it overrides forceAnalyticAA."); 103 104 DEFINE_bool(forceDeltaAA, false, "Force delta anti-aliasing for all paths."); 105 106 DEFINE_int32(backendTiles, 3, "Number of tiles in the experimental threaded backend."); 107 DEFINE_int32(backendThreads, 2, "Number of threads in the experimental threaded backend."); 108 109 bool CollectImages(SkCommandLineFlags::StringArray images, SkTArray<SkString>* output) { 110 SkASSERT(output); 111 112 static const char* const exts[] = { 113 "bmp", "gif", "jpg", "jpeg", "png", "webp", "ktx", "astc", "wbmp", "ico", 114 #if !defined(SK_BUILD_FOR_WIN) 115 "BMP", "GIF", "JPG", "JPEG", "PNG", "WEBP", "KTX", "ASTC", "WBMP", "ICO", 116 #endif 117 #ifdef SK_HAS_HEIF_LIBRARY 118 "heic", 119 #if !defined(SK_BUILD_FOR_WIN) 120 "HEIC", 121 #endif 122 #endif 123 #ifdef SK_CODEC_DECODES_RAW 124 "arw", "cr2", "dng", "nef", "nrw", "orf", "raf", "rw2", "pef", "srw", 125 #if !defined(SK_BUILD_FOR_WIN) 126 "ARW", "CR2", "DNG", "NEF", "NRW", "ORF", "RAF", "RW2", "PEF", "SRW", 127 #endif 128 #endif 129 }; 130 131 for (int i = 0; i < images.count(); ++i) { 132 const char* flag = images[i]; 133 if (!sk_exists(flag)) { 134 SkDebugf("%s does not exist!\n", flag); 135 return false; 136 } 137 138 if (sk_isdir(flag)) { 139 // If the value passed in is a directory, add all the images 140 bool foundAnImage = false; 141 for (const char* ext : exts) { 142 SkOSFile::Iter it(flag, ext); 143 SkString file; 144 while (it.next(&file)) { 145 foundAnImage = true; 146 output->push_back() = SkOSPath::Join(flag, file.c_str()); 147 } 148 } 149 if (!foundAnImage) { 150 SkDebugf("No supported images found in %s!\n", flag); 151 return false; 152 } 153 } else { 154 // Also add the value if it is a single image 155 output->push_back() = flag; 156 } 157 } 158 return true; 159 } 160 161 #include "SkCommonFlagsGpu.h" 162 163 DEFINE_int32(gpuThreads, 2, "Create this many extra threads to assist with GPU work, " 164 "including software path rendering. Defaults to two."); 165 166 DEFINE_bool(cachePathMasks, true, "Allows path mask textures to be cached in GPU configs."); 167 168 DEFINE_bool(noGS, false, "Disables support for geometry shaders."); 169 170 DEFINE_string(pr, "all", 171 "Set of enabled gpu path renderers. Defined as a list of: " 172 "[~]none [~]dashline [~]nvpr [~]ccpr [~]aahairline [~]aaconvex [~]aalinearizing " 173 "[~]small [~]tess] [~]all"); 174 175 DEFINE_bool(disableExplicitAlloc, false, "Disable explicit allocation of GPU resources"); 176 DEFINE_bool(reduceOpListSplitting, false, "Improve opList sorting"); 177 178 void SetCtxOptionsFromCommonFlags(GrContextOptions* ctxOptions) { 179 static std::unique_ptr<SkExecutor> gGpuExecutor = (0 != FLAGS_gpuThreads) 180 ? SkExecutor::MakeFIFOThreadPool(FLAGS_gpuThreads) : nullptr; 181 ctxOptions->fExecutor = gGpuExecutor.get(); 182 ctxOptions->fAllowPathMaskCaching = FLAGS_cachePathMasks; 183 ctxOptions->fSuppressGeometryShaders = FLAGS_noGS; 184 ctxOptions->fGpuPathRenderers = CollectGpuPathRenderersFromFlags(); 185 ctxOptions->fDisableDriverCorrectnessWorkarounds = FLAGS_disableDriverCorrectnessWorkarounds; 186 187 if (FLAGS_disableExplicitAlloc) { 188 ctxOptions->fExplicitlyAllocateGPUResources = GrContextOptions::Enable::kNo; 189 // Can't have sorting enabled when explicit allocation is disabled. 190 ctxOptions->fSortRenderTargets = GrContextOptions::Enable::kNo; 191 } 192 193 if (FLAGS_reduceOpListSplitting) { 194 ctxOptions->fReduceOpListSplitting = GrContextOptions::Enable::kYes; 195 } 196 } 197