comparison src/video/SDL_sysvideo.h @ 1662:782fd950bd46 SDL-1.3

Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API. WARNING: None of the video drivers have been updated for the new API yet! The API is still under design and very fluid. The code is now run through a consistent indent format: indent -i4 -nut -nsc -br -ce The headers are being converted to automatically generate doxygen documentation.
author Sam Lantinga <slouken@libsdl.org>
date Sun, 28 May 2006 13:04:16 +0000
parents e49147870aac
children 6e7ec5cb83c3
comparison
equal deleted inserted replaced
1661:281d3f4870e5 1662:782fd950bd46
36 #if SDL_VIDEO_OPENGL 36 #if SDL_VIDEO_OPENGL
37 #include "SDL_opengl.h" 37 #include "SDL_opengl.h"
38 #endif /* SDL_VIDEO_OPENGL */ 38 #endif /* SDL_VIDEO_OPENGL */
39 39
40 /* The SDL video driver */ 40 /* The SDL video driver */
41
42 /* Define the SDL window structure, corresponding to toplevel windows */
43 typedef struct SDL_Window SDL_Window;
44
45 struct SDL_Window
46 {
47 Uint32 id;
48
49 char *title;
50 int x, y;
51 int w, h;
52 Uint32 flags;
53
54 SDL_Surface *surface;
55 SDL_Surface *shadow;
56 Uint16 *gamma;
57
58 void *userdata;
59 void *driverdata;
60 };
61
62 /* Define the SDL display structure
63 This corresponds to physical monitors attached to the system.
64 */
65 typedef struct SDL_VideoDisplay
66 {
67 int num_display_modes;
68 SDL_DisplayMode *display_modes;
69 SDL_DisplayMode desktop_mode;
70 SDL_DisplayMode current_mode;
71
72 int max_windows;
73 int num_windows;
74 SDL_Window *windows;
75
76 void *driverdata;
77 } SDL_VideoDisplay;
78
41 typedef struct SDL_VideoDevice SDL_VideoDevice; 79 typedef struct SDL_VideoDevice SDL_VideoDevice;
42 80
43 /* Define the SDL video driver structure */ 81 /* Define the SDL video driver structure */
44 #define _THIS SDL_VideoDevice *_this 82 #define _THIS SDL_VideoDevice *_this
45 #ifndef _STATUS 83
46 #define _STATUS SDL_status *status 84 struct SDL_VideoDevice
47 #endif 85 {
48 struct SDL_VideoDevice { 86 /* * * */
49 /* * * */ 87 /* The name of this video driver */
50 /* The name of this video driver */ 88 const char *name;
51 const char *name; 89
52 90 /* * * */
53 /* * * */ 91 /* Initialization/Query functions */
54 /* Initialization/Query functions */ 92
55 93 /* Initialize the native video subsystem, filling in the list
56 /* Initialize the native video subsystem, filling 'vformat' with the 94 of displays for this driver, returning 0 or -1 if there's an error.
57 "best" display pixel format, returning 0 or -1 if there's an error. 95 */
58 */ 96 int (*VideoInit) (_THIS);
59 int (*VideoInit)(_THIS, SDL_PixelFormat *vformat); 97
60 98 /* * * */
61 /* List the available video modes for the given pixel format, sorted 99 /* Display functions
62 from largest to smallest. 100 */
63 */ 101 /* Setting the display mode is independent of creating windows,
64 SDL_Rect **(*ListModes)(_THIS, SDL_PixelFormat *format, Uint32 flags); 102 * so when the display mode is changed, all existing windows
65 103 * should have their data updated accordingly, including the
66 /* Set the requested video mode, returning a surface which will be 104 * display surfaces associated with them.
67 set to the SDL_VideoSurface. The width and height will already 105 */
68 be verified by ListModes(), and the video subsystem is free to 106 int (*SetDisplayMode) (_THIS, const SDL_DisplayMode * mode);
69 set the mode to a supported bit depth different from the one 107
70 specified -- the desired bpp will be emulated with a shadow 108 /* * * */
71 surface if necessary. If a new mode is returned, this function 109 /* Window functions
72 should take care of cleaning up the current mode. 110 */
73 */ 111 int (*CreateWindow) (_THIS, SDL_Window * window);
74 SDL_Surface *(*SetVideoMode)(_THIS, SDL_Surface *current, 112 int (*CreateWindowFrom) (_THIS, SDL_Window * window, void *data);
75 int width, int height, int bpp, Uint32 flags); 113 void (*SetWindowTitle) (_THIS, SDL_Window * window);
76 114 void (*SetWindowPosition) (_THIS, SDL_Window * window);
77 /* Toggle the fullscreen mode */ 115 void (*SetWindowSize) (_THIS, SDL_Window * window);
78 int (*ToggleFullScreen)(_THIS, int on); 116 void (*ShowWindow) (_THIS, SDL_Window * window);
79 117 void (*HideWindow) (_THIS, SDL_Window * window);
80 /* This is called after the video mode has been set, to get the 118 void (*RaiseWindow) (_THIS, SDL_Window * window);
81 initial mouse state. It should queue events as necessary to 119 void (*MaximizeWindow) (_THIS, SDL_Window * window);
82 properly represent the current mouse focus and position. 120 void (*MinimizeWindow) (_THIS, SDL_Window * window);
83 */ 121 void (*RestoreWindow) (_THIS, SDL_Window * window);
84 void (*UpdateMouse)(_THIS); 122 void (*SetWindowGrab) (_THIS, SDL_Window * window);
85 123 void (*DestroyWindow) (_THIS, SDL_Window * window);
86 /* Create a YUV video surface (possibly overlay) of the given 124
87 format. The hardware should be able to perform at least 2x 125 SDL_Surface *(*CreateWindowSurface) (_THIS, SDL_Window * window);
88 scaling on display. 126 void (*UpdateWindowSurface) (_THIS, SDL_Window * window, int numrects,
89 */ 127 SDL_Rect * rects);
90 SDL_Overlay *(*CreateYUVOverlay)(_THIS, int width, int height, 128 void (*FlipWindowSurface) (_THIS, SDL_Window * window);
91 Uint32 format, SDL_Surface *display); 129
92 130 /* Sets the color entries { firstcolor .. (firstcolor+ncolors-1) }
93 /* Sets the color entries { firstcolor .. (firstcolor+ncolors-1) } 131 of the physical palette to those in 'colors'. If the device is
94 of the physical palette to those in 'colors'. If the device is 132 using a software palette (SDL_HWPALETTE not set), then the
95 using a software palette (SDL_HWPALETTE not set), then the 133 changes are reflected in the logical palette of the screen
96 changes are reflected in the logical palette of the screen 134 as well.
97 as well. 135 The return value is 1 if all entries could be set properly
98 The return value is 1 if all entries could be set properly 136 or 0 otherwise.
99 or 0 otherwise. 137 */
100 */ 138 int (*SetWindowColors) (_THIS, SDL_Window * window,
101 int (*SetColors)(_THIS, int firstcolor, int ncolors, 139 int firstcolor, int ncolors, SDL_Color * colors);
102 SDL_Color *colors); 140
103 141 /* Get some platform dependent window information */
104 /* This pointer should exist in the native video subsystem and should 142 SDL_bool (*GetWindowWMInfo) (_THIS, SDL_Window * window,
105 point to an appropriate update function for the current video mode 143 SDL_SysWMinfo * info);
106 */ 144
107 void (*UpdateRects)(_THIS, int numrects, SDL_Rect *rects); 145 /* Create a YUV video surface (possibly overlay) of the given
108 146 format. The hardware should be able to perform at least 2x
109 /* Reverse the effects VideoInit() -- called if VideoInit() fails 147 scaling on display.
110 or if the application is shutting down the video subsystem. 148 */
111 */ 149 SDL_Overlay *(*CreateYUVOverlay) (_THIS, int width, int height,
112 void (*VideoQuit)(_THIS); 150 Uint32 format, SDL_Surface * display);
113 151
114 /* * * */ 152 /* Reverse the effects VideoInit() -- called if VideoInit() fails
115 /* Hardware acceleration functions */ 153 or if the application is shutting down the video subsystem.
116 154 */
117 /* Information about the video hardware */ 155 void (*VideoQuit) (_THIS);
118 SDL_VideoInfo info; 156
119 157 /* * * */
120 /* The pixel format used when SDL_CreateRGBSurface creates SDL_HWSURFACEs with alpha */ 158 /* Hardware acceleration functions */
121 SDL_PixelFormat* displayformatalphapixel; 159
122 160 /* Information about the video hardware */
123 /* Allocates a surface in video memory */ 161 SDL_VideoInfo info;
124 int (*AllocHWSurface)(_THIS, SDL_Surface *surface); 162
125 163 /* The pixel format used when SDL_CreateRGBSurface creates SDL_HWSURFACEs with alpha */
126 /* Sets the hardware accelerated blit function, if any, based 164 SDL_PixelFormat *displayformatalphapixel;
127 on the current flags of the surface (colorkey, alpha, etc.) 165
128 */ 166 /* Allocates a surface in video memory */
129 int (*CheckHWBlit)(_THIS, SDL_Surface *src, SDL_Surface *dst); 167 int (*AllocHWSurface) (_THIS, SDL_Surface * surface);
130 168
131 /* Fills a surface rectangle with the given color */ 169 /* Sets the hardware accelerated blit function, if any, based
132 int (*FillHWRect)(_THIS, SDL_Surface *dst, SDL_Rect *rect, Uint32 color); 170 on the current flags of the surface (colorkey, alpha, etc.)
133 171 */
134 /* Sets video mem colorkey and accelerated blit function */ 172 int (*CheckHWBlit) (_THIS, SDL_Surface * src, SDL_Surface * dst);
135 int (*SetHWColorKey)(_THIS, SDL_Surface *surface, Uint32 key); 173
136 174 /* Fills a surface rectangle with the given color */
137 /* Sets per surface hardware alpha value */ 175 int (*FillHWRect) (_THIS, SDL_Surface * dst, SDL_Rect * rect,
138 int (*SetHWAlpha)(_THIS, SDL_Surface *surface, Uint8 value); 176 Uint32 color);
139 177
140 /* Returns a readable/writable surface */ 178 /* Sets video mem colorkey and accelerated blit function */
141 int (*LockHWSurface)(_THIS, SDL_Surface *surface); 179 int (*SetHWColorKey) (_THIS, SDL_Surface * surface, Uint32 key);
142 void (*UnlockHWSurface)(_THIS, SDL_Surface *surface); 180
143 181 /* Sets per surface hardware alpha value */
144 /* Performs hardware flipping */ 182 int (*SetHWAlpha) (_THIS, SDL_Surface * surface, Uint8 value);
145 int (*FlipHWSurface)(_THIS, SDL_Surface *surface); 183
146 184 /* Returns a readable/writable surface */
147 /* Frees a previously allocated video surface */ 185 int (*LockHWSurface) (_THIS, SDL_Surface * surface);
148 void (*FreeHWSurface)(_THIS, SDL_Surface *surface); 186 void (*UnlockHWSurface) (_THIS, SDL_Surface * surface);
149 187
150 /* * * */ 188 /* Frees a previously allocated video surface */
151 /* Gamma support */ 189 void (*FreeHWSurface) (_THIS, SDL_Surface * surface);
152 190
153 Uint16 *gamma; 191 /* * * */
154 192 /* Gamma support */
155 /* Set the gamma correction directly (emulated with gamma ramps) */ 193
156 int (*SetGamma)(_THIS, float red, float green, float blue); 194 /* Set the gamma correction directly (emulated with gamma ramps) */
157 195 int (*SetGamma) (_THIS, float red, float green, float blue);
158 /* Get the gamma correction directly (emulated with gamma ramps) */ 196
159 int (*GetGamma)(_THIS, float *red, float *green, float *blue); 197 /* Get the gamma correction directly (emulated with gamma ramps) */
160 198 int (*GetGamma) (_THIS, float *red, float *green, float *blue);
161 /* Set the gamma ramp */ 199
162 int (*SetGammaRamp)(_THIS, Uint16 *ramp); 200 /* Set the gamma ramp */
163 201 int (*SetGammaRamp) (_THIS, Uint16 * ramp);
164 /* Get the gamma ramp */ 202
165 int (*GetGammaRamp)(_THIS, Uint16 *ramp); 203 /* Get the gamma ramp */
166 204 int (*GetGammaRamp) (_THIS, Uint16 * ramp);
167 /* * * */ 205
168 /* OpenGL support */ 206 /* * * */
169 207 /* OpenGL support */
170 /* Sets the dll to use for OpenGL and loads it */ 208
171 int (*GL_LoadLibrary)(_THIS, const char *path); 209 /* Sets the dll to use for OpenGL and loads it */
172 210 int (*GL_LoadLibrary) (_THIS, const char *path);
173 /* Retrieves the address of a function in the gl library */ 211
174 void* (*GL_GetProcAddress)(_THIS, const char *proc); 212 /* Retrieves the address of a function in the gl library */
175 213 void *(*GL_GetProcAddress) (_THIS, const char *proc);
176 /* Get attribute information from the windowing system. */ 214
177 int (*GL_GetAttribute)(_THIS, SDL_GLattr attrib, int* value); 215 /* Get attribute information from the windowing system. */
178 216 int (*GL_GetAttribute) (_THIS, SDL_GLattr attrib, int *value);
179 /* Make the context associated with this driver current */ 217
180 int (*GL_MakeCurrent)(_THIS); 218 /* Make the context associated with this driver current */
181 219 int (*GL_MakeCurrent) (_THIS);
182 /* Swap the current buffers in double buffer mode. */ 220
183 void (*GL_SwapBuffers)(_THIS); 221 /* Swap the current buffers in double buffer mode. */
184 222 void (*GL_SwapBuffers) (_THIS);
185 /* OpenGL functions for SDL_OPENGLBLIT */ 223
224 /* OpenGL functions for glSDL */
186 #if SDL_VIDEO_OPENGL 225 #if SDL_VIDEO_OPENGL
187 #if !defined(__WIN32__) 226 #if !defined(__WIN32__)
188 #define WINAPI 227 #define WINAPI
189 #endif 228 #endif
190 #define SDL_PROC(ret,func,params) ret (WINAPI *func) params; 229 #define SDL_PROC(ret,func,params) ret (WINAPI *func) params;
191 #include "SDL_glfuncs.h" 230 #include "SDL_glfuncs.h"
192 #undef SDL_PROC 231 #undef SDL_PROC
193 232
194 /* Texture id */ 233 /* Texture id */
195 GLuint texture; 234 GLuint texture;
196 #endif 235
197 int is_32bit; 236 int is_32bit;
198 237 #endif
199 /* * * */ 238
200 /* Window manager functions */ 239 /* * * */
201 240 /* Cursor manager functions */
202 /* Set the title and icon text */ 241
203 void (*SetCaption)(_THIS, const char *title, const char *icon); 242 /* Free a window manager cursor
204 243 This function can be NULL if CreateWMCursor is also NULL.
205 /* Set the window icon image */ 244 */
206 void (*SetIcon)(_THIS, SDL_Surface *icon, Uint8 *mask); 245 void (*FreeWMCursor) (_THIS, WMcursor * cursor);
207 246
208 /* Iconify the window. 247 /* If not NULL, create a black/white window manager cursor */
209 This function returns 1 if there is a window manager and the 248 WMcursor *(*CreateWMCursor) (_THIS,
210 window was actually iconified, it returns 0 otherwise. 249 Uint8 * data, Uint8 * mask, int w, int h,
211 */ 250 int hot_x, int hot_y);
212 int (*IconifyWindow)(_THIS); 251
213 252 /* Show the specified cursor, or hide if cursor is NULL */
214 /* Grab or ungrab keyboard and mouse input */ 253 int (*ShowWMCursor) (_THIS, WMcursor * cursor);
215 SDL_GrabMode (*GrabInput)(_THIS, SDL_GrabMode mode); 254
216 255 /* Warp the window manager cursor to (x,y)
217 /* Get some platform dependent window information */ 256 If NULL, a mouse motion event is posted internally.
218 int (*GetWMInfo)(_THIS, SDL_SysWMinfo *info); 257 */
219 258 void (*WarpWMCursor) (_THIS, Uint16 x, Uint16 y);
220 /* * * */ 259
221 /* Cursor manager functions */ 260 /* If not NULL, this is called when a mouse motion event occurs */
222 261 void (*MoveWMCursor) (_THIS, int x, int y);
223 /* Free a window manager cursor 262
224 This function can be NULL if CreateWMCursor is also NULL. 263 /* Determine whether the mouse should be in relative mode or not.
225 */ 264 This function is called when the input grab state or cursor
226 void (*FreeWMCursor)(_THIS, WMcursor *cursor); 265 visibility state changes.
227 266 If the cursor is not visible, and the input is grabbed, the
228 /* If not NULL, create a black/white window manager cursor */ 267 driver can place the mouse in relative mode, which may result
229 WMcursor *(*CreateWMCursor)(_THIS, 268 in higher accuracy sampling of the pointer motion.
230 Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y); 269 */
231 270 void (*CheckMouseMode) (_THIS);
232 /* Show the specified cursor, or hide if cursor is NULL */ 271
233 int (*ShowWMCursor)(_THIS, WMcursor *cursor); 272 /* * * */
234 273 /* Event manager functions */
235 /* Warp the window manager cursor to (x,y) 274
236 If NULL, a mouse motion event is posted internally. 275 /* Initialize keyboard mapping for this driver */
237 */ 276 void (*InitOSKeymap) (_THIS);
238 void (*WarpWMCursor)(_THIS, Uint16 x, Uint16 y); 277
239 278 /* Handle any queued OS events */
240 /* If not NULL, this is called when a mouse motion event occurs */ 279 void (*PumpEvents) (_THIS);
241 void (*MoveWMCursor)(_THIS, int x, int y); 280
242 281 /* * * */
243 /* Determine whether the mouse should be in relative mode or not. 282 /* Data common to all drivers */
244 This function is called when the input grab state or cursor 283 int num_displays;
245 visibility state changes. 284 SDL_VideoDisplay *displays;
246 If the cursor is not visible, and the input is grabbed, the 285 int current_display;
247 driver can place the mouse in relative mode, which may result 286 Uint32 next_window_id;
248 in higher accuracy sampling of the pointer motion. 287
249 */ 288 /* Driver information flags */
250 void (*CheckMouseMode)(_THIS); 289
251 290 /* * * */
252 /* * * */ 291 /* Data used by the GL drivers */
253 /* Event manager functions */ 292 struct
254 293 {
255 /* Initialize keyboard mapping for this driver */ 294 int red_size;
256 void (*InitOSKeymap)(_THIS); 295 int green_size;
257 296 int blue_size;
258 /* Handle any queued OS events */ 297 int alpha_size;
259 void (*PumpEvents)(_THIS); 298 int depth_size;
260 299 int buffer_size;
261 /* * * */ 300 int stencil_size;
262 /* Data common to all drivers */ 301 int double_buffer;
263 SDL_Surface *screen; 302 int accum_red_size;
264 SDL_Surface *shadow; 303 int accum_green_size;
265 SDL_Surface *visible; 304 int accum_blue_size;
266 SDL_Palette *physpal; /* physical palette, if != logical palette */ 305 int accum_alpha_size;
267 SDL_Color *gammacols; /* gamma-corrected colours, or NULL */ 306 int stereo;
268 char *wm_title; 307 int multisamplebuffers;
269 char *wm_icon; 308 int multisamplesamples;
270 int offset_x; 309 int accelerated;
271 int offset_y; 310 int swap_control;
272 SDL_GrabMode input_grab; 311 int driver_loaded;
273 312 char driver_path[256];
274 /* Driver information flags */ 313 void *dll_handle;
275 int handles_any_size; /* Driver handles any size video mode */ 314 } gl_config;
276 315
277 /* * * */ 316 /* * * */
278 /* Data used by the GL drivers */ 317 /* Data private to this driver */
279 struct { 318 struct SDL_PrivateVideoData *hidden;
280 int red_size; 319 struct SDL_PrivateGLData *gl_data;
281 int green_size; 320
282 int blue_size; 321 /* * * */
283 int alpha_size; 322 /* The function used to dispose of this structure */
284 int depth_size; 323 void (*free) (_THIS);
285 int buffer_size;
286 int stencil_size;
287 int double_buffer;
288 int accum_red_size;
289 int accum_green_size;
290 int accum_blue_size;
291 int accum_alpha_size;
292 int stereo;
293 int multisamplebuffers;
294 int multisamplesamples;
295 int accelerated;
296 int swap_control;
297 int driver_loaded;
298 char driver_path[256];
299 void* dll_handle;
300 } gl_config;
301
302 /* * * */
303 /* Data private to this driver */
304 struct SDL_PrivateVideoData *hidden;
305 struct SDL_PrivateGLData *gl_data;
306
307 /* * * */
308 /* The function used to dispose of this structure */
309 void (*free)(_THIS);
310 }; 324 };
311 #undef _THIS 325 #undef _THIS
312 326
313 typedef struct VideoBootStrap { 327 typedef struct VideoBootStrap
314 const char *name; 328 {
315 const char *desc; 329 const char *name;
316 int (*available)(void); 330 const char *desc;
317 SDL_VideoDevice *(*create)(int devindex); 331 int (*available) (void);
332 SDL_VideoDevice *(*create) (int devindex);
318 } VideoBootStrap; 333 } VideoBootStrap;
319 334
320 #if SDL_VIDEO_DRIVER_QUARTZ 335 #if SDL_VIDEO_DRIVER_QUARTZ
321 extern VideoBootStrap QZ_bootstrap; 336 extern VideoBootStrap QZ_bootstrap;
322 #endif 337 #endif
409 #endif 424 #endif
410 #if SDL_VIDEO_DRIVER_GLSDL 425 #if SDL_VIDEO_DRIVER_GLSDL
411 extern VideoBootStrap glSDL_bootstrap; 426 extern VideoBootStrap glSDL_bootstrap;
412 #endif 427 #endif
413 428
414 /* This is the current video device */ 429 #define SDL_CurrentDisplay (_this->displays[_this->current_display])
415 extern SDL_VideoDevice *current_video; 430 #define SDL_CurrentWindow (SDL_CurrentDisplay.windows[0])
416 431 #define SDL_VideoSurface ((_this && SDL_CurrentDisplay.num_windows > 0) ? SDL_CurrentWindow.surface : NULL)
417 #define SDL_VideoSurface (current_video->screen) 432 #define SDL_ShadowSurface ((_this && SDL_CurrentDisplay.num_windows > 0) ? SDL_CurrentWindow.shadow : NULL)
418 #define SDL_ShadowSurface (current_video->shadow) 433 #define SDL_PublicSurface (SDL_ShadowSurface ? SDL_ShadowSurface : SDL_VideoSurface)
419 #define SDL_PublicSurface (current_video->visible) 434
435 extern SDL_VideoDevice *SDL_GetVideoDevice ();
436 extern void SDL_AddBasicVideoDisplay (const SDL_DisplayMode * desktop_mode);
437 extern void SDL_AddVideoDisplay (SDL_VideoDisplay * display);
438 extern void SDL_AddDisplayMode (int display, const SDL_DisplayMode * mode);
439 extern SDL_Window *SDL_GetWindowFromSurface (SDL_Surface * surface);
420 440
421 #endif /* _SDL_sysvideo_h */ 441 #endif /* _SDL_sysvideo_h */
442
443 /* vi: set ts=4 sw=4 expandtab: */