Mercurial > sdl-ios-xcode
annotate src/video/svga/SDL_svgavideo.c @ 1554:0ca607a5d173
Fixed bug #84
Date: Sun, 23 Oct 2005 16:39:03 +0200
From: "A. Schmid" <sahib@phreaker.net>
Subject: [SDL] no software surfaces with svgalib driver?
Hi,
I noticed that the SDL (1.2.9) svgalib driver only makes use of linear
addressable (framebuffer) video modes. On older systems (like one of
mine), linear addressable modes are often not available.
Especially for cards with VESA VBE < 2.0 the svgalib vesa driver is
unusable, since VESA only supports framebuffering for VBE 2.0 and later.
The changes necessary to add support for software surfaces seem to be
relatively small. I only had to hack src/video/svga/SDL_svgavideo.c (see
attached patch). The code worked fine for me, but it is no more than a
proof of concept and should be reviewed (probably has a memory leak when
switching modes). It also uses the vgagl library (included in the
svgalib package) and needs to be linked against it.
-Alex
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sun, 19 Mar 2006 12:04:40 +0000 |
parents | 8d9bb0cf2c2a |
children | 011b633fa0c9 |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
3 Copyright (C) 1997-2006 Sam Lantinga |
0 | 4 |
5 This library is free software; you can redistribute it and/or | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
6 modify it under the terms of the GNU Lesser General Public |
0 | 7 License as published by the Free Software Foundation; either |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
8 version 2.1 of the License, or (at your option) any later version. |
0 | 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 | |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
13 Lesser General Public License for more details. |
0 | 14 |
1312
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
15 You should have received a copy of the GNU Lesser General Public |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
16 License along with this library; if not, write to the Free Software |
c9b51268668f
Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents:
769
diff
changeset
|
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 18 |
19 Sam Lantinga | |
252
e8157fcb3114
Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents:
226
diff
changeset
|
20 slouken@libsdl.org |
0 | 21 */ |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
22 #include "SDL_config.h" |
0 | 23 |
24 /* SVGAlib based SDL video driver implementation. | |
25 */ | |
26 | |
27 #include <unistd.h> | |
28 #include <sys/stat.h> | |
67
3647c809813d
Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents:
1
diff
changeset
|
29 #include <sys/types.h> |
3647c809813d
Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents:
1
diff
changeset
|
30 #include <sys/ioctl.h> |
3647c809813d
Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents:
1
diff
changeset
|
31 #include <fcntl.h> |
0 | 32 |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
33 #if defined(__LINUX__) |
0 | 34 #include <linux/vt.h> |
1402
d910939febfa
Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents:
1361
diff
changeset
|
35 #elif defined(__FREEBSD__) |
0 | 36 #include <sys/consio.h> |
37 #else | |
38 #error You must choose your operating system here | |
39 #endif | |
40 #include <vga.h> | |
41 #include <vgamouse.h> | |
42 #include <vgakeyboard.h> | |
1554 | 43 #include <vgagl.h> |
0 | 44 |
45 #include "SDL_video.h" | |
46 #include "SDL_mouse.h" | |
1361
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
47 #include "../SDL_sysvideo.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
48 #include "../SDL_pixels_c.h" |
19418e4422cb
New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents:
1358
diff
changeset
|
49 #include "../../events/SDL_events_c.h" |
0 | 50 #include "SDL_svgavideo.h" |
51 #include "SDL_svgaevents_c.h" | |
52 #include "SDL_svgamouse_c.h" | |
53 | |
1554 | 54 static GraphicsContext *realgc = NULL; |
55 static GraphicsContext *virtgc = NULL; | |
0 | 56 |
57 /* Initialization/Query functions */ | |
58 static int SVGA_VideoInit(_THIS, SDL_PixelFormat *vformat); | |
59 static SDL_Rect **SVGA_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); | |
60 static SDL_Surface *SVGA_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); | |
61 static int SVGA_SetColors(_THIS, int firstcolor, int ncolors, | |
62 SDL_Color *colors); | |
63 static void SVGA_VideoQuit(_THIS); | |
64 | |
65 /* Hardware surface functions */ | |
66 static int SVGA_AllocHWSurface(_THIS, SDL_Surface *surface); | |
67 static int SVGA_LockHWSurface(_THIS, SDL_Surface *surface); | |
68 static int SVGA_FlipHWSurface(_THIS, SDL_Surface *surface); | |
69 static void SVGA_UnlockHWSurface(_THIS, SDL_Surface *surface); | |
70 static void SVGA_FreeHWSurface(_THIS, SDL_Surface *surface); | |
71 | |
72 /* SVGAlib driver bootstrap functions */ | |
73 | |
74 static int SVGA_Available(void) | |
75 { | |
76 /* Check to see if we are root and stdin is a virtual console */ | |
77 int console; | |
67
3647c809813d
Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents:
1
diff
changeset
|
78 |
3647c809813d
Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents:
1
diff
changeset
|
79 /* SVGALib 1.9.x+ doesn't require root (via /dev/svga) */ |
3647c809813d
Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents:
1
diff
changeset
|
80 int svgalib2 = -1; |
0 | 81 |
67
3647c809813d
Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents:
1
diff
changeset
|
82 /* See if we are connected to a virtual terminal */ |
0 | 83 console = STDIN_FILENO; |
226
bb72c418a1f9
Disabled virtual terminal check for SVGAlib video
Sam Lantinga <slouken@libsdl.org>
parents:
205
diff
changeset
|
84 #if 0 /* This is no longer needed, SVGAlib can switch consoles for us */ |
0 | 85 if ( console >= 0 ) { |
86 struct stat sb; | |
87 struct vt_mode dummy; | |
88 | |
89 if ( (fstat(console, &sb) < 0) || | |
90 (ioctl(console, VT_GETMODE, &dummy) < 0) ) { | |
91 console = -1; | |
92 } | |
93 } | |
226
bb72c418a1f9
Disabled virtual terminal check for SVGAlib video
Sam Lantinga <slouken@libsdl.org>
parents:
205
diff
changeset
|
94 #endif /* 0 */ |
67
3647c809813d
Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents:
1
diff
changeset
|
95 |
3647c809813d
Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents:
1
diff
changeset
|
96 /* See if SVGAlib 2.0 is available */ |
3647c809813d
Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents:
1
diff
changeset
|
97 svgalib2 = open("/dev/svga", O_RDONLY); |
3647c809813d
Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents:
1
diff
changeset
|
98 if (svgalib2 != -1) { |
3647c809813d
Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents:
1
diff
changeset
|
99 close(svgalib2); |
3647c809813d
Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents:
1
diff
changeset
|
100 } |
3647c809813d
Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents:
1
diff
changeset
|
101 |
3647c809813d
Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents:
1
diff
changeset
|
102 return(((svgalib2 != -1) || (geteuid() == 0)) && (console >= 0)); |
0 | 103 } |
104 | |
105 static void SVGA_DeleteDevice(SDL_VideoDevice *device) | |
106 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
107 SDL_free(device->hidden); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
108 SDL_free(device); |
0 | 109 } |
110 | |
111 static SDL_VideoDevice *SVGA_CreateDevice(int devindex) | |
112 { | |
113 SDL_VideoDevice *device; | |
114 | |
115 /* Initialize all variables that we clean on shutdown */ | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
116 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); |
0 | 117 if ( device ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
118 SDL_memset(device, 0, (sizeof *device)); |
0 | 119 device->hidden = (struct SDL_PrivateVideoData *) |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
120 SDL_malloc((sizeof *device->hidden)); |
0 | 121 } |
122 if ( (device == NULL) || (device->hidden == NULL) ) { | |
123 SDL_OutOfMemory(); | |
124 if ( device ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
125 SDL_free(device); |
0 | 126 } |
127 return(0); | |
128 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
129 SDL_memset(device->hidden, 0, (sizeof *device->hidden)); |
0 | 130 |
131 /* Set the function pointers */ | |
132 device->VideoInit = SVGA_VideoInit; | |
133 device->ListModes = SVGA_ListModes; | |
134 device->SetVideoMode = SVGA_SetVideoMode; | |
135 device->SetColors = SVGA_SetColors; | |
136 device->UpdateRects = NULL; | |
137 device->VideoQuit = SVGA_VideoQuit; | |
138 device->AllocHWSurface = SVGA_AllocHWSurface; | |
139 device->CheckHWBlit = NULL; | |
140 device->FillHWRect = NULL; | |
141 device->SetHWColorKey = NULL; | |
142 device->SetHWAlpha = NULL; | |
143 device->LockHWSurface = SVGA_LockHWSurface; | |
144 device->UnlockHWSurface = SVGA_UnlockHWSurface; | |
205
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
145 device->FlipHWSurface = SVGA_FlipHWSurface; |
0 | 146 device->FreeHWSurface = SVGA_FreeHWSurface; |
147 device->SetCaption = NULL; | |
148 device->SetIcon = NULL; | |
149 device->IconifyWindow = NULL; | |
150 device->GrabInput = NULL; | |
151 device->GetWMInfo = NULL; | |
152 device->InitOSKeymap = SVGA_InitOSKeymap; | |
153 device->PumpEvents = SVGA_PumpEvents; | |
154 | |
155 device->free = SVGA_DeleteDevice; | |
156 | |
157 return device; | |
158 } | |
159 | |
160 VideoBootStrap SVGALIB_bootstrap = { | |
161 "svgalib", "SVGAlib", | |
162 SVGA_Available, SVGA_CreateDevice | |
163 }; | |
164 | |
165 static int SVGA_AddMode(_THIS, int mode, int actually_add, int force) | |
166 { | |
167 vga_modeinfo *modeinfo; | |
168 | |
169 modeinfo = vga_getmodeinfo(mode); | |
170 if ( force || ( modeinfo->flags & CAPABLE_LINEAR ) ) { | |
171 int i, j; | |
172 | |
173 i = modeinfo->bytesperpixel-1; | |
1554 | 174 if ( i < 0 ) { |
175 return 0; | |
176 } | |
0 | 177 if ( actually_add ) { |
178 SDL_Rect saved_rect[2]; | |
179 int saved_mode[2]; | |
180 int b; | |
181 | |
182 /* Add the mode, sorted largest to smallest */ | |
183 b = 0; | |
184 j = 0; | |
185 while ( (SDL_modelist[i][j]->w > modeinfo->width) || | |
186 (SDL_modelist[i][j]->h > modeinfo->height) ) { | |
187 ++j; | |
188 } | |
189 /* Skip modes that are already in our list */ | |
190 if ( (SDL_modelist[i][j]->w == modeinfo->width) && | |
191 (SDL_modelist[i][j]->h == modeinfo->height) ) { | |
192 return(0); | |
193 } | |
194 /* Insert the new mode */ | |
195 saved_rect[b] = *SDL_modelist[i][j]; | |
196 saved_mode[b] = SDL_vgamode[i][j]; | |
197 SDL_modelist[i][j]->w = modeinfo->width; | |
198 SDL_modelist[i][j]->h = modeinfo->height; | |
199 SDL_vgamode[i][j] = mode; | |
200 /* Everybody scoot down! */ | |
201 if ( saved_rect[b].w && saved_rect[b].h ) { | |
202 for ( ++j; SDL_modelist[i][j]->w; ++j ) { | |
203 saved_rect[!b] = *SDL_modelist[i][j]; | |
204 saved_mode[!b] = SDL_vgamode[i][j]; | |
205 *SDL_modelist[i][j] = saved_rect[b]; | |
206 SDL_vgamode[i][j] = saved_mode[b]; | |
207 b = !b; | |
208 } | |
209 *SDL_modelist[i][j] = saved_rect[b]; | |
210 SDL_vgamode[i][j] = saved_mode[b]; | |
211 } | |
212 } else { | |
213 ++SDL_nummodes[i]; | |
214 } | |
215 } | |
216 return( force || ( modeinfo->flags & CAPABLE_LINEAR ) ); | |
217 } | |
218 | |
219 static void SVGA_UpdateVideoInfo(_THIS) | |
220 { | |
221 vga_modeinfo *modeinfo; | |
222 | |
223 this->info.wm_available = 0; | |
1554 | 224 this->info.hw_available = (virtgc ? 0 : 1); |
0 | 225 modeinfo = vga_getmodeinfo(vga_getcurrentmode()); |
205
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
226 this->info.video_mem = modeinfo->memory; |
0 | 227 /* FIXME: Add hardware accelerated blit information */ |
226
bb72c418a1f9
Disabled virtual terminal check for SVGAlib video
Sam Lantinga <slouken@libsdl.org>
parents:
205
diff
changeset
|
228 #ifdef SVGALIB_DEBUG |
bb72c418a1f9
Disabled virtual terminal check for SVGAlib video
Sam Lantinga <slouken@libsdl.org>
parents:
205
diff
changeset
|
229 printf("Hardware accelerated blit: %savailable\n", modeinfo->haveblit ? "" : "not "); |
0 | 230 #endif |
231 } | |
232 | |
233 int SVGA_VideoInit(_THIS, SDL_PixelFormat *vformat) | |
234 { | |
235 int keyboard; | |
236 int i, j; | |
237 int mode, total_modes; | |
238 | |
239 /* Initialize all variables that we clean on shutdown */ | |
240 for ( i=0; i<NUM_MODELISTS; ++i ) { | |
241 SDL_nummodes[i] = 0; | |
242 SDL_modelist[i] = NULL; | |
243 SDL_vgamode[i] = NULL; | |
244 } | |
245 | |
246 /* Initialize the library */ | |
247 vga_disabledriverreport(); | |
248 if ( vga_init() < 0 ) { | |
249 SDL_SetError("Unable to initialize SVGAlib"); | |
250 return(-1); | |
251 } | |
252 vga_setmode(TEXT); | |
253 | |
254 /* Enable mouse and keyboard support */ | |
255 vga_setmousesupport(1); | |
256 keyboard = keyboard_init_return_fd(); | |
257 if ( keyboard < 0 ) { | |
258 SDL_SetError("Unable to initialize keyboard"); | |
259 return(-1); | |
260 } | |
261 if ( SVGA_initkeymaps(keyboard) < 0 ) { | |
262 return(-1); | |
263 } | |
264 keyboard_seteventhandler(SVGA_keyboardcallback); | |
265 | |
1545
8d9bb0cf2c2a
Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
266 /* Determine the current screen size */ |
8d9bb0cf2c2a
Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
267 this->info.current_w = 0; |
8d9bb0cf2c2a
Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
268 this->info.current_h = 0; |
8d9bb0cf2c2a
Added current_w and current_h to the SDL_VideoInfo structure, which is set to the desktop resolution during video intialization, and then set to the current resolution when a video mode is set.
Sam Lantinga <slouken@libsdl.org>
parents:
1402
diff
changeset
|
269 |
0 | 270 /* Determine the screen depth (use default 8-bit depth) */ |
271 vformat->BitsPerPixel = 8; | |
272 | |
273 /* Enumerate the available fullscreen modes */ | |
274 total_modes = 0; | |
275 for ( mode=vga_lastmodenumber(); mode; --mode ) { | |
276 if ( vga_hasmode(mode) ) { | |
1554 | 277 if ( SVGA_AddMode(this, mode, 0, 1) ) { |
0 | 278 ++total_modes; |
279 } | |
280 } | |
281 } | |
282 if ( SVGA_AddMode(this, G320x200x256, 0, 1) ) ++total_modes; | |
283 if ( total_modes == 0 ) { | |
284 SDL_SetError("No linear video modes available"); | |
285 return(-1); | |
286 } | |
287 for ( i=0; i<NUM_MODELISTS; ++i ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
288 SDL_vgamode[i] = (int *)SDL_malloc(SDL_nummodes[i]*sizeof(int)); |
0 | 289 if ( SDL_vgamode[i] == NULL ) { |
290 SDL_OutOfMemory(); | |
291 return(-1); | |
292 } | |
293 SDL_modelist[i] = (SDL_Rect **) | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
294 SDL_malloc((SDL_nummodes[i]+1)*sizeof(SDL_Rect *)); |
0 | 295 if ( SDL_modelist[i] == NULL ) { |
296 SDL_OutOfMemory(); | |
297 return(-1); | |
298 } | |
299 for ( j=0; j<SDL_nummodes[i]; ++j ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
300 SDL_modelist[i][j]=(SDL_Rect *)SDL_malloc(sizeof(SDL_Rect)); |
0 | 301 if ( SDL_modelist[i][j] == NULL ) { |
302 SDL_OutOfMemory(); | |
303 return(-1); | |
304 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
305 SDL_memset(SDL_modelist[i][j], 0, sizeof(SDL_Rect)); |
0 | 306 } |
307 SDL_modelist[i][j] = NULL; | |
308 } | |
309 for ( mode=vga_lastmodenumber(); mode; --mode ) { | |
310 if ( vga_hasmode(mode) ) { | |
1554 | 311 SVGA_AddMode(this, mode, 1, 1); |
0 | 312 } |
313 } | |
314 SVGA_AddMode(this, G320x200x256, 1, 1); | |
315 | |
316 /* Free extra (duplicated) modes */ | |
317 for ( i=0; i<NUM_MODELISTS; ++i ) { | |
318 j = 0; | |
319 while ( SDL_modelist[i][j] && SDL_modelist[i][j]->w ) { | |
320 j++; | |
321 } | |
322 while ( SDL_modelist[i][j] ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
323 SDL_free(SDL_modelist[i][j]); |
0 | 324 SDL_modelist[i][j] = NULL; |
325 j++; | |
326 } | |
327 } | |
328 | |
329 /* Fill in our hardware acceleration capabilities */ | |
330 SVGA_UpdateVideoInfo(this); | |
331 | |
332 /* We're done! */ | |
333 return(0); | |
334 } | |
335 | |
336 SDL_Rect **SVGA_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | |
337 { | |
338 return(SDL_modelist[((format->BitsPerPixel+7)/8)-1]); | |
339 } | |
340 | |
341 /* Various screen update functions available */ | |
342 static void SVGA_DirectUpdate(_THIS, int numrects, SDL_Rect *rects); | |
343 static void SVGA_BankedUpdate(_THIS, int numrects, SDL_Rect *rects); | |
344 | |
345 SDL_Surface *SVGA_SetVideoMode(_THIS, SDL_Surface *current, | |
346 int width, int height, int bpp, Uint32 flags) | |
347 { | |
348 int mode; | |
349 int vgamode; | |
350 vga_modeinfo *modeinfo; | |
205
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
351 int screenpage_len; |
0 | 352 |
1554 | 353 /* Clean up old video mode data */ |
354 if ( realgc ) { | |
355 free(realgc); | |
356 realgc = NULL; | |
357 } | |
358 if ( virtgc ) { | |
359 /* FIXME: Why does this crash? | |
360 gl_freecontext(virtgc);*/ | |
361 free(virtgc); | |
362 virtgc = NULL; | |
363 } | |
364 | |
0 | 365 /* Try to set the requested linear video mode */ |
366 bpp = (bpp+7)/8-1; | |
367 for ( mode=0; SDL_modelist[bpp][mode]; ++mode ) { | |
368 if ( (SDL_modelist[bpp][mode]->w == width) && | |
369 (SDL_modelist[bpp][mode]->h == height) ) { | |
370 break; | |
371 } | |
372 } | |
373 if ( SDL_modelist[bpp][mode] == NULL ) { | |
374 SDL_SetError("Couldn't find requested mode in list"); | |
375 return(NULL); | |
376 } | |
1554 | 377 vgamode = SDL_vgamode[bpp][mode]; |
378 vga_setmode(vgamode); | |
0 | 379 vga_setpage(0); |
380 | |
1554 | 381 if ( (vga_setlinearaddressing() < 0) && (vgamode != G320x200x256) ) { |
382 gl_setcontextvga(vgamode); | |
383 realgc = gl_allocatecontext(); | |
384 gl_getcontext(realgc); | |
385 | |
386 gl_setcontextvgavirtual(vgamode); | |
387 virtgc = gl_allocatecontext(); | |
388 gl_getcontext(virtgc); | |
389 | |
390 flags &= ~SDL_DOUBLEBUF; | |
0 | 391 } |
1554 | 392 |
0 | 393 modeinfo = vga_getmodeinfo(SDL_vgamode[bpp][mode]); |
394 | |
395 /* Update hardware acceleration info */ | |
396 SVGA_UpdateVideoInfo(this); | |
397 | |
398 /* Allocate the new pixel format for the screen */ | |
399 bpp = (bpp+1)*8; | |
400 if ( (bpp == 16) && (modeinfo->colors == 32768) ) { | |
401 bpp = 15; | |
402 } | |
403 if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) { | |
404 return(NULL); | |
405 } | |
406 | |
407 /* Set up the new mode framebuffer */ | |
1554 | 408 current->flags = SDL_FULLSCREEN; |
409 if ( virtgc ) { | |
410 current->flags |= SDL_SWSURFACE; | |
411 } else { | |
412 current->flags |= SDL_HWSURFACE; | |
413 } | |
1
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
414 if ( bpp == 8 ) { |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
415 /* FIXME: What about DirectColor? */ |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
416 current->flags |= SDL_HWPALETTE; |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
417 } |
0 | 418 current->w = width; |
419 current->h = height; | |
420 current->pitch = modeinfo->linewidth; | |
1554 | 421 if ( virtgc ) { |
422 current->pixels = virtgc->vbuf; | |
423 } else { | |
424 current->pixels = vga_getgraphmem(); | |
425 } | |
0 | 426 |
205
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
427 /* set double-buffering */ |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
428 if ( flags & SDL_DOUBLEBUF ) |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
429 { |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
430 /* length of one screen page in bytes */ |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
431 screenpage_len=current->h*modeinfo->linewidth; |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
432 |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
433 /* if start address should be aligned */ |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
434 if ( modeinfo->linewidth_unit ) |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
435 { |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
436 if ( screenpage_len % modeinfo->linewidth_unit ) |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
437 { |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
438 screenpage_len += modeinfo->linewidth_unit - ( screenpage_len % modeinfo->linewidth_unit ); |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
439 } |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
440 } |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
441 |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
442 /* if we heve enough videomemory = ak je dost videopamete */ |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
443 if ( modeinfo->memory > ( screenpage_len * 2 / 1024 ) ) |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
444 { |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
445 current->flags |= SDL_DOUBLEBUF; |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
446 flip_page = 0; |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
447 flip_offset[0] = 0; |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
448 flip_offset[1] = screenpage_len; |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
449 flip_address[0] = vga_getgraphmem(); |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
450 flip_address[1] = flip_address[0]+screenpage_len; |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
451 SVGA_FlipHWSurface(this,current); |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
452 } |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
453 } |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
454 |
0 | 455 /* Set the blit function */ |
1554 | 456 if ( virtgc ) { |
457 this->UpdateRects = SVGA_BankedUpdate; | |
458 } else { | |
459 this->UpdateRects = SVGA_DirectUpdate; | |
460 } | |
0 | 461 |
462 /* Set up the mouse handler again (buggy SVGAlib 1.40) */ | |
463 mouse_seteventhandler(SVGA_mousecallback); | |
464 | |
465 /* We're done */ | |
466 return(current); | |
467 } | |
468 | |
469 /* We don't actually allow hardware surfaces other than the main one */ | |
470 static int SVGA_AllocHWSurface(_THIS, SDL_Surface *surface) | |
471 { | |
472 return(-1); | |
473 } | |
474 static void SVGA_FreeHWSurface(_THIS, SDL_Surface *surface) | |
475 { | |
476 return; | |
477 } | |
478 | |
479 /* We need to wait for vertical retrace on page flipped displays */ | |
480 static int SVGA_LockHWSurface(_THIS, SDL_Surface *surface) | |
481 { | |
205
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
482 /* The waiting is done in SVGA_FlipHWSurface() */ |
0 | 483 return(0); |
484 } | |
485 static void SVGA_UnlockHWSurface(_THIS, SDL_Surface *surface) | |
486 { | |
487 return; | |
488 } | |
489 | |
490 static int SVGA_FlipHWSurface(_THIS, SDL_Surface *surface) | |
491 { | |
1554 | 492 if ( !virtgc ) { |
493 vga_setdisplaystart(flip_offset[flip_page]); | |
494 flip_page=!flip_page; | |
495 surface->pixels=flip_address[flip_page]; | |
496 vga_waitretrace(); | |
497 } | |
0 | 498 return(0); |
499 } | |
500 | |
501 static void SVGA_DirectUpdate(_THIS, int numrects, SDL_Rect *rects) | |
502 { | |
503 return; | |
504 } | |
505 | |
506 static void SVGA_BankedUpdate(_THIS, int numrects, SDL_Rect *rects) | |
507 { | |
1554 | 508 int i; |
509 SDL_Rect *rect; | |
510 | |
511 for ( i=0; i < numrects; ++i ) { | |
512 rect = &rects[i]; | |
513 gl_copyboxtocontext(rect->x, rect->y, rect->w, rect->h, realgc, rect->x, rect->y); | |
514 } | |
0 | 515 return; |
516 } | |
517 | |
518 int SVGA_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) | |
519 { | |
520 int i; | |
521 | |
522 for(i = 0; i < ncolors; i++) { | |
523 vga_setpalette(firstcolor + i, | |
524 colors[i].r>>2, | |
525 colors[i].g>>2, | |
526 colors[i].b>>2); | |
527 } | |
528 return(1); | |
529 } | |
530 | |
531 /* Note: If we are terminated, this could be called in the middle of | |
532 another SDL video routine -- notably UpdateRects. | |
533 */ | |
534 void SVGA_VideoQuit(_THIS) | |
535 { | |
536 int i, j; | |
537 | |
538 /* Reset the console video mode */ | |
539 if ( this->screen && (this->screen->w && this->screen->h) ) { | |
1554 | 540 if ( realgc ) { |
541 free(realgc); | |
542 realgc = NULL; | |
543 } | |
544 if ( virtgc ) { | |
545 /* FIXME: Why does this crash? | |
546 gl_freecontext(virtgc);*/ | |
547 free(virtgc); | |
548 virtgc = NULL; | |
549 } | |
0 | 550 vga_setmode(TEXT); |
551 } | |
552 keyboard_close(); | |
553 | |
554 /* Free video mode lists */ | |
555 for ( i=0; i<NUM_MODELISTS; ++i ) { | |
556 if ( SDL_modelist[i] != NULL ) { | |
557 for ( j=0; SDL_modelist[i][j]; ++j ) | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
558 SDL_free(SDL_modelist[i][j]); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
559 SDL_free(SDL_modelist[i]); |
0 | 560 SDL_modelist[i] = NULL; |
561 } | |
562 if ( SDL_vgamode[i] != NULL ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
563 SDL_free(SDL_vgamode[i]); |
0 | 564 SDL_vgamode[i] = NULL; |
565 } | |
566 } | |
567 if ( this->screen && (this->screen->flags & SDL_HWSURFACE) ) { | |
568 /* Direct screen access, no memory buffer */ | |
569 this->screen->pixels = NULL; | |
570 } | |
571 } | |
205
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
572 |