Use pixman regions to reduce repainting
[profile/ivi/wayland.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 <xf86drm.h>
23 #include <xf86drmMode.h>
24 #include <libudev.h>
25 #include <pixman.h>
26 #include "wayland-server.h"
27 #include "wayland-util.h"
28
29 #define GL_GLEXT_PROTOTYPES
30 #define EGL_EGLEXT_PROTOTYPES
31 #include <GLES2/gl2.h>
32 #include <GLES2/gl2ext.h>
33 #include <EGL/egl.h>
34 #include <EGL/eglext.h>
35
36 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
37
38 struct wlsc_matrix {
39         GLfloat d[16];
40 };
41
42 struct wlsc_surface;
43
44 struct wlsc_output {
45         struct wl_object object;
46         struct wl_list link;
47         struct wlsc_compositor *compositor;
48         struct wlsc_surface *background;
49         struct wlsc_matrix matrix;
50         int32_t x, y, width, height;
51         pixman_region32_t previous_damage_region;
52 };
53
54 enum wlsc_pointer_type {
55         WLSC_POINTER_BOTTOM_LEFT,
56         WLSC_POINTER_BOTTOM_RIGHT,
57         WLSC_POINTER_BOTTOM,
58         WLSC_POINTER_DRAGGING,
59         WLSC_POINTER_LEFT_PTR,
60         WLSC_POINTER_LEFT,
61         WLSC_POINTER_RIGHT,
62         WLSC_POINTER_TOP_LEFT,
63         WLSC_POINTER_TOP_RIGHT,
64         WLSC_POINTER_TOP,
65         WLSC_POINTER_IBEAM,
66 };
67
68 struct wlsc_input_device {
69         struct wl_input_device input_device;
70         struct wlsc_surface *sprite;
71         int32_t hotspot_x, hotspot_y;
72         struct wl_list link;
73         uint32_t modifier_state;
74         struct wl_selection *selection;
75 };
76
77 struct wlsc_drm {
78         struct wl_object object;
79         int fd;
80         char *filename;
81 };
82
83 struct wlsc_shm {
84         struct wl_object object;
85 };
86
87 struct wlsc_compositor {
88         struct wl_compositor compositor;
89
90         struct wlsc_drm drm;
91         struct wlsc_shm shm;
92         EGLDisplay display;
93         EGLContext context;
94         GLuint fbo, vbo;
95         GLuint proj_uniform, tex_uniform;
96         struct wl_buffer **pointer_buffers;
97         struct wl_display *wl_display;
98
99         /* We implement the shell interface. */
100         struct wl_shell shell;
101
102         /* There can be more than one, but not right now... */
103         struct wl_input_device *input_device;
104
105         struct wl_list output_list;
106         struct wl_list input_device_list;
107         struct wl_list surface_list;
108
109         /* Repaint state. */
110         struct wl_event_source *timer_source;
111         int repaint_needed;
112         int repaint_on_timeout;
113         struct timespec previous_swap;
114         pixman_region32_t damage_region;
115
116         struct wlsc_switcher *switcher;
117         uint32_t focus;
118
119         void (*destroy)(struct wlsc_compositor *ec);
120         int (*authenticate)(struct wlsc_compositor *c, uint32_t id);
121         void (*present)(struct wlsc_compositor *c);
122         struct wl_buffer *(*create_buffer)(struct wlsc_compositor *c,
123                                            int32_t width, int32_t height,
124                                            struct wl_visual *visual,
125                                            const void *data);
126 };
127
128 #define MODIFIER_CTRL   (1 << 8)
129 #define MODIFIER_ALT    (1 << 9)
130 #define MODIFIER_SUPER  (1 << 10)
131
132 struct wlsc_vector {
133         GLfloat f[4];
134 };
135
136 enum wlsc_surface_map_type {
137         WLSC_SURFACE_MAP_UNMAPPED,
138         WLSC_SURFACE_MAP_TOPLEVEL,
139         WLSC_SURFACE_MAP_TRANSIENT,
140         WLSC_SURFACE_MAP_FULLSCREEN
141 };
142
143 struct wlsc_surface {
144         struct wl_surface surface;
145         struct wlsc_compositor *compositor;
146         GLuint texture;
147         int32_t x, y, width, height;
148         int32_t saved_x, saved_y;
149         struct wl_list link;
150         struct wlsc_matrix matrix;
151         struct wlsc_matrix matrix_inv;
152         struct wl_visual *visual;
153         struct wl_buffer *buffer;
154         enum wlsc_surface_map_type map_type;
155         struct wlsc_output *fullscreen_output;
156 };
157
158 void
159 wlsc_surface_update_matrix(struct wlsc_surface *es);
160
161 void
162 notify_motion(struct wl_input_device *device,
163               uint32_t time, int x, int y);
164 void
165 notify_button(struct wl_input_device *device,
166               uint32_t time, int32_t button, int32_t state);
167 void
168 notify_key(struct wl_input_device *device,
169            uint32_t time, uint32_t key, uint32_t state);
170
171 void
172 notify_pointer_focus(struct wl_input_device *device,
173                      uint32_t time,
174                      struct wlsc_output *output,
175                      int32_t x, int32_t y);
176
177 void
178 notify_keyboard_focus(struct wl_input_device *device,
179                       uint32_t time, struct wlsc_output *output,
180                       struct wl_array *keys);
181
182 void
183 wlsc_compositor_finish_frame(struct wlsc_compositor *compositor, int msecs);
184 void
185 wlsc_compositor_schedule_repaint(struct wlsc_compositor *compositor);
186
187 void
188 wlsc_surface_damage(struct wlsc_surface *surface);
189
190 void
191 wlsc_surface_damage_rectangle(struct wlsc_surface *surface,
192                               int32_t x, int32_t y,
193                               int32_t width, int32_t height);
194
195 void
196 wlsc_input_device_set_pointer_image(struct wlsc_input_device *device,
197                                     enum wlsc_pointer_type type);
198 struct wlsc_surface *
199 pick_surface(struct wl_input_device *device, int32_t *sx, int32_t *sy);
200
201 void
202 wlsc_selection_set_focus(struct wl_selection *selection,
203                          struct wl_surface *surface, uint32_t time);
204
205 uint32_t
206 get_time(void);
207
208 struct wl_buffer *
209 wlsc_drm_buffer_create(struct wlsc_compositor *ec,
210                        int width, int height,
211                        struct wl_visual *visual, const void *data);
212
213 int
214 wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display);
215 void
216 wlsc_output_init(struct wlsc_output *output, struct wlsc_compositor *c,
217                  int x, int y, int width, int height);
218 void
219 wlsc_input_device_init(struct wlsc_input_device *device,
220                        struct wlsc_compositor *ec);
221 int
222 wlsc_drm_init(struct wlsc_compositor *ec, int fd, const char *filename);
223
224 int
225 wlsc_shm_init(struct wlsc_compositor *ec);
226
227 int
228 wlsc_shell_init(struct wlsc_compositor *ec);
229
230 void
231 shell_move(struct wl_client *client, struct wl_shell *shell,
232            struct wl_surface *surface,
233            struct wl_input_device *device, uint32_t time);
234
235 void
236 shell_resize(struct wl_client *client, struct wl_shell *shell,
237              struct wl_surface *surface,
238              struct wl_input_device *device, uint32_t time, uint32_t edges);
239
240 struct wl_buffer *
241 wl_buffer_create_drm(struct wlsc_compositor *compositor,
242                      struct wl_visual *visual);
243
244 struct wlsc_compositor *
245 x11_compositor_create(struct wl_display *display, int width, int height);
246
247 struct wlsc_compositor *
248 drm_compositor_create(struct wl_display *display, int connector);
249
250 struct wlsc_compositor *
251 wayland_compositor_create(struct wl_display *display, int width, int height);
252
253 void
254 evdev_input_add_devices(struct wlsc_compositor *c, struct udev *udev);
255
256 struct tty *
257 tty_create(struct wlsc_compositor *compositor);
258
259 void
260 tty_destroy(struct tty *tty);
261
262 void
263 screenshooter_create(struct wlsc_compositor *ec);
264
265 uint32_t *
266 wlsc_load_image(const char *filename, int width, int height);
267
268 #endif