Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
208 lines (176 loc) · 5.3 KB

SDL_fbvideo.c

File metadata and controls

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