diff options
Diffstat (limited to 'libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp')
-rw-r--r-- | libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp | 82 |
1 files changed, 68 insertions, 14 deletions
diff --git a/libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp b/libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp index a155519..62c550a 100644 --- a/libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp +++ b/libvendorgraphicbuffer/gralloc4/vendor_graphicbuffer_meta.cpp @@ -34,6 +34,8 @@ using arm::mapper::common::shared_metadata; using aidl::android::hardware::graphics::common::Dataspace; using android::gralloc4::encodeDataspace; using android::gralloc4::decodeDataspace; +using android::gralloc4::decodePixelFormatFourCC; +using android::gralloc4::decodePixelFormatModifier; using android::hardware::graphics::mapper::V4_0::IMapper; using android::hardware::graphics::mapper::V4_0::Error; @@ -45,8 +47,7 @@ using android::hardware::graphics::mapper::V4_0::Error; // libraries and should depend upon HAL (and it's extension) to call into // Gralloc. int mali_gralloc_reference_validate(buffer_handle_t handle) { - auto hnd = static_cast<const private_handle_t *>(handle); - return private_handle_t::validate(hnd); + return private_handle_t::validate(handle); } const private_handle_t * convertNativeHandleToPrivateHandle(buffer_handle_t handle) { @@ -70,7 +71,7 @@ android::sp<IMapper> get_mapper() { int VendorGraphicBufferMeta::get_video_metadata_fd(buffer_handle_t hnd) { - const private_handle_t *gralloc_hnd = static_cast<const private_handle_t *>(hnd); + const auto *gralloc_hnd = convertNativeHandleToPrivateHandle(hnd); if (!gralloc_hnd) return -EINVAL; @@ -136,7 +137,7 @@ int VendorGraphicBufferMeta::set_dataspace(buffer_handle_t hnd, android_dataspac int VendorGraphicBufferMeta::is_afbc(buffer_handle_t hnd) { - const private_handle_t *gralloc_hnd = static_cast<const private_handle_t *>(hnd); + const auto *gralloc_hnd = convertNativeHandleToPrivateHandle(hnd); if (!gralloc_hnd) return 0; @@ -147,11 +148,9 @@ int VendorGraphicBufferMeta::is_afbc(buffer_handle_t hnd) return 0; } -int VendorGraphicBufferMeta::is_sbwc(buffer_handle_t buffer_hnd_p) +int VendorGraphicBufferMeta::is_sbwc(buffer_handle_t hnd) { - const private_handle_t *hnd = static_cast<const private_handle_t *>(buffer_hnd_p); - - return is_sbwc_format(static_cast<uint32_t>(hnd->alloc_format & MALI_GRALLOC_INTFMT_FMT_MASK)); + return is_sbwc_format(VendorGraphicBufferMeta::get_internal_format(hnd)); } #define GRALLOC_META_GETTER(__type__, __name__, __member__) \ @@ -165,7 +164,8 @@ __type__ VendorGraphicBufferMeta::get_##__name__(buffer_handle_t hnd) \ uint32_t VendorGraphicBufferMeta::get_format(buffer_handle_t hnd) { - const private_handle_t *gralloc_hnd = static_cast<const private_handle_t *>(hnd); + const auto *gralloc_hnd = convertNativeHandleToPrivateHandle(hnd); + if (!gralloc_hnd) return 0; @@ -174,7 +174,8 @@ uint32_t VendorGraphicBufferMeta::get_format(buffer_handle_t hnd) uint64_t VendorGraphicBufferMeta::get_internal_format(buffer_handle_t hnd) { - const private_handle_t *gralloc_hnd = static_cast<const private_handle_t *>(hnd); + const auto *gralloc_hnd = convertNativeHandleToPrivateHandle(hnd);; + if (!gralloc_hnd) return 0; @@ -186,6 +187,7 @@ GRALLOC_META_GETTER(uint64_t, frameworkFormat, req_format); GRALLOC_META_GETTER(int, width, width); GRALLOC_META_GETTER(int, height, height); GRALLOC_META_GETTER(uint32_t, stride, stride); +GRALLOC_META_GETTER(uint32_t, stride_in_bytes, plane_info[0].byte_stride); GRALLOC_META_GETTER(uint32_t, vstride, plane_info[0].alloc_height); GRALLOC_META_GETTER(uint64_t, producer_usage, producer_usage); @@ -196,7 +198,7 @@ GRALLOC_META_GETTER(uint64_t, flags, flags); int VendorGraphicBufferMeta::get_fd(buffer_handle_t hnd, int num) { - const private_handle_t *gralloc_hnd = static_cast<const private_handle_t *>(hnd); + const auto *gralloc_hnd = convertNativeHandleToPrivateHandle(hnd); if (!gralloc_hnd) return -1; @@ -209,7 +211,7 @@ int VendorGraphicBufferMeta::get_fd(buffer_handle_t hnd, int num) int VendorGraphicBufferMeta::get_size(buffer_handle_t hnd, int num) { - const private_handle_t *gralloc_hnd = static_cast<const private_handle_t *>(hnd); + const auto *gralloc_hnd = convertNativeHandleToPrivateHandle(hnd); if (!gralloc_hnd) return 0; @@ -223,7 +225,7 @@ int VendorGraphicBufferMeta::get_size(buffer_handle_t hnd, int num) uint64_t VendorGraphicBufferMeta::get_usage(buffer_handle_t hnd) { - const private_handle_t *gralloc_hnd = static_cast<const private_handle_t *>(hnd); + const auto *gralloc_hnd = convertNativeHandleToPrivateHandle(hnd); if (!gralloc_hnd) return 0; @@ -255,9 +257,61 @@ void* VendorGraphicBufferMeta::get_video_metadata_roiinfo(buffer_handle_t hnd) return nullptr; } +uint32_t VendorGraphicBufferMeta::get_format_fourcc(buffer_handle_t hnd) { + native_handle_t* handle = const_cast<native_handle_t*>(hnd); + if (!handle) { + return DRM_FORMAT_INVALID; + } + + Error error = Error::NONE; + uint32_t fourcc; + get_mapper()->get(handle, android::gralloc4::MetadataType_PixelFormatFourCC, + [&](const auto& tmpError, const android::hardware::hidl_vec<uint8_t>& tmpVec) { + error = tmpError; + if (error != Error::NONE) { + return; + } + error = static_cast<Error>(decodePixelFormatFourCC(tmpVec, &fourcc)); + }); + + + if (error != Error::NONE) { + ALOGE("Failed to get fourcc"); + return DRM_FORMAT_INVALID; + } + + return fourcc; +} + +uint64_t VendorGraphicBufferMeta::get_format_modifier(buffer_handle_t hnd) { + native_handle_t* handle = const_cast<native_handle_t*>(hnd); + if (!handle) { + return DRM_FORMAT_MOD_INVALID; + } + + Error error = Error::NONE; + uint64_t modifier; + get_mapper()->get(handle, android::gralloc4::MetadataType_PixelFormatModifier, + [&](const auto& tmpError, const android::hardware::hidl_vec<uint8_t>& tmpVec) { + error = tmpError; + if (error != Error::NONE) { + return; + } + error = static_cast<Error>(decodePixelFormatModifier(tmpVec, &modifier)); + }); + + + if (error != Error::NONE) { + ALOGE("Failed to get format modifier"); + return DRM_FORMAT_MOD_INVALID; + } + + return modifier; +} + void VendorGraphicBufferMeta::init(const buffer_handle_t handle) { - const private_handle_t *gralloc_hnd = static_cast<const private_handle_t *>(handle); + const auto *gralloc_hnd = convertNativeHandleToPrivateHandle(handle); if (!gralloc_hnd) return; |