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