From 0ff95c9b2f9d85cac2015aa4de5731c6d5e1a060 Mon Sep 17 00:00:00 2001 From: John Reck Date: Thu, 8 Dec 2022 11:45:29 -0500 Subject: Add IMapper 5 implementation Fixes: 205761028 Test: boots on CF w/ mapper4 removed Change-Id: I062ba3160fae972757669241fedcaf6ac3c6c12b --- libs/ui/Gralloc5.cpp | 903 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 903 insertions(+) create mode 100644 libs/ui/Gralloc5.cpp (limited to 'libs/ui/Gralloc5.cpp') diff --git a/libs/ui/Gralloc5.cpp b/libs/ui/Gralloc5.cpp new file mode 100644 index 0000000000..6f196b86d5 --- /dev/null +++ b/libs/ui/Gralloc5.cpp @@ -0,0 +1,903 @@ +/* + * Copyright (C) 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "Gralloc5" +#define ATRACE_TAG ATRACE_TAG_GRAPHICS + +#include + +#include +#include +#include +#include +#include +#include +#include + +using namespace aidl::android::hardware::graphics::allocator; +using namespace aidl::android::hardware::graphics::common; +using namespace ::android::hardware::graphics::mapper; + +namespace android { + +static const auto kIAllocatorServiceName = IAllocator::descriptor + std::string("/default"); +static const auto kIAllocatorMinimumVersion = 2; + +// TODO(b/72323293, b/72703005): Remove these invalid bits from callers +static constexpr uint64_t kRemovedUsageBits = static_cast((1 << 10) | (1 << 13)); + +typedef AIMapper_Error (*AIMapper_loadIMapperFn)(AIMapper *_Nullable *_Nonnull outImplementation); + +struct Gralloc5 { + std::shared_ptr allocator; + AIMapper *mapper = nullptr; +}; + +static std::shared_ptr waitForAllocator() { + if (__builtin_available(android 31, *)) { + if (!AServiceManager_isDeclared(kIAllocatorServiceName.c_str())) { + return nullptr; + } + auto allocator = IAllocator::fromBinder( + ndk::SpAIBinder(AServiceManager_waitForService(kIAllocatorServiceName.c_str()))); + if (!allocator) { + ALOGE("AIDL IAllocator declared but failed to get service"); + return nullptr; + } + + int32_t version = 0; + if (!allocator->getInterfaceVersion(&version).isOk()) { + ALOGE("Failed to query interface version"); + return nullptr; + } + if (version < kIAllocatorMinimumVersion) { + return nullptr; + } + return allocator; + } else { + // TODO: LOG_ALWAYS_FATAL("libui is not backwards compatible"); + return nullptr; + } +} + +static void *loadIMapperLibrary() { + static void *imapperLibrary = []() -> void * { + auto allocator = waitForAllocator(); + std::string mapperSuffix; + auto status = allocator->getIMapperLibrarySuffix(&mapperSuffix); + if (!status.isOk()) { + ALOGE("Failed to get IMapper library suffix"); + return nullptr; + } + + std::string lib_name = "mapper." + mapperSuffix + ".so"; + void *so = android_load_sphal_library(lib_name.c_str(), RTLD_LOCAL | RTLD_NOW); + if (!so) { + ALOGE("Failed to load %s", lib_name.c_str()); + } + return so; + }(); + return imapperLibrary; +} + +static const Gralloc5 &getInstance() { + static Gralloc5 instance = []() { + auto allocator = waitForAllocator(); + if (!allocator) { + return Gralloc5{}; + } + void *so = loadIMapperLibrary(); + if (!so) { + return Gralloc5{}; + } + auto loadIMapper = (AIMapper_loadIMapperFn)dlsym(so, "AIMapper_loadIMapper"); + AIMapper *mapper = nullptr; + AIMapper_Error error = loadIMapper(&mapper); + if (error != AIMAPPER_ERROR_NONE) { + ALOGE("AIMapper_loadIMapper failed %d", error); + return Gralloc5{}; + } + return Gralloc5{std::move(allocator), mapper}; + }(); + return instance; +} + +template +static auto getStandardMetadata(AIMapper *mapper, buffer_handle_t bufferHandle) + -> decltype(StandardMetadata::value::decode(nullptr, 0)) { + using Value = typename StandardMetadata::value; + // TODO: Tune for common-case better + FatVector buffer; + int32_t sizeRequired = mapper->v5.getStandardMetadata(bufferHandle, static_cast(T), + buffer.data(), buffer.size()); + if (sizeRequired < 0) { + ALOGW_IF(-AIMAPPER_ERROR_UNSUPPORTED != sizeRequired, + "Unexpected error %d from valid getStandardMetadata call", -sizeRequired); + return std::nullopt; + } + if ((size_t)sizeRequired > buffer.size()) { + buffer.resize(sizeRequired); + sizeRequired = mapper->v5.getStandardMetadata(bufferHandle, static_cast(T), + buffer.data(), buffer.size()); + } + if (sizeRequired < 0 || (size_t)sizeRequired > buffer.size()) { + ALOGW("getStandardMetadata failed, received %d with buffer size %zd", sizeRequired, + buffer.size()); + // Generate a fail type + return std::nullopt; + } + return Value::decode(buffer.data(), sizeRequired); +} + +template +static AIMapper_Error setStandardMetadata(AIMapper *mapper, buffer_handle_t bufferHandle, + const typename StandardMetadata::value_type &value) { + using Value = typename StandardMetadata::value; + int32_t sizeRequired = Value::encode(value, nullptr, 0); + if (sizeRequired < 0) { + ALOGW("Failed to calculate required size"); + return static_cast(-sizeRequired); + } + FatVector buffer; + buffer.resize(sizeRequired); + sizeRequired = Value::encode(value, buffer.data(), buffer.size()); + if (sizeRequired < 0 || (size_t)sizeRequired > buffer.size()) { + ALOGW("Failed to encode with calculated size %d; buffer size %zd", sizeRequired, + buffer.size()); + return static_cast(-sizeRequired); + } + return mapper->v5.setStandardMetadata(bufferHandle, static_cast(T), buffer.data(), + sizeRequired); +} + +Gralloc5Allocator::Gralloc5Allocator(const Gralloc5Mapper &mapper) : mMapper(mapper) { + mAllocator = getInstance().allocator; +} + +bool Gralloc5Allocator::isLoaded() const { + return mAllocator != nullptr; +} + +static uint64_t getValidUsageBits() { + 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 | kRemovedUsageBits; +} + +static std::optional makeDescriptor(std::string requestorName, uint32_t width, + uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage) { + uint64_t validUsageBits = getValidUsageBits(); + if (usage & ~validUsageBits) { + ALOGE("buffer descriptor contains invalid usage bits 0x%" PRIx64, usage & ~validUsageBits); + return std::nullopt; + } + + BufferDescriptorInfo descriptorInfo{ + .width = static_cast(width), + .height = static_cast(height), + .layerCount = static_cast(layerCount), + .format = static_cast<::aidl::android::hardware::graphics::common::PixelFormat>(format), + .usage = static_cast(usage), + }; + auto nameLength = std::min(requestorName.length(), descriptorInfo.name.size() - 1); + memcpy(descriptorInfo.name.data(), requestorName.data(), nameLength); + requestorName.data()[nameLength] = 0; + return descriptorInfo; +} + +std::string Gralloc5Allocator::dumpDebugInfo(bool less) const { + return mMapper.dumpBuffers(less); +} + +status_t Gralloc5Allocator::allocate(std::string requestorName, uint32_t width, uint32_t height, + android::PixelFormat format, uint32_t layerCount, + uint64_t usage, uint32_t bufferCount, uint32_t *outStride, + buffer_handle_t *outBufferHandles, bool importBuffers) const { + auto descriptorInfo = makeDescriptor(requestorName, width, height, format, layerCount, usage); + if (!descriptorInfo) { + return BAD_VALUE; + } + + AllocationResult result; + auto status = mAllocator->allocate2(*descriptorInfo, bufferCount, &result); + if (!status.isOk()) { + auto error = status.getExceptionCode(); + if (error == EX_SERVICE_SPECIFIC) { + error = status.getServiceSpecificError(); + } + if (error == OK) { + error = UNKNOWN_ERROR; + } + return error; + } + + if (importBuffers) { + for (uint32_t i = 0; i < bufferCount; i++) { + auto handle = makeFromAidl(result.buffers[i]); + auto 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]); + outBufferHandles[j] = nullptr; + } + return error; + } + } + } 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; + } + return NO_MEMORY; + } + } + } + + *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 + // TODO: Re-enable this at some point if it's necessary. We can't do it now because libui + // is marked apex_available (b/214400477) and libbinder isn't (which of course is correct) + // IPCThreadState::self()->flushCommands(); + + return OK; +} + +void Gralloc5Mapper::preload() { + // TODO(b/261858155): Implement. We can't bounce off of IAllocator for this because zygote can't + // use binder. So when an alternate strategy of retrieving the library prefix is available, + // use that here. +} + +Gralloc5Mapper::Gralloc5Mapper() { + mMapper = getInstance().mapper; +} + +bool Gralloc5Mapper::isLoaded() const { + return mMapper != nullptr && mMapper->version >= AIMAPPER_VERSION_5; +} + +std::string Gralloc5Mapper::dumpBuffer(buffer_handle_t bufferHandle, bool less) const { + // TODO(b/261858392): Implement + (void)bufferHandle; + (void)less; + return {}; +} + +std::string Gralloc5Mapper::dumpBuffers(bool less) const { + // TODO(b/261858392): Implement + (void)less; + return {}; +} + +status_t Gralloc5Mapper::importBuffer(const native_handle_t *rawHandle, + buffer_handle_t *outBufferHandle) const { + return mMapper->v5.importBuffer(rawHandle, outBufferHandle); +} + +void Gralloc5Mapper::freeBuffer(buffer_handle_t bufferHandle) const { + mMapper->v5.freeBuffer(bufferHandle); +} + +status_t Gralloc5Mapper::validateBufferSize(buffer_handle_t bufferHandle, uint32_t width, + uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + uint32_t stride) const { + { + auto value = getStandardMetadata(mMapper, bufferHandle); + if (width != value) { + ALOGW("Width didn't match, expected %d got %" PRId64, width, value.value_or(-1)); + return BAD_VALUE; + } + } + { + auto value = getStandardMetadata(mMapper, bufferHandle); + if (height != value) { + ALOGW("Height didn't match, expected %d got %" PRId64, height, value.value_or(-1)); + return BAD_VALUE; + } + } + { + auto value = + getStandardMetadata(mMapper, + bufferHandle); + if (static_cast<::aidl::android::hardware::graphics::common::PixelFormat>(format) != + value) { + ALOGW("Format didn't match, expected %d got %s", format, + value.has_value() ? toString(*value).c_str() : ""); + return BAD_VALUE; + } + } + { + auto value = getStandardMetadata(mMapper, bufferHandle); + if (layerCount != value) { + ALOGW("Layer count didn't match, expected %d got %" PRId64, layerCount, + value.value_or(-1)); + return BAD_VALUE; + } + } + { + auto value = getStandardMetadata(mMapper, bufferHandle); + if (static_cast(usage) != value) { + ALOGW("Usage didn't match, expected %" PRIu64 " got %" PRId64, usage, + static_cast(value.value_or(BufferUsage::CPU_READ_NEVER))); + return BAD_VALUE; + } + } + { + (void)stride; + // TODO(b/261856851): Add StandardMetadataType::STRIDE && enable this + // auto value = getStandardMetadata(mMapper, + // bufferHandle); if (static_cast(usage) != value) { + // ALOGW("Layer count didn't match, expected %" PRIu64 " got %" PRId64, usage, + // static_cast(value.value_or(BufferUsage::CPU_READ_NEVER))); + // return BAD_VALUE; + // } + } + return OK; +} + +void Gralloc5Mapper::getTransportSize(buffer_handle_t bufferHandle, uint32_t *outNumFds, + uint32_t *outNumInts) const { + mMapper->v5.getTransportSize(bufferHandle, outNumFds, outNumInts); +} + +status_t Gralloc5Mapper::lock(buffer_handle_t bufferHandle, uint64_t usage, const Rect &bounds, + int acquireFence, void **outData, int32_t *outBytesPerPixel, + int32_t *outBytesPerStride) const { + std::vector planeLayouts; + status_t err = getPlaneLayouts(bufferHandle, &planeLayouts); + + if (err == NO_ERROR && !planeLayouts.empty()) { + if (outBytesPerPixel) { + int32_t bitsPerPixel = planeLayouts.front().sampleIncrementInBits; + for (const auto &planeLayout : planeLayouts) { + if (bitsPerPixel != planeLayout.sampleIncrementInBits) { + bitsPerPixel = -1; + } + } + if (bitsPerPixel >= 0 && bitsPerPixel % 8 == 0) { + *outBytesPerPixel = bitsPerPixel / 8; + } else { + *outBytesPerPixel = -1; + } + } + if (outBytesPerStride) { + int32_t bytesPerStride = planeLayouts.front().strideInBytes; + for (const auto &planeLayout : planeLayouts) { + if (bytesPerStride != planeLayout.strideInBytes) { + bytesPerStride = -1; + } + } + if (bytesPerStride >= 0) { + *outBytesPerStride = bytesPerStride; + } else { + *outBytesPerStride = -1; + } + } + } + + auto status = mMapper->v5.lock(bufferHandle, usage, bounds, acquireFence, outData); + + ALOGW_IF(status != AIMAPPER_ERROR_NONE, "lock(%p, ...) failed: %d", bufferHandle, status); + return static_cast(status); +} + +status_t Gralloc5Mapper::lock(buffer_handle_t bufferHandle, uint64_t usage, const Rect &bounds, + int acquireFence, android_ycbcr *outYcbcr) const { + if (!outYcbcr) { + return BAD_VALUE; + } + + // TODO(b/262279301): Change the return type of ::unlock to unique_fd instead of int so that + // ignoring the return value "just works" instead + auto unlock = [this](buffer_handle_t bufferHandle) { + int fence = this->unlock(bufferHandle); + if (fence != -1) { + ::close(fence); + } + }; + + std::vector planeLayouts; + status_t error = getPlaneLayouts(bufferHandle, &planeLayouts); + if (error != NO_ERROR) { + return error; + } + + void *data = nullptr; + error = lock(bufferHandle, usage, bounds, acquireFence, &data, nullptr, nullptr); + if (error != NO_ERROR) { + return error; + } + + android_ycbcr ycbcr; + + ycbcr.y = nullptr; + ycbcr.cb = nullptr; + ycbcr.cr = nullptr; + ycbcr.ystride = 0; + ycbcr.cstride = 0; + ycbcr.chroma_step = 0; + + for (const auto &planeLayout : planeLayouts) { + for (const auto &planeLayoutComponent : planeLayout.components) { + if (!gralloc4::isStandardPlaneLayoutComponentType(planeLayoutComponent.type)) { + continue; + } + + uint8_t *tmpData = static_cast(data) + planeLayout.offsetInBytes; + + // Note that `offsetInBits` may not be a multiple of 8 for packed formats (e.g. P010) + // but we still want to point to the start of the first byte. + tmpData += (planeLayoutComponent.offsetInBits / 8); + + uint64_t sampleIncrementInBytes; + + auto type = static_cast(planeLayoutComponent.type.value); + switch (type) { + case PlaneLayoutComponentType::Y: + if ((ycbcr.y != nullptr) || (planeLayout.sampleIncrementInBits % 8 != 0)) { + unlock(bufferHandle); + return BAD_VALUE; + } + ycbcr.y = tmpData; + ycbcr.ystride = planeLayout.strideInBytes; + break; + + case PlaneLayoutComponentType::CB: + case PlaneLayoutComponentType::CR: + if (planeLayout.sampleIncrementInBits % 8 != 0) { + unlock(bufferHandle); + return BAD_VALUE; + } + + sampleIncrementInBytes = planeLayout.sampleIncrementInBits / 8; + if ((sampleIncrementInBytes != 1) && (sampleIncrementInBytes != 2) && + (sampleIncrementInBytes != 4)) { + unlock(bufferHandle); + return BAD_VALUE; + } + + if (ycbcr.cstride == 0 && ycbcr.chroma_step == 0) { + ycbcr.cstride = planeLayout.strideInBytes; + ycbcr.chroma_step = sampleIncrementInBytes; + } else { + if ((static_cast(ycbcr.cstride) != planeLayout.strideInBytes) || + (ycbcr.chroma_step != sampleIncrementInBytes)) { + unlock(bufferHandle); + return BAD_VALUE; + } + } + + if (type == PlaneLayoutComponentType::CB) { + if (ycbcr.cb != nullptr) { + unlock(bufferHandle); + return BAD_VALUE; + } + ycbcr.cb = tmpData; + } else { + if (ycbcr.cr != nullptr) { + unlock(bufferHandle); + return BAD_VALUE; + } + ycbcr.cr = tmpData; + } + break; + default: + break; + }; + } + } + + *outYcbcr = ycbcr; + return OK; +} + +int Gralloc5Mapper::unlock(buffer_handle_t bufferHandle) const { + int fence = -1; + AIMapper_Error error = mMapper->v5.unlock(bufferHandle, &fence); + if (error != AIMAPPER_ERROR_NONE) { + ALOGW("unlock failed with error %d", error); + } + return fence; +} + +status_t Gralloc5Mapper::isSupported(uint32_t width, uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + bool *outSupported) const { + auto descriptorInfo = makeDescriptor("", width, height, format, layerCount, usage); + if (!descriptorInfo) { + *outSupported = false; + return OK; + } + auto status = getInstance().allocator->isSupported(*descriptorInfo, outSupported); + if (!status.isOk()) { + ALOGW("IAllocator::isSupported error %d (%s)", status.getStatus(), status.getMessage()); + *outSupported = false; + } + return OK; +} + +status_t Gralloc5Mapper::getBufferId(buffer_handle_t bufferHandle, uint64_t *outBufferId) const { + auto value = getStandardMetadata(mMapper, bufferHandle); + if (value.has_value()) { + *outBufferId = *value; + return OK; + } + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getName(buffer_handle_t bufferHandle, std::string *outName) const { + auto value = getStandardMetadata(mMapper, bufferHandle); + if (value.has_value()) { + *outName = *value; + return OK; + } + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getWidth(buffer_handle_t bufferHandle, uint64_t *outWidth) const { + auto value = getStandardMetadata(mMapper, bufferHandle); + if (value.has_value()) { + *outWidth = *value; + return OK; + } + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getHeight(buffer_handle_t bufferHandle, uint64_t *outHeight) const { + auto value = getStandardMetadata(mMapper, bufferHandle); + if (value.has_value()) { + *outHeight = *value; + return OK; + } + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getLayerCount(buffer_handle_t bufferHandle, + uint64_t *outLayerCount) const { + auto value = getStandardMetadata(mMapper, bufferHandle); + if (value.has_value()) { + *outLayerCount = *value; + return OK; + } + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getPixelFormatRequested(buffer_handle_t bufferHandle, + ui::PixelFormat *outPixelFormatRequested) const { + auto value = getStandardMetadata(mMapper, + bufferHandle); + if (value.has_value()) { + *outPixelFormatRequested = static_cast(*value); + return OK; + } + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getPixelFormatFourCC(buffer_handle_t bufferHandle, + uint32_t *outPixelFormatFourCC) const { + auto value = + getStandardMetadata(mMapper, bufferHandle); + if (value.has_value()) { + *outPixelFormatFourCC = *value; + return OK; + } + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getPixelFormatModifier(buffer_handle_t bufferHandle, + uint64_t *outPixelFormatModifier) const { + auto value = + getStandardMetadata(mMapper, bufferHandle); + if (value.has_value()) { + *outPixelFormatModifier = *value; + return OK; + } + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getUsage(buffer_handle_t bufferHandle, uint64_t *outUsage) const { + auto value = getStandardMetadata(mMapper, bufferHandle); + if (value.has_value()) { + *outUsage = static_cast(*value); + return OK; + } + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getAllocationSize(buffer_handle_t bufferHandle, + uint64_t *outAllocationSize) const { + auto value = getStandardMetadata(mMapper, bufferHandle); + if (value.has_value()) { + *outAllocationSize = *value; + return OK; + } + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getProtectedContent(buffer_handle_t bufferHandle, + uint64_t *outProtectedContent) const { + auto value = + getStandardMetadata(mMapper, bufferHandle); + if (value.has_value()) { + *outProtectedContent = *value; + return OK; + } + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getCompression( + buffer_handle_t bufferHandle, + aidl::android::hardware::graphics::common::ExtendableType *outCompression) const { + auto value = getStandardMetadata(mMapper, bufferHandle); + if (value.has_value()) { + *outCompression = *value; + return OK; + } + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getCompression(buffer_handle_t bufferHandle, + ui::Compression *outCompression) const { + auto value = getStandardMetadata(mMapper, bufferHandle); + if (!value.has_value()) { + return UNKNOWN_TRANSACTION; + } + if (!gralloc4::isStandardCompression(*value)) { + return BAD_TYPE; + } + *outCompression = gralloc4::getStandardCompressionValue(*value); + return OK; +} + +status_t Gralloc5Mapper::getInterlaced( + buffer_handle_t bufferHandle, + aidl::android::hardware::graphics::common::ExtendableType *outInterlaced) const { + auto value = getStandardMetadata(mMapper, bufferHandle); + if (value.has_value()) { + *outInterlaced = *value; + return OK; + } + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getInterlaced(buffer_handle_t bufferHandle, + ui::Interlaced *outInterlaced) const { + if (!outInterlaced) { + return BAD_VALUE; + } + ExtendableType interlaced; + status_t error = getInterlaced(bufferHandle, &interlaced); + if (error) { + return error; + } + if (!gralloc4::isStandardInterlaced(interlaced)) { + return BAD_TYPE; + } + *outInterlaced = gralloc4::getStandardInterlacedValue(interlaced); + return NO_ERROR; +} + +status_t Gralloc5Mapper::getChromaSiting( + buffer_handle_t bufferHandle, + aidl::android::hardware::graphics::common::ExtendableType *outChromaSiting) const { + auto value = getStandardMetadata(mMapper, bufferHandle); + if (value.has_value()) { + *outChromaSiting = *value; + return OK; + } + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getChromaSiting(buffer_handle_t bufferHandle, + ui::ChromaSiting *outChromaSiting) const { + if (!outChromaSiting) { + return BAD_VALUE; + } + ExtendableType chromaSiting; + status_t error = getChromaSiting(bufferHandle, &chromaSiting); + if (error) { + return error; + } + if (!gralloc4::isStandardChromaSiting(chromaSiting)) { + return BAD_TYPE; + } + *outChromaSiting = gralloc4::getStandardChromaSitingValue(chromaSiting); + return NO_ERROR; +} + +status_t Gralloc5Mapper::getPlaneLayouts(buffer_handle_t bufferHandle, + std::vector *outPlaneLayouts) const { + auto value = getStandardMetadata(mMapper, bufferHandle); + if (value.has_value()) { + *outPlaneLayouts = *value; + return OK; + } + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getDataspace(buffer_handle_t bufferHandle, + ui::Dataspace *outDataspace) const { + auto value = getStandardMetadata(mMapper, bufferHandle); + if (value.has_value()) { + *outDataspace = static_cast(*value); + return OK; + } + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::setDataspace(buffer_handle_t bufferHandle, ui::Dataspace dataspace) const { + return setStandardMetadata(mMapper, bufferHandle, + static_cast(dataspace)); +} + +status_t Gralloc5Mapper::getBlendMode(buffer_handle_t bufferHandle, + ui::BlendMode *outBlendMode) const { + auto value = getStandardMetadata(mMapper, bufferHandle); + if (value.has_value()) { + *outBlendMode = static_cast(*value); + return OK; + } + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getSmpte2086(buffer_handle_t bufferHandle, + std::optional *outSmpte2086) const { + auto value = getStandardMetadata(mMapper, bufferHandle); + if (value.has_value()) { + *outSmpte2086 = *value; + return OK; + } + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::setSmpte2086(buffer_handle_t bufferHandle, + std::optional smpte2086) const { + return setStandardMetadata(mMapper, bufferHandle, smpte2086); +} + +status_t Gralloc5Mapper::getCta861_3(buffer_handle_t bufferHandle, + std::optional *outCta861_3) const { + auto value = getStandardMetadata(mMapper, bufferHandle); + if (value.has_value()) { + *outCta861_3 = *value; + return OK; + } + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::setCta861_3(buffer_handle_t bufferHandle, + std::optional cta861_3) const { + return setStandardMetadata(mMapper, bufferHandle, cta861_3); +} + +status_t Gralloc5Mapper::getSmpte2094_40( + buffer_handle_t bufferHandle, std::optional> *outSmpte2094_40) const { + auto value = getStandardMetadata(mMapper, bufferHandle); + if (value.has_value()) { + *outSmpte2094_40 = std::move(*value); + return OK; + } + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::setSmpte2094_40(buffer_handle_t bufferHandle, + std::optional> smpte2094_40) const { + return setStandardMetadata(mMapper, bufferHandle, + smpte2094_40); +} + +status_t Gralloc5Mapper::getSmpte2094_10( + buffer_handle_t bufferHandle, std::optional> *outSmpte2094_10) const { + auto value = getStandardMetadata(mMapper, bufferHandle); + if (value.has_value()) { + *outSmpte2094_10 = std::move(*value); + return OK; + } + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::setSmpte2094_10(buffer_handle_t bufferHandle, + std::optional> smpte2094_10) const { + return setStandardMetadata(mMapper, bufferHandle, + smpte2094_10); +} + +status_t Gralloc5Mapper::getDefaultPixelFormatFourCC(uint32_t, uint32_t, PixelFormat, uint32_t, + uint64_t, uint32_t *) const { + // TODO(b/261857910): Remove + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getDefaultPixelFormatModifier(uint32_t, uint32_t, PixelFormat, uint32_t, + uint64_t, uint64_t *) const { + // TODO(b/261857910): Remove + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getDefaultAllocationSize(uint32_t, uint32_t, PixelFormat, uint32_t, + uint64_t, uint64_t *) const { + // TODO(b/261857910): Remove + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getDefaultProtectedContent(uint32_t, uint32_t, PixelFormat, uint32_t, + uint64_t, uint64_t *) const { + // TODO(b/261857910): Remove + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getDefaultCompression( + uint32_t, uint32_t, PixelFormat, uint32_t, uint64_t, + aidl::android::hardware::graphics::common::ExtendableType *) const { + // TODO(b/261857910): Remove + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getDefaultCompression(uint32_t, uint32_t, PixelFormat, uint32_t, uint64_t, + ui::Compression *) const { + // TODO(b/261857910): Remove + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getDefaultInterlaced( + uint32_t, uint32_t, PixelFormat, uint32_t, uint64_t, + aidl::android::hardware::graphics::common::ExtendableType *) const { + // TODO(b/261857910): Remove + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getDefaultInterlaced(uint32_t, uint32_t, PixelFormat, uint32_t, uint64_t, + ui::Interlaced *) const { + // TODO(b/261857910): Remove + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getDefaultChromaSiting( + uint32_t, uint32_t, PixelFormat, uint32_t, uint64_t, + aidl::android::hardware::graphics::common::ExtendableType *) const { + // TODO(b/261857910): Remove + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getDefaultChromaSiting(uint32_t, uint32_t, PixelFormat, uint32_t, uint64_t, + ui::ChromaSiting *) const { + // TODO(b/261857910): Remove + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getDefaultPlaneLayouts(uint32_t, uint32_t, PixelFormat, uint32_t, uint64_t, + std::vector *) const { + // TODO(b/261857910): Remove + return UNKNOWN_TRANSACTION; +} + +} // namespace android \ No newline at end of file -- cgit v1.2.3-59-g8ed1b From 9c1238df67d4b8619523e35f14e4f45d0d714687 Mon Sep 17 00:00:00 2001 From: John Reck Date: Tue, 21 Mar 2023 11:27:40 -0400 Subject: Remove unused code not implemented in gralloc5 Fixes: 261857910 Test: make Change-Id: If567ea91a9881c18f2d068ab1e0c9a37969d6a8a --- libs/ui/Gralloc4.cpp | 156 ------------------------------- libs/ui/Gralloc5.cpp | 69 -------------- libs/ui/GraphicBufferMapper.cpp | 79 ---------------- libs/ui/include/ui/Gralloc.h | 66 ------------- libs/ui/include/ui/Gralloc4.h | 36 ------- libs/ui/include/ui/Gralloc5.h | 54 ----------- libs/ui/include/ui/GraphicBufferMapper.h | 42 --------- 7 files changed, 502 deletions(-) (limited to 'libs/ui/Gralloc5.cpp') diff --git a/libs/ui/Gralloc4.cpp b/libs/ui/Gralloc4.cpp index c3af996b13..b6274ab9c0 100644 --- a/libs/ui/Gralloc4.cpp +++ b/libs/ui/Gralloc4.cpp @@ -766,162 +766,6 @@ status_t Gralloc4Mapper::setSmpte2094_10(buffer_handle_t bufferHandle, gralloc4::encodeSmpte2094_10); } -template -status_t Gralloc4Mapper::getDefault(uint32_t width, uint32_t height, PixelFormat format, - uint32_t layerCount, uint64_t usage, - const MetadataType& metadataType, - DecodeFunction decodeFunction, T* outMetadata) const { - if (!outMetadata) { - return BAD_VALUE; - } - - IMapper::BufferDescriptorInfo descriptorInfo; - if (auto error = sBufferDescriptorInfo("getDefault", width, height, format, layerCount, usage, - &descriptorInfo) != OK) { - return error; - } - - hidl_vec vec; - Error error; - auto ret = mMapper->getFromBufferDescriptorInfo(descriptorInfo, metadataType, - [&](const auto& tmpError, - const hidl_vec& tmpVec) { - error = tmpError; - vec = tmpVec; - }); - - if (!ret.isOk()) { - error = kTransactionError; - } - - if (error != Error::NONE) { - ALOGE("getDefault(%s, %" PRIu64 ", ...) failed with %d", metadataType.name.c_str(), - metadataType.value, error); - return static_cast(error); - } - - return decodeFunction(vec, outMetadata); -} - -status_t Gralloc4Mapper::getDefaultPixelFormatFourCC(uint32_t width, uint32_t height, - PixelFormat format, uint32_t layerCount, - uint64_t usage, - uint32_t* outPixelFormatFourCC) const { - return getDefault(width, height, format, layerCount, usage, - gralloc4::MetadataType_PixelFormatFourCC, gralloc4::decodePixelFormatFourCC, - outPixelFormatFourCC); -} - -status_t Gralloc4Mapper::getDefaultPixelFormatModifier(uint32_t width, uint32_t height, - PixelFormat format, uint32_t layerCount, - uint64_t usage, - uint64_t* outPixelFormatModifier) const { - return getDefault(width, height, format, layerCount, usage, - gralloc4::MetadataType_PixelFormatModifier, - gralloc4::decodePixelFormatModifier, outPixelFormatModifier); -} - -status_t Gralloc4Mapper::getDefaultAllocationSize(uint32_t width, uint32_t height, - PixelFormat format, uint32_t layerCount, - uint64_t usage, - uint64_t* outAllocationSize) const { - return getDefault(width, height, format, layerCount, usage, - gralloc4::MetadataType_AllocationSize, gralloc4::decodeAllocationSize, - outAllocationSize); -} - -status_t Gralloc4Mapper::getDefaultProtectedContent(uint32_t width, uint32_t height, - PixelFormat format, uint32_t layerCount, - uint64_t usage, - uint64_t* outProtectedContent) const { - return getDefault(width, height, format, layerCount, usage, - gralloc4::MetadataType_ProtectedContent, gralloc4::decodeProtectedContent, - outProtectedContent); -} - -status_t Gralloc4Mapper::getDefaultCompression(uint32_t width, uint32_t height, PixelFormat format, - uint32_t layerCount, uint64_t usage, - ExtendableType* outCompression) const { - return getDefault(width, height, format, layerCount, usage, gralloc4::MetadataType_Compression, - gralloc4::decodeCompression, outCompression); -} - -status_t Gralloc4Mapper::getDefaultCompression(uint32_t width, uint32_t height, PixelFormat format, - uint32_t layerCount, uint64_t usage, - ui::Compression* outCompression) const { - if (!outCompression) { - return BAD_VALUE; - } - ExtendableType compression; - status_t error = getDefaultCompression(width, height, format, layerCount, usage, &compression); - if (error) { - return error; - } - if (!gralloc4::isStandardCompression(compression)) { - return BAD_TYPE; - } - *outCompression = gralloc4::getStandardCompressionValue(compression); - return NO_ERROR; -} - -status_t Gralloc4Mapper::getDefaultInterlaced(uint32_t width, uint32_t height, PixelFormat format, - uint32_t layerCount, uint64_t usage, - ExtendableType* outInterlaced) const { - return getDefault(width, height, format, layerCount, usage, gralloc4::MetadataType_Interlaced, - gralloc4::decodeInterlaced, outInterlaced); -} - -status_t Gralloc4Mapper::getDefaultInterlaced(uint32_t width, uint32_t height, PixelFormat format, - uint32_t layerCount, uint64_t usage, - ui::Interlaced* outInterlaced) const { - if (!outInterlaced) { - return BAD_VALUE; - } - ExtendableType interlaced; - status_t error = getDefaultInterlaced(width, height, format, layerCount, usage, &interlaced); - if (error) { - return error; - } - if (!gralloc4::isStandardInterlaced(interlaced)) { - return BAD_TYPE; - } - *outInterlaced = gralloc4::getStandardInterlacedValue(interlaced); - return NO_ERROR; -} - -status_t Gralloc4Mapper::getDefaultChromaSiting(uint32_t width, uint32_t height, PixelFormat format, - uint32_t layerCount, uint64_t usage, - ExtendableType* outChromaSiting) const { - return getDefault(width, height, format, layerCount, usage, gralloc4::MetadataType_ChromaSiting, - gralloc4::decodeChromaSiting, outChromaSiting); -} - -status_t Gralloc4Mapper::getDefaultChromaSiting(uint32_t width, uint32_t height, PixelFormat format, - uint32_t layerCount, uint64_t usage, - ui::ChromaSiting* outChromaSiting) const { - if (!outChromaSiting) { - return BAD_VALUE; - } - ExtendableType chromaSiting; - status_t error = - getDefaultChromaSiting(width, height, format, layerCount, usage, &chromaSiting); - if (error) { - return error; - } - if (!gralloc4::isStandardChromaSiting(chromaSiting)) { - return BAD_TYPE; - } - *outChromaSiting = gralloc4::getStandardChromaSitingValue(chromaSiting); - return NO_ERROR; -} - -status_t Gralloc4Mapper::getDefaultPlaneLayouts( - uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage, - std::vector* outPlaneLayouts) const { - return getDefault(width, height, format, layerCount, usage, gralloc4::MetadataType_PlaneLayouts, - gralloc4::decodePlaneLayouts, outPlaneLayouts); -} - std::vector Gralloc4Mapper::listSupportedMetadataTypes() const { hidl_vec descriptions; Error error; diff --git a/libs/ui/Gralloc5.cpp b/libs/ui/Gralloc5.cpp index 6f196b86d5..514b45f0a5 100644 --- a/libs/ui/Gralloc5.cpp +++ b/libs/ui/Gralloc5.cpp @@ -831,73 +831,4 @@ status_t Gralloc5Mapper::setSmpte2094_10(buffer_handle_t bufferHandle, smpte2094_10); } -status_t Gralloc5Mapper::getDefaultPixelFormatFourCC(uint32_t, uint32_t, PixelFormat, uint32_t, - uint64_t, uint32_t *) const { - // TODO(b/261857910): Remove - return UNKNOWN_TRANSACTION; -} - -status_t Gralloc5Mapper::getDefaultPixelFormatModifier(uint32_t, uint32_t, PixelFormat, uint32_t, - uint64_t, uint64_t *) const { - // TODO(b/261857910): Remove - return UNKNOWN_TRANSACTION; -} - -status_t Gralloc5Mapper::getDefaultAllocationSize(uint32_t, uint32_t, PixelFormat, uint32_t, - uint64_t, uint64_t *) const { - // TODO(b/261857910): Remove - return UNKNOWN_TRANSACTION; -} - -status_t Gralloc5Mapper::getDefaultProtectedContent(uint32_t, uint32_t, PixelFormat, uint32_t, - uint64_t, uint64_t *) const { - // TODO(b/261857910): Remove - return UNKNOWN_TRANSACTION; -} - -status_t Gralloc5Mapper::getDefaultCompression( - uint32_t, uint32_t, PixelFormat, uint32_t, uint64_t, - aidl::android::hardware::graphics::common::ExtendableType *) const { - // TODO(b/261857910): Remove - return UNKNOWN_TRANSACTION; -} - -status_t Gralloc5Mapper::getDefaultCompression(uint32_t, uint32_t, PixelFormat, uint32_t, uint64_t, - ui::Compression *) const { - // TODO(b/261857910): Remove - return UNKNOWN_TRANSACTION; -} - -status_t Gralloc5Mapper::getDefaultInterlaced( - uint32_t, uint32_t, PixelFormat, uint32_t, uint64_t, - aidl::android::hardware::graphics::common::ExtendableType *) const { - // TODO(b/261857910): Remove - return UNKNOWN_TRANSACTION; -} - -status_t Gralloc5Mapper::getDefaultInterlaced(uint32_t, uint32_t, PixelFormat, uint32_t, uint64_t, - ui::Interlaced *) const { - // TODO(b/261857910): Remove - return UNKNOWN_TRANSACTION; -} - -status_t Gralloc5Mapper::getDefaultChromaSiting( - uint32_t, uint32_t, PixelFormat, uint32_t, uint64_t, - aidl::android::hardware::graphics::common::ExtendableType *) const { - // TODO(b/261857910): Remove - return UNKNOWN_TRANSACTION; -} - -status_t Gralloc5Mapper::getDefaultChromaSiting(uint32_t, uint32_t, PixelFormat, uint32_t, uint64_t, - ui::ChromaSiting *) const { - // TODO(b/261857910): Remove - return UNKNOWN_TRANSACTION; -} - -status_t Gralloc5Mapper::getDefaultPlaneLayouts(uint32_t, uint32_t, PixelFormat, uint32_t, uint64_t, - std::vector *) const { - // TODO(b/261857910): Remove - return UNKNOWN_TRANSACTION; -} - } // namespace android \ No newline at end of file diff --git a/libs/ui/GraphicBufferMapper.cpp b/libs/ui/GraphicBufferMapper.cpp index 6002a6d29e..7086e0470c 100644 --- a/libs/ui/GraphicBufferMapper.cpp +++ b/libs/ui/GraphicBufferMapper.cpp @@ -341,84 +341,5 @@ status_t GraphicBufferMapper::setSmpte2094_10(buffer_handle_t bufferHandle, 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, - uint32_t* outPixelFormatFourCC) { - return mMapper->getDefaultPixelFormatFourCC(width, height, format, layerCount, usage, - outPixelFormatFourCC); -} - -status_t GraphicBufferMapper::getDefaultPixelFormatModifier(uint32_t width, uint32_t height, - PixelFormat format, uint32_t layerCount, - uint64_t usage, - uint64_t* outPixelFormatModifier) { - return mMapper->getDefaultPixelFormatModifier(width, height, format, layerCount, usage, - outPixelFormatModifier); -} - -status_t GraphicBufferMapper::getDefaultAllocationSize(uint32_t width, uint32_t height, - PixelFormat format, uint32_t layerCount, - uint64_t usage, - uint64_t* outAllocationSize) { - return mMapper->getDefaultAllocationSize(width, height, format, layerCount, usage, - outAllocationSize); -} - -status_t GraphicBufferMapper::getDefaultProtectedContent(uint32_t width, uint32_t height, - PixelFormat format, uint32_t layerCount, - uint64_t usage, - uint64_t* outProtectedContent) { - return mMapper->getDefaultProtectedContent(width, height, format, layerCount, usage, - outProtectedContent); -} - -status_t GraphicBufferMapper::getDefaultCompression( - uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage, - aidl::android::hardware::graphics::common::ExtendableType* outCompression) { - return mMapper->getDefaultCompression(width, height, format, layerCount, usage, outCompression); -} - -status_t GraphicBufferMapper::getDefaultCompression(uint32_t width, uint32_t height, - PixelFormat format, uint32_t layerCount, - uint64_t usage, - ui::Compression* outCompression) { - return mMapper->getDefaultCompression(width, height, format, layerCount, usage, outCompression); -} - -status_t GraphicBufferMapper::getDefaultInterlaced( - uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage, - aidl::android::hardware::graphics::common::ExtendableType* outInterlaced) { - return mMapper->getDefaultInterlaced(width, height, format, layerCount, usage, outInterlaced); -} - -status_t GraphicBufferMapper::getDefaultInterlaced(uint32_t width, uint32_t height, - PixelFormat format, uint32_t layerCount, - uint64_t usage, ui::Interlaced* outInterlaced) { - return mMapper->getDefaultInterlaced(width, height, format, layerCount, usage, outInterlaced); -} - -status_t GraphicBufferMapper::getDefaultChromaSiting( - uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage, - aidl::android::hardware::graphics::common::ExtendableType* outChromaSiting) { - return mMapper->getDefaultChromaSiting(width, height, format, layerCount, usage, - outChromaSiting); -} - -status_t GraphicBufferMapper::getDefaultChromaSiting(uint32_t width, uint32_t height, - PixelFormat format, uint32_t layerCount, - uint64_t usage, - ui::ChromaSiting* outChromaSiting) { - return mMapper->getDefaultChromaSiting(width, height, format, layerCount, usage, - outChromaSiting); -} - -status_t GraphicBufferMapper::getDefaultPlaneLayouts( - uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage, - std::vector* outPlaneLayouts) { - return mMapper->getDefaultPlaneLayouts(width, height, format, layerCount, usage, - outPlaneLayouts); -} - // --------------------------------------------------------------------------- }; // namespace android diff --git a/libs/ui/include/ui/Gralloc.h b/libs/ui/include/ui/Gralloc.h index b494cbe4fa..496ba57789 100644 --- a/libs/ui/include/ui/Gralloc.h +++ b/libs/ui/include/ui/Gralloc.h @@ -200,72 +200,6 @@ public: 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*/, - uint32_t* /*outPixelFormatFourCC*/) const { - return INVALID_OPERATION; - } - virtual status_t getDefaultPixelFormatModifier(uint32_t /*width*/, uint32_t /*height*/, - PixelFormat /*format*/, uint32_t /*layerCount*/, - uint64_t /*usage*/, - uint64_t* /*outPixelFormatModifier*/) const { - return INVALID_OPERATION; - } - virtual status_t getDefaultAllocationSize(uint32_t /*width*/, uint32_t /*height*/, - PixelFormat /*format*/, uint32_t /*layerCount*/, - uint64_t /*usage*/, - uint64_t* /*outAllocationSize*/) const { - return INVALID_OPERATION; - } - virtual status_t getDefaultProtectedContent(uint32_t /*width*/, uint32_t /*height*/, - PixelFormat /*format*/, uint32_t /*layerCount*/, - uint64_t /*usage*/, - uint64_t* /*outProtectedContent*/) const { - return INVALID_OPERATION; - } - virtual status_t getDefaultCompression( - uint32_t /*width*/, uint32_t /*height*/, PixelFormat /*format*/, - uint32_t /*layerCount*/, uint64_t /*usage*/, - aidl::android::hardware::graphics::common::ExtendableType* /*outCompression*/) const { - return INVALID_OPERATION; - } - virtual status_t getDefaultCompression(uint32_t /*width*/, uint32_t /*height*/, - PixelFormat /*format*/, uint32_t /*layerCount*/, - uint64_t /*usage*/, - ui::Compression* /*outCompression*/) const { - return INVALID_OPERATION; - } - virtual status_t getDefaultInterlaced( - uint32_t /*width*/, uint32_t /*height*/, PixelFormat /*format*/, - uint32_t /*layerCount*/, uint64_t /*usage*/, - aidl::android::hardware::graphics::common::ExtendableType* /*outInterlaced*/) const { - return INVALID_OPERATION; - } - virtual status_t getDefaultInterlaced(uint32_t /*width*/, uint32_t /*height*/, - PixelFormat /*format*/, uint32_t /*layerCount*/, - uint64_t /*usage*/, - ui::Interlaced* /*outInterlaced*/) const { - return INVALID_OPERATION; - } - virtual status_t getDefaultChromaSiting( - uint32_t /*width*/, uint32_t /*height*/, PixelFormat /*format*/, - uint32_t /*layerCount*/, uint64_t /*usage*/, - aidl::android::hardware::graphics::common::ExtendableType* /*outChromaSiting*/) const { - return INVALID_OPERATION; - } - virtual status_t getDefaultChromaSiting(uint32_t /*width*/, uint32_t /*height*/, - PixelFormat /*format*/, uint32_t /*layerCount*/, - uint64_t /*usage*/, - ui::ChromaSiting* /*outChromaSiting*/) const { - return INVALID_OPERATION; - } - virtual status_t getDefaultPlaneLayouts( - uint32_t /*width*/, uint32_t /*height*/, PixelFormat /*format*/, - uint32_t /*layerCount*/, uint64_t /*usage*/, - std::vector* /*outPlaneLayouts*/) const { - return INVALID_OPERATION; - } }; // A wrapper to IAllocator diff --git a/libs/ui/include/ui/Gralloc4.h b/libs/ui/include/ui/Gralloc4.h index 6bc5ce5296..df43be87cd 100644 --- a/libs/ui/include/ui/Gralloc4.h +++ b/libs/ui/include/ui/Gralloc4.h @@ -120,42 +120,6 @@ public: 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; - status_t getDefaultPixelFormatModifier(uint32_t width, uint32_t height, PixelFormat format, - uint32_t layerCount, uint64_t usage, - uint64_t* outPixelFormatModifier) const override; - status_t getDefaultAllocationSize(uint32_t width, uint32_t height, PixelFormat format, - uint32_t layerCount, uint64_t usage, - uint64_t* outAllocationSize) const override; - status_t getDefaultProtectedContent(uint32_t width, uint32_t height, PixelFormat format, - uint32_t layerCount, uint64_t usage, - uint64_t* outProtectedContent) const override; - status_t getDefaultCompression(uint32_t width, uint32_t height, PixelFormat format, - uint32_t layerCount, uint64_t usage, - aidl::android::hardware::graphics::common::ExtendableType* - outCompression) const override; - status_t getDefaultCompression(uint32_t width, uint32_t height, PixelFormat format, - uint32_t layerCount, uint64_t usage, - ui::Compression* outCompression) const override; - status_t getDefaultInterlaced(uint32_t width, uint32_t height, PixelFormat format, - uint32_t layerCount, uint64_t usage, - aidl::android::hardware::graphics::common::ExtendableType* - outInterlaced) const override; - status_t getDefaultInterlaced(uint32_t width, uint32_t height, PixelFormat format, - uint32_t layerCount, uint64_t usage, - ui::Interlaced* outInterlaced) const override; - status_t getDefaultChromaSiting(uint32_t width, uint32_t height, PixelFormat format, - uint32_t layerCount, uint64_t usage, - aidl::android::hardware::graphics::common::ExtendableType* - outChromaSiting) const override; - status_t getDefaultChromaSiting(uint32_t width, uint32_t height, PixelFormat format, - uint32_t layerCount, uint64_t usage, - ui::ChromaSiting* outChromaSiting) const override; - status_t getDefaultPlaneLayouts(uint32_t width, uint32_t height, PixelFormat format, - uint32_t layerCount, uint64_t usage, - std::vector* outPlaneLayouts) const override; std::vector listSupportedMetadataTypes() const; diff --git a/libs/ui/include/ui/Gralloc5.h b/libs/ui/include/ui/Gralloc5.h index bc1016944a..44b97d1a6f 100644 --- a/libs/ui/include/ui/Gralloc5.h +++ b/libs/ui/include/ui/Gralloc5.h @@ -156,60 +156,6 @@ public: buffer_handle_t bufferHandle, std::optional> smpte2094_10) const override; - [[nodiscard]] status_t getDefaultPixelFormatFourCC( - uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, - uint64_t usage, uint32_t *outPixelFormatFourCC) const override; - - [[nodiscard]] status_t getDefaultPixelFormatModifier( - uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, - uint64_t usage, uint64_t *outPixelFormatModifier) const override; - - [[nodiscard]] status_t getDefaultAllocationSize(uint32_t width, uint32_t height, - PixelFormat format, uint32_t layerCount, - uint64_t usage, - uint64_t *outAllocationSize) const override; - - [[nodiscard]] status_t getDefaultProtectedContent(uint32_t width, uint32_t height, - PixelFormat format, uint32_t layerCount, - uint64_t usage, - uint64_t *outProtectedContent) const override; - - [[nodiscard]] status_t getDefaultCompression( - uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, - uint64_t usage, - aidl::android::hardware::graphics::common::ExtendableType *outCompression) - const override; - - [[nodiscard]] status_t getDefaultCompression(uint32_t width, uint32_t height, - PixelFormat format, uint32_t layerCount, - uint64_t usage, - ui::Compression *outCompression) const override; - - [[nodiscard]] status_t getDefaultInterlaced( - uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, - uint64_t usage, - aidl::android::hardware::graphics::common::ExtendableType *outInterlaced) - const override; - - [[nodiscard]] status_t getDefaultInterlaced(uint32_t width, uint32_t height, PixelFormat format, - uint32_t layerCount, uint64_t usage, - ui::Interlaced *outInterlaced) const override; - - [[nodiscard]] status_t getDefaultChromaSiting( - uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, - uint64_t usage, - aidl::android::hardware::graphics::common::ExtendableType *outChromaSiting) - const override; - - [[nodiscard]] status_t getDefaultChromaSiting(uint32_t width, uint32_t height, - PixelFormat format, uint32_t layerCount, - uint64_t usage, - ui::ChromaSiting *outChromaSiting) const override; - - [[nodiscard]] status_t getDefaultPlaneLayouts( - uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, - uint64_t usage, std::vector *outPlaneLayouts) const override; - private: void unlockBlocking(buffer_handle_t bufferHandle) const; diff --git a/libs/ui/include/ui/GraphicBufferMapper.h b/libs/ui/include/ui/GraphicBufferMapper.h index 51c6e92f43..3a5167ab25 100644 --- a/libs/ui/include/ui/GraphicBufferMapper.h +++ b/libs/ui/include/ui/GraphicBufferMapper.h @@ -138,48 +138,6 @@ public: 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. - * - * These functions are supported by gralloc 4.0+. - */ - status_t getDefaultPixelFormatFourCC(uint32_t width, uint32_t height, PixelFormat format, - uint32_t layerCount, uint64_t usage, - uint32_t* outPixelFormatFourCC); - status_t getDefaultPixelFormatModifier(uint32_t width, uint32_t height, PixelFormat format, - uint32_t layerCount, uint64_t usage, - uint64_t* outPixelFormatModifier); - status_t getDefaultAllocationSize(uint32_t width, uint32_t height, PixelFormat format, - uint32_t layerCount, uint64_t usage, - uint64_t* outAllocationSize); - status_t getDefaultProtectedContent(uint32_t width, uint32_t height, PixelFormat format, - uint32_t layerCount, uint64_t usage, - uint64_t* outProtectedContent); - status_t getDefaultCompression( - uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, - uint64_t usage, - aidl::android::hardware::graphics::common::ExtendableType* outCompression); - status_t getDefaultCompression(uint32_t width, uint32_t height, PixelFormat format, - uint32_t layerCount, uint64_t usage, - ui::Compression* outCompression); - status_t getDefaultInterlaced( - uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, - uint64_t usage, - aidl::android::hardware::graphics::common::ExtendableType* outInterlaced); - status_t getDefaultInterlaced(uint32_t width, uint32_t height, PixelFormat format, - uint32_t layerCount, uint64_t usage, - ui::Interlaced* outInterlaced); - status_t getDefaultChromaSiting( - uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, - uint64_t usage, - aidl::android::hardware::graphics::common::ExtendableType* outChromaSiting); - status_t getDefaultChromaSiting(uint32_t width, uint32_t height, PixelFormat format, - uint32_t layerCount, uint64_t usage, - ui::ChromaSiting* outChromaSiting); - status_t getDefaultPlaneLayouts(uint32_t width, uint32_t height, PixelFormat format, - uint32_t layerCount, uint64_t usage, - std::vector* outPlaneLayouts); - const GrallocMapper& getGrallocMapper() const { return reinterpret_cast(*mMapper); } -- cgit v1.2.3-59-g8ed1b From e225b28df5f4215d923a94f6ec4277651666d46b Mon Sep 17 00:00:00 2001 From: John Reck Date: Fri, 24 Mar 2023 16:15:17 -0400 Subject: Validate STRIDE Bug: 261856851 Test: build & boot cf Change-Id: I8a43d4eb3cb9d9bd6899e104ab443418587e6b98 --- libs/ui/Gralloc5.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'libs/ui/Gralloc5.cpp') diff --git a/libs/ui/Gralloc5.cpp b/libs/ui/Gralloc5.cpp index 514b45f0a5..21068394d2 100644 --- a/libs/ui/Gralloc5.cpp +++ b/libs/ui/Gralloc5.cpp @@ -352,14 +352,12 @@ status_t Gralloc5Mapper::validateBufferSize(buffer_handle_t bufferHandle, uint32 } } { - (void)stride; - // TODO(b/261856851): Add StandardMetadataType::STRIDE && enable this - // auto value = getStandardMetadata(mMapper, - // bufferHandle); if (static_cast(usage) != value) { - // ALOGW("Layer count didn't match, expected %" PRIu64 " got %" PRId64, usage, - // static_cast(value.value_or(BufferUsage::CPU_READ_NEVER))); - // return BAD_VALUE; - // } + auto value = getStandardMetadata(mMapper, bufferHandle); + if (stride != value) { + ALOGW("Stride didn't match, expected %" PRIu32 " got %" PRId32, stride, + value.value_or(-1)); + return BAD_VALUE; + } } return OK; } -- cgit v1.2.3-59-g8ed1b From 47390ece3c85ef17091b49d3503286e632b11c41 Mon Sep 17 00:00:00 2001 From: John Reck Date: Wed, 24 May 2023 13:46:37 -0400 Subject: Fix USAGE_FRONT_BUFFER failure on Cuttlefish Bug: 280866371 Test: repro in bug Change-Id: I2963143d88a6ffba68012f47b79155a01367d49d --- libs/ui/Gralloc5.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'libs/ui/Gralloc5.cpp') diff --git a/libs/ui/Gralloc5.cpp b/libs/ui/Gralloc5.cpp index 21068394d2..c3b2d3d808 100644 --- a/libs/ui/Gralloc5.cpp +++ b/libs/ui/Gralloc5.cpp @@ -343,14 +343,17 @@ status_t Gralloc5Mapper::validateBufferSize(buffer_handle_t bufferHandle, uint32 return BAD_VALUE; } } - { - auto value = getStandardMetadata(mMapper, bufferHandle); - if (static_cast(usage) != value) { - ALOGW("Usage didn't match, expected %" PRIu64 " got %" PRId64, usage, - static_cast(value.value_or(BufferUsage::CPU_READ_NEVER))); - return BAD_VALUE; - } - } + // TODO: This can false-positive fail if the allocator adjusted the USAGE bits internally + // Investigate further & re-enable or remove, but for now ignoring usage should be OK + (void)usage; + // { + // auto value = getStandardMetadata(mMapper, bufferHandle); + // if (static_cast(usage) != value) { + // ALOGW("Usage didn't match, expected %" PRIu64 " got %" PRId64, usage, + // static_cast(value.value_or(BufferUsage::CPU_READ_NEVER))); + // return BAD_VALUE; + // } + // } { auto value = getStandardMetadata(mMapper, bufferHandle); if (stride != value) { -- cgit v1.2.3-59-g8ed1b