From cf8d8bc76944e11e43add867358f9ac38316997b Mon Sep 17 00:00:00 2001 From: John Reck Date: Mon, 19 Dec 2022 16:35:22 -0500 Subject: [PATCH] Add ExtendableType to allocate Allows for passing arbitrary additional options to IAllocator Can be used to control things such as compression level without exhausting usage bits Currently there are no standard options defined so this only allows for vendor-internal extensions currently. Fixes: 257075040 Test: VtsHalGraphicsAllocatorAidl_TargetTest Change-Id: I37b730f5ba141b08d458866c6d03a39b27124e02 --- graphics/Android.bp | 6 ++ .../allocator/BufferDescriptorInfo.aidl | 1 + .../allocator/BufferDescriptorInfo.aidl | 16 +++++ ...VtsHalGraphicsAllocatorAidl_TargetTest.cpp | 58 +++++++++++++++++++ 4 files changed, 81 insertions(+) diff --git a/graphics/Android.bp b/graphics/Android.bp index 4c51454233..4ae7ec7c5e 100644 --- a/graphics/Android.bp +++ b/graphics/Android.bp @@ -21,6 +21,9 @@ cc_defaults { static_libs: [ "android.hardware.graphics.allocator-V2-ndk", ], + defaults: [ + "android.hardware.graphics.common-ndk_static", + ], } cc_defaults { @@ -28,6 +31,9 @@ cc_defaults { shared_libs: [ "android.hardware.graphics.allocator-V2-ndk", ], + defaults: [ + "android.hardware.graphics.common-ndk_shared", + ], } cc_defaults { diff --git a/graphics/allocator/aidl/aidl_api/android.hardware.graphics.allocator/current/android/hardware/graphics/allocator/BufferDescriptorInfo.aidl b/graphics/allocator/aidl/aidl_api/android.hardware.graphics.allocator/current/android/hardware/graphics/allocator/BufferDescriptorInfo.aidl index 980e246bb8..49c249742f 100644 --- a/graphics/allocator/aidl/aidl_api/android.hardware.graphics.allocator/current/android/hardware/graphics/allocator/BufferDescriptorInfo.aidl +++ b/graphics/allocator/aidl/aidl_api/android.hardware.graphics.allocator/current/android/hardware/graphics/allocator/BufferDescriptorInfo.aidl @@ -41,4 +41,5 @@ parcelable BufferDescriptorInfo { android.hardware.graphics.common.PixelFormat format = android.hardware.graphics.common.PixelFormat.UNSPECIFIED; android.hardware.graphics.common.BufferUsage usage = android.hardware.graphics.common.BufferUsage.CPU_READ_NEVER; long reservedSize; + android.hardware.graphics.common.ExtendableType[] additionalOptions; } diff --git a/graphics/allocator/aidl/android/hardware/graphics/allocator/BufferDescriptorInfo.aidl b/graphics/allocator/aidl/android/hardware/graphics/allocator/BufferDescriptorInfo.aidl index ffc50b8541..50aa2b7c7a 100644 --- a/graphics/allocator/aidl/android/hardware/graphics/allocator/BufferDescriptorInfo.aidl +++ b/graphics/allocator/aidl/android/hardware/graphics/allocator/BufferDescriptorInfo.aidl @@ -17,6 +17,7 @@ package android.hardware.graphics.allocator; import android.hardware.graphics.common.BufferUsage; +import android.hardware.graphics.common.ExtendableType; import android.hardware.graphics.common.PixelFormat; @VintfStability @@ -54,6 +55,9 @@ parcelable BufferDescriptorInfo { /** * Buffer usage mask; valid flags can be found in the definition of * BufferUsage.aidl in graphics/common + * + * The allocator must report isSupported() == false and reject any allocations + * with unrecognized buffer usages. */ BufferUsage usage = BufferUsage.CPU_READ_NEVER; @@ -62,4 +66,16 @@ parcelable BufferDescriptorInfo { * See getReservedRegion for more information. */ long reservedSize; + + /** + * Extensible additional options that can be set. + * + * This is intended for options that do not change the overall usage, but which do impact + * how a buffer is allocated. An example of this is compression level, such as for + * the EGL_EXT_surface_compression extension. + * + * The allocator must report isSupported() == false and reject any allocations + * with unrecognized options. + */ + ExtendableType[] additionalOptions; } diff --git a/graphics/allocator/aidl/vts/VtsHalGraphicsAllocatorAidl_TargetTest.cpp b/graphics/allocator/aidl/vts/VtsHalGraphicsAllocatorAidl_TargetTest.cpp index 09f1c1566b..4778020c6e 100644 --- a/graphics/allocator/aidl/vts/VtsHalGraphicsAllocatorAidl_TargetTest.cpp +++ b/graphics/allocator/aidl/vts/VtsHalGraphicsAllocatorAidl_TargetTest.cpp @@ -217,6 +217,8 @@ class GraphicsTestsBase { } return ret; } + + int32_t allocatorVersion() const { return mIAllocatorVersion; } }; BufferHandle::~BufferHandle() { @@ -309,6 +311,62 @@ TEST_P(GraphicsAllocatorAidlTests, CanAllocate) { EXPECT_GE(buffer->stride(), 64); } +TEST_P(GraphicsAllocatorAidlTests, RejectsUnknownUsages) { + if (allocatorVersion() < 2) { + GTEST_SKIP() << "Must be version 2+"; + return; + } + + constexpr auto FirstInvalidV2Usage = static_cast(1LL << 33); + + BufferUsage invalidUsage; + if (allocatorVersion() == 2) { + invalidUsage = FirstInvalidV2Usage; + } else { + GTEST_FAIL() << "Unknown version " << allocatorVersion(); + } + + BufferDescriptorInfo info{ + .name = {"CPU_8888"}, + .width = 64, + .height = 64, + .layerCount = 1, + .format = PixelFormat::RGBA_8888, + .usage = BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN, + .reservedSize = 0, + }; + + // First make sure we can allocate a known usage buffer as expected + EXPECT_TRUE(isSupported(info)); + EXPECT_TRUE(allocate(info)); + + // Now add the unknown bit and verify it's rejected + info.usage |= invalidUsage; + EXPECT_FALSE(isSupported(info)) << "isSupported() returned true for unknown-to-HAL usage"; + EXPECT_FALSE(allocate(info)) << "allocate succeeded for unknown-to-HAL usage"; +} + +TEST_P(GraphicsAllocatorAidlTests, RejectsUnknownOptions) { + if (allocatorVersion() < 2) { + GTEST_SKIP() << "Must be version 2+"; + return; + } + + BufferDescriptorInfo info{ + .name = {"CPU_8888"}, + .width = 64, + .height = 64, + .layerCount = 1, + .format = PixelFormat::RGBA_8888, + .usage = BufferUsage::CPU_READ_OFTEN | BufferUsage::CPU_WRITE_OFTEN, + .reservedSize = 0, + }; + info.additionalOptions.push_back({"android.hardware.graphics.common.NotARealOption", 1}); + + EXPECT_FALSE(isSupported(info)) << "isSupported() returned true for unknown-to-HAL option"; + EXPECT_FALSE(allocate(info)) << "allocate succeeded for unknown-to-HAL option"; +} + TEST_P(GraphicsFrontBufferTests, FrontBufferGpuToCpu) { BufferDescriptorInfo info{ .name = {"CPU_8888"},