Commit 35915d4f99433fa4083b1340d03d1c3b1e972d83

Gabriel Jacobo 2013-11-14T20:14:02

Clean up the EGL related video backends (X11, Android, RPi)

diff --git a/src/video/SDL_egl.c b/src/video/SDL_egl.c
index 70a1cee..f9ab8fa 100644
--- a/src/video/SDL_egl.c
+++ b/src/video/SDL_egl.c
@@ -209,9 +209,7 @@ SDL_EGL_LoadLibrary(_THIS, const char *egl_path, NativeDisplayType native_displa
     }
     
     /* 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 @@ SDL_EGL_DeleteContext(_THIS, SDL_GLContext context)
         _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 *
diff --git a/src/video/android/SDL_androidwindow.c b/src/video/android/SDL_androidwindow.c
index acc40db..cdc3a5c 100644
--- a/src/video/android/SDL_androidwindow.c
+++ b/src/video/android/SDL_androidwindow.c
@@ -72,6 +72,7 @@ Android_CreateWindow(_THIS, SDL_Window * window)
     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 @@ Android_DestroyWindow(_THIS, SDL_Window * window)
         
         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);
             }
diff --git a/src/video/raspberry/SDL_rpivideo.c b/src/video/raspberry/SDL_rpivideo.c
index dfad9ba..bf03b5b 100644
--- a/src/video/raspberry/SDL_rpivideo.c
+++ b/src/video/raspberry/SDL_rpivideo.c
@@ -281,6 +281,22 @@ RPI_CreateWindow(_THIS, SDL_Window * window)
     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 @@ RPI_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed)
 {
 
 }
-void
-RPI_DestroyWindow(_THIS, SDL_Window * window)
-{
-}
 
 /*****************************************************************************/
 /* SDL Window Manager function                                               */
diff --git a/src/video/x11/SDL_x11opengles.c b/src/video/x11/SDL_x11opengles.c
index f972cee..f5947e4 100644
--- a/src/video/x11/SDL_x11opengles.c
+++ b/src/video/x11/SDL_x11opengles.c
@@ -100,6 +100,19 @@ X11_GLES_CreateContext(_THIS, SDL_Window * window)
     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)
 
diff --git a/src/video/x11/SDL_x11opengles.h b/src/video/x11/SDL_x11opengles.h
index 978f91f..9574e1c 100644
--- a/src/video/x11/SDL_x11opengles.h
+++ b/src/video/x11/SDL_x11opengles.h
@@ -38,13 +38,13 @@ typedef struct SDL_PrivateGLESData
 #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 */