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