osal: add BufferMapper
authorJan Altensen <info@stricted.net>
Fri, 10 Apr 2020 19:55:59 +0000 (21:55 +0200)
committerJan Altensen <info@stricted.net>
Sat, 18 Apr 2020 19:44:22 +0000 (21:44 +0200)
Change-Id: Icc522de0024d70c2de2a6a93335b06fa8ff62423
(cherry picked from commit f12af59d7e8c8a65cd37d855f5cd584ad252813c)

osal/Android.mk
osal/Exynos_OSAL_Android.cpp
osal/Exynos_OSAL_BufferMapper.cpp [new file with mode: 0644]
osal/Exynos_OSAL_BufferMapper.h [new file with mode: 0644]

index d93f3f8b8e47f3e5042e0d0846b99549a89049ac..e2933509d4bd2bf75da977f3d2e017c3f983165d 100644 (file)
@@ -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)
index bb2baacdaadc42976a80699fbde23710d37a77ff..13a2e0a6c3b0756892703b1da61795ef2a799677 100644 (file)
@@ -45,6 +45,7 @@
 #include <ion/ion.h>
 #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 (file)
index 0000000..156500e
--- /dev/null
@@ -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 <string.h>
+#include <stdint.h>
+#include <errno.h>
+
+#include <utils/Errors.h>
+#include <utils/Log.h>
+#include <utils/Trace.h>
+
+#include <hardware/gralloc.h>
+
+#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<gralloc_module_t const *>(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<int>(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 (file)
index 0000000..aa9f74a
--- /dev/null
@@ -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 <stdint.h>
+#include <sys/types.h>
+
+#include <utils/Singleton.h>
+
+#include <hardware/gralloc.h>
+
+struct gralloc_module_t;
+
+namespace android {
+
+class BufferMapper : public android::Singleton<BufferMapper>
+{
+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<BufferMapper>;
+       const gralloc_module_t *mModule;
+
+       BufferMapper();
+};
+
+}; // namespace android
+
+#endif // EXYNOS_OSAL_BUFFERMAPPER_H
\ No newline at end of file