diff options
author | Wen Chang Liu <wenchangliu@google.com> | 2023-03-16 05:07:34 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-03-16 05:07:34 +0000 |
commit | 307f609f4ba9148854c212addb442bb83828d612 (patch) | |
tree | 75789018f699346151e52aee50de9e1374749582 | |
parent | a3e4a505e5b7ef8a9c087c3f84e38f41d85d4f6d (diff) | |
parent | ef15d4d67f6f27b3398c09fbae7ac439c0995582 (diff) | |
download | gchips-307f609f4ba9148854c212addb442bb83828d612.tar.gz |
Merge changes from topic "revert-21688145-revert_enable_mfc_single_fd-LOHBHRBITC" into udc-dev am: ef15d4d67f
Original change: https://googleplex-android-review.googlesource.com/c/platform/hardware/google/gchips/+/21701631
Change-Id: I77ace14893856d0980e0e84f1bbd78d76c1ce730
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | gralloc4/src/core/mali_gralloc_bufferallocation.cpp | 54 | ||||
-rw-r--r-- | gralloc4/src/core/mali_gralloc_formats.cpp | 27 | ||||
-rw-r--r-- | gralloc4/src/core/mali_gralloc_reference.cpp | 17 | ||||
-rw-r--r-- | gralloc4/src/hidl_common/MapperMetadata.cpp | 16 | ||||
-rw-r--r-- | gralloc4/src/mali_gralloc_formats.h | 2 |
5 files changed, 62 insertions, 54 deletions
diff --git a/gralloc4/src/core/mali_gralloc_bufferallocation.cpp b/gralloc4/src/core/mali_gralloc_bufferallocation.cpp index f76bcf9..7355930 100644 --- a/gralloc4/src/core/mali_gralloc_bufferallocation.cpp +++ b/gralloc4/src/core/mali_gralloc_bufferallocation.cpp @@ -22,6 +22,7 @@ #include <assert.h> #include <atomic> #include <algorithm> +#include <set> #include <utils/Trace.h> #include <hardware/hardware.h> @@ -792,12 +793,12 @@ static int prepare_descriptor_exynos_formats( buffer_descriptor_t *bufDescriptor, format_info_t format_info) { - int fd_count = 1; int w = bufDescriptor->width; int h = bufDescriptor->height; uint64_t usage = bufDescriptor->producer_usage | bufDescriptor->consumer_usage; int plane_count = 2; int format = MALI_GRALLOC_INTFMT_FMT_MASK & bufDescriptor->alloc_format; + int fd_count = get_exynos_fd_count(format); if (usage & (GRALLOC_USAGE_HW_VIDEO_ENCODER | GRALLOC_USAGE_HW_VIDEO_DECODER)) { @@ -806,23 +807,6 @@ static int prepare_descriptor_exynos_formats( bufDescriptor->consumer_usage |= GRALLOC_USAGE_VIDEO_PRIVATE_DATA; } - /* set SBWC format fd_count */ - fd_count = 1; - switch (format) - { - case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_SBWC: - case HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M_SBWC: - case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC: - case HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M_10B_SBWC: - case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_SBWC_L50: - case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_SBWC_L75: - case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC_L40: - case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC_L60: - case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC_L80: - fd_count = 2; - break; - } - /* SWBC Formats have special size requirements */ switch (format) { @@ -864,7 +848,6 @@ static int prepare_descriptor_exynos_formats( break; case HAL_PIXEL_FORMAT_YCrCb_420_SP: - fd_count = 1; h = GRALLOC_ALIGN(h, 2); plane_count = setup_420_sp(w, h, fd_count, bufDescriptor->plane_info); break; @@ -873,20 +856,17 @@ static int prepare_descriptor_exynos_formats( case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_P_M: w = GRALLOC_ALIGN(w, 32); h = GRALLOC_ALIGN(h, 16); - fd_count = 3; plane_count = setup_420_p(w, h, fd_count, bufDescriptor->plane_info); break; case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_TILED: w = GRALLOC_ALIGN(w, 16); h = GRALLOC_ALIGN(h, 32); - fd_count = 2; plane_count = setup_420_sp_tiled(w, h, fd_count, bufDescriptor->plane_info); break; case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_P: w = GRALLOC_ALIGN(w, 16); - fd_count = 1; plane_count = setup_420_p(w, h, fd_count, bufDescriptor->plane_info); break; @@ -895,14 +875,12 @@ static int prepare_descriptor_exynos_formats( case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M: w = GRALLOC_ALIGN(w, 16); h = GRALLOC_ALIGN(h, 32); - fd_count = 2; plane_count = setup_420_sp(w, h, fd_count, bufDescriptor->plane_info); break; case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN: w = GRALLOC_ALIGN(w, 64); h = GRALLOC_ALIGN(h, 16); - fd_count = 1; plane_count = setup_420_sp(w, h, fd_count, bufDescriptor->plane_info); break; @@ -910,28 +888,24 @@ static int prepare_descriptor_exynos_formats( /* This is 64 pixel align for now */ w = GRALLOC_ALIGN(w, BOARD_EXYNOS_S10B_FORMAT_ALIGN); h = GRALLOC_ALIGN(h, 16); - fd_count = 2; plane_count = setup_420_sp_s10b(w, h, fd_count, bufDescriptor->plane_info); break; case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SPN_S10B: w = GRALLOC_ALIGN(w, BOARD_EXYNOS_S10B_FORMAT_ALIGN); h = GRALLOC_ALIGN(h, 16); - fd_count = 1; plane_count = setup_420_sp_s10b(w, h, fd_count, bufDescriptor->plane_info); break; case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_P010_M: w = GRALLOC_ALIGN(w, 16); h = GRALLOC_ALIGN(h, 16); - fd_count = 2; plane_count = setup_p010_sp(w, h, fd_count, bufDescriptor->plane_info); break; case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_P010_SPN: w = GRALLOC_ALIGN(w, 64); h = GRALLOC_ALIGN(h, 16); - fd_count = 1; plane_count = setup_p010_sp(w, h, fd_count, bufDescriptor->plane_info); break; @@ -1002,7 +976,6 @@ static int prepare_descriptor_exynos_formats( bufDescriptor->alloc_sizes[fidx] = size; } - bufDescriptor->fd_count = fd_count; bufDescriptor->plane_count = plane_count; @@ -1024,6 +997,22 @@ int mali_gralloc_derive_format_and_size(buffer_descriptor_t * const bufDescripto bufDescriptor->alloc_format = mali_gralloc_select_format(bufDescriptor->hal_format, bufDescriptor->format_type, usage); + + int base_format = bufDescriptor->alloc_format & MALI_GRALLOC_INTFMT_FMT_MASK; + + // TODO(b/182885532): Delete all multi-fd related dead code from gralloc + if (is_exynos_format(base_format) && get_exynos_fd_count(base_format) != 1) + { + static std::set<uint32_t> seen_formats; + if (seen_formats.find(base_format) == seen_formats.end()) { + MALI_GRALLOC_LOGW("Multi-fd format (%s 0x%" PRIx64 ") have been deprecated. Requested format: %s 0x%" PRIx64 + ". Consider changing the format to one of the single-fd options.", + format_name(base_format), static_cast<uint64_t>(base_format), + format_name(bufDescriptor->hal_format), bufDescriptor->hal_format); + seen_formats.insert(base_format); + } + } + if (bufDescriptor->alloc_format == MALI_GRALLOC_FORMAT_INTERNAL_UNDEFINED) { MALI_GRALLOC_LOGE("ERROR: Unrecognized and/or unsupported format (%s 0x%" PRIx64 ") and usage (%s 0x%" PRIx64 ")", @@ -1032,7 +1021,7 @@ int mali_gralloc_derive_format_and_size(buffer_descriptor_t * const bufDescripto return -EINVAL; } - int32_t format_idx = get_format_index(bufDescriptor->alloc_format & MALI_GRALLOC_INTFMT_FMT_MASK); + int32_t format_idx = get_format_index(base_format); if (format_idx == -1) { return -EINVAL; @@ -1054,7 +1043,7 @@ int mali_gralloc_derive_format_and_size(buffer_descriptor_t * const bufDescripto return -EINVAL; } - if (is_exynos_format(bufDescriptor->alloc_format)) + if (is_exynos_format(base_format)) { prepare_descriptor_exynos_formats(bufDescriptor, formats[format_idx]); } @@ -1087,7 +1076,7 @@ int mali_gralloc_derive_format_and_size(buffer_descriptor_t * const bufDescripto } /* Set pixel stride differently for RAW formats */ - switch (MALI_GRALLOC_INTFMT_FMT_MASK & bufDescriptor->alloc_format) + switch (base_format) { case MALI_GRALLOC_FORMAT_INTERNAL_RAW12: case MALI_GRALLOC_FORMAT_INTERNAL_RAW10: @@ -1134,7 +1123,6 @@ int mali_gralloc_derive_format_and_size(buffer_descriptor_t * const bufDescripto return 0; } - int mali_gralloc_buffer_allocate(const gralloc_buffer_descriptor_t *descriptors, uint32_t numDescriptors, buffer_handle_t *pHandle, bool *shared_backend, int fd) diff --git a/gralloc4/src/core/mali_gralloc_formats.cpp b/gralloc4/src/core/mali_gralloc_formats.cpp index 402d138..5048cac 100644 --- a/gralloc4/src/core/mali_gralloc_formats.cpp +++ b/gralloc4/src/core/mali_gralloc_formats.cpp @@ -1627,3 +1627,30 @@ bool is_exynos_format(uint32_t base_format) return false; } +uint8_t get_exynos_fd_count(uint32_t format) { + switch (format) + { + case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_SBWC: + case HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M_SBWC: + case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC: + case HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M_10B_SBWC: + case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_SBWC_L50: + case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_SBWC_L75: + case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC_L40: + case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC_L60: + case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_10B_SBWC_L80: + case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_TILED: + case HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M: + case HAL_PIXEL_FORMAT_EXYNOS_YCrCb_420_SP_M_FULL: + case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M: + case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_SP_M_S10B: + case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_P010_M: + return 2; + case HAL_PIXEL_FORMAT_EXYNOS_YV12_M: + case HAL_PIXEL_FORMAT_EXYNOS_YCbCr_420_P_M: + return 3; + } + + return 1; +} + diff --git a/gralloc4/src/core/mali_gralloc_reference.cpp b/gralloc4/src/core/mali_gralloc_reference.cpp index 8f12975..b84cbb4 100644 --- a/gralloc4/src/core/mali_gralloc_reference.cpp +++ b/gralloc4/src/core/mali_gralloc_reference.cpp @@ -26,10 +26,7 @@ #include <mutex> #include "allocator/mali_gralloc_ion.h" -#include "allocator/mali_gralloc_shared_memory.h" #include "mali_gralloc_buffer.h" -#include "mali_gralloc_bufferallocation.h" -#include "mali_gralloc_usages.h" class BufferManager { private: @@ -48,17 +45,6 @@ private: std::mutex lock; std::map<const private_handle_t *, std::unique_ptr<MappedData>> buffer_map GUARDED_BY(lock); - static bool should_map_dmabuf(buffer_handle_t handle) { - private_handle_t *hnd = (private_handle_t *)handle; - - // TODO(b/187145254): CPU_READ/WRITE buffer is not being properly locked from - // MFC. This is a WA for the time being. - constexpr auto cpu_access_usage = - (GRALLOC_USAGE_SW_WRITE_OFTEN | GRALLOC_USAGE_SW_READ_OFTEN | - GRALLOC_USAGE_SW_WRITE_RARELY | GRALLOC_USAGE_SW_READ_RARELY); - return hnd->get_usage() & cpu_access_usage; - } - static off_t get_buffer_size(unsigned int fd) { off_t current = lseek(fd, 0, SEEK_CUR); off_t size = lseek(fd, 0, SEEK_END); @@ -213,8 +199,7 @@ public: auto &data = *(it->second.get()); data.ref_count++; - if (!should_map_dmabuf(handle)) return 0; - return map_locked(handle); + return 0; } int map(buffer_handle_t handle) EXCLUDES(lock) { diff --git a/gralloc4/src/hidl_common/MapperMetadata.cpp b/gralloc4/src/hidl_common/MapperMetadata.cpp index cb0a820..fb79930 100644 --- a/gralloc4/src/hidl_common/MapperMetadata.cpp +++ b/gralloc4/src/hidl_common/MapperMetadata.cpp @@ -286,7 +286,8 @@ static std::vector<std::vector<PlaneLayoutComponent>> plane_layout_components_fr static android::status_t get_plane_layouts(const private_handle_t *handle, std::vector<PlaneLayout> *layouts) { const int num_planes = get_num_planes(handle); - int32_t format_index = get_format_index(handle->alloc_format & MALI_GRALLOC_INTFMT_FMT_MASK); + uint32_t base_format = handle->alloc_format & MALI_GRALLOC_INTFMT_FMT_MASK; + int32_t format_index = get_format_index(base_format); if (format_index < 0) { MALI_GRALLOC_LOGE("Negative format index in get_plane_layouts"); @@ -304,10 +305,15 @@ static android::status_t get_plane_layouts(const private_handle_t *handle, std:: int64_t sample_increment_in_bits = format_info.bpp[plane_index]; int64_t offset = handle->plane_info[plane_index].offset; - // TODO(b/182885532): Allocate the complete buffer contiguously - if (handle->plane_info[plane_index].fd_idx == plane_index) - { - offset = (int64_t)handle->bases[plane_index] - handle->bases[0]; + static bool warn_multifd = true; + if (warn_multifd) { + uint8_t fd_count = get_exynos_fd_count(base_format); + if (fd_count != 1) { + warn_multifd = false; + MALI_GRALLOC_LOGW("Offsets in plane layouts of multi-fd format (%s %" PRIu64 + ") are not reliable. This can lead to image corruption.", + format_name(base_format), handle->alloc_format); + } } PlaneLayout layout = {.offsetInBytes = offset, diff --git a/gralloc4/src/mali_gralloc_formats.h b/gralloc4/src/mali_gralloc_formats.h index 0d16a50..e4120fa 100644 --- a/gralloc4/src/mali_gralloc_formats.h +++ b/gralloc4/src/mali_gralloc_formats.h @@ -371,4 +371,6 @@ bool is_subsampled_yuv(const uint32_t base_format); bool is_exynos_format(uint32_t base_format); +uint8_t get_exynos_fd_count(uint32_t format); + #endif /* MALI_GRALLOC_FORMATS_H_ */ |