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