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