Mercurial > sdl-ios-xcode
annotate src/video/SDL_video.c @ 19:8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
From: "Mike Gorchak" <mike@malva.com.ua>
Subject: Patches for QNX RtP
Here my patch for QNX RtP/Photon for SDL-1.2.
Detailed description of my changes:
SDL/configure.in:
If Photon detected declare define ENABLE_PHOTON.
SDL/src/video/SDL_sysvideo.h:
Added extern to ph_bootstrap.
SDL/src/video/SDL_video.c:
Added ph_bootstrap to bootstrap array.
SDL/src/video/photon/SDL_ph_events.c:
Declare DISABLE_X11 if compiled for Photon.
SDL/src/video/photon/SDL_ph_image.c:
Fixed segment violation on exit. Please update BUGS file.
SDL/src/video/photon/SDL_ph_video.c:
1. Enabling window manager.
2. Added to device capabilities Photon Window Manager functions:
SetCaption and IconifyWindow.
3. Renamed X11_bootstrap to ph_bootstrap.
4. Removed SEGFAULT termination of programs if Photon not available.
SDL/src/video/photon/SDL_ph_wm.c:
1. Declare DISABLE_X11 if compiled for Photon.
2. Added ph_SetCaption and ph_IconifyWindow code. (Thanks to
'phearbear' for iconify window source).
3. Some stubers for other wm functions.
Thanks !
----------------------------
Mike Gorchak
CJSC Malva
System Programmer
author | Sam Lantinga <slouken@lokigames.com> |
---|---|
date | Thu, 10 May 2001 18:42:17 +0000 |
parents | c3e9d4a623c1 |
children | 57bf11a5efd7 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga | |
4 | |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 of the License, or (at your option) any later version. | |
9 | |
10 This library is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
20 slouken@devolution.com | |
21 */ | |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 /* The high-level video driver subsystem */ | |
29 | |
30 #include <stdio.h> | |
31 #include <stdlib.h> | |
32 #include <string.h> | |
33 | |
34 #include "SDL.h" | |
35 #include "SDL_error.h" | |
36 #include "SDL_video.h" | |
37 #include "SDL_events.h" | |
38 #include "SDL_mutex.h" | |
39 #include "SDL_sysvideo.h" | |
40 #include "SDL_sysevents.h" | |
41 #include "SDL_blit.h" | |
42 #include "SDL_pixels_c.h" | |
43 #include "SDL_events_c.h" | |
44 #include "SDL_cursor_c.h" | |
45 | |
46 /* Available video drivers */ | |
47 static VideoBootStrap *bootstrap[] = { | |
48 #ifdef ENABLE_X11 | |
49 &X11_bootstrap, | |
50 #endif | |
51 #ifdef ENABLE_DGA | |
52 &DGA_bootstrap, | |
53 #endif | |
54 #ifdef ENABLE_FBCON | |
55 &FBCON_bootstrap, | |
56 #endif | |
57 #ifdef ENABLE_PS2GS | |
58 &PS2GS_bootstrap, | |
59 #endif | |
60 #ifdef ENABLE_GGI | |
61 &GGI_bootstrap, | |
62 #endif | |
63 #ifdef ENABLE_SVGALIB | |
64 &SVGALIB_bootstrap, | |
65 #endif | |
66 #ifdef ENABLE_AALIB | |
67 &AALIB_bootstrap, | |
68 #endif | |
69 #ifdef ENABLE_DIRECTX | |
70 &DIRECTX_bootstrap, | |
71 #endif | |
72 #ifdef ENABLE_WINDIB | |
73 &WINDIB_bootstrap, | |
74 #endif | |
75 #ifdef ENABLE_BWINDOW | |
76 &BWINDOW_bootstrap, | |
77 #endif | |
78 #ifdef ENABLE_TOOLBOX | |
79 &TOOLBOX_bootstrap, | |
80 #endif | |
81 #ifdef ENABLE_DRAWSPROCKET | |
82 &DSp_bootstrap, | |
83 #endif | |
84 #ifdef ENABLE_CYBERGRAPHICS | |
85 &CGX_bootstrap, | |
86 #endif | |
1
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
87 #ifdef ENABLE_DUMMYVIDEO |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
88 &DUMMY_bootstrap, |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
89 #endif |
19
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
14
diff
changeset
|
90 #ifdef ENABLE_PHOTON |
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
14
diff
changeset
|
91 &ph_bootstrap, |
8cc4dbfab9ab
Date: Thu, 19 Apr 2001 08:36:54 +0300
Sam Lantinga <slouken@lokigames.com>
parents:
14
diff
changeset
|
92 #endif |
0 | 93 NULL |
94 }; | |
95 SDL_VideoDevice *current_video = NULL; | |
96 | |
97 /* Places to store title and icon text for the app */ | |
98 static char *wm_title = NULL; | |
99 static char *wm_icon = NULL; | |
100 | |
101 /* Various local functions */ | |
102 int SDL_VideoInit(const char *driver_name, Uint32 flags); | |
103 void SDL_VideoQuit(void); | |
104 void SDL_GL_UpdateRectsLock(SDL_VideoDevice* this, int numrects, SDL_Rect* rects); | |
105 | |
106 static SDL_GrabMode SDL_WM_GrabInputOff(void); | |
107 #ifdef HAVE_OPENGL | |
108 static int lock_count = 0; | |
109 #endif | |
110 | |
111 | |
112 /* | |
113 * Initialize the video and event subsystems -- determine native pixel format | |
114 */ | |
115 int SDL_VideoInit (const char *driver_name, Uint32 flags) | |
116 { | |
117 SDL_VideoDevice *video; | |
118 int index; | |
119 int i; | |
120 SDL_PixelFormat vformat; | |
121 Uint32 video_flags; | |
122 | |
123 /* Toggle the event thread flags, based on OS requirements */ | |
124 #if defined(MUST_THREAD_EVENTS) | |
125 flags |= SDL_INIT_EVENTTHREAD; | |
126 #elif defined(CANT_THREAD_EVENTS) | |
127 if ( (flags & SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD ) { | |
128 SDL_SetError("OS doesn't support threaded events"); | |
129 return(-1); | |
130 } | |
131 #endif | |
132 | |
133 /* Check to make sure we don't overwrite 'current_video' */ | |
134 if ( current_video != NULL ) { | |
135 SDL_VideoQuit(); | |
136 } | |
137 | |
138 /* Select the proper video driver */ | |
139 index = 0; | |
140 video = NULL; | |
141 if ( driver_name != NULL ) { | |
142 #if 0 /* This will be replaced with a better driver selection API */ | |
143 if ( strrchr(driver_name, ':') != NULL ) { | |
144 index = atoi(strrchr(driver_name, ':')+1); | |
145 } | |
146 #endif | |
147 for ( i=0; bootstrap[i]; ++i ) { | |
148 if ( strncmp(bootstrap[i]->name, driver_name, | |
149 strlen(bootstrap[i]->name)) == 0 ) { | |
150 if ( bootstrap[i]->available() ) { | |
151 video = bootstrap[i]->create(index); | |
152 break; | |
153 } | |
154 } | |
155 } | |
156 } else { | |
157 for ( i=0; bootstrap[i]; ++i ) { | |
158 if ( bootstrap[i]->available() ) { | |
159 video = bootstrap[i]->create(index); | |
160 if ( video != NULL ) { | |
161 break; | |
162 } | |
163 } | |
164 } | |
165 } | |
166 if ( video == NULL ) { | |
167 SDL_SetError("No available video device"); | |
168 return(-1); | |
169 } | |
170 current_video = video; | |
171 current_video->name = bootstrap[i]->name; | |
172 | |
173 /* Do some basic variable initialization */ | |
174 video->screen = NULL; | |
175 video->shadow = NULL; | |
176 video->visible = NULL; | |
177 video->physpal = NULL; | |
178 video->gammacols = NULL; | |
179 video->gamma = NULL; | |
180 video->wm_title = NULL; | |
181 video->wm_icon = NULL; | |
182 video->offset_x = 0; | |
183 video->offset_y = 0; | |
184 memset(&video->info, 0, (sizeof video->info)); | |
185 | |
186 /* Set some very sane GL defaults */ | |
187 video->gl_config.driver_loaded = 0; | |
188 video->gl_config.dll_handle = NULL; | |
189 video->gl_config.red_size = 5; | |
190 #if 1 /* This seems to work on more video cards, as a default */ | |
191 video->gl_config.green_size = 5; | |
192 #else | |
193 video->gl_config.green_size = 6; | |
194 #endif | |
195 video->gl_config.blue_size = 5; | |
196 video->gl_config.alpha_size = 0; | |
197 video->gl_config.buffer_size = 0; | |
198 video->gl_config.depth_size = 16; | |
199 video->gl_config.stencil_size = 0; | |
200 video->gl_config.double_buffer = 1; | |
201 video->gl_config.accum_red_size = 0; | |
202 video->gl_config.accum_green_size = 0; | |
203 video->gl_config.accum_blue_size = 0; | |
204 video->gl_config.accum_alpha_size = 0; | |
205 | |
206 /* Initialize the video subsystem */ | |
207 memset(&vformat, 0, sizeof(vformat)); | |
208 if ( video->VideoInit(video, &vformat) < 0 ) { | |
209 SDL_VideoQuit(); | |
210 return(-1); | |
211 } | |
212 | |
213 /* Create a zero sized video surface of the appropriate format */ | |
214 video_flags = SDL_SWSURFACE; | |
215 SDL_VideoSurface = SDL_CreateRGBSurface(video_flags, 0, 0, | |
216 vformat.BitsPerPixel, | |
217 vformat.Rmask, vformat.Gmask, vformat.Bmask, 0); | |
218 if ( SDL_VideoSurface == NULL ) { | |
219 SDL_VideoQuit(); | |
220 return(-1); | |
221 } | |
222 SDL_PublicSurface = NULL; /* Until SDL_SetVideoMode() */ | |
223 | |
224 #if 0 /* Don't change the current palette - may be used by other programs. | |
225 * The application can't do anything with the display surface until | |
226 * a video mode has been set anyway. :) | |
227 */ | |
228 /* If we have a palettized surface, create a default palette */ | |
229 if ( SDL_VideoSurface->format->palette ) { | |
230 SDL_PixelFormat *vf = SDL_VideoSurface->format; | |
231 SDL_DitherColors(vf->palette->colors, vf->BitsPerPixel); | |
232 video->SetColors(video, | |
233 0, vf->palette->ncolors, vf->palette->colors); | |
234 } | |
235 #endif | |
236 video->info.vfmt = SDL_VideoSurface->format; | |
237 | |
238 /* Start the event loop */ | |
239 if ( SDL_StartEventLoop(flags) < 0 ) { | |
240 SDL_VideoQuit(); | |
241 return(-1); | |
242 } | |
243 SDL_CursorInit(flags & SDL_INIT_EVENTTHREAD); | |
244 | |
245 /* We're ready to go! */ | |
246 return(0); | |
247 } | |
248 | |
249 char *SDL_VideoDriverName(char *namebuf, int maxlen) | |
250 { | |
251 if ( current_video != NULL ) { | |
252 strncpy(namebuf, current_video->name, maxlen-1); | |
253 namebuf[maxlen-1] = '\0'; | |
254 return(namebuf); | |
255 } | |
256 return(NULL); | |
257 } | |
258 | |
259 /* | |
260 * Get the current display surface | |
261 */ | |
262 SDL_Surface *SDL_GetVideoSurface(void) | |
263 { | |
264 SDL_Surface *visible; | |
265 | |
266 visible = NULL; | |
267 if ( current_video ) { | |
268 visible = current_video->visible; | |
269 } | |
270 return(visible); | |
271 } | |
272 | |
273 /* | |
274 * Get the current information about the video hardware | |
275 */ | |
276 const SDL_VideoInfo *SDL_GetVideoInfo(void) | |
277 { | |
278 const SDL_VideoInfo *info; | |
279 | |
280 info = NULL; | |
281 if ( current_video ) { | |
282 info = ¤t_video->info; | |
283 } | |
284 return(info); | |
285 } | |
286 | |
287 /* | |
288 * Return a pointer to an array of available screen dimensions for the | |
289 * given format, sorted largest to smallest. Returns NULL if there are | |
290 * no dimensions available for a particular format, or (SDL_Rect **)-1 | |
291 * if any dimension is okay for the given format. If 'format' is NULL, | |
292 * the mode list will be for the format given by SDL_GetVideoInfo()->vfmt | |
293 */ | |
294 SDL_Rect ** SDL_ListModes (SDL_PixelFormat *format, Uint32 flags) | |
295 { | |
296 SDL_VideoDevice *video = current_video; | |
297 SDL_VideoDevice *this = current_video; | |
298 SDL_Rect **modes; | |
299 | |
300 modes = NULL; | |
301 if ( SDL_VideoSurface ) { | |
302 if ( format == NULL ) { | |
303 format = SDL_VideoSurface->format; | |
304 } | |
305 modes = video->ListModes(this, format, flags); | |
306 } | |
307 return(modes); | |
308 } | |
309 | |
310 /* | |
311 * Check to see if a particular video mode is supported. | |
312 * It returns 0 if the requested mode is not supported under any bit depth, | |
313 * or returns the bits-per-pixel of the closest available mode with the | |
314 * given width and height. If this bits-per-pixel is different from the | |
315 * one used when setting the video mode, SDL_SetVideoMode() will succeed, | |
316 * but will emulate the requested bits-per-pixel with a shadow surface. | |
317 */ | |
318 static Uint8 SDL_closest_depths[4][8] = { | |
319 /* 8 bit closest depth ordering */ | |
320 { 0, 8, 16, 15, 32, 24, 0, 0 }, | |
321 /* 15,16 bit closest depth ordering */ | |
322 { 0, 16, 15, 32, 24, 8, 0, 0 }, | |
323 /* 24 bit closest depth ordering */ | |
324 { 0, 24, 32, 16, 15, 8, 0, 0 }, | |
325 /* 32 bit closest depth ordering */ | |
326 { 0, 32, 16, 15, 24, 8, 0, 0 } | |
327 }; | |
328 | |
329 int SDL_VideoModeOK (int width, int height, int bpp, Uint32 flags) | |
330 { | |
331 int table, b, i; | |
332 int supported; | |
333 SDL_PixelFormat format; | |
334 SDL_Rect **sizes; | |
335 | |
336 /* Currently 1 and 4 bpp are not supported */ | |
337 if ( bpp < 8 || bpp > 32 ) { | |
338 return(0); | |
339 } | |
340 if ( (width == 0) || (height == 0) ) { | |
341 return(0); | |
342 } | |
343 | |
344 /* Search through the list valid of modes */ | |
345 memset(&format, 0, sizeof(format)); | |
346 supported = 0; | |
347 table = ((bpp+7)/8)-1; | |
348 SDL_closest_depths[table][0] = bpp; | |
349 SDL_closest_depths[table][7] = 0; | |
350 for ( b = 0; !supported && SDL_closest_depths[table][b]; ++b ) { | |
351 format.BitsPerPixel = SDL_closest_depths[table][b]; | |
352 sizes = SDL_ListModes(&format, flags); | |
353 if ( sizes == (SDL_Rect **)0 ) { | |
354 /* No sizes supported at this bit-depth */ | |
355 continue; | |
356 } else | |
357 #ifdef macintosh /* MPW optimization bug? */ | |
358 if ( (sizes == (SDL_Rect **)0xFFFFFFFF) || | |
359 #else | |
360 if ( (sizes == (SDL_Rect **)-1) || | |
361 #endif | |
362 current_video->handles_any_size ) { | |
363 /* Any size supported at this bit-depth */ | |
364 supported = 1; | |
365 continue; | |
366 } else | |
367 for ( i=0; sizes[i]; ++i ) { | |
368 if ((sizes[i]->w == width) && (sizes[i]->h == height)) { | |
369 supported = 1; | |
370 break; | |
371 } | |
372 } | |
373 } | |
374 if ( supported ) { | |
375 --b; | |
376 return(SDL_closest_depths[table][b]); | |
377 } else { | |
378 return(0); | |
379 } | |
380 } | |
381 | |
382 /* | |
383 * Get the closest non-emulated video mode to the one requested | |
384 */ | |
385 static int SDL_GetVideoMode (int *w, int *h, int *BitsPerPixel, Uint32 flags) | |
386 { | |
387 int table, b, i; | |
388 int supported; | |
389 int native_bpp; | |
390 SDL_PixelFormat format; | |
391 SDL_Rect **sizes; | |
392 | |
393 /* Try the original video mode, get the closest depth */ | |
394 native_bpp = SDL_VideoModeOK(*w, *h, *BitsPerPixel, flags); | |
395 if ( native_bpp == *BitsPerPixel ) { | |
396 return(1); | |
397 } | |
398 if ( native_bpp > 0 ) { | |
399 *BitsPerPixel = native_bpp; | |
400 return(1); | |
401 } | |
402 | |
403 /* No exact size match at any depth, look for closest match */ | |
404 memset(&format, 0, sizeof(format)); | |
405 supported = 0; | |
406 table = ((*BitsPerPixel+7)/8)-1; | |
407 SDL_closest_depths[table][0] = *BitsPerPixel; | |
408 SDL_closest_depths[table][7] = SDL_VideoSurface->format->BitsPerPixel; | |
409 for ( b = 0; !supported && SDL_closest_depths[table][b]; ++b ) { | |
410 format.BitsPerPixel = SDL_closest_depths[table][b]; | |
411 sizes = SDL_ListModes(&format, flags); | |
412 if ( sizes == (SDL_Rect **)0 ) { | |
413 /* No sizes supported at this bit-depth */ | |
414 continue; | |
415 } | |
416 for ( i=0; sizes[i]; ++i ) { | |
417 if ((sizes[i]->w < *w) || (sizes[i]->h < *h)) { | |
418 if ( i > 0 ) { | |
419 --i; | |
420 *w = sizes[i]->w; | |
421 *h = sizes[i]->h; | |
422 *BitsPerPixel = SDL_closest_depths[table][b]; | |
423 supported = 1; | |
424 } else { | |
425 /* Largest mode too small... */; | |
426 } | |
427 break; | |
428 } | |
429 } | |
430 if ( (i > 0) && ! sizes[i] ) { | |
431 /* The smallest mode was larger than requested, OK */ | |
432 --i; | |
433 *w = sizes[i]->w; | |
434 *h = sizes[i]->h; | |
435 *BitsPerPixel = SDL_closest_depths[table][b]; | |
436 supported = 1; | |
437 } | |
438 } | |
439 if ( ! supported ) { | |
440 SDL_SetError("No video mode large enough for %dx%d", *w, *h); | |
441 } | |
442 return(supported); | |
443 } | |
444 | |
445 /* This should probably go somewhere else -- like SDL_surface.c */ | |
446 static void SDL_ClearSurface(SDL_Surface *surface) | |
447 { | |
448 Uint32 black; | |
449 | |
450 black = SDL_MapRGB(surface->format, 0, 0, 0); | |
451 SDL_FillRect(surface, NULL, black); | |
452 if ((surface->flags&SDL_HWSURFACE) && (surface->flags&SDL_DOUBLEBUF)) { | |
453 SDL_Flip(surface); | |
454 SDL_FillRect(surface, NULL, black); | |
455 } | |
456 SDL_Flip(surface); | |
457 } | |
458 | |
459 /* | |
460 * Create a shadow surface suitable for fooling the app. :-) | |
461 */ | |
462 static void SDL_CreateShadowSurface(int depth) | |
463 { | |
464 Uint32 Rmask, Gmask, Bmask; | |
465 | |
466 /* Allocate the shadow surface */ | |
467 if ( depth == (SDL_VideoSurface->format)->BitsPerPixel ) { | |
468 Rmask = (SDL_VideoSurface->format)->Rmask; | |
469 Gmask = (SDL_VideoSurface->format)->Gmask; | |
470 Bmask = (SDL_VideoSurface->format)->Bmask; | |
471 } else { | |
472 Rmask = Gmask = Bmask = 0; | |
473 } | |
474 SDL_ShadowSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, | |
475 SDL_VideoSurface->w, SDL_VideoSurface->h, | |
476 depth, Rmask, Gmask, Bmask, 0); | |
477 if ( SDL_ShadowSurface == NULL ) { | |
478 return; | |
479 } | |
480 | |
481 /* 8-bit shadow surfaces report that they have exclusive palette */ | |
482 if ( SDL_ShadowSurface->format->palette ) { | |
483 SDL_ShadowSurface->flags |= SDL_HWPALETTE; | |
484 if ( depth == (SDL_VideoSurface->format)->BitsPerPixel ) { | |
485 memcpy(SDL_ShadowSurface->format->palette->colors, | |
486 SDL_VideoSurface->format->palette->colors, | |
487 SDL_VideoSurface->format->palette->ncolors* | |
488 sizeof(SDL_Color)); | |
489 } else { | |
490 SDL_DitherColors( | |
491 SDL_ShadowSurface->format->palette->colors, depth); | |
492 } | |
493 } | |
494 | |
495 /* If the video surface is resizable, the shadow should say so */ | |
496 if ( (SDL_VideoSurface->flags & SDL_RESIZABLE) == SDL_RESIZABLE ) { | |
497 SDL_ShadowSurface->flags |= SDL_RESIZABLE; | |
498 } | |
499 /* If the video surface has no frame, the shadow should say so */ | |
500 if ( (SDL_VideoSurface->flags & SDL_NOFRAME) == SDL_NOFRAME ) { | |
501 SDL_ShadowSurface->flags |= SDL_NOFRAME; | |
502 } | |
503 /* If the video surface is fullscreen, the shadow should say so */ | |
504 if ( (SDL_VideoSurface->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { | |
505 SDL_ShadowSurface->flags |= SDL_FULLSCREEN; | |
506 } | |
507 /* If the video surface is flippable, the shadow should say so */ | |
508 if ( (SDL_VideoSurface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) { | |
509 SDL_ShadowSurface->flags |= SDL_DOUBLEBUF; | |
510 } | |
511 return; | |
512 } | |
513 | |
514 /* | |
515 * Set the requested video mode, allocating a shadow buffer if necessary. | |
516 */ | |
517 SDL_Surface * SDL_SetVideoMode (int width, int height, int bpp, Uint32 flags) | |
518 { | |
519 SDL_VideoDevice *video, *this; | |
520 SDL_Surface *prev_mode, *mode; | |
521 int video_w; | |
522 int video_h; | |
523 int video_bpp; | |
524 int is_opengl; | |
525 SDL_GrabMode saved_grab; | |
526 | |
527 /* Start up the video driver, if necessary.. | |
528 WARNING: This is the only function protected this way! | |
529 */ | |
530 if ( ! current_video ) { | |
531 if ( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE) < 0 ) { | |
532 return(NULL); | |
533 } | |
534 } | |
535 this = video = current_video; | |
536 | |
537 /* Default to the current video bpp */ | |
538 if ( bpp == 0 ) { | |
539 flags |= SDL_ANYFORMAT; | |
540 bpp = SDL_VideoSurface->format->BitsPerPixel; | |
541 } | |
542 | |
543 /* Get a good video mode, the closest one possible */ | |
544 video_w = width; | |
545 video_h = height; | |
546 video_bpp = bpp; | |
547 if ( ! SDL_GetVideoMode(&video_w, &video_h, &video_bpp, flags) ) { | |
548 return(NULL); | |
549 } | |
550 | |
551 /* Check the requested flags */ | |
552 /* There's no palette in > 8 bits-per-pixel mode */ | |
553 if ( video_bpp > 8 ) { | |
554 flags &= ~SDL_HWPALETTE; | |
555 } | |
556 #if 0 | |
557 if ( (flags&SDL_FULLSCREEN) != SDL_FULLSCREEN ) { | |
558 /* There's no windowed double-buffering */ | |
559 flags &= ~SDL_DOUBLEBUF; | |
560 } | |
561 #endif | |
562 if ( (flags&SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) { | |
563 /* Use hardware surfaces when double-buffering */ | |
564 flags |= SDL_HWSURFACE; | |
565 } | |
566 | |
567 is_opengl = ( ( flags & SDL_OPENGL ) == SDL_OPENGL ); | |
568 if ( is_opengl ) { | |
569 /* These flags are for 2D video modes only */ | |
570 flags &= ~(SDL_HWSURFACE|SDL_DOUBLEBUF); | |
571 } | |
572 | |
14
c3e9d4a623c1
Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents:
11
diff
changeset
|
573 /* Reset the keyboard here so event callbacks can run */ |
c3e9d4a623c1
Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents:
11
diff
changeset
|
574 SDL_ResetKeyboard(); |
c3e9d4a623c1
Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents:
11
diff
changeset
|
575 |
0 | 576 /* Clean up any previous video mode */ |
577 if ( SDL_PublicSurface != NULL ) { | |
578 SDL_PublicSurface = NULL; | |
579 } | |
580 if ( SDL_ShadowSurface != NULL ) { | |
581 SDL_Surface *ready_to_go; | |
582 ready_to_go = SDL_ShadowSurface; | |
583 SDL_ShadowSurface = NULL; | |
584 SDL_FreeSurface(ready_to_go); | |
585 } | |
586 if ( video->physpal ) { | |
587 free(video->physpal->colors); | |
588 free(video->physpal); | |
589 video->physpal = NULL; | |
590 } | |
591 if( video->gammacols) { | |
592 free(video->gammacols); | |
593 video->gammacols = NULL; | |
594 } | |
595 | |
596 /* Save the previous grab state and turn off grab for mode switch */ | |
597 saved_grab = SDL_WM_GrabInputOff(); | |
598 | |
599 /* Try to set the video mode, along with offset and clipping */ | |
600 prev_mode = SDL_VideoSurface; | |
601 SDL_LockCursor(); | |
602 SDL_VideoSurface = NULL; /* In case it's freed by driver */ | |
603 mode = video->SetVideoMode(this, prev_mode,video_w,video_h,video_bpp,flags); | |
604 if ( mode ) { /* Prevent resize events from mode change */ | |
605 SDL_PrivateResize(mode->w, mode->h); | |
606 } | |
607 /* | |
608 * rcg11292000 | |
609 * If you try to set an SDL_OPENGL surface, and fail to find a | |
610 * matching visual, then the next call to SDL_SetVideoMode() | |
611 * will segfault, since we no longer point to a dummy surface, | |
612 * but rather NULL. | |
613 * Sam 11/29/00 | |
614 * WARNING, we need to make sure that the previous mode hasn't | |
615 * already been freed by the video driver. What do we do in | |
616 * that case? Should we call SDL_VideoInit() again? | |
617 */ | |
618 SDL_VideoSurface = (mode != NULL) ? mode : prev_mode; | |
619 | |
620 if ( (mode != NULL) && (!is_opengl) ) { | |
621 /* Sanity check */ | |
622 if ( (mode->w < width) || (mode->h < height) ) { | |
623 SDL_SetError("Video mode smaller than requested"); | |
624 return(NULL); | |
625 } | |
626 | |
627 /* If we have a palettized surface, create a default palette */ | |
628 if ( mode->format->palette ) { | |
629 SDL_PixelFormat *vf = mode->format; | |
630 SDL_DitherColors(vf->palette->colors, vf->BitsPerPixel); | |
631 video->SetColors(this, 0, vf->palette->ncolors, | |
632 vf->palette->colors); | |
633 } | |
634 | |
635 /* Clear the surface to black */ | |
636 video->offset_x = 0; | |
637 video->offset_y = 0; | |
638 mode->offset = 0; | |
639 SDL_SetClipRect(mode, NULL); | |
640 SDL_ClearSurface(mode); | |
641 | |
642 /* Now adjust the offsets to match the desired mode */ | |
643 video->offset_x = (mode->w-width)/2; | |
644 video->offset_y = (mode->h-height)/2; | |
645 mode->offset = video->offset_y*mode->pitch + | |
646 video->offset_x*mode->format->BytesPerPixel; | |
647 #ifdef DEBUG_VIDEO | |
648 fprintf(stderr, | |
649 "Requested mode: %dx%dx%d, obtained mode %dx%dx%d (offset %d)\n", | |
650 width, height, bpp, | |
651 mode->w, mode->h, mode->format->BitsPerPixel, mode->offset); | |
652 #endif | |
653 mode->w = width; | |
654 mode->h = height; | |
655 SDL_SetClipRect(mode, NULL); | |
656 } | |
657 SDL_ResetCursor(); | |
658 SDL_UnlockCursor(); | |
659 | |
660 /* If we failed setting a video mode, return NULL... (Uh Oh!) */ | |
661 if ( mode == NULL ) { | |
662 return(NULL); | |
663 } | |
664 | |
665 /* If there is no window manager, set the SDL_NOFRAME flag */ | |
666 if ( ! video->info.wm_available ) { | |
667 mode->flags |= SDL_NOFRAME; | |
668 } | |
669 | |
670 /* Reset the mouse cursor and grab for new video mode */ | |
671 SDL_SetCursor(NULL); | |
672 if ( video->UpdateMouse ) { | |
673 video->UpdateMouse(this); | |
674 } | |
675 SDL_WM_GrabInput(saved_grab); | |
676 SDL_GetRelativeMouseState(NULL, NULL); /* Clear first large delta */ | |
677 | |
678 /* If we're running OpenGL, make the context current */ | |
679 if ( (video->screen->flags & SDL_OPENGL) && | |
680 video->GL_MakeCurrent ) { | |
681 if ( video->GL_MakeCurrent(this) < 0 ) { | |
682 return(NULL); | |
683 } | |
684 } | |
685 | |
686 /* Set up a fake SDL surface for OpenGL "blitting" */ | |
687 if ( (flags & SDL_OPENGLBLIT) == SDL_OPENGLBLIT ) { | |
688 /* Load GL functions for performing the texture updates */ | |
689 #ifdef HAVE_OPENGL | |
690 #define SDL_PROC(ret,func,params) \ | |
691 do { \ | |
692 video->func = SDL_GL_GetProcAddress(#func); \ | |
693 if ( ! video->func ) { \ | |
694 SDL_SetError("Couldn't load GL function: %s\n", #func); \ | |
695 return(NULL); \ | |
696 } \ | |
697 } while ( 0 ); | |
698 #include "SDL_glfuncs.h" | |
699 #undef SDL_PROC | |
700 | |
701 /* Create a software surface for blitting */ | |
702 #ifdef GL_VERSION_1_2 | |
703 /* If the implementation either supports the packed pixels | |
704 extension, or implements the core OpenGL 1.2 API, it will | |
705 support the GL_UNSIGNED_SHORT_5_6_5 texture format. | |
706 */ | |
707 if ( (bpp == 16) && | |
708 (strstr((const char *)video->glGetString(GL_EXTENSIONS), | |
709 "GL_EXT_packed_pixels") || | |
710 (strncmp((const char *)video->glGetString(GL_VERSION), | |
711 "1.2", 3) == 0)) ) | |
712 { | |
713 video->is_32bit = 0; | |
714 SDL_VideoSurface = SDL_CreateRGBSurface( | |
715 flags, | |
716 width, | |
717 height, | |
718 16, | |
719 31 << 11, | |
720 63 << 5, | |
721 31, | |
722 0 | |
723 ); | |
724 } | |
725 else | |
726 #endif /* OpenGL 1.2 */ | |
727 { | |
728 video->is_32bit = 1; | |
729 SDL_VideoSurface = SDL_CreateRGBSurface( | |
730 flags, | |
731 width, | |
732 height, | |
733 32, | |
734 #if SDL_BYTEORDER == SDL_LIL_ENDIAN | |
735 0x000000FF, | |
736 0x0000FF00, | |
737 0x00FF0000, | |
738 0xFF000000 | |
739 #else | |
740 0xFF000000, | |
741 0x00FF0000, | |
742 0x0000FF00, | |
743 0x000000FF | |
744 #endif | |
745 ); | |
746 } | |
747 if ( ! SDL_VideoSurface ) { | |
748 return(NULL); | |
749 } | |
750 SDL_VideoSurface->flags = mode->flags | SDL_OPENGLBLIT; | |
751 | |
752 /* Free the original video mode surface (is this safe?) */ | |
753 SDL_FreeSurface(mode); | |
754 | |
755 /* Set the surface completely opaque & white by default */ | |
756 memset( SDL_VideoSurface->pixels, 255, SDL_VideoSurface->h * SDL_VideoSurface->pitch ); | |
757 video->glGenTextures( 1, &video->texture ); | |
758 video->glBindTexture( GL_TEXTURE_2D, video->texture ); | |
759 video->glTexImage2D( | |
760 GL_TEXTURE_2D, | |
761 0, | |
762 video->is_32bit ? GL_RGBA : GL_RGB, | |
763 256, | |
764 256, | |
765 0, | |
766 video->is_32bit ? GL_RGBA : GL_RGB, | |
767 #ifdef GL_VERSION_1_2 | |
768 video->is_32bit ? GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT_5_6_5, | |
769 #else | |
770 GL_UNSIGNED_BYTE, | |
771 #endif | |
772 NULL); | |
773 | |
774 video->UpdateRects = SDL_GL_UpdateRectsLock; | |
775 #else | |
776 SDL_SetError("Somebody forgot to #define HAVE_OPENGL"); | |
777 return(NULL); | |
778 #endif | |
779 } | |
780 | |
781 /* Create a shadow surface if necessary */ | |
782 /* There are three conditions under which we create a shadow surface: | |
783 1. We need a particular bits-per-pixel that we didn't get. | |
784 2. We need a hardware palette and didn't get one. | |
785 3. We need a software surface and got a hardware surface. | |
786 */ | |
787 if ( !(SDL_VideoSurface->flags & SDL_OPENGL) && | |
788 ( | |
789 ( !(flags&SDL_ANYFORMAT) && | |
790 (SDL_VideoSurface->format->BitsPerPixel != bpp)) || | |
791 ( (flags&SDL_HWPALETTE) && | |
792 !(SDL_VideoSurface->flags&SDL_HWPALETTE)) || | |
793 /* If the surface is in hardware, video writes are visible | |
794 as soon as they are performed, so we need to buffer them | |
795 */ | |
796 ( ((flags&SDL_HWSURFACE) == SDL_SWSURFACE) && | |
797 (SDL_VideoSurface->flags&SDL_HWSURFACE)) | |
798 ) ) { | |
799 SDL_CreateShadowSurface(bpp); | |
800 if ( SDL_ShadowSurface == NULL ) { | |
801 SDL_SetError("Couldn't create shadow surface"); | |
802 return(NULL); | |
803 } | |
804 SDL_PublicSurface = SDL_ShadowSurface; | |
805 } else { | |
806 SDL_PublicSurface = SDL_VideoSurface; | |
807 } | |
808 video->info.vfmt = SDL_VideoSurface->format; | |
809 | |
810 /* We're done! */ | |
811 return(SDL_PublicSurface); | |
812 } | |
813 | |
814 /* | |
815 * Convert a surface into the video pixel format. | |
816 */ | |
817 SDL_Surface * SDL_DisplayFormat (SDL_Surface *surface) | |
818 { | |
819 Uint32 flags; | |
820 | |
821 if ( ! SDL_PublicSurface ) { | |
822 SDL_SetError("No video mode has been set"); | |
823 return(NULL); | |
824 } | |
825 /* Set the flags appropriate for copying to display surface */ | |
826 flags = (SDL_PublicSurface->flags&SDL_HWSURFACE); | |
827 #ifdef AUTORLE_DISPLAYFORMAT | |
828 flags |= (surface->flags & (SDL_SRCCOLORKEY|SDL_SRCALPHA)); | |
829 flags |= SDL_RLEACCELOK; | |
830 #else | |
831 flags |= surface->flags & (SDL_SRCCOLORKEY|SDL_SRCALPHA|SDL_RLEACCELOK); | |
832 #endif | |
833 return(SDL_ConvertSurface(surface, SDL_PublicSurface->format, flags)); | |
834 } | |
835 | |
836 /* | |
837 * Convert a surface into a format that's suitable for blitting to | |
838 * the screen, but including an alpha channel. | |
839 */ | |
840 SDL_Surface *SDL_DisplayFormatAlpha(SDL_Surface *surface) | |
841 { | |
842 SDL_PixelFormat *vf; | |
843 SDL_PixelFormat *format; | |
844 SDL_Surface *converted; | |
845 Uint32 flags; | |
846 /* default to ARGB8888 */ | |
847 Uint32 amask = 0xff000000; | |
848 Uint32 rmask = 0x00ff0000; | |
849 Uint32 gmask = 0x0000ff00; | |
850 Uint32 bmask = 0x000000ff; | |
851 | |
852 if ( ! SDL_PublicSurface ) { | |
853 SDL_SetError("No video mode has been set"); | |
854 return(NULL); | |
855 } | |
856 vf = SDL_PublicSurface->format; | |
857 | |
858 switch(vf->BytesPerPixel) { | |
859 case 2: | |
860 /* For XGY5[56]5, use, AXGY8888, where {X, Y} = {R, B}. | |
861 For anything else (like ARGB4444) it doesn't matter | |
862 since we have no special code for it anyway */ | |
863 if ( (vf->Rmask == 0x1f) && | |
864 (vf->Bmask == 0xf800 || vf->Bmask == 0x7c00)) { | |
865 rmask = 0xff; | |
866 bmask = 0xff0000; | |
867 } | |
868 break; | |
869 | |
870 case 3: | |
871 case 4: | |
872 /* Keep the video format, as long as the high 8 bits are | |
873 unused or alpha */ | |
874 if ( (vf->Rmask == 0xff) && (vf->Bmask == 0xff0000) ) { | |
875 rmask = 0xff; | |
876 bmask = 0xff0000; | |
877 } | |
878 break; | |
879 | |
880 default: | |
881 /* We have no other optimised formats right now. When/if a new | |
882 optimised alpha format is written, add the converter here */ | |
883 break; | |
884 } | |
885 format = SDL_AllocFormat(32, rmask, gmask, bmask, amask); | |
886 flags = SDL_PublicSurface->flags & SDL_HWSURFACE; | |
887 flags |= surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK); | |
888 converted = SDL_ConvertSurface(surface, format, flags); | |
889 SDL_FreeFormat(format); | |
890 return(converted); | |
891 } | |
892 | |
893 /* | |
894 * Update a specific portion of the physical screen | |
895 */ | |
896 void SDL_UpdateRect(SDL_Surface *screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h) | |
897 { | |
898 if ( screen ) { | |
899 SDL_Rect rect; | |
900 | |
901 /* Perform some checking */ | |
902 if ( w == 0 ) | |
903 w = screen->w; | |
904 if ( h == 0 ) | |
905 h = screen->h; | |
906 if ( (int)(x+w) > screen->w ) | |
907 return; | |
908 if ( (int)(y+h) > screen->h ) | |
909 return; | |
910 | |
911 /* Fill the rectangle */ | |
912 rect.x = x; | |
913 rect.y = y; | |
914 rect.w = w; | |
915 rect.h = h; | |
916 SDL_UpdateRects(screen, 1, &rect); | |
917 } | |
918 } | |
919 void SDL_UpdateRects (SDL_Surface *screen, int numrects, SDL_Rect *rects) | |
920 { | |
921 int i; | |
922 SDL_VideoDevice *video = current_video; | |
923 SDL_VideoDevice *this = current_video; | |
924 | |
925 if ( screen == SDL_ShadowSurface ) { | |
926 /* Blit the shadow surface using saved mapping */ | |
927 SDL_Palette *pal = screen->format->palette; | |
928 SDL_Color *saved_colors = NULL; | |
929 if ( pal && !(SDL_VideoSurface->flags & SDL_HWPALETTE) ) { | |
930 /* simulated 8bpp, use correct physical palette */ | |
931 saved_colors = pal->colors; | |
932 if ( video->gammacols ) { | |
933 /* gamma-corrected palette */ | |
934 pal->colors = video->gammacols; | |
935 } else if ( video->physpal ) { | |
936 /* physical palette different from logical */ | |
937 pal->colors = video->physpal->colors; | |
938 } | |
939 } | |
940 if ( SHOULD_DRAWCURSOR(SDL_cursorstate) ) { | |
941 SDL_LockCursor(); | |
942 SDL_DrawCursor(SDL_ShadowSurface); | |
943 for ( i=0; i<numrects; ++i ) { | |
944 SDL_LowerBlit(SDL_ShadowSurface, &rects[i], | |
945 SDL_VideoSurface, &rects[i]); | |
946 } | |
947 SDL_EraseCursor(SDL_ShadowSurface); | |
948 SDL_UnlockCursor(); | |
949 } else { | |
950 for ( i=0; i<numrects; ++i ) { | |
951 SDL_LowerBlit(SDL_ShadowSurface, &rects[i], | |
952 SDL_VideoSurface, &rects[i]); | |
953 } | |
954 } | |
955 if ( saved_colors ) | |
956 pal->colors = saved_colors; | |
957 | |
958 /* Fall through to video surface update */ | |
959 screen = SDL_VideoSurface; | |
960 } | |
961 if ( screen == SDL_VideoSurface ) { | |
962 /* Update the video surface */ | |
963 if ( screen->offset ) { | |
964 for ( i=0; i<numrects; ++i ) { | |
965 rects[i].x += video->offset_x; | |
966 rects[i].y += video->offset_y; | |
967 } | |
968 video->UpdateRects(this, numrects, rects); | |
969 for ( i=0; i<numrects; ++i ) { | |
970 rects[i].x -= video->offset_x; | |
971 rects[i].y -= video->offset_y; | |
972 } | |
973 } else { | |
974 video->UpdateRects(this, numrects, rects); | |
975 } | |
976 } | |
977 } | |
978 | |
979 /* | |
980 * Performs hardware double buffering, if possible, or a full update if not. | |
981 */ | |
982 int SDL_Flip(SDL_Surface *screen) | |
983 { | |
984 SDL_VideoDevice *video = current_video; | |
985 /* Copy the shadow surface to the video surface */ | |
986 if ( screen == SDL_ShadowSurface ) { | |
987 SDL_Rect rect; | |
988 SDL_Palette *pal = screen->format->palette; | |
989 SDL_Color *saved_colors = NULL; | |
990 if ( pal && !(SDL_VideoSurface->flags & SDL_HWPALETTE) ) { | |
991 /* simulated 8bpp, use correct physical palette */ | |
992 saved_colors = pal->colors; | |
993 if ( video->gammacols ) { | |
994 /* gamma-corrected palette */ | |
995 pal->colors = video->gammacols; | |
996 } else if ( video->physpal ) { | |
997 /* physical palette different from logical */ | |
998 pal->colors = video->physpal->colors; | |
999 } | |
1000 } | |
1001 | |
1002 rect.x = 0; | |
1003 rect.y = 0; | |
1004 rect.w = screen->w; | |
1005 rect.h = screen->h; | |
1006 SDL_LowerBlit(SDL_ShadowSurface,&rect, SDL_VideoSurface,&rect); | |
1007 | |
1008 if ( saved_colors ) | |
1009 pal->colors = saved_colors; | |
1010 screen = SDL_VideoSurface; | |
1011 } | |
1012 if ( (screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) { | |
1013 SDL_VideoDevice *this = current_video; | |
1014 return(video->FlipHWSurface(this, SDL_VideoSurface)); | |
1015 } else { | |
1016 SDL_UpdateRect(screen, 0, 0, 0, 0); | |
1017 } | |
1018 return(0); | |
1019 } | |
1020 | |
1021 static void SetPalette_logical(SDL_Surface *screen, SDL_Color *colors, | |
1022 int firstcolor, int ncolors) | |
1023 { | |
1024 SDL_Palette *pal = screen->format->palette; | |
1025 SDL_Palette *vidpal; | |
1026 | |
1027 if ( colors != (pal->colors + firstcolor) ) { | |
1028 memcpy(pal->colors + firstcolor, colors, | |
1029 ncolors * sizeof(*colors)); | |
1030 } | |
1031 | |
1032 vidpal = SDL_VideoSurface->format->palette; | |
1033 if ( (screen == SDL_ShadowSurface) && vidpal ) { | |
1034 /* | |
1035 * This is a shadow surface, and the physical | |
1036 * framebuffer is also indexed. Propagate the | |
1037 * changes to its logical palette so that | |
1038 * updates are always identity blits | |
1039 */ | |
1040 memcpy(vidpal->colors + firstcolor, colors, | |
1041 ncolors * sizeof(*colors)); | |
1042 } | |
1043 SDL_FormatChanged(screen); | |
1044 } | |
1045 | |
1046 static int SetPalette_physical(SDL_Surface *screen, | |
1047 SDL_Color *colors, int firstcolor, int ncolors) | |
1048 { | |
1049 SDL_VideoDevice *video = current_video; | |
1050 int gotall = 1; | |
1051 | |
1052 if ( video->physpal ) { | |
1053 /* We need to copy the new colors, since we haven't | |
1054 * already done the copy in the logical set above. | |
1055 */ | |
1056 memcpy(video->physpal->colors + firstcolor, | |
1057 colors, ncolors * sizeof(*colors)); | |
1058 } | |
1059 if ( screen == SDL_ShadowSurface ) { | |
1060 if ( SDL_VideoSurface->flags & SDL_HWPALETTE ) { | |
1061 /* | |
1062 * The real screen is also indexed - set its physical | |
1063 * palette. The physical palette does not include the | |
1064 * gamma modification, we apply it directly instead, | |
1065 * but this only happens if we have hardware palette. | |
1066 */ | |
1067 screen = SDL_VideoSurface; | |
1068 } else { | |
1069 /* | |
1070 * The video surface is not indexed - invalidate any | |
1071 * active shadow-to-video blit mappings. | |
1072 */ | |
1073 if ( screen->map->dst == SDL_VideoSurface ) { | |
1074 SDL_InvalidateMap(screen->map); | |
1075 } | |
1076 if ( video->gamma ) { | |
1077 if( ! video->gammacols ) { | |
1078 SDL_Palette *pp = video->physpal; | |
1079 if(!pp) | |
1080 pp = screen->format->palette; | |
1081 video->gammacols = malloc(pp->ncolors | |
1082 * sizeof(SDL_Color)); | |
1083 SDL_ApplyGamma(video->gamma, | |
1084 pp->colors, | |
1085 video->gammacols, | |
1086 pp->ncolors); | |
1087 } else { | |
1088 SDL_ApplyGamma(video->gamma, colors, | |
1089 video->gammacols | |
1090 + firstcolor, | |
1091 ncolors); | |
1092 } | |
1093 } | |
1094 SDL_UpdateRect(screen, 0, 0, 0, 0); | |
1095 } | |
1096 } | |
1097 | |
1098 if ( screen == SDL_VideoSurface ) { | |
1099 SDL_Color gcolors[256]; | |
1100 | |
1101 if ( video->gamma ) { | |
1102 SDL_ApplyGamma(video->gamma, colors, gcolors, ncolors); | |
1103 colors = gcolors; | |
1104 } | |
1105 gotall = video->SetColors(video, firstcolor, ncolors, colors); | |
1106 if ( ! gotall ) { | |
1107 /* The video flags shouldn't have SDL_HWPALETTE, and | |
1108 the video driver is responsible for copying back the | |
1109 correct colors into the video surface palette. | |
1110 */ | |
1111 ; | |
1112 } | |
1113 SDL_CursorPaletteChanged(); | |
1114 } | |
1115 return gotall; | |
1116 } | |
1117 | |
1118 /* | |
1119 * Set the physical and/or logical colormap of a surface: | |
1120 * Only the screen has a physical colormap. It determines what is actually | |
1121 * sent to the display. | |
1122 * The logical colormap is used to map blits to/from the surface. | |
1123 * 'which' is one or both of SDL_LOGPAL, SDL_PHYSPAL | |
1124 * | |
1125 * Return nonzero if all colours were set as requested, or 0 otherwise. | |
1126 */ | |
1127 int SDL_SetPalette(SDL_Surface *screen, int which, | |
1128 SDL_Color *colors, int firstcolor, int ncolors) | |
1129 { | |
1130 SDL_Palette *pal; | |
1131 int gotall; | |
1132 int palsize; | |
1133 | |
1134 if ( screen != SDL_PublicSurface ) { | |
1135 /* only screens have physical palettes */ | |
1136 which &= ~SDL_PHYSPAL; | |
1137 } else if( (screen->flags & SDL_HWPALETTE) != SDL_HWPALETTE ) { | |
1138 /* hardware palettes required for split colormaps */ | |
1139 which |= SDL_PHYSPAL | SDL_LOGPAL; | |
1140 } | |
1141 | |
1142 /* Verify the parameters */ | |
1143 pal = screen->format->palette; | |
1144 if( !pal ) { | |
1145 return 0; /* not a palettized surface */ | |
1146 } | |
1147 gotall = 1; | |
1148 palsize = 1 << screen->format->BitsPerPixel; | |
1149 if ( ncolors > (palsize - firstcolor) ) { | |
1150 ncolors = (palsize - firstcolor); | |
1151 gotall = 0; | |
1152 } | |
1153 | |
1154 if ( which & SDL_LOGPAL ) { | |
1155 /* | |
1156 * Logical palette change: The actual screen isn't affected, | |
1157 * but the internal colormap is altered so that the | |
1158 * interpretation of the pixel values (for blits etc) is | |
1159 * changed. | |
1160 */ | |
1161 SetPalette_logical(screen, colors, firstcolor, ncolors); | |
1162 } | |
1163 if ( which & SDL_PHYSPAL ) { | |
1164 SDL_VideoDevice *video = current_video; | |
1165 /* | |
1166 * Physical palette change: This doesn't affect the | |
1167 * program's idea of what the screen looks like, but changes | |
1168 * its actual appearance. | |
1169 */ | |
1170 if(!video) | |
1171 return gotall; /* video not yet initialized */ | |
1172 if(!video->physpal && !(which & SDL_LOGPAL) ) { | |
1173 /* Lazy physical palette allocation */ | |
1174 int size; | |
1175 SDL_Palette *pp = malloc(sizeof(*pp)); | |
1176 current_video->physpal = pp; | |
1177 pp->ncolors = pal->ncolors; | |
1178 size = pp->ncolors * sizeof(SDL_Color); | |
1179 pp->colors = malloc(size); | |
1180 memcpy(pp->colors, pal->colors, size); | |
1181 } | |
1182 if ( ! SetPalette_physical(screen, | |
1183 colors, firstcolor, ncolors) ) { | |
1184 gotall = 0; | |
1185 } | |
1186 } | |
1187 return gotall; | |
1188 } | |
1189 | |
1190 int SDL_SetColors(SDL_Surface *screen, SDL_Color *colors, int firstcolor, | |
1191 int ncolors) | |
1192 { | |
1193 return SDL_SetPalette(screen, SDL_LOGPAL | SDL_PHYSPAL, | |
1194 colors, firstcolor, ncolors); | |
1195 } | |
1196 | |
1197 /* | |
1198 * Clean up the video subsystem | |
1199 */ | |
1200 void SDL_VideoQuit (void) | |
1201 { | |
1202 SDL_Surface *ready_to_go; | |
1203 | |
1204 if ( current_video ) { | |
1205 SDL_VideoDevice *video = current_video; | |
1206 SDL_VideoDevice *this = current_video; | |
1207 | |
1208 /* Halt event processing before doing anything else */ | |
1209 SDL_StopEventLoop(); | |
1210 | |
1211 /* Clean up allocated window manager items */ | |
1212 if ( SDL_PublicSurface ) { | |
1213 SDL_PublicSurface = NULL; | |
1214 } | |
1215 SDL_CursorQuit(); | |
1216 | |
1217 /* Just in case... */ | |
1218 SDL_WM_GrabInputOff(); | |
1219 | |
1220 /* Clean up the system video */ | |
1221 video->VideoQuit(this); | |
1222 | |
1223 /* Free any lingering surfaces */ | |
1224 ready_to_go = SDL_ShadowSurface; | |
1225 SDL_ShadowSurface = NULL; | |
1226 SDL_FreeSurface(ready_to_go); | |
1227 if ( SDL_VideoSurface != NULL ) { | |
1228 ready_to_go = SDL_VideoSurface; | |
1229 SDL_VideoSurface = NULL; | |
1230 SDL_FreeSurface(ready_to_go); | |
1231 } | |
1232 SDL_PublicSurface = NULL; | |
1233 | |
1234 /* Clean up miscellaneous memory */ | |
1235 if ( video->physpal ) { | |
1236 free(video->physpal->colors); | |
1237 free(video->physpal); | |
1238 video->physpal = NULL; | |
1239 } | |
1240 if ( video->gammacols ) { | |
1241 free(video->gammacols); | |
1242 video->gammacols = NULL; | |
1243 } | |
1244 if ( video->gamma ) { | |
1245 free(video->gamma); | |
1246 video->gamma = NULL; | |
1247 } | |
1248 if ( wm_title != NULL ) { | |
1249 free(wm_title); | |
1250 wm_title = NULL; | |
1251 } | |
1252 if ( wm_icon != NULL ) { | |
1253 free(wm_icon); | |
1254 wm_icon = NULL; | |
1255 } | |
1256 | |
1257 /* Finish cleaning up video subsystem */ | |
1258 video->free(this); | |
1259 current_video = NULL; | |
1260 } | |
1261 return; | |
1262 } | |
1263 | |
1264 /* Load the GL driver library */ | |
1265 int SDL_GL_LoadLibrary(const char *path) | |
1266 { | |
1267 SDL_VideoDevice *video = current_video; | |
1268 SDL_VideoDevice *this = current_video; | |
1269 int retval; | |
1270 | |
1271 retval = -1; | |
7
2c4a3a759c66
*** empty log message ***
Sam Lantinga <slouken@lokigames.com>
parents:
1
diff
changeset
|
1272 if ( video && video->GL_LoadLibrary ) { |
0 | 1273 retval = video->GL_LoadLibrary(this, path); |
1274 } else { | |
1275 SDL_SetError("No dynamic GL support in video driver"); | |
1276 } | |
1277 return(retval); | |
1278 } | |
1279 | |
1280 void *SDL_GL_GetProcAddress(const char* proc) | |
1281 { | |
1282 SDL_VideoDevice *video = current_video; | |
1283 SDL_VideoDevice *this = current_video; | |
1284 void *func; | |
1285 | |
1286 func = NULL; | |
1287 if ( video->GL_GetProcAddress ) { | |
1288 if ( video->gl_config.driver_loaded ) { | |
1289 func = video->GL_GetProcAddress(this, proc); | |
1290 } else { | |
1291 SDL_SetError("No GL driver has been loaded"); | |
1292 } | |
1293 } else { | |
1294 SDL_SetError("No dynamic GL support in video driver"); | |
1295 } | |
1296 return func; | |
1297 } | |
1298 | |
1299 /* Set the specified GL attribute for setting up a GL video mode */ | |
1300 int SDL_GL_SetAttribute( SDL_GLattr attr, int value ) | |
1301 { | |
1302 int retval; | |
1303 SDL_VideoDevice *video = current_video; | |
1304 | |
1305 retval = 0; | |
1306 switch (attr) { | |
1307 case SDL_GL_RED_SIZE: | |
1308 video->gl_config.red_size = value; | |
1309 break; | |
1310 case SDL_GL_GREEN_SIZE: | |
1311 video->gl_config.green_size = value; | |
1312 break; | |
1313 case SDL_GL_BLUE_SIZE: | |
1314 video->gl_config.blue_size = value; | |
1315 break; | |
1316 case SDL_GL_ALPHA_SIZE: | |
1317 video->gl_config.alpha_size = value; | |
1318 break; | |
1319 case SDL_GL_DOUBLEBUFFER: | |
1320 video->gl_config.double_buffer = value; | |
1321 break; | |
1322 case SDL_GL_BUFFER_SIZE: | |
1323 video->gl_config.buffer_size = value; | |
1324 break; | |
1325 case SDL_GL_DEPTH_SIZE: | |
1326 video->gl_config.depth_size = value; | |
1327 break; | |
1328 case SDL_GL_STENCIL_SIZE: | |
1329 video->gl_config.stencil_size = value; | |
1330 break; | |
1331 case SDL_GL_ACCUM_RED_SIZE: | |
1332 video->gl_config.accum_red_size = value; | |
1333 break; | |
1334 case SDL_GL_ACCUM_GREEN_SIZE: | |
1335 video->gl_config.accum_green_size = value; | |
1336 break; | |
1337 case SDL_GL_ACCUM_BLUE_SIZE: | |
1338 video->gl_config.accum_blue_size = value; | |
1339 break; | |
1340 case SDL_GL_ACCUM_ALPHA_SIZE: | |
1341 video->gl_config.accum_alpha_size = value; | |
1342 break; | |
1343 default: | |
1344 SDL_SetError("Unknown OpenGL attribute"); | |
1345 retval = -1; | |
1346 break; | |
1347 } | |
1348 return(retval); | |
1349 } | |
1350 | |
1351 /* Retrieve an attribute value from the windowing system. */ | |
1352 int SDL_GL_GetAttribute(SDL_GLattr attr, int* value) | |
1353 { | |
1354 int retval = -1; | |
1355 SDL_VideoDevice* video = current_video; | |
1356 SDL_VideoDevice* this = current_video; | |
1357 | |
1358 if ( video->GL_GetAttribute ) { | |
1359 retval = this->GL_GetAttribute(this, attr, value); | |
11
7b94b6379341
*** empty log message ***
Sam Lantinga <slouken@lokigames.com>
parents:
7
diff
changeset
|
1360 } else { |
7b94b6379341
*** empty log message ***
Sam Lantinga <slouken@lokigames.com>
parents:
7
diff
changeset
|
1361 *value = 0; |
7b94b6379341
*** empty log message ***
Sam Lantinga <slouken@lokigames.com>
parents:
7
diff
changeset
|
1362 SDL_SetError("GL_GetAttribute not supported"); |
0 | 1363 } |
1364 return retval; | |
1365 } | |
1366 | |
1367 /* Perform a GL buffer swap on the current GL context */ | |
1368 void SDL_GL_SwapBuffers(void) | |
1369 { | |
1370 SDL_VideoDevice *video = current_video; | |
1371 SDL_VideoDevice *this = current_video; | |
1372 | |
1373 if ( video->screen->flags & SDL_OPENGL ) { | |
1374 video->GL_SwapBuffers( this ); | |
1375 } | |
1376 } | |
1377 | |
1378 /* Update rects with locking */ | |
1379 void SDL_GL_UpdateRectsLock(SDL_VideoDevice* this, int numrects, SDL_Rect *rects) | |
1380 { | |
1381 SDL_GL_Lock(); | |
1382 SDL_GL_UpdateRects(numrects, rects); | |
1383 SDL_GL_Unlock(); | |
1384 } | |
1385 | |
1386 /* Update rects without state setting and changing (the caller is responsible for it) */ | |
1387 void SDL_GL_UpdateRects(int numrects, SDL_Rect *rects) | |
1388 { | |
1389 #ifdef HAVE_OPENGL | |
1390 SDL_VideoDevice *this = current_video; | |
1391 SDL_Rect update, tmp; | |
1392 int x, y, i; | |
1393 | |
1394 for ( i = 0; i < numrects; i++ ) | |
1395 { | |
1396 tmp.y = rects[i].y; | |
1397 tmp.h = rects[i].h; | |
1398 for ( y = 0; y <= rects[i].h / 256; y++ ) | |
1399 { | |
1400 tmp.x = rects[i].x; | |
1401 tmp.w = rects[i].w; | |
1402 for ( x = 0; x <= rects[i].w / 256; x++ ) | |
1403 { | |
1404 update.x = tmp.x; | |
1405 update.y = tmp.y; | |
1406 update.w = tmp.w; | |
1407 update.h = tmp.h; | |
1408 | |
1409 if ( update.w > 256 ) | |
1410 update.w = 256; | |
1411 | |
1412 if ( update.h > 256 ) | |
1413 update.h = 256; | |
1414 | |
1415 this->glFlush(); | |
1416 this->glTexSubImage2D( | |
1417 GL_TEXTURE_2D, | |
1418 0, | |
1419 0, | |
1420 0, | |
1421 update.w, | |
1422 update.h, | |
1423 this->is_32bit? GL_RGBA : GL_RGB, | |
1424 #ifdef GL_VERSION_1_2 | |
1425 this->is_32bit ? GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT_5_6_5, | |
1426 #else | |
1427 GL_UNSIGNED_BYTE, | |
1428 #endif | |
1429 (Uint8 *)this->screen->pixels + | |
1430 this->screen->format->BytesPerPixel * update.x + | |
1431 update.y * this->screen->pitch ); | |
1432 | |
1433 this->glFlush(); | |
1434 /* | |
1435 * Note the parens around the function name: | |
1436 * This is because some OpenGL implementations define glTexCoord etc | |
1437 * as macros, and we don't want them expanded here. | |
1438 */ | |
1439 this->glBegin(GL_TRIANGLE_STRIP); | |
1440 (this->glTexCoord2f)( 0.0, 0.0 ); | |
1441 (this->glVertex2i)( update.x, update.y ); | |
1442 (this->glTexCoord2f)( (float)(update.w / 256.0), 0.0 ); | |
1443 (this->glVertex2i)( update.x + update.w, update.y ); | |
1444 (this->glTexCoord2f)( 0.0, (float)(update.h / 256.0) ); | |
1445 (this->glVertex2i)( update.x, update.y + update.h ); | |
1446 (this->glTexCoord2f)( (float)(update.w / 256.0), (float)(update.h / 256.0) ); | |
1447 (this->glVertex2i)( update.x + update.w , update.y + update.h ); | |
1448 this->glEnd(); | |
1449 | |
1450 tmp.x += 256; | |
1451 tmp.w -= 256; | |
1452 } | |
1453 tmp.y += 256; | |
1454 tmp.h -= 256; | |
1455 } | |
1456 } | |
1457 #endif | |
1458 } | |
1459 | |
1460 /* Lock == save current state */ | |
1461 void SDL_GL_Lock() | |
1462 { | |
1463 #ifdef HAVE_OPENGL | |
1464 lock_count--; | |
1465 if (lock_count==-1) | |
1466 { | |
1467 SDL_VideoDevice *this = current_video; | |
1468 | |
1469 this->glPushAttrib( GL_ALL_ATTRIB_BITS ); /* TODO: narrow range of what is saved */ | |
1470 this->glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT ); | |
1471 | |
1472 this->glEnable(GL_TEXTURE_2D); | |
1473 this->glEnable(GL_BLEND); | |
1474 this->glDisable(GL_FOG); | |
1475 this->glDisable(GL_ALPHA_TEST); | |
1476 this->glDisable(GL_DEPTH_TEST); | |
1477 this->glDisable(GL_SCISSOR_TEST); | |
1478 this->glDisable(GL_STENCIL_TEST); | |
1479 this->glDisable(GL_CULL_FACE); | |
1480 | |
1481 this->glBindTexture( GL_TEXTURE_2D, this->texture ); | |
1482 this->glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); | |
1483 this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); | |
1484 this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); | |
1485 this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); | |
1486 this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); | |
1487 | |
1488 this->glPixelStorei( GL_UNPACK_ROW_LENGTH, this->screen->pitch / this->screen->format->BytesPerPixel ); | |
1489 this->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |
1490 (this->glColor4f)(1.0, 1.0, 1.0, 1.0); /* Solaris workaround */ | |
1491 | |
1492 this->glViewport(0, 0, this->screen->w, this->screen->h); | |
1493 this->glMatrixMode(GL_PROJECTION); | |
1494 this->glPushMatrix(); | |
1495 this->glLoadIdentity(); | |
1496 | |
1497 this->glOrtho(0.0, (GLdouble) this->screen->w, (GLdouble) this->screen->h, 0.0, 0.0, 1.0); | |
1498 | |
1499 this->glMatrixMode(GL_MODELVIEW); | |
1500 this->glPushMatrix(); | |
1501 this->glLoadIdentity(); | |
1502 } | |
1503 #endif | |
1504 } | |
1505 | |
1506 /* Unlock == restore saved state */ | |
1507 void SDL_GL_Unlock() | |
1508 { | |
1509 #ifdef HAVE_OPENGL | |
1510 lock_count++; | |
1511 if (lock_count==0) | |
1512 { | |
1513 SDL_VideoDevice *this = current_video; | |
1514 | |
1515 this->glPopMatrix(); | |
1516 this->glMatrixMode(GL_PROJECTION); | |
1517 this->glPopMatrix(); | |
1518 | |
1519 this->glPopClientAttrib(); | |
1520 this->glPopAttrib(); | |
1521 } | |
1522 #endif | |
1523 } | |
1524 | |
1525 /* | |
1526 * Sets/Gets the title and icon text of the display window, if any. | |
1527 */ | |
1528 void SDL_WM_SetCaption (const char *title, const char *icon) | |
1529 { | |
1530 SDL_VideoDevice *video = current_video; | |
1531 SDL_VideoDevice *this = current_video; | |
1532 | |
1533 if ( title ) { | |
1534 if ( wm_title ) { | |
1535 free(wm_title); | |
1536 } | |
1537 wm_title = (char *)malloc(strlen(title)+1); | |
1538 if ( wm_title != NULL ) { | |
1539 strcpy(wm_title, title); | |
1540 } | |
1541 } | |
1542 if ( icon ) { | |
1543 if ( wm_icon ) { | |
1544 free(wm_icon); | |
1545 } | |
1546 wm_icon = (char *)malloc(strlen(icon)+1); | |
1547 if ( wm_icon != NULL ) { | |
1548 strcpy(wm_icon, icon); | |
1549 } | |
1550 } | |
1551 if ( (title || icon) && video && (video->SetCaption != NULL) ) { | |
1552 video->SetCaption(this, wm_title, wm_icon); | |
1553 } | |
1554 } | |
1555 void SDL_WM_GetCaption (char **title, char **icon) | |
1556 { | |
1557 if ( title ) { | |
1558 *title = wm_title; | |
1559 } | |
1560 if ( icon ) { | |
1561 *icon = wm_icon; | |
1562 } | |
1563 } | |
1564 | |
1565 /* Utility function used by SDL_WM_SetIcon() */ | |
1566 static void CreateMaskFromColorKey(SDL_Surface *icon, Uint8 *mask) | |
1567 { | |
1568 int x, y; | |
1569 Uint32 colorkey; | |
1570 #define SET_MASKBIT(icon, x, y, mask) \ | |
1571 mask[(y*((icon->w+7)/8))+(x/8)] &= ~(0x01<<(7-(x%8))) | |
1572 | |
1573 colorkey = icon->format->colorkey; | |
1574 switch (icon->format->BytesPerPixel) { | |
1575 case 1: { Uint8 *pixels; | |
1576 for ( y=0; y<icon->h; ++y ) { | |
1577 pixels = (Uint8 *)icon->pixels + y*icon->pitch; | |
1578 for ( x=0; x<icon->w; ++x ) { | |
1579 if ( *pixels++ == colorkey ) { | |
1580 SET_MASKBIT(icon, x, y, mask); | |
1581 } | |
1582 } | |
1583 } | |
1584 } | |
1585 break; | |
1586 | |
1587 case 2: { Uint16 *pixels; | |
1588 for ( y=0; y<icon->h; ++y ) { | |
1589 pixels = (Uint16 *)icon->pixels + | |
1590 y*icon->pitch/2; | |
1591 for ( x=0; x<icon->w; ++x ) { | |
1592 if ( *pixels++ == colorkey ) { | |
1593 SET_MASKBIT(icon, x, y, mask); | |
1594 } | |
1595 } | |
1596 } | |
1597 } | |
1598 break; | |
1599 | |
1600 case 4: { Uint32 *pixels; | |
1601 for ( y=0; y<icon->h; ++y ) { | |
1602 pixels = (Uint32 *)icon->pixels + | |
1603 y*icon->pitch/4; | |
1604 for ( x=0; x<icon->w; ++x ) { | |
1605 if ( *pixels++ == colorkey ) { | |
1606 SET_MASKBIT(icon, x, y, mask); | |
1607 } | |
1608 } | |
1609 } | |
1610 } | |
1611 break; | |
1612 } | |
1613 } | |
1614 | |
1615 /* | |
1616 * Sets the window manager icon for the display window. | |
1617 */ | |
1618 void SDL_WM_SetIcon (SDL_Surface *icon, Uint8 *mask) | |
1619 { | |
1620 SDL_VideoDevice *video = current_video; | |
1621 SDL_VideoDevice *this = current_video; | |
1622 | |
1623 if ( icon && video->SetIcon ) { | |
1624 /* Generate a mask if necessary, and create the icon! */ | |
1625 if ( mask == NULL ) { | |
1626 int mask_len = icon->h*(icon->w+7)/8; | |
1627 mask = (Uint8 *)malloc(mask_len); | |
1628 if ( mask == NULL ) { | |
1629 return; | |
1630 } | |
1631 memset(mask, ~0, mask_len); | |
1632 if ( icon->flags & SDL_SRCCOLORKEY ) { | |
1633 CreateMaskFromColorKey(icon, mask); | |
1634 } | |
1635 video->SetIcon(video, icon, mask); | |
1636 free(mask); | |
1637 } else { | |
1638 video->SetIcon(this, icon, mask); | |
1639 } | |
1640 } | |
1641 } | |
1642 | |
1643 /* | |
1644 * Grab or ungrab the keyboard and mouse input. | |
1645 * This function returns the final grab mode after calling the | |
1646 * driver dependent function. | |
1647 */ | |
1648 static SDL_GrabMode SDL_WM_GrabInputRaw(SDL_GrabMode mode) | |
1649 { | |
1650 SDL_VideoDevice *video = current_video; | |
1651 SDL_VideoDevice *this = current_video; | |
1652 | |
1653 /* Only do something if we have support for grabs */ | |
1654 if ( video->GrabInput == NULL ) { | |
1655 return(video->input_grab); | |
1656 } | |
1657 | |
1658 /* If the final grab mode if off, only then do we actually grab */ | |
1659 #ifdef DEBUG_GRAB | |
1660 printf("SDL_WM_GrabInputRaw(%d) ... ", mode); | |
1661 #endif | |
1662 if ( mode == SDL_GRAB_OFF ) { | |
1663 if ( video->input_grab != SDL_GRAB_OFF ) { | |
1664 mode = video->GrabInput(this, mode); | |
1665 } | |
1666 } else { | |
1667 if ( video->input_grab == SDL_GRAB_OFF ) { | |
1668 mode = video->GrabInput(this, mode); | |
1669 } | |
1670 } | |
1671 if ( mode != video->input_grab ) { | |
1672 video->input_grab = mode; | |
1673 if ( video->CheckMouseMode ) { | |
1674 video->CheckMouseMode(this); | |
1675 } | |
1676 } | |
1677 #ifdef DEBUG_GRAB | |
1678 printf("Final mode %d\n", video->input_grab); | |
1679 #endif | |
1680 | |
1681 /* Return the final grab state */ | |
1682 if ( mode >= SDL_GRAB_FULLSCREEN ) { | |
1683 mode -= SDL_GRAB_FULLSCREEN; | |
1684 } | |
1685 return(mode); | |
1686 } | |
1687 SDL_GrabMode SDL_WM_GrabInput(SDL_GrabMode mode) | |
1688 { | |
1689 SDL_VideoDevice *video = current_video; | |
1690 | |
11
7b94b6379341
*** empty log message ***
Sam Lantinga <slouken@lokigames.com>
parents:
7
diff
changeset
|
1691 /* If the video isn't initialized yet, we can't do anything */ |
7b94b6379341
*** empty log message ***
Sam Lantinga <slouken@lokigames.com>
parents:
7
diff
changeset
|
1692 if ( ! video ) { |
7b94b6379341
*** empty log message ***
Sam Lantinga <slouken@lokigames.com>
parents:
7
diff
changeset
|
1693 return SDL_GRAB_OFF; |
7b94b6379341
*** empty log message ***
Sam Lantinga <slouken@lokigames.com>
parents:
7
diff
changeset
|
1694 } |
0 | 1695 |
1696 /* Return the current mode on query */ | |
1697 if ( mode == SDL_GRAB_QUERY ) { | |
1698 mode = video->input_grab; | |
1699 if ( mode >= SDL_GRAB_FULLSCREEN ) { | |
1700 mode -= SDL_GRAB_FULLSCREEN; | |
1701 } | |
1702 return(mode); | |
1703 } | |
1704 | |
1705 #ifdef DEBUG_GRAB | |
1706 printf("SDL_WM_GrabInput(%d) ... ", mode); | |
1707 #endif | |
1708 /* If the video surface is fullscreen, we always grab */ | |
1709 if ( mode >= SDL_GRAB_FULLSCREEN ) { | |
1710 mode -= SDL_GRAB_FULLSCREEN; | |
1711 } | |
1712 if ( SDL_VideoSurface && (SDL_VideoSurface->flags & SDL_FULLSCREEN) ) { | |
1713 mode += SDL_GRAB_FULLSCREEN; | |
1714 } | |
1715 return(SDL_WM_GrabInputRaw(mode)); | |
1716 } | |
1717 static SDL_GrabMode SDL_WM_GrabInputOff(void) | |
1718 { | |
1719 SDL_GrabMode mode; | |
1720 | |
1721 /* First query the current grab state */ | |
1722 mode = SDL_WM_GrabInput(SDL_GRAB_QUERY); | |
1723 | |
1724 /* Now explicitly turn off input grab */ | |
1725 SDL_WM_GrabInputRaw(SDL_GRAB_OFF); | |
1726 | |
1727 /* Return the old state */ | |
1728 return(mode); | |
1729 } | |
1730 | |
1731 /* | |
1732 * Iconify the window in window managed environments. | |
1733 * A successful iconification will result in an SDL_APPACTIVE loss event. | |
1734 */ | |
1735 int SDL_WM_IconifyWindow(void) | |
1736 { | |
1737 SDL_VideoDevice *video = current_video; | |
1738 SDL_VideoDevice *this = current_video; | |
1739 int retval; | |
1740 | |
1741 retval = 0; | |
1742 if ( video->IconifyWindow ) { | |
1743 retval = video->IconifyWindow(this); | |
1744 } | |
1745 return(retval); | |
1746 } | |
1747 | |
1748 /* | |
1749 * Toggle fullscreen mode | |
1750 */ | |
1751 int SDL_WM_ToggleFullScreen(SDL_Surface *surface) | |
1752 { | |
1753 SDL_VideoDevice *video = current_video; | |
1754 SDL_VideoDevice *this = current_video; | |
1755 int toggled; | |
1756 | |
1757 toggled = 0; | |
1758 if ( SDL_PublicSurface && (surface == SDL_PublicSurface) && | |
1759 video->ToggleFullScreen ) { | |
1760 if ( surface->flags & SDL_FULLSCREEN ) { | |
1761 toggled = video->ToggleFullScreen(this, 0); | |
1762 if ( toggled ) { | |
1763 SDL_VideoSurface->flags &= ~SDL_FULLSCREEN; | |
1764 SDL_PublicSurface->flags &= ~SDL_FULLSCREEN; | |
1765 } | |
1766 } else { | |
1767 toggled = video->ToggleFullScreen(this, 1); | |
1768 if ( toggled ) { | |
1769 SDL_VideoSurface->flags |= SDL_FULLSCREEN; | |
1770 SDL_PublicSurface->flags |= SDL_FULLSCREEN; | |
1771 } | |
1772 } | |
1773 /* Double-check the grab state inside SDL_WM_GrabInput() */ | |
1774 if ( toggled ) { | |
1775 SDL_WM_GrabInput(video->input_grab); | |
1776 } | |
1777 } | |
1778 return(toggled); | |
1779 } | |
1780 | |
1781 /* | |
1782 * Get some platform dependent window manager information | |
1783 */ | |
1784 int SDL_GetWMInfo (SDL_SysWMinfo *info) | |
1785 { | |
1786 SDL_VideoDevice *video = current_video; | |
1787 SDL_VideoDevice *this = current_video; | |
1788 | |
1789 if ( video && video->GetWMInfo ) { | |
1790 return(video->GetWMInfo(this, info)); | |
1791 } else { | |
1792 return(0); | |
1793 } | |
1794 } |