From 1fd84c4654ef4472effcd9b24fcc782e42bfd12f Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Wed, 14 Sep 2022 13:55:45 +0200 Subject: [PATCH] Add xdg_shell support to DEQP_TARGET=wayland Signed-off-by: Rahul Kumar --- framework/platform/CMakeLists.txt | 10 +++ .../platform/lnx/wayland/tcuLnxWayland.cpp | 67 ++++++++++++++++--- .../platform/lnx/wayland/tcuLnxWayland.hpp | 8 +++ targets/default/FindWayland.cmake | 10 ++- 4 files changed, 83 insertions(+), 12 deletions(-) diff --git a/framework/platform/CMakeLists.txt b/framework/platform/CMakeLists.txt index eed019541..d08ef7bc5 100644 --- a/framework/platform/CMakeLists.txt +++ b/framework/platform/CMakeLists.txt @@ -71,12 +71,22 @@ if (NOT DEFINED TCUTIL_PLATFORM_SRCS) if (DEQP_USE_WAYLAND) add_definitions(-DDEQP_SUPPORT_WAYLAND=1) + include_directories(${PROJECT_BINARY_DIR}/framework/platform/lnx/wayland) include_directories(lnx/wayland) + file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/framework/platform/lnx/wayland) + add_custom_command(OUTPUT lnx/wayland/xdg-shell.c + COMMAND ${WAYLAND_SCANNER} private-code ${WAYLAND_PROTO_XDG_SHELL_XML} ${PROJECT_BINARY_DIR}/framework/platform/lnx/wayland/xdg-shell.c) + file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/framework/platform/lnx/wayland) + add_custom_command(OUTPUT lnx/wayland/xdg-shell.h + COMMAND ${WAYLAND_SCANNER} client-header ${WAYLAND_PROTO_XDG_SHELL_XML} ${PROJECT_BINARY_DIR}/framework/platform/lnx/wayland/xdg-shell.h) + set(TCUTIL_PLATFORM_SRCS ${TCUTIL_PLATFORM_SRCS} lnx/wayland/tcuLnxWayland.hpp lnx/wayland/tcuLnxWayland.cpp + lnx/wayland/xdg-shell.c + lnx/wayland/xdg-shell.h lnx/wayland/tcuLnxWaylandEglDisplayFactory.cpp lnx/wayland/tcuLnxWaylandEglDisplayFactory.hpp ) diff --git a/framework/platform/lnx/wayland/tcuLnxWayland.cpp b/framework/platform/lnx/wayland/tcuLnxWayland.cpp index f4808db28..b337f95c7 100644 --- a/framework/platform/lnx/wayland/tcuLnxWayland.cpp +++ b/framework/platform/lnx/wayland/tcuLnxWayland.cpp @@ -27,6 +27,8 @@ #include "gluRenderConfig.hpp" #include "deMemory.h" +#include "xdg-shell.h" + #include namespace tcu @@ -58,9 +60,10 @@ void Display::handleGlobal (void* data, struct wl_registry* registry, uint32_t i if (!strcmp(interface, "wl_compositor")) _this->m_compositor = static_cast(wl_registry_bind(registry, id, &wl_compositor_interface, version > 3 ? version : 3)); - /* Todo: when the xdg_shell protocol has stablized, we should move wl_shell to xdg_shell. */ - if (!strcmp(interface, "wl_shell")) + else if (!strcmp(interface, "wl_shell")) _this->m_shell = static_cast(wl_registry_bind(registry, id, &wl_shell_interface, 1)); + else if (strcmp(interface, "zxdg_shell_v6") == 0) + _this->m_xdg_shell = static_cast(wl_registry_bind(registry, id, &zxdg_shell_v6_interface, 1)); } void Display::handleGlobalRemove (void* data, struct wl_registry* registry, uint32_t name) @@ -106,14 +109,17 @@ Display::Display (EventState& eventState, const char* name) wl_display_roundtrip(m_display); if (!m_compositor) throw ResourceError("Failed to bind compositor", name, __FILE__, __LINE__); - if (!m_shell) - throw ResourceError("Failed to bind shell", name, __FILE__, __LINE__); + if (!m_shell && !m_xdg_shell) + throw ResourceError("Failed to bind wl_shell and xdg_shell", name, __FILE__, __LINE__); } catch (...) { if (m_shell) wl_shell_destroy(m_shell); + if (m_xdg_shell) + zxdg_shell_v6_destroy(m_xdg_shell); + if (m_compositor) wl_compositor_destroy(m_compositor); @@ -132,6 +138,9 @@ Display::~Display (void) if (m_shell) wl_shell_destroy(m_shell); + if (m_xdg_shell) + zxdg_shell_v6_destroy(m_xdg_shell); + if (m_compositor) wl_compositor_destroy(m_compositor); @@ -146,8 +155,26 @@ void Display::processEvents (void) { } +void xdg_toplevel_configure_handler(void *, struct zxdg_toplevel_v6 *, int32_t, int32_t, struct wl_array *) { } + +void xdg_toplevel_close_handler(void *, struct zxdg_toplevel_v6 *) {} + +const struct zxdg_toplevel_v6_listener xdg_toplevel_listener = { + .configure = xdg_toplevel_configure_handler, + .close = xdg_toplevel_close_handler +}; + +void xdg_surface_configure_handler(void *, struct zxdg_surface_v6 *xdg_surface, uint32_t serial) { + zxdg_surface_v6_ack_configure(xdg_surface, serial); +} + +const struct zxdg_surface_v6_listener xdg_surface_listener = { + .configure = xdg_surface_configure_handler +}; + + Window::Window (Display& display, int width, int height) - : m_display (display) + : m_display (display), m_shellSurface(nullptr) { try { @@ -155,13 +182,25 @@ Window::Window (Display& display, int width, int height) if (!m_surface) throw ResourceError("Failed to create ", "surface", __FILE__, __LINE__); - m_shellSurface = wl_shell_get_shell_surface(display.getShell(), m_surface); - if (!m_shellSurface) - throw ResourceError("Failed to create ", "shell_surface", __FILE__, __LINE__); + if (display.getShell()) { + m_shellSurface = wl_shell_get_shell_surface(display.getShell(), m_surface); + if (!m_shellSurface) + throw ResourceError("Failed to create ", "shell_surface", __FILE__, __LINE__); + + wl_shell_surface_add_listener(m_shellSurface, &s_shellSurfaceListener, this); + wl_shell_surface_set_title(m_shellSurface, "CTS for OpenGL (ES)"); + wl_shell_surface_set_toplevel(m_shellSurface); + } else { + m_xdg_surface = zxdg_shell_v6_get_xdg_surface(display.getXdgShell(), m_surface); - wl_shell_surface_add_listener(m_shellSurface, &s_shellSurfaceListener, this); - wl_shell_surface_set_title(m_shellSurface, "CTS for OpenGL (ES)"); - wl_shell_surface_set_toplevel(m_shellSurface); + zxdg_surface_v6_add_listener(m_xdg_surface, &xdg_surface_listener, NULL); + + m_xdg_toplevel = zxdg_surface_v6_get_toplevel(m_xdg_surface); + zxdg_toplevel_v6_add_listener(m_xdg_toplevel, &xdg_toplevel_listener, NULL); + + wl_surface_commit(m_surface); + wl_display_roundtrip(display.getDisplay()); + } if (width == glu::RenderConfig::DONT_CARE) width = DEFAULT_WINDOW_WIDTH; @@ -169,6 +208,7 @@ Window::Window (Display& display, int width, int height) height = DEFAULT_WINDOW_HEIGHT; m_window = wl_egl_window_create(m_surface, width, height); + if (!m_window) throw ResourceError("Failed to create ", "window", __FILE__, __LINE__); } @@ -221,12 +261,17 @@ void Window::handlePopupDone (void* data, struct wl_shell_surface* shellSurface) Window::~Window (void) { + if (m_xdg_toplevel) + zxdg_toplevel_v6_destroy(m_xdg_toplevel); + if (m_xdg_surface) + zxdg_surface_v6_destroy(m_xdg_surface); if (m_window) wl_egl_window_destroy(m_window); if (m_shellSurface) wl_shell_surface_destroy(m_shellSurface); if (m_surface) wl_surface_destroy(m_surface); + } } // wayland diff --git a/framework/platform/lnx/wayland/tcuLnxWayland.hpp b/framework/platform/lnx/wayland/tcuLnxWayland.hpp index b7c540a81..14c59e3d9 100644 --- a/framework/platform/lnx/wayland/tcuLnxWayland.hpp +++ b/framework/platform/lnx/wayland/tcuLnxWayland.hpp @@ -33,6 +33,10 @@ #include #include +struct zxdg_shell_v6; +struct zxdg_toplevel_v6; +struct zxdg_surface_v6; + namespace tcu { namespace lnx @@ -49,6 +53,7 @@ public: struct wl_display* getDisplay (void) { return m_display; } struct wl_compositor* getCompositor (void) { return m_compositor; } struct wl_shell* getShell (void) { return m_shell; } + struct zxdg_shell_v6* getXdgShell (void) { return m_xdg_shell; } void processEvents (void); static bool hasDisplay (const char* name); @@ -67,6 +72,7 @@ protected: struct wl_registry* m_registry; struct wl_compositor* m_compositor; struct wl_shell* m_shell; + struct zxdg_shell_v6* m_xdg_shell; private: Display (const Display&); @@ -100,6 +106,8 @@ protected: struct wl_egl_window* m_window; struct wl_surface* m_surface; struct wl_shell_surface* m_shellSurface; + struct zxdg_surface_v6* m_xdg_surface; + struct zxdg_toplevel_v6* m_xdg_toplevel; bool m_visible; private: diff --git a/targets/default/FindWayland.cmake b/targets/default/FindWayland.cmake index f93218b87..c668af860 100644 --- a/targets/default/FindWayland.cmake +++ b/targets/default/FindWayland.cmake @@ -27,7 +27,7 @@ IF (NOT WIN32) # Use pkg-config to get the directories and then use these values # in the FIND_PATH() and FIND_LIBRARY() calls FIND_PACKAGE(PkgConfig) - PKG_CHECK_MODULES(PKG_WAYLAND QUIET wayland-client wayland-server wayland-egl wayland-cursor) + PKG_CHECK_MODULES(PKG_WAYLAND QUIET wayland-client wayland-server wayland-egl wayland-cursor wayland-protocols) SET(WAYLAND_DEFINITIONS ${PKG_WAYLAND_CFLAGS}) @@ -41,6 +41,14 @@ IF (NOT WIN32) FIND_LIBRARY(WAYLAND_EGL_LIBRARIES NAMES wayland-egl HINTS ${PKG_WAYLAND_LIBRARY_DIRS}) FIND_LIBRARY(WAYLAND_CURSOR_LIBRARIES NAMES wayland-cursor HINTS ${PKG_WAYLAND_LIBRARY_DIRS}) + FIND_PROGRAM(WAYLAND_SCANNER NAMES wayland-scanner) + pkg_get_variable(WAYLAND_PROTOCOLS_DATA_PATH wayland-protocols pkgdatadir) + FIND_FILE(WAYLAND_PROTO_XDG_SHELL_XML NAMES xdg-shell-unstable-v6.xml + PATHS ${WAYLAND_PROTOCOLS_DATA_PATH} + PATH_SUFFIXES unstable/xdg-shell + REQUIRED + NO_DEFAULT_PATH) + set(WAYLAND_INCLUDE_DIR ${WAYLAND_CLIENT_INCLUDE_DIR} ${WAYLAND_SERVER_INCLUDE_DIR} ${WAYLAND_EGL_INCLUDE_DIR} ${WAYLAND_CURSOR_INCLUDE_DIR}) set(WAYLAND_LIBRARIES ${WAYLAND_CLIENT_LIBRARIES} ${WAYLAND_SERVER_LIBRARIES} ${WAYLAND_EGL_LIBRARIES} ${WAYLAND_CURSOR_LIBRARIES}) -- 2.34.1