aboutsummaryrefslogtreecommitdiffhomepage
path: root/dm
diff options
context:
space:
mode:
authorGravatar msarett <msarett@google.com>2016-01-22 14:46:42 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-01-22 14:46:42 -0800
commitb714fb0199e8727ef2b6cddbee7eba6046f01554 (patch)
tree20c7f211949e24ed224901dcbf1e02c77b5da94b /dm
parent13aa1a5ad97156e35184970fc1ce1aaf3c50c91c (diff)
Add getYUV8Planes() API to SkCodec
Diffstat (limited to 'dm')
-rw-r--r--dm/DM.cpp23
-rw-r--r--dm/DMSrcSink.cpp45
-rw-r--r--dm/DMSrcSink.h1
3 files changed, 59 insertions, 10 deletions
diff --git a/dm/DM.cpp b/dm/DM.cpp
index 2f45c61dff..5124442a20 100644
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -244,6 +244,9 @@ static void push_codec_src(Path path, CodecSrc::Mode mode, CodecSrc::DstColorTyp
case CodecSrc::kSubset_Mode:
folder.append("codec_subset");
break;
+ case CodecSrc::kGen_Mode:
+ folder.append("gen");
+ break;
}
switch (dstColorType) {
@@ -315,7 +318,8 @@ static void push_codec_srcs(Path path) {
const float nativeScales[] = { 0.125f, 0.25f, 0.375f, 0.5f, 0.625f, 0.750f, 0.875f, 1.0f };
const CodecSrc::Mode nativeModes[] = { CodecSrc::kCodec_Mode, CodecSrc::kCodecZeroInit_Mode,
- CodecSrc::kScanline_Mode, CodecSrc::kStripe_Mode, CodecSrc::kSubset_Mode };
+ CodecSrc::kScanline_Mode, CodecSrc::kStripe_Mode, CodecSrc::kSubset_Mode,
+ CodecSrc::kGen_Mode };
CodecSrc::DstColorType colorTypes[3];
uint32_t numColorTypes;
@@ -341,8 +345,21 @@ static void push_codec_srcs(Path path) {
break;
}
- for (float scale : nativeScales) {
- for (CodecSrc::Mode mode : nativeModes) {
+
+ for (CodecSrc::Mode mode : nativeModes) {
+ // SkCodecImageGenerator only runs for the default colorType
+ // recommended by SkCodec. There is no need to generate multiple
+ // tests for different colorTypes.
+ // TODO (msarett): Add scaling support to SkCodecImageGenerator.
+ if (CodecSrc::kGen_Mode == mode) {
+ // FIXME: The gpu backend does not draw kGray sources correctly. (skbug.com/4822)
+ if (kGray_8_SkColorType != codec->getInfo().colorType()) {
+ push_codec_src(path, mode, CodecSrc::kGetFromCanvas_DstColorType, 1.0f);
+ }
+ continue;
+ }
+
+ for (float scale : nativeScales) {
for (uint32_t i = 0; i < numColorTypes; i++) {
push_codec_src(path, mode, colorTypes[i], scale);
}
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index bbfa5199e6..8598de781c 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -8,6 +8,7 @@
#include "DMSrcSink.h"
#include "SkAndroidCodec.h"
#include "SkCodec.h"
+#include "SkCodecImageGenerator.h"
#include "SkCommonFlags.h"
#include "SkData.h"
#include "SkDocument.h"
@@ -240,11 +241,14 @@ CodecSrc::CodecSrc(Path path, Mode mode, DstColorType dstColorType, float scale)
{}
bool CodecSrc::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;
+ // Test CodecImageGenerator on 8888, 565, and gpu
+ if (kGen_Mode == fMode) {
+ return (flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDirect) &&
+ flags.type != SinkFlags::kGPU;
+ }
+
+ // Test all other modes to direct raster backends (8888 and 565).
+ return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDirect;
}
bool get_decode_info(SkImageInfo* decodeInfo, const SkImageInfo& defaultInfo,
@@ -274,11 +278,37 @@ bool get_decode_info(SkImageInfo* decodeInfo, const SkImageInfo& defaultInfo,
return true;
}
+Error test_gen(SkCanvas* canvas, SkData* data) {
+ 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());
+
+ SkAutoTDelete<SkImage> image(SkImage::NewFromGenerator(gen, 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());
@@ -509,6 +539,9 @@ Error CodecSrc::draw(SkCanvas* canvas) const {
}
return "";
}
+ default:
+ SkASSERT(false);
+ return "Invalid fMode";
}
return "";
}
@@ -541,8 +574,6 @@ AndroidCodecSrc::AndroidCodecSrc(Path path, Mode mode, CodecSrc::DstColorType ds
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;
}
diff --git a/dm/DMSrcSink.h b/dm/DMSrcSink.h
index def7cc9f5c..632744cd62 100644
--- a/dm/DMSrcSink.h
+++ b/dm/DMSrcSink.h
@@ -111,6 +111,7 @@ public:
kScanline_Mode,
kStripe_Mode, // Tests the skipping of scanlines
kSubset_Mode, // For codecs that support subsets directly.
+ kGen_Mode, // Test SkCodecImageGenerator (includes YUV)
};
enum DstColorType {
kGetFromCanvas_DstColorType,