From d8abd6c8dc9f00fbed877069da1a430af25e8452 Mon Sep 17 00:00:00 2001 From: "Arun Kumar K.R" Date: Mon, 16 Apr 2012 16:56:12 -0700 Subject: [PATCH] liboverlay: free rotator memory in a new function - move freeing roator memory to a new function - In queueBuffer, updateDataChannel, if memory allocation fails for the rotator, free the previous allocated memory CRs-fixed: 353156 (cherry picked from commit 97de5b6dc39a8706ba90f4e8b191b18418cb0191) Change-Id: Icc774b67678426ea7ba43520b1186ea148ce1281 --- liboverlay/overlayLib.cpp | 39 +++++++++++++++++++++++---------------- liboverlay/overlayLib.h | 1 + 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/liboverlay/overlayLib.cpp b/liboverlay/overlayLib.cpp index 3d1c859..ba98e23 100755 --- a/liboverlay/overlayLib.cpp +++ b/liboverlay/overlayLib.cpp @@ -1841,7 +1841,8 @@ bool OverlayDataChannel::mapRotatorMemory(int num_buffers, bool uiChannel, int r //XXX: getInstance(false) implies that it should only // use the kernel allocator. Change it to something // more descriptive later. - android::sp allocController = gralloc::IAllocController::getInstance(false); + android::sp allocController = + gralloc::IAllocController::getInstance(false); int err = allocController->allocate(data, allocFlags, 0); if(err) { reportError("Cant allocate rotatory memory"); @@ -1899,12 +1900,7 @@ bool OverlayDataChannel::closeDataChannel() { return true; if (!mNoRot && mRotFD > 0) { - //XXX: getInstance(false) implies that it should only - // use the kernel allocator. Change it to something - // more descriptive later. - android::sp allocController = gralloc::IAllocController::getInstance(false); - sp memalloc = allocController->getAllocator(mBufferType); - memalloc->free_buffer(mPmemAddr, mPmemOffset * mNumBuffers, 0, mPmemFD); + freeRotatorMemory(mPmemAddr, mPmemOffset, mPmemFD); close(mPmemFD); mPmemFD = -1; close(mRotFD); @@ -1922,6 +1918,23 @@ bool OverlayDataChannel::closeDataChannel() { return true; } +bool OverlayDataChannel::freeRotatorMemory(void* pmemAddr, uint32_t + pmemOffset, int pmemFD) { + bool ret = true; + if(pmemFD != -1 && pmemAddr != MAP_FAILED) { + //XXX: getInstance(false) implies that it should only + // use the kernel allocator. Change it to something + // more descriptive later. + android::sp allocController = + gralloc::IAllocController::getInstance(false); + sp memalloc = allocController->getAllocator(mBufferType); + memalloc->free_buffer(pmemAddr, pmemOffset * mNumBuffers, 0, pmemFD); + } + else + ret = false; + return ret; +} + bool OverlayDataChannel::setFd(int fd) { mOvData.data.memory_id = fd; return true; @@ -1948,6 +1961,8 @@ bool OverlayDataChannel::queueBuffer(uint32_t offset) { result = mapRotatorMemory(mNumBuffers, 0, UPDATE_REQUEST); if (!result) { LOGE("queueBuffer: mapRotatorMemory failed"); + // free the oldPmemAddr if any + freeRotatorMemory(oldPmemAddr, oldPmemOffset, oldPmemFD); return false; } mUpdateDataChannel = false; @@ -1957,15 +1972,7 @@ bool OverlayDataChannel::queueBuffer(uint32_t offset) { result = queue(offset); // Unmap the old PMEM memory after the queueBuffer has returned - if (oldPmemFD != -1 && oldPmemAddr != MAP_FAILED) { - //XXX: getInstance(false) implies that it should only - // use the kernel allocator. Change it to something - // more descriptive later. - android::sp allocController = gralloc::IAllocController::getInstance(false); - sp memalloc = allocController->getAllocator(mBufferType); - memalloc->free_buffer(oldPmemAddr, oldPmemOffset * mNumBuffers, 0, oldPmemFD); - oldPmemFD = -1; - } + freeRotatorMemory(oldPmemAddr, oldPmemOffset, oldPmemFD); return result; } diff --git a/liboverlay/overlayLib.h b/liboverlay/overlayLib.h index e55a6a8..639d584 100755 --- a/liboverlay/overlayLib.h +++ b/liboverlay/overlayLib.h @@ -367,6 +367,7 @@ class OverlayDataChannel { bool openDevices(int fbnum = -1, bool uichannel = false, int num_buffers = 2); bool mapRotatorMemory(int num_buffers, bool uiChannel, int requestType); bool queue(uint32_t offset); + bool freeRotatorMemory(void *pmemAddr, uint32_t pmemOffset, int pmemFD); public: OverlayDataChannel();