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