From 7f63c67cf26fe5463ede87c4f4186548bc9297e9 Mon Sep 17 00:00:00 2001 From: ginujacob Date: Tue, 17 Sep 2024 18:27:34 +0100 Subject: [PATCH] Add support for wp_presentation in the WSI layer Enabling the support for wp_presentation in Wayland surface. A handle to the interface is stored in the Wayland surface. The handle is initialized for each VKSurface. Signed-off-by: ginujacob Change-Id: I9a2239b3047720fdeb857e23bb529c0f0fce9575 --- CMakeLists.txt | 13 +++++++++++-- wsi/wayland/surface.cpp | 19 +++++++++++++++++++ wsi/wayland/surface.hpp | 3 +++ wsi/wayland/wl_object_owner.hpp | 6 ++++++ 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2431174..9bee1a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -138,14 +138,23 @@ if(BUILD_WSI_WAYLAND) COMMAND ${WAYLAND_SCANNER_EXEC} public-code ${WAYLAND_PROTOCOLS_DIR}/unstable/linux-explicit-synchronization/linux-explicit-synchronization-unstable-v1.xml ${CMAKE_CURRENT_BINARY_DIR}/linux-explicit-synchronization-unstable-v1-protocol.c + COMMAND ${WAYLAND_SCANNER_EXEC} client-header + ${WAYLAND_PROTOCOLS_DIR}/stable/presentation-time/presentation-time.xml + ${CMAKE_CURRENT_BINARY_DIR}/presentation-time-client-protocol.h + COMMAND ${WAYLAND_SCANNER_EXEC} public-code + ${WAYLAND_PROTOCOLS_DIR}/stable/presentation-time/presentation-time.xml + ${CMAKE_CURRENT_BINARY_DIR}/presentation-time-client-protocol.c BYPRODUCTS linux-dmabuf-unstable-v1-protocol.c linux-dmabuf-unstable-v1-client-protocol.h - linux-explicit-synchronization-unstable-v1-protocol.c linux-explicit-synchronization-unstable-v1-protocol.h) + linux-explicit-synchronization-unstable-v1-protocol.c linux-explicit-synchronization-unstable-v1-protocol.h + presentation-time-client-protocol.c presentation-time-client-protocol.h) target_sources(wayland_wsi PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/linux-dmabuf-unstable-v1-protocol.c ${CMAKE_CURRENT_BINARY_DIR}/linux-dmabuf-unstable-v1-client-protocol.h ${CMAKE_CURRENT_BINARY_DIR}/linux-explicit-synchronization-unstable-v1-protocol.c - ${CMAKE_CURRENT_BINARY_DIR}/linux-explicit-synchronization-unstable-v1-protocol.h) + ${CMAKE_CURRENT_BINARY_DIR}/linux-explicit-synchronization-unstable-v1-protocol.h + ${CMAKE_CURRENT_BINARY_DIR}/presentation-time-client-protocol.c + ${CMAKE_CURRENT_BINARY_DIR}/presentation-time-client-protocol.h) add_dependencies(wayland_wsi wayland_generated_files) target_include_directories(wayland_wsi PRIVATE diff --git a/wsi/wayland/surface.cpp b/wsi/wayland/surface.cpp index 07ef607..61ed4b5 100644 --- a/wsi/wayland/surface.cpp +++ b/wsi/wayland/surface.cpp @@ -170,6 +170,19 @@ surface_registry_handler(void *data, struct wl_registry *wl_registry, uint32_t n wsi_surface->explicit_sync_interface.reset(explicit_sync_interface_obj); } + else if (!strcmp(interface, wp_presentation_interface.name)) + { + wp_presentation *wp_presentation_obj = + reinterpret_cast(wl_registry_bind(wl_registry, name, &wp_presentation_interface, 1)); + + if (wp_presentation_obj == nullptr) + { + WSI_LOG_ERROR("Failed to get wp_presentation interface."); + return; + } + + wsi_surface->presentation_time_interface.reset(wp_presentation_obj); + } } bool surface::init() @@ -222,6 +235,12 @@ bool surface::init() return false; } + if (presentation_time_interface.get() == nullptr) + { + WSI_LOG_ERROR("Failed to obtain wp_presentation interface."); + return false; + } + auto surface_sync_obj = zwp_linux_explicit_synchronization_v1_get_synchronization(explicit_sync_interface.get(), wayland_surface); if (surface_sync_obj == nullptr) diff --git a/wsi/wayland/surface.hpp b/wsi/wayland/surface.hpp index fd005d4..877ca99 100644 --- a/wsi/wayland/surface.hpp +++ b/wsi/wayland/surface.hpp @@ -171,6 +171,9 @@ private: /** Container for the surface specific zwp_linux_surface_synchronization_v1 interface. */ wayland_owner surface_sync_interface; + /** Container for the wp_presentation interface binding */ + wayland_owner presentation_time_interface; + /** * Container for a callback object for the latest frame done event. * diff --git a/wsi/wayland/wl_object_owner.hpp b/wsi/wayland/wl_object_owner.hpp index 7199e66..0ed09ef 100644 --- a/wsi/wayland/wl_object_owner.hpp +++ b/wsi/wayland/wl_object_owner.hpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -55,6 +56,11 @@ static inline void wayland_object_destroy(zwp_linux_surface_synchronization_v1 * zwp_linux_surface_synchronization_v1_destroy(obj); } +static inline void wayland_object_destroy(wp_presentation *obj) +{ + wp_presentation_destroy(obj); +} + static inline void wayland_object_destroy(wl_callback *obj) { wl_callback_destroy(obj);