From e09fd9e819c23dc90bca68375645e15544861330 Mon Sep 17 00:00:00 2001 From: The Android Open Source Project Date: Wed, 17 Dec 2008 18:05:43 -0800 Subject: Code drop from //branches/cupcake/...@124589 --- libs/surfaceflinger/VRamHeap.cpp | 81 ++++++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 32 deletions(-) (limited to 'libs/surfaceflinger/VRamHeap.cpp') diff --git a/libs/surfaceflinger/VRamHeap.cpp b/libs/surfaceflinger/VRamHeap.cpp index 3852d51954..77bc5766be 100644 --- a/libs/surfaceflinger/VRamHeap.cpp +++ b/libs/surfaceflinger/VRamHeap.cpp @@ -37,6 +37,8 @@ #include +#include "GPUHardware/GPUHardware.h" +#include "SurfaceFlinger.h" #include "VRamHeap.h" #if HAVE_ANDROID_OS @@ -59,8 +61,9 @@ int SurfaceHeapManager::global_pmem_heap = 0; // --------------------------------------------------------------------------- -SurfaceHeapManager::SurfaceHeapManager(size_t clientHeapSize) - : mClientHeapSize(clientHeapSize) +SurfaceHeapManager::SurfaceHeapManager(const sp& flinger, + size_t clientHeapSize) + : mFlinger(flinger), mClientHeapSize(clientHeapSize) { SurfaceHeapManager::global_pmem_heap = 1; } @@ -81,25 +84,53 @@ void SurfaceHeapManager::onFirstRef() } } -sp SurfaceHeapManager::createHeap(int type) +sp SurfaceHeapManager::createHeap( + uint32_t flags, + pid_t client_pid, + const sp& defaultAllocator) { - if (!global_pmem_heap && type==NATIVE_MEMORY_TYPE_PMEM) - type = NATIVE_MEMORY_TYPE_HEAP; - - const sp& heap(mPMemHeap); sp dealer; - switch (type) { - case NATIVE_MEMORY_TYPE_HEAP: - dealer = new MemoryDealer(mClientHeapSize, 0, "SFNativeHeap"); - break; - case NATIVE_MEMORY_TYPE_PMEM: - if (heap != 0) { - dealer = new MemoryDealer( - heap->createClientHeap(), - heap->getAllocator()); + if (flags & ISurfaceComposer::eGPU) { + // don't grant GPU memory if GPU is disabled + char value[PROPERTY_VALUE_MAX]; + property_get("debug.egl.hw", value, "1"); + if (atoi(value) == 0) { + flags &= ~ISurfaceComposer::eGPU; + } + } + + if (flags & ISurfaceComposer::eGPU) { + // FIXME: this is msm7201A specific, where gpu surfaces may not be secure + if (!(flags & ISurfaceComposer::eSecure)) { + // if GPU doesn't work, we try eHardware + flags |= ISurfaceComposer::eHardware; + // asked for GPU memory, try that first + dealer = mFlinger->getGPU()->request(client_pid); + } + } + + if (dealer == NULL) { + if (defaultAllocator != NULL) + // if a default allocator is given, use that + dealer = defaultAllocator; + } + + if (dealer == NULL) { + // always try h/w accelerated memory first + if (global_pmem_heap) { + const sp& heap(mPMemHeap); + if (dealer == NULL && heap != NULL) { + dealer = new MemoryDealer( + heap->createClientHeap(), + heap->getAllocator()); + } } - break; + } + + if (dealer == NULL) { + // return the ashmem allocator (software rendering) + dealer = new MemoryDealer(mClientHeapSize, 0, "SFNativeHeap"); } return dealer; } @@ -122,22 +153,8 @@ sp SurfaceHeapManager::getAllocator(int type) const // --------------------------------------------------------------------------- -PMemHeapInterface::PMemHeapInterface(int fd, size_t size) - : MemoryHeapBase(fd, size) { -} -PMemHeapInterface::PMemHeapInterface(const char* device, size_t size) - : MemoryHeapBase(device, size) { -} -PMemHeapInterface::PMemHeapInterface(size_t size, uint32_t flags, char const * name) - : MemoryHeapBase(size, flags, name) { -} -PMemHeapInterface::~PMemHeapInterface() { -} - -// --------------------------------------------------------------------------- - PMemHeap::PMemHeap(const char* const device, size_t size, size_t reserved) - : PMemHeapInterface(device, size) + : MemoryHeapBase(device, size) { //LOGD("%s, %p, mFD=%d", __PRETTY_FUNCTION__, this, heapID()); if (base() != MAP_FAILED) { -- cgit v1.2.3-59-g8ed1b