// if this handle was created in this process, then we keep it as is.
private_handle_t *hnd = (private_handle_t *)handle;
int retval = -EINVAL;
pthread_mutex_lock(&s_map_lock);
#if GRALLOC_ARM_UMP_MODULE
if (!s_ump_is_open)
{
ump_result res = ump_open(); // MJOLL-4012: UMP implementation needs a ump_close() for each ump_open
if (res != UMP_OK)
{
pthread_mutex_unlock(&s_map_lock);
AERR("Failed to open UMP library with res=%d", res); return retval;
}
s_ump_is_open = 1;
}
#endif
hnd->pid = getpid();
if (hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)
{
AINF("Register buffer %p although it will be treated as a nop", handle);
retval = 0;
} elseif (hnd->flags & private_handle_t::PRIV_FLAGS_USES_UMP)
{ #if GRALLOC_ARM_UMP_MODULE
hnd->ump_mem_handle = (int)ump_handle_create_from_secure_id(hnd->ump_id);
if (UMP_INVALID_MEMORY_HANDLE != (ump_handle)hnd->ump_mem_handle)
{
hnd->base = ump_mapped_pointer_get((ump_handle)hnd->ump_mem_handle);
#else
AERR("Gralloc does not support UMP. Unable to register UMP memory for handle %p", hnd); #endif
} elseif (hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION)
{ #if GRALLOC_ARM_DMA_BUF_MODULE unsignedchar *mappedAddress;
size_t size = hnd->size;
hw_module_t *pmodule = NULL;
private_module_t *m = NULL;
if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (const hw_module_t **)&pmodule) == 0)
{
m = reinterpret_cast<private_module_t *>(pmodule);
} else
{
AERR("Could not get gralloc module for handle: %p", hnd);
retval = -errno; goto cleanup;
}
/* the test condition is set to m->ion_client <= 0 here, because: *1)modulestructureareinitializedto0ifnoinitialvalueisapplied *2)aseconduserprocessshouldgetaionfdgreaterthan0.
*/ if (m->ion_client <= 0)
{ /* a second user process must obtain a client handle first via ion_open before it can obtain the shared ion buffer*/
m->ion_client = ion_open();
if (m->ion_client < 0)
{
AERR("Could not open ion device for handle: %p", hnd);
retval = -errno; goto cleanup;
}
}
if (hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)
{
AERR("Can't unregister buffer %p as it is a framebuffer", handle);
} elseif (hnd->pid == getpid()) // never unmap buffers that were not registered in this process
{
pthread_mutex_lock(&s_map_lock);
/* if handle is still locked, the unmapping would not happen until unlocked*/ if (!(hnd->lockState & private_handle_t::LOCK_STATE_WRITE))
{
unmap_buffer(hnd);
}
pthread_mutex_unlock(&s_map_lock);
} else
{
AERR("Trying to unregister buffer %p from process %d that was not created in current process: %d", hnd, hnd->pid, getpid());
}
return0;
}
staticint gralloc_lock(gralloc_module_t const *module, buffer_handle_t handle, int usage, int l, int t, int w, int h, void **vaddr)
{
if (hnd->format == HAL_PIXEL_FORMAT_YCbCr_420_888)
{
AERR("Buffer with format HAL_PIXEL_FORMAT_YCbCr_*_888 must be locked by lock_ycbcr()"); return -EINVAL;
}
pthread_mutex_lock(&s_map_lock);
if (hnd->lockState & private_handle_t::LOCK_STATE_UNREGISTERED)
{
AERR("Locking on an unregistered buffer %p, returning error", hnd);
pthread_mutex_unlock(&s_map_lock); return -EINVAL;
}
staticint gralloc_lock_ycbcr(gralloc_module_t const *module, buffer_handle_t handle, int usage, int l, int t, int w, int h, struct android_ycbcr *ycbcr)
{ int retval = 0; int ystride, cstride;
/* if the handle has already been unregistered, unmap it here*/ if (hnd->lockState & private_handle_t::LOCK_STATE_UNREGISTERED)
{
unmap_buffer(hnd);
}
pthread_mutex_unlock(&s_map_lock);
return0;
}
#ifdefined(GRALLOC_MODULE_API_VERSION_0_3) staticint gralloc_lock_async (gralloc_module_t const *module, buffer_handle_t handle, int usage, int l, int t, int w, int h, void **vaddr, int fenceFD)
{ if (fenceFD >= 0)
{
sync_wait(fenceFD, -1);
close(fenceFD);
}
if (gralloc_unlock(module, handle) < 0)
{ return -EINVAL;
}
return0;
}
staticint gralloc_lock_async_ycbcr(gralloc_module_t const *module, buffer_handle_t handle, int usage, int l, int t, int w, int h, struct android_ycbcr *ycbcr, int fenceFD)
{ if (fenceFD >= 0)
{
sync_wait(fenceFD, -1);
close(fenceFD);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.