src/video/SDL_egl_c.h
author Sam Lantinga <slouken@libsdl.org>
Wed, 31 Oct 2018 15:16:51 -0700
changeset 12376 cfc65d4d49ae
parent 12269 754cd2042e21
child 12503 806492103856
permissions -rw-r--r--
Fixed bug 4349 - SDL_CreateWindow fails with KMS/DRM after upgrading Mesa to 18.2.3

Rainer Sabelka

After I did an upgrade of my arch Linux installation (resulting in an update of Mesa to version 18.2.3), all my SDL2 applications which use the KMS/DRM driver stopped working.
Reason: Creating a Window with SDL_CreateWindow failed because the call to EGL
eglCreateWindowSurface() returns an error "EGL_BAD_MATCH".
After investigating with the debugger I figured, that the configuration, which has been selected from the output of eglChooseConfig(), has an "EGL_NATIVE_VISUAL_ID" which does not match the "format" of the underlying gbm surface.

The attached patch fixes the problem. It does so, by mimicking Weston's behavior.
All configurations returned from eglChooseConfig() which have an visual_id different from the gbm format are discarded, and only from the remaining ones the "best" match is selected.
gabomdq@8021
     1
/*
gabomdq@8021
     2
  Simple DirectMedia Layer
slouken@11811
     3
  Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
gabomdq@8021
     4
gabomdq@8021
     5
  This software is provided 'as-is', without any express or implied
gabomdq@8021
     6
  warranty.  In no event will the authors be held liable for any damages
gabomdq@8021
     7
  arising from the use of this software.
gabomdq@8021
     8
gabomdq@8021
     9
  Permission is granted to anyone to use this software for any purpose,
gabomdq@8021
    10
  including commercial applications, and to alter it and redistribute it
gabomdq@8021
    11
  freely, subject to the following restrictions:
gabomdq@8021
    12
gabomdq@8021
    13
  1. The origin of this software must not be misrepresented; you must not
gabomdq@8021
    14
     claim that you wrote the original software. If you use this software
gabomdq@8021
    15
     in a product, an acknowledgment in the product documentation would be
gabomdq@8021
    16
     appreciated but is not required.
gabomdq@8021
    17
  2. Altered source versions must be plainly marked as such, and must not be
gabomdq@8021
    18
     misrepresented as being the original software.
gabomdq@8021
    19
  3. This notice may not be removed or altered from any source distribution.
gabomdq@8021
    20
*/
icculus@8093
    21
#include "../SDL_internal.h"
gabomdq@8021
    22
slouken@10638
    23
#ifndef SDL_egl_h_
slouken@10638
    24
#define SDL_egl_h_
gabomdq@8021
    25
gabomdq@8021
    26
#if SDL_VIDEO_OPENGL_EGL
gabomdq@8021
    27
gabomdq@8021
    28
#include "SDL_egl.h"
gabomdq@8021
    29
gabomdq@8021
    30
#include "SDL_sysvideo.h"
gabomdq@8021
    31
gabomdq@8021
    32
typedef struct SDL_EGL_VideoData
gabomdq@8021
    33
{
gabomdq@8021
    34
    void *egl_dll_handle, *dll_handle;
gabomdq@8021
    35
    EGLDisplay egl_display;
gabomdq@8021
    36
    EGLConfig egl_config;
gabomdq@8021
    37
    int egl_swapinterval;
slouken@11677
    38
    int egl_surfacetype;
slouken@12269
    39
    int egl_version_major, egl_version_minor;
slouken@12376
    40
    EGLint egl_required_visual_id;
gabomdq@8021
    41
    
gabomdq@8021
    42
    EGLDisplay(EGLAPIENTRY *eglGetDisplay) (NativeDisplayType display);
slouken@11175
    43
    EGLDisplay(EGLAPIENTRY *eglGetPlatformDisplay) (EGLenum platform,
slouken@11175
    44
                                void *native_display,
slouken@11175
    45
                                const EGLint *attrib_list);
slouken@11175
    46
    EGLDisplay(EGLAPIENTRY *eglGetPlatformDisplayEXT) (EGLenum platform,
slouken@11175
    47
                                void *native_display,
slouken@11175
    48
                                const EGLint *attrib_list);
gabomdq@8021
    49
    EGLBoolean(EGLAPIENTRY *eglInitialize) (EGLDisplay dpy, EGLint * major,
gabomdq@8021
    50
                                EGLint * minor);
gabomdq@8021
    51
    EGLBoolean(EGLAPIENTRY  *eglTerminate) (EGLDisplay dpy);
gabomdq@8021
    52
    
gabomdq@8021
    53
    void *(EGLAPIENTRY *eglGetProcAddress) (const char * procName);
gabomdq@8021
    54
    
gabomdq@8021
    55
    EGLBoolean(EGLAPIENTRY *eglChooseConfig) (EGLDisplay dpy,
gabomdq@8021
    56
                                  const EGLint * attrib_list,
gabomdq@8021
    57
                                  EGLConfig * configs,
gabomdq@8021
    58
                                  EGLint config_size, EGLint * num_config);
gabomdq@8021
    59
    
gabomdq@8021
    60
    EGLContext(EGLAPIENTRY *eglCreateContext) (EGLDisplay dpy,
gabomdq@8021
    61
                                   EGLConfig config,
gabomdq@8021
    62
                                   EGLContext share_list,
gabomdq@8021
    63
                                   const EGLint * attrib_list);
gabomdq@8021
    64
    
gabomdq@8021
    65
    EGLBoolean(EGLAPIENTRY *eglDestroyContext) (EGLDisplay dpy, EGLContext ctx);
gabomdq@8021
    66
    
slouken@11719
    67
    EGLSurface(EGLAPIENTRY *eglCreatePbufferSurface)(EGLDisplay dpy, EGLConfig config,
slouken@11718
    68
                                                     EGLint const* attrib_list);
slouken@11718
    69
gabomdq@8021
    70
    EGLSurface(EGLAPIENTRY *eglCreateWindowSurface) (EGLDisplay dpy,
gabomdq@8021
    71
                                         EGLConfig config,
gabomdq@8021
    72
                                         NativeWindowType window,
gabomdq@8021
    73
                                         const EGLint * attrib_list);
gabomdq@8021
    74
    EGLBoolean(EGLAPIENTRY *eglDestroySurface) (EGLDisplay dpy, EGLSurface surface);
gabomdq@8021
    75
    
gabomdq@8021
    76
    EGLBoolean(EGLAPIENTRY *eglMakeCurrent) (EGLDisplay dpy, EGLSurface draw,
gabomdq@8021
    77
                                 EGLSurface read, EGLContext ctx);
gabomdq@8021
    78
    
gabomdq@8021
    79
    EGLBoolean(EGLAPIENTRY *eglSwapBuffers) (EGLDisplay dpy, EGLSurface draw);
gabomdq@8021
    80
    
gabomdq@8021
    81
    EGLBoolean(EGLAPIENTRY *eglSwapInterval) (EGLDisplay dpy, EGLint interval);
gabomdq@8021
    82
    
gabomdq@8021
    83
    const char *(EGLAPIENTRY *eglQueryString) (EGLDisplay dpy, EGLint name);
gabomdq@8021
    84
    
gabomdq@8021
    85
    EGLBoolean(EGLAPIENTRY  *eglGetConfigAttrib) (EGLDisplay dpy, EGLConfig config,
gabomdq@8021
    86
                                     EGLint attribute, EGLint * value);
gabomdq@8021
    87
    
gabomdq@8021
    88
    EGLBoolean(EGLAPIENTRY *eglWaitNative) (EGLint  engine);
gabomdq@8021
    89
gabomdq@8021
    90
    EGLBoolean(EGLAPIENTRY *eglWaitGL)(void);
gabomdq@8062
    91
    
gabomdq@8062
    92
    EGLBoolean(EGLAPIENTRY *eglBindAPI)(EGLenum);
gabomdq@8062
    93
dludwig@10740
    94
    EGLint(EGLAPIENTRY *eglGetError)(void);
dludwig@10740
    95
gabomdq@8021
    96
} SDL_EGL_VideoData;
gabomdq@8021
    97
gabomdq@8021
    98
/* OpenGLES functions */
gabomdq@8021
    99
extern int SDL_EGL_GetAttribute(_THIS, SDL_GLattr attrib, int *value);
slouken@11175
   100
/* SDL_EGL_LoadLibrary can get a display for a specific platform (EGL_PLATFORM_*)
slouken@11175
   101
 * or, if 0 is passed, let the implementation decide.
slouken@11175
   102
 */
slouken@11175
   103
extern int SDL_EGL_LoadLibrary(_THIS, const char *path, NativeDisplayType native_display, EGLenum platform);
gabomdq@8021
   104
extern void *SDL_EGL_GetProcAddress(_THIS, const char *proc);
gabomdq@8021
   105
extern void SDL_EGL_UnloadLibrary(_THIS);
slouken@12376
   106
extern void SDL_EGL_SetRequiredVisualId(_THIS, int visual_id);
gabomdq@8021
   107
extern int SDL_EGL_ChooseConfig(_THIS);
gabomdq@8021
   108
extern int SDL_EGL_SetSwapInterval(_THIS, int interval);
gabomdq@8021
   109
extern int SDL_EGL_GetSwapInterval(_THIS);
gabomdq@8021
   110
extern void SDL_EGL_DeleteContext(_THIS, SDL_GLContext context);
gabomdq@8021
   111
extern EGLSurface *SDL_EGL_CreateSurface(_THIS, NativeWindowType nw);
gabomdq@8021
   112
extern void SDL_EGL_DestroySurface(_THIS, EGLSurface egl_surface);
gabomdq@8021
   113
gabomdq@8021
   114
/* These need to be wrapped to get the surface for the window by the platform GLES implementation */
gabomdq@8021
   115
extern SDL_GLContext SDL_EGL_CreateContext(_THIS, EGLSurface egl_surface);
gabomdq@8021
   116
extern int SDL_EGL_MakeCurrent(_THIS, EGLSurface egl_surface, SDL_GLContext context);
slouken@10690
   117
extern int SDL_EGL_SwapBuffers(_THIS, EGLSurface egl_surface);
gabomdq@8021
   118
dludwig@10740
   119
/* SDL Error-reporting */
dludwig@10740
   120
extern int SDL_EGL_SetErrorEx(const char * message, const char * eglFunctionName, EGLint eglErrorCode);
dludwig@10740
   121
#define SDL_EGL_SetError(message, eglFunctionName) SDL_EGL_SetErrorEx(message, eglFunctionName, _this->egl_data->eglGetError())
dludwig@10740
   122
gabomdq@8021
   123
/* A few of useful macros */
gabomdq@8021
   124
slouken@10690
   125
#define SDL_EGL_SwapWindow_impl(BACKEND) int \
gabomdq@8021
   126
BACKEND ## _GLES_SwapWindow(_THIS, SDL_Window * window) \
gabomdq@8021
   127
{\
slouken@10690
   128
    return SDL_EGL_SwapBuffers(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);\
gabomdq@8021
   129
}
gabomdq@8021
   130
gabomdq@8021
   131
#define SDL_EGL_MakeCurrent_impl(BACKEND) int \
gabomdq@8021
   132
BACKEND ## _GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context) \
gabomdq@8021
   133
{\
gabomdq@8021
   134
    if (window && context) { \
gabomdq@8021
   135
        return SDL_EGL_MakeCurrent(_this, ((SDL_WindowData *) window->driverdata)->egl_surface, context); \
gabomdq@8021
   136
    }\
gabomdq@8021
   137
    else {\
gabomdq@8021
   138
        return SDL_EGL_MakeCurrent(_this, NULL, NULL);\
gabomdq@8021
   139
    }\
gabomdq@8021
   140
}
gabomdq@8021
   141
gabomdq@8021
   142
#define SDL_EGL_CreateContext_impl(BACKEND) SDL_GLContext \
gabomdq@8021
   143
BACKEND ## _GLES_CreateContext(_THIS, SDL_Window * window) \
gabomdq@8021
   144
{\
gabomdq@8021
   145
    return SDL_EGL_CreateContext(_this, ((SDL_WindowData *) window->driverdata)->egl_surface);\
gabomdq@8021
   146
}
gabomdq@8021
   147
gabomdq@8021
   148
#endif /* SDL_VIDEO_OPENGL_EGL */
gabomdq@8021
   149
slouken@10638
   150
#endif /* SDL_egl_h_ */
gabomdq@8021
   151
gabomdq@8021
   152
/* vi: set ts=4 sw=4 expandtab: */