scroggo | 478652e | 2015-03-25 07:11:02 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 8 | #ifndef DMSrcSink_DEFINED |
| 9 | #define DMSrcSink_DEFINED |
| 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "gm/gm.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 17 | #include "src/utils/SkMultiPictureDocument.h" |
| 18 | #include "tools/flags/CommonFlagsConfig.h" |
Brian Osman | 9c31047 | 2019-06-27 16:43:27 -0400 | [diff] [blame] | 19 | #include "tools/gpu/MemoryCache.h" |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 20 | |
Brian Osman | ed58e00 | 2019-09-06 14:42:43 -0400 | [diff] [blame] | 21 | #include <functional> |
| 22 | |
Mike Reed | bae888e | 2017-02-18 16:50:45 -0500 | [diff] [blame] | 23 | //#define TEST_VIA_SVG |
| 24 | |
Tyler Denniston | 45f94f8 | 2020-02-04 16:09:08 -0500 | [diff] [blame] | 25 | namespace skiagm { |
| 26 | namespace verifiers { |
| 27 | class VerifierList; |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 28 | } // namespace verifiers |
| 29 | } // namespace skiagm |
Tyler Denniston | 45f94f8 | 2020-02-04 16:09:08 -0500 | [diff] [blame] | 30 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 31 | namespace DM { |
| 32 | |
| 33 | // This is just convenience. It lets you use either return "foo" or return SkStringPrintf(...). |
| 34 | struct ImplicitString : public SkString { |
| 35 | template <typename T> |
| 36 | ImplicitString(const T& s) : SkString(s) {} |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 37 | ImplicitString() : SkString("") {} |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 38 | }; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 39 | typedef ImplicitString Name; |
mtklein | 8d17a13 | 2015-01-30 11:42:31 -0800 | [diff] [blame] | 40 | typedef ImplicitString Path; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 41 | |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 42 | class Result { |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 43 | public: |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 44 | 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) {} |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 49 | |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 50 | Result(const Result&) = default; |
| 51 | Result& operator=(const Result&) = default; |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 52 | |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 53 | 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...); |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 59 | } |
| 60 | |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 61 | 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 | |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 71 | const char* c_str() const { return fMsg.c_str(); } |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 72 | Status status() const { return fStatus; } |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 73 | |
| 74 | private: |
| 75 | SkString fMsg; |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 76 | Status fStatus; |
mtklein | 4089ef7 | 2015-03-05 08:40:28 -0800 | [diff] [blame] | 77 | }; |
| 78 | |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 79 | struct SinkFlags { |
Brian Salomon | bd7c551 | 2017-03-07 09:08:36 -0500 | [diff] [blame] | 80 | 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) {} |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 85 | }; |
mtklein | e0effd6 | 2015-07-29 06:37:28 -0700 | [diff] [blame] | 86 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 87 | struct Src { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 88 | virtual ~Src() {} |
John Stiles | dfd1a70 | 2021-07-20 12:50:40 -0400 | [diff] [blame] | 89 | virtual Result SK_WARN_UNUSED_RESULT draw(GrDirectContext* context, SkCanvas* canvas) const = 0; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 90 | virtual SkISize size() const = 0; |
| 91 | virtual Name name() const = 0; |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 92 | virtual void modifyGrContextOptions(GrContextOptions* options) const {} |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 93 | virtual bool veto(SinkFlags) const { return false; } |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 94 | |
halcanary | 45420a9 | 2016-06-02 12:41:14 -0700 | [diff] [blame] | 95 | virtual int pageCount() const { return 1; } |
John Stiles | dfd1a70 | 2021-07-20 12:50:40 -0400 | [diff] [blame] | 96 | virtual Result SK_WARN_UNUSED_RESULT draw([[maybe_unused]] int page, GrDirectContext* context, |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 97 | SkCanvas* canvas) const { |
Robert Phillips | 889d613 | 2020-06-16 11:11:33 -0400 | [diff] [blame] | 98 | return this->draw(context, canvas); |
halcanary | 45420a9 | 2016-06-02 12:41:14 -0700 | [diff] [blame] | 99 | } |
John Stiles | dfd1a70 | 2021-07-20 12:50:40 -0400 | [diff] [blame] | 100 | virtual SkISize size([[maybe_unused]] int page) const { return this->size(); } |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 101 | // Force Tasks using this Src to run on the main thread? |
| 102 | virtual bool serial() const { return false; } |
Tyler Denniston | 45f94f8 | 2020-02-04 16:09:08 -0500 | [diff] [blame] | 103 | |
| 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 | } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | struct Sink { |
| 111 | virtual ~Sink() {} |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 112 | // You may write to either the bitmap or stream. If you write to log, we'll print that out. |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 113 | virtual Result SK_WARN_UNUSED_RESULT draw(const Src&, SkBitmap*, SkWStream*, SkString* log) |
mtklein | b9eb4ac | 2015-02-02 18:26:03 -0800 | [diff] [blame] | 114 | const = 0; |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 115 | |
| 116 | // Force Tasks using this Sink to run on the main thread? |
| 117 | virtual bool serial() const { return false; } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 118 | |
| 119 | // File extension for the content draw() outputs, e.g. "png", "pdf". |
| 120 | virtual const char* fileExtension() const = 0; |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 121 | |
| 122 | virtual SinkFlags flags() const = 0; |
Tyler Denniston | 45f94f8 | 2020-02-04 16:09:08 -0500 | [diff] [blame] | 123 | |
| 124 | /** Returns the color type and space used by the sink. */ |
| 125 | virtual SkColorInfo colorInfo() const { return SkColorInfo(); } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 126 | }; |
| 127 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 128 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 129 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 130 | class GMSrc : public Src { |
| 131 | public: |
Hal Canary | 972eba3 | 2018-07-30 17:07:07 -0400 | [diff] [blame] | 132 | explicit GMSrc(skiagm::GMFactory); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 133 | |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 134 | Result draw(GrDirectContext*, SkCanvas*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 135 | SkISize size() const override; |
| 136 | Name name() const override; |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 137 | void modifyGrContextOptions(GrContextOptions* options) const override; |
| 138 | |
Tyler Denniston | 45f94f8 | 2020-02-04 16:09:08 -0500 | [diff] [blame] | 139 | std::unique_ptr<skiagm::verifiers::VerifierList> getVerifiers() const override; |
| 140 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 141 | private: |
Hal Canary | 972eba3 | 2018-07-30 17:07:07 -0400 | [diff] [blame] | 142 | skiagm::GMFactory fFactory; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 143 | }; |
| 144 | |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 145 | class CodecSrc : public Src { |
| 146 | public: |
scroggo | 9c59ebc | 2015-03-25 13:48:49 -0700 | [diff] [blame] | 147 | enum Mode { |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 148 | kCodec_Mode, |
msarett | bb25b53 | 2016-01-13 09:31:39 -0800 | [diff] [blame] | 149 | // We choose to test only one mode with zero initialized memory. |
| 150 | // This will exercise all of the interesting cases in SkSwizzler |
| 151 | // without doubling the size of our test suite. |
| 152 | kCodecZeroInit_Mode, |
scroggo | 9c59ebc | 2015-03-25 13:48:49 -0700 | [diff] [blame] | 153 | kScanline_Mode, |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 154 | kStripe_Mode, // Tests the skipping of scanlines |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 155 | kCroppedScanline_Mode, // Tests (jpeg) cropped scanline optimization |
scroggo | b636b45 | 2015-07-22 07:16:20 -0700 | [diff] [blame] | 156 | kSubset_Mode, // For codecs that support subsets directly. |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 157 | kAnimated_Mode, // For codecs that support animation. |
scroggo | 9c59ebc | 2015-03-25 13:48:49 -0700 | [diff] [blame] | 158 | }; |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 159 | enum DstColorType { |
| 160 | kGetFromCanvas_DstColorType, |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 161 | kGrayscale_Always_DstColorType, |
msarett | 34e0ec4 | 2016-04-22 16:27:24 -0700 | [diff] [blame] | 162 | kNonNative8888_Always_DstColorType, |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 163 | }; |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 164 | CodecSrc(Path, Mode, DstColorType, SkAlphaType, float); |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 165 | |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 166 | Result draw(GrDirectContext*, SkCanvas*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 167 | SkISize size() const override; |
| 168 | Name name() const override; |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 169 | bool veto(SinkFlags) const override; |
scroggo | 3ac66e9 | 2016-02-08 15:09:48 -0800 | [diff] [blame] | 170 | bool serial() const override { return fRunSerially; } |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 171 | private: |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 172 | Path fPath; |
| 173 | Mode fMode; |
| 174 | DstColorType fDstColorType; |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 175 | SkAlphaType fDstAlphaType; |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 176 | float fScale; |
scroggo | 3ac66e9 | 2016-02-08 15:09:48 -0800 | [diff] [blame] | 177 | bool fRunSerially; |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 178 | }; |
| 179 | |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 180 | class AndroidCodecSrc : public Src { |
| 181 | public: |
scroggo | f8dc9df | 2016-05-16 09:04:13 -0700 | [diff] [blame] | 182 | AndroidCodecSrc(Path, CodecSrc::DstColorType, SkAlphaType, int sampleSize); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 183 | |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 184 | Result draw(GrDirectContext*, SkCanvas*) const override; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 185 | SkISize size() const override; |
| 186 | Name name() const override; |
| 187 | bool veto(SinkFlags) const override; |
scroggo | 3ac66e9 | 2016-02-08 15:09:48 -0800 | [diff] [blame] | 188 | bool serial() const override { return fRunSerially; } |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 189 | private: |
| 190 | Path fPath; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 191 | CodecSrc::DstColorType fDstColorType; |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 192 | SkAlphaType fDstAlphaType; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 193 | int fSampleSize; |
scroggo | 3ac66e9 | 2016-02-08 15:09:48 -0800 | [diff] [blame] | 194 | bool fRunSerially; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 195 | }; |
| 196 | |
Leon Scroggins III | 87caae6 | 2020-05-04 10:02:45 -0400 | [diff] [blame] | 197 | #ifdef SK_ENABLE_ANDROID_UTILS |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 198 | // Allows for testing of various implementations of Android's BitmapRegionDecoder |
| 199 | class BRDSrc : public Src { |
| 200 | public: |
| 201 | enum Mode { |
| 202 | // Decode the entire image as one region. |
| 203 | kFullImage_Mode, |
| 204 | // Splits the image into multiple regions using a divisor and decodes the regions |
| 205 | // separately. Also, this test adds a border of a few pixels to each of the regions |
| 206 | // that it is decoding. This tests the behavior when a client asks for a region that |
| 207 | // does not fully fit in the image. |
| 208 | kDivisor_Mode, |
| 209 | }; |
| 210 | |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 211 | BRDSrc(Path, Mode, CodecSrc::DstColorType, uint32_t); |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 212 | |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 213 | Result draw(GrDirectContext*, SkCanvas*) const override; |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 214 | SkISize size() const override; |
| 215 | Name name() const override; |
| 216 | bool veto(SinkFlags) const override; |
| 217 | private: |
| 218 | Path fPath; |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 219 | Mode fMode; |
| 220 | CodecSrc::DstColorType fDstColorType; |
| 221 | uint32_t fSampleSize; |
| 222 | }; |
Leon Scroggins III | 87caae6 | 2020-05-04 10:02:45 -0400 | [diff] [blame] | 223 | #endif |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 224 | |
msarett | 1897631 | 2016-03-09 14:20:58 -0800 | [diff] [blame] | 225 | class ImageGenSrc : public Src { |
| 226 | public: |
| 227 | enum Mode { |
| 228 | kCodec_Mode, // Use CodecImageGenerator |
| 229 | kPlatform_Mode, // Uses CG or WIC |
| 230 | }; |
| 231 | ImageGenSrc(Path, Mode, SkAlphaType, bool); |
| 232 | |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 233 | Result draw(GrDirectContext*, SkCanvas*) const override; |
msarett | 1897631 | 2016-03-09 14:20:58 -0800 | [diff] [blame] | 234 | SkISize size() const override; |
| 235 | Name name() const override; |
| 236 | bool veto(SinkFlags) const override; |
| 237 | bool serial() const override { return fRunSerially; } |
| 238 | private: |
| 239 | Path fPath; |
| 240 | Mode fMode; |
| 241 | SkAlphaType fDstAlphaType; |
| 242 | bool fIsGpu; |
| 243 | bool fRunSerially; |
| 244 | }; |
| 245 | |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 246 | class ColorCodecSrc : public Src { |
| 247 | public: |
Mike Klein | 0d5d142 | 2019-03-06 10:56:04 -0600 | [diff] [blame] | 248 | ColorCodecSrc(Path, bool decode_to_dst); |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 249 | |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 250 | Result draw(GrDirectContext*, SkCanvas*) const override; |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 251 | SkISize size() const override; |
| 252 | Name name() const override; |
| 253 | bool veto(SinkFlags) const override; |
| 254 | private: |
Mike Klein | 0d5d142 | 2019-03-06 10:56:04 -0600 | [diff] [blame] | 255 | Path fPath; |
| 256 | bool fDecodeToDst; |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 257 | }; |
| 258 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 259 | class SKPSrc : public Src { |
| 260 | public: |
mtklein | 8d17a13 | 2015-01-30 11:42:31 -0800 | [diff] [blame] | 261 | explicit SKPSrc(Path path); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 262 | |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 263 | Result draw(GrDirectContext*, SkCanvas*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 264 | SkISize size() const override; |
| 265 | Name name() const override; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 266 | private: |
mtklein | 8d17a13 | 2015-01-30 11:42:31 -0800 | [diff] [blame] | 267 | Path fPath; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 268 | }; |
| 269 | |
Chris Dalton | 184c37e | 2018-09-28 11:27:39 -0600 | [diff] [blame] | 270 | // This class extracts all the paths from an SKP and then removes unwanted paths according to the |
| 271 | // provided l/r trail. It then just draws the remaining paths. (Non-path draws are thrown out.) It |
| 272 | // is useful for finding a reduced repo case for path drawing bugs. |
| 273 | class BisectSrc : public SKPSrc { |
| 274 | public: |
| 275 | explicit BisectSrc(Path path, const char* trail); |
| 276 | |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 277 | Result draw(GrDirectContext*, SkCanvas*) const override; |
Chris Dalton | 184c37e | 2018-09-28 11:27:39 -0600 | [diff] [blame] | 278 | |
| 279 | private: |
| 280 | SkString fTrail; |
| 281 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 282 | using INHERITED = SKPSrc; |
Chris Dalton | 184c37e | 2018-09-28 11:27:39 -0600 | [diff] [blame] | 283 | }; |
| 284 | |
Florin Malita | 87ccf33 | 2018-05-04 12:23:24 -0400 | [diff] [blame] | 285 | #if defined(SK_ENABLE_SKOTTIE) |
Florin Malita | 54f65c4 | 2018-01-16 17:04:30 -0500 | [diff] [blame] | 286 | class SkottieSrc final : public Src { |
Florin Malita | fc043dc | 2017-12-31 11:08:42 -0500 | [diff] [blame] | 287 | public: |
Florin Malita | 54f65c4 | 2018-01-16 17:04:30 -0500 | [diff] [blame] | 288 | explicit SkottieSrc(Path path); |
Florin Malita | fc043dc | 2017-12-31 11:08:42 -0500 | [diff] [blame] | 289 | |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 290 | Result draw(GrDirectContext*, SkCanvas*) const override; |
Florin Malita | fc043dc | 2017-12-31 11:08:42 -0500 | [diff] [blame] | 291 | SkISize size() const override; |
| 292 | Name name() const override; |
| 293 | bool veto(SinkFlags) const override; |
| 294 | |
| 295 | private: |
| 296 | // Generates a kTileCount x kTileCount filmstrip with evenly distributed frames. |
Florin Malita | 1022f74 | 2018-02-23 11:10:22 -0500 | [diff] [blame] | 297 | static constexpr int kTileCount = 5; |
Florin Malita | fc043dc | 2017-12-31 11:08:42 -0500 | [diff] [blame] | 298 | |
Florin Malita | 9f7d4cd | 2018-07-30 15:49:20 -0400 | [diff] [blame] | 299 | // Fit kTileCount x kTileCount frames to a 1000x1000 film strip. |
| 300 | static constexpr SkScalar kTargetSize = 1000; |
| 301 | static constexpr SkScalar kTileSize = kTargetSize / kTileCount; |
| 302 | |
| 303 | Path fPath; |
Florin Malita | fc043dc | 2017-12-31 11:08:42 -0500 | [diff] [blame] | 304 | }; |
Florin Malita | 124d5af | 2017-12-31 17:02:26 -0500 | [diff] [blame] | 305 | #endif |
Florin Malita | fc043dc | 2017-12-31 11:08:42 -0500 | [diff] [blame] | 306 | |
Florin Malita | 02616ea | 2020-06-25 13:33:17 -0400 | [diff] [blame] | 307 | #if defined(SK_ENABLE_SKRIVE) |
| 308 | class SkRiveSrc final : public Src { |
| 309 | public: |
| 310 | explicit SkRiveSrc(Path path); |
| 311 | |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 312 | Result draw(GrDirectContext*, SkCanvas*) const override; |
Florin Malita | 02616ea | 2020-06-25 13:33:17 -0400 | [diff] [blame] | 313 | SkISize size() const override; |
| 314 | Name name() const override; |
| 315 | bool veto(SinkFlags) const override; |
| 316 | |
| 317 | private: |
| 318 | // Generates a kTileCount x kTileCount filmstrip with evenly distributed frames. |
| 319 | static constexpr int kTileCount = 5; |
| 320 | |
| 321 | // Fit kTileCount x kTileCount frames to a 1000x1000 film strip. |
| 322 | static constexpr SkScalar kTargetSize = 1000; |
| 323 | static constexpr SkScalar kTileSize = kTargetSize / kTileCount; |
| 324 | |
| 325 | const Path fPath; |
| 326 | }; |
| 327 | #endif |
| 328 | |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 329 | #if defined(SK_XML) |
fmalita | bdf3e5c | 2016-09-17 07:26:26 -0700 | [diff] [blame] | 330 | } // namespace DM |
| 331 | |
| 332 | class SkSVGDOM; |
| 333 | |
| 334 | namespace DM { |
| 335 | |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 336 | class SVGSrc : public Src { |
| 337 | public: |
| 338 | explicit SVGSrc(Path path); |
| 339 | |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 340 | Result draw(GrDirectContext*, SkCanvas*) const override; |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 341 | SkISize size() const override; |
| 342 | Name name() const override; |
fmalita | 179d885 | 2016-08-16 14:23:29 -0700 | [diff] [blame] | 343 | bool veto(SinkFlags) const override; |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 344 | |
| 345 | private: |
fmalita | acd2f5c | 2016-11-08 07:13:45 -0800 | [diff] [blame] | 346 | Name fName; |
| 347 | sk_sp<SkSVGDOM> fDom; |
| 348 | SkScalar fScale; |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 349 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 350 | using INHERITED = Src; |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 351 | }; |
| 352 | #endif // SK_XML |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 353 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 354 | |
halcanary | 45420a9 | 2016-06-02 12:41:14 -0700 | [diff] [blame] | 355 | class MSKPSrc : public Src { |
| 356 | public: |
| 357 | explicit MSKPSrc(Path path); |
| 358 | |
| 359 | int pageCount() const override; |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 360 | Result draw(GrDirectContext*, SkCanvas* c) const override; |
| 361 | Result draw(int, GrDirectContext*, SkCanvas*) const override; |
halcanary | 45420a9 | 2016-06-02 12:41:14 -0700 | [diff] [blame] | 362 | SkISize size() const override; |
| 363 | SkISize size(int) const override; |
| 364 | Name name() const override; |
| 365 | |
| 366 | private: |
| 367 | Path fPath; |
Hal Canary | 45cde31 | 2017-04-03 16:06:42 -0400 | [diff] [blame] | 368 | mutable SkTArray<SkDocumentPage> fPages; |
halcanary | 45420a9 | 2016-06-02 12:41:14 -0700 | [diff] [blame] | 369 | }; |
| 370 | |
| 371 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 372 | |
mtklein | ad66f9b | 2015-02-13 15:11:10 -0800 | [diff] [blame] | 373 | class NullSink : public Sink { |
| 374 | public: |
| 375 | NullSink() {} |
| 376 | |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 377 | Result draw(const Src& src, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 378 | const char* fileExtension() const override { return ""; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 379 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kNull, SinkFlags::kDirect }; } |
mtklein | ad66f9b | 2015-02-13 15:11:10 -0800 | [diff] [blame] | 380 | }; |
| 381 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 382 | class GPUSink : public Sink { |
| 383 | public: |
Brian Osman | 3fdfe28 | 2019-09-09 13:46:52 -0400 | [diff] [blame] | 384 | GPUSink(const SkCommandLineConfigGpu*, const GrContextOptions&); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 385 | |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 386 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 387 | Result onDraw(const Src&, SkBitmap*, SkWStream*, SkString*, |
| 388 | const GrContextOptions& baseOptions, |
Robert Phillips | e219c7e | 2020-08-13 15:58:29 -0400 | [diff] [blame] | 389 | std::function<void(GrDirectContext*)> initContext = nullptr) const; |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 390 | |
Brian Salomon | b07fd4d | 2018-03-09 13:17:30 -0500 | [diff] [blame] | 391 | sk_gpu_test::GrContextFactory::ContextType contextType() const { return fContextType; } |
Robert Phillips | 3c1efd4 | 2020-02-13 15:51:59 -0500 | [diff] [blame] | 392 | const sk_gpu_test::GrContextFactory::ContextOverrides& contextOverrides() const { |
Brian Salomon | b07fd4d | 2018-03-09 13:17:30 -0500 | [diff] [blame] | 393 | return fContextOverrides; |
| 394 | } |
| 395 | SkCommandLineConfigGpu::SurfType surfType() const { return fSurfType; } |
Brian Osman | 3fdfe28 | 2019-09-09 13:46:52 -0400 | [diff] [blame] | 396 | bool serial() const override { return true; } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 397 | const char* fileExtension() const override { return "png"; } |
Brian Salomon | bd7c551 | 2017-03-07 09:08:36 -0500 | [diff] [blame] | 398 | SinkFlags flags() const override { |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 399 | SinkFlags::Multisampled ms = fSampleCount > 1 ? SinkFlags::kMultisampled |
Brian Salomon | fd171ed | 2017-03-08 11:38:45 -0500 | [diff] [blame] | 400 | : SinkFlags::kNotMultisampled; |
| 401 | return SinkFlags{ SinkFlags::kGPU, SinkFlags::kDirect, ms }; |
Brian Salomon | bd7c551 | 2017-03-07 09:08:36 -0500 | [diff] [blame] | 402 | } |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 403 | const GrContextOptions& baseContextOptions() const { return fBaseContextOptions; } |
Tyler Denniston | 45f94f8 | 2020-02-04 16:09:08 -0500 | [diff] [blame] | 404 | SkColorInfo colorInfo() const override { |
| 405 | return SkColorInfo(fColorType, fAlphaType, fColorSpace); |
| 406 | } |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 407 | |
Robert Phillips | 3c1efd4 | 2020-02-13 15:51:59 -0500 | [diff] [blame] | 408 | protected: |
Brian Salomon | f9b0042 | 2020-10-08 16:00:14 -0400 | [diff] [blame] | 409 | sk_sp<SkSurface> createDstSurface(GrDirectContext*, SkISize size) const; |
Robert Phillips | 3c1efd4 | 2020-02-13 15:51:59 -0500 | [diff] [blame] | 410 | bool readBack(SkSurface*, SkBitmap* dst) const; |
| 411 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 412 | private: |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 413 | sk_gpu_test::GrContextFactory::ContextType fContextType; |
| 414 | sk_gpu_test::GrContextFactory::ContextOverrides fContextOverrides; |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 415 | SkCommandLineConfigGpu::SurfType fSurfType; |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 416 | int fSampleCount; |
Chris Dalton | 180b4a1 | 2021-03-16 20:49:15 -0600 | [diff] [blame] | 417 | uint32_t fSurfaceFlags; |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 418 | SkColorType fColorType; |
Brian Salomon | ce5ee60 | 2017-07-17 11:31:31 -0400 | [diff] [blame] | 419 | SkAlphaType fAlphaType; |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 420 | sk_sp<SkColorSpace> fColorSpace; |
Brian Osman | f21aa04 | 2017-08-21 16:48:46 -0400 | [diff] [blame] | 421 | GrContextOptions fBaseContextOptions; |
Brian Osman | 9c31047 | 2019-06-27 16:43:27 -0400 | [diff] [blame] | 422 | sk_gpu_test::MemoryCache fMemoryCache; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 423 | }; |
| 424 | |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 425 | class GPUThreadTestingSink : public GPUSink { |
| 426 | public: |
Brian Osman | 3fdfe28 | 2019-09-09 13:46:52 -0400 | [diff] [blame] | 427 | GPUThreadTestingSink(const SkCommandLineConfigGpu*, const GrContextOptions&); |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 428 | |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 429 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 430 | |
Brian Osman | f1942de | 2017-08-30 14:50:22 -0400 | [diff] [blame] | 431 | const char* fileExtension() const override { |
| 432 | // Suppress writing out results from this config - we just want to do our matching test |
| 433 | return nullptr; |
| 434 | } |
| 435 | |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 436 | private: |
| 437 | std::unique_ptr<SkExecutor> fExecutor; |
| 438 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 439 | using INHERITED = GPUSink; |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 440 | }; |
| 441 | |
Brian Salomon | 00a5eb8 | 2018-07-11 15:32:05 -0400 | [diff] [blame] | 442 | class GPUPersistentCacheTestingSink : public GPUSink { |
| 443 | public: |
Brian Osman | 3fdfe28 | 2019-09-09 13:46:52 -0400 | [diff] [blame] | 444 | GPUPersistentCacheTestingSink(const SkCommandLineConfigGpu*, const GrContextOptions&); |
Brian Salomon | 00a5eb8 | 2018-07-11 15:32:05 -0400 | [diff] [blame] | 445 | |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 446 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
Brian Salomon | 00a5eb8 | 2018-07-11 15:32:05 -0400 | [diff] [blame] | 447 | |
| 448 | const char* fileExtension() const override { |
| 449 | // Suppress writing out results from this config - we just want to do our matching test |
| 450 | return nullptr; |
| 451 | } |
| 452 | |
| 453 | private: |
Brian Osman | f71b070 | 2019-04-03 13:04:16 -0400 | [diff] [blame] | 454 | int fCacheType; |
| 455 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 456 | using INHERITED = GPUSink; |
Brian Salomon | 00a5eb8 | 2018-07-11 15:32:05 -0400 | [diff] [blame] | 457 | }; |
| 458 | |
Brian Osman | ed58e00 | 2019-09-06 14:42:43 -0400 | [diff] [blame] | 459 | class GPUPrecompileTestingSink : public GPUSink { |
| 460 | public: |
Brian Osman | 3fdfe28 | 2019-09-09 13:46:52 -0400 | [diff] [blame] | 461 | GPUPrecompileTestingSink(const SkCommandLineConfigGpu*, const GrContextOptions&); |
Brian Osman | ed58e00 | 2019-09-06 14:42:43 -0400 | [diff] [blame] | 462 | |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 463 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
Brian Osman | ed58e00 | 2019-09-06 14:42:43 -0400 | [diff] [blame] | 464 | |
| 465 | const char* fileExtension() const override { |
| 466 | // Suppress writing out results from this config - we just want to do our matching test |
| 467 | return nullptr; |
| 468 | } |
| 469 | |
| 470 | private: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 471 | using INHERITED = GPUSink; |
Brian Osman | ed58e00 | 2019-09-06 14:42:43 -0400 | [diff] [blame] | 472 | }; |
| 473 | |
Robert Phillips | 762cb4e | 2020-06-15 13:12:32 -0400 | [diff] [blame] | 474 | // This sink attempts to emulate Chrome's OOP-R behavior. It: |
| 475 | // doesn't use promise images |
| 476 | // uses only a single thread for both DDL creation & drawing |
| 477 | class GPUOOPRSink : public GPUSink { |
| 478 | public: |
| 479 | GPUOOPRSink(const SkCommandLineConfigGpu*, const GrContextOptions&); |
| 480 | |
| 481 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 482 | |
| 483 | private: |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 484 | Result ooprDraw(const Src&, sk_sp<SkSurface> dstSurface, GrDirectContext*) const; |
Robert Phillips | 762cb4e | 2020-06-15 13:12:32 -0400 | [diff] [blame] | 485 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 486 | using INHERITED = GPUSink; |
Robert Phillips | 762cb4e | 2020-06-15 13:12:32 -0400 | [diff] [blame] | 487 | }; |
| 488 | |
Robert Phillips | 291f340 | 2020-02-19 14:14:47 -0500 | [diff] [blame] | 489 | // This sink attempts to better simulate the Chrome DDL use-case. It: |
| 490 | // creates the DDLs on separate recording threads |
| 491 | // performs all the GPU work on a separate GPU thread |
| 492 | // In the future this should be expanded to: |
| 493 | // upload on a utility thread w/ access to a shared context |
| 494 | // compile the programs on the utility thread |
| 495 | // perform fine grained scheduling of gpu tasks based on their image and program prerequisites |
| 496 | // create a single "compositing" DDL that is replayed last |
| 497 | class GPUDDLSink : public GPUSink { |
| 498 | public: |
| 499 | GPUDDLSink(const SkCommandLineConfigGpu*, const GrContextOptions&); |
| 500 | |
| 501 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 502 | |
| 503 | private: |
| 504 | Result ddlDraw(const Src&, |
| 505 | sk_sp<SkSurface> dstSurface, |
| 506 | SkTaskGroup* recordingTaskGroup, |
| 507 | SkTaskGroup* gpuTaskGroup, |
Robert Phillips | 19f466d | 2020-02-26 10:27:07 -0500 | [diff] [blame] | 508 | sk_gpu_test::TestContext* gpuTestCtx, |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 509 | GrDirectContext* gpuThreadCtx) const; |
Robert Phillips | 291f340 | 2020-02-19 14:14:47 -0500 | [diff] [blame] | 510 | |
Robert Phillips | 762cb4e | 2020-06-15 13:12:32 -0400 | [diff] [blame] | 511 | std::unique_ptr<SkExecutor> fRecordingExecutor; |
| 512 | std::unique_ptr<SkExecutor> fGPUExecutor; |
Robert Phillips | 291f340 | 2020-02-19 14:14:47 -0500 | [diff] [blame] | 513 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 514 | using INHERITED = GPUSink; |
Robert Phillips | 291f340 | 2020-02-19 14:14:47 -0500 | [diff] [blame] | 515 | }; |
| 516 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 517 | class PDFSink : public Sink { |
| 518 | public: |
Hal Canary | c7d295e | 2017-07-20 15:36:00 -0400 | [diff] [blame] | 519 | PDFSink(bool pdfa, SkScalar rasterDpi) : fPDFA(pdfa), fRasterDpi(rasterDpi) {} |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 520 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 521 | const char* fileExtension() const override { return "pdf"; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 522 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 523 | bool fPDFA; |
Hal Canary | c7d295e | 2017-07-20 15:36:00 -0400 | [diff] [blame] | 524 | SkScalar fRasterDpi; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 525 | }; |
| 526 | |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 527 | class XPSSink : public Sink { |
| 528 | public: |
| 529 | XPSSink(); |
| 530 | |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 531 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 532 | const char* fileExtension() const override { return "xps"; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 533 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 534 | }; |
| 535 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 536 | class RasterSink : public Sink { |
| 537 | public: |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 538 | explicit RasterSink(SkColorType, sk_sp<SkColorSpace> = nullptr); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 539 | |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 540 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 541 | const char* fileExtension() const override { return "png"; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 542 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kRaster, SinkFlags::kDirect }; } |
Yuqian Li | b8b6253 | 2018-02-23 14:13:36 +0800 | [diff] [blame] | 543 | |
Mike Klein | 48b6490 | 2018-07-25 13:28:44 -0400 | [diff] [blame] | 544 | private: |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 545 | SkColorType fColorType; |
| 546 | sk_sp<SkColorSpace> fColorSpace; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 547 | }; |
| 548 | |
Yuqian Li | b8b6253 | 2018-02-23 14:13:36 +0800 | [diff] [blame] | 549 | class ThreadedSink : public RasterSink { |
| 550 | public: |
| 551 | explicit ThreadedSink(SkColorType, sk_sp<SkColorSpace> = nullptr); |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 552 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
Yuqian Li | b8b6253 | 2018-02-23 14:13:36 +0800 | [diff] [blame] | 553 | }; |
| 554 | |
mtklein | 9c3f17d | 2015-01-28 11:35:18 -0800 | [diff] [blame] | 555 | class SKPSink : public Sink { |
| 556 | public: |
| 557 | SKPSink(); |
| 558 | |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 559 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 560 | const char* fileExtension() const override { return "skp"; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 561 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
mtklein | 9c3f17d | 2015-01-28 11:35:18 -0800 | [diff] [blame] | 562 | }; |
| 563 | |
Hal Canary | 85c7fe8 | 2016-10-25 10:33:27 -0400 | [diff] [blame] | 564 | class DebugSink : public Sink { |
| 565 | public: |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 566 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
Hal Canary | 85c7fe8 | 2016-10-25 10:33:27 -0400 | [diff] [blame] | 567 | const char* fileExtension() const override { return "json"; } |
| 568 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
| 569 | }; |
| 570 | |
mtklein | 8a4527e | 2015-01-31 20:00:58 -0800 | [diff] [blame] | 571 | class SVGSink : public Sink { |
| 572 | public: |
Bryce Thomas | 95a7b76 | 2018-03-02 13:54:21 -0800 | [diff] [blame] | 573 | SVGSink(int pageIndex = 0); |
mtklein | 8a4527e | 2015-01-31 20:00:58 -0800 | [diff] [blame] | 574 | |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 575 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 576 | const char* fileExtension() const override { return "svg"; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 577 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
Bryce Thomas | 95a7b76 | 2018-03-02 13:54:21 -0800 | [diff] [blame] | 578 | |
| 579 | private: |
| 580 | int fPageIndex; |
mtklein | 8a4527e | 2015-01-31 20:00:58 -0800 | [diff] [blame] | 581 | }; |
| 582 | |
| 583 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 584 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 585 | |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 586 | class Via : public Sink { |
| 587 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 588 | explicit Via(Sink* sink) : fSink(sink) {} |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 589 | const char* fileExtension() const override { return fSink->fileExtension(); } |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 590 | bool serial() const override { return fSink->serial(); } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 591 | SinkFlags flags() const override { |
| 592 | SinkFlags flags = fSink->flags(); |
| 593 | flags.approach = SinkFlags::kIndirect; |
| 594 | return flags; |
| 595 | } |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 596 | protected: |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 597 | std::unique_ptr<Sink> fSink; |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 598 | }; |
| 599 | |
| 600 | class ViaMatrix : public Via { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 601 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 602 | ViaMatrix(SkMatrix, Sink*); |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 603 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 604 | private: |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 605 | const SkMatrix fMatrix; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 606 | }; |
| 607 | |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 608 | class ViaUpright : public Via { |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 609 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 610 | ViaUpright(SkMatrix, Sink*); |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 611 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 612 | private: |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 613 | const SkMatrix fMatrix; |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 614 | }; |
| 615 | |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 616 | class ViaSerialization : public Via { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 617 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 618 | explicit ViaSerialization(Sink* sink) : Via(sink) {} |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 619 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 620 | }; |
| 621 | |
mtklein | 4a34ecb | 2016-01-08 10:19:35 -0800 | [diff] [blame] | 622 | class ViaPicture : public Via { |
| 623 | public: |
| 624 | explicit ViaPicture(Sink* sink) : Via(sink) {} |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 625 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 4a34ecb | 2016-01-08 10:19:35 -0800 | [diff] [blame] | 626 | }; |
| 627 | |
John Stiles | 65ec198 | 2021-07-20 12:53:54 -0400 | [diff] [blame] | 628 | class ViaRuntimeBlend : public Via { |
| 629 | public: |
| 630 | explicit ViaRuntimeBlend(Sink* sink) : Via(sink) {} |
| 631 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 632 | }; |
| 633 | |
Mike Reed | f67c459 | 2017-02-17 17:06:11 -0500 | [diff] [blame] | 634 | class ViaSVG : public Via { |
| 635 | public: |
| 636 | explicit ViaSVG(Sink* sink) : Via(sink) {} |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 637 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
Mike Reed | f67c459 | 2017-02-17 17:06:11 -0500 | [diff] [blame] | 638 | }; |
| 639 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 640 | } // namespace DM |
| 641 | |
| 642 | #endif//DMSrcSink_DEFINED |