Mercurial > sdl-ios-xcode
annotate src/video/svga/SDL_svgavideo.c @ 1400:5abff0870de2
Date: Mon, 20 Feb 2006 19:54:51 -0500
From: Brian Barnes
Subject: [SDL] Fix for FSAA OS X bug -- Please fix in CVS Code
I stopped complaining and went in an fixed the bug myself :) SDL
always dies if you try to use FSAA on Mac OS X, the problem is in the
file:
SDL_QuartzGL.m
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Tue, 21 Feb 2006 02:42:05 +0000 |
parents | 19418e4422cb |
children | d910939febfa |
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 */ |
22 | |
23 /* SVGAlib based SDL video driver implementation. | |
24 */ | |
25 | |
26 #include <unistd.h> | |
27 #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
|
28 #include <sys/types.h> |
3647c809813d
Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents:
1
diff
changeset
|
29 #include <sys/ioctl.h> |
3647c809813d
Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents:
1
diff
changeset
|
30 #include <fcntl.h> |
0 | 31 |
32 #if defined(linux) | |
33 #include <linux/vt.h> | |
34 #elif defined(__FreeBSD__) | |
35 #include <sys/consio.h> | |
36 #else | |
37 #error You must choose your operating system here | |
38 #endif | |
39 #include <vga.h> | |
40 #include <vgamouse.h> | |
41 #include <vgakeyboard.h> | |
42 | |
43 #include "SDL_video.h" | |
44 #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
|
45 #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
|
46 #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
|
47 #include "../../events/SDL_events_c.h" |
0 | 48 #include "SDL_svgavideo.h" |
49 #include "SDL_svgaevents_c.h" | |
50 #include "SDL_svgamouse_c.h" | |
51 | |
52 | |
53 /* Initialization/Query functions */ | |
54 static int SVGA_VideoInit(_THIS, SDL_PixelFormat *vformat); | |
55 static SDL_Rect **SVGA_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); | |
56 static SDL_Surface *SVGA_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); | |
57 static int SVGA_SetColors(_THIS, int firstcolor, int ncolors, | |
58 SDL_Color *colors); | |
59 static void SVGA_VideoQuit(_THIS); | |
60 | |
61 /* Hardware surface functions */ | |
62 static int SVGA_AllocHWSurface(_THIS, SDL_Surface *surface); | |
63 static int SVGA_LockHWSurface(_THIS, SDL_Surface *surface); | |
64 static int SVGA_FlipHWSurface(_THIS, SDL_Surface *surface); | |
65 static void SVGA_UnlockHWSurface(_THIS, SDL_Surface *surface); | |
66 static void SVGA_FreeHWSurface(_THIS, SDL_Surface *surface); | |
67 | |
68 /* SVGAlib driver bootstrap functions */ | |
69 | |
70 static int SVGA_Available(void) | |
71 { | |
72 /* Check to see if we are root and stdin is a virtual console */ | |
73 int console; | |
67
3647c809813d
Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents:
1
diff
changeset
|
74 |
3647c809813d
Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents:
1
diff
changeset
|
75 /* 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
|
76 int svgalib2 = -1; |
0 | 77 |
67
3647c809813d
Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents:
1
diff
changeset
|
78 /* See if we are connected to a virtual terminal */ |
0 | 79 console = STDIN_FILENO; |
226
bb72c418a1f9
Disabled virtual terminal check for SVGAlib video
Sam Lantinga <slouken@libsdl.org>
parents:
205
diff
changeset
|
80 #if 0 /* This is no longer needed, SVGAlib can switch consoles for us */ |
0 | 81 if ( console >= 0 ) { |
82 struct stat sb; | |
83 struct vt_mode dummy; | |
84 | |
85 if ( (fstat(console, &sb) < 0) || | |
86 (ioctl(console, VT_GETMODE, &dummy) < 0) ) { | |
87 console = -1; | |
88 } | |
89 } | |
226
bb72c418a1f9
Disabled virtual terminal check for SVGAlib video
Sam Lantinga <slouken@libsdl.org>
parents:
205
diff
changeset
|
90 #endif /* 0 */ |
67
3647c809813d
Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents:
1
diff
changeset
|
91 |
3647c809813d
Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents:
1
diff
changeset
|
92 /* 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
|
93 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
|
94 if (svgalib2 != -1) { |
3647c809813d
Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents:
1
diff
changeset
|
95 close(svgalib2); |
3647c809813d
Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents:
1
diff
changeset
|
96 } |
3647c809813d
Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents:
1
diff
changeset
|
97 |
3647c809813d
Support for SVGALib 2.0, thanks to Benjamin Joel Stover
Sam Lantinga <slouken@lokigames.com>
parents:
1
diff
changeset
|
98 return(((svgalib2 != -1) || (geteuid() == 0)) && (console >= 0)); |
0 | 99 } |
100 | |
101 static void SVGA_DeleteDevice(SDL_VideoDevice *device) | |
102 { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
103 SDL_free(device->hidden); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
104 SDL_free(device); |
0 | 105 } |
106 | |
107 static SDL_VideoDevice *SVGA_CreateDevice(int devindex) | |
108 { | |
109 SDL_VideoDevice *device; | |
110 | |
111 /* 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
|
112 device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice)); |
0 | 113 if ( device ) { |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
114 SDL_memset(device, 0, (sizeof *device)); |
0 | 115 device->hidden = (struct SDL_PrivateVideoData *) |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
116 SDL_malloc((sizeof *device->hidden)); |
0 | 117 } |
118 if ( (device == NULL) || (device->hidden == NULL) ) { | |
119 SDL_OutOfMemory(); | |
120 if ( device ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
121 SDL_free(device); |
0 | 122 } |
123 return(0); | |
124 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
125 SDL_memset(device->hidden, 0, (sizeof *device->hidden)); |
0 | 126 |
127 /* Set the function pointers */ | |
128 device->VideoInit = SVGA_VideoInit; | |
129 device->ListModes = SVGA_ListModes; | |
130 device->SetVideoMode = SVGA_SetVideoMode; | |
131 device->SetColors = SVGA_SetColors; | |
132 device->UpdateRects = NULL; | |
133 device->VideoQuit = SVGA_VideoQuit; | |
134 device->AllocHWSurface = SVGA_AllocHWSurface; | |
135 device->CheckHWBlit = NULL; | |
136 device->FillHWRect = NULL; | |
137 device->SetHWColorKey = NULL; | |
138 device->SetHWAlpha = NULL; | |
139 device->LockHWSurface = SVGA_LockHWSurface; | |
140 device->UnlockHWSurface = SVGA_UnlockHWSurface; | |
205
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
141 device->FlipHWSurface = SVGA_FlipHWSurface; |
0 | 142 device->FreeHWSurface = SVGA_FreeHWSurface; |
143 device->SetCaption = NULL; | |
144 device->SetIcon = NULL; | |
145 device->IconifyWindow = NULL; | |
146 device->GrabInput = NULL; | |
147 device->GetWMInfo = NULL; | |
148 device->InitOSKeymap = SVGA_InitOSKeymap; | |
149 device->PumpEvents = SVGA_PumpEvents; | |
150 | |
151 device->free = SVGA_DeleteDevice; | |
152 | |
153 return device; | |
154 } | |
155 | |
156 VideoBootStrap SVGALIB_bootstrap = { | |
157 "svgalib", "SVGAlib", | |
158 SVGA_Available, SVGA_CreateDevice | |
159 }; | |
160 | |
161 static int SVGA_AddMode(_THIS, int mode, int actually_add, int force) | |
162 { | |
163 vga_modeinfo *modeinfo; | |
164 | |
165 modeinfo = vga_getmodeinfo(mode); | |
166 if ( force || ( modeinfo->flags & CAPABLE_LINEAR ) ) { | |
167 int i, j; | |
168 | |
169 i = modeinfo->bytesperpixel-1; | |
170 if ( actually_add ) { | |
171 SDL_Rect saved_rect[2]; | |
172 int saved_mode[2]; | |
173 int b; | |
174 | |
175 /* Add the mode, sorted largest to smallest */ | |
176 b = 0; | |
177 j = 0; | |
178 while ( (SDL_modelist[i][j]->w > modeinfo->width) || | |
179 (SDL_modelist[i][j]->h > modeinfo->height) ) { | |
180 ++j; | |
181 } | |
182 /* Skip modes that are already in our list */ | |
183 if ( (SDL_modelist[i][j]->w == modeinfo->width) && | |
184 (SDL_modelist[i][j]->h == modeinfo->height) ) { | |
185 return(0); | |
186 } | |
187 /* Insert the new mode */ | |
188 saved_rect[b] = *SDL_modelist[i][j]; | |
189 saved_mode[b] = SDL_vgamode[i][j]; | |
190 SDL_modelist[i][j]->w = modeinfo->width; | |
191 SDL_modelist[i][j]->h = modeinfo->height; | |
192 SDL_vgamode[i][j] = mode; | |
193 /* Everybody scoot down! */ | |
194 if ( saved_rect[b].w && saved_rect[b].h ) { | |
195 for ( ++j; SDL_modelist[i][j]->w; ++j ) { | |
196 saved_rect[!b] = *SDL_modelist[i][j]; | |
197 saved_mode[!b] = SDL_vgamode[i][j]; | |
198 *SDL_modelist[i][j] = saved_rect[b]; | |
199 SDL_vgamode[i][j] = saved_mode[b]; | |
200 b = !b; | |
201 } | |
202 *SDL_modelist[i][j] = saved_rect[b]; | |
203 SDL_vgamode[i][j] = saved_mode[b]; | |
204 } | |
205 } else { | |
206 ++SDL_nummodes[i]; | |
207 } | |
208 } | |
209 return( force || ( modeinfo->flags & CAPABLE_LINEAR ) ); | |
210 } | |
211 | |
212 static void SVGA_UpdateVideoInfo(_THIS) | |
213 { | |
214 vga_modeinfo *modeinfo; | |
215 | |
216 this->info.wm_available = 0; | |
217 this->info.hw_available = 1; | |
218 modeinfo = vga_getmodeinfo(vga_getcurrentmode()); | |
205
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
219 this->info.video_mem = modeinfo->memory; |
0 | 220 /* FIXME: Add hardware accelerated blit information */ |
226
bb72c418a1f9
Disabled virtual terminal check for SVGAlib video
Sam Lantinga <slouken@libsdl.org>
parents:
205
diff
changeset
|
221 #ifdef SVGALIB_DEBUG |
bb72c418a1f9
Disabled virtual terminal check for SVGAlib video
Sam Lantinga <slouken@libsdl.org>
parents:
205
diff
changeset
|
222 printf("Hardware accelerated blit: %savailable\n", modeinfo->haveblit ? "" : "not "); |
0 | 223 #endif |
224 } | |
225 | |
226 int SVGA_VideoInit(_THIS, SDL_PixelFormat *vformat) | |
227 { | |
228 int keyboard; | |
229 int i, j; | |
230 int mode, total_modes; | |
231 | |
232 /* Initialize all variables that we clean on shutdown */ | |
233 for ( i=0; i<NUM_MODELISTS; ++i ) { | |
234 SDL_nummodes[i] = 0; | |
235 SDL_modelist[i] = NULL; | |
236 SDL_vgamode[i] = NULL; | |
237 } | |
238 | |
239 /* Initialize the library */ | |
240 vga_disabledriverreport(); | |
241 if ( vga_init() < 0 ) { | |
242 SDL_SetError("Unable to initialize SVGAlib"); | |
243 return(-1); | |
244 } | |
245 vga_setmode(TEXT); | |
246 | |
247 /* Enable mouse and keyboard support */ | |
248 vga_setmousesupport(1); | |
249 keyboard = keyboard_init_return_fd(); | |
250 if ( keyboard < 0 ) { | |
251 SDL_SetError("Unable to initialize keyboard"); | |
252 return(-1); | |
253 } | |
254 if ( SVGA_initkeymaps(keyboard) < 0 ) { | |
255 return(-1); | |
256 } | |
257 keyboard_seteventhandler(SVGA_keyboardcallback); | |
258 | |
259 /* Determine the screen depth (use default 8-bit depth) */ | |
260 vformat->BitsPerPixel = 8; | |
261 | |
262 /* Enumerate the available fullscreen modes */ | |
263 total_modes = 0; | |
264 for ( mode=vga_lastmodenumber(); mode; --mode ) { | |
265 if ( vga_hasmode(mode) ) { | |
266 if ( SVGA_AddMode(this, mode, 0, 0) ) { | |
267 ++total_modes; | |
268 } | |
269 } | |
270 } | |
271 if ( SVGA_AddMode(this, G320x200x256, 0, 1) ) ++total_modes; | |
272 if ( total_modes == 0 ) { | |
273 SDL_SetError("No linear video modes available"); | |
274 return(-1); | |
275 } | |
276 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
|
277 SDL_vgamode[i] = (int *)SDL_malloc(SDL_nummodes[i]*sizeof(int)); |
0 | 278 if ( SDL_vgamode[i] == NULL ) { |
279 SDL_OutOfMemory(); | |
280 return(-1); | |
281 } | |
282 SDL_modelist[i] = (SDL_Rect **) | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
283 SDL_malloc((SDL_nummodes[i]+1)*sizeof(SDL_Rect *)); |
0 | 284 if ( SDL_modelist[i] == NULL ) { |
285 SDL_OutOfMemory(); | |
286 return(-1); | |
287 } | |
288 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
|
289 SDL_modelist[i][j]=(SDL_Rect *)SDL_malloc(sizeof(SDL_Rect)); |
0 | 290 if ( SDL_modelist[i][j] == NULL ) { |
291 SDL_OutOfMemory(); | |
292 return(-1); | |
293 } | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
294 SDL_memset(SDL_modelist[i][j], 0, sizeof(SDL_Rect)); |
0 | 295 } |
296 SDL_modelist[i][j] = NULL; | |
297 } | |
298 for ( mode=vga_lastmodenumber(); mode; --mode ) { | |
299 if ( vga_hasmode(mode) ) { | |
300 SVGA_AddMode(this, mode, 1, 0); | |
301 } | |
302 } | |
303 SVGA_AddMode(this, G320x200x256, 1, 1); | |
304 | |
305 /* Free extra (duplicated) modes */ | |
306 for ( i=0; i<NUM_MODELISTS; ++i ) { | |
307 j = 0; | |
308 while ( SDL_modelist[i][j] && SDL_modelist[i][j]->w ) { | |
309 j++; | |
310 } | |
311 while ( SDL_modelist[i][j] ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
312 SDL_free(SDL_modelist[i][j]); |
0 | 313 SDL_modelist[i][j] = NULL; |
314 j++; | |
315 } | |
316 } | |
317 | |
318 /* Fill in our hardware acceleration capabilities */ | |
319 SVGA_UpdateVideoInfo(this); | |
320 | |
321 /* We're done! */ | |
322 return(0); | |
323 } | |
324 | |
325 SDL_Rect **SVGA_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | |
326 { | |
327 return(SDL_modelist[((format->BitsPerPixel+7)/8)-1]); | |
328 } | |
329 | |
330 /* Various screen update functions available */ | |
331 static void SVGA_DirectUpdate(_THIS, int numrects, SDL_Rect *rects); | |
332 static void SVGA_BankedUpdate(_THIS, int numrects, SDL_Rect *rects); | |
333 | |
334 SDL_Surface *SVGA_SetVideoMode(_THIS, SDL_Surface *current, | |
335 int width, int height, int bpp, Uint32 flags) | |
336 { | |
337 int mode; | |
338 int vgamode; | |
339 vga_modeinfo *modeinfo; | |
205
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
340 int screenpage_len; |
0 | 341 |
342 /* Try to set the requested linear video mode */ | |
343 bpp = (bpp+7)/8-1; | |
344 for ( mode=0; SDL_modelist[bpp][mode]; ++mode ) { | |
345 if ( (SDL_modelist[bpp][mode]->w == width) && | |
346 (SDL_modelist[bpp][mode]->h == height) ) { | |
347 break; | |
348 } | |
349 } | |
350 if ( SDL_modelist[bpp][mode] == NULL ) { | |
351 SDL_SetError("Couldn't find requested mode in list"); | |
352 return(NULL); | |
353 } | |
354 vga_setmode(SDL_vgamode[bpp][mode]); | |
355 vga_setpage(0); | |
356 | |
357 vgamode=SDL_vgamode[bpp][mode]; | |
358 if ((vga_setlinearaddressing()<0) && (vgamode!=G320x200x256)) { | |
359 SDL_SetError("Unable to set linear addressing"); | |
360 return(NULL); | |
361 } | |
362 modeinfo = vga_getmodeinfo(SDL_vgamode[bpp][mode]); | |
363 | |
364 /* Update hardware acceleration info */ | |
365 SVGA_UpdateVideoInfo(this); | |
366 | |
367 /* Allocate the new pixel format for the screen */ | |
368 bpp = (bpp+1)*8; | |
369 if ( (bpp == 16) && (modeinfo->colors == 32768) ) { | |
370 bpp = 15; | |
371 } | |
372 if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) { | |
373 return(NULL); | |
374 } | |
375 | |
376 /* Set up the new mode framebuffer */ | |
377 current->flags = (SDL_FULLSCREEN|SDL_HWSURFACE); | |
1
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
378 if ( bpp == 8 ) { |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
379 /* FIXME: What about DirectColor? */ |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
380 current->flags |= SDL_HWPALETTE; |
cf2af46e9e2a
Changes since SDL 1.2.0 release
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
381 } |
0 | 382 current->w = width; |
383 current->h = height; | |
384 current->pitch = modeinfo->linewidth; | |
385 current->pixels = vga_getgraphmem(); | |
386 | |
205
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
387 /* set double-buffering */ |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
388 if ( flags & SDL_DOUBLEBUF ) |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
389 { |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
390 /* 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
|
391 screenpage_len=current->h*modeinfo->linewidth; |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
392 |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
393 /* if start address should be aligned */ |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
394 if ( modeinfo->linewidth_unit ) |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
395 { |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
396 if ( screenpage_len % modeinfo->linewidth_unit ) |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
397 { |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
398 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
|
399 } |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
400 } |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
401 |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
402 /* 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
|
403 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
|
404 { |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
405 current->flags |= SDL_DOUBLEBUF; |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
406 flip_page = 0; |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
407 flip_offset[0] = 0; |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
408 flip_offset[1] = screenpage_len; |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
409 flip_address[0] = vga_getgraphmem(); |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
410 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
|
411 SVGA_FlipHWSurface(this,current); |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
412 } |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
413 } |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
414 |
0 | 415 /* Set the blit function */ |
416 this->UpdateRects = SVGA_DirectUpdate; | |
417 | |
418 /* Set up the mouse handler again (buggy SVGAlib 1.40) */ | |
419 mouse_seteventhandler(SVGA_mousecallback); | |
420 | |
421 /* We're done */ | |
422 return(current); | |
423 } | |
424 | |
425 /* We don't actually allow hardware surfaces other than the main one */ | |
426 static int SVGA_AllocHWSurface(_THIS, SDL_Surface *surface) | |
427 { | |
428 return(-1); | |
429 } | |
430 static void SVGA_FreeHWSurface(_THIS, SDL_Surface *surface) | |
431 { | |
432 return; | |
433 } | |
434 | |
435 /* We need to wait for vertical retrace on page flipped displays */ | |
436 static int SVGA_LockHWSurface(_THIS, SDL_Surface *surface) | |
437 { | |
205
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
438 /* The waiting is done in SVGA_FlipHWSurface() */ |
0 | 439 return(0); |
440 } | |
441 static void SVGA_UnlockHWSurface(_THIS, SDL_Surface *surface) | |
442 { | |
443 return; | |
444 } | |
445 | |
446 static int SVGA_FlipHWSurface(_THIS, SDL_Surface *surface) | |
447 { | |
205
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
448 vga_setdisplaystart(flip_offset[flip_page]); |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
449 flip_page=!flip_page; |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
450 surface->pixels=flip_address[flip_page]; |
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
451 vga_waitretrace(); |
0 | 452 return(0); |
453 } | |
454 | |
455 static void SVGA_DirectUpdate(_THIS, int numrects, SDL_Rect *rects) | |
456 { | |
457 return; | |
458 } | |
459 | |
460 /* FIXME: Can this be used under SVGAlib? */ | |
461 static void SVGA_BankedUpdate(_THIS, int numrects, SDL_Rect *rects) | |
462 { | |
463 return; | |
464 } | |
465 | |
466 int SVGA_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) | |
467 { | |
468 int i; | |
469 | |
470 for(i = 0; i < ncolors; i++) { | |
471 vga_setpalette(firstcolor + i, | |
472 colors[i].r>>2, | |
473 colors[i].g>>2, | |
474 colors[i].b>>2); | |
475 } | |
476 return(1); | |
477 } | |
478 | |
479 /* Note: If we are terminated, this could be called in the middle of | |
480 another SDL video routine -- notably UpdateRects. | |
481 */ | |
482 void SVGA_VideoQuit(_THIS) | |
483 { | |
484 int i, j; | |
485 | |
486 /* Reset the console video mode */ | |
487 if ( this->screen && (this->screen->w && this->screen->h) ) { | |
488 vga_setmode(TEXT); | |
489 } | |
490 keyboard_close(); | |
491 | |
492 /* Free video mode lists */ | |
493 for ( i=0; i<NUM_MODELISTS; ++i ) { | |
494 if ( SDL_modelist[i] != NULL ) { | |
495 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
|
496 SDL_free(SDL_modelist[i][j]); |
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
497 SDL_free(SDL_modelist[i]); |
0 | 498 SDL_modelist[i] = NULL; |
499 } | |
500 if ( SDL_vgamode[i] != NULL ) { | |
1336
3692456e7b0f
Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents:
1312
diff
changeset
|
501 SDL_free(SDL_vgamode[i]); |
0 | 502 SDL_vgamode[i] = NULL; |
503 } | |
504 } | |
505 if ( this->screen && (this->screen->flags & SDL_HWSURFACE) ) { | |
506 /* Direct screen access, no memory buffer */ | |
507 this->screen->pixels = NULL; | |
508 } | |
509 } | |
205
13161d3d349d
Added double-buffering support for SVGAlib (thanks Kutak!)
Sam Lantinga <slouken@libsdl.org>
parents:
67
diff
changeset
|
510 |