| 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 |
|
| 11 |
#include "gm/gm.h" |
| 12 |
#include "include/core/SkBitmap.h" |
| 13 |
#include "include/core/SkCanvas.h" |
| 14 |
#include "include/core/SkPicture.h" |
| 15 |
#include "include/core/SkSurfaceProps.h" |
| 16 |
#include "include/docs/SkMultiPictureDocument.h" |
| 17 |
#include "tools/flags/CommonFlagsConfig.h" |
| 18 |
|
| 19 |
#if defined(SK_GANESH) |
| 20 |
#include "tools/ganesh/MemoryCache.h" |
| 21 |
#endif |
| 22 |
|
| 23 |
#if defined(SK_GRAPHITE) |
| 24 |
#include "include/gpu/graphite/PrecompileContext.h" |
| 25 |
#include "tools/graphite/GraphiteMemoryPipelineStorage.h" |
| 26 |
#endif |
| 27 |
|
| 28 |
#include <functional> |
| 29 |
|
| 30 |
#if !defined (SK_DISABLE_LEGACY_TESTS) |
| 31 |
#include "include/gpu/graphite/ContextOptions.h" |
| 32 |
#include "tools/graphite/TestOptions.h" |
| 33 |
#endif |
| 34 |
|
| 35 |
//#define TEST_VIA_SVG |
| 36 |
|
| 37 |
namespace skgpu { |
| 38 |
class UniqueKey; |
| 39 |
} |
| 40 |
namespace skiagm::verifiers { |
| 41 |
class VerifierList; |
| 42 |
} |
| 43 |
namespace skiatools::graphite { |
| 44 |
class PipelineCallBackHandler; |
| 45 |
} |
| 46 |
namespace DM { |
| 47 |
|
| 48 |
// This is just convenience. It lets you use either return "foo" or return SkStringPrintf(...). |
| 49 |
struct ImplicitString : public SkString { |
| 50 |
// This constructor is intentionally not explicit to allow for convenient implicit conversions. |
| 51 |
template <typename T> |
| 52 |
ImplicitString(const T& s) : SkString(s) {} |
| 53 |
ImplicitString() : SkString("") {} |
| 54 |
}; |
| 55 |
typedef ImplicitString Name; |
| 56 |
typedef ImplicitString Path; |
| 57 |
|
| 58 |
class Result { |
| 59 |
public: |
| 60 |
enum class Status : int { Ok, Fatal, Skip }; |
| 61 |
|
| 62 |
Result(Status status, SkString msg) : fMsg(std::move(msg)), fStatus(status) {} |
| 63 |
|
| 64 |
Result(const Result&) = default; |
| 65 |
Result& operator=(const Result&) = default; |
| 66 |
|
| 67 |
static Result Ok() { return Result{Status::Ok, {}}; } |
| 68 |
|
| 69 |
static Result Fatal(const char* fmt, ...) SK_PRINTF_LIKE(1, 2) { |
| 70 |
SkString msg; |
| 71 |
va_list args; |
| 72 |
va_start(args, fmt); |
| 73 |
msg.printVAList(fmt, args); |
| 74 |
va_end(args); |
| 75 |
|
| 76 |
return Result{Status::Fatal, std::move(msg)}; |
| 77 |
} |
| 78 |
|
| 79 |
static Result Skip(const char* fmt, ...) SK_PRINTF_LIKE(1, 2) { |
| 80 |
SkString msg; |
| 81 |
va_list args; |
| 82 |
va_start(args, fmt); |
| 83 |
msg.printVAList(fmt, args); |
| 84 |
va_end(args); |
| 85 |
|
| 86 |
return Result{Status::Skip, std::move(msg)}; |
| 87 |
} |
| 88 |
|
| 89 |
bool isOk() { return fStatus == Status::Ok; } |
| 90 |
bool isFatal() { return fStatus == Status::Fatal; } |
| 91 |
bool isSkip() { return fStatus == Status::Skip; } |
| 92 |
|
| 93 |
const char* c_str() const { return fMsg.c_str(); } |
| 94 |
Status status() const { return fStatus; } |
| 95 |
|
| 96 |
private: |
| 97 |
SkString fMsg; |
| 98 |
Status fStatus; |
| 99 |
}; |
| 100 |
|
| 101 |
struct SinkFlags { |
| 102 |
enum Type { kNull, kGPU, kVector, kRaster } type; |
| 103 |
enum Approach { kDirect, kIndirect } approach; |
| 104 |
enum Multisampled { kNotMultisampled, kMultisampled } multisampled; |
| 105 |
SinkFlags(Type t, Approach a, Multisampled ms = kNotMultisampled) |
| 106 |
: type(t), approach(a), multisampled(ms) {} |
| 107 |
}; |
| 108 |
|
| 109 |
struct Src { |
| 110 |
using GraphiteTestContext = skiatest::graphite::GraphiteTestContext; |
| 111 |
|
| 112 |
virtual ~Src() {} |
| 113 |
[[nodiscard]] virtual Result draw(SkCanvas* canvas, GraphiteTestContext*) const = 0; |
| 114 |
virtual SkISize size() const = 0; |
| 115 |
virtual Name name() const = 0; |
| 116 |
// Called by sinks to modify the default-default surface properties (if applicable). |
| 117 |
// Sinks may then further update the value based on other criteria. |
| 118 |
virtual void modifySurfaceProps(SkSurfaceProps*) const {} |
| 119 |
virtual void modifyGrContextOptions(GrContextOptions*) const {} |
| 120 |
virtual void modifyGraphiteContextOptions(skgpu::graphite::ContextOptions*) const {} |
| 121 |
virtual bool veto(SinkFlags) const { return false; } |
| 122 |
|
| 123 |
virtual int pageCount() const { return 1; } |
| 124 |
[[nodiscard]] virtual Result draw([[maybe_unused]] int page, |
| 125 |
SkCanvas* canvas, |
| 126 |
GraphiteTestContext* graphiteTestContext) const { |
| 127 |
return this->draw(canvas, graphiteTestContext); |
| 128 |
} |
| 129 |
virtual SkISize size([[maybe_unused]] int page) const { return this->size(); } |
| 130 |
// Force Tasks using this Src to run on the main thread? |
| 131 |
virtual bool serial() const { return false; } |
| 132 |
}; |
| 133 |
|
| 134 |
struct Sink { |
| 135 |
virtual ~Sink() {} |
| 136 |
// You may write to either the bitmap or stream. If you write to log, we'll print that out. |
| 137 |
[[nodiscard]] virtual Result draw(const Src&, SkBitmap*, SkWStream*, SkString* log) const = 0; |
| 138 |
|
| 139 |
virtual void done() const {} |
| 140 |
|
| 141 |
// Override the color space of this Sink, after creation |
| 142 |
virtual void setColorSpace(sk_sp<SkColorSpace>) {} |
| 143 |
|
| 144 |
// Force Tasks using this Sink to run on the main thread? |
| 145 |
virtual bool serial() const { return false; } |
| 146 |
|
| 147 |
// File extension for the content draw() outputs, e.g. "png", "pdf". |
| 148 |
virtual const char* fileExtension() const = 0; |
| 149 |
|
| 150 |
virtual SinkFlags flags() const = 0; |
| 151 |
|
| 152 |
/** Returns the color type and space used by the sink. */ |
| 153 |
virtual SkColorInfo colorInfo() const { return SkColorInfo(); } |
| 154 |
}; |
| 155 |
|
| 156 |
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 157 |
|
| 158 |
class GMSrc : public Src { |
| 159 |
public: |
| 160 |
explicit GMSrc(skiagm::GMFactory); |
| 161 |
|
| 162 |
Result draw(SkCanvas*, GraphiteTestContext*) const override; |
| 163 |
SkISize size() const override; |
| 164 |
Name name() const override; |
| 165 |
void modifySurfaceProps(SkSurfaceProps*) const override; |
| 166 |
void modifyGrContextOptions(GrContextOptions* options) const override; |
| 167 |
#if defined(SK_GRAPHITE) |
| 168 |
void modifyGraphiteContextOptions(skgpu::graphite::ContextOptions*) const override; |
| 169 |
#endif |
| 170 |
|
| 171 |
private: |
| 172 |
skiagm::GMFactory fFactory; |
| 173 |
}; |
| 174 |
|
| 175 |
class CodecSrc : public Src { |
| 176 |
public: |
| 177 |
enum Mode { |
| 178 |
kCodec_Mode, |
| 179 |
// We choose to test only one mode with zero initialized memory. |
| 180 |
// This will exercise all of the interesting cases in SkSwizzler |
| 181 |
// without doubling the size of our test suite. |
| 182 |
kCodecZeroInit_Mode, |
| 183 |
kScanline_Mode, |
| 184 |
kStripe_Mode, // Tests the skipping of scanlines |
| 185 |
kCroppedScanline_Mode, // Tests (jpeg) cropped scanline optimization |
| 186 |
kSubset_Mode, // For codecs that support subsets directly. |
| 187 |
kAnimated_Mode, // For codecs that support animation. |
| 188 |
}; |
| 189 |
enum DstColorType { |
| 190 |
kGetFromCanvas_DstColorType, |
| 191 |
kGrayscale_Always_DstColorType, |
| 192 |
kNonNative8888_Always_DstColorType, |
| 193 |
}; |
| 194 |
CodecSrc(Path, Mode, DstColorType, SkAlphaType, float); |
| 195 |
|
| 196 |
Result draw(SkCanvas*, GraphiteTestContext*) const override; |
| 197 |
SkISize size() const override; |
| 198 |
Name name() const override; |
| 199 |
bool veto(SinkFlags) const override; |
| 200 |
bool serial() const override { return fRunSerially; } |
| 201 |
private: |
| 202 |
Path fPath; |
| 203 |
Mode fMode; |
| 204 |
DstColorType fDstColorType; |
| 205 |
SkAlphaType fDstAlphaType; |
| 206 |
float fScale; |
| 207 |
bool fRunSerially; |
| 208 |
}; |
| 209 |
|
| 210 |
class AndroidCodecSrc : public Src { |
| 211 |
public: |
| 212 |
AndroidCodecSrc(Path, CodecSrc::DstColorType, SkAlphaType, int sampleSize); |
| 213 |
|
| 214 |
Result draw(SkCanvas*, GraphiteTestContext*) const override; |
| 215 |
SkISize size() const override; |
| 216 |
Name name() const override; |
| 217 |
bool veto(SinkFlags) const override; |
| 218 |
bool serial() const override { return fRunSerially; } |
| 219 |
private: |
| 220 |
Path fPath; |
| 221 |
CodecSrc::DstColorType fDstColorType; |
| 222 |
SkAlphaType fDstAlphaType; |
| 223 |
int fSampleSize; |
| 224 |
bool fRunSerially; |
| 225 |
}; |
| 226 |
|
| 227 |
#ifdef SK_ENABLE_ANDROID_UTILS |
| 228 |
// Allows for testing of various implementations of Android's BitmapRegionDecoder |
| 229 |
class BRDSrc : public Src { |
| 230 |
public: |
| 231 |
enum Mode { |
| 232 |
// Decode the entire image as one region. |
| 233 |
kFullImage_Mode, |
| 234 |
// Splits the image into multiple regions using a divisor and decodes the regions |
| 235 |
// separately. Also, this test adds a border of a few pixels to each of the regions |
| 236 |
// that it is decoding. This tests the behavior when a client asks for a region that |
| 237 |
// does not fully fit in the image. |
| 238 |
kDivisor_Mode, |
| 239 |
}; |
| 240 |
|
| 241 |
BRDSrc(Path, Mode, CodecSrc::DstColorType, uint32_t); |
| 242 |
|
| 243 |
Result draw(SkCanvas*, GraphiteTestContext*) const override; |
| 244 |
SkISize size() const override; |
| 245 |
Name name() const override; |
| 246 |
bool veto(SinkFlags) const override; |
| 247 |
private: |
| 248 |
Path fPath; |
| 249 |
Mode fMode; |
| 250 |
CodecSrc::DstColorType fDstColorType; |
| 251 |
uint32_t fSampleSize; |
| 252 |
}; |
| 253 |
#endif |
| 254 |
|
| 255 |
class ImageGenSrc : public Src { |
| 256 |
public: |
| 257 |
enum Mode { |
| 258 |
kCodec_Mode, // Use CodecImageGenerator |
| 259 |
kPlatform_Mode, // Uses CG or WIC |
| 260 |
}; |
| 261 |
ImageGenSrc(Path, Mode, SkAlphaType, bool); |
| 262 |
|
| 263 |
Result draw(SkCanvas*, GraphiteTestContext*) const override; |
| 264 |
SkISize size() const override; |
| 265 |
Name name() const override; |
| 266 |
bool veto(SinkFlags) const override; |
| 267 |
bool serial() const override { return fRunSerially; } |
| 268 |
private: |
| 269 |
Path fPath; |
| 270 |
Mode fMode; |
| 271 |
SkAlphaType fDstAlphaType; |
| 272 |
bool fIsGpu; |
| 273 |
bool fRunSerially; |
| 274 |
}; |
| 275 |
|
| 276 |
class ColorCodecSrc : public Src { |
| 277 |
public: |
| 278 |
ColorCodecSrc(Path, bool decode_to_dst); |
| 279 |
|
| 280 |
Result draw(SkCanvas*, GraphiteTestContext*) const override; |
| 281 |
SkISize size() const override; |
| 282 |
Name name() const override; |
| 283 |
bool veto(SinkFlags) const override; |
| 284 |
private: |
| 285 |
Path fPath; |
| 286 |
bool fDecodeToDst; |
| 287 |
}; |
| 288 |
|
| 289 |
class SKPSrc : public Src { |
| 290 |
public: |
| 291 |
explicit SKPSrc(Path path); |
| 292 |
|
| 293 |
Result draw(SkCanvas*, GraphiteTestContext*) const override; |
| 294 |
SkISize size() const override; |
| 295 |
Name name() const override; |
| 296 |
private: |
| 297 |
Path fPath; |
| 298 |
}; |
| 299 |
|
| 300 |
// This class extracts all the paths from an SKP and then removes unwanted paths according to the |
| 301 |
// provided l/r trail. It then just draws the remaining paths. (Non-path draws are thrown out.) It |
| 302 |
// is useful for finding a reduced repo case for path drawing bugs. |
| 303 |
class BisectSrc : public SKPSrc { |
| 304 |
public: |
| 305 |
explicit BisectSrc(Path path, const char* trail); |
| 306 |
|
| 307 |
Result draw(SkCanvas*, GraphiteTestContext*) const override; |
| 308 |
|
| 309 |
private: |
| 310 |
SkString fTrail; |
| 311 |
|
| 312 |
using INHERITED = SKPSrc; |
| 313 |
}; |
| 314 |
|
| 315 |
#if defined(SK_ENABLE_SKOTTIE) |
| 316 |
class SkottieSrc final : public Src { |
| 317 |
public: |
| 318 |
explicit SkottieSrc(Path path); |
| 319 |
|
| 320 |
Result draw(SkCanvas*, GraphiteTestContext*) const override; |
| 321 |
SkISize size() const override; |
| 322 |
Name name() const override; |
| 323 |
bool veto(SinkFlags) const override; |
| 324 |
|
| 325 |
private: |
| 326 |
// Generates a kTileCount x kTileCount filmstrip with evenly distributed frames. |
| 327 |
inline static constexpr int kTileCount = 5; |
| 328 |
|
| 329 |
// Fit kTileCount x kTileCount frames to a 1000x1000 film strip. |
| 330 |
inline static constexpr SkScalar kTargetSize = 1000; |
| 331 |
inline static constexpr SkScalar kTileSize = kTargetSize / kTileCount; |
| 332 |
|
| 333 |
Path fPath; |
| 334 |
}; |
| 335 |
#endif |
| 336 |
|
| 337 |
#if defined(SK_ENABLE_SVG) |
| 338 |
} // namespace DM |
| 339 |
|
| 340 |
class SkSVGDOM; |
| 341 |
|
| 342 |
namespace DM { |
| 343 |
|
| 344 |
class SVGSrc : public Src { |
| 345 |
public: |
| 346 |
explicit SVGSrc(Path path); |
| 347 |
|
| 348 |
Result draw(SkCanvas*, GraphiteTestContext*) const override; |
| 349 |
SkISize size() const override; |
| 350 |
Name name() const override; |
| 351 |
bool veto(SinkFlags) const override; |
| 352 |
|
| 353 |
private: |
| 354 |
Name fName; |
| 355 |
sk_sp<SkSVGDOM> fDom; |
| 356 |
SkScalar fScale; |
| 357 |
|
| 358 |
using INHERITED = Src; |
| 359 |
}; |
| 360 |
#endif // SK_ENABLE_SVG |
| 361 |
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 362 |
|
| 363 |
class MSKPSrc : public Src { |
| 364 |
public: |
| 365 |
explicit MSKPSrc(Path path); |
| 366 |
|
| 367 |
int pageCount() const override; |
| 368 |
Result draw(SkCanvas* c, GraphiteTestContext*) const override; |
| 369 |
Result draw(int, SkCanvas*, GraphiteTestContext*) const override; |
| 370 |
SkISize size() const override; |
| 371 |
SkISize size(int) const override; |
| 372 |
Name name() const override; |
| 373 |
|
| 374 |
private: |
| 375 |
Path fPath; |
| 376 |
mutable skia_private::TArray<SkDocumentPage> fPages; |
| 377 |
}; |
| 378 |
|
| 379 |
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 380 |
|
| 381 |
class NullSink : public Sink { |
| 382 |
public: |
| 383 |
NullSink() {} |
| 384 |
|
| 385 |
Result draw(const Src& src, SkBitmap*, SkWStream*, SkString*) const override; |
| 386 |
const char* fileExtension() const override { return ""; } |
| 387 |
SinkFlags flags() const override { return SinkFlags{ SinkFlags::kNull, SinkFlags::kDirect }; } |
| 388 |
}; |
| 389 |
|
| 390 |
#if defined(SK_GANESH) |
| 391 |
class GPUSink : public Sink { |
| 392 |
public: |
| 393 |
GPUSink(const SkCommandLineConfigGpu*, const GrContextOptions&); |
| 394 |
|
| 395 |
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 396 |
Result onDraw(const Src&, SkBitmap*, SkWStream*, SkString*, |
| 397 |
const GrContextOptions& baseOptions, |
| 398 |
std::function<void(GrDirectContext*)> initContext = nullptr, |
| 399 |
std::function<SkCanvas*(SkCanvas*)> wrapCanvas = nullptr) const; |
| 400 |
|
| 401 |
skgpu::ContextType contextType() const { return fContextType; } |
| 402 |
const sk_gpu_test::GrContextFactory::ContextOverrides& contextOverrides() const { |
| 403 |
return fContextOverrides; |
| 404 |
} |
| 405 |
SkCommandLineConfigGpu::SurfType surfType() const { return fSurfType; } |
| 406 |
bool serial() const override { return true; } |
| 407 |
const char* fileExtension() const override { return "png"; } |
| 408 |
SinkFlags flags() const override { |
| 409 |
SinkFlags::Multisampled ms = fSampleCount > 1 ? SinkFlags::kMultisampled |
| 410 |
: SinkFlags::kNotMultisampled; |
| 411 |
return SinkFlags{ SinkFlags::kGPU, SinkFlags::kDirect, ms }; |
| 412 |
} |
| 413 |
const GrContextOptions& baseContextOptions() const { return fBaseContextOptions; } |
| 414 |
void setColorSpace(sk_sp<SkColorSpace> colorSpace) override { fColorSpace = colorSpace; } |
| 415 |
SkColorInfo colorInfo() const override { |
| 416 |
return SkColorInfo(fColorType, fAlphaType, fColorSpace); |
| 417 |
} |
| 418 |
|
| 419 |
protected: |
| 420 |
sk_sp<SkSurface> createDstSurface(GrDirectContext*, const Src&) const; |
| 421 |
bool readBack(SkSurface*, SkBitmap* dst) const; |
| 422 |
|
| 423 |
private: |
| 424 |
skgpu::ContextType fContextType; |
| 425 |
sk_gpu_test::GrContextFactory::ContextOverrides fContextOverrides; |
| 426 |
SkCommandLineConfigGpu::SurfType fSurfType; |
| 427 |
int fSampleCount; |
| 428 |
uint32_t fSurfaceFlags; |
| 429 |
SkColorType fColorType; |
| 430 |
SkAlphaType fAlphaType; |
| 431 |
sk_sp<SkColorSpace> fColorSpace; |
| 432 |
GrContextOptions fBaseContextOptions; |
| 433 |
sk_gpu_test::MemoryCache fMemoryCache; |
| 434 |
}; |
| 435 |
|
| 436 |
// Wrap a gpu canvas in one that routes all text draws through Slugs. |
| 437 |
// Note that text blobs that have an RSXForm aren't converted. |
| 438 |
class GPUSlugSink : public GPUSink { |
| 439 |
public: |
| 440 |
GPUSlugSink(const SkCommandLineConfigGpu*, const GrContextOptions&); |
| 441 |
|
| 442 |
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 443 |
}; |
| 444 |
|
| 445 |
class GPUSerializeSlugSink : public GPUSink { |
| 446 |
public: |
| 447 |
GPUSerializeSlugSink(const SkCommandLineConfigGpu*, const GrContextOptions&); |
| 448 |
|
| 449 |
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 450 |
}; |
| 451 |
|
| 452 |
class GPURemoteSlugSink : public GPUSink { |
| 453 |
public: |
| 454 |
GPURemoteSlugSink(const SkCommandLineConfigGpu*, const GrContextOptions&); |
| 455 |
|
| 456 |
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 457 |
}; |
| 458 |
|
| 459 |
class GPUPersistentCacheTestingSink : public GPUSink { |
| 460 |
public: |
| 461 |
GPUPersistentCacheTestingSink(const SkCommandLineConfigGpu*, const GrContextOptions&); |
| 462 |
|
| 463 |
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 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: |
| 471 |
int fCacheType; |
| 472 |
|
| 473 |
using INHERITED = GPUSink; |
| 474 |
}; |
| 475 |
|
| 476 |
class GaneshPrecompileTestingSink : public GPUSink { |
| 477 |
public: |
| 478 |
GaneshPrecompileTestingSink(const SkCommandLineConfigGpu*, const GrContextOptions&); |
| 479 |
|
| 480 |
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 481 |
|
| 482 |
const char* fileExtension() const override { |
| 483 |
// Suppress writing out results from this config - we just want to do our matching test |
| 484 |
return nullptr; |
| 485 |
} |
| 486 |
|
| 487 |
private: |
| 488 |
using INHERITED = GPUSink; |
| 489 |
}; |
| 490 |
|
| 491 |
// This sink attempts to better simulate the Chrome DDL use-case. It: |
| 492 |
// creates the DDLs on separate recording threads |
| 493 |
// performs all the GPU work on a separate GPU thread |
| 494 |
// In the future this should be expanded to: |
| 495 |
// upload on a utility thread w/ access to a shared context |
| 496 |
// compile the programs on the utility thread |
| 497 |
// perform fine grained scheduling of gpu tasks based on their image and program prerequisites |
| 498 |
// create a single "compositing" DDL that is replayed last |
| 499 |
class GPUDDLSink : public GPUSink { |
| 500 |
public: |
| 501 |
GPUDDLSink(const SkCommandLineConfigGpu*, const GrContextOptions&); |
| 502 |
|
| 503 |
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 504 |
|
| 505 |
private: |
| 506 |
Result ddlDraw(const Src&, |
| 507 |
sk_sp<SkSurface> dstSurface, |
| 508 |
SkTaskGroup* recordingTaskGroup, |
| 509 |
SkTaskGroup* gpuTaskGroup, |
| 510 |
sk_gpu_test::TestContext* gpuTestCtx, |
| 511 |
GrDirectContext* gpuThreadCtx) const; |
| 512 |
|
| 513 |
std::unique_ptr<SkExecutor> fRecordingExecutor; |
| 514 |
std::unique_ptr<SkExecutor> fGPUExecutor; |
| 515 |
|
| 516 |
using INHERITED = GPUSink; |
| 517 |
}; |
| 518 |
#endif |
| 519 |
|
| 520 |
class PDFSink : public Sink { |
| 521 |
public: |
| 522 |
PDFSink(bool pdfa, SkScalar rasterDpi) : fPDFA(pdfa), fRasterDpi(rasterDpi) {} |
| 523 |
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 524 |
const char* fileExtension() const override { return "pdf"; } |
| 525 |
SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
| 526 |
|
| 527 |
bool fPDFA; |
| 528 |
SkScalar fRasterDpi; |
| 529 |
}; |
| 530 |
|
| 531 |
class XPSSink : public Sink { |
| 532 |
public: |
| 533 |
XPSSink(); |
| 534 |
|
| 535 |
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 536 |
const char* fileExtension() const override { return "xps"; } |
| 537 |
SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
| 538 |
}; |
| 539 |
|
| 540 |
class RasterSink : public Sink { |
| 541 |
public: |
| 542 |
explicit RasterSink(SkColorType); |
| 543 |
|
| 544 |
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 545 |
const char* fileExtension() const override { return "png"; } |
| 546 |
SinkFlags flags() const override { return SinkFlags{ SinkFlags::kRaster, SinkFlags::kDirect }; } |
| 547 |
void setColorSpace(sk_sp<SkColorSpace> colorSpace) override { fColorSpace = colorSpace; } |
| 548 |
|
| 549 |
SkColorInfo colorInfo() const override { |
| 550 |
// If there's an appropriate alpha type for this color type, use it, otherwise use premul. |
| 551 |
SkAlphaType alphaType = kPremul_SkAlphaType; |
| 552 |
(void)SkColorTypeValidateAlphaType(fColorType, alphaType, &alphaType); |
| 553 |
|
| 554 |
return SkColorInfo(fColorType, alphaType, fColorSpace); |
| 555 |
} |
| 556 |
|
| 557 |
private: |
| 558 |
SkColorType fColorType; |
| 559 |
sk_sp<SkColorSpace> fColorSpace; |
| 560 |
}; |
| 561 |
|
| 562 |
class SKPSink : public Sink { |
| 563 |
public: |
| 564 |
SKPSink(); |
| 565 |
|
| 566 |
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 567 |
const char* fileExtension() const override { return "skp"; } |
| 568 |
SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
| 569 |
}; |
| 570 |
|
| 571 |
class DebugSink : public Sink { |
| 572 |
public: |
| 573 |
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 574 |
const char* fileExtension() const override { return "json"; } |
| 575 |
SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
| 576 |
}; |
| 577 |
|
| 578 |
class SVGSink : public Sink { |
| 579 |
public: |
| 580 |
explicit SVGSink(int pageIndex = 0); |
| 581 |
|
| 582 |
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 583 |
const char* fileExtension() const override { return "svg"; } |
| 584 |
SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; } |
| 585 |
|
| 586 |
private: |
| 587 |
int fPageIndex; |
| 588 |
}; |
| 589 |
|
| 590 |
#if defined(SK_GRAPHITE) |
| 591 |
|
| 592 |
class GraphiteSink : public Sink { |
| 593 |
public: |
| 594 |
GraphiteSink(const SkCommandLineConfigGraphite*, const skiatest::graphite::TestOptions&); |
| 595 |
|
| 596 |
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 597 |
bool serial() const override { return true; } |
| 598 |
const char* fileExtension() const override { return "png"; } |
| 599 |
SinkFlags flags() const override { return SinkFlags{SinkFlags::kGPU, SinkFlags::kDirect}; } |
| 600 |
void setColorSpace(sk_sp<SkColorSpace> colorSpace) override { fColorSpace = colorSpace; } |
| 601 |
SkColorInfo colorInfo() const override { |
| 602 |
return SkColorInfo(fColorType, fAlphaType, fColorSpace); |
| 603 |
} |
| 604 |
|
| 605 |
protected: |
| 606 |
sk_sp<SkSurface> makeSurface(skgpu::graphite::Recorder*, const Src&) const; |
| 607 |
|
| 608 |
skiatest::graphite::TestOptions fOptions; |
| 609 |
skgpu::ContextType fContextType; |
| 610 |
SkColorType fColorType; |
| 611 |
SkAlphaType fAlphaType; |
| 612 |
sk_sp<SkColorSpace> fColorSpace; |
| 613 |
}; |
| 614 |
|
| 615 |
class GraphitePersistentPipelineStorageTestingSink : public GraphiteSink { |
| 616 |
public: |
| 617 |
GraphitePersistentPipelineStorageTestingSink(const SkCommandLineConfigGraphite*, |
| 618 |
const skiatest::graphite::TestOptions&); |
| 619 |
|
| 620 |
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 621 |
|
| 622 |
const char* fileExtension() const override { |
| 623 |
// Suppress writing out results from this config - we just want to do our matching test |
| 624 |
return nullptr; |
| 625 |
} |
| 626 |
|
| 627 |
private: |
| 628 |
mutable sk_gpu_test::GraphiteMemoryPipelineStorage fMemoryPipelineStorage; |
| 629 |
}; |
| 630 |
|
| 631 |
// This Sink exercises the use case where Pipeline labels are tracked over the course of |
| 632 |
// many draws. It makes use of the ContextOptions::PipelineCachingCallback. |
| 633 |
class GraphitePipelineTrackingSink : public GraphiteSink { |
| 634 |
public: |
| 635 |
GraphitePipelineTrackingSink(const SkCommandLineConfigGraphite*, |
| 636 |
const skiatest::graphite::TestOptions&); |
| 637 |
|
| 638 |
void done() const override; |
| 639 |
|
| 640 |
const char* fileExtension() const override { |
| 641 |
// Suppress writing out results from this config - we just want to do our matching test |
| 642 |
return nullptr; |
| 643 |
} |
| 644 |
|
| 645 |
private: |
| 646 |
std::unique_ptr<skiatools::graphite::PipelineCallBackHandler> fPipelineHandler; |
| 647 |
}; |
| 648 |
|
| 649 |
#if defined(SK_ENABLE_PRECOMPILE) |
| 650 |
// In general this sink: |
| 651 |
// renders a gm, skp or svg (in drawSrc) |
| 652 |
// collects all the UniqueKeys | |
| 653 |
// clears the pipeline cache | (in resetAndRecreatePipelines) |
| 654 |
// recreates the pipelines from the UniqueKeys | |
| 655 |
// renders a second time (in drawSrc) |
| 656 |
// asserts that no new pipelines were created |
| 657 |
class GraphitePrecompileTestingSink : public GraphiteSink { |
| 658 |
public: |
| 659 |
GraphitePrecompileTestingSink(const SkCommandLineConfigGraphite*, |
| 660 |
const skiatest::graphite::TestOptions&); |
| 661 |
~GraphitePrecompileTestingSink() override; |
| 662 |
|
| 663 |
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 664 |
|
| 665 |
const char* fileExtension() const override { |
| 666 |
// Suppress writing out results from this config - we just want to check that |
| 667 |
// the precompilation API is expressive enough and prepopulates the cache. |
| 668 |
// If desired, this could be updated to save the result of the precompiled rendering. |
| 669 |
// However; if all the keys match, as is expected, the images should always match. |
| 670 |
return nullptr; |
| 671 |
} |
| 672 |
|
| 673 |
private: |
| 674 |
|
| 675 |
Result drawSrc(const Src&, |
| 676 |
skgpu::graphite::Context*, |
| 677 |
skiatest::graphite::GraphiteTestContext*, |
| 678 |
skgpu::graphite::Recorder*) const; |
| 679 |
|
| 680 |
Result resetAndRecreatePipelines(skgpu::graphite::PrecompileContext*) const; |
| 681 |
|
| 682 |
#ifdef SK_DEBUG |
| 683 |
static void LogMissingKey(skgpu::graphite::PrecompileContext*, |
| 684 |
const skgpu::UniqueKey& missingKey, |
| 685 |
const char* missingKeyName, |
| 686 |
const std::vector<skgpu::UniqueKey>& pool, |
| 687 |
const char* poolName); |
| 688 |
#endif |
| 689 |
|
| 690 |
static void CompareKeys(skgpu::graphite::PrecompileContext*, |
| 691 |
const std::vector<skgpu::UniqueKey>& vA, const char* aName, |
| 692 |
const std::vector<skgpu::UniqueKey>& vB, const char* bName); |
| 693 |
|
| 694 |
std::unique_ptr<skiatools::graphite::PipelineCallBackHandler> fPipelineHandler; |
| 695 |
}; |
| 696 |
#endif // SK_ENABLE_PRECOMPILE |
| 697 |
#endif // SK_GRAPHITE |
| 698 |
|
| 699 |
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ |
| 700 |
|
| 701 |
class Via : public Sink { |
| 702 |
public: |
| 703 |
explicit Via(Sink* sink) : fSink(sink) {} |
| 704 |
const char* fileExtension() const override { return fSink->fileExtension(); } |
| 705 |
bool serial() const override { return fSink->serial(); } |
| 706 |
SinkFlags flags() const override { |
| 707 |
SinkFlags flags = fSink->flags(); |
| 708 |
flags.approach = SinkFlags::kIndirect; |
| 709 |
return flags; |
| 710 |
} |
| 711 |
void setColorSpace(sk_sp<SkColorSpace> colorSpace) override { |
| 712 |
fSink->setColorSpace(colorSpace); |
| 713 |
} |
| 714 |
protected: |
| 715 |
std::unique_ptr<Sink> fSink; |
| 716 |
}; |
| 717 |
|
| 718 |
class ViaMatrix : public Via { |
| 719 |
public: |
| 720 |
ViaMatrix(SkMatrix, Sink*); |
| 721 |
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 722 |
|
| 723 |
private: |
| 724 |
const SkMatrix fMatrix; |
| 725 |
}; |
| 726 |
|
| 727 |
class ViaUpright : public Via { |
| 728 |
public: |
| 729 |
ViaUpright(SkMatrix, Sink*); |
| 730 |
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 731 |
|
| 732 |
private: |
| 733 |
const SkMatrix fMatrix; |
| 734 |
}; |
| 735 |
|
| 736 |
class ViaSerialization : public Via { |
| 737 |
public: |
| 738 |
explicit ViaSerialization(Sink* sink) : Via(sink) {} |
| 739 |
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 740 |
}; |
| 741 |
|
| 742 |
class ViaPicture : public Via { |
| 743 |
public: |
| 744 |
explicit ViaPicture(Sink* sink) : Via(sink) {} |
| 745 |
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 746 |
}; |
| 747 |
|
| 748 |
class ViaRuntimeBlend : public Via { |
| 749 |
public: |
| 750 |
explicit ViaRuntimeBlend(Sink* sink) : Via(sink) {} |
| 751 |
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 752 |
}; |
| 753 |
|
| 754 |
class ViaSVG : public Via { |
| 755 |
public: |
| 756 |
explicit ViaSVG(Sink* sink) : Via(sink) {} |
| 757 |
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override; |
| 758 |
}; |
| 759 |
|
| 760 |
} // namespace DM |
| 761 |
|
| 762 |
#endif//DMSrcSink_DEFINED |