From 5a5c2ce593384bec4fc6982976ec11afa18afe8f Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Fri, 15 Jan 2021 14:09:13 -0500 Subject: [PATCH] (A)ImageDecoder: fix sampled dimensions with exif Test: I138ec784a77253c7ae94765d0670e5947d97caf5 Recently (Ib93b0ced09fa3cca4a6681745406355c48158fae), handling exif moved from SkAndroidCodec to hwui/ImageDecoder. This missed getSampledDimensions, which reports the sampled dimensions without taking exif into account. Fix this for both android.graphics.ImageDecoder and AImageDecoder. Note that in the Java case, the method is private, and although the method was returning swapped dimensions in some cases, it gets corrected by getTargetDimension, so there is no user visible change. Change-Id: I918328c39d6230ae6ba4cab0733fff0732b39888 --- libs/hwui/hwui/ImageDecoder.cpp | 5 +++++ libs/hwui/hwui/ImageDecoder.h | 1 + libs/hwui/jni/ImageDecoder.cpp | 2 +- native/graphics/jni/imagedecoder.cpp | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/libs/hwui/hwui/ImageDecoder.cpp b/libs/hwui/hwui/ImageDecoder.cpp index 764bc4c7ff0ac..f055c6e0fa449 100644 --- a/libs/hwui/hwui/ImageDecoder.cpp +++ b/libs/hwui/hwui/ImageDecoder.cpp @@ -76,6 +76,11 @@ static bool requires_matrix_scaling(bool swapWidthHeight, const SkISize& decodeS || (!swapWidthHeight && decodeSize != targetSize); } +SkISize ImageDecoder::getSampledDimensions(int sampleSize) const { + auto size = mCodec->getSampledDimensions(sampleSize); + return swapWidthHeight() ? swapped(size) : size; +} + bool ImageDecoder::setTargetSize(int width, int height) { if (width <= 0 || height <= 0) { return false; diff --git a/libs/hwui/hwui/ImageDecoder.h b/libs/hwui/hwui/ImageDecoder.h index 1b309bcc7bf08..cbfffd5e9291d 100644 --- a/libs/hwui/hwui/ImageDecoder.h +++ b/libs/hwui/hwui/ImageDecoder.h @@ -38,6 +38,7 @@ public: sk_sp peeker = nullptr); ~ImageDecoder(); + SkISize getSampledDimensions(int sampleSize) const; bool setTargetSize(int width, int height); bool setCropRect(const SkIRect*); diff --git a/libs/hwui/jni/ImageDecoder.cpp b/libs/hwui/jni/ImageDecoder.cpp index 96e912fd9f26a..ad7741b61e9f4 100644 --- a/libs/hwui/jni/ImageDecoder.cpp +++ b/libs/hwui/jni/ImageDecoder.cpp @@ -465,7 +465,7 @@ static jobject ImageDecoder_nDecodeBitmap(JNIEnv* env, jobject /*clazz*/, jlong static jobject ImageDecoder_nGetSampledSize(JNIEnv* env, jobject /*clazz*/, jlong nativePtr, jint sampleSize) { auto* decoder = reinterpret_cast(nativePtr); - SkISize size = decoder->mCodec->getSampledDimensions(sampleSize); + SkISize size = decoder->getSampledDimensions(sampleSize); return env->NewObject(gSize_class, gSize_constructorMethodID, size.width(), size.height()); } diff --git a/native/graphics/jni/imagedecoder.cpp b/native/graphics/jni/imagedecoder.cpp index eab5f4143968f..385e455e3e1f3 100644 --- a/native/graphics/jni/imagedecoder.cpp +++ b/native/graphics/jni/imagedecoder.cpp @@ -353,7 +353,7 @@ int AImageDecoder_computeSampledSize(const AImageDecoder* decoder, int sampleSiz return ANDROID_IMAGE_DECODER_BAD_PARAMETER; } - SkISize size = toDecoder(decoder)->mCodec->getSampledDimensions(sampleSize); + SkISize size = toDecoder(decoder)->getSampledDimensions(sampleSize); *width = size.width(); *height = size.height(); return ANDROID_IMAGE_DECODER_SUCCESS;