Skip to content

Commit

Permalink
Add Wayland protocol dynamic loader generator
Browse files Browse the repository at this point in the history
Add Python script `generate_wayland.py` that generates source
code from a Wayland XML protocol. This script has the same
role as the `wayland-scanner` tool, except that the sources
generated use the GFXReconstruct `WaylandLoader` instead of
directly using `libwayland-client.so` symbols.

The current state now is:
- If the machine that compiles the code does not support
Wayland (no `libwayland-client.so`) then the Wayland code
is simply not compiled and the executable will not support
Wayland (as done until now)
- If the machine that compiles the code supports Wayland
and the executable is ran on a machine that supports
Wayland, then the `libwayland-client.so` of the client
will be loaded using `dlopen` and the generated protocol
sources will initialize protocol constants (interfaces).
- If the machine that compiles the code supports Wayland
but the executable is ran on a machine that does not
support Wayland, then the WaylandLoader will remain
uninitialized and thus not call the generated protocol
sources and not attempt to initialize the protocol
constants.

This way, the binaries will be able no matter the state of
the support of Wayland on the machine that runs them.

Change-Id: I9b3878a71b74002859f4edda6d9a6fe180278a8f
  • Loading branch information
marius-pelegrin-arm committed Feb 22, 2024
1 parent 080c8ea commit 879eae6
Show file tree
Hide file tree
Showing 12 changed files with 945 additions and 2,173 deletions.
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[submodule "external/Vulkan-Headers"]
path = external/Vulkan-Headers
url = https://github.com/KhronosGroup/Vulkan-Headers.git
[submodule "external/wayland-protocols"]
path = external/wayland-protocols
url = https://gitlab.freedesktop.org/wayland/wayland-protocols.git
branch = main
1 change: 1 addition & 0 deletions external/wayland-protocols
Submodule wayland-protocols added at 7f2001
10 changes: 5 additions & 5 deletions framework/application/wayland_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ WaylandContext::~WaylandContext()

if (xdg_wm_base_)
{
wl.xdg_wm_base_destroy(xdg_wm_base_);
wl.xdg->xdg_wm_base_destroy(xdg_wm_base_);
}

if (compositor_)
Expand Down Expand Up @@ -217,11 +217,11 @@ void WaylandContext::HandleRegistryGlobal(
{
wayland_context->shell_ = reinterpret_cast<wl_shell*>(wl.registry_bind(registry, id, wl.shell_interface, 1));
}
else if (util::platform::StringCompare(interface, wl.wm_base_xdg_interface->name) == 0)
else if (util::platform::StringCompare(interface, wl.xdg->xdg_wm_base_interface.name) == 0)
{
wayland_context->xdg_wm_base_ =
reinterpret_cast<xdg_wm_base*>(wl.registry_bind(registry, id, wl.wm_base_xdg_interface, 1));
wl.xdg_wm_base_add_listener(wayland_context->xdg_wm_base_, &xdg_wm_base_listener_, wayland_context);
reinterpret_cast<xdg_wm_base*>(wl.registry_bind(registry, id, &wl.xdg->xdg_wm_base_interface, 1));
wl.xdg->xdg_wm_base_add_listener(wayland_context->xdg_wm_base_, &xdg_wm_base_listener_, wayland_context);
}
else if (util::platform::StringCompare(interface, wl.seat_interface->name) == 0)
{
Expand Down Expand Up @@ -415,7 +415,7 @@ void WaylandContext::HandleOutputScale(void* data, struct wl_output* wl_output,
void WaylandContext::HandleXdgWmBasePing(void* data, struct xdg_wm_base* xdg_wm_base, uint32_t serial)
{
auto& wl = reinterpret_cast<WaylandContext*>(data)->GetWaylandFunctionTable();
wl.xdg_wm_base_pong(xdg_wm_base, serial);
wl.xdg->xdg_wm_base_pong(xdg_wm_base, serial);
}

GFXRECON_END_NAMESPACE(application)
Expand Down
24 changes: 12 additions & 12 deletions framework/application/wayland_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ WaylandWindow::~WaylandWindow()

if (xdg_toplevel_ != nullptr)
{
wl.xdg_toplevel_destroy(xdg_toplevel_);
wl.xdg_surface_destroy(xdg_surface_);
wl.xdg->xdg_toplevel_destroy(xdg_toplevel_);
wl.xdg->xdg_surface_destroy(xdg_surface_);
}
else if (shell_surface_ != nullptr)
{
Expand Down Expand Up @@ -95,11 +95,11 @@ bool WaylandWindow::Create(

if (wayland_context_->GetXdgWmBase() != nullptr)
{
xdg_surface_ = wl.xdg_wm_base_get_xdg_surface(wayland_context_->GetXdgWmBase(), surface_);
xdg_surface_ = wl.xdg->xdg_wm_base_get_xdg_surface(wayland_context_->GetXdgWmBase(), surface_);
if (xdg_surface_ != nullptr)
{
wl.xdg_surface_add_listener(xdg_surface_, &WaylandWindow::xdg_surface_listener_, this);
xdg_toplevel_ = wl.xdg_surface_get_toplevel(xdg_surface_);
wl.xdg->xdg_surface_add_listener(xdg_surface_, &WaylandWindow::xdg_surface_listener_, this);
xdg_toplevel_ = wl.xdg->xdg_surface_get_toplevel(xdg_surface_);
}
}

Expand All @@ -114,7 +114,7 @@ bool WaylandWindow::Create(

if (xdg_toplevel_ != nullptr)
{
wl.xdg_toplevel_add_listener(xdg_toplevel_, &WaylandWindow::xdg_toplevel_listener_, this);
wl.xdg->xdg_toplevel_add_listener(xdg_toplevel_, &WaylandWindow::xdg_toplevel_listener_, this);
}
else if (shell_surface_ != nullptr)
{
Expand All @@ -124,7 +124,7 @@ bool WaylandWindow::Create(
{
if (xdg_surface_ != nullptr)
{
wl.xdg_surface_destroy(xdg_surface_);
wl.xdg->xdg_surface_destroy(xdg_surface_);
xdg_surface_ = nullptr;
}

Expand Down Expand Up @@ -162,9 +162,9 @@ bool WaylandWindow::Destroy()

if (xdg_toplevel_ != nullptr)
{
wl.xdg_toplevel_destroy(xdg_toplevel_);
wl.xdg->xdg_toplevel_destroy(xdg_toplevel_);
xdg_toplevel_ = nullptr;
wl.xdg_surface_destroy(xdg_surface_);
wl.xdg->xdg_surface_destroy(xdg_surface_);
xdg_surface_ = nullptr;

xdg_surface_configured_ = false;
Expand All @@ -189,7 +189,7 @@ void WaylandWindow::SetTitle(const std::string& title)
auto& wl = wayland_context_->GetWaylandFunctionTable();
if (xdg_toplevel_ != nullptr)
{
wl.xdg_toplevel_set_title(xdg_toplevel_, title.c_str());
wl.xdg->xdg_toplevel_set_title(xdg_toplevel_, title.c_str());
}
else if (shell_surface_ != nullptr)
{
Expand Down Expand Up @@ -290,7 +290,7 @@ void WaylandWindow::UpdateWindowSize()
{
if (xdg_toplevel_ != nullptr)
{
wl.xdg_toplevel_set_fullscreen(xdg_toplevel_, output_);
wl.xdg->xdg_toplevel_set_fullscreen(xdg_toplevel_, output_);
}
else if (shell_surface_ != nullptr)
{
Expand Down Expand Up @@ -336,7 +336,7 @@ void WaylandWindow::HandleXdgSurfaceConfigure(void* data, struct xdg_surface* xd

auto& wl = window->wayland_context_->GetWaylandFunctionTable();

wl.xdg_surface_ack_configure(xdg_surface, serial);
wl.xdg->xdg_surface_ack_configure(xdg_surface, serial);
window->xdg_surface_configured_ = true;
}

Expand Down
1 change: 0 additions & 1 deletion framework/application/wayland_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "util/defines.h"

#include <wayland-client.h>
#include "util/xdg-shell-client.h"

GFXRECON_BEGIN_NAMESPACE(gfxrecon)
GFXRECON_BEGIN_NAMESPACE(application)
Expand Down
Loading

0 comments on commit 879eae6

Please sign in to comment.