Mercurial > sdl-ios-xcode
annotate src/video/fbcon/SDL_fbvideo.c @ 106:63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Fixed matrox blit bug where src Y less than dst Y
Fixed hardware surface init when no resolution change
author | Sam Lantinga <slouken@lokigames.com> |
---|---|
date | Fri, 13 Jul 2001 10:19:51 +0000 |
parents | e85e03f195b4 |
children | 5d4bafca35cd |
rev | line source |
---|---|
0 | 1 /* |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga | |
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 | |
20 slouken@devolution.com | |
21 */ | |
22 | |
23 #ifdef SAVE_RCSID | |
24 static char rcsid = | |
25 "@(#) $Id$"; | |
26 #endif | |
27 | |
28 /* Framebuffer console based SDL video driver implementation. | |
29 */ | |
30 | |
31 #include <stdlib.h> | |
32 #include <stdio.h> | |
33 #include <string.h> | |
34 #include <fcntl.h> | |
35 #include <unistd.h> | |
36 #include <sys/ioctl.h> | |
37 #include <sys/mman.h> | |
38 #include <asm/page.h> /* For definition of PAGE_SIZE */ | |
39 | |
40 #include "SDL.h" | |
41 #include "SDL_error.h" | |
42 #include "SDL_video.h" | |
43 #include "SDL_mouse.h" | |
44 #include "SDL_sysvideo.h" | |
45 #include "SDL_pixels_c.h" | |
46 #include "SDL_events_c.h" | |
47 #include "SDL_fbvideo.h" | |
48 #include "SDL_fbmouse_c.h" | |
49 #include "SDL_fbevents_c.h" | |
50 #include "SDL_fb3dfx.h" | |
51 #include "SDL_fbmatrox.h" | |
52 | |
53 #if defined(i386) && defined(FB_TYPE_VGA_PLANES) | |
54 #define VGA16_FBCON_SUPPORT | |
55 #ifndef FB_AUX_VGA_PLANES_VGA4 | |
56 #define FB_AUX_VGA_PLANES_VGA4 0 | |
57 #endif | |
58 static inline void outb (unsigned char value, unsigned short port) | |
59 { | |
60 __asm__ __volatile__ ("outb %b0,%w1"::"a" (value), "Nd" (port)); | |
61 } | |
62 #endif /* FB_TYPE_VGA_PLANES */ | |
63 | |
64 /* A list of video resolutions that we query for (sorted largest to smallest) */ | |
91
e85e03f195b4
From: "Markus F.X.J. Oberhumer"
Sam Lantinga <slouken@lokigames.com>
parents:
6
diff
changeset
|
65 static const SDL_Rect checkres[] = { |
0 | 66 { 0, 0, 1600, 1200 }, /* 16 bpp: 0x11E, or 286 */ |
67 { 0, 0, 1408, 1056 }, /* 16 bpp: 0x19A, or 410 */ | |
68 { 0, 0, 1280, 1024 }, /* 16 bpp: 0x11A, or 282 */ | |
69 { 0, 0, 1152, 864 }, /* 16 bpp: 0x192, or 402 */ | |
70 { 0, 0, 1024, 768 }, /* 16 bpp: 0x117, or 279 */ | |
71 { 0, 0, 960, 720 }, /* 16 bpp: 0x18A, or 394 */ | |
72 { 0, 0, 800, 600 }, /* 16 bpp: 0x114, or 276 */ | |
73 { 0, 0, 768, 576 }, /* 16 bpp: 0x182, or 386 */ | |
74 { 0, 0, 640, 480 }, /* 16 bpp: 0x111, or 273 */ | |
75 { 0, 0, 640, 400 }, /* 8 bpp: 0x100, or 256 */ | |
76 { 0, 0, 512, 384 }, | |
77 { 0, 0, 320, 240 }, | |
78 { 0, 0, 320, 200 } | |
79 }; | |
91
e85e03f195b4
From: "Markus F.X.J. Oberhumer"
Sam Lantinga <slouken@lokigames.com>
parents:
6
diff
changeset
|
80 static const struct { |
0 | 81 int xres; |
82 int yres; | |
83 int pixclock; | |
84 int left; | |
85 int right; | |
86 int upper; | |
87 int lower; | |
88 int hslen; | |
89 int vslen; | |
90 int sync; | |
91 int vmode; | |
92 } vesa_timings[] = { | |
93 #ifdef USE_VESA_TIMINGS /* Only tested on Matrox Millenium I */ | |
94 { 640, 400, 39771, 48, 16, 39, 8, 96, 2, 2, 0 }, /* 70 Hz */ | |
95 { 640, 480, 39683, 48, 16, 33, 10, 96, 2, 0, 0 }, /* 60 Hz */ | |
96 { 768, 576, 26101, 144, 16, 28, 6, 112, 4, 0, 0 }, /* 60 Hz */ | |
97 { 800, 600, 24038, 144, 24, 28, 8, 112, 6, 0, 0 }, /* 60 Hz */ | |
98 { 960, 720, 17686, 144, 24, 28, 8, 112, 4, 0, 0 }, /* 60 Hz */ | |
99 { 1024, 768, 15386, 160, 32, 30, 4, 128, 4, 0, 0 }, /* 60 Hz */ | |
100 { 1152, 864, 12286, 192, 32, 30, 4, 128, 4, 0, 0 }, /* 60 Hz */ | |
101 { 1280, 1024, 9369, 224, 32, 32, 4, 136, 4, 0, 0 }, /* 60 Hz */ | |
102 { 1408, 1056, 8214, 256, 40, 32, 5, 144, 5, 0, 0 }, /* 60 Hz */ | |
103 { 1600, 1200,/*?*/0, 272, 48, 32, 5, 152, 5, 0, 0 }, /* 60 Hz */ | |
104 #else | |
105 /* You can generate these timings from your XF86Config file using | |
106 the 'modeline2fb' perl script included with the fbset package. | |
107 These timings were generated for Matrox Millenium I, 15" monitor. | |
108 */ | |
109 { 320, 200, 79440, 16, 16, 20, 4, 48, 1, 0, 2 }, /* 70 Hz */ | |
110 { 320, 240, 63492, 16, 16, 16, 4, 48, 2, 0, 2 }, /* 72 Hz */ | |
111 { 512, 384, 49603, 48, 16, 16, 1, 64, 3, 0, 0 }, /* 78 Hz */ | |
112 { 640, 400, 31746, 96, 32, 41, 1, 64, 3, 2, 0 }, /* 85 Hz */ | |
113 { 640, 480, 31746, 120, 16, 16, 1, 64, 3, 0, 0 }, /* 75 Hz */ | |
114 { 768, 576, 26101, 144, 16, 28, 6, 112, 4, 0, 0 }, /* 60 Hz */ | |
115 { 800, 600, 20000, 64, 56, 23, 37, 120, 6, 3, 0 }, /* 72 Hz */ | |
116 { 960, 720, 17686, 144, 24, 28, 8, 112, 4, 0, 0 }, /* 60 Hz */ | |
117 { 1024, 768, 13333, 144, 24, 29, 3, 136, 6, 0, 0 }, /* 70 Hz */ | |
118 { 1152, 864, 12286, 192, 32, 30, 4, 128, 4, 0, 0 }, /* 60 Hz */ | |
119 { 1280, 1024, 9369, 224, 32, 32, 4, 136, 4, 0, 0 }, /* 60 Hz */ | |
120 { 1408, 1056, 8214, 256, 40, 32, 5, 144, 5, 0, 0 }, /* 60 Hz */ | |
121 { 1600, 1200,/*?*/0, 272, 48, 32, 5, 152, 5, 0, 0 }, /* 60 Hz */ | |
122 #endif | |
123 }; | |
124 | |
125 /* Initialization/Query functions */ | |
126 static int FB_VideoInit(_THIS, SDL_PixelFormat *vformat); | |
127 static SDL_Rect **FB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags); | |
128 static SDL_Surface *FB_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); | |
129 #ifdef VGA16_FBCON_SUPPORT | |
130 static SDL_Surface *FB_SetVGA16Mode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags); | |
131 #endif | |
132 static int FB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors); | |
133 static void FB_VideoQuit(_THIS); | |
134 | |
135 /* Hardware surface functions */ | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
136 static int FB_InitHWSurfaces(_THIS, SDL_Surface *screen, char *base, int size); |
0 | 137 static void FB_FreeHWSurfaces(_THIS); |
138 static int FB_AllocHWSurface(_THIS, SDL_Surface *surface); | |
139 static int FB_LockHWSurface(_THIS, SDL_Surface *surface); | |
140 static void FB_UnlockHWSurface(_THIS, SDL_Surface *surface); | |
141 static void FB_FreeHWSurface(_THIS, SDL_Surface *surface); | |
142 static void FB_WaitVBL(_THIS); | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
143 static void FB_WaitIdle(_THIS); |
0 | 144 static int FB_FlipHWSurface(_THIS, SDL_Surface *surface); |
145 | |
146 /* Internal palette functions */ | |
147 static void FB_SavePalette(_THIS, struct fb_fix_screeninfo *finfo, | |
148 struct fb_var_screeninfo *vinfo); | |
149 static void FB_RestorePalette(_THIS); | |
150 | |
151 /* FB driver bootstrap functions */ | |
152 | |
153 static int FB_Available(void) | |
154 { | |
155 int console; | |
156 const char *SDL_fbdev; | |
157 | |
158 SDL_fbdev = getenv("SDL_FBDEV"); | |
159 if ( SDL_fbdev == NULL ) { | |
160 SDL_fbdev = "/dev/fb0"; | |
161 } | |
162 console = open(SDL_fbdev, O_RDWR, 0); | |
163 if ( console >= 0 ) { | |
164 close(console); | |
165 } | |
166 return(console >= 0); | |
167 } | |
168 | |
169 static void FB_DeleteDevice(SDL_VideoDevice *device) | |
170 { | |
171 free(device->hidden); | |
172 free(device); | |
173 } | |
174 | |
175 static SDL_VideoDevice *FB_CreateDevice(int devindex) | |
176 { | |
177 SDL_VideoDevice *this; | |
178 | |
179 /* Initialize all variables that we clean on shutdown */ | |
180 this = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice)); | |
181 if ( this ) { | |
182 memset(this, 0, (sizeof *this)); | |
183 this->hidden = (struct SDL_PrivateVideoData *) | |
184 malloc((sizeof *this->hidden)); | |
185 } | |
186 if ( (this == NULL) || (this->hidden == NULL) ) { | |
187 SDL_OutOfMemory(); | |
188 if ( this ) { | |
189 free(this); | |
190 } | |
191 return(0); | |
192 } | |
193 memset(this->hidden, 0, (sizeof *this->hidden)); | |
194 wait_vbl = FB_WaitVBL; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
195 wait_idle = FB_WaitIdle; |
0 | 196 mouse_fd = -1; |
197 keyboard_fd = -1; | |
198 | |
199 /* Set the function pointers */ | |
200 this->VideoInit = FB_VideoInit; | |
201 this->ListModes = FB_ListModes; | |
202 this->SetVideoMode = FB_SetVideoMode; | |
203 this->SetColors = FB_SetColors; | |
204 this->UpdateRects = NULL; | |
205 this->VideoQuit = FB_VideoQuit; | |
206 this->AllocHWSurface = FB_AllocHWSurface; | |
207 this->CheckHWBlit = NULL; | |
208 this->FillHWRect = NULL; | |
209 this->SetHWColorKey = NULL; | |
210 this->SetHWAlpha = NULL; | |
211 this->LockHWSurface = FB_LockHWSurface; | |
212 this->UnlockHWSurface = FB_UnlockHWSurface; | |
213 this->FlipHWSurface = FB_FlipHWSurface; | |
214 this->FreeHWSurface = FB_FreeHWSurface; | |
215 this->SetCaption = NULL; | |
216 this->SetIcon = NULL; | |
217 this->IconifyWindow = NULL; | |
218 this->GrabInput = NULL; | |
219 this->GetWMInfo = NULL; | |
220 this->InitOSKeymap = FB_InitOSKeymap; | |
221 this->PumpEvents = FB_PumpEvents; | |
222 | |
223 this->free = FB_DeleteDevice; | |
224 | |
225 return this; | |
226 } | |
227 | |
228 VideoBootStrap FBCON_bootstrap = { | |
229 "fbcon", "Linux Framebuffer Console", | |
230 FB_Available, FB_CreateDevice | |
231 }; | |
232 | |
233 static int FB_CheckMode(_THIS, struct fb_var_screeninfo *vinfo, | |
234 int index, unsigned int *w, unsigned int *h) | |
235 { | |
236 int mode_okay; | |
237 | |
238 mode_okay = 0; | |
239 vinfo->bits_per_pixel = (index+1)*8; | |
240 vinfo->xres = *w; | |
241 vinfo->xres_virtual = *w; | |
242 vinfo->yres = *h; | |
243 vinfo->yres_virtual = *h; | |
244 vinfo->activate = FB_ACTIVATE_TEST; | |
245 if ( ioctl(console_fd, FBIOPUT_VSCREENINFO, vinfo) == 0 ) { | |
246 #ifdef FBCON_DEBUG | |
247 fprintf(stderr, "Checked mode %dx%d at %d bpp, got mode %dx%d at %d bpp\n", *w, *h, (index+1)*8, vinfo->xres, vinfo->yres, vinfo->bits_per_pixel); | |
248 #endif | |
249 if ( (((vinfo->bits_per_pixel+7)/8)-1) == index ) { | |
250 *w = vinfo->xres; | |
251 *h = vinfo->yres; | |
252 mode_okay = 1; | |
253 } | |
254 } | |
255 return mode_okay; | |
256 } | |
257 | |
258 static int FB_AddMode(_THIS, int index, unsigned int w, unsigned int h) | |
259 { | |
260 SDL_Rect *mode; | |
261 int i; | |
262 int next_mode; | |
263 | |
264 /* Check to see if we already have this mode */ | |
265 if ( SDL_nummodes[index] > 0 ) { | |
266 mode = SDL_modelist[index][SDL_nummodes[index]-1]; | |
267 if ( (mode->w == w) && (mode->h == h) ) { | |
268 #ifdef FBCON_DEBUG | |
269 fprintf(stderr, "We already have mode %dx%d at %d bytes per pixel\n", w, h, index+1); | |
270 #endif | |
271 return(0); | |
272 } | |
273 } | |
274 | |
275 /* Only allow a mode if we have a valid timing for it */ | |
6
332f458469f0
Fixed 320x200 video mode on framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
276 next_mode = -1; |
0 | 277 for ( i=0; i<(sizeof(vesa_timings)/sizeof(vesa_timings[0])); ++i ) { |
278 if ( (w == vesa_timings[i].xres) && | |
279 (h == vesa_timings[i].yres) && vesa_timings[i].pixclock ) { | |
280 next_mode = i; | |
281 break; | |
282 } | |
283 } | |
6
332f458469f0
Fixed 320x200 video mode on framebuffer console
Sam Lantinga <slouken@lokigames.com>
parents:
0
diff
changeset
|
284 if ( next_mode == -1 ) { |
0 | 285 #ifdef FBCON_DEBUG |
286 fprintf(stderr, "No valid timing line for mode %dx%d\n", w, h); | |
287 #endif | |
288 return(0); | |
289 } | |
290 | |
291 /* Set up the new video mode rectangle */ | |
292 mode = (SDL_Rect *)malloc(sizeof *mode); | |
293 if ( mode == NULL ) { | |
294 SDL_OutOfMemory(); | |
295 return(-1); | |
296 } | |
297 mode->x = 0; | |
298 mode->y = 0; | |
299 mode->w = w; | |
300 mode->h = h; | |
301 #ifdef FBCON_DEBUG | |
302 fprintf(stderr, "Adding mode %dx%d at %d bytes per pixel\n", w, h, index+1); | |
303 #endif | |
304 | |
305 /* Allocate the new list of modes, and fill in the new mode */ | |
306 next_mode = SDL_nummodes[index]; | |
307 SDL_modelist[index] = (SDL_Rect **) | |
308 realloc(SDL_modelist[index], (1+next_mode+1)*sizeof(SDL_Rect *)); | |
309 if ( SDL_modelist[index] == NULL ) { | |
310 SDL_OutOfMemory(); | |
311 SDL_nummodes[index] = 0; | |
312 free(mode); | |
313 return(-1); | |
314 } | |
315 SDL_modelist[index][next_mode] = mode; | |
316 SDL_modelist[index][next_mode+1] = NULL; | |
317 SDL_nummodes[index]++; | |
318 | |
319 return(0); | |
320 } | |
321 | |
322 static int FB_VideoInit(_THIS, SDL_PixelFormat *vformat) | |
323 { | |
324 struct fb_fix_screeninfo finfo; | |
325 struct fb_var_screeninfo vinfo; | |
326 int i, j; | |
327 int current_index; | |
328 unsigned int current_w; | |
329 unsigned int current_h; | |
330 const char *SDL_fbdev; | |
331 | |
332 /* Initialize the library */ | |
333 SDL_fbdev = getenv("SDL_FBDEV"); | |
334 if ( SDL_fbdev == NULL ) { | |
335 SDL_fbdev = "/dev/fb0"; | |
336 } | |
337 console_fd = open(SDL_fbdev, O_RDWR, 0); | |
338 if ( console_fd < 0 ) { | |
339 SDL_SetError("Unable to open %s", SDL_fbdev); | |
340 return(-1); | |
341 } | |
342 | |
343 #ifndef DISABLE_THREADS | |
344 /* Create the hardware surface lock mutex */ | |
345 hw_lock = SDL_CreateMutex(); | |
346 if ( hw_lock == NULL ) { | |
347 SDL_SetError("Unable to create lock mutex"); | |
348 FB_VideoQuit(this); | |
349 return(-1); | |
350 } | |
351 #endif | |
352 | |
353 /* Get the type of video hardware */ | |
354 if ( ioctl(console_fd, FBIOGET_FSCREENINFO, &finfo) < 0 ) { | |
355 SDL_SetError("Couldn't get console hardware info"); | |
356 FB_VideoQuit(this); | |
357 return(-1); | |
358 } | |
359 switch (finfo.type) { | |
360 case FB_TYPE_PACKED_PIXELS: | |
361 /* Supported, no worries.. */ | |
362 break; | |
363 #ifdef VGA16_FBCON_SUPPORT | |
364 case FB_TYPE_VGA_PLANES: | |
365 /* VGA16 is supported, but that's it */ | |
366 if ( finfo.type_aux == FB_AUX_VGA_PLANES_VGA4 ) { | |
367 if ( ioperm(0x3b4, 0x3df - 0x3b4 + 1, 1) < 0 ) { | |
368 SDL_SetError("No I/O port permissions"); | |
369 FB_VideoQuit(this); | |
370 return(-1); | |
371 } | |
372 this->SetVideoMode = FB_SetVGA16Mode; | |
373 break; | |
374 } | |
375 /* Fall through to unsupported case */ | |
376 #endif /* VGA16_FBCON_SUPPORT */ | |
377 default: | |
378 SDL_SetError("Unsupported console hardware"); | |
379 FB_VideoQuit(this); | |
380 return(-1); | |
381 } | |
382 switch (finfo.visual) { | |
383 case FB_VISUAL_TRUECOLOR: | |
384 case FB_VISUAL_PSEUDOCOLOR: | |
385 case FB_VISUAL_STATIC_PSEUDOCOLOR: | |
386 case FB_VISUAL_DIRECTCOLOR: | |
387 break; | |
388 default: | |
389 SDL_SetError("Unsupported console hardware"); | |
390 FB_VideoQuit(this); | |
391 return(-1); | |
392 } | |
393 | |
394 /* Check if the user wants to disable hardware acceleration */ | |
395 { const char *fb_accel; | |
396 fb_accel = getenv("SDL_FBACCEL"); | |
397 if ( fb_accel ) { | |
398 finfo.accel = atoi(fb_accel); | |
399 } | |
400 } | |
401 | |
402 /* Memory map the device, compensating for buggy PPC mmap() */ | |
403 mapped_offset = (((long)finfo.smem_start) - | |
404 (((long)finfo.smem_start)&~(PAGE_SIZE-1))); | |
405 mapped_memlen = finfo.smem_len+mapped_offset; | |
406 mapped_mem = mmap(NULL, mapped_memlen, | |
407 PROT_READ|PROT_WRITE, MAP_SHARED, console_fd, 0); | |
408 if ( mapped_mem == (char *)-1 ) { | |
409 SDL_SetError("Unable to memory map the video hardware"); | |
410 mapped_mem = NULL; | |
411 FB_VideoQuit(this); | |
412 return(-1); | |
413 } | |
414 | |
415 /* Determine the current screen depth */ | |
416 if ( ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0 ) { | |
417 SDL_SetError("Couldn't get console pixel format"); | |
418 FB_VideoQuit(this); | |
419 return(-1); | |
420 } | |
421 vformat->BitsPerPixel = vinfo.bits_per_pixel; | |
422 if ( vformat->BitsPerPixel < 8 ) { | |
423 /* Assuming VGA16, we handle this via a shadow framebuffer */ | |
424 vformat->BitsPerPixel = 8; | |
425 } | |
426 for ( i=0; i<vinfo.red.length; ++i ) { | |
427 vformat->Rmask <<= 1; | |
428 vformat->Rmask |= (0x00000001<<vinfo.red.offset); | |
429 } | |
430 for ( i=0; i<vinfo.green.length; ++i ) { | |
431 vformat->Gmask <<= 1; | |
432 vformat->Gmask |= (0x00000001<<vinfo.green.offset); | |
433 } | |
434 for ( i=0; i<vinfo.blue.length; ++i ) { | |
435 vformat->Bmask <<= 1; | |
436 vformat->Bmask |= (0x00000001<<vinfo.blue.offset); | |
437 } | |
438 saved_vinfo = vinfo; | |
439 | |
440 /* Save hardware palette, if needed */ | |
441 FB_SavePalette(this, &finfo, &vinfo); | |
442 | |
443 /* If the I/O registers are available, memory map them so we | |
444 can take advantage of any supported hardware acceleration. | |
445 */ | |
446 vinfo.accel_flags = 0; /* Temporarily reserve registers */ | |
447 ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo); | |
448 if ( finfo.accel && finfo.mmio_len ) { | |
449 mapped_iolen = finfo.mmio_len; | |
450 mapped_io = mmap(NULL, mapped_iolen, PROT_READ|PROT_WRITE, | |
451 MAP_SHARED, console_fd, mapped_memlen); | |
452 if ( mapped_io == (char *)-1 ) { | |
453 /* Hmm, failed to memory map I/O registers */ | |
454 mapped_io = NULL; | |
455 } | |
456 } | |
457 | |
458 /* Query for the list of available video modes */ | |
459 current_w = vinfo.xres; | |
460 current_h = vinfo.yres; | |
461 current_index = ((vinfo.bits_per_pixel+7)/8)-1; | |
462 for ( i=0; i<NUM_MODELISTS; ++i ) { | |
463 SDL_nummodes[i] = 0; | |
464 SDL_modelist[i] = NULL; | |
465 for ( j=0; j<(sizeof(checkres)/sizeof(checkres[0])); ++j ) { | |
466 unsigned int w, h; | |
467 | |
468 /* See if we are querying for the current mode */ | |
469 w = checkres[j].w; | |
470 h = checkres[j].h; | |
471 if ( i == current_index ) { | |
472 if ( (current_w > w) || (current_h > h) ) { | |
473 /* Only check once */ | |
474 FB_AddMode(this, i,current_w,current_h); | |
475 current_index = -1; | |
476 } | |
477 } | |
478 if ( FB_CheckMode(this, &vinfo, i, &w, &h) ) { | |
479 FB_AddMode(this, i, w, h); | |
480 } | |
481 } | |
482 } | |
483 | |
484 /* Fill in our hardware acceleration capabilities */ | |
485 this->info.wm_available = 0; | |
486 this->info.hw_available = 1; | |
487 this->info.video_mem = finfo.smem_len/1024; | |
488 if ( mapped_io ) { | |
489 switch (finfo.accel) { | |
490 case FB_ACCEL_MATROX_MGA2064W: | |
491 case FB_ACCEL_MATROX_MGA1064SG: | |
492 case FB_ACCEL_MATROX_MGA2164W: | |
493 case FB_ACCEL_MATROX_MGA2164W_AGP: | |
494 case FB_ACCEL_MATROX_MGAG100: | |
495 /*case FB_ACCEL_MATROX_MGAG200: G200 acceleration broken! */ | |
496 case FB_ACCEL_MATROX_MGAG400: | |
497 #ifdef FBACCEL_DEBUG | |
498 printf("Matrox hardware accelerator!\n"); | |
499 #endif | |
500 FB_MatroxAccel(this, finfo.accel); | |
501 break; | |
502 case FB_ACCEL_3DFX_BANSHEE: | |
503 #ifdef FBACCEL_DEBUG | |
504 printf("3DFX hardware accelerator!\n"); | |
505 #endif | |
506 FB_3DfxAccel(this, finfo.accel); | |
507 break; | |
508 default: | |
509 #ifdef FBACCEL_DEBUG | |
510 printf("Unknown hardware accelerator.\n"); | |
511 #endif | |
512 break; | |
513 } | |
514 } | |
515 | |
516 /* Enable mouse and keyboard support */ | |
517 if ( FB_OpenKeyboard(this) < 0 ) { | |
518 FB_VideoQuit(this); | |
519 return(-1); | |
520 } | |
521 if ( FB_OpenMouse(this) < 0 ) { | |
522 const char *sdl_nomouse; | |
523 | |
524 sdl_nomouse = getenv("SDL_NOMOUSE"); | |
525 if ( ! sdl_nomouse ) { | |
526 SDL_SetError("Unable to open mouse"); | |
527 FB_VideoQuit(this); | |
528 return(-1); | |
529 } | |
530 } | |
531 | |
532 /* We're done! */ | |
533 return(0); | |
534 } | |
535 | |
536 static SDL_Rect **FB_ListModes(_THIS, SDL_PixelFormat *format, Uint32 flags) | |
537 { | |
538 return(SDL_modelist[((format->BitsPerPixel+7)/8)-1]); | |
539 } | |
540 | |
541 /* Various screen update functions available */ | |
542 static void FB_DirectUpdate(_THIS, int numrects, SDL_Rect *rects); | |
543 #ifdef VGA16_FBCON_SUPPORT | |
544 static void FB_VGA16Update(_THIS, int numrects, SDL_Rect *rects); | |
545 #endif | |
546 | |
547 #ifdef FBCON_DEBUG | |
548 static void print_vinfo(struct fb_var_screeninfo *vinfo) | |
549 { | |
550 fprintf(stderr, "Printing vinfo:\n"); | |
551 fprintf(stderr, "\txres: %d\n", vinfo->xres); | |
552 fprintf(stderr, "\tyres: %d\n", vinfo->yres); | |
553 fprintf(stderr, "\txres_virtual: %d\n", vinfo->xres_virtual); | |
554 fprintf(stderr, "\tyres_virtual: %d\n", vinfo->yres_virtual); | |
555 fprintf(stderr, "\txoffset: %d\n", vinfo->xoffset); | |
556 fprintf(stderr, "\tyoffset: %d\n", vinfo->yoffset); | |
557 fprintf(stderr, "\tbits_per_pixel: %d\n", vinfo->bits_per_pixel); | |
558 fprintf(stderr, "\tgrayscale: %d\n", vinfo->grayscale); | |
559 fprintf(stderr, "\tnonstd: %d\n", vinfo->nonstd); | |
560 fprintf(stderr, "\tactivate: %d\n", vinfo->activate); | |
561 fprintf(stderr, "\theight: %d\n", vinfo->height); | |
562 fprintf(stderr, "\twidth: %d\n", vinfo->width); | |
563 fprintf(stderr, "\taccel_flags: %d\n", vinfo->accel_flags); | |
564 fprintf(stderr, "\tpixclock: %d\n", vinfo->pixclock); | |
565 fprintf(stderr, "\tleft_margin: %d\n", vinfo->left_margin); | |
566 fprintf(stderr, "\tright_margin: %d\n", vinfo->right_margin); | |
567 fprintf(stderr, "\tupper_margin: %d\n", vinfo->upper_margin); | |
568 fprintf(stderr, "\tlower_margin: %d\n", vinfo->lower_margin); | |
569 fprintf(stderr, "\thsync_len: %d\n", vinfo->hsync_len); | |
570 fprintf(stderr, "\tvsync_len: %d\n", vinfo->vsync_len); | |
571 fprintf(stderr, "\tsync: %d\n", vinfo->sync); | |
572 fprintf(stderr, "\tvmode: %d\n", vinfo->vmode); | |
573 fprintf(stderr, "\tred: %d/%d\n", vinfo->red.length, vinfo->red.offset); | |
574 fprintf(stderr, "\tgreen: %d/%d\n", vinfo->green.length, vinfo->green.offset); | |
575 fprintf(stderr, "\tblue: %d/%d\n", vinfo->blue.length, vinfo->blue.offset); | |
576 fprintf(stderr, "\talpha: %d/%d\n", vinfo->transp.length, vinfo->transp.offset); | |
577 } | |
578 static void print_finfo(struct fb_fix_screeninfo *finfo) | |
579 { | |
580 fprintf(stderr, "Printing finfo:\n"); | |
581 fprintf(stderr, "\tsmem_start = %p\n", (char *)finfo->smem_start); | |
582 fprintf(stderr, "\tsmem_len = %d\n", finfo->smem_len); | |
583 fprintf(stderr, "\ttype = %d\n", finfo->type); | |
584 fprintf(stderr, "\ttype_aux = %d\n", finfo->type_aux); | |
585 fprintf(stderr, "\tvisual = %d\n", finfo->visual); | |
586 fprintf(stderr, "\txpanstep = %d\n", finfo->xpanstep); | |
587 fprintf(stderr, "\typanstep = %d\n", finfo->ypanstep); | |
588 fprintf(stderr, "\tywrapstep = %d\n", finfo->ywrapstep); | |
589 fprintf(stderr, "\tline_length = %d\n", finfo->line_length); | |
590 fprintf(stderr, "\tmmio_start = %p\n", (char *)finfo->mmio_start); | |
591 fprintf(stderr, "\tmmio_len = %d\n", finfo->mmio_len); | |
592 fprintf(stderr, "\taccel = %d\n", finfo->accel); | |
593 } | |
594 #endif | |
595 | |
596 static int choose_fbmodes_mode(struct fb_var_screeninfo *vinfo) | |
597 { | |
598 int matched; | |
599 FILE *fbmodes; | |
600 | |
601 matched = 0; | |
602 fbmodes = fopen("/etc/fb.modes", "r"); | |
603 if ( fbmodes ) { | |
604 /* FIXME: Parse the mode definition file */ | |
605 fclose(fbmodes); | |
606 } | |
607 return(matched); | |
608 } | |
609 | |
610 static int choose_vesa_mode(struct fb_var_screeninfo *vinfo) | |
611 { | |
612 int matched; | |
613 int i; | |
614 | |
615 /* Check for VESA timings */ | |
616 matched = 0; | |
617 for ( i=0; i<(sizeof(vesa_timings)/sizeof(vesa_timings[0])); ++i ) { | |
618 if ( (vinfo->xres == vesa_timings[i].xres) && | |
619 (vinfo->yres == vesa_timings[i].yres) ) { | |
620 #ifdef FBCON_DEBUG | |
621 fprintf(stderr, "Using VESA timings for %dx%d\n", | |
622 vinfo->xres, vinfo->yres); | |
623 #endif | |
624 if ( vesa_timings[i].pixclock ) { | |
625 vinfo->pixclock = vesa_timings[i].pixclock; | |
626 } | |
627 vinfo->left_margin = vesa_timings[i].left; | |
628 vinfo->right_margin = vesa_timings[i].right; | |
629 vinfo->upper_margin = vesa_timings[i].upper; | |
630 vinfo->lower_margin = vesa_timings[i].lower; | |
631 vinfo->hsync_len = vesa_timings[i].hslen; | |
632 vinfo->vsync_len = vesa_timings[i].vslen; | |
633 vinfo->sync = vesa_timings[i].sync; | |
634 vinfo->vmode = vesa_timings[i].vmode; | |
635 matched = 1; | |
636 break; | |
637 } | |
638 } | |
639 return(matched); | |
640 } | |
641 | |
642 #ifdef VGA16_FBCON_SUPPORT | |
643 static SDL_Surface *FB_SetVGA16Mode(_THIS, SDL_Surface *current, | |
644 int width, int height, int bpp, Uint32 flags) | |
645 { | |
646 struct fb_fix_screeninfo finfo; | |
647 struct fb_var_screeninfo vinfo; | |
648 | |
649 /* Set the terminal into graphics mode */ | |
650 if ( FB_EnterGraphicsMode(this) < 0 ) { | |
651 return(NULL); | |
652 } | |
653 | |
654 /* Restore the original palette */ | |
655 FB_RestorePalette(this); | |
656 | |
657 /* Set the video mode and get the final screen format */ | |
658 if ( ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0 ) { | |
659 SDL_SetError("Couldn't get console screen info"); | |
660 return(NULL); | |
661 } | |
662 cache_vinfo = vinfo; | |
663 #ifdef FBCON_DEBUG | |
664 fprintf(stderr, "Printing actual vinfo:\n"); | |
665 print_vinfo(&vinfo); | |
666 #endif | |
667 if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) { | |
668 return(NULL); | |
669 } | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
670 current->format->palette->ncolors = 16; |
0 | 671 |
672 /* Get the fixed information about the console hardware. | |
673 This is necessary since finfo.line_length changes. | |
674 */ | |
675 if ( ioctl(console_fd, FBIOGET_FSCREENINFO, &finfo) < 0 ) { | |
676 SDL_SetError("Couldn't get console hardware info"); | |
677 return(NULL); | |
678 } | |
679 #ifdef FBCON_DEBUG | |
680 fprintf(stderr, "Printing actual finfo:\n"); | |
681 print_finfo(&finfo); | |
682 #endif | |
683 | |
684 /* Save hardware palette, if needed */ | |
685 FB_SavePalette(this, &finfo, &vinfo); | |
686 | |
687 /* Set up the new mode framebuffer */ | |
688 current->flags = SDL_FULLSCREEN; | |
689 current->w = vinfo.xres; | |
690 current->h = vinfo.yres; | |
691 current->pitch = current->w; | |
692 current->pixels = malloc(current->h*current->pitch); | |
693 | |
694 /* Set the update rectangle function */ | |
695 this->UpdateRects = FB_VGA16Update; | |
696 | |
697 /* We're done */ | |
698 return(current); | |
699 } | |
700 #endif /* VGA16_FBCON_SUPPORT */ | |
701 | |
702 static SDL_Surface *FB_SetVideoMode(_THIS, SDL_Surface *current, | |
703 int width, int height, int bpp, Uint32 flags) | |
704 { | |
705 struct fb_fix_screeninfo finfo; | |
706 struct fb_var_screeninfo vinfo; | |
707 int i; | |
708 Uint32 Rmask; | |
709 Uint32 Gmask; | |
710 Uint32 Bmask; | |
711 char *surfaces_mem; | |
712 int surfaces_len; | |
713 | |
714 /* Set the terminal into graphics mode */ | |
715 if ( FB_EnterGraphicsMode(this) < 0 ) { | |
716 return(NULL); | |
717 } | |
718 | |
719 /* Restore the original palette */ | |
720 FB_RestorePalette(this); | |
721 | |
722 /* Set the video mode and get the final screen format */ | |
723 if ( ioctl(console_fd, FBIOGET_VSCREENINFO, &vinfo) < 0 ) { | |
724 SDL_SetError("Couldn't get console screen info"); | |
725 return(NULL); | |
726 } | |
727 #ifdef FBCON_DEBUG | |
728 fprintf(stderr, "Printing original vinfo:\n"); | |
729 print_vinfo(&vinfo); | |
730 #endif | |
731 if ( (vinfo.xres != width) || (vinfo.yres != height) || | |
732 (vinfo.bits_per_pixel != bpp) || (flags & SDL_DOUBLEBUF) ) { | |
733 vinfo.activate = FB_ACTIVATE_NOW; | |
734 vinfo.accel_flags = 0; | |
735 vinfo.bits_per_pixel = bpp; | |
736 vinfo.xres = width; | |
737 vinfo.xres_virtual = width; | |
738 vinfo.yres = height; | |
739 if ( flags & SDL_DOUBLEBUF ) { | |
740 vinfo.yres_virtual = height*2; | |
741 } else { | |
742 vinfo.yres_virtual = height; | |
743 } | |
744 vinfo.xoffset = 0; | |
745 vinfo.yoffset = 0; | |
746 vinfo.red.length = vinfo.red.offset = 0; | |
747 vinfo.green.length = vinfo.green.offset = 0; | |
748 vinfo.blue.length = vinfo.blue.offset = 0; | |
749 vinfo.transp.length = vinfo.transp.offset = 0; | |
750 if ( ! choose_fbmodes_mode(&vinfo) ) { | |
751 choose_vesa_mode(&vinfo); | |
752 } | |
753 #ifdef FBCON_DEBUG | |
754 fprintf(stderr, "Printing wanted vinfo:\n"); | |
755 print_vinfo(&vinfo); | |
756 #endif | |
757 if ( ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo) < 0 ) { | |
758 vinfo.yres_virtual = height; | |
759 if ( ioctl(console_fd, FBIOPUT_VSCREENINFO, &vinfo) < 0 ) { | |
760 SDL_SetError("Couldn't set console screen info"); | |
761 return(NULL); | |
762 } | |
763 } | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
764 } else { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
765 int maxheight; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
766 |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
767 /* Figure out how much video memory is available */ |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
768 if ( flags & SDL_DOUBLEBUF ) { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
769 maxheight = height*2; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
770 } else { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
771 maxheight = height; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
772 } |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
773 if ( vinfo.yres_virtual > maxheight ) { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
774 vinfo.yres_virtual = maxheight; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
775 } |
0 | 776 } |
777 cache_vinfo = vinfo; | |
778 #ifdef FBCON_DEBUG | |
779 fprintf(stderr, "Printing actual vinfo:\n"); | |
780 print_vinfo(&vinfo); | |
781 #endif | |
782 Rmask = 0; | |
783 for ( i=0; i<vinfo.red.length; ++i ) { | |
784 Rmask <<= 1; | |
785 Rmask |= (0x00000001<<vinfo.red.offset); | |
786 } | |
787 Gmask = 0; | |
788 for ( i=0; i<vinfo.green.length; ++i ) { | |
789 Gmask <<= 1; | |
790 Gmask |= (0x00000001<<vinfo.green.offset); | |
791 } | |
792 Bmask = 0; | |
793 for ( i=0; i<vinfo.blue.length; ++i ) { | |
794 Bmask <<= 1; | |
795 Bmask |= (0x00000001<<vinfo.blue.offset); | |
796 } | |
797 if ( ! SDL_ReallocFormat(current, vinfo.bits_per_pixel, | |
798 Rmask, Gmask, Bmask, 0) ) { | |
799 return(NULL); | |
800 } | |
801 | |
802 /* Get the fixed information about the console hardware. | |
803 This is necessary since finfo.line_length changes. | |
804 */ | |
805 if ( ioctl(console_fd, FBIOGET_FSCREENINFO, &finfo) < 0 ) { | |
806 SDL_SetError("Couldn't get console hardware info"); | |
807 return(NULL); | |
808 } | |
809 | |
810 /* Save hardware palette, if needed */ | |
811 FB_SavePalette(this, &finfo, &vinfo); | |
812 | |
813 /* Set up the new mode framebuffer */ | |
814 current->flags = (SDL_FULLSCREEN|SDL_HWSURFACE); | |
815 current->w = vinfo.xres; | |
816 current->h = vinfo.yres; | |
817 current->pitch = finfo.line_length; | |
818 current->pixels = mapped_mem+mapped_offset; | |
819 | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
820 /* Set up the information for hardware surfaces */ |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
821 surfaces_mem = (char *)current->pixels + |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
822 vinfo.yres_virtual*current->pitch; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
823 surfaces_len = (mapped_memlen-(surfaces_mem-mapped_mem)); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
824 FB_FreeHWSurfaces(this); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
825 FB_InitHWSurfaces(this, current, surfaces_mem, surfaces_len); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
826 |
0 | 827 /* Let the application know we have a hardware palette */ |
828 switch (finfo.visual) { | |
829 case FB_VISUAL_PSEUDOCOLOR: | |
830 current->flags |= SDL_HWPALETTE; | |
831 break; | |
832 default: | |
833 break; | |
834 } | |
835 | |
836 /* Update for double-buffering, if we can */ | |
837 if ( flags & SDL_DOUBLEBUF ) { | |
838 if ( vinfo.yres_virtual == (height*2) ) { | |
839 current->flags |= SDL_DOUBLEBUF; | |
840 flip_page = 0; | |
841 flip_address[0] = (char *)current->pixels; | |
842 flip_address[1] = (char *)current->pixels+ | |
843 current->h*current->pitch; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
844 this->screen = current; |
0 | 845 FB_FlipHWSurface(this, current); |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
846 this->screen = NULL; |
0 | 847 } |
848 } | |
849 | |
850 /* Set the update rectangle function */ | |
851 this->UpdateRects = FB_DirectUpdate; | |
852 | |
853 /* We're done */ | |
854 return(current); | |
855 } | |
856 | |
857 #ifdef FBCON_DEBUG | |
858 void FB_DumpHWSurfaces(_THIS) | |
859 { | |
860 vidmem_bucket *bucket; | |
861 | |
862 printf("Memory left: %d (%d total)\n", surfaces_memleft, surfaces_memtotal); | |
863 printf("\n"); | |
864 printf(" Base Size\n"); | |
865 for ( bucket=&surfaces; bucket; bucket=bucket->next ) { | |
866 printf("Bucket: %p, %d (%s)\n", bucket->base, bucket->size, bucket->used ? "used" : "free"); | |
867 if ( bucket->prev ) { | |
868 if ( bucket->base != bucket->prev->base+bucket->prev->size ) { | |
869 printf("Warning, corrupt bucket list! (prev)\n"); | |
870 } | |
871 } else { | |
872 if ( bucket != &surfaces ) { | |
873 printf("Warning, corrupt bucket list! (!prev)\n"); | |
874 } | |
875 } | |
876 if ( bucket->next ) { | |
877 if ( bucket->next->base != bucket->base+bucket->size ) { | |
878 printf("Warning, corrupt bucket list! (next)\n"); | |
879 } | |
880 } | |
881 } | |
882 printf("\n"); | |
883 } | |
884 #endif | |
885 | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
886 static int FB_InitHWSurfaces(_THIS, SDL_Surface *screen, char *base, int size) |
0 | 887 { |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
888 vidmem_bucket *bucket; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
889 |
0 | 890 surfaces_memtotal = size; |
891 surfaces_memleft = size; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
892 |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
893 if ( surfaces_memleft > 0 ) { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
894 bucket = (vidmem_bucket *)malloc(sizeof(*bucket)); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
895 if ( bucket == NULL ) { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
896 SDL_OutOfMemory(); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
897 return(-1); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
898 } |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
899 bucket->prev = &surfaces; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
900 bucket->used = 0; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
901 bucket->dirty = 0; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
902 bucket->base = base; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
903 bucket->size = size; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
904 bucket->next = NULL; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
905 } else { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
906 bucket = NULL; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
907 } |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
908 |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
909 surfaces.prev = NULL; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
910 surfaces.used = 1; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
911 surfaces.dirty = 0; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
912 surfaces.base = screen->pixels; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
913 surfaces.size = (unsigned int)((long)base - (long)surfaces.base); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
914 surfaces.next = bucket; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
915 screen->hwdata = (struct private_hwdata *)&surfaces; |
0 | 916 return(0); |
917 } | |
918 static void FB_FreeHWSurfaces(_THIS) | |
919 { | |
920 vidmem_bucket *bucket, *freeable; | |
921 | |
922 bucket = surfaces.next; | |
923 while ( bucket ) { | |
924 freeable = bucket; | |
925 bucket = bucket->next; | |
926 free(freeable); | |
927 } | |
928 surfaces.next = NULL; | |
929 } | |
930 | |
931 static int FB_AllocHWSurface(_THIS, SDL_Surface *surface) | |
932 { | |
933 vidmem_bucket *bucket; | |
934 int size; | |
935 int extra; | |
936 | |
937 /* Temporarily, we only allow surfaces the same width as display. | |
938 Some blitters require the pitch between two hardware surfaces | |
939 to be the same. Others have interesting alignment restrictions. | |
940 Until someone who knows these details looks at the code... | |
941 */ | |
942 if ( surface->pitch > SDL_VideoSurface->pitch ) { | |
943 SDL_SetError("Surface requested wider than screen"); | |
944 return(-1); | |
945 } | |
946 surface->pitch = SDL_VideoSurface->pitch; | |
947 size = surface->h * surface->pitch; | |
948 #ifdef FBCON_DEBUG | |
949 fprintf(stderr, "Allocating bucket of %d bytes\n", size); | |
950 #endif | |
951 | |
952 /* Quick check for available mem */ | |
953 if ( size > surfaces_memleft ) { | |
954 SDL_SetError("Not enough video memory"); | |
955 return(-1); | |
956 } | |
957 | |
958 /* Search for an empty bucket big enough */ | |
959 for ( bucket=&surfaces; bucket; bucket=bucket->next ) { | |
960 if ( ! bucket->used && (size <= bucket->size) ) { | |
961 break; | |
962 } | |
963 } | |
964 if ( bucket == NULL ) { | |
965 SDL_SetError("Video memory too fragmented"); | |
966 return(-1); | |
967 } | |
968 | |
969 /* Create a new bucket for left-over memory */ | |
970 extra = (bucket->size - size); | |
971 if ( extra ) { | |
972 vidmem_bucket *newbucket; | |
973 | |
974 #ifdef FBCON_DEBUG | |
975 fprintf(stderr, "Adding new free bucket of %d bytes\n", extra); | |
976 #endif | |
977 newbucket = (vidmem_bucket *)malloc(sizeof(*newbucket)); | |
978 if ( newbucket == NULL ) { | |
979 SDL_OutOfMemory(); | |
980 return(-1); | |
981 } | |
982 newbucket->prev = bucket; | |
983 newbucket->used = 0; | |
984 newbucket->base = bucket->base+size; | |
985 newbucket->size = extra; | |
986 newbucket->next = bucket->next; | |
987 if ( bucket->next ) { | |
988 bucket->next->prev = newbucket; | |
989 } | |
990 bucket->next = newbucket; | |
991 } | |
992 | |
993 /* Set the current bucket values and return it! */ | |
994 bucket->used = 1; | |
995 bucket->size = size; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
996 bucket->dirty = 0; |
0 | 997 #ifdef FBCON_DEBUG |
998 fprintf(stderr, "Allocated %d bytes at %p\n", bucket->size, bucket->base); | |
999 #endif | |
1000 surfaces_memleft -= size; | |
1001 surface->flags |= SDL_HWSURFACE; | |
1002 surface->pixels = bucket->base; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1003 surface->hwdata = (struct private_hwdata *)bucket; |
0 | 1004 return(0); |
1005 } | |
1006 static void FB_FreeHWSurface(_THIS, SDL_Surface *surface) | |
1007 { | |
1008 vidmem_bucket *bucket, *freeable; | |
1009 | |
1010 /* Look for the bucket in the current list */ | |
1011 for ( bucket=&surfaces; bucket; bucket=bucket->next ) { | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1012 if ( bucket == (vidmem_bucket *)surface->hwdata ) { |
0 | 1013 break; |
1014 } | |
1015 } | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1016 if ( bucket && bucket->used ) { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1017 /* Add the memory back to the total */ |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1018 #ifdef DGA_DEBUG |
0 | 1019 printf("Freeing bucket of %d bytes\n", bucket->size); |
1020 #endif | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1021 surfaces_memleft += bucket->size; |
0 | 1022 |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1023 /* Can we merge the space with surrounding buckets? */ |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1024 bucket->used = 0; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1025 if ( bucket->next && ! bucket->next->used ) { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1026 #ifdef DGA_DEBUG |
0 | 1027 printf("Merging with next bucket, for %d total bytes\n", bucket->size+bucket->next->size); |
1028 #endif | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1029 freeable = bucket->next; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1030 bucket->size += bucket->next->size; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1031 bucket->next = bucket->next->next; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1032 if ( bucket->next ) { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1033 bucket->next->prev = bucket; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1034 } |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1035 free(freeable); |
0 | 1036 } |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1037 if ( bucket->prev && ! bucket->prev->used ) { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1038 #ifdef DGA_DEBUG |
0 | 1039 printf("Merging with previous bucket, for %d total bytes\n", bucket->prev->size+bucket->size); |
1040 #endif | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1041 freeable = bucket; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1042 bucket->prev->size += bucket->size; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1043 bucket->prev->next = bucket->next; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1044 if ( bucket->next ) { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1045 bucket->next->prev = bucket->prev; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1046 } |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1047 free(freeable); |
0 | 1048 } |
1049 } | |
1050 surface->pixels = NULL; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1051 surface->hwdata = NULL; |
0 | 1052 } |
1053 static int FB_LockHWSurface(_THIS, SDL_Surface *surface) | |
1054 { | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1055 if ( surface == this->screen ) { |
0 | 1056 SDL_mutexP(hw_lock); |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1057 if ( FB_IsSurfaceBusy(surface) ) { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1058 FB_WaitBusySurfaces(this); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1059 } |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1060 } else { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1061 if ( FB_IsSurfaceBusy(surface) ) { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1062 FB_WaitBusySurfaces(this); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1063 } |
0 | 1064 } |
1065 return(0); | |
1066 } | |
1067 static void FB_UnlockHWSurface(_THIS, SDL_Surface *surface) | |
1068 { | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1069 if ( surface == this->screen ) { |
0 | 1070 SDL_mutexV(hw_lock); |
1071 } | |
1072 } | |
1073 | |
1074 static void FB_WaitVBL(_THIS) | |
1075 { | |
1076 #ifdef FBIOWAITRETRACE /* Heheh, this didn't make it into the main kernel */ | |
1077 ioctl(console_fd, FBIOWAITRETRACE, 0); | |
1078 #endif | |
1079 return; | |
1080 } | |
1081 | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1082 static void FB_WaitIdle(_THIS) |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1083 { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1084 return; |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1085 } |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1086 |
0 | 1087 static int FB_FlipHWSurface(_THIS, SDL_Surface *surface) |
1088 { | |
1089 /* Wait for vertical retrace and then flip display */ | |
1090 cache_vinfo.yoffset = flip_page*surface->h; | |
106
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1091 if ( FB_IsSurfaceBusy(this->screen) ) { |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1092 FB_WaitBusySurfaces(this); |
63ec24e0575f
Merged DGA video surface handling improvements, unified locking code.
Sam Lantinga <slouken@lokigames.com>
parents:
91
diff
changeset
|
1093 } |
0 | 1094 wait_vbl(this); |
1095 if ( ioctl(console_fd, FBIOPAN_DISPLAY, &cache_vinfo) < 0 ) { | |
1096 SDL_SetError("ioctl(FBIOPAN_DISPLAY) failed"); | |
1097 return(-1); | |
1098 } | |
1099 flip_page = !flip_page; | |
1100 | |
1101 surface->pixels = flip_address[flip_page]; | |
1102 return(0); | |
1103 } | |
1104 | |
1105 static void FB_DirectUpdate(_THIS, int numrects, SDL_Rect *rects) | |
1106 { | |
1107 /* The application is already updating the visible video memory */ | |
1108 return; | |
1109 } | |
1110 | |
1111 #ifdef VGA16_FBCON_SUPPORT | |
1112 /* Code adapted with thanks from the XFree86 VGA16 driver! :) */ | |
1113 #define writeGr(index, value) \ | |
1114 outb(index, 0x3CE); \ | |
1115 outb(value, 0x3CF); | |
1116 #define writeSeq(index, value) \ | |
1117 outb(index, 0x3C4); \ | |
1118 outb(value, 0x3C5); | |
1119 | |
1120 static void FB_VGA16Update(_THIS, int numrects, SDL_Rect *rects) | |
1121 { | |
1122 SDL_Surface *screen; | |
1123 int width, height, FBPitch, left, i, j, SRCPitch, phase; | |
1124 register Uint32 m; | |
1125 Uint8 s1, s2, s3, s4; | |
1126 Uint32 *src, *srcPtr; | |
1127 Uint8 *dst, *dstPtr; | |
1128 | |
1129 screen = this->screen; | |
1130 FBPitch = screen->w >> 3; | |
1131 SRCPitch = screen->pitch >> 2; | |
1132 | |
1133 writeGr(0x03, 0x00); | |
1134 writeGr(0x05, 0x00); | |
1135 writeGr(0x01, 0x00); | |
1136 writeGr(0x08, 0xFF); | |
1137 | |
1138 while(numrects--) { | |
1139 left = rects->x & ~7; | |
1140 width = (rects->w + 7) >> 3; | |
1141 height = rects->h; | |
1142 src = (Uint32*)screen->pixels + (rects->y * SRCPitch) + (left >> 2); | |
1143 dst = (Uint8*)mapped_mem + (rects->y * FBPitch) + (left >> 3); | |
1144 | |
1145 if((phase = (long)dst & 3L)) { | |
1146 phase = 4 - phase; | |
1147 if(phase > width) phase = width; | |
1148 width -= phase; | |
1149 } | |
1150 | |
1151 while(height--) { | |
1152 writeSeq(0x02, 1 << 0); | |
1153 dstPtr = dst; | |
1154 srcPtr = src; | |
1155 i = width; | |
1156 j = phase; | |
1157 while(j--) { | |
1158 m = (srcPtr[1] & 0x01010101) | ((srcPtr[0] & 0x01010101) << 4); | |
1159 *dstPtr++ = (m >> 24) | (m >> 15) | (m >> 6) | (m << 3); | |
1160 srcPtr += 2; | |
1161 } | |
1162 while(i >= 4) { | |
1163 m = (srcPtr[1] & 0x01010101) | ((srcPtr[0] & 0x01010101) << 4); | |
1164 s1 = (m >> 24) | (m >> 15) | (m >> 6) | (m << 3); | |
1165 m = (srcPtr[3] & 0x01010101) | ((srcPtr[2] & 0x01010101) << 4); | |
1166 s2 = (m >> 24) | (m >> 15) | (m >> 6) | (m << 3); | |
1167 m = (srcPtr[5] & 0x01010101) | ((srcPtr[4] & 0x01010101) << 4); | |
1168 s3 = (m >> 24) | (m >> 15) | (m >> 6) | (m << 3); | |
1169 m = (srcPtr[7] & 0x01010101) | ((srcPtr[6] & 0x01010101) << 4); | |
1170 s4 = (m >> 24) | (m >> 15) | (m >> 6) | (m << 3); | |
1171 *((Uint32*)dstPtr) = s1 | (s2 << 8) | (s3 << 16) | (s4 << 24); | |
1172 srcPtr += 8; | |
1173 dstPtr += 4; | |
1174 i -= 4; | |
1175 } | |
1176 while(i--) { | |
1177 m = (srcPtr[1] & 0x01010101) | ((srcPtr[0] & 0x01010101) << 4); | |
1178 *dstPtr++ = (m >> 24) | (m >> 15) | (m >> 6) | (m << 3); | |
1179 srcPtr += 2; | |
1180 } | |
1181 | |
1182 writeSeq(0x02, 1 << 1); | |
1183 dstPtr = dst; | |
1184 srcPtr = src; | |
1185 i = width; | |
1186 j = phase; | |
1187 while(j--) { | |
1188 m = (srcPtr[1] & 0x02020202) | ((srcPtr[0] & 0x02020202) << 4); | |
1189 *dstPtr++ = (m >> 25) | (m >> 16) | (m >> 7) | (m << 2); | |
1190 srcPtr += 2; | |
1191 } | |
1192 while(i >= 4) { | |
1193 m = (srcPtr[1] & 0x02020202) | ((srcPtr[0] & 0x02020202) << 4); | |
1194 s1 = (m >> 25) | (m >> 16) | (m >> 7) | (m << 2); | |
1195 m = (srcPtr[3] & 0x02020202) | ((srcPtr[2] & 0x02020202) << 4); | |
1196 s2 = (m >> 25) | (m >> 16) | (m >> 7) | (m << 2); | |
1197 m = (srcPtr[5] & 0x02020202) | ((srcPtr[4] & 0x02020202) << 4); | |
1198 s3 = (m >> 25) | (m >> 16) | (m >> 7) | (m << 2); | |
1199 m = (srcPtr[7] & 0x02020202) | ((srcPtr[6] & 0x02020202) << 4); | |
1200 s4 = (m >> 25) | (m >> 16) | (m >> 7) | (m << 2); | |
1201 *((Uint32*)dstPtr) = s1 | (s2 << 8) | (s3 << 16) | (s4 << 24); | |
1202 srcPtr += 8; | |
1203 dstPtr += 4; | |
1204 i -= 4; | |
1205 } | |
1206 while(i--) { | |
1207 m = (srcPtr[1] & 0x02020202) | ((srcPtr[0] & 0x02020202) << 4); | |
1208 *dstPtr++ = (m >> 25) | (m >> 16) | (m >> 7) | (m << 2); | |
1209 srcPtr += 2; | |
1210 } | |
1211 | |
1212 writeSeq(0x02, 1 << 2); | |
1213 dstPtr = dst; | |
1214 srcPtr = src; | |
1215 i = width; | |
1216 j = phase; | |
1217 while(j--) { | |
1218 m = (srcPtr[1] & 0x04040404) | ((srcPtr[0] & 0x04040404) << 4); | |
1219 *dstPtr++ = (m >> 26) | (m >> 17) | (m >> 8) | (m << 1); | |
1220 srcPtr += 2; | |
1221 } | |
1222 while(i >= 4) { | |
1223 m = (srcPtr[1] & 0x04040404) | ((srcPtr[0] & 0x04040404) << 4); | |
1224 s1 = (m >> 26) | (m >> 17) | (m >> 8) | (m << 1); | |
1225 m = (srcPtr[3] & 0x04040404) | ((srcPtr[2] & 0x04040404) << 4); | |
1226 s2 = (m >> 26) | (m >> 17) | (m >> 8) | (m << 1); | |
1227 m = (srcPtr[5] & 0x04040404) | ((srcPtr[4] & 0x04040404) << 4); | |
1228 s3 = (m >> 26) | (m >> 17) | (m >> 8) | (m << 1); | |
1229 m = (srcPtr[7] & 0x04040404) | ((srcPtr[6] & 0x04040404) << 4); | |
1230 s4 = (m >> 26) | (m >> 17) | (m >> 8) | (m << 1); | |
1231 *((Uint32*)dstPtr) = s1 | (s2 << 8) | (s3 << 16) | (s4 << 24); | |
1232 srcPtr += 8; | |
1233 dstPtr += 4; | |
1234 i -= 4; | |
1235 } | |
1236 while(i--) { | |
1237 m = (srcPtr[1] & 0x04040404) | ((srcPtr[0] & 0x04040404) << 4); | |
1238 *dstPtr++ = (m >> 26) | (m >> 17) | (m >> 8) | (m << 1); | |
1239 srcPtr += 2; | |
1240 } | |
1241 | |
1242 writeSeq(0x02, 1 << 3); | |
1243 dstPtr = dst; | |
1244 srcPtr = src; | |
1245 i = width; | |
1246 j = phase; | |
1247 while(j--) { | |
1248 m = (srcPtr[1] & 0x08080808) | ((srcPtr[0] & 0x08080808) << 4); | |
1249 *dstPtr++ = (m >> 27) | (m >> 18) | (m >> 9) | m; | |
1250 srcPtr += 2; | |
1251 } | |
1252 while(i >= 4) { | |
1253 m = (srcPtr[1] & 0x08080808) | ((srcPtr[0] & 0x08080808) << 4); | |
1254 s1 = (m >> 27) | (m >> 18) | (m >> 9) | m; | |
1255 m = (srcPtr[3] & 0x08080808) | ((srcPtr[2] & 0x08080808) << 4); | |
1256 s2 = (m >> 27) | (m >> 18) | (m >> 9) | m; | |
1257 m = (srcPtr[5] & 0x08080808) | ((srcPtr[4] & 0x08080808) << 4); | |
1258 s3 = (m >> 27) | (m >> 18) | (m >> 9) | m; | |
1259 m = (srcPtr[7] & 0x08080808) | ((srcPtr[6] & 0x08080808) << 4); | |
1260 s4 = (m >> 27) | (m >> 18) | (m >> 9) | m; | |
1261 *((Uint32*)dstPtr) = s1 | (s2 << 8) | (s3 << 16) | (s4 << 24); | |
1262 srcPtr += 8; | |
1263 dstPtr += 4; | |
1264 i -= 4; | |
1265 } | |
1266 while(i--) { | |
1267 m = (srcPtr[1] & 0x08080808) | ((srcPtr[0] & 0x08080808) << 4); | |
1268 *dstPtr++ = (m >> 27) | (m >> 18) | (m >> 9) | m; | |
1269 srcPtr += 2; | |
1270 } | |
1271 | |
1272 dst += FBPitch; | |
1273 src += SRCPitch; | |
1274 } | |
1275 rects++; | |
1276 } | |
1277 } | |
1278 #endif /* VGA16_FBCON_SUPPORT */ | |
1279 | |
1280 void FB_SavePaletteTo(_THIS, int palette_len, __u16 *area) | |
1281 { | |
1282 struct fb_cmap cmap; | |
1283 | |
1284 cmap.start = 0; | |
1285 cmap.len = palette_len; | |
1286 cmap.red = &area[0*palette_len]; | |
1287 cmap.green = &area[1*palette_len]; | |
1288 cmap.blue = &area[2*palette_len]; | |
1289 cmap.transp = NULL; | |
1290 ioctl(console_fd, FBIOGETCMAP, &cmap); | |
1291 } | |
1292 | |
1293 void FB_RestorePaletteFrom(_THIS, int palette_len, __u16 *area) | |
1294 { | |
1295 struct fb_cmap cmap; | |
1296 | |
1297 cmap.start = 0; | |
1298 cmap.len = palette_len; | |
1299 cmap.red = &area[0*palette_len]; | |
1300 cmap.green = &area[1*palette_len]; | |
1301 cmap.blue = &area[2*palette_len]; | |
1302 cmap.transp = NULL; | |
1303 ioctl(console_fd, FBIOPUTCMAP, &cmap); | |
1304 } | |
1305 | |
1306 static void FB_SavePalette(_THIS, struct fb_fix_screeninfo *finfo, | |
1307 struct fb_var_screeninfo *vinfo) | |
1308 { | |
1309 int i; | |
1310 | |
1311 /* Save hardware palette, if needed */ | |
1312 if ( finfo->visual == FB_VISUAL_PSEUDOCOLOR ) { | |
1313 saved_cmaplen = 1<<vinfo->bits_per_pixel; | |
1314 saved_cmap=(__u16 *)malloc(3*saved_cmaplen*sizeof(*saved_cmap)); | |
1315 if ( saved_cmap != NULL ) { | |
1316 FB_SavePaletteTo(this, saved_cmaplen, saved_cmap); | |
1317 } | |
1318 } | |
1319 | |
1320 /* Added support for FB_VISUAL_DIRECTCOLOR. | |
1321 With this mode pixel information is passed through the palette... | |
1322 Neat fading and gamma correction effects can be had by simply | |
1323 fooling around with the palette instead of changing the pixel | |
1324 values themselves... Very neat! | |
1325 | |
1326 Adam Meyerowitz 1/19/2000 | |
1327 ameyerow@optonline.com | |
1328 */ | |
1329 if ( finfo->visual == FB_VISUAL_DIRECTCOLOR ) { | |
1330 __u16 new_entries[3*256]; | |
1331 | |
1332 /* Save the colormap */ | |
1333 saved_cmaplen = 256; | |
1334 saved_cmap=(__u16 *)malloc(3*saved_cmaplen*sizeof(*saved_cmap)); | |
1335 if ( saved_cmap != NULL ) { | |
1336 FB_SavePaletteTo(this, saved_cmaplen, saved_cmap); | |
1337 } | |
1338 | |
1339 /* Allocate new identity colormap */ | |
1340 for ( i=0; i<256; ++i ) { | |
1341 new_entries[(0*256)+i] = | |
1342 new_entries[(1*256)+i] = | |
1343 new_entries[(2*256)+i] = (i<<8)|i; | |
1344 } | |
1345 FB_RestorePaletteFrom(this, 256, new_entries); | |
1346 } | |
1347 } | |
1348 | |
1349 static void FB_RestorePalette(_THIS) | |
1350 { | |
1351 /* Restore the original palette */ | |
1352 if ( saved_cmap ) { | |
1353 FB_RestorePaletteFrom(this, saved_cmaplen, saved_cmap); | |
1354 free(saved_cmap); | |
1355 saved_cmap = NULL; | |
1356 } | |
1357 } | |
1358 | |
1359 static int FB_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) | |
1360 { | |
1361 int i; | |
1362 __u16 r[256]; | |
1363 __u16 g[256]; | |
1364 __u16 b[256]; | |
1365 struct fb_cmap cmap; | |
1366 | |
1367 /* Set up the colormap */ | |
1368 for (i = 0; i < ncolors; i++) { | |
1369 r[i] = colors[i].r << 8; | |
1370 g[i] = colors[i].g << 8; | |
1371 b[i] = colors[i].b << 8; | |
1372 } | |
1373 cmap.start = firstcolor; | |
1374 cmap.len = ncolors; | |
1375 cmap.red = r; | |
1376 cmap.green = g; | |
1377 cmap.blue = b; | |
1378 cmap.transp = NULL; | |
1379 | |
1380 if( (ioctl(console_fd, FBIOPUTCMAP, &cmap) < 0) || | |
1381 !(this->screen->flags & SDL_HWPALETTE) ) { | |
1382 colors = this->screen->format->palette->colors; | |
1383 ncolors = this->screen->format->palette->ncolors; | |
1384 cmap.start = 0; | |
1385 cmap.len = ncolors; | |
1386 memset(r, 0, sizeof(r)); | |
1387 memset(g, 0, sizeof(g)); | |
1388 memset(b, 0, sizeof(b)); | |
1389 if ( ioctl(console_fd, FBIOGETCMAP, &cmap) == 0 ) { | |
1390 for ( i=ncolors-1; i>=0; --i ) { | |
1391 colors[i].r = (r[i]>>8); | |
1392 colors[i].g = (g[i]>>8); | |
1393 colors[i].b = (b[i]>>8); | |
1394 } | |
1395 } | |
1396 return(0); | |
1397 } | |
1398 return(1); | |
1399 } | |
1400 | |
1401 /* Note: If we are terminated, this could be called in the middle of | |
1402 another SDL video routine -- notably UpdateRects. | |
1403 */ | |
1404 static void FB_VideoQuit(_THIS) | |
1405 { | |
1406 int i, j; | |
1407 | |
1408 if ( this->screen ) { | |
1409 /* Clear screen and tell SDL not to free the pixels */ | |
1410 if ( this->screen->pixels && FB_InGraphicsMode(this) ) { | |
1411 #ifdef __powerpc__ /* SIGBUS when using memset() ?? */ | |
1412 Uint8 *rowp = (Uint8 *)this->screen->pixels; | |
1413 int left = this->screen->pitch*this->screen->h; | |
1414 while ( left-- ) { *rowp++ = 0; } | |
1415 #else | |
1416 memset(this->screen->pixels,0,this->screen->h*this->screen->pitch); | |
1417 #endif | |
1418 } | |
1419 /* This test fails when using the VGA16 shadow memory */ | |
1420 if ( ((char *)this->screen->pixels >= mapped_mem) && | |
1421 ((char *)this->screen->pixels < (mapped_mem+mapped_memlen)) ) { | |
1422 this->screen->pixels = NULL; | |
1423 } | |
1424 } | |
1425 | |
1426 /* Clear the lock mutex */ | |
1427 if ( hw_lock ) { | |
1428 SDL_DestroyMutex(hw_lock); | |
1429 hw_lock = NULL; | |
1430 } | |
1431 | |
1432 /* Clean up defined video modes */ | |
1433 for ( i=0; i<NUM_MODELISTS; ++i ) { | |
1434 if ( SDL_modelist[i] != NULL ) { | |
1435 for ( j=0; SDL_modelist[i][j]; ++j ) { | |
1436 free(SDL_modelist[i][j]); | |
1437 } | |
1438 free(SDL_modelist[i]); | |
1439 SDL_modelist[i] = NULL; | |
1440 } | |
1441 } | |
1442 | |
1443 /* Clean up the memory bucket list */ | |
1444 FB_FreeHWSurfaces(this); | |
1445 | |
1446 /* Close console and input file descriptors */ | |
1447 if ( console_fd > 0 ) { | |
1448 /* Unmap the video framebuffer and I/O registers */ | |
1449 if ( mapped_mem ) { | |
1450 munmap(mapped_mem, mapped_memlen); | |
1451 mapped_mem = NULL; | |
1452 } | |
1453 if ( mapped_io ) { | |
1454 munmap(mapped_io, mapped_iolen); | |
1455 mapped_io = NULL; | |
1456 } | |
1457 | |
1458 /* Restore the original video mode and palette */ | |
1459 if ( FB_InGraphicsMode(this) ) { | |
1460 FB_RestorePalette(this); | |
1461 ioctl(console_fd, FBIOPUT_VSCREENINFO, &saved_vinfo); | |
1462 } | |
1463 | |
1464 /* We're all done with the framebuffer */ | |
1465 close(console_fd); | |
1466 console_fd = -1; | |
1467 } | |
1468 FB_CloseMouse(this); | |
1469 FB_CloseKeyboard(this); | |
1470 } |