diff options
-rw-r--r-- | libs/nativewindow/AHardwareBuffer.cpp | 26 | ||||
-rw-r--r-- | libs/nativewindow/Android.bp | 2 | ||||
-rw-r--r-- | libs/nativewindow/include/android/hardware_buffer.h | 50 | ||||
-rw-r--r-- | libs/ui/Gralloc2.cpp | 58 | ||||
-rw-r--r-- | libs/ui/GraphicBufferMapper.cpp | 1 | ||||
-rw-r--r-- | libs/ui/include/ui/Gralloc2.h | 7 |
6 files changed, 138 insertions, 6 deletions
diff --git a/libs/nativewindow/AHardwareBuffer.cpp b/libs/nativewindow/AHardwareBuffer.cpp index ed292e7bae..a2712b4e05 100644 --- a/libs/nativewindow/AHardwareBuffer.cpp +++ b/libs/nativewindow/AHardwareBuffer.cpp @@ -29,7 +29,7 @@ #include <system/graphics.h> #include <private/android/AHardwareBufferHelpers.h> -#include <android/hardware/graphics/common/1.0/types.h> +#include <android/hardware/graphics/common/1.1/types.h> static constexpr int kFdBufferSize = 128 * sizeof(int); // 128 ints @@ -311,6 +311,18 @@ bool AHardwareBuffer_isValidPixelFormat(uint32_t format) { "HAL and AHardwareBuffer pixel format don't match"); static_assert(HAL_PIXEL_FORMAT_BLOB == AHARDWAREBUFFER_FORMAT_BLOB, "HAL and AHardwareBuffer pixel format don't match"); + static_assert(HAL_PIXEL_FORMAT_DEPTH_16 == AHARDWAREBUFFER_FORMAT_D16_UNORM, + "HAL and AHardwareBuffer pixel format don't match"); + static_assert(HAL_PIXEL_FORMAT_DEPTH_24 == AHARDWAREBUFFER_FORMAT_D24_UNORM, + "HAL and AHardwareBuffer pixel format don't match"); + static_assert(HAL_PIXEL_FORMAT_DEPTH_24_STENCIL_8 == AHARDWAREBUFFER_FORMAT_D24_UNORM_S8_UINT, + "HAL and AHardwareBuffer pixel format don't match"); + static_assert(HAL_PIXEL_FORMAT_DEPTH_32F == AHARDWAREBUFFER_FORMAT_D32_FLOAT, + "HAL and AHardwareBuffer pixel format don't match"); + static_assert(HAL_PIXEL_FORMAT_DEPTH_32F_STENCIL_8 == AHARDWAREBUFFER_FORMAT_D32_FLOAT_S8_UINT, + "HAL and AHardwareBuffer pixel format don't match"); + static_assert(HAL_PIXEL_FORMAT_STENCIL_8 == AHARDWAREBUFFER_FORMAT_S8_UINT, + "HAL and AHardwareBuffer pixel format don't match"); static_assert(HAL_PIXEL_FORMAT_BGRA_8888 == AHARDWAREBUFFER_FORMAT_B8G8R8A8_UNORM, "HAL and AHardwareBuffer pixel format don't match"); static_assert(HAL_PIXEL_FORMAT_YV12 == AHARDWAREBUFFER_FORMAT_YV12, @@ -354,6 +366,12 @@ bool AHardwareBuffer_isValidPixelFormat(uint32_t format) { case AHARDWAREBUFFER_FORMAT_R16G16B16A16_FLOAT: case AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM: case AHARDWAREBUFFER_FORMAT_BLOB: + case AHARDWAREBUFFER_FORMAT_D16_UNORM: + case AHARDWAREBUFFER_FORMAT_D24_UNORM: + case AHARDWAREBUFFER_FORMAT_D24_UNORM_S8_UINT: + case AHARDWAREBUFFER_FORMAT_D32_FLOAT: + case AHARDWAREBUFFER_FORMAT_D32_FLOAT_S8_UINT: + case AHARDWAREBUFFER_FORMAT_S8_UINT: // VNDK formats only -- unfortunately we can't differentiate from where we're called case AHARDWAREBUFFER_FORMAT_B8G8R8A8_UNORM: case AHARDWAREBUFFER_FORMAT_YV12: @@ -388,7 +406,7 @@ uint32_t AHardwareBuffer_convertToPixelFormat(uint32_t ahardwarebuffer_format) { } uint64_t AHardwareBuffer_convertToGrallocUsageBits(uint64_t usage) { - using android::hardware::graphics::common::V1_0::BufferUsage; + using android::hardware::graphics::common::V1_1::BufferUsage; static_assert(AHARDWAREBUFFER_USAGE_CPU_READ_NEVER == (uint64_t)BufferUsage::CPU_READ_NEVER, "gralloc and AHardwareBuffer flags don't match"); static_assert(AHARDWAREBUFFER_USAGE_CPU_READ_RARELY == (uint64_t)BufferUsage::CPU_READ_RARELY, @@ -413,6 +431,10 @@ uint64_t AHardwareBuffer_convertToGrallocUsageBits(uint64_t usage) { "gralloc and AHardwareBuffer flags don't match"); static_assert(AHARDWAREBUFFER_USAGE_SENSOR_DIRECT_DATA == (uint64_t)BufferUsage::SENSOR_DIRECT_DATA, "gralloc and AHardwareBuffer flags don't match"); + static_assert(AHARDWAREBUFFER_USAGE_GPU_CUBE_MAP == (uint64_t)BufferUsage::GPU_CUBE_MAP, + "gralloc and AHardwareBuffer flags don't match"); + static_assert(AHARDWAREBUFFER_USAGE_GPU_MIPMAP_COMPLETE == (uint64_t)BufferUsage::GPU_MIPMAP_COMPLETE, + "gralloc and AHardwareBuffer flags don't match"); return usage; } diff --git a/libs/nativewindow/Android.bp b/libs/nativewindow/Android.bp index 29555fde9d..5fbb3b2f87 100644 --- a/libs/nativewindow/Android.bp +++ b/libs/nativewindow/Android.bp @@ -60,7 +60,7 @@ cc_library { "liblog", "libutils", "libui", - "android.hardware.graphics.common@1.0", + "android.hardware.graphics.common@1.1", ], static_libs: [ diff --git a/libs/nativewindow/include/android/hardware_buffer.h b/libs/nativewindow/include/android/hardware_buffer.h index 52440a5b79..a477bf2f3f 100644 --- a/libs/nativewindow/include/android/hardware_buffer.h +++ b/libs/nativewindow/include/android/hardware_buffer.h @@ -80,6 +80,48 @@ enum { * the buffer size in bytes. */ AHARDWAREBUFFER_FORMAT_BLOB = 0x21, + + /** + * Corresponding formats: + * Vulkan: VK_FORMAT_D16_UNORM + * OpenGL ES: GL_DEPTH_COMPONENT16 + */ + AHARDWAREBUFFER_FORMAT_D16_UNORM = 0x30, + + /** + * Corresponding formats: + * Vulkan: VK_FORMAT_X8_D24_UNORM_PACK32 + * OpenGL ES: GL_DEPTH_COMPONENT24 + */ + AHARDWAREBUFFER_FORMAT_D24_UNORM = 0x31, + + /** + * Corresponding formats: + * Vulkan: VK_FORMAT_D24_UNORM_S8_UINT + * OpenGL ES: GL_DEPTH24_STENCIL8 + */ + AHARDWAREBUFFER_FORMAT_D24_UNORM_S8_UINT = 0x32, + + /** + * Corresponding formats: + * Vulkan: VK_FORMAT_D32_SFLOAT + * OpenGL ES: GL_DEPTH_COMPONENT32F + */ + AHARDWAREBUFFER_FORMAT_D32_FLOAT = 0x33, + + /** + * Corresponding formats: + * Vulkan: VK_FORMAT_D32_SFLOAT_S8_UINT + * OpenGL ES: GL_DEPTH32F_STENCIL8 + */ + AHARDWAREBUFFER_FORMAT_D32_FLOAT_S8_UINT = 0x34, + + /** + * Corresponding formats: + * Vulkan: VK_FORMAT_S8_UINT + * OpenGL ES: GL_STENCIL_INDEX8 + */ + AHARDWAREBUFFER_FORMAT_S8_UINT = 0x35, }; enum { @@ -109,10 +151,14 @@ enum { AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT = 1UL << 14, /* The buffer will be read by a hardware video encoder */ AHARDWAREBUFFER_USAGE_VIDEO_ENCODE = 1UL << 16, - /** The buffer will be used for sensor direct data */ + /* The buffer will be used for sensor direct data */ AHARDWAREBUFFER_USAGE_SENSOR_DIRECT_DATA = 1UL << 23, - /* The buffer will be used as a shader storage or uniform buffer object*/ + /* The buffer will be used as a shader storage or uniform buffer object */ AHARDWAREBUFFER_USAGE_GPU_DATA_BUFFER = 1UL << 24, + /* The buffer will be used as a cube map texture */ + AHARDWAREBUFFER_USAGE_GPU_CUBE_MAP = 1UL << 25, + /* The buffer contains a complete mipmap hierarchy */ + AHARDWAREBUFFER_USAGE_GPU_MIPMAP_COMPLETE = 1UL << 26, AHARDWAREBUFFER_USAGE_VENDOR_0 = 1ULL << 28, AHARDWAREBUFFER_USAGE_VENDOR_1 = 1ULL << 29, diff --git a/libs/ui/Gralloc2.cpp b/libs/ui/Gralloc2.cpp index 1f746a2ed1..deaf8d3024 100644 --- a/libs/ui/Gralloc2.cpp +++ b/libs/ui/Gralloc2.cpp @@ -20,6 +20,7 @@ #include <hwbinder/IPCThreadState.h> #include <ui/Gralloc2.h> +#include <inttypes.h> #include <log/log.h> #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wzero-length-array" @@ -30,8 +31,37 @@ namespace android { namespace Gralloc2 { +namespace { + static constexpr Error kTransactionError = Error::NO_RESOURCES; +uint64_t getValid10UsageBits() { + static const uint64_t valid10UsageBits = []() -> uint64_t { + using hardware::graphics::common::V1_0::BufferUsage; + uint64_t bits = 0; + for (const auto bit : hardware::hidl_enum_iterator<BufferUsage>()) { + bits = bits | bit; + } + return bits; + }(); + return valid10UsageBits; +} + +uint64_t getValid11UsageBits() { + static const uint64_t valid11UsageBits = []() -> uint64_t { + using hardware::graphics::common::V1_1::BufferUsage; + uint64_t bits = 0; + for (const auto bit : hardware::hidl_enum_iterator<BufferUsage>()) { + bits = bits | bit; + } + // Return only the overlapping bits. + return bits & ~getValid10UsageBits(); + }(); + return valid11UsageBits; +} + +} // anonymous namespace + void Mapper::preload() { android::hardware::preloadPassthroughService<hardware::graphics::mapper::V2_0::IMapper>(); } @@ -50,11 +80,39 @@ Mapper::Mapper() mMapperV2_1 = hardware::graphics::mapper::V2_1::IMapper::castFrom(mMapper); } +Gralloc2::Error Mapper::validateBufferDescriptorInfo( + const IMapper::BufferDescriptorInfo& descriptorInfo) const { + uint64_t validUsageBits = getValid10UsageBits(); + if (mMapperV2_1 != nullptr) { + validUsageBits = validUsageBits | getValid11UsageBits(); + } + + if (descriptorInfo.usage & ~validUsageBits) { + ALOGE("buffer descriptor contains invalid usage bits 0x%" PRIx64, + descriptorInfo.usage & ~validUsageBits); + return Error::BAD_VALUE; + } + return Error::NONE; +} + Error Mapper::createDescriptor( const IMapper::BufferDescriptorInfo& descriptorInfo, BufferDescriptor* outDescriptor) const { Error error; + + if (descriptorInfo.usage & getValid11UsageBits()) { + // TODO(b/66900669): Use mMapperV2_1->createDescriptorV2_1(). + ALOGW("full support for new usage bits is unimplemented 0x%" PRIx64, + descriptorInfo.usage & getValid11UsageBits()); + return Error::BAD_VALUE; + } + + error = validateBufferDescriptorInfo(descriptorInfo); + if (error != Error::NONE) { + return error; + } + auto ret = mMapper->createDescriptor(descriptorInfo, [&](const auto& tmpError, const auto& tmpDescriptor) { diff --git a/libs/ui/GraphicBufferMapper.cpp b/libs/ui/GraphicBufferMapper.cpp index 2cac2874a8..2d8e5824b0 100644 --- a/libs/ui/GraphicBufferMapper.cpp +++ b/libs/ui/GraphicBufferMapper.cpp @@ -72,6 +72,7 @@ status_t GraphicBufferMapper::importBuffer(buffer_handle_t rawHandle, info.layerCount = layerCount; info.format = static_cast<Gralloc2::PixelFormat>(format); info.usage = usage; + error = mMapper->validateBufferSize(bufferHandle, info, stride); if (error != Gralloc2::Error::NONE) { ALOGE("validateBufferSize(%p) failed: %d", rawHandle, error); diff --git a/libs/ui/include/ui/Gralloc2.h b/libs/ui/include/ui/Gralloc2.h index 69c35f7dda..db3f10a1ae 100644 --- a/libs/ui/include/ui/Gralloc2.h +++ b/libs/ui/include/ui/Gralloc2.h @@ -20,6 +20,7 @@ #include <string> #include <android/hardware/graphics/allocator/2.0/IAllocator.h> +#include <android/hardware/graphics/common/1.1/types.h> #include <android/hardware/graphics/mapper/2.0/IMapper.h> #include <android/hardware/graphics/mapper/2.1/IMapper.h> #include <utils/StrongPointer.h> @@ -29,8 +30,8 @@ namespace android { namespace Gralloc2 { using hardware::graphics::allocator::V2_0::IAllocator; -using hardware::graphics::common::V1_0::BufferUsage; using hardware::graphics::common::V1_0::PixelFormat; +using hardware::graphics::common::V1_1::BufferUsage; using hardware::graphics::mapper::V2_0::BufferDescriptor; using hardware::graphics::mapper::V2_0::Error; using hardware::graphics::mapper::V2_0::IMapper; @@ -80,6 +81,10 @@ public: int unlock(buffer_handle_t bufferHandle) const; private: + // Determines whether the passed info is compatible with the mapper. + Error validateBufferDescriptorInfo( + const IMapper::BufferDescriptorInfo& descriptorInfo) const; + sp<IMapper> mMapper; sp<hardware::graphics::mapper::V2_1::IMapper> mMapperV2_1; }; |