summaryrefslogtreecommitdiff
path: root/graphics/java
diff options
context:
space:
mode:
author Xiao Huang <xiaohx@google.com> 2023-04-12 17:37:36 +0000
committer Xiao Huang <xiaohx@google.com> 2023-04-21 06:48:18 +0000
commitfff1a293e380ed87258f741475574eb37f77fe4f (patch)
treeb58c8f6c1a2935e2e101f47d942bb8c3b905b951 /graphics/java
parent50ab78c23458fb8ae2a2e8547306ab8add99ba48 (diff)
Fallback to RGBA_8888 when P010 is not supported
It's possible that a TV does not support P010, which means the TV is not able to decode 10-bit HEIF to RGBA_1010102. In this case, falling back to output RGBA_8888 is necessary. Bug: 276879147 Test: atest BitmapFactory#testDecode10BitHEIF10BitBitmap atest ImageDecoderTest#testDecode10BitHeif Change-Id: I33f7f30cbee0080dc81764c73428dcac3c75ce88
Diffstat (limited to 'graphics/java')
-rw-r--r--graphics/java/android/graphics/ImageDecoder.java41
1 files changed, 30 insertions, 11 deletions
diff --git a/graphics/java/android/graphics/ImageDecoder.java b/graphics/java/android/graphics/ImageDecoder.java
index 56c3068fe5e9..302c72ead52e 100644
--- a/graphics/java/android/graphics/ImageDecoder.java
+++ b/graphics/java/android/graphics/ImageDecoder.java
@@ -42,7 +42,6 @@ import android.media.MediaCodecInfo;
import android.media.MediaCodecList;
import android.net.Uri;
import android.os.Build;
-import android.os.SystemProperties;
import android.os.Trace;
import android.system.ErrnoException;
import android.system.Os;
@@ -2069,47 +2068,67 @@ public final class ImageDecoder implements AutoCloseable {
}
private static boolean sIsP010SupportedForAV1 = false;
- private static boolean sIsP010SupportedForAV1Initialized = false;
- private static final Object sIsP010SupportedForAV1Lock = new Object();
+ private static boolean sIsP010SupportedForHEVC = false;
+ private static boolean sIsP010SupportedFlagsInitialized = false;
+ private static final Object sIsP010SupportedLock = new Object();
/**
* Checks if the device supports decoding 10-bit AV1.
*/
@SuppressWarnings("AndroidFrameworkCompatChange") // This is not an app-visible API.
private static boolean isP010SupportedForAV1() {
- synchronized (sIsP010SupportedForAV1Lock) {
- if (sIsP010SupportedForAV1Initialized) {
+ synchronized (sIsP010SupportedLock) {
+ if (sIsP010SupportedFlagsInitialized) {
return sIsP010SupportedForAV1;
}
+ checkP010SupportforAV1HEVC();
+ return sIsP010SupportedForAV1;
+ }
+ }
- sIsP010SupportedForAV1Initialized = true;
- return sIsP010SupportedForAV1 = isP010SupportedforMime("video/av01");
+ /**
+ * Checks if the device supports decoding 10-bit HEVC.
+ * This method is called by JNI.
+ */
+ @SuppressWarnings("unused")
+ private static boolean isP010SupportedForHEVC() {
+ synchronized (sIsP010SupportedLock) {
+ if (sIsP010SupportedFlagsInitialized) {
+ return sIsP010SupportedForHEVC;
+ }
+ checkP010SupportforAV1HEVC();
+ return sIsP010SupportedForHEVC;
}
}
/**
* Checks if the device supports decoding 10-bit for the given mime type.
*/
- private static boolean isP010SupportedforMime(String mime) {
+ private static void checkP010SupportforAV1HEVC() {
MediaCodecList codecList = new MediaCodecList(MediaCodecList.ALL_CODECS);
for (MediaCodecInfo mediaCodecInfo : codecList.getCodecInfos()) {
if (mediaCodecInfo.isEncoder()) {
continue;
}
for (String mediaType : mediaCodecInfo.getSupportedTypes()) {
- if (mediaType.equalsIgnoreCase(mime)) {
+ if (mediaType.equalsIgnoreCase("video/av01")
+ || mediaType.equalsIgnoreCase("video/hevc")) {
MediaCodecInfo.CodecCapabilities codecCapabilities =
mediaCodecInfo.getCapabilitiesForType(mediaType);
for (int i = 0; i < codecCapabilities.colorFormats.length; ++i) {
if (codecCapabilities.colorFormats[i]
== MediaCodecInfo.CodecCapabilities.COLOR_FormatYUVP010) {
- return true;
+ if (mediaType.equalsIgnoreCase("video/av01")) {
+ sIsP010SupportedForAV1 = true;
+ } else {
+ sIsP010SupportedForHEVC = true;
+ }
}
}
}
}
}
- return false;
+ sIsP010SupportedFlagsInitialized = true;
}
/**