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