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