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