From 87c8ba767a25a4ee054d6c274405de89aae968c4 Mon Sep 17 00:00:00 2001 From: Marissa Wall Date: Thu, 20 Jun 2019 14:20:52 -0700 Subject: gralloc: add IAllocator/IMapper 4.0 to frameworks/native Add support for gralloc 4.0 to the framework. Bug: 136016160 Test: Compiles and boots Change-Id: I26408e984308fa557e102efabb60302907310308 --- libs/ui/GraphicBufferMapper.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'libs/ui/GraphicBufferMapper.cpp') diff --git a/libs/ui/GraphicBufferMapper.cpp b/libs/ui/GraphicBufferMapper.cpp index 25b7247b1b..4d087d151c 100644 --- a/libs/ui/GraphicBufferMapper.cpp +++ b/libs/ui/GraphicBufferMapper.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -47,20 +48,27 @@ ANDROID_SINGLETON_STATIC_INSTANCE( GraphicBufferMapper ) void GraphicBufferMapper::preloadHal() { Gralloc2Mapper::preload(); Gralloc3Mapper::preload(); + Gralloc4Mapper::preload(); } GraphicBufferMapper::GraphicBufferMapper() { + mMapper = std::make_unique(); + if (mMapper->isLoaded()) { + mMapperVersion = Version::GRALLOC_4; + return; + } mMapper = std::make_unique(); - if (!mMapper->isLoaded()) { - mMapper = std::make_unique(); - mMapperVersion = Version::GRALLOC_2; - } else { + if (mMapper->isLoaded()) { mMapperVersion = Version::GRALLOC_3; + return; } - - if (!mMapper->isLoaded()) { - LOG_ALWAYS_FATAL("gralloc-mapper is missing"); + mMapper = std::make_unique(); + if (mMapper->isLoaded()) { + mMapperVersion = Version::GRALLOC_2; + return; } + + LOG_ALWAYS_FATAL("gralloc-mapper is missing"); } status_t GraphicBufferMapper::importBuffer(buffer_handle_t rawHandle, -- cgit v1.2.3-59-g8ed1b From 22b2de1f4389befcd2eff9e894f53f872aa6f731 Mon Sep 17 00:00:00 2001 From: Marissa Wall Date: Mon, 2 Dec 2019 18:11:43 -0800 Subject: gralloc: expose Gralloc4 get/dump functions Expose Gralloc4 functions up to GraphicBufferAllocator/Mapper. By adding the functions to GraphicBufferAllocator/Mapper, the rest of the system can depend on GraphicBufferAllocator/Mapper instead of talking directly to IAllocator/IMapper. Bug: 141632767 Test: Implementation will be tested through VtsHalGraphicsMapperV4_0TargetTest Framework plumbing will be testing when it is exposed to GraphicBuffer Change-Id: Ie74a335a9d3a1e085e9fa186b327be8d21e870de --- libs/gralloc/types/Gralloc4.cpp | 144 +++- libs/gralloc/types/include/gralloctypes/Gralloc4.h | 181 +++-- libs/ui/Android.bp | 5 + libs/ui/Gralloc2.cpp | 16 +- libs/ui/Gralloc3.cpp | 10 +- libs/ui/Gralloc4.cpp | 781 ++++++++++++++++++++- libs/ui/GraphicBufferAllocator.cpp | 18 +- libs/ui/GraphicBufferMapper.cpp | 188 +++++ libs/ui/include/ui/Gralloc.h | 178 ++++- libs/ui/include/ui/Gralloc2.h | 12 +- libs/ui/include/ui/Gralloc3.h | 9 +- libs/ui/include/ui/Gralloc4.h | 128 +++- libs/ui/include/ui/GraphicBufferAllocator.h | 34 +- libs/ui/include/ui/GraphicBufferMapper.h | 81 ++- libs/ui/include/ui/GraphicTypes.h | 30 +- libs/ui/include_vndk/ui/Gralloc2.h | 1 - libs/ui/tests/Android.bp | 3 +- libs/ui/tests/GraphicBufferAllocator_test.cpp | 2 +- libs/ui/tests/mock/MockGrallocAllocator.h | 6 +- services/surfaceflinger/SurfaceFlinger.cpp | 1 + 20 files changed, 1635 insertions(+), 193 deletions(-) delete mode 120000 libs/ui/include_vndk/ui/Gralloc2.h (limited to 'libs/ui/GraphicBufferMapper.cpp') diff --git a/libs/gralloc/types/Gralloc4.cpp b/libs/gralloc/types/Gralloc4.cpp index 0330dac526..fd91b15c02 100644 --- a/libs/gralloc/types/Gralloc4.cpp +++ b/libs/gralloc/types/Gralloc4.cpp @@ -25,15 +25,19 @@ using android::hardware::hidl_vec; -using ::aidl::android::hardware::graphics::common::BlendMode; -using ::aidl::android::hardware::graphics::common::Dataspace; -using ::aidl::android::hardware::graphics::common::PlaneLayout; -using ::aidl::android::hardware::graphics::common::PlaneLayoutComponent; -using ::aidl::android::hardware::graphics::common::ExtendableType; -using ::aidl::android::hardware::graphics::common::Rect; -using ::aidl::android::hardware::graphics::common::StandardMetadataType; - -using MetadataType = ::android::hardware::graphics::mapper::V4_0::IMapper::MetadataType; +using aidl::android::hardware::graphics::common::BlendMode; +using aidl::android::hardware::graphics::common::ChromaSiting; +using aidl::android::hardware::graphics::common::Compression; +using aidl::android::hardware::graphics::common::Dataspace; +using aidl::android::hardware::graphics::common::ExtendableType; +using aidl::android::hardware::graphics::common::Interlaced; +using aidl::android::hardware::graphics::common::PlaneLayout; +using aidl::android::hardware::graphics::common::PlaneLayoutComponent; +using aidl::android::hardware::graphics::common::PlaneLayoutComponentType; +using aidl::android::hardware::graphics::common::Rect; +using aidl::android::hardware::graphics::common::StandardMetadataType; + +using MetadataType = android::hardware::graphics::mapper::V4_0::IMapper::MetadataType; namespace android { @@ -545,12 +549,9 @@ void clearPlaneLayouts(std::vector* output) { /** * Public API functions */ -bool isStandardMetadataType(const MetadataType& metadataType) { - return !std::strncmp(metadataType.name.c_str(), GRALLOC4_STANDARD_METADATA_TYPE, metadataType.name.size()); -} - -StandardMetadataType getStandardMetadataTypeValue(const MetadataType& metadataType) { - return static_cast(metadataType.value); +PlaneLayoutComponentType getStandardPlaneLayoutComponentTypeValue( + const ExtendableType& planeLayoutComponentType) { + return static_cast(planeLayoutComponentType.value); } status_t encodeBufferId(uint64_t bufferId, hidl_vec* outBufferId) { @@ -691,6 +692,119 @@ status_t decodeBlendMode(const hidl_vec& blendMode, BlendMode* outBlend return decode(blendMode, reinterpret_cast(outBlendMode), decodeInteger); } +bool isStandardMetadataType(const MetadataType& metadataType) { + return !std::strncmp(metadataType.name.c_str(), GRALLOC4_STANDARD_METADATA_TYPE, + metadataType.name.size()); +} + +bool isStandardCompression(const ExtendableType& compression) { + return !std::strncmp(compression.name.c_str(), GRALLOC4_STANDARD_COMPRESSION, + compression.name.size()); +} + +bool isStandardInterlaced(const ExtendableType& interlaced) { + return !std::strncmp(interlaced.name.c_str(), GRALLOC4_STANDARD_INTERLACED, + interlaced.name.size()); +} + +bool isStandardChromaSiting(const ExtendableType& chromaSiting) { + return !std::strncmp(chromaSiting.name.c_str(), GRALLOC4_STANDARD_CHROMA_SITING, + chromaSiting.name.size()); +} + +bool isStandardPlaneLayoutComponentType(const ExtendableType& planeLayoutComponentType) { + return !std::strncmp(planeLayoutComponentType.name.c_str(), GRALLOC4_STANDARD_PLANE_LAYOUT_COMPONENT_TYPE, + planeLayoutComponentType.name.size()); +} + +StandardMetadataType getStandardMetadataTypeValue(const MetadataType& metadataType) { + return static_cast(metadataType.value); +} + +Compression getStandardCompressionValue(const ExtendableType& compression) { + return static_cast(compression.value); +} + +Interlaced getStandardInterlacedValue(const ExtendableType& interlaced) { + return static_cast(interlaced.value); +} + +ChromaSiting getStandardChromaSitingValue(const ExtendableType& chromaSiting) { + return static_cast(chromaSiting.value); +} + +std::string getCompressionName(const ExtendableType& compression) { + if (!isStandardCompression(compression)) { + std::ostringstream stream; + stream << compression.name << "#" << compression.value; + return stream.str(); + } + switch (getStandardCompressionValue(compression)) { + case Compression::NONE: + return "None"; + case Compression::DISPLAY_STREAM_COMPRESSION: + return "DisplayStreamCompression"; + } +} + +std::string getInterlacedName(const ExtendableType& interlaced) { + if (!isStandardInterlaced(interlaced)) { + std::ostringstream stream; + stream << interlaced.name << "#" << interlaced.value; + return stream.str(); + } + switch (getStandardInterlacedValue(interlaced)) { + case Interlaced::NONE: + return "None"; + case Interlaced::TOP_BOTTOM: + return "TopBottom"; + case Interlaced::RIGHT_LEFT: + return "RightLeft"; + } +} + +std::string getChromaSitingName(const ExtendableType& chromaSiting) { + if (!isStandardChromaSiting(chromaSiting)) { + std::ostringstream stream; + stream << chromaSiting.name << "#" << chromaSiting.value; + return stream.str(); + } + switch (getStandardChromaSitingValue(chromaSiting)) { + case ChromaSiting::NONE: + return "None"; + case ChromaSiting::UNKNOWN: + return "Unknown"; + case ChromaSiting::SITED_INTERSTITIAL: + return "SitedInterstitial"; + case ChromaSiting::COSITED_HORIZONTAL: + return "CositedHorizontal"; + } +} + +std::string getPlaneLayoutComponentTypeName(const ExtendableType& planeLayoutComponentType) { + if (!isStandardPlaneLayoutComponentType(planeLayoutComponentType)) { + std::ostringstream stream; + stream << planeLayoutComponentType.name << "#" << planeLayoutComponentType.value; + return stream.str(); + } + switch (getStandardPlaneLayoutComponentTypeValue(planeLayoutComponentType)) { + case PlaneLayoutComponentType::Y: + return "Y"; + case PlaneLayoutComponentType::CB: + return "Cb"; + case PlaneLayoutComponentType::CR: + return "Cr"; + case PlaneLayoutComponentType::R: + return "R"; + case PlaneLayoutComponentType::G: + return "G"; + case PlaneLayoutComponentType::B: + return "B"; + case PlaneLayoutComponentType::A: + return "A"; + } +} + } // namespace gralloc4 } // namespace android diff --git a/libs/gralloc/types/include/gralloctypes/Gralloc4.h b/libs/gralloc/types/include/gralloctypes/Gralloc4.h index 80588cde73..a5d3bb2975 100644 --- a/libs/gralloc/types/include/gralloctypes/Gralloc4.h +++ b/libs/gralloc/types/include/gralloctypes/Gralloc4.h @@ -34,10 +34,11 @@ namespace android { namespace gralloc4 { #define GRALLOC4_STANDARD_METADATA_TYPE "android.hardware.graphics.common.StandardMetadataType" -#define GRALLOC4_CHROMA_SITING "android.hardware.graphics.common.ChromaSiting" -#define GRALLOC4_COMPRESSION "android.hardware.graphics.common.Compression" -#define GRALLOC4_INTERLACED "android.hardware.graphics.common.Interlaced" -#define GRALLOC4_PLANE_LAYOUT_COMPONENT_TYPE "android.hardware.graphics.common.PlaneLayoutComponentType" +#define GRALLOC4_STANDARD_CHROMA_SITING "android.hardware.graphics.common.ChromaSiting" +#define GRALLOC4_STANDARD_COMPRESSION "android.hardware.graphics.common.Compression" +#define GRALLOC4_STANDARD_INTERLACED "android.hardware.graphics.common.Interlaced" +#define GRALLOC4_STANDARD_PLANE_LAYOUT_COMPONENT_TYPE \ + "android.hardware.graphics.common.PlaneLayoutComponentType" /*---------------------------------------------------------------------------------------------*/ /** @@ -118,13 +119,15 @@ static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType Me * Definitions of the standard compression strategies. It is recommended that everyone uses * these definitions directly for standard compression strategies. */ -static const aidl::android::hardware::graphics::common::ExtendableType Compression_None = { - GRALLOC4_COMPRESSION, static_cast(aidl::android::hardware::graphics::common::Compression::NONE) -}; +static const aidl::android::hardware::graphics::common::ExtendableType Compression_None = + {GRALLOC4_STANDARD_COMPRESSION, + static_cast(aidl::android::hardware::graphics::common::Compression::NONE)}; -static const aidl::android::hardware::graphics::common::ExtendableType Compression_DisplayStreamCompression = { - GRALLOC4_COMPRESSION, static_cast(aidl::android::hardware::graphics::common::Compression::DISPLAY_STREAM_COMPRESSION) -}; +static const aidl::android::hardware::graphics::common::ExtendableType + Compression_DisplayStreamCompression = + {GRALLOC4_STANDARD_COMPRESSION, + static_cast(aidl::android::hardware::graphics::common::Compression:: + DISPLAY_STREAM_COMPRESSION)}; /*---------------------------------------------------------------------------------------------*/ @@ -132,17 +135,17 @@ static const aidl::android::hardware::graphics::common::ExtendableType Compressi * Definitions of the standard interlaced strategies. It is recommended that everyone uses * these definitions directly for standard interlaced strategies. */ -static const aidl::android::hardware::graphics::common::ExtendableType Interlaced_None = { - GRALLOC4_INTERLACED, static_cast(aidl::android::hardware::graphics::common::Interlaced::NONE) -}; +static const aidl::android::hardware::graphics::common::ExtendableType Interlaced_None = + {GRALLOC4_STANDARD_INTERLACED, + static_cast(aidl::android::hardware::graphics::common::Interlaced::NONE)}; -static const aidl::android::hardware::graphics::common::ExtendableType Interlaced_TopBottom = { - GRALLOC4_INTERLACED, static_cast(aidl::android::hardware::graphics::common::Interlaced::TOP_BOTTOM) -}; +static const aidl::android::hardware::graphics::common::ExtendableType Interlaced_TopBottom = + {GRALLOC4_STANDARD_INTERLACED, + static_cast(aidl::android::hardware::graphics::common::Interlaced::TOP_BOTTOM)}; -static const aidl::android::hardware::graphics::common::ExtendableType Interlaced_RightLeft = { - GRALLOC4_INTERLACED, static_cast(aidl::android::hardware::graphics::common::Interlaced::RIGHT_LEFT) -}; +static const aidl::android::hardware::graphics::common::ExtendableType Interlaced_RightLeft = + {GRALLOC4_STANDARD_INTERLACED, + static_cast(aidl::android::hardware::graphics::common::Interlaced::RIGHT_LEFT)}; /*---------------------------------------------------------------------------------------------*/ @@ -150,21 +153,25 @@ static const aidl::android::hardware::graphics::common::ExtendableType Interlace * Definitions of the standard chroma siting. It is recommended that everyone uses * these definitions directly for standard chroma siting. */ -static const aidl::android::hardware::graphics::common::ExtendableType ChromaSiting_None = { - GRALLOC4_CHROMA_SITING, static_cast(aidl::android::hardware::graphics::common::ChromaSiting::NONE) -}; - -static const aidl::android::hardware::graphics::common::ExtendableType ChromaSiting_Unknown = { - GRALLOC4_CHROMA_SITING, static_cast(aidl::android::hardware::graphics::common::ChromaSiting::UNKNOWN) -}; - -static const aidl::android::hardware::graphics::common::ExtendableType ChromaSiting_SitedInterstitial = { - GRALLOC4_CHROMA_SITING, static_cast(aidl::android::hardware::graphics::common::ChromaSiting::SITED_INTERSTITIAL) -}; - -static const aidl::android::hardware::graphics::common::ExtendableType ChromaSiting_CositedHorizontal = { - GRALLOC4_CHROMA_SITING, static_cast(aidl::android::hardware::graphics::common::ChromaSiting::COSITED_HORIZONTAL) -}; +static const aidl::android::hardware::graphics::common::ExtendableType ChromaSiting_None = + {GRALLOC4_STANDARD_CHROMA_SITING, + static_cast(aidl::android::hardware::graphics::common::ChromaSiting::NONE)}; + +static const aidl::android::hardware::graphics::common::ExtendableType ChromaSiting_Unknown = + {GRALLOC4_STANDARD_CHROMA_SITING, + static_cast(aidl::android::hardware::graphics::common::ChromaSiting::UNKNOWN)}; + +static const aidl::android::hardware::graphics::common::ExtendableType + ChromaSiting_SitedInterstitial = {GRALLOC4_STANDARD_CHROMA_SITING, + static_cast( + aidl::android::hardware::graphics::common:: + ChromaSiting::SITED_INTERSTITIAL)}; + +static const aidl::android::hardware::graphics::common::ExtendableType + ChromaSiting_CositedHorizontal = {GRALLOC4_STANDARD_CHROMA_SITING, + static_cast( + aidl::android::hardware::graphics::common:: + ChromaSiting::COSITED_HORIZONTAL)}; /*---------------------------------------------------------------------------------------------*/ @@ -172,43 +179,43 @@ static const aidl::android::hardware::graphics::common::ExtendableType ChromaSit * Definitions of the standard plane layout component types. It is recommended that everyone uses * these definitions directly for standard plane layout component types */ -static const aidl::android::hardware::graphics::common::ExtendableType PlaneLayoutComponentType_Y = { - GRALLOC4_PLANE_LAYOUT_COMPONENT_TYPE, static_cast(aidl::android::hardware::graphics::common::PlaneLayoutComponentType::Y) -}; - -static const aidl::android::hardware::graphics::common::ExtendableType PlaneLayoutComponentType_CB = { - GRALLOC4_PLANE_LAYOUT_COMPONENT_TYPE, static_cast(aidl::android::hardware::graphics::common::PlaneLayoutComponentType::CB) -}; - -static const aidl::android::hardware::graphics::common::ExtendableType PlaneLayoutComponentType_CR = { - GRALLOC4_PLANE_LAYOUT_COMPONENT_TYPE, static_cast(aidl::android::hardware::graphics::common::PlaneLayoutComponentType::CR) -}; - -static const aidl::android::hardware::graphics::common::ExtendableType PlaneLayoutComponentType_R = { - GRALLOC4_PLANE_LAYOUT_COMPONENT_TYPE, static_cast(aidl::android::hardware::graphics::common::PlaneLayoutComponentType::R) -}; - -static const aidl::android::hardware::graphics::common::ExtendableType PlaneLayoutComponentType_G = { - GRALLOC4_PLANE_LAYOUT_COMPONENT_TYPE, static_cast(aidl::android::hardware::graphics::common::PlaneLayoutComponentType::G) -}; - -static const aidl::android::hardware::graphics::common::ExtendableType PlaneLayoutComponentType_B = { - GRALLOC4_PLANE_LAYOUT_COMPONENT_TYPE, static_cast(aidl::android::hardware::graphics::common::PlaneLayoutComponentType::B) -}; - -static const aidl::android::hardware::graphics::common::ExtendableType PlaneLayoutComponentType_A = { - GRALLOC4_PLANE_LAYOUT_COMPONENT_TYPE, static_cast(aidl::android::hardware::graphics::common::PlaneLayoutComponentType::A) -}; +static const aidl::android::hardware::graphics::common::ExtendableType PlaneLayoutComponentType_Y = + {GRALLOC4_STANDARD_PLANE_LAYOUT_COMPONENT_TYPE, + static_cast( + aidl::android::hardware::graphics::common::PlaneLayoutComponentType::Y)}; + +static const aidl::android::hardware::graphics::common::ExtendableType PlaneLayoutComponentType_CB = + {GRALLOC4_STANDARD_PLANE_LAYOUT_COMPONENT_TYPE, + static_cast( + aidl::android::hardware::graphics::common::PlaneLayoutComponentType::CB)}; + +static const aidl::android::hardware::graphics::common::ExtendableType PlaneLayoutComponentType_CR = + {GRALLOC4_STANDARD_PLANE_LAYOUT_COMPONENT_TYPE, + static_cast( + aidl::android::hardware::graphics::common::PlaneLayoutComponentType::CR)}; + +static const aidl::android::hardware::graphics::common::ExtendableType PlaneLayoutComponentType_R = + {GRALLOC4_STANDARD_PLANE_LAYOUT_COMPONENT_TYPE, + static_cast( + aidl::android::hardware::graphics::common::PlaneLayoutComponentType::R)}; + +static const aidl::android::hardware::graphics::common::ExtendableType PlaneLayoutComponentType_G = + {GRALLOC4_STANDARD_PLANE_LAYOUT_COMPONENT_TYPE, + static_cast( + aidl::android::hardware::graphics::common::PlaneLayoutComponentType::G)}; + +static const aidl::android::hardware::graphics::common::ExtendableType PlaneLayoutComponentType_B = + {GRALLOC4_STANDARD_PLANE_LAYOUT_COMPONENT_TYPE, + static_cast( + aidl::android::hardware::graphics::common::PlaneLayoutComponentType::B)}; + +static const aidl::android::hardware::graphics::common::ExtendableType PlaneLayoutComponentType_A = + {GRALLOC4_STANDARD_PLANE_LAYOUT_COMPONENT_TYPE, + static_cast( + aidl::android::hardware::graphics::common::PlaneLayoutComponentType::A)}; /*---------------------------------------------------------------------------------------------*/ -/** - * The functions below can be used to parse a StandardMetadataType. - */ -bool isStandardMetadataType(const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType& metadataType); - -aidl::android::hardware::graphics::common::StandardMetadataType getStandardMetadataTypeValue(const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType& metadataType); - /** * The functions below encode and decode standard metadata into a byte stream. It is STRONGLY * recommended that both the vendor and system partitions use these functions when getting @@ -265,6 +272,44 @@ status_t decodeDataspace(const android::hardware::hidl_vec& dataspace, status_t encodeBlendMode(const aidl::android::hardware::graphics::common::BlendMode& blendMode, android::hardware::hidl_vec* outBlendMode); status_t decodeBlendMode(const android::hardware::hidl_vec& blendMode, aidl::android::hardware::graphics::common::BlendMode* outBlendMode); +/** + * The functions below can be used to parse extendable types. + */ +bool isStandardMetadataType( + const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType& metadataType); +bool isStandardCompression( + const aidl::android::hardware::graphics::common::ExtendableType& compression); +bool isStandardInterlaced( + const aidl::android::hardware::graphics::common::ExtendableType& interlaced); +bool isStandardChromaSiting( + const aidl::android::hardware::graphics::common::ExtendableType& chromaSiting); +bool isStandardPlaneLayoutComponentType( + const aidl::android::hardware::graphics::common::ExtendableType& planeLayoutComponentType); + +aidl::android::hardware::graphics::common::StandardMetadataType getStandardMetadataTypeValue( + const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType& metadataType); +aidl::android::hardware::graphics::common::Compression getStandardCompressionValue( + const aidl::android::hardware::graphics::common::ExtendableType& compression); +aidl::android::hardware::graphics::common::Interlaced getStandardInterlacedValue( + const aidl::android::hardware::graphics::common::ExtendableType& interlaced); +aidl::android::hardware::graphics::common::ChromaSiting getStandardChromaSitingValue( + const aidl::android::hardware::graphics::common::ExtendableType& chromaSiting); +aidl::android::hardware::graphics::common::PlaneLayoutComponentType +getStandardPlaneLayoutComponentTypeValue( + const aidl::android::hardware::graphics::common::ExtendableType& planeLayoutComponentType); + +/** + * The functions below return string representations of ExtendableTypes + */ +std::string getCompressionName( + const aidl::android::hardware::graphics::common::ExtendableType& compression); +std::string getInterlacedName( + const aidl::android::hardware::graphics::common::ExtendableType& interlaced); +std::string getChromaSitingName( + const aidl::android::hardware::graphics::common::ExtendableType& chromaSiting); +std::string getPlaneLayoutComponentTypeName( + const aidl::android::hardware::graphics::common::ExtendableType& planeLayoutComponentType); + } // namespace gralloc4 } // namespace android diff --git a/libs/ui/Android.bp b/libs/ui/Android.bp index 3775e2b600..124bda2fb3 100644 --- a/libs/ui/Android.bp +++ b/libs/ui/Android.bp @@ -89,14 +89,19 @@ cc_library_shared { "android.hardware.graphics.mapper@4.0", "libbase", "libcutils", + "libgralloctypes", "libhidlbase", "libsync", "libutils", "liblog", + "vintf-graphics-common-ndk_platform", ], export_shared_lib_headers: [ "android.hardware.graphics.common@1.2", + "android.hardware.graphics.mapper@4.0", + "libgralloctypes", + "vintf-graphics-common-ndk_platform", ], static_libs: [ diff --git a/libs/ui/Gralloc2.cpp b/libs/ui/Gralloc2.cpp index 0e23ddf74a..040a62b542 100644 --- a/libs/ui/Gralloc2.cpp +++ b/libs/ui/Gralloc2.cpp @@ -351,12 +351,6 @@ int Gralloc2Mapper::unlock(buffer_handle_t bufferHandle) const { return releaseFence; } -status_t Gralloc2Mapper::isSupported(uint32_t /*width*/, uint32_t /*height*/, - android::PixelFormat /*format*/, uint32_t /*layerCount*/, - uint64_t /*usage*/, bool* /*outSupported*/) const { - return INVALID_OPERATION; -} - Gralloc2Allocator::Gralloc2Allocator(const Gralloc2Mapper& mapper) : mMapper(mapper) { mAllocator = IAllocator::getService(); if (mAllocator == nullptr) { @@ -369,7 +363,7 @@ bool Gralloc2Allocator::isLoaded() const { return mAllocator != nullptr; } -std::string Gralloc2Allocator::dumpDebugInfo() const { +std::string Gralloc2Allocator::dumpDebugInfo(bool /*less*/) const { std::string debugInfo; mAllocator->dumpDebugInfo([&](const auto& tmpDebugInfo) { @@ -379,10 +373,10 @@ std::string Gralloc2Allocator::dumpDebugInfo() const { return debugInfo; } -status_t Gralloc2Allocator::allocate(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 { +status_t Gralloc2Allocator::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 { IMapper::BufferDescriptorInfo descriptorInfo = {}; descriptorInfo.width = width; descriptorInfo.height = height; diff --git a/libs/ui/Gralloc3.cpp b/libs/ui/Gralloc3.cpp index e189281c46..882674f479 100644 --- a/libs/ui/Gralloc3.cpp +++ b/libs/ui/Gralloc3.cpp @@ -352,7 +352,7 @@ bool Gralloc3Allocator::isLoaded() const { return mAllocator != nullptr; } -std::string Gralloc3Allocator::dumpDebugInfo() const { +std::string Gralloc3Allocator::dumpDebugInfo(bool /*less*/) const { std::string debugInfo; mAllocator->dumpDebugInfo([&](const auto& tmpDebugInfo) { debugInfo = tmpDebugInfo.c_str(); }); @@ -360,10 +360,10 @@ std::string Gralloc3Allocator::dumpDebugInfo() const { return debugInfo; } -status_t Gralloc3Allocator::allocate(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 { +status_t Gralloc3Allocator::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 { IMapper::BufferDescriptorInfo descriptorInfo; sBufferDescriptorInfo(width, height, format, layerCount, usage, &descriptorInfo); diff --git a/libs/ui/Gralloc4.cpp b/libs/ui/Gralloc4.cpp index afe26b7bf3..2c897cf4ff 100644 --- a/libs/ui/Gralloc4.cpp +++ b/libs/ui/Gralloc4.cpp @@ -27,11 +27,20 @@ #include #pragma clang diagnostic pop +using aidl::android::hardware::graphics::common::ExtendableType; +using aidl::android::hardware::graphics::common::PlaneLayoutComponentType; +using aidl::android::hardware::graphics::common::StandardMetadataType; +using android::hardware::hidl_vec; using android::hardware::graphics::allocator::V4_0::IAllocator; using android::hardware::graphics::common::V1_2::BufferUsage; using android::hardware::graphics::mapper::V4_0::BufferDescriptor; using android::hardware::graphics::mapper::V4_0::Error; using android::hardware::graphics::mapper::V4_0::IMapper; +using BufferDump = android::hardware::graphics::mapper::V4_0::IMapper::BufferDump; +using MetadataDump = android::hardware::graphics::mapper::V4_0::IMapper::MetadataDump; +using MetadataType = android::hardware::graphics::mapper::V4_0::IMapper::MetadataType; +using MetadataTypeDescription = + android::hardware::graphics::mapper::V4_0::IMapper::MetadataTypeDescription; namespace android { @@ -59,10 +68,10 @@ static inline IMapper::Rect sGralloc4Rect(const Rect& rect) { outRect.height = rect.height(); return outRect; } -static inline void sBufferDescriptorInfo(uint32_t width, uint32_t height, - android::PixelFormat format, uint32_t layerCount, - uint64_t usage, +static inline void sBufferDescriptorInfo(std::string name, uint32_t width, uint32_t height, + PixelFormat format, uint32_t layerCount, uint64_t usage, IMapper::BufferDescriptorInfo* outDescriptorInfo) { + outDescriptorInfo->name = name; outDescriptorInfo->width = width; outDescriptorInfo->height = height; outDescriptorInfo->layerCount = layerCount; @@ -151,11 +160,12 @@ void Gralloc4Mapper::freeBuffer(buffer_handle_t bufferHandle) const { } status_t Gralloc4Mapper::validateBufferSize(buffer_handle_t bufferHandle, uint32_t width, - uint32_t height, android::PixelFormat format, + uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage, uint32_t stride) const { IMapper::BufferDescriptorInfo descriptorInfo; - sBufferDescriptorInfo(width, height, format, layerCount, usage, &descriptorInfo); + sBufferDescriptorInfo("validateBufferSize", width, height, format, layerCount, usage, + &descriptorInfo); auto buffer = const_cast(bufferHandle); auto ret = mMapper->validateBufferSize(buffer, descriptorInfo, stride); @@ -189,14 +199,36 @@ void Gralloc4Mapper::getTransportSize(buffer_handle_t bufferHandle, uint32_t* ou status_t Gralloc4Mapper::lock(buffer_handle_t bufferHandle, uint64_t usage, const Rect& bounds, int acquireFence, void** outData, int32_t* outBytesPerPixel, int32_t* outBytesPerStride) const { - // In Gralloc 4 we can get this info per plane. Clients should check per plane. - if (outBytesPerPixel) { - // TODO add support to check per plane - *outBytesPerPixel = -1; - } - if (outBytesPerStride) { - // TODO add support to check per plane - *outBytesPerStride = -1; + std::vector planeLayouts; + status_t err = getPlaneLayouts(bufferHandle, &planeLayouts); + + if (err != NO_ERROR && !planeLayouts.empty()) { + if (outBytesPerPixel) { + int32_t bitsPerPixel = planeLayouts.front().sampleIncrementInBits; + for (const auto& planeLayout : planeLayouts) { + if (bitsPerPixel != planeLayout.sampleIncrementInBits) { + bitsPerPixel = -1; + } + } + if (bitsPerPixel >= 0 && bitsPerPixel % 8 == 0) { + *outBytesPerPixel = bitsPerPixel / 8; + } else { + *outBytesPerPixel = -1; + } + } + if (outBytesPerStride) { + int32_t bytesPerStride = planeLayouts.front().strideInBytes; + for (const auto& planeLayout : planeLayouts) { + if (bytesPerStride != planeLayout.strideInBytes) { + bytesPerStride = -1; + } + } + if (bytesPerStride >= 0) { + *outBytesPerStride = bytesPerStride; + } else { + *outBytesPerStride = -1; + } + } } auto buffer = const_cast(bufferHandle); @@ -234,10 +266,104 @@ status_t Gralloc4Mapper::lock(buffer_handle_t bufferHandle, uint64_t usage, cons return static_cast(error); } -status_t Gralloc4Mapper::lock(buffer_handle_t /*bufferHandle*/, uint64_t /*usage*/, - const Rect& /*bounds*/, int /*acquireFence*/, - android_ycbcr* /*ycbcr*/) const { - // TODO add lockYCbCr support +status_t Gralloc4Mapper::lock(buffer_handle_t bufferHandle, uint64_t usage, const Rect& bounds, + int acquireFence, android_ycbcr* outYcbcr) const { + if (!outYcbcr) { + return BAD_VALUE; + } + + std::vector planeLayouts; + status_t error = getPlaneLayouts(bufferHandle, &planeLayouts); + if (error != NO_ERROR) { + return error; + } + + void* data = nullptr; + error = lock(bufferHandle, usage, bounds, acquireFence, &data, nullptr, nullptr); + if (error != NO_ERROR) { + return error; + } + + android_ycbcr ycbcr; + + ycbcr.y = nullptr; + ycbcr.cb = nullptr; + ycbcr.cr = nullptr; + ycbcr.ystride = 0; + ycbcr.cstride = 0; + ycbcr.chroma_step = 0; + + for (const auto& planeLayout : planeLayouts) { + for (const auto& planeLayoutComponent : planeLayout.components) { + if (!gralloc4::isStandardPlaneLayoutComponentType(planeLayoutComponent.type)) { + continue; + } + if (0 != planeLayoutComponent.offsetInBits % 8) { + unlock(bufferHandle); + return BAD_VALUE; + } + + uint8_t* tmpData = static_cast(data) + planeLayout.offsetInBytes + + (planeLayoutComponent.offsetInBits / 8); + uint64_t sampleIncrementInBytes; + + auto type = static_cast(planeLayoutComponent.type.value); + switch (type) { + case PlaneLayoutComponentType::Y: + if ((ycbcr.y != nullptr) || (planeLayoutComponent.sizeInBits != 8) || + (planeLayout.sampleIncrementInBits != 8)) { + 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)) { + unlock(bufferHandle); + return BAD_VALUE; + } + + if (ycbcr.cstride == 0 && ycbcr.chroma_step == 0) { + ycbcr.cstride = planeLayout.strideInBytes; + ycbcr.chroma_step = sampleIncrementInBytes; + } else { + if ((static_cast(ycbcr.cstride) != planeLayout.strideInBytes) || + (ycbcr.chroma_step != sampleIncrementInBytes)) { + unlock(bufferHandle); + return BAD_VALUE; + } + } + + if (type == PlaneLayoutComponentType::CB) { + if (ycbcr.cb != nullptr) { + unlock(bufferHandle); + return BAD_VALUE; + } + ycbcr.cb = tmpData; + } else { + if (ycbcr.cr != nullptr) { + unlock(bufferHandle); + return BAD_VALUE; + } + ycbcr.cr = tmpData; + } + break; + default: + break; + }; + } + } + + *outYcbcr = ycbcr; return static_cast(Error::UNSUPPORTED); } @@ -275,11 +401,11 @@ int Gralloc4Mapper::unlock(buffer_handle_t bufferHandle) const { return releaseFence; } -status_t Gralloc4Mapper::isSupported(uint32_t width, uint32_t height, android::PixelFormat format, +status_t Gralloc4Mapper::isSupported(uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage, bool* outSupported) const { IMapper::BufferDescriptorInfo descriptorInfo; - sBufferDescriptorInfo(width, height, format, layerCount, usage, &descriptorInfo); + sBufferDescriptorInfo("isSupported", width, height, format, layerCount, usage, &descriptorInfo); Error error; auto ret = mMapper->isSupported(descriptorInfo, @@ -305,6 +431,605 @@ status_t Gralloc4Mapper::isSupported(uint32_t width, uint32_t height, android::P return static_cast(error); } +template +status_t Gralloc4Mapper::get(buffer_handle_t bufferHandle, const MetadataType& metadataType, + DecodeFunction decodeFunction, T* outMetadata) const { + if (!outMetadata) { + return BAD_VALUE; + } + + hidl_vec vec; + Error error; + auto ret = mMapper->get(const_cast(bufferHandle), metadataType, + [&](const auto& tmpError, const hidl_vec& tmpVec) { + error = tmpError; + vec = tmpVec; + }); + + if (!ret.isOk()) { + error = kTransactionError; + } + + if (error != Error::NONE) { + ALOGE("get(%s, %" PRIu64 ", ...) failed with %d", metadataType.name.c_str(), + metadataType.value, error); + return static_cast(error); + } + + return decodeFunction(vec, outMetadata); +} + +status_t Gralloc4Mapper::getBufferId(buffer_handle_t bufferHandle, uint64_t* outBufferId) const { + return get(bufferHandle, gralloc4::MetadataType_BufferId, gralloc4::decodeBufferId, + outBufferId); +} + +status_t Gralloc4Mapper::getName(buffer_handle_t bufferHandle, std::string* outName) const { + return get(bufferHandle, gralloc4::MetadataType_Name, gralloc4::decodeName, outName); +} + +status_t Gralloc4Mapper::getWidth(buffer_handle_t bufferHandle, uint64_t* outWidth) const { + return get(bufferHandle, gralloc4::MetadataType_Width, gralloc4::decodeWidth, outWidth); +} + +status_t Gralloc4Mapper::getHeight(buffer_handle_t bufferHandle, uint64_t* outHeight) const { + return get(bufferHandle, gralloc4::MetadataType_Height, gralloc4::decodeHeight, outHeight); +} + +status_t Gralloc4Mapper::getLayerCount(buffer_handle_t bufferHandle, + uint64_t* outLayerCount) const { + return get(bufferHandle, gralloc4::MetadataType_LayerCount, gralloc4::decodeLayerCount, + outLayerCount); +} + +status_t Gralloc4Mapper::getPixelFormatRequested(buffer_handle_t bufferHandle, + ui::PixelFormat* outPixelFormatRequested) const { + return get(bufferHandle, gralloc4::MetadataType_PixelFormatRequested, + gralloc4::decodePixelFormatRequested, outPixelFormatRequested); +} + +status_t Gralloc4Mapper::getPixelFormatFourCC(buffer_handle_t bufferHandle, + uint32_t* outPixelFormatFourCC) const { + return get(bufferHandle, gralloc4::MetadataType_PixelFormatFourCC, + gralloc4::decodePixelFormatFourCC, outPixelFormatFourCC); +} + +status_t Gralloc4Mapper::getPixelFormatModifier(buffer_handle_t bufferHandle, + uint64_t* outPixelFormatModifier) const { + return get(bufferHandle, gralloc4::MetadataType_PixelFormatModifier, + gralloc4::decodePixelFormatModifier, outPixelFormatModifier); +} + +status_t Gralloc4Mapper::getUsage(buffer_handle_t bufferHandle, uint64_t* outUsage) const { + return get(bufferHandle, gralloc4::MetadataType_Usage, gralloc4::decodeUsage, outUsage); +} + +status_t Gralloc4Mapper::getAllocationSize(buffer_handle_t bufferHandle, + uint64_t* outAllocationSize) const { + return get(bufferHandle, gralloc4::MetadataType_AllocationSize, gralloc4::decodeAllocationSize, + outAllocationSize); +} + +status_t Gralloc4Mapper::getProtectedContent(buffer_handle_t bufferHandle, + uint64_t* outProtectedContent) const { + return get(bufferHandle, gralloc4::MetadataType_ProtectedContent, + gralloc4::decodeProtectedContent, outProtectedContent); +} + +status_t Gralloc4Mapper::getCompression(buffer_handle_t bufferHandle, + ExtendableType* outCompression) const { + return get(bufferHandle, gralloc4::MetadataType_Compression, gralloc4::decodeCompression, + outCompression); +} + +status_t Gralloc4Mapper::getCompression(buffer_handle_t bufferHandle, + ui::Compression* outCompression) const { + if (!outCompression) { + return BAD_VALUE; + } + ExtendableType compression; + status_t error = getCompression(bufferHandle, &compression); + if (error) { + return error; + } + if (!gralloc4::isStandardCompression(compression)) { + return BAD_TYPE; + } + *outCompression = gralloc4::getStandardCompressionValue(compression); + return NO_ERROR; +} + +status_t Gralloc4Mapper::getInterlaced(buffer_handle_t bufferHandle, + ExtendableType* outInterlaced) const { + return get(bufferHandle, gralloc4::MetadataType_Interlaced, gralloc4::decodeInterlaced, + outInterlaced); +} + +status_t Gralloc4Mapper::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 Gralloc4Mapper::getChromaSiting(buffer_handle_t bufferHandle, + ExtendableType* outChromaSiting) const { + return get(bufferHandle, gralloc4::MetadataType_ChromaSiting, gralloc4::decodeChromaSiting, + outChromaSiting); +} + +status_t Gralloc4Mapper::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 Gralloc4Mapper::getPlaneLayouts(buffer_handle_t bufferHandle, + std::vector* outPlaneLayouts) const { + return get(bufferHandle, gralloc4::MetadataType_PlaneLayouts, gralloc4::decodePlaneLayouts, + outPlaneLayouts); +} + +status_t Gralloc4Mapper::getDataspace(buffer_handle_t bufferHandle, + ui::Dataspace* outDataspace) const { + if (!outDataspace) { + return BAD_VALUE; + } + aidl::android::hardware::graphics::common::Dataspace dataspace; + status_t error = get(bufferHandle, gralloc4::MetadataType_Dataspace, gralloc4::decodeDataspace, + &dataspace); + if (error) { + return error; + } + + // Gralloc4 uses stable AIDL dataspace but the rest of the system still uses HIDL dataspace + *outDataspace = static_cast(dataspace); + return NO_ERROR; +} + +status_t Gralloc4Mapper::getBlendMode(buffer_handle_t bufferHandle, + ui::BlendMode* outBlendMode) const { + return get(bufferHandle, gralloc4::MetadataType_BlendMode, gralloc4::decodeBlendMode, + outBlendMode); +} + +template +status_t Gralloc4Mapper::getDefault(uint32_t width, uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + const MetadataType& metadataType, + DecodeFunction decodeFunction, T* outMetadata) const { + if (!outMetadata) { + return BAD_VALUE; + } + + IMapper::BufferDescriptorInfo descriptorInfo; + sBufferDescriptorInfo("getDefault", width, height, format, layerCount, usage, &descriptorInfo); + + hidl_vec vec; + Error error; + auto ret = mMapper->getFromBufferDescriptorInfo(descriptorInfo, metadataType, + [&](const auto& tmpError, + const hidl_vec& tmpVec) { + error = tmpError; + vec = tmpVec; + }); + + if (!ret.isOk()) { + error = kTransactionError; + } + + if (error != Error::NONE) { + ALOGE("getDefault(%s, %" PRIu64 ", ...) failed with %d", metadataType.name.c_str(), + metadataType.value, error); + return static_cast(error); + } + + return decodeFunction(vec, outMetadata); +} + +status_t Gralloc4Mapper::getDefaultPixelFormatFourCC(uint32_t width, uint32_t height, + PixelFormat format, uint32_t layerCount, + uint64_t usage, + uint32_t* outPixelFormatFourCC) const { + return getDefault(width, height, format, layerCount, usage, + gralloc4::MetadataType_PixelFormatFourCC, gralloc4::decodePixelFormatFourCC, + outPixelFormatFourCC); +} + +status_t Gralloc4Mapper::getDefaultPixelFormatModifier(uint32_t width, uint32_t height, + PixelFormat format, uint32_t layerCount, + uint64_t usage, + uint64_t* outPixelFormatModifier) const { + return getDefault(width, height, format, layerCount, usage, + gralloc4::MetadataType_PixelFormatModifier, + gralloc4::decodePixelFormatModifier, outPixelFormatModifier); +} + +status_t Gralloc4Mapper::getDefaultAllocationSize(uint32_t width, uint32_t height, + PixelFormat format, uint32_t layerCount, + uint64_t usage, + uint64_t* outAllocationSize) const { + return getDefault(width, height, format, layerCount, usage, + gralloc4::MetadataType_AllocationSize, gralloc4::decodeAllocationSize, + outAllocationSize); +} + +status_t Gralloc4Mapper::getDefaultProtectedContent(uint32_t width, uint32_t height, + PixelFormat format, uint32_t layerCount, + uint64_t usage, + uint64_t* outProtectedContent) const { + return getDefault(width, height, format, layerCount, usage, + gralloc4::MetadataType_ProtectedContent, gralloc4::decodeProtectedContent, + outProtectedContent); +} + +status_t Gralloc4Mapper::getDefaultCompression(uint32_t width, uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + ExtendableType* outCompression) const { + return getDefault(width, height, format, layerCount, usage, gralloc4::MetadataType_Compression, + gralloc4::decodeCompression, outCompression); +} + +status_t Gralloc4Mapper::getDefaultCompression(uint32_t width, uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + ui::Compression* outCompression) const { + if (!outCompression) { + return BAD_VALUE; + } + ExtendableType compression; + status_t error = getDefaultCompression(width, height, format, layerCount, usage, &compression); + if (error) { + return error; + } + if (!gralloc4::isStandardCompression(compression)) { + return BAD_TYPE; + } + *outCompression = gralloc4::getStandardCompressionValue(compression); + return NO_ERROR; +} + +status_t Gralloc4Mapper::getDefaultInterlaced(uint32_t width, uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + ExtendableType* outInterlaced) const { + return getDefault(width, height, format, layerCount, usage, gralloc4::MetadataType_Interlaced, + gralloc4::decodeInterlaced, outInterlaced); +} + +status_t Gralloc4Mapper::getDefaultInterlaced(uint32_t width, uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + ui::Interlaced* outInterlaced) const { + if (!outInterlaced) { + return BAD_VALUE; + } + ExtendableType interlaced; + status_t error = getDefaultInterlaced(width, height, format, layerCount, usage, &interlaced); + if (error) { + return error; + } + if (!gralloc4::isStandardInterlaced(interlaced)) { + return BAD_TYPE; + } + *outInterlaced = gralloc4::getStandardInterlacedValue(interlaced); + return NO_ERROR; +} + +status_t Gralloc4Mapper::getDefaultChromaSiting(uint32_t width, uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + ExtendableType* outChromaSiting) const { + return getDefault(width, height, format, layerCount, usage, gralloc4::MetadataType_ChromaSiting, + gralloc4::decodeChromaSiting, outChromaSiting); +} + +status_t Gralloc4Mapper::getDefaultChromaSiting(uint32_t width, uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + ui::ChromaSiting* outChromaSiting) const { + if (!outChromaSiting) { + return BAD_VALUE; + } + ExtendableType chromaSiting; + status_t error = + getDefaultChromaSiting(width, height, format, layerCount, usage, &chromaSiting); + if (error) { + return error; + } + if (!gralloc4::isStandardChromaSiting(chromaSiting)) { + return BAD_TYPE; + } + *outChromaSiting = gralloc4::getStandardChromaSitingValue(chromaSiting); + return NO_ERROR; +} + +status_t Gralloc4Mapper::getDefaultPlaneLayouts( + uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage, + std::vector* outPlaneLayouts) const { + return getDefault(width, height, format, layerCount, usage, gralloc4::MetadataType_PlaneLayouts, + gralloc4::decodePlaneLayouts, outPlaneLayouts); +} + +std::vector Gralloc4Mapper::listSupportedMetadataTypes() const { + hidl_vec descriptions; + Error error; + auto ret = mMapper->listSupportedMetadataTypes( + [&](const auto& tmpError, const auto& tmpDescriptions) { + error = tmpError; + descriptions = tmpDescriptions; + }); + + if (!ret.isOk()) { + error = kTransactionError; + } + + if (error != Error::NONE) { + ALOGE("listSupportedMetadataType() failed with %d", error); + return {}; + } + + return static_cast>(descriptions); +} + +template +status_t Gralloc4Mapper::metadataDumpHelper(const BufferDump& bufferDump, + StandardMetadataType metadataType, + DecodeFunction decodeFunction, T* outT) const { + const auto& metadataDump = bufferDump.metadataDump; + + auto itr = + std::find_if(metadataDump.begin(), metadataDump.end(), + [&](const MetadataDump& tmpMetadataDump) { + if (!gralloc4::isStandardMetadataType(tmpMetadataDump.metadataType)) { + return false; + } + return metadataType == + gralloc4::getStandardMetadataTypeValue( + tmpMetadataDump.metadataType); + }); + if (itr == metadataDump.end()) { + return BAD_VALUE; + } + + return decodeFunction(itr->metadata, outT); +} + +status_t Gralloc4Mapper::bufferDumpHelper(const BufferDump& bufferDump, std::ostringstream* outDump, + uint64_t* outAllocationSize, bool less) const { + uint64_t bufferId; + std::string name; + uint64_t width; + uint64_t height; + uint64_t layerCount; + ui::PixelFormat pixelFormatRequested; + uint32_t pixelFormatFourCC; + uint64_t pixelFormatModifier; + uint64_t usage; + uint64_t allocationSize; + uint64_t protectedContent; + ExtendableType compression; + ExtendableType interlaced; + ExtendableType chromaSiting; + std::vector planeLayouts; + + status_t error = metadataDumpHelper(bufferDump, StandardMetadataType::BUFFER_ID, + gralloc4::decodeBufferId, &bufferId); + if (error != NO_ERROR) { + return error; + } + error = metadataDumpHelper(bufferDump, StandardMetadataType::NAME, gralloc4::decodeName, &name); + if (error != NO_ERROR) { + return error; + } + error = metadataDumpHelper(bufferDump, StandardMetadataType::WIDTH, gralloc4::decodeWidth, + &width); + if (error != NO_ERROR) { + return error; + } + error = metadataDumpHelper(bufferDump, StandardMetadataType::HEIGHT, gralloc4::decodeHeight, + &height); + if (error != NO_ERROR) { + return error; + } + error = metadataDumpHelper(bufferDump, StandardMetadataType::LAYER_COUNT, + gralloc4::decodeLayerCount, &layerCount); + if (error != NO_ERROR) { + return error; + } + error = metadataDumpHelper(bufferDump, StandardMetadataType::PIXEL_FORMAT_REQUESTED, + gralloc4::decodePixelFormatRequested, &pixelFormatRequested); + if (error != NO_ERROR) { + return error; + } + error = metadataDumpHelper(bufferDump, StandardMetadataType::PIXEL_FORMAT_FOURCC, + gralloc4::decodePixelFormatFourCC, &pixelFormatFourCC); + if (error != NO_ERROR) { + return error; + } + error = metadataDumpHelper(bufferDump, StandardMetadataType::PIXEL_FORMAT_MODIFIER, + gralloc4::decodePixelFormatModifier, &pixelFormatModifier); + if (error != NO_ERROR) { + return error; + } + error = metadataDumpHelper(bufferDump, StandardMetadataType::USAGE, gralloc4::decodeUsage, + &usage); + if (error != NO_ERROR) { + return error; + } + error = metadataDumpHelper(bufferDump, StandardMetadataType::ALLOCATION_SIZE, + gralloc4::decodeAllocationSize, &allocationSize); + if (error != NO_ERROR) { + return error; + } + error = metadataDumpHelper(bufferDump, StandardMetadataType::PROTECTED_CONTENT, + gralloc4::decodeProtectedContent, &protectedContent); + if (error != NO_ERROR) { + return error; + } + error = metadataDumpHelper(bufferDump, StandardMetadataType::COMPRESSION, + gralloc4::decodeCompression, &compression); + if (error != NO_ERROR) { + return error; + } + error = metadataDumpHelper(bufferDump, StandardMetadataType::INTERLACED, + gralloc4::decodeInterlaced, &interlaced); + if (error != NO_ERROR) { + return error; + } + error = metadataDumpHelper(bufferDump, StandardMetadataType::CHROMA_SITING, + gralloc4::decodeChromaSiting, &chromaSiting); + if (error != NO_ERROR) { + return error; + } + error = metadataDumpHelper(bufferDump, StandardMetadataType::PLANE_LAYOUTS, + gralloc4::decodePlaneLayouts, &planeLayouts); + if (error != NO_ERROR) { + return error; + } + + if (outAllocationSize) { + *outAllocationSize = allocationSize; + } + double allocationSizeKiB = static_cast(allocationSize) / 1024; + + *outDump << "+ name:" << name << ", id:" << bufferId << ", size:" << allocationSizeKiB + << "KiB, w/h:" << width << "x" << height << ", usage: 0x" << std::hex << usage + << std::dec << ", req fmt:" << static_cast(pixelFormatRequested) + << ", fourcc/mod:" << pixelFormatFourCC << "/" << pixelFormatModifier + << ", compressed: "; + + if (less) { + bool isCompressed = !gralloc4::isStandardCompression(compression) || + (gralloc4::getStandardCompressionValue(compression) != ui::Compression::NONE); + *outDump << std::boolalpha << isCompressed << "\n"; + } else { + *outDump << gralloc4::getCompressionName(compression) << "\n"; + } + + bool firstPlane = true; + for (const auto& planeLayout : planeLayouts) { + if (firstPlane) { + firstPlane = false; + *outDump << "\tplanes: "; + } else { + *outDump << "\t "; + } + + for (size_t i = 0; i < planeLayout.components.size(); i++) { + const auto& planeLayoutComponent = planeLayout.components[i]; + *outDump << gralloc4::getPlaneLayoutComponentTypeName(planeLayoutComponent.type); + if (i < planeLayout.components.size() - 1) { + *outDump << "/"; + } else { + *outDump << ":\t"; + } + } + *outDump << " w/h:" << planeLayout.widthInSamples << "x" << planeLayout.heightInSamples + << ", stride:" << planeLayout.strideInBytes + << " bytes, size:" << planeLayout.totalSizeInBytes; + if (!less) { + *outDump << ", inc:" << planeLayout.sampleIncrementInBits + << " bits, subsampling w/h:" << planeLayout.horizontalSubsampling << "x" + << planeLayout.verticalSubsampling; + } + *outDump << "\n"; + } + + if (!less) { + *outDump << "\tlayer cnt: " << layerCount << ", protected content: " << protectedContent + << ", interlaced: " << gralloc4::getInterlacedName(interlaced) + << ", chroma siting:" << gralloc4::getChromaSitingName(chromaSiting) << "\n"; + } + + return NO_ERROR; +} + +std::string Gralloc4Mapper::dumpBuffer(buffer_handle_t bufferHandle, bool less) const { + auto buffer = const_cast(bufferHandle); + + BufferDump bufferDump; + Error error; + auto ret = mMapper->dumpBuffer(buffer, [&](const auto& tmpError, const auto& tmpBufferDump) { + error = tmpError; + bufferDump = tmpBufferDump; + }); + + if (!ret.isOk()) { + error = kTransactionError; + } + + if (error != Error::NONE) { + ALOGE("dumpBuffer() failed with %d", error); + return ""; + } + + std::ostringstream stream; + stream.precision(2); + + status_t err = bufferDumpHelper(bufferDump, &stream, nullptr, less); + if (err != NO_ERROR) { + ALOGE("bufferDumpHelper() failed with %d", err); + return ""; + } + + return stream.str(); +} + +std::string Gralloc4Mapper::dumpBuffers(bool less) const { + hidl_vec bufferDumps; + Error error; + auto ret = mMapper->dumpBuffers([&](const auto& tmpError, const auto& tmpBufferDump) { + error = tmpError; + bufferDumps = tmpBufferDump; + }); + + if (!ret.isOk()) { + error = kTransactionError; + } + + if (error != Error::NONE) { + ALOGE("dumpBuffer() failed with %d", error); + return ""; + } + + uint64_t totalAllocationSize = 0; + std::ostringstream stream; + stream.precision(2); + + stream << "Imported gralloc buffers:\n"; + + for (const auto& bufferDump : bufferDumps) { + uint64_t allocationSize = 0; + status_t err = bufferDumpHelper(bufferDump, &stream, &allocationSize, less); + if (err != NO_ERROR) { + ALOGE("bufferDumpHelper() failed with %d", err); + return ""; + } + totalAllocationSize += allocationSize; + } + + double totalAllocationSizeKiB = static_cast(totalAllocationSize) / 1024; + stream << "Total imported by gralloc: " << totalAllocationSizeKiB << "KiB\n"; + return stream.str(); +} + Gralloc4Allocator::Gralloc4Allocator(const Gralloc4Mapper& mapper) : mMapper(mapper) { mAllocator = IAllocator::getService(); if (mAllocator == nullptr) { @@ -317,20 +1042,16 @@ bool Gralloc4Allocator::isLoaded() const { return mAllocator != nullptr; } -std::string Gralloc4Allocator::dumpDebugInfo() const { - std::string debugInfo; - - mAllocator->dumpDebugInfo([&](const auto& tmpDebugInfo) { debugInfo = tmpDebugInfo.c_str(); }); - - return debugInfo; +std::string Gralloc4Allocator::dumpDebugInfo(bool less) const { + return mMapper.dumpBuffers(less); } -status_t Gralloc4Allocator::allocate(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 { +status_t Gralloc4Allocator::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 { IMapper::BufferDescriptorInfo descriptorInfo; - sBufferDescriptorInfo(width, height, format, layerCount, usage, &descriptorInfo); + sBufferDescriptorInfo(requestorName, width, height, format, layerCount, usage, &descriptorInfo); BufferDescriptor descriptor; status_t error = mMapper.createDescriptor(static_cast(&descriptorInfo), diff --git a/libs/ui/GraphicBufferAllocator.cpp b/libs/ui/GraphicBufferAllocator.cpp index 3a90a988dc..943d13ec68 100644 --- a/libs/ui/GraphicBufferAllocator.cpp +++ b/libs/ui/GraphicBufferAllocator.cpp @@ -78,11 +78,11 @@ uint64_t GraphicBufferAllocator::getTotalSize() const { return total; } -void GraphicBufferAllocator::dump(std::string& result) const { +void GraphicBufferAllocator::dump(std::string& result, bool less) const { Mutex::Autolock _l(sLock); KeyedVector& list(sAllocList); uint64_t total = 0; - result.append("Allocated buffers:\n"); + result.append("GraphicBufferAllocator buffers:\n"); const size_t c = list.size(); for (size_t i=0 ; i(total) / 1024.0); + StringAppendF(&result, "Total allocated by GraphicBufferAllocator (estimate): %.2f KB\n", + static_cast(total) / 1024.0); - result.append(mAllocator->dumpDebugInfo()); + result.append(mAllocator->dumpDebugInfo(less)); } -void GraphicBufferAllocator::dumpToSystemLog() -{ +void GraphicBufferAllocator::dumpToSystemLog(bool less) { std::string s; - GraphicBufferAllocator::getInstance().dump(s); + GraphicBufferAllocator::getInstance().dump(s, less); ALOGD("%s", s.c_str()); } @@ -137,8 +137,8 @@ status_t GraphicBufferAllocator::allocateHelper(uint32_t width, uint32_t height, // TODO(b/72323293, b/72703005): Remove these invalid bits from callers usage &= ~static_cast((1 << 10) | (1 << 13)); - status_t error = mAllocator->allocate(width, height, format, layerCount, usage, 1, stride, - handle, importBuffer); + status_t error = mAllocator->allocate(requestorName, width, height, format, layerCount, usage, + 1, stride, handle, importBuffer); if (error != NO_ERROR) { ALOGE("Failed to allocate (%u x %u) layerCount %u format %d " "usage %" PRIx64 ": %d", diff --git a/libs/ui/GraphicBufferMapper.cpp b/libs/ui/GraphicBufferMapper.cpp index 4d087d151c..8540fd304b 100644 --- a/libs/ui/GraphicBufferMapper.cpp +++ b/libs/ui/GraphicBufferMapper.cpp @@ -71,6 +71,17 @@ GraphicBufferMapper::GraphicBufferMapper() { LOG_ALWAYS_FATAL("gralloc-mapper is missing"); } +void GraphicBufferMapper::dumpBuffer(buffer_handle_t bufferHandle, std::string& result, + bool less) const { + result.append(mMapper->dumpBuffer(bufferHandle, less)); +} + +void GraphicBufferMapper::dumpBufferToSystemLog(buffer_handle_t bufferHandle, bool less) { + std::string s; + GraphicBufferMapper::getInstance().dumpBuffer(bufferHandle, s, less); + 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, @@ -177,5 +188,182 @@ status_t GraphicBufferMapper::isSupported(uint32_t width, uint32_t height, uint64_t usage, bool* outSupported) { return mMapper->isSupported(width, height, format, layerCount, usage, outSupported); } + +status_t GraphicBufferMapper::getBufferId(buffer_handle_t bufferHandle, uint64_t* outBufferId) { + return mMapper->getBufferId(bufferHandle, outBufferId); +} + +status_t GraphicBufferMapper::getName(buffer_handle_t bufferHandle, std::string* outName) { + return mMapper->getName(bufferHandle, outName); +} + +status_t GraphicBufferMapper::getWidth(buffer_handle_t bufferHandle, uint64_t* outWidth) { + return mMapper->getWidth(bufferHandle, outWidth); +} + +status_t GraphicBufferMapper::getHeight(buffer_handle_t bufferHandle, uint64_t* outHeight) { + return mMapper->getHeight(bufferHandle, outHeight); +} + +status_t GraphicBufferMapper::getLayerCount(buffer_handle_t bufferHandle, uint64_t* outLayerCount) { + return mMapper->getLayerCount(bufferHandle, outLayerCount); +} + +status_t GraphicBufferMapper::getPixelFormatRequested(buffer_handle_t bufferHandle, + ui::PixelFormat* outPixelFormatRequested) { + return mMapper->getPixelFormatRequested(bufferHandle, outPixelFormatRequested); +} + +status_t GraphicBufferMapper::getPixelFormatFourCC(buffer_handle_t bufferHandle, + uint32_t* outPixelFormatFourCC) { + return mMapper->getPixelFormatFourCC(bufferHandle, outPixelFormatFourCC); +} + +status_t GraphicBufferMapper::getPixelFormatModifier(buffer_handle_t bufferHandle, + uint64_t* outPixelFormatModifier) { + return mMapper->getPixelFormatModifier(bufferHandle, outPixelFormatModifier); +} + +status_t GraphicBufferMapper::getUsage(buffer_handle_t bufferHandle, uint64_t* outUsage) { + return mMapper->getUsage(bufferHandle, outUsage); +} + +status_t GraphicBufferMapper::getAllocationSize(buffer_handle_t bufferHandle, + uint64_t* outAllocationSize) { + return mMapper->getAllocationSize(bufferHandle, outAllocationSize); +} + +status_t GraphicBufferMapper::getProtectedContent(buffer_handle_t bufferHandle, + uint64_t* outProtectedContent) { + return mMapper->getProtectedContent(bufferHandle, outProtectedContent); +} + +status_t GraphicBufferMapper::getCompression( + buffer_handle_t bufferHandle, + aidl::android::hardware::graphics::common::ExtendableType* outCompression) { + return mMapper->getCompression(bufferHandle, outCompression); +} + +status_t GraphicBufferMapper::getCompression(buffer_handle_t bufferHandle, + ui::Compression* outCompression) { + return mMapper->getCompression(bufferHandle, outCompression); +} + +status_t GraphicBufferMapper::getInterlaced( + buffer_handle_t bufferHandle, + aidl::android::hardware::graphics::common::ExtendableType* outInterlaced) { + return mMapper->getInterlaced(bufferHandle, outInterlaced); +} + +status_t GraphicBufferMapper::getInterlaced(buffer_handle_t bufferHandle, + ui::Interlaced* outInterlaced) { + return mMapper->getInterlaced(bufferHandle, outInterlaced); +} + +status_t GraphicBufferMapper::getChromaSiting( + buffer_handle_t bufferHandle, + aidl::android::hardware::graphics::common::ExtendableType* outChromaSiting) { + return mMapper->getChromaSiting(bufferHandle, outChromaSiting); +} + +status_t GraphicBufferMapper::getChromaSiting(buffer_handle_t bufferHandle, + ui::ChromaSiting* outChromaSiting) { + return mMapper->getChromaSiting(bufferHandle, outChromaSiting); +} + +status_t GraphicBufferMapper::getPlaneLayouts(buffer_handle_t bufferHandle, + std::vector* outPlaneLayouts) { + return mMapper->getPlaneLayouts(bufferHandle, outPlaneLayouts); +} + +status_t GraphicBufferMapper::getDataspace(buffer_handle_t bufferHandle, + ui::Dataspace* outDataspace) { + return mMapper->getDataspace(bufferHandle, outDataspace); +} + +status_t GraphicBufferMapper::getBlendMode(buffer_handle_t bufferHandle, + ui::BlendMode* outBlendMode) { + return mMapper->getBlendMode(bufferHandle, outBlendMode); +} + +status_t GraphicBufferMapper::getDefaultPixelFormatFourCC(uint32_t width, uint32_t height, + PixelFormat format, uint32_t layerCount, + uint64_t usage, + uint32_t* outPixelFormatFourCC) { + return mMapper->getDefaultPixelFormatFourCC(width, height, format, layerCount, usage, + outPixelFormatFourCC); +} + +status_t GraphicBufferMapper::getDefaultPixelFormatModifier(uint32_t width, uint32_t height, + PixelFormat format, uint32_t layerCount, + uint64_t usage, + uint64_t* outPixelFormatModifier) { + return mMapper->getDefaultPixelFormatModifier(width, height, format, layerCount, usage, + outPixelFormatModifier); +} + +status_t GraphicBufferMapper::getDefaultAllocationSize(uint32_t width, uint32_t height, + PixelFormat format, uint32_t layerCount, + uint64_t usage, + uint64_t* outAllocationSize) { + return mMapper->getDefaultAllocationSize(width, height, format, layerCount, usage, + outAllocationSize); +} + +status_t GraphicBufferMapper::getDefaultProtectedContent(uint32_t width, uint32_t height, + PixelFormat format, uint32_t layerCount, + uint64_t usage, + uint64_t* outProtectedContent) { + return mMapper->getDefaultProtectedContent(width, height, format, layerCount, usage, + outProtectedContent); +} + +status_t GraphicBufferMapper::getDefaultCompression( + uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage, + aidl::android::hardware::graphics::common::ExtendableType* outCompression) { + return mMapper->getDefaultCompression(width, height, format, layerCount, usage, outCompression); +} + +status_t GraphicBufferMapper::getDefaultCompression(uint32_t width, uint32_t height, + PixelFormat format, uint32_t layerCount, + uint64_t usage, + ui::Compression* outCompression) { + return mMapper->getDefaultCompression(width, height, format, layerCount, usage, outCompression); +} + +status_t GraphicBufferMapper::getDefaultInterlaced( + uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage, + aidl::android::hardware::graphics::common::ExtendableType* outInterlaced) { + return mMapper->getDefaultInterlaced(width, height, format, layerCount, usage, outInterlaced); +} + +status_t GraphicBufferMapper::getDefaultInterlaced(uint32_t width, uint32_t height, + PixelFormat format, uint32_t layerCount, + uint64_t usage, ui::Interlaced* outInterlaced) { + return mMapper->getDefaultInterlaced(width, height, format, layerCount, usage, outInterlaced); +} + +status_t GraphicBufferMapper::getDefaultChromaSiting( + uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage, + aidl::android::hardware::graphics::common::ExtendableType* outChromaSiting) { + return mMapper->getDefaultChromaSiting(width, height, format, layerCount, usage, + outChromaSiting); +} + +status_t GraphicBufferMapper::getDefaultChromaSiting(uint32_t width, uint32_t height, + PixelFormat format, uint32_t layerCount, + uint64_t usage, + ui::ChromaSiting* outChromaSiting) { + return mMapper->getDefaultChromaSiting(width, height, format, layerCount, usage, + outChromaSiting); +} + +status_t GraphicBufferMapper::getDefaultPlaneLayouts( + uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage, + std::vector* outPlaneLayouts) { + return mMapper->getDefaultPlaneLayouts(width, height, format, layerCount, usage, + outPlaneLayouts); +} + // --------------------------------------------------------------------------- }; // namespace android diff --git a/libs/ui/include/ui/Gralloc.h b/libs/ui/include/ui/Gralloc.h index c28f7a52a4..fcd959c2cc 100644 --- a/libs/ui/include/ui/Gralloc.h +++ b/libs/ui/include/ui/Gralloc.h @@ -17,13 +17,15 @@ #ifndef ANDROID_UI_GRALLOC_H #define ANDROID_UI_GRALLOC_H -#include - +#include #include +#include #include #include #include +#include + namespace android { // A wrapper to IMapper @@ -33,6 +35,10 @@ public: virtual bool isLoaded() const = 0; + virtual std::string dumpBuffer(buffer_handle_t /*bufferHandle*/, bool /*less*/) const { + return ""; + } + virtual status_t createDescriptor(void* bufferDescriptorInfo, void* outBufferDescriptor) const = 0; @@ -74,8 +80,163 @@ public: // allocated if resources are available. If false, a buffer with the given specifications will // never successfully allocate on this device. Note that this function is not guaranteed to be // supported on all devices, in which case a status_t of INVALID_OPERATION will be returned. - virtual status_t isSupported(uint32_t width, uint32_t height, android::PixelFormat format, - uint32_t layerCount, uint64_t usage, bool* outSupported) const = 0; + virtual status_t isSupported(uint32_t /*width*/, uint32_t /*height*/, + android::PixelFormat /*format*/, uint32_t /*layerCount*/, + uint64_t /*usage*/, bool* /*outSupported*/) const { + return INVALID_OPERATION; + } + + virtual status_t getBufferId(buffer_handle_t /*bufferHandle*/, + uint64_t* /*outBufferId*/) const { + return INVALID_OPERATION; + } + virtual status_t getName(buffer_handle_t /*bufferHandle*/, std::string* /*outName*/) const { + return INVALID_OPERATION; + } + virtual status_t getWidth(buffer_handle_t /*bufferHandle*/, uint64_t* /*outWidth*/) const { + return INVALID_OPERATION; + } + virtual status_t getHeight(buffer_handle_t /*bufferHandle*/, uint64_t* /*outHeight*/) const { + return INVALID_OPERATION; + } + virtual status_t getLayerCount(buffer_handle_t /*bufferHandle*/, + uint64_t* /*outLayerCount*/) const { + return INVALID_OPERATION; + } + virtual status_t getPixelFormatRequested(buffer_handle_t /*bufferHandle*/, + ui::PixelFormat* /*outPixelFormatRequested*/) const { + return INVALID_OPERATION; + } + virtual status_t getPixelFormatFourCC(buffer_handle_t /*bufferHandle*/, + uint32_t* /*outPixelFormatFourCC*/) const { + return INVALID_OPERATION; + } + virtual status_t getPixelFormatModifier(buffer_handle_t /*bufferHandle*/, + uint64_t* /*outPixelFormatModifier*/) const { + return INVALID_OPERATION; + } + virtual status_t getUsage(buffer_handle_t /*bufferHandle*/, uint64_t* /*outUsage*/) const { + return INVALID_OPERATION; + } + virtual status_t getAllocationSize(buffer_handle_t /*bufferHandle*/, + uint64_t* /*outAllocationSize*/) const { + return INVALID_OPERATION; + } + virtual status_t getProtectedContent(buffer_handle_t /*bufferHandle*/, + uint64_t* /*outProtectedContent*/) const { + return INVALID_OPERATION; + } + virtual status_t getCompression( + buffer_handle_t /*bufferHandle*/, + aidl::android::hardware::graphics::common::ExtendableType* /*outCompression*/) const { + return INVALID_OPERATION; + } + virtual status_t getCompression(buffer_handle_t /*bufferHandle*/, + ui::Compression* /*outCompression*/) const { + return INVALID_OPERATION; + } + virtual status_t getInterlaced( + buffer_handle_t /*bufferHandle*/, + aidl::android::hardware::graphics::common::ExtendableType* /*outInterlaced*/) const { + return INVALID_OPERATION; + } + virtual status_t getInterlaced(buffer_handle_t /*bufferHandle*/, + ui::Interlaced* /*outInterlaced*/) const { + return INVALID_OPERATION; + } + virtual status_t getChromaSiting( + buffer_handle_t /*bufferHandle*/, + aidl::android::hardware::graphics::common::ExtendableType* /*outChromaSiting*/) const { + return INVALID_OPERATION; + } + virtual status_t getChromaSiting(buffer_handle_t /*bufferHandle*/, + ui::ChromaSiting* /*outChromaSiting*/) const { + return INVALID_OPERATION; + } + virtual status_t getPlaneLayouts(buffer_handle_t /*bufferHandle*/, + std::vector* /*outPlaneLayouts*/) const { + return INVALID_OPERATION; + } + virtual status_t getDataspace(buffer_handle_t /*bufferHandle*/, + ui::Dataspace* /*outDataspace*/) const { + return INVALID_OPERATION; + } + virtual status_t getBlendMode(buffer_handle_t /*bufferHandle*/, + ui::BlendMode* /*outBlendMode*/) const { + return INVALID_OPERATION; + } + + virtual status_t getDefaultPixelFormatFourCC(uint32_t /*width*/, uint32_t /*height*/, + PixelFormat /*format*/, uint32_t /*layerCount*/, + uint64_t /*usage*/, + uint32_t* /*outPixelFormatFourCC*/) const { + return INVALID_OPERATION; + } + virtual status_t getDefaultPixelFormatModifier(uint32_t /*width*/, uint32_t /*height*/, + PixelFormat /*format*/, uint32_t /*layerCount*/, + uint64_t /*usage*/, + uint64_t* /*outPixelFormatModifier*/) const { + return INVALID_OPERATION; + } + virtual status_t getDefaultAllocationSize(uint32_t /*width*/, uint32_t /*height*/, + PixelFormat /*format*/, uint32_t /*layerCount*/, + uint64_t /*usage*/, + uint64_t* /*outAllocationSize*/) const { + return INVALID_OPERATION; + } + virtual status_t getDefaultProtectedContent(uint32_t /*width*/, uint32_t /*height*/, + PixelFormat /*format*/, uint32_t /*layerCount*/, + uint64_t /*usage*/, + uint64_t* /*outProtectedContent*/) const { + return INVALID_OPERATION; + } + virtual status_t getDefaultCompression( + uint32_t /*width*/, uint32_t /*height*/, PixelFormat /*format*/, + uint32_t /*layerCount*/, uint64_t /*usage*/, + aidl::android::hardware::graphics::common::ExtendableType* /*outCompression*/) const { + return INVALID_OPERATION; + } + virtual status_t getDefaultCompression(uint32_t /*width*/, uint32_t /*height*/, + PixelFormat /*format*/, uint32_t /*layerCount*/, + uint64_t /*usage*/, + ui::Compression* /*outCompression*/) const { + return INVALID_OPERATION; + } + virtual status_t getDefaultInterlaced( + uint32_t /*width*/, uint32_t /*height*/, PixelFormat /*format*/, + uint32_t /*layerCount*/, uint64_t /*usage*/, + aidl::android::hardware::graphics::common::ExtendableType* /*outInterlaced*/) const { + return INVALID_OPERATION; + } + virtual status_t getDefaultInterlaced(uint32_t /*width*/, uint32_t /*height*/, + PixelFormat /*format*/, uint32_t /*layerCount*/, + uint64_t /*usage*/, + ui::Interlaced* /*outInterlaced*/) const { + return INVALID_OPERATION; + } + virtual status_t getDefaultChromaSiting( + uint32_t /*width*/, uint32_t /*height*/, PixelFormat /*format*/, + uint32_t /*layerCount*/, uint64_t /*usage*/, + aidl::android::hardware::graphics::common::ExtendableType* /*outChromaSiting*/) const { + return INVALID_OPERATION; + } + virtual status_t getDefaultChromaSiting(uint32_t /*width*/, uint32_t /*height*/, + PixelFormat /*format*/, uint32_t /*layerCount*/, + uint64_t /*usage*/, + ui::ChromaSiting* /*outChromaSiting*/) const { + return INVALID_OPERATION; + } + virtual status_t getDefaultPlaneLayouts( + uint32_t /*width*/, uint32_t /*height*/, PixelFormat /*format*/, + uint32_t /*layerCount*/, uint64_t /*usage*/, + std::vector* /*outPlaneLayouts*/) const { + return INVALID_OPERATION; + } + + virtual std::vector + listSupportedMetadataTypes() const { + return {}; + } }; // A wrapper to IAllocator @@ -85,16 +246,17 @@ public: virtual bool isLoaded() const = 0; - virtual std::string dumpDebugInfo() const = 0; + virtual std::string dumpDebugInfo(bool less = true) const = 0; /* * The returned buffers are already imported and must not be imported * again. outBufferHandles must point to a space that can contain at * least "bufferCount" buffer_handle_t. */ - virtual status_t allocate(uint32_t width, uint32_t height, PixelFormat format, - uint32_t layerCount, uint64_t usage, uint32_t bufferCount, - uint32_t* outStride, buffer_handle_t* outBufferHandles, + virtual 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 = true) const = 0; }; diff --git a/libs/ui/include/ui/Gralloc2.h b/libs/ui/include/ui/Gralloc2.h index 12c772a737..f570c428b6 100644 --- a/libs/ui/include/ui/Gralloc2.h +++ b/libs/ui/include/ui/Gralloc2.h @@ -61,9 +61,6 @@ public: int unlock(buffer_handle_t bufferHandle) const override; - status_t isSupported(uint32_t width, uint32_t height, android::PixelFormat format, - uint32_t layerCount, uint64_t usage, bool* outSupported) const override; - private: // Determines whether the passed info is compatible with the mapper. status_t validateBufferDescriptorInfo( @@ -81,11 +78,12 @@ public: bool isLoaded() const override; - std::string dumpDebugInfo() const override; + std::string dumpDebugInfo(bool less = true) const override; - status_t allocate(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 = true) const override; + 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 = true) const override; private: const Gralloc2Mapper& mMapper; diff --git a/libs/ui/include/ui/Gralloc3.h b/libs/ui/include/ui/Gralloc3.h index bfbc2aa8fe..93a5077313 100644 --- a/libs/ui/include/ui/Gralloc3.h +++ b/libs/ui/include/ui/Gralloc3.h @@ -79,11 +79,12 @@ public: bool isLoaded() const override; - std::string dumpDebugInfo() const override; + std::string dumpDebugInfo(bool less = true) const override; - status_t allocate(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 = true) const override; + 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 = true) const override; private: const Gralloc3Mapper& mMapper; diff --git a/libs/ui/include/ui/Gralloc4.h b/libs/ui/include/ui/Gralloc4.h index 60115f9f1e..af7c076221 100644 --- a/libs/ui/include/ui/Gralloc4.h +++ b/libs/ui/include/ui/Gralloc4.h @@ -17,16 +17,17 @@ #ifndef ANDROID_UI_GRALLOC4_H #define ANDROID_UI_GRALLOC4_H -#include - #include #include #include +#include #include -#include +#include #include #include +#include + namespace android { class Gralloc4Mapper : public GrallocMapper { @@ -37,6 +38,9 @@ public: bool isLoaded() const override; + 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 importBuffer(const hardware::hidl_handle& rawHandle, @@ -45,7 +49,7 @@ public: void freeBuffer(buffer_handle_t bufferHandle) const override; status_t validateBufferSize(buffer_handle_t bufferHandle, uint32_t width, uint32_t height, - android::PixelFormat format, uint32_t layerCount, uint64_t usage, + PixelFormat format, uint32_t layerCount, uint64_t usage, uint32_t stride) const override; void getTransportSize(buffer_handle_t bufferHandle, uint32_t* outNumFds, @@ -60,14 +64,117 @@ public: int unlock(buffer_handle_t bufferHandle) const override; - status_t isSupported(uint32_t width, uint32_t height, android::PixelFormat format, - uint32_t layerCount, uint64_t usage, bool* outSupported) const override; + status_t isSupported(uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, + uint64_t usage, bool* outSupported) const override; + + status_t getBufferId(buffer_handle_t bufferHandle, uint64_t* outBufferId) const override; + status_t getName(buffer_handle_t bufferHandle, std::string* outName) const override; + status_t getWidth(buffer_handle_t bufferHandle, uint64_t* outWidth) const override; + status_t getHeight(buffer_handle_t bufferHandle, uint64_t* outHeight) const override; + status_t getLayerCount(buffer_handle_t bufferHandle, uint64_t* outLayerCount) const override; + status_t getPixelFormatRequested(buffer_handle_t bufferHandle, + ui::PixelFormat* outPixelFormatRequested) const override; + status_t getPixelFormatFourCC(buffer_handle_t bufferHandle, + uint32_t* outPixelFormatFourCC) const override; + status_t getPixelFormatModifier(buffer_handle_t bufferHandle, + uint64_t* outPixelFormatModifier) const override; + status_t getUsage(buffer_handle_t bufferHandle, uint64_t* outUsage) const override; + status_t getAllocationSize(buffer_handle_t bufferHandle, + uint64_t* outAllocationSize) const override; + status_t getProtectedContent(buffer_handle_t bufferHandle, + uint64_t* outProtectedContent) const override; + status_t getCompression(buffer_handle_t bufferHandle, + aidl::android::hardware::graphics::common::ExtendableType* + outCompression) const override; + status_t getCompression(buffer_handle_t bufferHandle, + ui::Compression* outCompression) const override; + status_t getInterlaced(buffer_handle_t bufferHandle, + aidl::android::hardware::graphics::common::ExtendableType* outInterlaced) + const override; + status_t getInterlaced(buffer_handle_t bufferHandle, + ui::Interlaced* outInterlaced) const override; + status_t getChromaSiting(buffer_handle_t bufferHandle, + aidl::android::hardware::graphics::common::ExtendableType* + outChromaSiting) const override; + status_t getChromaSiting(buffer_handle_t bufferHandle, + ui::ChromaSiting* outChromaSiting) const override; + status_t getPlaneLayouts(buffer_handle_t bufferHandle, + std::vector* outPlaneLayouts) const override; + status_t getDataspace(buffer_handle_t bufferHandle, ui::Dataspace* outDataspace) const override; + status_t getBlendMode(buffer_handle_t bufferHandle, ui::BlendMode* outBlendMode) const override; + + status_t getDefaultPixelFormatFourCC(uint32_t width, uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + uint32_t* outPixelFormatFourCC) const override; + status_t getDefaultPixelFormatModifier(uint32_t width, uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + uint64_t* outPixelFormatModifier) const override; + status_t getDefaultAllocationSize(uint32_t width, uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + uint64_t* outAllocationSize) const override; + status_t getDefaultProtectedContent(uint32_t width, uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + uint64_t* outProtectedContent) const override; + status_t getDefaultCompression(uint32_t width, uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + aidl::android::hardware::graphics::common::ExtendableType* + outCompression) const override; + status_t getDefaultCompression(uint32_t width, uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + ui::Compression* outCompression) const override; + status_t getDefaultInterlaced(uint32_t width, uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + aidl::android::hardware::graphics::common::ExtendableType* + outInterlaced) const override; + status_t getDefaultInterlaced(uint32_t width, uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + ui::Interlaced* outInterlaced) const override; + status_t getDefaultChromaSiting(uint32_t width, uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + aidl::android::hardware::graphics::common::ExtendableType* + outChromaSiting) const override; + status_t getDefaultChromaSiting(uint32_t width, uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + ui::ChromaSiting* outChromaSiting) const override; + status_t getDefaultPlaneLayouts(uint32_t width, uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + std::vector* outPlaneLayouts) const override; + + std::vector + listSupportedMetadataTypes() const; private: + friend class GraphicBufferAllocator; + // Determines whether the passed info is compatible with the mapper. status_t validateBufferDescriptorInfo( hardware::graphics::mapper::V4_0::IMapper::BufferDescriptorInfo* descriptorInfo) const; + template + using DecodeFunction = status_t (*)(const hardware::hidl_vec& input, T* output); + + template + status_t get( + buffer_handle_t bufferHandle, + const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType& metadataType, + DecodeFunction decodeFunction, T* outMetadata) const; + + template + status_t getDefault( + uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, + uint64_t usage, + const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType& metadataType, + DecodeFunction decodeFunction, T* outMetadata) const; + + template + status_t metadataDumpHelper( + const android::hardware::graphics::mapper::V4_0::IMapper::BufferDump& bufferDump, + aidl::android::hardware::graphics::common::StandardMetadataType metadataType, + DecodeFunction decodeFunction, T* outT) const; + status_t bufferDumpHelper( + const android::hardware::graphics::mapper::V4_0::IMapper::BufferDump& bufferDump, + std::ostringstream* outDump, uint64_t* outAllocationSize, bool less) const; + sp mMapper; }; @@ -79,11 +186,12 @@ public: bool isLoaded() const override; - std::string dumpDebugInfo() const override; + std::string dumpDebugInfo(bool less = true) const override; - status_t allocate(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 = true) const override; + 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 = true) const override; private: const Gralloc4Mapper& mMapper; diff --git a/libs/ui/include/ui/GraphicBufferAllocator.h b/libs/ui/include/ui/GraphicBufferAllocator.h index a182104856..3ed988c4c2 100644 --- a/libs/ui/include/ui/GraphicBufferAllocator.h +++ b/libs/ui/include/ui/GraphicBufferAllocator.h @@ -1,19 +1,19 @@ /* -** -** Copyright 2009, 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. -*/ + * + * Copyright 2009, 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. + */ #ifndef ANDROID_BUFFER_ALLOCATOR_H #define ANDROID_BUFFER_ALLOCATOR_H @@ -74,8 +74,8 @@ public: uint64_t getTotalSize() const; - void dump(std::string& res) const; - static void dumpToSystemLog(); + void dump(std::string& res, bool less = true) const; + static void dumpToSystemLog(bool less = true); protected: struct alloc_rec_t { diff --git a/libs/ui/include/ui/GraphicBufferMapper.h b/libs/ui/include/ui/GraphicBufferMapper.h index 83fb1447e6..77c00ae8e9 100644 --- a/libs/ui/include/ui/GraphicBufferMapper.h +++ b/libs/ui/include/ui/GraphicBufferMapper.h @@ -22,11 +22,11 @@ #include +#include #include #include #include - // Needed by code that still uses the GRALLOC_USAGE_* constants. // when/if we get rid of gralloc, we should provide aliases or fix call sites. #include @@ -49,6 +49,9 @@ public: static void preloadHal(); static inline GraphicBufferMapper& get() { return getInstance(); } + void dumpBuffer(buffer_handle_t bufferHandle, std::string& result, bool less = true) const; + static void dumpBufferToSystemLog(buffer_handle_t bufferHandle, bool less = true); + // 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, @@ -86,6 +89,82 @@ public: status_t isSupported(uint32_t width, uint32_t height, android::PixelFormat format, uint32_t layerCount, uint64_t usage, bool* outSupported); + /** + * Gets the gralloc metadata associated with the buffer. + * + * These functions are supported by gralloc 4.0+. + */ + status_t getBufferId(buffer_handle_t bufferHandle, uint64_t* outBufferId); + status_t getName(buffer_handle_t bufferHandle, std::string* outName); + status_t getWidth(buffer_handle_t bufferHandle, uint64_t* outWidth); + status_t getHeight(buffer_handle_t bufferHandle, uint64_t* outHeight); + status_t getLayerCount(buffer_handle_t bufferHandle, uint64_t* outLayerCount); + status_t getPixelFormatRequested(buffer_handle_t bufferHandle, + ui::PixelFormat* outPixelFormatRequested); + status_t getPixelFormatFourCC(buffer_handle_t bufferHandle, uint32_t* outPixelFormatFourCC); + status_t getPixelFormatModifier(buffer_handle_t bufferHandle, uint64_t* outPixelFormatModifier); + status_t getUsage(buffer_handle_t bufferHandle, uint64_t* outUsage); + status_t getAllocationSize(buffer_handle_t bufferHandle, uint64_t* outAllocationSize); + status_t getProtectedContent(buffer_handle_t bufferHandle, uint64_t* outProtectedContent); + status_t getCompression( + buffer_handle_t bufferHandle, + aidl::android::hardware::graphics::common::ExtendableType* outCompression); + status_t getCompression(buffer_handle_t bufferHandle, ui::Compression* outCompression); + status_t getInterlaced( + buffer_handle_t bufferHandle, + aidl::android::hardware::graphics::common::ExtendableType* outInterlaced); + status_t getInterlaced(buffer_handle_t bufferHandle, ui::Interlaced* outInterlaced); + status_t getChromaSiting( + buffer_handle_t bufferHandle, + aidl::android::hardware::graphics::common::ExtendableType* outChromaSiting); + status_t getChromaSiting(buffer_handle_t bufferHandle, ui::ChromaSiting* outChromaSiting); + status_t getPlaneLayouts(buffer_handle_t bufferHandle, + std::vector* outPlaneLayouts); + status_t getDataspace(buffer_handle_t bufferHandle, ui::Dataspace* outDataspace); + status_t getBlendMode(buffer_handle_t bufferHandle, ui::BlendMode* outBlendMode); + + /** + * Gets the default metadata for a gralloc buffer allocated with the given parameters. + * + * These functions are supported by gralloc 4.0+. + */ + status_t getDefaultPixelFormatFourCC(uint32_t width, uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + uint32_t* outPixelFormatFourCC); + status_t getDefaultPixelFormatModifier(uint32_t width, uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + uint64_t* outPixelFormatModifier); + status_t getDefaultAllocationSize(uint32_t width, uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + uint64_t* outAllocationSize); + status_t getDefaultProtectedContent(uint32_t width, uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + uint64_t* outProtectedContent); + status_t getDefaultCompression( + uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, + uint64_t usage, + aidl::android::hardware::graphics::common::ExtendableType* outCompression); + status_t getDefaultCompression(uint32_t width, uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + ui::Compression* outCompression); + status_t getDefaultInterlaced( + uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, + uint64_t usage, + aidl::android::hardware::graphics::common::ExtendableType* outInterlaced); + status_t getDefaultInterlaced(uint32_t width, uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + ui::Interlaced* outInterlaced); + status_t getDefaultChromaSiting( + uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, + uint64_t usage, + aidl::android::hardware::graphics::common::ExtendableType* outChromaSiting); + status_t getDefaultChromaSiting(uint32_t width, uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + ui::ChromaSiting* outChromaSiting); + status_t getDefaultPlaneLayouts(uint32_t width, uint32_t height, PixelFormat format, + uint32_t layerCount, uint64_t usage, + std::vector* outPlaneLayouts); + const GrallocMapper& getGrallocMapper() const { return reinterpret_cast(*mMapper); } diff --git a/libs/ui/include/ui/GraphicTypes.h b/libs/ui/include/ui/GraphicTypes.h index d7411ea36a..ad5ee8043a 100644 --- a/libs/ui/include/ui/GraphicTypes.h +++ b/libs/ui/include/ui/GraphicTypes.h @@ -16,21 +16,47 @@ #pragma once +#include +#include +#include +#include +#include #include #include #include namespace android { -// android::ui::* in this header file will alias different types as -// the HIDL interface is updated. +/** + * android::ui::* in this header file will alias different types as + * the HIDL and stable AIDL interfaces are updated. + */ namespace ui { +/** + * The following HIDL types should be moved to their stable AIDL + * equivalents when composer moves to stable AIDL. + */ 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; +/** + * Stable AIDL types + */ +using aidl::android::hardware::graphics::common::BlendMode; +using aidl::android::hardware::graphics::common::PlaneLayout; + +/** + * The following stable AIDL types below have standard platform definitions + * that can be extended by vendors. The extensions are not defined here + * because they cannot be understood by the framework. + */ +using ChromaSiting = aidl::android::hardware::graphics::common::ChromaSiting; +using Compression = aidl::android::hardware::graphics::common::Compression; +using Interlaced = aidl::android::hardware::graphics::common::Interlaced; + } // namespace ui } // namespace android diff --git a/libs/ui/include_vndk/ui/Gralloc2.h b/libs/ui/include_vndk/ui/Gralloc2.h deleted file mode 120000 index 66098c4edb..0000000000 --- a/libs/ui/include_vndk/ui/Gralloc2.h +++ /dev/null @@ -1 +0,0 @@ -../../include/ui/Gralloc2.h \ No newline at end of file diff --git a/libs/ui/tests/Android.bp b/libs/ui/tests/Android.bp index d2ad242df2..ff55bc2303 100644 --- a/libs/ui/tests/Android.bp +++ b/libs/ui/tests/Android.bp @@ -38,8 +38,9 @@ cc_test { "libgmock", ], shared_libs: [ + "libhidlbase", "liblog", - "libui", + "libui", ], srcs: [ "GraphicBufferAllocator_test.cpp", diff --git a/libs/ui/tests/GraphicBufferAllocator_test.cpp b/libs/ui/tests/GraphicBufferAllocator_test.cpp index efca083e6e..f4c0afa71b 100644 --- a/libs/ui/tests/GraphicBufferAllocator_test.cpp +++ b/libs/ui/tests/GraphicBufferAllocator_test.cpp @@ -51,7 +51,7 @@ public: std::cout << "Setting expected stride to " << stride << std::endl; EXPECT_CALL(*(reinterpret_cast(mAllocator.get())), allocate) - .WillOnce(DoAll(SetArgPointee<6>(stride), Return(err))); + .WillOnce(DoAll(SetArgPointee<7>(stride), Return(err))); } std::unique_ptr& getAllocator() { return mAllocator; } }; diff --git a/libs/ui/tests/mock/MockGrallocAllocator.h b/libs/ui/tests/mock/MockGrallocAllocator.h index 7660e9f66e..d62e3e2192 100644 --- a/libs/ui/tests/mock/MockGrallocAllocator.h +++ b/libs/ui/tests/mock/MockGrallocAllocator.h @@ -32,10 +32,10 @@ public: ~MockGrallocAllocator() override; MOCK_METHOD(bool, isLoaded, (), (const, override)); - MOCK_METHOD(std::string, dumpDebugInfo, (), (const, override)); + MOCK_METHOD(std::string, dumpDebugInfo, (bool less), (const, override)); MOCK_METHOD(status_t, allocate, - (uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, - uint64_t usage, uint32_t bufferCount, uint32_t* outStride, + (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 less), (const, override)); }; diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 9f4dd2bfc5..0a2890b5d2 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -2006,6 +2006,7 @@ void SurfaceFlinger::postComposition() // Even though ATRACE_INT64 already checks if tracing is enabled, it doesn't prevent the // side-effect of getTotalSize(), so we check that again here if (ATRACE_ENABLED()) { + // getTotalSize returns the total number of buffers that were allocated by SurfaceFlinger ATRACE_INT64("Total Buffer Size", GraphicBufferAllocator::get().getTotalSize()); } } -- cgit v1.2.3-59-g8ed1b From 317482c2e910aeab2eaac0bfe0d12d2843ecce8a Mon Sep 17 00:00:00 2001 From: Marissa Wall Date: Thu, 12 Dec 2019 14:26:59 -0800 Subject: gralloc: add gralloc4 HDR metadata support Add the ability to get and set HDR metadata. Bug: 141632767 Test: VtsHalGraphicsMapperV4_0TargetTest Change-Id: If6beca4b4280b3b94ef4fd295d530f067c7c3e59 --- libs/gralloc/types/Gralloc4.cpp | 193 ++++++++++++++++++++- libs/gralloc/types/fuzzer/gralloctypes.cpp | 3 + libs/gralloc/types/include/gralloctypes/Gralloc4.h | 46 ++++- libs/ui/Gralloc4.cpp | 18 ++ libs/ui/GraphicBufferMapper.cpp | 15 ++ libs/ui/include/ui/Gralloc.h | 13 ++ libs/ui/include/ui/Gralloc4.h | 6 + libs/ui/include/ui/GraphicBufferMapper.h | 4 + libs/ui/include/ui/GraphicTypes.h | 4 + 9 files changed, 295 insertions(+), 7 deletions(-) (limited to 'libs/ui/GraphicBufferMapper.cpp') diff --git a/libs/gralloc/types/Gralloc4.cpp b/libs/gralloc/types/Gralloc4.cpp index b762f1ebd3..d02e839b78 100644 --- a/libs/gralloc/types/Gralloc4.cpp +++ b/libs/gralloc/types/Gralloc4.cpp @@ -28,6 +28,7 @@ using android::hardware::hidl_vec; using aidl::android::hardware::graphics::common::BlendMode; using aidl::android::hardware::graphics::common::ChromaSiting; using aidl::android::hardware::graphics::common::Compression; +using aidl::android::hardware::graphics::common::Cta861_3; using aidl::android::hardware::graphics::common::Dataspace; using aidl::android::hardware::graphics::common::ExtendableType; using aidl::android::hardware::graphics::common::Interlaced; @@ -35,7 +36,9 @@ using aidl::android::hardware::graphics::common::PlaneLayout; using aidl::android::hardware::graphics::common::PlaneLayoutComponent; using aidl::android::hardware::graphics::common::PlaneLayoutComponentType; using aidl::android::hardware::graphics::common::Rect; +using aidl::android::hardware::graphics::common::Smpte2086; using aidl::android::hardware::graphics::common::StandardMetadataType; +using aidl::android::hardware::graphics::common::XyColor; using MetadataType = android::hardware::graphics::mapper::V4_0::IMapper::MetadataType; @@ -154,6 +157,13 @@ public: return mVec->size() > mOffset; } + size_t getRemainingSize() { + if (!mVec) { + return 0; + } + return mVec->size() - mOffset; + } + private: const hidl_vec* mVec; size_t mOffset = 0; @@ -218,6 +228,15 @@ status_t encode(const MetadataType& metadataType, const T& input, hidl_vec +status_t encodeOptional(const MetadataType& metadataType, const std::optional& input, + hidl_vec* output, EncodeHelper encodeHelper) { + if (!input) { + return NO_ERROR; + } + return encode(metadataType, *input, output, encodeHelper); +} + /** * decode is the main decode function. It takes in a hidl_vec and uses the decodeHelper function to * turn the hidl_vec byte stream into T. If an error occurs, the errorHandler function cleans up @@ -249,13 +268,32 @@ status_t decode(const MetadataType& metadataType, const hidl_vec& input return NO_ERROR; } +template +status_t decodeOptional(const MetadataType& metadataType, const hidl_vec& input, + std::optional* output, DecodeHelper decodeHelper) { + if (!output) { + return BAD_VALUE; + } + if (input.size() <= 0) { + output->reset(); + return NO_ERROR; + } + T tmp; + status_t err = decode(metadataType, input, &tmp, decodeHelper); + if (!err) { + *output = tmp; + } + return err; +} + /** * Private helper functions */ template status_t encodeInteger(const T& input, OutputHidlVec* output) { static_assert(std::is_same::value || std::is_same::value || - std::is_same::value || std::is_same::value); + std::is_same::value || std::is_same::value || + std::is_same::value || std::is_same::value); if (!output) { return BAD_VALUE; } @@ -267,7 +305,8 @@ status_t encodeInteger(const T& input, OutputHidlVec* output) { template status_t decodeInteger(InputHidlVec* input, T* output) { static_assert(std::is_same::value || std::is_same::value || - std::is_same::value || std::is_same::value); + std::is_same::value || std::is_same::value || + std::is_same::value || std::is_same::value); if (!output) { return BAD_VALUE; } @@ -306,6 +345,38 @@ status_t decodeString(InputHidlVec* input, std::string* output) { return input->decode(output, size); } +status_t encodeByteVector(const std::vector& input, OutputHidlVec* output) { + if (!output) { + return BAD_VALUE; + } + + status_t err = encodeInteger(input.size(), output); + if (err) { + return err; + } + + return output->encode(input.data(), input.size()); +} + +status_t decodeByteVector(InputHidlVec* input, std::vector* output) { + if (!output) { + return BAD_VALUE; + } + + int64_t size = 0; + status_t err = decodeInteger(input, &size); + if (err || size < 0) { + return err; + } + + if (size > input->getRemainingSize()) { + return BAD_VALUE; + } + output->resize(size); + + return input->decode(output->data(), size); +} + status_t encodeExtendableType(const ExtendableType& input, OutputHidlVec* output) { status_t err = encodeString(input.name, output); if (err) { @@ -391,6 +462,30 @@ status_t validateMetadataType(InputHidlVec* input, const MetadataType& expectedM return NO_ERROR; } +status_t encodeXyColor(const XyColor& input, OutputHidlVec* output) { + status_t err = encodeInteger(input.x, output); + if (err) { + return err; + } + return encodeInteger(input.y, output); +} + +status_t decodeXyColor(InputHidlVec* input, XyColor* output) { + status_t err = decodeInteger(input, &output->x); + if (err) { + return err; + } + return decodeInteger(input, &output->y); +} + +void clearXyColor(XyColor* output) { + if (!output) { + return; + } + output->x = 0; + output->y = 0; +} + status_t encodeRect(const Rect& input, OutputHidlVec* output) { status_t err = encodeInteger(static_cast(input.left), output); if (err) { @@ -635,6 +730,70 @@ void clearPlaneLayouts(std::vector* output) { output->clear(); } +status_t encodeSmpte2086Helper(const Smpte2086& smpte2086, OutputHidlVec* outOutputHidlVec) { + status_t err = encodeXyColor(smpte2086.primaryRed, outOutputHidlVec); + if (err) { + return err; + } + err = encodeXyColor(smpte2086.primaryGreen, outOutputHidlVec); + if (err) { + return err; + } + err = encodeXyColor(smpte2086.primaryBlue, outOutputHidlVec); + if (err) { + return err; + } + err = encodeXyColor(smpte2086.whitePoint, outOutputHidlVec); + if (err) { + return err; + } + err = encodeInteger(smpte2086.maxLuminance, outOutputHidlVec); + if (err) { + return err; + } + return encodeInteger(smpte2086.minLuminance, outOutputHidlVec); +} + +status_t decodeSmpte2086Helper(InputHidlVec* inputHidlVec, Smpte2086* outSmpte2086) { + status_t err = decodeXyColor(inputHidlVec, &outSmpte2086->primaryRed); + if (err) { + return err; + } + err = decodeXyColor(inputHidlVec, &outSmpte2086->primaryGreen); + if (err) { + return err; + } + err = decodeXyColor(inputHidlVec, &outSmpte2086->primaryBlue); + if (err) { + return err; + } + err = decodeXyColor(inputHidlVec, &outSmpte2086->whitePoint); + if (err) { + return err; + } + err = decodeInteger(inputHidlVec, &outSmpte2086->maxLuminance); + if (err) { + return err; + } + return decodeInteger(inputHidlVec, &outSmpte2086->minLuminance); +} + +status_t encodeCta861_3Helper(const Cta861_3& cta861_3, OutputHidlVec* outOutputHidlVec) { + status_t err = encodeInteger(cta861_3.maxContentLightLevel, outOutputHidlVec); + if (err) { + return err; + } + return encodeInteger(cta861_3.maxFrameAverageLightLevel, outOutputHidlVec); +} + +status_t decodeCta861_3Helper(InputHidlVec* inputHidlVec, Cta861_3* outCta861_3) { + status_t err = decodeInteger(inputHidlVec, &outCta861_3->maxContentLightLevel); + if (err) { + return err; + } + return decodeInteger(inputHidlVec, &outCta861_3->maxFrameAverageLightLevel); +} + /** * Public API functions */ @@ -798,6 +957,36 @@ status_t decodeBlendMode(const hidl_vec& blendMode, BlendMode* outBlend decodeInteger); } +status_t encodeSmpte2086(const std::optional& smpte2086, + hidl_vec* outSmpte2086) { + return encodeOptional(MetadataType_Smpte2086, smpte2086, outSmpte2086, encodeSmpte2086Helper); +} + +status_t decodeSmpte2086(const hidl_vec& smpte2086, + std::optional* outSmpte2086) { + return decodeOptional(MetadataType_Smpte2086, smpte2086, outSmpte2086, decodeSmpte2086Helper); +} + +status_t encodeCta861_3(const std::optional& cta861_3, hidl_vec* outCta861_3) { + return encodeOptional(MetadataType_Cta861_3, cta861_3, outCta861_3, encodeCta861_3Helper); +} + +status_t decodeCta861_3(const hidl_vec& cta861_3, std::optional* outCta861_3) { + return decodeOptional(MetadataType_Cta861_3, cta861_3, outCta861_3, decodeCta861_3Helper); +} + +status_t encodeSmpte2094_40(const std::optional>& smpte2094_40, + hidl_vec* outSmpte2094_40) { + return encodeOptional(MetadataType_Smpte2094_40, smpte2094_40, outSmpte2094_40, + encodeByteVector); +} + +status_t decodeSmpte2094_40(const hidl_vec& smpte2094_40, + std::optional>* outSmpte2094_40) { + return decodeOptional(MetadataType_Smpte2094_40, smpte2094_40, outSmpte2094_40, + decodeByteVector); +} + bool isStandardMetadataType(const MetadataType& metadataType) { return !std::strncmp(metadataType.name.c_str(), GRALLOC4_STANDARD_METADATA_TYPE, metadataType.name.size()); diff --git a/libs/gralloc/types/fuzzer/gralloctypes.cpp b/libs/gralloc/types/fuzzer/gralloctypes.cpp index 23c90b823d..da8cf97d4c 100644 --- a/libs/gralloc/types/fuzzer/gralloctypes.cpp +++ b/libs/gralloc/types/fuzzer/gralloctypes.cpp @@ -60,5 +60,8 @@ std::vector GRALLOCTYPES_DECODE_FUNCTIONS { GRALLOCTYPES_DECODE(std::vector, ::android::gralloc4::decodePlaneLayouts), GRALLOCTYPES_DECODE(aidl::android::hardware::graphics::common::Dataspace, ::android::gralloc4::decodeDataspace), GRALLOCTYPES_DECODE(aidl::android::hardware::graphics::common::BlendMode, ::android::gralloc4::decodeBlendMode), + GRALLOCTYPES_DECODE(std::optional, ::android::gralloc4::decodeSmpte2086), + GRALLOCTYPES_DECODE(std::optional, ::android::gralloc4::decodeCta861_3), + GRALLOCTYPES_DECODE(std::optional>, ::android::gralloc4::decodeSmpte2094_40), }; // clang-format on diff --git a/libs/gralloc/types/include/gralloctypes/Gralloc4.h b/libs/gralloc/types/include/gralloctypes/Gralloc4.h index a5d3bb2975..94de8f115f 100644 --- a/libs/gralloc/types/include/gralloctypes/Gralloc4.h +++ b/libs/gralloc/types/include/gralloctypes/Gralloc4.h @@ -17,16 +17,17 @@ #pragma once #include +#include +#include +#include #include #include #include #include -#include -#include -#include -#include #include - +#include +#include +#include #include namespace android { @@ -113,6 +114,22 @@ static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType Me GRALLOC4_STANDARD_METADATA_TYPE, static_cast(aidl::android::hardware::graphics::common::StandardMetadataType::BLEND_MODE) }; +static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType + MetadataType_Smpte2086 = {GRALLOC4_STANDARD_METADATA_TYPE, + static_cast(aidl::android::hardware::graphics::common:: + StandardMetadataType::SMPTE2086)}; + +static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType + MetadataType_Cta861_3 = {GRALLOC4_STANDARD_METADATA_TYPE, + static_cast(aidl::android::hardware::graphics::common:: + StandardMetadataType::CTA861_3)}; + +static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType + MetadataType_Smpte2094_40 = {GRALLOC4_STANDARD_METADATA_TYPE, + static_cast( + aidl::android::hardware::graphics::common:: + StandardMetadataType::SMPTE2094_40)}; + /*---------------------------------------------------------------------------------------------*/ /** @@ -272,6 +289,25 @@ status_t decodeDataspace(const android::hardware::hidl_vec& dataspace, status_t encodeBlendMode(const aidl::android::hardware::graphics::common::BlendMode& blendMode, android::hardware::hidl_vec* outBlendMode); status_t decodeBlendMode(const android::hardware::hidl_vec& blendMode, aidl::android::hardware::graphics::common::BlendMode* outBlendMode); +status_t encodeSmpte2086( + const std::optional& smpte2086, + android::hardware::hidl_vec* outSmpte2086); +status_t decodeSmpte2086( + const android::hardware::hidl_vec& smpte2086, + std::optional* outSmpte2086); + +status_t encodeCta861_3( + const std::optional& cta861_3, + android::hardware::hidl_vec* outCta861_3); +status_t decodeCta861_3( + const android::hardware::hidl_vec& cta861_3, + std::optional* outCta861_3); + +status_t encodeSmpte2094_40(const std::optional>& smpte2094_40, + android::hardware::hidl_vec* outSmpte2094_40); +status_t decodeSmpte2094_40(const android::hardware::hidl_vec& smpte2094_40, + std::optional>* outSmpte2094_40); + /** * The functions below can be used to parse extendable types. */ diff --git a/libs/ui/Gralloc4.cpp b/libs/ui/Gralloc4.cpp index 2c897cf4ff..30c48c8dc6 100644 --- a/libs/ui/Gralloc4.cpp +++ b/libs/ui/Gralloc4.cpp @@ -614,6 +614,24 @@ status_t Gralloc4Mapper::getBlendMode(buffer_handle_t bufferHandle, outBlendMode); } +status_t Gralloc4Mapper::getSmpte2086(buffer_handle_t bufferHandle, + std::optional* outSmpte2086) const { + return get(bufferHandle, gralloc4::MetadataType_Smpte2086, gralloc4::decodeSmpte2086, + outSmpte2086); +} + +status_t Gralloc4Mapper::getCta861_3(buffer_handle_t bufferHandle, + std::optional* outCta861_3) const { + return get(bufferHandle, gralloc4::MetadataType_Cta861_3, gralloc4::decodeCta861_3, + outCta861_3); +} + +status_t Gralloc4Mapper::getSmpte2094_40( + buffer_handle_t bufferHandle, std::optional>* outSmpte2094_40) const { + return get(bufferHandle, gralloc4::MetadataType_Smpte2094_40, gralloc4::decodeSmpte2094_40, + outSmpte2094_40); +} + template status_t Gralloc4Mapper::getDefault(uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage, diff --git a/libs/ui/GraphicBufferMapper.cpp b/libs/ui/GraphicBufferMapper.cpp index 8540fd304b..d20bd7a899 100644 --- a/libs/ui/GraphicBufferMapper.cpp +++ b/libs/ui/GraphicBufferMapper.cpp @@ -286,6 +286,21 @@ status_t GraphicBufferMapper::getBlendMode(buffer_handle_t bufferHandle, return mMapper->getBlendMode(bufferHandle, outBlendMode); } +status_t GraphicBufferMapper::getSmpte2086(buffer_handle_t bufferHandle, + std::optional* outSmpte2086) { + return mMapper->getSmpte2086(bufferHandle, outSmpte2086); +} + +status_t GraphicBufferMapper::getCta861_3(buffer_handle_t bufferHandle, + std::optional* outCta861_3) { + return mMapper->getCta861_3(bufferHandle, outCta861_3); +} + +status_t GraphicBufferMapper::getSmpte2094_40( + buffer_handle_t bufferHandle, std::optional>* outSmpte2094_40) { + return mMapper->getSmpte2094_40(bufferHandle, outSmpte2094_40); +} + status_t GraphicBufferMapper::getDefaultPixelFormatFourCC(uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage, diff --git a/libs/ui/include/ui/Gralloc.h b/libs/ui/include/ui/Gralloc.h index fcd959c2cc..e199648a8b 100644 --- a/libs/ui/include/ui/Gralloc.h +++ b/libs/ui/include/ui/Gralloc.h @@ -165,6 +165,19 @@ public: ui::BlendMode* /*outBlendMode*/) const { return INVALID_OPERATION; } + virtual status_t getSmpte2086(buffer_handle_t /*bufferHandle*/, + std::optional* /*outSmpte2086*/) const { + return INVALID_OPERATION; + } + virtual status_t getCta861_3(buffer_handle_t /*bufferHandle*/, + std::optional* /*outCta861_3*/) const { + return INVALID_OPERATION; + } + virtual status_t getSmpte2094_40( + buffer_handle_t /*bufferHandle*/, + std::optional>* /*outSmpte2094_40*/) const { + return INVALID_OPERATION; + } virtual status_t getDefaultPixelFormatFourCC(uint32_t /*width*/, uint32_t /*height*/, PixelFormat /*format*/, uint32_t /*layerCount*/, diff --git a/libs/ui/include/ui/Gralloc4.h b/libs/ui/include/ui/Gralloc4.h index af7c076221..4729cbaf67 100644 --- a/libs/ui/include/ui/Gralloc4.h +++ b/libs/ui/include/ui/Gralloc4.h @@ -102,6 +102,12 @@ public: std::vector* outPlaneLayouts) const override; status_t getDataspace(buffer_handle_t bufferHandle, ui::Dataspace* outDataspace) const override; status_t getBlendMode(buffer_handle_t bufferHandle, ui::BlendMode* outBlendMode) const override; + status_t getSmpte2086(buffer_handle_t bufferHandle, + std::optional* outSmpte2086) const override; + status_t getCta861_3(buffer_handle_t bufferHandle, + std::optional* outCta861_3) const override; + status_t getSmpte2094_40(buffer_handle_t bufferHandle, + std::optional>* outSmpte2094_40) const override; status_t getDefaultPixelFormatFourCC(uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage, diff --git a/libs/ui/include/ui/GraphicBufferMapper.h b/libs/ui/include/ui/GraphicBufferMapper.h index 77c00ae8e9..837e3d826b 100644 --- a/libs/ui/include/ui/GraphicBufferMapper.h +++ b/libs/ui/include/ui/GraphicBufferMapper.h @@ -122,6 +122,10 @@ public: std::vector* outPlaneLayouts); status_t getDataspace(buffer_handle_t bufferHandle, ui::Dataspace* outDataspace); status_t getBlendMode(buffer_handle_t bufferHandle, ui::BlendMode* outBlendMode); + status_t getSmpte2086(buffer_handle_t bufferHandle, std::optional* outSmpte2086); + status_t getCta861_3(buffer_handle_t bufferHandle, std::optional* outCta861_3); + status_t getSmpte2094_40(buffer_handle_t bufferHandle, + std::optional>* outSmpte2094_40); /** * Gets the default metadata for a gralloc buffer allocated with the given parameters. diff --git a/libs/ui/include/ui/GraphicTypes.h b/libs/ui/include/ui/GraphicTypes.h index ad5ee8043a..4bdacb0883 100644 --- a/libs/ui/include/ui/GraphicTypes.h +++ b/libs/ui/include/ui/GraphicTypes.h @@ -19,8 +19,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -47,7 +49,9 @@ using android::hardware::graphics::common::V1_2::PixelFormat; * Stable AIDL types */ using aidl::android::hardware::graphics::common::BlendMode; +using aidl::android::hardware::graphics::common::Cta861_3; using aidl::android::hardware::graphics::common::PlaneLayout; +using aidl::android::hardware::graphics::common::Smpte2086; /** * The following stable AIDL types below have standard platform definitions -- cgit v1.2.3-59-g8ed1b From 048552ff83a3e0751265a8bd1c82301babec67da Mon Sep 17 00:00:00 2001 From: Joseph Murphy Date: Tue, 17 Dec 2019 19:58:45 +0000 Subject: Revert submission Reason for revert: Buildcop - Build breaking references to std::optional Change-Id: Iad8f9de8ee5539cc9eaca35d7fad2e8d2e8c92dc --- libs/gralloc/types/Gralloc4.cpp | 193 +-------------------- libs/gralloc/types/fuzzer/gralloctypes.cpp | 3 - libs/gralloc/types/include/gralloctypes/Gralloc4.h | 46 +---- libs/ui/Gralloc4.cpp | 18 -- libs/ui/GraphicBufferMapper.cpp | 15 -- libs/ui/include/ui/Gralloc.h | 13 -- libs/ui/include/ui/Gralloc4.h | 6 - libs/ui/include/ui/GraphicBufferMapper.h | 4 - libs/ui/include/ui/GraphicTypes.h | 4 - 9 files changed, 7 insertions(+), 295 deletions(-) (limited to 'libs/ui/GraphicBufferMapper.cpp') diff --git a/libs/gralloc/types/Gralloc4.cpp b/libs/gralloc/types/Gralloc4.cpp index d02e839b78..b762f1ebd3 100644 --- a/libs/gralloc/types/Gralloc4.cpp +++ b/libs/gralloc/types/Gralloc4.cpp @@ -28,7 +28,6 @@ using android::hardware::hidl_vec; using aidl::android::hardware::graphics::common::BlendMode; using aidl::android::hardware::graphics::common::ChromaSiting; using aidl::android::hardware::graphics::common::Compression; -using aidl::android::hardware::graphics::common::Cta861_3; using aidl::android::hardware::graphics::common::Dataspace; using aidl::android::hardware::graphics::common::ExtendableType; using aidl::android::hardware::graphics::common::Interlaced; @@ -36,9 +35,7 @@ using aidl::android::hardware::graphics::common::PlaneLayout; using aidl::android::hardware::graphics::common::PlaneLayoutComponent; using aidl::android::hardware::graphics::common::PlaneLayoutComponentType; using aidl::android::hardware::graphics::common::Rect; -using aidl::android::hardware::graphics::common::Smpte2086; using aidl::android::hardware::graphics::common::StandardMetadataType; -using aidl::android::hardware::graphics::common::XyColor; using MetadataType = android::hardware::graphics::mapper::V4_0::IMapper::MetadataType; @@ -157,13 +154,6 @@ public: return mVec->size() > mOffset; } - size_t getRemainingSize() { - if (!mVec) { - return 0; - } - return mVec->size() - mOffset; - } - private: const hidl_vec* mVec; size_t mOffset = 0; @@ -228,15 +218,6 @@ status_t encode(const MetadataType& metadataType, const T& input, hidl_vec -status_t encodeOptional(const MetadataType& metadataType, const std::optional& input, - hidl_vec* output, EncodeHelper encodeHelper) { - if (!input) { - return NO_ERROR; - } - return encode(metadataType, *input, output, encodeHelper); -} - /** * decode is the main decode function. It takes in a hidl_vec and uses the decodeHelper function to * turn the hidl_vec byte stream into T. If an error occurs, the errorHandler function cleans up @@ -268,32 +249,13 @@ status_t decode(const MetadataType& metadataType, const hidl_vec& input return NO_ERROR; } -template -status_t decodeOptional(const MetadataType& metadataType, const hidl_vec& input, - std::optional* output, DecodeHelper decodeHelper) { - if (!output) { - return BAD_VALUE; - } - if (input.size() <= 0) { - output->reset(); - return NO_ERROR; - } - T tmp; - status_t err = decode(metadataType, input, &tmp, decodeHelper); - if (!err) { - *output = tmp; - } - return err; -} - /** * Private helper functions */ template status_t encodeInteger(const T& input, OutputHidlVec* output) { static_assert(std::is_same::value || std::is_same::value || - std::is_same::value || std::is_same::value || - std::is_same::value || std::is_same::value); + std::is_same::value || std::is_same::value); if (!output) { return BAD_VALUE; } @@ -305,8 +267,7 @@ status_t encodeInteger(const T& input, OutputHidlVec* output) { template status_t decodeInteger(InputHidlVec* input, T* output) { static_assert(std::is_same::value || std::is_same::value || - std::is_same::value || std::is_same::value || - std::is_same::value || std::is_same::value); + std::is_same::value || std::is_same::value); if (!output) { return BAD_VALUE; } @@ -345,38 +306,6 @@ status_t decodeString(InputHidlVec* input, std::string* output) { return input->decode(output, size); } -status_t encodeByteVector(const std::vector& input, OutputHidlVec* output) { - if (!output) { - return BAD_VALUE; - } - - status_t err = encodeInteger(input.size(), output); - if (err) { - return err; - } - - return output->encode(input.data(), input.size()); -} - -status_t decodeByteVector(InputHidlVec* input, std::vector* output) { - if (!output) { - return BAD_VALUE; - } - - int64_t size = 0; - status_t err = decodeInteger(input, &size); - if (err || size < 0) { - return err; - } - - if (size > input->getRemainingSize()) { - return BAD_VALUE; - } - output->resize(size); - - return input->decode(output->data(), size); -} - status_t encodeExtendableType(const ExtendableType& input, OutputHidlVec* output) { status_t err = encodeString(input.name, output); if (err) { @@ -462,30 +391,6 @@ status_t validateMetadataType(InputHidlVec* input, const MetadataType& expectedM return NO_ERROR; } -status_t encodeXyColor(const XyColor& input, OutputHidlVec* output) { - status_t err = encodeInteger(input.x, output); - if (err) { - return err; - } - return encodeInteger(input.y, output); -} - -status_t decodeXyColor(InputHidlVec* input, XyColor* output) { - status_t err = decodeInteger(input, &output->x); - if (err) { - return err; - } - return decodeInteger(input, &output->y); -} - -void clearXyColor(XyColor* output) { - if (!output) { - return; - } - output->x = 0; - output->y = 0; -} - status_t encodeRect(const Rect& input, OutputHidlVec* output) { status_t err = encodeInteger(static_cast(input.left), output); if (err) { @@ -730,70 +635,6 @@ void clearPlaneLayouts(std::vector* output) { output->clear(); } -status_t encodeSmpte2086Helper(const Smpte2086& smpte2086, OutputHidlVec* outOutputHidlVec) { - status_t err = encodeXyColor(smpte2086.primaryRed, outOutputHidlVec); - if (err) { - return err; - } - err = encodeXyColor(smpte2086.primaryGreen, outOutputHidlVec); - if (err) { - return err; - } - err = encodeXyColor(smpte2086.primaryBlue, outOutputHidlVec); - if (err) { - return err; - } - err = encodeXyColor(smpte2086.whitePoint, outOutputHidlVec); - if (err) { - return err; - } - err = encodeInteger(smpte2086.maxLuminance, outOutputHidlVec); - if (err) { - return err; - } - return encodeInteger(smpte2086.minLuminance, outOutputHidlVec); -} - -status_t decodeSmpte2086Helper(InputHidlVec* inputHidlVec, Smpte2086* outSmpte2086) { - status_t err = decodeXyColor(inputHidlVec, &outSmpte2086->primaryRed); - if (err) { - return err; - } - err = decodeXyColor(inputHidlVec, &outSmpte2086->primaryGreen); - if (err) { - return err; - } - err = decodeXyColor(inputHidlVec, &outSmpte2086->primaryBlue); - if (err) { - return err; - } - err = decodeXyColor(inputHidlVec, &outSmpte2086->whitePoint); - if (err) { - return err; - } - err = decodeInteger(inputHidlVec, &outSmpte2086->maxLuminance); - if (err) { - return err; - } - return decodeInteger(inputHidlVec, &outSmpte2086->minLuminance); -} - -status_t encodeCta861_3Helper(const Cta861_3& cta861_3, OutputHidlVec* outOutputHidlVec) { - status_t err = encodeInteger(cta861_3.maxContentLightLevel, outOutputHidlVec); - if (err) { - return err; - } - return encodeInteger(cta861_3.maxFrameAverageLightLevel, outOutputHidlVec); -} - -status_t decodeCta861_3Helper(InputHidlVec* inputHidlVec, Cta861_3* outCta861_3) { - status_t err = decodeInteger(inputHidlVec, &outCta861_3->maxContentLightLevel); - if (err) { - return err; - } - return decodeInteger(inputHidlVec, &outCta861_3->maxFrameAverageLightLevel); -} - /** * Public API functions */ @@ -957,36 +798,6 @@ status_t decodeBlendMode(const hidl_vec& blendMode, BlendMode* outBlend decodeInteger); } -status_t encodeSmpte2086(const std::optional& smpte2086, - hidl_vec* outSmpte2086) { - return encodeOptional(MetadataType_Smpte2086, smpte2086, outSmpte2086, encodeSmpte2086Helper); -} - -status_t decodeSmpte2086(const hidl_vec& smpte2086, - std::optional* outSmpte2086) { - return decodeOptional(MetadataType_Smpte2086, smpte2086, outSmpte2086, decodeSmpte2086Helper); -} - -status_t encodeCta861_3(const std::optional& cta861_3, hidl_vec* outCta861_3) { - return encodeOptional(MetadataType_Cta861_3, cta861_3, outCta861_3, encodeCta861_3Helper); -} - -status_t decodeCta861_3(const hidl_vec& cta861_3, std::optional* outCta861_3) { - return decodeOptional(MetadataType_Cta861_3, cta861_3, outCta861_3, decodeCta861_3Helper); -} - -status_t encodeSmpte2094_40(const std::optional>& smpte2094_40, - hidl_vec* outSmpte2094_40) { - return encodeOptional(MetadataType_Smpte2094_40, smpte2094_40, outSmpte2094_40, - encodeByteVector); -} - -status_t decodeSmpte2094_40(const hidl_vec& smpte2094_40, - std::optional>* outSmpte2094_40) { - return decodeOptional(MetadataType_Smpte2094_40, smpte2094_40, outSmpte2094_40, - decodeByteVector); -} - bool isStandardMetadataType(const MetadataType& metadataType) { return !std::strncmp(metadataType.name.c_str(), GRALLOC4_STANDARD_METADATA_TYPE, metadataType.name.size()); diff --git a/libs/gralloc/types/fuzzer/gralloctypes.cpp b/libs/gralloc/types/fuzzer/gralloctypes.cpp index da8cf97d4c..23c90b823d 100644 --- a/libs/gralloc/types/fuzzer/gralloctypes.cpp +++ b/libs/gralloc/types/fuzzer/gralloctypes.cpp @@ -60,8 +60,5 @@ std::vector GRALLOCTYPES_DECODE_FUNCTIONS { GRALLOCTYPES_DECODE(std::vector, ::android::gralloc4::decodePlaneLayouts), GRALLOCTYPES_DECODE(aidl::android::hardware::graphics::common::Dataspace, ::android::gralloc4::decodeDataspace), GRALLOCTYPES_DECODE(aidl::android::hardware::graphics::common::BlendMode, ::android::gralloc4::decodeBlendMode), - GRALLOCTYPES_DECODE(std::optional, ::android::gralloc4::decodeSmpte2086), - GRALLOCTYPES_DECODE(std::optional, ::android::gralloc4::decodeCta861_3), - GRALLOCTYPES_DECODE(std::optional>, ::android::gralloc4::decodeSmpte2094_40), }; // clang-format on diff --git a/libs/gralloc/types/include/gralloctypes/Gralloc4.h b/libs/gralloc/types/include/gralloctypes/Gralloc4.h index 94de8f115f..a5d3bb2975 100644 --- a/libs/gralloc/types/include/gralloctypes/Gralloc4.h +++ b/libs/gralloc/types/include/gralloctypes/Gralloc4.h @@ -17,17 +17,16 @@ #pragma once #include -#include -#include -#include #include #include #include #include -#include -#include +#include +#include +#include #include -#include +#include + #include namespace android { @@ -114,22 +113,6 @@ static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType Me GRALLOC4_STANDARD_METADATA_TYPE, static_cast(aidl::android::hardware::graphics::common::StandardMetadataType::BLEND_MODE) }; -static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType - MetadataType_Smpte2086 = {GRALLOC4_STANDARD_METADATA_TYPE, - static_cast(aidl::android::hardware::graphics::common:: - StandardMetadataType::SMPTE2086)}; - -static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType - MetadataType_Cta861_3 = {GRALLOC4_STANDARD_METADATA_TYPE, - static_cast(aidl::android::hardware::graphics::common:: - StandardMetadataType::CTA861_3)}; - -static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType - MetadataType_Smpte2094_40 = {GRALLOC4_STANDARD_METADATA_TYPE, - static_cast( - aidl::android::hardware::graphics::common:: - StandardMetadataType::SMPTE2094_40)}; - /*---------------------------------------------------------------------------------------------*/ /** @@ -289,25 +272,6 @@ status_t decodeDataspace(const android::hardware::hidl_vec& dataspace, status_t encodeBlendMode(const aidl::android::hardware::graphics::common::BlendMode& blendMode, android::hardware::hidl_vec* outBlendMode); status_t decodeBlendMode(const android::hardware::hidl_vec& blendMode, aidl::android::hardware::graphics::common::BlendMode* outBlendMode); -status_t encodeSmpte2086( - const std::optional& smpte2086, - android::hardware::hidl_vec* outSmpte2086); -status_t decodeSmpte2086( - const android::hardware::hidl_vec& smpte2086, - std::optional* outSmpte2086); - -status_t encodeCta861_3( - const std::optional& cta861_3, - android::hardware::hidl_vec* outCta861_3); -status_t decodeCta861_3( - const android::hardware::hidl_vec& cta861_3, - std::optional* outCta861_3); - -status_t encodeSmpte2094_40(const std::optional>& smpte2094_40, - android::hardware::hidl_vec* outSmpte2094_40); -status_t decodeSmpte2094_40(const android::hardware::hidl_vec& smpte2094_40, - std::optional>* outSmpte2094_40); - /** * The functions below can be used to parse extendable types. */ diff --git a/libs/ui/Gralloc4.cpp b/libs/ui/Gralloc4.cpp index 30c48c8dc6..2c897cf4ff 100644 --- a/libs/ui/Gralloc4.cpp +++ b/libs/ui/Gralloc4.cpp @@ -614,24 +614,6 @@ status_t Gralloc4Mapper::getBlendMode(buffer_handle_t bufferHandle, outBlendMode); } -status_t Gralloc4Mapper::getSmpte2086(buffer_handle_t bufferHandle, - std::optional* outSmpte2086) const { - return get(bufferHandle, gralloc4::MetadataType_Smpte2086, gralloc4::decodeSmpte2086, - outSmpte2086); -} - -status_t Gralloc4Mapper::getCta861_3(buffer_handle_t bufferHandle, - std::optional* outCta861_3) const { - return get(bufferHandle, gralloc4::MetadataType_Cta861_3, gralloc4::decodeCta861_3, - outCta861_3); -} - -status_t Gralloc4Mapper::getSmpte2094_40( - buffer_handle_t bufferHandle, std::optional>* outSmpte2094_40) const { - return get(bufferHandle, gralloc4::MetadataType_Smpte2094_40, gralloc4::decodeSmpte2094_40, - outSmpte2094_40); -} - template status_t Gralloc4Mapper::getDefault(uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage, diff --git a/libs/ui/GraphicBufferMapper.cpp b/libs/ui/GraphicBufferMapper.cpp index d20bd7a899..8540fd304b 100644 --- a/libs/ui/GraphicBufferMapper.cpp +++ b/libs/ui/GraphicBufferMapper.cpp @@ -286,21 +286,6 @@ status_t GraphicBufferMapper::getBlendMode(buffer_handle_t bufferHandle, return mMapper->getBlendMode(bufferHandle, outBlendMode); } -status_t GraphicBufferMapper::getSmpte2086(buffer_handle_t bufferHandle, - std::optional* outSmpte2086) { - return mMapper->getSmpte2086(bufferHandle, outSmpte2086); -} - -status_t GraphicBufferMapper::getCta861_3(buffer_handle_t bufferHandle, - std::optional* outCta861_3) { - return mMapper->getCta861_3(bufferHandle, outCta861_3); -} - -status_t GraphicBufferMapper::getSmpte2094_40( - buffer_handle_t bufferHandle, std::optional>* outSmpte2094_40) { - return mMapper->getSmpte2094_40(bufferHandle, outSmpte2094_40); -} - status_t GraphicBufferMapper::getDefaultPixelFormatFourCC(uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage, diff --git a/libs/ui/include/ui/Gralloc.h b/libs/ui/include/ui/Gralloc.h index e199648a8b..fcd959c2cc 100644 --- a/libs/ui/include/ui/Gralloc.h +++ b/libs/ui/include/ui/Gralloc.h @@ -165,19 +165,6 @@ public: ui::BlendMode* /*outBlendMode*/) const { return INVALID_OPERATION; } - virtual status_t getSmpte2086(buffer_handle_t /*bufferHandle*/, - std::optional* /*outSmpte2086*/) const { - return INVALID_OPERATION; - } - virtual status_t getCta861_3(buffer_handle_t /*bufferHandle*/, - std::optional* /*outCta861_3*/) const { - return INVALID_OPERATION; - } - virtual status_t getSmpte2094_40( - buffer_handle_t /*bufferHandle*/, - std::optional>* /*outSmpte2094_40*/) const { - return INVALID_OPERATION; - } virtual status_t getDefaultPixelFormatFourCC(uint32_t /*width*/, uint32_t /*height*/, PixelFormat /*format*/, uint32_t /*layerCount*/, diff --git a/libs/ui/include/ui/Gralloc4.h b/libs/ui/include/ui/Gralloc4.h index 4729cbaf67..af7c076221 100644 --- a/libs/ui/include/ui/Gralloc4.h +++ b/libs/ui/include/ui/Gralloc4.h @@ -102,12 +102,6 @@ public: std::vector* outPlaneLayouts) const override; status_t getDataspace(buffer_handle_t bufferHandle, ui::Dataspace* outDataspace) const override; status_t getBlendMode(buffer_handle_t bufferHandle, ui::BlendMode* outBlendMode) const override; - status_t getSmpte2086(buffer_handle_t bufferHandle, - std::optional* outSmpte2086) const override; - status_t getCta861_3(buffer_handle_t bufferHandle, - std::optional* outCta861_3) const override; - status_t getSmpte2094_40(buffer_handle_t bufferHandle, - std::optional>* outSmpte2094_40) const override; status_t getDefaultPixelFormatFourCC(uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage, diff --git a/libs/ui/include/ui/GraphicBufferMapper.h b/libs/ui/include/ui/GraphicBufferMapper.h index 837e3d826b..77c00ae8e9 100644 --- a/libs/ui/include/ui/GraphicBufferMapper.h +++ b/libs/ui/include/ui/GraphicBufferMapper.h @@ -122,10 +122,6 @@ public: std::vector* outPlaneLayouts); status_t getDataspace(buffer_handle_t bufferHandle, ui::Dataspace* outDataspace); status_t getBlendMode(buffer_handle_t bufferHandle, ui::BlendMode* outBlendMode); - status_t getSmpte2086(buffer_handle_t bufferHandle, std::optional* outSmpte2086); - status_t getCta861_3(buffer_handle_t bufferHandle, std::optional* outCta861_3); - status_t getSmpte2094_40(buffer_handle_t bufferHandle, - std::optional>* outSmpte2094_40); /** * Gets the default metadata for a gralloc buffer allocated with the given parameters. diff --git a/libs/ui/include/ui/GraphicTypes.h b/libs/ui/include/ui/GraphicTypes.h index 4bdacb0883..ad5ee8043a 100644 --- a/libs/ui/include/ui/GraphicTypes.h +++ b/libs/ui/include/ui/GraphicTypes.h @@ -19,10 +19,8 @@ #include #include #include -#include #include #include -#include #include #include #include @@ -49,9 +47,7 @@ using android::hardware::graphics::common::V1_2::PixelFormat; * Stable AIDL types */ using aidl::android::hardware::graphics::common::BlendMode; -using aidl::android::hardware::graphics::common::Cta861_3; using aidl::android::hardware::graphics::common::PlaneLayout; -using aidl::android::hardware::graphics::common::Smpte2086; /** * The following stable AIDL types below have standard platform definitions -- cgit v1.2.3-59-g8ed1b From ef785e119167cc5c5ccac99dafbe37d675a7d7fd Mon Sep 17 00:00:00 2001 From: Marissa Wall Date: Thu, 12 Dec 2019 14:26:59 -0800 Subject: gralloc: add gralloc4 HDR metadata support Add the ability to get and set HDR metadata. Bug: 141632767 Test: VtsHalGraphicsMapperV4_0TargetTest Change-Id: I2fb06eb0bb43d2a5689228f3bd3b76e904d647b6 --- libs/gralloc/types/Gralloc4.cpp | 193 ++++++++++++++++++++- libs/gralloc/types/fuzzer/gralloctypes.cpp | 3 + libs/gralloc/types/include/gralloctypes/Gralloc4.h | 46 ++++- libs/ui/Gralloc4.cpp | 18 ++ libs/ui/GraphicBufferMapper.cpp | 15 ++ libs/ui/include/ui/Gralloc.h | 13 ++ libs/ui/include/ui/Gralloc4.h | 6 + libs/ui/include/ui/GraphicBufferMapper.h | 4 + libs/ui/include/ui/GraphicTypes.h | 4 + 9 files changed, 295 insertions(+), 7 deletions(-) (limited to 'libs/ui/GraphicBufferMapper.cpp') diff --git a/libs/gralloc/types/Gralloc4.cpp b/libs/gralloc/types/Gralloc4.cpp index b762f1ebd3..d02e839b78 100644 --- a/libs/gralloc/types/Gralloc4.cpp +++ b/libs/gralloc/types/Gralloc4.cpp @@ -28,6 +28,7 @@ using android::hardware::hidl_vec; using aidl::android::hardware::graphics::common::BlendMode; using aidl::android::hardware::graphics::common::ChromaSiting; using aidl::android::hardware::graphics::common::Compression; +using aidl::android::hardware::graphics::common::Cta861_3; using aidl::android::hardware::graphics::common::Dataspace; using aidl::android::hardware::graphics::common::ExtendableType; using aidl::android::hardware::graphics::common::Interlaced; @@ -35,7 +36,9 @@ using aidl::android::hardware::graphics::common::PlaneLayout; using aidl::android::hardware::graphics::common::PlaneLayoutComponent; using aidl::android::hardware::graphics::common::PlaneLayoutComponentType; using aidl::android::hardware::graphics::common::Rect; +using aidl::android::hardware::graphics::common::Smpte2086; using aidl::android::hardware::graphics::common::StandardMetadataType; +using aidl::android::hardware::graphics::common::XyColor; using MetadataType = android::hardware::graphics::mapper::V4_0::IMapper::MetadataType; @@ -154,6 +157,13 @@ public: return mVec->size() > mOffset; } + size_t getRemainingSize() { + if (!mVec) { + return 0; + } + return mVec->size() - mOffset; + } + private: const hidl_vec* mVec; size_t mOffset = 0; @@ -218,6 +228,15 @@ status_t encode(const MetadataType& metadataType, const T& input, hidl_vec +status_t encodeOptional(const MetadataType& metadataType, const std::optional& input, + hidl_vec* output, EncodeHelper encodeHelper) { + if (!input) { + return NO_ERROR; + } + return encode(metadataType, *input, output, encodeHelper); +} + /** * decode is the main decode function. It takes in a hidl_vec and uses the decodeHelper function to * turn the hidl_vec byte stream into T. If an error occurs, the errorHandler function cleans up @@ -249,13 +268,32 @@ status_t decode(const MetadataType& metadataType, const hidl_vec& input return NO_ERROR; } +template +status_t decodeOptional(const MetadataType& metadataType, const hidl_vec& input, + std::optional* output, DecodeHelper decodeHelper) { + if (!output) { + return BAD_VALUE; + } + if (input.size() <= 0) { + output->reset(); + return NO_ERROR; + } + T tmp; + status_t err = decode(metadataType, input, &tmp, decodeHelper); + if (!err) { + *output = tmp; + } + return err; +} + /** * Private helper functions */ template status_t encodeInteger(const T& input, OutputHidlVec* output) { static_assert(std::is_same::value || std::is_same::value || - std::is_same::value || std::is_same::value); + std::is_same::value || std::is_same::value || + std::is_same::value || std::is_same::value); if (!output) { return BAD_VALUE; } @@ -267,7 +305,8 @@ status_t encodeInteger(const T& input, OutputHidlVec* output) { template status_t decodeInteger(InputHidlVec* input, T* output) { static_assert(std::is_same::value || std::is_same::value || - std::is_same::value || std::is_same::value); + std::is_same::value || std::is_same::value || + std::is_same::value || std::is_same::value); if (!output) { return BAD_VALUE; } @@ -306,6 +345,38 @@ status_t decodeString(InputHidlVec* input, std::string* output) { return input->decode(output, size); } +status_t encodeByteVector(const std::vector& input, OutputHidlVec* output) { + if (!output) { + return BAD_VALUE; + } + + status_t err = encodeInteger(input.size(), output); + if (err) { + return err; + } + + return output->encode(input.data(), input.size()); +} + +status_t decodeByteVector(InputHidlVec* input, std::vector* output) { + if (!output) { + return BAD_VALUE; + } + + int64_t size = 0; + status_t err = decodeInteger(input, &size); + if (err || size < 0) { + return err; + } + + if (size > input->getRemainingSize()) { + return BAD_VALUE; + } + output->resize(size); + + return input->decode(output->data(), size); +} + status_t encodeExtendableType(const ExtendableType& input, OutputHidlVec* output) { status_t err = encodeString(input.name, output); if (err) { @@ -391,6 +462,30 @@ status_t validateMetadataType(InputHidlVec* input, const MetadataType& expectedM return NO_ERROR; } +status_t encodeXyColor(const XyColor& input, OutputHidlVec* output) { + status_t err = encodeInteger(input.x, output); + if (err) { + return err; + } + return encodeInteger(input.y, output); +} + +status_t decodeXyColor(InputHidlVec* input, XyColor* output) { + status_t err = decodeInteger(input, &output->x); + if (err) { + return err; + } + return decodeInteger(input, &output->y); +} + +void clearXyColor(XyColor* output) { + if (!output) { + return; + } + output->x = 0; + output->y = 0; +} + status_t encodeRect(const Rect& input, OutputHidlVec* output) { status_t err = encodeInteger(static_cast(input.left), output); if (err) { @@ -635,6 +730,70 @@ void clearPlaneLayouts(std::vector* output) { output->clear(); } +status_t encodeSmpte2086Helper(const Smpte2086& smpte2086, OutputHidlVec* outOutputHidlVec) { + status_t err = encodeXyColor(smpte2086.primaryRed, outOutputHidlVec); + if (err) { + return err; + } + err = encodeXyColor(smpte2086.primaryGreen, outOutputHidlVec); + if (err) { + return err; + } + err = encodeXyColor(smpte2086.primaryBlue, outOutputHidlVec); + if (err) { + return err; + } + err = encodeXyColor(smpte2086.whitePoint, outOutputHidlVec); + if (err) { + return err; + } + err = encodeInteger(smpte2086.maxLuminance, outOutputHidlVec); + if (err) { + return err; + } + return encodeInteger(smpte2086.minLuminance, outOutputHidlVec); +} + +status_t decodeSmpte2086Helper(InputHidlVec* inputHidlVec, Smpte2086* outSmpte2086) { + status_t err = decodeXyColor(inputHidlVec, &outSmpte2086->primaryRed); + if (err) { + return err; + } + err = decodeXyColor(inputHidlVec, &outSmpte2086->primaryGreen); + if (err) { + return err; + } + err = decodeXyColor(inputHidlVec, &outSmpte2086->primaryBlue); + if (err) { + return err; + } + err = decodeXyColor(inputHidlVec, &outSmpte2086->whitePoint); + if (err) { + return err; + } + err = decodeInteger(inputHidlVec, &outSmpte2086->maxLuminance); + if (err) { + return err; + } + return decodeInteger(inputHidlVec, &outSmpte2086->minLuminance); +} + +status_t encodeCta861_3Helper(const Cta861_3& cta861_3, OutputHidlVec* outOutputHidlVec) { + status_t err = encodeInteger(cta861_3.maxContentLightLevel, outOutputHidlVec); + if (err) { + return err; + } + return encodeInteger(cta861_3.maxFrameAverageLightLevel, outOutputHidlVec); +} + +status_t decodeCta861_3Helper(InputHidlVec* inputHidlVec, Cta861_3* outCta861_3) { + status_t err = decodeInteger(inputHidlVec, &outCta861_3->maxContentLightLevel); + if (err) { + return err; + } + return decodeInteger(inputHidlVec, &outCta861_3->maxFrameAverageLightLevel); +} + /** * Public API functions */ @@ -798,6 +957,36 @@ status_t decodeBlendMode(const hidl_vec& blendMode, BlendMode* outBlend decodeInteger); } +status_t encodeSmpte2086(const std::optional& smpte2086, + hidl_vec* outSmpte2086) { + return encodeOptional(MetadataType_Smpte2086, smpte2086, outSmpte2086, encodeSmpte2086Helper); +} + +status_t decodeSmpte2086(const hidl_vec& smpte2086, + std::optional* outSmpte2086) { + return decodeOptional(MetadataType_Smpte2086, smpte2086, outSmpte2086, decodeSmpte2086Helper); +} + +status_t encodeCta861_3(const std::optional& cta861_3, hidl_vec* outCta861_3) { + return encodeOptional(MetadataType_Cta861_3, cta861_3, outCta861_3, encodeCta861_3Helper); +} + +status_t decodeCta861_3(const hidl_vec& cta861_3, std::optional* outCta861_3) { + return decodeOptional(MetadataType_Cta861_3, cta861_3, outCta861_3, decodeCta861_3Helper); +} + +status_t encodeSmpte2094_40(const std::optional>& smpte2094_40, + hidl_vec* outSmpte2094_40) { + return encodeOptional(MetadataType_Smpte2094_40, smpte2094_40, outSmpte2094_40, + encodeByteVector); +} + +status_t decodeSmpte2094_40(const hidl_vec& smpte2094_40, + std::optional>* outSmpte2094_40) { + return decodeOptional(MetadataType_Smpte2094_40, smpte2094_40, outSmpte2094_40, + decodeByteVector); +} + bool isStandardMetadataType(const MetadataType& metadataType) { return !std::strncmp(metadataType.name.c_str(), GRALLOC4_STANDARD_METADATA_TYPE, metadataType.name.size()); diff --git a/libs/gralloc/types/fuzzer/gralloctypes.cpp b/libs/gralloc/types/fuzzer/gralloctypes.cpp index 23c90b823d..da8cf97d4c 100644 --- a/libs/gralloc/types/fuzzer/gralloctypes.cpp +++ b/libs/gralloc/types/fuzzer/gralloctypes.cpp @@ -60,5 +60,8 @@ std::vector GRALLOCTYPES_DECODE_FUNCTIONS { GRALLOCTYPES_DECODE(std::vector, ::android::gralloc4::decodePlaneLayouts), GRALLOCTYPES_DECODE(aidl::android::hardware::graphics::common::Dataspace, ::android::gralloc4::decodeDataspace), GRALLOCTYPES_DECODE(aidl::android::hardware::graphics::common::BlendMode, ::android::gralloc4::decodeBlendMode), + GRALLOCTYPES_DECODE(std::optional, ::android::gralloc4::decodeSmpte2086), + GRALLOCTYPES_DECODE(std::optional, ::android::gralloc4::decodeCta861_3), + GRALLOCTYPES_DECODE(std::optional>, ::android::gralloc4::decodeSmpte2094_40), }; // clang-format on diff --git a/libs/gralloc/types/include/gralloctypes/Gralloc4.h b/libs/gralloc/types/include/gralloctypes/Gralloc4.h index a5d3bb2975..94de8f115f 100644 --- a/libs/gralloc/types/include/gralloctypes/Gralloc4.h +++ b/libs/gralloc/types/include/gralloctypes/Gralloc4.h @@ -17,16 +17,17 @@ #pragma once #include +#include +#include +#include #include #include #include #include -#include -#include -#include -#include #include - +#include +#include +#include #include namespace android { @@ -113,6 +114,22 @@ static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType Me GRALLOC4_STANDARD_METADATA_TYPE, static_cast(aidl::android::hardware::graphics::common::StandardMetadataType::BLEND_MODE) }; +static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType + MetadataType_Smpte2086 = {GRALLOC4_STANDARD_METADATA_TYPE, + static_cast(aidl::android::hardware::graphics::common:: + StandardMetadataType::SMPTE2086)}; + +static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType + MetadataType_Cta861_3 = {GRALLOC4_STANDARD_METADATA_TYPE, + static_cast(aidl::android::hardware::graphics::common:: + StandardMetadataType::CTA861_3)}; + +static const android::hardware::graphics::mapper::V4_0::IMapper::MetadataType + MetadataType_Smpte2094_40 = {GRALLOC4_STANDARD_METADATA_TYPE, + static_cast( + aidl::android::hardware::graphics::common:: + StandardMetadataType::SMPTE2094_40)}; + /*---------------------------------------------------------------------------------------------*/ /** @@ -272,6 +289,25 @@ status_t decodeDataspace(const android::hardware::hidl_vec& dataspace, status_t encodeBlendMode(const aidl::android::hardware::graphics::common::BlendMode& blendMode, android::hardware::hidl_vec* outBlendMode); status_t decodeBlendMode(const android::hardware::hidl_vec& blendMode, aidl::android::hardware::graphics::common::BlendMode* outBlendMode); +status_t encodeSmpte2086( + const std::optional& smpte2086, + android::hardware::hidl_vec* outSmpte2086); +status_t decodeSmpte2086( + const android::hardware::hidl_vec& smpte2086, + std::optional* outSmpte2086); + +status_t encodeCta861_3( + const std::optional& cta861_3, + android::hardware::hidl_vec* outCta861_3); +status_t decodeCta861_3( + const android::hardware::hidl_vec& cta861_3, + std::optional* outCta861_3); + +status_t encodeSmpte2094_40(const std::optional>& smpte2094_40, + android::hardware::hidl_vec* outSmpte2094_40); +status_t decodeSmpte2094_40(const android::hardware::hidl_vec& smpte2094_40, + std::optional>* outSmpte2094_40); + /** * The functions below can be used to parse extendable types. */ diff --git a/libs/ui/Gralloc4.cpp b/libs/ui/Gralloc4.cpp index 2c897cf4ff..30c48c8dc6 100644 --- a/libs/ui/Gralloc4.cpp +++ b/libs/ui/Gralloc4.cpp @@ -614,6 +614,24 @@ status_t Gralloc4Mapper::getBlendMode(buffer_handle_t bufferHandle, outBlendMode); } +status_t Gralloc4Mapper::getSmpte2086(buffer_handle_t bufferHandle, + std::optional* outSmpte2086) const { + return get(bufferHandle, gralloc4::MetadataType_Smpte2086, gralloc4::decodeSmpte2086, + outSmpte2086); +} + +status_t Gralloc4Mapper::getCta861_3(buffer_handle_t bufferHandle, + std::optional* outCta861_3) const { + return get(bufferHandle, gralloc4::MetadataType_Cta861_3, gralloc4::decodeCta861_3, + outCta861_3); +} + +status_t Gralloc4Mapper::getSmpte2094_40( + buffer_handle_t bufferHandle, std::optional>* outSmpte2094_40) const { + return get(bufferHandle, gralloc4::MetadataType_Smpte2094_40, gralloc4::decodeSmpte2094_40, + outSmpte2094_40); +} + template status_t Gralloc4Mapper::getDefault(uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage, diff --git a/libs/ui/GraphicBufferMapper.cpp b/libs/ui/GraphicBufferMapper.cpp index 8540fd304b..d20bd7a899 100644 --- a/libs/ui/GraphicBufferMapper.cpp +++ b/libs/ui/GraphicBufferMapper.cpp @@ -286,6 +286,21 @@ status_t GraphicBufferMapper::getBlendMode(buffer_handle_t bufferHandle, return mMapper->getBlendMode(bufferHandle, outBlendMode); } +status_t GraphicBufferMapper::getSmpte2086(buffer_handle_t bufferHandle, + std::optional* outSmpte2086) { + return mMapper->getSmpte2086(bufferHandle, outSmpte2086); +} + +status_t GraphicBufferMapper::getCta861_3(buffer_handle_t bufferHandle, + std::optional* outCta861_3) { + return mMapper->getCta861_3(bufferHandle, outCta861_3); +} + +status_t GraphicBufferMapper::getSmpte2094_40( + buffer_handle_t bufferHandle, std::optional>* outSmpte2094_40) { + return mMapper->getSmpte2094_40(bufferHandle, outSmpte2094_40); +} + status_t GraphicBufferMapper::getDefaultPixelFormatFourCC(uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage, diff --git a/libs/ui/include/ui/Gralloc.h b/libs/ui/include/ui/Gralloc.h index fcd959c2cc..e199648a8b 100644 --- a/libs/ui/include/ui/Gralloc.h +++ b/libs/ui/include/ui/Gralloc.h @@ -165,6 +165,19 @@ public: ui::BlendMode* /*outBlendMode*/) const { return INVALID_OPERATION; } + virtual status_t getSmpte2086(buffer_handle_t /*bufferHandle*/, + std::optional* /*outSmpte2086*/) const { + return INVALID_OPERATION; + } + virtual status_t getCta861_3(buffer_handle_t /*bufferHandle*/, + std::optional* /*outCta861_3*/) const { + return INVALID_OPERATION; + } + virtual status_t getSmpte2094_40( + buffer_handle_t /*bufferHandle*/, + std::optional>* /*outSmpte2094_40*/) const { + return INVALID_OPERATION; + } virtual status_t getDefaultPixelFormatFourCC(uint32_t /*width*/, uint32_t /*height*/, PixelFormat /*format*/, uint32_t /*layerCount*/, diff --git a/libs/ui/include/ui/Gralloc4.h b/libs/ui/include/ui/Gralloc4.h index af7c076221..4729cbaf67 100644 --- a/libs/ui/include/ui/Gralloc4.h +++ b/libs/ui/include/ui/Gralloc4.h @@ -102,6 +102,12 @@ public: std::vector* outPlaneLayouts) const override; status_t getDataspace(buffer_handle_t bufferHandle, ui::Dataspace* outDataspace) const override; status_t getBlendMode(buffer_handle_t bufferHandle, ui::BlendMode* outBlendMode) const override; + status_t getSmpte2086(buffer_handle_t bufferHandle, + std::optional* outSmpte2086) const override; + status_t getCta861_3(buffer_handle_t bufferHandle, + std::optional* outCta861_3) const override; + status_t getSmpte2094_40(buffer_handle_t bufferHandle, + std::optional>* outSmpte2094_40) const override; status_t getDefaultPixelFormatFourCC(uint32_t width, uint32_t height, PixelFormat format, uint32_t layerCount, uint64_t usage, diff --git a/libs/ui/include/ui/GraphicBufferMapper.h b/libs/ui/include/ui/GraphicBufferMapper.h index 77c00ae8e9..837e3d826b 100644 --- a/libs/ui/include/ui/GraphicBufferMapper.h +++ b/libs/ui/include/ui/GraphicBufferMapper.h @@ -122,6 +122,10 @@ public: std::vector* outPlaneLayouts); status_t getDataspace(buffer_handle_t bufferHandle, ui::Dataspace* outDataspace); status_t getBlendMode(buffer_handle_t bufferHandle, ui::BlendMode* outBlendMode); + status_t getSmpte2086(buffer_handle_t bufferHandle, std::optional* outSmpte2086); + status_t getCta861_3(buffer_handle_t bufferHandle, std::optional* outCta861_3); + status_t getSmpte2094_40(buffer_handle_t bufferHandle, + std::optional>* outSmpte2094_40); /** * Gets the default metadata for a gralloc buffer allocated with the given parameters. diff --git a/libs/ui/include/ui/GraphicTypes.h b/libs/ui/include/ui/GraphicTypes.h index ad5ee8043a..4bdacb0883 100644 --- a/libs/ui/include/ui/GraphicTypes.h +++ b/libs/ui/include/ui/GraphicTypes.h @@ -19,8 +19,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -47,7 +49,9 @@ using android::hardware::graphics::common::V1_2::PixelFormat; * Stable AIDL types */ using aidl::android::hardware::graphics::common::BlendMode; +using aidl::android::hardware::graphics::common::Cta861_3; using aidl::android::hardware::graphics::common::PlaneLayout; +using aidl::android::hardware::graphics::common::Smpte2086; /** * The following stable AIDL types below have standard platform definitions -- cgit v1.2.3-59-g8ed1b