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