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