diff options
Diffstat (limited to 'libs/ui')
31 files changed, 1236 insertions, 793 deletions
diff --git a/libs/ui/Android.bp b/libs/ui/Android.bp index 98d9b94322..ec0ab4e464 100644 --- a/libs/ui/Android.bp +++ b/libs/ui/Android.bp @@ -48,7 +48,6 @@ cc_defaults { integer_overflow: true, misc_undefined: ["bounds"], }, - } cc_library_static { @@ -127,7 +126,6 @@ cc_library_shared { "DebugUtils.cpp", "DeviceProductInfo.cpp", "DisplayIdentification.cpp", - "DisplayMode.cpp", "DynamicDisplayInfo.cpp", "Fence.cpp", "FenceTime.cpp", @@ -136,14 +134,13 @@ cc_library_shared { "Gralloc2.cpp", "Gralloc3.cpp", "Gralloc4.cpp", + "Gralloc5.cpp", "GraphicBuffer.cpp", "GraphicBufferAllocator.cpp", "GraphicBufferMapper.cpp", - "HdrCapabilities.cpp", "PixelFormat.cpp", "PublicFormat.cpp", "StaticAsserts.cpp", - "StaticDisplayInfo.cpp", ], include_dirs: [ @@ -179,6 +176,7 @@ cc_library_shared { "libsync", "libutils", "liblog", + "libvndksupport", ], export_shared_lib_headers: [ @@ -217,6 +215,8 @@ cc_library_shared { "libnativewindow_headers", "libhardware_headers", "libui_headers", + "libimapper_stablec", + "libimapper_providerutils", ], export_static_lib_headers: [ @@ -240,10 +240,6 @@ cc_library_shared { ], afdo: true, - - header_abi_checker: { - diff_flags: ["-allow-adding-removing-weak-symbols"], - }, } cc_library_headers { diff --git a/libs/ui/DeviceProductInfo.cpp b/libs/ui/DeviceProductInfo.cpp index 04d9d3c989..6ae27dee1d 100644 --- a/libs/ui/DeviceProductInfo.cpp +++ b/libs/ui/DeviceProductInfo.cpp @@ -14,74 +14,43 @@ * limitations under the License. */ +#include <ftl/match.h> #include <ui/DeviceProductInfo.h> #include <android-base/stringprintf.h> -#include <ui/FlattenableHelpers.h> -#include <utils/Log.h> - -#define RETURN_IF_ERROR(op) \ - if (const status_t status = (op); status != OK) return status; namespace android { -using base::StringAppendF; - -size_t DeviceProductInfo::getFlattenedSize() const { - return FlattenableHelpers::getFlattenedSize(name) + - FlattenableHelpers::getFlattenedSize(manufacturerPnpId) + - FlattenableHelpers::getFlattenedSize(productId) + - FlattenableHelpers::getFlattenedSize(manufactureOrModelDate) + - FlattenableHelpers::getFlattenedSize(relativeAddress); -} - -status_t DeviceProductInfo::flatten(void* buffer, size_t size) const { - if (size < getFlattenedSize()) { - return NO_MEMORY; - } - RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, name)); - RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, manufacturerPnpId)); - RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, productId)); - RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, manufactureOrModelDate)); - RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, relativeAddress)); - return OK; -} - -status_t DeviceProductInfo::unflatten(void const* buffer, size_t size) { - RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &name)); - RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &manufacturerPnpId)); - RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &productId)); - RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &manufactureOrModelDate)); - RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &relativeAddress)); - return OK; -} - -void DeviceProductInfo::dump(std::string& result) const { - StringAppendF(&result, "{name=\"%s\", ", name.c_str()); - StringAppendF(&result, "manufacturerPnpId=%s, ", manufacturerPnpId.data()); - StringAppendF(&result, "productId=%s, ", productId.c_str()); - - if (const auto* model = std::get_if<ModelYear>(&manufactureOrModelDate)) { - StringAppendF(&result, "modelYear=%u, ", model->year); - } else if (const auto* manufactureWeekAndYear = - std::get_if<ManufactureWeekAndYear>(&manufactureOrModelDate)) { - StringAppendF(&result, "manufactureWeek=%u, ", manufactureWeekAndYear->week); - StringAppendF(&result, "manufactureYear=%d, ", manufactureWeekAndYear->year); - } else if (const auto* manufactureYear = - std::get_if<ManufactureYear>(&manufactureOrModelDate)) { - StringAppendF(&result, "manufactureYear=%d, ", manufactureYear->year); - } else { - ALOGE("Unknown alternative for variant DeviceProductInfo::ManufactureOrModelDate"); - } +std::string to_string(const DeviceProductInfo& info) { + using base::StringAppendF; + + std::string result; + StringAppendF(&result, "{name=\"%s\", ", info.name.c_str()); + StringAppendF(&result, "manufacturerPnpId=%s, ", info.manufacturerPnpId.data()); + StringAppendF(&result, "productId=%s, ", info.productId.c_str()); + + ftl::match( + info.manufactureOrModelDate, + [&](DeviceProductInfo::ModelYear model) { + StringAppendF(&result, "modelYear=%u, ", model.year); + }, + [&](DeviceProductInfo::ManufactureWeekAndYear manufacture) { + StringAppendF(&result, "manufactureWeek=%u, ", manufacture.week); + StringAppendF(&result, "manufactureYear=%d, ", manufacture.year); + }, + [&](DeviceProductInfo::ManufactureYear manufacture) { + StringAppendF(&result, "manufactureYear=%d, ", manufacture.year); + }); result.append("relativeAddress=["); - for (size_t i = 0; i < relativeAddress.size(); i++) { + for (size_t i = 0; i < info.relativeAddress.size(); i++) { if (i != 0) { result.append(", "); } - StringAppendF(&result, "%u", relativeAddress[i]); + StringAppendF(&result, "%u", info.relativeAddress[i]); } result.append("]}"); + return result; } } // namespace android diff --git a/libs/ui/DisplayMode.cpp b/libs/ui/DisplayMode.cpp deleted file mode 100644 index cf05dbfb05..0000000000 --- a/libs/ui/DisplayMode.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2021 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. - */ - -#include <ui/DisplayMode.h> - -#include <cstdint> - -#include <ui/FlattenableHelpers.h> - -#define RETURN_IF_ERROR(op) \ - if (const status_t status = (op); status != OK) return status; - -namespace android::ui { - -size_t DisplayMode::getFlattenedSize() const { - return FlattenableHelpers::getFlattenedSize(id) + - FlattenableHelpers::getFlattenedSize(resolution) + - FlattenableHelpers::getFlattenedSize(xDpi) + - FlattenableHelpers::getFlattenedSize(yDpi) + - FlattenableHelpers::getFlattenedSize(refreshRate) + - FlattenableHelpers::getFlattenedSize(appVsyncOffset) + - FlattenableHelpers::getFlattenedSize(sfVsyncOffset) + - FlattenableHelpers::getFlattenedSize(presentationDeadline) + - FlattenableHelpers::getFlattenedSize(group); -} - -status_t DisplayMode::flatten(void* buffer, size_t size) const { - if (size < getFlattenedSize()) { - return NO_MEMORY; - } - RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, id)); - RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, resolution)); - RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, xDpi)); - RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, yDpi)); - RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, refreshRate)); - RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, appVsyncOffset)); - RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, sfVsyncOffset)); - RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, presentationDeadline)); - RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, group)); - return OK; -} - -status_t DisplayMode::unflatten(const void* buffer, size_t size) { - RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &id)); - RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &resolution)); - RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &xDpi)); - RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &yDpi)); - RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &refreshRate)); - RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &appVsyncOffset)); - RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &sfVsyncOffset)); - RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &presentationDeadline)); - RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &group)); - return OK; -} - -} // namespace android::ui diff --git a/libs/ui/DynamicDisplayInfo.cpp b/libs/ui/DynamicDisplayInfo.cpp index 78ba9965b6..f5feea925d 100644 --- a/libs/ui/DynamicDisplayInfo.cpp +++ b/libs/ui/DynamicDisplayInfo.cpp @@ -18,11 +18,6 @@ #include <cstdint> -#include <ui/FlattenableHelpers.h> - -#define RETURN_IF_ERROR(op) \ - if (const status_t status = (op); status != OK) return status; - namespace android::ui { std::optional<ui::DisplayMode> DynamicDisplayInfo::getActiveDisplayMode() const { @@ -34,42 +29,4 @@ std::optional<ui::DisplayMode> DynamicDisplayInfo::getActiveDisplayMode() const return {}; } -size_t DynamicDisplayInfo::getFlattenedSize() const { - return FlattenableHelpers::getFlattenedSize(supportedDisplayModes) + - FlattenableHelpers::getFlattenedSize(activeDisplayModeId) + - FlattenableHelpers::getFlattenedSize(supportedColorModes) + - FlattenableHelpers::getFlattenedSize(activeColorMode) + - FlattenableHelpers::getFlattenedSize(hdrCapabilities) + - FlattenableHelpers::getFlattenedSize(autoLowLatencyModeSupported) + - FlattenableHelpers::getFlattenedSize(gameContentTypeSupported) + - FlattenableHelpers::getFlattenedSize(preferredBootDisplayMode); -} - -status_t DynamicDisplayInfo::flatten(void* buffer, size_t size) const { - if (size < getFlattenedSize()) { - return NO_MEMORY; - } - RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, supportedDisplayModes)); - RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, activeDisplayModeId)); - RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, supportedColorModes)); - RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, activeColorMode)); - RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, hdrCapabilities)); - RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, autoLowLatencyModeSupported)); - RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, gameContentTypeSupported)); - RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, preferredBootDisplayMode)); - return OK; -} - -status_t DynamicDisplayInfo::unflatten(const void* buffer, size_t size) { - RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &supportedDisplayModes)); - RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &activeDisplayModeId)); - RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &supportedColorModes)); - RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &activeColorMode)); - RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &hdrCapabilities)); - RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &autoLowLatencyModeSupported)); - RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &gameContentTypeSupported)); - RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &preferredBootDisplayMode)); - return OK; -} - } // namespace android::ui diff --git a/libs/ui/Gralloc2.cpp b/libs/ui/Gralloc2.cpp index f23f10a1a9..e9b5decee8 100644 --- a/libs/ui/Gralloc2.cpp +++ b/libs/ui/Gralloc2.cpp @@ -161,7 +161,7 @@ status_t Gralloc2Mapper::createDescriptor(void* bufferDescriptorInfo, return static_cast<status_t>((ret.isOk()) ? error : kTransactionError); } -status_t Gralloc2Mapper::importBuffer(const hardware::hidl_handle& rawHandle, +status_t Gralloc2Mapper::importBuffer(const native_handle_t* rawHandle, buffer_handle_t* outBufferHandle) const { Error error; auto ret = mMapper->importBuffer(rawHandle, diff --git a/libs/ui/Gralloc3.cpp b/libs/ui/Gralloc3.cpp index 15c60bcadf..474d381dbb 100644 --- a/libs/ui/Gralloc3.cpp +++ b/libs/ui/Gralloc3.cpp @@ -138,7 +138,7 @@ status_t Gralloc3Mapper::createDescriptor(void* bufferDescriptorInfo, return static_cast<status_t>((ret.isOk()) ? error : kTransactionError); } -status_t Gralloc3Mapper::importBuffer(const hardware::hidl_handle& rawHandle, +status_t Gralloc3Mapper::importBuffer(const native_handle_t* rawHandle, buffer_handle_t* outBufferHandle) const { Error error; auto ret = mMapper->importBuffer(rawHandle, [&](const auto& tmpError, const auto& tmpBuffer) { diff --git a/libs/ui/Gralloc4.cpp b/libs/ui/Gralloc4.cpp index 53372c9866..b6274ab9c0 100644 --- a/libs/ui/Gralloc4.cpp +++ b/libs/ui/Gralloc4.cpp @@ -198,7 +198,7 @@ status_t Gralloc4Mapper::createDescriptor(void* bufferDescriptorInfo, return static_cast<status_t>((ret.isOk()) ? error : kTransactionError); } -status_t Gralloc4Mapper::importBuffer(const hardware::hidl_handle& rawHandle, +status_t Gralloc4Mapper::importBuffer(const native_handle_t* rawHandle, buffer_handle_t* outBufferHandle) const { Error error; auto ret = mMapper->importBuffer(rawHandle, [&](const auto& tmpError, const auto& tmpBuffer) { @@ -766,162 +766,6 @@ status_t Gralloc4Mapper::setSmpte2094_10(buffer_handle_t bufferHandle, gralloc4::encodeSmpte2094_10); } -template <class T> -status_t Gralloc4Mapper::getDefault(uint32_t width, uint32_t height, PixelFormat format, - uint32_t layerCount, uint64_t usage, - const MetadataType& metadataType, - DecodeFunction<T> 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<uint8_t> vec; - Error error; - auto ret = mMapper->getFromBufferDescriptorInfo(descriptorInfo, metadataType, - [&](const auto& tmpError, - const hidl_vec<uint8_t>& 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<status_t>(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<ui::PlaneLayout>* outPlaneLayouts) const { - return getDefault(width, height, format, layerCount, usage, gralloc4::MetadataType_PlaneLayouts, - gralloc4::decodePlaneLayouts, outPlaneLayouts); -} - std::vector<MetadataTypeDescription> Gralloc4Mapper::listSupportedMetadataTypes() const { hidl_vec<MetadataTypeDescription> descriptions; Error error; @@ -1242,7 +1086,10 @@ status_t Gralloc4Allocator::allocate(std::string requestorName, uint32_t width, if (mAidlAllocator) { AllocationResult result; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" auto status = mAidlAllocator->allocate(descriptor, bufferCount, &result); +#pragma clang diagnostic pop // deprecation if (!status.isOk()) { error = status.getExceptionCode(); if (error == EX_SERVICE_SPECIFIC) { diff --git a/libs/ui/Gralloc5.cpp b/libs/ui/Gralloc5.cpp new file mode 100644 index 0000000000..c3b2d3d808 --- /dev/null +++ b/libs/ui/Gralloc5.cpp @@ -0,0 +1,835 @@ +/* + * 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 <ui/Gralloc5.h> + +#include <aidlcommonsupport/NativeHandle.h> +#include <android/binder_manager.h> +#include <android/hardware/graphics/mapper/utils/IMapperMetadataTypes.h> +#include <binder/IPCThreadState.h> +#include <dlfcn.h> +#include <ui/FatVector.h> +#include <vndksupport/linker.h> + +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<uint64_t>((1 << 10) | (1 << 13)); + +typedef AIMapper_Error (*AIMapper_loadIMapperFn)(AIMapper *_Nullable *_Nonnull outImplementation); + +struct Gralloc5 { + std::shared_ptr<IAllocator> allocator; + AIMapper *mapper = nullptr; +}; + +static std::shared_ptr<IAllocator> 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 <StandardMetadataType T> +static auto getStandardMetadata(AIMapper *mapper, buffer_handle_t bufferHandle) + -> decltype(StandardMetadata<T>::value::decode(nullptr, 0)) { + using Value = typename StandardMetadata<T>::value; + // TODO: Tune for common-case better + FatVector<uint8_t, 128> buffer; + int32_t sizeRequired = mapper->v5.getStandardMetadata(bufferHandle, static_cast<int64_t>(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<int64_t>(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 <StandardMetadataType T> +static AIMapper_Error setStandardMetadata(AIMapper *mapper, buffer_handle_t bufferHandle, + const typename StandardMetadata<T>::value_type &value) { + using Value = typename StandardMetadata<T>::value; + int32_t sizeRequired = Value::encode(value, nullptr, 0); + if (sizeRequired < 0) { + ALOGW("Failed to calculate required size"); + return static_cast<AIMapper_Error>(-sizeRequired); + } + FatVector<uint8_t, 128> 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<AIMapper_Error>(-sizeRequired); + } + return mapper->v5.setStandardMetadata(bufferHandle, static_cast<int64_t>(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<BufferUsage>{}) { + bits |= static_cast<int64_t>(bit); + } + return bits; + }(); + return validUsageBits | kRemovedUsageBits; +} + +static std::optional<BufferDescriptorInfo> 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<int32_t>(width), + .height = static_cast<int32_t>(height), + .layerCount = static_cast<int32_t>(layerCount), + .format = static_cast<::aidl::android::hardware::graphics::common::PixelFormat>(format), + .usage = static_cast<BufferUsage>(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<native_handle_t *>(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<StandardMetadataType::WIDTH>(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<StandardMetadataType::HEIGHT>(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<StandardMetadataType::PIXEL_FORMAT_REQUESTED>(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() : "<null>"); + return BAD_VALUE; + } + } + { + auto value = getStandardMetadata<StandardMetadataType::LAYER_COUNT>(mMapper, bufferHandle); + if (layerCount != value) { + ALOGW("Layer count didn't match, expected %d got %" PRId64, layerCount, + value.value_or(-1)); + 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<StandardMetadataType::USAGE>(mMapper, bufferHandle); + // if (static_cast<BufferUsage>(usage) != value) { + // ALOGW("Usage didn't match, expected %" PRIu64 " got %" PRId64, usage, + // static_cast<int64_t>(value.value_or(BufferUsage::CPU_READ_NEVER))); + // return BAD_VALUE; + // } + // } + { + auto value = getStandardMetadata<StandardMetadataType::STRIDE>(mMapper, bufferHandle); + if (stride != value) { + ALOGW("Stride didn't match, expected %" PRIu32 " got %" PRId32, stride, + value.value_or(-1)); + 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<ui::PlaneLayout> 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_t>(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<ui::PlaneLayout> 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<uint8_t *>(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<PlaneLayoutComponentType>(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<int64_t>(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<StandardMetadataType::BUFFER_ID>(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<StandardMetadataType::NAME>(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<StandardMetadataType::WIDTH>(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<StandardMetadataType::HEIGHT>(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<StandardMetadataType::LAYER_COUNT>(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<StandardMetadataType::PIXEL_FORMAT_REQUESTED>(mMapper, + bufferHandle); + if (value.has_value()) { + *outPixelFormatRequested = static_cast<ui::PixelFormat>(*value); + return OK; + } + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getPixelFormatFourCC(buffer_handle_t bufferHandle, + uint32_t *outPixelFormatFourCC) const { + auto value = + getStandardMetadata<StandardMetadataType::PIXEL_FORMAT_FOURCC>(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<StandardMetadataType::PIXEL_FORMAT_MODIFIER>(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<StandardMetadataType::USAGE>(mMapper, bufferHandle); + if (value.has_value()) { + *outUsage = static_cast<uint64_t>(*value); + return OK; + } + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getAllocationSize(buffer_handle_t bufferHandle, + uint64_t *outAllocationSize) const { + auto value = getStandardMetadata<StandardMetadataType::ALLOCATION_SIZE>(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<StandardMetadataType::PROTECTED_CONTENT>(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<StandardMetadataType::COMPRESSION>(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<StandardMetadataType::COMPRESSION>(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<StandardMetadataType::INTERLACED>(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<StandardMetadataType::CHROMA_SITING>(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<ui::PlaneLayout> *outPlaneLayouts) const { + auto value = getStandardMetadata<StandardMetadataType::PLANE_LAYOUTS>(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<StandardMetadataType::DATASPACE>(mMapper, bufferHandle); + if (value.has_value()) { + *outDataspace = static_cast<ui::Dataspace>(*value); + return OK; + } + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::setDataspace(buffer_handle_t bufferHandle, ui::Dataspace dataspace) const { + return setStandardMetadata<StandardMetadataType::DATASPACE>(mMapper, bufferHandle, + static_cast<Dataspace>(dataspace)); +} + +status_t Gralloc5Mapper::getBlendMode(buffer_handle_t bufferHandle, + ui::BlendMode *outBlendMode) const { + auto value = getStandardMetadata<StandardMetadataType::BLEND_MODE>(mMapper, bufferHandle); + if (value.has_value()) { + *outBlendMode = static_cast<ui::BlendMode>(*value); + return OK; + } + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::getSmpte2086(buffer_handle_t bufferHandle, + std::optional<ui::Smpte2086> *outSmpte2086) const { + auto value = getStandardMetadata<StandardMetadataType::SMPTE2086>(mMapper, bufferHandle); + if (value.has_value()) { + *outSmpte2086 = *value; + return OK; + } + return UNKNOWN_TRANSACTION; +} + +status_t Gralloc5Mapper::setSmpte2086(buffer_handle_t bufferHandle, + std::optional<ui::Smpte2086> smpte2086) const { + return setStandardMetadata<StandardMetadataType::SMPTE2086>(mMapper, bufferHandle, smpte2086); +} + +status_t Gralloc5Mapper::getCta861_3(buffer_handle_t bufferHandle, + std::optional<ui::Cta861_3> *outCta861_3) const { + auto value = getStandardMetadata<StandardMetadataType::CTA861_3>(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<ui::Cta861_3> cta861_3) const { + return setStandardMetadata<StandardMetadataType::CTA861_3>(mMapper, bufferHandle, cta861_3); +} + +status_t Gralloc5Mapper::getSmpte2094_40( + buffer_handle_t bufferHandle, std::optional<std::vector<uint8_t>> *outSmpte2094_40) const { + auto value = getStandardMetadata<StandardMetadataType::SMPTE2094_40>(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<std::vector<uint8_t>> smpte2094_40) const { + return setStandardMetadata<StandardMetadataType::SMPTE2094_40>(mMapper, bufferHandle, + smpte2094_40); +} + +status_t Gralloc5Mapper::getSmpte2094_10( + buffer_handle_t bufferHandle, std::optional<std::vector<uint8_t>> *outSmpte2094_10) const { + auto value = getStandardMetadata<StandardMetadataType::SMPTE2094_10>(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<std::vector<uint8_t>> smpte2094_10) const { + return setStandardMetadata<StandardMetadataType::SMPTE2094_10>(mMapper, bufferHandle, + smpte2094_10); +} + +} // namespace android
\ No newline at end of file diff --git a/libs/ui/GraphicBufferAllocator.cpp b/libs/ui/GraphicBufferAllocator.cpp index 3f958ba68f..c0abec23e0 100644 --- a/libs/ui/GraphicBufferAllocator.cpp +++ b/libs/ui/GraphicBufferAllocator.cpp @@ -34,6 +34,7 @@ #include <ui/Gralloc2.h> #include <ui/Gralloc3.h> #include <ui/Gralloc4.h> +#include <ui/Gralloc5.h> #include <ui/GraphicBufferMapper.h> namespace android { @@ -48,23 +49,27 @@ KeyedVector<buffer_handle_t, GraphicBufferAllocator::alloc_rec_t> GraphicBufferAllocator::sAllocList; GraphicBufferAllocator::GraphicBufferAllocator() : mMapper(GraphicBufferMapper::getInstance()) { - mAllocator = std::make_unique<const Gralloc4Allocator>( - reinterpret_cast<const Gralloc4Mapper&>(mMapper.getGrallocMapper())); - if (mAllocator->isLoaded()) { - return; + switch (mMapper.getMapperVersion()) { + case GraphicBufferMapper::GRALLOC_5: + mAllocator = std::make_unique<const Gralloc5Allocator>( + reinterpret_cast<const Gralloc5Mapper&>(mMapper.getGrallocMapper())); + break; + case GraphicBufferMapper::GRALLOC_4: + mAllocator = std::make_unique<const Gralloc4Allocator>( + reinterpret_cast<const Gralloc4Mapper&>(mMapper.getGrallocMapper())); + break; + case GraphicBufferMapper::GRALLOC_3: + mAllocator = std::make_unique<const Gralloc3Allocator>( + reinterpret_cast<const Gralloc3Mapper&>(mMapper.getGrallocMapper())); + break; + case GraphicBufferMapper::GRALLOC_2: + mAllocator = std::make_unique<const Gralloc2Allocator>( + reinterpret_cast<const Gralloc2Mapper&>(mMapper.getGrallocMapper())); + break; } - mAllocator = std::make_unique<const Gralloc3Allocator>( - reinterpret_cast<const Gralloc3Mapper&>(mMapper.getGrallocMapper())); - if (mAllocator->isLoaded()) { - return; - } - mAllocator = std::make_unique<const Gralloc2Allocator>( - reinterpret_cast<const Gralloc2Mapper&>(mMapper.getGrallocMapper())); - if (mAllocator->isLoaded()) { - return; - } - - LOG_ALWAYS_FATAL("gralloc-allocator is missing"); + LOG_ALWAYS_FATAL_IF(!mAllocator->isLoaded(), + "Failed to load matching allocator for mapper version %d", + mMapper.getMapperVersion()); } GraphicBufferAllocator::~GraphicBufferAllocator() {} diff --git a/libs/ui/GraphicBufferMapper.cpp b/libs/ui/GraphicBufferMapper.cpp index f5824233e9..7086e0470c 100644 --- a/libs/ui/GraphicBufferMapper.cpp +++ b/libs/ui/GraphicBufferMapper.cpp @@ -36,6 +36,7 @@ #include <ui/Gralloc2.h> #include <ui/Gralloc3.h> #include <ui/Gralloc4.h> +#include <ui/Gralloc5.h> #include <ui/GraphicBuffer.h> #include <system/graphics.h> @@ -49,9 +50,15 @@ void GraphicBufferMapper::preloadHal() { Gralloc2Mapper::preload(); Gralloc3Mapper::preload(); Gralloc4Mapper::preload(); + Gralloc5Mapper::preload(); } GraphicBufferMapper::GraphicBufferMapper() { + mMapper = std::make_unique<const Gralloc5Mapper>(); + if (mMapper->isLoaded()) { + mMapperVersion = Version::GRALLOC_5; + return; + } mMapper = std::make_unique<const Gralloc4Mapper>(); if (mMapper->isLoaded()) { mMapperVersion = Version::GRALLOC_4; @@ -82,15 +89,14 @@ void GraphicBufferMapper::dumpBufferToSystemLog(buffer_handle_t bufferHandle, bo ALOGD("%s", s.c_str()); } -status_t GraphicBufferMapper::importBuffer(buffer_handle_t rawHandle, - uint32_t width, uint32_t height, uint32_t layerCount, - PixelFormat format, uint64_t usage, uint32_t stride, - buffer_handle_t* outHandle) -{ +status_t GraphicBufferMapper::importBuffer(const native_handle_t* rawHandle, uint32_t width, + uint32_t height, uint32_t layerCount, PixelFormat format, + uint64_t usage, uint32_t stride, + buffer_handle_t* outHandle) { ATRACE_CALL(); buffer_handle_t bufferHandle; - status_t error = mMapper->importBuffer(hardware::hidl_handle(rawHandle), &bufferHandle); + status_t error = mMapper->importBuffer(rawHandle, &bufferHandle); if (error != NO_ERROR) { ALOGW("importBuffer(%p) failed: %d", rawHandle, error); return error; @@ -335,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<ui::PlaneLayout>* outPlaneLayouts) { - return mMapper->getDefaultPlaneLayouts(width, height, format, layerCount, usage, - outPlaneLayouts); -} - // --------------------------------------------------------------------------- }; // namespace android diff --git a/libs/ui/HdrCapabilities.cpp b/libs/ui/HdrCapabilities.cpp deleted file mode 100644 index aec2fac780..0000000000 --- a/libs/ui/HdrCapabilities.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright 2016 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. - */ - -#include <ui/HdrCapabilities.h> - -namespace android { - -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wundefined-reinterpret-cast" -#endif - -size_t HdrCapabilities::getFlattenedSize() const { - return sizeof(mMaxLuminance) + - sizeof(mMaxAverageLuminance) + - sizeof(mMinLuminance) + - sizeof(int32_t) + - mSupportedHdrTypes.size() * sizeof(ui::Hdr); -} - -status_t HdrCapabilities::flatten(void* buffer, size_t size) const { - - if (size < getFlattenedSize()) { - return NO_MEMORY; - } - - int32_t* const buf = static_cast<int32_t*>(buffer); - reinterpret_cast<float&>(buf[0]) = mMaxLuminance; - reinterpret_cast<float&>(buf[1]) = mMaxAverageLuminance; - reinterpret_cast<float&>(buf[2]) = mMinLuminance; - buf[3] = static_cast<int32_t>(mSupportedHdrTypes.size()); - for (size_t i = 0, c = mSupportedHdrTypes.size(); i < c; ++i) { - buf[4 + i] = static_cast<int32_t>(mSupportedHdrTypes[i]); - } - return NO_ERROR; -} - -status_t HdrCapabilities::unflatten(void const* buffer, size_t size) { - - size_t minSize = sizeof(mMaxLuminance) + - sizeof(mMaxAverageLuminance) + - sizeof(mMinLuminance) + - sizeof(int32_t); - - if (size < minSize) { - return NO_MEMORY; - } - - int32_t const * const buf = static_cast<int32_t const *>(buffer); - const size_t itemCount = size_t(buf[3]); - - // check the buffer is large enough - if (size < minSize + itemCount * sizeof(int32_t)) { - return BAD_VALUE; - } - - mMaxLuminance = reinterpret_cast<float const&>(buf[0]); - mMaxAverageLuminance = reinterpret_cast<float const&>(buf[1]); - mMinLuminance = reinterpret_cast<float const&>(buf[2]); - if (itemCount) { - mSupportedHdrTypes.resize(itemCount); - for (size_t i = 0; i < itemCount; ++i) { - mSupportedHdrTypes[i] = static_cast<ui::Hdr>(buf[4 + i]); - } - } - return NO_ERROR; -} - -#if defined(__clang__) -#pragma clang diagnostic pop -#endif - -} // namespace android diff --git a/libs/ui/PublicFormat.cpp b/libs/ui/PublicFormat.cpp index 78e82dab39..c9663edd7a 100644 --- a/libs/ui/PublicFormat.cpp +++ b/libs/ui/PublicFormat.cpp @@ -14,14 +14,15 @@ * limitations under the License. */ -#include <ui/GraphicTypes.h> // ui::Dataspace +#include "aidl/android/hardware/graphics/common/Dataspace.h" #include <ui/PublicFormat.h> + // ---------------------------------------------------------------------------- namespace android { // ---------------------------------------------------------------------------- -using ui::Dataspace; +using ::aidl::android::hardware::graphics::common::Dataspace; int mapPublicFormatToHalFormat(PublicFormat f) { switch (f) { @@ -29,6 +30,7 @@ int mapPublicFormatToHalFormat(PublicFormat f) { case PublicFormat::DEPTH_POINT_CLOUD: case PublicFormat::DEPTH_JPEG: case PublicFormat::HEIC: + case PublicFormat::JPEG_R: return HAL_PIXEL_FORMAT_BLOB; case PublicFormat::DEPTH16: return HAL_PIXEL_FORMAT_Y16; @@ -47,7 +49,7 @@ android_dataspace mapPublicFormatToHalDataspace(PublicFormat f) { Dataspace dataspace; switch (f) { case PublicFormat::JPEG: - dataspace = Dataspace::V0_JFIF; + dataspace = Dataspace::JFIF; break; case PublicFormat::DEPTH_POINT_CLOUD: case PublicFormat::DEPTH16: @@ -64,7 +66,7 @@ android_dataspace mapPublicFormatToHalDataspace(PublicFormat f) { case PublicFormat::YUV_420_888: case PublicFormat::NV21: case PublicFormat::YV12: - dataspace = Dataspace::V0_JFIF; + dataspace = Dataspace::JFIF; break; case PublicFormat::DEPTH_JPEG: dataspace = Dataspace::DYNAMIC_DEPTH; @@ -72,6 +74,9 @@ android_dataspace mapPublicFormatToHalDataspace(PublicFormat f) { case PublicFormat::HEIC: dataspace = Dataspace::HEIF; break; + case PublicFormat::JPEG_R: + dataspace = Dataspace::JPEG_R; + break; default: // Most formats map to UNKNOWN dataspace = Dataspace::UNKNOWN; @@ -139,14 +144,16 @@ PublicFormat mapHalFormatDataspaceToPublicFormat(int format, android_dataspace d switch (ds) { case Dataspace::DEPTH: return PublicFormat::DEPTH_POINT_CLOUD; - case Dataspace::V0_JFIF: + case Dataspace::JFIF: return PublicFormat::JPEG; case Dataspace::HEIF: return PublicFormat::HEIC; default: if (dataSpace == static_cast<android_dataspace>(HAL_DATASPACE_DYNAMIC_DEPTH)) { return PublicFormat::DEPTH_JPEG; - } else { + } else if (dataSpace == static_cast<android_dataspace>(Dataspace::JPEG_R)) { + return PublicFormat::JPEG_R; + }else { // Assume otherwise-marked blobs are also JPEG return PublicFormat::JPEG; } diff --git a/libs/ui/StaticDisplayInfo.cpp b/libs/ui/StaticDisplayInfo.cpp deleted file mode 100644 index 03d15e4694..0000000000 --- a/libs/ui/StaticDisplayInfo.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2020 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. - */ - -#include <ui/StaticDisplayInfo.h> - -#include <cstdint> - -#include <ui/FlattenableHelpers.h> - -#define RETURN_IF_ERROR(op) \ - if (const status_t status = (op); status != OK) return status; - -namespace android::ui { - -size_t StaticDisplayInfo::getFlattenedSize() const { - return FlattenableHelpers::getFlattenedSize(connectionType) + - FlattenableHelpers::getFlattenedSize(density) + - FlattenableHelpers::getFlattenedSize(secure) + - FlattenableHelpers::getFlattenedSize(deviceProductInfo) + - FlattenableHelpers::getFlattenedSize(installOrientation); -} - -status_t StaticDisplayInfo::flatten(void* buffer, size_t size) const { - if (size < getFlattenedSize()) { - return NO_MEMORY; - } - RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, connectionType)); - RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, density)); - RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, secure)); - RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, deviceProductInfo)); - RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, installOrientation)); - return OK; -} - -status_t StaticDisplayInfo::unflatten(void const* buffer, size_t size) { - RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &connectionType)); - RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &density)); - RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &secure)); - RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &deviceProductInfo)); - RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &installOrientation)); - return OK; -} - -} // namespace android::ui diff --git a/libs/ui/include/ui/ColorMode.h b/libs/ui/include/ui/ColorMode.h new file mode 100644 index 0000000000..a47eaed171 --- /dev/null +++ b/libs/ui/include/ui/ColorMode.h @@ -0,0 +1,60 @@ +/* + * Copyright 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. + */ + +#pragma once + +#include <vector> + +#include <ui/GraphicTypes.h> + +namespace android::ui { + +using ColorModes = std::vector<ColorMode>; + +inline bool isWideColorMode(ColorMode colorMode) { + switch (colorMode) { + case ColorMode::DISPLAY_P3: + case ColorMode::ADOBE_RGB: + case ColorMode::DCI_P3: + case ColorMode::BT2020: + case ColorMode::DISPLAY_BT2020: + case ColorMode::BT2100_PQ: + case ColorMode::BT2100_HLG: + return true; + case ColorMode::NATIVE: + case ColorMode::STANDARD_BT601_625: + case ColorMode::STANDARD_BT601_625_UNADJUSTED: + case ColorMode::STANDARD_BT601_525: + case ColorMode::STANDARD_BT601_525_UNADJUSTED: + case ColorMode::STANDARD_BT709: + case ColorMode::SRGB: + return false; + } +} + +inline Dataspace pickDataspaceFor(ColorMode colorMode) { + switch (colorMode) { + case ColorMode::DISPLAY_P3: + case ColorMode::BT2100_PQ: + case ColorMode::BT2100_HLG: + case ColorMode::DISPLAY_BT2020: + return Dataspace::DISPLAY_P3; + default: + return Dataspace::V0_SRGB; + } +} + +} // namespace android::ui diff --git a/libs/ui/include/ui/DeviceProductInfo.h b/libs/ui/include/ui/DeviceProductInfo.h index 807a5d96a3..4229cf1507 100644 --- a/libs/ui/include/ui/DeviceProductInfo.h +++ b/libs/ui/include/ui/DeviceProductInfo.h @@ -24,8 +24,6 @@ #include <variant> #include <vector> -#include <utils/Flattenable.h> - namespace android { // NUL-terminated plug and play ID. @@ -34,7 +32,7 @@ using PnpId = std::array<char, 4>; // Product-specific information about the display or the directly connected device on the // display chain. For example, if the display is transitively connected, this field may contain // product information about the intermediate device. -struct DeviceProductInfo : LightFlattenable<DeviceProductInfo> { +struct DeviceProductInfo { struct ModelYear { uint32_t year; }; @@ -63,13 +61,8 @@ struct DeviceProductInfo : LightFlattenable<DeviceProductInfo> { // address is unavailable. // For example, for HDMI connected device this will be the physical address. std::vector<uint8_t> relativeAddress; - - bool isFixedSize() const { return false; } - size_t getFlattenedSize() const; - status_t flatten(void* buffer, size_t size) const; - status_t unflatten(void const* buffer, size_t size); - - void dump(std::string& result) const; }; +std::string to_string(const DeviceProductInfo&); + } // namespace android diff --git a/libs/ui/include/ui/DisplayId.h b/libs/ui/include/ui/DisplayId.h index 9120972a42..3a31fa0848 100644 --- a/libs/ui/include/ui/DisplayId.h +++ b/libs/ui/include/ui/DisplayId.h @@ -17,9 +17,11 @@ #pragma once #include <cstdint> -#include <optional> +#include <ostream> #include <string> +#include <ftl/optional.h> + namespace android { // ID of a physical or a virtual display. This class acts as a type safe wrapper around uint64_t. @@ -66,9 +68,14 @@ inline std::string to_string(DisplayId displayId) { return std::to_string(displayId.value); } +// For tests. +inline std::ostream& operator<<(std::ostream& stream, DisplayId displayId) { + return stream << "DisplayId{" << displayId.value << '}'; +} + // DisplayId of a physical display, such as the internal display or externally connected display. struct PhysicalDisplayId : DisplayId { - static constexpr std::optional<PhysicalDisplayId> tryCast(DisplayId id) { + static constexpr ftl::Optional<PhysicalDisplayId> tryCast(DisplayId id) { if (id.value & FLAG_VIRTUAL) { return std::nullopt; } diff --git a/libs/ui/include/ui/DisplayMode.h b/libs/ui/include/ui/DisplayMode.h index 56f68e7bb2..65a8769c98 100644 --- a/libs/ui/include/ui/DisplayMode.h +++ b/libs/ui/include/ui/DisplayMode.h @@ -19,6 +19,7 @@ #include <cstdint> #include <type_traits> +#include <ui/GraphicTypes.h> #include <ui/Size.h> #include <utils/Flattenable.h> #include <utils/Timers.h> @@ -29,22 +30,18 @@ namespace android::ui { using DisplayModeId = int32_t; // Mode supported by physical display. -struct DisplayMode : LightFlattenable<DisplayMode> { +struct DisplayMode { DisplayModeId id; ui::Size resolution; float xDpi = 0; float yDpi = 0; + std::vector<ui::Hdr> supportedHdrTypes; float refreshRate = 0; nsecs_t appVsyncOffset = 0; nsecs_t sfVsyncOffset = 0; nsecs_t presentationDeadline = 0; int32_t group = -1; - - bool isFixedSize() const { return false; } - size_t getFlattenedSize() const; - status_t flatten(void* buffer, size_t size) const; - status_t unflatten(const void* buffer, size_t size); }; } // namespace android::ui diff --git a/libs/ui/include/ui/DynamicDisplayInfo.h b/libs/ui/include/ui/DynamicDisplayInfo.h index ce75a65214..0b77754455 100644 --- a/libs/ui/include/ui/DynamicDisplayInfo.h +++ b/libs/ui/include/ui/DynamicDisplayInfo.h @@ -24,18 +24,18 @@ #include <ui/GraphicTypes.h> #include <ui/HdrCapabilities.h> -#include <utils/Flattenable.h> namespace android::ui { // Information about a physical display which may change on hotplug reconnect. -struct DynamicDisplayInfo : LightFlattenable<DynamicDisplayInfo> { +struct DynamicDisplayInfo { std::vector<ui::DisplayMode> supportedDisplayModes; // This struct is going to be serialized over binder, so // we can't use size_t because it may have different width // in the client process. ui::DisplayModeId activeDisplayModeId; + float renderFrameRate; std::vector<ui::ColorMode> supportedColorModes; ui::ColorMode activeColorMode; @@ -53,11 +53,6 @@ struct DynamicDisplayInfo : LightFlattenable<DynamicDisplayInfo> { ui::DisplayModeId preferredBootDisplayMode; std::optional<ui::DisplayMode> getActiveDisplayMode() const; - - bool isFixedSize() const { return false; } - size_t getFlattenedSize() const; - status_t flatten(void* buffer, size_t size) const; - status_t unflatten(const void* buffer, size_t size); }; } // namespace android::ui diff --git a/libs/ui/include/ui/FenceResult.h b/libs/ui/include/ui/FenceResult.h new file mode 100644 index 0000000000..6d63fc9973 --- /dev/null +++ b/libs/ui/include/ui/FenceResult.h @@ -0,0 +1,33 @@ +/* + * Copyright 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. + */ + +#pragma once + +#include <android-base/expected.h> +#include <utils/Errors.h> +#include <utils/StrongPointer.h> + +namespace android { + +class Fence; + +using FenceResult = base::expected<sp<Fence>, status_t>; + +inline status_t fenceStatus(const FenceResult& fenceResult) { + return fenceResult.ok() ? NO_ERROR : fenceResult.error(); +} + +} // namespace android diff --git a/libs/ui/include/ui/Gralloc.h b/libs/ui/include/ui/Gralloc.h index 6101d4b43b..496ba57789 100644 --- a/libs/ui/include/ui/Gralloc.h +++ b/libs/ui/include/ui/Gralloc.h @@ -39,14 +39,11 @@ public: return ""; } - virtual status_t createDescriptor(void* bufferDescriptorInfo, - void* outBufferDescriptor) const = 0; - // Import a buffer that is from another HAL, another process, or is // cloned. // // The returned handle must be freed with freeBuffer. - virtual status_t importBuffer(const hardware::hidl_handle& rawHandle, + virtual status_t importBuffer(const native_handle_t* rawHandle, buffer_handle_t* outBufferHandle) const = 0; virtual void freeBuffer(buffer_handle_t bufferHandle) const = 0; @@ -203,77 +200,6 @@ public: std::optional<std::vector<uint8_t>> /*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<ui::PlaneLayout>* /*outPlaneLayouts*/) const { - return INVALID_OPERATION; - } - - virtual std::vector<android::hardware::graphics::mapper::V4_0::IMapper::MetadataTypeDescription> - listSupportedMetadataTypes() const { - return {}; - } }; // A wrapper to IAllocator diff --git a/libs/ui/include/ui/Gralloc2.h b/libs/ui/include/ui/Gralloc2.h index f570c428b6..a7b6f49206 100644 --- a/libs/ui/include/ui/Gralloc2.h +++ b/libs/ui/include/ui/Gralloc2.h @@ -38,9 +38,9 @@ public: bool isLoaded() const override; - status_t createDescriptor(void* bufferDescriptorInfo, void* outBufferDescriptor) const override; + status_t createDescriptor(void* bufferDescriptorInfo, void* outBufferDescriptor) const; - status_t importBuffer(const hardware::hidl_handle& rawHandle, + status_t importBuffer(const native_handle_t* rawHandle, buffer_handle_t* outBufferHandle) const override; void freeBuffer(buffer_handle_t bufferHandle) const override; diff --git a/libs/ui/include/ui/Gralloc3.h b/libs/ui/include/ui/Gralloc3.h index 93a5077313..7367549964 100644 --- a/libs/ui/include/ui/Gralloc3.h +++ b/libs/ui/include/ui/Gralloc3.h @@ -37,9 +37,9 @@ public: bool isLoaded() const override; - status_t createDescriptor(void* bufferDescriptorInfo, void* outBufferDescriptor) const override; + status_t createDescriptor(void* bufferDescriptorInfo, void* outBufferDescriptor) const; - status_t importBuffer(const hardware::hidl_handle& rawHandle, + status_t importBuffer(const native_handle_t* rawHandle, buffer_handle_t* outBufferHandle) const override; void freeBuffer(buffer_handle_t bufferHandle) const override; diff --git a/libs/ui/include/ui/Gralloc4.h b/libs/ui/include/ui/Gralloc4.h index cf023c9bcc..df43be87cd 100644 --- a/libs/ui/include/ui/Gralloc4.h +++ b/libs/ui/include/ui/Gralloc4.h @@ -42,9 +42,9 @@ public: std::string dumpBuffer(buffer_handle_t bufferHandle, bool less = true) const override; std::string dumpBuffers(bool less = true) const; - status_t createDescriptor(void* bufferDescriptorInfo, void* outBufferDescriptor) const override; + status_t createDescriptor(void* bufferDescriptorInfo, void* outBufferDescriptor) const; - status_t importBuffer(const hardware::hidl_handle& rawHandle, + status_t importBuffer(const native_handle_t* rawHandle, buffer_handle_t* outBufferHandle) const override; void freeBuffer(buffer_handle_t bufferHandle) const override; @@ -120,42 +120,6 @@ public: std::optional<std::vector<uint8_t>>* outSmpte2094_10) const override; status_t setSmpte2094_10(buffer_handle_t bufferHandle, std::optional<std::vector<uint8_t>> 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<ui::PlaneLayout>* outPlaneLayouts) const override; std::vector<android::hardware::graphics::mapper::V4_0::IMapper::MetadataTypeDescription> listSupportedMetadataTypes() const; diff --git a/libs/ui/include/ui/Gralloc5.h b/libs/ui/include/ui/Gralloc5.h new file mode 100644 index 0000000000..44b97d1a6f --- /dev/null +++ b/libs/ui/include/ui/Gralloc5.h @@ -0,0 +1,184 @@ +/* + * 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. + */ + +#pragma once + +#include <aidl/android/hardware/graphics/allocator/IAllocator.h> +#include <android/hardware/graphics/mapper/IMapper.h> +#include <ui/Gralloc.h> + +namespace android { + +class Gralloc5Mapper : public GrallocMapper { +public: +public: + static void preload(); + + Gralloc5Mapper(); + + [[nodiscard]] bool isLoaded() const override; + + [[nodiscard]] std::string dumpBuffer(buffer_handle_t bufferHandle, bool less) const override; + + [[nodiscard]] std::string dumpBuffers(bool less = true) const; + + [[nodiscard]] status_t importBuffer(const native_handle_t *rawHandle, + buffer_handle_t *outBufferHandle) const override; + + void freeBuffer(buffer_handle_t bufferHandle) const override; + + [[nodiscard]] status_t validateBufferSize(buffer_handle_t bufferHandle, uint32_t width, + uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + uint32_t stride) const override; + + void getTransportSize(buffer_handle_t bufferHandle, uint32_t *outNumFds, + uint32_t *outNumInts) const override; + + [[nodiscard]] status_t lock(buffer_handle_t bufferHandle, uint64_t usage, const Rect &bounds, + int acquireFence, void **outData, int32_t *outBytesPerPixel, + int32_t *outBytesPerStride) const override; + + [[nodiscard]] status_t lock(buffer_handle_t bufferHandle, uint64_t usage, const Rect &bounds, + int acquireFence, android_ycbcr *ycbcr) const override; + + [[nodiscard]] int unlock(buffer_handle_t bufferHandle) const override; + + [[nodiscard]] status_t isSupported(uint32_t width, uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + bool *outSupported) const override; + + [[nodiscard]] status_t getBufferId(buffer_handle_t bufferHandle, + uint64_t *outBufferId) const override; + + [[nodiscard]] status_t getName(buffer_handle_t bufferHandle, + std::string *outName) const override; + + [[nodiscard]] status_t getWidth(buffer_handle_t bufferHandle, + uint64_t *outWidth) const override; + + [[nodiscard]] status_t getHeight(buffer_handle_t bufferHandle, + uint64_t *outHeight) const override; + + [[nodiscard]] status_t getLayerCount(buffer_handle_t bufferHandle, + uint64_t *outLayerCount) const override; + + [[nodiscard]] status_t getPixelFormatRequested( + buffer_handle_t bufferHandle, ui::PixelFormat *outPixelFormatRequested) const override; + + [[nodiscard]] status_t getPixelFormatFourCC(buffer_handle_t bufferHandle, + uint32_t *outPixelFormatFourCC) const override; + + [[nodiscard]] status_t getPixelFormatModifier(buffer_handle_t bufferHandle, + uint64_t *outPixelFormatModifier) const override; + + [[nodiscard]] status_t getUsage(buffer_handle_t bufferHandle, + uint64_t *outUsage) const override; + + [[nodiscard]] status_t getAllocationSize(buffer_handle_t bufferHandle, + uint64_t *outAllocationSize) const override; + + [[nodiscard]] status_t getProtectedContent(buffer_handle_t bufferHandle, + uint64_t *outProtectedContent) const override; + + [[nodiscard]] status_t getCompression(buffer_handle_t bufferHandle, + aidl::android::hardware::graphics::common::ExtendableType + *outCompression) const override; + + [[nodiscard]] status_t getCompression(buffer_handle_t bufferHandle, + ui::Compression *outCompression) const override; + + [[nodiscard]] status_t getInterlaced(buffer_handle_t bufferHandle, + aidl::android::hardware::graphics::common::ExtendableType + *outInterlaced) const override; + + [[nodiscard]] status_t getInterlaced(buffer_handle_t bufferHandle, + ui::Interlaced *outInterlaced) const override; + + [[nodiscard]] status_t getChromaSiting(buffer_handle_t bufferHandle, + aidl::android::hardware::graphics::common::ExtendableType + *outChromaSiting) const override; + + [[nodiscard]] status_t getChromaSiting(buffer_handle_t bufferHandle, + ui::ChromaSiting *outChromaSiting) const override; + + [[nodiscard]] status_t getPlaneLayouts( + buffer_handle_t bufferHandle, + std::vector<ui::PlaneLayout> *outPlaneLayouts) const override; + + [[nodiscard]] status_t getDataspace(buffer_handle_t bufferHandle, + ui::Dataspace *outDataspace) const override; + + [[nodiscard]] status_t setDataspace(buffer_handle_t bufferHandle, + ui::Dataspace dataspace) const override; + + [[nodiscard]] status_t getBlendMode(buffer_handle_t bufferHandle, + ui::BlendMode *outBlendMode) const override; + + [[nodiscard]] status_t getSmpte2086(buffer_handle_t bufferHandle, + std::optional<ui::Smpte2086> *outSmpte2086) const override; + + [[nodiscard]] status_t setSmpte2086(buffer_handle_t bufferHandle, + std::optional<ui::Smpte2086> smpte2086) const override; + + [[nodiscard]] status_t getCta861_3(buffer_handle_t bufferHandle, + std::optional<ui::Cta861_3> *outCta861_3) const override; + + [[nodiscard]] status_t setCta861_3(buffer_handle_t bufferHandle, + std::optional<ui::Cta861_3> cta861_3) const override; + + [[nodiscard]] status_t getSmpte2094_40( + buffer_handle_t bufferHandle, + std::optional<std::vector<uint8_t>> *outSmpte2094_40) const override; + + [[nodiscard]] status_t setSmpte2094_40( + buffer_handle_t bufferHandle, + std::optional<std::vector<uint8_t>> smpte2094_40) const override; + + [[nodiscard]] status_t getSmpte2094_10( + buffer_handle_t bufferHandle, + std::optional<std::vector<uint8_t>> *outSmpte2094_10) const override; + + [[nodiscard]] status_t setSmpte2094_10( + buffer_handle_t bufferHandle, + std::optional<std::vector<uint8_t>> smpte2094_10) const override; + +private: + void unlockBlocking(buffer_handle_t bufferHandle) const; + + AIMapper *mMapper = nullptr; +}; + +class Gralloc5Allocator : public GrallocAllocator { +public: + Gralloc5Allocator(const Gralloc5Mapper &mapper); + + [[nodiscard]] bool isLoaded() const override; + + [[nodiscard]] std::string dumpDebugInfo(bool less) const override; + + [[nodiscard]] status_t allocate(std::string requestorName, uint32_t width, uint32_t height, + PixelFormat format, uint32_t layerCount, uint64_t usage, + uint32_t bufferCount, uint32_t *outStride, + buffer_handle_t *outBufferHandles, + bool importBuffers) const override; + +private: + const Gralloc5Mapper &mMapper; + std::shared_ptr<aidl::android::hardware::graphics::allocator::IAllocator> mAllocator; +}; + +} // namespace android diff --git a/libs/ui/include/ui/GraphicBuffer.h b/libs/ui/include/ui/GraphicBuffer.h index 57be686592..dbe475b805 100644 --- a/libs/ui/include/ui/GraphicBuffer.h +++ b/libs/ui/include/ui/GraphicBuffer.h @@ -270,7 +270,7 @@ private: // Send a callback when a GraphicBuffer dies. // - // This is used for BufferStateLayer caching. GraphicBuffers are refcounted per process. When + // This is used for layer caching. GraphicBuffers are refcounted per process. When // A GraphicBuffer doesn't have any more sp<> in a process, it is destroyed. This causes // problems when trying to implicitcly cache across process boundaries. Ideally, both sides // of the cache would hold onto wp<> references. When an app dropped its sp<>, the GraphicBuffer diff --git a/libs/ui/include/ui/GraphicBufferMapper.h b/libs/ui/include/ui/GraphicBufferMapper.h index 37a2e1cc9f..3a5167ab25 100644 --- a/libs/ui/include/ui/GraphicBufferMapper.h +++ b/libs/ui/include/ui/GraphicBufferMapper.h @@ -42,9 +42,10 @@ class GraphicBufferMapper : public Singleton<GraphicBufferMapper> { public: enum Version { - GRALLOC_2, + GRALLOC_2 = 2, GRALLOC_3, GRALLOC_4, + GRALLOC_5, }; static void preloadHal(); static inline GraphicBufferMapper& get() { return getInstance(); } @@ -54,10 +55,9 @@ public: // The imported outHandle must be freed with freeBuffer when no longer // needed. rawHandle is owned by the caller. - status_t importBuffer(buffer_handle_t rawHandle, - uint32_t width, uint32_t height, uint32_t layerCount, - PixelFormat format, uint64_t usage, uint32_t stride, - buffer_handle_t* outHandle); + status_t importBuffer(const native_handle_t* rawHandle, uint32_t width, uint32_t height, + uint32_t layerCount, PixelFormat format, uint64_t usage, uint32_t stride, + buffer_handle_t* outHandle); status_t importBufferNoValidate(const native_handle_t* rawHandle, buffer_handle_t* outHandle); @@ -138,48 +138,6 @@ public: status_t setSmpte2094_10(buffer_handle_t bufferHandle, std::optional<std::vector<uint8_t>> 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<ui::PlaneLayout>* outPlaneLayouts); - const GrallocMapper& getGrallocMapper() const { return reinterpret_cast<const GrallocMapper&>(*mMapper); } diff --git a/libs/ui/include/ui/GraphicTypes.h b/libs/ui/include/ui/GraphicTypes.h index 8661c36676..1775d390f0 100644 --- a/libs/ui/include/ui/GraphicTypes.h +++ b/libs/ui/include/ui/GraphicTypes.h @@ -20,6 +20,7 @@ #include <aidl/android/hardware/graphics/common/ChromaSiting.h> #include <aidl/android/hardware/graphics/common/Compression.h> #include <aidl/android/hardware/graphics/common/Cta861_3.h> +#include <aidl/android/hardware/graphics/common/Hdr.h> #include <aidl/android/hardware/graphics/common/Interlaced.h> #include <aidl/android/hardware/graphics/common/PlaneLayout.h> #include <aidl/android/hardware/graphics/common/Smpte2086.h> @@ -42,7 +43,6 @@ namespace ui { using android::hardware::graphics::common::V1_1::RenderIntent; using android::hardware::graphics::common::V1_2::ColorMode; using android::hardware::graphics::common::V1_2::Dataspace; -using android::hardware::graphics::common::V1_2::Hdr; using android::hardware::graphics::common::V1_2::PixelFormat; /** @@ -50,6 +50,7 @@ using android::hardware::graphics::common::V1_2::PixelFormat; */ using aidl::android::hardware::graphics::common::BlendMode; using aidl::android::hardware::graphics::common::Cta861_3; +using aidl::android::hardware::graphics::common::Hdr; using aidl::android::hardware::graphics::common::PlaneLayout; using aidl::android::hardware::graphics::common::Smpte2086; diff --git a/libs/ui/include/ui/HdrCapabilities.h b/libs/ui/include/ui/HdrCapabilities.h index 813addeca6..ae54223585 100644 --- a/libs/ui/include/ui/HdrCapabilities.h +++ b/libs/ui/include/ui/HdrCapabilities.h @@ -22,12 +22,10 @@ #include <vector> #include <ui/GraphicTypes.h> -#include <utils/Flattenable.h> namespace android { -class HdrCapabilities : public LightFlattenable<HdrCapabilities> -{ +class HdrCapabilities { public: HdrCapabilities(const std::vector<ui::Hdr>& types, float maxLuminance, float maxAverageLuminance, float minLuminance) @@ -49,12 +47,6 @@ public: float getDesiredMaxAverageLuminance() const { return mMaxAverageLuminance; } float getDesiredMinLuminance() const { return mMinLuminance; } - // Flattenable protocol - bool isFixedSize() const { return false; } - size_t getFlattenedSize() const; - status_t flatten(void* buffer, size_t size) const; - status_t unflatten(void const* buffer, size_t size); - private: std::vector<ui::Hdr> mSupportedHdrTypes; float mMaxLuminance; diff --git a/libs/ui/include/ui/PublicFormat.h b/libs/ui/include/ui/PublicFormat.h index aa58805718..2248ccab0c 100644 --- a/libs/ui/include/ui/PublicFormat.h +++ b/libs/ui/include/ui/PublicFormat.h @@ -57,6 +57,7 @@ enum class PublicFormat { YCBCR_P010 = 0x36, DEPTH16 = 0x44363159, DEPTH_JPEG = 0x69656963, + JPEG_R = 0x1005, HEIC = 0x48454946, }; diff --git a/libs/ui/include/ui/Rotation.h b/libs/ui/include/ui/Rotation.h index 83d431dea3..c1d60f4f6c 100644 --- a/libs/ui/include/ui/Rotation.h +++ b/libs/ui/include/ui/Rotation.h @@ -20,7 +20,14 @@ namespace android::ui { -enum class Rotation { Rotation0 = 0, Rotation90 = 1, Rotation180 = 2, Rotation270 = 3 }; +enum class Rotation { + Rotation0 = 0, + Rotation90 = 1, + Rotation180 = 2, + Rotation270 = 3, + + ftl_last = Rotation270 +}; // Equivalent to Surface.java constants. constexpr auto ROTATION_0 = Rotation::Rotation0; diff --git a/libs/ui/include/ui/StaticDisplayInfo.h b/libs/ui/include/ui/StaticDisplayInfo.h index cc7c869b3b..83da821f37 100644 --- a/libs/ui/include/ui/StaticDisplayInfo.h +++ b/libs/ui/include/ui/StaticDisplayInfo.h @@ -20,24 +20,18 @@ #include <ui/DeviceProductInfo.h> #include <ui/Rotation.h> -#include <utils/Flattenable.h> namespace android::ui { -enum class DisplayConnectionType { Internal, External }; +enum class DisplayConnectionType { Internal, External, ftl_last = External }; // Immutable information about physical display. -struct StaticDisplayInfo : LightFlattenable<StaticDisplayInfo> { +struct StaticDisplayInfo { DisplayConnectionType connectionType = DisplayConnectionType::Internal; float density = 0.f; bool secure = false; std::optional<DeviceProductInfo> deviceProductInfo; Rotation installOrientation = ROTATION_0; - - bool isFixedSize() const { return false; } - size_t getFlattenedSize() const; - status_t flatten(void* buffer, size_t size) const; - status_t unflatten(void const* buffer, size_t size); }; } // namespace android::ui |