| Index: dm/DMSrcSink.cpp
|
| diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
|
| index ea21d7a69593c98df6627ee1360cddfa5669f067..b4094683eca86beb06907d85e9bdaac9be4efb29 100644
|
| --- a/dm/DMSrcSink.cpp
|
| +++ b/dm/DMSrcSink.cpp
|
| @@ -14,6 +14,7 @@
|
| #include "SkDocument.h"
|
| #include "SkError.h"
|
| #include "SkImageGenerator.h"
|
| +#include "SkImageGeneratorCG.h"
|
| #include "SkMallocPixelRef.h"
|
| #include "SkMultiPictureDraw.h"
|
| #include "SkNullCanvas.h"
|
| @@ -264,15 +265,7 @@ CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, SkAlphaType
|
| {}
|
|
|
| bool CodecSrc::veto(SinkFlags flags) const {
|
| - // Test CodecImageGenerator on 8888, 565, and gpu
|
| - if (kGen_Mode == fMode) {
|
| - // For image generator, we want to test kDirect approaches for kRaster and kGPU,
|
| - // while skipping everything else.
|
| - return (flags.type != SinkFlags::kRaster && flags.type != SinkFlags::kGPU) ||
|
| - flags.approach != SinkFlags::kDirect;
|
| - }
|
| -
|
| - // Test all other modes to direct raster backends (8888 and 565).
|
| + // Test to direct raster backends (8888 and 565).
|
| return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDirect;
|
| }
|
|
|
| @@ -334,42 +327,12 @@ bool get_decode_info(SkImageInfo* decodeInfo, SkColorType canvasColorType,
|
| return true;
|
| }
|
|
|
| -Error test_gen(SkCanvas* canvas, SkData* data) {
|
| - SkAutoTDelete<SkImageGenerator> gen = SkCodecImageGenerator::NewFromEncodedCodec(data);
|
| - if (!gen) {
|
| - return "Could not create image generator.";
|
| - }
|
| -
|
| - // FIXME: The gpu backend does not draw kGray sources correctly. (skbug.com/4822)
|
| - // Currently, we will avoid creating a CodecSrc for this case (see DM.cpp).
|
| - SkASSERT(kGray_8_SkColorType != gen->getInfo().colorType());
|
| -
|
| - if (kOpaque_SkAlphaType != gen->getInfo().alphaType() &&
|
| - kRGB_565_SkColorType == canvas->imageInfo().colorType()) {
|
| - return Error::Nonfatal("Skip testing non-opaque images to 565.");
|
| - }
|
| -
|
| - SkAutoTDelete<SkImage> image(SkImage::NewFromGenerator(gen.detach(), nullptr));
|
| - if (!image) {
|
| - return "Could not create image from codec image generator.";
|
| - }
|
| -
|
| - canvas->drawImage(image, 0, 0);
|
| - return "";
|
| -}
|
| -
|
| Error CodecSrc::draw(SkCanvas* canvas) const {
|
| SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
|
| if (!encoded) {
|
| return SkStringPrintf("Couldn't read %s.", fPath.c_str());
|
| }
|
|
|
| - // The CodecImageGenerator test does not share much code with the other tests,
|
| - // so we will handle it in its own function.
|
| - if (kGen_Mode == fMode) {
|
| - return test_gen(canvas, encoded);
|
| - }
|
| -
|
| SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
|
| if (nullptr == codec.get()) {
|
| return SkStringPrintf("Couldn't create codec for %s.", fPath.c_str());
|
| @@ -803,6 +766,79 @@ Name AndroidCodecSrc::name() const {
|
|
|
| /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
|
|
| +ImageGenSrc::ImageGenSrc(Path path, Mode mode)
|
| + : fPath(path)
|
| + , fMode(mode)
|
| + , fRunSerially(serial_from_path_name(path))
|
| +{}
|
| +
|
| +bool ImageGenSrc::veto(SinkFlags flags) const {
|
| + // For image generators, we want to test kDirect approaches for
|
| + // kRaster and kGPU (8888, 565, gpu).
|
| + return (flags.type != SinkFlags::kRaster && flags.type != SinkFlags::kGPU) ||
|
| + flags.approach != SinkFlags::kDirect;
|
| +}
|
| +
|
| +Error ImageGenSrc::draw(SkCanvas* canvas) const {
|
| + SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
|
| + if (!encoded) {
|
| + return SkStringPrintf("Couldn't read %s.", fPath.c_str());
|
| + }
|
| +
|
| + SkAutoTDelete<SkImageGenerator> gen(nullptr);
|
| + switch (fMode) {
|
| + case kCodec_Mode:
|
| + gen.reset(SkCodecImageGenerator::NewFromEncodedCodec(encoded));
|
| + if (!gen) {
|
| + return "Could not create codec image generator.";
|
| + }
|
| + break;
|
| +#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
|
| + case kCG_Mode:
|
| + gen.reset(SkImageGeneratorCG::NewFromEncodedCG(encoded));
|
| + if (!gen) {
|
| + return "Could not create CG image generator.";
|
| + }
|
| + break;
|
| +#endif
|
| + default:
|
| + SkASSERT(false);
|
| + return "Invalid image generator mode";
|
| + }
|
| +
|
| + // FIXME: The gpu backend does not draw kGray sources correctly. (skbug.com/4822)
|
| + // Currently, we will avoid creating a CodecSrc for this case (see DM.cpp).
|
| + SkASSERT(kGray_8_SkColorType != gen->getInfo().colorType());
|
| +
|
| + if (kOpaque_SkAlphaType != gen->getInfo().alphaType() &&
|
| + kRGB_565_SkColorType == canvas->imageInfo().colorType()) {
|
| + return Error::Nonfatal("Skip testing non-opaque images to 565.");
|
| + }
|
| +
|
| + SkAutoTDelete<SkImage> image(SkImage::NewFromGenerator(gen.detach(), nullptr));
|
| + if (!image) {
|
| + return "Could not create image from codec image generator.";
|
| + }
|
| +
|
| + canvas->drawImage(image, 0, 0);
|
| + return "";
|
| +}
|
| +
|
| +SkISize ImageGenSrc::size() const {
|
| + SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(fPath.c_str()));
|
| + SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded));
|
| + if (nullptr == codec) {
|
| + return SkISize::Make(0, 0);
|
| + }
|
| + return codec->getInfo().dimensions();
|
| +}
|
| +
|
| +Name ImageGenSrc::name() const {
|
| + return SkOSPath::Basename(fPath.c_str());
|
| +}
|
| +
|
| +/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
|
| +
|
| static const SkRect kSKPViewport = {0,0, 1000,1000};
|
|
|
| SKPSrc::SKPSrc(Path path) : fPath(path) {}
|
|
|