Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 1 | /* |
Kristian Høgsberg | 96aa7da | 2011-09-15 15:43:14 -0400 | [diff] [blame] | 2 | * Copyright © 2010-2011 Intel Corporation |
| 3 | * Copyright © 2008-2011 Kristian Høgsberg |
Pekka Paalanen | d581a8f | 2012-01-27 16:25:16 +0200 | [diff] [blame] | 4 | * Copyright © 2012 Collabora, Ltd. |
Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 5 | * |
Kristian Høgsberg | 96aa7da | 2011-09-15 15:43:14 -0400 | [diff] [blame] | 6 | * Permission to use, copy, modify, distribute, and sell this software and |
| 7 | * its documentation for any purpose is hereby granted without fee, provided |
| 8 | * that the above copyright notice appear in all copies and that both that |
| 9 | * copyright notice and this permission notice appear in supporting |
| 10 | * documentation, and that the name of the copyright holders not be used in |
| 11 | * advertising or publicity pertaining to distribution of the software |
| 12 | * without specific, written prior permission. The copyright holders make |
| 13 | * no representations about the suitability of this software for any |
| 14 | * purpose. It is provided "as is" without express or implied warranty. |
Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 15 | * |
Kristian Høgsberg | 96aa7da | 2011-09-15 15:43:14 -0400 | [diff] [blame] | 16 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 17 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 18 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 20 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 21 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 22 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 23 | */ |
| 24 | |
Kristian Høgsberg | a941022 | 2011-01-14 17:22:35 -0500 | [diff] [blame] | 25 | #include "config.h" |
| 26 | |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 27 | #include <fcntl.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 28 | #include <stdio.h> |
| 29 | #include <string.h> |
| 30 | #include <stdlib.h> |
| 31 | #include <stdint.h> |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 32 | #include <limits.h> |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 33 | #include <stdarg.h> |
Benjamin Franzke | 6f5fc69 | 2011-06-21 19:34:19 +0200 | [diff] [blame] | 34 | #include <assert.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 35 | #include <sys/ioctl.h> |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 36 | #include <sys/mman.h> |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 37 | #include <sys/wait.h> |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 38 | #include <sys/socket.h> |
Martin Minarik | f12c287 | 2012-06-11 00:57:39 +0200 | [diff] [blame] | 39 | #include <sys/utsname.h> |
Martin Minarik | 37032f8 | 2012-06-18 20:15:18 +0200 | [diff] [blame] | 40 | #include <sys/stat.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 41 | #include <unistd.h> |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 42 | #include <math.h> |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 43 | #include <linux/input.h> |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 44 | #include <dlfcn.h> |
Kristian Høgsberg | 8544903 | 2011-05-02 12:11:07 -0400 | [diff] [blame] | 45 | #include <signal.h> |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 46 | #include <setjmp.h> |
Kristian Høgsberg | a411c8b | 2012-06-08 16:16:52 -0400 | [diff] [blame] | 47 | #include <sys/time.h> |
| 48 | #include <time.h> |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 49 | |
Marcin Slusarz | 554a0da | 2013-02-18 13:27:22 -0500 | [diff] [blame] | 50 | #ifdef HAVE_LIBUNWIND |
| 51 | #define UNW_LOCAL_ONLY |
| 52 | #include <libunwind.h> |
| 53 | #endif |
| 54 | |
Pekka Paalanen | 50719bc | 2011-11-22 14:18:50 +0200 | [diff] [blame] | 55 | #include <wayland-server.h> |
Kristian Høgsberg | 8286302 | 2010-06-04 21:52:02 -0400 | [diff] [blame] | 56 | #include "compositor.h" |
U. Artie Eoff | ec08f33 | 2013-05-13 15:55:47 -0700 | [diff] [blame] | 57 | #include "subsurface-server-protocol.h" |
Pekka Paalanen | 51aaf64 | 2012-05-30 15:53:41 +0300 | [diff] [blame] | 58 | #include "../shared/os-compatibility.h" |
Kristian Høgsberg | a411c8b | 2012-06-08 16:16:52 -0400 | [diff] [blame] | 59 | #include "git-version.h" |
Kristian Høgsberg | af4f2aa | 2013-02-15 20:53:20 -0500 | [diff] [blame] | 60 | #include "version.h" |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 61 | |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 62 | static struct wl_list child_process_list; |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 63 | static struct weston_compositor *segv_compositor; |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 64 | |
| 65 | static int |
| 66 | sigchld_handler(int signal_number, void *data) |
| 67 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 68 | struct weston_process *p; |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 69 | int status; |
| 70 | pid_t pid; |
| 71 | |
Bill Spitzak | 027b962 | 2012-03-17 15:22:03 -0700 | [diff] [blame] | 72 | pid = waitpid(-1, &status, WNOHANG); |
| 73 | if (!pid) |
| 74 | return 1; |
| 75 | |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 76 | wl_list_for_each(p, &child_process_list, link) { |
| 77 | if (p->pid == pid) |
| 78 | break; |
| 79 | } |
| 80 | |
| 81 | if (&p->link == &child_process_list) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 82 | weston_log("unknown child process exited\n"); |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 83 | return 1; |
| 84 | } |
| 85 | |
| 86 | wl_list_remove(&p->link); |
| 87 | p->cleanup(p, status); |
| 88 | |
| 89 | return 1; |
| 90 | } |
| 91 | |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 92 | static void |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 93 | weston_output_transform_scale_init(struct weston_output *output, |
| 94 | uint32_t transform, uint32_t scale); |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 95 | |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 96 | WL_EXPORT int |
Alexander Larsson | 355748e | 2013-05-28 16:23:38 +0200 | [diff] [blame] | 97 | weston_output_switch_mode(struct weston_output *output, struct weston_mode *mode, int32_t scale) |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 98 | { |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 99 | struct weston_seat *seat; |
| 100 | pixman_region32_t old_output_region; |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 101 | int ret; |
| 102 | |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 103 | if (!output->switch_mode) |
| 104 | return -1; |
| 105 | |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 106 | ret = output->switch_mode(output, mode); |
| 107 | if (ret < 0) |
| 108 | return ret; |
| 109 | |
Alexander Larsson | 355748e | 2013-05-28 16:23:38 +0200 | [diff] [blame] | 110 | output->scale = scale; |
| 111 | |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 112 | pixman_region32_init(&old_output_region); |
| 113 | pixman_region32_copy(&old_output_region, &output->region); |
| 114 | |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 115 | /* Update output region and transformation matrix */ |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 116 | weston_output_transform_scale_init(output, output->transform, output->scale); |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 117 | |
| 118 | pixman_region32_init(&output->previous_damage); |
| 119 | pixman_region32_init_rect(&output->region, output->x, output->y, |
| 120 | output->width, output->height); |
| 121 | |
| 122 | weston_output_update_matrix(output); |
| 123 | |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 124 | /* If a pointer falls outside the outputs new geometry, move it to its |
| 125 | * lower-right corner */ |
| 126 | wl_list_for_each(seat, &output->compositor->seat_list, link) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 127 | struct weston_pointer *pointer = seat->pointer; |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 128 | int32_t x, y; |
| 129 | |
| 130 | if (!pointer) |
| 131 | continue; |
| 132 | |
| 133 | x = wl_fixed_to_int(pointer->x); |
| 134 | y = wl_fixed_to_int(pointer->y); |
| 135 | |
| 136 | if (!pixman_region32_contains_point(&old_output_region, |
| 137 | x, y, NULL) || |
| 138 | pixman_region32_contains_point(&output->region, |
| 139 | x, y, NULL)) |
| 140 | continue; |
| 141 | |
| 142 | if (x >= output->x + output->width) |
| 143 | x = output->x + output->width - 1; |
| 144 | if (y >= output->y + output->height) |
| 145 | y = output->y + output->height - 1; |
| 146 | |
| 147 | pointer->x = wl_fixed_from_int(x); |
| 148 | pointer->y = wl_fixed_from_int(y); |
| 149 | } |
| 150 | |
| 151 | pixman_region32_fini(&old_output_region); |
| 152 | |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 153 | return ret; |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 154 | } |
| 155 | |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 156 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 157 | weston_watch_process(struct weston_process *process) |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 158 | { |
| 159 | wl_list_insert(&child_process_list, &process->link); |
| 160 | } |
| 161 | |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 162 | static void |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 163 | child_client_exec(int sockfd, const char *path) |
| 164 | { |
Kristian Høgsberg | d42b0c9 | 2011-12-08 10:19:40 -0500 | [diff] [blame] | 165 | int clientfd; |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 166 | char s[32]; |
Pekka Paalanen | c47ddfd | 2011-12-08 10:44:56 +0200 | [diff] [blame] | 167 | sigset_t allsigs; |
| 168 | |
| 169 | /* do not give our signal mask to the new process */ |
| 170 | sigfillset(&allsigs); |
| 171 | sigprocmask(SIG_UNBLOCK, &allsigs, NULL); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 172 | |
Kristian Høgsberg | eb76484 | 2012-01-31 22:17:25 -0500 | [diff] [blame] | 173 | /* Launch clients as the user. */ |
| 174 | seteuid(getuid()); |
| 175 | |
Kristian Høgsberg | d42b0c9 | 2011-12-08 10:19:40 -0500 | [diff] [blame] | 176 | /* SOCK_CLOEXEC closes both ends, so we dup the fd to get a |
| 177 | * non-CLOEXEC fd to pass through exec. */ |
| 178 | clientfd = dup(sockfd); |
| 179 | if (clientfd == -1) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 180 | weston_log("compositor: dup failed: %m\n"); |
Kristian Høgsberg | d42b0c9 | 2011-12-08 10:19:40 -0500 | [diff] [blame] | 181 | return; |
| 182 | } |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 183 | |
Kristian Høgsberg | d42b0c9 | 2011-12-08 10:19:40 -0500 | [diff] [blame] | 184 | snprintf(s, sizeof s, "%d", clientfd); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 185 | setenv("WAYLAND_SOCKET", s, 1); |
| 186 | |
| 187 | if (execl(path, path, NULL) < 0) |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 188 | weston_log("compositor: executing '%s' failed: %m\n", |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 189 | path); |
| 190 | } |
| 191 | |
| 192 | WL_EXPORT struct wl_client * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 193 | weston_client_launch(struct weston_compositor *compositor, |
| 194 | struct weston_process *proc, |
| 195 | const char *path, |
| 196 | weston_process_cleanup_func_t cleanup) |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 197 | { |
| 198 | int sv[2]; |
| 199 | pid_t pid; |
| 200 | struct wl_client *client; |
| 201 | |
Pekka Paalanen | df1fd36 | 2012-08-06 14:57:03 +0300 | [diff] [blame] | 202 | weston_log("launching '%s'\n", path); |
| 203 | |
Pekka Paalanen | 51aaf64 | 2012-05-30 15:53:41 +0300 | [diff] [blame] | 204 | if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, sv) < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 205 | weston_log("weston_client_launch: " |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 206 | "socketpair failed while launching '%s': %m\n", |
| 207 | path); |
| 208 | return NULL; |
| 209 | } |
| 210 | |
| 211 | pid = fork(); |
| 212 | if (pid == -1) { |
| 213 | close(sv[0]); |
| 214 | close(sv[1]); |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 215 | weston_log("weston_client_launch: " |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 216 | "fork failed while launching '%s': %m\n", path); |
| 217 | return NULL; |
| 218 | } |
| 219 | |
| 220 | if (pid == 0) { |
| 221 | child_client_exec(sv[1], path); |
U. Artie Eoff | 3b64d62 | 2013-06-03 16:22:31 -0700 | [diff] [blame] | 222 | _exit(-1); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | close(sv[1]); |
| 226 | |
| 227 | client = wl_client_create(compositor->wl_display, sv[0]); |
| 228 | if (!client) { |
| 229 | close(sv[0]); |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 230 | weston_log("weston_client_launch: " |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 231 | "wl_client_create failed while launching '%s'.\n", |
| 232 | path); |
| 233 | return NULL; |
| 234 | } |
| 235 | |
| 236 | proc->pid = pid; |
| 237 | proc->cleanup = cleanup; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 238 | weston_watch_process(proc); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 239 | |
| 240 | return client; |
| 241 | } |
| 242 | |
| 243 | static void |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 244 | surface_handle_pending_buffer_destroy(struct wl_listener *listener, void *data) |
| 245 | { |
| 246 | struct weston_surface *surface = |
| 247 | container_of(listener, struct weston_surface, |
| 248 | pending.buffer_destroy_listener); |
| 249 | |
| 250 | surface->pending.buffer = NULL; |
| 251 | } |
| 252 | |
Ander Conselvan de Oliveira | 90fbbd7 | 2012-02-28 17:59:33 +0200 | [diff] [blame] | 253 | static void |
| 254 | empty_region(pixman_region32_t *region) |
| 255 | { |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 256 | pixman_region32_fini(region); |
Ander Conselvan de Oliveira | 90fbbd7 | 2012-02-28 17:59:33 +0200 | [diff] [blame] | 257 | pixman_region32_init(region); |
| 258 | } |
| 259 | |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 260 | static void |
| 261 | region_init_infinite(pixman_region32_t *region) |
| 262 | { |
| 263 | pixman_region32_init_rect(region, INT32_MIN, INT32_MIN, |
| 264 | UINT32_MAX, UINT32_MAX); |
| 265 | } |
| 266 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 267 | static struct weston_subsurface * |
| 268 | weston_surface_to_subsurface(struct weston_surface *surface); |
| 269 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 270 | WL_EXPORT struct weston_surface * |
Kristian Høgsberg | 18c9300 | 2012-01-27 11:58:31 -0500 | [diff] [blame] | 271 | weston_surface_create(struct weston_compositor *compositor) |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 272 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 273 | struct weston_surface *surface; |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 274 | |
Pekka Paalanen | 56cdea9 | 2011-11-23 16:14:12 +0200 | [diff] [blame] | 275 | surface = calloc(1, sizeof *surface); |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 276 | if (surface == NULL) |
| 277 | return NULL; |
| 278 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 279 | wl_signal_init(&surface->destroy_signal); |
| 280 | |
| 281 | surface->resource = NULL; |
Kristian Høgsberg | 4889154 | 2012-02-23 17:38:33 -0500 | [diff] [blame] | 282 | |
Kristian Høgsberg | f6b1471 | 2011-01-06 15:32:14 -0500 | [diff] [blame] | 283 | wl_list_init(&surface->link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 284 | wl_list_init(&surface->layer_link); |
Kristian Høgsberg | c551bd2 | 2010-12-06 16:43:16 -0500 | [diff] [blame] | 285 | |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 286 | surface->compositor = compositor; |
Kristian Høgsberg | a416fa1 | 2012-05-21 14:06:52 -0400 | [diff] [blame] | 287 | surface->alpha = 1.0; |
Kristian Høgsberg | 27803c6 | 2010-06-06 22:23:21 -0400 | [diff] [blame] | 288 | |
John Kåre Alsaker | 878f449 | 2012-11-13 19:10:23 +0100 | [diff] [blame] | 289 | if (compositor->renderer->create_surface(surface) < 0) { |
| 290 | free(surface); |
| 291 | return NULL; |
| 292 | } |
| 293 | |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 294 | surface->buffer_transform = WL_OUTPUT_TRANSFORM_NORMAL; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 295 | surface->buffer_scale = 1; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 296 | surface->pending.buffer_transform = surface->buffer_transform; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 297 | surface->pending.buffer_scale = surface->buffer_scale; |
Kristian Høgsberg | 6f7179c | 2011-08-29 16:09:32 -0400 | [diff] [blame] | 298 | surface->output = NULL; |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 299 | surface->plane = &compositor->primary_plane; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 300 | surface->pending.newly_attached = 0; |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 301 | |
Kristian Høgsberg | 20300ba | 2011-06-23 20:29:12 -0400 | [diff] [blame] | 302 | pixman_region32_init(&surface->damage); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 303 | pixman_region32_init(&surface->opaque); |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 304 | pixman_region32_init(&surface->clip); |
Pekka Paalanen | 8ec4ab6 | 2012-10-10 12:49:32 +0300 | [diff] [blame] | 305 | region_init_infinite(&surface->input); |
Pekka Paalanen | 730d87e | 2012-02-09 16:39:38 +0200 | [diff] [blame] | 306 | pixman_region32_init(&surface->transform.opaque); |
Kristian Høgsberg | 496433b | 2011-11-15 13:50:21 -0500 | [diff] [blame] | 307 | wl_list_init(&surface->frame_callback_list); |
Kristian Høgsberg | 20300ba | 2011-06-23 20:29:12 -0400 | [diff] [blame] | 308 | |
Pekka Paalanen | bc0b7e7 | 2012-01-24 09:53:37 +0200 | [diff] [blame] | 309 | wl_list_init(&surface->geometry.transformation_list); |
Pekka Paalanen | cd40362 | 2012-01-25 13:37:39 +0200 | [diff] [blame] | 310 | wl_list_insert(&surface->geometry.transformation_list, |
| 311 | &surface->transform.position.link); |
| 312 | weston_matrix_init(&surface->transform.position.matrix); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 313 | wl_list_init(&surface->geometry.child_list); |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 314 | pixman_region32_init(&surface->transform.boundingbox); |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 315 | surface->transform.dirty = 1; |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 316 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 317 | surface->pending.buffer_destroy_listener.notify = |
| 318 | surface_handle_pending_buffer_destroy; |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 319 | pixman_region32_init(&surface->pending.damage); |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 320 | pixman_region32_init(&surface->pending.opaque); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 321 | region_init_infinite(&surface->pending.input); |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 322 | wl_list_init(&surface->pending.frame_callback_list); |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 323 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 324 | wl_list_init(&surface->subsurface_list); |
| 325 | wl_list_init(&surface->subsurface_list_pending); |
| 326 | |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 327 | return surface; |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 328 | } |
| 329 | |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 330 | WL_EXPORT void |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 331 | weston_surface_set_color(struct weston_surface *surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 332 | float red, float green, float blue, float alpha) |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 333 | { |
John Kåre Alsaker | 878f449 | 2012-11-13 19:10:23 +0100 | [diff] [blame] | 334 | surface->compositor->renderer->surface_set_color(surface, red, green, blue, alpha); |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 335 | } |
| 336 | |
Kristian Høgsberg | e4c1a5f | 2012-06-18 13:17:32 -0400 | [diff] [blame] | 337 | WL_EXPORT void |
| 338 | weston_surface_to_global_float(struct weston_surface *surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 339 | float sx, float sy, float *x, float *y) |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 340 | { |
| 341 | if (surface->transform.enabled) { |
| 342 | struct weston_vector v = { { sx, sy, 0.0f, 1.0f } }; |
| 343 | |
| 344 | weston_matrix_transform(&surface->transform.matrix, &v); |
| 345 | |
| 346 | if (fabsf(v.f[3]) < 1e-6) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 347 | weston_log("warning: numerical instability in " |
Scott Moreau | 088c62e | 2013-02-11 04:45:38 -0700 | [diff] [blame] | 348 | "%s(), divisor = %g\n", __func__, |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 349 | v.f[3]); |
| 350 | *x = 0; |
| 351 | *y = 0; |
| 352 | return; |
| 353 | } |
| 354 | |
| 355 | *x = v.f[0] / v.f[3]; |
| 356 | *y = v.f[1] / v.f[3]; |
| 357 | } else { |
| 358 | *x = sx + surface->geometry.x; |
| 359 | *y = sy + surface->geometry.y; |
| 360 | } |
| 361 | } |
| 362 | |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 363 | WL_EXPORT void |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 364 | weston_transformed_coord(int width, int height, |
| 365 | enum wl_output_transform transform, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 366 | int32_t scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 367 | float sx, float sy, float *bx, float *by) |
| 368 | { |
| 369 | switch (transform) { |
| 370 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 371 | default: |
| 372 | *bx = sx; |
| 373 | *by = sy; |
| 374 | break; |
| 375 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 376 | *bx = width - sx; |
| 377 | *by = sy; |
| 378 | break; |
| 379 | case WL_OUTPUT_TRANSFORM_90: |
| 380 | *bx = height - sy; |
| 381 | *by = sx; |
| 382 | break; |
| 383 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 384 | *bx = height - sy; |
| 385 | *by = width - sx; |
| 386 | break; |
| 387 | case WL_OUTPUT_TRANSFORM_180: |
| 388 | *bx = width - sx; |
| 389 | *by = height - sy; |
| 390 | break; |
| 391 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 392 | *bx = sx; |
| 393 | *by = height - sy; |
| 394 | break; |
| 395 | case WL_OUTPUT_TRANSFORM_270: |
| 396 | *bx = sy; |
| 397 | *by = width - sx; |
| 398 | break; |
| 399 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 400 | *bx = sy; |
| 401 | *by = sx; |
| 402 | break; |
| 403 | } |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 404 | |
| 405 | *bx *= scale; |
| 406 | *by *= scale; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | WL_EXPORT pixman_box32_t |
| 410 | weston_transformed_rect(int width, int height, |
| 411 | enum wl_output_transform transform, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 412 | int32_t scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 413 | pixman_box32_t rect) |
| 414 | { |
| 415 | float x1, x2, y1, y2; |
| 416 | |
| 417 | pixman_box32_t ret; |
| 418 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 419 | weston_transformed_coord(width, height, transform, scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 420 | rect.x1, rect.y1, &x1, &y1); |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 421 | weston_transformed_coord(width, height, transform, scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 422 | rect.x2, rect.y2, &x2, &y2); |
| 423 | |
| 424 | if (x1 <= x2) { |
| 425 | ret.x1 = x1; |
| 426 | ret.x2 = x2; |
| 427 | } else { |
| 428 | ret.x1 = x2; |
| 429 | ret.x2 = x1; |
| 430 | } |
| 431 | |
| 432 | if (y1 <= y2) { |
| 433 | ret.y1 = y1; |
| 434 | ret.y2 = y2; |
| 435 | } else { |
| 436 | ret.y1 = y2; |
| 437 | ret.y2 = y1; |
| 438 | } |
| 439 | |
| 440 | return ret; |
| 441 | } |
| 442 | |
| 443 | WL_EXPORT void |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 444 | weston_surface_to_buffer_float(struct weston_surface *surface, |
| 445 | float sx, float sy, float *bx, float *by) |
| 446 | { |
Ander Conselvan de Oliveira | 409eebf | 2012-12-05 15:14:04 +0200 | [diff] [blame] | 447 | weston_transformed_coord(surface->geometry.width, |
| 448 | surface->geometry.height, |
| 449 | surface->buffer_transform, |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 450 | surface->buffer_scale, |
Ander Conselvan de Oliveira | 409eebf | 2012-12-05 15:14:04 +0200 | [diff] [blame] | 451 | sx, sy, bx, by); |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 452 | } |
| 453 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 454 | WL_EXPORT void |
| 455 | weston_surface_to_buffer(struct weston_surface *surface, |
| 456 | int sx, int sy, int *bx, int *by) |
| 457 | { |
| 458 | float bxf, byf; |
| 459 | |
| 460 | weston_transformed_coord(surface->geometry.width, |
| 461 | surface->geometry.height, |
| 462 | surface->buffer_transform, |
| 463 | surface->buffer_scale, |
| 464 | sx, sy, &bxf, &byf); |
| 465 | *bx = floorf(bxf); |
| 466 | *by = floorf(byf); |
| 467 | } |
| 468 | |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 469 | WL_EXPORT pixman_box32_t |
| 470 | weston_surface_to_buffer_rect(struct weston_surface *surface, |
| 471 | pixman_box32_t rect) |
| 472 | { |
Ander Conselvan de Oliveira | 409eebf | 2012-12-05 15:14:04 +0200 | [diff] [blame] | 473 | return weston_transformed_rect(surface->geometry.width, |
| 474 | surface->geometry.height, |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 475 | surface->buffer_transform, |
| 476 | surface->buffer_scale, |
| 477 | rect); |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | WL_EXPORT void |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 481 | weston_surface_move_to_plane(struct weston_surface *surface, |
| 482 | struct weston_plane *plane) |
| 483 | { |
| 484 | if (surface->plane == plane) |
| 485 | return; |
| 486 | |
| 487 | weston_surface_damage_below(surface); |
| 488 | surface->plane = plane; |
| 489 | weston_surface_damage(surface); |
| 490 | } |
| 491 | |
| 492 | WL_EXPORT void |
Kristian Høgsberg | 323ee04 | 2012-02-17 12:45:43 -0500 | [diff] [blame] | 493 | weston_surface_damage_below(struct weston_surface *surface) |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 494 | { |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 495 | pixman_region32_t damage; |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 496 | |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 497 | pixman_region32_init(&damage); |
| 498 | pixman_region32_subtract(&damage, &surface->transform.boundingbox, |
| 499 | &surface->clip); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 500 | pixman_region32_union(&surface->plane->damage, |
| 501 | &surface->plane->damage, &damage); |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 502 | pixman_region32_fini(&damage); |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 503 | } |
| 504 | |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 505 | static void |
| 506 | weston_surface_update_output_mask(struct weston_surface *es, uint32_t mask) |
| 507 | { |
| 508 | uint32_t different = es->output_mask ^ mask; |
| 509 | uint32_t entered = mask & different; |
| 510 | uint32_t left = es->output_mask & different; |
| 511 | struct weston_output *output; |
| 512 | struct wl_resource *resource = NULL; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 513 | struct wl_client *client; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 514 | |
| 515 | es->output_mask = mask; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 516 | if (es->resource == NULL) |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 517 | return; |
| 518 | if (different == 0) |
| 519 | return; |
| 520 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 521 | client = wl_resource_get_client(es->resource); |
| 522 | |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 523 | wl_list_for_each(output, &es->compositor->output_list, link) { |
| 524 | if (1 << output->id & different) |
| 525 | resource = |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 526 | wl_resource_find_for_client(&output->resource_list, |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 527 | client); |
| 528 | if (resource == NULL) |
| 529 | continue; |
| 530 | if (1 << output->id & entered) |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 531 | wl_surface_send_enter(es->resource, resource); |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 532 | if (1 << output->id & left) |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 533 | wl_surface_send_leave(es->resource, resource); |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 534 | } |
| 535 | } |
| 536 | |
| 537 | static void |
| 538 | weston_surface_assign_output(struct weston_surface *es) |
| 539 | { |
| 540 | struct weston_compositor *ec = es->compositor; |
| 541 | struct weston_output *output, *new_output; |
| 542 | pixman_region32_t region; |
| 543 | uint32_t max, area, mask; |
| 544 | pixman_box32_t *e; |
| 545 | |
| 546 | new_output = NULL; |
| 547 | max = 0; |
| 548 | mask = 0; |
| 549 | pixman_region32_init(®ion); |
| 550 | wl_list_for_each(output, &ec->output_list, link) { |
| 551 | pixman_region32_intersect(®ion, &es->transform.boundingbox, |
| 552 | &output->region); |
| 553 | |
| 554 | e = pixman_region32_extents(®ion); |
| 555 | area = (e->x2 - e->x1) * (e->y2 - e->y1); |
| 556 | |
| 557 | if (area > 0) |
| 558 | mask |= 1 << output->id; |
| 559 | |
| 560 | if (area >= max) { |
| 561 | new_output = output; |
| 562 | max = area; |
| 563 | } |
| 564 | } |
| 565 | pixman_region32_fini(®ion); |
| 566 | |
| 567 | es->output = new_output; |
| 568 | weston_surface_update_output_mask(es, mask); |
| 569 | } |
| 570 | |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 571 | static void |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 572 | surface_compute_bbox(struct weston_surface *surface, int32_t sx, int32_t sy, |
| 573 | int32_t width, int32_t height, |
| 574 | pixman_region32_t *bbox) |
| 575 | { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 576 | float min_x = HUGE_VALF, min_y = HUGE_VALF; |
| 577 | float max_x = -HUGE_VALF, max_y = -HUGE_VALF; |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 578 | int32_t s[4][2] = { |
| 579 | { sx, sy }, |
| 580 | { sx, sy + height }, |
| 581 | { sx + width, sy }, |
| 582 | { sx + width, sy + height } |
| 583 | }; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 584 | float int_x, int_y; |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 585 | int i; |
| 586 | |
Pekka Paalanen | 7c7d464 | 2012-09-04 13:55:44 +0300 | [diff] [blame] | 587 | if (width == 0 || height == 0) { |
| 588 | /* avoid rounding empty bbox to 1x1 */ |
| 589 | pixman_region32_init(bbox); |
| 590 | return; |
| 591 | } |
| 592 | |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 593 | for (i = 0; i < 4; ++i) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 594 | float x, y; |
Kristian Høgsberg | e4c1a5f | 2012-06-18 13:17:32 -0400 | [diff] [blame] | 595 | weston_surface_to_global_float(surface, |
| 596 | s[i][0], s[i][1], &x, &y); |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 597 | if (x < min_x) |
| 598 | min_x = x; |
| 599 | if (x > max_x) |
| 600 | max_x = x; |
| 601 | if (y < min_y) |
| 602 | min_y = y; |
| 603 | if (y > max_y) |
| 604 | max_y = y; |
| 605 | } |
| 606 | |
Pekka Paalanen | 219b982 | 2012-02-08 15:38:37 +0200 | [diff] [blame] | 607 | int_x = floorf(min_x); |
| 608 | int_y = floorf(min_y); |
| 609 | pixman_region32_init_rect(bbox, int_x, int_y, |
| 610 | ceilf(max_x) - int_x, ceilf(max_y) - int_y); |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 611 | } |
| 612 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 613 | static void |
| 614 | weston_surface_update_transform_disable(struct weston_surface *surface) |
| 615 | { |
| 616 | surface->transform.enabled = 0; |
| 617 | |
Pekka Paalanen | cc2f868 | 2012-02-13 10:34:04 +0200 | [diff] [blame] | 618 | /* round off fractions when not transformed */ |
| 619 | surface->geometry.x = roundf(surface->geometry.x); |
| 620 | surface->geometry.y = roundf(surface->geometry.y); |
| 621 | |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 622 | /* Otherwise identity matrix, but with x and y translation. */ |
| 623 | surface->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE; |
| 624 | surface->transform.position.matrix.d[12] = surface->geometry.x; |
| 625 | surface->transform.position.matrix.d[13] = surface->geometry.y; |
| 626 | |
| 627 | surface->transform.matrix = surface->transform.position.matrix; |
| 628 | |
Kristian Høgsberg | 9bcaaeb | 2013-02-28 14:56:43 -0500 | [diff] [blame] | 629 | surface->transform.inverse = surface->transform.position.matrix; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 630 | surface->transform.inverse.d[12] = -surface->geometry.x; |
| 631 | surface->transform.inverse.d[13] = -surface->geometry.y; |
| 632 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 633 | pixman_region32_init_rect(&surface->transform.boundingbox, |
| 634 | surface->geometry.x, |
| 635 | surface->geometry.y, |
| 636 | surface->geometry.width, |
| 637 | surface->geometry.height); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 638 | |
Kristian Høgsberg | a416fa1 | 2012-05-21 14:06:52 -0400 | [diff] [blame] | 639 | if (surface->alpha == 1.0) { |
Kristian Høgsberg | 3b4af20 | 2012-02-28 09:19:39 -0500 | [diff] [blame] | 640 | pixman_region32_copy(&surface->transform.opaque, |
| 641 | &surface->opaque); |
| 642 | pixman_region32_translate(&surface->transform.opaque, |
| 643 | surface->geometry.x, |
| 644 | surface->geometry.y); |
| 645 | } |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | static int |
| 649 | weston_surface_update_transform_enable(struct weston_surface *surface) |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 650 | { |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 651 | struct weston_surface *parent = surface->geometry.parent; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 652 | struct weston_matrix *matrix = &surface->transform.matrix; |
| 653 | struct weston_matrix *inverse = &surface->transform.inverse; |
| 654 | struct weston_transform *tform; |
| 655 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 656 | surface->transform.enabled = 1; |
| 657 | |
| 658 | /* Otherwise identity matrix, but with x and y translation. */ |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 659 | surface->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 660 | surface->transform.position.matrix.d[12] = surface->geometry.x; |
| 661 | surface->transform.position.matrix.d[13] = surface->geometry.y; |
| 662 | |
| 663 | weston_matrix_init(matrix); |
| 664 | wl_list_for_each(tform, &surface->geometry.transformation_list, link) |
| 665 | weston_matrix_multiply(matrix, &tform->matrix); |
| 666 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 667 | if (parent) |
| 668 | weston_matrix_multiply(matrix, &parent->transform.matrix); |
| 669 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 670 | if (weston_matrix_invert(inverse, matrix) < 0) { |
| 671 | /* Oops, bad total transformation, not invertible */ |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 672 | weston_log("error: weston_surface %p" |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 673 | " transformation not invertible.\n", surface); |
| 674 | return -1; |
| 675 | } |
| 676 | |
| 677 | surface_compute_bbox(surface, 0, 0, surface->geometry.width, |
| 678 | surface->geometry.height, |
| 679 | &surface->transform.boundingbox); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 680 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 681 | return 0; |
| 682 | } |
| 683 | |
| 684 | WL_EXPORT void |
| 685 | weston_surface_update_transform(struct weston_surface *surface) |
| 686 | { |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 687 | struct weston_surface *parent = surface->geometry.parent; |
| 688 | |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 689 | if (!surface->transform.dirty) |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 690 | return; |
| 691 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 692 | if (parent) |
| 693 | weston_surface_update_transform(parent); |
| 694 | |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 695 | surface->transform.dirty = 0; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 696 | |
Kristian Høgsberg | 323ee04 | 2012-02-17 12:45:43 -0500 | [diff] [blame] | 697 | weston_surface_damage_below(surface); |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 698 | |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 699 | pixman_region32_fini(&surface->transform.boundingbox); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 700 | pixman_region32_fini(&surface->transform.opaque); |
| 701 | pixman_region32_init(&surface->transform.opaque); |
| 702 | |
Pekka Paalanen | cd40362 | 2012-01-25 13:37:39 +0200 | [diff] [blame] | 703 | /* transform.position is always in transformation_list */ |
| 704 | if (surface->geometry.transformation_list.next == |
| 705 | &surface->transform.position.link && |
| 706 | surface->geometry.transformation_list.prev == |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 707 | &surface->transform.position.link && |
| 708 | !parent) { |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 709 | weston_surface_update_transform_disable(surface); |
| 710 | } else { |
| 711 | if (weston_surface_update_transform_enable(surface) < 0) |
| 712 | weston_surface_update_transform_disable(surface); |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 713 | } |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 714 | |
Kristian Høgsberg | f1ea63f | 2012-07-18 12:02:51 -0400 | [diff] [blame] | 715 | weston_surface_damage_below(surface); |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 716 | |
Ander Conselvan de Oliveira | 231ba17 | 2012-09-14 16:12:04 +0300 | [diff] [blame] | 717 | weston_surface_assign_output(surface); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 718 | |
| 719 | wl_signal_emit(&surface->compositor->transform_signal, surface); |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 720 | } |
| 721 | |
Pekka Paalanen | ddae03c | 2012-02-06 14:54:20 +0200 | [diff] [blame] | 722 | WL_EXPORT void |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 723 | weston_surface_geometry_dirty(struct weston_surface *surface) |
| 724 | { |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 725 | struct weston_surface *child; |
| 726 | |
| 727 | /* |
| 728 | * The invariant: if surface->geometry.dirty, then all surfaces |
| 729 | * in surface->geometry.child_list have geometry.dirty too. |
| 730 | * Corollary: if not parent->geometry.dirty, then all ancestors |
| 731 | * are not dirty. |
| 732 | */ |
| 733 | |
| 734 | if (surface->transform.dirty) |
| 735 | return; |
| 736 | |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 737 | surface->transform.dirty = 1; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 738 | |
| 739 | wl_list_for_each(child, &surface->geometry.child_list, |
| 740 | geometry.parent_link) |
| 741 | weston_surface_geometry_dirty(child); |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | WL_EXPORT void |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 745 | weston_surface_to_global_fixed(struct weston_surface *surface, |
| 746 | wl_fixed_t sx, wl_fixed_t sy, |
| 747 | wl_fixed_t *x, wl_fixed_t *y) |
| 748 | { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 749 | float xf, yf; |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 750 | |
| 751 | weston_surface_to_global_float(surface, |
| 752 | wl_fixed_to_double(sx), |
| 753 | wl_fixed_to_double(sy), |
| 754 | &xf, &yf); |
| 755 | *x = wl_fixed_from_double(xf); |
| 756 | *y = wl_fixed_from_double(yf); |
| 757 | } |
| 758 | |
Kristian Høgsberg | ecf6ede | 2012-09-05 21:59:35 -0400 | [diff] [blame] | 759 | WL_EXPORT void |
| 760 | weston_surface_from_global_float(struct weston_surface *surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 761 | float x, float y, float *sx, float *sy) |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 762 | { |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 763 | if (surface->transform.enabled) { |
| 764 | struct weston_vector v = { { x, y, 0.0f, 1.0f } }; |
| 765 | |
| 766 | weston_matrix_transform(&surface->transform.inverse, &v); |
| 767 | |
| 768 | if (fabsf(v.f[3]) < 1e-6) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 769 | weston_log("warning: numerical instability in " |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 770 | "weston_surface_from_global(), divisor = %g\n", |
| 771 | v.f[3]); |
| 772 | *sx = 0; |
| 773 | *sy = 0; |
| 774 | return; |
| 775 | } |
| 776 | |
Pekka Paalanen | cd40362 | 2012-01-25 13:37:39 +0200 | [diff] [blame] | 777 | *sx = v.f[0] / v.f[3]; |
| 778 | *sy = v.f[1] / v.f[3]; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 779 | } else { |
Pekka Paalanen | ba3cf95 | 2012-01-25 16:22:05 +0200 | [diff] [blame] | 780 | *sx = x - surface->geometry.x; |
| 781 | *sy = y - surface->geometry.y; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 782 | } |
| 783 | } |
| 784 | |
| 785 | WL_EXPORT void |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 786 | weston_surface_from_global_fixed(struct weston_surface *surface, |
| 787 | wl_fixed_t x, wl_fixed_t y, |
| 788 | wl_fixed_t *sx, wl_fixed_t *sy) |
| 789 | { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 790 | float sxf, syf; |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 791 | |
Kristian Høgsberg | ecf6ede | 2012-09-05 21:59:35 -0400 | [diff] [blame] | 792 | weston_surface_from_global_float(surface, |
| 793 | wl_fixed_to_double(x), |
| 794 | wl_fixed_to_double(y), |
| 795 | &sxf, &syf); |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 796 | *sx = wl_fixed_from_double(sxf); |
| 797 | *sy = wl_fixed_from_double(syf); |
| 798 | } |
| 799 | |
| 800 | WL_EXPORT void |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 801 | weston_surface_from_global(struct weston_surface *surface, |
| 802 | int32_t x, int32_t y, int32_t *sx, int32_t *sy) |
| 803 | { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 804 | float sxf, syf; |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 805 | |
Kristian Høgsberg | ecf6ede | 2012-09-05 21:59:35 -0400 | [diff] [blame] | 806 | weston_surface_from_global_float(surface, x, y, &sxf, &syf); |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 807 | *sx = floorf(sxf); |
| 808 | *sy = floorf(syf); |
| 809 | } |
| 810 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 811 | WL_EXPORT void |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 812 | weston_surface_schedule_repaint(struct weston_surface *surface) |
| 813 | { |
| 814 | struct weston_output *output; |
| 815 | |
| 816 | wl_list_for_each(output, &surface->compositor->output_list, link) |
| 817 | if (surface->output_mask & (1 << output->id)) |
| 818 | weston_output_schedule_repaint(output); |
| 819 | } |
| 820 | |
| 821 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 822 | weston_surface_damage(struct weston_surface *surface) |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 823 | { |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 824 | pixman_region32_union_rect(&surface->damage, &surface->damage, |
| 825 | 0, 0, surface->geometry.width, |
| 826 | surface->geometry.height); |
Pekka Paalanen | 2267d45 | 2012-01-26 13:12:45 +0200 | [diff] [blame] | 827 | |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 828 | weston_surface_schedule_repaint(surface); |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 829 | } |
| 830 | |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 831 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 832 | weston_surface_configure(struct weston_surface *surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 833 | float x, float y, int width, int height) |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 834 | { |
Pekka Paalanen | ba3cf95 | 2012-01-25 16:22:05 +0200 | [diff] [blame] | 835 | surface->geometry.x = x; |
| 836 | surface->geometry.y = y; |
Pekka Paalanen | 60921e5 | 2012-01-25 15:55:43 +0200 | [diff] [blame] | 837 | surface->geometry.width = width; |
| 838 | surface->geometry.height = height; |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 839 | weston_surface_geometry_dirty(surface); |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 840 | } |
| 841 | |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 842 | WL_EXPORT void |
| 843 | weston_surface_set_position(struct weston_surface *surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 844 | float x, float y) |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 845 | { |
| 846 | surface->geometry.x = x; |
| 847 | surface->geometry.y = y; |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 848 | weston_surface_geometry_dirty(surface); |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 849 | } |
| 850 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 851 | static void |
| 852 | transform_parent_handle_parent_destroy(struct wl_listener *listener, |
| 853 | void *data) |
| 854 | { |
| 855 | struct weston_surface *surface = |
| 856 | container_of(listener, struct weston_surface, |
| 857 | geometry.parent_destroy_listener); |
| 858 | |
| 859 | weston_surface_set_transform_parent(surface, NULL); |
| 860 | } |
| 861 | |
| 862 | WL_EXPORT void |
| 863 | weston_surface_set_transform_parent(struct weston_surface *surface, |
| 864 | struct weston_surface *parent) |
| 865 | { |
| 866 | if (surface->geometry.parent) { |
| 867 | wl_list_remove(&surface->geometry.parent_destroy_listener.link); |
| 868 | wl_list_remove(&surface->geometry.parent_link); |
| 869 | } |
| 870 | |
| 871 | surface->geometry.parent = parent; |
| 872 | |
| 873 | surface->geometry.parent_destroy_listener.notify = |
| 874 | transform_parent_handle_parent_destroy; |
| 875 | if (parent) { |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 876 | wl_signal_add(&parent->destroy_signal, |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 877 | &surface->geometry.parent_destroy_listener); |
| 878 | wl_list_insert(&parent->geometry.child_list, |
| 879 | &surface->geometry.parent_link); |
| 880 | } |
| 881 | |
| 882 | weston_surface_geometry_dirty(surface); |
| 883 | } |
| 884 | |
Ander Conselvan de Oliveira | b8ab14f | 2012-03-27 17:36:36 +0300 | [diff] [blame] | 885 | WL_EXPORT int |
| 886 | weston_surface_is_mapped(struct weston_surface *surface) |
| 887 | { |
| 888 | if (surface->output) |
| 889 | return 1; |
| 890 | else |
| 891 | return 0; |
| 892 | } |
| 893 | |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 894 | WL_EXPORT int32_t |
| 895 | weston_surface_buffer_width(struct weston_surface *surface) |
| 896 | { |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 897 | int32_t width; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 898 | switch (surface->buffer_transform) { |
| 899 | case WL_OUTPUT_TRANSFORM_90: |
| 900 | case WL_OUTPUT_TRANSFORM_270: |
| 901 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 902 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 903 | width = surface->buffer_ref.buffer->height; |
| 904 | break; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 905 | default: |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 906 | width = surface->buffer_ref.buffer->width; |
| 907 | break; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 908 | } |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 909 | return width / surface->buffer_scale; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 910 | } |
| 911 | |
| 912 | WL_EXPORT int32_t |
| 913 | weston_surface_buffer_height(struct weston_surface *surface) |
| 914 | { |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 915 | int32_t height; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 916 | switch (surface->buffer_transform) { |
| 917 | case WL_OUTPUT_TRANSFORM_90: |
| 918 | case WL_OUTPUT_TRANSFORM_270: |
| 919 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 920 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 921 | height = surface->buffer_ref.buffer->width; |
| 922 | break; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 923 | default: |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 924 | height = surface->buffer_ref.buffer->height; |
| 925 | break; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 926 | } |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 927 | return height / surface->buffer_scale; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 928 | } |
| 929 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 930 | WL_EXPORT uint32_t |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 931 | weston_compositor_get_time(void) |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 932 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 933 | struct timeval tv; |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 934 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 935 | gettimeofday(&tv, NULL); |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 936 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 937 | return tv.tv_sec * 1000 + tv.tv_usec / 1000; |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 938 | } |
| 939 | |
Kristian Høgsberg | 6848c25 | 2013-05-08 22:02:59 -0400 | [diff] [blame] | 940 | WL_EXPORT struct weston_surface * |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 941 | weston_compositor_pick_surface(struct weston_compositor *compositor, |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 942 | wl_fixed_t x, wl_fixed_t y, |
| 943 | wl_fixed_t *sx, wl_fixed_t *sy) |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 944 | { |
| 945 | struct weston_surface *surface; |
| 946 | |
| 947 | wl_list_for_each(surface, &compositor->surface_list, link) { |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 948 | weston_surface_from_global_fixed(surface, x, y, sx, sy); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 949 | if (pixman_region32_contains_point(&surface->input, |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 950 | wl_fixed_to_int(*sx), |
| 951 | wl_fixed_to_int(*sy), |
| 952 | NULL)) |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 953 | return surface; |
| 954 | } |
| 955 | |
| 956 | return NULL; |
| 957 | } |
| 958 | |
| 959 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 960 | weston_compositor_repick(struct weston_compositor *compositor) |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 961 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 962 | struct weston_seat *seat; |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 963 | |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 964 | if (!compositor->focus) |
| 965 | return; |
| 966 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 967 | wl_list_for_each(seat, &compositor->seat_list, link) |
Kristian Høgsberg | a71e8b2 | 2013-05-06 21:51:21 -0400 | [diff] [blame] | 968 | weston_seat_repick(seat); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 969 | } |
| 970 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 971 | WL_EXPORT void |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 972 | weston_surface_unmap(struct weston_surface *surface) |
| 973 | { |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 974 | struct weston_seat *seat; |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 975 | |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 976 | weston_surface_damage_below(surface); |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 977 | surface->output = NULL; |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 978 | wl_list_remove(&surface->layer_link); |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 979 | |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 980 | wl_list_for_each(seat, &surface->compositor->seat_list, link) { |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 981 | if (seat->keyboard && seat->keyboard->focus == surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 982 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Kristian Høgsberg | fe7aa90 | 2013-05-08 09:54:37 -0400 | [diff] [blame] | 983 | if (seat->pointer && seat->pointer->focus == surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 984 | weston_pointer_set_focus(seat->pointer, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 985 | NULL, |
| 986 | wl_fixed_from_int(0), |
| 987 | wl_fixed_from_int(0)); |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 988 | } |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 989 | |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 990 | weston_surface_schedule_repaint(surface); |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 991 | } |
| 992 | |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 993 | struct weston_frame_callback { |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 994 | struct wl_resource *resource; |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 995 | struct wl_list link; |
| 996 | }; |
| 997 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 998 | |
| 999 | WL_EXPORT void |
| 1000 | weston_surface_destroy(struct weston_surface *surface) |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 1001 | { |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1002 | /* Not a valid way to destroy a client surface */ |
| 1003 | assert(surface->resource == NULL); |
| 1004 | |
| 1005 | wl_signal_emit(&surface->destroy_signal, &surface->resource); |
| 1006 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1007 | struct weston_compositor *compositor = surface->compositor; |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 1008 | struct weston_frame_callback *cb, *next; |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 1009 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1010 | assert(wl_list_empty(&surface->geometry.child_list)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1011 | assert(wl_list_empty(&surface->subsurface_list_pending)); |
| 1012 | assert(wl_list_empty(&surface->subsurface_list)); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1013 | |
Ander Conselvan de Oliveira | b8ab14f | 2012-03-27 17:36:36 +0300 | [diff] [blame] | 1014 | if (weston_surface_is_mapped(surface)) |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 1015 | weston_surface_unmap(surface); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 1016 | |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 1017 | wl_list_for_each_safe(cb, next, |
| 1018 | &surface->pending.frame_callback_list, link) |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 1019 | wl_resource_destroy(cb->resource); |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 1020 | |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 1021 | pixman_region32_fini(&surface->pending.input); |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 1022 | pixman_region32_fini(&surface->pending.opaque); |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 1023 | pixman_region32_fini(&surface->pending.damage); |
| 1024 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1025 | if (surface->pending.buffer) |
| 1026 | wl_list_remove(&surface->pending.buffer_destroy_listener.link); |
| 1027 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1028 | weston_buffer_reference(&surface->buffer_ref, NULL); |
Kristian Høgsberg | 3f8f39c | 2009-09-18 17:05:13 -0400 | [diff] [blame] | 1029 | |
Kristian Høgsberg | 4226385 | 2012-09-06 21:59:29 -0400 | [diff] [blame] | 1030 | compositor->renderer->destroy_surface(surface); |
Benjamin Franzke | 1178a3c | 2011-04-10 16:49:52 +0200 | [diff] [blame] | 1031 | |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1032 | pixman_region32_fini(&surface->transform.boundingbox); |
Pekka Paalanen | 402ae6d | 2012-01-03 10:23:24 +0200 | [diff] [blame] | 1033 | pixman_region32_fini(&surface->damage); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1034 | pixman_region32_fini(&surface->opaque); |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 1035 | pixman_region32_fini(&surface->clip); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 1036 | pixman_region32_fini(&surface->input); |
Pekka Paalanen | 402ae6d | 2012-01-03 10:23:24 +0200 | [diff] [blame] | 1037 | |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 1038 | wl_list_for_each_safe(cb, next, &surface->frame_callback_list, link) |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 1039 | wl_resource_destroy(cb->resource); |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 1040 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1041 | weston_surface_set_transform_parent(surface, NULL); |
| 1042 | |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 1043 | free(surface); |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 1044 | } |
| 1045 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1046 | static void |
| 1047 | destroy_surface(struct wl_resource *resource) |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 1048 | { |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1049 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 1050 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1051 | surface->resource = NULL; |
| 1052 | weston_surface_destroy(surface); |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 1053 | } |
| 1054 | |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 1055 | static void |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1056 | weston_buffer_destroy_handler(struct wl_listener *listener, void *data) |
| 1057 | { |
| 1058 | struct weston_buffer *buffer = |
| 1059 | container_of(listener, struct weston_buffer, destroy_listener); |
| 1060 | |
| 1061 | wl_signal_emit(&buffer->destroy_signal, buffer); |
| 1062 | free(buffer); |
| 1063 | } |
| 1064 | |
| 1065 | struct weston_buffer * |
| 1066 | weston_buffer_from_resource(struct wl_resource *resource) |
| 1067 | { |
| 1068 | struct weston_buffer *buffer; |
| 1069 | struct wl_listener *listener; |
| 1070 | |
| 1071 | listener = wl_resource_get_destroy_listener(resource, |
| 1072 | weston_buffer_destroy_handler); |
| 1073 | |
| 1074 | if (listener) { |
| 1075 | buffer = container_of(listener, struct weston_buffer, |
| 1076 | destroy_listener); |
| 1077 | } else { |
| 1078 | buffer = malloc(sizeof *buffer); |
| 1079 | memset(buffer, 0, sizeof *buffer); |
| 1080 | |
| 1081 | buffer->resource = resource; |
| 1082 | wl_signal_init(&buffer->destroy_signal); |
| 1083 | buffer->destroy_listener.notify = weston_buffer_destroy_handler; |
| 1084 | wl_resource_add_destroy_listener(resource, |
| 1085 | &buffer->destroy_listener); |
| 1086 | } |
| 1087 | |
| 1088 | return buffer; |
| 1089 | } |
| 1090 | |
| 1091 | static void |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1092 | weston_buffer_reference_handle_destroy(struct wl_listener *listener, |
| 1093 | void *data) |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 1094 | { |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1095 | struct weston_buffer_reference *ref = |
| 1096 | container_of(listener, struct weston_buffer_reference, |
| 1097 | destroy_listener); |
| 1098 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1099 | assert((struct weston_buffer *)data == ref->buffer); |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1100 | ref->buffer = NULL; |
| 1101 | } |
| 1102 | |
| 1103 | WL_EXPORT void |
| 1104 | weston_buffer_reference(struct weston_buffer_reference *ref, |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1105 | struct weston_buffer *buffer) |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1106 | { |
| 1107 | if (ref->buffer && buffer != ref->buffer) { |
Kristian Høgsberg | 2034780 | 2013-03-04 12:07:46 -0500 | [diff] [blame] | 1108 | ref->buffer->busy_count--; |
| 1109 | if (ref->buffer->busy_count == 0) { |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1110 | assert(wl_resource_get_client(ref->buffer->resource)); |
| 1111 | wl_resource_queue_event(ref->buffer->resource, |
Kristian Høgsberg | 2034780 | 2013-03-04 12:07:46 -0500 | [diff] [blame] | 1112 | WL_BUFFER_RELEASE); |
| 1113 | } |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1114 | wl_list_remove(&ref->destroy_listener.link); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 1115 | } |
| 1116 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1117 | if (buffer && buffer != ref->buffer) { |
Kristian Høgsberg | b7b77e6 | 2012-09-05 22:38:18 -0400 | [diff] [blame] | 1118 | buffer->busy_count++; |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1119 | wl_signal_add(&buffer->destroy_signal, |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1120 | &ref->destroy_listener); |
Pekka Paalanen | a6421c4 | 2012-12-04 15:58:10 +0200 | [diff] [blame] | 1121 | } |
| 1122 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1123 | ref->buffer = buffer; |
| 1124 | ref->destroy_listener.notify = weston_buffer_reference_handle_destroy; |
| 1125 | } |
| 1126 | |
| 1127 | static void |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1128 | weston_surface_attach(struct weston_surface *surface, |
| 1129 | struct weston_buffer *buffer) |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1130 | { |
| 1131 | weston_buffer_reference(&surface->buffer_ref, buffer); |
| 1132 | |
Pekka Paalanen | a6421c4 | 2012-12-04 15:58:10 +0200 | [diff] [blame] | 1133 | if (!buffer) { |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1134 | if (weston_surface_is_mapped(surface)) |
| 1135 | weston_surface_unmap(surface); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 1136 | } |
| 1137 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1138 | surface->compositor->renderer->attach(surface, buffer); |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 1139 | } |
| 1140 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1141 | WL_EXPORT void |
| 1142 | weston_surface_restack(struct weston_surface *surface, struct wl_list *below) |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1143 | { |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1144 | wl_list_remove(&surface->layer_link); |
| 1145 | wl_list_insert(below, &surface->layer_link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1146 | weston_surface_damage_below(surface); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1147 | weston_surface_damage(surface); |
Kristian Høgsberg | 8da19ac | 2009-03-17 16:12:51 -0400 | [diff] [blame] | 1148 | } |
| 1149 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1150 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1151 | weston_compositor_damage_all(struct weston_compositor *compositor) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1152 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1153 | struct weston_output *output; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1154 | |
| 1155 | wl_list_for_each(output, &compositor->output_list, link) |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1156 | weston_output_damage(output); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1157 | } |
| 1158 | |
Kristian Høgsberg | 9f404b7 | 2012-01-26 00:11:01 -0500 | [diff] [blame] | 1159 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1160 | weston_output_damage(struct weston_output *output) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1161 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1162 | struct weston_compositor *compositor = output->compositor; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1163 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1164 | pixman_region32_union(&compositor->primary_plane.damage, |
| 1165 | &compositor->primary_plane.damage, |
| 1166 | &output->region); |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 1167 | weston_output_schedule_repaint(output); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1168 | } |
| 1169 | |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame] | 1170 | static void |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1171 | surface_accumulate_damage(struct weston_surface *surface, |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1172 | pixman_region32_t *opaque) |
| 1173 | { |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1174 | if (surface->buffer_ref.buffer && |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1175 | wl_shm_buffer_get(surface->buffer_ref.buffer->resource)) |
Kristian Høgsberg | fa1be02 | 2012-09-05 22:49:55 -0400 | [diff] [blame] | 1176 | surface->compositor->renderer->flush_damage(surface); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1177 | |
| 1178 | if (surface->transform.enabled) { |
| 1179 | pixman_box32_t *extents; |
| 1180 | |
| 1181 | extents = pixman_region32_extents(&surface->damage); |
| 1182 | surface_compute_bbox(surface, extents->x1, extents->y1, |
| 1183 | extents->x2 - extents->x1, |
| 1184 | extents->y2 - extents->y1, |
| 1185 | &surface->damage); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1186 | pixman_region32_translate(&surface->damage, |
| 1187 | -surface->plane->x, |
| 1188 | -surface->plane->y); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1189 | } else { |
| 1190 | pixman_region32_translate(&surface->damage, |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1191 | surface->geometry.x - surface->plane->x, |
| 1192 | surface->geometry.y - surface->plane->y); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1193 | } |
| 1194 | |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 1195 | pixman_region32_subtract(&surface->damage, &surface->damage, opaque); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1196 | pixman_region32_union(&surface->plane->damage, |
| 1197 | &surface->plane->damage, &surface->damage); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1198 | empty_region(&surface->damage); |
| 1199 | pixman_region32_copy(&surface->clip, opaque); |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 1200 | pixman_region32_union(opaque, opaque, &surface->transform.opaque); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1201 | } |
| 1202 | |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 1203 | static void |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 1204 | compositor_accumulate_damage(struct weston_compositor *ec) |
| 1205 | { |
| 1206 | struct weston_plane *plane; |
| 1207 | struct weston_surface *es; |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 1208 | pixman_region32_t opaque, clip; |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 1209 | |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 1210 | pixman_region32_init(&clip); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 1211 | |
| 1212 | wl_list_for_each(plane, &ec->plane_list, link) { |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 1213 | pixman_region32_copy(&plane->clip, &clip); |
| 1214 | |
| 1215 | pixman_region32_init(&opaque); |
| 1216 | |
| 1217 | wl_list_for_each(es, &ec->surface_list, link) { |
| 1218 | if (es->plane != plane) |
| 1219 | continue; |
| 1220 | |
| 1221 | surface_accumulate_damage(es, &opaque); |
| 1222 | } |
| 1223 | |
| 1224 | pixman_region32_union(&clip, &clip, &opaque); |
| 1225 | pixman_region32_fini(&opaque); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 1226 | } |
| 1227 | |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 1228 | pixman_region32_fini(&clip); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 1229 | |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 1230 | wl_list_for_each(es, &ec->surface_list, link) { |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 1231 | /* Both the renderer and the backend have seen the buffer |
| 1232 | * by now. If renderer needs the buffer, it has its own |
| 1233 | * reference set. If the backend wants to keep the buffer |
| 1234 | * around for migrating the surface into a non-primary plane |
| 1235 | * later, keep_buffer is true. Otherwise, drop the core |
| 1236 | * reference now, and allow early buffer release. This enables |
| 1237 | * clients to use single-buffering. |
| 1238 | */ |
| 1239 | if (!es->keep_buffer) |
| 1240 | weston_buffer_reference(&es->buffer_ref, NULL); |
| 1241 | } |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1245 | surface_list_add(struct weston_compositor *compositor, |
| 1246 | struct weston_surface *surface) |
| 1247 | { |
| 1248 | struct weston_subsurface *sub; |
| 1249 | |
| 1250 | if (wl_list_empty(&surface->subsurface_list)) { |
| 1251 | weston_surface_update_transform(surface); |
| 1252 | wl_list_insert(compositor->surface_list.prev, &surface->link); |
| 1253 | return; |
| 1254 | } |
| 1255 | |
| 1256 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
| 1257 | if (!weston_surface_is_mapped(sub->surface)) |
| 1258 | continue; |
| 1259 | |
| 1260 | if (sub->surface == surface) { |
| 1261 | weston_surface_update_transform(sub->surface); |
| 1262 | wl_list_insert(compositor->surface_list.prev, |
| 1263 | &sub->surface->link); |
| 1264 | } else { |
| 1265 | surface_list_add(compositor, sub->surface); |
| 1266 | } |
| 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | static void |
| 1271 | weston_compositor_build_surface_list(struct weston_compositor *compositor) |
| 1272 | { |
| 1273 | struct weston_surface *surface; |
| 1274 | struct weston_layer *layer; |
| 1275 | |
| 1276 | wl_list_init(&compositor->surface_list); |
| 1277 | wl_list_for_each(layer, &compositor->layer_list, link) { |
| 1278 | wl_list_for_each(surface, &layer->surface_list, layer_link) { |
| 1279 | surface_list_add(compositor, surface); |
| 1280 | } |
| 1281 | } |
| 1282 | } |
| 1283 | |
| 1284 | static void |
Rob Bradford | 0fb7975 | 2012-08-02 15:36:57 +0100 | [diff] [blame] | 1285 | weston_output_repaint(struct weston_output *output, uint32_t msecs) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 1286 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1287 | struct weston_compositor *ec = output->compositor; |
Kristian Høgsberg | 681f9f4 | 2012-01-26 10:55:10 -0500 | [diff] [blame] | 1288 | struct weston_surface *es; |
Kristian Høgsberg | 30c018b | 2012-01-26 08:40:37 -0500 | [diff] [blame] | 1289 | struct weston_animation *animation, *next; |
| 1290 | struct weston_frame_callback *cb, *cnext; |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 1291 | struct wl_list frame_callback_list; |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 1292 | pixman_region32_t output_damage; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 1293 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1294 | /* Rebuild the surface list and update surface transforms up front. */ |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1295 | weston_compositor_build_surface_list(ec); |
Pekka Paalanen | 15d60ef | 2012-01-27 14:38:33 +0200 | [diff] [blame] | 1296 | |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 1297 | if (output->assign_planes && !output->disable_planes) |
Jesse Barnes | 5308a5e | 2012-02-09 13:12:57 -0800 | [diff] [blame] | 1298 | output->assign_planes(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 1299 | else |
| 1300 | wl_list_for_each(es, &ec->surface_list, link) |
| 1301 | weston_surface_move_to_plane(es, &ec->primary_plane); |
| 1302 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1303 | wl_list_init(&frame_callback_list); |
| 1304 | wl_list_for_each(es, &ec->surface_list, link) { |
| 1305 | if (es->output == output) { |
| 1306 | wl_list_insert_list(&frame_callback_list, |
| 1307 | &es->frame_callback_list); |
| 1308 | wl_list_init(&es->frame_callback_list); |
| 1309 | } |
| 1310 | } |
| 1311 | |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 1312 | compositor_accumulate_damage(ec); |
Kristian Høgsberg | 53df1d8 | 2011-06-23 21:11:19 -0400 | [diff] [blame] | 1313 | |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 1314 | pixman_region32_init(&output_damage); |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 1315 | pixman_region32_intersect(&output_damage, |
| 1316 | &ec->primary_plane.damage, &output->region); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 1317 | pixman_region32_subtract(&output_damage, |
| 1318 | &output_damage, &ec->primary_plane.clip); |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 1319 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 1320 | if (output->dirty) |
| 1321 | weston_output_update_matrix(output); |
| 1322 | |
Kristian Høgsberg | d7c1726 | 2012-09-05 21:54:15 -0400 | [diff] [blame] | 1323 | output->repaint(output, &output_damage); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 1324 | |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 1325 | pixman_region32_fini(&output_damage); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1326 | |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 1327 | output->repaint_needed = 0; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 1328 | |
Kristian Høgsberg | aa6019e | 2012-03-11 16:35:16 -0400 | [diff] [blame] | 1329 | weston_compositor_repick(ec); |
| 1330 | wl_event_loop_dispatch(ec->input_loop, 0); |
| 1331 | |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 1332 | wl_list_for_each_safe(cb, cnext, &frame_callback_list, link) { |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 1333 | wl_callback_send_done(cb->resource, msecs); |
| 1334 | wl_resource_destroy(cb->resource); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 1335 | } |
| 1336 | |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 1337 | wl_list_for_each_safe(animation, next, &output->animation_list, link) { |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 1338 | animation->frame_counter++; |
Scott Moreau | 94b0b0c | 2012-06-14 01:01:56 -0600 | [diff] [blame] | 1339 | animation->frame(animation, output, msecs); |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 1340 | } |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 1341 | } |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 1342 | |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 1343 | static int |
| 1344 | weston_compositor_read_input(int fd, uint32_t mask, void *data) |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 1345 | { |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 1346 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | 34f80ff | 2012-01-18 11:50:31 -0500 | [diff] [blame] | 1347 | |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 1348 | wl_event_loop_dispatch(compositor->input_loop, 0); |
| 1349 | |
| 1350 | return 1; |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | WL_EXPORT void |
Rob Bradford | 0fb7975 | 2012-08-02 15:36:57 +0100 | [diff] [blame] | 1354 | weston_output_finish_frame(struct weston_output *output, uint32_t msecs) |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 1355 | { |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 1356 | struct weston_compositor *compositor = output->compositor; |
| 1357 | struct wl_event_loop *loop = |
| 1358 | wl_display_get_event_loop(compositor->wl_display); |
| 1359 | int fd; |
| 1360 | |
Kristian Høgsberg | e9d0492 | 2012-06-19 23:54:26 -0400 | [diff] [blame] | 1361 | output->frame_time = msecs; |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 1362 | if (output->repaint_needed) { |
Kristian Høgsberg | 30c018b | 2012-01-26 08:40:37 -0500 | [diff] [blame] | 1363 | weston_output_repaint(output, msecs); |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 1364 | return; |
| 1365 | } |
| 1366 | |
| 1367 | output->repaint_scheduled = 0; |
| 1368 | if (compositor->input_loop_source) |
| 1369 | return; |
| 1370 | |
| 1371 | fd = wl_event_loop_get_fd(compositor->input_loop); |
| 1372 | compositor->input_loop_source = |
| 1373 | wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE, |
| 1374 | weston_compositor_read_input, compositor); |
| 1375 | } |
| 1376 | |
| 1377 | static void |
| 1378 | idle_repaint(void *data) |
| 1379 | { |
| 1380 | struct weston_output *output = data; |
| 1381 | |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 1382 | output->start_repaint_loop(output); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 1383 | } |
| 1384 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1385 | WL_EXPORT void |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1386 | weston_layer_init(struct weston_layer *layer, struct wl_list *below) |
| 1387 | { |
| 1388 | wl_list_init(&layer->surface_list); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 1389 | if (below != NULL) |
| 1390 | wl_list_insert(below, &layer->link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1391 | } |
| 1392 | |
| 1393 | WL_EXPORT void |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 1394 | weston_output_schedule_repaint(struct weston_output *output) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 1395 | { |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 1396 | struct weston_compositor *compositor = output->compositor; |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 1397 | struct wl_event_loop *loop; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 1398 | |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 1399 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING || |
| 1400 | compositor->state == WESTON_COMPOSITOR_OFFSCREEN) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1401 | return; |
| 1402 | |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 1403 | loop = wl_display_get_event_loop(compositor->wl_display); |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 1404 | output->repaint_needed = 1; |
| 1405 | if (output->repaint_scheduled) |
| 1406 | return; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 1407 | |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 1408 | wl_event_loop_add_idle(loop, idle_repaint, output); |
| 1409 | output->repaint_scheduled = 1; |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 1410 | |
| 1411 | if (compositor->input_loop_source) { |
| 1412 | wl_event_source_remove(compositor->input_loop_source); |
| 1413 | compositor->input_loop_source = NULL; |
| 1414 | } |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 1415 | } |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 1416 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1417 | WL_EXPORT void |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 1418 | weston_compositor_schedule_repaint(struct weston_compositor *compositor) |
| 1419 | { |
| 1420 | struct weston_output *output; |
| 1421 | |
| 1422 | wl_list_for_each(output, &compositor->output_list, link) |
| 1423 | weston_output_schedule_repaint(output); |
| 1424 | } |
| 1425 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 1426 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 1427 | surface_destroy(struct wl_client *client, struct wl_resource *resource) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1428 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1429 | wl_resource_destroy(resource); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 1430 | } |
| 1431 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 1432 | static void |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 1433 | surface_attach(struct wl_client *client, |
| 1434 | struct wl_resource *resource, |
| 1435 | struct wl_resource *buffer_resource, int32_t sx, int32_t sy) |
| 1436 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1437 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1438 | struct weston_buffer *buffer = NULL; |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 1439 | |
| 1440 | if (buffer_resource) |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1441 | buffer = weston_buffer_from_resource(buffer_resource); |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 1442 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1443 | /* Attach, attach, without commit in between does not send |
| 1444 | * wl_buffer.release. */ |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1445 | if (surface->pending.buffer) |
| 1446 | wl_list_remove(&surface->pending.buffer_destroy_listener.link); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 1447 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1448 | surface->pending.sx = sx; |
| 1449 | surface->pending.sy = sy; |
| 1450 | surface->pending.buffer = buffer; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 1451 | surface->pending.newly_attached = 1; |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1452 | if (buffer) { |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1453 | wl_signal_add(&buffer->destroy_signal, |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1454 | &surface->pending.buffer_destroy_listener); |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1455 | } |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 1456 | } |
| 1457 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 1458 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1459 | surface_damage(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 1460 | struct wl_resource *resource, |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1461 | int32_t x, int32_t y, int32_t width, int32_t height) |
Kristian Høgsberg | 7f77bd8 | 2008-11-07 08:39:37 -0500 | [diff] [blame] | 1462 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1463 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 9d69f8e | 2010-09-03 14:46:38 -0400 | [diff] [blame] | 1464 | |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 1465 | pixman_region32_union_rect(&surface->pending.damage, |
| 1466 | &surface->pending.damage, |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1467 | x, y, width, height); |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 1468 | } |
| 1469 | |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 1470 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 1471 | destroy_frame_callback(struct wl_resource *resource) |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 1472 | { |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 1473 | struct weston_frame_callback *cb = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 1474 | |
| 1475 | wl_list_remove(&cb->link); |
Pekka Paalanen | 8c19645 | 2011-11-15 11:45:42 +0200 | [diff] [blame] | 1476 | free(cb); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | static void |
| 1480 | surface_frame(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 1481 | struct wl_resource *resource, uint32_t callback) |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 1482 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1483 | struct weston_frame_callback *cb; |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1484 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 1485 | |
| 1486 | cb = malloc(sizeof *cb); |
| 1487 | if (cb == NULL) { |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 1488 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 1489 | return; |
| 1490 | } |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 1491 | |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 1492 | cb->resource = wl_client_add_object(client, &wl_callback_interface, |
| 1493 | NULL, callback, cb); |
| 1494 | wl_resource_set_destructor(cb->resource, destroy_frame_callback); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 1495 | |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 1496 | wl_list_insert(surface->pending.frame_callback_list.prev, &cb->link); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 1497 | } |
| 1498 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1499 | static void |
| 1500 | surface_set_opaque_region(struct wl_client *client, |
| 1501 | struct wl_resource *resource, |
| 1502 | struct wl_resource *region_resource) |
| 1503 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1504 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1505 | struct weston_region *region; |
| 1506 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1507 | if (region_resource) { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 1508 | region = wl_resource_get_user_data(region_resource); |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 1509 | pixman_region32_copy(&surface->pending.opaque, |
| 1510 | ®ion->region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1511 | } else { |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 1512 | empty_region(&surface->pending.opaque); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1513 | } |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1514 | } |
| 1515 | |
| 1516 | static void |
| 1517 | surface_set_input_region(struct wl_client *client, |
| 1518 | struct wl_resource *resource, |
| 1519 | struct wl_resource *region_resource) |
| 1520 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1521 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 010f98b | 2012-02-23 17:30:45 -0500 | [diff] [blame] | 1522 | struct weston_region *region; |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1523 | |
| 1524 | if (region_resource) { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 1525 | region = wl_resource_get_user_data(region_resource); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 1526 | pixman_region32_copy(&surface->pending.input, |
| 1527 | ®ion->region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1528 | } else { |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 1529 | pixman_region32_fini(&surface->pending.input); |
| 1530 | region_init_infinite(&surface->pending.input); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1531 | } |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1532 | } |
| 1533 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1534 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1535 | weston_surface_commit_subsurface_order(struct weston_surface *surface) |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1536 | { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1537 | struct weston_subsurface *sub; |
| 1538 | |
| 1539 | wl_list_for_each_reverse(sub, &surface->subsurface_list_pending, |
| 1540 | parent_link_pending) { |
| 1541 | wl_list_remove(&sub->parent_link); |
| 1542 | wl_list_insert(&surface->subsurface_list, &sub->parent_link); |
| 1543 | } |
| 1544 | } |
| 1545 | |
| 1546 | static void |
| 1547 | weston_surface_commit(struct weston_surface *surface) |
| 1548 | { |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 1549 | pixman_region32_t opaque; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 1550 | int surface_width = 0; |
| 1551 | int surface_height = 0; |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 1552 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 1553 | /* wl_surface.set_buffer_transform */ |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1554 | surface->buffer_transform = surface->pending.buffer_transform; |
| 1555 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 1556 | /* wl_surface.set_buffer_scale */ |
| 1557 | surface->buffer_scale = surface->pending.buffer_scale; |
| 1558 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1559 | /* wl_surface.attach */ |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 1560 | if (surface->pending.buffer || surface->pending.newly_attached) |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1561 | weston_surface_attach(surface, surface->pending.buffer); |
| 1562 | |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 1563 | if (surface->buffer_ref.buffer) { |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 1564 | surface_width = weston_surface_buffer_width(surface); |
| 1565 | surface_height = weston_surface_buffer_height(surface); |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 1566 | } |
| 1567 | |
| 1568 | if (surface->configure && surface->pending.newly_attached) |
Pekka Paalanen | f1f48cf | 2013-03-08 14:56:48 +0200 | [diff] [blame] | 1569 | surface->configure(surface, |
| 1570 | surface->pending.sx, surface->pending.sy, |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 1571 | surface_width, surface_height); |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 1572 | |
Kristian Høgsberg | e7144fd | 2013-03-04 12:11:41 -0500 | [diff] [blame] | 1573 | if (surface->pending.buffer) |
| 1574 | wl_list_remove(&surface->pending.buffer_destroy_listener.link); |
| 1575 | surface->pending.buffer = NULL; |
Daniel Stone | b4f4a59 | 2012-11-07 17:51:44 +1100 | [diff] [blame] | 1576 | surface->pending.sx = 0; |
| 1577 | surface->pending.sy = 0; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 1578 | surface->pending.newly_attached = 0; |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 1579 | |
| 1580 | /* wl_surface.damage */ |
| 1581 | pixman_region32_union(&surface->damage, &surface->damage, |
| 1582 | &surface->pending.damage); |
Kristian Høgsberg | 4d0214c | 2012-11-08 11:36:02 -0500 | [diff] [blame] | 1583 | pixman_region32_intersect_rect(&surface->damage, &surface->damage, |
| 1584 | 0, 0, |
| 1585 | surface->geometry.width, |
| 1586 | surface->geometry.height); |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 1587 | empty_region(&surface->pending.damage); |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 1588 | |
| 1589 | /* wl_surface.set_opaque_region */ |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 1590 | pixman_region32_init_rect(&opaque, 0, 0, |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 1591 | surface->geometry.width, |
| 1592 | surface->geometry.height); |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 1593 | pixman_region32_intersect(&opaque, |
| 1594 | &opaque, &surface->pending.opaque); |
| 1595 | |
| 1596 | if (!pixman_region32_equal(&opaque, &surface->opaque)) { |
| 1597 | pixman_region32_copy(&surface->opaque, &opaque); |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 1598 | weston_surface_geometry_dirty(surface); |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 1599 | } |
| 1600 | |
| 1601 | pixman_region32_fini(&opaque); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 1602 | |
| 1603 | /* wl_surface.set_input_region */ |
| 1604 | pixman_region32_fini(&surface->input); |
| 1605 | pixman_region32_init_rect(&surface->input, 0, 0, |
| 1606 | surface->geometry.width, |
| 1607 | surface->geometry.height); |
| 1608 | pixman_region32_intersect(&surface->input, |
| 1609 | &surface->input, &surface->pending.input); |
| 1610 | |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 1611 | /* wl_surface.frame */ |
| 1612 | wl_list_insert_list(&surface->frame_callback_list, |
| 1613 | &surface->pending.frame_callback_list); |
| 1614 | wl_list_init(&surface->pending.frame_callback_list); |
| 1615 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1616 | weston_surface_commit_subsurface_order(surface); |
| 1617 | |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 1618 | weston_surface_schedule_repaint(surface); |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1619 | } |
| 1620 | |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1621 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1622 | weston_subsurface_commit(struct weston_subsurface *sub); |
| 1623 | |
| 1624 | static void |
| 1625 | weston_subsurface_parent_commit(struct weston_subsurface *sub, |
| 1626 | int parent_is_synchronized); |
| 1627 | |
| 1628 | static void |
| 1629 | surface_commit(struct wl_client *client, struct wl_resource *resource) |
| 1630 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1631 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1632 | struct weston_subsurface *sub = weston_surface_to_subsurface(surface); |
| 1633 | |
| 1634 | if (sub) { |
| 1635 | weston_subsurface_commit(sub); |
| 1636 | return; |
| 1637 | } |
| 1638 | |
| 1639 | weston_surface_commit(surface); |
| 1640 | |
| 1641 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
| 1642 | if (sub->surface != surface) |
| 1643 | weston_subsurface_parent_commit(sub, 0); |
| 1644 | } |
| 1645 | } |
| 1646 | |
| 1647 | static void |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1648 | surface_set_buffer_transform(struct wl_client *client, |
| 1649 | struct wl_resource *resource, int transform) |
| 1650 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1651 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1652 | |
| 1653 | surface->pending.buffer_transform = transform; |
| 1654 | } |
| 1655 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 1656 | static void |
| 1657 | surface_set_buffer_scale(struct wl_client *client, |
| 1658 | struct wl_resource *resource, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 1659 | int32_t scale) |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 1660 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 1661 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 1662 | |
| 1663 | surface->pending.buffer_scale = scale; |
| 1664 | } |
| 1665 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 1666 | static const struct wl_surface_interface surface_interface = { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1667 | surface_destroy, |
| 1668 | surface_attach, |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 1669 | surface_damage, |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1670 | surface_frame, |
| 1671 | surface_set_opaque_region, |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1672 | surface_set_input_region, |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1673 | surface_commit, |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 1674 | surface_set_buffer_transform, |
| 1675 | surface_set_buffer_scale |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1676 | }; |
| 1677 | |
| 1678 | static void |
| 1679 | compositor_create_surface(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 1680 | struct wl_resource *resource, uint32_t id) |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1681 | { |
Kristian Høgsberg | c2d7042 | 2013-06-25 15:34:33 -0400 | [diff] [blame^] | 1682 | struct weston_compositor *ec = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1683 | struct weston_surface *surface; |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1684 | |
Kristian Høgsberg | 18c9300 | 2012-01-27 11:58:31 -0500 | [diff] [blame] | 1685 | surface = weston_surface_create(ec); |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 1686 | if (surface == NULL) { |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 1687 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1688 | return; |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 1689 | } |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1690 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1691 | surface->resource = wl_client_add_object(client, &wl_surface_interface, |
| 1692 | &surface_interface, |
| 1693 | id, surface); |
| 1694 | wl_resource_set_destructor(surface->resource, destroy_surface); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1695 | } |
| 1696 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1697 | static void |
| 1698 | destroy_region(struct wl_resource *resource) |
| 1699 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 1700 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1701 | |
| 1702 | pixman_region32_fini(®ion->region); |
| 1703 | free(region); |
| 1704 | } |
| 1705 | |
| 1706 | static void |
| 1707 | region_destroy(struct wl_client *client, struct wl_resource *resource) |
| 1708 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1709 | wl_resource_destroy(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1710 | } |
| 1711 | |
| 1712 | static void |
| 1713 | region_add(struct wl_client *client, struct wl_resource *resource, |
| 1714 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 1715 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 1716 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1717 | |
| 1718 | pixman_region32_union_rect(®ion->region, ®ion->region, |
| 1719 | x, y, width, height); |
| 1720 | } |
| 1721 | |
| 1722 | static void |
| 1723 | region_subtract(struct wl_client *client, struct wl_resource *resource, |
| 1724 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 1725 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 1726 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1727 | pixman_region32_t rect; |
| 1728 | |
| 1729 | pixman_region32_init_rect(&rect, x, y, width, height); |
| 1730 | pixman_region32_subtract(®ion->region, ®ion->region, &rect); |
| 1731 | pixman_region32_fini(&rect); |
| 1732 | } |
| 1733 | |
| 1734 | static const struct wl_region_interface region_interface = { |
| 1735 | region_destroy, |
| 1736 | region_add, |
| 1737 | region_subtract |
| 1738 | }; |
| 1739 | |
| 1740 | static void |
| 1741 | compositor_create_region(struct wl_client *client, |
| 1742 | struct wl_resource *resource, uint32_t id) |
| 1743 | { |
| 1744 | struct weston_region *region; |
| 1745 | |
| 1746 | region = malloc(sizeof *region); |
| 1747 | if (region == NULL) { |
| 1748 | wl_resource_post_no_memory(resource); |
| 1749 | return; |
| 1750 | } |
| 1751 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1752 | pixman_region32_init(®ion->region); |
| 1753 | |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 1754 | region->resource = wl_client_add_object(client, &wl_region_interface, |
| 1755 | ®ion_interface, id, region); |
| 1756 | wl_resource_set_destructor(region->resource, destroy_region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1757 | } |
| 1758 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 1759 | static const struct wl_compositor_interface compositor_interface = { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1760 | compositor_create_surface, |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1761 | compositor_create_region |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 1762 | }; |
| 1763 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 1764 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1765 | weston_subsurface_commit_from_cache(struct weston_subsurface *sub) |
| 1766 | { |
| 1767 | struct weston_surface *surface = sub->surface; |
| 1768 | pixman_region32_t opaque; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 1769 | int surface_width = 0; |
| 1770 | int surface_height = 0; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1771 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 1772 | /* wl_surface.set_buffer_transform */ |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1773 | surface->buffer_transform = sub->cached.buffer_transform; |
| 1774 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 1775 | /* wl_surface.set_buffer_scale */ |
| 1776 | surface->buffer_scale = sub->cached.buffer_scale; |
| 1777 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1778 | /* wl_surface.attach */ |
| 1779 | if (sub->cached.buffer_ref.buffer || sub->cached.newly_attached) |
| 1780 | weston_surface_attach(surface, sub->cached.buffer_ref.buffer); |
| 1781 | weston_buffer_reference(&sub->cached.buffer_ref, NULL); |
| 1782 | |
| 1783 | if (surface->buffer_ref.buffer) { |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 1784 | surface_width = weston_surface_buffer_width(surface); |
| 1785 | surface_height = weston_surface_buffer_height(surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | if (surface->configure && sub->cached.newly_attached) |
| 1789 | surface->configure(surface, sub->cached.sx, sub->cached.sy, |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 1790 | surface_width, surface_height); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1791 | sub->cached.sx = 0; |
| 1792 | sub->cached.sy = 0; |
| 1793 | sub->cached.newly_attached = 0; |
| 1794 | |
| 1795 | /* wl_surface.damage */ |
| 1796 | pixman_region32_union(&surface->damage, &surface->damage, |
| 1797 | &sub->cached.damage); |
| 1798 | pixman_region32_intersect_rect(&surface->damage, &surface->damage, |
| 1799 | 0, 0, |
| 1800 | surface->geometry.width, |
| 1801 | surface->geometry.height); |
| 1802 | empty_region(&sub->cached.damage); |
| 1803 | |
| 1804 | /* wl_surface.set_opaque_region */ |
| 1805 | pixman_region32_init_rect(&opaque, 0, 0, |
| 1806 | surface->geometry.width, |
| 1807 | surface->geometry.height); |
| 1808 | pixman_region32_intersect(&opaque, |
| 1809 | &opaque, &sub->cached.opaque); |
| 1810 | |
| 1811 | if (!pixman_region32_equal(&opaque, &surface->opaque)) { |
| 1812 | pixman_region32_copy(&surface->opaque, &opaque); |
| 1813 | weston_surface_geometry_dirty(surface); |
| 1814 | } |
| 1815 | |
| 1816 | pixman_region32_fini(&opaque); |
| 1817 | |
| 1818 | /* wl_surface.set_input_region */ |
| 1819 | pixman_region32_fini(&surface->input); |
| 1820 | pixman_region32_init_rect(&surface->input, 0, 0, |
| 1821 | surface->geometry.width, |
| 1822 | surface->geometry.height); |
| 1823 | pixman_region32_intersect(&surface->input, |
| 1824 | &surface->input, &sub->cached.input); |
| 1825 | |
| 1826 | /* wl_surface.frame */ |
| 1827 | wl_list_insert_list(&surface->frame_callback_list, |
| 1828 | &sub->cached.frame_callback_list); |
| 1829 | wl_list_init(&sub->cached.frame_callback_list); |
| 1830 | |
| 1831 | weston_surface_commit_subsurface_order(surface); |
| 1832 | |
| 1833 | weston_surface_schedule_repaint(surface); |
| 1834 | |
| 1835 | sub->cached.has_data = 0; |
| 1836 | } |
| 1837 | |
| 1838 | static void |
| 1839 | weston_subsurface_commit_to_cache(struct weston_subsurface *sub) |
| 1840 | { |
| 1841 | struct weston_surface *surface = sub->surface; |
| 1842 | |
| 1843 | /* |
| 1844 | * If this commit would cause the surface to move by the |
| 1845 | * attach(dx, dy) parameters, the old damage region must be |
| 1846 | * translated to correspond to the new surface coordinate system |
| 1847 | * origin. |
| 1848 | */ |
| 1849 | pixman_region32_translate(&sub->cached.damage, |
| 1850 | -surface->pending.sx, -surface->pending.sy); |
| 1851 | pixman_region32_union(&sub->cached.damage, &sub->cached.damage, |
| 1852 | &surface->pending.damage); |
| 1853 | empty_region(&surface->pending.damage); |
| 1854 | |
| 1855 | if (surface->pending.newly_attached) { |
| 1856 | sub->cached.newly_attached = 1; |
| 1857 | weston_buffer_reference(&sub->cached.buffer_ref, |
| 1858 | surface->pending.buffer); |
| 1859 | } |
| 1860 | sub->cached.sx += surface->pending.sx; |
| 1861 | sub->cached.sy += surface->pending.sy; |
| 1862 | surface->pending.sx = 0; |
| 1863 | surface->pending.sy = 0; |
| 1864 | surface->pending.newly_attached = 0; |
| 1865 | |
| 1866 | sub->cached.buffer_transform = surface->pending.buffer_transform; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 1867 | sub->cached.buffer_scale = surface->pending.buffer_scale; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1868 | |
| 1869 | pixman_region32_copy(&sub->cached.opaque, &surface->pending.opaque); |
| 1870 | |
| 1871 | pixman_region32_copy(&sub->cached.input, &surface->pending.input); |
| 1872 | |
| 1873 | wl_list_insert_list(&sub->cached.frame_callback_list, |
| 1874 | &surface->pending.frame_callback_list); |
| 1875 | wl_list_init(&surface->pending.frame_callback_list); |
| 1876 | |
| 1877 | sub->cached.has_data = 1; |
| 1878 | } |
| 1879 | |
| 1880 | static int |
| 1881 | weston_subsurface_is_synchronized(struct weston_subsurface *sub) |
| 1882 | { |
| 1883 | while (sub) { |
| 1884 | if (sub->synchronized) |
| 1885 | return 1; |
| 1886 | |
| 1887 | if (!sub->parent) |
| 1888 | return 0; |
| 1889 | |
| 1890 | sub = weston_surface_to_subsurface(sub->parent); |
| 1891 | } |
| 1892 | |
| 1893 | return 0; |
| 1894 | } |
| 1895 | |
| 1896 | static void |
| 1897 | weston_subsurface_commit(struct weston_subsurface *sub) |
| 1898 | { |
| 1899 | struct weston_surface *surface = sub->surface; |
| 1900 | struct weston_subsurface *tmp; |
| 1901 | |
| 1902 | /* Recursive check for effectively synchronized. */ |
| 1903 | if (weston_subsurface_is_synchronized(sub)) { |
| 1904 | weston_subsurface_commit_to_cache(sub); |
| 1905 | } else { |
| 1906 | if (sub->cached.has_data) { |
| 1907 | /* flush accumulated state from cache */ |
| 1908 | weston_subsurface_commit_to_cache(sub); |
| 1909 | weston_subsurface_commit_from_cache(sub); |
| 1910 | } else { |
| 1911 | weston_surface_commit(surface); |
| 1912 | } |
| 1913 | |
| 1914 | wl_list_for_each(tmp, &surface->subsurface_list, parent_link) { |
| 1915 | if (tmp->surface != surface) |
| 1916 | weston_subsurface_parent_commit(tmp, 0); |
| 1917 | } |
| 1918 | } |
| 1919 | } |
| 1920 | |
| 1921 | static void |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 1922 | weston_subsurface_synchronized_commit(struct weston_subsurface *sub) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1923 | { |
| 1924 | struct weston_surface *surface = sub->surface; |
| 1925 | struct weston_subsurface *tmp; |
| 1926 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1927 | /* From now on, commit_from_cache the whole sub-tree, regardless of |
| 1928 | * the synchronized mode of each child. This sub-surface or some |
| 1929 | * of its ancestors were synchronized, so we are synchronized |
| 1930 | * all the way down. |
| 1931 | */ |
| 1932 | |
| 1933 | if (sub->cached.has_data) |
| 1934 | weston_subsurface_commit_from_cache(sub); |
| 1935 | |
| 1936 | wl_list_for_each(tmp, &surface->subsurface_list, parent_link) { |
| 1937 | if (tmp->surface != surface) |
| 1938 | weston_subsurface_parent_commit(tmp, 1); |
| 1939 | } |
| 1940 | } |
| 1941 | |
| 1942 | static void |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 1943 | weston_subsurface_parent_commit(struct weston_subsurface *sub, |
| 1944 | int parent_is_synchronized) |
| 1945 | { |
| 1946 | if (sub->position.set) { |
| 1947 | weston_surface_set_position(sub->surface, |
| 1948 | sub->position.x, sub->position.y); |
| 1949 | sub->position.set = 0; |
| 1950 | } |
| 1951 | |
| 1952 | if (parent_is_synchronized || sub->synchronized) |
| 1953 | weston_subsurface_synchronized_commit(sub); |
| 1954 | } |
| 1955 | |
| 1956 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1957 | subsurface_configure(struct weston_surface *surface, int32_t dx, int32_t dy, |
| 1958 | int32_t width, int32_t height) |
| 1959 | { |
| 1960 | struct weston_compositor *compositor = surface->compositor; |
| 1961 | |
| 1962 | weston_surface_configure(surface, |
| 1963 | surface->geometry.x + dx, |
| 1964 | surface->geometry.y + dy, |
| 1965 | width, height); |
| 1966 | |
| 1967 | /* No need to check parent mappedness, because if parent is not |
| 1968 | * mapped, parent is not in a visible layer, so this sub-surface |
| 1969 | * will not be drawn either. |
| 1970 | */ |
| 1971 | if (!weston_surface_is_mapped(surface)) { |
| 1972 | wl_list_init(&surface->layer_link); |
| 1973 | |
| 1974 | /* Cannot call weston_surface_update_transform(), |
| 1975 | * because that would call it also for the parent surface, |
| 1976 | * which might not be mapped yet. That would lead to |
| 1977 | * inconsistent state, where the window could never be |
| 1978 | * mapped. |
| 1979 | * |
| 1980 | * Instead just assing any output, to make |
| 1981 | * weston_surface_is_mapped() return true, so that when the |
| 1982 | * parent surface does get mapped, this one will get |
| 1983 | * included, too. See surface_list_add(). |
| 1984 | */ |
| 1985 | assert(!wl_list_empty(&compositor->output_list)); |
| 1986 | surface->output = container_of(compositor->output_list.next, |
| 1987 | struct weston_output, link); |
| 1988 | } |
| 1989 | } |
| 1990 | |
| 1991 | static struct weston_subsurface * |
| 1992 | weston_surface_to_subsurface(struct weston_surface *surface) |
| 1993 | { |
| 1994 | if (surface->configure == subsurface_configure) |
| 1995 | return surface->configure_private; |
| 1996 | |
| 1997 | return NULL; |
| 1998 | } |
| 1999 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 2000 | WL_EXPORT struct weston_surface * |
| 2001 | weston_surface_get_main_surface(struct weston_surface *surface) |
| 2002 | { |
| 2003 | struct weston_subsurface *sub; |
| 2004 | |
| 2005 | while (surface && (sub = weston_surface_to_subsurface(surface))) |
| 2006 | surface = sub->parent; |
| 2007 | |
| 2008 | return surface; |
| 2009 | } |
| 2010 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2011 | static void |
| 2012 | subsurface_set_position(struct wl_client *client, |
| 2013 | struct wl_resource *resource, int32_t x, int32_t y) |
| 2014 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 2015 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2016 | |
| 2017 | if (!sub) |
| 2018 | return; |
| 2019 | |
| 2020 | sub->position.x = x; |
| 2021 | sub->position.y = y; |
| 2022 | sub->position.set = 1; |
| 2023 | } |
| 2024 | |
| 2025 | static struct weston_subsurface * |
| 2026 | subsurface_from_surface(struct weston_surface *surface) |
| 2027 | { |
| 2028 | struct weston_subsurface *sub; |
| 2029 | |
| 2030 | sub = weston_surface_to_subsurface(surface); |
| 2031 | if (sub) |
| 2032 | return sub; |
| 2033 | |
| 2034 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) |
| 2035 | if (sub->surface == surface) |
| 2036 | return sub; |
| 2037 | |
| 2038 | return NULL; |
| 2039 | } |
| 2040 | |
| 2041 | static struct weston_subsurface * |
| 2042 | subsurface_sibling_check(struct weston_subsurface *sub, |
| 2043 | struct weston_surface *surface, |
| 2044 | const char *request) |
| 2045 | { |
| 2046 | struct weston_subsurface *sibling; |
| 2047 | |
| 2048 | sibling = subsurface_from_surface(surface); |
| 2049 | |
| 2050 | if (!sibling) { |
| 2051 | wl_resource_post_error(sub->resource, |
| 2052 | WL_SUBSURFACE_ERROR_BAD_SURFACE, |
| 2053 | "%s: wl_surface@%d is not a parent or sibling", |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2054 | request, wl_resource_get_id(surface->resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2055 | return NULL; |
| 2056 | } |
| 2057 | |
| 2058 | if (sibling->parent != sub->parent) { |
| 2059 | wl_resource_post_error(sub->resource, |
| 2060 | WL_SUBSURFACE_ERROR_BAD_SURFACE, |
| 2061 | "%s: wl_surface@%d has a different parent", |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2062 | request, wl_resource_get_id(surface->resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2063 | return NULL; |
| 2064 | } |
| 2065 | |
| 2066 | return sibling; |
| 2067 | } |
| 2068 | |
| 2069 | static void |
| 2070 | subsurface_place_above(struct wl_client *client, |
| 2071 | struct wl_resource *resource, |
| 2072 | struct wl_resource *sibling_resource) |
| 2073 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 2074 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2075 | struct weston_surface *surface = |
| 2076 | wl_resource_get_user_data(sibling_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2077 | struct weston_subsurface *sibling; |
| 2078 | |
| 2079 | if (!sub) |
| 2080 | return; |
| 2081 | |
| 2082 | sibling = subsurface_sibling_check(sub, surface, "place_above"); |
| 2083 | if (!sibling) |
| 2084 | return; |
| 2085 | |
| 2086 | wl_list_remove(&sub->parent_link_pending); |
| 2087 | wl_list_insert(sibling->parent_link_pending.prev, |
| 2088 | &sub->parent_link_pending); |
| 2089 | } |
| 2090 | |
| 2091 | static void |
| 2092 | subsurface_place_below(struct wl_client *client, |
| 2093 | struct wl_resource *resource, |
| 2094 | struct wl_resource *sibling_resource) |
| 2095 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 2096 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2097 | struct weston_surface *surface = |
| 2098 | wl_resource_get_user_data(sibling_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2099 | struct weston_subsurface *sibling; |
| 2100 | |
| 2101 | if (!sub) |
| 2102 | return; |
| 2103 | |
| 2104 | sibling = subsurface_sibling_check(sub, surface, "place_below"); |
| 2105 | if (!sibling) |
| 2106 | return; |
| 2107 | |
| 2108 | wl_list_remove(&sub->parent_link_pending); |
| 2109 | wl_list_insert(&sibling->parent_link_pending, |
| 2110 | &sub->parent_link_pending); |
| 2111 | } |
| 2112 | |
| 2113 | static void |
| 2114 | subsurface_set_sync(struct wl_client *client, struct wl_resource *resource) |
| 2115 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 2116 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2117 | |
| 2118 | if (sub) |
| 2119 | sub->synchronized = 1; |
| 2120 | } |
| 2121 | |
| 2122 | static void |
| 2123 | subsurface_set_desync(struct wl_client *client, struct wl_resource *resource) |
| 2124 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 2125 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2126 | |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 2127 | if (sub && sub->synchronized) { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2128 | sub->synchronized = 0; |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 2129 | |
| 2130 | /* If sub became effectively desynchronized, flush. */ |
| 2131 | if (!weston_subsurface_is_synchronized(sub)) |
| 2132 | weston_subsurface_synchronized_commit(sub); |
| 2133 | } |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2134 | } |
| 2135 | |
| 2136 | static void |
| 2137 | weston_subsurface_cache_init(struct weston_subsurface *sub) |
| 2138 | { |
| 2139 | pixman_region32_init(&sub->cached.damage); |
| 2140 | pixman_region32_init(&sub->cached.opaque); |
| 2141 | pixman_region32_init(&sub->cached.input); |
| 2142 | wl_list_init(&sub->cached.frame_callback_list); |
| 2143 | sub->cached.buffer_ref.buffer = NULL; |
| 2144 | } |
| 2145 | |
| 2146 | static void |
| 2147 | weston_subsurface_cache_fini(struct weston_subsurface *sub) |
| 2148 | { |
| 2149 | struct weston_frame_callback *cb, *tmp; |
| 2150 | |
| 2151 | wl_list_for_each_safe(cb, tmp, &sub->cached.frame_callback_list, link) |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 2152 | wl_resource_destroy(cb->resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2153 | |
| 2154 | weston_buffer_reference(&sub->cached.buffer_ref, NULL); |
| 2155 | pixman_region32_fini(&sub->cached.damage); |
| 2156 | pixman_region32_fini(&sub->cached.opaque); |
| 2157 | pixman_region32_fini(&sub->cached.input); |
| 2158 | } |
| 2159 | |
| 2160 | static void |
| 2161 | weston_subsurface_unlink_parent(struct weston_subsurface *sub) |
| 2162 | { |
| 2163 | wl_list_remove(&sub->parent_link); |
| 2164 | wl_list_remove(&sub->parent_link_pending); |
| 2165 | wl_list_remove(&sub->parent_destroy_listener.link); |
| 2166 | sub->parent = NULL; |
| 2167 | } |
| 2168 | |
| 2169 | static void |
| 2170 | weston_subsurface_destroy(struct weston_subsurface *sub); |
| 2171 | |
| 2172 | static void |
| 2173 | subsurface_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 2174 | { |
| 2175 | struct weston_subsurface *sub = |
| 2176 | container_of(listener, struct weston_subsurface, |
| 2177 | surface_destroy_listener); |
| 2178 | assert(data == &sub->surface->resource); |
| 2179 | |
| 2180 | /* The protocol object (wl_resource) is left inert. */ |
| 2181 | if (sub->resource) |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 2182 | wl_resource_set_user_data(sub->resource, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2183 | |
| 2184 | weston_subsurface_destroy(sub); |
| 2185 | } |
| 2186 | |
| 2187 | static void |
| 2188 | subsurface_handle_parent_destroy(struct wl_listener *listener, void *data) |
| 2189 | { |
| 2190 | struct weston_subsurface *sub = |
| 2191 | container_of(listener, struct weston_subsurface, |
| 2192 | parent_destroy_listener); |
| 2193 | assert(data == &sub->parent->resource); |
| 2194 | assert(sub->surface != sub->parent); |
| 2195 | |
| 2196 | if (weston_surface_is_mapped(sub->surface)) |
| 2197 | weston_surface_unmap(sub->surface); |
| 2198 | |
| 2199 | weston_subsurface_unlink_parent(sub); |
| 2200 | } |
| 2201 | |
| 2202 | static void |
| 2203 | subsurface_resource_destroy(struct wl_resource *resource) |
| 2204 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 2205 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2206 | |
| 2207 | if (sub) |
| 2208 | weston_subsurface_destroy(sub); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2209 | } |
| 2210 | |
| 2211 | static void |
| 2212 | subsurface_destroy(struct wl_client *client, struct wl_resource *resource) |
| 2213 | { |
| 2214 | wl_resource_destroy(resource); |
| 2215 | } |
| 2216 | |
| 2217 | static void |
| 2218 | weston_subsurface_link_parent(struct weston_subsurface *sub, |
| 2219 | struct weston_surface *parent) |
| 2220 | { |
| 2221 | sub->parent = parent; |
| 2222 | sub->parent_destroy_listener.notify = subsurface_handle_parent_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2223 | wl_signal_add(&parent->destroy_signal, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2224 | &sub->parent_destroy_listener); |
| 2225 | |
| 2226 | wl_list_insert(&parent->subsurface_list, &sub->parent_link); |
| 2227 | wl_list_insert(&parent->subsurface_list_pending, |
| 2228 | &sub->parent_link_pending); |
| 2229 | } |
| 2230 | |
| 2231 | static void |
| 2232 | weston_subsurface_link_surface(struct weston_subsurface *sub, |
| 2233 | struct weston_surface *surface) |
| 2234 | { |
| 2235 | sub->surface = surface; |
| 2236 | sub->surface_destroy_listener.notify = |
| 2237 | subsurface_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2238 | wl_signal_add(&surface->destroy_signal, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2239 | &sub->surface_destroy_listener); |
| 2240 | } |
| 2241 | |
| 2242 | static void |
| 2243 | weston_subsurface_destroy(struct weston_subsurface *sub) |
| 2244 | { |
| 2245 | assert(sub->surface); |
| 2246 | |
| 2247 | if (sub->resource) { |
| 2248 | assert(weston_surface_to_subsurface(sub->surface) == sub); |
| 2249 | assert(sub->parent_destroy_listener.notify == |
| 2250 | subsurface_handle_parent_destroy); |
| 2251 | |
| 2252 | weston_surface_set_transform_parent(sub->surface, NULL); |
| 2253 | if (sub->parent) |
| 2254 | weston_subsurface_unlink_parent(sub); |
| 2255 | |
| 2256 | weston_subsurface_cache_fini(sub); |
| 2257 | |
| 2258 | sub->surface->configure = NULL; |
| 2259 | sub->surface->configure_private = NULL; |
| 2260 | } else { |
| 2261 | /* the dummy weston_subsurface for the parent itself */ |
| 2262 | assert(sub->parent_destroy_listener.notify == NULL); |
| 2263 | wl_list_remove(&sub->parent_link); |
| 2264 | wl_list_remove(&sub->parent_link_pending); |
| 2265 | } |
| 2266 | |
| 2267 | wl_list_remove(&sub->surface_destroy_listener.link); |
| 2268 | free(sub); |
| 2269 | } |
| 2270 | |
| 2271 | static const struct wl_subsurface_interface subsurface_implementation = { |
| 2272 | subsurface_destroy, |
| 2273 | subsurface_set_position, |
| 2274 | subsurface_place_above, |
| 2275 | subsurface_place_below, |
| 2276 | subsurface_set_sync, |
| 2277 | subsurface_set_desync |
| 2278 | }; |
| 2279 | |
| 2280 | static struct weston_subsurface * |
| 2281 | weston_subsurface_create(uint32_t id, struct weston_surface *surface, |
| 2282 | struct weston_surface *parent) |
| 2283 | { |
| 2284 | struct weston_subsurface *sub; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2285 | struct wl_client *client = wl_resource_get_client(surface->resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2286 | |
| 2287 | sub = calloc(1, sizeof *sub); |
| 2288 | if (!sub) |
| 2289 | return NULL; |
| 2290 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2291 | sub->resource = wl_client_add_object(client, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2292 | &wl_subsurface_interface, |
| 2293 | &subsurface_implementation, |
| 2294 | id, sub); |
| 2295 | if (!sub->resource) { |
| 2296 | free(sub); |
| 2297 | return NULL; |
| 2298 | } |
| 2299 | |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 2300 | wl_resource_set_destructor(sub->resource, subsurface_resource_destroy); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2301 | weston_subsurface_link_surface(sub, surface); |
| 2302 | weston_subsurface_link_parent(sub, parent); |
| 2303 | weston_subsurface_cache_init(sub); |
| 2304 | sub->synchronized = 1; |
| 2305 | weston_surface_set_transform_parent(surface, parent); |
| 2306 | |
| 2307 | return sub; |
| 2308 | } |
| 2309 | |
| 2310 | /* Create a dummy subsurface for having the parent itself in its |
| 2311 | * sub-surface lists. Makes stacking order manipulation easy. |
| 2312 | */ |
| 2313 | static struct weston_subsurface * |
| 2314 | weston_subsurface_create_for_parent(struct weston_surface *parent) |
| 2315 | { |
| 2316 | struct weston_subsurface *sub; |
| 2317 | |
| 2318 | sub = calloc(1, sizeof *sub); |
| 2319 | if (!sub) |
| 2320 | return NULL; |
| 2321 | |
| 2322 | weston_subsurface_link_surface(sub, parent); |
| 2323 | sub->parent = parent; |
| 2324 | wl_list_insert(&parent->subsurface_list, &sub->parent_link); |
| 2325 | wl_list_insert(&parent->subsurface_list_pending, |
| 2326 | &sub->parent_link_pending); |
| 2327 | |
| 2328 | return sub; |
| 2329 | } |
| 2330 | |
| 2331 | static void |
| 2332 | subcompositor_get_subsurface(struct wl_client *client, |
| 2333 | struct wl_resource *resource, |
| 2334 | uint32_t id, |
| 2335 | struct wl_resource *surface_resource, |
| 2336 | struct wl_resource *parent_resource) |
| 2337 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2338 | struct weston_surface *surface = |
| 2339 | wl_resource_get_user_data(surface_resource); |
| 2340 | struct weston_surface *parent = |
| 2341 | wl_resource_get_user_data(parent_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2342 | struct weston_subsurface *sub; |
| 2343 | static const char where[] = "get_subsurface: wl_subsurface@"; |
| 2344 | |
| 2345 | if (surface == parent) { |
| 2346 | wl_resource_post_error(resource, |
| 2347 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 2348 | "%s%d: wl_surface@%d cannot be its own parent", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 2349 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2350 | return; |
| 2351 | } |
| 2352 | |
| 2353 | if (weston_surface_to_subsurface(surface)) { |
| 2354 | wl_resource_post_error(resource, |
| 2355 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 2356 | "%s%d: wl_surface@%d is already a sub-surface", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 2357 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2358 | return; |
| 2359 | } |
| 2360 | |
| 2361 | if (surface->configure) { |
| 2362 | wl_resource_post_error(resource, |
| 2363 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 2364 | "%s%d: wl_surface@%d already has a role", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 2365 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2366 | return; |
| 2367 | } |
| 2368 | |
Pekka Paalanen | 86c8ca0 | 2013-05-17 16:46:07 +0300 | [diff] [blame] | 2369 | if (weston_surface_get_main_surface(parent) == surface) { |
| 2370 | wl_resource_post_error(resource, |
| 2371 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 2372 | "%s%d: wl_surface@%d is an ancestor of parent", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 2373 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | 86c8ca0 | 2013-05-17 16:46:07 +0300 | [diff] [blame] | 2374 | return; |
| 2375 | } |
| 2376 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2377 | /* make sure the parent is in its own list */ |
| 2378 | if (wl_list_empty(&parent->subsurface_list)) { |
| 2379 | if (!weston_subsurface_create_for_parent(parent)) { |
| 2380 | wl_resource_post_no_memory(resource); |
| 2381 | return; |
| 2382 | } |
| 2383 | } |
| 2384 | |
| 2385 | sub = weston_subsurface_create(id, surface, parent); |
| 2386 | if (!sub) { |
| 2387 | wl_resource_post_no_memory(resource); |
| 2388 | return; |
| 2389 | } |
| 2390 | |
| 2391 | surface->configure = subsurface_configure; |
| 2392 | surface->configure_private = sub; |
| 2393 | } |
| 2394 | |
| 2395 | static void |
| 2396 | subcompositor_destroy(struct wl_client *client, struct wl_resource *resource) |
| 2397 | { |
| 2398 | wl_resource_destroy(resource); |
| 2399 | } |
| 2400 | |
| 2401 | static const struct wl_subcompositor_interface subcompositor_interface = { |
| 2402 | subcompositor_destroy, |
| 2403 | subcompositor_get_subsurface |
| 2404 | }; |
| 2405 | |
| 2406 | static void |
| 2407 | bind_subcompositor(struct wl_client *client, |
| 2408 | void *data, uint32_t version, uint32_t id) |
| 2409 | { |
| 2410 | struct weston_compositor *compositor = data; |
| 2411 | |
| 2412 | wl_client_add_object(client, &wl_subcompositor_interface, |
| 2413 | &subcompositor_interface, id, compositor); |
| 2414 | } |
| 2415 | |
| 2416 | static void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 2417 | weston_compositor_dpms(struct weston_compositor *compositor, |
| 2418 | enum dpms_enum state) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2419 | { |
| 2420 | struct weston_output *output; |
| 2421 | |
| 2422 | wl_list_for_each(output, &compositor->output_list, link) |
| 2423 | if (output->set_dpms) |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 2424 | output->set_dpms(output, state); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2425 | } |
| 2426 | |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 2427 | WL_EXPORT void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 2428 | weston_compositor_wake(struct weston_compositor *compositor) |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 2429 | { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 2430 | switch (compositor->state) { |
| 2431 | case WESTON_COMPOSITOR_SLEEPING: |
| 2432 | weston_compositor_dpms(compositor, WESTON_DPMS_ON); |
| 2433 | /* fall through */ |
| 2434 | case WESTON_COMPOSITOR_IDLE: |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 2435 | case WESTON_COMPOSITOR_OFFSCREEN: |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 2436 | wl_signal_emit(&compositor->wake_signal, compositor); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 2437 | /* fall through */ |
| 2438 | default: |
| 2439 | compositor->state = WESTON_COMPOSITOR_ACTIVE; |
| 2440 | wl_event_source_timer_update(compositor->idle_source, |
| 2441 | compositor->idle_time * 1000); |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 2442 | } |
| 2443 | } |
| 2444 | |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 2445 | WL_EXPORT void |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 2446 | weston_compositor_offscreen(struct weston_compositor *compositor) |
| 2447 | { |
| 2448 | switch (compositor->state) { |
| 2449 | case WESTON_COMPOSITOR_OFFSCREEN: |
| 2450 | return; |
| 2451 | case WESTON_COMPOSITOR_SLEEPING: |
| 2452 | weston_compositor_dpms(compositor, WESTON_DPMS_ON); |
| 2453 | /* fall through */ |
| 2454 | default: |
| 2455 | compositor->state = WESTON_COMPOSITOR_OFFSCREEN; |
| 2456 | wl_event_source_timer_update(compositor->idle_source, 0); |
| 2457 | } |
| 2458 | } |
| 2459 | |
| 2460 | WL_EXPORT void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 2461 | weston_compositor_sleep(struct weston_compositor *compositor) |
| 2462 | { |
| 2463 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING) |
| 2464 | return; |
| 2465 | |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 2466 | wl_event_source_timer_update(compositor->idle_source, 0); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 2467 | compositor->state = WESTON_COMPOSITOR_SLEEPING; |
| 2468 | weston_compositor_dpms(compositor, WESTON_DPMS_OFF); |
| 2469 | } |
| 2470 | |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2471 | static int |
| 2472 | idle_handler(void *data) |
| 2473 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2474 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2475 | |
| 2476 | if (compositor->idle_inhibit) |
| 2477 | return 1; |
| 2478 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 2479 | compositor->state = WESTON_COMPOSITOR_IDLE; |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 2480 | wl_signal_emit(&compositor->idle_signal, compositor); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2481 | |
| 2482 | return 1; |
| 2483 | } |
| 2484 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 2485 | WL_EXPORT void |
| 2486 | weston_plane_init(struct weston_plane *plane, int32_t x, int32_t y) |
| 2487 | { |
| 2488 | pixman_region32_init(&plane->damage); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2489 | pixman_region32_init(&plane->clip); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 2490 | plane->x = x; |
| 2491 | plane->y = y; |
| 2492 | } |
| 2493 | |
| 2494 | WL_EXPORT void |
| 2495 | weston_plane_release(struct weston_plane *plane) |
| 2496 | { |
| 2497 | pixman_region32_fini(&plane->damage); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2498 | pixman_region32_fini(&plane->clip); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 2499 | } |
| 2500 | |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2501 | WL_EXPORT void |
| 2502 | weston_compositor_stack_plane(struct weston_compositor *ec, |
| 2503 | struct weston_plane *plane, |
| 2504 | struct weston_plane *above) |
| 2505 | { |
| 2506 | if (above) |
| 2507 | wl_list_insert(above->link.prev, &plane->link); |
| 2508 | else |
| 2509 | wl_list_insert(&ec->plane_list, &plane->link); |
| 2510 | } |
| 2511 | |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 2512 | static void unbind_resource(struct wl_resource *resource) |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 2513 | { |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 2514 | wl_list_remove(wl_resource_get_link(resource)); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 2515 | } |
| 2516 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 2517 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 2518 | bind_output(struct wl_client *client, |
| 2519 | void *data, uint32_t version, uint32_t id) |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 2520 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2521 | struct weston_output *output = data; |
| 2522 | struct weston_mode *mode; |
Kristian Høgsberg | fd07fb7 | 2011-08-29 15:03:09 -0400 | [diff] [blame] | 2523 | struct wl_resource *resource; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 2524 | |
Kristian Høgsberg | fd07fb7 | 2011-08-29 15:03:09 -0400 | [diff] [blame] | 2525 | resource = wl_client_add_object(client, |
| 2526 | &wl_output_interface, NULL, id, data); |
| 2527 | |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 2528 | wl_list_insert(&output->resource_list, wl_resource_get_link(resource)); |
| 2529 | wl_resource_set_destructor(resource, unbind_resource); |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 2530 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 2531 | wl_output_send_geometry(resource, |
| 2532 | output->x, |
| 2533 | output->y, |
| 2534 | output->mm_width, |
| 2535 | output->mm_height, |
| 2536 | output->subpixel, |
Kristian Høgsberg | 0e69647 | 2012-07-22 15:49:57 -0400 | [diff] [blame] | 2537 | output->make, output->model, |
Kristian Høgsberg | 05890dc | 2012-08-10 10:09:20 -0400 | [diff] [blame] | 2538 | output->transform); |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 2539 | if (version >= 2) |
| 2540 | wl_output_send_scale(resource, |
| 2541 | output->scale); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 2542 | |
| 2543 | wl_list_for_each (mode, &output->mode_list, link) { |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 2544 | wl_output_send_mode(resource, |
| 2545 | mode->flags, |
| 2546 | mode->width, |
| 2547 | mode->height, |
| 2548 | mode->refresh); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 2549 | } |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 2550 | |
| 2551 | if (version >= 2) |
| 2552 | wl_output_send_done(resource); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 2553 | } |
| 2554 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2555 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2556 | weston_output_destroy(struct weston_output *output) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 2557 | { |
Benjamin Franzke | b687940 | 2012-04-10 18:28:54 +0200 | [diff] [blame] | 2558 | struct weston_compositor *c = output->compositor; |
| 2559 | |
Richard Hughes | 64ddde1 | 2013-05-01 21:52:10 +0100 | [diff] [blame] | 2560 | wl_signal_emit(&output->destroy_signal, output); |
| 2561 | |
Richard Hughes | afe690c | 2013-05-02 10:10:04 +0100 | [diff] [blame] | 2562 | free(output->name); |
Kristian Høgsberg | e75cb7f | 2011-06-21 15:27:41 -0400 | [diff] [blame] | 2563 | pixman_region32_fini(&output->region); |
Ander Conselvan de Oliveira | b8fcca9 | 2012-11-16 17:23:52 +0200 | [diff] [blame] | 2564 | pixman_region32_fini(&output->previous_damage); |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 2565 | output->compositor->output_id_pool &= ~(1 << output->id); |
Benjamin Franzke | b687940 | 2012-04-10 18:28:54 +0200 | [diff] [blame] | 2566 | |
| 2567 | wl_display_remove_global(c->wl_display, output->global); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2568 | } |
| 2569 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2570 | static void |
| 2571 | weston_output_compute_transform(struct weston_output *output) |
| 2572 | { |
| 2573 | struct weston_matrix transform; |
| 2574 | int flip; |
| 2575 | |
| 2576 | weston_matrix_init(&transform); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 2577 | transform.type = WESTON_MATRIX_TRANSFORM_ROTATE; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2578 | |
| 2579 | switch(output->transform) { |
| 2580 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 2581 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 2582 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 2583 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 2584 | transform.type |= WESTON_MATRIX_TRANSFORM_OTHER; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2585 | flip = -1; |
| 2586 | break; |
| 2587 | default: |
| 2588 | flip = 1; |
| 2589 | break; |
| 2590 | } |
| 2591 | |
| 2592 | switch(output->transform) { |
| 2593 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 2594 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 2595 | transform.d[0] = flip; |
| 2596 | transform.d[1] = 0; |
| 2597 | transform.d[4] = 0; |
| 2598 | transform.d[5] = 1; |
| 2599 | break; |
| 2600 | case WL_OUTPUT_TRANSFORM_90: |
| 2601 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 2602 | transform.d[0] = 0; |
| 2603 | transform.d[1] = -flip; |
| 2604 | transform.d[4] = 1; |
| 2605 | transform.d[5] = 0; |
| 2606 | break; |
| 2607 | case WL_OUTPUT_TRANSFORM_180: |
| 2608 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 2609 | transform.d[0] = -flip; |
| 2610 | transform.d[1] = 0; |
| 2611 | transform.d[4] = 0; |
| 2612 | transform.d[5] = -1; |
| 2613 | break; |
| 2614 | case WL_OUTPUT_TRANSFORM_270: |
| 2615 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 2616 | transform.d[0] = 0; |
| 2617 | transform.d[1] = flip; |
| 2618 | transform.d[4] = -1; |
| 2619 | transform.d[5] = 0; |
| 2620 | break; |
| 2621 | default: |
| 2622 | break; |
| 2623 | } |
| 2624 | |
| 2625 | weston_matrix_multiply(&output->matrix, &transform); |
| 2626 | } |
| 2627 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2628 | WL_EXPORT void |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2629 | weston_output_update_matrix(struct weston_output *output) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2630 | { |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 2631 | float magnification; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2632 | struct weston_matrix camera; |
| 2633 | struct weston_matrix modelview; |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 2634 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2635 | weston_matrix_init(&output->matrix); |
| 2636 | weston_matrix_translate(&output->matrix, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2637 | -(output->x + (output->border.right + output->width - output->border.left) / 2.0), |
| 2638 | -(output->y + (output->border.bottom + output->height - output->border.top) / 2.0), 0); |
Benjamin Franzke | 1b765ff | 2011-02-18 16:51:37 +0100 | [diff] [blame] | 2639 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2640 | weston_matrix_scale(&output->matrix, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2641 | 2.0 / (output->width + output->border.left + output->border.right), |
| 2642 | -2.0 / (output->height + output->border.top + output->border.bottom), 1); |
| 2643 | |
| 2644 | weston_output_compute_transform(output); |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 2645 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2646 | if (output->zoom.active) { |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 2647 | magnification = 1 / (1 - output->zoom.spring_z.current); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2648 | weston_matrix_init(&camera); |
| 2649 | weston_matrix_init(&modelview); |
Scott Moreau | 8dacaab | 2012-06-17 18:10:58 -0600 | [diff] [blame] | 2650 | weston_output_update_zoom(output, output->zoom.type); |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 2651 | weston_matrix_translate(&camera, output->zoom.trans_x, |
Kristian Høgsberg | 99fd101 | 2012-08-10 09:57:56 -0400 | [diff] [blame] | 2652 | -output->zoom.trans_y, 0); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2653 | weston_matrix_invert(&modelview, &camera); |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 2654 | weston_matrix_scale(&modelview, magnification, magnification, 1.0); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2655 | weston_matrix_multiply(&output->matrix, &modelview); |
| 2656 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2657 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2658 | output->dirty = 0; |
| 2659 | } |
| 2660 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2661 | static void |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 2662 | weston_output_transform_scale_init(struct weston_output *output, uint32_t transform, uint32_t scale) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2663 | { |
| 2664 | output->transform = transform; |
| 2665 | |
| 2666 | switch (transform) { |
| 2667 | case WL_OUTPUT_TRANSFORM_90: |
| 2668 | case WL_OUTPUT_TRANSFORM_270: |
| 2669 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 2670 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 2671 | /* Swap width and height */ |
| 2672 | output->width = output->current->height; |
| 2673 | output->height = output->current->width; |
| 2674 | break; |
| 2675 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 2676 | case WL_OUTPUT_TRANSFORM_180: |
| 2677 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 2678 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 2679 | output->width = output->current->width; |
| 2680 | output->height = output->current->height; |
| 2681 | break; |
| 2682 | default: |
| 2683 | break; |
| 2684 | } |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2685 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 2686 | output->scale = scale; |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 2687 | output->width /= scale; |
| 2688 | output->height /= scale; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 2689 | } |
| 2690 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2691 | WL_EXPORT void |
| 2692 | weston_output_move(struct weston_output *output, int x, int y) |
| 2693 | { |
| 2694 | output->x = x; |
| 2695 | output->y = y; |
| 2696 | |
Ander Conselvan de Oliveira | b8fcca9 | 2012-11-16 17:23:52 +0200 | [diff] [blame] | 2697 | pixman_region32_init(&output->previous_damage); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2698 | pixman_region32_init_rect(&output->region, x, y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 2699 | output->width, |
| 2700 | output->height); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2701 | } |
| 2702 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2703 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2704 | weston_output_init(struct weston_output *output, struct weston_compositor *c, |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 2705 | int x, int y, int mm_width, int mm_height, uint32_t transform, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 2706 | int32_t scale) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2707 | { |
| 2708 | output->compositor = c; |
| 2709 | output->x = x; |
| 2710 | output->y = y; |
Kristian Høgsberg | 546a812 | 2012-02-01 07:45:51 -0500 | [diff] [blame] | 2711 | output->border.top = 0; |
| 2712 | output->border.bottom = 0; |
| 2713 | output->border.left = 0; |
| 2714 | output->border.right = 0; |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 2715 | output->mm_width = mm_width; |
| 2716 | output->mm_height = mm_height; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2717 | output->dirty = 1; |
Alexander Larsson | e32c376 | 2013-05-28 16:23:37 +0200 | [diff] [blame] | 2718 | output->origin_scale = scale; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2719 | |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 2720 | weston_output_transform_scale_init(output, transform, scale); |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 2721 | weston_output_init_zoom(output); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2722 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2723 | weston_output_move(output, x, y); |
Benjamin Franzke | 78db848 | 2012-04-10 18:35:33 +0200 | [diff] [blame] | 2724 | weston_output_damage(output); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 2725 | |
Kristian Høgsberg | 5fb70bf | 2012-05-24 12:29:46 -0400 | [diff] [blame] | 2726 | wl_signal_init(&output->frame_signal); |
Richard Hughes | 64ddde1 | 2013-05-01 21:52:10 +0100 | [diff] [blame] | 2727 | wl_signal_init(&output->destroy_signal); |
Scott Moreau | 9d1b112 | 2012-06-08 19:40:53 -0600 | [diff] [blame] | 2728 | wl_list_init(&output->animation_list); |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 2729 | wl_list_init(&output->resource_list); |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 2730 | |
Casey Dahlin | 58ba137 | 2012-04-19 22:50:08 -0400 | [diff] [blame] | 2731 | output->id = ffs(~output->compositor->output_id_pool) - 1; |
| 2732 | output->compositor->output_id_pool |= 1 << output->id; |
| 2733 | |
Benjamin Franzke | b687940 | 2012-04-10 18:28:54 +0200 | [diff] [blame] | 2734 | output->global = |
| 2735 | wl_display_add_global(c->wl_display, &wl_output_interface, |
| 2736 | output, bind_output); |
Richard Hughes | 59d5da7 | 2013-05-01 21:52:11 +0100 | [diff] [blame] | 2737 | wl_signal_emit(&c->output_created_signal, output); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2738 | } |
| 2739 | |
Benjamin Franzke | 315b3dc | 2011-03-08 11:32:57 +0100 | [diff] [blame] | 2740 | static void |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 2741 | compositor_bind(struct wl_client *client, |
| 2742 | void *data, uint32_t version, uint32_t id) |
| 2743 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2744 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 2745 | |
| 2746 | wl_client_add_object(client, &wl_compositor_interface, |
| 2747 | &compositor_interface, id, compositor); |
| 2748 | } |
| 2749 | |
Kristian Høgsberg | fc9c5e0 | 2012-06-08 16:45:33 -0400 | [diff] [blame] | 2750 | static void |
Martin Minarik | f12c287 | 2012-06-11 00:57:39 +0200 | [diff] [blame] | 2751 | log_uname(void) |
| 2752 | { |
| 2753 | struct utsname usys; |
| 2754 | |
| 2755 | uname(&usys); |
| 2756 | |
| 2757 | weston_log("OS: %s, %s, %s, %s\n", usys.sysname, usys.release, |
| 2758 | usys.version, usys.machine); |
| 2759 | } |
| 2760 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 2761 | WL_EXPORT int |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 2762 | weston_environment_get_fd(const char *env) |
| 2763 | { |
| 2764 | char *e, *end; |
| 2765 | int fd, flags; |
| 2766 | |
| 2767 | e = getenv(env); |
| 2768 | if (!e) |
| 2769 | return -1; |
| 2770 | fd = strtol(e, &end, 0); |
| 2771 | if (*end != '\0') |
| 2772 | return -1; |
| 2773 | |
| 2774 | flags = fcntl(fd, F_GETFD); |
| 2775 | if (flags == -1) |
| 2776 | return -1; |
| 2777 | |
| 2778 | fcntl(fd, F_SETFD, flags | FD_CLOEXEC); |
| 2779 | unsetenv(env); |
| 2780 | |
| 2781 | return fd; |
| 2782 | } |
| 2783 | |
| 2784 | WL_EXPORT int |
Daniel Stone | baf4359 | 2012-06-01 11:11:10 -0400 | [diff] [blame] | 2785 | weston_compositor_init(struct weston_compositor *ec, |
| 2786 | struct wl_display *display, |
Kristian Høgsberg | 4172f66 | 2013-02-20 15:27:49 -0500 | [diff] [blame] | 2787 | int *argc, char *argv[], |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 2788 | struct weston_config *config) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 2789 | { |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 2790 | struct wl_event_loop *loop; |
Daniel Stone | e2ef43a | 2012-06-01 12:14:05 +0100 | [diff] [blame] | 2791 | struct xkb_rule_names xkb_names; |
Kristian Høgsberg | 6a04791 | 2013-05-23 15:56:29 -0400 | [diff] [blame] | 2792 | struct weston_config_section *s; |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 2793 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 2794 | ec->config = config; |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 2795 | ec->wl_display = display; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 2796 | wl_signal_init(&ec->destroy_signal); |
| 2797 | wl_signal_init(&ec->activate_signal); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 2798 | wl_signal_init(&ec->transform_signal); |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 2799 | wl_signal_init(&ec->kill_signal); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 2800 | wl_signal_init(&ec->idle_signal); |
| 2801 | wl_signal_init(&ec->wake_signal); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 2802 | wl_signal_init(&ec->show_input_panel_signal); |
| 2803 | wl_signal_init(&ec->hide_input_panel_signal); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 2804 | wl_signal_init(&ec->update_input_panel_signal); |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 2805 | wl_signal_init(&ec->seat_created_signal); |
Richard Hughes | 59d5da7 | 2013-05-01 21:52:11 +0100 | [diff] [blame] | 2806 | wl_signal_init(&ec->output_created_signal); |
Benjamin Franzke | bfeda13 | 2012-01-30 14:04:04 +0100 | [diff] [blame] | 2807 | ec->launcher_sock = weston_environment_get_fd("WESTON_LAUNCHER_SOCK"); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 2808 | |
Casey Dahlin | 58ba137 | 2012-04-19 22:50:08 -0400 | [diff] [blame] | 2809 | ec->output_id_pool = 0; |
| 2810 | |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 2811 | if (!wl_display_add_global(display, &wl_compositor_interface, |
| 2812 | ec, compositor_bind)) |
| 2813 | return -1; |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 2814 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2815 | if (!wl_display_add_global(display, &wl_subcompositor_interface, |
| 2816 | ec, bind_subcompositor)) |
| 2817 | return -1; |
| 2818 | |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 2819 | wl_list_init(&ec->surface_list); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2820 | wl_list_init(&ec->plane_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 2821 | wl_list_init(&ec->layer_list); |
| 2822 | wl_list_init(&ec->seat_list); |
| 2823 | wl_list_init(&ec->output_list); |
| 2824 | wl_list_init(&ec->key_binding_list); |
| 2825 | wl_list_init(&ec->button_binding_list); |
| 2826 | wl_list_init(&ec->axis_binding_list); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 2827 | wl_list_init(&ec->debug_binding_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 2828 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 2829 | weston_plane_init(&ec->primary_plane, 0, 0); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2830 | weston_compositor_stack_plane(ec, &ec->primary_plane, NULL); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 2831 | |
Kristian Høgsberg | 6a04791 | 2013-05-23 15:56:29 -0400 | [diff] [blame] | 2832 | s = weston_config_get_section(ec->config, "keyboard", NULL, NULL); |
| 2833 | weston_config_section_get_string(s, "keymap_rules", |
| 2834 | (char **) &xkb_names.rules, NULL); |
| 2835 | weston_config_section_get_string(s, "keymap_model", |
| 2836 | (char **) &xkb_names.model, NULL); |
| 2837 | weston_config_section_get_string(s, "keymap_layout", |
| 2838 | (char **) &xkb_names.layout, NULL); |
| 2839 | weston_config_section_get_string(s, "keymap_variant", |
| 2840 | (char **) &xkb_names.variant, NULL); |
| 2841 | weston_config_section_get_string(s, "keymap_options", |
| 2842 | (char **) &xkb_names.options, NULL); |
Kristian Høgsberg | 2f07ef6 | 2013-02-16 14:29:24 -0500 | [diff] [blame] | 2843 | if (weston_compositor_xkb_init(ec, &xkb_names) < 0) |
| 2844 | return -1; |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 2845 | |
| 2846 | ec->ping_handler = NULL; |
| 2847 | |
| 2848 | screenshooter_create(ec); |
| 2849 | text_cursor_position_notifier_create(ec); |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 2850 | text_backend_init(ec); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 2851 | |
| 2852 | wl_data_device_manager_init(ec->wl_display); |
| 2853 | |
Kristian Høgsberg | 9629fe3 | 2012-03-26 15:56:39 -0400 | [diff] [blame] | 2854 | wl_display_init_shm(display); |
Kristian Høgsberg | b5819dc | 2011-04-25 15:08:20 -0400 | [diff] [blame] | 2855 | |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 2856 | loop = wl_display_get_event_loop(ec->wl_display); |
| 2857 | ec->idle_source = wl_event_loop_add_timer(loop, idle_handler, ec); |
| 2858 | wl_event_source_timer_update(ec->idle_source, ec->idle_time * 1000); |
| 2859 | |
| 2860 | ec->input_loop = wl_event_loop_create(); |
| 2861 | |
Kristian Høgsberg | 861a50c | 2012-09-05 22:02:22 -0400 | [diff] [blame] | 2862 | weston_layer_init(&ec->fade_layer, &ec->layer_list); |
| 2863 | weston_layer_init(&ec->cursor_layer, &ec->fade_layer.link); |
| 2864 | |
| 2865 | weston_compositor_schedule_repaint(ec); |
| 2866 | |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 2867 | return 0; |
| 2868 | } |
| 2869 | |
Benjamin Franzke | b826302 | 2011-08-30 11:32:47 +0200 | [diff] [blame] | 2870 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2871 | weston_compositor_shutdown(struct weston_compositor *ec) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 2872 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2873 | struct weston_output *output, *next; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 2874 | |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 2875 | wl_event_source_remove(ec->idle_source); |
Jonas Ådahl | c97af92 | 2012-03-28 22:36:09 +0200 | [diff] [blame] | 2876 | if (ec->input_loop_source) |
| 2877 | wl_event_source_remove(ec->input_loop_source); |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 2878 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 2879 | /* Destroy all outputs associated with this compositor */ |
Tiago Vignatti | b303a1d | 2011-12-18 22:27:40 +0200 | [diff] [blame] | 2880 | wl_list_for_each_safe(output, next, &ec->output_list, link) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 2881 | output->destroy(output); |
Pekka Paalanen | 4738f3b | 2012-01-02 15:47:07 +0200 | [diff] [blame] | 2882 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 2883 | weston_binding_list_destroy_all(&ec->key_binding_list); |
| 2884 | weston_binding_list_destroy_all(&ec->button_binding_list); |
| 2885 | weston_binding_list_destroy_all(&ec->axis_binding_list); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 2886 | weston_binding_list_destroy_all(&ec->debug_binding_list); |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 2887 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 2888 | weston_plane_release(&ec->primary_plane); |
| 2889 | |
Jonas Ådahl | c97af92 | 2012-03-28 22:36:09 +0200 | [diff] [blame] | 2890 | wl_event_loop_destroy(ec->input_loop); |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 2891 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 2892 | weston_config_destroy(ec->config); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 2893 | } |
| 2894 | |
Kristian Høgsberg | af4f2aa | 2013-02-15 20:53:20 -0500 | [diff] [blame] | 2895 | WL_EXPORT void |
| 2896 | weston_version(int *major, int *minor, int *micro) |
| 2897 | { |
| 2898 | *major = WESTON_VERSION_MAJOR; |
| 2899 | *minor = WESTON_VERSION_MINOR; |
| 2900 | *micro = WESTON_VERSION_MICRO; |
| 2901 | } |
| 2902 | |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 2903 | static const struct { |
Pekka Paalanen | 4fc5dd0 | 2013-05-22 18:03:05 +0300 | [diff] [blame] | 2904 | uint32_t bit; /* enum weston_capability */ |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 2905 | const char *desc; |
| 2906 | } capability_strings[] = { |
| 2907 | { WESTON_CAP_ROTATION_ANY, "arbitrary surface rotation:" }, |
Pekka Paalanen | 4fc5dd0 | 2013-05-22 18:03:05 +0300 | [diff] [blame] | 2908 | { WESTON_CAP_CAPTURE_YFLIP, "screen capture uses y-flip:" }, |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 2909 | }; |
| 2910 | |
| 2911 | static void |
| 2912 | weston_compositor_log_capabilities(struct weston_compositor *compositor) |
| 2913 | { |
| 2914 | unsigned i; |
| 2915 | int yes; |
| 2916 | |
| 2917 | weston_log("Compositor capabilities:\n"); |
| 2918 | for (i = 0; i < ARRAY_LENGTH(capability_strings); i++) { |
| 2919 | yes = compositor->capabilities & capability_strings[i].bit; |
| 2920 | weston_log_continue(STAMP_SPACE "%s %s\n", |
| 2921 | capability_strings[i].desc, |
| 2922 | yes ? "yes" : "no"); |
| 2923 | } |
| 2924 | } |
| 2925 | |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 2926 | static int on_term_signal(int signal_number, void *data) |
Kristian Høgsberg | 50dc698 | 2010-12-01 16:43:56 -0500 | [diff] [blame] | 2927 | { |
Kristian Høgsberg | 6bded3f | 2011-08-12 14:55:07 -0400 | [diff] [blame] | 2928 | struct wl_display *display = data; |
Kristian Høgsberg | 50dc698 | 2010-12-01 16:43:56 -0500 | [diff] [blame] | 2929 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 2930 | weston_log("caught signal %d\n", signal_number); |
Kristian Høgsberg | 6bded3f | 2011-08-12 14:55:07 -0400 | [diff] [blame] | 2931 | wl_display_terminate(display); |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 2932 | |
| 2933 | return 1; |
Kristian Høgsberg | 50dc698 | 2010-12-01 16:43:56 -0500 | [diff] [blame] | 2934 | } |
| 2935 | |
Marcin Slusarz | 554a0da | 2013-02-18 13:27:22 -0500 | [diff] [blame] | 2936 | #ifdef HAVE_LIBUNWIND |
| 2937 | |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 2938 | static void |
Marcin Slusarz | 554a0da | 2013-02-18 13:27:22 -0500 | [diff] [blame] | 2939 | print_backtrace(void) |
| 2940 | { |
| 2941 | unw_cursor_t cursor; |
| 2942 | unw_context_t context; |
| 2943 | unw_word_t off; |
| 2944 | unw_proc_info_t pip; |
| 2945 | int ret, i = 0; |
| 2946 | char procname[256]; |
| 2947 | const char *filename; |
| 2948 | Dl_info dlinfo; |
| 2949 | |
| 2950 | pip.unwind_info = NULL; |
| 2951 | ret = unw_getcontext(&context); |
| 2952 | if (ret) { |
| 2953 | weston_log("unw_getcontext: %d\n", ret); |
| 2954 | return; |
| 2955 | } |
| 2956 | |
| 2957 | ret = unw_init_local(&cursor, &context); |
| 2958 | if (ret) { |
| 2959 | weston_log("unw_init_local: %d\n", ret); |
| 2960 | return; |
| 2961 | } |
| 2962 | |
| 2963 | ret = unw_step(&cursor); |
| 2964 | while (ret > 0) { |
| 2965 | ret = unw_get_proc_info(&cursor, &pip); |
| 2966 | if (ret) { |
| 2967 | weston_log("unw_get_proc_info: %d\n", ret); |
| 2968 | break; |
| 2969 | } |
| 2970 | |
| 2971 | ret = unw_get_proc_name(&cursor, procname, 256, &off); |
| 2972 | if (ret && ret != -UNW_ENOMEM) { |
| 2973 | if (ret != -UNW_EUNSPEC) |
| 2974 | weston_log("unw_get_proc_name: %d\n", ret); |
| 2975 | procname[0] = '?'; |
| 2976 | procname[1] = 0; |
| 2977 | } |
| 2978 | |
| 2979 | if (dladdr((void *)(pip.start_ip + off), &dlinfo) && dlinfo.dli_fname && |
| 2980 | *dlinfo.dli_fname) |
| 2981 | filename = dlinfo.dli_fname; |
| 2982 | else |
| 2983 | filename = "?"; |
| 2984 | |
| 2985 | weston_log("%u: %s (%s%s+0x%x) [%p]\n", i++, filename, procname, |
| 2986 | ret == -UNW_ENOMEM ? "..." : "", (int)off, (void *)(pip.start_ip + off)); |
| 2987 | |
| 2988 | ret = unw_step(&cursor); |
| 2989 | if (ret < 0) |
| 2990 | weston_log("unw_step: %d\n", ret); |
| 2991 | } |
| 2992 | } |
| 2993 | |
| 2994 | #else |
| 2995 | |
| 2996 | static void |
| 2997 | print_backtrace(void) |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 2998 | { |
| 2999 | void *buffer[32]; |
| 3000 | int i, count; |
| 3001 | Dl_info info; |
| 3002 | |
Marcin Slusarz | 554a0da | 2013-02-18 13:27:22 -0500 | [diff] [blame] | 3003 | count = backtrace(buffer, ARRAY_LENGTH(buffer)); |
| 3004 | for (i = 0; i < count; i++) { |
| 3005 | dladdr(buffer[i], &info); |
| 3006 | weston_log(" [%016lx] %s (%s)\n", |
| 3007 | (long) buffer[i], |
| 3008 | info.dli_sname ? info.dli_sname : "--", |
| 3009 | info.dli_fname); |
| 3010 | } |
| 3011 | } |
| 3012 | |
| 3013 | #endif |
| 3014 | |
| 3015 | static void |
Peter Maatman | e5b42e4 | 2013-03-27 22:38:53 +0100 | [diff] [blame] | 3016 | on_caught_signal(int s, siginfo_t *siginfo, void *context) |
Marcin Slusarz | 554a0da | 2013-02-18 13:27:22 -0500 | [diff] [blame] | 3017 | { |
Peter Maatman | e5b42e4 | 2013-03-27 22:38:53 +0100 | [diff] [blame] | 3018 | /* This signal handler will do a best-effort backtrace, and |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 3019 | * then call the backend restore function, which will switch |
| 3020 | * back to the vt we launched from or ungrab X etc and then |
| 3021 | * raise SIGTRAP. If we run weston under gdb from X or a |
Peter Maatman | e5b42e4 | 2013-03-27 22:38:53 +0100 | [diff] [blame] | 3022 | * different vt, and tell gdb "handle *s* nostop", this |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 3023 | * will allow weston to switch back to gdb on crash and then |
Peter Maatman | e5b42e4 | 2013-03-27 22:38:53 +0100 | [diff] [blame] | 3024 | * gdb will catch the crash with SIGTRAP.*/ |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 3025 | |
Peter Maatman | e5b42e4 | 2013-03-27 22:38:53 +0100 | [diff] [blame] | 3026 | weston_log("caught signal: %d\n", s); |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 3027 | |
Marcin Slusarz | 554a0da | 2013-02-18 13:27:22 -0500 | [diff] [blame] | 3028 | print_backtrace(); |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 3029 | |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 3030 | segv_compositor->restore(segv_compositor); |
| 3031 | |
| 3032 | raise(SIGTRAP); |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 3033 | } |
| 3034 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3035 | static void * |
Kristian Høgsberg | a4624f6 | 2012-09-11 14:08:26 -0400 | [diff] [blame] | 3036 | load_module(const char *name, const char *entrypoint) |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3037 | { |
| 3038 | char path[PATH_MAX]; |
| 3039 | void *module, *init; |
| 3040 | |
| 3041 | if (name[0] != '/') |
Chad Versace | bf38190 | 2012-05-23 23:42:15 -0700 | [diff] [blame] | 3042 | snprintf(path, sizeof path, "%s/%s", MODULEDIR, name); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3043 | else |
Benjamin Franzke | b7acce6 | 2011-05-06 23:19:22 +0200 | [diff] [blame] | 3044 | snprintf(path, sizeof path, "%s", name); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3045 | |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 3046 | module = dlopen(path, RTLD_NOW | RTLD_NOLOAD); |
| 3047 | if (module) { |
| 3048 | weston_log("Module '%s' already loaded\n", path); |
| 3049 | dlclose(module); |
| 3050 | return NULL; |
| 3051 | } |
| 3052 | |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 3053 | weston_log("Loading module '%s'\n", path); |
Kristian Høgsberg | 1acd9f8 | 2012-07-26 11:39:26 -0400 | [diff] [blame] | 3054 | module = dlopen(path, RTLD_NOW); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3055 | if (!module) { |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 3056 | weston_log("Failed to load module: %s\n", dlerror()); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3057 | return NULL; |
| 3058 | } |
| 3059 | |
| 3060 | init = dlsym(module, entrypoint); |
| 3061 | if (!init) { |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 3062 | weston_log("Failed to lookup init function: %s\n", dlerror()); |
Rob Bradford | c9e64ab | 2012-12-05 18:47:10 +0000 | [diff] [blame] | 3063 | dlclose(module); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3064 | return NULL; |
| 3065 | } |
| 3066 | |
| 3067 | return init; |
| 3068 | } |
| 3069 | |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 3070 | static int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 3071 | load_modules(struct weston_compositor *ec, const char *modules, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 3072 | int *argc, char *argv[]) |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 3073 | { |
| 3074 | const char *p, *end; |
| 3075 | char buffer[256]; |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 3076 | int (*module_init)(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 3077 | int *argc, char *argv[]); |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 3078 | |
| 3079 | if (modules == NULL) |
| 3080 | return 0; |
| 3081 | |
| 3082 | p = modules; |
| 3083 | while (*p) { |
| 3084 | end = strchrnul(p, ','); |
| 3085 | snprintf(buffer, sizeof buffer, "%.*s", (int) (end - p), p); |
| 3086 | module_init = load_module(buffer, "module_init"); |
| 3087 | if (module_init) |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 3088 | module_init(ec, argc, argv); |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 3089 | p = end; |
| 3090 | while (*p == ',') |
| 3091 | p++; |
| 3092 | |
| 3093 | } |
| 3094 | |
| 3095 | return 0; |
| 3096 | } |
| 3097 | |
Pekka Paalanen | 78a0b57 | 2012-06-06 16:59:44 +0300 | [diff] [blame] | 3098 | static const char xdg_error_message[] = |
Martin Minarik | 37032f8 | 2012-06-18 20:15:18 +0200 | [diff] [blame] | 3099 | "fatal: environment variable XDG_RUNTIME_DIR is not set.\n"; |
| 3100 | |
| 3101 | static const char xdg_wrong_message[] = |
| 3102 | "fatal: environment variable XDG_RUNTIME_DIR\n" |
| 3103 | "is set to \"%s\", which is not a directory.\n"; |
| 3104 | |
| 3105 | static const char xdg_wrong_mode_message[] = |
| 3106 | "warning: XDG_RUNTIME_DIR \"%s\" is not configured\n" |
| 3107 | "correctly. Unix access mode must be 0700 but is %o,\n" |
| 3108 | "and XDG_RUNTIME_DIR must be owned by the user, but is\n" |
Kristian Høgsberg | 3033425 | 2012-06-20 14:24:21 -0400 | [diff] [blame] | 3109 | "owned by UID %d.\n"; |
Martin Minarik | 37032f8 | 2012-06-18 20:15:18 +0200 | [diff] [blame] | 3110 | |
| 3111 | static const char xdg_detail_message[] = |
Pekka Paalanen | 78a0b57 | 2012-06-06 16:59:44 +0300 | [diff] [blame] | 3112 | "Refer to your distribution on how to get it, or\n" |
| 3113 | "http://www.freedesktop.org/wiki/Specifications/basedir-spec\n" |
| 3114 | "on how to implement it.\n"; |
| 3115 | |
Martin Minarik | 37032f8 | 2012-06-18 20:15:18 +0200 | [diff] [blame] | 3116 | static void |
| 3117 | verify_xdg_runtime_dir(void) |
| 3118 | { |
| 3119 | char *dir = getenv("XDG_RUNTIME_DIR"); |
| 3120 | struct stat s; |
| 3121 | |
| 3122 | if (!dir) { |
| 3123 | weston_log(xdg_error_message); |
| 3124 | weston_log_continue(xdg_detail_message); |
| 3125 | exit(EXIT_FAILURE); |
| 3126 | } |
| 3127 | |
| 3128 | if (stat(dir, &s) || !S_ISDIR(s.st_mode)) { |
| 3129 | weston_log(xdg_wrong_message, dir); |
| 3130 | weston_log_continue(xdg_detail_message); |
| 3131 | exit(EXIT_FAILURE); |
| 3132 | } |
| 3133 | |
| 3134 | if ((s.st_mode & 0777) != 0700 || s.st_uid != getuid()) { |
| 3135 | weston_log(xdg_wrong_mode_message, |
| 3136 | dir, s.st_mode & 0777, s.st_uid); |
| 3137 | weston_log_continue(xdg_detail_message); |
| 3138 | } |
| 3139 | } |
| 3140 | |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 3141 | static int |
| 3142 | usage(int error_code) |
| 3143 | { |
| 3144 | fprintf(stderr, |
| 3145 | "Usage: weston [OPTIONS]\n\n" |
| 3146 | "This is weston version " VERSION ", the Wayland reference compositor.\n" |
| 3147 | "Weston supports multiple backends, and depending on which backend is in use\n" |
| 3148 | "different options will be accepted.\n\n" |
| 3149 | |
| 3150 | |
| 3151 | "Core options:\n\n" |
Scott Moreau | 1224514 | 2012-08-29 15:15:58 -0600 | [diff] [blame] | 3152 | " --version\t\tPrint weston version\n" |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 3153 | " -B, --backend=MODULE\tBackend module, one of drm-backend.so,\n" |
Philipp Brüschweiler | e14560e | 2013-03-30 15:18:49 +0100 | [diff] [blame] | 3154 | "\t\t\t\tfbdev-backend.so, x11-backend.so or\n" |
| 3155 | "\t\t\t\twayland-backend.so\n" |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 3156 | " -S, --socket=NAME\tName of socket to listen on\n" |
| 3157 | " -i, --idle-time=SECS\tIdle time in seconds\n" |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 3158 | " --modules\t\tLoad the comma-separated list of modules\n" |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 3159 | " --log==FILE\t\tLog to the given file\n" |
| 3160 | " -h, --help\t\tThis help message\n\n"); |
| 3161 | |
| 3162 | fprintf(stderr, |
| 3163 | "Options for drm-backend.so:\n\n" |
| 3164 | " --connector=ID\tBring up only this connector\n" |
| 3165 | " --seat=SEAT\t\tThe seat that weston should run on\n" |
| 3166 | " --tty=TTY\t\tThe tty to use\n" |
Ander Conselvan de Oliveira | 23e72b8 | 2013-01-25 15:13:06 +0200 | [diff] [blame] | 3167 | " --use-pixman\t\tUse the pixman (CPU) renderer\n" |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 3168 | " --current-mode\tPrefer current KMS mode over EDID preferred mode\n\n"); |
| 3169 | |
| 3170 | fprintf(stderr, |
Philipp Brüschweiler | e14560e | 2013-03-30 15:18:49 +0100 | [diff] [blame] | 3171 | "Options for fbdev-backend.so:\n\n" |
| 3172 | " --tty=TTY\t\tThe tty to use\n" |
| 3173 | " --device=DEVICE\tThe framebuffer device to use\n\n"); |
| 3174 | |
| 3175 | fprintf(stderr, |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 3176 | "Options for x11-backend.so:\n\n" |
| 3177 | " --width=WIDTH\t\tWidth of X window\n" |
| 3178 | " --height=HEIGHT\tHeight of X window\n" |
| 3179 | " --fullscreen\t\tRun in fullscreen mode\n" |
Kristian Høgsberg | efaca34 | 2013-01-07 15:52:44 -0500 | [diff] [blame] | 3180 | " --use-pixman\t\tUse the pixman (CPU) renderer\n" |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 3181 | " --output-count=COUNT\tCreate multiple outputs\n" |
| 3182 | " --no-input\t\tDont create input devices\n\n"); |
| 3183 | |
| 3184 | fprintf(stderr, |
| 3185 | "Options for wayland-backend.so:\n\n" |
| 3186 | " --width=WIDTH\t\tWidth of Wayland surface\n" |
| 3187 | " --height=HEIGHT\tHeight of Wayland surface\n" |
| 3188 | " --display=DISPLAY\tWayland display to connect to\n\n"); |
| 3189 | |
Pekka Paalanen | e31e053 | 2013-05-22 18:03:07 +0300 | [diff] [blame] | 3190 | #if defined(BUILD_RPI_COMPOSITOR) && defined(HAVE_BCM_HOST) |
| 3191 | fprintf(stderr, |
| 3192 | "Options for rpi-backend.so:\n\n" |
| 3193 | " --tty=TTY\t\tThe tty to use\n" |
| 3194 | " --single-buffer\tUse single-buffered Dispmanx elements.\n" |
| 3195 | " --transform=TR\tThe output transformation, TR is one of:\n" |
| 3196 | "\tnormal 90 180 270 flipped flipped-90 flipped-180 flipped-270\n" |
| 3197 | "\n"); |
| 3198 | #endif |
| 3199 | |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 3200 | exit(error_code); |
| 3201 | } |
| 3202 | |
Peter Maatman | e5b42e4 | 2013-03-27 22:38:53 +0100 | [diff] [blame] | 3203 | static void |
| 3204 | catch_signals(void) |
| 3205 | { |
| 3206 | struct sigaction action; |
| 3207 | |
| 3208 | action.sa_flags = SA_SIGINFO | SA_RESETHAND; |
| 3209 | action.sa_sigaction = on_caught_signal; |
| 3210 | sigemptyset(&action.sa_mask); |
| 3211 | sigaction(SIGSEGV, &action, NULL); |
| 3212 | sigaction(SIGABRT, &action, NULL); |
| 3213 | } |
| 3214 | |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 3215 | int main(int argc, char *argv[]) |
| 3216 | { |
Pekka Paalanen | 3ab7269 | 2012-06-08 17:27:28 +0300 | [diff] [blame] | 3217 | int ret = EXIT_SUCCESS; |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 3218 | struct wl_display *display; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3219 | struct weston_compositor *ec; |
Pekka Paalanen | 51c769f | 2012-01-02 16:03:26 +0200 | [diff] [blame] | 3220 | struct wl_event_source *signals[4]; |
Kristian Høgsberg | 50dc698 | 2010-12-01 16:43:56 -0500 | [diff] [blame] | 3221 | struct wl_event_loop *loop; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3222 | struct weston_compositor |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 3223 | *(*backend_init)(struct wl_display *display, |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 3224 | int *argc, char *argv[], |
| 3225 | struct weston_config *config); |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 3226 | int i, config_fd; |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 3227 | char *backend = NULL; |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 3228 | char *modules, *option_modules = NULL; |
Martin Minarik | 19e6f26 | 2012-06-07 13:08:46 +0200 | [diff] [blame] | 3229 | char *log = NULL; |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 3230 | int32_t idle_time = 300; |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 3231 | int32_t help = 0; |
Kristian Høgsberg | eb00e2e | 2012-09-11 14:29:47 -0400 | [diff] [blame] | 3232 | char *socket_name = "wayland-0"; |
Scott Moreau | 1224514 | 2012-08-29 15:15:58 -0600 | [diff] [blame] | 3233 | int32_t version = 0; |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 3234 | struct weston_config *config; |
| 3235 | struct weston_config_section *section; |
Kristian Høgsberg | d34912c | 2011-05-02 10:36:04 -0400 | [diff] [blame] | 3236 | |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 3237 | const struct weston_option core_options[] = { |
| 3238 | { WESTON_OPTION_STRING, "backend", 'B', &backend }, |
| 3239 | { WESTON_OPTION_STRING, "socket", 'S', &socket_name }, |
| 3240 | { WESTON_OPTION_INTEGER, "idle-time", 'i', &idle_time }, |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 3241 | { WESTON_OPTION_STRING, "modules", 0, &option_modules }, |
Martin Minarik | 19e6f26 | 2012-06-07 13:08:46 +0200 | [diff] [blame] | 3242 | { WESTON_OPTION_STRING, "log", 0, &log }, |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 3243 | { WESTON_OPTION_BOOLEAN, "help", 'h', &help }, |
Scott Moreau | 1224514 | 2012-08-29 15:15:58 -0600 | [diff] [blame] | 3244 | { WESTON_OPTION_BOOLEAN, "version", 0, &version }, |
Kristian Høgsberg | d34912c | 2011-05-02 10:36:04 -0400 | [diff] [blame] | 3245 | }; |
Kristian Høgsberg | d653126 | 2008-12-12 11:06:18 -0500 | [diff] [blame] | 3246 | |
Kristian Høgsberg | 4172f66 | 2013-02-20 15:27:49 -0500 | [diff] [blame] | 3247 | parse_options(core_options, ARRAY_LENGTH(core_options), &argc, argv); |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 3248 | |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 3249 | if (help) |
| 3250 | usage(EXIT_SUCCESS); |
| 3251 | |
Scott Moreau | 1224514 | 2012-08-29 15:15:58 -0600 | [diff] [blame] | 3252 | if (version) { |
| 3253 | printf(PACKAGE_STRING "\n"); |
| 3254 | return EXIT_SUCCESS; |
| 3255 | } |
| 3256 | |
Rafal Mielniczuk | 6e0a7d8 | 2012-06-09 15:10:28 +0200 | [diff] [blame] | 3257 | weston_log_file_open(log); |
| 3258 | |
Pekka Paalanen | bce4c2b | 2012-06-11 14:04:21 +0300 | [diff] [blame] | 3259 | weston_log("%s\n" |
| 3260 | STAMP_SPACE "%s\n" |
| 3261 | STAMP_SPACE "Bug reports to: %s\n" |
| 3262 | STAMP_SPACE "Build: %s\n", |
| 3263 | PACKAGE_STRING, PACKAGE_URL, PACKAGE_BUGREPORT, |
Kristian Høgsberg | 23cf9eb | 2012-06-11 12:06:30 -0400 | [diff] [blame] | 3264 | BUILD_ID); |
Pekka Paalanen | 7f4d1a3 | 2012-06-11 14:06:03 +0300 | [diff] [blame] | 3265 | log_uname(); |
Kristian Høgsberg | a411c8b | 2012-06-08 16:16:52 -0400 | [diff] [blame] | 3266 | |
Martin Minarik | 37032f8 | 2012-06-18 20:15:18 +0200 | [diff] [blame] | 3267 | verify_xdg_runtime_dir(); |
| 3268 | |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 3269 | display = wl_display_create(); |
| 3270 | |
Tiago Vignatti | 2116b89 | 2011-08-08 05:52:59 -0700 | [diff] [blame] | 3271 | loop = wl_display_get_event_loop(display); |
Pekka Paalanen | 51c769f | 2012-01-02 16:03:26 +0200 | [diff] [blame] | 3272 | signals[0] = wl_event_loop_add_signal(loop, SIGTERM, on_term_signal, |
| 3273 | display); |
| 3274 | signals[1] = wl_event_loop_add_signal(loop, SIGINT, on_term_signal, |
| 3275 | display); |
| 3276 | signals[2] = wl_event_loop_add_signal(loop, SIGQUIT, on_term_signal, |
| 3277 | display); |
Tiago Vignatti | 2116b89 | 2011-08-08 05:52:59 -0700 | [diff] [blame] | 3278 | |
| 3279 | wl_list_init(&child_process_list); |
Pekka Paalanen | 51c769f | 2012-01-02 16:03:26 +0200 | [diff] [blame] | 3280 | signals[3] = wl_event_loop_add_signal(loop, SIGCHLD, sigchld_handler, |
| 3281 | NULL); |
Kristian Høgsberg | a941022 | 2011-01-14 17:22:35 -0500 | [diff] [blame] | 3282 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3283 | if (!backend) { |
| 3284 | if (getenv("WAYLAND_DISPLAY")) |
| 3285 | backend = "wayland-backend.so"; |
| 3286 | else if (getenv("DISPLAY")) |
| 3287 | backend = "x11-backend.so"; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3288 | else |
Pekka Paalanen | a51e6fa | 2012-11-07 12:25:12 +0200 | [diff] [blame] | 3289 | backend = WESTON_NATIVE_BACKEND; |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3290 | } |
| 3291 | |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 3292 | config_fd = open_config_file("weston.ini"); |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 3293 | config = weston_config_parse(config_fd); |
| 3294 | close(config_fd); |
| 3295 | |
| 3296 | section = weston_config_get_section(config, "core", NULL, NULL); |
| 3297 | weston_config_section_get_string(section, "modules", |
| 3298 | &modules, "desktop-shell.so"); |
Tiago Vignatti | 9a206c4 | 2012-03-21 19:49:18 +0200 | [diff] [blame] | 3299 | |
Kristian Høgsberg | a4624f6 | 2012-09-11 14:08:26 -0400 | [diff] [blame] | 3300 | backend_init = load_module(backend, "backend_init"); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3301 | if (!backend_init) |
| 3302 | exit(EXIT_FAILURE); |
Kristian Høgsberg | a941022 | 2011-01-14 17:22:35 -0500 | [diff] [blame] | 3303 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 3304 | ec = backend_init(display, &argc, argv, config); |
Kristian Høgsberg | 841883b | 2008-12-05 11:19:56 -0500 | [diff] [blame] | 3305 | if (ec == NULL) { |
Pekka Paalanen | 3361639 | 2012-07-30 16:56:57 +0300 | [diff] [blame] | 3306 | weston_log("fatal: failed to create compositor\n"); |
Kristian Høgsberg | 841883b | 2008-12-05 11:19:56 -0500 | [diff] [blame] | 3307 | exit(EXIT_FAILURE); |
| 3308 | } |
Kristian Høgsberg | 61a8251 | 2010-10-26 11:26:44 -0400 | [diff] [blame] | 3309 | |
Peter Maatman | e5b42e4 | 2013-03-27 22:38:53 +0100 | [diff] [blame] | 3310 | catch_signals(); |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 3311 | segv_compositor = ec; |
| 3312 | |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 3313 | ec->idle_time = idle_time; |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 3314 | |
Kristian Høgsberg | eb00e2e | 2012-09-11 14:29:47 -0400 | [diff] [blame] | 3315 | setenv("WAYLAND_DISPLAY", socket_name, 1); |
| 3316 | |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 3317 | if (load_modules(ec, modules, &argc, argv) < 0) |
Pekka Paalanen | 3361639 | 2012-07-30 16:56:57 +0300 | [diff] [blame] | 3318 | goto out; |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 3319 | if (load_modules(ec, option_modules, &argc, argv) < 0) |
Pekka Paalanen | 3361639 | 2012-07-30 16:56:57 +0300 | [diff] [blame] | 3320 | goto out; |
Tiago Vignatti | e4faa2a | 2012-04-16 17:31:44 +0300 | [diff] [blame] | 3321 | |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 3322 | for (i = 1; i < argc; i++) |
| 3323 | weston_log("fatal: unhandled option: %s\n", argv[i]); |
| 3324 | if (argc > 1) { |
| 3325 | ret = EXIT_FAILURE; |
| 3326 | goto out; |
| 3327 | } |
| 3328 | |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 3329 | weston_compositor_log_capabilities(ec); |
| 3330 | |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 3331 | if (wl_display_add_socket(display, socket_name)) { |
Pekka Paalanen | 3361639 | 2012-07-30 16:56:57 +0300 | [diff] [blame] | 3332 | weston_log("fatal: failed to add socket: %m\n"); |
| 3333 | ret = EXIT_FAILURE; |
| 3334 | goto out; |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 3335 | } |
| 3336 | |
Pekka Paalanen | c0444e3 | 2012-01-05 16:28:21 +0200 | [diff] [blame] | 3337 | weston_compositor_wake(ec); |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 3338 | |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 3339 | wl_display_run(display); |
| 3340 | |
| 3341 | out: |
Pekka Paalanen | 0135abe | 2012-01-03 10:01:20 +0200 | [diff] [blame] | 3342 | /* prevent further rendering while shutting down */ |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 3343 | ec->state = WESTON_COMPOSITOR_OFFSCREEN; |
Pekka Paalanen | 0135abe | 2012-01-03 10:01:20 +0200 | [diff] [blame] | 3344 | |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 3345 | wl_signal_emit(&ec->destroy_signal, ec); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 3346 | |
Pekka Paalanen | 51c769f | 2012-01-02 16:03:26 +0200 | [diff] [blame] | 3347 | for (i = ARRAY_LENGTH(signals); i;) |
| 3348 | wl_event_source_remove(signals[--i]); |
| 3349 | |
Daniel Stone | 855028f | 2012-05-01 20:37:10 +0100 | [diff] [blame] | 3350 | weston_compositor_xkb_destroy(ec); |
| 3351 | |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 3352 | ec->destroy(ec); |
Tiago Vignatti | 9e2be08 | 2011-12-19 00:04:46 +0200 | [diff] [blame] | 3353 | wl_display_destroy(display); |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 3354 | |
Martin Minarik | 19e6f26 | 2012-06-07 13:08:46 +0200 | [diff] [blame] | 3355 | weston_log_file_close(); |
| 3356 | |
Pekka Paalanen | 3ab7269 | 2012-06-08 17:27:28 +0300 | [diff] [blame] | 3357 | return ret; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 3358 | } |