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