Clean up the EGL related video backends (X11, Android, RPi)
authorGabriel Jacobo <gabomdq@gmail.com>
Thu, 14 Nov 2013 20:14:02 -0300
changeset 7986ffb7bf531644
parent 7985 1e2d63f57e04
child 7987 0f8c3cbcec54
Clean up the EGL related video backends (X11, Android, RPi)
src/video/SDL_egl.c
src/video/android/SDL_androidwindow.c
src/video/raspberry/SDL_rpivideo.c
src/video/x11/SDL_x11opengles.c
src/video/x11/SDL_x11opengles.h
     1.1 --- a/src/video/SDL_egl.c	Thu Nov 14 14:45:00 2013 -0500
     1.2 +++ b/src/video/SDL_egl.c	Thu Nov 14 20:14:02 2013 -0300
     1.3 @@ -209,9 +209,7 @@
     1.4      }
     1.5      
     1.6      /* We need to select a config here to satisfy some video backends such as X11 */
     1.7 -    SDL_EGL_ChooseConfig(_this);
     1.8 -    
     1.9 -    return 0;
    1.10 +    return SDL_EGL_ChooseConfig(_this);
    1.11  }
    1.12  
    1.13  int
    1.14 @@ -399,9 +397,6 @@
    1.15          _this->egl_data->eglDestroyContext(_this->egl_data->egl_display, egl_context);
    1.16      }
    1.17          
    1.18 -    /* FIXME: This "crappy fix" comes from the X11 code, 
    1.19 -     * it's required so you can create a GLX context, destroy it and create a EGL one */
    1.20 -    SDL_EGL_UnloadLibrary(_this);
    1.21  }
    1.22  
    1.23  EGLSurface *
     2.1 --- a/src/video/android/SDL_androidwindow.c	Thu Nov 14 14:45:00 2013 -0500
     2.2 +++ b/src/video/android/SDL_androidwindow.c	Thu Nov 14 20:14:02 2013 -0300
     2.3 @@ -72,6 +72,7 @@
     2.4      data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->native_window);
     2.5  
     2.6      if (data->egl_surface == EGL_NO_SURFACE) {
     2.7 +        ANativeWindow_release(data->native_window);
     2.8          SDL_free(data);
     2.9          return SDL_SetError("Could not create GLES window surface");
    2.10      }
    2.11 @@ -102,6 +103,9 @@
    2.12          
    2.13          if(window->driverdata) {
    2.14              data = (SDL_WindowData *) window->driverdata;
    2.15 +            if (data->egl_surface != EGL_NO_SURFACE) {
    2.16 +                SDL_EGL_DestroySurface(_this, data->egl_surface);
    2.17 +            }
    2.18              if(data->native_window) {
    2.19                  ANativeWindow_release(data->native_window);
    2.20              }
     3.1 --- a/src/video/raspberry/SDL_rpivideo.c	Thu Nov 14 14:45:00 2013 -0500
     3.2 +++ b/src/video/raspberry/SDL_rpivideo.c	Thu Nov 14 20:14:02 2013 -0300
     3.3 @@ -281,6 +281,22 @@
     3.4      return 0;
     3.5  }
     3.6  
     3.7 +void
     3.8 +RPI_DestroyWindow(_THIS, SDL_Window * window)
     3.9 +{
    3.10 +    SDL_WindowData *data;
    3.11 +        
    3.12 +    if(window->driverdata) {
    3.13 +        data = (SDL_WindowData *) window->driverdata;
    3.14 +        if (data->egl_surface != EGL_NO_SURFACE) {
    3.15 +            SDL_EGL_DestroySurface(_this, data->egl_surface);
    3.16 +            data->egl_surface = EGL_NO_SURFACE;
    3.17 +        }
    3.18 +        SDL_free(window->driverdata);
    3.19 +        window->driverdata = NULL;
    3.20 +    }
    3.21 +}
    3.22 +
    3.23  int
    3.24  RPI_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
    3.25  {
    3.26 @@ -332,10 +348,6 @@
    3.27  {
    3.28  
    3.29  }
    3.30 -void
    3.31 -RPI_DestroyWindow(_THIS, SDL_Window * window)
    3.32 -{
    3.33 -}
    3.34  
    3.35  /*****************************************************************************/
    3.36  /* SDL Window Manager function                                               */
     4.1 --- a/src/video/x11/SDL_x11opengles.c	Thu Nov 14 14:45:00 2013 -0500
     4.2 +++ b/src/video/x11/SDL_x11opengles.c	Thu Nov 14 20:14:02 2013 -0300
     4.3 @@ -100,6 +100,19 @@
     4.4      return context;
     4.5  }
     4.6  
     4.7 +void
     4.8 +X11_GLES_DeleteContext(_THIS, SDL_GLContext context)
     4.9 +{
    4.10 +    /* FIXME: This "crappy fix" comes from the previous GLES X11 code, 
    4.11 +     * it's required so you can create a GLX context, destroy it and create a EGL one 
    4.12 +     * To be able to fix this, we need to add a function SDL_GL_ResetContext and
    4.13 +     * disallow SDL_GL_MakeCurrent from taking a NULL pointer, thus ensuring we can
    4.14 +     * determine if it is a GLX or EGL context
    4.15 +     */
    4.16 +    SDL_EGL_DeleteContext(_this, context);
    4.17 +    X11_GLES_UnloadLibrary(_this);
    4.18 +}
    4.19 +
    4.20  SDL_EGL_SwapWindow_impl(X11)
    4.21  SDL_EGL_MakeCurrent_impl(X11)
    4.22  
     5.1 --- a/src/video/x11/SDL_x11opengles.h	Thu Nov 14 14:45:00 2013 -0500
     5.2 +++ b/src/video/x11/SDL_x11opengles.h	Thu Nov 14 20:14:02 2013 -0300
     5.3 @@ -38,13 +38,13 @@
     5.4  #define X11_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
     5.5  #define X11_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
     5.6  #define X11_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
     5.7 -#define X11_GLES_DeleteContext SDL_EGL_DeleteContext
     5.8  
     5.9  extern int X11_GLES_LoadLibrary(_THIS, const char *path);
    5.10  extern XVisualInfo *X11_GLES_GetVisual(_THIS, Display * display, int screen);
    5.11  extern SDL_GLContext X11_GLES_CreateContext(_THIS, SDL_Window * window);
    5.12  extern void X11_GLES_SwapWindow(_THIS, SDL_Window * window);
    5.13  extern int X11_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
    5.14 +extern void X11_GLES_DeleteContext(_THIS, SDL_GLContext context);
    5.15  
    5.16  #endif /* SDL_VIDEO_OPENGL_EGL */
    5.17