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