Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [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 | |
| 8 | #ifndef DMSrcSink_DEFINED |
| 9 | #define DMSrcSink_DEFINED |
| 10 | |
Xiaoming Shi | 73dfa20 | 2020-03-12 11:31:35 -0700 | [diff] [blame] | 11 | #include "gm/gm.h" |
| 12 | #include "include/android/SkBitmapRegionDecoder.h" |
| 13 | #include "include/core/SkBBHFactory.h" |
| 14 | #include "include/core/SkBitmap.h" |
| 15 | #include "include/core/SkCanvas.h" |
| 16 | #include "include/core/SkData.h" |
| 17 | #include "include/core/SkPicture.h" |
| 18 | #include "src/core/SkBBoxHierarchy.h" |
| 19 | #include "src/utils/SkMultiPictureDocument.h" |
| 20 | #include "tools/flags/CommonFlagsConfig.h" |
| 21 | #include "tools/gpu/MemoryCache.h" |
| 22 | |
| 23 | #include <functional> |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 24 | |
| 25 | //#define TEST_VIA_SVG |
| 26 | |
| 27 | namespace DM { |
| 28 | |
| 29 | // This is just convenience. It lets you use either return "foo" or return SkStringPrintf(...). |
| 30 | struct ImplicitString : public SkString { |
| 31 | template <typename T> |
| 32 | ImplicitString(const T& s) : SkString(s) {} |
| 33 | ImplicitString() : SkString("") {} |
| 34 | }; |
| 35 | typedef ImplicitString Name; |
| 36 | typedef ImplicitString Path; |
| 37 | |
| 38 | class Error { |
| 39 | public: |
| 40 | Error(const SkString& s) : fMsg(s), fFatal(!this->isEmpty()) {} |
| 41 | Error(const char* s) : fMsg(s), fFatal(!this->isEmpty()) {} |
| 42 | |
| 43 | Error(const Error&) = default; |
| 44 | Error& operator=(const Error&) = default; |
| 45 | |
| 46 | static Error Nonfatal(const SkString& s) { return Nonfatal(s.c_str()); } |
| 47 | static Error Nonfatal(const char* s) { |
| 48 | Error e(s); |
| 49 | e.fFatal = false; |
| 50 | return e; |
| 51 | } |
| 52 | |
| 53 | const char* c_str() const { return fMsg.c_str(); } |
| 54 | bool isEmpty() const { return fMsg.isEmpty(); } |
| 55 | bool isFatal() const { return fFatal; } |
| 56 | |
| 57 | private: |
| 58 | SkString fMsg; |
| 59 | bool fFatal; |
| 60 | }; |
| 61 | |
| 62 | struct SinkFlags { |
| 63 | enum Type { kNull, kGPU, kVector, kRaster } type; |
| 64 | enum Approach { kDirect, kIndirect } approach; |
| 65 | enum Multisampled { kNotMultisampled, kMultisampled } multisampled; |
| 66 | SinkFlags(Type t, Approach a, Multisampled ms = kNotMultisampled) |
| 67 | : type(t), approach(a), multisampled(ms) {} |
| 68 | }; |
| 69 | |
| 70 | struct Src { |
| 71 | virtual ~Src() {} |
| 72 | virtual Error SK_WARN_UNUSED_RESULT draw(SkCanvas*) const = 0; |
| 73 | virtual SkISize size() const = 0; |
| 74 | virtual Name name() const = 0; |
| 75 | virtual void modifyGrContextOptions(GrContextOptions* options) const {} |
| 76 | virtual bool veto(SinkFlags) const { return false; } |
| 77 | |
| 78 | virtual int pageCount() const { return 1; } |
| 79 | virtual Error SK_WARN_UNUSED_RESULT draw(int, SkCanvas* canvas) const { |
| 80 | return this->draw(canvas); |
| 81 | } |
| 82 | virtual SkISize size(int) const { return this->size(); } |
| 83 | // Force Tasks using this Src to run on the main thread? |
| 84 | virtual bool serial() const { return false; } |
| 85 | }; |
| 86 | |
| 87 | struct Sink { |
| 88 | virtual ~Sink() {} |
| 89 | // You may write to either the bitmap or stream. If you write to log, we'll print that out. |
| 90 | virtual Error SK_WARN_UNUSED_RESULT draw(const Src&, SkBitmap*, SkWStream*, SkString* log) |
| 91 | const = 0; |
| 92 | |
| 93 | // Force Tasks using this Sink to run on the main thread? |
| 94 | virtual bool serial() const { return false; } |
| 95 | |
| 96 | // File extension for the content draw() outputs, e.g. "png", "pdf". |
| 97 | virtual const char* fileExtension() const = 0; |
| 98 | |
| 99 | virtual SinkFlags flags() const = 0; |
| 100 | }; |
| 101 | |
| 102 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 103 | |
| 104 | class GMSrc : public Src { |
| 105 | public: |
Xiaoming Shi | 73dfa20 | 2020-03-12 11:31:35 -0700 | [diff] [blame] | 106 | explicit GMSrc(skiagm::GMFactory); |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 107 | |
| 108 | Error draw(SkCanvas*) const override; |
| 109 | SkISize size() const override; |
| 110 | Name name() const override; |
| 111 | void modifyGrContextOptions(GrContextOptions* options) const override; |
| 112 | |
| 113 | private: |
Xiaoming Shi | 73dfa20 | 2020-03-12 11:31:35 -0700 | [diff] [blame] | 114 | skiagm::GMFactory fFactory; |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | class CodecSrc : public Src { |
| 118 | public: |
| 119 | enum Mode { |
| 120 | kCodec_Mode, |
| 121 | // We choose to test only one mode with zero initialized memory. |
| 122 | // This will exercise all of the interesting cases in SkSwizzler |
| 123 | // without doubling the size of our test suite. |
| 124 | kCodecZeroInit_Mode, |
| 125 | kScanline_Mode, |
| 126 | kStripe_Mode, // Tests the skipping of scanlines |
| 127 | kCroppedScanline_Mode, // Tests (jpeg) cropped scanline optimization |
| 128 | kSubset_Mode, // For codecs that support subsets directly. |
| 129 | kAnimated_Mode, // For codecs that support animation. |
| 130 | }; |
| 131 | enum DstColorType { |
| 132 | kGetFromCanvas_DstColorType, |
| 133 | kGrayscale_Always_DstColorType, |
| 134 | kNonNative8888_Always_DstColorType, |
| 135 | }; |
| 136 | CodecSrc(Path, Mode, DstColorType, SkAlphaType, float); |
| 137 | |
| 138 | Error draw(SkCanvas*) const override; |
| 139 | SkISize size() const override; |
| 140 | Name name() const override; |
| 141 | bool veto(SinkFlags) const override; |
| 142 | bool serial() const override { return fRunSerially; } |
| 143 | private: |
| 144 | Path fPath; |
| 145 | Mode fMode; |
| 146 | DstColorType fDstColorType; |
| 147 | SkAlphaType fDstAlphaType; |
| 148 | float fScale; |
| 149 | bool fRunSerially; |
| 150 | }; |
| 151 | |
| 152 | class AndroidCodecSrc : public Src { |
| 153 | public: |
| 154 | AndroidCodecSrc(Path, CodecSrc::DstColorType, SkAlphaType, int sampleSize); |
| 155 | |
| 156 | Error draw(SkCanvas*) const override; |
| 157 | SkISize size() const override; |
| 158 | Name name() const override; |
| 159 | bool veto(SinkFlags) const override; |
| 160 | bool serial() const override { return fRunSerially; } |
| 161 | private: |
| 162 | Path fPath; |
| 163 | CodecSrc::DstColorType fDstColorType; |
| 164 | SkAlphaType fDstAlphaType; |
| 165 | int fSampleSize; |
| 166 | bool fRunSerially; |
| 167 | }; |
| 168 | |
| 169 | // Allows for testing of various implementations of Android's BitmapRegionDecoder |
| 170 | class BRDSrc : public Src { |
| 171 | public: |
| 172 | enum Mode { |
| 173 | // Decode the entire image as one region. |
| 174 | kFullImage_Mode, |
| 175 | // Splits the image into multiple regions using a divisor and decodes the regions |
| 176 | // separately. Also, this test adds a border of a few pixels to each of the regions |
| 177 | // that it is decoding. This tests the behavior when a client asks for a region that |
| 178 | // does not fully fit in the image. |
| 179 | kDivisor_Mode, |
| 180 | }; |
| 181 | |
| 182 | BRDSrc(Path, Mode, CodecSrc::DstColorType, uint32_t); |
| 183 | |
| 184 | Error draw(SkCanvas*) const override; |
| 185 | SkISize size() const override; |
| 186 | Name name() const override; |
| 187 | bool veto(SinkFlags) const override; |
| 188 | private: |
| 189 | Path fPath; |
| 190 | Mode fMode; |
| 191 | CodecSrc::DstColorType fDstColorType; |
| 192 | uint32_t fSampleSize; |
| 193 | }; |
| 194 | |
| 195 | class ImageGenSrc : public Src { |
| 196 | public: |
| 197 | enum Mode { |
| 198 | kCodec_Mode, // Use CodecImageGenerator |
| 199 | kPlatform_Mode, // Uses CG or WIC |
| 200 | }; |
| 201 | ImageGenSrc(Path, Mode, SkAlphaType, bool); |
| 202 | |
| 203 | Error draw(SkCanvas*) const override; |
| 204 | SkISize size() const override; |
| 205 | Name name() const override; |
| 206 | bool veto(SinkFlags) const override; |
| 207 | bool serial() const override { return fRunSerially; } |
| 208 | private: |
| 209 | Path fPath; |
| 210 | Mode fMode; |
| 211 | SkAlphaType fDstAlphaType; |
| 212 | bool fIsGpu; |
| 213 | bool fRunSerially; |
| 214 | }; |
| 215 | |
| 216 | class ColorCodecSrc : public Src { |
| 217 | public: |
Xiaoming Shi | 73dfa20 | 2020-03-12 11:31:35 -0700 | [diff] [blame] | 218 | ColorCodecSrc(Path, bool decode_to_dst); |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 219 | |
| 220 | Error draw(SkCanvas*) const override; |
| 221 | SkISize size() const override; |
| 222 | Name name() const override; |
| 223 | bool veto(SinkFlags) const override; |
| 224 | private: |
Xiaoming Shi | 73dfa20 | 2020-03-12 11:31:35 -0700 | [diff] [blame] | 225 | Path fPath; |
| 226 | bool fDecodeToDst; |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 227 | }; |
| 228 | |
| 229 | class SKPSrc : public Src { |
| 230 | public: |
| 231 | explicit SKPSrc(Path path); |
| 232 | |
| 233 | Error draw(SkCanvas*) const override; |
| 234 | SkISize size() const override; |
| 235 | Name name() const override; |
| 236 | private: |
| 237 | Path fPath; |
| 238 | }; |
| 239 | |
Xiaoming Shi | 73dfa20 | 2020-03-12 11:31:35 -0700 | [diff] [blame] | 240 | // This class extracts all the paths from an SKP and then removes unwanted paths according to the |
| 241 | // provided l/r trail. It then just draws the remaining paths. (Non-path draws are thrown out.) It |
| 242 | // is useful for finding a reduced repo case for path drawing bugs. |
| 243 | class BisectSrc : public SKPSrc { |
| 244 | public: |
| 245 | explicit BisectSrc(Path path, const char* trail); |
| 246 | |
| 247 | Error draw(SkCanvas*) const override; |
| 248 | |
| 249 | private: |
| 250 | SkString fTrail; |
| 251 | |
| 252 | typedef SKPSrc INHERITED; |
| 253 | }; |
| 254 | |
| 255 | |
| 256 | #if defined(SK_ENABLE_SKOTTIE) |
| 257 | class SkottieSrc final : public Src { |
| 258 | public: |
| 259 | explicit SkottieSrc(Path path); |
| 260 | |
| 261 | Error draw(SkCanvas*) const override; |
| 262 | SkISize size() const override; |
| 263 | Name name() const override; |
| 264 | bool veto(SinkFlags) const override; |
| 265 | |
| 266 | private: |
| 267 | // Generates a kTileCount x kTileCount filmstrip with evenly distributed frames. |
| 268 | static constexpr int kTileCount = 5; |
| 269 | |
| 270 | // Fit kTileCount x kTileCount frames to a 1000x1000 film strip. |
| 271 | static constexpr SkScalar kTargetSize = 1000; |
| 272 | static constexpr SkScalar kTileSize = kTargetSize / kTileCount; |
| 273 | |
| 274 | Path fPath; |
| 275 | }; |
| 276 | #endif |
| 277 | |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 278 | #if defined(SK_XML) |
| 279 | } // namespace DM |
| 280 | |
| 281 | class SkSVGDOM; |
| 282 | |
| 283 | namespace DM { |
| 284 | |
| 285 | class SVGSrc : public Src { |
| 286 | public: |
| 287 | explicit SVGSrc(Path path); |
| 288 | |
| 289 | Error draw(SkCanvas*) const override; |
| 290 | SkISize size() const override; |
| 291 | Name name() const override; |
| 292 | bool veto(SinkFlags) const override; |
| 293 | |
| 294 | private: |
| 295 | Name fName; |
| 296 | sk_sp<SkSVGDOM> fDom; |
| 297 | SkScalar fScale; |
| 298 | |
| 299 | typedef Src INHERITED; |
| 300 | }; |
| 301 | #endif // SK_XML |
| 302 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 303 | |
| 304 | class MSKPSrc : public Src { |
| 305 | public: |
| 306 | explicit MSKPSrc(Path path); |
| 307 | |
| 308 | int pageCount() const override; |
| 309 | Error draw(SkCanvas* c) const override; |
| 310 | Error draw(int, SkCanvas*) const override; |
| 311 | SkISize size() const override; |
| 312 | SkISize size(int) const override; |
| 313 | Name name() const override; |
| 314 | |
| 315 | private: |
| 316 | Path fPath; |
| 317 | mutable SkTArray<SkDocumentPage> fPages; |
| 318 | }; |
| 319 | |
| 320 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 321 | |
| 322 | class NullSink : public Sink { |
| 323 | public: |
| 324 | NullSink() {} |
| 325 | |
| 326 | Error draw(const Src& src, SkBitmap*, SkWStream*, SkString*) const override; |
| 327 | const char* fileExtension() const override { return ""; } |
| 328 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kNull, SinkFlags::kDirect }; } |
| 329 | }; |
| 330 | |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 331 | class GPUSink : public Sink { |
| 332 | public: |
Xiaoming Shi | 73dfa20 | 2020-03-12 11:31:35 -0700 | [diff] [blame] | 333 | GPUSink(const SkCommandLineConfigGpu*, const GrContextOptions&); |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 334 | |
| 335 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
Xiaoming Shi | 73dfa20 | 2020-03-12 11:31:35 -0700 | [diff] [blame] | 336 | Error onDraw(const Src&, SkBitmap*, SkWStream*, SkString*, |
| 337 | const GrContextOptions& baseOptions, |
| 338 | std::function<void(GrContext*)> initContext = nullptr) const; |
| 339 | |
| 340 | sk_gpu_test::GrContextFactory::ContextType contextType() const { return fContextType; } |
| 341 | const sk_gpu_test::GrContextFactory::ContextOverrides& contextOverrides() { |
| 342 | return fContextOverrides; |
| 343 | } |
| 344 | SkCommandLineConfigGpu::SurfType surfType() const { return fSurfType; } |
| 345 | bool useDIText() const { return fUseDIText; } |
| 346 | bool serial() const override { return true; } |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 347 | const char* fileExtension() const override { return "png"; } |
| 348 | SinkFlags flags() const override { |
Xiaoming Shi | 73dfa20 | 2020-03-12 11:31:35 -0700 | [diff] [blame] | 349 | SinkFlags::Multisampled ms = fSampleCount > 1 ? SinkFlags::kMultisampled |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 350 | : SinkFlags::kNotMultisampled; |
| 351 | return SinkFlags{ SinkFlags::kGPU, SinkFlags::kDirect, ms }; |
| 352 | } |
Xiaoming Shi | 73dfa20 | 2020-03-12 11:31:35 -0700 | [diff] [blame] | 353 | const GrContextOptions& baseContextOptions() const { return fBaseContextOptions; } |
| 354 | |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 355 | private: |
| 356 | sk_gpu_test::GrContextFactory::ContextType fContextType; |
| 357 | sk_gpu_test::GrContextFactory::ContextOverrides fContextOverrides; |
Xiaoming Shi | 73dfa20 | 2020-03-12 11:31:35 -0700 | [diff] [blame] | 358 | SkCommandLineConfigGpu::SurfType fSurfType; |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 359 | int fSampleCount; |
| 360 | bool fUseDIText; |
| 361 | SkColorType fColorType; |
| 362 | SkAlphaType fAlphaType; |
| 363 | sk_sp<SkColorSpace> fColorSpace; |
Xiaoming Shi | 73dfa20 | 2020-03-12 11:31:35 -0700 | [diff] [blame] | 364 | GrContextOptions fBaseContextOptions; |
| 365 | sk_gpu_test::MemoryCache fMemoryCache; |
| 366 | }; |
| 367 | |
| 368 | class GPUThreadTestingSink : public GPUSink { |
| 369 | public: |
| 370 | GPUThreadTestingSink(const SkCommandLineConfigGpu*, const GrContextOptions&); |
| 371 | |
| 372 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 373 | |
| 374 | const char* fileExtension() const override { |
| 375 | // Suppress writing out results from this config - we just want to do our matching test |
| 376 | return nullptr; |
| 377 | } |
| 378 | |
| 379 | private: |
| 380 | std::unique_ptr<SkExecutor> fExecutor; |
| 381 | |
| 382 | typedef GPUSink INHERITED; |
| 383 | }; |
| 384 | |
| 385 | class GPUPersistentCacheTestingSink : public GPUSink { |
| 386 | public: |
| 387 | GPUPersistentCacheTestingSink(const SkCommandLineConfigGpu*, const GrContextOptions&); |
| 388 | |
| 389 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 390 | |
| 391 | const char* fileExtension() const override { |
| 392 | // Suppress writing out results from this config - we just want to do our matching test |
| 393 | return nullptr; |
| 394 | } |
| 395 | |
| 396 | private: |
| 397 | int fCacheType; |
| 398 | |
| 399 | typedef GPUSink INHERITED; |
| 400 | }; |
| 401 | |
| 402 | class GPUPrecompileTestingSink : public GPUSink { |
| 403 | public: |
| 404 | GPUPrecompileTestingSink(const SkCommandLineConfigGpu*, const GrContextOptions&); |
| 405 | |
| 406 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 407 | |
| 408 | const char* fileExtension() const override { |
| 409 | // Suppress writing out results from this config - we just want to do our matching test |
| 410 | return nullptr; |
| 411 | } |
| 412 | |
| 413 | private: |
| 414 | typedef GPUSink INHERITED; |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 415 | }; |
| 416 | |
| 417 | class PDFSink : public Sink { |
| 418 | public: |
Xiaoming Shi | 73dfa20 | 2020-03-12 11:31:35 -0700 | [diff] [blame] | 419 | PDFSink(bool pdfa, SkScalar rasterDpi) : fPDFA(pdfa), fRasterDpi(rasterDpi) {} |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 420 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 421 | const char* fileExtension() const override { return "pdf"; } |
| 422 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
| 423 | bool fPDFA; |
Xiaoming Shi | 73dfa20 | 2020-03-12 11:31:35 -0700 | [diff] [blame] | 424 | SkScalar fRasterDpi; |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 425 | }; |
| 426 | |
| 427 | class XPSSink : public Sink { |
| 428 | public: |
| 429 | XPSSink(); |
| 430 | |
| 431 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 432 | const char* fileExtension() const override { return "xps"; } |
| 433 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
| 434 | }; |
| 435 | |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 436 | class RasterSink : public Sink { |
| 437 | public: |
| 438 | explicit RasterSink(SkColorType, sk_sp<SkColorSpace> = nullptr); |
| 439 | |
| 440 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 441 | const char* fileExtension() const override { return "png"; } |
| 442 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kRaster, SinkFlags::kDirect }; } |
Xiaoming Shi | 73dfa20 | 2020-03-12 11:31:35 -0700 | [diff] [blame] | 443 | |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 444 | private: |
| 445 | SkColorType fColorType; |
| 446 | sk_sp<SkColorSpace> fColorSpace; |
| 447 | }; |
| 448 | |
Xiaoming Shi | 73dfa20 | 2020-03-12 11:31:35 -0700 | [diff] [blame] | 449 | class ThreadedSink : public RasterSink { |
| 450 | public: |
| 451 | explicit ThreadedSink(SkColorType, sk_sp<SkColorSpace> = nullptr); |
| 452 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 453 | }; |
| 454 | |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 455 | class SKPSink : public Sink { |
| 456 | public: |
| 457 | SKPSink(); |
| 458 | |
| 459 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 460 | const char* fileExtension() const override { return "skp"; } |
| 461 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
| 462 | }; |
| 463 | |
| 464 | class DebugSink : public Sink { |
| 465 | public: |
| 466 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 467 | const char* fileExtension() const override { return "json"; } |
| 468 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
| 469 | }; |
| 470 | |
| 471 | class SVGSink : public Sink { |
| 472 | public: |
Xiaoming Shi | 73dfa20 | 2020-03-12 11:31:35 -0700 | [diff] [blame] | 473 | SVGSink(int pageIndex = 0); |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 474 | |
| 475 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 476 | const char* fileExtension() const override { return "svg"; } |
| 477 | SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
Xiaoming Shi | 73dfa20 | 2020-03-12 11:31:35 -0700 | [diff] [blame] | 478 | |
| 479 | private: |
| 480 | int fPageIndex; |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 481 | }; |
| 482 | |
| 483 | |
| 484 | /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 485 | |
| 486 | class Via : public Sink { |
| 487 | public: |
| 488 | explicit Via(Sink* sink) : fSink(sink) {} |
| 489 | const char* fileExtension() const override { return fSink->fileExtension(); } |
| 490 | bool serial() const override { return fSink->serial(); } |
| 491 | SinkFlags flags() const override { |
| 492 | SinkFlags flags = fSink->flags(); |
| 493 | flags.approach = SinkFlags::kIndirect; |
| 494 | return flags; |
| 495 | } |
| 496 | protected: |
| 497 | std::unique_ptr<Sink> fSink; |
| 498 | }; |
| 499 | |
| 500 | class ViaMatrix : public Via { |
| 501 | public: |
| 502 | ViaMatrix(SkMatrix, Sink*); |
| 503 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 504 | private: |
| 505 | const SkMatrix fMatrix; |
| 506 | }; |
| 507 | |
| 508 | class ViaUpright : public Via { |
| 509 | public: |
| 510 | ViaUpright(SkMatrix, Sink*); |
| 511 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 512 | private: |
| 513 | const SkMatrix fMatrix; |
| 514 | }; |
| 515 | |
| 516 | class ViaSerialization : public Via { |
| 517 | public: |
| 518 | explicit ViaSerialization(Sink* sink) : Via(sink) {} |
| 519 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 520 | }; |
| 521 | |
| 522 | class ViaPicture : public Via { |
| 523 | public: |
| 524 | explicit ViaPicture(Sink* sink) : Via(sink) {} |
| 525 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 526 | }; |
| 527 | |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 528 | class ViaTiles : public Via { |
| 529 | public: |
| 530 | ViaTiles(int w, int h, SkBBHFactory*, Sink*); |
| 531 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 532 | private: |
| 533 | const int fW, fH; |
| 534 | std::unique_ptr<SkBBHFactory> fFactory; |
| 535 | }; |
| 536 | |
Xiaoming Shi | 73dfa20 | 2020-03-12 11:31:35 -0700 | [diff] [blame] | 537 | class ViaDDL : public Via { |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 538 | public: |
Xiaoming Shi | 73dfa20 | 2020-03-12 11:31:35 -0700 | [diff] [blame] | 539 | ViaDDL(int numReplays, int numDivisions, Sink* sink); |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 540 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
Xiaoming Shi | 73dfa20 | 2020-03-12 11:31:35 -0700 | [diff] [blame] | 541 | private: |
| 542 | const int fNumReplays; |
| 543 | const int fNumDivisions; |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 544 | }; |
| 545 | |
| 546 | class ViaSVG : public Via { |
| 547 | public: |
| 548 | explicit ViaSVG(Sink* sink) : Via(sink) {} |
| 549 | Error draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 550 | }; |
| 551 | |
Andrew Top | 200ce4b | 2018-01-29 13:43:50 -0800 | [diff] [blame] | 552 | } // namespace DM |
| 553 | |
| 554 | #endif//DMSrcSink_DEFINED |