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