comparison src/video/fbcon-1.3/SDL_fbvideo.c @ 3158:30f3b987fec3 gsoc2009_ps3

created env (fbcon-1.3) and added basic files
author Martin Lowinski <martin@goldtopf.org>
date Sat, 07 Nov 2009 11:35:19 +0000
parents
children 2632b7453516
comparison
equal deleted inserted replaced
3157:cce01ba54174 3158:30f3b987fec3
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2009 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21 */
22
23 #include "SDL_config.h"
24
25 /* SDL fbcon video driver implementation based on dummy, ps3 video driver
26 * and sourcecode of the fbcon implementation in sdl-1.2
27 *
28 * Initial work by Ryan C. Gordon (icculus@icculus.org). A good portion
29 * of this was cut-and-pasted from Stephane Peter's work in the AAlib
30 * SDL video driver. Renamed to "DUMMY" by Sam Lantinga.
31 */
32
33 #include "SDL_video.h"
34 #include "../SDL_sysvideo.h"
35
36 #include "SDL_fbvideo.h"
37 #include "SDL_fbevents_c.h"
38 #include "SDL_fbrender_c.h"
39 #include "SDL_fbmodes_c.h"
40
41 #include <stdio.h>
42 #include <fcntl.h>
43 #include <unistd.h>
44 #include <sys/ioctl.h>
45 #include <sys/mman.h>
46
47 #ifndef HAVE_GETPAGESIZE
48 #include <asm/page.h> /* For definition of PAGE_SIZE */
49 #endif
50
51 #include <linux/vt.h>
52
53 #define FBVID_DRIVER_NAME "fbcon"
54
55 /* Initialization/Query functions */
56 static int FB_VideoInit(_THIS);
57 static int FB_SetDisplayMode(_THIS, SDL_DisplayMode * mode);
58 static void FB_VideoQuit(_THIS);
59
60 /* bootstrap functions */
61 static int
62 FB_Available(void)
63 {
64 deprintf(1, "+FB_Available()\n");
65 const char *envr = SDL_getenv("SDL_VIDEODRIVER");
66 if ((envr) && (SDL_strcmp(envr, FBVID_DRIVER_NAME) == 0)) {
67 return (1);
68 }
69
70 int console = -1;
71 /* Added check for /fb/0 (devfs) */
72 /* but - use environment variable first... if it fails, still check defaults */
73 int idx = 0;
74 const char *SDL_fbdevs[4] = { NULL, "/dev/fb0", "/dev/fb/0", NULL };
75
76 SDL_fbdevs[0] = SDL_getenv("SDL_FBDEV");
77 if (!SDL_fbdevs[0]) {
78 idx++;
79 }
80 for (; SDL_fbdevs[idx]; idx++) {
81 console = open(SDL_fbdevs[idx], O_RDWR, 0);
82 if (console >= 0) {
83 close(console);
84 break;
85 }
86 }
87 deprintf(1, "-FB_Available()\n");
88 return (console >= 0);
89 }
90
91 static void
92 FB_DeleteDevice(SDL_VideoDevice * device)
93 {
94 deprintf(1, "+FB_DeleteDevice()\n");
95 SDL_free(device->driverdata);
96 SDL_free(device);
97 deprintf(1, "-FB_DeleteDevice()\n");
98 }
99
100 static SDL_VideoDevice *
101 FB_CreateDevice(int devindex)
102 {
103 deprintf(1, "+FB_CreateDevice()\n");
104 SDL_VideoDevice *device;
105 SDL_VideoData *data;
106
107 /* Initialize all variables that we clean on shutdown */
108 device = (SDL_VideoDevice *) SDL_calloc(1, sizeof(SDL_VideoDevice));
109 if (!device) {
110 SDL_OutOfMemory();
111 if (device) {
112 SDL_free(device);
113 }
114 return (0);
115 }
116 data = (struct SDL_VideoData *) SDL_calloc(1, sizeof(SDL_VideoData));
117 if (!data) {
118 SDL_OutOfMemory();
119 SDL_free(device);
120 return (0);
121 }
122 device->driverdata = data;
123
124 /* Set the function pointers */
125 device->VideoInit = FB_VideoInit;
126 device->VideoQuit = FB_VideoQuit;
127 device->SetDisplayMode = FB_SetDisplayMode;
128 device->PumpEvents = FB_PumpEvents;
129
130 device->free = FB_DeleteDevice;
131
132 deprintf(1, "-FB_CreateDevice()\n");
133 return device;
134 }
135
136 VideoBootStrap FB_bootstrap = {
137 FBVID_DRIVER_NAME, "Linux framebuffer video driver",
138 FB_Available, FB_CreateDevice
139 };
140
141 int
142 FB_VideoInit(_THIS)
143 {
144 deprintf(1, "+FB_VideoInit()\n");
145 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
146 SDL_DisplayMode mode;
147 struct fb_fix_screeninfo finfo;
148 const char *SDL_fbdev;
149
150 /* Initialize the library */
151 SDL_fbdev = SDL_getenv("SDL_FBDEV");
152 if (SDL_fbdev == NULL) {
153 SDL_fbdev = "/dev/fb0";
154 }
155 data->console_fd = open(SDL_fbdev, O_RDWR, 0);
156 if (data->console_fd < 0) {
157 SDL_SetError("Unable to open %s", SDL_fbdev);
158 return -1;
159 }
160 #if !SDL_THREADS_DISABLED
161 /* Create the hardware surface lock mutex */
162 data->hw_lock = SDL_CreateMutex();
163 if (data->hw_lock == NULL) {
164 SDL_SetError("Unable to create lock mutex");
165 FB_VideoQuit(_this);
166 return -1;
167 }
168 #endif
169
170 /* Get the type of video hardware */
171 if (ioctl(data->console_fd, FBIOGET_FSCREENINFO, &finfo) < 0) {
172 SDL_SetError("Couldn't get console hardware info");
173 FB_VideoQuit(_this);
174 return -1;
175 }
176
177 /* Use a fake 32-bpp desktop mode */
178 mode.format = SDL_PIXELFORMAT_RGB888;
179 mode.w = 1024;
180 mode.h = 768;
181 mode.refresh_rate = 0;
182 mode.driverdata = NULL;
183 SDL_AddBasicVideoDisplay(&mode);
184 SDL_AddRenderDriver(0, &SDL_FB_RenderDriver);
185
186 SDL_zero(mode);
187 SDL_AddDisplayMode(0, &mode);
188
189 /* We're done! */
190 deprintf(1, "-FB_VideoInit()\n");
191 return 0;
192 }
193
194 static int
195 FB_SetDisplayMode(_THIS, SDL_DisplayMode * mode)
196 {
197 deprintf(1, "+FB_SetDisplayMode()\n");
198 deprintf(1, "-FB_SetDisplayMode()\n");
199 return 0;
200 }
201
202 void
203 FB_VideoQuit(_THIS)
204 {
205 deprintf(1, "+FB_VideoQuit()\n");
206 deprintf(1, "-FB_VideoQuit()\n");
207 }
208