Loading graphics/Android.bp +6 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,9 @@ cc_defaults { static_libs: [ "android.hardware.graphics.allocator-V2-ndk", ], defaults: [ "android.hardware.graphics.common-ndk_static", ], } cc_defaults { Loading @@ -28,6 +31,9 @@ cc_defaults { shared_libs: [ "android.hardware.graphics.allocator-V2-ndk", ], defaults: [ "android.hardware.graphics.common-ndk_shared", ], } cc_defaults { Loading graphics/allocator/aidl/aidl_api/android.hardware.graphics.allocator/current/android/hardware/graphics/allocator/BufferDescriptorInfo.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -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; } graphics/allocator/aidl/android/hardware/graphics/allocator/BufferDescriptorInfo.aidl +16 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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; Loading @@ -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; } graphics/allocator/aidl/vts/VtsHalGraphicsAllocatorAidl_TargetTest.cpp +58 −0 Original line number Diff line number Diff line Loading @@ -217,6 +217,8 @@ class GraphicsTestsBase { } return ret; } int32_t allocatorVersion() const { return mIAllocatorVersion; } }; BufferHandle::~BufferHandle() { Loading Loading @@ -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<BufferUsage>(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"}, Loading Loading
graphics/Android.bp +6 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,9 @@ cc_defaults { static_libs: [ "android.hardware.graphics.allocator-V2-ndk", ], defaults: [ "android.hardware.graphics.common-ndk_static", ], } cc_defaults { Loading @@ -28,6 +31,9 @@ cc_defaults { shared_libs: [ "android.hardware.graphics.allocator-V2-ndk", ], defaults: [ "android.hardware.graphics.common-ndk_shared", ], } cc_defaults { Loading
graphics/allocator/aidl/aidl_api/android.hardware.graphics.allocator/current/android/hardware/graphics/allocator/BufferDescriptorInfo.aidl +1 −0 Original line number Diff line number Diff line Loading @@ -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; }
graphics/allocator/aidl/android/hardware/graphics/allocator/BufferDescriptorInfo.aidl +16 −0 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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; Loading @@ -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; }
graphics/allocator/aidl/vts/VtsHalGraphicsAllocatorAidl_TargetTest.cpp +58 −0 Original line number Diff line number Diff line Loading @@ -217,6 +217,8 @@ class GraphicsTestsBase { } return ret; } int32_t allocatorVersion() const { return mIAllocatorVersion; } }; BufferHandle::~BufferHandle() { Loading Loading @@ -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<BufferUsage>(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"}, Loading