author | Sam Lantinga <slouken@libsdl.org> |
Tue, 24 Feb 2004 07:42:19 +0000 | |
changeset 853 | dddfc37e1f65 |
parent 769 | b8d311d90021 |
child 883 | 50f5a29c6a17 |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
SDL - Simple DirectMedia Layer |
|
769
b8d311d90021
Updated copyright information for 2004 (Happy New Year!)
Sam Lantinga <slouken@libsdl.org>
parents:
663
diff
changeset
|
3 |
Copyright (C) 1997-2004 Sam Lantinga |
0 | 4 |
|
5 |
This library is free software; you can redistribute it and/or |
|
6 |
modify it under the terms of the GNU Library General Public |
|
7 |
License as published by the Free Software Foundation; either |
|
8 |
version 2 of the License, or (at your option) any later version. |
|
9 |
||
10 |
This library is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 |
Library General Public License for more details. |
|
14 |
||
15 |
You should have received a copy of the GNU Library General Public |
|
16 |
License along with this library; if not, write to the Free |
|
17 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 |
||
19 |
Sam Lantinga |
|
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
229
diff
changeset
|
20 |
slouken@libsdl.org |
0 | 21 |
*/ |
22 |
||
23 |
#ifdef SAVE_RCSID |
|
24 |
static char rcsid = |
|
25 |
"@(#) $Id$"; |
|
26 |
#endif |
|
27 |
||
28 |
/* The high-level video driver subsystem */ |
|
29 |
||
30 |
#include <stdio.h> |
|
31 |
#include <stdlib.h> |
|
32 |
#include <string.h> |
|
33 |
||
34 |
#include "SDL.h" |
|
35 |
#include "SDL_error.h" |
|
36 |
#include "SDL_video.h" |
|
37 |
#include "SDL_events.h" |
|
38 |
#include "SDL_mutex.h" |
|
39 |
#include "SDL_sysvideo.h" |
|
40 |
#include "SDL_sysevents.h" |
|
41 |
#include "SDL_blit.h" |
|
42 |
#include "SDL_pixels_c.h" |
|
43 |
#include "SDL_events_c.h" |
|
44 |
#include "SDL_cursor_c.h" |
|
45 |
||
46 |
/* Available video drivers */ |
|
47 |
static VideoBootStrap *bootstrap[] = { |
|
48 |
#ifdef ENABLE_X11 |
|
49 |
&X11_bootstrap, |
|
50 |
#endif |
|
51 |
#ifdef ENABLE_DGA |
|
52 |
&DGA_bootstrap, |
|
53 |
#endif |
|
30
57bf11a5efd7
Added initial support for Nano-X (thanks Hsieh-Fu!)
Sam Lantinga <slouken@lokigames.com>
parents:
19
diff
changeset
|
54 |
#ifdef ENABLE_NANOX |
57bf11a5efd7
Added initial support for Nano-X (thanks Hsieh-Fu!)
Sam Lantinga <slouken@lokigames.com>
parents:
19
diff
changeset
|
55 |
&NX_bootstrap, |
57bf11a5efd7
Added initial support for Nano-X (thanks Hsieh-Fu!)
Sam Lantinga <slouken@lokigames.com>
parents:
19
diff
changeset
|
56 |
#endif |
567 | 57 |
#ifdef ENABLE_QTOPIA |
58 |
&Qtopia_bootstrap, |
|
59 |
#endif |
|
0 | 60 |
#ifdef ENABLE_FBCON |
61 |
&FBCON_bootstrap, |
|
62 |
#endif |
|
167
cb384ef627f6
Added support for DirectFB video on Linux (thanks Denis!)
Sam Lantinga <slouken@libsdl.org>
parents:
125
diff
changeset
|
63 |
#ifdef ENABLE_DIRECTFB |
cb384ef627f6
Added support for DirectFB video on Linux (thanks Denis!)
Sam Lantinga <slouken@libsdl.org>
parents:
125
diff
changeset
|
64 |
&DirectFB_bootstrap, |
cb384ef627f6
Added support for DirectFB video on Linux (thanks Denis!)
Sam Lantinga <slouken@libsdl.org>
parents:
125
diff
changeset
|
65 |
#endif |
0 | 66 |
#ifdef ENABLE_PS2GS |
67 |
&PS2GS_bootstrap, |
|
68 |
#endif |
|
69 |
#ifdef ENABLE_GGI |
|
70 |
&GGI_bootstrap, |
|
71 |
#endif |
|
75
b0ae59d0f3ee
Added patches from FreeBSD ports
Sam Lantinga <slouken@lokigames.com>
parents:
58
diff
changeset
|
72 |
#ifdef ENABLE_VGL |
b0ae59d0f3ee
Added patches from FreeBSD ports
Sam Lantinga <slouken@lokigames.com>
parents:
58
diff
changeset
|
73 |
&VGL_bootstrap, |
b0ae59d0f3ee
Added patches from FreeBSD ports
Sam Lantinga <slouken@lokigames.com>
parents:
58
diff
changeset
|
74 |
#endif |
0 | 75 |
#ifdef ENABLE_SVGALIB |
76 |
&SVGALIB_bootstrap, |
|
77 |
#endif |
|
78 |
#ifdef ENABLE_AALIB |
|
610
95433459fbd2
Date: Mon, 14 Apr 2003 22:08:27 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
580
diff
changeset
|
79 |
&AALIB_bootstrap, |
0 | 80 |
#endif |
81 |
#ifdef ENABLE_DIRECTX |
|
82 |
&DIRECTX_bootstrap, |
|
83 |
#endif |
|
84 |
#ifdef ENABLE_WINDIB |
|
85 |
&WINDIB_bootstrap, |
|
86 |
#endif |
|
87 |
#ifdef ENABLE_BWINDOW |
|
88 |
&BWINDOW_bootstrap, |
|
89 |
#endif |
|
90 |
#ifdef ENABLE_TOOLBOX |
|
91 |
&TOOLBOX_bootstrap, |
|
92 |
#endif |
|
93 |
#ifdef ENABLE_DRAWSPROCKET |
|
94 |
&DSp_bootstrap, |
|
95 |
#endif |
|
47
45b1c4303f87
Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
34
diff
changeset
|
96 |
#ifdef ENABLE_QUARTZ |
45b1c4303f87
Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
34
diff
changeset
|
97 |
&QZ_bootstrap, |
45b1c4303f87
Added initial support for Quartz video (thanks Darrell!)
Sam Lantinga <slouken@lokigames.com>
parents:
34
diff
changeset
|
98 |
#endif |
0 | 99 |
#ifdef ENABLE_CYBERGRAPHICS |
100 |
&CGX_bootstrap, |
|
101 |
#endif |
|
173
83018110dce8
Added initial support for EPOC/Symbian OS (thanks Hannu!)
Sam Lantinga <slouken@libsdl.org>
parents:
167
diff
changeset
|
102 |
#ifdef ENABLE_PHOTON |
83018110dce8
Added initial support for EPOC/Symbian OS (thanks Hannu!)
Sam Lantinga <slouken@libsdl.org>
parents:
167
diff
changeset
|
103 |
&ph_bootstrap, |
83018110dce8
Added initial support for EPOC/Symbian OS (thanks Hannu!)
Sam Lantinga <slouken@libsdl.org>
parents:
167
diff
changeset
|
104 |
#endif |
83018110dce8
Added initial support for EPOC/Symbian OS (thanks Hannu!)
Sam Lantinga <slouken@libsdl.org>
parents:
167
diff
changeset
|
105 |
#ifdef ENABLE_EPOC |
83018110dce8
Added initial support for EPOC/Symbian OS (thanks Hannu!)
Sam Lantinga <slouken@libsdl.org>
parents:
167
diff
changeset
|
106 |
&EPOC_bootstrap, |
83018110dce8
Added initial support for EPOC/Symbian OS (thanks Hannu!)
Sam Lantinga <slouken@libsdl.org>
parents:
167
diff
changeset
|
107 |
#endif |
281
c5010ab8ba35
Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
108 |
#ifdef ENABLE_XBIOS |
c5010ab8ba35
Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
109 |
&XBIOS_bootstrap, |
c5010ab8ba35
Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
110 |
#endif |
c5010ab8ba35
Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
111 |
#ifdef ENABLE_GEM |
c5010ab8ba35
Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
112 |
&GEM_bootstrap, |
c5010ab8ba35
Added initial support for Atari (thanks Patrice!)
Sam Lantinga <slouken@libsdl.org>
parents:
266
diff
changeset
|
113 |
#endif |
433
706de3956894
Added initial support for PicoGUI (thanks Micah!)
Sam Lantinga <slouken@libsdl.org>
parents:
430
diff
changeset
|
114 |
#ifdef ENABLE_PICOGUI |
706de3956894
Added initial support for PicoGUI (thanks Micah!)
Sam Lantinga <slouken@libsdl.org>
parents:
430
diff
changeset
|
115 |
&PG_bootstrap, |
706de3956894
Added initial support for PicoGUI (thanks Micah!)
Sam Lantinga <slouken@libsdl.org>
parents:
430
diff
changeset
|
116 |
#endif |
509
dad72daf44b3
Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
488
diff
changeset
|
117 |
#ifdef ENABLE_DC |
dad72daf44b3
Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
488
diff
changeset
|
118 |
&DC_bootstrap, |
dad72daf44b3
Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
488
diff
changeset
|
119 |
#endif |
630
550bccdf04bd
Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
610
diff
changeset
|
120 |
#ifdef ENABLE_RISCOS |
550bccdf04bd
Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
610
diff
changeset
|
121 |
&RISCOS_bootstrap, |
550bccdf04bd
Added initial support for RISC OS (thanks Peter Naulls!)
Sam Lantinga <slouken@libsdl.org>
parents:
610
diff
changeset
|
122 |
#endif |
610
95433459fbd2
Date: Mon, 14 Apr 2003 22:08:27 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
580
diff
changeset
|
123 |
#ifdef ENABLE_DUMMYVIDEO |
95433459fbd2
Date: Mon, 14 Apr 2003 22:08:27 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
580
diff
changeset
|
124 |
&DUMMY_bootstrap, |
95433459fbd2
Date: Mon, 14 Apr 2003 22:08:27 +0100
Sam Lantinga <slouken@libsdl.org>
parents:
580
diff
changeset
|
125 |
#endif |
0 | 126 |
NULL |
127 |
}; |
|
173
83018110dce8
Added initial support for EPOC/Symbian OS (thanks Hannu!)
Sam Lantinga <slouken@libsdl.org>
parents:
167
diff
changeset
|
128 |
|
0 | 129 |
SDL_VideoDevice *current_video = NULL; |
130 |
||
131 |
/* Various local functions */ |
|
132 |
int SDL_VideoInit(const char *driver_name, Uint32 flags); |
|
133 |
void SDL_VideoQuit(void); |
|
134 |
void SDL_GL_UpdateRectsLock(SDL_VideoDevice* this, int numrects, SDL_Rect* rects); |
|
135 |
||
136 |
static SDL_GrabMode SDL_WM_GrabInputOff(void); |
|
137 |
#ifdef HAVE_OPENGL |
|
138 |
static int lock_count = 0; |
|
139 |
#endif |
|
140 |
||
141 |
||
142 |
/* |
|
143 |
* Initialize the video and event subsystems -- determine native pixel format |
|
144 |
*/ |
|
145 |
int SDL_VideoInit (const char *driver_name, Uint32 flags) |
|
146 |
{ |
|
147 |
SDL_VideoDevice *video; |
|
148 |
int index; |
|
149 |
int i; |
|
150 |
SDL_PixelFormat vformat; |
|
151 |
Uint32 video_flags; |
|
152 |
||
153 |
/* Toggle the event thread flags, based on OS requirements */ |
|
154 |
#if defined(MUST_THREAD_EVENTS) |
|
155 |
flags |= SDL_INIT_EVENTTHREAD; |
|
156 |
#elif defined(CANT_THREAD_EVENTS) |
|
157 |
if ( (flags & SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD ) { |
|
158 |
SDL_SetError("OS doesn't support threaded events"); |
|
159 |
return(-1); |
|
160 |
} |
|
161 |
#endif |
|
162 |
||
163 |
/* Check to make sure we don't overwrite 'current_video' */ |
|
164 |
if ( current_video != NULL ) { |
|
165 |
SDL_VideoQuit(); |
|
166 |
} |
|
167 |
||
168 |
/* Select the proper video driver */ |
|
169 |
index = 0; |
|
170 |
video = NULL; |
|
171 |
if ( driver_name != NULL ) { |
|
172 |
#if 0 /* This will be replaced with a better driver selection API */ |
|
173 |
if ( strrchr(driver_name, ':') != NULL ) { |
|
174 |
index = atoi(strrchr(driver_name, ':')+1); |
|
175 |
} |
|
176 |
#endif |
|
177 |
for ( i=0; bootstrap[i]; ++i ) { |
|
178 |
if ( strncmp(bootstrap[i]->name, driver_name, |
|
179 |
strlen(bootstrap[i]->name)) == 0 ) { |
|
180 |
if ( bootstrap[i]->available() ) { |
|
181 |
video = bootstrap[i]->create(index); |
|
182 |
break; |
|
183 |
} |
|
184 |
} |
|
185 |
} |
|
186 |
} else { |
|
187 |
for ( i=0; bootstrap[i]; ++i ) { |
|
188 |
if ( bootstrap[i]->available() ) { |
|
189 |
video = bootstrap[i]->create(index); |
|
190 |
if ( video != NULL ) { |
|
191 |
break; |
|
192 |
} |
|
193 |
} |
|
194 |
} |
|
195 |
} |
|
196 |
if ( video == NULL ) { |
|
197 |
SDL_SetError("No available video device"); |
|
198 |
return(-1); |
|
199 |
} |
|
200 |
current_video = video; |
|
201 |
current_video->name = bootstrap[i]->name; |
|
202 |
||
203 |
/* Do some basic variable initialization */ |
|
204 |
video->screen = NULL; |
|
205 |
video->shadow = NULL; |
|
206 |
video->visible = NULL; |
|
207 |
video->physpal = NULL; |
|
208 |
video->gammacols = NULL; |
|
209 |
video->gamma = NULL; |
|
210 |
video->wm_title = NULL; |
|
211 |
video->wm_icon = NULL; |
|
212 |
video->offset_x = 0; |
|
213 |
video->offset_y = 0; |
|
214 |
memset(&video->info, 0, (sizeof video->info)); |
|
215 |
||
216 |
/* Set some very sane GL defaults */ |
|
217 |
video->gl_config.driver_loaded = 0; |
|
218 |
video->gl_config.dll_handle = NULL; |
|
219 |
video->gl_config.red_size = 5; |
|
220 |
#if 1 /* This seems to work on more video cards, as a default */ |
|
221 |
video->gl_config.green_size = 5; |
|
222 |
#else |
|
223 |
video->gl_config.green_size = 6; |
|
224 |
#endif |
|
225 |
video->gl_config.blue_size = 5; |
|
226 |
video->gl_config.alpha_size = 0; |
|
227 |
video->gl_config.buffer_size = 0; |
|
228 |
video->gl_config.depth_size = 16; |
|
229 |
video->gl_config.stencil_size = 0; |
|
230 |
video->gl_config.double_buffer = 1; |
|
231 |
video->gl_config.accum_red_size = 0; |
|
232 |
video->gl_config.accum_green_size = 0; |
|
233 |
video->gl_config.accum_blue_size = 0; |
|
234 |
video->gl_config.accum_alpha_size = 0; |
|
450
8a43e0cbf02f
Added SDL_GL_STEREO for stereoscopic OpenGL contexts
Sam Lantinga <slouken@libsdl.org>
parents:
433
diff
changeset
|
235 |
video->gl_config.stereo = 0; |
656
864e2d2a9a55
Merged in Ryan's multisample code for MacOS, and changed the constants to match.
Sam Lantinga <slouken@libsdl.org>
parents:
655
diff
changeset
|
236 |
video->gl_config.multisamplebuffers = 0; |
864e2d2a9a55
Merged in Ryan's multisample code for MacOS, and changed the constants to match.
Sam Lantinga <slouken@libsdl.org>
parents:
655
diff
changeset
|
237 |
video->gl_config.multisamplesamples = 0; |
0 | 238 |
|
239 |
/* Initialize the video subsystem */ |
|
240 |
memset(&vformat, 0, sizeof(vformat)); |
|
241 |
if ( video->VideoInit(video, &vformat) < 0 ) { |
|
242 |
SDL_VideoQuit(); |
|
243 |
return(-1); |
|
244 |
} |
|
245 |
||
246 |
/* Create a zero sized video surface of the appropriate format */ |
|
247 |
video_flags = SDL_SWSURFACE; |
|
248 |
SDL_VideoSurface = SDL_CreateRGBSurface(video_flags, 0, 0, |
|
249 |
vformat.BitsPerPixel, |
|
250 |
vformat.Rmask, vformat.Gmask, vformat.Bmask, 0); |
|
251 |
if ( SDL_VideoSurface == NULL ) { |
|
252 |
SDL_VideoQuit(); |
|
253 |
return(-1); |
|
254 |
} |
|
255 |
SDL_PublicSurface = NULL; /* Until SDL_SetVideoMode() */ |
|
256 |
||
257 |
#if 0 /* Don't change the current palette - may be used by other programs. |
|
258 |
* The application can't do anything with the display surface until |
|
259 |
* a video mode has been set anyway. :) |
|
260 |
*/ |
|
261 |
/* If we have a palettized surface, create a default palette */ |
|
262 |
if ( SDL_VideoSurface->format->palette ) { |
|
662
66c02f83f5bf
Date: Sun, 27 Jul 2003 22:37:59 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
656
diff
changeset
|
263 |
SDL_PixelFormat *vf = SDL_VideoSurface->format; |
0 | 264 |
SDL_DitherColors(vf->palette->colors, vf->BitsPerPixel); |
265 |
video->SetColors(video, |
|
266 |
0, vf->palette->ncolors, vf->palette->colors); |
|
267 |
} |
|
268 |
#endif |
|
269 |
video->info.vfmt = SDL_VideoSurface->format; |
|
270 |
||
271 |
/* Start the event loop */ |
|
272 |
if ( SDL_StartEventLoop(flags) < 0 ) { |
|
273 |
SDL_VideoQuit(); |
|
274 |
return(-1); |
|
275 |
} |
|
276 |
SDL_CursorInit(flags & SDL_INIT_EVENTTHREAD); |
|
277 |
||
278 |
/* We're ready to go! */ |
|
279 |
return(0); |
|
280 |
} |
|
281 |
||
282 |
char *SDL_VideoDriverName(char *namebuf, int maxlen) |
|
283 |
{ |
|
284 |
if ( current_video != NULL ) { |
|
285 |
strncpy(namebuf, current_video->name, maxlen-1); |
|
286 |
namebuf[maxlen-1] = '\0'; |
|
287 |
return(namebuf); |
|
288 |
} |
|
289 |
return(NULL); |
|
290 |
} |
|
291 |
||
292 |
/* |
|
293 |
* Get the current display surface |
|
294 |
*/ |
|
295 |
SDL_Surface *SDL_GetVideoSurface(void) |
|
296 |
{ |
|
297 |
SDL_Surface *visible; |
|
298 |
||
299 |
visible = NULL; |
|
300 |
if ( current_video ) { |
|
301 |
visible = current_video->visible; |
|
302 |
} |
|
303 |
return(visible); |
|
304 |
} |
|
305 |
||
306 |
/* |
|
307 |
* Get the current information about the video hardware |
|
308 |
*/ |
|
309 |
const SDL_VideoInfo *SDL_GetVideoInfo(void) |
|
310 |
{ |
|
311 |
const SDL_VideoInfo *info; |
|
312 |
||
313 |
info = NULL; |
|
314 |
if ( current_video ) { |
|
315 |
info = ¤t_video->info; |
|
316 |
} |
|
317 |
return(info); |
|
318 |
} |
|
319 |
||
320 |
/* |
|
321 |
* Return a pointer to an array of available screen dimensions for the |
|
322 |
* given format, sorted largest to smallest. Returns NULL if there are |
|
323 |
* no dimensions available for a particular format, or (SDL_Rect **)-1 |
|
324 |
* if any dimension is okay for the given format. If 'format' is NULL, |
|
325 |
* the mode list will be for the format given by SDL_GetVideoInfo()->vfmt |
|
326 |
*/ |
|
327 |
SDL_Rect ** SDL_ListModes (SDL_PixelFormat *format, Uint32 flags) |
|
328 |
{ |
|
329 |
SDL_VideoDevice *video = current_video; |
|
330 |
SDL_VideoDevice *this = current_video; |
|
331 |
SDL_Rect **modes; |
|
332 |
||
333 |
modes = NULL; |
|
334 |
if ( SDL_VideoSurface ) { |
|
335 |
if ( format == NULL ) { |
|
336 |
format = SDL_VideoSurface->format; |
|
337 |
} |
|
338 |
modes = video->ListModes(this, format, flags); |
|
339 |
} |
|
340 |
return(modes); |
|
341 |
} |
|
342 |
||
343 |
/* |
|
344 |
* Check to see if a particular video mode is supported. |
|
345 |
* It returns 0 if the requested mode is not supported under any bit depth, |
|
346 |
* or returns the bits-per-pixel of the closest available mode with the |
|
347 |
* given width and height. If this bits-per-pixel is different from the |
|
348 |
* one used when setting the video mode, SDL_SetVideoMode() will succeed, |
|
349 |
* but will emulate the requested bits-per-pixel with a shadow surface. |
|
350 |
*/ |
|
351 |
static Uint8 SDL_closest_depths[4][8] = { |
|
352 |
/* 8 bit closest depth ordering */ |
|
353 |
{ 0, 8, 16, 15, 32, 24, 0, 0 }, |
|
354 |
/* 15,16 bit closest depth ordering */ |
|
355 |
{ 0, 16, 15, 32, 24, 8, 0, 0 }, |
|
356 |
/* 24 bit closest depth ordering */ |
|
357 |
{ 0, 24, 32, 16, 15, 8, 0, 0 }, |
|
358 |
/* 32 bit closest depth ordering */ |
|
359 |
{ 0, 32, 16, 15, 24, 8, 0, 0 } |
|
360 |
}; |
|
361 |
||
853
dddfc37e1f65
Don't allow video modes larger than the maximum size
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
362 |
|
dddfc37e1f65
Don't allow video modes larger than the maximum size
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
363 |
#ifdef macintosh /* MPW optimization bug? */ |
dddfc37e1f65
Don't allow video modes larger than the maximum size
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
364 |
#define NEGATIVE_ONE 0xFFFFFFFF |
dddfc37e1f65
Don't allow video modes larger than the maximum size
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
365 |
#else |
dddfc37e1f65
Don't allow video modes larger than the maximum size
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
366 |
#define NEGATIVE_ONE -1 |
dddfc37e1f65
Don't allow video modes larger than the maximum size
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
367 |
#endif |
dddfc37e1f65
Don't allow video modes larger than the maximum size
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
368 |
|
dddfc37e1f65
Don't allow video modes larger than the maximum size
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
369 |
int SDL_VideoModeOK (int width, int height, int bpp, Uint32 flags) |
0 | 370 |
{ |
371 |
int table, b, i; |
|
372 |
int supported; |
|
373 |
SDL_PixelFormat format; |
|
374 |
SDL_Rect **sizes; |
|
375 |
||
376 |
/* Currently 1 and 4 bpp are not supported */ |
|
377 |
if ( bpp < 8 || bpp > 32 ) { |
|
378 |
return(0); |
|
379 |
} |
|
456
b4e14b15af3c
Fixed crash with invalid bpp in SDL_SetVideoMode()
Sam Lantinga <slouken@libsdl.org>
parents:
450
diff
changeset
|
380 |
if ( (width <= 0) || (height <= 0) ) { |
0 | 381 |
return(0); |
382 |
} |
|
383 |
||
384 |
/* Search through the list valid of modes */ |
|
385 |
memset(&format, 0, sizeof(format)); |
|
386 |
supported = 0; |
|
387 |
table = ((bpp+7)/8)-1; |
|
388 |
SDL_closest_depths[table][0] = bpp; |
|
389 |
SDL_closest_depths[table][7] = 0; |
|
390 |
for ( b = 0; !supported && SDL_closest_depths[table][b]; ++b ) { |
|
391 |
format.BitsPerPixel = SDL_closest_depths[table][b]; |
|
392 |
sizes = SDL_ListModes(&format, flags); |
|
393 |
if ( sizes == (SDL_Rect **)0 ) { |
|
394 |
/* No sizes supported at this bit-depth */ |
|
395 |
continue; |
|
396 |
} else |
|
853
dddfc37e1f65
Don't allow video modes larger than the maximum size
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
397 |
if (sizes == (SDL_Rect **)NEGATIVE_ONE) { |
0 | 398 |
/* Any size supported at this bit-depth */ |
399 |
supported = 1; |
|
400 |
continue; |
|
853
dddfc37e1f65
Don't allow video modes larger than the maximum size
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
401 |
} else if (current_video->handles_any_size) { |
dddfc37e1f65
Don't allow video modes larger than the maximum size
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
402 |
/* Driver can center a smaller surface to simulate fullscreen */ |
dddfc37e1f65
Don't allow video modes larger than the maximum size
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
403 |
for ( i=0; sizes[i]; ++i ) { |
dddfc37e1f65
Don't allow video modes larger than the maximum size
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
404 |
if ((sizes[i]->w >= width) && (sizes[i]->h >= height)) { |
dddfc37e1f65
Don't allow video modes larger than the maximum size
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
405 |
supported = 1; /* this mode can fit the centered window. */ |
dddfc37e1f65
Don't allow video modes larger than the maximum size
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
406 |
break; |
dddfc37e1f65
Don't allow video modes larger than the maximum size
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
407 |
} |
dddfc37e1f65
Don't allow video modes larger than the maximum size
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
408 |
} |
0 | 409 |
} else |
410 |
for ( i=0; sizes[i]; ++i ) { |
|
411 |
if ((sizes[i]->w == width) && (sizes[i]->h == height)) { |
|
412 |
supported = 1; |
|
413 |
break; |
|
414 |
} |
|
415 |
} |
|
416 |
} |
|
417 |
if ( supported ) { |
|
418 |
--b; |
|
419 |
return(SDL_closest_depths[table][b]); |
|
420 |
} else { |
|
421 |
return(0); |
|
422 |
} |
|
423 |
} |
|
424 |
||
425 |
/* |
|
426 |
* Get the closest non-emulated video mode to the one requested |
|
427 |
*/ |
|
428 |
static int SDL_GetVideoMode (int *w, int *h, int *BitsPerPixel, Uint32 flags) |
|
429 |
{ |
|
430 |
int table, b, i; |
|
431 |
int supported; |
|
432 |
int native_bpp; |
|
433 |
SDL_PixelFormat format; |
|
434 |
SDL_Rect **sizes; |
|
435 |
||
456
b4e14b15af3c
Fixed crash with invalid bpp in SDL_SetVideoMode()
Sam Lantinga <slouken@libsdl.org>
parents:
450
diff
changeset
|
436 |
/* Check parameters */ |
b4e14b15af3c
Fixed crash with invalid bpp in SDL_SetVideoMode()
Sam Lantinga <slouken@libsdl.org>
parents:
450
diff
changeset
|
437 |
if ( *BitsPerPixel < 8 || *BitsPerPixel > 32 ) { |
b4e14b15af3c
Fixed crash with invalid bpp in SDL_SetVideoMode()
Sam Lantinga <slouken@libsdl.org>
parents:
450
diff
changeset
|
438 |
SDL_SetError("Invalid bits per pixel (range is {8...32})"); |
b4e14b15af3c
Fixed crash with invalid bpp in SDL_SetVideoMode()
Sam Lantinga <slouken@libsdl.org>
parents:
450
diff
changeset
|
439 |
return(0); |
b4e14b15af3c
Fixed crash with invalid bpp in SDL_SetVideoMode()
Sam Lantinga <slouken@libsdl.org>
parents:
450
diff
changeset
|
440 |
} |
430
60effdbf14ee
Make sure width and height passed to SDL_GetVideoMode() are sane.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
441 |
if ((*w <= 0) || (*h <= 0)) { |
456
b4e14b15af3c
Fixed crash with invalid bpp in SDL_SetVideoMode()
Sam Lantinga <slouken@libsdl.org>
parents:
450
diff
changeset
|
442 |
SDL_SetError("Invalid width or height"); |
430
60effdbf14ee
Make sure width and height passed to SDL_GetVideoMode() are sane.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
443 |
return(0); |
60effdbf14ee
Make sure width and height passed to SDL_GetVideoMode() are sane.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
444 |
} |
60effdbf14ee
Make sure width and height passed to SDL_GetVideoMode() are sane.
Ryan C. Gordon <icculus@icculus.org>
parents:
423
diff
changeset
|
445 |
|
0 | 446 |
/* Try the original video mode, get the closest depth */ |
447 |
native_bpp = SDL_VideoModeOK(*w, *h, *BitsPerPixel, flags); |
|
448 |
if ( native_bpp == *BitsPerPixel ) { |
|
449 |
return(1); |
|
450 |
} |
|
451 |
if ( native_bpp > 0 ) { |
|
452 |
*BitsPerPixel = native_bpp; |
|
453 |
return(1); |
|
454 |
} |
|
455 |
||
456 |
/* No exact size match at any depth, look for closest match */ |
|
457 |
memset(&format, 0, sizeof(format)); |
|
458 |
supported = 0; |
|
459 |
table = ((*BitsPerPixel+7)/8)-1; |
|
460 |
SDL_closest_depths[table][0] = *BitsPerPixel; |
|
461 |
SDL_closest_depths[table][7] = SDL_VideoSurface->format->BitsPerPixel; |
|
462 |
for ( b = 0; !supported && SDL_closest_depths[table][b]; ++b ) { |
|
463 |
format.BitsPerPixel = SDL_closest_depths[table][b]; |
|
464 |
sizes = SDL_ListModes(&format, flags); |
|
465 |
if ( sizes == (SDL_Rect **)0 ) { |
|
466 |
/* No sizes supported at this bit-depth */ |
|
467 |
continue; |
|
468 |
} |
|
469 |
for ( i=0; sizes[i]; ++i ) { |
|
470 |
if ((sizes[i]->w < *w) || (sizes[i]->h < *h)) { |
|
471 |
if ( i > 0 ) { |
|
472 |
--i; |
|
473 |
*w = sizes[i]->w; |
|
474 |
*h = sizes[i]->h; |
|
475 |
*BitsPerPixel = SDL_closest_depths[table][b]; |
|
476 |
supported = 1; |
|
477 |
} else { |
|
478 |
/* Largest mode too small... */; |
|
479 |
} |
|
480 |
break; |
|
481 |
} |
|
482 |
} |
|
483 |
if ( (i > 0) && ! sizes[i] ) { |
|
484 |
/* The smallest mode was larger than requested, OK */ |
|
485 |
--i; |
|
486 |
*w = sizes[i]->w; |
|
487 |
*h = sizes[i]->h; |
|
488 |
*BitsPerPixel = SDL_closest_depths[table][b]; |
|
489 |
supported = 1; |
|
490 |
} |
|
491 |
} |
|
492 |
if ( ! supported ) { |
|
493 |
SDL_SetError("No video mode large enough for %dx%d", *w, *h); |
|
494 |
} |
|
495 |
return(supported); |
|
496 |
} |
|
497 |
||
498 |
/* This should probably go somewhere else -- like SDL_surface.c */ |
|
499 |
static void SDL_ClearSurface(SDL_Surface *surface) |
|
500 |
{ |
|
501 |
Uint32 black; |
|
502 |
||
503 |
black = SDL_MapRGB(surface->format, 0, 0, 0); |
|
504 |
SDL_FillRect(surface, NULL, black); |
|
505 |
if ((surface->flags&SDL_HWSURFACE) && (surface->flags&SDL_DOUBLEBUF)) { |
|
506 |
SDL_Flip(surface); |
|
507 |
SDL_FillRect(surface, NULL, black); |
|
508 |
} |
|
509 |
SDL_Flip(surface); |
|
510 |
} |
|
511 |
||
512 |
/* |
|
513 |
* Create a shadow surface suitable for fooling the app. :-) |
|
514 |
*/ |
|
515 |
static void SDL_CreateShadowSurface(int depth) |
|
516 |
{ |
|
517 |
Uint32 Rmask, Gmask, Bmask; |
|
518 |
||
519 |
/* Allocate the shadow surface */ |
|
520 |
if ( depth == (SDL_VideoSurface->format)->BitsPerPixel ) { |
|
521 |
Rmask = (SDL_VideoSurface->format)->Rmask; |
|
522 |
Gmask = (SDL_VideoSurface->format)->Gmask; |
|
523 |
Bmask = (SDL_VideoSurface->format)->Bmask; |
|
524 |
} else { |
|
525 |
Rmask = Gmask = Bmask = 0; |
|
526 |
} |
|
527 |
SDL_ShadowSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, |
|
528 |
SDL_VideoSurface->w, SDL_VideoSurface->h, |
|
529 |
depth, Rmask, Gmask, Bmask, 0); |
|
530 |
if ( SDL_ShadowSurface == NULL ) { |
|
531 |
return; |
|
532 |
} |
|
533 |
||
534 |
/* 8-bit shadow surfaces report that they have exclusive palette */ |
|
535 |
if ( SDL_ShadowSurface->format->palette ) { |
|
536 |
SDL_ShadowSurface->flags |= SDL_HWPALETTE; |
|
537 |
if ( depth == (SDL_VideoSurface->format)->BitsPerPixel ) { |
|
538 |
memcpy(SDL_ShadowSurface->format->palette->colors, |
|
539 |
SDL_VideoSurface->format->palette->colors, |
|
540 |
SDL_VideoSurface->format->palette->ncolors* |
|
541 |
sizeof(SDL_Color)); |
|
542 |
} else { |
|
543 |
SDL_DitherColors( |
|
544 |
SDL_ShadowSurface->format->palette->colors, depth); |
|
545 |
} |
|
546 |
} |
|
547 |
||
548 |
/* If the video surface is resizable, the shadow should say so */ |
|
549 |
if ( (SDL_VideoSurface->flags & SDL_RESIZABLE) == SDL_RESIZABLE ) { |
|
550 |
SDL_ShadowSurface->flags |= SDL_RESIZABLE; |
|
551 |
} |
|
552 |
/* If the video surface has no frame, the shadow should say so */ |
|
553 |
if ( (SDL_VideoSurface->flags & SDL_NOFRAME) == SDL_NOFRAME ) { |
|
554 |
SDL_ShadowSurface->flags |= SDL_NOFRAME; |
|
555 |
} |
|
556 |
/* If the video surface is fullscreen, the shadow should say so */ |
|
557 |
if ( (SDL_VideoSurface->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN ) { |
|
558 |
SDL_ShadowSurface->flags |= SDL_FULLSCREEN; |
|
559 |
} |
|
560 |
/* If the video surface is flippable, the shadow should say so */ |
|
561 |
if ( (SDL_VideoSurface->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) { |
|
562 |
SDL_ShadowSurface->flags |= SDL_DOUBLEBUF; |
|
563 |
} |
|
564 |
return; |
|
565 |
} |
|
566 |
||
567 |
/* |
|
568 |
* Set the requested video mode, allocating a shadow buffer if necessary. |
|
569 |
*/ |
|
570 |
SDL_Surface * SDL_SetVideoMode (int width, int height, int bpp, Uint32 flags) |
|
571 |
{ |
|
572 |
SDL_VideoDevice *video, *this; |
|
573 |
SDL_Surface *prev_mode, *mode; |
|
574 |
int video_w; |
|
575 |
int video_h; |
|
576 |
int video_bpp; |
|
577 |
int is_opengl; |
|
578 |
SDL_GrabMode saved_grab; |
|
579 |
||
580 |
/* Start up the video driver, if necessary.. |
|
581 |
WARNING: This is the only function protected this way! |
|
582 |
*/ |
|
583 |
if ( ! current_video ) { |
|
584 |
if ( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE) < 0 ) { |
|
585 |
return(NULL); |
|
586 |
} |
|
587 |
} |
|
588 |
this = video = current_video; |
|
589 |
||
590 |
/* Default to the current video bpp */ |
|
591 |
if ( bpp == 0 ) { |
|
592 |
flags |= SDL_ANYFORMAT; |
|
593 |
bpp = SDL_VideoSurface->format->BitsPerPixel; |
|
594 |
} |
|
595 |
||
596 |
/* Get a good video mode, the closest one possible */ |
|
597 |
video_w = width; |
|
598 |
video_h = height; |
|
599 |
video_bpp = bpp; |
|
600 |
if ( ! SDL_GetVideoMode(&video_w, &video_h, &video_bpp, flags) ) { |
|
601 |
return(NULL); |
|
602 |
} |
|
603 |
||
604 |
/* Check the requested flags */ |
|
605 |
/* There's no palette in > 8 bits-per-pixel mode */ |
|
606 |
if ( video_bpp > 8 ) { |
|
607 |
flags &= ~SDL_HWPALETTE; |
|
608 |
} |
|
609 |
#if 0 |
|
610 |
if ( (flags&SDL_FULLSCREEN) != SDL_FULLSCREEN ) { |
|
611 |
/* There's no windowed double-buffering */ |
|
612 |
flags &= ~SDL_DOUBLEBUF; |
|
613 |
} |
|
614 |
#endif |
|
615 |
if ( (flags&SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) { |
|
616 |
/* Use hardware surfaces when double-buffering */ |
|
617 |
flags |= SDL_HWSURFACE; |
|
618 |
} |
|
619 |
||
620 |
is_opengl = ( ( flags & SDL_OPENGL ) == SDL_OPENGL ); |
|
621 |
if ( is_opengl ) { |
|
622 |
/* These flags are for 2D video modes only */ |
|
623 |
flags &= ~(SDL_HWSURFACE|SDL_DOUBLEBUF); |
|
624 |
} |
|
625 |
||
14
c3e9d4a623c1
Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents:
11
diff
changeset
|
626 |
/* 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
|
627 |
SDL_ResetKeyboard(); |
460
a888b3ae31ff
Reset mouse state when changing video modes
Sam Lantinga <slouken@libsdl.org>
parents:
456
diff
changeset
|
628 |
SDL_ResetMouse(); |
14
c3e9d4a623c1
Fixed stuck keys when changing the video mode
Sam Lantinga <slouken@lokigames.com>
parents:
11
diff
changeset
|
629 |
|
0 | 630 |
/* Clean up any previous video mode */ |
631 |
if ( SDL_PublicSurface != NULL ) { |
|
632 |
SDL_PublicSurface = NULL; |
|
633 |
} |
|
634 |
if ( SDL_ShadowSurface != NULL ) { |
|
635 |
SDL_Surface *ready_to_go; |
|
636 |
ready_to_go = SDL_ShadowSurface; |
|
637 |
SDL_ShadowSurface = NULL; |
|
638 |
SDL_FreeSurface(ready_to_go); |
|
639 |
} |
|
640 |
if ( video->physpal ) { |
|
641 |
free(video->physpal->colors); |
|
642 |
free(video->physpal); |
|
643 |
video->physpal = NULL; |
|
644 |
} |
|
645 |
if( video->gammacols) { |
|
662
66c02f83f5bf
Date: Sun, 27 Jul 2003 22:37:59 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
656
diff
changeset
|
646 |
free(video->gammacols); |
0 | 647 |
video->gammacols = NULL; |
648 |
} |
|
649 |
||
650 |
/* Save the previous grab state and turn off grab for mode switch */ |
|
651 |
saved_grab = SDL_WM_GrabInputOff(); |
|
652 |
||
653 |
/* Try to set the video mode, along with offset and clipping */ |
|
654 |
prev_mode = SDL_VideoSurface; |
|
655 |
SDL_LockCursor(); |
|
656 |
SDL_VideoSurface = NULL; /* In case it's freed by driver */ |
|
657 |
mode = video->SetVideoMode(this, prev_mode,video_w,video_h,video_bpp,flags); |
|
658 |
if ( mode ) { /* Prevent resize events from mode change */ |
|
659 |
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
|
660 |
|
4d24d5a660a8
Fix a crash if an OpenGL video mode can't be set.
Sam Lantinga <slouken@libsdl.org>
parents:
216
diff
changeset
|
661 |
/* 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
|
662 |
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
|
663 |
mode = NULL; |
4d24d5a660a8
Fix a crash if an OpenGL video mode can't be set.
Sam Lantinga <slouken@libsdl.org>
parents:
216
diff
changeset
|
664 |
} |
662
66c02f83f5bf
Date: Sun, 27 Jul 2003 22:37:59 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
656
diff
changeset
|
665 |
} |
0 | 666 |
/* |
667 |
* rcg11292000 |
|
668 |
* If you try to set an SDL_OPENGL surface, and fail to find a |
|
669 |
* matching visual, then the next call to SDL_SetVideoMode() |
|
670 |
* will segfault, since we no longer point to a dummy surface, |
|
671 |
* but rather NULL. |
|
672 |
* Sam 11/29/00 |
|
673 |
* WARNING, we need to make sure that the previous mode hasn't |
|
674 |
* already been freed by the video driver. What do we do in |
|
675 |
* that case? Should we call SDL_VideoInit() again? |
|
676 |
*/ |
|
677 |
SDL_VideoSurface = (mode != NULL) ? mode : prev_mode; |
|
678 |
||
679 |
if ( (mode != NULL) && (!is_opengl) ) { |
|
680 |
/* Sanity check */ |
|
681 |
if ( (mode->w < width) || (mode->h < height) ) { |
|
682 |
SDL_SetError("Video mode smaller than requested"); |
|
683 |
return(NULL); |
|
684 |
} |
|
685 |
||
686 |
/* If we have a palettized surface, create a default palette */ |
|
687 |
if ( mode->format->palette ) { |
|
662
66c02f83f5bf
Date: Sun, 27 Jul 2003 22:37:59 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
656
diff
changeset
|
688 |
SDL_PixelFormat *vf = mode->format; |
0 | 689 |
SDL_DitherColors(vf->palette->colors, vf->BitsPerPixel); |
690 |
video->SetColors(this, 0, vf->palette->ncolors, |
|
691 |
vf->palette->colors); |
|
692 |
} |
|
693 |
||
694 |
/* Clear the surface to black */ |
|
695 |
video->offset_x = 0; |
|
696 |
video->offset_y = 0; |
|
697 |
mode->offset = 0; |
|
698 |
SDL_SetClipRect(mode, NULL); |
|
699 |
SDL_ClearSurface(mode); |
|
700 |
||
701 |
/* Now adjust the offsets to match the desired mode */ |
|
702 |
video->offset_x = (mode->w-width)/2; |
|
703 |
video->offset_y = (mode->h-height)/2; |
|
704 |
mode->offset = video->offset_y*mode->pitch + |
|
705 |
video->offset_x*mode->format->BytesPerPixel; |
|
706 |
#ifdef DEBUG_VIDEO |
|
707 |
fprintf(stderr, |
|
708 |
"Requested mode: %dx%dx%d, obtained mode %dx%dx%d (offset %d)\n", |
|
709 |
width, height, bpp, |
|
710 |
mode->w, mode->h, mode->format->BitsPerPixel, mode->offset); |
|
711 |
#endif |
|
712 |
mode->w = width; |
|
713 |
mode->h = height; |
|
714 |
SDL_SetClipRect(mode, NULL); |
|
715 |
} |
|
716 |
SDL_ResetCursor(); |
|
717 |
SDL_UnlockCursor(); |
|
718 |
||
719 |
/* If we failed setting a video mode, return NULL... (Uh Oh!) */ |
|
720 |
if ( mode == NULL ) { |
|
721 |
return(NULL); |
|
722 |
} |
|
723 |
||
724 |
/* If there is no window manager, set the SDL_NOFRAME flag */ |
|
725 |
if ( ! video->info.wm_available ) { |
|
726 |
mode->flags |= SDL_NOFRAME; |
|
727 |
} |
|
728 |
||
729 |
/* Reset the mouse cursor and grab for new video mode */ |
|
730 |
SDL_SetCursor(NULL); |
|
731 |
if ( video->UpdateMouse ) { |
|
732 |
video->UpdateMouse(this); |
|
733 |
} |
|
734 |
SDL_WM_GrabInput(saved_grab); |
|
735 |
SDL_GetRelativeMouseState(NULL, NULL); /* Clear first large delta */ |
|
736 |
||
650
fe445b59d307
We need to lookup the address of glGetString before calling GL_MakeCurrent(),
Ryan C. Gordon <icculus@icculus.org>
parents:
630
diff
changeset
|
737 |
#ifdef HAVE_OPENGL |
fe445b59d307
We need to lookup the address of glGetString before calling GL_MakeCurrent(),
Ryan C. Gordon <icculus@icculus.org>
parents:
630
diff
changeset
|
738 |
/* Load GL symbols (before MakeCurrent, where we need glGetString). */ |
fe445b59d307
We need to lookup the address of glGetString before calling GL_MakeCurrent(),
Ryan C. Gordon <icculus@icculus.org>
parents:
630
diff
changeset
|
739 |
if ( flags & (SDL_OPENGL | SDL_OPENGLBLIT) ) { |
663
8bedd6d61642
Date: Sat, 2 Aug 2003 16:22:51 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
662
diff
changeset
|
740 |
#ifndef __QNXNTO__ |
650
fe445b59d307
We need to lookup the address of glGetString before calling GL_MakeCurrent(),
Ryan C. Gordon <icculus@icculus.org>
parents:
630
diff
changeset
|
741 |
#define SDL_PROC(ret,func,params) \ |
fe445b59d307
We need to lookup the address of glGetString before calling GL_MakeCurrent(),
Ryan C. Gordon <icculus@icculus.org>
parents:
630
diff
changeset
|
742 |
do { \ |
fe445b59d307
We need to lookup the address of glGetString before calling GL_MakeCurrent(),
Ryan C. Gordon <icculus@icculus.org>
parents:
630
diff
changeset
|
743 |
video->func = SDL_GL_GetProcAddress(#func); \ |
fe445b59d307
We need to lookup the address of glGetString before calling GL_MakeCurrent(),
Ryan C. Gordon <icculus@icculus.org>
parents:
630
diff
changeset
|
744 |
if ( ! video->func ) { \ |
fe445b59d307
We need to lookup the address of glGetString before calling GL_MakeCurrent(),
Ryan C. Gordon <icculus@icculus.org>
parents:
630
diff
changeset
|
745 |
SDL_SetError("Couldn't load GL function: %s\n", #func); \ |
fe445b59d307
We need to lookup the address of glGetString before calling GL_MakeCurrent(),
Ryan C. Gordon <icculus@icculus.org>
parents:
630
diff
changeset
|
746 |
return(NULL); \ |
fe445b59d307
We need to lookup the address of glGetString before calling GL_MakeCurrent(),
Ryan C. Gordon <icculus@icculus.org>
parents:
630
diff
changeset
|
747 |
} \ |
fe445b59d307
We need to lookup the address of glGetString before calling GL_MakeCurrent(),
Ryan C. Gordon <icculus@icculus.org>
parents:
630
diff
changeset
|
748 |
} while ( 0 ); |
663
8bedd6d61642
Date: Sat, 2 Aug 2003 16:22:51 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
662
diff
changeset
|
749 |
#else |
8bedd6d61642
Date: Sat, 2 Aug 2003 16:22:51 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
662
diff
changeset
|
750 |
#define SDL_PROC(ret,func,params) video->func=func; |
8bedd6d61642
Date: Sat, 2 Aug 2003 16:22:51 +0300
Sam Lantinga <slouken@libsdl.org>
parents:
662
diff
changeset
|
751 |
#endif /* __QNXNTO__ */ |
650
fe445b59d307
We need to lookup the address of glGetString before calling GL_MakeCurrent(),
Ryan C. Gordon <icculus@icculus.org>
parents:
630
diff
changeset
|
752 |
#include "SDL_glfuncs.h" |
fe445b59d307
We need to lookup the address of glGetString before calling GL_MakeCurrent(),
Ryan C. Gordon <icculus@icculus.org>
parents:
630
diff
changeset
|
753 |
#undef SDL_PROC |
fe445b59d307
We need to lookup the address of glGetString before calling GL_MakeCurrent(),
Ryan C. Gordon <icculus@icculus.org>
parents:
630
diff
changeset
|
754 |
} |
fe445b59d307
We need to lookup the address of glGetString before calling GL_MakeCurrent(),
Ryan C. Gordon <icculus@icculus.org>
parents:
630
diff
changeset
|
755 |
#endif |
fe445b59d307
We need to lookup the address of glGetString before calling GL_MakeCurrent(),
Ryan C. Gordon <icculus@icculus.org>
parents:
630
diff
changeset
|
756 |
|
0 | 757 |
/* If we're running OpenGL, make the context current */ |
758 |
if ( (video->screen->flags & SDL_OPENGL) && |
|
759 |
video->GL_MakeCurrent ) { |
|
760 |
if ( video->GL_MakeCurrent(this) < 0 ) { |
|
761 |
return(NULL); |
|
762 |
} |
|
763 |
} |
|
764 |
||
765 |
/* Set up a fake SDL surface for OpenGL "blitting" */ |
|
766 |
if ( (flags & SDL_OPENGLBLIT) == SDL_OPENGLBLIT ) { |
|
767 |
/* Load GL functions for performing the texture updates */ |
|
768 |
#ifdef HAVE_OPENGL |
|
769 |
||
770 |
/* Create a software surface for blitting */ |
|
771 |
#ifdef GL_VERSION_1_2 |
|
772 |
/* If the implementation either supports the packed pixels |
|
773 |
extension, or implements the core OpenGL 1.2 API, it will |
|
774 |
support the GL_UNSIGNED_SHORT_5_6_5 texture format. |
|
775 |
*/ |
|
776 |
if ( (bpp == 16) && |
|
282
b42d80e73896
Fixed SDL_OPENGLBLIT with OpenGL API newer than 1.2
Sam Lantinga <slouken@libsdl.org>
parents:
281
diff
changeset
|
777 |
(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
|
778 |
(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
|
779 |
) { |
0 | 780 |
video->is_32bit = 0; |
781 |
SDL_VideoSurface = SDL_CreateRGBSurface( |
|
782 |
flags, |
|
783 |
width, |
|
784 |
height, |
|
785 |
16, |
|
786 |
31 << 11, |
|
787 |
63 << 5, |
|
788 |
31, |
|
789 |
0 |
|
790 |
); |
|
791 |
} |
|
792 |
else |
|
793 |
#endif /* OpenGL 1.2 */ |
|
794 |
{ |
|
795 |
video->is_32bit = 1; |
|
796 |
SDL_VideoSurface = SDL_CreateRGBSurface( |
|
797 |
flags, |
|
798 |
width, |
|
799 |
height, |
|
800 |
32, |
|
801 |
#if SDL_BYTEORDER == SDL_LIL_ENDIAN |
|
802 |
0x000000FF, |
|
803 |
0x0000FF00, |
|
804 |
0x00FF0000, |
|
805 |
0xFF000000 |
|
806 |
#else |
|
807 |
0xFF000000, |
|
808 |
0x00FF0000, |
|
809 |
0x0000FF00, |
|
810 |
0x000000FF |
|
811 |
#endif |
|
812 |
); |
|
813 |
} |
|
814 |
if ( ! SDL_VideoSurface ) { |
|
815 |
return(NULL); |
|
816 |
} |
|
817 |
SDL_VideoSurface->flags = mode->flags | SDL_OPENGLBLIT; |
|
818 |
||
819 |
/* Free the original video mode surface (is this safe?) */ |
|
820 |
SDL_FreeSurface(mode); |
|
821 |
||
662
66c02f83f5bf
Date: Sun, 27 Jul 2003 22:37:59 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
656
diff
changeset
|
822 |
/* Set the surface completely opaque & white by default */ |
0 | 823 |
memset( SDL_VideoSurface->pixels, 255, SDL_VideoSurface->h * SDL_VideoSurface->pitch ); |
824 |
video->glGenTextures( 1, &video->texture ); |
|
825 |
video->glBindTexture( GL_TEXTURE_2D, video->texture ); |
|
826 |
video->glTexImage2D( |
|
827 |
GL_TEXTURE_2D, |
|
828 |
0, |
|
829 |
video->is_32bit ? GL_RGBA : GL_RGB, |
|
830 |
256, |
|
831 |
256, |
|
832 |
0, |
|
833 |
video->is_32bit ? GL_RGBA : GL_RGB, |
|
834 |
#ifdef GL_VERSION_1_2 |
|
835 |
video->is_32bit ? GL_UNSIGNED_BYTE : GL_UNSIGNED_SHORT_5_6_5, |
|
836 |
#else |
|
837 |
GL_UNSIGNED_BYTE, |
|
838 |
#endif |
|
839 |
NULL); |
|
840 |
||
841 |
video->UpdateRects = SDL_GL_UpdateRectsLock; |
|
842 |
#else |
|
843 |
SDL_SetError("Somebody forgot to #define HAVE_OPENGL"); |
|
844 |
return(NULL); |
|
845 |
#endif |
|
846 |
} |
|
847 |
||
848 |
/* Create a shadow surface if necessary */ |
|
849 |
/* There are three conditions under which we create a shadow surface: |
|
850 |
1. We need a particular bits-per-pixel that we didn't get. |
|
851 |
2. We need a hardware palette and didn't get one. |
|
852 |
3. We need a software surface and got a hardware surface. |
|
853 |
*/ |
|
854 |
if ( !(SDL_VideoSurface->flags & SDL_OPENGL) && |
|
855 |
( |
|
856 |
( !(flags&SDL_ANYFORMAT) && |
|
857 |
(SDL_VideoSurface->format->BitsPerPixel != bpp)) || |
|
858 |
( (flags&SDL_HWPALETTE) && |
|
859 |
!(SDL_VideoSurface->flags&SDL_HWPALETTE)) || |
|
860 |
/* If the surface is in hardware, video writes are visible |
|
861 |
as soon as they are performed, so we need to buffer them |
|
862 |
*/ |
|
863 |
( ((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
|
864 |
(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
|
865 |
( (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
|
866 |
(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
|
867 |
!(SDL_VideoSurface->flags&SDL_DOUBLEBUF)) |
0 | 868 |
) ) { |
869 |
SDL_CreateShadowSurface(bpp); |
|
870 |
if ( SDL_ShadowSurface == NULL ) { |
|
871 |
SDL_SetError("Couldn't create shadow surface"); |
|
872 |
return(NULL); |
|
873 |
} |
|
874 |
SDL_PublicSurface = SDL_ShadowSurface; |
|
875 |
} else { |
|
876 |
SDL_PublicSurface = SDL_VideoSurface; |
|
877 |
} |
|
878 |
video->info.vfmt = SDL_VideoSurface->format; |
|
879 |
||
880 |
/* We're done! */ |
|
881 |
return(SDL_PublicSurface); |
|
882 |
} |
|
883 |
||
884 |
/* |
|
885 |
* Convert a surface into the video pixel format. |
|
886 |
*/ |
|
887 |
SDL_Surface * SDL_DisplayFormat (SDL_Surface *surface) |
|
888 |
{ |
|
889 |
Uint32 flags; |
|
890 |
||
891 |
if ( ! SDL_PublicSurface ) { |
|
892 |
SDL_SetError("No video mode has been set"); |
|
893 |
return(NULL); |
|
894 |
} |
|
895 |
/* Set the flags appropriate for copying to display surface */ |
|
313
67ad846ed21c
*** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents:
306
diff
changeset
|
896 |
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
|
897 |
flags = SDL_HWSURFACE; |
3879bed3395c
Only put surfaces in video memory if there are accelerated blits
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
898 |
else |
3879bed3395c
Only put surfaces in video memory if there are accelerated blits
Sam Lantinga <slouken@libsdl.org>
parents:
297
diff
changeset
|
899 |
flags = SDL_SWSURFACE; |
0 | 900 |
#ifdef AUTORLE_DISPLAYFORMAT |
901 |
flags |= (surface->flags & (SDL_SRCCOLORKEY|SDL_SRCALPHA)); |
|
902 |
flags |= SDL_RLEACCELOK; |
|
903 |
#else |
|
904 |
flags |= surface->flags & (SDL_SRCCOLORKEY|SDL_SRCALPHA|SDL_RLEACCELOK); |
|
905 |
#endif |
|
906 |
return(SDL_ConvertSurface(surface, SDL_PublicSurface->format, flags)); |
|
907 |
} |
|
908 |
||
909 |
/* |
|
910 |
* Convert a surface into a format that's suitable for blitting to |
|
911 |
* the screen, but including an alpha channel. |
|
912 |
*/ |
|
913 |
SDL_Surface *SDL_DisplayFormatAlpha(SDL_Surface *surface) |
|
914 |
{ |
|
915 |
SDL_PixelFormat *vf; |
|
916 |
SDL_PixelFormat *format; |
|
917 |
SDL_Surface *converted; |
|
918 |
Uint32 flags; |
|
919 |
/* default to ARGB8888 */ |
|
920 |
Uint32 amask = 0xff000000; |
|
921 |
Uint32 rmask = 0x00ff0000; |
|
922 |
Uint32 gmask = 0x0000ff00; |
|
923 |
Uint32 bmask = 0x000000ff; |
|
924 |
||
925 |
if ( ! SDL_PublicSurface ) { |
|
926 |
SDL_SetError("No video mode has been set"); |
|
927 |
return(NULL); |
|
928 |
} |
|
929 |
vf = SDL_PublicSurface->format; |
|
930 |
||
931 |
switch(vf->BytesPerPixel) { |
|
932 |
case 2: |
|
933 |
/* For XGY5[56]5, use, AXGY8888, where {X, Y} = {R, B}. |
|
934 |
For anything else (like ARGB4444) it doesn't matter |
|
935 |
since we have no special code for it anyway */ |
|
936 |
if ( (vf->Rmask == 0x1f) && |
|
937 |
(vf->Bmask == 0xf800 || vf->Bmask == 0x7c00)) { |
|
938 |
rmask = 0xff; |
|
939 |
bmask = 0xff0000; |
|
940 |
} |
|
941 |
break; |
|
942 |
||
943 |
case 3: |
|
944 |
case 4: |
|
945 |
/* Keep the video format, as long as the high 8 bits are |
|
946 |
unused or alpha */ |
|
947 |
if ( (vf->Rmask == 0xff) && (vf->Bmask == 0xff0000) ) { |
|
948 |
rmask = 0xff; |
|
949 |
bmask = 0xff0000; |
|
950 |
} |
|
951 |
break; |
|
952 |
||
953 |
default: |
|
954 |
/* We have no other optimised formats right now. When/if a new |
|
955 |
optimised alpha format is written, add the converter here */ |
|
956 |
break; |
|
957 |
} |
|
958 |
format = SDL_AllocFormat(32, rmask, gmask, bmask, amask); |
|
959 |
flags = SDL_PublicSurface->flags & SDL_HWSURFACE; |
|
960 |
flags |= surface->flags & (SDL_SRCALPHA | SDL_RLEACCELOK); |
|
961 |
converted = SDL_ConvertSurface(surface, format, flags); |
|
962 |
SDL_FreeFormat(format); |
|
963 |
return(converted); |
|
964 |
} |
|
965 |
||
966 |
/* |
|
967 |
* Update a specific portion of the physical screen |
|
968 |
*/ |
|
969 |
void SDL_UpdateRect(SDL_Surface *screen, Sint32 x, Sint32 y, Uint32 w, Uint32 h) |
|
970 |
{ |
|
971 |
if ( screen ) { |
|
972 |
SDL_Rect rect; |
|
973 |
||
974 |
/* Perform some checking */ |
|
975 |
if ( w == 0 ) |
|
976 |
w = screen->w; |
|
977 |
if ( h == 0 ) |
|
978 |
h = screen->h; |
|
979 |
if ( (int)(x+w) > screen->w ) |
|
980 |
return; |
|
981 |
if ( (int)(y+h) > screen->h ) |
|
982 |
return; |
|
983 |
||
984 |
/* Fill the rectangle */ |
|
985 |
rect.x = x; |
|
986 |
rect.y = y; |
|
987 |
rect.w = w; |
|
988 |
rect.h = h; |
|
989 |
SDL_UpdateRects(screen, 1, &rect); |
|
990 |
} |
|
991 |
} |
|
992 |
void SDL_UpdateRects (SDL_Surface *screen, int numrects, SDL_Rect *rects) |
|
993 |
{ |
|
994 |
int i; |
|
995 |
SDL_VideoDevice *video = current_video; |
|
996 |
SDL_VideoDevice *this = current_video; |
|
997 |
||
998 |
if ( screen == SDL_ShadowSurface ) { |
|
999 |
/* 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
|
1000 |
SDL_Palette *pal = screen->format->palette; |
0 | 1001 |
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
|
1002 |
if ( pal && !(SDL_VideoSurface->flags & SDL_HWPALETTE) ) { |
0 | 1003 |
/* simulated 8bpp, use correct physical palette */ |
1004 |
saved_colors = pal->colors; |
|
1005 |
if ( video->gammacols ) { |
|
1006 |
/* gamma-corrected palette */ |
|
1007 |
pal->colors = video->gammacols; |
|
1008 |
} else if ( video->physpal ) { |
|
1009 |
/* physical palette different from logical */ |
|
1010 |
pal->colors = video->physpal->colors; |
|
1011 |
} |
|
1012 |
} |
|
1013 |
if ( SHOULD_DRAWCURSOR(SDL_cursorstate) ) { |
|
1014 |
SDL_LockCursor(); |
|
1015 |
SDL_DrawCursor(SDL_ShadowSurface); |
|
1016 |
for ( i=0; i<numrects; ++i ) { |
|
1017 |
SDL_LowerBlit(SDL_ShadowSurface, &rects[i], |
|
1018 |
SDL_VideoSurface, &rects[i]); |
|
1019 |
} |
|
1020 |
SDL_EraseCursor(SDL_ShadowSurface); |
|
1021 |
SDL_UnlockCursor(); |
|
1022 |
} else { |
|
1023 |
for ( i=0; i<numrects; ++i ) { |
|
1024 |
SDL_LowerBlit(SDL_ShadowSurface, &rects[i], |
|
1025 |
SDL_VideoSurface, &rects[i]); |
|
1026 |
} |
|
1027 |
} |
|
488
0a111805b53a
Fixed missing cursor after shadow buffer flip (thanks Jan!)
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
1028 |
if ( saved_colors ) { |
0 | 1029 |
pal->colors = saved_colors; |
488
0a111805b53a
Fixed missing cursor after shadow buffer flip (thanks Jan!)
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
1030 |
} |
0 | 1031 |
|
1032 |
/* Fall through to video surface update */ |
|
1033 |
screen = SDL_VideoSurface; |
|
1034 |
} |
|
1035 |
if ( screen == SDL_VideoSurface ) { |
|
1036 |
/* Update the video surface */ |
|
1037 |
if ( screen->offset ) { |
|
1038 |
for ( i=0; i<numrects; ++i ) { |
|
1039 |
rects[i].x += video->offset_x; |
|
1040 |
rects[i].y += video->offset_y; |
|
1041 |
} |
|
1042 |
video->UpdateRects(this, numrects, rects); |
|
1043 |
for ( i=0; i<numrects; ++i ) { |
|
1044 |
rects[i].x -= video->offset_x; |
|
1045 |
rects[i].y -= video->offset_y; |
|
1046 |
} |
|
1047 |
} else { |
|
1048 |
video->UpdateRects(this, numrects, rects); |
|
1049 |
} |
|
1050 |
} |
|
1051 |
} |
|
1052 |
||
1053 |
/* |
|
1054 |
* Performs hardware double buffering, if possible, or a full update if not. |
|
1055 |
*/ |
|
1056 |
int SDL_Flip(SDL_Surface *screen) |
|
1057 |
{ |
|
1058 |
SDL_VideoDevice *video = current_video; |
|
1059 |
/* Copy the shadow surface to the video surface */ |
|
1060 |
if ( screen == SDL_ShadowSurface ) { |
|
1061 |
SDL_Rect rect; |
|
488
0a111805b53a
Fixed missing cursor after shadow buffer flip (thanks Jan!)
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
1062 |
SDL_Palette *pal = screen->format->palette; |
0 | 1063 |
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
|
1064 |
if ( pal && !(SDL_VideoSurface->flags & SDL_HWPALETTE) ) { |
0 | 1065 |
/* simulated 8bpp, use correct physical palette */ |
1066 |
saved_colors = pal->colors; |
|
1067 |
if ( video->gammacols ) { |
|
1068 |
/* gamma-corrected palette */ |
|
1069 |
pal->colors = video->gammacols; |
|
1070 |
} else if ( video->physpal ) { |
|
1071 |
/* physical palette different from logical */ |
|
1072 |
pal->colors = video->physpal->colors; |
|
1073 |
} |
|
1074 |
} |
|
1075 |
||
1076 |
rect.x = 0; |
|
1077 |
rect.y = 0; |
|
1078 |
rect.w = screen->w; |
|
1079 |
rect.h = screen->h; |
|
488
0a111805b53a
Fixed missing cursor after shadow buffer flip (thanks Jan!)
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
1080 |
if ( SHOULD_DRAWCURSOR(SDL_cursorstate) ) { |
0a111805b53a
Fixed missing cursor after shadow buffer flip (thanks Jan!)
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
1081 |
SDL_LockCursor(); |
0a111805b53a
Fixed missing cursor after shadow buffer flip (thanks Jan!)
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
1082 |
SDL_DrawCursor(SDL_ShadowSurface); |
0a111805b53a
Fixed missing cursor after shadow buffer flip (thanks Jan!)
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
1083 |
SDL_LowerBlit(SDL_ShadowSurface, &rect, |
0a111805b53a
Fixed missing cursor after shadow buffer flip (thanks Jan!)
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
1084 |
SDL_VideoSurface, &rect); |
0a111805b53a
Fixed missing cursor after shadow buffer flip (thanks Jan!)
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
1085 |
SDL_EraseCursor(SDL_ShadowSurface); |
0a111805b53a
Fixed missing cursor after shadow buffer flip (thanks Jan!)
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
1086 |
SDL_UnlockCursor(); |
0a111805b53a
Fixed missing cursor after shadow buffer flip (thanks Jan!)
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
1087 |
} else { |
0a111805b53a
Fixed missing cursor after shadow buffer flip (thanks Jan!)
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
1088 |
SDL_LowerBlit(SDL_ShadowSurface, &rect, |
0a111805b53a
Fixed missing cursor after shadow buffer flip (thanks Jan!)
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
1089 |
SDL_VideoSurface, &rect); |
0a111805b53a
Fixed missing cursor after shadow buffer flip (thanks Jan!)
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
1090 |
} |
0a111805b53a
Fixed missing cursor after shadow buffer flip (thanks Jan!)
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
1091 |
if ( saved_colors ) { |
0a111805b53a
Fixed missing cursor after shadow buffer flip (thanks Jan!)
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
1092 |
pal->colors = saved_colors; |
0a111805b53a
Fixed missing cursor after shadow buffer flip (thanks Jan!)
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
1093 |
} |
0 | 1094 |
|
488
0a111805b53a
Fixed missing cursor after shadow buffer flip (thanks Jan!)
Sam Lantinga <slouken@libsdl.org>
parents:
460
diff
changeset
|
1095 |
/* Fall through to video surface update */ |
0 | 1096 |
screen = SDL_VideoSurface; |
1097 |
} |
|
1098 |
if ( (screen->flags & SDL_DOUBLEBUF) == SDL_DOUBLEBUF ) { |
|
1099 |
SDL_VideoDevice *this = current_video; |
|
1100 |
return(video->FlipHWSurface(this, SDL_VideoSurface)); |
|
1101 |
} else { |
|
1102 |
SDL_UpdateRect(screen, 0, 0, 0, 0); |
|
1103 |
} |
|
1104 |
return(0); |
|
1105 |
} |
|
1106 |
||
1107 |
static void SetPalette_logical(SDL_Surface *screen, SDL_Color *colors, |
|
1108 |
int firstcolor, int ncolors) |
|
1109 |
{ |
|
662
66c02f83f5bf
Date: Sun, 27 Jul 2003 22:37:59 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
656
diff
changeset
|
1110 |
SDL_Palette *pal = screen->format->palette; |
0 | 1111 |
SDL_Palette *vidpal; |
1112 |
||
1113 |
if ( colors != (pal->colors + firstcolor) ) { |
|
662
66c02f83f5bf
Date: Sun, 27 Jul 2003 22:37:59 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
656
diff
changeset
|
1114 |
memcpy(pal->colors + firstcolor, colors, |
0 | 1115 |
ncolors * sizeof(*colors)); |
1116 |
} |
|
1117 |
||
1118 |
vidpal = SDL_VideoSurface->format->palette; |
|
1119 |
if ( (screen == SDL_ShadowSurface) && vidpal ) { |
|
662
66c02f83f5bf
Date: Sun, 27 Jul 2003 22:37:59 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
656
diff
changeset
|
1120 |
/* |
0 | 1121 |
* This is a shadow surface, and the physical |
1122 |
* framebuffer is also indexed. Propagate the |
|
1123 |
* changes to its logical palette so that |
|
1124 |
* updates are always identity blits |
|
1125 |
*/ |
|
1126 |
memcpy(vidpal->colors + firstcolor, colors, |
|
1127 |
ncolors * sizeof(*colors)); |
|
1128 |
} |
|
1129 |
SDL_FormatChanged(screen); |
|
1130 |
} |
|
1131 |
||
1132 |
static int SetPalette_physical(SDL_Surface *screen, |
|
1133 |
SDL_Color *colors, int firstcolor, int ncolors) |
|
1134 |
{ |
|
1135 |
SDL_VideoDevice *video = current_video; |
|
1136 |
int gotall = 1; |
|
1137 |
||
1138 |
if ( video->physpal ) { |
|
1139 |
/* We need to copy the new colors, since we haven't |
|
1140 |
* already done the copy in the logical set above. |
|
1141 |
*/ |
|
1142 |
memcpy(video->physpal->colors + firstcolor, |
|
1143 |
colors, ncolors * sizeof(*colors)); |
|
1144 |
} |
|
1145 |
if ( screen == SDL_ShadowSurface ) { |
|
1146 |
if ( SDL_VideoSurface->flags & SDL_HWPALETTE ) { |
|
1147 |
/* |
|
1148 |
* The real screen is also indexed - set its physical |
|
1149 |
* palette. The physical palette does not include the |
|
1150 |
* gamma modification, we apply it directly instead, |
|
1151 |
* but this only happens if we have hardware palette. |
|
1152 |
*/ |
|
1153 |
screen = SDL_VideoSurface; |
|
1154 |
} else { |
|
1155 |
/* |
|
1156 |
* The video surface is not indexed - invalidate any |
|
1157 |
* active shadow-to-video blit mappings. |
|
1158 |
*/ |
|
1159 |
if ( screen->map->dst == SDL_VideoSurface ) { |
|
1160 |
SDL_InvalidateMap(screen->map); |
|
1161 |
} |
|
1162 |
if ( video->gamma ) { |
|
1163 |
if( ! video->gammacols ) { |
|
1164 |
SDL_Palette *pp = video->physpal; |
|
1165 |
if(!pp) |
|
1166 |
pp = screen->format->palette; |
|
1167 |
video->gammacols = malloc(pp->ncolors |
|
1168 |
* sizeof(SDL_Color)); |
|
1169 |
SDL_ApplyGamma(video->gamma, |
|
1170 |
pp->colors, |
|
1171 |
video->gammacols, |
|
1172 |
pp->ncolors); |
|
1173 |
} else { |
|
1174 |
SDL_ApplyGamma(video->gamma, colors, |
|
1175 |
video->gammacols |
|
1176 |
+ firstcolor, |
|
1177 |
ncolors); |
|
1178 |
} |
|
1179 |
} |
|
1180 |
SDL_UpdateRect(screen, 0, 0, 0, 0); |
|
1181 |
} |
|
1182 |
} |
|
1183 |
||
1184 |
if ( screen == SDL_VideoSurface ) { |
|
1185 |
SDL_Color gcolors[256]; |
|
1186 |
||
662
66c02f83f5bf
Date: Sun, 27 Jul 2003 22:37:59 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
656
diff
changeset
|
1187 |
if ( video->gamma ) { |
66c02f83f5bf
Date: Sun, 27 Jul 2003 22:37:59 +0200
Sam Lantinga <slouken@libsdl.org>
parents:
656
diff
changeset
|
1188 |
SDL_ApplyGamma(video->gamma, colors, gcolors, ncolors); |
0 | 1189 |
colors = gcolors; |
1190 |
} |
|
1191 |
gotall = video->SetColors(video, firstcolor, ncolors, colors); |
|
1192 |
if ( ! gotall ) { |
|
1193 |
/* The video flags shouldn't have SDL_HWPALETTE, and |
|
1194 |
the video driver is responsible for copying back the |
|
1195 |
correct colors into the video surface palette. |
|
1196 |
*/ |
|
1197 |
; |
|
1198 |
} |
|
1199 |
SDL_CursorPaletteChanged(); |
|
1200 |
} |
|
1201 |