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