summaryrefslogtreecommitdiff
path: root/gralloc4/src
diff options
context:
space:
mode:
authorAnkit Goyal <layog@google.com>2021-06-16 15:04:00 +0800
committerAnkit Goyal <layog@google.com>2021-06-21 15:42:09 +0800
commita7f9366069f1ca857fbb8110ddf1e665ac961cee (patch)
treefc5b3bd3bca9c99400e2b1332f2079f678cbfb78 /gralloc4/src
parente37cdac52a575a68934af58b47767219a91acf07 (diff)
downloadgchips-a7f9366069f1ca857fbb8110ddf1e665ac961cee.tar.gz
Lazy map the buffers on lock
This potentially should improve the importBuffer calls as not all clients need CPU mapped buffers. This patch needs to be thoroughly tested as there are chances it might break metadata reporting. I did the smoke test and it seems fine. Fix: 190688388 Test: Yet to be tested Change-Id: I2f98b1f9646a1336ded3747d2a24c6851a883d73
Diffstat (limited to 'gralloc4/src')
-rw-r--r--gralloc4/src/allocator/mali_gralloc_ion.cpp1
-rw-r--r--gralloc4/src/core/mali_gralloc_bufferaccess.cpp9
-rw-r--r--gralloc4/src/core/mali_gralloc_reference.cpp25
-rw-r--r--gralloc4/src/core/mali_gralloc_reference.h1
-rw-r--r--gralloc4/src/hidl_common/Mapper.cpp10
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))
{