display: Clean up gralloc
* Remove pmem and ashmem implementations * Remove usage of RefBase * Reduce log verbosity Change-Id: If8ef543d236e5305bd5430f4f9c62c51b3a13787
This commit is contained in:
committed by
Brian Muramatsu
parent
0c8b7b5c84
commit
01d3fd3318
@@ -28,30 +28,16 @@
|
||||
*/
|
||||
|
||||
#include <cutils/log.h>
|
||||
#include <utils/RefBase.h>
|
||||
#include <fcntl.h>
|
||||
#include "gralloc_priv.h"
|
||||
#include "alloc_controller.h"
|
||||
#include "memalloc.h"
|
||||
#include "ionalloc.h"
|
||||
#include "pmemalloc.h"
|
||||
#include "ashmemalloc.h"
|
||||
#include "gr.h"
|
||||
#include "comptype.h"
|
||||
|
||||
using namespace gralloc;
|
||||
using namespace qdutils;
|
||||
using android::sp;
|
||||
|
||||
const int GRALLOC_HEAP_MASK = GRALLOC_USAGE_PRIVATE_ADSP_HEAP |
|
||||
GRALLOC_USAGE_PRIVATE_UI_CONTIG_HEAP |
|
||||
GRALLOC_USAGE_PRIVATE_SMI_HEAP |
|
||||
GRALLOC_USAGE_PRIVATE_SYSTEM_HEAP |
|
||||
GRALLOC_USAGE_PRIVATE_IOMMU_HEAP |
|
||||
GRALLOC_USAGE_PRIVATE_MM_HEAP |
|
||||
GRALLOC_USAGE_PRIVATE_WRITEBACK_HEAP |
|
||||
GRALLOC_USAGE_PRIVATE_CAMERA_HEAP;
|
||||
|
||||
|
||||
//Common functions
|
||||
static bool canFallback(int usage, bool triedSystem)
|
||||
@@ -88,18 +74,11 @@ static bool useUncached(int usage)
|
||||
return false;
|
||||
}
|
||||
|
||||
sp<IAllocController> IAllocController::sController = NULL;
|
||||
sp<IAllocController> IAllocController::getInstance(bool useMasterHeap)
|
||||
IAllocController* IAllocController::sController = NULL;
|
||||
IAllocController* IAllocController::getInstance(void)
|
||||
{
|
||||
if(sController == NULL) {
|
||||
#ifdef USE_ION
|
||||
sController = new IonController();
|
||||
#else
|
||||
if(useMasterHeap)
|
||||
sController = new PmemAshmemController();
|
||||
else
|
||||
sController = new PmemKernelController();
|
||||
#endif
|
||||
}
|
||||
return sController;
|
||||
}
|
||||
@@ -111,8 +90,7 @@ IonController::IonController()
|
||||
mIonAlloc = new IonAlloc();
|
||||
}
|
||||
|
||||
int IonController::allocate(alloc_data& data, int usage,
|
||||
int compositionType)
|
||||
int IonController::allocate(alloc_data& data, int usage)
|
||||
{
|
||||
int ionFlags = 0;
|
||||
int ret;
|
||||
@@ -135,20 +113,12 @@ int IonController::allocate(alloc_data& data, int usage,
|
||||
if(usage & GRALLOC_USAGE_PRIVATE_MM_HEAP)
|
||||
ionFlags |= ION_HEAP(ION_CP_MM_HEAP_ID);
|
||||
|
||||
if(usage & GRALLOC_USAGE_PRIVATE_WRITEBACK_HEAP)
|
||||
ionFlags |= ION_HEAP(ION_CP_WB_HEAP_ID);
|
||||
|
||||
if(usage & GRALLOC_USAGE_PRIVATE_CAMERA_HEAP)
|
||||
ionFlags |= ION_HEAP(ION_CAMERA_HEAP_ID);
|
||||
|
||||
if(usage & GRALLOC_USAGE_PRIVATE_CP_BUFFER)
|
||||
ionFlags |= ION_SECURE;
|
||||
|
||||
if(usage & GRALLOC_USAGE_PRIVATE_DO_NOT_MAP)
|
||||
data.allocType |= private_handle_t::PRIV_FLAGS_NOT_MAPPED;
|
||||
else
|
||||
data.allocType &= ~(private_handle_t::PRIV_FLAGS_NOT_MAPPED);
|
||||
|
||||
// if no flags are set, default to
|
||||
// SF + IOMMU heaps, so that bypass can work
|
||||
// we can fall back to system heap if
|
||||
@@ -180,9 +150,9 @@ int IonController::allocate(alloc_data& data, int usage,
|
||||
return ret;
|
||||
}
|
||||
|
||||
sp<IMemAlloc> IonController::getAllocator(int flags)
|
||||
IMemAlloc* IonController::getAllocator(int flags)
|
||||
{
|
||||
sp<IMemAlloc> memalloc;
|
||||
IMemAlloc* memalloc;
|
||||
if (flags & private_handle_t::PRIV_FLAGS_USES_ION) {
|
||||
memalloc = mIonAlloc;
|
||||
} else {
|
||||
@@ -192,151 +162,6 @@ sp<IMemAlloc> IonController::getAllocator(int flags)
|
||||
return memalloc;
|
||||
}
|
||||
|
||||
//-------------- PmemKernelController-----------------------//
|
||||
//XXX: Remove - we're not using pmem anymore
|
||||
#if 0
|
||||
PmemKernelController::PmemKernelController()
|
||||
{
|
||||
mPmemAdspAlloc = new PmemKernelAlloc(DEVICE_PMEM_ADSP);
|
||||
// XXX: Right now, there is no need to maintain an instance
|
||||
// of the SMI allocator as we need it only in a few cases
|
||||
}
|
||||
|
||||
PmemKernelController::~PmemKernelController()
|
||||
{
|
||||
}
|
||||
|
||||
int PmemKernelController::allocate(alloc_data& data, int usage,
|
||||
int compositionType)
|
||||
{
|
||||
int ret = 0;
|
||||
bool adspFallback = false;
|
||||
if (!(usage & GRALLOC_USAGE_PRIVATE_SMI_HEAP))
|
||||
adspFallback = true;
|
||||
|
||||
// Try SMI first
|
||||
if ((usage & GRALLOC_USAGE_PRIVATE_SMI_HEAP) ||
|
||||
(usage & GRALLOC_USAGE_EXTERNAL_DISP) ||
|
||||
(usage & GRALLOC_USAGE_PROTECTED))
|
||||
{
|
||||
int tempFd = open(DEVICE_PMEM_SMIPOOL, O_RDWR, 0);
|
||||
if(tempFd > 0) {
|
||||
close(tempFd);
|
||||
sp<IMemAlloc> memalloc;
|
||||
memalloc = new PmemKernelAlloc(DEVICE_PMEM_SMIPOOL);
|
||||
ret = memalloc->alloc_buffer(data);
|
||||
if(ret >= 0)
|
||||
return ret;
|
||||
else {
|
||||
if(adspFallback)
|
||||
ALOGW("Allocation from SMI failed, trying ADSP");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((usage & GRALLOC_USAGE_PRIVATE_ADSP_HEAP) || adspFallback) {
|
||||
ret = mPmemAdspAlloc->alloc_buffer(data);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
sp<IMemAlloc> PmemKernelController::getAllocator(int flags)
|
||||
{
|
||||
sp<IMemAlloc> memalloc;
|
||||
if (flags & private_handle_t::PRIV_FLAGS_USES_PMEM_ADSP)
|
||||
memalloc = mPmemAdspAlloc;
|
||||
else {
|
||||
ALOGE("%s: Invalid flags passed: 0x%x", __FUNCTION__, flags);
|
||||
memalloc = NULL;
|
||||
}
|
||||
|
||||
return memalloc;
|
||||
}
|
||||
|
||||
//-------------- PmemAshmmemController-----------------------//
|
||||
|
||||
PmemAshmemController::PmemAshmemController()
|
||||
{
|
||||
mPmemUserspaceAlloc = new PmemUserspaceAlloc();
|
||||
mAshmemAlloc = new AshmemAlloc();
|
||||
mPmemKernelCtrl = new PmemKernelController();
|
||||
}
|
||||
|
||||
PmemAshmemController::~PmemAshmemController()
|
||||
{
|
||||
}
|
||||
|
||||
int PmemAshmemController::allocate(alloc_data& data, int usage,
|
||||
int compositionType)
|
||||
{
|
||||
int ret = 0;
|
||||
data.allocType = 0;
|
||||
|
||||
// Make buffers cacheable by default
|
||||
data.uncached = false;
|
||||
|
||||
// Override if we explicitly need uncached buffers
|
||||
if (usage & GRALLOC_USAGE_PRIVATE_UNCACHED)
|
||||
data.uncached = true;
|
||||
|
||||
// If ADSP or SMI is requested use the kernel controller
|
||||
if(usage & (GRALLOC_USAGE_PRIVATE_ADSP_HEAP|
|
||||
GRALLOC_USAGE_PRIVATE_SMI_HEAP)) {
|
||||
ret = mPmemKernelCtrl->allocate(data, usage, compositionType);
|
||||
if(ret < 0)
|
||||
ALOGE("%s: Failed to allocate ADSP/SMI memory", __func__);
|
||||
else
|
||||
data.allocType = private_handle_t::PRIV_FLAGS_USES_PMEM_ADSP;
|
||||
return ret;
|
||||
}
|
||||
|
||||
if(usage & GRALLOC_USAGE_PRIVATE_SYSTEM_HEAP) {
|
||||
ret = mAshmemAlloc->alloc_buffer(data);
|
||||
if(ret >= 0) {
|
||||
data.allocType = private_handle_t::PRIV_FLAGS_USES_ASHMEM;
|
||||
data.allocType |= private_handle_t::PRIV_FLAGS_NONCONTIGUOUS_MEM;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// if no memory specific flags are set,
|
||||
// default to EBI heap, so that bypass
|
||||
// can work. We can fall back to system
|
||||
// heap if we run out.
|
||||
ret = mPmemUserspaceAlloc->alloc_buffer(data);
|
||||
|
||||
// Fallback
|
||||
if(ret >= 0 ) {
|
||||
data.allocType = private_handle_t::PRIV_FLAGS_USES_PMEM;
|
||||
} else if(ret < 0 && canFallback(usage, false)) {
|
||||
ALOGW("Falling back to ashmem");
|
||||
ret = mAshmemAlloc->alloc_buffer(data);
|
||||
if(ret >= 0) {
|
||||
data.allocType = private_handle_t::PRIV_FLAGS_USES_ASHMEM;
|
||||
data.allocType |= private_handle_t::PRIV_FLAGS_NONCONTIGUOUS_MEM;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
sp<IMemAlloc> PmemAshmemController::getAllocator(int flags)
|
||||
{
|
||||
sp<IMemAlloc> memalloc;
|
||||
if (flags & private_handle_t::PRIV_FLAGS_USES_PMEM)
|
||||
memalloc = mPmemUserspaceAlloc;
|
||||
else if (flags & private_handle_t::PRIV_FLAGS_USES_PMEM_ADSP)
|
||||
memalloc = mPmemKernelCtrl->getAllocator(flags);
|
||||
else if (flags & private_handle_t::PRIV_FLAGS_USES_ASHMEM)
|
||||
memalloc = mAshmemAlloc;
|
||||
else {
|
||||
ALOGE("%s: Invalid flags passed: 0x%x", __FUNCTION__, flags);
|
||||
memalloc = NULL;
|
||||
}
|
||||
|
||||
return memalloc;
|
||||
}
|
||||
#endif
|
||||
size_t getBufferSizeAndDimensions(int width, int height, int format,
|
||||
int& alignedw, int &alignedh)
|
||||
{
|
||||
@@ -417,8 +242,8 @@ int alloc_buffer(private_handle_t **pHnd, int w, int h, int format, int usage)
|
||||
{
|
||||
alloc_data data;
|
||||
int alignedw, alignedh;
|
||||
android::sp<gralloc::IAllocController> sAlloc =
|
||||
gralloc::IAllocController::getInstance(false);
|
||||
gralloc::IAllocController* sAlloc =
|
||||
gralloc::IAllocController::getInstance();
|
||||
data.base = 0;
|
||||
data.fd = -1;
|
||||
data.offset = 0;
|
||||
@@ -427,14 +252,15 @@ int alloc_buffer(private_handle_t **pHnd, int w, int h, int format, int usage)
|
||||
data.uncached = useUncached(usage);
|
||||
int allocFlags = usage;
|
||||
|
||||
int err = sAlloc->allocate(data, allocFlags, 0);
|
||||
int err = sAlloc->allocate(data, allocFlags);
|
||||
if (0 != err) {
|
||||
ALOGE("%s: allocate failed", __FUNCTION__);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
private_handle_t* hnd = new private_handle_t(data.fd, data.size,
|
||||
data.allocType, 0, format, alignedw, alignedh);
|
||||
data.allocType, 0, format,
|
||||
alignedw, alignedh);
|
||||
hnd->base = (int) data.base;
|
||||
hnd->offset = data.offset;
|
||||
hnd->gpuaddr = 0;
|
||||
@@ -444,10 +270,10 @@ int alloc_buffer(private_handle_t **pHnd, int w, int h, int format, int usage)
|
||||
|
||||
void free_buffer(private_handle_t *hnd)
|
||||
{
|
||||
android::sp<gralloc::IAllocController> sAlloc =
|
||||
gralloc::IAllocController::getInstance(false);
|
||||
gralloc::IAllocController* sAlloc =
|
||||
gralloc::IAllocController::getInstance();
|
||||
if (hnd && hnd->fd > 0) {
|
||||
sp<IMemAlloc> memalloc = sAlloc->getAllocator(hnd->flags);
|
||||
IMemAlloc* memalloc = sAlloc->getAllocator(hnd->flags);
|
||||
memalloc->free_buffer((void*)hnd->base, hnd->size, hnd->offset, hnd->fd);
|
||||
}
|
||||
if(hnd)
|
||||
|
||||
Reference in New Issue
Block a user