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.
|
|
|
|
*/
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
#include "DMSrcSink.h"
|
|
|
|
#include "SamplePipeControllers.h"
|
2015-10-21 17:27:10 +00:00
|
|
|
#include "SkAndroidCodec.h"
|
2015-03-03 16:59:20 +00:00
|
|
|
#include "SkCodec.h"
|
2015-05-05 18:38:45 +00:00
|
|
|
#include "SkCommonFlags.h"
|
2015-03-25 20:13:43 +00:00
|
|
|
#include "SkData.h"
|
2015-01-15 18:56:12 +00:00
|
|
|
#include "SkDocument.h"
|
2015-02-25 22:09:45 +00:00
|
|
|
#include "SkError.h"
|
2015-03-25 20:13:43 +00:00
|
|
|
#include "SkImageGenerator.h"
|
2015-01-15 18:56:12 +00:00
|
|
|
#include "SkMultiPictureDraw.h"
|
2015-02-13 23:11:10 +00:00
|
|
|
#include "SkNullCanvas.h"
|
2015-01-15 18:56:12 +00:00
|
|
|
#include "SkOSFile.h"
|
2015-03-16 17:38:07 +00:00
|
|
|
#include "SkPictureData.h"
|
2015-01-15 18:56:12 +00:00
|
|
|
#include "SkPictureRecorder.h"
|
|
|
|
#include "SkRandom.h"
|
2015-05-05 19:59:56 +00:00
|
|
|
#include "SkRecordDraw.h"
|
|
|
|
#include "SkRecorder.h"
|
2015-10-16 17:29:41 +00:00
|
|
|
#include "SkRemote.h"
|
2015-02-06 20:51:10 +00:00
|
|
|
#include "SkSVGCanvas.h"
|
2015-01-21 20:09:53 +00:00
|
|
|
#include "SkStream.h"
|
2015-09-28 17:33:02 +00:00
|
|
|
#include "SkTLogic.h"
|
2015-02-06 20:51:10 +00:00
|
|
|
#include "SkXMLWriter.h"
|
2015-10-09 18:07:34 +00:00
|
|
|
#include "SkSwizzler.h"
|
2015-11-12 18:41:05 +00:00
|
|
|
#include <functional>
|
2015-01-15 18:56:12 +00:00
|
|
|
|
2015-04-14 21:06:18 +00:00
|
|
|
DEFINE_bool(multiPage, false, "For document-type backends, render the source"
|
|
|
|
" into multiple pages");
|
|
|
|
|
2015-03-25 20:13:43 +00:00
|
|
|
static bool lazy_decode_bitmap(const void* src, size_t size, SkBitmap* dst) {
|
|
|
|
SkAutoTUnref<SkData> encoded(SkData::NewWithCopy(src, size));
|
2015-09-25 13:56:57 +00:00
|
|
|
return encoded && SkDEPRECATED_InstallDiscardablePixelRef(encoded, dst);
|
2015-03-25 20:13:43 +00:00
|
|
|
}
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
namespace DM {
|
|
|
|
|
|
|
|
GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {}
|
|
|
|
|
|
|
|
Error GMSrc::draw(SkCanvas* canvas) const {
|
2015-08-27 14:41:13 +00:00
|
|
|
SkAutoTDelete<skiagm::GM> gm(fFactory(nullptr));
|
2015-01-15 18:56:12 +00:00
|
|
|
canvas->concat(gm->getInitialTransform());
|
|
|
|
gm->draw(canvas);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize GMSrc::size() const {
|
2015-08-27 14:41:13 +00:00
|
|
|
SkAutoTDelete<skiagm::GM> gm(fFactory(nullptr));
|
2015-01-15 18:56:12 +00:00
|
|
|
return gm->getISize();
|
|
|
|
}
|
|
|
|
|
|
|
|
Name GMSrc::name() const {
|
2015-08-27 14:41:13 +00:00
|
|
|
SkAutoTDelete<skiagm::GM> gm(fFactory(nullptr));
|
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 {
|
2015-08-27 14:41:13 +00:00
|
|
|
SkAutoTDelete<skiagm::GM> gm(fFactory(nullptr));
|
2015-05-27 20:23:23 +00:00
|
|
|
gm->modifyGrContextOptions(options);
|
|
|
|
}
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2015-11-06 16:56:32 +00:00
|
|
|
BRDSrc::BRDSrc(Path path, SkBitmapRegionDecoder::Strategy strategy, Mode mode,
|
2015-09-08 22:35:32 +00:00
|
|
|
CodecSrc::DstColorType dstColorType, uint32_t sampleSize)
|
|
|
|
: fPath(path)
|
|
|
|
, fStrategy(strategy)
|
|
|
|
, 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;
|
|
|
|
}
|
|
|
|
|
2015-11-06 16:56:32 +00:00
|
|
|
static SkBitmapRegionDecoder* create_brd(Path path,
|
|
|
|
SkBitmapRegionDecoder::Strategy strategy) {
|
2015-09-08 22:35:32 +00:00
|
|
|
SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str()));
|
|
|
|
if (!encoded) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-11-06 16:56:32 +00:00
|
|
|
return SkBitmapRegionDecoder::Create(encoded, strategy);
|
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::kIndex8_Always_DstColorType:
|
|
|
|
colorType = kIndex_8_SkColorType;
|
|
|
|
break;
|
|
|
|
case CodecSrc::kGrayscale_Always_DstColorType:
|
|
|
|
colorType = kGray_8_SkColorType;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-11-06 16:56:32 +00:00
|
|
|
SkAutoTDelete<SkBitmapRegionDecoder> brd(create_brd(fPath, fStrategy));
|
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()));
|
|
|
|
}
|
|
|
|
|
2015-10-12 17:24:38 +00:00
|
|
|
if (!brd->conversionSupported(colorType)) {
|
2015-12-09 21:02:26 +00:00
|
|
|
return Error::Nonfatal("Cannot convert to color type.");
|
2015-10-12 17:24:38 +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),
|
|
|
|
fSampleSize, colorType, false)) {
|
2015-12-09 21:02:26 +00:00
|
|
|
return "Cannot decode (full) region.";
|
2015-10-27 19:50:25 +00:00
|
|
|
}
|
|
|
|
if (colorType != bitmap.colorType()) {
|
2015-12-09 21:02:26 +00:00
|
|
|
return Error::Nonfatal("Cannot convert to color type.");
|
2015-09-08 22:35:32 +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,
|
|
|
|
decodeTop, decodeWidth, decodeHeight), fSampleSize, colorType, false)) {
|
2015-12-09 21:02:26 +00:00
|
|
|
return "Cannot decode region.";
|
2015-10-27 19:50:25 +00:00
|
|
|
}
|
|
|
|
if (colorType != bitmap.colorType()) {
|
2015-12-09 21:02:26 +00:00
|
|
|
return Error::Nonfatal("Cannot convert to color type.");
|
2015-09-08 22:35:32 +00:00
|
|
|
}
|
|
|
|
|
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 {
|
2015-11-06 16:56:32 +00:00
|
|
|
SkAutoTDelete<SkBitmapRegionDecoder> brd(create_brd(fPath, fStrategy));
|
2015-09-08 22:35:32 +00:00
|
|
|
if (brd) {
|
|
|
|
return SkISize::Make(SkTMax(1, brd->width() / (int) fSampleSize),
|
|
|
|
SkTMax(1, brd->height() / (int) fSampleSize));
|
|
|
|
}
|
|
|
|
return SkISize::Make(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2015-06-11 21:27:27 +00:00
|
|
|
CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, float scale)
|
2015-04-09 19:43:10 +00:00
|
|
|
: fPath(path)
|
|
|
|
, fMode(mode)
|
|
|
|
, fDstColorType(dstColorType)
|
2015-06-11 21:27:27 +00:00
|
|
|
, fScale(scale)
|
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 {
|
|
|
|
// No need to test decoding to non-raster or indirect backend.
|
2015-07-29 13:37:28 +00:00
|
|
|
// TODO: Once we implement GPU paths (e.g. JPEG YUV), we should use a deferred decode to
|
|
|
|
// let the GPU handle it.
|
2015-07-31 13:43:04 +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
|
|
|
|
2015-10-21 17:27:10 +00:00
|
|
|
bool get_decode_info(SkImageInfo* decodeInfo, const SkImageInfo& defaultInfo,
|
|
|
|
SkColorType canvasColorType, CodecSrc::DstColorType dstColorType) {
|
|
|
|
switch (dstColorType) {
|
|
|
|
case CodecSrc::kIndex8_Always_DstColorType:
|
|
|
|
if (kRGB_565_SkColorType == canvasColorType) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*decodeInfo = defaultInfo.makeColorType(kIndex_8_SkColorType);
|
|
|
|
break;
|
|
|
|
case CodecSrc::kGrayscale_Always_DstColorType:
|
|
|
|
if (kRGB_565_SkColorType == canvasColorType) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*decodeInfo = defaultInfo.makeColorType(kGray_8_SkColorType);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*decodeInfo = defaultInfo.makeColorType(canvasColorType);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Currently we cannot draw unpremultiplied sources.
|
|
|
|
if (decodeInfo->alphaType() == kUnpremul_SkAlphaType) {
|
2015-10-27 14:12:24 +00:00
|
|
|
*decodeInfo = decodeInfo->makeAlphaType(kPremul_SkAlphaType);
|
2015-10-21 17:27:10 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-29 13:37:28 +00:00
|
|
|
Error CodecSrc::draw(SkCanvas* canvas) const {
|
2015-03-19 13:03:39 +00:00
|
|
|
SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
|
|
|
|
if (!encoded) {
|
|
|
|
return SkStringPrintf("Couldn't read %s.", fPath.c_str());
|
|
|
|
}
|
2015-10-21 17:27:10 +00:00
|
|
|
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(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
|
|
|
}
|
|
|
|
|
2015-10-21 17:27:10 +00:00
|
|
|
SkImageInfo decodeInfo;
|
|
|
|
if (!get_decode_info(&decodeInfo, codec->getInfo(), canvas->imageInfo().colorType(),
|
|
|
|
fDstColorType)) {
|
|
|
|
return Error::Nonfatal("Testing non-565 to 565 is uninteresting.");
|
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.");
|
|
|
|
}
|
2015-06-11 21:27:27 +00:00
|
|
|
decodeInfo = decodeInfo.makeWH(size.width(), size.height());
|
|
|
|
|
2015-04-09 19:43:10 +00:00
|
|
|
// Construct a color table for the decode if necessary
|
2015-08-27 14:41:13 +00:00
|
|
|
SkAutoTUnref<SkColorTable> colorTable(nullptr);
|
|
|
|
SkPMColor* colorPtr = nullptr;
|
|
|
|
int* colorCountPtr = nullptr;
|
2015-04-09 19:43:10 +00:00
|
|
|
int maxColors = 256;
|
|
|
|
if (kIndex_8_SkColorType == decodeInfo.colorType()) {
|
|
|
|
SkPMColor colors[256];
|
2015-08-26 20:07:48 +00:00
|
|
|
colorTable.reset(new SkColorTable(colors, maxColors));
|
2015-04-09 19:43:10 +00:00
|
|
|
colorPtr = const_cast<SkPMColor*>(colorTable->readColors());
|
|
|
|
colorCountPtr = &maxColors;
|
2015-03-19 13:03:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SkBitmap bitmap;
|
2015-08-27 14:41:13 +00:00
|
|
|
if (!bitmap.tryAllocPixels(decodeInfo, nullptr, colorTable.get())) {
|
2015-12-09 21:02:26 +00:00
|
|
|
return SkStringPrintf("Image(%s) is too large (%d x %d)", fPath.c_str(),
|
2015-03-19 13:03:39 +00:00
|
|
|
decodeInfo.width(), decodeInfo.height());
|
|
|
|
}
|
|
|
|
|
2015-03-25 20:48:49 +00:00
|
|
|
switch (fMode) {
|
2015-09-01 21:57:57 +00:00
|
|
|
case kCodec_Mode: {
|
2015-08-27 14:41:13 +00:00
|
|
|
switch (codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.rowBytes(), nullptr,
|
2015-04-09 19:43:10 +00:00
|
|
|
colorPtr, colorCountPtr)) {
|
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:
|
2015-03-25 20:48:49 +00:00
|
|
|
// We consider incomplete to be valid, since we should still decode what is
|
|
|
|
// available.
|
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;
|
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::kInvalidConversion:
|
2015-03-25 20:48:49 +00:00
|
|
|
return Error::Nonfatal("Incompatible colortype conversion");
|
|
|
|
default:
|
|
|
|
// Everything else is considered a failure.
|
|
|
|
return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str());
|
|
|
|
}
|
2015-05-27 19:36:10 +00:00
|
|
|
canvas->drawBitmap(bitmap, 0, 0);
|
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: {
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo, NULL, colorPtr,
|
|
|
|
colorCountPtr)) {
|
2015-09-01 21:57:57 +00:00
|
|
|
return Error::Nonfatal("Could not start scanline decoder");
|
2015-03-25 20:48:49 +00:00
|
|
|
}
|
2015-08-04 16:24:45 +00:00
|
|
|
|
2015-10-09 18:07:34 +00:00
|
|
|
void* dst = bitmap.getAddr(0, 0);
|
|
|
|
size_t rowBytes = bitmap.rowBytes();
|
|
|
|
uint32_t height = decodeInfo.height();
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
switch (codec->getScanlineOrder()) {
|
|
|
|
case SkCodec::kTopDown_SkScanlineOrder:
|
|
|
|
case SkCodec::kBottomUp_SkScanlineOrder:
|
|
|
|
case SkCodec::kNone_SkScanlineOrder:
|
2015-10-09 18:07:34 +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
|
|
|
break;
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
case SkCodec::kOutOfOrder_SkScanlineOrder: {
|
2015-09-07 15:54:01 +00:00
|
|
|
for (int y = 0; y < decodeInfo.height(); y++) {
|
2015-10-09 18:07:34 +00:00
|
|
|
int dstY = codec->outputScanline(y);
|
2015-09-07 15:54:01 +00:00
|
|
|
void* dstPtr = bitmap.getAddr(0, dstY);
|
2015-10-09 18:07:34 +00:00
|
|
|
// We complete the loop, even if this call begins to fail
|
|
|
|
// due to an incomplete image. This ensures any uninitialized
|
|
|
|
// memory will be filled with the proper value.
|
|
|
|
codec->getScanlines(dstPtr, 1, bitmap.rowBytes());
|
2015-09-07 15:54:01 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-27 19:36:10 +00:00
|
|
|
canvas->drawBitmap(bitmap, 0, 0);
|
|
|
|
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;
|
|
|
|
|
|
|
|
// Decode odd stripes
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
if (SkCodec::kSuccess != codec->startScanlineDecode(decodeInfo, NULL, colorPtr,
|
|
|
|
colorCountPtr)
|
|
|
|
|| SkCodec::kTopDown_SkScanlineOrder != codec->getScanlineOrder()) {
|
2015-09-01 21:57:57 +00:00
|
|
|
// 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.
|
2015-08-31 13:55:13 +00:00
|
|
|
return Error::Nonfatal("Could not start top-down scanline decoder");
|
2015-06-11 21:27:27 +00:00
|
|
|
}
|
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) {
|
2015-10-09 18:07:34 +00:00
|
|
|
codec->getScanlines(bitmap.getAddr(0, startY), linesToRead, bitmap.rowBytes());
|
2015-06-11 21:27:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Decode even stripes
|
Merge SkCodec with SkScanlineDecoder
Benefits:
- This mimics other decoding APIs (including the ones SkCodec relies
on, e.g. a png_struct, which can be used to decode an entire image or
one line at a time).
- It allows a client to ask us to do what we can do efficiently - i.e.
start from encoded data and either decode the whole thing or scanlines.
- It removes the duplicate methods which appeared in both SkCodec and
SkScanlineDecoder (some of which, e.g. in SkJpegScanlineDecoder, just
call fCodec->sameMethod()).
- It simplifies moving more checks into the base class (e.g. the
examples in skbug.com/4284).
BUG=skia:4175
BUG=skia:4284
=====================================================================
SkScanlineDecoder.h/.cpp:
Removed.
SkCodec.h/.cpp:
Add methods, enums, and variables which were previously in
SkScanlineDecoder.
Default fCurrScanline to -1, as a sentinel that start has not been
called.
General changes:
Convert SkScanlineDecoders to SkCodecs.
General changes in SkCodec subclasses:
Merge SkScanlineDecoder implementation into SkCodec. Most (all?) owned
an SkCodec, so they now call this-> instead of fCodec->.
SkBmpCodec.h/.cpp:
Replace the unused rowOrder method with an override for
onGetScanlineOrder.
Make getDstRow const, since it is called by onGetY, which is const.
SkCodec_libpng.h/.cpp:
Make SkPngCodec an abstract class, with two subclasses which handle
scanline decoding separately (they share code for decoding the entire
image). Reimplement onReallyHasAlpha so that it can return the most
recent result (e.g. after a scanline decode which only decoded part
of the image) or a better answer (e.g. if the whole image is known to
be opaque).
Compute fNumberPasses early, so we know which subclass to instantiate.
Make SkPngInterlaceScanlineDecoder use the base class' fCurrScanline
rather than a separate variable.
CodexTest.cpp:
Add tests for the state changes in SkCodec (need to call start before
decoding scanlines; calling getPixels means that start will need to
be called again before decoding more scanlines).
Add a test which decodes in stripes, currently only used for an
interlaced PNG.
TODO: Add tests for onReallyHasAlpha.
Review URL: https://codereview.chromium.org/1365313002
2015-09-30 15:57:13 +00:00
|
|
|
const SkCodec::Result startResult = codec->startScanlineDecode(decodeInfo, nullptr,
|
|
|
|
colorPtr, colorCountPtr);
|
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);
|
2015-10-09 18:07:34 +00:00
|
|
|
codec->getScanlines(bitmap.getAddr(0, startY), linesToRead, bitmap.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
|
|
|
}
|
|
|
|
}
|
|
|
|
canvas->drawBitmap(bitmap, 0, 0);
|
2015-06-22 17:40:21 +00:00
|
|
|
break;
|
2015-06-11 21:27:27 +00:00
|
|
|
}
|
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;
|
|
|
|
SkCodec::Options opts;
|
|
|
|
opts.fSubset = ⊂
|
|
|
|
SkBitmap subsetBm;
|
|
|
|
// We will reuse pixel memory from bitmap.
|
|
|
|
void* pixels = bitmap.getPixels();
|
|
|
|
// 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?
|
2015-10-09 18:07:34 +00:00
|
|
|
decodeInfo = decodeInfo.makeWH(
|
|
|
|
SkTMax(1, SkScalarRoundToInt(preScaleW * fScale)),
|
|
|
|
SkTMax(1, SkScalarRoundToInt(preScaleH * fScale)));
|
2015-07-22 14:16:20 +00:00
|
|
|
size_t rowBytes = decodeInfo.minRowBytes();
|
|
|
|
if (!subsetBm.installPixels(decodeInfo, pixels, rowBytes, colorTable.get(),
|
2015-08-27 14:41:13 +00:00
|
|
|
nullptr, nullptr)) {
|
2015-07-22 14:16:20 +00:00
|
|
|
return SkStringPrintf("could not install pixels for %s.", fPath.c_str());
|
|
|
|
}
|
|
|
|
const SkCodec::Result result = codec->getPixels(decodeInfo, pixels, rowBytes,
|
|
|
|
&opts, colorPtr, colorCountPtr);
|
|
|
|
switch (result) {
|
|
|
|
case SkCodec::kSuccess:
|
|
|
|
case SkCodec::kIncompleteInput:
|
|
|
|
break;
|
|
|
|
case SkCodec::kInvalidConversion:
|
|
|
|
if (0 == (x|y)) {
|
|
|
|
// First subset is okay to return unimplemented.
|
|
|
|
return Error::Nonfatal("Incompatible colortype conversion");
|
|
|
|
}
|
|
|
|
// If the first subset succeeded, a later one should not fail.
|
|
|
|
// fall through to failure
|
|
|
|
case SkCodec::kUnimplemented:
|
|
|
|
if (0 == (x|y)) {
|
|
|
|
// First subset is okay to return unimplemented.
|
|
|
|
return Error::Nonfatal("subset codec not supported");
|
|
|
|
}
|
|
|
|
// If the first subset succeeded, why would a later one fail?
|
|
|
|
// fall through to failure
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
canvas->drawBitmap(subsetBm, SkIntToScalar(left), SkIntToScalar(top));
|
|
|
|
// translate by the scaled height.
|
|
|
|
top += decodeInfo.height();
|
|
|
|
}
|
|
|
|
// translate by the scaled width.
|
|
|
|
left += decodeInfo.width();
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
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 {
|
|
|
|
SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
|
2015-10-21 17:27:10 +00:00
|
|
|
SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
|
2015-09-30 18:33:12 +00:00
|
|
|
if (nullptr == codec) {
|
|
|
|
return SkISize::Make(0, 0);
|
|
|
|
}
|
|
|
|
return codec->getScaledDimensions(fScale);
|
2015-03-19 13:03:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Name CodecSrc::name() const {
|
2015-06-11 21:27:27 +00:00
|
|
|
if (1.0f == fScale) {
|
|
|
|
return SkOSPath::Basename(fPath.c_str());
|
|
|
|
}
|
2015-09-08 22:35:32 +00:00
|
|
|
return get_scaled_name(fPath, fScale);
|
2015-03-19 13:03:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2015-10-21 17:27:10 +00:00
|
|
|
AndroidCodecSrc::AndroidCodecSrc(Path path, Mode mode, CodecSrc::DstColorType dstColorType,
|
|
|
|
int sampleSize)
|
|
|
|
: fPath(path)
|
|
|
|
, fMode(mode)
|
|
|
|
, fDstColorType(dstColorType)
|
|
|
|
, fSampleSize(sampleSize)
|
|
|
|
{}
|
|
|
|
|
|
|
|
bool AndroidCodecSrc::veto(SinkFlags flags) const {
|
|
|
|
// No need to test decoding to non-raster or indirect backend.
|
|
|
|
// TODO: Once we implement GPU paths (e.g. JPEG YUV), we should use a deferred decode to
|
|
|
|
// let the GPU handle it.
|
|
|
|
return flags.type != SinkFlags::kRaster
|
|
|
|
|| flags.approach != SinkFlags::kDirect;
|
|
|
|
}
|
|
|
|
|
|
|
|
Error AndroidCodecSrc::draw(SkCanvas* canvas) const {
|
|
|
|
SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
|
|
|
|
if (!encoded) {
|
|
|
|
return SkStringPrintf("Couldn't read %s.", fPath.c_str());
|
|
|
|
}
|
|
|
|
SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded));
|
|
|
|
if (nullptr == codec.get()) {
|
|
|
|
return SkStringPrintf("Couldn't create android codec for %s.", fPath.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
SkImageInfo decodeInfo;
|
|
|
|
if (!get_decode_info(&decodeInfo, codec->getInfo(), canvas->imageInfo().colorType(),
|
|
|
|
fDstColorType)) {
|
|
|
|
return Error::Nonfatal("Testing non-565 to 565 is uninteresting.");
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.");
|
|
|
|
}
|
|
|
|
decodeInfo = decodeInfo.makeWH(size.width(), size.height());
|
|
|
|
|
|
|
|
// Construct a color table for the decode if necessary
|
|
|
|
SkAutoTUnref<SkColorTable> colorTable(nullptr);
|
|
|
|
SkPMColor* colorPtr = nullptr;
|
|
|
|
int* colorCountPtr = nullptr;
|
|
|
|
int maxColors = 256;
|
|
|
|
if (kIndex_8_SkColorType == decodeInfo.colorType()) {
|
|
|
|
SkPMColor colors[256];
|
|
|
|
colorTable.reset(new SkColorTable(colors, maxColors));
|
|
|
|
colorPtr = const_cast<SkPMColor*>(colorTable->readColors());
|
|
|
|
colorCountPtr = &maxColors;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkBitmap bitmap;
|
|
|
|
if (!bitmap.tryAllocPixels(decodeInfo, nullptr, colorTable.get())) {
|
2015-12-09 21:02:26 +00:00
|
|
|
return SkStringPrintf("Image(%s) is too large (%d x %d)", fPath.c_str(),
|
2015-10-21 17:27:10 +00:00
|
|
|
decodeInfo.width(), decodeInfo.height());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create options for the codec.
|
|
|
|
SkAndroidCodec::AndroidOptions options;
|
|
|
|
options.fColorPtr = colorPtr;
|
|
|
|
options.fColorCount = colorCountPtr;
|
|
|
|
options.fSampleSize = fSampleSize;
|
|
|
|
|
|
|
|
switch (fMode) {
|
|
|
|
case kFullImage_Mode: {
|
|
|
|
switch (codec->getAndroidPixels(decodeInfo, bitmap.getPixels(), bitmap.rowBytes(),
|
|
|
|
&options)) {
|
|
|
|
case SkCodec::kSuccess:
|
|
|
|
case SkCodec::kIncompleteInput:
|
|
|
|
break;
|
|
|
|
case SkCodec::kInvalidConversion:
|
2015-12-09 21:02:26 +00:00
|
|
|
return Error::Nonfatal("Cannot convert to requested color type.");
|
2015-10-21 17:27:10 +00:00
|
|
|
default:
|
|
|
|
return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str());
|
|
|
|
}
|
|
|
|
canvas->drawBitmap(bitmap, 0, 0);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
case kDivisor_Mode: {
|
|
|
|
const int width = codec->getInfo().width();
|
|
|
|
const int height = codec->getInfo().height();
|
|
|
|
const int 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-10-21 17:27:10 +00:00
|
|
|
}
|
|
|
|
|
2015-10-21 20:26:59 +00:00
|
|
|
// Keep track of the final decoded dimensions.
|
|
|
|
int finalScaledWidth = 0;
|
|
|
|
int finalScaledHeight = 0;
|
2015-10-21 17:27:10 +00:00
|
|
|
for (int x = 0; x < divisor; x++) {
|
|
|
|
for (int y = 0; y < divisor; y++) {
|
|
|
|
// Calculate the subset dimensions
|
|
|
|
int subsetWidth = width / divisor;
|
|
|
|
int 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;
|
|
|
|
SkIRect subset = SkIRect::MakeXYWH(left, top, subsetWidth, subsetHeight);
|
|
|
|
if (!codec->getSupportedSubset(&subset)) {
|
2015-12-09 21:02:26 +00:00
|
|
|
return "Could not get supported subset to decode.";
|
2015-10-21 17:27:10 +00:00
|
|
|
}
|
|
|
|
options.fSubset = ⊂
|
2015-10-21 20:26:59 +00:00
|
|
|
const int scaledWidthOffset = subset.left() / fSampleSize;
|
|
|
|
const int scaledHeightOffset = subset.top() / fSampleSize;
|
|
|
|
void* pixels = bitmap.getAddr(scaledWidthOffset, scaledHeightOffset);
|
2015-10-21 17:27:10 +00:00
|
|
|
SkISize scaledSubsetSize = codec->getSampledSubsetDimensions(fSampleSize,
|
|
|
|
subset);
|
|
|
|
SkImageInfo subsetDecodeInfo = decodeInfo.makeWH(scaledSubsetSize.width(),
|
|
|
|
scaledSubsetSize.height());
|
|
|
|
|
2015-10-21 20:26:59 +00:00
|
|
|
if (x + 1 == divisor && y + 1 == divisor) {
|
|
|
|
finalScaledWidth = scaledWidthOffset + scaledSubsetSize.width();
|
|
|
|
finalScaledHeight = scaledHeightOffset + scaledSubsetSize.height();
|
|
|
|
}
|
|
|
|
|
2015-10-21 17:27:10 +00:00
|
|
|
switch (codec->getAndroidPixels(subsetDecodeInfo, pixels, bitmap.rowBytes(),
|
|
|
|
&options)) {
|
|
|
|
case SkCodec::kSuccess:
|
|
|
|
case SkCodec::kIncompleteInput:
|
|
|
|
break;
|
|
|
|
case SkCodec::kInvalidConversion:
|
2015-12-09 21:02:26 +00:00
|
|
|
return Error::Nonfatal("Cannot convert to requested color type.");
|
2015-10-21 17:27:10 +00:00
|
|
|
default:
|
|
|
|
return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-21 20:26:59 +00:00
|
|
|
|
|
|
|
SkRect rect = SkRect::MakeXYWH(0, 0, (SkScalar) finalScaledWidth,
|
|
|
|
(SkScalar) finalScaledHeight);
|
|
|
|
canvas->drawBitmapRect(bitmap, rect, rect, nullptr);
|
2015-10-21 17:27:10 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
SkASSERT(false);
|
2015-12-09 21:02:26 +00:00
|
|
|
return "Error: Should not be reached.";
|
2015-10-21 17:27:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize AndroidCodecSrc::size() const {
|
|
|
|
SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
|
|
|
|
SkAutoTDelete<SkAndroidCodec> codec(SkAndroidCodec::NewFromData(encoded));
|
|
|
|
if (nullptr == codec) {
|
|
|
|
return SkISize::Make(0, 0);
|
|
|
|
}
|
|
|
|
return codec->getSampledDimensions(fSampleSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
Name AndroidCodecSrc::name() const {
|
|
|
|
// We will replicate the names used by CodecSrc so that images can
|
|
|
|
// be compared in Gold.
|
|
|
|
if (1 == fSampleSize) {
|
|
|
|
return SkOSPath::Basename(fPath.c_str());
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2015-11-10 23:09:03 +00:00
|
|
|
ImageSrc::ImageSrc(Path path) : fPath(path) {}
|
2015-01-15 18:56:12 +00:00
|
|
|
|
2015-07-31 13:43:04 +00:00
|
|
|
bool ImageSrc::veto(SinkFlags flags) const {
|
|
|
|
// No need to test decoding to non-raster or indirect backend.
|
2015-07-29 13:37:28 +00:00
|
|
|
// TODO: Instead, use lazy decoding to allow the GPU to handle cases like YUV.
|
2015-07-31 13:43:04 +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
|
|
|
|
2015-07-29 13:37:28 +00:00
|
|
|
Error ImageSrc::draw(SkCanvas* canvas) const {
|
2015-01-18 15:05:01 +00:00
|
|
|
SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
|
2015-01-15 18:56:12 +00:00
|
|
|
if (!encoded) {
|
|
|
|
return SkStringPrintf("Couldn't read %s.", fPath.c_str());
|
|
|
|
}
|
2015-07-29 13:37:28 +00:00
|
|
|
const SkColorType dstColorType = canvas->imageInfo().colorType();
|
2015-03-05 19:46:40 +00:00
|
|
|
|
2015-11-10 23:09:03 +00:00
|
|
|
// Decode the full image.
|
|
|
|
SkBitmap bitmap;
|
|
|
|
if (!SkImageDecoder::DecodeMemory(encoded->data(), encoded->size(), &bitmap,
|
|
|
|
dstColorType, SkImageDecoder::kDecodePixels_Mode)) {
|
|
|
|
return SkStringPrintf("Couldn't decode %s.", fPath.c_str());
|
|
|
|
}
|
|
|
|
if (kRGB_565_SkColorType == dstColorType && !bitmap.isOpaque()) {
|
|
|
|
// Do not draw a bitmap with alpha to a destination without alpha.
|
|
|
|
return Error::Nonfatal("Uninteresting to decode image with alpha into 565.");
|
2015-01-15 18:56:12 +00:00
|
|
|
}
|
2015-11-10 23:09:03 +00:00
|
|
|
encoded.reset((SkData*)nullptr); // Might as well drop this when we're done with it.
|
|
|
|
canvas->drawBitmap(bitmap, 0,0);
|
2015-01-15 18:56:12 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize ImageSrc::size() const {
|
2015-01-18 15:05:01 +00:00
|
|
|
SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
|
2015-03-19 13:03:39 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
if (!encoded || !SkImageDecoder::DecodeMemory(encoded->data(),
|
|
|
|
encoded->size(),
|
|
|
|
&bitmap,
|
|
|
|
kUnknown_SkColorType,
|
|
|
|
SkImageDecoder::kDecodeBounds_Mode)) {
|
|
|
|
return SkISize::Make(0,0);
|
2015-01-15 18:56:12 +00:00
|
|
|
}
|
2015-03-19 13:03:39 +00:00
|
|
|
return bitmap.dimensions();
|
2015-01-15 18:56:12 +00:00
|
|
|
}
|
|
|
|
|
2015-01-20 18:11:53 +00:00
|
|
|
Name ImageSrc::name() const {
|
2015-01-30 21:22:23 +00:00
|
|
|
return SkOSPath::Basename(fPath.c_str());
|
2015-01-20 18:11:53 +00:00
|
|
|
}
|
2015-01-15 18:56:12 +00:00
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2015-01-28 23:32:24 +00:00
|
|
|
static const SkRect kSKPViewport = {0,0, 1000,1000};
|
|
|
|
|
2015-01-30 19:42:31 +00:00
|
|
|
SKPSrc::SKPSrc(Path path) : fPath(path) {}
|
2015-01-15 18:56:12 +00:00
|
|
|
|
|
|
|
Error SKPSrc::draw(SkCanvas* canvas) const {
|
2015-01-21 20:09:53 +00:00
|
|
|
SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str()));
|
2015-01-18 15:05:01 +00:00
|
|
|
if (!stream) {
|
2015-01-15 18:56:12 +00:00
|
|
|
return SkStringPrintf("Couldn't read %s.", fPath.c_str());
|
|
|
|
}
|
2015-03-25 20:13:43 +00:00
|
|
|
SkAutoTUnref<SkPicture> pic(SkPicture::CreateFromStream(stream, &lazy_decode_bitmap));
|
2015-01-18 15:05:01 +00:00
|
|
|
if (!pic) {
|
|
|
|
return SkStringPrintf("Couldn't decode %s as a picture.", fPath.c_str());
|
|
|
|
}
|
2015-08-27 14:41:13 +00:00
|
|
|
stream.reset((SkStream*)nullptr); // Might as well drop this when we're done with it.
|
2015-03-31 20:32:05 +00:00
|
|
|
|
2015-01-28 23:32:24 +00:00
|
|
|
canvas->clipRect(kSKPViewport);
|
2015-01-15 18:56:12 +00:00
|
|
|
canvas->drawPicture(pic);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
SkISize SKPSrc::size() const {
|
2015-03-16 17:38:07 +00:00
|
|
|
SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(fPath.c_str()));
|
|
|
|
if (!stream) {
|
|
|
|
return SkISize::Make(0,0);
|
|
|
|
}
|
|
|
|
SkPictInfo info;
|
|
|
|
if (!SkPicture::InternalOnly_StreamIsSKP(stream, &info)) {
|
|
|
|
return SkISize::Make(0,0);
|
|
|
|
}
|
|
|
|
SkRect viewport = kSKPViewport;
|
|
|
|
if (!viewport.intersect(info.fCullRect)) {
|
|
|
|
return SkISize::Make(0,0);
|
|
|
|
}
|
|
|
|
return viewport.roundOut().size();
|
2015-01-15 18:56:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Name SKPSrc::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 {
|
|
|
|
SkAutoTDelete<SkCanvas> canvas(SkCreateNullCanvas());
|
|
|
|
return src.draw(canvas);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2015-02-03 02:26:03 +00:00
|
|
|
DEFINE_bool(gpuStats, false, "Append GPU stats to the log for each GPU task?");
|
|
|
|
|
2015-01-15 20:46:02 +00:00
|
|
|
GPUSink::GPUSink(GrContextFactory::GLContextType ct,
|
2015-12-10 14:28:13 +00:00
|
|
|
GrContextFactory::GLContextOptions options,
|
Revert of Add config options to run different GPU APIs to dm and nanobench (patchset #21 id:400001 of https://codereview.chromium.org/1490113005/ )
Reason for revert:
The Test-Win8-MSVC-ShuttleB-GPU-HD4600-x86_64-Debug builder fails after this CL.
Links to specific builds:
http://build.chromium.org/p/client.skia/builders/Test-Win8-MSVC-ShuttleB-GPU-HD4600-x86_64-Debug/builds/1689
http://build.chromium.org/p/client.skia/builders/Test-Win8-MSVC-ShuttleB-GPU-HD4600-x86_64-Debug/builds/1690
http://build.chromium.org/p/client.skia/builders/Test-Win8-MSVC-ShuttleB-GPU-HD4600-x86_64-Debug/builds/1691
Original issue's description:
> Add config options to run different GPU APIs to dm and nanobench
>
> Add extended config specification form that can be used to run different
> gpu backend with different APIs.
>
> The configs can be specified with the form:
> gpu(api=string,dit=bool,nvpr=bool,samples=int)
>
> This replaces and removes the --gpuAPI flag.
>
> All existing configs should still work.
>
> Adds following documentation:
>
> out/Debug/dm --help config
>
> Flags:
> --config: type: string default: 565 8888 gpu nonrendering
> Options: 565 8888 debug gpu gpudebug gpudft gpunull msaa16 msaa4
> nonrendering null nullgpu nvprmsaa16 nvprmsaa4 pdf pdf_poppler skp svg
> xps or use extended form 'backend(option=value,...)'.
>
> Extended form: 'backend(option=value,...)'
>
> Possible backends and options:
>
> gpu(api=string,dit=bool,nvpr=bool,samples=int) GPU backend
> api type: string default: native.
> Select graphics API to use with gpu backend.
> Options:
> native Use platform default OpenGL or OpenGL ES backend.
> gl Use OpenGL.
> gles Use OpenGL ES.
> debug Use debug OpenGL.
> null Use null OpenGL.
> dit type: bool default: false.
> Use device independent text.
> nvpr type: bool default: false.
> Use NV_path_rendering OpenGL and OpenGL ES extension.
> samples type: int default: 0.
> Use multisampling with N samples.
>
> Predefined configs:
>
> gpu = gpu()
> msaa4 = gpu(samples=4)
> msaa16 = gpu(samples=16)
> nvprmsaa4 = gpu(nvpr=true,samples=4)
> nvprmsaa16 = gpu(nvpr=true,samples=16)
> gpudft = gpu(dit=true)
> gpudebug = gpu(api=debug)
> gpunull = gpu(api=null)
> debug = gpu(api=debug)
> nullgpu = gpu(api=null)
>
> BUG=skia:2992
>
> Committed: https://skia.googlesource.com/skia/+/e13ca329fca4c28cf4e078561f591ab27b743d23
> GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1490113005
>
> Committed: https://skia.googlesource.com/skia/+/c8b4336444e7b90382e04e33665fb3b8490b825b
>
> Committed: https://skia.googlesource.com/skia/+/9ebc3f0ee6db215dde461dc4777d85988cf272dd
TBR=mtklein@google.com,bsalomon@google.com,joshualitt@google.com,scroggo@google.com,kkinnunen@nvidia.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:2992
Review URL: https://codereview.chromium.org/1548683002
2015-12-22 18:22:26 +00:00
|
|
|
GrGLStandard gpuAPI,
|
2015-01-15 20:46:02 +00:00
|
|
|
int samples,
|
2015-08-31 19:39:41 +00:00
|
|
|
bool diText,
|
2015-01-15 20:46:02 +00:00
|
|
|
bool threaded)
|
2015-01-15 18:56:12 +00:00
|
|
|
: fContextType(ct)
|
2015-12-10 14:28:13 +00:00
|
|
|
, fContextOptions(options)
|
Revert of Add config options to run different GPU APIs to dm and nanobench (patchset #21 id:400001 of https://codereview.chromium.org/1490113005/ )
Reason for revert:
The Test-Win8-MSVC-ShuttleB-GPU-HD4600-x86_64-Debug builder fails after this CL.
Links to specific builds:
http://build.chromium.org/p/client.skia/builders/Test-Win8-MSVC-ShuttleB-GPU-HD4600-x86_64-Debug/builds/1689
http://build.chromium.org/p/client.skia/builders/Test-Win8-MSVC-ShuttleB-GPU-HD4600-x86_64-Debug/builds/1690
http://build.chromium.org/p/client.skia/builders/Test-Win8-MSVC-ShuttleB-GPU-HD4600-x86_64-Debug/builds/1691
Original issue's description:
> Add config options to run different GPU APIs to dm and nanobench
>
> Add extended config specification form that can be used to run different
> gpu backend with different APIs.
>
> The configs can be specified with the form:
> gpu(api=string,dit=bool,nvpr=bool,samples=int)
>
> This replaces and removes the --gpuAPI flag.
>
> All existing configs should still work.
>
> Adds following documentation:
>
> out/Debug/dm --help config
>
> Flags:
> --config: type: string default: 565 8888 gpu nonrendering
> Options: 565 8888 debug gpu gpudebug gpudft gpunull msaa16 msaa4
> nonrendering null nullgpu nvprmsaa16 nvprmsaa4 pdf pdf_poppler skp svg
> xps or use extended form 'backend(option=value,...)'.
>
> Extended form: 'backend(option=value,...)'
>
> Possible backends and options:
>
> gpu(api=string,dit=bool,nvpr=bool,samples=int) GPU backend
> api type: string default: native.
> Select graphics API to use with gpu backend.
> Options:
> native Use platform default OpenGL or OpenGL ES backend.
> gl Use OpenGL.
> gles Use OpenGL ES.
> debug Use debug OpenGL.
> null Use null OpenGL.
> dit type: bool default: false.
> Use device independent text.
> nvpr type: bool default: false.
> Use NV_path_rendering OpenGL and OpenGL ES extension.
> samples type: int default: 0.
> Use multisampling with N samples.
>
> Predefined configs:
>
> gpu = gpu()
> msaa4 = gpu(samples=4)
> msaa16 = gpu(samples=16)
> nvprmsaa4 = gpu(nvpr=true,samples=4)
> nvprmsaa16 = gpu(nvpr=true,samples=16)
> gpudft = gpu(dit=true)
> gpudebug = gpu(api=debug)
> gpunull = gpu(api=null)
> debug = gpu(api=debug)
> nullgpu = gpu(api=null)
>
> BUG=skia:2992
>
> Committed: https://skia.googlesource.com/skia/+/e13ca329fca4c28cf4e078561f591ab27b743d23
> GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1490113005
>
> Committed: https://skia.googlesource.com/skia/+/c8b4336444e7b90382e04e33665fb3b8490b825b
>
> Committed: https://skia.googlesource.com/skia/+/9ebc3f0ee6db215dde461dc4777d85988cf272dd
TBR=mtklein@google.com,bsalomon@google.com,joshualitt@google.com,scroggo@google.com,kkinnunen@nvidia.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:2992
Review URL: https://codereview.chromium.org/1548683002
2015-12-22 18:22:26 +00:00
|
|
|
, fGpuAPI(gpuAPI)
|
2015-01-15 18:56:12 +00:00
|
|
|
, fSampleCount(samples)
|
2015-08-31 19:39:41 +00:00
|
|
|
, fUseDIText(diText)
|
2015-01-15 20:46:02 +00:00
|
|
|
, fThreaded(threaded) {}
|
2015-01-15 18:56:12 +00:00
|
|
|
|
|
|
|
int GPUSink::enclave() const {
|
2015-01-21 23:50:13 +00:00
|
|
|
return fThreaded ? kAnyThread_Enclave : kGPU_Enclave;
|
2015-01-15 18:56:12 +00:00
|
|
|
}
|
|
|
|
|
2015-02-25 22:09:45 +00:00
|
|
|
void PreAbandonGpuContextErrorHandler(SkError, void*) {}
|
|
|
|
|
2015-10-23 16:06:59 +00:00
|
|
|
DEFINE_bool(imm, false, "Run gpu configs in immediate mode.");
|
2015-11-30 21:27:47 +00:00
|
|
|
DEFINE_bool(batchClip, false, "Clip each GrBatch to its device bounds for testing.");
|
2015-12-03 20:58:06 +00:00
|
|
|
DEFINE_bool(batchBounds, false, "Draw a wireframe bounds of each GrBatch.");
|
2015-12-14 20:13:09 +00:00
|
|
|
DEFINE_int32(batchLookback, -1, "Maximum GrBatch lookback for combining, negative means default.");
|
2015-10-23 16:06:59 +00:00
|
|
|
|
2015-02-03 02:26:03 +00:00
|
|
|
Error GPUSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log) const {
|
2015-12-10 14:28:13 +00:00
|
|
|
GrContextOptions grOptions;
|
2015-12-14 20:13:09 +00:00
|
|
|
grOptions.fImmediateMode = FLAGS_imm;
|
|
|
|
grOptions.fClipBatchToBounds = FLAGS_batchClip;
|
|
|
|
grOptions.fDrawBatchBounds = FLAGS_batchBounds;
|
|
|
|
grOptions.fMaxBatchLookback = FLAGS_batchLookback;
|
2015-12-10 14:28:13 +00:00
|
|
|
|
|
|
|
src.modifyGrContextOptions(&grOptions);
|
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();
|
2015-01-15 18:56:12 +00:00
|
|
|
const SkImageInfo info =
|
|
|
|
SkImageInfo::Make(size.width(), size.height(), kN32_SkColorType, kPremul_SkAlphaType);
|
|
|
|
SkAutoTUnref<SkSurface> surface(
|
Revert of Add config options to run different GPU APIs to dm and nanobench (patchset #21 id:400001 of https://codereview.chromium.org/1490113005/ )
Reason for revert:
The Test-Win8-MSVC-ShuttleB-GPU-HD4600-x86_64-Debug builder fails after this CL.
Links to specific builds:
http://build.chromium.org/p/client.skia/builders/Test-Win8-MSVC-ShuttleB-GPU-HD4600-x86_64-Debug/builds/1689
http://build.chromium.org/p/client.skia/builders/Test-Win8-MSVC-ShuttleB-GPU-HD4600-x86_64-Debug/builds/1690
http://build.chromium.org/p/client.skia/builders/Test-Win8-MSVC-ShuttleB-GPU-HD4600-x86_64-Debug/builds/1691
Original issue's description:
> Add config options to run different GPU APIs to dm and nanobench
>
> Add extended config specification form that can be used to run different
> gpu backend with different APIs.
>
> The configs can be specified with the form:
> gpu(api=string,dit=bool,nvpr=bool,samples=int)
>
> This replaces and removes the --gpuAPI flag.
>
> All existing configs should still work.
>
> Adds following documentation:
>
> out/Debug/dm --help config
>
> Flags:
> --config: type: string default: 565 8888 gpu nonrendering
> Options: 565 8888 debug gpu gpudebug gpudft gpunull msaa16 msaa4
> nonrendering null nullgpu nvprmsaa16 nvprmsaa4 pdf pdf_poppler skp svg
> xps or use extended form 'backend(option=value,...)'.
>
> Extended form: 'backend(option=value,...)'
>
> Possible backends and options:
>
> gpu(api=string,dit=bool,nvpr=bool,samples=int) GPU backend
> api type: string default: native.
> Select graphics API to use with gpu backend.
> Options:
> native Use platform default OpenGL or OpenGL ES backend.
> gl Use OpenGL.
> gles Use OpenGL ES.
> debug Use debug OpenGL.
> null Use null OpenGL.
> dit type: bool default: false.
> Use device independent text.
> nvpr type: bool default: false.
> Use NV_path_rendering OpenGL and OpenGL ES extension.
> samples type: int default: 0.
> Use multisampling with N samples.
>
> Predefined configs:
>
> gpu = gpu()
> msaa4 = gpu(samples=4)
> msaa16 = gpu(samples=16)
> nvprmsaa4 = gpu(nvpr=true,samples=4)
> nvprmsaa16 = gpu(nvpr=true,samples=16)
> gpudft = gpu(dit=true)
> gpudebug = gpu(api=debug)
> gpunull = gpu(api=null)
> debug = gpu(api=debug)
> nullgpu = gpu(api=null)
>
> BUG=skia:2992
>
> Committed: https://skia.googlesource.com/skia/+/e13ca329fca4c28cf4e078561f591ab27b743d23
> GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1490113005
>
> Committed: https://skia.googlesource.com/skia/+/c8b4336444e7b90382e04e33665fb3b8490b825b
>
> Committed: https://skia.googlesource.com/skia/+/9ebc3f0ee6db215dde461dc4777d85988cf272dd
TBR=mtklein@google.com,bsalomon@google.com,joshualitt@google.com,scroggo@google.com,kkinnunen@nvidia.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:2992
Review URL: https://codereview.chromium.org/1548683002
2015-12-22 18:22:26 +00:00
|
|
|
NewGpuSurface(&factory, fContextType, fContextOptions, fGpuAPI, info, fSampleCount,
|
|
|
|
fUseDIText));
|
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) {
|
2015-08-27 14:41:13 +00:00
|
|
|
SkSetErrorCallback(&PreAbandonGpuContextErrorHandler, nullptr);
|
2015-02-25 22:09:45 +00:00
|
|
|
factory.abandonContexts();
|
|
|
|
}
|
2015-01-15 18:56:12 +00:00
|
|
|
SkCanvas* canvas = surface->getCanvas();
|
|
|
|
Error err = src.draw(canvas);
|
|
|
|
if (!err.isEmpty()) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
canvas->flush();
|
2015-02-03 02:26:03 +00:00
|
|
|
if (FLAGS_gpuStats) {
|
|
|
|
canvas->getGrContext()->dumpCacheStats(log);
|
|
|
|
canvas->getGrContext()->dumpGpuStats(log);
|
|
|
|
}
|
2015-01-15 18:56:12 +00:00
|
|
|
dst->allocPixels(info);
|
2015-02-25 22:09:45 +00:00
|
|
|
canvas->readPixels(dst, 0, 0);
|
2015-01-21 23:50:13 +00:00
|
|
|
if (FLAGS_abandonGpuContext) {
|
|
|
|
factory.abandonContexts();
|
|
|
|
}
|
2015-01-15 18:56:12 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2015-03-03 17:13:09 +00:00
|
|
|
static Error draw_skdocument(const Src& src, SkDocument* doc, SkWStream* dst) {
|
|
|
|
// Print the given DM:Src to a document, breaking on 8.5x11 pages.
|
|
|
|
SkASSERT(doc);
|
2015-01-28 19:45:58 +00:00
|
|
|
int width = src.size().width(),
|
|
|
|
height = src.size().height();
|
|
|
|
|
2015-04-14 21:06:18 +00:00
|
|
|
if (FLAGS_multiPage) {
|
|
|
|
const int kLetterWidth = 612, // 8.5 * 72
|
|
|
|
kLetterHeight = 792; // 11 * 72
|
|
|
|
const SkRect letter = SkRect::MakeWH(SkIntToScalar(kLetterWidth),
|
|
|
|
SkIntToScalar(kLetterHeight));
|
|
|
|
|
|
|
|
int xPages = ((width - 1) / kLetterWidth) + 1;
|
|
|
|
int yPages = ((height - 1) / kLetterHeight) + 1;
|
|
|
|
|
|
|
|
for (int y = 0; y < yPages; ++y) {
|
|
|
|
for (int x = 0; x < xPages; ++x) {
|
|
|
|
int w = SkTMin(kLetterWidth, width - (x * kLetterWidth));
|
|
|
|
int h = SkTMin(kLetterHeight, height - (y * kLetterHeight));
|
|
|
|
SkCanvas* canvas =
|
|
|
|
doc->beginPage(SkIntToScalar(w), SkIntToScalar(h));
|
|
|
|
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
|
|
|
}
|
|
|
|
canvas->clipRect(letter);
|
|
|
|
canvas->translate(-letter.width() * x, -letter.height() * y);
|
|
|
|
Error err = src.draw(canvas);
|
|
|
|
if (!err.isEmpty()) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
doc->endPage();
|
2015-01-28 19:45:58 +00:00
|
|
|
}
|
|
|
|
}
|
2015-04-14 21:06:18 +00:00
|
|
|
} else {
|
|
|
|
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
|
|
|
}
|
|
|
|
Error err = src.draw(canvas);
|
|
|
|
if (!err.isEmpty()) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
doc->endPage();
|
|
|
|
}
|
|
|
|
if (!doc->close()) {
|
|
|
|
return "SkDocument::close() returned false";
|
2015-01-15 18:56:12 +00:00
|
|
|
}
|
2015-01-28 19:45:58 +00:00
|
|
|
dst->flush();
|
2015-01-15 18:56:12 +00:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2015-09-28 18:51:54 +00:00
|
|
|
PDFSink::PDFSink(const char* rasterizer) : fRasterizer(rasterizer) {}
|
2015-03-03 17:13:09 +00:00
|
|
|
|
|
|
|
Error PDFSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
|
|
|
|
SkAutoTUnref<SkDocument> doc(SkDocument::CreatePDF(dst));
|
|
|
|
if (!doc) {
|
2015-08-27 14:41:13 +00:00
|
|
|
return "SkDocument::CreatePDF() returned nullptr";
|
2015-03-03 17:13:09 +00:00
|
|
|
}
|
2015-09-23 19:45:49 +00:00
|
|
|
SkTArray<SkDocument::Attribute> info;
|
|
|
|
info.emplace_back(SkString("Title"), src.name());
|
|
|
|
info.emplace_back(SkString("Subject"),
|
|
|
|
SkString("rendering correctness test"));
|
|
|
|
info.emplace_back(SkString("Creator"), SkString("Skia/DM"));
|
2015-09-28 18:51:54 +00:00
|
|
|
|
|
|
|
info.emplace_back(SkString("Keywords"),
|
|
|
|
SkStringPrintf("Rasterizer:%s;", fRasterizer));
|
2015-09-23 19:45:49 +00:00
|
|
|
doc->setMetadata(info, nullptr, nullptr);
|
2015-03-03 17:13:09 +00:00
|
|
|
return draw_skdocument(src, doc.get(), dst);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
|
|
|
XPSSink::XPSSink() {}
|
|
|
|
|
|
|
|
Error XPSSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
|
|
|
|
SkAutoTUnref<SkDocument> doc(SkDocument::CreateXPS(dst));
|
|
|
|
if (!doc) {
|
2015-08-27 14:41:13 +00:00
|
|
|
return "SkDocument::CreateXPS() returned nullptr";
|
2015-03-03 17:13:09 +00:00
|
|
|
}
|
|
|
|
return draw_skdocument(src, doc.get(), dst);
|
|
|
|
}
|
2015-01-15 18:56:12 +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;
|
|
|
|
}
|
|
|
|
SkAutoTUnref<SkPicture> pic(recorder.endRecording());
|
|
|
|
pic->serialize(dst);
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2015-02-01 04:00:58 +00:00
|
|
|
SVGSink::SVGSink() {}
|
|
|
|
|
2015-02-03 02:26:03 +00:00
|
|
|
Error SVGSink::draw(const Src& src, SkBitmap*, SkWStream* dst, SkString*) const {
|
2015-08-26 20:07:48 +00:00
|
|
|
SkAutoTDelete<SkXMLWriter> xmlWriter(new SkXMLStreamWriter(dst));
|
2015-02-06 20:51:10 +00:00
|
|
|
SkAutoTUnref<SkCanvas> canvas(SkSVGCanvas::Create(
|
|
|
|
SkRect::MakeWH(SkIntToScalar(src.size().width()), SkIntToScalar(src.size().height())),
|
|
|
|
xmlWriter));
|
|
|
|
return src.draw(canvas);
|
2015-02-01 04:00:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
RasterSink::RasterSink(SkColorType colorType) : fColorType(colorType) {}
|
|
|
|
|
2015-02-03 02:26:03 +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);
|
|
|
|
|
|
|
|
dst->allocPixels(SkImageInfo::Make(size.width(), size.height(), fColorType, alphaType));
|
|
|
|
dst->eraseColor(SK_ColorTRANSPARENT);
|
|
|
|
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.
|
|
|
|
|
2015-12-10 23:14:27 +00:00
|
|
|
static Error draw_to_canvas(Sink* sink, SkBitmap* bitmap, SkWStream* stream, SkString* log,
|
2015-11-12 18:41:05 +00:00
|
|
|
SkISize size, std::function<Error(SkCanvas*)> draw) {
|
2015-05-05 18:38:45 +00:00
|
|
|
class ProxySrc : public Src {
|
|
|
|
public:
|
2015-12-10 23:14:27 +00:00
|
|
|
ProxySrc(SkISize size, std::function<Error(SkCanvas*)> draw) : fSize(size), fDraw(draw) {}
|
2015-05-05 18:38:45 +00:00
|
|
|
Error draw(SkCanvas* canvas) const override { return fDraw(canvas); }
|
2015-12-10 23:14:27 +00:00
|
|
|
Name name() const override { sk_throw(); return ""; } // Won't be called.
|
2015-05-05 18:38:45 +00:00
|
|
|
SkISize size() const override { return fSize; }
|
|
|
|
private:
|
2015-11-12 18:41:05 +00:00
|
|
|
SkISize fSize;
|
|
|
|
std::function<Error(SkCanvas*)> 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
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
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());
|
|
|
|
return SkISize::Make(SkScalarRoundToInt(bounds.width()), SkScalarRoundToInt(bounds.height()));
|
|
|
|
}
|
|
|
|
|
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());
|
2015-12-10 23:14:27 +00:00
|
|
|
return draw_to_canvas(fSink, 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());
|
|
|
|
uprighted.allocPixels(bitmap->info().makeWH(size.width(), size.height()));
|
|
|
|
|
|
|
|
SkCanvas canvas(uprighted);
|
|
|
|
canvas.concat(upright);
|
|
|
|
SkPaint paint;
|
|
|
|
paint.setXfermodeMode(SkXfermode::kSrc_Mode);
|
|
|
|
canvas.drawBitmap(*bitmap, 0, 0, &paint);
|
|
|
|
|
|
|
|
*bitmap = uprighted;
|
|
|
|
bitmap->lockPixels();
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2015-02-03 02:26:03 +00:00
|
|
|
Error ViaPipe::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
|
2015-05-05 18:38:45 +00:00
|
|
|
auto size = src.size();
|
2015-12-10 23:14:27 +00:00
|
|
|
return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) {
|
2015-05-05 18:38:45 +00:00
|
|
|
PipeController controller(canvas, &SkImageDecoder::DecodeMemory);
|
|
|
|
SkGPipeWriter pipe;
|
2015-08-19 15:18:04 +00:00
|
|
|
const uint32_t kFlags = 0;
|
2015-05-05 18:38:45 +00:00
|
|
|
return src.draw(pipe.startRecording(&controller, kFlags, size.width(), size.height()));
|
|
|
|
});
|
2015-01-15 18:56:12 +00:00
|
|
|
}
|
|
|
|
|
2015-10-16 17:29:41 +00:00
|
|
|
Error ViaRemote::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
|
2015-12-10 23:14:27 +00:00
|
|
|
return draw_to_canvas(fSink, bitmap, stream, log, src.size(), [&](SkCanvas* target) {
|
2015-10-21 19:34:01 +00:00
|
|
|
SkAutoTDelete<SkRemote::Encoder> decoder(SkRemote::NewDecoder(target));
|
|
|
|
SkAutoTDelete<SkRemote::Encoder> cache(fCache ? SkRemote::NewCachingEncoder(decoder)
|
|
|
|
: nullptr);
|
|
|
|
SkAutoTDelete<SkCanvas> canvas(SkRemote::NewCanvas(cache ? cache : decoder));
|
|
|
|
return src.draw(canvas);
|
2015-10-16 17:29:41 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-05-05 15:11:33 +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;
|
|
|
|
}
|
|
|
|
SkAutoTUnref<SkPicture> pic(recorder.endRecording());
|
|
|
|
|
|
|
|
// Serialize it and then deserialize it.
|
|
|
|
SkDynamicMemoryWStream wStream;
|
|
|
|
pic->serialize(&wStream);
|
2015-01-21 20:09:53 +00:00
|
|
|
SkAutoTDelete<SkStream> rStream(wStream.detachAsStream());
|
2015-03-25 20:13:43 +00:00
|
|
|
SkAutoTUnref<SkPicture> deserialized(SkPicture::CreateFromStream(rStream, &lazy_decode_bitmap));
|
2015-01-15 18:56:12 +00:00
|
|
|
|
2015-12-10 23:14:27 +00:00
|
|
|
return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) {
|
2015-05-05 18:38:45 +00:00
|
|
|
canvas->drawPicture(deserialized);
|
|
|
|
return "";
|
|
|
|
});
|
2015-01-15 18:56:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2015-12-10 23:14:27 +00:00
|
|
|
ViaTiles::ViaTiles(int w, int h, SkBBHFactory* factory, Sink* sink)
|
|
|
|
: Via(sink)
|
2015-05-06 14:54:07 +00:00
|
|
|
, fW(w)
|
2015-01-15 18:56:12 +00:00
|
|
|
, fH(h)
|
2015-05-06 14:54:07 +00:00
|
|
|
, fFactory(factory) {}
|
2015-01-15 18:56:12 +00:00
|
|
|
|
2015-02-03 02:26:03 +00:00
|
|
|
Error ViaTiles::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
|
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()),
|
|
|
|
fFactory.get()));
|
2015-01-15 18:56:12 +00:00
|
|
|
if (!err.isEmpty()) {
|
|
|
|
return err;
|
|
|
|
}
|
2015-04-07 15:30:32 +00:00
|
|
|
SkAutoTUnref<SkPicture> pic(recorder.endRecordingAsPicture());
|
2015-01-15 18:56:12 +00:00
|
|
|
|
2015-12-10 23:14:27 +00:00
|
|
|
return draw_to_canvas(fSink, bitmap, stream, log, src.size(), [&](SkCanvas* canvas) {
|
2015-05-05 18:38:45 +00:00
|
|
|
const int xTiles = (size.width() + fW - 1) / fW,
|
|
|
|
yTiles = (size.height() + fH - 1) / fH;
|
|
|
|
SkMultiPictureDraw mpd(xTiles*yTiles);
|
|
|
|
SkTDArray<SkSurface*> surfaces;
|
|
|
|
surfaces.setReserve(xTiles*yTiles);
|
|
|
|
|
|
|
|
SkImageInfo info = canvas->imageInfo().makeWH(fW, fH);
|
|
|
|
for (int j = 0; j < yTiles; j++) {
|
|
|
|
for (int i = 0; i < xTiles; i++) {
|
|
|
|
// This lets our ultimate Sink determine the best kind of surface.
|
|
|
|
// E.g., if it's a GpuSink, the surfaces and images are textures.
|
|
|
|
SkSurface* s = canvas->newSurface(info);
|
|
|
|
if (!s) {
|
|
|
|
s = SkSurface::NewRaster(info); // Some canvases can't create surfaces.
|
2015-01-15 18:56:12 +00:00
|
|
|
}
|
2015-05-05 18:38:45 +00:00
|
|
|
surfaces.push(s);
|
|
|
|
SkCanvas* c = s->getCanvas();
|
|
|
|
c->translate(SkIntToScalar(-i * fW),
|
|
|
|
SkIntToScalar(-j * fH)); // Line up the canvas with this tile.
|
|
|
|
mpd.add(c, pic);
|
2015-01-15 18:56:12 +00:00
|
|
|
}
|
2015-05-05 18:38:45 +00:00
|
|
|
}
|
|
|
|
mpd.draw();
|
|
|
|
for (int j = 0; j < yTiles; j++) {
|
|
|
|
for (int i = 0; i < xTiles; i++) {
|
|
|
|
SkAutoTUnref<SkImage> image(surfaces[i+xTiles*j]->newImageSnapshot());
|
|
|
|
canvas->drawImage(image, SkIntToScalar(i*fW), SkIntToScalar(j*fH));
|
2015-01-15 18:56:12 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-05 18:38:45 +00:00
|
|
|
surfaces.unrefAll();
|
|
|
|
return "";
|
|
|
|
});
|
2015-01-15 18:56:12 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 15:30:32 +00:00
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
|
|
|
// Draw the Src into two pictures, then draw the second picture into the wrapped Sink.
|
|
|
|
// This tests that any shortcuts we may take while recording that second picture are legal.
|
|
|
|
Error ViaSecondPicture::draw(
|
|
|
|
const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
|
2015-05-05 18:38:45 +00:00
|
|
|
auto size = src.size();
|
2015-12-10 23:14:27 +00:00
|
|
|
return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error {
|
2015-05-05 18:38:45 +00:00
|
|
|
SkPictureRecorder recorder;
|
|
|
|
SkAutoTUnref<SkPicture> pic;
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
Error err = src.draw(recorder.beginRecording(SkIntToScalar(size.width()),
|
|
|
|
SkIntToScalar(size.height())));
|
|
|
|
if (!err.isEmpty()) {
|
|
|
|
return err;
|
2015-04-07 15:30:32 +00:00
|
|
|
}
|
2015-05-05 18:38:45 +00:00
|
|
|
pic.reset(recorder.endRecordingAsPicture());
|
2015-04-07 15:30:32 +00:00
|
|
|
}
|
2015-05-05 18:38:45 +00:00
|
|
|
canvas->drawPicture(pic);
|
|
|
|
return "";
|
|
|
|
});
|
2015-04-07 15:30:32 +00:00
|
|
|
}
|
|
|
|
|
2015-05-05 19:59:56 +00:00
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2015-05-06 18:35:40 +00:00
|
|
|
// Draw the Src twice. This can help exercise caching.
|
|
|
|
Error ViaTwice::draw(const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
|
2015-12-10 23:14:27 +00:00
|
|
|
return draw_to_canvas(fSink, bitmap, stream, log, src.size(), [&](SkCanvas* canvas) -> Error {
|
2015-05-06 18:35:40 +00:00
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
SkAutoCanvasRestore acr(canvas, true/*save now*/);
|
|
|
|
canvas->clear(SK_ColorTRANSPARENT);
|
|
|
|
Error err = src.draw(canvas);
|
|
|
|
if (err.isEmpty()) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
|
|
2015-05-05 19:59:56 +00:00
|
|
|
// This is like SkRecords::Draw, in that it plays back SkRecords ops into a Canvas.
|
|
|
|
// Unlike SkRecords::Draw, it builds a single-op sub-picture out of each Draw-type op.
|
|
|
|
// This is an only-slightly-exaggerated simluation of Blink's Slimming Paint pictures.
|
|
|
|
struct DrawsAsSingletonPictures {
|
|
|
|
SkCanvas* fCanvas;
|
2015-07-07 16:43:28 +00:00
|
|
|
const SkDrawableList& fDrawables;
|
2015-05-05 19:59:56 +00:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void draw(const T& op, SkCanvas* canvas) {
|
|
|
|
// We must pass SkMatrix::I() as our initial matrix.
|
|
|
|
// By default SkRecords::Draw() uses the canvas' matrix as its initial matrix,
|
|
|
|
// which would have the funky effect of applying transforms over and over.
|
2015-07-07 16:43:28 +00:00
|
|
|
SkRecords::Draw d(canvas, nullptr, fDrawables.begin(), fDrawables.count(), &SkMatrix::I());
|
|
|
|
d(op);
|
2015-05-05 19:59:56 +00:00
|
|
|
}
|
|
|
|
|
2015-09-28 17:33:02 +00:00
|
|
|
// Draws get their own picture.
|
2015-05-05 19:59:56 +00:00
|
|
|
template <typename T>
|
2015-09-28 17:33:02 +00:00
|
|
|
SK_WHEN(T::kTags & SkRecords::kDraw_Tag, void) operator()(const T& op) {
|
2015-05-05 19:59:56 +00:00
|
|
|
SkPictureRecorder rec;
|
|
|
|
this->draw(op, rec.beginRecording(SkRect::MakeLargest()));
|
|
|
|
SkAutoTUnref<SkPicture> pic(rec.endRecordingAsPicture());
|
|
|
|
fCanvas->drawPicture(pic);
|
|
|
|
}
|
|
|
|
|
2015-09-28 17:33:02 +00:00
|
|
|
// We'll just issue non-draws directly.
|
2015-05-05 19:59:56 +00:00
|
|
|
template <typename T>
|
2015-09-28 17:33:02 +00:00
|
|
|
skstd::enable_if_t<!(T::kTags & SkRecords::kDraw_Tag), void> operator()(const T& op) {
|
|
|
|
this->draw(op, fCanvas);
|
|
|
|
}
|
2015-05-05 19:59:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Record Src into a picture, then record it into a macro picture with a sub-picture for each draw.
|
|
|
|
// Then play back that macro picture into our wrapped sink.
|
|
|
|
Error ViaSingletonPictures::draw(
|
|
|
|
const Src& src, SkBitmap* bitmap, SkWStream* stream, SkString* log) const {
|
|
|
|
auto size = src.size();
|
2015-12-10 23:14:27 +00:00
|
|
|
return draw_to_canvas(fSink, bitmap, stream, log, size, [&](SkCanvas* canvas) -> Error {
|
2015-05-05 19:59:56 +00:00
|
|
|
// Use low-level (Skia-private) recording APIs so we can read the SkRecord.
|
|
|
|
SkRecord skr;
|
|
|
|
SkRecorder recorder(&skr, size.width(), size.height());
|
|
|
|
Error err = src.draw(&recorder);
|
|
|
|
if (!err.isEmpty()) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Record our macro-picture, with each draw op as its own sub-picture.
|
|
|
|
SkPictureRecorder macroRec;
|
|
|
|
SkCanvas* macroCanvas = macroRec.beginRecording(SkIntToScalar(size.width()),
|
|
|
|
SkIntToScalar(size.height()));
|
2015-07-07 16:43:28 +00:00
|
|
|
|
|
|
|
SkAutoTDelete<SkDrawableList> drawables(recorder.detachDrawableList());
|
|
|
|
const SkDrawableList empty;
|
|
|
|
|
|
|
|
DrawsAsSingletonPictures drawsAsSingletonPictures = {
|
|
|
|
macroCanvas,
|
|
|
|
drawables ? *drawables : empty,
|
|
|
|
};
|
2015-08-19 16:51:00 +00:00
|
|
|
for (int i = 0; i < skr.count(); i++) {
|
2015-05-05 19:59:56 +00:00
|
|
|
skr.visit<void>(i, drawsAsSingletonPictures);
|
|
|
|
}
|
|
|
|
SkAutoTUnref<SkPicture> macroPic(macroRec.endRecordingAsPicture());
|
|
|
|
|
|
|
|
canvas->drawPicture(macroPic);
|
|
|
|
return "";
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-01-15 18:56:12 +00:00
|
|
|
} // namespace DM
|