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