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