277f8cd37e3852c4b332cd5f32af27d6d85a926e
[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 <xf86drm.h>
23 #include <xf86drmMode.h>
24 #include <libudev.h>
25 #include "wayland-server.h"
26 #include "wayland-util.h"
27
28 #define GL_GLEXT_PROTOTYPES
29 #define EGL_EGLEXT_PROTOTYPES
30 #include <GLES2/gl2.h>
31 #include <GLES2/gl2ext.h>
32 #include <EGL/egl.h>
33 #include <EGL/eglext.h>
34
35 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
36
37 struct wlsc_matrix {
38         GLfloat d[16];
39 };
40
41 struct wlsc_surface;
42
43 struct wlsc_output {
44         struct wl_object object;
45         struct wl_list link;
46         struct wlsc_compositor *compositor;
47         struct wlsc_surface *background;
48         struct wlsc_matrix matrix;
49         int32_t x, y, width, height;
50 };
51
52 enum wlsc_pointer_type {
53         WLSC_POINTER_BOTTOM_LEFT,
54         WLSC_POINTER_BOTTOM_RIGHT,
55         WLSC_POINTER_BOTTOM,
56         WLSC_POINTER_DRAGGING,
57         WLSC_POINTER_LEFT_PTR,
58         WLSC_POINTER_LEFT,
59         WLSC_POINTER_RIGHT,
60         WLSC_POINTER_TOP_LEFT,
61         WLSC_POINTER_TOP_RIGHT,
62         WLSC_POINTER_TOP,
63         WLSC_POINTER_IBEAM,
64 };
65
66 struct wlsc_input_device {
67         struct wl_input_device input_device;
68         struct wlsc_surface *sprite;
69         int32_t hotspot_x, hotspot_y;
70         struct wl_list link;
71         uint32_t modifier_state;
72 };
73
74 struct wlsc_drm {
75         struct wl_object object;
76         int fd;
77         char *filename;
78 };
79
80 struct wlsc_drm_buffer {
81         struct wl_buffer buffer;
82         EGLImageKHR image;
83 };
84
85 struct wlsc_shm {
86         struct wl_object object;
87 };
88
89 struct wlsc_shm_buffer {
90         struct wl_buffer buffer;
91         int32_t stride;
92         void *data;
93 };
94
95 struct wlsc_compositor {
96         struct wl_compositor compositor;
97
98         struct wlsc_drm drm;
99         struct wlsc_shm shm;
100         EGLDisplay display;
101         EGLContext context;
102         GLuint fbo, vbo;
103         GLuint proj_uniform, tex_uniform;
104         struct wlsc_drm_buffer **pointer_buffers;
105         struct wl_display *wl_display;
106
107         /* We implement the shell interface. */
108         struct wl_shell shell;
109
110         /* There can be more than one, but not right now... */
111         struct wl_input_device *input_device;
112
113         struct wl_list output_list;
114         struct wl_list input_device_list;
115         struct wl_list surface_list;
116
117         /* Repaint state. */
118         struct wl_event_source *timer_source;
119         int repaint_needed;
120         int repaint_on_timeout;
121         struct timespec previous_swap;
122
123         uint32_t focus;
124
125         void (*destroy)(struct wlsc_compositor *ec);
126         int (*authenticate)(struct wlsc_compositor *c, uint32_t id);
127         void (*present)(struct wlsc_compositor *c);
128 };
129
130 #define MODIFIER_CTRL   (1 << 8)
131 #define MODIFIER_ALT    (1 << 9)
132 #define MODIFIER_SUPER  (1 << 10)
133
134 struct wlsc_vector {
135         GLfloat f[4];
136 };
137
138 struct wlsc_surface {
139         struct wl_surface surface;
140         struct wlsc_compositor *compositor;
141         GLuint texture;
142         int32_t x, y, width, height;
143         struct wl_list link;
144         struct wlsc_matrix matrix;
145         struct wlsc_matrix matrix_inv;
146         struct wl_visual *visual;
147         struct wl_buffer *buffer;
148         int mapped;
149 };
150
151 void
152 notify_motion(struct wl_input_device *device,
153               uint32_t time, int x, int y);
154 void
155 notify_button(struct wl_input_device *device,
156               uint32_t time, int32_t button, int32_t state);
157 void
158 notify_key(struct wl_input_device *device,
159            uint32_t time, uint32_t key, uint32_t state);
160
161 void
162 wlsc_compositor_finish_frame(struct wlsc_compositor *compositor, int msecs);
163 void
164 wlsc_compositor_schedule_repaint(struct wlsc_compositor *compositor);
165
166 struct wlsc_drm_buffer *
167 wlsc_drm_buffer_create(struct wlsc_compositor *ec,
168                        int width, int height, struct wl_visual *visual);
169
170 int
171 wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display);
172 void
173 wlsc_output_init(struct wlsc_output *output, struct wlsc_compositor *c,
174                  int x, int y, int width, int height);
175 void
176 wlsc_input_device_init(struct wlsc_input_device *device,
177                        struct wlsc_compositor *ec);
178 int
179 wlsc_drm_init(struct wlsc_compositor *ec, int fd, const char *filename);
180
181 int
182 wlsc_shm_init(struct wlsc_compositor *ec);
183
184 struct wl_buffer *
185 wl_buffer_create_drm(struct wlsc_compositor *compositor,
186                      struct wl_visual *visual);
187
188 struct wlsc_compositor *
189 x11_compositor_create(struct wl_display *display, int width, int height);
190
191 struct wlsc_compositor *
192 drm_compositor_create(struct wl_display *display, int connector);
193
194 struct wlsc_compositor *
195 wayland_compositor_create(struct wl_display *display, int width, int height);
196
197 void
198 evdev_input_add_devices(struct wlsc_compositor *c, struct udev *udev);
199
200 struct tty *
201 tty_create(struct wlsc_compositor *compositor);
202
203 void
204 tty_destroy(struct tty *tty);
205
206 void
207 screenshooter_create(struct wlsc_compositor *ec);
208
209 #endif