From 31802ca9c030b8f9a137f32826e9c9a76d0d6e17 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Fri, 19 Jun 2009 16:14:09 -0700 Subject: fallback to ashmem when pmem is not availlable --- modules/gralloc/gralloc.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'modules/gralloc/gralloc.cpp') diff --git a/modules/gralloc/gralloc.cpp b/modules/gralloc/gralloc.cpp index 2cf6e02..ccfe40b 100644 --- a/modules/gralloc/gralloc.cpp +++ b/modules/gralloc/gralloc.cpp @@ -217,17 +217,23 @@ static int gralloc_alloc_buffer(alloc_device_t* dev, } if ((flags & private_handle_t::PRIV_FLAGS_USES_PMEM) == 0) { +try_ashmem: fd = ashmem_create_region("Buffer", size); if (fd < 0) { + LOGE("couldn't create ashmem (%s)", strerror(-errno)); err = -errno; } } else { private_module_t* m = reinterpret_cast( dev->common.module); - + pthread_mutex_lock(&m->lock); - if (m->pmem_master == -1) + if (m->pmem_master == -1) { err = init_pmem_area(m); + if (err) { + m->pmem_master = err; + } + } pthread_mutex_unlock(&m->lock); if (m->pmem_master >= 0) { @@ -254,6 +260,15 @@ static int gralloc_alloc_buffer(alloc_device_t* dev, } //LOGD_IF(!err, "allocating pmem size=%d, offset=%d", size, offset); } + } else { + if ((usage & GRALLOC_USAGE_HW_2D) == 0) { + // the caller didn't request PMEM, so we can try something else + flags &= ~private_handle_t::PRIV_FLAGS_USES_PMEM; + err = 0; + goto try_ashmem; + } else { + LOGE("couldn't open pmem (%s)", strerror(-errno)); + } } } -- cgit v1.1