SDL  2.0
SDL_offscreenvideo.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 
22 #include "../../SDL_internal.h"
23 
24 #if SDL_VIDEO_DRIVER_OFFSCREEN
25 
26 /* Offscreen video driver is similar to dummy driver, however its purpose
27  * is enabling applications to use some of the SDL video functionality
28  * (notably context creation) while not requiring a display output.
29  *
30  * An example would be running a graphical program on a headless box
31  * for automated testing.
32  */
33 
34 #include "SDL_video.h"
35 #include "SDL_mouse.h"
36 #include "../SDL_sysvideo.h"
37 #include "../SDL_pixels_c.h"
38 #include "../../events/SDL_events_c.h"
39 
40 #include "SDL_offscreenvideo.h"
41 #include "SDL_offscreenevents_c.h"
43 #include "SDL_offscreenopengl.h"
44 
45 #define OFFSCREENVID_DRIVER_NAME "offscreen"
46 
47 /* Initialization/Query functions */
48 static int OFFSCREEN_VideoInit(_THIS);
49 static int OFFSCREEN_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode);
50 static void OFFSCREEN_VideoQuit(_THIS);
51 
52 /* OFFSCREEN driver bootstrap functions */
53 
54 static void
55 OFFSCREEN_DeleteDevice(SDL_VideoDevice * device)
56 {
58 }
59 
60 static SDL_VideoDevice *
61 OFFSCREEN_CreateDevice(int devindex)
62 {
64 
65  /* Initialize all variables that we clean on shutdown */
67  if (!device) {
69  return (0);
70  }
71 
72  /* General video */
73  device->VideoInit = OFFSCREEN_VideoInit;
74  device->VideoQuit = OFFSCREEN_VideoQuit;
75  device->SetDisplayMode = OFFSCREEN_SetDisplayMode;
76  device->PumpEvents = OFFSCREEN_PumpEvents;
77  device->CreateWindowFramebuffer = SDL_OFFSCREEN_CreateWindowFramebuffer;
78  device->UpdateWindowFramebuffer = SDL_OFFSCREEN_UpdateWindowFramebuffer;
79  device->DestroyWindowFramebuffer = SDL_OFFSCREEN_DestroyWindowFramebuffer;
80  device->free = OFFSCREEN_DeleteDevice;
81 
82  /* GL context */
83  device->GL_SwapWindow = OFFSCREEN_GL_SwapWindow;
84  device->GL_MakeCurrent = OFFSCREEN_GL_MakeCurrent;
85  device->GL_CreateContext = OFFSCREEN_GL_CreateContext;
86  device->GL_DeleteContext = OFFSCREEN_GL_DeleteContext;
87  device->GL_LoadLibrary = OFFSCREEN_GL_LoadLibrary;
88  device->GL_UnloadLibrary = OFFSCREEN_GL_UnloadLibrary;
89  device->GL_GetProcAddress = OFFSCREEN_GL_GetProcAddress;
90  device->GL_GetSwapInterval = OFFSCREEN_GL_GetSwapInterval;
91  device->GL_SetSwapInterval = OFFSCREEN_GL_SetSwapInterval;
92 
93  /* "Window" */
94  device->CreateSDLWindow = OFFSCREEN_CreateWindow;
95  device->DestroyWindow = OFFSCREEN_DestroyWindow;
96 
97  return device;
98 }
99 
101  OFFSCREENVID_DRIVER_NAME, "SDL offscreen video driver",
102  OFFSCREEN_CreateDevice
103 };
104 
105 int
106 OFFSCREEN_VideoInit(_THIS)
107 {
109  SDL_Mouse *mouse = NULL;
110 
111  /* Use a fake 32-bpp desktop mode */
112  mode.format = SDL_PIXELFORMAT_RGB888;
113  mode.w = 1024;
114  mode.h = 768;
115  mode.refresh_rate = 0;
116  mode.driverdata = NULL;
117  if (SDL_AddBasicVideoDisplay(&mode) < 0) {
118  return -1;
119  }
120 
121  SDL_zero(mode);
123 
124  /* We're done! */
125  return 0;
126 }
127 
128 static int
129 OFFSCREEN_SetDisplayMode(_THIS, SDL_VideoDisplay * display, SDL_DisplayMode * mode)
130 {
131  return 0;
132 }
133 
134 void
135 OFFSCREEN_VideoQuit(_THIS)
136 {
137 }
138 
139 #endif /* SDL_VIDEO_DRIVER_OFFSCREEN */
140 
141 /* vi: set ts=4 sw=4 expandtab: */
#define _THIS
#define SDL_free
#define SDL_calloc
#define SDL_OutOfMemory()
Definition: SDL_error.h:88
void OFFSCREEN_PumpEvents(_THIS)
int SDL_OFFSCREEN_UpdateWindowFramebuffer(_THIS, SDL_Window *window, const SDL_Rect *rects, int numrects)
int SDL_OFFSCREEN_CreateWindowFramebuffer(_THIS, SDL_Window *window, Uint32 *format, void **pixels, int *pitch)
void SDL_OFFSCREEN_DestroyWindowFramebuffer(_THIS, SDL_Window *window)
int OFFSCREEN_GL_SwapWindow(_THIS, SDL_Window *window)
#define OFFSCREEN_GL_SetSwapInterval
void * OFFSCREEN_GL_GetProcAddress(_THIS, const char *proc)
#define OFFSCREEN_GL_GetSwapInterval
int OFFSCREEN_GL_LoadLibrary(_THIS, const char *path)
int OFFSCREEN_GL_MakeCurrent(_THIS, SDL_Window *window, SDL_GLContext context)
SDL_GLContext OFFSCREEN_GL_CreateContext(_THIS, SDL_Window *window)
#define OFFSCREEN_GL_DeleteContext
void OFFSCREEN_GL_UnloadLibrary(_THIS)
void OFFSCREEN_DestroyWindow(_THIS, SDL_Window *window)
int OFFSCREEN_CreateWindow(_THIS, SDL_Window *window)
GLenum mode
@ SDL_PIXELFORMAT_RGB888
Definition: SDL_pixels.h:246
#define SDL_zero(x)
Definition: SDL_stdinc.h:426
int SDL_AddBasicVideoDisplay(const SDL_DisplayMode *desktop_mode)
Definition: SDL_video.c:593
VideoBootStrap OFFSCREEN_bootstrap
SDL_bool SDL_AddDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode)
Definition: SDL_video.c:792
static SDL_VideoDevice * _this
Definition: SDL_video.c:126
#define NULL
Definition: begin_code.h:163
static SDL_AudioDeviceID device
Definition: loopwave.c:37
The structure that defines a display mode.
Definition: SDL_video.h:54
SDL_VideoDisplay * displays
Definition: SDL_sysvideo.h:326