diff --git a/Android.bp b/Android.bp new file mode 100644 index 0000000..9fe4500 --- /dev/null +++ b/Android.bp @@ -0,0 +1,86 @@ +// +// Copyright 2016-2024 Intel Corporation +// +// 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. +// + +cc_defaults { + name: "hwc_vhal_defaults", + + srcs: [ + "common/RemoteDisplay.cpp", + "common/RemoteDisplayMgr.cpp", + "common/LocalDisplay.cpp", + "common/BufferMapper.cpp", + "hwc2/Hwc2Device.cpp", + "hwc2/Hwc2Display.cpp", + "hwc2/Hwc2Layer.cpp", + ], + + local_include_dirs: [ + "common", + ], + + shared_libs: [ + "liblog", + "libcutils", + "libhardware", + ], + + cflags: [ + "-Werror", + "-Wno-error", + "-DLOG_TAG=\"hwc_vhal\"", + "-DHWC2_INCLUDE_STRINGIFICATION", + "-DHWC2_USE_CPP11", + "-DSUPPORT_HWC_2_0", + "-DSUPPORT_HWC_2_1", + "-DSUPPORT_HWC_2_2", + "-DSUPPORT_HWC_2_3", + "-DSUPPORT_HWC_2_4", + ], +} + +cc_library_shared { + name: "hwcomposer.remote", + defaults: ["hwc_vhal_defaults"], + + cflags: [ + "-DENABLE_HWC_REMOTE", + "-DUSE_ABSTRACT_SOCKET", + ], + + vendor: true, + relative_install_path: "hw", +} + +cc_library_shared { + name: "hwcomposer.uio", + defaults: ["hwc_vhal_defaults"], + + srcs: [ + "uio/UioDisplay.cpp", + ], + + local_include_dirs: [ + "uio", + ], + + cflags: [ + "-DENABLE_HWC_UIO", + "-DENABLE_MULTI_DISPLAY", + ], + + vendor: true, + relative_install_path: "hw", +} diff --git a/Android.mk b/Android.mk deleted file mode 100644 index d707a0a..0000000 --- a/Android.mk +++ /dev/null @@ -1,125 +0,0 @@ -# -# Copyright 2016 Intel Corporation -# -# 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. -# - -TARGET_USE_HWCOMPOSER_VHAL := true - -ifeq ($(TARGET_USE_HWCOMPOSER_VHAL), true) - -LOCAL_PATH := $(call my-dir) - -#####################lib########################### -include $(CLEAR_VARS) - -#TARGET_USES_HWC2 := false - -#ENABLE_LAYER_DUMP := true -ENABLE_HWC_UIO := true -ENABLE_MULTI_DISPLAY := true - -LOCAL_CFLAGS := -g -DLOG_TAG=\"hwc_vhal\" -g -Wno-missing-field-initializers -Wno-unused-parameter -LOCAL_CPPFLAGS := -g -std=c++11 -Wall -Werror -Wno-unused-parameter -LOCAL_LDFLAGS := -g - -ifeq ($(TARGET_USES_HWC2), false) -LOCAL_SRC_FILES := \ - common/RemoteDisplay.cpp \ - common/RemoteDisplayMgr.cpp \ - hwc1/Hwc1Device.cpp \ - hwc1/Hwc1Display.cpp \ - -else -LOCAL_CPPFLAGS += \ - -DHWC2_INCLUDE_STRINGIFICATION \ - -DHWC2_USE_CPP11 \ - -DSUPPORT_HWC_2_0 \ - -ifneq ($(filter 8, $(PLATFORM_VERSION)),) -LOCAL_CPPFLAGS += \ - -DSUPPORT_HWC_2_1 -endif -ifneq ($(filter 9, $(PLATFORM_VERSION)),) -LOCAL_CPPFLAGS += \ - -DSUPPORT_HWC_2_1 \ - -DSUPPORT_HWC_2_2 -endif -ifneq ($(filter 10, $(PLATFORM_VERSION)),) -LOCAL_CPPFLAGS += \ - -DSUPPORT_HWC_2_1 \ - -DSUPPORT_HWC_2_2 \ - -DSUPPORT_HWC_2_3 -endif -ifneq ($(filter 11, $(PLATFORM_VERSION)),) -LOCAL_CPPFLAGS += \ - -DSUPPORT_HWC_2_1 \ - -DSUPPORT_HWC_2_2 \ - -DSUPPORT_HWC_2_3 \ - -DSUPPORT_HWC_2_4 -endif - -LOCAL_SRC_FILES := \ - common/RemoteDisplay.cpp \ - common/RemoteDisplayMgr.cpp \ - common/LocalDisplay.cpp \ - common/BufferMapper.cpp \ - hwc2/Hwc2Device.cpp \ - hwc2/Hwc2Display.cpp \ - hwc2/Hwc2Layer.cpp \ - -endif - -ifeq ($(ENABLE_LAYER_DUMP), true) -LOCAL_SRC_FILES += \ - common/BufferDumper.cpp \ - -LOCAL_CPPFLAGS += \ - -DENABLE_LAYER_DUMP=1 - -LOCAL_STATIC_LIBRARIES += libpng libz - -endif - -ifeq ($(ENABLE_HWC_UIO), true) -LOCAL_SRC_FILES += \ - uio/UioDisplay.cpp - -LOCAL_CPPFLAGS += \ - -DENABLE_HWC_UIO - -LOCAL_C_INCLUDES += \ - $(LOCAL_PATH)/uio -endif - -ifeq ($(ENABLE_MULTI_DISPLAY), true) -LOCAL_CPPFLAGS += \ - -DENABLE_MULTI_DISPLAY -endif - -LOCAL_C_INCLUDES += \ - $(LOCAL_PATH) \ - $(LOCAL_PATH)/common \ - -LOCAL_SHARED_LIBRARIES := \ - liblog \ - libcutils \ - libhardware \ - -LOCAL_PROPRIETARY_MODULE := true -LOCAL_MODULE := hwcomposer.remote -LOCAL_MODULE_TAGS := optional -LOCAL_MODULE_RELATIVE_PATH := hw -include $(BUILD_SHARED_LIBRARY) - -endif diff --git a/common/RemoteDisplayMgr.cpp b/common/RemoteDisplayMgr.cpp index 7b49438..d1fd88d 100644 --- a/common/RemoteDisplayMgr.cpp +++ b/common/RemoteDisplayMgr.cpp @@ -27,6 +27,7 @@ Date: 2021.06.09 //#define LOG_NDEBUG 0 #include +#include #include #include @@ -52,9 +53,6 @@ RemoteDisplayMgr::~RemoteDisplayMgr() { } int RemoteDisplayMgr::init(IRemoteDevice* dev) { - - return -1; - mEpollFd = epoll_create(kMaxEvents); if (mEpollFd == -1) { ALOGE("epoll_create:%s", strerror(errno)); @@ -215,26 +213,44 @@ void RemoteDisplayMgr::socketThreadProc() { addr.sun_family = AF_UNIX; strncpy(&addr.sun_path[0], kServerSock, strlen(kServerSock)); - unlink(kServerSock); + const char* path = kServerSock; +#ifdef USE_ABSTRACT_SOCKET + bool abstract = true; +#else + bool abstract = false; +#endif + if (abstract) { + path = "hwc-sock"; + strncpy(&addr.sun_path[1], path, strlen(path)); + addr.sun_path[0] = 0; + } else { + strncpy(&addr.sun_path[0], path, strlen(path)); + unlink(path); + } + if (bind(mServerFd, (struct sockaddr*)&addr, - sizeof(sa_family_t) + strlen(kServerSock) + 1) < 0) { + sizeof(sa_family_t) + strlen(path) + 1) < 0) { ALOGE("Failed to bind server socket address"); return; } // TODO: use group access only for security - struct stat st; - __mode_t mod = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; - if (fstat(mServerFd, &st) == 0) { - mod |= st.st_mode; + if (!abstract) { + struct stat st; + __mode_t mod = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; + if (fstat(mServerFd, &st) == 0) { + mod |= st.st_mode; + } + chmod(path, mod); } - chmod(kServerSock, mod); if (listen(mServerFd, 1) < 0) { ALOGE("Failed to listen on server socket"); return; } + property_set("vendor.hwc_vhal.ready", "1"); + while (true) { struct epoll_event events[kMaxEvents]; int nfds = epoll_wait(mEpollFd, events, kMaxEvents, -1); diff --git a/hwc2/Hwc2Device.cpp b/hwc2/Hwc2Device.cpp index 8d28840..74c508b 100644 --- a/hwc2/Hwc2Device.cpp +++ b/hwc2/Hwc2Device.cpp @@ -58,6 +58,7 @@ Hwc2Device::Hwc2Device() { Error Hwc2Device::init() { ALOGV("%s", __func__); +#ifdef ENABLE_HWC_REMOTE mRemoteDisplayMgr = std::unique_ptr(new RemoteDisplayMgr()); if (!mRemoteDisplayMgr) { ALOGE("Failed to create remote display manager, out of memory"); @@ -68,6 +69,7 @@ Error Hwc2Device::init() { mDisplays.emplace(kPrimayDisplay, 0); onHotplug(kPrimayDisplay, true); } +#endif #ifdef ENABLE_MULTI_DISPLAY int maxDisplayCount = kMaxDisplayCount; @@ -519,9 +521,15 @@ hwc2_function_pointer_t Hwc2Device::getFunctionHook(struct hwc2_device* dev, case FunctionDescriptor::Invalid: default: - ALOGE("%s:Unsupported HWC2 function, descriptor=%d", __func__, - descriptor); - return nullptr; + if (descriptor == HWC3_FUNCTION_SET_EXPECTED_PRESENT_TIME) + return asFP( + DisplayHook&>); + else { + ALOGE("%s:Unsupported HWC2 function, descriptor=%d", __func__, + descriptor); + return nullptr; + } } } diff --git a/hwc2/Hwc2Display.cpp b/hwc2/Hwc2Display.cpp index 5572b4f..74ed8e0 100644 --- a/hwc2/Hwc2Display.cpp +++ b/hwc2/Hwc2Display.cpp @@ -68,7 +68,7 @@ Hwc2Display::Hwc2Display(hwc2_display_t id) { ALOGD("Display %" PRIu64 " default size <%d %d> from debug fs", id, w, h); } - if (w & h) { + if (w && h) { mWidth = w; mHeight = h; } @@ -631,3 +631,8 @@ Error Hwc2Display::setActiveConfigWithConstraints(hwc2_config_t config, ALOGV("Hwc2Display(%" PRIu64 ")::%s", mDisplayID, __func__); return Error::None; } + +HWC2::Error Hwc2Display::setExpectedPresentTime( + const std::optional& expectedPresentTime) { + return HWC2::Error::None; +} diff --git a/hwc2/Hwc2Display.h b/hwc2/Hwc2Display.h index fc298e6..30392a9 100644 --- a/hwc2/Hwc2Display.h +++ b/hwc2/Hwc2Display.h @@ -31,6 +31,7 @@ Date: 2021.06.09 #include #include #include +#include #include @@ -42,6 +43,17 @@ Date: 2021.06.09 #include "UioDisplay.h" #endif +//TODO: include HWC3 headers +struct ClockMonotonicTimestamp { + int64_t timestampNanos; +}; +typedef enum { + HWC3_FUNCTION_SET_EXPECTED_PRESENT_TIME = HWC2_FUNCTION_GET_LAYER_GENERIC_METADATA_KEY + 1, +} hwc3_function_descriptor_t; +typedef int32_t /*hwc_error_t*/ (*HWC3_PFN_SET_EXPECTED_PRESENT_TIME)(hwc2_device_t* device, + hwc2_display_t display, const std::optional& expectedPresentTime); + + class RemoteDisplay; class Hwc2Display : public DisplayEventListener { @@ -116,6 +128,8 @@ class Hwc2Display : public DisplayEventListener { HWC2::Error setActiveConfigWithConstraints(hwc2_config_t config, hwc_vsync_period_change_constraints_t* constraints, hwc_vsync_period_change_timeline_t* timeline_t); + HWC2::Error setExpectedPresentTime( + const std::optional& expectedPresentTime); protected: HWC2::Error hotplug(bool in);