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