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