summaryrefslogtreecommitdiff
path: root/src/tdm_fbdev_display.c
blob: fa05e8aa153501c94b2d1835b16a3d896fa2ab2c (plain)
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
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <tdm_helper.h>
#include <stdint.h>
#include "tdm_fbdev.h"

tdm_error tdm_fbdev_creat_output(tdm_fbdev_data *fbdev_data)
{
    tdm_fbdev_output_data *output = NULL;
    size_t size;

    output = calloc(1, sizeof(tdm_fbdev_output_data));
    if (output == NULL)
    {
        TDM_ERR("alloc output failed");
        return TDM_ERROR_OUT_OF_MEMORY;
    }

    /*
     * TODO: Size of framebuffer must be aligned to system page size before
     *  it is mapped
     */
    size = fbdev_data->vinfo.xres * fbdev_data->vinfo.yres * fbdev_data->vinfo.bits_per_pixel / 8 * MAX_BUF;

    output->vaddr = mmap(0, size, PROT_READ|PROT_WRITE,
            MAP_SHARED, fbdev_data->fbdev_fd, 0);
    if (output->vaddr == MAP_FAILED)
    {
        TDM_ERR("MMap framebuffer failed, errno=%d", errno);
        return TDM_ERROR_OPERATION_FAILED;
    }

    memset(output->vaddr, 0, size);

    output->width = fbdev_data->vinfo.width;
    output->height = fbdev_data->vinfo.height;
    output->pitch = fbdev_data->vinfo.width;
    output->bpp = fbdev_data->vinfo.bits_per_pixel;
    output->size = size;

    output->fbdev_data = fbdev_data;

    fbdev_data->fbdev_output = output;

    return TDM_ERROR_NONE;
}

void tdm_fbdev_destroy_output(tdm_fbdev_data *fbdev_data)
{
    tdm_fbdev_output_data *fbdev_output = fbdev_data->fbdev_output;

    if (fbdev_output == NULL)
        goto close;

    if (fbdev_output->vaddr == NULL)
        goto close_2;

    munmap(fbdev_output->vaddr, fbdev_output->size);

close_2:
    free(fbdev_output);
close:
    return;
}



tdm_error
fbdev_display_get_capabilitiy(tdm_backend_data *bdata, tdm_caps_display *caps)
{
    RETURN_VAL_IF_FAIL(caps, TDM_ERROR_INVALID_PARAMETER);

    /*
     * Framebuffer device does not support layers
     */
    caps->max_layer_count = 1;

    return TDM_ERROR_NONE;
}

tdm_output**
fbdev_display_get_outputs(tdm_backend_data *bdata, int *count, tdm_error *error)
{
    tdm_fbdev_data *fbdev_data = bdata;
    tdm_fbdev_output_data *fbdev_output = fbdev_data->fbdev_output;
    tdm_output **outputs;
    tdm_error ret;

    RETURN_VAL_IF_FAIL(fbdev_data, NULL);
    RETURN_VAL_IF_FAIL(count, NULL);

    if (fbdev_output == NULL)
    {
        ret = TDM_ERROR_NONE;
        goto failed_get;
    }

    /*
     * Since it is Framebuffer device there is only one output
     */
    *count = 1;

    /* will be freed in frontend */
    outputs = calloc(*count, sizeof(tdm_fbdev_output_data*));
    if (!outputs)
    {
        TDM_ERR("failed: alloc memory");
        *count = 0;
        ret = TDM_ERROR_OUT_OF_MEMORY;
        goto failed_get;
    }

    outputs[0] = fbdev_output;

    if (error)
        *error = TDM_ERROR_NONE;

    return outputs;

failed_get:
    if (error)
        *error = ret;
    return NULL;
}

tdm_error
fbdev_display_get_fd(tdm_backend_data *bdata, int *fd)
{
    RETURN_VAL_IF_FAIL(bdata, TDM_ERROR_INVALID_PARAMETER);
    RETURN_VAL_IF_FAIL(fd, TDM_ERROR_INVALID_PARAMETER);

    /*
     * TODO: It is tricky place since we don't know how drm
     *  file descriptor is used by software above in drm backend;
     */
    *fd = -1;

    return TDM_ERROR_NONE;
}

tdm_error
fbdev_display_handle_events(tdm_backend_data *bdata)
{
    /*
     * Framebuffer does not produce events
     */
    return TDM_ERROR_NONE;
}

tdm_error
fbdev_output_get_capability(tdm_output *output, tdm_caps_output *caps)
{
    return TDM_ERROR_NONE;
}

tdm_layer**
fbdev_output_get_layers(tdm_output *output,  int *count, tdm_error *error)
{
    return NULL;
}

tdm_error
fbdev_output_set_property(tdm_output *output, unsigned int id, tdm_value value)
{
    return TDM_ERROR_NONE;
}

tdm_error
fbdev_output_get_property(tdm_output *output, unsigned int id, tdm_value *value)
{
    return TDM_ERROR_NONE;
}

tdm_error
fbdev_output_wait_vblank(tdm_output *output, int interval, int sync, void *user_data)
{
    return TDM_ERROR_NONE;
}

tdm_error
fbdev_output_set_vblank_handler(tdm_output *output, tdm_output_vblank_handler func)
{
    return TDM_ERROR_NONE;
}


tdm_error
fbdev_output_commit(tdm_output *output, int sync, void *user_data)
{
    return TDM_ERROR_NONE;
}


tdm_error
fbdev_output_set_commit_handler(tdm_output *output, tdm_output_commit_handler func)
{
    return TDM_ERROR_NONE;
}


tdm_error
fbdev_output_set_dpms(tdm_output *output, tdm_output_dpms dpms_value)
{
    return TDM_ERROR_NONE;
}


tdm_error
fbdev_output_get_dpms(tdm_output *output, tdm_output_dpms *dpms_value)
{
    return TDM_ERROR_NONE;
}


tdm_error
fbdev_output_set_mode(tdm_output *output, const tdm_output_mode *mode)
{
    return TDM_ERROR_NONE;
}


tdm_error
fbdev_output_get_mode(tdm_output *output, const tdm_output_mode **mode)
{
    return TDM_ERROR_NONE;
}


tdm_error
fbdev_layer_get_capability(tdm_layer *layer, tdm_caps_layer *caps)
{
    return TDM_ERROR_NONE;
}


tdm_error
fbdev_layer_set_property(tdm_layer *layer, unsigned int id, tdm_value value)
{
    return TDM_ERROR_NONE;
}


tdm_error
fbdev_layer_get_property(tdm_layer *layer, unsigned int id, tdm_value *value)
{
    return TDM_ERROR_NONE;
}


tdm_error
fbdev_layer_set_info(tdm_layer *layer, tdm_info_layer *info)
{
    return TDM_ERROR_NONE;
}


tdm_error
fbdev_layer_get_info(tdm_layer *layer, tdm_info_layer *info)
{
    return TDM_ERROR_NONE;
}


tdm_error
fbdev_layer_set_buffer(tdm_layer *layer, tbm_surface_h buffer)
{
    return TDM_ERROR_NONE;
}


tdm_error
fbdev_layer_unset_buffer(tdm_layer *layer)
{
    return TDM_ERROR_NONE;
}