From 332765e8e3b0abae5cfce298c68d3b1015e2b641 Mon Sep 17 00:00:00 2001 From: Alec Mouri Date: Wed, 6 Oct 2021 16:38:12 -0700 Subject: Update gralloc wrappers to support querying SMPTE 2094-10 metadata Bug: 200309502 Test: builds Test: GrallocTypes_test Change-Id: Ia5b17d414d1ed83612e402e2615814f23d18830c --- libs/ui/Gralloc4.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'libs/ui/Gralloc4.cpp') diff --git a/libs/ui/Gralloc4.cpp b/libs/ui/Gralloc4.cpp index 80f6c82bb0..8ac08fb70d 100644 --- a/libs/ui/Gralloc4.cpp +++ b/libs/ui/Gralloc4.cpp @@ -634,6 +634,12 @@ status_t Gralloc4Mapper::getSmpte2094_40( outSmpte2094_40); } +status_t Gralloc4Mapper::getSmpte2094_10( + buffer_handle_t bufferHandle, std::optional>* outSmpte2094_10) const { + return get(bufferHandle, gralloc4::MetadataType_Smpte2094_10, gralloc4::decodeSmpte2094_10, + outSmpte2094_10); +} + template status_t Gralloc4Mapper::getDefault(uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage, -- cgit v1.2.3-59-g8ed1b From 04511efdf0678d8c022313e34d0c71764495885f Mon Sep 17 00:00:00 2001 From: Alec Mouri Date: Thu, 6 Jan 2022 12:57:12 -0800 Subject: Report gralloc4 buffer size in fixed fp notation Scientific notation is a little harder to read. Bug: None Test: dumpsys SurfaceFlinger Change-Id: Ic17052e57256aca64b6007f30b7dbfdcb09f3b65 --- libs/ui/Gralloc4.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'libs/ui/Gralloc4.cpp') diff --git a/libs/ui/Gralloc4.cpp b/libs/ui/Gralloc4.cpp index 8ac08fb70d..3fc99bb3fc 100644 --- a/libs/ui/Gralloc4.cpp +++ b/libs/ui/Gralloc4.cpp @@ -941,9 +941,10 @@ status_t Gralloc4Mapper::bufferDumpHelper(const BufferDump& bufferDump, std::ost } double allocationSizeKiB = static_cast(allocationSize) / 1024; - *outDump << "+ name:" << name << ", id:" << bufferId << ", size:" << allocationSizeKiB - << "KiB, w/h:" << width << "x" << height << ", usage: 0x" << std::hex << usage - << std::dec << ", req fmt:" << static_cast(pixelFormatRequested) + *outDump << "+ name:" << name << ", id:" << bufferId << ", size:" << std::fixed + << allocationSizeKiB << "KiB, w/h:" << width << "x" << height << ", usage: 0x" + << std::hex << usage << std::dec + << ", req fmt:" << static_cast(pixelFormatRequested) << ", fourcc/mod:" << pixelFormatFourCC << "/" << pixelFormatModifier << ", dataspace: 0x" << std::hex << static_cast(dataspace) << std::dec << ", compressed: "; -- cgit v1.2.3-59-g8ed1b From 614326b0e5a01bc60caad788f93111cfed98b8c4 Mon Sep 17 00:00:00 2001 From: John Reck Date: Tue, 11 Jan 2022 15:49:54 -0500 Subject: Add front buffer gralloc usage Test: builds & boots, still needs real tests Bug: 193558894 Change-Id: Iaf0421ad897966d13a4c231edf9ce78056e059a2 --- libs/ui/Android.bp | 3 ++ libs/ui/Gralloc4.cpp | 94 +++++++++++++++++++++++++++++++++++++++++++ libs/ui/include/ui/Gralloc4.h | 3 ++ 3 files changed, 100 insertions(+) (limited to 'libs/ui/Gralloc4.cpp') diff --git a/libs/ui/Android.bp b/libs/ui/Android.bp index 006c4780ad..e9f3633e14 100644 --- a/libs/ui/Android.bp +++ b/libs/ui/Android.bp @@ -160,6 +160,7 @@ cc_library_shared { "android.hardware.graphics.allocator@2.0", "android.hardware.graphics.allocator@3.0", "android.hardware.graphics.allocator@4.0", + "android.hardware.graphics.allocator-V1-ndk", "android.hardware.graphics.common-V3-ndk", "android.hardware.graphics.common@1.2", "android.hardware.graphics.mapper@2.0", @@ -167,6 +168,7 @@ cc_library_shared { "android.hardware.graphics.mapper@3.0", "android.hardware.graphics.mapper@4.0", "libbase", + "libbinder_ndk", "libcutils", "libgralloctypes", "libhidlbase", @@ -183,6 +185,7 @@ cc_library_shared { ], static_libs: [ + "libaidlcommonsupport", "libarect", "libgrallocusage", "libmath", diff --git a/libs/ui/Gralloc4.cpp b/libs/ui/Gralloc4.cpp index 8ac08fb70d..9241709c8c 100644 --- a/libs/ui/Gralloc4.cpp +++ b/libs/ui/Gralloc4.cpp @@ -16,6 +16,12 @@ #define LOG_TAG "Gralloc4" +#include +#include +#include +#include +#include +#include #include #include #include @@ -27,6 +33,8 @@ #include #pragma clang diagnostic pop +using aidl::android::hardware::graphics::allocator::AllocationError; +using aidl::android::hardware::graphics::allocator::AllocationResult; using aidl::android::hardware::graphics::common::ExtendableType; using aidl::android::hardware::graphics::common::PlaneLayoutComponentType; using aidl::android::hardware::graphics::common::StandardMetadataType; @@ -36,7 +44,10 @@ using android::hardware::graphics::common::V1_2::BufferUsage; using android::hardware::graphics::mapper::V4_0::BufferDescriptor; using android::hardware::graphics::mapper::V4_0::Error; using android::hardware::graphics::mapper::V4_0::IMapper; +using AidlIAllocator = ::aidl::android::hardware::graphics::allocator::IAllocator; +using AidlBufferUsage = ::aidl::android::hardware::graphics::common::BufferUsage; using AidlDataspace = ::aidl::android::hardware::graphics::common::Dataspace; +using AidlNativeHandle = ::aidl::android::hardware::common::NativeHandle; using BufferDump = android::hardware::graphics::mapper::V4_0::IMapper::BufferDump; using MetadataDump = android::hardware::graphics::mapper::V4_0::IMapper::MetadataDump; using MetadataType = android::hardware::graphics::mapper::V4_0::IMapper::MetadataType; @@ -48,6 +59,7 @@ namespace android { namespace { static constexpr Error kTransactionError = Error::NO_RESOURCES; +static const auto kAidlAllocatorServiceName = AidlIAllocator::descriptor + std::string("/default"); uint64_t getValidUsageBits() { static const uint64_t validUsageBits = []() -> uint64_t { @@ -61,6 +73,17 @@ uint64_t getValidUsageBits() { return validUsageBits; } +uint64_t getValidUsageBits41() { + static const uint64_t validUsageBits = []() -> uint64_t { + uint64_t bits = 0; + for (const auto bit : ndk::enum_range{}) { + bits |= static_cast(bit); + } + return bits; + }(); + return validUsageBits; +} + static inline IMapper::Rect sGralloc4Rect(const Rect& rect) { IMapper::Rect outRect{}; outRect.left = rect.left; @@ -81,6 +104,21 @@ static inline void sBufferDescriptorInfo(std::string name, uint32_t width, uint3 outDescriptorInfo->reservedSize = 0; } +// See if gralloc "4.1" is available. +static bool hasIAllocatorAidl() { + // Avoid re-querying repeatedly for this information; + static bool sHasIAllocatorAidl = []() -> bool { + // TODO: Enable after landing sepolicy changes + if constexpr ((true)) return false; + + if (__builtin_available(android 31, *)) { + return AServiceManager_isDeclared(kAidlAllocatorServiceName.c_str()); + } + return false; + }(); + return sHasIAllocatorAidl; +} + } // anonymous namespace void Gralloc4Mapper::preload() { @@ -105,6 +143,9 @@ bool Gralloc4Mapper::isLoaded() const { status_t Gralloc4Mapper::validateBufferDescriptorInfo( IMapper::BufferDescriptorInfo* descriptorInfo) const { uint64_t validUsageBits = getValidUsageBits(); + if (hasIAllocatorAidl()) { + validUsageBits |= getValidUsageBits41(); + } if (descriptorInfo->usage & ~validUsageBits) { ALOGE("buffer descriptor contains invalid usage bits 0x%" PRIx64, @@ -1069,6 +1110,13 @@ Gralloc4Allocator::Gralloc4Allocator(const Gralloc4Mapper& mapper) : mMapper(map ALOGW("allocator 4.x is not supported"); return; } + if (__builtin_available(android 31, *)) { + if (hasIAllocatorAidl()) { + mAidlAllocator = AidlIAllocator::fromBinder(ndk::SpAIBinder( + AServiceManager_waitForService(kAidlAllocatorServiceName.c_str()))); + ALOGE_IF(!mAidlAllocator, "AIDL IAllocator declared but failed to get service"); + } + } } bool Gralloc4Allocator::isLoaded() const { @@ -1093,6 +1141,52 @@ status_t Gralloc4Allocator::allocate(std::string requestorName, uint32_t width, return error; } + if (mAidlAllocator) { + AllocationResult result; + auto status = mAidlAllocator->allocate(descriptor, bufferCount, &result); + if (!status.isOk()) { + error = status.getExceptionCode(); + if (error == EX_SERVICE_SPECIFIC) { + error = status.getServiceSpecificError(); + } + if (error == OK) { + error = UNKNOWN_ERROR; + } + } else { + if (importBuffers) { + for (uint32_t i = 0; i < bufferCount; i++) { + error = mMapper.importBuffer(makeFromAidl(result.buffers[i]), + &outBufferHandles[i]); + if (error != NO_ERROR) { + for (uint32_t j = 0; j < i; j++) { + mMapper.freeBuffer(outBufferHandles[j]); + outBufferHandles[j] = nullptr; + } + break; + } + } + } else { + for (uint32_t i = 0; i < bufferCount; i++) { + outBufferHandles[i] = dupFromAidl(result.buffers[i]); + if (!outBufferHandles[i]) { + for (uint32_t j = 0; j < i; j++) { + auto buffer = const_cast(outBufferHandles[j]); + native_handle_close(buffer); + native_handle_delete(buffer); + outBufferHandles[j] = nullptr; + } + } + } + } + } + *outStride = result.stride; + // Release all the resources held by AllocationResult (specifically any remaining FDs) + result = {}; + // make sure the kernel driver sees BC_FREE_BUFFER and closes the fds now + hardware::IPCThreadState::self()->flushCommands(); + return error; + } + auto ret = mAllocator->allocate(descriptor, bufferCount, [&](const auto& tmpError, const auto& tmpStride, const auto& tmpBuffers) { diff --git a/libs/ui/include/ui/Gralloc4.h b/libs/ui/include/ui/Gralloc4.h index 62f9e4a53f..6bafcd6c81 100644 --- a/libs/ui/include/ui/Gralloc4.h +++ b/libs/ui/include/ui/Gralloc4.h @@ -17,6 +17,7 @@ #ifndef ANDROID_UI_GRALLOC4_H #define ANDROID_UI_GRALLOC4_H +#include #include #include #include @@ -204,6 +205,8 @@ public: private: const Gralloc4Mapper& mMapper; sp mAllocator; + // Optional "4.1" allocator + std::shared_ptr mAidlAllocator; }; } // namespace android -- cgit v1.2.3-59-g8ed1b From e071138365de28bd83526fb90677b080302cc14f Mon Sep 17 00:00:00 2001 From: John Reck Date: Wed, 26 Jan 2022 12:10:59 -0500 Subject: Fix mismatch between isSupported & allocate isSupported failed to validate usage bits like allocate does, meaning that isSupported can return true if a vendor is unaware of a usage bit but then allocate will (correctly!) fail to allocate. Fix this so that all buffer descriptions go through the same validation path. Bug: 216478685 Test: atest HardwareBufferTest#testInvalidUsage Change-Id: Idc9a0837f555beceb604f27a06e4833f41e97261 --- libs/ui/Gralloc4.cpp | 81 ++++++++++++++++++++++++++----------------- libs/ui/include/ui/Gralloc4.h | 4 --- 2 files changed, 49 insertions(+), 36 deletions(-) (limited to 'libs/ui/Gralloc4.cpp') diff --git a/libs/ui/Gralloc4.cpp b/libs/ui/Gralloc4.cpp index 1f8a2f058f..e02632460f 100644 --- a/libs/ui/Gralloc4.cpp +++ b/libs/ui/Gralloc4.cpp @@ -92,17 +92,6 @@ static inline IMapper::Rect sGralloc4Rect(const Rect& rect) { outRect.height = rect.height(); return outRect; } -static inline void sBufferDescriptorInfo(std::string name, uint32_t width, uint32_t height, - PixelFormat format, uint32_t layerCount, uint64_t usage, - IMapper::BufferDescriptorInfo* outDescriptorInfo) { - outDescriptorInfo->name = name; - outDescriptorInfo->width = width; - outDescriptorInfo->height = height; - outDescriptorInfo->layerCount = layerCount; - outDescriptorInfo->format = static_cast(format); - outDescriptorInfo->usage = usage; - outDescriptorInfo->reservedSize = 0; -} // See if gralloc "4.1" is available. static bool hasIAllocatorAidl() { @@ -119,6 +108,36 @@ static bool hasIAllocatorAidl() { return sHasIAllocatorAidl; } +// Determines whether the passed info is compatible with the mapper. +static status_t validateBufferDescriptorInfo(IMapper::BufferDescriptorInfo* descriptorInfo) { + uint64_t validUsageBits = getValidUsageBits(); + if (hasIAllocatorAidl()) { + validUsageBits |= getValidUsageBits41(); + } + + if (descriptorInfo->usage & ~validUsageBits) { + ALOGE("buffer descriptor contains invalid usage bits 0x%" PRIx64, + descriptorInfo->usage & ~validUsageBits); + return BAD_VALUE; + } + return NO_ERROR; +} + +static inline status_t sBufferDescriptorInfo(std::string name, uint32_t width, uint32_t height, + PixelFormat format, uint32_t layerCount, + uint64_t usage, + IMapper::BufferDescriptorInfo* outDescriptorInfo) { + outDescriptorInfo->name = name; + outDescriptorInfo->width = width; + outDescriptorInfo->height = height; + outDescriptorInfo->layerCount = layerCount; + outDescriptorInfo->format = static_cast(format); + outDescriptorInfo->usage = usage; + outDescriptorInfo->reservedSize = 0; + + return validateBufferDescriptorInfo(outDescriptorInfo); +} + } // anonymous namespace void Gralloc4Mapper::preload() { @@ -140,21 +159,6 @@ bool Gralloc4Mapper::isLoaded() const { return mMapper != nullptr; } -status_t Gralloc4Mapper::validateBufferDescriptorInfo( - IMapper::BufferDescriptorInfo* descriptorInfo) const { - uint64_t validUsageBits = getValidUsageBits(); - if (hasIAllocatorAidl()) { - validUsageBits |= getValidUsageBits41(); - } - - if (descriptorInfo->usage & ~validUsageBits) { - ALOGE("buffer descriptor contains invalid usage bits 0x%" PRIx64, - descriptorInfo->usage & ~validUsageBits); - return BAD_VALUE; - } - return NO_ERROR; -} - status_t Gralloc4Mapper::createDescriptor(void* bufferDescriptorInfo, void* outBufferDescriptor) const { IMapper::BufferDescriptorInfo* descriptorInfo = @@ -207,8 +211,10 @@ status_t Gralloc4Mapper::validateBufferSize(buffer_handle_t bufferHandle, uint32 uint32_t layerCount, uint64_t usage, uint32_t stride) const { IMapper::BufferDescriptorInfo descriptorInfo; - sBufferDescriptorInfo("validateBufferSize", width, height, format, layerCount, usage, - &descriptorInfo); + if (auto error = sBufferDescriptorInfo("validateBufferSize", width, height, format, layerCount, + usage, &descriptorInfo) != OK) { + return error; + } auto buffer = const_cast(bufferHandle); auto ret = mMapper->validateBufferSize(buffer, descriptorInfo, stride); @@ -427,7 +433,7 @@ int Gralloc4Mapper::unlock(buffer_handle_t bufferHandle) const { if (fd >= 0) { releaseFence = fd; } else { - ALOGD("failed to dup unlock release fence"); + ALOGW("failed to dup unlock release fence"); sync_wait(fenceHandle->data[0], -1); } } @@ -448,7 +454,12 @@ status_t Gralloc4Mapper::isSupported(uint32_t width, uint32_t height, PixelForma uint32_t layerCount, uint64_t usage, bool* outSupported) const { IMapper::BufferDescriptorInfo descriptorInfo; - sBufferDescriptorInfo("isSupported", width, height, format, layerCount, usage, &descriptorInfo); + if (auto error = sBufferDescriptorInfo("isSupported", width, height, format, layerCount, usage, + &descriptorInfo) != OK) { + // Usage isn't known to the HAL or otherwise failed validation. + *outSupported = false; + return OK; + } Error error; auto ret = mMapper->isSupported(descriptorInfo, @@ -691,7 +702,10 @@ status_t Gralloc4Mapper::getDefault(uint32_t width, uint32_t height, PixelFormat } IMapper::BufferDescriptorInfo descriptorInfo; - sBufferDescriptorInfo("getDefault", width, height, format, layerCount, usage, &descriptorInfo); + if (auto error = sBufferDescriptorInfo("getDefault", width, height, format, layerCount, usage, + &descriptorInfo) != OK) { + return error; + } hidl_vec vec; Error error; @@ -1133,7 +1147,10 @@ status_t Gralloc4Allocator::allocate(std::string requestorName, uint32_t width, uint64_t usage, uint32_t bufferCount, uint32_t* outStride, buffer_handle_t* outBufferHandles, bool importBuffers) const { IMapper::BufferDescriptorInfo descriptorInfo; - sBufferDescriptorInfo(requestorName, width, height, format, layerCount, usage, &descriptorInfo); + if (auto error = sBufferDescriptorInfo(requestorName, width, height, format, layerCount, usage, + &descriptorInfo) != OK) { + return error; + } BufferDescriptor descriptor; status_t error = mMapper.createDescriptor(static_cast(&descriptorInfo), diff --git a/libs/ui/include/ui/Gralloc4.h b/libs/ui/include/ui/Gralloc4.h index 6bafcd6c81..fe387090cc 100644 --- a/libs/ui/include/ui/Gralloc4.h +++ b/libs/ui/include/ui/Gralloc4.h @@ -155,10 +155,6 @@ public: private: friend class GraphicBufferAllocator; - // Determines whether the passed info is compatible with the mapper. - status_t validateBufferDescriptorInfo( - hardware::graphics::mapper::V4_0::IMapper::BufferDescriptorInfo* descriptorInfo) const; - template using DecodeFunction = status_t (*)(const hardware::hidl_vec& input, T* output); -- cgit v1.2.3-59-g8ed1b From a4df5019c4291ea1e9fb8a7b6eda6ebb51ad6b18 Mon Sep 17 00:00:00 2001 From: John Reck Date: Fri, 28 Jan 2022 12:24:32 -0500 Subject: Enable querying for IAllcoatorAidl sepolicy changes have merged through Bug: 193558894 Test: build, boot, verify no sepolicy errors Change-Id: I5fe2739e98d15d6bdff7966c321c874ed371f810 --- libs/ui/Gralloc4.cpp | 3 --- 1 file changed, 3 deletions(-) (limited to 'libs/ui/Gralloc4.cpp') diff --git a/libs/ui/Gralloc4.cpp b/libs/ui/Gralloc4.cpp index 1f8a2f058f..bdd3529bb2 100644 --- a/libs/ui/Gralloc4.cpp +++ b/libs/ui/Gralloc4.cpp @@ -108,9 +108,6 @@ static inline void sBufferDescriptorInfo(std::string name, uint32_t width, uint3 static bool hasIAllocatorAidl() { // Avoid re-querying repeatedly for this information; static bool sHasIAllocatorAidl = []() -> bool { - // TODO: Enable after landing sepolicy changes - if constexpr ((true)) return false; - if (__builtin_available(android 31, *)) { return AServiceManager_isDeclared(kAidlAllocatorServiceName.c_str()); } -- cgit v1.2.3-59-g8ed1b From 6c09ee7f4ec0c38766f6de2ad922d85a5035f565 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Wed, 26 Jan 2022 18:48:55 +1300 Subject: gralloc: Move validation of non-blob/gpu_data_buffer down to libui AIDL gralloc implementations may choose to support this combination. Existing implementations of HIDL gralloc 2/3/4 do not support it, and do not reliably reject it due to having been previously protected by validation at the AHardwareBuffer layer. Move the check down to the gralloc layer, and defer to the HAL only in the AIDL case. Bug: b/195944622 Test: build; real CTS/VTS to land soon after. Change-Id: I7b0b9de005a9b0f564915f9c71cc8aea3ef0618a --- libs/nativewindow/AHardwareBuffer.cpp | 4 ---- libs/ui/Gralloc2.cpp | 9 +++++++++ libs/ui/Gralloc3.cpp | 9 +++++++++ libs/ui/Gralloc4.cpp | 11 +++++++++++ 4 files changed, 29 insertions(+), 4 deletions(-) (limited to 'libs/ui/Gralloc4.cpp') diff --git a/libs/nativewindow/AHardwareBuffer.cpp b/libs/nativewindow/AHardwareBuffer.cpp index cb3361b431..2578ee8467 100644 --- a/libs/nativewindow/AHardwareBuffer.cpp +++ b/libs/nativewindow/AHardwareBuffer.cpp @@ -509,10 +509,6 @@ bool AHardwareBuffer_isValidDescription(const AHardwareBuffer_Desc* desc, bool l ALOGE_IF(log, "AHARDWAREBUFFER_USAGE_SENSOR_DIRECT_DATA requires AHARDWAREBUFFER_FORMAT_BLOB"); return false; } - if (desc->usage & AHARDWAREBUFFER_USAGE_GPU_DATA_BUFFER) { - ALOGE_IF(log, "AHARDWAREBUFFER_USAGE_GPU_DATA_BUFFER requires AHARDWAREBUFFER_FORMAT_BLOB"); - return false; - } } if ((desc->usage & (AHARDWAREBUFFER_USAGE_CPU_READ_MASK | AHARDWAREBUFFER_USAGE_CPU_WRITE_MASK)) && diff --git a/libs/ui/Gralloc2.cpp b/libs/ui/Gralloc2.cpp index 040a62b542..f23f10a1a9 100644 --- a/libs/ui/Gralloc2.cpp +++ b/libs/ui/Gralloc2.cpp @@ -110,6 +110,15 @@ status_t Gralloc2Mapper::validateBufferDescriptorInfo( descriptorInfo->usage & ~validUsageBits); return BAD_VALUE; } + + // Gralloc2 implementations never understand non-BLOB with GPU_DATA_BUFFER + // and do not reliably reject it. + if (descriptorInfo->usage & BufferUsage::GPU_DATA_BUFFER && + descriptorInfo->format != hardware::graphics::common::V1_1::PixelFormat::BLOB) { + ALOGE("gralloc2 does not support non-BLOB pixel formats with GPU_DATA_BUFFER usage"); + return BAD_VALUE; + } + return NO_ERROR; } diff --git a/libs/ui/Gralloc3.cpp b/libs/ui/Gralloc3.cpp index 882674f479..15c60bcadf 100644 --- a/libs/ui/Gralloc3.cpp +++ b/libs/ui/Gralloc3.cpp @@ -101,6 +101,15 @@ status_t Gralloc3Mapper::validateBufferDescriptorInfo( descriptorInfo->usage & ~validUsageBits); return BAD_VALUE; } + + // Gralloc3 implementations never understand non-BLOB with GPU_DATA_BUFFER + // and do not reliably reject it. + if (descriptorInfo->usage & BufferUsage::GPU_DATA_BUFFER && + descriptorInfo->format != hardware::graphics::common::V1_2::PixelFormat::BLOB) { + ALOGE("gralloc3 does not support non-BLOB pixel formats with GPU_DATA_BUFFER usage"); + return BAD_VALUE; + } + return NO_ERROR; } diff --git a/libs/ui/Gralloc4.cpp b/libs/ui/Gralloc4.cpp index e02632460f..9922d6afaf 100644 --- a/libs/ui/Gralloc4.cpp +++ b/libs/ui/Gralloc4.cpp @@ -41,6 +41,7 @@ using aidl::android::hardware::graphics::common::StandardMetadataType; using android::hardware::hidl_vec; using android::hardware::graphics::allocator::V4_0::IAllocator; using android::hardware::graphics::common::V1_2::BufferUsage; +using android::hardware::graphics::common::V1_2::PixelFormat; using android::hardware::graphics::mapper::V4_0::BufferDescriptor; using android::hardware::graphics::mapper::V4_0::Error; using android::hardware::graphics::mapper::V4_0::IMapper; @@ -120,6 +121,16 @@ static status_t validateBufferDescriptorInfo(IMapper::BufferDescriptorInfo* desc descriptorInfo->usage & ~validUsageBits); return BAD_VALUE; } + + // Combinations that are only allowed with gralloc 4.1. + // Previous grallocs must be protected from this. + if (!hasIAllocatorAidl() && + descriptorInfo->format != hardware::graphics::common::V1_2::PixelFormat::BLOB && + descriptorInfo->usage & BufferUsage::GPU_DATA_BUFFER) { + ALOGE("non-BLOB pixel format with GPU_DATA_BUFFER usage is not supported prior to gralloc 4.1"); + return BAD_VALUE; + } + return NO_ERROR; } -- cgit v1.2.3-59-g8ed1b From 38b59415d336b4f0de1441deb87a39a8e3e390cc Mon Sep 17 00:00:00 2001 From: Robin Lee Date: Wed, 2 Feb 2022 22:53:15 +0100 Subject: Gralloc4: accept invalid 0x2400 usage bits - 0x2000 is EXTERNAL_DISP which acodec2 sets. See b/72323293 - 0x0400 is USAGE_HW_2D which hikey sets. See b/72703005 Bug: 217506693 Change-Id: I3260e9e78ef62fc3f216d4478191ad3013047658 --- libs/ui/Gralloc4.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'libs/ui/Gralloc4.cpp') diff --git a/libs/ui/Gralloc4.cpp b/libs/ui/Gralloc4.cpp index c97cc94dd5..1a42642838 100644 --- a/libs/ui/Gralloc4.cpp +++ b/libs/ui/Gralloc4.cpp @@ -62,6 +62,9 @@ namespace { static constexpr Error kTransactionError = Error::NO_RESOURCES; static const auto kAidlAllocatorServiceName = AidlIAllocator::descriptor + std::string("/default"); +// TODO(b/72323293, b/72703005): Remove these invalid bits from callers +static constexpr uint64_t kRemovedUsageBits = static_cast((1 << 10) | (1 << 13)); + uint64_t getValidUsageBits() { static const uint64_t validUsageBits = []() -> uint64_t { uint64_t bits = 0; @@ -71,7 +74,7 @@ uint64_t getValidUsageBits() { } return bits; }(); - return validUsageBits; + return validUsageBits | kRemovedUsageBits; } uint64_t getValidUsageBits41() { -- cgit v1.2.3-59-g8ed1b From 9c604e3c31869d1a7a1654ea791267a29b053966 Mon Sep 17 00:00:00 2001 From: Alec Mouri Date: Fri, 18 Mar 2022 22:47:44 +0000 Subject: Polish up metadata propagation for native window Allow for native window apis to attempt to apply gralloc4 metadata whenever a buffer is queued onto a native window for dataspace and existing apis for HDR metadata. Motivation: 1. We are attempting to move to Gralloc 4 metadata as the source of truth for this information, rather than a separate side-channel. 2. ANativeWindow_setBuffersDataspace is a public api, but gralloc4 metadata is not public, so the only way to keep the gralloc4 metadata in sync for dataspace is to intercept on Surface. 3. HDR Metadata may be applied on eglSurface and vkSwapchain, which must be propagated to gralloc4 metadata to ensure consistency. 4. None of the plumbing for setting gralloc4 metadata existed, so now's a good time as any to add the plumbing so that we can start at least best-effort using this metadata infrastructure in the framework and so that vendor's don't have to reinvent setting metadata. Bug: 210498094 Test: builds, boots Change-Id: I6d19dc4ceca8fa885363faf84f57885e58e88240 --- libs/gui/Surface.cpp | 13 +++++++ libs/gui/include/gui/HdrMetadata.h | 23 ++++++++++++ libs/gui/include/gui/Surface.h | 7 ++++ libs/ui/Gralloc4.cpp | 61 ++++++++++++++++++++++++++++++++ libs/ui/GraphicBufferMapper.cpp | 24 +++++++++++++ libs/ui/include/ui/Gralloc.h | 21 ++++++++++- libs/ui/include/ui/Gralloc4.h | 18 +++++++++- libs/ui/include/ui/GraphicBufferMapper.h | 7 ++++ libs/ui/include/ui/GraphicTypes.h | 18 ++++++++++ 9 files changed, 190 insertions(+), 2 deletions(-) (limited to 'libs/ui/Gralloc4.cpp') diff --git a/libs/gui/Surface.cpp b/libs/gui/Surface.cpp index 20c41460d4..1fb11e0675 100644 --- a/libs/gui/Surface.cpp +++ b/libs/gui/Surface.cpp @@ -1096,6 +1096,17 @@ void Surface::getQueueBufferInputLocked(android_native_buffer_t* buffer, int fen *out = input; } +void Surface::applyGrallocMetadataLocked( + android_native_buffer_t* buffer, + const IGraphicBufferProducer::QueueBufferInput& queueBufferInput) { + ATRACE_CALL(); + auto& mapper = GraphicBufferMapper::get(); + mapper.setDataspace(buffer->handle, static_cast(queueBufferInput.dataSpace)); + mapper.setSmpte2086(buffer->handle, queueBufferInput.getHdrMetadata().getSmpte2086()); + mapper.setCta861_3(buffer->handle, queueBufferInput.getHdrMetadata().getCta8613()); + mapper.setSmpte2094_40(buffer->handle, queueBufferInput.getHdrMetadata().getHdr10Plus()); +} + void Surface::onBufferQueuedLocked(int slot, sp fence, const IGraphicBufferProducer::QueueBufferOutput& output) { mDequeuedSlots.erase(slot); @@ -1166,9 +1177,11 @@ int Surface::queueBuffer(android_native_buffer_t* buffer, int fenceFd) { IGraphicBufferProducer::QueueBufferOutput output; IGraphicBufferProducer::QueueBufferInput input; getQueueBufferInputLocked(buffer, fenceFd, mTimestamp, &input); + applyGrallocMetadataLocked(buffer, input); sp fence = input.fence; nsecs_t now = systemTime(); + status_t err = mGraphicBufferProducer->queueBuffer(i, input, &output); mLastQueueDuration = systemTime() - now; if (err != OK) { diff --git a/libs/gui/include/gui/HdrMetadata.h b/libs/gui/include/gui/HdrMetadata.h index 0bdffac5c6..98a07a3c07 100644 --- a/libs/gui/include/gui/HdrMetadata.h +++ b/libs/gui/include/gui/HdrMetadata.h @@ -17,6 +17,8 @@ #pragma once #include +#include +#include #include #include @@ -43,6 +45,27 @@ struct HdrMetadata : public LightFlattenable { status_t flatten(void* buffer, size_t size) const; status_t unflatten(void const* buffer, size_t size); + std::optional getSmpte2086() const { + if (validTypes & Type::SMPTE2086) { + return ui::translate(smpte2086); + } + return {}; + } + + std::optional getCta8613() const { + if (validTypes & Type::CTA861_3) { + return ui::translate(cta8613); + } + return {}; + } + + std::optional> getHdr10Plus() const { + if (validTypes & Type::HDR10PLUS) { + return hdr10plus; + } + return {}; + } + bool operator==(const HdrMetadata& rhs) const; bool operator!=(const HdrMetadata& rhs) const { return !(*this == rhs); } }; diff --git a/libs/gui/include/gui/Surface.h b/libs/gui/include/gui/Surface.h index 40d096e1e5..5fe308cf9f 100644 --- a/libs/gui/include/gui/Surface.h +++ b/libs/gui/include/gui/Surface.h @@ -398,6 +398,13 @@ protected: void getQueueBufferInputLocked(android_native_buffer_t* buffer, int fenceFd, nsecs_t timestamp, IGraphicBufferProducer::QueueBufferInput* out); + // For easing in adoption of gralloc4 metadata by vendor components, as well as for supporting + // the public ANativeWindow api, allow setting relevant metadata when queueing a buffer through + // a native window + void applyGrallocMetadataLocked( + android_native_buffer_t* buffer, + const IGraphicBufferProducer::QueueBufferInput& queueBufferInput); + void onBufferQueuedLocked(int slot, sp fence, const IGraphicBufferProducer::QueueBufferOutput& output); diff --git a/libs/ui/Gralloc4.cpp b/libs/ui/Gralloc4.cpp index 1a42642838..8de91dac61 100644 --- a/libs/ui/Gralloc4.cpp +++ b/libs/ui/Gralloc4.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -524,6 +525,37 @@ status_t Gralloc4Mapper::get(buffer_handle_t bufferHandle, const MetadataType& m return decodeFunction(vec, outMetadata); } +template +status_t Gralloc4Mapper::set(buffer_handle_t bufferHandle, const MetadataType& metadataType, + const T& metadata, EncodeFunction encodeFunction) const { + hidl_vec encodedMetadata; + if (const status_t status = encodeFunction(metadata, &encodedMetadata); status != OK) { + ALOGE("Encoding metadata(%s) failed with %d", metadataType.name.c_str(), status); + return status; + } + hidl_vec vec; + auto ret = + mMapper->set(const_cast(bufferHandle), metadataType, encodedMetadata); + + const Error error = ret.withDefault(kTransactionError); + switch (error) { + case Error::BAD_DESCRIPTOR: + case Error::BAD_BUFFER: + case Error::BAD_VALUE: + case Error::NO_RESOURCES: + ALOGE("set(%s, %" PRIu64 ", ...) failed with %d", metadataType.name.c_str(), + metadataType.value, error); + break; + // It is not an error to attempt to set metadata that a particular gralloc implementation + // happens to not support. + case Error::UNSUPPORTED: + case Error::NONE: + break; + } + + return static_cast(error); +} + status_t Gralloc4Mapper::getBufferId(buffer_handle_t bufferHandle, uint64_t* outBufferId) const { return get(bufferHandle, gralloc4::MetadataType_BufferId, gralloc4::decodeBufferId, outBufferId); @@ -673,6 +705,12 @@ status_t Gralloc4Mapper::getDataspace(buffer_handle_t bufferHandle, return NO_ERROR; } +status_t Gralloc4Mapper::setDataspace(buffer_handle_t bufferHandle, ui::Dataspace dataspace) const { + return set(bufferHandle, gralloc4::MetadataType_Dataspace, + static_cast(dataspace), + gralloc4::encodeDataspace); +} + status_t Gralloc4Mapper::getBlendMode(buffer_handle_t bufferHandle, ui::BlendMode* outBlendMode) const { return get(bufferHandle, gralloc4::MetadataType_BlendMode, gralloc4::decodeBlendMode, @@ -685,24 +723,47 @@ status_t Gralloc4Mapper::getSmpte2086(buffer_handle_t bufferHandle, outSmpte2086); } +status_t Gralloc4Mapper::setSmpte2086(buffer_handle_t bufferHandle, + std::optional smpte2086) const { + return set(bufferHandle, gralloc4::MetadataType_Smpte2086, smpte2086, + gralloc4::encodeSmpte2086); +} + status_t Gralloc4Mapper::getCta861_3(buffer_handle_t bufferHandle, std::optional* outCta861_3) const { return get(bufferHandle, gralloc4::MetadataType_Cta861_3, gralloc4::decodeCta861_3, outCta861_3); } +status_t Gralloc4Mapper::setCta861_3(buffer_handle_t bufferHandle, + std::optional cta861_3) const { + return set(bufferHandle, gralloc4::MetadataType_Cta861_3, cta861_3, gralloc4::encodeCta861_3); +} + status_t Gralloc4Mapper::getSmpte2094_40( buffer_handle_t bufferHandle, std::optional>* outSmpte2094_40) const { return get(bufferHandle, gralloc4::MetadataType_Smpte2094_40, gralloc4::decodeSmpte2094_40, outSmpte2094_40); } +status_t Gralloc4Mapper::setSmpte2094_40(buffer_handle_t bufferHandle, + std::optional> smpte2094_40) const { + return set(bufferHandle, gralloc4::MetadataType_Smpte2094_40, smpte2094_40, + gralloc4::encodeSmpte2094_40); +} + status_t Gralloc4Mapper::getSmpte2094_10( buffer_handle_t bufferHandle, std::optional>* outSmpte2094_10) const { return get(bufferHandle, gralloc4::MetadataType_Smpte2094_10, gralloc4::decodeSmpte2094_10, outSmpte2094_10); } +status_t Gralloc4Mapper::setSmpte2094_10(buffer_handle_t bufferHandle, + std::optional> smpte2094_10) const { + return set(bufferHandle, gralloc4::MetadataType_Smpte2094_10, smpte2094_10, + gralloc4::encodeSmpte2094_10); +} + template status_t Gralloc4Mapper::getDefault(uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage, diff --git a/libs/ui/GraphicBufferMapper.cpp b/libs/ui/GraphicBufferMapper.cpp index 82d6cd5ba3..a98e697eb1 100644 --- a/libs/ui/GraphicBufferMapper.cpp +++ b/libs/ui/GraphicBufferMapper.cpp @@ -281,6 +281,10 @@ status_t GraphicBufferMapper::getDataspace(buffer_handle_t bufferHandle, return mMapper->getDataspace(bufferHandle, outDataspace); } +status_t GraphicBufferMapper::setDataspace(buffer_handle_t bufferHandle, ui::Dataspace dataspace) { + return mMapper->setDataspace(bufferHandle, dataspace); +} + status_t GraphicBufferMapper::getBlendMode(buffer_handle_t bufferHandle, ui::BlendMode* outBlendMode) { return mMapper->getBlendMode(bufferHandle, outBlendMode); @@ -291,21 +295,41 @@ status_t GraphicBufferMapper::getSmpte2086(buffer_handle_t bufferHandle, return mMapper->getSmpte2086(bufferHandle, outSmpte2086); } +status_t GraphicBufferMapper::setSmpte2086(buffer_handle_t bufferHandle, + std::optional smpte2086) { + return mMapper->setSmpte2086(bufferHandle, smpte2086); +} + status_t GraphicBufferMapper::getCta861_3(buffer_handle_t bufferHandle, std::optional* outCta861_3) { return mMapper->getCta861_3(bufferHandle, outCta861_3); } +status_t GraphicBufferMapper::setCta861_3(buffer_handle_t bufferHandle, + std::optional cta861_3) { + return mMapper->setCta861_3(bufferHandle, cta861_3); +} + status_t GraphicBufferMapper::getSmpte2094_40( buffer_handle_t bufferHandle, std::optional>* outSmpte2094_40) { return mMapper->getSmpte2094_40(bufferHandle, outSmpte2094_40); } +status_t GraphicBufferMapper::setSmpte2094_40(buffer_handle_t bufferHandle, + std::optional> smpte2094_40) { + return mMapper->setSmpte2094_40(bufferHandle, smpte2094_40); +} + status_t GraphicBufferMapper::getSmpte2094_10( buffer_handle_t bufferHandle, std::optional>* outSmpte2094_10) { return mMapper->getSmpte2094_10(bufferHandle, outSmpte2094_10); } +status_t GraphicBufferMapper::setSmpte2094_10(buffer_handle_t bufferHandle, + std::optional> smpte2094_10) { + return mMapper->setSmpte2094_10(bufferHandle, smpte2094_10); +} + status_t GraphicBufferMapper::getDefaultPixelFormatFourCC(uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage, diff --git a/libs/ui/include/ui/Gralloc.h b/libs/ui/include/ui/Gralloc.h index 753b0a6794..6101d4b43b 100644 --- a/libs/ui/include/ui/Gralloc.h +++ b/libs/ui/include/ui/Gralloc.h @@ -161,6 +161,10 @@ public: ui::Dataspace* /*outDataspace*/) const { return INVALID_OPERATION; } + virtual status_t setDataspace(buffer_handle_t /*bufferHandle*/, + ui::Dataspace /*dataspace*/) const { + return INVALID_OPERATION; + } virtual status_t getBlendMode(buffer_handle_t /*bufferHandle*/, ui::BlendMode* /*outBlendMode*/) const { return INVALID_OPERATION; @@ -169,21 +173,36 @@ public: std::optional* /*outSmpte2086*/) const { return INVALID_OPERATION; } + virtual status_t setSmpte2086(buffer_handle_t /*bufferHandle*/, + std::optional /*smpte2086*/) const { + return INVALID_OPERATION; + } virtual status_t getCta861_3(buffer_handle_t /*bufferHandle*/, std::optional* /*outCta861_3*/) const { return INVALID_OPERATION; } + virtual status_t setCta861_3(buffer_handle_t /*bufferHandle*/, + std::optional /*cta861_3*/) const { + return INVALID_OPERATION; + } virtual status_t getSmpte2094_40( buffer_handle_t /*bufferHandle*/, std::optional>* /*outSmpte2094_40*/) const { return INVALID_OPERATION; } + virtual status_t setSmpte2094_40(buffer_handle_t /*bufferHandle*/, + std::optional> /*smpte2094_40*/) const { + return INVALID_OPERATION; + } virtual status_t getSmpte2094_10( buffer_handle_t /*bufferHandle*/, std::optional>* /*outSmpte2094_10*/) const { return INVALID_OPERATION; } - + virtual status_t setSmpte2094_10(buffer_handle_t /*bufferHandle*/, + std::optional> /*smpte2094_10*/) const { + return INVALID_OPERATION; + } virtual status_t getDefaultPixelFormatFourCC(uint32_t /*width*/, uint32_t /*height*/, PixelFormat /*format*/, uint32_t /*layerCount*/, uint64_t /*usage*/, diff --git a/libs/ui/include/ui/Gralloc4.h b/libs/ui/include/ui/Gralloc4.h index fe387090cc..cf023c9bcc 100644 --- a/libs/ui/include/ui/Gralloc4.h +++ b/libs/ui/include/ui/Gralloc4.h @@ -102,16 +102,24 @@ public: status_t getPlaneLayouts(buffer_handle_t bufferHandle, std::vector* outPlaneLayouts) const override; status_t getDataspace(buffer_handle_t bufferHandle, ui::Dataspace* outDataspace) const override; + status_t setDataspace(buffer_handle_t bufferHandle, ui::Dataspace dataspace) const override; status_t getBlendMode(buffer_handle_t bufferHandle, ui::BlendMode* outBlendMode) const override; status_t getSmpte2086(buffer_handle_t bufferHandle, std::optional* outSmpte2086) const override; + status_t setSmpte2086(buffer_handle_t bufferHandle, + std::optional smpte2086) const override; status_t getCta861_3(buffer_handle_t bufferHandle, std::optional* outCta861_3) const override; + status_t setCta861_3(buffer_handle_t bufferHandle, + std::optional cta861_3) const override; status_t getSmpte2094_40(buffer_handle_t bufferHandle, std::optional>* outSmpte2094_40) const override; + status_t setSmpte2094_40(buffer_handle_t bufferHandle, + std::optional> smpte2094_40) const override; status_t getSmpte2094_10(buffer_handle_t bufferHandle, std::optional>* outSmpte2094_10) const override; - + status_t setSmpte2094_10(buffer_handle_t bufferHandle, + std::optional> smpte2094_10) const override; status_t getDefaultPixelFormatFourCC(uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage, uint32_t* outPixelFormatFourCC) const override; @@ -157,6 +165,8 @@ private: template using DecodeFunction = status_t (*)(const hardware::hidl_vec& input, T* output); + template + using EncodeFunction = status_t (*)(const T& input, hardware::hidl_vec* output); template status_t get( @@ -164,6 +174,12 @@ private: const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType& metadataType, DecodeFunction decodeFunction, T* outMetadata) const; + template + status_t set( + buffer_handle_t bufferHandle, + const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType& metadataType, + const T& metadata, EncodeFunction encodeFunction) const; + template status_t getDefault( uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, diff --git a/libs/ui/include/ui/GraphicBufferMapper.h b/libs/ui/include/ui/GraphicBufferMapper.h index 257c155efd..507fa355a4 100644 --- a/libs/ui/include/ui/GraphicBufferMapper.h +++ b/libs/ui/include/ui/GraphicBufferMapper.h @@ -121,13 +121,20 @@ public: status_t getPlaneLayouts(buffer_handle_t bufferHandle, std::vector* outPlaneLayouts); status_t getDataspace(buffer_handle_t bufferHandle, ui::Dataspace* outDataspace); + status_t setDataspace(buffer_handle_t bufferHandle, ui::Dataspace dataspace); status_t getBlendMode(buffer_handle_t bufferHandle, ui::BlendMode* outBlendMode); status_t getSmpte2086(buffer_handle_t bufferHandle, std::optional* outSmpte2086); + status_t setSmpte2086(buffer_handle_t bufferHandle, std::optional smpte2086); status_t getCta861_3(buffer_handle_t bufferHandle, std::optional* outCta861_3); + status_t setCta861_3(buffer_handle_t bufferHandle, std::optional cta861_3); status_t getSmpte2094_40(buffer_handle_t bufferHandle, std::optional>* outSmpte2094_40); + status_t setSmpte2094_40(buffer_handle_t bufferHandle, + std::optional> smpte2094_40); status_t getSmpte2094_10(buffer_handle_t bufferHandle, std::optional>* outSmpte2094_10); + status_t setSmpte2094_10(buffer_handle_t bufferHandle, + std::optional> smpte2094_10); /** * Gets the default metadata for a gralloc buffer allocated with the given parameters. diff --git a/libs/ui/include/ui/GraphicTypes.h b/libs/ui/include/ui/GraphicTypes.h index 4bdacb0883..8661c36676 100644 --- a/libs/ui/include/ui/GraphicTypes.h +++ b/libs/ui/include/ui/GraphicTypes.h @@ -62,5 +62,23 @@ using ChromaSiting = aidl::android::hardware::graphics::common::ChromaSiting; using Compression = aidl::android::hardware::graphics::common::Compression; using Interlaced = aidl::android::hardware::graphics::common::Interlaced; +inline aidl::android::hardware::graphics::common::XyColor translate(const android_xy_color& color) { + return aidl::android::hardware::graphics::common::XyColor{.x = color.x, .y = color.y}; +} + +inline Smpte2086 translate(const android_smpte2086_metadata& metadata) { + return Smpte2086{.primaryRed = translate(metadata.displayPrimaryRed), + .primaryGreen = translate(metadata.displayPrimaryGreen), + .primaryBlue = translate(metadata.displayPrimaryBlue), + .whitePoint = translate(metadata.whitePoint), + .maxLuminance = metadata.maxLuminance, + .minLuminance = metadata.minLuminance}; +} + +inline Cta861_3 translate(const android_cta861_3_metadata& metadata) { + return Cta861_3{.maxContentLightLevel = metadata.maxContentLightLevel, + .maxFrameAverageLightLevel = metadata.maxFrameAverageLightLevel}; +} + } // namespace ui } // namespace android -- cgit v1.2.3-59-g8ed1b From e401e88200dbd4acb8a6f9694490ac53254de809 Mon Sep 17 00:00:00 2001 From: Devin Moore Date: Mon, 11 Apr 2022 22:41:58 +0000 Subject: Allow AIDL allocator service to be used by itself The HIDL service was required to be available all of the time. Bug: 205761012 Test: atest hal_implementation_test Test: Build and boot cuttlefish without the HIDL service Change-Id: I31dda32ee1758f55d745d00ab06ed890378e5e21 --- libs/ui/Gralloc4.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'libs/ui/Gralloc4.cpp') diff --git a/libs/ui/Gralloc4.cpp b/libs/ui/Gralloc4.cpp index 1fce31d877..4f950b8c4a 100644 --- a/libs/ui/Gralloc4.cpp +++ b/libs/ui/Gralloc4.cpp @@ -1193,10 +1193,6 @@ std::string Gralloc4Mapper::dumpBuffers(bool less) const { Gralloc4Allocator::Gralloc4Allocator(const Gralloc4Mapper& mapper) : mMapper(mapper) { mAllocator = IAllocator::getService(); - if (mAllocator == nullptr) { - ALOGW("allocator 4.x is not supported"); - return; - } if (__builtin_available(android 31, *)) { if (hasIAllocatorAidl()) { mAidlAllocator = AidlIAllocator::fromBinder(ndk::SpAIBinder( @@ -1204,10 +1200,14 @@ Gralloc4Allocator::Gralloc4Allocator(const Gralloc4Mapper& mapper) : mMapper(map ALOGE_IF(!mAidlAllocator, "AIDL IAllocator declared but failed to get service"); } } + if (mAllocator == nullptr && mAidlAllocator == nullptr) { + ALOGW("allocator 4.x is not supported"); + return; + } } bool Gralloc4Allocator::isLoaded() const { - return mAllocator != nullptr; + return mAllocator != nullptr || mAidlAllocator != nullptr; } std::string Gralloc4Allocator::dumpDebugInfo(bool less) const { -- cgit v1.2.3-59-g8ed1b From 14ec0809e70202dfd9bab6fa662bb4f73c2089d2 Mon Sep 17 00:00:00 2001 From: Christopher Ferris Date: Fri, 22 Apr 2022 13:23:43 -0700 Subject: Close native handle properly. Bug: 229900304 Test: No leaks from this location. Change-Id: Ib2618b0a5b55be648d0f12536e84a3a1b355b660 --- libs/ui/Gralloc4.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'libs/ui/Gralloc4.cpp') diff --git a/libs/ui/Gralloc4.cpp b/libs/ui/Gralloc4.cpp index 4f950b8c4a..f6ab7b2a5e 100644 --- a/libs/ui/Gralloc4.cpp +++ b/libs/ui/Gralloc4.cpp @@ -1245,8 +1245,9 @@ status_t Gralloc4Allocator::allocate(std::string requestorName, uint32_t width, } else { if (importBuffers) { for (uint32_t i = 0; i < bufferCount; i++) { - error = mMapper.importBuffer(makeFromAidl(result.buffers[i]), - &outBufferHandles[i]); + auto handle = makeFromAidl(result.buffers[i]); + error = mMapper.importBuffer(handle, &outBufferHandles[i]); + native_handle_delete(handle); if (error != NO_ERROR) { for (uint32_t j = 0; j < i; j++) { mMapper.freeBuffer(outBufferHandles[j]); -- cgit v1.2.3-59-g8ed1b