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 | |
Brian Osman | 54ef97c | 2021-08-11 17:06:42 -0400 | [diff] [blame] | 116 | // Override the color space of this Sink, after creation |
| 117 | virtual void setColorSpace(sk_sp<SkColorSpace>) {} |
| 118 | |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 119 | // Force Tasks using this Sink to run on the main thread? |
| 120 | virtual bool serial() const { return false; } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 121 | |
| 122 | // File extension for the content draw() outputs, e.g. "png", "pdf". |
| 123 | virtual const char* fileExtension() const = 0; |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 124 | |
| 125 | virtual SinkFlags flags() const = 0; |
Tyler Denniston | 45f94f8 | 2020-02-04 16:09:08 -0500 | [diff] [blame] | 126 | |
| 127 | /** Returns the color type and space used by the sink. */ |
| 128 | virtual SkColorInfo colorInfo() const { return SkColorInfo(); } |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 129 | }; |
| 130 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 131 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 132 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 133 | class GMSrc : public Src { |
| 134 | public: |
Hal Canary | 972eba3 | 2018-07-30 17:07:07 -0400 | [diff] [blame] | 135 | explicit GMSrc(skiagm::GMFactory); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 136 | |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 137 | Result draw(GrDirectContext*, SkCanvas*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 138 | SkISize size() const override; |
| 139 | Name name() const override; |
bsalomon | 4ee6bd8 | 2015-05-27 13:23:23 -0700 | [diff] [blame] | 140 | void modifyGrContextOptions(GrContextOptions* options) const override; |
| 141 | |
Tyler Denniston | 45f94f8 | 2020-02-04 16:09:08 -0500 | [diff] [blame] | 142 | std::unique_ptr<skiagm::verifiers::VerifierList> getVerifiers() const override; |
| 143 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 144 | private: |
Hal Canary | 972eba3 | 2018-07-30 17:07:07 -0400 | [diff] [blame] | 145 | skiagm::GMFactory fFactory; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 146 | }; |
| 147 | |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 148 | class CodecSrc : public Src { |
| 149 | public: |
scroggo | 9c59ebc | 2015-03-25 13:48:49 -0700 | [diff] [blame] | 150 | enum Mode { |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 151 | kCodec_Mode, |
msarett | bb25b53 | 2016-01-13 09:31:39 -0800 | [diff] [blame] | 152 | // 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, |
scroggo | 9c59ebc | 2015-03-25 13:48:49 -0700 | [diff] [blame] | 156 | kScanline_Mode, |
msarett | 0a24297 | 2015-06-11 14:27:27 -0700 | [diff] [blame] | 157 | kStripe_Mode, // Tests the skipping of scanlines |
msarett | 91c22b2 | 2016-02-22 12:27:46 -0800 | [diff] [blame] | 158 | kCroppedScanline_Mode, // Tests (jpeg) cropped scanline optimization |
scroggo | b636b45 | 2015-07-22 07:16:20 -0700 | [diff] [blame] | 159 | kSubset_Mode, // For codecs that support subsets directly. |
scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame] | 160 | kAnimated_Mode, // For codecs that support animation. |
scroggo | 9c59ebc | 2015-03-25 13:48:49 -0700 | [diff] [blame] | 161 | }; |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 162 | enum DstColorType { |
| 163 | kGetFromCanvas_DstColorType, |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 164 | kGrayscale_Always_DstColorType, |
msarett | 34e0ec4 | 2016-04-22 16:27:24 -0700 | [diff] [blame] | 165 | kNonNative8888_Always_DstColorType, |
msarett | 438b2ad | 2015-04-09 12:43:10 -0700 | [diff] [blame] | 166 | }; |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 167 | CodecSrc(Path, Mode, DstColorType, SkAlphaType, float); |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 168 | |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 169 | Result draw(GrDirectContext*, SkCanvas*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 170 | SkISize size() const override; |
| 171 | Name name() const override; |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 172 | bool veto(SinkFlags) const override; |
scroggo | 3ac66e9 | 2016-02-08 15:09:48 -0800 | [diff] [blame] | 173 | bool serial() const override { return fRunSerially; } |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 174 | private: |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 175 | Path fPath; |
| 176 | Mode fMode; |
| 177 | DstColorType fDstColorType; |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 178 | SkAlphaType fDstAlphaType; |
msarett | 9e707a0 | 2015-09-01 14:57:57 -0700 | [diff] [blame] | 179 | float fScale; |
scroggo | 3ac66e9 | 2016-02-08 15:09:48 -0800 | [diff] [blame] | 180 | bool fRunSerially; |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 181 | }; |
| 182 | |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 183 | class AndroidCodecSrc : public Src { |
| 184 | public: |
scroggo | f8dc9df | 2016-05-16 09:04:13 -0700 | [diff] [blame] | 185 | AndroidCodecSrc(Path, CodecSrc::DstColorType, SkAlphaType, int sampleSize); |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 186 | |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 187 | Result draw(GrDirectContext*, SkCanvas*) const override; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 188 | SkISize size() const override; |
| 189 | Name name() const override; |
| 190 | bool veto(SinkFlags) const override; |
scroggo | 3ac66e9 | 2016-02-08 15:09:48 -0800 | [diff] [blame] | 191 | bool serial() const override { return fRunSerially; } |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 192 | private: |
| 193 | Path fPath; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 194 | CodecSrc::DstColorType fDstColorType; |
scroggo | c5560be | 2016-02-03 09:42:42 -0800 | [diff] [blame] | 195 | SkAlphaType fDstAlphaType; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 196 | int fSampleSize; |
scroggo | 3ac66e9 | 2016-02-08 15:09:48 -0800 | [diff] [blame] | 197 | bool fRunSerially; |
msarett | 3d9d7a7 | 2015-10-21 10:27:10 -0700 | [diff] [blame] | 198 | }; |
| 199 | |
Leon Scroggins III | 87caae6 | 2020-05-04 10:02:45 -0400 | [diff] [blame] | 200 | #ifdef SK_ENABLE_ANDROID_UTILS |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 201 | // Allows for testing of various implementations of Android's BitmapRegionDecoder |
| 202 | class BRDSrc : public Src { |
| 203 | public: |
| 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 | |
msarett | d1227a7 | 2016-05-18 06:23:57 -0700 | [diff] [blame] | 214 | BRDSrc(Path, Mode, CodecSrc::DstColorType, uint32_t); |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 215 | |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 216 | Result draw(GrDirectContext*, SkCanvas*) const override; |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 217 | SkISize size() const override; |
| 218 | Name name() const override; |
| 219 | bool veto(SinkFlags) const override; |
| 220 | private: |
| 221 | Path fPath; |
msarett | a5783ae | 2015-09-08 15:35:32 -0700 | [diff] [blame] | 222 | Mode fMode; |
| 223 | CodecSrc::DstColorType fDstColorType; |
| 224 | uint32_t fSampleSize; |
| 225 | }; |
Leon Scroggins III | 87caae6 | 2020-05-04 10:02:45 -0400 | [diff] [blame] | 226 | #endif |
scroggo | 9b77ddd | 2015-03-19 06:03:39 -0700 | [diff] [blame] | 227 | |
msarett | 1897631 | 2016-03-09 14:20:58 -0800 | [diff] [blame] | 228 | class ImageGenSrc : public Src { |
| 229 | public: |
| 230 | enum Mode { |
| 231 | kCodec_Mode, // Use CodecImageGenerator |
| 232 | kPlatform_Mode, // Uses CG or WIC |
| 233 | }; |
| 234 | ImageGenSrc(Path, Mode, SkAlphaType, bool); |
| 235 | |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 236 | Result draw(GrDirectContext*, SkCanvas*) const override; |
msarett | 1897631 | 2016-03-09 14:20:58 -0800 | [diff] [blame] | 237 | SkISize size() const override; |
| 238 | Name name() const override; |
| 239 | bool veto(SinkFlags) const override; |
| 240 | bool serial() const override { return fRunSerially; } |
| 241 | private: |
| 242 | Path fPath; |
| 243 | Mode fMode; |
| 244 | SkAlphaType fDstAlphaType; |
| 245 | bool fIsGpu; |
| 246 | bool fRunSerially; |
| 247 | }; |
| 248 | |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 249 | class ColorCodecSrc : public Src { |
| 250 | public: |
Mike Klein | 0d5d142 | 2019-03-06 10:56:04 -0600 | [diff] [blame] | 251 | ColorCodecSrc(Path, bool decode_to_dst); |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 252 | |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 253 | Result draw(GrDirectContext*, SkCanvas*) const override; |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 254 | SkISize size() const override; |
| 255 | Name name() const override; |
| 256 | bool veto(SinkFlags) const override; |
| 257 | private: |
Mike Klein | 0d5d142 | 2019-03-06 10:56:04 -0600 | [diff] [blame] | 258 | Path fPath; |
| 259 | bool fDecodeToDst; |
msarett | 69deca8 | 2016-04-29 09:38:40 -0700 | [diff] [blame] | 260 | }; |
| 261 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 262 | class SKPSrc : public Src { |
| 263 | public: |
mtklein | 8d17a13 | 2015-01-30 11:42:31 -0800 | [diff] [blame] | 264 | explicit SKPSrc(Path path); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 265 | |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 266 | Result draw(GrDirectContext*, SkCanvas*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 267 | SkISize size() const override; |
| 268 | Name name() const override; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 269 | private: |
mtklein | 8d17a13 | 2015-01-30 11:42:31 -0800 | [diff] [blame] | 270 | Path fPath; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 271 | }; |
| 272 | |
Chris Dalton | 184c37e | 2018-09-28 11:27:39 -0600 | [diff] [blame] | 273 | // 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. |
| 276 | class BisectSrc : public SKPSrc { |
| 277 | public: |
| 278 | explicit BisectSrc(Path path, const char* trail); |
| 279 | |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 280 | Result draw(GrDirectContext*, SkCanvas*) const override; |
Chris Dalton | 184c37e | 2018-09-28 11:27:39 -0600 | [diff] [blame] | 281 | |
| 282 | private: |
| 283 | SkString fTrail; |
| 284 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 285 | using INHERITED = SKPSrc; |
Chris Dalton | 184c37e | 2018-09-28 11:27:39 -0600 | [diff] [blame] | 286 | }; |
| 287 | |
Florin Malita | 87ccf33 | 2018-05-04 12:23:24 -0400 | [diff] [blame] | 288 | #if defined(SK_ENABLE_SKOTTIE) |
Florin Malita | 54f65c4 | 2018-01-16 17:04:30 -0500 | [diff] [blame] | 289 | class SkottieSrc final : public Src { |
Florin Malita | fc043dc | 2017-12-31 11:08:42 -0500 | [diff] [blame] | 290 | public: |
Florin Malita | 54f65c4 | 2018-01-16 17:04:30 -0500 | [diff] [blame] | 291 | explicit SkottieSrc(Path path); |
Florin Malita | fc043dc | 2017-12-31 11:08:42 -0500 | [diff] [blame] | 292 | |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 293 | Result draw(GrDirectContext*, SkCanvas*) const override; |
Florin Malita | fc043dc | 2017-12-31 11:08:42 -0500 | [diff] [blame] | 294 | SkISize size() const override; |
| 295 | Name name() const override; |
| 296 | bool veto(SinkFlags) const override; |
| 297 | |
| 298 | private: |
| 299 | // Generates a kTileCount x kTileCount filmstrip with evenly distributed frames. |
Florin Malita | 1022f74 | 2018-02-23 11:10:22 -0500 | [diff] [blame] | 300 | static constexpr int kTileCount = 5; |
Florin Malita | fc043dc | 2017-12-31 11:08:42 -0500 | [diff] [blame] | 301 | |
Florin Malita | 9f7d4cd | 2018-07-30 15:49:20 -0400 | [diff] [blame] | 302 | // 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 Malita | fc043dc | 2017-12-31 11:08:42 -0500 | [diff] [blame] | 307 | }; |
Florin Malita | 124d5af | 2017-12-31 17:02:26 -0500 | [diff] [blame] | 308 | #endif |
Florin Malita | fc043dc | 2017-12-31 11:08:42 -0500 | [diff] [blame] | 309 | |
Florin Malita | 02616ea | 2020-06-25 13:33:17 -0400 | [diff] [blame] | 310 | #if defined(SK_ENABLE_SKRIVE) |
| 311 | class SkRiveSrc final : public Src { |
| 312 | public: |
| 313 | explicit SkRiveSrc(Path path); |
| 314 | |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 315 | Result draw(GrDirectContext*, SkCanvas*) const override; |
Florin Malita | 02616ea | 2020-06-25 13:33:17 -0400 | [diff] [blame] | 316 | SkISize size() const override; |
| 317 | Name name() const override; |
| 318 | bool veto(SinkFlags) const override; |
| 319 | |
| 320 | private: |
| 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 Phillips | 2af13c1 | 2021-09-01 16:47:01 +0000 | [diff] [blame] | 332 | #if defined(SK_ENABLE_SVG) |
fmalita | bdf3e5c | 2016-09-17 07:26:26 -0700 | [diff] [blame] | 333 | } // namespace DM |
| 334 | |
| 335 | class SkSVGDOM; |
| 336 | |
| 337 | namespace DM { |
| 338 | |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 339 | class SVGSrc : public Src { |
| 340 | public: |
| 341 | explicit SVGSrc(Path path); |
| 342 | |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 343 | Result draw(GrDirectContext*, SkCanvas*) const override; |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 344 | SkISize size() const override; |
| 345 | Name name() const override; |
fmalita | 179d885 | 2016-08-16 14:23:29 -0700 | [diff] [blame] | 346 | bool veto(SinkFlags) const override; |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 347 | |
| 348 | private: |
fmalita | acd2f5c | 2016-11-08 07:13:45 -0800 | [diff] [blame] | 349 | Name fName; |
| 350 | sk_sp<SkSVGDOM> fDom; |
| 351 | SkScalar fScale; |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 352 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 353 | using INHERITED = Src; |
fmalita | a2b9fdf | 2016-08-03 19:53:36 -0700 | [diff] [blame] | 354 | }; |
Robert Phillips | 2af13c1 | 2021-09-01 16:47:01 +0000 | [diff] [blame] | 355 | #endif // SK_ENABLE_SVG |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 356 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 357 | |
halcanary | 45420a9 | 2016-06-02 12:41:14 -0700 | [diff] [blame] | 358 | class MSKPSrc : public Src { |
| 359 | public: |
| 360 | explicit MSKPSrc(Path path); |
| 361 | |
| 362 | int pageCount() const override; |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 363 | Result draw(GrDirectContext*, SkCanvas* c) const override; |
| 364 | Result draw(int, GrDirectContext*, SkCanvas*) const override; |
halcanary | 45420a9 | 2016-06-02 12:41:14 -0700 | [diff] [blame] | 365 | SkISize size() const override; |
| 366 | SkISize size(int) const override; |
| 367 | Name name() const override; |
| 368 | |
| 369 | private: |
| 370 | Path fPath; |
Hal Canary | 45cde31 | 2017-04-03 16:06:42 -0400 | [diff] [blame] | 371 | mutable SkTArray<SkDocumentPage> fPages; |
halcanary | 45420a9 | 2016-06-02 12:41:14 -0700 | [diff] [blame] | 372 | }; |
| 373 | |
| 374 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 375 | |
mtklein | ad66f9b | 2015-02-13 15:11:10 -0800 | [diff] [blame] | 376 | class NullSink : public Sink { |
| 377 | public: |
| 378 | NullSink() {} |
| 379 | |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 380 | Result draw(const Src& src, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 381 | const char* fileExtension() const override { return ""; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 382 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kNull, SinkFlags::kDirect }; } |
mtklein | ad66f9b | 2015-02-13 15:11:10 -0800 | [diff] [blame] | 383 | }; |
| 384 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 385 | class GPUSink : public Sink { |
| 386 | public: |
Brian Osman | 3fdfe28 | 2019-09-09 13:46:52 -0400 | [diff] [blame] | 387 | GPUSink(const SkCommandLineConfigGpu*, const GrContextOptions&); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 388 | |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 389 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 390 | Result onDraw(const Src&, SkBitmap*, SkWStream*, SkString*, |
| 391 | const GrContextOptions& baseOptions, |
Robert Phillips | e219c7e | 2020-08-13 15:58:29 -0400 | [diff] [blame] | 392 | std::function<void(GrDirectContext*)> initContext = nullptr) const; |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 393 | |
Brian Salomon | b07fd4d | 2018-03-09 13:17:30 -0500 | [diff] [blame] | 394 | sk_gpu_test::GrContextFactory::ContextType contextType() const { return fContextType; } |
Robert Phillips | 3c1efd4 | 2020-02-13 15:51:59 -0500 | [diff] [blame] | 395 | const sk_gpu_test::GrContextFactory::ContextOverrides& contextOverrides() const { |
Brian Salomon | b07fd4d | 2018-03-09 13:17:30 -0500 | [diff] [blame] | 396 | return fContextOverrides; |
| 397 | } |
| 398 | SkCommandLineConfigGpu::SurfType surfType() const { return fSurfType; } |
Brian Osman | 3fdfe28 | 2019-09-09 13:46:52 -0400 | [diff] [blame] | 399 | bool serial() const override { return true; } |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 400 | const char* fileExtension() const override { return "png"; } |
Brian Salomon | bd7c551 | 2017-03-07 09:08:36 -0500 | [diff] [blame] | 401 | SinkFlags flags() const override { |
Brian Salomon | bdecacf | 2018-02-02 20:32:49 -0500 | [diff] [blame] | 402 | SinkFlags::Multisampled ms = fSampleCount > 1 ? SinkFlags::kMultisampled |
Brian Salomon | fd171ed | 2017-03-08 11:38:45 -0500 | [diff] [blame] | 403 | : SinkFlags::kNotMultisampled; |
| 404 | return SinkFlags{ SinkFlags::kGPU, SinkFlags::kDirect, ms }; |
Brian Salomon | bd7c551 | 2017-03-07 09:08:36 -0500 | [diff] [blame] | 405 | } |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 406 | const GrContextOptions& baseContextOptions() const { return fBaseContextOptions; } |
Brian Osman | 54ef97c | 2021-08-11 17:06:42 -0400 | [diff] [blame] | 407 | void setColorSpace(sk_sp<SkColorSpace> colorSpace) override { fColorSpace = colorSpace; } |
Tyler Denniston | 45f94f8 | 2020-02-04 16:09:08 -0500 | [diff] [blame] | 408 | SkColorInfo colorInfo() const override { |
| 409 | return SkColorInfo(fColorType, fAlphaType, fColorSpace); |
| 410 | } |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 411 | |
Robert Phillips | 3c1efd4 | 2020-02-13 15:51:59 -0500 | [diff] [blame] | 412 | protected: |
Brian Salomon | f9b0042 | 2020-10-08 16:00:14 -0400 | [diff] [blame] | 413 | sk_sp<SkSurface> createDstSurface(GrDirectContext*, SkISize size) const; |
Robert Phillips | 3c1efd4 | 2020-02-13 15:51:59 -0500 | [diff] [blame] | 414 | bool readBack(SkSurface*, SkBitmap* dst) const; |
| 415 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 416 | private: |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 417 | sk_gpu_test::GrContextFactory::ContextType fContextType; |
| 418 | sk_gpu_test::GrContextFactory::ContextOverrides fContextOverrides; |
Brian Salomon | f865b05 | 2018-03-09 09:01:53 -0500 | [diff] [blame] | 419 | SkCommandLineConfigGpu::SurfType fSurfType; |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 420 | int fSampleCount; |
Chris Dalton | 180b4a1 | 2021-03-16 20:49:15 -0600 | [diff] [blame] | 421 | uint32_t fSurfaceFlags; |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 422 | SkColorType fColorType; |
Brian Salomon | ce5ee60 | 2017-07-17 11:31:31 -0400 | [diff] [blame] | 423 | SkAlphaType fAlphaType; |
csmartdalton | e812d49 | 2017-02-21 12:36:05 -0700 | [diff] [blame] | 424 | sk_sp<SkColorSpace> fColorSpace; |
Brian Osman | f21aa04 | 2017-08-21 16:48:46 -0400 | [diff] [blame] | 425 | GrContextOptions fBaseContextOptions; |
Brian Osman | 9c31047 | 2019-06-27 16:43:27 -0400 | [diff] [blame] | 426 | sk_gpu_test::MemoryCache fMemoryCache; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 427 | }; |
| 428 | |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 429 | class GPUThreadTestingSink : public GPUSink { |
| 430 | public: |
Brian Osman | 3fdfe28 | 2019-09-09 13:46:52 -0400 | [diff] [blame] | 431 | GPUThreadTestingSink(const SkCommandLineConfigGpu*, const GrContextOptions&); |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 432 | |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 433 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 434 | |
Brian Osman | f1942de | 2017-08-30 14:50:22 -0400 | [diff] [blame] | 435 | 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 Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 440 | private: |
| 441 | std::unique_ptr<SkExecutor> fExecutor; |
| 442 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 443 | using INHERITED = GPUSink; |
Brian Osman | f981066 | 2017-08-30 10:02:10 -0400 | [diff] [blame] | 444 | }; |
| 445 | |
Brian Salomon | 00a5eb8 | 2018-07-11 15:32:05 -0400 | [diff] [blame] | 446 | class GPUPersistentCacheTestingSink : public GPUSink { |
| 447 | public: |
Brian Osman | 3fdfe28 | 2019-09-09 13:46:52 -0400 | [diff] [blame] | 448 | GPUPersistentCacheTestingSink(const SkCommandLineConfigGpu*, const GrContextOptions&); |
Brian Salomon | 00a5eb8 | 2018-07-11 15:32:05 -0400 | [diff] [blame] | 449 | |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 450 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
Brian Salomon | 00a5eb8 | 2018-07-11 15:32:05 -0400 | [diff] [blame] | 451 | |
| 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 | |
| 457 | private: |
Brian Osman | f71b070 | 2019-04-03 13:04:16 -0400 | [diff] [blame] | 458 | int fCacheType; |
| 459 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 460 | using INHERITED = GPUSink; |
Brian Salomon | 00a5eb8 | 2018-07-11 15:32:05 -0400 | [diff] [blame] | 461 | }; |
| 462 | |
Brian Osman | ed58e00 | 2019-09-06 14:42:43 -0400 | [diff] [blame] | 463 | class GPUPrecompileTestingSink : public GPUSink { |
| 464 | public: |
Brian Osman | 3fdfe28 | 2019-09-09 13:46:52 -0400 | [diff] [blame] | 465 | GPUPrecompileTestingSink(const SkCommandLineConfigGpu*, const GrContextOptions&); |
Brian Osman | ed58e00 | 2019-09-06 14:42:43 -0400 | [diff] [blame] | 466 | |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 467 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
Brian Osman | ed58e00 | 2019-09-06 14:42:43 -0400 | [diff] [blame] | 468 | |
| 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 | |
| 474 | private: |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 475 | using INHERITED = GPUSink; |
Brian Osman | ed58e00 | 2019-09-06 14:42:43 -0400 | [diff] [blame] | 476 | }; |
| 477 | |
Robert Phillips | 762cb4e | 2020-06-15 13:12:32 -0400 | [diff] [blame] | 478 | // 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 |
| 481 | class GPUOOPRSink : public GPUSink { |
| 482 | public: |
| 483 | GPUOOPRSink(const SkCommandLineConfigGpu*, const GrContextOptions&); |
| 484 | |
| 485 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 486 | |
| 487 | private: |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 488 | Result ooprDraw(const Src&, sk_sp<SkSurface> dstSurface, GrDirectContext*) const; |
Robert Phillips | 762cb4e | 2020-06-15 13:12:32 -0400 | [diff] [blame] | 489 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 490 | using INHERITED = GPUSink; |
Robert Phillips | 762cb4e | 2020-06-15 13:12:32 -0400 | [diff] [blame] | 491 | }; |
| 492 | |
Robert Phillips | 291f340 | 2020-02-19 14:14:47 -0500 | [diff] [blame] | 493 | // 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 |
| 501 | class GPUDDLSink : public GPUSink { |
| 502 | public: |
| 503 | GPUDDLSink(const SkCommandLineConfigGpu*, const GrContextOptions&); |
| 504 | |
| 505 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 506 | |
| 507 | private: |
| 508 | Result ddlDraw(const Src&, |
| 509 | sk_sp<SkSurface> dstSurface, |
| 510 | SkTaskGroup* recordingTaskGroup, |
| 511 | SkTaskGroup* gpuTaskGroup, |
Robert Phillips | 19f466d | 2020-02-26 10:27:07 -0500 | [diff] [blame] | 512 | sk_gpu_test::TestContext* gpuTestCtx, |
Robert Phillips | b87b39b | 2020-07-01 14:45:24 -0400 | [diff] [blame] | 513 | GrDirectContext* gpuThreadCtx) const; |
Robert Phillips | 291f340 | 2020-02-19 14:14:47 -0500 | [diff] [blame] | 514 | |
Robert Phillips | 762cb4e | 2020-06-15 13:12:32 -0400 | [diff] [blame] | 515 | std::unique_ptr<SkExecutor> fRecordingExecutor; |
| 516 | std::unique_ptr<SkExecutor> fGPUExecutor; |
Robert Phillips | 291f340 | 2020-02-19 14:14:47 -0500 | [diff] [blame] | 517 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 518 | using INHERITED = GPUSink; |
Robert Phillips | 291f340 | 2020-02-19 14:14:47 -0500 | [diff] [blame] | 519 | }; |
| 520 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 521 | class PDFSink : public Sink { |
| 522 | public: |
Hal Canary | c7d295e | 2017-07-20 15:36:00 -0400 | [diff] [blame] | 523 | PDFSink(bool pdfa, SkScalar rasterDpi) : fPDFA(pdfa), fRasterDpi(rasterDpi) {} |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 524 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 525 | const char* fileExtension() const override { return "pdf"; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 526 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
halcanary | 4b65666 | 2016-04-27 07:45:18 -0700 | [diff] [blame] | 527 | bool fPDFA; |
Hal Canary | c7d295e | 2017-07-20 15:36:00 -0400 | [diff] [blame] | 528 | SkScalar fRasterDpi; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 529 | }; |
| 530 | |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 531 | class XPSSink : public Sink { |
| 532 | public: |
| 533 | XPSSink(); |
| 534 | |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 535 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 536 | const char* fileExtension() const override { return "xps"; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 537 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
halcanary | 47ef4d5 | 2015-03-03 09:13:09 -0800 | [diff] [blame] | 538 | }; |
| 539 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 540 | class RasterSink : public Sink { |
| 541 | public: |
Brian Osman | fcb5023 | 2021-08-12 10:51:48 -0400 | [diff] [blame] | 542 | explicit RasterSink(SkColorType); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 543 | |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 544 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 545 | const char* fileExtension() const override { return "png"; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 546 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kRaster, SinkFlags::kDirect }; } |
Brian Osman | 54ef97c | 2021-08-11 17:06:42 -0400 | [diff] [blame] | 547 | void setColorSpace(sk_sp<SkColorSpace> colorSpace) override { fColorSpace = colorSpace; } |
Yuqian Li | b8b6253 | 2018-02-23 14:13:36 +0800 | [diff] [blame] | 548 | |
Mike Klein | 48b6490 | 2018-07-25 13:28:44 -0400 | [diff] [blame] | 549 | private: |
brianosman | b109b8c | 2016-06-16 13:03:24 -0700 | [diff] [blame] | 550 | SkColorType fColorType; |
| 551 | sk_sp<SkColorSpace> fColorSpace; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 552 | }; |
| 553 | |
mtklein | 9c3f17d | 2015-01-28 11:35:18 -0800 | [diff] [blame] | 554 | class SKPSink : public Sink { |
| 555 | public: |
| 556 | SKPSink(); |
| 557 | |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 558 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 559 | const char* fileExtension() const override { return "skp"; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 560 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
mtklein | 9c3f17d | 2015-01-28 11:35:18 -0800 | [diff] [blame] | 561 | }; |
| 562 | |
Hal Canary | 85c7fe8 | 2016-10-25 10:33:27 -0400 | [diff] [blame] | 563 | class DebugSink : public Sink { |
| 564 | public: |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 565 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
Hal Canary | 85c7fe8 | 2016-10-25 10:33:27 -0400 | [diff] [blame] | 566 | const char* fileExtension() const override { return "json"; } |
| 567 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
| 568 | }; |
| 569 | |
mtklein | 8a4527e | 2015-01-31 20:00:58 -0800 | [diff] [blame] | 570 | class SVGSink : public Sink { |
| 571 | public: |
Bryce Thomas | 95a7b76 | 2018-03-02 13:54:21 -0800 | [diff] [blame] | 572 | SVGSink(int pageIndex = 0); |
mtklein | 8a4527e | 2015-01-31 20:00:58 -0800 | [diff] [blame] | 573 | |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 574 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 575 | const char* fileExtension() const override { return "svg"; } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 576 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
Bryce Thomas | 95a7b76 | 2018-03-02 13:54:21 -0800 | [diff] [blame] | 577 | |
| 578 | private: |
| 579 | int fPageIndex; |
mtklein | 8a4527e | 2015-01-31 20:00:58 -0800 | [diff] [blame] | 580 | }; |
| 581 | |
| 582 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 583 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 584 | |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 585 | class Via : public Sink { |
| 586 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 587 | explicit Via(Sink* sink) : fSink(sink) {} |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 588 | const char* fileExtension() const override { return fSink->fileExtension(); } |
mtklein | 21eaf3b | 2016-02-08 12:39:59 -0800 | [diff] [blame] | 589 | bool serial() const override { return fSink->serial(); } |
mtklein | 99cab4e | 2015-07-31 06:43:04 -0700 | [diff] [blame] | 590 | SinkFlags flags() const override { |
| 591 | SinkFlags flags = fSink->flags(); |
| 592 | flags.approach = SinkFlags::kIndirect; |
| 593 | return flags; |
| 594 | } |
Brian Osman | 54ef97c | 2021-08-11 17:06:42 -0400 | [diff] [blame] | 595 | void setColorSpace(sk_sp<SkColorSpace> colorSpace) override { |
| 596 | fSink->setColorSpace(colorSpace); |
| 597 | } |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 598 | protected: |
Ben Wagner | 145dbcd | 2016-11-03 14:40:50 -0400 | [diff] [blame] | 599 | std::unique_ptr<Sink> fSink; |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 600 | }; |
| 601 | |
| 602 | class ViaMatrix : public Via { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 603 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 604 | ViaMatrix(SkMatrix, Sink*); |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 605 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 606 | private: |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 607 | const SkMatrix fMatrix; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 608 | }; |
| 609 | |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 610 | class ViaUpright : public Via { |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 611 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 612 | ViaUpright(SkMatrix, Sink*); |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 613 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 614 | private: |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 615 | const SkMatrix fMatrix; |
mtklein | d603b22 | 2015-02-17 11:13:33 -0800 | [diff] [blame] | 616 | }; |
| 617 | |
mtklein | 7882924 | 2015-05-06 07:54:07 -0700 | [diff] [blame] | 618 | class ViaSerialization : public Via { |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 619 | public: |
msarett | 62d3b10 | 2015-12-10 15:14:27 -0800 | [diff] [blame] | 620 | explicit ViaSerialization(Sink* sink) : Via(sink) {} |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 621 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 622 | }; |
| 623 | |
mtklein | 4a34ecb | 2016-01-08 10:19:35 -0800 | [diff] [blame] | 624 | class ViaPicture : public Via { |
| 625 | public: |
| 626 | explicit ViaPicture(Sink* sink) : Via(sink) {} |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 627 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
mtklein | 4a34ecb | 2016-01-08 10:19:35 -0800 | [diff] [blame] | 628 | }; |
| 629 | |
John Stiles | 65ec198 | 2021-07-20 12:53:54 -0400 | [diff] [blame] | 630 | class ViaRuntimeBlend : public Via { |
| 631 | public: |
| 632 | explicit ViaRuntimeBlend(Sink* sink) : Via(sink) {} |
| 633 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 634 | }; |
| 635 | |
Mike Reed | f67c459 | 2017-02-17 17:06:11 -0500 | [diff] [blame] | 636 | class ViaSVG : public Via { |
| 637 | public: |
| 638 | explicit ViaSVG(Sink* sink) : Via(sink) {} |
Ben Wagner | ea25fcf | 2020-02-12 11:18:46 -0500 | [diff] [blame] | 639 | Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
Mike Reed | f67c459 | 2017-02-17 17:06:11 -0500 | [diff] [blame] | 640 | }; |
| 641 | |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 642 | } // namespace DM |
| 643 | |
| 644 | #endif//DMSrcSink_DEFINED |