diff options
| author | 2023-03-29 17:17:21 +0000 | |
|---|---|---|
| committer | 2023-03-29 19:35:28 +0000 | |
| commit | 5c2505d0af08329de206e99c7755fae3025929ff (patch) | |
| tree | e1a680f61d7fa7845d551af3928adf2467801a7e /graphics/java/android | |
| parent | c1f3c3a3519b62c8ceb79aa0dc61f0faac93e9ae (diff) | |
Revert "Revert "ImageDecoder: Add AVIF to support list""
This reverts commit c1f3c3a3519b62c8ceb79aa0dc61f0faac93e9ae.
Reason for revert: re-land with error fixing
Change-Id: Icd3079a970fbf855fe2f33eabb0889f34536b78f
Diffstat (limited to 'graphics/java/android')
| -rw-r--r-- | graphics/java/android/graphics/ImageDecoder.java | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/graphics/java/android/graphics/ImageDecoder.java b/graphics/java/android/graphics/ImageDecoder.java index 51f99ec637da..0b29973507d2 100644 --- a/graphics/java/android/graphics/ImageDecoder.java +++ b/graphics/java/android/graphics/ImageDecoder.java @@ -38,8 +38,11 @@ import android.graphics.drawable.AnimatedImageDrawable; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.NinePatchDrawable; +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; @@ -928,6 +931,8 @@ public final class ImageDecoder implements AutoCloseable { case "image/x-pentax-pef": case "image/x-samsung-srw": return true; + case "image/avif": + return isP010SupportedForAV1(); default: return false; } @@ -2063,6 +2068,53 @@ public final class ImageDecoder implements AutoCloseable { return decodeBitmapImpl(src, null); } + private static boolean sIsP010SupportedForAV1 = false; + private static boolean sIsP010SupportedForAV1Initialized = false; + private static final Object sIsP010SupportedForAV1Lock = 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) { + return sIsP010SupportedForAV1; + } + + sIsP010SupportedForAV1Initialized = true; + + if (hasHardwareDecoder("video/av01")) { + sIsP010SupportedForAV1 = true; + return true; + } + + sIsP010SupportedForAV1 = Build.VERSION.DEVICE_INITIAL_SDK_INT + >= Build.VERSION_CODES.S; + return sIsP010SupportedForAV1; + } + } + + /** + * Checks if the device has hardware decoder for the target mime type. + */ + private static boolean hasHardwareDecoder(String mime) { + final MediaCodecList sMCL = new MediaCodecList(MediaCodecList.REGULAR_CODECS); + for (MediaCodecInfo info : sMCL.getCodecInfos()) { + if (info.isEncoder() == false && info.isHardwareAccelerated()) { + try { + if (info.getCapabilitiesForType(mime) != null) { + return true; + } + } catch (IllegalArgumentException e) { + // mime is not supported + return false; + } + } + } + return false; + } + /** * Private method called by JNI. */ |