diff options
author | 2017-12-27 14:59:29 -0800 | |
---|---|---|
committer | 2018-01-22 12:42:33 -0800 | |
commit | e6ecb920255d4dd4182ced22c75cc7c49355b469 (patch) | |
tree | 1f093388f1c38fc99b3060ce217ab3f82e1280f4 /libs/ui/Gralloc2.cpp | |
parent | 380a5388a83a22f913a48f97fee68364f98fc5d0 (diff) |
Add new AHardwareBuffer formats and usages with latest HAL change
This time we also mask out EXTERNAL_DISP since it is not supported
in HIDL.
Bug: 66900669
Test: build, and added validation logic to Gralloc2 and
GrallocBufferMapper.
Change-Id: I7f4174581e24e361577640b9263514a168ed482d
Diffstat (limited to 'libs/ui/Gralloc2.cpp')
-rw-r--r-- | libs/ui/Gralloc2.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/libs/ui/Gralloc2.cpp b/libs/ui/Gralloc2.cpp index 1f746a2ed1..60ec38c459 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,40 @@ 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; + } + // TODO(b/72323293): Remove this mask for EXTERNAL_DISP. + bits = bits | (1 << 13); + + 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 +83,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) { |