diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-03-02 20:35:12 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-03-02 20:35:12 +0000 |
commit | d27808fa52ca2a78af0c7e4380f65a452eb8ac6a (patch) | |
tree | 344a1d2f5bf5814b065ad793b2a03aba2df4adbe | |
parent | c46c08205bfcc2021714296e1906dc2ce0c38bef (diff) | |
parent | 545457b6a334e28f6f0d447f20037d37ec562f5e (diff) |
Merge cherrypicks of ['googleplex-android-review.googlesource.com/21688145', 'googleplex-android-review.googlesource.com/21688146', 'googleplex-android-review.googlesource.com/21688147', 'googleplex-android-review.googlesource.com/21688148'] into udc-release.
Change-Id: I394ff54b8475fd0141c6659f370d3b6a3694238b
-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, 54 insertions, 62 deletions
diff --git a/gralloc4/src/core/mali_gralloc_bufferallocation.cpp b/gralloc4/src/core/mali_gralloc_bufferallocation.cpp index 7355930..f76bcf9 100644 --- a/gralloc4/src/core/mali_gralloc_bufferallocation.cpp +++ b/gralloc4/src/core/mali_gralloc_bufferallocation.cpp @@ -22,7 +22,6 @@ #include <assert.h> #include <atomic> #include <algorithm> -#include <set> #include <utils/Trace.h> #include <hardware/hardware.h> @@ -793,12 +792,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)) { @@ -807,6 +806,23 @@ 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) { @@ -848,6 +864,7 @@ 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; @@ -856,17 +873,20 @@ 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; @@ -875,12 +895,14 @@ 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; @@ -888,24 +910,28 @@ 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; @@ -976,6 +1002,7 @@ static int prepare_descriptor_exynos_formats( bufDescriptor->alloc_sizes[fidx] = size; } + bufDescriptor->fd_count = fd_count; bufDescriptor->plane_count = plane_count; @@ -997,22 +1024,6 @@ 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 ")", @@ -1021,7 +1032,7 @@ int mali_gralloc_derive_format_and_size(buffer_descriptor_t * const bufDescripto return -EINVAL; } - int32_t format_idx = get_format_index(base_format); + int32_t format_idx = get_format_index(bufDescriptor->alloc_format & MALI_GRALLOC_INTFMT_FMT_MASK); if (format_idx == -1) { return -EINVAL; @@ -1043,7 +1054,7 @@ int mali_gralloc_derive_format_and_size(buffer_descriptor_t * const bufDescripto return -EINVAL; } - if (is_exynos_format(base_format)) + if (is_exynos_format(bufDescriptor->alloc_format)) { prepare_descriptor_exynos_formats(bufDescriptor, formats[format_idx]); } @@ -1076,7 +1087,7 @@ int mali_gralloc_derive_format_and_size(buffer_descriptor_t * const bufDescripto } /* Set pixel stride differently for RAW formats */ - switch (base_format) + switch (MALI_GRALLOC_INTFMT_FMT_MASK & bufDescriptor->alloc_format) { case MALI_GRALLOC_FORMAT_INTERNAL_RAW12: case MALI_GRALLOC_FORMAT_INTERNAL_RAW10: @@ -1123,6 +1134,7 @@ 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 5f7dee1..1baaada 100644 --- a/gralloc4/src/core/mali_gralloc_formats.cpp +++ b/gralloc4/src/core/mali_gralloc_formats.cpp @@ -1625,30 +1625,3 @@ 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 b84cbb4..8f12975 100644 --- a/gralloc4/src/core/mali_gralloc_reference.cpp +++ b/gralloc4/src/core/mali_gralloc_reference.cpp @@ -26,7 +26,10 @@ #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: @@ -45,6 +48,17 @@ 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); @@ -199,7 +213,8 @@ public: auto &data = *(it->second.get()); data.ref_count++; - return 0; + if (!should_map_dmabuf(handle)) return 0; + return map_locked(handle); } 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 fb79930..cb0a820 100644 --- a/gralloc4/src/hidl_common/MapperMetadata.cpp +++ b/gralloc4/src/hidl_common/MapperMetadata.cpp @@ -286,8 +286,7 @@ 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); - uint32_t base_format = handle->alloc_format & MALI_GRALLOC_INTFMT_FMT_MASK; - int32_t format_index = get_format_index(base_format); + int32_t format_index = get_format_index(handle->alloc_format & MALI_GRALLOC_INTFMT_FMT_MASK); if (format_index < 0) { MALI_GRALLOC_LOGE("Negative format index in get_plane_layouts"); @@ -305,15 +304,10 @@ 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; - 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); - } + // 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]; } PlaneLayout layout = {.offsetInBytes = offset, diff --git a/gralloc4/src/mali_gralloc_formats.h b/gralloc4/src/mali_gralloc_formats.h index e4120fa..0d16a50 100644 --- a/gralloc4/src/mali_gralloc_formats.h +++ b/gralloc4/src/mali_gralloc_formats.h @@ -371,6 +371,4 @@ 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_ */ |