From d08847b3354e6617a4432b01385e80c3486044e2 Mon Sep 17 00:00:00 2001 From: Heidi Gaertner Date: Tue, 21 Jan 2025 19:02:14 -0800 Subject: [PATCH] add 420 p hardware buffer support to igl Reviewed By: pixelperfect3, corporateshark Differential Revision: D68332754 fbshipit-source-id: 1edba8413d5a80f25956aa36ba6016a92387f575 --- src/igl/android/NativeHWBuffer.cpp | 17 +++++++++++++++++ src/igl/tests/android/NativeHWBuffer.cpp | 7 +++++++ 2 files changed, 24 insertions(+) diff --git a/src/igl/android/NativeHWBuffer.cpp b/src/igl/android/NativeHWBuffer.cpp index 2441fb09b9..6f043f2613 100644 --- a/src/igl/android/NativeHWBuffer.cpp +++ b/src/igl/android/NativeHWBuffer.cpp @@ -49,6 +49,11 @@ uint32_t getNativeHWFormat(TextureFormat iglFormat) { case TextureFormat::YUV_NV12: return AHARDWAREBUFFER_FORMAT_YCbCr_420_SP_VENUS; +#if __ANDROID_MIN_SDK_VERSION__ >= 30 + case TextureFormat::YUV_420p: + return AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_420; +#endif + default: return 0; } @@ -107,6 +112,11 @@ TextureFormat getIglFormat(uint32_t nativeFormat) { case COLOR_QCOM_FORMATYUV420PackedSemiPlanar32m: return TextureFormat::YUV_NV12; +#if __ANDROID_MIN_SDK_VERSION__ >= 30 + case AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_420: + return TextureFormat::YUV_420p; +#endif + default: return TextureFormat::Invalid; } @@ -191,6 +201,13 @@ Result INativeHWTextureBuffer::attachHWBuffer(AHardwareBuffer* buffer) { const bool isValid = desc.format != TextureFormat::Invalid && desc.usage != 0; if (!isValid) { AHardwareBuffer_release(buffer); + IGL_LOG_ERROR( + "Can not create texture for hardware buffer format is %x usage is %x width is %d height " + "is %d", + hwbDesc.format, + hwbDesc.usage, + hwbDesc.width, + hwbDesc.height); return Result(Result::Code::Unsupported, "Can not create texture for hardware buffer"); } diff --git a/src/igl/tests/android/NativeHWBuffer.cpp b/src/igl/tests/android/NativeHWBuffer.cpp index 5535a18ebc..fa04d8871c 100644 --- a/src/igl/tests/android/NativeHWBuffer.cpp +++ b/src/igl/tests/android/NativeHWBuffer.cpp @@ -59,6 +59,9 @@ TEST_F(NativeHWBufferTest, Basic_getNativeHWFormat) { EXPECT_EQ(getNativeHWFormat(igl::TextureFormat::YUV_NV12), AHARDWAREBUFFER_FORMAT_YCbCr_420_SP_VENUS); EXPECT_EQ(getNativeHWFormat(igl::TextureFormat::Invalid), 0); +#if __ANDROID_MIN_SDK_VERSION__ >= 30 + EXPECT_EQ(getNativeHWFormat(igl::TextureFormat::YUV_420p), AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_420); +#endif } TEST_F(NativeHWBufferTest, Basic_getIglFormat) { @@ -80,6 +83,10 @@ TEST_F(NativeHWBufferTest, Basic_getIglFormat) { EXPECT_EQ(igl::android::getIglFormat(AHARDWAREBUFFER_FORMAT_S8_UINT), TextureFormat::S_UInt8); EXPECT_EQ(igl::android::getIglFormat(AHARDWAREBUFFER_FORMAT_YCbCr_420_SP_VENUS), TextureFormat::YUV_NV12); +#if __ANDROID_MIN_SDK_VERSION__ >= 30 + EXPECT_EQ(igl::android::getIglFormat(AHARDWAREBUFFER_FORMAT_Y8Cb8Cr8_420), + TextureFormat::YUV_420p); +#endif } TEST_F(NativeHWBufferTest, getNativeHWBufferUsage) {