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