scroggo | 478652e | 2015-03-25 07:11:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 8 | #ifndef DMSrcSink_DEFINED |
| 9 | #define DMSrcSink_DEFINED |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "gm/gm.h" |
| 12 | #include "include/android/SkBitmapRegionDecoder.h" |
| 13 | #include "include/core/SkBBHFactory.h" |
| 14 | #include "include/core/SkBitmap.h" |
| 15 | #include "include/core/SkCanvas.h" |
| 16 | #include "include/core/SkData.h" |
| 17 | #include "include/core/SkPicture.h" |
| 18 | #include "src/core/SkBBoxHierarchy.h" |
| 19 | #include "src/utils/SkMultiPictureDocument.h" |
| 20 | #include "tools/flags/CommonFlagsConfig.h" |
Brian Osman | 9c31047 | 2019-06-27 16:43:27 -0400 | [diff] [blame] | 21 | #include "tools/gpu/MemoryCache.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 22 | |
Brian Osman | ed58e00 | 2019-09-06 14:42:43 -0400 | [diff] [blame] | 23 | #include <functional> |
| 24 | |
Mike Reed | bae888e | 2017-02-18 16:50:45 -0500 | [diff] [blame] | 25 | //#define TEST_VIA_SVG |
| 26 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 27 | namespace DM { |
| 28 | |
| 29 | // This is just convenience. It lets you use either return "foo" or return SkStringPrintf(...). |
| 30 | struct ImplicitString : public SkString { |
| 31 | template <typename T> |
| 32 | ImplicitString(const T& s) : SkString(s) {} |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 33 | ImplicitString() : SkString("") {} |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 34 | }; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 35 | typedef ImplicitString Name; |
mtklein | 8d17a13 | 2015-01-30 11:42:31 -0800 | [diff] [blame] | 36 | typedef ImplicitString Path; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 37 | |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 38 | class Error { |
| 39 | public: |
| 40 | Error(const SkString& s) : fMsg(s), fFatal(!this->isEmpty()) {} |
| 41 | Error(const char* s) : fMsg(s), fFatal(!this->isEmpty()) {} |
| 42 | |
| 43 | Error(const Error&) = default; |
| 44 | Error& operator=(const Error&) = default; |
| 45 | |
| 46 | static Error Nonfatal(const SkString& s) { return Nonfatal(s.c_str()); } |
| 47 | static Error Nonfatal(const char* s) { |
| 48 | Error e(s); |
| 49 | e.fFatal = false; |
| 50 | return e; |
| 51 | } |
| 52 | |
| 53 | const char* c_str() const { return fMsg.c_str(); } |
| 54 | bool isEmpty() const { return fMsg.isEmpty(); } |
| 55 | bool isFatal() const { return fFatal; } |
| 56 | |
| 57 | private: |
| 58 | SkString fMsg; |
| 59 | bool fFatal; |
| 60 | }; |
| 61 | |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 62 | struct SinkFlags { |
Brian Salomon | bd7c551 | 2017-03-07 09:08:36 -0500 | [diff] [blame] | 63 | enum Type { kNull, kGPU, kVector, kRaster } type; |
| 64 | enum Approach { kDirect, kIndirect } approach; |
| 65 | enum Multisampled { kNotMultisampled, kMultisampled } multisampled; |
| 66 | SinkFlags(Type t, Approach a, Multisampled ms = kNotMultisampled) |
| 67 | : type(t), approach(a), multisampled(ms) {} |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 68 | }; |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 69 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 70 | struct Src { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 71 | virtual ~Src() {} |
| 72 | virtual Error SK_WARN_UNUSED_RESULT draw(SkCanvas*) const = 0; |
| 73 | virtual SkISize size() const = 0; |
| 74 | virtual Name name() const = 0; |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 75 | virtual void modifyGrContextOptions(GrContextOptions* options) const {} |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 76 | virtual bool veto(SinkFlags) const { return false; } |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 77 | |
halcanary | 45420a9 | 2016-06-02 12:41:14 -0700 | [diff] [blame] | 78 | virtual int pageCount() const { return 1; } |
| 79 | virtual Error SK_WARN_UNUSED_RESULT draw(int, SkCanvas* canvas) const { |
| 80 | return this->draw(canvas); |
| 81 | } |
| 82 | virtual SkISize size(int) const { return this->size(); } |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 83 | // Force Tasks using this Src to run on the main thread? |
| 84 | virtual bool serial() const { return false; } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | struct Sink { |
| 88 | virtual ~Sink() {} |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 89 | // You may write to either the bitmap or stream. If you write to log, we'll print that out. |
| 90 | virtual Error SK_WARN_UNUSED_RESULT draw(const Src&, SkBitmap*, SkWStream*, SkString* log) |
| 91 | const = 0; |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 92 | |
| 93 | // Force Tasks using this Sink to run on the main thread? |
| 94 | virtual bool serial() const { return false; } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 95 | |
| 96 | // File extension for the content draw() outputs, e.g. "png", "pdf". |
| 97 | virtual const char* fileExtension() const = 0; |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 98 | |
| 99 | virtual SinkFlags flags() const = 0; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 100 | }; |
| 101 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 102 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 103 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 104 | class GMSrc : public Src { |
| 105 | public: |
Hal Canary | 972eba3 | 2018-07-30 17:07:07 -0400 | [diff] [blame] | 106 | explicit GMSrc(skiagm::GMFactory); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 107 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 108 | Error draw(SkCanvas*) const override; |
| 109 | SkISize size() const override; |
| 110 | Name name() const override; |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 111 | void modifyGrContextOptions(GrContextOptions* options) const override; |
| 112 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 113 | private: |
Hal Canary | 972eba3 | 2018-07-30 17:07:07 -0400 | [diff] [blame] | 114 | skiagm::GMFactory fFactory; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 115 | }; |
| 116 | |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 117 | class CodecSrc : public Src { |
| 118 | public: |
scroggo | 9c59ebc | 2015-03-25 13:48:49 -0700 | [diff] [blame] | 119 | enum Mode { |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 120 | kCodec_Mode, |
msarett | bb25b53 | 2016-01-13 09:31:39 -0800 | [diff] [blame] | 121 | // We choose to test only one mode with zero initialized memory. |
| 122 | // This will exercise all of the interesting cases in SkSwizzler |
| 123 | // without doubling the size of our test suite. |
| 124 | kCodecZeroInit_Mode, |
scroggo | 9c59ebc | 2015-03-25 13:48:49 -0700 | [diff] [blame] | 125 | kScanline_Mode, |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 126 | kStripe_Mode, // Tests the skipping of scanlines |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 127 | kCroppedScanline_Mode, // Tests (jpeg) cropped scanline optimization |
scroggo | b636b45 | 2015-07-22 07:16:20 -0700 | [diff] [blame] | 128 | kSubset_Mode, // For codecs that support subsets directly. |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 129 | kAnimated_Mode, // For codecs that support animation. |
scroggo | 9c59ebc | 2015-03-25 13:48:49 -0700 | [diff] [blame] | 130 | }; |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 131 | enum DstColorType { |
| 132 | kGetFromCanvas_DstColorType, |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 133 | kGrayscale_Always_DstColorType, |
msarett | 34e0ec4 | 2016-04-22 16:27:24 -0700 | [diff] [blame] | 134 | kNonNative8888_Always_DstColorType, |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 135 | }; |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 136 | CodecSrc(Path, Mode, DstColorType, SkAlphaType, float); |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 137 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 138 | Error draw(SkCanvas*) const override; |
| 139 | SkISize size() const override; |
| 140 | Name name() const override; |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 141 | bool veto(SinkFlags) const override; |
scroggo | 3ac66e9 | 2016-02-08 15:09:48 -0800 | [diff] [blame] | 142 | bool serial() const override { return fRunSerially; } |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 143 | private: |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 144 | Path fPath; |
| 145 | Mode fMode; |
| 146 | DstColorType fDstColorType; |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 147 | SkAlphaType fDstAlphaType; |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 148 | float fScale; |
scroggo | 3ac66e9 | 2016-02-08 15:09:48 -0800 | [diff] [blame] | 149 | bool fRunSerially; |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 150 | }; |
| 151 | |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 152 | class AndroidCodecSrc : public Src { |
| 153 | public: |
scroggo | f8dc9df | 2016-05-16 09:04:13 -0700 | [diff] [blame] | 154 | AndroidCodecSrc(Path, CodecSrc::DstColorType, SkAlphaType, int sampleSize); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 155 | |
| 156 | Error draw(SkCanvas*) const override; |
| 157 | SkISize size() const override; |
| 158 | Name name() const override; |
| 159 | bool veto(SinkFlags) const override; |
scroggo | 3ac66e9 | 2016-02-08 15:09:48 -0800 | [diff] [blame] | 160 | bool serial() const override { return fRunSerially; } |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 161 | private: |
| 162 | Path fPath; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 163 | CodecSrc::DstColorType fDstColorType; |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 164 | SkAlphaType fDstAlphaType; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 165 | int fSampleSize; |
scroggo | 3ac66e9 | 2016-02-08 15:09:48 -0800 | [diff] [blame] | 166 | bool fRunSerially; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 167 | }; |
| 168 | |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 169 | // Allows for testing of various implementations of Android's BitmapRegionDecoder |
| 170 | class BRDSrc : public Src { |
| 171 | public: |
| 172 | enum Mode { |
| 173 | // Decode the entire image as one region. |
| 174 | kFullImage_Mode, |
| 175 | // Splits the image into multiple regions using a divisor and decodes the regions |
| 176 | // separately. Also, this test adds a border of a few pixels to each of the regions |
| 177 | // that it is decoding. This tests the behavior when a client asks for a region that |
| 178 | // does not fully fit in the image. |
| 179 | kDivisor_Mode, |
| 180 | }; |
| 181 | |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 182 | BRDSrc(Path, Mode, CodecSrc::DstColorType, uint32_t); |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 183 | |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 184 | Error draw(SkCanvas*) const override; |
| 185 | SkISize size() const override; |
| 186 | Name name() const override; |
| 187 | bool veto(SinkFlags) const override; |
| 188 | private: |
| 189 | Path fPath; |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 190 | Mode fMode; |
| 191 | CodecSrc::DstColorType fDstColorType; |
| 192 | uint32_t fSampleSize; |
| 193 | }; |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 194 | |
msarett | 1897631 | 2016-03-09 14:20:58 -0800 | [diff] [blame] | 195 | class ImageGenSrc : public Src { |
| 196 | public: |
| 197 | enum Mode { |
| 198 | kCodec_Mode, // Use CodecImageGenerator |
| 199 | kPlatform_Mode, // Uses CG or WIC |
| 200 | }; |
| 201 | ImageGenSrc(Path, Mode, SkAlphaType, bool); |
| 202 | |
| 203 | Error draw(SkCanvas*) const override; |
| 204 | SkISize size() const override; |
| 205 | Name name() const override; |
| 206 | bool veto(SinkFlags) const override; |
| 207 | bool serial() const override { return fRunSerially; } |
| 208 | private: |
| 209 | Path fPath; |
| 210 | Mode fMode; |
| 211 | SkAlphaType fDstAlphaType; |
| 212 | bool fIsGpu; |
| 213 | bool fRunSerially; |
| 214 | }; |
| 215 | |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 216 | class ColorCodecSrc : public Src { |
| 217 | public: |
Mike Klein | 0d5d142 | 2019-03-06 10:56:04 -0600 | [diff] [blame] | 218 | ColorCodecSrc(Path, bool decode_to_dst); |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 219 | |
| 220 | Error draw(SkCanvas*) const override; |
| 221 | SkISize size() const override; |
| 222 | Name name() const override; |
| 223 | bool veto(SinkFlags) const override; |
| 224 | private: |
Mike Klein | 0d5d142 | 2019-03-06 10:56:04 -0600 | [diff] [blame] | 225 | Path fPath; |
| 226 | bool fDecodeToDst; |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 227 | }; |
| 228 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 229 | class SKPSrc : public Src { |
| 230 | public: |
mtklein | 8d17a13 | 2015-01-30 11:42:31 -0800 | [diff] [blame] | 231 | explicit SKPSrc(Path path); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 232 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 233 | Error draw(SkCanvas*) const override; |
| 234 | SkISize size() const override; |
| 235 | Name name() const override; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 236 | private: |
mtklein | 8d17a13 | 2015-01-30 11:42:31 -0800 | [diff] [blame] | 237 | Path fPath; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 238 | }; |
| 239 | |
Chris Dalton | 184c37e | 2018-09-28 11:27:39 -0600 | [diff] [blame] | 240 | // This class extracts all the paths from an SKP and then removes unwanted paths according to the |
| 241 | // provided l/r trail. It then just draws the remaining paths. (Non-path draws are thrown out.) It |
| 242 | // is useful for finding a reduced repo case for path drawing bugs. |
| 243 | class BisectSrc : public SKPSrc { |
| 244 | public: |
| 245 | explicit BisectSrc(Path path, const char* trail); |
| 246 | |
| 247 | Error draw(SkCanvas*) const override; |
| 248 | |
| 249 | private: |
| 250 | SkString fTrail; |
| 251 | |
| 252 | typedef SKPSrc INHERITED; |
| 253 | }; |
| 254 | |
Robert Phillips | ad8a43f | 2017-08-30 12:06:35 -0400 | [diff] [blame] | 255 | |
Florin Malita | 87ccf33 | 2018-05-04 12:23:24 -0400 | [diff] [blame] | 256 | #if defined(SK_ENABLE_SKOTTIE) |
Florin Malita | 54f65c4 | 2018-01-16 17:04:30 -0500 | [diff] [blame] | 257 | class SkottieSrc final : public Src { |
Florin Malita | fc043dc | 2017-12-31 11:08:42 -0500 | [diff] [blame] | 258 | public: |
Florin Malita | 54f65c4 | 2018-01-16 17:04:30 -0500 | [diff] [blame] | 259 | explicit SkottieSrc(Path path); |
Florin Malita | fc043dc | 2017-12-31 11:08:42 -0500 | [diff] [blame] | 260 | |
| 261 | Error draw(SkCanvas*) const override; |
| 262 | SkISize size() const override; |
| 263 | Name name() const override; |
| 264 | bool veto(SinkFlags) const override; |
| 265 | |
| 266 | private: |
| 267 | // Generates a kTileCount x kTileCount filmstrip with evenly distributed frames. |
Florin Malita | 1022f74 | 2018-02-23 11:10:22 -0500 | [diff] [blame] | 268 | static constexpr int kTileCount = 5; |
Florin Malita | fc043dc | 2017-12-31 11:08:42 -0500 | [diff] [blame] | 269 | |
Florin Malita | 9f7d4cd | 2018-07-30 15:49:20 -0400 | [diff] [blame] | 270 | // Fit kTileCount x kTileCount frames to a 1000x1000 film strip. |
| 271 | static constexpr SkScalar kTargetSize = 1000; |
| 272 | static constexpr SkScalar kTileSize = kTargetSize / kTileCount; |
| 273 | |
| 274 | Path fPath; |
Florin Malita | fc043dc | 2017-12-31 11:08:42 -0500 | [diff] [blame] | 275 | }; |
Florin Malita | 124d5af | 2017-12-31 17:02:26 -0500 | [diff] [blame] | 276 | #endif |
Florin Malita | fc043dc | 2017-12-31 11:08:42 -0500 | [diff] [blame] | 277 | |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 278 | #if defined(SK_XML) |
fmalita | bdf3e5c | 2016-09-17 07:26:26 -0700 | [diff] [blame] | 279 | } // namespace DM |
| 280 | |
| 281 | class SkSVGDOM; |
| 282 | |
| 283 | namespace DM { |
| 284 | |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 285 | class SVGSrc : public Src { |
| 286 | public: |
| 287 | explicit SVGSrc(Path path); |
| 288 | |
| 289 | Error draw(SkCanvas*) const override; |
| 290 | SkISize size() const override; |
| 291 | Name name() const override; |
fmalita | 179d885 | 2016-08-16 14:23:29 -0700 | [diff] [blame] | 292 | bool veto(SinkFlags) const override; |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 293 | |
| 294 | private: |
fmalita | acd2f5c | 2016-11-08 07:13:45 -0800 | [diff] [blame] | 295 | Name fName; |
| 296 | sk_sp<SkSVGDOM> fDom; |
| 297 | SkScalar fScale; |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 298 | |
| 299 | typedef Src INHERITED; |
| 300 | }; |
| 301 | #endif // SK_XML |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 302 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 303 | |
halcanary | 45420a9 | 2016-06-02 12:41:14 -0700 | [diff] [blame] | 304 | class MSKPSrc : public Src { |
| 305 | public: |
| 306 | explicit MSKPSrc(Path path); |
| 307 | |
| 308 | int pageCount() const override; |
| 309 | Error draw(SkCanvas* c) const override; |
| 310 | Error draw(int, SkCanvas*) const override; |
| 311 | SkISize size() const override; |
| 312 | SkISize size(int) const override; |
| 313 | Name name() const override; |
| 314 | |
| 315 | private: |
| 316 | Path fPath; |
Hal Canary | 45cde31 | 2017-04-03 16:06:42 -0400 | [diff] [blame] | 317 | mutable SkTArray<SkDocumentPage> fPages; |
halcanary | 45420a9 | 2016-06-02 12:41:14 -0700 | [diff] [blame] | 318 | }; |
| 319 | |
| 320 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 321 | |
mtklein | ad66f9b | 2015-02-13 15:11:10 -0800 | [diff] [blame] | 322 | class NullSink : public Sink { |
| 323 | public: |
| 324 | NullSink() {} |
| 325 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 326 | Error draw(const Src& src, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 327 | const char* fileExtension() const override { return ""; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 328 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kNull, SinkFlags::kDirect }; } |
mtklein | ad66f9b | 2015-02-13 15:11:10 -0800 | [diff] [blame] | 329 | }; |
| 330 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 331 | class GPUSink : public Sink { |
| 332 | public: |
Brian Osman | 3fdfe28 | 2019-09-09 13:46:52 -0400 | [diff] [blame] | 333 | GPUSink(const SkCommandLineConfigGpu*, const GrContextOptions&); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 334 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 335 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 336 | Error onDraw(const Src&, SkBitmap*, SkWStream*, SkString*, |
Brian Osman | ed58e00 | 2019-09-06 14:42:43 -0400 | [diff] [blame] | 337 | const GrContextOptions& baseOptions, |
| 338 | std::function<void(GrContext*)> initContext = nullptr) const; |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 339 | |
Brian Salomon | b07fd4d | 2018-03-09 13:17:30 -0500 | [diff] [blame] | 340 | sk_gpu_test::GrContextFactory::ContextType contextType() const { return fContextType; } |
| 341 | const sk_gpu_test::GrContextFactory::ContextOverrides& contextOverrides() { |
| 342 | return fContextOverrides; |
| 343 | } |
| 344 | SkCommandLineConfigGpu::SurfType surfType() const { return fSurfType; } |
| 345 | bool useDIText() const { return fUseDIText; } |
Brian Osman | 3fdfe28 | 2019-09-09 13:46:52 -0400 | [diff] [blame] | 346 | bool serial() const override { return true; } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 347 | const char* fileExtension() const override { return "png"; } |
Brian Salomon | bd7c551 | 2017-03-07 09:08:36 -0500 | [diff] [blame] | 348 | SinkFlags flags() const override { |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 349 | SinkFlags::Multisampled ms = fSampleCount > 1 ? SinkFlags::kMultisampled |
Brian Salomon | fd171ed | 2017-03-08 11:38:45 -0500 | [diff] [blame] | 350 | : SinkFlags::kNotMultisampled; |
| 351 | return SinkFlags{ SinkFlags::kGPU, SinkFlags::kDirect, ms }; |
Brian Salomon | bd7c551 | 2017-03-07 09:08:36 -0500 | [diff] [blame] | 352 | } |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 353 | const GrContextOptions& baseContextOptions() const { return fBaseContextOptions; } |
| 354 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 355 | private: |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 356 | sk_gpu_test::GrContextFactory::ContextType fContextType; |
| 357 | sk_gpu_test::GrContextFactory::ContextOverrides fContextOverrides; |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 358 | SkCommandLineConfigGpu::SurfType fSurfType; |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 359 | int fSampleCount; |
| 360 | bool fUseDIText; |
| 361 | SkColorType fColorType; |
Brian Salomon | ce5ee60 | 2017-07-17 11:31:31 -0400 | [diff] [blame] | 362 | SkAlphaType fAlphaType; |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 363 | sk_sp<SkColorSpace> fColorSpace; |
Brian Osman | f21aa04 | 2017-08-21 16:48:46 -0400 | [diff] [blame] | 364 | GrContextOptions fBaseContextOptions; |
Brian Osman | 9c31047 | 2019-06-27 16:43:27 -0400 | [diff] [blame] | 365 | sk_gpu_test::MemoryCache fMemoryCache; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 366 | }; |
| 367 | |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 368 | class GPUThreadTestingSink : public GPUSink { |
| 369 | public: |
Brian Osman | 3fdfe28 | 2019-09-09 13:46:52 -0400 | [diff] [blame] | 370 | GPUThreadTestingSink(const SkCommandLineConfigGpu*, const GrContextOptions&); |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 371 | |
| 372 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 373 | |
Brian Osman | f1942de | 2017-08-30 14:50:22 -0400 | [diff] [blame] | 374 | const char* fileExtension() const override { |
| 375 | // Suppress writing out results from this config - we just want to do our matching test |
| 376 | return nullptr; |
| 377 | } |
| 378 | |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 379 | private: |
| 380 | std::unique_ptr<SkExecutor> fExecutor; |
| 381 | |
| 382 | typedef GPUSink INHERITED; |
| 383 | }; |
| 384 | |
Brian Salomon | 00a5eb8 | 2018-07-11 15:32:05 -0400 | [diff] [blame] | 385 | class GPUPersistentCacheTestingSink : public GPUSink { |
| 386 | public: |
Brian Osman | 3fdfe28 | 2019-09-09 13:46:52 -0400 | [diff] [blame] | 387 | GPUPersistentCacheTestingSink(const SkCommandLineConfigGpu*, const GrContextOptions&); |
Brian Salomon | 00a5eb8 | 2018-07-11 15:32:05 -0400 | [diff] [blame] | 388 | |
| 389 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 390 | |
| 391 | const char* fileExtension() const override { |
| 392 | // Suppress writing out results from this config - we just want to do our matching test |
| 393 | return nullptr; |
| 394 | } |
| 395 | |
| 396 | private: |
Brian Osman | f71b070 | 2019-04-03 13:04:16 -0400 | [diff] [blame] | 397 | int fCacheType; |
| 398 | |
Brian Salomon | 00a5eb8 | 2018-07-11 15:32:05 -0400 | [diff] [blame] | 399 | typedef GPUSink INHERITED; |
| 400 | }; |
| 401 | |
Brian Osman | ed58e00 | 2019-09-06 14:42:43 -0400 | [diff] [blame] | 402 | class GPUPrecompileTestingSink : public GPUSink { |
| 403 | public: |
Brian Osman | 3fdfe28 | 2019-09-09 13:46:52 -0400 | [diff] [blame] | 404 | GPUPrecompileTestingSink(const SkCommandLineConfigGpu*, const GrContextOptions&); |
Brian Osman | ed58e00 | 2019-09-06 14:42:43 -0400 | [diff] [blame] | 405 | |
| 406 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 407 | |
| 408 | const char* fileExtension() const override { |
| 409 | // Suppress writing out results from this config - we just want to do our matching test |
| 410 | return nullptr; |
| 411 | } |
| 412 | |
| 413 | private: |
| 414 | typedef GPUSink INHERITED; |
| 415 | }; |
| 416 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 417 | class PDFSink : public Sink { |
| 418 | public: |
Hal Canary | c7d295e | 2017-07-20 15:36:00 -0400 | [diff] [blame] | 419 | PDFSink(bool pdfa, SkScalar rasterDpi) : fPDFA(pdfa), fRasterDpi(rasterDpi) {} |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 420 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 421 | const char* fileExtension() const override { return "pdf"; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 422 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 423 | bool fPDFA; |
Hal Canary | c7d295e | 2017-07-20 15:36:00 -0400 | [diff] [blame] | 424 | SkScalar fRasterDpi; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 425 | }; |
| 426 | |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 427 | class XPSSink : public Sink { |
| 428 | public: |
| 429 | XPSSink(); |
| 430 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 431 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 432 | const char* fileExtension() const override { return "xps"; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 433 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 434 | }; |
| 435 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 436 | class RasterSink : public Sink { |
| 437 | public: |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 438 | explicit RasterSink(SkColorType, sk_sp<SkColorSpace> = nullptr); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 439 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 440 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 441 | const char* fileExtension() const override { return "png"; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 442 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kRaster, SinkFlags::kDirect }; } |
Yuqian Li | b8b6253 | 2018-02-23 14:13:36 +0800 | [diff] [blame] | 443 | |
Mike Klein | 48b6490 | 2018-07-25 13:28:44 -0400 | [diff] [blame] | 444 | private: |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 445 | SkColorType fColorType; |
| 446 | sk_sp<SkColorSpace> fColorSpace; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 447 | }; |
| 448 | |
Yuqian Li | b8b6253 | 2018-02-23 14:13:36 +0800 | [diff] [blame] | 449 | class ThreadedSink : public RasterSink { |
| 450 | public: |
| 451 | explicit ThreadedSink(SkColorType, sk_sp<SkColorSpace> = nullptr); |
| 452 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
Yuqian Li | b8b6253 | 2018-02-23 14:13:36 +0800 | [diff] [blame] | 453 | }; |
| 454 | |
mtklein | 9c3f17d | 2015-01-28 11:35:18 -0800 | [diff] [blame] | 455 | class SKPSink : public Sink { |
| 456 | public: |
| 457 | SKPSink(); |
| 458 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 459 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 460 | const char* fileExtension() const override { return "skp"; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 461 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
mtklein | 9c3f17d | 2015-01-28 11:35:18 -0800 | [diff] [blame] | 462 | }; |
| 463 | |
Hal Canary | 85c7fe8 | 2016-10-25 10:33:27 -0400 | [diff] [blame] | 464 | class DebugSink : public Sink { |
| 465 | public: |
| 466 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 467 | const char* fileExtension() const override { return "json"; } |
| 468 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
| 469 | }; |
| 470 | |
mtklein | 8a4527e | 2015-01-31 20:00:58 -0800 | [diff] [blame] | 471 | class SVGSink : public Sink { |
| 472 | public: |
Bryce Thomas | 95a7b76 | 2018-03-02 13:54:21 -0800 | [diff] [blame] | 473 | SVGSink(int pageIndex = 0); |
mtklein | 8a4527e | 2015-01-31 20:00:58 -0800 | [diff] [blame] | 474 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 475 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 476 | const char* fileExtension() const override { return "svg"; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 477 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
Bryce Thomas | 95a7b76 | 2018-03-02 13:54:21 -0800 | [diff] [blame] | 478 | |
| 479 | private: |
| 480 | int fPageIndex; |
mtklein | 8a4527e | 2015-01-31 20:00:58 -0800 | [diff] [blame] | 481 | }; |
| 482 | |
| 483 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 484 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 485 | |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 486 | class Via : public Sink { |
| 487 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 488 | explicit Via(Sink* sink) : fSink(sink) {} |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 489 | const char* fileExtension() const override { return fSink->fileExtension(); } |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 490 | bool serial() const override { return fSink->serial(); } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 491 | SinkFlags flags() const override { |
| 492 | SinkFlags flags = fSink->flags(); |
| 493 | flags.approach = SinkFlags::kIndirect; |
| 494 | return flags; |
| 495 | } |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 496 | protected: |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 497 | std::unique_ptr<Sink> fSink; |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 498 | }; |
| 499 | |
| 500 | class ViaMatrix : public Via { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 501 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 502 | ViaMatrix(SkMatrix, Sink*); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 503 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 504 | private: |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 505 | const SkMatrix fMatrix; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 506 | }; |
| 507 | |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 508 | class ViaUpright : public Via { |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 509 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 510 | ViaUpright(SkMatrix, Sink*); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 511 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 512 | private: |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 513 | const SkMatrix fMatrix; |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 514 | }; |
| 515 | |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 516 | class ViaSerialization : public Via { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 517 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 518 | explicit ViaSerialization(Sink* sink) : Via(sink) {} |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 519 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 520 | }; |
| 521 | |
mtklein | 4a34ecb | 2016-01-08 10:19:35 -0800 | [diff] [blame] | 522 | class ViaPicture : public Via { |
| 523 | public: |
| 524 | explicit ViaPicture(Sink* sink) : Via(sink) {} |
| 525 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 526 | }; |
| 527 | |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 528 | class ViaTiles : public Via { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 529 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 530 | ViaTiles(int w, int h, SkBBHFactory*, Sink*); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 531 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 532 | private: |
| 533 | const int fW, fH; |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 534 | std::unique_ptr<SkBBHFactory> fFactory; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 535 | }; |
| 536 | |
Robert Phillips | 33f02ed | 2018-03-27 08:06:57 -0400 | [diff] [blame] | 537 | class ViaDDL : public Via { |
| 538 | public: |
Brian Salomon | 5790420 | 2018-12-17 14:45:00 -0500 | [diff] [blame] | 539 | ViaDDL(int numReplays, int numDivisions, Sink* sink); |
Robert Phillips | 33f02ed | 2018-03-27 08:06:57 -0400 | [diff] [blame] | 540 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 541 | private: |
Brian Salomon | 5790420 | 2018-12-17 14:45:00 -0500 | [diff] [blame] | 542 | const int fNumReplays; |
Robert Phillips | 33f02ed | 2018-03-27 08:06:57 -0400 | [diff] [blame] | 543 | const int fNumDivisions; |
Robert Phillips | 33f02ed | 2018-03-27 08:06:57 -0400 | [diff] [blame] | 544 | }; |
| 545 | |
Mike Reed | f67c459 | 2017-02-17 17:06:11 -0500 | [diff] [blame] | 546 | class ViaSVG : public Via { |
| 547 | public: |
| 548 | explicit ViaSVG(Sink* sink) : Via(sink) {} |
| 549 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 550 | }; |
| 551 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 552 | } // namespace DM |
| 553 | |
| 554 | #endif//DMSrcSink_DEFINED |