From 09367ef6e8fb13ffe28945c5c73be8e03d756bdd Mon Sep 17 00:00:00 2001 From: Naomi Luis Date: Sun, 20 Nov 2011 00:21:11 -0800 Subject: [PATCH] libgralloc: Map buffers during registration Map the gralloc buffer during the register_buffer phase. This allows the clients to obtain the virtual address without the need to call an additional mmap. Change-Id: I9377584ee564ad5113fd353b727793f16d7b9b94 --- libgralloc/mapper.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/libgralloc/mapper.cpp b/libgralloc/mapper.cpp index e324552..da1b2fa 100755 --- a/libgralloc/mapper.cpp +++ b/libgralloc/mapper.cpp @@ -133,6 +133,13 @@ int gralloc_register_buffer(gralloc_module_t const* module, private_handle_t* hnd = (private_handle_t*)handle; if (hnd->pid != getpid()) { hnd->base = 0; + void *vaddr; + int err = gralloc_map(module, handle, &vaddr); + if (err) { + LOGE("%s: gralloc_map failed", __FUNCTION__); + return err; + } + hnd->lockState = 0; hnd->writeOwner = 0; // Reset the genlock private fd flag in the handle @@ -141,11 +148,18 @@ int gralloc_register_buffer(gralloc_module_t const* module, // Check if there is a valid lock attached to the handle. if (-1 == hnd->genlockHandle) { LOGE("%s: the lock is invalid.", __FUNCTION__); + gralloc_unmap(module, handle); + hnd->base = 0; return -EINVAL; } // Attach the genlock handle - return genlock_attach_lock((native_handle_t *)handle); + if (GENLOCK_FAILURE == genlock_attach_lock((native_handle_t *)handle)) { + LOGE("%s: genlock_attach_lock failed", __FUNCTION__); + gralloc_unmap(module, handle); + hnd->base = 0; + return -EINVAL; + } } return 0; }