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)
#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"
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, };
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;
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);
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ * 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