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 | |
| 22 | namespace DM { |
| 23 | |
| 24 | // This is just convenience. It lets you use either return "foo" or return SkStringPrintf(...). |
| 25 | struct ImplicitString : public SkString { |
| 26 | template <typename T> |
| 27 | ImplicitString(const T& s) : SkString(s) {} |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 28 | ImplicitString() : SkString("") {} |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 29 | }; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 30 | typedef ImplicitString Name; |
mtklein | 8d17a13 | 2015-01-30 11:42:31 -0800 | [diff] [blame] | 31 | typedef ImplicitString Path; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 32 | |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 33 | class Error { |
| 34 | public: |
| 35 | Error(const SkString& s) : fMsg(s), fFatal(!this->isEmpty()) {} |
| 36 | Error(const char* s) : fMsg(s), fFatal(!this->isEmpty()) {} |
| 37 | |
| 38 | Error(const Error&) = default; |
| 39 | Error& operator=(const Error&) = default; |
| 40 | |
| 41 | static Error Nonfatal(const SkString& s) { return Nonfatal(s.c_str()); } |
| 42 | static Error Nonfatal(const char* s) { |
| 43 | Error e(s); |
| 44 | e.fFatal = false; |
| 45 | return e; |
| 46 | } |
| 47 | |
| 48 | const char* c_str() const { return fMsg.c_str(); } |
| 49 | bool isEmpty() const { return fMsg.isEmpty(); } |
| 50 | bool isFatal() const { return fFatal; } |
| 51 | |
| 52 | private: |
| 53 | SkString fMsg; |
| 54 | bool fFatal; |
| 55 | }; |
| 56 | |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 57 | struct SinkFlags { |
| 58 | enum { kNull, kGPU, kVector, kRaster } type; |
| 59 | enum { kDirect, kIndirect } approach; |
| 60 | }; |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 61 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 62 | struct Src { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 63 | virtual ~Src() {} |
| 64 | virtual Error SK_WARN_UNUSED_RESULT draw(SkCanvas*) const = 0; |
| 65 | virtual SkISize size() const = 0; |
| 66 | virtual Name name() const = 0; |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 67 | virtual void modifyGrContextOptions(GrContextOptions* options) const {} |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 68 | virtual bool veto(SinkFlags) const { return false; } |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 69 | |
halcanary | 45420a9 | 2016-06-02 12:41:14 -0700 | [diff] [blame] | 70 | virtual int pageCount() const { return 1; } |
| 71 | virtual Error SK_WARN_UNUSED_RESULT draw(int, SkCanvas* canvas) const { |
| 72 | return this->draw(canvas); |
| 73 | } |
| 74 | virtual SkISize size(int) const { return this->size(); } |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 75 | // Force Tasks using this Src to run on the main thread? |
| 76 | virtual bool serial() const { return false; } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | struct Sink { |
| 80 | virtual ~Sink() {} |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 81 | // You may write to either the bitmap or stream. If you write to log, we'll print that out. |
| 82 | virtual Error SK_WARN_UNUSED_RESULT draw(const Src&, SkBitmap*, SkWStream*, SkString* log) |
| 83 | const = 0; |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 84 | |
| 85 | // Force Tasks using this Sink to run on the main thread? |
| 86 | virtual bool serial() const { return false; } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 87 | |
| 88 | // File extension for the content draw() outputs, e.g. "png", "pdf". |
| 89 | virtual const char* fileExtension() const = 0; |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 90 | |
| 91 | virtual SinkFlags flags() const = 0; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 92 | }; |
| 93 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 94 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 95 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 96 | class GMSrc : public Src { |
| 97 | public: |
| 98 | explicit GMSrc(skiagm::GMRegistry::Factory); |
| 99 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 100 | Error draw(SkCanvas*) const override; |
| 101 | SkISize size() const override; |
| 102 | Name name() const override; |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 103 | void modifyGrContextOptions(GrContextOptions* options) const override; |
| 104 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 105 | private: |
| 106 | skiagm::GMRegistry::Factory fFactory; |
| 107 | }; |
| 108 | |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 109 | class CodecSrc : public Src { |
| 110 | public: |
scroggo | 9c59ebc | 2015-03-25 13:48:49 -0700 | [diff] [blame] | 111 | enum Mode { |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 112 | kCodec_Mode, |
msarett | bb25b53 | 2016-01-13 09:31:39 -0800 | [diff] [blame] | 113 | // We choose to test only one mode with zero initialized memory. |
| 114 | // This will exercise all of the interesting cases in SkSwizzler |
| 115 | // without doubling the size of our test suite. |
| 116 | kCodecZeroInit_Mode, |
scroggo | 9c59ebc | 2015-03-25 13:48:49 -0700 | [diff] [blame] | 117 | kScanline_Mode, |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 118 | kStripe_Mode, // Tests the skipping of scanlines |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 119 | kCroppedScanline_Mode, // Tests (jpeg) cropped scanline optimization |
scroggo | b636b45 | 2015-07-22 07:16:20 -0700 | [diff] [blame] | 120 | kSubset_Mode, // For codecs that support subsets directly. |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 121 | kAnimated_Mode, // For codecs that support animation. |
scroggo | 9c59ebc | 2015-03-25 13:48:49 -0700 | [diff] [blame] | 122 | }; |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 123 | enum DstColorType { |
| 124 | kGetFromCanvas_DstColorType, |
| 125 | kIndex8_Always_DstColorType, |
| 126 | kGrayscale_Always_DstColorType, |
msarett | 34e0ec4 | 2016-04-22 16:27:24 -0700 | [diff] [blame] | 127 | kNonNative8888_Always_DstColorType, |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 128 | }; |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 129 | CodecSrc(Path, Mode, DstColorType, SkAlphaType, float); |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 130 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 131 | Error draw(SkCanvas*) const override; |
| 132 | SkISize size() const override; |
| 133 | Name name() const override; |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 134 | bool veto(SinkFlags) const override; |
scroggo | 3ac66e9 | 2016-02-08 15:09:48 -0800 | [diff] [blame] | 135 | bool serial() const override { return fRunSerially; } |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 136 | private: |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 137 | Path fPath; |
| 138 | Mode fMode; |
| 139 | DstColorType fDstColorType; |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 140 | SkAlphaType fDstAlphaType; |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 141 | float fScale; |
scroggo | 3ac66e9 | 2016-02-08 15:09:48 -0800 | [diff] [blame] | 142 | bool fRunSerially; |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 143 | }; |
| 144 | |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 145 | class AndroidCodecSrc : public Src { |
| 146 | public: |
scroggo | f8dc9df | 2016-05-16 09:04:13 -0700 | [diff] [blame] | 147 | AndroidCodecSrc(Path, CodecSrc::DstColorType, SkAlphaType, int sampleSize); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 148 | |
| 149 | Error draw(SkCanvas*) const override; |
| 150 | SkISize size() const override; |
| 151 | Name name() const override; |
| 152 | bool veto(SinkFlags) const override; |
scroggo | 3ac66e9 | 2016-02-08 15:09:48 -0800 | [diff] [blame] | 153 | bool serial() const override { return fRunSerially; } |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 154 | private: |
| 155 | Path fPath; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 156 | CodecSrc::DstColorType fDstColorType; |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 157 | SkAlphaType fDstAlphaType; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 158 | int fSampleSize; |
scroggo | 3ac66e9 | 2016-02-08 15:09:48 -0800 | [diff] [blame] | 159 | bool fRunSerially; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 160 | }; |
| 161 | |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 162 | // Allows for testing of various implementations of Android's BitmapRegionDecoder |
| 163 | class BRDSrc : public Src { |
| 164 | public: |
| 165 | enum Mode { |
| 166 | // Decode the entire image as one region. |
| 167 | kFullImage_Mode, |
| 168 | // Splits the image into multiple regions using a divisor and decodes the regions |
| 169 | // separately. Also, this test adds a border of a few pixels to each of the regions |
| 170 | // that it is decoding. This tests the behavior when a client asks for a region that |
| 171 | // does not fully fit in the image. |
| 172 | kDivisor_Mode, |
| 173 | }; |
| 174 | |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 175 | BRDSrc(Path, Mode, CodecSrc::DstColorType, uint32_t); |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 176 | |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 177 | Error draw(SkCanvas*) const override; |
| 178 | SkISize size() const override; |
| 179 | Name name() const override; |
| 180 | bool veto(SinkFlags) const override; |
| 181 | private: |
| 182 | Path fPath; |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 183 | Mode fMode; |
| 184 | CodecSrc::DstColorType fDstColorType; |
| 185 | uint32_t fSampleSize; |
| 186 | }; |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 187 | |
msarett | 1897631 | 2016-03-09 14:20:58 -0800 | [diff] [blame] | 188 | class ImageGenSrc : public Src { |
| 189 | public: |
| 190 | enum Mode { |
| 191 | kCodec_Mode, // Use CodecImageGenerator |
| 192 | kPlatform_Mode, // Uses CG or WIC |
| 193 | }; |
| 194 | ImageGenSrc(Path, Mode, SkAlphaType, bool); |
| 195 | |
| 196 | Error draw(SkCanvas*) const override; |
| 197 | SkISize size() const override; |
| 198 | Name name() const override; |
| 199 | bool veto(SinkFlags) const override; |
| 200 | bool serial() const override { return fRunSerially; } |
| 201 | private: |
| 202 | Path fPath; |
| 203 | Mode fMode; |
| 204 | SkAlphaType fDstAlphaType; |
| 205 | bool fIsGpu; |
| 206 | bool fRunSerially; |
| 207 | }; |
| 208 | |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 209 | class ColorCodecSrc : public Src { |
| 210 | public: |
| 211 | enum Mode { |
| 212 | // Mimic legacy behavior and apply no color correction. |
| 213 | kBaseline_Mode, |
msarett | 888dc16 | 2016-05-23 10:21:17 -0700 | [diff] [blame] | 214 | |
| 215 | // Color correct images into a specific dst color space. If you happen to have this |
| 216 | // monitor, you're in luck! The unmarked outputs of this test should display |
| 217 | // correctly on this monitor in the Chrome browser. If not, it's useful to know |
| 218 | // that this monitor has a profile that is fairly similar to Adobe RGB. |
msarett | 888dc16 | 2016-05-23 10:21:17 -0700 | [diff] [blame] | 219 | kDst_HPZR30w_Mode, |
msarett | 9876ac5 | 2016-06-01 14:47:18 -0700 | [diff] [blame] | 220 | |
msarett | d280957 | 2016-06-20 06:07:45 -0700 | [diff] [blame] | 221 | kDst_sRGB_Mode, |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 222 | }; |
| 223 | |
msarett | 9ce3a54 | 2016-07-15 13:54:38 -0700 | [diff] [blame] | 224 | ColorCodecSrc(Path, Mode, SkColorType); |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 225 | |
| 226 | Error draw(SkCanvas*) const override; |
| 227 | SkISize size() const override; |
| 228 | Name name() const override; |
| 229 | bool veto(SinkFlags) const override; |
| 230 | private: |
| 231 | Path fPath; |
| 232 | Mode fMode; |
msarett | 9ce3a54 | 2016-07-15 13:54:38 -0700 | [diff] [blame] | 233 | SkColorType fColorType; |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 234 | }; |
| 235 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 236 | class SKPSrc : public Src { |
| 237 | public: |
mtklein | 8d17a13 | 2015-01-30 11:42:31 -0800 | [diff] [blame] | 238 | explicit SKPSrc(Path path); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 239 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 240 | Error draw(SkCanvas*) const override; |
| 241 | SkISize size() const override; |
| 242 | Name name() const override; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 243 | private: |
mtklein | 8d17a13 | 2015-01-30 11:42:31 -0800 | [diff] [blame] | 244 | Path fPath; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 245 | }; |
| 246 | |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 247 | #if defined(SK_XML) |
fmalita | bdf3e5c | 2016-09-17 07:26:26 -0700 | [diff] [blame] | 248 | } // namespace DM |
| 249 | |
| 250 | class SkSVGDOM; |
| 251 | |
| 252 | namespace DM { |
| 253 | |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 254 | class SVGSrc : public Src { |
| 255 | public: |
| 256 | explicit SVGSrc(Path path); |
| 257 | |
| 258 | Error draw(SkCanvas*) const override; |
| 259 | SkISize size() const override; |
| 260 | Name name() const override; |
fmalita | 179d885 | 2016-08-16 14:23:29 -0700 | [diff] [blame] | 261 | bool veto(SinkFlags) const override; |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 262 | |
| 263 | private: |
fmalita | acd2f5c | 2016-11-08 07:13:45 -0800 | [diff] [blame] | 264 | Name fName; |
| 265 | sk_sp<SkSVGDOM> fDom; |
| 266 | SkScalar fScale; |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 267 | |
| 268 | typedef Src INHERITED; |
| 269 | }; |
| 270 | #endif // SK_XML |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 271 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 272 | |
halcanary | 45420a9 | 2016-06-02 12:41:14 -0700 | [diff] [blame] | 273 | class MSKPSrc : public Src { |
| 274 | public: |
| 275 | explicit MSKPSrc(Path path); |
| 276 | |
| 277 | int pageCount() const override; |
| 278 | Error draw(SkCanvas* c) const override; |
| 279 | Error draw(int, SkCanvas*) const override; |
| 280 | SkISize size() const override; |
| 281 | SkISize size(int) const override; |
| 282 | Name name() const override; |
| 283 | |
| 284 | private: |
| 285 | Path fPath; |
| 286 | SkMultiPictureDocumentReader fReader; |
| 287 | }; |
| 288 | |
| 289 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 290 | |
mtklein | ad66f9b | 2015-02-13 15:11:10 -0800 | [diff] [blame] | 291 | class NullSink : public Sink { |
| 292 | public: |
| 293 | NullSink() {} |
| 294 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 295 | Error draw(const Src& src, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 296 | const char* fileExtension() const override { return ""; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 297 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kNull, SinkFlags::kDirect }; } |
mtklein | ad66f9b | 2015-02-13 15:11:10 -0800 | [diff] [blame] | 298 | }; |
| 299 | |
| 300 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 301 | class GPUSink : public Sink { |
| 302 | public: |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 303 | GPUSink(sk_gpu_test::GrContextFactory::ContextType, |
| 304 | sk_gpu_test::GrContextFactory::ContextOptions, |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 305 | int samples, bool diText, SkColorType colorType, sk_sp<SkColorSpace> colorSpace, |
brianosman | d93c120 | 2016-03-10 07:49:08 -0800 | [diff] [blame] | 306 | bool threaded); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 307 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 308 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 309 | bool serial() const override { return !fThreaded; } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 310 | const char* fileExtension() const override { return "png"; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 311 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kGPU, SinkFlags::kDirect }; } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 312 | private: |
bsalomon | 85b4b53 | 2016-04-05 11:06:27 -0700 | [diff] [blame] | 313 | sk_gpu_test::GrContextFactory::ContextType fContextType; |
| 314 | sk_gpu_test::GrContextFactory::ContextOptions fContextOptions; |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 315 | int fSampleCount; |
| 316 | bool fUseDIText; |
| 317 | SkColorType fColorType; |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 318 | sk_sp<SkColorSpace> fColorSpace; |
bsalomon | 3724e57 | 2016-03-30 18:56:19 -0700 | [diff] [blame] | 319 | bool fThreaded; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 320 | }; |
| 321 | |
| 322 | class PDFSink : public Sink { |
| 323 | public: |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 324 | PDFSink(bool pdfa = false) : fPDFA(pdfa) {} |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 325 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 326 | const char* fileExtension() const override { return "pdf"; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 327 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 328 | bool fPDFA; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 329 | }; |
| 330 | |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 331 | class XPSSink : public Sink { |
| 332 | public: |
| 333 | XPSSink(); |
| 334 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 335 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 336 | const char* fileExtension() const override { return "xps"; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 337 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 338 | }; |
| 339 | |
reed | 54dc487 | 2016-09-13 08:09:45 -0700 | [diff] [blame] | 340 | class PipeSink : public Sink { |
| 341 | public: |
| 342 | PipeSink(); |
| 343 | |
| 344 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 345 | const char* fileExtension() const override { return "skpipe"; } |
| 346 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
| 347 | }; |
| 348 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 349 | class RasterSink : public Sink { |
| 350 | public: |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 351 | explicit RasterSink(SkColorType, sk_sp<SkColorSpace> = nullptr); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 352 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 353 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 354 | const char* fileExtension() const override { return "png"; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 355 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kRaster, SinkFlags::kDirect }; } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 356 | private: |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 357 | SkColorType fColorType; |
| 358 | sk_sp<SkColorSpace> fColorSpace; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 359 | }; |
| 360 | |
mtklein | 9c3f17d | 2015-01-28 11:35:18 -0800 | [diff] [blame] | 361 | class SKPSink : public Sink { |
| 362 | public: |
| 363 | SKPSink(); |
| 364 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 365 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 366 | const char* fileExtension() const override { return "skp"; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 367 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
mtklein | 9c3f17d | 2015-01-28 11:35:18 -0800 | [diff] [blame] | 368 | }; |
| 369 | |
Hal Canary | 85c7fe8 | 2016-10-25 10:33:27 -0400 | [diff] [blame] | 370 | class DebugSink : public Sink { |
| 371 | public: |
| 372 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 373 | const char* fileExtension() const override { return "json"; } |
| 374 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
| 375 | }; |
| 376 | |
mtklein | 8a4527e | 2015-01-31 20:00:58 -0800 | [diff] [blame] | 377 | class SVGSink : public Sink { |
| 378 | public: |
| 379 | SVGSink(); |
| 380 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 381 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 382 | const char* fileExtension() const override { return "svg"; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 383 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
mtklein | 8a4527e | 2015-01-31 20:00:58 -0800 | [diff] [blame] | 384 | }; |
| 385 | |
| 386 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 387 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 388 | |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 389 | class Via : public Sink { |
| 390 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 391 | explicit Via(Sink* sink) : fSink(sink) {} |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 392 | const char* fileExtension() const override { return fSink->fileExtension(); } |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 393 | bool serial() const override { return fSink->serial(); } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 394 | SinkFlags flags() const override { |
| 395 | SinkFlags flags = fSink->flags(); |
| 396 | flags.approach = SinkFlags::kIndirect; |
| 397 | return flags; |
| 398 | } |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 399 | protected: |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 400 | std::unique_ptr<Sink> fSink; |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 401 | }; |
| 402 | |
| 403 | class ViaMatrix : public Via { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 404 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 405 | ViaMatrix(SkMatrix, Sink*); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 406 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 407 | private: |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 408 | const SkMatrix fMatrix; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 409 | }; |
| 410 | |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 411 | class ViaUpright : public Via { |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 412 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 413 | ViaUpright(SkMatrix, Sink*); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 414 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 415 | private: |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 416 | const SkMatrix fMatrix; |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 417 | }; |
| 418 | |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 419 | class ViaSerialization : public Via { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 420 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 421 | explicit ViaSerialization(Sink* sink) : Via(sink) {} |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 422 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 423 | }; |
| 424 | |
mtklein | 4a34ecb | 2016-01-08 10:19:35 -0800 | [diff] [blame] | 425 | class ViaPicture : public Via { |
| 426 | public: |
| 427 | explicit ViaPicture(Sink* sink) : Via(sink) {} |
| 428 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 429 | }; |
| 430 | |
reed | 54dc487 | 2016-09-13 08:09:45 -0700 | [diff] [blame] | 431 | class ViaPipe : public Via { |
| 432 | public: |
| 433 | explicit ViaPipe(Sink* sink) : Via(sink) {} |
| 434 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 435 | }; |
| 436 | |
reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 437 | class ViaDefer : public Via { |
| 438 | public: |
| 439 | explicit ViaDefer(Sink* sink) : Via(sink) {} |
| 440 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 441 | }; |
| 442 | |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 443 | class ViaTiles : public Via { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 444 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 445 | ViaTiles(int w, int h, SkBBHFactory*, Sink*); |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 446 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 447 | private: |
| 448 | const int fW, fH; |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 449 | std::unique_ptr<SkBBHFactory> fFactory; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 450 | }; |
| 451 | |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 452 | class ViaSecondPicture : public Via { |
mtklein | b7e8d69 | 2015-04-07 08:30:32 -0700 | [diff] [blame] | 453 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 454 | explicit ViaSecondPicture(Sink* sink) : Via(sink) {} |
mtklein | b7e8d69 | 2015-04-07 08:30:32 -0700 | [diff] [blame] | 455 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | b7e8d69 | 2015-04-07 08:30:32 -0700 | [diff] [blame] | 456 | }; |
| 457 | |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 458 | class ViaSingletonPictures : public Via { |
mtklein | d31c13d | 2015-05-05 12:59:56 -0700 | [diff] [blame] | 459 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 460 | explicit ViaSingletonPictures(Sink* sink) : Via(sink) {} |
mtklein | d31c13d | 2015-05-05 12:59:56 -0700 | [diff] [blame] | 461 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | d31c13d | 2015-05-05 12:59:56 -0700 | [diff] [blame] | 462 | }; |
| 463 | |
mtklein | 6fbf4b3 | 2015-05-06 11:35:40 -0700 | [diff] [blame] | 464 | class ViaTwice : public Via { |
| 465 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 466 | explicit ViaTwice(Sink* sink) : Via(sink) {} |
mtklein | 6fbf4b3 | 2015-05-06 11:35:40 -0700 | [diff] [blame] | 467 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 468 | }; |
| 469 | |
halcanary | 7a76f9c | 2016-02-03 11:53:18 -0800 | [diff] [blame] | 470 | class ViaMojo : public Via { |
| 471 | public: |
| 472 | explicit ViaMojo(Sink* sink) : Via(sink) {} |
| 473 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 474 | }; |
| 475 | |
mtklein | 9c5052f | 2016-08-06 12:51:51 -0700 | [diff] [blame] | 476 | class ViaLite : public Via { |
| 477 | public: |
| 478 | explicit ViaLite(Sink* sink) : Via(sink) {} |
| 479 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 480 | }; |
| 481 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 482 | } // namespace DM |
| 483 | |
| 484 | #endif//DMSrcSink_DEFINED |