summaryrefslogtreecommitdiff
path: root/src/tdm_fbdev.h
blob: 6da001b0441d305a5afb726f7456707667e77c4d (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
#ifndef _TDM_fbdev_H_
#define _TDM_fbdev_H_

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <pthread.h>
#include <errno.h>
#include <unistd.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <fcntl.h>

#include <linux/fb.h>

#include <tbm_surface.h>
#include <tbm_surface_internal.h>
#include <tdm_backend.h>
#include <tdm_log.h>
#include <tdm_list.h>

#define MAX_BUF 3

/* fbdev backend functions (display) */
tdm_error    fbdev_display_get_capabilitiy(tdm_backend_data *bdata, tdm_caps_display *caps);
tdm_output** fbdev_display_get_outputs(tdm_backend_data *bdata, int *count, tdm_error *error);
tdm_error    fbdev_display_get_fd(tdm_backend_data *bdata, int *fd);
tdm_error    fbdev_display_get_buffer_fd(tdm_backend_data *bdata, int *fd);
tdm_error    fbdev_display_handle_events(tdm_backend_data *bdata);
tdm_pp*      fbdev_display_create_pp(tdm_backend_data *bdata, tdm_error *error);
tdm_error    fbdev_output_get_capability(tdm_output *output, tdm_caps_output *caps);
tdm_layer**  fbdev_output_get_layers(tdm_output *output, int *count, tdm_error *error);
tdm_error    fbdev_output_set_property(tdm_output *output, unsigned int id, tdm_value value);
tdm_error    fbdev_output_get_property(tdm_output *output, unsigned int id, tdm_value *value);
tdm_error    fbdev_output_wait_vblank(tdm_output *output, int interval, int sync, void *user_data);
tdm_error    fbdev_output_set_vblank_handler(tdm_output *output, tdm_output_vblank_handler func);
tdm_error    fbdev_output_commit(tdm_output *output, int sync, void *user_data);
tdm_error    fbdev_output_set_commit_handler(tdm_output *output, tdm_output_commit_handler func);
tdm_error    fbdev_output_set_dpms(tdm_output *output, tdm_output_dpms dpms_value);
tdm_error    fbdev_output_get_dpms(tdm_output *output, tdm_output_dpms *dpms_value);
tdm_error    fbdev_output_set_mode(tdm_output *output, const tdm_output_mode *mode);
tdm_error    fbdev_output_get_mode(tdm_output *output, const tdm_output_mode **mode);
tdm_error    fbdev_layer_get_capability(tdm_layer *layer, tdm_caps_layer *caps);
tdm_error    fbdev_layer_set_property(tdm_layer *layer, unsigned int id, tdm_value value);
tdm_error    fbdev_layer_get_property(tdm_layer *layer, unsigned int id, tdm_value *value);
tdm_error    fbdev_layer_set_info(tdm_layer *layer, tdm_info_layer *info);
tdm_error    fbdev_layer_get_info(tdm_layer *layer, tdm_info_layer *info);
tdm_error    fbdev_layer_set_buffer(tdm_layer *layer, tbm_surface_h buffer);
tdm_error    fbdev_layer_unset_buffer(tdm_layer *layer);

/* Framebuffer moudel's internal macros, functions, structures */
#define NEVER_GET_HERE() TDM_ERR("** NEVER GET HERE **")

#define RETURN_VAL_IF_FAIL(cond, val) {\
    if (!(cond)) {\
        TDM_ERR("'%s' failed", #cond);\
        return val;\
    }\
}

typedef struct _tdm_fbdev_output_data tdm_fbdev_output_data;
typedef struct _tdm_fbdev_layer_data tdm_fbdev_layer_data;
typedef struct _tdm_fbdev_display_buffer tdm_fbdev_display_buffer;

typedef struct _tdm_fbdev_data
{
    tdm_fbdev_output_data *fbdev_output;

    int fbdev_fd;

    tdm_display *dpy;

    struct fb_fix_screeninfo *finfo;
    struct fb_var_screeninfo *vinfo;

    struct list_head buffer_list;
} tdm_fbdev_data;

struct _tdm_fbdev_output_data
{
    tdm_fbdev_data *fbdev_data;
    tdm_fbdev_layer_data *fbdev_layer;

    uint32_t width;
    uint32_t height;
    uint32_t pitch;
    uint32_t bpp;
    size_t   size;
    uint32_t max_width;
    uint32_t max_height;

    /*
     * Poinetr to Framebuffers's mapped memory
     */
    void *mem;

    int count_modes;
    tdm_output_mode *output_modes;
    int mode_changed;

    /*
     * Frambuffer device back end currently support only one mode
     */
    const tdm_output_mode *current_mode;

    tdm_output_type connector_type;
    tdm_output_conn_status status;
    unsigned int connector_type_id;

    tdm_output_dpms dpms_value;

    /*
     * Event handlers
     */
    tdm_output_vblank_handler vblank_func;
    tdm_output_commit_handler commit_func;

    void *user_data;

    /*
     * Fake flags are used to simulate event-operated back end. Since tdm
     *  library assumes its back ends to be event-operated and Framebuffer
     *  device is not event-operated we have to make fake events
     */
    int is_vblank;
    int is_commit;
};

struct _tdm_fbdev_layer_data
{
    tdm_fbdev_data *fbdev_data;
    tdm_fbdev_output_data *fbdev_output;

    tdm_fbdev_display_buffer *display_buffer;
    int display_buffer_changed;

    tdm_layer_capability capabilities;
    tdm_info_layer info;
    int info_changed;
};

enum
{
    DOWN = 0,
    UP,
};

struct _tdm_fbdev_display_buffer
{
    struct list_head link;

    int width;
    int height;
    int size;

    /*
     * Buffer's mapped memory
     */
    void *mem;

    tbm_surface_h buffer;
};

tdm_error    tdm_fbdev_creat_output(tdm_fbdev_data *fbdev_data);
void         tdm_fbdev_destroy_output(tdm_fbdev_data *fbdev_data);

tdm_error    tdm_fbdev_creat_layer(tdm_fbdev_data *fbdev_data);
void         tdm_fbdev_destroy_layer(tdm_fbdev_data *fbdev_data);

#endif /* _TDM_fbdev_H_ */