Fixed building offscreen video driver without EGL support

Also did miscellaneous style cleanup for consistency with other code
This commit is contained in:
Sam Lantinga 2022-09-15 12:04:08 -07:00
parent cc9638f2f7
commit 6de15ffcd6
10 changed files with 70 additions and 107 deletions

View File

@ -18,7 +18,6 @@
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_OFFSCREEN

View File

@ -18,11 +18,8 @@
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#include "SDL_offscreenvideo.h"
extern void OFFSCREEN_PumpEvents(_THIS);
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -18,7 +18,6 @@
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_OFFSCREEN

View File

@ -18,7 +18,6 @@
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
extern int SDL_OFFSCREEN_CreateWindowFramebuffer(_THIS, SDL_Window * window, Uint32 * format, void ** pixels, int *pitch);

View File

@ -18,48 +18,18 @@
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_OFFSCREEN
#if SDL_VIDEO_DRIVER_OFFSCREEN && SDL_VIDEO_OPENGL_EGL
#include "SDL_offscreenopengl.h"
#include "SDL_offscreenopengles.h"
#include "SDL_offscreenvideo.h"
#include "SDL_offscreenwindow.h"
#include "SDL_opengl.h"
/* EGL implementation of SDL OpenGL support */
int
OFFSCREEN_GL_SwapWindow(_THIS, SDL_Window* window)
{
OFFSCREEN_Window* offscreen_wind = window->driverdata;
SDL_EGL_SwapBuffers(_this, offscreen_wind->egl_surface);
return 0;
}
int
OFFSCREEN_GL_MakeCurrent(_THIS, SDL_Window* window, SDL_GLContext context)
{
if (window) {
EGLSurface egl_surface = ((OFFSCREEN_Window*)window->driverdata)->egl_surface;
return SDL_EGL_MakeCurrent(_this, egl_surface, context);
}
return SDL_EGL_MakeCurrent(_this, NULL, NULL);
}
SDL_GLContext
OFFSCREEN_GL_CreateContext(_THIS, SDL_Window* window)
{
OFFSCREEN_Window* offscreen_window = window->driverdata;
SDL_GLContext context;
context = SDL_EGL_CreateContext(_this, offscreen_window->egl_surface);
return context;
}
int
OFFSCREEN_GL_LoadLibrary(_THIS, const char* path)
OFFSCREEN_GLES_LoadLibrary(_THIS, const char* path)
{
int ret = SDL_EGL_LoadLibraryOnly(_this, path);
if (ret != 0) {
@ -85,24 +55,36 @@ OFFSCREEN_GL_LoadLibrary(_THIS, const char* path)
return 0;
}
void
OFFSCREEN_GL_UnloadLibrary(_THIS)
SDL_GLContext
OFFSCREEN_GLES_CreateContext(_THIS, SDL_Window* window)
{
SDL_EGL_UnloadLibrary(_this);
OFFSCREEN_Window* offscreen_window = window->driverdata;
SDL_GLContext context;
context = SDL_EGL_CreateContext(_this, offscreen_window->egl_surface);
return context;
}
void*
OFFSCREEN_GL_GetProcAddress(_THIS, const char* proc)
int
OFFSCREEN_GLES_MakeCurrent(_THIS, SDL_Window* window, SDL_GLContext context)
{
void* proc_addr = SDL_EGL_GetProcAddress(_this, proc);
if (!proc_addr) {
SDL_SetError("Failed to find proc address!");
if (window) {
EGLSurface egl_surface = ((OFFSCREEN_Window*)window->driverdata)->egl_surface;
return SDL_EGL_MakeCurrent(_this, egl_surface, context);
} else {
return SDL_EGL_MakeCurrent(_this, NULL, NULL);
}
return proc_addr;
}
#endif /* SDL_VIDEO_DRIVER_OFFSCREEN */
int
OFFSCREEN_GLES_SwapWindow(_THIS, SDL_Window* window)
{
OFFSCREEN_Window* offscreen_wind = window->driverdata;
return SDL_EGL_SwapBuffers(_this, offscreen_wind->egl_surface);
}
#endif /* SDL_VIDEO_DRIVER_OFFSCREEN && SDL_VIDEO_OPENGL_EGL */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -18,37 +18,30 @@
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef _SDL_offscreenopengl_h
#define _SDL_offscreenopengl_h
#ifndef _SDL_offscreenopengles_h
#define _SDL_offscreenopengles_h
#include "SDL_offscreenwindow.h"
#if SDL_VIDEO_DRIVER_OFFSCREEN && SDL_VIDEO_OPENGL_EGL
#include "../SDL_sysvideo.h"
#include "../SDL_egl_c.h"
#define OFFSCREEN_GL_DeleteContext SDL_EGL_DeleteContext
#define OFFSCREEN_GL_GetSwapInterval SDL_EGL_GetSwapInterval
#define OFFSCREEN_GL_SetSwapInterval SDL_EGL_SetSwapInterval
#define OFFSCREEN_GLES_GetProcAddress SDL_EGL_GetProcAddress
#define OFFSCREEN_GLES_UnloadLibrary SDL_EGL_UnloadLibrary
#define OFFSCREEN_GLES_GetSwapInterval SDL_EGL_GetSwapInterval
#define OFFSCREEN_GLES_SetSwapInterval SDL_EGL_SetSwapInterval
#define OFFSCREEN_GLES_DeleteContext SDL_EGL_DeleteContext
extern int
OFFSCREEN_GL_SwapWindow(_THIS, SDL_Window* window);
extern int OFFSCREEN_GLES_LoadLibrary(_THIS, const char *path);
extern SDL_GLContext OFFSCREEN_GLES_CreateContext(_THIS, SDL_Window *window);
extern int OFFSCREEN_GLES_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context);
extern int OFFSCREEN_GLES_SwapWindow(_THIS, SDL_Window *window);
extern int
OFFSCREEN_GL_MakeCurrent(_THIS, SDL_Window* window, SDL_GLContext context);
#endif /* SDL_VIDEO_DRIVER_OFFSCREEN && SDL_VIDEO_OPENGL_EGL */
extern SDL_GLContext
OFFSCREEN_GL_CreateContext(_THIS, SDL_Window* window);
extern int
OFFSCREEN_GL_LoadLibrary(_THIS, const char* path);
extern void
OFFSCREEN_GL_UnloadLibrary(_THIS);
extern void*
OFFSCREEN_GL_GetProcAddress(_THIS, const char* proc);
#endif /* _SDL_offscreenopengl_h */
#endif /* _SDL_offscreenopengles_h */
/* vi: set ts=4 sw=4 expandtab: */

View File

@ -18,7 +18,6 @@
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_OFFSCREEN
@ -32,15 +31,12 @@
*/
#include "SDL_video.h"
#include "SDL_mouse.h"
#include "../SDL_sysvideo.h"
#include "../SDL_pixels_c.h"
#include "../../events/SDL_events_c.h"
#include "SDL_offscreenvideo.h"
#include "SDL_offscreenevents_c.h"
#include "SDL_offscreenframebuffer_c.h"
#include "SDL_offscreenopengl.h"
#include "SDL_offscreenopengles.h"
#include "SDL_offscreenwindow.h"
#define OFFSCREENVID_DRIVER_NAME "offscreen"
@ -79,16 +75,18 @@ OFFSCREEN_CreateDevice(void)
device->DestroyWindowFramebuffer = SDL_OFFSCREEN_DestroyWindowFramebuffer;
device->free = OFFSCREEN_DeleteDevice;
#if SDL_VIDEO_OPENGL_EGL
/* GL context */
device->GL_SwapWindow = OFFSCREEN_GL_SwapWindow;
device->GL_MakeCurrent = OFFSCREEN_GL_MakeCurrent;
device->GL_CreateContext = OFFSCREEN_GL_CreateContext;
device->GL_DeleteContext = OFFSCREEN_GL_DeleteContext;
device->GL_LoadLibrary = OFFSCREEN_GL_LoadLibrary;
device->GL_UnloadLibrary = OFFSCREEN_GL_UnloadLibrary;
device->GL_GetProcAddress = OFFSCREEN_GL_GetProcAddress;
device->GL_GetSwapInterval = OFFSCREEN_GL_GetSwapInterval;
device->GL_SetSwapInterval = OFFSCREEN_GL_SetSwapInterval;
device->GL_SwapWindow = OFFSCREEN_GLES_SwapWindow;
device->GL_MakeCurrent = OFFSCREEN_GLES_MakeCurrent;
device->GL_CreateContext = OFFSCREEN_GLES_CreateContext;
device->GL_DeleteContext = OFFSCREEN_GLES_DeleteContext;
device->GL_LoadLibrary = OFFSCREEN_GLES_LoadLibrary;
device->GL_UnloadLibrary = OFFSCREEN_GLES_UnloadLibrary;
device->GL_GetProcAddress = OFFSCREEN_GLES_GetProcAddress;
device->GL_GetSwapInterval = OFFSCREEN_GLES_GetSwapInterval;
device->GL_SetSwapInterval = OFFSCREEN_GLES_SetSwapInterval;
#endif
/* "Window" */
device->CreateSDLWindow = OFFSCREEN_CreateWindow;
@ -106,7 +104,6 @@ int
OFFSCREEN_VideoInit(_THIS)
{
SDL_DisplayMode mode;
SDL_Mouse *mouse = NULL;
/* Use a fake 32-bpp desktop mode */
mode.format = SDL_PIXELFORMAT_RGB888;

View File

@ -18,14 +18,12 @@
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef _SDL_offscreenvideo_h
#define _SDL_offscreenvideo_h
#include "../SDL_sysvideo.h"
#include "../SDL_egl_c.h"
#endif /* _SDL_offscreenvideo_h */

View File

@ -18,7 +18,6 @@
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_OFFSCREEN
@ -31,7 +30,7 @@
int
OFFSCREEN_CreateWindow(_THIS, SDL_Window* window)
{
OFFSCREEN_Window* offscreen_window = SDL_calloc(1, sizeof(OFFSCREEN_Window));
OFFSCREEN_Window *offscreen_window = SDL_calloc(1, sizeof(OFFSCREEN_Window));
if (!offscreen_window) {
return SDL_OutOfMemory();
@ -49,6 +48,7 @@ OFFSCREEN_CreateWindow(_THIS, SDL_Window* window)
offscreen_window->sdl_window = window;
#if SDL_VIDEO_OPENGL_EGL
if (window->flags & SDL_WINDOW_OPENGL) {
if (!_this->egl_data) {
@ -61,10 +61,10 @@ OFFSCREEN_CreateWindow(_THIS, SDL_Window* window)
return SDL_SetError("Failed to created an offscreen surface (EGL display: %p)",
_this->egl_data->egl_display);
}
}
else {
} else {
offscreen_window->egl_surface = EGL_NO_SURFACE;
}
#endif /* SDL_VIDEO_OPENGL_EGL */
return 0;
}
@ -75,7 +75,9 @@ OFFSCREEN_DestroyWindow(_THIS, SDL_Window* window)
OFFSCREEN_Window* offscreen_window = window->driverdata;
if (offscreen_window) {
#if SDL_VIDEO_OPENGL_EGL
SDL_EGL_DestroySurface(_this, offscreen_window->egl_surface);
#endif
SDL_free(offscreen_window);
}

View File

@ -18,27 +18,24 @@
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#ifndef _SDL_offscreenwindow_h
#define _SDL_offscreenwindow_h
#include "../SDL_sysvideo.h"
#include "SDL_syswm.h"
#include "SDL_offscreenvideo.h"
typedef struct {
SDL_Window* sdl_window;
#if SDL_VIDEO_OPENGL_EGL
EGLSurface egl_surface;
#endif
} OFFSCREEN_Window;
extern int
OFFSCREEN_CreateWindow(_THIS, SDL_Window* window);
extern void
OFFSCREEN_DestroyWindow(_THIS, SDL_Window* window);
extern int OFFSCREEN_CreateWindow(_THIS, SDL_Window *window);
extern void OFFSCREEN_DestroyWindow(_THIS, SDL_Window *window);
#endif /* _SDL_offscreenwindow */