Clean up the EGL related video backends (X11, Android, RPi)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
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 */