compositor: Use stride/4 as width for shm textures
[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_shader {
94         GLuint program;
95         GLuint vertex_shader, fragment_shader;
96         GLuint proj_uniform;
97         GLuint tex_uniform;
98         GLuint color_uniform;
99 };
100
101 struct wlsc_animation {
102         void (*frame)(struct wlsc_animation *animation,
103                       struct wlsc_output *output, uint32_t msecs);
104         struct wl_list link;
105 };
106
107 struct wlsc_tweener {
108         double k;
109         double current;
110         double target;
111         double previous;
112         uint32_t timestamp;
113 };
114
115 struct wlsc_shell {
116         void (*lock)(struct wlsc_shell *shell);
117         void (*attach)(struct wlsc_shell *shell, struct wlsc_surface *surface);
118 };
119
120 enum {
121         WLSC_COMPOSITOR_ACTIVE,
122         WLSC_COMPOSITOR_SLEEPING
123 };
124
125 struct wlsc_compositor {
126         struct wl_compositor compositor;
127
128         struct wl_shm *shm;
129
130         EGLDisplay display;
131         EGLContext context;
132         EGLConfig config;
133         GLuint fbo;
134         GLuint proj_uniform, tex_uniform;
135         struct wlsc_sprite **pointer_sprites;
136         struct wlsc_shader texture_shader;
137         struct wlsc_shader solid_shader;
138         struct wl_display *wl_display;
139
140         struct wlsc_shell *shell;
141
142         /* There can be more than one, but not right now... */
143         struct wl_input_device *input_device;
144
145         struct wl_list output_list;
146         struct wl_list input_device_list;
147         struct wl_list surface_list;
148         struct wl_list binding_list;
149         struct wl_list animation_list;
150         struct {
151                 struct wlsc_tweener tweener;
152                 struct wlsc_animation animation;
153         } fade;
154
155         uint32_t state;
156         struct wl_event_source *idle_source;
157         uint32_t idle_inhibit;
158
159         /* Repaint state. */
160         struct wl_event_source *timer_source;
161         int repaint_on_timeout;
162         struct timespec previous_swap;
163         pixman_region32_t damage_region;
164         struct wl_array vertices, indices;
165
166         struct wlsc_surface *overlay;
167         struct wlsc_switcher *switcher;
168         uint32_t focus;
169
170         void (*destroy)(struct wlsc_compositor *ec);
171         int (*authenticate)(struct wlsc_compositor *c, uint32_t id);
172         EGLImageKHR (*create_cursor_image)(struct wlsc_compositor *c,
173                                            int32_t width, int32_t height);
174 };
175
176 #define MODIFIER_CTRL   (1 << 8)
177 #define MODIFIER_ALT    (1 << 9)
178 #define MODIFIER_SUPER  (1 << 10)
179
180 enum wlsc_output_flags {
181         WL_OUTPUT_FLIPPED = 0x01
182 };
183
184 struct wlsc_vector {
185         GLfloat f[4];
186 };
187
188 enum wlsc_surface_map_type {
189         WLSC_SURFACE_MAP_UNMAPPED,
190         WLSC_SURFACE_MAP_TOPLEVEL,
191         WLSC_SURFACE_MAP_TRANSIENT,
192         WLSC_SURFACE_MAP_FULLSCREEN
193 };
194
195 struct wlsc_surface {
196         struct wl_surface surface;
197         struct wlsc_compositor *compositor;
198         GLuint texture, saved_texture;
199         int32_t x, y, width, height;
200         int32_t pitch;
201         int32_t saved_x, saved_y;
202         struct wl_list link;
203         struct wl_list buffer_link;
204         struct wlsc_matrix matrix;
205         struct wlsc_matrix matrix_inv;
206         struct wl_visual *visual;
207         struct wl_buffer *buffer;
208         struct wlsc_output *output;
209         enum wlsc_surface_map_type map_type;
210         struct wlsc_output *fullscreen_output;
211
212         EGLImageKHR image;
213 };
214
215 void
216 wlsc_tweener_init(struct wlsc_tweener *tweener,
217                   double k, double current, double target);
218 void
219 wlsc_tweener_update(struct wlsc_tweener *tweener, uint32_t msec);
220 int
221 wlsc_tweener_done(struct wlsc_tweener *tweener);
222
223 void
224 wlsc_surface_update_matrix(struct wlsc_surface *es);
225
226 void
227 wlsc_surface_activate(struct wlsc_surface *surface,
228                       struct wlsc_input_device *device, uint32_t time);
229
230 void
231 notify_motion(struct wl_input_device *device,
232               uint32_t time, int x, int y);
233 void
234 notify_button(struct wl_input_device *device,
235               uint32_t time, int32_t button, int32_t state);
236 void
237 notify_key(struct wl_input_device *device,
238            uint32_t time, uint32_t key, uint32_t state);
239
240 void
241 notify_pointer_focus(struct wl_input_device *device,
242                      uint32_t time,
243                      struct wlsc_output *output,
244                      int32_t x, int32_t y);
245
246 void
247 notify_keyboard_focus(struct wl_input_device *device,
248                       uint32_t time, struct wlsc_output *output,
249                       struct wl_array *keys);
250
251 void
252 wlsc_output_finish_frame(struct wlsc_output *output, int msecs);
253 void
254 wlsc_output_damage(struct wlsc_output *output);
255 void
256 wlsc_compositor_schedule_repaint(struct wlsc_compositor *compositor);
257 void
258 wlsc_compositor_fade(struct wlsc_compositor *compositor, float tint);
259 void
260 wlsc_compositor_damage_all(struct wlsc_compositor *compositor);
261 void
262 wlsc_compositor_unlock(struct wlsc_compositor *compositor);
263 void
264 wlsc_compositor_wake(struct wlsc_compositor *compositor);
265
266 struct wlsc_binding;
267 typedef void (*wlsc_binding_handler_t)(struct wl_input_device *device,
268                                        uint32_t time, uint32_t key,
269                                        uint32_t button,
270                                        uint32_t state, void *data);
271 struct wlsc_binding *
272 wlsc_compositor_add_binding(struct wlsc_compositor *compositor,
273                             uint32_t key, uint32_t button, uint32_t modifier,
274                             wlsc_binding_handler_t binding, void *data);
275 void
276 wlsc_binding_destroy(struct wlsc_binding *binding);
277
278 struct wlsc_surface *
279 wlsc_surface_create(struct wlsc_compositor *compositor,
280                     int32_t x, int32_t y, int32_t width, int32_t height);
281
282 void
283 wlsc_surface_assign_output(struct wlsc_surface *surface);
284
285 void
286 wlsc_surface_damage(struct wlsc_surface *surface);
287
288 void
289 wlsc_surface_damage_rectangle(struct wlsc_surface *surface,
290                               int32_t x, int32_t y,
291                               int32_t width, int32_t height);
292
293 void
294 wlsc_input_device_set_pointer_image(struct wlsc_input_device *device,
295                                     enum wlsc_pointer_type type);
296 struct wlsc_surface *
297 pick_surface(struct wl_input_device *device, int32_t *sx, int32_t *sy);
298
299 void
300 wlsc_selection_set_focus(struct wl_selection *selection,
301                          struct wl_surface *surface, uint32_t time);
302
303 uint32_t
304 wlsc_compositor_get_time(void);
305
306 int
307 wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display);
308 void
309 wlsc_output_move(struct wlsc_output *output, int x, int y);
310 void
311 wlsc_output_init(struct wlsc_output *output, struct wlsc_compositor *c,
312                  int x, int y, int width, int height, uint32_t flags);
313 void
314 wlsc_output_destroy(struct wlsc_output *output);
315
316 void
317 wlsc_input_device_init(struct wlsc_input_device *device,
318                        struct wlsc_compositor *ec);
319
320 int
321 desktop_shell_init(struct wlsc_compositor *ec);
322
323 void
324 wlsc_switcher_init(struct wlsc_compositor *compositor);
325
326 struct wlsc_compositor *
327 x11_compositor_create(struct wl_display *display, int width, int height);
328
329 struct wlsc_compositor *
330 drm_compositor_create(struct wl_display *display, int connector);
331
332 struct wlsc_compositor *
333 wfd_compositor_create(struct wl_display *display, int connector);
334
335 struct wlsc_compositor *
336 wayland_compositor_create(struct wl_display *display, int width, int height);
337
338 void
339 evdev_input_add_devices(struct wlsc_compositor *c, struct udev *udev);
340
341 struct tty *
342 tty_create(struct wlsc_compositor *compositor);
343
344 void
345 tty_destroy(struct tty *tty);
346
347 void
348 screenshooter_create(struct wlsc_compositor *ec);
349
350 uint32_t *
351 wlsc_load_image(const char *filename, int width, int height);
352
353 #endif