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