aboutsummaryrefslogtreecommitdiffhomepage
path: root/dm/DMSrcSink.cpp
diff options
context:
space:
mode:
authorGravatar scroggo <scroggo@google.com>2015-03-19 06:03:39 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-03-19 06:03:39 -0700
commit9b77ddde08efe702256355a333cf31ade8f15bb0 (patch)
treeb3bc069a191e747bf5107740d5b3b9b3fc84d1e2 /dm/DMSrcSink.cpp
parenteffcba4a4d1a6fdfdd5ec440e10e1424b768182d (diff)
Run CodecSrc DM.
Rather than making SkCodec an option instead of SkImageDecoder, create a separate CodecSrc. This allows us to compare the two. For both CodecSrc and ImageSrc, do not decode to a gpu backend. BUG=skia:3475 Review URL: https://codereview.chromium.org/978823002
Diffstat (limited to 'dm/DMSrcSink.cpp')
-rw-r--r--dm/DMSrcSink.cpp156
1 files changed, 91 insertions, 65 deletions
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index 6f6664f27c..7bbdff73bc 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -14,8 +14,6 @@
#include "SkStream.h"
#include "SkXMLWriter.h"
-DEFINE_bool(codec, false, "Use SkCodec instead of SkImageDecoder");
-
namespace DM {
GMSrc::GMSrc(skiagm::GMRegistry::Factory factory) : fFactory(factory) {}
@@ -39,59 +37,99 @@ Name GMSrc::name() const {
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+CodecSrc::CodecSrc(Path path) : fPath(path) {}
+
+Error CodecSrc::draw(SkCanvas* canvas) const {
+ SkImageInfo canvasInfo;
+ if (NULL == canvas->peekPixels(&canvasInfo, NULL)) {
+ // TODO: Once we implement GPU paths (e.g. JPEG YUV), we should use a deferred decode to
+ // let the GPU handle it.
+ return Error::Nonfatal("No need to test decoding to non-raster backend.");
+ }
+
+ SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
+ if (!encoded) {
+ return SkStringPrintf("Couldn't read %s.", fPath.c_str());
+ }
+
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
+ if (!codec) {
+ return SkStringPrintf("Couldn't decode %s.", fPath.c_str());
+ }
+
+ SkImageInfo decodeInfo;
+ if (!codec->getInfo(&decodeInfo)) {
+ return SkStringPrintf("Couldn't getInfo %s.", fPath.c_str());
+ }
+
+ decodeInfo = decodeInfo.makeColorType(canvasInfo.colorType());
+ if (decodeInfo.alphaType() == kUnpremul_SkAlphaType) {
+ // FIXME: Currently we cannot draw unpremultiplied sources.
+ decodeInfo = decodeInfo.makeAlphaType(kPremul_SkAlphaType);
+ }
+
+ SkBitmap bitmap;
+ if (!bitmap.tryAllocPixels(decodeInfo)) {
+ return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPath.c_str(),
+ decodeInfo.width(), decodeInfo.height());
+ }
+
+ SkAutoLockPixels alp(bitmap);
+ switch (codec->getPixels(decodeInfo, bitmap.getPixels(), bitmap.rowBytes())) {
+ case SkImageGenerator::kSuccess:
+ // We consider incomplete to be valid, since we should still decode what is
+ // available.
+ case SkImageGenerator::kIncompleteInput:
+ canvas->drawBitmap(bitmap, 0, 0);
+ return "";
+ case SkImageGenerator::kInvalidConversion:
+ return Error::Nonfatal("Incompatible colortype conversion");
+ default:
+ // Everything else is considered a failure.
+ return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str());
+ }
+}
+
+SkISize CodecSrc::size() const {
+ SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
+ SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
+ SkImageInfo info;
+ if (codec && codec->getInfo(&info)) {
+ return info.dimensions();
+ }
+ return SkISize::Make(0,0);
+}
+
+Name CodecSrc::name() const {
+ return SkOSPath::Basename(fPath.c_str());
+}
+
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
ImageSrc::ImageSrc(Path path, int divisor) : fPath(path), fDivisor(divisor) {}
Error ImageSrc::draw(SkCanvas* canvas) const {
+ SkImageInfo canvasInfo;
+ if (NULL == canvas->peekPixels(&canvasInfo, NULL)) {
+ // TODO: Instead, use lazy decoding to allow the GPU to handle cases like YUV.
+ return Error::Nonfatal("No need to test decoding to non-raster backend.");
+ }
+
SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
if (!encoded) {
return SkStringPrintf("Couldn't read %s.", fPath.c_str());
}
- const SkColorType dstColorType = canvas->imageInfo().colorType();
+ const SkColorType dstColorType = canvasInfo.colorType();
if (fDivisor == 0) {
// Decode the full image.
SkBitmap bitmap;
- if (FLAGS_codec) {
- SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
- if (!codec) {
- return SkStringPrintf("Couldn't decode %s.", fPath.c_str());
- }
- SkImageInfo info;
- if (!codec->getInfo(&info)) {
- return SkStringPrintf("Couldn't getInfo %s.", fPath.c_str());
- }
- info = info.makeColorType(dstColorType);
- if (info.alphaType() == kUnpremul_SkAlphaType) {
- // FIXME: Currently we cannot draw unpremultiplied sources.
- info = info.makeAlphaType(kPremul_SkAlphaType);
- }
- if (!bitmap.tryAllocPixels(info)) {
- return SkStringPrintf("Image(%s) is too large (%d x %d)\n", fPath.c_str(),
- info.width(), info.height());
- }
- SkAutoLockPixels alp(bitmap);
- const SkImageGenerator::Result result = codec->getPixels(info, bitmap.getPixels(),
- bitmap.rowBytes());
- switch (result) {
- case SkImageGenerator::kSuccess:
- // We consider incomplete to be valid, since we should still decode what is
- // available.
- case SkImageGenerator::kIncompleteInput:
- break;
- case SkImageGenerator::kInvalidConversion:
- return Error::Nonfatal("Incompatible colortype conversion");
- default:
- // Everything else is considered a failure.
- return SkStringPrintf("Couldn't getPixels %s.", fPath.c_str());
- }
- } else {
- 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.");
- }
+ 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.");
}
encoded.reset((SkData*)NULL); // Might as well drop this when we're done with it.
canvas->drawBitmap(bitmap, 0,0);
@@ -141,27 +179,15 @@ Error ImageSrc::draw(SkCanvas* canvas) const {
SkISize ImageSrc::size() const {
SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
- if (FLAGS_codec) {
- SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
- if (!codec) {
- return SkISize::Make(0,0);
- }
- SkImageInfo info;
- if (!codec->getInfo(&info)) {
- return SkISize::Make(0,0);
- }
- return info.dimensions();
- } else {
- SkBitmap bitmap;
- if (!encoded || !SkImageDecoder::DecodeMemory(encoded->data(),
- encoded->size(),
- &bitmap,
- kUnknown_SkColorType,
- SkImageDecoder::kDecodeBounds_Mode)) {
- return SkISize::Make(0,0);
- }
- return bitmap.dimensions();
+ SkBitmap bitmap;
+ if (!encoded || !SkImageDecoder::DecodeMemory(encoded->data(),
+ encoded->size(),
+ &bitmap,
+ kUnknown_SkColorType,
+ SkImageDecoder::kDecodeBounds_Mode)) {
+ return SkISize::Make(0,0);
}
+ return bitmap.dimensions();
}
Name ImageSrc::name() const {