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