diff options
author | Linux Build Service Account <lnxbuild@localhost> | 2017-02-05 18:41:27 -0800 |
---|---|---|
committer | Gerrit - the friendly Code Review server <code-review@localhost> | 2017-02-05 18:41:26 -0800 |
commit | 8ab97573ab3139bb97e5bd4fddba8a3c7648ef85 (patch) | |
tree | 3961ec9397d61c7162b407bb2efc2a720b489b80 | |
parent | 40d2710a221b3780ca0c10762af8836123860593 (diff) | |
parent | 4a8b118e2bea9e46d07deaabcfc8f9ccd0ef8d17 (diff) | |
download | display-8ab97573ab3139bb97e5bd4fddba8a3c7648ef85.tar.gz |
Merge "display: Use ion cookie in GPU Tonemapper"
-rw-r--r-- | gpu_tonemapper/Android.mk | 1 | ||||
-rw-r--r-- | gpu_tonemapper/EGLImageWrapper.cpp | 118 | ||||
-rw-r--r-- | gpu_tonemapper/EGLImageWrapper.h | 23 | ||||
-rw-r--r-- | gpu_tonemapper/TonemapFactory.cpp | 11 | ||||
-rw-r--r-- | gpu_tonemapper/TonemapFactory.h | 3 | ||||
-rw-r--r-- | gpu_tonemapper/Tonemapper.cpp | 13 | ||||
-rw-r--r-- | gpu_tonemapper/Tonemapper.h | 2 | ||||
-rw-r--r-- | gpu_tonemapper/engine.h | 10 | ||||
-rw-r--r-- | gpu_tonemapper/glengine.cpp | 79 | ||||
-rw-r--r-- | sdm/libs/hwc/hwc_tonemapper.cpp | 1 |
10 files changed, 177 insertions, 84 deletions
diff --git a/gpu_tonemapper/Android.mk b/gpu_tonemapper/Android.mk index 4f716d24..5d1f9a97 100644 --- a/gpu_tonemapper/Android.mk +++ b/gpu_tonemapper/Android.mk @@ -10,6 +10,7 @@ include $(BUILD_COPY_HEADERS) LOCAL_MODULE := libgpu_tonemapper LOCAL_MODULE_TAGS := optional LOCAL_C_INCLUDES := $(TARGET_OUT_HEADERS)/qcom/display/ +LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include LOCAL_CFLAGS := $(version_flag) -Wno-missing-field-initializers -Wall \ -Wno-unused-parameter -std=c++11 -DLOG_TAG=\"GPU_TONEMAPPER\" diff --git a/gpu_tonemapper/EGLImageWrapper.cpp b/gpu_tonemapper/EGLImageWrapper.cpp index 1d5d57ee..84f43439 100644 --- a/gpu_tonemapper/EGLImageWrapper.cpp +++ b/gpu_tonemapper/EGLImageWrapper.cpp @@ -21,21 +21,101 @@ #include <cutils/native_handle.h> #include <gralloc_priv.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) +//----------------------------------------------------------------------------- +{ + 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) //----------------------------------------------------------------------------- { - const private_handle_t *src = static_cast<const private_handle_t *>(pvt_handle); + 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); int flags = android::GraphicBuffer::USAGE_HW_TEXTURE | android::GraphicBuffer::USAGE_SW_READ_NEVER | android::GraphicBuffer::USAGE_SW_WRITE_NEVER; + if (src->flags & private_handle_t::PRIV_FLAGS_SECURE_BUFFER) { flags |= android::GraphicBuffer::USAGE_PROTECTED; } @@ -50,21 +130,25 @@ EGLImageBuffer *EGLImageWrapper::wrap(const void *pvt_handle) result = new EGLImageBuffer(graphicBuffer); - eglImageBufferMap[src->fd] = result; - } else { - result = it->second; - } - - return result; + return result; } //----------------------------------------------------------------------------- -void EGLImageWrapper::destroy() +EGLImageBuffer *EGLImageWrapper::wrap(const void *pvt_handle) //----------------------------------------------------------------------------- { - std::map<int, EGLImageBuffer *>::iterator it = eglImageBufferMap.begin(); - for (; it != eglImageBufferMap.end(); it++) { - delete it->second; - } - eglImageBufferMap.clear(); + const private_handle_t *src = static_cast<const private_handle_t *>(pvt_handle); + + int ion_cookie = get_ion_cookie(ion_fd, src->fd); + EGLImageBuffer* eglImage = eglImageBufferMap->get(ion_cookie); + if( eglImage == 0 ) + { + eglImage = L_wrap(src); + eglImageBufferMap->put(ion_cookie, eglImage); + } + else { + free_ion_cookie(ion_fd, ion_cookie); + } + + return eglImage; } diff --git a/gpu_tonemapper/EGLImageWrapper.h b/gpu_tonemapper/EGLImageWrapper.h index 90aaf583..e9a4d68f 100644 --- a/gpu_tonemapper/EGLImageWrapper.h +++ b/gpu_tonemapper/EGLImageWrapper.h @@ -20,15 +20,28 @@ #ifndef __TONEMAPPER_EGLIMAGEWRAPPER_H__ #define __TONEMAPPER_EGLIMAGEWRAPPER_H__ -#include <map> +#include <utils/LruCache.h> #include "EGLImageBuffer.h" 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: - EGLImageBuffer *wrap(const void *pvt_handle); - void destroy(); + android::LruCache<int, EGLImageBuffer *>* eglImageBufferMap; + DeleteEGLImageCallback* callback; + int ion_fd; + + public: + EGLImageWrapper(); + ~EGLImageWrapper(); + EGLImageBuffer* wrap(const void *pvt_handle); }; #endif //__TONEMAPPER_EGLIMAGEWRAPPER_H__ diff --git a/gpu_tonemapper/TonemapFactory.cpp b/gpu_tonemapper/TonemapFactory.cpp index cffc33a0..5aae6979 100644 --- a/gpu_tonemapper/TonemapFactory.cpp +++ b/gpu_tonemapper/TonemapFactory.cpp @@ -27,19 +27,8 @@ Tonemapper *TonemapperFactory_GetInstance(int type, void *colorMap, int colorMap void *lutXform, int lutXformSize) //---------------------------------------------------------------------------------------------------------------------------------------------------------- { - // initializes the engine - does nothing if already initialized - engine_initialize(); - // build the tonemapper Tonemapper *tonemapper = Tonemapper::build(type, colorMap, colorMapSize, lutXform, lutXformSize); return tonemapper; } - -//------------------------------------------ -void TonemapperFactory_Destroy() -//------------------------------------------ -{ - // shutdown the engine - engine_shutdown(); -} diff --git a/gpu_tonemapper/TonemapFactory.h b/gpu_tonemapper/TonemapFactory.h index 10041705..404f4cda 100644 --- a/gpu_tonemapper/TonemapFactory.h +++ b/gpu_tonemapper/TonemapFactory.h @@ -30,9 +30,6 @@ extern "C" { Tonemapper *TonemapperFactory_GetInstance(int type, void *colorMap, int colorMapSize, void *lutXform, int lutXformSize); -// destroy tonemap session -void TonemapperFactory_Destroy(); - #ifdef __cplusplus } #endif diff --git a/gpu_tonemapper/Tonemapper.cpp b/gpu_tonemapper/Tonemapper.cpp index bb7ba1b7..ec74b801 100644 --- a/gpu_tonemapper/Tonemapper.cpp +++ b/gpu_tonemapper/Tonemapper.cpp @@ -39,17 +39,18 @@ Tonemapper::Tonemapper() Tonemapper::~Tonemapper() //----------------------------------------------------------------------------- { - engine_bind(); + engine_bind(engineContext); engine_deleteInputBuffer(tonemapTexture); engine_deleteInputBuffer(lutXformTexture); engine_deleteProgram(programID); // clear EGLImage mappings if (eglImageWrapper != 0) { - eglImageWrapper->destroy(); delete eglImageWrapper; eglImageWrapper = 0; } + + engine_shutdown(engineContext); } //----------------------------------------------------------------------------- @@ -61,10 +62,14 @@ Tonemapper *Tonemapper::build(int type, void *colorMap, int colorMapSize, void * ALOGE("Invalid Color Map size = %d", colorMapSize); return NULL; } - engine_bind(); // build new tonemapper Tonemapper *tonemapper = new Tonemapper(); + + tonemapper->engineContext = engine_initialize(); + + engine_bind(tonemapper->engineContext); + // load the 3d lut tonemapper->tonemapTexture = engine_load3DTexture(colorMap, colorMapSize, 0); // load the non-uniform xform @@ -101,7 +106,7 @@ int Tonemapper::blit(const void *dst, const void *src, int srcFenceFd) //----------------------------------------------------------------------------- { // make current - engine_bind(); + engine_bind(engineContext); // create eglimages if required EGLImageBuffer *dst_buffer = eglImageWrapper->wrap(dst); diff --git a/gpu_tonemapper/Tonemapper.h b/gpu_tonemapper/Tonemapper.h index 0f9bd513..1d6f8080 100644 --- a/gpu_tonemapper/Tonemapper.h +++ b/gpu_tonemapper/Tonemapper.h @@ -24,9 +24,11 @@ #define TONEMAP_INVERSE 1 #include "EGLImageWrapper.h" +#include "engine.h" class Tonemapper { private: + void* engineContext; unsigned int tonemapTexture; unsigned int lutXformTexture; unsigned int programID; diff --git a/gpu_tonemapper/engine.h b/gpu_tonemapper/engine.h index 5635ee39..ca914b27 100644 --- a/gpu_tonemapper/engine.h +++ b/gpu_tonemapper/engine.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, The Linux Foundation. All rights reserved. + * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. * Not a Contribution. * * Copyright 2015 The Android Open Source Project @@ -20,9 +20,9 @@ #ifndef __TONEMAPPER_ENGINE_H__ #define __TONEMAPPER_ENGINE_H__ -bool engine_initialize(); -void engine_bind(); -void engine_shutdown(); +void* engine_initialize(); +void engine_bind(void*); +void engine_shutdown(void*); unsigned int engine_loadProgram(int, const char **, int, const char **); void engine_setProgram(int); @@ -39,4 +39,4 @@ void engine_setDestination(int id, int x, int y, int w, int h); int engine_blit(int); -#endif //__TONEMAPPER_ENGINE_H__
\ No newline at end of file +#endif //__TONEMAPPER_ENGINE_H__ diff --git a/gpu_tonemapper/glengine.cpp b/gpu_tonemapper/glengine.cpp index e5c8e68a..9fc8f6b1 100644 --- a/gpu_tonemapper/glengine.cpp +++ b/gpu_tonemapper/glengine.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, The Linux Foundation. All rights reserved. + * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. * Not a Contribution. * * Copyright 2015 The Android Open Source Project @@ -24,37 +24,42 @@ void checkGlError(const char *, int); void checkEglError(const char *, int); -static EGLDisplay eglDisplay; -static EGLContext eglContext; -static EGLSurface eglSurface; - -static bool isEngineInitialized = false; +class EngineContext { + public: + EGLDisplay eglDisplay; + EGLContext eglContext; + EGLSurface eglSurface; + EngineContext() + { + eglDisplay = EGL_NO_DISPLAY; + eglContext = EGL_NO_CONTEXT; + eglSurface = EGL_NO_SURFACE; + } +}; //----------------------------------------------------------------------------- // Make Current -void engine_bind() +void engine_bind(void* context) //----------------------------------------------------------------------------- { - EGL(eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)); + EngineContext* engineContext = (EngineContext*)(context); + EGL(eglMakeCurrent(engineContext->eglDisplay, engineContext->eglSurface, engineContext->eglSurface, engineContext->eglContext)); } //----------------------------------------------------------------------------- // initialize GL // -bool engine_initialize() +void* engine_initialize() //----------------------------------------------------------------------------- { - if (isEngineInitialized) - return true; - - EGLBoolean result = false; + EngineContext* engineContext = new EngineContext(); // display - eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); + engineContext->eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); EGL(eglBindAPI(EGL_OPENGL_ES_API)); // initialize - EGL(eglInitialize(eglDisplay, 0, 0)); + EGL(eglInitialize(engineContext->eglDisplay, 0, 0)); // config EGLConfig eglConfig; @@ -65,38 +70,36 @@ bool engine_initialize() EGL_ALPHA_SIZE, 8, EGL_NONE}; int numConfig = 0; - EGL(eglChooseConfig(eglDisplay, eglConfigAttribList, &eglConfig, 1, &numConfig)); + EGL(eglChooseConfig(engineContext->eglDisplay, eglConfigAttribList, &eglConfig, 1, &numConfig)); // context EGLint eglContextAttribList[] = {EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE}; - eglContext = eglCreateContext(eglDisplay, eglConfig, NULL, eglContextAttribList); + engineContext->eglContext = eglCreateContext(engineContext->eglDisplay, eglConfig, NULL, eglContextAttribList); // surface EGLint eglSurfaceAttribList[] = {EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE, EGL_NONE}; - eglSurface = eglCreatePbufferSurface(eglDisplay, eglConfig, eglSurfaceAttribList); - - result = (EGL_TRUE == eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)); + engineContext->eglSurface = eglCreatePbufferSurface(engineContext->eglDisplay, eglConfig, eglSurfaceAttribList); - isEngineInitialized = result; + eglMakeCurrent(engineContext->eglDisplay, engineContext->eglSurface, engineContext->eglSurface, engineContext->eglContext); - ALOGI("In %s result = %d context = %p", __FUNCTION__, result, (void *)eglContext); + ALOGI("In %s context = %p", __FUNCTION__, (void *)(engineContext->eglContext)); - return result; + return (void*)(engineContext); } //----------------------------------------------------------------------------- // Shutdown. -void engine_shutdown() +void engine_shutdown(void* context) //----------------------------------------------------------------------------- { - EGL(eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)); - EGL(eglDestroySurface(eglDisplay, eglSurface)); - EGL(eglDestroyContext(eglDisplay, eglContext)); - EGL(eglTerminate(eglDisplay)); - eglDisplay = EGL_NO_DISPLAY; - eglContext = EGL_NO_CONTEXT; - eglSurface = EGL_NO_SURFACE; - isEngineInitialized = false; + EngineContext* engineContext = (EngineContext*)context; + EGL(eglMakeCurrent(engineContext->eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)); + EGL(eglDestroySurface(engineContext->eglDisplay, engineContext->eglSurface)); + EGL(eglDestroyContext(engineContext->eglDisplay, engineContext->eglContext)); + EGL(eglTerminate(engineContext->eglDisplay)); + engineContext->eglDisplay = EGL_NO_DISPLAY; + engineContext->eglContext = EGL_NO_CONTEXT; + engineContext->eglSurface = EGL_NO_SURFACE; } //----------------------------------------------------------------------------- @@ -206,14 +209,14 @@ void WaitOnNativeFence(int fd) if (fd != -1) { EGLint attribs[] = {EGL_SYNC_NATIVE_FENCE_FD_ANDROID, fd, EGL_NONE}; - EGLSyncKHR sync = eglCreateSyncKHR(eglDisplay, EGL_SYNC_NATIVE_FENCE_ANDROID, attribs); + EGLSyncKHR sync = eglCreateSyncKHR(eglGetCurrentDisplay(), EGL_SYNC_NATIVE_FENCE_ANDROID, attribs); if (sync == EGL_NO_SYNC_KHR) { ALOGE("%s - Failed to Create sync from source fd", __FUNCTION__); } else { // the gpu will wait for this sync - not this cpu thread. - EGL(eglWaitSyncKHR(eglDisplay, sync, 0)); - EGL(eglDestroySyncKHR(eglDisplay, sync)); + EGL(eglWaitSyncKHR(eglGetCurrentDisplay(), sync, 0)); + EGL(eglDestroySyncKHR(eglGetCurrentDisplay(), sync)); } } } @@ -224,16 +227,16 @@ int CreateNativeFence() { int fd = -1; - EGLSyncKHR sync = eglCreateSyncKHR(eglDisplay, EGL_SYNC_NATIVE_FENCE_ANDROID, NULL); + EGLSyncKHR sync = eglCreateSyncKHR(eglGetCurrentDisplay(), EGL_SYNC_NATIVE_FENCE_ANDROID, NULL); GL(glFlush()); if (sync == EGL_NO_SYNC_KHR) { ALOGE("%s - Failed to Create Native Fence sync", __FUNCTION__); } else { - fd = eglDupNativeFenceFDANDROID(eglDisplay, sync); + fd = eglDupNativeFenceFDANDROID(eglGetCurrentDisplay(), sync); if (fd == EGL_NO_NATIVE_FENCE_FD_ANDROID) { ALOGE("%s - Failed to dup sync", __FUNCTION__); } - EGL(eglDestroySyncKHR(eglDisplay, sync)); + EGL(eglDestroySyncKHR(eglGetCurrentDisplay(), sync)); } return fd; diff --git a/sdm/libs/hwc/hwc_tonemapper.cpp b/sdm/libs/hwc/hwc_tonemapper.cpp index e0d6ca87..0ceb2e5c 100644 --- a/sdm/libs/hwc/hwc_tonemapper.cpp +++ b/sdm/libs/hwc/hwc_tonemapper.cpp @@ -225,7 +225,6 @@ void HWCToneMapper::Terminate() { delete tone_map_sessions_.back(); tone_map_sessions_.pop_back(); } - TonemapperFactory_Destroy(); fb_session_index_ = 0; } } |