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;