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