skia2/dm/DMSrcSink.h

648 lines
21 KiB
C
Raw Normal View History

/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef DMSrcSink_DEFINED
#define DMSrcSink_DEFINED
#include "gm/gm.h"
#include "include/core/SkBBHFactory.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkData.h"
#include "include/core/SkPicture.h"
#include "src/utils/SkMultiPictureDocument.h"
#include "tools/flags/CommonFlagsConfig.h"
#include "tools/gpu/MemoryCache.h"
Add support for pre-compiling cached SkSL shaders The client can do a test run of their application with a persistent cache set to SkSL mode. They store the key and data blobs that are produced. Ship those blobs with the application. At startup, call GrContext::precompileShader for each key/data pair. This compiles the shaders, and stores the GL program ID, plus a small amount of metadata in our runtime program cache. Caveats: * Currently only implemented for the GL backend. Other backends will require more metadata to do any useful amount of work. Metal may need a more drastic workflow change, involving offline compilation of the shaders. * Currently only implemented for cached SkSL (not GLSL or program binaries). Supporting other formats again requires more metadata, and the cached shaders become increasingly specialized to GPU and driver versions. * Reusing the cached SkSL on different hardware is not supported. Many driver workarounds are implemented in the SkSL -> GLSL transformation, but some are higher level. Limiting device variance by artificially hiding extensions may help, but there are no guarantees. * The 'gltestprecompile' DM config exercises this code similarly to 'gltestpersistentcache', ensuring that results are visually identical when precompiling, and that no cache misses occur after precompiling. Change-Id: Id314c5d5f5a58fe503a0505a613bd4a540cc3589 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/239438 Reviewed-by: Greg Daniel <egdaniel@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
2019-09-06 18:42:43 +00:00
#include <functional>
//#define TEST_VIA_SVG
namespace skiagm {
namespace verifiers {
class VerifierList;
} // namespace verifiers
} // namespace skiagm
namespace DM {
// This is just convenience. It lets you use either return "foo" or return SkStringPrintf(...).
struct ImplicitString : public SkString {
template <typename T>
ImplicitString(const T& s) : SkString(s) {}
ImplicitString() : SkString("") {}
};
typedef ImplicitString Name;
typedef ImplicitString Path;
Replace DM:Error with DM::Result. Initially, Error was written with the intent that an empty string meant Ok and anything else meant Fatal. This made things simple with implicit constructors from strings. With the introduction of Nonfatal the state was now tied up with an additional boolean. Now the empty string meant Ok and causes the new boolean to be ignored, or at least that is the way it was used since Error didn't actually enforce that itself. This leads to GMs which return kSkip but don't set the message to not be skipped. This could be fixed in several ways. The first would be for the GMSrc to notice that a GM had returned kSkip with an empty message and create the Error::Nonfatal with a non-empty message. This has the downside of being some extra unexpected complexity and doesn't prevent similar issues from arising in the future. The second would be to change how DM interprets the Error, and if the non-fatal bit is set treat that as a sign to skip, even if the message is empty. This fixes the stated issue, but doesn't fix the issue where a GM can return kFail but also leave the message empty. This could again be fixed by either modifying GMSrc::draw or GM::drawContent, but this also seems a bit brittle in not preventing this from happening again in the future. So this replaces Error with Result, which makes the status orthogonal to the message. It does lose the automatic conversion from string, but by being able to wrap the many uses of SkStringPrintf the explicit nature doesn't add much additional noise to the more complex failure reports. Change-Id: Ibf48b67faa09a91a4a9d792d204bd9810b441c6c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270362 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
2020-02-12 16:18:46 +00:00
class Result {
public:
Replace DM:Error with DM::Result. Initially, Error was written with the intent that an empty string meant Ok and anything else meant Fatal. This made things simple with implicit constructors from strings. With the introduction of Nonfatal the state was now tied up with an additional boolean. Now the empty string meant Ok and causes the new boolean to be ignored, or at least that is the way it was used since Error didn't actually enforce that itself. This leads to GMs which return kSkip but don't set the message to not be skipped. This could be fixed in several ways. The first would be for the GMSrc to notice that a GM had returned kSkip with an empty message and create the Error::Nonfatal with a non-empty message. This has the downside of being some extra unexpected complexity and doesn't prevent similar issues from arising in the future. The second would be to change how DM interprets the Error, and if the non-fatal bit is set treat that as a sign to skip, even if the message is empty. This fixes the stated issue, but doesn't fix the issue where a GM can return kFail but also leave the message empty. This could again be fixed by either modifying GMSrc::draw or GM::drawContent, but this also seems a bit brittle in not preventing this from happening again in the future. So this replaces Error with Result, which makes the status orthogonal to the message. It does lose the automatic conversion from string, but by being able to wrap the many uses of SkStringPrintf the explicit nature doesn't add much additional noise to the more complex failure reports. Change-Id: Ibf48b67faa09a91a4a9d792d204bd9810b441c6c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270362 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
2020-02-12 16:18:46 +00:00
enum class Status : int { Ok, Fatal, Skip };
Result(Status status, const SkString& s) : fMsg(s), fStatus(status) {}
Result(Status status, const char* s) : fMsg(s), fStatus(status) {}
template <typename... Args> Result (Status status, const char* s, Args... args)
: fMsg(SkStringPrintf(s, args...)), fStatus(status) {}
Replace DM:Error with DM::Result. Initially, Error was written with the intent that an empty string meant Ok and anything else meant Fatal. This made things simple with implicit constructors from strings. With the introduction of Nonfatal the state was now tied up with an additional boolean. Now the empty string meant Ok and causes the new boolean to be ignored, or at least that is the way it was used since Error didn't actually enforce that itself. This leads to GMs which return kSkip but don't set the message to not be skipped. This could be fixed in several ways. The first would be for the GMSrc to notice that a GM had returned kSkip with an empty message and create the Error::Nonfatal with a non-empty message. This has the downside of being some extra unexpected complexity and doesn't prevent similar issues from arising in the future. The second would be to change how DM interprets the Error, and if the non-fatal bit is set treat that as a sign to skip, even if the message is empty. This fixes the stated issue, but doesn't fix the issue where a GM can return kFail but also leave the message empty. This could again be fixed by either modifying GMSrc::draw or GM::drawContent, but this also seems a bit brittle in not preventing this from happening again in the future. So this replaces Error with Result, which makes the status orthogonal to the message. It does lose the automatic conversion from string, but by being able to wrap the many uses of SkStringPrintf the explicit nature doesn't add much additional noise to the more complex failure reports. Change-Id: Ibf48b67faa09a91a4a9d792d204bd9810b441c6c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270362 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
2020-02-12 16:18:46 +00:00
Result(const Result&) = default;
Result& operator=(const Result&) = default;
Replace DM:Error with DM::Result. Initially, Error was written with the intent that an empty string meant Ok and anything else meant Fatal. This made things simple with implicit constructors from strings. With the introduction of Nonfatal the state was now tied up with an additional boolean. Now the empty string meant Ok and causes the new boolean to be ignored, or at least that is the way it was used since Error didn't actually enforce that itself. This leads to GMs which return kSkip but don't set the message to not be skipped. This could be fixed in several ways. The first would be for the GMSrc to notice that a GM had returned kSkip with an empty message and create the Error::Nonfatal with a non-empty message. This has the downside of being some extra unexpected complexity and doesn't prevent similar issues from arising in the future. The second would be to change how DM interprets the Error, and if the non-fatal bit is set treat that as a sign to skip, even if the message is empty. This fixes the stated issue, but doesn't fix the issue where a GM can return kFail but also leave the message empty. This could again be fixed by either modifying GMSrc::draw or GM::drawContent, but this also seems a bit brittle in not preventing this from happening again in the future. So this replaces Error with Result, which makes the status orthogonal to the message. It does lose the automatic conversion from string, but by being able to wrap the many uses of SkStringPrintf the explicit nature doesn't add much additional noise to the more complex failure reports. Change-Id: Ibf48b67faa09a91a4a9d792d204bd9810b441c6c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270362 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
2020-02-12 16:18:46 +00:00
static Result Ok() { return Result(Status::Ok, nullptr); }
static Result Fatal(const SkString& s) { return Result(Status::Fatal, s); }
static Result Fatal(const char* s) { return Result(Status::Fatal, s); }
template <typename... Args> static Result Fatal(const char* s, Args... args) {
return Result(Status::Fatal, s, args...);
}
static Result Skip(const SkString& s) { return Result(Status::Skip, s); }
static Result Skip(const char* s) { return Result(Status::Skip, s); }
template <typename... Args> static Result Skip(const char* s, Args... args) {
return Result(Status::Skip, s, args...);
}
Replace DM:Error with DM::Result. Initially, Error was written with the intent that an empty string meant Ok and anything else meant Fatal. This made things simple with implicit constructors from strings. With the introduction of Nonfatal the state was now tied up with an additional boolean. Now the empty string meant Ok and causes the new boolean to be ignored, or at least that is the way it was used since Error didn't actually enforce that itself. This leads to GMs which return kSkip but don't set the message to not be skipped. This could be fixed in several ways. The first would be for the GMSrc to notice that a GM had returned kSkip with an empty message and create the Error::Nonfatal with a non-empty message. This has the downside of being some extra unexpected complexity and doesn't prevent similar issues from arising in the future. The second would be to change how DM interprets the Error, and if the non-fatal bit is set treat that as a sign to skip, even if the message is empty. This fixes the stated issue, but doesn't fix the issue where a GM can return kFail but also leave the message empty. This could again be fixed by either modifying GMSrc::draw or GM::drawContent, but this also seems a bit brittle in not preventing this from happening again in the future. So this replaces Error with Result, which makes the status orthogonal to the message. It does lose the automatic conversion from string, but by being able to wrap the many uses of SkStringPrintf the explicit nature doesn't add much additional noise to the more complex failure reports. Change-Id: Ibf48b67faa09a91a4a9d792d204bd9810b441c6c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270362 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
2020-02-12 16:18:46 +00:00
bool isOk() { return fStatus == Status::Ok; }
bool isFatal() { return fStatus == Status::Fatal; }
bool isSkip() { return fStatus == Status::Skip; }
const char* c_str() const { return fMsg.c_str(); }
Replace DM:Error with DM::Result. Initially, Error was written with the intent that an empty string meant Ok and anything else meant Fatal. This made things simple with implicit constructors from strings. With the introduction of Nonfatal the state was now tied up with an additional boolean. Now the empty string meant Ok and causes the new boolean to be ignored, or at least that is the way it was used since Error didn't actually enforce that itself. This leads to GMs which return kSkip but don't set the message to not be skipped. This could be fixed in several ways. The first would be for the GMSrc to notice that a GM had returned kSkip with an empty message and create the Error::Nonfatal with a non-empty message. This has the downside of being some extra unexpected complexity and doesn't prevent similar issues from arising in the future. The second would be to change how DM interprets the Error, and if the non-fatal bit is set treat that as a sign to skip, even if the message is empty. This fixes the stated issue, but doesn't fix the issue where a GM can return kFail but also leave the message empty. This could again be fixed by either modifying GMSrc::draw or GM::drawContent, but this also seems a bit brittle in not preventing this from happening again in the future. So this replaces Error with Result, which makes the status orthogonal to the message. It does lose the automatic conversion from string, but by being able to wrap the many uses of SkStringPrintf the explicit nature doesn't add much additional noise to the more complex failure reports. Change-Id: Ibf48b67faa09a91a4a9d792d204bd9810b441c6c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270362 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
2020-02-12 16:18:46 +00:00
Status status() const { return fStatus; }
private:
SkString fMsg;
Replace DM:Error with DM::Result. Initially, Error was written with the intent that an empty string meant Ok and anything else meant Fatal. This made things simple with implicit constructors from strings. With the introduction of Nonfatal the state was now tied up with an additional boolean. Now the empty string meant Ok and causes the new boolean to be ignored, or at least that is the way it was used since Error didn't actually enforce that itself. This leads to GMs which return kSkip but don't set the message to not be skipped. This could be fixed in several ways. The first would be for the GMSrc to notice that a GM had returned kSkip with an empty message and create the Error::Nonfatal with a non-empty message. This has the downside of being some extra unexpected complexity and doesn't prevent similar issues from arising in the future. The second would be to change how DM interprets the Error, and if the non-fatal bit is set treat that as a sign to skip, even if the message is empty. This fixes the stated issue, but doesn't fix the issue where a GM can return kFail but also leave the message empty. This could again be fixed by either modifying GMSrc::draw or GM::drawContent, but this also seems a bit brittle in not preventing this from happening again in the future. So this replaces Error with Result, which makes the status orthogonal to the message. It does lose the automatic conversion from string, but by being able to wrap the many uses of SkStringPrintf the explicit nature doesn't add much additional noise to the more complex failure reports. Change-Id: Ibf48b67faa09a91a4a9d792d204bd9810b441c6c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270362 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
2020-02-12 16:18:46 +00:00
Status fStatus;
};
struct SinkFlags {
enum Type { kNull, kGPU, kVector, kRaster } type;
enum Approach { kDirect, kIndirect } approach;
enum Multisampled { kNotMultisampled, kMultisampled } multisampled;
SinkFlags(Type t, Approach a, Multisampled ms = kNotMultisampled)
: type(t), approach(a), multisampled(ms) {}
};
struct Src {
virtual ~Src() {}
virtual Result SK_WARN_UNUSED_RESULT draw(GrDirectContext*, SkCanvas*) const = 0;
virtual SkISize size() const = 0;
virtual Name name() const = 0;
virtual void modifyGrContextOptions(GrContextOptions* options) const {}
virtual bool veto(SinkFlags) const { return false; }
virtual int pageCount() const { return 1; }
virtual Result SK_WARN_UNUSED_RESULT draw(int, GrDirectContext* context,
SkCanvas* canvas) const {
return this->draw(context, canvas);
}
virtual SkISize size(int) const { return this->size(); }
// Force Tasks using this Src to run on the main thread?
virtual bool serial() const { return false; }
/** Return a list of verifiers for the src, or null if no verifiers should be run .*/
virtual std::unique_ptr<skiagm::verifiers::VerifierList> getVerifiers() const {
return nullptr;
}
};
struct Sink {
virtual ~Sink() {}
// You may write to either the bitmap or stream. If you write to log, we'll print that out.
Replace DM:Error with DM::Result. Initially, Error was written with the intent that an empty string meant Ok and anything else meant Fatal. This made things simple with implicit constructors from strings. With the introduction of Nonfatal the state was now tied up with an additional boolean. Now the empty string meant Ok and causes the new boolean to be ignored, or at least that is the way it was used since Error didn't actually enforce that itself. This leads to GMs which return kSkip but don't set the message to not be skipped. This could be fixed in several ways. The first would be for the GMSrc to notice that a GM had returned kSkip with an empty message and create the Error::Nonfatal with a non-empty message. This has the downside of being some extra unexpected complexity and doesn't prevent similar issues from arising in the future. The second would be to change how DM interprets the Error, and if the non-fatal bit is set treat that as a sign to skip, even if the message is empty. This fixes the stated issue, but doesn't fix the issue where a GM can return kFail but also leave the message empty. This could again be fixed by either modifying GMSrc::draw or GM::drawContent, but this also seems a bit brittle in not preventing this from happening again in the future. So this replaces Error with Result, which makes the status orthogonal to the message. It does lose the automatic conversion from string, but by being able to wrap the many uses of SkStringPrintf the explicit nature doesn't add much additional noise to the more complex failure reports. Change-Id: Ibf48b67faa09a91a4a9d792d204bd9810b441c6c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270362 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
2020-02-12 16:18:46 +00:00
virtual Result SK_WARN_UNUSED_RESULT draw(const Src&, SkBitmap*, SkWStream*, SkString* log)
const = 0;
// Force Tasks using this Sink to run on the main thread?
virtual bool serial() const { return false; }
// File extension for the content draw() outputs, e.g. "png", "pdf".
virtual const char* fileExtension() const = 0;
virtual SinkFlags flags() const = 0;
/** Returns the color type and space used by the sink. */
virtual SkColorInfo colorInfo() const { return SkColorInfo(); }
};
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
class GMSrc : public Src {
public:
explicit GMSrc(skiagm::GMFactory);
Result draw(GrDirectContext*, SkCanvas*) const override;
SkISize size() const override;
Name name() const override;
void modifyGrContextOptions(GrContextOptions* options) const override;
std::unique_ptr<skiagm::verifiers::VerifierList> getVerifiers() const override;
private:
skiagm::GMFactory fFactory;
};
class CodecSrc : public Src {
public:
enum Mode {
kCodec_Mode,
// We choose to test only one mode with zero initialized memory.
// This will exercise all of the interesting cases in SkSwizzler
// without doubling the size of our test suite.
kCodecZeroInit_Mode,
kScanline_Mode,
kStripe_Mode, // Tests the skipping of scanlines
kCroppedScanline_Mode, // Tests (jpeg) cropped scanline optimization
kSubset_Mode, // For codecs that support subsets directly.
Add support for multiple frames in SkCodec Add an interface to decode frames beyond the first in SkCodec, and add an implementation for SkGifCodec. Add getFrameData to SkCodec. This method reads ahead in the stream to return a vector containing meta data about each frame in the image. This is not required in order to decode frames beyond the first, but it allows a client to learn extra information: - how long the frame should be displayed - whether a frame should be blended with a prior frame, allowing the client to provide the prior frame to speed up decoding Add a new fields to SkCodec::Options: - fFrameIndex - fHasPriorFrame The API is designed so that SkCodec never caches frames. If a client wants a frame beyond the first, they specify the frame in Options.fFrameIndex. If the client does not have the frame's required frame (the frame that this frame must be blended on top of) cached, they pass false for Options.fHasPriorFrame. Unless the frame is independent, the codec will then recursively decode all frames necessary to decode fFrameIndex. If the client has the required frame cached, they can put it in the dst they pass to the codec, and the codec will only draw fFrameIndex onto it. Replace SkGifCodec's scanline decoding support with progressive decoding, and update the tests accordingly. Implement new APIs in SkGifCodec. Instead of using gif_lib, use GIFImageReader, imported from Chromium (along with its copyright headers) with the following changes: - SkGifCodec is now the client - Replace blink types - Combine GIFColorMap::buildTable and ::getTable into a method that creates and returns an SkColorTable - Input comes from an SkStream, instead of a SegmentReader. Add SkStreamBuffer, which buffers the (potentially partial) stream in order to decode progressively. (FIXME: This requires copying data that previously was read directly from the SegmentReader. Does this hurt performance? If so, can we fix it?) - Remove UMA code - Instead of reporting screen width and height to the client, allow the client to query for it - Fail earlier if the first frame AND screen have size of zero - Compute required previous frame when adding a new one - Move GIFParseQuery from GIFImageDecoder to GIFImageReader - Allow parsing up to a specific frame (to skip parsing the rest of the stream if a client only wants the first frame) - Compute whether the first frame has alpha and supports index 8, to create the SkImageInfo. This happens before reporting that the size has been decoded. Add GIFImageDecoder::haveDecodedRow to SkGifCodec, imported from Chromium (along with its copyright header), with the following changes: - Add support for sampling - Use the swizzler - Keep track of the rows decoded - Do *not* keep track of whether we've seen alpha Remove SkCodec::kOutOfOrder_SkScanlineOrder, which was only used by GIF scanline decoding. Call onRewind even if there is no stream (SkGifCodec needs to clear its decoded state so it will decode from the beginning). Add a method to SkSwizzler to access the offset into the dst, taking subsetting into account. Add a GM that animates a GIF. Add tests for the new APIs. *** Behavior changes: * Previously, we reported that an image with a subset frame and no transparent index was opaque and used the background index (if present) to fill the background. This is necessary in order to support index 8, but it does not match viewers/browsers I have seen. Examples: - Chromium and Gimp render the background transparent - Firefox, Safari, Linux Image Viewer, Safari Preview clip to the frame (for a single frame image) This CL matches Chromium's behavior and renders the background transparent. This allows us to have consistent behavior across products and simplifies the code (relative to what we would have to do to continue the old behavior on Android). It also means that we will no longer support index 8 for some GIFs. * Stop checking for GIFSTAMP - all GIFs should be either 89a or 87a. This matches Chromium. I suspect that bugs would have been reported if valid GIFs started with "GIFVER" instead of "GIF89a" or "GIF87a" (but did not decode in Chromium). *** Future work not included in this CL: * Move some checks out of haveDecodedRow, since they are the same for the entire frame e.g. - intersecting the frameRect with the full image size - whether there is a color table * Change when we write transparent pixels - In some cases, Chromium deemed this unnecessary, but I suspect it is slower than the fallback case. There will continue to be cases where we should *not* write them, but for e.g. the first pass where we have already cleared to transparent (which we may also be able to skip) writing the transparent pixels will not make anything incorrect. * Report color type and alpha type per frame - Depending on alpha values, disposal methods, frame rects, etc, subsequent frames may have different properties than the first. * Skip copies of the encoded data - We copy the encoded data in case the stream is one that cannot be rewound, so we can parse and then decode (possibly not immediately). For some input streams, this is unnecessary. - I was concerned this cause a performance regression, but on average the new code is faster than the old for the images I tested [1]. - It may cause a performance regression for Chromium, though, where we can always move back in the stream, so this should be addressed. Design doc: https://docs.google.com/a/google.com/document/d/12Qhf9T92MWfdWujQwCIjhCO3sw6pTJB5pJBwDM1T7Kc/ [1] https://docs.google.com/a/google.com/spreadsheets/d/19V-t9BfbFw5eiwBTKA1qOBkZbchjlTC5EIz6HFy-6RI/ GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=2045293002 Review-Url: https://codereview.chromium.org/2045293002
2016-10-24 16:03:26 +00:00
kAnimated_Mode, // For codecs that support animation.
};
enum DstColorType {
kGetFromCanvas_DstColorType,
kGrayscale_Always_DstColorType,
kNonNative8888_Always_DstColorType,
};
CodecSrc(Path, Mode, DstColorType, SkAlphaType, float);
Result draw(GrDirectContext*, SkCanvas*) const override;
SkISize size() const override;
Name name() const override;
bool veto(SinkFlags) const override;
bool serial() const override { return fRunSerially; }
private:
Path fPath;
Mode fMode;
DstColorType fDstColorType;
SkAlphaType fDstAlphaType;
float fScale;
bool fRunSerially;
};
class AndroidCodecSrc : public Src {
public:
AndroidCodecSrc(Path, CodecSrc::DstColorType, SkAlphaType, int sampleSize);
Result draw(GrDirectContext*, SkCanvas*) const override;
SkISize size() const override;
Name name() const override;
bool veto(SinkFlags) const override;
bool serial() const override { return fRunSerially; }
private:
Path fPath;
CodecSrc::DstColorType fDstColorType;
SkAlphaType fDstAlphaType;
int fSampleSize;
bool fRunSerially;
};
#ifdef SK_ENABLE_ANDROID_UTILS
// Allows for testing of various implementations of Android's BitmapRegionDecoder
class BRDSrc : public Src {
public:
enum Mode {
// Decode the entire image as one region.
kFullImage_Mode,
// Splits the image into multiple regions using a divisor and decodes the regions
// separately. Also, this test adds a border of a few pixels to each of the regions
// that it is decoding. This tests the behavior when a client asks for a region that
// does not fully fit in the image.
kDivisor_Mode,
};
BRDSrc(Path, Mode, CodecSrc::DstColorType, uint32_t);
Result draw(GrDirectContext*, SkCanvas*) const override;
SkISize size() const override;
Name name() const override;
bool veto(SinkFlags) const override;
private:
Path fPath;
Mode fMode;
CodecSrc::DstColorType fDstColorType;
uint32_t fSampleSize;
};
#endif
class ImageGenSrc : public Src {
public:
enum Mode {
kCodec_Mode, // Use CodecImageGenerator
kPlatform_Mode, // Uses CG or WIC
};
ImageGenSrc(Path, Mode, SkAlphaType, bool);
Result draw(GrDirectContext*, SkCanvas*) const override;
SkISize size() const override;
Name name() const override;
bool veto(SinkFlags) const override;
bool serial() const override { return fRunSerially; }
private:
Path fPath;
Mode fMode;
SkAlphaType fDstAlphaType;
bool fIsGpu;
bool fRunSerially;
};
class ColorCodecSrc : public Src {
public:
ColorCodecSrc(Path, bool decode_to_dst);
Result draw(GrDirectContext*, SkCanvas*) const override;
SkISize size() const override;
Name name() const override;
bool veto(SinkFlags) const override;
private:
Path fPath;
bool fDecodeToDst;
};
class SKPSrc : public Src {
public:
explicit SKPSrc(Path path);
Result draw(GrDirectContext*, SkCanvas*) const override;
SkISize size() const override;
Name name() const override;
private:
Path fPath;
};
// This class extracts all the paths from an SKP and then removes unwanted paths according to the
// provided l/r trail. It then just draws the remaining paths. (Non-path draws are thrown out.) It
// is useful for finding a reduced repo case for path drawing bugs.
class BisectSrc : public SKPSrc {
public:
explicit BisectSrc(Path path, const char* trail);
Result draw(GrDirectContext*, SkCanvas*) const override;
private:
SkString fTrail;
typedef SKPSrc INHERITED;
};
#if defined(SK_ENABLE_SKOTTIE)
class SkottieSrc final : public Src {
public:
explicit SkottieSrc(Path path);
Result draw(GrDirectContext*, SkCanvas*) const override;
SkISize size() const override;
Name name() const override;
bool veto(SinkFlags) const override;
private:
// Generates a kTileCount x kTileCount filmstrip with evenly distributed frames.
static constexpr int kTileCount = 5;
// Fit kTileCount x kTileCount frames to a 1000x1000 film strip.
static constexpr SkScalar kTargetSize = 1000;
static constexpr SkScalar kTileSize = kTargetSize / kTileCount;
Path fPath;
};
#endif
#if defined(SK_ENABLE_SKRIVE)
class SkRiveSrc final : public Src {
public:
explicit SkRiveSrc(Path path);
Result draw(GrDirectContext*, SkCanvas*) const override;
SkISize size() const override;
Name name() const override;
bool veto(SinkFlags) const override;
private:
// Generates a kTileCount x kTileCount filmstrip with evenly distributed frames.
static constexpr int kTileCount = 5;
// Fit kTileCount x kTileCount frames to a 1000x1000 film strip.
static constexpr SkScalar kTargetSize = 1000;
static constexpr SkScalar kTileSize = kTargetSize / kTileCount;
const Path fPath;
};
#endif
#if defined(SK_XML)
} // namespace DM
class SkSVGDOM;
namespace DM {
class SVGSrc : public Src {
public:
explicit SVGSrc(Path path);
Result draw(GrDirectContext*, SkCanvas*) const override;
SkISize size() const override;
Name name() const override;
bool veto(SinkFlags) const override;
private:
Name fName;
sk_sp<SkSVGDOM> fDom;
SkScalar fScale;
typedef Src INHERITED;
};
#endif // SK_XML
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
class MSKPSrc : public Src {
public:
explicit MSKPSrc(Path path);
int pageCount() const override;
Result draw(GrDirectContext*, SkCanvas* c) const override;
Result draw(int, GrDirectContext*, SkCanvas*) const override;
SkISize size() const override;
SkISize size(int) const override;
Name name() const override;
private:
Path fPath;
mutable SkTArray<SkDocumentPage> fPages;
};
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
class NullSink : public Sink {
public:
NullSink() {}
Replace DM:Error with DM::Result. Initially, Error was written with the intent that an empty string meant Ok and anything else meant Fatal. This made things simple with implicit constructors from strings. With the introduction of Nonfatal the state was now tied up with an additional boolean. Now the empty string meant Ok and causes the new boolean to be ignored, or at least that is the way it was used since Error didn't actually enforce that itself. This leads to GMs which return kSkip but don't set the message to not be skipped. This could be fixed in several ways. The first would be for the GMSrc to notice that a GM had returned kSkip with an empty message and create the Error::Nonfatal with a non-empty message. This has the downside of being some extra unexpected complexity and doesn't prevent similar issues from arising in the future. The second would be to change how DM interprets the Error, and if the non-fatal bit is set treat that as a sign to skip, even if the message is empty. This fixes the stated issue, but doesn't fix the issue where a GM can return kFail but also leave the message empty. This could again be fixed by either modifying GMSrc::draw or GM::drawContent, but this also seems a bit brittle in not preventing this from happening again in the future. So this replaces Error with Result, which makes the status orthogonal to the message. It does lose the automatic conversion from string, but by being able to wrap the many uses of SkStringPrintf the explicit nature doesn't add much additional noise to the more complex failure reports. Change-Id: Ibf48b67faa09a91a4a9d792d204bd9810b441c6c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270362 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
2020-02-12 16:18:46 +00:00
Result draw(const Src& src, SkBitmap*, SkWStream*, SkString*) const override;
const char* fileExtension() const override { return ""; }
SinkFlags flags() const override { return SinkFlags{ SinkFlags::kNull, SinkFlags::kDirect }; }
};
class GPUSink : public Sink {
public:
GPUSink(const SkCommandLineConfigGpu*, const GrContextOptions&);
Replace DM:Error with DM::Result. Initially, Error was written with the intent that an empty string meant Ok and anything else meant Fatal. This made things simple with implicit constructors from strings. With the introduction of Nonfatal the state was now tied up with an additional boolean. Now the empty string meant Ok and causes the new boolean to be ignored, or at least that is the way it was used since Error didn't actually enforce that itself. This leads to GMs which return kSkip but don't set the message to not be skipped. This could be fixed in several ways. The first would be for the GMSrc to notice that a GM had returned kSkip with an empty message and create the Error::Nonfatal with a non-empty message. This has the downside of being some extra unexpected complexity and doesn't prevent similar issues from arising in the future. The second would be to change how DM interprets the Error, and if the non-fatal bit is set treat that as a sign to skip, even if the message is empty. This fixes the stated issue, but doesn't fix the issue where a GM can return kFail but also leave the message empty. This could again be fixed by either modifying GMSrc::draw or GM::drawContent, but this also seems a bit brittle in not preventing this from happening again in the future. So this replaces Error with Result, which makes the status orthogonal to the message. It does lose the automatic conversion from string, but by being able to wrap the many uses of SkStringPrintf the explicit nature doesn't add much additional noise to the more complex failure reports. Change-Id: Ibf48b67faa09a91a4a9d792d204bd9810b441c6c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270362 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
2020-02-12 16:18:46 +00:00
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
Result onDraw(const Src&, SkBitmap*, SkWStream*, SkString*,
const GrContextOptions& baseOptions,
std::function<void(GrContext*)> initContext = nullptr) const;
sk_gpu_test::GrContextFactory::ContextType contextType() const { return fContextType; }
const sk_gpu_test::GrContextFactory::ContextOverrides& contextOverrides() const {
return fContextOverrides;
}
SkCommandLineConfigGpu::SurfType surfType() const { return fSurfType; }
bool useDIText() const { return fUseDIText; }
bool serial() const override { return true; }
const char* fileExtension() const override { return "png"; }
SinkFlags flags() const override {
SinkFlags::Multisampled ms = fSampleCount > 1 ? SinkFlags::kMultisampled
: SinkFlags::kNotMultisampled;
return SinkFlags{ SinkFlags::kGPU, SinkFlags::kDirect, ms };
}
const GrContextOptions& baseContextOptions() const { return fBaseContextOptions; }
SkColorInfo colorInfo() const override {
return SkColorInfo(fColorType, fAlphaType, fColorSpace);
}
protected:
sk_sp<SkSurface> createDstSurface(GrDirectContext*, SkISize size, GrBackendTexture*,
GrBackendRenderTarget*) const;
bool readBack(SkSurface*, SkBitmap* dst) const;
private:
sk_gpu_test::GrContextFactory::ContextType fContextType;
sk_gpu_test::GrContextFactory::ContextOverrides fContextOverrides;
SkCommandLineConfigGpu::SurfType fSurfType;
int fSampleCount;
bool fUseDIText;
SkColorType fColorType;
SkAlphaType fAlphaType;
sk_sp<SkColorSpace> fColorSpace;
GrContextOptions fBaseContextOptions;
sk_gpu_test::MemoryCache fMemoryCache;
};
class GPUThreadTestingSink : public GPUSink {
public:
GPUThreadTestingSink(const SkCommandLineConfigGpu*, const GrContextOptions&);
Replace DM:Error with DM::Result. Initially, Error was written with the intent that an empty string meant Ok and anything else meant Fatal. This made things simple with implicit constructors from strings. With the introduction of Nonfatal the state was now tied up with an additional boolean. Now the empty string meant Ok and causes the new boolean to be ignored, or at least that is the way it was used since Error didn't actually enforce that itself. This leads to GMs which return kSkip but don't set the message to not be skipped. This could be fixed in several ways. The first would be for the GMSrc to notice that a GM had returned kSkip with an empty message and create the Error::Nonfatal with a non-empty message. This has the downside of being some extra unexpected complexity and doesn't prevent similar issues from arising in the future. The second would be to change how DM interprets the Error, and if the non-fatal bit is set treat that as a sign to skip, even if the message is empty. This fixes the stated issue, but doesn't fix the issue where a GM can return kFail but also leave the message empty. This could again be fixed by either modifying GMSrc::draw or GM::drawContent, but this also seems a bit brittle in not preventing this from happening again in the future. So this replaces Error with Result, which makes the status orthogonal to the message. It does lose the automatic conversion from string, but by being able to wrap the many uses of SkStringPrintf the explicit nature doesn't add much additional noise to the more complex failure reports. Change-Id: Ibf48b67faa09a91a4a9d792d204bd9810b441c6c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270362 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
2020-02-12 16:18:46 +00:00
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
const char* fileExtension() const override {
// Suppress writing out results from this config - we just want to do our matching test
return nullptr;
}
private:
std::unique_ptr<SkExecutor> fExecutor;
typedef GPUSink INHERITED;
};
class GPUPersistentCacheTestingSink : public GPUSink {
public:
GPUPersistentCacheTestingSink(const SkCommandLineConfigGpu*, const GrContextOptions&);
Replace DM:Error with DM::Result. Initially, Error was written with the intent that an empty string meant Ok and anything else meant Fatal. This made things simple with implicit constructors from strings. With the introduction of Nonfatal the state was now tied up with an additional boolean. Now the empty string meant Ok and causes the new boolean to be ignored, or at least that is the way it was used since Error didn't actually enforce that itself. This leads to GMs which return kSkip but don't set the message to not be skipped. This could be fixed in several ways. The first would be for the GMSrc to notice that a GM had returned kSkip with an empty message and create the Error::Nonfatal with a non-empty message. This has the downside of being some extra unexpected complexity and doesn't prevent similar issues from arising in the future. The second would be to change how DM interprets the Error, and if the non-fatal bit is set treat that as a sign to skip, even if the message is empty. This fixes the stated issue, but doesn't fix the issue where a GM can return kFail but also leave the message empty. This could again be fixed by either modifying GMSrc::draw or GM::drawContent, but this also seems a bit brittle in not preventing this from happening again in the future. So this replaces Error with Result, which makes the status orthogonal to the message. It does lose the automatic conversion from string, but by being able to wrap the many uses of SkStringPrintf the explicit nature doesn't add much additional noise to the more complex failure reports. Change-Id: Ibf48b67faa09a91a4a9d792d204bd9810b441c6c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270362 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
2020-02-12 16:18:46 +00:00
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
const char* fileExtension() const override {
// Suppress writing out results from this config - we just want to do our matching test
return nullptr;
}
private:
int fCacheType;
typedef GPUSink INHERITED;
};
Add support for pre-compiling cached SkSL shaders The client can do a test run of their application with a persistent cache set to SkSL mode. They store the key and data blobs that are produced. Ship those blobs with the application. At startup, call GrContext::precompileShader for each key/data pair. This compiles the shaders, and stores the GL program ID, plus a small amount of metadata in our runtime program cache. Caveats: * Currently only implemented for the GL backend. Other backends will require more metadata to do any useful amount of work. Metal may need a more drastic workflow change, involving offline compilation of the shaders. * Currently only implemented for cached SkSL (not GLSL or program binaries). Supporting other formats again requires more metadata, and the cached shaders become increasingly specialized to GPU and driver versions. * Reusing the cached SkSL on different hardware is not supported. Many driver workarounds are implemented in the SkSL -> GLSL transformation, but some are higher level. Limiting device variance by artificially hiding extensions may help, but there are no guarantees. * The 'gltestprecompile' DM config exercises this code similarly to 'gltestpersistentcache', ensuring that results are visually identical when precompiling, and that no cache misses occur after precompiling. Change-Id: Id314c5d5f5a58fe503a0505a613bd4a540cc3589 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/239438 Reviewed-by: Greg Daniel <egdaniel@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
2019-09-06 18:42:43 +00:00
class GPUPrecompileTestingSink : public GPUSink {
public:
GPUPrecompileTestingSink(const SkCommandLineConfigGpu*, const GrContextOptions&);
Add support for pre-compiling cached SkSL shaders The client can do a test run of their application with a persistent cache set to SkSL mode. They store the key and data blobs that are produced. Ship those blobs with the application. At startup, call GrContext::precompileShader for each key/data pair. This compiles the shaders, and stores the GL program ID, plus a small amount of metadata in our runtime program cache. Caveats: * Currently only implemented for the GL backend. Other backends will require more metadata to do any useful amount of work. Metal may need a more drastic workflow change, involving offline compilation of the shaders. * Currently only implemented for cached SkSL (not GLSL or program binaries). Supporting other formats again requires more metadata, and the cached shaders become increasingly specialized to GPU and driver versions. * Reusing the cached SkSL on different hardware is not supported. Many driver workarounds are implemented in the SkSL -> GLSL transformation, but some are higher level. Limiting device variance by artificially hiding extensions may help, but there are no guarantees. * The 'gltestprecompile' DM config exercises this code similarly to 'gltestpersistentcache', ensuring that results are visually identical when precompiling, and that no cache misses occur after precompiling. Change-Id: Id314c5d5f5a58fe503a0505a613bd4a540cc3589 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/239438 Reviewed-by: Greg Daniel <egdaniel@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
2019-09-06 18:42:43 +00:00
Replace DM:Error with DM::Result. Initially, Error was written with the intent that an empty string meant Ok and anything else meant Fatal. This made things simple with implicit constructors from strings. With the introduction of Nonfatal the state was now tied up with an additional boolean. Now the empty string meant Ok and causes the new boolean to be ignored, or at least that is the way it was used since Error didn't actually enforce that itself. This leads to GMs which return kSkip but don't set the message to not be skipped. This could be fixed in several ways. The first would be for the GMSrc to notice that a GM had returned kSkip with an empty message and create the Error::Nonfatal with a non-empty message. This has the downside of being some extra unexpected complexity and doesn't prevent similar issues from arising in the future. The second would be to change how DM interprets the Error, and if the non-fatal bit is set treat that as a sign to skip, even if the message is empty. This fixes the stated issue, but doesn't fix the issue where a GM can return kFail but also leave the message empty. This could again be fixed by either modifying GMSrc::draw or GM::drawContent, but this also seems a bit brittle in not preventing this from happening again in the future. So this replaces Error with Result, which makes the status orthogonal to the message. It does lose the automatic conversion from string, but by being able to wrap the many uses of SkStringPrintf the explicit nature doesn't add much additional noise to the more complex failure reports. Change-Id: Ibf48b67faa09a91a4a9d792d204bd9810b441c6c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270362 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
2020-02-12 16:18:46 +00:00
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
Add support for pre-compiling cached SkSL shaders The client can do a test run of their application with a persistent cache set to SkSL mode. They store the key and data blobs that are produced. Ship those blobs with the application. At startup, call GrContext::precompileShader for each key/data pair. This compiles the shaders, and stores the GL program ID, plus a small amount of metadata in our runtime program cache. Caveats: * Currently only implemented for the GL backend. Other backends will require more metadata to do any useful amount of work. Metal may need a more drastic workflow change, involving offline compilation of the shaders. * Currently only implemented for cached SkSL (not GLSL or program binaries). Supporting other formats again requires more metadata, and the cached shaders become increasingly specialized to GPU and driver versions. * Reusing the cached SkSL on different hardware is not supported. Many driver workarounds are implemented in the SkSL -> GLSL transformation, but some are higher level. Limiting device variance by artificially hiding extensions may help, but there are no guarantees. * The 'gltestprecompile' DM config exercises this code similarly to 'gltestpersistentcache', ensuring that results are visually identical when precompiling, and that no cache misses occur after precompiling. Change-Id: Id314c5d5f5a58fe503a0505a613bd4a540cc3589 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/239438 Reviewed-by: Greg Daniel <egdaniel@google.com> Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
2019-09-06 18:42:43 +00:00
const char* fileExtension() const override {
// Suppress writing out results from this config - we just want to do our matching test
return nullptr;
}
private:
typedef GPUSink INHERITED;
};
// This sink attempts to emulate Chrome's OOP-R behavior. It:
// doesn't use promise images
// uses only a single thread for both DDL creation & drawing
class GPUOOPRSink : public GPUSink {
public:
GPUOOPRSink(const SkCommandLineConfigGpu*, const GrContextOptions&);
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
private:
Result ooprDraw(const Src&, sk_sp<SkSurface> dstSurface, GrDirectContext*) const;
typedef GPUSink INHERITED;
};
// This sink attempts to better simulate the Chrome DDL use-case. It:
// creates the DDLs on separate recording threads
// performs all the GPU work on a separate GPU thread
// In the future this should be expanded to:
// upload on a utility thread w/ access to a shared context
// compile the programs on the utility thread
// perform fine grained scheduling of gpu tasks based on their image and program prerequisites
// create a single "compositing" DDL that is replayed last
class GPUDDLSink : public GPUSink {
public:
GPUDDLSink(const SkCommandLineConfigGpu*, const GrContextOptions&);
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
private:
Result ddlDraw(const Src&,
sk_sp<SkSurface> dstSurface,
SkTaskGroup* recordingTaskGroup,
SkTaskGroup* gpuTaskGroup,
sk_gpu_test::TestContext* gpuTestCtx,
GrDirectContext* gpuThreadCtx) const;
std::unique_ptr<SkExecutor> fRecordingExecutor;
std::unique_ptr<SkExecutor> fGPUExecutor;
typedef GPUSink INHERITED;
};
class PDFSink : public Sink {
public:
PDFSink(bool pdfa, SkScalar rasterDpi) : fPDFA(pdfa), fRasterDpi(rasterDpi) {}
Replace DM:Error with DM::Result. Initially, Error was written with the intent that an empty string meant Ok and anything else meant Fatal. This made things simple with implicit constructors from strings. With the introduction of Nonfatal the state was now tied up with an additional boolean. Now the empty string meant Ok and causes the new boolean to be ignored, or at least that is the way it was used since Error didn't actually enforce that itself. This leads to GMs which return kSkip but don't set the message to not be skipped. This could be fixed in several ways. The first would be for the GMSrc to notice that a GM had returned kSkip with an empty message and create the Error::Nonfatal with a non-empty message. This has the downside of being some extra unexpected complexity and doesn't prevent similar issues from arising in the future. The second would be to change how DM interprets the Error, and if the non-fatal bit is set treat that as a sign to skip, even if the message is empty. This fixes the stated issue, but doesn't fix the issue where a GM can return kFail but also leave the message empty. This could again be fixed by either modifying GMSrc::draw or GM::drawContent, but this also seems a bit brittle in not preventing this from happening again in the future. So this replaces Error with Result, which makes the status orthogonal to the message. It does lose the automatic conversion from string, but by being able to wrap the many uses of SkStringPrintf the explicit nature doesn't add much additional noise to the more complex failure reports. Change-Id: Ibf48b67faa09a91a4a9d792d204bd9810b441c6c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270362 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
2020-02-12 16:18:46 +00:00
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
const char* fileExtension() const override { return "pdf"; }
SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
bool fPDFA;
SkScalar fRasterDpi;
};
class XPSSink : public Sink {
public:
XPSSink();
Replace DM:Error with DM::Result. Initially, Error was written with the intent that an empty string meant Ok and anything else meant Fatal. This made things simple with implicit constructors from strings. With the introduction of Nonfatal the state was now tied up with an additional boolean. Now the empty string meant Ok and causes the new boolean to be ignored, or at least that is the way it was used since Error didn't actually enforce that itself. This leads to GMs which return kSkip but don't set the message to not be skipped. This could be fixed in several ways. The first would be for the GMSrc to notice that a GM had returned kSkip with an empty message and create the Error::Nonfatal with a non-empty message. This has the downside of being some extra unexpected complexity and doesn't prevent similar issues from arising in the future. The second would be to change how DM interprets the Error, and if the non-fatal bit is set treat that as a sign to skip, even if the message is empty. This fixes the stated issue, but doesn't fix the issue where a GM can return kFail but also leave the message empty. This could again be fixed by either modifying GMSrc::draw or GM::drawContent, but this also seems a bit brittle in not preventing this from happening again in the future. So this replaces Error with Result, which makes the status orthogonal to the message. It does lose the automatic conversion from string, but by being able to wrap the many uses of SkStringPrintf the explicit nature doesn't add much additional noise to the more complex failure reports. Change-Id: Ibf48b67faa09a91a4a9d792d204bd9810b441c6c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270362 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
2020-02-12 16:18:46 +00:00
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
const char* fileExtension() const override { return "xps"; }
SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
};
class RasterSink : public Sink {
public:
explicit RasterSink(SkColorType, sk_sp<SkColorSpace> = nullptr);
Replace DM:Error with DM::Result. Initially, Error was written with the intent that an empty string meant Ok and anything else meant Fatal. This made things simple with implicit constructors from strings. With the introduction of Nonfatal the state was now tied up with an additional boolean. Now the empty string meant Ok and causes the new boolean to be ignored, or at least that is the way it was used since Error didn't actually enforce that itself. This leads to GMs which return kSkip but don't set the message to not be skipped. This could be fixed in several ways. The first would be for the GMSrc to notice that a GM had returned kSkip with an empty message and create the Error::Nonfatal with a non-empty message. This has the downside of being some extra unexpected complexity and doesn't prevent similar issues from arising in the future. The second would be to change how DM interprets the Error, and if the non-fatal bit is set treat that as a sign to skip, even if the message is empty. This fixes the stated issue, but doesn't fix the issue where a GM can return kFail but also leave the message empty. This could again be fixed by either modifying GMSrc::draw or GM::drawContent, but this also seems a bit brittle in not preventing this from happening again in the future. So this replaces Error with Result, which makes the status orthogonal to the message. It does lose the automatic conversion from string, but by being able to wrap the many uses of SkStringPrintf the explicit nature doesn't add much additional noise to the more complex failure reports. Change-Id: Ibf48b67faa09a91a4a9d792d204bd9810b441c6c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270362 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
2020-02-12 16:18:46 +00:00
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
const char* fileExtension() const override { return "png"; }
SinkFlags flags() const override { return SinkFlags{ SinkFlags::kRaster, SinkFlags::kDirect }; }
private:
SkColorType fColorType;
sk_sp<SkColorSpace> fColorSpace;
};
class ThreadedSink : public RasterSink {
public:
explicit ThreadedSink(SkColorType, sk_sp<SkColorSpace> = nullptr);
Replace DM:Error with DM::Result. Initially, Error was written with the intent that an empty string meant Ok and anything else meant Fatal. This made things simple with implicit constructors from strings. With the introduction of Nonfatal the state was now tied up with an additional boolean. Now the empty string meant Ok and causes the new boolean to be ignored, or at least that is the way it was used since Error didn't actually enforce that itself. This leads to GMs which return kSkip but don't set the message to not be skipped. This could be fixed in several ways. The first would be for the GMSrc to notice that a GM had returned kSkip with an empty message and create the Error::Nonfatal with a non-empty message. This has the downside of being some extra unexpected complexity and doesn't prevent similar issues from arising in the future. The second would be to change how DM interprets the Error, and if the non-fatal bit is set treat that as a sign to skip, even if the message is empty. This fixes the stated issue, but doesn't fix the issue where a GM can return kFail but also leave the message empty. This could again be fixed by either modifying GMSrc::draw or GM::drawContent, but this also seems a bit brittle in not preventing this from happening again in the future. So this replaces Error with Result, which makes the status orthogonal to the message. It does lose the automatic conversion from string, but by being able to wrap the many uses of SkStringPrintf the explicit nature doesn't add much additional noise to the more complex failure reports. Change-Id: Ibf48b67faa09a91a4a9d792d204bd9810b441c6c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270362 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
2020-02-12 16:18:46 +00:00
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
};
class SKPSink : public Sink {
public:
SKPSink();
Replace DM:Error with DM::Result. Initially, Error was written with the intent that an empty string meant Ok and anything else meant Fatal. This made things simple with implicit constructors from strings. With the introduction of Nonfatal the state was now tied up with an additional boolean. Now the empty string meant Ok and causes the new boolean to be ignored, or at least that is the way it was used since Error didn't actually enforce that itself. This leads to GMs which return kSkip but don't set the message to not be skipped. This could be fixed in several ways. The first would be for the GMSrc to notice that a GM had returned kSkip with an empty message and create the Error::Nonfatal with a non-empty message. This has the downside of being some extra unexpected complexity and doesn't prevent similar issues from arising in the future. The second would be to change how DM interprets the Error, and if the non-fatal bit is set treat that as a sign to skip, even if the message is empty. This fixes the stated issue, but doesn't fix the issue where a GM can return kFail but also leave the message empty. This could again be fixed by either modifying GMSrc::draw or GM::drawContent, but this also seems a bit brittle in not preventing this from happening again in the future. So this replaces Error with Result, which makes the status orthogonal to the message. It does lose the automatic conversion from string, but by being able to wrap the many uses of SkStringPrintf the explicit nature doesn't add much additional noise to the more complex failure reports. Change-Id: Ibf48b67faa09a91a4a9d792d204bd9810b441c6c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270362 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
2020-02-12 16:18:46 +00:00
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
const char* fileExtension() const override { return "skp"; }
SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
};
class DebugSink : public Sink {
public:
Replace DM:Error with DM::Result. Initially, Error was written with the intent that an empty string meant Ok and anything else meant Fatal. This made things simple with implicit constructors from strings. With the introduction of Nonfatal the state was now tied up with an additional boolean. Now the empty string meant Ok and causes the new boolean to be ignored, or at least that is the way it was used since Error didn't actually enforce that itself. This leads to GMs which return kSkip but don't set the message to not be skipped. This could be fixed in several ways. The first would be for the GMSrc to notice that a GM had returned kSkip with an empty message and create the Error::Nonfatal with a non-empty message. This has the downside of being some extra unexpected complexity and doesn't prevent similar issues from arising in the future. The second would be to change how DM interprets the Error, and if the non-fatal bit is set treat that as a sign to skip, even if the message is empty. This fixes the stated issue, but doesn't fix the issue where a GM can return kFail but also leave the message empty. This could again be fixed by either modifying GMSrc::draw or GM::drawContent, but this also seems a bit brittle in not preventing this from happening again in the future. So this replaces Error with Result, which makes the status orthogonal to the message. It does lose the automatic conversion from string, but by being able to wrap the many uses of SkStringPrintf the explicit nature doesn't add much additional noise to the more complex failure reports. Change-Id: Ibf48b67faa09a91a4a9d792d204bd9810b441c6c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270362 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
2020-02-12 16:18:46 +00:00
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
const char* fileExtension() const override { return "json"; }
SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
};
class SVGSink : public Sink {
public:
SVGSink(int pageIndex = 0);
Replace DM:Error with DM::Result. Initially, Error was written with the intent that an empty string meant Ok and anything else meant Fatal. This made things simple with implicit constructors from strings. With the introduction of Nonfatal the state was now tied up with an additional boolean. Now the empty string meant Ok and causes the new boolean to be ignored, or at least that is the way it was used since Error didn't actually enforce that itself. This leads to GMs which return kSkip but don't set the message to not be skipped. This could be fixed in several ways. The first would be for the GMSrc to notice that a GM had returned kSkip with an empty message and create the Error::Nonfatal with a non-empty message. This has the downside of being some extra unexpected complexity and doesn't prevent similar issues from arising in the future. The second would be to change how DM interprets the Error, and if the non-fatal bit is set treat that as a sign to skip, even if the message is empty. This fixes the stated issue, but doesn't fix the issue where a GM can return kFail but also leave the message empty. This could again be fixed by either modifying GMSrc::draw or GM::drawContent, but this also seems a bit brittle in not preventing this from happening again in the future. So this replaces Error with Result, which makes the status orthogonal to the message. It does lose the automatic conversion from string, but by being able to wrap the many uses of SkStringPrintf the explicit nature doesn't add much additional noise to the more complex failure reports. Change-Id: Ibf48b67faa09a91a4a9d792d204bd9810b441c6c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270362 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
2020-02-12 16:18:46 +00:00
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
const char* fileExtension() const override { return "svg"; }
SinkFlags flags() const override { return SinkFlags{ SinkFlags::kVector, SinkFlags::kDirect }; }
private:
int fPageIndex;
};
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
class Via : public Sink {
public:
explicit Via(Sink* sink) : fSink(sink) {}
const char* fileExtension() const override { return fSink->fileExtension(); }
bool serial() const override { return fSink->serial(); }
SinkFlags flags() const override {
SinkFlags flags = fSink->flags();
flags.approach = SinkFlags::kIndirect;
return flags;
}
protected:
std::unique_ptr<Sink> fSink;
};
class ViaMatrix : public Via {
public:
ViaMatrix(SkMatrix, Sink*);
Replace DM:Error with DM::Result. Initially, Error was written with the intent that an empty string meant Ok and anything else meant Fatal. This made things simple with implicit constructors from strings. With the introduction of Nonfatal the state was now tied up with an additional boolean. Now the empty string meant Ok and causes the new boolean to be ignored, or at least that is the way it was used since Error didn't actually enforce that itself. This leads to GMs which return kSkip but don't set the message to not be skipped. This could be fixed in several ways. The first would be for the GMSrc to notice that a GM had returned kSkip with an empty message and create the Error::Nonfatal with a non-empty message. This has the downside of being some extra unexpected complexity and doesn't prevent similar issues from arising in the future. The second would be to change how DM interprets the Error, and if the non-fatal bit is set treat that as a sign to skip, even if the message is empty. This fixes the stated issue, but doesn't fix the issue where a GM can return kFail but also leave the message empty. This could again be fixed by either modifying GMSrc::draw or GM::drawContent, but this also seems a bit brittle in not preventing this from happening again in the future. So this replaces Error with Result, which makes the status orthogonal to the message. It does lose the automatic conversion from string, but by being able to wrap the many uses of SkStringPrintf the explicit nature doesn't add much additional noise to the more complex failure reports. Change-Id: Ibf48b67faa09a91a4a9d792d204bd9810b441c6c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270362 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
2020-02-12 16:18:46 +00:00
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
private:
const SkMatrix fMatrix;
};
class ViaUpright : public Via {
public:
ViaUpright(SkMatrix, Sink*);
Replace DM:Error with DM::Result. Initially, Error was written with the intent that an empty string meant Ok and anything else meant Fatal. This made things simple with implicit constructors from strings. With the introduction of Nonfatal the state was now tied up with an additional boolean. Now the empty string meant Ok and causes the new boolean to be ignored, or at least that is the way it was used since Error didn't actually enforce that itself. This leads to GMs which return kSkip but don't set the message to not be skipped. This could be fixed in several ways. The first would be for the GMSrc to notice that a GM had returned kSkip with an empty message and create the Error::Nonfatal with a non-empty message. This has the downside of being some extra unexpected complexity and doesn't prevent similar issues from arising in the future. The second would be to change how DM interprets the Error, and if the non-fatal bit is set treat that as a sign to skip, even if the message is empty. This fixes the stated issue, but doesn't fix the issue where a GM can return kFail but also leave the message empty. This could again be fixed by either modifying GMSrc::draw or GM::drawContent, but this also seems a bit brittle in not preventing this from happening again in the future. So this replaces Error with Result, which makes the status orthogonal to the message. It does lose the automatic conversion from string, but by being able to wrap the many uses of SkStringPrintf the explicit nature doesn't add much additional noise to the more complex failure reports. Change-Id: Ibf48b67faa09a91a4a9d792d204bd9810b441c6c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270362 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
2020-02-12 16:18:46 +00:00
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
private:
const SkMatrix fMatrix;
};
class ViaSerialization : public Via {
public:
explicit ViaSerialization(Sink* sink) : Via(sink) {}
Replace DM:Error with DM::Result. Initially, Error was written with the intent that an empty string meant Ok and anything else meant Fatal. This made things simple with implicit constructors from strings. With the introduction of Nonfatal the state was now tied up with an additional boolean. Now the empty string meant Ok and causes the new boolean to be ignored, or at least that is the way it was used since Error didn't actually enforce that itself. This leads to GMs which return kSkip but don't set the message to not be skipped. This could be fixed in several ways. The first would be for the GMSrc to notice that a GM had returned kSkip with an empty message and create the Error::Nonfatal with a non-empty message. This has the downside of being some extra unexpected complexity and doesn't prevent similar issues from arising in the future. The second would be to change how DM interprets the Error, and if the non-fatal bit is set treat that as a sign to skip, even if the message is empty. This fixes the stated issue, but doesn't fix the issue where a GM can return kFail but also leave the message empty. This could again be fixed by either modifying GMSrc::draw or GM::drawContent, but this also seems a bit brittle in not preventing this from happening again in the future. So this replaces Error with Result, which makes the status orthogonal to the message. It does lose the automatic conversion from string, but by being able to wrap the many uses of SkStringPrintf the explicit nature doesn't add much additional noise to the more complex failure reports. Change-Id: Ibf48b67faa09a91a4a9d792d204bd9810b441c6c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270362 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
2020-02-12 16:18:46 +00:00
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
};
class ViaPicture : public Via {
public:
explicit ViaPicture(Sink* sink) : Via(sink) {}
Replace DM:Error with DM::Result. Initially, Error was written with the intent that an empty string meant Ok and anything else meant Fatal. This made things simple with implicit constructors from strings. With the introduction of Nonfatal the state was now tied up with an additional boolean. Now the empty string meant Ok and causes the new boolean to be ignored, or at least that is the way it was used since Error didn't actually enforce that itself. This leads to GMs which return kSkip but don't set the message to not be skipped. This could be fixed in several ways. The first would be for the GMSrc to notice that a GM had returned kSkip with an empty message and create the Error::Nonfatal with a non-empty message. This has the downside of being some extra unexpected complexity and doesn't prevent similar issues from arising in the future. The second would be to change how DM interprets the Error, and if the non-fatal bit is set treat that as a sign to skip, even if the message is empty. This fixes the stated issue, but doesn't fix the issue where a GM can return kFail but also leave the message empty. This could again be fixed by either modifying GMSrc::draw or GM::drawContent, but this also seems a bit brittle in not preventing this from happening again in the future. So this replaces Error with Result, which makes the status orthogonal to the message. It does lose the automatic conversion from string, but by being able to wrap the many uses of SkStringPrintf the explicit nature doesn't add much additional noise to the more complex failure reports. Change-Id: Ibf48b67faa09a91a4a9d792d204bd9810b441c6c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270362 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
2020-02-12 16:18:46 +00:00
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
};
class ViaDDL : public Via {
public:
ViaDDL(int numReplays, int numDivisions, Sink* sink);
Replace DM:Error with DM::Result. Initially, Error was written with the intent that an empty string meant Ok and anything else meant Fatal. This made things simple with implicit constructors from strings. With the introduction of Nonfatal the state was now tied up with an additional boolean. Now the empty string meant Ok and causes the new boolean to be ignored, or at least that is the way it was used since Error didn't actually enforce that itself. This leads to GMs which return kSkip but don't set the message to not be skipped. This could be fixed in several ways. The first would be for the GMSrc to notice that a GM had returned kSkip with an empty message and create the Error::Nonfatal with a non-empty message. This has the downside of being some extra unexpected complexity and doesn't prevent similar issues from arising in the future. The second would be to change how DM interprets the Error, and if the non-fatal bit is set treat that as a sign to skip, even if the message is empty. This fixes the stated issue, but doesn't fix the issue where a GM can return kFail but also leave the message empty. This could again be fixed by either modifying GMSrc::draw or GM::drawContent, but this also seems a bit brittle in not preventing this from happening again in the future. So this replaces Error with Result, which makes the status orthogonal to the message. It does lose the automatic conversion from string, but by being able to wrap the many uses of SkStringPrintf the explicit nature doesn't add much additional noise to the more complex failure reports. Change-Id: Ibf48b67faa09a91a4a9d792d204bd9810b441c6c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270362 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
2020-02-12 16:18:46 +00:00
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
private:
const int fNumReplays;
const int fNumDivisions;
};
class ViaSVG : public Via {
public:
explicit ViaSVG(Sink* sink) : Via(sink) {}
Replace DM:Error with DM::Result. Initially, Error was written with the intent that an empty string meant Ok and anything else meant Fatal. This made things simple with implicit constructors from strings. With the introduction of Nonfatal the state was now tied up with an additional boolean. Now the empty string meant Ok and causes the new boolean to be ignored, or at least that is the way it was used since Error didn't actually enforce that itself. This leads to GMs which return kSkip but don't set the message to not be skipped. This could be fixed in several ways. The first would be for the GMSrc to notice that a GM had returned kSkip with an empty message and create the Error::Nonfatal with a non-empty message. This has the downside of being some extra unexpected complexity and doesn't prevent similar issues from arising in the future. The second would be to change how DM interprets the Error, and if the non-fatal bit is set treat that as a sign to skip, even if the message is empty. This fixes the stated issue, but doesn't fix the issue where a GM can return kFail but also leave the message empty. This could again be fixed by either modifying GMSrc::draw or GM::drawContent, but this also seems a bit brittle in not preventing this from happening again in the future. So this replaces Error with Result, which makes the status orthogonal to the message. It does lose the automatic conversion from string, but by being able to wrap the many uses of SkStringPrintf the explicit nature doesn't add much additional noise to the more complex failure reports. Change-Id: Ibf48b67faa09a91a4a9d792d204bd9810b441c6c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/270362 Commit-Queue: Ben Wagner <bungeman@google.com> Reviewed-by: Mike Klein <mtklein@google.com>
2020-02-12 16:18:46 +00:00
Result draw(const Src&, SkBitmap*, SkWStream*, SkString*) const override;
};
} // namespace DM
#endif//DMSrcSink_DEFINED