097cdc64455d487cfbcc7a989b9207d8d7614b87
[profile/ivi/wayland.git] / 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 <termios.h>
23 #include <xf86drm.h>
24 #include <xf86drmMode.h>
25 #include <libudev.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_listener {
45         struct wl_list link;
46         void (*func)(struct wlsc_listener *listener,
47                      struct wlsc_surface *surface);
48 };
49
50 struct wlsc_output {
51         struct wl_object base;
52         struct wl_list link;
53         struct wlsc_compositor *compositor;
54         struct wlsc_surface *background;
55         struct wlsc_matrix matrix;
56         int32_t x, y, width, height;
57 };
58
59 /* These should be part of the protocol */
60 enum wlsc_grab_type {
61         WLSC_DEVICE_GRAB_NONE = 0,
62         WLSC_DEVICE_GRAB_RESIZE_TOP = 1,
63         WLSC_DEVICE_GRAB_RESIZE_BOTTOM = 2,
64         WLSC_DEVICE_GRAB_RESIZE_LEFT = 4,
65         WLSC_DEVICE_GRAB_RESIZE_TOP_LEFT = 5,
66         WLSC_DEVICE_GRAB_RESIZE_BOTTOM_LEFT = 6,
67         WLSC_DEVICE_GRAB_RESIZE_RIGHT = 8,
68         WLSC_DEVICE_GRAB_RESIZE_TOP_RIGHT = 9,
69         WLSC_DEVICE_GRAB_RESIZE_BOTTOM_RIGHT = 10,
70         WLSC_DEVICE_GRAB_RESIZE_MASK = 15,
71         WLSC_DEVICE_GRAB_MOVE = 16,
72         WLSC_DEVICE_GRAB_MOTION = 17,
73         WLSC_DEVICE_GRAB_DRAG = 18
74 };
75
76 enum wlsc_pointer_type {
77         WLSC_POINTER_BOTTOM_LEFT,
78         WLSC_POINTER_BOTTOM_RIGHT,
79         WLSC_POINTER_BOTTOM,
80         WLSC_POINTER_DRAGGING,
81         WLSC_POINTER_LEFT_PTR,
82         WLSC_POINTER_LEFT,
83         WLSC_POINTER_RIGHT,
84         WLSC_POINTER_TOP_LEFT,
85         WLSC_POINTER_TOP_RIGHT,
86         WLSC_POINTER_TOP,
87         WLSC_POINTER_IBEAM,
88 };
89
90 struct wlsc_input_device {
91         struct wl_input_device base;
92         int32_t x, y;
93         struct wlsc_compositor *ec;
94         struct wlsc_surface *sprite;
95         int32_t hotspot_x, hotspot_y;
96         struct wl_list link;
97
98         struct wlsc_surface *pointer_focus;
99         struct wlsc_surface *keyboard_focus;
100         struct wl_array keys;
101         uint32_t modifier_state;
102
103         enum wlsc_grab_type grab;
104         struct wlsc_surface *grab_surface;
105         uint32_t grab_time;
106         int32_t grab_x, grab_y;
107         int32_t grab_width, grab_height;
108         int32_t grab_dx, grab_dy;
109         uint32_t grab_button;
110         struct wl_drag *drag;
111
112         struct wlsc_listener listener;
113 };
114
115 struct wlsc_drm {
116         struct wl_object base;
117         int fd;
118         char *filename;
119 };
120
121 struct wlsc_buffer {
122         struct wl_buffer base;
123         int32_t width, height;
124         EGLImageKHR image;
125         struct wl_visual *visual;
126 };
127
128 struct wlsc_compositor {
129         struct wl_compositor base;
130         struct wl_visual argb_visual, premultiplied_argb_visual, rgb_visual;
131
132         struct wlsc_drm drm;
133         EGLDisplay display;
134         EGLContext context;
135         GLuint fbo, vbo;
136         GLuint proj_uniform, tex_uniform;
137         struct wlsc_buffer *pointer_buffers;
138         struct wl_display *wl_display;
139
140         /* We implement the shell interface. */
141         struct wl_shell shell;
142
143         /* There can be more than one, but not right now... */
144         struct wlsc_input_device *input_device;
145
146         struct wl_list output_list;
147         struct wl_list input_device_list;
148         struct wl_list surface_list;
149
150         struct wl_list surface_destroy_listener_list;
151
152         /* Repaint state. */
153         struct wl_event_source *timer_source;
154         int repaint_needed;
155         int repaint_on_timeout;
156         struct timespec previous_swap;
157         uint32_t current_frame;
158
159         uint32_t focus;
160
161         int (*authenticate)(struct wlsc_compositor *c, uint32_t id);
162         void (*present)(struct wlsc_compositor *c);
163 };
164
165 #define MODIFIER_CTRL   (1 << 8)
166 #define MODIFIER_ALT    (1 << 9)
167 #define MODIFIER_SUPER  (1 << 10)
168
169 struct wlsc_vector {
170         GLfloat f[4];
171 };
172
173 struct wlsc_surface {
174         struct wl_surface base;
175         struct wlsc_compositor *compositor;
176         GLuint texture;
177         int32_t x, y, width, height;
178         struct wl_list link;
179         struct wlsc_matrix matrix;
180         struct wlsc_matrix matrix_inv;
181         struct wl_visual *visual;
182 };
183
184 void
185 notify_motion(struct wlsc_input_device *device,
186               uint32_t time, int x, int y);
187 void
188 notify_button(struct wlsc_input_device *device,
189               uint32_t time, int32_t button, int32_t state);
190 void
191 notify_key(struct wlsc_input_device *device,
192            uint32_t time, uint32_t key, uint32_t state);
193
194 void
195 wlsc_compositor_finish_frame(struct wlsc_compositor *compositor, int msecs);
196 void
197 wlsc_compositor_schedule_repaint(struct wlsc_compositor *compositor);
198
199 int
200 wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display);
201 void
202 wlsc_output_init(struct wlsc_output *output, struct wlsc_compositor *c,
203                  int x, int y, int width, int height);
204 void
205 wlsc_input_device_init(struct wlsc_input_device *device,
206                        struct wlsc_compositor *ec);
207 int
208 wlsc_drm_init(struct wlsc_compositor *ec, int fd, const char *filename);
209
210 struct wlsc_compositor *
211 x11_compositor_create(struct wl_display *display);
212
213 struct wlsc_compositor *
214 drm_compositor_create(struct wl_display *display);
215
216 void
217 screenshooter_create(struct wlsc_compositor *ec);
218
219 extern const char *option_background;
220 extern int option_connector;
221
222 #endif