From 3b47bf27db6a84d48747d99b7e064296038cc94a Mon Sep 17 00:00:00 2001 From: Jan Altensen Date: Fri, 10 Apr 2020 21:55:59 +0200 Subject: [PATCH] osal: add BufferMapper Change-Id: Icc522de0024d70c2de2a6a93335b06fa8ff62423 (cherry picked from commit f12af59d7e8c8a65cd37d855f5cd584ad252813c) --- osal/Android.mk | 3 +- osal/Exynos_OSAL_Android.cpp | 8 +-- osal/Exynos_OSAL_BufferMapper.cpp | 82 +++++++++++++++++++++++++++++++ osal/Exynos_OSAL_BufferMapper.h | 50 +++++++++++++++++++ 4 files changed, 138 insertions(+), 5 deletions(-) create mode 100644 osal/Exynos_OSAL_BufferMapper.cpp create mode 100644 osal/Exynos_OSAL_BufferMapper.h diff --git a/osal/Android.mk b/osal/Android.mk index d93f3f8..e293350 100644 --- a/osal/Android.mk +++ b/osal/Android.mk @@ -120,7 +120,8 @@ LOCAL_CFLAGS := \ ifeq ($(BOARD_USE_ANDROID), true) LOCAL_SRC_FILES += \ - Exynos_OSAL_Android.cpp + Exynos_OSAL_Android.cpp \ + Exynos_OSAL_BufferMapper.cpp endif ifeq ($(BOARD_USE_ANB), true) diff --git a/osal/Exynos_OSAL_Android.cpp b/osal/Exynos_OSAL_Android.cpp index bb2baac..13a2e0a 100644 --- a/osal/Exynos_OSAL_Android.cpp +++ b/osal/Exynos_OSAL_Android.cpp @@ -45,6 +45,7 @@ #include #include "exynos_ion.h" +#include "Exynos_OSAL_BufferMapper.h" #include "Exynos_OSAL_Mutex.h" #include "Exynos_OSAL_Semaphore.h" #include "Exynos_OMX_Baseport.h" @@ -164,12 +165,11 @@ OMX_ERRORTYPE Exynos_OSAL_LockANBHandle( FunctionIn(); OMX_ERRORTYPE ret = OMX_ErrorNone; - GraphicBufferMapper &mapper = GraphicBufferMapper::get(); + BufferMapper &mapper = BufferMapper::get(); buffer_handle_t bufferHandle = (buffer_handle_t) handle; #ifdef USE_DMA_BUF private_handle_t *priv_hnd = (private_handle_t *) bufferHandle; #endif - Rect bounds((uint32_t)width, (uint32_t)height); ExynosVideoPlane *vplanes = (ExynosVideoPlane *) planes; void *vaddr[MAX_BUFFER_PLANE] = {NULL, }; @@ -202,7 +202,7 @@ OMX_ERRORTYPE Exynos_OSAL_LockANBHandle( break; } - if (mapper.lock(bufferHandle, usage, bounds, vaddr) != 0) { + if (mapper.lock(bufferHandle, usage, width, height, vaddr) != 0) { Exynos_OSAL_Log(EXYNOS_LOG_ERROR, "%s: mapper.lock() fail", __func__); ret = OMX_ErrorUndefined; goto EXIT; @@ -249,7 +249,7 @@ OMX_ERRORTYPE Exynos_OSAL_UnlockANBHandle(OMX_IN OMX_PTR handle) FunctionIn(); OMX_ERRORTYPE ret = OMX_ErrorNone; - GraphicBufferMapper &mapper = GraphicBufferMapper::get(); + BufferMapper &mapper = BufferMapper::get(); buffer_handle_t bufferHandle = (buffer_handle_t) handle; Exynos_OSAL_Log(EXYNOS_LOG_TRACE, "%s: handle: 0x%x", __func__, handle); diff --git a/osal/Exynos_OSAL_BufferMapper.cpp b/osal/Exynos_OSAL_BufferMapper.cpp new file mode 100644 index 0000000..156500e --- /dev/null +++ b/osal/Exynos_OSAL_BufferMapper.cpp @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2020 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define LOG_TAG "Exynos_OSAL_BufferMapper" +#define LOG_NDEBUG 0 + +#include +#include +#include + +#include +#include +#include + +#include + +#include "Exynos_OSAL_BufferMapper.h" + +namespace android { + +ANDROID_SINGLETON_STATIC_INSTANCE( BufferMapper ) + +BufferMapper::BufferMapper() + : mModule(nullptr) +{ + const hw_module_t* module; + int err = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module); + + ALOGE_IF(err, "cannot find gralloc-module %s", GRALLOC_HARDWARE_MODULE_ID); + if (err == 0) { + mModule = reinterpret_cast(module); + } +} + +android::status_t BufferMapper::lock(buffer_handle_t handle, + uint32_t usage, uint32_t width, uint32_t height, void** vaddr) +{ + ATRACE_CALL(); + android::status_t err; + + if (mModule->lock == NULL) { + ALOGW("lock(%p) not found", handle); + return -EINVAL; + } + + err = mModule->lock(mModule, handle, static_cast(usage), + 0, 0, width, height, vaddr); + + ALOGW_IF(err, "lock(%p) failed: %d (%s)", handle, -err, strerror(-err)); + return err; +} + +android::status_t BufferMapper::unlock(buffer_handle_t handle) +{ + ATRACE_CALL(); + android::status_t err; + + if (mModule->unlock == NULL) { + ALOGW("unlock(%p) not found", handle); + return -EINVAL; + } + + err = mModule->unlock(mModule, handle); + + ALOGW_IF(err, "unlock(%p) failed: %d (%s)", handle, -err, strerror(-err)); + return err; +} + +}; // namespace android diff --git a/osal/Exynos_OSAL_BufferMapper.h b/osal/Exynos_OSAL_BufferMapper.h new file mode 100644 index 0000000..aa9f74a --- /dev/null +++ b/osal/Exynos_OSAL_BufferMapper.h @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2020 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef EXYNOS_OSAL_BUFFERMAPPER_H +#define EXYNOS_OSAL_BUFFERMAPPER_H + +#include +#include + +#include + +#include + +struct gralloc_module_t; + +namespace android { + +class BufferMapper : public android::Singleton +{ +public: + static inline BufferMapper& get() { return getInstance(); } + + android::status_t lock(buffer_handle_t handle, + uint32_t usage, uint32_t width, uint32_t height, void** vaddr); + + android::status_t unlock(buffer_handle_t handle); + +private: + friend class Singleton; + const gralloc_module_t *mModule; + + BufferMapper(); +}; + +}; // namespace android + +#endif // EXYNOS_OSAL_BUFFERMAPPER_H \ No newline at end of file -- 2.20.1