/* failure simulation is enabled by setting the first_fail property to non-zero */ if (first_fail > 0)
{
LOGI("iteration %u (fail=%u, period=%u)\n", call_count, first_fail, fail_period);
/* if the failure condition matches, fail this iteration */ if (__ump_alloc_should_fail())
{
ump_mem_handle = UMP_INVALID_MEMORY_HANDLE;
} else #endif
{ if (usage & GRALLOC_USAGE_PROTECTED)
{
AERR("gralloc_alloc_buffer() does not support to allocate protected UMP memory.");
} else
{
ump_mem_handle = ump_ref_drv_allocate(size, constraints);
if (UMP_INVALID_MEMORY_HANDLE != ump_mem_handle)
{
cpu_ptr = ump_mapped_pointer_get(ump_mem_handle);
if (NULL != cpu_ptr)
{
ump_id = ump_secure_id_get(ump_mem_handle);
if (UMP_INVALID_SECURE_ID != ump_id)
{
private_handle_t *hnd = new private_handle_t(private_handle_t::PRIV_FLAGS_USES_UMP, usage, size, cpu_ptr,
private_handle_t::LOCK_STATE_MAPPED, ump_id, ump_mem_handle);
// allocate the framebuffer if (m->framebuffer == NULL)
{ // initialize the framebuffer, the framebuffer is mapped once and forever. int err = init_frame_buffer_locked(m);
if (numBuffers == 1)
{ // If we have only one buffer, we never use page-flipping. Instead, // we return a regular buffer which will be memcpy'ed to the main // screen when post is called. int newUsage = (usage & ~GRALLOC_USAGE_HW_FB) | GRALLOC_USAGE_HW_2D;
AERR("fallback to single buffering. Virtual Y-res too small %d", m->info.yres); return gralloc_alloc_buffer(dev, bufferSize, newUsage, pHandle);
}
if (bufferMask >= ((1LU << numBuffers) - 1))
{ // We ran out of buffers, reset bufferMask.
bufferMask = 0;
m->bufferMask = 0;
}
void *vaddr = m->framebuffer->base;
// find a free slot for (uint32_t i = 0 ; i < numBuffers ; i++)
{ if ((bufferMask & (1LU << i)) == 0)
{
m->bufferMask |= (1LU << i); break;
}
// The entire framebuffer memory is already mapped, now create a buffer object for parts of this memory
private_handle_t *hnd = new private_handle_t(private_handle_t::PRIV_FLAGS_FRAMEBUFFER, usage, size, vaddr, 0, m->framebuffer->fd, (uintptr_t)vaddr - (uintptr_t) m->framebuffer->base, m->framebuffer->fb_paddr);
/* create a backing ump memory handle if the framebuffer is exposed as a secure ID */ if ((int)UMP_INVALID_SECURE_ID != hnd->ump_id)
{
hnd->ump_mem_handle = (int)ump_handle_create_from_secure_id(hnd->ump_id);
if ((int)UMP_INVALID_MEMORY_HANDLE == hnd->ump_mem_handle)
{
AINF("warning: unable to create UMP handle from secure ID %i\n", hnd->ump_id);
}
}
AINF("Fallback to single buffering. Unable to map framebuffer memory to handle:%p", hnd); return gralloc_alloc_buffer(dev, bufferSize, newUsage, pHandle);
} #endif
}
// correct numFds/numInts when there is no dmabuf fd if (hnd->share_fd < 0)
{
hnd->numFds--;
hnd->numInts++;
} #endif
staticint alloc_device_alloc(alloc_device_t *dev, int w, int h, int format, int usage, buffer_handle_t *pHandle, int *pStride)
{ if (!pHandle || !pStride)
{ return -EINVAL;
}
size_t size;
size_t stride; int bpp = 1;
if (format == HAL_PIXEL_FORMAT_YCrCb_420_SP || format == HAL_PIXEL_FORMAT_YV12 /* HAL_PIXEL_FORMAT_YCbCr_420_SP, HAL_PIXEL_FORMAT_YCbCr_420_P, HAL_PIXEL_FORMAT_YCbCr_422_I are not defined in Android. *ToenableMaliDDKEGLImagesupportforthoseformats,firstly,youhavetoaddtheminAndroidsystem/core/include/system/graphics.h. *Then,defineSUPPORT_LEGACY_FORMATinthesameheaderfile(MaliDDKwillalsocheckthisdefinition).
*/ #ifdef SUPPORT_LEGACY_FORMAT
|| format == HAL_PIXEL_FORMAT_YCbCr_420_SP || format == HAL_PIXEL_FORMAT_YCbCr_420_P || format == HAL_PIXEL_FORMAT_YCbCr_422_I #endif
)
{ switch (format)
{ case HAL_PIXEL_FORMAT_YCrCb_420_SP:
stride = GRALLOC_ALIGN(w, 16);
size = GRALLOC_ALIGN(h, 16) * (stride + GRALLOC_ALIGN(stride / 2, 16)); break;
/* match the framebuffer format */ if (usage & GRALLOC_USAGE_HW_FB)
{ #ifdef GRALLOC_16_BITS
format = HAL_PIXEL_FORMAT_RGB_565; #else
format = HAL_PIXEL_FORMAT_BGRA_8888; #endif
}
/* Buffer might be unregistered so we need to check for invalid ump handle*/ if ((int)UMP_INVALID_MEMORY_HANDLE != hnd->ump_mem_handle)
{
ump_mapped_pointer_release((ump_handle)hnd->ump_mem_handle);
ump_reference_release((ump_handle)hnd->ump_mem_handle);
}
#else
AERR("Can't free ump memory for handle:%p. Not supported.", hnd); #endif
} elseif (hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION)
{ #if GRALLOC_ARM_DMA_BUF_MODULE /* Buffer might be unregistered so we need to check for invalid ump handle*/ if (0 != hnd->base)
{ if (0 != munmap((void *)hnd->base, hnd->size))
{
AERR("Failed to munmap handle %p", hnd);
}
}
close(hnd->share_fd);
memset((void *)hnd, 0, sizeof(*hnd)); #else
AERR("Can't free dma_buf memory for handle:0x%x. Not supported.", (unsignedint)hnd); #endif
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.