2 * Copyright © 2008 Kristian Høgsberg
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.
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.
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.
19 #ifndef _WAYLAND_SYSTEM_COMPOSITOR_H_
20 #define _WAYLAND_SYSTEM_COMPOSITOR_H_
24 #include <xf86drmMode.h>
26 #include "wayland-server.h"
27 #include "wayland-util.h"
29 #define GL_GLEXT_PROTOTYPES
30 #define EGL_EGLEXT_PROTOTYPES
31 #include <GLES2/gl2.h>
32 #include <GLES2/gl2ext.h>
34 #include <EGL/eglext.h>
36 #define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
44 struct wlsc_listener {
46 void (*func)(struct wlsc_listener *listener,
47 struct wlsc_surface *surface);
51 struct wl_object base;
53 struct wlsc_compositor *compositor;
54 struct wlsc_surface *background;
55 struct wlsc_matrix matrix;
56 int32_t x, y, width, height;
59 /* These should be part of the protocol */
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
76 enum wlsc_pointer_type {
77 WLSC_POINTER_BOTTOM_LEFT,
78 WLSC_POINTER_BOTTOM_RIGHT,
80 WLSC_POINTER_DRAGGING,
81 WLSC_POINTER_LEFT_PTR,
84 WLSC_POINTER_TOP_LEFT,
85 WLSC_POINTER_TOP_RIGHT,
90 struct wlsc_input_device {
91 struct wl_input_device base;
93 struct wlsc_compositor *ec;
94 struct wlsc_surface *sprite;
95 int32_t hotspot_x, hotspot_y;
98 struct wlsc_surface *pointer_focus;
99 struct wlsc_surface *keyboard_focus;
100 struct wl_array keys;
101 uint32_t modifier_state;
103 enum wlsc_grab_type grab;
104 struct wlsc_surface *grab_surface;
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;
112 struct wlsc_listener listener;
116 struct wl_object base;
122 struct wl_buffer base;
123 int32_t width, height;
125 struct wl_visual *visual;
128 struct wlsc_compositor {
129 struct wl_compositor base;
130 struct wl_visual argb_visual, premultiplied_argb_visual, rgb_visual;
136 GLuint proj_uniform, tex_uniform;
137 struct wlsc_buffer *pointer_buffers;
138 struct wl_display *wl_display;
140 /* We implement the shell interface. */
141 struct wl_shell shell;
143 /* There can be more than one, but not right now... */
144 struct wlsc_input_device *input_device;
146 struct wl_list output_list;
147 struct wl_list input_device_list;
148 struct wl_list surface_list;
150 struct wl_list surface_destroy_listener_list;
153 struct wl_event_source *timer_source;
155 int repaint_on_timeout;
156 struct timespec previous_swap;
157 uint32_t current_frame;
161 int (*authenticate)(struct wlsc_compositor *c, uint32_t id);
162 void (*present)(struct wlsc_compositor *c);
165 #define MODIFIER_CTRL (1 << 8)
166 #define MODIFIER_ALT (1 << 9)
167 #define MODIFIER_SUPER (1 << 10)
173 struct wlsc_surface {
174 struct wl_surface base;
175 struct wlsc_compositor *compositor;
177 int32_t x, y, width, height;
179 struct wlsc_matrix matrix;
180 struct wlsc_matrix matrix_inv;
181 struct wl_visual *visual;
185 notify_motion(struct wlsc_input_device *device,
186 uint32_t time, int x, int y);
188 notify_button(struct wlsc_input_device *device,
189 uint32_t time, int32_t button, int32_t state);
191 notify_key(struct wlsc_input_device *device,
192 uint32_t time, uint32_t key, uint32_t state);
195 wlsc_compositor_finish_frame(struct wlsc_compositor *compositor, int msecs);
197 wlsc_compositor_schedule_repaint(struct wlsc_compositor *compositor);
200 wlsc_compositor_init(struct wlsc_compositor *ec, struct wl_display *display);
202 wlsc_output_init(struct wlsc_output *output, struct wlsc_compositor *c,
203 int x, int y, int width, int height);
205 wlsc_input_device_init(struct wlsc_input_device *device,
206 struct wlsc_compositor *ec);
208 wlsc_drm_init(struct wlsc_compositor *ec, int fd, const char *filename);
210 struct wlsc_compositor *
211 x11_compositor_create(struct wl_display *display);
213 struct wlsc_compositor *
214 drm_compositor_create(struct wl_display *display);
217 screenshooter_create(struct wlsc_compositor *ec);
219 extern const char *option_background;
220 extern int option_connector;