diff options
author | Ankit Goyal <layog@google.com> | 2021-06-21 12:04:21 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2021-06-21 12:04:21 +0000 |
commit | b9eb3b87924454e3bf6810c92970c92d84f1f9eb (patch) | |
tree | 8770547d4dff5fb51a454ab4cc6d21f256bfebd7 | |
parent | 9d59748ced4a3c6dd27e74c0f98db1a22d9aaec2 (diff) | |
parent | a7f9366069f1ca857fbb8110ddf1e665ac961cee (diff) | |
download | gchips-b9eb3b87924454e3bf6810c92970c92d84f1f9eb.tar.gz |
Merge "Lazy map the buffers on lock" into sc-dev
-rw-r--r-- | gralloc4/src/allocator/mali_gralloc_ion.cpp | 1 | ||||
-rw-r--r-- | gralloc4/src/core/mali_gralloc_bufferaccess.cpp | 9 | ||||
-rw-r--r-- | gralloc4/src/core/mali_gralloc_reference.cpp | 25 | ||||
-rw-r--r-- | gralloc4/src/core/mali_gralloc_reference.h | 1 | ||||
-rw-r--r-- | gralloc4/src/hidl_common/Mapper.cpp | 10 |
5 files changed, 36 insertions, 10 deletions
diff --git a/gralloc4/src/allocator/mali_gralloc_ion.cpp b/gralloc4/src/allocator/mali_gralloc_ion.cpp index afb6620..3123848 100644 --- a/gralloc4/src/allocator/mali_gralloc_ion.cpp +++ b/gralloc4/src/allocator/mali_gralloc_ion.cpp @@ -726,6 +726,7 @@ int mali_gralloc_ion_map(private_handle_t *hnd) for (int cidx = 0; cidx < fidx; fidx++) { munmap((void*)hnd->bases[cidx], hnd->alloc_sizes[cidx]); + hnd->bases[cidx] = 0; } return -err; diff --git a/gralloc4/src/core/mali_gralloc_bufferaccess.cpp b/gralloc4/src/core/mali_gralloc_bufferaccess.cpp index bc6920e..6740556 100644 --- a/gralloc4/src/core/mali_gralloc_bufferaccess.cpp +++ b/gralloc4/src/core/mali_gralloc_bufferaccess.cpp @@ -24,6 +24,7 @@ #include "mali_gralloc_buffer.h" #include "mali_gralloc_formats.h" #include "mali_gralloc_usages.h" +#include "mali_gralloc_reference.h" #include "allocator/mali_gralloc_ion.h" #include "gralloc_helper.h" #include "format_info.h" @@ -240,13 +241,7 @@ int mali_gralloc_lock(buffer_handle_t buffer, return -EINVAL; } - /* Mapping is done during reference retain instead of lock */ -#if 0 - if (ion_map_for_lock(hnd) < 0) - { - return -EINVAL; - } -#endif + mali_gralloc_reference_map(buffer); *vaddr = (void *)hnd->bases[0]; diff --git a/gralloc4/src/core/mali_gralloc_reference.cpp b/gralloc4/src/core/mali_gralloc_reference.cpp index e24d9ff..59f82b4 100644 --- a/gralloc4/src/core/mali_gralloc_reference.cpp +++ b/gralloc4/src/core/mali_gralloc_reference.cpp @@ -40,16 +40,35 @@ int mali_gralloc_reference_retain(buffer_handle_t handle) if (hnd->allocating_pid == getpid() || hnd->remote_pid == getpid()) { hnd->ref_count++; - pthread_mutex_unlock(&s_map_lock); - return 0; } else { hnd->remote_pid = getpid(); hnd->ref_count = 1; + + // Reset the handle bases, this is used to check if a buffer is mapped + for (int fidx = 0; fidx < hnd->fd_count; fidx++) { + hnd->bases[fidx] = 0; + } + } + + pthread_mutex_unlock(&s_map_lock); + + return 0; +} + +int mali_gralloc_reference_map(buffer_handle_t handle) { + private_handle_t *hnd = (private_handle_t *)handle; + + pthread_mutex_lock(&s_map_lock); + + if (hnd->bases[0]) { + MALI_GRALLOC_LOGV("Buffer is already mapped"); + pthread_mutex_unlock(&s_map_lock); + return 0; } - int retval= mali_gralloc_ion_map(hnd); + int retval = mali_gralloc_ion_map(hnd); /* Import ION handle to let ION driver know who's using the buffer */ import_exynos_ion_handles(hnd); diff --git a/gralloc4/src/core/mali_gralloc_reference.h b/gralloc4/src/core/mali_gralloc_reference.h index 555be08..85bc1c9 100644 --- a/gralloc4/src/core/mali_gralloc_reference.h +++ b/gralloc4/src/core/mali_gralloc_reference.h @@ -24,5 +24,6 @@ int mali_gralloc_reference_retain(buffer_handle_t handle); int mali_gralloc_reference_release(buffer_handle_t handle, bool canFree); int mali_gralloc_reference_validate(buffer_handle_t handle); +int mali_gralloc_reference_map(buffer_handle_t handle); #endif /* MALI_GRALLOC_REFERENCE_H_ */ diff --git a/gralloc4/src/hidl_common/Mapper.cpp b/gralloc4/src/hidl_common/Mapper.cpp index b11361d..bfe632d 100644 --- a/gralloc4/src/hidl_common/Mapper.cpp +++ b/gralloc4/src/hidl_common/Mapper.cpp @@ -184,6 +184,16 @@ static Error lockBuffer(buffer_handle_t bufferHandle, return Error::BAD_BUFFER; } + if (mali_gralloc_reference_validate(bufferHandle) < 0) + { + if (fenceFd >= 0) + { + close(fenceFd); + } + MALI_GRALLOC_LOGE("Buffer: %p is not imported", bufferHandle); + return Error::BAD_VALUE; + } + auto private_handle = private_handle_t::dynamicCast(bufferHandle); if (private_handle->cpu_write != 0 && (cpuUsage & BufferUsage::CPU_WRITE_MASK)) { |