2015-03-25 14:11:02 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "dm/DMSrcSink.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/ports/SkImageGeneratorCG.h"
|
|
|
|
#include "include/ports/SkImageGeneratorWIC.h"
|
|
|
|
#include "include/private/SkImageInfoPriv.h"
|
|
|
|
#include "include/private/SkTLogic.h"
|
2019-04-29 14:28:22 +00:00
|
|
|
#include "include/third_party/skcms/skcms.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/utils/SkNullCanvas.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
|
|
|
#include "src/codec/SkCodecImageGenerator.h"
|
|
|
|
#include "src/codec/SkSwizzler.h"
|
|
|
|
#include "src/core/SkAutoMalloc.h"
|
|
|
|
#include "src/core/SkAutoPixmapStorage.h"
|
|
|
|
#include "src/core/SkMakeUnique.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/GrContextPriv.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/MemoryCache.h"
|
2016-03-17 20:50:17 +00:00
|
|
|
#if defined(SK_BUILD_FOR_WIN)
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/docs/SkXPSDocument.h"
|
|
|
|
#include "src/utils/win/SkAutoCoInitialize.h"
|
|
|
|
#include "src/utils/win/SkHRESULT.h"
|
|
|
|
#include "src/utils/win/SkTScopedComPtr.h"
|
2017-02-06 14:51:42 +00:00
|
|
|
#include <XpsObjectModel.h>
|
2016-03-17 20:50:17 +00:00
|
|
|
#endif
|
|
|
|
|
2018-05-04 16:23:24 +00:00
|
|
|
#if defined(SK_ENABLE_SKOTTIE)
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "modules/skottie/include/Skottie.h"
|
2019-11-26 13:58:26 +00:00
|
|
|
#include "modules/skresources/include/SkResources.h"
|
2017-12-31 22:02:26 +00:00
|
|
|
#endif
|
|
|
|
|
2016-07-15 17:33:29 +00:00
|
|
|
#if defined(SK_XML)
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "experimental/svg/model/SkSVGDOM.h"
|
|
|
|
#include "include/svg/SkSVGCanvas.h"
|
|
|
|
#include "src/xml/SkXMLWriter.h"
|
2016-07-15 17:33:29 +00:00
|
|
|
#endif
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/TestUtils.h"
|
2016-07-15 17:33:29 +00:00
|
|
|
|
2018-09-19 15:31:27 +00:00
|
|
|
#include <cmath>
|
|
|
|
#include <functional>
|
|
|
|
|
2019-03-21 16:31:36 +00:00
|
|
|
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?");
|
2015-04-14 21:06:18 +00:00
|
|
|
|
2019-03-22 16:08:02 +00:00
|
|
|
DECLARE_int(gpuThreads);
|
|
|
|
|
2016-03-31 01:56:19 +00:00
|
|
|
using sk_gpu_test::GrContextFactory;
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
namespace DM {
|
|
|
|
|
2018-07-30 21:07:07 +00:00
|
|
|
GMSrc::GMSrc(skiagm::GMFactory factory) : fFactory(factory) {}
|
2015-01-15 18:56:12 +00:00
|
|
|
|
|
|
|
Error GMSrc::draw(SkCanvas* canvas) const {
|
2019-08-05 14:28:09 +00:00
|
|
|
std::unique_ptr<skiagm::GM> gm(fFactory());
|
2019-02-07 23:20:09 +00:00
|
|
|
SkString errorMsg;
|
|
|
|
skiagm::DrawResult drawResult = gm->draw(canvas, &errorMsg);
|
|
|
|
if (skiagm::DrawResult::kSkip == drawResult) {
|
|
|
|
return Error::Nonfatal(std::move(errorMsg)); // Cause this test to be skipped.
|
|
|
|
}
|
2019-04-02 14:01:11 +00:00
|
|
|
return errorMsg;
|
2015-01-15 18:56:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkISize GMSrc::size() const {
|
2019-08-05 14:28:09 +00:00
|
|
|
std::unique_ptr<skiagm::GM> gm(fFactory());
|
2015-01-15 18:56:12 +00:00
|
|
|
return gm->getISize();
|
|
|
|
}
|
|
|
|
|
|
|
|
Name GMSrc::name() const {
|
2019-08-05 14:28:09 +00:00
|
|
|
std::unique_ptr<skiagm::GM> gm(fFactory());
|
2015-01-15 18:56:12 +00:00
|
|
|
return gm->getName();
|
|
|
|
}
|
|
|
|
|
2015-05-27 20:23:23 +00:00
|
|
|
void GMSrc::modifyGrContextOptions(GrContextOptions* options) const {
|
2019-08-05 14:28:09 +00:00
|
|
|
std::unique_ptr<skiagm::GM> gm(fFactory());
|
2015-05-27 20:23:23 +00:00
|
|
|
gm->modifyGrContextOptions(options);
|
|
|
|
}
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2016-05-18 13:23:57 +00:00
|
|
|
BRDSrc::BRDSrc(Path path, Mode mode, CodecSrc::DstColorType dstColorType, uint32_t sampleSize)
|
2015-09-08 22:35:32 +00:00
|
|
|
: 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;
|
|
|
|
}
|
|
|
|
|
2016-05-18 13:23:57 +00:00
|
|
|
static SkBitmapRegionDecoder* create_brd(Path path) {
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> encoded(SkData::MakeFromFileName(path.c_str()));
|
2015-09-08 22:35:32 +00:00
|
|
|
if (!encoded) {
|
2017-08-28 14:34:05 +00:00
|
|
|
return nullptr;
|
2015-09-08 22:35:32 +00:00
|
|
|
}
|
2016-09-12 19:01:44 +00:00
|
|
|
return SkBitmapRegionDecoder::Create(encoded, SkBitmapRegionDecoder::kAndroidCodec_Strategy);
|
2015-09-08 22:35:32 +00:00
|
|
|
}
|
|
|
|
|
2016-12-15 23:17:33 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-08 22:35:32 +00:00
|
|
|
Error BRDSrc::draw(SkCanvas* canvas) const {
|
|
|
|
SkColorType colorType = canvas->imageInfo().colorType();
|
|
|
|
if (kRGB_565_SkColorType == colorType &&
|
|
|
|
CodecSrc::kGetFromCanvas_DstColorType != fDstColorType) {
|
|
|
|
return Error::Nonfatal("Testing non-565 to 565 is uninteresting.");
|
|
|
|
}
|
|
|
|
switch (fDstColorType) {
|
|
|
|
case CodecSrc::kGetFromCanvas_DstColorType:
|
|
|
|
break;
|
|
|
|
case CodecSrc::kGrayscale_Always_DstColorType:
|
|
|
|
colorType = kGray_8_SkColorType;
|
|
|
|
break;
|
2016-04-22 23:27:24 +00:00
|
|
|
default:
|
|
|
|
SkASSERT(false);
|
|
|
|
break;
|
2015-09-08 22:35:32 +00:00
|
|
|
}
|
|
|
|
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<SkBitmapRegionDecoder> brd(create_brd(fPath));
|
2015-09-08 22:35:32 +00:00
|
|
|
if (nullptr == brd.get()) {
|
|
|
|
return Error::Nonfatal(SkStringPrintf("Could not create brd for %s.", fPath.c_str()));
|
|
|
|
}
|
|
|
|
|
2018-03-13 15:14:33 +00:00
|
|
|
auto recommendedCT = brd->computeOutputColorType(colorType);
|
|
|
|
if (kRGB_565_SkColorType == colorType && recommendedCT != colorType) {
|
|
|
|
return Error::Nonfatal("Skip decoding non-opaque to 565.");
|
2017-08-17 17:42:48 +00:00
|
|
|
}
|
2018-03-13 15:14:33 +00:00
|
|
|
colorType = recommendedCT;
|
|
|
|
|
|
|
|
auto colorSpace = brd->computeOutputColorSpace(colorType, nullptr);
|
2017-08-17 17:42:48 +00:00
|
|
|
|
2015-09-08 22:35:32 +00:00
|
|
|
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) {
|
|
|
|
return Error::Nonfatal("Scaling very small images is uninteresting.");
|
|
|
|
}
|
|
|
|
switch (fMode) {
|
|
|
|
case kFullImage_Mode: {
|
2015-10-27 19:50:25 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
if (!brd->decodeRegion(&bitmap, nullptr, SkIRect::MakeXYWH(0, 0, width, height),
|
2018-03-13 15:14:33 +00:00
|
|
|
fSampleSize, colorType, false, colorSpace)) {
|
2015-12-09 21:02:26 +00:00
|
|
|
return "Cannot decode (full) region.";
|
2015-10-27 19:50:25 +00:00
|
|
|
}
|
2016-12-15 23:17:33 +00:00
|
|
|
alpha8_to_gray8(&bitmap);
|
2017-06-14 13:02:05 +00:00
|
|
|
|
2015-10-27 19:50:25 +00:00
|
|
|
canvas->drawBitmap(bitmap, 0, 0);
|
2015-09-08 22:35:32 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
case kDivisor_Mode: {
|
|
|
|
const uint32_t divisor = 2;
|
|
|
|
if (width < divisor || height < divisor) {
|
2015-12-09 21:02:26 +00:00
|
|
|
return Error::Nonfatal("Divisor is larger than image dimension.");
|
2015-09-08 22:35:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 = SkTMin(width, height) / (fSampleSize * divisor);
|
|
|
|
const uint32_t scaledBorder = SkTMin(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;
|
2015-10-27 19:50:25 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
if (!brd->decodeRegion(&bitmap, nullptr, SkIRect::MakeXYWH(decodeLeft,
|
2017-04-11 13:51:32 +00:00
|
|
|
decodeTop, decodeWidth, decodeHeight), fSampleSize, colorType, false,
|
2018-03-13 15:14:33 +00:00
|
|
|
colorSpace)) {
|
2015-12-09 21:02:26 +00:00
|
|
|
return "Cannot decode region.";
|
2015-10-27 19:50:25 +00:00
|
|
|
}
|
2015-09-08 22:35:32 +00:00
|
|
|
|
2016-12-15 23:17:33 +00:00
|
|
|
alpha8_to_gray8(&bitmap);
|
2015-10-27 19:50:25 +00:00
|
|
|
canvas->drawBitmapRect(bitmap,
|
2015-09-08 22:35:32 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
SkASSERT(false);
|
2015-12-09 21:02:26 +00:00
|
|
|
return "Error: Should not be reached.";
|
2015-09-08 22:35:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize BRDSrc::size() const {
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<SkBitmapRegionDecoder> brd(create_brd(fPath));
|
2015-09-08 22:35:32 +00:00
|
|
|
if (brd) {
|
2017-04-11 16:12:02 +00:00
|
|
|
return {SkTMax(1, brd->width() / (int)fSampleSize),
|
|
|
|
SkTMax(1, brd->height() / (int)fSampleSize)};
|
2015-09-08 22:35:32 +00:00
|
|
|
}
|
2017-04-11 16:12:02 +00:00
|
|
|
return {0, 0};
|
2015-09-08 22:35:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static SkString get_scaled_name(const Path& path, float scale) {
|
|
|
|
return SkStringPrintf("%s_%.3f", SkOSPath::Basename(path.c_str()).c_str(), scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
2015-11-13 17:59:11 +00:00
|
|
|
return get_scaled_name(fPath, 1.0f / (float) fSampleSize);
|
2015-09-08 22:35:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2016-02-08 23:09:48 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-02-03 17:42:42 +00:00
|
|
|
CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, SkAlphaType dstAlphaType,
|
|
|
|
float scale)
|
2015-04-09 19:43:10 +00:00
|
|
|
: fPath(path)
|
|
|
|
, fMode(mode)
|
|
|
|
, fDstColorType(dstColorType)
|
2016-02-03 17:42:42 +00:00
|
|
|
, fDstAlphaType(dstAlphaType)
|
2015-06-11 21:27:27 +00:00
|
|
|
, fScale(scale)
|
2016-02-08 23:09:48 +00:00
|
|
|
, fRunSerially(serial_from_path_name(path))
|
2015-04-09 19:43:10 +00:00
|
|
|
{}
|
2015-03-19 13:03:39 +00:00
|
|
|
|
2015-07-31 13:43:04 +00:00
|
|
|
bool CodecSrc::veto(SinkFlags flags) const {
|
2016-03-09 22:20:58 +00:00
|
|
|
// Test to direct raster backends (8888 and 565).
|
2016-01-22 22:46:42 +00:00
|
|
|
return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDirect;
|
2015-07-29 13:37:28 +00:00
|
|
|
}
|
2015-03-19 13:03:39 +00:00
|
|
|
|
2016-04-22 23:27:24 +00:00
|
|
|
// Allows us to test decodes to non-native 8888.
|
2016-05-17 15:52:11 +00:00
|
|
|
static void swap_rb_if_necessary(SkBitmap& bitmap, CodecSrc::DstColorType dstColorType) {
|
2016-04-22 23:27:24 +00:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-17 15:52:11 +00:00
|
|
|
static bool get_decode_info(SkImageInfo* decodeInfo, SkColorType canvasColorType,
|
2016-05-20 20:56:13 +00:00
|
|
|
CodecSrc::DstColorType dstColorType, SkAlphaType dstAlphaType) {
|
2015-10-21 17:27:10 +00:00
|
|
|
switch (dstColorType) {
|
|
|
|
case CodecSrc::kGrayscale_Always_DstColorType:
|
2016-05-20 21:27:16 +00:00
|
|
|
if (kRGB_565_SkColorType == canvasColorType) {
|
2015-10-21 17:27:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-02-03 17:42:42 +00:00
|
|
|
*decodeInfo = decodeInfo->makeColorType(kGray_8_SkColorType);
|
2015-10-21 17:27:10 +00:00
|
|
|
break;
|
2016-04-22 23:27:24 +00:00
|
|
|
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) {
|
2016-04-22 23:27:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#ifdef SK_PMCOLOR_IS_RGBA
|
|
|
|
*decodeInfo = decodeInfo->makeColorType(kBGRA_8888_SkColorType);
|
|
|
|
#else
|
|
|
|
*decodeInfo = decodeInfo->makeColorType(kRGBA_8888_SkColorType);
|
|
|
|
#endif
|
|
|
|
break;
|
2015-10-21 17:27:10 +00:00
|
|
|
default:
|
2016-02-16 21:24:54 +00:00
|
|
|
if (kRGB_565_SkColorType == canvasColorType &&
|
|
|
|
kOpaque_SkAlphaType != decodeInfo->alphaType()) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-02-01 23:34:22 +00:00
|
|
|
|
2016-02-03 17:42:42 +00:00
|
|
|
*decodeInfo = decodeInfo->makeColorType(canvasColorType);
|
2015-10-21 17:27:10 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-05-20 20:56:13 +00:00
|
|
|
*decodeInfo = decodeInfo->makeAlphaType(dstAlphaType);
|
2015-10-21 17:27:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-17 15:52:11 +00:00
|
|
|
static void draw_to_canvas(SkCanvas* canvas, const SkImageInfo& info, void* pixels, size_t rowBytes,
|
2017-07-11 17:35:31 +00:00
|
|
|
CodecSrc::DstColorType dstColorType,
|
2016-05-17 15:52:11 +00:00
|
|
|
SkScalar left = 0, SkScalar top = 0) {
|
|
|
|
SkBitmap bitmap;
|
2017-07-11 17:35:31 +00:00
|
|
|
bitmap.installPixels(info, pixels, rowBytes);
|
2016-05-17 15:52:11 +00:00
|
|
|
swap_rb_if_necessary(bitmap, dstColorType);
|
|
|
|
canvas->drawBitmap(bitmap, left, top);
|
|
|
|
}
|
|
|
|
|
2017-05-26 12:58:03 +00:00
|
|
|
// 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) {
|
2018-08-27 19:16:02 +00:00
|
|
|
*info = info->makeColorSpace(SkColorSpace::MakeSRGB());
|
2017-05-26 12:58:03 +00:00
|
|
|
}
|
|
|
|
|
2015-07-29 13:37:28 +00:00
|
|
|
Error CodecSrc::draw(SkCanvas* canvas) const {
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
|
2015-03-19 13:03:39 +00:00
|
|
|
if (!encoded) {
|
|
|
|
return SkStringPrintf("Couldn't read %s.", fPath.c_str());
|
|
|
|
}
|
2016-01-22 22:46:42 +00:00
|
|
|
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(encoded));
|
2015-09-01 21:57:57 +00:00
|
|
|
if (nullptr == codec.get()) {
|
|
|
|
return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str());
|
2015-04-09 19:43:10 +00:00
|
|
|
}
|
|
|
|
|
2016-05-20 20:56:13 +00:00
|
|
|
SkImageInfo decodeInfo = codec->getInfo();
|
|
|
|
if (!get_decode_info(&decodeInfo, canvas->imageInfo().colorType(), fDstColorType,
|
|
|
|
fDstAlphaType)) {
|
2017-02-03 19:58:59 +00:00
|
|
|
return Error::Nonfatal("Skipping uninteresting test.");
|
2015-04-09 19:43:10 +00:00
|
|
|
}
|
|
|
|
|
2015-06-11 21:27:27 +00:00
|
|
|
// Try to scale the image if it is desired
|
|
|
|
SkISize size = codec->getScaledDimensions(fScale);
|
|
|
|
if (size == decodeInfo.dimensions() && 1.0f != fScale) {
|
|
|
|
return Error::Nonfatal("Test without scaling is uninteresting.");
|
|
|
|
}
|
2015-08-18 20:22:46 +00:00
|
|
|
|
|
|
|
// 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) {
|
|
|
|
return Error::Nonfatal("Scaling very small images is uninteresting.");
|
|
|
|
}
|
2019-10-03 17:26:54 +00:00
|
|
|
decodeInfo = decodeInfo.makeDimensions(size);
|
2015-06-11 21:27:27 +00:00
|
|
|
|
2018-02-09 18:26:46 +00:00
|
|
|
const int bpp = decodeInfo.bytesPerPixel();
|
2016-05-17 15:52:11 +00:00
|
|
|
const size_t rowBytes = size.width() * bpp;
|
2017-10-03 18:47:21 +00:00
|
|
|
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);
|
2015-03-19 13:03:39 +00:00
|
|
|
|
2016-01-13 17:31:39 +00:00
|
|
|
SkCodec::Options options;
|
|
|
|
if (kCodecZeroInit_Mode == fMode) {
|
2016-05-17 15:52:11 +00:00
|
|
|
memset(pixels.get(), 0, size.height() * rowBytes);
|
2016-01-13 17:31:39 +00:00
|
|
|
options.fZeroInitialized = SkCodec::kYes_ZeroInitialized;
|
|
|
|
}
|
2016-04-22 23:27:24 +00:00
|
|
|
|
|
|
|
SkImageInfo bitmapInfo = decodeInfo;
|
2017-05-26 12:58:03 +00:00
|
|
|
set_bitmap_color_space(&bitmapInfo);
|
2016-04-22 23:27:24 +00:00
|
|
|
if (kRGBA_8888_SkColorType == decodeInfo.colorType() ||
|
|
|
|
kBGRA_8888_SkColorType == decodeInfo.colorType()) {
|
|
|
|
bitmapInfo = bitmapInfo.makeColorType(kN32_SkColorType);
|
|
|
|
}
|
2015-03-19 13:03:39 +00:00
|
|
|
|
2015-03-25 20:48:49 +00:00
|
|
|
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: {
|
|
|
|
std::vector<SkCodec::FrameInfo> frameInfos = codec->getFrameInfo();
|
|
|
|
if (frameInfos.size() <= 1) {
|
|
|
|
return SkStringPrintf("%s is not an animated image.", fPath.c_str());
|
|
|
|
}
|
|
|
|
|
2016-10-25 13:11:01 +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;
|
2018-08-22 00:56:03 +00:00
|
|
|
int cachedFrame = SkCodec::kNoFrame;
|
2017-04-17 16:46:33 +00:00
|
|
|
for (int i = 0; static_cast<size_t>(i) < frameInfos.size(); 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
|
|
|
options.fFrameIndex = i;
|
|
|
|
// Check for a prior frame
|
2017-04-17 16:46:33 +00:00
|
|
|
const int reqFrame = frameInfos[i].fRequiredFrame;
|
2018-08-22 00:56:03 +00:00
|
|
|
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);
|
2017-06-07 16:31:51 +00:00
|
|
|
options.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 {
|
2018-08-22 00:56:03 +00:00
|
|
|
options.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
|
|
|
}
|
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
|
|
|
SkCodec::Result result = codec->getPixels(decodeInfo, pixels.get(),
|
2017-07-11 17:35:31 +00:00
|
|
|
rowBytes, &options);
|
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:
|
2017-07-06 16:26:09 +00:00
|
|
|
case SkCodec::kErrorInInput:
|
2016-10-25 13:11:01 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-10-25 13:11:01 +00:00
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
const int xTranslate = (i % factor) * decodeInfo.width();
|
|
|
|
const int yTranslate = (i / factor) * decodeInfo.height();
|
|
|
|
canvas->translate(SkIntToScalar(xTranslate), SkIntToScalar(yTranslate));
|
2017-07-11 17:35:31 +00:00
|
|
|
draw_to_canvas(canvas, bitmapInfo, pixels.get(), rowBytes, fDstColorType);
|
2017-07-06 16:26:09 +00:00
|
|
|
if (result != SkCodec::kSuccess) {
|
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 "";
|
|
|
|
}
|
|
|
|
break;
|
2016-10-25 13:11:01 +00:00
|
|
|
}
|
2016-10-27 15:29:13 +00:00
|
|
|
case SkCodec::kInvalidConversion:
|
2017-07-12 19:10:28 +00:00
|
|
|
if (i > 0 && (decodeInfo.colorType() == kRGB_565_SkColorType)) {
|
2016-10-27 15:29:13 +00:00
|
|
|
return Error::Nonfatal(SkStringPrintf(
|
2017-07-12 19:10:28 +00:00
|
|
|
"Cannot decode frame %i to 565 (%s).", i, fPath.c_str()));
|
2016-10-27 15:29:13 +00:00
|
|
|
}
|
|
|
|
// Fall through.
|
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:
|
|
|
|
return SkStringPrintf("Couldn't getPixels for frame %i in %s.",
|
|
|
|
i, fPath.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2016-01-13 17:31:39 +00:00
|
|
|
case kCodecZeroInit_Mode:
|
2015-09-01 21:57:57 +00:00
|
|
|
case kCodec_Mode: {
|
2017-07-11 17:35:31 +00:00
|
|
|
switch (codec->getPixels(decodeInfo, pixels.get(), rowBytes, &options)) {
|
SkCodec no longer inherits from SkImageGenerator.
SkImageGenerator makes some assumptions that are not necessarily valid
for SkCodec. For example, SkCodec does not assume that it can always be
rewound.
We also have an ongoing question of what an SkCodec should report as
its default settings (i.e. the return from getInfo). It makes sense for
an SkCodec to report that its pixels are unpremultiplied, if that is
the case for the underlying data, but if a client of SkImageGenerator
uses the default settings (as many do), they will receive
unpremultiplied pixels which cannot (currently) be drawn with Skia. We
may ultimately decide to revisit SkCodec reporting an SkImageInfo, but
I have left it unchanged for now.
Import features of SkImageGenerator used by SkCodec into SkCodec.
I have left SkImageGenerator unchanged for now, but it no longer needs
Result or Options. This will require changes to Chromium.
Manually handle the lifetime of fScanlineDecoder, so SkScanlineDecoder.h
can include SkCodec.h (where Result is), and SkCodec.h does not need
to include it (to delete fScanlineDecoder).
In many places, make the following simple changes:
- Now include SkScanlineDecoder.h, which is no longer included by
SkCodec.h
- Use the enums in SkCodec, rather than SkImageGenerator
- Stop including SkImageGenerator.h where no longer needed
Review URL: https://codereview.chromium.org/1220733013
2015-07-09 15:16:03 +00:00
|
|
|
case SkCodec::kSuccess:
|
2017-07-06 16:26:09 +00:00
|
|
|
// We consider these to be valid, since we should still decode what is
|
2015-03-25 20:48:49 +00:00
|
|
|
// available.
|
2017-07-06 16:26:09 +00:00
|
|
|
case SkCodec::kErrorInInput:
|
SkCodec no longer inherits from SkImageGenerator.
SkImageGenerator makes some assumptions that are not necessarily valid
for SkCodec. For example, SkCodec does not assume that it can always be
rewound.
We also have an ongoing question of what an SkCodec should report as
its default settings (i.e. the return from getInfo). It makes sense for
an SkCodec to report that its pixels are unpremultiplied, if that is
the case for the underlying data, but if a client of SkImageGenerator
uses the default settings (as many do), they will receive
unpremultiplied pixels which cannot (currently) be drawn with Skia. We
may ultimately decide to revisit SkCodec reporting an SkImageInfo, but
I have left it unchanged for now.
Import features of SkImageGenerator used by SkCodec into SkCodec.
I have left SkImageGenerator unchanged for now, but it no longer needs
Result or Options. This will require changes to Chromium.
Manually handle the lifetime of fScanlineDecoder, so SkScanlineDecoder.h
can include SkCodec.h (where Result is), and SkCodec.h does not need
to include it (to delete fScanlineDecoder).
In many places, make the following simple changes:
- Now include SkScanlineDecoder.h, which is no longer included by
SkCodec.h
- Use the enums in SkCodec, rather than SkImageGenerator
- Stop including SkImageGenerator.h where no longer needed
Review URL: https://codereview.chromium.org/1220733013
2015-07-09 15:16:03 +00:00
|
|
|
case SkCodec::kIncompleteInput:
|
2015-03-25 20:48:49 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// Everything else is considered a failure.
|
|
|
|
return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str());
|
|
|
|
}
|
2016-05-17 15:52:11 +00:00
|
|
|
|
2017-07-11 17:35:31 +00:00
|
|
|
draw_to_canvas(canvas, bitmapInfo, pixels.get(), rowBytes, fDstColorType);
|
2015-03-25 20:48:49 +00:00
|
|
|
break;
|
2015-06-22 17:40:21 +00:00
|
|
|
}
|
2015-03-25 20:48:49 +00:00
|
|
|
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,
|
2017-07-11 17:35:31 +00:00
|
|
|
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;
|
2017-07-06 16:26:09 +00:00
|
|
|
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.
|
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
|
|
|
return "Could not start incremental decode";
|
|
|
|
}
|
|
|
|
// Otherwise, this is an ICO. Since incremental failed, it must contain a BMP,
|
|
|
|
// which should work via startScanlineDecode
|
|
|
|
useOldScanlineMethod = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (useOldScanlineMethod) {
|
2017-07-11 17:35:31 +00:00
|
|
|
if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo)) {
|
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
|
|
|
return "Could not start scanline decoder";
|
|
|
|
}
|
|
|
|
|
2018-04-06 19:28:23 +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);
|
2015-09-07 15:54:01 +00:00
|
|
|
}
|
|
|
|
|
2017-07-11 17:35:31 +00:00
|
|
|
draw_to_canvas(canvas, bitmapInfo, dst, rowBytes, fDstColorType);
|
2015-05-27 19:36:10 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-06-11 21:27:27 +00:00
|
|
|
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;
|
2016-05-17 15:52:11 +00:00
|
|
|
void* dst = pixels.get();
|
2015-06-11 21:27:27 +00:00
|
|
|
|
|
|
|
// Decode odd stripes
|
2017-07-11 17:35:31 +00:00
|
|
|
if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo, &options)) {
|
2016-02-23 13:37:25 +00:00
|
|
|
return "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.
|
2016-05-16 16:04:18 +00:00
|
|
|
// We only run this on Jpeg, which is always kTopDown.
|
|
|
|
SkASSERT(SkCodec::kTopDown_SkScanlineOrder == codec->getScanlineOrder());
|
2015-10-09 18:07:34 +00:00
|
|
|
|
2015-06-11 21:27:27 +00:00
|
|
|
for (int i = 0; i < numStripes; i += 2) {
|
|
|
|
// Skip a stripe
|
|
|
|
const int linesToSkip = SkTMin(stripeHeight, height - i * stripeHeight);
|
2015-10-09 18:07:34 +00:00
|
|
|
codec->skipScanlines(linesToSkip);
|
2015-06-11 21:27:27 +00:00
|
|
|
|
|
|
|
// Read a stripe
|
|
|
|
const int startY = (i + 1) * stripeHeight;
|
|
|
|
const int linesToRead = SkTMin(stripeHeight, height - startY);
|
|
|
|
if (linesToRead > 0) {
|
2016-05-17 15:52:11 +00:00
|
|
|
codec->getScanlines(SkTAddOffset<void>(dst, rowBytes * startY), linesToRead,
|
|
|
|
rowBytes);
|
2015-06-11 21:27:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Decode even stripes
|
2017-07-11 17:35:31 +00:00
|
|
|
const SkCodec::Result startResult = codec->startScanlineDecode(decodeInfo);
|
2015-08-04 16:24:45 +00:00
|
|
|
if (SkCodec::kSuccess != startResult) {
|
|
|
|
return "Failed to restart scanline decoder with same parameters.";
|
2015-06-11 21:27:27 +00:00
|
|
|
}
|
|
|
|
for (int i = 0; i < numStripes; i += 2) {
|
|
|
|
// Read a stripe
|
|
|
|
const int startY = i * stripeHeight;
|
|
|
|
const int linesToRead = SkTMin(stripeHeight, height - startY);
|
2016-05-17 15:52:11 +00:00
|
|
|
codec->getScanlines(SkTAddOffset<void>(dst, rowBytes * startY), linesToRead,
|
|
|
|
rowBytes);
|
2015-06-11 21:27:27 +00:00
|
|
|
|
|
|
|
// Skip a stripe
|
2015-06-12 16:34:04 +00:00
|
|
|
const int linesToSkip = SkTMin(stripeHeight, height - (i + 1) * stripeHeight);
|
|
|
|
if (linesToSkip > 0) {
|
2015-10-09 18:07:34 +00:00
|
|
|
codec->skipScanlines(linesToSkip);
|
2015-06-11 21:27:27 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-17 15:52:11 +00:00
|
|
|
|
2017-07-11 17:35:31 +00:00
|
|
|
draw_to_canvas(canvas, bitmapInfo, dst, rowBytes, fDstColorType);
|
2015-06-22 17:40:21 +00:00
|
|
|
break;
|
2015-06-11 21:27:27 +00:00
|
|
|
}
|
2016-02-22 20:27:46 +00:00
|
|
|
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, SkTMin(tileSize, width - x), height);
|
2017-05-19 19:21:05 +00:00
|
|
|
options.fSubset = ⊂
|
2017-07-11 17:35:31 +00:00
|
|
|
if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo, &options)) {
|
2016-02-22 20:27:46 +00:00
|
|
|
return "Could not start scanline decoder.";
|
|
|
|
}
|
|
|
|
|
2016-05-17 15:52:11 +00:00
|
|
|
codec->getScanlines(SkTAddOffset<void>(pixels.get(), x * bpp), height, rowBytes);
|
2016-02-22 20:27:46 +00:00
|
|
|
}
|
|
|
|
|
2017-07-11 17:35:31 +00:00
|
|
|
draw_to_canvas(canvas, bitmapInfo, pixels.get(), rowBytes, fDstColorType);
|
2016-02-22 20:27:46 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-07-22 14:16:20 +00:00
|
|
|
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) {
|
|
|
|
return Error::Nonfatal(SkStringPrintf("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;
|
2017-05-19 19:21:05 +00:00
|
|
|
options.fSubset = ⊂
|
2015-07-22 14:16:20 +00:00
|
|
|
SkBitmap subsetBm;
|
|
|
|
// We will reuse pixel memory from bitmap.
|
2016-05-17 15:52:11 +00:00
|
|
|
void* dst = pixels.get();
|
2015-07-22 14:16:20 +00:00
|
|
|
// 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 = SkTMin(w, W - x);
|
|
|
|
const int preScaleH = SkTMin(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?
|
2016-04-25 14:04:58 +00:00
|
|
|
const int scaledW = SkTMax(1, SkScalarRoundToInt(preScaleW * fScale));
|
|
|
|
const int scaledH = SkTMax(1, SkScalarRoundToInt(preScaleH * fScale));
|
|
|
|
decodeInfo = decodeInfo.makeWH(scaledW, scaledH);
|
|
|
|
SkImageInfo subsetBitmapInfo = bitmapInfo.makeWH(scaledW, scaledH);
|
2016-05-17 15:52:11 +00:00
|
|
|
size_t subsetRowBytes = subsetBitmapInfo.minRowBytes();
|
|
|
|
const SkCodec::Result result = codec->getPixels(decodeInfo, dst, subsetRowBytes,
|
2017-07-11 17:35:31 +00:00
|
|
|
&options);
|
2015-07-22 14:16:20 +00:00
|
|
|
switch (result) {
|
|
|
|
case SkCodec::kSuccess:
|
2017-07-06 16:26:09 +00:00
|
|
|
case SkCodec::kErrorInInput:
|
2015-07-22 14:16:20 +00:00
|
|
|
case SkCodec::kIncompleteInput:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return SkStringPrintf("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);
|
|
|
|
}
|
2017-07-11 17:35:31 +00:00
|
|
|
draw_to_canvas(canvas, subsetBitmapInfo, dst, subsetRowBytes, fDstColorType,
|
|
|
|
SkIntToScalar(left), SkIntToScalar(top));
|
2016-05-17 15:52:11 +00:00
|
|
|
|
2015-07-22 14:16:20 +00:00
|
|
|
// translate by the scaled height.
|
|
|
|
top += decodeInfo.height();
|
|
|
|
}
|
|
|
|
// translate by the scaled width.
|
|
|
|
left += decodeInfo.width();
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
2016-01-22 22:46:42 +00:00
|
|
|
default:
|
|
|
|
SkASSERT(false);
|
|
|
|
return "Invalid fMode";
|
2015-03-19 13:03:39 +00:00
|
|
|
}
|
2015-03-25 20:48:49 +00:00
|
|
|
return "";
|
2015-03-19 13:03:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkISize CodecSrc::size() const {
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(encoded));
|
2015-09-30 18:33:12 +00:00
|
|
|
if (nullptr == codec) {
|
2017-04-11 16:12:02 +00:00
|
|
|
return {0, 0};
|
2015-09-30 18:33:12 +00:00
|
|
|
}
|
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
|
|
|
|
|
|
|
auto imageSize = codec->getScaledDimensions(fScale);
|
|
|
|
if (fMode == kAnimated_Mode) {
|
2016-10-25 13:11:01 +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.
|
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 size_t count = codec->getFrameInfo().size();
|
2016-10-25 13:11:01 +00:00
|
|
|
const float root = sqrt((float) count);
|
|
|
|
const int factor = sk_float_ceil2int(root);
|
|
|
|
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;
|
2015-03-19 13:03:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Name CodecSrc::name() const {
|
2015-06-11 21:27:27 +00:00
|
|
|
if (1.0f == fScale) {
|
2016-10-24 20:48:49 +00:00
|
|
|
Name name = SkOSPath::Basename(fPath.c_str());
|
|
|
|
if (fMode == kAnimated_Mode) {
|
|
|
|
name.append("_animated");
|
|
|
|
}
|
|
|
|
return name;
|
2015-06-11 21:27:27 +00:00
|
|
|
}
|
2016-10-24 20:48:49 +00:00
|
|
|
SkASSERT(fMode != kAnimated_Mode);
|
2015-09-08 22:35:32 +00:00
|
|
|
return get_scaled_name(fPath, fScale);
|
2015-03-19 13:03:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2016-05-16 16:04:13 +00:00
|
|
|
AndroidCodecSrc::AndroidCodecSrc(Path path, CodecSrc::DstColorType dstColorType,
|
2016-02-03 17:42:42 +00:00
|
|
|
SkAlphaType dstAlphaType, int sampleSize)
|
2015-10-21 17:27:10 +00:00
|
|
|
: fPath(path)
|
|
|
|
, fDstColorType(dstColorType)
|
2016-02-03 17:42:42 +00:00
|
|
|
, fDstAlphaType(dstAlphaType)
|
2015-10-21 17:27:10 +00:00
|
|
|
, fSampleSize(sampleSize)
|
2016-02-08 23:09:48 +00:00
|
|
|
, fRunSerially(serial_from_path_name(path))
|
2015-10-21 17:27:10 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
Error AndroidCodecSrc::draw(SkCanvas* canvas) const {
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
|
2015-10-21 17:27:10 +00:00
|
|
|
if (!encoded) {
|
|
|
|
return SkStringPrintf("Couldn't read %s.", fPath.c_str());
|
|
|
|
}
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromData(encoded));
|
|
|
|
if (nullptr == codec) {
|
2015-10-21 17:27:10 +00:00
|
|
|
return SkStringPrintf("Couldn't create android codec for %s.", fPath.c_str());
|
|
|
|
}
|
|
|
|
|
2016-05-20 20:56:13 +00:00
|
|
|
SkImageInfo decodeInfo = codec->getInfo();
|
|
|
|
if (!get_decode_info(&decodeInfo, canvas->imageInfo().colorType(), fDstColorType,
|
|
|
|
fDstAlphaType)) {
|
2017-02-03 19:58:59 +00:00
|
|
|
return Error::Nonfatal("Skipping uninteresting test.");
|
2015-10-21 17:27:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
return Error::Nonfatal("Scaling very small images is uninteresting.");
|
|
|
|
}
|
2019-10-03 17:26:54 +00:00
|
|
|
decodeInfo = decodeInfo.makeDimensions(size);
|
2015-10-21 17:27:10 +00:00
|
|
|
|
2018-02-09 18:26:46 +00:00
|
|
|
int bpp = decodeInfo.bytesPerPixel();
|
2016-05-17 15:52:11 +00:00
|
|
|
size_t rowBytes = size.width() * bpp;
|
|
|
|
SkAutoMalloc pixels(size.height() * rowBytes);
|
2015-10-21 17:27:10 +00:00
|
|
|
|
|
|
|
SkBitmap bitmap;
|
2016-04-22 23:27:24 +00:00
|
|
|
SkImageInfo bitmapInfo = decodeInfo;
|
2017-05-26 12:58:03 +00:00
|
|
|
set_bitmap_color_space(&bitmapInfo);
|
2016-04-22 23:27:24 +00:00
|
|
|
if (kRGBA_8888_SkColorType == decodeInfo.colorType() ||
|
|
|
|
kBGRA_8888_SkColorType == decodeInfo.colorType()) {
|
|
|
|
bitmapInfo = bitmapInfo.makeColorType(kN32_SkColorType);
|
|
|
|
}
|
2015-10-21 17:27:10 +00:00
|
|
|
|
|
|
|
// Create options for the codec.
|
|
|
|
SkAndroidCodec::AndroidOptions options;
|
|
|
|
options.fSampleSize = fSampleSize;
|
|
|
|
|
2016-05-17 15:52:11 +00:00
|
|
|
switch (codec->getAndroidPixels(decodeInfo, pixels.get(), rowBytes, &options)) {
|
2016-05-16 16:04:13 +00:00
|
|
|
case SkCodec::kSuccess:
|
2017-07-06 16:26:09 +00:00
|
|
|
case SkCodec::kErrorInInput:
|
2016-05-16 16:04:13 +00:00
|
|
|
case SkCodec::kIncompleteInput:
|
|
|
|
break;
|
2015-10-21 17:27:10 +00:00
|
|
|
default:
|
2016-05-16 16:04:13 +00:00
|
|
|
return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str());
|
2015-10-21 17:27:10 +00:00
|
|
|
}
|
2017-07-11 17:35:31 +00:00
|
|
|
draw_to_canvas(canvas, bitmapInfo, pixels.get(), rowBytes, fDstColorType);
|
2016-05-16 16:04:13 +00:00
|
|
|
return "";
|
2015-10-21 17:27:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkISize AndroidCodecSrc::size() const {
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromData(encoded));
|
2015-10-21 17:27:10 +00:00
|
|
|
if (nullptr == codec) {
|
2017-04-11 16:12:02 +00:00
|
|
|
return {0, 0};
|
2015-10-21 17:27:10 +00:00
|
|
|
}
|
|
|
|
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());
|
|
|
|
}
|
2015-11-13 17:59:11 +00:00
|
|
|
return get_scaled_name(fPath, 1.0f / (float) fSampleSize);
|
2015-10-21 17:27:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2016-03-09 22:20:58 +00:00
|
|
|
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) {
|
2017-03-07 14:08:36 +00:00
|
|
|
// 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;
|
2016-03-09 22:20:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDirect;
|
|
|
|
}
|
|
|
|
|
|
|
|
Error ImageGenSrc::draw(SkCanvas* canvas) const {
|
|
|
|
if (kRGB_565_SkColorType == canvas->imageInfo().colorType()) {
|
|
|
|
return Error::Nonfatal("Uninteresting to test image generator to 565.");
|
|
|
|
}
|
|
|
|
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
|
2016-03-09 22:20:58 +00:00
|
|
|
if (!encoded) {
|
|
|
|
return SkStringPrintf("Couldn't read %s.", fPath.c_str());
|
|
|
|
}
|
|
|
|
|
2016-03-17 20:50:17 +00:00
|
|
|
#if defined(SK_BUILD_FOR_WIN)
|
|
|
|
// Initialize COM in order to test with WIC.
|
|
|
|
SkAutoCoInitialize com;
|
|
|
|
if (!com.succeeded()) {
|
|
|
|
return "Could not initialize COM.";
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-11-03 18:40:50 +00:00
|
|
|
std::unique_ptr<SkImageGenerator> gen(nullptr);
|
2016-03-09 22:20:58 +00:00
|
|
|
switch (fMode) {
|
|
|
|
case kCodec_Mode:
|
2017-02-15 20:14:16 +00:00
|
|
|
gen = SkCodecImageGenerator::MakeFromEncodedCodec(encoded);
|
2016-03-09 22:20:58 +00:00
|
|
|
if (!gen) {
|
|
|
|
return "Could not create codec image generator.";
|
|
|
|
}
|
|
|
|
break;
|
2016-03-17 20:50:17 +00:00
|
|
|
case kPlatform_Mode: {
|
2016-03-09 22:20:58 +00:00
|
|
|
#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
|
2017-10-30 13:07:53 +00:00
|
|
|
gen = SkImageGeneratorCG::MakeFromEncodedCG(encoded);
|
2016-03-17 20:50:17 +00:00
|
|
|
#elif defined(SK_BUILD_FOR_WIN)
|
2018-06-25 18:01:29 +00:00
|
|
|
gen = SkImageGeneratorWIC::MakeFromEncodedWIC(encoded);
|
2016-03-17 20:50:17 +00:00
|
|
|
#endif
|
2016-03-09 22:20:58 +00:00
|
|
|
if (!gen) {
|
2016-03-17 20:50:17 +00:00
|
|
|
return "Could not create platform image generator.";
|
2016-03-09 22:20:58 +00:00
|
|
|
}
|
|
|
|
break;
|
2016-03-17 20:50:17 +00:00
|
|
|
}
|
2016-03-09 22:20:58 +00:00
|
|
|
default:
|
|
|
|
SkASSERT(false);
|
|
|
|
return "Invalid image generator mode";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test deferred decoding path on GPU
|
|
|
|
if (fIsGpu) {
|
2017-02-15 20:14:16 +00:00
|
|
|
sk_sp<SkImage> image(SkImage::MakeFromGenerator(std::move(gen), nullptr));
|
2016-03-09 22:20:58 +00:00
|
|
|
if (!image) {
|
|
|
|
return "Could not create image from codec image generator.";
|
|
|
|
}
|
|
|
|
canvas->drawImage(image, 0, 0);
|
|
|
|
return "";
|
|
|
|
}
|
2016-03-22 18:46:53 +00:00
|
|
|
|
2016-03-09 22:20:58 +00:00
|
|
|
// Test various color and alpha types on CPU
|
|
|
|
SkImageInfo decodeInfo = gen->getInfo().makeAlphaType(fDstAlphaType);
|
2016-03-22 18:46:53 +00:00
|
|
|
|
2018-02-09 18:26:46 +00:00
|
|
|
int bpp = decodeInfo.bytesPerPixel();
|
2016-05-17 15:52:11 +00:00
|
|
|
size_t rowBytes = decodeInfo.width() * bpp;
|
|
|
|
SkAutoMalloc pixels(decodeInfo.height() * rowBytes);
|
2018-07-11 13:08:46 +00:00
|
|
|
if (!gen->getPixels(decodeInfo, pixels.get(), rowBytes)) {
|
2017-03-02 17:07:46 +00:00
|
|
|
SkString err =
|
|
|
|
SkStringPrintf("Image generator could not getPixels() for %s\n", fPath.c_str());
|
|
|
|
|
|
|
|
#if defined(SK_BUILD_FOR_WIN)
|
|
|
|
if (kPlatform_Mode == fMode) {
|
|
|
|
// Do not issue a fatal error for WIC flakiness.
|
|
|
|
return Error::Nonfatal(err);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return err;
|
2016-03-09 22:20:58 +00:00
|
|
|
}
|
|
|
|
|
2017-05-26 12:58:03 +00:00
|
|
|
set_bitmap_color_space(&decodeInfo);
|
2017-07-11 17:35:31 +00:00
|
|
|
draw_to_canvas(canvas, decodeInfo, pixels.get(), rowBytes,
|
2016-05-17 15:52:11 +00:00
|
|
|
CodecSrc::kGetFromCanvas_DstColorType);
|
2016-03-09 22:20:58 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize ImageGenSrc::size() const {
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(encoded));
|
2016-03-09 22:20:58 +00:00
|
|
|
if (nullptr == codec) {
|
2017-04-11 16:12:02 +00:00
|
|
|
return {0, 0};
|
2016-03-09 22:20:58 +00:00
|
|
|
}
|
|
|
|
return codec->getInfo().dimensions();
|
|
|
|
}
|
|
|
|
|
|
|
|
Name ImageGenSrc::name() const {
|
|
|
|
return SkOSPath::Basename(fPath.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2019-03-06 16:56:04 +00:00
|
|
|
ColorCodecSrc::ColorCodecSrc(Path path, bool decode_to_dst) : fPath(path)
|
|
|
|
, fDecodeToDst(decode_to_dst) {}
|
2016-04-29 16:38:40 +00:00
|
|
|
|
|
|
|
bool ColorCodecSrc::veto(SinkFlags flags) const {
|
|
|
|
// Test to direct raster backends (8888 and 565).
|
|
|
|
return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDirect;
|
|
|
|
}
|
|
|
|
|
|
|
|
Error ColorCodecSrc::draw(SkCanvas* canvas) const {
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
|
2016-04-29 16:38:40 +00:00
|
|
|
if (!encoded) {
|
|
|
|
return SkStringPrintf("Couldn't read %s.", fPath.c_str());
|
|
|
|
}
|
|
|
|
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(encoded));
|
|
|
|
if (nullptr == codec) {
|
2016-04-29 16:38:40 +00:00
|
|
|
return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str());
|
|
|
|
}
|
|
|
|
|
2019-03-06 16:56:04 +00:00
|
|
|
SkImageInfo info = codec->getInfo();
|
|
|
|
if (fDecodeToDst) {
|
2019-10-03 17:26:54 +00:00
|
|
|
info = canvas->imageInfo().makeDimensions(info.dimensions());
|
2016-06-01 21:47:18 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 13:23:33 +00:00
|
|
|
SkBitmap bitmap;
|
2019-03-06 16:56:04 +00:00
|
|
|
if (!bitmap.tryAllocPixels(info)) {
|
|
|
|
return SkStringPrintf("Image(%s) is too large (%d x %d)",
|
|
|
|
fPath.c_str(), info.width(), info.height());
|
2016-07-29 13:23:33 +00:00
|
|
|
}
|
|
|
|
|
2019-03-06 16:56:04 +00:00
|
|
|
switch (auto r = codec->getPixels(info, bitmap.getPixels(), bitmap.rowBytes())) {
|
2017-07-06 16:26:09 +00:00
|
|
|
case SkCodec::kSuccess:
|
|
|
|
case SkCodec::kErrorInInput:
|
|
|
|
case SkCodec::kIncompleteInput:
|
2019-03-06 16:56:04 +00:00
|
|
|
canvas->drawBitmap(bitmap, 0,0);
|
|
|
|
return "";
|
|
|
|
case SkCodec::kInvalidConversion:
|
|
|
|
// TODO(mtklein): why are there formats we can't decode to?
|
|
|
|
return Error::Nonfatal("SkCodec can't decode to this format.");
|
2017-07-06 16:26:09 +00:00
|
|
|
default:
|
|
|
|
return SkStringPrintf("Couldn't getPixels %s. Error code %d", fPath.c_str(), r);
|
2016-07-29 00:11:18 +00:00
|
|
|
}
|
2016-04-29 16:38:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkISize ColorCodecSrc::size() const {
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> encoded(SkData::MakeFromFileName(fPath.c_str()));
|
2017-07-23 19:30:02 +00:00
|
|
|
std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(encoded));
|
2016-04-29 16:38:40 +00:00
|
|
|
if (nullptr == codec) {
|
2017-04-11 16:12:02 +00:00
|
|
|
return {0, 0};
|
2016-04-29 16:38:40 +00:00
|
|
|
}
|
2017-04-11 16:12:02 +00:00
|
|
|
return {codec->getInfo().width(), codec->getInfo().height()};
|
2016-04-29 16:38:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Name ColorCodecSrc::name() const {
|
|
|
|
return SkOSPath::Basename(fPath.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2019-03-21 18:08:08 +00:00
|
|
|
static DEFINE_int(skpViewportSize, 1000,
|
|
|
|
"Width & height of the viewport used to crop skp rendering.");
|
|
|
|
|
2017-08-30 16:06:35 +00:00
|
|
|
SKPSrc::SKPSrc(Path path) : fPath(path) { }
|
2015-01-15 18:56:12 +00:00
|
|
|
|
2019-01-14 17:47:59 +00:00
|
|
|
Error SKPSrc::draw(SkCanvas* canvas) const {
|
|
|
|
std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(fPath.c_str());
|
2015-01-18 15:05:01 +00:00
|
|
|
if (!stream) {
|
2019-01-14 17:47:59 +00:00
|
|
|
return SkStringPrintf("Couldn't read %s.", fPath.c_str());
|
2015-01-15 18:56:12 +00:00
|
|
|
}
|
2019-01-14 17:47:59 +00:00
|
|
|
sk_sp<SkPicture> pic(SkPicture::MakeFromStream(stream.get()));
|
2015-01-18 15:05:01 +00:00
|
|
|
if (!pic) {
|
2019-01-14 17:47:59 +00:00
|
|
|
return SkStringPrintf("Couldn't parse file %s.", fPath.c_str());
|
2015-01-18 15:05:01 +00:00
|
|
|
}
|
2016-09-16 13:24:20 +00:00
|
|
|
stream = nullptr; // Might as well drop this when we're done with it.
|
2018-03-27 12:06:57 +00:00
|
|
|
canvas->clipRect(SkRect::MakeWH(FLAGS_skpViewportSize, FLAGS_skpViewportSize));
|
2015-01-15 18:56:12 +00:00
|
|
|
canvas->drawPicture(pic);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2017-08-30 16:06:35 +00:00
|
|
|
static SkRect get_cull_rect_for_skp(const char* path) {
|
|
|
|
std::unique_ptr<SkStream> stream = SkStream::MakeFromFile(path);
|
2015-03-16 17:38:07 +00:00
|
|
|
if (!stream) {
|
2017-08-30 16:06:35 +00:00
|
|
|
return SkRect::MakeEmpty();
|
2015-03-16 17:38:07 +00:00
|
|
|
}
|
|
|
|
SkPictInfo info;
|
2017-12-20 19:09:20 +00:00
|
|
|
if (!SkPicture_StreamIsSKP(stream.get(), &info)) {
|
2017-08-30 16:06:35 +00:00
|
|
|
return SkRect::MakeEmpty();
|
2015-03-16 17:38:07 +00:00
|
|
|
}
|
2017-08-30 16:06:35 +00:00
|
|
|
|
|
|
|
return info.fCullRect;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize SKPSrc::size() const {
|
|
|
|
SkRect viewport = get_cull_rect_for_skp(fPath.c_str());
|
2018-03-27 12:06:57 +00:00
|
|
|
if (!viewport.intersect((SkRect::MakeWH(FLAGS_skpViewportSize, FLAGS_skpViewportSize)))) {
|
2017-04-11 16:12:02 +00:00
|
|
|
return {0, 0};
|
2015-03-16 17:38:07 +00:00
|
|
|
}
|
|
|
|
return viewport.roundOut().size();
|
2015-01-15 18:56:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Name SKPSrc::name() const { return SkOSPath::Basename(fPath.c_str()); }
|
|
|
|
|
2017-12-31 16:08:42 +00:00
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2018-09-28 17:27:39 +00:00
|
|
|
BisectSrc::BisectSrc(Path path, const char* trail) : INHERITED(path), fTrail(trail) {}
|
|
|
|
|
|
|
|
Error BisectSrc::draw(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());
|
|
|
|
Error err = this->INHERITED::draw(&pathFinder);
|
|
|
|
if (!err.isEmpty()) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2018-05-04 16:23:24 +00:00
|
|
|
#if defined(SK_ENABLE_SKOTTIE)
|
2018-07-30 19:49:20 +00:00
|
|
|
SkottieSrc::SkottieSrc(Path path) : fPath(std::move(path)) {}
|
2017-12-31 16:08:42 +00:00
|
|
|
|
2018-01-16 22:04:30 +00:00
|
|
|
Error SkottieSrc::draw(SkCanvas* canvas) const {
|
2018-11-09 21:19:44 +00:00
|
|
|
auto animation = skottie::Animation::Builder()
|
|
|
|
.setResourceProvider(
|
2019-11-26 13:58:26 +00:00
|
|
|
skresources::DataURIResourceProviderProxy::Make(
|
|
|
|
skresources::FileResourceProvider::Make(SkOSPath::Dirname(fPath.c_str()),
|
2019-10-18 17:13:40 +00:00
|
|
|
/*predecode=*/true),
|
|
|
|
/*predecode=*/true))
|
2018-11-09 21:19:44 +00:00
|
|
|
.makeFromFile(fPath.c_str());
|
2018-07-30 19:49:20 +00:00
|
|
|
if (!animation) {
|
|
|
|
return SkStringPrintf("Unable to parse file: %s", fPath.c_str());
|
2017-12-31 16:08:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
canvas->drawColor(SK_ColorWHITE);
|
|
|
|
|
2018-05-29 17:46:54 +00:00
|
|
|
const auto t_rate = 1.0f / (kTileCount * kTileCount - 1);
|
2017-12-31 16:08:42 +00:00
|
|
|
|
2018-08-29 13:52:52 +00:00
|
|
|
// 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, "");
|
2018-01-27 17:43:24 +00:00
|
|
|
|
2017-12-31 16:08:42 +00:00
|
|
|
for (int i = 0; i < kTileCount; ++i) {
|
2018-08-29 13:52:52 +00:00
|
|
|
const SkScalar y = frameOrder[i] * kTileSize;
|
2017-12-31 16:08:42 +00:00
|
|
|
|
|
|
|
for (int j = 0; j < kTileCount; ++j) {
|
2018-08-29 13:52:52 +00:00
|
|
|
const SkScalar x = frameOrder[j] * kTileSize;
|
2018-07-30 19:49:20 +00:00
|
|
|
SkRect dest = SkRect::MakeXYWH(x, y, kTileSize, kTileSize);
|
2017-12-31 16:08:42 +00:00
|
|
|
|
2018-08-29 13:52:52 +00:00
|
|
|
const auto t = t_rate * (frameOrder[i] * kTileCount + frameOrder[j]);
|
2018-01-09 20:51:21 +00:00
|
|
|
{
|
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
2018-01-27 17:43:24 +00:00
|
|
|
canvas->clipRect(dest, true);
|
2018-07-30 19:49:20 +00:00
|
|
|
canvas->concat(SkMatrix::MakeRectToRect(SkRect::MakeSize(animation->size()),
|
2018-01-09 20:51:21 +00:00
|
|
|
dest,
|
2018-03-16 01:52:54 +00:00
|
|
|
SkMatrix::kCenter_ScaleToFit));
|
2018-07-30 19:49:20 +00:00
|
|
|
animation->seek(t);
|
|
|
|
animation->render(canvas);
|
2018-01-09 20:51:21 +00:00
|
|
|
}
|
2017-12-31 16:08:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2018-01-16 22:04:30 +00:00
|
|
|
SkISize SkottieSrc::size() const {
|
2018-07-30 19:49:20 +00:00
|
|
|
return SkISize::Make(kTargetSize, kTargetSize);
|
2017-12-31 16:08:42 +00:00
|
|
|
}
|
|
|
|
|
2018-07-30 19:49:20 +00:00
|
|
|
Name SkottieSrc::name() const { return SkOSPath::Basename(fPath.c_str()); }
|
2017-12-31 16:08:42 +00:00
|
|
|
|
2018-01-16 22:04:30 +00:00
|
|
|
bool SkottieSrc::veto(SinkFlags flags) const {
|
2017-12-31 16:08:42 +00:00
|
|
|
// 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;
|
|
|
|
}
|
2017-12-31 22:02:26 +00:00
|
|
|
#endif
|
2017-12-31 16:08:42 +00:00
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
2016-08-04 02:53:36 +00:00
|
|
|
#if defined(SK_XML)
|
2016-09-17 14:26:26 +00:00
|
|
|
// Used when the image doesn't have an intrinsic size.
|
2017-04-11 16:12:02 +00:00
|
|
|
static const SkSize kDefaultSVGSize = {1000, 1000};
|
2016-08-04 02:53:36 +00:00
|
|
|
|
2016-09-17 14:26:26 +00:00
|
|
|
// Used to force-scale tiny fixed-size images.
|
2017-04-11 16:12:02 +00:00
|
|
|
static const SkSize kMinimumSVGSize = {128, 128};
|
2016-08-04 02:53:36 +00:00
|
|
|
|
2016-11-08 15:13:45 +00:00
|
|
|
SVGSrc::SVGSrc(Path path)
|
|
|
|
: fName(SkOSPath::Basename(path.c_str()))
|
|
|
|
, fScale(1) {
|
|
|
|
|
2018-09-19 18:14:15 +00:00
|
|
|
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 = SkTMax(1.f, SkTMax(kMinimumSVGSize.width() / sz.width(),
|
|
|
|
kMinimumSVGSize.height() / sz.height()));
|
|
|
|
}
|
2016-08-04 02:53:36 +00:00
|
|
|
}
|
|
|
|
|
2016-09-17 14:26:26 +00:00
|
|
|
Error SVGSrc::draw(SkCanvas* canvas) const {
|
2016-11-08 15:13:45 +00:00
|
|
|
if (!fDom) {
|
|
|
|
return SkStringPrintf("Unable to parse file: %s", fName.c_str());
|
2016-09-17 14:26:26 +00:00
|
|
|
}
|
|
|
|
|
2016-11-08 15:13:45 +00:00
|
|
|
SkAutoCanvasRestore acr(canvas, true);
|
|
|
|
canvas->scale(fScale, fScale);
|
|
|
|
fDom->render(canvas);
|
|
|
|
|
|
|
|
return "";
|
2016-09-17 14:26:26 +00:00
|
|
|
}
|
|
|
|
|
2016-08-04 02:53:36 +00:00
|
|
|
SkISize SVGSrc::size() const {
|
2016-11-08 15:13:45 +00:00
|
|
|
if (!fDom) {
|
2017-04-11 16:12:02 +00:00
|
|
|
return {0, 0};
|
2016-09-17 14:26:26 +00:00
|
|
|
}
|
|
|
|
|
2017-04-11 16:12:02 +00:00
|
|
|
return SkSize{fDom->containerSize().width() * fScale, fDom->containerSize().height() * fScale}
|
|
|
|
.toRound();
|
2016-08-04 02:53:36 +00:00
|
|
|
}
|
|
|
|
|
2016-11-08 15:13:45 +00:00
|
|
|
Name SVGSrc::name() const { return fName; }
|
2016-08-04 02:53:36 +00:00
|
|
|
|
2016-08-16 21:23:29 +00:00
|
|
|
bool SVGSrc::veto(SinkFlags flags) const {
|
2017-06-16 19:31:17 +00:00
|
|
|
// No need to test to non-(raster||gpu||vector) or indirect backends.
|
2016-08-16 21:23:29 +00:00
|
|
|
bool type_ok = flags.type == SinkFlags::kRaster
|
2017-06-16 19:31:17 +00:00
|
|
|
|| flags.type == SinkFlags::kGPU
|
|
|
|
|| flags.type == SinkFlags::kVector;
|
2016-08-16 21:23:29 +00:00
|
|
|
|
|
|
|
return !type_ok || flags.approach != SinkFlags::kDirect;
|
|
|
|
}
|
|
|
|
|
2016-08-04 02:53:36 +00:00
|
|
|
#endif // defined(SK_XML)
|
2015-01-15 18:56:12 +00:00
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2016-06-02 19:41:14 +00:00
|
|
|
MSKPSrc::MSKPSrc(Path path) : fPath(path) {
|
2016-09-16 13:24:20 +00:00
|
|
|
std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(fPath.c_str());
|
2017-04-03 20:06:42 +00:00
|
|
|
int count = SkMultiPictureDocumentReadPageCount(stream.get());
|
|
|
|
if (count > 0) {
|
|
|
|
fPages.reset(count);
|
|
|
|
(void)SkMultiPictureDocumentReadPageSizes(stream.get(), &fPages[0], fPages.count());
|
|
|
|
}
|
2016-06-02 19:41:14 +00:00
|
|
|
}
|
|
|
|
|
2017-04-03 20:06:42 +00:00
|
|
|
int MSKPSrc::pageCount() const { return fPages.count(); }
|
2016-06-02 19:41:14 +00:00
|
|
|
|
|
|
|
SkISize MSKPSrc::size() const { return this->size(0); }
|
2017-04-03 20:06:42 +00:00
|
|
|
SkISize MSKPSrc::size(int i) const {
|
2017-04-11 16:12:02 +00:00
|
|
|
return i >= 0 && i < fPages.count() ? fPages[i].fSize.toCeil() : SkISize{0, 0};
|
2017-04-03 20:06:42 +00:00
|
|
|
}
|
2016-06-02 19:41:14 +00:00
|
|
|
|
|
|
|
Error MSKPSrc::draw(SkCanvas* c) const { return this->draw(0, c); }
|
|
|
|
Error MSKPSrc::draw(int i, SkCanvas* canvas) const {
|
2017-04-03 20:06:42 +00:00
|
|
|
if (this->pageCount() == 0) {
|
2016-06-02 19:41:14 +00:00
|
|
|
return SkStringPrintf("Unable to parse MultiPictureDocument file: %s", fPath.c_str());
|
|
|
|
}
|
2017-04-03 20:06:42 +00:00
|
|
|
if (i >= fPages.count() || i < 0) {
|
2016-06-02 19:41:14 +00:00
|
|
|
return SkStringPrintf("MultiPictureDocument page number out of range: %d", i);
|
|
|
|
}
|
2017-04-03 20:06:42 +00:00
|
|
|
SkPicture* page = fPages[i].fPicture.get();
|
2016-06-02 19:41:14 +00:00
|
|
|
if (!page) {
|
2017-04-03 20:06:42 +00:00
|
|
|
std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(fPath.c_str());
|
|
|
|
if (!stream) {
|
|
|
|
return SkStringPrintf("Unable to open file: %s", fPath.c_str());
|
|
|
|
}
|
|
|
|
if (!SkMultiPictureDocumentRead(stream.get(), &fPages[0], fPages.count())) {
|
|
|
|
return SkStringPrintf("SkMultiPictureDocument reader failed on page %d: %s", i,
|
|
|
|
fPath.c_str());
|
|
|
|
}
|
|
|
|
page = fPages[i].fPicture.get();
|
2016-06-02 19:41:14 +00:00
|
|
|
}
|
|
|
|
canvas->drawPicture(page);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
Name MSKPSrc::name() const { return SkOSPath::Basename(fPath.c_str()); }
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2015-02-13 23:11:10 +00:00
|
|
|
Error NullSink::draw(const Src& src, SkBitmap*, SkWStream*, SkString*) const {
|
2016-11-12 14:06:55 +00:00
|
|
|
return src.draw(SkMakeNullCanvas().get());
|
2015-02-13 23:11:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2017-09-06 21:08:30 +00:00
|
|
|
static Error compare_bitmaps(const SkBitmap& reference, const SkBitmap& bitmap) {
|
|
|
|
// The dimensions are a property of the Src only, and so should be identical.
|
2017-10-03 18:47:21 +00:00
|
|
|
SkASSERT(reference.computeByteSize() == bitmap.computeByteSize());
|
|
|
|
if (reference.computeByteSize() != bitmap.computeByteSize()) {
|
2017-09-06 21:08:30 +00:00
|
|
|
return "Dimensions don't match reference";
|
|
|
|
}
|
|
|
|
// All SkBitmaps in DM are tight, so this comparison is easy.
|
2017-10-03 18:47:21 +00:00
|
|
|
if (0 != memcmp(reference.getPixels(), bitmap.getPixels(), reference.computeByteSize())) {
|
2017-09-06 21:08:30 +00:00
|
|
|
SkString encoded;
|
|
|
|
SkString errString("Pixels don't match reference");
|
2019-10-25 00:07:39 +00:00
|
|
|
if (BipmapToBase64DataURI(reference, &encoded)) {
|
2018-10-01 16:42:53 +00:00
|
|
|
errString.append("\nExpected: ");
|
2017-09-06 21:08:30 +00:00
|
|
|
errString.append(encoded);
|
|
|
|
} else {
|
|
|
|
errString.append("\nExpected image failed to encode: ");
|
|
|
|
errString.append(encoded);
|
|
|
|
}
|
2019-10-25 00:07:39 +00:00
|
|
|
if (BipmapToBase64DataURI(bitmap, &encoded)) {
|
2018-10-01 16:42:53 +00:00
|
|
|
errString.append("\nActual: ");
|
2017-09-06 21:08:30 +00:00
|
|
|
errString.append(encoded);
|
|
|
|
} else {
|
|
|
|
errString.append("\nActual image failed to encode: ");
|
|
|
|
errString.append(encoded);
|
|
|
|
}
|
|
|
|
return errString;
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2019-03-21 16:31:36 +00:00
|
|
|
static DEFINE_bool(gpuStats, false, "Append GPU stats to the log for each GPU task?");
|
2019-03-21 18:08:08 +00:00
|
|
|
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.");
|
2019-06-27 20:43:27 +00:00
|
|
|
static DEFINE_bool(programBinaryCache, true, "Use in-memory program binary cache");
|
2015-02-03 02:26:03 +00:00
|
|
|
|
2019-09-09 17:46:52 +00:00
|
|
|
GPUSink::GPUSink(const SkCommandLineConfigGpu* config,
|
2017-08-21 20:48:46 +00:00
|
|
|
const GrContextOptions& grCtxOptions)
|
2019-09-09 17:46:52 +00:00
|
|
|
: 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()))
|
2019-06-27 20:43:27 +00:00
|
|
|
, fBaseContextOptions(grCtxOptions) {
|
|
|
|
if (FLAGS_programBinaryCache) {
|
|
|
|
fBaseContextOptions.fPersistentCache = &fMemoryCache;
|
|
|
|
}
|
|
|
|
}
|
2015-01-15 18:56:12 +00:00
|
|
|
|
2017-08-30 14:02:10 +00:00
|
|
|
Error GPUSink::draw(const Src& src, SkBitmap* dst, SkWStream* dstStream, SkString* log) const {
|
|
|
|
return this->onDraw(src, dst, dstStream, log, fBaseContextOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
Error GPUSink::onDraw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log,
|
2019-09-06 18:42:43 +00:00
|
|
|
const GrContextOptions& baseOptions,
|
|
|
|
std::function<void(GrContext*)> initContext) const {
|
2017-08-30 14:02:10 +00:00
|
|
|
GrContextOptions grOptions = baseOptions;
|
2015-12-10 14:28:13 +00:00
|
|
|
|
2018-07-11 19:32:05 +00:00
|
|
|
// 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);
|
2015-12-10 14:28:13 +00:00
|
|
|
src.modifyGrContextOptions(&grOptions);
|
2018-07-11 19:32:05 +00:00
|
|
|
SkASSERT(cache == grOptions.fPersistentCache);
|
|
|
|
SkASSERT(exec == grOptions.fExecutor);
|
2015-05-27 20:23:23 +00:00
|
|
|
|
2015-12-10 14:28:13 +00:00
|
|
|
GrContextFactory factory(grOptions);
|
2015-01-28 23:32:24 +00:00
|
|
|
const SkISize size = src.size();
|
2019-09-30 19:12:27 +00:00
|
|
|
SkImageInfo info = SkImageInfo::Make(size, fColorType, fAlphaType, fColorSpace);
|
2018-03-09 14:01:53 +00:00
|
|
|
sk_sp<SkSurface> surface;
|
2017-02-21 19:36:05 +00:00
|
|
|
GrContext* context = factory.getContextInfo(fContextType, fContextOverrides).grContext();
|
2019-09-06 18:42:43 +00:00
|
|
|
if (initContext) {
|
|
|
|
initContext(context);
|
|
|
|
}
|
2019-02-04 18:26:26 +00:00
|
|
|
const int maxDimension = context->priv().caps()->maxTextureSize();
|
2016-02-08 17:10:47 +00:00
|
|
|
if (maxDimension < SkTMax(size.width(), size.height())) {
|
|
|
|
return Error::Nonfatal("Src too large to create a texture.\n");
|
|
|
|
}
|
2018-03-09 14:01:53 +00:00
|
|
|
uint32_t flags = fUseDIText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : 0;
|
|
|
|
SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
|
|
|
|
GrBackendTexture backendTexture;
|
|
|
|
GrBackendRenderTarget backendRT;
|
|
|
|
switch (fSurfType) {
|
|
|
|
case SkCommandLineConfigGpu::SurfType::kDefault:
|
|
|
|
surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, fSampleCount,
|
|
|
|
&props);
|
|
|
|
break;
|
|
|
|
case SkCommandLineConfigGpu::SurfType::kBackendTexture:
|
2019-06-04 15:03:06 +00:00
|
|
|
backendTexture = context->createBackendTexture(
|
2019-06-04 11:16:10 +00:00
|
|
|
info.width(), info.height(), info.colorType(), SkColors::kTransparent,
|
2019-07-01 19:04:06 +00:00
|
|
|
GrMipMapped::kNo, GrRenderable::kYes, GrProtected::kNo);
|
2018-03-09 14:01:53 +00:00
|
|
|
surface = SkSurface::MakeFromBackendTexture(context, backendTexture,
|
|
|
|
kTopLeft_GrSurfaceOrigin, fSampleCount,
|
2018-03-19 18:18:08 +00:00
|
|
|
fColorType, info.refColorSpace(), &props);
|
2018-03-09 14:01:53 +00:00
|
|
|
break;
|
|
|
|
case SkCommandLineConfigGpu::SurfType::kBackendRenderTarget:
|
|
|
|
if (1 == fSampleCount) {
|
|
|
|
auto colorType = SkColorTypeToGrColorType(info.colorType());
|
2019-02-04 18:26:26 +00:00
|
|
|
backendRT = context->priv().getGpu()->createTestingOnlyBackendRenderTarget(
|
2018-08-09 14:55:09 +00:00
|
|
|
info.width(), info.height(), colorType);
|
2018-03-23 19:31:32 +00:00
|
|
|
surface = SkSurface::MakeFromBackendRenderTarget(
|
|
|
|
context, backendRT, kBottomLeft_GrSurfaceOrigin, info.colorType(),
|
|
|
|
info.refColorSpace(), &props);
|
2018-03-09 14:01:53 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2016-02-08 17:10:47 +00:00
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
if (!surface) {
|
|
|
|
return "Could not create a surface.";
|
|
|
|
}
|
2015-02-25 22:09:45 +00:00
|
|
|
if (FLAGS_preAbandonGpuContext) {
|
|
|
|
factory.abandonContexts();
|
|
|
|
}
|
2015-01-15 18:56:12 +00:00
|
|
|
SkCanvas* canvas = surface->getCanvas();
|
|
|
|
Error err = src.draw(canvas);
|
|
|
|
if (!err.isEmpty()) {
|
|
|
|
return err;
|
|
|
|
}
|
2019-03-04 16:00:10 +00:00
|
|
|
surface->flush();
|
2015-02-03 02:26:03 +00:00
|
|
|
if (FLAGS_gpuStats) {
|
2019-02-04 18:26:26 +00:00
|
|
|
canvas->getGrContext()->priv().dumpCacheStats(log);
|
|
|
|
canvas->getGrContext()->priv().dumpGpuStats(log);
|
2015-02-03 02:26:03 +00:00
|
|
|
}
|
2018-03-22 14:01:16 +00:00
|
|
|
if (info.colorType() == kRGB_565_SkColorType || info.colorType() == kARGB_4444_SkColorType ||
|
|
|
|
info.colorType() == kRGB_888x_SkColorType) {
|
2017-07-17 15:31:31 +00:00
|
|
|
// We don't currently support readbacks into these formats on the GPU backend. Convert to
|
|
|
|
// 32 bit.
|
2019-09-30 19:12:27 +00:00
|
|
|
info = SkImageInfo::Make(size, kRGBA_8888_SkColorType, kPremul_SkAlphaType, fColorSpace);
|
2017-07-17 15:31:31 +00:00
|
|
|
}
|
2015-01-15 18:56:12 +00:00
|
|
|
dst->allocPixels(info);
|
2017-04-17 14:53:29 +00:00
|
|
|
canvas->readPixels(*dst, 0, 0);
|
2015-01-21 23:50:13 +00:00
|
|
|
if (FLAGS_abandonGpuContext) {
|
|
|
|
factory.abandonContexts();
|
2016-04-01 18:54:31 +00:00
|
|
|
} else if (FLAGS_releaseAndAbandonGpuContext) {
|
|
|
|
factory.releaseResourcesAndAbandonContexts();
|
2015-01-21 23:50:13 +00:00
|
|
|
}
|
2018-06-26 21:38:34 +00:00
|
|
|
if (!context->abandoned()) {
|
2018-03-09 14:01:53 +00:00
|
|
|
surface.reset();
|
|
|
|
if (backendTexture.isValid()) {
|
2019-05-20 12:38:07 +00:00
|
|
|
context->deleteBackendTexture(backendTexture);
|
2018-03-09 14:01:53 +00:00
|
|
|
}
|
|
|
|
if (backendRT.isValid()) {
|
2019-02-04 18:26:26 +00:00
|
|
|
context->priv().getGpu()->deleteTestingOnlyBackendRenderTarget(backendRT);
|
2018-03-09 14:01:53 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-08 20:49:46 +00:00
|
|
|
if (grOptions.fPersistentCache) {
|
|
|
|
context->storeVkPipelineCacheData();
|
|
|
|
}
|
2015-01-15 18:56:12 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2019-09-09 17:46:52 +00:00
|
|
|
GPUThreadTestingSink::GPUThreadTestingSink(const SkCommandLineConfigGpu* config,
|
2017-08-30 14:02:10 +00:00
|
|
|
const GrContextOptions& grCtxOptions)
|
2019-09-09 17:46:52 +00:00
|
|
|
: INHERITED(config, grCtxOptions)
|
2017-09-01 15:53:16 +00:00
|
|
|
, fExecutor(SkExecutor::MakeFIFOThreadPool(FLAGS_gpuThreads)) {
|
2017-08-30 14:02:10 +00:00
|
|
|
SkASSERT(fExecutor);
|
|
|
|
}
|
|
|
|
|
|
|
|
Error 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();
|
2017-08-30 19:14:04 +00:00
|
|
|
contextOptions.fGpuPathRenderers = GpuPathRenderers::kNone;
|
2018-05-10 17:25:52 +00:00
|
|
|
contextOptions.fExecutor = fExecutor.get();
|
2018-05-14 21:02:03 +00:00
|
|
|
|
2017-08-30 14:02:10 +00:00
|
|
|
Error err = this->onDraw(src, dst, wStream, log, contextOptions);
|
|
|
|
if (!err.isEmpty() || !dst) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkBitmap reference;
|
|
|
|
SkString refLog;
|
|
|
|
SkDynamicMemoryWStream refStream;
|
|
|
|
contextOptions.fExecutor = nullptr;
|
|
|
|
Error refErr = this->onDraw(src, &reference, &refStream, &refLog, contextOptions);
|
|
|
|
if (!refErr.isEmpty()) {
|
|
|
|
return refErr;
|
|
|
|
}
|
|
|
|
|
2017-09-06 21:08:30 +00:00
|
|
|
return compare_bitmaps(reference, *dst);
|
2017-08-30 14:02:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2019-09-09 17:46:52 +00:00
|
|
|
GPUPersistentCacheTestingSink::GPUPersistentCacheTestingSink(const SkCommandLineConfigGpu* config,
|
|
|
|
const GrContextOptions& grCtxOptions)
|
|
|
|
: INHERITED(config, grCtxOptions)
|
|
|
|
, fCacheType(config->getTestPersistentCache()) {}
|
2018-07-11 19:32:05 +00:00
|
|
|
|
|
|
|
Error 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;
|
2019-09-03 18:59:26 +00:00
|
|
|
if (fCacheType == 2) {
|
|
|
|
contextOptions.fShaderCacheStrategy = GrContextOptions::ShaderCacheStrategy::kBackendSource;
|
|
|
|
}
|
2019-06-27 20:15:11 +00:00
|
|
|
// anglebug.com/3619
|
|
|
|
contextOptions.fGpuPathRenderers =
|
|
|
|
contextOptions.fGpuPathRenderers & ~GpuPathRenderers::kStencilAndCover;
|
2018-07-11 19:32:05 +00:00
|
|
|
|
|
|
|
Error err = this->onDraw(src, dst, wStream, log, contextOptions);
|
|
|
|
if (!err.isEmpty() || !dst) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkBitmap reference;
|
|
|
|
SkString refLog;
|
|
|
|
SkDynamicMemoryWStream refStream;
|
|
|
|
memoryCache.resetNumCacheMisses();
|
|
|
|
Error refErr = this->onDraw(src, &reference, &refStream, &refLog, contextOptions);
|
|
|
|
if (!refErr.isEmpty()) {
|
|
|
|
return refErr;
|
|
|
|
}
|
2018-07-12 20:20:23 +00:00
|
|
|
SkASSERT(!memoryCache.numCacheMisses());
|
2018-07-11 19:32:05 +00:00
|
|
|
|
|
|
|
return compare_bitmaps(reference, *dst);
|
|
|
|
}
|
|
|
|
|
2019-09-06 18:42:43 +00:00
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2019-09-09 17:46:52 +00:00
|
|
|
GPUPrecompileTestingSink::GPUPrecompileTestingSink(const SkCommandLineConfigGpu* config,
|
|
|
|
const GrContextOptions& grCtxOptions)
|
|
|
|
: INHERITED(config, grCtxOptions) {}
|
2019-09-06 18:42:43 +00:00
|
|
|
|
|
|
|
Error GPUPrecompileTestingSink::draw(const Src& src, SkBitmap* dst, SkWStream* wStream,
|
|
|
|
SkString* log) const {
|
|
|
|
// 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;
|
|
|
|
// anglebug.com/3619 means that we don't cache shaders when we're using NVPR. That prevents
|
|
|
|
// the precompile from working, so we'll trigger the assert at the end of this test.
|
|
|
|
contextOptions.fGpuPathRenderers =
|
|
|
|
contextOptions.fGpuPathRenderers & ~GpuPathRenderers::kStencilAndCover;
|
|
|
|
|
|
|
|
Error err = this->onDraw(src, dst, wStream, log, contextOptions);
|
|
|
|
if (!err.isEmpty() || !dst) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto precompileShaders = [&memoryCache](GrContext* context) {
|
|
|
|
memoryCache.foreach([context](sk_sp<const SkData> key, sk_sp<SkData> data, int /*count*/) {
|
|
|
|
SkAssertResult(context->precompileShader(*key, *data));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
// anglebug.com/3619
|
|
|
|
replayOptions.fGpuPathRenderers =
|
|
|
|
replayOptions.fGpuPathRenderers & ~GpuPathRenderers::kStencilAndCover;
|
|
|
|
|
|
|
|
SkBitmap reference;
|
|
|
|
SkString refLog;
|
|
|
|
SkDynamicMemoryWStream refStream;
|
|
|
|
Error refErr = this->onDraw(src, &reference, &refStream, &refLog, replayOptions,
|
|
|
|
precompileShaders);
|
|
|
|
if (!refErr.isEmpty()) {
|
|
|
|
return refErr;
|
|
|
|
}
|
|
|
|
SkASSERT(!replayCache.numCacheMisses());
|
|
|
|
|
|
|
|
return compare_bitmaps(reference, *dst);
|
|
|
|
}
|
|
|
|
|
2018-07-11 19:32:05 +00:00
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
2015-03-03 17:13:09 +00:00
|
|
|
static Error draw_skdocument(const Src& src, SkDocument* doc, SkWStream* dst) {
|
2016-03-10 18:31:53 +00:00
|
|
|
if (src.size().isEmpty()) {
|
|
|
|
return "Source has empty dimensions";
|
|
|
|
}
|
2015-03-03 17:13:09 +00:00
|
|
|
SkASSERT(doc);
|
2016-06-02 19:41:14 +00:00
|
|
|
int pageCount = src.pageCount();
|
|
|
|
for (int i = 0; i < pageCount; ++i) {
|
|
|
|
int width = src.size(i).width(), height = src.size(i).height();
|
2015-04-14 21:06:18 +00:00
|
|
|
SkCanvas* canvas =
|
|
|
|
doc->beginPage(SkIntToScalar(width), SkIntToScalar(height));
|
|
|
|
if (!canvas) {
|
2015-08-27 14:41:13 +00:00
|
|
|
return "SkDocument::beginPage(w,h) returned nullptr";
|
2015-04-14 21:06:18 +00:00
|
|
|
}
|
2016-06-02 19:41:14 +00:00
|
|
|
Error err = src.draw(i, canvas);
|
2015-04-14 21:06:18 +00:00
|
|
|
if (!err.isEmpty()) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
doc->endPage();
|
|
|
|
}
|
2016-09-22 21:12:46 +00:00
|
|
|
doc->close();
|
2015-01-28 19:45:58 +00:00
|
|
|
dst->flush();
|
2015-01-15 18:56:12 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2015-03-03 17:13:09 +00:00
|
|
|
Error PDFSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
|
2018-09-07 18:33:14 +00:00
|
|
|
SkPDF::Metadata metadata;
|
2016-04-27 14:45:18 +00:00
|
|
|
metadata.fTitle = src.name();
|
|
|
|
metadata.fSubject = "rendering correctness test";
|
|
|
|
metadata.fCreator = "Skia/DM";
|
2017-12-14 18:25:04 +00:00
|
|
|
metadata.fRasterDPI = fRasterDpi;
|
|
|
|
metadata.fPDFA = fPDFA;
|
2018-12-18 20:11:03 +00:00
|
|
|
#if SK_PDF_TEST_EXECUTOR
|
2018-12-11 00:59:07 +00:00
|
|
|
std::unique_ptr<SkExecutor> executor = SkExecutor::MakeFIFOThreadPool();
|
|
|
|
metadata.fExecutor = executor.get();
|
|
|
|
#endif
|
2019-01-07 15:00:48 +00:00
|
|
|
auto doc = SkPDF::MakeDocument(dst, metadata);
|
2015-03-03 17:13:09 +00:00
|
|
|
if (!doc) {
|
2018-09-07 18:33:14 +00:00
|
|
|
return "SkPDF::MakeDocument() returned nullptr";
|
2016-04-27 14:45:18 +00:00
|
|
|
}
|
2015-03-03 17:13:09 +00:00
|
|
|
return draw_skdocument(src, doc.get(), dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
|
|
|
XPSSink::XPSSink() {}
|
|
|
|
|
2017-02-06 14:26:49 +00:00
|
|
|
#ifdef SK_BUILD_FOR_WIN
|
2017-02-06 14:51:42 +00:00
|
|
|
static SkTScopedComPtr<IXpsOMObjectFactory> make_xps_factory() {
|
|
|
|
IXpsOMObjectFactory* factory;
|
|
|
|
HRN(CoCreateInstance(CLSID_XpsOMObjectFactory,
|
|
|
|
nullptr,
|
|
|
|
CLSCTX_INPROC_SERVER,
|
|
|
|
IID_PPV_ARGS(&factory)));
|
|
|
|
return SkTScopedComPtr<IXpsOMObjectFactory>(factory);
|
|
|
|
}
|
|
|
|
|
|
|
|
Error XPSSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
|
2017-02-06 14:26:49 +00:00
|
|
|
SkAutoCoInitialize com;
|
|
|
|
if (!com.succeeded()) {
|
|
|
|
return "Could not initialize COM.";
|
|
|
|
}
|
2017-02-06 14:51:42 +00:00
|
|
|
SkTScopedComPtr<IXpsOMObjectFactory> factory = make_xps_factory();
|
|
|
|
if (!factory) {
|
|
|
|
return "Failed to create XPS Factory.";
|
|
|
|
}
|
2019-01-07 15:00:48 +00:00
|
|
|
auto doc = SkXPS::MakeDocument(dst, factory.get());
|
2015-03-03 17:13:09 +00:00
|
|
|
if (!doc) {
|
2019-01-07 15:00:48 +00:00
|
|
|
return "SkXPS::MakeDocument() returned nullptr";
|
2015-03-03 17:13:09 +00:00
|
|
|
}
|
|
|
|
return draw_skdocument(src, doc.get(), dst);
|
|
|
|
}
|
2017-02-06 14:51:42 +00:00
|
|
|
#else
|
|
|
|
Error XPSSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
|
|
|
|
return "XPS not supported on this platform.";
|
|
|
|
}
|
|
|
|
#endif
|
2016-09-13 15:09:45 +00:00
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2015-01-28 19:35:18 +00:00
|
|
|
SKPSink::SKPSink() {}
|
|
|
|
|
2015-02-03 02:26:03 +00:00
|
|
|
Error SKPSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
|
2015-01-28 19:35:18 +00:00
|
|
|
SkSize size;
|
|
|
|
size = src.size();
|
|
|
|
SkPictureRecorder recorder;
|
|
|
|
Error err = src.draw(recorder.beginRecording(size.width(), size.height()));
|
|
|
|
if (!err.isEmpty()) {
|
|
|
|
return err;
|
|
|
|
}
|
2016-03-18 14:25:55 +00:00
|
|
|
recorder.finishRecordingAsPicture()->serialize(dst);
|
2015-01-28 19:35:18 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
2016-10-25 14:33:27 +00:00
|
|
|
|
|
|
|
Error DebugSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
|
2019-03-20 16:59:00 +00:00
|
|
|
DebugCanvas debugCanvas(src.size().width(), src.size().height());
|
2016-10-25 14:33:27 +00:00
|
|
|
Error err = src.draw(&debugCanvas);
|
|
|
|
if (!err.isEmpty()) {
|
|
|
|
return err;
|
|
|
|
}
|
2016-11-12 14:06:55 +00:00
|
|
|
std::unique_ptr<SkCanvas> nullCanvas = SkMakeNullCanvas();
|
2016-10-25 14:33:27 +00:00
|
|
|
UrlDataManager dataManager(SkString("data"));
|
2019-01-28 18:41:19 +00:00
|
|
|
SkJSONWriter writer(dst, SkJSONWriter::Mode::kPretty);
|
|
|
|
writer.beginObject(); // root
|
|
|
|
debugCanvas.toJSON(writer, dataManager, debugCanvas.getSize(), nullCanvas.get());
|
|
|
|
writer.endObject(); // root
|
|
|
|
writer.flush();
|
|
|
|
return "";
|
2016-10-25 14:33:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
2015-01-28 19:35:18 +00:00
|
|
|
|
2018-03-02 21:54:21 +00:00
|
|
|
SVGSink::SVGSink(int pageIndex) : fPageIndex(pageIndex) {}
|
2015-02-01 04:00:58 +00:00
|
|
|
|
2015-02-03 02:26:03 +00:00
|
|
|
Error SVGSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
|
2016-07-15 17:33:29 +00:00
|
|
|
#if defined(SK_XML)
|
2018-03-02 21:54:21 +00:00
|
|
|
if (src.pageCount() > 1) {
|
|
|
|
int pageCount = src.pageCount();
|
|
|
|
if (fPageIndex > pageCount - 1) {
|
|
|
|
return Error(SkStringPrintf("Page index %d too high for document with only %d pages.",
|
|
|
|
fPageIndex, pageCount));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return src.draw(fPageIndex,
|
|
|
|
SkSVGCanvas::Make(SkRect::MakeWH(SkIntToScalar(src.size().width()),
|
2016-11-12 14:06:55 +00:00
|
|
|
SkIntToScalar(src.size().height())),
|
2019-02-14 18:42:15 +00:00
|
|
|
dst)
|
2018-03-02 21:54:21 +00:00
|
|
|
.get());
|
2016-07-15 17:33:29 +00:00
|
|
|
#else
|
2018-03-22 17:10:51 +00:00
|
|
|
(void)fPageIndex;
|
2016-07-15 17:33:29 +00:00
|
|
|
return Error("SVG sink is disabled.");
|
|
|
|
#endif // SK_XML
|
2015-02-01 04:00:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2016-06-16 20:03:24 +00:00
|
|
|
RasterSink::RasterSink(SkColorType colorType, sk_sp<SkColorSpace> colorSpace)
|
2016-02-26 22:43:21 +00:00
|
|
|
: fColorType(colorType)
|
2016-06-16 20:03:24 +00:00
|
|
|
, fColorSpace(std::move(colorSpace)) {}
|
2015-01-15 18:56:12 +00:00
|
|
|
|
2018-07-25 17:28:44 +00:00
|
|
|
Error RasterSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString*) const {
|
2015-01-28 23:32:24 +00:00
|
|
|
const SkISize size = src.size();
|
2015-01-15 18:56:12 +00:00
|
|
|
// 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);
|
|
|
|
|
2019-09-30 19:12:27 +00:00
|
|
|
dst->allocPixelsFlags(SkImageInfo::Make(size, fColorType, alphaType, fColorSpace),
|
2017-07-18 14:53:11 +00:00
|
|
|
SkBitmap::kZeroPixels_AllocFlag);
|
2018-02-23 06:13:36 +00:00
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
SkCanvas canvas(*dst);
|
|
|
|
return src.draw(&canvas);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2015-05-05 18:38:45 +00:00
|
|
|
// Handy for front-patching a Src. Do whatever up-front work you need, then call draw_to_canvas(),
|
2015-05-07 17:53:34 +00:00
|
|
|
// passing the Sink draw() arguments, a size, and a function draws into an SkCanvas.
|
2015-05-05 18:38:45 +00:00
|
|
|
// Several examples below.
|
|
|
|
|
2016-02-19 22:27:14 +00:00
|
|
|
template <typename Fn>
|
2015-12-10 23:14:27 +00:00
|
|
|
static Error draw_to_canvas(Sink* sink, SkBitmap* bitmap, SkWStream* stream, SkString* log,
|
2016-02-19 22:27:14 +00:00
|
|
|
SkISize size, const Fn& draw) {
|
2015-05-05 18:38:45 +00:00
|
|
|
class ProxySrc : public Src {
|
|
|
|
public:
|
2016-02-19 22:27:14 +00:00
|
|
|
ProxySrc(SkISize size, const Fn& draw) : fSize(size), fDraw(draw) {}
|
2015-05-05 18:38:45 +00:00
|
|
|
Error draw(SkCanvas* canvas) const override { return fDraw(canvas); }
|
2016-03-30 15:31:27 +00:00
|
|
|
Name name() const override { return "ProxySrc"; }
|
|
|
|
SkISize size() const override { return fSize; }
|
2015-05-05 18:38:45 +00:00
|
|
|
private:
|
2016-02-19 22:27:14 +00:00
|
|
|
SkISize fSize;
|
|
|
|
const Fn& fDraw;
|
2015-05-05 18:38:45 +00:00
|
|
|
};
|
2015-12-10 23:14:27 +00:00
|
|
|
return sink->draw(ProxySrc(size, draw), bitmap, stream, log);
|
2015-05-05 18:38:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2019-03-21 16:31:36 +00:00
|
|
|
static DEFINE_bool(check, true, "If true, have most Via- modes fail if they affect the output.");
|
2016-01-08 18:19:35 +00:00
|
|
|
|
|
|
|
// Is *bitmap identical to what you get drawing src into sink?
|
|
|
|
static Error 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;
|
2016-03-30 15:31:27 +00:00
|
|
|
SkDynamicMemoryWStream wStream;
|
|
|
|
Error err = sink->draw(src, &reference, &wStream, &log);
|
2016-01-08 18:19:35 +00:00
|
|
|
// If we can draw into this Sink via some pipeline, we should be able to draw directly.
|
|
|
|
SkASSERT(err.isEmpty());
|
|
|
|
if (!err.isEmpty()) {
|
|
|
|
return err;
|
|
|
|
}
|
2017-09-06 21:08:30 +00:00
|
|
|
return compare_bitmaps(reference, *bitmap);
|
2016-01-08 18:19:35 +00:00
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2015-02-17 19:13:33 +00:00
|
|
|
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());
|
2017-04-11 16:12:02 +00:00
|
|
|
return {SkScalarRoundToInt(bounds.width()), SkScalarRoundToInt(bounds.height())};
|
2015-02-17 19:13:33 +00:00
|
|
|
}
|
|
|
|
|
2015-12-10 23:14:27 +00:00
|
|
|
ViaMatrix::ViaMatrix(SkMatrix matrix, Sink* sink) : Via(sink), fMatrix(matrix) {}
|
2015-01-15 18:56:12 +00:00
|
|
|
|
2015-02-03 02:26:03 +00:00
|
|
|
Error ViaMatrix::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
|
2015-05-05 18:38:45 +00:00
|
|
|
SkMatrix matrix = fMatrix;
|
|
|
|
SkISize size = auto_compute_translate(&matrix, src.size().width(), src.size().height());
|
2016-11-03 18:40:50 +00:00
|
|
|
return draw_to_canvas(fSink.get(), bitmap, stream, log, size, [&](SkCanvas* canvas) {
|
2015-05-05 18:38:45 +00:00
|
|
|
canvas->concat(matrix);
|
|
|
|
return src.draw(canvas);
|
|
|
|
});
|
2015-01-15 18:56:12 +00:00
|
|
|
}
|
|
|
|
|
2015-02-17 19:13:33 +00:00
|
|
|
// Undoes any flip or 90 degree rotate without changing the scale of the bitmap.
|
|
|
|
// This should be pixel-preserving.
|
2015-12-10 23:14:27 +00:00
|
|
|
ViaUpright::ViaUpright(SkMatrix matrix, Sink* sink) : Via(sink), fMatrix(matrix) {}
|
2015-02-17 19:13:33 +00:00
|
|
|
|
|
|
|
Error ViaUpright::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
|
|
|
|
Error err = fSink->draw(src, bitmap, stream, log);
|
|
|
|
if (!err.isEmpty()) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkMatrix inverse;
|
|
|
|
if (!fMatrix.rectStaysRect() || !fMatrix.invert(&inverse)) {
|
|
|
|
return "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());
|
2019-10-03 17:26:54 +00:00
|
|
|
uprighted.allocPixels(bitmap->info().makeDimensions(size));
|
2015-02-17 19:13:33 +00:00
|
|
|
|
|
|
|
SkCanvas canvas(uprighted);
|
|
|
|
canvas.concat(upright);
|
|
|
|
SkPaint paint;
|
2016-10-06 00:33:02 +00:00
|
|
|
paint.setBlendMode(SkBlendMode::kSrc);
|
2015-02-17 19:13:33 +00:00
|
|
|
canvas.drawBitmap(*bitmap, 0, 0, &paint);
|
|
|
|
|
|
|
|
*bitmap = uprighted;
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2015-05-05 18:38:45 +00:00
|
|
|
Error ViaSerialization::draw(
|
|
|
|
const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
|
2015-01-15 18:56:12 +00:00
|
|
|
// Record our Src into a picture.
|
2015-05-05 18:38:45 +00:00
|
|
|
auto size = src.size();
|
2015-01-15 18:56:12 +00:00
|
|
|
SkPictureRecorder recorder;
|
2015-05-05 18:38:45 +00:00
|
|
|
Error err = src.draw(recorder.beginRecording(SkIntToScalar(size.width()),
|
|
|
|
SkIntToScalar(size.height())));
|
2015-01-15 18:56:12 +00:00
|
|
|
if (!err.isEmpty()) {
|
|
|
|
return err;
|
|
|
|
}
|
2016-03-18 14:25:55 +00:00
|
|
|
sk_sp<SkPicture> pic(recorder.finishRecordingAsPicture());
|
2015-01-15 18:56:12 +00:00
|
|
|
|
|
|
|
// Serialize it and then deserialize it.
|
2016-09-15 14:19:35 +00:00
|
|
|
sk_sp<SkPicture> deserialized(SkPicture::MakeFromData(pic->serialize().get()));
|
2015-01-15 18:56:12 +00:00
|
|
|
|
2018-04-04 21:40:46 +00:00
|
|
|
err = draw_to_canvas(fSink.get(), bitmap, stream, log, size, [&](SkCanvas* canvas) {
|
2015-05-05 18:38:45 +00:00
|
|
|
canvas->drawPicture(deserialized);
|
2018-04-04 21:40:46 +00:00
|
|
|
return "";
|
2015-05-05 18:38:45 +00:00
|
|
|
});
|
2018-04-04 21:40:46 +00:00
|
|
|
if (!err.isEmpty()) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return check_against_reference(bitmap, src, fSink.get());
|
2015-01-15 18:56:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
2015-04-07 15:30:32 +00:00
|
|
|
|
2018-12-17 19:45:00 +00:00
|
|
|
ViaDDL::ViaDDL(int numReplays, int numDivisions, Sink* sink)
|
|
|
|
: Via(sink), fNumReplays(numReplays), fNumDivisions(numDivisions) {}
|
2018-03-27 12:06:57 +00:00
|
|
|
|
|
|
|
Error ViaDDL::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
|
|
|
|
auto size = src.size();
|
|
|
|
SkPictureRecorder recorder;
|
|
|
|
Error err = src.draw(recorder.beginRecording(SkIntToScalar(size.width()),
|
|
|
|
SkIntToScalar(size.height())));
|
|
|
|
if (!err.isEmpty()) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
sk_sp<SkPicture> inputPicture(recorder.finishRecordingAsPicture());
|
|
|
|
|
|
|
|
// this is our ultimate final drawing area/rect
|
|
|
|
SkIRect viewport = SkIRect::MakeWH(size.fWidth, size.fHeight);
|
|
|
|
|
2019-02-28 15:03:03 +00:00
|
|
|
DDLPromiseImageHelper promiseImageHelper;
|
2018-05-29 20:13:26 +00:00
|
|
|
sk_sp<SkData> compressedPictureData = promiseImageHelper.deflateSKP(inputPicture.get());
|
|
|
|
if (!compressedPictureData) {
|
|
|
|
return SkStringPrintf("ViaDDL: Couldn't deflate SkPicture");
|
2018-03-27 12:06:57 +00:00
|
|
|
}
|
2018-12-17 19:45:00 +00:00
|
|
|
auto draw = [&](SkCanvas* canvas) -> Error {
|
|
|
|
GrContext* context = canvas->getGrContext();
|
2019-02-04 18:26:26 +00:00
|
|
|
if (!context || !context->priv().getGpu()) {
|
2018-12-17 19:45:00 +00:00
|
|
|
return SkStringPrintf("DDLs are GPU only");
|
|
|
|
}
|
2018-03-27 12:06:57 +00:00
|
|
|
|
2018-12-17 19:45:00 +00:00
|
|
|
// This is here bc this is the first point where we have access to the context
|
|
|
|
promiseImageHelper.uploadAllToGPU(context);
|
2019-02-28 15:03:03 +00:00
|
|
|
// We draw N times, with a clear between.
|
2018-12-17 19:45:00 +00:00
|
|
|
for (int replay = 0; replay < fNumReplays; ++replay) {
|
|
|
|
if (replay > 0) {
|
|
|
|
// Clear the drawing of the previous replay
|
2018-12-19 16:35:20 +00:00
|
|
|
canvas->clear(SK_ColorTRANSPARENT);
|
2018-12-17 19:45:00 +00:00
|
|
|
}
|
|
|
|
// First, create all the tiles (including their individual dest surfaces)
|
|
|
|
DDLTileHelper tiles(canvas, viewport, fNumDivisions);
|
2018-03-27 12:06:57 +00:00
|
|
|
|
2018-12-17 19:45:00 +00:00
|
|
|
// Second, reinflate the compressed picture individually for each thread
|
2019-01-16 18:51:35 +00:00
|
|
|
// 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.
|
2018-12-17 19:45:00 +00:00
|
|
|
tiles.createSKPPerTile(compressedPictureData.get(), promiseImageHelper);
|
2018-03-27 12:06:57 +00:00
|
|
|
|
2018-12-17 19:45:00 +00:00
|
|
|
// Third, create the DDLs in parallel
|
|
|
|
tiles.createDDLsInParallel();
|
2018-03-27 12:06:57 +00:00
|
|
|
|
2018-12-17 19:45:00 +00:00
|
|
|
if (replay == fNumReplays - 1) {
|
|
|
|
// This drops the promiseImageHelper's refs on all the promise images if we're in
|
|
|
|
// the last run.
|
|
|
|
promiseImageHelper.reset();
|
|
|
|
}
|
2018-03-27 12:06:57 +00:00
|
|
|
|
2018-12-17 19:45:00 +00:00
|
|
|
// 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.drawAllTilesAndFlush(context, false);
|
2018-03-27 12:06:57 +00:00
|
|
|
|
2018-12-17 19:45:00 +00:00
|
|
|
// Finally, compose the drawn tiles into the result
|
|
|
|
// Note: the separation between the tiles and the final composition better
|
|
|
|
// matches Chrome but costs us a copy
|
|
|
|
tiles.composeAllTiles(canvas);
|
|
|
|
context->flush();
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
};
|
|
|
|
return draw_to_canvas(fSink.get(), bitmap, stream, log, size, draw);
|
2018-03-27 12:06:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2016-01-08 18:19:35 +00:00
|
|
|
Error ViaPicture::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
|
|
|
|
auto size = src.size();
|
2018-04-04 21:40:46 +00:00
|
|
|
Error err = draw_to_canvas(fSink.get(), bitmap, stream, log, size, [&](SkCanvas* canvas) {
|
2016-01-08 18:19:35 +00:00
|
|
|
SkPictureRecorder recorder;
|
2016-03-18 14:25:55 +00:00
|
|
|
sk_sp<SkPicture> pic;
|
2016-01-08 18:19:35 +00:00
|
|
|
Error err = src.draw(recorder.beginRecording(SkIntToScalar(size.width()),
|
|
|
|
SkIntToScalar(size.height())));
|
|
|
|
if (!err.isEmpty()) {
|
|
|
|
return err;
|
|
|
|
}
|
2016-03-18 14:25:55 +00:00
|
|
|
pic = recorder.finishRecordingAsPicture();
|
2016-01-08 18:19:35 +00:00
|
|
|
canvas->drawPicture(pic);
|
2018-04-04 21:40:46 +00:00
|
|
|
return err;
|
2016-01-08 18:19:35 +00:00
|
|
|
});
|
2018-04-04 21:40:46 +00:00
|
|
|
if (!err.isEmpty()) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return check_against_reference(bitmap, src, fSink.get());
|
2016-01-08 18:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2017-02-18 21:50:45 +00:00
|
|
|
#ifdef TEST_VIA_SVG
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "experimental/svg/model/SkSVGDOM.h"
|
|
|
|
#include "include/svg/SkSVGCanvas.h"
|
|
|
|
#include "src/xml/SkXMLWriter.h"
|
2017-02-17 22:06:11 +00:00
|
|
|
|
|
|
|
Error ViaSVG::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
|
|
|
|
auto size = src.size();
|
|
|
|
return draw_to_canvas(fSink.get(), bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error {
|
|
|
|
SkDynamicMemoryWStream wstream;
|
|
|
|
SkXMLStreamWriter writer(&wstream);
|
|
|
|
Error err = src.draw(SkSVGCanvas::Make(SkRect::Make(size), &writer).get());
|
|
|
|
if (!err.isEmpty()) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
std::unique_ptr<SkStream> rstream(wstream.detachAsStream());
|
|
|
|
auto dom = SkSVGDOM::MakeFromStream(*rstream);
|
|
|
|
if (dom) {
|
|
|
|
dom->setContainerSize(SkSize::Make(size));
|
|
|
|
dom->render(canvas);
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
});
|
|
|
|
}
|
2017-02-18 21:50:45 +00:00
|
|
|
#endif
|
2017-02-17 22:06:11 +00:00
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
} // namespace DM
|