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