gralloc: Unregister graphicbuffer in separate thread

Change-Id: Iea08c633f6e0adffacb03b05ee041ff99f776787
This commit is contained in:
Dominggoes Isakh 2018-12-24 23:50:16 +01:00 committed by Shilin Victor
parent 3c913bf8c8
commit af9f15adb6
2 changed files with 51 additions and 7 deletions

View File

@ -361,11 +361,14 @@ static int gralloc_alloc_buffer(alloc_device_t* dev, size_t size, int usage,
hnd->ion_memory = ion_map(ion_fd, size, 0);
ALOGD_IF(debug_level > 0, "%s hnd->format=0x%x hnd->uoffset=%d hnd->voffset=%d hnd->paddr=%x hnd->bpp=%d", __func__, hnd->format, hnd->uoffset, hnd->voffset, hnd->paddr, hnd->bpp);
ALOGD_IF(debug_level > 1, "%s: ump_id:%d", __func__, hnd->ump_id);
/*
if (hnd->flags & private_handle_t::PRIV_FLAGS_GRAPHICBUFFER) {
ALOGD_IF(debug_level > 0, "%s: GraphicBuffer (ump_id:%d): ump_reference_add ump_mem_handle:%08x", __func__, ump_id, ump_mem_handle);
ump_reference_add(ump_mem_handle);
}
*/
return 0;
} else {
ALOGE("%s failed to allocate handle", __func__);
@ -653,6 +656,7 @@ static int alloc_device_free(alloc_device_t* dev, buffer_handle_t handle)
private_handle_t const* hnd = reinterpret_cast<private_handle_t const*>(handle);
private_module_t* m = reinterpret_cast<private_module_t*>(dev->common.module);
ALOGD_IF(debug_level > 1, "%s: ump_id:%d", __func__, hnd->ump_id);
pthread_mutex_lock(&l_surface);
if (hnd->flags & private_handle_t::PRIV_FLAGS_GRAPHICBUFFER) {
ALOGD_IF(debug_level > 0, "%s: GraphicBuffer (ump_id:%d): Freeing ump_mem_handle:%08x", __func__, hnd->ump_id, hnd->ump_mem_handle);

View File

@ -277,6 +277,7 @@ static int gralloc_register_buffer(gralloc_module_t const* module, buffer_handle
/* if this handle was created in this process, then we keep it as is. */
private_handle_t* hnd = (private_handle_t*)handle;
ALOGD_IF(debug_level > 1, "%s: ump_id:%d", __func__, hnd->ump_id);
ALOGD_IF(debug_level > 0, "%s flags=%x", __func__, hnd->flags);
#ifdef USE_PARTIAL_FLUSH
@ -323,6 +324,8 @@ sd
hnd->pid = getpid(); /* not in stock */
if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_UMP) {
ALOGD_IF(debug_level > 1, "%s: ump_id:%d ump_mem_handle:%08x", __func__, hnd->ump_id, hnd->ump_mem_handle);
hnd->ump_mem_handle = (int)ump_handle_create_from_secure_id(hnd->ump_id);
ALOGD_IF(debug_level > 0, "%s PRIV_FLAGS_USES_UMP hnd->ump_mem_handle=%d(%x)", __func__, hnd->ump_mem_handle, hnd->ump_mem_handle);
@ -408,6 +411,13 @@ sd
}
static int unregister_buffer(private_handle_t* hnd) {
if (private_handle_t::validate(hnd) < 0) {
ALOGE("%s Unregistering invalid buffer, returning error", __func__);
return -EINVAL;
}
ALOGD_IF(debug_level > 1, "%s: ump_id:%d", __func__, hnd->ump_id);
if (hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER) {
hnd->base = 0;
return 0;
@ -426,12 +436,17 @@ static int unregister_buffer(private_handle_t* hnd) {
pthread_mutex_lock(&s_map_lock);
if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_UMP) {
ump_mapped_pointer_release((ump_handle)hnd->ump_mem_handle);
hnd->base = 0;
ump_reference_release((ump_handle)hnd->ump_mem_handle);
hnd->ump_mem_handle = (int)UMP_INVALID_MEMORY_HANDLE;
hnd->lockState = 0;
hnd->writeOwner = 0;
if (UMP_INVALID_MEMORY_HANDLE != (ump_handle)hnd->ump_mem_handle) {
ALOGD_IF(debug_level > 1, "%s: ump_id:%d ump_mem_handle:%08x", __func__, hnd->ump_id, hnd->ump_mem_handle);
ump_mapped_pointer_release((ump_handle)hnd->ump_mem_handle);
hnd->base = 0;
ump_reference_release((ump_handle)hnd->ump_mem_handle);
hnd->ump_mem_handle = (int)UMP_INVALID_MEMORY_HANDLE;
hnd->lockState = 0;
hnd->writeOwner = 0;
} else {
ALOGD_IF(debug_level > 1, "%s: ump_id:%d SKIPPED ump_mem_handle:%08x", __func__, hnd->ump_id, hnd->ump_mem_handle);
}
} else if (hnd->flags & (private_handle_t::PRIV_FLAGS_USES_IOCTL | private_handle_t::PRIV_FLAGS_USES_HDMI)) {
if(hnd->base == 0) {
pthread_mutex_unlock(&s_map_lock);
@ -468,6 +483,15 @@ static int unregister_buffer(private_handle_t* hnd) {
return 0;
}
void* gralloc_unregister_buffer_thread(void *data) {
private_handle_t* hnd = (private_handle_t*)data;
ALOGD_IF(debug_level > 1, "%s: ump_id:%d START", __func__, hnd->ump_id);
usleep(1000000); // 1000ms
unregister_buffer(hnd);
ALOGD_IF(debug_level > 1, "%s: ump_id:%d END", __func__, hnd->ump_id);
return NULL;
}
static int gralloc_unregister_buffer(gralloc_module_t const* module, buffer_handle_t handle)
{
@ -477,6 +501,22 @@ static int gralloc_unregister_buffer(gralloc_module_t const* module, buffer_hand
}
private_handle_t* hnd = (private_handle_t*)handle;
ALOGD_IF(debug_level > 1, "%s: ump_id:%d", __func__, hnd->ump_id);
if (hnd->flags & private_handle_t::PRIV_FLAGS_GRAPHICBUFFER) {
pthread_attr_t thread_attr;
pthread_t unreg_buffer_thread;
pthread_attr_init(&thread_attr);
pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
int rc = pthread_create(&unreg_buffer_thread, &thread_attr,
gralloc_unregister_buffer_thread, (void *) handle);
if (rc < 0) {
ALOGE("%s: Unable to create thread", __func__);
return -1;
}
return 0;
}
return unregister_buffer(hnd);
}