blob: 85c71ee2fcdf45d3af25d055f2d056b9583051b8 [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"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/core/SkBBHFactory.h"
13#include "include/core/SkBitmap.h"
14#include "include/core/SkCanvas.h"
15#include "include/core/SkData.h"
16#include "include/core/SkPicture.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050017#include "src/utils/SkMultiPictureDocument.h"
18#include "tools/flags/CommonFlagsConfig.h"
Brian Osman9c310472019-06-27 16:43:27 -040019#include "tools/gpu/MemoryCache.h"
mtklein748ca3b2015-01-15 10:56:12 -080020
Brian Osmaned58e002019-09-06 14:42:43 -040021#include <functional>
22
Mike Reedbae888e2017-02-18 16:50:45 -050023//#define TEST_VIA_SVG
24
Tyler Denniston45f94f82020-02-04 16:09:08 -050025namespace skiagm {
26namespace verifiers {
27class VerifierList;
John Stilesa6841be2020-08-06 14:11:56 -040028} // namespace verifiers
29} // namespace skiagm
Tyler Denniston45f94f82020-02-04 16:09:08 -050030
mtklein748ca3b2015-01-15 10:56:12 -080031namespace DM {
32
33// This is just convenience. It lets you use either return "foo" or return SkStringPrintf(...).
34struct ImplicitString : public SkString {
35 template <typename T>
36 ImplicitString(const T& s) : SkString(s) {}
msarett9e707a02015-09-01 14:57:57 -070037 ImplicitString() : SkString("") {}
mtklein748ca3b2015-01-15 10:56:12 -080038};
mtklein748ca3b2015-01-15 10:56:12 -080039typedef ImplicitString Name;
mtklein8d17a132015-01-30 11:42:31 -080040typedef ImplicitString Path;
mtklein748ca3b2015-01-15 10:56:12 -080041
Ben Wagnerea25fcf2020-02-12 11:18:46 -050042class Result {
mtklein4089ef72015-03-05 08:40:28 -080043public:
Ben Wagnerea25fcf2020-02-12 11:18:46 -050044 enum class Status : int { Ok, Fatal, Skip };
45 Result(Status status, const SkString& s) : fMsg(s), fStatus(status) {}
46 Result(Status status, const char* s) : fMsg(s), fStatus(status) {}
47 template <typename... Args> Result (Status status, const char* s, Args... args)
48 : fMsg(SkStringPrintf(s, args...)), fStatus(status) {}
mtklein4089ef72015-03-05 08:40:28 -080049
Ben Wagnerea25fcf2020-02-12 11:18:46 -050050 Result(const Result&) = default;
51 Result& operator=(const Result&) = default;
mtklein4089ef72015-03-05 08:40:28 -080052
Ben Wagnerea25fcf2020-02-12 11:18:46 -050053 static Result Ok() { return Result(Status::Ok, nullptr); }
54
55 static Result Fatal(const SkString& s) { return Result(Status::Fatal, s); }
56 static Result Fatal(const char* s) { return Result(Status::Fatal, s); }
57 template <typename... Args> static Result Fatal(const char* s, Args... args) {
58 return Result(Status::Fatal, s, args...);
mtklein4089ef72015-03-05 08:40:28 -080059 }
60
Ben Wagnerea25fcf2020-02-12 11:18:46 -050061 static Result Skip(const SkString& s) { return Result(Status::Skip, s); }
62 static Result Skip(const char* s) { return Result(Status::Skip, s); }
63 template <typename... Args> static Result Skip(const char* s, Args... args) {
64 return Result(Status::Skip, s, args...);
65 }
66
67 bool isOk() { return fStatus == Status::Ok; }
68 bool isFatal() { return fStatus == Status::Fatal; }
69 bool isSkip() { return fStatus == Status::Skip; }
70
mtklein4089ef72015-03-05 08:40:28 -080071 const char* c_str() const { return fMsg.c_str(); }
Ben Wagnerea25fcf2020-02-12 11:18:46 -050072 Status status() const { return fStatus; }
mtklein4089ef72015-03-05 08:40:28 -080073
74private:
75 SkString fMsg;
Ben Wagnerea25fcf2020-02-12 11:18:46 -050076 Status fStatus;
mtklein4089ef72015-03-05 08:40:28 -080077};
78
mtklein99cab4e2015-07-31 06:43:04 -070079struct SinkFlags {
Brian Salomonbd7c5512017-03-07 09:08:36 -050080 enum Type { kNull, kGPU, kVector, kRaster } type;
81 enum Approach { kDirect, kIndirect } approach;
82 enum Multisampled { kNotMultisampled, kMultisampled } multisampled;
83 SinkFlags(Type t, Approach a, Multisampled ms = kNotMultisampled)
84 : type(t), approach(a), multisampled(ms) {}
mtklein99cab4e2015-07-31 06:43:04 -070085};
mtkleine0effd62015-07-29 06:37:28 -070086
mtklein748ca3b2015-01-15 10:56:12 -080087struct Src {
mtklein748ca3b2015-01-15 10:56:12 -080088 virtual ~Src() {}
John Stilesdfd1a702021-07-20 12:50:40 -040089 virtual Result SK_WARN_UNUSED_RESULT draw(GrDirectContext* context, SkCanvas* canvas) const = 0;
mtklein748ca3b2015-01-15 10:56:12 -080090 virtual SkISize size() const = 0;
91 virtual Name name() const = 0;
bsalomon4ee6bd82015-05-27 13:23:23 -070092 virtual void modifyGrContextOptions(GrContextOptions* options) const {}
mtklein99cab4e2015-07-31 06:43:04 -070093 virtual bool veto(SinkFlags) const { return false; }
mtklein21eaf3b2016-02-08 12:39:59 -080094
halcanary45420a92016-06-02 12:41:14 -070095 virtual int pageCount() const { return 1; }
John Stilesdfd1a702021-07-20 12:50:40 -040096 virtual Result SK_WARN_UNUSED_RESULT draw([[maybe_unused]] int page, GrDirectContext* context,
Robert Phillipsb87b39b2020-07-01 14:45:24 -040097 SkCanvas* canvas) const {
Robert Phillips889d6132020-06-16 11:11:33 -040098 return this->draw(context, canvas);
halcanary45420a92016-06-02 12:41:14 -070099 }
John Stilesdfd1a702021-07-20 12:50:40 -0400100 virtual SkISize size([[maybe_unused]] int page) const { return this->size(); }
mtklein21eaf3b2016-02-08 12:39:59 -0800101 // Force Tasks using this Src to run on the main thread?
102 virtual bool serial() const { return false; }
Tyler Denniston45f94f82020-02-04 16:09:08 -0500103
104 /** Return a list of verifiers for the src, or null if no verifiers should be run .*/
105 virtual std::unique_ptr<skiagm::verifiers::VerifierList> getVerifiers() const {
106 return nullptr;
107 }
mtklein748ca3b2015-01-15 10:56:12 -0800108};
109
110struct Sink {
111 virtual ~Sink() {}
mtkleinb9eb4ac2015-02-02 18:26:03 -0800112 // You may write to either the bitmap or stream. If you write to log, we'll print that out.
Ben Wagnerea25fcf2020-02-12 11:18:46 -0500113 virtual Result SK_WARN_UNUSED_RESULT draw(const Src&, SkBitmap*, SkWStream*, SkString* log)
mtkleinb9eb4ac2015-02-02 18:26:03 -0800114 const = 0;
mtklein21eaf3b2016-02-08 12:39:59 -0800115
Brian Osman54ef97c2021-08-11 17:06:42 -0400116 // Override the color space of this Sink, after creation
117 virtual void setColorSpace(sk_sp<SkColorSpace>) {}
118
mtklein21eaf3b2016-02-08 12:39:59 -0800119 // Force Tasks using this Sink to run on the main thread?
120 virtual bool serial() const { return false; }
mtklein748ca3b2015-01-15 10:56:12 -0800121
122 // File extension for the content draw() outputs, e.g. "png", "pdf".
123 virtual const char* fileExtension() const = 0;
mtklein99cab4e2015-07-31 06:43:04 -0700124
125 virtual SinkFlags flags() const = 0;
Tyler Denniston45f94f82020-02-04 16:09:08 -0500126
127 /** Returns the color type and space used by the sink. */
128 virtual SkColorInfo colorInfo() const { return SkColorInfo(); }
mtklein748ca3b2015-01-15 10:56:12 -0800129};
130
mtklein748ca3b2015-01-15 10:56:12 -0800131/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
132
mtklein748ca3b2015-01-15 10:56:12 -0800133class GMSrc : public Src {
134public:
Hal Canary972eba32018-07-30 17:07:07 -0400135 explicit GMSrc(skiagm::GMFactory);
mtklein748ca3b2015-01-15 10:56:12 -0800136
Robert Phillipsb87b39b2020-07-01 14:45:24 -0400137 Result draw(GrDirectContext*, SkCanvas*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700138 SkISize size() const override;
139 Name name() const override;
bsalomon4ee6bd82015-05-27 13:23:23 -0700140 void modifyGrContextOptions(GrContextOptions* options) const override;
141
Tyler Denniston45f94f82020-02-04 16:09:08 -0500142 std::unique_ptr<skiagm::verifiers::VerifierList> getVerifiers() const override;
143
mtklein748ca3b2015-01-15 10:56:12 -0800144private:
Hal Canary972eba32018-07-30 17:07:07 -0400145 skiagm::GMFactory fFactory;
mtklein748ca3b2015-01-15 10:56:12 -0800146};
147
scroggo9b77ddd2015-03-19 06:03:39 -0700148class CodecSrc : public Src {
149public:
scroggo9c59ebc2015-03-25 13:48:49 -0700150 enum Mode {
msarett9e707a02015-09-01 14:57:57 -0700151 kCodec_Mode,
msarettbb25b532016-01-13 09:31:39 -0800152 // We choose to test only one mode with zero initialized memory.
153 // This will exercise all of the interesting cases in SkSwizzler
154 // without doubling the size of our test suite.
155 kCodecZeroInit_Mode,
scroggo9c59ebc2015-03-25 13:48:49 -0700156 kScanline_Mode,
msarett0a242972015-06-11 14:27:27 -0700157 kStripe_Mode, // Tests the skipping of scanlines
msarett91c22b22016-02-22 12:27:46 -0800158 kCroppedScanline_Mode, // Tests (jpeg) cropped scanline optimization
scroggob636b452015-07-22 07:16:20 -0700159 kSubset_Mode, // For codecs that support subsets directly.
scroggo19b91532016-10-24 09:03:26 -0700160 kAnimated_Mode, // For codecs that support animation.
scroggo9c59ebc2015-03-25 13:48:49 -0700161 };
msarett438b2ad2015-04-09 12:43:10 -0700162 enum DstColorType {
163 kGetFromCanvas_DstColorType,
msarett438b2ad2015-04-09 12:43:10 -0700164 kGrayscale_Always_DstColorType,
msarett34e0ec42016-04-22 16:27:24 -0700165 kNonNative8888_Always_DstColorType,
msarett438b2ad2015-04-09 12:43:10 -0700166 };
scroggoc5560be2016-02-03 09:42:42 -0800167 CodecSrc(Path, Mode, DstColorType, SkAlphaType, float);
scroggo9b77ddd2015-03-19 06:03:39 -0700168
Robert Phillipsb87b39b2020-07-01 14:45:24 -0400169 Result draw(GrDirectContext*, SkCanvas*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700170 SkISize size() const override;
171 Name name() const override;
mtklein99cab4e2015-07-31 06:43:04 -0700172 bool veto(SinkFlags) const override;
scroggo3ac66e92016-02-08 15:09:48 -0800173 bool serial() const override { return fRunSerially; }
scroggo9b77ddd2015-03-19 06:03:39 -0700174private:
msarett9e707a02015-09-01 14:57:57 -0700175 Path fPath;
176 Mode fMode;
177 DstColorType fDstColorType;
scroggoc5560be2016-02-03 09:42:42 -0800178 SkAlphaType fDstAlphaType;
msarett9e707a02015-09-01 14:57:57 -0700179 float fScale;
scroggo3ac66e92016-02-08 15:09:48 -0800180 bool fRunSerially;
scroggo9b77ddd2015-03-19 06:03:39 -0700181};
182
msarett3d9d7a72015-10-21 10:27:10 -0700183class AndroidCodecSrc : public Src {
184public:
scroggof8dc9df2016-05-16 09:04:13 -0700185 AndroidCodecSrc(Path, CodecSrc::DstColorType, SkAlphaType, int sampleSize);
msarett3d9d7a72015-10-21 10:27:10 -0700186
Robert Phillipsb87b39b2020-07-01 14:45:24 -0400187 Result draw(GrDirectContext*, SkCanvas*) const override;
msarett3d9d7a72015-10-21 10:27:10 -0700188 SkISize size() const override;
189 Name name() const override;
190 bool veto(SinkFlags) const override;
scroggo3ac66e92016-02-08 15:09:48 -0800191 bool serial() const override { return fRunSerially; }
msarett3d9d7a72015-10-21 10:27:10 -0700192private:
193 Path fPath;
msarett3d9d7a72015-10-21 10:27:10 -0700194 CodecSrc::DstColorType fDstColorType;
scroggoc5560be2016-02-03 09:42:42 -0800195 SkAlphaType fDstAlphaType;
msarett3d9d7a72015-10-21 10:27:10 -0700196 int fSampleSize;
scroggo3ac66e92016-02-08 15:09:48 -0800197 bool fRunSerially;
msarett3d9d7a72015-10-21 10:27:10 -0700198};
199
Leon Scroggins III87caae62020-05-04 10:02:45 -0400200#ifdef SK_ENABLE_ANDROID_UTILS
msaretta5783ae2015-09-08 15:35:32 -0700201// Allows for testing of various implementations of Android's BitmapRegionDecoder
202class BRDSrc : public Src {
203public:
204 enum Mode {
205 // Decode the entire image as one region.
206 kFullImage_Mode,
207 // Splits the image into multiple regions using a divisor and decodes the regions
208 // separately. Also, this test adds a border of a few pixels to each of the regions
209 // that it is decoding. This tests the behavior when a client asks for a region that
210 // does not fully fit in the image.
211 kDivisor_Mode,
212 };
213
msarettd1227a72016-05-18 06:23:57 -0700214 BRDSrc(Path, Mode, CodecSrc::DstColorType, uint32_t);
msaretta5783ae2015-09-08 15:35:32 -0700215
Robert Phillipsb87b39b2020-07-01 14:45:24 -0400216 Result draw(GrDirectContext*, SkCanvas*) const override;
msaretta5783ae2015-09-08 15:35:32 -0700217 SkISize size() const override;
218 Name name() const override;
219 bool veto(SinkFlags) const override;
220private:
221 Path fPath;
msaretta5783ae2015-09-08 15:35:32 -0700222 Mode fMode;
223 CodecSrc::DstColorType fDstColorType;
224 uint32_t fSampleSize;
225};
Leon Scroggins III87caae62020-05-04 10:02:45 -0400226#endif
scroggo9b77ddd2015-03-19 06:03:39 -0700227
msarett18976312016-03-09 14:20:58 -0800228class ImageGenSrc : public Src {
229public:
230 enum Mode {
231 kCodec_Mode, // Use CodecImageGenerator
232 kPlatform_Mode, // Uses CG or WIC
233 };
234 ImageGenSrc(Path, Mode, SkAlphaType, bool);
235
Robert Phillipsb87b39b2020-07-01 14:45:24 -0400236 Result draw(GrDirectContext*, SkCanvas*) const override;
msarett18976312016-03-09 14:20:58 -0800237 SkISize size() const override;
238 Name name() const override;
239 bool veto(SinkFlags) const override;
240 bool serial() const override { return fRunSerially; }
241private:
242 Path fPath;
243 Mode fMode;
244 SkAlphaType fDstAlphaType;
245 bool fIsGpu;
246 bool fRunSerially;
247};
248
msarett69deca82016-04-29 09:38:40 -0700249class ColorCodecSrc : public Src {
250public:
Mike Klein0d5d1422019-03-06 10:56:04 -0600251 ColorCodecSrc(Path, bool decode_to_dst);
msarett69deca82016-04-29 09:38:40 -0700252
Robert Phillipsb87b39b2020-07-01 14:45:24 -0400253 Result draw(GrDirectContext*, SkCanvas*) const override;
msarett69deca82016-04-29 09:38:40 -0700254 SkISize size() const override;
255 Name name() const override;
256 bool veto(SinkFlags) const override;
257private:
Mike Klein0d5d1422019-03-06 10:56:04 -0600258 Path fPath;
259 bool fDecodeToDst;
msarett69deca82016-04-29 09:38:40 -0700260};
261
mtklein748ca3b2015-01-15 10:56:12 -0800262class SKPSrc : public Src {
263public:
mtklein8d17a132015-01-30 11:42:31 -0800264 explicit SKPSrc(Path path);
mtklein748ca3b2015-01-15 10:56:12 -0800265
Robert Phillipsb87b39b2020-07-01 14:45:24 -0400266 Result draw(GrDirectContext*, SkCanvas*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700267 SkISize size() const override;
268 Name name() const override;
mtklein748ca3b2015-01-15 10:56:12 -0800269private:
mtklein8d17a132015-01-30 11:42:31 -0800270 Path fPath;
mtklein748ca3b2015-01-15 10:56:12 -0800271};
272
Chris Dalton184c37e2018-09-28 11:27:39 -0600273// This class extracts all the paths from an SKP and then removes unwanted paths according to the
274// provided l/r trail. It then just draws the remaining paths. (Non-path draws are thrown out.) It
275// is useful for finding a reduced repo case for path drawing bugs.
276class BisectSrc : public SKPSrc {
277public:
278 explicit BisectSrc(Path path, const char* trail);
279
Robert Phillipsb87b39b2020-07-01 14:45:24 -0400280 Result draw(GrDirectContext*, SkCanvas*) const override;
Chris Dalton184c37e2018-09-28 11:27:39 -0600281
282private:
283 SkString fTrail;
284
John Stiles7571f9e2020-09-02 22:42:33 -0400285 using INHERITED = SKPSrc;
Chris Dalton184c37e2018-09-28 11:27:39 -0600286};
287
Florin Malita87ccf332018-05-04 12:23:24 -0400288#if defined(SK_ENABLE_SKOTTIE)
Florin Malita54f65c42018-01-16 17:04:30 -0500289class SkottieSrc final : public Src {
Florin Malitafc043dc2017-12-31 11:08:42 -0500290public:
Florin Malita54f65c42018-01-16 17:04:30 -0500291 explicit SkottieSrc(Path path);
Florin Malitafc043dc2017-12-31 11:08:42 -0500292
Robert Phillipsb87b39b2020-07-01 14:45:24 -0400293 Result draw(GrDirectContext*, SkCanvas*) const override;
Florin Malitafc043dc2017-12-31 11:08:42 -0500294 SkISize size() const override;
295 Name name() const override;
296 bool veto(SinkFlags) const override;
297
298private:
299 // Generates a kTileCount x kTileCount filmstrip with evenly distributed frames.
Florin Malita1022f742018-02-23 11:10:22 -0500300 static constexpr int kTileCount = 5;
Florin Malitafc043dc2017-12-31 11:08:42 -0500301
Florin Malita9f7d4cd2018-07-30 15:49:20 -0400302 // Fit kTileCount x kTileCount frames to a 1000x1000 film strip.
303 static constexpr SkScalar kTargetSize = 1000;
304 static constexpr SkScalar kTileSize = kTargetSize / kTileCount;
305
306 Path fPath;
Florin Malitafc043dc2017-12-31 11:08:42 -0500307};
Florin Malita124d5af2017-12-31 17:02:26 -0500308#endif
Florin Malitafc043dc2017-12-31 11:08:42 -0500309
Florin Malita02616ea2020-06-25 13:33:17 -0400310#if defined(SK_ENABLE_SKRIVE)
311class SkRiveSrc final : public Src {
312public:
313 explicit SkRiveSrc(Path path);
314
Robert Phillipsb87b39b2020-07-01 14:45:24 -0400315 Result draw(GrDirectContext*, SkCanvas*) const override;
Florin Malita02616ea2020-06-25 13:33:17 -0400316 SkISize size() const override;
317 Name name() const override;
318 bool veto(SinkFlags) const override;
319
320private:
321 // Generates a kTileCount x kTileCount filmstrip with evenly distributed frames.
322 static constexpr int kTileCount = 5;
323
324 // Fit kTileCount x kTileCount frames to a 1000x1000 film strip.
325 static constexpr SkScalar kTargetSize = 1000;
326 static constexpr SkScalar kTileSize = kTargetSize / kTileCount;
327
328 const Path fPath;
329};
330#endif
331
Robert Phillips2af13c12021-09-01 16:47:01 +0000332#if defined(SK_ENABLE_SVG)
fmalitabdf3e5c2016-09-17 07:26:26 -0700333} // namespace DM
334
335class SkSVGDOM;
336
337namespace DM {
338
fmalitaa2b9fdf2016-08-03 19:53:36 -0700339class SVGSrc : public Src {
340public:
341 explicit SVGSrc(Path path);
342
Robert Phillipsb87b39b2020-07-01 14:45:24 -0400343 Result draw(GrDirectContext*, SkCanvas*) const override;
fmalitaa2b9fdf2016-08-03 19:53:36 -0700344 SkISize size() const override;
345 Name name() const override;
fmalita179d8852016-08-16 14:23:29 -0700346 bool veto(SinkFlags) const override;
fmalitaa2b9fdf2016-08-03 19:53:36 -0700347
348private:
fmalitaacd2f5c2016-11-08 07:13:45 -0800349 Name fName;
350 sk_sp<SkSVGDOM> fDom;
351 SkScalar fScale;
fmalitaa2b9fdf2016-08-03 19:53:36 -0700352
John Stiles7571f9e2020-09-02 22:42:33 -0400353 using INHERITED = Src;
fmalitaa2b9fdf2016-08-03 19:53:36 -0700354};
Robert Phillips2af13c12021-09-01 16:47:01 +0000355#endif // SK_ENABLE_SVG
mtklein748ca3b2015-01-15 10:56:12 -0800356/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
357
halcanary45420a92016-06-02 12:41:14 -0700358class MSKPSrc : public Src {
359public:
360 explicit MSKPSrc(Path path);
361
362 int pageCount() const override;
Robert Phillipsb87b39b2020-07-01 14:45:24 -0400363 Result draw(GrDirectContext*, SkCanvas* c) const override;
364 Result draw(int, GrDirectContext*, SkCanvas*) const override;
halcanary45420a92016-06-02 12:41:14 -0700365 SkISize size() const override;
366 SkISize size(int) const override;
367 Name name() const override;
368
369private:
370 Path fPath;
Hal Canary45cde312017-04-03 16:06:42 -0400371 mutable SkTArray<SkDocumentPage> fPages;
halcanary45420a92016-06-02 12:41:14 -0700372};
373
374/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
375
mtkleinad66f9b2015-02-13 15:11:10 -0800376class NullSink : public Sink {
377public:
378 NullSink() {}
379
Ben Wagnerea25fcf2020-02-12 11:18:46 -0500380 Result draw(const Src& src, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700381 const char* fileExtension() const override { return ""; }
mtklein99cab4e2015-07-31 06:43:04 -0700382 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kNull, SinkFlags::kDirect }; }
mtkleinad66f9b2015-02-13 15:11:10 -0800383};
384
mtklein748ca3b2015-01-15 10:56:12 -0800385class GPUSink : public Sink {
386public:
Brian Osman3fdfe282019-09-09 13:46:52 -0400387 GPUSink(const SkCommandLineConfigGpu*, const GrContextOptions&);
mtklein748ca3b2015-01-15 10:56:12 -0800388
Ben Wagnerea25fcf2020-02-12 11:18:46 -0500389 Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
390 Result onDraw(const Src&, SkBitmap*, SkWStream*, SkString*,
391 const GrContextOptions& baseOptions,
Robert Phillipse219c7e2020-08-13 15:58:29 -0400392 std::function<void(GrDirectContext*)> initContext = nullptr) const;
Brian Osmanf9810662017-08-30 10:02:10 -0400393
Brian Salomonb07fd4d2018-03-09 13:17:30 -0500394 sk_gpu_test::GrContextFactory::ContextType contextType() const { return fContextType; }
Robert Phillips3c1efd42020-02-13 15:51:59 -0500395 const sk_gpu_test::GrContextFactory::ContextOverrides& contextOverrides() const {
Brian Salomonb07fd4d2018-03-09 13:17:30 -0500396 return fContextOverrides;
397 }
398 SkCommandLineConfigGpu::SurfType surfType() const { return fSurfType; }
Brian Osman3fdfe282019-09-09 13:46:52 -0400399 bool serial() const override { return true; }
mtklein36352bf2015-03-25 18:17:31 -0700400 const char* fileExtension() const override { return "png"; }
Brian Salomonbd7c5512017-03-07 09:08:36 -0500401 SinkFlags flags() const override {
Brian Salomonbdecacf2018-02-02 20:32:49 -0500402 SinkFlags::Multisampled ms = fSampleCount > 1 ? SinkFlags::kMultisampled
Brian Salomonfd171ed2017-03-08 11:38:45 -0500403 : SinkFlags::kNotMultisampled;
404 return SinkFlags{ SinkFlags::kGPU, SinkFlags::kDirect, ms };
Brian Salomonbd7c5512017-03-07 09:08:36 -0500405 }
Brian Osmanf9810662017-08-30 10:02:10 -0400406 const GrContextOptions& baseContextOptions() const { return fBaseContextOptions; }
Brian Osman54ef97c2021-08-11 17:06:42 -0400407 void setColorSpace(sk_sp<SkColorSpace> colorSpace) override { fColorSpace = colorSpace; }
Tyler Denniston45f94f82020-02-04 16:09:08 -0500408 SkColorInfo colorInfo() const override {
409 return SkColorInfo(fColorType, fAlphaType, fColorSpace);
410 }
Brian Osmanf9810662017-08-30 10:02:10 -0400411
Robert Phillips3c1efd42020-02-13 15:51:59 -0500412protected:
Brian Salomonf9b00422020-10-08 16:00:14 -0400413 sk_sp<SkSurface> createDstSurface(GrDirectContext*, SkISize size) const;
Robert Phillips3c1efd42020-02-13 15:51:59 -0500414 bool readBack(SkSurface*, SkBitmap* dst) const;
415
mtklein748ca3b2015-01-15 10:56:12 -0800416private:
csmartdaltone812d492017-02-21 12:36:05 -0700417 sk_gpu_test::GrContextFactory::ContextType fContextType;
418 sk_gpu_test::GrContextFactory::ContextOverrides fContextOverrides;
Brian Salomonf865b052018-03-09 09:01:53 -0500419 SkCommandLineConfigGpu::SurfType fSurfType;
csmartdaltone812d492017-02-21 12:36:05 -0700420 int fSampleCount;
Chris Dalton180b4a12021-03-16 20:49:15 -0600421 uint32_t fSurfaceFlags;
csmartdaltone812d492017-02-21 12:36:05 -0700422 SkColorType fColorType;
Brian Salomonce5ee602017-07-17 11:31:31 -0400423 SkAlphaType fAlphaType;
csmartdaltone812d492017-02-21 12:36:05 -0700424 sk_sp<SkColorSpace> fColorSpace;
Brian Osmanf21aa042017-08-21 16:48:46 -0400425 GrContextOptions fBaseContextOptions;
Brian Osman9c310472019-06-27 16:43:27 -0400426 sk_gpu_test::MemoryCache fMemoryCache;
mtklein748ca3b2015-01-15 10:56:12 -0800427};
428
Brian Osmanf9810662017-08-30 10:02:10 -0400429class GPUThreadTestingSink : public GPUSink {
430public:
Brian Osman3fdfe282019-09-09 13:46:52 -0400431 GPUThreadTestingSink(const SkCommandLineConfigGpu*, const GrContextOptions&);
Brian Osmanf9810662017-08-30 10:02:10 -0400432
Ben Wagnerea25fcf2020-02-12 11:18:46 -0500433 Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
Brian Osmanf9810662017-08-30 10:02:10 -0400434
Brian Osmanf1942de2017-08-30 14:50:22 -0400435 const char* fileExtension() const override {
436 // Suppress writing out results from this config - we just want to do our matching test
437 return nullptr;
438 }
439
Brian Osmanf9810662017-08-30 10:02:10 -0400440private:
441 std::unique_ptr<SkExecutor> fExecutor;
442
John Stiles7571f9e2020-09-02 22:42:33 -0400443 using INHERITED = GPUSink;
Brian Osmanf9810662017-08-30 10:02:10 -0400444};
445
Brian Salomon00a5eb82018-07-11 15:32:05 -0400446class GPUPersistentCacheTestingSink : public GPUSink {
447public:
Brian Osman3fdfe282019-09-09 13:46:52 -0400448 GPUPersistentCacheTestingSink(const SkCommandLineConfigGpu*, const GrContextOptions&);
Brian Salomon00a5eb82018-07-11 15:32:05 -0400449
Ben Wagnerea25fcf2020-02-12 11:18:46 -0500450 Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
Brian Salomon00a5eb82018-07-11 15:32:05 -0400451
452 const char* fileExtension() const override {
453 // Suppress writing out results from this config - we just want to do our matching test
454 return nullptr;
455 }
456
457private:
Brian Osmanf71b0702019-04-03 13:04:16 -0400458 int fCacheType;
459
John Stiles7571f9e2020-09-02 22:42:33 -0400460 using INHERITED = GPUSink;
Brian Salomon00a5eb82018-07-11 15:32:05 -0400461};
462
Brian Osmaned58e002019-09-06 14:42:43 -0400463class GPUPrecompileTestingSink : public GPUSink {
464public:
Brian Osman3fdfe282019-09-09 13:46:52 -0400465 GPUPrecompileTestingSink(const SkCommandLineConfigGpu*, const GrContextOptions&);
Brian Osmaned58e002019-09-06 14:42:43 -0400466
Ben Wagnerea25fcf2020-02-12 11:18:46 -0500467 Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
Brian Osmaned58e002019-09-06 14:42:43 -0400468
469 const char* fileExtension() const override {
470 // Suppress writing out results from this config - we just want to do our matching test
471 return nullptr;
472 }
473
474private:
John Stiles7571f9e2020-09-02 22:42:33 -0400475 using INHERITED = GPUSink;
Brian Osmaned58e002019-09-06 14:42:43 -0400476};
477
Robert Phillips762cb4e2020-06-15 13:12:32 -0400478// This sink attempts to emulate Chrome's OOP-R behavior. It:
479// doesn't use promise images
480// uses only a single thread for both DDL creation & drawing
481class GPUOOPRSink : public GPUSink {
482public:
483 GPUOOPRSink(const SkCommandLineConfigGpu*, const GrContextOptions&);
484
485 Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
486
487private:
Robert Phillipsb87b39b2020-07-01 14:45:24 -0400488 Result ooprDraw(const Src&, sk_sp<SkSurface> dstSurface, GrDirectContext*) const;
Robert Phillips762cb4e2020-06-15 13:12:32 -0400489
John Stiles7571f9e2020-09-02 22:42:33 -0400490 using INHERITED = GPUSink;
Robert Phillips762cb4e2020-06-15 13:12:32 -0400491};
492
Robert Phillips291f3402020-02-19 14:14:47 -0500493// This sink attempts to better simulate the Chrome DDL use-case. It:
494// creates the DDLs on separate recording threads
495// performs all the GPU work on a separate GPU thread
496// In the future this should be expanded to:
497// upload on a utility thread w/ access to a shared context
498// compile the programs on the utility thread
499// perform fine grained scheduling of gpu tasks based on their image and program prerequisites
500// create a single "compositing" DDL that is replayed last
501class GPUDDLSink : public GPUSink {
502public:
503 GPUDDLSink(const SkCommandLineConfigGpu*, const GrContextOptions&);
504
505 Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
506
507private:
508 Result ddlDraw(const Src&,
509 sk_sp<SkSurface> dstSurface,
510 SkTaskGroup* recordingTaskGroup,
511 SkTaskGroup* gpuTaskGroup,
Robert Phillips19f466d2020-02-26 10:27:07 -0500512 sk_gpu_test::TestContext* gpuTestCtx,
Robert Phillipsb87b39b2020-07-01 14:45:24 -0400513 GrDirectContext* gpuThreadCtx) const;
Robert Phillips291f3402020-02-19 14:14:47 -0500514
Robert Phillips762cb4e2020-06-15 13:12:32 -0400515 std::unique_ptr<SkExecutor> fRecordingExecutor;
516 std::unique_ptr<SkExecutor> fGPUExecutor;
Robert Phillips291f3402020-02-19 14:14:47 -0500517
John Stiles7571f9e2020-09-02 22:42:33 -0400518 using INHERITED = GPUSink;
Robert Phillips291f3402020-02-19 14:14:47 -0500519};
520
mtklein748ca3b2015-01-15 10:56:12 -0800521class PDFSink : public Sink {
522public:
Hal Canaryc7d295e2017-07-20 15:36:00 -0400523 PDFSink(bool pdfa, SkScalar rasterDpi) : fPDFA(pdfa), fRasterDpi(rasterDpi) {}
Ben Wagnerea25fcf2020-02-12 11:18:46 -0500524 Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700525 const char* fileExtension() const override { return "pdf"; }
mtklein99cab4e2015-07-31 06:43:04 -0700526 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
halcanary4b656662016-04-27 07:45:18 -0700527 bool fPDFA;
Hal Canaryc7d295e2017-07-20 15:36:00 -0400528 SkScalar fRasterDpi;
mtklein748ca3b2015-01-15 10:56:12 -0800529};
530
halcanary47ef4d52015-03-03 09:13:09 -0800531class XPSSink : public Sink {
532public:
533 XPSSink();
534
Ben Wagnerea25fcf2020-02-12 11:18:46 -0500535 Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700536 const char* fileExtension() const override { return "xps"; }
mtklein99cab4e2015-07-31 06:43:04 -0700537 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
halcanary47ef4d52015-03-03 09:13:09 -0800538};
539
mtklein748ca3b2015-01-15 10:56:12 -0800540class RasterSink : public Sink {
541public:
Brian Osmanfcb50232021-08-12 10:51:48 -0400542 explicit RasterSink(SkColorType);
mtklein748ca3b2015-01-15 10:56:12 -0800543
Ben Wagnerea25fcf2020-02-12 11:18:46 -0500544 Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700545 const char* fileExtension() const override { return "png"; }
mtklein99cab4e2015-07-31 06:43:04 -0700546 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kRaster, SinkFlags::kDirect }; }
Brian Osman54ef97c2021-08-11 17:06:42 -0400547 void setColorSpace(sk_sp<SkColorSpace> colorSpace) override { fColorSpace = colorSpace; }
Yuqian Lib8b62532018-02-23 14:13:36 +0800548
Mike Klein48b64902018-07-25 13:28:44 -0400549private:
brianosmanb109b8c2016-06-16 13:03:24 -0700550 SkColorType fColorType;
551 sk_sp<SkColorSpace> fColorSpace;
mtklein748ca3b2015-01-15 10:56:12 -0800552};
553
mtklein9c3f17d2015-01-28 11:35:18 -0800554class SKPSink : public Sink {
555public:
556 SKPSink();
557
Ben Wagnerea25fcf2020-02-12 11:18:46 -0500558 Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700559 const char* fileExtension() const override { return "skp"; }
mtklein99cab4e2015-07-31 06:43:04 -0700560 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
mtklein9c3f17d2015-01-28 11:35:18 -0800561};
562
Hal Canary85c7fe82016-10-25 10:33:27 -0400563class DebugSink : public Sink {
564public:
Ben Wagnerea25fcf2020-02-12 11:18:46 -0500565 Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
Hal Canary85c7fe82016-10-25 10:33:27 -0400566 const char* fileExtension() const override { return "json"; }
567 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
568};
569
mtklein8a4527e2015-01-31 20:00:58 -0800570class SVGSink : public Sink {
571public:
Bryce Thomas95a7b762018-03-02 13:54:21 -0800572 SVGSink(int pageIndex = 0);
mtklein8a4527e2015-01-31 20:00:58 -0800573
Ben Wagnerea25fcf2020-02-12 11:18:46 -0500574 Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein36352bf2015-03-25 18:17:31 -0700575 const char* fileExtension() const override { return "svg"; }
mtklein99cab4e2015-07-31 06:43:04 -0700576 SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
Bryce Thomas95a7b762018-03-02 13:54:21 -0800577
578private:
579 int fPageIndex;
mtklein8a4527e2015-01-31 20:00:58 -0800580};
581
582
mtklein748ca3b2015-01-15 10:56:12 -0800583/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
584
mtklein78829242015-05-06 07:54:07 -0700585class Via : public Sink {
586public:
msarett62d3b102015-12-10 15:14:27 -0800587 explicit Via(Sink* sink) : fSink(sink) {}
mtklein78829242015-05-06 07:54:07 -0700588 const char* fileExtension() const override { return fSink->fileExtension(); }
mtklein21eaf3b2016-02-08 12:39:59 -0800589 bool serial() const override { return fSink->serial(); }
mtklein99cab4e2015-07-31 06:43:04 -0700590 SinkFlags flags() const override {
591 SinkFlags flags = fSink->flags();
592 flags.approach = SinkFlags::kIndirect;
593 return flags;
594 }
Brian Osman54ef97c2021-08-11 17:06:42 -0400595 void setColorSpace(sk_sp<SkColorSpace> colorSpace) override {
596 fSink->setColorSpace(colorSpace);
597 }
mtklein78829242015-05-06 07:54:07 -0700598protected:
Ben Wagner145dbcd2016-11-03 14:40:50 -0400599 std::unique_ptr<Sink> fSink;
mtklein78829242015-05-06 07:54:07 -0700600};
601
602class ViaMatrix : public Via {
mtklein748ca3b2015-01-15 10:56:12 -0800603public:
msarett62d3b102015-12-10 15:14:27 -0800604 ViaMatrix(SkMatrix, Sink*);
Ben Wagnerea25fcf2020-02-12 11:18:46 -0500605 Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein748ca3b2015-01-15 10:56:12 -0800606private:
mtklein78829242015-05-06 07:54:07 -0700607 const SkMatrix fMatrix;
mtklein748ca3b2015-01-15 10:56:12 -0800608};
609
mtklein78829242015-05-06 07:54:07 -0700610class ViaUpright : public Via {
mtkleind603b222015-02-17 11:13:33 -0800611public:
msarett62d3b102015-12-10 15:14:27 -0800612 ViaUpright(SkMatrix, Sink*);
Ben Wagnerea25fcf2020-02-12 11:18:46 -0500613 Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtkleind603b222015-02-17 11:13:33 -0800614private:
mtklein78829242015-05-06 07:54:07 -0700615 const SkMatrix fMatrix;
mtkleind603b222015-02-17 11:13:33 -0800616};
617
mtklein78829242015-05-06 07:54:07 -0700618class ViaSerialization : public Via {
mtklein748ca3b2015-01-15 10:56:12 -0800619public:
msarett62d3b102015-12-10 15:14:27 -0800620 explicit ViaSerialization(Sink* sink) : Via(sink) {}
Ben Wagnerea25fcf2020-02-12 11:18:46 -0500621 Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein748ca3b2015-01-15 10:56:12 -0800622};
623
mtklein4a34ecb2016-01-08 10:19:35 -0800624class ViaPicture : public Via {
625public:
626 explicit ViaPicture(Sink* sink) : Via(sink) {}
Ben Wagnerea25fcf2020-02-12 11:18:46 -0500627 Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
mtklein4a34ecb2016-01-08 10:19:35 -0800628};
629
John Stiles65ec1982021-07-20 12:53:54 -0400630class ViaRuntimeBlend : public Via {
631public:
632 explicit ViaRuntimeBlend(Sink* sink) : Via(sink) {}
633 Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
634};
635
Mike Reedf67c4592017-02-17 17:06:11 -0500636class ViaSVG : public Via {
637public:
638 explicit ViaSVG(Sink* sink) : Via(sink) {}
Ben Wagnerea25fcf2020-02-12 11:18:46 -0500639 Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
Mike Reedf67c4592017-02-17 17:06:11 -0500640};
641
mtklein748ca3b2015-01-15 10:56:12 -0800642} // namespace DM
643
644#endif//DMSrcSink_DEFINED