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