blob: 26c32f59b7da6faf2fc06aabf1bd9e90831a3c65 [file] [log] [blame]
scroggo478652e2015-03-25 07:11:02 -07001/*
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
mtklein748ca3b2015-01-15 10:56:12 -08008#ifndef DMSrcSink_DEFINED
9#define DMSrcSink_DEFINED
10
11#include "DMGpuSupport.h"
12#include "SkBBHFactory.h"
13#include "SkBBoxHierarchy.h"
14#include "SkBitmap.h"
msarett5cb48852015-11-06 08:56:32 -080015#include "SkBitmapRegionDecoder.h"
mtklein748ca3b2015-01-15 10:56:12 -080016#include "SkCanvas.h"
17#include "SkData.h"
Hal Canary45cde312017-04-03 16:06:42 -040018#include "SkMultiPictureDocument.h"
mtklein748ca3b2015-01-15 10:56:12 -080019#include "SkPicture.h"
mtklein748ca3b2015-01-15 10:56:12 -080020#include "gm.h"
21
Mike Reedbae888e2017-02-18 16:50:45 -050022//#define TEST_VIA_SVG
23
mtklein748ca3b2015-01-15 10:56:12 -080024namespace DM {
25
26// This is just convenience. It lets you use either return "foo" or return SkStringPrintf(...).
27struct ImplicitString : public SkString {
28 template <typename T>
29 ImplicitString(const T& s) : SkString(s) {}
msarett9e707a02015-09-01 14:57:57 -070030 ImplicitString() : SkString("") {}
mtklein748ca3b2015-01-15 10:56:12 -080031};
mtklein748ca3b2015-01-15 10:56:12 -080032typedef ImplicitString Name;
mtklein8d17a132015-01-30 11:42:31 -080033typedef ImplicitString Path;
mtklein748ca3b2015-01-15 10:56:12 -080034
mtklein4089ef72015-03-05 08:40:28 -080035class Error {
36public:
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
54private:
55 SkString fMsg;
56 bool fFatal;
57};
58
mtklein99cab4e2015-07-31 06:43:04 -070059struct SinkFlags {
Brian Salomonbd7c5512017-03-07 09:08:36 -050060 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) {}
mtklein99cab4e2015-07-31 06:43:04 -070065};
mtkleine0effd62015-07-29 06:37:28 -070066
mtklein748ca3b2015-01-15 10:56:12 -080067struct Src {
mtklein748ca3b2015-01-15 10:56:12 -080068 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;
bsalomon4ee6bd82015-05-27 13:23:23 -070072 virtual void modifyGrContextOptions(GrContextOptions* options) const {}
mtklein99cab4e2015-07-31 06:43:04 -070073 virtual bool veto(SinkFlags) const { return false; }
mtklein21eaf3b2016-02-08 12:39:59 -080074
halcanary45420a92016-06-02 12:41:14 -070075 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(); }
mtklein21eaf3b2016-02-08 12:39:59 -080080 // Force Tasks using this Src to run on the main thread?
81 virtual bool serial() const { return false; }
mtklein748ca3b2015-01-15 10:56:12 -080082};
83
84struct Sink {
85 virtual ~Sink() {}
mtkleinb9eb4ac2015-02-02 18:26:03 -080086 // 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;
mtklein21eaf3b2016-02-08 12:39:59 -080089
90 // Force Tasks using this Sink to run on the main thread?
91 virtual bool serial() const { return false; }
mtklein748ca3b2015-01-15 10:56:12 -080092
93 // File extension for the content draw() outputs, e.g. "png", "pdf".
94 virtual const char* fileExtension() const = 0;
mtklein99cab4e2015-07-31 06:43:04 -070095
96 virtual SinkFlags flags() const = 0;
mtklein748ca3b2015-01-15 10:56:12 -080097};
98
mtklein748ca3b2015-01-15 10:56:12 -080099/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
100
mtklein748ca3b2015-01-15 10:56:12 -0800101class GMSrc : public Src {
102public:
103 explicit GMSrc(skiagm::GMRegistry::Factory);
104
mtklein36352bf2015-03-25 18:17:31 -0700105 Error draw(SkCanvas*) const override;
106 SkISize size() const override;
107 Name name() const override;
bsalomon4ee6bd82015-05-27 13:23:23 -0700108 void modifyGrContextOptions(GrContextOptions* options) const override;
109
mtklein748ca3b2015-01-15 10:56:12 -0800110private:
111 skiagm::GMRegistry::Factory fFactory;
112};
113
scroggo9b77ddd2015-03-19 06:03:39 -0700114class CodecSrc : public Src {
115public:
scroggo9c59ebc2015-03-25 13:48:49 -0700116 enum Mode {
msarett9e707a02015-09-01 14:57:57 -0700117 kCodec_Mode,
msarettbb25b532016-01-13 09:31:39 -0800118 // 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,
scroggo9c59ebc2015-03-25 13:48:49 -0700122 kScanline_Mode,
msarett0a242972015-06-11 14:27:27 -0700123 kStripe_Mode, // Tests the skipping of scanlines
msarett91c22b22016-02-22 12:27:46 -0800124 kCroppedScanline_Mode, // Tests (jpeg) cropped scanline optimization
scroggob636b452015-07-22 07:16:20 -0700125 kSubset_Mode, // For codecs that support subsets directly.
scroggo19b91532016-10-24 09:03:26 -0700126 kAnimated_Mode, // For codecs that support animation.
scroggo9c59ebc2015-03-25 13:48:49 -0700127 };
msarett438b2ad2015-04-09 12:43:10 -0700128 enum DstColorType {
129 kGetFromCanvas_DstColorType,
msarett438b2ad2015-04-09 12:43:10 -0700130 kGrayscale_Always_DstColorType,
msarett34e0ec42016-04-22 16:27:24 -0700131 kNonNative8888_Always_DstColorType,
msarett438b2ad2015-04-09 12:43:10 -0700132 };
scroggoc5560be2016-02-03 09:42:42 -0800133 CodecSrc(Path, Mode, DstColorType, SkAlphaType, float);
scroggo9b77ddd2015-03-19 06:03:39 -0700134
mtklein36352bf2015-03-25 18:17:31 -0700135 Error draw(SkCanvas*) const override;
136 SkISize size() const override;
137 Name name() const override;
mtklein99cab4e2015-07-31 06:43:04 -0700138 bool veto(SinkFlags) const override;
scroggo3ac66e92016-02-08 15:09:48 -0800139 bool serial() const override { return fRunSerially; }
scroggo9b77ddd2015-03-19 06:03:39 -0700140private:
msarett9e707a02015-09-01 14:57:57 -0700141 Path fPath;
142 Mode fMode;
143 DstColorType fDstColorType;
scroggoc5560be2016-02-03 09:42:42 -0800144 SkAlphaType fDstAlphaType;
msarett9e707a02015-09-01 14:57:57 -0700145 float fScale;
scroggo3ac66e92016-02-08 15:09:48 -0800146 bool fRunSerially;
scroggo9b77ddd2015-03-19 06:03:39 -0700147};
148
msarett3d9d7a72015-10-21 10:27:10 -0700149class AndroidCodecSrc : public Src {
150public:
scroggof8dc9df2016-05-16 09:04:13 -0700151 AndroidCodecSrc(Path, CodecSrc::DstColorType, SkAlphaType, int sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700152
153 Error draw(SkCanvas*) const override;
154 SkISize size() const override;
155 Name name() const override;
156 bool veto(SinkFlags) const override;
scroggo3ac66e92016-02-08 15:09:48 -0800157 bool serial() const override { return fRunSerially; }
msarett3d9d7a72015-10-21 10:27:10 -0700158private:
159 Path fPath;
msarett3d9d7a72015-10-21 10:27:10 -0700160 CodecSrc::DstColorType fDstColorType;
scroggoc5560be2016-02-03 09:42:42 -0800161 SkAlphaType fDstAlphaType;
msarett3d9d7a72015-10-21 10:27:10 -0700162 int fSampleSize;
scroggo3ac66e92016-02-08 15:09:48 -0800163 bool fRunSerially;
msarett3d9d7a72015-10-21 10:27:10 -0700164};
165
msaretta5783ae2015-09-08 15:35:32 -0700166// Allows for testing of various implementations of Android's BitmapRegionDecoder
167class BRDSrc : public Src {
168public:
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
msarettd1227a72016-05-18 06:23:57 -0700179 BRDSrc(Path, Mode, CodecSrc::DstColorType, uint32_t);
msaretta5783ae2015-09-08 15:35:32 -0700180
msaretta5783ae2015-09-08 15:35:32 -0700181 Error draw(SkCanvas*) const override;
182 SkISize size() const override;
183 Name name() const override;
184 bool veto(SinkFlags) const override;
185private:
186 Path fPath;
msaretta5783ae2015-09-08 15:35:32 -0700187 Mode fMode;
188 CodecSrc::DstColorType fDstColorType;
189 uint32_t fSampleSize;
190};
scroggo9b77ddd2015-03-19 06:03:39 -0700191
msarett18976312016-03-09 14:20:58 -0800192class ImageGenSrc : public Src {
193public:
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; }
205private:
206 Path fPath;
207 Mode fMode;
208 SkAlphaType fDstAlphaType;
209 bool fIsGpu;
210 bool fRunSerially;
211};
212
msarett69deca82016-04-29 09:38:40 -0700213class ColorCodecSrc : public Src {
214public:
215 enum Mode {
216 // Mimic legacy behavior and apply no color correction.
217 kBaseline_Mode,
msarett888dc162016-05-23 10:21:17 -0700218
219 // Color correct images into a specific dst color space. If you happen to have this
220 // monitor, you're in luck! The unmarked outputs of this test should display
221 // correctly on this monitor in the Chrome browser. If not, it's useful to know
222 // that this monitor has a profile that is fairly similar to Adobe RGB.
msarett888dc162016-05-23 10:21:17 -0700223 kDst_HPZR30w_Mode,
msarett9876ac52016-06-01 14:47:18 -0700224
msarettd2809572016-06-20 06:07:45 -0700225 kDst_sRGB_Mode,
msarett69deca82016-04-29 09:38:40 -0700226 };
227
msarett9ce3a542016-07-15 13:54:38 -0700228 ColorCodecSrc(Path, Mode, SkColorType);
msarett69deca82016-04-29 09:38:40 -0700229
230 Error draw(SkCanvas*) const override;
231 SkISize size() const override;
232 Name name() const override;
233 bool veto(SinkFlags) const override;
234private:
235 Path fPath;
236 Mode fMode;
msarett9ce3a542016-07-15 13:54:38 -0700237 SkColorType fColorType;
msarett69deca82016-04-29 09:38:40 -0700238};
239
mtklein748ca3b2015-01-15 10:56:12 -0800240class SKPSrc : public Src {
241public:
mtklein8d17a132015-01-30 11:42:31 -0800242 explicit SKPSrc(Path path);
mtklein748ca3b2015-01-15 10:56:12 -0800243
mtklein36352bf2015-03-25 18:17:31 -0700244 Error draw(SkCanvas*) const override;
245 SkISize size() const override;
246 Name name() const override;
mtklein748ca3b2015-01-15 10:56:12 -0800247private:
mtklein8d17a132015-01-30 11:42:31 -0800248 Path fPath;
mtklein748ca3b2015-01-15 10:56:12 -0800249};
250
Robert Phillipsad8a43f2017-08-30 12:06:35 -0400251// DeferredDisplayList flavor
252class DDLSKPSrc : public Src {
253public:
254 explicit DDLSKPSrc(Path path);
255
256 Error draw(SkCanvas*) const override;
257 SkISize size() const override;
258 Name name() const override;
259private:
260 Path fPath;
261};
262
fmalitaa2b9fdf2016-08-03 19:53:36 -0700263#if defined(SK_XML)
fmalitabdf3e5c2016-09-17 07:26:26 -0700264} // namespace DM
265
266class SkSVGDOM;
267
268namespace DM {
269
fmalitaa2b9fdf2016-08-03 19:53:36 -0700270class SVGSrc : public Src {
271public:
272 explicit SVGSrc(Path path);
273
274 Error draw(SkCanvas*) const override;
275 SkISize size() const override;
276 Name name() const override;
fmalita179d8852016-08-16 14:23:29 -0700277 bool veto(SinkFlags) const override;
fmalitaa2b9fdf2016-08-03 19:53:36 -0700278
279private:
fmalitaacd2f5c2016-11-08 07:13:45 -0800280 Name fName;
281 sk_sp<SkSVGDOM> fDom;
282 SkScalar fScale;
fmalitaa2b9fdf2016-08-03 19:53:36 -0700283
284 typedef Src INHERITED;
285};
286#endif // SK_XML
mtklein748ca3b2015-01-15 10:56:12 -0800287/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
288
halcanary45420a92016-06-02 12:41:14 -0700289class MSKPSrc : public Src {
290public:
291 explicit MSKPSrc(Path path);
292
293 int pageCount() const override;
294 Error draw(SkCanvas* c) const override;
295 Error draw(int, SkCanvas*) const override;
296 SkISize size() const override;
297 SkISize size(int) const override;
298 Name name() const override;
299
300private:
301 Path fPath;
Hal Canary45cde312017-04-03 16:06:42 -0400302 mutable SkTArray<SkDocumentPage> fPages;
halcanary45420a92016-06-02 12:41:14 -0700303};
304
305/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
306
mtkleinad66f9b2015-02-13 15:11:10 -0800307class NullSink : public Sink {
308public:
309 NullSink() {}
310
mtklein36352bf2015-03-25 18:17:31 -0700311 Error draw(const Src& src, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700312 const char* fileExtension() const override { return ""; }
mtklein99cab4e2015-07-31 06:43:04 -0700313 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kNull, SinkFlags::kDirect }; }
mtkleinad66f9b2015-02-13 15:11:10 -0800314};
315
316
mtklein748ca3b2015-01-15 10:56:12 -0800317class GPUSink : public Sink {
318public:
bsalomon85b4b532016-04-05 11:06:27 -0700319 GPUSink(sk_gpu_test::GrContextFactory::ContextType,
Brian Salomonce5ee602017-07-17 11:31:31 -0400320 sk_gpu_test::GrContextFactory::ContextOverrides, int samples, bool diText,
321 SkColorType colorType, SkAlphaType alphaType, sk_sp<SkColorSpace> colorSpace,
Brian Osmanf21aa042017-08-21 16:48:46 -0400322 bool threaded, const GrContextOptions& grCtxOptions);
mtklein748ca3b2015-01-15 10:56:12 -0800323
mtklein36352bf2015-03-25 18:17:31 -0700324 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
Brian Osmanf9810662017-08-30 10:02:10 -0400325 Error onDraw(const Src&, SkBitmap*, SkWStream*, SkString*,
326 const GrContextOptions& baseOptions) const;
327
mtklein21eaf3b2016-02-08 12:39:59 -0800328 bool serial() const override { return !fThreaded; }
mtklein36352bf2015-03-25 18:17:31 -0700329 const char* fileExtension() const override { return "png"; }
Brian Salomonbd7c5512017-03-07 09:08:36 -0500330 SinkFlags flags() const override {
Brian Salomonfd171ed2017-03-08 11:38:45 -0500331 SinkFlags::Multisampled ms = fSampleCount > 0 ? SinkFlags::kMultisampled
332 : SinkFlags::kNotMultisampled;
333 return SinkFlags{ SinkFlags::kGPU, SinkFlags::kDirect, ms };
Brian Salomonbd7c5512017-03-07 09:08:36 -0500334 }
Brian Osmanf9810662017-08-30 10:02:10 -0400335 const GrContextOptions& baseContextOptions() const { return fBaseContextOptions; }
336
mtklein748ca3b2015-01-15 10:56:12 -0800337private:
csmartdaltone812d492017-02-21 12:36:05 -0700338 sk_gpu_test::GrContextFactory::ContextType fContextType;
339 sk_gpu_test::GrContextFactory::ContextOverrides fContextOverrides;
340 int fSampleCount;
341 bool fUseDIText;
342 SkColorType fColorType;
Brian Salomonce5ee602017-07-17 11:31:31 -0400343 SkAlphaType fAlphaType;
csmartdaltone812d492017-02-21 12:36:05 -0700344 sk_sp<SkColorSpace> fColorSpace;
345 bool fThreaded;
Brian Osmanf21aa042017-08-21 16:48:46 -0400346 GrContextOptions fBaseContextOptions;
mtklein748ca3b2015-01-15 10:56:12 -0800347};
348
Brian Osmanf9810662017-08-30 10:02:10 -0400349class GPUThreadTestingSink : public GPUSink {
350public:
351 GPUThreadTestingSink(sk_gpu_test::GrContextFactory::ContextType,
352 sk_gpu_test::GrContextFactory::ContextOverrides, int samples, bool diText,
353 SkColorType colorType, SkAlphaType alphaType,
354 sk_sp<SkColorSpace> colorSpace, bool threaded,
355 const GrContextOptions& grCtxOptions);
356
357 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
358
Brian Osmanf1942de2017-08-30 14:50:22 -0400359 const char* fileExtension() const override {
360 // Suppress writing out results from this config - we just want to do our matching test
361 return nullptr;
362 }
363
Brian Osmanf9810662017-08-30 10:02:10 -0400364private:
365 std::unique_ptr<SkExecutor> fExecutor;
366
367 typedef GPUSink INHERITED;
368};
369
mtklein748ca3b2015-01-15 10:56:12 -0800370class PDFSink : public Sink {
371public:
Hal Canaryc7d295e2017-07-20 15:36:00 -0400372 PDFSink(bool pdfa, SkScalar rasterDpi) : fPDFA(pdfa), fRasterDpi(rasterDpi) {}
mtklein36352bf2015-03-25 18:17:31 -0700373 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700374 const char* fileExtension() const override { return "pdf"; }
mtklein99cab4e2015-07-31 06:43:04 -0700375 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
halcanary4b656662016-04-27 07:45:18 -0700376 bool fPDFA;
Hal Canaryc7d295e2017-07-20 15:36:00 -0400377 SkScalar fRasterDpi;
mtklein748ca3b2015-01-15 10:56:12 -0800378};
379
halcanary47ef4d52015-03-03 09:13:09 -0800380class XPSSink : public Sink {
381public:
382 XPSSink();
383
mtklein36352bf2015-03-25 18:17:31 -0700384 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700385 const char* fileExtension() const override { return "xps"; }
mtklein99cab4e2015-07-31 06:43:04 -0700386 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
halcanary47ef4d52015-03-03 09:13:09 -0800387};
388
reed54dc4872016-09-13 08:09:45 -0700389class PipeSink : public Sink {
390public:
391 PipeSink();
Mike Klein841101d2017-03-10 09:55:51 -0500392
reed54dc4872016-09-13 08:09:45 -0700393 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
394 const char* fileExtension() const override { return "skpipe"; }
395 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
396};
397
mtklein748ca3b2015-01-15 10:56:12 -0800398class RasterSink : public Sink {
399public:
brianosmanb109b8c2016-06-16 13:03:24 -0700400 explicit RasterSink(SkColorType, sk_sp<SkColorSpace> = nullptr);
mtklein748ca3b2015-01-15 10:56:12 -0800401
mtklein36352bf2015-03-25 18:17:31 -0700402 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700403 const char* fileExtension() const override { return "png"; }
mtklein99cab4e2015-07-31 06:43:04 -0700404 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kRaster, SinkFlags::kDirect }; }
mtklein748ca3b2015-01-15 10:56:12 -0800405private:
brianosmanb109b8c2016-06-16 13:03:24 -0700406 SkColorType fColorType;
407 sk_sp<SkColorSpace> fColorSpace;
mtklein748ca3b2015-01-15 10:56:12 -0800408};
409
mtklein9c3f17d2015-01-28 11:35:18 -0800410class SKPSink : public Sink {
411public:
412 SKPSink();
413
mtklein36352bf2015-03-25 18:17:31 -0700414 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700415 const char* fileExtension() const override { return "skp"; }
mtklein99cab4e2015-07-31 06:43:04 -0700416 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
mtklein9c3f17d2015-01-28 11:35:18 -0800417};
418
Hal Canary85c7fe82016-10-25 10:33:27 -0400419class DebugSink : public Sink {
420public:
421 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
422 const char* fileExtension() const override { return "json"; }
423 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
424};
425
mtklein8a4527e2015-01-31 20:00:58 -0800426class SVGSink : public Sink {
427public:
428 SVGSink();
429
mtklein36352bf2015-03-25 18:17:31 -0700430 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700431 const char* fileExtension() const override { return "svg"; }
mtklein99cab4e2015-07-31 06:43:04 -0700432 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
mtklein8a4527e2015-01-31 20:00:58 -0800433};
434
435
mtklein748ca3b2015-01-15 10:56:12 -0800436/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
437
mtklein78829242015-05-06 07:54:07 -0700438class Via : public Sink {
439public:
msarett62d3b102015-12-10 15:14:27 -0800440 explicit Via(Sink* sink) : fSink(sink) {}
mtklein78829242015-05-06 07:54:07 -0700441 const char* fileExtension() const override { return fSink->fileExtension(); }
mtklein21eaf3b2016-02-08 12:39:59 -0800442 bool serial() const override { return fSink->serial(); }
mtklein99cab4e2015-07-31 06:43:04 -0700443 SinkFlags flags() const override {
444 SinkFlags flags = fSink->flags();
445 flags.approach = SinkFlags::kIndirect;
446 return flags;
447 }
mtklein78829242015-05-06 07:54:07 -0700448protected:
Ben Wagner145dbcd2016-11-03 14:40:50 -0400449 std::unique_ptr<Sink> fSink;
mtklein78829242015-05-06 07:54:07 -0700450};
451
452class ViaMatrix : public Via {
mtklein748ca3b2015-01-15 10:56:12 -0800453public:
msarett62d3b102015-12-10 15:14:27 -0800454 ViaMatrix(SkMatrix, Sink*);
mtklein36352bf2015-03-25 18:17:31 -0700455 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein748ca3b2015-01-15 10:56:12 -0800456private:
mtklein78829242015-05-06 07:54:07 -0700457 const SkMatrix fMatrix;
mtklein748ca3b2015-01-15 10:56:12 -0800458};
459
mtklein78829242015-05-06 07:54:07 -0700460class ViaUpright : public Via {
mtkleind603b222015-02-17 11:13:33 -0800461public:
msarett62d3b102015-12-10 15:14:27 -0800462 ViaUpright(SkMatrix, Sink*);
mtklein36352bf2015-03-25 18:17:31 -0700463 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtkleind603b222015-02-17 11:13:33 -0800464private:
mtklein78829242015-05-06 07:54:07 -0700465 const SkMatrix fMatrix;
mtkleind603b222015-02-17 11:13:33 -0800466};
467
mtklein78829242015-05-06 07:54:07 -0700468class ViaSerialization : public Via {
mtklein748ca3b2015-01-15 10:56:12 -0800469public:
msarett62d3b102015-12-10 15:14:27 -0800470 explicit ViaSerialization(Sink* sink) : Via(sink) {}
mtklein36352bf2015-03-25 18:17:31 -0700471 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein748ca3b2015-01-15 10:56:12 -0800472};
473
mtklein4a34ecb2016-01-08 10:19:35 -0800474class ViaPicture : public Via {
475public:
476 explicit ViaPicture(Sink* sink) : Via(sink) {}
477 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
478};
479
reed54dc4872016-09-13 08:09:45 -0700480class ViaPipe : public Via {
481public:
482 explicit ViaPipe(Sink* sink) : Via(sink) {}
483 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
484};
485
reedbabc3de2016-07-08 08:43:27 -0700486class ViaDefer : public Via {
487public:
488 explicit ViaDefer(Sink* sink) : Via(sink) {}
489 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
490};
491
mtklein78829242015-05-06 07:54:07 -0700492class ViaTiles : public Via {
mtklein748ca3b2015-01-15 10:56:12 -0800493public:
msarett62d3b102015-12-10 15:14:27 -0800494 ViaTiles(int w, int h, SkBBHFactory*, Sink*);
mtklein36352bf2015-03-25 18:17:31 -0700495 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein748ca3b2015-01-15 10:56:12 -0800496private:
497 const int fW, fH;
Ben Wagner145dbcd2016-11-03 14:40:50 -0400498 std::unique_ptr<SkBBHFactory> fFactory;
mtklein748ca3b2015-01-15 10:56:12 -0800499};
500
mtklein78829242015-05-06 07:54:07 -0700501class ViaSecondPicture : public Via {
mtkleinb7e8d692015-04-07 08:30:32 -0700502public:
msarett62d3b102015-12-10 15:14:27 -0800503 explicit ViaSecondPicture(Sink* sink) : Via(sink) {}
mtkleinb7e8d692015-04-07 08:30:32 -0700504 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtkleinb7e8d692015-04-07 08:30:32 -0700505};
506
mtklein78829242015-05-06 07:54:07 -0700507class ViaSingletonPictures : public Via {
mtkleind31c13d2015-05-05 12:59:56 -0700508public:
msarett62d3b102015-12-10 15:14:27 -0800509 explicit ViaSingletonPictures(Sink* sink) : Via(sink) {}
mtkleind31c13d2015-05-05 12:59:56 -0700510 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtkleind31c13d2015-05-05 12:59:56 -0700511};
512
mtklein6fbf4b32015-05-06 11:35:40 -0700513class ViaTwice : public Via {
514public:
msarett62d3b102015-12-10 15:14:27 -0800515 explicit ViaTwice(Sink* sink) : Via(sink) {}
mtklein6fbf4b32015-05-06 11:35:40 -0700516 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
517};
518
Mike Reedf67c4592017-02-17 17:06:11 -0500519class ViaSVG : public Via {
520public:
521 explicit ViaSVG(Sink* sink) : Via(sink) {}
522 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
523};
524
halcanary7a76f9c2016-02-03 11:53:18 -0800525class ViaMojo : public Via {
526public:
527 explicit ViaMojo(Sink* sink) : Via(sink) {}
528 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
529};
530
mtklein9c5052f2016-08-06 12:51:51 -0700531class ViaLite : public Via {
532public:
533 explicit ViaLite(Sink* sink) : Via(sink) {}
534 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
535};
536
Mike Klein841101d2017-03-10 09:55:51 -0500537class ViaCSXform : public Via {
538public:
Mike Klein919cc452017-03-18 15:36:52 +0000539 explicit ViaCSXform(Sink*, sk_sp<SkColorSpace>, bool colorSpin);
Mike Klein841101d2017-03-10 09:55:51 -0500540 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
541private:
542 sk_sp<SkColorSpace> fCS;
Mike Klein919cc452017-03-18 15:36:52 +0000543 bool fColorSpin;
Mike Klein841101d2017-03-10 09:55:51 -0500544};
545
mtklein748ca3b2015-01-15 10:56:12 -0800546} // namespace DM
547
548#endif//DMSrcSink_DEFINED