Mercurial > sdl-ios-xcode
annotate src/video/SDL_video.c @ 232:678e3ed01019
Don't generate a spurious error on SDL_InitVideo()
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 06 Nov 2001 00:15:04 +0000 |
parents | 4d24d5a660a8 |
children | e8157fcb3114 |
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 | |
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 ) { | |
1394 video->GL_SwapBuffers( this ); | |
1395 } | |
1396 } | |
1397 | |
1398 /* Update rects with locking */ | |
1399 void SDL_GL_UpdateRectsLock(SDL_VideoDevice* this, int numrects, SDL_Rect *rects) | |
1400 { | |
1401 SDL_GL_Lock(); | |
1402 SDL_GL_UpdateRects(numrects, rects); | |
1403 SDL_GL_Unlock(); | |
1404 } | |
1405 | |
1406 /* Update rects without state setting and changing (the caller is responsible for it) */ | |
1407 void SDL_GL_UpdateRects(int numrects, SDL_Rect *rects) | |
1408 { | |
1409 #ifdef HAVE_OPENGL | |
1410 SDL_VideoDevice *this = current_video; | |
1411 SDL_Rect update, tmp; | |
1412 int x, y, i; | |
1413 | |
1414 for ( i = 0; i < numrects; i++ ) | |
1415 { | |
1416 tmp.y = rects[i].y; | |
1417 tmp.h = rects[i].h; | |
1418 for ( y = 0; y <= rects[i].h / 256; y++ ) | |
1419 { | |
1420 tmp.x = rects[i].x; | |
1421 tmp.w = rects[i].w; | |
1422 for ( x = 0; x <= rects[i].w / 256; x++ ) | |
1423 { | |
1424 update.x = tmp.x; | |
1425 update.y = tmp.y; | |
1426 update.w = tmp.w; | |
1427 update.h = tmp.h; | |
1428 | |
1429 if ( update.w > 256 ) | |
1430 update.w = 256; | |
1431 | |
1432 if ( update.h > 256 ) | |
1433 update.h = 256; | |
1434 | |
1435 this->glFlush(); | |
1436 this->glTexSubImage2D( | |
1437 GL_TEXTURE_2D, | |
1438 0, | |
1439 0, | |
1440 0, | |
1441 update.w, | |
1442 update.h, | |
1443 this->is_32bit? GL_RGBA : GL_RGB, | |
1444 #ifdef GL_VERSION_1_2 | |
1445 this->is_32bit ? GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT_5_6_5, | |
1446 #else | |
1447 GL_UNSIGNED_BYTE, | |
1448 #endif | |
1449 (Uint8 *)this->screen->pixels + | |
1450 this->screen->format->BytesPerPixel * update.x + | |
1451 update.y * this->screen->pitch ); | |
1452 | |
1453 this->glFlush(); | |
1454 /* | |
1455 * Note the parens around the function name: | |
1456 * This is because some OpenGL implementations define glTexCoord etc | |
1457 * as macros, and we don't want them expanded here. | |
1458 */ | |
1459 this->glBegin(GL_TRIANGLE_STRIP); | |
1460 (this->glTexCoord2f)( 0.0, 0.0 ); | |
1461 (this->glVertex2i)( update.x, update.y ); | |
1462 (this->glTexCoord2f)( (float)(update.w / 256.0), 0.0 ); | |
1463 (this->glVertex2i)( update.x + update.w, update.y ); | |
1464 (this->glTexCoord2f)( 0.0, (float)(update.h / 256.0) ); | |
1465 (this->glVertex2i)( update.x, update.y + update.h ); | |
1466 (this->glTexCoord2f)( (float)(update.w / 256.0), (float)(update.h / 256.0) ); | |
1467 (this->glVertex2i)( update.x + update.w , update.y + update.h ); | |
1468 this->glEnd(); | |
1469 | |
1470 tmp.x += 256; | |
1471 tmp.w -= 256; | |
1472 } | |
1473 tmp.y += 256; | |
1474 tmp.h -= 256; | |
1475 } | |
1476 } | |
1477 #endif | |
1478 } | |
1479 | |
1480 /* Lock == save current state */ | |
1481 void SDL_GL_Lock() | |
1482 { | |
1483 #ifdef HAVE_OPENGL | |
1484 lock_count--; | |
1485 if (lock_count==-1) | |
1486 { | |
1487 SDL_VideoDevice *this = current_video; | |
1488 | |
1489 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
|
1490 #ifdef GL_CLIENT_PIXEL_STORE_BIT |
0 | 1491 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
|
1492 #endif |
0 | 1493 |
1494 this->glEnable(GL_TEXTURE_2D); | |
1495 this->glEnable(GL_BLEND); | |
1496 this->glDisable(GL_FOG); | |
1497 this->glDisable(GL_ALPHA_TEST); | |
1498 this->glDisable(GL_DEPTH_TEST); | |
1499 this->glDisable(GL_SCISSOR_TEST); | |
1500 this->glDisable(GL_STENCIL_TEST); | |
1501 this->glDisable(GL_CULL_FACE); | |
1502 | |
1503 this->glBindTexture( GL_TEXTURE_2D, this->texture ); | |
1504 this->glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); | |
1505 this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); | |
1506 this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); | |
1507 this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); | |
1508 this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); | |
1509 | |
1510 this->glPixelStorei( GL_UNPACK_ROW_LENGTH, this->screen->pitch / this->screen->format->BytesPerPixel ); | |
1511 this->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |
1512 (this->glColor4f)(1.0, 1.0, 1.0, 1.0); /* Solaris workaround */ | |
1513 | |
1514 this->glViewport(0, 0, this->screen->w, this->screen->h); | |
1515 this->glMatrixMode(GL_PROJECTION); | |
1516 this->glPushMatrix(); | |
1517 this->glLoadIdentity(); | |
1518 | |
1519 this->glOrtho(0.0, (GLdouble) this->screen->w, (GLdouble) this->screen->h, 0.0, 0.0, 1.0); | |
1520 | |
1521 this->glMatrixMode(GL_MODELVIEW); | |
1522 this->glPushMatrix(); | |
1523 this->glLoadIdentity(); | |
1524 } | |
1525 #endif | |
1526 } | |
1527 | |
1528 /* Unlock == restore saved state */ | |
1529 void SDL_GL_Unlock() | |
1530 { | |
1531 #ifdef HAVE_OPENGL | |
1532 lock_count++; | |
1533 if (lock_count==0) | |
1534 { | |
1535 SDL_VideoDevice *this = current_video; | |
1536 | |
1537 this->glPopMatrix(); | |
1538 this->glMatrixMode(GL_PROJECTION); | |
1539 this->glPopMatrix(); | |
1540 | |
1541 this->glPopClientAttrib(); | |
1542 this->glPopAttrib(); | |
1543 } | |
1544 #endif | |
1545 } | |
1546 | |
1547 /* | |
1548 * Sets/Gets the title and icon text of the display window, if any. | |
1549 */ | |
1550 void SDL_WM_SetCaption (const char *title, const char *icon) | |
1551 { | |
1552 SDL_VideoDevice *video = current_video; | |
1553 SDL_VideoDevice *this = current_video; | |
1554 | |
58
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1555 if ( video ) { |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1556 if ( title ) { |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1557 if ( video->wm_title ) { |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1558 free(video->wm_title); |
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_title = (char *)malloc(strlen(title)+1); |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1561 if ( video->wm_title != NULL ) { |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1562 strcpy(video->wm_title, title); |
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 ( icon ) { |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1566 if ( video->wm_icon ) { |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1567 free(video->wm_icon); |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1568 } |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1569 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
|
1570 if ( video->wm_icon != NULL ) { |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1571 strcpy(video->wm_icon, icon); |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1572 } |
0 | 1573 } |
58
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1574 if ( (title || icon) && (video->SetCaption != NULL) ) { |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1575 video->SetCaption(this, video->wm_title,video->wm_icon); |
0 | 1576 } |
1577 } | |
1578 } | |
1579 void SDL_WM_GetCaption (char **title, char **icon) | |
1580 { | |
58
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1581 SDL_VideoDevice *video = current_video; |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1582 |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1583 if ( video ) { |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1584 if ( title ) { |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1585 *title = video->wm_title; |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1586 } |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1587 if ( icon ) { |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1588 *icon = video->wm_icon; |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1589 } |
0 | 1590 } |
1591 } | |
1592 | |
1593 /* Utility function used by SDL_WM_SetIcon() */ | |
1594 static void CreateMaskFromColorKey(SDL_Surface *icon, Uint8 *mask) | |
1595 { | |
1596 int x, y; | |
1597 Uint32 colorkey; | |
1598 #define SET_MASKBIT(icon, x, y, mask) \ | |
1599 mask[(y*((icon->w+7)/8))+(x/8)] &= ~(0x01<<(7-(x%8))) | |
1600 | |
1601 colorkey = icon->format->colorkey; | |
1602 switch (icon->format->BytesPerPixel) { | |
1603 case 1: { Uint8 *pixels; | |
1604 for ( y=0; y<icon->h; ++y ) { | |
1605 pixels = (Uint8 *)icon->pixels + y*icon->pitch; | |
1606 for ( x=0; x<icon->w; ++x ) { | |
1607 if ( *pixels++ == colorkey ) { | |
1608 SET_MASKBIT(icon, x, y, mask); | |
1609 } | |
1610 } | |
1611 } | |
1612 } | |
1613 break; | |
1614 | |
1615 case 2: { Uint16 *pixels; | |
1616 for ( y=0; y<icon->h; ++y ) { | |
1617 pixels = (Uint16 *)icon->pixels + | |
1618 y*icon->pitch/2; | |
1619 for ( x=0; x<icon->w; ++x ) { | |
1620 if ( *pixels++ == colorkey ) { | |
1621 SET_MASKBIT(icon, x, y, mask); | |
1622 } | |
1623 } | |
1624 } | |
1625 } | |
1626 break; | |
1627 | |
1628 case 4: { Uint32 *pixels; | |
1629 for ( y=0; y<icon->h; ++y ) { | |
1630 pixels = (Uint32 *)icon->pixels + | |
1631 y*icon->pitch/4; | |
1632 for ( x=0; x<icon->w; ++x ) { | |
1633 if ( *pixels++ == colorkey ) { | |
1634 SET_MASKBIT(icon, x, y, mask); | |
1635 } | |
1636 } | |
1637 } | |
1638 } | |
1639 break; | |
1640 } | |
1641 } | |
1642 | |
1643 /* | |
1644 * Sets the window manager icon for the display window. | |
1645 */ | |
1646 void SDL_WM_SetIcon (SDL_Surface *icon, Uint8 *mask) | |
1647 { | |
1648 SDL_VideoDevice *video = current_video; | |
1649 SDL_VideoDevice *this = current_video; | |
1650 | |
1651 if ( icon && video->SetIcon ) { | |
1652 /* Generate a mask if necessary, and create the icon! */ | |
1653 if ( mask == NULL ) { | |
1654 int mask_len = icon->h*(icon->w+7)/8; | |
1655 mask = (Uint8 *)malloc(mask_len); | |
1656 if ( mask == NULL ) { | |
1657 return; | |
1658 } | |
1659 memset(mask, ~0, mask_len); | |
1660 if ( icon->flags & SDL_SRCCOLORKEY ) { | |
1661 CreateMaskFromColorKey(icon, mask); | |
1662 } | |
1663 video->SetIcon(video, icon, mask); | |
1664 free(mask); | |
1665 } else { | |
1666 video->SetIcon(this, icon, mask); | |
1667 } | |
1668 } | |
1669 } | |
1670 | |
1671 /* | |
1672 * Grab or ungrab the keyboard and mouse input. | |
1673 * This function returns the final grab mode after calling the | |
1674 * driver dependent function. | |
1675 */ | |
1676 static SDL_GrabMode SDL_WM_GrabInputRaw(SDL_GrabMode mode) | |
1677 { | |
1678 SDL_VideoDevice *video = current_video; | |
1679 SDL_VideoDevice *this = current_video; | |
1680 | |
1681 /* Only do something if we have support for grabs */ | |
1682 if ( video->GrabInput == NULL ) { | |
1683 return(video->input_grab); | |
1684 } | |
1685 | |
1686 /* If the final grab mode if off, only then do we actually grab */ | |
1687 #ifdef DEBUG_GRAB | |
1688 printf("SDL_WM_GrabInputRaw(%d) ... ", mode); | |
1689 #endif | |
1690 if ( mode == SDL_GRAB_OFF ) { | |
1691 if ( video->input_grab != SDL_GRAB_OFF ) { | |
1692 mode = video->GrabInput(this, mode); | |
1693 } | |
1694 } else { | |
1695 if ( video->input_grab == SDL_GRAB_OFF ) { | |
1696 mode = video->GrabInput(this, mode); | |
1697 } | |
1698 } | |
1699 if ( mode != video->input_grab ) { | |
1700 video->input_grab = mode; | |
1701 if ( video->CheckMouseMode ) { | |
1702 video->CheckMouseMode(this); | |
1703 } | |
1704 } | |
1705 #ifdef DEBUG_GRAB | |
1706 printf("Final mode %d\n", video->input_grab); | |
1707 #endif | |
1708 | |
1709 /* Return the final grab state */ | |
1710 if ( mode >= SDL_GRAB_FULLSCREEN ) { | |
1711 mode -= SDL_GRAB_FULLSCREEN; | |
1712 } | |
1713 return(mode); | |
1714 } | |
1715 SDL_GrabMode SDL_WM_GrabInput(SDL_GrabMode mode) | |
1716 { | |
1717 SDL_VideoDevice *video = current_video; | |
1718 | |
11
7b94b6379341
*** empty log message ***
Sam Lantinga <slouken@lokigames.com>
parents:
7
diff
changeset
|
1719 /* 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
|
1720 if ( ! video ) { |
7b94b6379341
*** empty log message ***
Sam Lantinga <slouken@lokigames.com>
parents:
7
diff
changeset
|
1721 return SDL_GRAB_OFF; |
7b94b6379341
*** empty log message ***
Sam Lantinga <slouken@lokigames.com>
parents:
7
diff
changeset
|
1722 } |
0 | 1723 |
1724 /* Return the current mode on query */ | |
1725 if ( mode == SDL_GRAB_QUERY ) { | |
1726 mode = video->input_grab; | |
1727 if ( mode >= SDL_GRAB_FULLSCREEN ) { | |
1728 mode -= SDL_GRAB_FULLSCREEN; | |
1729 } | |
1730 return(mode); | |
1731 } | |
1732 | |
1733 #ifdef DEBUG_GRAB | |
1734 printf("SDL_WM_GrabInput(%d) ... ", mode); | |
1735 #endif | |
1736 /* If the video surface is fullscreen, we always grab */ | |
1737 if ( mode >= SDL_GRAB_FULLSCREEN ) { | |
1738 mode -= SDL_GRAB_FULLSCREEN; | |
1739 } | |
1740 if ( SDL_VideoSurface && (SDL_VideoSurface->flags & SDL_FULLSCREEN) ) { | |
1741 mode += SDL_GRAB_FULLSCREEN; | |
1742 } | |
1743 return(SDL_WM_GrabInputRaw(mode)); | |
1744 } | |
1745 static SDL_GrabMode SDL_WM_GrabInputOff(void) | |
1746 { | |
1747 SDL_GrabMode mode; | |
1748 | |
1749 /* First query the current grab state */ | |
1750 mode = SDL_WM_GrabInput(SDL_GRAB_QUERY); | |
1751 | |
1752 /* Now explicitly turn off input grab */ | |
1753 SDL_WM_GrabInputRaw(SDL_GRAB_OFF); | |
1754 | |
1755 /* Return the old state */ | |
1756 return(mode); | |
1757 } | |
1758 | |
1759 /* | |
1760 * Iconify the window in window managed environments. | |
1761 * A successful iconification will result in an SDL_APPACTIVE loss event. | |
1762 */ | |
1763 int SDL_WM_IconifyWindow(void) | |
1764 { | |
1765 SDL_VideoDevice *video = current_video; | |
1766 SDL_VideoDevice *this = current_video; | |
1767 int retval; | |
1768 | |
1769 retval = 0; | |
1770 if ( video->IconifyWindow ) { | |
1771 retval = video->IconifyWindow(this); | |
1772 } | |
1773 return(retval); | |
1774 } | |
1775 | |
1776 /* | |
1777 * Toggle fullscreen mode | |
1778 */ | |
1779 int SDL_WM_ToggleFullScreen(SDL_Surface *surface) | |
1780 { | |
1781 SDL_VideoDevice *video = current_video; | |
1782 SDL_VideoDevice *this = current_video; | |
1783 int toggled; | |
1784 | |
1785 toggled = 0; | |
1786 if ( SDL_PublicSurface && (surface == SDL_PublicSurface) && | |
1787 video->ToggleFullScreen ) { | |
1788 if ( surface->flags & SDL_FULLSCREEN ) { | |
1789 toggled = video->ToggleFullScreen(this, 0); | |
1790 if ( toggled ) { | |
1791 SDL_VideoSurface->flags &= ~SDL_FULLSCREEN; | |
1792 SDL_PublicSurface->flags &= ~SDL_FULLSCREEN; | |
1793 } | |
1794 } else { | |
1795 toggled = video->ToggleFullScreen(this, 1); | |
1796 if ( toggled ) { | |
1797 SDL_VideoSurface->flags |= SDL_FULLSCREEN; | |
1798 SDL_PublicSurface->flags |= SDL_FULLSCREEN; | |
1799 } | |
1800 } | |
1801 /* Double-check the grab state inside SDL_WM_GrabInput() */ | |
1802 if ( toggled ) { | |
1803 SDL_WM_GrabInput(video->input_grab); | |
1804 } | |
1805 } | |
1806 return(toggled); | |
1807 } | |
1808 | |
1809 /* | |
1810 * Get some platform dependent window manager information | |
1811 */ | |
1812 int SDL_GetWMInfo (SDL_SysWMinfo *info) | |
1813 { | |
1814 SDL_VideoDevice *video = current_video; | |
1815 SDL_VideoDevice *this = current_video; | |
1816 | |
1817 if ( video && video->GetWMInfo ) { | |
1818 return(video->GetWMInfo(this, info)); | |
1819 } else { | |
1820 return(0); | |
1821 } | |
1822 } |