Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 1 | // Copyright 2019 Google LLC. |
| 2 | // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. |
| 3 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 4 | #include "experimental/svg/model/SkSVGDOM.h" |
| 5 | #include "gm/gm.h" |
| 6 | #include "include/codec/SkCodec.h" |
Robert Phillips | e19babf | 2020-04-06 13:57:30 -0400 | [diff] [blame] | 7 | #include "include/core/SkCanvas.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/core/SkColorSpace.h" |
| 9 | #include "include/core/SkGraphics.h" |
| 10 | #include "include/core/SkPicture.h" |
| 11 | #include "include/core/SkPictureRecorder.h" |
| 12 | #include "include/docs/SkPDFDocument.h" |
| 13 | #include "include/gpu/GrContextOptions.h" |
Robert Phillips | 7b4e43c | 2020-07-01 16:59:17 -0400 | [diff] [blame] | 14 | #include "include/gpu/GrDirectContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 15 | #include "include/private/SkTHash.h" |
| 16 | #include "src/core/SkColorSpacePriv.h" |
| 17 | #include "src/core/SkMD5.h" |
| 18 | #include "src/core/SkOSFile.h" |
| 19 | #include "src/gpu/GrContextPriv.h" |
| 20 | #include "src/gpu/GrGpu.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 21 | #include "src/utils/SkOSPath.h" |
Mike Klein | fee0079 | 2019-11-21 16:18:47 -0600 | [diff] [blame] | 22 | #include "tests/Test.h" |
Jim Van Verth | 8a9a371 | 2019-05-31 10:49:12 -0400 | [diff] [blame] | 23 | #include "tools/AutoreleasePool.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 24 | #include "tools/CrashHandler.h" |
| 25 | #include "tools/HashAndEncode.h" |
| 26 | #include "tools/ToolUtils.h" |
| 27 | #include "tools/flags/CommandLineFlags.h" |
| 28 | #include "tools/flags/CommonFlags.h" |
| 29 | #include "tools/gpu/GrContextFactory.h" |
| 30 | #include "tools/gpu/MemoryCache.h" |
| 31 | #include "tools/trace/EventTracingPriv.h" |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 32 | #include <chrono> |
| 33 | #include <functional> |
| 34 | #include <stdio.h> |
| 35 | #include <stdlib.h> |
| 36 | |
Brian Osman | ca94656 | 2019-04-10 13:51:53 -0400 | [diff] [blame] | 37 | #if defined(SK_ENABLE_SKOTTIE) |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 38 | #include "modules/skottie/include/Skottie.h" |
Brian Osman | 849f4d6 | 2019-11-26 08:58:26 -0500 | [diff] [blame] | 39 | #include "modules/skresources/include/SkResources.h" |
Brian Osman | ca94656 | 2019-04-10 13:51:53 -0400 | [diff] [blame] | 40 | #endif |
| 41 | |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 42 | using sk_gpu_test::GrContextFactory; |
| 43 | |
Mike Klein | fee0079 | 2019-11-21 16:18:47 -0600 | [diff] [blame] | 44 | static DEFINE_bool(listGMs , false, "Print GM names and exit."); |
| 45 | static DEFINE_bool(listTests, false, "Print unit test names and exit."); |
| 46 | |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 47 | static DEFINE_string2(sources, s, "", "Which GMs, .skps, or images to draw."); |
| 48 | static DEFINE_string2(backend, b, "", "Backend used to create a canvas to draw into."); |
| 49 | |
Mike Klein | 4daf637 | 2019-04-03 11:19:45 -0400 | [diff] [blame] | 50 | static DEFINE_string(ct , "8888", "The color type for any raster backend."); |
| 51 | static DEFINE_string(at , "premul", "The alpha type for any raster backend."); |
| 52 | static DEFINE_string(gamut , "srgb", "The color gamut for any raster backend."); |
| 53 | static DEFINE_string(tf , "srgb", "The transfer function for any raster backend."); |
| 54 | static DEFINE_bool (legacy, false, "Use a null SkColorSpace instead of --gamut and --tf?"); |
Mike Klein | 2a57e79 | 2020-01-14 12:47:52 -0600 | [diff] [blame] | 55 | static DEFINE_bool (skvm , false, "Use SkVMBlitter when supported?"); |
Mike Klein | 31bfa83 | 2020-01-22 11:36:40 -0600 | [diff] [blame] | 56 | static DEFINE_bool (dylib , false, "Use SkVM via dylib?"); |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 57 | |
| 58 | static DEFINE_int (samples , 0, "Samples per pixel in GPU backends."); |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 59 | static DEFINE_bool (stencils, true, "If false, avoid stencil buffers in GPU backends."); |
| 60 | static DEFINE_bool (dit , false, "Use device-independent text in GPU backends."); |
| 61 | static DEFINE_string(surf , "default", "Backing store for GPU backend surfaces."); |
| 62 | |
| 63 | static DEFINE_bool( preAbandonGpuContext, false, "Abandon the GrContext before drawing."); |
| 64 | static DEFINE_bool( abandonGpuContext, false, "Abandon the GrContext after drawing."); |
| 65 | static DEFINE_bool(releaseAndAbandonGpuContext, false, |
| 66 | "Release all GPU resources and abandon the GrContext after drawing."); |
| 67 | |
| 68 | static DEFINE_bool(decodeToDst, false, |
| 69 | "Decode images to destination format rather than suggested natural format."); |
| 70 | |
Mike Klein | c245bd9 | 2019-03-27 14:31:09 -0500 | [diff] [blame] | 71 | static DEFINE_double(rasterDPI, SK_ScalarDefaultRasterDPI, |
| 72 | "DPI for rasterized content in vector backends like --backend pdf."); |
| 73 | static DEFINE_bool(PDFA, false, "Create PDF/A with --backend pdf?"); |
| 74 | |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 75 | static DEFINE_bool (cpuDetect, true, "Detect CPU features for runtime optimizations?"); |
| 76 | static DEFINE_string2(writePath, w, "", "Write .pngs to this directory if set."); |
Mike Klein | ed2cec4 | 2019-11-01 10:51:01 -0500 | [diff] [blame] | 77 | static DEFINE_bool (quick, false, "Skip image hashing and encoding?"); |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 78 | |
Brian Osman | 5aa11fb | 2019-04-08 16:40:36 -0400 | [diff] [blame] | 79 | static DEFINE_string(writeShaders, "", "Write GLSL shaders to this directory if set."); |
| 80 | |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 81 | static DEFINE_string(key, "", "Metadata passed through to .png encoder and .json output."); |
Mike Klein | 7b8bc53 | 2019-04-09 11:19:47 -0500 | [diff] [blame] | 82 | static DEFINE_string(properties, "", "Metadata passed through to .png encoder and .json output."); |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 83 | |
| 84 | template <typename T> |
| 85 | struct FlagOption { |
| 86 | const char* label; |
| 87 | T value; |
| 88 | }; |
| 89 | |
| 90 | template <typename T, int N> |
| 91 | static bool parse_flag(const CommandLineFlags::StringArray& flag, |
| 92 | const char* flag_name, |
| 93 | const FlagOption<T> (&array)[N], |
| 94 | T* value) { |
| 95 | for (auto entry : array) { |
| 96 | if (flag.contains(entry.label)) { |
| 97 | *value = entry.value; |
| 98 | return true; |
| 99 | } |
| 100 | } |
| 101 | fprintf(stderr, "Known values for --%s:\n", flag_name); |
| 102 | for (auto entry : array) { |
| 103 | fprintf(stderr, " --%s %s\n", flag_name, entry.label); |
| 104 | } |
| 105 | return false; |
| 106 | } |
| 107 | |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 108 | struct Result { |
| 109 | enum { Ok, Skip, Fail} status; |
| 110 | SkString failure; |
| 111 | }; |
| 112 | static const Result ok = {Result::Ok, {}}, |
| 113 | skip = {Result::Skip, {}}; |
| 114 | |
Adlai Holler | 684838f | 2020-05-12 10:41:04 -0400 | [diff] [blame] | 115 | static Result fail(const char* why) { |
| 116 | return { Result::Fail, SkString(why) }; |
| 117 | } |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 118 | template <typename... Args> |
Adlai Holler | 684838f | 2020-05-12 10:41:04 -0400 | [diff] [blame] | 119 | static Result fail(const char* whyFmt, Args... args) { |
| 120 | return { Result::Fail, SkStringPrintf(whyFmt, args...) }; |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 124 | struct Source { |
| 125 | SkString name; |
| 126 | SkISize size; |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 127 | std::function<Result(SkCanvas*)> draw; |
| 128 | std::function<void(GrContextOptions*)> tweak = [](GrContextOptions*){}; |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 129 | }; |
| 130 | |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 131 | static void init(Source* source, std::shared_ptr<skiagm::GM> gm) { |
| 132 | source->size = gm->getISize(); |
| 133 | source->tweak = [gm](GrContextOptions* options) { gm->modifyGrContextOptions(options); }; |
| 134 | source->draw = [gm](SkCanvas* canvas) { |
Adlai Holler | e3ad527 | 2020-07-07 10:27:55 -0400 | [diff] [blame] | 135 | auto direct = GrAsDirectContext(canvas->recordingContext()); |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 136 | |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 137 | SkString err; |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 138 | switch (gm->gpuSetup(direct, canvas, &err)) { |
Robert Phillips | 900630c | 2020-06-24 10:35:00 -0400 | [diff] [blame] | 139 | case skiagm::DrawResult::kOk : break; |
| 140 | case skiagm::DrawResult::kSkip: return skip; |
| 141 | case skiagm::DrawResult::kFail: return fail(err.c_str()); |
| 142 | } |
| 143 | |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 144 | switch (gm->draw(canvas, &err)) { |
| 145 | case skiagm::DrawResult::kOk: break; |
| 146 | case skiagm::DrawResult::kSkip: return skip; |
| 147 | case skiagm::DrawResult::kFail: return fail(err.c_str()); |
| 148 | } |
| 149 | return ok; |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 150 | }; |
| 151 | } |
| 152 | |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 153 | static void init(Source* source, sk_sp<SkPicture> pic) { |
| 154 | source->size = pic->cullRect().roundOut().size(); |
| 155 | source->draw = [pic](SkCanvas* canvas) { |
| 156 | canvas->drawPicture(pic); |
| 157 | return ok; |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 158 | }; |
| 159 | } |
| 160 | |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 161 | static void init(Source* source, std::shared_ptr<SkCodec> codec) { |
| 162 | source->size = codec->dimensions(); |
| 163 | source->draw = [codec](SkCanvas* canvas) { |
| 164 | SkImageInfo info = codec->getInfo(); |
| 165 | if (FLAGS_decodeToDst) { |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 166 | info = canvas->imageInfo().makeDimensions(info.dimensions()); |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 167 | } |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 168 | |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 169 | SkBitmap bm; |
| 170 | bm.allocPixels(info); |
| 171 | switch (SkCodec::Result result = codec->getPixels(info, bm.getPixels(), bm.rowBytes())) { |
| 172 | case SkCodec::kSuccess: |
| 173 | case SkCodec::kErrorInInput: |
| 174 | case SkCodec::kIncompleteInput: canvas->drawBitmap(bm, 0,0); |
| 175 | break; |
| 176 | default: return fail("codec->getPixels() failed: %d\n", result); |
| 177 | } |
| 178 | return ok; |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 179 | }; |
| 180 | } |
| 181 | |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 182 | static void init(Source* source, sk_sp<SkSVGDOM> svg) { |
| 183 | source->size = svg->containerSize().isEmpty() ? SkISize{1000,1000} |
| 184 | : svg->containerSize().toCeil(); |
| 185 | source->draw = [svg](SkCanvas* canvas) { |
| 186 | svg->render(canvas); |
| 187 | return ok; |
Mike Klein | 2292426 | 2019-04-02 14:14:56 -0400 | [diff] [blame] | 188 | }; |
| 189 | } |
| 190 | |
Brian Osman | ca94656 | 2019-04-10 13:51:53 -0400 | [diff] [blame] | 191 | #if defined(SK_ENABLE_SKOTTIE) |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 192 | static void init(Source* source, sk_sp<skottie::Animation> animation) { |
| 193 | source->size = {1000,1000}; |
| 194 | source->draw = [animation](SkCanvas* canvas) { |
| 195 | canvas->clear(SK_ColorWHITE); |
Mike Klein | 2292426 | 2019-04-02 14:14:56 -0400 | [diff] [blame] | 196 | |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 197 | // Draw frames in a shuffled order to exercise nonlinear frame progression. |
| 198 | // The film strip will still be in time order, just drawn out of order. |
| 199 | const int order[] = { 4, 0, 3, 1, 2 }; |
| 200 | const int tiles = SK_ARRAY_COUNT(order); |
| 201 | const float dim = 1000.0f / tiles; |
Mike Klein | 2292426 | 2019-04-02 14:14:56 -0400 | [diff] [blame] | 202 | |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 203 | const float dt = 1.0f / (tiles*tiles - 1); |
Mike Klein | 2292426 | 2019-04-02 14:14:56 -0400 | [diff] [blame] | 204 | |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 205 | for (int y : order) |
| 206 | for (int x : order) { |
| 207 | SkRect dst = {x*dim, y*dim, (x+1)*dim, (y+1)*dim}; |
Mike Klein | 2292426 | 2019-04-02 14:14:56 -0400 | [diff] [blame] | 208 | |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 209 | SkAutoCanvasRestore _(canvas, true/*save now*/); |
| 210 | canvas->clipRect(dst, /*aa=*/true); |
| 211 | canvas->concat(SkMatrix::MakeRectToRect(SkRect::MakeSize(animation->size()), |
| 212 | dst, |
| 213 | SkMatrix::kCenter_ScaleToFit)); |
| 214 | float t = (y*tiles + x) * dt; |
| 215 | animation->seek(t); |
| 216 | animation->render(canvas); |
| 217 | } |
| 218 | return ok; |
Mike Klein | 6253d90 | 2019-03-27 15:09:12 -0500 | [diff] [blame] | 219 | }; |
| 220 | } |
Brian Osman | ca94656 | 2019-04-10 13:51:53 -0400 | [diff] [blame] | 221 | #endif |
Mike Klein | 6253d90 | 2019-03-27 15:09:12 -0500 | [diff] [blame] | 222 | |
Mike Klein | fee0079 | 2019-11-21 16:18:47 -0600 | [diff] [blame] | 223 | static void init(Source* source, const skiatest::Test& test) { |
| 224 | source->size = {1,1}; |
| 225 | source->draw = [test](SkCanvas* canvas) { |
| 226 | struct Reporter : public skiatest::Reporter { |
| 227 | SkString msg; |
| 228 | |
| 229 | void reportFailed(const skiatest::Failure& failure) override { |
Mike Klein | 484b63b | 2020-04-15 12:43:12 -0500 | [diff] [blame] | 230 | msg += failure.toString(); |
| 231 | msg += "\n"; |
Mike Klein | fee0079 | 2019-11-21 16:18:47 -0600 | [diff] [blame] | 232 | } |
| 233 | } reporter; |
| 234 | |
| 235 | test.run(&reporter, GrContextOptions{}); |
| 236 | |
| 237 | if (reporter.msg.isEmpty()) { |
| 238 | canvas->clear(SK_ColorGREEN); |
| 239 | return ok; |
| 240 | } |
| 241 | |
| 242 | canvas->clear(SK_ColorRED); |
| 243 | return fail(reporter.msg.c_str()); |
| 244 | }; |
| 245 | } |
| 246 | |
Mike Klein | a5c2717 | 2019-04-02 10:26:48 -0400 | [diff] [blame] | 247 | static sk_sp<SkImage> draw_with_cpu(std::function<bool(SkCanvas*)> draw, |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 248 | SkImageInfo info) { |
| 249 | if (sk_sp<SkSurface> surface = SkSurface::MakeRaster(info)) { |
Mike Klein | a5c2717 | 2019-04-02 10:26:48 -0400 | [diff] [blame] | 250 | if (draw(surface->getCanvas())) { |
| 251 | return surface->makeImageSnapshot(); |
| 252 | } |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 253 | } |
| 254 | return nullptr; |
| 255 | } |
| 256 | |
Mike Klein | a5c2717 | 2019-04-02 10:26:48 -0400 | [diff] [blame] | 257 | static sk_sp<SkData> draw_as_skp(std::function<bool(SkCanvas*)> draw, |
Mike Klein | 9b46209 | 2019-03-27 13:52:35 -0500 | [diff] [blame] | 258 | SkImageInfo info) { |
| 259 | SkPictureRecorder recorder; |
Mike Klein | a5c2717 | 2019-04-02 10:26:48 -0400 | [diff] [blame] | 260 | if (draw(recorder.beginRecording(info.width(), info.height()))) { |
| 261 | return recorder.finishRecordingAsPicture()->serialize(); |
| 262 | } |
| 263 | return nullptr; |
Mike Klein | 9b46209 | 2019-03-27 13:52:35 -0500 | [diff] [blame] | 264 | } |
| 265 | |
Mike Klein | a5c2717 | 2019-04-02 10:26:48 -0400 | [diff] [blame] | 266 | static sk_sp<SkData> draw_as_pdf(std::function<bool(SkCanvas*)> draw, |
Mike Klein | c245bd9 | 2019-03-27 14:31:09 -0500 | [diff] [blame] | 267 | SkImageInfo info, |
| 268 | SkString name) { |
| 269 | SkPDF::Metadata metadata; |
| 270 | metadata.fTitle = name; |
| 271 | metadata.fCreator = "Skia/FM"; |
| 272 | metadata.fRasterDPI = FLAGS_rasterDPI; |
| 273 | metadata.fPDFA = FLAGS_PDFA; |
| 274 | |
| 275 | SkDynamicMemoryWStream stream; |
| 276 | if (sk_sp<SkDocument> doc = SkPDF::MakeDocument(&stream, metadata)) { |
Mike Klein | a5c2717 | 2019-04-02 10:26:48 -0400 | [diff] [blame] | 277 | if (draw(doc->beginPage(info.width(), info.height()))) { |
| 278 | doc->endPage(); |
| 279 | doc->close(); |
| 280 | return stream.detachAsData(); |
| 281 | } |
Mike Klein | c245bd9 | 2019-03-27 14:31:09 -0500 | [diff] [blame] | 282 | } |
| 283 | return nullptr; |
| 284 | } |
| 285 | |
Mike Klein | a5c2717 | 2019-04-02 10:26:48 -0400 | [diff] [blame] | 286 | static sk_sp<SkImage> draw_with_gpu(std::function<bool(SkCanvas*)> draw, |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 287 | SkImageInfo info, |
| 288 | GrContextFactory::ContextType api, |
| 289 | GrContextFactory* factory) { |
| 290 | enum class SurfaceType { kDefault, kBackendTexture, kBackendRenderTarget }; |
| 291 | const FlagOption<SurfaceType> kSurfaceTypes[] = { |
| 292 | { "default", SurfaceType::kDefault }, |
| 293 | { "betex" , SurfaceType::kBackendTexture }, |
| 294 | { "bert" , SurfaceType::kBackendRenderTarget }, |
| 295 | }; |
| 296 | SurfaceType surfaceType; |
| 297 | if (!parse_flag(FLAGS_surf, "surf", kSurfaceTypes, &surfaceType)) { |
| 298 | return nullptr; |
| 299 | } |
| 300 | |
Chris Dalton | b3c9745 | 2019-06-25 20:07:56 -0600 | [diff] [blame] | 301 | auto overrides = GrContextFactory::ContextOverrides::kNone; |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 302 | if (!FLAGS_stencils) { overrides |= GrContextFactory::ContextOverrides::kAvoidStencilBuffers; } |
| 303 | |
Robert Phillips | 7b4e43c | 2020-07-01 16:59:17 -0400 | [diff] [blame] | 304 | auto context = factory->getContextInfo(api, overrides).directContext(); |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 305 | |
| 306 | uint32_t flags = FLAGS_dit ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag |
| 307 | : 0; |
| 308 | SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
| 309 | |
| 310 | sk_sp<SkSurface> surface; |
| 311 | GrBackendTexture backendTexture; |
| 312 | GrBackendRenderTarget backendRT; |
| 313 | |
| 314 | switch (surfaceType) { |
| 315 | case SurfaceType::kDefault: |
| 316 | surface = SkSurface::MakeRenderTarget(context, |
| 317 | SkBudgeted::kNo, |
| 318 | info, |
| 319 | FLAGS_samples, |
| 320 | &props); |
| 321 | break; |
| 322 | |
| 323 | case SurfaceType::kBackendTexture: |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 324 | backendTexture = context->createBackendTexture(info.width(), |
| 325 | info.height(), |
| 326 | info.colorType(), |
| 327 | GrMipMapped::kNo, |
Emircan Uysaler | 23ca4e7 | 2019-06-24 10:53:09 -0400 | [diff] [blame] | 328 | GrRenderable::kYes, |
| 329 | GrProtected::kNo); |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 330 | surface = SkSurface::MakeFromBackendTexture(context, |
| 331 | backendTexture, |
| 332 | kTopLeft_GrSurfaceOrigin, |
| 333 | FLAGS_samples, |
| 334 | info.colorType(), |
| 335 | info.refColorSpace(), |
| 336 | &props); |
| 337 | break; |
| 338 | |
| 339 | case SurfaceType::kBackendRenderTarget: |
| 340 | backendRT = context->priv().getGpu() |
| 341 | ->createTestingOnlyBackendRenderTarget(info.width(), |
| 342 | info.height(), |
| 343 | SkColorTypeToGrColorType(info.colorType())); |
| 344 | surface = SkSurface::MakeFromBackendRenderTarget(context, |
| 345 | backendRT, |
| 346 | kBottomLeft_GrSurfaceOrigin, |
| 347 | info.colorType(), |
| 348 | info.refColorSpace(), |
| 349 | &props); |
| 350 | break; |
| 351 | } |
| 352 | |
| 353 | if (!surface) { |
| 354 | fprintf(stderr, "Could not create GPU surface.\n"); |
| 355 | return nullptr; |
| 356 | } |
| 357 | |
| 358 | if (FLAGS_preAbandonGpuContext) { |
| 359 | factory->abandonContexts(); |
| 360 | } |
| 361 | |
Mike Klein | a5c2717 | 2019-04-02 10:26:48 -0400 | [diff] [blame] | 362 | sk_sp<SkImage> image; |
| 363 | if (draw(surface->getCanvas())) { |
| 364 | image = surface->makeImageSnapshot(); |
| 365 | } |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 366 | |
| 367 | if (FLAGS_abandonGpuContext) { |
| 368 | factory->abandonContexts(); |
| 369 | } else if (FLAGS_releaseAndAbandonGpuContext) { |
| 370 | factory->releaseResourcesAndAbandonContexts(); |
| 371 | } |
| 372 | |
| 373 | if (!context->abandoned()) { |
| 374 | surface.reset(); |
| 375 | if (backendTexture.isValid()) { |
Robert Phillips | 5c7a25b | 2019-05-20 08:38:07 -0400 | [diff] [blame] | 376 | context->deleteBackendTexture(backendTexture); |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 377 | } |
| 378 | if (backendRT.isValid()) { |
| 379 | context->priv().getGpu()->deleteTestingOnlyBackendRenderTarget(backendRT); |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | return image; |
| 384 | } |
| 385 | |
Mike Klein | 2a57e79 | 2020-01-14 12:47:52 -0600 | [diff] [blame] | 386 | extern bool gUseSkVMBlitter; |
Mike Klein | 31bfa83 | 2020-01-22 11:36:40 -0600 | [diff] [blame] | 387 | extern bool gSkVMJITViaDylib; |
Mike Klein | 2a57e79 | 2020-01-14 12:47:52 -0600 | [diff] [blame] | 388 | |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 389 | int main(int argc, char** argv) { |
| 390 | CommandLineFlags::Parse(argc, argv); |
Mike Klein | bf15b66 | 2019-04-15 11:32:16 -0500 | [diff] [blame] | 391 | SetupCrashHandler(); |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 392 | |
| 393 | if (FLAGS_cpuDetect) { |
| 394 | SkGraphics::Init(); |
| 395 | } |
Mike Klein | 31bfa83 | 2020-01-22 11:36:40 -0600 | [diff] [blame] | 396 | gUseSkVMBlitter = FLAGS_skvm; |
| 397 | gSkVMJITViaDylib = FLAGS_dylib; |
Mike Klein | 2a57e79 | 2020-01-14 12:47:52 -0600 | [diff] [blame] | 398 | |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 399 | initializeEventTracingForTools(); |
| 400 | ToolUtils::SetDefaultFontMgr(); |
| 401 | SetAnalyticAAFromCommonFlags(); |
| 402 | |
| 403 | GrContextOptions baseOptions; |
| 404 | SetCtxOptionsFromCommonFlags(&baseOptions); |
| 405 | |
Brian Osman | 5aa11fb | 2019-04-08 16:40:36 -0400 | [diff] [blame] | 406 | sk_gpu_test::MemoryCache memoryCache; |
| 407 | if (!FLAGS_writeShaders.isEmpty()) { |
| 408 | baseOptions.fPersistentCache = &memoryCache; |
Brian Osman | a66081d | 2019-09-03 14:59:26 -0400 | [diff] [blame] | 409 | baseOptions.fShaderCacheStrategy = GrContextOptions::ShaderCacheStrategy::kBackendSource; |
Brian Osman | 5aa11fb | 2019-04-08 16:40:36 -0400 | [diff] [blame] | 410 | } |
| 411 | |
Mike Klein | cbe93ee | 2019-04-02 17:00:54 -0400 | [diff] [blame] | 412 | SkTHashMap<SkString, skiagm::GMFactory> gm_factories; |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 413 | for (skiagm::GMFactory factory : skiagm::GMRegistry::Range()) { |
Hal Canary | edda565 | 2019-08-05 10:28:09 -0400 | [diff] [blame] | 414 | std::unique_ptr<skiagm::GM> gm{factory()}; |
Mike Klein | fee0079 | 2019-11-21 16:18:47 -0600 | [diff] [blame] | 415 | if (FLAGS_listGMs) { |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 416 | fprintf(stdout, "%s\n", gm->getName()); |
Mike Klein | cbe93ee | 2019-04-02 17:00:54 -0400 | [diff] [blame] | 417 | } else { |
| 418 | gm_factories.set(SkString{gm->getName()}, factory); |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 419 | } |
| 420 | } |
Mike Klein | fee0079 | 2019-11-21 16:18:47 -0600 | [diff] [blame] | 421 | |
| 422 | SkTHashMap<SkString, const skiatest::Test*> tests; |
| 423 | for (const skiatest::Test& test : skiatest::TestRegistry::Range()) { |
| 424 | if (test.needsGpu) { |
| 425 | continue; // TODO |
| 426 | } |
| 427 | if (FLAGS_listTests) { |
| 428 | fprintf(stdout, "%s\n", test.name); |
| 429 | } else { |
| 430 | tests.set(SkString{test.name}, &test); |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | if (FLAGS_listGMs || FLAGS_listTests) { |
Mike Klein | cbe93ee | 2019-04-02 17:00:54 -0400 | [diff] [blame] | 435 | return 0; |
| 436 | } |
Mike Klein | fee0079 | 2019-11-21 16:18:47 -0600 | [diff] [blame] | 437 | if (FLAGS_sources.isEmpty()) { |
| 438 | fprintf(stderr, "Please give me something to run using -s/--sources!\n"); |
| 439 | return 1; |
| 440 | } |
Mike Klein | cbe93ee | 2019-04-02 17:00:54 -0400 | [diff] [blame] | 441 | |
| 442 | SkTArray<Source> sources; |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 443 | for (const SkString& name : FLAGS_sources) { |
| 444 | Source* source = &sources.push_back(); |
| 445 | |
| 446 | if (skiagm::GMFactory* factory = gm_factories.find(name)) { |
Hal Canary | edda565 | 2019-08-05 10:28:09 -0400 | [diff] [blame] | 447 | std::shared_ptr<skiagm::GM> gm{(*factory)()}; |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 448 | source->name = name; |
Ben Wagner | 406ff50 | 2019-08-12 16:39:24 -0400 | [diff] [blame] | 449 | init(source, std::move(gm)); |
Mike Klein | cbe93ee | 2019-04-02 17:00:54 -0400 | [diff] [blame] | 450 | continue; |
| 451 | } |
| 452 | |
Mike Klein | fee0079 | 2019-11-21 16:18:47 -0600 | [diff] [blame] | 453 | if (const skiatest::Test** test = tests.find(name)) { |
| 454 | source->name = name; |
| 455 | init(source, **test); |
| 456 | continue; |
| 457 | } |
| 458 | |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 459 | if (sk_sp<SkData> blob = SkData::MakeFromFileName(name.c_str())) { |
| 460 | source->name = SkOSPath::Basename(name.c_str()); |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 461 | |
Mike Klein | ce90d6f | 2019-03-29 11:14:14 -0500 | [diff] [blame] | 462 | if (name.endsWith(".skp")) { |
| 463 | if (sk_sp<SkPicture> pic = SkPicture::MakeFromData(blob.get())) { |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 464 | init(source, pic); |
Mike Klein | cbe93ee | 2019-04-02 17:00:54 -0400 | [diff] [blame] | 465 | continue; |
Mike Klein | ce90d6f | 2019-03-29 11:14:14 -0500 | [diff] [blame] | 466 | } |
| 467 | } else if (name.endsWith(".svg")) { |
| 468 | SkMemoryStream stream{blob}; |
| 469 | if (sk_sp<SkSVGDOM> svg = SkSVGDOM::MakeFromStream(stream)) { |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 470 | init(source, svg); |
Mike Klein | cbe93ee | 2019-04-02 17:00:54 -0400 | [diff] [blame] | 471 | continue; |
Mike Klein | ce90d6f | 2019-03-29 11:14:14 -0500 | [diff] [blame] | 472 | } |
Brian Osman | ca94656 | 2019-04-10 13:51:53 -0400 | [diff] [blame] | 473 | } |
| 474 | #if defined(SK_ENABLE_SKOTTIE) |
| 475 | else if (name.endsWith(".json")) { |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 476 | const SkString dir = SkOSPath::Dirname(name.c_str()); |
Mike Klein | 2292426 | 2019-04-02 14:14:56 -0400 | [diff] [blame] | 477 | if (sk_sp<skottie::Animation> animation = skottie::Animation::Builder() |
Brian Osman | 849f4d6 | 2019-11-26 08:58:26 -0500 | [diff] [blame] | 478 | .setResourceProvider(skresources::FileResourceProvider::Make(dir)) |
Mike Klein | 176da0b | 2019-04-03 07:44:24 -0400 | [diff] [blame] | 479 | .make((const char*)blob->data(), blob->size())) { |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 480 | init(source, animation); |
Mike Klein | cbe93ee | 2019-04-02 17:00:54 -0400 | [diff] [blame] | 481 | continue; |
Mike Klein | 2292426 | 2019-04-02 14:14:56 -0400 | [diff] [blame] | 482 | } |
Brian Osman | ca94656 | 2019-04-10 13:51:53 -0400 | [diff] [blame] | 483 | } |
| 484 | #endif |
| 485 | else if (std::shared_ptr<SkCodec> codec = SkCodec::MakeFromData(blob)) { |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 486 | init(source, codec); |
Mike Klein | cbe93ee | 2019-04-02 17:00:54 -0400 | [diff] [blame] | 487 | continue; |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 488 | } |
| 489 | } |
Mike Klein | cbe93ee | 2019-04-02 17:00:54 -0400 | [diff] [blame] | 490 | |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 491 | fprintf(stderr, "Don't understand source '%s'... bailing out.\n", name.c_str()); |
Mike Klein | cbe93ee | 2019-04-02 17:00:54 -0400 | [diff] [blame] | 492 | return 1; |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 493 | } |
| 494 | |
Mike Klein | 9b46209 | 2019-03-27 13:52:35 -0500 | [diff] [blame] | 495 | enum NonGpuBackends { |
| 496 | kCPU_Backend = -1, |
| 497 | kSKP_Backend = -2, |
Mike Klein | c245bd9 | 2019-03-27 14:31:09 -0500 | [diff] [blame] | 498 | kPDF_Backend = -3, |
Mike Klein | 9b46209 | 2019-03-27 13:52:35 -0500 | [diff] [blame] | 499 | }; |
| 500 | const FlagOption<int> kBackends[] = { |
| 501 | { "cpu" , kCPU_Backend }, |
| 502 | { "skp" , kSKP_Backend }, |
Mike Klein | c245bd9 | 2019-03-27 14:31:09 -0500 | [diff] [blame] | 503 | { "pdf" , kPDF_Backend }, |
Mike Klein | 9b46209 | 2019-03-27 13:52:35 -0500 | [diff] [blame] | 504 | { "gl" , GrContextFactory::kGL_ContextType }, |
| 505 | { "gles" , GrContextFactory::kGLES_ContextType }, |
| 506 | { "angle_d3d9_es2" , GrContextFactory::kANGLE_D3D9_ES2_ContextType }, |
| 507 | { "angle_d3d11_es2", GrContextFactory::kANGLE_D3D11_ES2_ContextType }, |
| 508 | { "angle_d3d11_es3", GrContextFactory::kANGLE_D3D11_ES3_ContextType }, |
| 509 | { "angle_gl_es2" , GrContextFactory::kANGLE_GL_ES2_ContextType }, |
| 510 | { "angle_gl_es3" , GrContextFactory::kANGLE_GL_ES3_ContextType }, |
| 511 | { "commandbuffer" , GrContextFactory::kCommandBuffer_ContextType }, |
| 512 | { "vk" , GrContextFactory::kVulkan_ContextType }, |
| 513 | { "mtl" , GrContextFactory::kMetal_ContextType }, |
| 514 | { "mock" , GrContextFactory::kMock_ContextType }, |
| 515 | }; |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 516 | const FlagOption<SkColorType> kColorTypes[] = { |
Mike Klein | d58e01b6 | 2020-07-17 13:52:41 -0500 | [diff] [blame^] | 517 | { "a8", kAlpha_8_SkColorType }, |
| 518 | { "g8", kGray_8_SkColorType }, |
| 519 | { "565", kRGB_565_SkColorType }, |
| 520 | { "4444", kARGB_4444_SkColorType }, |
| 521 | { "8888", kN32_SkColorType }, |
| 522 | { "888x", kRGB_888x_SkColorType }, |
| 523 | { "1010102", kRGBA_1010102_SkColorType }, |
| 524 | { "101010x", kRGB_101010x_SkColorType }, |
| 525 | { "bgra1010102", kBGRA_1010102_SkColorType }, |
| 526 | { "bgr101010x", kBGR_101010x_SkColorType }, |
| 527 | { "f16norm", kRGBA_F16Norm_SkColorType }, |
| 528 | { "f16", kRGBA_F16_SkColorType }, |
| 529 | { "f32", kRGBA_F32_SkColorType }, |
| 530 | { "rgba", kRGBA_8888_SkColorType }, |
| 531 | { "bgra", kBGRA_8888_SkColorType }, |
| 532 | { "16161616", kR16G16B16A16_unorm_SkColorType }, |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 533 | }; |
| 534 | const FlagOption<SkAlphaType> kAlphaTypes[] = { |
| 535 | { "premul", kPremul_SkAlphaType }, |
| 536 | { "unpremul", kUnpremul_SkAlphaType }, |
| 537 | }; |
| 538 | const FlagOption<skcms_Matrix3x3> kGamuts[] = { |
| 539 | { "srgb", SkNamedGamut::kSRGB }, |
Mike Klein | b147ace | 2020-01-16 11:11:06 -0600 | [diff] [blame] | 540 | { "p3", SkNamedGamut::kDisplayP3 }, |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 541 | { "rec2020", SkNamedGamut::kRec2020 }, |
| 542 | { "adobe", SkNamedGamut::kAdobeRGB }, |
| 543 | { "narrow", gNarrow_toXYZD50}, |
| 544 | }; |
| 545 | const FlagOption<skcms_TransferFunction> kTransferFunctions[] = { |
| 546 | { "srgb" , SkNamedTransferFn::kSRGB }, |
Hal Canary | be67a17 | 2019-05-24 10:13:36 -0400 | [diff] [blame] | 547 | { "rec2020", SkNamedTransferFn::kRec2020 }, |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 548 | { "2.2" , SkNamedTransferFn::k2Dot2 }, |
| 549 | { "linear" , SkNamedTransferFn::kLinear }, |
| 550 | }; |
| 551 | |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 552 | |
Mike Klein | 9b46209 | 2019-03-27 13:52:35 -0500 | [diff] [blame] | 553 | int backend; |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 554 | SkColorType ct; |
| 555 | SkAlphaType at; |
| 556 | skcms_Matrix3x3 gamut; |
| 557 | skcms_TransferFunction tf; |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 558 | |
Mike Klein | 9b46209 | 2019-03-27 13:52:35 -0500 | [diff] [blame] | 559 | if (!parse_flag(FLAGS_backend, "backend", kBackends , &backend) || |
| 560 | !parse_flag(FLAGS_ct , "ct" , kColorTypes , &ct) || |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 561 | !parse_flag(FLAGS_at , "at" , kAlphaTypes , &at) || |
| 562 | !parse_flag(FLAGS_gamut , "gamut" , kGamuts , &gamut) || |
Mike Klein | 9b46209 | 2019-03-27 13:52:35 -0500 | [diff] [blame] | 563 | !parse_flag(FLAGS_tf , "tf" , kTransferFunctions, &tf)) { |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 564 | return 1; |
| 565 | } |
| 566 | |
Mike Klein | 4daf637 | 2019-04-03 11:19:45 -0400 | [diff] [blame] | 567 | sk_sp<SkColorSpace> cs = FLAGS_legacy ? nullptr |
| 568 | : SkColorSpace::MakeRGB(tf,gamut); |
| 569 | const SkImageInfo unsized_info = SkImageInfo::Make(0,0, ct,at,cs); |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 570 | |
Jim Van Verth | 8a9a371 | 2019-05-31 10:49:12 -0400 | [diff] [blame] | 571 | AutoreleasePool pool; |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 572 | for (auto source : sources) { |
| 573 | const auto start = std::chrono::steady_clock::now(); |
Mike Klein | 832d3c5 | 2019-04-02 15:23:46 -0400 | [diff] [blame] | 574 | fprintf(stdout, "%50s", source.name.c_str()); |
Mike Klein | bf15b66 | 2019-04-15 11:32:16 -0500 | [diff] [blame] | 575 | fflush(stdout); |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 576 | |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 577 | const SkImageInfo info = unsized_info.makeDimensions(source.size); |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 578 | |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 579 | auto draw = [&source](SkCanvas* canvas) { |
| 580 | Result result = source.draw(canvas); |
| 581 | switch (result.status) { |
| 582 | case Result::Ok: break; |
| 583 | case Result::Skip: return false; |
| 584 | case Result::Fail: |
John Stiles | 616da10 | 2020-06-12 14:07:41 -0400 | [diff] [blame] | 585 | SK_ABORT("%s", result.failure.c_str()); |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 586 | } |
| 587 | return true; |
| 588 | }; |
| 589 | |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 590 | GrContextOptions options = baseOptions; |
| 591 | source.tweak(&options); |
| 592 | GrContextFactory factory(options); // N.B. factory must outlive image |
| 593 | |
| 594 | sk_sp<SkImage> image; |
Mike Klein | 9b46209 | 2019-03-27 13:52:35 -0500 | [diff] [blame] | 595 | sk_sp<SkData> blob; |
| 596 | const char* ext = ".png"; |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 597 | switch (backend) { |
| 598 | case kCPU_Backend: |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 599 | image = draw_with_cpu(draw, info); |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 600 | break; |
Mike Klein | 9b46209 | 2019-03-27 13:52:35 -0500 | [diff] [blame] | 601 | case kSKP_Backend: |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 602 | blob = draw_as_skp(draw, info); |
Mike Klein | 9b46209 | 2019-03-27 13:52:35 -0500 | [diff] [blame] | 603 | ext = ".skp"; |
| 604 | break; |
Mike Klein | c245bd9 | 2019-03-27 14:31:09 -0500 | [diff] [blame] | 605 | case kPDF_Backend: |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 606 | blob = draw_as_pdf(draw, info, source.name); |
Mike Klein | c245bd9 | 2019-03-27 14:31:09 -0500 | [diff] [blame] | 607 | ext = ".pdf"; |
| 608 | break; |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 609 | default: |
Mike Klein | a833cff | 2019-04-09 11:52:40 -0500 | [diff] [blame] | 610 | image = draw_with_gpu(draw, info, (GrContextFactory::ContextType)backend, &factory); |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 611 | break; |
| 612 | } |
| 613 | |
Mike Klein | 9b46209 | 2019-03-27 13:52:35 -0500 | [diff] [blame] | 614 | if (!image && !blob) { |
Mike Klein | 832d3c5 | 2019-04-02 15:23:46 -0400 | [diff] [blame] | 615 | fprintf(stdout, "\tskipped\n"); |
Mike Klein | a5c2717 | 2019-04-02 10:26:48 -0400 | [diff] [blame] | 616 | continue; |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 617 | } |
| 618 | |
Mike Klein | ed2cec4 | 2019-11-01 10:51:01 -0500 | [diff] [blame] | 619 | // We read back a bitmap even when --quick is set and we won't use it, |
| 620 | // to keep us honest about deferred work, flushing pipelines, etc. |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 621 | SkBitmap bitmap; |
Mike Klein | 9b46209 | 2019-03-27 13:52:35 -0500 | [diff] [blame] | 622 | if (image && !image->asLegacyBitmap(&bitmap)) { |
Mike Klein | bf15b66 | 2019-04-15 11:32:16 -0500 | [diff] [blame] | 623 | SK_ABORT("SkImage::asLegacyBitmap() failed."); |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 624 | } |
| 625 | |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 626 | SkString md5; |
Mike Klein | ed2cec4 | 2019-11-01 10:51:01 -0500 | [diff] [blame] | 627 | if (!FLAGS_quick) { |
| 628 | HashAndEncode hashAndEncode{bitmap}; |
| 629 | { |
| 630 | SkMD5 hash; |
| 631 | if (image) { |
| 632 | hashAndEncode.write(&hash); |
| 633 | } else { |
| 634 | hash.write(blob->data(), blob->size()); |
Mike Klein | 9b46209 | 2019-03-27 13:52:35 -0500 | [diff] [blame] | 635 | } |
Mike Klein | ed2cec4 | 2019-11-01 10:51:01 -0500 | [diff] [blame] | 636 | |
| 637 | SkMD5::Digest digest = hash.finish(); |
| 638 | for (int i = 0; i < 16; i++) { |
| 639 | md5.appendf("%02x", digest.data[i]); |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | if (!FLAGS_writePath.isEmpty()) { |
| 644 | sk_mkdir(FLAGS_writePath[0]); |
| 645 | SkString path = SkStringPrintf("%s/%s%s", |
| 646 | FLAGS_writePath[0], source.name.c_str(), ext); |
| 647 | |
| 648 | if (image) { |
| 649 | if (!hashAndEncode.writePngTo(path.c_str(), md5.c_str(), |
| 650 | FLAGS_key, FLAGS_properties)) { |
| 651 | SK_ABORT("Could not write .png."); |
| 652 | } |
| 653 | } else { |
| 654 | SkFILEWStream file(path.c_str()); |
| 655 | file.write(blob->data(), blob->size()); |
| 656 | } |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 657 | } |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 658 | } |
| 659 | |
Mike Klein | 832d3c5 | 2019-04-02 15:23:46 -0400 | [diff] [blame] | 660 | const auto elapsed = std::chrono::steady_clock::now() - start; |
| 661 | fprintf(stdout, "\t%s\t%7dms\n", |
| 662 | md5.c_str(), |
| 663 | (int)std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count()); |
Jim Van Verth | 8a9a371 | 2019-05-31 10:49:12 -0400 | [diff] [blame] | 664 | pool.drain(); |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 665 | } |
| 666 | |
Brian Osman | 5aa11fb | 2019-04-08 16:40:36 -0400 | [diff] [blame] | 667 | if (!FLAGS_writeShaders.isEmpty()) { |
| 668 | sk_mkdir(FLAGS_writeShaders[0]); |
| 669 | GrBackendApi api = |
| 670 | GrContextFactory::ContextTypeBackend((GrContextFactory::ContextType)backend); |
| 671 | memoryCache.writeShadersToDisk(FLAGS_writeShaders[0], api); |
| 672 | |
| 673 | } |
| 674 | |
Mike Klein | 735c7ba | 2019-03-25 12:57:58 -0500 | [diff] [blame] | 675 | return 0; |
| 676 | } |