Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright © 2008-2011 Kristian Høgsberg |
| 3 | * |
| 4 | * Permission to use, copy, modify, distribute, and sell this software and |
| 5 | * its documentation for any purpose is hereby granted without fee, provided |
| 6 | * that the above copyright notice appear in all copies and that both that |
| 7 | * copyright notice and this permission notice appear in supporting |
| 8 | * documentation, and that the name of the copyright holders not be used in |
| 9 | * advertising or publicity pertaining to distribution of the software |
| 10 | * without specific, written prior permission. The copyright holders make |
| 11 | * no representations about the suitability of this software for any |
| 12 | * purpose. It is provided "as is" without express or implied warranty. |
| 13 | * |
| 14 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 15 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 16 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 17 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 18 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 19 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 20 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 21 | */ |
| 22 | |
| 23 | #ifndef _WAYLAND_SYSTEM_COMPOSITOR_H_ |
| 24 | #define _WAYLAND_SYSTEM_COMPOSITOR_H_ |
| 25 | |
| 26 | #include <libudev.h> |
| 27 | #include <pixman.h> |
| 28 | #include <wayland-server.h> |
| 29 | |
| 30 | #include <GLES2/gl2.h> |
| 31 | #include <GLES2/gl2ext.h> |
| 32 | #include <EGL/egl.h> |
| 33 | #include <EGL/eglext.h> |
| 34 | |
| 35 | struct weston_matrix { |
| 36 | GLfloat d[16]; |
| 37 | }; |
| 38 | |
| 39 | struct weston_vector { |
| 40 | GLfloat f[4]; |
| 41 | }; |
| 42 | |
| 43 | void |
| 44 | weston_matrix_init(struct weston_matrix *matrix); |
| 45 | void |
| 46 | weston_matrix_scale(struct weston_matrix *matrix, GLfloat x, GLfloat y, GLfloat z); |
| 47 | void |
| 48 | weston_matrix_translate(struct weston_matrix *matrix, |
| 49 | GLfloat x, GLfloat y, GLfloat z); |
| 50 | void |
| 51 | weston_matrix_transform(struct weston_matrix *matrix, struct weston_vector *v); |
| 52 | |
| 53 | struct weston_transform { |
| 54 | struct weston_matrix matrix; |
| 55 | struct weston_matrix inverse; |
| 56 | }; |
| 57 | |
| 58 | struct weston_surface; |
| 59 | struct weston_input_device; |
| 60 | |
| 61 | struct weston_mode { |
| 62 | uint32_t flags; |
| 63 | int32_t width, height; |
| 64 | uint32_t refresh; |
| 65 | struct wl_list link; |
| 66 | }; |
| 67 | |
| 68 | struct weston_output { |
| 69 | struct wl_list link; |
| 70 | struct weston_compositor *compositor; |
| 71 | struct weston_matrix matrix; |
| 72 | struct wl_list frame_callback_list; |
| 73 | int32_t x, y, mm_width, mm_height; |
| 74 | pixman_region32_t region; |
| 75 | pixman_region32_t previous_damage; |
| 76 | uint32_t flags; |
| 77 | int repaint_needed; |
| 78 | int repaint_scheduled; |
| 79 | |
| 80 | char *make, *model; |
| 81 | uint32_t subpixel; |
| 82 | |
| 83 | struct weston_mode *current; |
| 84 | struct wl_list mode_list; |
| 85 | struct wl_buffer *scanout_buffer; |
| 86 | struct wl_listener scanout_buffer_destroy_listener; |
| 87 | struct wl_buffer *pending_scanout_buffer; |
| 88 | struct wl_listener pending_scanout_buffer_destroy_listener; |
| 89 | |
| 90 | int (*prepare_render)(struct weston_output *output); |
| 91 | int (*present)(struct weston_output *output); |
| 92 | int (*prepare_scanout_surface)(struct weston_output *output, |
| 93 | struct weston_surface *es); |
| 94 | int (*set_hardware_cursor)(struct weston_output *output, |
| 95 | struct weston_input_device *input); |
| 96 | void (*destroy)(struct weston_output *output); |
| 97 | }; |
| 98 | |
| 99 | struct weston_input_device { |
| 100 | struct wl_input_device input_device; |
| 101 | struct weston_compositor *compositor; |
| 102 | struct weston_surface *sprite; |
| 103 | int32_t hotspot_x, hotspot_y; |
| 104 | struct wl_list link; |
| 105 | uint32_t modifier_state; |
| 106 | struct wl_selection *selection; |
| 107 | |
| 108 | struct wl_list drag_resource_list; |
| 109 | struct weston_data_source *drag_data_source; |
| 110 | struct wl_surface *drag_focus; |
| 111 | struct wl_resource *drag_focus_resource; |
| 112 | struct wl_listener drag_focus_listener; |
| 113 | |
| 114 | struct weston_data_source *selection_data_source; |
| 115 | struct wl_listener selection_data_source_listener; |
| 116 | struct wl_grab grab; |
| 117 | |
| 118 | uint32_t num_tp; |
| 119 | struct wl_surface *touch_focus; |
| 120 | struct wl_listener touch_focus_listener; |
| 121 | struct wl_resource *touch_focus_resource; |
| 122 | struct wl_listener touch_focus_resource_listener; |
| 123 | }; |
| 124 | |
| 125 | enum weston_visual { |
| 126 | WESTON_NONE_VISUAL, |
| 127 | WESTON_ARGB_VISUAL, |
| 128 | WESTON_PREMUL_ARGB_VISUAL, |
| 129 | WESTON_RGB_VISUAL |
| 130 | }; |
| 131 | |
| 132 | struct weston_shader { |
| 133 | GLuint program; |
| 134 | GLuint vertex_shader, fragment_shader; |
| 135 | GLuint proj_uniform; |
| 136 | GLuint tex_uniform; |
| 137 | GLuint alpha_uniform; |
| 138 | GLuint color_uniform; |
| 139 | }; |
| 140 | |
| 141 | struct weston_animation { |
| 142 | void (*frame)(struct weston_animation *animation, |
| 143 | struct weston_output *output, uint32_t msecs); |
| 144 | struct wl_list link; |
| 145 | }; |
| 146 | |
| 147 | struct weston_spring { |
| 148 | double k; |
| 149 | double friction; |
| 150 | double current; |
| 151 | double target; |
| 152 | double previous; |
| 153 | uint32_t timestamp; |
| 154 | }; |
| 155 | |
| 156 | struct weston_shell { |
| 157 | void (*lock)(struct weston_shell *shell); |
| 158 | void (*unlock)(struct weston_shell *shell); |
| 159 | void (*map)(struct weston_shell *shell, struct weston_surface *surface, |
| 160 | int32_t width, int32_t height); |
| 161 | void (*configure)(struct weston_shell *shell, |
| 162 | struct weston_surface *surface, |
| 163 | int32_t x, int32_t y, int32_t width, int32_t height); |
| 164 | }; |
| 165 | |
| 166 | enum { |
| 167 | WESTON_COMPOSITOR_ACTIVE, |
| 168 | WESTON_COMPOSITOR_IDLE, /* shell->unlock called on activity */ |
| 169 | WESTON_COMPOSITOR_SLEEPING /* no rendering, no frame events */ |
| 170 | }; |
| 171 | |
| 172 | struct weston_compositor { |
| 173 | struct wl_shm *shm; |
| 174 | struct weston_xserver *wxs; |
| 175 | |
| 176 | EGLDisplay display; |
| 177 | EGLContext context; |
| 178 | EGLConfig config; |
| 179 | GLuint fbo; |
| 180 | GLuint proj_uniform, tex_uniform, alpha_uniform; |
| 181 | uint32_t current_alpha; |
| 182 | struct weston_shader texture_shader; |
| 183 | struct weston_shader solid_shader; |
| 184 | struct wl_display *wl_display; |
| 185 | |
| 186 | struct weston_shell *shell; |
| 187 | |
| 188 | /* There can be more than one, but not right now... */ |
| 189 | struct wl_input_device *input_device; |
| 190 | |
| 191 | struct wl_list output_list; |
| 192 | struct wl_list input_device_list; |
| 193 | struct wl_list surface_list; |
| 194 | struct wl_list binding_list; |
| 195 | struct wl_list animation_list; |
| 196 | struct { |
| 197 | struct weston_spring spring; |
| 198 | struct weston_animation animation; |
| 199 | } fade; |
| 200 | |
| 201 | uint32_t state; |
| 202 | struct wl_event_source *idle_source; |
| 203 | uint32_t idle_inhibit; |
| 204 | int option_idle_time; /* default timeout, s */ |
| 205 | int idle_time; /* effective timeout, s */ |
| 206 | |
| 207 | /* Repaint state. */ |
| 208 | struct timespec previous_swap; |
| 209 | struct wl_array vertices, indices; |
| 210 | |
| 211 | struct weston_surface *overlay; |
| 212 | struct weston_switcher *switcher; |
| 213 | uint32_t focus; |
| 214 | |
| 215 | PFNGLEGLIMAGETARGETRENDERBUFFERSTORAGEOESPROC |
| 216 | image_target_renderbuffer_storage; |
| 217 | PFNGLEGLIMAGETARGETTEXTURE2DOESPROC image_target_texture_2d; |
| 218 | PFNEGLCREATEIMAGEKHRPROC create_image; |
| 219 | PFNEGLDESTROYIMAGEKHRPROC destroy_image; |
| 220 | PFNEGLBINDWAYLANDDISPLAYWL bind_display; |
| 221 | PFNEGLUNBINDWAYLANDDISPLAYWL unbind_display; |
| 222 | int has_bind_display; |
| 223 | |
| 224 | void (*destroy)(struct weston_compositor *ec); |
| 225 | int (*authenticate)(struct weston_compositor *c, uint32_t id); |
| 226 | EGLImageKHR (*create_cursor_image)(struct weston_compositor *c, |
| 227 | int32_t *width, int32_t *height); |
| 228 | }; |
| 229 | |
| 230 | #define MODIFIER_CTRL (1 << 8) |
| 231 | #define MODIFIER_ALT (1 << 9) |
| 232 | #define MODIFIER_SUPER (1 << 10) |
| 233 | |
| 234 | enum weston_output_flags { |
| 235 | WL_OUTPUT_FLIPPED = 0x01 |
| 236 | }; |
| 237 | |
| 238 | struct weston_surface { |
| 239 | struct wl_surface surface; |
| 240 | struct weston_compositor *compositor; |
| 241 | GLuint texture, saved_texture; |
| 242 | pixman_region32_t damage; |
| 243 | pixman_region32_t opaque; |
| 244 | int32_t x, y, width, height; |
| 245 | int32_t pitch; |
| 246 | struct wl_list link; |
| 247 | struct wl_list buffer_link; |
| 248 | struct weston_transform *transform; |
| 249 | uint32_t alpha; |
| 250 | uint32_t visual; |
| 251 | |
| 252 | /* |
| 253 | * Which output to vsync this surface to. |
| 254 | * Used to determine, whether to send or queue frame events. |
| 255 | * Must be NULL, if 'link' is not in weston_compositor::surface_list. |
| 256 | */ |
| 257 | struct weston_output *output; |
| 258 | |
| 259 | struct weston_output *fullscreen_output; |
| 260 | struct wl_list frame_callback_list; |
| 261 | |
| 262 | EGLImageKHR image; |
| 263 | |
| 264 | struct wl_buffer *buffer; |
| 265 | struct wl_listener buffer_destroy_listener; |
| 266 | }; |
| 267 | |
| 268 | struct weston_data_source { |
| 269 | struct wl_resource resource; |
| 270 | struct wl_array mime_types; |
| 271 | int refcount; |
| 272 | void *data; |
| 273 | |
| 274 | struct wl_resource *(*create_offer)(struct weston_data_source *source, |
| 275 | struct wl_resource *target); |
| 276 | |
| 277 | void (*cancel)(struct weston_data_source *source); |
| 278 | }; |
| 279 | |
| 280 | void |
| 281 | weston_data_source_unref(struct weston_data_source *source); |
| 282 | |
| 283 | void |
| 284 | weston_input_device_set_selection(struct weston_input_device *device, |
| 285 | struct weston_data_source *source, |
| 286 | uint32_t time); |
| 287 | |
| 288 | void |
| 289 | weston_spring_init(struct weston_spring *spring, |
| 290 | double k, double current, double target); |
| 291 | void |
| 292 | weston_spring_update(struct weston_spring *spring, uint32_t msec); |
| 293 | int |
| 294 | weston_spring_done(struct weston_spring *spring); |
| 295 | |
| 296 | void |
| 297 | weston_surface_activate(struct weston_surface *surface, |
| 298 | struct weston_input_device *device, uint32_t time); |
| 299 | |
| 300 | void |
| 301 | notify_motion(struct wl_input_device *device, |
| 302 | uint32_t time, int x, int y); |
| 303 | void |
| 304 | notify_button(struct wl_input_device *device, |
| 305 | uint32_t time, int32_t button, int32_t state); |
| 306 | void |
| 307 | notify_key(struct wl_input_device *device, |
| 308 | uint32_t time, uint32_t key, uint32_t state); |
| 309 | |
| 310 | void |
| 311 | notify_pointer_focus(struct wl_input_device *device, |
| 312 | uint32_t time, |
| 313 | struct weston_output *output, |
| 314 | int32_t x, int32_t y); |
| 315 | |
| 316 | void |
| 317 | notify_keyboard_focus(struct wl_input_device *device, |
| 318 | uint32_t time, struct weston_output *output, |
| 319 | struct wl_array *keys); |
| 320 | |
| 321 | void |
| 322 | notify_touch(struct wl_input_device *device, uint32_t time, int touch_id, |
| 323 | int x, int y, int touch_type); |
| 324 | |
| 325 | void |
| 326 | weston_output_finish_frame(struct weston_output *output, int msecs); |
| 327 | void |
| 328 | weston_output_damage(struct weston_output *output); |
| 329 | void |
| 330 | weston_compositor_repick(struct weston_compositor *compositor); |
| 331 | void |
| 332 | weston_compositor_schedule_repaint(struct weston_compositor *compositor); |
| 333 | void |
| 334 | weston_compositor_fade(struct weston_compositor *compositor, float tint); |
| 335 | void |
| 336 | weston_compositor_damage_all(struct weston_compositor *compositor); |
| 337 | void |
| 338 | weston_compositor_unlock(struct weston_compositor *compositor); |
| 339 | void |
| 340 | weston_compositor_wake(struct weston_compositor *compositor); |
| 341 | void |
| 342 | weston_compositor_activity(struct weston_compositor *compositor); |
| 343 | |
| 344 | struct weston_binding; |
| 345 | typedef void (*weston_binding_handler_t)(struct wl_input_device *device, |
| 346 | uint32_t time, uint32_t key, |
| 347 | uint32_t button, |
| 348 | uint32_t state, void *data); |
| 349 | struct weston_binding * |
| 350 | weston_compositor_add_binding(struct weston_compositor *compositor, |
| 351 | uint32_t key, uint32_t button, uint32_t modifier, |
| 352 | weston_binding_handler_t binding, void *data); |
| 353 | void |
| 354 | weston_binding_destroy(struct weston_binding *binding); |
| 355 | |
| 356 | void |
| 357 | weston_compositor_run_binding(struct weston_compositor *compositor, |
| 358 | struct weston_input_device *device, |
| 359 | uint32_t time, |
| 360 | uint32_t key, uint32_t button, int32_t state); |
| 361 | |
| 362 | struct weston_surface * |
| 363 | weston_surface_create(struct weston_compositor *compositor, |
| 364 | int32_t x, int32_t y, int32_t width, int32_t height); |
| 365 | |
| 366 | void |
| 367 | weston_surface_configure(struct weston_surface *surface, |
| 368 | int x, int y, int width, int height); |
| 369 | |
| 370 | void |
| 371 | weston_surface_assign_output(struct weston_surface *surface); |
| 372 | |
| 373 | void |
| 374 | weston_surface_damage(struct weston_surface *surface); |
| 375 | |
| 376 | void |
| 377 | weston_surface_damage_below(struct weston_surface *surface); |
| 378 | |
| 379 | void |
| 380 | weston_surface_damage_rectangle(struct weston_surface *surface, |
| 381 | int32_t x, int32_t y, |
| 382 | int32_t width, int32_t height); |
| 383 | |
| 384 | struct weston_surface * |
| 385 | pick_surface(struct wl_input_device *device, int32_t *sx, int32_t *sy); |
| 386 | |
| 387 | uint32_t |
| 388 | weston_compositor_get_time(void); |
| 389 | |
| 390 | int |
| 391 | weston_compositor_init(struct weston_compositor *ec, struct wl_display *display); |
| 392 | void |
| 393 | weston_compositor_shutdown(struct weston_compositor *ec); |
| 394 | void |
| 395 | weston_output_move(struct weston_output *output, int x, int y); |
| 396 | void |
| 397 | weston_output_init(struct weston_output *output, struct weston_compositor *c, |
| 398 | int x, int y, int width, int height, uint32_t flags); |
| 399 | void |
| 400 | weston_output_destroy(struct weston_output *output); |
| 401 | |
| 402 | void |
| 403 | weston_input_device_init(struct weston_input_device *device, |
| 404 | struct weston_compositor *ec); |
| 405 | |
| 406 | void |
| 407 | weston_switcher_init(struct weston_compositor *compositor); |
| 408 | |
| 409 | enum { |
| 410 | TTY_ENTER_VT, |
| 411 | TTY_LEAVE_VT |
| 412 | }; |
| 413 | |
| 414 | typedef void (*tty_vt_func_t)(struct weston_compositor *compositor, int event); |
| 415 | |
| 416 | struct tty * |
| 417 | tty_create(struct weston_compositor *compositor, |
| 418 | tty_vt_func_t vt_func, int tty_nr); |
| 419 | |
| 420 | void |
| 421 | tty_destroy(struct tty *tty); |
| 422 | |
| 423 | void |
| 424 | screenshooter_create(struct weston_compositor *ec); |
| 425 | |
| 426 | uint32_t * |
| 427 | weston_load_image(const char *filename, |
| 428 | int32_t *width_arg, int32_t *height_arg, |
| 429 | uint32_t *stride_arg); |
| 430 | |
| 431 | struct weston_process; |
| 432 | typedef void (*weston_process_cleanup_func_t)(struct weston_process *process, |
| 433 | int status); |
| 434 | |
| 435 | struct weston_process { |
| 436 | pid_t pid; |
| 437 | weston_process_cleanup_func_t cleanup; |
| 438 | struct wl_list link; |
| 439 | }; |
| 440 | |
| 441 | struct wl_client * |
| 442 | weston_client_launch(struct weston_compositor *compositor, |
| 443 | struct weston_process *proc, |
| 444 | const char *path, |
| 445 | weston_process_cleanup_func_t cleanup); |
| 446 | |
| 447 | int |
| 448 | weston_data_device_manager_init(struct weston_compositor *compositor); |
| 449 | void |
| 450 | weston_data_device_set_keyboard_focus(struct weston_input_device *device); |
| 451 | |
| 452 | void |
| 453 | weston_watch_process(struct weston_process *process); |
| 454 | |
| 455 | int |
| 456 | weston_xserver_init(struct weston_compositor *compositor); |
| 457 | void |
| 458 | weston_xserver_destroy(struct weston_compositor *compositor); |
| 459 | void |
| 460 | weston_xserver_surface_activate(struct weston_surface *surface); |
| 461 | void |
| 462 | weston_xserver_set_selection(struct weston_input_device *device); |
| 463 | |
| 464 | struct weston_zoom; |
| 465 | typedef void (*weston_zoom_done_func_t)(struct weston_zoom *zoom, void *data); |
| 466 | |
| 467 | struct weston_zoom * |
| 468 | weston_zoom_run(struct weston_surface *surface, GLfloat start, GLfloat stop, |
| 469 | weston_zoom_done_func_t done, void *data); |
| 470 | |
| 471 | #endif |