| Index: dm/DMSrcSink.cpp
|
| diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
|
| index f555b9fcbdba78f485e47b9baf4be67d2fa1d83c..62a5772931f9e77dd358f752d94a005a60f8ba49 100644
|
| --- a/dm/DMSrcSink.cpp
|
| +++ b/dm/DMSrcSink.cpp
|
| @@ -64,6 +64,113 @@ void GMSrc::modifyGrContextOptions(GrContextOptions* options) const {
|
|
|
| /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
| +BRDSrc::BRDSrc(Path path, SkBitmapRegionDecoder::Strategy strategy, Mode mode,
|
| + SkColorType dstColorType, uint32_t sampleSize)
|
| + : fPath(path)
|
| + , fStrategy(strategy)
|
| + , fMode(mode)
|
| + , fColorType(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;
|
| +}
|
| +
|
| +Error BRDSrc::draw(SkCanvas* canvas) const {
|
| + if (kRGB_565_SkColorType == canvas->imageInfo().colorType()) {
|
| + return Error::Nonfatal("Testing to multiple backends is uninteresting.");
|
| + }
|
| +
|
| + SkAutoTDelete<SkBitmapRegionDecoder> brd(
|
| + SkBitmapRegionDecoder::CreateBitmapRegionDecoder(
|
| + SkNEW_ARGS(SkMemoryStream, (SkData::NewFromFileName(fPath.c_str()))),
|
| + fStrategy));
|
| + if (NULL == brd.get()) {
|
| + return SkStringPrintf("Could not create brd for %s.", fPath.c_str());
|
| + }
|
| +
|
| + switch (fMode) {
|
| + case kFullImage_Mode: {
|
| + SkAutoTDelete<SkBitmap> bitmap(brd->decodeRegion(0, 0, brd->width(),
|
| + brd->height(), fSampleSize, fColorType));
|
| + if (NULL == bitmap.get() || fColorType != bitmap->colorType()) {
|
| + return Error::Nonfatal("Cannot convert to color type.\n");
|
| + }
|
| + canvas->drawBitmap(*bitmap, 0, 0);
|
| + return "";
|
| + }
|
| + case kDivisor_Mode: {
|
| + // Use a border to test what happens when we ask for subsets that extend outside the image
|
| + uint32_t scaledBorder = 5;
|
| + uint32_t unscaledBorder = 5 * fSampleSize;
|
| + uint32_t divisor = 2;
|
| + uint32_t width = brd->width();
|
| + uint32_t height = brd->height();
|
| + 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;
|
| + int left = x * subsetWidth;
|
| + 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
|
| + int decodeLeft = left - unscaledBorder;
|
| + int decodeTop = top - unscaledBorder;
|
| + uint32_t decodeWidth = subsetWidth + unscaledBorder * 2;
|
| + uint32_t decodeHeight = subsetHeight + unscaledBorder * 2;
|
| +
|
| + SkAutoTDelete<SkBitmap> bitmap(brd->decodeRegion(decodeLeft,
|
| + decodeTop, decodeWidth, decodeHeight, fSampleSize, fColorType));
|
| + if (NULL == bitmap.get() || fColorType != bitmap->colorType()) {
|
| + return Error::Nonfatal("Cannot convert to color type.\n");
|
| + }
|
| + canvas->drawBitmapRect(*bitmap,
|
| + SkRect::MakeXYWH(scaledBorder, scaledBorder,
|
| + subsetWidth / fSampleSize, subsetHeight / fSampleSize),
|
| + SkRect::MakeXYWH(left / fSampleSize, top / fSampleSize,
|
| + subsetWidth / fSampleSize, subsetHeight / fSampleSize),
|
| + NULL);
|
| + }
|
| + }
|
| + return "";
|
| + }
|
| + default:
|
| + SkASSERT(false);
|
| + return "Error: Should not be reached.\n";
|
| + }
|
| +}
|
| +
|
| +SkISize BRDSrc::size() const {
|
| + SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
|
| + SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
|
| + if (codec) {
|
| + return SkISize::Make(codec->getInfo().width() / fSampleSize,
|
| + codec->getInfo().height() / fSampleSize);
|
| + }
|
| + return SkISize::Make(0, 0);
|
| +}
|
| +
|
| +Name BRDSrc::name() const {
|
| + // We will replicate the names used by CodecSrc so that images can
|
| + // be compared in Gold.
|
| + if (1.0f == fSampleSize) {
|
| + return SkOSPath::Basename(fPath.c_str());
|
| + }
|
| + float scale = 1.0f / fSampleSize;
|
| + return SkStringPrintf("%s_%.3f", SkOSPath::Basename(fPath.c_str()).c_str(), scale);
|
| +}
|
| +
|
| +/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
| +
|
| CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, float scale)
|
| : fPath(path)
|
| , fMode(mode)
|
| @@ -447,20 +554,17 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
|
| SkISize CodecSrc::size() const {
|
| SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
|
| SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
|
| - if (NULL != codec) {
|
| - SkISize size = codec->getScaledDimensions(fScale);
|
| - return size;
|
| - } else {
|
| - return SkISize::Make(0, 0);
|
| + if (codec) {
|
| + return codec->getScaledDimensions(fScale);
|
| }
|
| + return SkISize::Make(0, 0);
|
| }
|
|
|
| Name CodecSrc::name() const {
|
| if (1.0f == fScale) {
|
| return SkOSPath::Basename(fPath.c_str());
|
| - } else {
|
| - return SkStringPrintf("%s_%.3f", SkOSPath::Basename(fPath.c_str()).c_str(), fScale);
|
| }
|
| + return SkStringPrintf("%s_%.3f", SkOSPath::Basename(fPath.c_str()).c_str(), fScale);
|
| }
|
|
|
| /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|