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