wayland: Add the ability to import and wrap external surfaces

Add the ability to import and wrap external surfaces from external toolkits such as Qt and GTK.

Wayland surfaces and windows are more intrinsically tied to the client library than other windowing systems, so it is necessary to provide a way to initialize SDL with an existing wl_display object, which needs to be set prior to video system initialization, or export the internal SDL wl_display object for use by external applications or toolkits. For this, the global property SDL_PROPERTY_GLOBAL_VIDEO_WAYLAND_WL_DISPLAY_POINTER is used.

A Wayland example was added to testnative, and a basic example of Qt 6 interoperation is provided in the Wayland readme to demonstrate the use of external windows with both SDL owning the wl_display, and an external toolkit owning it.
This commit is contained in:
Frank Praznik
2024-01-09 11:38:38 -05:00
parent 99f6bcf504
commit 4f3d4bd110
11 changed files with 548 additions and 64 deletions

View File

@@ -30,6 +30,9 @@ static NativeWindowFactory *factories[] = {
#ifdef TEST_NATIVE_WINDOWS
&WindowsWindowFactory,
#endif
#ifdef TEST_NATIVE_WAYLAND
&WaylandWindowFactory,
#endif
#ifdef TEST_NATIVE_X11
&X11WindowFactory,
#endif
@@ -47,10 +50,10 @@ static SDLTest_CommonState *state;
static void
quit(int rc)
{
SDL_Quit();
if (native_window && factory) {
factory->DestroyNativeWindow(native_window);
}
SDL_Quit();
SDLTest_CommonDestroyState(state);
/* Let 'main()' return normally */
if (rc != 0) {
@@ -149,6 +152,9 @@ int main(int argc, char *argv[])
}
props = SDL_CreateProperties();
SDL_SetProperty(props, "sdl2-compat.external_window", native_window);
SDL_SetBooleanProperty(props, SDL_PROPERTY_WINDOW_CREATE_OPENGL_BOOLEAN, SDL_TRUE);
SDL_SetNumberProperty(props, SDL_PROPERTY_WINDOW_CREATE_WIDTH_NUMBER, WINDOW_W);
SDL_SetNumberProperty(props, SDL_PROPERTY_WINDOW_CREATE_HEIGHT_NUMBER, WINDOW_H);
window = SDL_CreateWindowWithProperties(props);
SDL_DestroyProperties(props);
if (!window) {