blob: 5b7338b4400416cdb9dbc8949471800c3b3c6ab7 [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"
Brian Osman9c310472019-06-27 16:43:27 -040021#include "tools/gpu/MemoryCache.h"
mtklein748ca3b2015-01-15 10:56:12 -080022
Brian Osmaned58e002019-09-06 14:42:43 -040023#include <functional>
24
Mike Reedbae888e2017-02-18 16:50:45 -050025//#define TEST_VIA_SVG
26
mtklein748ca3b2015-01-15 10:56:12 -080027namespace DM {
28
29// This is just convenience. It lets you use either return "foo" or return SkStringPrintf(...).
30struct ImplicitString : public SkString {
31 template <typename T>
32 ImplicitString(const T& s) : SkString(s) {}
msarett9e707a02015-09-01 14:57:57 -070033 ImplicitString() : SkString("") {}
mtklein748ca3b2015-01-15 10:56:12 -080034};
mtklein748ca3b2015-01-15 10:56:12 -080035typedef ImplicitString Name;
mtklein8d17a132015-01-30 11:42:31 -080036typedef ImplicitString Path;
mtklein748ca3b2015-01-15 10:56:12 -080037
mtklein4089ef72015-03-05 08:40:28 -080038class Error {
39public:
40 Error(const SkString& s) : fMsg(s), fFatal(!this->isEmpty()) {}
41 Error(const char* s) : fMsg(s), fFatal(!this->isEmpty()) {}
42
43 Error(const Error&) = default;
44 Error& operator=(const Error&) = default;
45
46 static Error Nonfatal(const SkString& s) { return Nonfatal(s.c_str()); }
47 static Error Nonfatal(const char* s) {
48 Error e(s);
49 e.fFatal = false;
50 return e;
51 }
52
53 const char* c_str() const { return fMsg.c_str(); }
54 bool isEmpty() const { return fMsg.isEmpty(); }
55 bool isFatal() const { return fFatal; }
56
57private:
58 SkString fMsg;
59 bool fFatal;
60};
61
mtklein99cab4e2015-07-31 06:43:04 -070062struct SinkFlags {
Brian Salomonbd7c5512017-03-07 09:08:36 -050063 enum Type { kNull, kGPU, kVector, kRaster } type;
64 enum Approach { kDirect, kIndirect } approach;
65 enum Multisampled { kNotMultisampled, kMultisampled } multisampled;
66 SinkFlags(Type t, Approach a, Multisampled ms = kNotMultisampled)
67 : type(t), approach(a), multisampled(ms) {}
mtklein99cab4e2015-07-31 06:43:04 -070068};
mtkleine0effd62015-07-29 06:37:28 -070069
mtklein748ca3b2015-01-15 10:56:12 -080070struct Src {
mtklein748ca3b2015-01-15 10:56:12 -080071 virtual ~Src() {}
72 virtual Error SK_WARN_UNUSED_RESULT draw(SkCanvas*) const = 0;
73 virtual SkISize size() const = 0;
74 virtual Name name() const = 0;
bsalomon4ee6bd82015-05-27 13:23:23 -070075 virtual void modifyGrContextOptions(GrContextOptions* options) const {}
mtklein99cab4e2015-07-31 06:43:04 -070076 virtual bool veto(SinkFlags) const { return false; }
mtklein21eaf3b2016-02-08 12:39:59 -080077
halcanary45420a92016-06-02 12:41:14 -070078 virtual int pageCount() const { return 1; }
79 virtual Error SK_WARN_UNUSED_RESULT draw(int, SkCanvas* canvas) const {
80 return this->draw(canvas);
81 }
82 virtual SkISize size(int) const { return this->size(); }
mtklein21eaf3b2016-02-08 12:39:59 -080083 // Force Tasks using this Src to run on the main thread?
84 virtual bool serial() const { return false; }
mtklein748ca3b2015-01-15 10:56:12 -080085};
86
87struct Sink {
88 virtual ~Sink() {}
mtkleinb9eb4ac2015-02-02 18:26:03 -080089 // You may write to either the bitmap or stream. If you write to log, we'll print that out.
90 virtual Error SK_WARN_UNUSED_RESULT draw(const Src&, SkBitmap*, SkWStream*, SkString* log)
91 const = 0;
mtklein21eaf3b2016-02-08 12:39:59 -080092
93 // Force Tasks using this Sink to run on the main thread?
94 virtual bool serial() const { return false; }
mtklein748ca3b2015-01-15 10:56:12 -080095
96 // File extension for the content draw() outputs, e.g. "png", "pdf".
97 virtual const char* fileExtension() const = 0;
mtklein99cab4e2015-07-31 06:43:04 -070098
99 virtual SinkFlags flags() const = 0;
mtklein748ca3b2015-01-15 10:56:12 -0800100};
101
mtklein748ca3b2015-01-15 10:56:12 -0800102/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
103
mtklein748ca3b2015-01-15 10:56:12 -0800104class GMSrc : public Src {
105public:
Hal Canary972eba32018-07-30 17:07:07 -0400106 explicit GMSrc(skiagm::GMFactory);
mtklein748ca3b2015-01-15 10:56:12 -0800107
mtklein36352bf2015-03-25 18:17:31 -0700108 Error draw(SkCanvas*) const override;
109 SkISize size() const override;
110 Name name() const override;
bsalomon4ee6bd82015-05-27 13:23:23 -0700111 void modifyGrContextOptions(GrContextOptions* options) const override;
112
mtklein748ca3b2015-01-15 10:56:12 -0800113private:
Hal Canary972eba32018-07-30 17:07:07 -0400114 skiagm::GMFactory fFactory;
mtklein748ca3b2015-01-15 10:56:12 -0800115};
116
scroggo9b77ddd2015-03-19 06:03:39 -0700117class CodecSrc : public Src {
118public:
scroggo9c59ebc2015-03-25 13:48:49 -0700119 enum Mode {
msarett9e707a02015-09-01 14:57:57 -0700120 kCodec_Mode,
msarettbb25b532016-01-13 09:31:39 -0800121 // We choose to test only one mode with zero initialized memory.
122 // This will exercise all of the interesting cases in SkSwizzler
123 // without doubling the size of our test suite.
124 kCodecZeroInit_Mode,
scroggo9c59ebc2015-03-25 13:48:49 -0700125 kScanline_Mode,
msarett0a242972015-06-11 14:27:27 -0700126 kStripe_Mode, // Tests the skipping of scanlines
msarett91c22b22016-02-22 12:27:46 -0800127 kCroppedScanline_Mode, // Tests (jpeg) cropped scanline optimization
scroggob636b452015-07-22 07:16:20 -0700128 kSubset_Mode, // For codecs that support subsets directly.
scroggo19b91532016-10-24 09:03:26 -0700129 kAnimated_Mode, // For codecs that support animation.
scroggo9c59ebc2015-03-25 13:48:49 -0700130 };
msarett438b2ad2015-04-09 12:43:10 -0700131 enum DstColorType {
132 kGetFromCanvas_DstColorType,
msarett438b2ad2015-04-09 12:43:10 -0700133 kGrayscale_Always_DstColorType,
msarett34e0ec42016-04-22 16:27:24 -0700134 kNonNative8888_Always_DstColorType,
msarett438b2ad2015-04-09 12:43:10 -0700135 };
scroggoc5560be2016-02-03 09:42:42 -0800136 CodecSrc(Path, Mode, DstColorType, SkAlphaType, float);
scroggo9b77ddd2015-03-19 06:03:39 -0700137
mtklein36352bf2015-03-25 18:17:31 -0700138 Error draw(SkCanvas*) const override;
139 SkISize size() const override;
140 Name name() const override;
mtklein99cab4e2015-07-31 06:43:04 -0700141 bool veto(SinkFlags) const override;
scroggo3ac66e92016-02-08 15:09:48 -0800142 bool serial() const override { return fRunSerially; }
scroggo9b77ddd2015-03-19 06:03:39 -0700143private:
msarett9e707a02015-09-01 14:57:57 -0700144 Path fPath;
145 Mode fMode;
146 DstColorType fDstColorType;
scroggoc5560be2016-02-03 09:42:42 -0800147 SkAlphaType fDstAlphaType;
msarett9e707a02015-09-01 14:57:57 -0700148 float fScale;
scroggo3ac66e92016-02-08 15:09:48 -0800149 bool fRunSerially;
scroggo9b77ddd2015-03-19 06:03:39 -0700150};
151
msarett3d9d7a72015-10-21 10:27:10 -0700152class AndroidCodecSrc : public Src {
153public:
scroggof8dc9df2016-05-16 09:04:13 -0700154 AndroidCodecSrc(Path, CodecSrc::DstColorType, SkAlphaType, int sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700155
156 Error draw(SkCanvas*) const override;
157 SkISize size() const override;
158 Name name() const override;
159 bool veto(SinkFlags) const override;
scroggo3ac66e92016-02-08 15:09:48 -0800160 bool serial() const override { return fRunSerially; }
msarett3d9d7a72015-10-21 10:27:10 -0700161private:
162 Path fPath;
msarett3d9d7a72015-10-21 10:27:10 -0700163 CodecSrc::DstColorType fDstColorType;
scroggoc5560be2016-02-03 09:42:42 -0800164 SkAlphaType fDstAlphaType;
msarett3d9d7a72015-10-21 10:27:10 -0700165 int fSampleSize;
scroggo3ac66e92016-02-08 15:09:48 -0800166 bool fRunSerially;
msarett3d9d7a72015-10-21 10:27:10 -0700167};
168
msaretta5783ae2015-09-08 15:35:32 -0700169// Allows for testing of various implementations of Android's BitmapRegionDecoder
170class BRDSrc : public Src {
171public:
172 enum Mode {
173 // Decode the entire image as one region.
174 kFullImage_Mode,
175 // Splits the image into multiple regions using a divisor and decodes the regions
176 // separately. Also, this test adds a border of a few pixels to each of the regions
177 // that it is decoding. This tests the behavior when a client asks for a region that
178 // does not fully fit in the image.
179 kDivisor_Mode,
180 };
181
msarettd1227a72016-05-18 06:23:57 -0700182 BRDSrc(Path, Mode, CodecSrc::DstColorType, uint32_t);
msaretta5783ae2015-09-08 15:35:32 -0700183
msaretta5783ae2015-09-08 15:35:32 -0700184 Error draw(SkCanvas*) const override;
185 SkISize size() const override;
186 Name name() const override;
187 bool veto(SinkFlags) const override;
188private:
189 Path fPath;
msaretta5783ae2015-09-08 15:35:32 -0700190 Mode fMode;
191 CodecSrc::DstColorType fDstColorType;
192 uint32_t fSampleSize;
193};
scroggo9b77ddd2015-03-19 06:03:39 -0700194
msarett18976312016-03-09 14:20:58 -0800195class ImageGenSrc : public Src {
196public:
197 enum Mode {
198 kCodec_Mode, // Use CodecImageGenerator
199 kPlatform_Mode, // Uses CG or WIC
200 };
201 ImageGenSrc(Path, Mode, SkAlphaType, bool);
202
203 Error draw(SkCanvas*) const override;
204 SkISize size() const override;
205 Name name() const override;
206 bool veto(SinkFlags) const override;
207 bool serial() const override { return fRunSerially; }
208private:
209 Path fPath;
210 Mode fMode;
211 SkAlphaType fDstAlphaType;
212 bool fIsGpu;
213 bool fRunSerially;
214};
215
msarett69deca82016-04-29 09:38:40 -0700216class ColorCodecSrc : public Src {
217public:
Mike Klein0d5d1422019-03-06 10:56:04 -0600218 ColorCodecSrc(Path, bool decode_to_dst);
msarett69deca82016-04-29 09:38:40 -0700219
220 Error draw(SkCanvas*) const override;
221 SkISize size() const override;
222 Name name() const override;
223 bool veto(SinkFlags) const override;
224private:
Mike Klein0d5d1422019-03-06 10:56:04 -0600225 Path fPath;
226 bool fDecodeToDst;
msarett69deca82016-04-29 09:38:40 -0700227};
228
mtklein748ca3b2015-01-15 10:56:12 -0800229class SKPSrc : public Src {
230public:
mtklein8d17a132015-01-30 11:42:31 -0800231 explicit SKPSrc(Path path);
mtklein748ca3b2015-01-15 10:56:12 -0800232
mtklein36352bf2015-03-25 18:17:31 -0700233 Error draw(SkCanvas*) const override;
234 SkISize size() const override;
235 Name name() const override;
mtklein748ca3b2015-01-15 10:56:12 -0800236private:
mtklein8d17a132015-01-30 11:42:31 -0800237 Path fPath;
mtklein748ca3b2015-01-15 10:56:12 -0800238};
239
Chris Dalton184c37e2018-09-28 11:27:39 -0600240// This class extracts all the paths from an SKP and then removes unwanted paths according to the
241// provided l/r trail. It then just draws the remaining paths. (Non-path draws are thrown out.) It
242// is useful for finding a reduced repo case for path drawing bugs.
243class BisectSrc : public SKPSrc {
244public:
245 explicit BisectSrc(Path path, const char* trail);
246
247 Error draw(SkCanvas*) const override;
248
249private:
250 SkString fTrail;
251
252 typedef SKPSrc INHERITED;
253};
254
Robert Phillipsad8a43f2017-08-30 12:06:35 -0400255
Florin Malita87ccf332018-05-04 12:23:24 -0400256#if defined(SK_ENABLE_SKOTTIE)
Florin Malita54f65c42018-01-16 17:04:30 -0500257class SkottieSrc final : public Src {
Florin Malitafc043dc2017-12-31 11:08:42 -0500258public:
Florin Malita54f65c42018-01-16 17:04:30 -0500259 explicit SkottieSrc(Path path);
Florin Malitafc043dc2017-12-31 11:08:42 -0500260
261 Error draw(SkCanvas*) const override;
262 SkISize size() const override;
263 Name name() const override;
264 bool veto(SinkFlags) const override;
265
266private:
267 // Generates a kTileCount x kTileCount filmstrip with evenly distributed frames.
Florin Malita1022f742018-02-23 11:10:22 -0500268 static constexpr int kTileCount = 5;
Florin Malitafc043dc2017-12-31 11:08:42 -0500269
Florin Malita9f7d4cd2018-07-30 15:49:20 -0400270 // Fit kTileCount x kTileCount frames to a 1000x1000 film strip.
271 static constexpr SkScalar kTargetSize = 1000;
272 static constexpr SkScalar kTileSize = kTargetSize / kTileCount;
273
274 Path fPath;
Florin Malitafc043dc2017-12-31 11:08:42 -0500275};
Florin Malita124d5af2017-12-31 17:02:26 -0500276#endif
Florin Malitafc043dc2017-12-31 11:08:42 -0500277
fmalitaa2b9fdf2016-08-03 19:53:36 -0700278#if defined(SK_XML)
fmalitabdf3e5c2016-09-17 07:26:26 -0700279} // namespace DM
280
281class SkSVGDOM;
282
283namespace DM {
284
fmalitaa2b9fdf2016-08-03 19:53:36 -0700285class SVGSrc : public Src {
286public:
287 explicit SVGSrc(Path path);
288
289 Error draw(SkCanvas*) const override;
290 SkISize size() const override;
291 Name name() const override;
fmalita179d8852016-08-16 14:23:29 -0700292 bool veto(SinkFlags) const override;
fmalitaa2b9fdf2016-08-03 19:53:36 -0700293
294private:
fmalitaacd2f5c2016-11-08 07:13:45 -0800295 Name fName;
296 sk_sp<SkSVGDOM> fDom;
297 SkScalar fScale;
fmalitaa2b9fdf2016-08-03 19:53:36 -0700298
299 typedef Src INHERITED;
300};
301#endif // SK_XML
mtklein748ca3b2015-01-15 10:56:12 -0800302/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
303
halcanary45420a92016-06-02 12:41:14 -0700304class MSKPSrc : public Src {
305public:
306 explicit MSKPSrc(Path path);
307
308 int pageCount() const override;
309 Error draw(SkCanvas* c) const override;
310 Error draw(int, SkCanvas*) const override;
311 SkISize size() const override;
312 SkISize size(int) const override;
313 Name name() const override;
314
315private:
316 Path fPath;
Hal Canary45cde312017-04-03 16:06:42 -0400317 mutable SkTArray<SkDocumentPage> fPages;
halcanary45420a92016-06-02 12:41:14 -0700318};
319
320/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
321
mtkleinad66f9b2015-02-13 15:11:10 -0800322class NullSink : public Sink {
323public:
324 NullSink() {}
325
mtklein36352bf2015-03-25 18:17:31 -0700326 Error draw(const Src& src, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700327 const char* fileExtension() const override { return ""; }
mtklein99cab4e2015-07-31 06:43:04 -0700328 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kNull, SinkFlags::kDirect }; }
mtkleinad66f9b2015-02-13 15:11:10 -0800329};
330
mtklein748ca3b2015-01-15 10:56:12 -0800331class GPUSink : public Sink {
332public:
Brian Osman3fdfe282019-09-09 13:46:52 -0400333 GPUSink(const SkCommandLineConfigGpu*, const GrContextOptions&);
mtklein748ca3b2015-01-15 10:56:12 -0800334
mtklein36352bf2015-03-25 18:17:31 -0700335 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
Brian Osmanf9810662017-08-30 10:02:10 -0400336 Error onDraw(const Src&, SkBitmap*, SkWStream*, SkString*,
Brian Osmaned58e002019-09-06 14:42:43 -0400337 const GrContextOptions& baseOptions,
338 std::function<void(GrContext*)> initContext = nullptr) const;
Brian Osmanf9810662017-08-30 10:02:10 -0400339
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; }
Brian Osman3fdfe282019-09-09 13:46:52 -0400346 bool serial() const override { return true; }
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;
Brian Osmanf21aa042017-08-21 16:48:46 -0400364 GrContextOptions fBaseContextOptions;
Brian Osman9c310472019-06-27 16:43:27 -0400365 sk_gpu_test::MemoryCache fMemoryCache;
mtklein748ca3b2015-01-15 10:56:12 -0800366};
367
Brian Osmanf9810662017-08-30 10:02:10 -0400368class GPUThreadTestingSink : public GPUSink {
369public:
Brian Osman3fdfe282019-09-09 13:46:52 -0400370 GPUThreadTestingSink(const SkCommandLineConfigGpu*, const GrContextOptions&);
Brian Osmanf9810662017-08-30 10:02:10 -0400371
372 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
373
Brian Osmanf1942de2017-08-30 14:50:22 -0400374 const char* fileExtension() const override {
375 // Suppress writing out results from this config - we just want to do our matching test
376 return nullptr;
377 }
378
Brian Osmanf9810662017-08-30 10:02:10 -0400379private:
380 std::unique_ptr<SkExecutor> fExecutor;
381
382 typedef GPUSink INHERITED;
383};
384
Brian Salomon00a5eb82018-07-11 15:32:05 -0400385class GPUPersistentCacheTestingSink : public GPUSink {
386public:
Brian Osman3fdfe282019-09-09 13:46:52 -0400387 GPUPersistentCacheTestingSink(const SkCommandLineConfigGpu*, const GrContextOptions&);
Brian Salomon00a5eb82018-07-11 15:32:05 -0400388
389 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
390
391 const char* fileExtension() const override {
392 // Suppress writing out results from this config - we just want to do our matching test
393 return nullptr;
394 }
395
396private:
Brian Osmanf71b0702019-04-03 13:04:16 -0400397 int fCacheType;
398
Brian Salomon00a5eb82018-07-11 15:32:05 -0400399 typedef GPUSink INHERITED;
400};
401
Brian Osmaned58e002019-09-06 14:42:43 -0400402class GPUPrecompileTestingSink : public GPUSink {
403public:
Brian Osman3fdfe282019-09-09 13:46:52 -0400404 GPUPrecompileTestingSink(const SkCommandLineConfigGpu*, const GrContextOptions&);
Brian Osmaned58e002019-09-06 14:42:43 -0400405
406 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
407
408 const char* fileExtension() const override {
409 // Suppress writing out results from this config - we just want to do our matching test
410 return nullptr;
411 }
412
413private:
414 typedef GPUSink INHERITED;
415};
416
mtklein748ca3b2015-01-15 10:56:12 -0800417class PDFSink : public Sink {
418public:
Hal Canaryc7d295e2017-07-20 15:36:00 -0400419 PDFSink(bool pdfa, SkScalar rasterDpi) : fPDFA(pdfa), fRasterDpi(rasterDpi) {}
mtklein36352bf2015-03-25 18:17:31 -0700420 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700421 const char* fileExtension() const override { return "pdf"; }
mtklein99cab4e2015-07-31 06:43:04 -0700422 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
halcanary4b656662016-04-27 07:45:18 -0700423 bool fPDFA;
Hal Canaryc7d295e2017-07-20 15:36:00 -0400424 SkScalar fRasterDpi;
mtklein748ca3b2015-01-15 10:56:12 -0800425};
426
halcanary47ef4d52015-03-03 09:13:09 -0800427class XPSSink : public Sink {
428public:
429 XPSSink();
430
mtklein36352bf2015-03-25 18:17:31 -0700431 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700432 const char* fileExtension() const override { return "xps"; }
mtklein99cab4e2015-07-31 06:43:04 -0700433 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
halcanary47ef4d52015-03-03 09:13:09 -0800434};
435
mtklein748ca3b2015-01-15 10:56:12 -0800436class RasterSink : public Sink {
437public:
brianosmanb109b8c2016-06-16 13:03:24 -0700438 explicit RasterSink(SkColorType, sk_sp<SkColorSpace> = nullptr);
mtklein748ca3b2015-01-15 10:56:12 -0800439
mtklein36352bf2015-03-25 18:17:31 -0700440 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700441 const char* fileExtension() const override { return "png"; }
mtklein99cab4e2015-07-31 06:43:04 -0700442 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kRaster, SinkFlags::kDirect }; }
Yuqian Lib8b62532018-02-23 14:13:36 +0800443
Mike Klein48b64902018-07-25 13:28:44 -0400444private:
brianosmanb109b8c2016-06-16 13:03:24 -0700445 SkColorType fColorType;
446 sk_sp<SkColorSpace> fColorSpace;
mtklein748ca3b2015-01-15 10:56:12 -0800447};
448
Yuqian Lib8b62532018-02-23 14:13:36 +0800449class ThreadedSink : public RasterSink {
450public:
451 explicit ThreadedSink(SkColorType, sk_sp<SkColorSpace> = nullptr);
452 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
Yuqian Lib8b62532018-02-23 14:13:36 +0800453};
454
mtklein9c3f17d2015-01-28 11:35:18 -0800455class SKPSink : public Sink {
456public:
457 SKPSink();
458
mtklein36352bf2015-03-25 18:17:31 -0700459 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700460 const char* fileExtension() const override { return "skp"; }
mtklein99cab4e2015-07-31 06:43:04 -0700461 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
mtklein9c3f17d2015-01-28 11:35:18 -0800462};
463
Hal Canary85c7fe82016-10-25 10:33:27 -0400464class DebugSink : public Sink {
465public:
466 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
467 const char* fileExtension() const override { return "json"; }
468 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
469};
470
mtklein8a4527e2015-01-31 20:00:58 -0800471class SVGSink : public Sink {
472public:
Bryce Thomas95a7b762018-03-02 13:54:21 -0800473 SVGSink(int pageIndex = 0);
mtklein8a4527e2015-01-31 20:00:58 -0800474
mtklein36352bf2015-03-25 18:17:31 -0700475 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700476 const char* fileExtension() const override { return "svg"; }
mtklein99cab4e2015-07-31 06:43:04 -0700477 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
Bryce Thomas95a7b762018-03-02 13:54:21 -0800478
479private:
480 int fPageIndex;
mtklein8a4527e2015-01-31 20:00:58 -0800481};
482
483
mtklein748ca3b2015-01-15 10:56:12 -0800484/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
485
mtklein78829242015-05-06 07:54:07 -0700486class Via : public Sink {
487public:
msarett62d3b102015-12-10 15:14:27 -0800488 explicit Via(Sink* sink) : fSink(sink) {}
mtklein78829242015-05-06 07:54:07 -0700489 const char* fileExtension() const override { return fSink->fileExtension(); }
mtklein21eaf3b2016-02-08 12:39:59 -0800490 bool serial() const override { return fSink->serial(); }
mtklein99cab4e2015-07-31 06:43:04 -0700491 SinkFlags flags() const override {
492 SinkFlags flags = fSink->flags();
493 flags.approach = SinkFlags::kIndirect;
494 return flags;
495 }
mtklein78829242015-05-06 07:54:07 -0700496protected:
Ben Wagner145dbcd2016-11-03 14:40:50 -0400497 std::unique_ptr<Sink> fSink;
mtklein78829242015-05-06 07:54:07 -0700498};
499
500class ViaMatrix : public Via {
mtklein748ca3b2015-01-15 10:56:12 -0800501public:
msarett62d3b102015-12-10 15:14:27 -0800502 ViaMatrix(SkMatrix, Sink*);
mtklein36352bf2015-03-25 18:17:31 -0700503 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein748ca3b2015-01-15 10:56:12 -0800504private:
mtklein78829242015-05-06 07:54:07 -0700505 const SkMatrix fMatrix;
mtklein748ca3b2015-01-15 10:56:12 -0800506};
507
mtklein78829242015-05-06 07:54:07 -0700508class ViaUpright : public Via {
mtkleind603b222015-02-17 11:13:33 -0800509public:
msarett62d3b102015-12-10 15:14:27 -0800510 ViaUpright(SkMatrix, Sink*);
mtklein36352bf2015-03-25 18:17:31 -0700511 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtkleind603b222015-02-17 11:13:33 -0800512private:
mtklein78829242015-05-06 07:54:07 -0700513 const SkMatrix fMatrix;
mtkleind603b222015-02-17 11:13:33 -0800514};
515
mtklein78829242015-05-06 07:54:07 -0700516class ViaSerialization : public Via {
mtklein748ca3b2015-01-15 10:56:12 -0800517public:
msarett62d3b102015-12-10 15:14:27 -0800518 explicit ViaSerialization(Sink* sink) : Via(sink) {}
mtklein36352bf2015-03-25 18:17:31 -0700519 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein748ca3b2015-01-15 10:56:12 -0800520};
521
mtklein4a34ecb2016-01-08 10:19:35 -0800522class ViaPicture : public Via {
523public:
524 explicit ViaPicture(Sink* sink) : Via(sink) {}
525 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
526};
527
mtklein78829242015-05-06 07:54:07 -0700528class ViaTiles : public Via {
mtklein748ca3b2015-01-15 10:56:12 -0800529public:
msarett62d3b102015-12-10 15:14:27 -0800530 ViaTiles(int w, int h, SkBBHFactory*, Sink*);
mtklein36352bf2015-03-25 18:17:31 -0700531 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein748ca3b2015-01-15 10:56:12 -0800532private:
533 const int fW, fH;
Ben Wagner145dbcd2016-11-03 14:40:50 -0400534 std::unique_ptr<SkBBHFactory> fFactory;
mtklein748ca3b2015-01-15 10:56:12 -0800535};
536
Robert Phillips33f02ed2018-03-27 08:06:57 -0400537class ViaDDL : public Via {
538public:
Brian Salomon57904202018-12-17 14:45:00 -0500539 ViaDDL(int numReplays, int numDivisions, Sink* sink);
Robert Phillips33f02ed2018-03-27 08:06:57 -0400540 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
541private:
Brian Salomon57904202018-12-17 14:45:00 -0500542 const int fNumReplays;
Robert Phillips33f02ed2018-03-27 08:06:57 -0400543 const int fNumDivisions;
Robert Phillips33f02ed2018-03-27 08:06:57 -0400544};
545
Mike Reedf67c4592017-02-17 17:06:11 -0500546class ViaSVG : public Via {
547public:
548 explicit ViaSVG(Sink* sink) : Via(sink) {}
549 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
550};
551
mtklein748ca3b2015-01-15 10:56:12 -0800552} // namespace DM
553
554#endif//DMSrcSink_DEFINED