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