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