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