Make use of wayland-server shm common code
[profile/ivi/weston.git] / compositor / compositor.h
1 /*
2  * Copyright © 2008 Kristian Høgsberg
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18
19 #ifndef _WAYLAND_SYSTEM_COMPOSITOR_H_
20 #define _WAYLAND_SYSTEM_COMPOSITOR_H_
21
22 #include <libudev.h>
23 #include <pixman.h>
24 #include "wayland-server.h"
25 #include "wayland-util.h"
26
27 #define GL_GLEXT_PROTOTYPES
28 #define EGL_EGLEXT_PROTOTYPES
29 #include <GLES2/gl2.h>
30 #include <GLES2/gl2ext.h>
31 #include <EGL/egl.h>
32 #include <EGL/eglext.h>
33
34 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
35
36 struct wlsc_matrix {
37         GLfloat d[16];
38 };
39
40 struct wlsc_surface;
41
42 struct wlsc_output {
43         struct wl_object object;
44         struct wl_list link;
45         struct wlsc_compositor *compositor;
46         struct wlsc_surface *background;
47         struct wlsc_matrix matrix;
48         int32_t x, y, width, height;
49         pixman_region32_t previous_damage_region;
50         uint32_t flags;
51         int repaint_needed;
52         int finished;
53
54         int (*prepare_render)(struct wlsc_output *output);
55         int (*present)(struct wlsc_output *output);
56         int (*prepare_scanout_surface)(struct wlsc_output *output,
57                                        struct wlsc_surface *es);
58         int (*set_hardware_cursor)(struct wlsc_output *output,
59                                    struct wl_input_device *input);
60 };
61
62 enum wlsc_pointer_type {
63         WLSC_POINTER_BOTTOM_LEFT,
64         WLSC_POINTER_BOTTOM_RIGHT,
65         WLSC_POINTER_BOTTOM,
66         WLSC_POINTER_DRAGGING,
67         WLSC_POINTER_LEFT_PTR,
68         WLSC_POINTER_LEFT,
69         WLSC_POINTER_RIGHT,
70         WLSC_POINTER_TOP_LEFT,
71         WLSC_POINTER_TOP_RIGHT,
72         WLSC_POINTER_TOP,
73         WLSC_POINTER_IBEAM,
74 };
75
76 struct wlsc_input_device {
77         struct wl_input_device input_device;
78         struct wlsc_surface *sprite;
79         int32_t hotspot_x, hotspot_y;
80         struct wl_list link;
81         uint32_t modifier_state;
82         struct wl_selection *selection;
83 };
84
85 struct wlsc_sprite {
86         GLuint texture;
87         EGLImageKHR image;
88         struct wl_visual *visual;
89         int width;
90         int height;
91 };
92
93 struct wlsc_compositor {
94         struct wl_compositor compositor;
95
96         struct wl_shm *shm;
97
98         EGLDisplay display;
99         EGLContext context;
100         EGLConfig config;
101         GLuint fbo;
102         GLuint proj_uniform, tex_uniform;
103         struct wlsc_sprite **pointer_sprites;
104         struct wl_display *wl_display;
105
106         /* We implement the shell interface. */
107         struct wl_shell shell;
108
109         /* There can be more than one, but not right now... */
110         struct wl_input_device *input_device;
111
112         struct wl_list output_list;
113         struct wl_list input_device_list;
114         struct wl_list surface_list;
115         struct wl_list binding_list;
116
117         /* Repaint state. */
118         struct wl_event_source *timer_source;
119         int repaint_on_timeout;
120         struct timespec previous_swap;
121         pixman_region32_t damage_region;
122         struct wl_array vertices, indices;
123
124         struct wlsc_surface *overlay;
125         struct wlsc_switcher *switcher;
126         uint32_t focus;
127
128         void (*destroy)(struct wlsc_compositor *ec);
129         int (*authenticate)(struct wlsc_compositor *c, uint32_t id);
130         EGLImageKHR (*create_cursor_image)(struct wlsc_compositor *c,
131                                            int32_t width, int32_t height);
132 };
133
134 #define MODIFIER_CTRL   (1 << 8)
135 #define MODIFIER_ALT    (1 << 9)
136 #define MODIFIER_SUPER  (1 << 10)
137
138 enum wlsc_output_flags {
139         WL_OUTPUT_FLIPPED = 0x01
140 };
141
142 struct wlsc_vector {
143         GLfloat f[4];
144 };
145
146 enum wlsc_surface_map_type {
147         WLSC_SURFACE_MAP_UNMAPPED,
148         WLSC_SURFACE_MAP_TOPLEVEL,
149         WLSC_SURFACE_MAP_TRANSIENT,
150         WLSC_SURFACE_MAP_FULLSCREEN
151 };
152
153 struct wlsc_surface {
154         struct wl_surface surface;
155         struct wlsc_compositor *compositor;
156         GLuint texture, saved_texture;
157         int32_t x, y, width, height;
158         int32_t saved_x, saved_y;
159         struct wl_list link;
160         struct wl_list buffer_link;
161         struct wlsc_matrix matrix;
162         struct wlsc_matrix matrix_inv;
163         struct wl_visual *visual;
164         struct wl_buffer *buffer;
165         struct wlsc_output *output;
166         enum wlsc_surface_map_type map_type;
167         struct wlsc_output *fullscreen_output;
168
169         EGLImageKHR image;
170 };
171
172 void
173 wlsc_surface_update_matrix(struct wlsc_surface *es);
174
175 void
176 wlsc_surface_activate(struct wlsc_surface *surface,
177                       struct wlsc_input_device *device, uint32_t time);
178
179 void
180 notify_motion(struct wl_input_device *device,
181               uint32_t time, int x, int y);
182 void
183 notify_button(struct wl_input_device *device,
184               uint32_t time, int32_t button, int32_t state);
185 void
186 notify_key(struct wl_input_device *device,
187            uint32_t time, uint32_t key, uint32_t state);
188
189 void
190 notify_pointer_focus(struct wl_input_device *device,
191                      uint32_t time,
192                      struct wlsc_output *output,
193                      int32_t x, int32_t y);
194
195 void
196 notify_keyboard_focus(struct wl_input_device *device,
197                       uint32_t time, struct wlsc_output *output,
198                       struct wl_array *keys);
199
200 void
201 wlsc_output_finish_frame(struct wlsc_output *output, int msecs);
202 void
203 wlsc_compositor_schedule_repaint(struct wlsc_compositor *compositor);
204
205 struct wlsc_binding;
206 typedef void (*wlsc_binding_handler_t)(struct wl_input_device *device,
207                                        uint32_t time, uint32_t key,
208                                        uint32_t button,
209                                        uint32_t state, void *data);
210 struct wlsc_binding *
211 wlsc_compositor_add_binding(struct wlsc_compositor *compositor,
212                             uint32_t key, uint32_t button, uint32_t modifier,
213                             wlsc_binding_handler_t binding, void *data);
214 void
215 wlsc_binding_destroy(struct wlsc_binding *binding);
216
217 struct wlsc_surface *
218 wlsc_surface_create(struct wlsc_compositor *compositor,
219                     int32_t x, int32_t y, int32_t width, int32_t height);
220
221 void
222 wlsc_surface_assign_output(struct wlsc_surface *surface);
223
224 void
225 wlsc_surface_damage(struct wlsc_surface *surface);
226
227 void
228 wlsc_surface_damage_rectangle(struct wlsc_surface *surface,
229                               int32_t x, int32_t y,
230                               int32_t width, int32_t height);
231
232 void
233 wlsc_input_device_set_pointer_image(struct wlsc_input_device *device,
234                                     enum wlsc_pointer_type type);
235 struct wlsc_surface *
236 pick_surface(struct wl_input_device *device, int32_t *sx, int32_t *sy);
237
238 void
239 wlsc_selection_set_focus(struct wl_selection *selection,
240                          struct wl_surface *surface, uint32_t time);
241
242 uint32_t
243 get_time(void);
244
245 int
246 wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display);
247 void
248 wlsc_output_move(struct wlsc_output *output, int x, int y);
249 void
250 wlsc_output_init(struct wlsc_output *output, struct wlsc_compositor *c,
251                  int x, int y, int width, int height, uint32_t flags);
252 void
253 wlsc_output_destroy(struct wlsc_output *output);
254
255 void
256 wlsc_input_device_init(struct wlsc_input_device *device,
257                        struct wlsc_compositor *ec);
258
259 int
260 wlsc_shell_init(struct wlsc_compositor *ec);
261
262 void
263 wlsc_switcher_init(struct wlsc_compositor *compositor);
264
265 struct wlsc_compositor *
266 x11_compositor_create(struct wl_display *display, int width, int height);
267
268 struct wlsc_compositor *
269 drm_compositor_create(struct wl_display *display, int connector);
270
271 struct wlsc_compositor *
272 wfd_compositor_create(struct wl_display *display, int connector);
273
274 struct wlsc_compositor *
275 wayland_compositor_create(struct wl_display *display, int width, int height);
276
277 void
278 evdev_input_add_devices(struct wlsc_compositor *c, struct udev *udev);
279
280 struct tty *
281 tty_create(struct wlsc_compositor *compositor);
282
283 void
284 tty_destroy(struct tty *tty);
285
286 void
287 screenshooter_create(struct wlsc_compositor *ec);
288
289 uint32_t *
290 wlsc_load_image(const char *filename, int width, int height);
291
292 #endif