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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "tdm_fbdev.h"
#include <tdm_helper.h>
#define TDM_FBDEV_NAME "fbdev"
static tdm_func_display fbdev_func_display =
{
fbdev_display_get_capabilitiy,
NULL, //display_get_pp_capability,
NULL, //display_get_capture_capability
fbdev_display_get_outputs,
fbdev_display_get_fd,
fbdev_display_handle_events,
NULL, //display_create_pp,
fbdev_output_get_capability,
fbdev_output_get_layers,
fbdev_output_set_property,
fbdev_output_get_property,
fbdev_output_wait_vblank,
fbdev_output_set_vblank_handler,
fbdev_output_commit,
fbdev_output_set_commit_handler,
fbdev_output_set_dpms,
fbdev_output_get_dpms,
fbdev_output_set_mode,
fbdev_output_get_mode,
NULL, //output_create_capture
fbdev_layer_get_capability,
fbdev_layer_set_property,
fbdev_layer_get_property,
fbdev_layer_set_info,
fbdev_layer_get_info,
fbdev_layer_set_buffer,
fbdev_layer_unset_buffer,
NULL, //layer_set_video_pos
NULL, //layer_create_capture
};
static tdm_fbdev_data *fbdev_data;
static int
_tdm_fbdev_open_fbdev(void)
{
const char *name = "/dev/fb0";
int fd = -1;
fd = open(name, O_RDWR);
if (fd < 0)
{
TDM_ERR("Cannot open fbdev device.. search by udev");
goto close;
}
/*
* TODO: If we failed directly to open framebuffer device
* we would try to open it through udev
*/
close:
return fd;
}
static tdm_error
_tdm_fbdev_init_internal(void)
{
struct fb_fix_screeninfo *finfo = calloc(1, sizeof(struct fb_fix_screeninfo));
struct fb_var_screeninfo *vinfo = calloc(1, sizeof(struct fb_var_screeninfo));
int ret = -1;
ret = ioctl(fbdev_data->fbdev_fd, FBIOGET_VSCREENINFO, vinfo);
if (ret < 0)
{
TDM_ERR("FBIOGET_VSCREENINFO ioctl failed errno=%d", errno);
goto close_1;
}
vinfo->reserved[0] = 0;
vinfo->reserved[1] = 0;
vinfo->reserved[2] = 0;
vinfo->xoffset = 0;
vinfo->yoffset = 0;
vinfo->activate = FB_ACTIVATE_NOW;
/*
* Explicitly request 32 bits per pixel colors with corresponding
* red, blue and green color offsets and length of colors
*/
vinfo->bits_per_pixel = 32;
vinfo->red.offset = 16;
vinfo->red.length = 8;
vinfo->green.offset = 8;
vinfo->green.length = 8;
vinfo->blue.offset = 0;
vinfo->blue.length = 8;
vinfo->transp.offset = 0;
vinfo->transp.length = 0;
/*
* Almost all framebuffers support off screen rendering.
* The code bellow requests Framebuffer to allocate memory equals to three
* buffers each of which width*height size. While the first drawn
* framebuffer's area is displaying the second or the third is redrawing
* or compositing by some application. When timer was expired or vblank
* was received Framebufer's areas swap, thus the second or the third is
* displaying and first is redrawing or compositing. Simple representation
* of what was said bellow
*
* SWAP Event SWAP Event
* | |
* +-------------+ | +-------------+ | +-------------+
* | | | | | | | Redrawing |
* | Displaying | | | queued | | | or |
* | | | | | | | Compositing |
* +-------------+ | +-------------+ | +-------------+
* | Redrawing | | | | | | |
* | or | +-------> | Displaying | +--------> | queued |
* | Compositing | | | | | | |
* +-------------+ | +-------------+ | +-------------+
* | | | | Redrawing | | | |
* | queued | | | or | | | Displaying |
* | | | | Compositing | | | |
* +-------------+ | +-------------+ | +-------------+
* | |
*/
/*
* TODO: Implement off screen rendering
*/
vinfo->yres_virtual = vinfo->yres * MAX_BUF;
ret = ioctl(fbdev_data->fbdev_fd, FBIOPAN_DISPLAY, vinfo);
if(ret < 0)
{
TDM_INFO("page flip not supported, errno=%d", errno);
vinfo->yres_virtual = vinfo->yres;
/*
* TODO: Does FBIOPAN_DISPLAY ioctl must be invoked for the second time?
*/
ret = ioctl(fbdev_data->fbdev_fd, FBIOPAN_DISPLAY, vinfo);
if(ret < 0)
{
TDM_ERR("FBIOPAN_DISPLAY ioctl failed, errno=%d", errno);
goto close_1;
}
}
ret = ioctl(fbdev_data->fbdev_fd, FBIOGET_FSCREENINFO, finfo);
if (ret < 0)
{
TDM_ERR("FBIOGET_FSCREENINFO ioctl failed, errno=%d", errno);
goto close_1;
}
if (finfo->smem_len <= 0)
{
TDM_ERR("Length of frame buffer mem less then 0");
goto close_1;
}
fbdev_data->vinfo = vinfo;
fbdev_data->finfo = finfo;
/*
* Output framebuffer's related information
*/
TDM_INFO("\n"
" VInfo\n"
" fb = %d\n"
" xres = %d px \n"
" yres = %d px \n"
" xres_virtual = %d px \n"
" yres_virtual = %d px \n"
" bpp = %d \n"
" r = %2u:%u\n"
" g = %2u:%u\n"
" b = %2u:%u\n"
" t = %2u:%u\n"
" active = %d \n"
" width = %d mm \n"
" height = %d mm \n",
fbdev_data->fbdev_fd,
vinfo->xres,
vinfo->yres,
vinfo->xres_virtual,
vinfo->yres_virtual,
vinfo->bits_per_pixel,
vinfo->red.offset, vinfo->red.length,
vinfo->green.offset, vinfo->green.length,
vinfo->blue.offset, vinfo->blue.length,
vinfo->transp.offset, vinfo->transp.length,
vinfo->activate,
vinfo->width,
vinfo->height);
TDM_INFO("\n"
" FInfo\n"
" id = %s\n"
" smem_len = %d\n"
" line_length = %d\n",
finfo->id,
finfo->smem_len,
finfo->line_length);
return TDM_ERROR_NONE;
close_1:
ret = TDM_ERROR_OPERATION_FAILED;
return ret;
}
void
tdm_fbdev_deinit(tdm_backend_data *bdata)
{
if (fbdev_data != bdata)
return;
TDM_INFO("deinit");
close(fbdev_data->fbdev_fd);
tdm_fbdev_destroy_layer(fbdev_data);
tdm_fbdev_destroy_output(fbdev_data);
if (fbdev_data->vinfo)
free(fbdev_data->vinfo);
if (fbdev_data->finfo)
free(fbdev_data->finfo);
free(fbdev_data);
fbdev_data = NULL;
}
tdm_backend_data*
tdm_fbdev_init(tdm_display *dpy, tdm_error *error)
{
tdm_error ret;
if (!dpy)
{
TDM_ERR("display is null");
if(error)
*error = TDM_ERROR_BAD_REQUEST;
return NULL;
}
if(fbdev_data)
{
TDM_ERR("failed: init twice");
if(error)
*error = TDM_ERROR_BAD_REQUEST;
return NULL;
}
fbdev_data = calloc(1, sizeof(struct _tdm_fbdev_data));
if (!fbdev_data)
{
TDM_ERR("alloc failed");
if(error)
*error = TDM_ERROR_OUT_OF_MEMORY;
return NULL;
}
ret = tdm_backend_register_func_display(dpy, &fbdev_func_display);
if (ret != TDM_ERROR_NONE)
goto failed;
LIST_INITHEAD(&fbdev_data->buffer_list);
fbdev_data->dpy = dpy;
/*
* TODO: does somebody open framebuffer device beside us?
*/
fbdev_data->fbdev_fd = _tdm_fbdev_open_fbdev();
if(fbdev_data->fbdev_fd < 0)
{
ret = TDM_ERROR_OPERATION_FAILED;
goto failed;
}
ret = _tdm_fbdev_init_internal();
if(ret != TDM_ERROR_NONE)
{
TDM_INFO("init of framebuffer failed");
goto failed;
}
ret = tdm_fbdev_creat_output(fbdev_data);
if (ret != TDM_ERROR_NONE)
{
TDM_INFO("init of output failed");
goto failed_2;
}
ret = tdm_fbdev_creat_layer(fbdev_data);
if (ret != TDM_ERROR_NONE)
{
TDM_INFO("init of output failed");
goto failed_3;
}
TDM_INFO("init success!");
if(error)
*error = TDM_ERROR_NONE;
return (tdm_backend_data*)fbdev_data;
failed_3:
tdm_fbdev_destroy_layer(fbdev_data);
failed_2:
tdm_fbdev_destroy_output(fbdev_data);
failed:
if(error)
*error = ret;
tdm_fbdev_deinit(fbdev_data);
TDM_ERR("init failed!");
return NULL;
}
tdm_backend_module tdm_backend_module_data =
{
"fbdev",
"Samsung",
TDM_BACKEND_ABI_VERSION,
tdm_fbdev_init,
tdm_fbdev_deinit
};
|