From 1634a6f5eea543980b5ae9d97120150c938a79d2 Mon Sep 17 00:00:00 2001 From: Astrako Date: Fri, 28 Feb 2020 12:11:49 +0100 Subject: [PATCH] universal7870: rework shims --- BoardConfigCommon.mk | 10 +- device-common.mk | 5 +- shims/Android.mk | 4 +- shims/libExynosOMX/Android.mk | 29 ++++ shims/libExynosOMX/Exynos_OMX_VdecControl.c | 61 +++++++++ shims/libcamera_client/Android.mk | 2 +- shims/libcamera_client/CameraParameters.cpp | 2 +- shims/libcamera_client/CameraParameters.h | 60 ++++----- shims/libexynoscamera/Android.mk | 11 +- shims/libexynoscamera/CameraParameters.cpp | 52 -------- shims/libexynoscamera/CameraParameters.h | 54 -------- shims/libexynoscamera/Fence.cpp | 26 ++++ shims/libexynoscamera/GraphicBuffer.cpp | 3 - shims/libstagefright/Android.mk | 3 +- shims/libui/Android.mk | 40 ++++++ shims/libui/GraphicBufferMapper.cpp | 138 ++++++++++++++++++++ shims/libui/GraphicBufferMapper.h | 61 +++++++++ 17 files changed, 410 insertions(+), 151 deletions(-) create mode 100644 shims/libExynosOMX/Android.mk create mode 100644 shims/libExynosOMX/Exynos_OMX_VdecControl.c delete mode 100644 shims/libexynoscamera/CameraParameters.cpp delete mode 100644 shims/libexynoscamera/CameraParameters.h create mode 100644 shims/libexynoscamera/Fence.cpp create mode 100644 shims/libui/Android.mk create mode 100644 shims/libui/GraphicBufferMapper.cpp create mode 100644 shims/libui/GraphicBufferMapper.h diff --git a/BoardConfigCommon.mk b/BoardConfigCommon.mk index faf3962..665db97 100644 --- a/BoardConfigCommon.mk +++ b/BoardConfigCommon.mk @@ -188,7 +188,15 @@ BOARD_VNDK_VERSION := current # Shims TARGET_LD_SHIM_LIBS += \ - /vendor/lib/libexynoscamera.so|libexynoscamera_shim.so + /vendor/lib/libcamera_client.so|/vendor/lib/libcamera_client_shim.so \ + /vendor/lib/omx/libOMX.Exynos.AVC.Decoder.so|/vendor/lib/libui_shim.so \ + /vendor/lib/omx/libOMX.Exynos.AVC.Encoder.so|/vendor/lib/libui_shim.so \ + /vendor/lib/omx/libOMX.Exynos.MPEG4.Decoder.so|/vendor/lib/libui_shim.so \ + /vendor/lib/omx/libOMX.Exynos.MPEG4.Encoder.so|/vendor/lib/libui_shim.so \ + /vendor/lib/omx/libOMX.Exynos.VP8.Decoder.so|/vendor/lib/libui_shim.so \ + /vendor/lib/omx/libOMX.Exynos.VP8.Encoder.so|/vendor/lib/libui_shim.so \ + /vendor/lib/omx/libOMX.Exynos.WMV.Decoder.so|/vendor/lib/libui_shim.so \ + /vendor/lib/libexynoscamera.so|/vendor/lib/libexynoscamera_shim.so # Wifi BOARD_HAVE_SAMSUNG_WIFI := true diff --git a/device-common.mk b/device-common.mk index 8c5c713..140edae 100644 --- a/device-common.mk +++ b/device-common.mk @@ -263,7 +263,10 @@ PRODUCT_PACKAGES += \ # Shims PRODUCT_PACKAGES += \ - libexynoscamera_shim + libcamera_client_shim \ + libexynoscamera_shim \ + libExynosOMX_shim \ + libui_shim # USB PRODUCT_PACKAGES += \ diff --git a/shims/Android.mk b/shims/Android.mk index 60d3a2c..4f5a74d 100644 --- a/shims/Android.mk +++ b/shims/Android.mk @@ -1,6 +1,5 @@ # -# -# Copyright (C) 2016 The CyanogenMod Project +# Copyright (C) 2018 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. @@ -13,7 +12,6 @@ # 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. -# LOCAL_PATH := $(call my-dir) diff --git a/shims/libExynosOMX/Android.mk b/shims/libExynosOMX/Android.mk new file mode 100644 index 0000000..78bb669 --- /dev/null +++ b/shims/libExynosOMX/Android.mk @@ -0,0 +1,29 @@ +# +# Copyright (C) 2018 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. + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := Exynos_OMX_VdecControl.c + +LOCAL_SHARED_LIBRARIES := liblog libcutils + +LOCAL_MODULE := libExynosOMX_shim +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_CLASS := SHARED_LIBRARIES +LOCAL_PROPRIETARY_MODULE := true + +include $(BUILD_SHARED_LIBRARY) diff --git a/shims/libExynosOMX/Exynos_OMX_VdecControl.c b/shims/libExynosOMX/Exynos_OMX_VdecControl.c new file mode 100644 index 0000000..6a14608 --- /dev/null +++ b/shims/libExynosOMX/Exynos_OMX_VdecControl.c @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2017 TeamNexus + * + * 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 "libExynosOMX_shim" + +#include +#include +#include + +int Exynos_OSAL_Strcmp(const char *s1, const char *s2) +{ + void *ptr; + int ret; + Dl_info info; + + /* get address of parent function */ + ptr = __builtin_return_address(0); + + /* skip index-check if we couldn't get return-address */ + if (!ptr) { + ALOGE("%s: failed to retrieve return address", __func__); + goto exit; + } + + /* get infos about parent function */ + ret = dladdr(ptr, &info); + + /* skip index-check if we couldn't get infos about parent function */ + if (!ret) { + ALOGE("%s: failed to retrieve informations about parent function", __func__); + goto exit; + } + + /* check if the parent function is Exynos_OMX_VideoDecodeGetExtensionIndex() */ + if (strcmp(info.dli_sname, "Exynos_OMX_VideoDecodeGetExtensionIndex")) { + /* no log here... */ + goto exit; + } + + /* prevent check for storeMetaDataInBuffers-support to succeed */ + if (!strcmp(s1, "OMX.google.android.index.storeMetaDataInBuffers")) { + ALOGI("%s: failing check for storeMetaDataInBuffers-support", __func__); + return -1; + } + +exit: + return strcmp(s1, s2); +} diff --git a/shims/libcamera_client/Android.mk b/shims/libcamera_client/Android.mk index 8aaab1a..8815531 100644 --- a/shims/libcamera_client/Android.mk +++ b/shims/libcamera_client/Android.mk @@ -21,6 +21,6 @@ LOCAL_SRC_FILES := CameraParameters.cpp LOCAL_MODULE := libcamera_client_shim LOCAL_MODULE_TAGS := optional LOCAL_MODULE_CLASS := SHARED_LIBRARIES -LOCAL_VENDOR_MODULE := true +LOCAL_PROPRIETARY_MODULE := true include $(BUILD_SHARED_LIBRARY) diff --git a/shims/libcamera_client/CameraParameters.cpp b/shims/libcamera_client/CameraParameters.cpp index ce26841..adca08b 100644 --- a/shims/libcamera_client/CameraParameters.cpp +++ b/shims/libcamera_client/CameraParameters.cpp @@ -49,4 +49,4 @@ const char CameraParameters::KEY_PHASE_AF[] = "phase-af"; const char CameraParameters::KEY_SUPPORTED_RT_HDR[] = "rt-hdr-values"; const char CameraParameters::KEY_RT_HDR[] = "rt-hdr"; -}; // namespace android +}; // namespace android \ No newline at end of file diff --git a/shims/libcamera_client/CameraParameters.h b/shims/libcamera_client/CameraParameters.h index e5dd660..970af51 100644 --- a/shims/libcamera_client/CameraParameters.h +++ b/shims/libcamera_client/CameraParameters.h @@ -19,36 +19,36 @@ namespace android { class CameraParameters { public: - static const char PIXEL_FORMAT_YUV420SP_NV21[]; - static const char EFFECT_CARTOONIZE[]; - static const char EFFECT_POINT_RED_YELLOW[]; - static const char EFFECT_POINT_GREEN[]; - static const char EFFECT_POINT_BLUE[]; - static const char EFFECT_VINTAGE_COLD[]; - static const char EFFECT_VINTAGE_WARM[]; - static const char EFFECT_WASHED[]; - static const char ISO_AUTO[]; - static const char ISO_NIGHT[]; - static const char ISO_SPORTS[]; - static const char ISO_6400[]; - static const char ISO_3200[]; - static const char ISO_1600[]; - static const char ISO_800[]; - static const char ISO_400[]; - static const char ISO_200[]; - static const char ISO_100[]; - static const char ISO_80[]; - static const char ISO_50[]; - static const char KEY_SUPPORTED_METERING_MODE[]; - static const char METERING_CENTER[]; - static const char METERING_MATRIX[]; - static const char METERING_SPOT[]; - static const char METERING_OFF[]; - static const char KEY_DYNAMIC_RANGE_CONTROL[]; - static const char KEY_SUPPORTED_PHASE_AF[]; - static const char KEY_PHASE_AF[]; - static const char KEY_SUPPORTED_RT_HDR[]; - static const char KEY_RT_HDR[]; + static const char PIXEL_FORMAT_YUV420SP_NV21[]; + static const char EFFECT_CARTOONIZE[]; + static const char EFFECT_POINT_RED_YELLOW[]; + static const char EFFECT_POINT_GREEN[]; + static const char EFFECT_POINT_BLUE[]; + static const char EFFECT_VINTAGE_COLD[]; + static const char EFFECT_VINTAGE_WARM[]; + static const char EFFECT_WASHED[]; + static const char ISO_AUTO[]; + static const char ISO_NIGHT[]; + static const char ISO_SPORTS[]; + static const char ISO_6400[]; + static const char ISO_3200[]; + static const char ISO_1600[]; + static const char ISO_800[]; + static const char ISO_400[]; + static const char ISO_200[]; + static const char ISO_100[]; + static const char ISO_80[]; + static const char ISO_50[]; + static const char KEY_SUPPORTED_METERING_MODE[]; + static const char METERING_CENTER[]; + static const char METERING_MATRIX[]; + static const char METERING_SPOT[]; + static const char METERING_OFF[]; + static const char KEY_DYNAMIC_RANGE_CONTROL[]; + static const char KEY_SUPPORTED_PHASE_AF[]; + static const char KEY_PHASE_AF[]; + static const char KEY_SUPPORTED_RT_HDR[]; + static const char KEY_RT_HDR[]; }; }; // namespace android diff --git a/shims/libexynoscamera/Android.mk b/shims/libexynoscamera/Android.mk index 058ceb2..6bb1378 100644 --- a/shims/libexynoscamera/Android.mk +++ b/shims/libexynoscamera/Android.mk @@ -1,5 +1,5 @@ # -# Copyright (C) 2019 The LineageOS Project +# Copyright (C) 2018 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. @@ -16,12 +16,15 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) -LOCAL_SRC_FILES := CameraParameters.cpp GraphicBuffer.cpp +LOCAL_SRC_FILES := GraphicBuffer.cpp Fence.cpp + LOCAL_C_INCLUDES := frameworks/native/include -LOCAL_SHARED_LIBRARIES := libui libutils + +LOCAL_SHARED_LIBRARIES := libgui_vendor libui + LOCAL_MODULE := libexynoscamera_shim LOCAL_MODULE_TAGS := optional LOCAL_MODULE_CLASS := SHARED_LIBRARIES -LOCAL_VENDOR_MODULE := true +LOCAL_PROPRIETARY_MODULE := true include $(BUILD_SHARED_LIBRARY) diff --git a/shims/libexynoscamera/CameraParameters.cpp b/shims/libexynoscamera/CameraParameters.cpp deleted file mode 100644 index ce26841..0000000 --- a/shims/libexynoscamera/CameraParameters.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2018 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. - */ - -#include "CameraParameters.h" - -namespace android { - -const char CameraParameters::PIXEL_FORMAT_YUV420SP_NV21[] = "nv21"; -const char CameraParameters::EFFECT_CARTOONIZE[] = "cartoonize"; -const char CameraParameters::EFFECT_POINT_RED_YELLOW[] = "point-red-yellow"; -const char CameraParameters::EFFECT_POINT_GREEN[] = "point-green"; -const char CameraParameters::EFFECT_POINT_BLUE[] = "point-blue"; -const char CameraParameters::EFFECT_VINTAGE_COLD[] = "vintage-cold"; -const char CameraParameters::EFFECT_VINTAGE_WARM[] = "vintage-warm"; -const char CameraParameters::EFFECT_WASHED[] = "washed"; -const char CameraParameters::ISO_AUTO[] = "auto"; -const char CameraParameters::ISO_NIGHT[] = "night"; -const char CameraParameters::ISO_SPORTS[] = "sports"; -const char CameraParameters::ISO_6400[] = "6400"; -const char CameraParameters::ISO_3200[] = "3200"; -const char CameraParameters::ISO_1600[] = "1600"; -const char CameraParameters::ISO_800[] = "800"; -const char CameraParameters::ISO_400[] = "400"; -const char CameraParameters::ISO_200[] = "200"; -const char CameraParameters::ISO_100[] = "100"; -const char CameraParameters::ISO_80[] = "80"; -const char CameraParameters::ISO_50[] = "50"; -const char CameraParameters::KEY_SUPPORTED_METERING_MODE[] = "metering-values"; -const char CameraParameters::METERING_CENTER[] = "center"; -const char CameraParameters::METERING_MATRIX[] = "matrix"; -const char CameraParameters::METERING_SPOT[] = "spot"; -const char CameraParameters::METERING_OFF[] = "off"; -const char CameraParameters::KEY_DYNAMIC_RANGE_CONTROL[] = "dynamic-range-control"; -const char CameraParameters::KEY_SUPPORTED_PHASE_AF[] = "phase-af-values"; -const char CameraParameters::KEY_PHASE_AF[] = "phase-af"; -const char CameraParameters::KEY_SUPPORTED_RT_HDR[] = "rt-hdr-values"; -const char CameraParameters::KEY_RT_HDR[] = "rt-hdr"; - -}; // namespace android diff --git a/shims/libexynoscamera/CameraParameters.h b/shims/libexynoscamera/CameraParameters.h deleted file mode 100644 index e5dd660..0000000 --- a/shims/libexynoscamera/CameraParameters.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (C) 2018 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. - */ - -namespace android { - -class CameraParameters -{ -public: - static const char PIXEL_FORMAT_YUV420SP_NV21[]; - static const char EFFECT_CARTOONIZE[]; - static const char EFFECT_POINT_RED_YELLOW[]; - static const char EFFECT_POINT_GREEN[]; - static const char EFFECT_POINT_BLUE[]; - static const char EFFECT_VINTAGE_COLD[]; - static const char EFFECT_VINTAGE_WARM[]; - static const char EFFECT_WASHED[]; - static const char ISO_AUTO[]; - static const char ISO_NIGHT[]; - static const char ISO_SPORTS[]; - static const char ISO_6400[]; - static const char ISO_3200[]; - static const char ISO_1600[]; - static const char ISO_800[]; - static const char ISO_400[]; - static const char ISO_200[]; - static const char ISO_100[]; - static const char ISO_80[]; - static const char ISO_50[]; - static const char KEY_SUPPORTED_METERING_MODE[]; - static const char METERING_CENTER[]; - static const char METERING_MATRIX[]; - static const char METERING_SPOT[]; - static const char METERING_OFF[]; - static const char KEY_DYNAMIC_RANGE_CONTROL[]; - static const char KEY_SUPPORTED_PHASE_AF[]; - static const char KEY_PHASE_AF[]; - static const char KEY_SUPPORTED_RT_HDR[]; - static const char KEY_RT_HDR[]; -}; - -}; // namespace android diff --git a/shims/libexynoscamera/Fence.cpp b/shims/libexynoscamera/Fence.cpp new file mode 100644 index 0000000..a78e785 --- /dev/null +++ b/shims/libexynoscamera/Fence.cpp @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2018 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. + */ + +/* status_t android::Fence::wait(int timeout); */ +extern "C" int _ZN7android5Fence4waitEi(int timeout); + +/* status_t android::Fence::wait(unsigned int timeout); */ +extern "C" int _ZN7android5Fence4waitEj(unsigned int timeout) +{ + return _ZN7android5Fence4waitEi(static_cast(timeout)); +} + +extern "C" void _ZN7android5FenceD1Ev() { } diff --git a/shims/libexynoscamera/GraphicBuffer.cpp b/shims/libexynoscamera/GraphicBuffer.cpp index 3607e59..1aee313 100644 --- a/shims/libexynoscamera/GraphicBuffer.cpp +++ b/shims/libexynoscamera/GraphicBuffer.cpp @@ -14,11 +14,8 @@ * limitations under the License. */ - #include -extern "C" void _ZN7android5FenceD1Ev() { } - extern "C" void _ZN7android13GraphicBufferC1EjjijjjP13native_handleb( const native_handle_t* handle, android::GraphicBuffer::HandleWrapMethod method, diff --git a/shims/libstagefright/Android.mk b/shims/libstagefright/Android.mk index 1b92221..5ede22e 100644 --- a/shims/libstagefright/Android.mk +++ b/shims/libstagefright/Android.mk @@ -20,12 +20,12 @@ LOCAL_SRC_FILES := CameraSource.cpp LOCAL_C_INCLUDES := \ $(TOP)/frameworks/av/include \ - $(TOP)/frameworks/av/media/ndk/include \ $(TOP)/frameworks/native/include/media/hardware \ $(TOP)/frameworks/native/include/media/openmax \ $(TOP)/frameworks/native/libs/arect/include \ $(TOP)/frameworks/native/libs/nativebase/include \ $(TOP)/frameworks/native/libs/nativewindow/include \ + $(TOP)/frameworks/av/media/ndk/include LOCAL_SHARED_LIBRARIES := \ android.hardware.graphics.bufferqueue@1.0 \ @@ -38,5 +38,6 @@ LOCAL_SHARED_LIBRARIES := \ LOCAL_MODULE := libstagefright_shim LOCAL_MODULE_TAGS := optional LOCAL_MODULE_CLASS := SHARED_LIBRARIES +LOCAL_PROPRIETARY_MODULE := true include $(BUILD_SHARED_LIBRARY) diff --git a/shims/libui/Android.mk b/shims/libui/Android.mk new file mode 100644 index 0000000..c1300c6 --- /dev/null +++ b/shims/libui/Android.mk @@ -0,0 +1,40 @@ +# +# Copyright (C) 2018 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. + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) + +LOCAL_SRC_FILES := \ + GraphicBufferMapper.cpp + +LOCAL_SHARED_LIBRARIES := \ + libbase \ + libcutils \ + libhardware \ + liblog \ + libnativewindow \ + libsync \ + libui + +LOCAL_STATIC_LIBRARIES := \ + libarect + +LOCAL_MODULE := libui_shim +LOCAL_MODULE_TAGS := optional +LOCAL_MODULE_CLASS := SHARED_LIBRARIES +LOCAL_PROPRIETARY_MODULE := true + +include $(BUILD_SHARED_LIBRARY) diff --git a/shims/libui/GraphicBufferMapper.cpp b/shims/libui/GraphicBufferMapper.cpp new file mode 100644 index 0000000..d8f6096 --- /dev/null +++ b/shims/libui/GraphicBufferMapper.cpp @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2007 The Android Open Source 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 "GraphicBufferMapper_shim" +#define LOG_NDEBUG 0 + +#include +#include + +#include + +#include +#include +#include + +#include + +#include + +#include "GraphicBufferMapper.h" + +namespace android { + +ANDROID_SINGLETON_STATIC_INSTANCE( GraphicBufferMapper ) + +GraphicBufferMapper::GraphicBufferMapper() + : 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); + } +} + +status_t GraphicBufferMapper::importBuffer(buffer_handle_t handle, buffer_handle_t* outHandle) +{ + ATRACE_CALL(); + status_t err; + + if (mModule->registerBuffer == NULL) { + ALOGW("registerBuffer(%p) not found", handle); + return -EINVAL; + } + + err = mModule->registerBuffer(mModule, handle); + *outHandle = handle; + + ALOGW_IF(err, "registerBuffer(%p) failed: %d (%s)", handle, -err, strerror(-err)); + return err; +} + +status_t GraphicBufferMapper::freeBuffer(buffer_handle_t handle) +{ + ATRACE_CALL(); + status_t err; + + if (mModule->unregisterBuffer == NULL) { + ALOGW("unregisterBuffer(%p) not found", handle); + return -EINVAL; + } + + err = mModule->unregisterBuffer(mModule, handle); + + ALOGW_IF(err, "unregisterBuffer(%p) failed: %d (%s)", handle, -err, strerror(-err)); + return err; +} + +status_t GraphicBufferMapper::lock(buffer_handle_t handle, + uint32_t usage, const Rect& bounds, void** vaddr) +{ + ATRACE_CALL(); + status_t err; + + if (mModule->lock == NULL) { + ALOGW("lock(%p) not found", handle); + return -EINVAL; + } + + err = mModule->lock(mModule, handle, static_cast(usage), + bounds.left, bounds.top, bounds.width(), bounds.height(), + vaddr); + + ALOGW_IF(err, "lock(%p) failed: %d (%s)", handle, -err, strerror(-err)); + return err; +} + +status_t GraphicBufferMapper::lockYCbCr(buffer_handle_t handle, + uint32_t usage, const Rect& bounds, android_ycbcr *ycbcr) +{ + ATRACE_CALL(); + status_t err; + + if (mModule->lock_ycbcr == NULL) { + ALOGW("lock_ycbcr(%p) not found", handle); + return -EINVAL; + } + + err = mModule->lock_ycbcr(mModule, handle, static_cast(usage), + bounds.left, bounds.top, bounds.width(), bounds.height(), + ycbcr); + + ALOGW_IF(err, "lock_ycbcr(%p) failed: %d (%s)", handle, -err, strerror(-err)); + return err; +} + +status_t GraphicBufferMapper::unlock(buffer_handle_t handle) +{ + ATRACE_CALL(); + 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/shims/libui/GraphicBufferMapper.h b/shims/libui/GraphicBufferMapper.h new file mode 100644 index 0000000..14703c8 --- /dev/null +++ b/shims/libui/GraphicBufferMapper.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2007 The Android Open Source 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 ANDROID_UI_BUFFER_MAPPER_H +#define ANDROID_UI_BUFFER_MAPPER_H + +#include +#include + +#include + +#include + +struct gralloc_module_t; + +namespace android { + +class Rect; + +class GraphicBufferMapper : public Singleton +{ +public: + static inline GraphicBufferMapper& get() { return getInstance(); } + + status_t importBuffer(buffer_handle_t handle, buffer_handle_t* outHandle); + + status_t freeBuffer(buffer_handle_t handle); + + status_t lock(buffer_handle_t handle, + uint32_t usage, const Rect& bounds, void** vaddr); + + status_t lockYCbCr(buffer_handle_t handle, + uint32_t usage, const Rect& bounds, android_ycbcr *ycbcr); + + status_t unlock(buffer_handle_t handle); + + void dump(buffer_handle_t handle); + +private: + friend class Singleton; + const gralloc_module_t *mModule; + + GraphicBufferMapper(); +}; + +}; // namespace android + +#endif // ANDROID_UI_BUFFER_MAPPER_H