src/video/wayland/SDL_waylandopengles.c
author Sebastian Krzyszkowiak <dos@dosowisko.net>
Wed, 07 Nov 2018 01:08:35 +0100
changeset 12400 28303fca62bd
parent 11811 5d94cb6b24d3
child 12503 806492103856
permissions -rw-r--r--
wayland: fix resizing and fullscreen toggling
For starters, we need to correctly respond to 0,0 configure after unsetting
fullscreen. Also, turns out that there should be no drawing calls at all
in between eglSwapBuffers and wl_egl_window_resize, as otherwise EGL can
already allocate a wrongly sized buffer for a next frame, so handle those
together.
gabomdq@8062
     1
/*
gabomdq@8062
     2
  Simple DirectMedia Layer
slouken@11811
     3
  Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
gabomdq@8062
     4
gabomdq@8062
     5
  This software is provided 'as-is', without any express or implied
gabomdq@8062
     6
  warranty.  In no event will the authors be held liable for any damages
gabomdq@8062
     7
  arising from the use of this software.
gabomdq@8062
     8
gabomdq@8062
     9
  Permission is granted to anyone to use this software for any purpose,
gabomdq@8062
    10
  including commercial applications, and to alter it and redistribute it
gabomdq@8062
    11
  freely, subject to the following restrictions:
gabomdq@8062
    12
gabomdq@8062
    13
  1. The origin of this software must not be misrepresented; you must not
gabomdq@8062
    14
     claim that you wrote the original software. If you use this software
gabomdq@8062
    15
     in a product, an acknowledgment in the product documentation would be
gabomdq@8062
    16
     appreciated but is not required.
gabomdq@8062
    17
  2. Altered source versions must be plainly marked as such, and must not be
gabomdq@8062
    18
     misrepresented as being the original software.
gabomdq@8062
    19
  3. This notice may not be removed or altered from any source distribution.
gabomdq@8062
    20
*/
gabomdq@8104
    21
#include "../../SDL_internal.h"
gabomdq@8062
    22
gabomdq@8062
    23
#if SDL_VIDEO_DRIVER_WAYLAND && SDL_VIDEO_OPENGL_EGL
gabomdq@8062
    24
dos@12400
    25
#include "../SDL_sysvideo.h"
dos@12400
    26
#include "../../events/SDL_windowevents_c.h"
gabomdq@8062
    27
#include "SDL_waylandvideo.h"
gabomdq@8062
    28
#include "SDL_waylandopengles.h"
gabomdq@8062
    29
#include "SDL_waylandwindow.h"
gabomdq@8062
    30
#include "SDL_waylandevents_c.h"
gabomdq@8104
    31
#include "SDL_waylanddyn.h"
gabomdq@8062
    32
dos@12400
    33
#include "xdg-shell-client-protocol.h"
dos@12400
    34
#include "xdg-shell-unstable-v6-client-protocol.h"
dos@12400
    35
gabomdq@8062
    36
/* EGL implementation of SDL OpenGL ES support */
gabomdq@8062
    37
gabomdq@8062
    38
int
gabomdq@8062
    39
Wayland_GLES_LoadLibrary(_THIS, const char *path) {
gabomdq@8062
    40
    int ret;
gabomdq@8062
    41
    SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
gabomdq@8062
    42
    
slouken@11175
    43
    ret = SDL_EGL_LoadLibrary(_this, path, (NativeDisplayType) data->display, 0);
gabomdq@8062
    44
gabomdq@8062
    45
    Wayland_PumpEvents(_this);
gabomdq@8104
    46
    WAYLAND_wl_display_flush(data->display);
gabomdq@8062
    47
    
gabomdq@8062
    48
    return ret;
gabomdq@8062
    49
}
gabomdq@8062
    50
gabomdq@8062
    51
gabomdq@8062
    52
SDL_GLContext
gabomdq@8062
    53
Wayland_GLES_CreateContext(_THIS, SDL_Window * window)
gabomdq@8062
    54
{
gabomdq@8062
    55
    SDL_GLContext context;
gabomdq@8062
    56
    context = SDL_EGL_CreateContext(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);
gabomdq@8104
    57
    WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
gabomdq@8062
    58
    
gabomdq@8062
    59
    return context;
gabomdq@8062
    60
}
gabomdq@8062
    61
slouken@10695
    62
int
gabomdq@8062
    63
Wayland_GLES_SwapWindow(_THIS, SDL_Window *window)
gabomdq@8062
    64
{
dos@12400
    65
    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
dos@12400
    66
    struct wl_region *region;
dos@12400
    67
dos@12400
    68
    if (SDL_EGL_SwapBuffers(_this, data->egl_surface) < 0) {
slouken@10695
    69
        return -1;
slouken@10695
    70
    }
dos@12400
    71
dos@12400
    72
    // Wayland-EGL forbids drawing calls in-between SwapBuffers and wl_egl_window_resize
dos@12400
    73
    if (data->resize.pending) {
dos@12400
    74
        SDL_SendWindowEvent(window, SDL_WINDOWEVENT_RESIZED, data->resize.width, data->resize.height);
dos@12400
    75
        window->w = data->resize.width;
dos@12400
    76
        window->h = data->resize.height;
dos@12400
    77
dos@12400
    78
        WAYLAND_wl_egl_window_resize(data->egl_window, window->w, window->h, 0, 0);
dos@12400
    79
dos@12400
    80
        if (data->waylandData->shell.xdg) {
dos@12400
    81
           xdg_surface_ack_configure(data->shell_surface.xdg.surface, data->resize.serial);
dos@12400
    82
        } else if (data->waylandData->shell.zxdg) {
dos@12400
    83
           zxdg_surface_v6_ack_configure(data->shell_surface.zxdg.surface, data->resize.serial);
dos@12400
    84
        }
dos@12400
    85
dos@12400
    86
        region = wl_compositor_create_region(data->waylandData->compositor);
dos@12400
    87
        wl_region_add(region, 0, 0, window->w, window->h);
dos@12400
    88
        wl_surface_set_opaque_region(data->surface, region);
dos@12400
    89
        wl_region_destroy(region);
dos@12400
    90
dos@12400
    91
        data->resize.pending = SDL_FALSE;
dos@12400
    92
    }
dos@12400
    93
dos@12400
    94
    WAYLAND_wl_display_flush( data->waylandData->display );
dos@12400
    95
slouken@10695
    96
    return 0;
gabomdq@8062
    97
}
gabomdq@8062
    98
gabomdq@8062
    99
int
gabomdq@8062
   100
Wayland_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context)
gabomdq@8062
   101
{
gabomdq@8062
   102
    int ret;
gabomdq@8062
   103
    
gabomdq@8062
   104
    if (window && context) {
gabomdq@8062
   105
        ret = SDL_EGL_MakeCurrent(_this, ((SDL_WindowData *) window->driverdata)->egl_surface, context);
gabomdq@8062
   106
    }
gabomdq@8062
   107
    else {
gabomdq@8062
   108
        ret = SDL_EGL_MakeCurrent(_this, NULL, NULL);
gabomdq@8062
   109
    }
gabomdq@8062
   110
    
gabomdq@8104
   111
    WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
gabomdq@8062
   112
    
gabomdq@8062
   113
    return ret;
gabomdq@8062
   114
}
gabomdq@8062
   115
gabomdq@8062
   116
void 
gabomdq@8062
   117
Wayland_GLES_DeleteContext(_THIS, SDL_GLContext context)
gabomdq@8062
   118
{
gabomdq@8062
   119
    SDL_EGL_DeleteContext(_this, context);
gabomdq@8104
   120
    WAYLAND_wl_display_flush( ((SDL_VideoData*)_this->driverdata)->display );
gabomdq@8062
   121
}
gabomdq@8062
   122
gabomdq@8062
   123
#endif /* SDL_VIDEO_DRIVER_WAYLAND && SDL_VIDEO_OPENGL_EGL */
gabomdq@8062
   124
slouken@8149
   125
/* vi: set ts=4 sw=4 expandtab: */