Mercurial > sdl-ios-xcode
annotate src/video/SDL_video.c @ 350:6dd188952b9e
Bump the version, so that it isn't forotten later. :)
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 14 Apr 2002 21:51:25 +0000 |
parents | 67ad846ed21c |
children | db0cc6034336 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
297
f6ffac90895c
Updated copyright information for 2002
Sam Lantinga <slouken@libsdl.org>
parents:
282
diff
changeset
|
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga |
0 | 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 */ | |
313
67ad846ed21c
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
306
diff
changeset
|
847 if (((SDL_PublicSurface->flags&SDL_HWSURFACE) == SDL_HWSURFACE) && current_video->info.blit_hw) |
306
3879bed3395c
Only put surfaces in video memory if there are accelerated blits
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
848 flags = SDL_HWSURFACE; |
3879bed3395c
Only put surfaces in video memory if there are accelerated blits
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
849 else |
3879bed3395c
Only put surfaces in video memory if there are accelerated blits
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
850 flags = SDL_SWSURFACE; |
0 | 851 #ifdef AUTORLE_DISPLAYFORMAT |
852 flags |= (surface->flags & (SDL_SRCCOLORKEY|SDL_SRCALPHA)); | |
853 flags |= SDL_RLEACCELOK; | |
854 #else | |
855 flags |= surface->flags & (SDL_SRCCOLORKEY|SDL_SRCALPHA|SDL_RLEACCELOK); | |
856 #endif | |
857 return(SDL_ConvertSurface(surface, SDL_PublicSurface->format, flags)); | |
858 } | |
859 | |
860 /* | |
861 * Convert a surface into a format that's suitable for blitting to | |
862 * the screen, but including an alpha channel. | |
863 */ | |
864 SDL_Surface *SDL_DisplayFormatAlpha(SDL_Surface *surface) | |
865 { | |
866 SDL_PixelFormat *vf; | |
867 SDL_PixelFormat *format; | |
868 SDL_Surface *converted; | |
869 Uint32 flags; | |
870 /* default to ARGB8888 */ | |
871 Uint32 amask = 0xff000000; | |
872 Uint32 rmask = 0x00ff0000; | |
873 Uint32 gmask = 0x0000ff00; | |
874 Uint32 bmask = 0x000000ff; | |
875 | |
876 if ( ! SDL_PublicSurface ) { | |
877 SDL_SetError("No video mode has been set"); | |
878 return(NULL); | |
879 } | |
880 vf = SDL_PublicSurface->format; | |
881 | |
882 switch(vf->BytesPerPixel) { | |
883 case 2: | |
884 /* For XGY5[56]5, use, AXGY8888, where {X, Y} = {R, B}. | |
885 For anything else (like ARGB4444) it doesn't matter | |
886 since we have no special code for it anyway */ | |
887 if ( (vf->Rmask == 0x1f) && | |
888 (vf->Bmask == 0xf800 || vf->Bmask == 0x7c00)) { | |
889 rmask = 0xff; | |
890 bmask = 0xff0000; | |
891 } | |
892 break; | |
893 | |
894 case 3: | |
895 case 4: | |
896 /* Keep the video format, as long as the high 8 bits are | |
897 unused or alpha */ | |
898 if ( (vf->Rmask == 0xff) && (vf->Bmask == 0xff0000) ) { | |
899 rmask = 0xff; | |
900 bmask = 0xff0000; | |
901 } | |
902 break; | |
903 | |
904 default: | |
905 /* We have no other optimised formats right now. When/if a new | |
906 optimised alpha format is written, add the converter here */ | |
907 break; | |
908 } | |
909 format = SDL_AllocFormat(32, rmask, gmask, bmask, amask); | |
910 flags = SDL_PublicSurface->flags & SDL_HWSURFACE; | |
911 flags |= surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK); | |
912 converted = SDL_ConvertSurface(surface, format, flags); | |
913 SDL_FreeFormat(format); | |
914 return(converted); | |
915 } | |
916 | |
917 /* | |
918 * Update a specific portion of the physical screen | |
919 */ | |
920 void SDL_UpdateRect(SDL_Surface *screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h) | |
921 { | |
922 if ( screen ) { | |
923 SDL_Rect rect; | |
924 | |
925 /* Perform some checking */ | |
926 if ( w == 0 ) | |
927 w = screen->w; | |
928 if ( h == 0 ) | |
929 h = screen->h; | |
930 if ( (int)(x+w) > screen->w ) | |
931 return; | |
932 if ( (int)(y+h) > screen->h ) | |
933 return; | |
934 | |
935 /* Fill the rectangle */ | |
936 rect.x = x; | |
937 rect.y = y; | |
938 rect.w = w; | |
939 rect.h = h; | |
940 SDL_UpdateRects(screen, 1, &rect); | |
941 } | |
942 } | |
943 void SDL_UpdateRects (SDL_Surface *screen, int numrects, SDL_Rect *rects) | |
944 { | |
945 int i; | |
946 SDL_VideoDevice *video = current_video; | |
947 SDL_VideoDevice *this = current_video; | |
948 | |
949 if ( screen == SDL_ShadowSurface ) { | |
950 /* Blit the shadow surface using saved mapping */ | |
951 SDL_Palette *pal = screen->format->palette; | |
952 SDL_Color *saved_colors = NULL; | |
953 if ( pal && !(SDL_VideoSurface->flags & SDL_HWPALETTE) ) { | |
954 /* simulated 8bpp, use correct physical palette */ | |
955 saved_colors = pal->colors; | |
956 if ( video->gammacols ) { | |
957 /* gamma-corrected palette */ | |
958 pal->colors = video->gammacols; | |
959 } else if ( video->physpal ) { | |
960 /* physical palette different from logical */ | |
961 pal->colors = video->physpal->colors; | |
962 } | |
963 } | |
964 if ( SHOULD_DRAWCURSOR(SDL_cursorstate) ) { | |
965 SDL_LockCursor(); | |
966 SDL_DrawCursor(SDL_ShadowSurface); | |
967 for ( i=0; i<numrects; ++i ) { | |
968 SDL_LowerBlit(SDL_ShadowSurface, &rects[i], | |
969 SDL_VideoSurface, &rects[i]); | |
970 } | |
971 SDL_EraseCursor(SDL_ShadowSurface); | |
972 SDL_UnlockCursor(); | |
973 } else { | |
974 for ( i=0; i<numrects; ++i ) { | |
975 SDL_LowerBlit(SDL_ShadowSurface, &rects[i], | |
976 SDL_VideoSurface, &rects[i]); | |
977 } | |
978 } | |
979 if ( saved_colors ) | |
980 pal->colors = saved_colors; | |
981 | |
982 /* Fall through to video surface update */ | |
983 screen = SDL_VideoSurface; | |
984 } | |
985 if ( screen == SDL_VideoSurface ) { | |
986 /* Update the video surface */ | |
987 if ( screen->offset ) { | |
988 for ( i=0; i<numrects; ++i ) { | |
989 rects[i].x += video->offset_x; | |
990 rects[i].y += video->offset_y; | |
991 } | |
992 video->UpdateRects(this, numrects, rects); | |
993 for ( i=0; i<numrects; ++i ) { | |
994 rects[i].x -= video->offset_x; | |
995 rects[i].y -= video->offset_y; | |
996 } | |
997 } else { | |
998 video->UpdateRects(this, numrects, rects); | |
999 } | |
1000 } | |
1001 } | |
1002 | |
1003 /* | |
1004 * Performs hardware double buffering, if possible, or a full update if not. | |
1005 */ | |
1006 int SDL_Flip(SDL_Surface *screen) | |
1007 { | |
1008 SDL_VideoDevice *video = current_video; | |
1009 /* Copy the shadow surface to the video surface */ | |
1010 if ( screen == SDL_ShadowSurface ) { | |
1011 SDL_Rect rect; | |
1012 SDL_Palette *pal = screen->format->palette; | |
1013 SDL_Color *saved_colors = NULL; | |
1014 if ( pal && !(SDL_VideoSurface->flags & SDL_HWPALETTE) ) { | |
1015 /* simulated 8bpp, use correct physical palette */ | |
1016 saved_colors = pal->colors; | |
1017 if ( video->gammacols ) { | |
1018 /* gamma-corrected palette */ | |
1019 pal->colors = video->gammacols; | |
1020 } else if ( video->physpal ) { | |
1021 /* physical palette different from logical */ | |
1022 pal->colors = video->physpal->colors; | |
1023 } | |
1024 } | |
1025 | |
1026 rect.x = 0; | |
1027 rect.y = 0; | |
1028 rect.w = screen->w; | |
1029 rect.h = screen->h; | |
1030 SDL_LowerBlit(SDL_ShadowSurface,&rect, SDL_VideoSurface,&rect); | |
1031 | |
1032 if ( saved_colors ) | |
1033 pal->colors = saved_colors; | |
1034 screen = SDL_VideoSurface; | |
1035 } | |
1036 if ( (screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) { | |
1037 SDL_VideoDevice *this = current_video; | |
1038 return(video->FlipHWSurface(this, SDL_VideoSurface)); | |
1039 } else { | |
1040 SDL_UpdateRect(screen, 0, 0, 0, 0); | |
1041 } | |
1042 return(0); | |
1043 } | |
1044 | |
1045 static void SetPalette_logical(SDL_Surface *screen, SDL_Color *colors, | |
1046 int firstcolor, int ncolors) | |
1047 { | |
1048 SDL_Palette *pal = screen->format->palette; | |
1049 SDL_Palette *vidpal; | |
1050 | |
1051 if ( colors != (pal->colors + firstcolor) ) { | |
1052 memcpy(pal->colors + firstcolor, colors, | |
1053 ncolors * sizeof(*colors)); | |
1054 } | |
1055 | |
1056 vidpal = SDL_VideoSurface->format->palette; | |
1057 if ( (screen == SDL_ShadowSurface) && vidpal ) { | |
1058 /* | |
1059 * This is a shadow surface, and the physical | |
1060 * framebuffer is also indexed. Propagate the | |
1061 * changes to its logical palette so that | |
1062 * updates are always identity blits | |
1063 */ | |
1064 memcpy(vidpal->colors + firstcolor, colors, | |
1065 ncolors * sizeof(*colors)); | |
1066 } | |
1067 SDL_FormatChanged(screen); | |
1068 } | |
1069 | |
1070 static int SetPalette_physical(SDL_Surface *screen, | |
1071 SDL_Color *colors, int firstcolor, int ncolors) | |
1072 { | |
1073 SDL_VideoDevice *video = current_video; | |
1074 int gotall = 1; | |
1075 | |
1076 if ( video->physpal ) { | |
1077 /* We need to copy the new colors, since we haven't | |
1078 * already done the copy in the logical set above. | |
1079 */ | |
1080 memcpy(video->physpal->colors + firstcolor, | |
1081 colors, ncolors * sizeof(*colors)); | |
1082 } | |
1083 if ( screen == SDL_ShadowSurface ) { | |
1084 if ( SDL_VideoSurface->flags & SDL_HWPALETTE ) { | |
1085 /* | |
1086 * The real screen is also indexed - set its physical | |
1087 * palette. The physical palette does not include the | |
1088 * gamma modification, we apply it directly instead, | |
1089 * but this only happens if we have hardware palette. | |
1090 */ | |
1091 screen = SDL_VideoSurface; | |
1092 } else { | |
1093 /* | |
1094 * The video surface is not indexed - invalidate any | |
1095 * active shadow-to-video blit mappings. | |
1096 */ | |
1097 if ( screen->map->dst == SDL_VideoSurface ) { | |
1098 SDL_InvalidateMap(screen->map); | |
1099 } | |
1100 if ( video->gamma ) { | |
1101 if( ! video->gammacols ) { | |
1102 SDL_Palette *pp = video->physpal; | |
1103 if(!pp) | |
1104 pp = screen->format->palette; | |
1105 video->gammacols = malloc(pp->ncolors | |
1106 * sizeof(SDL_Color)); | |
1107 SDL_ApplyGamma(video->gamma, | |
1108 pp->colors, | |
1109 video->gammacols, | |
1110 pp->ncolors); | |
1111 } else { | |
1112 SDL_ApplyGamma(video->gamma, colors, | |
1113 video->gammacols | |
1114 + firstcolor, | |
1115 ncolors); | |
1116 } | |
1117 } | |
1118 SDL_UpdateRect(screen, 0, 0, 0, 0); | |
1119 } | |
1120 } | |
1121 | |
1122 if ( screen == SDL_VideoSurface ) { | |
1123 SDL_Color gcolors[256]; | |
1124 | |
1125 if ( video->gamma ) { | |
1126 SDL_ApplyGamma(video->gamma, colors, gcolors, ncolors); | |
1127 colors = gcolors; | |
1128 } | |
1129 gotall = video->SetColors(video, firstcolor, ncolors, colors); | |
1130 if ( ! gotall ) { | |
1131 /* The video flags shouldn't have SDL_HWPALETTE, and | |
1132 the video driver is responsible for copying back the | |
1133 correct colors into the video surface palette. | |
1134 */ | |
1135 ; | |
1136 } | |
1137 SDL_CursorPaletteChanged(); | |
1138 } | |
1139 return gotall; | |
1140 } | |
1141 | |
1142 /* | |
1143 * Set the physical and/or logical colormap of a surface: | |
1144 * Only the screen has a physical colormap. It determines what is actually | |
1145 * sent to the display. | |
1146 * The logical colormap is used to map blits to/from the surface. | |
1147 * 'which' is one or both of SDL_LOGPAL, SDL_PHYSPAL | |
1148 * | |
1149 * Return nonzero if all colours were set as requested, or 0 otherwise. | |
1150 */ | |
1151 int SDL_SetPalette(SDL_Surface *screen, int which, | |
1152 SDL_Color *colors, int firstcolor, int ncolors) | |
1153 { | |
1154 SDL_Palette *pal; | |
1155 int gotall; | |
1156 int palsize; | |
1157 | |
34 | 1158 if ( ! current_video ) { |
1159 return 0; | |
1160 } | |
0 | 1161 if ( screen != SDL_PublicSurface ) { |
1162 /* only screens have physical palettes */ | |
1163 which &= ~SDL_PHYSPAL; | |
1164 } else if( (screen->flags & SDL_HWPALETTE) != SDL_HWPALETTE ) { | |
1165 /* hardware palettes required for split colormaps */ | |
1166 which |= SDL_PHYSPAL | SDL_LOGPAL; | |
1167 } | |
1168 | |
1169 /* Verify the parameters */ | |
1170 pal = screen->format->palette; | |
1171 if( !pal ) { | |
1172 return 0; /* not a palettized surface */ | |
1173 } | |
1174 gotall = 1; | |
1175 palsize = 1 << screen->format->BitsPerPixel; | |
1176 if ( ncolors > (palsize - firstcolor) ) { | |
1177 ncolors = (palsize - firstcolor); | |
1178 gotall = 0; | |
1179 } | |
1180 | |
1181 if ( which & SDL_LOGPAL ) { | |
1182 /* | |
1183 * Logical palette change: The actual screen isn't affected, | |
1184 * but the internal colormap is altered so that the | |
1185 * interpretation of the pixel values (for blits etc) is | |
1186 * changed. | |
1187 */ | |
1188 SetPalette_logical(screen, colors, firstcolor, ncolors); | |
1189 } | |
1190 if ( which & SDL_PHYSPAL ) { | |
1191 SDL_VideoDevice *video = current_video; | |
1192 /* | |
1193 * Physical palette change: This doesn't affect the | |
1194 * program's idea of what the screen looks like, but changes | |
1195 * its actual appearance. | |
1196 */ | |
1197 if(!video) | |
1198 return gotall; /* video not yet initialized */ | |
1199 if(!video->physpal && !(which & SDL_LOGPAL) ) { | |
1200 /* Lazy physical palette allocation */ | |
1201 int size; | |
1202 SDL_Palette *pp = malloc(sizeof(*pp)); | |
1203 current_video->physpal = pp; | |
1204 pp->ncolors = pal->ncolors; | |
1205 size = pp->ncolors * sizeof(SDL_Color); | |
1206 pp->colors = malloc(size); | |
1207 memcpy(pp->colors, pal->colors, size); | |
1208 } | |
1209 if ( ! SetPalette_physical(screen, | |
1210 colors, firstcolor, ncolors) ) { | |
1211 gotall = 0; | |
1212 } | |
1213 } | |
1214 return gotall; | |
1215 } | |
1216 | |
1217 int SDL_SetColors(SDL_Surface *screen, SDL_Color *colors, int firstcolor, | |
1218 int ncolors) | |
1219 { | |
1220 return SDL_SetPalette(screen, SDL_LOGPAL | SDL_PHYSPAL, | |
1221 colors, firstcolor, ncolors); | |
1222 } | |
1223 | |
1224 /* | |
1225 * Clean up the video subsystem | |
1226 */ | |
1227 void SDL_VideoQuit (void) | |
1228 { | |
1229 SDL_Surface *ready_to_go; | |
1230 | |
1231 if ( current_video ) { | |
1232 SDL_VideoDevice *video = current_video; | |
1233 SDL_VideoDevice *this = current_video; | |
1234 | |
1235 /* Halt event processing before doing anything else */ | |
1236 SDL_StopEventLoop(); | |
1237 | |
1238 /* Clean up allocated window manager items */ | |
1239 if ( SDL_PublicSurface ) { | |
1240 SDL_PublicSurface = NULL; | |
1241 } | |
1242 SDL_CursorQuit(); | |
1243 | |
1244 /* Just in case... */ | |
1245 SDL_WM_GrabInputOff(); | |
1246 | |
1247 /* Clean up the system video */ | |
1248 video->VideoQuit(this); | |
1249 | |
1250 /* Free any lingering surfaces */ | |
1251 ready_to_go = SDL_ShadowSurface; | |
1252 SDL_ShadowSurface = NULL; | |
1253 SDL_FreeSurface(ready_to_go); | |
1254 if ( SDL_VideoSurface != NULL ) { | |
1255 ready_to_go = SDL_VideoSurface; | |
1256 SDL_VideoSurface = NULL; | |
1257 SDL_FreeSurface(ready_to_go); | |
1258 } | |
1259 SDL_PublicSurface = NULL; | |
1260 | |
1261 /* Clean up miscellaneous memory */ | |
1262 if ( video->physpal ) { | |
1263 free(video->physpal->colors); | |
1264 free(video->physpal); | |
1265 video->physpal = NULL; | |
1266 } | |
1267 if ( video->gammacols ) { | |
1268 free(video->gammacols); | |
1269 video->gammacols = NULL; | |
1270 } | |
1271 if ( video->gamma ) { | |
1272 free(video->gamma); | |
1273 video->gamma = NULL; | |
1274 } | |
58
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1275 if ( video->wm_title != NULL ) { |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1276 free(video->wm_title); |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1277 video->wm_title = NULL; |
0 | 1278 } |
58
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1279 if ( video->wm_icon != NULL ) { |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1280 free(video->wm_icon); |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1281 video->wm_icon = NULL; |
0 | 1282 } |
1283 | |
1284 /* Finish cleaning up video subsystem */ | |
1285 video->free(this); | |
1286 current_video = NULL; | |
1287 } | |
1288 return; | |
1289 } | |
1290 | |
1291 /* Load the GL driver library */ | |
1292 int SDL_GL_LoadLibrary(const char *path) | |
1293 { | |
1294 SDL_VideoDevice *video = current_video; | |
1295 SDL_VideoDevice *this = current_video; | |
1296 int retval; | |
1297 | |
1298 retval = -1; | |
7
2c4a3a759c66
*** empty log message ***
Sam Lantinga <slouken@lokigames.com>
parents:
1
diff
changeset
|
1299 if ( video && video->GL_LoadLibrary ) { |
0 | 1300 retval = video->GL_LoadLibrary(this, path); |
1301 } else { | |
1302 SDL_SetError("No dynamic GL support in video driver"); | |
1303 } | |
1304 return(retval); | |
1305 } | |
1306 | |
1307 void *SDL_GL_GetProcAddress(const char* proc) | |
1308 { | |
1309 SDL_VideoDevice *video = current_video; | |
1310 SDL_VideoDevice *this = current_video; | |
1311 void *func; | |
1312 | |
1313 func = NULL; | |
1314 if ( video->GL_GetProcAddress ) { | |
1315 if ( video->gl_config.driver_loaded ) { | |
1316 func = video->GL_GetProcAddress(this, proc); | |
1317 } else { | |
1318 SDL_SetError("No GL driver has been loaded"); | |
1319 } | |
1320 } else { | |
1321 SDL_SetError("No dynamic GL support in video driver"); | |
1322 } | |
1323 return func; | |
1324 } | |
1325 | |
1326 /* Set the specified GL attribute for setting up a GL video mode */ | |
1327 int SDL_GL_SetAttribute( SDL_GLattr attr, int value ) | |
1328 { | |
1329 int retval; | |
1330 SDL_VideoDevice *video = current_video; | |
1331 | |
1332 retval = 0; | |
1333 switch (attr) { | |
1334 case SDL_GL_RED_SIZE: | |
1335 video->gl_config.red_size = value; | |
1336 break; | |
1337 case SDL_GL_GREEN_SIZE: | |
1338 video->gl_config.green_size = value; | |
1339 break; | |
1340 case SDL_GL_BLUE_SIZE: | |
1341 video->gl_config.blue_size = value; | |
1342 break; | |
1343 case SDL_GL_ALPHA_SIZE: | |
1344 video->gl_config.alpha_size = value; | |
1345 break; | |
1346 case SDL_GL_DOUBLEBUFFER: | |
1347 video->gl_config.double_buffer = value; | |
1348 break; | |
1349 case SDL_GL_BUFFER_SIZE: | |
1350 video->gl_config.buffer_size = value; | |
1351 break; | |
1352 case SDL_GL_DEPTH_SIZE: | |
1353 video->gl_config.depth_size = value; | |
1354 break; | |
1355 case SDL_GL_STENCIL_SIZE: | |
1356 video->gl_config.stencil_size = value; | |
1357 break; | |
1358 case SDL_GL_ACCUM_RED_SIZE: | |
1359 video->gl_config.accum_red_size = value; | |
1360 break; | |
1361 case SDL_GL_ACCUM_GREEN_SIZE: | |
1362 video->gl_config.accum_green_size = value; | |
1363 break; | |
1364 case SDL_GL_ACCUM_BLUE_SIZE: | |
1365 video->gl_config.accum_blue_size = value; | |
1366 break; | |
1367 case SDL_GL_ACCUM_ALPHA_SIZE: | |
1368 video->gl_config.accum_alpha_size = value; | |
1369 break; | |
1370 default: | |
1371 SDL_SetError("Unknown OpenGL attribute"); | |
1372 retval = -1; | |
1373 break; | |
1374 } | |
1375 return(retval); | |
1376 } | |
1377 | |
1378 /* Retrieve an attribute value from the windowing system. */ | |
1379 int SDL_GL_GetAttribute(SDL_GLattr attr, int* value) | |
1380 { | |
1381 int retval = -1; | |
1382 SDL_VideoDevice* video = current_video; | |
1383 SDL_VideoDevice* this = current_video; | |
1384 | |
1385 if ( video->GL_GetAttribute ) { | |
1386 retval = this->GL_GetAttribute(this, attr, value); | |
11
7b94b6379341
*** empty log message ***
Sam Lantinga <slouken@lokigames.com>
parents:
7
diff
changeset
|
1387 } else { |
7b94b6379341
*** empty log message ***
Sam Lantinga <slouken@lokigames.com>
parents:
7
diff
changeset
|
1388 *value = 0; |
7b94b6379341
*** empty log message ***
Sam Lantinga <slouken@lokigames.com>
parents:
7
diff
changeset
|
1389 SDL_SetError("GL_GetAttribute not supported"); |
0 | 1390 } |
1391 return retval; | |
1392 } | |
1393 | |
1394 /* Perform a GL buffer swap on the current GL context */ | |
1395 void SDL_GL_SwapBuffers(void) | |
1396 { | |
1397 SDL_VideoDevice *video = current_video; | |
1398 SDL_VideoDevice *this = current_video; | |
1399 | |
1400 if ( video->screen->flags & SDL_OPENGL ) { | |
266
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
1401 video->GL_SwapBuffers(this); |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
1402 } else { |
c6abdda2f666
Added QNX cleanups by Mike Gorchak (thanks!)
Sam Lantinga <slouken@libsdl.org>
parents:
252
diff
changeset
|
1403 SDL_SetError("OpenGL video mode has not been set"); |
0 | 1404 } |
1405 } | |
1406 | |
1407 /* Update rects with locking */ | |
1408 void SDL_GL_UpdateRectsLock(SDL_VideoDevice* this, int numrects, SDL_Rect *rects) | |
1409 { | |
1410 SDL_GL_Lock(); | |
1411 SDL_GL_UpdateRects(numrects, rects); | |
1412 SDL_GL_Unlock(); | |
1413 } | |
1414 | |
1415 /* Update rects without state setting and changing (the caller is responsible for it) */ | |
1416 void SDL_GL_UpdateRects(int numrects, SDL_Rect *rects) | |
1417 { | |
1418 #ifdef HAVE_OPENGL | |
1419 SDL_VideoDevice *this = current_video; | |
1420 SDL_Rect update, tmp; | |
1421 int x, y, i; | |
1422 | |
1423 for ( i = 0; i < numrects; i++ ) | |
1424 { | |
1425 tmp.y = rects[i].y; | |
1426 tmp.h = rects[i].h; | |
1427 for ( y = 0; y <= rects[i].h / 256; y++ ) | |
1428 { | |
1429 tmp.x = rects[i].x; | |
1430 tmp.w = rects[i].w; | |
1431 for ( x = 0; x <= rects[i].w / 256; x++ ) | |
1432 { | |
1433 update.x = tmp.x; | |
1434 update.y = tmp.y; | |
1435 update.w = tmp.w; | |
1436 update.h = tmp.h; | |
1437 | |
1438 if ( update.w > 256 ) | |
1439 update.w = 256; | |
1440 | |
1441 if ( update.h > 256 ) | |
1442 update.h = 256; | |
1443 | |
1444 this->glFlush(); | |
1445 this->glTexSubImage2D( | |
1446 GL_TEXTURE_2D, | |
1447 0, | |
1448 0, | |
1449 0, | |
1450 update.w, | |
1451 update.h, | |
1452 this->is_32bit? GL_RGBA : GL_RGB, | |
1453 #ifdef GL_VERSION_1_2 | |
1454 this->is_32bit ? GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT_5_6_5, | |
1455 #else | |
1456 GL_UNSIGNED_BYTE, | |
1457 #endif | |
1458 (Uint8 *)this->screen->pixels + | |
1459 this->screen->format->BytesPerPixel * update.x + | |
1460 update.y * this->screen->pitch ); | |
1461 | |
1462 this->glFlush(); | |
1463 /* | |
1464 * Note the parens around the function name: | |
1465 * This is because some OpenGL implementations define glTexCoord etc | |
1466 * as macros, and we don't want them expanded here. | |
1467 */ | |
1468 this->glBegin(GL_TRIANGLE_STRIP); | |
1469 (this->glTexCoord2f)( 0.0, 0.0 ); | |
1470 (this->glVertex2i)( update.x, update.y ); | |
1471 (this->glTexCoord2f)( (float)(update.w / 256.0), 0.0 ); | |
1472 (this->glVertex2i)( update.x + update.w, update.y ); | |
1473 (this->glTexCoord2f)( 0.0, (float)(update.h / 256.0) ); | |
1474 (this->glVertex2i)( update.x, update.y + update.h ); | |
1475 (this->glTexCoord2f)( (float)(update.w / 256.0), (float)(update.h / 256.0) ); | |
1476 (this->glVertex2i)( update.x + update.w , update.y + update.h ); | |
1477 this->glEnd(); | |
1478 | |
1479 tmp.x += 256; | |
1480 tmp.w -= 256; | |
1481 } | |
1482 tmp.y += 256; | |
1483 tmp.h -= 256; | |
1484 } | |
1485 } | |
1486 #endif | |
1487 } | |
1488 | |
1489 /* Lock == save current state */ | |
1490 void SDL_GL_Lock() | |
1491 { | |
1492 #ifdef HAVE_OPENGL | |
1493 lock_count--; | |
1494 if (lock_count==-1) | |
1495 { | |
1496 SDL_VideoDevice *this = current_video; | |
1497 | |
1498 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
|
1499 #ifdef GL_CLIENT_PIXEL_STORE_BIT |
0 | 1500 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
|
1501 #endif |
0 | 1502 |
1503 this->glEnable(GL_TEXTURE_2D); | |
1504 this->glEnable(GL_BLEND); | |
1505 this->glDisable(GL_FOG); | |
1506 this->glDisable(GL_ALPHA_TEST); | |
1507 this->glDisable(GL_DEPTH_TEST); | |
1508 this->glDisable(GL_SCISSOR_TEST); | |
1509 this->glDisable(GL_STENCIL_TEST); | |
1510 this->glDisable(GL_CULL_FACE); | |
1511 | |
1512 this->glBindTexture( GL_TEXTURE_2D, this->texture ); | |
1513 this->glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); | |
1514 this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); | |
1515 this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); | |
1516 this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); | |
1517 this->glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); | |
1518 | |
1519 this->glPixelStorei( GL_UNPACK_ROW_LENGTH, this->screen->pitch / this->screen->format->BytesPerPixel ); | |
1520 this->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |
1521 (this->glColor4f)(1.0, 1.0, 1.0, 1.0); /* Solaris workaround */ | |
1522 | |
1523 this->glViewport(0, 0, this->screen->w, this->screen->h); | |
1524 this->glMatrixMode(GL_PROJECTION); | |
1525 this->glPushMatrix(); | |
1526 this->glLoadIdentity(); | |
1527 | |
1528 this->glOrtho(0.0, (GLdouble) this->screen->w, (GLdouble) this->screen->h, 0.0, 0.0, 1.0); | |
1529 | |
1530 this->glMatrixMode(GL_MODELVIEW); | |
1531 this->glPushMatrix(); | |
1532 this->glLoadIdentity(); | |
1533 } | |
1534 #endif | |
1535 } | |
1536 | |
1537 /* Unlock == restore saved state */ | |
1538 void SDL_GL_Unlock() | |
1539 { | |
1540 #ifdef HAVE_OPENGL | |
1541 lock_count++; | |
1542 if (lock_count==0) | |
1543 { | |
1544 SDL_VideoDevice *this = current_video; | |
1545 | |
1546 this->glPopMatrix(); | |
1547 this->glMatrixMode(GL_PROJECTION); | |
1548 this->glPopMatrix(); | |
1549 | |
1550 this->glPopClientAttrib(); | |
1551 this->glPopAttrib(); | |
1552 } | |
1553 #endif | |
1554 } | |
1555 | |
1556 /* | |
1557 * Sets/Gets the title and icon text of the display window, if any. | |
1558 */ | |
1559 void SDL_WM_SetCaption (const char *title, const char *icon) | |
1560 { | |
1561 SDL_VideoDevice *video = current_video; | |
1562 SDL_VideoDevice *this = current_video; | |
1563 | |
58
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1564 if ( video ) { |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1565 if ( title ) { |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1566 if ( video->wm_title ) { |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1567 free(video->wm_title); |
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_title = (char *)malloc(strlen(title)+1); |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1570 if ( video->wm_title != NULL ) { |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1571 strcpy(video->wm_title, title); |
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 ( icon ) { |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1575 if ( video->wm_icon ) { |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1576 free(video->wm_icon); |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1577 } |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1578 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
|
1579 if ( video->wm_icon != NULL ) { |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1580 strcpy(video->wm_icon, icon); |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1581 } |
0 | 1582 } |
58
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1583 if ( (title || icon) && (video->SetCaption != NULL) ) { |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1584 video->SetCaption(this, video->wm_title,video->wm_icon); |
0 | 1585 } |
1586 } | |
1587 } | |
1588 void SDL_WM_GetCaption (char **title, char **icon) | |
1589 { | |
58
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1590 SDL_VideoDevice *video = current_video; |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1591 |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1592 if ( video ) { |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1593 if ( title ) { |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1594 *title = video->wm_title; |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1595 } |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1596 if ( icon ) { |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1597 *icon = video->wm_icon; |
bd6b0a910a65
* Removed fullscreen menu option from the "Window" menu
Sam Lantinga <slouken@lokigames.com>
parents:
47
diff
changeset
|
1598 } |
0 | 1599 } |
1600 } | |
1601 | |
1602 /* Utility function used by SDL_WM_SetIcon() */ | |
1603 static void CreateMaskFromColorKey(SDL_Surface *icon, Uint8 *mask) | |
1604 { | |
1605 int x, y; | |
1606 Uint32 colorkey; | |
1607 #define SET_MASKBIT(icon, x, y, mask) \ | |
1608 mask[(y*((icon->w+7)/8))+(x/8)] &= ~(0x01<<(7-(x%8))) | |
1609 | |
1610 colorkey = icon->format->colorkey; | |
1611 switch (icon->format->BytesPerPixel) { | |
1612 case 1: { Uint8 *pixels; | |
1613 for ( y=0; y<icon->h; ++y ) { | |
1614 pixels = (Uint8 *)icon->pixels + y*icon->pitch; | |
1615 for ( x=0; x<icon->w; ++x ) { | |
1616 if ( *pixels++ == colorkey ) { | |
1617 SET_MASKBIT(icon, x, y, mask); | |
1618 } | |
1619 } | |
1620 } | |
1621 } | |
1622 break; | |
1623 | |
1624 case 2: { Uint16 *pixels; | |
1625 for ( y=0; y<icon->h; ++y ) { | |
1626 pixels = (Uint16 *)icon->pixels + | |
1627 y*icon->pitch/2; | |
1628 for ( x=0; x<icon->w; ++x ) { | |
1629 if ( *pixels++ == colorkey ) { | |
1630 SET_MASKBIT(icon, x, y, mask); | |
1631 } | |
1632 } | |
1633 } | |
1634 } | |
1635 break; | |
1636 | |
1637 case 4: { Uint32 *pixels; | |
1638 for ( y=0; y<icon->h; ++y ) { | |
1639 pixels = (Uint32 *)icon->pixels + | |
1640 y*icon->pitch/4; | |
1641 for ( x=0; x<icon->w; ++x ) { | |
1642 if ( *pixels++ == colorkey ) { | |
1643 SET_MASKBIT(icon, x, y, mask); | |
1644 } | |
1645 } | |
1646 } | |
1647 } | |
1648 break; | |
1649 } | |
1650 } | |
1651 | |
1652 /* | |
1653 * Sets the window manager icon for the display window. | |
1654 */ | |
1655 void SDL_WM_SetIcon (SDL_Surface *icon, Uint8 *mask) | |
1656 { | |
1657 SDL_VideoDevice *video = current_video; | |
1658 SDL_VideoDevice *this = current_video; | |
1659 | |
1660 if ( icon && video->SetIcon ) { | |
1661 /* Generate a mask if necessary, and create the icon! */ | |
1662 if ( mask == NULL ) { | |
1663 int mask_len = icon->h*(icon->w+7)/8; | |
1664 mask = (Uint8 *)malloc(mask_len); | |
1665 if ( mask == NULL ) { | |
1666 return; | |
1667 } | |
1668 memset(mask, ~0, mask_len); | |
1669 if ( icon->flags & SDL_SRCCOLORKEY ) { | |
1670 CreateMaskFromColorKey(icon, mask); | |
1671 } | |
1672 video->SetIcon(video, icon, mask); | |
1673 free(mask); | |
1674 } else { | |
1675 video->SetIcon(this, icon, mask); | |
1676 } | |
1677 } | |
1678 } | |
1679 | |
1680 /* | |
1681 * Grab or ungrab the keyboard and mouse input. | |
1682 * This function returns the final grab mode after calling the | |
1683 * driver dependent function. | |
1684 */ | |
1685 static SDL_GrabMode SDL_WM_GrabInputRaw(SDL_GrabMode mode) | |
1686 { | |
1687 SDL_VideoDevice *video = current_video; | |
1688 SDL_VideoDevice *this = current_video; | |
1689 | |
1690 /* Only do something if we have support for grabs */ | |
1691 if ( video->GrabInput == NULL ) { | |
1692 return(video->input_grab); | |
1693 } | |
1694 | |
1695 /* If the final grab mode if off, only then do we actually grab */ | |
1696 #ifdef DEBUG_GRAB | |
1697 printf("SDL_WM_GrabInputRaw(%d) ... ", mode); | |
1698 #endif | |
1699 if ( mode == SDL_GRAB_OFF ) { | |
1700 if ( video->input_grab != SDL_GRAB_OFF ) { | |
1701 mode = video->GrabInput(this, mode); | |
1702 } | |
1703 } else { | |
1704 if ( video->input_grab == SDL_GRAB_OFF ) { | |
1705 mode = video->GrabInput(this, mode); | |
1706 } | |
1707 } | |
1708 if ( mode != video->input_grab ) { | |
1709 video->input_grab = mode; | |
1710 if ( video->CheckMouseMode ) { | |
1711 video->CheckMouseMode(this); | |
1712 } | |
1713 } | |
1714 #ifdef DEBUG_GRAB | |
1715 printf("Final mode %d\n", video->input_grab); | |
1716 #endif | |
1717 | |
1718 /* Return the final grab state */ | |
1719 if ( mode >= SDL_GRAB_FULLSCREEN ) { | |
1720 mode -= SDL_GRAB_FULLSCREEN; | |
1721 } | |
1722 return(mode); | |
1723 } | |
1724 SDL_GrabMode SDL_WM_GrabInput(SDL_GrabMode mode) | |
1725 { | |
1726 SDL_VideoDevice *video = current_video; | |
1727 | |
11
7b94b6379341
*** empty log message ***
Sam Lantinga <slouken@lokigames.com>
parents:
7
diff
changeset
|
1728 /* 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
|
1729 if ( ! video ) { |
7b94b6379341
*** empty log message ***
Sam Lantinga <slouken@lokigames.com>
parents:
7
diff
changeset
|
1730 return SDL_GRAB_OFF; |
7b94b6379341
*** empty log message ***
Sam Lantinga <slouken@lokigames.com>
parents:
7
diff
changeset
|
1731 } |
0 | 1732 |
1733 /* Return the current mode on query */ | |
1734 if ( mode == SDL_GRAB_QUERY ) { | |
1735 mode = video->input_grab; | |
1736 if ( mode >= SDL_GRAB_FULLSCREEN ) { | |
1737 mode -= SDL_GRAB_FULLSCREEN; | |
1738 } | |
1739 return(mode); | |
1740 } | |
1741 | |
1742 #ifdef DEBUG_GRAB | |
1743 printf("SDL_WM_GrabInput(%d) ... ", mode); | |
1744 #endif | |
1745 /* If the video surface is fullscreen, we always grab */ | |
1746 if ( mode >= SDL_GRAB_FULLSCREEN ) { | |
1747 mode -= SDL_GRAB_FULLSCREEN; | |
1748 } | |
1749 if ( SDL_VideoSurface && (SDL_VideoSurface->flags & SDL_FULLSCREEN) ) { | |
1750 mode += SDL_GRAB_FULLSCREEN; | |
1751 } | |
1752 return(SDL_WM_GrabInputRaw(mode)); | |
1753 } | |
1754 static SDL_GrabMode SDL_WM_GrabInputOff(void) | |
1755 { | |
1756 SDL_GrabMode mode; | |
1757 | |
1758 /* First query the current grab state */ | |
1759 mode = SDL_WM_GrabInput(SDL_GRAB_QUERY); | |
1760 | |
1761 /* Now explicitly turn off input grab */ | |
1762 SDL_WM_GrabInputRaw(SDL_GRAB_OFF); | |
1763 | |
1764 /* Return the old state */ | |
1765 return(mode); | |
1766 } | |
1767 | |
1768 /* | |
1769 * Iconify the window in window managed environments. | |
1770 * A successful iconification will result in an SDL_APPACTIVE loss event. | |
1771 */ | |
1772 int SDL_WM_IconifyWindow(void) | |
1773 { | |
1774 SDL_VideoDevice *video = current_video; | |
1775 SDL_VideoDevice *this = current_video; | |
1776 int retval; | |
1777 | |
1778 retval = 0; | |
1779 if ( video->IconifyWindow ) { | |
1780 retval = video->IconifyWindow(this); | |
1781 } | |
1782 return(retval); | |
1783 } | |
1784 | |
1785 /* | |
1786 * Toggle fullscreen mode | |
1787 */ | |
1788 int SDL_WM_ToggleFullScreen(SDL_Surface *surface) | |
1789 { | |
1790 SDL_VideoDevice *video = current_video; | |
1791 SDL_VideoDevice *this = current_video; | |
1792 int toggled; | |
1793 | |
1794 toggled = 0; | |
1795 if ( SDL_PublicSurface && (surface == SDL_PublicSurface) && | |
1796 video->ToggleFullScreen ) { | |
1797 if ( surface->flags & SDL_FULLSCREEN ) { | |
1798 toggled = video->ToggleFullScreen(this, 0); | |
1799 if ( toggled ) { | |
1800 SDL_VideoSurface->flags &= ~SDL_FULLSCREEN; | |
1801 SDL_PublicSurface->flags &= ~SDL_FULLSCREEN; | |
1802 } | |
1803 } else { | |
1804 toggled = video->ToggleFullScreen(this, 1); | |
1805 if ( toggled ) { | |
1806 SDL_VideoSurface->flags |= SDL_FULLSCREEN; | |
1807 SDL_PublicSurface->flags |= SDL_FULLSCREEN; | |
1808 } | |
1809 } | |
1810 /* Double-check the grab state inside SDL_WM_GrabInput() */ | |
1811 if ( toggled ) { | |
1812 SDL_WM_GrabInput(video->input_grab); | |
1813 } | |
1814 } | |
1815 return(toggled); | |
1816 } | |
1817 | |
1818 /* | |
1819 * Get some platform dependent window manager information | |
1820 */ | |
1821 int SDL_GetWMInfo (SDL_SysWMinfo *info) | |
1822 { | |
1823 SDL_VideoDevice *video = current_video; | |
1824 SDL_VideoDevice *this = current_video; | |
1825 | |
1826 if ( video && video->GetWMInfo ) { | |
1827 return(video->GetWMInfo(this, info)); | |
1828 } else { | |
1829 return(0); | |
1830 } | |
1831 } |