blob: d9dd346ed0aae2b056ee94eeca45e4b15f7b9bed [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "gm/gm.h"
12#include "include/android/SkBitmapRegionDecoder.h"
13#include "include/core/SkBBHFactory.h"
14#include "include/core/SkBitmap.h"
15#include "include/core/SkCanvas.h"
16#include "include/core/SkData.h"
17#include "include/core/SkPicture.h"
18#include "src/core/SkBBoxHierarchy.h"
19#include "src/utils/SkMultiPictureDocument.h"
20#include "tools/flags/CommonFlagsConfig.h"
mtklein748ca3b2015-01-15 10:56:12 -080021
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:
Hal Canary972eba32018-07-30 17:07:07 -0400103 explicit GMSrc(skiagm::GMFactory);
mtklein748ca3b2015-01-15 10:56:12 -0800104
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:
Hal Canary972eba32018-07-30 17:07:07 -0400111 skiagm::GMFactory fFactory;
mtklein748ca3b2015-01-15 10:56:12 -0800112};
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:
Mike Klein0d5d1422019-03-06 10:56:04 -0600215 ColorCodecSrc(Path, bool decode_to_dst);
msarett69deca82016-04-29 09:38:40 -0700216
217 Error draw(SkCanvas*) const override;
218 SkISize size() const override;
219 Name name() const override;
220 bool veto(SinkFlags) const override;
221private:
Mike Klein0d5d1422019-03-06 10:56:04 -0600222 Path fPath;
223 bool fDecodeToDst;
msarett69deca82016-04-29 09:38:40 -0700224};
225
mtklein748ca3b2015-01-15 10:56:12 -0800226class SKPSrc : public Src {
227public:
mtklein8d17a132015-01-30 11:42:31 -0800228 explicit SKPSrc(Path path);
mtklein748ca3b2015-01-15 10:56:12 -0800229
mtklein36352bf2015-03-25 18:17:31 -0700230 Error draw(SkCanvas*) const override;
231 SkISize size() const override;
232 Name name() const override;
mtklein748ca3b2015-01-15 10:56:12 -0800233private:
mtklein8d17a132015-01-30 11:42:31 -0800234 Path fPath;
mtklein748ca3b2015-01-15 10:56:12 -0800235};
236
Chris Dalton184c37e2018-09-28 11:27:39 -0600237// This class extracts all the paths from an SKP and then removes unwanted paths according to the
238// provided l/r trail. It then just draws the remaining paths. (Non-path draws are thrown out.) It
239// is useful for finding a reduced repo case for path drawing bugs.
240class BisectSrc : public SKPSrc {
241public:
242 explicit BisectSrc(Path path, const char* trail);
243
244 Error draw(SkCanvas*) const override;
245
246private:
247 SkString fTrail;
248
249 typedef SKPSrc INHERITED;
250};
251
Robert Phillipsad8a43f2017-08-30 12:06:35 -0400252
Florin Malita87ccf332018-05-04 12:23:24 -0400253#if defined(SK_ENABLE_SKOTTIE)
Florin Malita54f65c42018-01-16 17:04:30 -0500254class SkottieSrc final : public Src {
Florin Malitafc043dc2017-12-31 11:08:42 -0500255public:
Florin Malita54f65c42018-01-16 17:04:30 -0500256 explicit SkottieSrc(Path path);
Florin Malitafc043dc2017-12-31 11:08:42 -0500257
258 Error draw(SkCanvas*) const override;
259 SkISize size() const override;
260 Name name() const override;
261 bool veto(SinkFlags) const override;
262
263private:
264 // Generates a kTileCount x kTileCount filmstrip with evenly distributed frames.
Florin Malita1022f742018-02-23 11:10:22 -0500265 static constexpr int kTileCount = 5;
Florin Malitafc043dc2017-12-31 11:08:42 -0500266
Florin Malita9f7d4cd2018-07-30 15:49:20 -0400267 // Fit kTileCount x kTileCount frames to a 1000x1000 film strip.
268 static constexpr SkScalar kTargetSize = 1000;
269 static constexpr SkScalar kTileSize = kTargetSize / kTileCount;
270
271 Path fPath;
Florin Malitafc043dc2017-12-31 11:08:42 -0500272};
Florin Malita124d5af2017-12-31 17:02:26 -0500273#endif
Florin Malitafc043dc2017-12-31 11:08:42 -0500274
fmalitaa2b9fdf2016-08-03 19:53:36 -0700275#if defined(SK_XML)
fmalitabdf3e5c2016-09-17 07:26:26 -0700276} // namespace DM
277
278class SkSVGDOM;
279
280namespace DM {
281
fmalitaa2b9fdf2016-08-03 19:53:36 -0700282class SVGSrc : public Src {
283public:
284 explicit SVGSrc(Path path);
285
286 Error draw(SkCanvas*) const override;
287 SkISize size() const override;
288 Name name() const override;
fmalita179d8852016-08-16 14:23:29 -0700289 bool veto(SinkFlags) const override;
fmalitaa2b9fdf2016-08-03 19:53:36 -0700290
291private:
fmalitaacd2f5c2016-11-08 07:13:45 -0800292 Name fName;
293 sk_sp<SkSVGDOM> fDom;
294 SkScalar fScale;
fmalitaa2b9fdf2016-08-03 19:53:36 -0700295
296 typedef Src INHERITED;
297};
298#endif // SK_XML
mtklein748ca3b2015-01-15 10:56:12 -0800299/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
300
halcanary45420a92016-06-02 12:41:14 -0700301class MSKPSrc : public Src {
302public:
303 explicit MSKPSrc(Path path);
304
305 int pageCount() const override;
306 Error draw(SkCanvas* c) const override;
307 Error draw(int, SkCanvas*) const override;
308 SkISize size() const override;
309 SkISize size(int) const override;
310 Name name() const override;
311
312private:
313 Path fPath;
Hal Canary45cde312017-04-03 16:06:42 -0400314 mutable SkTArray<SkDocumentPage> fPages;
halcanary45420a92016-06-02 12:41:14 -0700315};
316
317/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
318
mtkleinad66f9b2015-02-13 15:11:10 -0800319class NullSink : public Sink {
320public:
321 NullSink() {}
322
mtklein36352bf2015-03-25 18:17:31 -0700323 Error draw(const Src& src, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700324 const char* fileExtension() const override { return ""; }
mtklein99cab4e2015-07-31 06:43:04 -0700325 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kNull, SinkFlags::kDirect }; }
mtkleinad66f9b2015-02-13 15:11:10 -0800326};
327
mtklein748ca3b2015-01-15 10:56:12 -0800328class GPUSink : public Sink {
329public:
bsalomon85b4b532016-04-05 11:06:27 -0700330 GPUSink(sk_gpu_test::GrContextFactory::ContextType,
Brian Salomonf865b052018-03-09 09:01:53 -0500331 sk_gpu_test::GrContextFactory::ContextOverrides,
332 SkCommandLineConfigGpu::SurfType surfType, int samples, bool diText,
Brian Salomonce5ee602017-07-17 11:31:31 -0400333 SkColorType colorType, SkAlphaType alphaType, sk_sp<SkColorSpace> colorSpace,
Brian Osmanf21aa042017-08-21 16:48:46 -0400334 bool threaded, const GrContextOptions& grCtxOptions);
mtklein748ca3b2015-01-15 10:56:12 -0800335
mtklein36352bf2015-03-25 18:17:31 -0700336 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
Brian Osmanf9810662017-08-30 10:02:10 -0400337 Error onDraw(const Src&, SkBitmap*, SkWStream*, SkString*,
338 const GrContextOptions& baseOptions) const;
339
Brian Salomonb07fd4d2018-03-09 13:17:30 -0500340 sk_gpu_test::GrContextFactory::ContextType contextType() const { return fContextType; }
341 const sk_gpu_test::GrContextFactory::ContextOverrides& contextOverrides() {
342 return fContextOverrides;
343 }
344 SkCommandLineConfigGpu::SurfType surfType() const { return fSurfType; }
345 bool useDIText() const { return fUseDIText; }
mtklein21eaf3b2016-02-08 12:39:59 -0800346 bool serial() const override { return !fThreaded; }
mtklein36352bf2015-03-25 18:17:31 -0700347 const char* fileExtension() const override { return "png"; }
Brian Salomonbd7c5512017-03-07 09:08:36 -0500348 SinkFlags flags() const override {
Brian Salomonbdecacf2018-02-02 20:32:49 -0500349 SinkFlags::Multisampled ms = fSampleCount > 1 ? SinkFlags::kMultisampled
Brian Salomonfd171ed2017-03-08 11:38:45 -0500350 : SinkFlags::kNotMultisampled;
351 return SinkFlags{ SinkFlags::kGPU, SinkFlags::kDirect, ms };
Brian Salomonbd7c5512017-03-07 09:08:36 -0500352 }
Brian Osmanf9810662017-08-30 10:02:10 -0400353 const GrContextOptions& baseContextOptions() const { return fBaseContextOptions; }
354
mtklein748ca3b2015-01-15 10:56:12 -0800355private:
csmartdaltone812d492017-02-21 12:36:05 -0700356 sk_gpu_test::GrContextFactory::ContextType fContextType;
357 sk_gpu_test::GrContextFactory::ContextOverrides fContextOverrides;
Brian Salomonf865b052018-03-09 09:01:53 -0500358 SkCommandLineConfigGpu::SurfType fSurfType;
csmartdaltone812d492017-02-21 12:36:05 -0700359 int fSampleCount;
360 bool fUseDIText;
361 SkColorType fColorType;
Brian Salomonce5ee602017-07-17 11:31:31 -0400362 SkAlphaType fAlphaType;
csmartdaltone812d492017-02-21 12:36:05 -0700363 sk_sp<SkColorSpace> fColorSpace;
364 bool fThreaded;
Brian Osmanf21aa042017-08-21 16:48:46 -0400365 GrContextOptions fBaseContextOptions;
mtklein748ca3b2015-01-15 10:56:12 -0800366};
367
Brian Osmanf9810662017-08-30 10:02:10 -0400368class GPUThreadTestingSink : public GPUSink {
369public:
370 GPUThreadTestingSink(sk_gpu_test::GrContextFactory::ContextType,
Brian Salomonf865b052018-03-09 09:01:53 -0500371 sk_gpu_test::GrContextFactory::ContextOverrides,
372 SkCommandLineConfigGpu::SurfType surfType, int samples, bool diText,
Brian Osmanf9810662017-08-30 10:02:10 -0400373 SkColorType colorType, SkAlphaType alphaType,
374 sk_sp<SkColorSpace> colorSpace, bool threaded,
375 const GrContextOptions& grCtxOptions);
376
377 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
378
Brian Osmanf1942de2017-08-30 14:50:22 -0400379 const char* fileExtension() const override {
380 // Suppress writing out results from this config - we just want to do our matching test
381 return nullptr;
382 }
383
Brian Osmanf9810662017-08-30 10:02:10 -0400384private:
385 std::unique_ptr<SkExecutor> fExecutor;
386
387 typedef GPUSink INHERITED;
388};
389
Brian Salomon00a5eb82018-07-11 15:32:05 -0400390class GPUPersistentCacheTestingSink : public GPUSink {
391public:
392 GPUPersistentCacheTestingSink(sk_gpu_test::GrContextFactory::ContextType,
393 sk_gpu_test::GrContextFactory::ContextOverrides,
394 SkCommandLineConfigGpu::SurfType surfType, int samples,
395 bool diText, SkColorType colorType, SkAlphaType alphaType,
396 sk_sp<SkColorSpace> colorSpace, bool threaded,
Brian Osmanf71b0702019-04-03 13:04:16 -0400397 const GrContextOptions& grCtxOptions,
398 int cacheType);
Brian Salomon00a5eb82018-07-11 15:32:05 -0400399
400 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
401
402 const char* fileExtension() const override {
403 // Suppress writing out results from this config - we just want to do our matching test
404 return nullptr;
405 }
406
407private:
Brian Osmanf71b0702019-04-03 13:04:16 -0400408 int fCacheType;
409
Brian Salomon00a5eb82018-07-11 15:32:05 -0400410 typedef GPUSink INHERITED;
411};
412
mtklein748ca3b2015-01-15 10:56:12 -0800413class PDFSink : public Sink {
414public:
Hal Canaryc7d295e2017-07-20 15:36:00 -0400415 PDFSink(bool pdfa, SkScalar rasterDpi) : fPDFA(pdfa), fRasterDpi(rasterDpi) {}
mtklein36352bf2015-03-25 18:17:31 -0700416 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700417 const char* fileExtension() const override { return "pdf"; }
mtklein99cab4e2015-07-31 06:43:04 -0700418 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
halcanary4b656662016-04-27 07:45:18 -0700419 bool fPDFA;
Hal Canaryc7d295e2017-07-20 15:36:00 -0400420 SkScalar fRasterDpi;
mtklein748ca3b2015-01-15 10:56:12 -0800421};
422
halcanary47ef4d52015-03-03 09:13:09 -0800423class XPSSink : public Sink {
424public:
425 XPSSink();
426
mtklein36352bf2015-03-25 18:17:31 -0700427 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700428 const char* fileExtension() const override { return "xps"; }
mtklein99cab4e2015-07-31 06:43:04 -0700429 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
halcanary47ef4d52015-03-03 09:13:09 -0800430};
431
mtklein748ca3b2015-01-15 10:56:12 -0800432class RasterSink : public Sink {
433public:
brianosmanb109b8c2016-06-16 13:03:24 -0700434 explicit RasterSink(SkColorType, sk_sp<SkColorSpace> = nullptr);
mtklein748ca3b2015-01-15 10:56:12 -0800435
mtklein36352bf2015-03-25 18:17:31 -0700436 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700437 const char* fileExtension() const override { return "png"; }
mtklein99cab4e2015-07-31 06:43:04 -0700438 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kRaster, SinkFlags::kDirect }; }
Yuqian Lib8b62532018-02-23 14:13:36 +0800439
Mike Klein48b64902018-07-25 13:28:44 -0400440private:
brianosmanb109b8c2016-06-16 13:03:24 -0700441 SkColorType fColorType;
442 sk_sp<SkColorSpace> fColorSpace;
mtklein748ca3b2015-01-15 10:56:12 -0800443};
444
Yuqian Lib8b62532018-02-23 14:13:36 +0800445class ThreadedSink : public RasterSink {
446public:
447 explicit ThreadedSink(SkColorType, sk_sp<SkColorSpace> = nullptr);
448 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
Yuqian Lib8b62532018-02-23 14:13:36 +0800449};
450
mtklein9c3f17d2015-01-28 11:35:18 -0800451class SKPSink : public Sink {
452public:
453 SKPSink();
454
mtklein36352bf2015-03-25 18:17:31 -0700455 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700456 const char* fileExtension() const override { return "skp"; }
mtklein99cab4e2015-07-31 06:43:04 -0700457 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
mtklein9c3f17d2015-01-28 11:35:18 -0800458};
459
Hal Canary85c7fe82016-10-25 10:33:27 -0400460class DebugSink : public Sink {
461public:
462 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
463 const char* fileExtension() const override { return "json"; }
464 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
465};
466
mtklein8a4527e2015-01-31 20:00:58 -0800467class SVGSink : public Sink {
468public:
Bryce Thomas95a7b762018-03-02 13:54:21 -0800469 SVGSink(int pageIndex = 0);
mtklein8a4527e2015-01-31 20:00:58 -0800470
mtklein36352bf2015-03-25 18:17:31 -0700471 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700472 const char* fileExtension() const override { return "svg"; }
mtklein99cab4e2015-07-31 06:43:04 -0700473 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
Bryce Thomas95a7b762018-03-02 13:54:21 -0800474
475private:
476 int fPageIndex;
mtklein8a4527e2015-01-31 20:00:58 -0800477};
478
479
mtklein748ca3b2015-01-15 10:56:12 -0800480/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
481
mtklein78829242015-05-06 07:54:07 -0700482class Via : public Sink {
483public:
msarett62d3b102015-12-10 15:14:27 -0800484 explicit Via(Sink* sink) : fSink(sink) {}
mtklein78829242015-05-06 07:54:07 -0700485 const char* fileExtension() const override { return fSink->fileExtension(); }
mtklein21eaf3b2016-02-08 12:39:59 -0800486 bool serial() const override { return fSink->serial(); }
mtklein99cab4e2015-07-31 06:43:04 -0700487 SinkFlags flags() const override {
488 SinkFlags flags = fSink->flags();
489 flags.approach = SinkFlags::kIndirect;
490 return flags;
491 }
mtklein78829242015-05-06 07:54:07 -0700492protected:
Ben Wagner145dbcd2016-11-03 14:40:50 -0400493 std::unique_ptr<Sink> fSink;
mtklein78829242015-05-06 07:54:07 -0700494};
495
496class ViaMatrix : public Via {
mtklein748ca3b2015-01-15 10:56:12 -0800497public:
msarett62d3b102015-12-10 15:14:27 -0800498 ViaMatrix(SkMatrix, Sink*);
mtklein36352bf2015-03-25 18:17:31 -0700499 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein748ca3b2015-01-15 10:56:12 -0800500private:
mtklein78829242015-05-06 07:54:07 -0700501 const SkMatrix fMatrix;
mtklein748ca3b2015-01-15 10:56:12 -0800502};
503
mtklein78829242015-05-06 07:54:07 -0700504class ViaUpright : public Via {
mtkleind603b222015-02-17 11:13:33 -0800505public:
msarett62d3b102015-12-10 15:14:27 -0800506 ViaUpright(SkMatrix, Sink*);
mtklein36352bf2015-03-25 18:17:31 -0700507 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtkleind603b222015-02-17 11:13:33 -0800508private:
mtklein78829242015-05-06 07:54:07 -0700509 const SkMatrix fMatrix;
mtkleind603b222015-02-17 11:13:33 -0800510};
511
mtklein78829242015-05-06 07:54:07 -0700512class ViaSerialization : public Via {
mtklein748ca3b2015-01-15 10:56:12 -0800513public:
msarett62d3b102015-12-10 15:14:27 -0800514 explicit ViaSerialization(Sink* sink) : Via(sink) {}
mtklein36352bf2015-03-25 18:17:31 -0700515 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein748ca3b2015-01-15 10:56:12 -0800516};
517
mtklein4a34ecb2016-01-08 10:19:35 -0800518class ViaPicture : public Via {
519public:
520 explicit ViaPicture(Sink* sink) : Via(sink) {}
521 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
522};
523
mtklein78829242015-05-06 07:54:07 -0700524class ViaTiles : public Via {
mtklein748ca3b2015-01-15 10:56:12 -0800525public:
msarett62d3b102015-12-10 15:14:27 -0800526 ViaTiles(int w, int h, SkBBHFactory*, Sink*);
mtklein36352bf2015-03-25 18:17:31 -0700527 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein748ca3b2015-01-15 10:56:12 -0800528private:
529 const int fW, fH;
Ben Wagner145dbcd2016-11-03 14:40:50 -0400530 std::unique_ptr<SkBBHFactory> fFactory;
mtklein748ca3b2015-01-15 10:56:12 -0800531};
532
Robert Phillips33f02ed2018-03-27 08:06:57 -0400533class ViaDDL : public Via {
534public:
Brian Salomon57904202018-12-17 14:45:00 -0500535 ViaDDL(int numReplays, int numDivisions, Sink* sink);
Robert Phillips33f02ed2018-03-27 08:06:57 -0400536 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
537private:
Brian Salomon57904202018-12-17 14:45:00 -0500538 const int fNumReplays;
Robert Phillips33f02ed2018-03-27 08:06:57 -0400539 const int fNumDivisions;
Robert Phillips33f02ed2018-03-27 08:06:57 -0400540};
541
Mike Reedf67c4592017-02-17 17:06:11 -0500542class ViaSVG : public Via {
543public:
544 explicit ViaSVG(Sink* sink) : Via(sink) {}
545 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
546};
547
mtklein748ca3b2015-01-15 10:56:12 -0800548} // namespace DM
549
550#endif//DMSrcSink_DEFINED