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 | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 4 | * Copyright © 2012-2014 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> |
Pekka Paalanen | 23ade62 | 2014-08-27 13:31:26 +0300 | [diff] [blame] | 49 | #include <errno.h> |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 50 | |
Marcin Slusarz | 554a0da | 2013-02-18 13:27:22 -0500 | [diff] [blame] | 51 | #ifdef HAVE_LIBUNWIND |
| 52 | #define UNW_LOCAL_ONLY |
| 53 | #include <libunwind.h> |
| 54 | #endif |
| 55 | |
Kristian Høgsberg | 8286302 | 2010-06-04 21:52:02 -0400 | [diff] [blame] | 56 | #include "compositor.h" |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 57 | #include "scaler-server-protocol.h" |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 58 | #include "presentation_timing-server-protocol.h" |
Pekka Paalanen | 51aaf64 | 2012-05-30 15:53:41 +0300 | [diff] [blame] | 59 | #include "../shared/os-compatibility.h" |
Kristian Høgsberg | a411c8b | 2012-06-08 16:16:52 -0400 | [diff] [blame] | 60 | #include "git-version.h" |
Kristian Høgsberg | af4f2aa | 2013-02-15 20:53:20 -0500 | [diff] [blame] | 61 | #include "version.h" |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 62 | |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 63 | static struct wl_list child_process_list; |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 64 | static struct weston_compositor *segv_compositor; |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 65 | |
| 66 | static int |
| 67 | sigchld_handler(int signal_number, void *data) |
| 68 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 69 | struct weston_process *p; |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 70 | int status; |
| 71 | pid_t pid; |
| 72 | |
Pekka Paalanen | 23ade62 | 2014-08-27 13:31:26 +0300 | [diff] [blame] | 73 | while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { |
| 74 | wl_list_for_each(p, &child_process_list, link) { |
| 75 | if (p->pid == pid) |
| 76 | break; |
| 77 | } |
Bill Spitzak | 027b962 | 2012-03-17 15:22:03 -0700 | [diff] [blame] | 78 | |
Pekka Paalanen | 23ade62 | 2014-08-27 13:31:26 +0300 | [diff] [blame] | 79 | if (&p->link == &child_process_list) { |
| 80 | weston_log("unknown child process exited\n"); |
| 81 | continue; |
| 82 | } |
| 83 | |
| 84 | wl_list_remove(&p->link); |
| 85 | p->cleanup(p, status); |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 86 | } |
| 87 | |
Pekka Paalanen | 23ade62 | 2014-08-27 13:31:26 +0300 | [diff] [blame] | 88 | if (pid < 0 && errno != ECHILD) |
| 89 | weston_log("waitpid error %m\n"); |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 90 | |
| 91 | return 1; |
| 92 | } |
| 93 | |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 94 | static void |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 95 | weston_output_transform_scale_init(struct weston_output *output, |
| 96 | uint32_t transform, uint32_t scale); |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 97 | |
Rob Bradford | 27b1793 | 2013-06-26 18:08:46 +0100 | [diff] [blame] | 98 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 99 | weston_compositor_build_view_list(struct weston_compositor *compositor); |
Rob Bradford | 27b1793 | 2013-06-26 18:08:46 +0100 | [diff] [blame] | 100 | |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 101 | static void weston_mode_switch_finish(struct weston_output *output, |
| 102 | int mode_changed, |
| 103 | int scale_changed) |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 104 | { |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 105 | struct weston_seat *seat; |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 106 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 107 | pixman_region32_t old_output_region; |
Derek Foreman | 41bdc27 | 2014-11-05 13:26:57 -0600 | [diff] [blame] | 108 | int version; |
Alexander Larsson | 355748e | 2013-05-28 16:23:38 +0200 | [diff] [blame] | 109 | |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 110 | pixman_region32_init(&old_output_region); |
| 111 | pixman_region32_copy(&old_output_region, &output->region); |
| 112 | |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 113 | /* Update output region and transformation matrix */ |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 114 | 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] | 115 | |
| 116 | pixman_region32_init(&output->previous_damage); |
| 117 | pixman_region32_init_rect(&output->region, output->x, output->y, |
| 118 | output->width, output->height); |
| 119 | |
| 120 | weston_output_update_matrix(output); |
| 121 | |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 122 | /* If a pointer falls outside the outputs new geometry, move it to its |
| 123 | * lower-right corner */ |
| 124 | wl_list_for_each(seat, &output->compositor->seat_list, link) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 125 | struct weston_pointer *pointer = seat->pointer; |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 126 | int32_t x, y; |
| 127 | |
| 128 | if (!pointer) |
| 129 | continue; |
| 130 | |
| 131 | x = wl_fixed_to_int(pointer->x); |
| 132 | y = wl_fixed_to_int(pointer->y); |
| 133 | |
| 134 | if (!pixman_region32_contains_point(&old_output_region, |
| 135 | x, y, NULL) || |
| 136 | pixman_region32_contains_point(&output->region, |
| 137 | x, y, NULL)) |
| 138 | continue; |
| 139 | |
| 140 | if (x >= output->x + output->width) |
| 141 | x = output->x + output->width - 1; |
| 142 | if (y >= output->y + output->height) |
| 143 | y = output->y + output->height - 1; |
| 144 | |
| 145 | pointer->x = wl_fixed_from_int(x); |
| 146 | pointer->y = wl_fixed_from_int(y); |
| 147 | } |
| 148 | |
| 149 | pixman_region32_fini(&old_output_region); |
| 150 | |
Derek Foreman | dd4cd33 | 2014-11-10 10:29:59 -0600 | [diff] [blame] | 151 | if (!mode_changed && !scale_changed) |
| 152 | return; |
| 153 | |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 154 | /* notify clients of the changes */ |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 155 | wl_resource_for_each(resource, &output->resource_list) { |
| 156 | if (mode_changed) { |
| 157 | wl_output_send_mode(resource, |
| 158 | output->current_mode->flags, |
| 159 | output->current_mode->width, |
| 160 | output->current_mode->height, |
| 161 | output->current_mode->refresh); |
| 162 | } |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 163 | |
Derek Foreman | 41bdc27 | 2014-11-05 13:26:57 -0600 | [diff] [blame] | 164 | version = wl_resource_get_version(resource); |
| 165 | if (version >= WL_OUTPUT_SCALE_SINCE_VERSION && scale_changed) |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 166 | wl_output_send_scale(resource, output->current_scale); |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 167 | |
Derek Foreman | 41bdc27 | 2014-11-05 13:26:57 -0600 | [diff] [blame] | 168 | if (version >= WL_OUTPUT_DONE_SINCE_VERSION) |
| 169 | wl_output_send_done(resource); |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 170 | } |
| 171 | } |
| 172 | |
| 173 | WL_EXPORT int |
| 174 | weston_output_mode_set_native(struct weston_output *output, |
| 175 | struct weston_mode *mode, |
| 176 | int32_t scale) |
| 177 | { |
| 178 | int ret; |
| 179 | int mode_changed = 0, scale_changed = 0; |
| 180 | |
| 181 | if (!output->switch_mode) |
| 182 | return -1; |
| 183 | |
| 184 | if (!output->original_mode) { |
| 185 | mode_changed = 1; |
| 186 | ret = output->switch_mode(output, mode); |
| 187 | if (ret < 0) |
| 188 | return ret; |
| 189 | if (output->current_scale != scale) { |
| 190 | scale_changed = 1; |
| 191 | output->current_scale = scale; |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 192 | } |
| 193 | } |
| 194 | |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 195 | output->native_mode = mode; |
| 196 | output->native_scale = scale; |
| 197 | |
| 198 | weston_mode_switch_finish(output, mode_changed, scale_changed); |
| 199 | |
| 200 | return 0; |
| 201 | } |
| 202 | |
| 203 | WL_EXPORT int |
| 204 | weston_output_mode_switch_to_native(struct weston_output *output) |
| 205 | { |
| 206 | int ret; |
| 207 | int mode_changed = 0, scale_changed = 0; |
| 208 | |
| 209 | if (!output->switch_mode) |
| 210 | return -1; |
| 211 | |
| 212 | if (!output->original_mode) { |
| 213 | weston_log("already in the native mode\n"); |
| 214 | return -1; |
| 215 | } |
| 216 | /* the non fullscreen clients haven't seen a mode set since we |
| 217 | * switched into a temporary, so we need to notify them if the |
| 218 | * mode at that time is different from the native mode now. |
| 219 | */ |
| 220 | mode_changed = (output->original_mode != output->native_mode); |
| 221 | scale_changed = (output->original_scale != output->native_scale); |
| 222 | |
| 223 | ret = output->switch_mode(output, output->native_mode); |
| 224 | if (ret < 0) |
| 225 | return ret; |
| 226 | |
| 227 | output->current_scale = output->native_scale; |
| 228 | |
| 229 | output->original_mode = NULL; |
| 230 | output->original_scale = 0; |
| 231 | |
| 232 | weston_mode_switch_finish(output, mode_changed, scale_changed); |
| 233 | |
| 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | WL_EXPORT int |
| 238 | weston_output_mode_switch_to_temporary(struct weston_output *output, |
| 239 | struct weston_mode *mode, |
| 240 | int32_t scale) |
| 241 | { |
| 242 | int ret; |
| 243 | |
| 244 | if (!output->switch_mode) |
| 245 | return -1; |
| 246 | |
| 247 | /* original_mode is the last mode non full screen clients have seen, |
| 248 | * so we shouldn't change it if we already have one set. |
| 249 | */ |
| 250 | if (!output->original_mode) { |
| 251 | output->original_mode = output->native_mode; |
| 252 | output->original_scale = output->native_scale; |
| 253 | } |
| 254 | ret = output->switch_mode(output, mode); |
| 255 | if (ret < 0) |
| 256 | return ret; |
| 257 | |
| 258 | output->current_scale = scale; |
| 259 | |
| 260 | weston_mode_switch_finish(output, 0, 0); |
| 261 | |
| 262 | return 0; |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 263 | } |
| 264 | |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 265 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 266 | weston_watch_process(struct weston_process *process) |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 267 | { |
| 268 | wl_list_insert(&child_process_list, &process->link); |
| 269 | } |
| 270 | |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 271 | static void |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 272 | child_client_exec(int sockfd, const char *path) |
| 273 | { |
Kristian Høgsberg | d42b0c9 | 2011-12-08 10:19:40 -0500 | [diff] [blame] | 274 | int clientfd; |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 275 | char s[32]; |
Pekka Paalanen | c47ddfd | 2011-12-08 10:44:56 +0200 | [diff] [blame] | 276 | sigset_t allsigs; |
| 277 | |
| 278 | /* do not give our signal mask to the new process */ |
| 279 | sigfillset(&allsigs); |
| 280 | sigprocmask(SIG_UNBLOCK, &allsigs, NULL); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 281 | |
Alexandru DAMIAN | 840a421 | 2013-09-25 14:47:47 +0100 | [diff] [blame] | 282 | /* Launch clients as the user. Do not lauch clients with wrong euid.*/ |
| 283 | if (seteuid(getuid()) == -1) { |
| 284 | weston_log("compositor: failed seteuid\n"); |
| 285 | return; |
| 286 | } |
Kristian Høgsberg | eb76484 | 2012-01-31 22:17:25 -0500 | [diff] [blame] | 287 | |
Kristian Høgsberg | d42b0c9 | 2011-12-08 10:19:40 -0500 | [diff] [blame] | 288 | /* SOCK_CLOEXEC closes both ends, so we dup the fd to get a |
| 289 | * non-CLOEXEC fd to pass through exec. */ |
| 290 | clientfd = dup(sockfd); |
| 291 | if (clientfd == -1) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 292 | weston_log("compositor: dup failed: %m\n"); |
Kristian Høgsberg | d42b0c9 | 2011-12-08 10:19:40 -0500 | [diff] [blame] | 293 | return; |
| 294 | } |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 295 | |
Kristian Høgsberg | d42b0c9 | 2011-12-08 10:19:40 -0500 | [diff] [blame] | 296 | snprintf(s, sizeof s, "%d", clientfd); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 297 | setenv("WAYLAND_SOCKET", s, 1); |
| 298 | |
| 299 | if (execl(path, path, NULL) < 0) |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 300 | weston_log("compositor: executing '%s' failed: %m\n", |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 301 | path); |
| 302 | } |
| 303 | |
| 304 | WL_EXPORT struct wl_client * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 305 | weston_client_launch(struct weston_compositor *compositor, |
| 306 | struct weston_process *proc, |
| 307 | const char *path, |
| 308 | weston_process_cleanup_func_t cleanup) |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 309 | { |
| 310 | int sv[2]; |
| 311 | pid_t pid; |
| 312 | struct wl_client *client; |
| 313 | |
Pekka Paalanen | df1fd36 | 2012-08-06 14:57:03 +0300 | [diff] [blame] | 314 | weston_log("launching '%s'\n", path); |
| 315 | |
Pekka Paalanen | 51aaf64 | 2012-05-30 15:53:41 +0300 | [diff] [blame] | 316 | if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, sv) < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 317 | weston_log("weston_client_launch: " |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 318 | "socketpair failed while launching '%s': %m\n", |
| 319 | path); |
| 320 | return NULL; |
| 321 | } |
| 322 | |
| 323 | pid = fork(); |
| 324 | if (pid == -1) { |
| 325 | close(sv[0]); |
| 326 | close(sv[1]); |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 327 | weston_log("weston_client_launch: " |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 328 | "fork failed while launching '%s': %m\n", path); |
| 329 | return NULL; |
| 330 | } |
| 331 | |
| 332 | if (pid == 0) { |
| 333 | child_client_exec(sv[1], path); |
U. Artie Eoff | 3b64d62 | 2013-06-03 16:22:31 -0700 | [diff] [blame] | 334 | _exit(-1); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | close(sv[1]); |
| 338 | |
| 339 | client = wl_client_create(compositor->wl_display, sv[0]); |
| 340 | if (!client) { |
| 341 | close(sv[0]); |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 342 | weston_log("weston_client_launch: " |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 343 | "wl_client_create failed while launching '%s'.\n", |
| 344 | path); |
| 345 | return NULL; |
| 346 | } |
| 347 | |
| 348 | proc->pid = pid; |
| 349 | proc->cleanup = cleanup; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 350 | weston_watch_process(proc); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 351 | |
| 352 | return client; |
| 353 | } |
| 354 | |
Pekka Paalanen | 9c1ac7b | 2014-08-27 12:03:38 +0300 | [diff] [blame] | 355 | struct process_info { |
| 356 | struct weston_process proc; |
| 357 | char *path; |
| 358 | }; |
| 359 | |
| 360 | static void |
| 361 | process_handle_sigchld(struct weston_process *process, int status) |
| 362 | { |
| 363 | struct process_info *pinfo = |
| 364 | container_of(process, struct process_info, proc); |
| 365 | |
| 366 | /* |
| 367 | * There are no guarantees whether this runs before or after |
| 368 | * the wl_client destructor. |
| 369 | */ |
| 370 | |
| 371 | if (WIFEXITED(status)) { |
| 372 | weston_log("%s exited with status %d\n", pinfo->path, |
| 373 | WEXITSTATUS(status)); |
| 374 | } else if (WIFSIGNALED(status)) { |
| 375 | weston_log("%s died on signal %d\n", pinfo->path, |
| 376 | WTERMSIG(status)); |
| 377 | } else { |
| 378 | weston_log("%s disappeared\n", pinfo->path); |
| 379 | } |
| 380 | |
| 381 | free(pinfo->path); |
| 382 | free(pinfo); |
| 383 | } |
| 384 | |
| 385 | WL_EXPORT struct wl_client * |
| 386 | weston_client_start(struct weston_compositor *compositor, const char *path) |
| 387 | { |
| 388 | struct process_info *pinfo; |
| 389 | struct wl_client *client; |
| 390 | |
| 391 | pinfo = zalloc(sizeof *pinfo); |
| 392 | if (!pinfo) |
| 393 | return NULL; |
| 394 | |
| 395 | pinfo->path = strdup(path); |
| 396 | if (!pinfo->path) |
| 397 | goto out_free; |
| 398 | |
| 399 | client = weston_client_launch(compositor, &pinfo->proc, path, |
| 400 | process_handle_sigchld); |
| 401 | if (!client) |
| 402 | goto out_str; |
| 403 | |
| 404 | return client; |
| 405 | |
| 406 | out_str: |
| 407 | free(pinfo->path); |
| 408 | |
| 409 | out_free: |
| 410 | free(pinfo); |
| 411 | |
| 412 | return NULL; |
| 413 | } |
| 414 | |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 415 | static void |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 416 | region_init_infinite(pixman_region32_t *region) |
| 417 | { |
| 418 | pixman_region32_init_rect(region, INT32_MIN, INT32_MIN, |
| 419 | UINT32_MAX, UINT32_MAX); |
| 420 | } |
| 421 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 422 | static struct weston_subsurface * |
| 423 | weston_surface_to_subsurface(struct weston_surface *surface); |
| 424 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 425 | WL_EXPORT struct weston_view * |
| 426 | weston_view_create(struct weston_surface *surface) |
| 427 | { |
| 428 | struct weston_view *view; |
| 429 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 430 | view = zalloc(sizeof *view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 431 | if (view == NULL) |
| 432 | return NULL; |
| 433 | |
| 434 | view->surface = surface; |
| 435 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 436 | /* Assign to surface */ |
| 437 | wl_list_insert(&surface->views, &view->surface_link); |
| 438 | |
| 439 | wl_signal_init(&view->destroy_signal); |
| 440 | wl_list_init(&view->link); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 441 | wl_list_init(&view->layer_link.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 442 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 443 | pixman_region32_init(&view->clip); |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 444 | pixman_region32_init(&view->transform.masked_boundingbox); |
| 445 | pixman_region32_init(&view->transform.masked_opaque); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 446 | |
| 447 | view->alpha = 1.0; |
| 448 | pixman_region32_init(&view->transform.opaque); |
| 449 | |
| 450 | wl_list_init(&view->geometry.transformation_list); |
| 451 | wl_list_insert(&view->geometry.transformation_list, |
| 452 | &view->transform.position.link); |
| 453 | weston_matrix_init(&view->transform.position.matrix); |
| 454 | wl_list_init(&view->geometry.child_list); |
| 455 | pixman_region32_init(&view->transform.boundingbox); |
| 456 | view->transform.dirty = 1; |
| 457 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 458 | return view; |
| 459 | } |
| 460 | |
Jason Ekstrand | 108865d | 2014-06-26 10:04:49 -0700 | [diff] [blame] | 461 | struct weston_frame_callback { |
| 462 | struct wl_resource *resource; |
| 463 | struct wl_list link; |
| 464 | }; |
| 465 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 466 | struct weston_presentation_feedback { |
| 467 | struct wl_resource *resource; |
| 468 | |
| 469 | /* XXX: could use just wl_resource_get_link() instead */ |
| 470 | struct wl_list link; |
| 471 | }; |
| 472 | |
| 473 | static void |
| 474 | weston_presentation_feedback_discard( |
| 475 | struct weston_presentation_feedback *feedback) |
| 476 | { |
| 477 | presentation_feedback_send_discarded(feedback->resource); |
| 478 | wl_resource_destroy(feedback->resource); |
| 479 | } |
| 480 | |
| 481 | static void |
| 482 | weston_presentation_feedback_discard_list(struct wl_list *list) |
| 483 | { |
| 484 | struct weston_presentation_feedback *feedback, *tmp; |
| 485 | |
| 486 | wl_list_for_each_safe(feedback, tmp, list, link) |
| 487 | weston_presentation_feedback_discard(feedback); |
| 488 | } |
| 489 | |
| 490 | static void |
| 491 | weston_presentation_feedback_present( |
| 492 | struct weston_presentation_feedback *feedback, |
| 493 | struct weston_output *output, |
| 494 | uint32_t refresh_nsec, |
| 495 | const struct timespec *ts, |
| 496 | uint64_t seq) |
| 497 | { |
| 498 | struct wl_client *client = wl_resource_get_client(feedback->resource); |
| 499 | struct wl_resource *o; |
| 500 | uint64_t secs; |
| 501 | uint32_t flags = 0; |
| 502 | |
| 503 | wl_resource_for_each(o, &output->resource_list) { |
| 504 | if (wl_resource_get_client(o) != client) |
| 505 | continue; |
| 506 | |
| 507 | presentation_feedback_send_sync_output(feedback->resource, o); |
| 508 | } |
| 509 | |
| 510 | secs = ts->tv_sec; |
| 511 | presentation_feedback_send_presented(feedback->resource, |
| 512 | secs >> 32, secs & 0xffffffff, |
| 513 | ts->tv_nsec, |
| 514 | refresh_nsec, |
| 515 | seq >> 32, seq & 0xffffffff, |
| 516 | flags); |
| 517 | wl_resource_destroy(feedback->resource); |
| 518 | } |
| 519 | |
| 520 | static void |
| 521 | weston_presentation_feedback_present_list(struct wl_list *list, |
| 522 | struct weston_output *output, |
| 523 | uint32_t refresh_nsec, |
| 524 | const struct timespec *ts, |
| 525 | uint64_t seq) |
| 526 | { |
| 527 | struct weston_presentation_feedback *feedback, *tmp; |
| 528 | |
| 529 | wl_list_for_each_safe(feedback, tmp, list, link) |
| 530 | weston_presentation_feedback_present(feedback, output, |
| 531 | refresh_nsec, ts, seq); |
| 532 | } |
| 533 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 534 | static void |
| 535 | surface_state_handle_buffer_destroy(struct wl_listener *listener, void *data) |
| 536 | { |
| 537 | struct weston_surface_state *state = |
| 538 | container_of(listener, struct weston_surface_state, |
| 539 | buffer_destroy_listener); |
| 540 | |
| 541 | state->buffer = NULL; |
| 542 | } |
| 543 | |
| 544 | static void |
| 545 | weston_surface_state_init(struct weston_surface_state *state) |
| 546 | { |
| 547 | state->newly_attached = 0; |
| 548 | state->buffer = NULL; |
| 549 | state->buffer_destroy_listener.notify = |
| 550 | surface_state_handle_buffer_destroy; |
| 551 | state->sx = 0; |
| 552 | state->sy = 0; |
| 553 | |
| 554 | pixman_region32_init(&state->damage); |
| 555 | pixman_region32_init(&state->opaque); |
| 556 | region_init_infinite(&state->input); |
| 557 | |
| 558 | wl_list_init(&state->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 559 | wl_list_init(&state->feedback_list); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 560 | |
| 561 | state->buffer_viewport.buffer.transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 562 | state->buffer_viewport.buffer.scale = 1; |
| 563 | state->buffer_viewport.buffer.src_width = wl_fixed_from_int(-1); |
| 564 | state->buffer_viewport.surface.width = -1; |
| 565 | state->buffer_viewport.changed = 0; |
| 566 | } |
| 567 | |
| 568 | static void |
| 569 | weston_surface_state_fini(struct weston_surface_state *state) |
| 570 | { |
| 571 | struct weston_frame_callback *cb, *next; |
| 572 | |
| 573 | wl_list_for_each_safe(cb, next, |
| 574 | &state->frame_callback_list, link) |
| 575 | wl_resource_destroy(cb->resource); |
| 576 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 577 | weston_presentation_feedback_discard_list(&state->feedback_list); |
| 578 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 579 | pixman_region32_fini(&state->input); |
| 580 | pixman_region32_fini(&state->opaque); |
| 581 | pixman_region32_fini(&state->damage); |
| 582 | |
| 583 | if (state->buffer) |
| 584 | wl_list_remove(&state->buffer_destroy_listener.link); |
| 585 | state->buffer = NULL; |
| 586 | } |
| 587 | |
| 588 | static void |
| 589 | weston_surface_state_set_buffer(struct weston_surface_state *state, |
| 590 | struct weston_buffer *buffer) |
| 591 | { |
| 592 | if (state->buffer == buffer) |
| 593 | return; |
| 594 | |
| 595 | if (state->buffer) |
| 596 | wl_list_remove(&state->buffer_destroy_listener.link); |
| 597 | state->buffer = buffer; |
| 598 | if (state->buffer) |
| 599 | wl_signal_add(&state->buffer->destroy_signal, |
| 600 | &state->buffer_destroy_listener); |
| 601 | } |
| 602 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 603 | WL_EXPORT struct weston_surface * |
Kristian Høgsberg | 18c9300 | 2012-01-27 11:58:31 -0500 | [diff] [blame] | 604 | weston_surface_create(struct weston_compositor *compositor) |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 605 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 606 | struct weston_surface *surface; |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 607 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 608 | surface = zalloc(sizeof *surface); |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 609 | if (surface == NULL) |
| 610 | return NULL; |
| 611 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 612 | wl_signal_init(&surface->destroy_signal); |
| 613 | |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 614 | surface->compositor = compositor; |
Giulio Camuffo | 13b85bd | 2013-08-13 23:10:14 +0200 | [diff] [blame] | 615 | surface->ref_count = 1; |
Kristian Høgsberg | 27803c6 | 2010-06-06 22:23:21 -0400 | [diff] [blame] | 616 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 617 | surface->buffer_viewport.buffer.transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 618 | surface->buffer_viewport.buffer.scale = 1; |
Pekka Paalanen | f0cad48 | 2014-03-14 14:38:16 +0200 | [diff] [blame] | 619 | surface->buffer_viewport.buffer.src_width = wl_fixed_from_int(-1); |
| 620 | surface->buffer_viewport.surface.width = -1; |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 621 | |
| 622 | weston_surface_state_init(&surface->pending); |
| 623 | |
Kristian Høgsberg | 20300ba | 2011-06-23 20:29:12 -0400 | [diff] [blame] | 624 | pixman_region32_init(&surface->damage); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 625 | pixman_region32_init(&surface->opaque); |
Pekka Paalanen | 8ec4ab6 | 2012-10-10 12:49:32 +0300 | [diff] [blame] | 626 | region_init_infinite(&surface->input); |
Kristian Høgsberg | 20300ba | 2011-06-23 20:29:12 -0400 | [diff] [blame] | 627 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 628 | wl_list_init(&surface->views); |
| 629 | |
| 630 | wl_list_init(&surface->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 631 | wl_list_init(&surface->feedback_list); |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 632 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 633 | wl_list_init(&surface->subsurface_list); |
| 634 | wl_list_init(&surface->subsurface_list_pending); |
| 635 | |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 636 | return surface; |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 637 | } |
| 638 | |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 639 | WL_EXPORT void |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 640 | weston_surface_set_color(struct weston_surface *surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 641 | float red, float green, float blue, float alpha) |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 642 | { |
John Kåre Alsaker | 878f449 | 2012-11-13 19:10:23 +0100 | [diff] [blame] | 643 | surface->compositor->renderer->surface_set_color(surface, red, green, blue, alpha); |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 644 | } |
| 645 | |
Kristian Høgsberg | e4c1a5f | 2012-06-18 13:17:32 -0400 | [diff] [blame] | 646 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 647 | weston_view_to_global_float(struct weston_view *view, |
| 648 | float sx, float sy, float *x, float *y) |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 649 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 650 | if (view->transform.enabled) { |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 651 | struct weston_vector v = { { sx, sy, 0.0f, 1.0f } }; |
| 652 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 653 | weston_matrix_transform(&view->transform.matrix, &v); |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 654 | |
| 655 | if (fabsf(v.f[3]) < 1e-6) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 656 | weston_log("warning: numerical instability in " |
Scott Moreau | 088c62e | 2013-02-11 04:45:38 -0700 | [diff] [blame] | 657 | "%s(), divisor = %g\n", __func__, |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 658 | v.f[3]); |
| 659 | *x = 0; |
| 660 | *y = 0; |
| 661 | return; |
| 662 | } |
| 663 | |
| 664 | *x = v.f[0] / v.f[3]; |
| 665 | *y = v.f[1] / v.f[3]; |
| 666 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 667 | *x = sx + view->geometry.x; |
| 668 | *y = sy + view->geometry.y; |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 669 | } |
| 670 | } |
| 671 | |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 672 | WL_EXPORT void |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 673 | weston_transformed_coord(int width, int height, |
| 674 | enum wl_output_transform transform, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 675 | int32_t scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 676 | float sx, float sy, float *bx, float *by) |
| 677 | { |
| 678 | switch (transform) { |
| 679 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 680 | default: |
| 681 | *bx = sx; |
| 682 | *by = sy; |
| 683 | break; |
| 684 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 685 | *bx = width - sx; |
| 686 | *by = sy; |
| 687 | break; |
| 688 | case WL_OUTPUT_TRANSFORM_90: |
| 689 | *bx = height - sy; |
| 690 | *by = sx; |
| 691 | break; |
| 692 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 693 | *bx = height - sy; |
| 694 | *by = width - sx; |
| 695 | break; |
| 696 | case WL_OUTPUT_TRANSFORM_180: |
| 697 | *bx = width - sx; |
| 698 | *by = height - sy; |
| 699 | break; |
| 700 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 701 | *bx = sx; |
| 702 | *by = height - sy; |
| 703 | break; |
| 704 | case WL_OUTPUT_TRANSFORM_270: |
| 705 | *bx = sy; |
| 706 | *by = width - sx; |
| 707 | break; |
| 708 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 709 | *bx = sy; |
| 710 | *by = sx; |
| 711 | break; |
| 712 | } |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 713 | |
| 714 | *bx *= scale; |
| 715 | *by *= scale; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | WL_EXPORT pixman_box32_t |
| 719 | weston_transformed_rect(int width, int height, |
| 720 | enum wl_output_transform transform, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 721 | int32_t scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 722 | pixman_box32_t rect) |
| 723 | { |
| 724 | float x1, x2, y1, y2; |
| 725 | |
| 726 | pixman_box32_t ret; |
| 727 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 728 | weston_transformed_coord(width, height, transform, scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 729 | rect.x1, rect.y1, &x1, &y1); |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 730 | weston_transformed_coord(width, height, transform, scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 731 | rect.x2, rect.y2, &x2, &y2); |
| 732 | |
| 733 | if (x1 <= x2) { |
| 734 | ret.x1 = x1; |
| 735 | ret.x2 = x2; |
| 736 | } else { |
| 737 | ret.x1 = x2; |
| 738 | ret.x2 = x1; |
| 739 | } |
| 740 | |
| 741 | if (y1 <= y2) { |
| 742 | ret.y1 = y1; |
| 743 | ret.y2 = y2; |
| 744 | } else { |
| 745 | ret.y1 = y2; |
| 746 | ret.y2 = y1; |
| 747 | } |
| 748 | |
| 749 | return ret; |
| 750 | } |
| 751 | |
| 752 | WL_EXPORT void |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 753 | weston_transformed_region(int width, int height, |
| 754 | enum wl_output_transform transform, |
| 755 | int32_t scale, |
| 756 | pixman_region32_t *src, pixman_region32_t *dest) |
| 757 | { |
| 758 | pixman_box32_t *src_rects, *dest_rects; |
| 759 | int nrects, i; |
| 760 | |
| 761 | if (transform == WL_OUTPUT_TRANSFORM_NORMAL && scale == 1) { |
| 762 | if (src != dest) |
| 763 | pixman_region32_copy(dest, src); |
| 764 | return; |
| 765 | } |
| 766 | |
| 767 | src_rects = pixman_region32_rectangles(src, &nrects); |
| 768 | dest_rects = malloc(nrects * sizeof(*dest_rects)); |
| 769 | if (!dest_rects) |
| 770 | return; |
| 771 | |
| 772 | if (transform == WL_OUTPUT_TRANSFORM_NORMAL) { |
| 773 | memcpy(dest_rects, src_rects, nrects * sizeof(*dest_rects)); |
| 774 | } else { |
| 775 | for (i = 0; i < nrects; i++) { |
| 776 | switch (transform) { |
| 777 | default: |
| 778 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 779 | dest_rects[i].x1 = src_rects[i].x1; |
| 780 | dest_rects[i].y1 = src_rects[i].y1; |
| 781 | dest_rects[i].x2 = src_rects[i].x2; |
| 782 | dest_rects[i].y2 = src_rects[i].y2; |
| 783 | break; |
| 784 | case WL_OUTPUT_TRANSFORM_90: |
| 785 | dest_rects[i].x1 = height - src_rects[i].y2; |
| 786 | dest_rects[i].y1 = src_rects[i].x1; |
| 787 | dest_rects[i].x2 = height - src_rects[i].y1; |
| 788 | dest_rects[i].y2 = src_rects[i].x2; |
| 789 | break; |
| 790 | case WL_OUTPUT_TRANSFORM_180: |
| 791 | dest_rects[i].x1 = width - src_rects[i].x2; |
| 792 | dest_rects[i].y1 = height - src_rects[i].y2; |
| 793 | dest_rects[i].x2 = width - src_rects[i].x1; |
| 794 | dest_rects[i].y2 = height - src_rects[i].y1; |
| 795 | break; |
| 796 | case WL_OUTPUT_TRANSFORM_270: |
| 797 | dest_rects[i].x1 = src_rects[i].y1; |
| 798 | dest_rects[i].y1 = width - src_rects[i].x2; |
| 799 | dest_rects[i].x2 = src_rects[i].y2; |
| 800 | dest_rects[i].y2 = width - src_rects[i].x1; |
| 801 | break; |
| 802 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 803 | dest_rects[i].x1 = width - src_rects[i].x2; |
| 804 | dest_rects[i].y1 = src_rects[i].y1; |
| 805 | dest_rects[i].x2 = width - src_rects[i].x1; |
| 806 | dest_rects[i].y2 = src_rects[i].y2; |
| 807 | break; |
| 808 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 809 | dest_rects[i].x1 = height - src_rects[i].y2; |
| 810 | dest_rects[i].y1 = width - src_rects[i].x2; |
| 811 | dest_rects[i].x2 = height - src_rects[i].y1; |
| 812 | dest_rects[i].y2 = width - src_rects[i].x1; |
| 813 | break; |
| 814 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 815 | dest_rects[i].x1 = src_rects[i].x1; |
| 816 | dest_rects[i].y1 = height - src_rects[i].y2; |
| 817 | dest_rects[i].x2 = src_rects[i].x2; |
| 818 | dest_rects[i].y2 = height - src_rects[i].y1; |
| 819 | break; |
| 820 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 821 | dest_rects[i].x1 = src_rects[i].y1; |
| 822 | dest_rects[i].y1 = src_rects[i].x1; |
| 823 | dest_rects[i].x2 = src_rects[i].y2; |
| 824 | dest_rects[i].y2 = src_rects[i].x2; |
| 825 | break; |
| 826 | } |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | if (scale != 1) { |
| 831 | for (i = 0; i < nrects; i++) { |
| 832 | dest_rects[i].x1 *= scale; |
| 833 | dest_rects[i].x2 *= scale; |
| 834 | dest_rects[i].y1 *= scale; |
| 835 | dest_rects[i].y2 *= scale; |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | pixman_region32_clear(dest); |
| 840 | pixman_region32_init_rects(dest, dest_rects, nrects); |
| 841 | free(dest_rects); |
| 842 | } |
| 843 | |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 844 | static void |
| 845 | scaler_surface_to_buffer(struct weston_surface *surface, |
| 846 | float sx, float sy, float *bx, float *by) |
| 847 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 848 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 849 | double src_width, src_height; |
| 850 | double src_x, src_y; |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 851 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 852 | if (vp->buffer.src_width == wl_fixed_from_int(-1)) { |
| 853 | if (vp->surface.width == -1) { |
| 854 | *bx = sx; |
| 855 | *by = sy; |
| 856 | return; |
| 857 | } |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 858 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 859 | src_x = 0.0; |
| 860 | src_y = 0.0; |
| 861 | src_width = surface->width_from_buffer; |
| 862 | src_height = surface->height_from_buffer; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 863 | } else { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 864 | src_x = wl_fixed_to_double(vp->buffer.src_x); |
| 865 | src_y = wl_fixed_to_double(vp->buffer.src_y); |
| 866 | src_width = wl_fixed_to_double(vp->buffer.src_width); |
| 867 | src_height = wl_fixed_to_double(vp->buffer.src_height); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 868 | } |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 869 | |
| 870 | *bx = sx * src_width / surface->width + src_x; |
| 871 | *by = sy * src_height / surface->height + src_y; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 872 | } |
| 873 | |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 874 | WL_EXPORT void |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 875 | weston_surface_to_buffer_float(struct weston_surface *surface, |
| 876 | float sx, float sy, float *bx, float *by) |
| 877 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 878 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
| 879 | |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 880 | /* first transform coordinates if the scaler is set */ |
| 881 | scaler_surface_to_buffer(surface, sx, sy, bx, by); |
| 882 | |
Jason Ekstrand | d0cebc3 | 2014-04-21 20:56:46 -0500 | [diff] [blame] | 883 | weston_transformed_coord(surface->width_from_buffer, |
| 884 | surface->height_from_buffer, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 885 | vp->buffer.transform, vp->buffer.scale, |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 886 | *bx, *by, bx, by); |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 887 | } |
| 888 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 889 | WL_EXPORT void |
| 890 | weston_surface_to_buffer(struct weston_surface *surface, |
| 891 | int sx, int sy, int *bx, int *by) |
| 892 | { |
| 893 | float bxf, byf; |
| 894 | |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 895 | weston_surface_to_buffer_float(surface, |
| 896 | sx, sy, &bxf, &byf); |
| 897 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 898 | *bx = floorf(bxf); |
| 899 | *by = floorf(byf); |
| 900 | } |
| 901 | |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 902 | WL_EXPORT pixman_box32_t |
| 903 | weston_surface_to_buffer_rect(struct weston_surface *surface, |
| 904 | pixman_box32_t rect) |
| 905 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 906 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 907 | float xf, yf; |
| 908 | |
| 909 | /* first transform box coordinates if the scaler is set */ |
| 910 | scaler_surface_to_buffer(surface, rect.x1, rect.y1, &xf, &yf); |
| 911 | rect.x1 = floorf(xf); |
| 912 | rect.y1 = floorf(yf); |
| 913 | |
| 914 | scaler_surface_to_buffer(surface, rect.x2, rect.y2, &xf, &yf); |
| 915 | rect.x2 = floorf(xf); |
| 916 | rect.y2 = floorf(yf); |
| 917 | |
Jason Ekstrand | d0cebc3 | 2014-04-21 20:56:46 -0500 | [diff] [blame] | 918 | return weston_transformed_rect(surface->width_from_buffer, |
| 919 | surface->height_from_buffer, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 920 | vp->buffer.transform, vp->buffer.scale, |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 921 | rect); |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 922 | } |
| 923 | |
| 924 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 925 | weston_view_move_to_plane(struct weston_view *view, |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 926 | struct weston_plane *plane) |
| 927 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 928 | if (view->plane == plane) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 929 | return; |
| 930 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 931 | weston_view_damage_below(view); |
| 932 | view->plane = plane; |
| 933 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 937 | weston_view_damage_below(struct weston_view *view) |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 938 | { |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 939 | pixman_region32_t damage; |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 940 | |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 941 | pixman_region32_init(&damage); |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 942 | pixman_region32_subtract(&damage, &view->transform.masked_boundingbox, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 943 | &view->clip); |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 944 | if (view->plane) |
| 945 | pixman_region32_union(&view->plane->damage, |
| 946 | &view->plane->damage, &damage); |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 947 | pixman_region32_fini(&damage); |
Kristian Høgsberg | a3a784a | 2013-11-13 21:33:43 -0800 | [diff] [blame] | 948 | weston_view_schedule_repaint(view); |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 949 | } |
| 950 | |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 951 | static void |
| 952 | weston_surface_update_output_mask(struct weston_surface *es, uint32_t mask) |
| 953 | { |
| 954 | uint32_t different = es->output_mask ^ mask; |
| 955 | uint32_t entered = mask & different; |
| 956 | uint32_t left = es->output_mask & different; |
| 957 | struct weston_output *output; |
| 958 | struct wl_resource *resource = NULL; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 959 | struct wl_client *client; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 960 | |
| 961 | es->output_mask = mask; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 962 | if (es->resource == NULL) |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 963 | return; |
| 964 | if (different == 0) |
| 965 | return; |
| 966 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 967 | client = wl_resource_get_client(es->resource); |
| 968 | |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 969 | wl_list_for_each(output, &es->compositor->output_list, link) { |
| 970 | if (1 << output->id & different) |
| 971 | resource = |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 972 | wl_resource_find_for_client(&output->resource_list, |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 973 | client); |
| 974 | if (resource == NULL) |
| 975 | continue; |
| 976 | if (1 << output->id & entered) |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 977 | wl_surface_send_enter(es->resource, resource); |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 978 | if (1 << output->id & left) |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 979 | wl_surface_send_leave(es->resource, resource); |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 980 | } |
| 981 | } |
| 982 | |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 983 | |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 984 | static void |
| 985 | weston_surface_assign_output(struct weston_surface *es) |
| 986 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 987 | struct weston_output *new_output; |
| 988 | struct weston_view *view; |
| 989 | pixman_region32_t region; |
| 990 | uint32_t max, area, mask; |
| 991 | pixman_box32_t *e; |
| 992 | |
| 993 | new_output = NULL; |
| 994 | max = 0; |
| 995 | mask = 0; |
| 996 | pixman_region32_init(®ion); |
| 997 | wl_list_for_each(view, &es->views, surface_link) { |
| 998 | if (!view->output) |
| 999 | continue; |
| 1000 | |
| 1001 | pixman_region32_intersect(®ion, &view->transform.boundingbox, |
| 1002 | &view->output->region); |
| 1003 | |
| 1004 | e = pixman_region32_extents(®ion); |
| 1005 | area = (e->x2 - e->x1) * (e->y2 - e->y1); |
| 1006 | |
| 1007 | mask |= view->output_mask; |
| 1008 | |
| 1009 | if (area >= max) { |
| 1010 | new_output = view->output; |
| 1011 | max = area; |
| 1012 | } |
| 1013 | } |
| 1014 | pixman_region32_fini(®ion); |
| 1015 | |
| 1016 | es->output = new_output; |
| 1017 | weston_surface_update_output_mask(es, mask); |
| 1018 | } |
| 1019 | |
| 1020 | static void |
| 1021 | weston_view_assign_output(struct weston_view *ev) |
| 1022 | { |
| 1023 | struct weston_compositor *ec = ev->surface->compositor; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1024 | struct weston_output *output, *new_output; |
| 1025 | pixman_region32_t region; |
| 1026 | uint32_t max, area, mask; |
| 1027 | pixman_box32_t *e; |
| 1028 | |
| 1029 | new_output = NULL; |
| 1030 | max = 0; |
| 1031 | mask = 0; |
| 1032 | pixman_region32_init(®ion); |
| 1033 | wl_list_for_each(output, &ec->output_list, link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1034 | pixman_region32_intersect(®ion, &ev->transform.boundingbox, |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1035 | &output->region); |
| 1036 | |
| 1037 | e = pixman_region32_extents(®ion); |
| 1038 | area = (e->x2 - e->x1) * (e->y2 - e->y1); |
| 1039 | |
| 1040 | if (area > 0) |
| 1041 | mask |= 1 << output->id; |
| 1042 | |
| 1043 | if (area >= max) { |
| 1044 | new_output = output; |
| 1045 | max = area; |
| 1046 | } |
| 1047 | } |
| 1048 | pixman_region32_fini(®ion); |
| 1049 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1050 | ev->output = new_output; |
| 1051 | ev->output_mask = mask; |
| 1052 | |
| 1053 | weston_surface_assign_output(ev->surface); |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1054 | } |
| 1055 | |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 1056 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1057 | view_compute_bbox(struct weston_view *view, int32_t sx, int32_t sy, |
| 1058 | int32_t width, int32_t height, |
| 1059 | pixman_region32_t *bbox) |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1060 | { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1061 | float min_x = HUGE_VALF, min_y = HUGE_VALF; |
| 1062 | float max_x = -HUGE_VALF, max_y = -HUGE_VALF; |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1063 | int32_t s[4][2] = { |
| 1064 | { sx, sy }, |
| 1065 | { sx, sy + height }, |
| 1066 | { sx + width, sy }, |
| 1067 | { sx + width, sy + height } |
| 1068 | }; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1069 | float int_x, int_y; |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1070 | int i; |
| 1071 | |
Pekka Paalanen | 7c7d464 | 2012-09-04 13:55:44 +0300 | [diff] [blame] | 1072 | if (width == 0 || height == 0) { |
| 1073 | /* avoid rounding empty bbox to 1x1 */ |
| 1074 | pixman_region32_init(bbox); |
| 1075 | return; |
| 1076 | } |
| 1077 | |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1078 | for (i = 0; i < 4; ++i) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1079 | float x, y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1080 | 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] | 1081 | if (x < min_x) |
| 1082 | min_x = x; |
| 1083 | if (x > max_x) |
| 1084 | max_x = x; |
| 1085 | if (y < min_y) |
| 1086 | min_y = y; |
| 1087 | if (y > max_y) |
| 1088 | max_y = y; |
| 1089 | } |
| 1090 | |
Pekka Paalanen | 219b982 | 2012-02-08 15:38:37 +0200 | [diff] [blame] | 1091 | int_x = floorf(min_x); |
| 1092 | int_y = floorf(min_y); |
| 1093 | pixman_region32_init_rect(bbox, int_x, int_y, |
| 1094 | ceilf(max_x) - int_x, ceilf(max_y) - int_y); |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1095 | } |
| 1096 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1097 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1098 | weston_view_update_transform_disable(struct weston_view *view) |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1099 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1100 | view->transform.enabled = 0; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1101 | |
Pekka Paalanen | cc2f868 | 2012-02-13 10:34:04 +0200 | [diff] [blame] | 1102 | /* round off fractions when not transformed */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1103 | view->geometry.x = roundf(view->geometry.x); |
| 1104 | view->geometry.y = roundf(view->geometry.y); |
Pekka Paalanen | cc2f868 | 2012-02-13 10:34:04 +0200 | [diff] [blame] | 1105 | |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1106 | /* Otherwise identity matrix, but with x and y translation. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1107 | view->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE; |
| 1108 | view->transform.position.matrix.d[12] = view->geometry.x; |
| 1109 | view->transform.position.matrix.d[13] = view->geometry.y; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1110 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1111 | view->transform.matrix = view->transform.position.matrix; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1112 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1113 | view->transform.inverse = view->transform.position.matrix; |
| 1114 | view->transform.inverse.d[12] = -view->geometry.x; |
| 1115 | view->transform.inverse.d[13] = -view->geometry.y; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1116 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1117 | pixman_region32_init_rect(&view->transform.boundingbox, |
| 1118 | view->geometry.x, |
| 1119 | view->geometry.y, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1120 | view->surface->width, |
| 1121 | view->surface->height); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1122 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1123 | if (view->alpha == 1.0) { |
| 1124 | pixman_region32_copy(&view->transform.opaque, |
| 1125 | &view->surface->opaque); |
| 1126 | pixman_region32_translate(&view->transform.opaque, |
| 1127 | view->geometry.x, |
| 1128 | view->geometry.y); |
Kristian Høgsberg | 3b4af20 | 2012-02-28 09:19:39 -0500 | [diff] [blame] | 1129 | } |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | static int |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1133 | weston_view_update_transform_enable(struct weston_view *view) |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1134 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1135 | struct weston_view *parent = view->geometry.parent; |
| 1136 | struct weston_matrix *matrix = &view->transform.matrix; |
| 1137 | struct weston_matrix *inverse = &view->transform.inverse; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1138 | struct weston_transform *tform; |
| 1139 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1140 | view->transform.enabled = 1; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1141 | |
| 1142 | /* Otherwise identity matrix, but with x and y translation. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1143 | view->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE; |
| 1144 | view->transform.position.matrix.d[12] = view->geometry.x; |
| 1145 | view->transform.position.matrix.d[13] = view->geometry.y; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1146 | |
| 1147 | weston_matrix_init(matrix); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1148 | wl_list_for_each(tform, &view->geometry.transformation_list, link) |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1149 | weston_matrix_multiply(matrix, &tform->matrix); |
| 1150 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1151 | if (parent) |
| 1152 | weston_matrix_multiply(matrix, &parent->transform.matrix); |
| 1153 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1154 | if (weston_matrix_invert(inverse, matrix) < 0) { |
| 1155 | /* Oops, bad total transformation, not invertible */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1156 | weston_log("error: weston_view %p" |
| 1157 | " transformation not invertible.\n", view); |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1158 | return -1; |
| 1159 | } |
| 1160 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1161 | view_compute_bbox(view, 0, 0, |
| 1162 | view->surface->width, view->surface->height, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1163 | &view->transform.boundingbox); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1164 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1165 | return 0; |
| 1166 | } |
| 1167 | |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1168 | static struct weston_layer * |
| 1169 | get_view_layer(struct weston_view *view) |
| 1170 | { |
| 1171 | if (view->parent_view) |
| 1172 | return get_view_layer(view->parent_view); |
| 1173 | return view->layer_link.layer; |
| 1174 | } |
| 1175 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1176 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1177 | weston_view_update_transform(struct weston_view *view) |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1178 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1179 | struct weston_view *parent = view->geometry.parent; |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1180 | struct weston_layer *layer; |
| 1181 | pixman_region32_t mask; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1182 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1183 | if (!view->transform.dirty) |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1184 | return; |
| 1185 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1186 | if (parent) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1187 | weston_view_update_transform(parent); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1188 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1189 | view->transform.dirty = 0; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1190 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1191 | weston_view_damage_below(view); |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 1192 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1193 | pixman_region32_fini(&view->transform.boundingbox); |
| 1194 | pixman_region32_fini(&view->transform.opaque); |
| 1195 | pixman_region32_init(&view->transform.opaque); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1196 | |
Pekka Paalanen | cd40362 | 2012-01-25 13:37:39 +0200 | [diff] [blame] | 1197 | /* transform.position is always in transformation_list */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1198 | if (view->geometry.transformation_list.next == |
| 1199 | &view->transform.position.link && |
| 1200 | view->geometry.transformation_list.prev == |
| 1201 | &view->transform.position.link && |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1202 | !parent) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1203 | weston_view_update_transform_disable(view); |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1204 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1205 | if (weston_view_update_transform_enable(view) < 0) |
| 1206 | weston_view_update_transform_disable(view); |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1207 | } |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 1208 | |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1209 | layer = get_view_layer(view); |
| 1210 | if (layer) { |
| 1211 | pixman_region32_init_with_extents(&mask, &layer->mask); |
| 1212 | pixman_region32_intersect(&view->transform.masked_boundingbox, |
| 1213 | &view->transform.boundingbox, &mask); |
| 1214 | pixman_region32_intersect(&view->transform.masked_opaque, |
| 1215 | &view->transform.opaque, &mask); |
| 1216 | pixman_region32_fini(&mask); |
| 1217 | } |
| 1218 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1219 | weston_view_damage_below(view); |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 1220 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1221 | weston_view_assign_output(view); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 1222 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1223 | wl_signal_emit(&view->surface->compositor->transform_signal, |
| 1224 | view->surface); |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1225 | } |
| 1226 | |
Pekka Paalanen | ddae03c | 2012-02-06 14:54:20 +0200 | [diff] [blame] | 1227 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1228 | weston_view_geometry_dirty(struct weston_view *view) |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 1229 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1230 | struct weston_view *child; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1231 | |
| 1232 | /* |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1233 | * The invariant: if view->geometry.dirty, then all views |
| 1234 | * in view->geometry.child_list have geometry.dirty too. |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1235 | * Corollary: if not parent->geometry.dirty, then all ancestors |
| 1236 | * are not dirty. |
| 1237 | */ |
| 1238 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1239 | if (view->transform.dirty) |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1240 | return; |
| 1241 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1242 | view->transform.dirty = 1; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1243 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1244 | wl_list_for_each(child, &view->geometry.child_list, |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1245 | geometry.parent_link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1246 | weston_view_geometry_dirty(child); |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1250 | weston_view_to_global_fixed(struct weston_view *view, |
| 1251 | wl_fixed_t vx, wl_fixed_t vy, |
| 1252 | wl_fixed_t *x, wl_fixed_t *y) |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1253 | { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1254 | float xf, yf; |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1255 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1256 | weston_view_to_global_float(view, |
| 1257 | wl_fixed_to_double(vx), |
| 1258 | wl_fixed_to_double(vy), |
| 1259 | &xf, &yf); |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1260 | *x = wl_fixed_from_double(xf); |
| 1261 | *y = wl_fixed_from_double(yf); |
| 1262 | } |
| 1263 | |
Kristian Høgsberg | ecf6ede | 2012-09-05 21:59:35 -0400 | [diff] [blame] | 1264 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1265 | weston_view_from_global_float(struct weston_view *view, |
| 1266 | float x, float y, float *vx, float *vy) |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1267 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1268 | if (view->transform.enabled) { |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1269 | struct weston_vector v = { { x, y, 0.0f, 1.0f } }; |
| 1270 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1271 | weston_matrix_transform(&view->transform.inverse, &v); |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1272 | |
| 1273 | if (fabsf(v.f[3]) < 1e-6) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1274 | weston_log("warning: numerical instability in " |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1275 | "weston_view_from_global(), divisor = %g\n", |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1276 | v.f[3]); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1277 | *vx = 0; |
| 1278 | *vy = 0; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1279 | return; |
| 1280 | } |
| 1281 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1282 | *vx = v.f[0] / v.f[3]; |
| 1283 | *vy = v.f[1] / v.f[3]; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1284 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1285 | *vx = x - view->geometry.x; |
| 1286 | *vy = y - view->geometry.y; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1287 | } |
| 1288 | } |
| 1289 | |
| 1290 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1291 | weston_view_from_global_fixed(struct weston_view *view, |
| 1292 | wl_fixed_t x, wl_fixed_t y, |
| 1293 | wl_fixed_t *vx, wl_fixed_t *vy) |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1294 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1295 | float vxf, vyf; |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1296 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1297 | weston_view_from_global_float(view, |
| 1298 | wl_fixed_to_double(x), |
| 1299 | wl_fixed_to_double(y), |
| 1300 | &vxf, &vyf); |
| 1301 | *vx = wl_fixed_from_double(vxf); |
| 1302 | *vy = wl_fixed_from_double(vyf); |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1306 | weston_view_from_global(struct weston_view *view, |
| 1307 | int32_t x, int32_t y, int32_t *vx, int32_t *vy) |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1308 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1309 | float vxf, vyf; |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1310 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1311 | weston_view_from_global_float(view, x, y, &vxf, &vyf); |
| 1312 | *vx = floorf(vxf); |
| 1313 | *vy = floorf(vyf); |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1314 | } |
| 1315 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1316 | WL_EXPORT void |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1317 | weston_surface_schedule_repaint(struct weston_surface *surface) |
| 1318 | { |
| 1319 | struct weston_output *output; |
| 1320 | |
| 1321 | wl_list_for_each(output, &surface->compositor->output_list, link) |
| 1322 | if (surface->output_mask & (1 << output->id)) |
| 1323 | weston_output_schedule_repaint(output); |
| 1324 | } |
| 1325 | |
| 1326 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1327 | weston_view_schedule_repaint(struct weston_view *view) |
| 1328 | { |
| 1329 | struct weston_output *output; |
| 1330 | |
| 1331 | wl_list_for_each(output, &view->surface->compositor->output_list, link) |
| 1332 | if (view->output_mask & (1 << output->id)) |
| 1333 | weston_output_schedule_repaint(output); |
| 1334 | } |
| 1335 | |
| 1336 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1337 | weston_surface_damage(struct weston_surface *surface) |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 1338 | { |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1339 | pixman_region32_union_rect(&surface->damage, &surface->damage, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1340 | 0, 0, surface->width, |
| 1341 | surface->height); |
Pekka Paalanen | 2267d45 | 2012-01-26 13:12:45 +0200 | [diff] [blame] | 1342 | |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1343 | weston_surface_schedule_repaint(surface); |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 1344 | } |
| 1345 | |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 1346 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1347 | weston_view_set_position(struct weston_view *view, float x, float y) |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1348 | { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1349 | if (view->geometry.x == x && view->geometry.y == y) |
| 1350 | return; |
| 1351 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1352 | view->geometry.x = x; |
| 1353 | view->geometry.y = y; |
| 1354 | weston_view_geometry_dirty(view); |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1355 | } |
| 1356 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1357 | static void |
| 1358 | transform_parent_handle_parent_destroy(struct wl_listener *listener, |
| 1359 | void *data) |
| 1360 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1361 | struct weston_view *view = |
| 1362 | container_of(listener, struct weston_view, |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1363 | geometry.parent_destroy_listener); |
| 1364 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1365 | weston_view_set_transform_parent(view, NULL); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1369 | weston_view_set_transform_parent(struct weston_view *view, |
| 1370 | struct weston_view *parent) |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1371 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1372 | if (view->geometry.parent) { |
| 1373 | wl_list_remove(&view->geometry.parent_destroy_listener.link); |
| 1374 | wl_list_remove(&view->geometry.parent_link); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1375 | } |
| 1376 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1377 | view->geometry.parent = parent; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1378 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1379 | view->geometry.parent_destroy_listener.notify = |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1380 | transform_parent_handle_parent_destroy; |
| 1381 | if (parent) { |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1382 | wl_signal_add(&parent->destroy_signal, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1383 | &view->geometry.parent_destroy_listener); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1384 | wl_list_insert(&parent->geometry.child_list, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1385 | &view->geometry.parent_link); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1386 | } |
| 1387 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1388 | weston_view_geometry_dirty(view); |
| 1389 | } |
| 1390 | |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 1391 | WL_EXPORT bool |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1392 | weston_view_is_mapped(struct weston_view *view) |
| 1393 | { |
| 1394 | if (view->output) |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 1395 | return true; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1396 | else |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 1397 | return false; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1398 | } |
| 1399 | |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 1400 | WL_EXPORT bool |
Ander Conselvan de Oliveira | b8ab14f | 2012-03-27 17:36:36 +0300 | [diff] [blame] | 1401 | weston_surface_is_mapped(struct weston_surface *surface) |
| 1402 | { |
| 1403 | if (surface->output) |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 1404 | return true; |
Ander Conselvan de Oliveira | b8ab14f | 2012-03-27 17:36:36 +0300 | [diff] [blame] | 1405 | else |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 1406 | return false; |
Ander Conselvan de Oliveira | b8ab14f | 2012-03-27 17:36:36 +0300 | [diff] [blame] | 1407 | } |
| 1408 | |
Pekka Paalanen | da75ee1 | 2013-11-26 18:19:43 +0100 | [diff] [blame] | 1409 | static void |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 1410 | surface_set_size(struct weston_surface *surface, int32_t width, int32_t height) |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1411 | { |
| 1412 | struct weston_view *view; |
| 1413 | |
| 1414 | if (surface->width == width && surface->height == height) |
| 1415 | return; |
| 1416 | |
| 1417 | surface->width = width; |
| 1418 | surface->height = height; |
| 1419 | |
| 1420 | wl_list_for_each(view, &surface->views, surface_link) |
| 1421 | weston_view_geometry_dirty(view); |
| 1422 | } |
| 1423 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 1424 | WL_EXPORT void |
| 1425 | weston_surface_set_size(struct weston_surface *surface, |
| 1426 | int32_t width, int32_t height) |
| 1427 | { |
| 1428 | assert(!surface->resource); |
| 1429 | surface_set_size(surface, width, height); |
| 1430 | } |
| 1431 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1432 | static int |
| 1433 | fixed_round_up_to_int(wl_fixed_t f) |
| 1434 | { |
| 1435 | return wl_fixed_to_int(wl_fixed_from_int(1) - 1 + f); |
| 1436 | } |
| 1437 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1438 | static void |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1439 | weston_surface_calculate_size_from_buffer(struct weston_surface *surface) |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1440 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 1441 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Pekka Paalanen | da75ee1 | 2013-11-26 18:19:43 +0100 | [diff] [blame] | 1442 | int32_t width, height; |
| 1443 | |
| 1444 | if (!surface->buffer_ref.buffer) { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1445 | surface->width_from_buffer = 0; |
| 1446 | surface->height_from_buffer = 0; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 1447 | return; |
| 1448 | } |
| 1449 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 1450 | switch (vp->buffer.transform) { |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1451 | case WL_OUTPUT_TRANSFORM_90: |
| 1452 | case WL_OUTPUT_TRANSFORM_270: |
| 1453 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 1454 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1455 | width = surface->buffer_ref.buffer->height / vp->buffer.scale; |
| 1456 | height = surface->buffer_ref.buffer->width / vp->buffer.scale; |
Pekka Paalanen | da75ee1 | 2013-11-26 18:19:43 +0100 | [diff] [blame] | 1457 | break; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1458 | default: |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1459 | width = surface->buffer_ref.buffer->width / vp->buffer.scale; |
| 1460 | height = surface->buffer_ref.buffer->height / vp->buffer.scale; |
Pekka Paalanen | da75ee1 | 2013-11-26 18:19:43 +0100 | [diff] [blame] | 1461 | break; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1462 | } |
Pekka Paalanen | da75ee1 | 2013-11-26 18:19:43 +0100 | [diff] [blame] | 1463 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1464 | surface->width_from_buffer = width; |
| 1465 | surface->height_from_buffer = height; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1466 | } |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1467 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1468 | static void |
| 1469 | weston_surface_update_size(struct weston_surface *surface) |
| 1470 | { |
| 1471 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
| 1472 | int32_t width, height; |
| 1473 | |
| 1474 | width = surface->width_from_buffer; |
| 1475 | height = surface->height_from_buffer; |
| 1476 | |
| 1477 | if (width != 0 && vp->surface.width != -1) { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1478 | surface_set_size(surface, |
| 1479 | vp->surface.width, vp->surface.height); |
| 1480 | return; |
| 1481 | } |
| 1482 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1483 | if (width != 0 && vp->buffer.src_width != wl_fixed_from_int(-1)) { |
Pekka Paalanen | e931721 | 2014-04-04 14:22:13 +0300 | [diff] [blame] | 1484 | int32_t w = fixed_round_up_to_int(vp->buffer.src_width); |
| 1485 | int32_t h = fixed_round_up_to_int(vp->buffer.src_height); |
| 1486 | |
| 1487 | surface_set_size(surface, w ?: 1, h ?: 1); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1488 | return; |
| 1489 | } |
| 1490 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 1491 | surface_set_size(surface, width, height); |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1492 | } |
| 1493 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1494 | WL_EXPORT uint32_t |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1495 | weston_compositor_get_time(void) |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 1496 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1497 | struct timeval tv; |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 1498 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1499 | gettimeofday(&tv, NULL); |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 1500 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1501 | return tv.tv_sec * 1000 + tv.tv_usec / 1000; |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 1502 | } |
| 1503 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1504 | WL_EXPORT struct weston_view * |
| 1505 | weston_compositor_pick_view(struct weston_compositor *compositor, |
| 1506 | wl_fixed_t x, wl_fixed_t y, |
| 1507 | wl_fixed_t *vx, wl_fixed_t *vy) |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 1508 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1509 | struct weston_view *view; |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1510 | int ix = wl_fixed_to_int(x); |
| 1511 | int iy = wl_fixed_to_int(y); |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 1512 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1513 | wl_list_for_each(view, &compositor->view_list, link) { |
| 1514 | weston_view_from_global_fixed(view, x, y, vx, vy); |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1515 | if (pixman_region32_contains_point( |
| 1516 | &view->transform.masked_boundingbox, |
| 1517 | ix, iy, NULL) && |
| 1518 | pixman_region32_contains_point(&view->surface->input, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1519 | wl_fixed_to_int(*vx), |
| 1520 | wl_fixed_to_int(*vy), |
Daniel Stone | 103db7f | 2012-05-08 17:17:55 +0100 | [diff] [blame] | 1521 | NULL)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1522 | return view; |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | return NULL; |
| 1526 | } |
| 1527 | |
| 1528 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1529 | weston_compositor_repick(struct weston_compositor *compositor) |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 1530 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1531 | struct weston_seat *seat; |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 1532 | |
Kristian Høgsberg | 10ddd97 | 2013-10-22 12:40:54 -0700 | [diff] [blame] | 1533 | if (!compositor->session_active) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1534 | return; |
| 1535 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1536 | wl_list_for_each(seat, &compositor->seat_list, link) |
Kristian Høgsberg | a71e8b2 | 2013-05-06 21:51:21 -0400 | [diff] [blame] | 1537 | weston_seat_repick(seat); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 1538 | } |
| 1539 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1540 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1541 | weston_view_unmap(struct weston_view *view) |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 1542 | { |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 1543 | struct weston_seat *seat; |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 1544 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1545 | if (!weston_view_is_mapped(view)) |
| 1546 | return; |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 1547 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1548 | weston_view_damage_below(view); |
| 1549 | view->output = NULL; |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 1550 | view->plane = NULL; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1551 | weston_layer_entry_remove(&view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1552 | wl_list_remove(&view->link); |
| 1553 | wl_list_init(&view->link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1554 | view->output_mask = 0; |
| 1555 | weston_surface_assign_output(view->surface); |
| 1556 | |
| 1557 | if (weston_surface_is_mapped(view->surface)) |
| 1558 | return; |
| 1559 | |
| 1560 | wl_list_for_each(seat, &view->surface->compositor->seat_list, link) { |
| 1561 | if (seat->keyboard && seat->keyboard->focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1562 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1563 | if (seat->pointer && seat->pointer->focus == view) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1564 | weston_pointer_set_focus(seat->pointer, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1565 | NULL, |
| 1566 | wl_fixed_from_int(0), |
| 1567 | wl_fixed_from_int(0)); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1568 | if (seat->touch && seat->touch->focus == view) |
Michael Fu | a2bb791 | 2013-07-23 15:51:06 +0800 | [diff] [blame] | 1569 | weston_touch_set_focus(seat, NULL); |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 1570 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1571 | } |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 1572 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1573 | WL_EXPORT void |
| 1574 | weston_surface_unmap(struct weston_surface *surface) |
| 1575 | { |
| 1576 | struct weston_view *view; |
| 1577 | |
| 1578 | wl_list_for_each(view, &surface->views, surface_link) |
| 1579 | weston_view_unmap(view); |
| 1580 | surface->output = NULL; |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 1581 | } |
| 1582 | |
Pekka Paalanen | 3c9b802 | 2014-03-14 14:38:13 +0200 | [diff] [blame] | 1583 | static void |
| 1584 | weston_surface_reset_pending_buffer(struct weston_surface *surface) |
| 1585 | { |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 1586 | weston_surface_state_set_buffer(&surface->pending, NULL); |
Pekka Paalanen | 3c9b802 | 2014-03-14 14:38:13 +0200 | [diff] [blame] | 1587 | surface->pending.sx = 0; |
| 1588 | surface->pending.sy = 0; |
| 1589 | surface->pending.newly_attached = 0; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1590 | surface->pending.buffer_viewport.changed = 0; |
Pekka Paalanen | 3c9b802 | 2014-03-14 14:38:13 +0200 | [diff] [blame] | 1591 | } |
| 1592 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1593 | WL_EXPORT void |
| 1594 | weston_view_destroy(struct weston_view *view) |
| 1595 | { |
| 1596 | wl_signal_emit(&view->destroy_signal, view); |
| 1597 | |
| 1598 | assert(wl_list_empty(&view->geometry.child_list)); |
| 1599 | |
| 1600 | if (weston_view_is_mapped(view)) { |
| 1601 | weston_view_unmap(view); |
| 1602 | weston_compositor_build_view_list(view->surface->compositor); |
| 1603 | } |
| 1604 | |
| 1605 | wl_list_remove(&view->link); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1606 | weston_layer_entry_remove(&view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1607 | |
| 1608 | pixman_region32_fini(&view->clip); |
| 1609 | pixman_region32_fini(&view->transform.boundingbox); |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1610 | pixman_region32_fini(&view->transform.masked_boundingbox); |
| 1611 | pixman_region32_fini(&view->transform.masked_opaque); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1612 | |
| 1613 | weston_view_set_transform_parent(view, NULL); |
| 1614 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1615 | wl_list_remove(&view->surface_link); |
| 1616 | |
| 1617 | free(view); |
| 1618 | } |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1619 | |
| 1620 | WL_EXPORT void |
| 1621 | weston_surface_destroy(struct weston_surface *surface) |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 1622 | { |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 1623 | struct weston_frame_callback *cb, *next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1624 | struct weston_view *ev, *nv; |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 1625 | |
Giulio Camuffo | 13b85bd | 2013-08-13 23:10:14 +0200 | [diff] [blame] | 1626 | if (--surface->ref_count > 0) |
| 1627 | return; |
| 1628 | |
| 1629 | wl_signal_emit(&surface->destroy_signal, &surface->resource); |
| 1630 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1631 | assert(wl_list_empty(&surface->subsurface_list_pending)); |
| 1632 | assert(wl_list_empty(&surface->subsurface_list)); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1633 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1634 | wl_list_for_each_safe(ev, nv, &surface->views, surface_link) |
| 1635 | weston_view_destroy(ev); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 1636 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 1637 | weston_surface_state_fini(&surface->pending); |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1638 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1639 | weston_buffer_reference(&surface->buffer_ref, NULL); |
Kristian Høgsberg | 3f8f39c | 2009-09-18 17:05:13 -0400 | [diff] [blame] | 1640 | |
Pekka Paalanen | 402ae6d | 2012-01-03 10:23:24 +0200 | [diff] [blame] | 1641 | pixman_region32_fini(&surface->damage); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1642 | pixman_region32_fini(&surface->opaque); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 1643 | pixman_region32_fini(&surface->input); |
Pekka Paalanen | 402ae6d | 2012-01-03 10:23:24 +0200 | [diff] [blame] | 1644 | |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 1645 | wl_list_for_each_safe(cb, next, &surface->frame_callback_list, link) |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 1646 | wl_resource_destroy(cb->resource); |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 1647 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 1648 | weston_presentation_feedback_discard_list(&surface->feedback_list); |
| 1649 | |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 1650 | free(surface); |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 1651 | } |
| 1652 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1653 | static void |
| 1654 | destroy_surface(struct wl_resource *resource) |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 1655 | { |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1656 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 1657 | |
Giulio Camuffo | 0d37974 | 2013-11-15 22:06:15 +0100 | [diff] [blame] | 1658 | /* Set the resource to NULL, since we don't want to leave a |
| 1659 | * dangling pointer if the surface was refcounted and survives |
| 1660 | * the weston_surface_destroy() call. */ |
| 1661 | surface->resource = NULL; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1662 | weston_surface_destroy(surface); |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 1663 | } |
| 1664 | |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 1665 | static void |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1666 | weston_buffer_destroy_handler(struct wl_listener *listener, void *data) |
| 1667 | { |
| 1668 | struct weston_buffer *buffer = |
| 1669 | container_of(listener, struct weston_buffer, destroy_listener); |
| 1670 | |
| 1671 | wl_signal_emit(&buffer->destroy_signal, buffer); |
| 1672 | free(buffer); |
| 1673 | } |
| 1674 | |
Giulio Camuffo | e058cd1 | 2013-12-12 14:14:29 +0100 | [diff] [blame] | 1675 | WL_EXPORT struct weston_buffer * |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1676 | weston_buffer_from_resource(struct wl_resource *resource) |
| 1677 | { |
| 1678 | struct weston_buffer *buffer; |
| 1679 | struct wl_listener *listener; |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 1680 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1681 | listener = wl_resource_get_destroy_listener(resource, |
| 1682 | weston_buffer_destroy_handler); |
| 1683 | |
Kristian Høgsberg | 08b58c7 | 2013-08-15 12:26:42 -0700 | [diff] [blame] | 1684 | if (listener) |
| 1685 | return container_of(listener, struct weston_buffer, |
| 1686 | destroy_listener); |
| 1687 | |
| 1688 | buffer = zalloc(sizeof *buffer); |
| 1689 | if (buffer == NULL) |
| 1690 | return NULL; |
| 1691 | |
| 1692 | buffer->resource = resource; |
| 1693 | wl_signal_init(&buffer->destroy_signal); |
| 1694 | buffer->destroy_listener.notify = weston_buffer_destroy_handler; |
Stanislav Vorobiov | bfbb8e5 | 2013-08-29 11:36:44 +0400 | [diff] [blame] | 1695 | buffer->y_inverted = 1; |
Kristian Høgsberg | 08b58c7 | 2013-08-15 12:26:42 -0700 | [diff] [blame] | 1696 | wl_resource_add_destroy_listener(resource, &buffer->destroy_listener); |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 1697 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1698 | return buffer; |
| 1699 | } |
| 1700 | |
| 1701 | static void |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1702 | weston_buffer_reference_handle_destroy(struct wl_listener *listener, |
| 1703 | void *data) |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 1704 | { |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1705 | struct weston_buffer_reference *ref = |
| 1706 | container_of(listener, struct weston_buffer_reference, |
| 1707 | destroy_listener); |
| 1708 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1709 | assert((struct weston_buffer *)data == ref->buffer); |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1710 | ref->buffer = NULL; |
| 1711 | } |
| 1712 | |
| 1713 | WL_EXPORT void |
| 1714 | weston_buffer_reference(struct weston_buffer_reference *ref, |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1715 | struct weston_buffer *buffer) |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1716 | { |
| 1717 | if (ref->buffer && buffer != ref->buffer) { |
Kristian Høgsberg | 2034780 | 2013-03-04 12:07:46 -0500 | [diff] [blame] | 1718 | ref->buffer->busy_count--; |
| 1719 | if (ref->buffer->busy_count == 0) { |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1720 | assert(wl_resource_get_client(ref->buffer->resource)); |
| 1721 | wl_resource_queue_event(ref->buffer->resource, |
Kristian Høgsberg | 2034780 | 2013-03-04 12:07:46 -0500 | [diff] [blame] | 1722 | WL_BUFFER_RELEASE); |
| 1723 | } |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1724 | wl_list_remove(&ref->destroy_listener.link); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 1725 | } |
| 1726 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1727 | if (buffer && buffer != ref->buffer) { |
Kristian Høgsberg | b7b77e6 | 2012-09-05 22:38:18 -0400 | [diff] [blame] | 1728 | buffer->busy_count++; |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1729 | wl_signal_add(&buffer->destroy_signal, |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1730 | &ref->destroy_listener); |
Pekka Paalanen | a6421c4 | 2012-12-04 15:58:10 +0200 | [diff] [blame] | 1731 | } |
| 1732 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1733 | ref->buffer = buffer; |
| 1734 | ref->destroy_listener.notify = weston_buffer_reference_handle_destroy; |
| 1735 | } |
| 1736 | |
| 1737 | static void |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1738 | weston_surface_attach(struct weston_surface *surface, |
| 1739 | struct weston_buffer *buffer) |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1740 | { |
| 1741 | weston_buffer_reference(&surface->buffer_ref, buffer); |
| 1742 | |
Pekka Paalanen | a6421c4 | 2012-12-04 15:58:10 +0200 | [diff] [blame] | 1743 | if (!buffer) { |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1744 | if (weston_surface_is_mapped(surface)) |
| 1745 | weston_surface_unmap(surface); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 1746 | } |
| 1747 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1748 | surface->compositor->renderer->attach(surface, buffer); |
Pekka Paalanen | bb2f3f2 | 2014-03-14 14:38:11 +0200 | [diff] [blame] | 1749 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1750 | weston_surface_calculate_size_from_buffer(surface); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 1751 | weston_presentation_feedback_discard_list(&surface->feedback_list); |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 1752 | } |
| 1753 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1754 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1755 | weston_compositor_damage_all(struct weston_compositor *compositor) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1756 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1757 | struct weston_output *output; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1758 | |
| 1759 | wl_list_for_each(output, &compositor->output_list, link) |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1760 | weston_output_damage(output); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1761 | } |
| 1762 | |
Kristian Høgsberg | 9f404b7 | 2012-01-26 00:11:01 -0500 | [diff] [blame] | 1763 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1764 | weston_output_damage(struct weston_output *output) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1765 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1766 | struct weston_compositor *compositor = output->compositor; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1767 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1768 | pixman_region32_union(&compositor->primary_plane.damage, |
| 1769 | &compositor->primary_plane.damage, |
| 1770 | &output->region); |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 1771 | weston_output_schedule_repaint(output); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1772 | } |
| 1773 | |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame] | 1774 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1775 | surface_flush_damage(struct weston_surface *surface) |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1776 | { |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1777 | if (surface->buffer_ref.buffer && |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1778 | wl_shm_buffer_get(surface->buffer_ref.buffer->resource)) |
Kristian Høgsberg | fa1be02 | 2012-09-05 22:49:55 -0400 | [diff] [blame] | 1779 | surface->compositor->renderer->flush_damage(surface); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1780 | |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 1781 | pixman_region32_clear(&surface->damage); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | static void |
| 1785 | view_accumulate_damage(struct weston_view *view, |
| 1786 | pixman_region32_t *opaque) |
| 1787 | { |
| 1788 | pixman_region32_t damage; |
| 1789 | |
| 1790 | pixman_region32_init(&damage); |
| 1791 | if (view->transform.enabled) { |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1792 | pixman_box32_t *extents; |
| 1793 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1794 | extents = pixman_region32_extents(&view->surface->damage); |
| 1795 | view_compute_bbox(view, extents->x1, extents->y1, |
| 1796 | extents->x2 - extents->x1, |
| 1797 | extents->y2 - extents->y1, |
| 1798 | &damage); |
| 1799 | pixman_region32_translate(&damage, |
| 1800 | -view->plane->x, |
| 1801 | -view->plane->y); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1802 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1803 | pixman_region32_copy(&damage, &view->surface->damage); |
| 1804 | pixman_region32_translate(&damage, |
| 1805 | view->geometry.x - view->plane->x, |
| 1806 | view->geometry.y - view->plane->y); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1807 | } |
| 1808 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1809 | pixman_region32_subtract(&damage, &damage, opaque); |
| 1810 | pixman_region32_union(&view->plane->damage, |
| 1811 | &view->plane->damage, &damage); |
| 1812 | pixman_region32_fini(&damage); |
| 1813 | pixman_region32_copy(&view->clip, opaque); |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1814 | pixman_region32_union(opaque, opaque, &view->transform.masked_opaque); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1815 | } |
| 1816 | |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 1817 | static void |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 1818 | compositor_accumulate_damage(struct weston_compositor *ec) |
| 1819 | { |
| 1820 | struct weston_plane *plane; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1821 | struct weston_view *ev; |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 1822 | pixman_region32_t opaque, clip; |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 1823 | |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 1824 | pixman_region32_init(&clip); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 1825 | |
| 1826 | wl_list_for_each(plane, &ec->plane_list, link) { |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 1827 | pixman_region32_copy(&plane->clip, &clip); |
| 1828 | |
| 1829 | pixman_region32_init(&opaque); |
| 1830 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1831 | wl_list_for_each(ev, &ec->view_list, link) { |
| 1832 | if (ev->plane != plane) |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 1833 | continue; |
| 1834 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1835 | view_accumulate_damage(ev, &opaque); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 1836 | } |
| 1837 | |
| 1838 | pixman_region32_union(&clip, &clip, &opaque); |
| 1839 | pixman_region32_fini(&opaque); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 1840 | } |
| 1841 | |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 1842 | pixman_region32_fini(&clip); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 1843 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1844 | wl_list_for_each(ev, &ec->view_list, link) |
| 1845 | ev->surface->touched = 0; |
| 1846 | |
| 1847 | wl_list_for_each(ev, &ec->view_list, link) { |
| 1848 | if (ev->surface->touched) |
| 1849 | continue; |
| 1850 | ev->surface->touched = 1; |
| 1851 | |
| 1852 | surface_flush_damage(ev->surface); |
| 1853 | |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 1854 | /* Both the renderer and the backend have seen the buffer |
| 1855 | * by now. If renderer needs the buffer, it has its own |
| 1856 | * reference set. If the backend wants to keep the buffer |
| 1857 | * around for migrating the surface into a non-primary plane |
| 1858 | * later, keep_buffer is true. Otherwise, drop the core |
| 1859 | * reference now, and allow early buffer release. This enables |
| 1860 | * clients to use single-buffering. |
| 1861 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1862 | if (!ev->surface->keep_buffer) |
| 1863 | weston_buffer_reference(&ev->surface->buffer_ref, NULL); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 1864 | } |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 1865 | } |
| 1866 | |
| 1867 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1868 | surface_stash_subsurface_views(struct weston_surface *surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1869 | { |
| 1870 | struct weston_subsurface *sub; |
| 1871 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1872 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1873 | if (sub->surface == surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1874 | continue; |
| 1875 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1876 | wl_list_insert_list(&sub->unused_views, &sub->surface->views); |
| 1877 | wl_list_init(&sub->surface->views); |
| 1878 | |
| 1879 | surface_stash_subsurface_views(sub->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1880 | } |
| 1881 | } |
| 1882 | |
| 1883 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1884 | surface_free_unused_subsurface_views(struct weston_surface *surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1885 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1886 | struct weston_subsurface *sub; |
| 1887 | struct weston_view *view, *nv; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1888 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1889 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
| 1890 | if (sub->surface == surface) |
| 1891 | continue; |
| 1892 | |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 1893 | wl_list_for_each_safe(view, nv, &sub->unused_views, surface_link) { |
| 1894 | weston_view_unmap (view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1895 | weston_view_destroy(view); |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 1896 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1897 | |
| 1898 | surface_free_unused_subsurface_views(sub->surface); |
| 1899 | } |
| 1900 | } |
| 1901 | |
| 1902 | static void |
| 1903 | view_list_add_subsurface_view(struct weston_compositor *compositor, |
| 1904 | struct weston_subsurface *sub, |
| 1905 | struct weston_view *parent) |
| 1906 | { |
| 1907 | struct weston_subsurface *child; |
| 1908 | struct weston_view *view = NULL, *iv; |
| 1909 | |
Pekka Paalanen | 661de3a | 2014-07-28 12:49:24 +0300 | [diff] [blame] | 1910 | if (!weston_surface_is_mapped(sub->surface)) |
| 1911 | return; |
| 1912 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1913 | wl_list_for_each(iv, &sub->unused_views, surface_link) { |
| 1914 | if (iv->geometry.parent == parent) { |
| 1915 | view = iv; |
| 1916 | break; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1917 | } |
| 1918 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1919 | |
| 1920 | if (view) { |
| 1921 | /* Put it back in the surface's list of views */ |
| 1922 | wl_list_remove(&view->surface_link); |
| 1923 | wl_list_insert(&sub->surface->views, &view->surface_link); |
| 1924 | } else { |
| 1925 | view = weston_view_create(sub->surface); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1926 | weston_view_set_position(view, |
| 1927 | sub->position.x, |
| 1928 | sub->position.y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1929 | weston_view_set_transform_parent(view, parent); |
| 1930 | } |
| 1931 | |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1932 | view->parent_view = parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1933 | weston_view_update_transform(view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1934 | |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 1935 | if (wl_list_empty(&sub->surface->subsurface_list)) { |
| 1936 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 1937 | return; |
| 1938 | } |
| 1939 | |
| 1940 | wl_list_for_each(child, &sub->surface->subsurface_list, parent_link) { |
| 1941 | if (child->surface == sub->surface) |
| 1942 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 1943 | else |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1944 | view_list_add_subsurface_view(compositor, child, view); |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 1945 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1946 | } |
| 1947 | |
| 1948 | static void |
| 1949 | view_list_add(struct weston_compositor *compositor, |
| 1950 | struct weston_view *view) |
| 1951 | { |
| 1952 | struct weston_subsurface *sub; |
| 1953 | |
| 1954 | weston_view_update_transform(view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1955 | |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 1956 | if (wl_list_empty(&view->surface->subsurface_list)) { |
| 1957 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 1958 | return; |
| 1959 | } |
| 1960 | |
| 1961 | wl_list_for_each(sub, &view->surface->subsurface_list, parent_link) { |
| 1962 | if (sub->surface == view->surface) |
| 1963 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 1964 | else |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1965 | view_list_add_subsurface_view(compositor, sub, view); |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 1966 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | static void |
| 1970 | weston_compositor_build_view_list(struct weston_compositor *compositor) |
| 1971 | { |
| 1972 | struct weston_view *view; |
| 1973 | struct weston_layer *layer; |
| 1974 | |
| 1975 | wl_list_for_each(layer, &compositor->layer_list, link) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1976 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1977 | surface_stash_subsurface_views(view->surface); |
| 1978 | |
| 1979 | wl_list_init(&compositor->view_list); |
| 1980 | wl_list_for_each(layer, &compositor->layer_list, link) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1981 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1982 | view_list_add(compositor, view); |
| 1983 | } |
| 1984 | } |
| 1985 | |
| 1986 | wl_list_for_each(layer, &compositor->layer_list, link) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1987 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1988 | surface_free_unused_subsurface_views(view->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1989 | } |
| 1990 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 1991 | static int |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 1992 | weston_output_repaint(struct weston_output *output) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 1993 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1994 | struct weston_compositor *ec = output->compositor; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1995 | struct weston_view *ev; |
Kristian Høgsberg | 30c018b | 2012-01-26 08:40:37 -0500 | [diff] [blame] | 1996 | struct weston_animation *animation, *next; |
| 1997 | struct weston_frame_callback *cb, *cnext; |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 1998 | struct wl_list frame_callback_list; |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 1999 | pixman_region32_t output_damage; |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2000 | int r; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 2001 | |
Ander Conselvan de Oliveira | e1e2352 | 2013-12-13 22:10:55 +0200 | [diff] [blame] | 2002 | if (output->destroying) |
| 2003 | return 0; |
| 2004 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2005 | /* Rebuild the surface list and update surface transforms up front. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2006 | weston_compositor_build_view_list(ec); |
Pekka Paalanen | 15d60ef | 2012-01-27 14:38:33 +0200 | [diff] [blame] | 2007 | |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 2008 | if (output->assign_planes && !output->disable_planes) |
Jesse Barnes | 5308a5e | 2012-02-09 13:12:57 -0800 | [diff] [blame] | 2009 | output->assign_planes(output); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 2010 | else |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2011 | wl_list_for_each(ev, &ec->view_list, link) |
| 2012 | weston_view_move_to_plane(ev, &ec->primary_plane); |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 2013 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2014 | wl_list_init(&frame_callback_list); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2015 | wl_list_for_each(ev, &ec->view_list, link) { |
| 2016 | /* Note: This operation is safe to do multiple times on the |
| 2017 | * same surface. |
| 2018 | */ |
| 2019 | if (ev->surface->output == output) { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2020 | wl_list_insert_list(&frame_callback_list, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2021 | &ev->surface->frame_callback_list); |
| 2022 | wl_list_init(&ev->surface->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2023 | |
| 2024 | wl_list_insert_list(&output->feedback_list, |
| 2025 | &ev->surface->feedback_list); |
| 2026 | wl_list_init(&ev->surface->feedback_list); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2027 | } |
| 2028 | } |
| 2029 | |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2030 | compositor_accumulate_damage(ec); |
Kristian Høgsberg | 53df1d8 | 2011-06-23 21:11:19 -0400 | [diff] [blame] | 2031 | |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 2032 | pixman_region32_init(&output_damage); |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 2033 | pixman_region32_intersect(&output_damage, |
| 2034 | &ec->primary_plane.damage, &output->region); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2035 | pixman_region32_subtract(&output_damage, |
| 2036 | &output_damage, &ec->primary_plane.clip); |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 2037 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2038 | if (output->dirty) |
| 2039 | weston_output_update_matrix(output); |
| 2040 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2041 | r = output->repaint(output, &output_damage); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2042 | |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 2043 | pixman_region32_fini(&output_damage); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 2044 | |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2045 | output->repaint_needed = 0; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 2046 | |
Kristian Høgsberg | aa6019e | 2012-03-11 16:35:16 -0400 | [diff] [blame] | 2047 | weston_compositor_repick(ec); |
| 2048 | wl_event_loop_dispatch(ec->input_loop, 0); |
| 2049 | |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 2050 | wl_list_for_each_safe(cb, cnext, &frame_callback_list, link) { |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 2051 | wl_callback_send_done(cb->resource, output->frame_time); |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 2052 | wl_resource_destroy(cb->resource); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 2053 | } |
| 2054 | |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 2055 | wl_list_for_each_safe(animation, next, &output->animation_list, link) { |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 2056 | animation->frame_counter++; |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 2057 | animation->frame(animation, output, output->frame_time); |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 2058 | } |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2059 | |
| 2060 | return r; |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2061 | } |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 2062 | |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2063 | static int |
| 2064 | weston_compositor_read_input(int fd, uint32_t mask, void *data) |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2065 | { |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2066 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | 34f80ff | 2012-01-18 11:50:31 -0500 | [diff] [blame] | 2067 | |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2068 | wl_event_loop_dispatch(compositor->input_loop, 0); |
| 2069 | |
| 2070 | return 1; |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2071 | } |
| 2072 | |
| 2073 | WL_EXPORT void |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 2074 | weston_output_finish_frame(struct weston_output *output, |
| 2075 | const struct timespec *stamp) |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2076 | { |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2077 | struct weston_compositor *compositor = output->compositor; |
| 2078 | struct wl_event_loop *loop = |
| 2079 | wl_display_get_event_loop(compositor->wl_display); |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2080 | int fd, r; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2081 | uint32_t refresh_nsec; |
| 2082 | |
| 2083 | refresh_nsec = 1000000000000UL / output->current_mode->refresh; |
| 2084 | weston_presentation_feedback_present_list(&output->feedback_list, |
| 2085 | output, refresh_nsec, stamp, |
Pekka Paalanen | 641307c | 2014-09-23 22:08:47 -0400 | [diff] [blame] | 2086 | output->msc); |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2087 | |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 2088 | output->frame_time = stamp->tv_sec * 1000 + stamp->tv_nsec / 1000000; |
Kristian Høgsberg | 991810c | 2013-10-16 11:10:12 -0700 | [diff] [blame] | 2089 | |
| 2090 | if (output->repaint_needed && |
| 2091 | compositor->state != WESTON_COMPOSITOR_SLEEPING && |
| 2092 | compositor->state != WESTON_COMPOSITOR_OFFSCREEN) { |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 2093 | r = weston_output_repaint(output); |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2094 | if (!r) |
| 2095 | return; |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2096 | } |
| 2097 | |
| 2098 | output->repaint_scheduled = 0; |
| 2099 | if (compositor->input_loop_source) |
| 2100 | return; |
| 2101 | |
| 2102 | fd = wl_event_loop_get_fd(compositor->input_loop); |
| 2103 | compositor->input_loop_source = |
| 2104 | wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE, |
| 2105 | weston_compositor_read_input, compositor); |
| 2106 | } |
| 2107 | |
| 2108 | static void |
| 2109 | idle_repaint(void *data) |
| 2110 | { |
| 2111 | struct weston_output *output = data; |
| 2112 | |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 2113 | output->start_repaint_loop(output); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2114 | } |
| 2115 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2116 | WL_EXPORT void |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2117 | weston_layer_entry_insert(struct weston_layer_entry *list, |
| 2118 | struct weston_layer_entry *entry) |
| 2119 | { |
| 2120 | wl_list_insert(&list->link, &entry->link); |
| 2121 | entry->layer = list->layer; |
| 2122 | } |
| 2123 | |
| 2124 | WL_EXPORT void |
| 2125 | weston_layer_entry_remove(struct weston_layer_entry *entry) |
| 2126 | { |
| 2127 | wl_list_remove(&entry->link); |
| 2128 | wl_list_init(&entry->link); |
| 2129 | entry->layer = NULL; |
| 2130 | } |
| 2131 | |
| 2132 | WL_EXPORT void |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2133 | weston_layer_init(struct weston_layer *layer, struct wl_list *below) |
| 2134 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2135 | wl_list_init(&layer->view_list.link); |
| 2136 | layer->view_list.layer = layer; |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 2137 | weston_layer_set_mask_infinite(layer); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 2138 | if (below != NULL) |
| 2139 | wl_list_insert(below, &layer->link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2140 | } |
| 2141 | |
| 2142 | WL_EXPORT void |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 2143 | weston_layer_set_mask(struct weston_layer *layer, |
| 2144 | int x, int y, int width, int height) |
| 2145 | { |
| 2146 | struct weston_view *view; |
| 2147 | |
| 2148 | layer->mask.x1 = x; |
| 2149 | layer->mask.x2 = x + width; |
| 2150 | layer->mask.y1 = y; |
| 2151 | layer->mask.y2 = y + height; |
| 2152 | |
| 2153 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
| 2154 | weston_view_geometry_dirty(view); |
| 2155 | } |
| 2156 | } |
| 2157 | |
| 2158 | WL_EXPORT void |
| 2159 | weston_layer_set_mask_infinite(struct weston_layer *layer) |
| 2160 | { |
| 2161 | weston_layer_set_mask(layer, INT32_MIN, INT32_MIN, |
| 2162 | UINT32_MAX, UINT32_MAX); |
| 2163 | } |
| 2164 | |
| 2165 | WL_EXPORT void |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2166 | weston_output_schedule_repaint(struct weston_output *output) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2167 | { |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2168 | struct weston_compositor *compositor = output->compositor; |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2169 | struct wl_event_loop *loop; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 2170 | |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 2171 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING || |
| 2172 | compositor->state == WESTON_COMPOSITOR_OFFSCREEN) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2173 | return; |
| 2174 | |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2175 | loop = wl_display_get_event_loop(compositor->wl_display); |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2176 | output->repaint_needed = 1; |
| 2177 | if (output->repaint_scheduled) |
| 2178 | return; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 2179 | |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2180 | wl_event_loop_add_idle(loop, idle_repaint, output); |
| 2181 | output->repaint_scheduled = 1; |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2182 | |
| 2183 | if (compositor->input_loop_source) { |
| 2184 | wl_event_source_remove(compositor->input_loop_source); |
| 2185 | compositor->input_loop_source = NULL; |
| 2186 | } |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2187 | } |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 2188 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2189 | WL_EXPORT void |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2190 | weston_compositor_schedule_repaint(struct weston_compositor *compositor) |
| 2191 | { |
| 2192 | struct weston_output *output; |
| 2193 | |
| 2194 | wl_list_for_each(output, &compositor->output_list, link) |
| 2195 | weston_output_schedule_repaint(output); |
| 2196 | } |
| 2197 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 2198 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 2199 | surface_destroy(struct wl_client *client, struct wl_resource *resource) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 2200 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2201 | wl_resource_destroy(resource); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 2202 | } |
| 2203 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 2204 | static void |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2205 | surface_attach(struct wl_client *client, |
| 2206 | struct wl_resource *resource, |
| 2207 | struct wl_resource *buffer_resource, int32_t sx, int32_t sy) |
| 2208 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2209 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2210 | struct weston_buffer *buffer = NULL; |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2211 | |
Kristian Høgsberg | ab19f93 | 2013-08-20 11:30:54 -0700 | [diff] [blame] | 2212 | if (buffer_resource) { |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2213 | buffer = weston_buffer_from_resource(buffer_resource); |
Kristian Høgsberg | ab19f93 | 2013-08-20 11:30:54 -0700 | [diff] [blame] | 2214 | if (buffer == NULL) { |
| 2215 | wl_client_post_no_memory(client); |
| 2216 | return; |
| 2217 | } |
Kristian Høgsberg | 08b58c7 | 2013-08-15 12:26:42 -0700 | [diff] [blame] | 2218 | } |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 2219 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2220 | /* Attach, attach, without commit in between does not send |
| 2221 | * wl_buffer.release. */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2222 | weston_surface_state_set_buffer(&surface->pending, buffer); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2223 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2224 | surface->pending.sx = sx; |
| 2225 | surface->pending.sy = sy; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2226 | surface->pending.newly_attached = 1; |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 2227 | } |
| 2228 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 2229 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2230 | surface_damage(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 2231 | struct wl_resource *resource, |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2232 | 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] | 2233 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2234 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 9d69f8e | 2010-09-03 14:46:38 -0400 | [diff] [blame] | 2235 | |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 2236 | pixman_region32_union_rect(&surface->pending.damage, |
| 2237 | &surface->pending.damage, |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2238 | x, y, width, height); |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 2239 | } |
| 2240 | |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2241 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 2242 | destroy_frame_callback(struct wl_resource *resource) |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2243 | { |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 2244 | struct weston_frame_callback *cb = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 2245 | |
| 2246 | wl_list_remove(&cb->link); |
Pekka Paalanen | 8c19645 | 2011-11-15 11:45:42 +0200 | [diff] [blame] | 2247 | free(cb); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2248 | } |
| 2249 | |
| 2250 | static void |
| 2251 | surface_frame(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 2252 | struct wl_resource *resource, uint32_t callback) |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2253 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2254 | struct weston_frame_callback *cb; |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2255 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2256 | |
| 2257 | cb = malloc(sizeof *cb); |
| 2258 | if (cb == NULL) { |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 2259 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2260 | return; |
| 2261 | } |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 2262 | |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 2263 | cb->resource = wl_resource_create(client, &wl_callback_interface, 1, |
| 2264 | callback); |
| 2265 | if (cb->resource == NULL) { |
| 2266 | free(cb); |
| 2267 | wl_resource_post_no_memory(resource); |
| 2268 | return; |
| 2269 | } |
| 2270 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 2271 | wl_resource_set_implementation(cb->resource, NULL, cb, |
| 2272 | destroy_frame_callback); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2273 | |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 2274 | wl_list_insert(surface->pending.frame_callback_list.prev, &cb->link); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2275 | } |
| 2276 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2277 | static void |
| 2278 | surface_set_opaque_region(struct wl_client *client, |
| 2279 | struct wl_resource *resource, |
| 2280 | struct wl_resource *region_resource) |
| 2281 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2282 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2283 | struct weston_region *region; |
| 2284 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2285 | if (region_resource) { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 2286 | region = wl_resource_get_user_data(region_resource); |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 2287 | pixman_region32_copy(&surface->pending.opaque, |
| 2288 | ®ion->region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2289 | } else { |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 2290 | pixman_region32_clear(&surface->pending.opaque); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2291 | } |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2292 | } |
| 2293 | |
| 2294 | static void |
| 2295 | surface_set_input_region(struct wl_client *client, |
| 2296 | struct wl_resource *resource, |
| 2297 | struct wl_resource *region_resource) |
| 2298 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2299 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 010f98b | 2012-02-23 17:30:45 -0500 | [diff] [blame] | 2300 | struct weston_region *region; |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2301 | |
| 2302 | if (region_resource) { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 2303 | region = wl_resource_get_user_data(region_resource); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 2304 | pixman_region32_copy(&surface->pending.input, |
| 2305 | ®ion->region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2306 | } else { |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 2307 | pixman_region32_fini(&surface->pending.input); |
| 2308 | region_init_infinite(&surface->pending.input); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2309 | } |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2310 | } |
| 2311 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2312 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2313 | weston_surface_commit_subsurface_order(struct weston_surface *surface) |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2314 | { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2315 | struct weston_subsurface *sub; |
| 2316 | |
| 2317 | wl_list_for_each_reverse(sub, &surface->subsurface_list_pending, |
| 2318 | parent_link_pending) { |
| 2319 | wl_list_remove(&sub->parent_link); |
| 2320 | wl_list_insert(&surface->subsurface_list, &sub->parent_link); |
| 2321 | } |
| 2322 | } |
| 2323 | |
| 2324 | static void |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2325 | weston_surface_commit_state(struct weston_surface *surface, |
| 2326 | struct weston_surface_state *state) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2327 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2328 | struct weston_view *view; |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 2329 | pixman_region32_t opaque; |
| 2330 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 2331 | /* wl_surface.set_buffer_transform */ |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 2332 | /* wl_surface.set_buffer_scale */ |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 2333 | /* wl_viewport.set */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2334 | surface->buffer_viewport = state->buffer_viewport; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 2335 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2336 | /* wl_surface.attach */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2337 | if (state->newly_attached) |
| 2338 | weston_surface_attach(surface, state->buffer); |
| 2339 | weston_surface_state_set_buffer(state, NULL); |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2340 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2341 | if (state->newly_attached || state->buffer_viewport.changed) { |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 2342 | weston_surface_update_size(surface); |
| 2343 | if (surface->configure) |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2344 | surface->configure(surface, state->sx, state->sy); |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 2345 | } |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2346 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2347 | state->sx = 0; |
| 2348 | state->sy = 0; |
| 2349 | state->newly_attached = 0; |
| 2350 | state->buffer_viewport.changed = 0; |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 2351 | |
| 2352 | /* wl_surface.damage */ |
| 2353 | pixman_region32_union(&surface->damage, &surface->damage, |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2354 | &state->damage); |
Kristian Høgsberg | 4d0214c | 2012-11-08 11:36:02 -0500 | [diff] [blame] | 2355 | pixman_region32_intersect_rect(&surface->damage, &surface->damage, |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 2356 | 0, 0, surface->width, surface->height); |
Jason Ekstrand | f83a0d4 | 2014-09-06 09:01:28 -0700 | [diff] [blame] | 2357 | pixman_region32_clear(&state->damage); |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 2358 | |
| 2359 | /* wl_surface.set_opaque_region */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2360 | pixman_region32_init(&opaque); |
| 2361 | pixman_region32_intersect_rect(&opaque, &state->opaque, |
| 2362 | 0, 0, surface->width, surface->height); |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 2363 | |
| 2364 | if (!pixman_region32_equal(&opaque, &surface->opaque)) { |
| 2365 | pixman_region32_copy(&surface->opaque, &opaque); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2366 | wl_list_for_each(view, &surface->views, surface_link) |
| 2367 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 2368 | } |
| 2369 | |
| 2370 | pixman_region32_fini(&opaque); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 2371 | |
| 2372 | /* wl_surface.set_input_region */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2373 | pixman_region32_intersect_rect(&surface->input, &state->input, |
| 2374 | 0, 0, surface->width, surface->height); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 2375 | |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 2376 | /* wl_surface.frame */ |
| 2377 | wl_list_insert_list(&surface->frame_callback_list, |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2378 | &state->frame_callback_list); |
| 2379 | wl_list_init(&state->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2380 | |
| 2381 | /* XXX: |
| 2382 | * What should happen with a feedback request, if there |
| 2383 | * is no wl_buffer attached for this commit? |
| 2384 | */ |
| 2385 | |
| 2386 | /* presentation.feedback */ |
| 2387 | wl_list_insert_list(&surface->feedback_list, |
| 2388 | &state->feedback_list); |
| 2389 | wl_list_init(&state->feedback_list); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2390 | } |
| 2391 | |
| 2392 | static void |
| 2393 | weston_surface_commit(struct weston_surface *surface) |
| 2394 | { |
| 2395 | weston_surface_commit_state(surface, &surface->pending); |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 2396 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2397 | weston_surface_commit_subsurface_order(surface); |
| 2398 | |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 2399 | weston_surface_schedule_repaint(surface); |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2400 | } |
| 2401 | |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 2402 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2403 | weston_subsurface_commit(struct weston_subsurface *sub); |
| 2404 | |
| 2405 | static void |
| 2406 | weston_subsurface_parent_commit(struct weston_subsurface *sub, |
| 2407 | int parent_is_synchronized); |
| 2408 | |
| 2409 | static void |
| 2410 | surface_commit(struct wl_client *client, struct wl_resource *resource) |
| 2411 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2412 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2413 | struct weston_subsurface *sub = weston_surface_to_subsurface(surface); |
| 2414 | |
| 2415 | if (sub) { |
| 2416 | weston_subsurface_commit(sub); |
| 2417 | return; |
| 2418 | } |
| 2419 | |
| 2420 | weston_surface_commit(surface); |
| 2421 | |
| 2422 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
| 2423 | if (sub->surface != surface) |
| 2424 | weston_subsurface_parent_commit(sub, 0); |
| 2425 | } |
| 2426 | } |
| 2427 | |
| 2428 | static void |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 2429 | surface_set_buffer_transform(struct wl_client *client, |
| 2430 | struct wl_resource *resource, int transform) |
| 2431 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2432 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 2433 | |
Jonny Lamb | a55f139 | 2014-05-30 12:07:15 +0200 | [diff] [blame] | 2434 | /* if wl_output.transform grows more members this will need to be updated. */ |
| 2435 | if (transform < 0 || |
| 2436 | transform > WL_OUTPUT_TRANSFORM_FLIPPED_270) { |
| 2437 | wl_resource_post_error(resource, |
| 2438 | WL_SURFACE_ERROR_INVALID_TRANSFORM, |
| 2439 | "buffer transform must be a valid transform " |
| 2440 | "('%d' specified)", transform); |
| 2441 | return; |
| 2442 | } |
| 2443 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 2444 | surface->pending.buffer_viewport.buffer.transform = transform; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 2445 | surface->pending.buffer_viewport.changed = 1; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 2446 | } |
| 2447 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 2448 | static void |
| 2449 | surface_set_buffer_scale(struct wl_client *client, |
| 2450 | struct wl_resource *resource, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 2451 | int32_t scale) |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 2452 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2453 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 2454 | |
Jonny Lamb | a55f139 | 2014-05-30 12:07:15 +0200 | [diff] [blame] | 2455 | if (scale < 1) { |
| 2456 | wl_resource_post_error(resource, |
| 2457 | WL_SURFACE_ERROR_INVALID_SCALE, |
| 2458 | "buffer scale must be at least one " |
| 2459 | "('%d' specified)", scale); |
| 2460 | return; |
| 2461 | } |
| 2462 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 2463 | surface->pending.buffer_viewport.buffer.scale = scale; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 2464 | surface->pending.buffer_viewport.changed = 1; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 2465 | } |
| 2466 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 2467 | static const struct wl_surface_interface surface_interface = { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2468 | surface_destroy, |
| 2469 | surface_attach, |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2470 | surface_damage, |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2471 | surface_frame, |
| 2472 | surface_set_opaque_region, |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2473 | surface_set_input_region, |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 2474 | surface_commit, |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 2475 | surface_set_buffer_transform, |
| 2476 | surface_set_buffer_scale |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2477 | }; |
| 2478 | |
| 2479 | static void |
| 2480 | compositor_create_surface(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 2481 | struct wl_resource *resource, uint32_t id) |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2482 | { |
Kristian Høgsberg | c2d7042 | 2013-06-25 15:34:33 -0400 | [diff] [blame] | 2483 | struct weston_compositor *ec = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2484 | struct weston_surface *surface; |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2485 | |
Kristian Høgsberg | 18c9300 | 2012-01-27 11:58:31 -0500 | [diff] [blame] | 2486 | surface = weston_surface_create(ec); |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 2487 | if (surface == NULL) { |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 2488 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2489 | return; |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 2490 | } |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2491 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 2492 | surface->resource = |
| 2493 | wl_resource_create(client, &wl_surface_interface, |
| 2494 | wl_resource_get_version(resource), id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 2495 | if (surface->resource == NULL) { |
| 2496 | weston_surface_destroy(surface); |
| 2497 | wl_resource_post_no_memory(resource); |
| 2498 | return; |
| 2499 | } |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 2500 | wl_resource_set_implementation(surface->resource, &surface_interface, |
| 2501 | surface, destroy_surface); |
Kristian Høgsberg | f03a04a | 2014-04-06 22:04:50 -0700 | [diff] [blame] | 2502 | |
| 2503 | wl_signal_emit(&ec->create_surface_signal, surface); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2504 | } |
| 2505 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2506 | static void |
| 2507 | destroy_region(struct wl_resource *resource) |
| 2508 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 2509 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2510 | |
| 2511 | pixman_region32_fini(®ion->region); |
| 2512 | free(region); |
| 2513 | } |
| 2514 | |
| 2515 | static void |
| 2516 | region_destroy(struct wl_client *client, struct wl_resource *resource) |
| 2517 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2518 | wl_resource_destroy(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2519 | } |
| 2520 | |
| 2521 | static void |
| 2522 | region_add(struct wl_client *client, struct wl_resource *resource, |
| 2523 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 2524 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 2525 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2526 | |
| 2527 | pixman_region32_union_rect(®ion->region, ®ion->region, |
| 2528 | x, y, width, height); |
| 2529 | } |
| 2530 | |
| 2531 | static void |
| 2532 | region_subtract(struct wl_client *client, struct wl_resource *resource, |
| 2533 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 2534 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 2535 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2536 | pixman_region32_t rect; |
| 2537 | |
| 2538 | pixman_region32_init_rect(&rect, x, y, width, height); |
| 2539 | pixman_region32_subtract(®ion->region, ®ion->region, &rect); |
| 2540 | pixman_region32_fini(&rect); |
| 2541 | } |
| 2542 | |
| 2543 | static const struct wl_region_interface region_interface = { |
| 2544 | region_destroy, |
| 2545 | region_add, |
| 2546 | region_subtract |
| 2547 | }; |
| 2548 | |
| 2549 | static void |
| 2550 | compositor_create_region(struct wl_client *client, |
| 2551 | struct wl_resource *resource, uint32_t id) |
| 2552 | { |
| 2553 | struct weston_region *region; |
| 2554 | |
| 2555 | region = malloc(sizeof *region); |
| 2556 | if (region == NULL) { |
| 2557 | wl_resource_post_no_memory(resource); |
| 2558 | return; |
| 2559 | } |
| 2560 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2561 | pixman_region32_init(®ion->region); |
| 2562 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 2563 | region->resource = |
| 2564 | wl_resource_create(client, &wl_region_interface, 1, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 2565 | if (region->resource == NULL) { |
| 2566 | free(region); |
| 2567 | wl_resource_post_no_memory(resource); |
| 2568 | return; |
| 2569 | } |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 2570 | wl_resource_set_implementation(region->resource, ®ion_interface, |
| 2571 | region, destroy_region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2572 | } |
| 2573 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 2574 | static const struct wl_compositor_interface compositor_interface = { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2575 | compositor_create_surface, |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2576 | compositor_create_region |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2577 | }; |
| 2578 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2579 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2580 | weston_subsurface_commit_from_cache(struct weston_subsurface *sub) |
| 2581 | { |
| 2582 | struct weston_surface *surface = sub->surface; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2583 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2584 | weston_surface_commit_state(surface, &sub->cached); |
| 2585 | weston_buffer_reference(&sub->cached_buffer_ref, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2586 | |
| 2587 | weston_surface_commit_subsurface_order(surface); |
| 2588 | |
| 2589 | weston_surface_schedule_repaint(surface); |
| 2590 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2591 | sub->has_cached_data = 0; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2592 | } |
| 2593 | |
| 2594 | static void |
| 2595 | weston_subsurface_commit_to_cache(struct weston_subsurface *sub) |
| 2596 | { |
| 2597 | struct weston_surface *surface = sub->surface; |
| 2598 | |
| 2599 | /* |
| 2600 | * If this commit would cause the surface to move by the |
| 2601 | * attach(dx, dy) parameters, the old damage region must be |
| 2602 | * translated to correspond to the new surface coordinate system |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 2603 | * original_mode. |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2604 | */ |
| 2605 | pixman_region32_translate(&sub->cached.damage, |
| 2606 | -surface->pending.sx, -surface->pending.sy); |
| 2607 | pixman_region32_union(&sub->cached.damage, &sub->cached.damage, |
| 2608 | &surface->pending.damage); |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 2609 | pixman_region32_clear(&surface->pending.damage); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2610 | |
| 2611 | if (surface->pending.newly_attached) { |
| 2612 | sub->cached.newly_attached = 1; |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2613 | weston_surface_state_set_buffer(&sub->cached, |
| 2614 | surface->pending.buffer); |
| 2615 | weston_buffer_reference(&sub->cached_buffer_ref, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2616 | surface->pending.buffer); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2617 | weston_presentation_feedback_discard_list( |
| 2618 | &sub->cached.feedback_list); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2619 | } |
| 2620 | sub->cached.sx += surface->pending.sx; |
| 2621 | sub->cached.sy += surface->pending.sy; |
Pekka Paalanen | 260ba38 | 2014-03-14 14:38:12 +0200 | [diff] [blame] | 2622 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 2623 | sub->cached.buffer_viewport.changed |= |
| 2624 | surface->pending.buffer_viewport.changed; |
| 2625 | sub->cached.buffer_viewport.buffer = |
| 2626 | surface->pending.buffer_viewport.buffer; |
| 2627 | sub->cached.buffer_viewport.surface = |
| 2628 | surface->pending.buffer_viewport.surface; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2629 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 2630 | weston_surface_reset_pending_buffer(surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2631 | |
| 2632 | pixman_region32_copy(&sub->cached.opaque, &surface->pending.opaque); |
| 2633 | |
| 2634 | pixman_region32_copy(&sub->cached.input, &surface->pending.input); |
| 2635 | |
| 2636 | wl_list_insert_list(&sub->cached.frame_callback_list, |
| 2637 | &surface->pending.frame_callback_list); |
| 2638 | wl_list_init(&surface->pending.frame_callback_list); |
| 2639 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2640 | wl_list_insert_list(&sub->cached.feedback_list, |
| 2641 | &surface->pending.feedback_list); |
| 2642 | wl_list_init(&surface->pending.feedback_list); |
| 2643 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2644 | sub->has_cached_data = 1; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2645 | } |
| 2646 | |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 2647 | static bool |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2648 | weston_subsurface_is_synchronized(struct weston_subsurface *sub) |
| 2649 | { |
| 2650 | while (sub) { |
| 2651 | if (sub->synchronized) |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 2652 | return true; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2653 | |
| 2654 | if (!sub->parent) |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 2655 | return false; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2656 | |
| 2657 | sub = weston_surface_to_subsurface(sub->parent); |
| 2658 | } |
| 2659 | |
Carlos Olmedo Escobar | 61a9bf5 | 2014-11-04 14:38:39 +0100 | [diff] [blame] | 2660 | return false; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2661 | } |
| 2662 | |
| 2663 | static void |
| 2664 | weston_subsurface_commit(struct weston_subsurface *sub) |
| 2665 | { |
| 2666 | struct weston_surface *surface = sub->surface; |
| 2667 | struct weston_subsurface *tmp; |
| 2668 | |
| 2669 | /* Recursive check for effectively synchronized. */ |
| 2670 | if (weston_subsurface_is_synchronized(sub)) { |
| 2671 | weston_subsurface_commit_to_cache(sub); |
| 2672 | } else { |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2673 | if (sub->has_cached_data) { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2674 | /* flush accumulated state from cache */ |
| 2675 | weston_subsurface_commit_to_cache(sub); |
| 2676 | weston_subsurface_commit_from_cache(sub); |
| 2677 | } else { |
| 2678 | weston_surface_commit(surface); |
| 2679 | } |
| 2680 | |
| 2681 | wl_list_for_each(tmp, &surface->subsurface_list, parent_link) { |
| 2682 | if (tmp->surface != surface) |
| 2683 | weston_subsurface_parent_commit(tmp, 0); |
| 2684 | } |
| 2685 | } |
| 2686 | } |
| 2687 | |
| 2688 | static void |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 2689 | weston_subsurface_synchronized_commit(struct weston_subsurface *sub) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2690 | { |
| 2691 | struct weston_surface *surface = sub->surface; |
| 2692 | struct weston_subsurface *tmp; |
| 2693 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2694 | /* From now on, commit_from_cache the whole sub-tree, regardless of |
| 2695 | * the synchronized mode of each child. This sub-surface or some |
| 2696 | * of its ancestors were synchronized, so we are synchronized |
| 2697 | * all the way down. |
| 2698 | */ |
| 2699 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2700 | if (sub->has_cached_data) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2701 | weston_subsurface_commit_from_cache(sub); |
| 2702 | |
| 2703 | wl_list_for_each(tmp, &surface->subsurface_list, parent_link) { |
| 2704 | if (tmp->surface != surface) |
| 2705 | weston_subsurface_parent_commit(tmp, 1); |
| 2706 | } |
| 2707 | } |
| 2708 | |
| 2709 | static void |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 2710 | weston_subsurface_parent_commit(struct weston_subsurface *sub, |
| 2711 | int parent_is_synchronized) |
| 2712 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2713 | struct weston_view *view; |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 2714 | if (sub->position.set) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2715 | wl_list_for_each(view, &sub->surface->views, surface_link) |
| 2716 | weston_view_set_position(view, |
| 2717 | sub->position.x, |
| 2718 | sub->position.y); |
| 2719 | |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 2720 | sub->position.set = 0; |
| 2721 | } |
| 2722 | |
| 2723 | if (parent_is_synchronized || sub->synchronized) |
| 2724 | weston_subsurface_synchronized_commit(sub); |
| 2725 | } |
| 2726 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame^] | 2727 | static int |
| 2728 | subsurface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 2729 | { |
| 2730 | return snprintf(buf, len, "sub-surface"); |
| 2731 | } |
| 2732 | |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 2733 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2734 | subsurface_configure(struct weston_surface *surface, int32_t dx, int32_t dy) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2735 | { |
| 2736 | struct weston_compositor *compositor = surface->compositor; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2737 | struct weston_view *view; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2738 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2739 | wl_list_for_each(view, &surface->views, surface_link) |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2740 | weston_view_set_position(view, |
| 2741 | view->geometry.x + dx, |
| 2742 | view->geometry.y + dy); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2743 | |
| 2744 | /* No need to check parent mappedness, because if parent is not |
| 2745 | * mapped, parent is not in a visible layer, so this sub-surface |
| 2746 | * will not be drawn either. |
| 2747 | */ |
| 2748 | if (!weston_surface_is_mapped(surface)) { |
Pekka Paalanen | eb3cf22 | 2014-06-30 11:52:07 +0300 | [diff] [blame] | 2749 | struct weston_output *output; |
| 2750 | |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 2751 | /* Cannot call weston_view_update_transform(), |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2752 | * because that would call it also for the parent surface, |
| 2753 | * which might not be mapped yet. That would lead to |
| 2754 | * inconsistent state, where the window could never be |
| 2755 | * mapped. |
| 2756 | * |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 2757 | * Instead just assign any output, to make |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2758 | * weston_surface_is_mapped() return true, so that when the |
| 2759 | * parent surface does get mapped, this one will get |
Pekka Paalanen | eb3cf22 | 2014-06-30 11:52:07 +0300 | [diff] [blame] | 2760 | * included, too. See view_list_add(). |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2761 | */ |
| 2762 | assert(!wl_list_empty(&compositor->output_list)); |
Pekka Paalanen | eb3cf22 | 2014-06-30 11:52:07 +0300 | [diff] [blame] | 2763 | output = container_of(compositor->output_list.next, |
| 2764 | struct weston_output, link); |
| 2765 | |
| 2766 | surface->output = output; |
| 2767 | weston_surface_update_output_mask(surface, 1 << output->id); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2768 | } |
| 2769 | } |
| 2770 | |
| 2771 | static struct weston_subsurface * |
| 2772 | weston_surface_to_subsurface(struct weston_surface *surface) |
| 2773 | { |
| 2774 | if (surface->configure == subsurface_configure) |
| 2775 | return surface->configure_private; |
| 2776 | |
| 2777 | return NULL; |
| 2778 | } |
| 2779 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 2780 | WL_EXPORT struct weston_surface * |
| 2781 | weston_surface_get_main_surface(struct weston_surface *surface) |
| 2782 | { |
| 2783 | struct weston_subsurface *sub; |
| 2784 | |
| 2785 | while (surface && (sub = weston_surface_to_subsurface(surface))) |
| 2786 | surface = sub->parent; |
| 2787 | |
| 2788 | return surface; |
| 2789 | } |
| 2790 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 2791 | WL_EXPORT int |
| 2792 | weston_surface_set_role(struct weston_surface *surface, |
| 2793 | const char *role_name, |
| 2794 | struct wl_resource *error_resource, |
| 2795 | uint32_t error_code) |
| 2796 | { |
| 2797 | assert(role_name); |
| 2798 | |
| 2799 | if (surface->role_name == NULL || |
| 2800 | surface->role_name == role_name || |
| 2801 | strcmp(surface->role_name, role_name) == 0) { |
| 2802 | surface->role_name = role_name; |
| 2803 | |
| 2804 | return 0; |
| 2805 | } |
| 2806 | |
| 2807 | wl_resource_post_error(error_resource, error_code, |
| 2808 | "Cannot assign role %s to wl_surface@%d," |
| 2809 | " already has role %s\n", |
| 2810 | role_name, |
| 2811 | wl_resource_get_id(surface->resource), |
| 2812 | surface->role_name); |
| 2813 | return -1; |
| 2814 | } |
| 2815 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame^] | 2816 | WL_EXPORT void |
| 2817 | weston_surface_set_label_func(struct weston_surface *surface, |
| 2818 | int (*desc)(struct weston_surface *, |
| 2819 | char *, size_t)) |
| 2820 | { |
| 2821 | surface->get_label = desc; |
| 2822 | } |
| 2823 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2824 | static void |
| 2825 | subsurface_set_position(struct wl_client *client, |
| 2826 | struct wl_resource *resource, int32_t x, int32_t y) |
| 2827 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 2828 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2829 | |
| 2830 | if (!sub) |
| 2831 | return; |
| 2832 | |
| 2833 | sub->position.x = x; |
| 2834 | sub->position.y = y; |
| 2835 | sub->position.set = 1; |
| 2836 | } |
| 2837 | |
| 2838 | static struct weston_subsurface * |
| 2839 | subsurface_from_surface(struct weston_surface *surface) |
| 2840 | { |
| 2841 | struct weston_subsurface *sub; |
| 2842 | |
| 2843 | sub = weston_surface_to_subsurface(surface); |
| 2844 | if (sub) |
| 2845 | return sub; |
| 2846 | |
| 2847 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) |
| 2848 | if (sub->surface == surface) |
| 2849 | return sub; |
| 2850 | |
| 2851 | return NULL; |
| 2852 | } |
| 2853 | |
| 2854 | static struct weston_subsurface * |
| 2855 | subsurface_sibling_check(struct weston_subsurface *sub, |
| 2856 | struct weston_surface *surface, |
| 2857 | const char *request) |
| 2858 | { |
| 2859 | struct weston_subsurface *sibling; |
| 2860 | |
| 2861 | sibling = subsurface_from_surface(surface); |
| 2862 | |
| 2863 | if (!sibling) { |
| 2864 | wl_resource_post_error(sub->resource, |
| 2865 | WL_SUBSURFACE_ERROR_BAD_SURFACE, |
| 2866 | "%s: wl_surface@%d is not a parent or sibling", |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2867 | request, wl_resource_get_id(surface->resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2868 | return NULL; |
| 2869 | } |
| 2870 | |
| 2871 | if (sibling->parent != sub->parent) { |
| 2872 | wl_resource_post_error(sub->resource, |
| 2873 | WL_SUBSURFACE_ERROR_BAD_SURFACE, |
| 2874 | "%s: wl_surface@%d has a different parent", |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2875 | request, wl_resource_get_id(surface->resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2876 | return NULL; |
| 2877 | } |
| 2878 | |
| 2879 | return sibling; |
| 2880 | } |
| 2881 | |
| 2882 | static void |
| 2883 | subsurface_place_above(struct wl_client *client, |
| 2884 | struct wl_resource *resource, |
| 2885 | struct wl_resource *sibling_resource) |
| 2886 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 2887 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2888 | struct weston_surface *surface = |
| 2889 | wl_resource_get_user_data(sibling_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2890 | struct weston_subsurface *sibling; |
| 2891 | |
| 2892 | if (!sub) |
| 2893 | return; |
| 2894 | |
| 2895 | sibling = subsurface_sibling_check(sub, surface, "place_above"); |
| 2896 | if (!sibling) |
| 2897 | return; |
| 2898 | |
| 2899 | wl_list_remove(&sub->parent_link_pending); |
| 2900 | wl_list_insert(sibling->parent_link_pending.prev, |
| 2901 | &sub->parent_link_pending); |
| 2902 | } |
| 2903 | |
| 2904 | static void |
| 2905 | subsurface_place_below(struct wl_client *client, |
| 2906 | struct wl_resource *resource, |
| 2907 | struct wl_resource *sibling_resource) |
| 2908 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 2909 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2910 | struct weston_surface *surface = |
| 2911 | wl_resource_get_user_data(sibling_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2912 | struct weston_subsurface *sibling; |
| 2913 | |
| 2914 | if (!sub) |
| 2915 | return; |
| 2916 | |
| 2917 | sibling = subsurface_sibling_check(sub, surface, "place_below"); |
| 2918 | if (!sibling) |
| 2919 | return; |
| 2920 | |
| 2921 | wl_list_remove(&sub->parent_link_pending); |
| 2922 | wl_list_insert(&sibling->parent_link_pending, |
| 2923 | &sub->parent_link_pending); |
| 2924 | } |
| 2925 | |
| 2926 | static void |
| 2927 | subsurface_set_sync(struct wl_client *client, struct wl_resource *resource) |
| 2928 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 2929 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2930 | |
| 2931 | if (sub) |
| 2932 | sub->synchronized = 1; |
| 2933 | } |
| 2934 | |
| 2935 | static void |
| 2936 | subsurface_set_desync(struct wl_client *client, struct wl_resource *resource) |
| 2937 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 2938 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2939 | |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 2940 | if (sub && sub->synchronized) { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2941 | sub->synchronized = 0; |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 2942 | |
| 2943 | /* If sub became effectively desynchronized, flush. */ |
| 2944 | if (!weston_subsurface_is_synchronized(sub)) |
| 2945 | weston_subsurface_synchronized_commit(sub); |
| 2946 | } |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2950 | weston_subsurface_unlink_parent(struct weston_subsurface *sub) |
| 2951 | { |
| 2952 | wl_list_remove(&sub->parent_link); |
| 2953 | wl_list_remove(&sub->parent_link_pending); |
| 2954 | wl_list_remove(&sub->parent_destroy_listener.link); |
| 2955 | sub->parent = NULL; |
| 2956 | } |
| 2957 | |
| 2958 | static void |
| 2959 | weston_subsurface_destroy(struct weston_subsurface *sub); |
| 2960 | |
| 2961 | static void |
| 2962 | subsurface_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 2963 | { |
| 2964 | struct weston_subsurface *sub = |
| 2965 | container_of(listener, struct weston_subsurface, |
| 2966 | surface_destroy_listener); |
| 2967 | assert(data == &sub->surface->resource); |
| 2968 | |
| 2969 | /* The protocol object (wl_resource) is left inert. */ |
| 2970 | if (sub->resource) |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 2971 | wl_resource_set_user_data(sub->resource, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2972 | |
| 2973 | weston_subsurface_destroy(sub); |
| 2974 | } |
| 2975 | |
| 2976 | static void |
| 2977 | subsurface_handle_parent_destroy(struct wl_listener *listener, void *data) |
| 2978 | { |
| 2979 | struct weston_subsurface *sub = |
| 2980 | container_of(listener, struct weston_subsurface, |
| 2981 | parent_destroy_listener); |
| 2982 | assert(data == &sub->parent->resource); |
| 2983 | assert(sub->surface != sub->parent); |
| 2984 | |
| 2985 | if (weston_surface_is_mapped(sub->surface)) |
| 2986 | weston_surface_unmap(sub->surface); |
| 2987 | |
| 2988 | weston_subsurface_unlink_parent(sub); |
| 2989 | } |
| 2990 | |
| 2991 | static void |
| 2992 | subsurface_resource_destroy(struct wl_resource *resource) |
| 2993 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 2994 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2995 | |
| 2996 | if (sub) |
| 2997 | weston_subsurface_destroy(sub); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2998 | } |
| 2999 | |
| 3000 | static void |
| 3001 | subsurface_destroy(struct wl_client *client, struct wl_resource *resource) |
| 3002 | { |
| 3003 | wl_resource_destroy(resource); |
| 3004 | } |
| 3005 | |
| 3006 | static void |
| 3007 | weston_subsurface_link_parent(struct weston_subsurface *sub, |
| 3008 | struct weston_surface *parent) |
| 3009 | { |
| 3010 | sub->parent = parent; |
| 3011 | sub->parent_destroy_listener.notify = subsurface_handle_parent_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3012 | wl_signal_add(&parent->destroy_signal, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3013 | &sub->parent_destroy_listener); |
| 3014 | |
| 3015 | wl_list_insert(&parent->subsurface_list, &sub->parent_link); |
| 3016 | wl_list_insert(&parent->subsurface_list_pending, |
| 3017 | &sub->parent_link_pending); |
| 3018 | } |
| 3019 | |
| 3020 | static void |
| 3021 | weston_subsurface_link_surface(struct weston_subsurface *sub, |
| 3022 | struct weston_surface *surface) |
| 3023 | { |
| 3024 | sub->surface = surface; |
| 3025 | sub->surface_destroy_listener.notify = |
| 3026 | subsurface_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3027 | wl_signal_add(&surface->destroy_signal, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3028 | &sub->surface_destroy_listener); |
| 3029 | } |
| 3030 | |
| 3031 | static void |
| 3032 | weston_subsurface_destroy(struct weston_subsurface *sub) |
| 3033 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3034 | struct weston_view *view, *next; |
| 3035 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3036 | assert(sub->surface); |
| 3037 | |
| 3038 | if (sub->resource) { |
| 3039 | assert(weston_surface_to_subsurface(sub->surface) == sub); |
| 3040 | assert(sub->parent_destroy_listener.notify == |
| 3041 | subsurface_handle_parent_destroy); |
| 3042 | |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 3043 | wl_list_for_each_safe(view, next, &sub->surface->views, surface_link) { |
| 3044 | weston_view_unmap(view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3045 | weston_view_destroy(view); |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 3046 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3047 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3048 | if (sub->parent) |
| 3049 | weston_subsurface_unlink_parent(sub); |
| 3050 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3051 | weston_surface_state_fini(&sub->cached); |
| 3052 | weston_buffer_reference(&sub->cached_buffer_ref, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3053 | |
| 3054 | sub->surface->configure = NULL; |
| 3055 | sub->surface->configure_private = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame^] | 3056 | weston_surface_set_label_func(sub->surface, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3057 | } else { |
| 3058 | /* the dummy weston_subsurface for the parent itself */ |
| 3059 | assert(sub->parent_destroy_listener.notify == NULL); |
| 3060 | wl_list_remove(&sub->parent_link); |
| 3061 | wl_list_remove(&sub->parent_link_pending); |
| 3062 | } |
| 3063 | |
| 3064 | wl_list_remove(&sub->surface_destroy_listener.link); |
| 3065 | free(sub); |
| 3066 | } |
| 3067 | |
| 3068 | static const struct wl_subsurface_interface subsurface_implementation = { |
| 3069 | subsurface_destroy, |
| 3070 | subsurface_set_position, |
| 3071 | subsurface_place_above, |
| 3072 | subsurface_place_below, |
| 3073 | subsurface_set_sync, |
| 3074 | subsurface_set_desync |
| 3075 | }; |
| 3076 | |
| 3077 | static struct weston_subsurface * |
| 3078 | weston_subsurface_create(uint32_t id, struct weston_surface *surface, |
| 3079 | struct weston_surface *parent) |
| 3080 | { |
| 3081 | struct weston_subsurface *sub; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3082 | struct wl_client *client = wl_resource_get_client(surface->resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3083 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 3084 | sub = zalloc(sizeof *sub); |
| 3085 | if (sub == NULL) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3086 | return NULL; |
| 3087 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3088 | wl_list_init(&sub->unused_views); |
| 3089 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3090 | sub->resource = |
| 3091 | wl_resource_create(client, &wl_subsurface_interface, 1, id); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3092 | if (!sub->resource) { |
| 3093 | free(sub); |
| 3094 | return NULL; |
| 3095 | } |
| 3096 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3097 | wl_resource_set_implementation(sub->resource, |
| 3098 | &subsurface_implementation, |
| 3099 | sub, subsurface_resource_destroy); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3100 | weston_subsurface_link_surface(sub, surface); |
| 3101 | weston_subsurface_link_parent(sub, parent); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3102 | weston_surface_state_init(&sub->cached); |
| 3103 | sub->cached_buffer_ref.buffer = NULL; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3104 | sub->synchronized = 1; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3105 | |
| 3106 | return sub; |
| 3107 | } |
| 3108 | |
| 3109 | /* Create a dummy subsurface for having the parent itself in its |
| 3110 | * sub-surface lists. Makes stacking order manipulation easy. |
| 3111 | */ |
| 3112 | static struct weston_subsurface * |
| 3113 | weston_subsurface_create_for_parent(struct weston_surface *parent) |
| 3114 | { |
| 3115 | struct weston_subsurface *sub; |
| 3116 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 3117 | sub = zalloc(sizeof *sub); |
| 3118 | if (sub == NULL) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3119 | return NULL; |
| 3120 | |
| 3121 | weston_subsurface_link_surface(sub, parent); |
| 3122 | sub->parent = parent; |
| 3123 | wl_list_insert(&parent->subsurface_list, &sub->parent_link); |
| 3124 | wl_list_insert(&parent->subsurface_list_pending, |
| 3125 | &sub->parent_link_pending); |
| 3126 | |
| 3127 | return sub; |
| 3128 | } |
| 3129 | |
| 3130 | static void |
| 3131 | subcompositor_get_subsurface(struct wl_client *client, |
| 3132 | struct wl_resource *resource, |
| 3133 | uint32_t id, |
| 3134 | struct wl_resource *surface_resource, |
| 3135 | struct wl_resource *parent_resource) |
| 3136 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3137 | struct weston_surface *surface = |
| 3138 | wl_resource_get_user_data(surface_resource); |
| 3139 | struct weston_surface *parent = |
| 3140 | wl_resource_get_user_data(parent_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3141 | struct weston_subsurface *sub; |
| 3142 | static const char where[] = "get_subsurface: wl_subsurface@"; |
| 3143 | |
| 3144 | if (surface == parent) { |
| 3145 | wl_resource_post_error(resource, |
| 3146 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 3147 | "%s%d: wl_surface@%d cannot be its own parent", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 3148 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3149 | return; |
| 3150 | } |
| 3151 | |
| 3152 | if (weston_surface_to_subsurface(surface)) { |
| 3153 | wl_resource_post_error(resource, |
| 3154 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 3155 | "%s%d: wl_surface@%d is already a sub-surface", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 3156 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3157 | return; |
| 3158 | } |
| 3159 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3160 | if (weston_surface_set_role(surface, "wl_subsurface", resource, |
| 3161 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE) < 0) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3162 | return; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3163 | |
Pekka Paalanen | 86c8ca0 | 2013-05-17 16:46:07 +0300 | [diff] [blame] | 3164 | if (weston_surface_get_main_surface(parent) == surface) { |
| 3165 | wl_resource_post_error(resource, |
| 3166 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 3167 | "%s%d: wl_surface@%d is an ancestor of parent", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 3168 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | 86c8ca0 | 2013-05-17 16:46:07 +0300 | [diff] [blame] | 3169 | return; |
| 3170 | } |
| 3171 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3172 | /* make sure the parent is in its own list */ |
| 3173 | if (wl_list_empty(&parent->subsurface_list)) { |
| 3174 | if (!weston_subsurface_create_for_parent(parent)) { |
| 3175 | wl_resource_post_no_memory(resource); |
| 3176 | return; |
| 3177 | } |
| 3178 | } |
| 3179 | |
| 3180 | sub = weston_subsurface_create(id, surface, parent); |
| 3181 | if (!sub) { |
| 3182 | wl_resource_post_no_memory(resource); |
| 3183 | return; |
| 3184 | } |
| 3185 | |
| 3186 | surface->configure = subsurface_configure; |
| 3187 | surface->configure_private = sub; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame^] | 3188 | weston_surface_set_label_func(surface, subsurface_get_label); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3189 | } |
| 3190 | |
| 3191 | static void |
| 3192 | subcompositor_destroy(struct wl_client *client, struct wl_resource *resource) |
| 3193 | { |
| 3194 | wl_resource_destroy(resource); |
| 3195 | } |
| 3196 | |
| 3197 | static const struct wl_subcompositor_interface subcompositor_interface = { |
| 3198 | subcompositor_destroy, |
| 3199 | subcompositor_get_subsurface |
| 3200 | }; |
| 3201 | |
| 3202 | static void |
| 3203 | bind_subcompositor(struct wl_client *client, |
| 3204 | void *data, uint32_t version, uint32_t id) |
| 3205 | { |
| 3206 | struct weston_compositor *compositor = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3207 | struct wl_resource *resource; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3208 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3209 | resource = |
| 3210 | wl_resource_create(client, &wl_subcompositor_interface, 1, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 3211 | if (resource == NULL) { |
| 3212 | wl_client_post_no_memory(client); |
| 3213 | return; |
| 3214 | } |
| 3215 | wl_resource_set_implementation(resource, &subcompositor_interface, |
| 3216 | compositor, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3217 | } |
| 3218 | |
| 3219 | static void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3220 | weston_compositor_dpms(struct weston_compositor *compositor, |
| 3221 | enum dpms_enum state) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3222 | { |
| 3223 | struct weston_output *output; |
| 3224 | |
| 3225 | wl_list_for_each(output, &compositor->output_list, link) |
| 3226 | if (output->set_dpms) |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3227 | output->set_dpms(output, state); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3228 | } |
| 3229 | |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3230 | WL_EXPORT void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3231 | weston_compositor_wake(struct weston_compositor *compositor) |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3232 | { |
Neil Roberts | 8b62e20 | 2013-09-30 13:14:47 +0100 | [diff] [blame] | 3233 | uint32_t old_state = compositor->state; |
| 3234 | |
| 3235 | /* The state needs to be changed before emitting the wake |
| 3236 | * signal because that may try to schedule a repaint which |
| 3237 | * will not work if the compositor is still sleeping */ |
| 3238 | compositor->state = WESTON_COMPOSITOR_ACTIVE; |
| 3239 | |
| 3240 | switch (old_state) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3241 | case WESTON_COMPOSITOR_SLEEPING: |
| 3242 | weston_compositor_dpms(compositor, WESTON_DPMS_ON); |
| 3243 | /* fall through */ |
| 3244 | case WESTON_COMPOSITOR_IDLE: |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 3245 | case WESTON_COMPOSITOR_OFFSCREEN: |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 3246 | wl_signal_emit(&compositor->wake_signal, compositor); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3247 | /* fall through */ |
| 3248 | default: |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3249 | wl_event_source_timer_update(compositor->idle_source, |
| 3250 | compositor->idle_time * 1000); |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3251 | } |
| 3252 | } |
| 3253 | |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3254 | WL_EXPORT void |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 3255 | weston_compositor_offscreen(struct weston_compositor *compositor) |
| 3256 | { |
| 3257 | switch (compositor->state) { |
| 3258 | case WESTON_COMPOSITOR_OFFSCREEN: |
| 3259 | return; |
| 3260 | case WESTON_COMPOSITOR_SLEEPING: |
| 3261 | weston_compositor_dpms(compositor, WESTON_DPMS_ON); |
| 3262 | /* fall through */ |
| 3263 | default: |
| 3264 | compositor->state = WESTON_COMPOSITOR_OFFSCREEN; |
| 3265 | wl_event_source_timer_update(compositor->idle_source, 0); |
| 3266 | } |
| 3267 | } |
| 3268 | |
| 3269 | WL_EXPORT void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3270 | weston_compositor_sleep(struct weston_compositor *compositor) |
| 3271 | { |
| 3272 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING) |
| 3273 | return; |
| 3274 | |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 3275 | wl_event_source_timer_update(compositor->idle_source, 0); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3276 | compositor->state = WESTON_COMPOSITOR_SLEEPING; |
| 3277 | weston_compositor_dpms(compositor, WESTON_DPMS_OFF); |
| 3278 | } |
| 3279 | |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 3280 | static int |
| 3281 | idle_handler(void *data) |
| 3282 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3283 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 3284 | |
| 3285 | if (compositor->idle_inhibit) |
| 3286 | return 1; |
| 3287 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3288 | compositor->state = WESTON_COMPOSITOR_IDLE; |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 3289 | wl_signal_emit(&compositor->idle_signal, compositor); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 3290 | |
| 3291 | return 1; |
| 3292 | } |
| 3293 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 3294 | WL_EXPORT void |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 3295 | weston_plane_init(struct weston_plane *plane, |
| 3296 | struct weston_compositor *ec, |
| 3297 | int32_t x, int32_t y) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 3298 | { |
| 3299 | pixman_region32_init(&plane->damage); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 3300 | pixman_region32_init(&plane->clip); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 3301 | plane->x = x; |
| 3302 | plane->y = y; |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 3303 | plane->compositor = ec; |
Ander Conselvan de Oliveira | 3c36bf3 | 2013-07-05 16:05:26 +0300 | [diff] [blame] | 3304 | |
| 3305 | /* Init the link so that the call to wl_list_remove() when releasing |
| 3306 | * the plane without ever stacking doesn't lead to a crash */ |
| 3307 | wl_list_init(&plane->link); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 3308 | } |
| 3309 | |
| 3310 | WL_EXPORT void |
| 3311 | weston_plane_release(struct weston_plane *plane) |
| 3312 | { |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 3313 | struct weston_view *view; |
| 3314 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 3315 | pixman_region32_fini(&plane->damage); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 3316 | pixman_region32_fini(&plane->clip); |
Ander Conselvan de Oliveira | 3c36bf3 | 2013-07-05 16:05:26 +0300 | [diff] [blame] | 3317 | |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 3318 | wl_list_for_each(view, &plane->compositor->view_list, link) { |
| 3319 | if (view->plane == plane) |
| 3320 | view->plane = NULL; |
| 3321 | } |
| 3322 | |
Ander Conselvan de Oliveira | 3c36bf3 | 2013-07-05 16:05:26 +0300 | [diff] [blame] | 3323 | wl_list_remove(&plane->link); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 3324 | } |
| 3325 | |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 3326 | WL_EXPORT void |
| 3327 | weston_compositor_stack_plane(struct weston_compositor *ec, |
| 3328 | struct weston_plane *plane, |
| 3329 | struct weston_plane *above) |
| 3330 | { |
| 3331 | if (above) |
| 3332 | wl_list_insert(above->link.prev, &plane->link); |
| 3333 | else |
| 3334 | wl_list_insert(&ec->plane_list, &plane->link); |
| 3335 | } |
| 3336 | |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 3337 | static void unbind_resource(struct wl_resource *resource) |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 3338 | { |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3339 | wl_list_remove(wl_resource_get_link(resource)); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 3340 | } |
| 3341 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 3342 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 3343 | bind_output(struct wl_client *client, |
| 3344 | void *data, uint32_t version, uint32_t id) |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 3345 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3346 | struct weston_output *output = data; |
| 3347 | struct weston_mode *mode; |
Kristian Høgsberg | fd07fb7 | 2011-08-29 15:03:09 -0400 | [diff] [blame] | 3348 | struct wl_resource *resource; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 3349 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3350 | resource = wl_resource_create(client, &wl_output_interface, |
| 3351 | MIN(version, 2), id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 3352 | if (resource == NULL) { |
| 3353 | wl_client_post_no_memory(client); |
| 3354 | return; |
| 3355 | } |
Kristian Høgsberg | fd07fb7 | 2011-08-29 15:03:09 -0400 | [diff] [blame] | 3356 | |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3357 | wl_list_insert(&output->resource_list, wl_resource_get_link(resource)); |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3358 | wl_resource_set_implementation(resource, NULL, data, unbind_resource); |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 3359 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3360 | wl_output_send_geometry(resource, |
| 3361 | output->x, |
| 3362 | output->y, |
| 3363 | output->mm_width, |
| 3364 | output->mm_height, |
| 3365 | output->subpixel, |
Kristian Høgsberg | 0e69647 | 2012-07-22 15:49:57 -0400 | [diff] [blame] | 3366 | output->make, output->model, |
Kristian Høgsberg | 05890dc | 2012-08-10 10:09:20 -0400 | [diff] [blame] | 3367 | output->transform); |
Jasper St. Pierre | 0013a29 | 2014-08-07 16:43:11 -0400 | [diff] [blame] | 3368 | if (version >= WL_OUTPUT_SCALE_SINCE_VERSION) |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3369 | wl_output_send_scale(resource, |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 3370 | output->current_scale); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 3371 | |
| 3372 | wl_list_for_each (mode, &output->mode_list, link) { |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3373 | wl_output_send_mode(resource, |
| 3374 | mode->flags, |
| 3375 | mode->width, |
| 3376 | mode->height, |
| 3377 | mode->refresh); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 3378 | } |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3379 | |
Jasper St. Pierre | 0013a29 | 2014-08-07 16:43:11 -0400 | [diff] [blame] | 3380 | if (version >= WL_OUTPUT_DONE_SINCE_VERSION) |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3381 | wl_output_send_done(resource); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 3382 | } |
| 3383 | |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 3384 | /* Move other outputs when one is removed so the space remains contiguos. */ |
| 3385 | static void |
| 3386 | weston_compositor_remove_output(struct weston_compositor *compositor, |
| 3387 | struct weston_output *remove_output) |
| 3388 | { |
| 3389 | struct weston_output *output; |
| 3390 | int offset = 0; |
| 3391 | |
| 3392 | wl_list_for_each(output, &compositor->output_list, link) { |
| 3393 | if (output == remove_output) { |
| 3394 | offset = output->width; |
| 3395 | continue; |
| 3396 | } |
| 3397 | |
| 3398 | if (offset > 0) { |
| 3399 | weston_output_move(output, |
| 3400 | output->x - offset, output->y); |
| 3401 | output->dirty = 1; |
| 3402 | } |
| 3403 | } |
| 3404 | } |
| 3405 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3406 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3407 | weston_output_destroy(struct weston_output *output) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 3408 | { |
Giulio Camuffo | 00535ce | 2014-09-06 16:18:02 +0300 | [diff] [blame] | 3409 | struct wl_resource *resource; |
| 3410 | |
Ander Conselvan de Oliveira | e1e2352 | 2013-12-13 22:10:55 +0200 | [diff] [blame] | 3411 | output->destroying = 1; |
| 3412 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3413 | weston_presentation_feedback_discard_list(&output->feedback_list); |
| 3414 | |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 3415 | weston_compositor_remove_output(output->compositor, output); |
Ander Conselvan de Oliveira | f749fc3 | 2013-12-13 22:10:50 +0200 | [diff] [blame] | 3416 | wl_list_remove(&output->link); |
| 3417 | |
Ander Conselvan de Oliveira | f84327a | 2014-01-29 18:47:51 +0200 | [diff] [blame] | 3418 | wl_signal_emit(&output->compositor->output_destroyed_signal, output); |
Richard Hughes | 64ddde1 | 2013-05-01 21:52:10 +0100 | [diff] [blame] | 3419 | wl_signal_emit(&output->destroy_signal, output); |
| 3420 | |
Richard Hughes | afe690c | 2013-05-02 10:10:04 +0100 | [diff] [blame] | 3421 | free(output->name); |
Kristian Høgsberg | e75cb7f | 2011-06-21 15:27:41 -0400 | [diff] [blame] | 3422 | pixman_region32_fini(&output->region); |
Ander Conselvan de Oliveira | b8fcca9 | 2012-11-16 17:23:52 +0200 | [diff] [blame] | 3423 | pixman_region32_fini(&output->previous_damage); |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 3424 | output->compositor->output_id_pool &= ~(1 << output->id); |
Benjamin Franzke | b687940 | 2012-04-10 18:28:54 +0200 | [diff] [blame] | 3425 | |
Giulio Camuffo | 00535ce | 2014-09-06 16:18:02 +0300 | [diff] [blame] | 3426 | wl_resource_for_each(resource, &output->resource_list) { |
| 3427 | wl_resource_set_destructor(resource, NULL); |
| 3428 | } |
| 3429 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 3430 | wl_global_destroy(output->global); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 3431 | } |
| 3432 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3433 | static void |
| 3434 | weston_output_compute_transform(struct weston_output *output) |
| 3435 | { |
| 3436 | struct weston_matrix transform; |
| 3437 | int flip; |
| 3438 | |
| 3439 | weston_matrix_init(&transform); |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3440 | transform.type = WESTON_MATRIX_TRANSFORM_ROTATE; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3441 | |
| 3442 | switch(output->transform) { |
| 3443 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 3444 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 3445 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 3446 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
Vasily Khoruzhick | 1bbf372 | 2013-01-28 22:40:28 +0300 | [diff] [blame] | 3447 | transform.type |= WESTON_MATRIX_TRANSFORM_OTHER; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3448 | flip = -1; |
| 3449 | break; |
| 3450 | default: |
| 3451 | flip = 1; |
| 3452 | break; |
| 3453 | } |
| 3454 | |
| 3455 | switch(output->transform) { |
| 3456 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 3457 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 3458 | transform.d[0] = flip; |
| 3459 | transform.d[1] = 0; |
| 3460 | transform.d[4] = 0; |
| 3461 | transform.d[5] = 1; |
| 3462 | break; |
| 3463 | case WL_OUTPUT_TRANSFORM_90: |
| 3464 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 3465 | transform.d[0] = 0; |
| 3466 | transform.d[1] = -flip; |
| 3467 | transform.d[4] = 1; |
| 3468 | transform.d[5] = 0; |
| 3469 | break; |
| 3470 | case WL_OUTPUT_TRANSFORM_180: |
| 3471 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 3472 | transform.d[0] = -flip; |
| 3473 | transform.d[1] = 0; |
| 3474 | transform.d[4] = 0; |
| 3475 | transform.d[5] = -1; |
| 3476 | break; |
| 3477 | case WL_OUTPUT_TRANSFORM_270: |
| 3478 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 3479 | transform.d[0] = 0; |
| 3480 | transform.d[1] = flip; |
| 3481 | transform.d[4] = -1; |
| 3482 | transform.d[5] = 0; |
| 3483 | break; |
| 3484 | default: |
| 3485 | break; |
| 3486 | } |
| 3487 | |
| 3488 | weston_matrix_multiply(&output->matrix, &transform); |
| 3489 | } |
| 3490 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3491 | WL_EXPORT void |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3492 | weston_output_update_matrix(struct weston_output *output) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 3493 | { |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 3494 | float magnification; |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 3495 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3496 | weston_matrix_init(&output->matrix); |
| 3497 | weston_matrix_translate(&output->matrix, |
Jason Ekstrand | 00b8428 | 2013-10-27 22:24:59 -0500 | [diff] [blame] | 3498 | -(output->x + output->width / 2.0), |
| 3499 | -(output->y + output->height / 2.0), 0); |
Benjamin Franzke | 1b765ff | 2011-02-18 16:51:37 +0100 | [diff] [blame] | 3500 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3501 | weston_matrix_scale(&output->matrix, |
Jason Ekstrand | 00b8428 | 2013-10-27 22:24:59 -0500 | [diff] [blame] | 3502 | 2.0 / output->width, |
| 3503 | -2.0 / output->height, 1); |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3504 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3505 | if (output->zoom.active) { |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3506 | magnification = 1 / (1 - output->zoom.spring_z.current); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3507 | weston_output_update_zoom(output); |
Neil Roberts | 1e40a7e | 2014-04-25 13:19:37 +0100 | [diff] [blame] | 3508 | weston_matrix_translate(&output->matrix, -output->zoom.trans_x, |
| 3509 | output->zoom.trans_y, 0); |
| 3510 | weston_matrix_scale(&output->matrix, magnification, |
| 3511 | magnification, 1.0); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3512 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 3513 | |
Neil Roberts | 6c3b01f | 2014-05-06 19:04:15 +0100 | [diff] [blame] | 3514 | weston_output_compute_transform(output); |
| 3515 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3516 | output->dirty = 0; |
| 3517 | } |
| 3518 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3519 | static void |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 3520 | 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] | 3521 | { |
| 3522 | output->transform = transform; |
| 3523 | |
| 3524 | switch (transform) { |
| 3525 | case WL_OUTPUT_TRANSFORM_90: |
| 3526 | case WL_OUTPUT_TRANSFORM_270: |
| 3527 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 3528 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 3529 | /* Swap width and height */ |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 3530 | output->width = output->current_mode->height; |
| 3531 | output->height = output->current_mode->width; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3532 | break; |
| 3533 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 3534 | case WL_OUTPUT_TRANSFORM_180: |
| 3535 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 3536 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 3537 | output->width = output->current_mode->width; |
| 3538 | output->height = output->current_mode->height; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3539 | break; |
| 3540 | default: |
| 3541 | break; |
| 3542 | } |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3543 | |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 3544 | output->native_scale = output->current_scale = scale; |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 3545 | output->width /= scale; |
| 3546 | output->height /= scale; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3547 | } |
| 3548 | |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 3549 | static void |
| 3550 | weston_output_init_geometry(struct weston_output *output, int x, int y) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3551 | { |
| 3552 | output->x = x; |
| 3553 | output->y = y; |
| 3554 | |
Ander Conselvan de Oliveira | b8fcca9 | 2012-11-16 17:23:52 +0200 | [diff] [blame] | 3555 | pixman_region32_init(&output->previous_damage); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3556 | pixman_region32_init_rect(&output->region, x, y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3557 | output->width, |
| 3558 | output->height); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 3559 | } |
| 3560 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3561 | WL_EXPORT void |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 3562 | weston_output_move(struct weston_output *output, int x, int y) |
| 3563 | { |
| 3564 | pixman_region32_t old_region; |
| 3565 | struct wl_resource *resource; |
| 3566 | |
| 3567 | output->move_x = x - output->x; |
| 3568 | output->move_y = y - output->y; |
| 3569 | |
| 3570 | if (output->move_x == 0 && output->move_y == 0) |
| 3571 | return; |
| 3572 | |
| 3573 | pixman_region32_init(&old_region); |
| 3574 | pixman_region32_copy(&old_region, &output->region); |
| 3575 | |
| 3576 | weston_output_init_geometry(output, x, y); |
| 3577 | |
| 3578 | output->dirty = 1; |
| 3579 | |
| 3580 | /* Move views on this output. */ |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 3581 | wl_signal_emit(&output->compositor->output_moved_signal, output); |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 3582 | |
| 3583 | /* Notify clients of the change for output position. */ |
Quanxian Wang | b2c8636 | 2014-03-14 09:16:25 +0800 | [diff] [blame] | 3584 | wl_resource_for_each(resource, &output->resource_list) { |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 3585 | wl_output_send_geometry(resource, |
| 3586 | output->x, |
| 3587 | output->y, |
| 3588 | output->mm_width, |
| 3589 | output->mm_height, |
| 3590 | output->subpixel, |
| 3591 | output->make, |
| 3592 | output->model, |
| 3593 | output->transform); |
Quanxian Wang | b2c8636 | 2014-03-14 09:16:25 +0800 | [diff] [blame] | 3594 | |
| 3595 | if (wl_resource_get_version(resource) >= 2) |
| 3596 | wl_output_send_done(resource); |
| 3597 | } |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 3598 | } |
| 3599 | |
| 3600 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3601 | weston_output_init(struct weston_output *output, struct weston_compositor *c, |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 3602 | 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] | 3603 | int32_t scale) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 3604 | { |
| 3605 | output->compositor = c; |
| 3606 | output->x = x; |
| 3607 | output->y = y; |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 3608 | output->mm_width = mm_width; |
| 3609 | output->mm_height = mm_height; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3610 | output->dirty = 1; |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 3611 | output->original_scale = scale; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3612 | |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 3613 | weston_output_transform_scale_init(output, transform, scale); |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 3614 | weston_output_init_zoom(output); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 3615 | |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 3616 | weston_output_init_geometry(output, x, y); |
Benjamin Franzke | 78db848 | 2012-04-10 18:35:33 +0200 | [diff] [blame] | 3617 | weston_output_damage(output); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 3618 | |
Kristian Høgsberg | 5fb70bf | 2012-05-24 12:29:46 -0400 | [diff] [blame] | 3619 | wl_signal_init(&output->frame_signal); |
Richard Hughes | 64ddde1 | 2013-05-01 21:52:10 +0100 | [diff] [blame] | 3620 | wl_signal_init(&output->destroy_signal); |
Scott Moreau | 9d1b112 | 2012-06-08 19:40:53 -0600 | [diff] [blame] | 3621 | wl_list_init(&output->animation_list); |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 3622 | wl_list_init(&output->resource_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3623 | wl_list_init(&output->feedback_list); |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 3624 | |
Casey Dahlin | 58ba137 | 2012-04-19 22:50:08 -0400 | [diff] [blame] | 3625 | output->id = ffs(~output->compositor->output_id_pool) - 1; |
| 3626 | output->compositor->output_id_pool |= 1 << output->id; |
| 3627 | |
Benjamin Franzke | b687940 | 2012-04-10 18:28:54 +0200 | [diff] [blame] | 3628 | output->global = |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 3629 | wl_global_create(c->wl_display, &wl_output_interface, 2, |
| 3630 | output, bind_output); |
Richard Hughes | 59d5da7 | 2013-05-01 21:52:11 +0100 | [diff] [blame] | 3631 | wl_signal_emit(&c->output_created_signal, output); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 3632 | } |
| 3633 | |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 3634 | WL_EXPORT void |
| 3635 | weston_output_transform_coordinate(struct weston_output *output, |
Jason Ekstrand | b6a3cc7 | 2013-10-27 22:25:00 -0500 | [diff] [blame] | 3636 | wl_fixed_t device_x, wl_fixed_t device_y, |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 3637 | wl_fixed_t *x, wl_fixed_t *y) |
| 3638 | { |
| 3639 | wl_fixed_t tx, ty; |
| 3640 | wl_fixed_t width, height; |
Neil Roberts | eb5a200 | 2014-05-01 16:13:55 +0100 | [diff] [blame] | 3641 | float zoom_scale, zx, zy; |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 3642 | |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 3643 | width = wl_fixed_from_int(output->width * output->current_scale - 1); |
| 3644 | height = wl_fixed_from_int(output->height * output->current_scale - 1); |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 3645 | |
| 3646 | switch(output->transform) { |
| 3647 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 3648 | default: |
Jason Ekstrand | b6a3cc7 | 2013-10-27 22:25:00 -0500 | [diff] [blame] | 3649 | tx = device_x; |
| 3650 | ty = device_y; |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 3651 | break; |
| 3652 | case WL_OUTPUT_TRANSFORM_90: |
Jason Ekstrand | b6a3cc7 | 2013-10-27 22:25:00 -0500 | [diff] [blame] | 3653 | tx = device_y; |
| 3654 | ty = height - device_x; |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 3655 | break; |
| 3656 | case WL_OUTPUT_TRANSFORM_180: |
Jason Ekstrand | b6a3cc7 | 2013-10-27 22:25:00 -0500 | [diff] [blame] | 3657 | tx = width - device_x; |
| 3658 | ty = height - device_y; |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 3659 | break; |
| 3660 | case WL_OUTPUT_TRANSFORM_270: |
Jason Ekstrand | b6a3cc7 | 2013-10-27 22:25:00 -0500 | [diff] [blame] | 3661 | tx = width - device_y; |
| 3662 | ty = device_x; |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 3663 | break; |
| 3664 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
Jason Ekstrand | b6a3cc7 | 2013-10-27 22:25:00 -0500 | [diff] [blame] | 3665 | tx = width - device_x; |
| 3666 | ty = device_y; |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 3667 | break; |
| 3668 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
Jason Ekstrand | b6a3cc7 | 2013-10-27 22:25:00 -0500 | [diff] [blame] | 3669 | tx = width - device_y; |
| 3670 | ty = height - device_x; |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 3671 | break; |
| 3672 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
Jason Ekstrand | b6a3cc7 | 2013-10-27 22:25:00 -0500 | [diff] [blame] | 3673 | tx = device_x; |
| 3674 | ty = height - device_y; |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 3675 | break; |
| 3676 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
Jason Ekstrand | b6a3cc7 | 2013-10-27 22:25:00 -0500 | [diff] [blame] | 3677 | tx = device_y; |
| 3678 | ty = device_x; |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 3679 | break; |
| 3680 | } |
| 3681 | |
Neil Roberts | eb5a200 | 2014-05-01 16:13:55 +0100 | [diff] [blame] | 3682 | tx /= output->current_scale; |
| 3683 | ty /= output->current_scale; |
| 3684 | |
| 3685 | if (output->zoom.active) { |
| 3686 | zoom_scale = output->zoom.spring_z.current; |
| 3687 | zx = (wl_fixed_to_double(tx) * (1.0f - zoom_scale) + |
| 3688 | output->width / 2.0f * |
| 3689 | (zoom_scale + output->zoom.trans_x)); |
| 3690 | zy = (wl_fixed_to_double(ty) * (1.0f - zoom_scale) + |
| 3691 | output->height / 2.0f * |
| 3692 | (zoom_scale + output->zoom.trans_y)); |
| 3693 | tx = wl_fixed_from_double(zx); |
| 3694 | ty = wl_fixed_from_double(zy); |
| 3695 | } |
| 3696 | |
| 3697 | *x = tx + wl_fixed_from_int(output->x); |
| 3698 | *y = ty + wl_fixed_from_int(output->y); |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 3699 | } |
| 3700 | |
Benjamin Franzke | 315b3dc | 2011-03-08 11:32:57 +0100 | [diff] [blame] | 3701 | static void |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 3702 | destroy_viewport(struct wl_resource *resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 3703 | { |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 3704 | struct weston_surface *surface = |
| 3705 | wl_resource_get_user_data(resource); |
| 3706 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 3707 | surface->viewport_resource = NULL; |
Pekka Paalanen | f0cad48 | 2014-03-14 14:38:16 +0200 | [diff] [blame] | 3708 | surface->pending.buffer_viewport.buffer.src_width = |
| 3709 | wl_fixed_from_int(-1); |
| 3710 | surface->pending.buffer_viewport.surface.width = -1; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3711 | surface->pending.buffer_viewport.changed = 1; |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 3712 | } |
| 3713 | |
| 3714 | static void |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 3715 | viewport_destroy(struct wl_client *client, |
| 3716 | struct wl_resource *resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 3717 | { |
| 3718 | wl_resource_destroy(resource); |
| 3719 | } |
| 3720 | |
| 3721 | static void |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 3722 | viewport_set(struct wl_client *client, |
| 3723 | struct wl_resource *resource, |
| 3724 | wl_fixed_t src_x, |
| 3725 | wl_fixed_t src_y, |
| 3726 | wl_fixed_t src_width, |
| 3727 | wl_fixed_t src_height, |
| 3728 | int32_t dst_width, |
| 3729 | int32_t dst_height) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 3730 | { |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 3731 | struct weston_surface *surface = |
| 3732 | wl_resource_get_user_data(resource); |
| 3733 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 3734 | assert(surface->viewport_resource != NULL); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 3735 | |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 3736 | if (wl_fixed_to_double(src_width) < 0 || |
| 3737 | wl_fixed_to_double(src_height) < 0) { |
| 3738 | wl_resource_post_error(resource, |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 3739 | WL_VIEWPORT_ERROR_BAD_VALUE, |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 3740 | "source dimensions must be non-negative (%fx%f)", |
| 3741 | wl_fixed_to_double(src_width), |
| 3742 | wl_fixed_to_double(src_height)); |
| 3743 | return; |
| 3744 | } |
| 3745 | |
| 3746 | if (dst_width <= 0 || dst_height <= 0) { |
| 3747 | wl_resource_post_error(resource, |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 3748 | WL_VIEWPORT_ERROR_BAD_VALUE, |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 3749 | "destination dimensions must be positive (%dx%d)", |
| 3750 | dst_width, dst_height); |
| 3751 | return; |
| 3752 | } |
| 3753 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 3754 | surface->pending.buffer_viewport.buffer.src_x = src_x; |
| 3755 | surface->pending.buffer_viewport.buffer.src_y = src_y; |
| 3756 | surface->pending.buffer_viewport.buffer.src_width = src_width; |
| 3757 | surface->pending.buffer_viewport.buffer.src_height = src_height; |
| 3758 | surface->pending.buffer_viewport.surface.width = dst_width; |
| 3759 | surface->pending.buffer_viewport.surface.height = dst_height; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3760 | surface->pending.buffer_viewport.changed = 1; |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 3761 | } |
| 3762 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 3763 | static void |
| 3764 | viewport_set_source(struct wl_client *client, |
| 3765 | struct wl_resource *resource, |
| 3766 | wl_fixed_t src_x, |
| 3767 | wl_fixed_t src_y, |
| 3768 | wl_fixed_t src_width, |
| 3769 | wl_fixed_t src_height) |
| 3770 | { |
| 3771 | struct weston_surface *surface = |
| 3772 | wl_resource_get_user_data(resource); |
| 3773 | |
| 3774 | assert(surface->viewport_resource != NULL); |
| 3775 | |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 3776 | if (src_width == wl_fixed_from_int(-1) && |
| 3777 | src_height == wl_fixed_from_int(-1)) { |
| 3778 | /* unset source size */ |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 3779 | surface->pending.buffer_viewport.buffer.src_width = |
| 3780 | wl_fixed_from_int(-1); |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3781 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 3782 | return; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 3783 | } |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 3784 | |
| 3785 | if (src_width <= 0 || src_height <= 0) { |
| 3786 | wl_resource_post_error(resource, |
| 3787 | WL_VIEWPORT_ERROR_BAD_VALUE, |
| 3788 | "source size must be positive (%fx%f)", |
| 3789 | wl_fixed_to_double(src_width), |
| 3790 | wl_fixed_to_double(src_height)); |
| 3791 | return; |
| 3792 | } |
| 3793 | |
| 3794 | surface->pending.buffer_viewport.buffer.src_x = src_x; |
| 3795 | surface->pending.buffer_viewport.buffer.src_y = src_y; |
| 3796 | surface->pending.buffer_viewport.buffer.src_width = src_width; |
| 3797 | surface->pending.buffer_viewport.buffer.src_height = src_height; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3798 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 3799 | } |
| 3800 | |
| 3801 | static void |
| 3802 | viewport_set_destination(struct wl_client *client, |
| 3803 | struct wl_resource *resource, |
| 3804 | int32_t dst_width, |
| 3805 | int32_t dst_height) |
| 3806 | { |
| 3807 | struct weston_surface *surface = |
| 3808 | wl_resource_get_user_data(resource); |
| 3809 | |
| 3810 | assert(surface->viewport_resource != NULL); |
| 3811 | |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 3812 | if (dst_width == -1 && dst_height == -1) { |
| 3813 | /* unset destination size */ |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 3814 | surface->pending.buffer_viewport.surface.width = -1; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3815 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 3816 | return; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 3817 | } |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 3818 | |
| 3819 | if (dst_width <= 0 || dst_height <= 0) { |
| 3820 | wl_resource_post_error(resource, |
| 3821 | WL_VIEWPORT_ERROR_BAD_VALUE, |
| 3822 | "destination size must be positive (%dx%d)", |
| 3823 | dst_width, dst_height); |
| 3824 | return; |
| 3825 | } |
| 3826 | |
| 3827 | surface->pending.buffer_viewport.surface.width = dst_width; |
| 3828 | surface->pending.buffer_viewport.surface.height = dst_height; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3829 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 3830 | } |
| 3831 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 3832 | static const struct wl_viewport_interface viewport_interface = { |
| 3833 | viewport_destroy, |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 3834 | viewport_set, |
| 3835 | viewport_set_source, |
| 3836 | viewport_set_destination |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 3837 | }; |
| 3838 | |
| 3839 | static void |
| 3840 | scaler_destroy(struct wl_client *client, |
| 3841 | struct wl_resource *resource) |
| 3842 | { |
| 3843 | wl_resource_destroy(resource); |
| 3844 | } |
| 3845 | |
| 3846 | static void |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 3847 | scaler_get_viewport(struct wl_client *client, |
| 3848 | struct wl_resource *scaler, |
| 3849 | uint32_t id, |
| 3850 | struct wl_resource *surface_resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 3851 | { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 3852 | int version = wl_resource_get_version(scaler); |
| 3853 | struct weston_surface *surface = |
| 3854 | wl_resource_get_user_data(surface_resource); |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 3855 | struct wl_resource *resource; |
| 3856 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 3857 | if (surface->viewport_resource) { |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 3858 | wl_resource_post_error(scaler, |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 3859 | WL_SCALER_ERROR_VIEWPORT_EXISTS, |
| 3860 | "a viewport for that surface already exists"); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 3861 | return; |
| 3862 | } |
| 3863 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 3864 | resource = wl_resource_create(client, &wl_viewport_interface, |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 3865 | version, id); |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 3866 | if (resource == NULL) { |
| 3867 | wl_client_post_no_memory(client); |
| 3868 | return; |
| 3869 | } |
| 3870 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 3871 | wl_resource_set_implementation(resource, &viewport_interface, |
| 3872 | surface, destroy_viewport); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 3873 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 3874 | surface->viewport_resource = resource; |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 3875 | } |
| 3876 | |
| 3877 | static const struct wl_scaler_interface scaler_interface = { |
| 3878 | scaler_destroy, |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 3879 | scaler_get_viewport |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 3880 | }; |
| 3881 | |
| 3882 | static void |
| 3883 | bind_scaler(struct wl_client *client, |
| 3884 | void *data, uint32_t version, uint32_t id) |
| 3885 | { |
| 3886 | struct wl_resource *resource; |
| 3887 | |
| 3888 | resource = wl_resource_create(client, &wl_scaler_interface, |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 3889 | MIN(version, 2), id); |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 3890 | if (resource == NULL) { |
| 3891 | wl_client_post_no_memory(client); |
| 3892 | return; |
| 3893 | } |
| 3894 | |
| 3895 | wl_resource_set_implementation(resource, &scaler_interface, |
| 3896 | NULL, NULL); |
| 3897 | } |
| 3898 | |
| 3899 | static void |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3900 | destroy_presentation_feedback(struct wl_resource *feedback_resource) |
| 3901 | { |
| 3902 | struct weston_presentation_feedback *feedback; |
| 3903 | |
| 3904 | feedback = wl_resource_get_user_data(feedback_resource); |
| 3905 | |
| 3906 | wl_list_remove(&feedback->link); |
| 3907 | free(feedback); |
| 3908 | } |
| 3909 | |
| 3910 | static void |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 3911 | presentation_destroy(struct wl_client *client, struct wl_resource *resource) |
| 3912 | { |
| 3913 | wl_resource_destroy(resource); |
| 3914 | } |
| 3915 | |
| 3916 | static void |
| 3917 | presentation_feedback(struct wl_client *client, |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3918 | struct wl_resource *presentation_resource, |
| 3919 | struct wl_resource *surface_resource, |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 3920 | uint32_t callback) |
| 3921 | { |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3922 | struct weston_surface *surface; |
| 3923 | struct weston_presentation_feedback *feedback; |
| 3924 | |
| 3925 | surface = wl_resource_get_user_data(surface_resource); |
| 3926 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 3927 | feedback = zalloc(sizeof *feedback); |
| 3928 | if (feedback == NULL) |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3929 | goto err_calloc; |
| 3930 | |
| 3931 | feedback->resource = wl_resource_create(client, |
| 3932 | &presentation_feedback_interface, |
| 3933 | 1, callback); |
| 3934 | if (!feedback->resource) |
| 3935 | goto err_create; |
| 3936 | |
| 3937 | wl_resource_set_implementation(feedback->resource, NULL, feedback, |
| 3938 | destroy_presentation_feedback); |
| 3939 | |
| 3940 | wl_list_insert(&surface->pending.feedback_list, &feedback->link); |
| 3941 | |
| 3942 | return; |
| 3943 | |
| 3944 | err_create: |
| 3945 | free(feedback); |
| 3946 | |
| 3947 | err_calloc: |
| 3948 | wl_client_post_no_memory(client); |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 3949 | } |
| 3950 | |
| 3951 | static const struct presentation_interface presentation_implementation = { |
| 3952 | presentation_destroy, |
| 3953 | presentation_feedback |
| 3954 | }; |
| 3955 | |
| 3956 | static void |
| 3957 | bind_presentation(struct wl_client *client, |
| 3958 | void *data, uint32_t version, uint32_t id) |
| 3959 | { |
| 3960 | struct weston_compositor *compositor = data; |
| 3961 | struct wl_resource *resource; |
| 3962 | |
| 3963 | resource = wl_resource_create(client, &presentation_interface, |
| 3964 | MIN(version, 1), id); |
| 3965 | if (resource == NULL) { |
| 3966 | wl_client_post_no_memory(client); |
| 3967 | return; |
| 3968 | } |
| 3969 | |
| 3970 | wl_resource_set_implementation(resource, &presentation_implementation, |
| 3971 | compositor, NULL); |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 3972 | presentation_send_clock_id(resource, compositor->presentation_clock); |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 3973 | } |
| 3974 | |
| 3975 | static void |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 3976 | compositor_bind(struct wl_client *client, |
| 3977 | void *data, uint32_t version, uint32_t id) |
| 3978 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3979 | struct weston_compositor *compositor = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3980 | struct wl_resource *resource; |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 3981 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3982 | resource = wl_resource_create(client, &wl_compositor_interface, |
| 3983 | MIN(version, 3), id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 3984 | if (resource == NULL) { |
| 3985 | wl_client_post_no_memory(client); |
| 3986 | return; |
| 3987 | } |
| 3988 | |
| 3989 | wl_resource_set_implementation(resource, &compositor_interface, |
| 3990 | compositor, NULL); |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 3991 | } |
| 3992 | |
Kristian Høgsberg | fc9c5e0 | 2012-06-08 16:45:33 -0400 | [diff] [blame] | 3993 | static void |
Martin Minarik | f12c287 | 2012-06-11 00:57:39 +0200 | [diff] [blame] | 3994 | log_uname(void) |
| 3995 | { |
| 3996 | struct utsname usys; |
| 3997 | |
| 3998 | uname(&usys); |
| 3999 | |
| 4000 | weston_log("OS: %s, %s, %s, %s\n", usys.sysname, usys.release, |
| 4001 | usys.version, usys.machine); |
| 4002 | } |
| 4003 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 4004 | WL_EXPORT int |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 4005 | weston_environment_get_fd(const char *env) |
| 4006 | { |
| 4007 | char *e, *end; |
| 4008 | int fd, flags; |
| 4009 | |
| 4010 | e = getenv(env); |
| 4011 | if (!e) |
| 4012 | return -1; |
| 4013 | fd = strtol(e, &end, 0); |
| 4014 | if (*end != '\0') |
| 4015 | return -1; |
| 4016 | |
| 4017 | flags = fcntl(fd, F_GETFD); |
| 4018 | if (flags == -1) |
| 4019 | return -1; |
| 4020 | |
| 4021 | fcntl(fd, F_SETFD, flags | FD_CLOEXEC); |
| 4022 | unsetenv(env); |
| 4023 | |
| 4024 | return fd; |
| 4025 | } |
| 4026 | |
| 4027 | WL_EXPORT int |
Daniel Stone | baf4359 | 2012-06-01 11:11:10 -0400 | [diff] [blame] | 4028 | weston_compositor_init(struct weston_compositor *ec, |
| 4029 | struct wl_display *display, |
Kristian Høgsberg | 4172f66 | 2013-02-20 15:27:49 -0500 | [diff] [blame] | 4030 | int *argc, char *argv[], |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 4031 | struct weston_config *config) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 4032 | { |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 4033 | struct wl_event_loop *loop; |
Daniel Stone | e2ef43a | 2012-06-01 12:14:05 +0100 | [diff] [blame] | 4034 | struct xkb_rule_names xkb_names; |
Kristian Høgsberg | 6a04791 | 2013-05-23 15:56:29 -0400 | [diff] [blame] | 4035 | struct weston_config_section *s; |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 4036 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 4037 | ec->config = config; |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 4038 | ec->wl_display = display; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 4039 | wl_signal_init(&ec->destroy_signal); |
Kristian Høgsberg | f03a04a | 2014-04-06 22:04:50 -0700 | [diff] [blame] | 4040 | wl_signal_init(&ec->create_surface_signal); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 4041 | wl_signal_init(&ec->activate_signal); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 4042 | wl_signal_init(&ec->transform_signal); |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 4043 | wl_signal_init(&ec->kill_signal); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4044 | wl_signal_init(&ec->idle_signal); |
| 4045 | wl_signal_init(&ec->wake_signal); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4046 | wl_signal_init(&ec->show_input_panel_signal); |
| 4047 | wl_signal_init(&ec->hide_input_panel_signal); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4048 | wl_signal_init(&ec->update_input_panel_signal); |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 4049 | wl_signal_init(&ec->seat_created_signal); |
Richard Hughes | 59d5da7 | 2013-05-01 21:52:11 +0100 | [diff] [blame] | 4050 | wl_signal_init(&ec->output_created_signal); |
Ander Conselvan de Oliveira | f84327a | 2014-01-29 18:47:51 +0200 | [diff] [blame] | 4051 | wl_signal_init(&ec->output_destroyed_signal); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4052 | wl_signal_init(&ec->output_moved_signal); |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 4053 | wl_signal_init(&ec->session_signal); |
| 4054 | ec->session_active = 1; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 4055 | |
Casey Dahlin | 58ba137 | 2012-04-19 22:50:08 -0400 | [diff] [blame] | 4056 | ec->output_id_pool = 0; |
| 4057 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 4058 | if (!wl_global_create(display, &wl_compositor_interface, 3, |
| 4059 | ec, compositor_bind)) |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 4060 | return -1; |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 4061 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 4062 | if (!wl_global_create(display, &wl_subcompositor_interface, 1, |
| 4063 | ec, bind_subcompositor)) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4064 | return -1; |
| 4065 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 4066 | if (!wl_global_create(ec->wl_display, &wl_scaler_interface, 2, |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 4067 | ec, bind_scaler)) |
| 4068 | return -1; |
| 4069 | |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 4070 | if (!wl_global_create(ec->wl_display, &presentation_interface, 1, |
| 4071 | ec, bind_presentation)) |
| 4072 | return -1; |
| 4073 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4074 | wl_list_init(&ec->view_list); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 4075 | wl_list_init(&ec->plane_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 4076 | wl_list_init(&ec->layer_list); |
| 4077 | wl_list_init(&ec->seat_list); |
| 4078 | wl_list_init(&ec->output_list); |
| 4079 | wl_list_init(&ec->key_binding_list); |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 4080 | wl_list_init(&ec->modifier_binding_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 4081 | wl_list_init(&ec->button_binding_list); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4082 | wl_list_init(&ec->touch_binding_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 4083 | wl_list_init(&ec->axis_binding_list); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 4084 | wl_list_init(&ec->debug_binding_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 4085 | |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 4086 | weston_plane_init(&ec->primary_plane, ec, 0, 0); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 4087 | weston_compositor_stack_plane(ec, &ec->primary_plane, NULL); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4088 | |
Kristian Høgsberg | 6a04791 | 2013-05-23 15:56:29 -0400 | [diff] [blame] | 4089 | s = weston_config_get_section(ec->config, "keyboard", NULL, NULL); |
| 4090 | weston_config_section_get_string(s, "keymap_rules", |
| 4091 | (char **) &xkb_names.rules, NULL); |
| 4092 | weston_config_section_get_string(s, "keymap_model", |
| 4093 | (char **) &xkb_names.model, NULL); |
| 4094 | weston_config_section_get_string(s, "keymap_layout", |
| 4095 | (char **) &xkb_names.layout, NULL); |
| 4096 | weston_config_section_get_string(s, "keymap_variant", |
| 4097 | (char **) &xkb_names.variant, NULL); |
| 4098 | weston_config_section_get_string(s, "keymap_options", |
| 4099 | (char **) &xkb_names.options, NULL); |
Rob Bradford | 382ff46 | 2013-06-24 16:52:45 +0100 | [diff] [blame] | 4100 | |
Kristian Høgsberg | 2f07ef6 | 2013-02-16 14:29:24 -0500 | [diff] [blame] | 4101 | if (weston_compositor_xkb_init(ec, &xkb_names) < 0) |
| 4102 | return -1; |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 4103 | |
Jonny Lamb | 66a41a0 | 2014-08-12 14:58:25 +0200 | [diff] [blame] | 4104 | weston_config_section_get_int(s, "repeat-rate", |
| 4105 | &ec->kb_repeat_rate, 40); |
| 4106 | weston_config_section_get_int(s, "repeat-delay", |
| 4107 | &ec->kb_repeat_delay, 400); |
| 4108 | |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 4109 | text_backend_init(ec); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 4110 | |
| 4111 | wl_data_device_manager_init(ec->wl_display); |
| 4112 | |
Kristian Høgsberg | 9629fe3 | 2012-03-26 15:56:39 -0400 | [diff] [blame] | 4113 | wl_display_init_shm(display); |
Kristian Høgsberg | b5819dc | 2011-04-25 15:08:20 -0400 | [diff] [blame] | 4114 | |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 4115 | loop = wl_display_get_event_loop(ec->wl_display); |
| 4116 | ec->idle_source = wl_event_loop_add_timer(loop, idle_handler, ec); |
| 4117 | wl_event_source_timer_update(ec->idle_source, ec->idle_time * 1000); |
| 4118 | |
| 4119 | ec->input_loop = wl_event_loop_create(); |
| 4120 | |
Kristian Høgsberg | 861a50c | 2012-09-05 22:02:22 -0400 | [diff] [blame] | 4121 | weston_layer_init(&ec->fade_layer, &ec->layer_list); |
| 4122 | weston_layer_init(&ec->cursor_layer, &ec->fade_layer.link); |
| 4123 | |
| 4124 | weston_compositor_schedule_repaint(ec); |
| 4125 | |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 4126 | return 0; |
| 4127 | } |
| 4128 | |
Benjamin Franzke | b826302 | 2011-08-30 11:32:47 +0200 | [diff] [blame] | 4129 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4130 | weston_compositor_shutdown(struct weston_compositor *ec) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 4131 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4132 | struct weston_output *output, *next; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 4133 | |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 4134 | wl_event_source_remove(ec->idle_source); |
Jonas Ådahl | c97af92 | 2012-03-28 22:36:09 +0200 | [diff] [blame] | 4135 | if (ec->input_loop_source) |
| 4136 | wl_event_source_remove(ec->input_loop_source); |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 4137 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 4138 | /* Destroy all outputs associated with this compositor */ |
Tiago Vignatti | b303a1d | 2011-12-18 22:27:40 +0200 | [diff] [blame] | 4139 | wl_list_for_each_safe(output, next, &ec->output_list, link) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 4140 | output->destroy(output); |
Pekka Paalanen | 4738f3b | 2012-01-02 15:47:07 +0200 | [diff] [blame] | 4141 | |
Ander Conselvan de Oliveira | 1853676 | 2013-12-20 21:07:00 +0200 | [diff] [blame] | 4142 | if (ec->renderer) |
| 4143 | ec->renderer->destroy(ec); |
| 4144 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4145 | weston_binding_list_destroy_all(&ec->key_binding_list); |
| 4146 | weston_binding_list_destroy_all(&ec->button_binding_list); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4147 | weston_binding_list_destroy_all(&ec->touch_binding_list); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4148 | weston_binding_list_destroy_all(&ec->axis_binding_list); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 4149 | weston_binding_list_destroy_all(&ec->debug_binding_list); |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 4150 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4151 | weston_plane_release(&ec->primary_plane); |
| 4152 | |
Jonas Ådahl | c97af92 | 2012-03-28 22:36:09 +0200 | [diff] [blame] | 4153 | wl_event_loop_destroy(ec->input_loop); |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 4154 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 4155 | weston_config_destroy(ec->config); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 4156 | } |
| 4157 | |
Kristian Høgsberg | af4f2aa | 2013-02-15 20:53:20 -0500 | [diff] [blame] | 4158 | WL_EXPORT void |
Frederic Plourde | c336f06 | 2014-10-29 14:44:33 -0400 | [diff] [blame] | 4159 | weston_compositor_exit_with_code(struct weston_compositor *compositor, |
| 4160 | int exit_code) |
| 4161 | { |
Pekka Paalanen | f5ef88f | 2014-11-18 15:57:04 +0200 | [diff] [blame] | 4162 | if (compositor->exit_code == EXIT_SUCCESS) |
| 4163 | compositor->exit_code = exit_code; |
| 4164 | |
Frederic Plourde | c336f06 | 2014-10-29 14:44:33 -0400 | [diff] [blame] | 4165 | wl_display_terminate(compositor->wl_display); |
| 4166 | } |
| 4167 | |
| 4168 | WL_EXPORT void |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 4169 | weston_compositor_set_default_pointer_grab(struct weston_compositor *ec, |
| 4170 | const struct weston_pointer_grab_interface *interface) |
| 4171 | { |
| 4172 | struct weston_seat *seat; |
| 4173 | |
| 4174 | ec->default_pointer_grab = interface; |
| 4175 | wl_list_for_each(seat, &ec->seat_list, link) { |
| 4176 | if (seat->pointer) { |
| 4177 | weston_pointer_set_default_grab(seat->pointer, |
| 4178 | interface); |
| 4179 | } |
| 4180 | } |
| 4181 | } |
| 4182 | |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 4183 | WL_EXPORT int |
| 4184 | weston_compositor_set_presentation_clock(struct weston_compositor *compositor, |
| 4185 | clockid_t clk_id) |
| 4186 | { |
| 4187 | struct timespec ts; |
| 4188 | |
| 4189 | if (clock_gettime(clk_id, &ts) < 0) |
| 4190 | return -1; |
| 4191 | |
| 4192 | compositor->presentation_clock = clk_id; |
| 4193 | |
| 4194 | return 0; |
| 4195 | } |
| 4196 | |
| 4197 | /* |
| 4198 | * For choosing the software clock, when the display hardware or API |
| 4199 | * does not expose a compatible presentation timestamp. |
| 4200 | */ |
| 4201 | WL_EXPORT int |
| 4202 | weston_compositor_set_presentation_clock_software( |
| 4203 | struct weston_compositor *compositor) |
| 4204 | { |
| 4205 | /* In order of preference */ |
| 4206 | static const clockid_t clocks[] = { |
| 4207 | CLOCK_MONOTONIC_RAW, /* no jumps, no crawling */ |
| 4208 | CLOCK_MONOTONIC_COARSE, /* no jumps, may crawl, fast & coarse */ |
| 4209 | CLOCK_MONOTONIC, /* no jumps, may crawl */ |
| 4210 | CLOCK_REALTIME_COARSE, /* may jump and crawl, fast & coarse */ |
| 4211 | CLOCK_REALTIME /* may jump and crawl */ |
| 4212 | }; |
| 4213 | unsigned i; |
| 4214 | |
| 4215 | for (i = 0; i < ARRAY_LENGTH(clocks); i++) |
| 4216 | if (weston_compositor_set_presentation_clock(compositor, |
| 4217 | clocks[i]) == 0) |
| 4218 | return 0; |
| 4219 | |
| 4220 | weston_log("Error: no suitable presentation clock available.\n"); |
| 4221 | |
| 4222 | return -1; |
| 4223 | } |
| 4224 | |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 4225 | WL_EXPORT void |
Kristian Høgsberg | af4f2aa | 2013-02-15 20:53:20 -0500 | [diff] [blame] | 4226 | weston_version(int *major, int *minor, int *micro) |
| 4227 | { |
| 4228 | *major = WESTON_VERSION_MAJOR; |
| 4229 | *minor = WESTON_VERSION_MINOR; |
| 4230 | *micro = WESTON_VERSION_MICRO; |
| 4231 | } |
| 4232 | |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 4233 | static const char * |
| 4234 | clock_name(clockid_t clk_id) |
| 4235 | { |
| 4236 | static const char *names[] = { |
| 4237 | [CLOCK_REALTIME] = "CLOCK_REALTIME", |
| 4238 | [CLOCK_MONOTONIC] = "CLOCK_MONOTONIC", |
| 4239 | [CLOCK_MONOTONIC_RAW] = "CLOCK_MONOTONIC_RAW", |
| 4240 | [CLOCK_REALTIME_COARSE] = "CLOCK_REALTIME_COARSE", |
| 4241 | [CLOCK_MONOTONIC_COARSE] = "CLOCK_MONOTONIC_COARSE", |
| 4242 | [CLOCK_BOOTTIME] = "CLOCK_BOOTTIME", |
| 4243 | }; |
| 4244 | |
| 4245 | if (clk_id < 0 || (unsigned)clk_id >= ARRAY_LENGTH(names)) |
| 4246 | return "unknown"; |
| 4247 | |
| 4248 | return names[clk_id]; |
| 4249 | } |
| 4250 | |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 4251 | static const struct { |
Pekka Paalanen | 4fc5dd0 | 2013-05-22 18:03:05 +0300 | [diff] [blame] | 4252 | uint32_t bit; /* enum weston_capability */ |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 4253 | const char *desc; |
| 4254 | } capability_strings[] = { |
| 4255 | { WESTON_CAP_ROTATION_ANY, "arbitrary surface rotation:" }, |
Pekka Paalanen | 4fc5dd0 | 2013-05-22 18:03:05 +0300 | [diff] [blame] | 4256 | { WESTON_CAP_CAPTURE_YFLIP, "screen capture uses y-flip:" }, |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 4257 | }; |
| 4258 | |
| 4259 | static void |
| 4260 | weston_compositor_log_capabilities(struct weston_compositor *compositor) |
| 4261 | { |
| 4262 | unsigned i; |
| 4263 | int yes; |
| 4264 | |
| 4265 | weston_log("Compositor capabilities:\n"); |
| 4266 | for (i = 0; i < ARRAY_LENGTH(capability_strings); i++) { |
| 4267 | yes = compositor->capabilities & capability_strings[i].bit; |
| 4268 | weston_log_continue(STAMP_SPACE "%s %s\n", |
| 4269 | capability_strings[i].desc, |
| 4270 | yes ? "yes" : "no"); |
| 4271 | } |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 4272 | |
| 4273 | weston_log_continue(STAMP_SPACE "presentation clock: %s, id %d\n", |
| 4274 | clock_name(compositor->presentation_clock), |
| 4275 | compositor->presentation_clock); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 4276 | } |
| 4277 | |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 4278 | static int on_term_signal(int signal_number, void *data) |
Kristian Høgsberg | 50dc698 | 2010-12-01 16:43:56 -0500 | [diff] [blame] | 4279 | { |
Kristian Høgsberg | 6bded3f | 2011-08-12 14:55:07 -0400 | [diff] [blame] | 4280 | struct wl_display *display = data; |
Kristian Høgsberg | 50dc698 | 2010-12-01 16:43:56 -0500 | [diff] [blame] | 4281 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 4282 | weston_log("caught signal %d\n", signal_number); |
Kristian Høgsberg | 6bded3f | 2011-08-12 14:55:07 -0400 | [diff] [blame] | 4283 | wl_display_terminate(display); |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 4284 | |
| 4285 | return 1; |
Kristian Høgsberg | 50dc698 | 2010-12-01 16:43:56 -0500 | [diff] [blame] | 4286 | } |
| 4287 | |
Marcin Slusarz | 554a0da | 2013-02-18 13:27:22 -0500 | [diff] [blame] | 4288 | #ifdef HAVE_LIBUNWIND |
| 4289 | |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 4290 | static void |
Marcin Slusarz | 554a0da | 2013-02-18 13:27:22 -0500 | [diff] [blame] | 4291 | print_backtrace(void) |
| 4292 | { |
| 4293 | unw_cursor_t cursor; |
| 4294 | unw_context_t context; |
| 4295 | unw_word_t off; |
| 4296 | unw_proc_info_t pip; |
| 4297 | int ret, i = 0; |
| 4298 | char procname[256]; |
| 4299 | const char *filename; |
| 4300 | Dl_info dlinfo; |
| 4301 | |
| 4302 | pip.unwind_info = NULL; |
| 4303 | ret = unw_getcontext(&context); |
| 4304 | if (ret) { |
| 4305 | weston_log("unw_getcontext: %d\n", ret); |
| 4306 | return; |
| 4307 | } |
| 4308 | |
| 4309 | ret = unw_init_local(&cursor, &context); |
| 4310 | if (ret) { |
| 4311 | weston_log("unw_init_local: %d\n", ret); |
| 4312 | return; |
| 4313 | } |
| 4314 | |
| 4315 | ret = unw_step(&cursor); |
| 4316 | while (ret > 0) { |
| 4317 | ret = unw_get_proc_info(&cursor, &pip); |
| 4318 | if (ret) { |
| 4319 | weston_log("unw_get_proc_info: %d\n", ret); |
| 4320 | break; |
| 4321 | } |
| 4322 | |
| 4323 | ret = unw_get_proc_name(&cursor, procname, 256, &off); |
| 4324 | if (ret && ret != -UNW_ENOMEM) { |
| 4325 | if (ret != -UNW_EUNSPEC) |
| 4326 | weston_log("unw_get_proc_name: %d\n", ret); |
| 4327 | procname[0] = '?'; |
| 4328 | procname[1] = 0; |
| 4329 | } |
| 4330 | |
| 4331 | if (dladdr((void *)(pip.start_ip + off), &dlinfo) && dlinfo.dli_fname && |
| 4332 | *dlinfo.dli_fname) |
| 4333 | filename = dlinfo.dli_fname; |
| 4334 | else |
| 4335 | filename = "?"; |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 4336 | |
Marcin Slusarz | 554a0da | 2013-02-18 13:27:22 -0500 | [diff] [blame] | 4337 | weston_log("%u: %s (%s%s+0x%x) [%p]\n", i++, filename, procname, |
| 4338 | ret == -UNW_ENOMEM ? "..." : "", (int)off, (void *)(pip.start_ip + off)); |
| 4339 | |
| 4340 | ret = unw_step(&cursor); |
| 4341 | if (ret < 0) |
| 4342 | weston_log("unw_step: %d\n", ret); |
| 4343 | } |
| 4344 | } |
| 4345 | |
| 4346 | #else |
| 4347 | |
| 4348 | static void |
| 4349 | print_backtrace(void) |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 4350 | { |
| 4351 | void *buffer[32]; |
| 4352 | int i, count; |
| 4353 | Dl_info info; |
| 4354 | |
Marcin Slusarz | 554a0da | 2013-02-18 13:27:22 -0500 | [diff] [blame] | 4355 | count = backtrace(buffer, ARRAY_LENGTH(buffer)); |
| 4356 | for (i = 0; i < count; i++) { |
| 4357 | dladdr(buffer[i], &info); |
| 4358 | weston_log(" [%016lx] %s (%s)\n", |
| 4359 | (long) buffer[i], |
| 4360 | info.dli_sname ? info.dli_sname : "--", |
| 4361 | info.dli_fname); |
| 4362 | } |
| 4363 | } |
| 4364 | |
| 4365 | #endif |
| 4366 | |
| 4367 | static void |
Peter Maatman | e5b42e4 | 2013-03-27 22:38:53 +0100 | [diff] [blame] | 4368 | on_caught_signal(int s, siginfo_t *siginfo, void *context) |
Marcin Slusarz | 554a0da | 2013-02-18 13:27:22 -0500 | [diff] [blame] | 4369 | { |
Peter Maatman | e5b42e4 | 2013-03-27 22:38:53 +0100 | [diff] [blame] | 4370 | /* This signal handler will do a best-effort backtrace, and |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 4371 | * then call the backend restore function, which will switch |
| 4372 | * back to the vt we launched from or ungrab X etc and then |
| 4373 | * raise SIGTRAP. If we run weston under gdb from X or a |
Peter Maatman | e5b42e4 | 2013-03-27 22:38:53 +0100 | [diff] [blame] | 4374 | * different vt, and tell gdb "handle *s* nostop", this |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 4375 | * will allow weston to switch back to gdb on crash and then |
Peter Maatman | e5b42e4 | 2013-03-27 22:38:53 +0100 | [diff] [blame] | 4376 | * gdb will catch the crash with SIGTRAP.*/ |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 4377 | |
Peter Maatman | e5b42e4 | 2013-03-27 22:38:53 +0100 | [diff] [blame] | 4378 | weston_log("caught signal: %d\n", s); |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 4379 | |
Marcin Slusarz | 554a0da | 2013-02-18 13:27:22 -0500 | [diff] [blame] | 4380 | print_backtrace(); |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 4381 | |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 4382 | segv_compositor->restore(segv_compositor); |
| 4383 | |
| 4384 | raise(SIGTRAP); |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 4385 | } |
| 4386 | |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 4387 | WL_EXPORT void * |
| 4388 | weston_load_module(const char *name, const char *entrypoint) |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 4389 | { |
| 4390 | char path[PATH_MAX]; |
| 4391 | void *module, *init; |
| 4392 | |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 4393 | if (name == NULL) |
| 4394 | return NULL; |
| 4395 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 4396 | if (name[0] != '/') |
Chad Versace | bf38190 | 2012-05-23 23:42:15 -0700 | [diff] [blame] | 4397 | snprintf(path, sizeof path, "%s/%s", MODULEDIR, name); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 4398 | else |
Benjamin Franzke | b7acce6 | 2011-05-06 23:19:22 +0200 | [diff] [blame] | 4399 | snprintf(path, sizeof path, "%s", name); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 4400 | |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 4401 | module = dlopen(path, RTLD_NOW | RTLD_NOLOAD); |
| 4402 | if (module) { |
| 4403 | weston_log("Module '%s' already loaded\n", path); |
| 4404 | dlclose(module); |
| 4405 | return NULL; |
| 4406 | } |
| 4407 | |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 4408 | weston_log("Loading module '%s'\n", path); |
Kristian Høgsberg | 1acd9f8 | 2012-07-26 11:39:26 -0400 | [diff] [blame] | 4409 | module = dlopen(path, RTLD_NOW); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 4410 | if (!module) { |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 4411 | weston_log("Failed to load module: %s\n", dlerror()); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 4412 | return NULL; |
| 4413 | } |
| 4414 | |
| 4415 | init = dlsym(module, entrypoint); |
| 4416 | if (!init) { |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 4417 | weston_log("Failed to lookup init function: %s\n", dlerror()); |
Rob Bradford | c9e64ab | 2012-12-05 18:47:10 +0000 | [diff] [blame] | 4418 | dlclose(module); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 4419 | return NULL; |
| 4420 | } |
| 4421 | |
| 4422 | return init; |
| 4423 | } |
| 4424 | |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 4425 | static int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 4426 | load_modules(struct weston_compositor *ec, const char *modules, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 4427 | int *argc, char *argv[]) |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 4428 | { |
| 4429 | const char *p, *end; |
| 4430 | char buffer[256]; |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 4431 | int (*module_init)(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 4432 | int *argc, char *argv[]); |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 4433 | |
| 4434 | if (modules == NULL) |
| 4435 | return 0; |
| 4436 | |
| 4437 | p = modules; |
| 4438 | while (*p) { |
| 4439 | end = strchrnul(p, ','); |
| 4440 | snprintf(buffer, sizeof buffer, "%.*s", (int) (end - p), p); |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 4441 | module_init = weston_load_module(buffer, "module_init"); |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 4442 | if (module_init) |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 4443 | module_init(ec, argc, argv); |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 4444 | p = end; |
| 4445 | while (*p == ',') |
| 4446 | p++; |
| 4447 | |
| 4448 | } |
| 4449 | |
| 4450 | return 0; |
| 4451 | } |
| 4452 | |
Pekka Paalanen | 78a0b57 | 2012-06-06 16:59:44 +0300 | [diff] [blame] | 4453 | static const char xdg_error_message[] = |
Martin Minarik | 37032f8 | 2012-06-18 20:15:18 +0200 | [diff] [blame] | 4454 | "fatal: environment variable XDG_RUNTIME_DIR is not set.\n"; |
| 4455 | |
| 4456 | static const char xdg_wrong_message[] = |
| 4457 | "fatal: environment variable XDG_RUNTIME_DIR\n" |
| 4458 | "is set to \"%s\", which is not a directory.\n"; |
| 4459 | |
| 4460 | static const char xdg_wrong_mode_message[] = |
| 4461 | "warning: XDG_RUNTIME_DIR \"%s\" is not configured\n" |
Guillem Jover | 32b793c | 2014-01-31 20:41:21 +0100 | [diff] [blame] | 4462 | "correctly. Unix access mode must be 0700 (current mode is %o),\n" |
| 4463 | "and must be owned by the user (current owner is UID %d).\n"; |
Martin Minarik | 37032f8 | 2012-06-18 20:15:18 +0200 | [diff] [blame] | 4464 | |
| 4465 | static const char xdg_detail_message[] = |
Pekka Paalanen | 78a0b57 | 2012-06-06 16:59:44 +0300 | [diff] [blame] | 4466 | "Refer to your distribution on how to get it, or\n" |
| 4467 | "http://www.freedesktop.org/wiki/Specifications/basedir-spec\n" |
| 4468 | "on how to implement it.\n"; |
| 4469 | |
Martin Minarik | 37032f8 | 2012-06-18 20:15:18 +0200 | [diff] [blame] | 4470 | static void |
| 4471 | verify_xdg_runtime_dir(void) |
| 4472 | { |
| 4473 | char *dir = getenv("XDG_RUNTIME_DIR"); |
| 4474 | struct stat s; |
| 4475 | |
| 4476 | if (!dir) { |
| 4477 | weston_log(xdg_error_message); |
| 4478 | weston_log_continue(xdg_detail_message); |
| 4479 | exit(EXIT_FAILURE); |
| 4480 | } |
| 4481 | |
| 4482 | if (stat(dir, &s) || !S_ISDIR(s.st_mode)) { |
| 4483 | weston_log(xdg_wrong_message, dir); |
| 4484 | weston_log_continue(xdg_detail_message); |
| 4485 | exit(EXIT_FAILURE); |
| 4486 | } |
| 4487 | |
| 4488 | if ((s.st_mode & 0777) != 0700 || s.st_uid != getuid()) { |
| 4489 | weston_log(xdg_wrong_mode_message, |
| 4490 | dir, s.st_mode & 0777, s.st_uid); |
| 4491 | weston_log_continue(xdg_detail_message); |
| 4492 | } |
| 4493 | } |
| 4494 | |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 4495 | static int |
| 4496 | usage(int error_code) |
| 4497 | { |
| 4498 | fprintf(stderr, |
| 4499 | "Usage: weston [OPTIONS]\n\n" |
| 4500 | "This is weston version " VERSION ", the Wayland reference compositor.\n" |
| 4501 | "Weston supports multiple backends, and depending on which backend is in use\n" |
| 4502 | "different options will be accepted.\n\n" |
| 4503 | |
| 4504 | |
| 4505 | "Core options:\n\n" |
Scott Moreau | 1224514 | 2012-08-29 15:15:58 -0600 | [diff] [blame] | 4506 | " --version\t\tPrint weston version\n" |
Bryce Harrington | 32297c9 | 2014-10-23 15:25:04 -0700 | [diff] [blame] | 4507 | " -B, --backend=MODULE\tBackend module, one of\n" |
| 4508 | #if defined(BUILD_DRM_COMPOSITOR) |
| 4509 | "\t\t\t\tdrm-backend.so\n" |
| 4510 | #endif |
| 4511 | #if defined(BUILD_FBDEV_COMPOSITOR) |
Pekka Paalanen | 86b70e1 | 2014-11-11 14:10:46 +0200 | [diff] [blame] | 4512 | "\t\t\t\tfbdev-backend.so\n" |
Bryce Harrington | 32297c9 | 2014-10-23 15:25:04 -0700 | [diff] [blame] | 4513 | #endif |
| 4514 | #if defined(BUILD_X11_COMPOSITOR) |
| 4515 | "\t\t\t\tx11-backend.so\n" |
| 4516 | #endif |
| 4517 | #if defined(BUILD_WAYLAND_COMPOSITOR) |
| 4518 | "\t\t\t\twayland-backend.so\n" |
| 4519 | #endif |
| 4520 | #if defined(BUILD_RDP_COMPOSITOR) |
| 4521 | "\t\t\t\trdp-backend.so\n" |
| 4522 | #endif |
| 4523 | #if defined(BUILD_RPI_COMPOSITOR) && defined(HAVE_BCM_HOST) |
| 4524 | "\t\t\t\trpi-backend.so\n" |
| 4525 | #endif |
Jason Ekstrand | a985da4 | 2013-08-22 17:28:03 -0500 | [diff] [blame] | 4526 | " --shell=MODULE\tShell module, defaults to desktop-shell.so\n" |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 4527 | " -S, --socket=NAME\tName of socket to listen on\n" |
| 4528 | " -i, --idle-time=SECS\tIdle time in seconds\n" |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 4529 | " --modules\t\tLoad the comma-separated list of modules\n" |
Bryce Harrington | b8b25bd | 2014-10-23 14:44:36 -0700 | [diff] [blame] | 4530 | " --log=FILE\t\tLog to the given file\n" |
Pekka Paalanen | 588bee1 | 2014-05-07 16:26:25 +0300 | [diff] [blame] | 4531 | " --no-config\t\tDo not read weston.ini\n" |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 4532 | " -h, --help\t\tThis help message\n\n"); |
| 4533 | |
Bryce Harrington | 8eb95c4 | 2014-10-23 15:25:03 -0700 | [diff] [blame] | 4534 | #if defined(BUILD_DRM_COMPOSITOR) |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 4535 | fprintf(stderr, |
| 4536 | "Options for drm-backend.so:\n\n" |
| 4537 | " --connector=ID\tBring up only this connector\n" |
| 4538 | " --seat=SEAT\t\tThe seat that weston should run on\n" |
| 4539 | " --tty=TTY\t\tThe tty to use\n" |
Ander Conselvan de Oliveira | 23e72b8 | 2013-01-25 15:13:06 +0200 | [diff] [blame] | 4540 | " --use-pixman\t\tUse the pixman (CPU) renderer\n" |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 4541 | " --current-mode\tPrefer current KMS mode over EDID preferred mode\n\n"); |
Bryce Harrington | 8eb95c4 | 2014-10-23 15:25:03 -0700 | [diff] [blame] | 4542 | #endif |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 4543 | |
Bryce Harrington | 8eb95c4 | 2014-10-23 15:25:03 -0700 | [diff] [blame] | 4544 | #if defined(BUILD_FBDEV_COMPOSITOR) |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 4545 | fprintf(stderr, |
Philipp Brüschweiler | e14560e | 2013-03-30 15:18:49 +0100 | [diff] [blame] | 4546 | "Options for fbdev-backend.so:\n\n" |
| 4547 | " --tty=TTY\t\tThe tty to use\n" |
| 4548 | " --device=DEVICE\tThe framebuffer device to use\n\n"); |
Bryce Harrington | 8eb95c4 | 2014-10-23 15:25:03 -0700 | [diff] [blame] | 4549 | #endif |
Philipp Brüschweiler | e14560e | 2013-03-30 15:18:49 +0100 | [diff] [blame] | 4550 | |
Bryce Harrington | 8eb95c4 | 2014-10-23 15:25:03 -0700 | [diff] [blame] | 4551 | #if defined(BUILD_X11_COMPOSITOR) |
Philipp Brüschweiler | e14560e | 2013-03-30 15:18:49 +0100 | [diff] [blame] | 4552 | fprintf(stderr, |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 4553 | "Options for x11-backend.so:\n\n" |
| 4554 | " --width=WIDTH\t\tWidth of X window\n" |
| 4555 | " --height=HEIGHT\tHeight of X window\n" |
| 4556 | " --fullscreen\t\tRun in fullscreen mode\n" |
Kristian Høgsberg | efaca34 | 2013-01-07 15:52:44 -0500 | [diff] [blame] | 4557 | " --use-pixman\t\tUse the pixman (CPU) renderer\n" |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 4558 | " --output-count=COUNT\tCreate multiple outputs\n" |
| 4559 | " --no-input\t\tDont create input devices\n\n"); |
Bryce Harrington | 8eb95c4 | 2014-10-23 15:25:03 -0700 | [diff] [blame] | 4560 | #endif |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 4561 | |
Bryce Harrington | 8eb95c4 | 2014-10-23 15:25:03 -0700 | [diff] [blame] | 4562 | #if defined(BUILD_WAYLAND_COMPOSITOR) |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 4563 | fprintf(stderr, |
| 4564 | "Options for wayland-backend.so:\n\n" |
| 4565 | " --width=WIDTH\t\tWidth of Wayland surface\n" |
| 4566 | " --height=HEIGHT\tHeight of Wayland surface\n" |
Bryce Harrington | b8b25bd | 2014-10-23 14:44:36 -0700 | [diff] [blame] | 4567 | " --scale=SCALE\t\tScale factor of output\n" |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 4568 | " --fullscreen\t\tRun in fullscreen mode\n" |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 4569 | " --use-pixman\t\tUse the pixman (CPU) renderer\n" |
Jason Ekstrand | 48ce421 | 2013-10-27 22:25:02 -0500 | [diff] [blame] | 4570 | " --output-count=COUNT\tCreate multiple outputs\n" |
Jason Ekstrand | e4ca8b0 | 2014-04-02 19:53:55 -0500 | [diff] [blame] | 4571 | " --sprawl\t\tCreate one fullscreen output for every parent output\n" |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 4572 | " --display=DISPLAY\tWayland display to connect to\n\n"); |
Bryce Harrington | 8eb95c4 | 2014-10-23 15:25:03 -0700 | [diff] [blame] | 4573 | #endif |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 4574 | |
Pekka Paalanen | e31e053 | 2013-05-22 18:03:07 +0300 | [diff] [blame] | 4575 | #if defined(BUILD_RPI_COMPOSITOR) && defined(HAVE_BCM_HOST) |
| 4576 | fprintf(stderr, |
| 4577 | "Options for rpi-backend.so:\n\n" |
| 4578 | " --tty=TTY\t\tThe tty to use\n" |
| 4579 | " --single-buffer\tUse single-buffered Dispmanx elements.\n" |
| 4580 | " --transform=TR\tThe output transformation, TR is one of:\n" |
| 4581 | "\tnormal 90 180 270 flipped flipped-90 flipped-180 flipped-270\n" |
Tomeu Vizoso | e4f7b92 | 2013-12-02 17:18:58 +0100 | [diff] [blame] | 4582 | " --opaque-regions\tEnable support for opaque regions, can be " |
| 4583 | "very slow without support in the GPU firmware.\n" |
Pekka Paalanen | e31e053 | 2013-05-22 18:03:07 +0300 | [diff] [blame] | 4584 | "\n"); |
| 4585 | #endif |
| 4586 | |
Hardening | c077a84 | 2013-07-08 00:51:35 +0200 | [diff] [blame] | 4587 | #if defined(BUILD_RDP_COMPOSITOR) |
Bryce Harrington | 59fe423 | 2014-10-23 14:44:34 -0700 | [diff] [blame] | 4588 | fprintf(stderr, |
| 4589 | "Options for rdp-backend.so:\n\n" |
| 4590 | " --width=WIDTH\t\tWidth of desktop\n" |
| 4591 | " --height=HEIGHT\tHeight of desktop\n" |
| 4592 | " --env-socket=SOCKET\tUse that socket as peer connection\n" |
| 4593 | " --address=ADDR\tThe address to bind\n" |
Bryce Harrington | f5b34ae | 2014-10-23 14:44:35 -0700 | [diff] [blame] | 4594 | " --port=PORT\t\tThe port to listen on\n" |
Bryce Harrington | 59fe423 | 2014-10-23 14:44:34 -0700 | [diff] [blame] | 4595 | " --no-clients-resize\tThe RDP peers will be forced to the size of the desktop\n" |
| 4596 | " --rdp4-key=FILE\tThe file containing the key for RDP4 encryption\n" |
| 4597 | " --rdp-tls-cert=FILE\tThe file containing the certificate for TLS encryption\n" |
| 4598 | " --rdp-tls-key=FILE\tThe file containing the private key for TLS encryption\n" |
| 4599 | "\n"); |
Hardening | c077a84 | 2013-07-08 00:51:35 +0200 | [diff] [blame] | 4600 | #endif |
| 4601 | |
Bryce Harrington | 3e3b59e | 2014-11-19 15:06:19 -0800 | [diff] [blame] | 4602 | #if defined(BUILD_HEADLESS_COMPOSITOR) |
| 4603 | fprintf(stderr, |
| 4604 | "Options for headless-backend.so:\n\n" |
| 4605 | " --width=WIDTH\t\tWidth of memory surface\n" |
| 4606 | " --height=HEIGHT\tHeight of memory surface\n" |
| 4607 | " --transform=TR\tThe output transformation, TR is one of:\n" |
| 4608 | "\tnormal 90 180 270 flipped flipped-90 flipped-180 flipped-270\n" |
| 4609 | " --use-pixman\t\tUse the pixman (CPU) renderer (default: no rendering)\n\n"); |
| 4610 | #endif |
| 4611 | |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 4612 | exit(error_code); |
| 4613 | } |
| 4614 | |
Peter Maatman | e5b42e4 | 2013-03-27 22:38:53 +0100 | [diff] [blame] | 4615 | static void |
| 4616 | catch_signals(void) |
| 4617 | { |
| 4618 | struct sigaction action; |
| 4619 | |
| 4620 | action.sa_flags = SA_SIGINFO | SA_RESETHAND; |
| 4621 | action.sa_sigaction = on_caught_signal; |
| 4622 | sigemptyset(&action.sa_mask); |
| 4623 | sigaction(SIGSEGV, &action, NULL); |
| 4624 | sigaction(SIGABRT, &action, NULL); |
| 4625 | } |
| 4626 | |
Jason Ekstrand | 923bfe6 | 2014-04-02 19:53:58 -0500 | [diff] [blame] | 4627 | static void |
| 4628 | handle_primary_client_destroyed(struct wl_listener *listener, void *data) |
| 4629 | { |
| 4630 | struct wl_client *client = data; |
| 4631 | |
| 4632 | weston_log("Primary client died. Closing...\n"); |
| 4633 | |
| 4634 | wl_display_terminate(wl_client_get_display(client)); |
| 4635 | } |
| 4636 | |
Ryo Munakata | d8deff6 | 2014-09-06 07:32:05 +0900 | [diff] [blame] | 4637 | static char * |
| 4638 | weston_choose_default_backend(void) |
| 4639 | { |
| 4640 | char *backend = NULL; |
| 4641 | |
| 4642 | if (getenv("WAYLAND_DISPLAY") || getenv("WAYLAND_SOCKET")) |
| 4643 | backend = strdup("wayland-backend.so"); |
| 4644 | else if (getenv("DISPLAY")) |
| 4645 | backend = strdup("x11-backend.so"); |
| 4646 | else |
| 4647 | backend = strdup(WESTON_NATIVE_BACKEND); |
| 4648 | |
| 4649 | return backend; |
| 4650 | } |
| 4651 | |
| 4652 | static int |
| 4653 | weston_create_listening_socket(struct wl_display *display, const char *socket_name) |
| 4654 | { |
| 4655 | if (socket_name) { |
| 4656 | if (wl_display_add_socket(display, socket_name)) { |
| 4657 | weston_log("fatal: failed to add socket: %m\n"); |
| 4658 | return -1; |
| 4659 | } |
| 4660 | } else { |
| 4661 | socket_name = wl_display_add_socket_auto(display); |
| 4662 | if (!socket_name) { |
| 4663 | weston_log("fatal: failed to add socket: %m\n"); |
| 4664 | return -1; |
| 4665 | } |
| 4666 | } |
| 4667 | |
| 4668 | setenv("WAYLAND_DISPLAY", socket_name, 1); |
| 4669 | |
| 4670 | return 0; |
| 4671 | } |
| 4672 | |
Derek Foreman | 64a3df0 | 2014-10-23 12:24:18 -0500 | [diff] [blame] | 4673 | static const struct { const char *name; uint32_t token; } transforms[] = { |
| 4674 | { "normal", WL_OUTPUT_TRANSFORM_NORMAL }, |
| 4675 | { "90", WL_OUTPUT_TRANSFORM_90 }, |
| 4676 | { "180", WL_OUTPUT_TRANSFORM_180 }, |
| 4677 | { "270", WL_OUTPUT_TRANSFORM_270 }, |
| 4678 | { "flipped", WL_OUTPUT_TRANSFORM_FLIPPED }, |
| 4679 | { "flipped-90", WL_OUTPUT_TRANSFORM_FLIPPED_90 }, |
| 4680 | { "flipped-180", WL_OUTPUT_TRANSFORM_FLIPPED_180 }, |
| 4681 | { "flipped-270", WL_OUTPUT_TRANSFORM_FLIPPED_270 }, |
| 4682 | }; |
| 4683 | |
| 4684 | WL_EXPORT int |
| 4685 | weston_parse_transform(const char *transform, uint32_t *out) |
| 4686 | { |
| 4687 | unsigned int i; |
| 4688 | |
| 4689 | for (i = 0; i < ARRAY_LENGTH(transforms); i++) |
| 4690 | if (strcmp(transforms[i].name, transform) == 0) { |
| 4691 | *out = transforms[i].token; |
| 4692 | return 0; |
| 4693 | } |
| 4694 | |
| 4695 | *out = WL_OUTPUT_TRANSFORM_NORMAL; |
| 4696 | return -1; |
| 4697 | } |
| 4698 | |
| 4699 | WL_EXPORT const char * |
| 4700 | weston_transform_to_string(uint32_t output_transform) |
| 4701 | { |
| 4702 | unsigned int i; |
| 4703 | |
| 4704 | for (i = 0; i < ARRAY_LENGTH(transforms); i++) |
| 4705 | if (transforms[i].token == output_transform) |
| 4706 | return transforms[i].name; |
| 4707 | |
| 4708 | return "<illegal value>"; |
| 4709 | } |
| 4710 | |
| 4711 | |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 4712 | int main(int argc, char *argv[]) |
| 4713 | { |
Pekka Paalanen | 3ab7269 | 2012-06-08 17:27:28 +0300 | [diff] [blame] | 4714 | int ret = EXIT_SUCCESS; |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 4715 | struct wl_display *display; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4716 | struct weston_compositor *ec; |
Pekka Paalanen | 51c769f | 2012-01-02 16:03:26 +0200 | [diff] [blame] | 4717 | struct wl_event_source *signals[4]; |
Kristian Høgsberg | 50dc698 | 2010-12-01 16:43:56 -0500 | [diff] [blame] | 4718 | struct wl_event_loop *loop; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4719 | struct weston_compositor |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 4720 | *(*backend_init)(struct wl_display *display, |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 4721 | int *argc, char *argv[], |
| 4722 | struct weston_config *config); |
Jason Ekstrand | 923bfe6 | 2014-04-02 19:53:58 -0500 | [diff] [blame] | 4723 | int i, fd; |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 4724 | char *backend = NULL; |
Jason Ekstrand | a985da4 | 2013-08-22 17:28:03 -0500 | [diff] [blame] | 4725 | char *shell = NULL; |
Ondřej Majerech | 03db71c | 2014-09-11 15:53:15 +0200 | [diff] [blame] | 4726 | char *modules = NULL; |
| 4727 | char *option_modules = NULL; |
Martin Minarik | 19e6f26 | 2012-06-07 13:08:46 +0200 | [diff] [blame] | 4728 | char *log = NULL; |
Jason Ekstrand | 923bfe6 | 2014-04-02 19:53:58 -0500 | [diff] [blame] | 4729 | char *server_socket = NULL, *end; |
Frederic Plourde | 4a84c83 | 2014-10-30 15:06:34 -0400 | [diff] [blame] | 4730 | int32_t idle_time = -1; |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 4731 | int32_t help = 0; |
Ryo Munakata | 03faed2 | 2014-09-06 07:32:51 +0900 | [diff] [blame] | 4732 | char *socket_name = NULL; |
Scott Moreau | 1224514 | 2012-08-29 15:15:58 -0600 | [diff] [blame] | 4733 | int32_t version = 0; |
Pekka Paalanen | 588bee1 | 2014-05-07 16:26:25 +0300 | [diff] [blame] | 4734 | int32_t noconfig = 0; |
Giulio Camuffo | de7e2b3 | 2014-08-28 19:44:10 +0300 | [diff] [blame] | 4735 | int32_t numlock_on; |
Pekka Paalanen | 588bee1 | 2014-05-07 16:26:25 +0300 | [diff] [blame] | 4736 | struct weston_config *config = NULL; |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 4737 | struct weston_config_section *section; |
Jason Ekstrand | 923bfe6 | 2014-04-02 19:53:58 -0500 | [diff] [blame] | 4738 | struct wl_client *primary_client; |
| 4739 | struct wl_listener primary_client_destroyed; |
Giulio Camuffo | de7e2b3 | 2014-08-28 19:44:10 +0300 | [diff] [blame] | 4740 | struct weston_seat *seat; |
Kristian Høgsberg | d34912c | 2011-05-02 10:36:04 -0400 | [diff] [blame] | 4741 | |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 4742 | const struct weston_option core_options[] = { |
Ryo Munakata | 03faed2 | 2014-09-06 07:32:51 +0900 | [diff] [blame] | 4743 | { WESTON_OPTION_STRING, "backend", 'B', &backend }, |
| 4744 | { WESTON_OPTION_STRING, "shell", 0, &shell }, |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 4745 | { WESTON_OPTION_STRING, "socket", 'S', &socket_name }, |
| 4746 | { WESTON_OPTION_INTEGER, "idle-time", 'i', &idle_time }, |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 4747 | { WESTON_OPTION_STRING, "modules", 0, &option_modules }, |
Martin Minarik | 19e6f26 | 2012-06-07 13:08:46 +0200 | [diff] [blame] | 4748 | { WESTON_OPTION_STRING, "log", 0, &log }, |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 4749 | { WESTON_OPTION_BOOLEAN, "help", 'h', &help }, |
Scott Moreau | 1224514 | 2012-08-29 15:15:58 -0600 | [diff] [blame] | 4750 | { WESTON_OPTION_BOOLEAN, "version", 0, &version }, |
Pekka Paalanen | 588bee1 | 2014-05-07 16:26:25 +0300 | [diff] [blame] | 4751 | { WESTON_OPTION_BOOLEAN, "no-config", 0, &noconfig }, |
Kristian Høgsberg | d34912c | 2011-05-02 10:36:04 -0400 | [diff] [blame] | 4752 | }; |
Kristian Høgsberg | d653126 | 2008-12-12 11:06:18 -0500 | [diff] [blame] | 4753 | |
Kristian Høgsberg | 4172f66 | 2013-02-20 15:27:49 -0500 | [diff] [blame] | 4754 | parse_options(core_options, ARRAY_LENGTH(core_options), &argc, argv); |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 4755 | |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 4756 | if (help) |
| 4757 | usage(EXIT_SUCCESS); |
| 4758 | |
Scott Moreau | 1224514 | 2012-08-29 15:15:58 -0600 | [diff] [blame] | 4759 | if (version) { |
| 4760 | printf(PACKAGE_STRING "\n"); |
| 4761 | return EXIT_SUCCESS; |
| 4762 | } |
| 4763 | |
Rafal Mielniczuk | 6e0a7d8 | 2012-06-09 15:10:28 +0200 | [diff] [blame] | 4764 | weston_log_file_open(log); |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 4765 | |
Pekka Paalanen | bce4c2b | 2012-06-11 14:04:21 +0300 | [diff] [blame] | 4766 | weston_log("%s\n" |
| 4767 | STAMP_SPACE "%s\n" |
| 4768 | STAMP_SPACE "Bug reports to: %s\n" |
| 4769 | STAMP_SPACE "Build: %s\n", |
| 4770 | PACKAGE_STRING, PACKAGE_URL, PACKAGE_BUGREPORT, |
Kristian Høgsberg | 23cf9eb | 2012-06-11 12:06:30 -0400 | [diff] [blame] | 4771 | BUILD_ID); |
Pekka Paalanen | 7f4d1a3 | 2012-06-11 14:06:03 +0300 | [diff] [blame] | 4772 | log_uname(); |
Kristian Høgsberg | a411c8b | 2012-06-08 16:16:52 -0400 | [diff] [blame] | 4773 | |
Martin Minarik | 37032f8 | 2012-06-18 20:15:18 +0200 | [diff] [blame] | 4774 | verify_xdg_runtime_dir(); |
| 4775 | |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 4776 | display = wl_display_create(); |
| 4777 | |
Tiago Vignatti | 2116b89 | 2011-08-08 05:52:59 -0700 | [diff] [blame] | 4778 | loop = wl_display_get_event_loop(display); |
Pekka Paalanen | 51c769f | 2012-01-02 16:03:26 +0200 | [diff] [blame] | 4779 | signals[0] = wl_event_loop_add_signal(loop, SIGTERM, on_term_signal, |
| 4780 | display); |
| 4781 | signals[1] = wl_event_loop_add_signal(loop, SIGINT, on_term_signal, |
| 4782 | display); |
| 4783 | signals[2] = wl_event_loop_add_signal(loop, SIGQUIT, on_term_signal, |
| 4784 | display); |
Tiago Vignatti | 2116b89 | 2011-08-08 05:52:59 -0700 | [diff] [blame] | 4785 | |
| 4786 | wl_list_init(&child_process_list); |
Pekka Paalanen | 51c769f | 2012-01-02 16:03:26 +0200 | [diff] [blame] | 4787 | signals[3] = wl_event_loop_add_signal(loop, SIGCHLD, sigchld_handler, |
| 4788 | NULL); |
Kristian Høgsberg | a941022 | 2011-01-14 17:22:35 -0500 | [diff] [blame] | 4789 | |
Srivardhan Hebbar | ba2a36d | 2014-05-27 14:30:59 +0530 | [diff] [blame] | 4790 | if (!signals[0] || !signals[1] || !signals[2] || !signals[3]) { |
| 4791 | ret = EXIT_FAILURE; |
| 4792 | goto out_signals; |
| 4793 | } |
| 4794 | |
Pekka Paalanen | 588bee1 | 2014-05-07 16:26:25 +0300 | [diff] [blame] | 4795 | if (noconfig == 0) |
| 4796 | config = weston_config_parse("weston.ini"); |
Lubomir Rintel | ba44c6b | 2013-11-15 14:18:15 +0100 | [diff] [blame] | 4797 | if (config != NULL) { |
| 4798 | weston_log("Using config file '%s'\n", |
| 4799 | weston_config_get_full_path(config)); |
| 4800 | } else { |
| 4801 | weston_log("Starting with no config file.\n"); |
| 4802 | } |
| 4803 | section = weston_config_get_section(config, "core", NULL, NULL); |
| 4804 | |
Ryo Munakata | 03faed2 | 2014-09-06 07:32:51 +0900 | [diff] [blame] | 4805 | if (!backend) { |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 4806 | weston_config_section_get_string(section, "backend", &backend, |
| 4807 | NULL); |
Ryo Munakata | 03faed2 | 2014-09-06 07:32:51 +0900 | [diff] [blame] | 4808 | if (!backend) |
| 4809 | backend = weston_choose_default_backend(); |
| 4810 | } |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 4811 | |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 4812 | backend_init = weston_load_module(backend, "backend_init"); |
Srivardhan Hebbar | ba2a36d | 2014-05-27 14:30:59 +0530 | [diff] [blame] | 4813 | if (!backend_init) { |
| 4814 | ret = EXIT_FAILURE; |
| 4815 | goto out_signals; |
| 4816 | } |
Kristian Høgsberg | a941022 | 2011-01-14 17:22:35 -0500 | [diff] [blame] | 4817 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 4818 | ec = backend_init(display, &argc, argv, config); |
Kristian Høgsberg | 841883b | 2008-12-05 11:19:56 -0500 | [diff] [blame] | 4819 | if (ec == NULL) { |
Pekka Paalanen | 3361639 | 2012-07-30 16:56:57 +0300 | [diff] [blame] | 4820 | weston_log("fatal: failed to create compositor\n"); |
Srivardhan Hebbar | ba2a36d | 2014-05-27 14:30:59 +0530 | [diff] [blame] | 4821 | ret = EXIT_FAILURE; |
| 4822 | goto out_signals; |
Kristian Høgsberg | 841883b | 2008-12-05 11:19:56 -0500 | [diff] [blame] | 4823 | } |
Kristian Høgsberg | 61a8251 | 2010-10-26 11:26:44 -0400 | [diff] [blame] | 4824 | |
Peter Maatman | e5b42e4 | 2013-03-27 22:38:53 +0100 | [diff] [blame] | 4825 | catch_signals(); |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 4826 | segv_compositor = ec; |
| 4827 | |
Frederic Plourde | 4a84c83 | 2014-10-30 15:06:34 -0400 | [diff] [blame] | 4828 | if (idle_time < 0) |
| 4829 | weston_config_section_get_int(section, "idle-time", &idle_time, -1); |
| 4830 | if (idle_time < 0) |
| 4831 | idle_time = 300; /* default idle timeout, in seconds */ |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 4832 | ec->idle_time = idle_time; |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 4833 | ec->default_pointer_grab = NULL; |
Frederic Plourde | c336f06 | 2014-10-29 14:44:33 -0400 | [diff] [blame] | 4834 | ec->exit_code = EXIT_SUCCESS; |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 4835 | |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 4836 | for (i = 1; i < argc; i++) |
| 4837 | weston_log("fatal: unhandled option: %s\n", argv[i]); |
| 4838 | if (argc > 1) { |
| 4839 | ret = EXIT_FAILURE; |
| 4840 | goto out; |
| 4841 | } |
| 4842 | |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 4843 | weston_compositor_log_capabilities(ec); |
| 4844 | |
Jason Ekstrand | 923bfe6 | 2014-04-02 19:53:58 -0500 | [diff] [blame] | 4845 | server_socket = getenv("WAYLAND_SERVER_SOCKET"); |
| 4846 | if (server_socket) { |
| 4847 | weston_log("Running with single client\n"); |
| 4848 | fd = strtol(server_socket, &end, 0); |
| 4849 | if (*end != '\0') |
| 4850 | fd = -1; |
| 4851 | } else { |
| 4852 | fd = -1; |
| 4853 | } |
| 4854 | |
| 4855 | if (fd != -1) { |
| 4856 | primary_client = wl_client_create(display, fd); |
| 4857 | if (!primary_client) { |
| 4858 | weston_log("fatal: failed to add client: %m\n"); |
| 4859 | ret = EXIT_FAILURE; |
| 4860 | goto out; |
| 4861 | } |
| 4862 | primary_client_destroyed.notify = |
| 4863 | handle_primary_client_destroyed; |
| 4864 | wl_client_add_destroy_listener(primary_client, |
| 4865 | &primary_client_destroyed); |
Ryo Munakata | d8deff6 | 2014-09-06 07:32:05 +0900 | [diff] [blame] | 4866 | } else if (weston_create_listening_socket(display, socket_name)) { |
| 4867 | ret = EXIT_FAILURE; |
| 4868 | goto out; |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 4869 | } |
| 4870 | |
Ryo Munakata | 03faed2 | 2014-09-06 07:32:51 +0900 | [diff] [blame] | 4871 | if (!shell) |
Jasper St. Pierre | e2f0f84 | 2014-07-17 13:55:44 -0400 | [diff] [blame] | 4872 | weston_config_section_get_string(section, "shell", &shell, |
| 4873 | "desktop-shell.so"); |
| 4874 | |
Ryo Munakata | 03faed2 | 2014-09-06 07:32:51 +0900 | [diff] [blame] | 4875 | if (load_modules(ec, shell, &argc, argv) < 0) |
Jasper St. Pierre | e2f0f84 | 2014-07-17 13:55:44 -0400 | [diff] [blame] | 4876 | goto out; |
Jasper St. Pierre | e2f0f84 | 2014-07-17 13:55:44 -0400 | [diff] [blame] | 4877 | |
| 4878 | weston_config_section_get_string(section, "modules", &modules, ""); |
Ryo Munakata | 03faed2 | 2014-09-06 07:32:51 +0900 | [diff] [blame] | 4879 | if (load_modules(ec, modules, &argc, argv) < 0) |
Jasper St. Pierre | e2f0f84 | 2014-07-17 13:55:44 -0400 | [diff] [blame] | 4880 | goto out; |
Jasper St. Pierre | e2f0f84 | 2014-07-17 13:55:44 -0400 | [diff] [blame] | 4881 | |
| 4882 | if (load_modules(ec, option_modules, &argc, argv) < 0) |
| 4883 | goto out; |
| 4884 | |
Giulio Camuffo | de7e2b3 | 2014-08-28 19:44:10 +0300 | [diff] [blame] | 4885 | section = weston_config_get_section(config, "keyboard", NULL, NULL); |
| 4886 | weston_config_section_get_bool(section, "numlock-on", &numlock_on, 0); |
| 4887 | if (numlock_on) { |
| 4888 | wl_list_for_each(seat, &ec->seat_list, link) { |
| 4889 | if (seat->keyboard) |
| 4890 | weston_keyboard_set_locks(seat->keyboard, |
| 4891 | WESTON_NUM_LOCK, |
| 4892 | WESTON_NUM_LOCK); |
| 4893 | } |
| 4894 | } |
| 4895 | |
Pekka Paalanen | c0444e3 | 2012-01-05 16:28:21 +0200 | [diff] [blame] | 4896 | weston_compositor_wake(ec); |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 4897 | |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 4898 | wl_display_run(display); |
| 4899 | |
Frederic Plourde | c336f06 | 2014-10-29 14:44:33 -0400 | [diff] [blame] | 4900 | /* Allow for setting return exit code after |
| 4901 | * wl_display_run returns normally. This is |
| 4902 | * useful for devs/testers and automated tests |
| 4903 | * that want to indicate failure status to |
| 4904 | * testing infrastructure above |
| 4905 | */ |
| 4906 | ret = ec->exit_code; |
| 4907 | |
Ryo Munakata | 03faed2 | 2014-09-06 07:32:51 +0900 | [diff] [blame] | 4908 | out: |
Pekka Paalanen | 0135abe | 2012-01-03 10:01:20 +0200 | [diff] [blame] | 4909 | /* prevent further rendering while shutting down */ |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4910 | ec->state = WESTON_COMPOSITOR_OFFSCREEN; |
Pekka Paalanen | 0135abe | 2012-01-03 10:01:20 +0200 | [diff] [blame] | 4911 | |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 4912 | wl_signal_emit(&ec->destroy_signal, ec); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 4913 | |
Daniel Stone | 855028f | 2012-05-01 20:37:10 +0100 | [diff] [blame] | 4914 | weston_compositor_xkb_destroy(ec); |
| 4915 | |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 4916 | ec->destroy(ec); |
Srivardhan Hebbar | ba2a36d | 2014-05-27 14:30:59 +0530 | [diff] [blame] | 4917 | |
| 4918 | out_signals: |
| 4919 | for (i = ARRAY_LENGTH(signals) - 1; i >= 0; i--) |
| 4920 | if (signals[i]) |
| 4921 | wl_event_source_remove(signals[i]); |
| 4922 | |
Tiago Vignatti | 9e2be08 | 2011-12-19 00:04:46 +0200 | [diff] [blame] | 4923 | wl_display_destroy(display); |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 4924 | |
Martin Minarik | 19e6f26 | 2012-06-07 13:08:46 +0200 | [diff] [blame] | 4925 | weston_log_file_close(); |
| 4926 | |
Ryo Munakata | 03faed2 | 2014-09-06 07:32:51 +0900 | [diff] [blame] | 4927 | free(backend); |
| 4928 | free(shell); |
| 4929 | free(socket_name); |
| 4930 | free(option_modules); |
| 4931 | free(log); |
| 4932 | free(modules); |
| 4933 | |
Pekka Paalanen | 3ab7269 | 2012-06-08 17:27:28 +0300 | [diff] [blame] | 4934 | return ret; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 4935 | } |