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