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