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