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