From 950ab4c045253d5f939e7357e1149a5d5f84ccad Mon Sep 17 00:00:00 2001 From: Harshad Bhutada Date: Thu, 9 Jun 2011 15:36:38 +0530 Subject: [PATCH] libgralloc-qsd8k: Dynamic ASHMEM When USE_ASHMEM is set, ASHMEM will be used only for non-MDP composition. This implementation will force to use PMEM for MDP composition case. This will allow using ASHMEM or PMEM at run time, depending on the composition type. USE_ASHMEM would mean that use ASHMEM where possible. This will also make sure that video works properly when dynamic ASHMEM feature is enabled on 7x27 / 7x27a / 7x25a targets. Change-Id: I5860311aad20d33e2d078cd6f0d05e041ff3364a --- gpu.cpp | 16 +++++++++++++++- gpu.h | 1 + gralloc.cpp | 19 +++++++++++++++---- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/gpu.cpp b/gpu.cpp index dd73a91..efe1ab6 100644 --- a/gpu.cpp +++ b/gpu.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include @@ -27,7 +28,8 @@ gpu_context_t::gpu_context_t(Deps& deps, PmemAllocator& pmemAllocator, PmemAllocator& pmemAdspAllocator, const private_module_t* module) : deps(deps), pmemAllocator(pmemAllocator), - pmemAdspAllocator(pmemAdspAllocator) + pmemAdspAllocator(pmemAdspAllocator), + isMDPComposition(false) { // Zero out the alloc_device_t memset(static_cast(this), 0, sizeof(alloc_device_t)); @@ -39,6 +41,11 @@ gpu_context_t::gpu_context_t(Deps& deps, PmemAllocator& pmemAllocator, common.close = gralloc_close; alloc = gralloc_alloc; free = gralloc_free; + + char property[PROPERTY_VALUE_MAX]; + if((property_get("debug.composition.type", property, NULL) > 0) && + (strncmp(property, "mdp", 3) == 0)) + isMDPComposition = true; } int gpu_context_t::gralloc_alloc_framebuffer_locked(size_t size, int usage, @@ -177,6 +184,13 @@ int gpu_context_t::gralloc_alloc_buffer(size_t size, int usage, buffer_handle_t* if (usage & GRALLOC_USAGE_PRIVATE_PMEM){ flags |= private_handle_t::PRIV_FLAGS_USES_PMEM; } + + // Enable use of PMEM only when MDP composition is used (and other conditions apply). + // Else fall back on using ASHMEM + if (isMDPComposition && + ((usage & GRALLOC_USAGE_HW_TEXTURE) || (usage & GRALLOC_USAGE_HW_2D)) ) { + flags |= private_handle_t::PRIV_FLAGS_USES_PMEM; + } #endif if (usage & GRALLOC_USAGE_PRIVATE_PMEM_ADSP) { flags |= private_handle_t::PRIV_FLAGS_USES_PMEM_ADSP; diff --git a/gpu.h b/gpu.h index 5449999..9833d60 100644 --- a/gpu.h +++ b/gpu.h @@ -71,6 +71,7 @@ class gpu_context_t : public alloc_device_t { Deps& deps; PmemAllocator& pmemAllocator; PmemAllocator& pmemAdspAllocator; + bool isMDPComposition; int alloc_ashmem_buffer(size_t size, unsigned int postfix, void** pBase, int* pOffset, int* pFd); }; diff --git a/gralloc.cpp b/gralloc.cpp index 9ac7bd6..8556780 100644 --- a/gralloc.cpp +++ b/gralloc.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -76,10 +77,20 @@ class PmemAllocatorDepsDeviceImpl : public PmemUserspaceAllocator::Deps, } #else #ifdef USE_ASHMEM - if(module != NULL) - *size = module->info.xres * module->info.yres * 2 * 2; - else - return -ENOMEM; + char property[PROPERTY_VALUE_MAX]; + bool isMDPComposition = false; + if((property_get("debug.composition.type", property, NULL) > 0) && + (strncmp(property, "mdp", 3) == 0)) + isMDPComposition = true; + + if (isMDPComposition) { + *size = 23<<20; //23MB for 7x27 + } else { + if(module != NULL) + *size = module->info.xres * module->info.yres * 2 * 2; + else + return -ENOMEM; + } #else *size = 23<<20; //23MB for 7x27 #endif