Mac and Linux SDL2 binary snapshots
Edward Rudd
2020-05-02 03f8528315fa46c95991a34f3325d7b33ae5538c
source/src/video/wayland/SDL_waylandvideo.c
@@ -1,6 +1,6 @@
/*
  Simple DirectMedia Layer
  Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
  This software is provided 'as-is', without any express or implied
  warranty.  In no event will the authors be held liable for any damages
@@ -47,6 +47,8 @@
#include "xdg-shell-client-protocol.h"
#include "xdg-shell-unstable-v6-client-protocol.h"
#include "xdg-decoration-unstable-v1-client-protocol.h"
#include "org-kde-kwin-server-decoration-manager-client-protocol.h"
#define WAYLANDVID_DRIVER_NAME "wayland"
@@ -170,6 +172,7 @@
    device->GL_SwapWindow = Wayland_GLES_SwapWindow;
    device->GL_GetSwapInterval = Wayland_GLES_GetSwapInterval;
    device->GL_SetSwapInterval = Wayland_GLES_SetSwapInterval;
    device->GL_GetDrawableSize = Wayland_GLES_GetDrawableSize;
    device->GL_MakeCurrent = Wayland_GLES_MakeCurrent;
    device->GL_CreateContext = Wayland_GLES_CreateContext;
    device->GL_LoadLibrary = Wayland_GLES_LoadLibrary;
@@ -182,6 +185,7 @@
    device->SetWindowFullscreen = Wayland_SetWindowFullscreen;
    device->MaximizeWindow = Wayland_MaximizeWindow;
    device->RestoreWindow = Wayland_RestoreWindow;
    device->SetWindowBordered = Wayland_SetWindowBordered;
    device->SetWindowSize = Wayland_SetWindowSize;
    device->SetWindowTitle = Wayland_SetWindowTitle;
    device->DestroyWindow = Wayland_DestroyWindow;
@@ -196,6 +200,7 @@
    device->Vulkan_UnloadLibrary = Wayland_Vulkan_UnloadLibrary;
    device->Vulkan_GetInstanceExtensions = Wayland_Vulkan_GetInstanceExtensions;
    device->Vulkan_CreateSurface = Wayland_Vulkan_CreateSurface;
    device->Vulkan_GetDrawableSize = Wayland_Vulkan_GetDrawableSize;
#endif
    device->free = Wayland_DeleteDevice;
@@ -223,7 +228,6 @@
    SDL_VideoDisplay *display = data;
    display->name = SDL_strdup(model);
    display->driverdata = output;
}
static void
@@ -234,15 +238,15 @@
                    int height,
                    int refresh)
{
    SDL_VideoDisplay *display = data;
    SDL_DisplayMode mode;
    SDL_VideoDisplay *display = data;
    SDL_zero(mode);
    mode.format = SDL_PIXELFORMAT_RGB888;
    mode.w = width;
    mode.h = height;
    mode.refresh_rate = refresh / 1000; // mHz to Hz
    mode.driverdata = display->driverdata;
    mode.driverdata = ((SDL_WaylandOutputData*)display->driverdata)->output;
    SDL_AddDisplayMode(display, &mode);
    if (flags & WL_OUTPUT_MODE_CURRENT) {
@@ -255,8 +259,10 @@
display_handle_done(void *data,
                    struct wl_output *output)
{
    /* !!! FIXME: this will fail on any further property changes! */
    SDL_VideoDisplay *display = data;
    SDL_AddVideoDisplay(display);
    wl_output_set_user_data(output, display->driverdata);
    SDL_free(display->name);
    SDL_free(display);
}
@@ -266,7 +272,8 @@
                     struct wl_output *output,
                     int32_t factor)
{
    // TODO: do HiDPI stuff.
    SDL_VideoDisplay *display = data;
    ((SDL_WaylandOutputData*)display->driverdata)->scale_factor = factor;
}
static const struct wl_output_listener output_listener = {
@@ -280,6 +287,7 @@
Wayland_add_display(SDL_VideoData *d, uint32_t id)
{
    struct wl_output *output;
    SDL_WaylandOutputData *data;
    SDL_VideoDisplay *display = SDL_malloc(sizeof *display);
    if (!display) {
        SDL_OutOfMemory();
@@ -293,6 +301,10 @@
        SDL_free(display);
        return;
    }
    data = SDL_malloc(sizeof *data);
    data->output = output;
    data->scale_factor = 1.0;
    display->driverdata = data;
    wl_output_add_listener(output, &output_listener, display);
}
@@ -345,8 +357,10 @@
{
    SDL_VideoData *d = data;
    /*printf("WAYLAND INTERFACE: %s\n", interface);*/
    if (strcmp(interface, "wl_compositor") == 0) {
        d->compositor = wl_registry_bind(d->registry, id, &wl_compositor_interface, 1);
        d->compositor = wl_registry_bind(d->registry, id, &wl_compositor_interface, SDL_min(3, version));
    } else if (strcmp(interface, "wl_output") == 0) {
        Wayland_add_display(d, id);
    } else if (strcmp(interface, "wl_seat") == 0) {
@@ -367,7 +381,11 @@
    } else if (strcmp(interface, "zwp_pointer_constraints_v1") == 0) {
        Wayland_display_add_pointer_constraints(d, id);
    } else if (strcmp(interface, "wl_data_device_manager") == 0) {
        d->data_device_manager = wl_registry_bind(d->registry, id, &wl_data_device_manager_interface, 3);
        d->data_device_manager = wl_registry_bind(d->registry, id, &wl_data_device_manager_interface, SDL_min(3, version));
    } else if (strcmp(interface, "zxdg_decoration_manager_v1") == 0) {
        d->decoration_manager = wl_registry_bind(d->registry, id, &zxdg_decoration_manager_v1_interface, 1);
    } else if (strcmp(interface, "org_kde_kwin_server_decoration_manager") == 0) {
        d->kwin_server_decoration_manager = wl_registry_bind(d->registry, id, &org_kde_kwin_server_decoration_manager_interface, 1);
#ifdef SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH
    } else if (strcmp(interface, "qt_touch_extension") == 0) {
@@ -383,18 +401,20 @@
    }
}
static void
display_remove_global(void *data, struct wl_registry *registry, uint32_t id) {}
static const struct wl_registry_listener registry_listener = {
    display_handle_global,
    NULL, /* global_remove */
    display_remove_global
};
int
Wayland_VideoInit(_THIS)
{
    SDL_VideoData *data = SDL_malloc(sizeof *data);
    SDL_VideoData *data = SDL_calloc(1, sizeof(*data));
    if (data == NULL)
        return SDL_OutOfMemory();
    memset(data, 0, sizeof *data);
    _this->driverdata = data;
@@ -454,7 +474,9 @@
    for (i = 0; i < _this->num_displays; ++i) {
        SDL_VideoDisplay *display = &_this->displays[i];
        wl_output_destroy(display->driverdata);
        wl_output_destroy(((SDL_WaylandOutputData*)display->driverdata)->output);
        SDL_free(display->driverdata);
        display->driverdata = NULL;
        for (j = display->num_display_modes; j--;) {