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