display: Use ion cookie in GPU Tonemapper
- The fd's used for book-keeping can change when the clients close and reopen sessions, hence they are not reliable and can lead to incorrect virtual address usage causing corruption or stale data. - Hence use ion cookie for book-keeping which is unique for a given memory fd. - Use LRU method free up/reuse on reaching max limit. - Remove Tonemapper_destroy which is not needed anymore. Change-Id: I5777649b34210977c18ce20c65e0aa2baa8e7d26 Crs-fixed: 1110175
This commit is contained in:
@@ -10,6 +10,7 @@ include $(BUILD_COPY_HEADERS)
|
|||||||
LOCAL_MODULE := libgpu_tonemapper
|
LOCAL_MODULE := libgpu_tonemapper
|
||||||
LOCAL_MODULE_TAGS := optional
|
LOCAL_MODULE_TAGS := optional
|
||||||
LOCAL_C_INCLUDES := $(TARGET_OUT_HEADERS)/qcom/display/
|
LOCAL_C_INCLUDES := $(TARGET_OUT_HEADERS)/qcom/display/
|
||||||
|
LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
|
||||||
|
|
||||||
LOCAL_CFLAGS := -Wno-missing-field-initializers -Wall \
|
LOCAL_CFLAGS := -Wno-missing-field-initializers -Wall \
|
||||||
-Wno-unused-parameter -std=c++11 -DLOG_TAG=\"GPU_TONEMAPPER\"
|
-Wno-unused-parameter -std=c++11 -DLOG_TAG=\"GPU_TONEMAPPER\"
|
||||||
|
|||||||
@@ -21,21 +21,101 @@
|
|||||||
#include <cutils/native_handle.h>
|
#include <cutils/native_handle.h>
|
||||||
#include <gralloc_priv.h>
|
#include <gralloc_priv.h>
|
||||||
#include <ui/GraphicBuffer.h>
|
#include <ui/GraphicBuffer.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <linux/msm_ion.h>
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
EGLImageBuffer *EGLImageWrapper::wrap(const void *pvt_handle)
|
void free_ion_cookie(int ion_fd, int cookie)
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
{
|
{
|
||||||
const private_handle_t *src = static_cast<const private_handle_t *>(pvt_handle);
|
if (ion_fd && !ioctl(ion_fd, ION_IOC_FREE, &cookie)) {
|
||||||
|
} else {
|
||||||
|
ALOGE("ION_IOC_FREE failed: ion_fd = %d, cookie = %d", ion_fd, cookie);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
int get_ion_cookie(int ion_fd, int fd)
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
{
|
||||||
|
int cookie = fd;
|
||||||
|
|
||||||
|
struct ion_fd_data fdData;
|
||||||
|
memset(&fdData, 0, sizeof(fdData));
|
||||||
|
fdData.fd = fd;
|
||||||
|
|
||||||
|
if (ion_fd && !ioctl(ion_fd, ION_IOC_IMPORT, &fdData)) {
|
||||||
|
cookie = fdData.handle;
|
||||||
|
} else {
|
||||||
|
ALOGE("ION_IOC_IMPORT failed: ion_fd = %d, fd = %d", ion_fd, fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cookie;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
EGLImageWrapper::DeleteEGLImageCallback::DeleteEGLImageCallback(int fd)
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
{
|
||||||
|
ion_fd = fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void EGLImageWrapper::DeleteEGLImageCallback::operator()(int& k, EGLImageBuffer*& eglImage)
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
{
|
||||||
|
free_ion_cookie(ion_fd, k);
|
||||||
|
if( eglImage != 0 )
|
||||||
|
{
|
||||||
|
delete eglImage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
EGLImageWrapper::EGLImageWrapper()
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
{
|
||||||
|
eglImageBufferMap = new android::LruCache<int, EGLImageBuffer*>(32);
|
||||||
|
ion_fd = open("/dev/ion", O_RDONLY);
|
||||||
|
callback = new DeleteEGLImageCallback(ion_fd);
|
||||||
|
eglImageBufferMap->setOnEntryRemovedListener(callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
EGLImageWrapper::~EGLImageWrapper()
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
{
|
||||||
|
if( eglImageBufferMap != 0 )
|
||||||
|
{
|
||||||
|
eglImageBufferMap->clear();
|
||||||
|
delete eglImageBufferMap;
|
||||||
|
eglImageBufferMap = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( callback != 0 )
|
||||||
|
{
|
||||||
|
delete callback;
|
||||||
|
callback = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( ion_fd > 0 )
|
||||||
|
{
|
||||||
|
close(ion_fd);
|
||||||
|
}
|
||||||
|
ion_fd = -1;
|
||||||
|
}
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
static EGLImageBuffer* L_wrap(const private_handle_t *src)
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
{
|
||||||
|
EGLImageBuffer* result = 0;
|
||||||
|
|
||||||
EGLImageBuffer *result = 0;
|
|
||||||
std::map<int, EGLImageBuffer *>::iterator it = eglImageBufferMap.find(src->fd);
|
|
||||||
if (it == eglImageBufferMap.end()) {
|
|
||||||
native_handle_t *native_handle = const_cast<private_handle_t *>(src);
|
native_handle_t *native_handle = const_cast<private_handle_t *>(src);
|
||||||
|
|
||||||
int flags = android::GraphicBuffer::USAGE_HW_TEXTURE |
|
int flags = android::GraphicBuffer::USAGE_HW_TEXTURE |
|
||||||
android::GraphicBuffer::USAGE_SW_READ_NEVER |
|
android::GraphicBuffer::USAGE_SW_READ_NEVER |
|
||||||
android::GraphicBuffer::USAGE_SW_WRITE_NEVER;
|
android::GraphicBuffer::USAGE_SW_WRITE_NEVER;
|
||||||
|
|
||||||
if (src->flags & private_handle_t::PRIV_FLAGS_SECURE_BUFFER) {
|
if (src->flags & private_handle_t::PRIV_FLAGS_SECURE_BUFFER) {
|
||||||
flags |= android::GraphicBuffer::USAGE_PROTECTED;
|
flags |= android::GraphicBuffer::USAGE_PROTECTED;
|
||||||
}
|
}
|
||||||
@@ -46,21 +126,25 @@ EGLImageBuffer *EGLImageWrapper::wrap(const void *pvt_handle)
|
|||||||
|
|
||||||
result = new EGLImageBuffer(graphicBuffer);
|
result = new EGLImageBuffer(graphicBuffer);
|
||||||
|
|
||||||
eglImageBufferMap[src->fd] = result;
|
return result;
|
||||||
} else {
|
|
||||||
result = it->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void EGLImageWrapper::destroy()
|
EGLImageBuffer *EGLImageWrapper::wrap(const void *pvt_handle)
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
{
|
{
|
||||||
std::map<int, EGLImageBuffer *>::iterator it = eglImageBufferMap.begin();
|
const private_handle_t *src = static_cast<const private_handle_t *>(pvt_handle);
|
||||||
for (; it != eglImageBufferMap.end(); it++) {
|
|
||||||
delete it->second;
|
int ion_cookie = get_ion_cookie(ion_fd, src->fd);
|
||||||
}
|
EGLImageBuffer* eglImage = eglImageBufferMap->get(ion_cookie);
|
||||||
eglImageBufferMap.clear();
|
if( eglImage == 0 )
|
||||||
|
{
|
||||||
|
eglImage = L_wrap(src);
|
||||||
|
eglImageBufferMap->put(ion_cookie, eglImage);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
free_ion_cookie(ion_fd, ion_cookie);
|
||||||
|
}
|
||||||
|
|
||||||
|
return eglImage;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,15 +20,28 @@
|
|||||||
#ifndef __TONEMAPPER_EGLIMAGEWRAPPER_H__
|
#ifndef __TONEMAPPER_EGLIMAGEWRAPPER_H__
|
||||||
#define __TONEMAPPER_EGLIMAGEWRAPPER_H__
|
#define __TONEMAPPER_EGLIMAGEWRAPPER_H__
|
||||||
|
|
||||||
#include <map>
|
#include <utils/LruCache.h>
|
||||||
#include "EGLImageBuffer.h"
|
#include "EGLImageBuffer.h"
|
||||||
|
|
||||||
class EGLImageWrapper {
|
class EGLImageWrapper {
|
||||||
std::map<int, EGLImageBuffer *> eglImageBufferMap;
|
private:
|
||||||
|
class DeleteEGLImageCallback : public android::OnEntryRemoved<int, EGLImageBuffer*>
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
int ion_fd;
|
||||||
|
public:
|
||||||
|
DeleteEGLImageCallback(int ion_fd);
|
||||||
|
void operator()(int& ion_cookie, EGLImageBuffer*& eglImage);
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
android::LruCache<int, EGLImageBuffer *>* eglImageBufferMap;
|
||||||
EGLImageBuffer *wrap(const void *pvt_handle);
|
DeleteEGLImageCallback* callback;
|
||||||
void destroy();
|
int ion_fd;
|
||||||
|
|
||||||
|
public:
|
||||||
|
EGLImageWrapper();
|
||||||
|
~EGLImageWrapper();
|
||||||
|
EGLImageBuffer* wrap(const void *pvt_handle);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //__TONEMAPPER_EGLIMAGEWRAPPER_H__
|
#endif //__TONEMAPPER_EGLIMAGEWRAPPER_H__
|
||||||
|
|||||||
@@ -32,9 +32,3 @@ Tonemapper *TonemapperFactory_GetInstance(int type, void *colorMap, int colorMap
|
|||||||
|
|
||||||
return tonemapper;
|
return tonemapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------
|
|
||||||
void TonemapperFactory_Destroy()
|
|
||||||
//------------------------------------------
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -30,9 +30,6 @@ extern "C" {
|
|||||||
Tonemapper *TonemapperFactory_GetInstance(int type, void *colorMap, int colorMapSize,
|
Tonemapper *TonemapperFactory_GetInstance(int type, void *colorMap, int colorMapSize,
|
||||||
void *lutXform, int lutXformSize);
|
void *lutXform, int lutXformSize);
|
||||||
|
|
||||||
// destroy tonemap session
|
|
||||||
void TonemapperFactory_Destroy();
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ Tonemapper::~Tonemapper()
|
|||||||
|
|
||||||
// clear EGLImage mappings
|
// clear EGLImage mappings
|
||||||
if (eglImageWrapper != 0) {
|
if (eglImageWrapper != 0) {
|
||||||
eglImageWrapper->destroy();
|
|
||||||
delete eglImageWrapper;
|
delete eglImageWrapper;
|
||||||
eglImageWrapper = 0;
|
eglImageWrapper = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -223,7 +223,6 @@ void HWCToneMapper::Terminate() {
|
|||||||
delete tone_map_sessions_.back();
|
delete tone_map_sessions_.back();
|
||||||
tone_map_sessions_.pop_back();
|
tone_map_sessions_.pop_back();
|
||||||
}
|
}
|
||||||
TonemapperFactory_Destroy();
|
|
||||||
fb_session_index_ = 0;
|
fb_session_index_ = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user