diff --git a/Android.bp b/Android.bp index 1eae1b0c..8b6997e7 100644 --- a/Android.bp +++ b/Android.bp @@ -1,40 +1,10 @@ -cc_defaults { - name: "display_defaults", - cflags: [ - "-Wno-missing-field-initializers", - "-Wconversion", - "-Wall", - "-Werror", - "-std=c++14", - ], - shared_libs: [ - "liblog", - "libcutils", - "libutils", - ], - header_libs: ["display_headers"], - clang: true, -} - cc_library_headers { - name: "display_headers", + name: "display_intf_headers", vendor_available: true, export_include_dirs: [ - "include", - "libcopybit", - "libdrmutils", - "libqdutils", - "libqservice", - "gpu_tonemapper", - "sdm/include", "gralloc", - "libdebug", + "include", + "libdisplayconfig", + "libqdmetadata", ], - header_libs: ["libhardware_headers"], - export_header_lib_headers: ["libhardware_headers"], } - -subdirs = [ - "libqservice", - "libqdutils", -] diff --git a/Android.mk b/Android.mk deleted file mode 100644 index 707acf1f..00000000 --- a/Android.mk +++ /dev/null @@ -1,19 +0,0 @@ -ifneq ($(TARGET_DISABLE_DISPLAY),true) -sdm-libs := sdm/libs -display-hals := include libdebug $(sdm-libs)/utils $(sdm-libs)/core - -ifneq ($(TARGET_IS_HEADLESS), true) - display-hals += libcopybit liblight libmemtrack hdmi_cec \ - $(sdm-libs)/hwc2 gpu_tonemapper libdrmutils libdisplayconfig -endif - -display-hals += gralloc - -ifeq ($(call is-vendor-board-platform,QCOM),true) - include $(call all-named-subdir-makefiles,$(display-hals)) -else -ifneq ($(filter msm% apq%,$(TARGET_BOARD_PLATFORM)),) - include $(call all-named-subdir-makefiles,$(display-hals)) -endif -endif -endif #TARGET_DISABLE_DISPLAY diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index 8ecc86b4..00000000 --- a/Makefile.am +++ /dev/null @@ -1,5 +0,0 @@ -# Makefile.am - Automake script for sdm - -ACLOCAL_AMFLAGS = -I m4 - -SUBDIRS = libqservice libqdutils sdm/libs/utils sdm/libs/core diff --git a/common.mk b/common.mk deleted file mode 100644 index c1b13ec1..00000000 --- a/common.mk +++ /dev/null @@ -1,86 +0,0 @@ -#Common headers -display_top := $(call my-dir) -display_config_version := $(shell \ - if [ -d "$(TOP)/vendor/qcom/opensource/interfaces/display/config/1.1" ];\ - then echo DISPLAY_CONFIG_1_1; fi) - -#Common C flags -common_flags := -Wno-missing-field-initializers -common_flags += -Wconversion -Wall -Werror -std=c++14 -common_flags += -DUSE_GRALLOC1 -ifeq ($(TARGET_IS_HEADLESS), true) - common_flags += -DTARGET_HEADLESS - LOCAL_CLANG := false -endif - -ifeq ($(display_config_version), DISPLAY_CONFIG_1_1) - common_flags += -DDISPLAY_CONFIG_1_1 -endif - -ifeq ($(TARGET_USES_COLOR_METADATA), true) - common_flags += -DUSE_COLOR_METADATA -endif - -ifeq ($(TARGET_USES_QCOM_BSP),true) - common_flags += -DQTI_BSP -endif - -ifeq ($(ARCH_ARM_HAVE_NEON),true) - common_flags += -D__ARM_HAVE_NEON -endif - -ifeq ($(call is-board-platform-in-list, $(MASTER_SIDE_CP_TARGET_LIST)), true) - common_flags += -DMASTER_SIDE_CP -endif - -use_hwc2 := false -ifeq ($(TARGET_USES_HWC2), true) - use_hwc2 := true - common_flags += -DVIDEO_MODE_DEFER_RETIRE_FENCE -endif - -ifneq (,$(filter userdebug eng, $(TARGET_BUILD_VARIANT))) - common_flags += -DUSER_DEBUG -endif - -ifeq ($(LLVM_SA), true) - common_flags += --compile-and-analyze --analyzer-perf --analyzer-Werror -endif - -common_includes := system/core/base/include -CHECK_VERSION_LE = $(shell if [ $(1) -le $(2) ] ; then echo true ; else echo false ; fi) -PLATFORM_SDK_NOUGAT = 25 -ifeq "REL" "$(PLATFORM_VERSION_CODENAME)" -ifeq ($(call CHECK_VERSION_LE, $(PLATFORM_SDK_VERSION), $(PLATFORM_SDK_NOUGAT)), true) -version_flag := -D__NOUGAT__ - -# These include paths are deprecated post N -common_includes += $(display_top)/libqdutils -common_includes += $(display_top)/libqservice -common_includes += $(display_top)/gpu_tonemapper -ifneq ($(TARGET_IS_HEADLESS), true) - common_includes += $(display_top)/libcopybit -endif - -common_includes += $(display_top)/include -common_includes += $(display_top)/sdm/include -common_flags += -isystem $(TARGET_OUT_HEADERS)/qcom/display -endif -endif - -common_header_export_path := qcom/display - -#Common libraries external to display HAL -common_libs := liblog libutils libcutils libhardware -common_deps := -kernel_includes := - -ifeq ($(TARGET_COMPILE_WITH_MSM_KERNEL),true) -# This check is to pick the kernel headers from the right location. -# If the macro above is defined, we make the assumption that we have the kernel -# available in the build tree. -# If the macro is not present, the headers are picked from hardware/qcom/msmXXXX -# failing which, they are picked from bionic. - common_deps += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr - kernel_includes += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include -endif diff --git a/config/sdm845.mk b/config/sdm845.mk deleted file mode 100644 index b7be15ba..00000000 --- a/config/sdm845.mk +++ /dev/null @@ -1,43 +0,0 @@ -#Display related packages and configuration - -PRODUCT_PACKAGES += \ - android.hardware.graphics.composer@2.1-impl \ - android.hardware.graphics.composer@2.1-service \ - android.hardware.graphics.mapper@2.0-impl-qti-display \ - vendor.qti.hardware.display.allocator@1.0-service \ - android.hardware.memtrack@1.0-impl \ - android.hardware.memtrack@1.0-service \ - android.hardware.light@2.0-impl \ - android.hardware.light@2.0-service \ - modetest \ - gralloc.sdm845 \ - lights.sdm845 \ - hwcomposer.sdm845 \ - memtrack.sdm845 \ - libqdutils \ - libqdMetaData \ - libqdMetaData.system - - -TARGET_FORCE_HWC_FOR_VIRTUAL_DISPLAYS := true -MAX_VIRTUAL_DISPLAY_DIMENSION := 4096 -NUM_FRAMEBUFFER_SURFACE_BUFFERS := 2 -#Enable Charging Icon -TARGET_RECOVERY_PIXEL_FORMAT := RGBX_8888 -TARGET_USES_GRALLOC1 := true -TARGET_USES_HWC2 := true -TARGET_USES_QCOM_DISPLAY_BSP := true -TARGET_USES_COLOR_METADATA := true -TARGET_USES_DRM_PP := true - -PRODUCT_PROPERTY_OVERRIDES += \ - debug.sf.enable_hwc_vds=1 \ - persist.demo.hdmirotationlock=false \ - ro.vendor.display.cabl=2 \ - debug.sf.hw=0 \ - debug.egl.hw=0 \ - debug.sf.latch_unsignaled=1 - - - - diff --git a/configure.ac b/configure.ac deleted file mode 100644 index 24c41fd9..00000000 --- a/configure.ac +++ /dev/null @@ -1,56 +0,0 @@ -# -*- Autoconf -*- -# configure.ac -- Autoconf script for sdm -# - -# Process this file with autoconf to produce a configure script - -# Requires autoconf tool later than 2.61 -AC_PREREQ(2.61) -# Initialize the display package version 1.0.0 -AC_INIT([display],1.0.0) -# Does not strictly follow GNU Coding standards -AM_INIT_AUTOMAKE([foreign]) -# Disables auto rebuilding of configure, Makefile.ins -AM_MAINTAINER_MODE -# defines some macros variable to be included by source -AC_CONFIG_HEADERS([config.h]) -AC_CONFIG_MACRO_DIR([m4]) -AC_SUBST([COMMON_CFLAGS], [-Wall -Werror -Wno-sign-conversion -Wconversion -DDEBUG_CALC_FPS]) -AC_SUBST([AM_CPPFLAGS], [--std=c++11]) - -AC_ARG_WITH([core_includes], - AC_HELP_STRING([--with-core-includes=@<:@dir@:>@], - [Specify the location of the core headers]), - [core_incdir=$withval], - with_core_includes=no) - -if test "x$with_core_includes" != "xno"; then - CFLAGS="${CFLAGS} -I${core_incdir}" -fi - -AC_ARG_WITH(sanitized-headers, - AS_HELP_STRING([--with-sanitized-headers=DIR], - [Specify the location of the sanitized Linux headers]), - [CPPFLAGS="$CPPFLAGS -idirafter $withval"]) - -# Checks for programs. -AC_PROG_CC -AM_PROG_CC_C_O -AC_PROG_CXX -AC_PROG_LIBTOOL -AC_PROG_AWK -AC_PROG_CPP -AC_PROG_INSTALL -AC_PROG_LN_S -AC_PROG_MAKE_SET - -AC_SUBST([CFLAGS]) -AC_SUBST([CC]) -AC_CONFIG_FILES([ \ - Makefile \ - libqservice/Makefile \ - libqdutils/Makefile \ - sdm/libs/utils/Makefile \ - sdm/libs/core/Makefile - ]) -AC_OUTPUT diff --git a/gpu_tonemapper/Android.mk b/gpu_tonemapper/Android.mk deleted file mode 100644 index 6c6ccd16..00000000 --- a/gpu_tonemapper/Android.mk +++ /dev/null @@ -1,28 +0,0 @@ -LOCAL_PATH := $(call my-dir) -include $(LOCAL_PATH)/../common.mk - -include $(CLEAR_VARS) -LOCAL_COPY_HEADERS_TO := $(common_header_export_path) -LOCAL_COPY_HEADERS := TonemapFactory.h Tonemapper.h -LOCAL_VENDOR_MODULE := true -include $(BUILD_COPY_HEADERS) - -include $(CLEAR_VARS) -LOCAL_MODULE := libgpu_tonemapper -LOCAL_VENDOR_MODULE := true -LOCAL_MODULE_TAGS := optional -LOCAL_C_INCLUDES := $(TARGET_OUT_HEADERS)/qcom/display/ -LOCAL_C_INCLUDES += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include -LOCAL_SHARED_LIBRARIES := libEGL libGLESv2 libGLESv3 libui libutils liblog -LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps) $(kernel_deps) - -LOCAL_CFLAGS := $(version_flag) -Wno-missing-field-initializers -Wall \ - -Wno-unused-parameter -std=c++11 -DLOG_TAG=\"GPU_TONEMAPPER\" - -LOCAL_SRC_FILES := TonemapFactory.cpp \ - glengine.cpp \ - EGLImageBuffer.cpp \ - EGLImageWrapper.cpp \ - Tonemapper.cpp - -include $(BUILD_SHARED_LIBRARY) diff --git a/gpu_tonemapper/EGLImageBuffer.cpp b/gpu_tonemapper/EGLImageBuffer.cpp deleted file mode 100644 index eeb02733..00000000 --- a/gpu_tonemapper/EGLImageBuffer.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. - * Not a Contribution. - * - * Copyright 2015 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. - */ - -#include "EGLImageBuffer.h" -#include -#include -#include -#include -#include "EGLImageWrapper.h" -#include "glengine.h" - -//----------------------------------------------------------------------------- -EGLImageKHR create_eglImage(android::sp graphicBuffer) -//----------------------------------------------------------------------------- -{ - bool isProtected = (graphicBuffer->getUsage() & GRALLOC_USAGE_PROTECTED); - EGLint attrs[] = {EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, - isProtected ? EGL_PROTECTED_CONTENT_EXT : EGL_NONE, - isProtected ? EGL_TRUE : EGL_NONE, EGL_NONE}; - - EGLImageKHR eglImage = eglCreateImageKHR( - eglGetCurrentDisplay(), (EGLContext)EGL_NO_CONTEXT, EGL_NATIVE_BUFFER_ANDROID, - (EGLClientBuffer)(graphicBuffer->getNativeBuffer()), attrs); - - return eglImage; -} - -//----------------------------------------------------------------------------- -EGLImageBuffer::EGLImageBuffer(android::sp graphicBuffer) -//----------------------------------------------------------------------------- -{ - // this->graphicBuffer = graphicBuffer; - this->eglImageID = create_eglImage(graphicBuffer); - this->width = graphicBuffer->getWidth(); - this->height = graphicBuffer->getHeight(); - - textureID = 0; - renderbufferID = 0; - framebufferID = 0; -} - -//----------------------------------------------------------------------------- -EGLImageBuffer::~EGLImageBuffer() -//----------------------------------------------------------------------------- -{ - if (textureID != 0) { - GL(glDeleteTextures(1, &textureID)); - textureID = 0; - } - - if (renderbufferID != 0) { - GL(glDeleteRenderbuffers(1, &renderbufferID)); - renderbufferID = 0; - } - - if (framebufferID != 0) { - GL(glDeleteFramebuffers(1, &framebufferID)); - framebufferID = 0; - } - - // Delete the eglImage - if (eglImageID != 0) - { - eglDestroyImageKHR(eglGetCurrentDisplay(), eglImageID); - eglImageID = 0; - } -} - -//----------------------------------------------------------------------------- -int EGLImageBuffer::getWidth() -//----------------------------------------------------------------------------- -{ - return width; -} - -//----------------------------------------------------------------------------- -int EGLImageBuffer::getHeight() -//----------------------------------------------------------------------------- -{ - return height; -} - -//----------------------------------------------------------------------------- -unsigned int EGLImageBuffer::getTexture() -//----------------------------------------------------------------------------- -{ - if (textureID == 0) { - bindAsTexture(); - } - - return textureID; -} - -//----------------------------------------------------------------------------- -unsigned int EGLImageBuffer::getFramebuffer() -//----------------------------------------------------------------------------- -{ - if (framebufferID == 0) { - bindAsFramebuffer(); - } - - return framebufferID; -} - -//----------------------------------------------------------------------------- -void EGLImageBuffer::bindAsTexture() -//----------------------------------------------------------------------------- -{ - if (textureID == 0) { - GL(glGenTextures(1, &textureID)); - int target = 0x8D65; - GL(glBindTexture(target, textureID)); - GL(glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); - GL(glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); - GL(glTexParameteri(target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); - GL(glTexParameteri(target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); - - GL(glEGLImageTargetTexture2DOES(0x8D65, eglImageID)); - } - - GL(glBindTexture(0x8D65, textureID)); -} - -//----------------------------------------------------------------------------- -void EGLImageBuffer::bindAsFramebuffer() -//----------------------------------------------------------------------------- -{ - if (renderbufferID == 0) { - GL(glGenFramebuffers(1, &framebufferID)); - GL(glGenRenderbuffers(1, &renderbufferID)); - - GL(glBindRenderbuffer(GL_RENDERBUFFER, renderbufferID)); - GL(glEGLImageTargetRenderbufferStorageOES(GL_RENDERBUFFER, eglImageID)); - - GL(glBindFramebuffer(GL_FRAMEBUFFER, framebufferID)); - GL(glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, - renderbufferID)); - GLenum result = glCheckFramebufferStatus(GL_FRAMEBUFFER); - if (result != GL_FRAMEBUFFER_COMPLETE) { - ALOGI("%s Framebuffer Invalid***************", __FUNCTION__); - } - } - - GL(glBindFramebuffer(GL_FRAMEBUFFER, framebufferID)); -} diff --git a/gpu_tonemapper/EGLImageBuffer.h b/gpu_tonemapper/EGLImageBuffer.h deleted file mode 100644 index 23af5732..00000000 --- a/gpu_tonemapper/EGLImageBuffer.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2016, The Linux Foundation. All rights reserved. - * Not a Contribution. - * - * Copyright 2015 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 __EGLIMAGE_BUFFER_H__ -#define __EGLIMAGE_BUFFER_H__ - -#include -#include -#include -#include "engine.h" - -class EGLImageBuffer { - // android::sp graphicBuffer; - void *eglImageID; - int width; - int height; - uint textureID; - uint renderbufferID; - uint framebufferID; - - public: - int getWidth(); - int getHeight(); - EGLImageBuffer(android::sp); - unsigned int getTexture(); - unsigned int getFramebuffer(); - void bindAsTexture(); - void bindAsFramebuffer(); - ~EGLImageBuffer(); - static EGLImageBuffer *from(const private_handle_t *src); - static void clear(); -}; - -#endif //__EGLIMAGE_BUFFER_H__ \ No newline at end of file diff --git a/gpu_tonemapper/EGLImageWrapper.cpp b/gpu_tonemapper/EGLImageWrapper.cpp deleted file mode 100644 index dfc16d84..00000000 --- a/gpu_tonemapper/EGLImageWrapper.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. - * Not a Contribution. - * - * Copyright 2015 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. - */ - -#include "EGLImageWrapper.h" -#include -#include -#include -#include -#include - -//----------------------------------------------------------------------------- -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) -//----------------------------------------------------------------------------- -{ - 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(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; - - native_handle_t *native_handle = const_cast(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; - } - - android::sp graphicBuffer = - new android::GraphicBuffer(src->unaligned_width, src->unaligned_height, src->format, -#ifndef __NOUGAT__ - 1, // Layer count -#endif - flags, src->width /*src->stride*/, - native_handle, false); - - result = new EGLImageBuffer(graphicBuffer); - - return result; -} - -//----------------------------------------------------------------------------- -EGLImageBuffer *EGLImageWrapper::wrap(const void *pvt_handle) -//----------------------------------------------------------------------------- -{ - const private_handle_t *src = static_cast(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 deleted file mode 100644 index e9a4d68f..00000000 --- a/gpu_tonemapper/EGLImageWrapper.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. - * Not a Contribution. - * - * Copyright 2015 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 __TONEMAPPER_EGLIMAGEWRAPPER_H__ -#define __TONEMAPPER_EGLIMAGEWRAPPER_H__ - -#include -#include "EGLImageBuffer.h" - -class EGLImageWrapper { - private: - class DeleteEGLImageCallback : public android::OnEntryRemoved - { - private: - int ion_fd; - public: - DeleteEGLImageCallback(int ion_fd); - void operator()(int& ion_cookie, EGLImageBuffer*& eglImage); - }; - - android::LruCache* 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 deleted file mode 100644 index db4b8be6..00000000 --- a/gpu_tonemapper/TonemapFactory.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. - * Not a Contribution. - * - * Copyright 2015 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. - */ - -#include "TonemapFactory.h" -#include -#include "Tonemapper.h" -#include "engine.h" - -//---------------------------------------------------------------------------------------------------------------------------------------------------------- -Tonemapper *TonemapperFactory_GetInstance(int type, void *colorMap, int colorMapSize, - void *lutXform, int lutXformSize, bool isSecure) -//---------------------------------------------------------------------------------------------------------------------------------------------------------- -{ - // build the tonemapper - Tonemapper *tonemapper = Tonemapper::build(type, colorMap, colorMapSize, lutXform, lutXformSize, isSecure); - - return tonemapper; -} diff --git a/gpu_tonemapper/TonemapFactory.h b/gpu_tonemapper/TonemapFactory.h deleted file mode 100644 index 17cad400..00000000 --- a/gpu_tonemapper/TonemapFactory.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2016, The Linux Foundation. All rights reserved. - * Not a Contribution. - * - * Copyright 2015 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 __TONEMAPPER_TONEMAPPERFACTORY_H__ -#define __TONEMAPPER_TONEMAPPERFACTORY_H__ - -#include "Tonemapper.h" - -#ifdef __cplusplus -extern "C" { -#endif - -// returns an instance of Tonemapper -Tonemapper *TonemapperFactory_GetInstance(int type, void *colorMap, int colorMapSize, - void *lutXform, int lutXformSize, bool isSecure); - -#ifdef __cplusplus -} -#endif - -#endif //__TONEMAPPER_TONEMAPPERFACTORY_H__ diff --git a/gpu_tonemapper/Tonemapper.cpp b/gpu_tonemapper/Tonemapper.cpp deleted file mode 100644 index 811e091a..00000000 --- a/gpu_tonemapper/Tonemapper.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. - * Not a Contribution. - * - * Copyright 2015 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. - */ -#include - -#include "EGLImageWrapper.h" -#include "Tonemapper.h" -#include "engine.h" -#include "forward_tonemap.inl" -#include "fullscreen_vertex_shader.inl" -#include "rgba_inverse_tonemap.inl" - -//----------------------------------------------------------------------------- -Tonemapper::Tonemapper() -//----------------------------------------------------------------------------- -{ - tonemapTexture = 0; - lutXformTexture = 0; - programID = 0; - eglImageWrapper = new EGLImageWrapper(); - - lutXformScaleOffset[0] = 1.0f; - lutXformScaleOffset[1] = 0.0f; - - tonemapScaleOffset[0] = 1.0f; - tonemapScaleOffset[1] = 0.0f; -} - -//----------------------------------------------------------------------------- -Tonemapper::~Tonemapper() -//----------------------------------------------------------------------------- -{ - engine_bind(engineContext); - engine_deleteInputBuffer(tonemapTexture); - engine_deleteInputBuffer(lutXformTexture); - engine_deleteProgram(programID); - - // clear EGLImage mappings - if (eglImageWrapper != 0) { - delete eglImageWrapper; - eglImageWrapper = 0; - } - - engine_shutdown(engineContext); -} - -//----------------------------------------------------------------------------- -Tonemapper *Tonemapper::build(int type, void *colorMap, int colorMapSize, void *lutXform, - int lutXformSize, bool isSecure) -//----------------------------------------------------------------------------- -{ - if (colorMapSize <= 0) { - ALOGE("Invalid Color Map size = %d", colorMapSize); - return NULL; - } - - // build new tonemapper - Tonemapper *tonemapper = new Tonemapper(); - - tonemapper->engineContext = engine_initialize(isSecure); - - engine_bind(tonemapper->engineContext); - - // load the 3d lut - tonemapper->tonemapTexture = engine_load3DTexture(colorMap, colorMapSize, 0); - tonemapper->tonemapScaleOffset[0] = ((float)(colorMapSize-1))/((float)(colorMapSize)); - tonemapper->tonemapScaleOffset[1] = 1.0f/(2.0f*colorMapSize); - - // load the non-uniform xform - tonemapper->lutXformTexture = engine_load1DTexture(lutXform, lutXformSize, 0); - bool bUseXform = (tonemapper->lutXformTexture != 0) && (lutXformSize != 0); - if( bUseXform ) - { - tonemapper->lutXformScaleOffset[0] = ((float)(lutXformSize-1))/((float)(lutXformSize)); - tonemapper->lutXformScaleOffset[1] = 1.0f/(2.0f*lutXformSize); - } - - // create the program - const char *fragmentShaders[3]; - int fragmentShaderCount = 0; - const char *version = "#version 300 es\n"; - const char *define = "#define USE_NONUNIFORM_SAMPLING\n"; - - fragmentShaders[fragmentShaderCount++] = version; - - // non-uniform sampling - if (bUseXform) { - fragmentShaders[fragmentShaderCount++] = define; - } - - if (type == TONEMAP_INVERSE) { // inverse tonemapping - fragmentShaders[fragmentShaderCount++] = rgba_inverse_tonemap_shader; - } else { // forward tonemapping - fragmentShaders[fragmentShaderCount++] = forward_tonemap_shader; - } - - tonemapper->programID = - engine_loadProgram(1, &fullscreen_vertex_shader, fragmentShaderCount, fragmentShaders); - - return tonemapper; -} - -//----------------------------------------------------------------------------- -int Tonemapper::blit(const void *dst, const void *src, int srcFenceFd) -//----------------------------------------------------------------------------- -{ - // make current - engine_bind(engineContext); - - // create eglimages if required - EGLImageBuffer *dst_buffer = eglImageWrapper->wrap(dst); - EGLImageBuffer *src_buffer = eglImageWrapper->wrap(src); - - // bind the program - engine_setProgram(programID); - - engine_setData2f(3, tonemapScaleOffset); - bool bUseXform = (lutXformTexture != 0); - if( bUseXform ) - { - engine_setData2f(4, lutXformScaleOffset); - } - - // set destination - engine_setDestination(dst_buffer->getFramebuffer(), 0, 0, dst_buffer->getWidth(), - dst_buffer->getHeight()); - // set source - engine_setExternalInputBuffer(0, src_buffer->getTexture()); - // set 3d lut - engine_set3DInputBuffer(1, tonemapTexture); - // set non-uniform xform - engine_set2DInputBuffer(2, lutXformTexture); - - // perform - int fenceFD = engine_blit(srcFenceFd); - - return fenceFD; -} diff --git a/gpu_tonemapper/Tonemapper.h b/gpu_tonemapper/Tonemapper.h deleted file mode 100644 index 707cdfe6..00000000 --- a/gpu_tonemapper/Tonemapper.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. - * Not a Contribution. - * - * Copyright 2015 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 __TONEMAPPER_TONEMAP_H__ -#define __TONEMAPPER_TONEMAP_H__ - -#define TONEMAP_FORWARD 0 -#define TONEMAP_INVERSE 1 - -#include "EGLImageWrapper.h" -#include "engine.h" - -class Tonemapper { - private: - void* engineContext; - unsigned int tonemapTexture; - unsigned int lutXformTexture; - unsigned int programID; - float lutXformScaleOffset[2]; - float tonemapScaleOffset[2]; - EGLImageWrapper* eglImageWrapper; - Tonemapper(); - - public: - ~Tonemapper(); - static Tonemapper *build(int type, void *colorMap, int colorMapSize, void *lutXform, - int lutXformSize, bool isSecure); - int blit(const void *dst, const void *src, int srcFenceFd); -}; - -#endif //__TONEMAPPER_TONEMAP_H__ diff --git a/gpu_tonemapper/engine.h b/gpu_tonemapper/engine.h deleted file mode 100644 index 8fb9452f..00000000 --- a/gpu_tonemapper/engine.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. - * Not a Contribution. - * - * Copyright 2015 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 __TONEMAPPER_ENGINE_H__ -#define __TONEMAPPER_ENGINE_H__ - -void* engine_initialize(bool isSecure); -void engine_bind(void*); -void engine_shutdown(void*); - -unsigned int engine_loadProgram(int, const char **, int, const char **); -void engine_setProgram(int); -void engine_deleteProgram(unsigned int); - -unsigned int engine_load3DTexture(void *data, int sz, int format); -unsigned int engine_load1DTexture(void *xform, int xformSize, int format); -void engine_deleteInputBuffer(unsigned int); - -void engine_set2DInputBuffer(int binding, unsigned int textureID); -void engine_set3DInputBuffer(int binding, unsigned int textureID); -void engine_setExternalInputBuffer(int binding, unsigned int textureID); -void engine_setDestination(int id, int x, int y, int w, int h); -void engine_setData2f(int loc, float* data); - -int engine_blit(int); - -#endif //__TONEMAPPER_ENGINE_H__ diff --git a/gpu_tonemapper/forward_tonemap.inl b/gpu_tonemapper/forward_tonemap.inl deleted file mode 100644 index 0d89a9ea..00000000 --- a/gpu_tonemapper/forward_tonemap.inl +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. - * Not a Contribution. - * - * Copyright 2015 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. - */ - -const char* forward_tonemap_shader = "" - "#extension GL_OES_EGL_image_external_essl3 : require \n" - "precision highp float; \n" - "precision highp sampler2D; \n" - "layout(binding = 0) uniform samplerExternalOES externalTexture; \n" - "layout(binding = 1) uniform sampler3D tonemapper; \n" - "layout(binding = 2) uniform sampler2D xform; \n" - "layout(location = 3) uniform vec2 tSO; \n" - "#ifdef USE_NONUNIFORM_SAMPLING \n" - "layout(location = 4) uniform vec2 xSO; \n" - "#endif \n" - "in vec2 uv; \n" - "out vec4 fs_color; \n" - " \n" - "vec3 ScaleOffset(in vec3 samplePt, in vec2 so) \n" - "{ \n" - " vec3 adjPt = so.x * samplePt + so.y; \n" - " return adjPt; \n" - "} \n" - " \n" - "void main() \n" - "{ \n" - "vec2 flipped = vec2(uv.x, 1.0f - uv.y); \n" - "vec4 rgb = texture(externalTexture, flipped); \n" - "#ifdef USE_NONUNIFORM_SAMPLING \n" - "vec3 adj = ScaleOffset(rgb.xyz, xSO); \n" - "float r = texture(xform, vec2(adj.r, 0.5f)).r; \n" - "float g = texture(xform, vec2(adj.g, 0.5f)).g; \n" - "float b = texture(xform, vec2(adj.b, 0.5f)).b; \n" - "#else \n" - "float r = rgb.r; \n" - "float g = rgb.g; \n" - "float b = rgb.b; \n" - "#endif \n" - "fs_color.rgb = texture(tonemapper, ScaleOffset(vec3(r, g, b), tSO)).rgb; \n" - "} \n"; diff --git a/gpu_tonemapper/fullscreen_vertex_shader.inl b/gpu_tonemapper/fullscreen_vertex_shader.inl deleted file mode 100644 index 9a70c2b3..00000000 --- a/gpu_tonemapper/fullscreen_vertex_shader.inl +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2016, The Linux Foundation. All rights reserved. - * Not a Contribution. - * - * Copyright 2015 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. - */ - -const char* fullscreen_vertex_shader = " " -"#version 300 es \n" -"precision highp float; \n" -"layout(location = 0) in vec2 iUV; \n" -"out vec2 uv; \n" -"void main() \n" -"{ \n" -" vec2 positions[3]; \n" -" positions[0] = vec2(-1.0f, 3.0f); \n" -" positions[1] = vec2(-1.0f, -1.0f); \n" -" positions[2] = vec2(3.0f, -1.0f); \n" -" vec2 uvs[3]; \n" -" uvs[0] = vec2(0.0f, -1.0f); \n" -" uvs[1] = vec2(0.0f, 1.0f); \n" -" uvs[2] = vec2(2.0f, 1.0f); \n" -" gl_Position = vec4(positions[gl_VertexID], -1.0f, 1.0f); \n" -" uv = uvs[gl_VertexID]; \n" -"} \n"; diff --git a/gpu_tonemapper/glengine.cpp b/gpu_tonemapper/glengine.cpp deleted file mode 100644 index 35e1932c..00000000 --- a/gpu_tonemapper/glengine.cpp +++ /dev/null @@ -1,415 +0,0 @@ -/* - * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. - * Not a Contribution. - * - * Copyright 2015 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. - */ - -#include "glengine.h" -#include -#include "engine.h" - -void checkGlError(const char *, int); -void checkEglError(const char *, int); - -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* context) -//----------------------------------------------------------------------------- -{ - EngineContext* engineContext = (EngineContext*)(context); - EGL(eglMakeCurrent(engineContext->eglDisplay, engineContext->eglSurface, engineContext->eglSurface, engineContext->eglContext)); -} - -//----------------------------------------------------------------------------- -// initialize GL -// -void* engine_initialize(bool isSecure) -//----------------------------------------------------------------------------- -{ - EngineContext* engineContext = new EngineContext(); - - // display - engineContext->eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); - EGL(eglBindAPI(EGL_OPENGL_ES_API)); - - // initialize - EGL(eglInitialize(engineContext->eglDisplay, 0, 0)); - - // config - EGLConfig eglConfig; - EGLint eglConfigAttribList[] = {EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, - EGL_RED_SIZE, 8, - EGL_GREEN_SIZE, 8, - EGL_BLUE_SIZE, 8, - EGL_ALPHA_SIZE, 8, - EGL_NONE}; - int numConfig = 0; - EGL(eglChooseConfig(engineContext->eglDisplay, eglConfigAttribList, &eglConfig, 1, &numConfig)); - - // context - EGLint eglContextAttribList[] = {EGL_CONTEXT_CLIENT_VERSION, 3, - isSecure ? EGL_PROTECTED_CONTENT_EXT : EGL_NONE, - isSecure ? EGL_TRUE : EGL_NONE, - EGL_NONE}; - engineContext->eglContext = eglCreateContext(engineContext->eglDisplay, eglConfig, NULL, eglContextAttribList); - - // surface - EGLint eglSurfaceAttribList[] = {EGL_WIDTH, 1, - EGL_HEIGHT, 1, - isSecure ? EGL_PROTECTED_CONTENT_EXT : EGL_NONE, - isSecure ? EGL_TRUE : EGL_NONE, - EGL_NONE}; - engineContext->eglSurface = eglCreatePbufferSurface(engineContext->eglDisplay, eglConfig, eglSurfaceAttribList); - - eglMakeCurrent(engineContext->eglDisplay, engineContext->eglSurface, engineContext->eglSurface, engineContext->eglContext); - - ALOGI("In %s context = %p", __FUNCTION__, (void *)(engineContext->eglContext)); - - return (void*)(engineContext); -} - -//----------------------------------------------------------------------------- -// Shutdown. -void engine_shutdown(void* context) -//----------------------------------------------------------------------------- -{ - 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; -} - -//----------------------------------------------------------------------------- -void engine_deleteInputBuffer(unsigned int id) -//----------------------------------------------------------------------------- -{ - if (id != 0) { - GL(glDeleteTextures(1, &id)); - } -} - -//----------------------------------------------------------------------------- -void engine_deleteProgram(unsigned int id) -//----------------------------------------------------------------------------- -{ - if (id != 0) { - GL(glDeleteProgram(id)); - } -} - -//----------------------------------------------------------------------------- -void engine_setData2f(int location, float* data) -//----------------------------------------------------------------------------- -{ - GL(glUniform2f(location, data[0], data[1])); -} - -//----------------------------------------------------------------------------- -unsigned int engine_load3DTexture(void *colorMapData, int sz, int format) -//----------------------------------------------------------------------------- -{ - GLuint texture = 0; - GL(glGenTextures(1, &texture)); - GL(glBindTexture(GL_TEXTURE_3D, texture)); - GL(glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); - GL(glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); - GL(glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE)); - GL(glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); - GL(glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); - - GL(glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB10_A2, sz, sz, sz, 0, GL_RGBA, - GL_UNSIGNED_INT_2_10_10_10_REV, colorMapData)); - - return texture; -} -//----------------------------------------------------------------------------- -unsigned int engine_load1DTexture(void *data, int sz, int format) -//----------------------------------------------------------------------------- -{ - GLuint texture = 0; - if ((data != 0) && (sz != 0)) { - GL(glGenTextures(1, &texture)); - GL(glBindTexture(GL_TEXTURE_2D, texture)); - GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); - GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); - GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); - GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); - - GL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB10_A2, sz, 1, 0, GL_RGBA, - GL_UNSIGNED_INT_2_10_10_10_REV, data)); - } - return texture; -} - -//----------------------------------------------------------------------------- -void dumpShaderLog(int shader) -//----------------------------------------------------------------------------- -{ - int success = 0; - GLchar infoLog[512]; - GL(glGetShaderiv(shader, GL_COMPILE_STATUS, &success)); - if (!success) { - glGetShaderInfoLog(shader, 512, NULL, infoLog); - ALOGI("Shader Failed to compile: %s\n", infoLog); - } -} - -//----------------------------------------------------------------------------- -GLuint engine_loadProgram(int vertexEntries, const char **vertex, int fragmentEntries, - const char **fragment) -//----------------------------------------------------------------------------- -{ - GLuint progId = glCreateProgram(); - - int vertId = glCreateShader(GL_VERTEX_SHADER); - int fragId = glCreateShader(GL_FRAGMENT_SHADER); - - GL(glShaderSource(vertId, vertexEntries, vertex, 0)); - GL(glCompileShader(vertId)); - dumpShaderLog(vertId); - - GL(glShaderSource(fragId, fragmentEntries, fragment, 0)); - GL(glCompileShader(fragId)); - dumpShaderLog(fragId); - - GL(glAttachShader(progId, vertId)); - GL(glAttachShader(progId, fragId)); - - GL(glLinkProgram(progId)); - - GL(glDetachShader(progId, vertId)); - GL(glDetachShader(progId, fragId)); - - GL(glDeleteShader(vertId)); - GL(glDeleteShader(fragId)); - - return progId; -} - -//----------------------------------------------------------------------------- -void WaitOnNativeFence(int fd) -//----------------------------------------------------------------------------- -{ - if (fd != -1) { - EGLint attribs[] = {EGL_SYNC_NATIVE_FENCE_FD_ANDROID, fd, EGL_NONE}; - - 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(eglGetCurrentDisplay(), sync, 0)); - EGL(eglDestroySyncKHR(eglGetCurrentDisplay(), sync)); - } - } -} - -//----------------------------------------------------------------------------- -int CreateNativeFence() -//----------------------------------------------------------------------------- -{ - int fd = -1; - - 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(eglGetCurrentDisplay(), sync); - if (fd == EGL_NO_NATIVE_FENCE_FD_ANDROID) { - ALOGE("%s - Failed to dup sync", __FUNCTION__); - } - EGL(eglDestroySyncKHR(eglGetCurrentDisplay(), sync)); - } - - return fd; -} - -//----------------------------------------------------------------------------- -void engine_setDestination(int id, int x, int y, int w, int h) -//----------------------------------------------------------------------------- -{ - GL(glBindFramebuffer(GL_FRAMEBUFFER, id)); - GL(glViewport(x, y, w, h)); -} - -//----------------------------------------------------------------------------- -void engine_setProgram(int id) -//----------------------------------------------------------------------------- -{ - GL(glUseProgram(id)); -} - -//----------------------------------------------------------------------------- -void engine_set2DInputBuffer(int binding, unsigned int id) -//----------------------------------------------------------------------------- -{ - GL(glActiveTexture(GL_TEXTURE0 + binding)); - GL(glBindTexture(GL_TEXTURE_2D, id)); -} - -//----------------------------------------------------------------------------- -void engine_set3DInputBuffer(int binding, unsigned int id) -//----------------------------------------------------------------------------- -{ - GL(glActiveTexture(GL_TEXTURE0 + binding)); - GL(glBindTexture(GL_TEXTURE_3D, id)); -} - -//----------------------------------------------------------------------------- -void engine_setExternalInputBuffer(int binding, unsigned int id) -//----------------------------------------------------------------------------- -{ - GL(glActiveTexture(GL_TEXTURE0 + binding)); - GL(glBindTexture(0x8D65, id)); -} - -//----------------------------------------------------------------------------- -int engine_blit(int srcFenceFd) -//----------------------------------------------------------------------------- -{ - int fd = -1; - WaitOnNativeFence(srcFenceFd); - float fullscreen_vertices[]{0.0f, 2.0f, 0.0f, 0.0f, 2.0f, 0.0f}; - GL(glEnableVertexAttribArray(0)); - GL(glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, fullscreen_vertices)); - GL(glDrawArrays(GL_TRIANGLES, 0, 3)); - fd = CreateNativeFence(); - GL(glFlush()); - return fd; -} - -//----------------------------------------------------------------------------- -void checkGlError(const char *file, int line) -//----------------------------------------------------------------------------- -{ - for (GLint error = glGetError(); error; error = glGetError()) { - char *pError; - switch (error) { - case GL_NO_ERROR: - pError = (char *)"GL_NO_ERROR"; - break; - case GL_INVALID_ENUM: - pError = (char *)"GL_INVALID_ENUM"; - break; - case GL_INVALID_VALUE: - pError = (char *)"GL_INVALID_VALUE"; - break; - case GL_INVALID_OPERATION: - pError = (char *)"GL_INVALID_OPERATION"; - break; - case GL_OUT_OF_MEMORY: - pError = (char *)"GL_OUT_OF_MEMORY"; - break; - case GL_INVALID_FRAMEBUFFER_OPERATION: - pError = (char *)"GL_INVALID_FRAMEBUFFER_OPERATION"; - break; - - default: - ALOGE("glError (0x%x) %s:%d\n", error, file, line); - return; - } - - ALOGE("glError (%s) %s:%d\n", pError, file, line); - return; - } - return; -} - -//----------------------------------------------------------------------------- -void checkEglError(const char *file, int line) -//----------------------------------------------------------------------------- -{ - for (int i = 0; i < 5; i++) { - const EGLint error = eglGetError(); - if (error == EGL_SUCCESS) { - break; - } - - char *pError; - switch (error) { - case EGL_SUCCESS: - pError = (char *)"EGL_SUCCESS"; - break; - case EGL_NOT_INITIALIZED: - pError = (char *)"EGL_NOT_INITIALIZED"; - break; - case EGL_BAD_ACCESS: - pError = (char *)"EGL_BAD_ACCESS"; - break; - case EGL_BAD_ALLOC: - pError = (char *)"EGL_BAD_ALLOC"; - break; - case EGL_BAD_ATTRIBUTE: - pError = (char *)"EGL_BAD_ATTRIBUTE"; - break; - case EGL_BAD_CONTEXT: - pError = (char *)"EGL_BAD_CONTEXT"; - break; - case EGL_BAD_CONFIG: - pError = (char *)"EGL_BAD_CONFIG"; - break; - case EGL_BAD_CURRENT_SURFACE: - pError = (char *)"EGL_BAD_CURRENT_SURFACE"; - break; - case EGL_BAD_DISPLAY: - pError = (char *)"EGL_BAD_DISPLAY"; - break; - case EGL_BAD_SURFACE: - pError = (char *)"EGL_BAD_SURFACE"; - break; - case EGL_BAD_MATCH: - pError = (char *)"EGL_BAD_MATCH"; - break; - case EGL_BAD_PARAMETER: - pError = (char *)"EGL_BAD_PARAMETER"; - break; - case EGL_BAD_NATIVE_PIXMAP: - pError = (char *)"EGL_BAD_NATIVE_PIXMAP"; - break; - case EGL_BAD_NATIVE_WINDOW: - pError = (char *)"EGL_BAD_NATIVE_WINDOW"; - break; - case EGL_CONTEXT_LOST: - pError = (char *)"EGL_CONTEXT_LOST"; - break; - default: - ALOGE("eglError (0x%x) %s:%d\n", error, file, line); - return; - } - ALOGE("eglError (%s) %s:%d\n", pError, file, line); - return; - } - return; -} diff --git a/gpu_tonemapper/glengine.h b/gpu_tonemapper/glengine.h deleted file mode 100644 index f6aeec84..00000000 --- a/gpu_tonemapper/glengine.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2016, The Linux Foundation. All rights reserved. - * Not a Contribution. - * - * Copyright 2015 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 __TONEMAPPER_GLENGINE_H__ -#define __TONEMAPPER_GLENGINE_H__ -#include -#define EGL_EGLEXT_PROTOTYPES -#include -#include -#define GL_GLEXT_PROTOTYPES -#include -#include - -#if defined(CHECK_GL_ERRORS) -#define GL(func) func; -#define EGL(func) func; -#else -#define GL(func) \ - func; \ - checkGlError(__FILE__, __LINE__); -#define EGL(func) \ - func; \ - checkEglError(__FILE__, __LINE__); -#endif - -#define EGL_PROTECTED_CONTENT_EXT 0x32C0 - -void checkGlError(const char *file, int line); -void checkEglError(const char *file, int line); - -#endif //__TONEMAPPER_GLENGINE_H__ diff --git a/gpu_tonemapper/rgba_inverse_tonemap.inl b/gpu_tonemapper/rgba_inverse_tonemap.inl deleted file mode 100644 index 2865fbe0..00000000 --- a/gpu_tonemapper/rgba_inverse_tonemap.inl +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. - * Not a Contribution. - * - * Copyright 2015 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. - */ - -const char* rgba_inverse_tonemap_shader = "" - "#extension GL_OES_EGL_image_external_essl3 : require \n" - "precision highp float; \n" - "precision highp sampler2D; \n" - "layout(binding = 0) uniform samplerExternalOES externalTexture; \n" - "layout(binding = 1) uniform sampler3D tonemapper; \n" - "layout(binding = 2) uniform sampler2D xform; \n" - "layout(location = 3) uniform vec2 tSO; \n" - "#if defined(USE_NONUNIFORM_SAMPLING) \n" - "layout(location = 4) uniform vec2 xSO; \n" - "#endif \n" - "in vec2 uv; \n" - "out vec4 fs_color; \n" - " \n" - "vec3 ScaleOffset(in vec3 samplePt, in vec2 so) \n" - "{ \n" - " vec3 adjPt = so.x * samplePt + so.y; \n" - " return adjPt; \n" - "} \n" - " \n" - "void main() \n" - "{ \n" - "vec2 flipped = vec2(uv.x, 1.0f - uv.y); \n" - "vec4 rgb_premulalpha = texture(externalTexture, flipped); \n" - "fs_color = rgb_premulalpha; \n" - "if( rgb_premulalpha.a > 0.0 ) { \n" - "vec3 rgb = rgb_premulalpha.rgb/rgb_premulalpha.a; \n" - "#if defined(USE_NONUNIFORM_SAMPLING) \n" - "vec3 adj = ScaleOffset(rgb.xyz, xSO); \n" - "float r = texture(xform, vec2(adj.r, 0.5f)).r; \n" - "float g = texture(xform, vec2(adj.g, 0.5f)).g; \n" - "float b = texture(xform, vec2(adj.b, 0.5f)).b; \n" - "#else \n" - "float r = rgb.r; \n" - "float g = rgb.g; \n" - "float b = rgb.b; \n" - "#endif \n" - "fs_color.rgb = texture(tonemapper, ScaleOffset(vec3(r, g, b), tSO)).rgb * rgb_premulalpha.a; \n" - "fs_color.a = rgb_premulalpha.a; \n" - "} \n" - "} \n"; diff --git a/gralloc/Android.mk b/gralloc/Android.mk deleted file mode 100644 index 3d19ce16..00000000 --- a/gralloc/Android.mk +++ /dev/null @@ -1,101 +0,0 @@ -# Gralloc module -LOCAL_PATH := $(call my-dir) -include $(LOCAL_PATH)/../common.mk -include $(CLEAR_VARS) - -LOCAL_MODULE := gralloc.$(TARGET_BOARD_PLATFORM) -LOCAL_VENDOR_MODULE := true -LOCAL_MODULE_RELATIVE_PATH := hw -LOCAL_MODULE_TAGS := optional -LOCAL_C_INCLUDES := $(common_includes) - -LOCAL_HEADER_LIBRARIES := display_headers -LOCAL_SHARED_LIBRARIES := $(common_libs) libqdMetaData libsync libgrallocutils \ - libgralloccore android.hardware.graphics.mapper@2.0 -LOCAL_CFLAGS := $(common_flags) -DLOG_TAG=\"qdgralloc\" -Wall -std=c++14 -Werror -LOCAL_CFLAGS += -isystem $(kernel_includes) -LOCAL_CLANG := true -LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps) -LOCAL_SRC_FILES := gr_device_impl.cpp -LOCAL_COPY_HEADERS_TO := $(common_header_export_path) -LOCAL_COPY_HEADERS := gr_device_impl.h gralloc_priv.h gr_priv_handle.h -include $(BUILD_SHARED_LIBRARY) - -#libgrallocutils -include $(CLEAR_VARS) -LOCAL_MODULE := libgrallocutils -LOCAL_VENDOR_MODULE := true -LOCAL_MODULE_TAGS := optional -LOCAL_C_INCLUDES := $(common_includes) $(kernel_includes) -LOCAL_HEADER_LIBRARIES := display_headers -LOCAL_SHARED_LIBRARIES := $(common_libs) libqdMetaData libdl \ - android.hardware.graphics.mapper@2.0 -LOCAL_CFLAGS := $(common_flags) -DLOG_TAG=\"qdgralloc\" -Wno-sign-conversion -LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps) -LOCAL_SRC_FILES := gr_utils.cpp gr_adreno_info.cpp -include $(BUILD_SHARED_LIBRARY) - -#libgralloccore -include $(CLEAR_VARS) -LOCAL_MODULE := libgralloccore -LOCAL_VENDOR_MODULE := true -LOCAL_MODULE_TAGS := optional -LOCAL_C_INCLUDES := $(common_includes) $(kernel_includes) -LOCAL_HEADER_LIBRARIES := display_headers -LOCAL_SHARED_LIBRARIES := $(common_libs) libqdMetaData libdl libgrallocutils \ - android.hardware.graphics.mapper@2.0 -LOCAL_CFLAGS := $(common_flags) -DLOG_TAG=\"qdgralloc\" -Wno-sign-conversion -LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps) -LOCAL_SRC_FILES := gr_allocator.cpp gr_buf_mgr.cpp gr_ion_alloc.cpp -include $(BUILD_SHARED_LIBRARY) - - -qti_mapper_version := $(shell \ - if [ -d "$(TOP)/vendor/qcom/opensource/interfaces/display/mapper/1.0" ];\ - then echo QTI_MAPPER_1_0; fi) - -qti_allocator_version := $(shell \ - if [ -d "$(TOP)/vendor/qcom/opensource/interfaces/display/allocator/1.0" ];\ - then echo QTI_ALLOCATOR_1_0; fi) - - -#mapper -include $(CLEAR_VARS) -LOCAL_MODULE := android.hardware.graphics.mapper@2.0-impl-qti-display -LOCAL_VENDOR_MODULE := true -LOCAL_MODULE_RELATIVE_PATH := hw -LOCAL_MODULE_TAGS := optional -LOCAL_C_INCLUDES := $(common_includes) $(kernel_includes) -LOCAL_HEADER_LIBRARIES := display_headers -LOCAL_SHARED_LIBRARIES := $(common_libs) \ - libhidlbase \ - libhidltransport \ - libqdMetaData \ - libgrallocutils \ - libgralloccore \ - libsync \ - android.hardware.graphics.mapper@2.0 -LOCAL_CFLAGS := $(common_flags) -DLOG_TAG=\"qdgralloc\" -Wno-sign-conversion -LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps) -LOCAL_SRC_FILES := QtiMapper.cpp -include $(BUILD_SHARED_LIBRARY) - -include $(CLEAR_VARS) -LOCAL_MODULE := vendor.qti.hardware.display.allocator@1.0-service -LOCAL_VENDOR_MODULE := true -LOCAL_MODULE_RELATIVE_PATH := hw -LOCAL_MODULE_TAGS := optional -LOCAL_HEADER_LIBRARIES := display_headers -LOCAL_SHARED_LIBRARIES := $(common_libs) \ - libhidlbase \ - libhidltransport\ - libqdMetaData \ - libgrallocutils \ - libgralloccore \ - android.hardware.graphics.allocator@2.0 -LOCAL_CFLAGS := -DLOG_TAG=\"qdgralloc\" $(common_flags) -LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps) -LOCAL_C_INCLUDES := $(common_includes) $(kernel_includes) -LOCAL_SRC_FILES := QtiAllocator.cpp service.cpp -LOCAL_INIT_RC := vendor.qti.hardware.display.allocator@1.0-service.rc -include $(BUILD_EXECUTABLE) diff --git a/gralloc/QtiAllocator.cpp b/gralloc/QtiAllocator.cpp deleted file mode 100644 index c4d7aef4..00000000 --- a/gralloc/QtiAllocator.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright (c) 2018, The Linux Foundation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of The Linux Foundation. nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#define DEBUG 0 -#include "QtiAllocator.h" - -#include -#include - -#include "gr_utils.h" - -namespace vendor { -namespace qti { -namespace hardware { -namespace display { -namespace allocator { -namespace V1_0 { -namespace implementation { - -using android::hardware::hidl_handle; -using gralloc::BufferDescriptor; - -QtiAllocator::QtiAllocator() { - buf_mgr_ = BufferManager::GetInstance(); -} - -// Methods from ::android::hardware::graphics::allocator::V2_0::IAllocator follow. -Return QtiAllocator::dumpDebugInfo(dumpDebugInfo_cb hidl_cb) { - std::ostringstream os; - buf_mgr_->Dump(&os); - hidl_string reply; - reply.setToExternal(os.str().c_str(), os.str().length()); - hidl_cb(reply); - return Void(); -} - -Return QtiAllocator::allocate(const hidl_vec &descriptor, uint32_t count, - allocate_cb hidl_cb) { - ALOGD_IF(DEBUG, "Allocating buffers count: %d", count); - gralloc::BufferDescriptor desc; - - auto err = desc.Decode(descriptor); - if (err != Error::NONE) { - hidl_cb(err, 0, hidl_vec()); - return Void(); - } - - std::vector buffers; - buffers.reserve(count); - for (uint32_t i = 0; i < count; i++) { - buffer_handle_t buffer; - ALOGD_IF(DEBUG, "buffer: %p", &buffer); - err = buf_mgr_->AllocateBuffer(desc, &buffer); - if (err != Error::NONE) { - break; - } - buffers.emplace_back(hidl_handle(buffer)); - } - - uint32_t stride = 0; - hidl_vec hidl_buffers; - if (err == Error::NONE && buffers.size() > 0) { - stride = static_cast(PRIV_HANDLE_CONST(buffers[0].getNativeHandle())->width); - hidl_buffers.setToExternal(buffers.data(), buffers.size()); - } - hidl_cb(err, stride, hidl_buffers); - - for (const auto &b : buffers) { - buf_mgr_->ReleaseBuffer(PRIV_HANDLE_CONST(b.getNativeHandle())); - } - - return Void(); -} - -// Methods from ::android::hidl::base::V1_0::IBase follow. - -IAllocator *HIDL_FETCH_IAllocator(const char * /* name */) { - return new QtiAllocator(); -} - -} // namespace implementation -} // namespace V1_0 -} // namespace allocator -} // namespace display -} // namespace hardware -} // namespace qti -} // namespace vendor diff --git a/gralloc/QtiAllocator.h b/gralloc/QtiAllocator.h deleted file mode 100644 index 1e683e87..00000000 --- a/gralloc/QtiAllocator.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2018, The Linux Foundation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of The Linux Foundation. nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __QTIALLOCATOR_H__ -#define __QTIALLOCATOR_H__ - -#include -#include -#include - -#include "gr_buf_mgr.h" - -namespace vendor { -namespace qti { -namespace hardware { -namespace display { -namespace allocator { -namespace V1_0 { -namespace implementation { - -using ::android::hardware::Return; -using ::android::hardware::Void; -using ::android::hardware::graphics::allocator::V2_0::IAllocator; -using ::android::hardware::graphics::mapper::V2_0::Error; -using ::android::hardware::hidl_array; -using ::android::hardware::hidl_memory; -using ::android::hardware::hidl_string; -using ::android::hardware::hidl_vec; -using ::android::hidl::base::V1_0::DebugInfo; -using ::android::hidl::base::V1_0::IBase; -using ::android::sp; -using gralloc::BufferManager; - -class QtiAllocator : public IAllocator { - public: - QtiAllocator(); - // Methods from ::android::hardware::graphics::allocator::V2_0::IAllocator follow. - Return dumpDebugInfo(dumpDebugInfo_cb _hidl_cb) override; - Return allocate(const hidl_vec &descriptor, uint32_t count, - allocate_cb _hidl_cb) override; - - // Methods from ::android::hidl::base::V1_0::IBase follow. - private: - BufferManager *buf_mgr_ = nullptr; -}; - -extern "C" IAllocator *HIDL_FETCH_IAllocator(const char *name); - -} // namespace implementation -} // namespace V1_0 -} // namespace allocator -} // namespace display -} // namespace hardware -} // namespace qti -} // namespace vendor - -#endif // __QTIALLOCATOR_H__ diff --git a/gralloc/QtiMapper.cpp b/gralloc/QtiMapper.cpp deleted file mode 100644 index bcf3549d..00000000 --- a/gralloc/QtiMapper.cpp +++ /dev/null @@ -1,345 +0,0 @@ -/* - * Copyright (c) 2018, The Linux Foundation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of The Linux Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL) -#define DEBUG 0 -#include "QtiMapper.h" -#include -#include -#include -#include "gr_utils.h" - -namespace vendor { -namespace qti { -namespace hardware { -namespace display { -namespace mapper { -namespace V1_0 { -namespace implementation { - -using gralloc::BufferInfo; - -QtiMapper::QtiMapper() { - buf_mgr_ = BufferManager::GetInstance(); - ALOGD_IF(DEBUG, "Created QtiMapper instance"); -} - -bool QtiMapper::ValidDescriptor(const IMapper::BufferDescriptorInfo &bd) { - if (bd.width == 0 || bd.height == 0 || (static_cast(bd.format) <= 0) || - bd.layerCount <= 0) { - return false; - } - - return true; -} - -// Methods from ::android::hardware::graphics::mapper::V2_0::IMapper follow. -Return QtiMapper::createDescriptor(const IMapper::BufferDescriptorInfo &descriptor_info, - createDescriptor_cb hidl_cb) { - ALOGD_IF(DEBUG, - "BufferDescriptorInfo: wxh: %dx%d usage: 0x%" PRIu64 " format: %d layer_count: %d", - descriptor_info.width, descriptor_info.height, descriptor_info.usage, - static_cast(descriptor_info.format), descriptor_info.layerCount); - - if (ValidDescriptor(descriptor_info)) { - auto vec = gralloc::BufferDescriptor::Encode(descriptor_info); - hidl_cb(Error::NONE, vec); - } else { - hidl_cb(Error::BAD_VALUE, hidl_vec()); - } - return Void(); -} - -Return QtiMapper::importBuffer(const hidl_handle &raw_handle, importBuffer_cb hidl_cb) { - if (!raw_handle.getNativeHandle()) { - ALOGE("%s: Unable to import handle", __FUNCTION__); - hidl_cb(Error::BAD_BUFFER, nullptr); - return Void(); - } - - native_handle_t *buffer_handle = native_handle_clone(raw_handle.getNativeHandle()); - if (!buffer_handle) { - ALOGE("%s: Unable to clone handle", __FUNCTION__); - hidl_cb(Error::NO_RESOURCES, nullptr); - return Void(); - } - - auto error = buf_mgr_->RetainBuffer(PRIV_HANDLE_CONST(buffer_handle)); - if (error != Error::NONE) { - ALOGE("%s: Unable to retain handle: %p", __FUNCTION__, buffer_handle); - native_handle_close(buffer_handle); - native_handle_delete(buffer_handle); - - hidl_cb(error, nullptr); - return Void(); - } - ALOGD_IF(DEBUG, "Imported handle: %p id: %" PRIu64, buffer_handle, - PRIV_HANDLE_CONST(buffer_handle)->id); - hidl_cb(Error::NONE, buffer_handle); - return Void(); -} - -Return QtiMapper::freeBuffer(void *buffer) { - if (!buffer) { - return Error::BAD_BUFFER; - } - return buf_mgr_->ReleaseBuffer(PRIV_HANDLE_CONST(buffer)); -} - -bool QtiMapper::GetFenceFd(const hidl_handle &fence_handle, int *outFenceFd) { - auto handle = fence_handle.getNativeHandle(); - if (handle && handle->numFds > 1) { - ALOGE("invalid fence handle with %d fds", handle->numFds); - return false; - } - - *outFenceFd = (handle && handle->numFds == 1) ? handle->data[0] : -1; - return true; -} - -void QtiMapper::WaitFenceFd(int fence_fd) { - if (fence_fd < 0) { - return; - } - - const int timeout = 3000; - ATRACE_BEGIN("fence wait"); - const int error = sync_wait(fence_fd, timeout); - ATRACE_END(); - if (error < 0) { - ALOGE("QtiMapper: lock fence %d didn't signal in %u ms - error: %s", fence_fd, timeout, - strerror(errno)); - } -} - -Error QtiMapper::LockBuffer(void *buffer, uint64_t usage, const hidl_handle &acquire_fence) { - if (!buffer) { - return Error::BAD_BUFFER; - } - - int fence_fd; - if (!GetFenceFd(acquire_fence, &fence_fd)) { - return Error::BAD_VALUE; - } - - if (fence_fd > 0) { - WaitFenceFd(fence_fd); - } - - auto hnd = PRIV_HANDLE_CONST(buffer); - - return buf_mgr_->LockBuffer(hnd, usage); -} - -Return QtiMapper::lock(void *buffer, uint64_t cpu_usage, - const IMapper::Rect & /*access_region*/, - const hidl_handle &acquire_fence, lock_cb hidl_cb) { - auto err = LockBuffer(buffer, cpu_usage, acquire_fence); - if (err != Error::NONE) { - hidl_cb(err, nullptr); - return Void(); - } - - auto hnd = PRIV_HANDLE_CONST(buffer); - auto *out_data = reinterpret_cast(hnd->base); - hidl_cb(Error::NONE, out_data); - return Void(); -} - -Return QtiMapper::lockYCbCr(void *buffer, uint64_t cpu_usage, - const IMapper::Rect & /*access_region*/, - const hidl_handle &acquire_fence, lockYCbCr_cb hidl_cb) { - YCbCrLayout layout = {}; - auto err = LockBuffer(buffer, cpu_usage, acquire_fence); - if (err != Error::NONE) { - hidl_cb(err, layout); - return Void(); - } - - auto hnd = PRIV_HANDLE_CONST(buffer); - android_ycbcr yuv_plane_info[2]; - if (gralloc::GetYUVPlaneInfo(hnd, yuv_plane_info) != 0) { - hidl_cb(Error::BAD_VALUE, layout); - } - layout.y = yuv_plane_info[0].y; - layout.cr = yuv_plane_info[0].cr; - layout.cb = yuv_plane_info[0].cb; - layout.yStride = static_cast(yuv_plane_info[0].ystride); - layout.cStride = static_cast(yuv_plane_info[0].cstride); - layout.chromaStep = static_cast(yuv_plane_info[0].chroma_step); - hidl_cb(Error::NONE, layout); - return Void(); -} - -Return QtiMapper::unlock(void *buffer, unlock_cb hidl_cb) { - auto err = Error::BAD_BUFFER; - if (buffer != nullptr) { - err = buf_mgr_->UnlockBuffer(PRIV_HANDLE_CONST(buffer)); - } - // We don't have a release fence - hidl_cb(err, hidl_handle(nullptr)); - return Void(); -} - -#ifdef ENABLE_QTI_MAPPER_EXTENSION -Return QtiMapper::getMapSecureBufferFlag(void *buffer, getMapSecureBufferFlag_cb hidl_cb) { - auto err = Error::BAD_BUFFER; - auto hnd = static_cast(buffer); - int *map_secure_buffer = 0; - if (buffer != nullptr && private_handle_t::validate(hnd) != 0) { - if (getMetaData(hnd, GET_MAP_SECURE_BUFFER, map_secure_buffer) != 0) { - *map_secure_buffer = 0; - } else { - err = Error::NONE; - } - } - hidl_cb(err, *map_secure_buffer != 0); - return Void(); -} - -Return QtiMapper::getInterlacedFlag(void *buffer, getInterlacedFlag_cb hidl_cb) { - auto err = Error::BAD_BUFFER; - auto hnd = static_cast(buffer); - int *interlaced_flag = nullptr; - if (buffer != nullptr && private_handle_t::validate(hnd) != 0) { - if (getMetaData(hnd, GET_PP_PARAM_INTERLACED, interlaced_flag) != 0) { - *interlaced_flag = 0; - } else { - err = Error::NONE; - } - } - hidl_cb(err, *interlaced_flag != 0); - return Void(); -} - -Return QtiMapper::getCustomDimensions(void *buffer, getCustomDimensions_cb hidl_cb) { - auto err = Error::BAD_BUFFER; - auto hnd = static_cast(buffer); - int stride = 0; - int height = 0; - if (buffer != nullptr && private_handle_t::validate(hnd) != 0) { - stride = hnd->width; - height = hnd->height; - gralloc::GetCustomDimensions(hnd, &stride, &height); - err = Error::NONE; - } - hidl_cb(err, stride, height); - return Void(); -} - -Return QtiMapper::getRgbDataAddress(void *buffer, getRgbDataAddress_cb hidl_cb) { - auto err = Error::BAD_BUFFER; - auto hnd = static_cast(buffer); - void *rgb_data = nullptr; - if (buffer != nullptr && private_handle_t::validate(hnd) != 0) { - if (gralloc::GetRgbDataAddress(hnd, &rgb_data) == 0) { - err = Error::NONE; - } - } - hidl_cb(err, rgb_data); - return Void(); -} - -Return QtiMapper::calculateBufferAttributes(int32_t width, int32_t height, int32_t format, - uint64_t usage, - calculateBufferAttributes_cb hidl_cb) { - unsigned int alignedw, alignedh; - BufferInfo info(width, height, format, usage); - gralloc::GetAlignedWidthAndHeight(info, &alignedw, &alignedh); - bool ubwc_enabled = gralloc::IsUBwcEnabled(format, usage); - hidl_cb(Error::NONE, alignedw, alignedh, ubwc_enabled); - return Void(); -} - -Return QtiMapper::getColorSpace(void *buffer, getColorSpace_cb hidl_cb) { - auto err = Error::BAD_BUFFER; - auto hnd = static_cast(buffer); - int color_space = 0; - if (buffer != nullptr && private_handle_t::validate(hnd) != 0) { - gralloc::GetColorSpaceFromMetadata(hnd, &color_space); - err = Error::NONE; - } - hidl_cb(err, color_space); - return Void(); -} - -Return QtiMapper::getYuvPlaneInfo(void *buffer, getYuvPlaneInfo_cb hidl_cb) { - auto err = Error::BAD_BUFFER; - auto hnd = static_cast(buffer); - hidl_vec layout; - layout.resize(2); - android_ycbcr yuv_plane_info[2]; - if (buffer != nullptr && private_handle_t::validate(hnd) != 0) { - if (gralloc::GetYUVPlaneInfo(hnd, yuv_plane_info) == 0) { - err = Error::NONE; - for (int i=0; i < 2; i++) { - layout[i].y = yuv_plane_info[i].y; - layout[i].cr = yuv_plane_info[i].cr; - layout[i].cb = yuv_plane_info[i].cb; - layout[i].yStride = static_cast(yuv_plane_info[i].ystride); - layout[i].cStride = static_cast(yuv_plane_info[i].cstride); - layout[i].chromaStep = static_cast(yuv_plane_info[i].chroma_step); - } - } - } - hidl_cb(err, layout); - return Void(); -} - -Return QtiMapper::setSingleBufferMode(void *buffer, bool enable) { - auto err = Error::BAD_BUFFER; - auto hnd = static_cast(buffer); - if (buffer != nullptr && private_handle_t::validate(hnd) != 0) { - if (setMetaData(hnd, SET_SINGLE_BUFFER_MODE, &enable) != 0) { - err = Error::UNSUPPORTED; - } else { - err = Error::NONE; - } - } - return err; -} -#endif - -// Methods from ::android::hidl::base::V1_0::IBase follow. - -// When we are in passthrough mode, this method is used -// by hidl to obtain the SP HAL object -IMapper *HIDL_FETCH_IMapper(const char * /* name */) { - ALOGD_IF(DEBUG, "Fetching IMapper from QtiMapper"); - auto mapper = new QtiMapper(); - return static_cast(mapper); -} - -} // namespace implementation -} // namespace V1_0 -} // namespace mapper -} // namespace display -} // namespace hardware -} // namespace qti -} // namespace vendor diff --git a/gralloc/QtiMapper.h b/gralloc/QtiMapper.h deleted file mode 100644 index 218f0749..00000000 --- a/gralloc/QtiMapper.h +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2018, The Linux Foundation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of The Linux Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __QTIMAPPER_H__ -#define __QTIMAPPER_H__ - -#include -#include - -#include "gr_buf_mgr.h" -namespace vendor { -namespace qti { -namespace hardware { -namespace display { -namespace mapper { -namespace V1_0 { -namespace implementation { - -using ::android::hardware::Return; -using ::android::hardware::Void; -using ::android::hardware::graphics::mapper::V2_0::Error; -using ::android::hardware::graphics::mapper::V2_0::IMapper; -using ::android::hardware::graphics::mapper::V2_0::YCbCrLayout; -using ::android::hardware::hidl_array; -using ::android::hardware::hidl_handle; -using ::android::hardware::hidl_memory; -using ::android::hardware::hidl_string; -using ::android::hardware::hidl_vec; -using ::android::hidl::base::V1_0::DebugInfo; -using ::android::hidl::base::V1_0::IBase; -using ::android::sp; -using gralloc::BufferManager; - -class QtiMapper : public IMapper { - public: - QtiMapper(); - // Methods from ::android::hardware::graphics::mapper::V2_0::IMapper follow. - Return createDescriptor(const IMapper::BufferDescriptorInfo &descriptor_info, - createDescriptor_cb hidl_cb) override; - Return importBuffer(const hidl_handle &raw_handle, importBuffer_cb hidl_cb) override; - Return freeBuffer(void *buffer) override; - Return lock(void *buffer, uint64_t cpu_usage, const IMapper::Rect &access_region, - const hidl_handle &acquire_fence, lock_cb hidl_cb) override; - Return lockYCbCr(void *buffer, uint64_t cpu_usage, const IMapper::Rect &access_region, - const hidl_handle &acquire_fence, lockYCbCr_cb hidl_cb) override; - Return unlock(void *buffer, unlock_cb hidl_cb) override; - -#ifdef ENABLE_QTI_MAPPER_EXTENSION - Return getMapSecureBufferFlag(void *buffer, getMapSecureBufferFlag_cb _hidl_cb) override; - Return getInterlacedFlag(void *buffer, getInterlacedFlag_cb _hidl_cb) override; - Return getCustomDimensions(void *buffer, getCustomDimensions_cb _hidl_cb) override; - Return getRgbDataAddress(void *buffer, getRgbDataAddress_cb _hidl_cb) override; - Return calculateBufferAttributes(int32_t width, int32_t height, int32_t format, - uint64_t usage, - calculateBufferAttributes_cb _hidl_cb) override; - Return getColorSpace(void *buffer, getColorSpace_cb _hidl_cb) override; - Return getYuvPlaneInfo(void *buffer, getYuvPlaneInfo_cb _hidl_cb) override; - Return setSingleBufferMode(void *buffer, bool enable) override; -#endif - - private: - BufferManager *buf_mgr_ = nullptr; - bool ValidDescriptor(const IMapper::BufferDescriptorInfo &bd); - bool GetFenceFd(const hidl_handle &fence_handle, int *outFenceFd); - void WaitFenceFd(int fence_fd); - Error LockBuffer(void *buffer, uint64_t usage, const hidl_handle &acquire_fence); -}; - -extern "C" IMapper *HIDL_FETCH_IMapper(const char *name); -} // namespace implementation -} // namespace V1_0 -} // namespace mapper -} // namespace display -} // namespace hardware -} // namespace qti -} // namespace vendor - -#endif // __QTIMAPPER_H__ diff --git a/gralloc/gr_adreno_info.cpp b/gralloc/gr_adreno_info.cpp deleted file mode 100644 index 03aacffe..00000000 --- a/gralloc/gr_adreno_info.cpp +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Copyright (c) 2011-2018, The Linux Foundation. All rights reserved. - - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of The Linux Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include - -#include "gr_adreno_info.h" -#include "gr_utils.h" -#include "gralloc_priv.h" - -using std::lock_guard; -using std::mutex; - -namespace gralloc { - -AdrenoMemInfo *AdrenoMemInfo::s_instance = nullptr; - -AdrenoMemInfo *AdrenoMemInfo::GetInstance() { - static mutex s_lock; - lock_guard obj(s_lock); - if (!s_instance) { - s_instance = new AdrenoMemInfo(); - } - - return s_instance; -} - -AdrenoMemInfo::AdrenoMemInfo() { - libadreno_utils_ = ::dlopen("libadreno_utils.so", RTLD_NOW); - if (libadreno_utils_) { - *reinterpret_cast(&LINK_adreno_compute_aligned_width_and_height) = - ::dlsym(libadreno_utils_, "compute_aligned_width_and_height"); - *reinterpret_cast(&LINK_adreno_compute_fmt_aligned_width_and_height) = - ::dlsym(libadreno_utils_, "compute_fmt_aligned_width_and_height"); - *reinterpret_cast(&LINK_adreno_compute_padding) = - ::dlsym(libadreno_utils_, "compute_surface_padding"); - *reinterpret_cast(&LINK_adreno_compute_compressedfmt_aligned_width_and_height) = - ::dlsym(libadreno_utils_, "compute_compressedfmt_aligned_width_and_height"); - *reinterpret_cast(&LINK_adreno_isUBWCSupportedByGpu) = - ::dlsym(libadreno_utils_, "isUBWCSupportedByGpu"); - *reinterpret_cast(&LINK_adreno_get_gpu_pixel_alignment) = - ::dlsym(libadreno_utils_, "get_gpu_pixel_alignment"); - } else { - ALOGE(" Failed to load libadreno_utils.so"); - } - - // Check if the overriding property debug.gralloc.gfx_ubwc_disable - // that disables UBWC allocations for the graphics stack is set - char property[PROPERTY_VALUE_MAX]; - property_get(DISABLE_UBWC_PROP, property, "0"); - if (!(strncmp(property, "1", PROPERTY_VALUE_MAX)) || - !(strncmp(property, "true", PROPERTY_VALUE_MAX))) { - gfx_ubwc_disable_ = true; - } - -} - -AdrenoMemInfo::~AdrenoMemInfo() { - if (libadreno_utils_) { - ::dlclose(libadreno_utils_); - } -} - -void AdrenoMemInfo::AlignUnCompressedRGB(int width, int height, int format, int tile_enabled, - unsigned int *aligned_w, unsigned int *aligned_h) { - *aligned_w = (unsigned int)ALIGN(width, 32); - *aligned_h = (unsigned int)ALIGN(height, 32); - - int bpp = 4; - switch (format) { - case HAL_PIXEL_FORMAT_RGB_888: - case HAL_PIXEL_FORMAT_BGR_888: - bpp = 3; - break; - case HAL_PIXEL_FORMAT_RGB_565: - case HAL_PIXEL_FORMAT_BGR_565: - case HAL_PIXEL_FORMAT_RGBA_5551: - case HAL_PIXEL_FORMAT_RGBA_4444: - bpp = 2; - break; - default: - break; - } - - int raster_mode = 0; // Adreno unknown raster mode. - int padding_threshold = 512; // Threshold for padding surfaces. - // the function below computes aligned width and aligned height - // based on linear or macro tile mode selected. - if (LINK_adreno_compute_fmt_aligned_width_and_height) { - // We call into adreno_utils only for RGB formats. So plane_id is 0 and - // num_samples is 1 always. We may have to add uitility function to - // find out these if there is a need to call this API for YUV formats. - LINK_adreno_compute_fmt_aligned_width_and_height( - width, height, 0 /*plane_id*/, GetGpuPixelFormat(format), 1 /*num_samples*/, tile_enabled, - raster_mode, padding_threshold, reinterpret_cast(aligned_w), - reinterpret_cast(aligned_h)); - } else if (LINK_adreno_compute_aligned_width_and_height) { - LINK_adreno_compute_aligned_width_and_height( - width, height, bpp, tile_enabled, raster_mode, padding_threshold, - reinterpret_cast(aligned_w), reinterpret_cast(aligned_h)); - } else if (LINK_adreno_compute_padding) { - int surface_tile_height = 1; // Linear surface - *aligned_w = UINT(LINK_adreno_compute_padding(width, bpp, surface_tile_height, raster_mode, - padding_threshold)); - ALOGW("%s: Warning!! Old GFX API is used to calculate stride", __FUNCTION__); - } else { - ALOGW( - "%s: Warning!! Symbols compute_surface_padding and " - "compute_fmt_aligned_width_and_height and " - "compute_aligned_width_and_height not found", - __FUNCTION__); - } -} - -void AdrenoMemInfo::AlignCompressedRGB(int width, int height, int format, unsigned int *aligned_w, - unsigned int *aligned_h) { - if (LINK_adreno_compute_compressedfmt_aligned_width_and_height) { - int bytesPerPixel = 0; - int raster_mode = 0; // Adreno unknown raster mode. - int padding_threshold = 512; // Threshold for padding - // surfaces. - - LINK_adreno_compute_compressedfmt_aligned_width_and_height( - width, height, format, 0, raster_mode, padding_threshold, - reinterpret_cast(aligned_w), reinterpret_cast(aligned_h), &bytesPerPixel); - } else { - *aligned_w = (unsigned int)ALIGN(width, 32); - *aligned_h = (unsigned int)ALIGN(height, 32); - ALOGW("%s: Warning!! compute_compressedfmt_aligned_width_and_height not found", __FUNCTION__); - } -} - -bool AdrenoMemInfo::IsUBWCSupportedByGPU(int format) { - if (!gfx_ubwc_disable_ && LINK_adreno_isUBWCSupportedByGpu) { - ADRENOPIXELFORMAT gpu_format = GetGpuPixelFormat(format); - return LINK_adreno_isUBWCSupportedByGpu(gpu_format); - } - - return false; -} - -uint32_t AdrenoMemInfo::GetGpuPixelAlignment() { - if (LINK_adreno_get_gpu_pixel_alignment) { - return LINK_adreno_get_gpu_pixel_alignment(); - } - - return 1; -} - -ADRENOPIXELFORMAT AdrenoMemInfo::GetGpuPixelFormat(int hal_format) { - switch (hal_format) { - case HAL_PIXEL_FORMAT_RGBA_8888: - return ADRENO_PIXELFORMAT_R8G8B8A8; - case HAL_PIXEL_FORMAT_RGBX_8888: - return ADRENO_PIXELFORMAT_R8G8B8X8; - case HAL_PIXEL_FORMAT_BGRA_8888: - return ADRENO_PIXELFORMAT_B8G8R8A8; - case HAL_PIXEL_FORMAT_RGB_888: - return ADRENO_PIXELFORMAT_R8G8B8; - case HAL_PIXEL_FORMAT_RGB_565: - return ADRENO_PIXELFORMAT_B5G6R5; - case HAL_PIXEL_FORMAT_BGR_565: - return ADRENO_PIXELFORMAT_R5G6B5; - case HAL_PIXEL_FORMAT_RGBA_5551: - return ADRENO_PIXELFORMAT_R5G5B5A1; - case HAL_PIXEL_FORMAT_RGBA_4444: - return ADRENO_PIXELFORMAT_R4G4B4A4; - case HAL_PIXEL_FORMAT_RGBA_1010102: - return ADRENO_PIXELFORMAT_R10G10B10A2_UNORM; - case HAL_PIXEL_FORMAT_RGBX_1010102: - return ADRENO_PIXELFORMAT_R10G10B10X2_UNORM; - case HAL_PIXEL_FORMAT_ABGR_2101010: - return ADRENO_PIXELFORMAT_A2B10G10R10_UNORM; - case HAL_PIXEL_FORMAT_RGBA_FP16: - return ADRENO_PIXELFORMAT_R16G16B16A16_FLOAT; - case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: - return ADRENO_PIXELFORMAT_NV12; - case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS: - case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC: - return ADRENO_PIXELFORMAT_NV12_EXT; - case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC: - return ADRENO_PIXELFORMAT_TP10; - case HAL_PIXEL_FORMAT_YCbCr_420_P010: - case HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC: - case HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS: - return ADRENO_PIXELFORMAT_P010; - default: - ALOGE("%s: No map for format: 0x%x", __FUNCTION__, hal_format); - break; - } - - return ADRENO_PIXELFORMAT_UNKNOWN; -} - -} // namespace gralloc diff --git a/gralloc/gr_adreno_info.h b/gralloc/gr_adreno_info.h deleted file mode 100644 index b85e7c1d..00000000 --- a/gralloc/gr_adreno_info.h +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (c) 2011-2018, The Linux Foundation. All rights reserved. - - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of The Linux Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __GR_ADRENO_INFO_H__ -#define __GR_ADRENO_INFO_H__ - -#include - -namespace gralloc { - -// Adreno Pixel Formats -typedef enum { - ADRENO_PIXELFORMAT_UNKNOWN = 0, - ADRENO_PIXELFORMAT_R16G16B16A16_FLOAT = 10, - ADRENO_PIXELFORMAT_R10G10B10A2_UNORM = 24, // Vertex, Normalized GL_UNSIGNED_INT_10_10_10_2_OES - ADRENO_PIXELFORMAT_R8G8B8A8 = 28, - ADRENO_PIXELFORMAT_R8G8B8A8_SRGB = 29, - ADRENO_PIXELFORMAT_B5G6R5 = 85, - ADRENO_PIXELFORMAT_B5G5R5A1 = 86, - ADRENO_PIXELFORMAT_B8G8R8A8 = 90, - ADRENO_PIXELFORMAT_B8G8R8A8_SRGB = 91, - ADRENO_PIXELFORMAT_B8G8R8X8_SRGB = 93, - ADRENO_PIXELFORMAT_NV12 = 103, - ADRENO_PIXELFORMAT_P010 = 104, - ADRENO_PIXELFORMAT_YUY2 = 107, - ADRENO_PIXELFORMAT_B4G4R4A4 = 115, - ADRENO_PIXELFORMAT_NV12_EXT = 506, // NV12 with non-std alignment and offsets - ADRENO_PIXELFORMAT_R8G8B8X8 = 507, // GL_RGB8 (Internal) - ADRENO_PIXELFORMAT_R8G8B8 = 508, // GL_RGB8 - ADRENO_PIXELFORMAT_A1B5G5R5 = 519, // GL_RGB5_A1 - ADRENO_PIXELFORMAT_R8G8B8X8_SRGB = 520, // GL_SRGB8 - ADRENO_PIXELFORMAT_R8G8B8_SRGB = 521, // GL_SRGB8 - ADRENO_PIXELFORMAT_A2B10G10R10_UNORM = 532, - // Vertex, Normalized GL_UNSIGNED_INT_10_10_10_2_OES - ADRENO_PIXELFORMAT_R10G10B10X2_UNORM = 537, - // Vertex, Normalized GL_UNSIGNED_INT_10_10_10_2_OES - ADRENO_PIXELFORMAT_R5G6B5 = 610, // RGBA version of B5G6R5 - ADRENO_PIXELFORMAT_R5G5B5A1 = 611, // RGBA version of B5G5R5A1 - ADRENO_PIXELFORMAT_R4G4B4A4 = 612, // RGBA version of B4G4R4A4 - ADRENO_PIXELFORMAT_UYVY = 614, // YUV 4:2:2 packed progressive (1 plane) - ADRENO_PIXELFORMAT_NV21 = 619, - ADRENO_PIXELFORMAT_Y8U8V8A8 = 620, // YUV 4:4:4 packed (1 plane) - ADRENO_PIXELFORMAT_Y8 = 625, // Single 8-bit luma only channel YUV format - ADRENO_PIXELFORMAT_TP10 = 654, // YUV 4:2:0 planar 10 bits/comp (2 planes) -} ADRENOPIXELFORMAT; - -class AdrenoMemInfo { - public: - /* - * Function to compute aligned width and aligned height based on - * width, height, format and usage flags. - * - * @return aligned width, aligned height - */ - void GetAlignedWidthAndHeight(int width, int height, int format, int usage, - unsigned int *aligned_w, unsigned int *aligned_h, bool ubwc_enabled, - bool tile_enabled); - - /* - * Function to compute the adreno aligned width and aligned height - * based on the width and format. - * - * @return aligned width, aligned height - */ - void AlignUnCompressedRGB(int width, int height, int format, int tileEnabled, - unsigned int *aligned_w, unsigned int *aligned_h); - - /* - * Function to compute the adreno aligned width and aligned height - * based on the width and format. - * - * @return aligned width, aligned height - */ - void AlignCompressedRGB(int width, int height, int format, unsigned int *aligned_w, - unsigned int *aligned_h); - - /* - * Function to compute the pixel alignment requirement. - * - * @return alignment - */ - uint32_t GetGpuPixelAlignment(); - - /* - * Function to query whether GPU supports UBWC for given HAL format - * @return > 0 : supported - * 0 : not supported - */ - bool IsUBWCSupportedByGPU(int format); - - /* - * Function to get the corresponding Adreno format for given HAL format - */ - ADRENOPIXELFORMAT GetGpuPixelFormat(int hal_format); - - static AdrenoMemInfo *GetInstance(); - - private: - AdrenoMemInfo(); - ~AdrenoMemInfo(); - // link(s)to adreno surface padding library. - int (*LINK_adreno_compute_padding)(int width, int bpp, int surface_tile_height, - int screen_tile_height, int padding_threshold) = NULL; - void (*LINK_adreno_compute_aligned_width_and_height)(int width, int height, int bpp, - int tile_mode, int raster_mode, - int padding_threshold, int *aligned_w, - int *aligned_h) = NULL; - void (*LINK_adreno_compute_fmt_aligned_width_and_height)(int width, int height, int plane_id, - int format, int num_samples, - int tile_mode, int raster_mode, - int padding_threshold, int *aligned_w, - int *aligned_h) = NULL; - void (*LINK_adreno_compute_compressedfmt_aligned_width_and_height)( - int width, int height, int format, int tile_mode, int raster_mode, int padding_threshold, - int *aligned_w, int *aligned_h, int *bpp) = NULL; - int (*LINK_adreno_isUBWCSupportedByGpu)(ADRENOPIXELFORMAT format) = NULL; - unsigned int (*LINK_adreno_get_gpu_pixel_alignment)() = NULL; - - bool gfx_ubwc_disable_ = false; - void *libadreno_utils_ = NULL; - - static AdrenoMemInfo *s_instance; -}; - -} // namespace gralloc - -#endif // __GR_ADRENO_INFO_H__ diff --git a/gralloc/gr_allocator.cpp b/gralloc/gr_allocator.cpp deleted file mode 100644 index 912ada03..00000000 --- a/gralloc/gr_allocator.cpp +++ /dev/null @@ -1,301 +0,0 @@ -/* - * Copyright (c) 2011-2018, The Linux Foundation. All rights reserved. - - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of The Linux Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include - -#include "gr_allocator.h" -#include "gr_utils.h" -#include "gralloc_priv.h" - -#include "qd_utils.h" - -#ifndef ION_FLAG_CP_PIXEL -#define ION_FLAG_CP_PIXEL 0 -#endif - -#ifndef ION_FLAG_ALLOW_NON_CONTIG -#define ION_FLAG_ALLOW_NON_CONTIG 0 -#endif - -#ifndef ION_FLAG_CP_CAMERA_PREVIEW -#define ION_FLAG_CP_CAMERA_PREVIEW 0 -#endif - -#ifdef MASTER_SIDE_CP -#define CP_HEAP_ID ION_SECURE_HEAP_ID -#define SD_HEAP_ID ION_SECURE_DISPLAY_HEAP_ID -#define ION_CP_FLAGS (ION_SECURE | ION_FLAG_CP_PIXEL) -#define ION_SD_FLAGS (ION_SECURE | ION_FLAG_CP_SEC_DISPLAY) -#define ION_SC_FLAGS (ION_SECURE | ION_FLAG_CP_CAMERA) -#define ION_SC_PREVIEW_FLAGS (ION_SECURE | ION_FLAG_CP_CAMERA_PREVIEW) -#else // SLAVE_SIDE_CP -#define CP_HEAP_ID ION_CP_MM_HEAP_ID -#define SD_HEAP_ID CP_HEAP_ID -#define ION_CP_FLAGS (ION_SECURE | ION_FLAG_ALLOW_NON_CONTIG) -#define ION_SD_FLAGS ION_SECURE -#define ION_SC_FLAGS ION_SECURE -#define ION_SC_PREVIEW_FLAGS ION_SECURE -#endif - -using std::shared_ptr; -using std::vector; - -namespace gralloc { - -static BufferInfo GetBufferInfo(const BufferDescriptor &descriptor) { - return BufferInfo(descriptor.GetWidth(), descriptor.GetHeight(), descriptor.GetFormat(), - descriptor.GetUsage()); -} - -Allocator::Allocator() : ion_allocator_(nullptr) {} - -bool Allocator::Init() { - ion_allocator_ = new IonAlloc(); - if (!ion_allocator_->Init()) { - return false; - } - - return true; -} - -Allocator::~Allocator() { - if (ion_allocator_) { - delete ion_allocator_; - } -} - -int Allocator::AllocateMem(AllocData *alloc_data, uint64_t usage) { - int ret; - alloc_data->uncached = UseUncached(usage); - - // After this point we should have the right heap set, there is no fallback - GetIonHeapInfo(usage, &alloc_data->heap_id, &alloc_data->alloc_type, &alloc_data->flags); - - ret = ion_allocator_->AllocBuffer(alloc_data); - if (ret >= 0) { - alloc_data->alloc_type |= private_handle_t::PRIV_FLAGS_USES_ION; - } else { - ALOGE("%s: Failed to allocate buffer - heap: 0x%x flags: 0x%x", __FUNCTION__, - alloc_data->heap_id, alloc_data->flags); - } - - return ret; -} - -int Allocator::MapBuffer(void **base, unsigned int size, unsigned int offset, int fd) { - if (ion_allocator_) { - return ion_allocator_->MapBuffer(base, size, offset, fd); - } - - return -EINVAL; -} - -int Allocator::ImportBuffer(int fd) { - if (ion_allocator_) { - return ion_allocator_->ImportBuffer(fd); - } - return -EINVAL; -} - -int Allocator::FreeBuffer(void *base, unsigned int size, unsigned int offset, int fd, int handle) { - if (ion_allocator_) { - return ion_allocator_->FreeBuffer(base, size, offset, fd, handle); - } - - return -EINVAL; -} - -int Allocator::CleanBuffer(void *base, unsigned int size, unsigned int offset, int handle, int op) { - if (ion_allocator_) { - return ion_allocator_->CleanBuffer(base, size, offset, handle, op); - } - - return -EINVAL; -} - -bool Allocator::CheckForBufferSharing(uint32_t num_descriptors, - const vector> &descriptors, - ssize_t *max_index) { - unsigned int cur_heap_id = 0, prev_heap_id = 0; - unsigned int cur_alloc_type = 0, prev_alloc_type = 0; - unsigned int cur_ion_flags = 0, prev_ion_flags = 0; - bool cur_uncached = false, prev_uncached = false; - unsigned int alignedw, alignedh; - unsigned int max_size = 0; - - *max_index = -1; - for (uint32_t i = 0; i < num_descriptors; i++) { - // Check Cached vs non-cached and all the ION flags - cur_uncached = UseUncached(descriptors[i]->GetUsage()); - GetIonHeapInfo(descriptors[i]->GetUsage(), &cur_heap_id, &cur_alloc_type, &cur_ion_flags); - - if (i > 0 && (cur_heap_id != prev_heap_id || cur_alloc_type != prev_alloc_type || - cur_ion_flags != prev_ion_flags)) { - return false; - } - - // For same format type, find the descriptor with bigger size - GetAlignedWidthAndHeight(GetBufferInfo(*descriptors[i]), &alignedw, &alignedh); - unsigned int size = GetSize(GetBufferInfo(*descriptors[i]), alignedw, alignedh); - if (max_size < size) { - *max_index = INT(i); - max_size = size; - } - - prev_heap_id = cur_heap_id; - prev_uncached = cur_uncached; - prev_ion_flags = cur_ion_flags; - prev_alloc_type = cur_alloc_type; - } - - return true; -} - -int Allocator::GetImplDefinedFormat(uint64_t usage, int format) { - int gr_format = format; - - // If input format is HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED then based on - // the usage bits, gralloc assigns a format. - if (format == HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED || - format == HAL_PIXEL_FORMAT_YCbCr_420_888) { - if (usage & GRALLOC_USAGE_PRIVATE_ALLOC_UBWC) { - // Use of 10BIT_TP and 10BIT bits is supposed to be mutually exclusive. - // Each bit maps to only one format. Here we will check one of the bits - // and ignore the other. - if (usage & GRALLOC_USAGE_PRIVATE_10BIT_TP) { - gr_format = HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC; - } else if (usage & GRALLOC_USAGE_PRIVATE_10BIT) { - gr_format = HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC; - } else { - gr_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC; - } - } else if (usage & GRALLOC_USAGE_PRIVATE_10BIT) { - gr_format = HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS; - } else if (usage & BufferUsage::VIDEO_ENCODER) { - gr_format = HAL_PIXEL_FORMAT_NV12_ENCODEABLE; // NV12 - } else if (usage & BufferUsage::CAMERA_INPUT) { - if (usage & BufferUsage::CAMERA_OUTPUT) { - // Assumed ZSL if both producer and consumer camera flags set - gr_format = HAL_PIXEL_FORMAT_NV21_ZSL; // NV21 - } else { - gr_format = HAL_PIXEL_FORMAT_YCrCb_420_SP; // NV21 - } - } else if (usage & BufferUsage::CAMERA_OUTPUT) { - if (format == HAL_PIXEL_FORMAT_YCbCr_420_888) { - gr_format = HAL_PIXEL_FORMAT_NV21_ZSL; // NV21 - } else { - gr_format = HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS; // NV12 preview - } - } else if (usage & BufferUsage::COMPOSER_OVERLAY) { - // XXX: If we still haven't set a format, default to RGBA8888 - gr_format = HAL_PIXEL_FORMAT_RGBA_8888; - } else if (format == HAL_PIXEL_FORMAT_YCbCr_420_888) { - // If no other usage flags are detected, default the - // flexible YUV format to NV21_ZSL - gr_format = HAL_PIXEL_FORMAT_NV21_ZSL; - } - } - - return gr_format; -} - -/* The default policy is to return cached buffers unless the client explicity - * sets the PRIVATE_UNCACHED flag or indicates that the buffer will be rarely - * read or written in software. */ -bool Allocator::UseUncached(uint64_t usage) { - if ((usage & GRALLOC_USAGE_PRIVATE_UNCACHED) || (usage & BufferUsage::PROTECTED)) { - return true; - } - - // CPU read rarely - if ((usage & BufferUsage::CPU_READ_MASK) == static_cast(BufferUsage::CPU_READ_RARELY)) { - return true; - } - - // CPU write rarely - if ((usage & BufferUsage::CPU_WRITE_MASK) == - static_cast(BufferUsage::CPU_WRITE_RARELY)) { - return true; - } - - if ((usage & BufferUsage::SENSOR_DIRECT_DATA) || (usage & BufferUsage::GPU_DATA_BUFFER)) { - return true; - } - - return false; -} - -void Allocator::GetIonHeapInfo(uint64_t usage, unsigned int *ion_heap_id, unsigned int *alloc_type, - unsigned int *ion_flags) { - unsigned int heap_id = 0; - unsigned int type = 0; - uint32_t flags = 0; - if (usage & GRALLOC_USAGE_PROTECTED) { - if (usage & GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY) { - heap_id = ION_HEAP(SD_HEAP_ID); - /* - * There is currently no flag in ION for Secure Display - * VM. Please add it to the define once available. - */ - flags |= UINT(ION_SD_FLAGS); - } else if (usage & BufferUsage::CAMERA_OUTPUT) { - heap_id = ION_HEAP(SD_HEAP_ID); - if (usage & BufferUsage::COMPOSER_OVERLAY) { - flags |= UINT(ION_SC_PREVIEW_FLAGS); - } else { - flags |= UINT(ION_SC_FLAGS); - } - } else { - heap_id = ION_HEAP(CP_HEAP_ID); - flags |= UINT(ION_CP_FLAGS); - } - } - - if (usage & BufferUsage::SENSOR_DIRECT_DATA) { - heap_id |= ION_HEAP(ION_ADSP_HEAP_ID); - } - - if (flags & UINT(ION_SECURE)) { - type |= private_handle_t::PRIV_FLAGS_SECURE_BUFFER; - } - - // if no ion heap flags are set, default to system heap - if (!heap_id) { - heap_id = ION_HEAP(ION_SYSTEM_HEAP_ID); - } - - *alloc_type = type; - *ion_flags = flags; - *ion_heap_id = heap_id; - - return; -} -} // namespace gralloc diff --git a/gralloc/gr_allocator.h b/gralloc/gr_allocator.h deleted file mode 100644 index fd316efc..00000000 --- a/gralloc/gr_allocator.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2011-2018, The Linux Foundation. All rights reserved. - - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of The Linux Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __GR_ALLOCATOR_H__ -#define __GR_ALLOCATOR_H__ - -#ifdef MASTER_SIDE_CP -#define SECURE_ALIGN SZ_4K -#else -#define SECURE_ALIGN SZ_1M -#endif - -#include - -#include "gr_buf_descriptor.h" -#include "gr_ion_alloc.h" -#include "gralloc_priv.h" - -namespace gralloc { - -class Allocator { - public: - Allocator(); - ~Allocator(); - bool Init(); - int MapBuffer(void **base, unsigned int size, unsigned int offset, int fd); - int ImportBuffer(int fd); - int FreeBuffer(void *base, unsigned int size, unsigned int offset, int fd, int handle); - int CleanBuffer(void *base, unsigned int size, unsigned int offset, int handle, int op); - int AllocateMem(AllocData *data, uint64_t usage); - // @return : index of the descriptor with maximum buffer size req - bool CheckForBufferSharing(uint32_t num_descriptors, - const std::vector> &descriptors, - ssize_t *max_index); - int GetImplDefinedFormat(uint64_t usage, int format); - bool UseUncached(uint64_t usage); - - private: - void GetIonHeapInfo(uint64_t usage, unsigned int *ion_heap_id, unsigned int *alloc_type, - unsigned int *ion_flags); - - IonAlloc *ion_allocator_ = NULL; -}; - -} // namespace gralloc - -#endif // __GR_ALLOCATOR_H__ diff --git a/gralloc/gr_buf_descriptor.h b/gralloc/gr_buf_descriptor.h deleted file mode 100644 index 932db33e..00000000 --- a/gralloc/gr_buf_descriptor.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved. - - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of The Linux Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __GR_BUF_DESCRIPTOR_H__ -#define __GR_BUF_DESCRIPTOR_H__ - -#include -#include - -namespace gralloc { -using android::hardware::graphics::mapper::V2_0::Error; -using android::hardware::graphics::mapper::V2_0::IMapper; -using android::hardware::hidl_vec; - -const uint32_t kBufferDescriptorSize = 7; -const uint32_t kMagicVersion = 0x76312E30; // v1.0 - -class BufferDescriptor { - public: - BufferDescriptor() {} - explicit BufferDescriptor(uint64_t id) : id_(id) {} - - static hidl_vec Encode(const IMapper::BufferDescriptorInfo &bd_info) { - hidl_vec out; - out.resize(kBufferDescriptorSize); - out[0] = kMagicVersion; - out[1] = bd_info.width; - out[2] = bd_info.height; - out[3] = bd_info.layerCount; - out[4] = static_cast(bd_info.format); - out[5] = static_cast(bd_info.usage); - out[6] = static_cast(bd_info.usage >> 32); - return out; - } - - Error Decode(const hidl_vec &in) { - if (in.size() != kBufferDescriptorSize || in[0] != kMagicVersion) { - return Error::BAD_DESCRIPTOR; - } - width_ = static_cast(in[1]); - height_ = static_cast(in[2]); - layer_count_ = in[3]; - format_ = static_cast(in[4]); - usage_ = static_cast(in[6]) << 32 | in[5]; - return Error::NONE; - } - - void SetUsage(uint64_t usage) { usage_ |= usage; } - - void SetDimensions(int w, int h) { - width_ = w; - height_ = h; - } - - void SetColorFormat(int format) { format_ = format; } - - void SetLayerCount(uint32_t layer_count) { layer_count_ = layer_count; } - - uint64_t GetUsage() const { return usage_; } - - int GetWidth() const { return width_; } - - int GetHeight() const { return height_; } - - int GetFormat() const { return format_; } - - uint32_t GetLayerCount() const { return layer_count_; } - - uint64_t GetId() const { return id_; } - - private: - int width_ = -1; - int height_ = -1; - int format_ = -1; - uint32_t layer_count_ = 1; - uint64_t usage_ = 0; - const uint64_t id_ = 0; -}; -}; // namespace gralloc -#endif // __GR_BUF_DESCRIPTOR_H__ diff --git a/gralloc/gr_buf_mgr.cpp b/gralloc/gr_buf_mgr.cpp deleted file mode 100644 index 687f3c1f..00000000 --- a/gralloc/gr_buf_mgr.cpp +++ /dev/null @@ -1,399 +0,0 @@ -/* - * Copyright (c) 2011-2018 The Linux Foundation. All rights reserved. - * Not a Contribution - * - * Copyright (C) 2010 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 DEBUG 0 - -#include -#include -#include -#include - -#include "gr_buf_descriptor.h" -#include "gr_buf_mgr.h" -#include "gr_priv_handle.h" -#include "gr_utils.h" -#include "qdMetaData.h" -#include "qd_utils.h" - -namespace gralloc { - -static BufferInfo GetBufferInfo(const BufferDescriptor &descriptor) { - return BufferInfo(descriptor.GetWidth(), descriptor.GetHeight(), descriptor.GetFormat(), - descriptor.GetUsage()); -} - -BufferManager::BufferManager() : next_id_(0) { - handles_map_.clear(); - allocator_ = new Allocator(); - allocator_->Init(); -} - -BufferManager *BufferManager::GetInstance() { - static BufferManager *instance = new BufferManager(); - return instance; -} - -BufferManager::~BufferManager() { - if (allocator_) { - delete allocator_; - } -} - -Error BufferManager::FreeBuffer(std::shared_ptr buf) { - auto hnd = buf->handle; - ALOGD_IF(DEBUG, "FreeBuffer handle:%p", hnd); - - if (private_handle_t::validate(hnd) != 0) { - ALOGE("FreeBuffer: Invalid handle: %p", hnd); - return Error::BAD_BUFFER; - } - - if (allocator_->FreeBuffer(reinterpret_cast(hnd->base), hnd->size, hnd->offset, hnd->fd, - buf->ion_handle_main) != 0) { - return Error::BAD_BUFFER; - } - - unsigned int meta_size = ALIGN((unsigned int)sizeof(MetaData_t), PAGE_SIZE); - if (allocator_->FreeBuffer(reinterpret_cast(hnd->base_metadata), meta_size, - hnd->offset_metadata, hnd->fd_metadata, buf->ion_handle_meta) != 0) { - return Error::BAD_BUFFER; - } - - private_handle_t *handle = const_cast(hnd); - handle->fd = -1; - handle->fd_metadata = -1; - if (!(handle->flags & private_handle_t::PRIV_FLAGS_CLIENT_ALLOCATED)) { - delete handle; - } - return Error::NONE; -} - -void BufferManager::RegisterHandleLocked(const private_handle_t *hnd, int ion_handle, - int ion_handle_meta) { - auto buffer = std::make_shared(hnd, ion_handle, ion_handle_meta); - handles_map_.emplace(std::make_pair(hnd, buffer)); -} - -Error BufferManager::ImportHandleLocked(private_handle_t *hnd) { - ALOGD_IF(DEBUG, "Importing handle:%p id: %" PRIu64, hnd, hnd->id); - int ion_handle = allocator_->ImportBuffer(hnd->fd); - if (ion_handle < 0) { - ALOGE("Failed to import ion buffer: hnd: %p, fd:%d, id:%" PRIu64, hnd, hnd->fd, hnd->id); - return Error::BAD_BUFFER; - } - int ion_handle_meta = allocator_->ImportBuffer(hnd->fd_metadata); - if (ion_handle_meta < 0) { - ALOGE("Failed to import ion metadata buffer: hnd: %p, fd:%d, id:%" PRIu64, hnd, hnd->fd, - hnd->id); - return Error::BAD_BUFFER; - } - // Set base pointers to NULL since the data here was received over binder - hnd->base = 0; - hnd->base_metadata = 0; - RegisterHandleLocked(hnd, ion_handle, ion_handle_meta); - return Error::NONE; -} - -std::shared_ptr BufferManager::GetBufferFromHandleLocked( - const private_handle_t *hnd) { - auto it = handles_map_.find(hnd); - if (it != handles_map_.end()) { - return it->second; - } else { - return nullptr; - } -} - -Error BufferManager::MapBuffer(private_handle_t const *handle) { - private_handle_t *hnd = const_cast(handle); - ALOGD_IF(DEBUG, "Map buffer handle:%p id: %" PRIu64, hnd, hnd->id); - - hnd->base = 0; - if (allocator_->MapBuffer(reinterpret_cast(&hnd->base), hnd->size, hnd->offset, - hnd->fd) != 0) { - return Error::BAD_BUFFER; - } - return Error::NONE; -} - -Error BufferManager::RetainBuffer(private_handle_t const *hnd) { - ALOGD_IF(DEBUG, "Retain buffer handle:%p id: %" PRIu64, hnd, hnd->id); - auto err = Error::NONE; - std::lock_guard lock(buffer_lock_); - auto buf = GetBufferFromHandleLocked(hnd); - if (buf != nullptr) { - buf->IncRef(); - } else { - private_handle_t *handle = const_cast(hnd); - err = ImportHandleLocked(handle); - } - return err; -} - -Error BufferManager::ReleaseBuffer(private_handle_t const *hnd) { - ALOGD_IF(DEBUG, "Release buffer handle:%p", hnd); - std::lock_guard lock(buffer_lock_); - auto buf = GetBufferFromHandleLocked(hnd); - if (buf == nullptr) { - ALOGE("Could not find handle: %p id: %" PRIu64, hnd, hnd->id); - return Error::BAD_BUFFER; - } else { - if (buf->DecRef()) { - handles_map_.erase(hnd); - // Unmap, close ion handle and close fd - FreeBuffer(buf); - } - } - return Error::NONE; -} - -Error BufferManager::LockBuffer(const private_handle_t *hnd, uint64_t usage) { - std::lock_guard lock(buffer_lock_); - auto err = Error::NONE; - ALOGD_IF(DEBUG, "LockBuffer buffer handle:%p id: %" PRIu64, hnd, hnd->id); - - // If buffer is not meant for CPU return err - if (!CpuCanAccess(usage)) { - return Error::BAD_VALUE; - } - - auto buf = GetBufferFromHandleLocked(hnd); - if (buf == nullptr) { - return Error::BAD_BUFFER; - } - - if (hnd->base == 0) { - // we need to map for real - err = MapBuffer(hnd); - } - - // Invalidate if CPU reads in software and there are non-CPU - // writers. No need to do this for the metadata buffer as it is - // only read/written in software. - - // todo use handle here - if (err == Error::NONE && (hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION) && - (hnd->flags & private_handle_t::PRIV_FLAGS_CACHED)) { - if (allocator_->CleanBuffer(reinterpret_cast(hnd->base), hnd->size, hnd->offset, - buf->ion_handle_main, CACHE_INVALIDATE)) { - return Error::BAD_BUFFER; - } - } - - // Mark the buffer to be flushed after CPU write. - if (err == Error::NONE && CpuCanWrite(usage)) { - private_handle_t *handle = const_cast(hnd); - handle->flags |= private_handle_t::PRIV_FLAGS_NEEDS_FLUSH; - } - - return err; -} - -Error BufferManager::UnlockBuffer(const private_handle_t *handle) { - std::lock_guard lock(buffer_lock_); - auto status = Error::NONE; - - private_handle_t *hnd = const_cast(handle); - auto buf = GetBufferFromHandleLocked(hnd); - if (buf == nullptr) { - return Error::BAD_BUFFER; - } - - if (hnd->flags & private_handle_t::PRIV_FLAGS_NEEDS_FLUSH) { - if (allocator_->CleanBuffer(reinterpret_cast(hnd->base), hnd->size, hnd->offset, - buf->ion_handle_main, CACHE_CLEAN) != 0) { - status = Error::BAD_BUFFER; - } - hnd->flags &= ~private_handle_t::PRIV_FLAGS_NEEDS_FLUSH; - } - - return status; -} - -uint32_t BufferManager::GetDataAlignment(int format, uint64_t usage) { - uint32_t align = UINT(getpagesize()); - if (format == HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED) { - align = 8192; - } - - if (usage & BufferUsage::PROTECTED) { - if ((usage & BufferUsage::CAMERA_OUTPUT) || (usage & GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY)) { - // The alignment here reflects qsee mmu V7L/V8L requirement - align = SZ_2M; - } else { - align = SECURE_ALIGN; - } - } - - return align; -} - -int BufferManager::GetHandleFlags(int format, uint64_t usage) { - int flags = 0; - if (usage & BufferUsage::VIDEO_ENCODER) { - flags |= private_handle_t::PRIV_FLAGS_VIDEO_ENCODER; - } - - if (usage & BufferUsage::CAMERA_OUTPUT) { - flags |= private_handle_t::PRIV_FLAGS_CAMERA_WRITE; - } - - if (usage & BufferUsage::CAMERA_INPUT) { - flags |= private_handle_t::PRIV_FLAGS_CAMERA_READ; - } - - if (usage & BufferUsage::COMPOSER_OVERLAY) { - flags |= private_handle_t::PRIV_FLAGS_DISP_CONSUMER; - } - - if (usage & BufferUsage::GPU_TEXTURE) { - flags |= private_handle_t::PRIV_FLAGS_HW_TEXTURE; - } - - if (usage & GRALLOC_USAGE_PRIVATE_SECURE_DISPLAY) { - flags |= private_handle_t::PRIV_FLAGS_SECURE_DISPLAY; - } - - if (IsUBwcEnabled(format, usage)) { - flags |= private_handle_t::PRIV_FLAGS_UBWC_ALIGNED; - } - - if (usage & (BufferUsage::CPU_READ_MASK | BufferUsage::CPU_WRITE_MASK)) { - flags |= private_handle_t::PRIV_FLAGS_CPU_RENDERED; - } - - if ((usage & (BufferUsage::VIDEO_ENCODER | BufferUsage::VIDEO_DECODER | - BufferUsage::CAMERA_OUTPUT | BufferUsage::GPU_RENDER_TARGET))) { - flags |= private_handle_t::PRIV_FLAGS_NON_CPU_WRITER; - } - - if (!allocator_->UseUncached(usage)) { - flags |= private_handle_t::PRIV_FLAGS_CACHED; - } - - return flags; -} - -int BufferManager::GetBufferType(int inputFormat) { - int buffer_type = BUFFER_TYPE_VIDEO; - if (IsUncompressedRGBFormat(inputFormat)) { - // RGB formats - buffer_type = BUFFER_TYPE_UI; - } - - return buffer_type; -} - -Error BufferManager::AllocateBuffer(const BufferDescriptor &descriptor, buffer_handle_t *handle, - unsigned int bufferSize) { - if (!handle) - return Error::BAD_BUFFER; - std::lock_guard buffer_lock(buffer_lock_); - - uint64_t usage = descriptor.GetUsage(); - int format = allocator_->GetImplDefinedFormat(usage, descriptor.GetFormat()); - uint32_t layer_count = descriptor.GetLayerCount(); - - unsigned int size; - unsigned int alignedw, alignedh; - - int buffer_type = GetBufferType(format); - BufferInfo info = GetBufferInfo(descriptor); - info.format = format; - GetBufferSizeAndDimensions(info, &size, &alignedw, &alignedh); - size = (bufferSize >= size) ? bufferSize : size; - - int err = 0; - int flags = 0; - auto page_size = UINT(getpagesize()); - AllocData data; - data.align = GetDataAlignment(format, usage); - size = ALIGN(size, data.align) * layer_count; - data.size = size; - data.handle = (uintptr_t)handle; - data.uncached = allocator_->UseUncached(usage); - - // Allocate buffer memory - err = allocator_->AllocateMem(&data, usage); - if (err) { - ALOGE("gralloc failed to allocate err=%s", strerror(-err)); - return Error::NO_RESOURCES; - } - - // Allocate memory for MetaData - AllocData e_data; - e_data.size = ALIGN(UINT(sizeof(MetaData_t)), page_size); - e_data.handle = data.handle; - e_data.align = page_size; - - err = allocator_->AllocateMem(&e_data, 0); - if (err) { - ALOGE("gralloc failed to allocate metadata error=%s", strerror(-err)); - return Error::NO_RESOURCES; - } - - flags = GetHandleFlags(format, usage); - flags |= data.alloc_type; - - // Create handle - private_handle_t *hnd = new private_handle_t( - data.fd, e_data.fd, flags, INT(alignedw), INT(alignedh), descriptor.GetWidth(), - descriptor.GetHeight(), format, buffer_type, data.size, usage); - - hnd->id = ++next_id_; - hnd->base = 0; - hnd->base_metadata = 0; - hnd->layer_count = layer_count; - - ColorSpace_t colorSpace = ITU_R_601; - setMetaData(hnd, UPDATE_COLOR_SPACE, reinterpret_cast(&colorSpace)); - *handle = hnd; - RegisterHandleLocked(hnd, data.ion_handle, e_data.ion_handle); - ALOGD_IF(DEBUG, "Allocated buffer handle: %p id: %" PRIu64, hnd, hnd->id); - if (DEBUG) { - private_handle_t::Dump(hnd); - } - return Error::NONE; -} - -Error BufferManager::Dump(std::ostringstream *os) { - std::lock_guard buffer_lock(buffer_lock_); - for (auto it : handles_map_) { - auto buf = it.second; - auto hnd = buf->handle; - *os << "handle id: " << std::setw(4) << hnd->id; - *os << " fd: " << std::setw(3) << hnd->fd; - *os << " fd_meta: " << std::setw(3) << hnd->fd_metadata; - *os << " wxh: " << std::setw(4) << hnd->width << " x " << std::setw(4) << hnd->height; - *os << " uwxuh: " << std::setw(4) << hnd->unaligned_width << " x "; - *os << std::setw(4) << hnd->unaligned_height; - *os << " size: " << std::setw(9) << hnd->size; - *os << std::hex << std::setfill('0'); - *os << " priv_flags: " - << "0x" << std::setw(8) << hnd->flags; - *os << " usage: " - << "0x" << std::setw(8) << hnd->usage; - // TODO(user): get format string from qdutils - *os << " format: " - << "0x" << std::setw(8) << hnd->format; - *os << std::dec << std::setfill(' ') << std::endl; - } - return Error::NONE; -} -} // namespace gralloc diff --git a/gralloc/gr_buf_mgr.h b/gralloc/gr_buf_mgr.h deleted file mode 100644 index 258be2b2..00000000 --- a/gralloc/gr_buf_mgr.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2011-2018, The Linux Foundation. All rights reserved. - * Not a Contribution - * - * Copyright (C) 2008 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 __GR_BUF_MGR_H__ -#define __GR_BUF_MGR_H__ - -#include -#include -#include -#include -#include - -#include "gr_allocator.h" -#include "gr_buf_descriptor.h" -#include "gralloc_priv.h" - -namespace gralloc { - -using android::hardware::graphics::mapper::V2_0::Error; - -class BufferManager { - public: - ~BufferManager(); - - Error AllocateBuffer(const BufferDescriptor &descriptor, buffer_handle_t *handle, - unsigned int bufferSize = 0); - Error RetainBuffer(private_handle_t const *hnd); - Error ReleaseBuffer(private_handle_t const *hnd); - Error LockBuffer(const private_handle_t *hnd, uint64_t usage); - Error UnlockBuffer(const private_handle_t *hnd); - Error Dump(std::ostringstream *os); - static BufferManager *GetInstance(); - - private: - BufferManager(); - Error MapBuffer(private_handle_t const *hnd); - int GetBufferType(int format); - uint32_t GetDataAlignment(int format, uint64_t usage); - int GetHandleFlags(int format, uint64_t usage); - - // Imports the ion fds into the current process. Returns an error for invalid handles - Error ImportHandleLocked(private_handle_t *hnd); - - // Creates a Buffer from the valid private handle and adds it to the map - void RegisterHandleLocked(const private_handle_t *hnd, int ion_handle, int ion_handle_meta); - - // Wrapper structure over private handle - // Values associated with the private handle - // that do not need to go over IPC can be placed here - // This structure is also not expected to be ABI stable - // unlike private_handle_t - struct Buffer { - const private_handle_t *handle = nullptr; - int ref_count = 1; - // Hold the main and metadata ion handles - // Freed from the allocator process - // and unused in the mapping process - int ion_handle_main = -1; - int ion_handle_meta = -1; - - Buffer() = delete; - explicit Buffer(const private_handle_t *h, int ih_main = -1, int ih_meta = -1) - : handle(h), ion_handle_main(ih_main), ion_handle_meta(ih_meta) {} - void IncRef() { ++ref_count; } - bool DecRef() { return --ref_count == 0; } - }; - - Error FreeBuffer(std::shared_ptr buf); - - // Get the wrapper Buffer object from the handle, returns nullptr if handle is not found - std::shared_ptr GetBufferFromHandleLocked(const private_handle_t *hnd); - Allocator *allocator_ = NULL; - std::mutex buffer_lock_; - std::unordered_map> handles_map_ = {}; - std::atomic next_id_; -}; - -} // namespace gralloc - -#endif // __GR_BUF_MGR_H__ diff --git a/gralloc/gr_device_impl.cpp b/gralloc/gr_device_impl.cpp deleted file mode 100644 index a26ea81b..00000000 --- a/gralloc/gr_device_impl.cpp +++ /dev/null @@ -1,869 +0,0 @@ -/* - * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved. - - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of The Linux Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL) -#include -#include -#include -#include -#include -#include -#include - -#include "gr_buf_descriptor.h" -#include "gr_device_impl.h" -#include "gr_utils.h" -#include "gralloc_priv.h" -#include "qdMetaData.h" -#include "qd_utils.h" - -int gralloc_device_open(const struct hw_module_t *module, const char *name, hw_device_t **device); - -int gralloc_device_close(struct hw_device_t *device); - -static struct hw_module_methods_t gralloc_module_methods = {.open = gralloc_device_open}; - -struct gralloc_module_t HAL_MODULE_INFO_SYM = { - // clang-format off - .common = { - .tag = HARDWARE_MODULE_TAG, - .module_api_version = GRALLOC_MODULE_API_VERSION_1_0, - .hal_api_version = HARDWARE_HAL_API_VERSION, - .id = GRALLOC_HARDWARE_MODULE_ID, - .name = "Graphics Memory Module", - .author = "Code Aurora Forum", - .methods = &gralloc_module_methods, - .dso = 0, - .reserved = {0}, - }, - // clang-format on -}; - -int gralloc_device_open(const struct hw_module_t *module, const char *name, hw_device_t **device) { - int status = -EINVAL; - if (module && device && !strcmp(name, GRALLOC_HARDWARE_MODULE_ID)) { - gralloc::GrallocImpl * /*gralloc1_device_t*/ dev = gralloc::GrallocImpl::GetInstance(module); - *device = reinterpret_cast(dev); - if (dev) { - status = 0; - } else { - ALOGE("Fatal error opening gralloc1 device"); - } - } - return status; -} - -namespace gralloc { - -std::atomic GrallocImpl::next_descriptor_id_(1); - -GrallocImpl::GrallocImpl(const hw_module_t *module) { - common.tag = HARDWARE_DEVICE_TAG; - common.version = GRALLOC_MODULE_API_VERSION_1_0; - common.module = const_cast(module); - common.close = CloseDevice; - getFunction = GetFunction; - getCapabilities = GetCapabilities; - - initialized_ = Init(); -} - -inline gralloc1_error_t ToError(Error error) { - switch (error) { - case Error::NONE: - return GRALLOC1_ERROR_NONE; - case Error::BAD_DESCRIPTOR: - return GRALLOC1_ERROR_BAD_DESCRIPTOR; - case Error::BAD_BUFFER: - return GRALLOC1_ERROR_BAD_HANDLE; - case Error::BAD_VALUE: - return GRALLOC1_ERROR_BAD_VALUE; - case Error::NO_RESOURCES: - return GRALLOC1_ERROR_NO_RESOURCES; - case Error::UNSUPPORTED: - default: - return GRALLOC1_ERROR_UNSUPPORTED; - } -} - -static uint64_t ProducerUsageToBufferUsage(gralloc1_producer_usage_t producer_usage) { - uint64_t usage = producer_usage & ~(GRALLOC1_PRODUCER_USAGE_CPU_READ_OFTEN | - GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN); - if ((producer_usage & GRALLOC1_PRODUCER_USAGE_CPU_READ_OFTEN) == - GRALLOC1_PRODUCER_USAGE_CPU_READ_OFTEN) { - usage |= BufferUsage::CPU_READ_OFTEN; - } else if ((producer_usage & GRALLOC1_PRODUCER_USAGE_CPU_READ) == - GRALLOC1_PRODUCER_USAGE_CPU_READ) { - usage |= BufferUsage::CPU_READ_RARELY; - } - - if ((producer_usage & GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN) == - GRALLOC1_PRODUCER_USAGE_CPU_WRITE_OFTEN) { - usage |= BufferUsage::CPU_WRITE_OFTEN; - } else if ((producer_usage & GRALLOC1_PRODUCER_USAGE_CPU_WRITE) == - GRALLOC1_PRODUCER_USAGE_CPU_WRITE) { - usage |= BufferUsage::CPU_WRITE_RARELY; - } - return usage; -} - -static uint64_t ConsumerUsageToBufferUsage(gralloc1_consumer_usage_t consumer_usage) { - uint64_t usage = consumer_usage & ~(GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN); - if ((consumer_usage & GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN) == - GRALLOC1_CONSUMER_USAGE_CPU_READ_OFTEN) { - usage |= BufferUsage::CPU_READ_OFTEN; - } else if ((consumer_usage & GRALLOC1_CONSUMER_USAGE_CPU_READ) == - GRALLOC1_CONSUMER_USAGE_CPU_READ) { - usage |= BufferUsage::CPU_READ_RARELY; - } - return usage; -} - -bool GrallocImpl::Init() { - buf_mgr_ = BufferManager::GetInstance(); - return buf_mgr_ != nullptr; -} - -GrallocImpl::~GrallocImpl() {} - -gralloc1_error_t GrallocImpl::CreateBufferDescriptorLocked( - gralloc1_buffer_descriptor_t *descriptor_id) { - std::lock_guard lock(descriptor_lock_); - auto descriptor = std::make_shared(next_descriptor_id_++); - *descriptor_id = static_cast(descriptor->GetId()); - descriptors_map_.emplace(*descriptor_id, descriptor); - return GRALLOC1_ERROR_NONE; -} - -gralloc1_error_t GrallocImpl::DestroyBufferDescriptorLocked( - gralloc1_buffer_descriptor_t descriptor_id) { - std::lock_guard lock(descriptor_lock_); - const auto descriptor = descriptors_map_.find(descriptor_id); - if (descriptor == descriptors_map_.end()) { - return GRALLOC1_ERROR_BAD_DESCRIPTOR; - } - descriptors_map_.erase(descriptor); - return GRALLOC1_ERROR_NONE; -} - -int GrallocImpl::CloseDevice(hw_device_t *device __unused) { - // No-op since the gralloc device is a singleton - return 0; -} - -void GrallocImpl::GetCapabilities(struct gralloc1_device *device, uint32_t *out_count, - int32_t /*gralloc1_capability_t*/ *out_capabilities) { - if (device != nullptr && out_count != nullptr) { - if (out_capabilities != nullptr && *out_count >= 3) { - out_capabilities[0] = GRALLOC1_CAPABILITY_TEST_ALLOCATE; - out_capabilities[1] = GRALLOC1_CAPABILITY_LAYERED_BUFFERS; - out_capabilities[2] = GRALLOC1_CAPABILITY_RELEASE_IMPLY_DELETE; - } - *out_count = 3; - } - return; -} - -gralloc1_function_pointer_t GrallocImpl::GetFunction(gralloc1_device_t *device, int32_t function) { - if (!device) { - return NULL; - } - - switch (function) { - case GRALLOC1_FUNCTION_DUMP: - return reinterpret_cast(Dump); - case GRALLOC1_FUNCTION_CREATE_DESCRIPTOR: - return reinterpret_cast(CreateBufferDescriptor); - case GRALLOC1_FUNCTION_DESTROY_DESCRIPTOR: - return reinterpret_cast(DestroyBufferDescriptor); - case GRALLOC1_FUNCTION_SET_CONSUMER_USAGE: - return reinterpret_cast(SetConsumerUsage); - case GRALLOC1_FUNCTION_SET_DIMENSIONS: - return reinterpret_cast(SetBufferDimensions); - case GRALLOC1_FUNCTION_SET_FORMAT: - return reinterpret_cast(SetColorFormat); - case GRALLOC1_FUNCTION_SET_LAYER_COUNT: - return reinterpret_cast(SetLayerCount); - case GRALLOC1_FUNCTION_SET_PRODUCER_USAGE: - return reinterpret_cast(SetProducerUsage); - case GRALLOC1_FUNCTION_GET_BACKING_STORE: - return reinterpret_cast(GetBackingStore); - case GRALLOC1_FUNCTION_GET_CONSUMER_USAGE: - return reinterpret_cast(GetConsumerUsage); - case GRALLOC1_FUNCTION_GET_DIMENSIONS: - return reinterpret_cast(GetBufferDimensions); - case GRALLOC1_FUNCTION_GET_FORMAT: - return reinterpret_cast(GetColorFormat); - case GRALLOC1_FUNCTION_GET_LAYER_COUNT: - return reinterpret_cast(GetLayerCount); - case GRALLOC1_FUNCTION_GET_PRODUCER_USAGE: - return reinterpret_cast(GetProducerUsage); - case GRALLOC1_FUNCTION_GET_STRIDE: - return reinterpret_cast(GetBufferStride); - case GRALLOC1_FUNCTION_ALLOCATE: - return reinterpret_cast(AllocateBuffers); - case GRALLOC1_FUNCTION_RETAIN: - return reinterpret_cast(RetainBuffer); - case GRALLOC1_FUNCTION_RELEASE: - return reinterpret_cast(ReleaseBuffer); - case GRALLOC1_FUNCTION_GET_NUM_FLEX_PLANES: - return reinterpret_cast(GetNumFlexPlanes); - case GRALLOC1_FUNCTION_LOCK: - return reinterpret_cast(LockBuffer); - case GRALLOC1_FUNCTION_LOCK_FLEX: - return reinterpret_cast(LockFlex); - case GRALLOC1_FUNCTION_UNLOCK: - return reinterpret_cast(UnlockBuffer); - case GRALLOC1_FUNCTION_PERFORM: - return reinterpret_cast(Gralloc1Perform); - default: - ALOGE("%s:Gralloc Error. Client Requested for unsupported function", __FUNCTION__); - return NULL; - } - - return NULL; -} - -gralloc1_error_t GrallocImpl::Dump(gralloc1_device_t *device, uint32_t *out_size, - char *out_buffer) { - if (!device || !out_size) { - ALOGE("Gralloc Error : device=%p", (void *)device); - return GRALLOC1_ERROR_BAD_DESCRIPTOR; - } - const size_t max_dump_size = 8192; - if (out_buffer == nullptr) { - *out_size = max_dump_size; - } else { - std::ostringstream os; - os << "-------------------------------" << std::endl; - os << "QTI gralloc dump:" << std::endl; - os << "-------------------------------" << std::endl; - GrallocImpl const *dev = GRALLOC_IMPL(device); - dev->buf_mgr_->Dump(&os); - os << "-------------------------------" << std::endl; - auto copied = os.str().copy(out_buffer, std::min(os.str().size(), max_dump_size), 0); - *out_size = UINT(copied); - } - - return GRALLOC1_ERROR_NONE; -} - -gralloc1_error_t GrallocImpl::CheckDeviceAndHandle(gralloc1_device_t *device, - buffer_handle_t buffer) { - const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); - if (!device || (private_handle_t::validate(hnd) != 0)) { - ALOGE("Gralloc Error : device= %p, buffer-handle=%p", (void *)device, (void *)buffer); - return GRALLOC1_ERROR_BAD_HANDLE; - } - - return GRALLOC1_ERROR_NONE; -} - -gralloc1_error_t GrallocImpl::CreateBufferDescriptor(gralloc1_device_t *device, - gralloc1_buffer_descriptor_t *out_descriptor) { - if (!device || !out_descriptor) { - return GRALLOC1_ERROR_BAD_DESCRIPTOR; - } - auto *dev = reinterpret_cast(device); - return dev->CreateBufferDescriptorLocked(out_descriptor); -} - -gralloc1_error_t GrallocImpl::DestroyBufferDescriptor(gralloc1_device_t *device, - gralloc1_buffer_descriptor_t descriptor) { - if (!device) { - return GRALLOC1_ERROR_BAD_DESCRIPTOR; - } - auto *dev = reinterpret_cast(device); - return dev->DestroyBufferDescriptorLocked(descriptor); -} - -gralloc1_error_t GrallocImpl::SetConsumerUsage(gralloc1_device_t *device, - gralloc1_buffer_descriptor_t descriptor, - gralloc1_consumer_usage_t usage) { - if (!device) { - return GRALLOC1_ERROR_BAD_DESCRIPTOR; - } else { - auto *dev = reinterpret_cast(device); - return dev->CallBufferDescriptorFunction(descriptor, &BufferDescriptor::SetUsage, - ConsumerUsageToBufferUsage(usage)); - } -} - -gralloc1_error_t GrallocImpl::SetBufferDimensions(gralloc1_device_t *device, - gralloc1_buffer_descriptor_t descriptor, - uint32_t width, uint32_t height) { - if (!device) { - return GRALLOC1_ERROR_BAD_DESCRIPTOR; - } else { - auto *dev = reinterpret_cast(device); - return dev->CallBufferDescriptorFunction(descriptor, &BufferDescriptor::SetDimensions, - INT(width), INT(height)); - } -} - -gralloc1_error_t GrallocImpl::SetColorFormat(gralloc1_device_t *device, - gralloc1_buffer_descriptor_t descriptor, - int32_t format) { - if (!device) { - return GRALLOC1_ERROR_BAD_DESCRIPTOR; - } else { - auto *dev = reinterpret_cast(device); - return dev->CallBufferDescriptorFunction(descriptor, &BufferDescriptor::SetColorFormat, format); - } -} - -gralloc1_error_t GrallocImpl::SetLayerCount(gralloc1_device_t *device, - gralloc1_buffer_descriptor_t descriptor, - uint32_t layer_count) { - if (!device) { - return GRALLOC1_ERROR_BAD_DESCRIPTOR; - } else { - auto *dev = reinterpret_cast(device); - return dev->CallBufferDescriptorFunction(descriptor, &BufferDescriptor::SetLayerCount, - layer_count); - } -} - -gralloc1_error_t GrallocImpl::SetProducerUsage(gralloc1_device_t *device, - gralloc1_buffer_descriptor_t descriptor, - gralloc1_producer_usage_t usage) { - if (!device) { - return GRALLOC1_ERROR_BAD_DESCRIPTOR; - } else { - auto *dev = reinterpret_cast(device); - return dev->CallBufferDescriptorFunction(descriptor, &BufferDescriptor::SetUsage, - ProducerUsageToBufferUsage(usage)); - } -} - -gralloc1_error_t GrallocImpl::GetBackingStore(gralloc1_device_t *device, buffer_handle_t buffer, - gralloc1_backing_store_t *out_backstore) { - if (!device || !buffer) { - return GRALLOC1_ERROR_BAD_HANDLE; - } - - *out_backstore = - static_cast(PRIV_HANDLE_CONST(buffer)->GetBackingstore()); - - return GRALLOC1_ERROR_NONE; -} - -gralloc1_error_t GrallocImpl::GetConsumerUsage(gralloc1_device_t *device, buffer_handle_t buffer, - gralloc1_consumer_usage_t *outUsage) { - gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); - if (status == GRALLOC1_ERROR_NONE) { - *outUsage = static_cast(PRIV_HANDLE_CONST(buffer)->GetUsage()); - } - - return status; -} - -gralloc1_error_t GrallocImpl::GetBufferDimensions(gralloc1_device_t *device, buffer_handle_t buffer, - uint32_t *outWidth, uint32_t *outHeight) { - gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); - if (status == GRALLOC1_ERROR_NONE) { - const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); - *outWidth = UINT(hnd->GetUnalignedWidth()); - *outHeight = UINT(hnd->GetUnalignedHeight()); - } - - return status; -} - -gralloc1_error_t GrallocImpl::GetColorFormat(gralloc1_device_t *device, buffer_handle_t buffer, - int32_t *outFormat) { - gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); - if (status == GRALLOC1_ERROR_NONE) { - *outFormat = PRIV_HANDLE_CONST(buffer)->GetColorFormat(); - } - - return status; -} - -gralloc1_error_t GrallocImpl::GetLayerCount(gralloc1_device_t *device, buffer_handle_t buffer, - uint32_t *outLayerCount) { - gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); - if (status == GRALLOC1_ERROR_NONE) { - *outLayerCount = PRIV_HANDLE_CONST(buffer)->GetLayerCount(); - } - - return status; -} - -gralloc1_error_t GrallocImpl::GetProducerUsage(gralloc1_device_t *device, buffer_handle_t buffer, - gralloc1_producer_usage_t *outUsage) { - if (!outUsage) { - return GRALLOC1_ERROR_BAD_VALUE; - } - - gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); - if (status == GRALLOC1_ERROR_NONE) { - *outUsage = static_cast(PRIV_HANDLE_CONST(buffer)->GetUsage()); - } - - return status; -} - -gralloc1_error_t GrallocImpl::GetBufferStride(gralloc1_device_t *device, buffer_handle_t buffer, - uint32_t *outStride) { - if (!outStride) { - return GRALLOC1_ERROR_BAD_VALUE; - } - - gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); - if (status == GRALLOC1_ERROR_NONE) { - *outStride = UINT(PRIV_HANDLE_CONST(buffer)->GetStride()); - } - - return status; -} - -gralloc1_error_t GrallocImpl::AllocateBuffer(const gralloc1_buffer_descriptor_t *descriptor_ids, - buffer_handle_t *out_buffers) { - gralloc1_error_t status = GRALLOC1_ERROR_NONE; - - // Validate descriptor - std::lock_guard descriptor_lock(descriptor_lock_); - std::shared_ptr descriptor; - const auto map_descriptor = descriptors_map_.find(descriptor_ids[0]); - if (map_descriptor == descriptors_map_.end()) { - return GRALLOC1_ERROR_BAD_DESCRIPTOR; - } else { - descriptor = map_descriptor->second; - } - - // Allocate separate buffer for each descriptor - if (buf_mgr_->AllocateBuffer(*descriptor, &out_buffers[0]) != Error::NONE) { - return GRALLOC1_ERROR_NO_RESOURCES; - } - - return status; -} - -gralloc1_error_t GrallocImpl::AllocateBuffers(gralloc1_device_t *device, uint32_t num_descriptors, - const gralloc1_buffer_descriptor_t *descriptors, - buffer_handle_t *out_buffers) { - if (!num_descriptors || !descriptors) { - return GRALLOC1_ERROR_BAD_DESCRIPTOR; - } - - if (!device) { - return GRALLOC1_ERROR_BAD_VALUE; - } - - if (num_descriptors != 1) { - return GRALLOC1_ERROR_UNSUPPORTED; - } - - auto *dev = reinterpret_cast(device); - gralloc1_error_t status = dev->AllocateBuffer(descriptors, out_buffers); - - return status; -} - -gralloc1_error_t GrallocImpl::RetainBuffer(gralloc1_device_t *device, buffer_handle_t buffer) { - gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); - if (status == GRALLOC1_ERROR_NONE) { - const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); - GrallocImpl const *dev = GRALLOC_IMPL(device); - status = ToError(dev->buf_mgr_->RetainBuffer(hnd)); - } - - return status; -} - -gralloc1_error_t GrallocImpl::ReleaseBuffer(gralloc1_device_t *device, buffer_handle_t buffer) { - if (!device || !buffer) { - return GRALLOC1_ERROR_BAD_DESCRIPTOR; - } - - const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); - GrallocImpl const *dev = GRALLOC_IMPL(device); - return ToError(dev->buf_mgr_->ReleaseBuffer(hnd)); -} - -gralloc1_error_t GrallocImpl::GetFlexLayout(const private_handle_t *hnd, - struct android_flex_layout *layout) { - if (!IsYuvFormat(hnd)) { - return GRALLOC1_ERROR_UNSUPPORTED; - } - - android_ycbcr yuvPlaneInfo[2]; - int err = GetYUVPlaneInfo(hnd, yuvPlaneInfo); - - if (err != 0) { - return GRALLOC1_ERROR_BAD_HANDLE; - } - - layout->format = FLEX_FORMAT_YCbCr; - layout->num_planes = 3; - - for (uint32_t i = 0; i < layout->num_planes; i++) { - layout->planes[i].bits_per_component = 8; - layout->planes[i].bits_used = 8; - layout->planes[i].h_increment = 1; - layout->planes[i].v_increment = 1; - layout->planes[i].h_subsampling = 2; - layout->planes[i].v_subsampling = 2; - } - - // We are only returning flex layout for progressive or single field formats. - struct android_ycbcr ycbcr = yuvPlaneInfo[0]; - layout->planes[0].top_left = static_cast(ycbcr.y); - layout->planes[0].component = FLEX_COMPONENT_Y; - layout->planes[0].v_increment = static_cast(ycbcr.ystride); - - layout->planes[1].top_left = static_cast(ycbcr.cb); - layout->planes[1].component = FLEX_COMPONENT_Cb; - layout->planes[1].h_increment = static_cast(ycbcr.chroma_step); - layout->planes[1].v_increment = static_cast(ycbcr.cstride); - - layout->planes[2].top_left = static_cast(ycbcr.cr); - layout->planes[2].component = FLEX_COMPONENT_Cr; - layout->planes[2].h_increment = static_cast(ycbcr.chroma_step); - layout->planes[2].v_increment = static_cast(ycbcr.cstride); - return GRALLOC1_ERROR_NONE; -} - -gralloc1_error_t GrallocImpl::GetNumFlexPlanes(gralloc1_device_t *device, buffer_handle_t buffer, - uint32_t *out_num_planes) { - if (!out_num_planes) { - return GRALLOC1_ERROR_BAD_VALUE; - } - - gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); - if (status == GRALLOC1_ERROR_NONE) { - const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); - if (!IsYuvFormat(hnd)) { - status = GRALLOC1_ERROR_UNSUPPORTED; - } else { - *out_num_planes = 3; - } - } - return status; -} - -static inline void CloseFdIfValid(int fd) { - if (fd > 0) { - close(fd); - } -} - -gralloc1_error_t GrallocImpl::LockBuffer(gralloc1_device_t *device, buffer_handle_t buffer, - gralloc1_producer_usage_t prod_usage, - gralloc1_consumer_usage_t cons_usage, - const gralloc1_rect_t *region, void **out_data, - int32_t acquire_fence) { - ATRACE_CALL(); - gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); - if (status != GRALLOC1_ERROR_NONE || !out_data || - !region) { // currently we ignore the region/rect client wants to lock - CloseFdIfValid(acquire_fence); - return status; - } - - if (acquire_fence > 0) { - ATRACE_BEGIN("fence wait"); - int error = sync_wait(acquire_fence, 1000); - ATRACE_END(); - CloseFdIfValid(acquire_fence); - if (error < 0) { - ALOGE("%s: sync_wait timedout! error = %s", __FUNCTION__, strerror(errno)); - return GRALLOC1_ERROR_UNDEFINED; - } - } - - const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); - GrallocImpl const *dev = GRALLOC_IMPL(device); - - // Either producer usage or consumer usage must be *_USAGE_NONE - if ((prod_usage != GRALLOC1_PRODUCER_USAGE_NONE) && - (cons_usage != GRALLOC1_CONSUMER_USAGE_NONE)) { - // Current gralloc1 clients do not satisfy this restriction. - // See b/33588773 for details - // return GRALLOC1_ERROR_BAD_VALUE; - } - - status = ToError(dev->buf_mgr_->LockBuffer( - hnd, ProducerUsageToBufferUsage(prod_usage) | ConsumerUsageToBufferUsage(cons_usage))); - *out_data = reinterpret_cast(hnd->base); - - return status; -} - -gralloc1_error_t GrallocImpl::LockFlex(gralloc1_device_t *device, buffer_handle_t buffer, - gralloc1_producer_usage_t prod_usage, - gralloc1_consumer_usage_t cons_usage, - const gralloc1_rect_t *region, - struct android_flex_layout *out_flex_layout, - int32_t acquire_fence) { - if (!out_flex_layout) { - CloseFdIfValid(acquire_fence); - return GRALLOC1_ERROR_BAD_VALUE; - } - - void *out_data{}; - gralloc1_error_t status = GrallocImpl::LockBuffer(device, buffer, prod_usage, cons_usage, region, - &out_data, acquire_fence); - if (status != GRALLOC1_ERROR_NONE) { - return status; - } - - auto *dev = reinterpret_cast(device); - const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); - dev->GetFlexLayout(hnd, out_flex_layout); - return status; -} - -gralloc1_error_t GrallocImpl::UnlockBuffer(gralloc1_device_t *device, buffer_handle_t buffer, - int32_t *release_fence) { - gralloc1_error_t status = CheckDeviceAndHandle(device, buffer); - if (status != GRALLOC1_ERROR_NONE) { - return status; - } - - if (!release_fence) { - return GRALLOC1_ERROR_BAD_VALUE; - } - - const private_handle_t *hnd = PRIV_HANDLE_CONST(buffer); - GrallocImpl const *dev = GRALLOC_IMPL(device); - - *release_fence = -1; - - return ToError(dev->buf_mgr_->UnlockBuffer(hnd)); -} - -static gralloc1_error_t Perform(int operation, va_list args) { - switch (operation) { - case GRALLOC_MODULE_PERFORM_GET_STRIDE: { - int width = va_arg(args, int); - int format = va_arg(args, int); - int *stride = va_arg(args, int *); - unsigned int alignedw = 0, alignedh = 0; - - if (!stride) { - return GRALLOC1_ERROR_BAD_VALUE; - } - - BufferInfo info(width, width, format); - GetAlignedWidthAndHeight(info, &alignedw, &alignedh); - *stride = INT(alignedw); - } break; - - case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_FROM_HANDLE: { - private_handle_t *hnd = va_arg(args, private_handle_t *); - int *stride = va_arg(args, int *); - if (private_handle_t::validate(hnd) != 0) { - return GRALLOC1_ERROR_BAD_HANDLE; - } - - if (!stride) { - return GRALLOC1_ERROR_BAD_VALUE; - } - - BufferDim_t buffer_dim; - if (getMetaData(hnd, GET_BUFFER_GEOMETRY, &buffer_dim) == 0) { - *stride = buffer_dim.sliceWidth; - } else { - *stride = hnd->width; - } - } break; - - case GRALLOC_MODULE_PERFORM_GET_CUSTOM_STRIDE_AND_HEIGHT_FROM_HANDLE: { - private_handle_t *hnd = va_arg(args, private_handle_t *); - int *stride = va_arg(args, int *); - int *height = va_arg(args, int *); - if (private_handle_t::validate(hnd) != 0) { - return GRALLOC1_ERROR_BAD_HANDLE; - } - - if (!stride || !height) { - return GRALLOC1_ERROR_BAD_VALUE; - } - - GetCustomDimensions(hnd, stride, height); - } break; - - case GRALLOC_MODULE_PERFORM_GET_ATTRIBUTES: { - int width = va_arg(args, int); - int height = va_arg(args, int); - int format = va_arg(args, int); - uint64_t usage = va_arg(args, uint64_t); - usage |= va_arg(args, uint64_t); - - int *aligned_width = va_arg(args, int *); - int *aligned_height = va_arg(args, int *); - int *tile_enabled = va_arg(args, int *); - if (!aligned_width || !aligned_height || !tile_enabled) { - return GRALLOC1_ERROR_BAD_VALUE; - } - - unsigned int alignedw, alignedh; - BufferInfo info(width, height, format, usage); - *tile_enabled = IsUBwcEnabled(format, usage); - GetAlignedWidthAndHeight(info, &alignedw, &alignedh); - *aligned_width = INT(alignedw); - *aligned_height = INT(alignedh); - } break; - - case GRALLOC_MODULE_PERFORM_GET_COLOR_SPACE_FROM_HANDLE: { - private_handle_t *hnd = va_arg(args, private_handle_t *); - int *color_space = va_arg(args, int *); - - if (private_handle_t::validate(hnd) != 0) { - return GRALLOC1_ERROR_BAD_HANDLE; - } - - if (!color_space) { - return GRALLOC1_ERROR_BAD_VALUE; - } - - *color_space = 0; - GetColorSpaceFromMetadata(hnd, color_space); - } break; - case GRALLOC_MODULE_PERFORM_GET_YUV_PLANE_INFO: { - private_handle_t *hnd = va_arg(args, private_handle_t *); - android_ycbcr *ycbcr = va_arg(args, struct android_ycbcr *); - if (private_handle_t::validate(hnd) != 0) { - return GRALLOC1_ERROR_BAD_HANDLE; - } - - if (!ycbcr) { - return GRALLOC1_ERROR_BAD_VALUE; - } - - if (GetYUVPlaneInfo(hnd, ycbcr)) { - return GRALLOC1_ERROR_UNDEFINED; - } - } break; - - case GRALLOC_MODULE_PERFORM_GET_MAP_SECURE_BUFFER_INFO: { - private_handle_t *hnd = va_arg(args, private_handle_t *); - int *map_secure_buffer = va_arg(args, int *); - - if (private_handle_t::validate(hnd) != 0) { - return GRALLOC1_ERROR_BAD_HANDLE; - } - - if (!map_secure_buffer) { - return GRALLOC1_ERROR_BAD_VALUE; - } - - if (getMetaData(hnd, GET_MAP_SECURE_BUFFER, map_secure_buffer) != 0) { - *map_secure_buffer = 0; - } - } break; - - case GRALLOC_MODULE_PERFORM_GET_UBWC_FLAG: { - private_handle_t *hnd = va_arg(args, private_handle_t *); - int *flag = va_arg(args, int *); - - if (private_handle_t::validate(hnd) != 0) { - return GRALLOC1_ERROR_BAD_HANDLE; - } - - if (!flag) { - return GRALLOC1_ERROR_BAD_VALUE; - } - - *flag = hnd->flags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED; - int linear_format = 0; - if (getMetaData(hnd, GET_LINEAR_FORMAT, &linear_format) == 0) { - if (linear_format) { - *flag = 0; - } - } - } break; - - case GRALLOC_MODULE_PERFORM_GET_RGB_DATA_ADDRESS: { - private_handle_t *hnd = va_arg(args, private_handle_t *); - void **rgb_data = va_arg(args, void **); - - if (private_handle_t::validate(hnd) != 0) { - return GRALLOC1_ERROR_BAD_HANDLE; - } - - if (!rgb_data) { - return GRALLOC1_ERROR_BAD_VALUE; - } - - if (GetRgbDataAddress(hnd, rgb_data)) { - return GRALLOC1_ERROR_UNDEFINED; - } - } break; - - case GRALLOC1_MODULE_PERFORM_GET_INTERLACE_FLAG: { - private_handle_t *hnd = va_arg(args, private_handle_t *); - int *flag = va_arg(args, int *); - - if (private_handle_t::validate(hnd) != 0) { - return GRALLOC1_ERROR_BAD_HANDLE; - } - - if (!flag) { - return GRALLOC1_ERROR_BAD_VALUE; - } - - if (getMetaData(hnd, GET_PP_PARAM_INTERLACED, flag) != 0) { - *flag = 0; - } - } break; - - case GRALLOC_MODULE_PERFORM_SET_SINGLE_BUFFER_MODE: { - private_handle_t *hnd = va_arg(args, private_handle_t *); - uint32_t *enable = va_arg(args, uint32_t *); - if (private_handle_t::validate(hnd) != 0) { - return GRALLOC1_ERROR_BAD_HANDLE; - } - if (setMetaData(hnd, SET_SINGLE_BUFFER_MODE, enable) != 0) { - return GRALLOC1_ERROR_UNSUPPORTED; - } - } break; - - default: - break; - } - return GRALLOC1_ERROR_NONE; -} - -gralloc1_error_t GrallocImpl::Gralloc1Perform(gralloc1_device_t *device, int operation, ...) { - if (!device) { - return GRALLOC1_ERROR_BAD_VALUE; - } - - va_list args; - va_start(args, operation); - gralloc1_error_t err = Perform(operation, args); - va_end(args); - - return err; -} - -} // namespace gralloc diff --git a/gralloc/gr_device_impl.h b/gralloc/gr_device_impl.h deleted file mode 100644 index 82e9e714..00000000 --- a/gralloc/gr_device_impl.h +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright (c) 2016-2018, The Linux Foundation. All rights reserved. - - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of The Linux Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __GR_DEVICE_IMPL_H__ -#define __GR_DEVICE_IMPL_H__ - -#include -#include -#include "gr_buf_mgr.h" - -struct private_module_t { - hw_module_t base; -}; - -#define GRALLOC_IMPL(exp) reinterpret_cast(exp) - -namespace gralloc { - -class GrallocImpl : public gralloc1_device_t { - public: - static int CloseDevice(hw_device_t *device); - static void GetCapabilities(struct gralloc1_device *device, uint32_t *out_count, - int32_t * /*gralloc1_capability_t*/ out_capabilities); - static gralloc1_function_pointer_t GetFunction( - struct gralloc1_device *device, int32_t /*gralloc1_function_descriptor_t*/ descriptor); - - static GrallocImpl *GetInstance(const struct hw_module_t *module) { - static GrallocImpl *instance = new GrallocImpl(module); - if (instance->IsInitialized()) { - return instance; - } else { - return nullptr; - } - } - - private: - static inline gralloc1_error_t Dump(gralloc1_device_t *device, uint32_t *out_size, - char *out_buffer); - static inline gralloc1_error_t CheckDeviceAndHandle(gralloc1_device_t *device, - buffer_handle_t buffer); - static gralloc1_error_t CreateBufferDescriptor(gralloc1_device_t *device, - gralloc1_buffer_descriptor_t *out_descriptor); - static gralloc1_error_t DestroyBufferDescriptor(gralloc1_device_t *device, - gralloc1_buffer_descriptor_t descriptor); - static gralloc1_error_t SetConsumerUsage(gralloc1_device_t *device, - gralloc1_buffer_descriptor_t descriptor, - gralloc1_consumer_usage_t usage); - static gralloc1_error_t SetBufferDimensions(gralloc1_device_t *device, - gralloc1_buffer_descriptor_t descriptor, - uint32_t width, uint32_t height); - static gralloc1_error_t SetColorFormat(gralloc1_device_t *device, - gralloc1_buffer_descriptor_t descriptor, int32_t format); - static gralloc1_error_t SetLayerCount(gralloc1_device_t *device, - gralloc1_buffer_descriptor_t descriptor, - uint32_t layer_count); - static gralloc1_error_t SetProducerUsage(gralloc1_device_t *device, - gralloc1_buffer_descriptor_t descriptor, - gralloc1_producer_usage_t usage); - static gralloc1_error_t GetBackingStore(gralloc1_device_t *device, buffer_handle_t buffer, - gralloc1_backing_store_t *out_store); - static gralloc1_error_t GetConsumerUsage(gralloc1_device_t *device, buffer_handle_t buffer, - gralloc1_consumer_usage_t *out_usage); - static gralloc1_error_t GetBufferDimensions(gralloc1_device_t *device, buffer_handle_t buffer, - uint32_t *out_width, uint32_t *out_height); - static gralloc1_error_t GetColorFormat(gralloc1_device_t *device, buffer_handle_t descriptor, - int32_t *outFormat); - static gralloc1_error_t GetLayerCount(gralloc1_device_t *device, buffer_handle_t buffer, - uint32_t *out_layer_count); - static gralloc1_error_t GetProducerUsage(gralloc1_device_t *device, buffer_handle_t buffer, - gralloc1_producer_usage_t *out_usage); - static gralloc1_error_t GetBufferStride(gralloc1_device_t *device, buffer_handle_t buffer, - uint32_t *out_stride); - static gralloc1_error_t AllocateBuffers(gralloc1_device_t *device, uint32_t num_dptors, - const gralloc1_buffer_descriptor_t *descriptors, - buffer_handle_t *out_buffers); - static gralloc1_error_t RetainBuffer(gralloc1_device_t *device, buffer_handle_t buffer); - static gralloc1_error_t ReleaseBuffer(gralloc1_device_t *device, buffer_handle_t buffer); - static gralloc1_error_t GetNumFlexPlanes(gralloc1_device_t *device, buffer_handle_t buffer, - uint32_t *out_num_planes); - static gralloc1_error_t LockBuffer(gralloc1_device_t *device, buffer_handle_t buffer, - gralloc1_producer_usage_t prod_usage, - gralloc1_consumer_usage_t cons_usage, - const gralloc1_rect_t *region, void **out_data, - int32_t acquire_fence); - static gralloc1_error_t LockFlex(gralloc1_device_t *device, buffer_handle_t buffer, - gralloc1_producer_usage_t prod_usage, - gralloc1_consumer_usage_t cons_usage, - const gralloc1_rect_t *region, - struct android_flex_layout *out_flex_layout, - int32_t acquire_fence); - - static gralloc1_error_t UnlockBuffer(gralloc1_device_t *device, buffer_handle_t buffer, - int32_t *release_fence); - static gralloc1_error_t Gralloc1Perform(gralloc1_device_t *device, int operation, ...); - - gralloc1_error_t CreateBufferDescriptorLocked(gralloc1_buffer_descriptor_t *descriptor_id); - gralloc1_error_t DestroyBufferDescriptorLocked(gralloc1_buffer_descriptor_t descriptor_id); - gralloc1_error_t AllocateBuffer(const gralloc1_buffer_descriptor_t *descriptor_ids, - buffer_handle_t *out_buffers); - gralloc1_error_t GetFlexLayout(const private_handle_t *hnd, struct android_flex_layout *layout); - - template - gralloc1_error_t CallBufferDescriptorFunction(gralloc1_buffer_descriptor_t descriptor_id, - void (BufferDescriptor::*member)(Args...), - Args... args) { - std::lock_guard lock(descriptor_lock_); - const auto map_descriptor = descriptors_map_.find(descriptor_id); - if (map_descriptor == descriptors_map_.end()) { - return GRALLOC1_ERROR_BAD_DESCRIPTOR; - } - const auto descriptor = map_descriptor->second; - (descriptor.get()->*member)(std::forward(args)...); - return GRALLOC1_ERROR_NONE; - } - - explicit GrallocImpl(const hw_module_t *module); - ~GrallocImpl(); - bool Init(); - bool IsInitialized() const { return initialized_; } - - BufferManager *buf_mgr_ = NULL; - bool initialized_ = false; - std::mutex descriptor_lock_; - std::unordered_map> - descriptors_map_ = {}; - static std::atomic next_descriptor_id_; -}; - -} // namespace gralloc - -#endif // __GR_DEVICE_IMPL_H__ diff --git a/gralloc/gr_ion_alloc.cpp b/gralloc/gr_ion_alloc.cpp deleted file mode 100644 index 33a13abf..00000000 --- a/gralloc/gr_ion_alloc.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright (c) 2011-2018, The Linux Foundation. All rights reserved. - - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of The Linux Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#define DEBUG 0 -#define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL) -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "gr_ion_alloc.h" -#include "gr_utils.h" -#include "gralloc_priv.h" - -namespace gralloc { - -bool IonAlloc::Init() { - if (ion_dev_fd_ == FD_INIT) { - ion_dev_fd_ = open(kIonDevice, O_RDONLY); - } - - if (ion_dev_fd_ < 0) { - ALOGE("%s: Failed to open ion device - %s", __FUNCTION__, strerror(errno)); - ion_dev_fd_ = FD_INIT; - return false; - } - - return true; -} - -void IonAlloc::CloseIonDevice() { - if (ion_dev_fd_ > FD_INIT) { - close(ion_dev_fd_); - } - - ion_dev_fd_ = FD_INIT; -} - -int IonAlloc::AllocBuffer(AllocData *data) { - ATRACE_CALL(); - int err = 0; - struct ion_handle_data handle_data; - struct ion_fd_data fd_data; - struct ion_allocation_data ion_alloc_data; - - ion_alloc_data.len = data->size; - ion_alloc_data.align = data->align; - ion_alloc_data.heap_id_mask = data->heap_id; - ion_alloc_data.flags = data->flags; - ion_alloc_data.flags |= data->uncached ? 0 : ION_FLAG_CACHED; - std::string tag_name{}; - if (ATRACE_ENABLED()) { - tag_name = "ION_IOC_ALLOC size: " + std::to_string(data->size); - } - - ATRACE_BEGIN(tag_name.c_str()); - if (ioctl(ion_dev_fd_, INT(ION_IOC_ALLOC), &ion_alloc_data)) { - err = -errno; - ALOGE("ION_IOC_ALLOC failed with error - %s", strerror(errno)); - return err; - } - ATRACE_END(); - - fd_data.handle = ion_alloc_data.handle; - handle_data.handle = ion_alloc_data.handle; - ATRACE_BEGIN("ION_IOC_MAP"); - if (ioctl(ion_dev_fd_, INT(ION_IOC_MAP), &fd_data)) { - err = -errno; - ALOGE("%s: ION_IOC_MAP failed with error - %s", __FUNCTION__, strerror(errno)); - ioctl(ion_dev_fd_, INT(ION_IOC_FREE), &handle_data); - return err; - } - ATRACE_END(); - - data->fd = fd_data.fd; - data->ion_handle = handle_data.handle; - ALOGD_IF(DEBUG, "ion: Allocated buffer size:%zu fd:%d handle:0x%x", ion_alloc_data.len, data->fd, - data->ion_handle); - - return 0; -} - -int IonAlloc::FreeBuffer(void *base, unsigned int size, unsigned int offset, int fd, - int ion_handle) { - ATRACE_CALL(); - int err = 0; - ALOGD_IF(DEBUG, "ion: Freeing buffer base:%p size:%u fd:%d handle:0x%x", base, size, fd, - ion_handle); - - if (base) { - err = UnmapBuffer(base, size, offset); - } - - if (ion_handle > 0) { - struct ion_handle_data handle_data; - handle_data.handle = ion_handle; - ioctl(ion_dev_fd_, INT(ION_IOC_FREE), &handle_data); - } - close(fd); - return err; -} - -int IonAlloc::MapBuffer(void **base, unsigned int size, unsigned int offset, int fd) { - ATRACE_CALL(); - int err = 0; - void *addr = 0; - - // It is a (quirky) requirement of ION to have opened the - // ion fd in the process that is doing the mapping - addr = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); - *base = addr; - if (addr == MAP_FAILED) { - err = -errno; - ALOGE("ion: Failed to map memory in the client: %s", strerror(errno)); - } else { - ALOGD_IF(DEBUG, "ion: Mapped buffer base:%p size:%u offset:%u fd:%d", addr, size, offset, fd); - } - - return err; -} - -int IonAlloc::ImportBuffer(int fd) { - struct ion_fd_data fd_data; - int err = 0; - fd_data.fd = fd; - if (ioctl(ion_dev_fd_, INT(ION_IOC_IMPORT), &fd_data)) { - err = -errno; - ALOGE("%s: ION_IOC_IMPORT failed with error - %s", __FUNCTION__, strerror(errno)); - return err; - } - return fd_data.handle; -} - -int IonAlloc::UnmapBuffer(void *base, unsigned int size, unsigned int /*offset*/) { - ATRACE_CALL(); - ALOGD_IF(DEBUG, "ion: Unmapping buffer base:%p size:%u", base, size); - - int err = 0; - if (munmap(base, size)) { - err = -errno; - ALOGE("ion: Failed to unmap memory at %p : %s", base, strerror(errno)); - } - - return err; -} - -int IonAlloc::CleanBuffer(void *base, unsigned int size, unsigned int offset, int handle, int op) { - ATRACE_CALL(); - ATRACE_INT("operation id", op); - struct ion_flush_data flush_data; - int err = 0; - - flush_data.handle = handle; - flush_data.vaddr = base; - // offset and length are unsigned int - flush_data.offset = offset; - flush_data.length = size; - - struct ion_custom_data d; - switch (op) { - case CACHE_CLEAN: - d.cmd = ION_IOC_CLEAN_CACHES; - break; - case CACHE_INVALIDATE: - d.cmd = ION_IOC_INV_CACHES; - break; - case CACHE_CLEAN_AND_INVALIDATE: - default: - d.cmd = ION_IOC_CLEAN_INV_CACHES; - } - - d.arg = (unsigned long)(&flush_data); // NOLINT - if (ioctl(ion_dev_fd_, INT(ION_IOC_CUSTOM), &d)) { - err = -errno; - ALOGE("%s: ION_IOC_CLEAN_INV_CACHES failed with error - %s", __FUNCTION__, strerror(errno)); - return err; - } - - return 0; -} - -} // namespace gralloc diff --git a/gralloc/gr_ion_alloc.h b/gralloc/gr_ion_alloc.h deleted file mode 100644 index 6a1fd7f6..00000000 --- a/gralloc/gr_ion_alloc.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (c) 2011-2018, The Linux Foundation. All rights reserved. - - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of The Linux Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __GR_ION_ALLOC_H__ -#define __GR_ION_ALLOC_H__ - -#include - -#define FD_INIT -1 - -namespace gralloc { - -enum { - CACHE_CLEAN = 0x1, - CACHE_INVALIDATE, - CACHE_CLEAN_AND_INVALIDATE, -}; - -struct AllocData { - void *base = NULL; - int fd = -1; - int ion_handle = -1; - unsigned int offset = 0; - unsigned int size = 0; - unsigned int align = 1; - uintptr_t handle = 0; - bool uncached = false; - unsigned int flags = 0x0; - unsigned int heap_id = 0x0; - unsigned int alloc_type = 0x0; -}; - -class IonAlloc { - public: - IonAlloc() { ion_dev_fd_ = FD_INIT; } - - ~IonAlloc() { CloseIonDevice(); } - - bool Init(); - int AllocBuffer(AllocData *data); - int FreeBuffer(void *base, unsigned int size, unsigned int offset, int fd, int ion_handle); - int MapBuffer(void **base, unsigned int size, unsigned int offset, int fd); - int ImportBuffer(int fd); - int UnmapBuffer(void *base, unsigned int size, unsigned int offset); - int CleanBuffer(void *base, unsigned int size, unsigned int offset, int handle, int op); - - private: - const char *kIonDevice = "/dev/ion"; - - int OpenIonDevice(); - void CloseIonDevice(); - - int ion_dev_fd_; -}; - -} // namespace gralloc - -#endif // __GR_ION_ALLOC_H__ diff --git a/gralloc/gr_utils.cpp b/gralloc/gr_utils.cpp deleted file mode 100644 index 68bdb4cb..00000000 --- a/gralloc/gr_utils.cpp +++ /dev/null @@ -1,933 +0,0 @@ -/* - * Copyright (c) 2011-2018, The Linux Foundation. All rights reserved. - - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of The Linux Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include - -#include "gr_adreno_info.h" -#include "gr_utils.h" -#include "qdMetaData.h" - -#define ASTC_BLOCK_SIZE 16 - -#ifndef COLOR_FMT_P010_UBWC -#define COLOR_FMT_P010_UBWC 9 -#endif - -namespace gralloc { - -bool IsYuvFormat(const private_handle_t *hnd) { - switch (hnd->format) { - case HAL_PIXEL_FORMAT_YCbCr_420_SP: - case HAL_PIXEL_FORMAT_YCbCr_422_SP: - case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS: - case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: // Same as YCbCr_420_SP_VENUS - case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC: - case HAL_PIXEL_FORMAT_YCrCb_420_SP: - case HAL_PIXEL_FORMAT_YCrCb_422_SP: - case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO: - case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS: - case HAL_PIXEL_FORMAT_NV21_ZSL: - case HAL_PIXEL_FORMAT_RAW16: - case HAL_PIXEL_FORMAT_Y16: - case HAL_PIXEL_FORMAT_RAW12: - case HAL_PIXEL_FORMAT_RAW10: - case HAL_PIXEL_FORMAT_YV12: - case HAL_PIXEL_FORMAT_Y8: - case HAL_PIXEL_FORMAT_YCbCr_420_P010: - case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC: - case HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC: - case HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS: - return true; - default: - return false; - } -} - -bool IsUncompressedRGBFormat(int format) { - switch (format) { - case HAL_PIXEL_FORMAT_RGBA_8888: - case HAL_PIXEL_FORMAT_RGBX_8888: - case HAL_PIXEL_FORMAT_RGB_888: - case HAL_PIXEL_FORMAT_RGB_565: - case HAL_PIXEL_FORMAT_BGR_565: - case HAL_PIXEL_FORMAT_BGRA_8888: - case HAL_PIXEL_FORMAT_RGBA_5551: - case HAL_PIXEL_FORMAT_RGBA_4444: - case HAL_PIXEL_FORMAT_R_8: - case HAL_PIXEL_FORMAT_RG_88: - case HAL_PIXEL_FORMAT_BGRX_8888: - case HAL_PIXEL_FORMAT_RGBA_1010102: - case HAL_PIXEL_FORMAT_ARGB_2101010: - case HAL_PIXEL_FORMAT_RGBX_1010102: - case HAL_PIXEL_FORMAT_XRGB_2101010: - case HAL_PIXEL_FORMAT_BGRA_1010102: - case HAL_PIXEL_FORMAT_ABGR_2101010: - case HAL_PIXEL_FORMAT_BGRX_1010102: - case HAL_PIXEL_FORMAT_XBGR_2101010: - case HAL_PIXEL_FORMAT_RGBA_FP16: - case HAL_PIXEL_FORMAT_BGR_888: - return true; - default: - break; - } - - return false; -} - -bool IsCompressedRGBFormat(int format) { - switch (format) { - case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_4x4_KHR: - case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR: - case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_5x4_KHR: - case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR: - case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_5x5_KHR: - case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR: - case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_6x5_KHR: - case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR: - case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_6x6_KHR: - case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR: - case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x5_KHR: - case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR: - case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x6_KHR: - case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR: - case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_8x8_KHR: - case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR: - case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x5_KHR: - case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR: - case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x6_KHR: - case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR: - case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x8_KHR: - case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR: - case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_10x10_KHR: - case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR: - case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_12x10_KHR: - case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR: - case HAL_PIXEL_FORMAT_COMPRESSED_RGBA_ASTC_12x12_KHR: - case HAL_PIXEL_FORMAT_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR: - return true; - default: - break; - } - - return false; -} - -uint32_t GetBppForUncompressedRGB(int format) { - uint32_t bpp = 0; - switch (format) { - case HAL_PIXEL_FORMAT_RGBA_FP16: - bpp = 8; - break; - case HAL_PIXEL_FORMAT_RGBA_8888: - case HAL_PIXEL_FORMAT_RGBX_8888: - case HAL_PIXEL_FORMAT_BGRA_8888: - case HAL_PIXEL_FORMAT_BGRX_8888: - case HAL_PIXEL_FORMAT_RGBA_1010102: - case HAL_PIXEL_FORMAT_ARGB_2101010: - case HAL_PIXEL_FORMAT_RGBX_1010102: - case HAL_PIXEL_FORMAT_XRGB_2101010: - case HAL_PIXEL_FORMAT_BGRA_1010102: - case HAL_PIXEL_FORMAT_ABGR_2101010: - case HAL_PIXEL_FORMAT_BGRX_1010102: - case HAL_PIXEL_FORMAT_XBGR_2101010: - bpp = 4; - break; - case HAL_PIXEL_FORMAT_RGB_888: - case HAL_PIXEL_FORMAT_BGR_888: - bpp = 3; - break; - case HAL_PIXEL_FORMAT_RGB_565: - case HAL_PIXEL_FORMAT_BGR_565: - case HAL_PIXEL_FORMAT_RGBA_5551: - case HAL_PIXEL_FORMAT_RGBA_4444: - bpp = 2; - break; - default: - ALOGE("Error : %s New format request = 0x%x", __FUNCTION__, format); - break; - } - - return bpp; -} - -bool CpuCanAccess(uint64_t usage) { - return CpuCanRead(usage) || CpuCanWrite(usage); -} - -bool CpuCanRead(uint64_t usage) { - if (usage & BufferUsage::CPU_READ_MASK) { - return true; - } - - return false; -} - -bool CpuCanWrite(uint64_t usage) { - if (usage & BufferUsage::CPU_WRITE_MASK) { - // Application intends to use CPU for rendering - return true; - } - - return false; -} - -unsigned int GetSize(const BufferInfo &info, unsigned int alignedw, unsigned int alignedh) { - unsigned int size = 0; - int format = info.format; - int width = info.width; - int height = info.height; - uint64_t usage = info.usage; - - if (IsUBwcEnabled(format, usage)) { - return GetUBwcSize(width, height, format, alignedw, alignedh); - } - - if (IsUncompressedRGBFormat(format)) { - uint32_t bpp = GetBppForUncompressedRGB(format); - size = alignedw * alignedh * bpp; - return size; - } - - if (IsCompressedRGBFormat(format)) { - size = alignedw * alignedh * ASTC_BLOCK_SIZE; - return size; - } - - // Below switch should be for only YUV/custom formats - switch (format) { - case HAL_PIXEL_FORMAT_RAW16: - case HAL_PIXEL_FORMAT_Y16: - size = alignedw * alignedh * 2; - break; - case HAL_PIXEL_FORMAT_RAW10: - case HAL_PIXEL_FORMAT_RAW12: - size = ALIGN(alignedw * alignedh, SIZE_4K); - break; - case HAL_PIXEL_FORMAT_RAW8: - case HAL_PIXEL_FORMAT_Y8: - size = alignedw * alignedh * 1; - break; - - // adreno formats - case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO: // NV21 - size = ALIGN(alignedw * alignedh, SIZE_4K); - size += (unsigned int)ALIGN(2 * ALIGN(width / 2, 32) * ALIGN(height / 2, 32), SIZE_4K); - break; - case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED: // NV12 - // The chroma plane is subsampled, - // but the pitch in bytes is unchanged - // The GPU needs 4K alignment, but the video decoder needs 8K - size = ALIGN(alignedw * alignedh, SIZE_8K); - size += ALIGN(alignedw * (unsigned int)ALIGN(height / 2, 32), SIZE_8K); - break; - case HAL_PIXEL_FORMAT_YV12: - if ((format == HAL_PIXEL_FORMAT_YV12) && ((width & 1) || (height & 1))) { - ALOGE("w or h is odd for the YV12 format"); - return 0; - } - size = alignedw * alignedh + (ALIGN(alignedw / 2, 16) * (alignedh / 2)) * 2; - size = ALIGN(size, (unsigned int)SIZE_4K); - break; - case HAL_PIXEL_FORMAT_YCbCr_420_SP: - case HAL_PIXEL_FORMAT_YCrCb_420_SP: - size = ALIGN((alignedw * alignedh) + (alignedw * alignedh) / 2 + 1, SIZE_4K); - break; - case HAL_PIXEL_FORMAT_YCbCr_420_P010: - size = ALIGN((alignedw * alignedh * 2) + (alignedw * alignedh) + 1, SIZE_4K); - break; - case HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS: - size = VENUS_BUFFER_SIZE(COLOR_FMT_P010, width, height); - break; - case HAL_PIXEL_FORMAT_YCbCr_422_SP: - case HAL_PIXEL_FORMAT_YCrCb_422_SP: - case HAL_PIXEL_FORMAT_YCbCr_422_I: - case HAL_PIXEL_FORMAT_YCrCb_422_I: - case HAL_PIXEL_FORMAT_CbYCrY_422_I: - if (width & 1) { - ALOGE("width is odd for the YUV422_SP format"); - return 0; - } - size = ALIGN(alignedw * alignedh * 2, SIZE_4K); - break; - case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS: - case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: - size = VENUS_BUFFER_SIZE(COLOR_FMT_NV12, width, height); - break; - case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS: - size = VENUS_BUFFER_SIZE(COLOR_FMT_NV21, width, height); - break; - case HAL_PIXEL_FORMAT_BLOB: - case HAL_PIXEL_FORMAT_RAW_OPAQUE: - if (height != 1) { - ALOGE("%s: Buffers with HAL_PIXEL_FORMAT_BLOB must have height 1 ", __FUNCTION__); - return 0; - } - size = (unsigned int)width; - break; - case HAL_PIXEL_FORMAT_NV21_ZSL: - size = ALIGN((alignedw * alignedh) + (alignedw * alignedh) / 2, SIZE_4K); - break; - default: - ALOGE("%s: Unrecognized pixel format: 0x%x", __FUNCTION__, format); - return 0; - } - - return size; -} - -void GetBufferSizeAndDimensions(const BufferInfo &info, unsigned int *size, unsigned int *alignedw, - unsigned int *alignedh) { - GetAlignedWidthAndHeight(info, alignedw, alignedh); - *size = GetSize(info, *alignedw, *alignedh); -} - -void GetYuvUbwcSPPlaneInfo(uint64_t base, uint32_t width, uint32_t height, int color_format, - struct android_ycbcr *ycbcr) { - // UBWC buffer has these 4 planes in the following sequence: - // Y_Meta_Plane, Y_Plane, UV_Meta_Plane, UV_Plane - unsigned int y_meta_stride, y_meta_height, y_meta_size; - unsigned int y_stride, y_height, y_size; - unsigned int c_meta_stride, c_meta_height, c_meta_size; - unsigned int alignment = 4096; - - y_meta_stride = VENUS_Y_META_STRIDE(color_format, INT(width)); - y_meta_height = VENUS_Y_META_SCANLINES(color_format, INT(height)); - y_meta_size = ALIGN((y_meta_stride * y_meta_height), alignment); - - y_stride = VENUS_Y_STRIDE(color_format, INT(width)); - y_height = VENUS_Y_SCANLINES(color_format, INT(height)); - y_size = ALIGN((y_stride * y_height), alignment); - - c_meta_stride = VENUS_UV_META_STRIDE(color_format, INT(width)); - c_meta_height = VENUS_UV_META_SCANLINES(color_format, INT(height)); - c_meta_size = ALIGN((c_meta_stride * c_meta_height), alignment); - - ycbcr->y = reinterpret_cast(base + y_meta_size); - ycbcr->cb = reinterpret_cast(base + y_meta_size + y_size + c_meta_size); - ycbcr->cr = reinterpret_cast(base + y_meta_size + y_size + c_meta_size + 1); - ycbcr->ystride = y_stride; - ycbcr->cstride = VENUS_UV_STRIDE(color_format, INT(width)); -} - -void GetYuvUbwcInterlacedSPPlaneInfo(uint64_t base, uint32_t width, uint32_t height, - int color_format, struct android_ycbcr ycbcr[2]) { - unsigned int uv_stride, uv_height, uv_size; - unsigned int alignment = 4096; - uint64_t field_base; - - // UBWC interlaced has top-bottom field layout with each field as - // 4-plane NV12_UBWC with width = image_width & height = image_height / 2. - // Client passed ycbcr argument is ptr to struct android_ycbcr[2]. - // Plane info to be filled for each field separately. - height = (height + 1) >> 1; - uv_stride = VENUS_UV_STRIDE(color_format, INT(width)); - uv_height = VENUS_UV_SCANLINES(color_format, INT(height)); - uv_size = ALIGN((uv_stride * uv_height), alignment); - - field_base = base; - GetYuvUbwcSPPlaneInfo(field_base, width, height, COLOR_FMT_NV12_UBWC, &ycbcr[0]); - - memset(ycbcr[1].reserved, 0, sizeof(ycbcr[1].reserved)); - field_base = reinterpret_cast(ycbcr[0].cb) + uv_size; - GetYuvUbwcSPPlaneInfo(field_base, width, height, COLOR_FMT_NV12_UBWC, &ycbcr[1]); -} - -void GetYuvSPPlaneInfo(uint64_t base, uint32_t width, uint32_t height, uint32_t bpp, - struct android_ycbcr *ycbcr) { - unsigned int ystride, cstride; - - ystride = cstride = UINT(width) * bpp; - ycbcr->y = reinterpret_cast(base); - ycbcr->cb = reinterpret_cast(base + ystride * UINT(height)); - ycbcr->cr = reinterpret_cast(base + ystride * UINT(height) + 1); - ycbcr->ystride = ystride; - ycbcr->cstride = cstride; - ycbcr->chroma_step = 2 * bpp; -} - -int GetYUVPlaneInfo(const private_handle_t *hnd, struct android_ycbcr ycbcr[2]) { - int err = 0; - uint32_t width = UINT(hnd->width); - uint32_t height = UINT(hnd->height); - int format = hnd->format; - uint64_t usage = hnd->usage; - unsigned int ystride, cstride; - bool interlaced = false; - - memset(ycbcr->reserved, 0, sizeof(ycbcr->reserved)); - - // Check if UBWC buffer has been rendered in linear format. - int linear_format = 0; - if (getMetaData(const_cast(hnd), GET_LINEAR_FORMAT, &linear_format) == 0) { - format = INT(linear_format); - } - - // Check metadata if the geometry has been updated. - BufferDim_t buffer_dim; - if (getMetaData(const_cast(hnd), GET_BUFFER_GEOMETRY, &buffer_dim) == 0) { - BufferInfo info(buffer_dim.sliceWidth, buffer_dim.sliceHeight, format, usage); - GetAlignedWidthAndHeight(info, &width, &height); - } - - // Check metadata for interlaced content. - int interlace_flag = 0; - if (getMetaData(const_cast(hnd), GET_PP_PARAM_INTERLACED, &interlace_flag) == - 0) { - interlaced = interlace_flag; - } - - // Get the chroma offsets from the handle width/height. We take advantage - // of the fact the width _is_ the stride - switch (format) { - // Semiplanar - case HAL_PIXEL_FORMAT_YCbCr_420_SP: - case HAL_PIXEL_FORMAT_YCbCr_422_SP: - case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS: - case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: - // Same as YCbCr_420_SP_VENUS - GetYuvSPPlaneInfo(hnd->base, width, height, 1, ycbcr); - break; - - case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC: - if (!interlaced) { - GetYuvUbwcSPPlaneInfo(hnd->base, width, height, COLOR_FMT_NV12_UBWC, ycbcr); - } else { - GetYuvUbwcInterlacedSPPlaneInfo(hnd->base, width, height, COLOR_FMT_NV12_UBWC, ycbcr); - } - ycbcr->chroma_step = 2; - break; - - case HAL_PIXEL_FORMAT_YCbCr_420_P010: - GetYuvSPPlaneInfo(hnd->base, width, height, 2, ycbcr); - break; - - case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC: - GetYuvUbwcSPPlaneInfo(hnd->base, width, height, COLOR_FMT_NV12_BPP10_UBWC, ycbcr); - ycbcr->chroma_step = 3; - break; - - case HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC: - GetYuvUbwcSPPlaneInfo(hnd->base, width, height, COLOR_FMT_P010_UBWC, ycbcr); - ycbcr->chroma_step = 4; - break; - - case HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS: - ystride = VENUS_Y_STRIDE(COLOR_FMT_P010, width); - cstride = VENUS_UV_STRIDE(COLOR_FMT_P010, width); - ycbcr->y = reinterpret_cast(hnd->base); - ycbcr->cb = - reinterpret_cast(hnd->base + ystride * VENUS_Y_SCANLINES(COLOR_FMT_P010, height)); - ycbcr->cr = reinterpret_cast(hnd->base + - ystride * VENUS_Y_SCANLINES(COLOR_FMT_P010, height) + 1); - ycbcr->ystride = ystride; - ycbcr->cstride = cstride; - ycbcr->chroma_step = 4; - break; - - case HAL_PIXEL_FORMAT_YCrCb_420_SP: - case HAL_PIXEL_FORMAT_YCrCb_422_SP: - case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO: - case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS: - case HAL_PIXEL_FORMAT_NV21_ZSL: - case HAL_PIXEL_FORMAT_RAW16: - case HAL_PIXEL_FORMAT_Y16: - case HAL_PIXEL_FORMAT_RAW10: - case HAL_PIXEL_FORMAT_RAW8: - case HAL_PIXEL_FORMAT_Y8: - GetYuvSPPlaneInfo(hnd->base, width, height, 1, ycbcr); - std::swap(ycbcr->cb, ycbcr->cr); - break; - - // Planar - case HAL_PIXEL_FORMAT_YV12: - ystride = width; - cstride = ALIGN(width / 2, 16); - ycbcr->y = reinterpret_cast(hnd->base); - ycbcr->cr = reinterpret_cast(hnd->base + ystride * height); - ycbcr->cb = reinterpret_cast(hnd->base + ystride * height + cstride * height / 2); - ycbcr->ystride = ystride; - ycbcr->cstride = cstride; - ycbcr->chroma_step = 1; - break; - case HAL_PIXEL_FORMAT_CbYCrY_422_I: - ystride = width * 2; - cstride = 0; - ycbcr->y = reinterpret_cast(hnd->base); - ycbcr->cr = NULL; - ycbcr->cb = NULL; - ycbcr->ystride = ystride; - ycbcr->cstride = 0; - ycbcr->chroma_step = 0; - break; - // Unsupported formats - case HAL_PIXEL_FORMAT_YCbCr_422_I: - case HAL_PIXEL_FORMAT_YCrCb_422_I: - case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED: - default: - ALOGD("%s: Invalid format passed: 0x%x", __FUNCTION__, format); - err = -EINVAL; - } - - return err; -} - -// Explicitly defined UBWC formats -bool IsUBwcFormat(int format) { - switch (format) { - case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC: - case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC: - case HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC: - return true; - default: - return false; - } -} - -bool IsUBwcSupported(int format) { - // Existing HAL formats with UBWC support - switch (format) { - case HAL_PIXEL_FORMAT_BGR_565: - case HAL_PIXEL_FORMAT_RGBA_8888: - case HAL_PIXEL_FORMAT_RGBX_8888: - case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: - case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS: - case HAL_PIXEL_FORMAT_RGBA_1010102: - case HAL_PIXEL_FORMAT_RGBX_1010102: - return true; - default: - break; - } - - return false; -} - -bool IsUBwcEnabled(int format, uint64_t usage) { - // Allow UBWC, if client is using an explicitly defined UBWC pixel format. - if (IsUBwcFormat(format)) { - return true; - } - - // Allow UBWC, if an OpenGL client sets UBWC usage flag and GPU plus MDP - // support the format. OR if a non-OpenGL client like Rotator, sets UBWC - // usage flag and MDP supports the format. - if ((usage & GRALLOC_USAGE_PRIVATE_ALLOC_UBWC) && IsUBwcSupported(format)) { - bool enable = true; - // Query GPU for UBWC only if buffer is intended to be used by GPU. - if ((usage & BufferUsage::GPU_TEXTURE) || (usage & BufferUsage::GPU_RENDER_TARGET)) { - if (AdrenoMemInfo::GetInstance()) { - enable = AdrenoMemInfo::GetInstance()->IsUBWCSupportedByGPU(format); - } - } - - // Allow UBWC, only if CPU usage flags are not set - if (enable && !(CpuCanAccess(usage))) { - return true; - } - } - - return false; -} - -void GetYuvUBwcWidthAndHeight(int width, int height, int format, unsigned int *aligned_w, - unsigned int *aligned_h) { - switch (format) { - case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: - case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS: - case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC: - *aligned_w = VENUS_Y_STRIDE(COLOR_FMT_NV12_UBWC, width); - *aligned_h = VENUS_Y_SCANLINES(COLOR_FMT_NV12_UBWC, height); - break; - case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC: - // The macro returns the stride which is 4/3 times the width, hence * 3/4 - *aligned_w = (VENUS_Y_STRIDE(COLOR_FMT_NV12_BPP10_UBWC, width) * 3) / 4; - *aligned_h = VENUS_Y_SCANLINES(COLOR_FMT_NV12_BPP10_UBWC, height); - break; - case HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC: - // The macro returns the stride which is 2 times the width, hence / 2 - *aligned_w = (VENUS_Y_STRIDE(COLOR_FMT_P010_UBWC, width) / 2); - *aligned_h = VENUS_Y_SCANLINES(COLOR_FMT_P010_UBWC, height); - break; - default: - ALOGE("%s: Unsupported pixel format: 0x%x", __FUNCTION__, format); - *aligned_w = 0; - *aligned_h = 0; - break; - } -} - -void GetRgbUBwcBlockSize(uint32_t bpp, int *block_width, int *block_height) { - *block_width = 0; - *block_height = 0; - - switch (bpp) { - case 2: - case 4: - *block_width = 16; - *block_height = 4; - break; - case 8: - *block_width = 8; - *block_height = 4; - break; - case 16: - *block_width = 4; - *block_height = 4; - break; - default: - ALOGE("%s: Unsupported bpp: %d", __FUNCTION__, bpp); - break; - } -} - -unsigned int GetRgbUBwcMetaBufferSize(int width, int height, uint32_t bpp) { - unsigned int size = 0; - int meta_width, meta_height; - int block_width, block_height; - - GetRgbUBwcBlockSize(bpp, &block_width, &block_height); - if (!block_width || !block_height) { - ALOGE("%s: Unsupported bpp: %d", __FUNCTION__, bpp); - return size; - } - - // Align meta buffer height to 16 blocks - meta_height = ALIGN(((height + block_height - 1) / block_height), 16); - - // Align meta buffer width to 64 blocks - meta_width = ALIGN(((width + block_width - 1) / block_width), 64); - - // Align meta buffer size to 4K - size = (unsigned int)ALIGN((meta_width * meta_height), 4096); - - return size; -} - -unsigned int GetUBwcSize(int width, int height, int format, unsigned int alignedw, - unsigned int alignedh) { - unsigned int size = 0; - uint32_t bpp = 0; - switch (format) { - case HAL_PIXEL_FORMAT_BGR_565: - case HAL_PIXEL_FORMAT_RGBA_8888: - case HAL_PIXEL_FORMAT_RGBX_8888: - case HAL_PIXEL_FORMAT_RGBA_1010102: - case HAL_PIXEL_FORMAT_RGBX_1010102: - bpp = GetBppForUncompressedRGB(format); - size = alignedw * alignedh * bpp; - size += GetRgbUBwcMetaBufferSize(width, height, bpp); - break; - case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: - case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS: - case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC: - size = VENUS_BUFFER_SIZE(COLOR_FMT_NV12_UBWC, width, height); - break; - case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC: - size = VENUS_BUFFER_SIZE(COLOR_FMT_NV12_BPP10_UBWC, width, height); - break; - case HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC: - size = VENUS_BUFFER_SIZE(COLOR_FMT_P010_UBWC, width, height); - break; - default: - ALOGE("%s: Unsupported pixel format: 0x%x", __FUNCTION__, format); - break; - } - - return size; -} - -int GetRgbDataAddress(private_handle_t *hnd, void **rgb_data) { - int err = 0; - - // This api is for RGB* formats - if (!IsUncompressedRGBFormat(hnd->format)) { - return -EINVAL; - } - - // linear buffer, nothing to do further - if (!(hnd->flags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED)) { - *rgb_data = reinterpret_cast(hnd->base); - return err; - } - - unsigned int meta_size = 0; - uint32_t bpp = GetBppForUncompressedRGB(hnd->format); - switch (hnd->format) { - case HAL_PIXEL_FORMAT_BGR_565: - case HAL_PIXEL_FORMAT_RGBA_8888: - case HAL_PIXEL_FORMAT_RGBX_8888: - case HAL_PIXEL_FORMAT_RGBA_1010102: - case HAL_PIXEL_FORMAT_RGBX_1010102: - meta_size = GetRgbUBwcMetaBufferSize(hnd->width, hnd->height, bpp); - break; - default: - ALOGE("%s:Unsupported RGB format: 0x%x", __FUNCTION__, hnd->format); - err = -EINVAL; - break; - } - *rgb_data = reinterpret_cast(hnd->base + meta_size); - - return err; -} - -void GetCustomDimensions(private_handle_t *hnd, int *stride, int *height) { - BufferDim_t buffer_dim; - int interlaced = 0; - - *stride = hnd->width; - *height = hnd->height; - if (getMetaData(hnd, GET_BUFFER_GEOMETRY, &buffer_dim) == 0) { - *stride = buffer_dim.sliceWidth; - *height = buffer_dim.sliceHeight; - } else if (getMetaData(hnd, GET_PP_PARAM_INTERLACED, &interlaced) == 0) { - if (interlaced && IsUBwcFormat(hnd->format)) { - unsigned int alignedw = 0, alignedh = 0; - // Get re-aligned height for single ubwc interlaced field and - // multiply by 2 to get frame height. - BufferInfo info(hnd->width, ((hnd->height + 1) >> 1), hnd->format); - GetAlignedWidthAndHeight(info, &alignedw, &alignedh); - *stride = static_cast(alignedw); - *height = static_cast(alignedh * 2); - } - } -} - -void GetColorSpaceFromMetadata(private_handle_t *hnd, int *color_space) { - ColorMetaData color_metadata; - if (getMetaData(hnd, GET_COLOR_METADATA, &color_metadata) == 0) { - switch (color_metadata.colorPrimaries) { - case ColorPrimaries_BT709_5: - *color_space = HAL_CSC_ITU_R_709; - break; - case ColorPrimaries_BT601_6_525: - case ColorPrimaries_BT601_6_625: - *color_space = ((color_metadata.range) ? HAL_CSC_ITU_R_601_FR : HAL_CSC_ITU_R_601); - break; - case ColorPrimaries_BT2020: - *color_space = (color_metadata.range) ? HAL_CSC_ITU_R_2020_FR : HAL_CSC_ITU_R_2020; - break; - default: - ALOGE("Unknown Color Space = %d", color_metadata.colorPrimaries); - break; - } - } else if (getMetaData(hnd, GET_COLOR_SPACE, color_space) != 0) { - *color_space = 0; - } -} - -void GetAlignedWidthAndHeight(const BufferInfo &info, unsigned int *alignedw, - unsigned int *alignedh) { - int width = info.width; - int height = info.height; - int format = info.format; - uint64_t usage = info.usage; - - // Currently surface padding is only computed for RGB* surfaces. - bool ubwc_enabled = IsUBwcEnabled(format, usage); - int tile = ubwc_enabled; - - if (IsUncompressedRGBFormat(format)) { - if (AdrenoMemInfo::GetInstance()) { - AdrenoMemInfo::GetInstance()->AlignUnCompressedRGB(width, height, format, tile, alignedw, - alignedh); - } - return; - } - - if (ubwc_enabled) { - GetYuvUBwcWidthAndHeight(width, height, format, alignedw, alignedh); - return; - } - - if (IsCompressedRGBFormat(format)) { - if (AdrenoMemInfo::GetInstance()) { - AdrenoMemInfo::GetInstance()->AlignCompressedRGB(width, height, format, alignedw, alignedh); - } - return; - } - - int aligned_w = width; - int aligned_h = height; - unsigned int alignment = 32; - - // Below should be only YUV family - switch (format) { - case HAL_PIXEL_FORMAT_YCrCb_420_SP: - case HAL_PIXEL_FORMAT_YCbCr_420_SP: - if (AdrenoMemInfo::GetInstance() == nullptr) { - return; - } - alignment = AdrenoMemInfo::GetInstance()->GetGpuPixelAlignment(); - aligned_w = ALIGN(width, alignment); - break; - case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO: - aligned_w = ALIGN(width, alignment); - break; - case HAL_PIXEL_FORMAT_RAW16: - case HAL_PIXEL_FORMAT_Y16: - case HAL_PIXEL_FORMAT_Y8: - aligned_w = ALIGN(width, 16); - break; - case HAL_PIXEL_FORMAT_RAW12: - aligned_w = ALIGN(width * 12 / 8, 16); - break; - case HAL_PIXEL_FORMAT_RAW10: - aligned_w = ALIGN(width * 10 / 8, 16); - break; - case HAL_PIXEL_FORMAT_RAW8: - aligned_w = ALIGN(width, 16); - break; - case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED: - aligned_w = ALIGN(width, 128); - break; - case HAL_PIXEL_FORMAT_YV12: - case HAL_PIXEL_FORMAT_YCbCr_422_SP: - case HAL_PIXEL_FORMAT_YCrCb_422_SP: - case HAL_PIXEL_FORMAT_YCbCr_422_I: - case HAL_PIXEL_FORMAT_YCrCb_422_I: - case HAL_PIXEL_FORMAT_YCbCr_420_P010: - aligned_w = ALIGN(width, 16); - break; - case HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS: - aligned_w = INT(VENUS_Y_STRIDE(COLOR_FMT_P010, width) / 2); - aligned_h = INT(VENUS_Y_SCANLINES(COLOR_FMT_P010, height)); - break; - case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS: - case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: - aligned_w = INT(VENUS_Y_STRIDE(COLOR_FMT_NV12, width)); - aligned_h = INT(VENUS_Y_SCANLINES(COLOR_FMT_NV12, height)); - break; - case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS: - aligned_w = INT(VENUS_Y_STRIDE(COLOR_FMT_NV21, width)); - aligned_h = INT(VENUS_Y_SCANLINES(COLOR_FMT_NV21, height)); - break; - case HAL_PIXEL_FORMAT_BLOB: - case HAL_PIXEL_FORMAT_RAW_OPAQUE: - break; - case HAL_PIXEL_FORMAT_NV21_ZSL: - aligned_w = ALIGN(width, 64); - aligned_h = ALIGN(height, 64); - break; - default: - break; - } - - *alignedw = (unsigned int)aligned_w; - *alignedh = (unsigned int)aligned_h; -} - -int GetBufferLayout(private_handle_t *hnd, uint32_t stride[4], uint32_t offset[4], - uint32_t *num_planes) { - if (!hnd || !stride || !offset || !num_planes) { - return -EINVAL; - } - - struct android_ycbcr yuvPlaneInfo[2] = {}; - *num_planes = 1; - stride[0] = 0; - - switch (hnd->format) { - case HAL_PIXEL_FORMAT_RGB_565: - case HAL_PIXEL_FORMAT_BGR_565: - case HAL_PIXEL_FORMAT_RGBA_5551: - case HAL_PIXEL_FORMAT_RGBA_4444: - stride[0] = static_cast(hnd->width * 2); - break; - case HAL_PIXEL_FORMAT_RGB_888: - stride[0] = static_cast(hnd->width * 3); - break; - case HAL_PIXEL_FORMAT_RGBA_8888: - case HAL_PIXEL_FORMAT_BGRA_8888: - case HAL_PIXEL_FORMAT_RGBX_8888: - case HAL_PIXEL_FORMAT_BGRX_8888: - case HAL_PIXEL_FORMAT_RGBA_1010102: - case HAL_PIXEL_FORMAT_ARGB_2101010: - case HAL_PIXEL_FORMAT_RGBX_1010102: - case HAL_PIXEL_FORMAT_XRGB_2101010: - case HAL_PIXEL_FORMAT_BGRA_1010102: - case HAL_PIXEL_FORMAT_ABGR_2101010: - case HAL_PIXEL_FORMAT_BGRX_1010102: - case HAL_PIXEL_FORMAT_XBGR_2101010: - stride[0] = static_cast(hnd->width * 4); - break; - } - - // Format is RGB - if (stride[0]) { - return 0; - } - - (*num_planes)++; - int ret = GetYUVPlaneInfo(hnd, yuvPlaneInfo); - if (ret < 0) { - ALOGE("%s failed", __FUNCTION__); - return ret; - } - - // We are only returning buffer layout for progressive or single field formats. - struct android_ycbcr yuvInfo = yuvPlaneInfo[0]; - stride[0] = static_cast(yuvInfo.ystride); - offset[0] = static_cast(reinterpret_cast(yuvInfo.y) - hnd->base); - stride[1] = static_cast(yuvInfo.cstride); - switch (hnd->format) { - case HAL_PIXEL_FORMAT_YCbCr_420_SP: - case HAL_PIXEL_FORMAT_YCbCr_422_SP: - case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS: - case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: - case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC: - case HAL_PIXEL_FORMAT_YCbCr_420_P010: - case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC: - case HAL_PIXEL_FORMAT_YCbCr_420_P010_UBWC: - case HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS: - offset[1] = static_cast(reinterpret_cast(yuvInfo.cb) - hnd->base); - break; - case HAL_PIXEL_FORMAT_YCrCb_420_SP: - case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS: - case HAL_PIXEL_FORMAT_YCrCb_422_SP: - offset[1] = static_cast(reinterpret_cast(yuvInfo.cr) - hnd->base); - break; - case HAL_PIXEL_FORMAT_YV12: - offset[1] = static_cast(reinterpret_cast(yuvInfo.cr) - hnd->base); - stride[2] = static_cast(yuvInfo.cstride); - offset[2] = static_cast(reinterpret_cast(yuvInfo.cb) - hnd->base); - (*num_planes)++; - break; - default: - ALOGW("%s: Unsupported format", __FUNCTION__); - ret = -EINVAL; - } - - if (hnd->flags & private_handle_t::PRIV_FLAGS_UBWC_ALIGNED) { - std::fill(offset, offset + 4, 0); - } - - return 0; -} - -} // namespace gralloc diff --git a/gralloc/gr_utils.h b/gralloc/gr_utils.h deleted file mode 100644 index eb35a6a3..00000000 --- a/gralloc/gr_utils.h +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2011-2016,2018, The Linux Foundation. All rights reserved. - - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of The Linux Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __GR_UTILS_H__ -#define __GR_UTILS_H__ - -#include -#include "gralloc_priv.h" - -#define SZ_2M 0x200000 -#define SZ_1M 0x100000 -#define SZ_4K 0x1000 - -#define SIZE_4K 4096 -#define SIZE_8K 4096 - -#define INT(exp) static_cast(exp) -#define UINT(exp) static_cast(exp) - -using android::hardware::graphics::common::V1_0::BufferUsage; - -namespace gralloc { -struct BufferInfo { - BufferInfo(int w, int h, int f, uint64_t usage = 0) - : width(w), height(h), format(f), usage(usage) {} - int width; - int height; - int format; - uint64_t usage; -}; - -template -inline Type1 ALIGN(Type1 x, Type2 align) { - return (Type1)((x + (Type1)align - 1) & ~((Type1)align - 1)); -} - -bool IsYuvFormat(const private_handle_t *hnd); -bool IsCompressedRGBFormat(int format); -bool IsUncompressedRGBFormat(int format); -uint32_t GetBppForUncompressedRGB(int format); -bool CpuCanAccess(uint64_t usage); -bool CpuCanRead(uint64_t usage); -bool CpuCanWrite(uint64_t usage); -unsigned int GetSize(const BufferInfo &d, unsigned int alignedw, unsigned int alignedh); -void GetBufferSizeAndDimensions(const BufferInfo &d, unsigned int *size, unsigned int *alignedw, - unsigned int *alignedh); -void GetCustomDimensions(private_handle_t *hnd, int *stride, int *height); -void GetColorSpaceFromMetadata(private_handle_t *hnd, int *color_space); -void GetAlignedWidthAndHeight(const BufferInfo &d, unsigned int *aligned_w, - unsigned int *aligned_h); -int GetYUVPlaneInfo(const private_handle_t *hnd, struct android_ycbcr ycbcr[2]); -int GetRgbDataAddress(private_handle_t *hnd, void **rgb_data); -bool IsUBwcFormat(int format); -bool IsUBwcSupported(int format); -bool IsUBwcEnabled(int format, uint64_t usage); -void GetYuvUBwcWidthAndHeight(int width, int height, int format, unsigned int *aligned_w, - unsigned int *aligned_h); -void GetYuvSPPlaneInfo(uint64_t base, uint32_t width, uint32_t height, uint32_t bpp, - struct android_ycbcr *ycbcr); -void GetYuvUbwcSPPlaneInfo(uint64_t base, uint32_t width, uint32_t height, int color_format, - struct android_ycbcr *ycbcr); -void GetYuvUbwcInterlacedSPPlaneInfo(uint64_t base, uint32_t width, uint32_t height, - int color_format, struct android_ycbcr ycbcr[2]); -void GetRgbUBwcBlockSize(uint32_t bpp, int *block_width, int *block_height); -unsigned int GetRgbUBwcMetaBufferSize(int width, int height, uint32_t bpp); -unsigned int GetUBwcSize(int width, int height, int format, unsigned int alignedw, - unsigned int alignedh); -int GetBufferLayout(private_handle_t *hnd, uint32_t stride[4], uint32_t offset[4], - uint32_t *num_planes); - -} // namespace gralloc - -#endif // __GR_UTILS_H__ diff --git a/gralloc/service.cpp b/gralloc/service.cpp deleted file mode 100644 index 5832386b..00000000 --- a/gralloc/service.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2018, The Linux Foundation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of The Linux Foundation. nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -#include -#include "QtiAllocator.h" - -using android::hardware::configureRpcThreadpool; -using android::hardware::joinRpcThreadpool; -using vendor::qti::hardware::display::allocator::V1_0::implementation::QtiAllocator; -using android::hardware::graphics::allocator::V2_0::IAllocator; - -int main(int, char **) { - android::sp service = new QtiAllocator(); - configureRpcThreadpool(4, true /*callerWillJoin*/); - if (service->registerAsService() != android::OK) { - ALOGE("Cannot register QTI Allocator service"); - return -EINVAL; - } - ALOGI("Initialized qti-allocator"); - joinRpcThreadpool(); - return 0; -} diff --git a/gralloc/vendor.qti.hardware.display.allocator@1.0-service.rc b/gralloc/vendor.qti.hardware.display.allocator@1.0-service.rc deleted file mode 100644 index 07bb2ff5..00000000 --- a/gralloc/vendor.qti.hardware.display.allocator@1.0-service.rc +++ /dev/null @@ -1,6 +0,0 @@ -service vendor.qti.hardware.display.allocator /vendor/bin/hw/vendor.qti.hardware.display.allocator@1.0-service - class hal animation - user system - group graphics drmrpc - capabilities SYS_NICE - onrestart restart surfaceflinger diff --git a/hdmi_cec/Android.mk b/hdmi_cec/Android.mk deleted file mode 100644 index a333654c..00000000 --- a/hdmi_cec/Android.mk +++ /dev/null @@ -1,18 +0,0 @@ -LOCAL_PATH := $(call my-dir) -include $(LOCAL_PATH)/../common.mk -include $(CLEAR_VARS) - -LOCAL_MODULE := hdmi_cec.$(TARGET_BOARD_PLATFORM) -LOCAL_VENDOR_MODULE := true -LOCAL_MODULE_RELATIVE_PATH := hw -LOCAL_MODULE_TAGS := optional -LOCAL_C_INCLUDES := $(common_includes) -LOCAL_HEADER_LIBRARIES := display_headers -LOCAL_SHARED_LIBRARIES := $(common_libs) libqservice libbinder libqdutils - -LOCAL_CFLAGS := $(common_flags) -DLOG_TAG=\"qdhdmi_cec\" -Wno-sign-conversion -LOCAL_CLANG := true -LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps) -LOCAL_SRC_FILES := qhdmi_cec.cpp \ - QHDMIClient.cpp -include $(BUILD_SHARED_LIBRARY) diff --git a/hdmi_cec/QHDMIClient.cpp b/hdmi_cec/QHDMIClient.cpp deleted file mode 100644 index 2b2b1e6f..00000000 --- a/hdmi_cec/QHDMIClient.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* -* Copyright (c) 2014 The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation. nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#define DEBUG 0 -#include -#include "QHDMIClient.h" - -using namespace android; -using namespace qhdmicec; -using namespace qService; - -namespace qClient { - -void QHDMIClient::binderDied(const wp& who __unused) -{ - ALOGW("%s: Display QService died", __FUNCTION__); -} - -void QHDMIClient::onHdmiHotplug(int connected) -{ - ALOGD("%s: HDMI connected event connected: %d", __FUNCTION__, connected); - cec_hdmi_hotplug(mCtx, connected); -} - -void QHDMIClient::onCECMessageRecieved(char *msg, ssize_t len) -{ - ALOGD_IF(DEBUG, "%s: CEC message received len: %zd", __FUNCTION__, len); - cec_receive_message(mCtx, msg, len); -} - -void QHDMIClient::registerClient(sp& client) -{ - sp sm = defaultServiceManager(); - sp binder = sm->getService(String16("display.qservice")); - binder->linkToDeath(client); - mQService = interface_cast(binder); - mQService->connect(interface_cast(client)); -} - -}; diff --git a/hdmi_cec/QHDMIClient.h b/hdmi_cec/QHDMIClient.h deleted file mode 100644 index 9e54f2f4..00000000 --- a/hdmi_cec/QHDMIClient.h +++ /dev/null @@ -1,57 +0,0 @@ -/* -* Copyright (c) 2014 The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation. nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include "IQHDMIClient.h" -#include "qhdmi_cec.h" -#include - -namespace qClient { - -class QHDMIClient: public android::IBinder::DeathRecipient, - public BnQHDMIClient -{ -public: - QHDMIClient() {} - - virtual void binderDied(const android::wp& who); - - virtual void onHdmiHotplug(int connected); - - virtual void onCECMessageRecieved(char *msg, ssize_t len); - - void setCECContext(qhdmicec::cec_context_t* ctx) { mCtx = ctx; } - - void registerClient(android::sp& client); - -private: - qhdmicec::cec_context_t* mCtx; - android::sp mQService; - -}; -}; diff --git a/hdmi_cec/qhdmi_cec.cpp b/hdmi_cec/qhdmi_cec.cpp deleted file mode 100644 index 2760334a..00000000 --- a/hdmi_cec/qhdmi_cec.cpp +++ /dev/null @@ -1,520 +0,0 @@ -/* -* Copyright (c) 2014, 2016-2017, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation. nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#define DEBUG 0 -#define ATRACE_TAG (ATRACE_TAG_GRAPHICS | ATRACE_TAG_HAL) -#include -#include -#include -#include -#include -#include -#include "qhdmi_cec.h" -#include "QHDMIClient.h" - -namespace qhdmicec { - -const int NUM_HDMI_PORTS = 1; -const int MAX_SYSFS_DATA = 128; -const int MAX_CEC_FRAME_SIZE = 20; -const int MAX_SEND_MESSAGE_RETRIES = 1; - -enum { - LOGICAL_ADDRESS_SET = 1, - LOGICAL_ADDRESS_UNSET = -1, -}; - -// Offsets of members of struct hdmi_cec_msg -// drivers/video/msm/mdss/mdss_hdmi_cec.c -// XXX: Get this from a driver header -enum { - CEC_OFFSET_SENDER_ID, - CEC_OFFSET_RECEIVER_ID, - CEC_OFFSET_OPCODE, - CEC_OFFSET_OPERAND, - CEC_OFFSET_FRAME_LENGTH = 17, - CEC_OFFSET_RETRANSMIT, -}; - -//Forward declarations -static void cec_close_context(cec_context_t* ctx __unused); -static int cec_enable(cec_context_t *ctx, int enable); -static int cec_is_connected(const struct hdmi_cec_device* dev, int port_id); - -static ssize_t read_node(const char *path, char *data) -{ - ssize_t err = 0; - FILE *fp = NULL; - err = access(path, R_OK); - if (!err) { - fp = fopen(path, "r"); - if (fp) { - err = fread(data, sizeof(char), MAX_SYSFS_DATA ,fp); - fclose(fp); - } - } - return err; -} - -static ssize_t write_node(const char *path, const char *data, size_t len) -{ - ssize_t err = 0; - int fd = -1; - err = access(path, W_OK); - if (!err) { - fd = open(path, O_WRONLY); - errno = 0; - err = write(fd, data, len); - if (err < 0) { - err = -errno; - } - close(fd); - } else { - ALOGE("%s: Failed to access path: %s error: %s", - __FUNCTION__, path, strerror(errno)); - err = -errno; - } - return err; -} - -// Helper function to write integer values to the full sysfs path -static ssize_t write_int_to_node(cec_context_t *ctx, - const char *path_postfix, - const int value) -{ - char sysfs_full_path[MAX_PATH_LENGTH]; - char sysfs_data[MAX_SYSFS_DATA]; - snprintf(sysfs_data, sizeof(sysfs_data), "%d",value); - snprintf(sysfs_full_path,sizeof(sysfs_full_path), "%s/%s", - ctx->fb_sysfs_path, path_postfix); - ssize_t err = write_node(sysfs_full_path, sysfs_data, strlen(sysfs_data)); - return err; -} - -static void hex_to_string(const char *msg, ssize_t len, char *str) -{ - //Functions assumes sufficient memory in str - char *ptr = str; - for(int i=0; i < len ; i++) { - ptr += snprintf(ptr, 3, "%02X", msg[i]); - // Overwrite null termination of snprintf in all except the last byte - if (i < len - 1) - *ptr = ':'; - ptr++; - } -} - -static ssize_t cec_get_fb_node_number(cec_context_t *ctx) -{ - //XXX: Do this from a common utility library across the display HALs - const int MAX_FB_DEVICES = 2; - ssize_t len = 0; - char fb_type_path[MAX_PATH_LENGTH]; - char fb_type[MAX_SYSFS_DATA]; - const char *dtv_panel_str = "dtv panel"; - - for(int num = 0; num < MAX_FB_DEVICES; num++) { - snprintf(fb_type_path, sizeof(fb_type_path),"%s%d/msm_fb_type", - SYSFS_BASE,num); - ALOGD_IF(DEBUG, "%s: num: %d fb_type_path: %s", __FUNCTION__, num, fb_type_path); - len = read_node(fb_type_path, fb_type); - ALOGD_IF(DEBUG, "%s: fb_type:%s", __FUNCTION__, fb_type); - if(len > 0 && (strncmp(fb_type, dtv_panel_str, strlen(dtv_panel_str)) == 0)){ - ALOGD_IF(DEBUG, "%s: Found DTV panel at fb%d", __FUNCTION__, num); - ctx->fb_num = num; - snprintf(ctx->fb_sysfs_path, sizeof(ctx->fb_sysfs_path), - "%s%d", SYSFS_BASE, num); - break; - } - } - if (len < 0) - return len; - else - return 0; -} - -static int cec_add_logical_address(const struct hdmi_cec_device* dev, - cec_logical_address_t addr) -{ - if (addr < CEC_ADDR_TV || addr > CEC_ADDR_BROADCAST) { - ALOGE("%s: Received invalid address: %d ", __FUNCTION__, addr); - return -EINVAL; - } - cec_context_t* ctx = (cec_context_t*)(dev); - ctx->logical_address[addr] = LOGICAL_ADDRESS_SET; - - //XXX: We can get multiple logical addresses here but we can only send one - //to the driver. Store locally for now - ssize_t err = write_int_to_node(ctx, "cec/logical_addr", addr); - ALOGI("%s: Allocated logical address: %d ", __FUNCTION__, addr); - return (int) err; -} - -static void cec_clear_logical_address(const struct hdmi_cec_device* dev) -{ - cec_context_t* ctx = (cec_context_t*)(dev); - memset(ctx->logical_address, LOGICAL_ADDRESS_UNSET, - sizeof(ctx->logical_address)); - //XXX: Find logical_addr that needs to be reset - write_int_to_node(ctx, "cec/logical_addr", 15); - ALOGD_IF(DEBUG, "%s: Cleared logical addresses", __FUNCTION__); -} - -static int cec_get_physical_address(const struct hdmi_cec_device* dev, - uint16_t* addr) -{ - cec_context_t* ctx = (cec_context_t*)(dev); - char pa_path[MAX_PATH_LENGTH]; - char pa_data[MAX_SYSFS_DATA]; - snprintf (pa_path, sizeof(pa_path),"%s/pa", - ctx->fb_sysfs_path); - int err = (int) read_node(pa_path, pa_data); - *addr = (uint16_t) atoi(pa_data); - ALOGD_IF(DEBUG, "%s: Physical Address: 0x%x", __FUNCTION__, *addr); - if (err < 0) - return err; - else - return 0; -} - -static int cec_send_message(const struct hdmi_cec_device* dev, - const cec_message_t* msg) -{ - ATRACE_CALL(); - if(cec_is_connected(dev, 0) <= 0) - return HDMI_RESULT_FAIL; - - cec_context_t* ctx = (cec_context_t*)(dev); - ALOGD_IF(DEBUG, "%s: initiator: %d destination: %d length: %u", - __FUNCTION__, msg->initiator, msg->destination, - (uint32_t) msg->length); - - // Dump message received from framework - char dump[128]; - if(msg->length > 0) { - hex_to_string((char*)msg->body, msg->length, dump); - ALOGD_IF(DEBUG, "%s: message from framework: %s", __FUNCTION__, dump); - } - - char write_msg_path[MAX_PATH_LENGTH]; - char write_msg[MAX_CEC_FRAME_SIZE]; - memset(write_msg, 0, sizeof(write_msg)); - // See definition of struct hdmi_cec_msg in driver code - // drivers/video/msm/mdss/mdss_hdmi_cec.c - // Write header block - // XXX: Include this from header in kernel - write_msg[CEC_OFFSET_SENDER_ID] = msg->initiator; - write_msg[CEC_OFFSET_RECEIVER_ID] = msg->destination; - //Kernel splits opcode/operand, but Android sends it in one byte array - write_msg[CEC_OFFSET_OPCODE] = msg->body[0]; - if(msg->length > 1) { - memcpy(&write_msg[CEC_OFFSET_OPERAND], &msg->body[1], - sizeof(char)*(msg->length - 1)); - } - //msg length + initiator + destination - write_msg[CEC_OFFSET_FRAME_LENGTH] = (unsigned char) (msg->length + 1); - hex_to_string(write_msg, sizeof(write_msg), dump); - ALOGD_IF(DEBUG, "%s: message to driver: %s", __FUNCTION__, dump); - snprintf(write_msg_path, sizeof(write_msg_path), "%s/cec/wr_msg", - ctx->fb_sysfs_path); - int retry_count = 0; - ssize_t err = 0; - //HAL spec requires us to retry at least once. - while (true) { - err = write_node(write_msg_path, write_msg, sizeof(write_msg)); - retry_count++; - if (err == -EAGAIN && retry_count <= MAX_SEND_MESSAGE_RETRIES) { - ALOGE("%s: CEC line busy, retrying", __FUNCTION__); - } else { - break; - } - } - - if (err < 0) { - if (err == -ENXIO) { - ALOGI("%s: No device exists with the destination address", - __FUNCTION__); - return HDMI_RESULT_NACK; - } else if (err == -EAGAIN) { - ALOGE("%s: CEC line is busy, max retry count exceeded", - __FUNCTION__); - return HDMI_RESULT_BUSY; - } else { - return HDMI_RESULT_FAIL; - ALOGE("%s: Failed to send CEC message err: %zd - %s", - __FUNCTION__, err, strerror(int(-err))); - } - } else { - ALOGD_IF(DEBUG, "%s: Sent CEC message - %zd bytes written", - __FUNCTION__, err); - return HDMI_RESULT_SUCCESS; - } -} - -void cec_receive_message(cec_context_t *ctx, char *msg, ssize_t len) -{ - if(!ctx->system_control) - return; - - char dump[128]; - if(len > 0) { - hex_to_string(msg, len, dump); - ALOGD_IF(DEBUG, "%s: Message from driver: %s", __FUNCTION__, dump); - } - - hdmi_event_t event; - event.type = HDMI_EVENT_CEC_MESSAGE; - event.dev = (hdmi_cec_device *) ctx; - // Remove initiator/destination from this calculation - event.cec.length = msg[CEC_OFFSET_FRAME_LENGTH] - 1; - event.cec.initiator = (cec_logical_address_t) msg[CEC_OFFSET_SENDER_ID]; - event.cec.destination = (cec_logical_address_t) msg[CEC_OFFSET_RECEIVER_ID]; - //Copy opcode and operand - size_t copy_size = event.cec.length > sizeof(event.cec.body) ? - sizeof(event.cec.body) : event.cec.length; - memcpy(event.cec.body, &msg[CEC_OFFSET_OPCODE],copy_size); - hex_to_string((char *) event.cec.body, copy_size, dump); - ALOGD_IF(DEBUG, "%s: Message to framework: %s", __FUNCTION__, dump); - ctx->callback.callback_func(&event, ctx->callback.callback_arg); -} - -void cec_hdmi_hotplug(cec_context_t *ctx, int connected) -{ - //Ignore unplug events when system control is disabled - if(!ctx->system_control && connected == 0) - return; - hdmi_event_t event; - event.type = HDMI_EVENT_HOT_PLUG; - event.dev = (hdmi_cec_device *) ctx; - event.hotplug.connected = connected ? HDMI_CONNECTED : HDMI_NOT_CONNECTED; - ctx->callback.callback_func(&event, ctx->callback.callback_arg); -} - -static void cec_register_event_callback(const struct hdmi_cec_device* dev, - event_callback_t callback, void* arg) -{ - ALOGD_IF(DEBUG, "%s: Registering callback", __FUNCTION__); - cec_context_t* ctx = (cec_context_t*)(dev); - ctx->callback.callback_func = callback; - ctx->callback.callback_arg = arg; -} - -static void cec_get_version(const struct hdmi_cec_device* dev, int* version) -{ - cec_context_t* ctx = (cec_context_t*)(dev); - *version = ctx->version; - ALOGD_IF(DEBUG, "%s: version: %d", __FUNCTION__, *version); -} - -static void cec_get_vendor_id(const struct hdmi_cec_device* dev, - uint32_t* vendor_id) -{ - cec_context_t* ctx = (cec_context_t*)(dev); - *vendor_id = ctx->vendor_id; - ALOGD_IF(DEBUG, "%s: vendor id: %u", __FUNCTION__, *vendor_id); -} - -static void cec_get_port_info(const struct hdmi_cec_device* dev, - struct hdmi_port_info* list[], int* total) -{ - ALOGD_IF(DEBUG, "%s: Get port info", __FUNCTION__); - cec_context_t* ctx = (cec_context_t*)(dev); - *total = NUM_HDMI_PORTS; - *list = ctx->port_info; -} - -static void cec_set_option(const struct hdmi_cec_device* dev, int flag, - int value) -{ - cec_context_t* ctx = (cec_context_t*)(dev); - switch (flag) { - case HDMI_OPTION_WAKEUP: - ALOGD_IF(DEBUG, "%s: Wakeup: value: %d", __FUNCTION__, value); - //XXX - break; - case HDMI_OPTION_ENABLE_CEC: - ALOGD_IF(DEBUG, "%s: Enable CEC: value: %d", __FUNCTION__, value); - cec_enable(ctx, value? 1 : 0); - break; - case HDMI_OPTION_SYSTEM_CEC_CONTROL: - ALOGD_IF(DEBUG, "%s: system_control: value: %d", - __FUNCTION__, value); - ctx->system_control = !!value; - break; - } -} - -static void cec_set_audio_return_channel(const struct hdmi_cec_device* dev, - int port, int flag) -{ - cec_context_t* ctx = (cec_context_t*)(dev); - ctx->arc_enabled = flag ? true : false; - ALOGD_IF(DEBUG, "%s: ARC flag: %d port: %d", __FUNCTION__, flag, port); -} - -static int cec_is_connected(const struct hdmi_cec_device* dev, int port_id) -{ - // Ignore port_id since we have only one port - int connected = 0; - cec_context_t* ctx = (cec_context_t*)(dev); - char connected_path[MAX_PATH_LENGTH]; - char connected_data[MAX_SYSFS_DATA]; - snprintf (connected_path, sizeof(connected_path),"%s/connected", - ctx->fb_sysfs_path); - ssize_t err = read_node(connected_path, connected_data); - connected = atoi(connected_data); - - ALOGD_IF(DEBUG, "%s: HDMI at port %d is - %s", __FUNCTION__, port_id, - connected ? "connected":"disconnected"); - if (err < 0) - return (int) err; - else - return connected; -} - -static int cec_device_close(struct hw_device_t *dev) -{ - ALOGD_IF(DEBUG, "%s: Close CEC HAL ", __FUNCTION__); - if (!dev) { - ALOGE("%s: NULL device pointer", __FUNCTION__); - return -EINVAL; - } - cec_context_t* ctx = (cec_context_t*)(dev); - cec_close_context(ctx); - free(dev); - return 0; -} - -static int cec_enable(cec_context_t *ctx, int enable) -{ - ssize_t err; - // Enable CEC - int value = enable ? 0x3 : 0x0; - err = write_int_to_node(ctx, "cec/enable", value); - if(err < 0) { - ALOGE("%s: Failed to toggle CEC: enable: %d", - __FUNCTION__, enable); - return (int) err; - } - ctx->enabled = enable; - return 0; -} - -static void cec_init_context(cec_context_t *ctx) -{ - ALOGD_IF(DEBUG, "%s: Initializing context", __FUNCTION__); - cec_get_fb_node_number(ctx); - - //Initialize ports - We support only one output port - ctx->port_info = new hdmi_port_info[NUM_HDMI_PORTS]; - ctx->port_info[0].type = HDMI_OUTPUT; - ctx->port_info[0].port_id = 1; - ctx->port_info[0].cec_supported = 1; - //XXX: Enable ARC if supported - ctx->port_info[0].arc_supported = 0; - cec_get_physical_address((hdmi_cec_device *) ctx, - &ctx->port_info[0].physical_address ); - - ctx->version = 0x4; - ctx->vendor_id = 0xA47733; - cec_clear_logical_address((hdmi_cec_device_t*)ctx); - - //Set up listener for HDMI events - ctx->disp_client = new qClient::QHDMIClient(); - ctx->disp_client->setCECContext(ctx); - ctx->disp_client->registerClient(ctx->disp_client); - - //Enable CEC - framework expects it to be enabled by default - cec_enable(ctx, true); - - ALOGD("%s: CEC enabled", __FUNCTION__); -} - -static void cec_close_context(cec_context_t* ctx __unused) -{ - ALOGD("%s: Closing context", __FUNCTION__); -} - -static int cec_device_open(const struct hw_module_t* module, - const char* name, - struct hw_device_t** device) -{ - ALOGD_IF(DEBUG, "%s: name: %s", __FUNCTION__, name); - int status = -EINVAL; - if (!strcmp(name, HDMI_CEC_HARDWARE_INTERFACE )) { - struct cec_context_t *dev; - dev = (cec_context_t *) calloc (1, sizeof(*dev)); - if (dev) { - cec_init_context(dev); - - //Setup CEC methods - dev->device.common.tag = HARDWARE_DEVICE_TAG; - dev->device.common.version = HDMI_CEC_DEVICE_API_VERSION_1_0; - dev->device.common.module = const_cast(module); - dev->device.common.close = cec_device_close; - dev->device.add_logical_address = cec_add_logical_address; - dev->device.clear_logical_address = cec_clear_logical_address; - dev->device.get_physical_address = cec_get_physical_address; - dev->device.send_message = cec_send_message; - dev->device.register_event_callback = cec_register_event_callback; - dev->device.get_version = cec_get_version; - dev->device.get_vendor_id = cec_get_vendor_id; - dev->device.get_port_info = cec_get_port_info; - dev->device.set_option = cec_set_option; - dev->device.set_audio_return_channel = cec_set_audio_return_channel; - dev->device.is_connected = cec_is_connected; - - *device = &dev->device.common; - status = 0; - } else { - status = -EINVAL; - } - } - return status; -} -}; //namespace qhdmicec - -// Standard HAL module, should be outside qhdmicec namespace -static struct hw_module_methods_t cec_module_methods = { - .open = qhdmicec::cec_device_open -}; - -hdmi_module_t HAL_MODULE_INFO_SYM = { - .common = { - .tag = HARDWARE_MODULE_TAG, - .version_major = 1, - .version_minor = 0, - .id = HDMI_CEC_HARDWARE_MODULE_ID, - .name = "QTI HDMI CEC module", - .author = "The Linux Foundation", - .methods = &cec_module_methods, - } -}; - - diff --git a/hdmi_cec/qhdmi_cec.h b/hdmi_cec/qhdmi_cec.h deleted file mode 100644 index aa97620a..00000000 --- a/hdmi_cec/qhdmi_cec.h +++ /dev/null @@ -1,74 +0,0 @@ -/* -* Copyright (c) 2014 The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation. nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ -#ifndef QHDMI_CEC_H -#define QHDMI_CEC_H - -#include -#include - -namespace qClient { - class QHDMIClient; -}; - -namespace qhdmicec { - -#define SYSFS_BASE "/sys/class/graphics/fb" -#define MAX_PATH_LENGTH 128 - -struct cec_callback_t { - // Function in HDMI service to call back on CEC messages - event_callback_t callback_func; - // This stores the object to pass back to the framework - void* callback_arg; - -}; - -struct cec_context_t { - hdmi_cec_device_t device; // Device for HW module - cec_callback_t callback; // Struct storing callback object - bool enabled; - bool arc_enabled; - bool system_control; // If true, HAL/driver handle CEC messages - int fb_num; // Framebuffer node for HDMI - char fb_sysfs_path[MAX_PATH_LENGTH]; - hdmi_port_info *port_info; // HDMI port info - - // Logical address is stored in an array, the index of the array is the - // logical address and the value in the index shows whether it is set or not - int logical_address[CEC_ADDR_BROADCAST]; - int version; - uint32_t vendor_id; - android::sp disp_client; -}; - -void cec_receive_message(cec_context_t *ctx, char *msg, ssize_t len); -void cec_hdmi_hotplug(cec_context_t *ctx, int connected); - -}; //namespace -#endif /* end of include guard: QHDMI_CEC_H */ diff --git a/include/Android.mk b/include/Android.mk deleted file mode 100644 index 58653c16..00000000 --- a/include/Android.mk +++ /dev/null @@ -1,21 +0,0 @@ -LOCAL_PATH:= $(call my-dir) -include $(LOCAL_PATH)/../common.mk -include $(CLEAR_VARS) - -# Legacy header copy. This is deprecated. -# Modules using these headers should shift to using -# LOCAL_HEADER_LIBRARIES := display_headers -LOCAL_VENDOR_MODULE := true -LOCAL_COPY_HEADERS_TO := $(common_header_export_path) -LOCAL_COPY_HEADERS := color_metadata.h \ - display_properties.h \ - ../libqdutils/qd_utils.h \ - ../libqdutils/qdMetaData.h \ - ../libqdutils/display_config.h \ - ../libdebug/debug_handler.h \ - ../libqservice/QServiceUtils.h \ - ../libqservice/IQService.h \ - ../libqservice/IQHDMIClient.h \ - ../libqservice/IQClient.h - -include $(BUILD_COPY_HEADERS) diff --git a/include/color_metadata.h b/include/color_metadata.h index 3ddf7577..25dc5b52 100644 --- a/include/color_metadata.h +++ b/include/color_metadata.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. +* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted * provided that the following conditions are met: @@ -33,8 +33,9 @@ extern "C" { #include typedef enum ColorRange { - Range_Limited = 0, - Range_Full = 1, + Range_Limited = 0, + Range_Full = 1, + Range_Extended = 2, Range_Max = 0xff, } ColorRange; diff --git a/include/display_properties.h b/include/display_properties.h deleted file mode 100644 index df29eb02..00000000 --- a/include/display_properties.h +++ /dev/null @@ -1,100 +0,0 @@ -/* -* Copyright (c) 2018, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __DISPLAY_PROPERTIES_H__ -#define __DISPLAY_PROPERTIES_H__ - -#define DISP_PROP_PREFIX "vendor.display." -#define GRALLOC_PROP_PREFIX "vendor.gralloc." -#define RO_DISP_PROP_PREFIX "ro.vendor.display." -#define PERSIST_DISP_PROP_PREFIX "persist.vendor.display." - -#define DISPLAY_PROP(prop_name) DISP_PROP_PREFIX prop_name -#define GRALLOC_PROP(prop_name) GRALLOC_PROP_PREFIX prop_name -#define RO_DISPLAY_PROP(prop_name) RO_DISP_PROP_PREFIX prop_name -#define PERSIST_DISPLAY_PROP(prop_name) PERSIST_DISP_PROP_PREFIX prop_name - -#define COMPOSITION_MASK_PROP DISPLAY_PROP("comp_mask") -#define HDMI_CONFIG_INDEX_PROP DISPLAY_PROP("hdmi_cfg_idx") -#define IDLE_TIME_PROP DISPLAY_PROP("idle_time") -#define IDLE_TIME_INACTIVE_PROP DISPLAY_PROP("idle_time_inactive") -#define BOOT_ANIMATION_LAYER_COUNT_PROP DISPLAY_PROP("boot_anim_layer_count") -#define DISABLE_ROTATOR_DOWNSCALE_PROP DISPLAY_PROP("disable_rotator_downscale") -#define DISABLE_DECIMATION_PROP DISPLAY_PROP("disable_decimation") -#define PRIMARY_MIXER_STAGES_PROP DISPLAY_PROP("primary_mixer_stages") -#define EXTERNAL_MIXER_STAGES_PROP DISPLAY_PROP("external_mixer_stages") -#define VIRTUAL_MIXER_STAGES_PROP DISPLAY_PROP("virtual_mixer_stages") -#define MAX_UPSCALE_PROP DISPLAY_PROP("max_upscale") -#define VIDEO_MODE_PANEL_PROP DISPLAY_PROP("video_mode_panel") -#define DISABLE_ROTATOR_UBWC_PROP DISPLAY_PROP("disable_rotator_ubwc") -#define DISABLE_ROTATOR_SPLIT_PROP DISPLAY_PROP("disable_rotator_split") -#define DISABLE_SCALER_PROP DISPLAY_PROP("disable_scaler") -#define DISABLE_AVR_PROP DISPLAY_PROP("disable_avr") -#define DISABLE_EXTERNAL_ANIMATION_PROP DISPLAY_PROP("disable_ext_anim") -#define DISABLE_PARTIAL_SPLIT_PROP DISPLAY_PROP("disable_partial_split") -#define PREFER_SOURCE_SPLIT_PROP DISPLAY_PROP("prefer_source_split") -#define MIXER_RESOLUTION_PROP DISPLAY_PROP("mixer_resolution") -#define SIMULATED_CONFIG_PROP DISPLAY_PROP("simulated_config") -#define MAX_EXTERNAL_LAYERS_PROP DISPLAY_PROP("max_external_layers") -#define PERF_HINT_WINDOW_PROP DISPLAY_PROP("perf_hint_window") -#define ENABLE_EXTERNAL_DOWNSCALE_PROP DISPLAY_PROP("enable_external_downscale") -#define EXTERNAL_ACTION_SAFE_WIDTH_PROP DISPLAY_PROP("external_action_safe_width") -#define EXTERNAL_ACTION_SAFE_HEIGHT_PROP DISPLAY_PROP("external_action_safe_height") -#define FB_WIDTH_PROP DISPLAY_PROP("fb_width") -#define FB_HEIGHT_PROP DISPLAY_PROP("fb_height") -#define DISABLE_METADATA_DYNAMIC_FPS_PROP DISPLAY_PROP("disable_metadata_dynamic_fps") -#define DISABLE_BLIT_COMPOSITION_PROP DISPLAY_PROP("disable_blit_comp") -#define DISABLE_SKIP_VALIDATE_PROP DISPLAY_PROP("disable_skip_validate") -#define HDMI_S3D_MODE_PROP DISPLAY_PROP("hdmi_s3d_mode") -#define DISABLE_DESTINATION_SCALER_PROP DISPLAY_PROP("disable_dest_scaler") -#define ENABLE_PARTIAL_UPDATE_PROP DISPLAY_PROP("enable_partial_update") -#define DISABLE_UBWC_PROP GRALLOC_PROP("disable_ubwc") -#define ENABLE_FB_UBWC_PROP GRALLOC_PROP("enable_fb_ubwc") -#define MAP_FB_MEMORY_PROP GRALLOC_PROP("map_fb_memory") - -#define MAX_BLIT_FACTOR_PROP DISPLAY_PROP("max_blit_factor") -#define DISABLE_SECURE_INLINE_ROTATOR_PROP DISPLAY_PROP("disable_secure_inline_rotator") -#define DISABLE_MULTIRECT_PROP DISPLAY_PROP("disable_multirect") -#define DISABLE_UBWC_FF_VOTING_PROP DISPLAY_PROP("disable_ubwc_ff_voting") -#define DISABLE_INLINE_ROTATOR_PROP DISPLAY_PROP("disable_inline_rotator") -#define DISABLE_FB_CROPPING_PROP DISPLAY_PROP("disable_fb_cropping") -#define PRIORITIZE_CACHE_COMPOSITION_PROP DISPLAY_PROP("prioritize_cache_comp") - -#define DISABLE_HDR_LUT_GEN DISPLAY_PROP("disable_hdr_lut_gen") -#define ENABLE_DEFAULT_COLOR_MODE DISPLAY_PROP("enable_default_color_mode") -#define DISABLE_HDR DISPLAY_PROP("hwc_disable_hdr") - -#define HDR_CONFIG_PROP RO_DISPLAY_PROP("hdr.config") -#define QDCM_PCC_TRANS_PROP DISPLAY_PROP("qdcm.pcc_for_trans") -#define QDCM_DIAGONAL_MATRIXMODE_PROP DISPLAY_PROP("qdcm.diagonal_matrix_mode") -#define QDCM_DISABLE_TIMEOUT_PROP PERSIST_DISPLAY_PROP("qdcm.disable_timeout") - -#define ZERO_SWAP_INTERVAL "vendor.debug.egl.swapinterval" - -#endif // __DISPLAY_PROPERTIES_H__ diff --git a/libcopybit/Android.mk b/libcopybit/Android.mk deleted file mode 100644 index 8396d510..00000000 --- a/libcopybit/Android.mk +++ /dev/null @@ -1,23 +0,0 @@ -# Copyright (C) 2008 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. - -LOCAL_PATH:= $(call my-dir) -include $(LOCAL_PATH)/../common.mk -include $(CLEAR_VARS) - -LOCAL_VENDOR_MODULE := true -LOCAL_COPY_HEADERS_TO := $(common_header_export_path) -LOCAL_COPY_HEADERS := copybit.h copybit_priv.h c2d2.h -#Copy the headers regardless of whether copybit is built -include $(BUILD_COPY_HEADERS) diff --git a/libcopybit/MODULE_LICENSE_APACHE2 b/libcopybit/MODULE_LICENSE_APACHE2 deleted file mode 100644 index e69de29b..00000000 diff --git a/libcopybit/NOTICE b/libcopybit/NOTICE deleted file mode 100644 index 9c1e63ab..00000000 --- a/libcopybit/NOTICE +++ /dev/null @@ -1,189 +0,0 @@ - - Copyright (c) 2008, 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. - - 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. - - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS diff --git a/libcopybit/c2d2.h b/libcopybit/c2d2.h deleted file mode 100644 index 315a3ba5..00000000 --- a/libcopybit/c2d2.h +++ /dev/null @@ -1,685 +0,0 @@ -/* Copyright (c) 2010-2013, The Linux Foundation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of The Linux Foundation. nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ -#ifndef __c2d2_h_ -#define __c2d2_h_ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef C2D_API -#define C2D_API /* define API export as needed */ -#endif -#if !defined(int32) && !defined(_INT32_DEFINED) -typedef int int32; -#define _INT32_DEFINED -#endif -#if !defined(uint32) && !defined(_UINT32_DEFINED) -typedef unsigned int uint32; -#define _UINT32_DEFINED -#endif - -/*****************************************************************************/ -/*********************** Blit definitions *****************************/ -/*****************************************************************************/ - -/* Status codes, returned by any blit function */ -typedef enum { - C2D_STATUS_OK = 0, - C2D_STATUS_NOT_SUPPORTED = 1, - C2D_STATUS_OUT_OF_MEMORY = 2, - C2D_STATUS_INVALID_PARAM = 3, - C2D_STATUS_SURFACE_IN_USE = 4, -} C2D_STATUS; - - -/* Definitions of color format modes, used together with color formats */ -typedef enum { - C2D_FORMAT_PACK_INTO_32BIT = (1 << 8), /* pack into dword if set */ - C2D_FORMAT_SWAP_ENDIANNESS = (1 << 9), /* swaps the order */ - C2D_FORMAT_LINEAR_SPACE = (1 << 10), /* linear color space */ - C2D_FORMAT_PREMULTIPLIED = (1 << 11), /* alpha premultiplied */ - C2D_FORMAT_INVERT_ALPHA = (1 << 12), /* inverts alpha */ - C2D_FORMAT_DISABLE_ALPHA = (1 << 13), /* disables alpha */ - C2D_FORMAT_INTERLACED = (1 << 14), /* YUV line-interlaced */ - C2D_FORMAT_TRANSPARENT = (1 << 15), /* YUV 1-bit alpha in Y */ - C2D_FORMAT_MACROTILED = (1 << 16), /* tiled in macro level */ - C2D_FORMAT_TILED_4x4 = (1 << 17), /* 4x4 tiled format */ - C2D_FORMAT_SWAP_RB = (1 << 18), /* Swap R & B color components */ - C2D_FORMAT_UBWC_COMPRESSED = (1 << 23), /* UBWC compressed format */ -} C2D_FORMAT_MODE; - -/* Definitions of supported RGB formats, used in C2D_RGB_SURFACE_DEF. - * The bits of each color channel are packed into a machine word - * representing a single pixel from left to right (MSB to LSB) in the - * order indicated by format name. For the sub-byte formats the pixels - * are packed into bytes from left to right (MSbit to LSBit). - * If the C2D_FORMAT_PACK_INTO_32BIT bit is set, the minimal - * machine word used for pixel storage is 32-bit and the whole word - * is reversed if endianness is swapped. - * If the C2D_FORMAT_SWAP_ENDIANNESS bit is set, the order within a - * minimal machine word representing a pixel - * is reversed for both sub-byte and multi-byte formats. - * If the C2D_FORMAT_LINEAR_SPACE bit is set, the color space of - * the formats below is considered linear, if applicable. - * If the C2D_FORMAT_PREMULTIPLIED bit is set, the color channels - * are premultiplied with the alpha, if applicable. - * If the C2D_FORMAT_INVERT_ALPHA bit is set, the alpha interpretation - * is inverted: 0 - opaque, 1 - transparent, if applicable. - * If the C2D_FORMAT_DISABLE_ALPHA bit is set, the alpha channel serves - * as a placeholder and is ignored during blit, if applicable. - * If the C2D_FORMAT_MACROTILED bit is set, the surface is in the - * tiled format : 64x32 for 8bpp, 32x32 for 16bpp formats */ -typedef enum { - C2D_COLOR_FORMAT_1 = 0, /* 1-bit alpha/color expansion */ - - C2D_COLOR_FORMAT_2_PALETTE = 1, /* 2-bit indices for palette */ - C2D_COLOR_FORMAT_4_PALETTE = 2, /* 4-bit indices for palette */ - C2D_COLOR_FORMAT_8_PALETTE = 3, /* 8-bit indices for palette */ - - C2D_COLOR_FORMAT_2_L = 4, /* 2-bit grayscale */ - C2D_COLOR_FORMAT_4_L = 5, /* 4-bit grayscale */ - C2D_COLOR_FORMAT_8_L = 6, /* 8-bit grayscale */ - - C2D_COLOR_FORMAT_2_A = 7, /* 2-bit alpha only */ - C2D_COLOR_FORMAT_4_A = 8, /* 4-bit alpha only */ - C2D_COLOR_FORMAT_8_A = 9, /* 8-bit alpha only */ - - C2D_COLOR_FORMAT_444_RGB = 10, /* 12-bit colors */ - C2D_COLOR_FORMAT_565_RGB = 11, /* 16-bit colors */ - C2D_COLOR_FORMAT_888_RGB = 12, /* 24-bit colors */ - - C2D_COLOR_FORMAT_1555_ARGB = 13, /* 16-bit colors (1-bit alpha) */ - C2D_COLOR_FORMAT_4444_ARGB = 14, /* 16-bit colors (4-bit alpha) */ - C2D_COLOR_FORMAT_8565_ARGB = 15, /* 24-bit colors (8-bit alpha) */ - C2D_COLOR_FORMAT_8888_ARGB = 16, /* 32-bit colors (8-bit alpha) */ - - C2D_COLOR_FORMAT_5551_RGBA = 17, /* 16-bit colors (1-bit alpha) */ - C2D_COLOR_FORMAT_4444_RGBA = 18, /* 16-bit colors (4-bit alpha) */ - C2D_COLOR_FORMAT_5658_RGBA = 19, /* 24-bit colors (8-bit alpha) */ - C2D_COLOR_FORMAT_8888_RGBA = 20, /* 32-bit colors (8-bit alpha) */ - - /* derived RGB color formats (base format + mode bits) */ - -} C2D_RGB_FORMAT; - -/* Definitions of supported YUV formats, used in C2D_YUV_SURFACE_DEF. - * Each of Y,U,V channels usually takes 1 byte and therefore is - * individually addressable. The definitions below show how Y,U,V - * channels are packed into macropixels for each particular format. - * The order is from left (smaller byte addresses) to right (larger - * byte addresses). The first three digits (4xx) denote the chroma - * subsampling in standard YUV notation. The digits in the macropixel - * denote that the whole block (from the previous digit or from the - * beginning) has to be repeated the number of times. Underscores - * between Y,U,V channels are used to describe separate planes for - * planar YUV formats. Formats are mapped to numbers so that future - * versions with various YUV permutations are easy to add. - * If the C2D_FORMAT_INTERLACED bit is set, the line order is - * interlaced: 0,2,4,...1,3,5... if applicable. - * If the C2D_FORMAT_TRANSPARENT bit is set, the least significant - * bit of Y channel serves as alpha: 0 - transparent, 1 - opaque. */ -typedef enum { - C2D_COLOR_FORMAT_411_YYUYYV = 110, /* packed, 12-bit */ - C2D_COLOR_FORMAT_411_YUYYVY = 111, /* packed, 12-bit */ - C2D_COLOR_FORMAT_411_UYYVYY = 112, /* packed, 12-bit, "Y411" */ - C2D_COLOR_FORMAT_411_YUYV2Y4 = 116, /* packed, 12-bit */ - C2D_COLOR_FORMAT_411_UYVY2Y4 = 117, /* packed, 12-bit, "Y41P" */ - - C2D_COLOR_FORMAT_422_YUYV = 120, /* packed, 16-bit, "YUY2" */ - C2D_COLOR_FORMAT_422_UYVY = 121, /* packed, 16-bit, "UYVY" */ - C2D_COLOR_FORMAT_422_YVYU = 122, /* packed, 16-bit, "YVYU" */ - C2D_COLOR_FORMAT_422_VYUY = 123, /* packed, 16-bit */ - - C2D_COLOR_FORMAT_444_YUV = 130, /* packed, 24-bit */ - C2D_COLOR_FORMAT_444_UYV = 131, /* packed, 24-bit, "IYU2" */ - C2D_COLOR_FORMAT_444_AYUV = 136, /* packed, 24-bit, "AYUV" */ - - C2D_COLOR_FORMAT_410_Y_UV = 150, /* planar, Y + interleaved UV */ - C2D_COLOR_FORMAT_411_Y_UV = 151, /* planar, Y + interleaved UV */ - C2D_COLOR_FORMAT_420_Y_UV = 152, /* planar, Y + interleaved UV */ - C2D_COLOR_FORMAT_422_Y_UV = 153, /* planar, Y + interleaved UV */ - C2D_COLOR_FORMAT_444_Y_UV = 154, /* planar, Y + interleaved UV */ - - C2D_COLOR_FORMAT_410_Y_VU = 160, /* planar, Y + interleaved VU */ - C2D_COLOR_FORMAT_411_Y_VU = 161, /* planar, Y + interleaved VU */ - C2D_COLOR_FORMAT_420_Y_VU = 162, /* planar, Y + interleaved VU */ - C2D_COLOR_FORMAT_422_Y_VU = 163, /* planar, Y + interleaved VU */ - C2D_COLOR_FORMAT_444_Y_VU = 164, /* planar, Y + interleaved VU */ - - C2D_COLOR_FORMAT_410_Y_U_V = 170, /* planar, Y + U + V separate */ - C2D_COLOR_FORMAT_411_Y_U_V = 171, /* planar, Y + U + V separate */ - C2D_COLOR_FORMAT_420_Y_V_U = 172, /* planar, Y + V + U separate */ - C2D_COLOR_FORMAT_420_Y_U_V = 173, /* planar, Y + U + V separate */ - C2D_COLOR_FORMAT_422_Y_U_V = 174, /* planar, Y + U + V separate */ - C2D_COLOR_FORMAT_444_Y_U_V = 175, /* planar, Y + U + V separate */ - - C2D_COLOR_FORMAT_800_Y = 190, /* planar, Y only, grayscale */ - - /* derived YUV color formats (base format + mode bits), FOURCC */ - - C2D_COLOR_FORMAT_411_Y411 = 112, - C2D_COLOR_FORMAT_411_Y41P = 117, - C2D_COLOR_FORMAT_411_IY41 = 117 | (1 << 14), - C2D_COLOR_FORMAT_411_Y41T = 117 | (1 << 15), - - C2D_COLOR_FORMAT_422_YUY2 = 120, - C2D_COLOR_FORMAT_422_IUYV = 121 | (1 << 14), - C2D_COLOR_FORMAT_422_Y42T = 121 | (1 << 15), - C2D_COLOR_FORMAT_444_IYU2 = 131, - - C2D_COLOR_FORMAT_420_NV12 = 152, - C2D_COLOR_FORMAT_420_NV21 = 162, - - C2D_COLOR_FORMAT_410_YUV9 = 170, - C2D_COLOR_FORMAT_410_YVU9 = 170, - C2D_COLOR_FORMAT_411_Y41B = 171, - C2D_COLOR_FORMAT_420_YV12 = 172, - C2D_COLOR_FORMAT_420_IYUV = 173, - C2D_COLOR_FORMAT_420_I420 = 173, - C2D_COLOR_FORMAT_422_YV16 = 174, - C2D_COLOR_FORMAT_422_Y42B = 174, - - C2D_COLOR_FORMAT_800_Y800 = 190, - -} C2D_YUV_FORMAT; - - -/* Configuration bits, used in the config_mask field of C2D_OBJECT struct */ -typedef enum { - C2D_SOURCE_RECT_BIT = (1 << 0), /* enables source_rect field */ - C2D_MIRROR_H_BIT = (1 << 1), /* enables horizontal flipping */ - C2D_MIRROR_V_BIT = (1 << 2), /* enables vertical flipping */ - C2D_SOURCE_TILE_BIT = (1 << 3), /* enables source surface tiling */ - C2D_TARGET_RECT_BIT = (1 << 4), /* enables target_rect field */ - C2D_ROTATE_BIT = (1 << 5), /* enables all rotation fields */ - C2D_SCISSOR_RECT_BIT = (1 << 6), /* enables scissor_rect field */ - C2D_MASK_SURFACE_BIT = (1 << 7), /* enables mask_surface_id field */ - C2D_MASK_ALIGN_BIT = (1 << 8), /* aligns mask to source_rect */ - C2D_MASK_SCALE_BIT = (1 << 9), /* enables mask surface scaling */ - C2D_MASK_TILE_BIT = (1 << 10), /* enables mask surface tiling */ - C2D_GLOBAL_ALPHA_BIT = (1 << 11), /* enables global_alpha field */ - C2D_COLOR_KEY_BIT = (1 << 12), /* enables color_key field */ - C2D_NO_PIXEL_ALPHA_BIT = (1 << 13), /* disables source alpha channel */ - C2D_NO_BILINEAR_BIT = (1 << 14), /* disables bilinear on scaling */ - C2D_NO_ANTIALIASING_BIT = (1 << 15), /* disables antialiasing on edges */ - C2D_DRAW_LINE_BIT = (1 << 16), /* enables line drawing with source rectangle */ - C2D_DRAW_LINE_NOLAST = (1 << 17), /* disable last pixel draw for line */ -} C2D_SOURCE_CONFIG; - - -/* Target configuration bits, defines rotation + mirroring. - * Mirror is applied prior to rotation if enabled. */ -typedef enum { - C2D_TARGET_MIRROR_H = (1 << 0), /* horizontal flip */ - C2D_TARGET_MIRROR_V = (1 << 1), /* vertical flip */ - C2D_TARGET_ROTATE_0 = (0 << 2), /* no rotation */ - C2D_TARGET_ROTATE_90 = (1 << 2), /* 90 degree rotation */ - C2D_TARGET_ROTATE_180 = (2 << 2), /* 180 degree rotation */ - C2D_TARGET_ROTATE_270 = (3 << 2), /* 270 degree rotation, 90 + 180 */ - C2D_TARGET_MASK_ALIGN = (1 << 4), /* aligns mask to target scissor */ - C2D_TARGET_MASK_SCALE = (1 << 5), /* enables mask scaling */ - C2D_TARGET_MASK_TILE = (1 << 6), /* enables mask tiling */ - C2D_TARGET_COLOR_KEY = (1 << 7), /* enables target_color_key */ - C2D_TARGET_NO_PIXEL_ALPHA = (1 << 8), /* disables target alpha channel */ -} C2D_TARGET_CONFIG; - -#define C2D_TARGET_ROTATION_MASK (C2D_TARGET_ROTATE_90*3) - -/* Additional blend modes, can be used with both source and target configs. - If none of the below is set, the default "SRC over DST" is applied. */ -typedef enum { - C2D_ALPHA_BLEND_SRC_OVER = (0 << 20), /* Default, Porter-Duff "SRC over DST" */ - C2D_ALPHA_BLEND_SRC = (1 << 20), /* Porter-Duff "SRC" */ - C2D_ALPHA_BLEND_SRC_IN = (2 << 20), /* Porter-Duff "SRC in DST" */ - C2D_ALPHA_BLEND_DST_IN = (3 << 20), /* Porter-Duff "DST in SRC" */ - C2D_ALPHA_BLEND_SRC_OUT = (4 << 20), /* Porter-Duff "SRC out DST" */ - C2D_ALPHA_BLEND_DST_OUT = (5 << 20), /* Porter-Duff "DST out SRC" */ - C2D_ALPHA_BLEND_DST_OVER = (6 << 20), /* Porter-Duff "DST over SRC" */ - C2D_ALPHA_BLEND_SRC_ATOP = (7 << 20), /* Porter-Duff "SRC ATOP" */ - C2D_ALPHA_BLEND_DST_ATOP = (8 << 20), /* Porter-Duff "DST ATOP" */ - C2D_ALPHA_BLEND_XOR = (9 << 20), /* Xor */ - C2D_ALPHA_BLEND_MULTIPLY = (10 << 20), /* OpenVG "MULTIPLY" */ - C2D_ALPHA_BLEND_SCREEN = (11 << 20), /* OpenVG "SCREEN" */ - C2D_ALPHA_BLEND_DARKEN = (12 << 20), /* OpenVG "DARKEN" */ - C2D_ALPHA_BLEND_LIGHTEN = (13 << 20), /* OpenVG "LIGHTEN" */ - C2D_ALPHA_BLEND_ADDITIVE = (14 << 20), /* OpenVG "ADDITIVE" */ - C2D_ALPHA_BLEND_DIRECT = (15 << 20), /* Direct alpha blitting */ - C2D_ALPHA_BLEND_INVERTC = (16 << 20), /* Invert color */ - C2D_ALPHA_BLEND_NONE = (1 << 25), /* disables alpha blending */ -} C2D_ALPHA_BLEND_MODE; - -/* Configuration bits, used in the config_mask field of C2D_OBJECT struct */ -typedef enum { - C2D_OVERRIDE_GLOBAL_TARGET_ROTATE_CONFIG = (1 << 27), /* Overrides TARGET Config */ - C2D_OVERRIDE_TARGET_ROTATE_0 = (0 << 28), /* no rotation */ - C2D_OVERRIDE_TARGET_ROTATE_90 = (1 << 28), /* 90 degree rotation */ - C2D_OVERRIDE_TARGET_ROTATE_180 = (2 << 28), /* 180 degree rotation */ - C2D_OVERRIDE_TARGET_ROTATE_270 = (3 << 28), /* 270 degree rotation */ -} C2D_SOURCE_TARGET_CONFIG; - -#define C2D_OVERRIDE_SOURCE_CONFIG_TARGET_ROTATION_SHIFT_MASK 28 -#define C2D_OVERRIDE_TARGET_CONFIG_TARGET_ROTATION_SHIFT_MASK 2 - - -/* Surface caps enumeration */ -typedef enum { - C2D_SOURCE = (1 << 0), /* allows to use as a source */ - C2D_TARGET = (1 << 1), /* allows to use as a target */ - C2D_MASK = (1 << 2), /* allows to use as a mask */ - C2D_PALETTE = (1 << 3), /* allows to use as a palette */ -} C2D_SURFACE_BITS; - -/* Surface type enumeration */ -typedef enum { - C2D_SURFACE_RGB_HOST = 1, /* Host memory RGB surface */ - C2D_SURFACE_RGB_EXT = 2, /* External memory RGB surface */ - C2D_SURFACE_YUV_HOST = 3, /* Host memory YUV surface */ - C2D_SURFACE_YUV_EXT = 4, /* External memory YUV surface */ - C2D_SURFACE_WITH_PHYS = (1<<3), /* physical address already mapped */ - /* this bit is valid with HOST types */ - C2D_SURFACE_WITH_PHYS_DUMMY = (1<<4), /* physical address already mapped */ - /* this bit is valid with HOST types */ -} C2D_SURFACE_TYPE; - -/* Structure for registering a RGB buffer as a blit surface */ -typedef struct { - uint32 format; /* RGB color format plus additional mode bits */ - uint32 width; /* defines width in pixels */ - uint32 height; /* defines height in pixels */ - void *buffer; /* pointer to the RGB buffer */ - void *phys; /* physical address */ - int32 stride; /* defines stride in bytes, negative stride is allowed */ -} C2D_RGB_SURFACE_DEF; - -/* Structure for registering a YUV plane(s) as a blit surface */ -typedef struct { - uint32 format; /* YUV color format plus additional mode bits */ - uint32 width; /* defines width in pixels */ - uint32 height; /* defines height in pixels */ - void *plane0; /* holds the whole buffer if YUV format is not planar */ - void *phys0; /* physical address */ - int32 stride0; /* stride in bytes if YUV format is not planar */ - void *plane1; /* holds UV or VU plane for planar interleaved */ - void *phys1; /* physical address */ - int32 stride1; /* stride for UV or VU plane for planar interleaved */ - void *plane2; /* holds the 3. plane, ignored if YUV format is not planar */ - void *phys2; /* physical address */ - int32 stride2; /* stride for the 3. plane, ignored if YUV format is not planar */ -} C2D_YUV_SURFACE_DEF; - - -/* Rectangle definition */ -typedef struct { - int32 x; /* upper-left x */ - int32 y; /* upper-left y */ - int32 width; /* width */ - int32 height; /* height */ -} C2D_RECT; - -/* C2D_OBJECT encapsulates the blit parameters for a source surface. - * The fg_color defines color in target format for bits equal to 1 - * in the source C2D_COLOR_FORMAT_1 format. It also defines rendering - * color for all alpha-only source formats. If the surface_id is 0 - * the fg_color defines a constant fill color used instead of the surface. - * The bg_color defines color in target format for bits equal to 0 - * in the source C2D_COLOR_FORMAT_1 format, otherwise both are ignored. - * The palette_id is used for all palette source formats, otherwise ignored. - - * The source_rect first defines the content of the source surface, - * it is then horizontally/vertically flipped if C2D_MIRROR_*_BIT is set, - * then scaled with bilinear interpolation to exactly fit target_rect - * or repeated across target_rect if C2D_SOURCE_TILE_BIT is set, - * target_rect is then rotated clockwise by an arbitrary angle in degrees - * around the rot_orig_x/y, defined relative to target_rect's top left point, - * and then clipped to scissor_rect defined in target coordinate system. - - * Finally alpha blending is applied before pixels get written into the target. - * Surface's pixel alpha is combined with mask alpha and with global alpha. - * Mask surface follows all transformations applied to the source surface. - * Source color key defines transparent color, applied together with alpha. */ -typedef struct C2D_OBJECT_STR { - uint32 surface_id; /* source surface */ - - uint32 fg_color; /* foreground color */ - uint32 bg_color; /* background color */ - uint32 palette_id; /* one-dimensional horizontal palette surface */ - - uint32 config_mask; /* defines which fields below are enabled */ - - C2D_RECT source_rect; /* region of the source surface, 16.16 fp */ - C2D_RECT target_rect; /* position and scaling in target, 16.16 fp */ - - int32 rot_orig_x; /* rotation origin relative to target_rect's... */ - int32 rot_orig_y; /* ...top left point, both are 16.16 fp */ - int32 rotation; /* clock-wise rotation in degrees, 16.16 fp */ - - C2D_RECT scissor_rect; /* defines the clip rectangle in target surface */ - - uint32 mask_surface_id; /* source alpha-mask surface */ - uint32 global_alpha; /* 0 = fully transparent, 255 = fully opaque */ - uint32 color_key; /* transparent color for the source surface */ - - struct C2D_OBJECT_STR *next; /* pointer to the next object or NULL */ -} C2D_OBJECT; - -/* Configuration bits, driver capabilities used by 2Dapplications */ -typedef enum { - C2D_DRIVER_SUPPORTS_GLOBAL_ALPHA_OP = (1 << 0), - C2D_DRIVER_SUPPORTS_TILE_OP = (1 << 1), - C2D_DRIVER_SUPPORTS_COLOR_KEY_OP = (1 << 2), - C2D_DRIVER_SUPPORTS_NO_PIXEL_ALPHA_OP = (1 << 3), - C2D_DRIVER_SUPPORTS_TARGET_ROTATE_OP = (1 << 4), - C2D_DRIVER_SUPPORTS_ANTI_ALIASING_OP = (1 << 5), /* antialiasing */ - C2D_DRIVER_SUPPORTS_BILINEAR_FILTER_OP = (1 << 6), - C2D_DRIVER_SUPPORTS_LENS_CORRECTION_OP = (1 << 7), - C2D_DRIVER_SUPPORTS_OVERRIDE_TARGET_ROTATE_OP = (1 << 8), - C2D_DRIVER_SUPPORTS_SHADER_BLOB_OP = (1 << 9), - C2D_DRIVER_SUPPORTS_MASK_SURFACE_OP = (1 << 10), /* mask surface */ - C2D_DRIVER_SUPPORTS_MIRROR_H_OP = (1 << 11), /* horizontal flip */ - C2D_DRIVER_SUPPORTS_MIRROR_V_OP = (1 << 12), /* vertical flip */ - C2D_DRIVER_SUPPORTS_SCISSOR_RECT_OP = (1 << 13), - C2D_DRIVER_SUPPORTS_SOURCE_RECT_OP = (1 << 14), - C2D_DRIVER_SUPPORTS_TARGET_RECT_OP = (1 << 15), - C2D_DRIVER_SUPPORTS_ROTATE_OP = (1 << 16), /* all rotations */ - C2D_DRIVER_SUPPORTS_FLUSH_WITH_FENCE_FD_OP = (1 << 17), /* all rotations */ - C2D_DRIVER_SUPPORTS_UBWC_COMPRESSED_OP = (1 << 18), /* UBWC Compression */ - C2D_DRIVER_SUPPORTS_ALL_CAPABILITIES_OP = ((0xFFFFFFFF) >> (31 - 18)) /* mask for all capabilities supported */ -} C2D_DRIVER_CAPABILITIES; - -/* 2D driver workaround bits used by the 2D applications */ -typedef enum { - C2D_DRIVER_WORKAROUND_NONE = 0, /* NO workaround */ - C2D_DRIVER_WORKAROUND_SWAP_UV_FOR_YUV_TARGET = (1 << 0), /* Swap UV when this flag set */ -} C2D_DRIVER_WORKAROUND; - -/* Structure to query Driver information */ -typedef struct { - uint32 capabilities_mask; - uint32 workaround_mask; - uint32 reserved1; - uint32 reserved2; - uint32 reserved3; -} C2D_DRIVER_INFO; - -/* Structure to query Driver information */ -typedef struct { - uint32 max_surface_template_needed; - uint32 reserved1; - uint32 reserved2; - uint32 reserved3; -} C2D_DRIVER_SETUP_INFO; - -/*****************************************************************************/ -/**************************** C2D API 2.0 ********************************/ -/*****************************************************************************/ - -/****************************************************************************** - * Functions to create/destroy surfaces */ - -/* Creates a generic blit surface according to its type. - * Pass a combination of desired surface bits according to planned usage. - * Accepted values for surface_bits may include bits from C2D_SURFACE_BITS, - * and also from C2D_DISPLAY for compatibility with HW display controller. - * For host memory types the memory is preallocated outside the API - * and should remain valid until surface is destroyed. - * For external memory types the memory is allocated within API. - * On success, the non-zero surface identifier is returned. - * All numbers greater that 0 are valid surface identifiers, 0 is invalid. - - * Host memory RGB surface: - * surface_type = C2D_SURFACE_RGB_HOST - * surface_definition = C2D_RGB_SURFACE_DEF - * all fields in definition structure should be set - - * External memory RGB surface: - * surface_type = C2D_SURFACE_RGB_EXT - * surface_definition = C2D_RGB_SURFACE_DEF - * buffer field in definition structure is ignored - - * Host memory YUV surface: - * surface_type = C2D_SURFACE_YUV_HOST - * surface_definition = C2D_YUV_SURFACE_DEF - * one or all plane and stride fields in definition structure - * should be set depending on whether the format is planar or not - - * External memory YUV surface: - * surface_type = C2D_SURFACE_YUV_EXT - * surface_definition = C2D_YUV_SURFACE_DEF - * all plane and stride fields in definition structure are ignored */ -C2D_API C2D_STATUS c2dCreateSurface( uint32 *surface_id, - uint32 surface_bits, - C2D_SURFACE_TYPE surface_type, - void *surface_definition ); - -/* Requests properties of the specified surface. */ -C2D_API C2D_STATUS c2dQuerySurface( uint32 surface_id, - uint32 *surface_bits, - C2D_SURFACE_TYPE *surface_type, - uint32 *width, uint32 *height, - uint32 *format ); - -/* Destroys a generic blit surface. - * For external memory surfaces also deallocates the memory. - * It is safe to free any external resources associated with a given - * surface on c2dCreateSurface call after this function returns. */ -C2D_API C2D_STATUS c2dDestroySurface( uint32 surface_id ); - - -/****************************************************************************** - * Functions to modify/exchange surface data */ - -/* The format of fill_color is the same as color format being used - * for specified surface. If fill_rect is NULL the whole surface is filled. - * Alpha-blending is not performed while filling. - * The operation is complete when function returns. */ -C2D_API C2D_STATUS c2dFillSurface( uint32 surface_id, - uint32 fill_color, - C2D_RECT *fill_rect ); - -/* Writes data located in host memory into the specified surface. - * The chunk of host memory is identified with surface_type and - * surface_definition, no surface registration needed in this case. - * Only C2D_SURFACE_RGB_HOST, C2D_SURFACE_YUV_HOST are accepted. - * If only part of the host memory buffer should be loaded, it should - * be configured in surface_definition using width, height and stride. - * The x and y are defined in target surface coordinate space. - * Color conversion has to be done, if color formats differ. - * Alpha-blending is not performed while writing. - * The operation is complete when function returns. */ -C2D_API C2D_STATUS c2dWriteSurface( uint32 surface_id, - C2D_SURFACE_TYPE surface_type, - void *surface_definition, - int32 x, int32 y ); - -/* Reads data from the specified surface into the host memory. - * The chunk of host memory is identified with surface_type and - * surface_definition, no surface registration needed in this case. - * Only C2D_SURFACE_RGB_HOST, C2D_SURFACE_YUV_HOST are accepted. - * If only part of the surface should be read, it should - * be configured in surface_definition using width, height and stride. - * The x and y are defined in source surface coordinate space. - * Color conversion has to be done, if color formats differ. - * Alpha-blending is not performed while reading. - * The operation is complete when function returns. */ -C2D_API C2D_STATUS c2dReadSurface( uint32 surface_id, - C2D_SURFACE_TYPE surface_type, - void *surface_definition, - int32 x, int32 y ); - -/* Notifies c2d imlementation that surface has been updated from outside the API, - * if updated_rect is NULL then the whole surface has been updated. */ -C2D_API C2D_STATUS c2dSurfaceUpdated( uint32 surface_id, - C2D_RECT *updated_rect ); - -/* Updates surface information. - * Could be called only for host surfaces set with parameter "C2D_SURFACE_WITH_PHYS". - * Count for surface planes have to be same than for already allocated surface */ -C2D_API C2D_STATUS c2dUpdateSurface( uint32 surface_id, - uint32 surface_bits, - C2D_SURFACE_TYPE surface_type, - void *surface_definition ); - -/****************************************************************************** - * Functions to do actual blit */ - -/* Draw a list of blit objects into the given target. - * The target_config is a bitwise OR of values from C2D_TARGET_CONFIG. - * The target transformation creates the effect that target surface - * is transformed before the blit and then transformed back - * after blit, however no physical target transform is performed. - * The objects_list is a linked list of blit objects, no more - * than num_objects is drawn from the given list. - * If num_objects is 0, the whole list is drawn. - * The blit is not guaranteed to complete after function returns. */ -C2D_API C2D_STATUS c2dDraw( uint32 target_id, - uint32 target_config, C2D_RECT *target_scissor, - uint32 target_mask_id, uint32 target_color_key, - C2D_OBJECT *objects_list, uint32 num_objects ); - - -/* timstamp set in the blit commands flush */ -typedef void* c2d_ts_handle; - -/* Forces any pending blit to complete for a given target. - * Non-blocking. All input surfaces for this target except those - * which are shared with other targets are expected to be immediately - * writable after client has been waiting returned timestamp with - * c2dWaitTimestamp funtion or c2dFinish has been called for same target */ -C2D_API C2D_STATUS c2dFlush( uint32 target_id, c2d_ts_handle *timestamp); - - -/* Waits the pending timestamp */ -C2D_API C2D_STATUS c2dWaitTimestamp( c2d_ts_handle timestamp ); - - -/* Forces any pending blit to complete for a given target. - * Blocking version, returns when blit is done. - * All input surfaces for this target except those which are shared with - * other targets are expected to be immediately - * writable after this function returns. */ -C2D_API C2D_STATUS c2dFinish( uint32 target_id ); - - -/*****************************************************************************/ -/****************************** Display API **********************************/ -/*****************************************************************************/ - - -/* Display input enumeration */ -typedef enum { - C2D_DISPLAY_INPUT_0 = 0, /*!< default input */ - C2D_DISPLAY_INPUT_1 = (1<<16), /*!< Overlay 1 */ - C2D_DISPLAY_INPUT_2 = (1<<17), /*!< Overlay 2... */ -} C2D_DISPLAY_INPUT; - - -/****************************************************************************** - * Functions for display output. */ - -/* Functionality described in this section is optional and is - * provided only for the cases when blit HW - * is tightly bound to the display controller. */ - -/* Display enumeration, may also be used in surface caps */ -typedef enum { - C2D_DISPLAY_MAIN = (1 << 10), /* main display */ - C2D_DISPLAY_SECONDARY = (1 << 11), /* secondary display */ - C2D_DISPLAY_TV_OUT = (1 << 12), /* tv-out */ -} C2D_DISPLAY; - -/* Display window enumeration */ -typedef enum { - C2D_DISPLAY_OVERLAY = C2D_DISPLAY_INPUT_1, /*!< Overlay window bit. This defines display input. - When defined the surface is set on the overlay window - otherwise the surface is set on the background window. */ -} C2D_DISPLAY_WINDOW; /*!< Window bit set with display parameter */ - - -/* Display update modes */ -typedef enum { - C2D_DISPLAY_MODE_TEAR_SYNC = (1 << 0), /* enables tearing sync */ - C2D_DISPLAY_MODE_SURF_REMOVE = (1 << 1), /* Remove surface from given display + input */ -} C2D_DISPLAY_MODE; - - -/* Sets the given surface as a current display front buffer. - * Several displays can be specified as an output if supported. - * Still only one input can be specified at a time fro display/displays. - * The surface remains shown until it gets replaced with another one. */ -C2D_API C2D_STATUS c2dDisplaySetSurface( uint32 display, - uint32 surface_id, uint32 mode ); - -/* Returns the current surface for a particular display. - * Only one display can be specified at a time. - * The latest surface set with compDisplaySetSurface or - * the default pre-allocated surface is returned. */ -C2D_API C2D_STATUS c2dDisplayGetSurface( uint32 display, - uint32 *surface_id ); - -/* Returns the properties for a particular display. - * Only one display can be specified at a time. */ -C2D_API C2D_STATUS c2dDisplayGetProperties( uint32 display, - uint32 *width, uint32 *height, - uint32 *format ); - -/* Sets the properties for a particular display input. - * Only one display + input can be specified at a time. - * C2D_OBJECT used to set input rect(target rect), - * blending operations, rotation...etc for display source */ -C2D_API C2D_STATUS c2dDisplaySetObject( uint32 display, - uint32 target_config, uint32 target_color_key, - C2D_OBJECT * c2dObject, uint32 mode); - -/* allows user to map a memory region to the gpu. only supported on linux - * mem_fd is the fd of the memory region, hostptr is the host pointer to the region, - * len and offset are the size and offset of the memory. - * flags is one of the memory types supported by gsl - * gpaddr is passed by refernce back to the user - */ -C2D_API C2D_STATUS c2dMapAddr ( int mem_fd, void * hostptr, uint32 len, uint32 offset, uint32 flags, void ** gpuaddr); - -/* allows user to unmap memory region mapped by c2dMapAddr. - * gpaddr is the gpuaddr to unmap */ -C2D_API C2D_STATUS c2dUnMapAddr (void * gpuaddr); - -/* allows user to query driver capabilities. - * driver_info is the information about driver */ -C2D_API C2D_STATUS c2dGetDriverCapabilities( C2D_DRIVER_INFO * driver_info); - -/* create a fence fd for the timestamp */ -C2D_API C2D_STATUS c2dCreateFenceFD( uint32 target_id, c2d_ts_handle timestamp, int32 *fd); - -/*****************************************************************************/ - -#ifdef __cplusplus -} -#endif - -#endif /* __c2d2_h_ */ diff --git a/libcopybit/copybit.cpp b/libcopybit/copybit.cpp deleted file mode 100644 index bd49edc2..00000000 --- a/libcopybit/copybit.cpp +++ /dev/null @@ -1,794 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * Copyright (c) 2010 - 2014, The Linux Foundation. All rights reserved. - * - * Not a Contribution, Apache license notifications and license are retained - * for attribution purposes only. - * - * 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 - -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -#include "gralloc_priv.h" -#include "software_converter.h" -#include - -#define DEBUG_MDP_ERRORS 1 - -/******************************************************************************/ - -#define MAX_SCALE_FACTOR (4) -#define MAX_DIMENSION (4096) - -/******************************************************************************/ -struct blitReq{ - struct mdp_buf_sync sync; - uint32_t count; - struct mdp_blit_req req[10]; -}; - -/** State information for each device instance */ -struct copybit_context_t { - struct copybit_device_t device; - int mFD; - uint8_t mAlpha; - int mFlags; - bool mBlitToFB; - int acqFence[MDP_MAX_FENCE_FD]; - int relFence; - struct mdp_buf_sync sync; - struct blitReq list; - uint8_t dynamic_fps; -}; - -/** - * Common hardware methods - */ - -static int open_copybit(const struct hw_module_t* module, const char* name, - struct hw_device_t** device); - -static struct hw_module_methods_t copybit_module_methods = { -open: open_copybit -}; - -/* - * The COPYBIT Module - */ -struct copybit_module_t HAL_MODULE_INFO_SYM = { -common: { -tag: HARDWARE_MODULE_TAG, - version_major: 1, - version_minor: 0, - id: COPYBIT_HARDWARE_MODULE_ID, - name: "QCT MSM7K COPYBIT Module", - author: "Google, Inc.", - methods: ©bit_module_methods - } -}; - -/******************************************************************************/ - -/** min of int a, b */ -static inline int min(int a, int b) { - return (ab) ? a : b; -} - -/** scale each parameter by mul/div. Assume div isn't 0 */ -static inline void MULDIV(uint32_t *a, uint32_t *b, int mul, int div) { - if (mul != div) { - *a = (mul * *a) / div; - *b = (mul * *b) / div; - } -} - -/** Determine the intersection of lhs & rhs store in out */ -static void intersect(struct copybit_rect_t *out, - const struct copybit_rect_t *lhs, - const struct copybit_rect_t *rhs) { - out->l = max(lhs->l, rhs->l); - out->t = max(lhs->t, rhs->t); - out->r = min(lhs->r, rhs->r); - out->b = min(lhs->b, rhs->b); -} - -static bool validateCopybitRect(struct copybit_rect_t *rect) { - return ((rect->b > rect->t) && (rect->r > rect->l)) ; -} - -/** convert COPYBIT_FORMAT to MDP format */ -static int get_format(int format) { - switch (format) { - case HAL_PIXEL_FORMAT_RGB_565: return MDP_RGB_565; - case HAL_PIXEL_FORMAT_RGBA_5551: return MDP_RGBA_5551; - case HAL_PIXEL_FORMAT_RGBA_4444: return MDP_RGBA_4444; - case HAL_PIXEL_FORMAT_RGBX_8888: return MDP_RGBX_8888; - case HAL_PIXEL_FORMAT_BGRX_8888: return MDP_BGRX_8888; - case HAL_PIXEL_FORMAT_RGB_888: return MDP_RGB_888; - case HAL_PIXEL_FORMAT_RGBA_8888: return MDP_RGBA_8888; - case HAL_PIXEL_FORMAT_BGRA_8888: return MDP_BGRA_8888; - case HAL_PIXEL_FORMAT_YCrCb_422_I: return MDP_YCRYCB_H2V1; - case HAL_PIXEL_FORMAT_YCbCr_422_I: return MDP_YCBYCR_H2V1; - case HAL_PIXEL_FORMAT_YCrCb_422_SP: return MDP_Y_CRCB_H2V1; - case HAL_PIXEL_FORMAT_YCrCb_420_SP: return MDP_Y_CRCB_H2V2; - case HAL_PIXEL_FORMAT_YCbCr_422_SP: return MDP_Y_CBCR_H2V1; - case HAL_PIXEL_FORMAT_YCbCr_420_SP: return MDP_Y_CBCR_H2V2; - case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO: return MDP_Y_CBCR_H2V2_ADRENO; - case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS: return MDP_Y_CBCR_H2V2_VENUS; - case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS: return MDP_Y_CRCB_H2V2_VENUS; - case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: return MDP_Y_CBCR_H2V2; - case HAL_PIXEL_FORMAT_CbYCrY_422_I: return MDP_CBYCRY_H2V1; - case HAL_PIXEL_FORMAT_BGR_888: return MDP_BGR_888; - } - return -1; -} - -/** convert from copybit image to mdp image structure */ -static void set_image(struct mdp_img *img, const struct copybit_image_t *rhs) -{ - private_handle_t* hnd = (private_handle_t*)rhs->handle; - if(hnd == NULL){ - ALOGE("copybit: Invalid handle"); - return; - } - img->width = rhs->w; - img->height = rhs->h; - img->format = get_format(rhs->format); - img->offset = (uint32_t)hnd->offset; - img->memory_id = hnd->fd; -} -/** setup rectangles */ -static bool set_rects(struct copybit_context_t *dev, - struct mdp_blit_req *e, - const struct copybit_rect_t *dst, - const struct copybit_rect_t *src, - const struct copybit_rect_t *scissor) { - struct copybit_rect_t clip; - intersect(&clip, scissor, dst); - - if (!validateCopybitRect(&clip)) - return false; - - e->dst_rect.x = clip.l; - e->dst_rect.y = clip.t; - e->dst_rect.w = clip.r - clip.l; - e->dst_rect.h = clip.b - clip.t; - - uint32_t W, H, delta_x, delta_y; - if (dev->mFlags & COPYBIT_TRANSFORM_ROT_90) { - delta_x = (clip.t - dst->t); - delta_y = (dst->r - clip.r); - e->src_rect.w = (clip.b - clip.t); - e->src_rect.h = (clip.r - clip.l); - W = dst->b - dst->t; - H = dst->r - dst->l; - } else { - delta_x = (clip.l - dst->l); - delta_y = (clip.t - dst->t); - e->src_rect.w = (clip.r - clip.l); - e->src_rect.h = (clip.b - clip.t); - W = dst->r - dst->l; - H = dst->b - dst->t; - } - - MULDIV(&delta_x, &e->src_rect.w, src->r - src->l, W); - MULDIV(&delta_y, &e->src_rect.h, src->b - src->t, H); - - e->src_rect.x = delta_x + src->l; - e->src_rect.y = delta_y + src->t; - - if (dev->mFlags & COPYBIT_TRANSFORM_FLIP_V) { - if (dev->mFlags & COPYBIT_TRANSFORM_ROT_90) { - e->src_rect.x = (src->l + src->r) - (e->src_rect.x + e->src_rect.w); - }else{ - e->src_rect.y = (src->t + src->b) - (e->src_rect.y + e->src_rect.h); - } - } - - if (dev->mFlags & COPYBIT_TRANSFORM_FLIP_H) { - if (dev->mFlags & COPYBIT_TRANSFORM_ROT_90) { - e->src_rect.y = (src->t + src->b) - (e->src_rect.y + e->src_rect.h); - }else{ - e->src_rect.x = (src->l + src->r) - (e->src_rect.x + e->src_rect.w); - } - } - return true; -} - -/** setup mdp request */ -static void set_infos(struct copybit_context_t *dev, - struct mdp_blit_req *req, int flags) -{ - req->alpha = dev->mAlpha; - req->fps = dev->dynamic_fps; - req->transp_mask = MDP_TRANSP_NOP; - req->flags = dev->mFlags | flags; - // check if we are blitting to f/b - if (COPYBIT_ENABLE == dev->mBlitToFB) { - req->flags |= MDP_MEMORY_ID_TYPE_FB; - } -#if defined(COPYBIT_QSD8K) - req->flags |= MDP_BLEND_FG_PREMULT; -#endif -} - -/** copy the bits */ -static int msm_copybit(struct copybit_context_t *dev, void const *list) -{ - int err; - if (dev->relFence != -1) { - close(dev->relFence); - dev->relFence = -1; - } - err = ioctl(dev->mFD, MSMFB_ASYNC_BLIT, - (struct mdp_async_blit_req_list const*)list); - ALOGE_IF(err<0, "copyBits failed (%s)", strerror(errno)); - if (err == 0) { - return 0; - } else { -#if DEBUG_MDP_ERRORS - struct mdp_async_blit_req_list const* l = - (struct mdp_async_blit_req_list const*)list; - for (unsigned int i=0 ; icount ; i++) { - ALOGE("%d: src={w=%d, h=%d, f=%d, rect={%d,%d,%d,%d}}\n" - " dst={w=%d, h=%d, f=%d, rect={%d,%d,%d,%d}}\n" - " flags=%08x, fps=%d" - , - i, - l->req[i].src.width, - l->req[i].src.height, - l->req[i].src.format, - l->req[i].src_rect.x, - l->req[i].src_rect.y, - l->req[i].src_rect.w, - l->req[i].src_rect.h, - l->req[i].dst.width, - l->req[i].dst.height, - l->req[i].dst.format, - l->req[i].dst_rect.x, - l->req[i].dst_rect.y, - l->req[i].dst_rect.w, - l->req[i].dst_rect.h, - l->req[i].flags, - l->req[i].fps - ); - } -#endif - return -errno; - } -} - -/*****************************************************************************/ - -/** Set a parameter to value */ -static int set_parameter_copybit( - struct copybit_device_t *dev, - int name, - int value) -{ - struct copybit_context_t* ctx = (struct copybit_context_t*)dev; - int status = 0; - if (ctx) { - switch(name) { - case COPYBIT_ROTATION_DEG: - switch (value) { - case 0: - ctx->mFlags &= ~0x7; - break; - case 90: - ctx->mFlags &= ~0x7; - ctx->mFlags |= MDP_ROT_90; - break; - case 180: - ctx->mFlags &= ~0x7; - ctx->mFlags |= MDP_ROT_180; - break; - case 270: - ctx->mFlags &= ~0x7; - ctx->mFlags |= MDP_ROT_270; - break; - default: - ALOGE("Invalid value for COPYBIT_ROTATION_DEG"); - status = -EINVAL; - break; - } - break; - case COPYBIT_PLANE_ALPHA: - if (value < 0) value = MDP_ALPHA_NOP; - if (value >= 256) value = 255; - ctx->mAlpha = (uint8_t)value; - break; - case COPYBIT_DYNAMIC_FPS: - ctx->dynamic_fps = (uint8_t)value; - break; - case COPYBIT_DITHER: - if (value == COPYBIT_ENABLE) { - ctx->mFlags |= MDP_DITHER; - } else if (value == COPYBIT_DISABLE) { - ctx->mFlags &= ~MDP_DITHER; - } - break; - case COPYBIT_BLUR: - if (value == COPYBIT_ENABLE) { - ctx->mFlags |= MDP_BLUR; - } else if (value == COPYBIT_DISABLE) { - ctx->mFlags &= ~MDP_BLUR; - } - break; - case COPYBIT_BLEND_MODE: - if(value == COPYBIT_BLENDING_PREMULT) { - ctx->mFlags |= MDP_BLEND_FG_PREMULT; - } else { - ctx->mFlags &= ~MDP_BLEND_FG_PREMULT; - } - break; - case COPYBIT_TRANSFORM: - ctx->mFlags &= ~0x7; - ctx->mFlags |= value & 0x7; - break; - case COPYBIT_BLIT_TO_FRAMEBUFFER: - if (COPYBIT_ENABLE == value) { - ctx->mBlitToFB = value; - } else if (COPYBIT_DISABLE == value) { - ctx->mBlitToFB = value; - } else { - ALOGE ("%s:Invalid input for COPYBIT_BLIT_TO_FRAMEBUFFER : %d", - __FUNCTION__, value); - } - break; - case COPYBIT_FG_LAYER: - if(value == COPYBIT_ENABLE) { - ctx->mFlags |= MDP_IS_FG; - } else if (value == COPYBIT_DISABLE) { - ctx->mFlags &= ~MDP_IS_FG; - } - break ; - default: - status = -EINVAL; - break; - } - } else { - status = -EINVAL; - } - return status; -} - -/** Get a static info value */ -static int get(struct copybit_device_t *dev, int name) -{ - struct copybit_context_t* ctx = (struct copybit_context_t*)dev; - int value; - if (ctx) { - switch(name) { - case COPYBIT_MINIFICATION_LIMIT: - value = MAX_SCALE_FACTOR; - break; - case COPYBIT_MAGNIFICATION_LIMIT: - value = MAX_SCALE_FACTOR; - break; - case COPYBIT_SCALING_FRAC_BITS: - value = 32; - break; - case COPYBIT_ROTATION_STEP_DEG: - value = 90; - break; - default: - value = -EINVAL; - } - } else { - value = -EINVAL; - } - return value; -} - -static int set_sync_copybit(struct copybit_device_t *dev, - int acquireFenceFd) -{ - struct copybit_context_t* ctx = (struct copybit_context_t*)dev; - if (acquireFenceFd != -1) { - if (ctx->list.sync.acq_fen_fd_cnt < (MDP_MAX_FENCE_FD - 1)) { - ctx->acqFence[ctx->list.sync.acq_fen_fd_cnt++] = acquireFenceFd; - } else { - int ret = -EINVAL; - struct blitReq *list = &ctx->list; - - // Since fence is full kick off what is already in the list - ret = msm_copybit(ctx, list); - if (ret < 0) { - ALOGE("%s: Blit call failed", __FUNCTION__); - return -EINVAL; - } - list->count = 0; - list->sync.acq_fen_fd_cnt = 0; - ctx->acqFence[list->sync.acq_fen_fd_cnt++] = acquireFenceFd; - } - } - return 0; -} - -/** do a stretch blit type operation */ -static int stretch_copybit( - struct copybit_device_t *dev, - struct copybit_image_t const *dst, - struct copybit_image_t const *src, - struct copybit_rect_t const *dst_rect, - struct copybit_rect_t const *src_rect, - struct copybit_region_t const *region) -{ - struct copybit_context_t* ctx = (struct copybit_context_t*)dev; - struct blitReq *list; - int status = 0; - private_handle_t *yv12_handle = NULL; - - if (ctx) { - list = &ctx->list; - - if (ctx->mAlpha < 255) { - switch (src->format) { - // we don't support plane alpha with RGBA formats - case HAL_PIXEL_FORMAT_RGBA_8888: - case HAL_PIXEL_FORMAT_BGRA_8888: - case HAL_PIXEL_FORMAT_RGBA_5551: - case HAL_PIXEL_FORMAT_RGBA_4444: - ALOGE ("%s : Unsupported Pixel format %d", __FUNCTION__, - src->format); - return -EINVAL; - } - } - - if (src_rect->l < 0 || (uint32_t)src_rect->r > src->w || - src_rect->t < 0 || (uint32_t)src_rect->b > src->h) { - // this is always invalid - ALOGE ("%s : Invalid source rectangle : src_rect l %d t %d r %d b %d",\ - __FUNCTION__, src_rect->l, src_rect->t, src_rect->r, src_rect->b); - - return -EINVAL; - } - - if (src->w > MAX_DIMENSION || src->h > MAX_DIMENSION) { - ALOGE ("%s : Invalid source dimensions w %d h %d", __FUNCTION__, src->w, src->h); - return -EINVAL; - } - - if (dst->w > MAX_DIMENSION || dst->h > MAX_DIMENSION) { - ALOGE ("%s : Invalid DST dimensions w %d h %d", __FUNCTION__, dst->w, dst->h); - return -EINVAL; - } - - if(src->format == HAL_PIXEL_FORMAT_YV12) { - int usage = - GRALLOC_USAGE_PRIVATE_IOMMU_HEAP | GRALLOC_USAGE_PRIVATE_UNCACHED; - if (0 == alloc_buffer(&yv12_handle,src->w,src->h, - src->format, usage)){ - if(0 == convertYV12toYCrCb420SP(src,yv12_handle)){ - (const_cast(src))->format = - HAL_PIXEL_FORMAT_YCrCb_420_SP; - (const_cast(src))->handle = - yv12_handle; - (const_cast(src))->base = - (void *)yv12_handle->base; - } - else{ - ALOGE("Error copybit conversion from yv12 failed"); - if(yv12_handle) - free_buffer(yv12_handle); - return -EINVAL; - } - } - else{ - ALOGE("Error:unable to allocate memeory for yv12 software conversion"); - return -EINVAL; - } - } - const uint32_t maxCount = - (uint32_t)(sizeof(list->req)/sizeof(list->req[0])); - const struct copybit_rect_t bounds = { 0, 0, (int)dst->w, (int)dst->h }; - struct copybit_rect_t clip; - status = 0; - while ((status == 0) && region->next(region, &clip)) { - intersect(&clip, &bounds, &clip); - mdp_blit_req* req = &list->req[list->count]; - int flags = 0; - - private_handle_t* src_hnd = (private_handle_t*)src->handle; - if(src_hnd != NULL && - (!(src_hnd->flags & private_handle_t::PRIV_FLAGS_CACHED))) { - flags |= MDP_BLIT_NON_CACHED; - } - - // Set Color Space for MDP to configure CSC matrix - req->color_space = ITU_R_601; - MetaData_t *metadata = NULL; - - if (src_hnd != NULL) - metadata = (MetaData_t *)src_hnd->base_metadata; - - if (metadata && (metadata->operation & UPDATE_COLOR_SPACE)) { - req->color_space = metadata->colorSpace; - } - - set_infos(ctx, req, flags); - set_image(&req->dst, dst); - set_image(&req->src, src); - if (set_rects(ctx, req, dst_rect, src_rect, &clip) == false) - continue; - - if (req->src_rect.w<=0 || req->src_rect.h<=0) - continue; - - if (req->dst_rect.w<=0 || req->dst_rect.h<=0) - continue; - - if (++list->count == maxCount) { - status = msm_copybit(ctx, list); - list->sync.acq_fen_fd_cnt = 0; - list->count = 0; - } - } - if(yv12_handle) { - //Before freeing the buffer we need buffer passed through blit call - if (list->count != 0) { - status = msm_copybit(ctx, list); - list->sync.acq_fen_fd_cnt = 0; - list->count = 0; - } - free_buffer(yv12_handle); - } - } else { - ALOGE ("%s : Invalid COPYBIT context", __FUNCTION__); - status = -EINVAL; - } - return status; -} - -/** Perform a blit type operation */ -static int blit_copybit( - struct copybit_device_t *dev, - struct copybit_image_t const *dst, - struct copybit_image_t const *src, - struct copybit_region_t const *region) -{ - struct copybit_rect_t dr = { 0, 0, (int)dst->w, (int)dst->h }; - struct copybit_rect_t sr = { 0, 0, (int)src->w, (int)src->h }; - return stretch_copybit(dev, dst, src, &dr, &sr, region); -} - -static int finish_copybit(struct copybit_device_t *dev) -{ - // NOP for MDP copybit - if(!dev) - return -EINVAL; - - return 0; -} -static int clear_copybit(struct copybit_device_t *dev, - struct copybit_image_t const *buf, - struct copybit_rect_t *rect) -{ - struct copybit_context_t* ctx = (struct copybit_context_t*)dev; - uint32_t color = 0; // black color - - if (!ctx) { - ALOGE ("%s: Invalid copybit context", __FUNCTION__); - return -EINVAL; - } - - struct blitReq list1; - memset((char *)&list1 , 0 ,sizeof (struct blitReq) ); - list1.count = 1; - int my_tmp_get_fence = -1; - - list1.sync.acq_fen_fd = ctx->acqFence; - list1.sync.rel_fen_fd = &my_tmp_get_fence; - list1.sync.acq_fen_fd_cnt = ctx->list.sync.acq_fen_fd_cnt; - mdp_blit_req* req = &list1.req[0]; - - if(!req) { - ALOGE ("%s : Invalid request", __FUNCTION__); - return -EINVAL; - } - - set_image(&req->dst, buf); - set_image(&req->src, buf); - - if (rect->l < 0 || (uint32_t)(rect->r - rect->l) > req->dst.width || - rect->t < 0 || (uint32_t)(rect->b - rect->t) > req->dst.height) { - ALOGE ("%s : Invalid rect : src_rect l %d t %d r %d b %d",\ - __FUNCTION__, rect->l, rect->t, rect->r, rect->b); - return -EINVAL; - } - - req->dst_rect.x = rect->l; - req->dst_rect.y = rect->t; - req->dst_rect.w = rect->r - rect->l; - req->dst_rect.h = rect->b - rect->t; - - req->src_rect = req->dst_rect; - - req->const_color.b = (uint32_t)((color >> 16) & 0xff); - req->const_color.g = (uint32_t)((color >> 8) & 0xff); - req->const_color.r = (uint32_t)((color >> 0) & 0xff); - req->const_color.alpha = MDP_ALPHA_NOP; - - req->transp_mask = MDP_TRANSP_NOP; - req->flags = MDP_SOLID_FILL | MDP_MEMORY_ID_TYPE_FB | MDP_BLEND_FG_PREMULT; - int status = msm_copybit(ctx, &list1); - - ctx->list.sync.acq_fen_fd_cnt = 0; - if (my_tmp_get_fence != -1) - close(my_tmp_get_fence); - - return status; -} - -/** Fill the rect on dst with RGBA color **/ -static int fill_color(struct copybit_device_t *dev, - struct copybit_image_t const *dst, - struct copybit_rect_t const *rect, - uint32_t color) -{ - struct copybit_context_t* ctx = (struct copybit_context_t*)dev; - if (!ctx) { - ALOGE("%s: Invalid copybit context", __FUNCTION__); - return -EINVAL; - } - - if (dst->w > MAX_DIMENSION || dst->h > MAX_DIMENSION) { - ALOGE("%s: Invalid DST w=%d h=%d", __FUNCTION__, dst->w, dst->h); - return -EINVAL; - } - - if (rect->l < 0 || (uint32_t)(rect->r - rect->l) > dst->w || - rect->t < 0 || (uint32_t)(rect->b - rect->t) > dst->h) { - ALOGE("%s: Invalid destination rect: l=%d t=%d r=%d b=%d", - __FUNCTION__, rect->l, rect->t, rect->r, rect->b); - return -EINVAL; - } - - int status = 0; - struct blitReq* list = &ctx->list; - mdp_blit_req* req = &list->req[list->count++]; - set_infos(ctx, req, MDP_SOLID_FILL); - set_image(&req->src, dst); - set_image(&req->dst, dst); - - req->dst_rect.x = rect->l; - req->dst_rect.y = rect->t; - req->dst_rect.w = rect->r - rect->l; - req->dst_rect.h = rect->b - rect->t; - req->src_rect = req->dst_rect; - - req->const_color.r = (uint32_t)((color >> 0) & 0xff); - req->const_color.g = (uint32_t)((color >> 8) & 0xff); - req->const_color.b = (uint32_t)((color >> 16) & 0xff); - req->const_color.alpha = (uint32_t)((color >> 24) & 0xff); - - if (list->count == sizeof(list->req)/sizeof(list->req[0])) { - status = msm_copybit(ctx, list); - list->sync.acq_fen_fd_cnt = 0; - list->count = 0; - } - return status; -} - -/*****************************************************************************/ - -/** Close the copybit device */ -static int close_copybit(struct hw_device_t *dev) -{ - struct copybit_context_t* ctx = (struct copybit_context_t*)dev; - if (ctx) { - close(ctx->mFD); - free(ctx); - } - return 0; -} - -static int flush_get_fence(struct copybit_device_t *dev, int* fd) -{ - struct copybit_context_t* ctx = (struct copybit_context_t*)dev; - struct blitReq *list = &ctx->list; - int ret = -EINVAL; - - if (list->count) { - ret = msm_copybit(ctx, list); - if (ret < 0) - ALOGE("%s: Blit call failed", __FUNCTION__); - list->count = 0; - } - *fd = ctx->relFence; - list->sync.acq_fen_fd_cnt = 0; - ctx->relFence = -1; - return ret; -} - -/** Open a new instance of a copybit device using name */ -static int open_copybit(const struct hw_module_t* module, const char* name, - struct hw_device_t** device) -{ - int status = -EINVAL; - - if (strcmp(name, COPYBIT_HARDWARE_COPYBIT0)) { - return COPYBIT_FAILURE; - } - copybit_context_t *ctx; - ctx = (copybit_context_t *)malloc(sizeof(copybit_context_t)); - - if (ctx == NULL ) { - return COPYBIT_FAILURE; - } - - memset(ctx, 0, sizeof(*ctx)); - - ctx->device.common.tag = HARDWARE_DEVICE_TAG; - ctx->device.common.version = 1; - ctx->device.common.module = const_cast(module); - ctx->device.common.close = close_copybit; - ctx->device.set_parameter = set_parameter_copybit; - ctx->device.get = get; - ctx->device.blit = blit_copybit; - ctx->device.set_sync = set_sync_copybit; - ctx->device.stretch = stretch_copybit; - ctx->device.finish = finish_copybit; - ctx->device.fill_color = fill_color; - ctx->device.flush_get_fence = flush_get_fence; - ctx->device.clear = clear_copybit; - ctx->mAlpha = MDP_ALPHA_NOP; - //dynamic_fps is zero means default - //panel refresh rate for driver. - ctx->dynamic_fps = 0; - ctx->mFlags = 0; - ctx->sync.flags = 0; - ctx->relFence = -1; - for (int i=0; i < MDP_MAX_FENCE_FD; i++) { - ctx->acqFence[i] = -1; - } - ctx->sync.acq_fen_fd = ctx->acqFence; - ctx->sync.rel_fen_fd = &ctx->relFence; - ctx->list.count = 0; - ctx->list.sync.acq_fen_fd_cnt = 0; - ctx->list.sync.rel_fen_fd = ctx->sync.rel_fen_fd; - ctx->list.sync.acq_fen_fd = ctx->sync.acq_fen_fd; - ctx->mFD = open("/dev/graphics/fb0", O_RDWR, 0); - if (ctx->mFD < 0) { - status = errno; - ALOGE("Error opening frame buffer errno=%d (%s)", - status, strerror(status)); - status = -status; - } else { - status = 0; - *device = &ctx->device.common; - } - return status; -} diff --git a/libcopybit/copybit.h b/libcopybit/copybit.h deleted file mode 100644 index de585ee3..00000000 --- a/libcopybit/copybit.h +++ /dev/null @@ -1,319 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * Copyright (c) 2012-2015, The Linux Foundation. All rights reserved. - * - * Not a Contribution, Apache license notifications and license are retained - * for attribution purposes only. - * - * 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_COPYBIT_INTERFACE_H -#define ANDROID_COPYBIT_INTERFACE_H - -#include - -#include -#include -#include -#include - -__BEGIN_DECLS - -/** - * The id of this module - */ -#define COPYBIT_HARDWARE_MODULE_ID "copybit" - -/** - * Name of the graphics device to open - */ -#define COPYBIT_HARDWARE_COPYBIT0 "copybit0" - -/* supported pixel-formats. these must be compatible with - * graphics/PixelFormat.java, ui/PixelFormat.h, pixelflinger/format.h - */ -enum { - COPYBIT_FORMAT_RGBA_8888 = HAL_PIXEL_FORMAT_RGBA_8888, - COPYBIT_FORMAT_RGBX_8888 = HAL_PIXEL_FORMAT_RGBX_8888, - COPYBIT_FORMAT_RGB_888 = HAL_PIXEL_FORMAT_RGB_888, - COPYBIT_FORMAT_RGB_565 = HAL_PIXEL_FORMAT_RGB_565, - COPYBIT_FORMAT_BGRA_8888 = HAL_PIXEL_FORMAT_BGRA_8888, - COPYBIT_FORMAT_RGBA_5551 = HAL_PIXEL_FORMAT_RGBA_5551, - COPYBIT_FORMAT_RGBA_4444 = HAL_PIXEL_FORMAT_RGBA_4444, - COPYBIT_FORMAT_YCbCr_422_SP = 0x10, - COPYBIT_FORMAT_YCrCb_420_SP = 0x11, -}; - -/* name for copybit_set_parameter */ -enum { - /* Default blit destination is offline buffer */ - /* clients to set this to '1', if blitting to framebuffer */ - /* and reset to '0', after calling blit/stretch */ - COPYBIT_BLIT_TO_FRAMEBUFFER = 0, - /* rotation of the source image in degrees (0 to 359) */ - COPYBIT_ROTATION_DEG = 1, - /* plane alpha value */ - COPYBIT_PLANE_ALPHA = 2, - /* enable or disable dithering */ - COPYBIT_DITHER = 3, - /* transformation applied (this is a superset of COPYBIT_ROTATION_DEG) */ - COPYBIT_TRANSFORM = 4, - /* blurs the copied bitmap. The amount of blurring cannot be changed - * at this time. */ - COPYBIT_BLUR = 5, - /* Blend mode */ - COPYBIT_BLEND_MODE = 6, - /* FB width */ - COPYBIT_FRAMEBUFFER_WIDTH = 7, - /* FB height */ - COPYBIT_FRAMEBUFFER_HEIGHT = 8, - COPYBIT_FG_LAYER = 9, - COPYBIT_DYNAMIC_FPS = 10, - /* Source Format Mode */ - COPYBIT_SRC_FORMAT_MODE = 11, - /* Destination Format Mode */ - COPYBIT_DST_FORMAT_MODE = 12, -}; - -/* values for copybit_set_parameter(COPYBIT_TRANSFORM) */ -enum { - /* flip source image horizontally */ - COPYBIT_TRANSFORM_FLIP_H = HAL_TRANSFORM_FLIP_H, - /* flip source image vertically */ - COPYBIT_TRANSFORM_FLIP_V = HAL_TRANSFORM_FLIP_V, - /* rotate source image 90 degres */ - COPYBIT_TRANSFORM_ROT_90 = HAL_TRANSFORM_ROT_90, - /* rotate source image 180 degres */ - COPYBIT_TRANSFORM_ROT_180 = HAL_TRANSFORM_ROT_180, - /* rotate source image 270 degres */ - COPYBIT_TRANSFORM_ROT_270 = HAL_TRANSFORM_ROT_270, -}; - -/* enable/disable value copybit_set_parameter */ -enum { - COPYBIT_DISABLE = 0, - COPYBIT_ENABLE = 1 -}; - -/* - * copybit blending values. same as HWC blending values - */ -enum { - /* no blending */ - COPYBIT_BLENDING_NONE = 0x0100, - - /* ONE / ONE_MINUS_SRC_ALPHA */ - COPYBIT_BLENDING_PREMULT = 0x0105, - - /* SRC_ALPHA / ONE_MINUS_SRC_ALPHA */ - COPYBIT_BLENDING_COVERAGE = 0x0405 -}; - -enum { - /* Linear format mode*/ - COPYBIT_LINEAR = 0x0000, - /* UBWC format mode*/ - COPYBIT_UBWC_COMPRESSED = 0x0001, -}; - -/* use get_static_info() to query static informations about the hardware */ -enum { - /* Maximum amount of minification supported by the hardware*/ - COPYBIT_MINIFICATION_LIMIT = 1, - /* Maximum amount of magnification supported by the hardware */ - COPYBIT_MAGNIFICATION_LIMIT = 2, - /* Number of fractional bits support by the scaling engine */ - COPYBIT_SCALING_FRAC_BITS = 3, - /* Supported rotation step in degres. */ - COPYBIT_ROTATION_STEP_DEG = 4, - /* UBWC support*/ - COPYBIT_UBWC_SUPPORT = 5, -}; - -/* Image structure */ -struct copybit_image_t { - /* width */ - uint32_t w; - /* height */ - uint32_t h; - /* format COPYBIT_FORMAT_xxx */ - int32_t format; - /* base of buffer with image */ - void *base; - /* handle to the image */ - native_handle_t* handle; - /* number of pixels added for the stride */ - uint32_t horiz_padding; - /* number of pixels added for the vertical stride */ - uint32_t vert_padding; -}; - -/* Rectangle */ -struct copybit_rect_t { - /* left */ - int l; - /* top */ - int t; - /* right */ - int r; - /* bottom */ - int b; -}; - -/* Region */ -struct copybit_region_t { - int (*next)(struct copybit_region_t const *region, struct copybit_rect_t *rect); -}; - -/** - * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM - * and the fields of this data structure must begin with hw_module_t - * followed by module specific information. - */ -struct copybit_module_t { - struct hw_module_t common; -}; - -/** - * Every device data structure must begin with hw_device_t - * followed by module specific public methods and attributes. - */ -struct copybit_device_t { - struct hw_device_t common; - - /** - * Set a copybit parameter. - * - * @param dev from open - * @param name one for the COPYBIT_NAME_xxx - * @param value one of the COPYBIT_VALUE_xxx - * - * @return 0 if successful - */ - int (*set_parameter)(struct copybit_device_t *dev, int name, int value); - - /** - * Get a static copybit information. - * - * @param dev from open - * @param name one of the COPYBIT_STATIC_xxx - * - * @return value or -EINVAL if error - */ - int (*get)(struct copybit_device_t *dev, int name); - - /** - * Execute the bit blit copy operation - * - * @param dev from open - * @param dst is the destination image - * @param src is the source image - * @param region the clip region - * - * @return 0 if successful - */ - int (*blit)(struct copybit_device_t *dev, - struct copybit_image_t const *dst, - struct copybit_image_t const *src, - struct copybit_region_t const *region); - - /** - * Give acquire fence to copybit to be used in upcoming stretch - * call - * - * @param dev from open - * @param acquireFenceFd is the acquire fence - * - * @return 0 if successful - */ - int (*set_sync)(struct copybit_device_t *dev, - int acquireFenceFd); - - /** - * Execute the stretch bit blit copy operation - * - * @param dev from open - * @param dst is the destination image - * @param src is the source image - * @param dst_rect is the destination rectangle - * @param src_rect is the source rectangle - * @param region the clip region - * - * @return 0 if successful - */ - int (*stretch)(struct copybit_device_t *dev, - struct copybit_image_t const *dst, - struct copybit_image_t const *src, - struct copybit_rect_t const *dst_rect, - struct copybit_rect_t const *src_rect, - struct copybit_region_t const *region); - - /** - * Fill the rect on dst with RGBA color - * - * @param dev from open - * @param dst is destination image - * @param rect is destination rectangle - * @param color is RGBA color to fill - * - * @return 0 if successful - */ - int (*fill_color)(struct copybit_device_t *dev, - struct copybit_image_t const *dst, - struct copybit_rect_t const *rect, - uint32_t color); - - /** - * Execute the completion of the copybit draw operation. - * - * @param dev from open - * - * @return 0 if successful - */ - int (*finish)(struct copybit_device_t *dev); - - /** - * Trigger the copybit draw operation(async). - * - * @param dev from open - * - * @param fd - gets the fencefd - * - * @return 0 if successful - */ - int (*flush_get_fence)(struct copybit_device_t *dev, int* fd); - - /* Clears the buffer - */ - int (*clear)(struct copybit_device_t *dev, struct copybit_image_t const *buf, - struct copybit_rect_t *rect); -}; - - -/** convenience API for opening and closing a device */ - -static inline int copybit_open(const struct hw_module_t* module, - struct copybit_device_t** device) { - return module->methods->open(module, - COPYBIT_HARDWARE_COPYBIT0, (struct hw_device_t**)device); -} - -static inline int copybit_close(struct copybit_device_t* device) { - return device->common.close(&device->common); -} - - -__END_DECLS - -#endif // ANDROID_COPYBIT_INTERFACE_H diff --git a/libcopybit/copybit_c2d.cpp b/libcopybit/copybit_c2d.cpp deleted file mode 100644 index 63c13790..00000000 --- a/libcopybit/copybit_c2d.cpp +++ /dev/null @@ -1,1776 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * Copyright (c) 2010-2015, The Linux Foundation. All rights reserved. - * - * Not a Contribution, Apache license notifications and license are retained - * for attribution purposes only. - * - * 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 -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -#include -#include - -#include -#include -#include - -#include "c2d2.h" -#include "software_converter.h" - -#include - -using gralloc::IMemAlloc; -using gralloc::IonController; -using gralloc::alloc_data; - -C2D_STATUS (*LINK_c2dCreateSurface)( uint32 *surface_id, - uint32 surface_bits, - C2D_SURFACE_TYPE surface_type, - void *surface_definition ); - -C2D_STATUS (*LINK_c2dUpdateSurface)( uint32 surface_id, - uint32 surface_bits, - C2D_SURFACE_TYPE surface_type, - void *surface_definition ); - -C2D_STATUS (*LINK_c2dReadSurface)( uint32 surface_id, - C2D_SURFACE_TYPE surface_type, - void *surface_definition, - int32 x, int32 y ); - -C2D_STATUS (*LINK_c2dDraw)( uint32 target_id, - uint32 target_config, C2D_RECT *target_scissor, - uint32 target_mask_id, uint32 target_color_key, - C2D_OBJECT *objects_list, uint32 num_objects ); - -C2D_STATUS (*LINK_c2dFinish)( uint32 target_id); - -C2D_STATUS (*LINK_c2dFlush)( uint32 target_id, c2d_ts_handle *timestamp); - -C2D_STATUS (*LINK_c2dWaitTimestamp)( c2d_ts_handle timestamp ); - -C2D_STATUS (*LINK_c2dDestroySurface)( uint32 surface_id ); - -C2D_STATUS (*LINK_c2dMapAddr) ( int mem_fd, void * hostptr, size_t len, - size_t offset, uint32 flags, void ** gpuaddr); - -C2D_STATUS (*LINK_c2dUnMapAddr) ( void * gpuaddr); - -C2D_STATUS (*LINK_c2dGetDriverCapabilities) ( C2D_DRIVER_INFO * driver_info); - -/* create a fence fd for the timestamp */ -C2D_STATUS (*LINK_c2dCreateFenceFD) ( uint32 target_id, c2d_ts_handle timestamp, - int32 *fd); - -C2D_STATUS (*LINK_c2dFillSurface) ( uint32 surface_id, uint32 fill_color, - C2D_RECT * fill_rect); - -/******************************************************************************/ - -#if defined(COPYBIT_Z180) -#define MAX_SCALE_FACTOR (4096) -#define MAX_DIMENSION (4096) -#else -#error "Unsupported HW version" -#endif - -// The following defines can be changed as required i.e. as we encounter -// complex use cases. -#define MAX_RGB_SURFACES 32 // Max. RGB layers currently supported per draw -#define MAX_YUV_2_PLANE_SURFACES 4// Max. 2-plane YUV layers currently supported per draw -#define MAX_YUV_3_PLANE_SURFACES 1// Max. 3-plane YUV layers currently supported per draw -// +1 for the destination surface. We cannot have multiple destination surfaces. -#define MAX_SURFACES (MAX_RGB_SURFACES + MAX_YUV_2_PLANE_SURFACES + MAX_YUV_3_PLANE_SURFACES + 1) -#define NUM_SURFACE_TYPES 3 // RGB_SURFACE + YUV_SURFACE_2_PLANES + YUV_SURFACE_3_PLANES -#define MAX_BLIT_OBJECT_COUNT 50 // Max. blit objects that can be passed per draw - -enum { - RGB_SURFACE, - YUV_SURFACE_2_PLANES, - YUV_SURFACE_3_PLANES -}; - -enum eConversionType { - CONVERT_TO_ANDROID_FORMAT, - CONVERT_TO_C2D_FORMAT -}; - -enum eC2DFlags { - FLAGS_PREMULTIPLIED_ALPHA = 1<<0, - FLAGS_YUV_DESTINATION = 1<<1, - FLAGS_TEMP_SRC_DST = 1<<2, - FLAGS_UBWC_FORMAT_MODE = 1<<3 -}; - -static gralloc::IAllocController* sAlloc = 0; -/******************************************************************************/ - -/** State information for each device instance */ -struct copybit_context_t { - struct copybit_device_t device; - // Templates for the various source surfaces. These templates are created - // to avoid the expensive create/destroy C2D Surfaces - C2D_OBJECT_STR blit_rgb_object[MAX_RGB_SURFACES]; - C2D_OBJECT_STR blit_yuv_2_plane_object[MAX_YUV_2_PLANE_SURFACES]; - C2D_OBJECT_STR blit_yuv_3_plane_object[MAX_YUV_3_PLANE_SURFACES]; - C2D_OBJECT_STR blit_list[MAX_BLIT_OBJECT_COUNT]; // Z-ordered list of blit objects - C2D_DRIVER_INFO c2d_driver_info; - void *libc2d2; - alloc_data temp_src_buffer; - alloc_data temp_dst_buffer; - unsigned int dst[NUM_SURFACE_TYPES]; // dst surfaces - uintptr_t mapped_gpu_addr[MAX_SURFACES]; // GPU addresses mapped inside copybit - int blit_rgb_count; // Total RGB surfaces being blit - int blit_yuv_2_plane_count; // Total 2 plane YUV surfaces being - int blit_yuv_3_plane_count; // Total 3 plane YUV surfaces being blit - int blit_count; // Total blit objects. - unsigned int trg_transform; /* target transform */ - int fb_width; - int fb_height; - int src_global_alpha; - int config_mask; - int dst_surface_type; - bool is_premultiplied_alpha; - void* time_stamp; - bool dst_surface_mapped; // Set when dst surface is mapped to GPU addr - void* dst_surface_base; // Stores the dst surface addr - bool is_src_ubwc_format; - bool is_dst_ubwc_format; - - // used for signaling the wait thread - bool wait_timestamp; - pthread_t wait_thread_id; - bool stop_thread; - pthread_mutex_t wait_cleanup_lock; - pthread_cond_t wait_cleanup_cond; - -}; - -struct bufferInfo { - int width; - int height; - int format; -}; - -struct yuvPlaneInfo { - int yStride; //luma stride - int plane1_stride; - int plane2_stride; - size_t plane1_offset; - size_t plane2_offset; -}; - -/** - * Common hardware methods - */ - -static int open_copybit(const struct hw_module_t* module, const char* name, - struct hw_device_t** device); - -static struct hw_module_methods_t copybit_module_methods = { - .open = open_copybit, -}; - -/* - * The COPYBIT Module - */ -struct copybit_module_t HAL_MODULE_INFO_SYM = { - .common = { - .tag = HARDWARE_MODULE_TAG, - .version_major = 1, - .version_minor = 0, - .id = COPYBIT_HARDWARE_MODULE_ID, - .name = "QCT COPYBIT C2D 2.0 Module", - .author = "Qualcomm", - .methods = ©bit_module_methods - } -}; - - -/* thread function which waits on the timeStamp and cleans up the surfaces */ -static void* c2d_wait_loop(void* ptr) { - copybit_context_t* ctx = (copybit_context_t*)(ptr); - char thread_name[64] = "copybitWaitThr"; - prctl(PR_SET_NAME, (unsigned long) &thread_name, 0, 0, 0); - setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY); - - while(ctx->stop_thread == false) { - pthread_mutex_lock(&ctx->wait_cleanup_lock); - while(ctx->wait_timestamp == false && !ctx->stop_thread) { - pthread_cond_wait(&(ctx->wait_cleanup_cond), - &(ctx->wait_cleanup_lock)); - } - if(ctx->wait_timestamp) { - if(LINK_c2dWaitTimestamp(ctx->time_stamp)) { - ALOGE("%s: LINK_c2dWaitTimeStamp ERROR!!", __FUNCTION__); - } - ctx->wait_timestamp = false; - // Unmap any mapped addresses. - for (int i = 0; i < MAX_SURFACES; i++) { - if (ctx->mapped_gpu_addr[i]) { - LINK_c2dUnMapAddr( (void*)ctx->mapped_gpu_addr[i]); - ctx->mapped_gpu_addr[i] = 0; - } - } - // Reset the counts after the draw. - ctx->blit_rgb_count = 0; - ctx->blit_yuv_2_plane_count = 0; - ctx->blit_yuv_3_plane_count = 0; - ctx->blit_count = 0; - ctx->dst_surface_mapped = false; - ctx->dst_surface_base = 0; - } - pthread_mutex_unlock(&ctx->wait_cleanup_lock); - if(ctx->stop_thread) - break; - } - pthread_exit(NULL); - return NULL; -} - - -/* convert COPYBIT_FORMAT to C2D format */ -static int get_format(int format) { - switch (format) { - case HAL_PIXEL_FORMAT_RGB_565: return C2D_COLOR_FORMAT_565_RGB; - case HAL_PIXEL_FORMAT_RGB_888: return C2D_COLOR_FORMAT_888_RGB | - C2D_FORMAT_SWAP_RB; - case HAL_PIXEL_FORMAT_RGBX_8888: return C2D_COLOR_FORMAT_8888_ARGB | - C2D_FORMAT_SWAP_RB | - C2D_FORMAT_DISABLE_ALPHA; - case HAL_PIXEL_FORMAT_RGBA_8888: return C2D_COLOR_FORMAT_8888_ARGB | - C2D_FORMAT_SWAP_RB; - case HAL_PIXEL_FORMAT_BGRA_8888: return C2D_COLOR_FORMAT_8888_ARGB; - case HAL_PIXEL_FORMAT_RGBA_5551: return C2D_COLOR_FORMAT_5551_RGBA; - case HAL_PIXEL_FORMAT_RGBA_4444: return C2D_COLOR_FORMAT_4444_RGBA; - case HAL_PIXEL_FORMAT_YCbCr_420_SP: return C2D_COLOR_FORMAT_420_NV12; - case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:return C2D_COLOR_FORMAT_420_NV12; - case HAL_PIXEL_FORMAT_YCrCb_420_SP: return C2D_COLOR_FORMAT_420_NV21; - case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED: return C2D_COLOR_FORMAT_420_NV12 | - C2D_FORMAT_MACROTILED; - default: ALOGE("%s: invalid format (0x%x", - __FUNCTION__, format); - return -EINVAL; - } - return -EINVAL; -} - -/* Get the C2D formats needed for conversion to YUV */ -static int get_c2d_format_for_yuv_destination(int halFormat) { - switch (halFormat) { - // We do not swap the RB when the target is YUV - case HAL_PIXEL_FORMAT_RGBX_8888: return C2D_COLOR_FORMAT_8888_ARGB | - C2D_FORMAT_DISABLE_ALPHA; - case HAL_PIXEL_FORMAT_RGBA_8888: return C2D_COLOR_FORMAT_8888_ARGB; - // The U and V need to be interchanged when the target is YUV - case HAL_PIXEL_FORMAT_YCbCr_420_SP: return C2D_COLOR_FORMAT_420_NV21; - case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:return C2D_COLOR_FORMAT_420_NV21; - case HAL_PIXEL_FORMAT_YCrCb_420_SP: return C2D_COLOR_FORMAT_420_NV12; - default: return get_format(halFormat); - } - return -EINVAL; -} - -/* ------------------------------------------------------------------- *//*! - * \internal - * \brief Get the bpp for a particular color format - * \param color format - * \return bits per pixel - *//* ------------------------------------------------------------------- */ -int c2diGetBpp(int32 colorformat) -{ - - int c2dBpp = 0; - - switch(colorformat&0xFF) - { - case C2D_COLOR_FORMAT_4444_RGBA: - case C2D_COLOR_FORMAT_4444_ARGB: - case C2D_COLOR_FORMAT_1555_ARGB: - case C2D_COLOR_FORMAT_565_RGB: - case C2D_COLOR_FORMAT_5551_RGBA: - c2dBpp = 16; - break; - case C2D_COLOR_FORMAT_8888_RGBA: - case C2D_COLOR_FORMAT_8888_ARGB: - c2dBpp = 32; - break; - case C2D_COLOR_FORMAT_888_RGB: - c2dBpp = 24; - break; - case C2D_COLOR_FORMAT_8_L: - case C2D_COLOR_FORMAT_8_A: - c2dBpp = 8; - break; - case C2D_COLOR_FORMAT_4_A: - c2dBpp = 4; - break; - case C2D_COLOR_FORMAT_1: - c2dBpp = 1; - break; - default: - ALOGE("%s ERROR", __func__); - break; - } - return c2dBpp; -} - -static size_t c2d_get_gpuaddr(copybit_context_t* ctx, - struct private_handle_t *handle, int &mapped_idx) -{ - uint32 memtype; - size_t *gpuaddr = 0; - C2D_STATUS rc; - int freeindex = 0; - bool mapaddr = false; - - if(!handle) - return 0; - - if (handle->flags & private_handle_t::PRIV_FLAGS_USES_ION) - memtype = KGSL_USER_MEM_TYPE_ION; - else { - ALOGE("Invalid handle flags: 0x%x", handle->flags); - return 0; - } - - // Check for a freeindex in the mapped_gpu_addr list - for (freeindex = 0; freeindex < MAX_SURFACES; freeindex++) { - if (ctx->mapped_gpu_addr[freeindex] == 0) { - // free index is available - // map GPU addr and use this as mapped_idx - mapaddr = true; - break; - } - } - - if(mapaddr) { - rc = LINK_c2dMapAddr(handle->fd, (void*)handle->base, handle->size, - handle->offset, memtype, (void**)&gpuaddr); - - if (rc == C2D_STATUS_OK) { - // We have mapped the GPU address inside copybit. We need to unmap - // this address after the blit. Store this address - ctx->mapped_gpu_addr[freeindex] = (size_t)gpuaddr; - mapped_idx = freeindex; - } - } - return (size_t)gpuaddr; -} - -static void unmap_gpuaddr(copybit_context_t* ctx, int mapped_idx) -{ - if (!ctx || (mapped_idx == -1)) - return; - - if (ctx->mapped_gpu_addr[mapped_idx]) { - LINK_c2dUnMapAddr( (void*)ctx->mapped_gpu_addr[mapped_idx]); - ctx->mapped_gpu_addr[mapped_idx] = 0; - } -} - -static int is_supported_rgb_format(int format) -{ - switch(format) { - case HAL_PIXEL_FORMAT_RGBA_8888: - case HAL_PIXEL_FORMAT_RGBX_8888: - case HAL_PIXEL_FORMAT_RGB_888: - case HAL_PIXEL_FORMAT_RGB_565: - case HAL_PIXEL_FORMAT_BGRA_8888: - case HAL_PIXEL_FORMAT_RGBA_5551: - case HAL_PIXEL_FORMAT_RGBA_4444: { - return COPYBIT_SUCCESS; - } - default: - return COPYBIT_FAILURE; - } -} - -static int get_num_planes(int format) -{ - switch(format) { - case HAL_PIXEL_FORMAT_YCbCr_420_SP: - case HAL_PIXEL_FORMAT_YCrCb_420_SP: - case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: - case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED: { - return 2; - } - case HAL_PIXEL_FORMAT_YV12: { - return 3; - } - default: - return COPYBIT_FAILURE; - } -} - -static int is_supported_yuv_format(int format) -{ - switch(format) { - case HAL_PIXEL_FORMAT_YCbCr_420_SP: - case HAL_PIXEL_FORMAT_YCrCb_420_SP: - case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: - case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED: { - return COPYBIT_SUCCESS; - } - default: - return COPYBIT_FAILURE; - } -} - -static int is_valid_destination_format(int format) -{ - if (format == HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED) { - // C2D does not support NV12Tile as a destination format. - return COPYBIT_FAILURE; - } - return COPYBIT_SUCCESS; -} - -static int calculate_yuv_offset_and_stride(const bufferInfo& info, - yuvPlaneInfo& yuvInfo) -{ - int width = info.width; - int height = info.height; - int format = info.format; - - int aligned_height = 0; - int aligned_width = 0, size = 0; - - switch (format) { - case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED: { - /* NV12 Tile buffers have their luma height aligned to 32bytes and width - * aligned to 128 bytes. The chroma offset starts at an 8K boundary - */ - aligned_height = ALIGN(height, 32); - aligned_width = ALIGN(width, 128); - size = aligned_width * aligned_height; - yuvInfo.plane1_offset = ALIGN(size,8192); - yuvInfo.yStride = aligned_width; - yuvInfo.plane1_stride = aligned_width; - break; - } - case HAL_PIXEL_FORMAT_YCbCr_420_SP: - case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: - case HAL_PIXEL_FORMAT_YCrCb_420_SP: { - aligned_width = ALIGN(width, 32); - yuvInfo.yStride = aligned_width; - yuvInfo.plane1_stride = aligned_width; - if (HAL_PIXEL_FORMAT_NV12_ENCODEABLE == format) { - // The encoder requires a 2K aligned chroma offset - yuvInfo.plane1_offset = ALIGN(aligned_width * height, 2048); - } else - yuvInfo.plane1_offset = aligned_width * height; - - break; - } - default: { - return COPYBIT_FAILURE; - } - } - return COPYBIT_SUCCESS; -} - -/** create C2D surface from copybit image */ -static int set_image(copybit_context_t* ctx, uint32 surfaceId, - const struct copybit_image_t *rhs, - const eC2DFlags flags, int &mapped_idx) -{ - struct private_handle_t* handle = (struct private_handle_t*)rhs->handle; - C2D_SURFACE_TYPE surfaceType; - int status = COPYBIT_SUCCESS; - uint64_t gpuaddr = 0; - int c2d_format; - mapped_idx = -1; - - if (flags & FLAGS_YUV_DESTINATION) { - c2d_format = get_c2d_format_for_yuv_destination(rhs->format); - } else { - c2d_format = get_format(rhs->format); - } - - if(c2d_format == -EINVAL) { - ALOGE("%s: invalid format", __FUNCTION__); - return -EINVAL; - } - - if(handle == NULL) { - ALOGE("%s: invalid handle", __func__); - return -EINVAL; - } - - if (handle->gpuaddr == 0) { - gpuaddr = c2d_get_gpuaddr(ctx, handle, mapped_idx); - if(!gpuaddr) { - ALOGE("%s: c2d_get_gpuaddr failed", __FUNCTION__); - return COPYBIT_FAILURE; - } - } else { - gpuaddr = handle->gpuaddr; - } - - /* create C2D surface */ - if(is_supported_rgb_format(rhs->format) == COPYBIT_SUCCESS) { - /* RGB */ - C2D_RGB_SURFACE_DEF surfaceDef; - - surfaceType = (C2D_SURFACE_TYPE) (C2D_SURFACE_RGB_HOST | C2D_SURFACE_WITH_PHYS); - - surfaceDef.phys = (void*) gpuaddr; - surfaceDef.buffer = (void*) (handle->base); - - surfaceDef.format = c2d_format | - ((flags & FLAGS_PREMULTIPLIED_ALPHA) ? C2D_FORMAT_PREMULTIPLIED : 0); - - surfaceDef.format = surfaceDef.format | - ((flags & FLAGS_UBWC_FORMAT_MODE) ? C2D_FORMAT_UBWC_COMPRESSED : 0); - - surfaceDef.width = rhs->w; - surfaceDef.height = rhs->h; - int aligned_width = ALIGN((int)surfaceDef.width,32); - surfaceDef.stride = (aligned_width * c2diGetBpp(surfaceDef.format))>>3; - - if(LINK_c2dUpdateSurface( surfaceId,C2D_TARGET | C2D_SOURCE, surfaceType, - &surfaceDef)) { - ALOGE("%s: RGB Surface c2dUpdateSurface ERROR", __FUNCTION__); - unmap_gpuaddr(ctx, mapped_idx); - status = COPYBIT_FAILURE; - } - } else if (is_supported_yuv_format(rhs->format) == COPYBIT_SUCCESS) { - C2D_YUV_SURFACE_DEF surfaceDef; - memset(&surfaceDef, 0, sizeof(surfaceDef)); - surfaceType = (C2D_SURFACE_TYPE)(C2D_SURFACE_YUV_HOST | C2D_SURFACE_WITH_PHYS); - surfaceDef.format = c2d_format; - - bufferInfo info; - info.width = rhs->w; - info.height = rhs->h; - info.format = rhs->format; - - yuvPlaneInfo yuvInfo = {0}; - status = calculate_yuv_offset_and_stride(info, yuvInfo); - if(status != COPYBIT_SUCCESS) { - ALOGE("%s: calculate_yuv_offset_and_stride error", __FUNCTION__); - unmap_gpuaddr(ctx, mapped_idx); - } - - surfaceDef.width = rhs->w; - surfaceDef.height = rhs->h; - surfaceDef.plane0 = (void*) (handle->base); - surfaceDef.phys0 = (void*) (gpuaddr); - surfaceDef.stride0 = yuvInfo.yStride; - - surfaceDef.plane1 = (void*) (handle->base + yuvInfo.plane1_offset); - surfaceDef.phys1 = (void*) (gpuaddr + yuvInfo.plane1_offset); - surfaceDef.stride1 = yuvInfo.plane1_stride; - if (3 == get_num_planes(rhs->format)) { - surfaceDef.plane2 = (void*) (handle->base + yuvInfo.plane2_offset); - surfaceDef.phys2 = (void*) (gpuaddr + yuvInfo.plane2_offset); - surfaceDef.stride2 = yuvInfo.plane2_stride; - } - - if(LINK_c2dUpdateSurface( surfaceId,C2D_TARGET | C2D_SOURCE, surfaceType, - &surfaceDef)) { - ALOGE("%s: YUV Surface c2dUpdateSurface ERROR", __FUNCTION__); - unmap_gpuaddr(ctx, mapped_idx); - status = COPYBIT_FAILURE; - } - } else { - ALOGE("%s: invalid format 0x%x", __FUNCTION__, rhs->format); - unmap_gpuaddr(ctx, mapped_idx); - status = COPYBIT_FAILURE; - } - - return status; -} - -/** copy the bits */ -static int msm_copybit(struct copybit_context_t *ctx, unsigned int target) -{ - if (ctx->blit_count == 0) { - return COPYBIT_SUCCESS; - } - - for (int i = 0; i < ctx->blit_count; i++) - { - ctx->blit_list[i].next = &(ctx->blit_list[i+1]); - } - ctx->blit_list[ctx->blit_count-1].next = NULL; - uint32_t target_transform = ctx->trg_transform; - if (ctx->c2d_driver_info.capabilities_mask & - C2D_DRIVER_SUPPORTS_OVERRIDE_TARGET_ROTATE_OP) { - // For A3xx - set 0x0 as the transform is set in the config_mask - target_transform = 0x0; - } - if(LINK_c2dDraw(target, target_transform, 0x0, 0, 0, ctx->blit_list, - ctx->blit_count)) { - ALOGE("%s: LINK_c2dDraw ERROR", __FUNCTION__); - return COPYBIT_FAILURE; - } - return COPYBIT_SUCCESS; -} - - - -static int flush_get_fence_copybit (struct copybit_device_t *dev, int* fd) -{ - struct copybit_context_t* ctx = (struct copybit_context_t*)dev; - int status = COPYBIT_FAILURE; - if (!ctx) - return COPYBIT_FAILURE; - pthread_mutex_lock(&ctx->wait_cleanup_lock); - status = msm_copybit(ctx, ctx->dst[ctx->dst_surface_type]); - - if(LINK_c2dFlush(ctx->dst[ctx->dst_surface_type], &ctx->time_stamp)) { - ALOGE("%s: LINK_c2dFlush ERROR", __FUNCTION__); - // unlock the mutex and return failure - pthread_mutex_unlock(&ctx->wait_cleanup_lock); - return COPYBIT_FAILURE; - } - if(LINK_c2dCreateFenceFD(ctx->dst[ctx->dst_surface_type], ctx->time_stamp, - fd)) { - ALOGE("%s: LINK_c2dCreateFenceFD ERROR", __FUNCTION__); - status = COPYBIT_FAILURE; - } - if(status == COPYBIT_SUCCESS) { - //signal the wait_thread - ctx->wait_timestamp = true; - pthread_cond_signal(&ctx->wait_cleanup_cond); - } - pthread_mutex_unlock(&ctx->wait_cleanup_lock); - return status; -} - -static int finish_copybit(struct copybit_device_t *dev) -{ - struct copybit_context_t* ctx = (struct copybit_context_t*)dev; - if (!ctx) - return COPYBIT_FAILURE; - - int status = msm_copybit(ctx, ctx->dst[ctx->dst_surface_type]); - - if(LINK_c2dFinish(ctx->dst[ctx->dst_surface_type])) { - ALOGE("%s: LINK_c2dFinish ERROR", __FUNCTION__); - return COPYBIT_FAILURE; - } - - // Unmap any mapped addresses. - for (int i = 0; i < MAX_SURFACES; i++) { - if (ctx->mapped_gpu_addr[i]) { - LINK_c2dUnMapAddr( (void*)ctx->mapped_gpu_addr[i]); - ctx->mapped_gpu_addr[i] = 0; - } - } - - // Reset the counts after the draw. - ctx->blit_rgb_count = 0; - ctx->blit_yuv_2_plane_count = 0; - ctx->blit_yuv_3_plane_count = 0; - ctx->blit_count = 0; - ctx->dst_surface_mapped = false; - ctx->dst_surface_base = 0; - - return status; -} - -static int clear_copybit(struct copybit_device_t *dev, - struct copybit_image_t const *buf, - struct copybit_rect_t *rect) -{ - int ret = COPYBIT_SUCCESS; - int flags = FLAGS_PREMULTIPLIED_ALPHA; - int mapped_dst_idx = -1; - struct copybit_context_t* ctx = (struct copybit_context_t*)dev; - if (ctx->is_dst_ubwc_format) - flags |= FLAGS_UBWC_FORMAT_MODE; - C2D_RECT c2drect = {rect->l, rect->t, rect->r - rect->l, rect->b - rect->t}; - pthread_mutex_lock(&ctx->wait_cleanup_lock); - if(!ctx->dst_surface_mapped) { - ret = set_image(ctx, ctx->dst[RGB_SURFACE], buf, - (eC2DFlags)flags, mapped_dst_idx); - if(ret) { - ALOGE("%s: set_image error", __FUNCTION__); - unmap_gpuaddr(ctx, mapped_dst_idx); - pthread_mutex_unlock(&ctx->wait_cleanup_lock); - return COPYBIT_FAILURE; - } - //clear_copybit is the first call made by HWC for each composition - //with the dest surface, hence set dst_surface_mapped. - ctx->dst_surface_mapped = true; - ctx->dst_surface_base = buf->base; - ret = LINK_c2dFillSurface(ctx->dst[RGB_SURFACE], 0x0, &c2drect); - } - pthread_mutex_unlock(&ctx->wait_cleanup_lock); - return ret; -} - - -/** setup rectangles */ -static void set_rects(struct copybit_context_t *ctx, - C2D_OBJECT *c2dObject, - const struct copybit_rect_t *dst, - const struct copybit_rect_t *src, - const struct copybit_rect_t *scissor) -{ - // Set the target rect. - if((ctx->trg_transform & C2D_TARGET_ROTATE_90) && - (ctx->trg_transform & C2D_TARGET_ROTATE_180)) { - /* target rotation is 270 */ - c2dObject->target_rect.x = (dst->t)<<16; - c2dObject->target_rect.y = ctx->fb_width? - (ALIGN(ctx->fb_width,32)- dst->r):dst->r; - c2dObject->target_rect.y = c2dObject->target_rect.y<<16; - c2dObject->target_rect.height = ((dst->r) - (dst->l))<<16; - c2dObject->target_rect.width = ((dst->b) - (dst->t))<<16; - } else if(ctx->trg_transform & C2D_TARGET_ROTATE_90) { - c2dObject->target_rect.x = ctx->fb_height?(ctx->fb_height - dst->b):dst->b; - c2dObject->target_rect.x = c2dObject->target_rect.x<<16; - c2dObject->target_rect.y = (dst->l)<<16; - c2dObject->target_rect.height = ((dst->r) - (dst->l))<<16; - c2dObject->target_rect.width = ((dst->b) - (dst->t))<<16; - } else if(ctx->trg_transform & C2D_TARGET_ROTATE_180) { - c2dObject->target_rect.y = ctx->fb_height?(ctx->fb_height - dst->b):dst->b; - c2dObject->target_rect.y = c2dObject->target_rect.y<<16; - c2dObject->target_rect.x = ctx->fb_width? - (ALIGN(ctx->fb_width,32) - dst->r):dst->r; - c2dObject->target_rect.x = c2dObject->target_rect.x<<16; - c2dObject->target_rect.height = ((dst->b) - (dst->t))<<16; - c2dObject->target_rect.width = ((dst->r) - (dst->l))<<16; - } else { - c2dObject->target_rect.x = (dst->l)<<16; - c2dObject->target_rect.y = (dst->t)<<16; - c2dObject->target_rect.height = ((dst->b) - (dst->t))<<16; - c2dObject->target_rect.width = ((dst->r) - (dst->l))<<16; - } - c2dObject->config_mask |= C2D_TARGET_RECT_BIT; - - // Set the source rect - c2dObject->source_rect.x = (src->l)<<16; - c2dObject->source_rect.y = (src->t)<<16; - c2dObject->source_rect.height = ((src->b) - (src->t))<<16; - c2dObject->source_rect.width = ((src->r) - (src->l))<<16; - c2dObject->config_mask |= C2D_SOURCE_RECT_BIT; - - // Set the scissor rect - c2dObject->scissor_rect.x = scissor->l; - c2dObject->scissor_rect.y = scissor->t; - c2dObject->scissor_rect.height = (scissor->b) - (scissor->t); - c2dObject->scissor_rect.width = (scissor->r) - (scissor->l); - c2dObject->config_mask |= C2D_SCISSOR_RECT_BIT; -} - -/*****************************************************************************/ - -/** Set a parameter to value */ -static int set_parameter_copybit( - struct copybit_device_t *dev, - int name, - int value) -{ - struct copybit_context_t* ctx = (struct copybit_context_t*)dev; - int status = COPYBIT_SUCCESS; - if (!ctx) { - ALOGE("%s: null context", __FUNCTION__); - return -EINVAL; - } - - pthread_mutex_lock(&ctx->wait_cleanup_lock); - switch(name) { - case COPYBIT_PLANE_ALPHA: - { - if (value < 0) value = 0; - if (value >= 256) value = 255; - - ctx->src_global_alpha = value; - if (value < 255) - ctx->config_mask |= C2D_GLOBAL_ALPHA_BIT; - else - ctx->config_mask &= ~C2D_GLOBAL_ALPHA_BIT; - } - break; - case COPYBIT_BLEND_MODE: - { - if (value == COPYBIT_BLENDING_NONE) { - ctx->config_mask |= C2D_ALPHA_BLEND_NONE; - ctx->is_premultiplied_alpha = true; - } else if (value == COPYBIT_BLENDING_PREMULT) { - ctx->is_premultiplied_alpha = true; - } else { - ctx->config_mask &= ~C2D_ALPHA_BLEND_NONE; - } - } - break; - case COPYBIT_TRANSFORM: - { - unsigned int transform = 0; - uint32 config_mask = 0; - config_mask |= C2D_OVERRIDE_GLOBAL_TARGET_ROTATE_CONFIG; - if((value & 0x7) == COPYBIT_TRANSFORM_ROT_180) { - transform = C2D_TARGET_ROTATE_180; - config_mask |= C2D_OVERRIDE_TARGET_ROTATE_180; - } else if((value & 0x7) == COPYBIT_TRANSFORM_ROT_270) { - transform = C2D_TARGET_ROTATE_90; - config_mask |= C2D_OVERRIDE_TARGET_ROTATE_90; - } else if(value == COPYBIT_TRANSFORM_ROT_90) { - transform = C2D_TARGET_ROTATE_270; - config_mask |= C2D_OVERRIDE_TARGET_ROTATE_270; - } else { - config_mask |= C2D_OVERRIDE_TARGET_ROTATE_0; - if(value & COPYBIT_TRANSFORM_FLIP_H) { - config_mask |= C2D_MIRROR_H_BIT; - } else if(value & COPYBIT_TRANSFORM_FLIP_V) { - config_mask |= C2D_MIRROR_V_BIT; - } - } - - if (ctx->c2d_driver_info.capabilities_mask & - C2D_DRIVER_SUPPORTS_OVERRIDE_TARGET_ROTATE_OP) { - ctx->config_mask |= config_mask; - } else { - // The transform for this surface does not match the current - // target transform. Draw all previous surfaces. This will be - // changed once we have a new mechanism to send different - // target rotations to c2d. - finish_copybit(dev); - } - ctx->trg_transform = transform; - } - break; - case COPYBIT_FRAMEBUFFER_WIDTH: - ctx->fb_width = value; - break; - case COPYBIT_FRAMEBUFFER_HEIGHT: - ctx->fb_height = value; - break; - case COPYBIT_ROTATION_DEG: - case COPYBIT_DITHER: - case COPYBIT_BLUR: - case COPYBIT_BLIT_TO_FRAMEBUFFER: - // Do nothing - break; - case COPYBIT_SRC_FORMAT_MODE: - ctx->is_src_ubwc_format = (value == COPYBIT_UBWC_COMPRESSED); - break; - case COPYBIT_DST_FORMAT_MODE: - ctx->is_dst_ubwc_format = (value == COPYBIT_UBWC_COMPRESSED); - break; - default: - ALOGE("%s: default case param=0x%x", __FUNCTION__, name); - status = -EINVAL; - break; - } - pthread_mutex_unlock(&ctx->wait_cleanup_lock); - return status; -} - -/** Get a static info value */ -static int get(struct copybit_device_t *dev, int name) -{ - struct copybit_context_t* ctx = (struct copybit_context_t*)dev; - int value; - - if (!ctx) { - ALOGE("%s: null context error", __FUNCTION__); - return -EINVAL; - } - - switch(name) { - case COPYBIT_MINIFICATION_LIMIT: - value = MAX_SCALE_FACTOR; - break; - case COPYBIT_MAGNIFICATION_LIMIT: - value = MAX_SCALE_FACTOR; - break; - case COPYBIT_SCALING_FRAC_BITS: - value = 32; - break; - case COPYBIT_ROTATION_STEP_DEG: - value = 1; - break; - case COPYBIT_UBWC_SUPPORT: - value = 0; - if (ctx->c2d_driver_info.capabilities_mask & C2D_DRIVER_SUPPORTS_UBWC_COMPRESSED_OP) { - value = 1; - } - break; - default: - ALOGE("%s: default case param=0x%x", __FUNCTION__, name); - value = -EINVAL; - } - return value; -} - -/* Function to check if we need a temporary buffer for the blit. - * This would happen if the requested destination stride and the - * C2D stride do not match. We ignore RGB buffers, since their - * stride is always aligned to 32. - */ -static bool need_temp_buffer(struct copybit_image_t const *img) -{ - if (COPYBIT_SUCCESS == is_supported_rgb_format(img->format)) - return false; - - struct private_handle_t* handle = (struct private_handle_t*)img->handle; - - // The width parameter in the handle contains the aligned_w. We check if we - // need to convert based on this param. YUV formats have bpp=1, so checking - // if the requested stride is aligned should suffice. - if (0 == (handle->width)%32) { - return false; - } - - return true; -} - -/* Function to extract the information from the copybit image and set the corresponding - * values in the bufferInfo struct. - */ -static void populate_buffer_info(struct copybit_image_t const *img, bufferInfo& info) -{ - info.width = img->w; - info.height = img->h; - info.format = img->format; -} - -/* Function to get the required size for a particular format, inorder for C2D to perform - * the blit operation. - */ -static int get_size(const bufferInfo& info) -{ - int size = 0; - int w = info.width; - int h = info.height; - int aligned_w = ALIGN(w, 32); - switch(info.format) { - case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: - { - // Chroma for this format is aligned to 2K. - size = ALIGN((aligned_w*h), 2048) + - ALIGN(aligned_w/2, 32) * (h/2) *2; - size = ALIGN(size, 4096); - } break; - case HAL_PIXEL_FORMAT_YCbCr_420_SP: - case HAL_PIXEL_FORMAT_YCrCb_420_SP: - { - size = aligned_w * h + - ALIGN(aligned_w/2, 32) * (h/2) * 2; - size = ALIGN(size, 4096); - } break; - default: break; - } - return size; -} - -/* Function to allocate memory for the temporary buffer. This memory is - * allocated from Ashmem. It is the caller's responsibility to free this - * memory. - */ -static int get_temp_buffer(const bufferInfo& info, alloc_data& data) -{ - ALOGD("%s E", __FUNCTION__); - // Alloc memory from system heap - data.base = 0; - data.fd = -1; - data.offset = 0; - data.size = get_size(info); - data.align = getpagesize(); - data.uncached = true; - int allocFlags = 0; - - if (sAlloc == 0) { - sAlloc = gralloc::IAllocController::getInstance(); - } - - if (sAlloc == 0) { - ALOGE("%s: sAlloc is still NULL", __FUNCTION__); - return COPYBIT_FAILURE; - } - - int err = sAlloc->allocate(data, allocFlags); - if (0 != err) { - ALOGE("%s: allocate failed", __FUNCTION__); - return COPYBIT_FAILURE; - } - - ALOGD("%s X", __FUNCTION__); - return err; -} - -/* Function to free the temporary allocated memory.*/ -static void free_temp_buffer(alloc_data &data) -{ - if (-1 != data.fd) { - IMemAlloc* memalloc = sAlloc->getAllocator(data.allocType); - memalloc->free_buffer(data.base, data.size, 0, data.fd); - } -} - -/* Function to perform the software color conversion. Convert the - * C2D compatible format to the Android compatible format - */ -static int copy_image(private_handle_t *src_handle, - struct copybit_image_t const *rhs, - eConversionType conversionType) -{ - if (src_handle->fd == -1) { - ALOGE("%s: src_handle fd is invalid", __FUNCTION__); - return COPYBIT_FAILURE; - } - - // Copy the info. - int ret = COPYBIT_SUCCESS; - switch(rhs->format) { - case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: - case HAL_PIXEL_FORMAT_YCbCr_420_SP: - case HAL_PIXEL_FORMAT_YCrCb_420_SP: - { - if (CONVERT_TO_ANDROID_FORMAT == conversionType) { - return convert_yuv_c2d_to_yuv_android(src_handle, rhs); - } else { - return convert_yuv_android_to_yuv_c2d(src_handle, rhs); - } - - } break; - default: { - ALOGE("%s: invalid format 0x%x", __FUNCTION__, rhs->format); - ret = COPYBIT_FAILURE; - } break; - } - return ret; -} - -static void delete_handle(private_handle_t *handle) -{ - if (handle) { - delete handle; - handle = 0; - } -} - -static bool need_to_execute_draw(eC2DFlags flags) -{ - if (flags & FLAGS_TEMP_SRC_DST) { - return true; - } - if (flags & FLAGS_YUV_DESTINATION) { - return true; - } - return false; -} - -/** do a stretch blit type operation */ -static int stretch_copybit_internal( - struct copybit_device_t *dev, - struct copybit_image_t const *dst, - struct copybit_image_t const *src, - struct copybit_rect_t const *dst_rect, - struct copybit_rect_t const *src_rect, - struct copybit_region_t const *region, - bool enableBlend) -{ - struct copybit_context_t* ctx = (struct copybit_context_t*)dev; - int status = COPYBIT_SUCCESS; - int flags = 0; - int src_surface_type; - int mapped_src_idx = -1, mapped_dst_idx = -1; - C2D_OBJECT_STR src_surface; - - if (!ctx) { - ALOGE("%s: null context error", __FUNCTION__); - return -EINVAL; - } - - if (src->w > MAX_DIMENSION || src->h > MAX_DIMENSION) { - ALOGE("%s: src dimension error", __FUNCTION__); - return -EINVAL; - } - - if (dst->w > MAX_DIMENSION || dst->h > MAX_DIMENSION) { - ALOGE("%s : dst dimension error dst w %d h %d", __FUNCTION__, dst->w, - dst->h); - return -EINVAL; - } - - if (is_valid_destination_format(dst->format) == COPYBIT_FAILURE) { - ALOGE("%s: Invalid destination format format = 0x%x", __FUNCTION__, - dst->format); - return COPYBIT_FAILURE; - } - - int dst_surface_type; - if (ctx->is_dst_ubwc_format) - flags |= FLAGS_UBWC_FORMAT_MODE; - - if (is_supported_rgb_format(dst->format) == COPYBIT_SUCCESS) { - dst_surface_type = RGB_SURFACE; - flags |= FLAGS_PREMULTIPLIED_ALPHA; - } else if (is_supported_yuv_format(dst->format) == COPYBIT_SUCCESS) { - int num_planes = get_num_planes(dst->format); - flags |= FLAGS_YUV_DESTINATION; - if (num_planes == 2) { - dst_surface_type = YUV_SURFACE_2_PLANES; - } else if (num_planes == 3) { - dst_surface_type = YUV_SURFACE_3_PLANES; - } else { - ALOGE("%s: dst number of YUV planes is invalid dst format = 0x%x", - __FUNCTION__, dst->format); - return COPYBIT_FAILURE; - } - } else { - ALOGE("%s: Invalid dst surface format 0x%x", __FUNCTION__, - dst->format); - return COPYBIT_FAILURE; - } - - if (ctx->blit_rgb_count == MAX_RGB_SURFACES || - ctx->blit_yuv_2_plane_count == MAX_YUV_2_PLANE_SURFACES || - ctx->blit_yuv_3_plane_count == MAX_YUV_2_PLANE_SURFACES || - ctx->blit_count == MAX_BLIT_OBJECT_COUNT || - ctx->dst_surface_type != dst_surface_type) { - // we have reached the max. limits of our internal structures or - // changed the target. - // Draw the remaining surfaces. We need to do the finish here since - // we need to free up the surface templates. - finish_copybit(dev); - } - - ctx->dst_surface_type = dst_surface_type; - - // Update the destination - copybit_image_t dst_image; - dst_image.w = dst->w; - dst_image.h = dst->h; - dst_image.format = dst->format; - dst_image.handle = dst->handle; - // Check if we need a temp. copy for the destination. We'd need this the destination - // width is not aligned to 32. This case occurs for YUV formats. RGB formats are - // aligned to 32. - bool need_temp_dst = need_temp_buffer(dst); - bufferInfo dst_info; - populate_buffer_info(dst, dst_info); - private_handle_t* dst_hnd = new private_handle_t(-1, 0, 0, 0, dst_info.format, - dst_info.width, dst_info.height); - if (dst_hnd == NULL) { - ALOGE("%s: dst_hnd is null", __FUNCTION__); - return COPYBIT_FAILURE; - } - if (need_temp_dst) { - if (get_size(dst_info) != (int) ctx->temp_dst_buffer.size) { - free_temp_buffer(ctx->temp_dst_buffer); - // Create a temp buffer and set that as the destination. - if (COPYBIT_FAILURE == get_temp_buffer(dst_info, ctx->temp_dst_buffer)) { - ALOGE("%s: get_temp_buffer(dst) failed", __FUNCTION__); - delete_handle(dst_hnd); - return COPYBIT_FAILURE; - } - } - dst_hnd->fd = ctx->temp_dst_buffer.fd; - dst_hnd->size = ctx->temp_dst_buffer.size; - dst_hnd->flags = ctx->temp_dst_buffer.allocType; - dst_hnd->base = (uintptr_t)(ctx->temp_dst_buffer.base); - dst_hnd->offset = ctx->temp_dst_buffer.offset; - dst_hnd->gpuaddr = 0; - dst_image.handle = dst_hnd; - } - if(!ctx->dst_surface_mapped) { - //map the destination surface to GPU address - status = set_image(ctx, ctx->dst[ctx->dst_surface_type], &dst_image, - (eC2DFlags)flags, mapped_dst_idx); - if(status) { - ALOGE("%s: dst: set_image error", __FUNCTION__); - delete_handle(dst_hnd); - unmap_gpuaddr(ctx, mapped_dst_idx); - return COPYBIT_FAILURE; - } - ctx->dst_surface_mapped = true; - ctx->dst_surface_base = dst->base; - } else if(ctx->dst_surface_mapped && ctx->dst_surface_base != dst->base) { - // Destination surface for the operation should be same for multiple - // requests, this check is catch if there is any case when the - // destination changes - ALOGE("%s: a different destination surface!!", __FUNCTION__); - } - - // Update the source - flags = 0; - if(is_supported_rgb_format(src->format) == COPYBIT_SUCCESS) { - src_surface_type = RGB_SURFACE; - src_surface = ctx->blit_rgb_object[ctx->blit_rgb_count]; - } else if (is_supported_yuv_format(src->format) == COPYBIT_SUCCESS) { - int num_planes = get_num_planes(src->format); - if (num_planes == 2) { - src_surface_type = YUV_SURFACE_2_PLANES; - src_surface = ctx->blit_yuv_2_plane_object[ctx->blit_yuv_2_plane_count]; - } else if (num_planes == 3) { - src_surface_type = YUV_SURFACE_3_PLANES; - src_surface = ctx->blit_yuv_3_plane_object[ctx->blit_yuv_2_plane_count]; - } else { - ALOGE("%s: src number of YUV planes is invalid src format = 0x%x", - __FUNCTION__, src->format); - delete_handle(dst_hnd); - unmap_gpuaddr(ctx, mapped_dst_idx); - return -EINVAL; - } - } else { - ALOGE("%s: Invalid source surface format 0x%x", __FUNCTION__, - src->format); - delete_handle(dst_hnd); - unmap_gpuaddr(ctx, mapped_dst_idx); - return -EINVAL; - } - - copybit_image_t src_image; - src_image.w = src->w; - src_image.h = src->h; - src_image.format = src->format; - src_image.handle = src->handle; - - bool need_temp_src = need_temp_buffer(src); - bufferInfo src_info; - populate_buffer_info(src, src_info); - private_handle_t* src_hnd = new private_handle_t(-1, 0, 0, 0, src_info.format, - src_info.width, src_info.height); - if (NULL == src_hnd) { - ALOGE("%s: src_hnd is null", __FUNCTION__); - delete_handle(dst_hnd); - unmap_gpuaddr(ctx, mapped_dst_idx); - return COPYBIT_FAILURE; - } - if (need_temp_src) { - if (get_size(src_info) != (int) ctx->temp_src_buffer.size) { - free_temp_buffer(ctx->temp_src_buffer); - // Create a temp buffer and set that as the destination. - if (COPYBIT_SUCCESS != get_temp_buffer(src_info, - ctx->temp_src_buffer)) { - ALOGE("%s: get_temp_buffer(src) failed", __FUNCTION__); - delete_handle(dst_hnd); - delete_handle(src_hnd); - unmap_gpuaddr(ctx, mapped_dst_idx); - return COPYBIT_FAILURE; - } - } - src_hnd->fd = ctx->temp_src_buffer.fd; - src_hnd->size = ctx->temp_src_buffer.size; - src_hnd->flags = ctx->temp_src_buffer.allocType; - src_hnd->base = (uintptr_t)(ctx->temp_src_buffer.base); - src_hnd->offset = ctx->temp_src_buffer.offset; - src_hnd->gpuaddr = 0; - src_image.handle = src_hnd; - - // Copy the source. - status = copy_image((private_handle_t *)src->handle, &src_image, - CONVERT_TO_C2D_FORMAT); - if (status == COPYBIT_FAILURE) { - ALOGE("%s:copy_image failed in temp source",__FUNCTION__); - delete_handle(dst_hnd); - delete_handle(src_hnd); - unmap_gpuaddr(ctx, mapped_dst_idx); - return status; - } - - // Clean the cache - IMemAlloc* memalloc = sAlloc->getAllocator(src_hnd->flags); - if (memalloc->clean_buffer((void *)(src_hnd->base), src_hnd->size, - src_hnd->offset, src_hnd->fd, - gralloc::CACHE_CLEAN)) { - ALOGE("%s: clean_buffer failed", __FUNCTION__); - delete_handle(dst_hnd); - delete_handle(src_hnd); - unmap_gpuaddr(ctx, mapped_dst_idx); - return COPYBIT_FAILURE; - } - } - - flags |= (ctx->is_premultiplied_alpha) ? FLAGS_PREMULTIPLIED_ALPHA : 0; - flags |= (ctx->dst_surface_type != RGB_SURFACE) ? FLAGS_YUV_DESTINATION : 0; - flags |= (ctx->is_src_ubwc_format) ? FLAGS_UBWC_FORMAT_MODE : 0; - status = set_image(ctx, src_surface.surface_id, &src_image, - (eC2DFlags)flags, mapped_src_idx); - if(status) { - ALOGE("%s: set_image (src) error", __FUNCTION__); - delete_handle(dst_hnd); - delete_handle(src_hnd); - unmap_gpuaddr(ctx, mapped_dst_idx); - unmap_gpuaddr(ctx, mapped_src_idx); - return COPYBIT_FAILURE; - } - - src_surface.config_mask = C2D_NO_ANTIALIASING_BIT | ctx->config_mask; - src_surface.global_alpha = ctx->src_global_alpha; - if (enableBlend) { - if(src_surface.config_mask & C2D_GLOBAL_ALPHA_BIT) { - src_surface.config_mask &= ~C2D_ALPHA_BLEND_NONE; - if(!(src_surface.global_alpha)) { - // src alpha is zero - delete_handle(dst_hnd); - delete_handle(src_hnd); - unmap_gpuaddr(ctx, mapped_dst_idx); - unmap_gpuaddr(ctx, mapped_src_idx); - return COPYBIT_FAILURE; - } - } - } else { - src_surface.config_mask |= C2D_ALPHA_BLEND_NONE; - } - - if (src_surface_type == RGB_SURFACE) { - ctx->blit_rgb_object[ctx->blit_rgb_count] = src_surface; - ctx->blit_rgb_count++; - } else if (src_surface_type == YUV_SURFACE_2_PLANES) { - ctx->blit_yuv_2_plane_object[ctx->blit_yuv_2_plane_count] = src_surface; - ctx->blit_yuv_2_plane_count++; - } else { - ctx->blit_yuv_3_plane_object[ctx->blit_yuv_3_plane_count] = src_surface; - ctx->blit_yuv_3_plane_count++; - } - - struct copybit_rect_t clip; - while ((status == 0) && region->next(region, &clip)) { - set_rects(ctx, &(src_surface), dst_rect, src_rect, &clip); - if (ctx->blit_count == MAX_BLIT_OBJECT_COUNT) { - ALOGW("Reached end of blit count"); - finish_copybit(dev); - } - ctx->blit_list[ctx->blit_count] = src_surface; - ctx->blit_count++; - } - - // Check if we need to perform an early draw-finish. - flags |= (need_temp_dst || need_temp_src) ? FLAGS_TEMP_SRC_DST : 0; - if (need_to_execute_draw((eC2DFlags)flags)) - { - finish_copybit(dev); - } - - if (need_temp_dst) { - // copy the temp. destination without the alignment to the actual - // destination. - status = copy_image(dst_hnd, dst, CONVERT_TO_ANDROID_FORMAT); - if (status == COPYBIT_FAILURE) { - ALOGE("%s:copy_image failed in temp Dest",__FUNCTION__); - delete_handle(dst_hnd); - delete_handle(src_hnd); - unmap_gpuaddr(ctx, mapped_dst_idx); - unmap_gpuaddr(ctx, mapped_src_idx); - return status; - } - // Clean the cache. - IMemAlloc* memalloc = sAlloc->getAllocator(dst_hnd->flags); - memalloc->clean_buffer((void *)(dst_hnd->base), dst_hnd->size, - dst_hnd->offset, dst_hnd->fd, - gralloc::CACHE_CLEAN); - } - delete_handle(dst_hnd); - delete_handle(src_hnd); - - ctx->is_premultiplied_alpha = false; - ctx->fb_width = 0; - ctx->fb_height = 0; - ctx->config_mask = 0; - return status; -} - -static int set_sync_copybit(struct copybit_device_t *dev, - int /*acquireFenceFd*/) -{ - if(!dev) - return -EINVAL; - - return 0; -} - -static int stretch_copybit( - struct copybit_device_t *dev, - struct copybit_image_t const *dst, - struct copybit_image_t const *src, - struct copybit_rect_t const *dst_rect, - struct copybit_rect_t const *src_rect, - struct copybit_region_t const *region) -{ - struct copybit_context_t* ctx = (struct copybit_context_t*)dev; - int status = COPYBIT_SUCCESS; - bool needsBlending = (ctx->src_global_alpha != 0); - pthread_mutex_lock(&ctx->wait_cleanup_lock); - status = stretch_copybit_internal(dev, dst, src, dst_rect, src_rect, - region, needsBlending); - pthread_mutex_unlock(&ctx->wait_cleanup_lock); - return status; -} - -/** Perform a blit type operation */ -static int blit_copybit( - struct copybit_device_t *dev, - struct copybit_image_t const *dst, - struct copybit_image_t const *src, - struct copybit_region_t const *region) -{ - int status = COPYBIT_SUCCESS; - struct copybit_context_t* ctx = (struct copybit_context_t*)dev; - struct copybit_rect_t dr = { 0, 0, (int)dst->w, (int)dst->h }; - struct copybit_rect_t sr = { 0, 0, (int)src->w, (int)src->h }; - pthread_mutex_lock(&ctx->wait_cleanup_lock); - status = stretch_copybit_internal(dev, dst, src, &dr, &sr, region, false); - pthread_mutex_unlock(&ctx->wait_cleanup_lock); - return status; -} - -/** Fill the rect on dst with RGBA color **/ -static int fill_color(struct copybit_device_t *dev, - struct copybit_image_t const *dst, - struct copybit_rect_t const *rect, - uint32_t /*color*/) -{ - // TODO: Implement once c2d driver supports color fill - if(!dev || !dst || !rect) - return -EINVAL; - - return -EINVAL; -} - -/*****************************************************************************/ - -static void clean_up(copybit_context_t* ctx) -{ - void* ret; - if (!ctx) - return; - - // stop the wait_cleanup_thread - pthread_mutex_lock(&ctx->wait_cleanup_lock); - ctx->stop_thread = true; - // Signal waiting thread - pthread_cond_signal(&ctx->wait_cleanup_cond); - pthread_mutex_unlock(&ctx->wait_cleanup_lock); - // waits for the cleanup thread to exit - pthread_join(ctx->wait_thread_id, &ret); - pthread_mutex_destroy(&ctx->wait_cleanup_lock); - pthread_cond_destroy (&ctx->wait_cleanup_cond); - - for (int i = 0; i < NUM_SURFACE_TYPES; i++) { - if (ctx->dst[i]) - LINK_c2dDestroySurface(ctx->dst[i]); - } - - for (int i = 0; i < MAX_RGB_SURFACES; i++) { - if (ctx->blit_rgb_object[i].surface_id) - LINK_c2dDestroySurface(ctx->blit_rgb_object[i].surface_id); - } - - for (int i = 0; i < MAX_YUV_2_PLANE_SURFACES; i++) { - if (ctx->blit_yuv_2_plane_object[i].surface_id) - LINK_c2dDestroySurface(ctx->blit_yuv_2_plane_object[i].surface_id); - } - - for (int i = 0; i < MAX_YUV_3_PLANE_SURFACES; i++) { - if (ctx->blit_yuv_3_plane_object[i].surface_id) - LINK_c2dDestroySurface(ctx->blit_yuv_3_plane_object[i].surface_id); - } - - if (ctx->libc2d2) { - ::dlclose(ctx->libc2d2); - ALOGV("dlclose(libc2d2)"); - } - - free(ctx); -} - -/** Close the copybit device */ -static int close_copybit(struct hw_device_t *dev) -{ - struct copybit_context_t* ctx = (struct copybit_context_t*)dev; - if (ctx) { - free_temp_buffer(ctx->temp_src_buffer); - free_temp_buffer(ctx->temp_dst_buffer); - } - clean_up(ctx); - return 0; -} - -/** Open a new instance of a copybit device using name */ -static int open_copybit(const struct hw_module_t* module, const char* name, - struct hw_device_t** device) -{ - int status = COPYBIT_SUCCESS; - if (strcmp(name, COPYBIT_HARDWARE_COPYBIT0)) { - return COPYBIT_FAILURE; - } - - C2D_RGB_SURFACE_DEF surfDefinition = {0}; - C2D_YUV_SURFACE_DEF yuvSurfaceDef = {0} ; - struct copybit_context_t *ctx; - - ctx = (struct copybit_context_t *)malloc(sizeof(struct copybit_context_t)); - if(!ctx) { - ALOGE("%s: malloc failed", __FUNCTION__); - return COPYBIT_FAILURE; - } - - /* initialize drawstate */ - memset(ctx, 0, sizeof(*ctx)); - ctx->libc2d2 = ::dlopen("libC2D2.so", RTLD_NOW); - if (!ctx->libc2d2) { - ALOGE("FATAL ERROR: could not dlopen libc2d2.so: %s", dlerror()); - clean_up(ctx); - status = COPYBIT_FAILURE; - *device = NULL; - return status; - } - *(void **)&LINK_c2dCreateSurface = ::dlsym(ctx->libc2d2, - "c2dCreateSurface"); - *(void **)&LINK_c2dUpdateSurface = ::dlsym(ctx->libc2d2, - "c2dUpdateSurface"); - *(void **)&LINK_c2dReadSurface = ::dlsym(ctx->libc2d2, - "c2dReadSurface"); - *(void **)&LINK_c2dDraw = ::dlsym(ctx->libc2d2, "c2dDraw"); - *(void **)&LINK_c2dFlush = ::dlsym(ctx->libc2d2, "c2dFlush"); - *(void **)&LINK_c2dFinish = ::dlsym(ctx->libc2d2, "c2dFinish"); - *(void **)&LINK_c2dWaitTimestamp = ::dlsym(ctx->libc2d2, - "c2dWaitTimestamp"); - *(void **)&LINK_c2dDestroySurface = ::dlsym(ctx->libc2d2, - "c2dDestroySurface"); - *(void **)&LINK_c2dMapAddr = ::dlsym(ctx->libc2d2, - "c2dMapAddr"); - *(void **)&LINK_c2dUnMapAddr = ::dlsym(ctx->libc2d2, - "c2dUnMapAddr"); - *(void **)&LINK_c2dGetDriverCapabilities = ::dlsym(ctx->libc2d2, - "c2dGetDriverCapabilities"); - *(void **)&LINK_c2dCreateFenceFD = ::dlsym(ctx->libc2d2, - "c2dCreateFenceFD"); - *(void **)&LINK_c2dFillSurface = ::dlsym(ctx->libc2d2, - "c2dFillSurface"); - - if (!LINK_c2dCreateSurface || !LINK_c2dUpdateSurface || !LINK_c2dReadSurface - || !LINK_c2dDraw || !LINK_c2dFlush || !LINK_c2dWaitTimestamp || - !LINK_c2dFinish || !LINK_c2dDestroySurface || - !LINK_c2dGetDriverCapabilities || !LINK_c2dCreateFenceFD || - !LINK_c2dFillSurface) { - ALOGE("%s: dlsym ERROR", __FUNCTION__); - clean_up(ctx); - status = COPYBIT_FAILURE; - *device = NULL; - return status; - } - - ctx->device.common.tag = HARDWARE_DEVICE_TAG; - ctx->device.common.version = 1; - ctx->device.common.module = (hw_module_t*)(module); - ctx->device.common.close = close_copybit; - ctx->device.set_parameter = set_parameter_copybit; - ctx->device.get = get; - ctx->device.blit = blit_copybit; - ctx->device.set_sync = set_sync_copybit; - ctx->device.stretch = stretch_copybit; - ctx->device.finish = finish_copybit; - ctx->device.flush_get_fence = flush_get_fence_copybit; - ctx->device.clear = clear_copybit; - ctx->device.fill_color = fill_color; - - /* Create RGB Surface */ - surfDefinition.buffer = (void*)0xdddddddd; - surfDefinition.phys = (void*)0xdddddddd; - surfDefinition.stride = 1 * 4; - surfDefinition.width = 1; - surfDefinition.height = 1; - surfDefinition.format = C2D_COLOR_FORMAT_8888_ARGB; - if (LINK_c2dCreateSurface(&(ctx->dst[RGB_SURFACE]), C2D_TARGET | C2D_SOURCE, - (C2D_SURFACE_TYPE)(C2D_SURFACE_RGB_HOST | - C2D_SURFACE_WITH_PHYS | - C2D_SURFACE_WITH_PHYS_DUMMY ), - &surfDefinition)) { - ALOGE("%s: create ctx->dst_surface[RGB_SURFACE] failed", __FUNCTION__); - ctx->dst[RGB_SURFACE] = 0; - clean_up(ctx); - status = COPYBIT_FAILURE; - *device = NULL; - return status; - } - - unsigned int surface_id = 0; - for (int i = 0; i < MAX_RGB_SURFACES; i++) - { - if (LINK_c2dCreateSurface(&surface_id, C2D_TARGET | C2D_SOURCE, - (C2D_SURFACE_TYPE)(C2D_SURFACE_RGB_HOST | - C2D_SURFACE_WITH_PHYS | - C2D_SURFACE_WITH_PHYS_DUMMY ), - &surfDefinition)) { - ALOGE("%s: create RGB source surface %d failed", __FUNCTION__, i); - ctx->blit_rgb_object[i].surface_id = 0; - status = COPYBIT_FAILURE; - break; - } else { - ctx->blit_rgb_object[i].surface_id = surface_id; - ALOGW("%s i = %d surface_id=%d", __FUNCTION__, i, - ctx->blit_rgb_object[i].surface_id); - } - } - - if (status == COPYBIT_FAILURE) { - clean_up(ctx); - status = COPYBIT_FAILURE; - *device = NULL; - return status; - } - - // Create 2 plane YUV surfaces - yuvSurfaceDef.format = C2D_COLOR_FORMAT_420_NV12; - yuvSurfaceDef.width = 4; - yuvSurfaceDef.height = 4; - yuvSurfaceDef.plane0 = (void*)0xaaaaaaaa; - yuvSurfaceDef.phys0 = (void*) 0xaaaaaaaa; - yuvSurfaceDef.stride0 = 4; - - yuvSurfaceDef.plane1 = (void*)0xaaaaaaaa; - yuvSurfaceDef.phys1 = (void*) 0xaaaaaaaa; - yuvSurfaceDef.stride1 = 4; - if (LINK_c2dCreateSurface(&(ctx->dst[YUV_SURFACE_2_PLANES]), - C2D_TARGET | C2D_SOURCE, - (C2D_SURFACE_TYPE)(C2D_SURFACE_YUV_HOST | - C2D_SURFACE_WITH_PHYS | - C2D_SURFACE_WITH_PHYS_DUMMY), - &yuvSurfaceDef)) { - ALOGE("%s: create ctx->dst[YUV_SURFACE_2_PLANES] failed", __FUNCTION__); - ctx->dst[YUV_SURFACE_2_PLANES] = 0; - clean_up(ctx); - status = COPYBIT_FAILURE; - *device = NULL; - return status; - } - - for (int i=0; i < MAX_YUV_2_PLANE_SURFACES; i++) - { - if (LINK_c2dCreateSurface(&surface_id, C2D_TARGET | C2D_SOURCE, - (C2D_SURFACE_TYPE)(C2D_SURFACE_YUV_HOST | - C2D_SURFACE_WITH_PHYS | - C2D_SURFACE_WITH_PHYS_DUMMY ), - &yuvSurfaceDef)) { - ALOGE("%s: create YUV source %d failed", __FUNCTION__, i); - ctx->blit_yuv_2_plane_object[i].surface_id = 0; - status = COPYBIT_FAILURE; - break; - } else { - ctx->blit_yuv_2_plane_object[i].surface_id = surface_id; - ALOGW("%s: 2 Plane YUV i=%d surface_id=%d", __FUNCTION__, i, - ctx->blit_yuv_2_plane_object[i].surface_id); - } - } - - if (status == COPYBIT_FAILURE) { - clean_up(ctx); - status = COPYBIT_FAILURE; - *device = NULL; - return status; - } - - // Create YUV 3 plane surfaces - yuvSurfaceDef.format = C2D_COLOR_FORMAT_420_YV12; - yuvSurfaceDef.plane2 = (void*)0xaaaaaaaa; - yuvSurfaceDef.phys2 = (void*) 0xaaaaaaaa; - yuvSurfaceDef.stride2 = 4; - - if (LINK_c2dCreateSurface(&(ctx->dst[YUV_SURFACE_3_PLANES]), - C2D_TARGET | C2D_SOURCE, - (C2D_SURFACE_TYPE)(C2D_SURFACE_YUV_HOST | - C2D_SURFACE_WITH_PHYS | - C2D_SURFACE_WITH_PHYS_DUMMY), - &yuvSurfaceDef)) { - ALOGE("%s: create ctx->dst[YUV_SURFACE_3_PLANES] failed", __FUNCTION__); - ctx->dst[YUV_SURFACE_3_PLANES] = 0; - clean_up(ctx); - status = COPYBIT_FAILURE; - *device = NULL; - return status; - } - - for (int i=0; i < MAX_YUV_3_PLANE_SURFACES; i++) - { - if (LINK_c2dCreateSurface(&(surface_id), - C2D_TARGET | C2D_SOURCE, - (C2D_SURFACE_TYPE)(C2D_SURFACE_YUV_HOST | - C2D_SURFACE_WITH_PHYS | - C2D_SURFACE_WITH_PHYS_DUMMY), - &yuvSurfaceDef)) { - ALOGE("%s: create 3 plane YUV surface %d failed", __FUNCTION__, i); - ctx->blit_yuv_3_plane_object[i].surface_id = 0; - status = COPYBIT_FAILURE; - break; - } else { - ctx->blit_yuv_3_plane_object[i].surface_id = surface_id; - ALOGW("%s: 3 Plane YUV i=%d surface_id=%d", __FUNCTION__, i, - ctx->blit_yuv_3_plane_object[i].surface_id); - } - } - - if (status == COPYBIT_FAILURE) { - clean_up(ctx); - status = COPYBIT_FAILURE; - *device = NULL; - return status; - } - - if (LINK_c2dGetDriverCapabilities(&(ctx->c2d_driver_info))) { - ALOGE("%s: LINK_c2dGetDriverCapabilities failed", __FUNCTION__); - clean_up(ctx); - status = COPYBIT_FAILURE; - *device = NULL; - return status; - } - // Initialize context variables. - ctx->trg_transform = C2D_TARGET_ROTATE_0; - - ctx->temp_src_buffer.fd = -1; - ctx->temp_src_buffer.base = 0; - ctx->temp_src_buffer.size = 0; - - ctx->temp_dst_buffer.fd = -1; - ctx->temp_dst_buffer.base = 0; - ctx->temp_dst_buffer.size = 0; - - ctx->fb_width = 0; - ctx->fb_height = 0; - - ctx->blit_rgb_count = 0; - ctx->blit_yuv_2_plane_count = 0; - ctx->blit_yuv_3_plane_count = 0; - ctx->blit_count = 0; - - ctx->wait_timestamp = false; - ctx->stop_thread = false; - pthread_mutex_init(&(ctx->wait_cleanup_lock), NULL); - pthread_cond_init(&(ctx->wait_cleanup_cond), NULL); - /* Start the wait thread */ - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); - - pthread_create(&ctx->wait_thread_id, &attr, &c2d_wait_loop, - (void *)ctx); - pthread_attr_destroy(&attr); - - *device = &ctx->device.common; - return status; -} diff --git a/libcopybit/copybit_priv.h b/libcopybit/copybit_priv.h deleted file mode 100644 index 68dfac4b..00000000 --- a/libcopybit/copybit_priv.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2011, The Linux Foundation. All rights reserved. - - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of The Linux Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -struct copybit_iterator : public copybit_region_t { - copybit_iterator(const copybit_rect_t& rect) { - mRect = rect; - mCount = 1; - this->next = iterate; - } -private: - static int iterate(copybit_region_t const * self, copybit_rect_t* rect) { - if (!self || !rect) { - return 0; - } - - copybit_iterator const* me = static_cast(self); - if (me->mCount) { - rect->l = me->mRect.l; - rect->t = me->mRect.t; - rect->r = me->mRect.r; - rect->b = me->mRect.b; - me->mCount--; - return 1; - } - return 0; - } - copybit_rect_t mRect; - mutable int mCount; -}; diff --git a/libcopybit/software_converter.cpp b/libcopybit/software_converter.cpp deleted file mode 100644 index 1aa3ce60..00000000 --- a/libcopybit/software_converter.cpp +++ /dev/null @@ -1,263 +0,0 @@ -/* - * Copyright (c) 2011-2014, The Linux Foundation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of The Linux Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include "software_converter.h" - -/** Convert YV12 to YCrCb_420_SP */ -int convertYV12toYCrCb420SP(const copybit_image_t *src, private_handle_t *yv12_handle) -{ - private_handle_t* hnd = (private_handle_t*)src->handle; - - if(hnd == NULL || yv12_handle == NULL){ - ALOGE("Invalid handle"); - return -1; - } - - // Please refer to the description of YV12 in hardware.h - // for the formulae used to calculate buffer sizes and offsets - - // In a copybit_image_t, w is the stride and - // stride - horiz_padding is the actual width - // vertical stride is the same as height, so not considered - unsigned int stride = src->w; - unsigned int width = src->w - src->horiz_padding; - unsigned int height = src->h; - unsigned int y_size = stride * src->h; - unsigned int c_width = ALIGN(stride/2, (unsigned int)16); - unsigned int c_size = c_width * src->h/2; - unsigned int chromaPadding = c_width - width/2; - unsigned int chromaSize = c_size * 2; - unsigned char* newChroma = (unsigned char *)(yv12_handle->base + y_size); - unsigned char* oldChroma = (unsigned char*)(hnd->base + y_size); - memcpy((char *)yv12_handle->base,(char *)hnd->base,y_size); - -#if defined(__ARM_HAVE_NEON) && !defined(__aarch64__) - /* interleave */ - if(!chromaPadding) { - unsigned char * t1 = newChroma; - unsigned char * t2 = oldChroma; - unsigned char * t3 = t2 + chromaSize/2; - for(unsigned int i=0; i < (chromaSize/2)>>3; i++) { - __asm__ __volatile__ ( - "vld1.u8 d0, [%0]! \n" - "vld1.u8 d1, [%1]! \n" - "vst2.u8 {d0, d1}, [%2]! \n" - :"+r"(t2), "+r"(t3), "+r"(t1) - : - :"memory","d0","d1" - ); - - } - } -#else //__ARM_HAVE_NEON - if(!chromaPadding) { - for(unsigned int i = 0; i< chromaSize/2; i++) { - newChroma[i*2] = oldChroma[i]; - newChroma[i*2+1] = oldChroma[i+chromaSize/2]; - } - - } -#endif - // If the image is not aligned to 16 pixels, - // convert using the C routine below - // r1 tracks the row of the source buffer - // r2 tracks the row of the destination buffer - // The width/2 checks are to avoid copying - // from the padding - - if(chromaPadding) { - unsigned int r1 = 0, r2 = 0, i = 0, j = 0; - while(r1 < height/2) { - if(j == width) { - j = 0; - r2++; - continue; - } - if (j+1 == width) { - newChroma[r2*width + j] = oldChroma[r1*c_width+i]; - r2++; - newChroma[r2*width] = oldChroma[r1*c_width+i+c_size]; - j = 1; - } else { - newChroma[r2*width + j] = oldChroma[r1*c_width+i]; - newChroma[r2*width + j + 1] = oldChroma[r1*c_width+i+c_size]; - j+=2; - } - i++; - if (i == width/2 ) { - i = 0; - r1++; - } - } - } - - return 0; -} - -struct copyInfo{ - int width; - int height; - int src_stride; - int dst_stride; - size_t src_plane1_offset; - size_t src_plane2_offset; - size_t dst_plane1_offset; - size_t dst_plane2_offset; -}; - -/* Internal function to do the actual copy of source to destination */ -static int copy_source_to_destination(const uintptr_t src_base, - const uintptr_t dst_base, - copyInfo& info) -{ - if (!src_base || !dst_base) { - ALOGE("%s: invalid memory src_base = 0x%p dst_base=0x%p", - __FUNCTION__, (void*)src_base, (void*)dst_base); - return COPYBIT_FAILURE; - } - - int width = info.width; - int height = info.height; - unsigned char *src = (unsigned char*)src_base; - unsigned char *dst = (unsigned char*)dst_base; - - // Copy the luma - for (int i = 0; i < height; i++) { - memcpy(dst, src, width); - src += info.src_stride; - dst += info.dst_stride; - } - - // Copy plane 1 - src = (unsigned char*)(src_base + info.src_plane1_offset); - dst = (unsigned char*)(dst_base + info.dst_plane1_offset); - width = width/2; - height = height/2; - for (int i = 0; i < height; i++) { - memcpy(dst, src, info.src_stride); - src += info.src_stride; - dst += info.dst_stride; - } - return 0; -} - - -/* - * Function to convert the c2d format into an equivalent Android format - * - * @param: source buffer handle - * @param: destination image - * - * @return: return status - */ -int convert_yuv_c2d_to_yuv_android(private_handle_t *hnd, - struct copybit_image_t const *rhs) -{ - ALOGD("Enter %s", __FUNCTION__); - if (!hnd || !rhs) { - ALOGE("%s: invalid inputs hnd=%p rhs=%p", __FUNCTION__, hnd, rhs); - return COPYBIT_FAILURE; - } - - int ret = COPYBIT_SUCCESS; - private_handle_t *dst_hnd = (private_handle_t *)rhs->handle; - - copyInfo info; - info.width = rhs->w; - info.height = rhs->h; - info.src_stride = ALIGN(info.width, 32); - info.dst_stride = ALIGN(info.width, 16); - switch(rhs->format) { - case HAL_PIXEL_FORMAT_YCbCr_420_SP: - case HAL_PIXEL_FORMAT_YCrCb_420_SP: { - info.src_plane1_offset = info.src_stride*info.height; - info.dst_plane1_offset = info.dst_stride*info.height; - } break; - case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: { - // Chroma is 2K aligned for the NV12 encodeable format. - info.src_plane1_offset = ALIGN(info.src_stride*info.height, 2048); - info.dst_plane1_offset = ALIGN(info.dst_stride*info.height, 2048); - } break; - default: - ALOGE("%s: unsupported format (format=0x%x)", __FUNCTION__, - rhs->format); - return COPYBIT_FAILURE; - } - - ret = copy_source_to_destination((uintptr_t) hnd->base, (uintptr_t) dst_hnd->base, info); - return ret; -} - -/* - * Function to convert the Android format into an equivalent C2D format - * - * @param: source buffer handle - * @param: destination image - * - * @return: return status - */ -int convert_yuv_android_to_yuv_c2d(private_handle_t *hnd, - struct copybit_image_t const *rhs) -{ - if (!hnd || !rhs) { - ALOGE("%s: invalid inputs hnd=%p rhs=%p", __FUNCTION__, hnd, rhs); - return COPYBIT_FAILURE; - } - - int ret = COPYBIT_SUCCESS; - private_handle_t *dst_hnd = (private_handle_t *)rhs->handle; - - copyInfo info; - info.width = rhs->w; - info.height = rhs->h; - info.src_stride = ALIGN(hnd->width, 16); - info.dst_stride = ALIGN(info.width, 32); - switch(rhs->format) { - case HAL_PIXEL_FORMAT_YCbCr_420_SP: - case HAL_PIXEL_FORMAT_YCrCb_420_SP: { - info.src_plane1_offset = info.src_stride*info.height; - info.dst_plane1_offset = info.dst_stride*info.height; - } break; - case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: { - // Chroma is 2K aligned for the NV12 encodeable format. - info.src_plane1_offset = ALIGN(info.src_stride*info.height, 2048); - info.dst_plane1_offset = ALIGN(info.dst_stride*info.height, 2048); - } break; - default: - ALOGE("%s: unsupported format (format=0x%x)", __FUNCTION__, - rhs->format); - return -1; - } - - ret = copy_source_to_destination((uintptr_t) hnd->base, (uintptr_t) dst_hnd->base, info); - return ret; -} diff --git a/libcopybit/software_converter.h b/libcopybit/software_converter.h deleted file mode 100644 index cc6ae342..00000000 --- a/libcopybit/software_converter.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2011, The Linux Foundation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of The Linux Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - - - -#include -#include "gralloc_priv.h" - -#define COPYBIT_SUCCESS 0 -#define COPYBIT_FAILURE -1 - -#define ALIGN(x, y) (((x) + y - 1) & (~(y - 1))) - -int convertYV12toYCrCb420SP(const copybit_image_t *src,private_handle_t *yv12_handle); - -/* - * Function to convert the c2d format into an equivalent Android format - * - * @param: source buffer handle - * @param: destination image - * - * @return: return status - */ -int convert_yuv_c2d_to_yuv_android(private_handle_t *hnd, - struct copybit_image_t const *rhs); - - -/* - * Function to convert the Android format into an equivalent C2D format - * - * @param: source buffer handle - * @param: destination image - * - * @return: return status - */ -int convert_yuv_android_to_yuv_c2d(private_handle_t *hnd, - struct copybit_image_t const *rhs); diff --git a/libdebug/Android.mk b/libdebug/Android.mk deleted file mode 100644 index e975a22a..00000000 --- a/libdebug/Android.mk +++ /dev/null @@ -1,14 +0,0 @@ -LOCAL_PATH := $(call my-dir) -include $(CLEAR_VARS) - -LOCAL_MODULE := libdisplaydebug -LOCAL_VENDOR_MODULE := true -LOCAL_MODULE_TAGS := optional -LOCAL_SHARED_LIBRARIES := libdl -LOCAL_CFLAGS := -DLOG_TAG=\"SDM\" -Wall -std=c++11 -Werror -fno-operator-names -LOCAL_CLANG := true -LOCAL_SRC_FILES := debug_handler.cpp -LOCAL_COPY_HEADERS_TO := qcom/display -LOCAL_COPY_HEADERS := debug_handler.h - -include $(BUILD_SHARED_LIBRARY) diff --git a/libdebug/debug_handler.cpp b/libdebug/debug_handler.cpp deleted file mode 100644 index 00c3ec9f..00000000 --- a/libdebug/debug_handler.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* -* Copyright (c) 2018, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include "debug_handler.h" - -namespace display { - -// By default, drop any log messages/traces. It need to be overridden by client. -class DefaultDebugHandler : public DebugHandler { - public: - virtual void Error(const char *, ...) { } - virtual void Warning(const char *, ...) { } - virtual void Info(const char *, ...) { } - virtual void Debug(const char *, ...) { } - virtual void Verbose(const char *, ...) { } - virtual void BeginTrace(const char *, const char *, const char *) { } - virtual void EndTrace() { } - virtual int GetProperty(const char *, int *) { return -1; } - virtual int GetProperty(const char *, char *) { return -1; } -}; - -DefaultDebugHandler g_default_debug_handler; -DebugHandler * DebugHandler::debug_handler_ = &g_default_debug_handler; -std::bitset<32> DebugHandler::log_mask_ = 0x1; // Always print logs tagged with value 0 - -void DebugHandler::Set(DebugHandler *debug_handler) { - if (debug_handler) { - debug_handler_ = debug_handler; - } else { - debug_handler_ = &g_default_debug_handler; - } -} - -} // namespace display diff --git a/libdebug/debug_handler.h b/libdebug/debug_handler.h deleted file mode 100644 index 81795e41..00000000 --- a/libdebug/debug_handler.h +++ /dev/null @@ -1,101 +0,0 @@ -/* -* Copyright (c) 2018, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __DEBUG_HANDLER_H__ -#define __DEBUG_HANDLER_H__ - -#include - -#define DLOG(method, format, ...) \ - display::DebugHandler::Get()->method(__CLASS__ "::%s: " format, __FUNCTION__, ##__VA_ARGS__) - -#define DLOG_IF(tag, method, format, ...) \ - if (display::DebugHandler::GetLogMask()[tag]) { \ - DLOG(method, format, ##__VA_ARGS__); \ - } - -#define DLOGE_IF(tag, format, ...) DLOG_IF(tag, Error, format, ##__VA_ARGS__) -#define DLOGW_IF(tag, format, ...) DLOG_IF(tag, Warning, format, ##__VA_ARGS__) -#define DLOGI_IF(tag, format, ...) DLOG_IF(tag, Info, format, ##__VA_ARGS__) -#define DLOGD_IF(tag, format, ...) DLOG_IF(tag, Debug, format, ##__VA_ARGS__) -#define DLOGV_IF(tag, format, ...) DLOG_IF(tag, Verbose, format, ##__VA_ARGS__) - -#define DLOGE(format, ...) DLOG(Error, format, ##__VA_ARGS__) -#define DLOGW(format, ...) DLOG(Warning, format, ##__VA_ARGS__) -#define DLOGI(format, ...) DLOG(Info, format, ##__VA_ARGS__) -#define DLOGD(format, ...) DLOG(Debug, format, ##__VA_ARGS__) -#define DLOGV(format, ...) DLOG(Verbose, format, ##__VA_ARGS__) - -#define DTRACE_BEGIN(custom_string) display::DebugHandler::Get()->BeginTrace( \ - __CLASS__, __FUNCTION__, custom_string) -#define DTRACE_END() display::DebugHandler::Get()->EndTrace() -#define DTRACE_SCOPED() display::ScopeTracer \ - scope_tracer(__CLASS__, __FUNCTION__) - -namespace display { - -class DebugHandler { - public: - virtual void Error(const char *format, ...) = 0; - virtual void Warning(const char *format, ...) = 0; - virtual void Info(const char *format, ...) = 0; - virtual void Debug(const char *format, ...) = 0; - virtual void Verbose(const char *format, ...) = 0; - virtual void BeginTrace(const char *class_name, const char *function_name, - const char *custom_string) = 0; - virtual void EndTrace() = 0; - virtual int GetProperty(const char *property_name, int *value) = 0; - virtual int GetProperty(const char *property_name, char *value) = 0; - - static inline DebugHandler *Get() { return debug_handler_; } - static void Set(DebugHandler *debug_handler); - static inline std::bitset<32> & GetLogMask() { return log_mask_; } - static void SetLogMask(const std::bitset<32> &log_mask) { log_mask_ = log_mask; } - - protected: - virtual ~DebugHandler() { } - - private: - static DebugHandler *debug_handler_; - static std::bitset<32> log_mask_; -}; - -template -class ScopeTracer { - public: - ScopeTracer(const char *class_name, const char *function_name) { - T::Get()->BeginTrace(class_name, function_name, ""); - } - - ~ScopeTracer() { T::Get()->EndTrace(); } -}; - -} // namespace display - -#endif // __DEBUG_HANDLER_H__ diff --git a/libdrmutils/Android.mk b/libdrmutils/Android.mk deleted file mode 100644 index 97c052b1..00000000 --- a/libdrmutils/Android.mk +++ /dev/null @@ -1,18 +0,0 @@ -LOCAL_PATH := $(call my-dir) -include $(CLEAR_VARS) - -LOCAL_MODULE := libdrmutils -LOCAL_VENDOR_MODULE := true -LOCAL_MODULE_TAGS := optional -LOCAL_C_INCLUDES := external/libdrm \ - $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include -LOCAL_HEADER_LIBRARIES := display_headers -LOCAL_SHARED_LIBRARIES := libdrm libdl libdisplaydebug -LOCAL_CFLAGS := -DLOG_TAG=\"DRMUTILS\" -Wall -std=c++11 -Werror -fno-operator-names -LOCAL_CLANG := true -LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr -LOCAL_SRC_FILES := drm_master.cpp drm_res_mgr.cpp drm_lib_loader.cpp -LOCAL_COPY_HEADERS_TO := qcom/display -LOCAL_COPY_HEADERS := drm_master.h drm_res_mgr.h drm_lib_loader.h drm_logger.h drm_interface.h - -include $(BUILD_SHARED_LIBRARY) diff --git a/libdrmutils/drm_interface.h b/libdrmutils/drm_interface.h deleted file mode 100644 index 8dcab3ad..00000000 --- a/libdrmutils/drm_interface.h +++ /dev/null @@ -1,718 +0,0 @@ -/* -* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __DRM_INTERFACE_H__ -#define __DRM_INTERFACE_H__ - -#include -#include -#include -#include - -#include "xf86drm.h" -#include "xf86drmMode.h" -#include - -namespace sde_drm { - -typedef std::map, float> CompRatioMap; - -/* - * Drm Atomic Operation Codes - */ -enum struct DRMOps { - /* - * Op: Sets plane source crop - * Arg: uint32_t - Plane ID - * DRMRect - Source Rectangle - */ - PLANE_SET_SRC_RECT, - /* - * Op: Sets plane destination rect - * Arg: uint32_t - Plane ID - * DRMRect - Dst Rectangle - */ - PLANE_SET_DST_RECT, - /* - * Op: Sets plane zorder - * Arg: uint32_t - Plane ID - * uint32_t - zorder - */ - PLANE_SET_ZORDER, - /* - * Op: Sets plane rotation flags - * Arg: uint32_t - Plane ID - * uint32_t - bit mask of rotation flags (See drm_mode.h for enums) - */ - PLANE_SET_ROTATION, - /* - * Op: Sets plane alpha - * Arg: uint32_t - Plane ID - * uint32_t - alpha value - */ - PLANE_SET_ALPHA, - /* - * Op: Sets the blend type - * Arg: uint32_t - Plane ID - * uint32_t - blend type (see DRMBlendType) - */ - PLANE_SET_BLEND_TYPE, - /* - * Op: Sets horizontal decimation - * Arg: uint32_t - Plane ID - * uint32_t - decimation factor - */ - PLANE_SET_H_DECIMATION, - /* - * Op: Sets vertical decimation - * Arg: uint32_t - Plane ID - * uint32_t - decimation factor - */ - PLANE_SET_V_DECIMATION, - /* - * Op: Sets source config flags - * Arg: uint32_t - Plane ID - * uint32_t - flags to enable or disable a specific op. E.g. deinterlacing - */ - PLANE_SET_SRC_CONFIG, - /* - * Op: Sets frame buffer ID for plane. Set together with CRTC. - * Arg: uint32_t - Plane ID - * uint32_t - Framebuffer ID - */ - PLANE_SET_FB_ID, - /* - * Op: Sets the crtc for this plane. Set together with FB_ID. - * Arg: uint32_t - Plane ID - * uint32_t - CRTC ID - */ - PLANE_SET_CRTC, - /* - * Op: Sets acquire fence for this plane's buffer. Set together with FB_ID, CRTC. - * Arg: uint32_t - Plane ID - * uint32_t - Input fence - */ - PLANE_SET_INPUT_FENCE, - /* - * Op: Sets scaler config on this plane. - * Arg: uint32_t - Plane ID - * uint64_t - Address of the scaler config object (version based) - */ - PLANE_SET_SCALER_CONFIG, - /* - * Op: Sets plane rotation destination rect - * Arg: uint32_t - Plane ID - * DRMRect - rotator dst Rectangle - */ - PLANE_SET_ROTATION_DST_RECT, - /* - * Op: Sets FB Secure mode for this plane. - * Arg: uint32_t - Plane ID - * uint32_t - Value of the FB Secure mode. - */ - PLANE_SET_FB_SECURE_MODE, - /* - * Op: Sets csc config on this plane. - * Arg: uint32_t - Plane ID - * uint32_t* - pointer to csc type - */ - PLANE_SET_CSC_CONFIG, - /* - * Op: Sets multirect mode on this plane. - * Arg: uint32_t - Plane ID - * uint32_t - multirect mode - */ - PLANE_SET_MULTIRECT_MODE, - /* - * Op: Activate or deactivate a CRTC - * Arg: uint32_t - CRTC ID - * uint32_t - 1 to enable, 0 to disable - */ - CRTC_SET_ACTIVE, - /* - * Op: Sets display mode - * Arg: uint32_t - CRTC ID - * drmModeModeInfo* - Pointer to display mode - */ - CRTC_SET_MODE, - /* - * Op: Sets an offset indicating when a release fence should be signalled. - * Arg: uint32_t - offset - * 0: non-speculative, default - * 1: speculative - */ - CRTC_SET_OUTPUT_FENCE_OFFSET, - /* - * Op: Sets overall SDE core clock - * Arg: uint32_t - CRTC ID - * uint32_t - core_clk - */ - CRTC_SET_CORE_CLK, - /* - * Op: Sets MNOC bus average bandwidth - * Arg: uint32_t - CRTC ID - * uint32_t - core_ab - */ - CRTC_SET_CORE_AB, - /* - * Op: Sets MNOC bus instantaneous bandwidth - * Arg: uint32_t - CRTC ID - * uint32_t - core_ib - */ - CRTC_SET_CORE_IB, - /* - * Op: Sets LLCC Bus average bandwidth - * Arg: uint32_t - CRTC ID - * uint32_t - llcc_ab - */ - CRTC_SET_LLCC_AB, - /* - * Op: Sets LLCC Bus instantaneous bandwidth - * Arg: uint32_t - CRTC ID - * uint32_t - llcc_ib - */ - CRTC_SET_LLCC_IB, - /* - * Op: Sets DRAM bus average bandwidth - * Arg: uint32_t - CRTC ID - * uint32_t - dram_ab - */ - CRTC_SET_DRAM_AB, - /* - * Op: Sets DRAM bus instantaneous bandwidth - * Arg: uint32_t - CRTC ID - * uint32_t - dram_ib - */ - CRTC_SET_DRAM_IB, - /* - * Op: Sets Rotator BW for inline rotation - * Arg: uint32_t - CRTC ID - * uint32_t - rot_bw - */ - CRTC_SET_ROT_PREFILL_BW, - /* - * Op: Sets rotator clock for inline rotation - * Arg: uint32_t - CRTC ID - * uint32_t - rot_clk - */ - CRTC_SET_ROT_CLK, - /* - * Op: Sets destination scalar data - * Arg: uint32_t - CRTC ID - * uint64_t - Pointer to destination scalar data - */ - CRTC_SET_DEST_SCALER_CONFIG, - /* - * Op: Returns release fence for this frame. Should be called after Commit() on - * DRMAtomicReqInterface. - * Arg: uint32_t - CRTC ID - * int * - Pointer to an integer that will hold the returned fence - */ - CRTC_GET_RELEASE_FENCE, - /* - * Op: Sets PP feature - * Arg: uint32_t - CRTC ID - * DRMPPFeatureInfo * - PP feature data pointer - */ - CRTC_SET_POST_PROC, - /* - * Op: Sets CRTC ROIs. - * Arg: uint32_t - CRTC ID - * uint32_t - number of ROIs - * DRMRect * - Array of CRTC ROIs - */ - CRTC_SET_ROI, - /* - * Op: Sets Security level for CRTC. - * Arg: uint32_t - CRTC ID - * uint32_t - Security level - */ - CRTC_SET_SECURITY_LEVEL, - /* - * Op: sets solid fill stages - * Arg: uint32_t - CRTC ID - * Vector of DRMSolidfillStage - */ - CRTC_SET_SOLIDFILL_STAGES, - /* - * Op: Sets idle timeout. - * Arg: uint32_t - CRTC ID - * uint32_t - idle timeout in ms - */ - CRTC_SET_IDLE_TIMEOUT, - /* - * Op: Returns retire fence for this commit. Should be called after Commit() on - * DRMAtomicReqInterface. - * Arg: uint32_t - Connector ID - * int * - Pointer to an integer that will hold the returned fence - */ - CONNECTOR_GET_RETIRE_FENCE, - /* - * Op: Sets writeback connector destination rect - * Arg: uint32_t - Connector ID - * DRMRect - Dst Rectangle - */ - CONNECTOR_SET_OUTPUT_RECT, - /* - * Op: Sets frame buffer ID for writeback connector. - * Arg: uint32_t - Connector ID - * uint32_t - Framebuffer ID - */ - CONNECTOR_SET_OUTPUT_FB_ID, - /* - * Op: Sets power mode for connector. - * Arg: uint32_t - Connector ID - * uint32_t - Power Mode - */ - CONNECTOR_SET_POWER_MODE, - /* - * Op: Sets panel ROIs. - * Arg: uint32_t - Connector ID - * uint32_t - number of ROIs - * DRMRect * - Array of Connector ROIs - */ - CONNECTOR_SET_ROI, - /* - * Op: Sets the connector to autorefresh mode. - * Arg: uint32_t - Connector ID - * uint32_t - Enable-1, Disable-0 - */ - CONNECTOR_SET_AUTOREFRESH, - /* - * Op: Set FB secure mode for Writeback connector. - * Arg: uint32_t - Connector ID - * uint32_t - FB Secure mode - */ - CONNECTOR_SET_FB_SECURE_MODE, - /* - * Op: Sets a crtc id to this connector - * Arg: uint32_t - Connector ID - * uint32_t - CRTC ID - */ - CONNECTOR_SET_CRTC, - /* - * Op: Sets PP feature - * Arg: uint32_t - Connector ID - * DRMPPFeatureInfo * - PP feature data pointer - */ - CONNECTOR_SET_POST_PROC, - /* - * Op: Sets connector hdr metadata - * Arg: uint32_t - Connector ID - * drm_msm_ext_hdr_metadata - hdr_metadata - */ - CONNECTOR_SET_HDR_METADATA, -}; - -enum struct DRMRotation { - FLIP_H = 0x1, - FLIP_V = 0x2, - ROT_180 = FLIP_H | FLIP_V, - ROT_90 = 0x4, -}; - -enum struct DRMPowerMode { - ON, - DOZE, - DOZE_SUSPEND, - OFF, -}; - -enum struct DRMBlendType { - UNDEFINED = 0, - OPAQUE = 1, - PREMULTIPLIED = 2, - COVERAGE = 3, -}; - -enum struct DRMSrcConfig { - DEINTERLACE = 0, -}; - -/* Display type to identify a suitable connector */ -enum struct DRMDisplayType { - PERIPHERAL, - TV, - VIRTUAL, -}; - -struct DRMRect { - uint32_t left; // Left-most pixel coordinate. - uint32_t top; // Top-most pixel coordinate. - uint32_t right; // Right-most pixel coordinate. - uint32_t bottom; // Bottom-most pixel coordinate. -}; - -//------------------------------------------------------------------------ -// DRM Info Query Types -//------------------------------------------------------------------------ - -enum struct QSEEDVersion { - V1, - V2, - V3, -}; - -/* QSEED3 Step version */ -enum struct QSEEDStepVersion { - V2, - V3, - V4, -}; - -enum struct SmartDMARevision { - V1, - V2, -}; - -/* Per CRTC Resource Info*/ -struct DRMCrtcInfo { - bool has_src_split; - bool has_hdr; - uint32_t max_blend_stages; - uint32_t max_solidfill_stages; - QSEEDVersion qseed_version; - SmartDMARevision smart_dma_rev; - float ib_fudge_factor; - float clk_fudge_factor; - uint32_t dest_scale_prefill_lines; - uint32_t undersized_prefill_lines; - uint32_t macrotile_prefill_lines; - uint32_t nv12_prefill_lines; - uint32_t linear_prefill_lines; - uint32_t downscale_prefill_lines; - uint32_t extra_prefill_lines; - uint32_t amortized_threshold; - uint64_t max_bandwidth_low; - uint64_t max_bandwidth_high; - uint32_t max_sde_clk; - CompRatioMap comp_ratio_rt_map; - CompRatioMap comp_ratio_nrt_map; - uint32_t hw_version; - uint32_t dest_scaler_count = 0; - uint32_t max_dest_scaler_input_width = 0; - uint32_t max_dest_scaler_output_width = 0; - uint32_t max_dest_scale_up = 1; - uint32_t min_prefill_lines = 0; -}; - -enum struct DRMPlaneType { - // Has CSC and scaling capability - VIG = 0, - // Has scaling capability but no CSC - RGB, - // No scaling support - DMA, - // Supports a small dimension and doesn't use a CRTC stage - CURSOR, - MAX, -}; - -struct DRMPlaneTypeInfo { - DRMPlaneType type; - uint32_t master_plane_id; - // FourCC format enum and modifier - std::vector> formats_supported; - uint32_t max_linewidth; - uint32_t max_upscale; - uint32_t max_downscale; - uint32_t max_horizontal_deci; - uint32_t max_vertical_deci; - uint64_t max_pipe_bandwidth; - uint32_t cache_size; // cache size in bytes for inline rotation support. - QSEEDStepVersion qseed3_version; - bool multirect_prop_present = false; -}; - -// All DRM Planes as map listed from highest to lowest priority -typedef std::vector> DRMPlanesInfo; - -enum struct DRMTopology { - UNKNOWN, // To be compat with driver defs in sde_rm.h - SINGLE_LM, - SINGLE_LM_DSC, - DUAL_LM, - DUAL_LM_DSC, - DUAL_LM_MERGE, - DUAL_LM_MERGE_DSC, - DUAL_LM_DSCMERGE, - PPSPLIT, -}; - -enum struct DRMPanelMode { - VIDEO, - COMMAND, -}; - -/* Per mode info */ -struct DRMModeInfo { - drmModeModeInfo mode; - DRMTopology topology; - // Valid only if mode is command - int num_roi; - int xstart; - int ystart; - int walign; - int halign; - int wmin; - int hmin; - bool roi_merge; -}; - -/* Per Connector Info*/ -struct DRMConnectorInfo { - uint32_t mmWidth; - uint32_t mmHeight; - uint32_t type; - std::vector modes; - std::string panel_name; - DRMPanelMode panel_mode; - bool is_primary; - // Valid only if DRMPanelMode is VIDEO - bool dynamic_fps; - // FourCC format enum and modifier - std::vector> formats_supported; - // Valid only if type is DRM_MODE_CONNECTOR_VIRTUAL - uint32_t max_linewidth; - DRMRotation panel_orientation; - drm_panel_hdr_properties panel_hdr_prop; - uint32_t transfer_time_us; - drm_msm_ext_hdr_properties ext_hdr_prop; -}; - -/* Identifier token for a display */ -struct DRMDisplayToken { - uint32_t conn_id; - uint32_t crtc_id; - uint32_t crtc_index; -}; - -enum DRMPPFeatureID { - kFeaturePcc, - kFeatureIgc, - kFeaturePgc, - kFeatureMixerGc, - kFeaturePaV2, - kFeatureDither, - kFeatureGamut, - kFeaturePADither, - kFeaturePAHsic, - kFeaturePASixZone, - kFeaturePAMemColSkin, - kFeaturePAMemColSky, - kFeaturePAMemColFoliage, - kFeaturePAMemColProt, - kPPFeaturesMax, -}; - -enum DRMPPPropType { - kPropEnum, - kPropRange, - kPropBlob, - kPropTypeMax, -}; - -struct DRMPPFeatureInfo { - DRMPPFeatureID id; - DRMPPPropType type; - uint32_t version; - uint32_t payload_size; - void *payload; - uint32_t object_type; -}; - -enum DRMCscType { - kCscYuv2Rgb601L, - kCscYuv2Rgb601FR, - kCscYuv2Rgb709L, - kCscYuv2Rgb2020L, - kCscYuv2Rgb2020FR, - kCscTypeMax, -}; - -struct DRMScalerLUTInfo { - uint32_t dir_lut_size = 0; - uint32_t cir_lut_size = 0; - uint32_t sep_lut_size = 0; - uint64_t dir_lut = 0; - uint64_t cir_lut = 0; - uint64_t sep_lut = 0; -}; - -enum struct DRMSecureMode { - NON_SECURE, - SECURE, - NON_SECURE_DIR_TRANSLATION, - SECURE_DIR_TRANSLATION, -}; - -enum struct DRMSecurityLevel { - SECURE_NON_SECURE, - SECURE_ONLY, -}; - -enum struct DRMMultiRectMode { - NONE = 0, - PARALLEL = 1, - SERIAL = 2, -}; - -struct DRMSolidfillStage { - DRMRect bounding_rect {}; - bool is_exclusion_rect = false; - uint32_t color = 0xff000000; // in 8bit argb - uint32_t red = 0; - uint32_t blue = 0; - uint32_t green = 0; - uint32_t alpha = 0xff; - uint32_t color_bit_depth = 0; - uint32_t z_order = 0; - uint32_t plane_alpha = 0xff; -}; - -/* DRM Atomic Request Property Set. - * - * Helper class to create and populate atomic properties of DRM components - * when rendered in DRM atomic mode */ -class DRMAtomicReqInterface { - public: - virtual ~DRMAtomicReqInterface() {} - /* Perform request operation. - * - * [input]: opcode: operation code from DRMOps list. - * var_arg: arguments for DRMOps's can differ in number and - * data type. Refer above DRMOps to details. - * [return]: Error code if the API fails, 0 on success. - */ - virtual int Perform(DRMOps opcode, ...) = 0; - - /* - * Commit the params set via Perform(). Also resets the properties after commit. Needs to be - * called every frame. - * [input]: synchronous: Determines if the call should block until a h/w flip - * [input]: retain_planes: Retains already staged planes. Useful when not explicitly programming - * planes but still need the previously staged ones to not be unstaged - * [return]: Error code if the API fails, 0 on success. - */ - virtual int Commit(bool synchronous, bool retain_planes) = 0; - /* - * Validate the params set via Perform(). - * [return]: Error code if the API fails, 0 on success. - */ - virtual int Validate() = 0; -}; - -class DRMManagerInterface; - -/* Populates a singleton instance of DRMManager */ -typedef int (*GetDRMManager)(int fd, DRMManagerInterface **intf); - -/* Destroy DRMManager instance */ -typedef int (*DestroyDRMManager)(); - -/* - * DRM Manager Interface - Any class which plans to implement helper function for vendor - * specific DRM driver implementation must implement the below interface routines to work - * with SDM. - */ - -class DRMManagerInterface { - public: - virtual ~DRMManagerInterface() {} - - /* - * Since SDM completely manages the planes. GetPlanesInfo will provide all - * the plane information. - * [output]: DRMPlanesInfo: Resource Info for planes. - */ - virtual void GetPlanesInfo(DRMPlanesInfo *info) = 0; - - /* - * Will provide all the information of a selected crtc. - * [input]: Use crtc id 0 to obtain system wide info - * [output]: DRMCrtcInfo: Resource Info for the given CRTC id. - */ - virtual void GetCrtcInfo(uint32_t crtc_id, DRMCrtcInfo *info) = 0; - - /* - * Will provide all the information of a selected connector. - * [output]: DRMConnectorInfo: Resource Info for the given connector id - */ - virtual void GetConnectorInfo(uint32_t conn_id, DRMConnectorInfo *info) = 0; - - /* - * Will query post propcessing feature info of a CRTC. - * [output]: DRMPPFeatureInfo: CRTC post processing feature info - */ - virtual void GetCrtcPPInfo(uint32_t crtc_id, DRMPPFeatureInfo *info) = 0; - /* - * Register a logical display to receive a token. - * Each display pipeline in DRM is identified by its CRTC and Connector(s). - * On display connect(bootup or hotplug), clients should invoke this interface to - * establish the pipeline for the display and should get a DisplayToken - * populated with crtc and connnector(s) id's. Here onwards, Client should - * use this token to represent the display for any Perform operations if - * needed. - * - * [input]: disp_type - Peripheral / TV / Virtual - * [output]: DRMDisplayToken - CRTC and Connector id's for the display - * [return]: 0 on success, a negative error value otherwise - */ - virtual int RegisterDisplay(DRMDisplayType disp_type, DRMDisplayToken *tok) = 0; - - /* Client should invoke this interface on display disconnect. - * [input]: DRMDisplayToken - identifier for the display. - */ - virtual void UnregisterDisplay(const DRMDisplayToken &token) = 0; - - /* - * Creates and returns an instance of DRMAtomicReqInterface corresponding to a display token - * returned as part of RegisterDisplay API. Needs to be called per display. - * [input]: DRMDisplayToken that identifies a display pipeline - * [output]: Pointer to an instance of DRMAtomicReqInterface. - * [return]: Error code if the API fails, 0 on success. - */ - virtual int CreateAtomicReq(const DRMDisplayToken &token, DRMAtomicReqInterface **intf) = 0; - - /* - * Destroys the instance of DRMAtomicReqInterface - * [input]: Pointer to a DRMAtomicReqInterface - * [return]: Error code if the API fails, 0 on success. - */ - virtual int DestroyAtomicReq(DRMAtomicReqInterface *intf) = 0; - /* - * Sets the global scaler LUT - * [input]: LUT Info - * [return]: Error code if the API fails, 0 on success. - */ - virtual int SetScalerLUT(const DRMScalerLUTInfo &lut_info) = 0; -}; - -} // namespace sde_drm -#endif // __DRM_INTERFACE_H__ diff --git a/libdrmutils/drm_lib_loader.cpp b/libdrmutils/drm_lib_loader.cpp deleted file mode 100644 index 83c9f1b5..00000000 --- a/libdrmutils/drm_lib_loader.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* -* Copyright (c) 2017, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include - -#include "drm_lib_loader.h" - -#define __CLASS__ "DRMLibLoader" - -using std::mutex; -using std::lock_guard; - -namespace drm_utils { - -DRMLibLoader *DRMLibLoader::s_instance = nullptr; -mutex DRMLibLoader::s_lock; - -DRMLibLoader *DRMLibLoader::GetInstance() { - lock_guard obj(s_lock); - - if (!s_instance) { - s_instance = new DRMLibLoader(); - } - - return s_instance; -} - -void DRMLibLoader::Destroy() { - lock_guard obj(s_lock); - if (s_instance) { - delete s_instance; - s_instance = nullptr; - } -} - -DRMLibLoader::DRMLibLoader() { - if (Open("libsdedrm.so")) { - if (Sym("GetDRMManager", reinterpret_cast(&func_get_drm_manager_)) && - Sym("DestroyDRMManager", reinterpret_cast(&func_destroy_drm_manager_))) { - is_loaded_ = true; - } - } -} - -DRMLibLoader::~DRMLibLoader() { - if (lib_) { - ::dlclose(lib_); - lib_ = nullptr; - } -} - -bool DRMLibLoader::Open(const char *lib_name) { - lib_ = ::dlopen(lib_name, RTLD_NOW); - - return (lib_ != nullptr); -} - -bool DRMLibLoader::Sym(const char *func_name, void **func_ptr) { - if (lib_) { - *func_ptr = ::dlsym(lib_, func_name); - } - - return (*func_ptr != nullptr); -} - -} // namespace drm_utils diff --git a/libdrmutils/drm_lib_loader.h b/libdrmutils/drm_lib_loader.h deleted file mode 100644 index d132d69c..00000000 --- a/libdrmutils/drm_lib_loader.h +++ /dev/null @@ -1,64 +0,0 @@ -/* -* Copyright (c) 2017, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __DRM_LIB_LOADER_H__ -#define __DRM_LIB_LOADER_H__ - -#include -#include - -namespace drm_utils { - -class DRMLibLoader { - public: - ~DRMLibLoader(); - bool IsLoaded() { return is_loaded_; } - sde_drm::GetDRMManager FuncGetDRMManager() { return func_get_drm_manager_; } - sde_drm::DestroyDRMManager FuncDestroyDRMManager() { return func_destroy_drm_manager_; } - - static DRMLibLoader *GetInstance(); - static void Destroy(); - - private: - DRMLibLoader(); - bool Open(const char *lib_name); - bool Sym(const char *func_name, void **func_ptr); - - void *lib_ = {}; - sde_drm::GetDRMManager func_get_drm_manager_ = {}; - sde_drm::DestroyDRMManager func_destroy_drm_manager_ = {}; - bool is_loaded_ = false; - - static DRMLibLoader *s_instance; // Singleton instance - static std::mutex s_lock; -}; - -} // namespace drm_utils - -#endif // __DRM_LIB_LOADER_H__ diff --git a/libdrmutils/drm_logger.h b/libdrmutils/drm_logger.h deleted file mode 100644 index 7f81d887..00000000 --- a/libdrmutils/drm_logger.h +++ /dev/null @@ -1,48 +0,0 @@ -/* -* Copyright (c) 2017 - 2018, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __DRM_LOGGER_H__ -#define __DRM_LOGGER_H__ - -#include -#include - -namespace drm_utils { - -#define DRM_LOG_TAG 4 // = kTagRotator - -#define DRM_LOGE(format, ...) DLOGE(format, ##__VA_ARGS__) -#define DRM_LOGW(format, ...) DLOGW_IF(DRM_LOG_TAG, format, ##__VA_ARGS__) -#define DRM_LOGI(format, ...) DLOGI_IF(DRM_LOG_TAG, format, ##__VA_ARGS__) -#define DRM_LOGD(format, ...) DLOGD_IF(DRM_LOG_TAG, format, ##__VA_ARGS__) -#define DRM_LOGV(format, ...) DLOGV_IF(DRM_LOG_TAG, format, ##__VA_ARGS__) - -} // namespace drm_utils - -#endif // __DRM_LOGGER_H__ diff --git a/libdrmutils/drm_master.cpp b/libdrmutils/drm_master.cpp deleted file mode 100644 index 96429e28..00000000 --- a/libdrmutils/drm_master.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/* -* Copyright (c) 2017 - 2018, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include -#include -#include -#include -#include -#include -// Intentionally included after xf86 headers so that they in-turn include libdrm version of drm.h -// that doesn't use keyword "virtual" for a variable name. Not doing so leads to the kernel version -// of drm.h being included causing compilation to fail -#include -#include -#include - -#include "drm_master.h" - -#define __CLASS__ "DRMMaster" - -using std::mutex; -using std::lock_guard; -using std::begin; -using std::copy; -using std::end; -using std::fill; - -namespace drm_utils { - -DRMMaster *DRMMaster::s_instance = nullptr; -mutex DRMMaster::s_lock; - -int DRMMaster::GetInstance(DRMMaster **master) { - lock_guard obj(s_lock); - - if (!s_instance) { - s_instance = new DRMMaster(); - if (s_instance->Init() < 0) { - delete s_instance; - s_instance = nullptr; - return -ENODEV; - } - } - - *master = s_instance; - return 0; -} - -void DRMMaster::DestroyInstance() { - lock_guard obj(s_lock); - delete s_instance; - s_instance = nullptr; -} - -int DRMMaster::Init() { - dev_fd_ = drmOpen("msm_drm", nullptr); - if (dev_fd_ < 0) { - DRM_LOGE("drmOpen failed with error %d", dev_fd_); - return -ENODEV; - } - - return 0; -} - -DRMMaster::~DRMMaster() { - drmClose(dev_fd_); - dev_fd_ = -1; -} - -int DRMMaster::CreateFbId(const DRMBuffer &drm_buffer, uint32_t *fb_id) { - uint32_t gem_handle = 0; - int ret = drmPrimeFDToHandle(dev_fd_, drm_buffer.fd, &gem_handle); - if (ret) { - DRM_LOGW("drmPrimeFDToHandle failed with error %d", ret); - return ret; - } - - struct drm_mode_fb_cmd2 cmd2 {}; - cmd2.width = drm_buffer.width; - cmd2.height = drm_buffer.height; - cmd2.pixel_format = drm_buffer.drm_format; - cmd2.flags = DRM_MODE_FB_MODIFIERS; - fill(begin(cmd2.handles), begin(cmd2.handles) + drm_buffer.num_planes, gem_handle); - copy(begin(drm_buffer.stride), end(drm_buffer.stride), begin(cmd2.pitches)); - copy(begin(drm_buffer.offset), end(drm_buffer.offset), begin(cmd2.offsets)); - fill(begin(cmd2.modifier), begin(cmd2.modifier) + drm_buffer.num_planes, - drm_buffer.drm_format_modifier); - - if ((ret = drmIoctl(dev_fd_, DRM_IOCTL_MODE_ADDFB2, &cmd2))) { - DRM_LOGE("DRM_IOCTL_MODE_ADDFB2 failed with error %d", ret); - } else { - *fb_id = cmd2.fb_id; - } - - struct drm_gem_close gem_close = {}; - gem_close.handle = gem_handle; - int ret1 = drmIoctl(dev_fd_, DRM_IOCTL_GEM_CLOSE, &gem_close); - if (ret1) { - DRM_LOGE("drmIoctl::DRM_IOCTL_GEM_CLOSE failed with error %d", ret1); - return ret1; - } - - return ret; -} - -int DRMMaster::RemoveFbId(uint32_t fb_id) { - int ret = 0; -#ifdef DRM_IOCTL_MSM_RMFB2 - ret = drmIoctl(dev_fd_, DRM_IOCTL_MSM_RMFB2, &fb_id); - if (ret) { - DRM_LOGE("drmIoctl::DRM_IOCTL_MSM_RMFB2 failed for fb_id %d with error %d", fb_id, errno); - } -#else - ret = drmModeRmFB(dev_fd_, fb_id); - if (ret) { - DRM_LOGE("drmModeRmFB failed for fb_id %d with error %d", fb_id, ret); - } -#endif - return ret; -} - -bool DRMMaster::IsRmFbRefCounted() { -#ifdef DRM_IOCTL_MSM_RMFB2 - return true; -#endif - return false; -} - -} // namespace drm_utils diff --git a/libdrmutils/drm_master.h b/libdrmutils/drm_master.h deleted file mode 100644 index 18f51ebc..00000000 --- a/libdrmutils/drm_master.h +++ /dev/null @@ -1,97 +0,0 @@ -/* -* Copyright (c) 2017, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __DRM_MASTER_H__ -#define __DRM_MASTER_H__ - -#include - -#include "drm_logger.h" - -namespace drm_utils { - -struct DRMBuffer { - int fd = -1; - uint32_t width = 0; - uint32_t height = 0; - uint32_t drm_format = 0; - uint64_t drm_format_modifier = 0; - uint32_t stride[4] = {}; - uint32_t offset[4] = {}; - uint32_t num_planes = 1; -}; - -class DRMMaster { - public: - ~DRMMaster(); - /* Converts from ION fd --> Prime Handle --> FB_ID. - * Input: - * drm_buffer: A DRMBuffer obj that packages description of buffer - * Output: - * fb_id: Pointer to store DRM framebuffer id into - * Returns: - * ioctl error code - */ - int CreateFbId(const DRMBuffer &drm_buffer, uint32_t *fb_id); - /* Removes the fb_id from DRM - * Input: - * fb_id: DRM FB to be removed - * Returns: - * ioctl error code - */ - int RemoveFbId(uint32_t fb_id); - /* Poplulates master DRM fd - * Input: - * fd: Pointer to store master fd into - */ - void GetHandle(int *fd) { *fd = dev_fd_; } - /* Returns true if the ref counted version of rmfb is being used */ - bool IsRmFbRefCounted(); - - /* Creates an instance of DRMMaster if it doesn't exist and initializes it. Threadsafe. - * Input: - * master: Pointer to store a pointer to the instance - * Returns: - * -ENODEV if device cannot be opened or initilization fails - */ - static int GetInstance(DRMMaster **master); - static void DestroyInstance(); - - private: - DRMMaster() {} - int Init(); - - int dev_fd_ = -1; // Master fd for DRM - static DRMMaster *s_instance; // Singleton instance - static std::mutex s_lock; -}; - -} // namespace drm_utils - -#endif // __DRM_MASTER_H__ diff --git a/libdrmutils/drm_res_mgr.cpp b/libdrmutils/drm_res_mgr.cpp deleted file mode 100644 index 1d29495d..00000000 --- a/libdrmutils/drm_res_mgr.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* -* Copyright (c) 2017, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include - -#include "drm_master.h" -#include "drm_res_mgr.h" - -#define DEBUG 0 -#define __CLASS__ "DRMResMgr" - -using std::mutex; -using std::lock_guard; - -namespace drm_utils { - -DRMResMgr *DRMResMgr::s_instance = nullptr; -mutex DRMResMgr::s_lock; - -static bool GetConnector(int dev_fd, drmModeRes *res, drmModeConnector **connector) { - for (auto i = 0; i < res->count_connectors; i++) { - drmModeConnector *conn = drmModeGetConnector(dev_fd, res->connectors[i]); - if (conn && conn->connector_type == DRM_MODE_CONNECTOR_DSI && conn->count_modes && - conn->connection == DRM_MODE_CONNECTED) { - *connector = conn; - DRM_LOGI("Found connector %d", conn->connector_id); - return true; - } - } - - return false; -} - -static bool GetEncoder(int dev_fd, drmModeConnector *conn, drmModeEncoder **encoder) { - for (auto i = 0; i < conn->count_encoders; i++) { - drmModeEncoder *enc = drmModeGetEncoder(dev_fd, conn->encoders[i]); - if (enc && enc->encoder_type == DRM_MODE_ENCODER_DSI) { - *encoder = enc; - DRM_LOGI("Found encoder %d", enc->encoder_id); - return true; - } - } - return false; -} - -static bool GetCrtc(int dev_fd, drmModeRes *res, drmModeEncoder *enc, drmModeCrtc **crtc) { - for (auto i = 0; i < res->count_crtcs; i++) { - if (enc->possible_crtcs & (1 << i)) { - drmModeCrtc *c = drmModeGetCrtc(dev_fd, res->crtcs[i]); - if (c) { - *crtc = c; - DRM_LOGI("Found crtc %d", c->crtc_id); - return true; - } - } - } - - return false; -} - -#define __CLASS__ "DRMResMgr" - -int DRMResMgr::GetInstance(DRMResMgr **res_mgr) { - lock_guard obj(s_lock); - - if (!s_instance) { - s_instance = new DRMResMgr(); - if (s_instance->Init() < 0) { - delete s_instance; - s_instance = nullptr; - return -ENODEV; - } - } - - *res_mgr = s_instance; - return 0; -} - -int DRMResMgr::Init() { - DRMMaster *master = nullptr; - int dev_fd = -1; - - int ret = DRMMaster::GetInstance(&master); - if (ret < 0) { - return ret; - } - - master->GetHandle(&dev_fd); - drmModeRes *res = drmModeGetResources(dev_fd); - if (res == nullptr) { - DRM_LOGE("drmModeGetResources failed"); - return -ENODEV; - } - - drmModeConnector *conn = nullptr; - if (!GetConnector(dev_fd, res, &conn)) { - DRM_LOGE("Failed to find a connector"); - return -ENODEV; - } - - drmModeEncoder *enc = nullptr; - if (!GetEncoder(dev_fd, conn, &enc)) { - DRM_LOGE("Failed to find an encoder"); - drmModeFreeConnector(conn); - return -ENODEV; - } - - drmModeCrtc *crtc = nullptr; - if (!GetCrtc(dev_fd, res, enc, &crtc)) { - DRM_LOGE("Failed to find a crtc"); - drmModeFreeEncoder(enc); - drmModeFreeConnector(conn); - drmModeFreeResources(res); - return -ENODEV; - } - - res_ = res; - conn_ = conn; - enc_ = enc; - crtc_ = crtc; - - return 0; -} - -} // namespace drm_utils diff --git a/libdrmutils/drm_res_mgr.h b/libdrmutils/drm_res_mgr.h deleted file mode 100644 index 3a8378c5..00000000 --- a/libdrmutils/drm_res_mgr.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -* Copyright (c) 2017, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __DRM_RES_MGR_H__ -#define __DRM_RES_MGR_H__ - -#include -#include - -#include - -namespace drm_utils { - -class DRMResMgr { - public: - /* Returns the default connector id for primary panel */ - void GetConnectorId(uint32_t *id) { *id = conn_->connector_id; } - /* Returns the default crtc id for primary pipeline */ - void GetCrtcId(uint32_t *id) { *id = crtc_->crtc_id; } - /* Returns the default mode currently used by the connector */ - void GetMode(drmModeModeInfo *mode) { *mode = conn_->modes[0]; } - /* Returns the panel dimensions in mm */ - void GetDisplayDimInMM(uint32_t *w, uint32_t *h) { - *w = conn_->mmWidth; - *h = conn_->mmHeight; - } - - /* Creates and initializes an instance of DRMResMgr. On success, returns a pointer to it, on - * failure returns -ENODEV */ - static int GetInstance(DRMResMgr **res_mgr); - - private: - int Init(); - - drmModeRes *res_ = nullptr; - drmModeConnector *conn_ = nullptr; - drmModeEncoder *enc_ = nullptr; - drmModeCrtc *crtc_ = nullptr; - - static DRMResMgr *s_instance; - static std::mutex s_lock; -}; - -} // namespace drm_utils - -#endif // __DRM_RES_MGR_H__ diff --git a/liblight/Android.mk b/liblight/Android.mk deleted file mode 100644 index 5720bbab..00000000 --- a/liblight/Android.mk +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright (C) 2008 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. - -LOCAL_PATH:= $(call my-dir) -# HAL module implemenation stored in -# hw/..so -include $(CLEAR_VARS) - -LOCAL_SRC_FILES := lights.c -LOCAL_MODULE_RELATIVE_PATH := hw -LOCAL_SHARED_LIBRARIES := liblog -LOCAL_HEADER_LIBRARIES := libhardware_headers -LOCAL_CFLAGS := -DLOG_TAG=\"qdlights\" -ifeq ($(LLVM_SA), true) - LOCAL_CFLAGS += --compile-and-analyze --analyzer-perf --analyzer-Werror -endif -LOCAL_CLANG := true -LOCAL_MODULE := lights.$(TARGET_BOARD_PLATFORM) -LOCAL_MODULE_TAGS := optional -LOCAL_VENDOR_MODULE := true - -include $(BUILD_SHARED_LIBRARY) diff --git a/liblight/NOTICE b/liblight/NOTICE deleted file mode 100644 index 7340b9e3..00000000 --- a/liblight/NOTICE +++ /dev/null @@ -1,190 +0,0 @@ - - Copyright (c) 2008, 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. - - 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. - - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - diff --git a/liblight/lights.c b/liblight/lights.c deleted file mode 100644 index e83be16f..00000000 --- a/liblight/lights.c +++ /dev/null @@ -1,382 +0,0 @@ -/* - * Copyright (C) 2014, 2017-2018 The Linux Foundation. All rights reserved. - * Not a contribution - * Copyright (C) 2008 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_NDEBUG 0 - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -#ifndef DEFAULT_LOW_PERSISTENCE_MODE_BRIGHTNESS -#define DEFAULT_LOW_PERSISTENCE_MODE_BRIGHTNESS 0x80 -#endif - -/******************************************************************************/ - -static pthread_once_t g_init = PTHREAD_ONCE_INIT; -static pthread_mutex_t g_lock = PTHREAD_MUTEX_INITIALIZER; -static struct light_state_t g_notification; -static struct light_state_t g_battery; -static int g_last_backlight_mode = BRIGHTNESS_MODE_USER; -static int g_attention = 0; -static bool g_has_persistence_node = false; - -char const*const RED_LED_FILE - = "/sys/class/leds/red/brightness"; - -char const*const GREEN_LED_FILE - = "/sys/class/leds/green/brightness"; - -char const*const BLUE_LED_FILE - = "/sys/class/leds/blue/brightness"; - -char const*const LCD_FILE - = "/sys/class/leds/lcd-backlight/brightness"; - -char const*const LCD_FILE2 - = "/sys/class/backlight/panel0-backlight/brightness"; - -char const*const BUTTON_FILE - = "/sys/class/leds/button-backlight/brightness"; - -char const*const RED_BLINK_FILE - = "/sys/class/leds/red/blink"; - -char const*const GREEN_BLINK_FILE - = "/sys/class/leds/green/blink"; - -char const*const BLUE_BLINK_FILE - = "/sys/class/leds/blue/blink"; - -char const*const PERSISTENCE_FILE - = "/sys/class/graphics/fb0/msm_fb_persist_mode"; - -/** - * device methods - */ - -void init_globals(void) -{ - // init the mutex - pthread_mutex_init(&g_lock, NULL); -} - -static int -write_int(char const* path, int value) -{ - int fd; - static int already_warned = 0; - - fd = open(path, O_RDWR); - if (fd >= 0) { - char buffer[20]; - int bytes = snprintf(buffer, sizeof(buffer), "%d\n", value); - ssize_t amt = write(fd, buffer, (size_t)bytes); - close(fd); - return amt == -1 ? -errno : 0; - } else { - if (already_warned == 0) { - ALOGE("write_int failed to open %s\n", path); - already_warned = 1; - } - return -errno; - } -} - -static int -is_lit(struct light_state_t const* state) -{ - return state->color & 0x00ffffff; -} - -static int -rgb_to_brightness(struct light_state_t const* state) -{ - int color = state->color & 0x00ffffff; - return ((77*((color>>16)&0x00ff)) - + (150*((color>>8)&0x00ff)) + (29*(color&0x00ff))) >> 8; -} - -static int -set_light_backlight(struct light_device_t* dev, - struct light_state_t const* state) -{ - int err = 0; - int brightness = rgb_to_brightness(state); - unsigned int lpEnabled = - state->brightnessMode == BRIGHTNESS_MODE_LOW_PERSISTENCE; - if(!dev) { - return -1; - } - - pthread_mutex_lock(&g_lock); - // Toggle low persistence mode state - bool persistence_mode = ((g_last_backlight_mode != state->brightnessMode && lpEnabled) || - (!lpEnabled && - g_last_backlight_mode == BRIGHTNESS_MODE_LOW_PERSISTENCE)); - bool cannot_handle_persistence = !g_has_persistence_node && persistence_mode; - if (g_has_persistence_node) { - if (persistence_mode) { - if ((err = write_int(PERSISTENCE_FILE, lpEnabled)) != 0) { - ALOGE("%s: Failed to write to %s: %s\n", __FUNCTION__, - PERSISTENCE_FILE, strerror(errno)); - } - if (lpEnabled != 0) { - brightness = DEFAULT_LOW_PERSISTENCE_MODE_BRIGHTNESS; - } - } - g_last_backlight_mode = state->brightnessMode; - } - - if (!err) { - if (!access(LCD_FILE, F_OK)) { - err = write_int(LCD_FILE, brightness); - } else { - err = write_int(LCD_FILE2, brightness); - } - } - - pthread_mutex_unlock(&g_lock); - return cannot_handle_persistence ? -ENOSYS : err; -} - -static int -set_speaker_light_locked(struct light_device_t* dev, - struct light_state_t const* state) -{ - int red, green, blue; - int blink; - int onMS, offMS; - unsigned int colorRGB; - - if(!dev) { - return -1; - } - - switch (state->flashMode) { - case LIGHT_FLASH_TIMED: - onMS = state->flashOnMS; - offMS = state->flashOffMS; - break; - case LIGHT_FLASH_NONE: - default: - onMS = 0; - offMS = 0; - break; - } - - colorRGB = state->color; - -#if 0 - ALOGD("set_speaker_light_locked mode %d, colorRGB=%08X, onMS=%d, offMS=%d\n", - state->flashMode, colorRGB, onMS, offMS); -#endif - - red = (colorRGB >> 16) & 0xFF; - green = (colorRGB >> 8) & 0xFF; - blue = colorRGB & 0xFF; - - if (onMS > 0 && offMS > 0) { - /* - * if ON time == OFF time - * use blink mode 2 - * else - * use blink mode 1 - */ - if (onMS == offMS) - blink = 2; - else - blink = 1; - } else { - blink = 0; - } - - if (blink) { - if (red) { - if (write_int(RED_BLINK_FILE, blink)) - write_int(RED_LED_FILE, 0); - } - if (green) { - if (write_int(GREEN_BLINK_FILE, blink)) - write_int(GREEN_LED_FILE, 0); - } - if (blue) { - if (write_int(BLUE_BLINK_FILE, blink)) - write_int(BLUE_LED_FILE, 0); - } - } else { - write_int(RED_LED_FILE, red); - write_int(GREEN_LED_FILE, green); - write_int(BLUE_LED_FILE, blue); - } - - return 0; -} - -static void -handle_speaker_battery_locked(struct light_device_t* dev) -{ - if (is_lit(&g_battery)) { - set_speaker_light_locked(dev, &g_battery); - } else { - set_speaker_light_locked(dev, &g_notification); - } -} - -static int -set_light_battery(struct light_device_t* dev, - struct light_state_t const* state) -{ - pthread_mutex_lock(&g_lock); - g_battery = *state; - handle_speaker_battery_locked(dev); - pthread_mutex_unlock(&g_lock); - return 0; -} - -static int -set_light_notifications(struct light_device_t* dev, - struct light_state_t const* state) -{ - pthread_mutex_lock(&g_lock); - g_notification = *state; - handle_speaker_battery_locked(dev); - pthread_mutex_unlock(&g_lock); - return 0; -} - -static int -set_light_attention(struct light_device_t* dev, - struct light_state_t const* state) -{ - pthread_mutex_lock(&g_lock); - if (state->flashMode == LIGHT_FLASH_HARDWARE) { - g_attention = state->flashOnMS; - } else if (state->flashMode == LIGHT_FLASH_NONE) { - g_attention = 0; - } - handle_speaker_battery_locked(dev); - pthread_mutex_unlock(&g_lock); - return 0; -} - -static int -set_light_buttons(struct light_device_t* dev, - struct light_state_t const* state) -{ - int err = 0; - if(!dev) { - return -1; - } - pthread_mutex_lock(&g_lock); - err = write_int(BUTTON_FILE, state->color & 0xFF); - pthread_mutex_unlock(&g_lock); - return err; -} - -/** Close the lights device */ -static int -close_lights(struct light_device_t *dev) -{ - if (dev) { - free(dev); - } - return 0; -} - - -/******************************************************************************/ - -/** - * module methods - */ - -/** Open a new instance of a lights device using name */ -static int open_lights(const struct hw_module_t* module, char const* name, - struct hw_device_t** device) -{ - int (*set_light)(struct light_device_t* dev, - struct light_state_t const* state); - - if (0 == strcmp(LIGHT_ID_BACKLIGHT, name)) { - g_has_persistence_node = !access(PERSISTENCE_FILE, F_OK); - set_light = set_light_backlight; - } else if (0 == strcmp(LIGHT_ID_BATTERY, name)) - set_light = set_light_battery; - else if (0 == strcmp(LIGHT_ID_NOTIFICATIONS, name)) - set_light = set_light_notifications; - else if (0 == strcmp(LIGHT_ID_BUTTONS, name)) { - if (!access(BUTTON_FILE, F_OK)) { - // enable light button when the file is present - set_light = set_light_buttons; - } else { - return -EINVAL; - } - } - else if (0 == strcmp(LIGHT_ID_ATTENTION, name)) - set_light = set_light_attention; - else - return -EINVAL; - - pthread_once(&g_init, init_globals); - - struct light_device_t *dev = malloc(sizeof(struct light_device_t)); - - if(!dev) - return -ENOMEM; - - memset(dev, 0, sizeof(*dev)); - - dev->common.tag = HARDWARE_DEVICE_TAG; - dev->common.version = LIGHTS_DEVICE_API_VERSION_2_0; - dev->common.module = (struct hw_module_t*)module; - dev->common.close = (int (*)(struct hw_device_t*))close_lights; - dev->set_light = set_light; - - *device = (struct hw_device_t*)dev; - return 0; -} - -static struct hw_module_methods_t lights_module_methods = { - .open = open_lights, -}; - -/* - * The lights Module - */ -struct hw_module_t HAL_MODULE_INFO_SYM = { - .tag = HARDWARE_MODULE_TAG, - .version_major = 1, - .version_minor = 0, - .id = LIGHTS_HARDWARE_MODULE_ID, - .name = "lights Module", - .author = "Google, Inc.", - .methods = &lights_module_methods, -}; diff --git a/libmemtrack/Android.mk b/libmemtrack/Android.mk deleted file mode 100644 index 10fd40a9..00000000 --- a/libmemtrack/Android.mk +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (C) 2013 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. - -LOCAL_PATH := $(call my-dir) - -# HAL module implemenation stored in -# hw/..so -include $(CLEAR_VARS) - -LOCAL_MODULE_RELATIVE_PATH := hw -LOCAL_VENDOR_MODULE := true -LOCAL_C_INCLUDES += hardware/libhardware/include -LOCAL_CFLAGS := -Wconversion -Wall -Werror -Wno-sign-conversion -LOCAL_CLANG := true -LOCAL_SHARED_LIBRARIES := liblog -LOCAL_HEADER_LIBRARIES := libhardware_headers -LOCAL_SRC_FILES := memtrack_msm.c kgsl.c -LOCAL_MODULE := memtrack.$(TARGET_BOARD_PLATFORM) -include $(BUILD_SHARED_LIBRARY) diff --git a/libmemtrack/kgsl.c b/libmemtrack/kgsl.c deleted file mode 100644 index 69ee9018..00000000 --- a/libmemtrack/kgsl.c +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (C) 2013 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. - */ - -#include -#include -#include -#include -#include - -#include - -#include "memtrack_msm.h" - -#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) -#define min(x, y) ((x) < (y) ? (x) : (y)) - -struct memtrack_record record_templates[] = { - { - .flags = MEMTRACK_FLAG_SMAPS_ACCOUNTED | - MEMTRACK_FLAG_PRIVATE | - MEMTRACK_FLAG_NONSECURE, - }, - { - .flags = MEMTRACK_FLAG_SMAPS_UNACCOUNTED | - MEMTRACK_FLAG_PRIVATE | - MEMTRACK_FLAG_NONSECURE, - }, -}; - -int kgsl_memtrack_get_memory(pid_t pid, enum memtrack_type type, - struct memtrack_record *records, - size_t *num_records) -{ - size_t allocated_records = min(*num_records, ARRAY_SIZE(record_templates)); - FILE *fp; - char line[1024]; - char tmp[128]; - size_t accounted_size = 0; - size_t unaccounted_size = 0; - - *num_records = ARRAY_SIZE(record_templates); - - /* fastpath to return the necessary number of records */ - if (allocated_records == 0) { - return 0; - } - - memcpy(records, record_templates, - sizeof(struct memtrack_record) * allocated_records); - - snprintf(tmp, sizeof(tmp), "/d/kgsl/proc/%d/mem", pid); - fp = fopen(tmp, "r"); - if (fp == NULL) { - return -errno; - } - - /* Go through each line of /mem file and for every entry of type "gpumem" - * check if the gpubuffer entry is usermapped or not. If the entry is usermapped - * count the entry as accounted else count the entry as unaccounted. - */ - while (1) { - unsigned long size, mapsize; - char line_type[7]; - char flags[10]; - char line_usage[19]; - int ret, egl_surface_count = 0, egl_image_count = 0; - - if (fgets(line, sizeof(line), fp) == NULL) { - break; - } - - /* Format: - * gpuaddr useraddr size id flags type usage sglen mapsize eglsrf eglimg - * 545ba000 545ba000 4096 1 -----pY gpumem arraybuffer 1 4096 0 0 - */ - ret = sscanf(line, "%*x %*x %lu %*d %9s %6s %18s %*d %lu %6d %6d\n", - &size, flags, line_type, line_usage, &mapsize, - &egl_surface_count, &egl_image_count); - if (ret != 7) { - continue; - } - - if (size == 0) { - fclose(fp); - return -EINVAL; - } - - if (unaccounted_size + size < size) { - fclose(fp); - return -ERANGE; - } - - if (type == MEMTRACK_TYPE_GL && strcmp(line_type, "gpumem") == 0) { - - if (flags[6] == 'Y') { - if (accounted_size + mapsize < accounted_size) { - fclose(fp); - return -ERANGE; - } - - accounted_size += mapsize; - - if (mapsize > size) { - fclose(fp); - return -EINVAL; - } - unaccounted_size += size - mapsize; - } else { - unaccounted_size += size; - } - } else if (type == MEMTRACK_TYPE_GRAPHICS && strcmp(line_type, "ion") == 0) { - if (strcmp(line_usage, "egl_surface") == 0) { - unaccounted_size += size; - } - else if (egl_surface_count == 0) { - unaccounted_size += size / (egl_image_count ? egl_image_count : 1); - } - } - } - - if (allocated_records > 0) { - records[0].size_in_bytes = accounted_size; - } - if (allocated_records > 1) { - records[1].size_in_bytes = unaccounted_size; - } - - fclose(fp); - - return 0; -} diff --git a/libmemtrack/memtrack_msm.c b/libmemtrack/memtrack_msm.c deleted file mode 100644 index e369d5fd..00000000 --- a/libmemtrack/memtrack_msm.c +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2013 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. - */ - -#include - -#include - -#include "memtrack_msm.h" - -int msm_memtrack_init(const struct memtrack_module *module) -{ - if(!module) - return -1; - return 0; -} - -int msm_memtrack_get_memory(const struct memtrack_module *module, - pid_t pid, - int type, - struct memtrack_record *records, - size_t *num_records) -{ - if(!module) - return -1; - if (type == MEMTRACK_TYPE_GL || type == MEMTRACK_TYPE_GRAPHICS) { - return kgsl_memtrack_get_memory(pid, type, records, num_records); - } - - return -EINVAL; -} - -static struct hw_module_methods_t memtrack_module_methods = { - .open = NULL, -}; - -struct memtrack_module HAL_MODULE_INFO_SYM = { - .common = { - .tag = HARDWARE_MODULE_TAG, - .module_api_version = MEMTRACK_MODULE_API_VERSION_0_1, - .hal_api_version = HARDWARE_HAL_API_VERSION, - .id = MEMTRACK_HARDWARE_MODULE_ID, - .name = "MSM Memory Tracker HAL", - .author = "The Android Open Source Project", - .methods = &memtrack_module_methods, - }, - - .init = msm_memtrack_init, - .getMemory = msm_memtrack_get_memory, -}; - diff --git a/libmemtrack/memtrack_msm.h b/libmemtrack/memtrack_msm.h deleted file mode 100644 index 74aa5768..00000000 --- a/libmemtrack/memtrack_msm.h +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2013 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 _MEMTRACK_MSM_H_ -#define _MEMTRACK_MSM_H_ - -int kgsl_memtrack_get_memory(pid_t pid, enum memtrack_type type, - struct memtrack_record *records, - size_t *num_records); - -#endif diff --git a/libqdmetadata/Android.bp b/libqdmetadata/Android.bp new file mode 100644 index 00000000..fdf577f8 --- /dev/null +++ b/libqdmetadata/Android.bp @@ -0,0 +1,34 @@ +cc_library_shared { + name: "libqdMetaData", + vendor_available: true, + cflags: [ + "-Wno-sign-conversion", + "-DLOG_TAG=\"qdmetadata\"", + ], + shared_libs: [ + "liblog", + "libcutils", + "libutils", + ], + header_libs: ["libhardware_headers", "display_intf_headers"], + srcs: ["qdMetaData.cpp", "qd_utils.cpp"], + export_header_lib_headers: ["display_intf_headers"], +} + +// Remove after WFD moves to use libqdMetaData directly +cc_library_shared { + name: "libqdMetaData.system", + vendor_available: true, + cflags: [ + "-Wno-sign-conversion", + "-DLOG_TAG=\"qdmetadata\"", + ], + shared_libs: [ + "liblog", + "libcutils", + "libutils", + ], + header_libs: ["libhardware_headers", "display_intf_headers"], + srcs: ["qdMetaData.cpp", "qd_utils.cpp"], + export_header_lib_headers: ["display_intf_headers"], +} diff --git a/libqdutils/Makefile.am b/libqdmetadata/Makefile.am similarity index 100% rename from libqdutils/Makefile.am rename to libqdmetadata/Makefile.am diff --git a/libqdutils/qdMetaData.cpp b/libqdmetadata/qdMetaData.cpp similarity index 100% rename from libqdutils/qdMetaData.cpp rename to libqdmetadata/qdMetaData.cpp diff --git a/libqdutils/qdMetaData.h b/libqdmetadata/qdMetaData.h similarity index 100% rename from libqdutils/qdMetaData.h rename to libqdmetadata/qdMetaData.h diff --git a/libqdmetadata/qd_utils.cpp b/libqdmetadata/qd_utils.cpp new file mode 100644 index 00000000..108514b5 --- /dev/null +++ b/libqdmetadata/qd_utils.cpp @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2013, 2018 The Linux Foundation. All rights reserved. + + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include "qd_utils.h" + +static const int kFBNodeMax = 4; +namespace qdutils { + +static int getExternalNode(const char *type) { + FILE *displayDeviceFP = NULL; + char fbType[MAX_FRAME_BUFFER_NAME_SIZE]; + char msmFbTypePath[MAX_FRAME_BUFFER_NAME_SIZE]; + int j = 0; + + for(j = 0; j < kFBNodeMax; j++) { + snprintf (msmFbTypePath, sizeof(msmFbTypePath), + "/sys/devices/virtual/graphics/fb%d/msm_fb_type", j); + displayDeviceFP = fopen(msmFbTypePath, "r"); + if(displayDeviceFP) { + fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE, + displayDeviceFP); + if(strncmp(fbType, type, strlen(type)) == 0) { + ALOGD("%s: %s is at fb%d", __func__, type, j); + fclose(displayDeviceFP); + break; + } + fclose(displayDeviceFP); + } else { + ALOGE("%s: Failed to open fb node %s", __func__, msmFbTypePath); + } + } + + if (j < kFBNodeMax) + return j; + else + ALOGE("%s: Failed to find %s node", __func__, type); + + return -1; +} + +int getHDMINode(void) { + return getExternalNode("dtv panel"); +} + +int getEdidRawData(char *buffer) +{ + int size; + int edidFile; + char msmFbTypePath[MAX_FRAME_BUFFER_NAME_SIZE]; + int node_id = getHDMINode(); + + if (node_id < 0) { + ALOGE("%s no HDMI node found", __func__); + return 0; + } + + snprintf(msmFbTypePath, sizeof(msmFbTypePath), + "/sys/devices/virtual/graphics/fb%d/edid_raw_data", node_id); + + edidFile = open(msmFbTypePath, O_RDONLY, 0); + + if (edidFile < 0) { + ALOGE("%s no edid raw data found %s", __func__,msmFbTypePath); + return 0; + } + + size = (int)read(edidFile, (char*)buffer, EDID_RAW_DATA_SIZE); + close(edidFile); + return size; +} + +}; //namespace qdutils diff --git a/libqdutils/qd_utils.h b/libqdmetadata/qd_utils.h similarity index 100% rename from libqdutils/qd_utils.h rename to libqdmetadata/qd_utils.h diff --git a/libqdutils/Android.bp b/libqdutils/Android.bp deleted file mode 100644 index 0c1b96a1..00000000 --- a/libqdutils/Android.bp +++ /dev/null @@ -1,40 +0,0 @@ -cc_library_shared { - name: "libqdutils", - vendor: true, - defaults: ["display_defaults"], - header_libs: ["libhardware_headers", "libutils_headers"], - shared_libs: [ - "libbinder", - "libqservice", - ], - cflags: [ - "-DLOG_TAG=\"qdutils\"", - "-Wno-sign-conversion", - ], - srcs: [ - "qd_utils.cpp", - "display_config.cpp", - ], -} - -cc_library_shared { - name: "libqdMetaData", - vendor: true, - defaults: ["display_defaults"], - cflags: [ - "-Wno-sign-conversion", - "-DLOG_TAG=\"qdmetadata\"", - ], - srcs: ["qdMetaData.cpp","qd_utils.cpp"], -} - -// Remove after WFD moves to use libqdMetaData directly -cc_library_shared { - name: "libqdMetaData.system", - defaults: ["display_defaults"], - cflags: [ - "-Wno-sign-conversion", - "-DLOG_TAG=\"qdmetadata\"", - ], - srcs: ["qdMetaData.cpp","qd_utils.cpp"], -} diff --git a/libqdutils/display_config.cpp b/libqdutils/display_config.cpp deleted file mode 100644 index 87ca401e..00000000 --- a/libqdutils/display_config.cpp +++ /dev/null @@ -1,390 +0,0 @@ -/* -* Copyright (c) 2013-2014, 2016, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation. nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace android; -using namespace qService; - -namespace qdutils { - -//============================================================================= -// The functions below run in the client process and wherever necessary -// do a binder call to HWC to get/set data. - -int isExternalConnected(void) { - int ret; - status_t err = (status_t) FAILED_TRANSACTION; - sp binder = getBinder(); - Parcel inParcel, outParcel; - if(binder != NULL) { - err = binder->dispatch(IQService::CHECK_EXTERNAL_STATUS, - &inParcel , &outParcel); - } - if(err) { - ALOGE("%s: Failed to get external status err=%d", __FUNCTION__, err); - ret = err; - } else { - ret = outParcel.readInt32(); - } - return ret; -} - -int getDisplayAttributes(int dpy, DisplayAttributes_t& dpyattr) { - status_t err = (status_t) FAILED_TRANSACTION; - sp binder = getBinder(); - Parcel inParcel, outParcel; - inParcel.writeInt32(dpy); - if(binder != NULL) { - err = binder->dispatch(IQService::GET_DISPLAY_ATTRIBUTES, - &inParcel, &outParcel); - } - if(!err) { - dpyattr.vsync_period = outParcel.readInt32(); - dpyattr.xres = outParcel.readInt32(); - dpyattr.yres = outParcel.readInt32(); - dpyattr.xdpi = outParcel.readFloat(); - dpyattr.ydpi = outParcel.readFloat(); - dpyattr.panel_type = outParcel.readInt32(); - } else { - ALOGE("%s() failed with err %d", __FUNCTION__, err); - } - return err; -} - -int setHSIC(int dpy, const HSICData_t& hsic_data) { - status_t err = (status_t) FAILED_TRANSACTION; - sp binder = getBinder(); - Parcel inParcel, outParcel; - inParcel.writeInt32(dpy); - inParcel.writeInt32(hsic_data.hue); - inParcel.writeFloat(hsic_data.saturation); - inParcel.writeInt32(hsic_data.intensity); - inParcel.writeFloat(hsic_data.contrast); - if(binder != NULL) { - err = binder->dispatch(IQService::SET_HSIC_DATA, &inParcel, &outParcel); - } - if(err) - ALOGE("%s: Failed to get external status err=%d", __FUNCTION__, err); - return err; -} - -int getDisplayVisibleRegion(int dpy, hwc_rect_t &rect) { - status_t err = (status_t) FAILED_TRANSACTION; - sp binder = getBinder(); - Parcel inParcel, outParcel; - inParcel.writeInt32(dpy); - if(binder != NULL) { - err = binder->dispatch(IQService::GET_DISPLAY_VISIBLE_REGION, - &inParcel, &outParcel); - } - if(!err) { - rect.left = outParcel.readInt32(); - rect.top = outParcel.readInt32(); - rect.right = outParcel.readInt32(); - rect.bottom = outParcel.readInt32(); - } else { - ALOGE("%s: Failed to getVisibleRegion for dpy =%d: err = %d", - __FUNCTION__, dpy, err); - } - return err; -} - -int setViewFrame(int dpy, int l, int t, int r, int b) { - status_t err = (status_t) FAILED_TRANSACTION; - sp binder = getBinder(); - Parcel inParcel, outParcel; - inParcel.writeInt32(dpy); - inParcel.writeInt32(l); - inParcel.writeInt32(t); - inParcel.writeInt32(r); - inParcel.writeInt32(b); - - if(binder != NULL) { - err = binder->dispatch(IQService::SET_VIEW_FRAME, - &inParcel, &outParcel); - } - if(err) - ALOGE("%s: Failed to set view frame for dpy %d err=%d", - __FUNCTION__, dpy, err); - - return err; -} - -int setSecondaryDisplayStatus(int dpy, uint32_t status) { - status_t err = (status_t) FAILED_TRANSACTION; - sp binder = getBinder(); - Parcel inParcel, outParcel; - inParcel.writeInt32(dpy); - inParcel.writeInt32(status); - - if(binder != NULL) { - err = binder->dispatch(IQService::SET_SECONDARY_DISPLAY_STATUS, - &inParcel, &outParcel); - } - if(err) - ALOGE("%s: Failed for dpy %d status = %d err=%d", __FUNCTION__, dpy, - status, err); - - return err; -} - -int configureDynRefreshRate(uint32_t op, uint32_t refreshRate) { - status_t err = (status_t) FAILED_TRANSACTION; - sp binder = getBinder(); - Parcel inParcel, outParcel; - inParcel.writeInt32(op); - inParcel.writeInt32(refreshRate); - - if(binder != NULL) { - err = binder->dispatch(IQService::CONFIGURE_DYN_REFRESH_RATE, - &inParcel, &outParcel); - } - - if(err) - ALOGE("%s: Failed setting op %d err=%d", __FUNCTION__, op, err); - - return err; -} - -int getConfigCount(int /*dpy*/) { - int numConfigs = -1; - sp binder = getBinder(); - if(binder != NULL) { - Parcel inParcel, outParcel; - inParcel.writeInt32(DISPLAY_PRIMARY); - status_t err = binder->dispatch(IQService::GET_CONFIG_COUNT, - &inParcel, &outParcel); - if(!err) { - numConfigs = outParcel.readInt32(); - ALOGI("%s() Received num configs %d", __FUNCTION__, numConfigs); - } else { - ALOGE("%s() failed with err %d", __FUNCTION__, err); - } - } - return numConfigs; -} - -int getActiveConfig(int dpy) { - int configIndex = -1; - sp binder = getBinder(); - if(binder != NULL) { - Parcel inParcel, outParcel; - inParcel.writeInt32(dpy); - status_t err = binder->dispatch(IQService::GET_ACTIVE_CONFIG, - &inParcel, &outParcel); - if(!err) { - configIndex = outParcel.readInt32(); - ALOGI("%s() Received active config index %d", __FUNCTION__, - configIndex); - } else { - ALOGE("%s() failed with err %d", __FUNCTION__, err); - } - } - return configIndex; -} - -int setActiveConfig(int configIndex, int /*dpy*/) { - status_t err = (status_t) FAILED_TRANSACTION; - sp binder = getBinder(); - if(binder != NULL) { - Parcel inParcel, outParcel; - inParcel.writeInt32(configIndex); - inParcel.writeInt32(DISPLAY_PRIMARY); - err = binder->dispatch(IQService::SET_ACTIVE_CONFIG, - &inParcel, &outParcel); - if(!err) { - ALOGI("%s() Successfully set active config index %d", __FUNCTION__, - configIndex); - } else { - ALOGE("%s() failed with err %d", __FUNCTION__, err); - } - } - return err; -} - -DisplayAttributes getDisplayAttributes(int configIndex, int dpy) { - DisplayAttributes dpyattr = {}; - sp binder = getBinder(); - if(binder != NULL) { - Parcel inParcel, outParcel; - inParcel.writeInt32(configIndex); - inParcel.writeInt32(dpy); - status_t err = binder->dispatch( - IQService::GET_DISPLAY_ATTRIBUTES_FOR_CONFIG, &inParcel, - &outParcel); - if(!err) { - dpyattr.vsync_period = outParcel.readInt32(); - dpyattr.xres = outParcel.readInt32(); - dpyattr.yres = outParcel.readInt32(); - dpyattr.xdpi = outParcel.readFloat(); - dpyattr.ydpi = outParcel.readFloat(); - dpyattr.panel_type = outParcel.readInt32(); - dpyattr.is_yuv = outParcel.readInt32(); - ALOGI("%s() Received attrs for index %d: xres %d, yres %d", - __FUNCTION__, configIndex, dpyattr.xres, dpyattr.yres); - } else { - ALOGE("%s() failed with err %d", __FUNCTION__, err); - } - } - return dpyattr; -} - -int setPanelMode(int mode) { - status_t err = (status_t) FAILED_TRANSACTION; - sp binder = getBinder(); - if(binder != NULL) { - Parcel inParcel, outParcel; - inParcel.writeInt32(mode); - err = binder->dispatch(IQService::SET_DISPLAY_MODE, - &inParcel, &outParcel); - if(!err) { - ALOGI("%s() Successfully set the display mode to %d", __FUNCTION__, - mode); - } else { - ALOGE("%s() failed with err %d", __FUNCTION__, err); - } - } - return err; -} - -int setPanelBrightness(int level) { - status_t err = (status_t) FAILED_TRANSACTION; - sp binder = getBinder(); - Parcel inParcel, outParcel; - - if(binder != NULL) { - inParcel.writeInt32(level); - status_t err = binder->dispatch(IQService::SET_PANEL_BRIGHTNESS, - &inParcel, &outParcel); - if(err) { - ALOGE("%s() failed with err %d", __FUNCTION__, err); - } - } - return err; -} - -int getPanelBrightness() { - int panel_brightness = -1; - sp binder = getBinder(); - Parcel inParcel, outParcel; - - if(binder != NULL) { - status_t err = binder->dispatch(IQService::GET_PANEL_BRIGHTNESS, - &inParcel, &outParcel); - if(!err) { - panel_brightness = outParcel.readInt32(); - ALOGI("%s() Current panel brightness value %d", __FUNCTION__, - panel_brightness); - } else { - ALOGE("%s() failed with err %d", __FUNCTION__, err); - } - } - return panel_brightness; -} - -}// namespace - -// ---------------------------------------------------------------------------- -// Functions for linking dynamically to libqdutils -// ---------------------------------------------------------------------------- -extern "C" int minHdcpEncryptionLevelChanged(int dpy, int min_enc_level) { - status_t err = (status_t) FAILED_TRANSACTION; - sp binder = getBinder(); - Parcel inParcel, outParcel; - inParcel.writeInt32(dpy); - inParcel.writeInt32(min_enc_level); - - if(binder != NULL) { - err = binder->dispatch(IQService::MIN_HDCP_ENCRYPTION_LEVEL_CHANGED, - &inParcel, &outParcel); - } - - if(err) { - ALOGE("%s: Failed for dpy %d err=%d", __FUNCTION__, dpy, err); - } else { - err = outParcel.readInt32(); - } - - return err; -} - -extern "C" int refreshScreen() { - int ret = 0; - ret = screenRefresh(); - return ret; -} - -extern "C" int controlPartialUpdate(int dpy, int mode) { - status_t err = (status_t) FAILED_TRANSACTION; - sp binder = getBinder(); - if(binder != NULL) { - Parcel inParcel, outParcel; - inParcel.writeInt32(dpy); - inParcel.writeInt32(mode); - err = binder->dispatch(IQService::CONTROL_PARTIAL_UPDATE, &inParcel, &outParcel); - if(err != 0) { - ALOGE_IF(getBinder(), "%s() failed with err %d", __FUNCTION__, err); - } else { - return outParcel.readInt32(); - } - } - - return err; -} - -// returns 0 if composer is up -extern "C" int waitForComposerInit() { - int status = false; - sp binder = getBinder(); - if (binder == NULL) { - sleep(2); - binder = getBinder(); - } - - if (binder != NULL) { - Parcel inParcel, outParcel; - binder->dispatch(IQService::GET_COMPOSER_STATUS, &inParcel, &outParcel); - status = !!outParcel.readInt32(); - if (!status) { - sleep(2); - binder->dispatch(IQService::GET_COMPOSER_STATUS, &inParcel, &outParcel); - status = !!outParcel.readInt32(); - } - } - - return !status; -} diff --git a/libqdutils/display_config.h b/libqdutils/display_config.h deleted file mode 100644 index c6926990..00000000 --- a/libqdutils/display_config.h +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (c) 2013 - 2016 The Linux Foundation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of The Linux Foundation. nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _DISPLAY_CONFIG_H -#define _DISPLAY_CONFIG_H - -#include -#include -#include - -// This header is for clients to use to set/get global display configuration. -// Only primary and external displays are supported here. - -namespace qdutils { - - -/* TODO: Have all the common enums that need be exposed to clients and which - * are also needed in hwc defined here. Remove such definitions we have in - * hwc_utils.h - */ - -// Use this enum to specify the dpy parameters where needed -enum { - DISPLAY_PRIMARY = HWC_DISPLAY_PRIMARY, - DISPLAY_EXTERNAL = HWC_DISPLAY_EXTERNAL, -#ifdef QTI_BSP - DISPLAY_TERTIARY = HWC_DISPLAY_TERTIARY, -#endif - DISPLAY_VIRTUAL = HWC_DISPLAY_VIRTUAL, -}; - -// External Display states - used in setSecondaryDisplayStatus() -// To be consistent with the same defined in hwc_utils.h -enum { - EXTERNAL_OFFLINE = 0, - EXTERNAL_ONLINE, - EXTERNAL_PAUSE, - EXTERNAL_RESUME, -}; - -enum { - DISABLE_METADATA_DYN_REFRESH_RATE = 0, - ENABLE_METADATA_DYN_REFRESH_RATE, - SET_BINDER_DYN_REFRESH_RATE, -}; - -enum { - DEFAULT_MODE = 0, - VIDEO_MODE, - COMMAND_MODE, -}; - -enum { - DISPLAY_PORT_DEFAULT = 0, - DISPLAY_PORT_DSI, - DISPLAY_PORT_DTV, - DISPLAY_PORT_WRITEBACK, - DISPLAY_PORT_LVDS, - DISPLAY_PORT_EDP, - DISPLAY_PORT_DP, -}; - -// Display Attributes that are available to clients of this library -// Not to be confused with a similar struct in hwc_utils (in the hwc namespace) -typedef struct DisplayAttributes { - uint32_t vsync_period = 0; //nanoseconds - uint32_t xres = 0; - uint32_t yres = 0; - float xdpi = 0.0f; - float ydpi = 0.0f; - int panel_type = DISPLAY_PORT_DEFAULT; - bool is_yuv = false; -} DisplayAttributes_t; - -//============================================================================= -// The functions below run in the client process and wherever necessary -// do a binder call to HWC to get/set data. - -// Check if external display is connected. Useful to check before making -// calls for external displays -// Returns 1 if connected, 0 if disconnected, negative values on errors -int isExternalConnected(void); - -// Get display vsync period which is in nanoseconds -// i.e vsync_period = 1000000000l / fps -// Returns 0 on success, negative values on errors -int getDisplayAttributes(int dpy, DisplayAttributes_t& dpyattr); - -// Set HSIC data on a given display ID -// Returns 0 on success, negative values on errors -int setHSIC(int dpy, const HSICData_t& hsic_data); - -// get the active visible region for the display -// Returns 0 on success, negative values on errors -int getDisplayVisibleRegion(int dpy, hwc_rect_t &rect); - -// set the view frame information in hwc context from surfaceflinger -int setViewFrame(int dpy, int l, int t, int r, int b); - -// Set the secondary display status(pause/resume/offline etc.,) -int setSecondaryDisplayStatus(int dpy, uint32_t status); - -// Enable/Disable/Set refresh rate dynamically -int configureDynRefreshRate(uint32_t op, uint32_t refreshRate); - -// Returns the number of configs supported for the display on success. -// Returns -1 on error. -// Only primary display supported for now, value of dpy ignored. -int getConfigCount(int dpy); - -// Returns the index of config that is current set for the display on success. -// Returns -1 on error. -// Only primary display supported for now, value of dpy ignored. -int getActiveConfig(int dpy); - -// Sets the config for the display on success and returns 0. -// Returns -1 on error. -// Only primary display supported for now, value of dpy ignored -int setActiveConfig(int configIndex, int dpy); - -// Returns the attributes for the specified config for the display on success. -// Returns xres and yres as 0 on error. -// Only primary display supported for now, value of dpy ignored -DisplayAttributes getDisplayAttributes(int configIndex, int dpy); - -// Set the primary display mode to command or video mode -int setDisplayMode(int mode); - -// Sets the panel brightness of the primary display -int setPanelBrightness(int level); - -// Retrieves the current panel brightness value -int getPanelBrightness(); - -}; //namespace - - -extern "C" int waitForComposerInit(); -#endif diff --git a/libqdutils/qd_utils.cpp b/libqdutils/qd_utils.cpp deleted file mode 100644 index e1afd7c5..00000000 --- a/libqdutils/qd_utils.cpp +++ /dev/null @@ -1,365 +0,0 @@ -/* - * Copyright (c) 2013, 2018 The Linux Foundation. All rights reserved. - - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of The Linux Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include "qd_utils.h" - -static const int kFBNodeMax = 4; -namespace qdutils { - -static int parseLine(char *input, char *tokens[], const uint32_t maxToken, uint32_t *count) { - char *tmpToken = NULL; - char *tmpPtr; - uint32_t index = 0; - const char *delim = ", =\n"; - if (!input) { - return -1; - } - tmpToken = strtok_r(input, delim, &tmpPtr); - while (tmpToken && index < maxToken) { - tokens[index++] = tmpToken; - tmpToken = strtok_r(NULL, delim, &tmpPtr); - } - *count = index; - - return 0; -} - -static int getExternalNode(const char *type) { - FILE *displayDeviceFP = NULL; - char fbType[MAX_FRAME_BUFFER_NAME_SIZE]; - char msmFbTypePath[MAX_FRAME_BUFFER_NAME_SIZE]; - int j = 0; - - for(j = 0; j < kFBNodeMax; j++) { - snprintf (msmFbTypePath, sizeof(msmFbTypePath), - "/sys/devices/virtual/graphics/fb%d/msm_fb_type", j); - displayDeviceFP = fopen(msmFbTypePath, "r"); - if(displayDeviceFP) { - fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE, - displayDeviceFP); - if(strncmp(fbType, type, strlen(type)) == 0) { - ALOGD("%s: %s is at fb%d", __func__, type, j); - fclose(displayDeviceFP); - break; - } - fclose(displayDeviceFP); - } else { - ALOGE("%s: Failed to open fb node %s", __func__, msmFbTypePath); - } - } - - if (j < kFBNodeMax) - return j; - else - ALOGE("%s: Failed to find %s node", __func__, type); - - return -1; -} - -static int querySDEInfoDRM(HWQueryType type, int *value) { - char property[PROPERTY_VALUE_MAX] = {0}; - - // TODO(user): If future targets don't support WB UBWC, add separate - // properties in target specific system.prop and have clients like WFD - // directly rely on those. - switch(type) { - case HAS_UBWC: - case HAS_WB_UBWC: // WFD stack still uses this - *value = 1; - property_get(DISABLE_UBWC_PROP, property, "0"); - if(!(strncmp(property, "1", PROPERTY_VALUE_MAX)) || - !(strncmp(property, "true", PROPERTY_VALUE_MAX))) { - *value = 0; - } - break; - default: - ALOGE("Invalid query type %d", type); - return -EINVAL; - } - - return 0; -} - -static int querySDEInfoFB(HWQueryType type, int *value) { - FILE *fileptr = NULL; - const char *featureName; - char stringBuffer[MAX_STRING_LENGTH]; - uint32_t tokenCount = 0; - const uint32_t maxCount = 10; - char *tokens[maxCount] = { NULL }; - - switch(type) { - case HAS_UBWC: - featureName = "ubwc"; - break; - case HAS_WB_UBWC: - featureName = "wb_ubwc"; - break; - default: - ALOGE("Invalid query type %d", type); - return -EINVAL; - } - - fileptr = fopen("/sys/devices/virtual/graphics/fb0/mdp/caps", "rb"); - if (!fileptr) { - ALOGE("File '%s' not found", stringBuffer); - return -EINVAL; - } - - size_t len = MAX_STRING_LENGTH; - ssize_t read; - char *line = stringBuffer; - while ((read = getline(&line, &len, fileptr)) != -1) { - // parse the line and update information accordingly - if (parseLine(line, tokens, maxCount, &tokenCount)) { - continue; - } - - if (strncmp(tokens[0], "features", strlen("features"))) { - continue; - } - - for (uint32_t i = 0; i < tokenCount; i++) { - if (!strncmp(tokens[i], featureName, strlen(featureName))) { - *value = 1; - } - } - } - fclose(fileptr); - - return 0; -} - -int querySDEInfo(HWQueryType type, int *value) { - if (!value) { - return -EINVAL; - } - - if (getDriverType() == DriverType::DRM) { - return querySDEInfoDRM(type, value); - } - - return querySDEInfoFB(type, value); -} - -int getHDMINode(void) { - return getExternalNode("dtv panel"); -} - -int getEdidRawData(char *buffer) -{ - int size; - int edidFile; - char msmFbTypePath[MAX_FRAME_BUFFER_NAME_SIZE]; - int node_id = getHDMINode(); - - if (node_id < 0) { - ALOGE("%s no HDMI node found", __func__); - return 0; - } - - snprintf(msmFbTypePath, sizeof(msmFbTypePath), - "/sys/devices/virtual/graphics/fb%d/edid_raw_data", node_id); - - edidFile = open(msmFbTypePath, O_RDONLY, 0); - - if (edidFile < 0) { - ALOGE("%s no edid raw data found %s", __func__,msmFbTypePath); - return 0; - } - - size = (int)read(edidFile, (char*)buffer, EDID_RAW_DATA_SIZE); - close(edidFile); - return size; -} - -bool isDPConnected() { - char connectPath[MAX_FRAME_BUFFER_NAME_SIZE]; - FILE *connectFile = NULL; - size_t len = MAX_STRING_LENGTH; - char stringBuffer[MAX_STRING_LENGTH]; - char *line = stringBuffer; - - int nodeId = getExternalNode("dp panel"); - if (nodeId < 0) { - ALOGE("%s no DP node found", __func__); - return false; - } - - snprintf(connectPath, sizeof(connectPath), - "/sys/devices/virtual/graphics/fb%d/connected", nodeId); - - connectFile = fopen(connectPath, "rb"); - if (!connectFile) { - ALOGW("Failed to open connect node for device node %s", connectPath); - return false; - } - - if (getline(&line, &len, connectFile) < 0) { - fclose(connectFile); - return false; - } - - fclose(connectFile); - - return atoi(line); -} - -int getDPTestConfig(uint32_t *panelBpp, uint32_t *patternType) { - if (!panelBpp || !patternType) { - return -1; - } - - char configPath[MAX_FRAME_BUFFER_NAME_SIZE]; - FILE *configFile = NULL; - uint32_t tokenCount = 0; - const uint32_t maxCount = 10; - char *tokens[maxCount] = { NULL }; - size_t len = MAX_STRING_LENGTH; - char stringBuffer[MAX_STRING_LENGTH]; - char *line = stringBuffer; - - int nodeId = getExternalNode("dp panel"); - if (nodeId < 0) { - ALOGE("%s no DP node found", __func__); - return -EINVAL; - } - - snprintf(configPath, sizeof(configPath), - "/sys/devices/virtual/graphics/fb%d/config", nodeId); - - configFile = fopen(configPath, "rb"); - if (!configFile) { - ALOGW("Failed to open config node for device node %s", configPath); - return -EINVAL; - } - - while (getline(&line, &len, configFile) != -1) { - if (!parseLine(line, tokens, maxCount, &tokenCount)) { - if (tokens[0] != NULL) { - if (!strncmp(tokens[0], "bpp", strlen("bpp"))) { - *panelBpp = static_cast(atoi(tokens[1])); - } else if (!strncmp(tokens[0], "pattern", strlen("pattern"))) { - *patternType = static_cast(atoi(tokens[1])); - } - } - } - } - - fclose(configFile); - - return 0; -} - -DriverType getDriverType() { - const char *fb_caps = "/sys/devices/virtual/graphics/fb0/mdp/caps"; - // 0 - File exists - return access(fb_caps, F_OK) ? DriverType::DRM : DriverType::FB; -} - -const char *GetHALPixelFormatString(int format) { - switch (format) { - case HAL_PIXEL_FORMAT_RGBA_8888: - return "RGBA_8888"; - case HAL_PIXEL_FORMAT_RGBX_8888: - return "RGBX_8888"; - case HAL_PIXEL_FORMAT_RGB_888: - return "RGB_888"; - case HAL_PIXEL_FORMAT_RGB_565: - return "RGB_565"; - case HAL_PIXEL_FORMAT_BGR_565: - return "BGR_565"; - case HAL_PIXEL_FORMAT_BGRA_8888: - return "BGRA_8888"; - case HAL_PIXEL_FORMAT_RGBA_5551: - return "RGBA_5551"; - case HAL_PIXEL_FORMAT_RGBA_4444: - return "RGBA_4444"; - case HAL_PIXEL_FORMAT_YV12: - return "YV12"; - case HAL_PIXEL_FORMAT_YCbCr_422_SP: - return "YCbCr_422_SP_NV16"; - case HAL_PIXEL_FORMAT_YCrCb_420_SP: - return "YCrCb_420_SP_NV21"; - case HAL_PIXEL_FORMAT_YCbCr_422_I: - return "YCbCr_422_I_YUY2"; - case HAL_PIXEL_FORMAT_YCrCb_422_I: - return "YCrCb_422_I_YVYU"; - case HAL_PIXEL_FORMAT_NV12_ENCODEABLE: - return "NV12_ENCODEABLE"; - case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED: - return "YCbCr_420_SP_TILED_TILE_4x2"; - case HAL_PIXEL_FORMAT_YCbCr_420_SP: - return "YCbCr_420_SP"; - case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO: - return "YCrCb_420_SP_ADRENO"; - case HAL_PIXEL_FORMAT_YCrCb_422_SP: - return "YCrCb_422_SP"; - case HAL_PIXEL_FORMAT_R_8: - return "R_8"; - case HAL_PIXEL_FORMAT_RG_88: - return "RG_88"; - case HAL_PIXEL_FORMAT_INTERLACE: - return "INTERLACE"; - case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS: - return "YCbCr_420_SP_VENUS"; - case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS: - return "YCrCb_420_SP_VENUS"; - case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC: - return "YCbCr_420_SP_VENUS_UBWC"; - case HAL_PIXEL_FORMAT_RGBA_1010102: - return "RGBA_1010102"; - case HAL_PIXEL_FORMAT_ARGB_2101010: - return "ARGB_2101010"; - case HAL_PIXEL_FORMAT_RGBX_1010102: - return "RGBX_1010102"; - case HAL_PIXEL_FORMAT_XRGB_2101010: - return "XRGB_2101010"; - case HAL_PIXEL_FORMAT_BGRA_1010102: - return "BGRA_1010102"; - case HAL_PIXEL_FORMAT_ABGR_2101010: - return "ABGR_2101010"; - case HAL_PIXEL_FORMAT_BGRX_1010102: - return "BGRX_1010102"; - case HAL_PIXEL_FORMAT_XBGR_2101010: - return "XBGR_2101010"; - case HAL_PIXEL_FORMAT_YCbCr_420_P010: - return "YCbCr_420_P010"; - case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC: - return "YCbCr_420_TP10_UBWC"; - case HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS: - return "YCbCr_420_P010_VENUS"; - default: - return "Unknown_format"; - } -} - -}; //namespace qdutils diff --git a/libqservice/Android.bp b/libqservice/Android.bp deleted file mode 100644 index fe69d393..00000000 --- a/libqservice/Android.bp +++ /dev/null @@ -1,16 +0,0 @@ -cc_library_shared { - name: "libqservice", - vendor: true, - defaults: ["display_defaults"], - shared_libs: ["libbinder"], - cflags: [ - "-DLOG_TAG=\"qdqservice\"", - "-Wno-sign-conversion", - ], - srcs: [ - "QService.cpp", - "IQService.cpp", - "IQClient.cpp", - "IQHDMIClient.cpp", - ], -} diff --git a/libqservice/IQClient.cpp b/libqservice/IQClient.cpp deleted file mode 100644 index a6251c88..00000000 --- a/libqservice/IQClient.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * Copyright (C) 2012-2013, The Linux Foundation. All rights reserved. - * - * Not a Contribution, Apache license notifications and license are - * retained for attribution purposes only. - - * 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 -#include -#include -#include -#include -#include - -using namespace android; - -// --------------------------------------------------------------------------- -// XXX: Since qservice currently runs as part of hwc instead of a standalone -// process, the implementation below is overridden and the notifyCallback in -// hwc_qclient is directly called. - -namespace qClient { - -enum { - NOTIFY_CALLBACK = IBinder::FIRST_CALL_TRANSACTION, -}; - -class BpQClient : public BpInterface -{ -public: - BpQClient(const sp& impl) - : BpInterface(impl) {} - - virtual status_t notifyCallback(uint32_t command, - const Parcel* inParcel, - Parcel* outParcel) { - Parcel data; - Parcel *reply = outParcel; - data.writeInterfaceToken(IQClient::getInterfaceDescriptor()); - data.writeInt32(command); - if (inParcel->dataAvail()) - data.appendFrom(inParcel, inParcel->dataPosition(), - inParcel->dataAvail()); - status_t result = remote()->transact(NOTIFY_CALLBACK, data, reply); - return result; - } -}; - -IMPLEMENT_META_INTERFACE(QClient, "android.display.IQClient"); - -// ---------------------------------------------------------------------- -//Stub implementation - nothing needed here -status_t BnQClient::onTransact( - uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) -{ - switch(code) { - case NOTIFY_CALLBACK: { - CHECK_INTERFACE(IQClient, data, reply); - uint32_t command = data.readInt32(); - notifyCallback(command, &data, reply); - return NO_ERROR; - } break; - default: - return BBinder::onTransact(code, data, reply, flags); - } - -} - -}; // namespace qClient diff --git a/libqservice/IQClient.h b/libqservice/IQClient.h deleted file mode 100644 index 7d816d28..00000000 --- a/libqservice/IQClient.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * Copyright (C) 2012-2013, The Linux Foundation. All rights reserved. - * - * Not a Contribution, Apache license notifications and license are - * retained for attribution purposes only. - - * 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_IQCLIENT_H -#define ANDROID_IQCLIENT_H - -#include -#include -#include -#include -#include - -namespace qClient { -// ---------------------------------------------------------------------------- -class IQClient : public android::IInterface -{ -public: - DECLARE_META_INTERFACE(QClient); - virtual android::status_t notifyCallback(uint32_t command, - const android::Parcel* inParcel, - android::Parcel* outParcel) = 0; -}; - -// ---------------------------------------------------------------------------- - -class BnQClient : public android::BnInterface -{ -public: - virtual android::status_t onTransact( uint32_t code, - const android::Parcel& data, - android::Parcel* reply, - uint32_t flags = 0); -}; - -// ---------------------------------------------------------------------------- -}; // namespace qClient - -#endif // ANDROID_IQCLIENT_H diff --git a/libqservice/IQHDMIClient.cpp b/libqservice/IQHDMIClient.cpp deleted file mode 100644 index 6379e574..00000000 --- a/libqservice/IQHDMIClient.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* -* Copyright (c) 2014 The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation. nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ -#include -#include -#include "IQHDMIClient.h" - -using namespace android; -namespace qClient { - -enum { - HDMI_CONNECTED = IBinder::FIRST_CALL_TRANSACTION, - CEC_MESSAGE_RECEIVED -}; - -class BpQHDMIClient : public BpInterface -{ -public: - BpQHDMIClient(const sp& impl) - :BpInterface(impl) - { - } - - void onHdmiHotplug(int connected) - { - Parcel data, reply; - data.writeInterfaceToken(IQHDMIClient::getInterfaceDescriptor()); - data.writeInt32(connected); - remote()->transact(HDMI_CONNECTED, data, &reply, IBinder::FLAG_ONEWAY); - } - - void onCECMessageRecieved(char *msg, ssize_t len) - { - Parcel data, reply; - data.writeInterfaceToken(IQHDMIClient::getInterfaceDescriptor()); - data.writeInt32((int32_t)len); - void *buf = data.writeInplace(len); - if (buf != NULL) - memcpy(buf, msg, len); - remote()->transact(CEC_MESSAGE_RECEIVED, data, &reply, - IBinder::FLAG_ONEWAY); - } -}; - -IMPLEMENT_META_INTERFACE(QHDMIClient, - "android.display.IQHDMIClient"); - -status_t BnQHDMIClient::onTransact(uint32_t code, const Parcel& data, - Parcel* reply, uint32_t flags) -{ - switch(code) { - case HDMI_CONNECTED: { - CHECK_INTERFACE(IQHDMIClient, data, reply); - int connected = data.readInt32(); - onHdmiHotplug(connected); - return NO_ERROR; - } - case CEC_MESSAGE_RECEIVED: { - CHECK_INTERFACE(IQHDMIClient, data, reply); - ssize_t len = data.readInt32(); - const void* msg; - if(len >= 0 && len <= (ssize_t) data.dataAvail()) { - msg = data.readInplace(len); - } else { - msg = NULL; - len = 0; - } - if (msg != NULL) - onCECMessageRecieved((char*) msg, len); - return NO_ERROR; - } - default: { - return BBinder::onTransact(code, data, reply, flags); - } - } -} - -}; //namespace qClient diff --git a/libqservice/IQHDMIClient.h b/libqservice/IQHDMIClient.h deleted file mode 100644 index c3d012a4..00000000 --- a/libqservice/IQHDMIClient.h +++ /dev/null @@ -1,57 +0,0 @@ -/* -* Copyright (c) 2014 The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation. nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef HDMI_EVENTS_LISTENER_H_ -#define HDMI_EVENTS_LISTENER_H_ - -#include -#include - -namespace qClient { - -class IQHDMIClient : public android::IInterface -{ -public: - DECLARE_META_INTERFACE(QHDMIClient); - virtual void onHdmiHotplug(int connected) = 0; - virtual void onCECMessageRecieved(char *msg, ssize_t len) = 0; -}; - -class BnQHDMIClient : public android::BnInterface -{ -public: - virtual android::status_t onTransact( uint32_t code, - const android::Parcel& data, - android::Parcel* reply, uint32_t flags = 0); -}; - -}; //namespace qhdmi - -#endif // HDMI_EVENTS_LISTENER_H_ - diff --git a/libqservice/IQService.cpp b/libqservice/IQService.cpp deleted file mode 100644 index d45a141c..00000000 --- a/libqservice/IQService.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * Copyright (C) 2012-2016, The Linux Foundation. All rights reserved. - * - * Not a Contribution, Apache license notifications and license are - * retained for attribution purposes only. - - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define QSERVICE_DEBUG 0 - -using namespace android; -using namespace qClient; - -// --------------------------------------------------------------------------- - -namespace qService { - -class BpQService : public BpInterface -{ -public: - BpQService(const sp& impl) - : BpInterface(impl) {} - - virtual void connect(const sp& client) { - ALOGD_IF(QSERVICE_DEBUG, "%s: connect HWC client", __FUNCTION__); - Parcel data, reply; - data.writeInterfaceToken(IQService::getInterfaceDescriptor()); - data.writeStrongBinder(IInterface::asBinder(client)); - remote()->transact(CONNECT_HWC_CLIENT, data, &reply); - } - - virtual void connect(const sp& client) { - ALOGD_IF(QSERVICE_DEBUG, "%s: connect HDMI client", __FUNCTION__); - Parcel data, reply; - data.writeInterfaceToken(IQService::getInterfaceDescriptor()); - data.writeStrongBinder(IInterface::asBinder(client)); - remote()->transact(CONNECT_HDMI_CLIENT, data, &reply); - } - - - virtual android::status_t dispatch(uint32_t command, const Parcel* inParcel, - Parcel* outParcel) { - ALOGD_IF(QSERVICE_DEBUG, "%s: dispatch in:%p", __FUNCTION__, inParcel); - status_t err = (status_t) android::FAILED_TRANSACTION; - Parcel data; - Parcel *reply = outParcel; - data.writeInterfaceToken(IQService::getInterfaceDescriptor()); - if (inParcel && inParcel->dataSize() > 0) - data.appendFrom(inParcel, 0, inParcel->dataSize()); - err = remote()->transact(command, data, reply); - return err; - } -}; - -IMPLEMENT_META_INTERFACE(QService, "android.display.IQService"); - -// ---------------------------------------------------------------------- - -status_t BnQService::onTransact( - uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) -{ - ALOGD_IF(QSERVICE_DEBUG, "%s: code: %d", __FUNCTION__, code); - // IPC should be from certain processes only - IPCThreadState* ipc = IPCThreadState::self(); - const int callerPid = ipc->getCallingPid(); - const int callerUid = ipc->getCallingUid(); - - const bool permission = (callerUid == AID_MEDIA || - callerUid == AID_GRAPHICS || - callerUid == AID_ROOT || - callerUid == AID_CAMERASERVER || - callerUid == AID_AUDIO || - callerUid == AID_SYSTEM || - callerUid == AID_MEDIA_CODEC); - - if (code == CONNECT_HWC_CLIENT) { - CHECK_INTERFACE(IQService, data, reply); - if(callerUid != AID_GRAPHICS) { - ALOGE("display.qservice CONNECT_HWC_CLIENT access denied: pid=%d uid=%d", - callerPid, callerUid); - return PERMISSION_DENIED; - } - sp client = - interface_cast(data.readStrongBinder()); - connect(client); - return NO_ERROR; - } else if(code == CONNECT_HDMI_CLIENT) { - CHECK_INTERFACE(IQService, data, reply); - if(callerUid != AID_SYSTEM && callerUid != AID_ROOT) { - ALOGE("display.qservice CONNECT_HDMI_CLIENT access denied: pid=%d uid=%d", - callerPid, callerUid); - return PERMISSION_DENIED; - } - sp client = - interface_cast(data.readStrongBinder()); - connect(client); - return NO_ERROR; - } else if (code > COMMAND_LIST_START && code < COMMAND_LIST_END) { - if(!permission) { - ALOGE("display.qservice access denied: command=%d pid=%d uid=%d", - code, callerPid, callerUid); - return PERMISSION_DENIED; - } - CHECK_INTERFACE(IQService, data, reply); - dispatch(code, &data, reply); - return NO_ERROR; - } else { - return BBinder::onTransact(code, data, reply, flags); - } -} - -}; // namespace qService diff --git a/libqservice/IQService.h b/libqservice/IQService.h deleted file mode 100644 index 5765b10d..00000000 --- a/libqservice/IQService.h +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * Copyright (C) 2012-2014, 2016-2017 The Linux Foundation. All rights reserved. - * - * Not a Contribution, Apache license notifications and license are - * retained for attribution purposes only. - - * 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_IQSERVICE_H -#define ANDROID_IQSERVICE_H - -#include -#include -#include -#include -#include -#include -#include -#include - - -namespace qService { -// ---------------------------------------------------------------------------- - -class IQService : public android::IInterface -{ -public: - DECLARE_META_INTERFACE(QService); - enum { - COMMAND_LIST_START = android::IBinder::FIRST_CALL_TRANSACTION, - GET_PANEL_BRIGHTNESS = 2, // Provides ability to set the panel brightness - SET_PANEL_BRIGHTNESS = 3, // Provides ability to get the panel brightness - CONNECT_HWC_CLIENT = 4, // Connect to qservice - SCREEN_REFRESH = 5, // Refresh screen through SF invalidate - EXTERNAL_ORIENTATION = 6,// Set external orientation - BUFFER_MIRRORMODE = 7, // Buffer mirrormode - CHECK_EXTERNAL_STATUS = 8,// Check status of external display - GET_DISPLAY_ATTRIBUTES = 9,// Get display attributes - SET_HSIC_DATA = 10, // Set HSIC on dspp - GET_DISPLAY_VISIBLE_REGION = 11,// Get the visibleRegion for dpy - SET_SECONDARY_DISPLAY_STATUS = 12,// Sets secondary display status - SET_MAX_PIPES_PER_MIXER = 13,// Set max pipes per mixer for MDPComp - SET_VIEW_FRAME = 14, // Set view frame of display - DYNAMIC_DEBUG = 15, // Enable more logging on the fly - SET_IDLE_TIMEOUT = 16, // Set idle timeout for GPU fallback - TOGGLE_BWC = 17, // Toggle BWC On/Off on targets that support - /* Enable/Disable/Set refresh rate dynamically */ - CONFIGURE_DYN_REFRESH_RATE = 18, - CONTROL_PARTIAL_UPDATE = 19, // Provides ability to enable/disable partial update - TOGGLE_SCREEN_UPDATES = 20, // Provides ability to set the panel brightness - SET_FRAME_DUMP_CONFIG = 21, // Provides ability to set the frame dump config - SET_S3D_MODE = 22, // Set the 3D mode as specified in msm_hdmi_modes.h - CONNECT_HDMI_CLIENT = 23, // Connect HDMI CEC HAL Client - QDCM_SVC_CMDS = 24, // request QDCM services. - SET_ACTIVE_CONFIG = 25, //Set a specified display config - GET_ACTIVE_CONFIG = 26, //Get the current config index - GET_CONFIG_COUNT = 27, //Get the number of supported display configs - GET_DISPLAY_ATTRIBUTES_FOR_CONFIG = 28, //Get attr for specified config - SET_DISPLAY_MODE = 29, // Set display mode to command or video mode - SET_CAMERA_STATUS = 30, // To notify display when camera is on and off - MIN_HDCP_ENCRYPTION_LEVEL_CHANGED = 31, - GET_BW_TRANSACTION_STATUS = 32, //Client can query BW transaction status. - SET_LAYER_MIXER_RESOLUTION = 33, // Enables client to set layer mixer resolution. - SET_COLOR_MODE = 34, // Overrides the QDCM mode on the display - GET_HDR_CAPABILITIES = 35, // Get HDR capabilities for legacy HWC interface - SET_COLOR_MODE_BY_ID = 36, // Overrides the QDCM mode using the given mode ID - GET_COMPOSER_STATUS = 37, // Get composer init status-true if primary display init is done - COMMAND_LIST_END = 400, - }; - - enum { - END = 0, - START, - }; - - enum { - DEBUG_ALL, - DEBUG_MDPCOMP, - DEBUG_VSYNC, - DEBUG_VD, - DEBUG_PIPE_LIFECYCLE, - DEBUG_DRIVER_CONFIG, - DEBUG_ROTATOR, - DEBUG_QDCM, - DEBUG_SCALAR, - DEBUG_CLIENT, - DEBUG_DISPLAY, - DEBUG_MAX_VAL = DEBUG_DISPLAY, // Used to check each bit of the debug command paramater. - // Update DEBUG_MAX_VAL when adding new debug tag. - }; - - enum { - PREF_POST_PROCESSING, - PREF_PARTIAL_UPDATE, - ENABLE_PARTIAL_UPDATE, - }; - - // Register a HWC client that can be notified - // This client is generic and is intended to get - // dispatches of all events calling into QService - virtual void connect(const android::sp& client) = 0; - // Register an HDMI client. This client gets notification of HDMI events - // such as plug/unplug and CEC messages - virtual void connect(const android::sp& client) = 0; - // Generic function to dispatch binder commands - // The type of command decides how the data is parceled - virtual android::status_t dispatch(uint32_t command, - const android::Parcel* inParcel, - android::Parcel* outParcel) = 0; -}; - -// ---------------------------------------------------------------------------- - -class BnQService : public android::BnInterface -{ -public: - virtual android::status_t onTransact( uint32_t code, - const android::Parcel& data, - android::Parcel* reply, - uint32_t flags = 0); -}; - -// ---------------------------------------------------------------------------- -}; // namespace qService - -#endif // ANDROID_IQSERVICE_H diff --git a/libqservice/Makefile.am b/libqservice/Makefile.am deleted file mode 100644 index 79935b8b..00000000 --- a/libqservice/Makefile.am +++ /dev/null @@ -1,18 +0,0 @@ -h_sources = IQService.h \ - IQClient.h - -cpp_sources = QService.cpp \ - IQService.cpp \ - IQClient.cpp \ - IQHDMIClient.cpp - -library_includedir = $(includedir) -library_include_HEADERS = $(h_sources) - -lib_LTLIBRARIES = libqservice.la -libqservice_la_CC = @CC@ -libqservice_la_SOURCES = $(cpp_sources) -libqservice_la_CFLAGS = $(COMMON_CFLAGS) -DLOG_TAG=\"qdqservice\" -libqservice_la_CPPFLAGS = $(AM_CPPFLAGS) -libqservice_LDADD = -lhardware -lcutils -llog -lbinder -libqservice_la_LDFLAGS = -shared -avoid-version \ No newline at end of file diff --git a/libqservice/QService.cpp b/libqservice/QService.cpp deleted file mode 100644 index 546ad7ee..00000000 --- a/libqservice/QService.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2012-2014, 2016, The Linux Foundation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of The Linux Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include - -#define QSERVICE_DEBUG 0 - -using namespace android; - -namespace qService { - -QService* QService::sQService = NULL; -// ---------------------------------------------------------------------------- -QService::QService() -{ - ALOGD_IF(QSERVICE_DEBUG, "QService Constructor invoked"); -} - -QService::~QService() -{ - ALOGD_IF(QSERVICE_DEBUG,"QService Destructor invoked"); -} - -void QService::connect(const sp& client) { - ALOGD_IF(QSERVICE_DEBUG,"HWC client connected"); - mClient = client; -} - -void QService::connect(const sp& client) { - ALOGD_IF(QSERVICE_DEBUG,"HDMI client connected"); - mHDMIClient = client; -} - -status_t QService::dispatch(uint32_t command, const Parcel* inParcel, - Parcel* outParcel) { - status_t err = (status_t) FAILED_TRANSACTION; - IPCThreadState* ipc = IPCThreadState::self(); - //Rewind parcel in case we're calling from the same process - bool sameProcess = (ipc->getCallingPid() == getpid()); - if(sameProcess) - inParcel->setDataPosition(0); - if (mClient.get()) { - ALOGD_IF(QSERVICE_DEBUG, "Dispatching command: %d", command); - err = mClient->notifyCallback(command, inParcel, outParcel); - //Rewind parcel in case we're calling from the same process - if (sameProcess) - outParcel->setDataPosition(0); - } - return err; -} - -void QService::onHdmiHotplug(int connected) { - if(mHDMIClient.get()) { - ALOGD_IF(QSERVICE_DEBUG, "%s: HDMI hotplug", __FUNCTION__); - mHDMIClient->onHdmiHotplug(connected); - } else { - ALOGW("%s: Failed to get a valid HDMI client", __FUNCTION__); - } -} - -void QService::onCECMessageReceived(char *msg, ssize_t len) { - if(mHDMIClient.get()) { - ALOGD_IF(QSERVICE_DEBUG, "%s: CEC message received", __FUNCTION__); - mHDMIClient->onCECMessageRecieved(msg, len); - } else { - ALOGW("%s: Failed to get a valid HDMI client", __FUNCTION__); - } -} - - -void QService::init() -{ - if(!sQService) { - sQService = new QService(); - sp sm = defaultServiceManager(); - sm->addService(String16("display.qservice"), sQService); - if(sm->checkService(String16("display.qservice")) != NULL) - ALOGD_IF(QSERVICE_DEBUG, "adding display.qservice succeeded"); - else - ALOGD_IF(QSERVICE_DEBUG, "adding display.qservice failed"); - } -} - -} diff --git a/libqservice/QService.h b/libqservice/QService.h deleted file mode 100644 index 6bb4d7d5..00000000 --- a/libqservice/QService.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2012-2013, 2016, The Linux Foundation. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * * Neither the name of The Linux Foundation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR - * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE - * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN - * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef ANDROID_QSERVICE_H -#define ANDROID_QSERVICE_H - -#include -#include -#include -#include -#include -#include - -struct hwc_context_t; - -namespace qService { -// ---------------------------------------------------------------------------- - -class QService : public BnQService { -public: - virtual ~QService(); - virtual void connect(const android::sp& client); - virtual void connect(const android::sp& client); - virtual android::status_t dispatch(uint32_t command, - const android::Parcel* data, - android::Parcel* reply); - virtual void onHdmiHotplug(int connected); - virtual void onCECMessageReceived(char *msg, ssize_t len); - static void init(); -private: - QService(); - android::sp mClient; - android::sp mHDMIClient; - static QService *sQService; -}; -}; // namespace qService -#endif // ANDROID_QSERVICE_H diff --git a/libqservice/QServiceUtils.h b/libqservice/QServiceUtils.h deleted file mode 100644 index 8f25253c..00000000 --- a/libqservice/QServiceUtils.h +++ /dev/null @@ -1,102 +0,0 @@ -/* -* Copyright (c) 2013-14 The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation. nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef QSERVICEUTILS_H -#define QSERVICEUTILS_H -#include -#include -#include -#include - -// ---------------------------------------------------------------------------- -// Helpers -// ---------------------------------------------------------------------------- -inline android::sp getBinder() { - android::sp sm = android::defaultServiceManager(); - android::sp binder = - android::interface_cast - (sm->getService(android::String16("display.qservice"))); - if (binder == NULL) { - ALOGE("%s: invalid binder object", __FUNCTION__); - } - return binder; -} - -inline android::status_t sendSingleParam(uint32_t command, uint32_t value) { - android::status_t err = (android::status_t) android::FAILED_TRANSACTION; - android::sp binder = getBinder(); - android::Parcel inParcel, outParcel; - inParcel.writeInt32(value); - if(binder != NULL) { - err = binder->dispatch(command, &inParcel , &outParcel); - } - return err; -} - -// ---------------------------------------------------------------------------- -// Convenience wrappers that clients can call -// ---------------------------------------------------------------------------- -inline android::status_t screenRefresh() { - return sendSingleParam(qService::IQService::SCREEN_REFRESH, 1); -} - -inline android::status_t toggleScreenUpdate(uint32_t on) { - return sendSingleParam(qService::IQService::TOGGLE_SCREEN_UPDATES, on); -} - -inline android::status_t setExtOrientation(uint32_t orientation) { - return sendSingleParam(qService::IQService::EXTERNAL_ORIENTATION, - orientation); -} - -inline android::status_t setBufferMirrorMode(uint32_t enable) { - return sendSingleParam(qService::IQService::BUFFER_MIRRORMODE, enable); -} - -inline android::status_t setCameraLaunchStatus(uint32_t on) { - return sendSingleParam(qService::IQService::SET_CAMERA_STATUS, on); -} - -inline bool displayBWTransactionPending() { - android::status_t err = (android::status_t) android::FAILED_TRANSACTION; - bool ret = false; - android::sp binder = getBinder(); - android::Parcel inParcel, outParcel; - if(binder != NULL) { - err = binder->dispatch(qService::IQService::GET_BW_TRANSACTION_STATUS, - &inParcel , &outParcel); - if(err != android::NO_ERROR){ - ALOGE("GET_BW_TRANSACTION_STATUS binder call failed err=%d", err); - return ret; - } - } - ret = outParcel.readInt32(); - return ret; -} -#endif /* end of include guard: QSERVICEUTILS_H */ diff --git a/sdm/include/core/buffer_allocator.h b/sdm/include/core/buffer_allocator.h deleted file mode 100644 index 6d77bcde..00000000 --- a/sdm/include/core/buffer_allocator.h +++ /dev/null @@ -1,159 +0,0 @@ -/* -* Copyright (c) 2015 - 2017, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/*! @file buffer_allocator.h - @brief Interface file for platform specific buffer allocator. - - @details This interface is used by SDM to allocate internal buffers. -*/ - -#ifndef __BUFFER_ALLOCATOR_H__ -#define __BUFFER_ALLOCATOR_H__ - -#include "layer_buffer.h" - -namespace sdm { -/*! @brief Input configuration set by the client for buffer allocation. - - @sa BufferInfo::BufferConfig -*/ - -struct BufferConfig { - uint32_t width = 0; //!< Specifies buffer width for buffer allocation. - uint32_t height = 0; //!< Specifies buffer height for buffer allocation. - LayerBufferFormat format = kFormatInvalid; //!< Specifies buffer format for buffer allocation. - uint32_t buffer_count = 0; //!< Specifies number of buffers to be allocated. - bool secure = false; //!< Specifies buffer to be allocated from - //!< secure region. - bool cache = false; //!< Specifies whether the buffer needs to be cache. - bool secure_camera = false; //!< Specifies buffer to be allocated from specific - //!< secure heap and with a specific alignment. - bool gfx_client = false; //!< Specifies whether buffer is used by gfx. -}; - -/*! @brief Holds the information about the allocated buffer. - - @sa BufferAllocator::AllocateBuffer - @sa BufferAllocator::FreeBuffer - @sa BufferAllocator::GetAllocatedBufferInfo -*/ -struct AllocatedBufferInfo { - int fd = -1; //!< Specifies the fd of the allocated buffer. - uint32_t stride = 0; //!< Specifies allocated buffer stride in bytes. - uint32_t aligned_width = 0; //!< Specifies aligned allocated buffer width in pixels. - uint32_t aligned_height = 0; //!< Specifies aligned allocated buffer height in pixels. - LayerBufferFormat format = kFormatInvalid; // Specifies buffer format for allocated buffer. - uint32_t size = 0; //!< Specifies the size of the allocated buffer. -}; - -/*! @brief Holds the information about the input/output configuration of an output buffer. - - @sa BufferAllocator::AllocateBuffer - @sa BufferAllocator::FreeBuffer -*/ -struct BufferInfo { - BufferConfig buffer_config; //!< Specifies configuration of a buffer to be allocated. - AllocatedBufferInfo alloc_buffer_info; //!< Specifies buffer information of allocated buffer. - - void *private_data = NULL; //!< Pointer to private data. -}; - -/*! @brief Buffer allocator implemented by the client - - @details This class declares prototype for BufferAllocator methods which must be - implemented by the client. Buffer manager in display manager will use these methods to - allocate/deallocate buffers for display manager. - - @sa CoreInterface::CreateCore -*/ -class BufferAllocator { - public: - /*! @brief Method to allocate ouput buffer for the given input configuration. - - @details This method allocates memory based on input configuration. - - @param[in] buffer_info \link BufferInfo \endlink - - @return \link DisplayError \endlink - */ - virtual DisplayError AllocateBuffer(BufferInfo *buffer_info) = 0; - - - /*! @brief Method to deallocate the ouput buffer. - - @details This method deallocates the memory allocated using AllocateBuffer method. - - @param[in] buffer_info \link BufferInfo \endlink - - @return \link DisplayError \endlink - */ - virtual DisplayError FreeBuffer(BufferInfo *buffer_info) = 0; - - - /*! @brief Method to get the buffer size. - - @details This method returns buffer size for a specific configuration mentioned in buffer info. - - @param[in] buffer_info \link BufferInfo \endlink - - @return \link unsigned int \endlink - */ - virtual uint32_t GetBufferSize(BufferInfo *buffer_info) = 0; - - /*! @brief Method to Get the AllocatedBufferInfo only. - - @details This method populates the AllocatedBufferInfo as per the configuration in BufferInfo, - but fd will be invalid. - - @param[in] buffer_info \link BufferInfo \endlink - - @param[out] allocated_buffer_info \link AllocatedBufferInfo \endlink - - @return \link DisplayError \endlink - */ - virtual DisplayError GetAllocatedBufferInfo(const BufferConfig &buffer_config, - AllocatedBufferInfo *allocated_buffer_info) = 0; - - /* - * Retuns a buffer's layout in terms of number of planes, stride and offset of each plane - * Input: AllocatedBufferInfo with a valid aligned width, aligned height, SDM format - * Output: stride for each plane, offset of each plane from base, number of planes - */ - virtual DisplayError GetBufferLayout(const AllocatedBufferInfo &buf_info, - uint32_t stride[4], uint32_t offset[4], - uint32_t *num_planes) { return kErrorNotSupported; } - - protected: - virtual ~BufferAllocator() { } -}; - -} // namespace sdm - -#endif // __BUFFER_ALLOCATOR_H__ - diff --git a/sdm/include/core/buffer_sync_handler.h b/sdm/include/core/buffer_sync_handler.h deleted file mode 100644 index 1dc54138..00000000 --- a/sdm/include/core/buffer_sync_handler.h +++ /dev/null @@ -1,99 +0,0 @@ -/* -* Copyright (c) 2015, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/*! @file buffer_sync_handler.h - @brief Interface file for platform specific buffer allocator. - - @details SDM will use this interface to wait for buffer sync fd to be signaled/merge - the two buffer sync fds into one. -*/ - -#ifndef __BUFFER_SYNC_HANDLER_H__ -#define __BUFFER_SYNC_HANDLER_H__ - -#include "sdm_types.h" - -namespace sdm { - -/*! @brief Buffer sync handler implemented by the client - - @details This class declares prototype for BufferSyncHandler methods which must be - implemented by the client. SDM will use these methods to wait for buffer sync fd to be - signaled/merge two buffer sync fds into one. - - @sa CoreInterface::CreateCore -*/ -class BufferSyncHandler { - public: - /*! @brief Method to wait for ouput buffer to be released. - - @details This method waits for fd to be signaled by the producer/consumer. - It is responsibility of the caller to close file descriptor. - - @param[in] fd - - @return \link DisplayError \endlink - */ - - virtual DisplayError SyncWait(int fd) = 0; - - /*! @brief Method to merge two sync fds into one sync fd - - @details This method merges two buffer sync fds into one sync fd, if a producer/consumer - requires to wait for more than one sync fds. It is responsibility of the caller to close file - descriptor. - - @param[in] fd1 - @param[in] fd2 - @param[out] merged_fd - - @return \link DisplayError \endlink - */ - - virtual DisplayError SyncMerge(int fd1, int fd2, int *merged_fd) = 0; - - /*! @brief Method to detect if sync fd is signaled - - @details This method detects if sync fd is signaled. It is responsibility of the caller to - close file descriptor. - - @param[in] fd - - @return \link Tue if fd has been signaled \endlink - */ - virtual bool IsSyncSignaled(int fd) = 0; - - protected: - virtual ~BufferSyncHandler() { } -}; - -} // namespace sdm - -#endif // __BUFFER_SYNC_HANDLER_H__ - diff --git a/sdm/include/core/core_interface.h b/sdm/include/core/core_interface.h deleted file mode 100644 index d169956d..00000000 --- a/sdm/include/core/core_interface.h +++ /dev/null @@ -1,205 +0,0 @@ -/* -* Copyright (c) 2014 - 2016, 2018 The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/*! @file core_interface.h - @brief Interface file for core of the display subsystem. - - @details Display core is primarily used for loading and unloading different display device - components viz primary, external and virtual. Display core is a statically linked library which - runs in caller's process context. -*/ -#ifndef __CORE_INTERFACE_H__ -#define __CORE_INTERFACE_H__ - -#include - -#include "display_interface.h" -#include "sdm_types.h" -#include "buffer_allocator.h" -#include "buffer_sync_handler.h" -#include "socket_handler.h" - -/*! @brief Display manager interface version. - - @details Display manager interfaces are version tagged to maintain backward compatibility. This - version is supplied as a default argument during display core initialization. - - Client may use an older version of interfaces and link to a higher version of display manager - library, but vice versa is not allowed. - - A 32-bit client must use 32-bit display core library and a 64-bit client must use 64-bit display - core library. - - Display manager interfaces follow default data structures alignment. Client must not override the - default padding rules while using these interfaces. - - @warning It is assumed that client upgrades or downgrades display core interface all at once - and recompile all binaries which use these interfaces. Mix and match of these interfaces can - lead to unpredictable behaviour. - - @sa CoreInterface::CreateCore -*/ -#define SDM_REVISION_MAJOR (1) -#define SDM_REVISION_MINOR (0) - -#define SDM_VERSION_TAG ((uint32_t) ((SDM_REVISION_MAJOR << 24) | (SDM_REVISION_MINOR << 16) | \ - (sizeof(SDMCompatibility) << 8) | sizeof(int *))) - -namespace sdm { - -/*! @brief This enum represents max bandwidth limit mode. - - @sa DisplayInterface::SetMaxBandwidthMode -*/ -enum HWBwModes { - kBwDefault, //!< Default state. No change in device bandwidth limit. - kBwCamera, //!< Camera is on. Bandwidth limit should be reduced accordingly. - kBwVFlip, //!< VFlip is required. Reduce bandwidth limit accordingly. - kBwHFlip, //!< HFlip is required. Reduce bandwidth limit accordingly. - kBwModeMax, //!< Limiter for maximum available bandwidth modes. -}; - - -/*! @brief Information on hardware for the first display - - @details This structure returns the display type of the first display on the device - (internal display or HDMI etc) and whether it is currently connected, - -*/ -struct HWDisplayInterfaceInfo { - DisplayType type; - bool is_connected; -}; - -/*! @brief Display core interface. - - @details This class defines display core interfaces. It contains methods which client shall use - to create/destroy different display devices. This interface is created during display core - CreateCore() and remains valid until DestroyCore(). - - @sa CoreInterface::CreateCore - @sa CoreInterface::DestroyCore -*/ -class CoreInterface { - public: - /*! @brief Method to create and get handle to display core interface. - - @details This method is the entry point into the display core. Client can create and operate on - different display devices only through a valid interface handle obtained using this method. An - object of display core is created and handle to this object is returned via output parameter. - This interface shall be called only once. - - @param[in] buffer_allocator \link BufferAllocator \endlink - @param[in] buffer_sync_handler \link BufferSyncHandler \endlink - @param[in] socket_handler \link SocketHandler \endlink - @param[out] interface \link CoreInterface \endlink - @param[in] version \link SDM_VERSION_TAG \endlink. Client must not override this argument. - - @return \link DisplayError \endlink - - @sa DestroyCore - */ - static DisplayError CreateCore(BufferAllocator *buffer_allocator, - BufferSyncHandler *buffer_sync_handler, - SocketHandler *socket_handler, CoreInterface **interface, - uint32_t version = SDM_VERSION_TAG); - - /*! @brief Method to release handle to display core interface. - - @details The object of corresponding display core is destroyed when this method is invoked. - Client must explicitly destroy all created display device objects associated with this handle - before invoking this method. - - @param[in] interface \link CoreInterface \endlink - - @return \link DisplayError \endlink - - @sa CreateCore - */ - static DisplayError DestroyCore(); - - /*! @brief Method to create a display device for a given type. - - @details Client shall use this method to create each of the connected display type. A handle to - interface associated with this object is returned via output parameter which can be used to - interact further with the display device. - - @param[in] type \link DisplayType \endlink - @param[in] event_handler \link DisplayEventHandler \endlink - @param[out] interface \link DisplayInterface \endlink - - @return \link DisplayError \endlink - - @sa DestroyDisplay - */ - virtual DisplayError CreateDisplay(DisplayType type, DisplayEventHandler *event_handler, - DisplayInterface **interface) = 0; - - /*! @brief Method to destroy a display device. - - @details Client shall use this method to destroy each of the created display device objects. - - @param[in] interface \link DisplayInterface \endlink - - @return \link DisplayError \endlink - - @sa CreateDisplay - */ - virtual DisplayError DestroyDisplay(DisplayInterface *interface) = 0; - - /*! @brief Method to update the bandwidth limit as per given mode. - - @param[in] mode indicate the mode or use case - - @return \link DisplayError \endlink - - */ - virtual DisplayError SetMaxBandwidthMode(HWBwModes mode) = 0; - - /*! @brief Method to get characteristics of the first display. - - @details Client shall use this method to determine if the first display is HDMI, and whether - it is currently connected. - - @param[in] hw_disp_info structure that this method will fill up with info. - - @return \link DisplayError \endlink - - */ - virtual DisplayError GetFirstDisplayInterfaceType(HWDisplayInterfaceInfo *hw_disp_info) = 0; - - - protected: - virtual ~CoreInterface() { } -}; - -} // namespace sdm - -#endif // __CORE_INTERFACE_H__ - diff --git a/sdm/include/core/display_interface.h b/sdm/include/core/display_interface.h deleted file mode 100644 index 8156ca41..00000000 --- a/sdm/include/core/display_interface.h +++ /dev/null @@ -1,700 +0,0 @@ -/* -* Copyright (c) 2014 - 2018, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted -* provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright notice, this list of -* conditions and the following disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its contributors may be used to -* endorse or promote products derived from this software without specific prior written -* permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/*! @file display_interface.h - @brief Interface file for display device which represents a physical panel or an output buffer - where contents can be rendered. - - @details Display device is used to send layer buffers for composition and get them rendered onto - the target device. Each display device represents a unique display target which may be either a - physical panel or an output buffer.. -*/ -#ifndef __DISPLAY_INTERFACE_H__ -#define __DISPLAY_INTERFACE_H__ - -#include -#include -#include -#include - -#include "layer_stack.h" -#include "sdm_types.h" - -namespace sdm { - -typedef std::vector> AttrVal; - -/*! @brief This enum represents display device types where contents can be rendered. - - @sa CoreInterface::CreateDisplay - @sa CoreInterface::IsDisplaySupported -*/ -enum DisplayType { - kPrimary, //!< Main physical display which is attached to the handheld device. - kHDMI, //!< HDMI physical display which is generally detachable. - kVirtual, //!< Contents would be rendered into the output buffer provided by the client - //!< e.g. wireless display. - kDisplayMax, -}; - -/*! @brief This enum represents states of a display device. - - @sa DisplayInterface::GetDisplayState - @sa DisplayInterface::SetDisplayState -*/ -enum DisplayState { - kStateOff, //!< Display is OFF. Contents are not rendered in this state. Client will not - //!< receive VSync events in this state. This is default state as well. - - kStateOn, //!< Display is ON. Contents are rendered in this state. - - kStateDoze, //!< Display is ON and it is configured in a low power state. - - kStateDozeSuspend, - //!< Display is ON in a low power state and continue showing its current - //!< contents indefinitely until the mode changes. - - kStateStandby, //!< Display is OFF. Client will continue to receive VSync events in this state - //!< if VSync is enabled. Contents are not rendered in this state. -}; - -/*! @brief This enum represents flags to override detail enhancer parameters. - - @sa DisplayInterface::SetDetailEnhancerData -*/ -enum DetailEnhancerOverrideFlags { - kOverrideDEEnable = 0x1, // Specifies to enable detail enhancer - kOverrideDESharpen1 = 0x2, // Specifies user defined Sharpening/smooth for noise - kOverrideDESharpen2 = 0x4, // Specifies user defined Sharpening/smooth for signal - kOverrideDEClip = 0x8, // Specifies user defined DE clip shift - kOverrideDELimit = 0x10, // Specifies user defined DE limit value - kOverrideDEThrQuiet = 0x20, // Specifies user defined DE quiet threshold - kOverrideDEThrDieout = 0x40, // Specifies user defined DE dieout threshold - kOverrideDEThrLow = 0x80, // Specifies user defined DE low threshold - kOverrideDEThrHigh = 0x100, // Specifies user defined DE high threshold - kOverrideDEFilterConfig = 0x200, // Specifies user defined scaling filter config - kOverrideDEMax = 0xFFFFFFFF, -}; - -/*! @brief This enum represents Y/RGB scaling filter configuration. - - @sa DisplayInterface::SetDetailEnhancerData -*/ -enum ScalingFilterConfig { - kFilterEdgeDirected, - kFilterCircular, - kFilterSeparable, - kFilterBilinear, - kFilterMax, -}; - -/*! @brief This enum represents the quality level of the content. - - @sa DisplayInterface::SetDetailEnhancerData -*/ -enum ContentQuality { - kContentQualityUnknown, // Default: high artifact and noise - kContentQualityLow, // Low quality content, high artifact and noise, - kContentQualityMedium, // Medium quality, medium artifact and noise, - kContentQualityHigh, // High quality content, low artifact and noise - kContentQualityMax, -}; - -/*! @brief This enum represents the display port. - - @sa DisplayInterface::GetDisplayPort -*/ -enum DisplayPort { - kPortDefault, - kPortDSI, // Display is connected to DSI port. - kPortDTV, // Display is connected to DTV port - kPortWriteBack, // Display is connected to writeback port - kPortLVDS, // Display is connected to LVDS port - kPortEDP, // Display is connected to EDP port - kPortDP, // Display is connected to DP port. -}; - -/*! @brief This enum represents the events received by Display HAL. */ -enum DisplayEvent { - kIdleTimeout, // Event triggered by Idle Timer. - kThermalEvent, // Event triggered by Thermal. - kIdlePowerCollapse, // Event triggered by Idle Power Collapse. - kPanelDeadEvent, // Event triggered by ESD. -}; - -/*! @brief This structure defines configuration for fixed properties of a display device. - - @sa DisplayInterface::GetConfig - @sa DisplayInterface::SetConfig -*/ -struct DisplayConfigFixedInfo { - bool underscan = false; //!< If display support CE underscan. - bool secure = false; //!< If this display is capable of handling secure content. - bool is_cmdmode = false; //!< If panel is command mode panel. - bool hdr_supported = false; //!< if HDR is enabled - bool hdr_metadata_type_one = false; //!< Metadata type one obtained from HDR sink - uint32_t hdr_eotf = 0; //!< Electro optical transfer function - uint32_t max_luminance = 0; //!< From Panel's peak luminance - uint32_t average_luminance = 0; //!< From Panel's average luminance - uint32_t min_luminance = 0; //!< From Panel's blackness level -}; - -/*! @brief This structure defines configuration for variable properties of a display device. - - @sa DisplayInterface::GetConfig - @sa DisplayInterface::SetConfig -*/ -struct DisplayConfigVariableInfo { - uint32_t x_pixels = 0; //!< Total number of pixels in X-direction on the display panel. - uint32_t y_pixels = 0; //!< Total number of pixels in Y-direction on the display panel. - float x_dpi = 0.0f; //!< Dots per inch in X-direction. - float y_dpi = 0.0f; //!< Dots per inch in Y-direction. - uint32_t fps = 0; //!< Frame rate per second. - uint32_t vsync_period_ns = 0; //!< VSync period in nanoseconds. - bool is_yuv = false; //!< If the display output is in YUV format. -}; - -/*! @brief Event data associated with VSync event. - - @sa DisplayEventHandler::VSync -*/ -struct DisplayEventVSync { - int64_t timestamp = 0; //!< System monotonic clock timestamp in nanoseconds. -}; - -/*! @brief The structure defines the user input for detail enhancer module. - - @sa DisplayInterface::SetDetailEnhancerData -*/ -struct DisplayDetailEnhancerData { - uint32_t override_flags = 0; // flags to specify which data to be set. - uint16_t enable = 0; // Detail enchancer enable - int16_t sharpen_level1 = 0; // Sharpening/smooth strenght for noise - int16_t sharpen_level2 = 0; // Sharpening/smooth strenght for signal - uint16_t clip = 0; // DE clip shift - uint16_t limit = 0; // DE limit value - uint16_t thr_quiet = 0; // DE quiet threshold - uint16_t thr_dieout = 0; // DE dieout threshold - uint16_t thr_low = 0; // DE low threshold - uint16_t thr_high = 0; // DE high threshold - int32_t sharp_factor = 50; // sharp_factor specifies sharpness/smoothness level, - // range -100..100 positive for sharpness and negative for - // smoothness - ContentQuality quality_level = kContentQualityUnknown; - // Specifies context quality level - ScalingFilterConfig filter_config = kFilterEdgeDirected; - // Y/RGB filter configuration -}; - -/*! @brief Display device event handler implemented by the client. - - @details This class declares prototype for display device event handler methods which must be - implemented by the client. Display device will use these methods to notify events to the client. - Client must post heavy-weight event handling to a separate thread and unblock display manager - thread instantly. - - @sa CoreInterface::CreateDisplay -*/ -class DisplayEventHandler { - public: - /*! @brief Event handler for VSync event. - - @details This event is dispatched on every vertical synchronization. The event is disabled by - default. - - @param[in] vsync \link DisplayEventVSync \endlink - - @return \link DisplayError \endlink - - @sa DisplayInterface::GetDisplayState - @sa DisplayInterface::SetDisplayState - */ - virtual DisplayError VSync(const DisplayEventVSync &vsync) = 0; - - /*! @brief Event handler for Refresh event. - - @details This event is dispatched to trigger a screen refresh. Client must call Prepare() and - Commit() in response to it from a separate thread. There is no data associated with this - event. - - @return \link DisplayError \endlink - - @sa DisplayInterface::Prepare - @sa DisplayInterface::Commit - */ - virtual DisplayError Refresh() = 0; - - /*! @brief Event handler for CEC messages. - - @details This event is dispatched to send CEC messages to the CEC HAL. - - @param[in] message message to be sent - - @return \link DisplayError \endlink - */ - virtual DisplayError CECMessage(char *message) = 0; - - /*! @brief Event handler for events received by Display HAL. */ - virtual DisplayError HandleEvent(DisplayEvent event) = 0; - - protected: - virtual ~DisplayEventHandler() { } -}; - -struct PPDisplayAPIPayload; -struct PPPendingParams; - -/*! @brief Display device interface. - - @details This class defines display device interface. It contains methods which client shall use - to configure or submit layers for composition on the display device. This interface is created - during display device creation and remains valid until destroyed. - - @sa CoreInterface::CreateDisplay - @sa CoreInterface::DestroyDisplay -*/ -class DisplayInterface { - public: - /*! @brief Method to determine hardware capability to compose layers associated with given frame. - - @details Client shall send all layers associated with a frame targeted for current display - using this method and check the layers which can be handled completely in display manager. - - Client shall mark composition type for one of the layer as kCompositionGPUTarget; the GPU - composed output would be rendered at the specified layer if some of the layers are not handled - by SDM. - - Display manager will set each layer as kCompositionGPU or kCompositionSDE upon return. Client - shall render all the layers marked as kCompositionGPU using GPU. - - This method can be called multiple times but only last call prevails. This method must be - followed by Commit(). - - @param[inout] layer_stack \link LayerStack \endlink - - @return \link DisplayError \endlink - - @sa Commit - */ - virtual DisplayError Prepare(LayerStack *layer_stack) = 0; - - /*! @brief Method to commit layers of a frame submitted in a former call to Prepare(). - - @details Client shall call this method to submit layers for final composition. The composed - output would be displayed on the panel or written in output buffer. - - Client must ensure that layer stack is same as previous call to Prepare. - - This method shall be called only once for each frame. - - In the event of an error as well, this call will cause any fences returned in the previous call - to Commit() to eventually become signaled, so the client's wait on fences can be released to - prevent deadlocks. - - @param[in] layer_stack \link LayerStack \endlink - - @return \link DisplayError \endlink - - @sa Prepare - */ - virtual DisplayError Commit(LayerStack *layer_stack) = 0; - - /*! @brief Method to flush any pending buffers/fences submitted previously via Commit() call. - - @details Client shall call this method to request the Display manager to release all buffers and - respective fences currently in use. This operation may result in a blank display on the panel - until a new frame is submitted for composition. - - @return \link DisplayError \endlink - - @sa Prepare - @sa Commit - */ - virtual DisplayError Flush() = 0; - - /*! @brief Method to get current state of the display device. - - @param[out] state \link DisplayState \endlink - - @return \link DisplayError \endlink - - @sa SetDisplayState - */ - virtual DisplayError GetDisplayState(DisplayState *state) = 0; - - /*! @brief Method to get number of configurations(variable properties) supported on the display - device. - - @param[out] count Number of modes supported; mode index starts with 0. - - @return \link DisplayError \endlink - */ - virtual DisplayError GetNumVariableInfoConfigs(uint32_t *count) = 0; - - /*! @brief Method to get configuration for fixed properties of the display device. - - @param[out] fixed_info \link DisplayConfigFixedInfo \endlink - - @return \link DisplayError \endlink - */ - virtual DisplayError GetConfig(DisplayConfigFixedInfo *fixed_info) = 0; - - /*! @brief Method to get configuration for variable properties of the display device. - - @param[in] index index of the mode - @param[out] variable_info \link DisplayConfigVariableInfo \endlink - - @return \link DisplayError \endlink - */ - virtual DisplayError GetConfig(uint32_t index, DisplayConfigVariableInfo *variable_info) = 0; - - /*! @brief Method to get index of active configuration of the display device. - - @param[out] index index of the mode corresponding to variable properties. - - @return \link DisplayError \endlink - */ - virtual DisplayError GetActiveConfig(uint32_t *index) = 0; - - /*! @brief Method to get VSync event state. Default event state is disabled. - - @param[out] enabled vsync state - - @return \link DisplayError \endlink - */ - virtual DisplayError GetVSyncState(bool *enabled) = 0; - - /*! @brief Method to set current state of the display device. - - @param[in] state \link DisplayState \endlink - @param[in] pointer to release fence - - @return \link DisplayError \endlink - - @sa SetDisplayState - */ - virtual DisplayError SetDisplayState(DisplayState state, int *release_fence) = 0; - - /*! @brief Method to set active configuration for variable properties of the display device. - - @param[in] variable_info \link DisplayConfigVariableInfo \endlink - - @return \link DisplayError \endlink - */ - virtual DisplayError SetActiveConfig(DisplayConfigVariableInfo *variable_info) = 0; - - /*! @brief Method to set active configuration for variable properties of the display device. - - @param[in] index index of the mode corresponding to variable properties. - - @return \link DisplayError \endlink - */ - virtual DisplayError SetActiveConfig(uint32_t index) = 0; - - /*! @brief Method to set VSync event state. Default event state is disabled. - - @param[out] enabled vsync state - - @return \link DisplayError \endlink - */ - virtual DisplayError SetVSyncState(bool enable) = 0; - - /*! @brief Method to set idle timeout value. Idle fallback is disabled with timeout value 0. - - @param[in] active_ms value in milliseconds. - - @return \link void \endlink - */ - virtual void SetIdleTimeoutMs(uint32_t active_ms) = 0; - - /*! @brief Method to set maximum number of mixer stages for each display. - - @param[in] max_mixer_stages maximum number of mixer stages. - - @return \link DisplayError \endlink - */ - virtual DisplayError SetMaxMixerStages(uint32_t max_mixer_stages) = 0; - - /*! @brief Method to control partial update feature for each display. - - @param[in] enable partial update feature control flag - @param[out] pending whether the operation is completed or pending for completion - - @return \link DisplayError \endlink - */ - virtual DisplayError ControlPartialUpdate(bool enable, uint32_t *pending) = 0; - - /*! @brief Method to disable partial update for at least 1 frame. - @return \link DisplayError \endlink - */ - virtual DisplayError DisablePartialUpdateOneFrame() = 0; - - /*! @brief Method to set the mode of the primary display. - - @param[in] mode the new display mode. - - @return \link DisplayError \endlink - */ - virtual DisplayError SetDisplayMode(uint32_t mode) = 0; - - /*! @brief Method to get the min and max refresh rate of a display. - - @param[out] min and max refresh rate. - - @return \link DisplayError \endlink - */ - virtual DisplayError GetRefreshRateRange(uint32_t *min_refresh_rate, - uint32_t *max_refresh_rate) = 0; - - /*! @brief Method to set the refresh rate of a display. - - @param[in] refresh_rate new refresh rate of the display. - - @param[in] final_rate indicates whether refresh rate is final rate or can be changed by sdm - - @return \link DisplayError \endlink - */ - virtual DisplayError SetRefreshRate(uint32_t refresh_rate, bool final_rate) = 0; - - /*! @brief Method to query whether scanning is support for the HDMI display. - - @return \link DisplayError \endlink - */ - virtual bool IsUnderscanSupported() = 0; - - /*! @brief Method to set brightness of the primary display. - - @param[in] level the new backlight level. - - @return \link DisplayError \endlink - */ - virtual DisplayError SetPanelBrightness(int level) = 0; - - /*! @brief Method to notify display about change in min HDCP encryption level. - - @param[in] min_enc_level minimum encryption level value. - - @return \link DisplayError \endlink - */ - virtual DisplayError OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level) = 0; - - /*! @brief Method to route display API requests to color service. - - @param[in] in_payload \link PPDisplayAPIPayload \endlink - @param[out] out_payload \link PPDisplayPayload \endlink - @param[out] pending_action \link PPPendingParams \endlink - - @return \link DisplayError \endlink - */ - virtual DisplayError ColorSVCRequestRoute(const PPDisplayAPIPayload &in_payload, - PPDisplayAPIPayload *out_payload, - PPPendingParams *pending_action) = 0; - - /*! @brief Method to request the number of color modes supported. - - @param[out] mode_count Number of modes - - @return \link DisplayError \endlink - */ - virtual DisplayError GetColorModeCount(uint32_t *mode_count) = 0; - - /*! @brief Method to request the information of supported color modes. - - @param[inout] mode_count Number of updated modes - @param[out] vector of mode strings - - @return \link DisplayError \endlink - */ - virtual DisplayError GetColorModes(uint32_t *mode_count, - std::vector *color_modes) = 0; - - /*! @brief Method to request the attributes of color mode. - - @param[in] mode name - @param[out] vector of mode attributes - - @return \link DisplayError \endlink - */ - virtual DisplayError GetColorModeAttr(const std::string &color_mode, - AttrVal *attr_map) = 0; - - /*! @brief Method to set the color mode - - @param[in] mode_name Mode name which needs to be set - - @return \link DisplayError \endlink - */ - virtual DisplayError SetColorMode(const std::string &color_mode) = 0; - - /*! @brief Method to set the color mode by ID. This method is used for debugging only. - - @param[in] mode_name Mode ID which needs to be set - - @return \link DisplayError \endlink - */ - virtual DisplayError SetColorModeById(int32_t color_mode_id) = 0; - /*! @brief Method to set the color transform - - @param[in] length Mode name which needs to be set - @param[in] color_transform 4x4 Matrix for color transform - - @return \link DisplayError \endlink - */ - virtual DisplayError SetColorTransform(const uint32_t length, const double *color_transform) = 0; - - /*! @brief Method to get the default color mode. - - @param[out] default mode name - - @return \link DisplayError \endlink - */ - virtual DisplayError GetDefaultColorMode(std::string *color_mode) = 0; - - /*! @brief Method to request applying default display mode. - - @return \link DisplayError \endlink - */ - virtual DisplayError ApplyDefaultDisplayMode() = 0; - - /*! @brief Method to set the position of the hw cursor. - - @param[in] x \link x position \endlink - @param[in] y \link y position \endlink - - @return \link DisplayError \endlink - */ - virtual DisplayError SetCursorPosition(int x, int y) = 0; - - /*! @brief Method to get the brightness level of the display - - @param[out] level brightness level - - @return \link DisplayError \endlink - */ - virtual DisplayError GetPanelBrightness(int *level) = 0; - - /*! @brief Method to set layer mixer resolution. - - @param[in] width layer mixer width - @param[in] height layer mixer height - - @return \link DisplayError \endlink - */ - virtual DisplayError SetMixerResolution(uint32_t width, uint32_t height) = 0; - - /*! @brief Method to get layer mixer resolution. - - @param[out] width layer mixer width - @param[out] height layer mixer height - - @return \link DisplayError \endlink - */ - virtual DisplayError GetMixerResolution(uint32_t *width, uint32_t *height) = 0; - - /*! @brief Method to set frame buffer configuration. - - @param[in] variable_info \link DisplayConfigVariableInfo \endlink - - @return \link DisplayError \endlink - */ - virtual DisplayError SetFrameBufferConfig(const DisplayConfigVariableInfo &variable_info) = 0; - - /*! @brief Method to get frame buffer configuration. - - @param[out] variable_info \link DisplayConfigVariableInfo \endlink - - @return \link DisplayError \endlink - */ - virtual DisplayError GetFrameBufferConfig(DisplayConfigVariableInfo *variable_info) = 0; - - /*! @brief Method to set detail enhancement data. - - @param[in] de_data \link DisplayDetailEnhancerData \endlink - - @return \link DisplayError \endlink - */ - virtual DisplayError SetDetailEnhancerData(const DisplayDetailEnhancerData &de_data) = 0; - - /*! @brief Method to get display port information. - - @param[out] port \link DisplayPort \endlink - - @return \link DisplayError \endlink - */ - virtual DisplayError GetDisplayPort(DisplayPort *port) = 0; - - /*! @brief Method to query whether it is Primrary device. - - @return true if this interface is primary. - */ - virtual bool IsPrimaryDisplay() = 0; - - /*! @brief Method to toggle composition types handling by SDM. - - @details Client shall call this method to request SDM to enable/disable a specific type of - layer composition. If client disables a composition type, SDM will not handle any of the layer - composition using the disabled method in a draw cycle. On lack of resources to handle all - layers using other enabled composition methods, Prepare() will return an error. - - Request to toggle composition type is applied from subsequent draw cycles. - - Default state of all defined composition types is enabled. - - @param[in] composition_type \link LayerComposition \endlink - @param[in] enable \link enable composition type \endlink - - @return \link DisplayError \endlink - - @sa Prepare - */ - virtual DisplayError SetCompositionState(LayerComposition composition_type, bool enable) = 0; - - /*! @brief Method to check whether a client target with the given properties - can be supported/handled by hardware. - - @param[in] width client target width - @param[in] height client target height - @param[in] format client target format - @param[in] colorMetaData client target colorMetaData - - @return \link DisplayError \endlink - */ - virtual DisplayError GetClientTargetSupport(uint32_t width, uint32_t height, - LayerBufferFormat format, - const ColorMetaData &color_metadata) = 0; - - /* - * Returns a string consisting of a dump of SDM's display and layer related state - * as programmed to driver - */ - virtual std::string Dump() = 0; - - protected: - virtual ~DisplayInterface() { } -}; - -} // namespace sdm - -#endif // __DISPLAY_INTERFACE_H__ - diff --git a/sdm/include/core/layer_buffer.h b/sdm/include/core/layer_buffer.h deleted file mode 100644 index 649dda4a..00000000 --- a/sdm/include/core/layer_buffer.h +++ /dev/null @@ -1,293 +0,0 @@ -/* -* Copyright (c) 2014, 2016-2017, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted -* provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright notice, this list of -* conditions and the following disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its contributors may be used to -* endorse or promote products derived from this software without specific prior written -* permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/*! @file layer_buffer.h - @brief File for layer buffer structure. - -*/ -#ifndef __LAYER_BUFFER_H__ -#define __LAYER_BUFFER_H__ - -#include -#include -#include -#include - -#include "sdm_types.h" - -namespace sdm { - -#define NUM_UBWC_CR_STATS_LAYERS 2 -typedef std::vector> UbwcCrStatsVector; - -/*! @brief This enum represents display layer inverse gamma correction (IGC) types. - - @sa Layer -*/ -enum LayerIGC { - kIGCNotSpecified, //!< IGC is not specified. - kIGCsRGB, //!< sRGB IGC type. -}; - -/*! @brief This enum represents different buffer formats supported by display manager. - - @sa LayerBuffer -*/ -enum LayerBufferFormat { - /* All RGB formats, Any new format will be added towards end of this group to maintain backward - compatibility. - */ - kFormatARGB8888, //!< 8-bits Alpha, Red, Green, Blue interleaved in ARGB order. - kFormatRGBA8888, //!< 8-bits Red, Green, Blue, Alpha interleaved in RGBA order. - kFormatBGRA8888, //!< 8-bits Blue, Green, Red, Alpha interleaved in BGRA order. - kFormatXRGB8888, //!< 8-bits Padding, Red, Green, Blue interleaved in XRGB order. No Alpha. - kFormatRGBX8888, //!< 8-bits Red, Green, Blue, Padding interleaved in RGBX order. No Alpha. - kFormatBGRX8888, //!< 8-bits Blue, Green, Red, Padding interleaved in BGRX order. No Alpha. - kFormatRGBA5551, //!< 5-bits Red, Green, Blue, and 1 bit Alpha interleaved in RGBA order. - kFormatRGBA4444, //!< 4-bits Red, Green, Blue, Alpha interleaved in RGBA order. - kFormatRGB888, //!< 8-bits Red, Green, Blue interleaved in RGB order. No Alpha. - kFormatBGR888, //!< 8-bits Blue, Green, Red interleaved in BGR order. No Alpha. - kFormatRGB565, //!< 5-bit Red, 6-bit Green, 5-bit Blue interleaved in RGB order. No Alpha. - kFormatBGR565, //!< 5-bit Blue, 6-bit Green, 5-bit Red interleaved in BGR order. No Alpha. - kFormatRGBA8888Ubwc, //!< UBWC aligned RGBA8888 format - kFormatRGBX8888Ubwc, //!< UBWC aligned RGBX8888 format - kFormatBGR565Ubwc, //!< UBWC aligned BGR565 format - kFormatRGBA1010102, //!< 10-bits Red, Green, Blue, Alpha interleaved in RGBA order. - kFormatARGB2101010, //!< 10-bits Alpha, Red, Green, Blue interleaved in ARGB order. - kFormatRGBX1010102, //!< 10-bits Red, Green, Blue, Padding interleaved in RGBX order. No Alpha. - kFormatXRGB2101010, //!< 10-bits Padding, Red, Green, Blue interleaved in XRGB order. No Alpha. - kFormatBGRA1010102, //!< 10-bits Blue, Green, Red, Alpha interleaved in BGRA order. - kFormatABGR2101010, //!< 10-bits Alpha, Blue, Green, Red interleaved in ABGR order. - kFormatBGRX1010102, //!< 10-bits Blue, Green, Red, Padding interleaved in BGRX order. No Alpha. - kFormatXBGR2101010, //!< 10-bits Padding, Blue, Green, Red interleaved in XBGR order. No Alpha. - kFormatRGBA1010102Ubwc, //!< UBWC aligned RGBA1010102 format - kFormatRGBX1010102Ubwc, //!< UBWC aligned RGBX1010102 format - kFormatRGB101010, // 10-bits Red, Green, Blue, interleaved in RGB order. No Alpha. - - /* All YUV-Planar formats, Any new format will be added towards end of this group to maintain - backward compatibility. - */ - kFormatYCbCr420Planar = 0x100, //!< Y-plane: y(0), y(1), y(2) ... y(n) - //!< 2x2 subsampled U-plane: u(0), u(2) ... u(n-1) - //!< 2x2 subsampled V-plane: v(0), v(2) ... v(n-1) - - kFormatYCrCb420Planar, //!< Y-plane: y(0), y(1), y(2) ... y(n) - //!< 2x2 subsampled V-plane: v(0), v(2) ... v(n-1) - //!< 2x2 subsampled U-plane: u(0), u(2) ... u(n-1) - - kFormatYCrCb420PlanarStride16, //!< kFormatYCrCb420Planar with stride aligned to 16 bytes - - /* All YUV-Semiplanar formats, Any new format will be added towards end of this group to - maintain backward compatibility. - */ - kFormatYCbCr420SemiPlanar = 0x200, //!< Y-plane: y(0), y(1), y(2) ... y(n) - //!< 2x2 subsampled interleaved UV-plane: - //!< u(0), v(0), u(2), v(2) ... u(n-1), v(n-1) - //!< aka NV12. - - kFormatYCrCb420SemiPlanar, //!< Y-plane: y(0), y(1), y(2) ... y(n) - //!< 2x2 subsampled interleaved VU-plane: - //!< v(0), u(0), v(2), u(2) ... v(n-1), u(n-1) - //!< aka NV21. - - kFormatYCbCr420SemiPlanarVenus, //!< Y-plane: y(0), y(1), y(2) ... y(n) - //!< 2x2 subsampled interleaved UV-plane: - //!< u(0), v(0), u(2), v(2) ... u(n-1), v(n-1) - - kFormatYCbCr422H1V2SemiPlanar, //!< Y-plane: y(0), y(1), y(2) ... y(n) - //!< vertically subsampled interleaved UV-plane: - //!< u(0), v(1), u(2), v(3) ... u(n-1), v(n) - - kFormatYCrCb422H1V2SemiPlanar, //!< Y-plane: y(0), y(1), y(2) ... y(n) - //!< vertically subsampled interleaved VU-plane: - //!< v(0), u(1), v(2), u(3) ... v(n-1), u(n) - - kFormatYCbCr422H2V1SemiPlanar, //!< Y-plane: y(0), y(1), y(2) ... y(n) - //!< horizontally subsampled interleaved UV-plane: - //!< u(0), v(1), u(2), v(3) ... u(n-1), v(n) - - kFormatYCrCb422H2V1SemiPlanar, //!< Y-plane: y(0), y(1), y(2) ... y(n) - //!< horizontally subsampled interleaved VU-plane: - //!< v(0), u(1), v(2), u(3) ... v(n-1), u(n) - - kFormatYCbCr420SPVenusUbwc, //!< UBWC aligned YCbCr420SemiPlanarVenus format - - kFormatYCrCb420SemiPlanarVenus, //!< Y-plane: y(0), y(1), y(2) ... y(n) - //!< 2x2 subsampled interleaved UV-plane: - //!< v(0), u(0), v(2), u(2) ... v(n-1), u(n-1) - - kFormatYCbCr420P010, //!< 16 bit Y-plane with 5 MSB bits set to 0: - //!< y(0), y(1), y(2) ... y(n) - //!< 2x2 subsampled interleaved 10 bit UV-plane with - //!< 5 MSB bits set to 0: - //!< u(0), v(0), u(2), v(2) ... u(n-1), v(n-1) - //!< aka P010. - - kFormatYCbCr420TP10Ubwc, //!< UBWC aligned YCbCr420TP10 format. - - kFormatYCbCr420P010Ubwc, //!< UBWC aligned YCbCr420P010 format. - - kFormatYCbCr420P010Venus, //!< Venus aligned YCbCr420P010 format. - - /* All YUV-Packed formats, Any new format will be added towards end of this group to maintain - backward compatibility. - */ - kFormatYCbCr422H2V1Packed = 0x300, //!< Y-plane interleaved with horizontally subsampled U/V by - //!< factor of 2 - //!< y(0), u(0), y(1), v(0), y(2), u(2), y(3), v(2) - //!< y(n-1), u(n-1), y(n), v(n-1) - - kFormatCbYCrY422H2V1Packed, - kFormatInvalid = 0xFFFFFFFF, -}; - - -/*! @brief This enum represents different types of 3D formats supported. - - @sa LayerBufferS3DFormat -*/ -enum LayerBufferS3DFormat { - kS3dFormatNone, //!< Layer buffer content is not 3D content. - kS3dFormatLeftRight, //!< Left and Right view of a 3D content stitched left and right. - kS3dFormatRightLeft, //!< Right and Left view of a 3D content stitched left and right. - kS3dFormatTopBottom, //!< Left and RightView of a 3D content stitched top and bottom. - kS3dFormatFramePacking //!< Left and right view of 3D content coded in consecutive frames. -}; - -/*! @brief This structure defines a color sample plane belonging to a buffer format. RGB buffer - formats have 1 plane whereas YUV buffer formats may have upto 4 planes. - - @sa LayerBuffer -*/ -struct LayerBufferPlane { - int fd = -1; //!< File descriptor referring to the buffer associated with this plane. - uint32_t offset = 0; //!< Offset of the plane in bytes from beginning of the buffer. - uint32_t stride = 0; //!< Stride in bytes i.e. length of a scanline including padding. -}; - -/*! @brief This structure defines flags associated with a layer buffer. The 1-bit flag can be set - to ON(1) or OFF(0). - - @sa LayerBuffer -*/ -struct LayerBufferFlags { - union { - struct { - uint32_t secure : 1; //!< This flag shall be set by client to indicate that the - //!< buffer need to be handled securely. - - uint32_t video : 1; //!< This flag shall be set by client to indicate that the - //!< buffer is video/ui buffer. - - uint32_t macro_tile : 1; //!< This flag shall be set by client to indicate that the - //!< buffer format is macro tiled. - - uint32_t interlace : 1; //!< This flag shall be set by the client to indicate that - //!< the buffer has interlaced content. - - uint32_t secure_display : 1; //!< This flag shall be set by the client to indicate that the - //!< secure display session is in progress. Secure display - //!< session can not coexist with non-secure session. - - uint32_t secure_camera : 1; //!< This flag shall be set by the client to indicate that the - //!< buffer is associated with secure camera session. A secure - //!< camera layer can co-exist with non-secure layer(s). - - uint32_t hdr : 1; //!< This flag shall be set by the client to indicate that the - //!< the content is HDR. - }; - - uint32_t flags = 0; //!< For initialization purpose only. - //!< Client shall not refer to it directly. - }; -}; - -/*! @brief This structure defines a layer buffer handle which contains raw buffer and its associated - properties. - - @sa LayerBuffer - @sa LayerStack -*/ -struct LayerBuffer { - uint32_t width = 0; //!< Aligned width of the Layer that this buffer is for. - uint32_t height = 0; //!< Aligned height of the Layer that this buffer is for. - uint32_t unaligned_width = 0; - //!< Unaligned width of the Layer that this buffer is for. - uint32_t unaligned_height = 0; - //!< Unaligned height of the Layer that this buffer is for. - uint32_t size = 0; //!< Size of a single buffer (even if multiple clubbed together) - LayerBufferFormat format = kFormatRGBA8888; //!< Format of the buffer content. - ColorMetaData color_metadata = {}; //!< CSC + Range + Transfer + Matrix + HDR Info - LayerIGC igc = kIGCNotSpecified; //!< IGC that will be applied on this layer. - LayerBufferPlane planes[4] = {}; - //!< Array of planes that this buffer contains. RGB buffer formats - //!< have 1 plane whereas YUV buffer formats may have upto 4 planes - //!< Total number of planes for the buffer will be interpreted based - //!< on the buffer format specified. - - int acquire_fence_fd = -1; //!< File descriptor referring to a sync fence object which will be - //!< signaled when buffer can be read/write by display manager. - //!< This fence object is set by the client during Commit(). For - //!< input buffers client shall signal this fence when buffer - //!< content is available and can be read by display manager. For - //!< output buffers, client shall signal fence when buffer is ready - //!< to be written by display manager. - - //!< This field is used only during Commit() and shall be set to -1 - //!< by the client when buffer is already available for read/write. - - int release_fence_fd = -1; //!< File descriptor referring to a sync fence object which will be - //!< signaled when buffer has been read/written by display manager. - //!< This fence object is set by display manager during Commit(). - //!< For input buffers display manager will signal this fence when - //!< buffer has been consumed. For output buffers, display manager - //!< will signal this fence when buffer is produced. - - //!< This field is used only during Commit() and will be set to -1 - //!< by display manager when buffer is already available for - //!< read/write. - - LayerBufferFlags flags; //!< Flags associated with this buffer. - - LayerBufferS3DFormat s3d_format = kS3dFormatNone; - //!< Represents the format of the buffer content in 3D. This field - //!< could be modified by both client and SDM. - uint64_t buffer_id __attribute__((aligned(8))) = 0; - //!< Specifies the buffer id. - UbwcCrStatsVector ubwc_crstats[NUM_UBWC_CR_STATS_LAYERS] = {}; - //! < UBWC Compression ratio,stats. Stored as a vector of pair of - //! of (tile size, #of tiles) -}; - -// This enum represents buffer layout types. -enum BufferLayout { - kLinear, //!< Linear data - kUBWC, //!< UBWC aligned data - kTPTiled //!< Tightly Packed data -}; - -} // namespace sdm - -#endif // __LAYER_BUFFER_H__ - diff --git a/sdm/include/core/layer_stack.h b/sdm/include/core/layer_stack.h deleted file mode 100644 index 3dd1c6f4..00000000 --- a/sdm/include/core/layer_stack.h +++ /dev/null @@ -1,414 +0,0 @@ -/* -* Copyright (c) 2014 - 2017, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted -* provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright notice, this list of -* conditions and the following disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its contributors may be used to -* endorse or promote products derived from this software without specific prior written -* permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/*! @file layer_stack.h - @brief File for display layer stack structure which represents a drawing buffer. - - @details Display layer is a drawing buffer object which will be blended with other drawing buffers - under blending rules. -*/ -#ifndef __LAYER_STACK_H__ -#define __LAYER_STACK_H__ - -#include -#include - -#include -#include - -#include "layer_buffer.h" -#include "sdm_types.h" - -namespace sdm { - -/*! @brief This enum represents display layer blending types. - - @sa Layer -*/ -enum LayerBlending { - kBlendingPremultiplied, //!< Pixel color is expressed using premultiplied alpha in RGBA tuples. - //!< If plane alpha is less than 0xFF, apply modulation as well. - //!< pixel.rgb = src.rgb + dest.rgb x (1 - src.a) - - kBlendingOpaque, //!< Pixel color is expressed using straight alpha in color tuples. It - //!< is constant blend operation. The layer would appear opaque if plane - //!< alpha is 0xFF. - - kBlendingCoverage, //!< Pixel color is expressed using straight alpha in color tuples. If - //!< plane alpha is less than 0xff, apply modulation as well. - //!< pixel.rgb = src.rgb x src.a + dest.rgb x (1 - src.a) -}; - -/*! @brief This enum represents display layer composition types. - - @sa Layer -*/ -enum LayerComposition { - /* ==== List of composition types set by SDM === */ - /* These composition types represent SDM composition decision for the layers which need to - be blended. Composition types are set during Prepare() by SDM. - Client can set default composition type to any of the below before calling into Prepare(), - however client's input value is ignored and does not play any role in composition decision. - */ - kCompositionGPU, //!< This layer will be drawn onto the target buffer by GPU. Display - //!< device will mark the layer for GPU composition if it can not - //!< handle composition for it. - //!< This composition type is used only if GPUTarget layer is provided - //!< in a composition cycle. - - kCompositionGPUS3D, //!< This layer will be drawn onto the target buffer in s3d mode by GPU. - //!< Display device will mark the layer for GPU composition if it can - //!< not handle composition for it. - //!< This composition type is used only if GPUTarget layer is provided - //!< in a composition cycle. - - kCompositionSDE, //!< This layer will be composed by SDE. It must not be composed by - //!< GPU or Blit. - - kCompositionCursor, // This cursor layer can receive async position updates irrespective of - // dedicated h/w cursor usage. It must not be composed by GPU or Blit - - kCompositionHybrid, //!< This layer will be drawn by a blit engine and SDE together. - //!< Display device will split the layer, update the blit rectangle - //!< that need to be composed by a blit engine and update original - //!< source rectangle that will be composed by SDE. - //!< This composition type is used only if GPUTarget and BlitTarget - //!< layers are provided in a composition cycle. - - kCompositionBlit, //!< This layer will be composed using Blit Engine. - //!< This composition type is used only if BlitTarget layer is provided - //!< in a composition cycle. - - /* === List of composition types set by Client === */ - /* These composition types represent target buffer layers onto which GPU or Blit will draw if SDM - decide to have some or all layers drawn by respective composition engine. - Client must provide a target buffer layer, if respective composition type is not disabled by - an explicit call to SetCompositionState() method. If a composition type is not disabled, - providing a target buffer layer is optional. If SDM is unable to handle layers without support - of such a composition engine, Prepare() call will return failure. - */ - kCompositionGPUTarget, //!< This layer will hold result of composition for layers marked for - //!< GPU composition. - //!< If display device does not set any layer for GPU composition then - //!< this layer would be ignored. Else, this layer will be composed - //!< with other layers marked for SDE composition by SDE. - //!< Only one layer shall be marked as target buffer by the caller. - //!< GPU target layer shall be placed after all application layers - //!< in the layer stack. - - kCompositionBlitTarget, //!< This layer will hold result of composition for blit rectangles - //!< from the layers marked for hybrid composition. Nth blit rectangle - //!< in a layer shall be composed onto Nth blit target. - //!< If display device does not set any layer for hybrid composition - //!< then this would be ignored. - //!< Blit target layers shall be placed after GPUTarget in the layer - //!< stack. -}; - -/*! @brief This structure defines rotation and flip values for a display layer. - - @sa Layer -*/ -struct LayerTransform { - float rotation = 0.0f; //!< Left most pixel coordinate. - bool flip_horizontal = false; //!< Mirror reversal of the layer across a horizontal axis. - bool flip_vertical = false; //!< Mirror reversal of the layer across a vertical axis. - - bool operator==(const LayerTransform& transform) const { - return (rotation == transform.rotation && flip_horizontal == transform.flip_horizontal && - flip_vertical == transform.flip_vertical); - } - - bool operator!=(const LayerTransform& transform) const { - return !operator==(transform); - } -}; - -/*! @brief This structure defines flags associated with a layer. The 1-bit flag can be set to ON(1) - or OFF(0). - - @sa LayerBuffer -*/ -struct LayerFlags { - union { - struct { - uint32_t skip : 1; //!< This flag shall be set by client to indicate that this layer - //!< will be handled by GPU. Display Device will not consider it - //!< for composition. - - uint32_t updating : 1; //!< This flag shall be set by client to indicate that this is - //!< updating non-updating. so strategy manager will mark them for - //!< SDE/GPU composition respectively when the layer stack qualifies - //!< for cache based composition. - - uint32_t solid_fill : 1; - //!< This flag shall be set by client to indicate that this layer - //!< is for solid fill without input buffer. Display Device will - //!< use SDE HW feature to achieve it. - - uint32_t cursor : 1; //!< This flag shall be set by client to indicate that this layer - //!< is a cursor - //!< Display Device may handle this layer using HWCursor - - uint32_t single_buffer : 1; //!< This flag shall be set by client to indicate that the layer - //!< uses only a single buffer that will not be swapped out - }; - - uint32_t flags = 0; //!< For initialization purpose only. - //!< Client shall not refer it directly. - }; -}; - -/*! @brief This structure defines flags associated with the layer requests. The 1-bit flag can be - set to ON(1) or OFF(0). - - @sa Layer -*/ -struct LayerRequestFlags { - union { - struct { - uint32_t tone_map : 1; //!< This flag will be set by SDM when the layer needs tone map - uint32_t secure: 1; //!< This flag will be set by SDM when the layer must be secure - uint32_t flip_buffer: 1; //!< This flag will be set by SDM when the layer needs FBT flip - }; - uint32_t request_flags = 0; //!< For initialization purpose only. - //!< Shall not be refered directly. - }; -}; - -/*! @brief This structure defines LayerRequest. - Includes width/height/format of the LayerRequest. - - SDM shall set the properties of LayerRequest to be used by the client - - @sa LayerRequest -*/ -struct LayerRequest { - LayerRequestFlags flags; // Flags associated with this request - LayerBufferFormat format = kFormatRGBA8888; // Requested format - uint32_t width = 0; // Requested unaligned width. - uint32_t height = 0; // Requested unalighed height -}; - -/*! @brief This structure defines flags associated with a layer stack. The 1-bit flag can be set to - ON(1) or OFF(0). - - @sa LayerBuffer -*/ -struct LayerStackFlags { - union { - struct { - uint32_t geometry_changed : 1; //!< This flag shall be set by client to indicate that the - //!< layer set passed to Prepare() has changed by more than - //!< just the buffer handles and acquire fences. - - uint32_t skip_present : 1; //!< This flag will be set to true, if the current layer - //!< stack contains skip layers. - - uint32_t video_present : 1; //!< This flag will be set to true, if current layer stack - //!< contains video. - - uint32_t secure_present : 1; //!< This flag will be set to true, if the current layer - //!< stack contains secure layers. - - uint32_t animating : 1; //!< This flag shall be set by client to indicate that the - //!< current frame is animating.i - - uint32_t attributes_changed : 1; - //!< This flag shall be set by client to indicate that the - //!< current frame has some properties changed and - //!< needs re-config. - - uint32_t cursor_present : 1; //!< This flag will be set to true if the current layer - //!< stack contains cursor layer. - - uint32_t single_buffered_layer_present : 1; //!< Set if stack has single buffered layer - - uint32_t s3d_mode_present : 1; //!< This flag will be set to true, if the current layer - //!< stack contains s3d layer, and the layer stack can enter - //!< s3d mode. - - uint32_t post_processed_output : 1; // If output_buffer should contain post processed output - // This applies only to primary displays currently - - uint32_t hdr_present : 1; //!< Set if stack has HDR content - }; - - uint32_t flags = 0; //!< For initialization purpose only. - //!< Client shall not refer it directly. - }; -}; - -/*! @brief This structure defines a rectanglular area inside a display layer. - - @sa LayerRectArray -*/ -struct LayerRect { - float left = 0.0f; //!< Left-most pixel coordinate. - float top = 0.0f; //!< Top-most pixel coordinate. - float right = 0.0f; //!< Right-most pixel coordinate. - float bottom = 0.0f; //!< Bottom-most pixel coordinate. - - LayerRect() = default; - - LayerRect(float l, float t, float r, float b) : left(l), top(t), right(r), bottom(b) { } - - bool operator==(const LayerRect& rect) const { - return left == rect.left && right == rect.right && top == rect.top && bottom == rect.bottom; - } - - bool operator!=(const LayerRect& rect) const { - return !operator==(rect); - } -}; - -/*! @brief This structure defines an array of display layer rectangles. - - @sa LayerRect -*/ -struct LayerRectArray { - LayerRect *rect = NULL; //!< Pointer to first element of array. - uint32_t count = 0; //!< Number of elements in the array. -}; - -/*! @brief This structure defines solidfill structure. - - @sa LayerSolidFill -*/ -struct LayerSolidFill { - uint32_t bit_depth = 0; //!< Bit depth of solid fill colors - uint32_t red = 0; //!< Red value - uint32_t green = 0; //!< Green value - uint32_t blue = 0; //!< Blue value - uint32_t alpha = 0; //!< Alpha value -}; - -/*! @brief This structure defines display layer object which contains layer properties and a drawing - buffer. - - @sa LayerArray -*/ -struct Layer { - LayerBuffer input_buffer = {}; //!< Buffer to be composed. - //!< If this remains unchanged between two - //!< consecutive Prepare() calls and - //!< geometry_changed flag is not set for the - //!< second call, then the display device will - //!< assume that buffer content has not - //!< changed. - - LayerComposition composition = kCompositionGPU; //!< Composition type which can be set by either - //!< the client or the display device. This value - //!< should be preserved between Prepare() and - //!< Commit() calls. - - LayerRect src_rect = {}; //!< Rectangular area of the layer buffer to - //!< consider for composition. - - LayerRect dst_rect = {}; //!< The target position where the frame will be - //!< displayed. Cropping rectangle is scaled to - //!< fit into this rectangle. The origin is the - //!< top-left corner of the screen. - - std::vector visible_regions = {}; //!< Visible rectangular areas in screen space. - //!< The visible region includes areas overlapped - //!< by a translucent layer. - - std::vector dirty_regions = {}; //!< Rectangular areas in the current frames - //!< that have changed in comparison to - //!< previous frame. - - std::vector blit_regions = {}; //!< Rectangular areas of this layer which need - //!< to be composed to blit target. Display - //!< device will update blit rectangles if a - //!< layer composition is set as hybrid. Nth blit - //!< rectangle shall be composed onto Nth blit - //!< target. - - LayerBlending blending = kBlendingPremultiplied; //!< Blending operation which need to be - //!< applied on the layer buffer during - //!< composition. - - LayerTransform transform = {}; //!< Rotation/Flip operations which need to be - //!< applied to the layer buffer during - //!< composition. - - uint8_t plane_alpha = 0xff; //!< Alpha value applied to the whole layer. - //!< Value of each pixel is computed as: - //!< if(kBlendingPremultiplied) { - //!< pixel.RGB = pixel.RGB * planeAlpha/255 - //!< } - //!< pixel.a = pixel.a * planeAlpha - - uint32_t frame_rate = 0; //!< Rate at which frames are being updated for - //!< this layer. - - uint32_t solid_fill_color = 0; //!< TODO: Remove this field when fb support - //! is deprecated. - //!< Solid color used to fill the layer when - //!< no content is associated with the layer. - - LayerFlags flags; //!< Flags associated with this layer. - - LayerRequest request = {}; //!< o/p - request on this Layer by SDM. - - Lut3d lut_3d = {}; //!< o/p - Populated by SDM when tone mapping is - //!< needed on this layer. - LayerSolidFill solid_fill_info = {}; //!< solid fill info along with depth. -}; - -/*! @brief This structure defines a layer stack that contains layers which need to be composed and - rendered onto the target. - - @sa DisplayInterface::Prepare - @sa DisplayInterface::Commit -*/ - -typedef std::pair PrimariesTransfer; - -struct LayerStack { - std::vector layers = {}; //!< Vector of layer pointers. - - int retire_fence_fd = -1; //!< File descriptor referring to a sync fence object which - //!< will be signaled when this composited frame has been - //!< replaced on screen by a subsequent frame on a physical - //!< display. The fence object is created and returned during - //!< Commit(). Client shall close the returned file - //!< descriptor. - //!< NOTE: This field applies to a physical display only. - - LayerBuffer *output_buffer = NULL; //!< Pointer to the buffer where composed buffer would be - //!< rendered for virtual displays. - //!< NOTE: This field applies to a virtual display only. - - LayerStackFlags flags; //!< Flags associated with this layer set. - - PrimariesTransfer blend_cs = {ColorPrimaries_BT709_5, Transfer_sRGB}; - //!< o/p - Blending color space updated by SDM -}; - -} // namespace sdm - -#endif // __LAYER_STACK_H__ - diff --git a/sdm/include/core/sdm_types.h b/sdm/include/core/sdm_types.h deleted file mode 100644 index b624049e..00000000 --- a/sdm/include/core/sdm_types.h +++ /dev/null @@ -1,95 +0,0 @@ -/* -* Copyright (c) 2014 - 2018, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/*! @file sdm_types.h - @brief This file contains miscellaneous data types used across display interfaces. -*/ -#ifndef __SDM_TYPES_H__ -#define __SDM_TYPES_H__ - -namespace sdm { - -/*! @brief This enum represents different error codes that display interfaces may return. -*/ -enum DisplayError { - kErrorNone, //!< Call executed successfully. - kErrorUndefined, //!< An unspecified error has occured. - kErrorNotSupported, //!< Requested operation is not supported. - kErrorPermission, //!< Operation is not permitted in current state. - kErrorVersion, //!< Client is using advanced version of interfaces and calling into an - //!< older version of display library. - kErrorDataAlignment, //!< Client data structures are not aligned on naturual boundaries. - kErrorInstructionSet, //!< 32-bit client is calling into 64-bit library or vice versa. - kErrorParameters, //!< Invalid parameters passed to a method. - kErrorFileDescriptor, //!< Invalid file descriptor. - kErrorMemory, //!< System is running low on memory. - kErrorResources, //!< Not enough hardware resources available to execute call. - kErrorHardware, //!< A hardware error has occured. - kErrorTimeOut, //!< The operation has timed out to prevent client from waiting forever. - kErrorShutDown, //!< Driver is processing shutdown sequence - kErrorPerfValidation, //!< Bandwidth or Clock requirement validation failure. - kErrorNoAppLayers, //!< No App layer(s) in the draw cycle. - kErrorRotatorValidation, //!< Rotator configuration validation failure. - kErrorNotValidated, //!< Draw cycle has not been validated. - kErrorCriticalResource, //!< Critical resource allocation has failed. -}; - -/*! @brief This structure is defined for client and library compatibility check purpose only. This - structure is used in SDM_VERSION_TAG definition only. Client should not refer it directly for - any purpose. -*/ -struct SDMCompatibility { - char c1; - int i1; - char c2; - int i2; -}; - -/*! @brief This enum represents different modules/logical unit tags that a log message may - be associated with. Client may use this to filter messages for dynamic logging. - -*/ -enum DebugTag { - kTagNone, //!< Debug log is not tagged. This type of logs should always be printed. - kTagResources, //!< Debug log is tagged for resource management. - kTagStrategy, //!< Debug log is tagged for strategy decisions. - kTagCompManager, //!< Debug log is tagged for composition manager. - kTagDriverConfig, //!< Debug log is tagged for driver config. - kTagRotator, //!< Debug log is tagged for rotator. - kTagScalar, //!< Debug log is tagged for Scalar Helper. - kTagQDCM, //!< Debug log is tagged for display QDCM color managing. - kTagQOSClient, //!< Debug log is tagged for Qos client. - kTagDisplay, //!< Debug log is tagged for display core logs. - kTagClient, //!< Debug log is tagged for SDM client. -}; - -} // namespace sdm - -#endif // __SDM_TYPES_H__ - diff --git a/sdm/include/core/socket_handler.h b/sdm/include/core/socket_handler.h deleted file mode 100644 index e7fe00e4..00000000 --- a/sdm/include/core/socket_handler.h +++ /dev/null @@ -1,75 +0,0 @@ -/* -* Copyright (c) 2016, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/*! @file socket_handler.h - @brief Interface file for platform specific Socket Handler. - - @details SDM will use this interface to get the platform specific Socket fd. -*/ - -#ifndef __SOCKET_HANDLER_H__ -#define __SOCKET_HANDLER_H__ - -namespace sdm { - -/*! @brief This enum represents Socket types, for which SDM can request the fd. - -*/ -enum SocketType { - kDpps, //!< Socket for Dpps -}; - -/*! @brief Socket handler implemented by the client - - @details This class declares prototype for SocketHandler methods which must be - implemented by client. SDM will use these methods to get the platform specific Socket fd. - - @sa CoreInterface::CreateCore -*/ -class SocketHandler { - public: - /*! @brief Method to get the platform specific Socket fd for a given socket type. - - @details This method returns the platform specific Socket fd for a given socket type. - It is the responsibility of the caller to close the file descriptor. - - @param[in] socket_type - - @return \link int \endlink - */ - - virtual int GetSocketFd(SocketType socket_type) = 0; - - protected: - virtual ~SocketHandler() { } -}; - -} // namespace sdm - -#endif // __SOCKET_HANDLER_H__ diff --git a/sdm/include/private/color_interface.h b/sdm/include/private/color_interface.h deleted file mode 100644 index 9802e1d7..00000000 --- a/sdm/include/private/color_interface.h +++ /dev/null @@ -1,106 +0,0 @@ -/* Copyright (c) 2015-2018, The Linux Foundataion. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -* -*/ - -#ifndef __COLOR_INTERFACE_H__ -#define __COLOR_INTERFACE_H__ - -#include -#include "core/sdm_types.h" -#include "color_params.h" - -namespace sdm { - -#define COLORMGR_LIBRARY_NAME "libsdm-color.so" -#define CREATE_COLOR_INTERFACE_NAME "CreateColorInterface" -#define DESTROY_COLOR_INTERFACE_NAME "DestroyColorInterface" -#define COLOR_REVISION_MAJOR (1) -#define COLOR_REVISION_MINOR (0) - -#define COLOR_VERSION_TAG ((uint16_t)((COLOR_REVISION_MAJOR << 8) | COLOR_REVISION_MINOR)) - -class ColorInterface; - -typedef DisplayError (*CreateColorInterface)(uint16_t version, DisplayType type, - const PPHWAttributes &attributes, - ColorInterface **interface); - -typedef DisplayError (*DestroyColorInterface)(DisplayType type); - -class ColorModeInterface { - public: - virtual DisplayError ColorIntfGetActiveColorParam(uint32_t hint, uint32_t display_id, - void* data) = 0; - virtual DisplayError ColorIntfSetActiveColorParam(uint32_t hint, uint32_t display_id, - void* data) = 0; - virtual DisplayError ColorIntfSetHdrInterface(void *hdr_intf) = 0; - - protected: - virtual ~ColorModeInterface() {} -}; - -extern "C" ColorModeInterface* GetColorModeInterface(DisplayType type); -extern "C" void ReleaseColorModeInterface(DisplayType type); - -class ColorInterface { - public: - virtual DisplayError ColorSVCRequestRoute(const PPDisplayAPIPayload &in_payload, - PPDisplayAPIPayload *out_payload, - PPFeaturesConfig *out_features, - PPPendingParams *pending_action) = 0; - - virtual DisplayError ApplyDefaultDisplayMode(PPFeaturesConfig *out_features) = 0; - - virtual DisplayError ColorIntfSetColorTransform(PPFeaturesConfig *out_features, - uint32_t disp_id, uint32_t length, - const double *trans_data) = 0; - - virtual DisplayError ColorIntfSetDisplayMode(PPFeaturesConfig *out_features, - uint32_t disp_id, int32_t mode_id) = 0; - - virtual DisplayError ColorIntfGetNumDisplayModes(PPFeaturesConfig *out_features, - uint32_t disp_id, uint32_t *mode_cnt) = 0; - - virtual DisplayError ColorIntfEnumerateDisplayModes(PPFeaturesConfig *out_features, - uint32_t disp_id, SDEDisplayMode *modes, - uint32_t *mode_cnt) = 0; - virtual DisplayError ColorIntfGetModeInfo(PPFeaturesConfig *out_features, - uint32_t disp_id, int32_t mode_id, - AttrVal *query) = 0; - virtual DisplayError ColorIntfGetDefaultModeID(PPFeaturesConfig *out_features, - uint32_t disp_id, int32_t *mode_id) = 0; - virtual DisplayError ColorIntfGetActiveMode(PPFeaturesConfig *out_features, - int32_t disp_id, std::string *mode) = 0; - - protected: - virtual ~ColorInterface() {} -}; - -} // namespace sdm - -#endif // __COLOR_INTERFACE_H__ diff --git a/sdm/include/private/color_params.h b/sdm/include/private/color_params.h deleted file mode 100644 index b71266cf..00000000 --- a/sdm/include/private/color_params.h +++ /dev/null @@ -1,652 +0,0 @@ -/* Copyright (c) 2015-2018, The Linux Foundataion. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -* -*/ - -#ifndef __COLOR_PARAMS_H__ -#define __COLOR_PARAMS_H__ - -#include -#include -#include -#include -#include -#include - -#include - -#include "hw_info_types.h" - -namespace sdm { - -// Bitmap Pending action to indicate to the caller what's pending to be taken care of. -enum PendingAction { - kInvalidating = BITMAP(0), - kApplySolidFill = BITMAP(1), - kDisableSolidFill = BITMAP(2), - kEnterQDCMMode = BITMAP(3), - kExitQDCMMode = BITMAP(4), - kSetPanelBrightness = BITMAP(5), - kEnableFrameCapture = BITMAP(6), - kDisableFrameCapture = BITMAP(7), - kConfigureDetailedEnhancer = BITMAP(8), - kModeSet = BITMAP(10), - kGetDetailedEnhancerData = BITMAP(21), - kNoAction = BITMAP(31), -}; - -static const uint32_t kOpsEnable = BITMAP(0); -static const uint32_t kOpsRead = BITMAP(1); -static const uint32_t kOpsWrite = BITMAP(2); -static const uint32_t kOpsDisable = BITMAP(3); - -static const uint32_t kOpsGc8BitRoundEnable = BITMAP(4); - -static const uint32_t kPaHueEnable = BITMAP(4); -static const uint32_t kPaSatEnable = BITMAP(5); -static const uint32_t kPaValEnable = BITMAP(6); -static const uint32_t kPaContEnable = BITMAP(7); - -static const uint32_t kPaSixZoneEnable = BITMAP(8); -static const uint32_t kPaSkinEnable = BITMAP(9); -static const uint32_t kPaSkyEnable = BITMAP(10); -static const uint32_t kPaFoliageEnable = BITMAP(11); - -static const uint32_t kLeftSplitMode = BITMAP(28); // 0x10000000 -static const uint32_t kRightSplitMode = BITMAP(29); // 0x20000000 - -static const int32_t kInvalidModeId = -1; - -static const std::string kDynamicRangeAttribute = "DynamicRange"; -static const std::string kColorGamutAttribute = "ColorGamut"; -static const std::string kPictureQualityAttribute = "PictureQuality"; - -static const std::string kHdr = "hdr"; -static const std::string kSdr = "sdr"; - -static const std::string kNative = "native"; -static const std::string kDcip3 = "dcip3"; -static const std::string kSrgb = "srgb"; -static const std::string kDisplayP3 = "display_p3"; - -static const std::string kVivid = "vivid"; -static const std::string kSharp = "sharp"; -static const std::string kStandard = "standard"; -static const std::string kAmazon = "amazon"; -static const std::string kNetflix = "netflix"; - -// Enum to identify type of dynamic range of color mode. -enum DynamicRangeType { - kSdrType, - kHdrType, -}; - -// ENUM to identify different Postprocessing feature block to program. -// Note: For each new entry added here, also need update hw_interface::GetPPFeaturesVersion<> -// AND HWPrimary::SetPPFeatures<>. -enum PPGlobalColorFeatureID { - kGlobalColorFeaturePcc, - kGlobalColorFeatureIgc, - kGlobalColorFeaturePgc, - kMixerColorFeatureGc, - kGlobalColorFeaturePaV2, - kGlobalColorFeatureDither, - kGlobalColorFeatureGamut, - kGlobalColorFeaturePADither, - kMaxNumPPFeatures, -}; - -struct PPPendingParams { - int32_t action = kNoAction; - void *params = NULL; -}; - -struct PPColorInfo { - uint32_t r_bitdepth = 0; - uint32_t r = 0; - uint32_t g_bitdepth = 0; - uint32_t g = 0; - uint32_t b_bitdepth = 0; - uint32_t b = 0; -}; - -struct PPColorFillParams { - uint32_t flags = 0; - struct { - uint32_t width = 0; - uint32_t height = 0; - int32_t x = 0; - int32_t y = 0; - } rect; - - PPColorInfo color; -}; - -struct PPFeatureVersion { - // SDE ASIC versioning its PP block at each specific feature level. - static const uint32_t kSDEPpVersionInvalid = 0; - static const uint32_t kSDEIgcV17 = 1; - static const uint32_t kSDEPgcV17 = 5; - static const uint32_t kSDEDitherV17 = 7; - static const uint32_t kSDEGamutV17 = 9; - static const uint32_t kSDEPaV17 = 11; - static const uint32_t kSDEPccV17 = 13; - static const uint32_t kSDELegacyPP = 15; - static const uint32_t kSDEPADitherV17 = 16; - static const uint32_t kSDEIgcV30 = 17; - static const uint32_t kSDEGamutV4 = 18; - static const uint32_t kSDEPccV4 = 19; - - uint32_t version[kMaxNumPPFeatures]; - PPFeatureVersion() { memset(version, 0, sizeof(version)); } -}; - -struct PPHWAttributes : HWResourceInfo, HWPanelInfo, DisplayConfigVariableInfo { - char panel_name[256] = "generic_panel"; - PPFeatureVersion version; - int panel_max_brightness = 0; - - void Set(const HWResourceInfo &hw_res, const HWPanelInfo &panel_info, - const DisplayConfigVariableInfo &attr, const PPFeatureVersion &feature_ver); -}; - -struct PPDisplayAPIPayload { - bool own_payload = false; // to indicate if *payload is owned by this or just a reference. - uint32_t size = 0; - uint8_t *payload = NULL; - - PPDisplayAPIPayload() = default; - PPDisplayAPIPayload(uint32_t size, uint8_t *param) - : size(size), payload(param) {} - - template - DisplayError CreatePayload(T *&output) { - DisplayError ret = kErrorNone; - - payload = new uint8_t[sizeof(T)](); - if (!payload) { - ret = kErrorMemory; - output = NULL; - } else { - this->size = sizeof(T); - output = reinterpret_cast(payload); - own_payload = true; - } - return ret; - } - - DisplayError CreatePayloadBytes(uint32_t size_in_bytes, uint8_t **output) { - DisplayError ret = kErrorNone; - - payload = new uint8_t[size_in_bytes](); - if (!payload) { - ret = kErrorMemory; - *output = NULL; - } else { - this->size = size_in_bytes; - *output = payload; - own_payload = true; - } - return ret; - } - - inline void DestroyPayload() { - if (payload && own_payload) { - delete[] payload; - payload = NULL; - size = 0; - } else { - payload = NULL; - size = 0; - } - } -}; - -struct PPRectInfo { - uint32_t width; - uint32_t height; - int32_t x; - int32_t y; -}; - -typedef enum { - PP_PIXEL_FORMAT_NONE = 0, - PP_PIXEL_FORMAT_RGB_888, - PP_PIXEL_FORMAT_RGB_2101010, - PP_PIXEL_FORMAT_MAX, - PP_PIXEL_FORMAT_FORCE32BIT = 0x7FFFFFFF, -} PPPixelFormats; - -struct PPFrameCaptureInputParams { - PPRectInfo rect; - PPPixelFormats out_pix_format; - uint32_t flags; -}; - -struct PPFrameCaptureData { - PPFrameCaptureInputParams input_params; - uint8_t *buffer; - uint32_t buffer_stride; - uint32_t buffer_size; -}; - -static const uint32_t kDeTuningFlagSharpFactor = 0x01; -static const uint32_t kDeTuningFlagClip = 0x02; -static const uint32_t kDeTuningFlagThrQuiet = 0x04; -static const uint32_t kDeTuningFlagThrDieout = 0x08; -static const uint32_t kDeTuningFlagThrLow = 0x10; -static const uint32_t kDeTuningFlagThrHigh = 0x20; -static const uint32_t kDeTuningFlagContentQualLevel = 0x40; - -typedef enum { - kDeContentQualUnknown, - kDeContentQualLow, - kDeContentQualMedium, - kDeContentQualHigh, - kDeContentQualMax, -} PPDEContentQualLevel; - -typedef enum { - kDeContentTypeUnknown, - kDeContentTypeVideo, - kDeContentTypeGraphics, - kDeContentTypeMax, -} PPDEContentType; - -struct PPDETuningCfg { - uint32_t flags = 0; - int32_t sharp_factor = 0; - uint16_t thr_quiet = 0; - uint16_t thr_dieout = 0; - uint16_t thr_low = 0; - uint16_t thr_high = 0; - uint16_t clip = 0; - PPDEContentQualLevel quality = kDeContentQualUnknown; - PPDEContentType content_type = kDeContentTypeUnknown; -}; - -struct PPDETuningCfgData { - uint32_t cfg_en = 0; - PPDETuningCfg params; - bool cfg_pending = false; -}; - -struct SDEGamutCfg { - static const int kGamutTableNum = 4; - static const int kGamutScaleoffTableNum = 3; - static const int kGamutTableSize = 1229; - static const int kGamutTableCoarse13Size = 550; - static const int kGamutTableCoarseSize = 32; - static const int kGamutScaleoffSize = 16; - uint32_t mode; - uint32_t map_en; - uint32_t tbl_size[kGamutTableNum]; - uint32_t *c0_data[kGamutTableNum]; - uint32_t *c1_c2_data[kGamutTableNum]; - uint32_t tbl_scale_off_sz[kGamutScaleoffTableNum]; - uint32_t *scale_off_data[kGamutScaleoffTableNum]; -}; - -struct SDEPccCoeff { - uint32_t c = 0; - uint32_t r = 0; - uint32_t g = 0; - uint32_t b = 0; - uint32_t rg = 0; - uint32_t gb = 0; - uint32_t rb = 0; - uint32_t rgb = 0; -}; - -struct SDEPccCfg { - SDEPccCoeff red; - SDEPccCoeff green; - SDEPccCoeff blue; - - static SDEPccCfg *Init(uint32_t arg __attribute__((__unused__))); - SDEPccCfg *GetConfig() { return this; } -}; - -struct SDEPccV4Coeff { - uint32_t c = 0; - uint32_t r = 0; - uint32_t g = 0; - uint32_t b = 0; - uint32_t rg = 0; - uint32_t gb = 0; - uint32_t rb = 0; - uint32_t rgb = 0; - uint32_t rr = 0; - uint32_t gg = 0; - uint32_t bb = 0; -}; - -struct SDEPccV4Cfg { - SDEPccV4Coeff red; - SDEPccV4Coeff green; - SDEPccV4Coeff blue; - - static SDEPccV4Cfg *Init(uint32_t arg __attribute__((__unused__))); - SDEPccV4Cfg *GetConfig() { return this; } -}; - -struct SDEDitherCfg { - uint32_t g_y_depth; - uint32_t r_cr_depth; - uint32_t b_cb_depth; - uint32_t length; - uint32_t dither_matrix[16]; - uint32_t temporal_en; - - static SDEDitherCfg *Init(uint32_t arg __attribute__((__unused__))); - SDEDitherCfg *GetConfig() { return this; } -}; - -struct SDEPADitherData { - uint64_t data_flags; - uint32_t matrix_size; - uint64_t matrix_data_addr; - uint32_t strength; - uint32_t offset_en; -}; - -class SDEPADitherWrapper : private SDEPADitherData { - public: - static SDEPADitherWrapper *Init(uint32_t arg __attribute__((__unused__))); - ~SDEPADitherWrapper() { - if (buffer_) - delete[] buffer_; - } - inline SDEPADitherData *GetConfig(void) { return this; } - - private: - SDEPADitherWrapper() {} - uint32_t *buffer_ = NULL; -}; - -struct SDEPaMemColorData { - uint32_t adjust_p0 = 0; - uint32_t adjust_p1 = 0; - uint32_t adjust_p2 = 0; - uint32_t blend_gain = 0; - uint8_t sat_hold = 0; - uint8_t val_hold = 0; - uint32_t hue_region = 0; - uint32_t sat_region = 0; - uint32_t val_region = 0; -}; - -struct SDEPaData { - static const int kSixZoneLUTSize = 384; - uint32_t mode = 0; - uint32_t hue_adj = 0; - uint32_t sat_adj = 0; - uint32_t val_adj = 0; - uint32_t cont_adj; - SDEPaMemColorData skin; - SDEPaMemColorData sky; - SDEPaMemColorData foliage; - uint32_t six_zone_thresh = 0; - uint32_t six_zone_adj_p0 = 0; - uint32_t six_zone_adj_p1 = 0; - uint8_t six_zone_sat_hold = 0; - uint8_t six_zone_val_hold = 0; - uint32_t six_zone_len = 0; - uint32_t *six_zone_curve_p0 = NULL; - uint32_t *six_zone_curve_p1 = NULL; -}; - -struct SDEIgcLUTData { - static const int kMaxIgcLUTEntries = 256; - uint32_t table_fmt = 0; - uint32_t len = 0; - uint32_t *c0_c1_data = NULL; - uint32_t *c2_data = NULL; -}; - -struct SDEIgcV30LUTData { - static const int kMaxIgcLUTEntries = 256; - uint32_t table_fmt = 0; - uint32_t len = 0; - uint64_t c0_c1_data = 0; - uint64_t c2_data = 0; - uint32_t strength = 0; -}; - -struct SDEPgcLUTData { - static const int kPgcLUTEntries = 1024; - uint32_t len = 0; - uint32_t *c0_data = NULL; - uint32_t *c1_data = NULL; - uint32_t *c2_data = NULL; -}; - -struct SDEDisplayMode { - static const int kMaxModeNameSize = 256; - int32_t id = -1; - uint32_t type = 0; - char name[kMaxModeNameSize] = {0}; -}; - -// Wrapper on HW block config data structure to encapsulate the details of allocating -// and destroying from the caller. -class SDEGamutCfgWrapper : private SDEGamutCfg { - public: - enum GamutMode { - GAMUT_FINE_MODE = 0x01, - GAMUT_COARSE_MODE, - GAMUT_COARSE_MODE_13, - }; - - // This factory method will be used by libsdm-color.so data producer to be populated with - // converted config values for SDE feature blocks. - static SDEGamutCfgWrapper *Init(uint32_t arg); - - // Data consumer will be responsible to destroy it once the feature is commited. - ~SDEGamutCfgWrapper() { - if (buffer_) - delete[] buffer_; - } - - // Data consumer will use this method to retrieve contained feature configuration. - inline SDEGamutCfg *GetConfig(void) { return this; } - - private: - SDEGamutCfgWrapper() {} - uint32_t *buffer_ = NULL; -}; - -class SDEPaCfgWrapper : private SDEPaData { - public: - static SDEPaCfgWrapper *Init(uint32_t arg = 0); - ~SDEPaCfgWrapper() { - if (buffer_) - delete[] buffer_; - } - inline SDEPaData *GetConfig(void) { return this; } - - private: - SDEPaCfgWrapper() {} - uint32_t *buffer_ = NULL; -}; - -class SDEIgcLUTWrapper : private SDEIgcLUTData { - public: - static SDEIgcLUTWrapper *Init(uint32_t arg __attribute__((__unused__))); - ~SDEIgcLUTWrapper() { - if (buffer_) - delete[] buffer_; - } - inline SDEIgcLUTData *GetConfig(void) { return this; } - - private: - SDEIgcLUTWrapper() {} - uint32_t *buffer_ = NULL; -}; - -class SDEIgcV30LUTWrapper : private SDEIgcV30LUTData { - public: - static SDEIgcV30LUTWrapper *Init(uint32_t arg __attribute__((__unused__))); - ~SDEIgcV30LUTWrapper() { - if (buffer_) - delete[] buffer_; - } - inline SDEIgcV30LUTData *GetConfig(void) { return this; } - - private: - SDEIgcV30LUTWrapper(const SDEIgcV30LUTWrapper& src) { /* do not create copies */ } - SDEIgcV30LUTWrapper& operator=(const SDEIgcV30LUTWrapper&) { return *this; } - SDEIgcV30LUTWrapper() {} - uint32_t *buffer_ = NULL; -}; - -class SDEPgcLUTWrapper : private SDEPgcLUTData { - public: - static SDEPgcLUTWrapper *Init(uint32_t arg __attribute__((__unused__))); - ~SDEPgcLUTWrapper() { - if (buffer_) - delete[] buffer_; - } - inline SDEPgcLUTData *GetConfig(void) { return this; } - - private: - SDEPgcLUTWrapper() {} - uint32_t *buffer_ = NULL; -}; - -// Base Postprocessing features information. -class PPFeatureInfo { - public: - uint32_t enable_flags_ = 0; // bitmap to indicate subset of parameters enabling or not. - uint32_t feature_version_ = 0; - uint32_t feature_id_ = 0; - uint32_t disp_id_ = 0; - uint32_t pipe_id_ = 0; - - virtual ~PPFeatureInfo() {} - virtual void *GetConfigData(void) const = 0; -}; - -// Individual Postprocessing feature representing physical attributes and information -// This template class wrapping around abstract data type representing different -// post-processing features. It will take output from ColorManager converting from raw metadata. -// The configuration will directly pass into HWInterface to program the hardware accordingly. -template -class TPPFeatureInfo : public PPFeatureInfo { - public: - virtual ~TPPFeatureInfo() { - if (params_) - delete params_; - } - - // API for data consumer to get underlying data configs to program into pp hardware block. - virtual void *GetConfigData(void) const { return params_->GetConfig(); } - - // API for data producer to get access to underlying data configs to populate it. - T *GetParamsReference(void) { return params_; } - - // API for create this template object. - static TPPFeatureInfo *Init(uint32_t arg = 0) { - TPPFeatureInfo *info = new TPPFeatureInfo(); - if (info) { - info->params_ = T::Init(arg); - if (!info->params_) { - delete info; - info = NULL; - } - } - - return info; - } - - protected: - TPPFeatureInfo() = default; - - private: - T *params_ = NULL; -}; - -// This singleton class serves as data exchanging central between data producer -// and data consumer -// This class defines PP pending features to be programmed, which generated from -// ColorManager. Dirty flag indicates some features are available to be programmed. -// () Lock is needed since the object wil be accessed from 2 tasks. -// All API exposed are not threadsafe, it's caller's responsiblity to acquire the locker. -class PPFeaturesConfig { - public: - PPFeaturesConfig() { memset(feature_, 0, sizeof(feature_)); } - ~PPFeaturesConfig() { Reset(); } - - // ColorManager installs one TFeatureInfo to take the output configs computed - // from ColorManager, containing all physical features to be programmed and also compute - // metadata/populate into T. - inline DisplayError AddFeature(uint32_t feature_id, PPFeatureInfo *feature) { - if (feature_id < kMaxNumPPFeatures) { - if (feature_[feature_id]) { - delete feature_[feature_id]; - feature_[feature_id] = NULL; - } - feature_[feature_id] = feature; - } - return kErrorNone; - } - - inline PPFeatureInfo* GetFeature(uint32_t feature_id) { - PPFeatureInfo* feature = nullptr; - if (feature_id < kMaxNumPPFeatures) { - if (feature_[feature_id]) { - feature = feature_[feature_id]; - } - } - return feature; - } - - inline Locker &GetLocker(void) { return locker_; } - inline PPFrameCaptureData *GetFrameCaptureData(void) { return &frame_capture_data; } - inline PPDETuningCfgData *GetDETuningCfgData(void) { return &de_tuning_data_; } - // Once all features are consumed, destroy/release all TFeatureInfo on the list, - // then clear dirty_ flag and return the lock to the TFeatureInfo producer. - void Reset(); - - // Consumer to call this to retrieve all the TFeatureInfo on the list to be programmed. - DisplayError RetrieveNextFeature(PPFeatureInfo **feature); - - inline bool IsDirty() { return dirty_; } - inline void MarkAsDirty() { dirty_ = true; } - - private: - bool dirty_ = 0; - Locker locker_; - PPFeatureInfo *feature_[kMaxNumPPFeatures]; // reference to TFeatureInfo. - uint32_t next_idx_ = 0; - PPFrameCaptureData frame_capture_data; - PPDETuningCfgData de_tuning_data_; -}; - -} // namespace sdm - -#endif // __COLOR_PARAMS_H__ diff --git a/sdm/include/private/dpps_control_interface.h b/sdm/include/private/dpps_control_interface.h deleted file mode 100644 index 8a449079..00000000 --- a/sdm/include/private/dpps_control_interface.h +++ /dev/null @@ -1,40 +0,0 @@ -/* -* Copyright (c) 2016, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted -* provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright notice, this list of -* conditions and the following disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its contributors may be used to -* endorse or promote products derived from this software without specific prior written -* permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __DPPS_CONTROL_INTERFACE_H__ -#define __DPPS_CONTROL_INTERFACE_H__ - -namespace sdm { - -class DppsControlInterface { - public: - virtual ~DppsControlInterface() { } - virtual DisplayError On() = 0; - virtual DisplayError Off() = 0; -}; - -} // namespace sdm - -#endif // __DPPS_CONTROL_INTERFACE_H__ - diff --git a/sdm/include/private/extension_interface.h b/sdm/include/private/extension_interface.h deleted file mode 100644 index 2e5bd49c..00000000 --- a/sdm/include/private/extension_interface.h +++ /dev/null @@ -1,87 +0,0 @@ -/* -* Copyright (c) 2015 - 2017, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted -* provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright notice, this list of -* conditions and the following disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its contributors may be used to -* endorse or promote products derived from this software without specific prior written -* permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __EXTENSION_INTERFACE_H__ -#define __EXTENSION_INTERFACE_H__ - -#include -#include - -#include "partial_update_interface.h" -#include "strategy_interface.h" -#include "resource_interface.h" -#include "dpps_control_interface.h" - -namespace sdm { - -#define EXTENSION_LIBRARY_NAME "libsdmextension.so" -#define CREATE_EXTENSION_INTERFACE_NAME "CreateExtensionInterface" -#define DESTROY_EXTENSION_INTERFACE_NAME "DestroyExtensionInterface" - -#define EXTENSION_REVISION_MAJOR (1) -#define EXTENSION_REVISION_MINOR (0) - -#define EXTENSION_VERSION_TAG ((uint16_t) ((EXTENSION_REVISION_MAJOR << 8) \ - | EXTENSION_REVISION_MINOR)) - -class ExtensionInterface; - -typedef DisplayError (*CreateExtensionInterface)(uint16_t version, ExtensionInterface **interface); -typedef DisplayError (*DestroyExtensionInterface)(ExtensionInterface *interface); - -class ExtensionInterface { - public: - virtual DisplayError CreatePartialUpdate(DisplayType type, const HWResourceInfo &hw_resource_info, - const HWPanelInfo &hw_panel_info, - const HWMixerAttributes &mixer_attributes, - const HWDisplayAttributes &display_attributes, - const DisplayConfigVariableInfo &fb_config, - PartialUpdateInterface **interface) = 0; - virtual DisplayError DestroyPartialUpdate(PartialUpdateInterface *interface) = 0; - - virtual DisplayError CreateStrategyExtn(DisplayType type, BufferAllocator *buffer_allocator, - const HWResourceInfo &hw_resource_info, - const HWPanelInfo &hw_panel_info, - const HWMixerAttributes &mixer_attributes, - const DisplayConfigVariableInfo &fb_config, - StrategyInterface **interface) = 0; - virtual DisplayError DestroyStrategyExtn(StrategyInterface *interface) = 0; - - virtual DisplayError CreateResourceExtn(const HWResourceInfo &hw_resource_info, - BufferAllocator *buffer_allocator, - BufferSyncHandler *buffer_sync_handler, - ResourceInterface **interface) = 0; - virtual DisplayError DestroyResourceExtn(ResourceInterface *interface) = 0; - virtual DisplayError CreateDppsControlExtn(DppsControlInterface **dpps_control_interface, - SocketHandler *socket_handler) = 0; - virtual DisplayError DestroyDppsControlExtn(DppsControlInterface *interface) = 0; - - protected: - virtual ~ExtensionInterface() { } -}; - -} // namespace sdm - -#endif // __EXTENSION_INTERFACE_H__ - diff --git a/sdm/include/private/hw_info_types.h b/sdm/include/private/hw_info_types.h deleted file mode 100644 index 43551deb..00000000 --- a/sdm/include/private/hw_info_types.h +++ /dev/null @@ -1,618 +0,0 @@ -/* -* Copyright (c) 2015-2018, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted -* provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright notice, this list of -* conditions and the following disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its contributors may be used to -* endorse or promote products derived from this software without specific prior written -* permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __HW_INFO_TYPES_H__ -#define __HW_INFO_TYPES_H__ - -#include -#include -#include -#include -#include -#include -#include - -namespace sdm { -using std::string; - -const int kMaxSDELayers = 16; // Maximum number of layers that can be handled by MDP5 hardware - // in a given layer stack. -#define MAX_PLANES 4 -#define MAX_DETAIL_ENHANCE_CURVE 3 -#define MAJOR 28 -#define MINOR 16 -#define SDEVERSION(major, minor, hw_rev) ((major) << MAJOR) | ((minor) << MINOR) | (hw_rev) - -enum HWDeviceType { - kDevicePrimary, - kDeviceHDMI, - kDeviceVirtual, - kDeviceRotator, - kDeviceMax, -}; - -enum HWBlockType { - kHWPrimary, - kHWHDMI, - kHWWriteback0, - kHWWriteback1, - kHWWriteback2, - kHWBlockMax -}; - -enum HWDisplayMode { - kModeDefault, - kModeVideo, - kModeCommand, -}; - -enum PipeType { - kPipeTypeUnused, - kPipeTypeVIG, - kPipeTypeRGB, - kPipeTypeDMA, - kPipeTypeCursor, -}; - -enum HWSubBlockType { - kHWVIGPipe, - kHWRGBPipe, - kHWDMAPipe, - kHWCursorPipe, - kHWRotatorInput, - kHWRotatorOutput, - kHWWBIntfOutput, - kHWDestinationScalar, - kHWSubBlockMax, -}; - -enum HWAlphaInterpolation { - kInterpolationPixelRepeat, - kInterpolationBilinear, - kInterpolation2D, - kInterpolationMax, -}; - -enum HWBlendingFilter { - kBlendFilterCircular, - kBlendFilterSeparable, - kBlendFilterMax, -}; - -enum HWPipeFlags { - kIGC = 0x01, - kMultiRect = 0x02, - kMultiRectParallelMode = 0x04, -}; - -enum HWAVRModes { - kContinuousMode, // Mode to enable AVR feature for every frame. - kOneShotMode, // Mode to enable AVR feature for particular frame. -}; - -enum HWTopology { - kUnknown, - kSingleLM, - kSingleLMDSC, - kDualLM, - kDualLMDSC, - kDualLMMerge, - kDualLMMergeDSC, - kDualLMDSCMerge, - kPPSplit, -}; - -enum HwHdrEotf { - kHdrEOTFInvalid = 0, - kHdrEOTFSDR = 0x1, - kHdrEOTFHdrLumRange = 0x2, - kHdrEOTFHDR10 = 0x4, - kHdrEOTFHLG = 0x8, -}; - -typedef std::map> FormatsMap; -typedef std::map CompRatioMap; - -struct HWDynBwLimitInfo { - uint32_t cur_mode = kBwDefault; - uint64_t total_bw_limit[kBwModeMax] = { 0 }; - uint64_t pipe_bw_limit[kBwModeMax] = { 0 }; -}; - -struct HWPipeCaps { - PipeType type = kPipeTypeUnused; - uint32_t id = 0; - uint32_t master_pipe_id = 0; - uint32_t max_rects = 1; -}; - -struct HWRotatorInfo { - enum { ROT_TYPE_MDSS, ROT_TYPE_V4L2 }; - uint32_t type = ROT_TYPE_MDSS; - uint32_t num_rotator = 0; - bool has_downscale = false; - std::string device_path = ""; - float min_downscale = 2.0f; - bool downscale_compression = false; -}; - -enum HWQseedStepVersion { - kQseed3v2, - kQseed3v3, - kQseed3v4, -}; - -struct HWDestScalarInfo { - uint32_t count = 0; - uint32_t max_input_width = 0; - uint32_t max_output_width = 0; - uint32_t max_scale_up = 1; - uint32_t prefill_lines = 4; -}; - -enum SmartDMARevision { - V1, - V2, -}; - -struct HWResourceInfo { - uint32_t hw_version = 0; - uint32_t hw_revision = 0; - uint32_t num_dma_pipe = 0; - uint32_t num_vig_pipe = 0; - uint32_t num_rgb_pipe = 0; - uint32_t num_cursor_pipe = 0; - uint32_t num_blending_stages = 0; - uint32_t num_solidfill_stages = 0; - uint32_t num_control = 0; - uint32_t num_mixer_to_disp = 0; - uint32_t smp_total = 0; - uint32_t smp_size = 0; - uint32_t num_smp_per_pipe = 0; - uint32_t max_scale_up = 1; - uint32_t max_scale_down = 1; - uint64_t max_bandwidth_low = 0; - uint64_t max_bandwidth_high = 0; - uint32_t max_mixer_width = 2048; - uint32_t max_pipe_width = 2048; - uint32_t max_cursor_size = 0; - uint64_t max_pipe_bw = 0; - uint32_t max_sde_clk = 0; - float clk_fudge_factor = 1.0f; - uint32_t macrotile_nv12_factor = 0; - uint32_t macrotile_factor = 0; - uint32_t linear_factor = 0; - uint32_t scale_factor = 0; - uint32_t extra_fudge_factor = 0; - uint32_t amortizable_threshold = 0; - uint32_t system_overhead_lines = 0; - bool has_bwc = false; - bool has_ubwc = false; - bool has_decimation = false; - bool has_macrotile = false; - bool has_non_scalar_rgb = false; - bool is_src_split = false; - bool has_dyn_bw_support = false; - bool separate_rotator = false; - bool has_qseed3 = false; - bool has_concurrent_writeback = false; - bool has_ppp = false; - uint32_t writeback_index = kHWBlockMax; - HWDynBwLimitInfo dyn_bw_info; - std::vector hw_pipes; - FormatsMap supported_formats_map; - HWRotatorInfo hw_rot_info; - HWDestScalarInfo hw_dest_scalar_info; - bool has_avr = false; - bool has_hdr = false; - SmartDMARevision smart_dma_rev = SmartDMARevision::V1; - float ib_fudge_factor = 1.0f; - uint32_t undersized_prefill_lines = 0; - CompRatioMap comp_ratio_rt_map; - CompRatioMap comp_ratio_nrt_map; - uint32_t cache_size = 0; // cache size in bytes - HWQseedStepVersion pipe_qseed3_version = kQseed3v2; // only valid when has_qseed3=true - uint32_t min_prefill_lines = 0; -}; - -struct HWSplitInfo { - uint32_t left_split = 0; - uint32_t right_split = 0; - - bool operator !=(const HWSplitInfo &split_info) { - return ((left_split != split_info.left_split) || (right_split != split_info.right_split)); - } - - bool operator ==(const HWSplitInfo &split_info) { - return !(operator !=(split_info)); - } -}; - -enum HWS3DMode { - kS3DModeNone, - kS3DModeLR, - kS3DModeRL, - kS3DModeTB, - kS3DModeFP, - kS3DModeMax, -}; - -struct HWColorPrimaries { - uint32_t white_point[2] = {}; // White point - uint32_t red[2] = {}; // Red color primary - uint32_t green[2] = {}; // Green color primary - uint32_t blue[2] = {}; // Blue color primary -}; - -struct HWPanelOrientation { - bool rotation = false; - bool flip_horizontal = false; - bool flip_vertical = false; -}; - -struct HWPanelInfo { - DisplayPort port = kPortDefault; // Display port - HWDisplayMode mode = kModeDefault; // Display mode - bool partial_update = false; // Partial update feature - int left_align = 1; // ROI left alignment restriction - int width_align = 1; // ROI width alignment restriction - int top_align = 1; // ROI top alignment restriction - int height_align = 1; // ROI height alignment restriction - int min_roi_width = 1; // Min width needed for ROI - int min_roi_height = 1; // Min height needed for ROI - bool needs_roi_merge = false; // Merge ROI's of both the DSI's - bool dynamic_fps = false; // Panel Supports dynamic fps - bool dfps_porch_mode = false; // dynamic fps VFP or HFP mode - bool ping_pong_split = false; // Supports Ping pong split - uint32_t min_fps = 0; // Min fps supported by panel - uint32_t max_fps = 0; // Max fps supported by panel - bool is_primary_panel = false; // Panel is primary display - bool is_pluggable = false; // Panel is pluggable - HWSplitInfo split_info; // Panel split configuration - char panel_name[256] = {0}; // Panel name - HWS3DMode s3d_mode = kS3DModeNone; // Panel's current s3d mode. - int panel_max_brightness = 0; // Max panel brightness - uint32_t left_roi_count = 1; // Number if ROI supported on left panel - uint32_t right_roi_count = 1; // Number if ROI supported on right panel - bool hdr_enabled = false; // HDR feature supported - bool hdr_metadata_type_one = false; // Static HDR metadata type one - uint32_t hdr_eotf = 0; // Electro optical transfer function - uint32_t peak_luminance = 0; // Panel's peak luminance level - uint32_t average_luminance = 0; // Panel's average luminance level - uint32_t blackness_level = 0; // Panel's blackness level - HWColorPrimaries primaries = {}; // WRGB color primaries - HWPanelOrientation panel_orientation = {}; // Panel Orientation - uint32_t transfer_time_us = 0; // transfer time in micro seconds to panel's active region - - bool operator !=(const HWPanelInfo &panel_info) { - return ((port != panel_info.port) || (mode != panel_info.mode) || - (partial_update != panel_info.partial_update) || - (left_align != panel_info.left_align) || (width_align != panel_info.width_align) || - (top_align != panel_info.top_align) || (height_align != panel_info.height_align) || - (min_roi_width != panel_info.min_roi_width) || - (min_roi_height != panel_info.min_roi_height) || - (needs_roi_merge != panel_info.needs_roi_merge) || - (dynamic_fps != panel_info.dynamic_fps) || (min_fps != panel_info.min_fps) || - (dfps_porch_mode != panel_info.dfps_porch_mode) || - (ping_pong_split != panel_info.ping_pong_split) || - (max_fps != panel_info.max_fps) || (is_primary_panel != panel_info.is_primary_panel) || - (split_info != panel_info.split_info) || (s3d_mode != panel_info.s3d_mode) || - (left_roi_count != panel_info.left_roi_count) || - (right_roi_count != panel_info.right_roi_count) || - (transfer_time_us != panel_info.transfer_time_us)); - } - - bool operator ==(const HWPanelInfo &panel_info) { - return !(operator !=(panel_info)); - } -}; - -struct HWSessionConfig { - LayerRect src_rect {}; - LayerRect dst_rect {}; - uint32_t buffer_count = 0; - bool secure = false; - uint32_t frame_rate = 0; - LayerTransform transform; - bool secure_camera = false; - - bool operator==(const HWSessionConfig& config) const { - return (src_rect == config.src_rect && - dst_rect == config.dst_rect && - buffer_count == config.buffer_count && - secure == config.secure && - frame_rate == config.frame_rate && - transform == config.transform && - secure_camera == config.secure_camera); - } - - bool operator!=(const HWSessionConfig& config) const { - return !operator==(config); - } -}; - -enum HWRotatorMode { - kRotatorNone, - kRotatorOffline, - kRotatorInline -}; - -struct HWRotateInfo { - int pipe_id = -1; // Not actual pipe id, but the relative DMA id - int writeback_id = -1; // Writeback block id, but this is the same as DMA id - LayerRect src_roi {}; // Source crop of each split - LayerRect dst_roi {}; // Destination crop of each split - bool valid = false; - int rotate_id = -1; // Actual rotator session id with driver -}; - -struct HWRotatorSession { - HWRotateInfo hw_rotate_info[kMaxRotatePerLayer] {}; - uint32_t hw_block_count = 0; // number of rotator hw blocks used by rotator session - int session_id = -1; // A handle with Session Manager - HWSessionConfig hw_session_config {}; - LayerBuffer input_buffer {}; // Input to rotator - LayerBuffer output_buffer {}; // Output of rotator, crop width and stride are same - float input_compression = 1.0f; - float output_compression = 1.0f; - bool is_buffer_cached = false; - HWRotatorMode mode = kRotatorNone; -}; - -struct HWScaleLutInfo { - uint32_t dir_lut_size = 0; - uint32_t cir_lut_size = 0; - uint32_t sep_lut_size = 0; - uint64_t dir_lut = 0; - uint64_t cir_lut = 0; - uint64_t sep_lut = 0; -}; - -struct HWDetailEnhanceData : DisplayDetailEnhancerData { - uint16_t prec_shift = 0; - int16_t adjust_a[MAX_DETAIL_ENHANCE_CURVE] = {0}; - int16_t adjust_b[MAX_DETAIL_ENHANCE_CURVE] = {0}; - int16_t adjust_c[MAX_DETAIL_ENHANCE_CURVE] = {0}; -}; - -struct HWPixelExtension { - int32_t extension = 0; // Number of pixels extension in left, right, top and bottom directions - // for all color components. This pixel value for each color component - // should be sum of fetch and repeat pixels. - - int32_t overfetch = 0; // Number of pixels need to be overfetched in left, right, top and bottom - // directions from source image for scaling. - - int32_t repeat = 0; // Number of pixels need to be repeated in left, right, top and bottom - // directions for scaling. -}; - -struct HWPlane { - int32_t init_phase_x = 0; - int32_t phase_step_x = 0; - int32_t init_phase_y = 0; - int32_t phase_step_y = 0; - HWPixelExtension left {}; - HWPixelExtension top {}; - HWPixelExtension right {}; - HWPixelExtension bottom {}; - uint32_t roi_width = 0; - int32_t preload_x = 0; - int32_t preload_y = 0; - uint32_t src_width = 0; - uint32_t src_height = 0; -}; - -struct HWScaleData { - struct enable { - uint8_t scale = 0; - uint8_t direction_detection = 0; - uint8_t detail_enhance = 0; - } enable; - uint32_t dst_width = 0; - uint32_t dst_height = 0; - HWPlane plane[MAX_PLANES] {}; - // scale_v2_data fields - ScalingFilterConfig y_rgb_filter_cfg = kFilterEdgeDirected; - ScalingFilterConfig uv_filter_cfg = kFilterEdgeDirected; - HWAlphaInterpolation alpha_filter_cfg = kInterpolationPixelRepeat; - HWBlendingFilter blend_cfg = kBlendFilterCircular; - - struct lut_flags { - uint8_t lut_swap = 0; - uint8_t lut_dir_wr = 0; - uint8_t lut_y_cir_wr = 0; - uint8_t lut_uv_cir_wr = 0; - uint8_t lut_y_sep_wr = 0; - uint8_t lut_uv_sep_wr = 0; - } lut_flag; - - uint32_t dir_lut_idx = 0; - /* for Y(RGB) and UV planes*/ - uint32_t y_rgb_cir_lut_idx = 0; - uint32_t uv_cir_lut_idx = 0; - uint32_t y_rgb_sep_lut_idx = 0; - uint32_t uv_sep_lut_idx = 0; - HWDetailEnhanceData detail_enhance {}; -}; - -struct HWDestScaleInfo { - uint32_t mixer_width = 0; - uint32_t mixer_height = 0; - bool scale_update = false; - HWScaleData scale_data = {}; - LayerRect panel_roi = {}; -}; - -typedef std::map DestScaleInfoMap; - -struct HWAVRInfo { - bool enable = false; // Flag to Enable AVR feature - HWAVRModes mode = kContinuousMode; // Specifies the AVR mode -}; - -struct HWPipeInfo { - HWPipeInfo *pair = NULL; - uint8_t rect = 255; - uint32_t pipe_id = 0; - HWSubBlockType sub_block_type = kHWSubBlockMax; - LayerRect src_roi {}; - LayerRect dst_roi {}; - uint8_t horizontal_decimation = 0; - uint8_t vertical_decimation = 0; - HWScaleData scale_data {}; - uint32_t z_order = 0; - uint8_t flags = 0; - bool valid = false; - bool is_virtual = 0; -}; - -struct HWSolidfillStage { - uint32_t z_order = kMaxSDELayers; - uint32_t color = 0; - LayerRect roi = {}; - bool is_exclusion_rect = false; - LayerSolidFill solid_fill_info = {}; -}; - -struct HWLayerConfig { - HWPipeInfo left_pipe {}; // pipe for left side of output - HWPipeInfo right_pipe {}; // pipe for right side of output - HWRotatorSession hw_rotator_session {}; - HWSolidfillStage hw_solidfill_stage {}; - float compression = 1.0f; - bool use_solidfill_stage = false; -}; - -struct HWHDRLayerInfo { - enum HDROperation { - kNoOp, // No-op. - kSet, // Sets the HDR MetaData - Start of HDR - kReset, // resets the previously set HDR Metadata, End of HDR - }; - - int32_t layer_index = -1; - HDROperation operation = kNoOp; -}; - -struct HWLayersInfo { - LayerStack *stack = NULL; // Input layer stack. Set by the caller. - uint32_t app_layer_count = 0; // Total number of app layers. Must not be 0. - uint32_t gpu_target_index = 0; // GPU target layer index. 0 if not present. - std::vector hw_layers = {}; // Layers which need to be programmed on the HW - std::vector index {}; // Indexes of the layers from the layer stack which need to - std::vector roi_index {}; // Stores the ROI index where the layers are visible. - int sync_handle = -1; // Release fence id for current draw cycle. - int set_idle_time_ms = -1; // Set idle time to the new specified value. - // -1 indicates no change in idle time since last set value. - std::vector left_frame_roi = {}; // Left ROI. - std::vector right_frame_roi = {}; // Right ROI. - LayerRect partial_fb_roi = {}; // Damaged area in framebuffer. - bool roi_split = false; // Indicates separated left and right ROI - bool async_cursor_updates = false; // Cursor layer allowed to have async updates - DestScaleInfoMap dest_scale_info_map = {}; - HWHDRLayerInfo hdr_layer_info = {}; - Handle pvt_data = NULL; // Private data used by sdm extension only. -}; - -struct HWQosData { - uint64_t core_ab_bps = 0; - uint64_t core_ib_bps = 0; - uint64_t llcc_ab_bps = 0; - uint64_t llcc_ib_bps = 0; - uint64_t dram_ab_bps = 0; - uint64_t dram_ib_bps = 0; - uint64_t rot_prefill_bw_bps = 0; - uint32_t clock_hz = 0; - uint32_t rot_clock_hz = 0; -}; - -struct HWLayers { - HWLayersInfo info {}; - HWLayerConfig config[kMaxSDELayers] {}; - float output_compression = 1.0f; - HWQosData qos_data = {}; - HWAVRInfo hw_avr_info = {}; -}; - -struct HWDisplayAttributes : DisplayConfigVariableInfo { - bool is_device_split = false; - uint32_t v_front_porch = 0; //!< Vertical front porch of panel - uint32_t v_back_porch = 0; //!< Vertical back porch of panel - uint32_t v_pulse_width = 0; //!< Vertical pulse width of panel - uint32_t h_total = 0; //!< Total width of panel (hActive + hFP + hBP + hPulseWidth) - uint32_t v_total = 0; //!< Total height of panel (vActive + vFP + vBP + vPulseWidth) - std::bitset<32> s3d_config {}; //!< Stores the bit mask of S3D modes - uint32_t clock_khz = 0; //!< Stores the pixel clock of panel in khz - HWTopology topology = kUnknown; //!< Stores the topology information. - - bool operator !=(const HWDisplayAttributes &display_attributes) { - return ((is_device_split != display_attributes.is_device_split) || - (x_pixels != display_attributes.x_pixels) || - (y_pixels != display_attributes.y_pixels) || - (x_dpi != display_attributes.x_dpi) || - (y_dpi != display_attributes.y_dpi) || - (fps != display_attributes.fps) || - (vsync_period_ns != display_attributes.vsync_period_ns) || - (v_front_porch != display_attributes.v_front_porch) || - (v_back_porch != display_attributes.v_back_porch) || - (v_pulse_width != display_attributes.v_pulse_width) || - (h_total != display_attributes.h_total) || - (is_yuv != display_attributes.is_yuv) || - (s3d_config != display_attributes.s3d_config) || - (clock_khz != display_attributes.clock_khz) || - (topology != display_attributes.topology)); - } - - bool operator ==(const HWDisplayAttributes &display_attributes) { - return !(operator !=(display_attributes)); - } -}; - -struct HWMixerAttributes { - uint32_t width = 0; // Layer mixer width - uint32_t height = 0; // Layer mixer height - uint32_t split_left = 0; - LayerBufferFormat output_format = kFormatRGB101010; // Layer mixer output format - - bool operator !=(const HWMixerAttributes &mixer_attributes) { - return ((width != mixer_attributes.width) || - (height != mixer_attributes.height) || - (output_format != mixer_attributes.output_format) || - (split_left != mixer_attributes.split_left)); - } - - bool operator ==(const HWMixerAttributes &mixer_attributes) { - return !(operator !=(mixer_attributes)); - } - - bool IsValid() { - return (width > 0 && height > 0); - } -}; - -} // namespace sdm - -#endif // __HW_INFO_TYPES_H__ - diff --git a/sdm/include/private/partial_update_interface.h b/sdm/include/private/partial_update_interface.h deleted file mode 100644 index a1c23827..00000000 --- a/sdm/include/private/partial_update_interface.h +++ /dev/null @@ -1,53 +0,0 @@ -/* -* Copyright (c) 2015, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted -* provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright notice, this list of -* conditions and the following disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its contributors may be used to -* endorse or promote products derived from this software without specific prior written -* permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __PARTIAL_UPDATE_INTERFACE_H__ -#define __PARTIAL_UPDATE_INTERFACE_H__ - -#include -#include -#include - -#include "hw_info_types.h" - -namespace sdm { - -struct PUConstraints { - bool enable = true; //!< If this is set, PU will be enabled or it will be disabled -}; - -class PartialUpdateInterface { - public: - virtual DisplayError Start(const PUConstraints &pu_constraints) = 0; - virtual DisplayError GenerateROI(HWLayersInfo *hw_layers_info) = 0; - virtual DisplayError Stop() = 0; - - protected: - virtual ~PartialUpdateInterface() { } -}; - -} // namespace sdm - -#endif // __PARTIAL_UPDATE_INTERFACE_H__ - diff --git a/sdm/include/private/resource_interface.h b/sdm/include/private/resource_interface.h deleted file mode 100644 index 1e752988..00000000 --- a/sdm/include/private/resource_interface.h +++ /dev/null @@ -1,75 +0,0 @@ -/* -* Copyright (c) 2015 - 2017, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted -* provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright notice, this list of -* conditions and the following disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its contributors may be used to -* endorse or promote products derived from this software without specific prior written -* permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __RESOURCE_INTERFACE_H__ -#define __RESOURCE_INTERFACE_H__ - -#include -#include "hw_info_types.h" - -namespace sdm { - -class ResourceInterface { - public: - enum ResourceCmd { - kCmdResetScalarLUT, - kCmdMax, - }; - - virtual DisplayError RegisterDisplay(DisplayType type, - const HWDisplayAttributes &display_attributes, - const HWPanelInfo &hw_panel_info, - const HWMixerAttributes &mixer_attributes, - Handle *display_ctx) = 0; - virtual DisplayError UnregisterDisplay(Handle display_ctx) = 0; - virtual DisplayError ReconfigureDisplay(Handle display_ctx, - const HWDisplayAttributes &display_attributes, - const HWPanelInfo &hw_panel_info, - const HWMixerAttributes &mixer_attributes) = 0; - virtual DisplayError Start(Handle display_ctx) = 0; - virtual DisplayError Stop(Handle display_ctx, HWLayers *hw_layers) = 0; - virtual DisplayError Prepare(Handle display_ctx, HWLayers *hw_layers) = 0; - virtual DisplayError PostPrepare(Handle display_ctx, HWLayers *hw_layers) = 0; - virtual DisplayError Commit(Handle display_ctx, HWLayers *hw_layers) = 0; - virtual DisplayError PostCommit(Handle display_ctx, HWLayers *hw_layers) = 0; - virtual void Purge(Handle display_ctx) = 0; - virtual DisplayError SetMaxMixerStages(Handle display_ctx, uint32_t max_mixer_stages) = 0; - virtual DisplayError ValidateScaling(const LayerRect &crop, const LayerRect &dst, - bool rotate90, BufferLayout layout, - bool use_rotator_downscale) = 0; - virtual DisplayError ValidateAndSetCursorPosition(Handle display_ctx, HWLayers *hw_layers, - int x, int y, - DisplayConfigVariableInfo *fb_config) = 0; - virtual DisplayError SetMaxBandwidthMode(HWBwModes mode) = 0; - virtual DisplayError GetScaleLutConfig(HWScaleLutInfo *lut_info) = 0; - virtual DisplayError SetDetailEnhancerData(Handle display_ctx, - const DisplayDetailEnhancerData &de_data) = 0; - virtual DisplayError Perform(int cmd, ...) = 0; - virtual ~ResourceInterface() { } -}; - -} // namespace sdm - -#endif // __RESOURCE_INTERFACE_H__ - diff --git a/sdm/include/private/strategy_interface.h b/sdm/include/private/strategy_interface.h deleted file mode 100644 index 1174e7f3..00000000 --- a/sdm/include/private/strategy_interface.h +++ /dev/null @@ -1,62 +0,0 @@ -/* -* Copyright (c) 2014 - 2017, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted -* provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright notice, this list of -* conditions and the following disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its contributors may be used to -* endorse or promote products derived from this software without specific prior written -* permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __STRATEGY_INTERFACE_H__ -#define __STRATEGY_INTERFACE_H__ - -#include -#include -#include "hw_info_types.h" - -namespace sdm { - -struct StrategyConstraints { - bool safe_mode = false; //!< In this mode, strategy manager chooses the composition strategy - //!< that requires minimum number of pipe for the current frame. i.e., - //!< video only composition, secure only composition or GPU composition - - uint32_t max_layers = kMaxSDELayers; //!< Maximum number of layers that shall be programmed - //!< on hardware for the given layer stack. -}; - -class StrategyInterface { - public: - virtual DisplayError Start(HWLayersInfo *hw_layers_info, uint32_t *max_attempts) = 0; - virtual DisplayError GetNextStrategy(StrategyConstraints *constraints) = 0; - virtual DisplayError Stop() = 0; - virtual DisplayError Reconfigure(const HWPanelInfo &hw_panel_info, - const HWResourceInfo &hw_res_info, - const HWMixerAttributes &mixer_attributes, - const DisplayConfigVariableInfo &fb_config) = 0; - virtual DisplayError SetCompositionState(LayerComposition composition_type, bool enable) = 0; - virtual DisplayError Purge() = 0; - virtual DisplayError SetIdleTimeoutMs(uint32_t active_ms) = 0; - - virtual ~StrategyInterface() { } -}; - -} // namespace sdm - -#endif // __STRATEGY_INTERFACE_H__ - diff --git a/sdm/include/utils/constants.h b/sdm/include/utils/constants.h deleted file mode 100644 index 5efe3571..00000000 --- a/sdm/include/utils/constants.h +++ /dev/null @@ -1,84 +0,0 @@ -/* -* Copyright (c) 2014 - 2017, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted -* provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright notice, this list of -* conditions and the following disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its contributors may be used to -* endorse or promote products derived from this software without specific prior written -* permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __CONSTANTS_H__ -#define __CONSTANTS_H__ - -#include -#include - -#ifndef PRIu64 -#define PRIu64 "llu" -#endif - -#define INT(exp) static_cast(exp) -#define FLOAT(exp) static_cast(exp) -#define UINT8(exp) static_cast(exp) -#define UINT16(exp) static_cast(exp) -#define UINT32(exp) static_cast(exp) -#define INT32(exp) static_cast(exp) -#define UINT64(exp) static_cast(exp) - -#define ROUND_UP(number, step) ((((number) + ((step) - 1)) / (step)) * (step)) - -#define BITMAP(bit) (1 << (bit)) - -#define ROUND_UP_ALIGN_DOWN(value, a) FLOAT(FloorToMultipleOf(UINT32(value + 0.5f), UINT32(a))) -#define ROUND_UP_ALIGN_UP(value, a) FLOAT(CeilToMultipleOf(UINT32(value + 0.5f), UINT32(a))) - -#define IDLE_TIMEOUT_DEFAULT_MS 70 -#define IDLE_TIMEOUT_ACTIVE_MS IDLE_TIMEOUT_DEFAULT_MS -#define IDLE_TIMEOUT_INACTIVE_MS 520 - -#define IS_RGB_FORMAT(format) (((format) < kFormatYCbCr420Planar) ? true: false) - -#define BITS_PER_BYTE 8 -#define BITS_TO_BYTES(x) (((x) + (BITS_PER_BYTE - 1)) / (BITS_PER_BYTE)) - -// factor value should be in powers of 2(eg: 1, 2, 4, 8) -template -inline T1 FloorToMultipleOf(const T1 &value, const T2 &factor) { - return (T1)(value & (~(factor - 1))); -} - -template -inline T1 CeilToMultipleOf(const T1 &value, const T2 &factor) { - return (T1)((value + (factor - 1)) & (~(factor - 1))); -} - -namespace sdm { - - const int kThreadPriorityUrgent = -9; - const int kMaxRotatePerLayer = 2; - const uint32_t kMaxBlitTargetLayers = 2; - const int kPageSize = 4096; - const uint32_t kGridSize = 129; // size used for non-linear transformation before Tone-mapping - const uint32_t kLutDim = 17; // Dim of the 3d LUT for tone-mapping. - - typedef void * Handle; - -} // namespace sdm - -#endif // __CONSTANTS_H__ - diff --git a/sdm/include/utils/debug.h b/sdm/include/utils/debug.h deleted file mode 100644 index b4334b7c..00000000 --- a/sdm/include/utils/debug.h +++ /dev/null @@ -1,73 +0,0 @@ -/* -* Copyright (c) 2014 - 2018, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __DEBUG_H__ -#define __DEBUG_H__ - -#include -#include -#include -#include -#include - -namespace sdm { - -using display::DebugHandler; - -class Debug { - public: - static inline DebugHandler* Get() { return DebugHandler::Get(); } - static int GetSimulationFlag(); - static bool GetExternalResolution(char *val); - static void GetIdleTimeoutMs(uint32_t *active_ms, uint32_t *inactive_ms); - static int GetBootAnimLayerCount(); - static bool IsRotatorDownScaleDisabled(); - static bool IsDecimationDisabled(); - static int GetMaxPipesPerMixer(DisplayType display_type); - static int GetMaxUpscale(); - static bool IsVideoModeEnabled(); - static bool IsRotatorUbwcDisabled(); - static bool IsRotatorSplitDisabled(); - static bool IsScalarDisabled(); - static bool IsUbwcTiledFrameBuffer(); - static bool IsAVRDisabled(); - static bool IsExtAnimDisabled(); - static bool IsPartialSplitDisabled(); - static bool IsSrcSplitPreferred(); - static DisplayError GetMixerResolution(uint32_t *width, uint32_t *height); - static DisplayError GetReducedConfig(uint32_t *num_vig_pipes, uint32_t *num_dma_pipes); - static int GetExtMaxlayers(); - static DisplayError GetProperty(const char *property_name, char *value); - static DisplayError GetProperty(const char *property_name, int *value); -}; - -} // namespace sdm - -#endif // __DEBUG_H__ - diff --git a/sdm/include/utils/factory.h b/sdm/include/utils/factory.h deleted file mode 100644 index f77a2999..00000000 --- a/sdm/include/utils/factory.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -* Copyright (c) 2017, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __FACTORY_H__ -#define __FACTORY_H__ - -#include -#include -#include - -namespace sdm { - -template -class Factory { - public: - int Add(const std::string &name, const Creator &creator) { - map_.insert(std::pair(name, creator)); - - return 0; - } - - Creator Get(const std::string &name) { - typename std::map::iterator it = map_.find(name); - if (it != map_.end()) { - return it->second; - } - - return nullptr; - } - - private: - std::map map_; -}; - -} // namespace sdm - -#endif // __FACTORY_H__ diff --git a/sdm/include/utils/formats.h b/sdm/include/utils/formats.h deleted file mode 100644 index 2d438506..00000000 --- a/sdm/include/utils/formats.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -* Copyright (c) 2016 - 2017, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __FORMATS_H__ -#define __FORMATS_H__ - -#include - -namespace sdm { - -struct FormatTileSize { - /*< Tile width in pixels. For YUV formats this will give only the - tile width for Y plane*/ - uint32_t tile_width = 0; - /*< Tile height in pixels. For YUV formats this will give only the - tile height for Y plane*/ - uint32_t tile_height = 0; - - /*< Tile width in pixels. Only valid for YUV formats where this will - give tile width for UV plane*/ - uint32_t uv_tile_width = 0; - /*< Tile height in pixels. Only valid for YUV formats where this will - give tile height for UV plane*/ - uint32_t uv_tile_height = 0; -}; - -bool IsUBWCFormat(LayerBufferFormat format); -bool Is10BitFormat(LayerBufferFormat format); -const char *GetFormatString(const LayerBufferFormat &format); -BufferLayout GetBufferLayout(LayerBufferFormat format); -DisplayError GetBufferFormatTileSize(LayerBufferFormat format, FormatTileSize *tile_size); -float GetBufferFormatBpp(LayerBufferFormat format); - -} // namespace sdm - -#endif // __FORMATS_H__ - diff --git a/sdm/include/utils/locker.h b/sdm/include/utils/locker.h deleted file mode 100755 index e0d91cbe..00000000 --- a/sdm/include/utils/locker.h +++ /dev/null @@ -1,171 +0,0 @@ -/* -* Copyright (c) 2014 - 2016, 2018 The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted -* provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright notice, this list of -* conditions and the following disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its contributors may be used to -* endorse or promote products derived from this software without specific prior written -* permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __LOCKER_H__ -#define __LOCKER_H__ - -#include -#include -#include -#include - -#define SCOPE_LOCK(locker) Locker::ScopeLock lock(locker) -#define SEQUENCE_ENTRY_SCOPE_LOCK(locker) Locker::SequenceEntryScopeLock lock(locker) -#define SEQUENCE_EXIT_SCOPE_LOCK(locker) Locker::SequenceExitScopeLock lock(locker) -#define SEQUENCE_WAIT_SCOPE_LOCK(locker) Locker::SequenceWaitScopeLock lock(locker) -#define SEQUENCE_CANCEL_SCOPE_LOCK(locker) Locker::SequenceCancelScopeLock lock(locker) - -namespace sdm { - -class Locker { - public: - class ScopeLock { - public: - explicit ScopeLock(Locker& locker) : locker_(locker) { - locker_.Lock(); - } - - ~ScopeLock() { - locker_.Unlock(); - } - - private: - Locker &locker_; - }; - - class SequenceEntryScopeLock { - public: - explicit SequenceEntryScopeLock(Locker& locker) : locker_(locker) { - locker_.Lock(); - locker_.sequence_wait_ = 1; - } - - ~SequenceEntryScopeLock() { - locker_.Unlock(); - } - - private: - Locker &locker_; - }; - - class SequenceExitScopeLock { - public: - explicit SequenceExitScopeLock(Locker& locker) : locker_(locker) { - locker_.Lock(); - locker_.sequence_wait_ = 0; - } - - ~SequenceExitScopeLock() { - locker_.Broadcast(); - locker_.Unlock(); - } - - private: - Locker &locker_; - }; - - class SequenceWaitScopeLock { - public: - explicit SequenceWaitScopeLock(Locker& locker) : locker_(locker), error_(false) { - locker_.Lock(); - - while (locker_.sequence_wait_ == 1) { - locker_.Wait(); - error_ = (locker_.sequence_wait_ == -1); - } - } - - ~SequenceWaitScopeLock() { - locker_.Unlock(); - } - - bool IsError() { - return error_; - } - - private: - Locker &locker_; - bool error_; - }; - - class SequenceCancelScopeLock { - public: - explicit SequenceCancelScopeLock(Locker& locker) : locker_(locker) { - locker_.Lock(); - locker_.sequence_wait_ = -1; - } - - ~SequenceCancelScopeLock() { - locker_.Broadcast(); - locker_.Unlock(); - } - - private: - Locker &locker_; - }; - - Locker() : sequence_wait_(0) { - pthread_mutex_init(&mutex_, 0); - pthread_condattr_init(&cond_attr_); - pthread_condattr_setclock(&cond_attr_, CLOCK_MONOTONIC); - pthread_cond_init(&condition_, &cond_attr_); - } - - ~Locker() { - pthread_mutex_destroy(&mutex_); - pthread_cond_destroy(&condition_); - pthread_condattr_destroy(&cond_attr_); - } - - void Lock() { pthread_mutex_lock(&mutex_); } - void Unlock() { pthread_mutex_unlock(&mutex_); } - void Signal() { pthread_cond_signal(&condition_); } - void Broadcast() { pthread_cond_broadcast(&condition_); } - void Wait() { pthread_cond_wait(&condition_, &mutex_); } - int WaitFinite(uint32_t ms) { - struct timespec ts; - if (clock_gettime(CLOCK_MONOTONIC, &ts)) { - return EINVAL; - } - uint64_t ns = (uint64_t)ts.tv_nsec + (ms * 1000000L); - ts.tv_sec = ts.tv_sec + (time_t)(ns / 1000000000L); - ts.tv_nsec = ns % 1000000000L; - return pthread_cond_timedwait(&condition_, &mutex_, &ts); - } - - private: - pthread_mutex_t mutex_; - pthread_cond_t condition_; - pthread_condattr_t cond_attr_; - int sequence_wait_; // This flag is set to 1 on sequence entry, 0 on exit, and -1 on cancel. - // Some routines will wait for sequence of function calls to finish - // so that capturing a transitionary snapshot of context is prevented. - // If flag is set to -1, these routines will exit without doing any - // further processing. -}; - -} // namespace sdm - -#endif // __LOCKER_H__ - diff --git a/sdm/include/utils/rect.h b/sdm/include/utils/rect.h deleted file mode 100644 index b25f76e8..00000000 --- a/sdm/include/utils/rect.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -* Copyright (c) 2015-2017, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __RECT_H__ -#define __RECT_H__ - -#include -#include -#include -#include - -namespace sdm { - - enum RectOrientation { - kOrientationPortrait, - kOrientationLandscape, - kOrientationUnknown, - }; - - bool IsValid(const LayerRect &rect); - bool IsCongruent(const LayerRect &rect1, const LayerRect &rect2); - void LogI(DebugTag debug_tag, const char *prefix, const LayerRect &roi); - void Log(DebugTag debug_tag, const char *prefix, const LayerRect &roi); - void Normalize(const uint32_t &align_x, const uint32_t &align_y, LayerRect *rect); - LayerRect Union(const LayerRect &rect1, const LayerRect &rect2); - LayerRect Intersection(const LayerRect &rect1, const LayerRect &rect2); - LayerRect Subtract(const LayerRect &rect1, const LayerRect &rect2); - LayerRect Reposition(const LayerRect &rect1, const int &x_offset, const int &y_offset); - void SplitLeftRight(const LayerRect &in_rect, uint32_t split_count, uint32_t align_x, - bool flip_horizontal, LayerRect *out_rects); - void SplitTopBottom(const LayerRect &in_rect, uint32_t split_count, uint32_t align_y, - bool flip_horizontal, LayerRect *out_rects); - void MapRect(const LayerRect &src_domain, const LayerRect &dst_domain, const LayerRect &in_rect, - LayerRect *out_rect); - void TransformHV(const LayerRect &src_domain, const LayerRect &in_rect, - const LayerTransform &transform, LayerRect *out_rect); - RectOrientation GetOrientation(const LayerRect &in_rect); - DisplayError GetCropAndDestination(const LayerRect &crop, const LayerRect &dst, - bool rotate90, float *crop_width, float *crop_height, - float *dst_width, float *dst_height); - DisplayError GetScaleFactor(const LayerRect &crop, const LayerRect &dst, bool rotate90, - float *scale_x, float *scale_y); -} // namespace sdm - -#endif // __RECT_H__ - diff --git a/sdm/include/utils/sync_task.h b/sdm/include/utils/sync_task.h deleted file mode 100644 index 725460a1..00000000 --- a/sdm/include/utils/sync_task.h +++ /dev/null @@ -1,143 +0,0 @@ -/* -* Copyright (c) 2017, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __SYNC_TASK_H__ -#define __SYNC_TASK_H__ - -#include -#include -#include // NOLINT - -namespace sdm { - -template -class SyncTask { - public: - // This class need to be overridden by caller to pass on a task context. - class TaskContext { - public: - virtual ~TaskContext() { } - }; - - // Methods to callback into caller for command codes executions in worker thread. - class TaskHandler { - public: - virtual ~TaskHandler() { } - virtual void OnTask(const TaskCode &task_code, TaskContext *task_context) = 0; - }; - - explicit SyncTask(TaskHandler &task_handler) : task_handler_(task_handler) { - // Block caller thread until worker thread has started and ready to listen to task commands. - // Worker thread will signal as soon as callback is received in the new thread. - std::unique_lock caller_lock(caller_mutex_); - std::thread worker_thread(SyncTaskThread, this); - worker_thread_.swap(worker_thread); - caller_cv_.wait(caller_lock); - } - - ~SyncTask() { - // Task code does not matter here. - PerformTask(task_code_, nullptr, true); - worker_thread_.join(); - } - - void PerformTask(const TaskCode &task_code, TaskContext *task_context) { - PerformTask(task_code, task_context, false); - } - - private: - void PerformTask(const TaskCode &task_code, TaskContext *task_context, bool terminate) { - std::unique_lock caller_lock(caller_mutex_); - - // New scope to limit scope of worker lock to this block. - { - // Set task command code and notify worker thread. - std::unique_lock worker_lock(worker_mutex_); - task_code_ = task_code; - task_context_ = task_context; - worker_thread_exit_ = terminate; - pending_code_ = true; - worker_cv_.notify_one(); - } - - // Wait for worker thread to finish and signal. - caller_cv_.wait(caller_lock); - } - - static void SyncTaskThread(SyncTask *sync_task) { - if (sync_task) { - sync_task->OnThreadCallback(); - } - } - - void OnThreadCallback() { - // Acquire worker lock and start waiting for events. - // Wait must start before caller thread can post events, otherwise posted events will be lost. - // Caller thread will be blocked until worker thread signals readiness. - std::unique_lock worker_lock(worker_mutex_); - - // New scope to limit scope of caller lock to this block. - { - // Signal caller thread that worker thread is ready to listen to events. - std::unique_lock caller_lock(caller_mutex_); - caller_cv_.notify_one(); - } - - while (!worker_thread_exit_) { - // Add predicate to handle spurious interrupts. - // Wait for caller thread to signal new command codes. - worker_cv_.wait(worker_lock, [this] { return pending_code_; }); - - // Call task handler which is implemented by the caller. - if (!worker_thread_exit_) { - task_handler_.OnTask(task_code_, task_context_); - } - - pending_code_ = false; - // Notify completion of current task to the caller thread which is blocked. - std::unique_lock caller_lock(caller_mutex_); - caller_cv_.notify_one(); - } - } - - TaskHandler &task_handler_; - TaskCode task_code_; - TaskContext *task_context_ = nullptr; - std::thread worker_thread_; - std::mutex caller_mutex_; - std::mutex worker_mutex_; - std::condition_variable caller_cv_; - std::condition_variable worker_cv_; - bool worker_thread_exit_ = false; - bool pending_code_ = false; -}; - -} // namespace sdm - -#endif // __SYNC_TASK_H__ diff --git a/sdm/include/utils/sys.h b/sdm/include/utils/sys.h deleted file mode 100644 index 6b40df45..00000000 --- a/sdm/include/utils/sys.h +++ /dev/null @@ -1,101 +0,0 @@ -/* -* Copyright (c) 2015, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted -* provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright notice, this list of -* conditions and the following disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its contributors may be used to -* endorse or promote products derived from this software without specific prior written -* permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __SYS_H__ -#define __SYS_H__ - -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef SDM_VIRTUAL_DRIVER -#include -#endif - -namespace sdm { - -class Sys { - public: -#ifndef SDM_VIRTUAL_DRIVER - typedef std::fstream fstream; -#else - typedef VirtualFStream fstream; -#endif - - // Pointers to system calls which are either mapped to actual system call or virtual driver. -#ifdef TARGET_HEADLESS - typedef int (*ioctl)(int, unsigned long int, ...); // NOLINT -#else - typedef int (*ioctl)(int, int, ...); -#endif - typedef int (*access)(const char *, int); - typedef int (*open)(const char *, int, ...); - typedef int (*close)(int); - typedef int (*poll)(struct pollfd *, nfds_t, int); - typedef ssize_t (*pread)(int, void *, size_t, off_t); - typedef ssize_t (*pwrite)(int, const void *, size_t, off_t); - typedef int (*pthread_cancel)(pthread_t thread); - typedef int (*dup)(int fd); - typedef ssize_t (*read)(int, void *, size_t); - typedef ssize_t (*write)(int, const void *, size_t); - typedef int (*eventfd)(unsigned int, int); - - static bool getline_(fstream &fs, std::string &line); // NOLINT - - static ioctl ioctl_; - static access access_; - static open open_; - static close close_; - static poll poll_; - static pread pread_; - static pwrite pwrite_; - static pthread_cancel pthread_cancel_; - static dup dup_; - static read read_; - static write write_; - static eventfd eventfd_; -}; - -class DynLib { - public: - ~DynLib(); - bool Open(const char *lib_name); - bool Sym(const char *func_name, void **func_ptr); - const char * Error() { return ::dlerror(); } - operator bool() const { return lib_ != NULL; } - - private: - void Close(); - - void *lib_ = NULL; -}; - -} // namespace sdm - -#endif // __SYS_H__ diff --git a/sdm/include/utils/utils.h b/sdm/include/utils/utils.h deleted file mode 100644 index b1c55c41..00000000 --- a/sdm/include/utils/utils.h +++ /dev/null @@ -1,49 +0,0 @@ -/* -* Copyright (c) 2016 - 2017, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __UTILS_H__ -#define __UTILS_H__ - -namespace sdm { - -float gcd(float a, float b); -float lcm(float a, float b); -void CloseFd(int *fd); - -enum class DriverType { - FB = 0, - DRM, -}; - -DriverType GetDriverType(); - -} // namespace sdm - -#endif // __UTILS_H__ - diff --git a/sdm/libs/core/Android.mk b/sdm/libs/core/Android.mk deleted file mode 100644 index d4aa9331..00000000 --- a/sdm/libs/core/Android.mk +++ /dev/null @@ -1,86 +0,0 @@ -LOCAL_PATH := $(call my-dir) -include $(CLEAR_VARS) -include $(LOCAL_PATH)/../../../common.mk - -LOCAL_MODULE := libsdmcore -LOCAL_VENDOR_MODULE := true -LOCAL_MODULE_TAGS := optional -LOCAL_C_INCLUDES := $(common_includes) $(kernel_includes) -LOCAL_HEADER_LIBRARIES := display_headers -LOCAL_CFLAGS := -fno-operator-names -Wno-unused-parameter -DLOG_TAG=\"SDM\" \ - $(common_flags) -LOCAL_HW_INTF_PATH_1 := fb -LOCAL_SHARED_LIBRARIES := libdl libdisplaydebug libsdmutils - -ifneq ($(TARGET_IS_HEADLESS), true) - LOCAL_CFLAGS += -isystem external/libdrm - LOCAL_SHARED_LIBRARIES += libdrm libdrmutils - LOCAL_HW_INTF_PATH_2 := drm -endif - -ifeq ($(TARGET_USES_DRM_PP),true) - LOCAL_CFLAGS += -DPP_DRM_ENABLE -endif - -LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps) $(kernel_deps) -LOCAL_SRC_FILES := core_interface.cpp \ - core_impl.cpp \ - display_base.cpp \ - display_primary.cpp \ - display_hdmi.cpp \ - display_virtual.cpp \ - comp_manager.cpp \ - strategy.cpp \ - resource_default.cpp \ - color_manager.cpp \ - hw_events_interface.cpp \ - hw_info_interface.cpp \ - hw_interface.cpp \ - $(LOCAL_HW_INTF_PATH_1)/hw_info.cpp \ - $(LOCAL_HW_INTF_PATH_1)/hw_device.cpp \ - $(LOCAL_HW_INTF_PATH_1)/hw_primary.cpp \ - $(LOCAL_HW_INTF_PATH_1)/hw_hdmi.cpp \ - $(LOCAL_HW_INTF_PATH_1)/hw_virtual.cpp \ - $(LOCAL_HW_INTF_PATH_1)/hw_color_manager.cpp \ - $(LOCAL_HW_INTF_PATH_1)/hw_scale.cpp \ - $(LOCAL_HW_INTF_PATH_1)/hw_events.cpp - -ifneq ($(TARGET_IS_HEADLESS), true) - LOCAL_SRC_FILES += $(LOCAL_HW_INTF_PATH_2)/hw_info_drm.cpp \ - $(LOCAL_HW_INTF_PATH_2)/hw_device_drm.cpp \ - $(LOCAL_HW_INTF_PATH_2)/hw_peripheral_drm.cpp \ - $(LOCAL_HW_INTF_PATH_2)/hw_tv_drm.cpp \ - $(LOCAL_HW_INTF_PATH_2)/hw_events_drm.cpp \ - $(LOCAL_HW_INTF_PATH_2)/hw_scale_drm.cpp \ - $(LOCAL_HW_INTF_PATH_2)/hw_virtual_drm.cpp \ - $(LOCAL_HW_INTF_PATH_2)/hw_color_manager_drm.cpp -endif - -include $(BUILD_SHARED_LIBRARY) - -SDM_HEADER_PATH := ../../include -include $(CLEAR_VARS) -LOCAL_VENDOR_MODULE := true -LOCAL_COPY_HEADERS_TO := $(common_header_export_path)/sdm/core -LOCAL_COPY_HEADERS = $(SDM_HEADER_PATH)/core/buffer_allocator.h \ - $(SDM_HEADER_PATH)/core/buffer_sync_handler.h \ - $(SDM_HEADER_PATH)/core/core_interface.h \ - $(SDM_HEADER_PATH)/core/display_interface.h \ - $(SDM_HEADER_PATH)/core/layer_buffer.h \ - $(SDM_HEADER_PATH)/core/layer_stack.h \ - $(SDM_HEADER_PATH)/core/sdm_types.h \ - $(SDM_HEADER_PATH)/core/socket_handler.h -include $(BUILD_COPY_HEADERS) - -include $(CLEAR_VARS) -LOCAL_VENDOR_MODULE := true -LOCAL_COPY_HEADERS_TO := $(common_header_export_path)/sdm/private -LOCAL_COPY_HEADERS = $(SDM_HEADER_PATH)/private/color_interface.h \ - $(SDM_HEADER_PATH)/private/color_params.h \ - $(SDM_HEADER_PATH)/private/extension_interface.h \ - $(SDM_HEADER_PATH)/private/hw_info_types.h \ - $(SDM_HEADER_PATH)/private/partial_update_interface.h \ - $(SDM_HEADER_PATH)/private/resource_interface.h \ - $(SDM_HEADER_PATH)/private/strategy_interface.h \ - $(SDM_HEADER_PATH)/private/dpps_control_interface.h -include $(BUILD_COPY_HEADERS) diff --git a/sdm/libs/core/Makefile.am b/sdm/libs/core/Makefile.am deleted file mode 100644 index 2b45d8e3..00000000 --- a/sdm/libs/core/Makefile.am +++ /dev/null @@ -1,47 +0,0 @@ -HEADER_PATH := ${WORKSPACE}/display/display-hal/sdm/include - -c_sources = core_interface.cpp \ - core_impl.cpp \ - display_base.cpp \ - display_primary.cpp \ - display_hdmi.cpp \ - display_virtual.cpp \ - comp_manager.cpp \ - strategy.cpp \ - resource_default.cpp \ - dump_impl.cpp \ - color_manager.cpp \ - hw_interface.cpp \ - hw_info_interface.cpp \ - hw_events_interface.cpp \ - fb/hw_info.cpp \ - fb/hw_device.cpp \ - fb/hw_primary.cpp \ - fb/hw_hdmi.cpp \ - fb/hw_virtual.cpp \ - fb/hw_color_manager.cpp \ - fb/hw_scale.cpp \ - fb/hw_events.cpp - -core_h_sources = $(HEADER_PATH)/core/*.h - -core_includedir = $(includedir)/sdm/core -core_include_HEADERS = $(core_h_sources) - -private_h_sources = $(HEADER_PATH)/private/*.h - -private_includedir = $(includedir)/sdm/private -private_include_HEADERS = $(private_h_sources) - -utils_h_sources = $(HEADER_PATH)/utils/*.h - -utils_includedir = $(includedir)/sdm/utils -utils_include_HEADERS = $(utils_h_sources) - -lib_LTLIBRARIES = libsdmcore.la -libsdmcore_la_CC = @CC@ -libsdmcore_la_SOURCES = $(c_sources) -libsdmcore_la_CFLAGS = $(COMMON_CFLAGS) -DLOG_TAG=\"SDM\" -libsdmcore_la_CPPFLAGS = $(AM_CPPFLAGS) -libsdmcore_la_LIBADD = ../utils/libsdmutils.la -libsdmcore_la_LDFLAGS = -shared -avoid-version diff --git a/sdm/libs/core/color_manager.cpp b/sdm/libs/core/color_manager.cpp deleted file mode 100644 index 04af820d..00000000 --- a/sdm/libs/core/color_manager.cpp +++ /dev/null @@ -1,254 +0,0 @@ -/* Copyright (c) 2015 - 2018, The Linux Foundataion. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -* -*/ - -#include -#include -#include -#include -#include -#include "color_manager.h" - -#define __CLASS__ "ColorManager" - -namespace sdm { - -DynLib ColorManagerProxy::color_lib_; -CreateColorInterface ColorManagerProxy::create_intf_ = NULL; -DestroyColorInterface ColorManagerProxy::destroy_intf_ = NULL; -HWResourceInfo ColorManagerProxy::hw_res_info_; - -// Below two functions are part of concrete implementation for SDM core private -// color_params.h -void PPFeaturesConfig::Reset() { - for (int i = 0; i < kMaxNumPPFeatures; i++) { - if (feature_[i]) { - delete feature_[i]; - feature_[i] = NULL; - } - } - dirty_ = false; - next_idx_ = 0; -} - -DisplayError PPFeaturesConfig::RetrieveNextFeature(PPFeatureInfo **feature) { - DisplayError ret = kErrorNone; - uint32_t i(0); - - for (i = next_idx_; i < kMaxNumPPFeatures; i++) { - if (feature_[i]) { - *feature = feature_[i]; - next_idx_ = i + 1; - break; - } - } - - if (i == kMaxNumPPFeatures) { - ret = kErrorParameters; - next_idx_ = 0; - } - - return ret; -} - -DisplayError ColorManagerProxy::Init(const HWResourceInfo &hw_res_info) { - DisplayError error = kErrorNone; - - // Load color service library and retrieve its entry points. - if (color_lib_.Open(COLORMGR_LIBRARY_NAME)) { - if (!color_lib_.Sym(CREATE_COLOR_INTERFACE_NAME, reinterpret_cast(&create_intf_)) || - !color_lib_.Sym(DESTROY_COLOR_INTERFACE_NAME, reinterpret_cast(&destroy_intf_))) { - DLOGW("Fail to retrieve = %s from %s", CREATE_COLOR_INTERFACE_NAME, COLORMGR_LIBRARY_NAME); - error = kErrorResources; - } - } else { - DLOGW("Fail to load = %s", COLORMGR_LIBRARY_NAME); - error = kErrorResources; - } - - hw_res_info_ = hw_res_info; - - return error; -} - -void ColorManagerProxy::Deinit() { - color_lib_.~DynLib(); -} - -ColorManagerProxy::ColorManagerProxy(DisplayType type, HWInterface *intf, - const HWDisplayAttributes &attr, - const HWPanelInfo &info) - : device_type_(type), pp_hw_attributes_(), hw_intf_(intf), color_intf_(NULL), pp_features_() {} - -ColorManagerProxy *ColorManagerProxy::CreateColorManagerProxy(DisplayType type, - HWInterface *hw_intf, - const HWDisplayAttributes &attribute, - const HWPanelInfo &panel_info) { - DisplayError error = kErrorNone; - PPFeatureVersion versions; - - // check if all resources are available before invoking factory method from libsdm-color.so. - if (!color_lib_ || !create_intf_ || !destroy_intf_) { - DLOGW("Information for %s isn't available!", COLORMGR_LIBRARY_NAME); - return NULL; - } - - ColorManagerProxy *color_manager_proxy = - new ColorManagerProxy(type, hw_intf, attribute, panel_info); - if (color_manager_proxy) { - // 1. need query post-processing feature version from HWInterface. - error = color_manager_proxy->hw_intf_->GetPPFeaturesVersion(&versions); - PPHWAttributes &hw_attr = color_manager_proxy->pp_hw_attributes_; - if (error != kErrorNone) { - DLOGW("Fail to get DSPP feature versions"); - } else { - hw_attr.Set(hw_res_info_, panel_info, attribute, versions); - DLOGI("PAV2 version is versions = %d, version = %d ", - hw_attr.version.version[kGlobalColorFeaturePaV2], - versions.version[kGlobalColorFeaturePaV2]); - } - - // 2. instantiate concrete ColorInterface from libsdm-color.so, pass all hardware info in. - error = create_intf_(COLOR_VERSION_TAG, color_manager_proxy->device_type_, hw_attr, - &color_manager_proxy->color_intf_); - if (error != kErrorNone) { - DLOGW("Unable to instantiate concrete ColorInterface from %s", COLORMGR_LIBRARY_NAME); - delete color_manager_proxy; - color_manager_proxy = NULL; - } - } - - return color_manager_proxy; -} - -ColorManagerProxy::~ColorManagerProxy() { - if (destroy_intf_) - destroy_intf_(device_type_); - color_intf_ = NULL; -} - -DisplayError ColorManagerProxy::ColorSVCRequestRoute(const PPDisplayAPIPayload &in_payload, - PPDisplayAPIPayload *out_payload, - PPPendingParams *pending_action) { - DisplayError ret = kErrorNone; - - // On completion, dspp_features_ will be populated and mark dirty with all resolved dspp - // feature list with paramaters being transformed into target requirement. - ret = color_intf_->ColorSVCRequestRoute(in_payload, out_payload, &pp_features_, pending_action); - - return ret; -} - -DisplayError ColorManagerProxy::ApplyDefaultDisplayMode(void) { - DisplayError ret = kErrorNone; - - // On POR, will be invoked from prepare<> request once bootanimation is done. - ret = color_intf_->ApplyDefaultDisplayMode(&pp_features_); - - return ret; -} - -bool ColorManagerProxy::NeedsPartialUpdateDisable() { - Locker &locker(pp_features_.GetLocker()); - SCOPE_LOCK(locker); - - return pp_features_.IsDirty(); -} - -DisplayError ColorManagerProxy::Commit() { - static bool first_cycle = true; - if (first_cycle) { - first_cycle = false; - return kErrorNone; - } - - Locker &locker(pp_features_.GetLocker()); - SCOPE_LOCK(locker); - - DisplayError ret = kErrorNone; - if (pp_features_.IsDirty()) { - ret = hw_intf_->SetPPFeatures(&pp_features_); - } - - return ret; -} - -void PPHWAttributes::Set(const HWResourceInfo &hw_res, - const HWPanelInfo &panel_info, - const DisplayConfigVariableInfo &attr, - const PPFeatureVersion &feature_ver) { - HWResourceInfo &res = *this; - res = hw_res; - HWPanelInfo &panel = *this; - panel = panel_info; - DisplayConfigVariableInfo &attributes = *this; - attributes = attr; - version = feature_ver; - panel_max_brightness = panel_info.panel_max_brightness; - - if (strlen(panel_info.panel_name)) { - snprintf(&panel_name[0], sizeof(panel_name), "%s", &panel_info.panel_name[0]); - char *tmp = panel_name; - while ((tmp = strstr(tmp, " ")) != NULL) - *tmp = '_'; - if ((tmp = strstr(panel_name, "\n")) != NULL) - *tmp = '\0'; - } -} - -DisplayError ColorManagerProxy::ColorMgrGetNumOfModes(uint32_t *mode_cnt) { - return color_intf_->ColorIntfGetNumDisplayModes(&pp_features_, 0, mode_cnt); -} - -DisplayError ColorManagerProxy::ColorMgrGetModes(uint32_t *mode_cnt, - SDEDisplayMode *modes) { - return color_intf_->ColorIntfEnumerateDisplayModes(&pp_features_, 0, modes, mode_cnt); -} - -DisplayError ColorManagerProxy::ColorMgrSetMode(int32_t color_mode_id) { - return color_intf_->ColorIntfSetDisplayMode(&pp_features_, 0, color_mode_id); -} - -DisplayError ColorManagerProxy::ColorMgrGetModeInfo(int32_t mode_id, AttrVal *query) { - return color_intf_->ColorIntfGetModeInfo(&pp_features_, 0, mode_id, query); -} - -DisplayError ColorManagerProxy::ColorMgrSetColorTransform(uint32_t length, - const double *trans_data) { - return color_intf_->ColorIntfSetColorTransform(&pp_features_, 0, length, trans_data); -} - -DisplayError ColorManagerProxy::ColorMgrGetDefaultModeID(int32_t *mode_id) { - return color_intf_->ColorIntfGetDefaultModeID(&pp_features_, 0, mode_id); -} - -DisplayError ColorManagerProxy::ColorMgrGetActiveMode(std::string *mode) { - return color_intf_->ColorIntfGetActiveMode(&pp_features_, 0, mode); -} - -} // namespace sdm diff --git a/sdm/libs/core/color_manager.h b/sdm/libs/core/color_manager.h deleted file mode 100644 index d29422ea..00000000 --- a/sdm/libs/core/color_manager.h +++ /dev/null @@ -1,100 +0,0 @@ -/* Copyright (c) 2015-2018, The Linux Foundataion. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -* -*/ - -#ifndef __COLOR_MANAGER_H__ -#define __COLOR_MANAGER_H__ - -#include -#include -#include -#include -#include -#include -#include -#include "hw_interface.h" - -namespace sdm { - -/* - * ColorManager proxy to maintain necessary information to interact with underlying color service. - * Each display object has its own proxy. - */ -class ColorManagerProxy { - public: - static DisplayError Init(const HWResourceInfo &hw_res_info); - static void Deinit(); - - /* Create ColorManagerProxy for this display object, following things need to be happening - * 1. Instantiates concrete ColorInerface implementation. - * 2. Pass all display object specific informations into it. - * 3. Populate necessary resources. - * 4. Need get panel name for hw_panel_info_. - */ - static ColorManagerProxy *CreateColorManagerProxy(DisplayType type, HWInterface *hw_intf, - const HWDisplayAttributes &attribute, - const HWPanelInfo &panel_info); - - /* need reverse the effect of CreateColorManagerProxy. */ - ~ColorManagerProxy(); - - DisplayError ColorSVCRequestRoute(const PPDisplayAPIPayload &in_payload, - PPDisplayAPIPayload *out_payload, - PPPendingParams *pending_action); - DisplayError ApplyDefaultDisplayMode(); - DisplayError ColorMgrGetNumOfModes(uint32_t *mode_cnt); - DisplayError ColorMgrGetModes(uint32_t *mode_cnt, SDEDisplayMode *modes); - DisplayError ColorMgrSetMode(int32_t color_mode_id); - DisplayError ColorMgrGetModeInfo(int32_t mode_id, AttrVal *query); - DisplayError ColorMgrSetColorTransform(uint32_t length, const double *trans_data); - DisplayError ColorMgrGetDefaultModeID(int32_t *mode_id); - DisplayError ColorMgrGetActiveMode(std::string *mode); - bool NeedsPartialUpdateDisable(); - DisplayError Commit(); - - protected: - ColorManagerProxy() {} - ColorManagerProxy(DisplayType type, HWInterface *intf, const HWDisplayAttributes &attr, - const HWPanelInfo &info); - - private: - static DynLib color_lib_; - static CreateColorInterface create_intf_; - static DestroyColorInterface destroy_intf_; - static HWResourceInfo hw_res_info_; - - DisplayType device_type_; - PPHWAttributes pp_hw_attributes_; - HWInterface *hw_intf_; - ColorInterface *color_intf_; - PPFeaturesConfig pp_features_; -}; - -} // namespace sdm - -#endif // __COLOR_MANAGER_H__ diff --git a/sdm/libs/core/comp_manager.cpp b/sdm/libs/core/comp_manager.cpp deleted file mode 100644 index 3acdcf0a..00000000 --- a/sdm/libs/core/comp_manager.cpp +++ /dev/null @@ -1,540 +0,0 @@ -/* -* Copyright (c) 2014 - 2017, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted -* provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright notice, this list of -* conditions and the following disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its contributors may be used to -* endorse or promote products derived from this software without specific prior written -* permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include -#include -#include - -#include "comp_manager.h" -#include "strategy.h" - -#define __CLASS__ "CompManager" - -namespace sdm { - -DisplayError CompManager::Init(const HWResourceInfo &hw_res_info, - ExtensionInterface *extension_intf, - BufferAllocator *buffer_allocator, - BufferSyncHandler *buffer_sync_handler, - SocketHandler *socket_handler) { - SCOPE_LOCK(locker_); - - DisplayError error = kErrorNone; - - if (extension_intf) { - error = extension_intf->CreateResourceExtn(hw_res_info, buffer_allocator, buffer_sync_handler, - &resource_intf_); - extension_intf->CreateDppsControlExtn(&dpps_ctrl_intf_, socket_handler); - } else { - error = ResourceDefault::CreateResourceDefault(hw_res_info, &resource_intf_); - } - - if (error != kErrorNone) { - if (extension_intf) { - extension_intf->DestroyDppsControlExtn(dpps_ctrl_intf_); - } - return error; - } - - hw_res_info_ = hw_res_info; - buffer_allocator_ = buffer_allocator; - extension_intf_ = extension_intf; - - return error; -} - -DisplayError CompManager::Deinit() { - SCOPE_LOCK(locker_); - - if (extension_intf_) { - extension_intf_->DestroyResourceExtn(resource_intf_); - extension_intf_->DestroyDppsControlExtn(dpps_ctrl_intf_); - } else { - ResourceDefault::DestroyResourceDefault(resource_intf_); - } - - return kErrorNone; -} - -DisplayError CompManager::RegisterDisplay(DisplayType type, - const HWDisplayAttributes &display_attributes, - const HWPanelInfo &hw_panel_info, - const HWMixerAttributes &mixer_attributes, - const DisplayConfigVariableInfo &fb_config, - Handle *display_ctx) { - SCOPE_LOCK(locker_); - - DisplayError error = kErrorNone; - - DisplayCompositionContext *display_comp_ctx = new DisplayCompositionContext(); - if (!display_comp_ctx) { - return kErrorMemory; - } - - Strategy *&strategy = display_comp_ctx->strategy; - strategy = new Strategy(extension_intf_, buffer_allocator_, type, hw_res_info_, hw_panel_info, - mixer_attributes, display_attributes, fb_config); - if (!strategy) { - DLOGE("Unable to create strategy"); - delete display_comp_ctx; - return kErrorMemory; - } - - error = strategy->Init(); - if (error != kErrorNone) { - delete strategy; - delete display_comp_ctx; - return error; - } - - error = resource_intf_->RegisterDisplay(type, display_attributes, hw_panel_info, mixer_attributes, - &display_comp_ctx->display_resource_ctx); - if (error != kErrorNone) { - strategy->Deinit(); - delete strategy; - delete display_comp_ctx; - display_comp_ctx = NULL; - return error; - } - - registered_displays_[type] = 1; - display_comp_ctx->is_primary_panel = hw_panel_info.is_primary_panel; - display_comp_ctx->display_type = type; - display_comp_ctx->fb_config = fb_config; - *display_ctx = display_comp_ctx; - // New non-primary display device has been added, so move the composition mode to safe mode until - // resources for the added display is configured properly. - if (!display_comp_ctx->is_primary_panel) { - safe_mode_ = true; - max_sde_ext_layers_ = UINT32(Debug::GetExtMaxlayers()); - } - - DLOGV_IF(kTagCompManager, "registered display bit mask 0x%x, configured display bit mask 0x%x, " \ - "display type %d", registered_displays_.to_ulong(), configured_displays_.to_ulong(), - display_comp_ctx->display_type); - - return kErrorNone; -} - -DisplayError CompManager::UnregisterDisplay(Handle display_ctx) { - SCOPE_LOCK(locker_); - - DisplayCompositionContext *display_comp_ctx = - reinterpret_cast(display_ctx); - - if (!display_comp_ctx) { - return kErrorParameters; - } - - resource_intf_->UnregisterDisplay(display_comp_ctx->display_resource_ctx); - - Strategy *&strategy = display_comp_ctx->strategy; - strategy->Deinit(); - delete strategy; - - registered_displays_[display_comp_ctx->display_type] = 0; - configured_displays_[display_comp_ctx->display_type] = 0; - - if (display_comp_ctx->display_type == kHDMI) { - max_layers_ = kMaxSDELayers; - } - - DLOGV_IF(kTagCompManager, "registered display bit mask 0x%x, configured display bit mask 0x%x, " \ - "display type %d", registered_displays_.to_ulong(), configured_displays_.to_ulong(), - display_comp_ctx->display_type); - - delete display_comp_ctx; - display_comp_ctx = NULL; - return kErrorNone; -} - -DisplayError CompManager::ReconfigureDisplay(Handle comp_handle, - const HWDisplayAttributes &display_attributes, - const HWPanelInfo &hw_panel_info, - const HWMixerAttributes &mixer_attributes, - const DisplayConfigVariableInfo &fb_config) { - SCOPE_LOCK(locker_); - - DisplayError error = kErrorNone; - DisplayCompositionContext *display_comp_ctx = - reinterpret_cast(comp_handle); - - error = resource_intf_->ReconfigureDisplay(display_comp_ctx->display_resource_ctx, - display_attributes, hw_panel_info, mixer_attributes); - if (error != kErrorNone) { - return error; - } - - if (display_comp_ctx->strategy) { - error = display_comp_ctx->strategy->Reconfigure(hw_panel_info, display_attributes, - mixer_attributes, fb_config); - if (error != kErrorNone) { - DLOGE("Unable to Reconfigure strategy."); - display_comp_ctx->strategy->Deinit(); - delete display_comp_ctx->strategy; - display_comp_ctx->strategy = NULL; - return error; - } - } - - // For HDMI S3D mode, set max_layers_ to 0 so that primary display would fall back - // to GPU composition to release pipes for HDMI. - if (display_comp_ctx->display_type == kHDMI) { - if (hw_panel_info.s3d_mode != kS3DModeNone) { - max_layers_ = 0; - } else { - max_layers_ = kMaxSDELayers; - } - } - - // Update new resolution. - display_comp_ctx->fb_config = fb_config; - return error; -} - -void CompManager::PrepareStrategyConstraints(Handle comp_handle, HWLayers *hw_layers) { - DisplayCompositionContext *display_comp_ctx = - reinterpret_cast(comp_handle); - StrategyConstraints *constraints = &display_comp_ctx->constraints; - - constraints->safe_mode = safe_mode_; - constraints->max_layers = max_layers_; - - // Limit 2 layer SDE Comp if its not a Primary Display. - // Safe mode is the policy for External display on a low end device. - if (!display_comp_ctx->is_primary_panel) { - bool low_end_hw = ((hw_res_info_.num_vig_pipe + hw_res_info_.num_rgb_pipe + - hw_res_info_.num_dma_pipe) <= kSafeModeThreshold); - constraints->max_layers = max_sde_ext_layers_; - constraints->safe_mode = (low_end_hw && !hw_res_info_.separate_rotator) ? true : safe_mode_; - } - - // If a strategy fails after successfully allocating resources, then set safe mode - if (display_comp_ctx->remaining_strategies != display_comp_ctx->max_strategies) { - constraints->safe_mode = true; - } - - // TODO(user): App layer count will change for hybrid composition - uint32_t app_layer_count = UINT32(hw_layers->info.stack->layers.size()) - 1; - if (display_comp_ctx->idle_fallback || display_comp_ctx->thermal_fallback_) { - // Handle the idle timeout by falling back - constraints->safe_mode = true; - } - - // Avoid safe mode, if there is only one app layer. - if (app_layer_count == 1) { - constraints->safe_mode = false; - } -} - -void CompManager::PrePrepare(Handle display_ctx, HWLayers *hw_layers) { - SCOPE_LOCK(locker_); - DisplayCompositionContext *display_comp_ctx = - reinterpret_cast(display_ctx); - display_comp_ctx->strategy->Start(&hw_layers->info, &display_comp_ctx->max_strategies, - display_comp_ctx->pu_constraints); - display_comp_ctx->remaining_strategies = display_comp_ctx->max_strategies; -} - -DisplayError CompManager::Prepare(Handle display_ctx, HWLayers *hw_layers) { - SCOPE_LOCK(locker_); - - DisplayCompositionContext *display_comp_ctx = - reinterpret_cast(display_ctx); - Handle &display_resource_ctx = display_comp_ctx->display_resource_ctx; - - DisplayError error = kErrorUndefined; - - PrepareStrategyConstraints(display_ctx, hw_layers); - - // Select a composition strategy, and try to allocate resources for it. - resource_intf_->Start(display_resource_ctx); - - bool exit = false; - uint32_t &count = display_comp_ctx->remaining_strategies; - for (; !exit && count > 0; count--) { - error = display_comp_ctx->strategy->GetNextStrategy(&display_comp_ctx->constraints); - if (error != kErrorNone) { - // Composition strategies exhausted. Resource Manager could not allocate resources even for - // GPU composition. This will never happen. - exit = true; - } - - if (!exit) { - error = resource_intf_->Prepare(display_resource_ctx, hw_layers); - // Exit if successfully prepared resource, else try next strategy. - exit = (error == kErrorNone); - } - } - - if (error != kErrorNone) { - resource_intf_->Stop(display_resource_ctx, hw_layers); - DLOGE("Composition strategies exhausted for display = %d", display_comp_ctx->display_type); - return error; - } - - error = resource_intf_->Stop(display_resource_ctx, hw_layers); - - return error; -} - -DisplayError CompManager::PostPrepare(Handle display_ctx, HWLayers *hw_layers) { - SCOPE_LOCK(locker_); - DisplayCompositionContext *display_comp_ctx = - reinterpret_cast(display_ctx); - Handle &display_resource_ctx = display_comp_ctx->display_resource_ctx; - - DisplayError error = kErrorNone; - error = resource_intf_->PostPrepare(display_resource_ctx, hw_layers); - if (error != kErrorNone) { - return error; - } - - display_comp_ctx->strategy->Stop(); - - return kErrorNone; -} - -DisplayError CompManager::Commit(Handle display_ctx, HWLayers *hw_layers) { - SCOPE_LOCK(locker_); - - DisplayCompositionContext *display_comp_ctx = - reinterpret_cast(display_ctx); - - return resource_intf_->Commit(display_comp_ctx->display_resource_ctx, hw_layers); -} - -DisplayError CompManager::ReConfigure(Handle display_ctx, HWLayers *hw_layers) { - SCOPE_LOCK(locker_); - - DisplayCompositionContext *display_comp_ctx = - reinterpret_cast(display_ctx); - Handle &display_resource_ctx = display_comp_ctx->display_resource_ctx; - - DisplayError error = kErrorUndefined; - resource_intf_->Start(display_resource_ctx); - error = resource_intf_->Prepare(display_resource_ctx, hw_layers); - - if (error != kErrorNone) { - DLOGE("Reconfigure failed for display = %d", display_comp_ctx->display_type); - } - - resource_intf_->Stop(display_resource_ctx, hw_layers); - if (error != kErrorNone) { - error = resource_intf_->PostPrepare(display_resource_ctx, hw_layers); - } - - return error; -} - -DisplayError CompManager::PostCommit(Handle display_ctx, HWLayers *hw_layers) { - SCOPE_LOCK(locker_); - - DisplayError error = kErrorNone; - DisplayCompositionContext *display_comp_ctx = - reinterpret_cast(display_ctx); - configured_displays_[display_comp_ctx->display_type] = 1; - if (configured_displays_ == registered_displays_) { - safe_mode_ = false; - } - - error = resource_intf_->PostCommit(display_comp_ctx->display_resource_ctx, hw_layers); - if (error != kErrorNone) { - return error; - } - - display_comp_ctx->idle_fallback = false; - - DLOGV_IF(kTagCompManager, "registered display bit mask 0x%x, configured display bit mask 0x%x, " \ - "display type %d", registered_displays_, configured_displays_, - display_comp_ctx->display_type); - - return kErrorNone; -} - -void CompManager::Purge(Handle display_ctx) { - SCOPE_LOCK(locker_); - - DisplayCompositionContext *display_comp_ctx = - reinterpret_cast(display_ctx); - - resource_intf_->Purge(display_comp_ctx->display_resource_ctx); - - display_comp_ctx->strategy->Purge(); -} - -DisplayError CompManager::SetIdleTimeoutMs(Handle display_ctx, uint32_t active_ms) { - SCOPE_LOCK(locker_); - - DisplayCompositionContext *display_comp_ctx = - reinterpret_cast(display_ctx); - - return display_comp_ctx->strategy->SetIdleTimeoutMs(active_ms); -} - -void CompManager::ProcessIdleTimeout(Handle display_ctx) { - SCOPE_LOCK(locker_); - - DisplayCompositionContext *display_comp_ctx = - reinterpret_cast(display_ctx); - - if (!display_comp_ctx) { - return; - } - - display_comp_ctx->idle_fallback = true; -} - -void CompManager::ProcessThermalEvent(Handle display_ctx, int64_t thermal_level) { - SCOPE_LOCK(locker_); - - DisplayCompositionContext *display_comp_ctx = - reinterpret_cast(display_ctx); - - if (thermal_level >= kMaxThermalLevel) { - display_comp_ctx->thermal_fallback_ = true; - } else { - display_comp_ctx->thermal_fallback_ = false; - } -} - -void CompManager::ProcessIdlePowerCollapse(Handle display_ctx) { - SCOPE_LOCK(locker_); - - DisplayCompositionContext *display_comp_ctx = - reinterpret_cast(display_ctx); - - if (display_comp_ctx) { - resource_intf_->Perform(ResourceInterface::kCmdResetScalarLUT, - display_comp_ctx->display_resource_ctx); - } -} - -DisplayError CompManager::SetMaxMixerStages(Handle display_ctx, uint32_t max_mixer_stages) { - SCOPE_LOCK(locker_); - - DisplayError error = kErrorNone; - DisplayCompositionContext *display_comp_ctx = - reinterpret_cast(display_ctx); - - if (display_comp_ctx) { - error = resource_intf_->SetMaxMixerStages(display_comp_ctx->display_resource_ctx, - max_mixer_stages); - } - - return error; -} - -void CompManager::ControlPartialUpdate(Handle display_ctx, bool enable) { - SCOPE_LOCK(locker_); - - DisplayCompositionContext *display_comp_ctx = - reinterpret_cast(display_ctx); - display_comp_ctx->pu_constraints.enable = enable; -} - -DisplayError CompManager::ValidateScaling(const LayerRect &crop, const LayerRect &dst, - bool rotate90) { - BufferLayout layout = Debug::IsUbwcTiledFrameBuffer() ? kUBWC : kLinear; - return resource_intf_->ValidateScaling(crop, dst, rotate90, layout, true); -} - -DisplayError CompManager::ValidateAndSetCursorPosition(Handle display_ctx, HWLayers *hw_layers, - int x, int y) { - DisplayCompositionContext *display_comp_ctx = - reinterpret_cast(display_ctx); - Handle &display_resource_ctx = display_comp_ctx->display_resource_ctx; - return resource_intf_->ValidateAndSetCursorPosition(display_resource_ctx, hw_layers, x, y, - &display_comp_ctx->fb_config); -} - -DisplayError CompManager::SetMaxBandwidthMode(HWBwModes mode) { - if ((hw_res_info_.has_dyn_bw_support == false) || (mode >= kBwModeMax)) { - return kErrorNotSupported; - } - - return resource_intf_->SetMaxBandwidthMode(mode); -} - -DisplayError CompManager::GetScaleLutConfig(HWScaleLutInfo *lut_info) { - return resource_intf_->GetScaleLutConfig(lut_info); -} - -DisplayError CompManager::SetDetailEnhancerData(Handle display_ctx, - const DisplayDetailEnhancerData &de_data) { - SCOPE_LOCK(locker_); - if (!hw_res_info_.hw_dest_scalar_info.count) { - return kErrorResources; - } - - DisplayCompositionContext *display_comp_ctx = - reinterpret_cast(display_ctx); - - return resource_intf_->SetDetailEnhancerData(display_comp_ctx->display_resource_ctx, de_data); -} - -DisplayError CompManager::SetCompositionState(Handle display_ctx, - LayerComposition composition_type, bool enable) { - SCOPE_LOCK(locker_); - - DisplayCompositionContext *display_comp_ctx = - reinterpret_cast(display_ctx); - - return display_comp_ctx->strategy->SetCompositionState(composition_type, enable); -} - -DisplayError CompManager::ControlDpps(bool enable) { - if (dpps_ctrl_intf_) { - return enable ? dpps_ctrl_intf_->On() : dpps_ctrl_intf_->Off(); - } - - return kErrorNone; -} - -bool CompManager::SetDisplayState(Handle display_ctx, - DisplayState state, DisplayType display_type) { - display_state_[display_type] = state; - - switch (state) { - case kStateOff: - Purge(display_ctx); - configured_displays_.reset(display_type); - DLOGV_IF(kTagCompManager, "configured_displays_ = 0x%x", configured_displays_); - break; - - case kStateOn: - if (registered_displays_.count() > 1) { - safe_mode_ = true; - DLOGV_IF(kTagCompManager, "safe_mode = %d", safe_mode_); - } - break; - - default: - break; - } - - return true; -} - -} // namespace sdm diff --git a/sdm/libs/core/comp_manager.h b/sdm/libs/core/comp_manager.h deleted file mode 100644 index 7fe4482d..00000000 --- a/sdm/libs/core/comp_manager.h +++ /dev/null @@ -1,118 +0,0 @@ -/* -* Copyright (c) 2014 - 2017, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted -* provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright notice, this list of -* conditions and the following disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its contributors may be used to -* endorse or promote products derived from this software without specific prior written -* permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __COMP_MANAGER_H__ -#define __COMP_MANAGER_H__ - -#include -#include -#include -#include - -#include "strategy.h" -#include "resource_default.h" -#include "hw_interface.h" - -namespace sdm { - -class CompManager { - public: - DisplayError Init(const HWResourceInfo &hw_res_info_, ExtensionInterface *extension_intf, - BufferAllocator *buffer_allocator, BufferSyncHandler *buffer_sync_handler, - SocketHandler *socket_handler); - DisplayError Deinit(); - DisplayError RegisterDisplay(DisplayType type, const HWDisplayAttributes &display_attributes, - const HWPanelInfo &hw_panel_info, - const HWMixerAttributes &mixer_attributes, - const DisplayConfigVariableInfo &fb_config, Handle *display_ctx); - DisplayError UnregisterDisplay(Handle display_ctx); - DisplayError ReconfigureDisplay(Handle display_ctx, const HWDisplayAttributes &display_attributes, - const HWPanelInfo &hw_panel_info, - const HWMixerAttributes &mixer_attributes, - const DisplayConfigVariableInfo &fb_config); - void PrePrepare(Handle display_ctx, HWLayers *hw_layers); - DisplayError Prepare(Handle display_ctx, HWLayers *hw_layers); - DisplayError Commit(Handle display_ctx, HWLayers *hw_layers); - DisplayError PostPrepare(Handle display_ctx, HWLayers *hw_layers); - DisplayError ReConfigure(Handle display_ctx, HWLayers *hw_layers); - DisplayError PostCommit(Handle display_ctx, HWLayers *hw_layers); - void Purge(Handle display_ctx); - DisplayError SetIdleTimeoutMs(Handle display_ctx, uint32_t active_ms); - void ProcessIdleTimeout(Handle display_ctx); - void ProcessThermalEvent(Handle display_ctx, int64_t thermal_level); - void ProcessIdlePowerCollapse(Handle display_ctx); - DisplayError SetMaxMixerStages(Handle display_ctx, uint32_t max_mixer_stages); - void ControlPartialUpdate(Handle display_ctx, bool enable); - DisplayError ValidateScaling(const LayerRect &crop, const LayerRect &dst, bool rotate90); - DisplayError ValidateAndSetCursorPosition(Handle display_ctx, HWLayers *hw_layers, int x, int y); - bool SetDisplayState(Handle display_ctx, DisplayState state, DisplayType display_type); - DisplayError SetMaxBandwidthMode(HWBwModes mode); - DisplayError GetScaleLutConfig(HWScaleLutInfo *lut_info); - DisplayError SetDetailEnhancerData(Handle display_ctx, const DisplayDetailEnhancerData &de_data); - DisplayError SetCompositionState(Handle display_ctx, LayerComposition composition_type, - bool enable); - DisplayError ControlDpps(bool enable); - - private: - static const int kMaxThermalLevel = 3; - static const int kSafeModeThreshold = 4; - - void PrepareStrategyConstraints(Handle display_ctx, HWLayers *hw_layers); - - struct DisplayCompositionContext { - Strategy *strategy = NULL; - StrategyConstraints constraints; - Handle display_resource_ctx = NULL; - DisplayType display_type = kPrimary; - uint32_t max_strategies = 0; - uint32_t remaining_strategies = 0; - bool idle_fallback = false; - bool thermal_fallback_ = false; - // Using primary panel flag of hw panel to configure Constraints. We do not need other hw - // panel parameters for now. - bool is_primary_panel = false; - PUConstraints pu_constraints = {}; - DisplayConfigVariableInfo fb_config = {}; - }; - - Locker locker_; - ResourceInterface *resource_intf_ = NULL; - std::bitset registered_displays_; // Bit mask of registered displays - std::bitset configured_displays_; // Bit mask of sucessfully configured displays - uint32_t display_state_[kDisplayMax] = {}; - bool safe_mode_ = false; // Flag to notify all displays to be in resource crunch - // mode, where strategy manager chooses the best strategy - // that uses optimal number of pipes for each display - HWResourceInfo hw_res_info_; - BufferAllocator *buffer_allocator_ = NULL; - ExtensionInterface *extension_intf_ = NULL; - uint32_t max_layers_ = kMaxSDELayers; - uint32_t max_sde_ext_layers_ = 0; - DppsControlInterface *dpps_ctrl_intf_ = NULL; -}; - -} // namespace sdm - -#endif // __COMP_MANAGER_H__ - diff --git a/sdm/libs/core/core_impl.cpp b/sdm/libs/core/core_impl.cpp deleted file mode 100644 index 5532858e..00000000 --- a/sdm/libs/core/core_impl.cpp +++ /dev/null @@ -1,184 +0,0 @@ -/* -* Copyright (c) 2014 - 2016, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted -* provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright notice, this list of -* conditions and the following disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its contributors may be used to -* endorse or promote products derived from this software without specific prior written -* permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include -#include -#include -#include -#include - -#include "core_impl.h" -#include "display_primary.h" -#include "display_hdmi.h" -#include "display_virtual.h" -#include "hw_info_interface.h" -#include "color_manager.h" - -#define __CLASS__ "CoreImpl" - -namespace sdm { - -CoreImpl::CoreImpl(BufferAllocator *buffer_allocator, - BufferSyncHandler *buffer_sync_handler, - SocketHandler *socket_handler) - : buffer_allocator_(buffer_allocator), buffer_sync_handler_(buffer_sync_handler), - socket_handler_(socket_handler) { -} - -DisplayError CoreImpl::Init() { - SCOPE_LOCK(locker_); - DisplayError error = kErrorNone; - - // Try to load extension library & get handle to its interface. - if (extension_lib_.Open(EXTENSION_LIBRARY_NAME)) { - if (!extension_lib_.Sym(CREATE_EXTENSION_INTERFACE_NAME, - reinterpret_cast(&create_extension_intf_)) || - !extension_lib_.Sym(DESTROY_EXTENSION_INTERFACE_NAME, - reinterpret_cast(&destroy_extension_intf_))) { - DLOGE("Unable to load symbols, error = %s", extension_lib_.Error()); - return kErrorUndefined; - } - - error = create_extension_intf_(EXTENSION_VERSION_TAG, &extension_intf_); - if (error != kErrorNone) { - DLOGE("Unable to create interface"); - return error; - } - } else { - DLOGW("Unable to load = %s, error = %s", EXTENSION_LIBRARY_NAME, extension_lib_.Error()); - } - - error = HWInfoInterface::Create(&hw_info_intf_); - if (error != kErrorNone) { - goto CleanupOnError; - } - - error = hw_info_intf_->GetHWResourceInfo(&hw_resource_); - if (error != kErrorNone) { - goto CleanupOnError; - } - - error = comp_mgr_.Init(hw_resource_, extension_intf_, buffer_allocator_, - buffer_sync_handler_, socket_handler_); - - if (error != kErrorNone) { - goto CleanupOnError; - } - - error = ColorManagerProxy::Init(hw_resource_); - // if failed, doesn't affect display core functionalities. - if (error != kErrorNone) { - DLOGW("Unable creating color manager and continue without it."); - } - - signal(SIGPIPE, SIG_IGN); - return kErrorNone; - -CleanupOnError: - if (hw_info_intf_) { - HWInfoInterface::Destroy(hw_info_intf_); - } - - return error; -} - -DisplayError CoreImpl::Deinit() { - SCOPE_LOCK(locker_); - - ColorManagerProxy::Deinit(); - - comp_mgr_.Deinit(); - HWInfoInterface::Destroy(hw_info_intf_); - - return kErrorNone; -} - -DisplayError CoreImpl::CreateDisplay(DisplayType type, DisplayEventHandler *event_handler, - DisplayInterface **intf) { - SCOPE_LOCK(locker_); - - if (!event_handler || !intf) { - return kErrorParameters; - } - - DisplayBase *display_base = NULL; - - switch (type) { - case kPrimary: - display_base = new DisplayPrimary(event_handler, hw_info_intf_, buffer_sync_handler_, - buffer_allocator_, &comp_mgr_); - break; - case kHDMI: - display_base = new DisplayHDMI(event_handler, hw_info_intf_, buffer_sync_handler_, - buffer_allocator_, &comp_mgr_); - break; - case kVirtual: - display_base = new DisplayVirtual(event_handler, hw_info_intf_, buffer_sync_handler_, - buffer_allocator_, &comp_mgr_); - break; - default: - DLOGE("Spurious display type %d", type); - return kErrorParameters; - } - - if (!display_base) { - return kErrorMemory; - } - - DisplayError error = display_base->Init(); - if (error != kErrorNone) { - delete display_base; - return error; - } - - *intf = display_base; - return kErrorNone; -} - -DisplayError CoreImpl::DestroyDisplay(DisplayInterface *intf) { - SCOPE_LOCK(locker_); - - if (!intf) { - return kErrorParameters; - } - - DisplayBase *display_base = static_cast(intf); - display_base->Deinit(); - delete display_base; - - return kErrorNone; -} - -DisplayError CoreImpl::SetMaxBandwidthMode(HWBwModes mode) { - SCOPE_LOCK(locker_); - - return comp_mgr_.SetMaxBandwidthMode(mode); -} - -DisplayError CoreImpl::GetFirstDisplayInterfaceType(HWDisplayInterfaceInfo *hw_disp_info) { - return hw_info_intf_->GetFirstDisplayInterfaceType(hw_disp_info); -} - -} // namespace sdm - diff --git a/sdm/libs/core/core_impl.h b/sdm/libs/core/core_impl.h deleted file mode 100644 index 2647c78d..00000000 --- a/sdm/libs/core/core_impl.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -* Copyright (c) 2014 - 2016, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted -* provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright notice, this list of -* conditions and the following disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its contributors may be used to -* endorse or promote products derived from this software without specific prior written -* permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __CORE_IMPL_H__ -#define __CORE_IMPL_H__ - -#include -#include -#include -#include -#include - -#include "hw_interface.h" -#include "comp_manager.h" - -#define SET_REVISION(major, minor) ((major << 8) | minor) - -namespace sdm { - -class CoreImpl : public CoreInterface { - public: - // This class implements display core interface revision 1.0. - static const uint16_t kRevision = SET_REVISION(1, 0); - CoreImpl(BufferAllocator *buffer_allocator, BufferSyncHandler *buffer_sync_handler, - SocketHandler *socket_handler); - virtual ~CoreImpl() { } - - // This method returns the interface revision for the current display core object. - // Future revisions will override this method and return the appropriate revision upon query. - virtual uint16_t GetRevision() { return kRevision; } - virtual DisplayError Init(); - virtual DisplayError Deinit(); - - // Methods from core interface - virtual DisplayError CreateDisplay(DisplayType type, DisplayEventHandler *event_handler, - DisplayInterface **intf); - virtual DisplayError DestroyDisplay(DisplayInterface *intf); - virtual DisplayError SetMaxBandwidthMode(HWBwModes mode); - virtual DisplayError GetFirstDisplayInterfaceType(HWDisplayInterfaceInfo *hw_disp_info); - - protected: - Locker locker_; - BufferAllocator *buffer_allocator_ = NULL; - BufferSyncHandler *buffer_sync_handler_ = NULL; - HWResourceInfo hw_resource_; - CompManager comp_mgr_; - HWInfoInterface *hw_info_intf_ = NULL; - DynLib extension_lib_; - ExtensionInterface *extension_intf_ = NULL; - CreateExtensionInterface create_extension_intf_ = NULL; - DestroyExtensionInterface destroy_extension_intf_ = NULL; - SocketHandler *socket_handler_ = NULL; -}; - -} // namespace sdm - -#endif // __CORE_IMPL_H__ - diff --git a/sdm/libs/core/core_interface.cpp b/sdm/libs/core/core_interface.cpp deleted file mode 100644 index b880298d..00000000 --- a/sdm/libs/core/core_interface.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* -* Copyright (c) 2014 - 2015, 2018 The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include -#include -#include -#include - -#include "core_impl.h" - -#define __CLASS__ "CoreInterface" - -#define GET_REVISION(version) (version >> 16) -#define GET_DATA_ALIGNMENT(version) ((version >> 8) & 0xFF) -#define GET_INSTRUCTION_SET(version) (version & 0xFF) - -namespace sdm { - -// Currently, we support only one client and one session for display core. So, create a global -// singleton core object. -struct CoreSingleton { - CoreSingleton() : core_impl(NULL) { } - - CoreImpl *core_impl; - Locker locker; -} g_core; - -DisplayError CoreInterface::CreateCore(BufferAllocator *buffer_allocator, - BufferSyncHandler *buffer_sync_handler, - SocketHandler *socket_handler, - CoreInterface **interface, uint32_t client_version) { - SCOPE_LOCK(g_core.locker); - - if (!buffer_allocator || !buffer_sync_handler || !interface) { - return kErrorParameters; - } - - // Check compatibility of client and core. - uint32_t lib_version = SDM_VERSION_TAG; - if (GET_REVISION(client_version) > GET_REVISION(lib_version)) { - return kErrorVersion; - } else if (GET_DATA_ALIGNMENT(client_version) != GET_DATA_ALIGNMENT(lib_version)) { - return kErrorDataAlignment; - } else if (GET_INSTRUCTION_SET(client_version) != GET_INSTRUCTION_SET(lib_version)) { - return kErrorInstructionSet; - } - - CoreImpl *&core_impl = g_core.core_impl; - if (core_impl) { - return kErrorUndefined; - } - - // Create appropriate CoreImpl object based on client version. - if (GET_REVISION(client_version) == CoreImpl::kRevision) { - core_impl = new CoreImpl(buffer_allocator, buffer_sync_handler, socket_handler); - } else { - return kErrorNotSupported; - } - - if (!core_impl) { - return kErrorMemory; - } - - DisplayError error = core_impl->Init(); - if (error != kErrorNone) { - delete core_impl; - core_impl = NULL; - return error; - } - - *interface = core_impl; - DLOGI("Open interface handle = %p", *interface); - - return kErrorNone; -} - -DisplayError CoreInterface::DestroyCore() { - SCOPE_LOCK(g_core.locker); - - DLOGI("Close handle"); - - CoreImpl *&core_impl = g_core.core_impl; - if (!core_impl) { - return kErrorUndefined; - } - - core_impl->Deinit(); - delete core_impl; - core_impl = NULL; - - return kErrorNone; -} - -} // namespace sdm - diff --git a/sdm/libs/core/display_base.cpp b/sdm/libs/core/display_base.cpp deleted file mode 100644 index 5ae6c18e..00000000 --- a/sdm/libs/core/display_base.cpp +++ /dev/null @@ -1,1688 +0,0 @@ -/* -* Copyright (c) 2014 - 2018, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted -* provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright notice, this list of -* conditions and the following disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its contributors may be used to -* endorse or promote products derived from this software without specific prior written -* permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "display_base.h" -#include "hw_info_interface.h" - -#define __CLASS__ "DisplayBase" - -namespace sdm { - -// TODO(user): Have a single structure handle carries all the interface pointers and variables. -DisplayBase::DisplayBase(DisplayType display_type, DisplayEventHandler *event_handler, - HWDeviceType hw_device_type, BufferSyncHandler *buffer_sync_handler, - BufferAllocator *buffer_allocator, CompManager *comp_manager, - HWInfoInterface *hw_info_intf) - : display_type_(display_type), event_handler_(event_handler), hw_device_type_(hw_device_type), - buffer_sync_handler_(buffer_sync_handler), buffer_allocator_(buffer_allocator), - comp_manager_(comp_manager), hw_info_intf_(hw_info_intf) { -} - -DisplayError DisplayBase::Init() { - lock_guard obj(recursive_mutex_); - DisplayError error = kErrorNone; - hw_panel_info_ = HWPanelInfo(); - hw_intf_->GetHWPanelInfo(&hw_panel_info_); - - uint32_t active_index = 0; - int drop_vsync = 0; - hw_intf_->GetActiveConfig(&active_index); - hw_intf_->GetDisplayAttributes(active_index, &display_attributes_); - fb_config_ = display_attributes_; - - error = Debug::GetMixerResolution(&mixer_attributes_.width, &mixer_attributes_.height); - if (error == kErrorNone) { - hw_intf_->SetMixerAttributes(mixer_attributes_); - } - - error = hw_intf_->GetMixerAttributes(&mixer_attributes_); - if (error != kErrorNone) { - return error; - } - - // Override x_pixels and y_pixels of frame buffer with mixer width and height - fb_config_.x_pixels = mixer_attributes_.width; - fb_config_.y_pixels = mixer_attributes_.height; - - HWScaleLutInfo lut_info = {}; - error = comp_manager_->GetScaleLutConfig(&lut_info); - if (error == kErrorNone) { - error = hw_intf_->SetScaleLutConfig(&lut_info); - if (error != kErrorNone) { - goto CleanupOnError; - } - } - - color_mgr_ = ColorManagerProxy::CreateColorManagerProxy(display_type_, hw_intf_, - display_attributes_, hw_panel_info_); - - if (!color_mgr_) { - DLOGW("Unable to create ColorManagerProxy for display = %d", display_type_); - } else if (InitializeColorModes() != kErrorNone) { - DLOGW("InitColorModes failed for display = %d", display_type_); - } - - error = comp_manager_->RegisterDisplay(display_type_, display_attributes_, hw_panel_info_, - mixer_attributes_, fb_config_, &display_comp_ctx_); - if (error != kErrorNone) { - goto CleanupOnError; - } - - if (hw_info_intf_) { - HWResourceInfo hw_resource_info = HWResourceInfo(); - hw_info_intf_->GetHWResourceInfo(&hw_resource_info); - auto max_mixer_stages = hw_resource_info.num_blending_stages; - int property_value = Debug::GetMaxPipesPerMixer(display_type_); - if (property_value >= 0) { - max_mixer_stages = std::min(UINT32(property_value), hw_resource_info.num_blending_stages); - } - DisplayBase::SetMaxMixerStages(max_mixer_stages); - } - - Debug::GetProperty(DISABLE_HDR_LUT_GEN, &disable_hdr_lut_gen_); - // TODO(user): Temporary changes, to be removed when DRM driver supports - // Partial update with Destination scaler enabled. - SetPUonDestScaler(); - Debug::Get()->GetProperty("sdm.drop_skewed_vsync", &drop_vsync); - drop_skewed_vsync_ = (drop_vsync == 1); - return kErrorNone; - -CleanupOnError: - ClearColorInfo(); - if (display_comp_ctx_) { - comp_manager_->UnregisterDisplay(display_comp_ctx_); - } - - return error; -} - -DisplayError DisplayBase::Deinit() { - { // Scope for lock - lock_guard obj(recursive_mutex_); - ClearColorInfo(); - comp_manager_->UnregisterDisplay(display_comp_ctx_); - } - HWEventsInterface::Destroy(hw_events_intf_); - HWInterface::Destroy(hw_intf_); - - return kErrorNone; -} - -DisplayError DisplayBase::BuildLayerStackStats(LayerStack *layer_stack) { - std::vector &layers = layer_stack->layers; - HWLayersInfo &hw_layers_info = hw_layers_.info; - - hw_layers_info.stack = layer_stack; - - for (auto &layer : layers) { - if (layer->composition == kCompositionGPUTarget) { - hw_layers_info.gpu_target_index = hw_layers_info.app_layer_count; - break; - } - hw_layers_info.app_layer_count++; - } - - DLOGD_IF(kTagDisplay, "LayerStack layer_count: %d, app_layer_count: %d, gpu_target_index: %d, " - "display type: %d", layers.size(), hw_layers_info.app_layer_count, - hw_layers_info.gpu_target_index, display_type_); - - if (!hw_layers_info.app_layer_count) { - DLOGW("Layer count is zero"); - return kErrorNoAppLayers; - } - - if (hw_layers_info.gpu_target_index) { - return ValidateGPUTargetParams(); - } - - return kErrorNone; -} - -DisplayError DisplayBase::ValidateGPUTargetParams() { - HWLayersInfo &hw_layers_info = hw_layers_.info; - Layer *gpu_target_layer = hw_layers_info.stack->layers.at(hw_layers_info.gpu_target_index); - - if (!IsValid(gpu_target_layer->src_rect)) { - DLOGE("Invalid src rect for GPU target layer"); - return kErrorParameters; - } - - if (!IsValid(gpu_target_layer->dst_rect)) { - DLOGE("Invalid dst rect for GPU target layer"); - return kErrorParameters; - } - - float layer_mixer_width = FLOAT(mixer_attributes_.width); - float layer_mixer_height = FLOAT(mixer_attributes_.height); - float fb_width = FLOAT(fb_config_.x_pixels); - float fb_height = FLOAT(fb_config_.y_pixels); - LayerRect src_domain = (LayerRect){0.0f, 0.0f, fb_width, fb_height}; - LayerRect dst_domain = (LayerRect){0.0f, 0.0f, layer_mixer_width, layer_mixer_height}; - LayerRect out_rect = gpu_target_layer->dst_rect; - - MapRect(src_domain, dst_domain, gpu_target_layer->dst_rect, &out_rect); - Normalize(1, 1, &out_rect); - - auto gpu_target_layer_dst_xpixels = out_rect.right - out_rect.left; - auto gpu_target_layer_dst_ypixels = out_rect.bottom - out_rect.top; - - if (gpu_target_layer_dst_xpixels > mixer_attributes_.width || - gpu_target_layer_dst_ypixels > mixer_attributes_.height) { - DLOGE("GPU target layer dst rect is not with in limits gpu wxh %fx%f, mixer wxh %dx%d", - gpu_target_layer_dst_xpixels, gpu_target_layer_dst_ypixels, - mixer_attributes_.width, mixer_attributes_.height); - return kErrorParameters; - } - - return kErrorNone; -} - -DisplayError DisplayBase::Prepare(LayerStack *layer_stack) { - lock_guard obj(recursive_mutex_); - DisplayError error = kErrorNone; - needs_validate_ = true; - - if (!active_) { - return kErrorPermission; - } - - if (!layer_stack) { - return kErrorParameters; - } - - DLOGI_IF(kTagDisplay, "Entering Prepare for display type : %d", display_type_); - error = BuildLayerStackStats(layer_stack); - if (error != kErrorNone) { - return error; - } - - error = HandleHDR(layer_stack); - if (error != kErrorNone) { - DLOGW("HandleHDR failed"); - return error; - } - - if (color_mgr_ && color_mgr_->NeedsPartialUpdateDisable()) { - DisablePartialUpdateOneFrame(); - } - // TODO(user): Temporary changes, to be removed when DRM driver supports - // Partial update with Destination scaler enabled. - if (partial_update_control_ == false || disable_pu_one_frame_ || - disable_pu_on_dest_scaler_) { - comp_manager_->ControlPartialUpdate(display_comp_ctx_, false /* enable */); - disable_pu_one_frame_ = false; - } - - comp_manager_->PrePrepare(display_comp_ctx_, &hw_layers_); - while (true) { - error = comp_manager_->Prepare(display_comp_ctx_, &hw_layers_); - if (error != kErrorNone) { - break; - } - - error = hw_intf_->Validate(&hw_layers_); - if (error == kErrorNone) { - // Strategy is successful now, wait for Commit(). - needs_validate_ = false; - break; - } - if (error == kErrorShutDown) { - comp_manager_->PostPrepare(display_comp_ctx_, &hw_layers_); - return error; - } - } - - comp_manager_->PostPrepare(display_comp_ctx_, &hw_layers_); - - if (error != kErrorNone) { - return error; - } - - error = ValidateHDR(layer_stack); - if (error != kErrorNone) { - DLOGW("ValidateHDR failed"); - } - - DLOGI_IF(kTagDisplay, "Exiting Prepare for display type : %d", display_type_); - return error; -} - -DisplayError DisplayBase::Commit(LayerStack *layer_stack) { - lock_guard obj(recursive_mutex_); - DisplayError error = kErrorNone; - - if (!active_) { - needs_validate_ = true; - return kErrorPermission; - } - - if (!layer_stack) { - return kErrorParameters; - } - - if (needs_validate_) { - DLOGE("Commit: Corresponding Prepare() is not called for display = %d", display_type_); - return kErrorNotValidated; - } - - // Layer stack attributes has changed, need to Reconfigure, currently in use for Hybrid Comp - if (layer_stack->flags.attributes_changed) { - error = comp_manager_->ReConfigure(display_comp_ctx_, &hw_layers_); - if (error != kErrorNone) { - return error; - } - - error = hw_intf_->Validate(&hw_layers_); - if (error != kErrorNone) { - return error; - } - } - - DLOGI_IF(kTagDisplay, "Entering commit for display type : %d", display_type_); - CommitLayerParams(layer_stack); - - error = comp_manager_->Commit(display_comp_ctx_, &hw_layers_); - if (error != kErrorNone) { - return error; - } - - // check if feature list cache is dirty and pending. - // If dirty, need program to hardware blocks. - if (color_mgr_) - error = color_mgr_->Commit(); - if (error != kErrorNone) { // won't affect this execution path. - DLOGW("ColorManager::Commit(...) isn't working"); - } - - error = hw_intf_->Commit(&hw_layers_); - if (error != kErrorNone) { - return error; - } - - PostCommitLayerParams(layer_stack); - - if (partial_update_control_) { - comp_manager_->ControlPartialUpdate(display_comp_ctx_, true /* enable */); - } - - error = comp_manager_->PostCommit(display_comp_ctx_, &hw_layers_); - if (error != kErrorNone) { - return error; - } - // Stop dropping vsync when first commit is received after idle fallback. - drop_hw_vsync_ = false; - DLOGI_IF(kTagDisplay, "Exiting commit for display type : %d", display_type_); - return kErrorNone; -} - -DisplayError DisplayBase::Flush() { - lock_guard obj(recursive_mutex_); - DisplayError error = kErrorNone; - - if (!active_) { - return kErrorPermission; - } - hw_layers_.info.hw_layers.clear(); - error = hw_intf_->Flush(); - if (error == kErrorNone) { - comp_manager_->Purge(display_comp_ctx_); - needs_validate_ = true; - } else { - DLOGW("Unable to flush display = %d", display_type_); - } - - return error; -} - -DisplayError DisplayBase::GetDisplayState(DisplayState *state) { - lock_guard obj(recursive_mutex_); - if (!state) { - return kErrorParameters; - } - - *state = state_; - return kErrorNone; -} - -DisplayError DisplayBase::GetNumVariableInfoConfigs(uint32_t *count) { - lock_guard obj(recursive_mutex_); - return hw_intf_->GetNumDisplayAttributes(count); -} - -DisplayError DisplayBase::GetConfig(uint32_t index, DisplayConfigVariableInfo *variable_info) { - lock_guard obj(recursive_mutex_); - HWDisplayAttributes attrib; - if (hw_intf_->GetDisplayAttributes(index, &attrib) == kErrorNone) { - *variable_info = attrib; - return kErrorNone; - } - - return kErrorNotSupported; -} - -DisplayError DisplayBase::GetConfig(DisplayConfigFixedInfo *fixed_info) { - lock_guard obj(recursive_mutex_); - fixed_info->is_cmdmode = (hw_panel_info_.mode == kModeCommand); - - HWResourceInfo hw_resource_info = HWResourceInfo(); - hw_info_intf_->GetHWResourceInfo(&hw_resource_info); - bool hdr_supported = hw_resource_info.has_hdr; - HWDisplayInterfaceInfo hw_disp_info = {}; - hw_info_intf_->GetFirstDisplayInterfaceType(&hw_disp_info); - if (hw_disp_info.type == kHDMI) { - hdr_supported = (hdr_supported && hw_panel_info_.hdr_enabled); - } - - fixed_info->hdr_supported = hdr_supported; - // Populate luminance values only if hdr will be supported on that display - fixed_info->max_luminance = fixed_info->hdr_supported ? hw_panel_info_.peak_luminance: 0; - fixed_info->average_luminance = fixed_info->hdr_supported ? hw_panel_info_.average_luminance : 0; - fixed_info->min_luminance = fixed_info->hdr_supported ? hw_panel_info_.blackness_level: 0; - fixed_info->hdr_eotf = hw_panel_info_.hdr_eotf; - fixed_info->hdr_metadata_type_one = hw_panel_info_.hdr_metadata_type_one; - - return kErrorNone; -} - -DisplayError DisplayBase::GetActiveConfig(uint32_t *index) { - lock_guard obj(recursive_mutex_); - return hw_intf_->GetActiveConfig(index); -} - -DisplayError DisplayBase::GetVSyncState(bool *enabled) { - lock_guard obj(recursive_mutex_); - if (!enabled) { - return kErrorParameters; - } - - *enabled = vsync_enable_; - - return kErrorNone; -} - -DisplayState DisplayBase::GetLastPowerMode() { - return last_power_mode_; -} - -DisplayError DisplayBase::SetDisplayState(DisplayState state, int *release_fence) { - lock_guard obj(recursive_mutex_); - DisplayError error = kErrorNone; - bool active = false; - - DLOGI("Set state = %d, display %d", state, display_type_); - - if (state == state_) { - DLOGI("Same state transition is requested."); - return kErrorNone; - } - - switch (state) { - case kStateOff: - hw_layers_.info.hw_layers.clear(); - error = hw_intf_->Flush(); - if (error == kErrorNone) { - error = hw_intf_->PowerOff(); - } - break; - - case kStateOn: - error = hw_intf_->PowerOn(release_fence); - if (error != kErrorNone) { - return error; - } - - error = comp_manager_->ReconfigureDisplay(display_comp_ctx_, display_attributes_, - hw_panel_info_, mixer_attributes_, fb_config_); - if (error != kErrorNone) { - return error; - } - - active = true; - last_power_mode_ = kStateOn; - break; - - case kStateDoze: - error = hw_intf_->Doze(release_fence); - active = true; - last_power_mode_ = kStateDoze; - break; - - case kStateDozeSuspend: - error = hw_intf_->DozeSuspend(release_fence); - if (display_type_ != kPrimary) { - active = true; - } - last_power_mode_ = kStateDozeSuspend; - break; - - case kStateStandby: - error = hw_intf_->Standby(); - last_power_mode_ = kStateStandby; - break; - - default: - DLOGE("Spurious state = %d transition requested.", state); - return kErrorParameters; - } - - DisablePartialUpdateOneFrame(); - - if (error == kErrorNone) { - active_ = active; - state_ = state; - comp_manager_->SetDisplayState(display_comp_ctx_, state, display_type_); - } - - return error; -} - -DisplayError DisplayBase::SetActiveConfig(uint32_t index) { - lock_guard obj(recursive_mutex_); - DisplayError error = kErrorNone; - uint32_t active_index = 0; - - hw_intf_->GetActiveConfig(&active_index); - - if (active_index == index) { - return kErrorNone; - } - - error = hw_intf_->SetDisplayAttributes(index); - if (error != kErrorNone) { - return error; - } - - return ReconfigureDisplay(); -} - -DisplayError DisplayBase::SetMaxMixerStages(uint32_t max_mixer_stages) { - lock_guard obj(recursive_mutex_); - DisplayError error = kErrorNone; - - error = comp_manager_->SetMaxMixerStages(display_comp_ctx_, max_mixer_stages); - - if (error == kErrorNone) { - max_mixer_stages_ = max_mixer_stages; - } - - return error; -} - -std::string DisplayBase::Dump() { - lock_guard obj(recursive_mutex_); - HWDisplayAttributes attrib; - uint32_t active_index = 0; - uint32_t num_modes = 0; - std::ostringstream os; - - hw_intf_->GetNumDisplayAttributes(&num_modes); - hw_intf_->GetActiveConfig(&active_index); - hw_intf_->GetDisplayAttributes(active_index, &attrib); - - os << "device type:" << display_type_; - os << "\nstate: " << state_ << " vsync on: " << vsync_enable_ << " max. mixer stages: " - << max_mixer_stages_; - os << "\nnum configs: " << num_modes << " active config index: " << active_index; - - DisplayConfigVariableInfo &info = attrib; - - uint32_t num_hw_layers = 0; - if (hw_layers_.info.stack) { - num_hw_layers = UINT32(hw_layers_.info.hw_layers.size()); - } - - if (num_hw_layers == 0) { - os << "\nNo hardware layers programmed"; - return os.str(); - } - - LayerBuffer *out_buffer = hw_layers_.info.stack->output_buffer; - if (out_buffer) { - os << "\nres: " << out_buffer->width << "x" << out_buffer->height << " format: " - << GetFormatString(out_buffer->format); - } else { - os.precision(2); - os << "\nres: " << info.x_pixels << "x" << info.y_pixels << " dpi: " << std::fixed << - info.x_dpi << "x" << std::fixed << info.y_dpi << " fps: " << info.fps << - " vsync period: " << info.vsync_period_ns; - } - - HWLayersInfo &layer_info = hw_layers_.info; - for (uint32_t i = 0; i < layer_info.left_frame_roi.size(); i++) { - LayerRect &l_roi = layer_info.left_frame_roi.at(i); - LayerRect &r_roi = layer_info.right_frame_roi.at(i); - - os << "\nROI(LTRB)#" << i << " LEFT(" << INT(l_roi.left) << " " << INT(l_roi.top) << " " << - INT(l_roi.right) << " " << INT(l_roi.bottom) << ")"; - if (IsValid(r_roi)) { - os << " RIGHT(" << INT(r_roi.left) << " " << INT(r_roi.top) << " " << INT(r_roi.right) << " " - << INT(r_roi.bottom) << ")"; - } - } - - LayerRect &fb_roi = layer_info.partial_fb_roi; - if (IsValid(fb_roi)) { - os << "\nPartial FB ROI(LTRB):(" << INT(fb_roi.left) << " " << INT(fb_roi.top) << " " << - INT(fb_roi.right) << " " << INT(fb_roi.bottom) << ")"; - } - - const char *header = "\n| Idx | Comp Type | Split | Pipe | W x H | Format | Src Rect (L T R B) | Dst Rect (L T R B) | Z | Flags | Deci(HxV) | CS | Rng |"; //NOLINT - const char *newline = "\n|-----|------------|-----------|------|-------------|--------------------------|---------------------|---------------------|----|------------|-----------|----|-----|"; //NOLINT - const char *format = "\n| %3s | %10s | %9s | %4d | %4d x %4d | %24s | %4d %4d %4d %4d | %4d %4d %4d %4d | %2s | %10s | %9s | %2s | %3s |"; //NOLINT - - os << "\n"; - os << newline; - os << header; - os << newline; - - for (uint32_t i = 0; i < num_hw_layers; i++) { - uint32_t layer_index = hw_layers_.info.index.at(i); - // sdm-layer from client layer stack - Layer *sdm_layer = hw_layers_.info.stack->layers.at(layer_index); - // hw-layer from hw layers info - Layer &hw_layer = hw_layers_.info.hw_layers.at(i); - LayerBuffer *input_buffer = &hw_layer.input_buffer; - HWLayerConfig &layer_config = hw_layers_.config[i]; - HWRotatorSession &hw_rotator_session = layer_config.hw_rotator_session; - - const char *comp_type = GetName(sdm_layer->composition); - const char *buffer_format = GetFormatString(input_buffer->format); - const char *pipe_split[2] = { "Pipe-1", "Pipe-2" }; - char idx[8]; - - snprintf(idx, sizeof(idx), "%d", layer_index); - - for (uint32_t count = 0; count < hw_rotator_session.hw_block_count; count++) { - char row[1024]; - HWRotateInfo &rotate = hw_rotator_session.hw_rotate_info[count]; - LayerRect &src_roi = rotate.src_roi; - LayerRect &dst_roi = rotate.dst_roi; - char rot[12] = { 0 }; - - snprintf(rot, sizeof(rot), "Rot-%s-%d", hw_rotator_session.mode == kRotatorInline ? - "inl" : "off", count + 1); - - snprintf(row, sizeof(row), format, idx, comp_type, rot, - 0, input_buffer->width, input_buffer->height, buffer_format, - INT(src_roi.left), INT(src_roi.top), INT(src_roi.right), INT(src_roi.bottom), - INT(dst_roi.left), INT(dst_roi.top), INT(dst_roi.right), INT(dst_roi.bottom), - "-", "- ", "- ", "-", "-"); - os << row; - // print the below only once per layer block, fill with spaces for rest. - idx[0] = 0; - comp_type = ""; - } - - if (hw_rotator_session.hw_block_count > 0) { - input_buffer = &hw_rotator_session.output_buffer; - buffer_format = GetFormatString(input_buffer->format); - } - - if (layer_config.use_solidfill_stage) { - LayerRect src_roi = layer_config.hw_solidfill_stage.roi; - const char *decimation = ""; - char flags[16] = { 0 }; - char z_order[8] = { 0 }; - const char *color_primary = ""; - const char *range = ""; - char row[1024] = { 0 }; - - snprintf(z_order, sizeof(z_order), "%d", layer_config.hw_solidfill_stage.z_order); - snprintf(flags, sizeof(flags), "0x%08x", hw_layer.flags.flags); - snprintf(row, sizeof(row), format, idx, comp_type, pipe_split[0], - 0, INT(src_roi.right), INT(src_roi.bottom), - buffer_format, INT(src_roi.left), INT(src_roi.top), - INT(src_roi.right), INT(src_roi.bottom), INT(src_roi.left), - INT(src_roi.top), INT(src_roi.right), INT(src_roi.bottom), - z_order, flags, decimation, color_primary, range); - os << row; - continue; - } - - for (uint32_t count = 0; count < 2; count++) { - char decimation[16] = { 0 }; - char flags[16] = { 0 }; - char z_order[8] = { 0 }; - char color_primary[8] = { 0 }; - char range[8] = { 0 }; - - HWPipeInfo &pipe = (count == 0) ? layer_config.left_pipe : layer_config.right_pipe; - - if (!pipe.valid) { - continue; - } - - LayerRect src_roi = pipe.src_roi; - LayerRect &dst_roi = pipe.dst_roi; - if (hw_rotator_session.mode == kRotatorInline) { - src_roi = hw_rotator_session.hw_rotate_info[count].dst_roi; - } - - snprintf(z_order, sizeof(z_order), "%d", pipe.z_order); - snprintf(flags, sizeof(flags), "0x%08x", hw_layer.flags.flags); - snprintf(decimation, sizeof(decimation), "%3d x %3d", pipe.horizontal_decimation, - pipe.vertical_decimation); - ColorMetaData &color_metadata = hw_layer.input_buffer.color_metadata; - snprintf(color_primary, sizeof(color_primary), "%d", color_metadata.colorPrimaries); - snprintf(range, sizeof(range), "%d", color_metadata.range); - - char row[1024]; - snprintf(row, sizeof(row), format, idx, comp_type, pipe_split[count], - pipe.pipe_id, input_buffer->width, input_buffer->height, - buffer_format, INT(src_roi.left), INT(src_roi.top), - INT(src_roi.right), INT(src_roi.bottom), INT(dst_roi.left), - INT(dst_roi.top), INT(dst_roi.right), INT(dst_roi.bottom), - z_order, flags, decimation, color_primary, range); - - os << row; - // print the below only once per layer block, fill with spaces for rest. - idx[0] = 0; - comp_type = ""; - } - } - - os << newline << "\n"; - - return os.str(); -} - -const char * DisplayBase::GetName(const LayerComposition &composition) { - switch (composition) { - case kCompositionGPU: return "GPU"; - case kCompositionSDE: return "SDE"; - case kCompositionCursor: return "CURSOR"; - case kCompositionHybrid: return "HYBRID"; - case kCompositionBlit: return "BLIT"; - case kCompositionGPUTarget: return "GPU_TARGET"; - case kCompositionBlitTarget: return "BLIT_TARGET"; - default: return "UNKNOWN"; - } -} - -DisplayError DisplayBase::ColorSVCRequestRoute(const PPDisplayAPIPayload &in_payload, - PPDisplayAPIPayload *out_payload, - PPPendingParams *pending_action) { - lock_guard obj(recursive_mutex_); - if (color_mgr_) - return color_mgr_->ColorSVCRequestRoute(in_payload, out_payload, pending_action); - else - return kErrorParameters; -} - -DisplayError DisplayBase::GetColorModeCount(uint32_t *mode_count) { - lock_guard obj(recursive_mutex_); - if (!mode_count) { - return kErrorParameters; - } - - if (!color_mgr_) { - return kErrorNotSupported; - } - - DLOGV_IF(kTagQDCM, "Number of modes from color manager = %d", num_color_modes_); - *mode_count = num_color_modes_; - - return kErrorNone; -} - -DisplayError DisplayBase::GetColorModes(uint32_t *mode_count, - std::vector *color_modes) { - lock_guard obj(recursive_mutex_); - if (!mode_count || !color_modes) { - return kErrorParameters; - } - - if (!color_mgr_) { - return kErrorNotSupported; - } - - for (uint32_t i = 0; i < num_color_modes_; i++) { - DLOGV_IF(kTagQDCM, "Color Mode[%d]: Name = %s mode_id = %d", i, color_modes_[i].name, - color_modes_[i].id); - color_modes->at(i) = color_modes_[i].name; - } - - return kErrorNone; -} - -DisplayError DisplayBase::GetColorModeAttr(const std::string &color_mode, AttrVal *attr) { - lock_guard obj(recursive_mutex_); - if (!attr) { - return kErrorParameters; - } - - if (!color_mgr_) { - return kErrorNotSupported; - } - - auto it = color_mode_attr_map_.find(color_mode); - if (it == color_mode_attr_map_.end()) { - DLOGI("Mode %s has no attribute", color_mode.c_str()); - return kErrorNotSupported; - } - *attr = it->second; - - return kErrorNone; -} - -DisplayError DisplayBase::SetColorMode(const std::string &color_mode) { - lock_guard obj(recursive_mutex_); - if (!color_mgr_) { - return kErrorNotSupported; - } - - DynamicRangeType dynamic_range_type; - if (IsSupportColorModeAttribute(color_mode)) { - auto it_mode = color_mode_attr_map_.find(color_mode); - std::string dynamic_range; - GetValueOfModeAttribute(it_mode->second, kDynamicRangeAttribute, &dynamic_range); - if (dynamic_range == kHdr) { - dynamic_range_type = kHdrType; - } else { - dynamic_range_type = kSdrType; - } - } else { - if (color_mode.find("hal_hdr") != std::string::npos) { - dynamic_range_type = kHdrType; - } else { - dynamic_range_type = kSdrType; - } - } - - DisplayError error = kErrorNone; - if (disable_hdr_lut_gen_) { - error = SetColorModeInternal(color_mode); - if (error != kErrorNone) { - return error; - } - // Store the new SDR color mode request by client - if (dynamic_range_type == kSdrType) { - current_color_mode_ = color_mode; - } - return error; - } - - if (hdr_playback_) { - // HDR playback on, If incoming mode is SDR mode, - // cache the mode and apply it after HDR playback stop. - if (dynamic_range_type == kHdrType) { - error = SetColorModeInternal(color_mode); - if (error != kErrorNone) { - return error; - } - } else if (dynamic_range_type == kSdrType) { - current_color_mode_ = color_mode; - } - } else { - // HDR playback off, do not apply HDR mode - if (dynamic_range_type == kHdrType) { - DLOGE("Failed: Forbid setting HDR Mode : %s when HDR playback off", color_mode.c_str()); - return kErrorNotSupported; - } - error = SetColorModeInternal(color_mode); - if (error != kErrorNone) { - return error; - } - current_color_mode_ = color_mode; - } - - return error; -} - -DisplayError DisplayBase::SetColorModeById(int32_t color_mode_id) { - return color_mgr_->ColorMgrSetMode(color_mode_id); -} - -DisplayError DisplayBase::SetColorModeInternal(const std::string &color_mode) { - DLOGV_IF(kTagQDCM, "Color Mode = %s", color_mode.c_str()); - - ColorModeMap::iterator it = color_mode_map_.find(color_mode); - if (it == color_mode_map_.end()) { - DLOGE("Failed: Unknown Mode : %s", color_mode.c_str()); - return kErrorNotSupported; - } - - SDEDisplayMode *sde_display_mode = it->second; - - DLOGV_IF(kTagQDCM, "Color Mode Name = %s corresponding mode_id = %d", sde_display_mode->name, - sde_display_mode->id); - DisplayError error = kErrorNone; - error = color_mgr_->ColorMgrSetMode(sde_display_mode->id); - if (error != kErrorNone) { - DLOGE("Failed for mode id = %d", sde_display_mode->id); - return error; - } - - return error; -} - -DisplayError DisplayBase::GetValueOfModeAttribute(const AttrVal &attr, const std::string &type, - std::string *value) { - if (!value) { - return kErrorParameters; - } - for (auto &it : attr) { - if (it.first.find(type) != std::string::npos) { - *value = it.second; - } - } - - return kErrorNone; -} - -bool DisplayBase::IsSupportColorModeAttribute(const std::string &color_mode) { - auto it = color_mode_attr_map_.find(color_mode); - if (it == color_mode_attr_map_.end()) { - return false; - } - return true; -} - -DisplayError DisplayBase::GetHdrColorMode(std::string *color_mode, bool *found_hdr) { - if (!found_hdr || !color_mode) { - return kErrorParameters; - } - *found_hdr = false; - // get the default HDR mode which is value of picture quality equal to "standard" - for (auto &it_hdr : color_mode_attr_map_) { - std::string dynamic_range, pic_quality; - GetValueOfModeAttribute(it_hdr.second, kDynamicRangeAttribute, &dynamic_range); - GetValueOfModeAttribute(it_hdr.second, kPictureQualityAttribute, &pic_quality); - if (dynamic_range == kHdr && pic_quality == kStandard) { - *color_mode = it_hdr.first; - *found_hdr = true; - } - } - - return kErrorNone; -} - -DisplayError DisplayBase::SetColorTransform(const uint32_t length, const double *color_transform) { - lock_guard obj(recursive_mutex_); - DisplayError ret = kErrorNone; - if (!color_mgr_) { - return kErrorNotSupported; - } - - if (!color_transform) { - return kErrorParameters; - } - - color_transform_active_ = false; - ret = color_mgr_->ColorMgrSetColorTransform(length, color_transform); - if (!ret) { - CopyColorTransformMatrix(color_transform); - } - return ret; -} - -DisplayError DisplayBase::GetDefaultColorMode(std::string *color_mode) { - lock_guard obj(recursive_mutex_); - if (!color_mode) { - return kErrorParameters; - } - - if (!color_mgr_) { - return kErrorNotSupported; - } - - int32_t default_id = kInvalidModeId; - DisplayError error = color_mgr_->ColorMgrGetDefaultModeID(&default_id); - if (error != kErrorNone) { - DLOGE("Failed for get default color mode id"); - return error; - } - - for (uint32_t i = 0; i < num_color_modes_; i++) { - if (color_modes_[i].id == default_id) { - *color_mode = color_modes_[i].name; - return kErrorNone; - } - } - - return kErrorNotSupported; -} - -DisplayError DisplayBase::ApplyDefaultDisplayMode() { - lock_guard obj(recursive_mutex_); - DisplayError error = kErrorNone; - if (color_mgr_) { - error = color_mgr_->ApplyDefaultDisplayMode(); - // Apply default mode failed - if (error != kErrorNone) { - DLOGI("default mode not found"); - return error; - } - DeInitializeColorModes(); - // Default mode apply is called during first frame, if file system - // where mode files is present, ColorManager will not find any modes. - // Once boot animation is complete we re-try to apply the modes, since - // file system should be mounted. InitColorModes needs to called again - error = InitializeColorModes(); - if (error != kErrorNone) { - DLOGE("failed to initial modes\n"); - return error; - } - } else { - return kErrorParameters; - } - return kErrorNone; -} - -DisplayError DisplayBase::SetCursorPosition(int x, int y) { - lock_guard obj(recursive_mutex_); - if (state_ != kStateOn) { - return kErrorNotSupported; - } - - DisplayError error = comp_manager_->ValidateAndSetCursorPosition(display_comp_ctx_, &hw_layers_, - x, y); - if (error == kErrorNone) { - return hw_intf_->SetCursorPosition(&hw_layers_, x, y); - } - - return kErrorNone; -} - -DisplayError DisplayBase::GetRefreshRateRange(uint32_t *min_refresh_rate, - uint32_t *max_refresh_rate) { - lock_guard obj(recursive_mutex_); - // The min and max refresh rates will be same when the HWPanelInfo does not contain valid rates. - // Usually for secondary displays, command mode panels - HWDisplayAttributes display_attributes; - uint32_t active_index = 0; - hw_intf_->GetActiveConfig(&active_index); - DisplayError error = hw_intf_->GetDisplayAttributes(active_index, &display_attributes); - if (error) { - return error; - } - - *min_refresh_rate = display_attributes.fps; - *max_refresh_rate = display_attributes.fps; - - return error; -} - -DisplayError DisplayBase::SetVSyncState(bool enable) { - lock_guard obj(recursive_mutex_); - DisplayError error = kErrorNone; - if (vsync_enable_ != enable) { - error = hw_intf_->SetVSyncState(enable); - if (error == kErrorNotSupported) { - if (drop_skewed_vsync_ && (hw_panel_info_.mode == kModeVideo) && - enable && (current_refresh_rate_ == hw_panel_info_.min_fps)) { - drop_hw_vsync_ = true; - } - error = hw_events_intf_->SetEventState(HWEvent::VSYNC, enable); - } - if (error == kErrorNone) { - vsync_enable_ = enable; - } - } - - return error; -} - -DisplayError DisplayBase::ReconfigureDisplay() { - lock_guard obj(recursive_mutex_); - DisplayError error = kErrorNone; - HWDisplayAttributes display_attributes; - HWMixerAttributes mixer_attributes; - HWPanelInfo hw_panel_info; - uint32_t active_index = 0; - - error = hw_intf_->GetActiveConfig(&active_index); - if (error != kErrorNone) { - return error; - } - - error = hw_intf_->GetDisplayAttributes(active_index, &display_attributes); - if (error != kErrorNone) { - return error; - } - - error = hw_intf_->GetMixerAttributes(&mixer_attributes); - if (error != kErrorNone) { - return error; - } - - error = hw_intf_->GetHWPanelInfo(&hw_panel_info); - if (error != kErrorNone) { - return error; - } - - if (display_attributes == display_attributes_ && mixer_attributes == mixer_attributes_ && - hw_panel_info == hw_panel_info_) { - return kErrorNone; - } - - error = comp_manager_->ReconfigureDisplay(display_comp_ctx_, display_attributes, hw_panel_info, - mixer_attributes, fb_config_); - if (error != kErrorNone) { - return error; - } - - // Disable partial update for one frame on any display changes - DisablePartialUpdateOneFrame(); - - display_attributes_ = display_attributes; - mixer_attributes_ = mixer_attributes; - hw_panel_info_ = hw_panel_info; - // TODO(user): Temporary changes, to be removed when DRM driver supports - // Partial update with Destination scaler enabled. - SetPUonDestScaler(); - - return kErrorNone; -} - -DisplayError DisplayBase::SetMixerResolution(uint32_t width, uint32_t height) { - lock_guard obj(recursive_mutex_); - - DisplayError error = ReconfigureMixer(width, height); - if (error != kErrorNone) { - return error; - } - - req_mixer_width_ = width; - req_mixer_height_ = height; - - return kErrorNone; -} - -DisplayError DisplayBase::GetMixerResolution(uint32_t *width, uint32_t *height) { - lock_guard obj(recursive_mutex_); - if (!width || !height) { - return kErrorParameters; - } - - *width = mixer_attributes_.width; - *height = mixer_attributes_.height; - - return kErrorNone; -} - -DisplayError DisplayBase::ReconfigureMixer(uint32_t width, uint32_t height) { - lock_guard obj(recursive_mutex_); - DisplayError error = kErrorNone; - - if (!width || !height) { - return kErrorParameters; - } - - DLOGD_IF(kTagQDCM, "Reconfiguring mixer with width : %d, height : %d", width, height); - HWMixerAttributes mixer_attributes; - mixer_attributes.width = width; - mixer_attributes.height = height; - - error = hw_intf_->SetMixerAttributes(mixer_attributes); - if (error != kErrorNone) { - return error; - } - - return ReconfigureDisplay(); -} - -bool DisplayBase::NeedsDownScale(const LayerRect &src_rect, const LayerRect &dst_rect, - bool needs_rotation) { - float src_width = FLOAT(src_rect.right - src_rect.left); - float src_height = FLOAT(src_rect.bottom - src_rect.top); - float dst_width = FLOAT(dst_rect.right - dst_rect.left); - float dst_height = FLOAT(dst_rect.bottom - dst_rect.top); - - if (needs_rotation) { - std::swap(src_width, src_height); - } - - if ((src_width > dst_width) || (src_height > dst_height)) { - return true; - } - - return false; -} - -bool DisplayBase::NeedsMixerReconfiguration(LayerStack *layer_stack, uint32_t *new_mixer_width, - uint32_t *new_mixer_height) { - lock_guard obj(recursive_mutex_); - uint32_t layer_count = UINT32(layer_stack->layers.size()); - - uint32_t fb_width = fb_config_.x_pixels; - uint32_t fb_height = fb_config_.y_pixels; - uint32_t fb_area = fb_width * fb_height; - LayerRect fb_rect = (LayerRect) {0.0f, 0.0f, FLOAT(fb_width), FLOAT(fb_height)}; - uint32_t mixer_width = mixer_attributes_.width; - uint32_t mixer_height = mixer_attributes_.height; - uint32_t display_width = display_attributes_.x_pixels; - uint32_t display_height = display_attributes_.y_pixels; - - RectOrientation fb_orientation = GetOrientation(fb_rect); - uint32_t max_layer_area = 0; - uint32_t max_area_layer_index = 0; - std::vector layers = layer_stack->layers; - uint32_t align_x = display_attributes_.is_device_split ? 4 : 2; - uint32_t align_y = 2; - - if (req_mixer_width_ && req_mixer_height_) { - DLOGD_IF(kTagDisplay, "Required mixer width : %d, height : %d", - req_mixer_width_, req_mixer_height_); - *new_mixer_width = req_mixer_width_; - *new_mixer_height = req_mixer_height_; - return (req_mixer_width_ != mixer_width || req_mixer_height_ != mixer_height); - } - - for (uint32_t i = 0; i < layer_count; i++) { - Layer *layer = layers.at(i); - - uint32_t layer_width = UINT32(layer->src_rect.right - layer->src_rect.left); - uint32_t layer_height = UINT32(layer->src_rect.bottom - layer->src_rect.top); - uint32_t layer_area = layer_width * layer_height; - - if (layer_area > max_layer_area) { - max_layer_area = layer_area; - max_area_layer_index = i; - } - } - DLOGV_IF(kTagDisplay, "Max area layer at index : %d", max_area_layer_index); - - // TODO(user): Mark layer which needs downscaling on GPU fallback as priority layer and use MDP - // for composition to avoid quality mismatch between GPU and MDP switch(idle timeout usecase). - if (max_layer_area >= fb_area) { - Layer *layer = layers.at(max_area_layer_index); - bool needs_rotation = (layer->transform.rotation == 90.0f); - - uint32_t layer_width = UINT32(layer->src_rect.right - layer->src_rect.left); - uint32_t layer_height = UINT32(layer->src_rect.bottom - layer->src_rect.top); - LayerRect layer_dst_rect = {}; - - RectOrientation layer_orientation = GetOrientation(layer->src_rect); - if (layer_orientation != kOrientationUnknown && - fb_orientation != kOrientationUnknown) { - if (layer_orientation != fb_orientation) { - std::swap(layer_width, layer_height); - } - } - - // Align the width and height according to fb's aspect ratio - *new_mixer_width = FloorToMultipleOf(UINT32((FLOAT(fb_width) / FLOAT(fb_height)) * - layer_height), align_x); - *new_mixer_height = FloorToMultipleOf(layer_height, align_y); - - LayerRect dst_domain = {0.0f, 0.0f, FLOAT(*new_mixer_width), FLOAT(*new_mixer_height)}; - - MapRect(fb_rect, dst_domain, layer->dst_rect, &layer_dst_rect); - if (NeedsDownScale(layer->src_rect, layer_dst_rect, needs_rotation)) { - *new_mixer_width = display_width; - *new_mixer_height = display_height; - } - if (*new_mixer_width > display_width || *new_mixer_height > display_height) { - *new_mixer_width = display_width; - *new_mixer_height = display_height; - } - return true; - } - - return false; -} - -DisplayError DisplayBase::SetFrameBufferConfig(const DisplayConfigVariableInfo &variable_info) { - lock_guard obj(recursive_mutex_); - uint32_t width = variable_info.x_pixels; - uint32_t height = variable_info.y_pixels; - - if (width == 0 || height == 0) { - DLOGE("Unsupported resolution: (%dx%d)", width, height); - return kErrorParameters; - } - - // Create rects to represent the new source and destination crops - LayerRect crop = LayerRect(0, 0, FLOAT(width), FLOAT(height)); - LayerRect dst = LayerRect(0, 0, FLOAT(mixer_attributes_.width), FLOAT(mixer_attributes_.height)); - // Set rotate90 to false since this is taken care of during regular composition. - bool rotate90 = false; - - DisplayError error = comp_manager_->ValidateScaling(crop, dst, rotate90); - if (error != kErrorNone) { - DLOGE("Unsupported resolution: (%dx%d)", width, height); - return kErrorParameters; - } - - error = comp_manager_->ReconfigureDisplay(display_comp_ctx_, display_attributes_, hw_panel_info_, - mixer_attributes_, variable_info); - if (error != kErrorNone) { - return error; - } - - fb_config_.x_pixels = width; - fb_config_.y_pixels = height; - - DLOGI("New framebuffer resolution (%dx%d)", fb_config_.x_pixels, fb_config_.y_pixels); - - return kErrorNone; -} - -DisplayError DisplayBase::GetFrameBufferConfig(DisplayConfigVariableInfo *variable_info) { - lock_guard obj(recursive_mutex_); - if (!variable_info) { - return kErrorParameters; - } - - *variable_info = fb_config_; - - return kErrorNone; -} - -DisplayError DisplayBase::SetDetailEnhancerData(const DisplayDetailEnhancerData &de_data) { - lock_guard obj(recursive_mutex_); - DisplayError error = comp_manager_->SetDetailEnhancerData(display_comp_ctx_, de_data); - if (error != kErrorNone) { - return error; - } - // TODO(user): Temporary changes, to be removed when DRM driver supports - // Partial update with Destination scaler enabled. - if (GetDriverType() == DriverType::DRM) { - if (de_data.enable) { - disable_pu_on_dest_scaler_ = true; - } else { - SetPUonDestScaler(); - } - } else { - DisablePartialUpdateOneFrame(); - } - - return kErrorNone; -} - -DisplayError DisplayBase::GetDisplayPort(DisplayPort *port) { - lock_guard obj(recursive_mutex_); - - if (!port) { - return kErrorParameters; - } - - *port = hw_panel_info_.port; - - return kErrorNone; -} - -bool DisplayBase::IsPrimaryDisplay() { - lock_guard obj(recursive_mutex_); - - return hw_panel_info_.is_primary_panel; -} - -DisplayError DisplayBase::SetCompositionState(LayerComposition composition_type, bool enable) { - lock_guard obj(recursive_mutex_); - - return comp_manager_->SetCompositionState(display_comp_ctx_, composition_type, enable); -} - -void DisplayBase::CommitLayerParams(LayerStack *layer_stack) { - // Copy the acquire fence from clients layers to HWLayers - uint32_t hw_layers_count = UINT32(hw_layers_.info.hw_layers.size()); - - for (uint32_t i = 0; i < hw_layers_count; i++) { - Layer *sdm_layer = layer_stack->layers.at(hw_layers_.info.index.at(i)); - Layer &hw_layer = hw_layers_.info.hw_layers.at(i); - - hw_layer.input_buffer.planes[0].fd = sdm_layer->input_buffer.planes[0].fd; - hw_layer.input_buffer.planes[0].offset = sdm_layer->input_buffer.planes[0].offset; - hw_layer.input_buffer.planes[0].stride = sdm_layer->input_buffer.planes[0].stride; - hw_layer.input_buffer.size = sdm_layer->input_buffer.size; - hw_layer.input_buffer.acquire_fence_fd = sdm_layer->input_buffer.acquire_fence_fd; - } - - return; -} - -void DisplayBase::PostCommitLayerParams(LayerStack *layer_stack) { - // Copy the release fence from HWLayers to clients layers - uint32_t hw_layers_count = UINT32(hw_layers_.info.hw_layers.size()); - - std::vector fence_dup_flag; - - for (uint32_t i = 0; i < hw_layers_count; i++) { - uint32_t sdm_layer_index = hw_layers_.info.index.at(i); - Layer *sdm_layer = layer_stack->layers.at(sdm_layer_index); - Layer &hw_layer = hw_layers_.info.hw_layers.at(i); - - // Copy the release fence only once for a SDM Layer. - // In S3D use case, two hw layers can share the same input buffer, So make sure to merge the - // output fence fd and assign it to layer's input buffer release fence fd. - if (std::find(fence_dup_flag.begin(), fence_dup_flag.end(), sdm_layer_index) == - fence_dup_flag.end()) { - sdm_layer->input_buffer.release_fence_fd = hw_layer.input_buffer.release_fence_fd; - fence_dup_flag.push_back(sdm_layer_index); - } else { - int temp = -1; - buffer_sync_handler_->SyncMerge(hw_layer.input_buffer.release_fence_fd, - sdm_layer->input_buffer.release_fence_fd, &temp); - - if (hw_layer.input_buffer.release_fence_fd >= 0) { - Sys::close_(hw_layer.input_buffer.release_fence_fd); - hw_layer.input_buffer.release_fence_fd = -1; - } - - if (sdm_layer->input_buffer.release_fence_fd >= 0) { - Sys::close_(sdm_layer->input_buffer.release_fence_fd); - sdm_layer->input_buffer.release_fence_fd = -1; - } - - sdm_layer->input_buffer.release_fence_fd = temp; - } - } - - return; -} - -DisplayError DisplayBase::InitializeColorModes() { - if (!color_mgr_) { - return kErrorNotSupported; - } - - DisplayError error = color_mgr_->ColorMgrGetNumOfModes(&num_color_modes_); - if (error != kErrorNone || !num_color_modes_) { - DLOGV_IF(kTagQDCM, "GetNumModes failed = %d count = %d", error, num_color_modes_); - return kErrorNotSupported; - } - DLOGI("Number of Color Modes = %d", num_color_modes_); - - if (!color_modes_.size()) { - color_modes_.resize(num_color_modes_); - - DisplayError error = color_mgr_->ColorMgrGetModes(&num_color_modes_, color_modes_.data()); - if (error != kErrorNone) { - color_modes_.clear(); - DLOGE("Failed"); - return error; - } - int32_t default_id = kInvalidModeId; - error = color_mgr_->ColorMgrGetDefaultModeID(&default_id); - - AttrVal var; - for (uint32_t i = 0; i < num_color_modes_; i++) { - DLOGV_IF(kTagQDCM, "Color Mode[%d]: Name = %s mode_id = %d", i, color_modes_[i].name, - color_modes_[i].id); - // get the name of default color mode - if (color_modes_[i].id == default_id) { - current_color_mode_ = color_modes_[i].name; - } - auto it = color_mode_map_.find(color_modes_[i].name); - if (it != color_mode_map_.end()) { - if (it->second->id < color_modes_[i].id) { - color_mode_map_.erase(it); - color_mode_map_.insert(std::make_pair(color_modes_[i].name, &color_modes_[i])); - } - } else { - color_mode_map_.insert(std::make_pair(color_modes_[i].name, &color_modes_[i])); - } - - var.clear(); - error = color_mgr_->ColorMgrGetModeInfo(color_modes_[i].id, &var); - if (error != kErrorNone) { - DLOGE("Failed for get attributes of mode_id = %d", color_modes_[i].id); - continue; - } - if (!var.empty()) { - auto it = color_mode_attr_map_.find(color_modes_[i].name); - if (it == color_mode_attr_map_.end()) { - color_mode_attr_map_.insert(std::make_pair(color_modes_[i].name, var)); - } - } - } - } - - return kErrorNone; -} - -DisplayError DisplayBase::SetHDRMode(bool set) { - DisplayError error = kErrorNone; - std::string color_mode = ""; - - if (color_mgr_ && !disable_hdr_lut_gen_) { - // Do not apply HDR Mode when hdr lut generation is disabled - if (set) { - color_mode = "hal_hdr"; - error = color_mgr_->ColorMgrGetActiveMode(¤t_color_mode_); - if (error != kErrorNone) { - DLOGW("Failed to get active color mode"); - } - if (IsSupportColorModeAttribute(current_color_mode_)) { - bool found_hdr = false; - error = GetHdrColorMode(&color_mode, &found_hdr); - if (!found_hdr) { - color_mode = "hal_hdr"; - } - } - } else { - // HDR playback off - set prev mode - color_mode = current_color_mode_; - } - DLOGI("Setting color mode = %s", color_mode.c_str()); - error = SetColorModeInternal(color_mode); - if (color_transform_active_) { - color_mgr_->ColorMgrSetColorTransform(kColorTransformlength_, color_transform_); - } - } - - // DPPS and HDR features are mutually exclusive - comp_manager_->ControlDpps(!set); - hdr_mode_ = set; - - return error; -} - -DisplayError DisplayBase::HandleHDR(LayerStack *layer_stack) { - DisplayError error = kErrorNone; - - if (display_type_ != kPrimary) { - // Handling is needed for only primary displays - return kErrorNone; - } - - if (!layer_stack->flags.hdr_present) { - // HDR playback off - set prev mode - if (hdr_playback_) { - hdr_playback_ = false; - if (hdr_mode_) { - error = SetHDRMode(false); - } - } - } else { - // hdr is present - if (!hdr_playback_ && !layer_stack->flags.animating) { - // hdr is starting - hdr_playback_ = true; - error = SetHDRMode(true); - if (error != kErrorNone) { - DLOGW("Failed to set HDR mode"); - } - } else if (hdr_playback_ && !hdr_mode_) { - error = SetHDRMode(true); - if (error != kErrorNone) { - DLOGW("Failed to set HDR mode"); - } - } - } - - return error; -} - -DisplayError DisplayBase::ValidateHDR(LayerStack *layer_stack) { - DisplayError error = kErrorNone; - - if (display_type_ != kPrimary) { - // Handling is needed for only primary displays - return kErrorNone; - } - - if (hdr_playback_) { - // HDR color mode is set when hdr layer is present in layer_stack. - // If client flags HDR layer as skipped, then blending happens - // in SDR color space. Hence, need to restore the SDR color mode. - if (layer_stack->blend_cs.first != ColorPrimaries_BT2020) { - error = SetHDRMode(false); - if (error != kErrorNone) { - DLOGW("Failed to restore SDR mode"); - } - } - } - - return kErrorNone; -} - -DisplayError DisplayBase::GetClientTargetSupport(uint32_t width, uint32_t height, - LayerBufferFormat format, - const ColorMetaData &color_metadata) { - if (format != kFormatRGBA8888 && format != kFormatRGBA1010102) { - DLOGW("Unsupported format = %d", format); - return kErrorNotSupported; - } else if (ValidateScaling(width, height) != kErrorNone) { - DLOGW("Unsupported width = %d height = %d", width, height); - return kErrorNotSupported; - } else if (color_metadata.transfer && color_metadata.colorPrimaries) { - DisplayError error = ValidateDataspace(color_metadata); - if (error != kErrorNone) { - DLOGW("Unsupported Transfer Request = %d Color Primary = %d", - color_metadata.transfer, color_metadata.colorPrimaries); - return error; - } - - // Check for BT2020 support - if (color_metadata.colorPrimaries == ColorPrimaries_BT2020) { - DLOGW("Unsupported Color Primary = %d", color_metadata.colorPrimaries); - return kErrorNotSupported; - } - } - - return kErrorNone; -} - -DisplayError DisplayBase::ValidateScaling(uint32_t width, uint32_t height) { - uint32_t display_width = display_attributes_.x_pixels; - uint32_t display_height = display_attributes_.y_pixels; - - HWResourceInfo hw_resource_info = HWResourceInfo(); - hw_info_intf_->GetHWResourceInfo(&hw_resource_info); - float max_scale_down = FLOAT(hw_resource_info.max_scale_down); - float max_scale_up = FLOAT(hw_resource_info.max_scale_up); - - float scale_x = FLOAT(width / display_width); - float scale_y = FLOAT(height / display_height); - - if (scale_x > max_scale_down || scale_y > max_scale_down) { - return kErrorNotSupported; - } - - if (UINT32(scale_x) < 1 && scale_x > 0.0f) { - if ((1.0f / scale_x) > max_scale_up) { - return kErrorNotSupported; - } - } - - if (UINT32(scale_y) < 1 && scale_y > 0.0f) { - if ((1.0f / scale_y) > max_scale_up) { - return kErrorNotSupported; - } - } - - return kErrorNone; -} - -DisplayError DisplayBase::ValidateDataspace(const ColorMetaData &color_metadata) { - // Handle transfer - switch (color_metadata.transfer) { - case Transfer_sRGB: - case Transfer_SMPTE_170M: - case Transfer_SMPTE_ST2084: - case Transfer_HLG: - case Transfer_Linear: - case Transfer_Gamma2_2: - break; - default: - DLOGW("Unsupported Transfer Request = %d", color_metadata.transfer); - return kErrorNotSupported; - } - - // Handle colorPrimaries - switch (color_metadata.colorPrimaries) { - case ColorPrimaries_BT709_5: - case ColorPrimaries_BT601_6_525: - case ColorPrimaries_BT601_6_625: - case ColorPrimaries_DCIP3: - case ColorPrimaries_BT2020: - break; - default: - DLOGW("Unsupported Color Primary = %d", color_metadata.colorPrimaries); - return kErrorNotSupported; - } - - return kErrorNone; -} - -// TODO(user): Temporary changes, to be removed when DRM driver supports -// Partial update with Destination scaler enabled. -void DisplayBase::SetPUonDestScaler() { - if (GetDriverType() == DriverType::FB) { - return; - } - uint32_t mixer_width = mixer_attributes_.width; - uint32_t mixer_height = mixer_attributes_.height; - uint32_t display_width = display_attributes_.x_pixels; - uint32_t display_height = display_attributes_.y_pixels; - - disable_pu_on_dest_scaler_ = (mixer_width != display_width || - mixer_height != display_height); -} - -void DisplayBase::ClearColorInfo() { - color_modes_.clear(); - color_mode_map_.clear(); - color_mode_attr_map_.clear(); - - if (color_mgr_) { - delete color_mgr_; - color_mgr_ = NULL; - } -} - -void DisplayBase::DeInitializeColorModes() { - color_mode_map_.clear(); - color_modes_.clear(); - color_mode_attr_map_.clear(); - num_color_modes_ = 0; -} -} // namespace sdm diff --git a/sdm/libs/core/display_base.h b/sdm/libs/core/display_base.h deleted file mode 100644 index 9252c005..00000000 --- a/sdm/libs/core/display_base.h +++ /dev/null @@ -1,205 +0,0 @@ -/* -* Copyright (c) 2014-2018, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted -* provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright notice, this list of -* conditions and the following disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its contributors may be used to -* endorse or promote products derived from this software without specific prior written -* permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __DISPLAY_BASE_H__ -#define __DISPLAY_BASE_H__ - -#include -#include -#include - -#include -#include -#include -#include - -#include "hw_interface.h" -#include "comp_manager.h" -#include "color_manager.h" -#include "hw_events_interface.h" - -namespace sdm { - -using std::recursive_mutex; -using std::lock_guard; - -class DisplayBase : public DisplayInterface { - public: - DisplayBase(DisplayType display_type, DisplayEventHandler *event_handler, - HWDeviceType hw_device_type, BufferSyncHandler *buffer_sync_handler, - BufferAllocator *buffer_allocator, CompManager *comp_manager, - HWInfoInterface *hw_info_intf); - virtual ~DisplayBase() { } - virtual DisplayError Init(); - virtual DisplayError Deinit(); - DisplayError Prepare(LayerStack *layer_stack); - DisplayError Commit(LayerStack *layer_stack); - virtual DisplayError Flush(); - virtual DisplayError GetDisplayState(DisplayState *state); - virtual DisplayError GetNumVariableInfoConfigs(uint32_t *count); - virtual DisplayError GetConfig(uint32_t index, DisplayConfigVariableInfo *variable_info); - virtual DisplayError GetConfig(DisplayConfigFixedInfo *variable_info); - virtual DisplayError GetActiveConfig(uint32_t *index); - virtual DisplayError GetVSyncState(bool *enabled); - virtual DisplayError SetDisplayState(DisplayState state, int *release_fence); - virtual DisplayError SetActiveConfig(uint32_t index); - virtual DisplayError SetActiveConfig(DisplayConfigVariableInfo *variable_info) { - return kErrorNotSupported; - } - virtual DisplayError SetMaxMixerStages(uint32_t max_mixer_stages); - virtual DisplayError ControlPartialUpdate(bool enable, uint32_t *pending) { - return kErrorNotSupported; - } - virtual DisplayError DisablePartialUpdateOneFrame() { - return kErrorNotSupported; - } - virtual DisplayError SetDisplayMode(uint32_t mode) { - return kErrorNotSupported; - } - virtual bool IsUnderscanSupported() { - return false; - } - virtual DisplayError SetPanelBrightness(int level) { - return kErrorNotSupported; - } - virtual DisplayError OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level) { - return kErrorNotSupported; - } - virtual DisplayError ColorSVCRequestRoute(const PPDisplayAPIPayload &in_payload, - PPDisplayAPIPayload *out_payload, - PPPendingParams *pending_action); - virtual DisplayError GetColorModeCount(uint32_t *mode_count); - virtual DisplayError GetColorModes(uint32_t *mode_count, std::vector *color_modes); - virtual DisplayError GetColorModeAttr(const std::string &color_mode, AttrVal *attr); - virtual DisplayError SetColorMode(const std::string &color_mode); - virtual DisplayError SetColorModeById(int32_t color_mode_id); - virtual DisplayError SetColorTransform(const uint32_t length, const double *color_transform); - virtual DisplayError GetDefaultColorMode(std::string *color_mode); - virtual DisplayError ApplyDefaultDisplayMode(void); - virtual DisplayError SetCursorPosition(int x, int y); - virtual DisplayError GetRefreshRateRange(uint32_t *min_refresh_rate, uint32_t *max_refresh_rate); - virtual DisplayError GetPanelBrightness(int *level) { - return kErrorNotSupported; - } - virtual DisplayError SetVSyncState(bool enable); - virtual void SetIdleTimeoutMs(uint32_t active_ms) {} - virtual DisplayError SetMixerResolution(uint32_t width, uint32_t height); - virtual DisplayError GetMixerResolution(uint32_t *width, uint32_t *height); - virtual DisplayError SetFrameBufferConfig(const DisplayConfigVariableInfo &variable_info); - virtual DisplayError GetFrameBufferConfig(DisplayConfigVariableInfo *variable_info); - virtual DisplayError SetDetailEnhancerData(const DisplayDetailEnhancerData &de_data); - virtual DisplayError GetDisplayPort(DisplayPort *port); - virtual bool IsPrimaryDisplay(); - virtual DisplayError SetCompositionState(LayerComposition composition_type, bool enable); - virtual DisplayError GetClientTargetSupport(uint32_t width, uint32_t height, - LayerBufferFormat format, - const ColorMetaData &color_metadata); - virtual std::string Dump(); - - protected: - DisplayError BuildLayerStackStats(LayerStack *layer_stack); - virtual DisplayError ValidateGPUTargetParams(); - void CommitLayerParams(LayerStack *layer_stack); - void PostCommitLayerParams(LayerStack *layer_stack); - DisplayError HandleHDR(LayerStack *layer_stack); - DisplayError ValidateHDR(LayerStack *layer_stack); - DisplayError SetHDRMode(bool set); - DisplayError ValidateScaling(uint32_t width, uint32_t height); - DisplayError ValidateDataspace(const ColorMetaData &color_metadata); - - const char *GetName(const LayerComposition &composition); - DisplayError ReconfigureDisplay(); - bool NeedsMixerReconfiguration(LayerStack *layer_stack, uint32_t *new_mixer_width, - uint32_t *new_mixer_height); - DisplayError ReconfigureMixer(uint32_t width, uint32_t height); - bool NeedsDownScale(const LayerRect &src_rect, const LayerRect &dst_rect, bool needs_rotation); - DisplayError InitializeColorModes(); - void DeInitializeColorModes(); - DisplayError SetColorModeInternal(const std::string &color_mode); - DisplayError GetValueOfModeAttribute(const AttrVal &attr, const std::string &type, - std::string *value); - DisplayError GetHdrColorMode(std::string *color_mode, bool *found_hdr); - bool IsSupportColorModeAttribute(const std::string &color_mode); - DisplayState GetLastPowerMode(); - void SetPUonDestScaler(); - void ClearColorInfo(); - void CopyColorTransformMatrix(const double *input_matrix) { - for (uint32_t i = 0; i < kColorTransformlength_; i++) { - color_transform_[i] = input_matrix[i]; - } - color_transform_active_ = true; - } - - recursive_mutex recursive_mutex_; - DisplayType display_type_; - DisplayEventHandler *event_handler_ = NULL; - HWDeviceType hw_device_type_; - HWInterface *hw_intf_ = NULL; - HWPanelInfo hw_panel_info_; - BufferSyncHandler *buffer_sync_handler_ = NULL; - BufferAllocator *buffer_allocator_ {}; - CompManager *comp_manager_ = NULL; - DisplayState state_ = kStateOff; - bool active_ = false; - Handle hw_device_ = 0; - Handle display_comp_ctx_ = 0; - HWLayers hw_layers_; - bool needs_validate_ = true; - bool vsync_enable_ = false; - uint32_t max_mixer_stages_ = 0; - HWInfoInterface *hw_info_intf_ = NULL; - ColorManagerProxy *color_mgr_ = NULL; // each display object owns its ColorManagerProxy - bool partial_update_control_ = true; - HWEventsInterface *hw_events_intf_ = NULL; - bool disable_pu_one_frame_ = false; - // TODO(user): Temporary changes, to be removed when DRM driver supports - // Partial update with Destination scaler enabled. - bool disable_pu_on_dest_scaler_ = false; - uint32_t num_color_modes_ = 0; - std::vector color_modes_; - typedef std::map ColorModeMap; - ColorModeMap color_mode_map_ = {}; - typedef std::map ColorModeAttrMap; - ColorModeAttrMap color_mode_attr_map_ = {}; - HWDisplayAttributes display_attributes_ = {}; - HWMixerAttributes mixer_attributes_ = {}; - DisplayConfigVariableInfo fb_config_ = {}; - uint32_t req_mixer_width_ = 0; - uint32_t req_mixer_height_ = 0; - std::string current_color_mode_ = "hal_native"; - bool hdr_playback_ = false; - bool hdr_mode_ = false; - int disable_hdr_lut_gen_ = 0; - DisplayState last_power_mode_ = kStateOff; - bool drop_hw_vsync_ = false; - uint32_t current_refresh_rate_ = 0; - bool drop_skewed_vsync_ = false; - static const uint32_t kColorTransformlength_ = 16; - double color_transform_[kColorTransformlength_] = {0}; - bool color_transform_active_ = false; -}; - -} // namespace sdm - -#endif // __DISPLAY_BASE_H__ diff --git a/sdm/libs/core/display_hdmi.cpp b/sdm/libs/core/display_hdmi.cpp deleted file mode 100644 index ed9a739a..00000000 --- a/sdm/libs/core/display_hdmi.cpp +++ /dev/null @@ -1,310 +0,0 @@ -/* -* Copyright (c) 2014 - 2018, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted -* provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright notice, this list of -* conditions and the following disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its contributors may be used to -* endorse or promote products derived from this software without specific prior written -* permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include -#include -#include -#include -#include - -#include "display_hdmi.h" -#include "hw_interface.h" -#include "hw_info_interface.h" - -#define __CLASS__ "DisplayHDMI" - -namespace sdm { - -DisplayHDMI::DisplayHDMI(DisplayEventHandler *event_handler, HWInfoInterface *hw_info_intf, - BufferSyncHandler *buffer_sync_handler, BufferAllocator *buffer_allocator, - CompManager *comp_manager) - : DisplayBase(kHDMI, event_handler, kDeviceHDMI, buffer_sync_handler, buffer_allocator, - comp_manager, hw_info_intf) { -} - -DisplayError DisplayHDMI::Init() { - lock_guard obj(recursive_mutex_); - - DisplayError error = HWInterface::Create(kHDMI, hw_info_intf_, buffer_sync_handler_, - buffer_allocator_, &hw_intf_); - if (error != kErrorNone) { - return error; - } - - uint32_t active_mode_index; - char value[64] = "0"; - Debug::GetProperty(HDMI_S3D_MODE_PROP, value); - HWS3DMode mode = (HWS3DMode)atoi(value); - if (mode > kS3DModeNone && mode < kS3DModeMax) { - active_mode_index = GetBestConfig(mode); - } else { - active_mode_index = GetBestConfig(kS3DModeNone); - } - - error = hw_intf_->SetDisplayAttributes(active_mode_index); - if (error != kErrorNone) { - HWInterface::Destroy(hw_intf_); - return error; - } - - error = DisplayBase::Init(); - if (error != kErrorNone) { - HWInterface::Destroy(hw_intf_); - return error; - } - - GetScanSupport(); - underscan_supported_ = (scan_support_ == kScanAlwaysUnderscanned) || (scan_support_ == kScanBoth); - - s3d_format_to_mode_.insert(std::pair - (kS3dFormatNone, kS3DModeNone)); - s3d_format_to_mode_.insert(std::pair - (kS3dFormatLeftRight, kS3DModeLR)); - s3d_format_to_mode_.insert(std::pair - (kS3dFormatRightLeft, kS3DModeRL)); - s3d_format_to_mode_.insert(std::pair - (kS3dFormatTopBottom, kS3DModeTB)); - s3d_format_to_mode_.insert(std::pair - (kS3dFormatFramePacking, kS3DModeFP)); - - error = HWEventsInterface::Create(INT(display_type_), this, event_list_, hw_intf_, - &hw_events_intf_); - if (error != kErrorNone) { - DisplayBase::Deinit(); - HWInterface::Destroy(hw_intf_); - DLOGE("Failed to create hardware events interface. Error = %d", error); - } - - current_refresh_rate_ = hw_panel_info_.max_fps; - - return error; -} - -DisplayError DisplayHDMI::Prepare(LayerStack *layer_stack) { - lock_guard obj(recursive_mutex_); - DisplayError error = kErrorNone; - uint32_t new_mixer_width = 0; - uint32_t new_mixer_height = 0; - uint32_t display_width = display_attributes_.x_pixels; - uint32_t display_height = display_attributes_.y_pixels; - - if (NeedsMixerReconfiguration(layer_stack, &new_mixer_width, &new_mixer_height)) { - error = ReconfigureMixer(new_mixer_width, new_mixer_height); - if (error != kErrorNone) { - ReconfigureMixer(display_width, display_height); - } - } - - SetS3DMode(layer_stack); - - // Clean hw layers for reuse. - hw_layers_ = HWLayers(); - - return DisplayBase::Prepare(layer_stack); -} - -DisplayError DisplayHDMI::GetRefreshRateRange(uint32_t *min_refresh_rate, - uint32_t *max_refresh_rate) { - lock_guard obj(recursive_mutex_); - DisplayError error = kErrorNone; - - if (hw_panel_info_.min_fps && hw_panel_info_.max_fps) { - *min_refresh_rate = hw_panel_info_.min_fps; - *max_refresh_rate = hw_panel_info_.max_fps; - } else { - error = DisplayBase::GetRefreshRateRange(min_refresh_rate, max_refresh_rate); - } - - return error; -} - -DisplayError DisplayHDMI::SetRefreshRate(uint32_t refresh_rate, bool final_rate) { - lock_guard obj(recursive_mutex_); - - if (!active_) { - return kErrorPermission; - } - - if (current_refresh_rate_ != refresh_rate) { - DisplayError error = hw_intf_->SetRefreshRate(refresh_rate); - if (error != kErrorNone) { - return error; - } - } - - current_refresh_rate_ = refresh_rate; - return DisplayBase::ReconfigureDisplay(); -} - -bool DisplayHDMI::IsUnderscanSupported() { - lock_guard obj(recursive_mutex_); - return underscan_supported_; -} - -DisplayError DisplayHDMI::OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level) { - lock_guard obj(recursive_mutex_); - return hw_intf_->OnMinHdcpEncryptionLevelChange(min_enc_level); -} - -uint32_t DisplayHDMI::GetBestConfig(HWS3DMode s3d_mode) { - uint32_t best_index = 0, index; - uint32_t num_modes = 0; - - hw_intf_->GetNumDisplayAttributes(&num_modes); - - // Get display attribute for each mode - std::vector attrib(num_modes); - for (index = 0; index < num_modes; index++) { - hw_intf_->GetDisplayAttributes(index, &attrib[index]); - } - - // Select best config for s3d_mode. If s3d is not enabled, s3d_mode is kS3DModeNone - for (index = 0; index < num_modes; index ++) { - if (attrib[index].s3d_config[s3d_mode]) { - break; - } - } - - index = 0; - best_index = UINT32(index); - for (size_t index = best_index + 1; index < num_modes; index ++) { - // TODO(user): Need to add support to S3D modes - // From the available configs, select the best - // Ex: 1920x1080@60Hz is better than 1920x1080@30 and 1920x1080@30 is better than 1280x720@60 - if (attrib[index].x_pixels > attrib[best_index].x_pixels) { - best_index = UINT32(index); - } else if (attrib[index].x_pixels == attrib[best_index].x_pixels) { - if (attrib[index].y_pixels > attrib[best_index].y_pixels) { - best_index = UINT32(index); - } else if (attrib[index].y_pixels == attrib[best_index].y_pixels) { - if (attrib[index].vsync_period_ns < attrib[best_index].vsync_period_ns) { - best_index = UINT32(index); - } - } - } - } - char val[kPropertyMax]={}; - // Used for changing HDMI Resolution - override the best with user set config - bool user_config = (Debug::GetExternalResolution(val)); - - if (user_config) { - uint32_t config_index = 0; - // For the config, get the corresponding index - DisplayError error = hw_intf_->GetConfigIndex(val, &config_index); - if (error == kErrorNone) - return config_index; - } - - return best_index; -} - -void DisplayHDMI::GetScanSupport() { - DisplayError error = kErrorNone; - uint32_t video_format = 0; - uint32_t max_cea_format = 0; - HWScanInfo scan_info = HWScanInfo(); - hw_intf_->GetHWScanInfo(&scan_info); - - uint32_t active_mode_index = 0; - hw_intf_->GetActiveConfig(&active_mode_index); - - error = hw_intf_->GetVideoFormat(active_mode_index, &video_format); - if (error != kErrorNone) { - return; - } - - error = hw_intf_->GetMaxCEAFormat(&max_cea_format); - if (error != kErrorNone) { - return; - } - - // The scan support for a given HDMI TV must be read from scan info corresponding to - // Preferred Timing if the preferred timing of the display is currently active, and if it is - // valid. In all other cases, we must read the scan support from CEA scan info if - // the resolution is a CEA resolution, or from IT scan info for all other resolutions. - if (active_mode_index == 0 && scan_info.pt_scan_support != kScanNotSupported) { - scan_support_ = scan_info.pt_scan_support; - } else if (video_format < max_cea_format) { - scan_support_ = scan_info.cea_scan_support; - } else { - scan_support_ = scan_info.it_scan_support; - } -} - -void DisplayHDMI::SetS3DMode(LayerStack *layer_stack) { - uint32_t s3d_layer_count = 0; - HWS3DMode s3d_mode = kS3DModeNone; - uint32_t layer_count = UINT32(layer_stack->layers.size()); - - // S3D mode is supported for the following scenarios: - // 1. Layer stack containing only one s3d layer which is not skip - // 2. Layer stack containing only one secure layer along with one s3d layer - for (uint32_t i = 0; i < layer_count; i++) { - Layer *layer = layer_stack->layers.at(i); - LayerBuffer &layer_buffer = layer->input_buffer; - - if (layer_buffer.s3d_format != kS3dFormatNone) { - s3d_layer_count++; - if (s3d_layer_count > 1 || layer->flags.skip) { - s3d_mode = kS3DModeNone; - break; - } - - std::map::iterator it = - s3d_format_to_mode_.find(layer_buffer.s3d_format); - if (it != s3d_format_to_mode_.end()) { - s3d_mode = it->second; - } - } else if (layer_buffer.flags.secure && layer_count > 2) { - s3d_mode = kS3DModeNone; - break; - } - } - - if (hw_intf_->SetS3DMode(s3d_mode) != kErrorNone) { - hw_intf_->SetS3DMode(kS3DModeNone); - layer_stack->flags.s3d_mode_present = false; - } else if (s3d_mode != kS3DModeNone) { - layer_stack->flags.s3d_mode_present = true; - } - - DisplayBase::ReconfigureDisplay(); -} - -void DisplayHDMI::CECMessage(char *message) { - event_handler_->CECMessage(message); -} - -DisplayError DisplayHDMI::VSync(int64_t timestamp) { - if (vsync_enable_) { - DisplayEventVSync vsync; - vsync.timestamp = timestamp; - event_handler_->VSync(vsync); - } - - return kErrorNone; -} - -} // namespace sdm - diff --git a/sdm/libs/core/display_hdmi.h b/sdm/libs/core/display_hdmi.h deleted file mode 100644 index 64aa6c7c..00000000 --- a/sdm/libs/core/display_hdmi.h +++ /dev/null @@ -1,76 +0,0 @@ -/* -* Copyright (c) 2014 - 2017, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted -* provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright notice, this list of -* conditions and the following disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its contributors may be used to -* endorse or promote products derived from this software without specific prior written -* permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __DISPLAY_HDMI_H__ -#define __DISPLAY_HDMI_H__ - -#include -#include - -#include "display_base.h" -#include "hw_events_interface.h" - -namespace sdm { - -class HWHDMIInterface; - -class DisplayHDMI : public DisplayBase, HWEventHandler { - public: - DisplayHDMI(DisplayEventHandler *event_handler, HWInfoInterface *hw_info_intf, - BufferSyncHandler *buffer_sync_handler, BufferAllocator *buffer_allocator, - CompManager *comp_manager); - virtual DisplayError Init(); - virtual DisplayError Prepare(LayerStack *layer_stack); - virtual DisplayError GetRefreshRateRange(uint32_t *min_refresh_rate, uint32_t *max_refresh_rate); - virtual DisplayError SetRefreshRate(uint32_t refresh_rate, bool final_rate); - virtual bool IsUnderscanSupported(); - virtual DisplayError OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level); - - // Implement the HWEventHandlers - virtual DisplayError VSync(int64_t timestamp); - virtual DisplayError Blank(bool blank) { return kErrorNone; } - virtual void IdleTimeout() { } - virtual void ThermalEvent(int64_t thermal_level) { } - virtual void CECMessage(char *message); - virtual void IdlePowerCollapse() { } - virtual void PingPongTimeout() { } - virtual void PanelDead() { } - - private: - uint32_t GetBestConfig(HWS3DMode s3d_mode); - void GetScanSupport(); - void SetS3DMode(LayerStack *layer_stack); - static const int kPropertyMax = 256; - - bool underscan_supported_ = false; - HWScanSupport scan_support_; - std::map s3d_format_to_mode_; - std::vector event_list_ = { HWEvent::VSYNC, HWEvent::IDLE_NOTIFY, HWEvent::EXIT, - HWEvent::CEC_READ_MESSAGE }; - uint32_t current_refresh_rate_ = 0; -}; - -} // namespace sdm - -#endif // __DISPLAY_HDMI_H__ diff --git a/sdm/libs/core/display_primary.cpp b/sdm/libs/core/display_primary.cpp deleted file mode 100644 index ba83d05c..00000000 --- a/sdm/libs/core/display_primary.cpp +++ /dev/null @@ -1,420 +0,0 @@ -/* -* Copyright (c) 2014 - 2018, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted -* provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright notice, this list of -* conditions and the following disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its contributors may be used to -* endorse or promote products derived from this software without specific prior written -* permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include -#include -#include -#include -#include -#include -#include - -#include "display_primary.h" -#include "hw_interface.h" -#include "hw_info_interface.h" - -#define __CLASS__ "DisplayPrimary" - -namespace sdm { - -DisplayPrimary::DisplayPrimary(DisplayEventHandler *event_handler, HWInfoInterface *hw_info_intf, - BufferSyncHandler *buffer_sync_handler, - BufferAllocator *buffer_allocator, CompManager *comp_manager) - : DisplayBase(kPrimary, event_handler, kDevicePrimary, buffer_sync_handler, buffer_allocator, - comp_manager, hw_info_intf) { -} - -DisplayError DisplayPrimary::Init() { - lock_guard obj(recursive_mutex_); - - DisplayError error = HWInterface::Create(kPrimary, hw_info_intf_, buffer_sync_handler_, - buffer_allocator_, &hw_intf_); - if (error != kErrorNone) { - return error; - } - - error = DisplayBase::Init(); - if (error != kErrorNone) { - HWInterface::Destroy(hw_intf_); - return error; - } - - if (hw_panel_info_.mode == kModeCommand && Debug::IsVideoModeEnabled()) { - error = hw_intf_->SetDisplayMode(kModeVideo); - if (error != kErrorNone) { - DLOGW("Retaining current display mode. Current = %d, Requested = %d", hw_panel_info_.mode, - kModeVideo); - } - } - - if (hw_panel_info_.mode == kModeCommand) { - event_list_ = { HWEvent::VSYNC, - HWEvent::EXIT, - HWEvent::SHOW_BLANK_EVENT, - HWEvent::THERMAL_LEVEL, - HWEvent::IDLE_POWER_COLLAPSE, - HWEvent::PINGPONG_TIMEOUT, - HWEvent::PANEL_DEAD }; - } else { - event_list_ = { HWEvent::VSYNC, - HWEvent::EXIT, - HWEvent::IDLE_NOTIFY, - HWEvent::SHOW_BLANK_EVENT, - HWEvent::THERMAL_LEVEL, - HWEvent::PINGPONG_TIMEOUT, - HWEvent::PANEL_DEAD }; - } - - avr_prop_disabled_ = Debug::IsAVRDisabled(); - - error = HWEventsInterface::Create(INT(display_type_), this, event_list_, hw_intf_, - &hw_events_intf_); - if (error != kErrorNone) { - DLOGE("Failed to create hardware events interface. Error = %d", error); - DisplayBase::Deinit(); - HWInterface::Destroy(hw_intf_); - } - - current_refresh_rate_ = hw_panel_info_.max_fps; - - return error; -} - -DisplayError DisplayPrimary::Prepare(LayerStack *layer_stack) { - lock_guard obj(recursive_mutex_); - DisplayError error = kErrorNone; - uint32_t new_mixer_width = 0; - uint32_t new_mixer_height = 0; - uint32_t display_width = display_attributes_.x_pixels; - uint32_t display_height = display_attributes_.y_pixels; - - if (reset_panel_) { - DLOGW("panel is in bad state, resetting the panel"); - ResetPanel(); - reset_panel_ = false; - } - - if (NeedsMixerReconfiguration(layer_stack, &new_mixer_width, &new_mixer_height)) { - error = ReconfigureMixer(new_mixer_width, new_mixer_height); - if (error != kErrorNone) { - ReconfigureMixer(display_width, display_height); - } - } - - // Clean hw layers for reuse. - hw_layers_ = HWLayers(); - hw_layers_.hw_avr_info.enable = NeedsAVREnable(); - - return DisplayBase::Prepare(layer_stack); -} - -DisplayError DisplayPrimary::Commit(LayerStack *layer_stack) { - lock_guard obj(recursive_mutex_); - DisplayError error = kErrorNone; - uint32_t app_layer_count = hw_layers_.info.app_layer_count; - - // Enabling auto refresh is async and needs to happen before commit ioctl - if (hw_panel_info_.mode == kModeCommand) { - bool enable = (app_layer_count == 1) && layer_stack->flags.single_buffered_layer_present; - bool need_refresh = layer_stack->flags.single_buffered_layer_present && (app_layer_count > 1); - - hw_intf_->SetAutoRefresh(enable); - if (need_refresh) { - event_handler_->Refresh(); - } - } - - error = DisplayBase::Commit(layer_stack); - if (error != kErrorNone) { - return error; - } - - DisplayBase::ReconfigureDisplay(); - - int idle_time_ms = hw_layers_.info.set_idle_time_ms; - if (idle_time_ms >= 0) { - hw_intf_->SetIdleTimeoutMs(UINT32(idle_time_ms)); - } - - if (switch_to_cmd_) { - uint32_t pending; - switch_to_cmd_ = false; - ControlPartialUpdate(true /* enable */, &pending); - } - - return error; -} - -DisplayError DisplayPrimary::SetDisplayState(DisplayState state, int *release_fence) { - lock_guard obj(recursive_mutex_); - DisplayError error = kErrorNone; - error = DisplayBase::SetDisplayState(state, release_fence); - if (error != kErrorNone) { - return error; - } - - // Set vsync enable state to false, as driver disables vsync during display power off. - if (state == kStateOff) { - vsync_enable_ = false; - } - - return kErrorNone; -} - -void DisplayPrimary::SetIdleTimeoutMs(uint32_t active_ms) { - lock_guard obj(recursive_mutex_); - comp_manager_->SetIdleTimeoutMs(display_comp_ctx_, active_ms); -} - -DisplayError DisplayPrimary::SetDisplayMode(uint32_t mode) { - DisplayError error = kErrorNone; - - // Limit scope of mutex to this block - { - lock_guard obj(recursive_mutex_); - HWDisplayMode hw_display_mode = static_cast(mode); - uint32_t pending = 0; - - if (!active_) { - DLOGW("Invalid display state = %d. Panel must be on.", state_); - return kErrorNotSupported; - } - - if (hw_display_mode != kModeCommand && hw_display_mode != kModeVideo) { - DLOGW("Invalid panel mode parameters. Requested = %d", hw_display_mode); - return kErrorParameters; - } - - if (hw_display_mode == hw_panel_info_.mode) { - DLOGW("Same display mode requested. Current = %d, Requested = %d", hw_panel_info_.mode, - hw_display_mode); - return kErrorNone; - } - - error = hw_intf_->SetDisplayMode(hw_display_mode); - if (error != kErrorNone) { - DLOGW("Retaining current display mode. Current = %d, Requested = %d", hw_panel_info_.mode, - hw_display_mode); - return error; - } - - if (mode == kModeVideo) { - ControlPartialUpdate(false /* enable */, &pending); - } else if (mode == kModeCommand) { - // Flush idle timeout value currently set. - comp_manager_->SetIdleTimeoutMs(display_comp_ctx_, 0); - switch_to_cmd_ = true; - } - } - - // Request for a new draw cycle. New display mode will get applied on next draw cycle. - // New idle time will get configured as part of this. - event_handler_->Refresh(); - - return error; -} - -DisplayError DisplayPrimary::SetPanelBrightness(int level) { - lock_guard obj(recursive_mutex_); - return hw_intf_->SetPanelBrightness(level); -} - -DisplayError DisplayPrimary::GetRefreshRateRange(uint32_t *min_refresh_rate, - uint32_t *max_refresh_rate) { - lock_guard obj(recursive_mutex_); - DisplayError error = kErrorNone; - - if (hw_panel_info_.min_fps && hw_panel_info_.max_fps) { - *min_refresh_rate = hw_panel_info_.min_fps; - *max_refresh_rate = hw_panel_info_.max_fps; - } else { - error = DisplayBase::GetRefreshRateRange(min_refresh_rate, max_refresh_rate); - } - - return error; -} - -DisplayError DisplayPrimary::SetRefreshRate(uint32_t refresh_rate, bool final_rate) { - lock_guard obj(recursive_mutex_); - - if (!active_ || !hw_panel_info_.dynamic_fps) { - return kErrorNotSupported; - } - - if (refresh_rate < hw_panel_info_.min_fps || refresh_rate > hw_panel_info_.max_fps) { - DLOGE("Invalid Fps = %d request", refresh_rate); - return kErrorParameters; - } - - if (handle_idle_timeout_ && !final_rate) { - refresh_rate = hw_panel_info_.min_fps; - } - - if ((current_refresh_rate_ != refresh_rate) || handle_idle_timeout_) { - DisplayError error = hw_intf_->SetRefreshRate(refresh_rate); - if (error != kErrorNone) { - return error; - } - } - - // On success, set current refresh rate to new refresh rate - current_refresh_rate_ = refresh_rate; - handle_idle_timeout_ = false; - - return DisplayBase::ReconfigureDisplay(); -} - -DisplayError DisplayPrimary::VSync(int64_t timestamp) { - if (vsync_enable_ && !drop_hw_vsync_) { - DisplayEventVSync vsync; - vsync.timestamp = timestamp; - event_handler_->VSync(vsync); - } - - return kErrorNone; -} - -void DisplayPrimary::IdleTimeout() { - if (hw_panel_info_.mode == kModeVideo) { - if (event_handler_->HandleEvent(kIdleTimeout) != kErrorNone) { - return; - } - handle_idle_timeout_ = true; - event_handler_->Refresh(); - lock_guard obj(recursive_mutex_); - comp_manager_->ProcessIdleTimeout(display_comp_ctx_); - } -} - -void DisplayPrimary::PingPongTimeout() { - lock_guard obj(recursive_mutex_); - hw_intf_->DumpDebugData(); -} - -void DisplayPrimary::ThermalEvent(int64_t thermal_level) { - event_handler_->HandleEvent(kThermalEvent); - lock_guard obj(recursive_mutex_); - comp_manager_->ProcessThermalEvent(display_comp_ctx_, thermal_level); -} - -void DisplayPrimary::IdlePowerCollapse() { - if (hw_panel_info_.mode == kModeCommand) { - event_handler_->HandleEvent(kIdlePowerCollapse); - lock_guard obj(recursive_mutex_); - comp_manager_->ProcessIdlePowerCollapse(display_comp_ctx_); - } -} - -void DisplayPrimary::PanelDead() { - event_handler_->HandleEvent(kPanelDeadEvent); - event_handler_->Refresh(); - { - lock_guard obj(recursive_mutex_); - reset_panel_ = true; - } -} - -DisplayError DisplayPrimary::GetPanelBrightness(int *level) { - lock_guard obj(recursive_mutex_); - return hw_intf_->GetPanelBrightness(level); -} - -DisplayError DisplayPrimary::ControlPartialUpdate(bool enable, uint32_t *pending) { - lock_guard obj(recursive_mutex_); - if (!pending) { - return kErrorParameters; - } - - if (!hw_panel_info_.partial_update) { - // Nothing to be done. - DLOGI("partial update is not applicable for display=%d", display_type_); - return kErrorNotSupported; - } - - *pending = 0; - if (enable == partial_update_control_) { - DLOGI("Same state transition is requested."); - return kErrorNone; - } - - partial_update_control_ = enable; - - if (!enable) { - // If the request is to turn off feature, new draw call is required to have - // the new setting into effect. - *pending = 1; - } - - return kErrorNone; -} - -DisplayError DisplayPrimary::DisablePartialUpdateOneFrame() { - lock_guard obj(recursive_mutex_); - disable_pu_one_frame_ = true; - - return kErrorNone; -} - -bool DisplayPrimary::NeedsAVREnable() { - if (avr_prop_disabled_) { - return false; - } - - return (hw_panel_info_.mode == kModeVideo && ((hw_panel_info_.dynamic_fps && - hw_panel_info_.dfps_porch_mode) || (!hw_panel_info_.dynamic_fps && - hw_panel_info_.min_fps != hw_panel_info_.max_fps))); -} - -void DisplayPrimary::ResetPanel() { - DisplayError status = kErrorNone; - int release_fence = -1; - - DLOGI("Powering off primary"); - status = SetDisplayState(kStateOff, &release_fence); - if (status != kErrorNone) { - DLOGE("power-off on primary failed with error = %d", status); - } - if (release_fence >= 0) { - ::close(release_fence); - } - - DLOGI("Restoring power mode on primary"); - DisplayState mode = GetLastPowerMode(); - status = SetDisplayState(mode, &release_fence); - if (status != kErrorNone) { - DLOGE("Setting power mode = %d on primary failed with error = %d", mode, status); - } - if (release_fence >= 0) { - ::close(release_fence); - } - - DLOGI("Enabling HWVsync"); - status = SetVSyncState(true); - if (status != kErrorNone) { - DLOGE("enabling vsync failed for primary with error = %d", status); - } -} - -} // namespace sdm - diff --git a/sdm/libs/core/display_primary.h b/sdm/libs/core/display_primary.h deleted file mode 100644 index a5a3ae0f..00000000 --- a/sdm/libs/core/display_primary.h +++ /dev/null @@ -1,79 +0,0 @@ -/* -* Copyright (c) 2014 - 2018, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted -* provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright notice, this list of -* conditions and the following disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its contributors may be used to -* endorse or promote products derived from this software without specific prior written -* permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __DISPLAY_PRIMARY_H__ -#define __DISPLAY_PRIMARY_H__ - -#include - -#include "display_base.h" -#include "hw_events_interface.h" - -namespace sdm { - -class HWPrimaryInterface; - -class DisplayPrimary : public DisplayBase, HWEventHandler { - public: - DisplayPrimary(DisplayEventHandler *event_handler, HWInfoInterface *hw_info_intf, - BufferSyncHandler *buffer_sync_handler, BufferAllocator *buffer_allocator, - CompManager *comp_manager); - virtual DisplayError Init(); - virtual DisplayError Prepare(LayerStack *layer_stack); - virtual DisplayError Commit(LayerStack *layer_stack); - virtual DisplayError ControlPartialUpdate(bool enable, uint32_t *pending); - virtual DisplayError DisablePartialUpdateOneFrame(); - virtual DisplayError SetDisplayState(DisplayState state, int *release_fence); - virtual void SetIdleTimeoutMs(uint32_t active_ms); - virtual DisplayError SetDisplayMode(uint32_t mode); - virtual DisplayError GetRefreshRateRange(uint32_t *min_refresh_rate, uint32_t *max_refresh_rate); - virtual DisplayError SetRefreshRate(uint32_t refresh_rate, bool final_rate); - virtual DisplayError SetPanelBrightness(int level); - virtual DisplayError GetPanelBrightness(int *level); - - // Implement the HWEventHandlers - virtual DisplayError VSync(int64_t timestamp); - virtual DisplayError Blank(bool blank) { return kErrorNone; } - virtual void IdleTimeout(); - virtual void ThermalEvent(int64_t thermal_level); - virtual void CECMessage(char *message) { } - virtual void IdlePowerCollapse(); - virtual void PingPongTimeout(); - virtual void PanelDead(); - - private: - bool NeedsAVREnable(); - void ResetPanel(); - - std::vector event_list_; - bool avr_prop_disabled_ = false; - bool switch_to_cmd_ = false; - bool handle_idle_timeout_ = false; - bool reset_panel_ = false; -}; - -} // namespace sdm - -#endif // __DISPLAY_PRIMARY_H__ - diff --git a/sdm/libs/core/display_virtual.cpp b/sdm/libs/core/display_virtual.cpp deleted file mode 100644 index d46c8c0b..00000000 --- a/sdm/libs/core/display_virtual.cpp +++ /dev/null @@ -1,174 +0,0 @@ -/* -* Copyright (c) 2014 - 2018, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted -* provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright notice, this list of -* conditions and the following disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its contributors may be used to -* endorse or promote products derived from this software without specific prior written -* permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include -#include -#include -#include "display_virtual.h" -#include "hw_interface.h" -#include "hw_info_interface.h" - -#define __CLASS__ "DisplayVirtual" - -namespace sdm { - -DisplayVirtual::DisplayVirtual(DisplayEventHandler *event_handler, HWInfoInterface *hw_info_intf, - BufferSyncHandler *buffer_sync_handler, - BufferAllocator *buffer_allocator, CompManager *comp_manager) - : DisplayBase(kVirtual, event_handler, kDeviceVirtual, buffer_sync_handler, buffer_allocator, - comp_manager, hw_info_intf) { -} - -DisplayError DisplayVirtual::Init() { - lock_guard obj(recursive_mutex_); - - DisplayError error = HWInterface::Create(kVirtual, hw_info_intf_, buffer_sync_handler_, - buffer_allocator_, &hw_intf_); - if (error != kErrorNone) { - return error; - } - - HWScaleLutInfo lut_info = {}; - error = comp_manager_->GetScaleLutConfig(&lut_info); - if (error == kErrorNone) { - error = hw_intf_->SetScaleLutConfig(&lut_info); - if (error != kErrorNone) { - HWInterface::Destroy(hw_intf_); - return error; - } - } - - if (hw_info_intf_) { - HWResourceInfo hw_resource_info = HWResourceInfo(); - hw_info_intf_->GetHWResourceInfo(&hw_resource_info); - auto max_mixer_stages = hw_resource_info.num_blending_stages; - int property_value = Debug::GetMaxPipesPerMixer(display_type_); - if (property_value >= 0) { - max_mixer_stages = std::min(UINT32(property_value), hw_resource_info.num_blending_stages); - } - DisplayBase::SetMaxMixerStages(max_mixer_stages); - } - - return error; -} - -DisplayError DisplayVirtual::GetNumVariableInfoConfigs(uint32_t *count) { - lock_guard obj(recursive_mutex_); - *count = 1; - return kErrorNone; -} - -DisplayError DisplayVirtual::GetConfig(uint32_t index, DisplayConfigVariableInfo *variable_info) { - lock_guard obj(recursive_mutex_); - *variable_info = display_attributes_; - return kErrorNone; -} - -DisplayError DisplayVirtual::GetActiveConfig(uint32_t *index) { - lock_guard obj(recursive_mutex_); - *index = 0; - return kErrorNone; -} - -DisplayError DisplayVirtual::SetActiveConfig(DisplayConfigVariableInfo *variable_info) { - lock_guard obj(recursive_mutex_); - - if (!variable_info) { - return kErrorParameters; - } - - DisplayError error = kErrorNone; - HWDisplayAttributes display_attributes; - HWMixerAttributes mixer_attributes; - HWPanelInfo hw_panel_info = {}; - DisplayConfigVariableInfo fb_config = fb_config_; - - display_attributes.x_pixels = variable_info->x_pixels; - display_attributes.y_pixels = variable_info->y_pixels; - display_attributes.fps = variable_info->fps; - - if (display_attributes == display_attributes_) { - return kErrorNone; - } - - error = hw_intf_->SetDisplayAttributes(display_attributes); - if (error != kErrorNone) { - return error; - } - - hw_intf_->GetHWPanelInfo(&hw_panel_info); - - error = hw_intf_->GetMixerAttributes(&mixer_attributes); - if (error != kErrorNone) { - return error; - } - - // fb_config will be updated only once after creation of virtual display - if (fb_config.x_pixels == 0 || fb_config.y_pixels == 0) { - fb_config = display_attributes; - } - - // if display is already connected, unregister display from composition manager and register - // the display with new configuration. - if (display_comp_ctx_) { - comp_manager_->UnregisterDisplay(display_comp_ctx_); - } - - error = comp_manager_->RegisterDisplay(display_type_, display_attributes, hw_panel_info, - mixer_attributes, fb_config, &display_comp_ctx_); - if (error != kErrorNone) { - return error; - } - - display_attributes_ = display_attributes; - mixer_attributes_ = mixer_attributes; - hw_panel_info_ = hw_panel_info; - fb_config_ = fb_config; - - DLOGI("Virtual display resolution changed to[%dx%d]", display_attributes_.x_pixels, - display_attributes_.y_pixels); - - return kErrorNone; -} - -DisplayError DisplayVirtual::Prepare(LayerStack *layer_stack) { - lock_guard obj(recursive_mutex_); - - // Clean hw layers for reuse. - hw_layers_ = HWLayers(); - - return DisplayBase::Prepare(layer_stack); -} - -DisplayError DisplayVirtual::GetColorModeCount(uint32_t *mode_count) { - lock_guard obj(recursive_mutex_); - - // Color Manager isn't supported for virtual displays. - *mode_count = 1; - - return kErrorNone; -} - -} // namespace sdm - diff --git a/sdm/libs/core/display_virtual.h b/sdm/libs/core/display_virtual.h deleted file mode 100644 index ca154c44..00000000 --- a/sdm/libs/core/display_virtual.h +++ /dev/null @@ -1,72 +0,0 @@ -/* -* Copyright (c) 2014 - 2018, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted -* provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright notice, this list of -* conditions and the following disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its contributors may be used to -* endorse or promote products derived from this software without specific prior written -* permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __DISPLAY_VIRTUAL_H__ -#define __DISPLAY_VIRTUAL_H__ - -#include -#include "display_base.h" - -namespace sdm { - -class HWVirtualInterface; - -class DisplayVirtual : public DisplayBase { - public: - DisplayVirtual(DisplayEventHandler *event_handler, HWInfoInterface *hw_info_intf, - BufferSyncHandler *buffer_sync_handler, BufferAllocator *buffer_allocator, - CompManager *comp_manager); - virtual DisplayError Init(); - virtual DisplayError Prepare(LayerStack *layer_stack); - virtual DisplayError GetNumVariableInfoConfigs(uint32_t *count); - virtual DisplayError GetConfig(uint32_t index, DisplayConfigVariableInfo *variable_info); - virtual DisplayError GetActiveConfig(uint32_t *index); - virtual DisplayError SetActiveConfig(uint32_t index) { - return kErrorNotSupported; - } - virtual DisplayError SetActiveConfig(DisplayConfigVariableInfo *variable_info); - virtual DisplayError SetMixerResolution(uint32_t width, uint32_t height) { - return kErrorNotSupported; - } - virtual DisplayError SetVSyncState(bool enable) { - return kErrorNotSupported; - } - virtual DisplayError SetRefreshRate(uint32_t refresh_rate, bool final_rate) { - return kErrorNotSupported; - } - virtual DisplayError SetDetailEnhancerData(const DisplayDetailEnhancerData &de_data) { - return kErrorNotSupported; - } - virtual DisplayError ValidateGPUTargetParams() { - // TODO(user): Validate GPU target for virtual display when query display attributes - // on virtual display is functional. - return kErrorNone; - } - virtual DisplayError GetColorModeCount(uint32_t *mode_count); -}; - -} // namespace sdm - -#endif // __DISPLAY_VIRTUAL_H__ - diff --git a/sdm/libs/core/drm/hw_color_manager_drm.cpp b/sdm/libs/core/drm/hw_color_manager_drm.cpp deleted file mode 100644 index 85e95746..00000000 --- a/sdm/libs/core/drm/hw_color_manager_drm.cpp +++ /dev/null @@ -1,967 +0,0 @@ -/* -* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#define __CLASS__ "HWColorManagerDRM" - -#ifdef PP_DRM_ENABLE -#include -#endif -#include -#include "hw_color_manager_drm.h" - -#ifdef PP_DRM_ENABLE -static const uint32_t kPgcDataMask = 0x3FF; -static const uint32_t kPgcShift = 16; - -static const uint32_t kIgcDataMask = 0xFFF; -static const uint32_t kIgcShift = 16; - -#ifdef DRM_MSM_PA_HSIC -static const uint32_t kPAHueMask = (1 << 12); -static const uint32_t kPASatMask = (1 << 13); -static const uint32_t kPAValMask = (1 << 14); -static const uint32_t kPAContrastMask = (1 << 15); -#endif - -#ifdef DRM_MSM_SIXZONE -static const uint32_t kSixZoneP0Mask = 0x0FFF; -static const uint32_t kSixZoneP1Mask = 0x0FFF0FFF; -static const uint32_t kSixZoneHueMask = (1 << 16); -static const uint32_t kSixZoneSatMask = (1 << 17); -static const uint32_t kSixZoneValMask = (1 << 18); -#endif - -#ifdef DRM_MSM_MEMCOL -static const uint32_t kMemColorProtHueMask = (1 << 0); -static const uint32_t kMemColorProtSatMask = (1 << 1); -static const uint32_t kMemColorProtValMask = (1 << 2); -static const uint32_t kMemColorProtContMask = (1 << 3); -static const uint32_t kMemColorProtSixZoneMask = (1 << 4); -static const uint32_t kMemColorProtBlendMask = (1 << 5); - -static const uint32_t kMemColorProtMask = \ - (kMemColorProtHueMask | kMemColorProtSatMask | kMemColorProtValMask | \ - kMemColorProtContMask | kMemColorProtSixZoneMask | kMemColorProtBlendMask); - -static const uint32_t kMemColorSkinMask = (1 << 19); -static const uint32_t kMemColorSkyMask = (1 << 20); -static const uint32_t kMemColorFolMask = (1 << 21); -#endif -#endif - -namespace sdm { - -DisplayError (*HWColorManagerDrm::GetDrmFeature[])(const PPFeatureInfo &, DRMPPFeatureInfo *) = { - [kFeaturePcc] = &HWColorManagerDrm::GetDrmPCC, - [kFeatureIgc] = &HWColorManagerDrm::GetDrmIGC, - [kFeaturePgc] = &HWColorManagerDrm::GetDrmPGC, - [kFeatureMixerGc] = &HWColorManagerDrm::GetDrmMixerGC, - [kFeaturePaV2] = NULL, - [kFeatureDither] = &HWColorManagerDrm::GetDrmDither, - [kFeatureGamut] = &HWColorManagerDrm::GetDrmGamut, - [kFeaturePADither] = &HWColorManagerDrm::GetDrmPADither, - [kFeaturePAHsic] = &HWColorManagerDrm::GetDrmPAHsic, - [kFeaturePASixZone] = &HWColorManagerDrm::GetDrmPASixZone, - [kFeaturePAMemColSkin] = &HWColorManagerDrm::GetDrmPAMemColSkin, - [kFeaturePAMemColSky] = &HWColorManagerDrm::GetDrmPAMemColSky, - [kFeaturePAMemColFoliage] = &HWColorManagerDrm::GetDrmPAMemColFoliage, - [kFeaturePAMemColProt] = &HWColorManagerDrm::GetDrmPAMemColProt, -}; - -void HWColorManagerDrm::FreeDrmFeatureData(DRMPPFeatureInfo *feature) { - if (feature->payload) - free(feature->payload); - feature->payload = NULL; -} - -uint32_t HWColorManagerDrm::GetFeatureVersion(const DRMPPFeatureInfo &feature) { - uint32_t version = PPFeatureVersion::kSDEPpVersionInvalid; - - switch (feature.id) { - case kFeaturePcc: - if (feature.version == 1) { - version = PPFeatureVersion::kSDEPccV17; - } else if (feature.version == 4) { - version = PPFeatureVersion::kSDEPccV4; - } - break; - case kFeatureIgc: - if (feature.version == 3) - version = PPFeatureVersion::kSDEIgcV30; - break; - case kFeaturePgc: - if (feature.version == 1) - version = PPFeatureVersion::kSDEPgcV17; - break; - case kFeatureMixerGc: - version = PPFeatureVersion::kSDEPgcV17; - break; - case kFeaturePAHsic: - case kFeaturePASixZone: - case kFeaturePAMemColSkin: - case kFeaturePAMemColSky: - case kFeaturePAMemColFoliage: - case kFeaturePAMemColProt: - if (feature.version == 1) - version = PPFeatureVersion::kSDEPaV17; - break; - case kFeatureDither: - version = PPFeatureVersion::kSDEDitherV17; - break; - case kFeatureGamut: - if (feature.version == 1) - version = PPFeatureVersion::kSDEGamutV17; - else if (feature.version == 4) - version = PPFeatureVersion::kSDEGamutV4; - break; - case kFeaturePADither: - version = PPFeatureVersion::kSDEPADitherV17; - break; - default: - break; - } - return version; -} - -DRMPPFeatureID HWColorManagerDrm::ToDrmFeatureId(uint32_t id) { - DRMPPFeatureID ret = kPPFeaturesMax; - - switch (id) { - case kGlobalColorFeaturePcc: - ret = kFeaturePcc; - break; - case kGlobalColorFeatureIgc: - ret = kFeatureIgc; - break; - case kGlobalColorFeaturePgc: - ret = kFeaturePgc; - break; - case kMixerColorFeatureGc: - ret = kFeatureMixerGc; - break; - case kGlobalColorFeaturePaV2: - ret = kFeaturePAHsic; - break; - case kGlobalColorFeatureDither: - ret = kFeatureDither; - break; - case kGlobalColorFeatureGamut: - ret = kFeatureGamut; - break; - case kGlobalColorFeaturePADither: - ret = kFeaturePADither; - break; - default: - break; - } - return ret; -} - -DisplayError HWColorManagerDrm::GetDrmPCC(const PPFeatureInfo &in_data, - DRMPPFeatureInfo *out_data) { - DisplayError ret = kErrorNone; -#ifdef PP_DRM_ENABLE - struct SDEPccV4Cfg *sde_pcc = NULL; - struct SDEPccV4Coeff *sde_pcc_coeffs = NULL; - struct drm_msm_pcc *mdp_pcc = NULL; - struct drm_msm_pcc_coeff *mdp_pcc_coeffs = NULL; - uint32_t i = 0; - - if (!out_data) { - DLOGE("Invalid input parameter for pcc"); - return kErrorParameters; - } - - switch (in_data.feature_version_) { - case PPFeatureVersion::kSDEPccV4: - sde_pcc = (struct SDEPccV4Cfg *) in_data.GetConfigData(); - break; - default: - DLOGE("Unsupported pcc feature version: %d", in_data.feature_version_); - return kErrorParameters; - } - - out_data->id = kFeaturePcc; - out_data->type = sde_drm::kPropBlob; - out_data->version = in_data.feature_version_; - out_data->payload_size = sizeof(struct drm_msm_pcc); - - if (in_data.enable_flags_ & kOpsDisable) { - /* feature disable case */ - out_data->payload = NULL; - return ret; - } else if (!(in_data.enable_flags_ & kOpsEnable)) { - out_data->payload = NULL; - return kErrorParameters; - } - - mdp_pcc = new drm_msm_pcc(); - if (!mdp_pcc) { - DLOGE("Failed to allocate memory for pcc"); - return kErrorMemory; - } - - mdp_pcc->flags = 0; - - for (i = 0; i < kMaxPCCChanel; i++) { - switch (i) { - case 0: - sde_pcc_coeffs = &sde_pcc->red; - mdp_pcc_coeffs = &mdp_pcc->r; - mdp_pcc->r_rr = sde_pcc_coeffs->rr; - mdp_pcc->r_gg = sde_pcc_coeffs->gg; - mdp_pcc->r_bb = sde_pcc_coeffs->bb; - break; - case 1: - sde_pcc_coeffs = &sde_pcc->green; - mdp_pcc_coeffs = &mdp_pcc->g; - mdp_pcc->g_rr = sde_pcc_coeffs->rr; - mdp_pcc->g_gg = sde_pcc_coeffs->gg; - mdp_pcc->g_bb = sde_pcc_coeffs->bb; - break; - case 2: - sde_pcc_coeffs = &sde_pcc->blue; - mdp_pcc_coeffs = &mdp_pcc->b; - mdp_pcc->b_rr = sde_pcc_coeffs->rr; - mdp_pcc->b_gg = sde_pcc_coeffs->gg; - mdp_pcc->b_bb = sde_pcc_coeffs->bb; - break; - } - mdp_pcc_coeffs->c = sde_pcc_coeffs->c; - mdp_pcc_coeffs->r = sde_pcc_coeffs->r; - mdp_pcc_coeffs->g = sde_pcc_coeffs->g; - mdp_pcc_coeffs->b = sde_pcc_coeffs->b; - mdp_pcc_coeffs->rg = sde_pcc_coeffs->rg; - mdp_pcc_coeffs->gb = sde_pcc_coeffs->gb; - mdp_pcc_coeffs->rb = sde_pcc_coeffs->rb; - mdp_pcc_coeffs->rgb = sde_pcc_coeffs->rgb; - } - out_data->payload = mdp_pcc; -#endif - return ret; -} - -DisplayError HWColorManagerDrm::GetDrmIGC(const PPFeatureInfo &in_data, - DRMPPFeatureInfo *out_data) { - DisplayError ret = kErrorNone; -#ifdef PP_DRM_ENABLE - struct SDEIgcV30LUTData *sde_igc; - struct drm_msm_igc_lut *mdp_igc; - uint32_t *c0_c1_data_ptr = NULL; - uint32_t *c2_data_ptr = NULL; - - - if (!out_data) { - DLOGE("Invalid input parameter for igc"); - return kErrorParameters; - } - - switch (in_data.feature_version_) { - case PPFeatureVersion::kSDEIgcV30: - sde_igc = (struct SDEIgcV30LUTData *) in_data.GetConfigData(); - break; - default: - DLOGE("Unsupported igc feature version: %d", in_data.feature_version_); - return kErrorParameters; - } - - out_data->id = kFeatureIgc; - out_data->type = sde_drm::kPropBlob; - out_data->version = in_data.feature_version_; - out_data->payload_size = sizeof(struct drm_msm_igc_lut); - - if (in_data.enable_flags_ & kOpsDisable) { - /* feature disable case */ - out_data->payload = NULL; - return ret; - } else if (!(in_data.enable_flags_ & kOpsEnable)) { - out_data->payload = NULL; - return kErrorParameters; - } - - mdp_igc = new drm_msm_igc_lut(); - if (!mdp_igc) { - DLOGE("Failed to allocate memory for igc"); - return kErrorMemory; - } - - mdp_igc->flags = IGC_DITHER_ENABLE; - mdp_igc->strength = sde_igc->strength; - - c0_c1_data_ptr = reinterpret_cast(sde_igc->c0_c1_data); - c2_data_ptr = reinterpret_cast(sde_igc->c2_data); - - if (!c0_c1_data_ptr || !c2_data_ptr) { - DLOGE("Invaid igc data pointer"); - delete mdp_igc; - out_data->payload = NULL; - return kErrorParameters; - } - - for (int i = 0; i < IGC_TBL_LEN; i++) { - mdp_igc->c0[i] = c0_c1_data_ptr[i] & kIgcDataMask; - mdp_igc->c1[i] = (c0_c1_data_ptr[i] >> kIgcShift) & kIgcDataMask; - mdp_igc->c2[i] = c2_data_ptr[i] & kIgcDataMask; - } - out_data->payload = mdp_igc; -#endif - return ret; -} - -DisplayError HWColorManagerDrm::GetDrmPGC(const PPFeatureInfo &in_data, - DRMPPFeatureInfo *out_data) { - DisplayError ret = kErrorNone; -#ifdef PP_DRM_ENABLE - struct SDEPgcLUTData *sde_pgc; - struct drm_msm_pgc_lut *mdp_pgc; - - if (!out_data) { - DLOGE("Invalid input parameter for gamut"); - return kErrorParameters; - } - sde_pgc = (struct SDEPgcLUTData *)in_data.GetConfigData(); - out_data->id = kFeaturePgc; - out_data->type = sde_drm::kPropBlob; - out_data->version = in_data.feature_version_; - out_data->payload_size = sizeof(struct drm_msm_pgc_lut); - - if (in_data.enable_flags_ & kOpsDisable) { - /* feature disable case */ - out_data->payload = NULL; - return ret; - } else if (!(in_data.enable_flags_ & kOpsEnable)) { - out_data->payload = NULL; - return kErrorParameters; - } - - mdp_pgc = new drm_msm_pgc_lut(); - if (!mdp_pgc) { - DLOGE("Failed to allocate memory for pgc"); - return kErrorMemory; - } - - if (in_data.enable_flags_ & kOpsEnable) - mdp_pgc->flags = PGC_8B_ROUND; - else - mdp_pgc->flags = 0; - - for (int i = 0, j = 0; i < PGC_TBL_LEN; i++, j += 2) { - mdp_pgc->c0[i] = (sde_pgc->c0_data[j] & kPgcDataMask) | - (sde_pgc->c0_data[j + 1] & kPgcDataMask) << kPgcShift; - mdp_pgc->c1[i] = (sde_pgc->c1_data[j] & kPgcDataMask) | - (sde_pgc->c1_data[j + 1] & kPgcDataMask) << kPgcShift; - mdp_pgc->c2[i] = (sde_pgc->c2_data[j] & kPgcDataMask) | - (sde_pgc->c2_data[j + 1] & kPgcDataMask) << kPgcShift; - } - out_data->payload = mdp_pgc; -#endif - return ret; -} - -DisplayError HWColorManagerDrm::GetDrmMixerGC(const PPFeatureInfo &in_data, - DRMPPFeatureInfo *out_data) { - DisplayError ret = kErrorNone; -#ifdef PP_DRM_ENABLE - if (!out_data) { - DLOGE("Invalid input parameter for Mixer GC"); - return kErrorParameters; - } - - out_data->id = kPPFeaturesMax; - out_data->type = sde_drm::kPropBlob; - out_data->version = in_data.feature_version_; -#endif - return ret; -} - -DisplayError HWColorManagerDrm::GetDrmPAHsic(const PPFeatureInfo &in_data, - DRMPPFeatureInfo *out_data) { - DisplayError ret = kErrorNone; -#if defined(PP_DRM_ENABLE) && defined(DRM_MSM_PA_HSIC) - struct SDEPaData *sde_pa; - struct drm_msm_pa_hsic *mdp_hsic; - - if (!out_data) { - DLOGE("Invalid input parameter for pa hsic"); - return kErrorParameters; - } - - sde_pa = (struct SDEPaData *) in_data.GetConfigData(); - - out_data->id = kFeaturePAHsic; - out_data->type = sde_drm::kPropBlob; - out_data->version = in_data.feature_version_; - out_data->payload_size = 0; - out_data->payload = NULL; - - if (in_data.enable_flags_ & kOpsDisable) { - /* Complete PA features disable case */ - return ret; - } else if (!(in_data.enable_flags_ & kOpsEnable)) { - DLOGE("Invalid ops for pa hsic"); - return kErrorParameters; - } - - if (!(sde_pa->mode & (kPAHueMask | kPASatMask | - kPAValMask | kPAContrastMask))) { - /* PA HSIC feature disable case, but other PA features active */ - return ret; - } - - mdp_hsic = new drm_msm_pa_hsic(); - if (!mdp_hsic) { - DLOGE("Failed to allocate memory for pa hsic"); - return kErrorMemory; - } - - mdp_hsic->flags = 0; - - if (in_data.enable_flags_ & kPaHueEnable) { - mdp_hsic->flags |= PA_HSIC_HUE_ENABLE; - mdp_hsic->hue = sde_pa->hue_adj; - } - if (in_data.enable_flags_ & kPaSatEnable) { - mdp_hsic->flags |= PA_HSIC_SAT_ENABLE; - mdp_hsic->saturation = sde_pa->sat_adj; - } - if (in_data.enable_flags_ & kPaValEnable) { - mdp_hsic->flags |= PA_HSIC_VAL_ENABLE; - mdp_hsic->value = sde_pa->val_adj; - } - if (in_data.enable_flags_ & kPaContEnable) { - mdp_hsic->flags |= PA_HSIC_CONT_ENABLE; - mdp_hsic->contrast = sde_pa->cont_adj; - } - - if (mdp_hsic->flags) { - out_data->payload = mdp_hsic; - out_data->payload_size = sizeof(struct drm_msm_pa_hsic); - } else { - /* PA HSIC configuration unchanged, no better return code available */ - delete mdp_hsic; - ret = kErrorPermission; - } -#endif - return ret; -} - -DisplayError HWColorManagerDrm::GetDrmPASixZone(const PPFeatureInfo &in_data, - DRMPPFeatureInfo *out_data) { - DisplayError ret = kErrorNone; -#if defined(PP_DRM_ENABLE) && defined(DRM_MSM_SIXZONE) - struct SDEPaData *sde_pa; - - if (!out_data) { - DLOGE("Invalid input parameter for six zone"); - return kErrorParameters; - } - - sde_pa = (struct SDEPaData *) in_data.GetConfigData(); - - out_data->id = kFeaturePASixZone; - out_data->type = sde_drm::kPropBlob; - out_data->version = in_data.feature_version_; - out_data->payload_size = 0; - out_data->payload = NULL; - - if (in_data.enable_flags_ & kOpsDisable) { - /* Complete PA features disable case */ - return ret; - } else if (!(in_data.enable_flags_ & kOpsEnable)) { - DLOGE("Invalid ops for six zone"); - return kErrorParameters; - } - - if (!(sde_pa->mode & (kSixZoneHueMask | kSixZoneSatMask | - kSixZoneValMask))) { - /* PA SixZone feature disable case, but other PA features active */ - return ret; - } - - if (in_data.enable_flags_ & kPaSixZoneEnable) { - struct drm_msm_sixzone *mdp_sixzone = NULL; - - if ((!sde_pa->six_zone_curve_p0 || !sde_pa->six_zone_curve_p1) || - (sde_pa->six_zone_len != SIXZONE_LUT_SIZE)) { - DLOGE("Invaid sixzone curve"); - return kErrorParameters; - } - - mdp_sixzone = new drm_msm_sixzone(); - if (!mdp_sixzone) { - DLOGE("Failed to allocate memory for six zone"); - return kErrorMemory; - } - - mdp_sixzone->flags = 0; - - if (sde_pa->mode & kSixZoneHueMask) { - mdp_sixzone->flags |= SIXZONE_HUE_ENABLE; - } - if (sde_pa->mode & kSixZoneSatMask) { - mdp_sixzone->flags |= SIXZONE_SAT_ENABLE; - } - if (sde_pa->mode & kSixZoneValMask) { - mdp_sixzone->flags |= SIXZONE_VAL_ENABLE; - } - - mdp_sixzone->threshold = sde_pa->six_zone_thresh; - mdp_sixzone->adjust_p0 = sde_pa->six_zone_adj_p0; - mdp_sixzone->adjust_p1 = sde_pa->six_zone_adj_p1; - mdp_sixzone->sat_hold = sde_pa->six_zone_sat_hold; - mdp_sixzone->val_hold = sde_pa->six_zone_val_hold; - - for (int i = 0; i < SIXZONE_LUT_SIZE; i++) { - mdp_sixzone->curve[i].p0 = sde_pa->six_zone_curve_p0[i] & kSixZoneP0Mask; - mdp_sixzone->curve[i].p1 = sde_pa->six_zone_curve_p1[i] & kSixZoneP1Mask; - } - out_data->payload = mdp_sixzone; - out_data->payload_size = sizeof(struct drm_msm_sixzone); - } else { - /* PA SixZone configuration unchanged, no better return code available */ - ret = kErrorPermission; - } - -#endif - return ret; -} - -DisplayError HWColorManagerDrm::GetDrmPAMemColSkin(const PPFeatureInfo &in_data, - DRMPPFeatureInfo *out_data) { - DisplayError ret = kErrorNone; -#if defined(PP_DRM_ENABLE) && defined(DRM_MSM_MEMCOL) - struct SDEPaData *sde_pa; - - if (!out_data) { - DLOGE("Invalid input parameter for memory color skin"); - return kErrorParameters; - } - - sde_pa = (struct SDEPaData *) in_data.GetConfigData(); - - out_data->id = kFeaturePAMemColSkin; - out_data->type = sde_drm::kPropBlob; - out_data->version = in_data.feature_version_; - out_data->payload_size = 0; - out_data->payload = NULL; - - if (in_data.enable_flags_ & kOpsDisable) { - /* Complete PA features disable case */ - return ret; - } else if (!(in_data.enable_flags_ & kOpsEnable)) { - DLOGE("Invalid ops for memory color skin"); - return kErrorParameters; - } - - if (!(sde_pa->mode & kMemColorSkinMask)) { - /* PA MemColSkin feature disable case, but other PA features active */ - return ret; - } - - if (in_data.enable_flags_ & kPaSkinEnable) { - struct drm_msm_memcol *mdp_memcol = NULL; - struct SDEPaMemColorData *pa_memcol = &sde_pa->skin; - - mdp_memcol = new drm_msm_memcol(); - if (!mdp_memcol) { - DLOGE("Failed to allocate memory for memory color skin"); - return kErrorMemory; - } - - mdp_memcol->prot_flags = 0; - mdp_memcol->color_adjust_p0 = pa_memcol->adjust_p0; - mdp_memcol->color_adjust_p1 = pa_memcol->adjust_p1; - mdp_memcol->color_adjust_p2 = pa_memcol->adjust_p2; - mdp_memcol->blend_gain = pa_memcol->blend_gain; - mdp_memcol->sat_hold = pa_memcol->sat_hold; - mdp_memcol->val_hold = pa_memcol->val_hold; - mdp_memcol->hue_region = pa_memcol->hue_region; - mdp_memcol->sat_region = pa_memcol->sat_region; - mdp_memcol->val_region = pa_memcol->val_region; - - out_data->payload = mdp_memcol; - out_data->payload_size = sizeof(struct drm_msm_memcol); - } else { - /* PA MemColSkin configuration unchanged, no better return code available */ - ret = kErrorPermission; - } -#endif - return ret; -} - -DisplayError HWColorManagerDrm::GetDrmPAMemColSky(const PPFeatureInfo &in_data, - DRMPPFeatureInfo *out_data) { - DisplayError ret = kErrorNone; -#if defined(PP_DRM_ENABLE) && defined(DRM_MSM_MEMCOL) - struct SDEPaData *sde_pa; - - if (!out_data) { - DLOGE("Invalid input parameter for memory color sky"); - return kErrorParameters; - } - - sde_pa = (struct SDEPaData *) in_data.GetConfigData(); - - out_data->id = kFeaturePAMemColSky; - out_data->type = sde_drm::kPropBlob; - out_data->version = in_data.feature_version_; - out_data->payload_size = 0; - out_data->payload = NULL; - - if (in_data.enable_flags_ & kOpsDisable) { - /* Complete PA features disable case */ - return ret; - } else if (!(in_data.enable_flags_ & kOpsEnable)) { - DLOGE("Invalid ops for memory color sky"); - return kErrorParameters; - } - - if (!(sde_pa->mode & kMemColorSkyMask)) { - /* PA MemColSky feature disable case, but other PA features active */ - return ret; - } - - if (in_data.enable_flags_ & kPaSkyEnable) { - struct drm_msm_memcol *mdp_memcol = NULL; - struct SDEPaMemColorData *pa_memcol = &sde_pa->sky; - - mdp_memcol = new drm_msm_memcol(); - if (!mdp_memcol) { - DLOGE("Failed to allocate memory for memory color sky"); - return kErrorMemory; - } - - mdp_memcol->prot_flags = 0; - mdp_memcol->color_adjust_p0 = pa_memcol->adjust_p0; - mdp_memcol->color_adjust_p1 = pa_memcol->adjust_p1; - mdp_memcol->color_adjust_p2 = pa_memcol->adjust_p2; - mdp_memcol->blend_gain = pa_memcol->blend_gain; - mdp_memcol->sat_hold = pa_memcol->sat_hold; - mdp_memcol->val_hold = pa_memcol->val_hold; - mdp_memcol->hue_region = pa_memcol->hue_region; - mdp_memcol->sat_region = pa_memcol->sat_region; - mdp_memcol->val_region = pa_memcol->val_region; - - out_data->payload = mdp_memcol; - out_data->payload_size = sizeof(struct drm_msm_memcol); - } else { - /* PA MemColSky configuration unchanged, no better return code available */ - ret = kErrorPermission; - } -#endif - return ret; -} - -DisplayError HWColorManagerDrm::GetDrmPAMemColFoliage(const PPFeatureInfo &in_data, - DRMPPFeatureInfo *out_data) { - DisplayError ret = kErrorNone; -#if defined(PP_DRM_ENABLE) && defined(DRM_MSM_MEMCOL) - struct SDEPaData *sde_pa; - - if (!out_data) { - DLOGE("Invalid input parameter for memory color foliage"); - return kErrorParameters; - } - - sde_pa = (struct SDEPaData *) in_data.GetConfigData(); - - out_data->id = kFeaturePAMemColFoliage; - out_data->type = sde_drm::kPropBlob; - out_data->version = in_data.feature_version_; - out_data->payload_size = 0; - out_data->payload = NULL; - - if (in_data.enable_flags_ & kOpsDisable) { - /* Complete PA features disable case */ - return ret; - } else if (!(in_data.enable_flags_ & kOpsEnable)) { - DLOGE("Invalid ops for memory color foliage"); - return kErrorParameters; - } - - if (!(sde_pa->mode & kMemColorFolMask)) { - /* PA MemColFoliage feature disable case, but other PA features active */ - return ret; - } - - if (in_data.enable_flags_ & kPaFoliageEnable) { - struct drm_msm_memcol *mdp_memcol = NULL; - struct SDEPaMemColorData *pa_memcol = &sde_pa->foliage; - - mdp_memcol = new drm_msm_memcol(); - if (!mdp_memcol) { - DLOGE("Failed to allocate memory for memory color foliage"); - return kErrorMemory; - } - - mdp_memcol->prot_flags = 0; - mdp_memcol->color_adjust_p0 = pa_memcol->adjust_p0; - mdp_memcol->color_adjust_p1 = pa_memcol->adjust_p1; - mdp_memcol->color_adjust_p2 = pa_memcol->adjust_p2; - mdp_memcol->blend_gain = pa_memcol->blend_gain; - mdp_memcol->sat_hold = pa_memcol->sat_hold; - mdp_memcol->val_hold = pa_memcol->val_hold; - mdp_memcol->hue_region = pa_memcol->hue_region; - mdp_memcol->sat_region = pa_memcol->sat_region; - mdp_memcol->val_region = pa_memcol->val_region; - - out_data->payload = mdp_memcol; - out_data->payload_size = sizeof(struct drm_msm_memcol); - } else { - /* PA MemColFoliage configuration unchanged, no better return code available */ - ret = kErrorPermission; - } -#endif - return ret; -} - -DisplayError HWColorManagerDrm::GetDrmPAMemColProt(const PPFeatureInfo &in_data, - DRMPPFeatureInfo *out_data) { - DisplayError ret = kErrorNone; -#if defined(PP_DRM_ENABLE) && defined(DRM_MSM_MEMCOL) - struct SDEPaData *sde_pa; - struct drm_msm_memcol *mdp_memcol; - - if (!out_data) { - DLOGE("Invalid input parameter for memory color prot"); - return kErrorParameters; - } - - sde_pa = (struct SDEPaData *) in_data.GetConfigData(); - - out_data->id = kFeaturePAMemColProt; - out_data->type = sde_drm::kPropBlob; - out_data->version = in_data.feature_version_; - out_data->payload_size = sizeof(struct drm_msm_memcol); - - if (in_data.enable_flags_ & kOpsDisable) { - /* Complete PA features disable case */ - out_data->payload = NULL; - return ret; - } else if (!(in_data.enable_flags_ & kOpsEnable)) { - out_data->payload = NULL; - return kErrorParameters; - } - - out_data->payload = NULL; - if (!(sde_pa->mode & kMemColorProtMask)) { - /* PA MemColProt feature disable case, but other PA features active */ - return ret; - } - - mdp_memcol = new drm_msm_memcol(); - if (!mdp_memcol) { - DLOGE("Failed to allocate memory for memory color prot"); - return kErrorMemory; - } - - mdp_memcol->prot_flags = 0; - - if (sde_pa->mode & kMemColorProtMask) { - mdp_memcol->prot_flags |= (sde_pa->mode & kMemColorProtMask); - } - - out_data->payload = mdp_memcol; - -#endif - return ret; -} - -DisplayError HWColorManagerDrm::GetDrmDither(const PPFeatureInfo &in_data, - DRMPPFeatureInfo *out_data) { - DisplayError ret = kErrorNone; -#ifdef PP_DRM_ENABLE - struct SDEDitherCfg *sde_dither = NULL; - struct drm_msm_dither *mdp_dither = NULL; - - if (!out_data) { - DLOGE("Invalid input parameter for dither"); - return kErrorParameters; - } - - sde_dither = (struct SDEDitherCfg *)in_data.GetConfigData(); - out_data->id = kFeatureDither; - out_data->type = sde_drm::kPropBlob; - out_data->version = in_data.feature_version_; - out_data->payload_size = sizeof(struct drm_msm_dither); - - if (in_data.enable_flags_ & kOpsDisable) { - out_data->payload = NULL; - return ret; - } else if (!(in_data.enable_flags_ & kOpsEnable)) { - out_data->payload = NULL; - return kErrorParameters; - } - - mdp_dither = new drm_msm_dither(); - if (!mdp_dither) { - DLOGE("Failed to allocate memory for dither"); - return kErrorMemory; - } - - mdp_dither->flags = 0; - std::memcpy(mdp_dither->matrix, sde_dither->dither_matrix, - sizeof(sde_dither->dither_matrix)); - mdp_dither->temporal_en = sde_dither->temporal_en; - mdp_dither->c0_bitdepth = sde_dither->g_y_depth; - mdp_dither->c1_bitdepth = sde_dither->b_cb_depth; - mdp_dither->c2_bitdepth = sde_dither->r_cr_depth; - mdp_dither->c3_bitdepth = 0; - out_data->payload = mdp_dither; -#endif - return ret; -} - -DisplayError HWColorManagerDrm::GetDrmGamut(const PPFeatureInfo &in_data, - DRMPPFeatureInfo *out_data) { - DisplayError ret = kErrorNone; -#ifdef PP_DRM_ENABLE - struct SDEGamutCfg *sde_gamut = NULL; - struct drm_msm_3d_gamut *mdp_gamut = NULL; - uint32_t size = 0; - - if (!out_data) { - DLOGE("Invalid input parameter for gamut"); - return kErrorParameters; - } - sde_gamut = (struct SDEGamutCfg *)in_data.GetConfigData(); - out_data->id = kFeatureGamut; - out_data->type = sde_drm::kPropBlob; - out_data->version = in_data.feature_version_; - out_data->payload_size = sizeof(struct drm_msm_3d_gamut); - if (in_data.enable_flags_ & kOpsDisable) { - /* feature disable case */ - out_data->payload = NULL; - return ret; - } else if (!(in_data.enable_flags_ & kOpsEnable)) { - out_data->payload = NULL; - return kErrorParameters; - } - - mdp_gamut = new drm_msm_3d_gamut(); - if (!mdp_gamut) { - DLOGE("Failed to allocate memory for gamut"); - return kErrorMemory; - } - - if (sde_gamut->map_en) - mdp_gamut->flags = GAMUT_3D_MAP_EN; - else - mdp_gamut->flags = 0; - - switch (sde_gamut->mode) { - case SDEGamutCfgWrapper::GAMUT_FINE_MODE: - mdp_gamut->mode = GAMUT_3D_MODE_17; - size = GAMUT_3D_MODE17_TBL_SZ; - break; - case SDEGamutCfgWrapper::GAMUT_COARSE_MODE: - mdp_gamut->mode = GAMUT_3D_MODE_5; - size = GAMUT_3D_MODE5_TBL_SZ; - break; - case SDEGamutCfgWrapper::GAMUT_COARSE_MODE_13: - mdp_gamut->mode = GAMUT_3D_MODE_13; - size = GAMUT_3D_MODE13_TBL_SZ; - break; - default: - DLOGE("Invalid gamut mode %d", sde_gamut->mode); - delete mdp_gamut; - return kErrorParameters; - } - - if (sde_gamut->map_en) { - std::memcpy(&mdp_gamut->scale_off[0][0], sde_gamut->scale_off_data[0], - sizeof(uint32_t) * GAMUT_3D_SCALE_OFF_SZ); - std::memcpy(&mdp_gamut->scale_off[1][0], sde_gamut->scale_off_data[1], - sizeof(uint32_t) * GAMUT_3D_SCALE_OFF_SZ); - std::memcpy(&mdp_gamut->scale_off[2][0], sde_gamut->scale_off_data[2], - sizeof(uint32_t) * GAMUT_3D_SCALE_OFF_SZ); - } - - for (uint32_t row = 0; row < GAMUT_3D_TBL_NUM; row++) { - for (uint32_t col = 0; col < size; col++) { - mdp_gamut->col[row][col].c0 = sde_gamut->c0_data[row][col]; - mdp_gamut->col[row][col].c2_c1 = sde_gamut->c1_c2_data[row][col]; - } - } - out_data->payload = mdp_gamut; -#endif - return ret; -} - -DisplayError HWColorManagerDrm::GetDrmPADither(const PPFeatureInfo &in_data, - DRMPPFeatureInfo *out_data) { - DisplayError ret = kErrorNone; -#if defined(PP_DRM_ENABLE) && defined(DRM_MSM_PA_DITHER) - struct SDEPADitherData* sde_dither; - struct drm_msm_pa_dither* mdp_dither; - - if (!out_data) { - DLOGE("Invalid input parameter for PA dither"); - return kErrorParameters; - } - - out_data->id = kFeaturePADither; - out_data->type = sde_drm::kPropBlob; - out_data->version = in_data.feature_version_; - - out_data->payload_size = sizeof(struct drm_msm_pa_dither); - if (in_data.enable_flags_ & kOpsDisable) { - /* feature disable case */ - out_data->payload = NULL; - return ret; - } else if (!(in_data.enable_flags_ & kOpsEnable)) { - out_data->payload = NULL; - return kErrorParameters; - } - - sde_dither = (struct SDEPADitherData *)in_data.GetConfigData(); - if (sde_dither->matrix_size != DITHER_MATRIX_SZ) { - DLOGE("Invalid dither matrix size %d, exp sz %d", - sde_dither->matrix_size, DITHER_MATRIX_SZ); - return kErrorParameters; - } - - mdp_dither = new drm_msm_pa_dither(); - if (!mdp_dither) { - DLOGE("Failed to allocate memory for dither"); - return kErrorMemory; - } - - mdp_dither->flags = 0; - mdp_dither->strength = sde_dither->strength; - mdp_dither->offset_en = sde_dither->offset_en; - std::memcpy(&mdp_dither->matrix[0], - reinterpret_cast(sde_dither->matrix_data_addr), - sizeof(uint32_t) * DITHER_MATRIX_SZ); - out_data->payload = mdp_dither; -#endif - return ret; -} - -} // namespace sdm diff --git a/sdm/libs/core/drm/hw_color_manager_drm.h b/sdm/libs/core/drm/hw_color_manager_drm.h deleted file mode 100644 index 1e77f6cd..00000000 --- a/sdm/libs/core/drm/hw_color_manager_drm.h +++ /dev/null @@ -1,106 +0,0 @@ -/* -* Copyright (c) 2017, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __HW_COLOR_MANAGER_DRM_H__ -#define __HW_COLOR_MANAGER_DRM_H__ - -#include -#include -#include -#include - -using sde_drm::DRMPPFeatureID; -using sde_drm::DRMPPFeatureInfo; - -using sde_drm::kFeaturePcc; -using sde_drm::kFeatureIgc; -using sde_drm::kFeaturePgc; -using sde_drm::kFeatureMixerGc; -using sde_drm::kFeaturePaV2; -using sde_drm::kFeatureDither; -using sde_drm::kFeatureGamut; -using sde_drm::kFeaturePADither; -using sde_drm::kFeaturePAHsic; -using sde_drm::kFeaturePASixZone; -using sde_drm::kFeaturePAMemColSkin; -using sde_drm::kFeaturePAMemColSky; -using sde_drm::kFeaturePAMemColFoliage; -using sde_drm::kFeaturePAMemColProt; -using sde_drm::kPPFeaturesMax; - -namespace sdm { - -typedef std::map> DrmPPFeatureMap; - -static const DrmPPFeatureMap DrmPPfeatureMap_ = \ - {{kGlobalColorFeaturePcc, {kFeaturePcc}}, - {kGlobalColorFeatureIgc, {kFeatureIgc}}, - {kGlobalColorFeaturePgc, {kFeaturePgc}}, - {kMixerColorFeatureGc, {kMixerColorFeatureGc}}, - {kGlobalColorFeaturePaV2, {kFeaturePAHsic, kFeaturePASixZone, - kFeaturePAMemColSkin, kFeaturePAMemColSky, - kFeaturePAMemColFoliage, kFeaturePAMemColProt}}, - {kGlobalColorFeatureDither, {kFeatureDither}}, - {kGlobalColorFeatureGamut, {kFeatureGamut}}, - {kGlobalColorFeaturePADither, {kFeaturePADither}}, -}; - -static const uint32_t kMaxPCCChanel = 3; - -class HWColorManagerDrm { - public: - static DisplayError (*GetDrmFeature[kPPFeaturesMax])(const PPFeatureInfo &in_data, - DRMPPFeatureInfo *out_data); - static void FreeDrmFeatureData(DRMPPFeatureInfo *feature); - static uint32_t GetFeatureVersion(const DRMPPFeatureInfo &feature); - static DRMPPFeatureID ToDrmFeatureId(uint32_t id); - - protected: - HWColorManagerDrm() {} - - private: - static DisplayError GetDrmPCC(const PPFeatureInfo &in_data, DRMPPFeatureInfo *out_data); - static DisplayError GetDrmIGC(const PPFeatureInfo &in_data, DRMPPFeatureInfo *out_data); - static DisplayError GetDrmPGC(const PPFeatureInfo &in_data, DRMPPFeatureInfo *out_data); - static DisplayError GetDrmMixerGC(const PPFeatureInfo &in_data, DRMPPFeatureInfo *out_data); - static DisplayError GetDrmDither(const PPFeatureInfo &in_data, DRMPPFeatureInfo *out_data); - static DisplayError GetDrmGamut(const PPFeatureInfo &in_data, DRMPPFeatureInfo *out_data); - static DisplayError GetDrmPADither(const PPFeatureInfo &in_data, DRMPPFeatureInfo *out_data); - static DisplayError GetDrmPAHsic(const PPFeatureInfo &in_data, DRMPPFeatureInfo *out_data); - static DisplayError GetDrmPASixZone(const PPFeatureInfo &in_data, DRMPPFeatureInfo *out_data); - static DisplayError GetDrmPAMemColSkin(const PPFeatureInfo &in_data, DRMPPFeatureInfo *out_data); - static DisplayError GetDrmPAMemColSky(const PPFeatureInfo &in_data, DRMPPFeatureInfo *out_data); - static DisplayError GetDrmPAMemColFoliage(const PPFeatureInfo &in_data, - DRMPPFeatureInfo *out_data); - static DisplayError GetDrmPAMemColProt(const PPFeatureInfo &in_data, DRMPPFeatureInfo *out_data); -}; - -} // namespace sdm - -#endif // __HW_COLOR_MANAGER_DRM_H__ diff --git a/sdm/libs/core/drm/hw_device_drm.cpp b/sdm/libs/core/drm/hw_device_drm.cpp deleted file mode 100644 index ef8deeb7..00000000 --- a/sdm/libs/core/drm/hw_device_drm.cpp +++ /dev/null @@ -1,1579 +0,0 @@ -/* -* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#define __STDC_FORMAT_MACROS - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "hw_device_drm.h" -#include "hw_info_interface.h" -#include "hw_color_manager_drm.h" - -#define __CLASS__ "HWDeviceDRM" - -#ifndef DRM_FORMAT_MOD_QCOM_COMPRESSED -#define DRM_FORMAT_MOD_QCOM_COMPRESSED fourcc_mod_code(QCOM, 1) -#endif -#ifndef DRM_FORMAT_MOD_QCOM_DX -#define DRM_FORMAT_MOD_QCOM_DX fourcc_mod_code(QCOM, 0x2) -#endif -#ifndef DRM_FORMAT_MOD_QCOM_TIGHT -#define DRM_FORMAT_MOD_QCOM_TIGHT fourcc_mod_code(QCOM, 0x4) -#endif - -using std::string; -using std::to_string; -using std::fstream; -using std::unordered_map; -using drm_utils::DRMMaster; -using drm_utils::DRMResMgr; -using drm_utils::DRMLibLoader; -using drm_utils::DRMBuffer; -using sde_drm::GetDRMManager; -using sde_drm::DestroyDRMManager; -using sde_drm::DRMDisplayType; -using sde_drm::DRMDisplayToken; -using sde_drm::DRMConnectorInfo; -using sde_drm::DRMPPFeatureInfo; -using sde_drm::DRMRect; -using sde_drm::DRMRotation; -using sde_drm::DRMBlendType; -using sde_drm::DRMSrcConfig; -using sde_drm::DRMOps; -using sde_drm::DRMTopology; -using sde_drm::DRMPowerMode; -using sde_drm::DRMSecureMode; -using sde_drm::DRMSecurityLevel; -using sde_drm::DRMCscType; -using sde_drm::DRMMultiRectMode; - -namespace sdm { - -static void GetDRMFormat(LayerBufferFormat format, uint32_t *drm_format, - uint64_t *drm_format_modifier) { - switch (format) { - case kFormatRGBA8888: - *drm_format = DRM_FORMAT_ABGR8888; - break; - case kFormatRGBA8888Ubwc: - *drm_format = DRM_FORMAT_ABGR8888; - *drm_format_modifier = DRM_FORMAT_MOD_QCOM_COMPRESSED; - break; - case kFormatRGBA5551: - *drm_format = DRM_FORMAT_ABGR1555; - break; - case kFormatRGBA4444: - *drm_format = DRM_FORMAT_ABGR4444; - break; - case kFormatBGRA8888: - *drm_format = DRM_FORMAT_ARGB8888; - break; - case kFormatRGBX8888: - *drm_format = DRM_FORMAT_XBGR8888; - break; - case kFormatRGBX8888Ubwc: - *drm_format = DRM_FORMAT_XBGR8888; - *drm_format_modifier = DRM_FORMAT_MOD_QCOM_COMPRESSED; - break; - case kFormatBGRX8888: - *drm_format = DRM_FORMAT_XRGB8888; - break; - case kFormatRGB888: - *drm_format = DRM_FORMAT_BGR888; - break; - case kFormatRGB565: - *drm_format = DRM_FORMAT_BGR565; - break; - case kFormatBGR565: - *drm_format = DRM_FORMAT_RGB565; - break; - case kFormatBGR565Ubwc: - *drm_format = DRM_FORMAT_BGR565; - *drm_format_modifier = DRM_FORMAT_MOD_QCOM_COMPRESSED; - break; - case kFormatRGBA1010102: - *drm_format = DRM_FORMAT_ABGR2101010; - break; - case kFormatRGBA1010102Ubwc: - *drm_format = DRM_FORMAT_ABGR2101010; - *drm_format_modifier = DRM_FORMAT_MOD_QCOM_COMPRESSED; - break; - case kFormatARGB2101010: - *drm_format = DRM_FORMAT_BGRA1010102; - break; - case kFormatRGBX1010102: - *drm_format = DRM_FORMAT_XBGR2101010; - break; - case kFormatRGBX1010102Ubwc: - *drm_format = DRM_FORMAT_XBGR2101010; - *drm_format_modifier = DRM_FORMAT_MOD_QCOM_COMPRESSED; - break; - case kFormatXRGB2101010: - *drm_format = DRM_FORMAT_BGRX1010102; - break; - case kFormatBGRA1010102: - *drm_format = DRM_FORMAT_ARGB2101010; - break; - case kFormatABGR2101010: - *drm_format = DRM_FORMAT_RGBA1010102; - break; - case kFormatBGRX1010102: - *drm_format = DRM_FORMAT_XRGB2101010; - break; - case kFormatXBGR2101010: - *drm_format = DRM_FORMAT_RGBX1010102; - break; - case kFormatYCbCr420SemiPlanar: - *drm_format = DRM_FORMAT_NV12; - break; - case kFormatYCbCr420SemiPlanarVenus: - *drm_format = DRM_FORMAT_NV12; - break; - case kFormatYCbCr420SPVenusUbwc: - *drm_format = DRM_FORMAT_NV12; - *drm_format_modifier = DRM_FORMAT_MOD_QCOM_COMPRESSED; - break; - case kFormatYCrCb420SemiPlanar: - *drm_format = DRM_FORMAT_NV21; - break; - case kFormatYCrCb420SemiPlanarVenus: - *drm_format = DRM_FORMAT_NV21; - break; - case kFormatYCbCr420P010: - case kFormatYCbCr420P010Venus: - *drm_format = DRM_FORMAT_NV12; - *drm_format_modifier = DRM_FORMAT_MOD_QCOM_DX; - break; - case kFormatYCbCr420P010Ubwc: - *drm_format = DRM_FORMAT_NV12; - *drm_format_modifier = DRM_FORMAT_MOD_QCOM_COMPRESSED | - DRM_FORMAT_MOD_QCOM_DX; - break; - case kFormatYCbCr420TP10Ubwc: - *drm_format = DRM_FORMAT_NV12; - *drm_format_modifier = DRM_FORMAT_MOD_QCOM_COMPRESSED | - DRM_FORMAT_MOD_QCOM_DX | DRM_FORMAT_MOD_QCOM_TIGHT; - break; - case kFormatYCbCr422H2V1SemiPlanar: - *drm_format = DRM_FORMAT_NV16; - break; - case kFormatYCrCb422H2V1SemiPlanar: - *drm_format = DRM_FORMAT_NV61; - break; - case kFormatYCrCb420PlanarStride16: - *drm_format = DRM_FORMAT_YVU420; - break; - default: - DLOGW("Unsupported format %s", GetFormatString(format)); - } -} - -HWDeviceDRM::Registry::Registry(BufferAllocator *buffer_allocator) : - buffer_allocator_(buffer_allocator) { - DRMMaster *master = nullptr; - DRMMaster::GetInstance(&master); - - if (!master) { - DLOGE("Failed to acquire DRM Master instance"); - return; - } - - // If RMFB is ref-counted, we should immediately make a call to clean up fb_id after commit. - // Driver will release fb_id after its usage. Otherwise speculatively free up fb_id after 3 - // cycles assuming driver is done with it. - rmfb_delay_ = master->IsRmFbRefCounted() ? 1 : 3; - hashmap_ = new std::unordered_map[rmfb_delay_]; -} - -HWDeviceDRM::Registry::~Registry() { - delete [] hashmap_; -} - -void HWDeviceDRM::Registry::Register(HWLayers *hw_layers) { - HWLayersInfo &hw_layer_info = hw_layers->info; - uint32_t hw_layer_count = UINT32(hw_layer_info.hw_layers.size()); - - for (uint32_t i = 0; i < hw_layer_count; i++) { - Layer &layer = hw_layer_info.hw_layers.at(i); - LayerBuffer *input_buffer = &layer.input_buffer; - HWRotatorSession *hw_rotator_session = &hw_layers->config[i].hw_rotator_session; - HWRotateInfo *hw_rotate_info = &hw_rotator_session->hw_rotate_info[0]; - - if (hw_rotator_session->mode == kRotatorOffline && hw_rotate_info->valid) { - input_buffer = &hw_rotator_session->output_buffer; - } - - MapBufferToFbId(input_buffer); - } -} - -void HWDeviceDRM::Registry::MapBufferToFbId(LayerBuffer* buffer) { - int fd = buffer->planes[0].fd; - DRMMaster *master = nullptr; - DRMMaster::GetInstance(&master); - - if (!master) { - DLOGE("Failed to acquire DRM Master instance"); - return; - } - - if (fd >= 0 && hashmap_[current_index_].find(fd) == hashmap_[current_index_].end()) { - AllocatedBufferInfo buf_info{}; - DRMBuffer layout{}; - buf_info.fd = layout.fd = fd; - buf_info.aligned_width = layout.width = buffer->width; - buf_info.aligned_height = layout.height = buffer->height; - buf_info.format = buffer->format; - GetDRMFormat(buf_info.format, &layout.drm_format, &layout.drm_format_modifier); - buffer_allocator_->GetBufferLayout(buf_info, layout.stride, layout.offset, - &layout.num_planes); - uint32_t fb_id = 0; - int ret = master->CreateFbId(layout, &fb_id); - if (ret < 0) { - DLOGW("CreateFbId failed. width %d, height %d, format: %s, stride %u, error %d", - layout.width, layout.height, GetFormatString(buf_info.format), layout.stride[0], - errno); - } else { - hashmap_[current_index_][fd] = fb_id; - } - } - return; -} - -void HWDeviceDRM::Registry::Next() { - current_index_ = (current_index_ + 1) % rmfb_delay_; -} - -void HWDeviceDRM::Registry::Unregister() { - DRMMaster *master = nullptr; - DRMMaster::GetInstance(&master); - - if (!master) { - DLOGE("Failed to acquire DRM Master instance"); - return; - } - - auto &curr_map = hashmap_[current_index_]; - for (auto &pair : curr_map) { - uint32_t fb_id = pair.second; - int ret = master->RemoveFbId(fb_id); - if (ret < 0) { - DLOGE("Removing fb_id %d failed with error %d", fb_id, errno); - } - } - - curr_map.clear(); -} - -void HWDeviceDRM::Registry::Clear() { - for (int i = 0; i < rmfb_delay_; i++) { - Unregister(); - Next(); - } - current_index_ = 0; -} - -uint32_t HWDeviceDRM::Registry::GetFbId(int fd) { - auto it = hashmap_[current_index_].find(fd); - return (it == hashmap_[current_index_].end()) ? 0 : it->second; -} - -HWDeviceDRM::HWDeviceDRM(BufferSyncHandler *buffer_sync_handler, BufferAllocator *buffer_allocator, - HWInfoInterface *hw_info_intf) - : hw_info_intf_(hw_info_intf), buffer_sync_handler_(buffer_sync_handler), - registry_(buffer_allocator) { - hw_info_intf_ = hw_info_intf; -} - -DisplayError HWDeviceDRM::Init() { - DRMMaster *drm_master = {}; - DRMMaster::GetInstance(&drm_master); - drm_master->GetHandle(&dev_fd_); - DRMLibLoader::GetInstance()->FuncGetDRMManager()(dev_fd_, &drm_mgr_intf_); - - if (drm_mgr_intf_->RegisterDisplay(disp_type_, &token_)) { - DLOGE("RegisterDisplay failed for %s", device_name_); - return kErrorResources; - } - - drm_mgr_intf_->CreateAtomicReq(token_, &drm_atomic_intf_); - drm_mgr_intf_->GetConnectorInfo(token_.conn_id, &connector_info_); - hw_info_intf_->GetHWResourceInfo(&hw_resource_); - - InitializeConfigs(); - PopulateHWPanelInfo(); - UpdateMixerAttributes(); - - // TODO(user): In future, remove has_qseed3 member, add version and pass version to constructor - if (hw_resource_.has_qseed3) { - hw_scale_ = new HWScaleDRM(HWScaleDRM::Version::V2); - } - - return kErrorNone; -} - -DisplayError HWDeviceDRM::Deinit() { - DisplayError err = kErrorNone; - drm_atomic_intf_->Perform(DRMOps::CONNECTOR_SET_CRTC, token_.conn_id, 0); - drm_atomic_intf_->Perform(DRMOps::CONNECTOR_SET_POWER_MODE, token_.conn_id, DRMPowerMode::OFF); - drm_atomic_intf_->Perform(DRMOps::CRTC_SET_MODE, token_.crtc_id, nullptr); - drm_atomic_intf_->Perform(DRMOps::CRTC_SET_ACTIVE, token_.crtc_id, 0); - int ret = drm_atomic_intf_->Commit(true /* synchronous */, false /* retain_planes */); - if (ret) { - DLOGE("Commit failed with error: %d", ret); - err = kErrorHardware; - } - - delete hw_scale_; - registry_.Clear(); - display_attributes_ = {}; - drm_mgr_intf_->DestroyAtomicReq(drm_atomic_intf_); - drm_atomic_intf_ = {}; - drm_mgr_intf_->UnregisterDisplay(token_); - return err; -} - -void HWDeviceDRM::InitializeConfigs() { - current_mode_index_ = 0; - // Update current mode with preferred mode - for (uint32_t mode_index = 0; mode_index < connector_info_.modes.size(); mode_index++) { - if (connector_info_.modes[mode_index].mode.type & DRM_MODE_TYPE_PREFERRED) { - current_mode_index_ = mode_index; - break; - } - } - - display_attributes_.resize(connector_info_.modes.size()); - - uint32_t width = connector_info_.modes[current_mode_index_].mode.hdisplay; - uint32_t height = connector_info_.modes[current_mode_index_].mode.vdisplay; - for (uint32_t i = 0; i < connector_info_.modes.size(); i++) { - auto &mode = connector_info_.modes[i].mode; - if (mode.hdisplay != width || mode.vdisplay != height) { - resolution_switch_enabled_ = true; - } - PopulateDisplayAttributes(i); - } -} - -DisplayError HWDeviceDRM::PopulateDisplayAttributes(uint32_t index) { - drmModeModeInfo mode = {}; - uint32_t mm_width = 0; - uint32_t mm_height = 0; - DRMTopology topology = DRMTopology::SINGLE_LM; - - if (default_mode_) { - DRMResMgr *res_mgr = nullptr; - int ret = DRMResMgr::GetInstance(&res_mgr); - if (ret < 0) { - DLOGE("Failed to acquire DRMResMgr instance"); - return kErrorResources; - } - - res_mgr->GetMode(&mode); - res_mgr->GetDisplayDimInMM(&mm_width, &mm_height); - } else { - mode = connector_info_.modes[index].mode; - mm_width = connector_info_.mmWidth; - mm_height = connector_info_.mmHeight; - topology = connector_info_.modes[index].topology; - } - - display_attributes_[index].x_pixels = mode.hdisplay; - display_attributes_[index].y_pixels = mode.vdisplay; - display_attributes_[index].fps = mode.vrefresh; - display_attributes_[index].vsync_period_ns = - UINT32(1000000000L / display_attributes_[index].fps); - - /* - Active Front Sync Back - Region Porch Porch - <-----------------------><----------------><-------------><--------------> - <----- [hv]display -----> - <------------- [hv]sync_start ------------> - <--------------------- [hv]sync_end ---------------------> - <-------------------------------- [hv]total -----------------------------> - */ - - display_attributes_[index].v_front_porch = mode.vsync_start - mode.vdisplay; - display_attributes_[index].v_pulse_width = mode.vsync_end - mode.vsync_start; - display_attributes_[index].v_back_porch = mode.vtotal - mode.vsync_end; - display_attributes_[index].v_total = mode.vtotal; - display_attributes_[index].h_total = mode.htotal; - display_attributes_[index].is_device_split = - (topology == DRMTopology::DUAL_LM || topology == DRMTopology::DUAL_LM_MERGE || - topology == DRMTopology::DUAL_LM_MERGE_DSC || topology == DRMTopology::DUAL_LM_DSC || - topology == DRMTopology::DUAL_LM_DSCMERGE); - display_attributes_[index].clock_khz = mode.clock; - - // If driver doesn't return panel width/height information, default to 320 dpi - if (INT(mm_width) <= 0 || INT(mm_height) <= 0) { - mm_width = UINT32(((FLOAT(mode.hdisplay) * 25.4f) / 320.0f) + 0.5f); - mm_height = UINT32(((FLOAT(mode.vdisplay) * 25.4f) / 320.0f) + 0.5f); - DLOGW("Driver doesn't report panel physical width and height - defaulting to 320dpi"); - } - - display_attributes_[index].x_dpi = (FLOAT(mode.hdisplay) * 25.4f) / FLOAT(mm_width); - display_attributes_[index].y_dpi = (FLOAT(mode.vdisplay) * 25.4f) / FLOAT(mm_height); - SetTopology(topology, &display_attributes_[index].topology); - - DLOGI("Display attributes[%d]: WxH: %dx%d, DPI: %fx%f, FPS: %d, LM_SPLIT: %d, V_BACK_PORCH: %d," \ - " V_FRONT_PORCH: %d, V_PULSE_WIDTH: %d, V_TOTAL: %d, H_TOTAL: %d, CLK: %dKHZ, TOPOLOGY: %d", - index, display_attributes_[index].x_pixels, display_attributes_[index].y_pixels, - display_attributes_[index].x_dpi, display_attributes_[index].y_dpi, - display_attributes_[index].fps, display_attributes_[index].is_device_split, - display_attributes_[index].v_back_porch, display_attributes_[index].v_front_porch, - display_attributes_[index].v_pulse_width, display_attributes_[index].v_total, - display_attributes_[index].h_total, display_attributes_[index].clock_khz, - display_attributes_[index].topology); - - return kErrorNone; -} - -void HWDeviceDRM::PopulateHWPanelInfo() { - hw_panel_info_ = {}; - - snprintf(hw_panel_info_.panel_name, sizeof(hw_panel_info_.panel_name), "%s", - connector_info_.panel_name.c_str()); - - uint32_t index = current_mode_index_; - hw_panel_info_.split_info.left_split = display_attributes_[index].x_pixels; - if (display_attributes_[index].is_device_split) { - hw_panel_info_.split_info.left_split = hw_panel_info_.split_info.right_split = - display_attributes_[index].x_pixels / 2; - } - - hw_panel_info_.partial_update = connector_info_.modes[index].num_roi; - hw_panel_info_.left_roi_count = UINT32(connector_info_.modes[index].num_roi); - hw_panel_info_.right_roi_count = UINT32(connector_info_.modes[index].num_roi); - hw_panel_info_.left_align = connector_info_.modes[index].xstart; - hw_panel_info_.top_align = connector_info_.modes[index].ystart; - hw_panel_info_.width_align = connector_info_.modes[index].walign; - hw_panel_info_.height_align = connector_info_.modes[index].halign; - hw_panel_info_.min_roi_width = connector_info_.modes[index].wmin; - hw_panel_info_.min_roi_height = connector_info_.modes[index].hmin; - hw_panel_info_.needs_roi_merge = connector_info_.modes[index].roi_merge; - hw_panel_info_.dynamic_fps = connector_info_.dynamic_fps; - drmModeModeInfo current_mode = connector_info_.modes[current_mode_index_].mode; - if (hw_panel_info_.dynamic_fps) { - uint32_t min_fps = current_mode.vrefresh; - uint32_t max_fps = current_mode.vrefresh; - for (uint32_t mode_index = 0; mode_index < connector_info_.modes.size(); mode_index++) { - if ((current_mode.vdisplay == connector_info_.modes[mode_index].mode.vdisplay) && - (current_mode.hdisplay == connector_info_.modes[mode_index].mode.hdisplay)) { - if (min_fps > connector_info_.modes[mode_index].mode.vrefresh) { - min_fps = connector_info_.modes[mode_index].mode.vrefresh; - } - if (max_fps < connector_info_.modes[mode_index].mode.vrefresh) { - max_fps = connector_info_.modes[mode_index].mode.vrefresh; - } - } - } - hw_panel_info_.min_fps = min_fps; - hw_panel_info_.max_fps = max_fps; - } else { - hw_panel_info_.min_fps = current_mode.vrefresh; - hw_panel_info_.max_fps = current_mode.vrefresh; - } - - hw_panel_info_.is_primary_panel = connector_info_.is_primary; - hw_panel_info_.is_pluggable = 0; - hw_panel_info_.hdr_enabled = connector_info_.panel_hdr_prop.hdr_enabled; - hw_panel_info_.peak_luminance = connector_info_.panel_hdr_prop.peak_brightness; - hw_panel_info_.blackness_level = connector_info_.panel_hdr_prop.blackness_level; - hw_panel_info_.primaries.white_point[0] = connector_info_.panel_hdr_prop.display_primaries[0]; - hw_panel_info_.primaries.white_point[1] = connector_info_.panel_hdr_prop.display_primaries[1]; - hw_panel_info_.primaries.red[0] = connector_info_.panel_hdr_prop.display_primaries[2]; - hw_panel_info_.primaries.red[1] = connector_info_.panel_hdr_prop.display_primaries[3]; - hw_panel_info_.primaries.green[0] = connector_info_.panel_hdr_prop.display_primaries[4]; - hw_panel_info_.primaries.green[1] = connector_info_.panel_hdr_prop.display_primaries[5]; - hw_panel_info_.primaries.blue[0] = connector_info_.panel_hdr_prop.display_primaries[6]; - hw_panel_info_.primaries.blue[1] = connector_info_.panel_hdr_prop.display_primaries[7]; - hw_panel_info_.transfer_time_us = connector_info_.transfer_time_us; - - // no supprt for 90 rotation only flips or 180 supported - hw_panel_info_.panel_orientation.rotation = 0; - hw_panel_info_.panel_orientation.flip_horizontal = - (connector_info_.panel_orientation == DRMRotation::FLIP_H) || - (connector_info_.panel_orientation == DRMRotation::ROT_180); - hw_panel_info_.panel_orientation.flip_vertical = - (connector_info_.panel_orientation == DRMRotation::FLIP_V) || - (connector_info_.panel_orientation == DRMRotation::ROT_180); - - GetHWDisplayPortAndMode(); - GetHWPanelMaxBrightness(); - - DLOGI("%s, Panel Interface = %s, Panel Mode = %s, Is Primary = %d", device_name_, - interface_str_.c_str(), hw_panel_info_.mode == kModeVideo ? "Video" : "Command", - hw_panel_info_.is_primary_panel); - DLOGI("Partial Update = %d, Dynamic FPS = %d, HDR Panel = %d", hw_panel_info_.partial_update, - hw_panel_info_.dynamic_fps, hw_panel_info_.hdr_enabled); - DLOGI("Align: left = %d, width = %d, top = %d, height = %d", hw_panel_info_.left_align, - hw_panel_info_.width_align, hw_panel_info_.top_align, hw_panel_info_.height_align); - DLOGI("ROI: min_width = %d, min_height = %d, need_merge = %d", hw_panel_info_.min_roi_width, - hw_panel_info_.min_roi_height, hw_panel_info_.needs_roi_merge); - DLOGI("FPS: min = %d, max = %d", hw_panel_info_.min_fps, hw_panel_info_.max_fps); - DLOGI("Left Split = %d, Right Split = %d", hw_panel_info_.split_info.left_split, - hw_panel_info_.split_info.right_split); - DLOGI("Panel Transfer time = %d us", hw_panel_info_.transfer_time_us); -} - -void HWDeviceDRM::GetHWDisplayPortAndMode() { - hw_panel_info_.port = kPortDefault; - hw_panel_info_.mode = - (connector_info_.panel_mode == sde_drm::DRMPanelMode::VIDEO) ? kModeVideo : kModeCommand; - - if (default_mode_) { - return; - } - - switch (connector_info_.type) { - case DRM_MODE_CONNECTOR_DSI: - hw_panel_info_.port = kPortDSI; - interface_str_ = "DSI"; - break; - case DRM_MODE_CONNECTOR_LVDS: - hw_panel_info_.port = kPortLVDS; - interface_str_ = "LVDS"; - break; - case DRM_MODE_CONNECTOR_eDP: - hw_panel_info_.port = kPortEDP; - interface_str_ = "EDP"; - break; - case DRM_MODE_CONNECTOR_TV: - case DRM_MODE_CONNECTOR_HDMIA: - case DRM_MODE_CONNECTOR_HDMIB: - hw_panel_info_.port = kPortDTV; - interface_str_ = "HDMI"; - break; - case DRM_MODE_CONNECTOR_VIRTUAL: - hw_panel_info_.port = kPortWriteBack; - interface_str_ = "Virtual"; - break; - case DRM_MODE_CONNECTOR_DisplayPort: - // TODO(user): Add when available - interface_str_ = "DisplayPort"; - break; - } - - return; -} - -void HWDeviceDRM::GetHWPanelMaxBrightness() { - char brightness[kMaxStringLength] = {0}; - string kMaxBrightnessNode = "/sys/class/backlight/panel0-backlight/max_brightness"; - - hw_panel_info_.panel_max_brightness = 255; - int fd = Sys::open_(kMaxBrightnessNode.c_str(), O_RDONLY); - if (fd < 0) { - DLOGW("Failed to open max brightness node = %s, error = %s", kMaxBrightnessNode.c_str(), - strerror(errno)); - return; - } - - if (Sys::pread_(fd, brightness, sizeof(brightness), 0) > 0) { - hw_panel_info_.panel_max_brightness = atoi(brightness); - DLOGI("Max brightness level = %d", hw_panel_info_.panel_max_brightness); - } else { - DLOGW("Failed to read max brightness level. error = %s", strerror(errno)); - } - - Sys::close_(fd); -} - -DisplayError HWDeviceDRM::GetActiveConfig(uint32_t *active_config) { - if (IsResolutionSwitchEnabled()) { - *active_config = current_mode_index_; - } else { - *active_config = 0; - } - return kErrorNone; -} - -DisplayError HWDeviceDRM::GetNumDisplayAttributes(uint32_t *count) { - if (IsResolutionSwitchEnabled()) { - *count = UINT32(display_attributes_.size()); - if (*count <= 0) { - return kErrorHardware; - } - } else { - *count = 1; - } - return kErrorNone; -} - -DisplayError HWDeviceDRM::GetDisplayAttributes(uint32_t index, - HWDisplayAttributes *display_attributes) { - if (index >= display_attributes_.size()) { - return kErrorParameters; - } - if (IsResolutionSwitchEnabled()) { - *display_attributes = display_attributes_[index]; - } else { - *display_attributes = display_attributes_[current_mode_index_]; - } - return kErrorNone; -} - -DisplayError HWDeviceDRM::GetHWPanelInfo(HWPanelInfo *panel_info) { - *panel_info = hw_panel_info_; - return kErrorNone; -} - -DisplayError HWDeviceDRM::SetDisplayAttributes(uint32_t index) { - if (!IsResolutionSwitchEnabled()) { - return kErrorNotSupported; - } - - if (index >= display_attributes_.size()) { - DLOGE("Invalid mode index %d mode size %d", index, UINT32(display_attributes_.size())); - return kErrorParameters; - } - - current_mode_index_ = index; - PopulateHWPanelInfo(); - UpdateMixerAttributes(); - - DLOGI("Display attributes[%d]: WxH: %dx%d, DPI: %fx%f, FPS: %d, LM_SPLIT: %d, V_BACK_PORCH: %d," \ - " V_FRONT_PORCH: %d, V_PULSE_WIDTH: %d, V_TOTAL: %d, H_TOTAL: %d, CLK: %dKHZ, TOPOLOGY: %d", - index, display_attributes_[index].x_pixels, display_attributes_[index].y_pixels, - display_attributes_[index].x_dpi, display_attributes_[index].y_dpi, - display_attributes_[index].fps, display_attributes_[index].is_device_split, - display_attributes_[index].v_back_porch, display_attributes_[index].v_front_porch, - display_attributes_[index].v_pulse_width, display_attributes_[index].v_total, - display_attributes_[index].h_total, display_attributes_[index].clock_khz, - display_attributes_[index].topology); - - return kErrorNone; -} - -DisplayError HWDeviceDRM::SetDisplayAttributes(const HWDisplayAttributes &display_attributes) { - return kErrorNotSupported; -} - -DisplayError HWDeviceDRM::GetConfigIndex(char *mode, uint32_t *index) { - return kErrorNone; -} - -DisplayError HWDeviceDRM::PowerOn(int *release_fence) { - DTRACE_SCOPED(); - if (!drm_atomic_intf_) { - DLOGE("DRM Atomic Interface is null!"); - return kErrorUndefined; - } - - if (first_cycle_) { - return kErrorNone; - } - - drm_atomic_intf_->Perform(DRMOps::CRTC_SET_ACTIVE, token_.crtc_id, 1); - drm_atomic_intf_->Perform(DRMOps::CONNECTOR_SET_POWER_MODE, token_.conn_id, DRMPowerMode::ON); - int ret = drm_atomic_intf_->Commit(true /* synchronous */, true /* retain_planes */); - if (ret) { - DLOGE("Failed with error: %d", ret); - return kErrorHardware; - } - drm_atomic_intf_->Perform(DRMOps::CRTC_GET_RELEASE_FENCE, token_.crtc_id, release_fence); - - return kErrorNone; -} - -DisplayError HWDeviceDRM::PowerOff() { - DTRACE_SCOPED(); - if (!drm_atomic_intf_) { - DLOGE("DRM Atomic Interface is null!"); - return kErrorUndefined; - } - - SetFullROI(); - drmModeModeInfo current_mode = connector_info_.modes[current_mode_index_].mode; - drm_atomic_intf_->Perform(DRMOps::CRTC_SET_MODE, token_.crtc_id, ¤t_mode); - drm_atomic_intf_->Perform(DRMOps::CONNECTOR_SET_POWER_MODE, token_.conn_id, DRMPowerMode::OFF); - drm_atomic_intf_->Perform(DRMOps::CRTC_SET_ACTIVE, token_.crtc_id, 0); - int ret = drm_atomic_intf_->Commit(true /* synchronous */, false /* retain_planes */); - if (ret) { - DLOGE("Failed with error: %d", ret); - return kErrorHardware; - } - - return kErrorNone; -} - -DisplayError HWDeviceDRM::Doze(int *release_fence) { - DTRACE_SCOPED(); - drm_atomic_intf_->Perform(DRMOps::CRTC_SET_ACTIVE, token_.crtc_id, 1); - drm_atomic_intf_->Perform(DRMOps::CONNECTOR_SET_POWER_MODE, token_.conn_id, DRMPowerMode::DOZE); - int ret = drm_atomic_intf_->Commit(true /* synchronous */, true /* retain_planes */); - if (ret) { - DLOGE("Failed with error: %d", ret); - return kErrorHardware; - } - - drm_atomic_intf_->Perform(DRMOps::CRTC_GET_RELEASE_FENCE, token_.crtc_id, release_fence); - - return kErrorNone; -} - -DisplayError HWDeviceDRM::DozeSuspend(int *release_fence) { - DTRACE_SCOPED(); - drm_atomic_intf_->Perform(DRMOps::CRTC_SET_ACTIVE, token_.crtc_id, 1); - drm_atomic_intf_->Perform(DRMOps::CONNECTOR_SET_POWER_MODE, token_.conn_id, - DRMPowerMode::DOZE_SUSPEND); - int ret = drm_atomic_intf_->Commit(true /* synchronous */, true /* retain_planes */); - if (ret) { - DLOGE("Failed with error: %d", ret); - return kErrorHardware; - } - - drm_atomic_intf_->Perform(DRMOps::CRTC_GET_RELEASE_FENCE, token_.crtc_id, release_fence); - - return kErrorNone; -} - -DisplayError HWDeviceDRM::Standby() { - return kErrorNone; -} - -void HWDeviceDRM::SetupAtomic(HWLayers *hw_layers, bool validate) { - if (default_mode_) { - return; - } - - HWLayersInfo &hw_layer_info = hw_layers->info; - uint32_t hw_layer_count = UINT32(hw_layer_info.hw_layers.size()); - HWQosData &qos_data = hw_layers->qos_data; - DRMSecurityLevel crtc_security_level = DRMSecurityLevel::SECURE_NON_SECURE; - uint32_t index = current_mode_index_; - drmModeModeInfo current_mode = connector_info_.modes[index].mode; - - solid_fills_.clear(); - - // TODO(user): Once destination scalar is enabled we can always send ROIs if driver allows - if (hw_panel_info_.partial_update) { - const int kNumMaxROIs = 4; - DRMRect crtc_rects[kNumMaxROIs] = {{0, 0, mixer_attributes_.width, mixer_attributes_.height}}; - DRMRect conn_rects[kNumMaxROIs] = {{0, 0, display_attributes_[index].x_pixels, - display_attributes_[index].y_pixels}}; - - for (uint32_t i = 0; i < hw_layer_info.left_frame_roi.size(); i++) { - auto &roi = hw_layer_info.left_frame_roi.at(i); - // TODO(user): In multi PU, stitch ROIs vertically adjacent and upate plane destination - crtc_rects[i].left = UINT32(roi.left); - crtc_rects[i].right = UINT32(roi.right); - crtc_rects[i].top = UINT32(roi.top); - crtc_rects[i].bottom = UINT32(roi.bottom); - // TODO(user): In Dest scaler + PU, populate from HWDestScaleInfo->panel_roi - // TODO(user): panel_roi need to be made as a vector in HWLayersInfo and - // needs to be removed from HWDestScaleInfo. - conn_rects[i].left = UINT32(roi.left); - conn_rects[i].right = UINT32(roi.right); - conn_rects[i].top = UINT32(roi.top); - conn_rects[i].bottom = UINT32(roi.bottom); - } - - uint32_t num_rects = std::max(1u, static_cast(hw_layer_info.left_frame_roi.size())); - drm_atomic_intf_->Perform(DRMOps::CRTC_SET_ROI, token_.crtc_id, - num_rects, crtc_rects); - drm_atomic_intf_->Perform(DRMOps::CONNECTOR_SET_ROI, token_.conn_id, - num_rects, conn_rects); - } - - for (uint32_t i = 0; i < hw_layer_count; i++) { - Layer &layer = hw_layer_info.hw_layers.at(i); - LayerBuffer *input_buffer = &layer.input_buffer; - HWPipeInfo *left_pipe = &hw_layers->config[i].left_pipe; - HWPipeInfo *right_pipe = &hw_layers->config[i].right_pipe; - HWRotatorSession *hw_rotator_session = &hw_layers->config[i].hw_rotator_session; - - if (hw_layers->config[i].use_solidfill_stage) { - hw_layers->config[i].hw_solidfill_stage.solid_fill_info = layer.solid_fill_info; - AddSolidfillStage(hw_layers->config[i].hw_solidfill_stage, layer.plane_alpha); - continue; - } - - for (uint32_t count = 0; count < 2; count++) { - HWPipeInfo *pipe_info = (count == 0) ? left_pipe : right_pipe; - HWRotateInfo *hw_rotate_info = &hw_rotator_session->hw_rotate_info[count]; - - if (hw_rotator_session->mode == kRotatorOffline && hw_rotate_info->valid) { - input_buffer = &hw_rotator_session->output_buffer; - } - - uint32_t fb_id = registry_.GetFbId(input_buffer->planes[0].fd); - if (pipe_info->valid && fb_id) { - uint32_t pipe_id = pipe_info->pipe_id; - drm_atomic_intf_->Perform(DRMOps::PLANE_SET_ALPHA, pipe_id, layer.plane_alpha); - drm_atomic_intf_->Perform(DRMOps::PLANE_SET_ZORDER, pipe_id, pipe_info->z_order); - DRMBlendType blending = {}; - SetBlending(layer.blending, &blending); - drm_atomic_intf_->Perform(DRMOps::PLANE_SET_BLEND_TYPE, pipe_id, blending); - DRMRect src = {}; - SetRect(pipe_info->src_roi, &src); - drm_atomic_intf_->Perform(DRMOps::PLANE_SET_SRC_RECT, pipe_id, src); - DRMRect rot_dst = {0, 0, 0, 0}; - if (hw_rotator_session->mode == kRotatorInline && hw_rotate_info->valid) { - SetRect(hw_rotate_info->dst_roi, &rot_dst); - drm_atomic_intf_->Perform(DRMOps::PLANE_SET_ROTATION_DST_RECT, pipe_id, rot_dst); - } - DRMRect dst = {}; - SetRect(pipe_info->dst_roi, &dst); - drm_atomic_intf_->Perform(DRMOps::PLANE_SET_DST_RECT, pipe_id, dst); - - uint32_t rot_bit_mask = 0; - SetRotation(layer.transform, hw_rotator_session->mode, &rot_bit_mask); - drm_atomic_intf_->Perform(DRMOps::PLANE_SET_ROTATION, pipe_id, rot_bit_mask); - drm_atomic_intf_->Perform(DRMOps::PLANE_SET_H_DECIMATION, pipe_id, - pipe_info->horizontal_decimation); - drm_atomic_intf_->Perform(DRMOps::PLANE_SET_V_DECIMATION, pipe_id, - pipe_info->vertical_decimation); - - DRMSecureMode fb_secure_mode; - DRMSecurityLevel security_level; - SetSecureConfig(layer.input_buffer, &fb_secure_mode, &security_level); - drm_atomic_intf_->Perform(DRMOps::PLANE_SET_FB_SECURE_MODE, pipe_id, fb_secure_mode); - if (security_level > crtc_security_level) { - crtc_security_level = security_level; - } - - uint32_t config = 0; - SetSrcConfig(layer.input_buffer, hw_rotator_session->mode, &config); - drm_atomic_intf_->Perform(DRMOps::PLANE_SET_SRC_CONFIG, pipe_id, config);; - drm_atomic_intf_->Perform(DRMOps::PLANE_SET_FB_ID, pipe_id, fb_id); - drm_atomic_intf_->Perform(DRMOps::PLANE_SET_CRTC, pipe_id, token_.crtc_id); - if (!validate && input_buffer->acquire_fence_fd >= 0) { - drm_atomic_intf_->Perform(DRMOps::PLANE_SET_INPUT_FENCE, pipe_id, - input_buffer->acquire_fence_fd); - } - if (hw_scale_) { - SDEScaler scaler_output = {}; - hw_scale_->SetScaler(pipe_info->scale_data, &scaler_output); - // TODO(user): Remove qseed3 and add version check, then send appropriate scaler object - if (hw_resource_.has_qseed3) { - drm_atomic_intf_->Perform(DRMOps::PLANE_SET_SCALER_CONFIG, pipe_id, - reinterpret_cast(&scaler_output.scaler_v2)); - } - } - - DRMCscType csc_type = DRMCscType::kCscTypeMax; - SelectCscType(layer.input_buffer, &csc_type); - drm_atomic_intf_->Perform(DRMOps::PLANE_SET_CSC_CONFIG, pipe_id, &csc_type); - - DRMMultiRectMode multirect_mode; - SetMultiRectMode(pipe_info->flags, &multirect_mode); - drm_atomic_intf_->Perform(DRMOps::PLANE_SET_MULTIRECT_MODE, pipe_id, multirect_mode); - } - } - } - - SetSolidfillStages(); - drm_atomic_intf_->Perform(DRMOps::CRTC_SET_CORE_CLK, token_.crtc_id, qos_data.clock_hz); - drm_atomic_intf_->Perform(DRMOps::CRTC_SET_CORE_AB, token_.crtc_id, qos_data.core_ab_bps); - drm_atomic_intf_->Perform(DRMOps::CRTC_SET_CORE_IB, token_.crtc_id, qos_data.core_ib_bps); - drm_atomic_intf_->Perform(DRMOps::CRTC_SET_LLCC_AB, token_.crtc_id, qos_data.llcc_ab_bps); - drm_atomic_intf_->Perform(DRMOps::CRTC_SET_LLCC_IB, token_.crtc_id, qos_data.llcc_ib_bps); - drm_atomic_intf_->Perform(DRMOps::CRTC_SET_DRAM_AB, token_.crtc_id, qos_data.dram_ab_bps); - drm_atomic_intf_->Perform(DRMOps::CRTC_SET_DRAM_IB, token_.crtc_id, qos_data.dram_ib_bps); - drm_atomic_intf_->Perform(DRMOps::CRTC_SET_ROT_PREFILL_BW, token_.crtc_id, - qos_data.rot_prefill_bw_bps); - drm_atomic_intf_->Perform(DRMOps::CRTC_SET_ROT_CLK, token_.crtc_id, qos_data.rot_clock_hz); - drm_atomic_intf_->Perform(DRMOps::CRTC_SET_SECURITY_LEVEL, token_.crtc_id, crtc_security_level); - - DLOGI_IF(kTagDriverConfig, "%s::%s System Clock=%d Hz, Core: AB=%llu Bps, IB=%llu Bps, " \ - "LLCC: AB=%llu Bps, IB=%llu Bps, DRAM AB=%llu Bps, IB=%llu Bps, "\ - "Rot: Bw=%llu Bps, Clock=%d Hz", validate ? "Validate" : "Commit", device_name_, - qos_data.clock_hz, qos_data.core_ab_bps, qos_data.core_ib_bps, qos_data.llcc_ab_bps, - qos_data.llcc_ib_bps, qos_data.dram_ab_bps, qos_data.dram_ib_bps, - qos_data.rot_prefill_bw_bps, qos_data.rot_clock_hz); - - // Set refresh rate - if (vrefresh_) { - for (uint32_t mode_index = 0; mode_index < connector_info_.modes.size(); mode_index++) { - if ((current_mode.vdisplay == connector_info_.modes[mode_index].mode.vdisplay) && - (current_mode.hdisplay == connector_info_.modes[mode_index].mode.hdisplay) && - (vrefresh_ == connector_info_.modes[mode_index].mode.vrefresh)) { - current_mode = connector_info_.modes[mode_index].mode; - break; - } - } - } - - if (first_cycle_) { - drm_atomic_intf_->Perform(DRMOps::CONNECTOR_SET_CRTC, token_.conn_id, token_.crtc_id); - drm_atomic_intf_->Perform(DRMOps::CONNECTOR_SET_POWER_MODE, token_.conn_id, DRMPowerMode::ON); - } - - drm_atomic_intf_->Perform(DRMOps::CRTC_SET_MODE, token_.crtc_id, ¤t_mode); - drm_atomic_intf_->Perform(DRMOps::CRTC_SET_ACTIVE, token_.crtc_id, 1); - - if (!validate && (hw_layer_info.set_idle_time_ms >= 0)) { - DLOGI_IF(kTagDriverConfig, "Setting idle timeout to = %d ms", - hw_layer_info.set_idle_time_ms); - drm_atomic_intf_->Perform(DRMOps::CRTC_SET_IDLE_TIMEOUT, token_.crtc_id, - hw_layer_info.set_idle_time_ms); - } - - if (hw_panel_info_.mode == kModeCommand) { - drm_atomic_intf_->Perform(DRMOps::CONNECTOR_SET_AUTOREFRESH, token_.conn_id, autorefresh_); - } -} - -void HWDeviceDRM::AddSolidfillStage(const HWSolidfillStage &sf, uint32_t plane_alpha) { - sde_drm::DRMSolidfillStage solidfill; - solidfill.bounding_rect.left = UINT32(sf.roi.left); - solidfill.bounding_rect.top = UINT32(sf.roi.top); - solidfill.bounding_rect.right = UINT32(sf.roi.right); - solidfill.bounding_rect.bottom = UINT32(sf.roi.bottom); - solidfill.is_exclusion_rect = sf.is_exclusion_rect; - solidfill.plane_alpha = plane_alpha; - solidfill.z_order = sf.z_order; - if (!sf.solid_fill_info.bit_depth) { - solidfill.color_bit_depth = 8; - solidfill.alpha = (0xff000000 & sf.color) >> 24; - solidfill.red = (0xff0000 & sf.color) >> 16; - solidfill.green = (0xff00 & sf.color) >> 8; - solidfill.blue = 0xff & sf.color; - } else { - solidfill.color_bit_depth = sf.solid_fill_info.bit_depth; - solidfill.alpha = sf.solid_fill_info.alpha; - solidfill.red = sf.solid_fill_info.red; - solidfill.green = sf.solid_fill_info.green; - solidfill.blue = sf.solid_fill_info.blue; - } - solid_fills_.push_back(solidfill); - DLOGI_IF(kTagDriverConfig, "Add a solidfill stage at z_order:%d argb_color:%x plane_alpha:%x", - solidfill.z_order, solidfill.color, solidfill.plane_alpha); -} - -void HWDeviceDRM::SetSolidfillStages() { - if (hw_resource_.num_solidfill_stages) { - drm_atomic_intf_->Perform(DRMOps::CRTC_SET_SOLIDFILL_STAGES, token_.crtc_id, - reinterpret_cast (&solid_fills_)); - } -} - -DisplayError HWDeviceDRM::Validate(HWLayers *hw_layers) { - DTRACE_SCOPED(); - - DisplayError err = kErrorNone; - registry_.Register(hw_layers); - SetupAtomic(hw_layers, true /* validate */); - - int ret = drm_atomic_intf_->Validate(); - if (ret) { - DLOGE("failed with error %d for %s", ret, device_name_); - vrefresh_ = 0; - err = kErrorHardware; - } - - registry_.Unregister(); - return err; -} - -DisplayError HWDeviceDRM::Commit(HWLayers *hw_layers) { - DTRACE_SCOPED(); - - DisplayError err = kErrorNone; - registry_.Register(hw_layers); - - if (default_mode_) { - err = DefaultCommit(hw_layers); - } else { - err = AtomicCommit(hw_layers); - } - - registry_.Next(); - registry_.Unregister(); - - return err; -} - -DisplayError HWDeviceDRM::DefaultCommit(HWLayers *hw_layers) { - DTRACE_SCOPED(); - - HWLayersInfo &hw_layer_info = hw_layers->info; - LayerStack *stack = hw_layer_info.stack; - - stack->retire_fence_fd = -1; - for (Layer &layer : hw_layer_info.hw_layers) { - layer.input_buffer.release_fence_fd = -1; - } - - DRMMaster *master = nullptr; - int ret = DRMMaster::GetInstance(&master); - if (ret < 0) { - DLOGE("Failed to acquire DRMMaster instance"); - return kErrorResources; - } - - DRMResMgr *res_mgr = nullptr; - ret = DRMResMgr::GetInstance(&res_mgr); - if (ret < 0) { - DLOGE("Failed to acquire DRMResMgr instance"); - return kErrorResources; - } - - int dev_fd = -1; - master->GetHandle(&dev_fd); - - uint32_t connector_id = 0; - res_mgr->GetConnectorId(&connector_id); - - uint32_t crtc_id = 0; - res_mgr->GetCrtcId(&crtc_id); - - drmModeModeInfo mode; - res_mgr->GetMode(&mode); - - uint32_t fb_id = registry_.GetFbId(hw_layer_info.hw_layers.at(0).input_buffer.planes[0].fd); - ret = drmModeSetCrtc(dev_fd, crtc_id, fb_id, 0 /* x */, 0 /* y */, &connector_id, - 1 /* num_connectors */, &mode); - if (ret < 0) { - DLOGE("drmModeSetCrtc failed dev fd %d, fb_id %d, crtc id %d, connector id %d, %s", dev_fd, - fb_id, crtc_id, connector_id, strerror(errno)); - return kErrorHardware; - } - - return kErrorNone; -} - -DisplayError HWDeviceDRM::AtomicCommit(HWLayers *hw_layers) { - DTRACE_SCOPED(); - SetupAtomic(hw_layers, false /* validate */); - - int ret = drm_atomic_intf_->Commit(false /* synchronous */, false /* retain_planes*/); - if (ret) { - DLOGE("%s failed with error %d crtc %d", __FUNCTION__, ret, token_.crtc_id); - vrefresh_ = 0; - return kErrorHardware; - } - - int release_fence = -1; - int retire_fence = -1; - - drm_atomic_intf_->Perform(DRMOps::CRTC_GET_RELEASE_FENCE, token_.crtc_id, &release_fence); - drm_atomic_intf_->Perform(DRMOps::CONNECTOR_GET_RETIRE_FENCE, token_.conn_id, &retire_fence); - - HWLayersInfo &hw_layer_info = hw_layers->info; - LayerStack *stack = hw_layer_info.stack; - stack->retire_fence_fd = retire_fence; - - for (uint32_t i = 0; i < hw_layer_info.hw_layers.size(); i++) { - Layer &layer = hw_layer_info.hw_layers.at(i); - HWRotatorSession *hw_rotator_session = &hw_layers->config[i].hw_rotator_session; - if (hw_rotator_session->mode == kRotatorOffline) { - hw_rotator_session->output_buffer.release_fence_fd = Sys::dup_(release_fence); - } else { - layer.input_buffer.release_fence_fd = Sys::dup_(release_fence); - } - } - - hw_layer_info.sync_handle = release_fence; - - if (vrefresh_) { - // Update current mode index if refresh rate is changed - drmModeModeInfo current_mode = connector_info_.modes[current_mode_index_].mode; - for (uint32_t mode_index = 0; mode_index < connector_info_.modes.size(); mode_index++) { - if ((current_mode.vdisplay == connector_info_.modes[mode_index].mode.vdisplay) && - (current_mode.hdisplay == connector_info_.modes[mode_index].mode.hdisplay) && - (vrefresh_ == connector_info_.modes[mode_index].mode.vrefresh)) { - current_mode_index_ = mode_index; - break; - } - } - vrefresh_ = 0; - } - - first_cycle_ = false; - - return kErrorNone; -} - -DisplayError HWDeviceDRM::Flush() { - DTRACE_SCOPED(); - int ret = drm_atomic_intf_->Commit(false /* synchronous */, false /* retain_planes*/); - if (ret) { - DLOGE("failed with error %d", ret); - return kErrorHardware; - } - - return kErrorNone; -} - -void HWDeviceDRM::SetBlending(const LayerBlending &source, DRMBlendType *target) { - switch (source) { - case kBlendingPremultiplied: - *target = DRMBlendType::PREMULTIPLIED; - break; - case kBlendingOpaque: - *target = DRMBlendType::OPAQUE; - break; - case kBlendingCoverage: - *target = DRMBlendType::COVERAGE; - break; - default: - *target = DRMBlendType::UNDEFINED; - } -} - -void HWDeviceDRM::SetSrcConfig(const LayerBuffer &input_buffer, const HWRotatorMode &mode, - uint32_t *config) { - // In offline rotation case, rotator will handle deinterlacing. - if (mode != kRotatorOffline) { - if (input_buffer.flags.interlace) { - *config |= (0x01 << UINT32(DRMSrcConfig::DEINTERLACE)); - } - } -} - -void HWDeviceDRM::SelectCscType(const LayerBuffer &input_buffer, DRMCscType *type) { - if (type == NULL) { - return; - } - - *type = DRMCscType::kCscTypeMax; - if (input_buffer.format < kFormatYCbCr420Planar) { - return; - } - - switch (input_buffer.color_metadata.colorPrimaries) { - case ColorPrimaries_BT601_6_525: - case ColorPrimaries_BT601_6_625: - *type = ((input_buffer.color_metadata.range == Range_Full) ? - DRMCscType::kCscYuv2Rgb601FR : DRMCscType::kCscYuv2Rgb601L); - break; - case ColorPrimaries_BT709_5: - *type = DRMCscType::kCscYuv2Rgb709L; - break; - case ColorPrimaries_BT2020: - *type = ((input_buffer.color_metadata.range == Range_Full) ? - DRMCscType::kCscYuv2Rgb2020FR : DRMCscType::kCscYuv2Rgb2020L); - break; - default: - break; - } -} - -void HWDeviceDRM::SetRect(const LayerRect &source, DRMRect *target) { - target->left = UINT32(source.left); - target->top = UINT32(source.top); - target->right = UINT32(source.right); - target->bottom = UINT32(source.bottom); -} - -void HWDeviceDRM::SetRotation(LayerTransform transform, const HWRotatorMode &mode, - uint32_t* rot_bit_mask) { - // In offline rotation case, rotator will handle flips set via offline rotator interface. - if (mode == kRotatorOffline) { - *rot_bit_mask = 0; - return; - } - - // In no rotation case or inline rotation case, plane will handle flips - // In DRM framework rotation is applied in counter-clockwise direction. - if (mode == kRotatorInline && transform.rotation == 90) { - // a) rotate 90 clockwise = rotate 270 counter-clockwise in DRM - // rotate 270 is translated as hflip + vflip + rotate90 - // b) rotate 270 clockwise = rotate 90 counter-clockwise in DRM - // c) hflip + rotate 90 clockwise = vflip + rotate 90 counter-clockwise in DRM - // d) vflip + rotate 90 clockwise = hflip + rotate 90 counter-clockwise in DRM - *rot_bit_mask = UINT32(DRMRotation::ROT_90); - transform.flip_horizontal = !transform.flip_horizontal; - transform.flip_vertical = !transform.flip_vertical; - } - - if (transform.flip_horizontal) { - *rot_bit_mask |= UINT32(DRMRotation::FLIP_H); - } - - if (transform.flip_vertical) { - *rot_bit_mask |= UINT32(DRMRotation::FLIP_V); - } -} - -bool HWDeviceDRM::EnableHotPlugDetection(int enable) { - return true; -} - -DisplayError HWDeviceDRM::SetCursorPosition(HWLayers *hw_layers, int x, int y) { - DTRACE_SCOPED(); - return kErrorNone; -} - -DisplayError HWDeviceDRM::GetPPFeaturesVersion(PPFeatureVersion *vers) { - struct DRMPPFeatureInfo info = {}; - for (uint32_t i = 0; i < kMaxNumPPFeatures; i++) { - memset(&info, 0, sizeof(struct DRMPPFeatureInfo)); - info.id = HWColorManagerDrm::ToDrmFeatureId(i); - if (info.id >= sde_drm::kPPFeaturesMax) - continue; - // use crtc_id_ = 0 since PP features are same across all CRTCs - drm_mgr_intf_->GetCrtcPPInfo(0, &info); - vers->version[i] = HWColorManagerDrm::GetFeatureVersion(info); - } - return kErrorNone; -} - -DisplayError HWDeviceDRM::SetPPFeatures(PPFeaturesConfig *feature_list) { - int ret = 0; - PPFeatureInfo *feature = NULL; - DRMPPFeatureInfo kernel_params = {}; - bool crtc_feature = true; - - while (true) { - crtc_feature = true; - ret = feature_list->RetrieveNextFeature(&feature); - if (ret) - break; - kernel_params.id = HWColorManagerDrm::ToDrmFeatureId(feature->feature_id_); - drm_mgr_intf_->GetCrtcPPInfo(0, &kernel_params); - if (kernel_params.version == std::numeric_limits::max()) - crtc_feature = false; - if (feature) { - DLOGV_IF(kTagDriverConfig, "feature_id = %d", feature->feature_id_); - auto drm_features = DrmPPfeatureMap_.find(feature->feature_id_); - if (drm_features == DrmPPfeatureMap_.end()) { - DLOGE("DrmFeatures not valid for feature %d", feature->feature_id_); - continue; - } - - for (uint32_t drm_feature : drm_features->second) { - if (!HWColorManagerDrm::GetDrmFeature[drm_feature]) { - DLOGE("GetDrmFeature is not valid for DRM feature %d", drm_feature); - continue; - } - ret = HWColorManagerDrm::GetDrmFeature[drm_feature](*feature, &kernel_params); - if (!ret && crtc_feature) - drm_atomic_intf_->Perform(DRMOps::CRTC_SET_POST_PROC, token_.crtc_id, &kernel_params); - else if (!ret && !crtc_feature) - drm_atomic_intf_->Perform(DRMOps::CONNECTOR_SET_POST_PROC, token_.conn_id, &kernel_params); - HWColorManagerDrm::FreeDrmFeatureData(&kernel_params); - } - } - } - - // Once all features were consumed, then destroy all feature instance from feature_list, - feature_list->Reset(); - - return kErrorNone; -} - -DisplayError HWDeviceDRM::SetVSyncState(bool enable) { - return kErrorNotSupported; -} - -void HWDeviceDRM::SetIdleTimeoutMs(uint32_t timeout_ms) { - // TODO(user): This function can be removed after fb is deprecated -} - -DisplayError HWDeviceDRM::SetDisplayMode(const HWDisplayMode hw_display_mode) { - return kErrorNotSupported; -} - -DisplayError HWDeviceDRM::SetRefreshRate(uint32_t refresh_rate) { - // Check if requested refresh rate is valid - drmModeModeInfo current_mode = connector_info_.modes[current_mode_index_].mode; - for (uint32_t mode_index = 0; mode_index < connector_info_.modes.size(); mode_index++) { - if ((current_mode.vdisplay == connector_info_.modes[mode_index].mode.vdisplay) && - (current_mode.hdisplay == connector_info_.modes[mode_index].mode.hdisplay) && - (refresh_rate == connector_info_.modes[mode_index].mode.vrefresh)) { - vrefresh_ = refresh_rate; - DLOGV_IF(kTagDriverConfig, "Set refresh rate to %d", refresh_rate); - return kErrorNone; - } - } - return kErrorNotSupported; -} - -DisplayError HWDeviceDRM::SetPanelBrightness(int level) { - DisplayError err = kErrorNone; - char buffer[kMaxSysfsCommandLength] = {0}; - - DLOGV_IF(kTagDriverConfig, "Set brightness level to %d", level); - int fd = Sys::open_(kBrightnessNode, O_RDWR); - if (fd < 0) { - DLOGV_IF(kTagDriverConfig, "Failed to open node = %s, error = %s ", kBrightnessNode, - strerror(errno)); - return kErrorFileDescriptor; - } - - int32_t bytes = snprintf(buffer, kMaxSysfsCommandLength, "%d\n", level); - ssize_t ret = Sys::pwrite_(fd, buffer, static_cast(bytes), 0); - if (ret <= 0) { - DLOGV_IF(kTagDriverConfig, "Failed to write to node = %s, error = %s ", kBrightnessNode, - strerror(errno)); - err = kErrorHardware; - } - - Sys::close_(fd); - - return err; -} - -DisplayError HWDeviceDRM::GetPanelBrightness(int *level) { - DisplayError err = kErrorNone; - char brightness[kMaxStringLength] = {0}; - - if (!level) { - DLOGV_IF(kTagDriverConfig, "Invalid input, null pointer."); - return kErrorParameters; - } - - int fd = Sys::open_(kBrightnessNode, O_RDWR); - if (fd < 0) { - DLOGV_IF(kTagDriverConfig, "Failed to open brightness node = %s, error = %s", kBrightnessNode, - strerror(errno)); - return kErrorFileDescriptor; - } - - if (Sys::pread_(fd, brightness, sizeof(brightness), 0) > 0) { - *level = atoi(brightness); - DLOGV_IF(kTagDriverConfig, "Brightness level = %d", *level); - } else { - DLOGV_IF(kTagDriverConfig, "Failed to read panel brightness"); - err = kErrorHardware; - } - - Sys::close_(fd); - - return err; -} - -DisplayError HWDeviceDRM::GetHWScanInfo(HWScanInfo *scan_info) { - return kErrorNotSupported; -} - -DisplayError HWDeviceDRM::GetVideoFormat(uint32_t config_index, uint32_t *video_format) { - return kErrorNotSupported; -} - -DisplayError HWDeviceDRM::GetMaxCEAFormat(uint32_t *max_cea_format) { - return kErrorNotSupported; -} - -DisplayError HWDeviceDRM::OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level) { - return kErrorNotSupported; -} - -DisplayError HWDeviceDRM::SetS3DMode(HWS3DMode s3d_mode) { - return kErrorNotSupported; -} - -DisplayError HWDeviceDRM::SetScaleLutConfig(HWScaleLutInfo *lut_info) { - sde_drm::DRMScalerLUTInfo drm_lut_info = {}; - drm_lut_info.cir_lut = lut_info->cir_lut; - drm_lut_info.dir_lut = lut_info->dir_lut; - drm_lut_info.sep_lut = lut_info->sep_lut; - drm_lut_info.cir_lut_size = lut_info->cir_lut_size; - drm_lut_info.dir_lut_size = lut_info->dir_lut_size; - drm_lut_info.sep_lut_size = lut_info->sep_lut_size; - drm_mgr_intf_->SetScalerLUT(drm_lut_info); - - return kErrorNone; -} - -DisplayError HWDeviceDRM::SetMixerAttributes(const HWMixerAttributes &mixer_attributes) { - if (IsResolutionSwitchEnabled()) { - return kErrorNotSupported; - } - - if (!hw_resource_.hw_dest_scalar_info.count) { - return kErrorNotSupported; - } - - uint32_t index = current_mode_index_; - - if (mixer_attributes.width > display_attributes_[index].x_pixels || - mixer_attributes.height > display_attributes_[index].y_pixels) { - DLOGW("Input resolution exceeds display resolution! input: res %dx%d display: res %dx%d", - mixer_attributes.width, mixer_attributes.height, display_attributes_[index].x_pixels, - display_attributes_[index].y_pixels); - return kErrorNotSupported; - } - - uint32_t max_input_width = hw_resource_.hw_dest_scalar_info.max_input_width; - if (display_attributes_[index].is_device_split) { - max_input_width *= 2; - } - - if (mixer_attributes.width > max_input_width) { - DLOGW("Input width exceeds width limit! input_width %d width_limit %d", mixer_attributes.width, - max_input_width); - return kErrorNotSupported; - } - - float mixer_aspect_ratio = FLOAT(mixer_attributes.width) / FLOAT(mixer_attributes.height); - float display_aspect_ratio = - FLOAT(display_attributes_[index].x_pixels) / FLOAT(display_attributes_[index].y_pixels); - - if (display_aspect_ratio != mixer_aspect_ratio) { - DLOGW("Aspect ratio mismatch! input: res %dx%d display: res %dx%d", mixer_attributes.width, - mixer_attributes.height, display_attributes_[index].x_pixels, - display_attributes_[index].y_pixels); - return kErrorNotSupported; - } - - float scale_x = FLOAT(display_attributes_[index].x_pixels) / FLOAT(mixer_attributes.width); - float scale_y = FLOAT(display_attributes_[index].y_pixels) / FLOAT(mixer_attributes.height); - float max_scale_up = hw_resource_.hw_dest_scalar_info.max_scale_up; - if (scale_x > max_scale_up || scale_y > max_scale_up) { - DLOGW( - "Up scaling ratio exceeds for destination scalar upscale limit scale_x %f scale_y %f " - "max_scale_up %f", - scale_x, scale_y, max_scale_up); - return kErrorNotSupported; - } - - float mixer_split_ratio = FLOAT(mixer_attributes_.split_left) / FLOAT(mixer_attributes_.width); - - mixer_attributes_ = mixer_attributes; - mixer_attributes_.split_left = mixer_attributes_.width; - if (display_attributes_[index].is_device_split) { - mixer_attributes_.split_left = UINT32(FLOAT(mixer_attributes.width) * mixer_split_ratio); - } - - return kErrorNone; -} - -DisplayError HWDeviceDRM::GetMixerAttributes(HWMixerAttributes *mixer_attributes) { - if (!mixer_attributes) { - return kErrorParameters; - } - - *mixer_attributes = mixer_attributes_; - - return kErrorNone; -} - -void HWDeviceDRM::GetDRMDisplayToken(sde_drm::DRMDisplayToken *token) const { - *token = token_; -} - -void HWDeviceDRM::UpdateMixerAttributes() { - uint32_t index = current_mode_index_; - - mixer_attributes_.width = display_attributes_[index].x_pixels; - mixer_attributes_.height = display_attributes_[index].y_pixels; - mixer_attributes_.split_left = display_attributes_[index].is_device_split - ? hw_panel_info_.split_info.left_split - : mixer_attributes_.width; - DLOGI("Mixer WxH %dx%d for %s", mixer_attributes_.width, mixer_attributes_.height, device_name_); -} - -void HWDeviceDRM::SetSecureConfig(const LayerBuffer &input_buffer, DRMSecureMode *fb_secure_mode, - DRMSecurityLevel *security_level) { - *fb_secure_mode = DRMSecureMode::NON_SECURE; - *security_level = DRMSecurityLevel::SECURE_NON_SECURE; - - if (input_buffer.flags.secure) { - if (input_buffer.flags.secure_camera) { - // IOMMU configuration for this framebuffer mode is secure domain & requires - // only stage II translation, when this buffer is accessed by Display H/W. - // Secure and non-secure planes can be attached to this CRTC. - *fb_secure_mode = DRMSecureMode::SECURE_DIR_TRANSLATION; - } else if (input_buffer.flags.secure_display) { - // IOMMU configuration for this framebuffer mode is secure domain & requires - // only stage II translation, when this buffer is accessed by Display H/W. - // Only secure planes can be attached to this CRTC. - *fb_secure_mode = DRMSecureMode::SECURE_DIR_TRANSLATION; - *security_level = DRMSecurityLevel::SECURE_ONLY; - } else { - // IOMMU configuration for this framebuffer mode is secure domain & requires both - // stage I and stage II translations, when this buffer is accessed by Display H/W. - // Secure and non-secure planes can be attached to this CRTC. - *fb_secure_mode = DRMSecureMode::SECURE; - } - } -} - -void HWDeviceDRM::SetTopology(sde_drm::DRMTopology drm_topology, HWTopology *hw_topology) { - switch (drm_topology) { - case DRMTopology::SINGLE_LM: *hw_topology = kSingleLM; break; - case DRMTopology::SINGLE_LM_DSC: *hw_topology = kSingleLMDSC; break; - case DRMTopology::DUAL_LM: *hw_topology = kDualLM; break; - case DRMTopology::DUAL_LM_DSC: *hw_topology = kDualLMDSC; break; - case DRMTopology::DUAL_LM_MERGE: *hw_topology = kDualLMMerge; break; - case DRMTopology::DUAL_LM_MERGE_DSC: *hw_topology = kDualLMMergeDSC; break; - case DRMTopology::DUAL_LM_DSCMERGE: *hw_topology = kDualLMDSCMerge; break; - case DRMTopology::PPSPLIT: *hw_topology = kPPSplit; break; - default: *hw_topology = kUnknown; break; - } -} - -void HWDeviceDRM::SetMultiRectMode(const uint32_t flags, DRMMultiRectMode *target) { - *target = DRMMultiRectMode::NONE; - if (flags & kMultiRect) { - *target = DRMMultiRectMode::SERIAL; - if (flags & kMultiRectParallelMode) { - *target = DRMMultiRectMode::PARALLEL; - } - } -} - -void HWDeviceDRM::SetFullROI() { - // Reset the CRTC ROI and connector ROI only for the panel that supports partial update - if (!hw_panel_info_.partial_update) { - return; - } - uint32_t index = current_mode_index_; - DRMRect crtc_rects = {0, 0, mixer_attributes_.width, mixer_attributes_.height}; - DRMRect conn_rects = {0, 0, display_attributes_[index].x_pixels, - display_attributes_[index].y_pixels}; - drm_atomic_intf_->Perform(DRMOps::CRTC_SET_ROI, token_.crtc_id, 1, &crtc_rects); - drm_atomic_intf_->Perform(DRMOps::CONNECTOR_SET_ROI, token_.conn_id, 1, &conn_rects); -} - -} // namespace sdm diff --git a/sdm/libs/core/drm/hw_device_drm.h b/sdm/libs/core/drm/hw_device_drm.h deleted file mode 100644 index d2fa276f..00000000 --- a/sdm/libs/core/drm/hw_device_drm.h +++ /dev/null @@ -1,195 +0,0 @@ -/* -* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __HW_DEVICE_DRM_H__ -#define __HW_DEVICE_DRM_H__ - -#include -#include -#include -#include -#include -#include -#include - -#include "hw_interface.h" -#include "hw_scale_drm.h" - -#define IOCTL_LOGE(ioctl, type) \ - DLOGE("ioctl %s, device = %d errno = %d, desc = %s", #ioctl, type, errno, strerror(errno)) - -namespace sdm { -class HWInfoInterface; - -class HWDeviceDRM : public HWInterface { - public: - HWDeviceDRM(BufferSyncHandler *buffer_sync_handler, BufferAllocator *buffer_allocator, - HWInfoInterface *hw_info_intf); - virtual ~HWDeviceDRM() {} - virtual DisplayError Init(); - virtual DisplayError Deinit(); - void GetDRMDisplayToken(sde_drm::DRMDisplayToken *token) const; - bool IsPrimaryDisplay() const { return hw_panel_info_.is_primary_panel; } - - protected: - // From HWInterface - virtual DisplayError GetActiveConfig(uint32_t *active_config); - virtual DisplayError GetNumDisplayAttributes(uint32_t *count); - virtual DisplayError GetDisplayAttributes(uint32_t index, - HWDisplayAttributes *display_attributes); - virtual DisplayError GetHWPanelInfo(HWPanelInfo *panel_info); - virtual DisplayError SetDisplayAttributes(uint32_t index); - virtual DisplayError SetDisplayAttributes(const HWDisplayAttributes &display_attributes); - virtual DisplayError GetConfigIndex(char *mode, uint32_t *index); - virtual DisplayError PowerOn(int *release_fence); - virtual DisplayError PowerOff(); - virtual DisplayError Doze(int *release_fence); - virtual DisplayError DozeSuspend(int *release_fence); - virtual DisplayError Standby(); - virtual DisplayError Validate(HWLayers *hw_layers); - virtual DisplayError Commit(HWLayers *hw_layers); - virtual DisplayError Flush(); - virtual DisplayError GetPPFeaturesVersion(PPFeatureVersion *vers); - virtual DisplayError SetPPFeatures(PPFeaturesConfig *feature_list); - // This API is no longer supported, expectation is to call the correct API on HWEvents - virtual DisplayError SetVSyncState(bool enable); - virtual void SetIdleTimeoutMs(uint32_t timeout_ms); - virtual DisplayError SetDisplayMode(const HWDisplayMode hw_display_mode); - virtual DisplayError SetRefreshRate(uint32_t refresh_rate); - virtual DisplayError SetPanelBrightness(int level); - virtual DisplayError GetHWScanInfo(HWScanInfo *scan_info); - virtual DisplayError GetVideoFormat(uint32_t config_index, uint32_t *video_format); - virtual DisplayError GetMaxCEAFormat(uint32_t *max_cea_format); - virtual DisplayError SetCursorPosition(HWLayers *hw_layers, int x, int y); - virtual DisplayError OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level); - virtual DisplayError GetPanelBrightness(int *level); - virtual DisplayError SetAutoRefresh(bool enable) { autorefresh_ = enable; return kErrorNone; } - virtual DisplayError SetS3DMode(HWS3DMode s3d_mode); - virtual DisplayError SetScaleLutConfig(HWScaleLutInfo *lut_info); - virtual DisplayError SetMixerAttributes(const HWMixerAttributes &mixer_attributes); - virtual DisplayError GetMixerAttributes(HWMixerAttributes *mixer_attributes); - virtual void InitializeConfigs(); - virtual DisplayError DumpDebugData() { return kErrorNone; } - virtual void PopulateHWPanelInfo(); - - enum { - kHWEventVSync, - kHWEventBlank, - }; - - static const int kMaxStringLength = 1024; - static const int kNumPhysicalDisplays = 2; - static const int kMaxSysfsCommandLength = 12; - static constexpr const char *kBrightnessNode = - "/sys/class/backlight/panel0-backlight/brightness"; - - DisplayError SetFormat(const LayerBufferFormat &source, uint32_t *target); - DisplayError SetStride(HWDeviceType device_type, LayerBufferFormat format, uint32_t width, - uint32_t *target); - DisplayError PopulateDisplayAttributes(uint32_t index); - void GetHWDisplayPortAndMode(); - void GetHWPanelMaxBrightness(); - bool EnableHotPlugDetection(int enable); - void UpdateMixerAttributes(); - void SetSolidfillStages(); - void AddSolidfillStage(const HWSolidfillStage &sf, uint32_t plane_alpha); - void SetBlending(const LayerBlending &source, sde_drm::DRMBlendType *target); - void SetSrcConfig(const LayerBuffer &input_buffer, const HWRotatorMode &mode, uint32_t *config); - void SelectCscType(const LayerBuffer &input_buffer, sde_drm::DRMCscType *type); - void SetRect(const LayerRect &source, sde_drm::DRMRect *target); - void SetRotation(LayerTransform transform, const HWRotatorMode &mode, uint32_t* rot_bit_mask); - DisplayError DefaultCommit(HWLayers *hw_layers); - DisplayError AtomicCommit(HWLayers *hw_layers); - void SetupAtomic(HWLayers *hw_layers, bool validate); - void SetSecureConfig(const LayerBuffer &input_buffer, sde_drm::DRMSecureMode *fb_secure_mode, - sde_drm::DRMSecurityLevel *security_level); - bool IsResolutionSwitchEnabled() const { return resolution_switch_enabled_; } - void SetTopology(sde_drm::DRMTopology drm_topology, HWTopology *hw_topology); - void SetMultiRectMode(const uint32_t flags, sde_drm::DRMMultiRectMode *target); - void SetFullROI(); - - class Registry { - public: - explicit Registry(BufferAllocator *buffer_allocator); - ~Registry(); - // Called on each Validate and Commit to register layer buffers fds to the slot pointed to by - // current_index_ - void Register(HWLayers *hw_layers); - // Clears the slot pointed to by current_index_ - void Unregister(); - // Moves current_index_ to the next position - void Next(); - // Called on display disconnect to release all gem handles and fb_ids - void Clear(); - // Maps given fd to FB ID - void MapBufferToFbId(LayerBuffer* buffer); - // Finds an fb_id corresponding to an fd in current map - uint32_t GetFbId(int fd); - - private: - uint8_t rmfb_delay_ = 1; // N cycle delay before destroy - // fd to fb_id map. fd is used as key only for a single draw cycle between - // prepare and commit. It should not be used for caching in future due to fd recycling - std::unordered_map *hashmap_ {}; - int current_index_ = 0; - BufferAllocator *buffer_allocator_ = {}; - }; - - protected: - const char *device_name_ = {}; - bool default_mode_ = false; - sde_drm::DRMDisplayType disp_type_ = {}; - HWInfoInterface *hw_info_intf_ = {}; - BufferSyncHandler *buffer_sync_handler_ = {}; - int dev_fd_ = -1; - Registry registry_; - sde_drm::DRMDisplayToken token_ = {}; - HWResourceInfo hw_resource_ = {}; - HWPanelInfo hw_panel_info_ = {}; - HWScaleDRM *hw_scale_ = {}; - sde_drm::DRMManagerInterface *drm_mgr_intf_ = {}; - sde_drm::DRMAtomicReqInterface *drm_atomic_intf_ = {}; - std::vector display_attributes_ = {}; - uint32_t current_mode_index_ = 0; - sde_drm::DRMConnectorInfo connector_info_ = {}; - bool first_cycle_ = true; - - private: - bool synchronous_commit_ = false; - HWMixerAttributes mixer_attributes_ = {}; - std::string interface_str_ = "DSI"; - std::vector solid_fills_ {}; - bool resolution_switch_enabled_ = false; - uint32_t vrefresh_ = 0; - bool autorefresh_ = false; -}; - -} // namespace sdm - -#endif // __HW_DEVICE_DRM_H__ diff --git a/sdm/libs/core/drm/hw_events_drm.cpp b/sdm/libs/core/drm/hw_events_drm.cpp deleted file mode 100644 index 4d1eea9a..00000000 --- a/sdm/libs/core/drm/hw_events_drm.cpp +++ /dev/null @@ -1,616 +0,0 @@ -/* -* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "hw_events_drm.h" - -#define __CLASS__ "HWEventsDRM" - -namespace sdm { - -using drm_utils::DRMMaster; - -DisplayError HWEventsDRM::InitializePollFd() { - for (uint32_t i = 0; i < event_data_list_.size(); i++) { - char data[kMaxStringLength]{}; - HWEventData &event_data = event_data_list_[i]; - poll_fds_[i] = {}; - poll_fds_[i].fd = -1; - - switch (event_data.event_type) { - case HWEvent::VSYNC: { - poll_fds_[i].events = POLLIN | POLLPRI | POLLERR; - if (is_primary_) { - DRMMaster *master = nullptr; - int ret = DRMMaster::GetInstance(&master); - if (ret < 0) { - DLOGE("Failed to acquire DRMMaster instance"); - return kErrorNotSupported; - } - master->GetHandle(&poll_fds_[i].fd); - } else { - poll_fds_[i].fd = drmOpen("msm_drm", nullptr); - } - vsync_index_ = i; - } break; - case HWEvent::EXIT: { - // Create an eventfd to be used to unblock the poll system call when - // a thread is exiting. - poll_fds_[i].fd = Sys::eventfd_(0, 0); - poll_fds_[i].events |= POLLIN; - // Clear any existing data - Sys::pread_(poll_fds_[i].fd, data, kMaxStringLength, 0); - } break; - case HWEvent::IDLE_NOTIFY: { - poll_fds_[i].fd = drmOpen("msm_drm", nullptr); - if (poll_fds_[i].fd < 0) { - DLOGE("drmOpen failed with error %d", poll_fds_[i].fd); - return kErrorResources; - } - poll_fds_[i].events = POLLIN | POLLPRI | POLLERR; - idle_notify_index_ = i; - } break; - case HWEvent::IDLE_POWER_COLLAPSE: { - poll_fds_[i].fd = drmOpen("msm_drm", nullptr); - if (poll_fds_[i].fd < 0) { - DLOGE("drmOpen failed with error %d", poll_fds_[i].fd); - return kErrorResources; - } - poll_fds_[i].events = POLLIN | POLLPRI | POLLERR; - idle_pc_index_ = i; - } break; - case HWEvent::PANEL_DEAD: { - poll_fds_[i].fd = drmOpen("msm_drm", nullptr); - if (poll_fds_[i].fd < 0) { - DLOGE("drmOpen failed with error %d", poll_fds_[i].fd); - return kErrorResources; - } - poll_fds_[i].events = POLLIN | POLLPRI | POLLERR; - panel_dead_index_ = i; - } break; - case HWEvent::CEC_READ_MESSAGE: - case HWEvent::SHOW_BLANK_EVENT: - case HWEvent::THERMAL_LEVEL: - case HWEvent::PINGPONG_TIMEOUT: - break; - } - } - - return kErrorNone; -} - -DisplayError HWEventsDRM::SetEventParser() { - DisplayError error = kErrorNone; - - for (auto &event_data : event_data_list_) { - switch (event_data.event_type) { - case HWEvent::VSYNC: - event_data.event_parser = &HWEventsDRM::HandleVSync; - break; - case HWEvent::IDLE_NOTIFY: - event_data.event_parser = &HWEventsDRM::HandleIdleTimeout; - break; - case HWEvent::CEC_READ_MESSAGE: - event_data.event_parser = &HWEventsDRM::HandleCECMessage; - break; - case HWEvent::EXIT: - event_data.event_parser = &HWEventsDRM::HandleThreadExit; - break; - case HWEvent::SHOW_BLANK_EVENT: - event_data.event_parser = &HWEventsDRM::HandleBlank; - break; - case HWEvent::THERMAL_LEVEL: - event_data.event_parser = &HWEventsDRM::HandleThermal; - break; - case HWEvent::IDLE_POWER_COLLAPSE: - event_data.event_parser = &HWEventsDRM::HandleIdlePowerCollapse; - break; - case HWEvent::PANEL_DEAD: - event_data.event_parser = &HWEventsDRM::HandlePanelDead; - break; - default: - error = kErrorParameters; - break; - } - } - - return error; -} - -void HWEventsDRM::PopulateHWEventData(const vector &event_list) { - for (auto &event : event_list) { - HWEventData event_data; - event_data.event_type = event; - event_data_list_.push_back(std::move(event_data)); - } - - SetEventParser(); - InitializePollFd(); -} - -DisplayError HWEventsDRM::Init(int display_type, HWEventHandler *event_handler, - const vector &event_list, - const HWInterface *hw_intf) { - if (!event_handler) - return kErrorParameters; - - static_cast(hw_intf)->GetDRMDisplayToken(&token_); - is_primary_ = static_cast(hw_intf)->IsPrimaryDisplay(); - - DLOGI("Setup event handler for display %d, CRTC %d, Connector %d", - display_type, token_.crtc_id, token_.conn_id); - - event_handler_ = event_handler; - poll_fds_.resize(event_list.size()); - event_thread_name_ += " - " + std::to_string(display_type); - - PopulateHWEventData(event_list); - - if (pthread_create(&event_thread_, NULL, &DisplayEventThread, this) < 0) { - DLOGE("Failed to start %s, error = %s", event_thread_name_.c_str()); - return kErrorResources; - } - - RegisterVSync(); - vsync_registered_ = true; - RegisterPanelDead(true); - RegisterIdleNotify(true); - RegisterIdlePowerCollapse(true); - - return kErrorNone; -} - -DisplayError HWEventsDRM::Deinit() { - exit_threads_ = true; - RegisterPanelDead(false); - RegisterIdleNotify(false); - RegisterIdlePowerCollapse(false); - Sys::pthread_cancel_(event_thread_); - WakeUpEventThread(); - pthread_join(event_thread_, NULL); - CloseFds(); - - return kErrorNone; -} - -DisplayError HWEventsDRM::SetEventState(HWEvent event, bool enable, void *arg) { - switch (event) { - case HWEvent::VSYNC: { - std::lock_guard lock(vsync_mutex_); - vsync_enabled_ = enable; - if (vsync_enabled_ && !vsync_registered_) { - RegisterVSync(); - vsync_registered_ = true; - } - } break; - default: - DLOGE("Event not supported"); - return kErrorNotSupported; - } - - return kErrorNone; -} - -void HWEventsDRM::WakeUpEventThread() { - for (uint32_t i = 0; i < event_data_list_.size(); i++) { - if (event_data_list_[i].event_type == HWEvent::EXIT && poll_fds_[i].fd >= 0) { - uint64_t exit_value = 1; - ssize_t write_size = Sys::write_(poll_fds_[i].fd, &exit_value, sizeof(uint64_t)); - if (write_size != sizeof(uint64_t)) { - DLOGW("Error triggering exit fd (%d). write size = %d, error = %s", poll_fds_[i].fd, - write_size, strerror(errno)); - } - break; - } - } -} - -DisplayError HWEventsDRM::CloseFds() { - for (uint32_t i = 0; i < event_data_list_.size(); i++) { - switch (event_data_list_[i].event_type) { - case HWEvent::VSYNC: - if (!is_primary_) { - Sys::close_(poll_fds_[i].fd); - } - poll_fds_[i].fd = -1; - break; - case HWEvent::EXIT: - Sys::close_(poll_fds_[i].fd); - poll_fds_[i].fd = -1; - break; - case HWEvent::IDLE_NOTIFY: - case HWEvent::IDLE_POWER_COLLAPSE: - case HWEvent::PANEL_DEAD: - drmClose(poll_fds_[i].fd); - poll_fds_[i].fd = -1; - break; - case HWEvent::CEC_READ_MESSAGE: - case HWEvent::SHOW_BLANK_EVENT: - case HWEvent::THERMAL_LEVEL: - break; - default: - return kErrorNotSupported; - } - } - - return kErrorNone; -} - -void *HWEventsDRM::DisplayEventThread(void *context) { - if (context) { - return reinterpret_cast(context)->DisplayEventHandler(); - } - - return NULL; -} - -void *HWEventsDRM::DisplayEventHandler() { - char data[kMaxStringLength]{}; - - prctl(PR_SET_NAME, event_thread_name_.c_str(), 0, 0, 0); - setpriority(PRIO_PROCESS, 0, kThreadPriorityUrgent); - - while (!exit_threads_) { - int error = Sys::poll_(poll_fds_.data(), UINT32(poll_fds_.size()), -1); - if (error <= 0) { - DLOGW("poll failed. error = %s", strerror(errno)); - continue; - } - - for (uint32_t i = 0; i < event_data_list_.size(); i++) { - pollfd &poll_fd = poll_fds_[i]; - if (poll_fd.fd < 0) { - continue; - } - - switch (event_data_list_[i].event_type) { - case HWEvent::VSYNC: - case HWEvent::PANEL_DEAD: - case HWEvent::IDLE_NOTIFY: - case HWEvent::IDLE_POWER_COLLAPSE: - if (poll_fd.revents & (POLLIN | POLLPRI | POLLERR)) { - (this->*(event_data_list_[i]).event_parser)(nullptr); - } - break; - case HWEvent::EXIT: - if ((poll_fd.revents & POLLIN) && - (Sys::read_(poll_fd.fd, data, kMaxStringLength) > 0)) { - (this->*(event_data_list_[i]).event_parser)(data); - } - break; - case HWEvent::CEC_READ_MESSAGE: - case HWEvent::SHOW_BLANK_EVENT: - case HWEvent::THERMAL_LEVEL: - case HWEvent::PINGPONG_TIMEOUT: - if ((poll_fd.revents & POLLPRI) && - (Sys::pread_(poll_fd.fd, data, kMaxStringLength, 0) > 0)) { - (this->*(event_data_list_[i]).event_parser)(data); - } - break; - } - } - } - - pthread_exit(0); - - return nullptr; -} - -DisplayError HWEventsDRM::RegisterVSync() { - drmVBlank vblank {}; - uint32_t high_crtc = token_.crtc_index << DRM_VBLANK_HIGH_CRTC_SHIFT; - vblank.request.type = (drmVBlankSeqType)(DRM_VBLANK_RELATIVE | DRM_VBLANK_EVENT | - (high_crtc & DRM_VBLANK_HIGH_CRTC_MASK)); - vblank.request.sequence = 1; - // DRM hack to pass in context to unused field signal. Driver will write this to the node being - // polled on, and will be read as part of drm event handling and sent to handler - vblank.request.signal = reinterpret_cast(this); // NOLINT - int error = drmWaitVBlank(poll_fds_[vsync_index_].fd, &vblank); - if (error < 0) { - DLOGE("drmWaitVBlank failed with err %d", errno); - return kErrorResources; - } - - return kErrorNone; -} - -DisplayError HWEventsDRM::RegisterPanelDead(bool enable) { - uint32_t i = 0; - for (; i < event_data_list_.size(); i++) { - if (event_data_list_[i].event_type == HWEvent::PANEL_DEAD) { - break; - } - } - - if (i == event_data_list_.size()) { - DLOGI("panel dead is not supported event"); - return kErrorNone; - } - - struct drm_msm_event_req req = {}; - int ret = 0; - - req.object_id = token_.conn_id; - req.object_type = DRM_MODE_OBJECT_CONNECTOR; - req.event = DRM_EVENT_PANEL_DEAD; - if (enable) { - ret = drmIoctl(poll_fds_[panel_dead_index_].fd, DRM_IOCTL_MSM_REGISTER_EVENT, &req); - } else { - ret = drmIoctl(poll_fds_[panel_dead_index_].fd, DRM_IOCTL_MSM_DEREGISTER_EVENT, &req); - } - - if (ret) { - DLOGE("register panel dead enable:%d failed", enable); - return kErrorResources; - } - - return kErrorNone; -} - -DisplayError HWEventsDRM::RegisterIdleNotify(bool enable) { - uint32_t i = 0; - for (; i < event_data_list_.size(); i++) { - if (event_data_list_[i].event_type == HWEvent::IDLE_NOTIFY) { - break; - } - } - - if (i == event_data_list_.size()) { - DLOGI("idle notify is not supported event"); - return kErrorNone; - } - - struct drm_msm_event_req req = {}; - int ret = 0; - - req.object_id = token_.crtc_id; - req.object_type = DRM_MODE_OBJECT_CRTC; - req.event = DRM_EVENT_IDLE_NOTIFY; - if (enable) { - ret = drmIoctl(poll_fds_[idle_notify_index_].fd, DRM_IOCTL_MSM_REGISTER_EVENT, &req); - } else { - ret = drmIoctl(poll_fds_[idle_notify_index_].fd, DRM_IOCTL_MSM_DEREGISTER_EVENT, &req); - } - - if (ret) { - DLOGE("register idle notify enable:%d failed", enable); - return kErrorResources; - } - - return kErrorNone; -} - -DisplayError HWEventsDRM::RegisterIdlePowerCollapse(bool enable) { - uint32_t i = 0; - for (; i < event_data_list_.size(); i++) { - if (event_data_list_[i].event_type == HWEvent::IDLE_POWER_COLLAPSE) { - break; - } - } - - if (i == event_data_list_.size()) { - DLOGI("idle power collapse is not supported event"); - return kErrorNone; - } - - struct drm_msm_event_req req = {}; - int ret = 0; - - req.object_id = token_.crtc_id; - req.object_type = DRM_MODE_OBJECT_CRTC; - req.event = DRM_EVENT_SDE_POWER; - if (enable) { - ret = drmIoctl(poll_fds_[idle_pc_index_].fd, DRM_IOCTL_MSM_REGISTER_EVENT, &req); - } else { - ret = drmIoctl(poll_fds_[idle_pc_index_].fd, DRM_IOCTL_MSM_DEREGISTER_EVENT, &req); - } - - if (ret) { - DLOGE("register idle power collapse enable:%d failed", enable); - return kErrorResources; - } - - return kErrorNone; -} - -void HWEventsDRM::HandleVSync(char *data) { - drmEventContext event = {}; - event.version = DRM_EVENT_CONTEXT_VERSION; - event.vblank_handler = &HWEventsDRM::VSyncHandlerCallback; - int error = drmHandleEvent(poll_fds_[vsync_index_].fd, &event); - if (error != 0) { - DLOGE("drmHandleEvent failed: %i", error); - } - - std::lock_guard lock(vsync_mutex_); - vsync_registered_ = false; - if (vsync_enabled_) { - RegisterVSync(); - vsync_registered_ = true; - } -} - -void HWEventsDRM::HandlePanelDead(char *data) { - char event_data[kMaxStringLength] = {0}; - int32_t size; - struct drm_msm_event_resp *event_resp = NULL; - - size = (int32_t)Sys::pread_(poll_fds_[panel_dead_index_].fd, event_data, kMaxStringLength, 0); - if (size <= 0) { - return; - } - - if (size > kMaxStringLength) { - DLOGE("event size %d is greater than event buffer size %zd\n", size, kMaxStringLength); - return; - } - - if (size < (int32_t)sizeof(*event_resp)) { - DLOGE("Invalid event size %d expected %zd\n", size, sizeof(*event_resp)); - return; - } - - int32_t i = 0; - while (i < size) { - event_resp = (struct drm_msm_event_resp *)&event_data[i]; - switch (event_resp->base.type) { - case DRM_EVENT_PANEL_DEAD: - { - DLOGI("Received panel dead event"); - event_handler_->PanelDead(); - break; - } - default: { - DLOGE("invalid event %d", event_resp->base.type); - break; - } - } - i += event_resp->base.length; - } - - return; -} - -void HWEventsDRM::VSyncHandlerCallback(int fd, unsigned int sequence, unsigned int tv_sec, - unsigned int tv_usec, void *data) { - int64_t timestamp = (int64_t)(tv_sec)*1000000000 + (int64_t)(tv_usec)*1000; - reinterpret_cast(data)->event_handler_->VSync(timestamp); -} - -void HWEventsDRM::HandleIdleTimeout(char *data) { - char event_data[kMaxStringLength]; - int32_t size; - struct drm_msm_event_resp *event_resp = NULL; - - size = (int32_t)Sys::pread_(poll_fds_[idle_notify_index_].fd, event_data, kMaxStringLength, 0); - if (size < 0) { - return; - } - - if (size > kMaxStringLength) { - DLOGE("event size %d is greater than event buffer size %zd\n", size, kMaxStringLength); - return; - } - - if (size < (int32_t)sizeof(*event_resp)) { - DLOGE("size %d exp %zd\n", size, sizeof(*event_resp)); - return; - } - - int32_t i = 0; - - while (i < size) { - event_resp = (struct drm_msm_event_resp *)&event_data[i]; - switch (event_resp->base.type) { - case DRM_EVENT_IDLE_NOTIFY: - { - DLOGV("Received Idle time event"); - event_handler_->IdleTimeout(); - break; - } - default: { - DLOGE("invalid event %d", event_resp->base.type); - break; - } - } - i += event_resp->base.length; - } - - return; -} - -void HWEventsDRM::HandleCECMessage(char *data) { - event_handler_->CECMessage(data); -} - -void HWEventsDRM::HandleIdlePowerCollapse(char *data) { - char event_data[kMaxStringLength]; - int32_t size; - struct drm_msm_event_resp *event_resp = NULL; - - size = (int32_t)Sys::pread_(poll_fds_[idle_pc_index_].fd, event_data, kMaxStringLength, 0); - if (size < 0) { - return; - } - - if (size > kMaxStringLength) { - DLOGE("event size %d is greater than event buffer size %zd\n", size, kMaxStringLength); - return; - } - - if (size < (int32_t)sizeof(*event_resp)) { - DLOGE("size %d exp %zd\n", size, sizeof(*event_resp)); - return; - } - - int32_t i = 0; - - while (i < size) { - event_resp = (struct drm_msm_event_resp *)&event_data[i]; - switch (event_resp->base.type) { - case DRM_EVENT_SDE_POWER: - { - uint32_t* event_payload = reinterpret_cast(event_resp->data); - if (*event_payload == 0) { - DLOGV("Received Idle power collapse event"); - event_handler_->IdlePowerCollapse(); - } - break; - } - default: { - DLOGE("invalid event %d", event_resp->base.type); - break; - } - } - i += event_resp->base.length; - } - - return; -} - -} // namespace sdm diff --git a/sdm/libs/core/drm/hw_events_drm.h b/sdm/libs/core/drm/hw_events_drm.h deleted file mode 100644 index fafe606b..00000000 --- a/sdm/libs/core/drm/hw_events_drm.h +++ /dev/null @@ -1,109 +0,0 @@ -/* -* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __HW_EVENTS_DRM_H__ -#define __HW_EVENTS_DRM_H__ - -#include -#include -#include -#include -#include -#include -#include - -#include "hw_events_interface.h" -#include "hw_interface.h" -#include "hw_device_drm.h" - -namespace sdm { - -using std::vector; - -class HWEventsDRM : public HWEventsInterface { - public: - virtual DisplayError Init(int display_type, HWEventHandler *event_handler, - const vector &event_list, - const HWInterface *hw_intf); - virtual DisplayError Deinit(); - virtual DisplayError SetEventState(HWEvent event, bool enable, void *aux = nullptr); - - private: - static const int kMaxStringLength = 1024; - - typedef void (HWEventsDRM::*EventParser)(char *); - - struct HWEventData { - HWEvent event_type {}; - EventParser event_parser {}; - }; - - static void *DisplayEventThread(void *context); - static void VSyncHandlerCallback(int fd, unsigned int sequence, unsigned int tv_sec, - unsigned int tv_usec, void *data); - - void *DisplayEventHandler(); - void HandleVSync(char *data); - void HandleIdleTimeout(char *data); - void HandleCECMessage(char *data); - void HandleThreadExit(char *data) {} - void HandleThermal(char *data) {} - void HandleBlank(char *data) {} - void HandleIdlePowerCollapse(char *data); - void HandlePanelDead(char *data); - void PopulateHWEventData(const vector &event_list); - void WakeUpEventThread(); - DisplayError SetEventParser(); - DisplayError InitializePollFd(); - DisplayError CloseFds(); - DisplayError RegisterVSync(); - DisplayError RegisterPanelDead(bool enable); - DisplayError RegisterIdleNotify(bool enable); - DisplayError RegisterIdlePowerCollapse(bool enable); - - HWEventHandler *event_handler_{}; - vector event_data_list_{}; - vector poll_fds_{}; - pthread_t event_thread_{}; - std::string event_thread_name_ = "SDM_EventThread"; - bool exit_threads_ = false; - uint32_t vsync_index_ = 0; - bool vsync_enabled_ = false; - bool vsync_registered_ = false; - std::mutex vsync_mutex_; // To protect vsync_enabled_ and vsync_registered_ - uint32_t idle_notify_index_ = 0; - sde_drm::DRMDisplayToken token_ = {}; - bool is_primary_ = false; - uint32_t panel_dead_index_ = 0; - uint32_t idle_pc_index_ = 0; -}; - -} // namespace sdm - -#endif // __HW_EVENTS_DRM_H__ diff --git a/sdm/libs/core/drm/hw_info_drm.cpp b/sdm/libs/core/drm/hw_info_drm.cpp deleted file mode 100644 index 6469094d..00000000 --- a/sdm/libs/core/drm/hw_info_drm.cpp +++ /dev/null @@ -1,672 +0,0 @@ -/* -* Copyright (c) 2017 - 2018, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "hw_info_drm.h" - -#ifndef DRM_FORMAT_MOD_QCOM_COMPRESSED -#define DRM_FORMAT_MOD_QCOM_COMPRESSED fourcc_mod_code(QCOM, 1) -#endif -#ifndef DRM_FORMAT_MOD_QCOM_DX -#define DRM_FORMAT_MOD_QCOM_DX fourcc_mod_code(QCOM, 0x2) -#endif -#ifndef DRM_FORMAT_MOD_QCOM_TIGHT -#define DRM_FORMAT_MOD_QCOM_TIGHT fourcc_mod_code(QCOM, 0x4) -#endif - -#define __CLASS__ "HWInfoDRM" - -using drm_utils::DRMMaster; -using drm_utils::DRMResMgr; -using drm_utils::DRMLibLoader; -using sde_drm::GetDRMManager; -using sde_drm::DRMPlanesInfo; -using sde_drm::DRMCrtcInfo; -using sde_drm::DRMPlaneType; - -using std::vector; -using std::map; -using std::string; -using std::fstream; -using std::to_string; - -namespace sdm { - -static HWQseedStepVersion GetQseedStepVersion(sde_drm::QSEEDStepVersion drm_version) { - HWQseedStepVersion sdm_version; - switch (drm_version) { - case sde_drm::QSEEDStepVersion::V2: - default: - sdm_version = kQseed3v2; - break; - case sde_drm::QSEEDStepVersion::V3: - sdm_version = kQseed3v3; - break; - case sde_drm::QSEEDStepVersion::V4: - sdm_version = kQseed3v4; - break; - } - return sdm_version; -} - -HWResourceInfo *HWInfoDRM::hw_resource_ = nullptr; - -HWInfoDRM::HWInfoDRM() { - default_mode_ = (DRMLibLoader::GetInstance()->IsLoaded() == false); - if (!default_mode_) { - DRMMaster *drm_master = {}; - int dev_fd = -1; - DRMMaster::GetInstance(&drm_master); - if (!drm_master) { - DLOGE("Failed to acquire DRMMaster instance"); - return; - } - drm_master->GetHandle(&dev_fd); - DRMLibLoader::GetInstance()->FuncGetDRMManager()(dev_fd, &drm_mgr_intf_); - } -} - -HWInfoDRM::~HWInfoDRM() { - delete hw_resource_; - hw_resource_ = nullptr; - - if (drm_mgr_intf_) { - DRMLibLoader::GetInstance()->FuncDestroyDRMManager()(); - drm_mgr_intf_ = nullptr; - } - - DRMLibLoader::Destroy(); - DRMMaster::DestroyInstance(); -} - -DisplayError HWInfoDRM::GetDynamicBWLimits(HWResourceInfo *hw_resource) { - HWDynBwLimitInfo* bw_info = &hw_resource->dyn_bw_info; - for (int index = 0; index < kBwModeMax; index++) { - bw_info->total_bw_limit[index] = hw_resource->max_bandwidth_low; - bw_info->pipe_bw_limit[index] = hw_resource->max_pipe_bw; - } - - return kErrorNone; -} - -DisplayError HWInfoDRM::GetHWResourceInfo(HWResourceInfo *hw_resource) { - if (hw_resource_) { - *hw_resource = *hw_resource_; - return kErrorNone; - } - - hw_resource->num_blending_stages = 1; - hw_resource->max_pipe_width = 2560; - hw_resource->max_cursor_size = 128; - hw_resource->max_scale_down = 1; - hw_resource->max_scale_up = 1; - hw_resource->has_decimation = false; - hw_resource->max_bandwidth_low = 9600000; - hw_resource->max_bandwidth_high = 9600000; - hw_resource->max_pipe_bw = 4500000; - hw_resource->max_sde_clk = 412500000; - hw_resource->clk_fudge_factor = FLOAT(105) / FLOAT(100); - hw_resource->macrotile_nv12_factor = 8; - hw_resource->macrotile_factor = 4; - hw_resource->linear_factor = 1; - hw_resource->scale_factor = 1; - hw_resource->extra_fudge_factor = 2; - hw_resource->amortizable_threshold = 25; - hw_resource->system_overhead_lines = 0; - hw_resource->hw_dest_scalar_info.count = 0; - hw_resource->hw_dest_scalar_info.max_scale_up = 0; - hw_resource->hw_dest_scalar_info.max_input_width = 0; - hw_resource->hw_dest_scalar_info.max_output_width = 0; - hw_resource->is_src_split = true; - hw_resource->has_dyn_bw_support = false; - hw_resource->has_qseed3 = false; - hw_resource->has_concurrent_writeback = false; - - hw_resource->hw_version = SDEVERSION(4, 0, 1); - // TODO(user): On FB driver hw_revision comprises of major version, minor version and hw_revision. - // On DRM driver, hw_revision is deprecated and hw_version comprises major version, minor version - // and hw_revision information. Since QDCM uses hw_revision variable populate hw_revision with - // hw_version. Remove hw_revision variable when FB code is deperecated. - hw_resource->hw_revision = SDEVERSION(4, 0, 1); - - // TODO(user): Deprecate - hw_resource->max_mixer_width = 2560; - hw_resource->writeback_index = 0; - hw_resource->has_bwc = false; - hw_resource->has_ubwc = true; - hw_resource->has_macrotile = true; - hw_resource->separate_rotator = true; - hw_resource->has_non_scalar_rgb = false; - - GetSystemInfo(hw_resource); - GetHWPlanesInfo(hw_resource); - GetWBInfo(hw_resource); - - // Disable destination scalar count to 0 if extension library is not present or disabled - // through property - int value = 0; - bool disable_dest_scalar = false; - if (Debug::GetProperty(DISABLE_DESTINATION_SCALER_PROP, &value) == kErrorNone) { - disable_dest_scalar = (value == 1); - } - DynLib extension_lib; - if (!extension_lib.Open("libsdmextension.so") || disable_dest_scalar) { - hw_resource->hw_dest_scalar_info.count = 0; - } - - DLOGI("Max plane width = %d", hw_resource->max_pipe_width); - DLOGI("Max cursor width = %d", hw_resource->max_cursor_size); - DLOGI("Max plane upscale = %d", hw_resource->max_scale_up); - DLOGI("Max plane downscale = %d", hw_resource->max_scale_down); - DLOGI("Has Decimation = %d", hw_resource->has_decimation); - DLOGI("Max Blending Stages = %d", hw_resource->num_blending_stages); - DLOGI("Has Source Split = %d", hw_resource->is_src_split); - DLOGI("Has QSEED3 = %d", hw_resource->has_qseed3); - DLOGI("Has UBWC = %d", hw_resource->has_ubwc); - DLOGI("Has Concurrent Writeback = %d", hw_resource->has_concurrent_writeback); - DLOGI("Max Low Bw = %" PRIu64 "", hw_resource->max_bandwidth_low); - DLOGI("Max High Bw = % " PRIu64 "", hw_resource->max_bandwidth_high); - DLOGI("Max Pipe Bw = %" PRIu64 " KBps", hw_resource->max_pipe_bw); - DLOGI("MaxSDEClock = % " PRIu64 " Hz", hw_resource->max_sde_clk); - DLOGI("Clock Fudge Factor = %f", hw_resource->clk_fudge_factor); - DLOGI("Prefill factors:"); - DLOGI("\tTiled_NV12 = %d", hw_resource->macrotile_nv12_factor); - DLOGI("\tTiled = %d", hw_resource->macrotile_factor); - DLOGI("\tLinear = %d", hw_resource->linear_factor); - DLOGI("\tScale = %d", hw_resource->scale_factor); - DLOGI("\tFudge_factor = %d", hw_resource->extra_fudge_factor); - DLOGI("\tib_fudge_factor = %f", hw_resource->ib_fudge_factor); - - if (hw_resource->separate_rotator || hw_resource->num_dma_pipe) { - GetHWRotatorInfo(hw_resource); - } - - if (hw_resource->has_dyn_bw_support) { - DisplayError ret = GetDynamicBWLimits(hw_resource); - if (ret != kErrorNone) { - DLOGE("Failed to read dynamic band width info"); - return ret; - } - - DLOGI("Has Support for multiple bw limits shown below"); - for (int index = 0; index < kBwModeMax; index++) { - DLOGI("Mode-index=%d total_bw_limit=%d and pipe_bw_limit=%d", index, - hw_resource->dyn_bw_info.total_bw_limit[index], - hw_resource->dyn_bw_info.pipe_bw_limit[index]); - } - } - - if (!hw_resource_) { - hw_resource_ = new HWResourceInfo(); - *hw_resource_ = *hw_resource; - } - - return kErrorNone; -} - -void HWInfoDRM::GetSystemInfo(HWResourceInfo *hw_resource) { - DRMCrtcInfo info; - drm_mgr_intf_->GetCrtcInfo(0 /* system_info */, &info); - hw_resource->has_hdr = info.has_hdr; - hw_resource->is_src_split = info.has_src_split; - hw_resource->has_qseed3 = (info.qseed_version == sde_drm::QSEEDVersion::V3); - hw_resource->num_blending_stages = info.max_blend_stages; - hw_resource->num_solidfill_stages = info.max_solidfill_stages; - hw_resource->smart_dma_rev = (info.smart_dma_rev == sde_drm::SmartDMARevision::V2) ? - SmartDMARevision::V2 : SmartDMARevision::V1; - hw_resource->ib_fudge_factor = info.ib_fudge_factor; - hw_resource->hw_dest_scalar_info.prefill_lines = info.dest_scale_prefill_lines; - hw_resource->undersized_prefill_lines = info.undersized_prefill_lines; - hw_resource->macrotile_factor = info.macrotile_prefill_lines; - hw_resource->macrotile_nv12_factor = info.nv12_prefill_lines; - hw_resource->linear_factor = info.linear_prefill_lines; - hw_resource->scale_factor = info.downscale_prefill_lines; - hw_resource->extra_fudge_factor = info.extra_prefill_lines; - hw_resource->amortizable_threshold = info.amortized_threshold; - hw_resource->max_bandwidth_low = info.max_bandwidth_low / kKiloUnit; - hw_resource->max_bandwidth_high = info.max_bandwidth_high / kKiloUnit; - hw_resource->max_sde_clk = info.max_sde_clk; - hw_resource->hw_version = info.hw_version; - // TODO(user): On FB driver hw_revision comprises of major version, minor version and hw_revision. - // On DRM driver, hw_revision is deprecated and hw_version comprises major version, minor version - // and hw_revision information. Since QDCM uses hw_revision variable populate hw_revision with - // hw_version. Remove hw_revision variable when FB code is deperecated. - hw_resource->hw_revision = info.hw_version; - - std::vector sdm_format; - for (auto &it : info.comp_ratio_rt_map) { - std::pair drm_format = it.first; - GetSDMFormat(drm_format.first, drm_format.second, &sdm_format); - hw_resource->comp_ratio_rt_map.insert(std::make_pair(sdm_format[0], it.second)); - sdm_format.clear(); - } - - for (auto &it : info.comp_ratio_nrt_map) { - std::pair drm_format = it.first; - GetSDMFormat(drm_format.first, drm_format.second, &sdm_format); - hw_resource->comp_ratio_rt_map.insert(std::make_pair(sdm_format[0], it.second)); - sdm_format.clear(); - } - - hw_resource->hw_dest_scalar_info.count = info.dest_scaler_count; - hw_resource->hw_dest_scalar_info.max_scale_up = info.max_dest_scale_up; - hw_resource->hw_dest_scalar_info.max_input_width = info.max_dest_scaler_input_width; - hw_resource->hw_dest_scalar_info.max_output_width = info.max_dest_scaler_output_width; - hw_resource->min_prefill_lines = info.min_prefill_lines; -} - -void HWInfoDRM::GetHWPlanesInfo(HWResourceInfo *hw_resource) { - DRMPlanesInfo planes; - drm_mgr_intf_->GetPlanesInfo(&planes); - - // To simulate reduced config. - uint32_t max_vig_pipes = 0; - uint32_t max_dma_pipes = 0; - Debug::GetReducedConfig(&max_vig_pipes, &max_dma_pipes); - uint32_t max_virtual_pipes = max_vig_pipes + max_dma_pipes; - uint32_t vig_pipe_count = 0; - uint32_t dma_pipe_count = 0; - uint32_t virtual_pipe_count = 0; - - for (auto &pipe_obj : planes) { - if (max_vig_pipes && max_dma_pipes) { - uint32_t master_plane_id = pipe_obj.second.master_plane_id; - if ((pipe_obj.second.type == DRMPlaneType::DMA) && (dma_pipe_count < max_dma_pipes) - && !master_plane_id) { - dma_pipe_count++; - } else if ((pipe_obj.second.type == DRMPlaneType::VIG) && (vig_pipe_count < max_vig_pipes) - && !master_plane_id) { - vig_pipe_count++; - } else if ((master_plane_id) && (virtual_pipe_count < max_virtual_pipes)) { - bool is_virtual = false; - for (auto &pipe_caps : hw_resource->hw_pipes) { - if (master_plane_id == pipe_caps.id) { - is_virtual = true; - virtual_pipe_count++; - break; - } - } - if (!is_virtual) { - continue; - } - } else { - continue; - } - } - - HWPipeCaps pipe_caps; - string name = {}; - switch (pipe_obj.second.type) { - case DRMPlaneType::DMA: - name = "DMA"; - pipe_caps.type = kPipeTypeDMA; - if (!hw_resource->num_dma_pipe) { - PopulateSupportedFmts(kHWDMAPipe, pipe_obj.second, hw_resource); - } - hw_resource->num_dma_pipe++; - break; - case DRMPlaneType::VIG: - name = "VIG"; - pipe_caps.type = kPipeTypeVIG; - if (!hw_resource->num_vig_pipe) { - PopulatePipeCaps(pipe_obj.second, hw_resource); - PopulateSupportedFmts(kHWVIGPipe, pipe_obj.second, hw_resource); - } - hw_resource->num_vig_pipe++; - break; - case DRMPlaneType::CURSOR: - name = "CURSOR"; - pipe_caps.type = kPipeTypeCursor; - if (!hw_resource->num_cursor_pipe) { - PopulateSupportedFmts(kHWCursorPipe, pipe_obj.second, hw_resource); - hw_resource->max_cursor_size = pipe_obj.second.max_linewidth; - } - hw_resource->num_cursor_pipe++; - break; - default: - continue; // Not adding any other pipe type - } - pipe_caps.id = pipe_obj.first; - pipe_caps.master_pipe_id = pipe_obj.second.master_plane_id; - DLOGI("Adding %s Pipe : Id %x, master_pipe_id : Id %x", - name.c_str(), pipe_obj.first, pipe_obj.second.master_plane_id); - hw_resource->hw_pipes.push_back(std::move(pipe_caps)); - } -} - -void HWInfoDRM::PopulatePipeCaps(const sde_drm::DRMPlaneTypeInfo &info, - HWResourceInfo *hw_resource) { - hw_resource->max_pipe_width = info.max_linewidth; - hw_resource->max_scale_down = info.max_downscale; - hw_resource->max_scale_up = info.max_upscale; - hw_resource->has_decimation = info.max_horizontal_deci > 1 && info.max_vertical_deci > 1; - hw_resource->max_pipe_bw = info.max_pipe_bandwidth / kKiloUnit; - hw_resource->cache_size = info.cache_size; - hw_resource->pipe_qseed3_version = GetQseedStepVersion(info.qseed3_version); -} - -void HWInfoDRM::PopulateSupportedFmts(HWSubBlockType sub_blk_type, - const sde_drm::DRMPlaneTypeInfo &info, - HWResourceInfo *hw_resource) { - vector sdm_formats; - FormatsMap &fmts_map = hw_resource->supported_formats_map; - - if (fmts_map.find(sub_blk_type) == fmts_map.end()) { - for (auto &fmts : info.formats_supported) { - GetSDMFormat(fmts.first, fmts.second, &sdm_formats); - } - - fmts_map.insert(make_pair(sub_blk_type, sdm_formats)); - } -} - -void HWInfoDRM::GetWBInfo(HWResourceInfo *hw_resource) { - HWSubBlockType sub_blk_type = kHWWBIntfOutput; - vector supported_sdm_formats; - sde_drm::DRMDisplayToken token; - - // Fake register - if (drm_mgr_intf_->RegisterDisplay(sde_drm::DRMDisplayType::VIRTUAL, &token)) { - return; - } - - sde_drm::DRMConnectorInfo connector_info; - drm_mgr_intf_->GetConnectorInfo(token.conn_id, &connector_info); - for (auto &fmts : connector_info.formats_supported) { - GetSDMFormat(fmts.first, fmts.second, &supported_sdm_formats); - } - - hw_resource->supported_formats_map.erase(sub_blk_type); - hw_resource->supported_formats_map.insert(make_pair(sub_blk_type, supported_sdm_formats)); - - drm_mgr_intf_->UnregisterDisplay(token); -} - -void HWInfoDRM::GetSDMFormat(uint32_t v4l2_format, LayerBufferFormat *sdm_format) { - switch (v4l2_format) { - case SDE_PIX_FMT_ARGB_8888: *sdm_format = kFormatARGB8888; break; - case SDE_PIX_FMT_RGBA_8888: *sdm_format = kFormatRGBA8888; break; - case SDE_PIX_FMT_BGRA_8888: *sdm_format = kFormatBGRA8888; break; - case SDE_PIX_FMT_RGBX_8888: *sdm_format = kFormatRGBX8888; break; - case SDE_PIX_FMT_BGRX_8888: *sdm_format = kFormatBGRX8888; break; - case SDE_PIX_FMT_RGBA_5551: *sdm_format = kFormatRGBA5551; break; - case SDE_PIX_FMT_RGBA_4444: *sdm_format = kFormatRGBA4444; break; - case SDE_PIX_FMT_RGB_888: *sdm_format = kFormatRGB888; break; - case SDE_PIX_FMT_BGR_888: *sdm_format = kFormatBGR888; break; - case SDE_PIX_FMT_RGB_565: *sdm_format = kFormatRGB565; break; - case SDE_PIX_FMT_BGR_565: *sdm_format = kFormatBGR565; break; - case SDE_PIX_FMT_Y_CB_CR_H2V2: *sdm_format = kFormatYCbCr420Planar; break; - case SDE_PIX_FMT_Y_CR_CB_H2V2: *sdm_format = kFormatYCrCb420Planar; break; - case SDE_PIX_FMT_Y_CR_CB_GH2V2: *sdm_format = kFormatYCrCb420PlanarStride16; break; - case SDE_PIX_FMT_Y_CBCR_H2V2: *sdm_format = kFormatYCbCr420SemiPlanar; break; - case SDE_PIX_FMT_Y_CRCB_H2V2: *sdm_format = kFormatYCrCb420SemiPlanar; break; - case SDE_PIX_FMT_Y_CBCR_H1V2: *sdm_format = kFormatYCbCr422H1V2SemiPlanar; break; - case SDE_PIX_FMT_Y_CRCB_H1V2: *sdm_format = kFormatYCrCb422H1V2SemiPlanar; break; - case SDE_PIX_FMT_Y_CBCR_H2V1: *sdm_format = kFormatYCbCr422H2V1SemiPlanar; break; - case SDE_PIX_FMT_Y_CRCB_H2V1: *sdm_format = kFormatYCrCb422H2V1SemiPlanar; break; - case SDE_PIX_FMT_YCBYCR_H2V1: *sdm_format = kFormatYCbCr422H2V1Packed; break; - case SDE_PIX_FMT_Y_CBCR_H2V2_VENUS: *sdm_format = kFormatYCbCr420SemiPlanarVenus; break; - case SDE_PIX_FMT_Y_CRCB_H2V2_VENUS: *sdm_format = kFormatYCrCb420SemiPlanarVenus; break; - case SDE_PIX_FMT_RGBA_8888_UBWC: *sdm_format = kFormatRGBA8888Ubwc; break; - case SDE_PIX_FMT_RGBX_8888_UBWC: *sdm_format = kFormatRGBX8888Ubwc; break; - case SDE_PIX_FMT_RGB_565_UBWC: *sdm_format = kFormatBGR565Ubwc; break; - case SDE_PIX_FMT_Y_CBCR_H2V2_UBWC: *sdm_format = kFormatYCbCr420SPVenusUbwc; break; - case SDE_PIX_FMT_RGBA_1010102: *sdm_format = kFormatRGBA1010102; break; - case SDE_PIX_FMT_ARGB_2101010: *sdm_format = kFormatARGB2101010; break; - case SDE_PIX_FMT_RGBX_1010102: *sdm_format = kFormatRGBX1010102; break; - case SDE_PIX_FMT_XRGB_2101010: *sdm_format = kFormatXRGB2101010; break; - case SDE_PIX_FMT_BGRA_1010102: *sdm_format = kFormatBGRA1010102; break; - case SDE_PIX_FMT_ABGR_2101010: *sdm_format = kFormatABGR2101010; break; - case SDE_PIX_FMT_BGRX_1010102: *sdm_format = kFormatBGRX1010102; break; - case SDE_PIX_FMT_XBGR_2101010: *sdm_format = kFormatXBGR2101010; break; - case SDE_PIX_FMT_RGBA_1010102_UBWC: *sdm_format = kFormatRGBA1010102Ubwc; break; - case SDE_PIX_FMT_RGBX_1010102_UBWC: *sdm_format = kFormatRGBX1010102Ubwc; break; - case SDE_PIX_FMT_Y_CBCR_H2V2_P010: *sdm_format = kFormatYCbCr420P010; break; - case SDE_PIX_FMT_Y_CBCR_H2V2_TP10_UBWC: *sdm_format = kFormatYCbCr420TP10Ubwc; break; - case SDE_PIX_FMT_Y_CBCR_H2V2_P010_UBWC: *sdm_format = kFormatYCbCr420P010Ubwc; break; - case SDE_PIX_FMT_Y_CBCR_H2V2_P010_VENUS: *sdm_format = kFormatYCbCr420P010Venus; break; - default: *sdm_format = kFormatInvalid; - } -} - -void HWInfoDRM::GetRotatorFormatsForType(int fd, uint32_t type, - vector *supported_formats) { - struct v4l2_fmtdesc fmtdesc = {}; - fmtdesc.type = type; - while (!Sys::ioctl_(fd, static_cast(VIDIOC_ENUM_FMT), &fmtdesc)) { - LayerBufferFormat sdm_format = kFormatInvalid; - GetSDMFormat(fmtdesc.pixelformat, &sdm_format); - if (sdm_format != kFormatInvalid) { - supported_formats->push_back(sdm_format); - } - fmtdesc.index++; - } -} - -DisplayError HWInfoDRM::GetRotatorSupportedFormats(uint32_t v4l2_index, - HWResourceInfo *hw_resource) { - string path = "/dev/video" + to_string(v4l2_index); - int fd = Sys::open_(path.c_str(), O_RDONLY); - if (fd < 0) { - DLOGE("Failed to open %s with error %d", path.c_str(), errno); - return kErrorNotSupported; - } - - vector supported_formats = {}; - GetRotatorFormatsForType(fd, V4L2_BUF_TYPE_VIDEO_OUTPUT, &supported_formats); - hw_resource->supported_formats_map.erase(kHWRotatorInput); - hw_resource->supported_formats_map.insert(make_pair(kHWRotatorInput, supported_formats)); - - supported_formats = {}; - GetRotatorFormatsForType(fd, V4L2_BUF_TYPE_VIDEO_CAPTURE, &supported_formats); - hw_resource->supported_formats_map.erase(kHWRotatorOutput); - hw_resource->supported_formats_map.insert(make_pair(kHWRotatorOutput, supported_formats)); - - Sys::close_(fd); - - return kErrorNone; -} - -DisplayError HWInfoDRM::GetHWRotatorInfo(HWResourceInfo *hw_resource) { - string v4l2_path = "/sys/class/video4linux/video"; - const uint32_t kMaxV4L2Nodes = 64; - - for (uint32_t i = 0; i < kMaxV4L2Nodes; i++) { - string path = v4l2_path + to_string(i) + "/name"; - Sys::fstream fs(path, fstream::in); - if (!fs.is_open()) { - continue; - } - - string line; - if (Sys::getline_(fs, line) && (!strncmp(line.c_str(), "sde_rotator", strlen("sde_rotator")))) { - hw_resource->hw_rot_info.device_path = string("/dev/video" + to_string(i)); - hw_resource->hw_rot_info.num_rotator++; - hw_resource->hw_rot_info.type = HWRotatorInfo::ROT_TYPE_V4L2; - hw_resource->hw_rot_info.has_downscale = true; - GetRotatorSupportedFormats(i, hw_resource); - - string caps_path = v4l2_path + to_string(i) + "/device/caps"; - Sys::fstream caps_fs(caps_path, fstream::in); - - if (caps_fs.is_open()) { - string caps; - while (Sys::getline_(caps_fs, caps)) { - const string downscale_compression = "downscale_compression="; - const string min_downscale = "min_downscale="; - if (caps.find(downscale_compression) != string::npos) { - hw_resource->hw_rot_info.downscale_compression = - std::stoi(string(caps, downscale_compression.length())); - } else if (caps.find(min_downscale) != string::npos) { - hw_resource->hw_rot_info.min_downscale = - std::stof(string(caps, min_downscale.length())); - } - } - } - - // We support only 1 rotator - break; - } - } - - DLOGI("V4L2 Rotator: Count = %d, Downscale = %d, Min_downscale = %f, Downscale_compression = %d", - hw_resource->hw_rot_info.num_rotator, hw_resource->hw_rot_info.has_downscale, - hw_resource->hw_rot_info.min_downscale, hw_resource->hw_rot_info.downscale_compression); - - return kErrorNone; -} - -void HWInfoDRM::GetSDMFormat(uint32_t drm_format, uint64_t drm_format_modifier, - vector *sdm_formats) { - vector &fmts(*sdm_formats); - switch (drm_format) { - case DRM_FORMAT_BGRA8888: - fmts.push_back(kFormatARGB8888); - break; - case DRM_FORMAT_ABGR8888: - fmts.push_back(drm_format_modifier ? kFormatRGBA8888Ubwc : kFormatRGBA8888); - break; - case DRM_FORMAT_ARGB8888: - fmts.push_back(kFormatBGRA8888); - break; - case DRM_FORMAT_BGRX8888: - fmts.push_back(kFormatXRGB8888); - break; - case DRM_FORMAT_XBGR8888: - fmts.push_back(drm_format_modifier ? kFormatRGBX8888Ubwc : kFormatRGBX8888); - break; - case DRM_FORMAT_XRGB8888: - fmts.push_back(kFormatBGRX8888); - break; - case DRM_FORMAT_ABGR1555: - fmts.push_back(kFormatRGBA5551); - break; - case DRM_FORMAT_ABGR4444: - fmts.push_back(kFormatRGBA4444); - break; - case DRM_FORMAT_BGR888: - fmts.push_back(kFormatRGB888); - break; - case DRM_FORMAT_RGB888: - fmts.push_back(kFormatBGR888); - break; - case DRM_FORMAT_BGR565: - fmts.push_back(drm_format_modifier ? kFormatBGR565Ubwc : kFormatRGB565); - break; - case DRM_FORMAT_RGB565: - fmts.push_back(kFormatBGR565); - break; - case DRM_FORMAT_ABGR2101010: - fmts.push_back(drm_format_modifier ? kFormatRGBA1010102Ubwc : kFormatRGBA1010102); - break; - case DRM_FORMAT_BGRA1010102: - fmts.push_back(kFormatARGB2101010); - break; - case DRM_FORMAT_XBGR2101010: - fmts.push_back(drm_format_modifier ? kFormatRGBX1010102Ubwc : kFormatRGBX1010102); - break; - case DRM_FORMAT_BGRX1010102: - fmts.push_back(kFormatXRGB2101010); - break; - case DRM_FORMAT_ARGB2101010: - fmts.push_back(kFormatBGRA1010102); - break; - case DRM_FORMAT_RGBA1010102: - fmts.push_back(kFormatABGR2101010); - break; - case DRM_FORMAT_XRGB2101010: - fmts.push_back(kFormatBGRX1010102); - break; - case DRM_FORMAT_RGBX1010102: - fmts.push_back(kFormatXBGR2101010); - break; - case DRM_FORMAT_YVU420: - fmts.push_back(kFormatYCrCb420PlanarStride16); - break; - case DRM_FORMAT_NV12: - if (drm_format_modifier == (DRM_FORMAT_MOD_QCOM_COMPRESSED | - DRM_FORMAT_MOD_QCOM_DX | DRM_FORMAT_MOD_QCOM_TIGHT)) { - fmts.push_back(kFormatYCbCr420TP10Ubwc); - } else if (drm_format_modifier == (DRM_FORMAT_MOD_QCOM_COMPRESSED | - DRM_FORMAT_MOD_QCOM_DX)) { - fmts.push_back(kFormatYCbCr420P010Ubwc); - } else if (drm_format_modifier == DRM_FORMAT_MOD_QCOM_COMPRESSED) { - fmts.push_back(kFormatYCbCr420SPVenusUbwc); - } else if (drm_format_modifier == DRM_FORMAT_MOD_QCOM_DX) { - fmts.push_back(kFormatYCbCr420P010); - fmts.push_back(kFormatYCbCr420P010Venus); - } else { - fmts.push_back(kFormatYCbCr420SemiPlanarVenus); - fmts.push_back(kFormatYCbCr420SemiPlanar); - } - break; - case DRM_FORMAT_NV21: - fmts.push_back(kFormatYCrCb420SemiPlanarVenus); - fmts.push_back(kFormatYCrCb420SemiPlanar); - break; - case DRM_FORMAT_NV16: - fmts.push_back(kFormatYCbCr422H2V1SemiPlanar); - break; - default: - break; - } -} - -DisplayError HWInfoDRM::GetFirstDisplayInterfaceType(HWDisplayInterfaceInfo *hw_disp_info) { - hw_disp_info->type = kPrimary; - hw_disp_info->is_connected = true; - - return kErrorNone; -} - -} // namespace sdm diff --git a/sdm/libs/core/drm/hw_info_drm.h b/sdm/libs/core/drm/hw_info_drm.h deleted file mode 100644 index 82fb1755..00000000 --- a/sdm/libs/core/drm/hw_info_drm.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -* Copyright (c) 2017, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __HW_INFO_DRM_H__ -#define __HW_INFO_DRM_H__ - -#include -#include -#include -#include -#include -#include - -#include "hw_info_interface.h" - -namespace sdm { - -class HWInfoDRM: public HWInfoInterface { - public: - HWInfoDRM(); - virtual ~HWInfoDRM(); - virtual DisplayError GetHWResourceInfo(HWResourceInfo *hw_resource); - virtual DisplayError GetFirstDisplayInterfaceType(HWDisplayInterfaceInfo *hw_disp_info); - - private: - DisplayError GetHWRotatorInfo(HWResourceInfo *hw_resource); - void GetSystemInfo(HWResourceInfo *hw_resource); - void GetHWPlanesInfo(HWResourceInfo *hw_resource); - void GetWBInfo(HWResourceInfo *hw_resource); - DisplayError GetDynamicBWLimits(HWResourceInfo *hw_resource); - void GetSDMFormat(uint32_t drm_format, uint64_t drm_format_modifier, - std::vector *sdm_formats); - void GetSDMFormat(uint32_t v4l2_format, LayerBufferFormat *sdm_format); - void GetRotatorFormatsForType(int fd, uint32_t type, - std::vector *supported_formats); - DisplayError GetRotatorSupportedFormats(uint32_t v4l2_index, HWResourceInfo *hw_resource); - void PopulateSupportedFmts(HWSubBlockType sub_blk_type, const sde_drm::DRMPlaneTypeInfo &info, - HWResourceInfo *hw_resource); - void PopulatePipeCaps(const sde_drm::DRMPlaneTypeInfo &info, HWResourceInfo *hw_resource); - - sde_drm::DRMManagerInterface *drm_mgr_intf_ = {}; - bool default_mode_ = false; - - static const int kMaxStringLength = 1024; - static const int kKiloUnit = 1000; - - static HWResourceInfo *hw_resource_; -}; - -} // namespace sdm - -#endif // __HW_INFO_DRM_H__ diff --git a/sdm/libs/core/drm/hw_peripheral_drm.cpp b/sdm/libs/core/drm/hw_peripheral_drm.cpp deleted file mode 100644 index 44c22e79..00000000 --- a/sdm/libs/core/drm/hw_peripheral_drm.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/* -Copyright (c) 2017, The Linux Foundation. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials provided - with the distribution. - * Neither the name of The Linux Foundation nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include - -#include "hw_peripheral_drm.h" - -#define __CLASS__ "HWPeripheralDRM" - -using sde_drm::DRMDisplayType; -using sde_drm::DRMOps; -using sde_drm::DRMPowerMode; - -namespace sdm { - -HWPeripheralDRM::HWPeripheralDRM(BufferSyncHandler *buffer_sync_handler, - BufferAllocator *buffer_allocator, - HWInfoInterface *hw_info_intf) - : HWDeviceDRM(buffer_sync_handler, buffer_allocator, hw_info_intf) { - disp_type_ = DRMDisplayType::PERIPHERAL; - device_name_ = "Peripheral Display"; -} - -DisplayError HWPeripheralDRM::Init() { - DisplayError ret = HWDeviceDRM::Init(); - if (ret != kErrorNone) { - DLOGE("Init failed for %s", device_name_); - return ret; - } - - scalar_data_.resize(hw_resource_.hw_dest_scalar_info.count); - - return kErrorNone; -} - -DisplayError HWPeripheralDRM::Validate(HWLayers *hw_layers) { - HWLayersInfo &hw_layer_info = hw_layers->info; - SetDestScalarData(hw_layer_info); - - return HWDeviceDRM::Validate(hw_layers); -} - -DisplayError HWPeripheralDRM::Commit(HWLayers *hw_layers) { - HWLayersInfo &hw_layer_info = hw_layers->info; - SetDestScalarData(hw_layer_info); - - return HWDeviceDRM::Commit(hw_layers); -} - -void HWPeripheralDRM::ResetDisplayParams() { - sde_dest_scalar_data_ = {}; - for (uint32_t j = 0; j < scalar_data_.size(); j++) { - scalar_data_[j] = {}; - } -} - -void HWPeripheralDRM::SetDestScalarData(HWLayersInfo hw_layer_info) { - if (!hw_resource_.hw_dest_scalar_info.count) { - return; - } - - uint32_t index = 0; - for (uint32_t i = 0; i < hw_resource_.hw_dest_scalar_info.count; i++) { - DestScaleInfoMap::iterator it = hw_layer_info.dest_scale_info_map.find(i); - - if (it == hw_layer_info.dest_scale_info_map.end()) { - continue; - } - - HWDestScaleInfo *dest_scale_info = it->second; - SDEScaler *scale = &scalar_data_[index]; - hw_scale_->SetScaler(dest_scale_info->scale_data, scale); - sde_drm_dest_scaler_cfg *dest_scalar_data = &sde_dest_scalar_data_.ds_cfg[index]; - dest_scalar_data->flags = 0; - if (scale->scaler_v2.enable) { - dest_scalar_data->flags |= SDE_DRM_DESTSCALER_ENABLE; - } - if (scale->scaler_v2.de.enable) { - dest_scalar_data->flags |= SDE_DRM_DESTSCALER_ENHANCER_UPDATE; - } - if (dest_scale_info->scale_update) { - dest_scalar_data->flags |= SDE_DRM_DESTSCALER_SCALE_UPDATE; - } - dest_scalar_data->index = i; - dest_scalar_data->lm_width = dest_scale_info->mixer_width; - dest_scalar_data->lm_height = dest_scale_info->mixer_height; - dest_scalar_data->scaler_cfg = reinterpret_cast(&scale->scaler_v2); - if (hw_panel_info_.partial_update) { - dest_scalar_data->flags |= SDE_DRM_DESTSCALER_PU_ENABLE; - } - index++; - } - sde_dest_scalar_data_.num_dest_scaler = UINT32(hw_layer_info.dest_scale_info_map.size()); - drm_atomic_intf_->Perform(DRMOps::CRTC_SET_DEST_SCALER_CONFIG, token_.crtc_id, - reinterpret_cast(&sde_dest_scalar_data_)); -} - -DisplayError HWPeripheralDRM::Flush() { - DisplayError err = HWDeviceDRM::Flush(); - if (err != kErrorNone) { - return err; - } - - ResetDisplayParams(); - return kErrorNone; -} - - -} // namespace sdm diff --git a/sdm/libs/core/drm/hw_peripheral_drm.h b/sdm/libs/core/drm/hw_peripheral_drm.h deleted file mode 100644 index e4b33cf3..00000000 --- a/sdm/libs/core/drm/hw_peripheral_drm.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -Copyright (c) 2017, The Linux Foundation. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials provided - with the distribution. - * Neither the name of The Linux Foundation nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __HW_PERIPHERAL_DRM_H__ -#define __HW_PERIPHERAL_DRM_H__ - -#include -#include "hw_device_drm.h" - -namespace sdm { - -class HWPeripheralDRM : public HWDeviceDRM { - public: - explicit HWPeripheralDRM(BufferSyncHandler *buffer_sync_handler, - BufferAllocator *buffer_allocator, - HWInfoInterface *hw_info_intf); - virtual ~HWPeripheralDRM() {} - - protected: - virtual DisplayError Init(); - virtual DisplayError Validate(HWLayers *hw_layers); - virtual DisplayError Commit(HWLayers *hw_layers); - virtual DisplayError Flush(); - private: - void SetDestScalarData(HWLayersInfo hw_layer_info); - void ResetDisplayParams(); - sde_drm_dest_scaler_data sde_dest_scalar_data_ = {}; - std::vector scalar_data_ = {}; -}; - -} // namespace sdm - -#endif // __HW_PERIPHERAL_DRM_H__ diff --git a/sdm/libs/core/drm/hw_scale_drm.cpp b/sdm/libs/core/drm/hw_scale_drm.cpp deleted file mode 100644 index b2f6d3bd..00000000 --- a/sdm/libs/core/drm/hw_scale_drm.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/* -* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include -#include - -#include "hw_scale_drm.h" - -#define __CLASS__ "HWScaleDRM" - -namespace sdm { - -static uint32_t GetScalingFilter(ScalingFilterConfig filter_cfg) { - switch (filter_cfg) { - case kFilterEdgeDirected: - return FILTER_EDGE_DIRECTED_2D; - case kFilterCircular: - return FILTER_CIRCULAR_2D; - case kFilterSeparable: - return FILTER_SEPARABLE_1D; - case kFilterBilinear: - return FILTER_BILINEAR; - default: - DLOGE("Invalid Scaling Filter"); - return kFilterMax; - } -} - -static uint32_t GetAlphaInterpolation(HWAlphaInterpolation alpha_filter_cfg) { - switch (alpha_filter_cfg) { - case kInterpolationPixelRepeat: - return FILTER_ALPHA_DROP_REPEAT; - case kInterpolationBilinear: - return FILTER_ALPHA_BILINEAR; - case kInterpolation2D: - return FILTER_ALPHA_2D; - default: - DLOGE("Invalid Alpha Interpolation"); - return kInterpolationMax; - } -} - -void HWScaleDRM::SetScaler(const HWScaleData &scale_data, SDEScaler *scaler) { - if (version_ == Version::V2) { - SetScalerV2(scale_data, &scaler->scaler_v2); - } -} - -void HWScaleDRM::SetScalerV2(const HWScaleData &scale_data, sde_drm_scaler_v2 *scaler) { - if (!scale_data.enable.scale && !scale_data.enable.direction_detection && - !scale_data.enable.detail_enhance) { - scaler->enable = 0; - scaler->dir_en = 0; - scaler->de.enable = 0; - return; - } - - scaler->enable = scale_data.enable.scale | scale_data.enable.direction_detection | - scale_data.detail_enhance.enable; - - scaler->dir_en = scale_data.enable.direction_detection; - scaler->de.enable = scale_data.detail_enhance.enable; - - for (int i = 0; i < SDE_MAX_PLANES; i++) { - const HWPlane &plane = scale_data.plane[i]; - scaler->init_phase_x[i] = plane.init_phase_x; - scaler->phase_step_x[i] = plane.phase_step_x; - scaler->init_phase_y[i] = plane.init_phase_y; - scaler->phase_step_y[i] = plane.phase_step_y; - - // TODO(user): Remove right, bottom from HWPlane and rename to LR, TB similar to qseed3 - // Also remove roi_width which is unused. - scaler->pe.num_ext_pxls_lr[i] = plane.left.extension; - scaler->pe.num_ext_pxls_tb[i] = plane.top.extension; - - scaler->pe.left_ftch[i] = plane.left.overfetch; - scaler->pe.top_ftch[i] = plane.top.overfetch; - scaler->pe.right_ftch[i] = plane.right.overfetch; - scaler->pe.btm_ftch[i] = plane.bottom.overfetch; - - scaler->pe.left_rpt[i] = plane.left.repeat; - scaler->pe.top_rpt[i] = plane.top.repeat; - scaler->pe.right_rpt[i] = plane.right.repeat; - scaler->pe.btm_rpt[i] = plane.bottom.repeat; - - scaler->preload_x[i] = UINT32(plane.preload_x); - scaler->preload_y[i] = UINT32(plane.preload_y); - - scaler->src_width[i] = plane.src_width; - scaler->src_height[i] = plane.src_height; - } - - scaler->dst_width = scale_data.dst_width; - scaler->dst_height = scale_data.dst_height; - - scaler->y_rgb_filter_cfg = GetScalingFilter(scale_data.y_rgb_filter_cfg); - scaler->uv_filter_cfg = GetScalingFilter(scale_data.uv_filter_cfg); - scaler->alpha_filter_cfg = GetAlphaInterpolation(scale_data.alpha_filter_cfg); - scaler->blend_cfg = scale_data.blend_cfg; - - scaler->lut_flag = (scale_data.lut_flag.lut_swap ? SCALER_LUT_SWAP : 0) | - (scale_data.lut_flag.lut_dir_wr ? SCALER_LUT_DIR_WR : 0) | - (scale_data.lut_flag.lut_y_cir_wr ? SCALER_LUT_Y_CIR_WR : 0) | - (scale_data.lut_flag.lut_uv_cir_wr ? SCALER_LUT_UV_CIR_WR : 0) | - (scale_data.lut_flag.lut_y_sep_wr ? SCALER_LUT_Y_SEP_WR : 0) | - (scale_data.lut_flag.lut_uv_sep_wr ? SCALER_LUT_UV_SEP_WR : 0); - - scaler->dir_lut_idx = scale_data.dir_lut_idx; - scaler->y_rgb_cir_lut_idx = scale_data.y_rgb_cir_lut_idx; - scaler->uv_cir_lut_idx = scale_data.uv_cir_lut_idx; - scaler->y_rgb_sep_lut_idx = scale_data.y_rgb_sep_lut_idx; - scaler->uv_sep_lut_idx = scale_data.uv_sep_lut_idx; - - if (scaler->de.enable) { - sde_drm_de_v1 *det_enhance = &scaler->de; - det_enhance->sharpen_level1 = scale_data.detail_enhance.sharpen_level1; - det_enhance->sharpen_level2 = scale_data.detail_enhance.sharpen_level2; - det_enhance->clip = scale_data.detail_enhance.clip; - det_enhance->limit = scale_data.detail_enhance.limit; - det_enhance->thr_quiet = scale_data.detail_enhance.thr_quiet; - det_enhance->thr_dieout = scale_data.detail_enhance.thr_dieout; - det_enhance->thr_low = scale_data.detail_enhance.thr_low; - det_enhance->thr_high = scale_data.detail_enhance.thr_high; - det_enhance->prec_shift = scale_data.detail_enhance.prec_shift; - - for (int i = 0; i < SDE_MAX_DE_CURVES; i++) { - det_enhance->adjust_a[i] = scale_data.detail_enhance.adjust_a[i]; - det_enhance->adjust_b[i] = scale_data.detail_enhance.adjust_b[i]; - det_enhance->adjust_c[i] = scale_data.detail_enhance.adjust_c[i]; - } - } - - return; -} - -} // namespace sdm diff --git a/sdm/libs/core/drm/hw_scale_drm.h b/sdm/libs/core/drm/hw_scale_drm.h deleted file mode 100644 index 6f96ecaf..00000000 --- a/sdm/libs/core/drm/hw_scale_drm.h +++ /dev/null @@ -1,62 +0,0 @@ -/* -* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __HW_SCALE_DRM_H__ -#define __HW_SCALE_DRM_H__ - -#include -#include -#include -// The 3 headers above are a workaround to prevent kernel drm.h from being used that has the -// "virtual" keyword used for a variable. In future replace libdrm version drm.h with kernel -// version drm/drm.h -#include -#include - -namespace sdm { - -struct SDEScaler { - struct sde_drm_scaler_v2 scaler_v2 = {}; - // More here, maybe in a union -}; - -class HWScaleDRM { - public: - enum class Version { V2 }; - explicit HWScaleDRM(Version v) : version_(v) {} - void SetScaler(const HWScaleData &scale, SDEScaler *scaler); - - private: - void SetScalerV2(const HWScaleData &scale, sde_drm_scaler_v2 *scaler_v2); - Version version_ = Version::V2; -}; - -} // namespace sdm - -#endif // __HW_SCALE_DRM_H__ diff --git a/sdm/libs/core/drm/hw_tv_drm.cpp b/sdm/libs/core/drm/hw_tv_drm.cpp deleted file mode 100644 index adf1f1ea..00000000 --- a/sdm/libs/core/drm/hw_tv_drm.cpp +++ /dev/null @@ -1,321 +0,0 @@ -/* -* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include "hw_tv_drm.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifndef HDR_EOTF_SMTPE_ST2084 -#define HDR_EOTF_SMTPE_ST2084 2 -#endif -#ifndef HDR_EOTF_HLG -#define HDR_EOTF_HLG 3 -#endif - -#define __CLASS__ "HWTVDRM" - -#define HDR_DISABLE 0 -#define HDR_ENABLE 1 -#define MIN_HDR_RESET_WAITTIME 2 - -using drm_utils::DRMMaster; -using drm_utils::DRMResMgr; -using drm_utils::DRMLibLoader; -using drm_utils::DRMBuffer; -using sde_drm::GetDRMManager; -using sde_drm::DestroyDRMManager; -using sde_drm::DRMDisplayType; -using sde_drm::DRMDisplayToken; -using sde_drm::DRMConnectorInfo; -using sde_drm::DRMPPFeatureInfo; -using sde_drm::DRMOps; -using sde_drm::DRMTopology; -using sde_drm::DRMPowerMode; - -namespace sdm { - -static int32_t GetEOTF(const GammaTransfer &transfer) { - int32_t hdr_transfer = -1; - - switch (transfer) { - case Transfer_SMPTE_ST2084: - hdr_transfer = HDR_EOTF_SMTPE_ST2084; - break; - case Transfer_HLG: - hdr_transfer = HDR_EOTF_HLG; - break; - default: - DLOGW("Unknown Transfer: %d", transfer); - } - - return hdr_transfer; -} - -HWTVDRM::HWTVDRM(BufferSyncHandler *buffer_sync_handler, BufferAllocator *buffer_allocator, - HWInfoInterface *hw_info_intf) - : HWDeviceDRM(buffer_sync_handler, buffer_allocator, hw_info_intf) { - disp_type_ = DRMDisplayType::TV; - device_name_ = "TV Display Device"; -} - -DisplayError HWTVDRM::SetDisplayAttributes(uint32_t index) { - if (index >= connector_info_.modes.size()) { - DLOGE("Invalid mode index %d mode size %d", index, UINT32(connector_info_.modes.size())); - return kErrorNotSupported; - } - - current_mode_index_ = index; - PopulateHWPanelInfo(); - UpdateMixerAttributes(); - - DLOGI("Display attributes[%d]: WxH: %dx%d, DPI: %fx%f, FPS: %d, LM_SPLIT: %d, V_BACK_PORCH: %d," \ - " V_FRONT_PORCH: %d, V_PULSE_WIDTH: %d, V_TOTAL: %d, H_TOTAL: %d, CLK: %dKHZ, TOPOLOGY: %d", - index, display_attributes_[index].x_pixels, display_attributes_[index].y_pixels, - display_attributes_[index].x_dpi, display_attributes_[index].y_dpi, - display_attributes_[index].fps, display_attributes_[index].is_device_split, - display_attributes_[index].v_back_porch, display_attributes_[index].v_front_porch, - display_attributes_[index].v_pulse_width, display_attributes_[index].v_total, - display_attributes_[index].h_total, display_attributes_[index].clock_khz, - display_attributes_[index].topology); - - return kErrorNone; -} - -DisplayError HWTVDRM::GetConfigIndex(char *mode, uint32_t *index) { - uint32_t width = 0, height = 0, fps = 0, format = 0; - std::string str(mode); - - // mode should be in width:height:fps:format - // TODO(user): it is not fully robust, User needs to provide in above format only - if (str.length() != 0) { - width = UINT32(stoi(str)); - height = UINT32(stoi(str.substr(str.find(':') + 1))); - std::string str3 = str.substr(str.find(':') + 1); - fps = UINT32(stoi(str3.substr(str3.find(':') + 1))); - std::string str4 = str3.substr(str3.find(':') + 1); - format = UINT32(stoi(str4.substr(str4.find(':') + 1))); - } - - for (size_t idex = 0; idex < connector_info_.modes.size(); idex ++) { - if ((height == connector_info_.modes[idex].mode.vdisplay) && - (width == connector_info_.modes[idex].mode.hdisplay) && - (fps == connector_info_.modes[idex].mode.vrefresh)) { - if ((format >> 1) & (connector_info_.modes[idex].mode.flags >> kBitYUV)) { - *index = UINT32(idex); - break; - } - - if (format & (connector_info_.modes[idex].mode.flags >> kBitRGB)) { - *index = UINT32(idex); - break; - } - } - } - - return kErrorNone; -} - -DisplayError HWTVDRM::PowerOff() { - DTRACE_SCOPED(); - - int ret = drm_atomic_intf_->Commit(true /* synchronous */, false /* retain_planes*/); - if (ret) { - DLOGE("%s failed with error %d", __FUNCTION__, ret); - return kErrorHardware; - } - - return kErrorNone; -} - -DisplayError HWTVDRM::Doze(int *release_fence) { - return kErrorNone; -} - -DisplayError HWTVDRM::DozeSuspend(int *release_fence) { - return kErrorNone; -} - -DisplayError HWTVDRM::Standby() { - return kErrorNone; -} - -void HWTVDRM::PopulateHWPanelInfo() { - hw_panel_info_ = {}; - - HWDeviceDRM::PopulateHWPanelInfo(); - hw_panel_info_.hdr_enabled = connector_info_.ext_hdr_prop.hdr_supported; - hw_panel_info_.hdr_metadata_type_one = connector_info_.ext_hdr_prop.hdr_metadata_type_one; - hw_panel_info_.hdr_eotf = connector_info_.ext_hdr_prop.hdr_eotf; - hw_panel_info_.peak_luminance = connector_info_.ext_hdr_prop.hdr_max_luminance; - hw_panel_info_.average_luminance = connector_info_.ext_hdr_prop.hdr_avg_luminance; - hw_panel_info_.blackness_level = connector_info_.ext_hdr_prop.hdr_min_luminance; - DLOGI("TV Panel: %s, type_one = %d, eotf = %d, luminance[max = %d, min = %d, avg = %d]", - hw_panel_info_.hdr_enabled ? "HDR" : "Non-HDR", hw_panel_info_.hdr_metadata_type_one, - hw_panel_info_.hdr_eotf, hw_panel_info_.peak_luminance, hw_panel_info_.blackness_level, - hw_panel_info_.average_luminance); -} - -DisplayError HWTVDRM::Commit(HWLayers *hw_layers) { - DisplayError error = UpdateHDRMetaData(hw_layers); - if (error != kErrorNone) { - return error; - } - return HWDeviceDRM::Commit(hw_layers); -} - -DisplayError HWTVDRM::UpdateHDRMetaData(HWLayers *hw_layers) { - static struct timeval hdr_reset_start, hdr_reset_end; - static bool reset_hdr_flag = false; - const HWHDRLayerInfo &hdr_layer_info = hw_layers->info.hdr_layer_info; - if (!hw_panel_info_.hdr_enabled) { - return kErrorNone; - } - - DisplayError error = kErrorNone; - - Layer hdr_layer = {}; - if (hdr_layer_info.operation == HWHDRLayerInfo::kSet && hdr_layer_info.layer_index > -1) { - hdr_layer = *(hw_layers->info.stack->layers.at(UINT32(hdr_layer_info.layer_index))); - } - - const LayerBuffer *layer_buffer = &hdr_layer.input_buffer; - const MasteringDisplay &mastering_display = layer_buffer->color_metadata.masteringDisplayInfo; - const ContentLightLevel &light_level = layer_buffer->color_metadata.contentLightLevel; - const Primaries &primaries = mastering_display.primaries; - - if (hdr_layer_info.operation == HWHDRLayerInfo::kSet) { - // Reset reset_hdr_flag to handle where there are two consecutive HDR video playbacks with not - // enough non-HDR frames in between to reset the HDR metadata. - reset_hdr_flag = false; - - int32_t eotf = GetEOTF(layer_buffer->color_metadata.transfer); - hdr_metadata_.hdr_supported = 1; - hdr_metadata_.hdr_state = HDR_ENABLE; - hdr_metadata_.eotf = (eotf < 0) ? 0 : UINT32(eotf); - hdr_metadata_.white_point_x = primaries.whitePoint[0]; - hdr_metadata_.white_point_y = primaries.whitePoint[1]; - hdr_metadata_.display_primaries_x[0] = primaries.rgbPrimaries[0][0]; - hdr_metadata_.display_primaries_y[0] = primaries.rgbPrimaries[0][1]; - hdr_metadata_.display_primaries_x[1] = primaries.rgbPrimaries[1][0]; - hdr_metadata_.display_primaries_y[1] = primaries.rgbPrimaries[1][1]; - hdr_metadata_.display_primaries_x[2] = primaries.rgbPrimaries[2][0]; - hdr_metadata_.display_primaries_y[2] = primaries.rgbPrimaries[2][1]; - hdr_metadata_.min_luminance = mastering_display.minDisplayLuminance; - hdr_metadata_.max_luminance = mastering_display.maxDisplayLuminance/10000; - hdr_metadata_.max_content_light_level = light_level.maxContentLightLevel; - hdr_metadata_.max_average_light_level = light_level.minPicAverageLightLevel; - - drm_atomic_intf_->Perform(DRMOps::CONNECTOR_SET_HDR_METADATA, token_.conn_id, &hdr_metadata_); - DumpHDRMetaData(hdr_layer_info.operation); - } else if (hdr_layer_info.operation == HWHDRLayerInfo::kReset) { - memset(&hdr_metadata_, 0, sizeof(hdr_metadata_)); - hdr_metadata_.hdr_supported = 1; - hdr_metadata_.hdr_state = HDR_ENABLE; - reset_hdr_flag = true; - gettimeofday(&hdr_reset_start, NULL); - - drm_atomic_intf_->Perform(DRMOps::CONNECTOR_SET_HDR_METADATA, token_.conn_id, &hdr_metadata_); - DumpHDRMetaData(hdr_layer_info.operation); - } else if (hdr_layer_info.operation == HWHDRLayerInfo::kNoOp) { - // TODO(user): This case handles the state transition from HDR_ENABLED to HDR_DISABLED. - // As per HDMI spec requirement, we need to send zero metadata for atleast 2 sec after end of - // playback. This timer calculates the 2 sec window after playback stops to stop sending HDR - // metadata. This will be replaced with an idle timer implementation in the future. - if (reset_hdr_flag) { - gettimeofday(&hdr_reset_end, NULL); - float hdr_reset_time_start = ((hdr_reset_start.tv_sec*1000) + (hdr_reset_start.tv_usec/1000)); - float hdr_reset_time_end = ((hdr_reset_end.tv_sec*1000) + (hdr_reset_end.tv_usec/1000)); - - if (((hdr_reset_time_end-hdr_reset_time_start)/1000) >= MIN_HDR_RESET_WAITTIME) { - memset(&hdr_metadata_, 0, sizeof(hdr_metadata_)); - hdr_metadata_.hdr_supported = 1; - hdr_metadata_.hdr_state = HDR_DISABLE; - reset_hdr_flag = false; - - drm_atomic_intf_->Perform(DRMOps::CONNECTOR_SET_HDR_METADATA, token_.conn_id, - &hdr_metadata_); - } - } - } - - return error; -} - -void HWTVDRM::DumpHDRMetaData(HWHDRLayerInfo::HDROperation operation) { - DLOGI("Operation = %d, HDR Metadata: MaxDisplayLuminance = %d MinDisplayLuminance = %d\n" - "MaxContentLightLevel = %d MaxAverageLightLevel = %d Red_x = %d Red_y = %d Green_x = %d\n" - "Green_y = %d Blue_x = %d Blue_y = %d WhitePoint_x = %d WhitePoint_y = %d EOTF = %d\n", - operation, hdr_metadata_.max_luminance, hdr_metadata_.min_luminance, - hdr_metadata_.max_content_light_level, hdr_metadata_.max_average_light_level, - hdr_metadata_.display_primaries_x[0], hdr_metadata_.display_primaries_y[0], - hdr_metadata_.display_primaries_x[1], hdr_metadata_.display_primaries_y[1], - hdr_metadata_.display_primaries_x[2], hdr_metadata_.display_primaries_y[2], - hdr_metadata_.white_point_x, hdr_metadata_.white_point_y, hdr_metadata_.eotf); -} - -DisplayError HWTVDRM::OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level) { - DisplayError error = kErrorNone; - int fd = -1; - char data[kMaxStringLength] = {'\0'}; - - snprintf(data, sizeof(data), "/sys/devices/virtual/hdcp/msm_hdcp/min_level_change"); - - fd = Sys::open_(data, O_WRONLY); - if (fd < 0) { - DLOGE("File '%s' could not be opened. errno = %d, desc = %s", data, errno, strerror(errno)); - return kErrorHardware; - } - - snprintf(data, sizeof(data), "%d", min_enc_level); - - ssize_t err = Sys::pwrite_(fd, data, strlen(data), 0); - if (err <= 0) { - DLOGE("Write failed, Error = %s", strerror(errno)); - error = kErrorHardware; - } - - Sys::close_(fd); - - return error; -} - -} // namespace sdm - diff --git a/sdm/libs/core/drm/hw_tv_drm.h b/sdm/libs/core/drm/hw_tv_drm.h deleted file mode 100644 index 3e592f97..00000000 --- a/sdm/libs/core/drm/hw_tv_drm.h +++ /dev/null @@ -1,65 +0,0 @@ -/* -* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted -* provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright notice, this list of -* conditions and the following disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its contributors may be used to -* endorse or promote products derived from this software without specific prior written -* permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __HW_TV_DRM_H__ -#define __HW_TV_DRM_H__ - -#include -#include - -#include "hw_device_drm.h" - -namespace sdm { - -using std::vector; - -class HWTVDRM : public HWDeviceDRM { - public: - explicit HWTVDRM(BufferSyncHandler *buffer_sync_handler, BufferAllocator *buffer_allocator, - HWInfoInterface *hw_info_intf); - - protected: - virtual DisplayError SetDisplayAttributes(uint32_t index); - virtual DisplayError GetConfigIndex(char *mode, uint32_t *index); - virtual DisplayError PowerOff(); - virtual DisplayError Doze(int *release_fence); - virtual DisplayError DozeSuspend(int *release_fence); - virtual DisplayError Standby(); - virtual DisplayError Commit(HWLayers *hw_layers); - virtual void PopulateHWPanelInfo(); - virtual DisplayError OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level); - - private: - DisplayError UpdateHDRMetaData(HWLayers *hw_layers); - void DumpHDRMetaData(HWHDRLayerInfo::HDROperation operation); - - static const int kBitRGB = 20; - static const int kBitYUV = 21; - drm_msm_ext_hdr_metadata hdr_metadata_ = {}; -}; - -} // namespace sdm - -#endif // __HW_TV_DRM_H__ - diff --git a/sdm/libs/core/drm/hw_virtual_drm.cpp b/sdm/libs/core/drm/hw_virtual_drm.cpp deleted file mode 100644 index 6f7b12b3..00000000 --- a/sdm/libs/core/drm/hw_virtual_drm.cpp +++ /dev/null @@ -1,226 +0,0 @@ -/* -Copyright (c) 2017, The Linux Foundation. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials provided - with the distribution. - * Neither the name of The Linux Foundation nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include -#include -#include -#include -#include -#include -#include "hw_device_drm.h" -#include "hw_virtual_drm.h" -#include "hw_info_drm.h" - -#define __CLASS__ "HWVirtualDRM" - -using std::vector; - -using sde_drm::DRMDisplayType; -using sde_drm::DRMConnectorInfo; -using sde_drm::DRMRect; -using sde_drm::DRMOps; -using sde_drm::DRMPowerMode; -using sde_drm::DRMSecureMode; - -namespace sdm { - -HWVirtualDRM::HWVirtualDRM(BufferSyncHandler *buffer_sync_handler, - BufferAllocator *buffer_allocator, - HWInfoInterface *hw_info_intf) - : HWDeviceDRM(buffer_sync_handler, buffer_allocator, hw_info_intf) { - HWDeviceDRM::device_name_ = "Virtual Display Device"; - HWDeviceDRM::disp_type_ = DRMDisplayType::VIRTUAL; -} - -void HWVirtualDRM::ConfigureWbConnectorFbId(uint32_t fb_id) { - drm_atomic_intf_->Perform(DRMOps::CONNECTOR_SET_OUTPUT_FB_ID, token_.conn_id, fb_id); - return; -} - -void HWVirtualDRM::ConfigureWbConnectorDestRect() { - DRMRect dst = {}; - dst.left = 0; - dst.bottom = display_attributes_[current_mode_index_].y_pixels; - dst.top = 0; - dst.right = display_attributes_[current_mode_index_].x_pixels; - drm_atomic_intf_->Perform(DRMOps::CONNECTOR_SET_OUTPUT_RECT, token_.conn_id, dst); - return; -} - -void HWVirtualDRM::ConfigureWbConnectorSecureMode(bool secure) { - DRMSecureMode secure_mode = secure ? DRMSecureMode::SECURE : DRMSecureMode::NON_SECURE; - drm_atomic_intf_->Perform(DRMOps::CONNECTOR_SET_FB_SECURE_MODE, token_.conn_id, secure_mode); -} - -void HWVirtualDRM::InitializeConfigs() { - display_attributes_.resize(connector_info_.modes.size()); - for (uint32_t i = 0; i < connector_info_.modes.size(); i++) { - PopulateDisplayAttributes(i); - } -} - -DisplayError HWVirtualDRM::SetWbConfigs(const HWDisplayAttributes &display_attributes) { - drmModeModeInfo mode = {}; - vector modes; - - mode.hdisplay = mode.hsync_start = mode.hsync_end = mode.htotal = - UINT16(display_attributes.x_pixels); - mode.vdisplay = mode.vsync_start = mode.vsync_end = mode.vtotal = - UINT16(display_attributes.y_pixels); - mode.vrefresh = UINT32(display_attributes.fps); - mode.clock = (mode.htotal * mode.vtotal * mode.vrefresh) / 1000; - snprintf(mode.name, DRM_DISPLAY_MODE_LEN, "%dx%d", mode.hdisplay, mode.vdisplay); - modes.push_back(mode); - for (auto &item : connector_info_.modes) { - modes.push_back(item.mode); - } - - // Inform the updated mode list to the driver - struct sde_drm_wb_cfg wb_cfg = {}; - wb_cfg.connector_id = token_.conn_id; - wb_cfg.flags = SDE_DRM_WB_CFG_FLAGS_CONNECTED; - wb_cfg.count_modes = UINT32(modes.size()); - wb_cfg.modes = (uint64_t)modes.data(); - - int ret = -EINVAL; -#ifdef DRM_IOCTL_SDE_WB_CONFIG - ret = drmIoctl(dev_fd_, DRM_IOCTL_SDE_WB_CONFIG, &wb_cfg); -#endif - if (ret) { - DLOGE("Dump WBConfig: mode_count %d flags %x", wb_cfg.count_modes, wb_cfg.flags); - DumpConnectorModeInfo(); - return kErrorHardware; - } - - return kErrorNone; -} - -void HWVirtualDRM::DumpConnectorModeInfo() { - for (uint32_t i = 0; i < (uint32_t)connector_info_.modes.size(); i++) { - DLOGI("Mode[%d] Name:%s vref:%d hdisp:%d hsync_s:%d hsync_e:%d htotal:%d " \ - "vdisp:%d vsync_s:%d vsync_e:%d vtotal:%d\n", i, connector_info_.modes[i].mode.name, - connector_info_.modes[i].mode.vrefresh, connector_info_.modes[i].mode.hdisplay, - connector_info_.modes[i].mode.hsync_start, connector_info_.modes[i].mode.hsync_end, - connector_info_.modes[i].mode.htotal, connector_info_.modes[i].mode.vdisplay, - connector_info_.modes[i].mode.vsync_start, connector_info_.modes[i].mode.vsync_end, - connector_info_.modes[i].mode.vtotal); - } -} - -DisplayError HWVirtualDRM::Commit(HWLayers *hw_layers) { - LayerBuffer *output_buffer = hw_layers->info.stack->output_buffer; - DisplayError err = kErrorNone; - - registry_.Register(hw_layers); - registry_.MapBufferToFbId(output_buffer); - uint32_t fb_id = registry_.GetFbId(output_buffer->planes[0].fd); - - ConfigureWbConnectorFbId(fb_id); - ConfigureWbConnectorDestRect(); - ConfigureWbConnectorSecureMode(output_buffer->flags.secure); - - err = HWDeviceDRM::AtomicCommit(hw_layers); - if (err != kErrorNone) { - DLOGE("Atomic commit failed for crtc_id %d conn_id %d", token_.crtc_id, token_.conn_id); - } - - registry_.Next(); - registry_.Unregister(); - - return(err); -} - -DisplayError HWVirtualDRM::Validate(HWLayers *hw_layers) { - LayerBuffer *output_buffer = hw_layers->info.stack->output_buffer; - - registry_.MapBufferToFbId(output_buffer); - uint32_t fb_id = registry_.GetFbId(output_buffer->planes[0].fd); - - ConfigureWbConnectorFbId(fb_id); - ConfigureWbConnectorDestRect(); - ConfigureWbConnectorSecureMode(output_buffer->flags.secure); - - return HWDeviceDRM::Validate(hw_layers); -} - -DisplayError HWVirtualDRM::SetDisplayAttributes(const HWDisplayAttributes &display_attributes) { - if (display_attributes.x_pixels == 0 || display_attributes.y_pixels == 0) { - return kErrorParameters; - } - - int mode_index = -1; - GetModeIndex(display_attributes, &mode_index); - - if (mode_index < 0) { - DisplayError error = SetWbConfigs(display_attributes); - if (error != kErrorNone) { - return error; - } - } - - // Reload connector info for updated info - drm_mgr_intf_->GetConnectorInfo(token_.conn_id, &connector_info_); - GetModeIndex(display_attributes, &mode_index); - - if (mode_index < 0) { - DLOGE("Mode not found for resolution %dx%d fps %d", display_attributes.x_pixels, - display_attributes.y_pixels, UINT32(display_attributes.fps)); - DumpConnectorModeInfo(); - return kErrorNotSupported; - } - - current_mode_index_ = UINT32(mode_index); - InitializeConfigs(); - PopulateHWPanelInfo(); - UpdateMixerAttributes(); - - DLOGI("New WB Resolution: %dx%d cur_mode_index %d", display_attributes.x_pixels, - display_attributes.y_pixels, current_mode_index_); - - return kErrorNone; -} - -DisplayError HWVirtualDRM::GetPPFeaturesVersion(PPFeatureVersion *vers) { - return kErrorNone; -} - -void HWVirtualDRM::GetModeIndex(const HWDisplayAttributes &display_attributes, int *mode_index) { - *mode_index = -1; - for (uint32_t i = 0; i < connector_info_.modes.size(); i++) { - if (display_attributes.x_pixels == connector_info_.modes[i].mode.hdisplay && - display_attributes.y_pixels == connector_info_.modes[i].mode.vdisplay && - display_attributes.fps == connector_info_.modes[i].mode.vrefresh) { - *mode_index = INT32(i); - break; - } - } -} - -} // namespace sdm - diff --git a/sdm/libs/core/drm/hw_virtual_drm.h b/sdm/libs/core/drm/hw_virtual_drm.h deleted file mode 100644 index 257e08a8..00000000 --- a/sdm/libs/core/drm/hw_virtual_drm.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -Copyright (c) 2017, The Linux Foundation. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials provided - with the distribution. - * Neither the name of The Linux Foundation nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __HW_VIRTUAL_DRM_H__ -#define __HW_VIRTUAL_DRM_H__ - -#include "hw_device_drm.h" -#include -#include -#include - -namespace sdm { - -class HWVirtualDRM : public HWDeviceDRM { - public: - HWVirtualDRM(BufferSyncHandler *buffer_sync_handler, - BufferAllocator *buffer_allocator, HWInfoInterface *hw_info_intf); - virtual ~HWVirtualDRM() {} - virtual DisplayError SetVSyncState(bool enable) { return kErrorNotSupported; } - virtual DisplayError SetMixerAttributes(const HWMixerAttributes &mixer_attributes) { - return kErrorNotSupported; - } - virtual DisplayError SetDisplayAttributes(const HWDisplayAttributes &display_attributes); - - protected: - virtual DisplayError Validate(HWLayers *hw_layers); - virtual DisplayError Commit(HWLayers *hw_layers); - virtual DisplayError GetPPFeaturesVersion(PPFeatureVersion *vers); - - private: - void ConfigureWbConnectorFbId(uint32_t fb_id); - void ConfigureWbConnectorDestRect(); - void ConfigureWbConnectorSecureMode(bool secure); - void InitializeConfigs(); - void DumpConnectorModeInfo(); - DisplayError SetWbConfigs(const HWDisplayAttributes &display_attributes); - void GetModeIndex(const HWDisplayAttributes &display_attributes, int *mode_index); -}; - -} // namespace sdm - -#endif // __HW_VIRTUAL_DRM_H__ - diff --git a/sdm/libs/core/fb/hw_color_manager.cpp b/sdm/libs/core/fb/hw_color_manager.cpp deleted file mode 100644 index a6c78b01..00000000 --- a/sdm/libs/core/fb/hw_color_manager.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/* -* Copyright (c) 2015-2016, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "hw_color_manager.h" - -#define __CLASS__ "HWColorManager" - -namespace sdm { - -DisplayError (*HWColorManager::SetFeature[])(const PPFeatureInfo &, msmfb_mdp_pp *) = { - [kGlobalColorFeaturePcc] = &HWColorManager::SetPCC, - [kGlobalColorFeatureIgc] = &HWColorManager::SetIGC, - [kGlobalColorFeaturePgc] = &HWColorManager::SetPGC, - [kMixerColorFeatureGc] = &HWColorManager::SetMixerGC, - [kGlobalColorFeaturePaV2] = &HWColorManager::SetPAV2, - [kGlobalColorFeatureDither] = &HWColorManager::SetDither, - [kGlobalColorFeatureGamut] = &HWColorManager::SetGamut, - [kGlobalColorFeaturePADither] = &HWColorManager::SetPADither, -}; - -DisplayError HWColorManager::SetPCC(const PPFeatureInfo &feature, msmfb_mdp_pp *kernel_params) { - DisplayError ret = kErrorNone; - - kernel_params->op = mdp_op_pcc_cfg; - kernel_params->data.pcc_cfg_data.version = feature.feature_version_; - kernel_params->data.pcc_cfg_data.block = MDP_LOGICAL_BLOCK_DISP_0 + feature.disp_id_; - kernel_params->data.pcc_cfg_data.ops = feature.enable_flags_; - kernel_params->data.pcc_cfg_data.cfg_payload = feature.GetConfigData(); - DLOGV_IF(kTagQDCM, "kernel params version = %d, block = %d, flags = %d", - kernel_params->data.pcc_cfg_data.version, kernel_params->data.pcc_cfg_data.block, - kernel_params->data.pcc_cfg_data.ops); - - return ret; -} - -DisplayError HWColorManager::SetIGC(const PPFeatureInfo &feature, msmfb_mdp_pp *kernel_params) { - DisplayError ret = kErrorNone; - - kernel_params->op = mdp_op_lut_cfg; - kernel_params->data.lut_cfg_data.lut_type = mdp_lut_igc; - kernel_params->data.lut_cfg_data.data.igc_lut_data.block = - MDP_LOGICAL_BLOCK_DISP_0 + feature.disp_id_; - kernel_params->data.lut_cfg_data.data.igc_lut_data.version = feature.feature_version_; - kernel_params->data.lut_cfg_data.data.igc_lut_data.ops = feature.enable_flags_; - kernel_params->data.lut_cfg_data.data.igc_lut_data.cfg_payload = feature.GetConfigData(); - - return ret; -} - -DisplayError HWColorManager::SetPGC(const PPFeatureInfo &feature, msmfb_mdp_pp *kernel_params) { - DisplayError ret = kErrorNone; - - kernel_params->op = mdp_op_lut_cfg; - kernel_params->data.lut_cfg_data.lut_type = mdp_lut_pgc; - kernel_params->data.lut_cfg_data.data.pgc_lut_data.version = feature.feature_version_; - kernel_params->data.lut_cfg_data.data.pgc_lut_data.block = - MDP_LOGICAL_BLOCK_DISP_0 + feature.disp_id_; - kernel_params->data.lut_cfg_data.data.pgc_lut_data.flags = feature.enable_flags_; - kernel_params->data.lut_cfg_data.data.pgc_lut_data.cfg_payload = feature.GetConfigData(); - - return ret; -} - -DisplayError HWColorManager::SetMixerGC(const PPFeatureInfo &feature, msmfb_mdp_pp *kernel_params) { - DisplayError ret = kErrorNone; - - kernel_params->op = mdp_op_lut_cfg; - kernel_params->data.lut_cfg_data.lut_type = mdp_lut_pgc; - kernel_params->data.lut_cfg_data.data.pgc_lut_data.version = feature.feature_version_; - kernel_params->data.lut_cfg_data.data.pgc_lut_data.block = - (MDP_LOGICAL_BLOCK_DISP_0 + feature.disp_id_) | MDSS_PP_LM_CFG; - kernel_params->data.lut_cfg_data.data.pgc_lut_data.flags = feature.enable_flags_; - kernel_params->data.lut_cfg_data.data.pgc_lut_data.cfg_payload = feature.GetConfigData(); - return ret; -} - -DisplayError HWColorManager::SetPAV2(const PPFeatureInfo &feature, msmfb_mdp_pp *kernel_params) { - DisplayError ret = kErrorNone; - - kernel_params->op = mdp_op_pa_v2_cfg; - kernel_params->data.pa_v2_cfg_data.version = feature.feature_version_; - kernel_params->data.pa_v2_cfg_data.block = MDP_LOGICAL_BLOCK_DISP_0 + feature.disp_id_; - kernel_params->data.pa_v2_cfg_data.flags = feature.enable_flags_; - kernel_params->data.pa_v2_cfg_data.cfg_payload = feature.GetConfigData(); - DLOGV_IF(kTagQDCM, "kernel params version = %d, block = %d, flags = %d", - kernel_params->data.pa_v2_cfg_data.version, kernel_params->data.pa_v2_cfg_data.block, - kernel_params->data.pa_v2_cfg_data.flags); - - return ret; -} - -DisplayError HWColorManager::SetDither(const PPFeatureInfo &feature, msmfb_mdp_pp *kernel_params) { - DisplayError ret = kErrorNone; - - kernel_params->op = mdp_op_dither_cfg; - kernel_params->data.dither_cfg_data.version = feature.feature_version_; - kernel_params->data.dither_cfg_data.block = MDP_LOGICAL_BLOCK_DISP_0 + feature.disp_id_; - kernel_params->data.dither_cfg_data.flags = feature.enable_flags_; - kernel_params->data.dither_cfg_data.cfg_payload = feature.GetConfigData(); - - return ret; -} - -DisplayError HWColorManager::SetGamut(const PPFeatureInfo &feature, msmfb_mdp_pp *kernel_params) { - DisplayError ret = kErrorNone; - - kernel_params->op = mdp_op_gamut_cfg; - kernel_params->data.gamut_cfg_data.version = feature.feature_version_; - kernel_params->data.gamut_cfg_data.block = MDP_LOGICAL_BLOCK_DISP_0 + feature.disp_id_; - kernel_params->data.gamut_cfg_data.flags = feature.enable_flags_; - kernel_params->data.gamut_cfg_data.cfg_payload = feature.GetConfigData(); - - return ret; -} - -DisplayError HWColorManager::SetPADither(const PPFeatureInfo &feature, - msmfb_mdp_pp *kernel_params) { - DisplayError ret = kErrorNone; -#ifdef PA_DITHER - kernel_params->op = mdp_op_pa_dither_cfg; - kernel_params->data.dither_cfg_data.version = feature.feature_version_; - kernel_params->data.dither_cfg_data.block = MDP_LOGICAL_BLOCK_DISP_0 + feature.disp_id_; - kernel_params->data.dither_cfg_data.flags = feature.enable_flags_; - kernel_params->data.dither_cfg_data.cfg_payload = feature.GetConfigData(); -#endif - return ret; -} - -} // namespace sdm diff --git a/sdm/libs/core/fb/hw_color_manager.h b/sdm/libs/core/fb/hw_color_manager.h deleted file mode 100644 index c9eea5ba..00000000 --- a/sdm/libs/core/fb/hw_color_manager.h +++ /dev/null @@ -1,60 +0,0 @@ -/* Copyright (c) 2015-2016, The Linux Foundataion. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -* -*/ - -#ifndef __HW_COLOR_MANAGER_H__ -#define __HW_COLOR_MANAGER_H__ - -#include -#include - -#include - -namespace sdm { - -class HWColorManager { - public: - static DisplayError SetPCC(const PPFeatureInfo &feature, msmfb_mdp_pp *kernel_params); - static DisplayError SetIGC(const PPFeatureInfo &feature, msmfb_mdp_pp *kernel_params); - static DisplayError SetPGC(const PPFeatureInfo &feature, msmfb_mdp_pp *kernel_params); - static DisplayError SetMixerGC(const PPFeatureInfo &feature, msmfb_mdp_pp *kernel_params); - static DisplayError SetPAV2(const PPFeatureInfo &feature, msmfb_mdp_pp *kernel_params); - static DisplayError SetDither(const PPFeatureInfo &feature, msmfb_mdp_pp *kernel_params); - static DisplayError SetGamut(const PPFeatureInfo &feature, msmfb_mdp_pp *kernel_params); - static DisplayError SetPADither(const PPFeatureInfo &feature, msmfb_mdp_pp *kernel_params); - - static DisplayError (*SetFeature[kMaxNumPPFeatures])(const PPFeatureInfo &feature, - msmfb_mdp_pp *kernel_params); - - protected: - HWColorManager() {} -}; - -} // namespace sdm - -#endif // __HW_COLOR_MANAGER_H__ diff --git a/sdm/libs/core/fb/hw_device.cpp b/sdm/libs/core/fb/hw_device.cpp deleted file mode 100644 index 148f866e..00000000 --- a/sdm/libs/core/fb/hw_device.cpp +++ /dev/null @@ -1,1400 +0,0 @@ -/* -* Copyright (c) 2014 - 2018, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#define __STDC_FORMAT_MACROS - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "hw_device.h" -#include "hw_primary.h" -#include "hw_hdmi.h" -#include "hw_virtual.h" -#include "hw_info_interface.h" - -#define __CLASS__ "HWDevice" - -using std::string; -using std::to_string; -using std::fstream; - -namespace sdm { - -HWDevice::HWDevice(BufferSyncHandler *buffer_sync_handler) - : fb_node_index_(-1), fb_path_("/sys/devices/virtual/graphics/fb"), - buffer_sync_handler_(buffer_sync_handler), synchronous_commit_(false) { -} - -DisplayError HWDevice::Init() { - // Read the fb node index - fb_node_index_ = GetFBNodeIndex(device_type_); - if (fb_node_index_ == -1) { - DLOGE("device type = %d should be present", device_type_); - return kErrorHardware; - } - - const char *dev_name = NULL; - vector dev_paths = {"/dev/graphics/fb", "/dev/fb"}; - for (size_t i = 0; i < dev_paths.size(); i++) { - dev_paths[i] += to_string(fb_node_index_); - if (Sys::access_(dev_paths[i].c_str(), F_OK) >= 0) { - dev_name = dev_paths[i].c_str(); - DLOGI("access(%s) successful", dev_name); - break; - } - - DLOGI("access(%s), errno = %d, error = %s", dev_paths[i].c_str(), errno, strerror(errno)); - } - - if (!dev_name) { - DLOGE("access() failed for all possible paths"); - return kErrorHardware; - } - - // Populate Panel Info (Used for Partial Update) - PopulateHWPanelInfo(); - // Populate HW Capabilities - hw_resource_ = HWResourceInfo(); - hw_info_intf_->GetHWResourceInfo(&hw_resource_); - - device_fd_ = Sys::open_(dev_name, O_RDWR); - if (device_fd_ < 0) { - DLOGE("open %s failed errno = %d, error = %s", dev_name, errno, strerror(errno)); - return kErrorResources; - } - - return HWScale::Create(&hw_scale_, hw_resource_.has_qseed3); -} - -DisplayError HWDevice::Deinit() { - HWScale::Destroy(hw_scale_); - - if (device_fd_ >= 0) { - Sys::close_(device_fd_); - device_fd_ = -1; - } - - if (stored_retire_fence >= 0) { - Sys::close_(stored_retire_fence); - stored_retire_fence = -1; - } - return kErrorNone; -} - -DisplayError HWDevice::GetActiveConfig(uint32_t *active_config) { - *active_config = 0; - return kErrorNone; -} - -DisplayError HWDevice::GetNumDisplayAttributes(uint32_t *count) { - *count = 1; - return kErrorNone; -} - -DisplayError HWDevice::GetDisplayAttributes(uint32_t index, - HWDisplayAttributes *display_attributes) { - return kErrorNone; -} - -DisplayError HWDevice::GetHWPanelInfo(HWPanelInfo *panel_info) { - *panel_info = hw_panel_info_; - return kErrorNone; -} - -DisplayError HWDevice::SetDisplayAttributes(uint32_t index) { - return kErrorNone; -} - -DisplayError HWDevice::SetDisplayAttributes(const HWDisplayAttributes &display_attributes) { - return kErrorNotSupported; -} - -DisplayError HWDevice::GetConfigIndex(char *mode, uint32_t *index) { - return kErrorNone; -} - -DisplayError HWDevice::PowerOn(int *release_fence) { - DTRACE_SCOPED(); - - if (Sys::ioctl_(device_fd_, FBIOBLANK, FB_BLANK_UNBLANK) < 0) { - if (errno == ESHUTDOWN) { - DLOGI_IF(kTagDriverConfig, "Driver is processing shutdown sequence"); - return kErrorShutDown; - } - IOCTL_LOGE(FB_BLANK_UNBLANK, device_type_); - return kErrorHardware; - } - - return kErrorNone; -} - -DisplayError HWDevice::PowerOff() { - return kErrorNone; -} - -DisplayError HWDevice::Doze(int *release_fence) { - return kErrorNone; -} - -DisplayError HWDevice::DozeSuspend(int *release_fence) { - return kErrorNone; -} - -DisplayError HWDevice::Standby() { - return kErrorNone; -} - -DisplayError HWDevice::Validate(HWLayers *hw_layers) { - DTRACE_SCOPED(); - - DisplayError error = kErrorNone; - - HWLayersInfo &hw_layer_info = hw_layers->info; - uint32_t hw_layer_count = UINT32(hw_layer_info.hw_layers.size()); - - DLOGD_IF(kTagDriverConfig, "************************** %s Validate Input ***********************", - device_name_); - DLOGD_IF(kTagDriverConfig, "SDE layer count is %d", hw_layer_count); - - mdp_layer_commit_v1 &mdp_commit = mdp_disp_commit_.commit_v1; - uint32_t &mdp_layer_count = mdp_commit.input_layer_cnt; - - DLOGI_IF(kTagDriverConfig, "left_roi: x = %d, y = %d, w = %d, h = %d", mdp_commit.left_roi.x, - mdp_commit.left_roi.y, mdp_commit.left_roi.w, mdp_commit.left_roi.h); - DLOGI_IF(kTagDriverConfig, "right_roi: x = %d, y = %d, w = %d, h = %d", mdp_commit.right_roi.x, - mdp_commit.right_roi.y, mdp_commit.right_roi.w, mdp_commit.right_roi.h); - - for (uint32_t i = 0; i < hw_layer_count; i++) { - const Layer &layer = hw_layer_info.hw_layers.at(i); - LayerBuffer input_buffer = layer.input_buffer; - HWPipeInfo *left_pipe = &hw_layers->config[i].left_pipe; - HWPipeInfo *right_pipe = &hw_layers->config[i].right_pipe; - HWRotatorSession *hw_rotator_session = &hw_layers->config[i].hw_rotator_session; - bool is_rotator_used = (hw_rotator_session->hw_block_count != 0); - - for (uint32_t count = 0; count < 2; count++) { - HWPipeInfo *pipe_info = (count == 0) ? left_pipe : right_pipe; - HWRotateInfo *hw_rotate_info = &hw_rotator_session->hw_rotate_info[count]; - - if (hw_rotate_info->valid) { - input_buffer = hw_rotator_session->output_buffer; - } - - if (pipe_info->valid) { - mdp_input_layer &mdp_layer = mdp_in_layers_[mdp_layer_count]; - mdp_layer_buffer &mdp_buffer = mdp_layer.buffer; - - mdp_buffer.width = input_buffer.width; - mdp_buffer.height = input_buffer.height; - mdp_buffer.comp_ratio.denom = 1000; - mdp_buffer.comp_ratio.numer = UINT32(hw_layers->config[i].compression * 1000); - - if (layer.flags.solid_fill) { - mdp_buffer.format = MDP_ARGB_8888; - } else { - error = SetFormat(input_buffer.format, &mdp_buffer.format); - if (error != kErrorNone) { - return error; - } - } - mdp_layer.alpha = layer.plane_alpha; - mdp_layer.z_order = UINT16(pipe_info->z_order); - mdp_layer.transp_mask = 0xffffffff; - SetBlending(layer.blending, &mdp_layer.blend_op); - mdp_layer.pipe_ndx = pipe_info->pipe_id; - mdp_layer.horz_deci = pipe_info->horizontal_decimation; - mdp_layer.vert_deci = pipe_info->vertical_decimation; -#ifdef MDP_COMMIT_RECT_NUM - mdp_layer.rect_num = pipe_info->rect; -#endif - SetRect(pipe_info->src_roi, &mdp_layer.src_rect); - SetRect(pipe_info->dst_roi, &mdp_layer.dst_rect); - SetMDPFlags(&layer, is_rotator_used, hw_layer_info.async_cursor_updates, &mdp_layer.flags); - SetCSC(layer.input_buffer.color_metadata, &mdp_layer.color_space); - if (pipe_info->flags & kIGC) { - SetIGC(&layer.input_buffer, mdp_layer_count); - } - if (pipe_info->flags & kMultiRect) { - mdp_layer.flags |= MDP_LAYER_MULTIRECT_ENABLE; - if (pipe_info->flags & kMultiRectParallelMode) { - mdp_layer.flags |= MDP_LAYER_MULTIRECT_PARALLEL_MODE; - } - } - mdp_layer.bg_color = layer.solid_fill_color; - - // HWScaleData to MDP driver - hw_scale_->SetHWScaleData(pipe_info->scale_data, mdp_layer_count, &mdp_commit, - pipe_info->sub_block_type); - mdp_layer.scale = hw_scale_->GetScaleDataRef(mdp_layer_count, pipe_info->sub_block_type); - - mdp_layer_count++; - - DLOGD_IF(kTagDriverConfig, "******************* Layer[%d] %s pipe Input ******************", - i, count ? "Right" : "Left"); - DLOGD_IF(kTagDriverConfig, "in_w %d, in_h %d, in_f %d", mdp_buffer.width, mdp_buffer.height, - mdp_buffer.format); - DLOGD_IF(kTagDriverConfig, "plane_alpha %d, zorder %d, blending %d, horz_deci %d, " - "vert_deci %d, pipe_id = 0x%x, mdp_flags 0x%x", mdp_layer.alpha, mdp_layer.z_order, - mdp_layer.blend_op, mdp_layer.horz_deci, mdp_layer.vert_deci, mdp_layer.pipe_ndx, - mdp_layer.flags); - DLOGV_IF(kTagDriverConfig, "src_rect [%d, %d, %d, %d]", mdp_layer.src_rect.x, - mdp_layer.src_rect.y, mdp_layer.src_rect.w, mdp_layer.src_rect.h); - DLOGV_IF(kTagDriverConfig, "dst_rect [%d, %d, %d, %d]", mdp_layer.dst_rect.x, - mdp_layer.dst_rect.y, mdp_layer.dst_rect.w, mdp_layer.dst_rect.h); - hw_scale_->DumpScaleData(mdp_layer.scale); - DLOGD_IF(kTagDriverConfig, "*************************************************************"); - } - } - } - - // TODO(user): This block should move to the derived class - if (device_type_ == kDeviceVirtual) { - LayerBuffer *output_buffer = hw_layers->info.stack->output_buffer; - mdp_out_layer_.writeback_ndx = hw_resource_.writeback_index; - mdp_out_layer_.buffer.width = output_buffer->width; - mdp_out_layer_.buffer.height = output_buffer->height; - if (output_buffer->flags.secure) { - mdp_out_layer_.flags |= MDP_LAYER_SECURE_SESSION; - } - mdp_out_layer_.buffer.comp_ratio.denom = 1000; - mdp_out_layer_.buffer.comp_ratio.numer = UINT32(hw_layers->output_compression * 1000); -#ifdef OUT_LAYER_COLOR_SPACE - SetCSC(output_buffer->color_metadata, &mdp_out_layer_.color_space); -#endif - SetFormat(output_buffer->format, &mdp_out_layer_.buffer.format); - - DLOGI_IF(kTagDriverConfig, "********************* Output buffer Info ************************"); - DLOGI_IF(kTagDriverConfig, "out_w %d, out_h %d, out_f %d, wb_id %d", - mdp_out_layer_.buffer.width, mdp_out_layer_.buffer.height, - mdp_out_layer_.buffer.format, mdp_out_layer_.writeback_ndx); - DLOGI_IF(kTagDriverConfig, "*****************************************************************"); - } - - uint32_t index = 0; - for (uint32_t i = 0; i < hw_resource_.hw_dest_scalar_info.count; i++) { - DestScaleInfoMap::iterator it = hw_layer_info.dest_scale_info_map.find(i); - - if (it == hw_layer_info.dest_scale_info_map.end()) { - continue; - } - - HWDestScaleInfo *dest_scale_info = it->second; - - mdp_destination_scaler_data *dest_scalar_data = &mdp_dest_scalar_data_[index]; - hw_scale_->SetHWScaleData(dest_scale_info->scale_data, index, &mdp_commit, - kHWDestinationScalar); - - if (dest_scale_info->scale_update) { - dest_scalar_data->flags |= MDP_DESTSCALER_SCALE_UPDATE; - } - - dest_scalar_data->dest_scaler_ndx = i; - dest_scalar_data->lm_width = dest_scale_info->mixer_width; - dest_scalar_data->lm_height = dest_scale_info->mixer_height; -#ifdef MDP_DESTSCALER_ROI_ENABLE - SetRect(dest_scale_info->panel_roi, &dest_scalar_data->panel_roi); - dest_scalar_data->flags |= MDP_DESTSCALER_ROI_ENABLE; -#endif - dest_scalar_data->scale = reinterpret_cast - (hw_scale_->GetScaleDataRef(index, kHWDestinationScalar)); - - index++; - - DLOGD_IF(kTagDriverConfig, "************************ DestScalar[%d] **************************", - dest_scalar_data->dest_scaler_ndx); - DLOGD_IF(kTagDriverConfig, "Mixer WxH %dx%d flags %x", dest_scalar_data->lm_width, - dest_scalar_data->lm_height, dest_scalar_data->flags); -#ifdef MDP_DESTSCALER_ROI_ENABLE - DLOGD_IF(kTagDriverConfig, "Panel ROI [%d, %d, %d, %d]", dest_scalar_data->panel_roi.x, - dest_scalar_data->panel_roi.y, dest_scalar_data->panel_roi.w, - dest_scalar_data->panel_roi.h); -#endif - DLOGD_IF(kTagDriverConfig, "*****************************************************************"); - } - mdp_commit.dest_scaler_cnt = UINT32(hw_layer_info.dest_scale_info_map.size()); - - mdp_commit.flags |= MDP_VALIDATE_LAYER; -#ifdef MDP_COMMIT_RECT_NUM - mdp_commit.flags |= MDP_COMMIT_RECT_NUM; -#endif - if (Sys::ioctl_(device_fd_, INT(MSMFB_ATOMIC_COMMIT), &mdp_disp_commit_) < 0) { - if (errno == ESHUTDOWN) { - DLOGI_IF(kTagDriverConfig, "Driver is processing shutdown sequence"); - return kErrorShutDown; - } - IOCTL_LOGE(MSMFB_ATOMIC_COMMIT, device_type_); - DumpLayerCommit(mdp_disp_commit_); - return kErrorHardware; - } - - return kErrorNone; -} - -void HWDevice::DumpLayerCommit(const mdp_layer_commit &layer_commit) { - const mdp_layer_commit_v1 &mdp_commit = layer_commit.commit_v1; - const mdp_input_layer *mdp_layers = mdp_commit.input_layers; - const mdp_rect &l_roi = mdp_commit.left_roi; - const mdp_rect &r_roi = mdp_commit.right_roi; - - DLOGI("mdp_commit: flags = %x, release fence = %x", mdp_commit.flags, mdp_commit.release_fence); - DLOGI("left_roi: x = %d, y = %d, w = %d, h = %d", l_roi.x, l_roi.y, l_roi.w, l_roi.h); - DLOGI("right_roi: x = %d, y = %d, w = %d, h = %d", r_roi.x, r_roi.y, r_roi.w, r_roi.h); - for (uint32_t i = 0; i < mdp_commit.dest_scaler_cnt; i++) { - mdp_destination_scaler_data *dest_scalar_data = &mdp_dest_scalar_data_[i]; - mdp_scale_data_v2 *mdp_scale = reinterpret_cast(dest_scalar_data->scale); - - DLOGI("Dest scalar index %d Mixer WxH %dx%d", dest_scalar_data->dest_scaler_ndx, - dest_scalar_data->lm_width, dest_scalar_data->lm_height); -#ifdef MDP_DESTSCALER_ROI_ENABLE - DLOGI("Panel ROI [%d, %d, %d, %d]", dest_scalar_data->panel_roi.x, - dest_scalar_data->panel_roi.y, dest_scalar_data->panel_roi.w, - dest_scalar_data->panel_roi.h); -#endif - DLOGI("Dest scalar Dst WxH %dx%d", mdp_scale->dst_width, mdp_scale->dst_height); - } - for (uint32_t i = 0; i < mdp_commit.input_layer_cnt; i++) { - const mdp_input_layer &layer = mdp_layers[i]; - const mdp_rect &src_rect = layer.src_rect; - const mdp_rect &dst_rect = layer.dst_rect; - DLOGI("layer = %d, pipe_ndx = %x, z = %d, flags = %x", - i, layer.pipe_ndx, layer.z_order, layer.flags); - DLOGI("src_width = %d, src_height = %d, src_format = %d", - layer.buffer.width, layer.buffer.height, layer.buffer.format); - DLOGI("src_rect: x = %d, y = %d, w = %d, h = %d", - src_rect.x, src_rect.y, src_rect.w, src_rect.h); - DLOGI("dst_rect: x = %d, y = %d, w = %d, h = %d", - dst_rect.x, dst_rect.y, dst_rect.w, dst_rect.h); - } -} - -DisplayError HWDevice::Commit(HWLayers *hw_layers) { - DTRACE_SCOPED(); - - HWLayersInfo &hw_layer_info = hw_layers->info; - uint32_t hw_layer_count = UINT32(hw_layer_info.hw_layers.size()); - - DLOGD_IF(kTagDriverConfig, "*************************** %s Commit Input ************************", - device_name_); - DLOGD_IF(kTagDriverConfig, "SDE layer count is %d", hw_layer_count); - - mdp_layer_commit_v1 &mdp_commit = mdp_disp_commit_.commit_v1; - uint32_t mdp_layer_index = 0; - - for (uint32_t i = 0; i < hw_layer_count; i++) { - const Layer &layer = hw_layer_info.hw_layers.at(i); - LayerBuffer *input_buffer = const_cast(&layer.input_buffer); - HWPipeInfo *left_pipe = &hw_layers->config[i].left_pipe; - HWPipeInfo *right_pipe = &hw_layers->config[i].right_pipe; - HWRotatorSession *hw_rotator_session = &hw_layers->config[i].hw_rotator_session; - - for (uint32_t count = 0; count < 2; count++) { - HWPipeInfo *pipe_info = (count == 0) ? left_pipe : right_pipe; - HWRotateInfo *hw_rotate_info = &hw_rotator_session->hw_rotate_info[count]; - - if (hw_rotate_info->valid) { - input_buffer = &hw_rotator_session->output_buffer; - } - - if (pipe_info->valid) { - mdp_layer_buffer &mdp_buffer = mdp_in_layers_[mdp_layer_index].buffer; - mdp_input_layer &mdp_layer = mdp_in_layers_[mdp_layer_index]; - if (input_buffer->planes[0].fd >= 0) { - mdp_buffer.plane_count = 1; - mdp_buffer.planes[0].fd = input_buffer->planes[0].fd; - mdp_buffer.planes[0].offset = input_buffer->planes[0].offset; - SetStride(device_type_, input_buffer->format, input_buffer->planes[0].stride, - &mdp_buffer.planes[0].stride); - } else { - mdp_buffer.plane_count = 0; - } - - mdp_buffer.fence = input_buffer->acquire_fence_fd; - mdp_layer_index++; - - DLOGD_IF(kTagDriverConfig, "****************** Layer[%d] %s pipe Input *******************", - i, count ? "Right" : "Left"); - DLOGD_IF(kTagDriverConfig, "in_w %d, in_h %d, in_f %d, horz_deci %d, vert_deci %d", - mdp_buffer.width, mdp_buffer.height, mdp_buffer.format, mdp_layer.horz_deci, - mdp_layer.vert_deci); - DLOGV_IF(kTagDriverConfig, "in_buf_fd %d, in_buf_offset %d, in_buf_stride %d, " \ - "in_plane_count %d, in_fence %d, layer count %d", mdp_buffer.planes[0].fd, - mdp_buffer.planes[0].offset, mdp_buffer.planes[0].stride, mdp_buffer.plane_count, - mdp_buffer.fence, mdp_commit.input_layer_cnt); - DLOGD_IF(kTagDriverConfig, "*************************************************************"); - } - } - } - - // TODO(user): Move to derived class - if (device_type_ == kDeviceVirtual) { - LayerBuffer *output_buffer = hw_layers->info.stack->output_buffer; - - if (output_buffer->planes[0].fd >= 0) { - mdp_out_layer_.buffer.planes[0].fd = output_buffer->planes[0].fd; - mdp_out_layer_.buffer.planes[0].offset = output_buffer->planes[0].offset; - SetStride(device_type_, output_buffer->format, output_buffer->planes[0].stride, - &mdp_out_layer_.buffer.planes[0].stride); - mdp_out_layer_.buffer.plane_count = 1; - } else { - DLOGE("Invalid output buffer fd"); - return kErrorParameters; - } - - mdp_out_layer_.buffer.fence = output_buffer->acquire_fence_fd; - - DLOGI_IF(kTagDriverConfig, "********************** Output buffer Info ***********************"); - DLOGI_IF(kTagDriverConfig, "out_fd %d, out_offset %d, out_stride %d, acquire_fence %d", - mdp_out_layer_.buffer.planes[0].fd, mdp_out_layer_.buffer.planes[0].offset, - mdp_out_layer_.buffer.planes[0].stride, mdp_out_layer_.buffer.fence); - DLOGI_IF(kTagDriverConfig, "*****************************************************************"); - } - - mdp_commit.release_fence = -1; - mdp_commit.flags &= UINT32(~MDP_VALIDATE_LAYER); - if (synchronous_commit_) { - mdp_commit.flags |= MDP_COMMIT_WAIT_FOR_FINISH; - } - if (Sys::ioctl_(device_fd_, INT(MSMFB_ATOMIC_COMMIT), &mdp_disp_commit_) < 0) { - if (errno == ESHUTDOWN) { - DLOGI_IF(kTagDriverConfig, "Driver is processing shutdown sequence"); - return kErrorShutDown; - } - IOCTL_LOGE(MSMFB_ATOMIC_COMMIT, device_type_); - DumpLayerCommit(mdp_disp_commit_); - synchronous_commit_ = false; - return kErrorHardware; - } - - LayerStack *stack = hw_layer_info.stack; - stack->retire_fence_fd = mdp_commit.retire_fence; -#ifdef VIDEO_MODE_DEFER_RETIRE_FENCE - if (hw_panel_info_.mode == kModeVideo) { - stack->retire_fence_fd = stored_retire_fence; - stored_retire_fence = mdp_commit.retire_fence; - } -#endif - // MDP returns only one release fence for the entire layer stack. Duplicate this fence into all - // layers being composed by MDP. - - for (uint32_t i = 0; i < hw_layer_count; i++) { - const Layer &layer = hw_layer_info.hw_layers.at(i); - LayerBuffer *input_buffer = const_cast(&layer.input_buffer); - HWRotatorSession *hw_rotator_session = &hw_layers->config[i].hw_rotator_session; - - if (hw_rotator_session->hw_block_count) { - input_buffer = &hw_rotator_session->output_buffer; - input_buffer->release_fence_fd = Sys::dup_(mdp_commit.release_fence); - continue; - } - - input_buffer->release_fence_fd = Sys::dup_(mdp_commit.release_fence); - } - - hw_layer_info.sync_handle = Sys::dup_(mdp_commit.release_fence); - - DLOGI_IF(kTagDriverConfig, "*************************** %s Commit Input ************************", - device_name_); - DLOGI_IF(kTagDriverConfig, "retire_fence_fd %d", stack->retire_fence_fd); - DLOGI_IF(kTagDriverConfig, "*******************************************************************"); - - if (mdp_commit.release_fence >= 0) { - Sys::close_(mdp_commit.release_fence); - } - - if (synchronous_commit_) { - // A synchronous commit can be requested when changing the display mode so we need to update - // panel info. - PopulateHWPanelInfo(); - synchronous_commit_ = false; - } - - return kErrorNone; -} - -DisplayError HWDevice::Flush() { - ResetDisplayParams(); - mdp_layer_commit_v1 &mdp_commit = mdp_disp_commit_.commit_v1; - mdp_commit.input_layer_cnt = 0; - mdp_commit.output_layer = NULL; - - mdp_commit.flags &= UINT32(~MDP_VALIDATE_LAYER); - if (Sys::ioctl_(device_fd_, INT(MSMFB_ATOMIC_COMMIT), &mdp_disp_commit_) < 0) { - if (errno == ESHUTDOWN) { - DLOGI_IF(kTagDriverConfig, "Driver is processing shutdown sequence"); - return kErrorShutDown; - } - IOCTL_LOGE(MSMFB_ATOMIC_COMMIT, device_type_); - DumpLayerCommit(mdp_disp_commit_); - return kErrorHardware; - } - return kErrorNone; -} - -DisplayError HWDevice::SetFormat(const LayerBufferFormat &source, uint32_t *target) { - switch (source) { - case kFormatARGB8888: *target = MDP_ARGB_8888; break; - case kFormatRGBA8888: *target = MDP_RGBA_8888; break; - case kFormatBGRA8888: *target = MDP_BGRA_8888; break; - case kFormatRGBX8888: *target = MDP_RGBX_8888; break; - case kFormatBGRX8888: *target = MDP_BGRX_8888; break; - case kFormatRGBA5551: *target = MDP_RGBA_5551; break; - case kFormatRGBA4444: *target = MDP_RGBA_4444; break; - case kFormatRGB888: *target = MDP_RGB_888; break; - case kFormatBGR888: *target = MDP_BGR_888; break; - case kFormatRGB565: *target = MDP_RGB_565; break; - case kFormatBGR565: *target = MDP_BGR_565; break; - case kFormatYCbCr420Planar: *target = MDP_Y_CB_CR_H2V2; break; - case kFormatYCrCb420Planar: *target = MDP_Y_CR_CB_H2V2; break; - case kFormatYCrCb420PlanarStride16: *target = MDP_Y_CR_CB_GH2V2; break; - case kFormatYCbCr420SemiPlanar: *target = MDP_Y_CBCR_H2V2; break; - case kFormatYCrCb420SemiPlanar: *target = MDP_Y_CRCB_H2V2; break; - case kFormatYCbCr422H1V2SemiPlanar: *target = MDP_Y_CBCR_H1V2; break; - case kFormatYCrCb422H1V2SemiPlanar: *target = MDP_Y_CRCB_H1V2; break; - case kFormatYCbCr422H2V1SemiPlanar: *target = MDP_Y_CBCR_H2V1; break; - case kFormatYCrCb422H2V1SemiPlanar: *target = MDP_Y_CRCB_H2V1; break; - case kFormatYCbCr422H2V1Packed: *target = MDP_YCBYCR_H2V1; break; - case kFormatYCbCr420SemiPlanarVenus: *target = MDP_Y_CBCR_H2V2_VENUS; break; - case kFormatRGBA8888Ubwc: *target = MDP_RGBA_8888_UBWC; break; - case kFormatRGBX8888Ubwc: *target = MDP_RGBX_8888_UBWC; break; - case kFormatBGR565Ubwc: *target = MDP_RGB_565_UBWC; break; - case kFormatYCbCr420SPVenusUbwc: *target = MDP_Y_CBCR_H2V2_UBWC; break; - case kFormatCbYCrY422H2V1Packed: *target = MDP_CBYCRY_H2V1; break; - case kFormatRGBA1010102: *target = MDP_RGBA_1010102; break; - case kFormatARGB2101010: *target = MDP_ARGB_2101010; break; - case kFormatRGBX1010102: *target = MDP_RGBX_1010102; break; - case kFormatXRGB2101010: *target = MDP_XRGB_2101010; break; - case kFormatBGRA1010102: *target = MDP_BGRA_1010102; break; - case kFormatABGR2101010: *target = MDP_ABGR_2101010; break; - case kFormatBGRX1010102: *target = MDP_BGRX_1010102; break; - case kFormatXBGR2101010: *target = MDP_XBGR_2101010; break; - case kFormatRGBA1010102Ubwc: *target = MDP_RGBA_1010102_UBWC; break; - case kFormatRGBX1010102Ubwc: *target = MDP_RGBX_1010102_UBWC; break; - case kFormatYCbCr420P010: *target = MDP_Y_CBCR_H2V2_P010; break; - case kFormatYCbCr420TP10Ubwc: *target = MDP_Y_CBCR_H2V2_TP10_UBWC; break; - default: - DLOGE("Unsupported format type %d", source); - return kErrorParameters; - } - - return kErrorNone; -} - -DisplayError HWDevice::SetStride(HWDeviceType device_type, LayerBufferFormat format, - uint32_t width, uint32_t *target) { - // TODO(user): This SetStride function is a workaround to satisfy the driver expectation for - // rotator and virtual devices. Eventually this will be taken care in the driver. - if (device_type != kDeviceRotator && device_type != kDeviceVirtual) { - *target = width; - return kErrorNone; - } - - switch (format) { - case kFormatARGB8888: - case kFormatRGBA8888: - case kFormatBGRA8888: - case kFormatRGBX8888: - case kFormatBGRX8888: - case kFormatRGBA8888Ubwc: - case kFormatRGBX8888Ubwc: - case kFormatRGBA1010102: - case kFormatARGB2101010: - case kFormatRGBX1010102: - case kFormatXRGB2101010: - case kFormatBGRA1010102: - case kFormatABGR2101010: - case kFormatBGRX1010102: - case kFormatXBGR2101010: - case kFormatRGBA1010102Ubwc: - case kFormatRGBX1010102Ubwc: - *target = width * 4; - break; - case kFormatRGB888: - case kFormatBGR888: - *target = width * 3; - break; - case kFormatRGB565: - case kFormatBGR565: - case kFormatBGR565Ubwc: - *target = width * 2; - break; - case kFormatYCbCr420SemiPlanarVenus: - case kFormatYCbCr420SPVenusUbwc: - case kFormatYCbCr420Planar: - case kFormatYCrCb420Planar: - case kFormatYCrCb420PlanarStride16: - case kFormatYCbCr420SemiPlanar: - case kFormatYCrCb420SemiPlanar: - case kFormatYCbCr420TP10Ubwc: - *target = width; - break; - case kFormatYCbCr422H2V1Packed: - case kFormatCbYCrY422H2V1Packed: - case kFormatYCrCb422H2V1SemiPlanar: - case kFormatYCrCb422H1V2SemiPlanar: - case kFormatYCbCr422H2V1SemiPlanar: - case kFormatYCbCr422H1V2SemiPlanar: - case kFormatYCbCr420P010: - case kFormatRGBA5551: - case kFormatRGBA4444: - *target = width * 2; - break; - default: - DLOGE("Unsupported format type %d", format); - return kErrorParameters; - } - - return kErrorNone; -} - -void HWDevice::SetBlending(const LayerBlending &source, mdss_mdp_blend_op *target) { - switch (source) { - case kBlendingPremultiplied: *target = BLEND_OP_PREMULTIPLIED; break; - case kBlendingOpaque: *target = BLEND_OP_OPAQUE; break; - case kBlendingCoverage: *target = BLEND_OP_COVERAGE; break; - default: *target = BLEND_OP_NOT_DEFINED; break; - } -} - -void HWDevice::SetRect(const LayerRect &source, mdp_rect *target) { - target->x = UINT32(source.left); - target->y = UINT32(source.top); - target->w = UINT32(source.right) - target->x; - target->h = UINT32(source.bottom) - target->y; -} - -void HWDevice::SetMDPFlags(const Layer *layer, const bool &is_rotator_used, - bool async_cursor_updates, uint32_t *mdp_flags) { - const LayerBuffer &input_buffer = layer->input_buffer; - - // Flips will be taken care by rotator, if layer uses rotator for downscale/rotation. So ignore - // flip flags for MDP. - if (!is_rotator_used) { - if (layer->transform.flip_vertical) { - *mdp_flags |= MDP_LAYER_FLIP_UD; - } - - if (layer->transform.flip_horizontal) { - *mdp_flags |= MDP_LAYER_FLIP_LR; - } - - if (input_buffer.flags.interlace) { - *mdp_flags |= MDP_LAYER_DEINTERLACE; - } - } - - if (input_buffer.flags.secure_camera) { - *mdp_flags |= MDP_LAYER_SECURE_CAMERA_SESSION; - } else if (input_buffer.flags.secure) { - *mdp_flags |= MDP_LAYER_SECURE_SESSION; - } - - if (input_buffer.flags.secure_display) { - *mdp_flags |= MDP_LAYER_SECURE_DISPLAY_SESSION; - } - - if (layer->flags.solid_fill) { - *mdp_flags |= MDP_LAYER_SOLID_FILL; - } - - if (layer->flags.cursor && async_cursor_updates) { - // command mode panels does not support async position update - *mdp_flags |= MDP_LAYER_ASYNC; - } -} - -int HWDevice::GetFBNodeIndex(HWDeviceType device_type) { - for (int i = 0; i < kFBNodeMax; i++) { - HWPanelInfo panel_info; - GetHWPanelInfoByNode(i, &panel_info); - switch (device_type) { - case kDevicePrimary: - if (panel_info.is_primary_panel) { - return i; - } - break; - case kDeviceHDMI: - if (panel_info.is_pluggable == true) { - if (IsFBNodeConnected(i)) { - return i; - } - } - break; - case kDeviceVirtual: - if (panel_info.port == kPortWriteBack) { - return i; - } - break; - default: - break; - } - } - return -1; -} - -void HWDevice::PopulateHWPanelInfo() { - hw_panel_info_ = HWPanelInfo(); - GetHWPanelInfoByNode(fb_node_index_, &hw_panel_info_); - DLOGI("Device type = %d, Display Port = %d, Display Mode = %d, Device Node = %d, Is Primary = %d", - device_type_, hw_panel_info_.port, hw_panel_info_.mode, fb_node_index_, - hw_panel_info_.is_primary_panel); - DLOGI("Partial Update = %d, supported roi_count =%d, Dynamic FPS = %d", - hw_panel_info_.partial_update, hw_panel_info_.left_roi_count, hw_panel_info_.dynamic_fps); - DLOGI("Align: left = %d, width = %d, top = %d, height = %d", - hw_panel_info_.left_align, hw_panel_info_.width_align, - hw_panel_info_.top_align, hw_panel_info_.height_align); - DLOGI("ROI: min_width = %d, min_height = %d, need_merge = %d", - hw_panel_info_.min_roi_width, hw_panel_info_.min_roi_height, - hw_panel_info_.needs_roi_merge); - DLOGI("FPS: min = %d, max =%d", hw_panel_info_.min_fps, hw_panel_info_.max_fps); - DLOGI("Ping Pong Split = %d", hw_panel_info_.ping_pong_split); - DLOGI("Left Split = %d, Right Split = %d", hw_panel_info_.split_info.left_split, - hw_panel_info_.split_info.right_split); -} - -void HWDevice::GetHWPanelNameByNode(int device_node, HWPanelInfo *panel_info) { - string file_name = fb_path_ + to_string(device_node) + "/msm_fb_panel_info"; - - Sys::fstream fs(file_name, fstream::in); - if (!fs.is_open()) { - DLOGW("Failed to open msm_fb_panel_info node device node %d", device_node); - return; - } - - string line; - while (Sys::getline_(fs, line)) { - uint32_t token_count = 0; - const uint32_t max_count = 10; - char *tokens[max_count] = { NULL }; - if (!ParseLine(line.c_str(), "=\n", tokens, max_count, &token_count)) { - if (tokens[0] != NULL) { - if (!strncmp(tokens[0], "panel_name", strlen("panel_name"))) { - snprintf(panel_info->panel_name, sizeof(panel_info->panel_name), "%s", tokens[1]); - break; - } - } - } - } -} - -void HWDevice::GetHWPanelInfoByNode(int device_node, HWPanelInfo *panel_info) { - string file_name = fb_path_ + to_string(device_node) + "/msm_fb_panel_info"; - - Sys::fstream fs(file_name, fstream::in); - if (!fs.is_open()) { - DLOGW("Failed to open msm_fb_panel_info node device node %d", device_node); - return; - } - - string line; - while (Sys::getline_(fs, line)) { - uint32_t token_count = 0; - const uint32_t max_count = 10; - char *tokens[max_count] = { NULL }; - if (!ParseLine(line.c_str(), tokens, max_count, &token_count)) { - if (!strncmp(tokens[0], "pu_en", strlen("pu_en"))) { - panel_info->partial_update = atoi(tokens[1]); - } else if (!strncmp(tokens[0], "xstart", strlen("xstart"))) { - panel_info->left_align = atoi(tokens[1]); - } else if (!strncmp(tokens[0], "walign", strlen("walign"))) { - panel_info->width_align = atoi(tokens[1]); - } else if (!strncmp(tokens[0], "ystart", strlen("ystart"))) { - panel_info->top_align = atoi(tokens[1]); - } else if (!strncmp(tokens[0], "halign", strlen("halign"))) { - panel_info->height_align = atoi(tokens[1]); - } else if (!strncmp(tokens[0], "min_w", strlen("min_w"))) { - panel_info->min_roi_width = atoi(tokens[1]); - } else if (!strncmp(tokens[0], "min_h", strlen("min_h"))) { - panel_info->min_roi_height = atoi(tokens[1]); - } else if (!strncmp(tokens[0], "roi_merge", strlen("roi_merge"))) { - panel_info->needs_roi_merge = atoi(tokens[1]); - } else if (!strncmp(tokens[0], "dyn_fps_en", strlen("dyn_fps_en"))) { - panel_info->dynamic_fps = atoi(tokens[1]); - } else if (!strncmp(tokens[0], "dfps_porch_mode", strlen("dfps_porch_mode"))) { - panel_info->dfps_porch_mode = atoi(tokens[1]); - } else if (!strncmp(tokens[0], "is_pingpong_split", strlen("is_pingpong_split"))) { - panel_info->ping_pong_split = atoi(tokens[1]); - } else if (!strncmp(tokens[0], "min_fps", strlen("min_fps"))) { - panel_info->min_fps = UINT32(atoi(tokens[1])); - } else if (!strncmp(tokens[0], "max_fps", strlen("max_fps"))) { - panel_info->max_fps = UINT32(atoi(tokens[1])); - } else if (!strncmp(tokens[0], "primary_panel", strlen("primary_panel"))) { - panel_info->is_primary_panel = atoi(tokens[1]); - } else if (!strncmp(tokens[0], "is_pluggable", strlen("is_pluggable"))) { - panel_info->is_pluggable = atoi(tokens[1]); - } else if (!strncmp(tokens[0], "pu_roi_cnt", strlen("pu_roi_cnt"))) { - panel_info->left_roi_count = UINT32(atoi(tokens[1])); - panel_info->right_roi_count = UINT32(atoi(tokens[1])); - } else if (!strncmp(tokens[0], "is_hdr_enabled", strlen("is_hdr_enabled"))) { - panel_info->hdr_enabled = atoi(tokens[1]); - } else if (!strncmp(tokens[0], "peak_brightness", strlen("peak_brightness"))) { - panel_info->peak_luminance = UINT32(atoi(tokens[1])); - } else if (!strncmp(tokens[0], "average_brightness", strlen("average_brightness"))) { - panel_info->average_luminance = UINT32(atoi(tokens[1])); - } else if (!strncmp(tokens[0], "blackness_level", strlen("blackness_level"))) { - panel_info->blackness_level = UINT32(atoi(tokens[1])); - } else if (!strncmp(tokens[0], "white_chromaticity_x", strlen("white_chromaticity_x"))) { - panel_info->primaries.white_point[0] = UINT32(atoi(tokens[1])); - } else if (!strncmp(tokens[0], "white_chromaticity_y", strlen("white_chromaticity_y"))) { - panel_info->primaries.white_point[1] = UINT32(atoi(tokens[1])); - } else if (!strncmp(tokens[0], "red_chromaticity_x", strlen("red_chromaticity_x"))) { - panel_info->primaries.red[0] = UINT32(atoi(tokens[1])); - } else if (!strncmp(tokens[0], "red_chromaticity_y", strlen("red_chromaticity_y"))) { - panel_info->primaries.red[1] = UINT32(atoi(tokens[1])); - } else if (!strncmp(tokens[0], "green_chromaticity_x", strlen("green_chromaticity_x"))) { - panel_info->primaries.green[0] = UINT32(atoi(tokens[1])); - } else if (!strncmp(tokens[0], "green_chromaticity_y", strlen("green_chromaticity_y"))) { - panel_info->primaries.green[1] = UINT32(atoi(tokens[1])); - } else if (!strncmp(tokens[0], "blue_chromaticity_x", strlen("blue_chromaticity_x"))) { - panel_info->primaries.blue[0] = UINT32(atoi(tokens[1])); - } else if (!strncmp(tokens[0], "blue_chromaticity_y", strlen("blue_chromaticity_y"))) { - panel_info->primaries.blue[1] = UINT32(atoi(tokens[1])); - } else if (!strncmp(tokens[0], "panel_orientation", strlen("panel_orientation"))) { - int32_t panel_orient = atoi(tokens[1]); - panel_info->panel_orientation.flip_horizontal = ((panel_orient & MDP_FLIP_LR) > 0); - panel_info->panel_orientation.flip_vertical = ((panel_orient & MDP_FLIP_UD) > 0); - panel_info->panel_orientation.rotation = ((panel_orient & MDP_ROT_90) > 0); - } - } - } - - GetHWDisplayPortAndMode(device_node, panel_info); - GetSplitInfo(device_node, panel_info); - GetHWPanelNameByNode(device_node, panel_info); - GetHWPanelMaxBrightnessFromNode(panel_info); -} - -void HWDevice::GetHWDisplayPortAndMode(int device_node, HWPanelInfo *panel_info) { - DisplayPort *port = &panel_info->port; - HWDisplayMode *mode = &panel_info->mode; - - *port = kPortDefault; - *mode = kModeDefault; - - string file_name = fb_path_ + to_string(device_node) + "/msm_fb_type"; - - Sys::fstream fs(file_name, fstream::in); - if (!fs.is_open()) { - DLOGW("File not found %s", file_name.c_str()); - return; - } - - string line; - if (!Sys::getline_(fs, line)) { - return; - } - - if ((strncmp(line.c_str(), "mipi dsi cmd panel", strlen("mipi dsi cmd panel")) == 0)) { - *port = kPortDSI; - *mode = kModeCommand; - } else if ((strncmp(line.c_str(), "mipi dsi video panel", strlen("mipi dsi video panel")) == 0)) { - *port = kPortDSI; - *mode = kModeVideo; - } else if ((strncmp(line.c_str(), "lvds panel", strlen("lvds panel")) == 0)) { - *port = kPortLVDS; - *mode = kModeVideo; - } else if ((strncmp(line.c_str(), "edp panel", strlen("edp panel")) == 0)) { - *port = kPortEDP; - *mode = kModeVideo; - } else if ((strncmp(line.c_str(), "dtv panel", strlen("dtv panel")) == 0)) { - *port = kPortDTV; - *mode = kModeVideo; - } else if ((strncmp(line.c_str(), "writeback panel", strlen("writeback panel")) == 0)) { - *port = kPortWriteBack; - *mode = kModeCommand; - } else if ((strncmp(line.c_str(), "dp panel", strlen("dp panel")) == 0)) { - *port = kPortDP; - *mode = kModeVideo; - } - - return; -} - -void HWDevice::GetSplitInfo(int device_node, HWPanelInfo *panel_info) { - // Split info - for MDSS Version 5 - No need to check version here - string file_name = fb_path_ + to_string(device_node) + "/msm_fb_split"; - - Sys::fstream fs(file_name, fstream::in); - if (!fs.is_open()) { - DLOGW("File not found %s", file_name.c_str()); - return; - } - - // Format "left right" space as delimiter - uint32_t token_count = 0; - const uint32_t max_count = 10; - char *tokens[max_count] = { NULL }; - string line; - if (Sys::getline_(fs, line)) { - if (!ParseLine(line.c_str(), tokens, max_count, &token_count)) { - panel_info->split_info.left_split = UINT32(atoi(tokens[0])); - panel_info->split_info.right_split = UINT32(atoi(tokens[1])); - } - } -} - -void HWDevice::GetHWPanelMaxBrightnessFromNode(HWPanelInfo *panel_info) { - char brightness[kMaxStringLength] = { 0 }; - char kMaxBrightnessNode[64] = { 0 }; - - snprintf(kMaxBrightnessNode, sizeof(kMaxBrightnessNode), "%s", - "/sys/class/leds/lcd-backlight/max_brightness"); - - panel_info->panel_max_brightness = 0; - int fd = Sys::open_(kMaxBrightnessNode, O_RDONLY); - if (fd < 0) { - DLOGW("Failed to open max brightness node = %s, error = %s", kMaxBrightnessNode, - strerror(errno)); - return; - } - - if (Sys::pread_(fd, brightness, sizeof(brightness), 0) > 0) { - panel_info->panel_max_brightness = atoi(brightness); - DLOGI("Max brightness level = %d", panel_info->panel_max_brightness); - } else { - DLOGW("Failed to read max brightness level. error = %s", strerror(errno)); - } - Sys::close_(fd); -} - -int HWDevice::ParseLine(const char *input, char *tokens[], const uint32_t max_token, - uint32_t *count) { - char *tmp_token = NULL; - char *temp_ptr; - uint32_t index = 0; - const char *delim = ", =\n"; - if (!input) { - return -1; - } - tmp_token = strtok_r(const_cast(input), delim, &temp_ptr); - while (tmp_token && index < max_token) { - tokens[index++] = tmp_token; - tmp_token = strtok_r(NULL, delim, &temp_ptr); - } - *count = index; - - return 0; -} - -int HWDevice::ParseLine(const char *input, const char *delim, char *tokens[], - const uint32_t max_token, uint32_t *count) { - char *tmp_token = NULL; - char *temp_ptr; - uint32_t index = 0; - if (!input) { - return -1; - } - tmp_token = strtok_r(const_cast(input), delim, &temp_ptr); - while (tmp_token && index < max_token) { - tokens[index++] = tmp_token; - tmp_token = strtok_r(NULL, delim, &temp_ptr); - } - *count = index; - - return 0; -} - -bool HWDevice::EnableHotPlugDetection(int enable) { - char hpdpath[kMaxStringLength]; - const char *value = enable ? "1" : "0"; - - // Enable HPD for all pluggable devices. - for (int i = 0; i < kFBNodeMax; i++) { - HWPanelInfo panel_info; - GetHWPanelInfoByNode(i, &panel_info); - if (panel_info.is_pluggable == true) { - snprintf(hpdpath , sizeof(hpdpath), "%s%d/hpd", fb_path_, i); - - ssize_t length = SysFsWrite(hpdpath, value, 1); - if (length <= 0) { - return false; - } - } - } - - return true; -} - -void HWDevice::ResetDisplayParams() { - memset(&mdp_disp_commit_, 0, sizeof(mdp_disp_commit_)); - memset(&mdp_in_layers_, 0, sizeof(mdp_in_layers_)); - memset(&mdp_out_layer_, 0, sizeof(mdp_out_layer_)); - mdp_out_layer_.buffer.fence = -1; - hw_scale_->ResetScaleParams(); - memset(&pp_params_, 0, sizeof(pp_params_)); - memset(&igc_lut_data_, 0, sizeof(igc_lut_data_)); - - for (size_t i = 0; i < mdp_dest_scalar_data_.size(); i++) { - mdp_dest_scalar_data_[i] = {}; - } - - for (uint32_t i = 0; i < kMaxSDELayers * 2; i++) { - mdp_in_layers_[i].buffer.fence = -1; - } - - mdp_disp_commit_.version = MDP_COMMIT_VERSION_1_0; - mdp_disp_commit_.commit_v1.input_layers = mdp_in_layers_; - mdp_disp_commit_.commit_v1.output_layer = &mdp_out_layer_; - mdp_disp_commit_.commit_v1.release_fence = -1; - mdp_disp_commit_.commit_v1.retire_fence = -1; - mdp_disp_commit_.commit_v1.dest_scaler = mdp_dest_scalar_data_.data(); -} - -void HWDevice::SetCSC(const ColorMetaData &color_metadata, mdp_color_space *color_space) { - switch (color_metadata.colorPrimaries) { - case ColorPrimaries_BT601_6_525: - case ColorPrimaries_BT601_6_625: - *color_space = ((color_metadata.range == Range_Full) ? MDP_CSC_ITU_R_601_FR : - MDP_CSC_ITU_R_601); - break; - case ColorPrimaries_BT709_5: - *color_space = MDP_CSC_ITU_R_709; - break; -#if defined MDP_CSC_ITU_R_2020 && defined MDP_CSC_ITU_R_2020_FR - case ColorPrimaries_BT2020: - *color_space = static_cast((color_metadata.range == Range_Full) ? - MDP_CSC_ITU_R_2020_FR : MDP_CSC_ITU_R_2020); - break; -#endif - default: - break; - } -} - -void HWDevice::SetIGC(const LayerBuffer *layer_buffer, uint32_t index) { - mdp_input_layer &mdp_layer = mdp_in_layers_[index]; - mdp_overlay_pp_params &pp_params = pp_params_[index]; - mdp_igc_lut_data_v1_7 &igc_lut_data = igc_lut_data_[index]; - - switch (layer_buffer->igc) { - case kIGCsRGB: - igc_lut_data.table_fmt = mdp_igc_srgb; - pp_params.igc_cfg.ops = MDP_PP_OPS_WRITE | MDP_PP_OPS_ENABLE; - break; - - default: - pp_params.igc_cfg.ops = MDP_PP_OPS_DISABLE; - break; - } - - pp_params.config_ops = MDP_OVERLAY_PP_IGC_CFG; - pp_params.igc_cfg.version = mdp_igc_v1_7; - pp_params.igc_cfg.cfg_payload = &igc_lut_data; - - mdp_layer.pp_info = &pp_params; - mdp_layer.flags |= MDP_LAYER_PP; -} - -DisplayError HWDevice::SetCursorPosition(HWLayers *hw_layers, int x, int y) { - DTRACE_SCOPED(); - - HWLayersInfo &hw_layer_info = hw_layers->info; - uint32_t count = UINT32(hw_layer_info.hw_layers.size()); - uint32_t cursor_index = count - 1; - HWPipeInfo *left_pipe = &hw_layers->config[cursor_index].left_pipe; - - mdp_async_layer async_layer = {}; - async_layer.flags = MDP_LAYER_ASYNC; - async_layer.pipe_ndx = left_pipe->pipe_id; - async_layer.src.x = UINT32(left_pipe->src_roi.left); - async_layer.src.y = UINT32(left_pipe->src_roi.top); - async_layer.dst.x = UINT32(left_pipe->dst_roi.left); - async_layer.dst.y = UINT32(left_pipe->dst_roi.top); - - mdp_position_update pos_update = {}; - pos_update.input_layer_cnt = 1; - pos_update.input_layers = &async_layer; - if (Sys::ioctl_(device_fd_, INT(MSMFB_ASYNC_POSITION_UPDATE), &pos_update) < 0) { - if (errno == ESHUTDOWN) { - DLOGI_IF(kTagDriverConfig, "Driver is processing shutdown sequence"); - return kErrorShutDown; - } - IOCTL_LOGE(MSMFB_ASYNC_POSITION_UPDATE, device_type_); - return kErrorHardware; - } - - return kErrorNone; -} - -DisplayError HWDevice::GetPPFeaturesVersion(PPFeatureVersion *vers) { - return kErrorNotSupported; -} - -DisplayError HWDevice::SetPPFeatures(PPFeaturesConfig *feature_list) { - return kErrorNotSupported; -} - -DisplayError HWDevice::SetVSyncState(bool enable) { - int vsync_on = enable ? 1 : 0; - if (Sys::ioctl_(device_fd_, MSMFB_OVERLAY_VSYNC_CTRL, &vsync_on) < 0) { - if (errno == ESHUTDOWN) { - DLOGI_IF(kTagDriverConfig, "Driver is processing shutdown sequence"); - return kErrorShutDown; - } - IOCTL_LOGE(MSMFB_OVERLAY_VSYNC_CTRL, device_type_); - return kErrorHardware; - } - return kErrorNone; -} - -void HWDevice::SetIdleTimeoutMs(uint32_t timeout_ms) { -} - -DisplayError HWDevice::SetDisplayMode(const HWDisplayMode hw_display_mode) { - return kErrorNotSupported; -} - -DisplayError HWDevice::SetRefreshRate(uint32_t refresh_rate) { - return kErrorNotSupported; -} - -DisplayError HWDevice::SetPanelBrightness(int level) { - return kErrorNotSupported; -} - -DisplayError HWDevice::GetHWScanInfo(HWScanInfo *scan_info) { - return kErrorNotSupported; -} - -DisplayError HWDevice::GetVideoFormat(uint32_t config_index, uint32_t *video_format) { - return kErrorNotSupported; -} - -DisplayError HWDevice::GetMaxCEAFormat(uint32_t *max_cea_format) { - return kErrorNotSupported; -} - -DisplayError HWDevice::OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level) { - return kErrorNotSupported; -} - -DisplayError HWDevice::GetPanelBrightness(int *level) { - return kErrorNotSupported; -} - -ssize_t HWDevice::SysFsWrite(const char* file_node, const char* value, ssize_t length) { - int fd = Sys::open_(file_node, O_RDWR, 0); - if (fd < 0) { - DLOGW("Open failed = %s", file_node); - return -1; - } - ssize_t len = Sys::pwrite_(fd, value, static_cast(length), 0); - if (len <= 0) { - DLOGE("Write failed for path %s with value %s", file_node, value); - } - Sys::close_(fd); - - return len; -} - -bool HWDevice::IsFBNodeConnected(int fb_node) { - string file_name = fb_path_ + to_string(fb_node) + "/connected"; - - Sys::fstream fs(file_name, fstream::in); - if (!fs.is_open()) { - DLOGW("File not found %s", file_name.c_str()); - return false; - } - - string line; - if (!Sys::getline_(fs, line)) { - return false; - } - - return atoi(line.c_str()); -} - -DisplayError HWDevice::SetS3DMode(HWS3DMode s3d_mode) { - return kErrorNotSupported; -} - -DisplayError HWDevice::SetScaleLutConfig(HWScaleLutInfo *lut_info) { - mdp_scale_luts_info mdp_lut_info = {}; - mdp_set_cfg cfg = {}; - - if (!hw_resource_.has_qseed3) { - DLOGV_IF(kTagDriverConfig, "No support for QSEED3 luts"); - return kErrorNone; - } - - if (!lut_info->dir_lut_size && !lut_info->dir_lut && !lut_info->cir_lut_size && - !lut_info->cir_lut && !lut_info->sep_lut_size && !lut_info->sep_lut) { - // HWSupports QSEED3, but LutInfo is invalid as scalar is disabled by property or - // its loading failed. Driver will use default settings/filter - return kErrorNone; - } - - mdp_lut_info.dir_lut_size = lut_info->dir_lut_size; - mdp_lut_info.dir_lut = lut_info->dir_lut; - mdp_lut_info.cir_lut_size = lut_info->cir_lut_size; - mdp_lut_info.cir_lut = lut_info->cir_lut; - mdp_lut_info.sep_lut_size = lut_info->sep_lut_size; - mdp_lut_info.sep_lut = lut_info->sep_lut; - - cfg.flags = MDP_QSEED3_LUT_CFG; - cfg.len = sizeof(mdp_scale_luts_info); - cfg.payload = reinterpret_cast(&mdp_lut_info); - - if (Sys::ioctl_(device_fd_, MSMFB_MDP_SET_CFG, &cfg) < 0) { - if (errno == ESHUTDOWN) { - DLOGI_IF(kTagDriverConfig, "Driver is processing shutdown sequence"); - return kErrorShutDown; - } - IOCTL_LOGE(MSMFB_MDP_SET_CFG, device_type_); - return kErrorHardware; - } - - return kErrorNone; -} - -DisplayError HWDevice::SetMixerAttributes(const HWMixerAttributes &mixer_attributes) { - if (!hw_resource_.hw_dest_scalar_info.count) { - return kErrorNotSupported; - } - - if (mixer_attributes.width > display_attributes_.x_pixels || - mixer_attributes.height > display_attributes_.y_pixels) { - DLOGW_IF(kTagDriverConfig, "Input resolution exceeds display resolution! input: res %dx%d "\ - "display: res %dx%d", mixer_attributes.width, mixer_attributes.height, - display_attributes_.x_pixels, display_attributes_.y_pixels); - return kErrorNotSupported; - } - - uint32_t max_input_width = hw_resource_.hw_dest_scalar_info.max_input_width; - if (display_attributes_.is_device_split) { - max_input_width *= 2; - } - - if (mixer_attributes.width > max_input_width) { - DLOGW_IF(kTagDriverConfig, "Input width exceeds width limit! input_width %d width_limit %d", - mixer_attributes.width, max_input_width); - return kErrorNotSupported; - } - - float mixer_aspect_ratio = FLOAT(mixer_attributes.width) / FLOAT(mixer_attributes.height); - float display_aspect_ratio = - FLOAT(display_attributes_.x_pixels) / FLOAT(display_attributes_.y_pixels); - - if (display_aspect_ratio != mixer_aspect_ratio) { - DLOGW_IF(kTagDriverConfig, "Aspect ratio mismatch! input: res %dx%d display: res %dx%d", - mixer_attributes.width, mixer_attributes.height, display_attributes_.x_pixels, - display_attributes_.y_pixels); - return kErrorNotSupported; - } - - float scale_x = FLOAT(display_attributes_.x_pixels) / FLOAT(mixer_attributes.width); - float scale_y = FLOAT(display_attributes_.y_pixels) / FLOAT(mixer_attributes.height); - float max_scale_up = hw_resource_.hw_dest_scalar_info.max_scale_up; - if (scale_x > max_scale_up || scale_y > max_scale_up) { - DLOGW_IF(kTagDriverConfig, "Up scaling ratio exceeds for destination scalar upscale " \ - "limit scale_x %f scale_y %f max_scale_up %f", scale_x, scale_y, max_scale_up); - return kErrorNotSupported; - } - - float mixer_split_ratio = FLOAT(mixer_attributes_.split_left) / FLOAT(mixer_attributes_.width); - - mixer_attributes_ = mixer_attributes; - mixer_attributes_.split_left = mixer_attributes_.width; - if (display_attributes_.is_device_split) { - mixer_attributes_.split_left = UINT32(FLOAT(mixer_attributes.width) * mixer_split_ratio); - } - - return kErrorNone; -} - -DisplayError HWDevice::GetMixerAttributes(HWMixerAttributes *mixer_attributes) { - if (!mixer_attributes) { - return kErrorParameters; - } - - *mixer_attributes = mixer_attributes_; - - return kErrorNone; -} - -DisplayError HWDevice::DumpDebugData() { - DLOGW("Pingpong timeout occurred in the driver."); -#ifdef USER_DEBUG - // Save the xlogs on ping pong time out - const char* xlog_path = "/data/vendor/display/mdp_xlog"; - DLOGD("Dumping debugfs data to %s", xlog_path); - std::ostringstream dst; - auto file = open(xlog_path, O_CREAT | O_TRUNC | O_DSYNC | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP); - if (file < 0) { - DLOGE("Couldn't open file: err:%d (%s)", errno, strerror(errno)); - return kErrorResources; - } - dst << "+++ MDP:XLOG +++" << std::endl; - std::ifstream src("/sys/kernel/debug/mdp/xlog/dump"); - dst << src.rdbuf() << std::endl; - src.close(); - - dst << "+++ MDP:REG_XLOG +++" << std::endl; - src.open("/sys/kernel/debug/mdp/xlog/reg_xlog"); - dst << src.rdbuf() << std::endl; - src.close(); - - dst << "+++ MDP:DBGBUS_XLOG +++" << std::endl; - src.open("/sys/kernel/debug/mdp/xlog/dbgbus_xlog"); - dst << src.rdbuf() << std::endl; - src.close(); - - dst << "+++ MDP:VBIF_DBGBUS_XLOG +++" << std::endl; - src.open("/sys/kernel/debug/mdp/xlog/vbif_dbgbus_xlog"); - dst << src.rdbuf() << std::endl; - src.close(); - auto ret = write(file, dst.str().c_str(), dst.str().size()); - if (ret < 0) { - DLOGE("Failed to write xlog data err: %d (%s)", errno, strerror(errno)); - } else { - fsync(file); - } - close(file); - DLOGD("Finished dumping xlogs");; -#endif - return kErrorNone; -} - -} // namespace sdm - diff --git a/sdm/libs/core/fb/hw_device.h b/sdm/libs/core/fb/hw_device.h deleted file mode 100644 index fe954aee..00000000 --- a/sdm/libs/core/fb/hw_device.h +++ /dev/null @@ -1,165 +0,0 @@ -/* -* Copyright (c) 2014 - 2018, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted -* provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright notice, this list of -* conditions and the following disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its contributors may be used to -* endorse or promote products derived from this software without specific prior written -* permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __HW_DEVICE_H__ -#define __HW_DEVICE_H__ - -#include -#include -#include -#include -#include - -#include "hw_interface.h" -#include "hw_scale.h" - -#define IOCTL_LOGE(ioctl, type) DLOGE("ioctl %s, device = %d errno = %d, desc = %s", #ioctl, \ - type, errno, strerror(errno)) - -#ifndef MDP_LAYER_MULTIRECT_ENABLE -#define MDP_LAYER_MULTIRECT_ENABLE 0 -#endif - -#ifndef MDP_LAYER_MULTIRECT_PARALLEL_MODE -#define MDP_LAYER_MULTIRECT_PARALLEL_MODE 0 -#endif - -#ifndef MDP_LAYER_SECURE_CAMERA_SESSION -#define MDP_LAYER_SECURE_CAMERA_SESSION 0 -#endif - -namespace sdm { -class HWInfoInterface; - -class HWDevice : public HWInterface { - public: - virtual ~HWDevice() {} - virtual DisplayError Init(); - virtual DisplayError Deinit(); - - protected: - explicit HWDevice(BufferSyncHandler *buffer_sync_handler); - - // From HWInterface - virtual DisplayError GetActiveConfig(uint32_t *active_config); - virtual DisplayError GetNumDisplayAttributes(uint32_t *count); - virtual DisplayError GetDisplayAttributes(uint32_t index, - HWDisplayAttributes *display_attributes); - virtual DisplayError GetHWPanelInfo(HWPanelInfo *panel_info); - virtual DisplayError SetDisplayAttributes(uint32_t index); - virtual DisplayError SetDisplayAttributes(const HWDisplayAttributes &display_attributes); - virtual DisplayError GetConfigIndex(char *mode, uint32_t *index); - virtual DisplayError PowerOn(int *release_fence); - virtual DisplayError PowerOff(); - virtual DisplayError Doze(int *release_fence); - virtual DisplayError DozeSuspend(int *release_fence); - virtual DisplayError Standby(); - virtual DisplayError Validate(HWLayers *hw_layers); - virtual DisplayError Commit(HWLayers *hw_layers); - virtual DisplayError Flush(); - virtual DisplayError GetPPFeaturesVersion(PPFeatureVersion *vers); - virtual DisplayError SetPPFeatures(PPFeaturesConfig *feature_list); - virtual DisplayError SetVSyncState(bool enable); - virtual void SetIdleTimeoutMs(uint32_t timeout_ms); - virtual DisplayError SetDisplayMode(const HWDisplayMode hw_display_mode); - virtual DisplayError SetRefreshRate(uint32_t refresh_rate); - virtual DisplayError SetPanelBrightness(int level); - virtual DisplayError GetHWScanInfo(HWScanInfo *scan_info); - virtual DisplayError GetVideoFormat(uint32_t config_index, uint32_t *video_format); - virtual DisplayError GetMaxCEAFormat(uint32_t *max_cea_format); - virtual DisplayError SetCursorPosition(HWLayers *hw_layers, int x, int y); - virtual DisplayError OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level); - virtual DisplayError GetPanelBrightness(int *level); - virtual DisplayError SetAutoRefresh(bool enable) { return kErrorNone; } - virtual DisplayError SetS3DMode(HWS3DMode s3d_mode); - virtual DisplayError SetScaleLutConfig(HWScaleLutInfo *lut_info); - virtual DisplayError SetMixerAttributes(const HWMixerAttributes &mixer_attributes); - virtual DisplayError GetMixerAttributes(HWMixerAttributes *mixer_attributes); - virtual DisplayError DumpDebugData(); - - enum { - kHWEventVSync, - kHWEventBlank, - }; - - static const int kMaxStringLength = 1024; - static const int kNumPhysicalDisplays = 2; - // This indicates the number of fb devices created in the driver for all interfaces. Any addition - // of new fb devices should be added here. - static const int kFBNodeMax = 4; - - void DumpLayerCommit(const mdp_layer_commit &layer_commit); - DisplayError SetFormat(const LayerBufferFormat &source, uint32_t *target); - DisplayError SetStride(HWDeviceType device_type, LayerBufferFormat format, - uint32_t width, uint32_t *target); - void SetBlending(const LayerBlending &source, mdss_mdp_blend_op *target); - void SetRect(const LayerRect &source, mdp_rect *target); - void SetMDPFlags(const Layer *layer, const bool &is_rotator_used, - bool async_cursor_updates, uint32_t *mdp_flags); - // Retrieves HW FrameBuffer Node Index - int GetFBNodeIndex(HWDeviceType device_type); - // Populates HWPanelInfo based on node index - void PopulateHWPanelInfo(); - void GetHWPanelInfoByNode(int device_node, HWPanelInfo *panel_info); - void GetHWPanelNameByNode(int device_node, HWPanelInfo *panel_info); - void GetHWDisplayPortAndMode(int device_node, HWPanelInfo *panel_info); - void GetSplitInfo(int device_node, HWPanelInfo *panel_info); - void GetHWPanelMaxBrightnessFromNode(HWPanelInfo *panel_info); - int ParseLine(const char *input, char *tokens[], const uint32_t max_token, uint32_t *count); - int ParseLine(const char *input, const char *delim, char *tokens[], - const uint32_t max_token, uint32_t *count); - void ResetDisplayParams(); - void SetCSC(const ColorMetaData &color_metadata, mdp_color_space *color_space); - void SetIGC(const LayerBuffer *layer_buffer, uint32_t index); - - bool EnableHotPlugDetection(int enable); - ssize_t SysFsWrite(const char* file_node, const char* value, ssize_t length); - bool IsFBNodeConnected(int fb_node); - - HWResourceInfo hw_resource_; - HWPanelInfo hw_panel_info_; - HWInfoInterface *hw_info_intf_; - int fb_node_index_; - const char *fb_path_; - BufferSyncHandler *buffer_sync_handler_; - int device_fd_ = -1; - int stored_retire_fence = -1; - HWDeviceType device_type_; - mdp_layer_commit mdp_disp_commit_; - mdp_input_layer mdp_in_layers_[kMaxSDELayers * 2]; // split panel (left + right) - HWScale *hw_scale_ = NULL; - mdp_overlay_pp_params pp_params_[kMaxSDELayers * 2]; - mdp_igc_lut_data_v1_7 igc_lut_data_[kMaxSDELayers * 2]; - mdp_output_layer mdp_out_layer_; - const char *device_name_; - bool synchronous_commit_; - HWDisplayAttributes display_attributes_ = {}; - HWMixerAttributes mixer_attributes_ = {}; - std::vector mdp_dest_scalar_data_; -}; - -} // namespace sdm - -#endif // __HW_DEVICE_H__ - diff --git a/sdm/libs/core/fb/hw_events.cpp b/sdm/libs/core/fb/hw_events.cpp deleted file mode 100644 index d9446240..00000000 --- a/sdm/libs/core/fb/hw_events.cpp +++ /dev/null @@ -1,257 +0,0 @@ -/* -* Copyright (c) 2015 - 2017, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "hw_events.h" - -#define __CLASS__ "HWEvents" - -namespace sdm { - -pollfd HWEvents::InitializePollFd(HWEventData *event_data) { - char node_path[kMaxStringLength] = {0}; - char data[kMaxStringLength] = {0}; - pollfd poll_fd = {0}; - poll_fd.fd = -1; - - if (event_data->event_type == HWEvent::EXIT) { - // Create an eventfd to be used to unblock the poll system call when - // a thread is exiting. - poll_fd.fd = Sys::eventfd_(0, 0); - poll_fd.events |= POLLIN; - exit_fd_ = poll_fd.fd; - } else { - snprintf(node_path, sizeof(node_path), "%s%d/%s", fb_path_, fb_num_, - map_event_to_node_[event_data->event_type]); - poll_fd.fd = Sys::open_(node_path, O_RDONLY); - poll_fd.events |= POLLPRI | POLLERR; - } - - if (poll_fd.fd < 0) { - DLOGW("open failed for display=%d event=%s, error=%s", fb_num_, - map_event_to_node_[event_data->event_type], strerror(errno)); - return poll_fd; - } - - // Read once on all fds to clear data on all fds. - Sys::pread_(poll_fd.fd, data , kMaxStringLength, 0); - - return poll_fd; -} - -DisplayError HWEvents::SetEventParser(HWEvent event_type, HWEventData *event_data) { - DisplayError error = kErrorNone; - switch (event_type) { - case HWEvent::VSYNC: - event_data->event_parser = &HWEvents::HandleVSync; - break; - case HWEvent::IDLE_NOTIFY: - event_data->event_parser = &HWEvents::HandleIdleTimeout; - break; - case HWEvent::CEC_READ_MESSAGE: - event_data->event_parser = &HWEvents::HandleCECMessage; - break; - case HWEvent::EXIT: - event_data->event_parser = &HWEvents::HandleThreadExit; - break; - case HWEvent::SHOW_BLANK_EVENT: - event_data->event_parser = &HWEvents::HandleBlank; - break; - case HWEvent::THERMAL_LEVEL: - event_data->event_parser = &HWEvents::HandleThermal; - break; - case HWEvent::IDLE_POWER_COLLAPSE: - event_data->event_parser = &HWEvents::HandleIdlePowerCollapse; - break; - case HWEvent::PINGPONG_TIMEOUT: - event_data->event_parser = &HWEvents::HandlePingPongTimeout; - break; - default: - error = kErrorParameters; - break; - } - - return error; -} - -void HWEvents::PopulateHWEventData() { - for (uint32_t i = 0; i < event_list_.size(); i++) { - HWEventData event_data; - event_data.event_type = event_list_[i]; - SetEventParser(event_list_[i], &event_data); - poll_fds_[i] = InitializePollFd(&event_data); - event_data_list_.push_back(event_data); - } -} - -DisplayError HWEvents::Init(int fb_num, HWEventHandler *event_handler, - const vector &event_list, - const HWInterface *hw_intf) { - if (!event_handler) - return kErrorParameters; - - event_handler_ = event_handler; - fb_num_ = fb_num; - event_list_ = event_list; - poll_fds_.resize(event_list_.size()); - event_thread_name_ += " - " + std::to_string(fb_num_); - map_event_to_node_ = {{HWEvent::VSYNC, "vsync_event"}, - {HWEvent::EXIT, "thread_exit"}, - {HWEvent::IDLE_NOTIFY, "idle_notify"}, - {HWEvent::SHOW_BLANK_EVENT, "show_blank_event"}, - {HWEvent::CEC_READ_MESSAGE, "cec/rd_msg"}, - {HWEvent::THERMAL_LEVEL, "msm_fb_thermal_level"}, - {HWEvent::IDLE_POWER_COLLAPSE, "idle_power_collapse"}, - {HWEvent::PINGPONG_TIMEOUT, "pingpong_timeout"}}; - - PopulateHWEventData(); - - if (pthread_create(&event_thread_, NULL, &DisplayEventThread, this) < 0) { - DLOGE("Failed to start %s, error = %s", event_thread_name_.c_str()); - return kErrorResources; - } - - return kErrorNone; -} - -DisplayError HWEvents::Deinit() { - exit_threads_ = true; - Sys::pthread_cancel_(event_thread_); - - uint64_t exit_value = 1; - ssize_t write_size = Sys::write_(exit_fd_, &exit_value, sizeof(uint64_t)); - if (write_size != sizeof(uint64_t)) - DLOGW("Error triggering exit_fd_ (%d). write size = %d, error = %s", exit_fd_, write_size, - strerror(errno)); - - pthread_join(event_thread_, NULL); - - for (uint32_t i = 0; i < event_list_.size(); i++) { - Sys::close_(poll_fds_[i].fd); - poll_fds_[i].fd = -1; - } - - return kErrorNone; -} - -void* HWEvents::DisplayEventThread(void *context) { - if (context) { - return reinterpret_cast(context)->DisplayEventHandler(); - } - - return NULL; -} - -void* HWEvents::DisplayEventHandler() { - char data[kMaxStringLength] = {0}; - - prctl(PR_SET_NAME, event_thread_name_.c_str(), 0, 0, 0); - setpriority(PRIO_PROCESS, 0, kThreadPriorityUrgent); - - while (!exit_threads_) { - int error = Sys::poll_(poll_fds_.data(), UINT32(event_list_.size()), -1); - - if (error <= 0) { - DLOGW("poll failed. error = %s", strerror(errno)); - continue; - } - - for (uint32_t event = 0; event < event_list_.size(); event++) { - pollfd &poll_fd = poll_fds_[event]; - - if (event_list_.at(event) == HWEvent::EXIT) { - if ((poll_fd.revents & POLLIN) && (Sys::read_(poll_fd.fd, data, kMaxStringLength) > 0)) { - (this->*(event_data_list_[event]).event_parser)(data); - } - } else { - if ((poll_fd.revents & POLLPRI) && - (Sys::pread_(poll_fd.fd, data, kMaxStringLength, 0) > 0)) { - (this->*(event_data_list_[event]).event_parser)(data); - } - } - } - } - - pthread_exit(0); - - return NULL; -} - -void HWEvents::HandleVSync(char *data) { - int64_t timestamp = 0; - if (!strncmp(data, "VSYNC=", strlen("VSYNC="))) { - timestamp = strtoll(data + strlen("VSYNC="), NULL, 0); - } - - event_handler_->VSync(timestamp); -} - -void HWEvents::HandleIdleTimeout(char *data) { - event_handler_->IdleTimeout(); -} - -void HWEvents::HandlePingPongTimeout(char *data) { - event_handler_->PingPongTimeout(); -} - -void HWEvents::HandleThermal(char *data) { - int64_t thermal_level = 0; - if (!strncmp(data, "thermal_level=", strlen("thermal_level="))) { - thermal_level = strtoll(data + strlen("thermal_level="), NULL, 0); - } - - DLOGI("Received thermal notification with thermal level = %d", thermal_level); - - event_handler_->ThermalEvent(thermal_level); -} - -void HWEvents::HandleCECMessage(char *data) { - event_handler_->CECMessage(data); -} - -void HWEvents::HandleIdlePowerCollapse(char *data) { - event_handler_->IdlePowerCollapse(); -} - -} // namespace sdm diff --git a/sdm/libs/core/fb/hw_events.h b/sdm/libs/core/fb/hw_events.h deleted file mode 100644 index 8ffd6d54..00000000 --- a/sdm/libs/core/fb/hw_events.h +++ /dev/null @@ -1,92 +0,0 @@ -/* -* Copyright (c) 2015 - 2017, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted -* provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright notice, this list of -* conditions and the following disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its contributors may be used to -* endorse or promote products derived from this software without specific prior written -* permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __HW_EVENTS_H__ -#define __HW_EVENTS_H__ - -#include -#include -#include -#include -#include - -#include "hw_interface.h" -#include "hw_events_interface.h" - -namespace sdm { - -using std::vector; -using std::map; - -class HWEvents : public HWEventsInterface { - public: - virtual DisplayError Init(int fb_num, HWEventHandler *event_handler, - const vector &event_list, - const HWInterface *hw_intf); - virtual DisplayError Deinit(); - virtual DisplayError SetEventState(HWEvent event, bool enable, void *aux = nullptr) { - return kErrorNotSupported; - } - - private: - static const int kMaxStringLength = 1024; - - typedef void (HWEvents::*EventParser)(char *); - - struct HWEventData { - HWEvent event_type {}; - EventParser event_parser {}; - }; - - static void* DisplayEventThread(void *context); - void* DisplayEventHandler(); - void HandleVSync(char *data); - void HandleBlank(char *data) { } - void HandleIdleTimeout(char *data); - void HandleThermal(char *data); - void HandleCECMessage(char *data); - void HandleThreadExit(char *data) { } - void HandleIdlePowerCollapse(char *data); - void HandlePingPongTimeout(char *data); - void PopulateHWEventData(); - DisplayError SetEventParser(HWEvent event_type, HWEventData *event_data); - pollfd InitializePollFd(HWEventData *event_data); - - HWEventHandler *event_handler_ = {}; - vector event_list_ = {}; - vector event_data_list_ = {}; - vector poll_fds_ = {}; - map map_event_to_node_ = {}; - pthread_t event_thread_ = {}; - std::string event_thread_name_ = "SDM_EventThread"; - bool exit_threads_ = false; - const char* fb_path_ = "/sys/devices/virtual/graphics/fb"; - int fb_num_ = -1; - int exit_fd_ = -1; -}; - -} // namespace sdm - -#endif // __HW_EVENTS_H__ - diff --git a/sdm/libs/core/fb/hw_hdmi.cpp b/sdm/libs/core/fb/hw_hdmi.cpp deleted file mode 100644 index 532c3ba1..00000000 --- a/sdm/libs/core/fb/hw_hdmi.cpp +++ /dev/null @@ -1,1123 +0,0 @@ -/* -* Copyright (c) 2015 - 2018, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without -* modification, are permitted provided that the following conditions are -* met: -* * Redistributions of source code must retain the above copyright -* notice, this list of conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above -* copyright notice, this list of conditions and the following -* disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its -* contributors may be used to endorse or promote products derived -* from this software without specific prior written permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED -* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT -* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS -* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR -* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE -* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN -* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "hw_hdmi.h" - -#define __CLASS__ "HWHDMI" - -#define MIN_HDR_RESET_WAITTIME_SEC 2 - -namespace sdm { - -#ifdef MDP_HDR_STREAM -static int32_t GetEOTF(const GammaTransfer &transfer) { - int32_t mdp_transfer = -1; - - switch (transfer) { - case Transfer_SMPTE_ST2084: - mdp_transfer = MDP_HDR_EOTF_SMTPE_ST2084; - break; - case Transfer_HLG: - mdp_transfer = MDP_HDR_EOTF_HLG; - break; - default: - DLOGW("Unknown Transfer: %d", transfer); - } - - return mdp_transfer; -} - -static int32_t GetColoriMetry(const LayerBuffer & layer_buffer) { - bool is_yuv = layer_buffer.flags.video; - int32_t colorimetry = -1; - - if (is_yuv) { - switch (layer_buffer.color_metadata.colorPrimaries) { - case ColorPrimaries_BT601_6_525: - case ColorPrimaries_BT601_6_625: - colorimetry = MDP_COLORIMETRY_YCBCR_ITU_R_BT_601; - break; - case ColorPrimaries_BT709_5: - colorimetry = MDP_COLORIMETRY_YCBCR_ITU_R_BT_709; - break; - case ColorPrimaries_BT2020: - colorimetry = MDP_COLORIMETRY_YCBCR_ITU_R_BT_2020_YCBCR; - break; - default: - DLOGW("Unknown color primary = %d for YUV", layer_buffer.color_metadata.colorPrimaries); - } - } - - return colorimetry; -} - -static int32_t GetPixelEncoding(const LayerBuffer &layer_buffer) { - bool is_yuv = layer_buffer.flags.video; - int32_t mdp_pixel_encoding = -1; - mdp_pixel_encoding = MDP_PIXEL_ENCODING_RGB; // set RGB as default - - if (is_yuv) { - switch (layer_buffer.format) { - case kFormatYCbCr420SemiPlanarVenus: - case kFormatYCbCr420SPVenusUbwc: - case kFormatYCbCr420Planar: - case kFormatYCrCb420Planar: - case kFormatYCrCb420PlanarStride16: - case kFormatYCbCr420SemiPlanar: - case kFormatYCrCb420SemiPlanar: - case kFormatYCbCr420P010: - case kFormatYCbCr420TP10Ubwc: - mdp_pixel_encoding = MDP_PIXEL_ENCODING_YCBCR_420; - break; - case kFormatYCbCr422H2V1Packed: - case kFormatYCrCb422H2V1SemiPlanar: - case kFormatYCrCb422H1V2SemiPlanar: - case kFormatYCbCr422H2V1SemiPlanar: - case kFormatYCbCr422H1V2SemiPlanar: - mdp_pixel_encoding = MDP_PIXEL_ENCODING_YCBCR_422; - break; - default: // other yuv formats - DLOGW("New YUV format = %d, need to add support", layer_buffer.format); - break; - } - } - - return mdp_pixel_encoding; -} -static int32_t GetBitsPerComponent(const LayerBuffer &layer_buffer) { - bool is_yuv = layer_buffer.flags.video; - bool is_10_bit = Is10BitFormat(layer_buffer.format); - int32_t mdp_bpc = -1; - - if (is_yuv) { - mdp_bpc = is_10_bit ? MDP_YUV_10_BPC : MDP_YUV_8_BPC; - } else { - mdp_bpc = is_10_bit ? MDP_RGB_10_BPC : MDP_RGB_8_BPC; - } - - return mdp_bpc; -} - -static uint32_t GetRange(const ColorRange &range) { - return ((range == Range_Full) ? MDP_DYNAMIC_RANGE_VESA : MDP_DYNAMIC_RANGE_CEA); -} - -static uint32_t GetContentType(const LayerBuffer &layer_buffer) { - return (layer_buffer.flags.video ? MDP_CONTENT_TYPE_VIDEO : MDP_CONTENT_TYPE_GRAPHICS); -} -#endif - -static bool MapHDMIDisplayTiming(const msm_hdmi_mode_timing_info *mode, - fb_var_screeninfo *info) { - if (!mode || !info) { - return false; - } - - info->reserved[0] = 0; - info->reserved[1] = 0; - info->reserved[2] = 0; - info->reserved[3] = (info->reserved[3] & 0xFFFF) | (mode->video_format << 16); - info->xoffset = 0; - info->yoffset = 0; - info->xres = mode->active_h; - info->yres = mode->active_v; - info->pixclock = (mode->pixel_freq) * 1000; - info->vmode = mode->interlaced ? FB_VMODE_INTERLACED : FB_VMODE_NONINTERLACED; - info->right_margin = mode->front_porch_h; - info->hsync_len = mode->pulse_width_h; - info->left_margin = mode->back_porch_h; - info->lower_margin = mode->front_porch_v; - info->vsync_len = mode->pulse_width_v; - info->upper_margin = mode->back_porch_v; - - info->grayscale = V4L2_PIX_FMT_RGB24; - // If the mode supports YUV420 set grayscale to the FOURCC value for YUV420. - std::bitset<32> pixel_formats = mode->pixel_formats; - if (pixel_formats[1]) { - info->grayscale = V4L2_PIX_FMT_NV12; - } - - return true; -} - -HWHDMI::HWHDMI(BufferSyncHandler *buffer_sync_handler, HWInfoInterface *hw_info_intf) - : HWDevice(buffer_sync_handler), hw_scan_info_(), active_config_index_(0) { - HWDevice::device_type_ = kDeviceHDMI; - HWDevice::device_name_ = "HDMI Display Device"; - HWDevice::hw_info_intf_ = hw_info_intf; - (void)hdr_reset_start_; - (void)hdr_reset_end_; - (void)reset_hdr_flag_; - (void)cdm_color_space_; -} - -DisplayError HWHDMI::Init() { - DisplayError error = kErrorNone; - - SetSourceProductInformation("vendor_name", "ro.product.manufacturer"); - SetSourceProductInformation("product_description", "ro.product.name"); - - error = HWDevice::Init(); - if (error != kErrorNone) { - return error; - } - - mdp_dest_scalar_data_.resize(hw_resource_.hw_dest_scalar_info.count); - - error = ReadEDIDInfo(); - if (error != kErrorNone) { - Deinit(); - return error; - } - - if (!IsResolutionFilePresent()) { - Deinit(); - return kErrorHardware; - } - - error = ReadTimingInfo(); - if (error != kErrorNone) { - Deinit(); - return error; - } - - ReadScanInfo(); - - GetPanelS3DMode(); - - s3d_mode_sdm_to_mdp_.insert(std::pair - (kS3DModeNone, HDMI_S3D_NONE)); - s3d_mode_sdm_to_mdp_.insert(std::pair - (kS3DModeLR, HDMI_S3D_SIDE_BY_SIDE)); - s3d_mode_sdm_to_mdp_.insert(std::pair - (kS3DModeRL, HDMI_S3D_SIDE_BY_SIDE)); - s3d_mode_sdm_to_mdp_.insert(std::pair - (kS3DModeTB, HDMI_S3D_TOP_AND_BOTTOM)); - s3d_mode_sdm_to_mdp_.insert(std::pair - (kS3DModeFP, HDMI_S3D_FRAME_PACKING)); - - return error; -} - -DisplayError HWHDMI::GetNumDisplayAttributes(uint32_t *count) { - *count = UINT32(hdmi_modes_.size()); - if (*count <= 0) { - return kErrorHardware; - } - - return kErrorNone; -} - -DisplayError HWHDMI::GetActiveConfig(uint32_t *active_config_index) { - *active_config_index = active_config_index_; - return kErrorNone; -} - -DisplayError HWHDMI::ReadEDIDInfo() { - ssize_t length = -1; - char edid_str[kPageSize] = {'\0'}; - char edid_path[kMaxStringLength] = {'\0'}; - snprintf(edid_path, sizeof(edid_path), "%s%d/edid_modes", fb_path_, fb_node_index_); - int edid_file = Sys::open_(edid_path, O_RDONLY); - if (edid_file < 0) { - DLOGE("EDID file open failed."); - return kErrorHardware; - } - - length = Sys::pread_(edid_file, edid_str, sizeof(edid_str)-1, 0); - if (length <= 0) { - DLOGE("%s: edid_modes file empty"); - return kErrorHardware; - } - Sys::close_(edid_file); - - DLOGI("EDID mode string: %s", edid_str); - while (length > 1 && isspace(edid_str[length-1])) { - --length; - } - edid_str[length] = '\0'; - - if (length > 0) { - // Get EDID modes from the EDID string - char *ptr = edid_str; - const uint32_t edid_count_max = 128; - char *tokens[edid_count_max] = { NULL }; - uint32_t hdmi_mode_count = 0; - - ParseLine(ptr, tokens, edid_count_max, &hdmi_mode_count); - - supported_video_modes_.resize(hdmi_mode_count); - - hdmi_modes_.resize(hdmi_mode_count); - for (uint32_t i = 0; i < hdmi_mode_count; i++) { - hdmi_modes_[i] = UINT32(atoi(tokens[i])); - } - } - - return kErrorNone; -} - -DisplayError HWHDMI::GetDisplayAttributes(uint32_t index, - HWDisplayAttributes *display_attributes) { - DTRACE_SCOPED(); - - if (index >= hdmi_modes_.size()) { - return kErrorNotSupported; - } - - // Get the resolution info from the look up table - msm_hdmi_mode_timing_info *timing_mode = &supported_video_modes_[0]; - for (uint32_t i = 0; i < hdmi_modes_.size(); i++) { - msm_hdmi_mode_timing_info *cur = &supported_video_modes_[i]; - if (cur->video_format == hdmi_modes_[index]) { - timing_mode = cur; - break; - } - } - display_attributes->x_pixels = timing_mode->active_h; - display_attributes->y_pixels = timing_mode->active_v; - display_attributes->v_front_porch = timing_mode->front_porch_v; - display_attributes->v_back_porch = timing_mode->back_porch_v; - display_attributes->v_pulse_width = timing_mode->pulse_width_v; - uint32_t h_blanking = timing_mode->front_porch_h + timing_mode->back_porch_h + - timing_mode->pulse_width_h; - display_attributes->h_total = timing_mode->active_h + h_blanking; - display_attributes->x_dpi = 0; - display_attributes->y_dpi = 0; - display_attributes->fps = timing_mode->refresh_rate / 1000; - display_attributes->vsync_period_ns = UINT32(1000000000L / display_attributes->fps); - display_attributes->is_device_split = false; - if (display_attributes->x_pixels > hw_resource_.max_mixer_width) { - display_attributes->is_device_split = true; - display_attributes->h_total += h_blanking; - } - - GetDisplayS3DSupport(index, display_attributes); - std::bitset<32> pixel_formats = timing_mode->pixel_formats; - - display_attributes->is_yuv = pixel_formats[1]; - - return kErrorNone; -} - -DisplayError HWHDMI::SetDisplayAttributes(uint32_t index) { - DTRACE_SCOPED(); - - if (index > hdmi_modes_.size()) { - return kErrorNotSupported; - } - - // Variable screen info - fb_var_screeninfo vscreeninfo = {}; - if (Sys::ioctl_(device_fd_, FBIOGET_VSCREENINFO, &vscreeninfo) < 0) { - IOCTL_LOGE(FBIOGET_VSCREENINFO, device_type_); - return kErrorHardware; - } - - DLOGI("GetInfo", vscreeninfo.reserved[3], - vscreeninfo.xres, vscreeninfo.yres, vscreeninfo.right_margin, vscreeninfo.hsync_len, - vscreeninfo.left_margin, vscreeninfo.lower_margin, vscreeninfo.vsync_len, - vscreeninfo.upper_margin, vscreeninfo.pixclock/1000000); - - msm_hdmi_mode_timing_info *timing_mode = &supported_video_modes_[0]; - for (uint32_t i = 0; i < hdmi_modes_.size(); i++) { - msm_hdmi_mode_timing_info *cur = &supported_video_modes_[i]; - if (cur->video_format == hdmi_modes_[index]) { - timing_mode = cur; - break; - } - } - - if (MapHDMIDisplayTiming(timing_mode, &vscreeninfo) == false) { - return kErrorParameters; - } - - msmfb_metadata metadata = {}; - metadata.op = metadata_op_vic; - metadata.data.video_info_code = timing_mode->video_format; - if (Sys::ioctl_(device_fd_, MSMFB_METADATA_SET, &metadata) < 0) { - IOCTL_LOGE(MSMFB_METADATA_SET, device_type_); - return kErrorHardware; - } - - DLOGI("SetInfo", vscreeninfo.reserved[3] & 0xFF00, - vscreeninfo.xres, vscreeninfo.yres, vscreeninfo.right_margin, vscreeninfo.hsync_len, - vscreeninfo.left_margin, vscreeninfo.lower_margin, vscreeninfo.vsync_len, - vscreeninfo.upper_margin, vscreeninfo.pixclock/1000000); - - vscreeninfo.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_ALL | FB_ACTIVATE_FORCE; - if (Sys::ioctl_(device_fd_, FBIOPUT_VSCREENINFO, &vscreeninfo) < 0) { - IOCTL_LOGE(FBIOPUT_VSCREENINFO, device_type_); - return kErrorHardware; - } - - active_config_index_ = index; - - frame_rate_ = timing_mode->refresh_rate; - - // Get the display attributes for current active config index - GetDisplayAttributes(active_config_index_, &display_attributes_); - UpdateMixerAttributes(); - - supported_s3d_modes_.clear(); - supported_s3d_modes_.push_back(kS3DModeNone); - for (uint32_t mode = kS3DModeNone + 1; mode < kS3DModeMax; mode ++) { - if (display_attributes_.s3d_config[(HWS3DMode)mode]) { - supported_s3d_modes_.push_back((HWS3DMode)mode); - } - } - - SetS3DMode(kS3DModeNone); - - return kErrorNone; -} - -DisplayError HWHDMI::GetConfigIndex(char *mode, uint32_t *index) { - std::string str(mode); - uint32_t value = UINT32(stoi(str)); - - // Check if the mode is valid and return corresponding index - for (uint32_t i = 0; i < hdmi_modes_.size(); i++) { - if (hdmi_modes_[i] == value) { - *index = i; - DLOGI("Index = %d for config = %d", *index, value); - return kErrorNone; - } - } - - DLOGE("Config = %d not supported", value); - return kErrorNotSupported; -} - -DisplayError HWHDMI::Validate(HWLayers *hw_layers) { - HWDevice::ResetDisplayParams(); - return HWDevice::Validate(hw_layers); -} - -DisplayError HWHDMI::Commit(HWLayers *hw_layers) { - DisplayError error = UpdateHDRMetaData(hw_layers); - if (error != kErrorNone) { - return error; - } - if (cdm_color_space_commit_) { -#ifdef MDP_COMMIT_UPDATE_CDM_COLOR_SPACE - mdp_layer_commit_v1 &mdp_commit = mdp_disp_commit_.commit_v1; - mdp_commit.cdm_color_space = cdm_color_space_; - mdp_commit.flags |= MDP_COMMIT_UPDATE_CDM_COLOR_SPACE; -#endif - } - - error = HWDevice::Commit(hw_layers); - if (cdm_color_space_commit_) - cdm_color_space_commit_ = false; - - return error; -} - -DisplayError HWHDMI::GetHWScanInfo(HWScanInfo *scan_info) { - if (!scan_info) { - return kErrorParameters; - } - *scan_info = hw_scan_info_; - return kErrorNone; -} - -DisplayError HWHDMI::GetVideoFormat(uint32_t config_index, uint32_t *video_format) { - if (config_index > hdmi_modes_.size()) { - return kErrorNotSupported; - } - - *video_format = hdmi_modes_[config_index]; - - return kErrorNone; -} - -DisplayError HWHDMI::GetMaxCEAFormat(uint32_t *max_cea_format) { - *max_cea_format = HDMI_VFRMT_END; - - return kErrorNone; -} - -DisplayError HWHDMI::OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level) { - DisplayError error = kErrorNone; - int fd = -1; - char data[kMaxStringLength] = {'\0'}; - - snprintf(data, sizeof(data), "%s%d/hdcp2p2/min_level_change", fb_path_, fb_node_index_); - - fd = Sys::open_(data, O_WRONLY); - if (fd < 0) { - DLOGW("File '%s' could not be opened.", data); - return kErrorHardware; - } - - snprintf(data, sizeof(data), "%d", min_enc_level); - - ssize_t err = Sys::pwrite_(fd, data, strlen(data), 0); - if (err <= 0) { - DLOGE("Write failed, Error = %s", strerror(errno)); - error = kErrorHardware; - } - - Sys::close_(fd); - - return error; -} - -HWScanSupport HWHDMI::MapHWScanSupport(uint32_t value) { - switch (value) { - // TODO(user): Read the scan type from driver defined values instead of hardcoding - case 0: - return kScanNotSupported; - case 1: - return kScanAlwaysOverscanned; - case 2: - return kScanAlwaysUnderscanned; - case 3: - return kScanBoth; - default: - return kScanNotSupported; - break; - } -} - -void HWHDMI::ReadScanInfo() { - int scan_info_file = -1; - ssize_t len = -1; - char data[kPageSize] = {'\0'}; - - snprintf(data, sizeof(data), "%s%d/scan_info", fb_path_, fb_node_index_); - scan_info_file = Sys::open_(data, O_RDONLY); - if (scan_info_file < 0) { - DLOGW("File '%s' not found.", data); - return; - } - - memset(&data[0], 0, sizeof(data)); - len = Sys::pread_(scan_info_file, data, sizeof(data) - 1, 0); - if (len <= 0) { - Sys::close_(scan_info_file); - DLOGW("File %s%d/scan_info is empty.", fb_path_, fb_node_index_); - return; - } - data[len] = '\0'; - Sys::close_(scan_info_file); - - const uint32_t scan_info_max_count = 3; - uint32_t scan_info_count = 0; - char *tokens[scan_info_max_count] = { NULL }; - ParseLine(data, tokens, scan_info_max_count, &scan_info_count); - if (scan_info_count != scan_info_max_count) { - DLOGW("Failed to parse scan info string %s", data); - return; - } - - hw_scan_info_.pt_scan_support = MapHWScanSupport(UINT32(atoi(tokens[0]))); - hw_scan_info_.it_scan_support = MapHWScanSupport(UINT32(atoi(tokens[1]))); - hw_scan_info_.cea_scan_support = MapHWScanSupport(UINT32(atoi(tokens[2]))); - DLOGI("PT %d IT %d CEA %d", hw_scan_info_.pt_scan_support, hw_scan_info_.it_scan_support, - hw_scan_info_.cea_scan_support); -} - -int HWHDMI::OpenResolutionFile(int file_mode) { - char file_path[kMaxStringLength]; - memset(file_path, 0, sizeof(file_path)); - snprintf(file_path , sizeof(file_path), "%s%d/res_info", fb_path_, fb_node_index_); - - int fd = Sys::open_(file_path, file_mode); - - if (fd < 0) { - DLOGE("file '%s' not found : ret = %d err str: %s", file_path, fd, strerror(errno)); - } - - return fd; -} - -// Method to request HDMI driver to write a new page of timing info into res_info node -void HWHDMI::RequestNewPage(uint32_t page_number) { - char page_string[kPageSize]; - int fd = OpenResolutionFile(O_WRONLY); - if (fd < 0) { - return; - } - - snprintf(page_string, sizeof(page_string), "%d", page_number); - - DLOGI_IF(kTagDriverConfig, "page=%s", page_string); - - ssize_t err = Sys::pwrite_(fd, page_string, sizeof(page_string), 0); - if (err <= 0) { - DLOGE("Write to res_info failed (%s)", strerror(errno)); - } - - Sys::close_(fd); -} - -// Reads the contents of res_info node into a buffer if the file is not empty -bool HWHDMI::ReadResolutionFile(char *config_buffer) { - ssize_t bytes_read = 0; - int fd = OpenResolutionFile(O_RDONLY); - if (fd >= 0) { - bytes_read = Sys::pread_(fd, config_buffer, kPageSize, 0); - Sys::close_(fd); - } - - DLOGI_IF(kTagDriverConfig, "bytes_read = %d", bytes_read); - - return (bytes_read > 0); -} - -// Populates the internal timing info structure with the timing info obtained -// from the HDMI driver -DisplayError HWHDMI::ReadTimingInfo() { - uint32_t config_index = 0; - uint32_t page_number = MSM_HDMI_INIT_RES_PAGE; - uint32_t size = sizeof(msm_hdmi_mode_timing_info); - - while (true) { - char config_buffer[kPageSize] = {0}; - msm_hdmi_mode_timing_info *info = reinterpret_cast(config_buffer); - RequestNewPage(page_number); - - if (!ReadResolutionFile(config_buffer)) { - break; - } - - while (info->video_format && size < kPageSize && config_index < hdmi_modes_.size()) { - supported_video_modes_[config_index] = *info; - size += sizeof(msm_hdmi_mode_timing_info); - - DLOGI_IF(kTagDriverConfig, "Config=%d Mode %d: (%dx%d) @ %d, pixel formats %d", - config_index, - supported_video_modes_[config_index].video_format, - supported_video_modes_[config_index].active_h, - supported_video_modes_[config_index].active_v, - supported_video_modes_[config_index].refresh_rate, - supported_video_modes_[config_index].pixel_formats); - - info++; - config_index++; - } - - size = sizeof(msm_hdmi_mode_timing_info); - // Request HDMI driver to populate res_info with more - // timing information - page_number++; - } - - if (page_number == MSM_HDMI_INIT_RES_PAGE || config_index == 0) { - DLOGE("No timing information found."); - return kErrorHardware; - } - - return kErrorNone; -} - -bool HWHDMI::IsResolutionFilePresent() { - bool is_file_present = false; - int fd = OpenResolutionFile(O_RDONLY); - if (fd >= 0) { - is_file_present = true; - Sys::close_(fd); - } - - return is_file_present; -} - -void HWHDMI::SetSourceProductInformation(const char *node, const char *name) { - char property_value[kMaxStringLength]; - char sys_fs_path[kMaxStringLength]; - int hdmi_node_index = GetFBNodeIndex(kDeviceHDMI); - if (hdmi_node_index < 0) { - return; - } - - ssize_t length = 0; - DisplayError error = Debug::GetProperty(name, property_value); - if (error != kErrorNone) { - return; - } - - snprintf(sys_fs_path , sizeof(sys_fs_path), "%s%d/%s", fb_path_, hdmi_node_index, node); - length = HWDevice::SysFsWrite(sys_fs_path, property_value, - static_cast(strlen(property_value))); - if (length <= 0) { - DLOGW("Failed to write %s = %s", node, property_value); - } -} - -DisplayError HWHDMI::GetDisplayS3DSupport(uint32_t index, - HWDisplayAttributes *attrib) { - ssize_t length = -1; - char edid_s3d_str[kPageSize] = {'\0'}; - char edid_s3d_path[kMaxStringLength] = {'\0'}; - snprintf(edid_s3d_path, sizeof(edid_s3d_path), "%s%d/edid_3d_modes", fb_path_, fb_node_index_); - - if (index > hdmi_modes_.size()) { - return kErrorNotSupported; - } - - attrib->s3d_config[kS3DModeNone] = 1; - - // Three level inception! - // The string looks like 16=SSH,4=FP:TAB:SSH,5=FP:SSH,32=FP:TAB:SSH - // Initialize all the pointers to NULL to avoid crash in function strtok_r() - char *saveptr_l1 = NULL, *saveptr_l2 = NULL, *saveptr_l3 = NULL; - char *l1 = NULL, *l2 = NULL, *l3 = NULL; - - int edid_s3d_node = Sys::open_(edid_s3d_path, O_RDONLY); - if (edid_s3d_node < 0) { - DLOGW("%s could not be opened : %s", edid_s3d_path, strerror(errno)); - return kErrorNotSupported; - } - - length = Sys::pread_(edid_s3d_node, edid_s3d_str, sizeof(edid_s3d_str)-1, 0); - if (length <= 0) { - Sys::close_(edid_s3d_node); - return kErrorNotSupported; - } - - l1 = strtok_r(edid_s3d_str, ",", &saveptr_l1); - while (l1 != NULL) { - l2 = strtok_r(l1, "=", &saveptr_l2); - if (l2 != NULL) { - if (hdmi_modes_[index] == (uint32_t)atoi(l2)) { - l3 = strtok_r(saveptr_l2, ":", &saveptr_l3); - while (l3 != NULL) { - if (strncmp("SSH", l3, strlen("SSH")) == 0) { - attrib->s3d_config[kS3DModeLR] = 1; - attrib->s3d_config[kS3DModeRL] = 1; - } else if (strncmp("TAB", l3, strlen("TAB")) == 0) { - attrib->s3d_config[kS3DModeTB] = 1; - } else if (strncmp("FP", l3, strlen("FP")) == 0) { - attrib->s3d_config[kS3DModeFP] = 1; - } - l3 = strtok_r(NULL, ":", &saveptr_l3); - } - } - } - l1 = strtok_r(NULL, ",", &saveptr_l1); - } - - Sys::close_(edid_s3d_node); - return kErrorNone; -} - -bool HWHDMI::IsSupportedS3DMode(HWS3DMode s3d_mode) { - for (uint32_t i = 0; i < supported_s3d_modes_.size(); i++) { - if (supported_s3d_modes_[i] == s3d_mode) { - return true; - } - } - return false; -} - -DisplayError HWHDMI::SetS3DMode(HWS3DMode s3d_mode) { - if (!IsSupportedS3DMode(s3d_mode)) { - DLOGW("S3D mode is not supported s3d_mode = %d", s3d_mode); - return kErrorNotSupported; - } - - std::map::iterator it = s3d_mode_sdm_to_mdp_.find(s3d_mode); - if (it == s3d_mode_sdm_to_mdp_.end()) { - return kErrorNotSupported; - } - msm_hdmi_s3d_mode s3d_mdp_mode = it->second; - - if (active_mdp_s3d_mode_ == s3d_mdp_mode) { - // HDMI_S3D_SIDE_BY_SIDE is an mdp mapping for kS3DModeLR and kS3DModeRL s3d modes. So no need - // to update the s3d_mode node. hw_panel_info needs to be updated to differentiate these two s3d - // modes in strategy - hw_panel_info_.s3d_mode = s3d_mode; - return kErrorNone; - } - - ssize_t length = -1; - char s3d_mode_path[kMaxStringLength] = {'\0'}; - char s3d_mode_string[kMaxStringLength] = {'\0'}; - snprintf(s3d_mode_path, sizeof(s3d_mode_path), "%s%d/s3d_mode", fb_path_, fb_node_index_); - - int s3d_mode_node = Sys::open_(s3d_mode_path, O_RDWR); - if (s3d_mode_node < 0) { - DLOGW("%s could not be opened : %s", s3d_mode_path, strerror(errno)); - return kErrorNotSupported; - } - - snprintf(s3d_mode_string, sizeof(s3d_mode_string), "%d", s3d_mdp_mode); - length = Sys::pwrite_(s3d_mode_node, s3d_mode_string, sizeof(s3d_mode_string), 0); - if (length <= 0) { - DLOGW("Failed to write into s3d node: %s", strerror(errno)); - Sys::close_(s3d_mode_node); - return kErrorNotSupported; - } - - active_mdp_s3d_mode_ = s3d_mdp_mode; - hw_panel_info_.s3d_mode = s3d_mode; - Sys::close_(s3d_mode_node); - - DLOGI_IF(kTagDriverConfig, "Set s3d mode %d", hw_panel_info_.s3d_mode); - return kErrorNone; -} - -DisplayError HWHDMI::GetPanelS3DMode() { - ssize_t length = -1; - char s3d_mode_path[kMaxStringLength] = {'\0'}; - char s3d_mode_string[kMaxStringLength] = {'\0'}; - snprintf(s3d_mode_path, sizeof(s3d_mode_path), "%s%d/s3d_mode", fb_path_, fb_node_index_); - int panel_s3d_mode = 0; - - int s3d_mode_node = Sys::open_(s3d_mode_path, O_RDWR); - if (s3d_mode_node < 0) { - DLOGE("%s could not be opened : %s", s3d_mode_path, strerror(errno)); - return kErrorNotSupported; - } - - length = Sys::pread_(s3d_mode_node, s3d_mode_string, sizeof(s3d_mode_string), 0); - if (length <= 0) { - DLOGE("Failed read s3d node: %s", strerror(errno)); - Sys::close_(s3d_mode_node); - return kErrorNotSupported; - } - - panel_s3d_mode = atoi(s3d_mode_string); - if (panel_s3d_mode < HDMI_S3D_NONE || panel_s3d_mode >= HDMI_S3D_MAX) { - Sys::close_(s3d_mode_node); - DLOGW("HDMI panel S3D mode is not supported panel_s3d_mode = %d", panel_s3d_mode); - return kErrorUndefined; - } - - active_mdp_s3d_mode_ = static_cast(panel_s3d_mode); - Sys::close_(s3d_mode_node); - - DLOGI_IF(kTagDriverConfig, "Get HDMI panel s3d mode %d", active_mdp_s3d_mode_); - return kErrorNone; -} - -DisplayError HWHDMI::GetDynamicFrameRateMode(uint32_t refresh_rate, uint32_t *mode, - DynamicFPSData *data, uint32_t *config_index) { - msm_hdmi_mode_timing_info *cur = NULL; - msm_hdmi_mode_timing_info *dst = NULL; - uint32_t i = 0; - int pre_refresh_rate_diff = 0; - bool pre_unstd_mode = false; - - for (i = 0; i < hdmi_modes_.size(); i++) { - msm_hdmi_mode_timing_info *timing_mode = &supported_video_modes_[i]; - if (timing_mode->video_format == hdmi_modes_[active_config_index_]) { - cur = timing_mode; - break; - } - } - - if (cur == NULL) { - DLOGE("can't find timing info for active config index(%d)", active_config_index_); - return kErrorUndefined; - } - - if (cur->refresh_rate != frame_rate_) { - pre_unstd_mode = true; - } - - if (i >= hdmi_modes_.size()) { - return kErrorNotSupported; - } - - dst = cur; - pre_refresh_rate_diff = static_cast(dst->refresh_rate) - static_cast(refresh_rate); - - for (i = 0; i < hdmi_modes_.size(); i++) { - msm_hdmi_mode_timing_info *timing_mode = &supported_video_modes_[i]; - if (cur->active_h == timing_mode->active_h && - cur->active_v == timing_mode->active_v && - cur->pixel_formats == timing_mode->pixel_formats ) { - int cur_refresh_rate_diff = static_cast(timing_mode->refresh_rate) - - static_cast(refresh_rate); - if (abs(pre_refresh_rate_diff) > abs(cur_refresh_rate_diff)) { - pre_refresh_rate_diff = cur_refresh_rate_diff; - dst = timing_mode; - } - } - } - - if (pre_refresh_rate_diff > kThresholdRefreshRate) { - return kErrorNotSupported; - } - - char mode_val[kVideoFormatArrayMax]={}; - snprintf(mode_val, sizeof(mode_val), "%d", dst->video_format); - GetConfigIndex(mode_val, config_index); - - data->hor_front_porch = dst->front_porch_h; - data->hor_back_porch = dst->back_porch_h; - data->hor_pulse_width = dst->pulse_width_h; - data->clk_rate_hz = dst->pixel_freq; - data->fps = refresh_rate; - - if (dst->front_porch_h != cur->front_porch_h) { - *mode = kModeHFP; - } - - if (dst->refresh_rate != refresh_rate || dst->pixel_freq != cur->pixel_freq) { - if (*mode == kModeHFP) { - if (dst->refresh_rate != refresh_rate) { - *mode = kModeHFPCalcClock; - } else { - *mode = kModeClockHFP; - } - } else { - *mode = kModeClock; - } - } - - if (pre_unstd_mode && (*mode == kModeHFP)) { - *mode = kModeClockHFP; - } - - return kErrorNone; -} - -DisplayError HWHDMI::SetRefreshRate(uint32_t refresh_rate) { - char mode_path[kMaxStringLength] = {0}; - char node_path[kMaxStringLength] = {0}; - uint32_t mode = kModeClock; - uint32_t config_index = 0; - DynamicFPSData data; - DisplayError error = kErrorNone; - - if (refresh_rate == frame_rate_) { - return error; - } - - error = GetDynamicFrameRateMode(refresh_rate, &mode, &data, &config_index); - if (error != kErrorNone) { - return error; - } - - snprintf(mode_path, sizeof(mode_path), "%s%d/msm_fb_dfps_mode", fb_path_, fb_node_index_); - snprintf(node_path, sizeof(node_path), "%s%d/dynamic_fps", fb_path_, fb_node_index_); - - int fd_mode = Sys::open_(mode_path, O_WRONLY); - if (fd_mode < 0) { - DLOGE("Failed to open %s with error %s", mode_path, strerror(errno)); - return kErrorFileDescriptor; - } - - char dfps_mode[kMaxStringLength]; - snprintf(dfps_mode, sizeof(dfps_mode), "%d", mode); - DLOGI_IF(kTagDriverConfig, "Setting dfps_mode = %d", mode); - ssize_t len = Sys::pwrite_(fd_mode, dfps_mode, strlen(dfps_mode), 0); - if (len < 0) { - DLOGE("Failed to enable dfps mode %d with error %s", mode, strerror(errno)); - Sys::close_(fd_mode); - return kErrorUndefined; - } - Sys::close_(fd_mode); - - int fd_node = Sys::open_(node_path, O_WRONLY); - if (fd_node < 0) { - DLOGE("Failed to open %s with error %s", node_path, strerror(errno)); - return kErrorFileDescriptor; - } - - char refresh_rate_string[kMaxStringLength]; - if (mode == kModeHFP || mode == kModeClock) { - snprintf(refresh_rate_string, sizeof(refresh_rate_string), "%d", data.fps); - DLOGI_IF(kTagDriverConfig, "Setting refresh rate = %d", data.fps); - } else { - snprintf(refresh_rate_string, sizeof(refresh_rate_string), "%d %d %d %d %d", - data.hor_front_porch, data.hor_back_porch, data.hor_pulse_width, - data.clk_rate_hz, data.fps); - } - len = Sys::pwrite_(fd_node, refresh_rate_string, strlen(refresh_rate_string), 0); - if (len < 0) { - DLOGE("Failed to write %d with error %s", refresh_rate, strerror(errno)); - Sys::close_(fd_node); - return kErrorUndefined; - } - Sys::close_(fd_node); - - error = ReadTimingInfo(); - if (error != kErrorNone) { - return error; - } - - GetDisplayAttributes(config_index, &display_attributes_); - UpdateMixerAttributes(); - - frame_rate_ = refresh_rate; - active_config_index_ = config_index; - - DLOGI_IF(kTagDriverConfig, "config_index(%d) Mode(%d) frame_rate(%d)", - config_index, - mode, - frame_rate_); - - return kErrorNone; -} - -void HWHDMI::UpdateMixerAttributes() { - mixer_attributes_.width = display_attributes_.x_pixels; - mixer_attributes_.height = display_attributes_.y_pixels; - mixer_attributes_.split_left = display_attributes_.is_device_split ? - (display_attributes_.x_pixels / 2) : mixer_attributes_.width; -} - -DisplayError HWHDMI::UpdateHDRMetaData(HWLayers *hw_layers) { - if (!hw_panel_info_.hdr_enabled) { - return kErrorNone; - } - - DisplayError error = kErrorNone; - -#ifdef MDP_HDR_STREAM - const HWHDRLayerInfo &hdr_layer_info = hw_layers->info.hdr_layer_info; - char hdr_stream_path[kMaxStringLength] = {}; - snprintf(hdr_stream_path, sizeof(hdr_stream_path), "%s%d/hdr_stream", fb_path_, fb_node_index_); - - Layer hdr_layer = {}; - if (hdr_layer_info.operation == HWHDRLayerInfo::kSet && hdr_layer_info.layer_index > -1) { - hdr_layer = *(hw_layers->info.stack->layers.at(UINT32(hdr_layer_info.layer_index))); - } - - const LayerBuffer *layer_buffer = &hdr_layer.input_buffer; - const MasteringDisplay &mastering_display = layer_buffer->color_metadata.masteringDisplayInfo; - const ContentLightLevel &light_level = layer_buffer->color_metadata.contentLightLevel; - const Primaries &primaries = mastering_display.primaries; - - mdp_hdr_stream_ctrl hdr_ctrl = {}; - if (hdr_layer_info.operation == HWHDRLayerInfo::kSet) { - int32_t eotf = GetEOTF(layer_buffer->color_metadata.transfer); - hdr_ctrl.hdr_stream.eotf = (eotf < 0) ? 0 : UINT32(eotf); - hdr_ctrl.hdr_stream.white_point_x = primaries.whitePoint[0]; - hdr_ctrl.hdr_stream.white_point_y = primaries.whitePoint[1]; - hdr_ctrl.hdr_stream.display_primaries_x[0] = primaries.rgbPrimaries[0][0]; - hdr_ctrl.hdr_stream.display_primaries_y[0] = primaries.rgbPrimaries[0][1]; - hdr_ctrl.hdr_stream.display_primaries_x[1] = primaries.rgbPrimaries[1][0]; - hdr_ctrl.hdr_stream.display_primaries_y[1] = primaries.rgbPrimaries[1][1]; - hdr_ctrl.hdr_stream.display_primaries_x[2] = primaries.rgbPrimaries[2][0]; - hdr_ctrl.hdr_stream.display_primaries_y[2] = primaries.rgbPrimaries[2][1]; - hdr_ctrl.hdr_stream.min_luminance = mastering_display.minDisplayLuminance; - hdr_ctrl.hdr_stream.max_luminance = mastering_display.maxDisplayLuminance/10000; - hdr_ctrl.hdr_stream.max_content_light_level = light_level.maxContentLightLevel; - hdr_ctrl.hdr_stream.max_average_light_level = light_level.minPicAverageLightLevel; - hdr_ctrl.hdr_state = HDR_ENABLE; - reset_hdr_flag_ = false; -#ifdef MDP_COMMIT_UPDATE_CDM_COLOR_SPACE - HWDevice::SetCSC(layer_buffer->color_metadata, &cdm_color_space_); - cdm_color_space_commit_ = true; -#endif - // DP related - int32_t pixel_encoding = GetPixelEncoding(hdr_layer.input_buffer); - hdr_ctrl.hdr_stream.pixel_encoding = (pixel_encoding < 0) ? 0 : UINT32(pixel_encoding); - int32_t colorimetry = GetColoriMetry(hdr_layer.input_buffer); - hdr_ctrl.hdr_stream.colorimetry = (colorimetry < 0) ? 0 : UINT32(colorimetry); - hdr_ctrl.hdr_stream.range = GetRange(hdr_layer.input_buffer.color_metadata.range); - int32_t bits_per_component = GetBitsPerComponent(hdr_layer.input_buffer); - hdr_ctrl.hdr_stream.bits_per_component = - (bits_per_component < 0) ? 0 : UINT32(bits_per_component); - hdr_ctrl.hdr_stream.content_type = GetContentType(hdr_layer.input_buffer); - - DLOGD_IF(kTagDriverConfig, "kSet: HDR Stream : MaxDisplayLuminance = %d\n" - "MinDisplayLuminance = %d MaxContentLightLevel = %d MaxAverageLightLevel = %d\n" - "Red_x = %d Red_y = %d Green_x = %d Green_y = %d Blue_x = %d Blue_y = %d\n" - "WhitePoint_x = %d WhitePoint_y = %d EOTF = %d PixelEncoding = %d Colorimetry = %d\n" - "Range = %d BPC = %d ContentType = %d hdr_state = %d", - hdr_ctrl.hdr_stream.max_luminance, hdr_ctrl.hdr_stream.min_luminance, - hdr_ctrl.hdr_stream.max_content_light_level, hdr_ctrl.hdr_stream.max_average_light_level, - hdr_ctrl.hdr_stream.display_primaries_x[0], hdr_ctrl.hdr_stream.display_primaries_y[0], - hdr_ctrl.hdr_stream.display_primaries_x[1], hdr_ctrl.hdr_stream.display_primaries_y[1], - hdr_ctrl.hdr_stream.display_primaries_x[2], hdr_ctrl.hdr_stream.display_primaries_y[2], - hdr_ctrl.hdr_stream.white_point_x, hdr_ctrl.hdr_stream.white_point_x, - hdr_ctrl.hdr_stream.eotf, hdr_ctrl.hdr_stream.pixel_encoding, - hdr_ctrl.hdr_stream.colorimetry, hdr_ctrl.hdr_stream.range, - hdr_ctrl.hdr_stream.bits_per_component, hdr_ctrl.hdr_stream.content_type, - hdr_ctrl.hdr_state); - } else if (hdr_layer_info.operation == HWHDRLayerInfo::kReset) { - memset(&hdr_ctrl.hdr_stream, 0, sizeof(hdr_ctrl.hdr_stream)); - hdr_ctrl.hdr_state = HDR_RESET; - reset_hdr_flag_ = true; - hdr_reset_start_ = time(NULL); -#ifdef MDP_COMMIT_UPDATE_CDM_COLOR_SPACE - cdm_color_space_ = (mdp_color_space) MDP_CSC_DEFAULT; - cdm_color_space_commit_ = true; -#endif - DLOGD_IF(kTagDriverConfig, "kReset: HDR Stream: HDR_RESET"); - } else if (hdr_layer_info.operation == HWHDRLayerInfo::kNoOp) { - if (reset_hdr_flag_) { - hdr_reset_end_ = time(NULL); - - if ((hdr_reset_end_ - hdr_reset_start_) >= MIN_HDR_RESET_WAITTIME_SEC) { - reset_hdr_flag_ = false; - memset(&hdr_ctrl.hdr_stream, 0, sizeof(hdr_ctrl.hdr_stream)); - hdr_ctrl.hdr_state = HDR_DISABLE; - DLOGD_IF(kTagDriverConfig, "kNoOp: HDR Stream: HDR_DISABLE"); - } else { - return kErrorNone; - } - } else { - return kErrorNone; - } - } - - int fd = Sys::open_(hdr_stream_path, O_WRONLY); - if (fd < 0) { - DLOGE("Failed to open %s with error %s", hdr_stream_path, strerror(errno)); - return kErrorFileDescriptor; - } - - const void *hdr_metadata = reinterpret_cast(&hdr_ctrl); - ssize_t len = Sys::pwrite_(fd, hdr_metadata, sizeof(hdr_ctrl), 0); - if (len <= 0) { - DLOGE("Failed to write hdr_metadata"); - error = kErrorUndefined; - } - Sys::close_(fd); -#endif - - return error; -} - -} // namespace sdm - diff --git a/sdm/libs/core/fb/hw_hdmi.h b/sdm/libs/core/fb/hw_hdmi.h deleted file mode 100644 index 183e9db0..00000000 --- a/sdm/libs/core/fb/hw_hdmi.h +++ /dev/null @@ -1,131 +0,0 @@ -/* -* Copyright (c) 2015 - 2017, The Linux Foundation. All rights reserved. -* -* Redistribution and use in source and binary forms, with or without modification, are permitted -* provided that the following conditions are met: -* * Redistributions of source code must retain the above copyright notice, this list of -* conditions and the following disclaimer. -* * Redistributions in binary form must reproduce the above copyright notice, this list of -* conditions and the following disclaimer in the documentation and/or other materials provided -* with the distribution. -* * Neither the name of The Linux Foundation nor the names of its contributors may be used to -* endorse or promote products derived from this software without specific prior written -* permission. -* -* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE -* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef __HW_HDMI_H__ -#define __HW_HDMI_H__ - -#include