blob: 157a484d2b781d6e19c8bfa3d2136dd877ef0ee6 [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
Florin Malita54f65c42018-01-16 17:04:30 -050024namespace skottie { class Animation; }
Florin Malitafc043dc2017-12-31 11:08:42 -050025
mtklein748ca3b2015-01-15 10:56:12 -080026namespace DM {
27
28// This is just convenience. It lets you use either return "foo" or return SkStringPrintf(...).
29struct ImplicitString : public SkString {
30 template <typename T>
31 ImplicitString(const T& s) : SkString(s) {}
msarett9e707a02015-09-01 14:57:57 -070032 ImplicitString() : SkString("") {}
mtklein748ca3b2015-01-15 10:56:12 -080033};
mtklein748ca3b2015-01-15 10:56:12 -080034typedef ImplicitString Name;
mtklein8d17a132015-01-30 11:42:31 -080035typedef ImplicitString Path;
mtklein748ca3b2015-01-15 10:56:12 -080036
mtklein4089ef72015-03-05 08:40:28 -080037class Error {
38public:
39 Error(const SkString& s) : fMsg(s), fFatal(!this->isEmpty()) {}
40 Error(const char* s) : fMsg(s), fFatal(!this->isEmpty()) {}
41
42 Error(const Error&) = default;
43 Error& operator=(const Error&) = default;
44
45 static Error Nonfatal(const SkString& s) { return Nonfatal(s.c_str()); }
46 static Error Nonfatal(const char* s) {
47 Error e(s);
48 e.fFatal = false;
49 return e;
50 }
51
52 const char* c_str() const { return fMsg.c_str(); }
53 bool isEmpty() const { return fMsg.isEmpty(); }
54 bool isFatal() const { return fFatal; }
55
56private:
57 SkString fMsg;
58 bool fFatal;
59};
60
mtklein99cab4e2015-07-31 06:43:04 -070061struct SinkFlags {
Brian Salomonbd7c5512017-03-07 09:08:36 -050062 enum Type { kNull, kGPU, kVector, kRaster } type;
63 enum Approach { kDirect, kIndirect } approach;
64 enum Multisampled { kNotMultisampled, kMultisampled } multisampled;
65 SinkFlags(Type t, Approach a, Multisampled ms = kNotMultisampled)
66 : type(t), approach(a), multisampled(ms) {}
mtklein99cab4e2015-07-31 06:43:04 -070067};
mtkleine0effd62015-07-29 06:37:28 -070068
mtklein748ca3b2015-01-15 10:56:12 -080069struct Src {
mtklein748ca3b2015-01-15 10:56:12 -080070 virtual ~Src() {}
71 virtual Error SK_WARN_UNUSED_RESULT draw(SkCanvas*) const = 0;
72 virtual SkISize size() const = 0;
73 virtual Name name() const = 0;
bsalomon4ee6bd82015-05-27 13:23:23 -070074 virtual void modifyGrContextOptions(GrContextOptions* options) const {}
mtklein99cab4e2015-07-31 06:43:04 -070075 virtual bool veto(SinkFlags) const { return false; }
mtklein21eaf3b2016-02-08 12:39:59 -080076
halcanary45420a92016-06-02 12:41:14 -070077 virtual int pageCount() const { return 1; }
78 virtual Error SK_WARN_UNUSED_RESULT draw(int, SkCanvas* canvas) const {
79 return this->draw(canvas);
80 }
81 virtual SkISize size(int) const { return this->size(); }
mtklein21eaf3b2016-02-08 12:39:59 -080082 // Force Tasks using this Src to run on the main thread?
83 virtual bool serial() const { return false; }
mtklein748ca3b2015-01-15 10:56:12 -080084};
85
86struct Sink {
87 virtual ~Sink() {}
mtkleinb9eb4ac2015-02-02 18:26:03 -080088 // You may write to either the bitmap or stream. If you write to log, we'll print that out.
89 virtual Error SK_WARN_UNUSED_RESULT draw(const Src&, SkBitmap*, SkWStream*, SkString* log)
90 const = 0;
mtklein21eaf3b2016-02-08 12:39:59 -080091
92 // Force Tasks using this Sink to run on the main thread?
93 virtual bool serial() const { return false; }
mtklein748ca3b2015-01-15 10:56:12 -080094
95 // File extension for the content draw() outputs, e.g. "png", "pdf".
96 virtual const char* fileExtension() const = 0;
mtklein99cab4e2015-07-31 06:43:04 -070097
98 virtual SinkFlags flags() const = 0;
mtklein748ca3b2015-01-15 10:56:12 -080099};
100
mtklein748ca3b2015-01-15 10:56:12 -0800101/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
102
mtklein748ca3b2015-01-15 10:56:12 -0800103class GMSrc : public Src {
104public:
105 explicit GMSrc(skiagm::GMRegistry::Factory);
106
mtklein36352bf2015-03-25 18:17:31 -0700107 Error draw(SkCanvas*) const override;
108 SkISize size() const override;
109 Name name() const override;
bsalomon4ee6bd82015-05-27 13:23:23 -0700110 void modifyGrContextOptions(GrContextOptions* options) const override;
111
mtklein748ca3b2015-01-15 10:56:12 -0800112private:
113 skiagm::GMRegistry::Factory fFactory;
114};
115
scroggo9b77ddd2015-03-19 06:03:39 -0700116class CodecSrc : public Src {
117public:
scroggo9c59ebc2015-03-25 13:48:49 -0700118 enum Mode {
msarett9e707a02015-09-01 14:57:57 -0700119 kCodec_Mode,
msarettbb25b532016-01-13 09:31:39 -0800120 // We choose to test only one mode with zero initialized memory.
121 // This will exercise all of the interesting cases in SkSwizzler
122 // without doubling the size of our test suite.
123 kCodecZeroInit_Mode,
scroggo9c59ebc2015-03-25 13:48:49 -0700124 kScanline_Mode,
msarett0a242972015-06-11 14:27:27 -0700125 kStripe_Mode, // Tests the skipping of scanlines
msarett91c22b22016-02-22 12:27:46 -0800126 kCroppedScanline_Mode, // Tests (jpeg) cropped scanline optimization
scroggob636b452015-07-22 07:16:20 -0700127 kSubset_Mode, // For codecs that support subsets directly.
scroggo19b91532016-10-24 09:03:26 -0700128 kAnimated_Mode, // For codecs that support animation.
scroggo9c59ebc2015-03-25 13:48:49 -0700129 };
msarett438b2ad2015-04-09 12:43:10 -0700130 enum DstColorType {
131 kGetFromCanvas_DstColorType,
msarett438b2ad2015-04-09 12:43:10 -0700132 kGrayscale_Always_DstColorType,
msarett34e0ec42016-04-22 16:27:24 -0700133 kNonNative8888_Always_DstColorType,
msarett438b2ad2015-04-09 12:43:10 -0700134 };
scroggoc5560be2016-02-03 09:42:42 -0800135 CodecSrc(Path, Mode, DstColorType, SkAlphaType, float);
scroggo9b77ddd2015-03-19 06:03:39 -0700136
mtklein36352bf2015-03-25 18:17:31 -0700137 Error draw(SkCanvas*) const override;
138 SkISize size() const override;
139 Name name() const override;
mtklein99cab4e2015-07-31 06:43:04 -0700140 bool veto(SinkFlags) const override;
scroggo3ac66e92016-02-08 15:09:48 -0800141 bool serial() const override { return fRunSerially; }
scroggo9b77ddd2015-03-19 06:03:39 -0700142private:
msarett9e707a02015-09-01 14:57:57 -0700143 Path fPath;
144 Mode fMode;
145 DstColorType fDstColorType;
scroggoc5560be2016-02-03 09:42:42 -0800146 SkAlphaType fDstAlphaType;
msarett9e707a02015-09-01 14:57:57 -0700147 float fScale;
scroggo3ac66e92016-02-08 15:09:48 -0800148 bool fRunSerially;
scroggo9b77ddd2015-03-19 06:03:39 -0700149};
150
msarett3d9d7a72015-10-21 10:27:10 -0700151class AndroidCodecSrc : public Src {
152public:
scroggof8dc9df2016-05-16 09:04:13 -0700153 AndroidCodecSrc(Path, CodecSrc::DstColorType, SkAlphaType, int sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700154
155 Error draw(SkCanvas*) const override;
156 SkISize size() const override;
157 Name name() const override;
158 bool veto(SinkFlags) const override;
scroggo3ac66e92016-02-08 15:09:48 -0800159 bool serial() const override { return fRunSerially; }
msarett3d9d7a72015-10-21 10:27:10 -0700160private:
161 Path fPath;
msarett3d9d7a72015-10-21 10:27:10 -0700162 CodecSrc::DstColorType fDstColorType;
scroggoc5560be2016-02-03 09:42:42 -0800163 SkAlphaType fDstAlphaType;
msarett3d9d7a72015-10-21 10:27:10 -0700164 int fSampleSize;
scroggo3ac66e92016-02-08 15:09:48 -0800165 bool fRunSerially;
msarett3d9d7a72015-10-21 10:27:10 -0700166};
167
msaretta5783ae2015-09-08 15:35:32 -0700168// Allows for testing of various implementations of Android's BitmapRegionDecoder
169class BRDSrc : public Src {
170public:
171 enum Mode {
172 // Decode the entire image as one region.
173 kFullImage_Mode,
174 // Splits the image into multiple regions using a divisor and decodes the regions
175 // separately. Also, this test adds a border of a few pixels to each of the regions
176 // that it is decoding. This tests the behavior when a client asks for a region that
177 // does not fully fit in the image.
178 kDivisor_Mode,
179 };
180
msarettd1227a72016-05-18 06:23:57 -0700181 BRDSrc(Path, Mode, CodecSrc::DstColorType, uint32_t);
msaretta5783ae2015-09-08 15:35:32 -0700182
msaretta5783ae2015-09-08 15:35:32 -0700183 Error draw(SkCanvas*) const override;
184 SkISize size() const override;
185 Name name() const override;
186 bool veto(SinkFlags) const override;
187private:
188 Path fPath;
msaretta5783ae2015-09-08 15:35:32 -0700189 Mode fMode;
190 CodecSrc::DstColorType fDstColorType;
191 uint32_t fSampleSize;
192};
scroggo9b77ddd2015-03-19 06:03:39 -0700193
msarett18976312016-03-09 14:20:58 -0800194class ImageGenSrc : public Src {
195public:
196 enum Mode {
197 kCodec_Mode, // Use CodecImageGenerator
198 kPlatform_Mode, // Uses CG or WIC
199 };
200 ImageGenSrc(Path, Mode, SkAlphaType, bool);
201
202 Error draw(SkCanvas*) const override;
203 SkISize size() const override;
204 Name name() const override;
205 bool veto(SinkFlags) const override;
206 bool serial() const override { return fRunSerially; }
207private:
208 Path fPath;
209 Mode fMode;
210 SkAlphaType fDstAlphaType;
211 bool fIsGpu;
212 bool fRunSerially;
213};
214
msarett69deca82016-04-29 09:38:40 -0700215class ColorCodecSrc : public Src {
216public:
217 enum Mode {
218 // Mimic legacy behavior and apply no color correction.
219 kBaseline_Mode,
msarett888dc162016-05-23 10:21:17 -0700220
221 // Color correct images into a specific dst color space. If you happen to have this
222 // monitor, you're in luck! The unmarked outputs of this test should display
223 // correctly on this monitor in the Chrome browser. If not, it's useful to know
224 // that this monitor has a profile that is fairly similar to Adobe RGB.
msarett888dc162016-05-23 10:21:17 -0700225 kDst_HPZR30w_Mode,
msarett9876ac52016-06-01 14:47:18 -0700226
msarettd2809572016-06-20 06:07:45 -0700227 kDst_sRGB_Mode,
msarett69deca82016-04-29 09:38:40 -0700228 };
229
msarett9ce3a542016-07-15 13:54:38 -0700230 ColorCodecSrc(Path, Mode, SkColorType);
msarett69deca82016-04-29 09:38:40 -0700231
232 Error draw(SkCanvas*) const override;
233 SkISize size() const override;
234 Name name() const override;
235 bool veto(SinkFlags) const override;
236private:
237 Path fPath;
238 Mode fMode;
msarett9ce3a542016-07-15 13:54:38 -0700239 SkColorType fColorType;
msarett69deca82016-04-29 09:38:40 -0700240};
241
mtklein748ca3b2015-01-15 10:56:12 -0800242class SKPSrc : public Src {
243public:
mtklein8d17a132015-01-30 11:42:31 -0800244 explicit SKPSrc(Path path);
mtklein748ca3b2015-01-15 10:56:12 -0800245
mtklein36352bf2015-03-25 18:17:31 -0700246 Error draw(SkCanvas*) const override;
247 SkISize size() const override;
248 Name name() const override;
mtklein748ca3b2015-01-15 10:56:12 -0800249private:
mtklein8d17a132015-01-30 11:42:31 -0800250 Path fPath;
mtklein748ca3b2015-01-15 10:56:12 -0800251};
252
Robert Phillipsad8a43f2017-08-30 12:06:35 -0400253// DeferredDisplayList flavor
254class DDLSKPSrc : public Src {
255public:
256 explicit DDLSKPSrc(Path path);
257
258 Error draw(SkCanvas*) const override;
259 SkISize size() const override;
260 Name name() const override;
261private:
262 Path fPath;
263};
264
Florin Malita124d5af2017-12-31 17:02:26 -0500265#if !defined(SK_BUILD_FOR_GOOGLE3)
Florin Malita54f65c42018-01-16 17:04:30 -0500266class SkottieSrc final : public Src {
Florin Malitafc043dc2017-12-31 11:08:42 -0500267public:
Florin Malita54f65c42018-01-16 17:04:30 -0500268 explicit SkottieSrc(Path path);
Florin Malitafc043dc2017-12-31 11:08:42 -0500269
270 Error draw(SkCanvas*) const override;
271 SkISize size() const override;
272 Name name() const override;
273 bool veto(SinkFlags) const override;
274
275private:
276 // Generates a kTileCount x kTileCount filmstrip with evenly distributed frames.
277 static constexpr int kTileCount = 5;
278
279 Name fName;
280 SkISize fTileSize = SkISize::MakeEmpty();
Florin Malita54f65c42018-01-16 17:04:30 -0500281 std::unique_ptr<skottie::Animation> fAnimation;
Florin Malitafc043dc2017-12-31 11:08:42 -0500282};
Florin Malita124d5af2017-12-31 17:02:26 -0500283#endif
Florin Malitafc043dc2017-12-31 11:08:42 -0500284
fmalitaa2b9fdf2016-08-03 19:53:36 -0700285#if defined(SK_XML)
fmalitabdf3e5c2016-09-17 07:26:26 -0700286} // namespace DM
287
288class SkSVGDOM;
289
290namespace DM {
291
fmalitaa2b9fdf2016-08-03 19:53:36 -0700292class SVGSrc : public Src {
293public:
294 explicit SVGSrc(Path path);
295
296 Error draw(SkCanvas*) const override;
297 SkISize size() const override;
298 Name name() const override;
fmalita179d8852016-08-16 14:23:29 -0700299 bool veto(SinkFlags) const override;
fmalitaa2b9fdf2016-08-03 19:53:36 -0700300
301private:
fmalitaacd2f5c2016-11-08 07:13:45 -0800302 Name fName;
303 sk_sp<SkSVGDOM> fDom;
304 SkScalar fScale;
fmalitaa2b9fdf2016-08-03 19:53:36 -0700305
306 typedef Src INHERITED;
307};
308#endif // SK_XML
mtklein748ca3b2015-01-15 10:56:12 -0800309/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
310
halcanary45420a92016-06-02 12:41:14 -0700311class MSKPSrc : public Src {
312public:
313 explicit MSKPSrc(Path path);
314
315 int pageCount() const override;
316 Error draw(SkCanvas* c) const override;
317 Error draw(int, SkCanvas*) const override;
318 SkISize size() const override;
319 SkISize size(int) const override;
320 Name name() const override;
321
322private:
323 Path fPath;
Hal Canary45cde312017-04-03 16:06:42 -0400324 mutable SkTArray<SkDocumentPage> fPages;
halcanary45420a92016-06-02 12:41:14 -0700325};
326
327/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
328
mtkleinad66f9b2015-02-13 15:11:10 -0800329class NullSink : public Sink {
330public:
331 NullSink() {}
332
mtklein36352bf2015-03-25 18:17:31 -0700333 Error draw(const Src& src, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700334 const char* fileExtension() const override { return ""; }
mtklein99cab4e2015-07-31 06:43:04 -0700335 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kNull, SinkFlags::kDirect }; }
mtkleinad66f9b2015-02-13 15:11:10 -0800336};
337
338
mtklein748ca3b2015-01-15 10:56:12 -0800339class GPUSink : public Sink {
340public:
bsalomon85b4b532016-04-05 11:06:27 -0700341 GPUSink(sk_gpu_test::GrContextFactory::ContextType,
Brian Salomonce5ee602017-07-17 11:31:31 -0400342 sk_gpu_test::GrContextFactory::ContextOverrides, int samples, bool diText,
343 SkColorType colorType, SkAlphaType alphaType, sk_sp<SkColorSpace> colorSpace,
Brian Osmanf21aa042017-08-21 16:48:46 -0400344 bool threaded, const GrContextOptions& grCtxOptions);
mtklein748ca3b2015-01-15 10:56:12 -0800345
mtklein36352bf2015-03-25 18:17:31 -0700346 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
Brian Osmanf9810662017-08-30 10:02:10 -0400347 Error onDraw(const Src&, SkBitmap*, SkWStream*, SkString*,
348 const GrContextOptions& baseOptions) const;
349
mtklein21eaf3b2016-02-08 12:39:59 -0800350 bool serial() const override { return !fThreaded; }
mtklein36352bf2015-03-25 18:17:31 -0700351 const char* fileExtension() const override { return "png"; }
Brian Salomonbd7c5512017-03-07 09:08:36 -0500352 SinkFlags flags() const override {
Brian Salomond0d72702018-02-01 14:16:02 -0500353 SinkFlags::Multisampled ms = fSampleCount > 1 ? SinkFlags::kMultisampled
Brian Salomonfd171ed2017-03-08 11:38:45 -0500354 : SinkFlags::kNotMultisampled;
355 return SinkFlags{ SinkFlags::kGPU, SinkFlags::kDirect, ms };
Brian Salomonbd7c5512017-03-07 09:08:36 -0500356 }
Brian Osmanf9810662017-08-30 10:02:10 -0400357 const GrContextOptions& baseContextOptions() const { return fBaseContextOptions; }
358
mtklein748ca3b2015-01-15 10:56:12 -0800359private:
csmartdaltone812d492017-02-21 12:36:05 -0700360 sk_gpu_test::GrContextFactory::ContextType fContextType;
361 sk_gpu_test::GrContextFactory::ContextOverrides fContextOverrides;
362 int fSampleCount;
363 bool fUseDIText;
364 SkColorType fColorType;
Brian Salomonce5ee602017-07-17 11:31:31 -0400365 SkAlphaType fAlphaType;
csmartdaltone812d492017-02-21 12:36:05 -0700366 sk_sp<SkColorSpace> fColorSpace;
367 bool fThreaded;
Brian Osmanf21aa042017-08-21 16:48:46 -0400368 GrContextOptions fBaseContextOptions;
mtklein748ca3b2015-01-15 10:56:12 -0800369};
370
Brian Osmanf9810662017-08-30 10:02:10 -0400371class GPUThreadTestingSink : public GPUSink {
372public:
373 GPUThreadTestingSink(sk_gpu_test::GrContextFactory::ContextType,
374 sk_gpu_test::GrContextFactory::ContextOverrides, int samples, bool diText,
375 SkColorType colorType, SkAlphaType alphaType,
376 sk_sp<SkColorSpace> colorSpace, bool threaded,
377 const GrContextOptions& grCtxOptions);
378
379 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
380
Brian Osmanf1942de2017-08-30 14:50:22 -0400381 const char* fileExtension() const override {
382 // Suppress writing out results from this config - we just want to do our matching test
383 return nullptr;
384 }
385
Brian Osmanf9810662017-08-30 10:02:10 -0400386private:
387 std::unique_ptr<SkExecutor> fExecutor;
388
389 typedef GPUSink INHERITED;
390};
391
mtklein748ca3b2015-01-15 10:56:12 -0800392class PDFSink : public Sink {
393public:
Hal Canaryc7d295e2017-07-20 15:36:00 -0400394 PDFSink(bool pdfa, SkScalar rasterDpi) : fPDFA(pdfa), fRasterDpi(rasterDpi) {}
mtklein36352bf2015-03-25 18:17:31 -0700395 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700396 const char* fileExtension() const override { return "pdf"; }
mtklein99cab4e2015-07-31 06:43:04 -0700397 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
halcanary4b656662016-04-27 07:45:18 -0700398 bool fPDFA;
Hal Canaryc7d295e2017-07-20 15:36:00 -0400399 SkScalar fRasterDpi;
mtklein748ca3b2015-01-15 10:56:12 -0800400};
401
halcanary47ef4d52015-03-03 09:13:09 -0800402class XPSSink : public Sink {
403public:
404 XPSSink();
405
mtklein36352bf2015-03-25 18:17:31 -0700406 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700407 const char* fileExtension() const override { return "xps"; }
mtklein99cab4e2015-07-31 06:43:04 -0700408 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
halcanary47ef4d52015-03-03 09:13:09 -0800409};
410
reed54dc4872016-09-13 08:09:45 -0700411class PipeSink : public Sink {
412public:
413 PipeSink();
Mike Klein841101d2017-03-10 09:55:51 -0500414
reed54dc4872016-09-13 08:09:45 -0700415 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
416 const char* fileExtension() const override { return "skpipe"; }
417 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
418};
419
mtklein748ca3b2015-01-15 10:56:12 -0800420class RasterSink : public Sink {
421public:
brianosmanb109b8c2016-06-16 13:03:24 -0700422 explicit RasterSink(SkColorType, sk_sp<SkColorSpace> = nullptr);
mtklein748ca3b2015-01-15 10:56:12 -0800423
mtklein36352bf2015-03-25 18:17:31 -0700424 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700425 const char* fileExtension() const override { return "png"; }
mtklein99cab4e2015-07-31 06:43:04 -0700426 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kRaster, SinkFlags::kDirect }; }
mtklein748ca3b2015-01-15 10:56:12 -0800427private:
brianosmanb109b8c2016-06-16 13:03:24 -0700428 SkColorType fColorType;
429 sk_sp<SkColorSpace> fColorSpace;
mtklein748ca3b2015-01-15 10:56:12 -0800430};
431
mtklein9c3f17d2015-01-28 11:35:18 -0800432class SKPSink : public Sink {
433public:
434 SKPSink();
435
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 "skp"; }
mtklein99cab4e2015-07-31 06:43:04 -0700438 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
mtklein9c3f17d2015-01-28 11:35:18 -0800439};
440
Hal Canary85c7fe82016-10-25 10:33:27 -0400441class DebugSink : public Sink {
442public:
443 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
444 const char* fileExtension() const override { return "json"; }
445 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
446};
447
mtklein8a4527e2015-01-31 20:00:58 -0800448class SVGSink : public Sink {
449public:
450 SVGSink();
451
mtklein36352bf2015-03-25 18:17:31 -0700452 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700453 const char* fileExtension() const override { return "svg"; }
mtklein99cab4e2015-07-31 06:43:04 -0700454 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
mtklein8a4527e2015-01-31 20:00:58 -0800455};
456
457
mtklein748ca3b2015-01-15 10:56:12 -0800458/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
459
mtklein78829242015-05-06 07:54:07 -0700460class Via : public Sink {
461public:
msarett62d3b102015-12-10 15:14:27 -0800462 explicit Via(Sink* sink) : fSink(sink) {}
mtklein78829242015-05-06 07:54:07 -0700463 const char* fileExtension() const override { return fSink->fileExtension(); }
mtklein21eaf3b2016-02-08 12:39:59 -0800464 bool serial() const override { return fSink->serial(); }
mtklein99cab4e2015-07-31 06:43:04 -0700465 SinkFlags flags() const override {
466 SinkFlags flags = fSink->flags();
467 flags.approach = SinkFlags::kIndirect;
468 return flags;
469 }
mtklein78829242015-05-06 07:54:07 -0700470protected:
Ben Wagner145dbcd2016-11-03 14:40:50 -0400471 std::unique_ptr<Sink> fSink;
mtklein78829242015-05-06 07:54:07 -0700472};
473
474class ViaMatrix : public Via {
mtklein748ca3b2015-01-15 10:56:12 -0800475public:
msarett62d3b102015-12-10 15:14:27 -0800476 ViaMatrix(SkMatrix, Sink*);
mtklein36352bf2015-03-25 18:17:31 -0700477 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein748ca3b2015-01-15 10:56:12 -0800478private:
mtklein78829242015-05-06 07:54:07 -0700479 const SkMatrix fMatrix;
mtklein748ca3b2015-01-15 10:56:12 -0800480};
481
mtklein78829242015-05-06 07:54:07 -0700482class ViaUpright : public Via {
mtkleind603b222015-02-17 11:13:33 -0800483public:
msarett62d3b102015-12-10 15:14:27 -0800484 ViaUpright(SkMatrix, Sink*);
mtklein36352bf2015-03-25 18:17:31 -0700485 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtkleind603b222015-02-17 11:13:33 -0800486private:
mtklein78829242015-05-06 07:54:07 -0700487 const SkMatrix fMatrix;
mtkleind603b222015-02-17 11:13:33 -0800488};
489
mtklein78829242015-05-06 07:54:07 -0700490class ViaSerialization : public Via {
mtklein748ca3b2015-01-15 10:56:12 -0800491public:
msarett62d3b102015-12-10 15:14:27 -0800492 explicit ViaSerialization(Sink* sink) : Via(sink) {}
mtklein36352bf2015-03-25 18:17:31 -0700493 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein748ca3b2015-01-15 10:56:12 -0800494};
495
mtklein4a34ecb2016-01-08 10:19:35 -0800496class ViaPicture : public Via {
497public:
498 explicit ViaPicture(Sink* sink) : Via(sink) {}
499 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
500};
501
reed54dc4872016-09-13 08:09:45 -0700502class ViaPipe : public Via {
503public:
504 explicit ViaPipe(Sink* sink) : Via(sink) {}
505 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
506};
507
mtklein78829242015-05-06 07:54:07 -0700508class ViaTiles : public Via {
mtklein748ca3b2015-01-15 10:56:12 -0800509public:
msarett62d3b102015-12-10 15:14:27 -0800510 ViaTiles(int w, int h, SkBBHFactory*, Sink*);
mtklein36352bf2015-03-25 18:17:31 -0700511 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein748ca3b2015-01-15 10:56:12 -0800512private:
513 const int fW, fH;
Ben Wagner145dbcd2016-11-03 14:40:50 -0400514 std::unique_ptr<SkBBHFactory> fFactory;
mtklein748ca3b2015-01-15 10:56:12 -0800515};
516
Mike Reedf67c4592017-02-17 17:06:11 -0500517class ViaSVG : public Via {
518public:
519 explicit ViaSVG(Sink* sink) : Via(sink) {}
520 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
521};
522
mtklein9c5052f2016-08-06 12:51:51 -0700523class ViaLite : public Via {
524public:
525 explicit ViaLite(Sink* sink) : Via(sink) {}
526 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
527};
528
Mike Klein841101d2017-03-10 09:55:51 -0500529class ViaCSXform : public Via {
530public:
Mike Klein919cc452017-03-18 15:36:52 +0000531 explicit ViaCSXform(Sink*, sk_sp<SkColorSpace>, bool colorSpin);
Mike Klein841101d2017-03-10 09:55:51 -0500532 Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
533private:
534 sk_sp<SkColorSpace> fCS;
Mike Klein919cc452017-03-18 15:36:52 +0000535 bool fColorSpin;
Mike Klein841101d2017-03-10 09:55:51 -0500536};
537
mtklein748ca3b2015-01-15 10:56:12 -0800538} // namespace DM
539
540#endif//DMSrcSink_DEFINED