libgralloc-qsd8k: Fallback to ashmem if pmem allocation fails

If we are not using MDP composition, and the pmem allocation fails,
try allocating the surface memory from the ashmem region, if a PMEM
surface is not explicitly requested.

Change-Id: I528cd6b31cc84fb3a4b4611cf197baffe1465ee9
This commit is contained in:
Naomi Luis 2011-07-19 12:17:39 -07:00
parent 77b2f9b9a2
commit 7d0082bc06

16
gpu.cpp
View File

@ -228,11 +228,13 @@ int gpu_context_t::gralloc_alloc_buffer(size_t size, int usage, buffer_handle_t*
// Allocate the buffer from pmem
err = pma->alloc_pmem_buffer(size, usage, &base, &offset, &fd);
if (err < 0) {
if (((usage & GRALLOC_USAGE_HW_MASK) == 0) &&
((usage & GRALLOC_USAGE_PRIVATE_PMEM_ADSP) == 0)) {
if (((usage & GRALLOC_USAGE_PRIVATE_PMEM) == 0) &&
((usage & GRALLOC_USAGE_PRIVATE_PMEM_ADSP) == 0) &&
!isMDPComposition) {
// the caller didn't request PMEM, so we can try something else
flags &= ~private_handle_t::PRIV_FLAGS_USES_PMEM;
err = 0;
LOGE("Pmem allocation failed. Trying ashmem");
goto try_ashmem;
} else {
LOGE("couldn't open pmem (%s)", strerror(errno));
@ -240,10 +242,12 @@ int gpu_context_t::gralloc_alloc_buffer(size_t size, int usage, buffer_handle_t*
}
} else {
try_ashmem:
fd = deps.ashmem_create_region("gralloc-buffer", size);
if (fd < 0) {
LOGE("couldn't create ashmem (%s)", strerror(errno));
err = -errno;
err = alloc_ashmem_buffer(size, (unsigned int)pHandle, &base, &offset, &fd);
if (err >= 0) {
lockState |= private_handle_t::LOCK_STATE_MAPPED;
flags |= private_handle_t::PRIV_FLAGS_USES_ASHMEM;
} else {
LOGE("Ashmem fallback failed");
}
}