blob: 18e854bb0cce8a205c26a915b7cd5cc9368e810c [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"
Brian Salomonf865b052018-03-09 09:01:53 -050017#include "SkCommonFlagsConfig.h"
mtklein748ca3b2015-01-15 10:56:12 -080018#include "SkData.h"
Hal Canary45cde312017-04-03 16:06:42 -040019#include "SkMultiPictureDocument.h"
mtklein748ca3b2015-01-15 10:56:12 -080020#include "SkPicture.h"
mtklein748ca3b2015-01-15 10:56:12 -080021#include "gm.h"
22
Mike Reedbae888e2017-02-18 16:50:45 -050023//#define TEST_VIA_SVG
24
Florin Malita54f65c42018-01-16 17:04:30 -050025namespace skottie { class Animation; }
Florin Malitafc043dc2017-12-31 11:08:42 -050026
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:
106 explicit GMSrc(skiagm::GMRegistry::Factory);
107
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:
114 skiagm::GMRegistry::Factory fFactory;
115};
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:
218 enum Mode {
219 // Mimic legacy behavior and apply no color correction.
220 kBaseline_Mode,
msarett888dc162016-05-23 10:21:17 -0700221
222 // Color correct images into a specific dst color space. If you happen to have this
223 // monitor, you're in luck! The unmarked outputs of this test should display
224 // correctly on this monitor in the Chrome browser. If not, it's useful to know
225 // that this monitor has a profile that is fairly similar to Adobe RGB.
msarett888dc162016-05-23 10:21:17 -0700226 kDst_HPZR30w_Mode,
msarett9876ac52016-06-01 14:47:18 -0700227
msarettd2809572016-06-20 06:07:45 -0700228 kDst_sRGB_Mode,
msarett69deca82016-04-29 09:38:40 -0700229 };
230
msarett9ce3a542016-07-15 13:54:38 -0700231 ColorCodecSrc(Path, Mode, SkColorType);
msarett69deca82016-04-29 09:38:40 -0700232
233 Error draw(SkCanvas*) const override;
234 SkISize size() const override;
235 Name name() const override;
236 bool veto(SinkFlags) const override;
237private:
238 Path fPath;
239 Mode fMode;
msarett9ce3a542016-07-15 13:54:38 -0700240 SkColorType fColorType;
msarett69deca82016-04-29 09:38:40 -0700241};
242
mtklein748ca3b2015-01-15 10:56:12 -0800243class SKPSrc : public Src {
244public:
mtklein8d17a132015-01-30 11:42:31 -0800245 explicit SKPSrc(Path path);
mtklein748ca3b2015-01-15 10:56:12 -0800246
mtklein36352bf2015-03-25 18:17:31 -0700247 Error draw(SkCanvas*) const override;
248 SkISize size() const override;
249 Name name() const override;
mtklein748ca3b2015-01-15 10:56:12 -0800250private:
mtklein8d17a132015-01-30 11:42:31 -0800251 Path fPath;
mtklein748ca3b2015-01-15 10:56:12 -0800252};
253
Robert Phillipsad8a43f2017-08-30 12:06:35 -0400254// DeferredDisplayList flavor
255class DDLSKPSrc : public Src {
256public:
257 explicit DDLSKPSrc(Path path);
258
259 Error draw(SkCanvas*) const override;
260 SkISize size() const override;
261 Name name() const override;
262private:
263 Path fPath;
264};
265
Florin Malita124d5af2017-12-31 17:02:26 -0500266#if !defined(SK_BUILD_FOR_GOOGLE3)
Florin Malita54f65c42018-01-16 17:04:30 -0500267class SkottieSrc final : public Src {
Florin Malitafc043dc2017-12-31 11:08:42 -0500268public:
Florin Malita54f65c42018-01-16 17:04:30 -0500269 explicit SkottieSrc(Path path);
Florin Malitafc043dc2017-12-31 11:08:42 -0500270
271 Error draw(SkCanvas*) const override;
272 SkISize size() const override;
273 Name name() const override;
274 bool veto(SinkFlags) const override;
275
276private:
277 // Generates a kTileCount x kTileCount filmstrip with evenly distributed frames.
Florin Malita1022f742018-02-23 11:10:22 -0500278 static constexpr int kTileCount = 5;
Florin Malitafc043dc2017-12-31 11:08:42 -0500279
Florin Malita1022f742018-02-23 11:10:22 -0500280 Name fName;
281 SkISize fTileSize = SkISize::MakeEmpty();
282 sk_sp<skottie::Animation> fAnimation;
Florin Malitafc043dc2017-12-31 11:08:42 -0500283};
Florin Malita124d5af2017-12-31 17:02:26 -0500284#endif
Florin Malitafc043dc2017-12-31 11:08:42 -0500285
fmalitaa2b9fdf2016-08-03 19:53:36 -0700286#if defined(SK_XML)
fmalitabdf3e5c2016-09-17 07:26:26 -0700287} // namespace DM
288
289class SkSVGDOM;
290
291namespace DM {
292
fmalitaa2b9fdf2016-08-03 19:53:36 -0700293class SVGSrc : public Src {
294public:
295 explicit SVGSrc(Path path);
296
297 Error draw(SkCanvas*) const override;
298 SkISize size() const override;
299 Name name() const override;
fmalita179d8852016-08-16 14:23:29 -0700300 bool veto(SinkFlags) const override;
fmalitaa2b9fdf2016-08-03 19:53:36 -0700301
302private:
fmalitaacd2f5c2016-11-08 07:13:45 -0800303 Name fName;
304 sk_sp<SkSVGDOM> fDom;
305 SkScalar fScale;
fmalitaa2b9fdf2016-08-03 19:53:36 -0700306
307 typedef Src INHERITED;
308};
309#endif // SK_XML
mtklein748ca3b2015-01-15 10:56:12 -0800310/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
311
halcanary45420a92016-06-02 12:41:14 -0700312class MSKPSrc : public Src {
313public:
314 explicit MSKPSrc(Path path);
315
316 int pageCount() const override;
317 Error draw(SkCanvas* c) const override;
318 Error draw(int, SkCanvas*) const override;
319 SkISize size() const override;
320 SkISize size(int) const override;
321 Name name() const override;
322
323private:
324 Path fPath;
Hal Canary45cde312017-04-03 16:06:42 -0400325 mutable SkTArray<SkDocumentPage> fPages;
halcanary45420a92016-06-02 12:41:14 -0700326};
327
328/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
329
mtkleinad66f9b2015-02-13 15:11:10 -0800330class NullSink : public Sink {
331public:
332 NullSink() {}
333
mtklein36352bf2015-03-25 18:17:31 -0700334 Error draw(const Src& src, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700335 const char* fileExtension() const override { return ""; }
mtklein99cab4e2015-07-31 06:43:04 -0700336 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kNull, SinkFlags::kDirect }; }
mtkleinad66f9b2015-02-13 15:11:10 -0800337};
338
339
mtklein748ca3b2015-01-15 10:56:12 -0800340class GPUSink : public Sink {
341public:
bsalomon85b4b532016-04-05 11:06:27 -0700342 GPUSink(sk_gpu_test::GrContextFactory::ContextType,
Brian Salomonf865b052018-03-09 09:01:53 -0500343 sk_gpu_test::GrContextFactory::ContextOverrides,
344 SkCommandLineConfigGpu::SurfType surfType, int samples, bool diText,
Brian Salomonce5ee602017-07-17 11:31:31 -0400345 SkColorType colorType, SkAlphaType alphaType, sk_sp<SkColorSpace> colorSpace,
Brian Osmanf21aa042017-08-21 16:48:46 -0400346 bool threaded, const GrContextOptions& grCtxOptions);
mtklein748ca3b2015-01-15 10:56:12 -0800347
mtklein36352bf2015-03-25 18:17:31 -0700348 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
Brian Osmanf9810662017-08-30 10:02:10 -0400349 Error onDraw(const Src&, SkBitmap*, SkWStream*, SkString*,
350 const GrContextOptions& baseOptions) const;
351
mtklein21eaf3b2016-02-08 12:39:59 -0800352 bool serial() const override { return !fThreaded; }
mtklein36352bf2015-03-25 18:17:31 -0700353 const char* fileExtension() const override { return "png"; }
Brian Salomonbd7c5512017-03-07 09:08:36 -0500354 SinkFlags flags() const override {
Brian Salomonbdecacf2018-02-02 20:32:49 -0500355 SinkFlags::Multisampled ms = fSampleCount > 1 ? SinkFlags::kMultisampled
Brian Salomonfd171ed2017-03-08 11:38:45 -0500356 : SinkFlags::kNotMultisampled;
357 return SinkFlags{ SinkFlags::kGPU, SinkFlags::kDirect, ms };
Brian Salomonbd7c5512017-03-07 09:08:36 -0500358 }
Brian Osmanf9810662017-08-30 10:02:10 -0400359 const GrContextOptions& baseContextOptions() const { return fBaseContextOptions; }
360
mtklein748ca3b2015-01-15 10:56:12 -0800361private:
csmartdaltone812d492017-02-21 12:36:05 -0700362 sk_gpu_test::GrContextFactory::ContextType fContextType;
363 sk_gpu_test::GrContextFactory::ContextOverrides fContextOverrides;
Brian Salomonf865b052018-03-09 09:01:53 -0500364 SkCommandLineConfigGpu::SurfType fSurfType;
csmartdaltone812d492017-02-21 12:36:05 -0700365 int fSampleCount;
366 bool fUseDIText;
367 SkColorType fColorType;
Brian Salomonce5ee602017-07-17 11:31:31 -0400368 SkAlphaType fAlphaType;
csmartdaltone812d492017-02-21 12:36:05 -0700369 sk_sp<SkColorSpace> fColorSpace;
370 bool fThreaded;
Brian Osmanf21aa042017-08-21 16:48:46 -0400371 GrContextOptions fBaseContextOptions;
mtklein748ca3b2015-01-15 10:56:12 -0800372};
373
Brian Osmanf9810662017-08-30 10:02:10 -0400374class GPUThreadTestingSink : public GPUSink {
375public:
376 GPUThreadTestingSink(sk_gpu_test::GrContextFactory::ContextType,
Brian Salomonf865b052018-03-09 09:01:53 -0500377 sk_gpu_test::GrContextFactory::ContextOverrides,
378 SkCommandLineConfigGpu::SurfType surfType, int samples, bool diText,
Brian Osmanf9810662017-08-30 10:02:10 -0400379 SkColorType colorType, SkAlphaType alphaType,
380 sk_sp<SkColorSpace> colorSpace, bool threaded,
381 const GrContextOptions& grCtxOptions);
382
383 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
384
Brian Osmanf1942de2017-08-30 14:50:22 -0400385 const char* fileExtension() const override {
386 // Suppress writing out results from this config - we just want to do our matching test
387 return nullptr;
388 }
389
Brian Osmanf9810662017-08-30 10:02:10 -0400390private:
391 std::unique_ptr<SkExecutor> fExecutor;
392
393 typedef GPUSink INHERITED;
394};
395
mtklein748ca3b2015-01-15 10:56:12 -0800396class PDFSink : public Sink {
397public:
Hal Canaryc7d295e2017-07-20 15:36:00 -0400398 PDFSink(bool pdfa, SkScalar rasterDpi) : fPDFA(pdfa), fRasterDpi(rasterDpi) {}
mtklein36352bf2015-03-25 18:17:31 -0700399 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700400 const char* fileExtension() const override { return "pdf"; }
mtklein99cab4e2015-07-31 06:43:04 -0700401 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
halcanary4b656662016-04-27 07:45:18 -0700402 bool fPDFA;
Hal Canaryc7d295e2017-07-20 15:36:00 -0400403 SkScalar fRasterDpi;
mtklein748ca3b2015-01-15 10:56:12 -0800404};
405
halcanary47ef4d52015-03-03 09:13:09 -0800406class XPSSink : public Sink {
407public:
408 XPSSink();
409
mtklein36352bf2015-03-25 18:17:31 -0700410 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700411 const char* fileExtension() const override { return "xps"; }
mtklein99cab4e2015-07-31 06:43:04 -0700412 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
halcanary47ef4d52015-03-03 09:13:09 -0800413};
414
reed54dc4872016-09-13 08:09:45 -0700415class PipeSink : public Sink {
416public:
417 PipeSink();
Mike Klein841101d2017-03-10 09:55:51 -0500418
reed54dc4872016-09-13 08:09:45 -0700419 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
420 const char* fileExtension() const override { return "skpipe"; }
421 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
422};
423
mtklein748ca3b2015-01-15 10:56:12 -0800424class RasterSink : public Sink {
425public:
brianosmanb109b8c2016-06-16 13:03:24 -0700426 explicit RasterSink(SkColorType, sk_sp<SkColorSpace> = nullptr);
mtklein748ca3b2015-01-15 10:56:12 -0800427
mtklein36352bf2015-03-25 18:17:31 -0700428 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700429 const char* fileExtension() const override { return "png"; }
mtklein99cab4e2015-07-31 06:43:04 -0700430 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kRaster, SinkFlags::kDirect }; }
Yuqian Lib8b62532018-02-23 14:13:36 +0800431protected:
432 void allocPixels(const Src& src, SkBitmap*) const;
433
brianosmanb109b8c2016-06-16 13:03:24 -0700434 SkColorType fColorType;
435 sk_sp<SkColorSpace> fColorSpace;
mtklein748ca3b2015-01-15 10:56:12 -0800436};
437
Yuqian Lib8b62532018-02-23 14:13:36 +0800438class ThreadedSink : public RasterSink {
439public:
440 explicit ThreadedSink(SkColorType, sk_sp<SkColorSpace> = nullptr);
441 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
442
443private:
444 std::unique_ptr<SkExecutor> fExecutor;
445};
446
mtklein9c3f17d2015-01-28 11:35:18 -0800447class SKPSink : public Sink {
448public:
449 SKPSink();
450
mtklein36352bf2015-03-25 18:17:31 -0700451 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700452 const char* fileExtension() const override { return "skp"; }
mtklein99cab4e2015-07-31 06:43:04 -0700453 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
mtklein9c3f17d2015-01-28 11:35:18 -0800454};
455
Hal Canary85c7fe82016-10-25 10:33:27 -0400456class DebugSink : public Sink {
457public:
458 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
459 const char* fileExtension() const override { return "json"; }
460 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
461};
462
mtklein8a4527e2015-01-31 20:00:58 -0800463class SVGSink : public Sink {
464public:
Bryce Thomas95a7b762018-03-02 13:54:21 -0800465 SVGSink(int pageIndex = 0);
mtklein8a4527e2015-01-31 20:00:58 -0800466
mtklein36352bf2015-03-25 18:17:31 -0700467 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700468 const char* fileExtension() const override { return "svg"; }
mtklein99cab4e2015-07-31 06:43:04 -0700469 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
Bryce Thomas95a7b762018-03-02 13:54:21 -0800470
471private:
472 int fPageIndex;
mtklein8a4527e2015-01-31 20:00:58 -0800473};
474
475
mtklein748ca3b2015-01-15 10:56:12 -0800476/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
477
mtklein78829242015-05-06 07:54:07 -0700478class Via : public Sink {
479public:
msarett62d3b102015-12-10 15:14:27 -0800480 explicit Via(Sink* sink) : fSink(sink) {}
mtklein78829242015-05-06 07:54:07 -0700481 const char* fileExtension() const override { return fSink->fileExtension(); }
mtklein21eaf3b2016-02-08 12:39:59 -0800482 bool serial() const override { return fSink->serial(); }
mtklein99cab4e2015-07-31 06:43:04 -0700483 SinkFlags flags() const override {
484 SinkFlags flags = fSink->flags();
485 flags.approach = SinkFlags::kIndirect;
486 return flags;
487 }
mtklein78829242015-05-06 07:54:07 -0700488protected:
Ben Wagner145dbcd2016-11-03 14:40:50 -0400489 std::unique_ptr<Sink> fSink;
mtklein78829242015-05-06 07:54:07 -0700490};
491
492class ViaMatrix : public Via {
mtklein748ca3b2015-01-15 10:56:12 -0800493public:
msarett62d3b102015-12-10 15:14:27 -0800494 ViaMatrix(SkMatrix, Sink*);
mtklein36352bf2015-03-25 18:17:31 -0700495 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein748ca3b2015-01-15 10:56:12 -0800496private:
mtklein78829242015-05-06 07:54:07 -0700497 const SkMatrix fMatrix;
mtklein748ca3b2015-01-15 10:56:12 -0800498};
499
mtklein78829242015-05-06 07:54:07 -0700500class ViaUpright : public Via {
mtkleind603b222015-02-17 11:13:33 -0800501public:
msarett62d3b102015-12-10 15:14:27 -0800502 ViaUpright(SkMatrix, Sink*);
mtklein36352bf2015-03-25 18:17:31 -0700503 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtkleind603b222015-02-17 11:13:33 -0800504private:
mtklein78829242015-05-06 07:54:07 -0700505 const SkMatrix fMatrix;
mtkleind603b222015-02-17 11:13:33 -0800506};
507
mtklein78829242015-05-06 07:54:07 -0700508class ViaSerialization : public Via {
mtklein748ca3b2015-01-15 10:56:12 -0800509public:
msarett62d3b102015-12-10 15:14:27 -0800510 explicit ViaSerialization(Sink* sink) : Via(sink) {}
mtklein36352bf2015-03-25 18:17:31 -0700511 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein748ca3b2015-01-15 10:56:12 -0800512};
513
mtklein4a34ecb2016-01-08 10:19:35 -0800514class ViaPicture : public Via {
515public:
516 explicit ViaPicture(Sink* sink) : Via(sink) {}
517 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
518};
519
reed54dc4872016-09-13 08:09:45 -0700520class ViaPipe : public Via {
521public:
522 explicit ViaPipe(Sink* sink) : Via(sink) {}
523 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
524};
525
mtklein78829242015-05-06 07:54:07 -0700526class ViaTiles : public Via {
mtklein748ca3b2015-01-15 10:56:12 -0800527public:
msarett62d3b102015-12-10 15:14:27 -0800528 ViaTiles(int w, int h, SkBBHFactory*, Sink*);
mtklein36352bf2015-03-25 18:17:31 -0700529 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein748ca3b2015-01-15 10:56:12 -0800530private:
531 const int fW, fH;
Ben Wagner145dbcd2016-11-03 14:40:50 -0400532 std::unique_ptr<SkBBHFactory> fFactory;
mtklein748ca3b2015-01-15 10:56:12 -0800533};
534
Mike Reedf67c4592017-02-17 17:06:11 -0500535class ViaSVG : public Via {
536public:
537 explicit ViaSVG(Sink* sink) : Via(sink) {}
538 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
539};
540
mtklein9c5052f2016-08-06 12:51:51 -0700541class ViaLite : public Via {
542public:
543 explicit ViaLite(Sink* sink) : Via(sink) {}
544 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
545};
546
Mike Klein841101d2017-03-10 09:55:51 -0500547class ViaCSXform : public Via {
548public:
Mike Klein919cc452017-03-18 15:36:52 +0000549 explicit ViaCSXform(Sink*, sk_sp<SkColorSpace>, bool colorSpin);
Mike Klein841101d2017-03-10 09:55:51 -0500550 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
551private:
552 sk_sp<SkColorSpace> fCS;
Mike Klein919cc452017-03-18 15:36:52 +0000553 bool fColorSpin;
Mike Klein841101d2017-03-10 09:55:51 -0500554};
555
mtklein748ca3b2015-01-15 10:56:12 -0800556} // namespace DM
557
558#endif//DMSrcSink_DEFINED