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 | |
| 11 | #include "DMGpuSupport.h" |
| 12 | #include "SkBBHFactory.h" |
| 13 | #include "SkBBoxHierarchy.h" |
| 14 | #include "SkBitmap.h" |
msarett | 5cb4885 | 2015-11-06 08:56:32 -0800 | [diff] [blame] | 15 | #include "SkBitmapRegionDecoder.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 16 | #include "SkCanvas.h" |
| 17 | #include "SkData.h" |
halcanary | 45420a9 | 2016-06-02 12:41:14 -0700 | [diff] [blame] | 18 | #include "SkMultiPictureDocumentReader.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 19 | #include "SkPicture.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 20 | #include "gm.h" |
| 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: |
| 103 | explicit GMSrc(skiagm::GMRegistry::Factory); |
| 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: |
| 111 | skiagm::GMRegistry::Factory fFactory; |
| 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, |
| 130 | kIndex8_Always_DstColorType, |
| 131 | kGrayscale_Always_DstColorType, |
msarett | 34e0ec4 | 2016-04-22 16:27:24 -0700 | [diff] [blame] | 132 | kNonNative8888_Always_DstColorType, |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 133 | }; |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 134 | CodecSrc(Path, Mode, DstColorType, SkAlphaType, float); |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 135 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 136 | Error draw(SkCanvas*) const override; |
| 137 | SkISize size() const override; |
| 138 | Name name() const override; |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 139 | bool veto(SinkFlags) const override; |
scroggo | 3ac66e9 | 2016-02-08 15:09:48 -0800 | [diff] [blame] | 140 | bool serial() const override { return fRunSerially; } |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 141 | private: |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 142 | Path fPath; |
| 143 | Mode fMode; |
| 144 | DstColorType fDstColorType; |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 145 | SkAlphaType fDstAlphaType; |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 146 | float fScale; |
scroggo | 3ac66e9 | 2016-02-08 15:09:48 -0800 | [diff] [blame] | 147 | bool fRunSerially; |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 148 | }; |
| 149 | |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 150 | class AndroidCodecSrc : public Src { |
| 151 | public: |
scroggo | f8dc9df | 2016-05-16 09:04:13 -0700 | [diff] [blame] | 152 | AndroidCodecSrc(Path, CodecSrc::DstColorType, SkAlphaType, int sampleSize); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 153 | |
| 154 | Error draw(SkCanvas*) const override; |
| 155 | SkISize size() const override; |
| 156 | Name name() const override; |
| 157 | bool veto(SinkFlags) const override; |
scroggo | 3ac66e9 | 2016-02-08 15:09:48 -0800 | [diff] [blame] | 158 | bool serial() const override { return fRunSerially; } |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 159 | private: |
| 160 | Path fPath; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 161 | CodecSrc::DstColorType fDstColorType; |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 162 | SkAlphaType fDstAlphaType; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 163 | int fSampleSize; |
scroggo | 3ac66e9 | 2016-02-08 15:09:48 -0800 | [diff] [blame] | 164 | bool fRunSerially; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 165 | }; |
| 166 | |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 167 | // Allows for testing of various implementations of Android's BitmapRegionDecoder |
| 168 | class BRDSrc : public Src { |
| 169 | public: |
| 170 | enum Mode { |
| 171 | // Decode the entire image as one region. |
| 172 | kFullImage_Mode, |
| 173 | // Splits the image into multiple regions using a divisor and decodes the regions |
| 174 | // separately. Also, this test adds a border of a few pixels to each of the regions |
| 175 | // that it is decoding. This tests the behavior when a client asks for a region that |
| 176 | // does not fully fit in the image. |
| 177 | kDivisor_Mode, |
| 178 | }; |
| 179 | |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 180 | BRDSrc(Path, Mode, CodecSrc::DstColorType, uint32_t); |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 181 | |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 182 | Error draw(SkCanvas*) const override; |
| 183 | SkISize size() const override; |
| 184 | Name name() const override; |
| 185 | bool veto(SinkFlags) const override; |
| 186 | private: |
| 187 | Path fPath; |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 188 | Mode fMode; |
| 189 | CodecSrc::DstColorType fDstColorType; |
| 190 | uint32_t fSampleSize; |
| 191 | }; |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 192 | |
msarett | 1897631 | 2016-03-09 14:20:58 -0800 | [diff] [blame] | 193 | class ImageGenSrc : public Src { |
| 194 | public: |
| 195 | enum Mode { |
| 196 | kCodec_Mode, // Use CodecImageGenerator |
| 197 | kPlatform_Mode, // Uses CG or WIC |
| 198 | }; |
| 199 | ImageGenSrc(Path, Mode, SkAlphaType, bool); |
| 200 | |
| 201 | Error draw(SkCanvas*) const override; |
| 202 | SkISize size() const override; |
| 203 | Name name() const override; |
| 204 | bool veto(SinkFlags) const override; |
| 205 | bool serial() const override { return fRunSerially; } |
| 206 | private: |
| 207 | Path fPath; |
| 208 | Mode fMode; |
| 209 | SkAlphaType fDstAlphaType; |
| 210 | bool fIsGpu; |
| 211 | bool fRunSerially; |
| 212 | }; |
| 213 | |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 214 | class ColorCodecSrc : public Src { |
| 215 | public: |
| 216 | enum Mode { |
| 217 | // Mimic legacy behavior and apply no color correction. |
| 218 | kBaseline_Mode, |
msarett | 888dc16 | 2016-05-23 10:21:17 -0700 | [diff] [blame] | 219 | |
| 220 | // Color correct images into a specific dst color space. If you happen to have this |
| 221 | // monitor, you're in luck! The unmarked outputs of this test should display |
| 222 | // correctly on this monitor in the Chrome browser. If not, it's useful to know |
| 223 | // that this monitor has a profile that is fairly similar to Adobe RGB. |
msarett | 888dc16 | 2016-05-23 10:21:17 -0700 | [diff] [blame] | 224 | kDst_HPZR30w_Mode, |
msarett | 9876ac5 | 2016-06-01 14:47:18 -0700 | [diff] [blame] | 225 | |
msarett | d280957 | 2016-06-20 06:07:45 -0700 | [diff] [blame] | 226 | kDst_sRGB_Mode, |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 227 | }; |
| 228 | |
msarett | 9ce3a54 | 2016-07-15 13:54:38 -0700 | [diff] [blame] | 229 | ColorCodecSrc(Path, Mode, SkColorType); |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 230 | |
| 231 | Error draw(SkCanvas*) const override; |
| 232 | SkISize size() const override; |
| 233 | Name name() const override; |
| 234 | bool veto(SinkFlags) const override; |
| 235 | private: |
| 236 | Path fPath; |
| 237 | Mode fMode; |
msarett | 9ce3a54 | 2016-07-15 13:54:38 -0700 | [diff] [blame] | 238 | SkColorType fColorType; |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 239 | }; |
| 240 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 241 | class SKPSrc : public Src { |
| 242 | public: |
mtklein | 8d17a13 | 2015-01-30 11:42:31 -0800 | [diff] [blame] | 243 | explicit SKPSrc(Path path); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 244 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 245 | Error draw(SkCanvas*) const override; |
| 246 | SkISize size() const override; |
| 247 | Name name() const override; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 248 | private: |
mtklein | 8d17a13 | 2015-01-30 11:42:31 -0800 | [diff] [blame] | 249 | Path fPath; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 250 | }; |
| 251 | |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 252 | #if defined(SK_XML) |
fmalita | bdf3e5c | 2016-09-17 07:26:26 -0700 | [diff] [blame] | 253 | } // namespace DM |
| 254 | |
| 255 | class SkSVGDOM; |
| 256 | |
| 257 | namespace DM { |
| 258 | |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 259 | class SVGSrc : public Src { |
| 260 | public: |
| 261 | explicit SVGSrc(Path path); |
| 262 | |
| 263 | Error draw(SkCanvas*) const override; |
| 264 | SkISize size() const override; |
| 265 | Name name() const override; |
fmalita | 179d885 | 2016-08-16 14:23:29 -0700 | [diff] [blame] | 266 | bool veto(SinkFlags) const override; |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 267 | |
| 268 | private: |
fmalita | acd2f5c | 2016-11-08 07:13:45 -0800 | [diff] [blame] | 269 | Name fName; |
| 270 | sk_sp<SkSVGDOM> fDom; |
| 271 | SkScalar fScale; |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 272 | |
| 273 | typedef Src INHERITED; |
| 274 | }; |
| 275 | #endif // SK_XML |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 276 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 277 | |
halcanary | 45420a9 | 2016-06-02 12:41:14 -0700 | [diff] [blame] | 278 | class MSKPSrc : public Src { |
| 279 | public: |
| 280 | explicit MSKPSrc(Path path); |
| 281 | |
| 282 | int pageCount() const override; |
| 283 | Error draw(SkCanvas* c) const override; |
| 284 | Error draw(int, SkCanvas*) const override; |
| 285 | SkISize size() const override; |
| 286 | SkISize size(int) const override; |
| 287 | Name name() const override; |
| 288 | |
| 289 | private: |
| 290 | Path fPath; |
| 291 | SkMultiPictureDocumentReader fReader; |
| 292 | }; |
| 293 | |
| 294 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 295 | |
mtklein | ad66f9b | 2015-02-13 15:11:10 -0800 | [diff] [blame] | 296 | class NullSink : public Sink { |
| 297 | public: |
| 298 | NullSink() {} |
| 299 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 300 | Error draw(const Src& src, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 301 | const char* fileExtension() const override { return ""; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 302 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kNull, SinkFlags::kDirect }; } |
mtklein | ad66f9b | 2015-02-13 15:11:10 -0800 | [diff] [blame] | 303 | }; |
| 304 | |
| 305 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 306 | class GPUSink : public Sink { |
| 307 | public: |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 308 | GPUSink(sk_gpu_test::GrContextFactory::ContextType, |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 309 | sk_gpu_test::GrContextFactory::ContextOverrides, |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 310 | int samples, bool diText, SkColorType colorType, sk_sp<SkColorSpace> colorSpace, |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 311 | bool threaded); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 312 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 313 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 314 | bool serial() const override { return !fThreaded; } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 315 | const char* fileExtension() const override { return "png"; } |
Brian Salomon | bd7c551 | 2017-03-07 09:08:36 -0500 | [diff] [blame] | 316 | SinkFlags flags() const override { |
Brian Salomon | fd171ed | 2017-03-08 11:38:45 -0500 | [diff] [blame] | 317 | SinkFlags::Multisampled ms = fSampleCount > 0 ? SinkFlags::kMultisampled |
| 318 | : SinkFlags::kNotMultisampled; |
| 319 | return SinkFlags{ SinkFlags::kGPU, SinkFlags::kDirect, ms }; |
Brian Salomon | bd7c551 | 2017-03-07 09:08:36 -0500 | [diff] [blame] | 320 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 321 | private: |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 322 | sk_gpu_test::GrContextFactory::ContextType fContextType; |
| 323 | sk_gpu_test::GrContextFactory::ContextOverrides fContextOverrides; |
| 324 | int fSampleCount; |
| 325 | bool fUseDIText; |
| 326 | SkColorType fColorType; |
| 327 | sk_sp<SkColorSpace> fColorSpace; |
| 328 | bool fThreaded; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 329 | }; |
| 330 | |
| 331 | class PDFSink : public Sink { |
| 332 | public: |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 333 | PDFSink(bool pdfa = false) : fPDFA(pdfa) {} |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 334 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 335 | const char* fileExtension() const override { return "pdf"; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 336 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 337 | bool fPDFA; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 338 | }; |
| 339 | |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 340 | class XPSSink : public Sink { |
| 341 | public: |
| 342 | XPSSink(); |
| 343 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 344 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 345 | const char* fileExtension() const override { return "xps"; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 346 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 347 | }; |
| 348 | |
reed | 54dc487 | 2016-09-13 08:09:45 -0700 | [diff] [blame] | 349 | class PipeSink : public Sink { |
| 350 | public: |
| 351 | PipeSink(); |
| 352 | |
| 353 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 354 | const char* fileExtension() const override { return "skpipe"; } |
| 355 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
| 356 | }; |
| 357 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 358 | class RasterSink : public Sink { |
| 359 | public: |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 360 | explicit RasterSink(SkColorType, sk_sp<SkColorSpace> = nullptr); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 361 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 362 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 363 | const char* fileExtension() const override { return "png"; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 364 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kRaster, SinkFlags::kDirect }; } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 365 | private: |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 366 | SkColorType fColorType; |
| 367 | sk_sp<SkColorSpace> fColorSpace; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 368 | }; |
| 369 | |
mtklein | 9c3f17d | 2015-01-28 11:35:18 -0800 | [diff] [blame] | 370 | class SKPSink : public Sink { |
| 371 | public: |
| 372 | SKPSink(); |
| 373 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 374 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 375 | const char* fileExtension() const override { return "skp"; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 376 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
mtklein | 9c3f17d | 2015-01-28 11:35:18 -0800 | [diff] [blame] | 377 | }; |
| 378 | |
Hal Canary | 85c7fe8 | 2016-10-25 10:33:27 -0400 | [diff] [blame] | 379 | class DebugSink : public Sink { |
| 380 | public: |
| 381 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 382 | const char* fileExtension() const override { return "json"; } |
| 383 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
| 384 | }; |
| 385 | |
mtklein | 8a4527e | 2015-01-31 20:00:58 -0800 | [diff] [blame] | 386 | class SVGSink : public Sink { |
| 387 | public: |
| 388 | SVGSink(); |
| 389 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 390 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 391 | const char* fileExtension() const override { return "svg"; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 392 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
mtklein | 8a4527e | 2015-01-31 20:00:58 -0800 | [diff] [blame] | 393 | }; |
| 394 | |
| 395 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 396 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 397 | |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 398 | class Via : public Sink { |
| 399 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 400 | explicit Via(Sink* sink) : fSink(sink) {} |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 401 | const char* fileExtension() const override { return fSink->fileExtension(); } |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 402 | bool serial() const override { return fSink->serial(); } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 403 | SinkFlags flags() const override { |
| 404 | SinkFlags flags = fSink->flags(); |
| 405 | flags.approach = SinkFlags::kIndirect; |
| 406 | return flags; |
| 407 | } |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 408 | protected: |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 409 | std::unique_ptr<Sink> fSink; |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 410 | }; |
| 411 | |
| 412 | class ViaMatrix : public Via { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 413 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 414 | ViaMatrix(SkMatrix, Sink*); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 415 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 416 | private: |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 417 | const SkMatrix fMatrix; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 418 | }; |
| 419 | |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 420 | class ViaUpright : public Via { |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 421 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 422 | ViaUpright(SkMatrix, Sink*); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 423 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 424 | private: |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 425 | const SkMatrix fMatrix; |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 426 | }; |
| 427 | |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 428 | class ViaSerialization : public Via { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 429 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 430 | explicit ViaSerialization(Sink* sink) : Via(sink) {} |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 431 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 432 | }; |
| 433 | |
mtklein | 4a34ecb | 2016-01-08 10:19:35 -0800 | [diff] [blame] | 434 | class ViaPicture : public Via { |
| 435 | public: |
| 436 | explicit ViaPicture(Sink* sink) : Via(sink) {} |
| 437 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 438 | }; |
| 439 | |
reed | 54dc487 | 2016-09-13 08:09:45 -0700 | [diff] [blame] | 440 | class ViaPipe : public Via { |
| 441 | public: |
| 442 | explicit ViaPipe(Sink* sink) : Via(sink) {} |
| 443 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 444 | }; |
| 445 | |
reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 446 | class ViaDefer : public Via { |
| 447 | public: |
| 448 | explicit ViaDefer(Sink* sink) : Via(sink) {} |
| 449 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 450 | }; |
| 451 | |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 452 | class ViaTiles : public Via { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 453 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 454 | ViaTiles(int w, int h, SkBBHFactory*, Sink*); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 455 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 456 | private: |
| 457 | const int fW, fH; |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 458 | std::unique_ptr<SkBBHFactory> fFactory; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 459 | }; |
| 460 | |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 461 | class ViaSecondPicture : public Via { |
mtklein | b7e8d69 | 2015-04-07 08:30:32 -0700 | [diff] [blame] | 462 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 463 | explicit ViaSecondPicture(Sink* sink) : Via(sink) {} |
mtklein | b7e8d69 | 2015-04-07 08:30:32 -0700 | [diff] [blame] | 464 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | b7e8d69 | 2015-04-07 08:30:32 -0700 | [diff] [blame] | 465 | }; |
| 466 | |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 467 | class ViaSingletonPictures : public Via { |
mtklein | d31c13d | 2015-05-05 12:59:56 -0700 | [diff] [blame] | 468 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 469 | explicit ViaSingletonPictures(Sink* sink) : Via(sink) {} |
mtklein | d31c13d | 2015-05-05 12:59:56 -0700 | [diff] [blame] | 470 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | d31c13d | 2015-05-05 12:59:56 -0700 | [diff] [blame] | 471 | }; |
| 472 | |
mtklein | 6fbf4b3 | 2015-05-06 11:35:40 -0700 | [diff] [blame] | 473 | class ViaTwice : public Via { |
| 474 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 475 | explicit ViaTwice(Sink* sink) : Via(sink) {} |
mtklein | 6fbf4b3 | 2015-05-06 11:35:40 -0700 | [diff] [blame] | 476 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 477 | }; |
| 478 | |
Mike Reed | f67c459 | 2017-02-17 17:06:11 -0500 | [diff] [blame] | 479 | class ViaSVG : public Via { |
| 480 | public: |
| 481 | explicit ViaSVG(Sink* sink) : Via(sink) {} |
| 482 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 483 | }; |
| 484 | |
halcanary | 7a76f9c | 2016-02-03 11:53:18 -0800 | [diff] [blame] | 485 | class ViaMojo : public Via { |
| 486 | public: |
| 487 | explicit ViaMojo(Sink* sink) : Via(sink) {} |
| 488 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 489 | }; |
| 490 | |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 491 | class ViaLite : public Via { |
| 492 | public: |
| 493 | explicit ViaLite(Sink* sink) : Via(sink) {} |
| 494 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 495 | }; |
| 496 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 497 | } // namespace DM |
| 498 | |
| 499 | #endif//DMSrcSink_DEFINED |