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