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