skia2/dm/DMSrcSink.cpp

2391 lines
94 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.
*/
#include "dm/DMSrcSink.h"
#include "gm/verifiers/gmverifier.h"
#include "include/codec/SkAndroidCodec.h"
#include "include/codec/SkCodec.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkData.h"
#include "include/core/SkDeferredDisplayListRecorder.h"
#include "include/core/SkDocument.h"
#include "include/core/SkExecutor.h"
#include "include/core/SkImageGenerator.h"
#include "include/core/SkMallocPixelRef.h"
#include "include/core/SkPictureRecorder.h"
#include "include/core/SkStream.h"
#include "include/core/SkSurface.h"
#include "include/core/SkSurfaceCharacterization.h"
#include "include/docs/SkPDFDocument.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrDirectContext.h"
#include "include/ports/SkImageGeneratorCG.h"
#include "include/ports/SkImageGeneratorNDK.h"
#include "include/ports/SkImageGeneratorWIC.h"
#include "include/private/SkImageInfoPriv.h"
#include "include/private/SkTLogic.h"
#include "include/third_party/skcms/skcms.h"
#include "include/utils/SkNullCanvas.h"
#include "include/utils/SkRandom.h"
#include "modules/skottie/utils/SkottieUtils.h"
#include "src/codec/SkCodecImageGenerator.h"
#include "src/codec/SkSwizzler.h"
#include "src/core/SkAutoMalloc.h"
#include "src/core/SkAutoPixmapStorage.h"
#include "src/core/SkOSFile.h"
#include "src/core/SkOpts.h"
#include "src/core/SkPictureCommon.h"
#include "src/core/SkPictureData.h"
#include "src/core/SkRecordDraw.h"
#include "src/core/SkRecorder.h"
#include "src/core/SkTaskGroup.h"
#include "src/gpu/GrDirectContextPriv.h"
#include "src/gpu/GrGpu.h"
#include "src/utils/SkMultiPictureDocumentPriv.h"
#include "src/utils/SkOSPath.h"
#include "tools/DDLPromiseImageHelper.h"
#include "tools/DDLTileHelper.h"
#include "tools/Resources.h"
#include "tools/debugger/DebugCanvas.h"
#include "tools/gpu/BackendSurfaceFactory.h"
#include "tools/gpu/MemoryCache.h"
#if defined(SK_BUILD_FOR_WIN)
#include "include/docs/SkXPSDocument.h"
#include "src/utils/win/SkAutoCoInitialize.h"
#include "src/utils/win/SkHRESULT.h"
#include "src/utils/win/SkTScopedComPtr.h"
#include <XpsObjectModel.h>
#endif
#if defined(SK_ENABLE_SKOTTIE)
#include "modules/skottie/include/Skottie.h"
#include "modules/skresources/include/SkResources.h"
#endif
#if defined(SK_ENABLE_SKRIVE)
#include "experimental/skrive/include/SkRive.h"
#endif
#if defined(SK_XML)
#include "include/svg/SkSVGCanvas.h"
#include "modules/svg/include/SkSVGDOM.h"
#include "src/xml/SkXMLWriter.h"
#endif
#if defined(SK_ENABLE_ANDROID_UTILS)
#include "client_utils/android/BitmapRegionDecoder.h"
#endif
#include "tests/TestUtils.h"
#include <cmath>
#include <functional>
static DEFINE_bool(multiPage, false,
"For document-type backends, render the source into multiple pages");
static DEFINE_bool(RAW_threading, true, "Allow RAW decodes to run on multiple threads?");
DECLARE_int(gpuThreads);
using sk_gpu_test::GrContextFactory;
using sk_gpu_test::ContextInfo;
namespace DM {
GMSrc::GMSrc(skiagm::GMFactory factory) : fFactory(factory) {}
Result GMSrc::draw(GrDirectContext* context, SkCanvas* canvas) const {
std::unique_ptr<skiagm::GM> gm(fFactory());
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
SkString msg;
skiagm::DrawResult gpuSetupResult = gm->gpuSetup(context, canvas, &msg);
switch (gpuSetupResult) {
case skiagm::DrawResult::kOk : break;
case skiagm::DrawResult::kFail: return Result(Result::Status::Fatal, msg);
case skiagm::DrawResult::kSkip: return Result(Result::Status::Skip, msg);
default: SK_ABORT("");
}
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
skiagm::DrawResult drawResult = gm->draw(canvas, &msg);
switch (drawResult) {
case skiagm::DrawResult::kOk : return Result(Result::Status::Ok, msg);
case skiagm::DrawResult::kFail: return Result(Result::Status::Fatal, msg);
case skiagm::DrawResult::kSkip: return Result(Result::Status::Skip, msg);
default: SK_ABORT("");
}
// Note: we don't call "gpuTeardown" here because, when testing DDL recording, we want
// the gpu-backed images to live past the lifetime of the GM.
}
SkISize GMSrc::size() const {
std::unique_ptr<skiagm::GM> gm(fFactory());
return gm->getISize();
}
Name GMSrc::name() const {
std::unique_ptr<skiagm::GM> gm(fFactory());
return gm->getName();
}
void GMSrc::modifyGrContextOptions(GrContextOptions* options) const {
std::unique_ptr<skiagm::GM> gm(fFactory());
gm->modifyGrContextOptions(options);
}
std::unique_ptr<skiagm::verifiers::VerifierList> GMSrc::getVerifiers() const {
std::unique_ptr<skiagm::GM> gm(fFactory());
return gm->getVerifiers();
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
static SkString get_scaled_name(const Path& path, float scale) {
return SkStringPrintf("%s_%.3f", SkOSPath::Basename(path.c_str()).c_str(), scale);
}
#ifdef SK_ENABLE_ANDROID_UTILS
BRDSrc::BRDSrc(Path path, Mode mode, CodecSrc::DstColorType dstColorType, uint32_t sampleSize)
: fPath(path)
, fMode(mode)
, fDstColorType(dstColorType)
, fSampleSize(sampleSize)
{}
bool BRDSrc::veto(SinkFlags flags) const {
// No need to test to non-raster or indirect backends.
return flags.type != SinkFlags::kRaster
|| flags.approach != SinkFlags::kDirect;
}
static std::unique_ptr<android::skia::BitmapRegionDecoder> create_brd(Path path) {
sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
return android::skia::BitmapRegionDecoder::Make(encoded);
}
static inline void alpha8_to_gray8(SkBitmap* bitmap) {
// Android requires kGray8 bitmaps to be tagged as kAlpha8. Here we convert
// them back to kGray8 so our test framework can draw them correctly.
if (kAlpha_8_SkColorType == bitmap->info().colorType()) {
SkImageInfo newInfo = bitmap->info().makeColorType(kGray_8_SkColorType)
.makeAlphaType(kOpaque_SkAlphaType);
*const_cast<SkImageInfo*>(&bitmap->info()) = newInfo;
}
}
Result BRDSrc::draw(GrDirectContext*, SkCanvas* canvas) const {
SkColorType colorType = canvas->imageInfo().colorType();
if (kRGB_565_SkColorType == colorType &&
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
CodecSrc::kGetFromCanvas_DstColorType != fDstColorType)
{
return Result::Skip("Testing non-565 to 565 is uninteresting.");
}
switch (fDstColorType) {
case CodecSrc::kGetFromCanvas_DstColorType:
break;
case CodecSrc::kGrayscale_Always_DstColorType:
colorType = kGray_8_SkColorType;
break;
default:
SkASSERT(false);
break;
}
auto brd = create_brd(fPath);
if (nullptr == brd) {
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
return Result::Skip("Could not create brd for %s.", fPath.c_str());
}
auto recommendedCT = brd->computeOutputColorType(colorType);
if (kRGB_565_SkColorType == colorType && recommendedCT != colorType) {
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
return Result::Skip("Skip decoding non-opaque to 565.");
}
colorType = recommendedCT;
auto colorSpace = brd->computeOutputColorSpace(colorType, nullptr);
const uint32_t width = brd->width();
const uint32_t height = brd->height();
// Visually inspecting very small output images is not necessary.
if ((width / fSampleSize <= 10 || height / fSampleSize <= 10) && 1 != fSampleSize) {
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
return Result::Skip("Scaling very small images is uninteresting.");
}
switch (fMode) {
case kFullImage_Mode: {
SkBitmap bitmap;
if (!brd->decodeRegion(&bitmap, nullptr, SkIRect::MakeXYWH(0, 0, width, height),
fSampleSize, colorType, false, colorSpace)) {
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
return Result::Fatal("Cannot decode (full) region.");
}
alpha8_to_gray8(&bitmap);
Revert "Revert "Do not return Index8 from SkAndroidCodec::computeOutputColorType"" This reverts commit 81c83a7db4e524b19d33bf7c8a9b537b9d606c93. Reason for revert: <INSERT REASONING HERE> Original change's description: > Revert "Do not return Index8 from SkAndroidCodec::computeOutputColorType" > > This reverts commit b6f4767294261dca3beef6f280c4bac69df3f930. > > Reason for revert: This breaks CTS tests in Android. Doh. > > Original change's description: > > Do not return Index8 from SkAndroidCodec::computeOutputColorType > > > > Given that this is the only known use of Index8 color type, > > this is essentially an experimental delete. > > > > Bug: skia:6620 > > Change-Id: Ib363d237e0217f6e7f461a62e54d32892c428095 > > Reviewed-on: https://skia-review.googlesource.com/10586 > > Reviewed-by: Leon Scroggins <scroggo@google.com> > > Commit-Queue: Matt Sarett <msarett@google.com> > > TBR=msarett@google.com,scroggo@google.com,reed@google.com > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:6620 > > Change-Id: I2b44c695b8b95659520e9532901f636f56e01e2a > Reviewed-on: https://skia-review.googlesource.com/19084 > Reviewed-by: Matt Sarett <msarett@google.com> > Commit-Queue: Matt Sarett <msarett@google.com> TBR=msarett@google.com,scroggo@google.com,reviews@skia.org,reed@google.com # Not skipping CQ checks because original CL landed > 1 day ago. Bug: skia:6620 Change-Id: I7e4e3a5ec068102244ad3a0259aa6aded4f12f36 Reviewed-on: https://skia-review.googlesource.com/19802 Reviewed-by: Matt Sarett <msarett@google.com> Commit-Queue: Matt Sarett <msarett@google.com>
2017-06-14 13:02:05 +00:00
canvas->drawBitmap(bitmap, 0, 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
return Result::Ok();
}
case kDivisor_Mode: {
const uint32_t divisor = 2;
if (width < divisor || height < divisor) {
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
return Result::Skip("Divisor is larger than image dimension.");
}
// Use a border to test subsets that extend outside the image.
// We will not allow the border to be larger than the image dimensions. Allowing
// these large borders causes off by one errors that indicate a problem with the
// test suite, not a problem with the implementation.
const uint32_t maxBorder = std::min(width, height) / (fSampleSize * divisor);
const uint32_t scaledBorder = std::min(5u, maxBorder);
const uint32_t unscaledBorder = scaledBorder * fSampleSize;
// We may need to clear the canvas to avoid uninitialized memory.
// Assume we are scaling a 780x780 image with sampleSize = 8.
// The output image should be 97x97.
// Each subset will be 390x390.
// Each scaled subset be 48x48.
// Four scaled subsets will only fill a 96x96 image.
// The bottom row and last column will not be touched.
// This is an unfortunate result of our rounding rules when scaling.
// Maybe we need to consider testing scaled subsets without trying to
// combine them to match the full scaled image? Or maybe this is the
// best we can do?
canvas->clear(0);
for (uint32_t x = 0; x < divisor; x++) {
for (uint32_t y = 0; y < divisor; y++) {
// Calculate the subset dimensions
uint32_t subsetWidth = width / divisor;
uint32_t subsetHeight = height / divisor;
const int left = x * subsetWidth;
const int top = y * subsetHeight;
// Increase the size of the last subset in each row or column, when the
// divisor does not divide evenly into the image dimensions
subsetWidth += (x + 1 == divisor) ? (width % divisor) : 0;
subsetHeight += (y + 1 == divisor) ? (height % divisor) : 0;
// Increase the size of the subset in order to have a border on each side
const int decodeLeft = left - unscaledBorder;
const int decodeTop = top - unscaledBorder;
const uint32_t decodeWidth = subsetWidth + unscaledBorder * 2;
const uint32_t decodeHeight = subsetHeight + unscaledBorder * 2;
SkBitmap bitmap;
if (!brd->decodeRegion(&bitmap, nullptr, SkIRect::MakeXYWH(decodeLeft,
decodeTop, decodeWidth, decodeHeight), fSampleSize, colorType, false,
colorSpace)) {
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
return Result::Fatal("Cannot decode region.");
}
alpha8_to_gray8(&bitmap);
canvas->drawBitmapRect(bitmap,
SkRect::MakeXYWH((SkScalar) scaledBorder, (SkScalar) scaledBorder,
(SkScalar) (subsetWidth / fSampleSize),
(SkScalar) (subsetHeight / fSampleSize)),
SkRect::MakeXYWH((SkScalar) (left / fSampleSize),
(SkScalar) (top / fSampleSize),
(SkScalar) (subsetWidth / fSampleSize),
(SkScalar) (subsetHeight / fSampleSize)),
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
return Result::Ok();
}
default:
SkASSERT(false);
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
return Result::Fatal("Error: Should not be reached.");
}
}
SkISize BRDSrc::size() const {
auto brd = create_brd(fPath);
if (brd) {
return {std::max(1, brd->width() / (int)fSampleSize),
std::max(1, brd->height() / (int)fSampleSize)};
}
return {0, 0};
}
Name BRDSrc::name() const {
// We will replicate the names used by CodecSrc so that images can
// be compared in Gold.
if (1 == fSampleSize) {
return SkOSPath::Basename(fPath.c_str());
}
return get_scaled_name(fPath, 1.0f / (float) fSampleSize);
}
#endif // SK_ENABLE_ANDROID_UTILS
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
static bool serial_from_path_name(const SkString& path) {
if (!FLAGS_RAW_threading) {
static const char* const exts[] = {
"arw", "cr2", "dng", "nef", "nrw", "orf", "raf", "rw2", "pef", "srw",
"ARW", "CR2", "DNG", "NEF", "NRW", "ORF", "RAF", "RW2", "PEF", "SRW",
};
const char* actualExt = strrchr(path.c_str(), '.');
if (actualExt) {
actualExt++;
for (auto* ext : exts) {
if (0 == strcmp(ext, actualExt)) {
return true;
}
}
}
}
return false;
}
CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, SkAlphaType dstAlphaType,
float scale)
: fPath(path)
, fMode(mode)
, fDstColorType(dstColorType)
, fDstAlphaType(dstAlphaType)
, fScale(scale)
, fRunSerially(serial_from_path_name(path))
{}
bool CodecSrc::veto(SinkFlags flags) const {
// Test to direct raster backends (8888 and 565).
return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDirect;
}
// Allows us to test decodes to non-native 8888.
static void swap_rb_if_necessary(SkBitmap& bitmap, CodecSrc::DstColorType dstColorType) {
if (CodecSrc::kNonNative8888_Always_DstColorType != dstColorType) {
return;
}
for (int y = 0; y < bitmap.height(); y++) {
uint32_t* row = (uint32_t*) bitmap.getAddr(0, y);
SkOpts::RGBA_to_BGRA(row, row, bitmap.width());
}
}
static bool get_decode_info(SkImageInfo* decodeInfo, SkColorType canvasColorType,
CodecSrc::DstColorType dstColorType, SkAlphaType dstAlphaType) {
switch (dstColorType) {
case CodecSrc::kGrayscale_Always_DstColorType:
if (kRGB_565_SkColorType == canvasColorType) {
return false;
}
*decodeInfo = decodeInfo->makeColorType(kGray_8_SkColorType);
break;
case CodecSrc::kNonNative8888_Always_DstColorType:
Add animation support to SkWebpCodec TBR=reed@google.com (No change to the public API, but changed a header file) SkWebpCodec: - Implement onGetFrameCount, onGetFrameInfo, and onGetRepetitionCount - Respect the alpha reported by libwebp. Although the spec states that it is only a hint, the libwebp encoder uses it properly. Respecting allows us to draw opaque images faster and decode them to 565. This also matches other SkCodecs (and Chromium). - onGetPixels: - Decode the frame requested, recursively decoding required frame if necessary - When blending with a prior frame, use SkRasterPipeline SkCodec: - Move check for negative index to getFrameInfo - Reset the colorXform if one is not needed SkCodecAnimation: - Add new blend enum, for WebP's (and APNG's) non-blending option SkFrameHolder: - New base classes for frames and the owner of the frames, allowing code sharing between SkWebpCodec and SkGifCodec (particularly for determining whether a frame has alpha and what frame it depends on) - When moving items from SkGIFFrameContext, use Skia conventions (i.e. int instead of unsigned) - Rename "delay time" to "duration", to match e.g. SkFrameInfo:: fDuration SkGifImageReader: - Move pieces to SkFrameHolder, and adapt to changes made in the process - Make setAlphaAndRequiredFrame (now on the base class SkFrameHolder) more general to support webp, and add support for frames that do not blend - Change SkGIFFrameContext from a struct to a class, to match how we use the distinction elsewhere (i.e. struct is a small object with public fields) - Rework hasTransparentPixel (now hasTransparency, since it returns true in some cases where there is not a transparent pixel) to better fit with the modified setAlphaAndRequiredFrame. Also be more consistent when there is no transparent pixel but no color map. - Simplify an if condition that was previously simplified in 2d61e717 but accidentally got reverted in a4db9be6 CodecAnimTest: - Test new animated webp files - Rearrange the test to more cleanly print alpha type mismatches for the first frame resources: - webp-animated.webp - animated webp from Chromium - blendBG.webp - new webp file using bits of webp-animated-semitransparent4.webp from Chromium - tests required frame and alpha when using the non-blending mode - frames have the following properties: - Frame 0: no alpha, fills screen - Frame 1: alpha, fills screen - Frame 2: no alpha, fills screen - Frame 3: alpha, fills screen, blendBG - Frame 4: no alpha, fills screen, blendBG - Frame 5: alpha, blendBG - Frame 6: covers 4, has alpha, blendBG - also used to test decoding to 565 if the new frame data has alpha but blends onto an opaque frame DM.cpp: - Test animated images to non-native 8888 and unpremul DMSrcSink.cpp: - Do not test non-native 8888 decodes to f16 dst - Test unpremul decodes to f16 - Copy a frame of an animated image prior to drawing, since in unpremul mode, the DM code will premultiply first. Bug: skia: 3315 Change-Id: I4e55ae2ee5bc095b37a743bdcfac644be603b980 Reviewed-on: https://skia-review.googlesource.com/16707 Commit-Queue: Mike Reed <reed@google.com> Reviewed-by: Mike Reed <reed@google.com> Reviewed-by: Leon Scroggins <scroggo@google.com> Reviewed-by: Matt Sarett <msarett@google.com>
2017-05-23 13:37:21 +00:00
if (kRGB_565_SkColorType == canvasColorType
|| kRGBA_F16_SkColorType == canvasColorType) {
return false;
}
#ifdef SK_PMCOLOR_IS_RGBA
*decodeInfo = decodeInfo->makeColorType(kBGRA_8888_SkColorType);
#else
*decodeInfo = decodeInfo->makeColorType(kRGBA_8888_SkColorType);
#endif
break;
default:
if (kRGB_565_SkColorType == canvasColorType &&
kOpaque_SkAlphaType != decodeInfo->alphaType()) {
return false;
}
*decodeInfo = decodeInfo->makeColorType(canvasColorType);
break;
}
*decodeInfo = decodeInfo->makeAlphaType(dstAlphaType);
return true;
}
static void draw_to_canvas(SkCanvas* canvas, const SkImageInfo& info, void* pixels, size_t rowBytes,
CodecSrc::DstColorType dstColorType,
SkScalar left = 0, SkScalar top = 0) {
SkBitmap bitmap;
bitmap.installPixels(info, pixels, rowBytes);
swap_rb_if_necessary(bitmap, dstColorType);
canvas->drawBitmap(bitmap, left, top);
}
// For codec srcs, we want the "draw" step to be a memcpy. Any interesting color space or
// color format conversions should be performed by the codec. Sometimes the output of the
// decode will be in an interesting color space. On our srgb and f16 backends, we need to
// "pretend" that the color space is standard sRGB to avoid triggering color conversion
// at draw time.
static void set_bitmap_color_space(SkImageInfo* info) {
Reland "Stop conflating F16 with linear gamma" This reverts commit 5f7b5e3624dcb055acc64fcf90c513408d1789ed. Reason for revert: Codec CL has re-landed. Original change's description: > Revert "Stop conflating F16 with linear gamma" > > This reverts commit d1589c7213d4a23c7c5c352f70d753eb7f07518d. > > Reason for revert: Depends on skcms CL that's been reverted. > > Original change's description: > > Stop conflating F16 with linear gamma > > > > Note to self: I debugged this, realized that the codecs > > need to handle A2B -> XYZ, then realized that I just need > > to wait for https://skia-review.googlesource.com/c/skia/+/136062 > > > > Bug: skia: > > Change-Id: I594c22076feb3700b8a40c471a541fef5ff4e13e > > Reviewed-on: https://skia-review.googlesource.com/137587 > > Commit-Queue: Brian Osman <brianosman@google.com> > > Reviewed-by: Mike Klein <mtklein@google.com> > > TBR=mtklein@google.com,brianosman@google.com > > Change-Id: I6dca583697c8efd2563d30cb7ab9ef505b6903ae > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia: > Reviewed-on: https://skia-review.googlesource.com/148860 > Reviewed-by: Brian Osman <brianosman@google.com> > Commit-Queue: Brian Osman <brianosman@google.com> TBR=mtklein@google.com,brianosman@google.com # Not skipping CQ checks because original CL landed > 1 day ago. Bug: skia: Change-Id: Iee66531049843758e7ed4130b99d8df6a553d805 Reviewed-on: https://skia-review.googlesource.com/149700 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Brian Osman <brianosman@google.com>
2018-08-27 19:16:02 +00:00
*info = info->makeColorSpace(SkColorSpace::MakeSRGB());
}
Result CodecSrc::draw(GrDirectContext*, SkCanvas* canvas) const {
sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
if (!encoded) {
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
return Result::Fatal("Couldn't read %s.", fPath.c_str());
}
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(encoded));
if (nullptr == codec) {
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
return Result::Fatal("Couldn't create codec for %s.", fPath.c_str());
}
SkImageInfo decodeInfo = codec->getInfo();
if (!get_decode_info(&decodeInfo, canvas->imageInfo().colorType(), fDstColorType,
fDstAlphaType)) {
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
return Result::Skip("Skipping uninteresting test.");
}
// Try to scale the image if it is desired
SkISize size = codec->getScaledDimensions(fScale);
Reland "SkAndroidCodec: Support decoding all frames" This is a reland of fc4fdc5b25f448dd9c2cd4e445561a840ce8514b Original change's description: > SkAndroidCodec: Support decoding all frames > > Bug: b/160984428 > Bug: b/163595585 > > Add support to SkAndroidCodec for decoding all frames with an > fSampleSize, so that an entire animation can be decoded to a smaller > size. > > dm/: > - Test scaled + animated decodes > > SkAndroidCodec: > - Make AndroidOptions inherit from SkCodec::Options. This allows > SkAndroidCodec to use fFrameIndex. (It also combines the two versions > of fSubset, which is now const for both.) > - Respect fFrameIndex, and call SkCodec::handleFrameIndex to decode > the required frame. > - Disallow decoding with kRespect + fFrameIndex > 0 if there is a > non-default orientation. As currently written (except without > disabling this combination), SkPixmapPriv::Orient would draw the new > portion of the frame on top of uninitialized pixels, instead of the > prior frame. This could be fixed by > - If SkAndroidCodec needs to decode the required frame, it could do so > without applying the orientation, then decode fFrameIndex, and then > apply the orientation. > - If the client provided the required frame, SkAndroidCodec would need > to un-apply the orientation to get the proper starting state, then > decode and apply. > I think it is simpler to force the client to handle the orientation > externally. > > SkCodec: > - Allow SkAndroidCodec to call its private method handleFrameIndex. This > method handles decoding a required frame, if necessary. When called by > SkAndroidCodec, it now uses the SkAndroidCodec to check for/decode the > required frame, so that it will scale properly. > - Call rewindIfNeeded inside handleFrameIndex. handleFrameIndex calls a > virtual method which may set some state (e.g. in SkJpegCodec). Without > this change, that state would be reset by rewindIfNeeded. > - Simplify handling a kRestoreBGColor frame. Whether provided or not, > take the same path to calling zero_rect. > - Updates to zero_rect: > - Intersect after scaling, which will also check for empty. > - Round out instead of in - this ensures we don't under-erase > - Use kFill_ScaleToFit, which better matches the intent. > > Change-Id: Ibe1951980a0dca8f5b7b1f20192432d395681683 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/333225 > Commit-Queue: Leon Scroggins <scroggo@google.com> > Reviewed-by: Derek Sollenberger <djsollen@google.com> Bug: b/160984428 Bug: b/163595585 Change-Id: I7c1e79e0f92c75b4840eef65c8fc2b8497189e81 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/334842 Auto-Submit: Leon Scroggins <scroggo@google.com> Commit-Queue: Derek Sollenberger <djsollen@google.com> Reviewed-by: Derek Sollenberger <djsollen@google.com>
2020-11-09 19:18:12 +00:00
std::unique_ptr<SkAndroidCodec> androidCodec;
if (1.0f != fScale && fMode == kAnimated_Mode) {
androidCodec = SkAndroidCodec::MakeFromData(encoded);
size = androidCodec->getSampledDimensions(1 / fScale);
}
if (size == decodeInfo.dimensions() && 1.0f != fScale) {
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
return Result::Skip("Test without scaling is uninteresting.");
}
// Visually inspecting very small output images is not necessary. We will
// cover these cases in unit testing.
if ((size.width() <= 10 || size.height() <= 10) && 1.0f != fScale) {
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
return Result::Skip("Scaling very small images is uninteresting.");
}
Reland "Reland "SkSurface asynchronous read APIs allow client to extend pixel lifetime"" This is a reland of 6fc04f88a89ed2c9a1b4aa48bcd28602a69a457b Original change's description: > Reland "SkSurface asynchronous read APIs allow client to extend pixel lifetime" > > This is a reland of ce240cc6fd8ec95bd051c7df2173dad2ae8f6ad6 > > Original change's description: > > SkSurface asynchronous read APIs allow client to extend pixel lifetime > > > > Previously the pixel data passed to the client was only valid during > > the client's callback. This meant if the client wanted to defer > > processing of the data a copy was necessary. > > > > Now we pass an object to the callback and the pixel lifetime is tied > > to the lifetime of that object. > > > > The object may be holding a GPU transfer buffer mapped. We don't assume > > that the object will be released on the direct GrContext thread. So > > when the object is destroyed it posts a message to a new type, > > GrClientMappedBufferManager, hanging off the direct context. The direct > > context will periodically check for messages and unmap and then unref > > buffers so that they can be reused. Currently this is done in > > GrContext::performDeferredCleanup() and GrDrawingManager::flush(). > > > > The old API is kept around for backwards compatibility but it is > > reimplemented as a bridge on top of the new mechanism. > > > > Also a utility function to SkImageInfo is added to directly make a new > > info with a specified dimensions rather than passing the width and > > height separately to makeWH(). > > > > Bug: chromium:973403 > > Bug: skia:8962 > > > > Change-Id: Id5cf04235376170142a48e90d3ecd13fd021a2a6 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/245457 > > Reviewed-by: Brian Osman <brianosman@google.com> > > Commit-Queue: Brian Salomon <bsalomon@google.com> > > Bug: chromium:973403, skia:8962 > Change-Id: I5cecd36276c8b6dc942cf549c7095db2df88530c > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/245678 > Reviewed-by: Brian Salomon <bsalomon@google.com> > Commit-Queue: Brian Salomon <bsalomon@google.com> Bug: chromium:973403, skia:8962 Change-Id: Ie584c1c3ef8021c976f71b708e53871c693cc450 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/246057 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
2019-10-03 17:26:54 +00:00
decodeInfo = decodeInfo.makeDimensions(size);
const int bpp = decodeInfo.bytesPerPixel();
const size_t rowBytes = size.width() * bpp;
const size_t safeSize = decodeInfo.computeByteSize(rowBytes);
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
SkAutoMalloc pixels(safeSize);
SkCodec::Options options;
if (kCodecZeroInit_Mode == fMode) {
memset(pixels.get(), 0, size.height() * rowBytes);
options.fZeroInitialized = SkCodec::kYes_ZeroInitialized;
}
SkImageInfo bitmapInfo = decodeInfo;
set_bitmap_color_space(&bitmapInfo);
if (kRGBA_8888_SkColorType == decodeInfo.colorType() ||
kBGRA_8888_SkColorType == decodeInfo.colorType()) {
bitmapInfo = bitmapInfo.makeColorType(kN32_SkColorType);
}
switch (fMode) {
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
case kAnimated_Mode: {
Reland "SkAndroidCodec: Support decoding all frames" This is a reland of fc4fdc5b25f448dd9c2cd4e445561a840ce8514b Original change's description: > SkAndroidCodec: Support decoding all frames > > Bug: b/160984428 > Bug: b/163595585 > > Add support to SkAndroidCodec for decoding all frames with an > fSampleSize, so that an entire animation can be decoded to a smaller > size. > > dm/: > - Test scaled + animated decodes > > SkAndroidCodec: > - Make AndroidOptions inherit from SkCodec::Options. This allows > SkAndroidCodec to use fFrameIndex. (It also combines the two versions > of fSubset, which is now const for both.) > - Respect fFrameIndex, and call SkCodec::handleFrameIndex to decode > the required frame. > - Disallow decoding with kRespect + fFrameIndex > 0 if there is a > non-default orientation. As currently written (except without > disabling this combination), SkPixmapPriv::Orient would draw the new > portion of the frame on top of uninitialized pixels, instead of the > prior frame. This could be fixed by > - If SkAndroidCodec needs to decode the required frame, it could do so > without applying the orientation, then decode fFrameIndex, and then > apply the orientation. > - If the client provided the required frame, SkAndroidCodec would need > to un-apply the orientation to get the proper starting state, then > decode and apply. > I think it is simpler to force the client to handle the orientation > externally. > > SkCodec: > - Allow SkAndroidCodec to call its private method handleFrameIndex. This > method handles decoding a required frame, if necessary. When called by > SkAndroidCodec, it now uses the SkAndroidCodec to check for/decode the > required frame, so that it will scale properly. > - Call rewindIfNeeded inside handleFrameIndex. handleFrameIndex calls a > virtual method which may set some state (e.g. in SkJpegCodec). Without > this change, that state would be reset by rewindIfNeeded. > - Simplify handling a kRestoreBGColor frame. Whether provided or not, > take the same path to calling zero_rect. > - Updates to zero_rect: > - Intersect after scaling, which will also check for empty. > - Round out instead of in - this ensures we don't under-erase > - Use kFill_ScaleToFit, which better matches the intent. > > Change-Id: Ibe1951980a0dca8f5b7b1f20192432d395681683 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/333225 > Commit-Queue: Leon Scroggins <scroggo@google.com> > Reviewed-by: Derek Sollenberger <djsollen@google.com> Bug: b/160984428 Bug: b/163595585 Change-Id: I7c1e79e0f92c75b4840eef65c8fc2b8497189e81 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/334842 Auto-Submit: Leon Scroggins <scroggo@google.com> Commit-Queue: Derek Sollenberger <djsollen@google.com> Reviewed-by: Derek Sollenberger <djsollen@google.com>
2020-11-09 19:18:12 +00:00
SkAndroidCodec::AndroidOptions androidOptions;
if (fScale != 1.0f) {
SkASSERT(androidCodec);
androidOptions.fSampleSize = 1 / fScale;
auto dims = androidCodec->getSampledDimensions(androidOptions.fSampleSize);
decodeInfo = decodeInfo.makeDimensions(dims);
}
std::vector<SkCodec::FrameInfo> frameInfos = androidCodec
? androidCodec->codec()->getFrameInfo() : codec->getFrameInfo();
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
if (frameInfos.size() <= 1) {
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
return Result::Fatal("%s is not an animated image.", fPath.c_str());
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
}
// As in CodecSrc::size(), compute a roughly square grid to draw the frames
// into. "factor" is the number of frames to draw on one row. There will be
// up to "factor" rows as well.
const float root = sqrt((float) frameInfos.size());
const int factor = sk_float_ceil2int(root);
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
// Used to cache a frame that future frames will depend on.
SkAutoMalloc priorFramePixels;
int cachedFrame = SkCodec::kNoFrame;
for (int i = 0; static_cast<size_t>(i) < frameInfos.size(); i++) {
Reland "SkAndroidCodec: Support decoding all frames" This is a reland of fc4fdc5b25f448dd9c2cd4e445561a840ce8514b Original change's description: > SkAndroidCodec: Support decoding all frames > > Bug: b/160984428 > Bug: b/163595585 > > Add support to SkAndroidCodec for decoding all frames with an > fSampleSize, so that an entire animation can be decoded to a smaller > size. > > dm/: > - Test scaled + animated decodes > > SkAndroidCodec: > - Make AndroidOptions inherit from SkCodec::Options. This allows > SkAndroidCodec to use fFrameIndex. (It also combines the two versions > of fSubset, which is now const for both.) > - Respect fFrameIndex, and call SkCodec::handleFrameIndex to decode > the required frame. > - Disallow decoding with kRespect + fFrameIndex > 0 if there is a > non-default orientation. As currently written (except without > disabling this combination), SkPixmapPriv::Orient would draw the new > portion of the frame on top of uninitialized pixels, instead of the > prior frame. This could be fixed by > - If SkAndroidCodec needs to decode the required frame, it could do so > without applying the orientation, then decode fFrameIndex, and then > apply the orientation. > - If the client provided the required frame, SkAndroidCodec would need > to un-apply the orientation to get the proper starting state, then > decode and apply. > I think it is simpler to force the client to handle the orientation > externally. > > SkCodec: > - Allow SkAndroidCodec to call its private method handleFrameIndex. This > method handles decoding a required frame, if necessary. When called by > SkAndroidCodec, it now uses the SkAndroidCodec to check for/decode the > required frame, so that it will scale properly. > - Call rewindIfNeeded inside handleFrameIndex. handleFrameIndex calls a > virtual method which may set some state (e.g. in SkJpegCodec). Without > this change, that state would be reset by rewindIfNeeded. > - Simplify handling a kRestoreBGColor frame. Whether provided or not, > take the same path to calling zero_rect. > - Updates to zero_rect: > - Intersect after scaling, which will also check for empty. > - Round out instead of in - this ensures we don't under-erase > - Use kFill_ScaleToFit, which better matches the intent. > > Change-Id: Ibe1951980a0dca8f5b7b1f20192432d395681683 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/333225 > Commit-Queue: Leon Scroggins <scroggo@google.com> > Reviewed-by: Derek Sollenberger <djsollen@google.com> Bug: b/160984428 Bug: b/163595585 Change-Id: I7c1e79e0f92c75b4840eef65c8fc2b8497189e81 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/334842 Auto-Submit: Leon Scroggins <scroggo@google.com> Commit-Queue: Derek Sollenberger <djsollen@google.com> Reviewed-by: Derek Sollenberger <djsollen@google.com>
2020-11-09 19:18:12 +00:00
androidOptions.fFrameIndex = i;
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
// Check for a prior frame
const int reqFrame = frameInfos[i].fRequiredFrame;
if (reqFrame != SkCodec::kNoFrame && reqFrame == cachedFrame
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
&& priorFramePixels.get()) {
// Copy into pixels
memcpy(pixels.get(), priorFramePixels.get(), safeSize);
Reland "SkAndroidCodec: Support decoding all frames" This is a reland of fc4fdc5b25f448dd9c2cd4e445561a840ce8514b Original change's description: > SkAndroidCodec: Support decoding all frames > > Bug: b/160984428 > Bug: b/163595585 > > Add support to SkAndroidCodec for decoding all frames with an > fSampleSize, so that an entire animation can be decoded to a smaller > size. > > dm/: > - Test scaled + animated decodes > > SkAndroidCodec: > - Make AndroidOptions inherit from SkCodec::Options. This allows > SkAndroidCodec to use fFrameIndex. (It also combines the two versions > of fSubset, which is now const for both.) > - Respect fFrameIndex, and call SkCodec::handleFrameIndex to decode > the required frame. > - Disallow decoding with kRespect + fFrameIndex > 0 if there is a > non-default orientation. As currently written (except without > disabling this combination), SkPixmapPriv::Orient would draw the new > portion of the frame on top of uninitialized pixels, instead of the > prior frame. This could be fixed by > - If SkAndroidCodec needs to decode the required frame, it could do so > without applying the orientation, then decode fFrameIndex, and then > apply the orientation. > - If the client provided the required frame, SkAndroidCodec would need > to un-apply the orientation to get the proper starting state, then > decode and apply. > I think it is simpler to force the client to handle the orientation > externally. > > SkCodec: > - Allow SkAndroidCodec to call its private method handleFrameIndex. This > method handles decoding a required frame, if necessary. When called by > SkAndroidCodec, it now uses the SkAndroidCodec to check for/decode the > required frame, so that it will scale properly. > - Call rewindIfNeeded inside handleFrameIndex. handleFrameIndex calls a > virtual method which may set some state (e.g. in SkJpegCodec). Without > this change, that state would be reset by rewindIfNeeded. > - Simplify handling a kRestoreBGColor frame. Whether provided or not, > take the same path to calling zero_rect. > - Updates to zero_rect: > - Intersect after scaling, which will also check for empty. > - Round out instead of in - this ensures we don't under-erase > - Use kFill_ScaleToFit, which better matches the intent. > > Change-Id: Ibe1951980a0dca8f5b7b1f20192432d395681683 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/333225 > Commit-Queue: Leon Scroggins <scroggo@google.com> > Reviewed-by: Derek Sollenberger <djsollen@google.com> Bug: b/160984428 Bug: b/163595585 Change-Id: I7c1e79e0f92c75b4840eef65c8fc2b8497189e81 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/334842 Auto-Submit: Leon Scroggins <scroggo@google.com> Commit-Queue: Derek Sollenberger <djsollen@google.com> Reviewed-by: Derek Sollenberger <djsollen@google.com>
2020-11-09 19:18:12 +00:00
androidOptions.fPriorFrame = reqFrame;
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
} else {
Reland "SkAndroidCodec: Support decoding all frames" This is a reland of fc4fdc5b25f448dd9c2cd4e445561a840ce8514b Original change's description: > SkAndroidCodec: Support decoding all frames > > Bug: b/160984428 > Bug: b/163595585 > > Add support to SkAndroidCodec for decoding all frames with an > fSampleSize, so that an entire animation can be decoded to a smaller > size. > > dm/: > - Test scaled + animated decodes > > SkAndroidCodec: > - Make AndroidOptions inherit from SkCodec::Options. This allows > SkAndroidCodec to use fFrameIndex. (It also combines the two versions > of fSubset, which is now const for both.) > - Respect fFrameIndex, and call SkCodec::handleFrameIndex to decode > the required frame. > - Disallow decoding with kRespect + fFrameIndex > 0 if there is a > non-default orientation. As currently written (except without > disabling this combination), SkPixmapPriv::Orient would draw the new > portion of the frame on top of uninitialized pixels, instead of the > prior frame. This could be fixed by > - If SkAndroidCodec needs to decode the required frame, it could do so > without applying the orientation, then decode fFrameIndex, and then > apply the orientation. > - If the client provided the required frame, SkAndroidCodec would need > to un-apply the orientation to get the proper starting state, then > decode and apply. > I think it is simpler to force the client to handle the orientation > externally. > > SkCodec: > - Allow SkAndroidCodec to call its private method handleFrameIndex. This > method handles decoding a required frame, if necessary. When called by > SkAndroidCodec, it now uses the SkAndroidCodec to check for/decode the > required frame, so that it will scale properly. > - Call rewindIfNeeded inside handleFrameIndex. handleFrameIndex calls a > virtual method which may set some state (e.g. in SkJpegCodec). Without > this change, that state would be reset by rewindIfNeeded. > - Simplify handling a kRestoreBGColor frame. Whether provided or not, > take the same path to calling zero_rect. > - Updates to zero_rect: > - Intersect after scaling, which will also check for empty. > - Round out instead of in - this ensures we don't under-erase > - Use kFill_ScaleToFit, which better matches the intent. > > Change-Id: Ibe1951980a0dca8f5b7b1f20192432d395681683 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/333225 > Commit-Queue: Leon Scroggins <scroggo@google.com> > Reviewed-by: Derek Sollenberger <djsollen@google.com> Bug: b/160984428 Bug: b/163595585 Change-Id: I7c1e79e0f92c75b4840eef65c8fc2b8497189e81 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/334842 Auto-Submit: Leon Scroggins <scroggo@google.com> Commit-Queue: Derek Sollenberger <djsollen@google.com> Reviewed-by: Derek Sollenberger <djsollen@google.com>
2020-11-09 19:18:12 +00:00
androidOptions.fPriorFrame = SkCodec::kNoFrame;
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
}
Reland "SkAndroidCodec: Support decoding all frames" This is a reland of fc4fdc5b25f448dd9c2cd4e445561a840ce8514b Original change's description: > SkAndroidCodec: Support decoding all frames > > Bug: b/160984428 > Bug: b/163595585 > > Add support to SkAndroidCodec for decoding all frames with an > fSampleSize, so that an entire animation can be decoded to a smaller > size. > > dm/: > - Test scaled + animated decodes > > SkAndroidCodec: > - Make AndroidOptions inherit from SkCodec::Options. This allows > SkAndroidCodec to use fFrameIndex. (It also combines the two versions > of fSubset, which is now const for both.) > - Respect fFrameIndex, and call SkCodec::handleFrameIndex to decode > the required frame. > - Disallow decoding with kRespect + fFrameIndex > 0 if there is a > non-default orientation. As currently written (except without > disabling this combination), SkPixmapPriv::Orient would draw the new > portion of the frame on top of uninitialized pixels, instead of the > prior frame. This could be fixed by > - If SkAndroidCodec needs to decode the required frame, it could do so > without applying the orientation, then decode fFrameIndex, and then > apply the orientation. > - If the client provided the required frame, SkAndroidCodec would need > to un-apply the orientation to get the proper starting state, then > decode and apply. > I think it is simpler to force the client to handle the orientation > externally. > > SkCodec: > - Allow SkAndroidCodec to call its private method handleFrameIndex. This > method handles decoding a required frame, if necessary. When called by > SkAndroidCodec, it now uses the SkAndroidCodec to check for/decode the > required frame, so that it will scale properly. > - Call rewindIfNeeded inside handleFrameIndex. handleFrameIndex calls a > virtual method which may set some state (e.g. in SkJpegCodec). Without > this change, that state would be reset by rewindIfNeeded. > - Simplify handling a kRestoreBGColor frame. Whether provided or not, > take the same path to calling zero_rect. > - Updates to zero_rect: > - Intersect after scaling, which will also check for empty. > - Round out instead of in - this ensures we don't under-erase > - Use kFill_ScaleToFit, which better matches the intent. > > Change-Id: Ibe1951980a0dca8f5b7b1f20192432d395681683 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/333225 > Commit-Queue: Leon Scroggins <scroggo@google.com> > Reviewed-by: Derek Sollenberger <djsollen@google.com> Bug: b/160984428 Bug: b/163595585 Change-Id: I7c1e79e0f92c75b4840eef65c8fc2b8497189e81 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/334842 Auto-Submit: Leon Scroggins <scroggo@google.com> Commit-Queue: Derek Sollenberger <djsollen@google.com> Reviewed-by: Derek Sollenberger <djsollen@google.com>
2020-11-09 19:18:12 +00:00
SkCodec::Result result = androidCodec
? androidCodec->getAndroidPixels(decodeInfo, pixels.get(), rowBytes,
&androidOptions)
: codec->getPixels(decodeInfo, pixels.get(), rowBytes, &androidOptions);
Fix SkGifCodec bugs around truncated data Prior to this CL, if a GIF file was truncated before reading the local color map of a frame, incremental decode would do the wrong thing. In onStartIncrementalDecode, we would either create a color table based on the global color map, or we would create a dummy one with only one color (transparent). The dummy color table is correct if there is neither a global nor a local color map, and allows us to fill the frame with transparent. But if more data is provided, and it includes an actual color map and image data, one of the following can happen: - If the created color table is smaller than the actual one, the decoded data may include indices outside of the range of the created color table, resulting in a crash. - If we get lucky, and the created color table is large enough, it may still be the wrong colors (and most likely is). To solve this, make onStartIncrementalDecode fail if there is a local color map that has not been read yet. A future call may read more data and read the correct color map. This is done by returning kIncompleteInput in SkGifCodec::prepareToDecode if there is a local color map that has not yet been read. (It is possible that there is no color map at all, in which case we still need to support decoding that frame. Skip attempting to decode in that case.) In onGetPixels, if prepareToDecode returned kIncompleteInput, return kInvalidInput. Although the input is technically incomplete, no future call will provide more data (unlike in incremental decoding), and there is nothing interesting for the client to draw. This also prevents SkCodec from attempting to fill the data with an SkSwizzler, which has not been created. (An alternative solution would be create the dummy color table and an SkSwizzler, which would keep the current behavior. But I think the new behavior of returning kInvalidInput makes more sense.) Add tests to verify the intended behavior: - getPixels fails. - startIncrementalDecode fails, but after providing more data it will succeed and incremental decoding matches the image decoded from the full stream. - Both succeed if there is no color table at all. Change-Id: Ifb52fe7f723673406a28e80c8805a552f0ac33b6 Reviewed-on: https://skia-review.googlesource.com/5758 Reviewed-by: Matt Sarett <msarett@google.com> Commit-Queue: Leon Scroggins <scroggo@google.com>
2016-12-09 21:39:33 +00:00
if (SkCodec::kInvalidInput == result && i > 0) {
// Some of our test images have truncated later frames. Treat that
// the same as incomplete.
result = SkCodec::kIncompleteInput;
}
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
switch (result) {
case SkCodec::kSuccess:
case SkCodec::kErrorInInput:
case SkCodec::kIncompleteInput: {
Add animation support to SkWebpCodec TBR=reed@google.com (No change to the public API, but changed a header file) SkWebpCodec: - Implement onGetFrameCount, onGetFrameInfo, and onGetRepetitionCount - Respect the alpha reported by libwebp. Although the spec states that it is only a hint, the libwebp encoder uses it properly. Respecting allows us to draw opaque images faster and decode them to 565. This also matches other SkCodecs (and Chromium). - onGetPixels: - Decode the frame requested, recursively decoding required frame if necessary - When blending with a prior frame, use SkRasterPipeline SkCodec: - Move check for negative index to getFrameInfo - Reset the colorXform if one is not needed SkCodecAnimation: - Add new blend enum, for WebP's (and APNG's) non-blending option SkFrameHolder: - New base classes for frames and the owner of the frames, allowing code sharing between SkWebpCodec and SkGifCodec (particularly for determining whether a frame has alpha and what frame it depends on) - When moving items from SkGIFFrameContext, use Skia conventions (i.e. int instead of unsigned) - Rename "delay time" to "duration", to match e.g. SkFrameInfo:: fDuration SkGifImageReader: - Move pieces to SkFrameHolder, and adapt to changes made in the process - Make setAlphaAndRequiredFrame (now on the base class SkFrameHolder) more general to support webp, and add support for frames that do not blend - Change SkGIFFrameContext from a struct to a class, to match how we use the distinction elsewhere (i.e. struct is a small object with public fields) - Rework hasTransparentPixel (now hasTransparency, since it returns true in some cases where there is not a transparent pixel) to better fit with the modified setAlphaAndRequiredFrame. Also be more consistent when there is no transparent pixel but no color map. - Simplify an if condition that was previously simplified in 2d61e717 but accidentally got reverted in a4db9be6 CodecAnimTest: - Test new animated webp files - Rearrange the test to more cleanly print alpha type mismatches for the first frame resources: - webp-animated.webp - animated webp from Chromium - blendBG.webp - new webp file using bits of webp-animated-semitransparent4.webp from Chromium - tests required frame and alpha when using the non-blending mode - frames have the following properties: - Frame 0: no alpha, fills screen - Frame 1: alpha, fills screen - Frame 2: no alpha, fills screen - Frame 3: alpha, fills screen, blendBG - Frame 4: no alpha, fills screen, blendBG - Frame 5: alpha, blendBG - Frame 6: covers 4, has alpha, blendBG - also used to test decoding to 565 if the new frame data has alpha but blends onto an opaque frame DM.cpp: - Test animated images to non-native 8888 and unpremul DMSrcSink.cpp: - Do not test non-native 8888 decodes to f16 dst - Test unpremul decodes to f16 - Copy a frame of an animated image prior to drawing, since in unpremul mode, the DM code will premultiply first. Bug: skia: 3315 Change-Id: I4e55ae2ee5bc095b37a743bdcfac644be603b980 Reviewed-on: https://skia-review.googlesource.com/16707 Commit-Queue: Mike Reed <reed@google.com> Reviewed-by: Mike Reed <reed@google.com> Reviewed-by: Leon Scroggins <scroggo@google.com> Reviewed-by: Matt Sarett <msarett@google.com>
2017-05-23 13:37:21 +00:00
// If the next frame depends on this one, store it in priorFrame.
// It is possible that we may discard a frame that future frames depend on,
// but the codec will simply redecode the discarded frame.
// Do this before calling draw_to_canvas, which premultiplies in place. If
// we're decoding to unpremul, we want to pass the unmodified frame to the
// codec for decoding the next frame.
if (static_cast<size_t>(i+1) < frameInfos.size()
&& frameInfos[i+1].fRequiredFrame == i) {
memcpy(priorFramePixels.reset(safeSize), pixels.get(), safeSize);
cachedFrame = i;
}
SkAutoCanvasRestore acr(canvas, true);
const int xTranslate = (i % factor) * decodeInfo.width();
const int yTranslate = (i / factor) * decodeInfo.height();
canvas->translate(SkIntToScalar(xTranslate), SkIntToScalar(yTranslate));
draw_to_canvas(canvas, bitmapInfo, pixels.get(), rowBytes, fDstColorType);
if (result != SkCodec::kSuccess) {
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
return Result::Ok();
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
}
break;
}
case SkCodec::kInvalidConversion:
if (i > 0 && (decodeInfo.colorType() == kRGB_565_SkColorType)) {
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
return Result::Skip(
"Cannot decode frame %i to 565 (%s).", i, fPath.c_str());
}
[[fallthrough]];
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
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
return Result::Fatal(
"Couldn't getPixels for frame %i in %s.", i, fPath.c_str());
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
}
}
break;
}
case kCodecZeroInit_Mode:
case kCodec_Mode: {
switch (codec->getPixels(decodeInfo, pixels.get(), rowBytes, &options)) {
case SkCodec::kSuccess:
// We consider these to be valid, since we should still decode what is
// available.
case SkCodec::kErrorInInput:
case SkCodec::kIncompleteInput:
break;
default:
// Everything else is considered a failure.
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
return Result::Fatal("Couldn't getPixels %s.", fPath.c_str());
}
draw_to_canvas(canvas, bitmapInfo, pixels.get(), rowBytes, fDstColorType);
break;
}
case kScanline_Mode: {
Revert of Make SkPngCodec decode progressively. (patchset #26 id:520001 of https://codereview.chromium.org/1997703003/ ) Reason for revert: Still causing problems in Google3, e.g. https://test.corp.google.com/ui#cl=124138817&flags=CAMQBQ==&id=OCL:124138817:BASE:124139560:1465227435491:219ffbdb&t=//third_party/skia/HEAD:dm Original issue's description: > Make SkPngCodec decode progressively. > > This is a step towards using SkCodec in Chromium, where progressive > decoding is necessary. > > Switch from using png_read_row (which expects all the data to be > available) to png_process_data, which uses callbacks when rows are > available. > > Create a new API for SkCodec, which supports progressive decoding and > scanline decoding. Future changes will switch the other clients off of > startScanlineDecode and get/skip-Scanlines to the new API. > > Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced > PNG images. In the new API, interlaced PNG fits kTopDown. Also remove > updateCurrScanline(), which was only used by the old implementation for > interlaced PNG. > > DMSrcSink: > - In CodecSrc::kScanline_Mode, use the new method for scanline decoding > for the supported formats (just PNG and PNG-in-ICO for now). > > fuzz.cpp: > - Remove reference to kNone_ScanlineOrder > > SkCodec: > - Add new APIs: > - startIncrementalDecode > - incrementalDecode > - Remove kNone_SkScanlineOrder and updateCurrScanline() > > SkPngCodec: > - Implement new APIs > - Switch from sk_read_fn/png_read_row etc to png_process_data > - Expand AutoCleanPng's role to decode the header and create the > SkPngCodec > - Make the interlaced PNG decoder report how many lines were > initialized during an incomplete decode > - Make initializeSwizzler return a bool instead of an SkCodec::Result > (It only returned kSuccess or kInvalidInput anyway) > > SkIcoCodec: > - Implement the new APIs; supported for PNG in ICO > > SkSampledCodec: > - Call the new method for decoding scanlines, and fall back to the old > method if the new version is unimplemented > - Remove references to kNone_SkScanlineOrder > > tests/CodecPartial: > - Add a test which decodes part of an image, then finishes the decode, > and compares it to the straightforward method > > tests/CodecTest: > - Add a test which decodes all scanlines using the new method > - Repurpose the Codec_stripes test to decode using the new method in > sections rather than all at once > - In the method check(), add a parameter for whether the image supports > the new method of scanline decoding, and be explicit about whether an > image supports incomplete > - Test incomplete PNG decodes. We should have been doing it anyway for > non-interlaced (except for an image that is too small - one row), but > the new method supports interlaced incomplete as well > - Make test_invalid_parameters test the new method > - Add a test to ensure that it's safe to fall back to scanline decoding without > rewinding > > BUG=skia:4211 > > The new version was generally faster than the old version (but not significantly so). > > Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/ > > Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/ > > GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003 > > Committed: https://skia.googlesource.com/skia/+/a4b09a117d4d1ba5dda372e6a2323e653766539e > > Committed: https://skia.googlesource.com/skia/+/30e78c9737ff4861dc4e3fa1e4cd010680ed6965 > > Committed: https://skia.googlesource.com/skia/+/6fb2391b2cc83ee2160b4e994faa8128975acc1f TBR=reed@google.com,msarett@google.com,scroggo@chromium.org # Not skipping CQ checks because original CL landed more than 1 days ago. BUG=skia:4211 GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2044573002 Review-Url: https://codereview.chromium.org/2044573002
2016-06-06 18:26:17 +00:00
void* dst = pixels.get();
uint32_t height = decodeInfo.height();
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
const bool useIncremental = [this]() {
auto exts = { "png", "PNG", "gif", "GIF" };
for (auto ext : exts) {
if (fPath.endsWith(ext)) {
return true;
}
}
return false;
}();
// ico may use the old scanline method or the new one, depending on whether it
// internally holds a bmp or a png.
Make SkPngCodec decode progressively. This is a step towards using SkCodec in Chromium, where progressive decoding is necessary. Switch from using png_read_row (which expects all the data to be available) to png_process_data, which uses callbacks when rows are available. Create a new API for SkCodec, which supports progressive decoding and scanline decoding. Future changes will switch the other clients off of startScanlineDecode and get/skip-Scanlines to the new API. Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced PNG images. In the new API, interlaced PNG fits kTopDown. Also remove updateCurrScanline(), which was only used by the old implementation for interlaced PNG. DMSrcSink: - In CodecSrc::kScanline_Mode, use the new method for scanline decoding for the supported formats (just PNG and PNG-in-ICO for now). fuzz.cpp: - Remove reference to kNone_ScanlineOrder SkCodec: - Add new APIs: - startIncrementalDecode - incrementalDecode - Remove kNone_SkScanlineOrder and updateCurrScanline() - Set fDstInfo and fOptions in getPixels(). This may not be necessary for all implementations, but it simplifies things for SkPngCodec. SkPngCodec: - Implement new APIs - Switch from sk_read_fn/png_read_row etc to png_process_data - Expand AutoCleanPng's role to decode the header and create the SkPngCodec - Make the interlaced PNG decoder report how many lines were initialized during an incomplete decode SkIcoCodec: - Implement the new APIs; supported for PNG in ICO SkSampledCodec: - Call the new method for decoding scanlines, and fall back to the old method if the new version is unimplemented - Remove references to kNone_SkScanlineOrder tests/CodecPartial: - Add a test which decodes part of an image, then finishes the decode, and compares it to the straightforward method tests/CodecTest: - Add a test which decodes all scanlines using the new method - Repurpose the Codec_stripes test to decode using the new method in sections rather than all at once - In the method check(), add a parameter for whether the image supports the new method of scanline decoding, and be explicit about whether an image supports incomplete - Test incomplete PNG decodes. We should have been doing it anyway for non-interlaced (except for an image that is too small - one row), but the new method supports interlaced incomplete as well - Make test_invalid_parameters test the new method - Add a test to ensure that it's safe to fall back to scanline decoding without rewinding BUG=skia:4211 The new version was generally faster than the old version (but not significantly so). Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/ Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/ GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003 Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
const bool ico = fPath.endsWith("ico");
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
bool useOldScanlineMethod = !useIncremental && !ico;
if (useIncremental || ico) {
Make SkPngCodec decode progressively. This is a step towards using SkCodec in Chromium, where progressive decoding is necessary. Switch from using png_read_row (which expects all the data to be available) to png_process_data, which uses callbacks when rows are available. Create a new API for SkCodec, which supports progressive decoding and scanline decoding. Future changes will switch the other clients off of startScanlineDecode and get/skip-Scanlines to the new API. Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced PNG images. In the new API, interlaced PNG fits kTopDown. Also remove updateCurrScanline(), which was only used by the old implementation for interlaced PNG. DMSrcSink: - In CodecSrc::kScanline_Mode, use the new method for scanline decoding for the supported formats (just PNG and PNG-in-ICO for now). fuzz.cpp: - Remove reference to kNone_ScanlineOrder SkCodec: - Add new APIs: - startIncrementalDecode - incrementalDecode - Remove kNone_SkScanlineOrder and updateCurrScanline() - Set fDstInfo and fOptions in getPixels(). This may not be necessary for all implementations, but it simplifies things for SkPngCodec. SkPngCodec: - Implement new APIs - Switch from sk_read_fn/png_read_row etc to png_process_data - Expand AutoCleanPng's role to decode the header and create the SkPngCodec - Make the interlaced PNG decoder report how many lines were initialized during an incomplete decode SkIcoCodec: - Implement the new APIs; supported for PNG in ICO SkSampledCodec: - Call the new method for decoding scanlines, and fall back to the old method if the new version is unimplemented - Remove references to kNone_SkScanlineOrder tests/CodecPartial: - Add a test which decodes part of an image, then finishes the decode, and compares it to the straightforward method tests/CodecTest: - Add a test which decodes all scanlines using the new method - Repurpose the Codec_stripes test to decode using the new method in sections rather than all at once - In the method check(), add a parameter for whether the image supports the new method of scanline decoding, and be explicit about whether an image supports incomplete - Test incomplete PNG decodes. We should have been doing it anyway for non-interlaced (except for an image that is too small - one row), but the new method supports interlaced incomplete as well - Make test_invalid_parameters test the new method - Add a test to ensure that it's safe to fall back to scanline decoding without rewinding BUG=skia:4211 The new version was generally faster than the old version (but not significantly so). Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/ Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/ GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003 Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
if (SkCodec::kSuccess == codec->startIncrementalDecode(decodeInfo, dst,
rowBytes, &options)) {
Make SkPngCodec decode progressively. This is a step towards using SkCodec in Chromium, where progressive decoding is necessary. Switch from using png_read_row (which expects all the data to be available) to png_process_data, which uses callbacks when rows are available. Create a new API for SkCodec, which supports progressive decoding and scanline decoding. Future changes will switch the other clients off of startScanlineDecode and get/skip-Scanlines to the new API. Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced PNG images. In the new API, interlaced PNG fits kTopDown. Also remove updateCurrScanline(), which was only used by the old implementation for interlaced PNG. DMSrcSink: - In CodecSrc::kScanline_Mode, use the new method for scanline decoding for the supported formats (just PNG and PNG-in-ICO for now). fuzz.cpp: - Remove reference to kNone_ScanlineOrder SkCodec: - Add new APIs: - startIncrementalDecode - incrementalDecode - Remove kNone_SkScanlineOrder and updateCurrScanline() - Set fDstInfo and fOptions in getPixels(). This may not be necessary for all implementations, but it simplifies things for SkPngCodec. SkPngCodec: - Implement new APIs - Switch from sk_read_fn/png_read_row etc to png_process_data - Expand AutoCleanPng's role to decode the header and create the SkPngCodec - Make the interlaced PNG decoder report how many lines were initialized during an incomplete decode SkIcoCodec: - Implement the new APIs; supported for PNG in ICO SkSampledCodec: - Call the new method for decoding scanlines, and fall back to the old method if the new version is unimplemented - Remove references to kNone_SkScanlineOrder tests/CodecPartial: - Add a test which decodes part of an image, then finishes the decode, and compares it to the straightforward method tests/CodecTest: - Add a test which decodes all scanlines using the new method - Repurpose the Codec_stripes test to decode using the new method in sections rather than all at once - In the method check(), add a parameter for whether the image supports the new method of scanline decoding, and be explicit about whether an image supports incomplete - Test incomplete PNG decodes. We should have been doing it anyway for non-interlaced (except for an image that is too small - one row), but the new method supports interlaced incomplete as well - Make test_invalid_parameters test the new method - Add a test to ensure that it's safe to fall back to scanline decoding without rewinding BUG=skia:4211 The new version was generally faster than the old version (but not significantly so). Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/ Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/ GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003 Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
int rowsDecoded;
auto result = codec->incrementalDecode(&rowsDecoded);
if (SkCodec::kIncompleteInput == result || SkCodec::kErrorInInput == result) {
Make SkPngCodec decode progressively. This is a step towards using SkCodec in Chromium, where progressive decoding is necessary. Switch from using png_read_row (which expects all the data to be available) to png_process_data, which uses callbacks when rows are available. Create a new API for SkCodec, which supports progressive decoding and scanline decoding. Future changes will switch the other clients off of startScanlineDecode and get/skip-Scanlines to the new API. Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced PNG images. In the new API, interlaced PNG fits kTopDown. Also remove updateCurrScanline(), which was only used by the old implementation for interlaced PNG. DMSrcSink: - In CodecSrc::kScanline_Mode, use the new method for scanline decoding for the supported formats (just PNG and PNG-in-ICO for now). fuzz.cpp: - Remove reference to kNone_ScanlineOrder SkCodec: - Add new APIs: - startIncrementalDecode - incrementalDecode - Remove kNone_SkScanlineOrder and updateCurrScanline() - Set fDstInfo and fOptions in getPixels(). This may not be necessary for all implementations, but it simplifies things for SkPngCodec. SkPngCodec: - Implement new APIs - Switch from sk_read_fn/png_read_row etc to png_process_data - Expand AutoCleanPng's role to decode the header and create the SkPngCodec - Make the interlaced PNG decoder report how many lines were initialized during an incomplete decode SkIcoCodec: - Implement the new APIs; supported for PNG in ICO SkSampledCodec: - Call the new method for decoding scanlines, and fall back to the old method if the new version is unimplemented - Remove references to kNone_SkScanlineOrder tests/CodecPartial: - Add a test which decodes part of an image, then finishes the decode, and compares it to the straightforward method tests/CodecTest: - Add a test which decodes all scanlines using the new method - Repurpose the Codec_stripes test to decode using the new method in sections rather than all at once - In the method check(), add a parameter for whether the image supports the new method of scanline decoding, and be explicit about whether an image supports incomplete - Test incomplete PNG decodes. We should have been doing it anyway for non-interlaced (except for an image that is too small - one row), but the new method supports interlaced incomplete as well - Make test_invalid_parameters test the new method - Add a test to ensure that it's safe to fall back to scanline decoding without rewinding BUG=skia:4211 The new version was generally faster than the old version (but not significantly so). Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/ Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/ GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003 Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
codec->fillIncompleteImage(decodeInfo, dst, rowBytes,
SkCodec::kNo_ZeroInitialized, height,
rowsDecoded);
}
} else {
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
if (useIncremental) {
// Error: These should support incremental decode.
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
return Result::Fatal("Could not start incremental decode");
Make SkPngCodec decode progressively. This is a step towards using SkCodec in Chromium, where progressive decoding is necessary. Switch from using png_read_row (which expects all the data to be available) to png_process_data, which uses callbacks when rows are available. Create a new API for SkCodec, which supports progressive decoding and scanline decoding. Future changes will switch the other clients off of startScanlineDecode and get/skip-Scanlines to the new API. Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced PNG images. In the new API, interlaced PNG fits kTopDown. Also remove updateCurrScanline(), which was only used by the old implementation for interlaced PNG. DMSrcSink: - In CodecSrc::kScanline_Mode, use the new method for scanline decoding for the supported formats (just PNG and PNG-in-ICO for now). fuzz.cpp: - Remove reference to kNone_ScanlineOrder SkCodec: - Add new APIs: - startIncrementalDecode - incrementalDecode - Remove kNone_SkScanlineOrder and updateCurrScanline() - Set fDstInfo and fOptions in getPixels(). This may not be necessary for all implementations, but it simplifies things for SkPngCodec. SkPngCodec: - Implement new APIs - Switch from sk_read_fn/png_read_row etc to png_process_data - Expand AutoCleanPng's role to decode the header and create the SkPngCodec - Make the interlaced PNG decoder report how many lines were initialized during an incomplete decode SkIcoCodec: - Implement the new APIs; supported for PNG in ICO SkSampledCodec: - Call the new method for decoding scanlines, and fall back to the old method if the new version is unimplemented - Remove references to kNone_SkScanlineOrder tests/CodecPartial: - Add a test which decodes part of an image, then finishes the decode, and compares it to the straightforward method tests/CodecTest: - Add a test which decodes all scanlines using the new method - Repurpose the Codec_stripes test to decode using the new method in sections rather than all at once - In the method check(), add a parameter for whether the image supports the new method of scanline decoding, and be explicit about whether an image supports incomplete - Test incomplete PNG decodes. We should have been doing it anyway for non-interlaced (except for an image that is too small - one row), but the new method supports interlaced incomplete as well - Make test_invalid_parameters test the new method - Add a test to ensure that it's safe to fall back to scanline decoding without rewinding BUG=skia:4211 The new version was generally faster than the old version (but not significantly so). Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/ Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/ GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003 Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
}
// Otherwise, this is an ICO. Since incremental failed, it must contain a BMP,
// which should work via startScanlineDecode
useOldScanlineMethod = true;
}
}
if (useOldScanlineMethod) {
if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo)) {
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
return Result::Fatal("Could not start scanline decoder");
Make SkPngCodec decode progressively. This is a step towards using SkCodec in Chromium, where progressive decoding is necessary. Switch from using png_read_row (which expects all the data to be available) to png_process_data, which uses callbacks when rows are available. Create a new API for SkCodec, which supports progressive decoding and scanline decoding. Future changes will switch the other clients off of startScanlineDecode and get/skip-Scanlines to the new API. Remove SkCodec::kNone_ScanlineOrder, which was only used for interlaced PNG images. In the new API, interlaced PNG fits kTopDown. Also remove updateCurrScanline(), which was only used by the old implementation for interlaced PNG. DMSrcSink: - In CodecSrc::kScanline_Mode, use the new method for scanline decoding for the supported formats (just PNG and PNG-in-ICO for now). fuzz.cpp: - Remove reference to kNone_ScanlineOrder SkCodec: - Add new APIs: - startIncrementalDecode - incrementalDecode - Remove kNone_SkScanlineOrder and updateCurrScanline() - Set fDstInfo and fOptions in getPixels(). This may not be necessary for all implementations, but it simplifies things for SkPngCodec. SkPngCodec: - Implement new APIs - Switch from sk_read_fn/png_read_row etc to png_process_data - Expand AutoCleanPng's role to decode the header and create the SkPngCodec - Make the interlaced PNG decoder report how many lines were initialized during an incomplete decode SkIcoCodec: - Implement the new APIs; supported for PNG in ICO SkSampledCodec: - Call the new method for decoding scanlines, and fall back to the old method if the new version is unimplemented - Remove references to kNone_SkScanlineOrder tests/CodecPartial: - Add a test which decodes part of an image, then finishes the decode, and compares it to the straightforward method tests/CodecTest: - Add a test which decodes all scanlines using the new method - Repurpose the Codec_stripes test to decode using the new method in sections rather than all at once - In the method check(), add a parameter for whether the image supports the new method of scanline decoding, and be explicit about whether an image supports incomplete - Test incomplete PNG decodes. We should have been doing it anyway for non-interlaced (except for an image that is too small - one row), but the new method supports interlaced incomplete as well - Make test_invalid_parameters test the new method - Add a test to ensure that it's safe to fall back to scanline decoding without rewinding BUG=skia:4211 The new version was generally faster than the old version (but not significantly so). Some raw performance differences can be found at https://docs.google.com/a/google.com/spreadsheets/d/1Gis3aRCEa72qBNDRMgGDg3jD-pMgO-FXldlNF9ejo4o/ Design doc can be found at https://docs.google.com/a/google.com/document/d/11Mn8-ePDKwVEMCjs3nWwSjxcSpJ_Cu8DF57KNtUmgLM/ GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1997703003 Review-Url: https://codereview.chromium.org/1997703003
2016-09-16 15:20:38 +00:00
}
// We do not need to check the return value. On an incomplete
// image, memory will be filled with a default value.
codec->getScanlines(dst, height, rowBytes);
}
draw_to_canvas(canvas, bitmapInfo, dst, rowBytes, fDstColorType);
break;
}
case kStripe_Mode: {
const int height = decodeInfo.height();
// This value is chosen arbitrarily. We exercise more cases by choosing a value that
// does not align with image blocks.
const int stripeHeight = 37;
const int numStripes = (height + stripeHeight - 1) / stripeHeight;
void* dst = pixels.get();
// Decode odd stripes
if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo, &options)) {
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
return Result::Fatal("Could not start scanline decoder");
}
// This mode was designed to test the new skip scanlines API in libjpeg-turbo.
// Jpegs have kTopDown_SkScanlineOrder, and at this time, it is not interesting
// to run this test for image types that do not have this scanline ordering.
// We only run this on Jpeg, which is always kTopDown.
SkASSERT(SkCodec::kTopDown_SkScanlineOrder == codec->getScanlineOrder());
for (int i = 0; i < numStripes; i += 2) {
// Skip a stripe
const int linesToSkip = std::min(stripeHeight, height - i * stripeHeight);
codec->skipScanlines(linesToSkip);
// Read a stripe
const int startY = (i + 1) * stripeHeight;
const int linesToRead = std::min(stripeHeight, height - startY);
if (linesToRead > 0) {
codec->getScanlines(SkTAddOffset<void>(dst, rowBytes * startY), linesToRead,
rowBytes);
}
}
// Decode even stripes
const SkCodec::Result startResult = codec->startScanlineDecode(decodeInfo);
if (SkCodec::kSuccess != startResult) {
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
return Result::Fatal("Failed to restart scanline decoder with same parameters.");
}
for (int i = 0; i < numStripes; i += 2) {
// Read a stripe
const int startY = i * stripeHeight;
const int linesToRead = std::min(stripeHeight, height - startY);
codec->getScanlines(SkTAddOffset<void>(dst, rowBytes * startY), linesToRead,
rowBytes);
// Skip a stripe
const int linesToSkip = std::min(stripeHeight, height - (i + 1) * stripeHeight);
if (linesToSkip > 0) {
codec->skipScanlines(linesToSkip);
}
}
draw_to_canvas(canvas, bitmapInfo, dst, rowBytes, fDstColorType);
break;
}
case kCroppedScanline_Mode: {
const int width = decodeInfo.width();
const int height = decodeInfo.height();
// This value is chosen because, as we move across the image, it will sometimes
// align with the jpeg block sizes and it will sometimes not. This allows us
// to test interestingly different code paths in the implementation.
const int tileSize = 36;
SkIRect subset;
for (int x = 0; x < width; x += tileSize) {
subset = SkIRect::MakeXYWH(x, 0, std::min(tileSize, width - x), height);
options.fSubset = &subset;
if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo, &options)) {
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
return Result::Fatal("Could not start scanline decoder.");
}
codec->getScanlines(SkTAddOffset<void>(pixels.get(), x * bpp), height, rowBytes);
}
draw_to_canvas(canvas, bitmapInfo, pixels.get(), rowBytes, fDstColorType);
break;
}
case kSubset_Mode: {
// Arbitrarily choose a divisor.
int divisor = 2;
// Total width/height of the image.
const int W = codec->getInfo().width();
const int H = codec->getInfo().height();
if (divisor > W || divisor > H) {
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
return Result::Skip("Cannot codec subset: divisor %d is too big "
"for %s with dimensions (%d x %d)", divisor,
fPath.c_str(), W, H);
}
// subset dimensions
// SkWebpCodec, the only one that supports subsets, requires even top/left boundaries.
const int w = SkAlign2(W / divisor);
const int h = SkAlign2(H / divisor);
SkIRect subset;
options.fSubset = &subset;
SkBitmap subsetBm;
// We will reuse pixel memory from bitmap.
void* dst = pixels.get();
// Keep track of left and top (for drawing subsetBm into canvas). We could use
// fScale * x and fScale * y, but we want integers such that the next subset will start
// where the last one ended. So we'll add decodeInfo.width() and height().
int left = 0;
for (int x = 0; x < W; x += w) {
int top = 0;
for (int y = 0; y < H; y+= h) {
// Do not make the subset go off the edge of the image.
const int preScaleW = std::min(w, W - x);
const int preScaleH = std::min(h, H - y);
subset.setXYWH(x, y, preScaleW, preScaleH);
// And scale
// FIXME: Should we have a version of getScaledDimensions that takes a subset
// into account?
const int scaledW = std::max(1, SkScalarRoundToInt(preScaleW * fScale));
const int scaledH = std::max(1, SkScalarRoundToInt(preScaleH * fScale));
decodeInfo = decodeInfo.makeWH(scaledW, scaledH);
SkImageInfo subsetBitmapInfo = bitmapInfo.makeWH(scaledW, scaledH);
size_t subsetRowBytes = subsetBitmapInfo.minRowBytes();
const SkCodec::Result result = codec->getPixels(decodeInfo, dst, subsetRowBytes,
&options);
switch (result) {
case SkCodec::kSuccess:
case SkCodec::kErrorInInput:
case SkCodec::kIncompleteInput:
break;
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
return Result::Fatal("subset codec failed to decode (%d, %d, %d, %d) "
"from %s with dimensions (%d x %d)\t error %d",
x, y, decodeInfo.width(), decodeInfo.height(),
fPath.c_str(), W, H, result);
}
draw_to_canvas(canvas, subsetBitmapInfo, dst, subsetRowBytes, fDstColorType,
SkIntToScalar(left), SkIntToScalar(top));
// translate by the scaled height.
top += decodeInfo.height();
}
// translate by the scaled width.
left += decodeInfo.width();
}
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
return Result::Ok();
}
default:
SkASSERT(false);
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
return Result::Fatal("Invalid fMode");
}
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
return Result::Ok();
}
SkISize CodecSrc::size() const {
sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(encoded));
if (nullptr == codec) {
return {0, 0};
}
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
Reland "SkAndroidCodec: Support decoding all frames" This is a reland of fc4fdc5b25f448dd9c2cd4e445561a840ce8514b Original change's description: > SkAndroidCodec: Support decoding all frames > > Bug: b/160984428 > Bug: b/163595585 > > Add support to SkAndroidCodec for decoding all frames with an > fSampleSize, so that an entire animation can be decoded to a smaller > size. > > dm/: > - Test scaled + animated decodes > > SkAndroidCodec: > - Make AndroidOptions inherit from SkCodec::Options. This allows > SkAndroidCodec to use fFrameIndex. (It also combines the two versions > of fSubset, which is now const for both.) > - Respect fFrameIndex, and call SkCodec::handleFrameIndex to decode > the required frame. > - Disallow decoding with kRespect + fFrameIndex > 0 if there is a > non-default orientation. As currently written (except without > disabling this combination), SkPixmapPriv::Orient would draw the new > portion of the frame on top of uninitialized pixels, instead of the > prior frame. This could be fixed by > - If SkAndroidCodec needs to decode the required frame, it could do so > without applying the orientation, then decode fFrameIndex, and then > apply the orientation. > - If the client provided the required frame, SkAndroidCodec would need > to un-apply the orientation to get the proper starting state, then > decode and apply. > I think it is simpler to force the client to handle the orientation > externally. > > SkCodec: > - Allow SkAndroidCodec to call its private method handleFrameIndex. This > method handles decoding a required frame, if necessary. When called by > SkAndroidCodec, it now uses the SkAndroidCodec to check for/decode the > required frame, so that it will scale properly. > - Call rewindIfNeeded inside handleFrameIndex. handleFrameIndex calls a > virtual method which may set some state (e.g. in SkJpegCodec). Without > this change, that state would be reset by rewindIfNeeded. > - Simplify handling a kRestoreBGColor frame. Whether provided or not, > take the same path to calling zero_rect. > - Updates to zero_rect: > - Intersect after scaling, which will also check for empty. > - Round out instead of in - this ensures we don't under-erase > - Use kFill_ScaleToFit, which better matches the intent. > > Change-Id: Ibe1951980a0dca8f5b7b1f20192432d395681683 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/333225 > Commit-Queue: Leon Scroggins <scroggo@google.com> > Reviewed-by: Derek Sollenberger <djsollen@google.com> Bug: b/160984428 Bug: b/163595585 Change-Id: I7c1e79e0f92c75b4840eef65c8fc2b8497189e81 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/334842 Auto-Submit: Leon Scroggins <scroggo@google.com> Commit-Queue: Derek Sollenberger <djsollen@google.com> Reviewed-by: Derek Sollenberger <djsollen@google.com>
2020-11-09 19:18:12 +00:00
if (fMode != kAnimated_Mode) {
return codec->getScaledDimensions(fScale);
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
}
Reland "SkAndroidCodec: Support decoding all frames" This is a reland of fc4fdc5b25f448dd9c2cd4e445561a840ce8514b Original change's description: > SkAndroidCodec: Support decoding all frames > > Bug: b/160984428 > Bug: b/163595585 > > Add support to SkAndroidCodec for decoding all frames with an > fSampleSize, so that an entire animation can be decoded to a smaller > size. > > dm/: > - Test scaled + animated decodes > > SkAndroidCodec: > - Make AndroidOptions inherit from SkCodec::Options. This allows > SkAndroidCodec to use fFrameIndex. (It also combines the two versions > of fSubset, which is now const for both.) > - Respect fFrameIndex, and call SkCodec::handleFrameIndex to decode > the required frame. > - Disallow decoding with kRespect + fFrameIndex > 0 if there is a > non-default orientation. As currently written (except without > disabling this combination), SkPixmapPriv::Orient would draw the new > portion of the frame on top of uninitialized pixels, instead of the > prior frame. This could be fixed by > - If SkAndroidCodec needs to decode the required frame, it could do so > without applying the orientation, then decode fFrameIndex, and then > apply the orientation. > - If the client provided the required frame, SkAndroidCodec would need > to un-apply the orientation to get the proper starting state, then > decode and apply. > I think it is simpler to force the client to handle the orientation > externally. > > SkCodec: > - Allow SkAndroidCodec to call its private method handleFrameIndex. This > method handles decoding a required frame, if necessary. When called by > SkAndroidCodec, it now uses the SkAndroidCodec to check for/decode the > required frame, so that it will scale properly. > - Call rewindIfNeeded inside handleFrameIndex. handleFrameIndex calls a > virtual method which may set some state (e.g. in SkJpegCodec). Without > this change, that state would be reset by rewindIfNeeded. > - Simplify handling a kRestoreBGColor frame. Whether provided or not, > take the same path to calling zero_rect. > - Updates to zero_rect: > - Intersect after scaling, which will also check for empty. > - Round out instead of in - this ensures we don't under-erase > - Use kFill_ScaleToFit, which better matches the intent. > > Change-Id: Ibe1951980a0dca8f5b7b1f20192432d395681683 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/333225 > Commit-Queue: Leon Scroggins <scroggo@google.com> > Reviewed-by: Derek Sollenberger <djsollen@google.com> Bug: b/160984428 Bug: b/163595585 Change-Id: I7c1e79e0f92c75b4840eef65c8fc2b8497189e81 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/334842 Auto-Submit: Leon Scroggins <scroggo@google.com> Commit-Queue: Derek Sollenberger <djsollen@google.com> Reviewed-by: Derek Sollenberger <djsollen@google.com>
2020-11-09 19:18:12 +00:00
// We'll draw one of each frame, so make it big enough to hold them all
// in a grid. The grid will be roughly square, with "factor" frames per
// row and up to "factor" rows.
const size_t count = codec->getFrameInfo().size();
const float root = sqrt((float) count);
const int factor = sk_float_ceil2int(root);
auto androidCodec = SkAndroidCodec::MakeFromCodec(std::move(codec));
auto imageSize = androidCodec->getSampledDimensions(1 / fScale);
imageSize.fWidth = imageSize.fWidth * factor;
imageSize.fHeight = imageSize.fHeight * sk_float_ceil2int((float) count / (float) factor);
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
return imageSize;
}
Name CodecSrc::name() const {
Reland "SkAndroidCodec: Support decoding all frames" This is a reland of fc4fdc5b25f448dd9c2cd4e445561a840ce8514b Original change's description: > SkAndroidCodec: Support decoding all frames > > Bug: b/160984428 > Bug: b/163595585 > > Add support to SkAndroidCodec for decoding all frames with an > fSampleSize, so that an entire animation can be decoded to a smaller > size. > > dm/: > - Test scaled + animated decodes > > SkAndroidCodec: > - Make AndroidOptions inherit from SkCodec::Options. This allows > SkAndroidCodec to use fFrameIndex. (It also combines the two versions > of fSubset, which is now const for both.) > - Respect fFrameIndex, and call SkCodec::handleFrameIndex to decode > the required frame. > - Disallow decoding with kRespect + fFrameIndex > 0 if there is a > non-default orientation. As currently written (except without > disabling this combination), SkPixmapPriv::Orient would draw the new > portion of the frame on top of uninitialized pixels, instead of the > prior frame. This could be fixed by > - If SkAndroidCodec needs to decode the required frame, it could do so > without applying the orientation, then decode fFrameIndex, and then > apply the orientation. > - If the client provided the required frame, SkAndroidCodec would need > to un-apply the orientation to get the proper starting state, then > decode and apply. > I think it is simpler to force the client to handle the orientation > externally. > > SkCodec: > - Allow SkAndroidCodec to call its private method handleFrameIndex. This > method handles decoding a required frame, if necessary. When called by > SkAndroidCodec, it now uses the SkAndroidCodec to check for/decode the > required frame, so that it will scale properly. > - Call rewindIfNeeded inside handleFrameIndex. handleFrameIndex calls a > virtual method which may set some state (e.g. in SkJpegCodec). Without > this change, that state would be reset by rewindIfNeeded. > - Simplify handling a kRestoreBGColor frame. Whether provided or not, > take the same path to calling zero_rect. > - Updates to zero_rect: > - Intersect after scaling, which will also check for empty. > - Round out instead of in - this ensures we don't under-erase > - Use kFill_ScaleToFit, which better matches the intent. > > Change-Id: Ibe1951980a0dca8f5b7b1f20192432d395681683 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/333225 > Commit-Queue: Leon Scroggins <scroggo@google.com> > Reviewed-by: Derek Sollenberger <djsollen@google.com> Bug: b/160984428 Bug: b/163595585 Change-Id: I7c1e79e0f92c75b4840eef65c8fc2b8497189e81 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/334842 Auto-Submit: Leon Scroggins <scroggo@google.com> Commit-Queue: Derek Sollenberger <djsollen@google.com> Reviewed-by: Derek Sollenberger <djsollen@google.com>
2020-11-09 19:18:12 +00:00
Name name = SkOSPath::Basename(fPath.c_str());
if (fMode == kAnimated_Mode) {
name.append("_animated");
}
if (1.0f == fScale) {
return name;
}
Reland "SkAndroidCodec: Support decoding all frames" This is a reland of fc4fdc5b25f448dd9c2cd4e445561a840ce8514b Original change's description: > SkAndroidCodec: Support decoding all frames > > Bug: b/160984428 > Bug: b/163595585 > > Add support to SkAndroidCodec for decoding all frames with an > fSampleSize, so that an entire animation can be decoded to a smaller > size. > > dm/: > - Test scaled + animated decodes > > SkAndroidCodec: > - Make AndroidOptions inherit from SkCodec::Options. This allows > SkAndroidCodec to use fFrameIndex. (It also combines the two versions > of fSubset, which is now const for both.) > - Respect fFrameIndex, and call SkCodec::handleFrameIndex to decode > the required frame. > - Disallow decoding with kRespect + fFrameIndex > 0 if there is a > non-default orientation. As currently written (except without > disabling this combination), SkPixmapPriv::Orient would draw the new > portion of the frame on top of uninitialized pixels, instead of the > prior frame. This could be fixed by > - If SkAndroidCodec needs to decode the required frame, it could do so > without applying the orientation, then decode fFrameIndex, and then > apply the orientation. > - If the client provided the required frame, SkAndroidCodec would need > to un-apply the orientation to get the proper starting state, then > decode and apply. > I think it is simpler to force the client to handle the orientation > externally. > > SkCodec: > - Allow SkAndroidCodec to call its private method handleFrameIndex. This > method handles decoding a required frame, if necessary. When called by > SkAndroidCodec, it now uses the SkAndroidCodec to check for/decode the > required frame, so that it will scale properly. > - Call rewindIfNeeded inside handleFrameIndex. handleFrameIndex calls a > virtual method which may set some state (e.g. in SkJpegCodec). Without > this change, that state would be reset by rewindIfNeeded. > - Simplify handling a kRestoreBGColor frame. Whether provided or not, > take the same path to calling zero_rect. > - Updates to zero_rect: > - Intersect after scaling, which will also check for empty. > - Round out instead of in - this ensures we don't under-erase > - Use kFill_ScaleToFit, which better matches the intent. > > Change-Id: Ibe1951980a0dca8f5b7b1f20192432d395681683 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/333225 > Commit-Queue: Leon Scroggins <scroggo@google.com> > Reviewed-by: Derek Sollenberger <djsollen@google.com> Bug: b/160984428 Bug: b/163595585 Change-Id: I7c1e79e0f92c75b4840eef65c8fc2b8497189e81 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/334842 Auto-Submit: Leon Scroggins <scroggo@google.com> Commit-Queue: Derek Sollenberger <djsollen@google.com> Reviewed-by: Derek Sollenberger <djsollen@google.com>
2020-11-09 19:18:12 +00:00
return get_scaled_name(name.c_str(), fScale);
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
AndroidCodecSrc::AndroidCodecSrc(Path path, CodecSrc::DstColorType dstColorType,
SkAlphaType dstAlphaType, int sampleSize)
: fPath(path)
, fDstColorType(dstColorType)
, fDstAlphaType(dstAlphaType)
, fSampleSize(sampleSize)
, fRunSerially(serial_from_path_name(path))
{}
bool AndroidCodecSrc::veto(SinkFlags flags) const {
// No need to test decoding to non-raster or indirect backend.
return flags.type != SinkFlags::kRaster
|| flags.approach != SinkFlags::kDirect;
}
Result AndroidCodecSrc::draw(GrDirectContext*, SkCanvas* canvas) const {
sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
if (!encoded) {
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
return Result::Fatal("Couldn't read %s.", fPath.c_str());
}
std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromData(encoded));
if (nullptr == codec) {
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
return Result::Fatal("Couldn't create android codec for %s.", fPath.c_str());
}
SkImageInfo decodeInfo = codec->getInfo();
if (!get_decode_info(&decodeInfo, canvas->imageInfo().colorType(), fDstColorType,
fDstAlphaType)) {
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
return Result::Skip("Skipping uninteresting test.");
}
// Scale the image if it is desired.
SkISize size = codec->getSampledDimensions(fSampleSize);
// Visually inspecting very small output images is not necessary. We will
// cover these cases in unit testing.
if ((size.width() <= 10 || size.height() <= 10) && 1 != fSampleSize) {
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
return Result::Skip("Scaling very small images is uninteresting.");
}
Reland "Reland "SkSurface asynchronous read APIs allow client to extend pixel lifetime"" This is a reland of 6fc04f88a89ed2c9a1b4aa48bcd28602a69a457b Original change's description: > Reland "SkSurface asynchronous read APIs allow client to extend pixel lifetime" > > This is a reland of ce240cc6fd8ec95bd051c7df2173dad2ae8f6ad6 > > Original change's description: > > SkSurface asynchronous read APIs allow client to extend pixel lifetime > > > > Previously the pixel data passed to the client was only valid during > > the client's callback. This meant if the client wanted to defer > > processing of the data a copy was necessary. > > > > Now we pass an object to the callback and the pixel lifetime is tied > > to the lifetime of that object. > > > > The object may be holding a GPU transfer buffer mapped. We don't assume > > that the object will be released on the direct GrContext thread. So > > when the object is destroyed it posts a message to a new type, > > GrClientMappedBufferManager, hanging off the direct context. The direct > > context will periodically check for messages and unmap and then unref > > buffers so that they can be reused. Currently this is done in > > GrContext::performDeferredCleanup() and GrDrawingManager::flush(). > > > > The old API is kept around for backwards compatibility but it is > > reimplemented as a bridge on top of the new mechanism. > > > > Also a utility function to SkImageInfo is added to directly make a new > > info with a specified dimensions rather than passing the width and > > height separately to makeWH(). > > > > Bug: chromium:973403 > > Bug: skia:8962 > > > > Change-Id: Id5cf04235376170142a48e90d3ecd13fd021a2a6 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/245457 > > Reviewed-by: Brian Osman <brianosman@google.com> > > Commit-Queue: Brian Salomon <bsalomon@google.com> > > Bug: chromium:973403, skia:8962 > Change-Id: I5cecd36276c8b6dc942cf549c7095db2df88530c > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/245678 > Reviewed-by: Brian Salomon <bsalomon@google.com> > Commit-Queue: Brian Salomon <bsalomon@google.com> Bug: chromium:973403, skia:8962 Change-Id: Ie584c1c3ef8021c976f71b708e53871c693cc450 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/246057 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
2019-10-03 17:26:54 +00:00
decodeInfo = decodeInfo.makeDimensions(size);
int bpp = decodeInfo.bytesPerPixel();
size_t rowBytes = size.width() * bpp;
SkAutoMalloc pixels(size.height() * rowBytes);
SkBitmap bitmap;
SkImageInfo bitmapInfo = decodeInfo;
set_bitmap_color_space(&bitmapInfo);
if (kRGBA_8888_SkColorType == decodeInfo.colorType() ||
kBGRA_8888_SkColorType == decodeInfo.colorType()) {
bitmapInfo = bitmapInfo.makeColorType(kN32_SkColorType);
}
// Create options for the codec.
SkAndroidCodec::AndroidOptions options;
options.fSampleSize = fSampleSize;
switch (codec->getAndroidPixels(decodeInfo, pixels.get(), rowBytes, &options)) {
case SkCodec::kSuccess:
case SkCodec::kErrorInInput:
case SkCodec::kIncompleteInput:
break;
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
return Result::Fatal("Couldn't getPixels %s.", fPath.c_str());
}
draw_to_canvas(canvas, bitmapInfo, pixels.get(), rowBytes, fDstColorType);
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
return Result::Ok();
}
SkISize AndroidCodecSrc::size() const {
sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromData(encoded));
if (nullptr == codec) {
return {0, 0};
}
return codec->getSampledDimensions(fSampleSize);
}
Name AndroidCodecSrc::name() const {
// We will replicate the names used by CodecSrc so that images can
// be compared in Gold.
if (1 == fSampleSize) {
return SkOSPath::Basename(fPath.c_str());
}
return get_scaled_name(fPath, 1.0f / (float) fSampleSize);
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
ImageGenSrc::ImageGenSrc(Path path, Mode mode, SkAlphaType alphaType, bool isGpu)
: fPath(path)
, fMode(mode)
, fDstAlphaType(alphaType)
, fIsGpu(isGpu)
, fRunSerially(serial_from_path_name(path))
{}
bool ImageGenSrc::veto(SinkFlags flags) const {
if (fIsGpu) {
// MSAA runs tend to run out of memory and tests the same code paths as regular gpu configs.
return flags.type != SinkFlags::kGPU || flags.approach != SinkFlags::kDirect ||
flags.multisampled == SinkFlags::kMultisampled;
}
return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDirect;
}
Result ImageGenSrc::draw(GrDirectContext*, SkCanvas* canvas) const {
if (kRGB_565_SkColorType == canvas->imageInfo().colorType()) {
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
return Result::Skip("Uninteresting to test image generator to 565.");
}
sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
if (!encoded) {
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
return Result::Fatal("Couldn't read %s.", fPath.c_str());
}
#if defined(SK_BUILD_FOR_WIN)
// Initialize COM in order to test with WIC.
SkAutoCoInitialize com;
if (!com.succeeded()) {
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
return Result::Fatal("Could not initialize COM.");
}
#endif
std::unique_ptr<SkImageGenerator> gen(nullptr);
switch (fMode) {
case kCodec_Mode:
gen = SkCodecImageGenerator::MakeFromEncodedCodec(encoded);
if (!gen) {
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
return Result::Fatal("Could not create codec image generator.");
}
break;
case kPlatform_Mode: {
#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
gen = SkImageGeneratorCG::MakeFromEncodedCG(encoded);
#elif defined(SK_BUILD_FOR_WIN)
gen = SkImageGeneratorWIC::MakeFromEncodedWIC(encoded);
#elif defined(SK_ENABLE_NDK_IMAGES)
gen = SkImageGeneratorNDK::MakeFromEncodedNDK(encoded);
#endif
if (!gen) {
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
return Result::Fatal("Could not create platform image generator.");
}
break;
}
default:
SkASSERT(false);
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
return Result::Fatal("Invalid image generator mode");
}
// Test deferred decoding path on GPU
if (fIsGpu) {
sk_sp<SkImage> image(SkImage::MakeFromGenerator(std::move(gen)));
if (!image) {
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
return Result::Fatal("Could not create image from codec image generator.");
}
canvas->drawImage(image, 0, 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
return Result::Ok();
}
// Test various color and alpha types on CPU
SkImageInfo decodeInfo = gen->getInfo().makeAlphaType(fDstAlphaType);
int bpp = decodeInfo.bytesPerPixel();
size_t rowBytes = decodeInfo.width() * bpp;
SkAutoMalloc pixels(decodeInfo.height() * rowBytes);
if (!gen->getPixels(decodeInfo, pixels.get(), rowBytes)) {
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::Status status = Result::Status::Fatal;
#if defined(SK_BUILD_FOR_WIN)
if (kPlatform_Mode == fMode) {
// Do not issue a fatal error for WIC flakiness.
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 = Result::Status::Skip;
}
#endif
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
return Result(status, "Image generator could not getPixels() for %s\n", fPath.c_str());
}
set_bitmap_color_space(&decodeInfo);
draw_to_canvas(canvas, decodeInfo, pixels.get(), rowBytes,
CodecSrc::kGetFromCanvas_DstColorType);
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
return Result::Ok();
}
SkISize ImageGenSrc::size() const {
sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(encoded));
if (nullptr == codec) {
return {0, 0};
}
return codec->getInfo().dimensions();
}
Name ImageGenSrc::name() const {
return SkOSPath::Basename(fPath.c_str());
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
ColorCodecSrc::ColorCodecSrc(Path path, bool decode_to_dst) : fPath(path)
, fDecodeToDst(decode_to_dst) {}
bool ColorCodecSrc::veto(SinkFlags flags) const {
// Test to direct raster backends (8888 and 565).
return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDirect;
}
Result ColorCodecSrc::draw(GrDirectContext*, SkCanvas* canvas) const {
sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
if (!encoded) {
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
return Result::Fatal("Couldn't read %s.", fPath.c_str());
}
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(encoded));
if (nullptr == codec) {
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
return Result::Fatal("Couldn't create codec for %s.", fPath.c_str());
}
SkImageInfo info = codec->getInfo();
if (fDecodeToDst) {
SkImageInfo canvasInfo = canvas->imageInfo();
if (!canvasInfo.colorSpace()) {
// This will skip color conversion, and the resulting images will
// look different from images they are compared against in Gold, but
// that doesn't mean they are wrong. We have a test verifying that
// passing a null SkColorSpace skips conversion, so skip this
// misleading test.
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
return Result::Skip("Skipping decoding without color transform.");
}
info = canvasInfo.makeDimensions(info.dimensions());
}
SkBitmap bitmap;
if (!bitmap.tryAllocPixels(info)) {
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
return Result::Fatal("Image(%s) is too large (%d x %d)",
fPath.c_str(), info.width(), info.height());
}
switch (auto r = codec->getPixels(info, bitmap.getPixels(), bitmap.rowBytes())) {
case SkCodec::kSuccess:
case SkCodec::kErrorInInput:
case SkCodec::kIncompleteInput:
canvas->drawBitmap(bitmap, 0,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
return Result::Ok();
case SkCodec::kInvalidConversion:
// TODO(mtklein): why are there formats we can't decode to?
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
return Result::Skip("SkCodec can't decode to this format.");
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
return Result::Fatal("Couldn't getPixels %s. Error code %d", fPath.c_str(), r);
}
}
SkISize ColorCodecSrc::size() const {
sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(encoded));
if (nullptr == codec) {
return {0, 0};
}
return {codec->getInfo().width(), codec->getInfo().height()};
}
Name ColorCodecSrc::name() const {
return SkOSPath::Basename(fPath.c_str());
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
static DEFINE_int(skpViewportSize, 1000,
"Width & height of the viewport used to crop skp rendering.");
SKPSrc::SKPSrc(Path path) : fPath(path) { }
Result SKPSrc::draw(GrDirectContext*, SkCanvas* canvas) const {
std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(fPath.c_str());
if (!stream) {
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
return Result::Fatal("Couldn't read %s.", fPath.c_str());
}
sk_sp<SkPicture> pic(SkPicture::MakeFromStream(stream.get()));
if (!pic) {
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
return Result::Fatal("Couldn't parse file %s.", fPath.c_str());
}
stream = nullptr; // Might as well drop this when we're done with it.
canvas->clipRect(SkRect::MakeWH(FLAGS_skpViewportSize, FLAGS_skpViewportSize));
canvas->drawPicture(pic);
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
return Result::Ok();
}
static SkRect get_cull_rect_for_skp(const char* path) {
std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(path);
if (!stream) {
return SkRect::MakeEmpty();
}
SkPictInfo info;
if (!SkPicture_StreamIsSKP(stream.get(), &info)) {
return SkRect::MakeEmpty();
}
return info.fCullRect;
}
SkISize SKPSrc::size() const {
SkRect viewport = get_cull_rect_for_skp(fPath.c_str());
if (!viewport.intersect((SkRect::MakeWH(FLAGS_skpViewportSize, FLAGS_skpViewportSize)))) {
return {0, 0};
}
return viewport.roundOut().size();
}
Name SKPSrc::name() const { return SkOSPath::Basename(fPath.c_str()); }
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
BisectSrc::BisectSrc(Path path, const char* trail) : INHERITED(path), fTrail(trail) {}
Result BisectSrc::draw(GrDirectContext* context, SkCanvas* canvas) const {
struct FoundPath {
SkPath fPath;
SkPaint fPaint;
SkMatrix fViewMatrix;
};
// This subclass of SkCanvas just extracts all the SkPaths (drawn via drawPath) from an SKP.
class PathFindingCanvas : public SkCanvas {
public:
PathFindingCanvas(int width, int height) : SkCanvas(width, height, nullptr) {}
const SkTArray<FoundPath>& foundPaths() const { return fFoundPaths; }
private:
void onDrawPath(const SkPath& path, const SkPaint& paint) override {
fFoundPaths.push_back() = {path, paint, this->getTotalMatrix()};
}
SkTArray<FoundPath> fFoundPaths;
};
PathFindingCanvas pathFinder(canvas->getBaseLayerSize().width(),
canvas->getBaseLayerSize().height());
Result result = this->INHERITED::draw(context, &pathFinder);
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
if (!result.isOk()) {
return result;
}
int start = 0, end = pathFinder.foundPaths().count();
for (const char* ch = fTrail.c_str(); *ch; ++ch) {
int midpt = (start + end) / 2;
if ('l' == *ch) {
start = midpt;
} else if ('r' == *ch) {
end = midpt;
}
}
for (int i = start; i < end; ++i) {
const FoundPath& path = pathFinder.foundPaths()[i];
SkAutoCanvasRestore acr(canvas, true);
canvas->concat(path.fViewMatrix);
canvas->drawPath(path.fPath, path.fPaint);
}
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
return Result::Ok();
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#if defined(SK_ENABLE_SKOTTIE)
static DEFINE_bool(useLottieGlyphPaths, false,
"Prioritize embedded glyph paths over native fonts.");
SkottieSrc::SkottieSrc(Path path) : fPath(std::move(path)) {}
Result SkottieSrc::draw(GrDirectContext*, SkCanvas* canvas) const {
auto resource_provider =
skresources::DataURIResourceProviderProxy::Make(
skresources::FileResourceProvider::Make(SkOSPath::Dirname(fPath.c_str()),
/*predecode=*/true),
/*predecode=*/true);
static constexpr char kInterceptPrefix[] = "__";
auto precomp_interceptor =
sk_make_sp<skottie_utils::ExternalAnimationPrecompInterceptor>(resource_provider,
kInterceptPrefix);
uint32_t flags = 0;
if (FLAGS_useLottieGlyphPaths) {
flags |= skottie::Animation::Builder::kPreferEmbeddedFonts;
}
auto animation = skottie::Animation::Builder(flags)
.setResourceProvider(std::move(resource_provider))
.setPrecompInterceptor(std::move(precomp_interceptor))
.makeFromFile(fPath.c_str());
if (!animation) {
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
return Result::Fatal("Unable to parse file: %s", fPath.c_str());
}
canvas->drawColor(SK_ColorWHITE);
const auto t_rate = 1.0f / (kTileCount * kTileCount - 1);
// Draw the frames in a shuffled order to exercise non-linear
// frame progression. The film strip will still be in order left-to-right,
// top-down, just not drawn in that order.
static constexpr int frameOrder[] = { 4, 0, 3, 1, 2 };
static_assert(SK_ARRAY_COUNT(frameOrder) == kTileCount, "");
for (int i = 0; i < kTileCount; ++i) {
const SkScalar y = frameOrder[i] * kTileSize;
for (int j = 0; j < kTileCount; ++j) {
const SkScalar x = frameOrder[j] * kTileSize;
SkRect dest = SkRect::MakeXYWH(x, y, kTileSize, kTileSize);
const auto t = t_rate * (frameOrder[i] * kTileCount + frameOrder[j]);
{
SkAutoCanvasRestore acr(canvas, true);
canvas->clipRect(dest, true);
canvas->concat(SkMatrix::MakeRectToRect(SkRect::MakeSize(animation->size()),
dest,
SkMatrix::kCenter_ScaleToFit));
animation->seek(t);
animation->render(canvas);
}
}
}
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
return Result::Ok();
}
SkISize SkottieSrc::size() const {
return SkISize::Make(kTargetSize, kTargetSize);
}
Name SkottieSrc::name() const { return SkOSPath::Basename(fPath.c_str()); }
bool SkottieSrc::veto(SinkFlags flags) const {
// No need to test to non-(raster||gpu||vector) or indirect backends.
bool type_ok = flags.type == SinkFlags::kRaster
|| flags.type == SinkFlags::kGPU
|| flags.type == SinkFlags::kVector;
return !type_ok || flags.approach != SinkFlags::kDirect;
}
#endif
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#if defined(SK_ENABLE_SKRIVE)
SkRiveSrc::SkRiveSrc(Path path) : fPath(std::move(path)) {}
Result SkRiveSrc::draw(GrDirectContext*, SkCanvas* canvas) const {
auto fileStream = SkFILEStream::Make(fPath.c_str());
if (!fileStream) {
return Result::Fatal("Unable to open file: %s", fPath.c_str());
}
const auto skrive = skrive::SkRive::Builder().make(std::move(fileStream));
if (!skrive) {
return Result::Fatal("Unable to parse file: %s", fPath.c_str());
}
auto bounds = SkRect::MakeEmpty();
for (const auto& ab : skrive->artboards()) {
const auto& pos = ab->getTranslation();
const auto& size = ab->getSize();
bounds.join(SkRect::MakeXYWH(pos.x, pos.y, size.x, size.y));
}
canvas->drawColor(SK_ColorWHITE);
if (!bounds.isEmpty()) {
// TODO: tiled frames when we add animation support
SkAutoCanvasRestore acr(canvas, true);
canvas->concat(SkMatrix::MakeRectToRect(bounds,
SkRect::MakeWH(kTargetSize, kTargetSize),
SkMatrix::kCenter_ScaleToFit ));
for (const auto& ab : skrive->artboards()) {
ab->render(canvas);
}
}
return Result::Ok();
}
SkISize SkRiveSrc::size() const {
return SkISize::Make(kTargetSize, kTargetSize);
}
Name SkRiveSrc::name() const { return SkOSPath::Basename(fPath.c_str()); }
bool SkRiveSrc::veto(SinkFlags flags) const {
// No need to test to non-(raster||gpu||vector) or indirect backends.
bool type_ok = flags.type == SinkFlags::kRaster
|| flags.type == SinkFlags::kGPU
|| flags.type == SinkFlags::kVector;
return !type_ok || flags.approach != SinkFlags::kDirect;
}
#endif
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#if defined(SK_XML)
// Used when the image doesn't have an intrinsic size.
static const SkSize kDefaultSVGSize = {1000, 1000};
// Used to force-scale tiny fixed-size images.
static const SkSize kMinimumSVGSize = {128, 128};
SVGSrc::SVGSrc(Path path)
: fName(SkOSPath::Basename(path.c_str()))
, fScale(1) {
sk_sp<SkData> data(SkData::MakeFromFileName(path.c_str()));
if (!data) {
return;
}
SkMemoryStream stream(std::move(data));
fDom = SkSVGDOM::MakeFromStream(stream);
if (!fDom) {
return;
}
const SkSize& sz = fDom->containerSize();
if (sz.isEmpty()) {
// no intrinsic size
fDom->setContainerSize(kDefaultSVGSize);
} else {
fScale = std::max(1.f, std::max(kMinimumSVGSize.width() / sz.width(),
kMinimumSVGSize.height() / sz.height()));
}
}
Result SVGSrc::draw(GrDirectContext*, SkCanvas* canvas) const {
if (!fDom) {
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
return Result::Fatal("Unable to parse file: %s", fName.c_str());
}
SkAutoCanvasRestore acr(canvas, true);
canvas->scale(fScale, fScale);
canvas->drawColor(SK_ColorWHITE);
fDom->render(canvas);
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
return Result::Ok();
}
SkISize SVGSrc::size() const {
if (!fDom) {
return {0, 0};
}
return SkSize{fDom->containerSize().width() * fScale, fDom->containerSize().height() * fScale}
.toRound();
}
Name SVGSrc::name() const { return fName; }
bool SVGSrc::veto(SinkFlags flags) const {
// No need to test to non-(raster||gpu||vector) or indirect backends.
bool type_ok = flags.type == SinkFlags::kRaster
|| flags.type == SinkFlags::kGPU
|| flags.type == SinkFlags::kVector;
return !type_ok || flags.approach != SinkFlags::kDirect;
}
#endif // defined(SK_XML)
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
MSKPSrc::MSKPSrc(Path path) : fPath(path) {
std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(fPath.c_str());
int count = SkMultiPictureDocumentReadPageCount(stream.get());
if (count > 0) {
fPages.reset(count);
(void)SkMultiPictureDocumentReadPageSizes(stream.get(), &fPages[0], fPages.count());
}
}
int MSKPSrc::pageCount() const { return fPages.count(); }
SkISize MSKPSrc::size() const { return this->size(0); }
SkISize MSKPSrc::size(int i) const {
return i >= 0 && i < fPages.count() ? fPages[i].fSize.toCeil() : SkISize{0, 0};
}
Result MSKPSrc::draw(GrDirectContext* context, SkCanvas* c) const {
return this->draw(0, context, c);
}
Result MSKPSrc::draw(int i, GrDirectContext*, SkCanvas* canvas) const {
if (this->pageCount() == 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
return Result::Fatal("Unable to parse MultiPictureDocument file: %s", fPath.c_str());
}
if (i >= fPages.count() || i < 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
return Result::Fatal("MultiPictureDocument page number out of range: %d", i);
}
SkPicture* page = fPages[i].fPicture.get();
if (!page) {
std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(fPath.c_str());
if (!stream) {
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
return Result::Fatal("Unable to open file: %s", fPath.c_str());
}
if (!SkMultiPictureDocumentRead(stream.get(), &fPages[0], fPages.count())) {
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
return Result::Fatal("SkMultiPictureDocument reader failed on page %d: %s", i,
fPath.c_str());
}
page = fPages[i].fPicture.get();
}
canvas->drawPicture(page);
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
return Result::Ok();
}
Name MSKPSrc::name() const { return SkOSPath::Basename(fPath.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
Result NullSink::draw(const Src& src, SkBitmap*, SkWStream*, SkString*) const {
return src.draw(nullptr, SkMakeNullCanvas().get());
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
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 compare_bitmaps(const SkBitmap& reference, const SkBitmap& bitmap) {
// The dimensions are a property of the Src only, and so should be identical.
SkASSERT(reference.computeByteSize() == bitmap.computeByteSize());
if (reference.computeByteSize() != bitmap.computeByteSize()) {
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
return Result::Fatal("Dimensions don't match reference");
}
// All SkBitmaps in DM are tight, so this comparison is easy.
if (0 != memcmp(reference.getPixels(), bitmap.getPixels(), reference.computeByteSize())) {
SkString encoded;
SkString errString("Pixels don't match reference");
if (BipmapToBase64DataURI(reference, &encoded)) {
errString.append("\nExpected: ");
errString.append(encoded);
} else {
errString.append("\nExpected image failed to encode: ");
errString.append(encoded);
}
if (BipmapToBase64DataURI(bitmap, &encoded)) {
errString.append("\nActual: ");
errString.append(encoded);
} else {
errString.append("\nActual image failed to encode: ");
errString.append(encoded);
}
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
return Result::Fatal(errString);
}
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
return Result::Ok();
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
static DEFINE_bool(gpuStats, false, "Append GPU stats to the log for each GPU task?");
static DEFINE_bool(preAbandonGpuContext, false,
"Test abandoning the GrContext before running the test.");
static DEFINE_bool(abandonGpuContext, false,
"Test abandoning the GrContext after running each test.");
static DEFINE_bool(releaseAndAbandonGpuContext, false,
"Test releasing all gpu resources and abandoning the GrContext "
"after running each test");
static DEFINE_bool(drawOpClip, false, "Clip each GrDrawOp to its device bounds for testing.");
static DEFINE_bool(programBinaryCache, true, "Use in-memory program binary cache");
GPUSink::GPUSink(const SkCommandLineConfigGpu* config,
const GrContextOptions& grCtxOptions)
: fContextType(config->getContextType())
, fContextOverrides(config->getContextOverrides())
, fSurfType(config->getSurfType())
, fSampleCount(config->getSamples())
, fUseDIText(config->getUseDIText())
, fColorType(config->getColorType())
, fAlphaType(config->getAlphaType())
, fColorSpace(sk_ref_sp(config->getColorSpace()))
, fBaseContextOptions(grCtxOptions) {
if (FLAGS_programBinaryCache) {
fBaseContextOptions.fPersistentCache = &fMemoryCache;
}
}
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 GPUSink::draw(const Src& src, SkBitmap* dst, SkWStream* dstStream, SkString* log) const {
return this->onDraw(src, dst, dstStream, log, fBaseContextOptions);
}
sk_sp<SkSurface> GPUSink::createDstSurface(GrDirectContext* context, SkISize size) const {
sk_sp<SkSurface> surface;
SkImageInfo info = SkImageInfo::Make(size, fColorType, fAlphaType, fColorSpace);
uint32_t flags = fUseDIText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : 0;
SkSurfaceProps props(flags, kRGB_H_SkPixelGeometry);
switch (fSurfType) {
case SkCommandLineConfigGpu::SurfType::kDefault:
surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, fSampleCount,
&props);
break;
case SkCommandLineConfigGpu::SurfType::kBackendTexture:
surface = sk_gpu_test::MakeBackendTextureSurface(context,
info,
kTopLeft_GrSurfaceOrigin,
fSampleCount,
GrMipmapped::kNo,
GrProtected::kNo,
&props);
break;
case SkCommandLineConfigGpu::SurfType::kBackendRenderTarget:
surface = sk_gpu_test::MakeBackendRenderTargetSurface(context,
info,
kBottomLeft_GrSurfaceOrigin,
fSampleCount,
GrProtected::kNo,
&props);
break;
}
return surface;
}
bool GPUSink::readBack(SkSurface* surface, SkBitmap* dst) const {
SkCanvas* canvas = surface->getCanvas();
SkISize size = surface->imageInfo().dimensions();
SkImageInfo info = SkImageInfo::Make(size, fColorType, fAlphaType, fColorSpace);
dst->allocPixels(info);
return canvas->readPixels(*dst, 0, 0);
}
Result GPUSink::onDraw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log,
const GrContextOptions& baseOptions,
std::function<void(GrDirectContext*)> initContext) const {
GrContextOptions grOptions = baseOptions;
// We don't expect the src to mess with the persistent cache or the executor.
SkDEBUGCODE(auto cache = grOptions.fPersistentCache);
SkDEBUGCODE(auto exec = grOptions.fExecutor);
src.modifyGrContextOptions(&grOptions);
SkASSERT(cache == grOptions.fPersistentCache);
SkASSERT(exec == grOptions.fExecutor);
GrContextFactory factory(grOptions);
auto direct = factory.getContextInfo(fContextType, fContextOverrides).directContext();
if (initContext) {
initContext(direct);
}
const int maxDimension = direct->priv().caps()->maxTextureSize();
if (maxDimension < std::max(src.size().width(), src.size().height())) {
return Result::Skip("Src too large to create a texture.\n");
}
sk_sp<SkSurface> surface = this->createDstSurface(direct, src.size());
if (!surface) {
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
return Result::Fatal("Could not create a surface.");
}
if (FLAGS_preAbandonGpuContext) {
factory.abandonContexts();
}
SkCanvas* canvas = surface->getCanvas();
Result result = src.draw(direct, canvas);
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
if (!result.isOk()) {
return result;
}
surface->flushAndSubmit();
if (FLAGS_gpuStats) {
direct->priv().dumpCacheStats(log);
direct->priv().dumpGpuStats(log);
direct->priv().dumpContextStats(log);
}
this->readBack(surface.get(), dst);
if (FLAGS_abandonGpuContext) {
factory.abandonContexts();
} else if (FLAGS_releaseAndAbandonGpuContext) {
factory.releaseResourcesAndAbandonContexts();
}
if (grOptions.fPersistentCache) {
direct->storeVkPipelineCacheData();
}
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
return Result::Ok();
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GPUThreadTestingSink::GPUThreadTestingSink(const SkCommandLineConfigGpu* config,
const GrContextOptions& grCtxOptions)
: INHERITED(config, grCtxOptions)
, fExecutor(SkExecutor::MakeFIFOThreadPool(FLAGS_gpuThreads)) {
SkASSERT(fExecutor);
}
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 GPUThreadTestingSink::draw(const Src& src, SkBitmap* dst, SkWStream* wStream,
SkString* log) const {
// Draw twice, once with worker threads, and once without. Verify that we get the same result.
// Also, force us to only use the software path renderer, so we really stress-test the threaded
// version of that code.
GrContextOptions contextOptions = this->baseContextOptions();
contextOptions.fGpuPathRenderers = GpuPathRenderers::kNone;
contextOptions.fExecutor = fExecutor.get();
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 result = this->onDraw(src, dst, wStream, log, contextOptions);
if (!result.isOk() || !dst) {
return result;
}
SkBitmap reference;
SkString refLog;
SkDynamicMemoryWStream refStream;
contextOptions.fExecutor = 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 refResult = this->onDraw(src, &reference, &refStream, &refLog, contextOptions);
if (!refResult.isOk()) {
return refResult;
}
return compare_bitmaps(reference, *dst);
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GPUPersistentCacheTestingSink::GPUPersistentCacheTestingSink(const SkCommandLineConfigGpu* config,
const GrContextOptions& grCtxOptions)
: INHERITED(config, grCtxOptions)
, fCacheType(config->getTestPersistentCache()) {}
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 GPUPersistentCacheTestingSink::draw(const Src& src, SkBitmap* dst, SkWStream* wStream,
SkString* log) const {
// Draw twice, once with a cold cache, and again with a warm cache. Verify that we get the same
// result.
sk_gpu_test::MemoryCache memoryCache;
GrContextOptions contextOptions = this->baseContextOptions();
contextOptions.fPersistentCache = &memoryCache;
if (fCacheType == 2) {
contextOptions.fShaderCacheStrategy = GrContextOptions::ShaderCacheStrategy::kBackendSource;
}
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 result = this->onDraw(src, dst, wStream, log, contextOptions);
if (!result.isOk() || !dst) {
return result;
}
SkBitmap reference;
SkString refLog;
SkDynamicMemoryWStream refStream;
memoryCache.resetCacheStats();
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 refResult = this->onDraw(src, &reference, &refStream, &refLog, contextOptions);
if (!refResult.isOk()) {
return refResult;
}
SkASSERT(!memoryCache.numCacheMisses());
SkASSERT(!memoryCache.numCacheStores());
return compare_bitmaps(reference, *dst);
}
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
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GPUPrecompileTestingSink::GPUPrecompileTestingSink(const SkCommandLineConfigGpu* config,
const GrContextOptions& grCtxOptions)
: INHERITED(config, grCtxOptions) {}
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 GPUPrecompileTestingSink::draw(const Src& src, SkBitmap* dst, SkWStream* wStream,
SkString* log) const {
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
// Three step process:
// 1) Draw once with an SkSL cache, and store off the shader blobs.
// 2) For the second context, pre-compile the shaders to warm the cache.
// 3) Draw with the second context, ensuring that we get the same result, and no cache misses.
sk_gpu_test::MemoryCache memoryCache;
GrContextOptions contextOptions = this->baseContextOptions();
contextOptions.fPersistentCache = &memoryCache;
contextOptions.fShaderCacheStrategy = GrContextOptions::ShaderCacheStrategy::kSkSL;
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 result = this->onDraw(src, dst, wStream, log, contextOptions);
if (!result.isOk() || !dst) {
return result;
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
}
auto precompileShaders = [&memoryCache](GrDirectContext* dContext) {
memoryCache.foreach([dContext](sk_sp<const SkData> key,
sk_sp<SkData> data,
int /*count*/) {
SkAssertResult(dContext->precompileShader(*key, *data));
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
});
};
sk_gpu_test::MemoryCache replayCache;
GrContextOptions replayOptions = this->baseContextOptions();
// Ensure that the runtime cache is large enough to hold all of the shaders we pre-compile
replayOptions.fRuntimeProgramCacheSize = memoryCache.numCacheMisses();
replayOptions.fPersistentCache = &replayCache;
SkBitmap reference;
SkString refLog;
SkDynamicMemoryWStream refStream;
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 refResult = this->onDraw(src, &reference, &refStream, &refLog, replayOptions,
precompileShaders);
if (!refResult.isOk()) {
return refResult;
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
}
SkASSERT(!replayCache.numCacheMisses());
return compare_bitmaps(reference, *dst);
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GPUOOPRSink::GPUOOPRSink(const SkCommandLineConfigGpu* config, const GrContextOptions& ctxOptions)
: INHERITED(config, ctxOptions) {
}
Result GPUOOPRSink::ooprDraw(const Src& src,
sk_sp<SkSurface> dstSurface,
GrDirectContext* context) const {
SkSurfaceCharacterization dstCharacterization;
SkAssertResult(dstSurface->characterize(&dstCharacterization));
SkDeferredDisplayListRecorder recorder(dstCharacterization);
Result result = src.draw(context, recorder.getCanvas());
if (!result.isOk()) {
return result;
}
auto ddl = recorder.detach();
SkDeferredDisplayList::ProgramIterator iter(context, ddl.get());
for (; !iter.done(); iter.next()) {
iter.compile();
}
SkAssertResult(dstSurface->draw(std::move(ddl)));
return Result::Ok();
}
Result GPUOOPRSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log) const {
GrContextOptions contextOptions = this->baseContextOptions();
src.modifyGrContextOptions(&contextOptions);
contextOptions.fPersistentCache = nullptr;
contextOptions.fExecutor = nullptr;
GrContextFactory factory(contextOptions);
ContextInfo ctxInfo = factory.getContextInfo(this->contextType(), this->contextOverrides());
auto context = ctxInfo.directContext();
if (!context) {
return Result::Fatal("Could not create context.");
}
SkASSERT(context->priv().getGpu());
sk_sp<SkSurface> surface = this->createDstSurface(context, src.size());
if (!surface) {
return Result::Fatal("Could not create a surface.");
}
Result result = this->ooprDraw(src, surface, context);
if (!result.isOk()) {
return result;
}
if (FLAGS_gpuStats) {
context->priv().dumpCacheStats(log);
context->priv().dumpGpuStats(log);
context->priv().dumpContextStats(log);
}
if (!this->readBack(surface.get(), dst)) {
return Result::Fatal("Could not readback from surface.");
}
return Result::Ok();
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
GPUDDLSink::GPUDDLSink(const SkCommandLineConfigGpu* config, const GrContextOptions& ctxOptions)
: INHERITED(config, ctxOptions)
, fRecordingExecutor(SkExecutor::MakeLIFOThreadPool(1))
, fGPUExecutor(SkExecutor::MakeFIFOThreadPool(1, false)) {
}
Result GPUDDLSink::ddlDraw(const Src& src,
sk_sp<SkSurface> dstSurface,
SkTaskGroup* recordingTaskGroup,
SkTaskGroup* gpuTaskGroup,
sk_gpu_test::TestContext* gpuTestCtx,
GrDirectContext* gpuThreadCtx) const {
// We have to do this here bc characterization can hit the SkGpuDevice's thread guard (i.e.,
// leaving it until the DDLTileHelper ctor will result in multiple threads trying to use the
// same context (this thread and the gpuThread - which will be uploading textures)).
SkSurfaceCharacterization dstCharacterization;
SkAssertResult(dstSurface->characterize(&dstCharacterization));
auto size = src.size();
SkPictureRecorder recorder;
Result result = src.draw(gpuThreadCtx, recorder.beginRecording(SkIntToScalar(size.width()),
SkIntToScalar(size.height())));
if (!result.isOk()) {
return result;
}
sk_sp<SkPicture> inputPicture(recorder.finishRecordingAsPicture());
// this is our ultimate final drawing area/rect
SkIRect viewport = SkIRect::MakeWH(size.fWidth, size.fHeight);
2020-09-01 19:01:15 +00:00
SkYUVAPixmapInfo::SupportedDataTypes supportedYUVADataTypes(*gpuThreadCtx);
DDLPromiseImageHelper promiseImageHelper(supportedYUVADataTypes);
sk_sp<SkData> compressedPictureData = promiseImageHelper.deflateSKP(inputPicture.get());
if (!compressedPictureData) {
return Result::Fatal("GPUDDLSink: Couldn't deflate SkPicture");
}
promiseImageHelper.createCallbackContexts(gpuThreadCtx);
// 'gpuTestCtx/gpuThreadCtx' is being shifted to the gpuThread. Leave the main (this)
// thread w/o a context.
gpuTestCtx->makeNotCurrent();
// Job one for the GPU thread is to make 'gpuTestCtx' current!
gpuTaskGroup->add([gpuTestCtx] { gpuTestCtx->makeCurrent(); });
// TODO: move the image upload to the utility thread
promiseImageHelper.uploadAllToGPU(gpuTaskGroup, gpuThreadCtx);
// Care must be taken when using 'gpuThreadCtx' bc it moves between the gpu-thread and this
// one. About all it can be consistently used for is GrCaps access and 'defaultBackendFormat'
// calls.
constexpr int kNumDivisions = 3;
DDLTileHelper tiles(gpuThreadCtx, dstCharacterization, viewport, kNumDivisions,
/* addRandomPaddingToDst */ false);
tiles.createBackendTextures(gpuTaskGroup, gpuThreadCtx);
// Reinflate the compressed picture individually for each thread.
tiles.createSKPPerTile(compressedPictureData.get(), promiseImageHelper);
tiles.kickOffThreadedWork(recordingTaskGroup, gpuTaskGroup, gpuThreadCtx);
// We have to wait for the recording threads to schedule all their work on the gpu thread
// before we can schedule the composition draw and the flush. Note that the gpu thread
// is not blocked at this point and this thread is borrowing recording work.
recordingTaskGroup->wait();
// Note: at this point the recording thread(s) are stalled out w/ nothing to do.
// The recording threads have already scheduled the drawing of each tile's DDL on the gpu
// thread. The composition DDL must be scheduled last bc it relies on the result of all
// the tiles' rendering. Additionally, bc we're aliasing the tiles' backend textures,
// there is nothing in the DAG to automatically force the required order.
gpuTaskGroup->add([dstSurface, ddl = tiles.composeDDL()]() {
dstSurface->draw(ddl);
});
// This should be the only explicit flush for the entire DDL draw.
// TODO: remove the flushes in do_gpu_stuff
gpuTaskGroup->add([gpuThreadCtx]() {
// We need to ensure all the GPU work is finished so
// the following 'deleteAllFromGPU' call will work
// on Vulkan.
// TODO: switch over to using the promiseImage callbacks
// to free the backendTextures. This is complicated a
// bit by which thread possesses the direct context.
gpuThreadCtx->flush();
gpuThreadCtx->submit(true);
});
// The backend textures are created on the gpuThread by the 'uploadAllToGPU' call.
// It is simpler to also delete them at this point on the gpuThread.
promiseImageHelper.deleteAllFromGPU(gpuTaskGroup, gpuThreadCtx);
tiles.deleteBackendTextures(gpuTaskGroup, gpuThreadCtx);
// A flush has already been scheduled on the gpu thread along with the clean up of the backend
// textures so it is safe to schedule making 'gpuTestCtx' not current on the gpuThread.
gpuTaskGroup->add([gpuTestCtx] { gpuTestCtx->makeNotCurrent(); });
// All the work is scheduled on the gpu thread, we just need to wait
gpuTaskGroup->wait();
return Result::Ok();
}
Result GPUDDLSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log) const {
GrContextOptions contextOptions = this->baseContextOptions();
src.modifyGrContextOptions(&contextOptions);
contextOptions.fPersistentCache = nullptr;
contextOptions.fExecutor = nullptr;
GrContextFactory factory(contextOptions);
// This captures the context destined to be the main gpu context
ContextInfo mainCtxInfo = factory.getContextInfo(this->contextType(), this->contextOverrides());
sk_gpu_test::TestContext* mainTestCtx = mainCtxInfo.testContext();
auto mainCtx = mainCtxInfo.directContext();
if (!mainCtx) {
return Result::Fatal("Could not create context.");
}
SkASSERT(mainCtx->priv().getGpu());
// TODO: make use of 'otherCtx' for uploads & compilation
#if 0
// This captures the context destined to be the utility context. It is in a share group
// with the main context
ContextInfo otherCtxInfo = factory.getSharedContextInfo(mainCtx);
sk_gpu_test::TestContext* otherTestCtx = otherCtxInfo.testContext();
auto otherCtx = otherCtxInfo.directContext();
if (!otherCtx) {
return Result::Fatal("Cound not create shared context.");
}
SkASSERT(otherCtx->priv().getGpu());
#endif
SkTaskGroup recordingTaskGroup(*fRecordingExecutor);
SkTaskGroup gpuTaskGroup(*fGPUExecutor);
// Make sure 'mainCtx' is current
mainTestCtx->makeCurrent();
sk_sp<SkSurface> surface = this->createDstSurface(mainCtx, src.size());
if (!surface) {
return Result::Fatal("Could not create a surface.");
}
Result result = this->ddlDraw(src, surface, &recordingTaskGroup, &gpuTaskGroup,
mainTestCtx, mainCtx);
if (!result.isOk()) {
return result;
}
// 'ddlDraw' will have made 'mainCtx' not current on the gpuThread
mainTestCtx->makeCurrent();
if (FLAGS_gpuStats) {
mainCtx->priv().dumpCacheStats(log);
mainCtx->priv().dumpGpuStats(log);
mainCtx->priv().dumpContextStats(log);
#if 0
otherCtx->priv().dumpCacheStats(log);
otherCtx->priv().dumpGpuStats(log);
otherCtx->priv().dumpContextStats(log);
#endif
}
if (!this->readBack(surface.get(), dst)) {
return Result::Fatal("Could not readback from surface.");
}
return Result::Ok();
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
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 draw_skdocument(const Src& src, SkDocument* doc, SkWStream* dst) {
if (src.size().isEmpty()) {
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
return Result::Fatal("Source has empty dimensions");
}
SkASSERT(doc);
int pageCount = src.pageCount();
for (int i = 0; i < pageCount; ++i) {
int width = src.size(i).width(), height = src.size(i).height();
SkCanvas* canvas =
doc->beginPage(SkIntToScalar(width), SkIntToScalar(height));
if (!canvas) {
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
return Result::Fatal("SkDocument::beginPage(w,h) returned nullptr");
}
Result result = src.draw(i, nullptr, canvas);
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
if (!result.isOk()) {
return result;
}
doc->endPage();
}
doc->close();
dst->flush();
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
return Result::Ok();
}
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 PDFSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
SkPDF::Metadata metadata;
metadata.fTitle = src.name();
metadata.fSubject = "rendering correctness test";
metadata.fCreator = "Skia/DM";
metadata.fRasterDPI = fRasterDpi;
metadata.fPDFA = fPDFA;
#if SK_PDF_TEST_EXECUTOR
std::unique_ptr<SkExecutor> executor = SkExecutor::MakeFIFOThreadPool();
metadata.fExecutor = executor.get();
#endif
auto doc = SkPDF::MakeDocument(dst, metadata);
if (!doc) {
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
return Result::Fatal("SkPDF::MakeDocument() returned nullptr");
}
return draw_skdocument(src, doc.get(), dst);
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
XPSSink::XPSSink() {}
#if defined(SK_SUPPORT_XPS)
static SkTScopedComPtr<IXpsOMObjectFactory> make_xps_factory() {
IXpsOMObjectFactory* factory;
HRN(CoCreateInstance(CLSID_XpsOMObjectFactory,
nullptr,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(&factory)));
return SkTScopedComPtr<IXpsOMObjectFactory>(factory);
}
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 XPSSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
SkAutoCoInitialize com;
if (!com.succeeded()) {
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
return Result::Fatal("Could not initialize COM.");
}
SkTScopedComPtr<IXpsOMObjectFactory> factory = make_xps_factory();
if (!factory) {
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
return Result::Fatal("Failed to create XPS Factory.");
}
auto doc = SkXPS::MakeDocument(dst, factory.get());
if (!doc) {
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
return Result::Fatal("SkXPS::MakeDocument() returned nullptr");
}
return draw_skdocument(src, doc.get(), dst);
}
#else
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 XPSSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
return Result::Fatal("XPS not supported on this platform.");
}
#endif
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
SKPSink::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 SKPSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
auto size = SkSize::Make(src.size());
SkPictureRecorder recorder;
Result result = src.draw(nullptr, recorder.beginRecording(size.width(), size.height()));
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
if (!result.isOk()) {
return result;
}
recorder.finishRecordingAsPicture()->serialize(dst);
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
return Result::Ok();
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
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 DebugSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
DebugCanvas debugCanvas(src.size().width(), src.size().height());
Result result = src.draw(nullptr, &debugCanvas);
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
if (!result.isOk()) {
return result;
}
std::unique_ptr<SkCanvas> nullCanvas = SkMakeNullCanvas();
UrlDataManager dataManager(SkString("data"));
SkJSONWriter writer(dst, SkJSONWriter::Mode::kPretty);
writer.beginObject(); // root
debugCanvas.toJSON(writer, dataManager, nullCanvas.get());
writer.endObject(); // root
writer.flush();
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
return Result::Ok();
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
SVGSink::SVGSink(int pageIndex) : fPageIndex(pageIndex) {}
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 SVGSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
#if defined(SK_XML)
if (src.pageCount() > 1) {
int pageCount = src.pageCount();
if (fPageIndex > pageCount - 1) {
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
return Result::Fatal("Page index %d too high for document with only %d pages.",
fPageIndex, pageCount);
}
}
return src.draw(fPageIndex, nullptr,
SkSVGCanvas::Make(SkRect::MakeWH(SkIntToScalar(src.size().width()),
SkIntToScalar(src.size().height())),
dst)
.get());
#else
(void)fPageIndex;
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
return Result::Fatal("SVG sink is disabled.");
#endif // SK_XML
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
RasterSink::RasterSink(SkColorType colorType, sk_sp<SkColorSpace> colorSpace)
: fColorType(colorType)
, fColorSpace(std::move(colorSpace)) {}
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 RasterSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString*) const {
const SkISize size = src.size();
// If there's an appropriate alpha type for this color type, use it, otherwise use premul.
SkAlphaType alphaType = kPremul_SkAlphaType;
(void)SkColorTypeValidateAlphaType(fColorType, alphaType, &alphaType);
dst->allocPixelsFlags(SkImageInfo::Make(size, fColorType, alphaType, fColorSpace),
SkBitmap::kZeroPixels_AllocFlag);
SkCanvas canvas(*dst, SkSurfaceProps(0, kRGB_H_SkPixelGeometry));
return src.draw(nullptr, &canvas);
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
// Handy for front-patching a Src. Do whatever up-front work you need, then call draw_to_canvas(),
// passing the Sink draw() arguments, a size, and a function draws into an SkCanvas.
// Several examples below.
template <typename Fn>
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 draw_to_canvas(Sink* sink, SkBitmap* bitmap, SkWStream* stream, SkString* log,
SkISize size, const Fn& draw) {
class ProxySrc : public Src {
public:
ProxySrc(SkISize size, const Fn& draw) : fSize(size), fDraw(draw) {}
Result draw(GrDirectContext*, SkCanvas* canvas) const override { return fDraw(canvas); }
Name name() const override { return "ProxySrc"; }
SkISize size() const override { return fSize; }
private:
SkISize fSize;
const Fn& fDraw;
};
return sink->draw(ProxySrc(size, draw), bitmap, stream, log);
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
static DEFINE_bool(check, true, "If true, have most Via- modes fail if they affect the output.");
// Is *bitmap identical to what you get drawing src into 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
static Result check_against_reference(const SkBitmap* bitmap, const Src& src, Sink* sink) {
// We can only check raster outputs.
// (Non-raster outputs like .pdf, .skp, .svg may differ but still draw identically.)
if (FLAGS_check && bitmap) {
SkBitmap reference;
SkString log;
SkDynamicMemoryWStream wStream;
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 result = sink->draw(src, &reference, &wStream, &log);
// If we can draw into this Sink via some pipeline, we should be able to draw directly.
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
SkASSERT(result.isOk());
if (!result.isOk()) {
return result;
}
return compare_bitmaps(reference, *bitmap);
}
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
return Result::Ok();
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
static SkISize auto_compute_translate(SkMatrix* matrix, int srcW, int srcH) {
SkRect bounds = SkRect::MakeIWH(srcW, srcH);
matrix->mapRect(&bounds);
matrix->postTranslate(-bounds.x(), -bounds.y());
return {SkScalarRoundToInt(bounds.width()), SkScalarRoundToInt(bounds.height())};
}
ViaMatrix::ViaMatrix(SkMatrix matrix, Sink* sink) : Via(sink), fMatrix(matrix) {}
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 ViaMatrix::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
SkMatrix matrix = fMatrix;
SkISize size = auto_compute_translate(&matrix, src.size().width(), src.size().height());
return draw_to_canvas(fSink.get(), bitmap, stream, log, size, [&](SkCanvas* canvas) {
canvas->concat(matrix);
return src.draw(nullptr, canvas);
});
}
// Undoes any flip or 90 degree rotate without changing the scale of the bitmap.
// This should be pixel-preserving.
ViaUpright::ViaUpright(SkMatrix matrix, Sink* sink) : Via(sink), fMatrix(matrix) {}
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 ViaUpright::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
Result result = fSink->draw(src, bitmap, stream, log);
if (!result.isOk()) {
return result;
}
SkMatrix inverse;
if (!fMatrix.rectStaysRect() || !fMatrix.invert(&inverse)) {
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
return Result::Fatal("Cannot upright --matrix.");
}
SkMatrix upright = SkMatrix::I();
upright.setScaleX(SkScalarSignAsScalar(inverse.getScaleX()));
upright.setScaleY(SkScalarSignAsScalar(inverse.getScaleY()));
upright.setSkewX(SkScalarSignAsScalar(inverse.getSkewX()));
upright.setSkewY(SkScalarSignAsScalar(inverse.getSkewY()));
SkBitmap uprighted;
SkISize size = auto_compute_translate(&upright, bitmap->width(), bitmap->height());
Reland "Reland "SkSurface asynchronous read APIs allow client to extend pixel lifetime"" This is a reland of 6fc04f88a89ed2c9a1b4aa48bcd28602a69a457b Original change's description: > Reland "SkSurface asynchronous read APIs allow client to extend pixel lifetime" > > This is a reland of ce240cc6fd8ec95bd051c7df2173dad2ae8f6ad6 > > Original change's description: > > SkSurface asynchronous read APIs allow client to extend pixel lifetime > > > > Previously the pixel data passed to the client was only valid during > > the client's callback. This meant if the client wanted to defer > > processing of the data a copy was necessary. > > > > Now we pass an object to the callback and the pixel lifetime is tied > > to the lifetime of that object. > > > > The object may be holding a GPU transfer buffer mapped. We don't assume > > that the object will be released on the direct GrContext thread. So > > when the object is destroyed it posts a message to a new type, > > GrClientMappedBufferManager, hanging off the direct context. The direct > > context will periodically check for messages and unmap and then unref > > buffers so that they can be reused. Currently this is done in > > GrContext::performDeferredCleanup() and GrDrawingManager::flush(). > > > > The old API is kept around for backwards compatibility but it is > > reimplemented as a bridge on top of the new mechanism. > > > > Also a utility function to SkImageInfo is added to directly make a new > > info with a specified dimensions rather than passing the width and > > height separately to makeWH(). > > > > Bug: chromium:973403 > > Bug: skia:8962 > > > > Change-Id: Id5cf04235376170142a48e90d3ecd13fd021a2a6 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/245457 > > Reviewed-by: Brian Osman <brianosman@google.com> > > Commit-Queue: Brian Salomon <bsalomon@google.com> > > Bug: chromium:973403, skia:8962 > Change-Id: I5cecd36276c8b6dc942cf549c7095db2df88530c > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/245678 > Reviewed-by: Brian Salomon <bsalomon@google.com> > Commit-Queue: Brian Salomon <bsalomon@google.com> Bug: chromium:973403, skia:8962 Change-Id: Ie584c1c3ef8021c976f71b708e53871c693cc450 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/246057 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
2019-10-03 17:26:54 +00:00
uprighted.allocPixels(bitmap->info().makeDimensions(size));
SkCanvas canvas(uprighted);
canvas.concat(upright);
SkPaint paint;
paint.setBlendMode(SkBlendMode::kSrc);
canvas.drawBitmap(*bitmap, 0, 0, &paint);
*bitmap = uprighted;
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
return Result::Ok();
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
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 ViaSerialization::draw(
const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
// Record our Src into a picture.
auto size = src.size();
SkPictureRecorder recorder;
Result result = src.draw(nullptr, recorder.beginRecording(SkIntToScalar(size.width()),
SkIntToScalar(size.height())));
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
if (!result.isOk()) {
return result;
}
sk_sp<SkPicture> pic(recorder.finishRecordingAsPicture());
// Serialize it and then deserialize it.
sk_sp<SkPicture> deserialized(SkPicture::MakeFromData(pic->serialize().get()));
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_to_canvas(fSink.get(), bitmap, stream, log, size, [&](SkCanvas* canvas) {
canvas->drawPicture(deserialized);
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
return Result::Ok();
});
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
if (!result.isOk()) {
return result;
}
return check_against_reference(bitmap, src, fSink.get());
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
ViaDDL::ViaDDL(int numReplays, int numDivisions, Sink* sink)
: Via(sink), fNumReplays(numReplays), fNumDivisions(numDivisions) {}
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 ViaDDL::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
auto size = src.size();
SkPictureRecorder recorder;
Result result = src.draw(nullptr, recorder.beginRecording(SkIntToScalar(size.width()),
SkIntToScalar(size.height())));
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
if (!result.isOk()) {
return result;
}
sk_sp<SkPicture> inputPicture(recorder.finishRecordingAsPicture());
// this is our ultimate final drawing area/rect
SkIRect viewport = SkIRect::MakeWH(size.fWidth, size.fHeight);
2020-09-01 19:01:15 +00:00
DDLPromiseImageHelper promiseImageHelper(SkYUVAPixmapInfo::SupportedDataTypes::All());
sk_sp<SkData> compressedPictureData = promiseImageHelper.deflateSKP(inputPicture.get());
if (!compressedPictureData) {
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
return Result::Fatal("ViaDDL: Couldn't deflate SkPicture");
}
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
auto draw = [&](SkCanvas* canvas) -> Result {
auto direct = canvas->recordingContext() ? canvas->recordingContext()->asDirectContext()
: nullptr;
if (!direct) {
return Result::Fatal("ViaDDL: DDLs are GPU only");
}
SkSurface* tmp = canvas->getSurface();
if (!tmp) {
return Result::Fatal("ViaDDL: cannot get surface from canvas");
}
sk_sp<SkSurface> dstSurface = sk_ref_sp(tmp);
SkSurfaceCharacterization dstCharacterization;
SkAssertResult(dstSurface->characterize(&dstCharacterization));
promiseImageHelper.createCallbackContexts(direct);
// This is here bc this is the first point where we have access to the context
promiseImageHelper.uploadAllToGPU(nullptr, direct);
// We draw N times, with a clear between.
for (int replay = 0; replay < fNumReplays; ++replay) {
if (replay > 0) {
// Clear the drawing of the previous replay
canvas->clear(SK_ColorTRANSPARENT);
}
// First, create all the tiles (including their individual dest surfaces)
DDLTileHelper tiles(direct, dstCharacterization, viewport, fNumDivisions,
/* addRandomPaddingToDst */ false);
tiles.createBackendTextures(nullptr, direct);
// Second, reinflate the compressed picture individually for each thread
// This recreates the promise SkImages on each replay iteration. We are currently
// relying on this to test using a SkPromiseImageTexture to fulfill different
// SkImages. On each replay the promise SkImages are recreated in createSKPPerTile.
tiles.createSKPPerTile(compressedPictureData.get(), promiseImageHelper);
// Third, create the DDLs in parallel
tiles.createDDLsInParallel();
if (replay == fNumReplays - 1) {
// All the DDLs are created and they ref any created promise images which,
// in turn, ref the callback contexts. If it is the last run, drop the
// promise image helper's refs on the callback contexts.
promiseImageHelper.reset();
// Note: we cannot drop the tiles' callback contexts here bc they are needed
// to create each tile's destination surface.
}
// Fourth, synchronously render the display lists into the dest tiles
// TODO: it would be cool to not wait until all the tiles are drawn to begin
// drawing to the GPU and composing to the final surface
tiles.precompileAndDrawAllTiles(direct);
if (replay == fNumReplays - 1) {
// At this point the compose DDL holds refs to the composition promise images
// which, in turn, hold refs on the tile callback contexts. If it is the last run,
// drop the refs on tile callback contexts.
tiles.dropCallbackContexts();
}
dstSurface->draw(tiles.composeDDL());
// We need to ensure all the GPU work is finished so the promise image callback
// contexts will delete all the backend textures.
direct->flush();
direct->submit(true);
}
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
return Result::Ok();
};
return draw_to_canvas(fSink.get(), bitmap, stream, log, size, draw);
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
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 ViaPicture::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
auto size = src.size();
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 result = draw_to_canvas(fSink.get(), bitmap, stream, log, size, [&](SkCanvas* canvas) {
SkPictureRecorder recorder;
sk_sp<SkPicture> pic;
Result result = src.draw(nullptr, recorder.beginRecording(SkIntToScalar(size.width()),
SkIntToScalar(size.height())));
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
if (!result.isOk()) {
return result;
}
pic = recorder.finishRecordingAsPicture();
canvas->drawPicture(pic);
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
return result;
});
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
if (!result.isOk()) {
return result;
}
return check_against_reference(bitmap, src, fSink.get());
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#ifdef TEST_VIA_SVG
#include "include/svg/SkSVGCanvas.h"
#include "modules/svg/include/SkSVGDOM.h"
#include "src/xml/SkXMLWriter.h"
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 ViaSVG::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
auto size = src.size();
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
return draw_to_canvas(fSink.get(), bitmap, stream, log, size, [&](SkCanvas* canvas) -> Result {
SkDynamicMemoryWStream wstream;
SkXMLStreamWriter writer(&wstream);
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 result = src.draw(SkSVGCanvas::Make(SkRect::Make(size), &writer).get());
if (!result.isOk()) {
return result;
}
std::unique_ptr<SkStream> rstream(wstream.detachAsStream());
auto dom = SkSVGDOM::MakeFromStream(*rstream);
if (dom) {
dom->setContainerSize(SkSize::Make(size));
dom->render(canvas);
}
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
return Result::Ok();
});
}
#endif
} // namespace DM