Clean up the EGL related video backends (X11, Android, RPi)
authorGabriel Jacobo <gabomdq@gmail.com>
Thu, 14 Nov 2013 20:14:02 -0300
changeset 7986 ffb7bf531644
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
--- a/src/video/SDL_egl.c	Thu Nov 14 14:45:00 2013 -0500
+++ b/src/video/SDL_egl.c	Thu Nov 14 20:14:02 2013 -0300
@@ -209,9 +209,7 @@
     }
     
     /* We need to select a config here to satisfy some video backends such as X11 */
-    SDL_EGL_ChooseConfig(_this);
-    
-    return 0;
+    return SDL_EGL_ChooseConfig(_this);
 }
 
 int
@@ -399,9 +397,6 @@
         _this->egl_data->eglDestroyContext(_this->egl_data->egl_display, egl_context);
     }
         
-    /* FIXME: This "crappy fix" comes from the X11 code, 
-     * it's required so you can create a GLX context, destroy it and create a EGL one */
-    SDL_EGL_UnloadLibrary(_this);
 }
 
 EGLSurface *
--- a/src/video/android/SDL_androidwindow.c	Thu Nov 14 14:45:00 2013 -0500
+++ b/src/video/android/SDL_androidwindow.c	Thu Nov 14 20:14:02 2013 -0300
@@ -72,6 +72,7 @@
     data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->native_window);
 
     if (data->egl_surface == EGL_NO_SURFACE) {
+        ANativeWindow_release(data->native_window);
         SDL_free(data);
         return SDL_SetError("Could not create GLES window surface");
     }
@@ -102,6 +103,9 @@
         
         if(window->driverdata) {
             data = (SDL_WindowData *) window->driverdata;
+            if (data->egl_surface != EGL_NO_SURFACE) {
+                SDL_EGL_DestroySurface(_this, data->egl_surface);
+            }
             if(data->native_window) {
                 ANativeWindow_release(data->native_window);
             }
--- a/src/video/raspberry/SDL_rpivideo.c	Thu Nov 14 14:45:00 2013 -0500
+++ b/src/video/raspberry/SDL_rpivideo.c	Thu Nov 14 20:14:02 2013 -0300
@@ -281,6 +281,22 @@
     return 0;
 }
 
+void
+RPI_DestroyWindow(_THIS, SDL_Window * window)
+{
+    SDL_WindowData *data;
+        
+    if(window->driverdata) {
+        data = (SDL_WindowData *) window->driverdata;
+        if (data->egl_surface != EGL_NO_SURFACE) {
+            SDL_EGL_DestroySurface(_this, data->egl_surface);
+            data->egl_surface = EGL_NO_SURFACE;
+        }
+        SDL_free(window->driverdata);
+        window->driverdata = NULL;
+    }
+}
+
 int
 RPI_CreateWindowFrom(_THIS, SDL_Window * window, const void *data)
 {
@@ -332,10 +348,6 @@
 {
 
 }
-void
-RPI_DestroyWindow(_THIS, SDL_Window * window)
-{
-}
 
 /*****************************************************************************/
 /* SDL Window Manager function                                               */
--- a/src/video/x11/SDL_x11opengles.c	Thu Nov 14 14:45:00 2013 -0500
+++ b/src/video/x11/SDL_x11opengles.c	Thu Nov 14 20:14:02 2013 -0300
@@ -100,6 +100,19 @@
     return context;
 }
 
+void
+X11_GLES_DeleteContext(_THIS, SDL_GLContext context)
+{
+    /* FIXME: This "crappy fix" comes from the previous GLES X11 code, 
+     * it's required so you can create a GLX context, destroy it and create a EGL one 
+     * To be able to fix this, we need to add a function SDL_GL_ResetContext and
+     * disallow SDL_GL_MakeCurrent from taking a NULL pointer, thus ensuring we can
+     * determine if it is a GLX or EGL context
+     */
+    SDL_EGL_DeleteContext(_this, context);
+    X11_GLES_UnloadLibrary(_this);
+}
+
 SDL_EGL_SwapWindow_impl(X11)
 SDL_EGL_MakeCurrent_impl(X11)
 
--- a/src/video/x11/SDL_x11opengles.h	Thu Nov 14 14:45:00 2013 -0500
+++ b/src/video/x11/SDL_x11opengles.h	Thu Nov 14 20:14:02 2013 -0300
@@ -38,13 +38,13 @@
 #define X11_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
 #define X11_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
 #define X11_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
-#define X11_GLES_DeleteContext SDL_EGL_DeleteContext
 
 extern int X11_GLES_LoadLibrary(_THIS, const char *path);
 extern XVisualInfo *X11_GLES_GetVisual(_THIS, Display * display, int screen);
 extern SDL_GLContext X11_GLES_CreateContext(_THIS, SDL_Window * window);
 extern void X11_GLES_SwapWindow(_THIS, SDL_Window * window);
 extern int X11_GLES_MakeCurrent(_THIS, SDL_Window * window, SDL_GLContext context);
+extern void X11_GLES_DeleteContext(_THIS, SDL_GLContext context);
 
 #endif /* SDL_VIDEO_OPENGL_EGL */