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 | c647ed7 | 2015-02-09 13:16:57 +0200 | [diff] [blame] | 4 | * Copyright © 2012-2015 Collabora, Ltd. |
Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 5 | * |
Kristian Høgsberg | 96aa7da | 2011-09-15 15:43:14 -0400 | [diff] [blame] | 6 | * Permission to use, copy, modify, distribute, and sell this software and |
| 7 | * its documentation for any purpose is hereby granted without fee, provided |
| 8 | * that the above copyright notice appear in all copies and that both that |
| 9 | * copyright notice and this permission notice appear in supporting |
| 10 | * documentation, and that the name of the copyright holders not be used in |
| 11 | * advertising or publicity pertaining to distribution of the software |
| 12 | * without specific, written prior permission. The copyright holders make |
| 13 | * no representations about the suitability of this software for any |
| 14 | * purpose. It is provided "as is" without express or implied warranty. |
Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 15 | * |
Kristian Høgsberg | 96aa7da | 2011-09-15 15:43:14 -0400 | [diff] [blame] | 16 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 17 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 18 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 19 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 20 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 21 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 22 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 23 | */ |
| 24 | |
Kristian Høgsberg | a941022 | 2011-01-14 17:22:35 -0500 | [diff] [blame] | 25 | #include "config.h" |
| 26 | |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 27 | #include <fcntl.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 28 | #include <stdio.h> |
| 29 | #include <string.h> |
| 30 | #include <stdlib.h> |
| 31 | #include <stdint.h> |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 32 | #include <limits.h> |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 33 | #include <stdarg.h> |
Benjamin Franzke | 6f5fc69 | 2011-06-21 19:34:19 +0200 | [diff] [blame] | 34 | #include <assert.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 35 | #include <sys/ioctl.h> |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 36 | #include <sys/mman.h> |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 37 | #include <sys/wait.h> |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 38 | #include <sys/socket.h> |
Martin Minarik | f12c287 | 2012-06-11 00:57:39 +0200 | [diff] [blame] | 39 | #include <sys/utsname.h> |
Martin Minarik | 37032f8 | 2012-06-18 20:15:18 +0200 | [diff] [blame] | 40 | #include <sys/stat.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 41 | #include <unistd.h> |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 42 | #include <math.h> |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 43 | #include <linux/input.h> |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 44 | #include <dlfcn.h> |
Kristian Høgsberg | 8544903 | 2011-05-02 12:11:07 -0400 | [diff] [blame] | 45 | #include <signal.h> |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 46 | #include <setjmp.h> |
Kristian Høgsberg | a411c8b | 2012-06-08 16:16:52 -0400 | [diff] [blame] | 47 | #include <sys/time.h> |
| 48 | #include <time.h> |
Pekka Paalanen | 23ade62 | 2014-08-27 13:31:26 +0300 | [diff] [blame] | 49 | #include <errno.h> |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 50 | |
Marcin Slusarz | 554a0da | 2013-02-18 13:27:22 -0500 | [diff] [blame] | 51 | #ifdef HAVE_LIBUNWIND |
| 52 | #define UNW_LOCAL_ONLY |
| 53 | #include <libunwind.h> |
| 54 | #endif |
| 55 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 56 | #include "timeline.h" |
| 57 | |
Kristian Høgsberg | 8286302 | 2010-06-04 21:52:02 -0400 | [diff] [blame] | 58 | #include "compositor.h" |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 59 | #include "scaler-server-protocol.h" |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 60 | #include "presentation_timing-server-protocol.h" |
Pekka Paalanen | 51aaf64 | 2012-05-30 15:53:41 +0300 | [diff] [blame] | 61 | #include "../shared/os-compatibility.h" |
Kristian Høgsberg | a411c8b | 2012-06-08 16:16:52 -0400 | [diff] [blame] | 62 | #include "git-version.h" |
Kristian Høgsberg | af4f2aa | 2013-02-15 20:53:20 -0500 | [diff] [blame] | 63 | #include "version.h" |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 64 | |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 65 | #define DEFAULT_REPAINT_WINDOW 7 /* milliseconds */ |
| 66 | |
| 67 | #define NSEC_PER_SEC 1000000000 |
| 68 | |
| 69 | static void |
| 70 | timespec_sub(struct timespec *r, |
| 71 | const struct timespec *a, const struct timespec *b) |
| 72 | { |
| 73 | r->tv_sec = a->tv_sec - b->tv_sec; |
| 74 | r->tv_nsec = a->tv_nsec - b->tv_nsec; |
| 75 | if (r->tv_nsec < 0) { |
| 76 | r->tv_sec--; |
| 77 | r->tv_nsec += NSEC_PER_SEC; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | static int64_t |
| 82 | timespec_to_nsec(const struct timespec *a) |
| 83 | { |
| 84 | return (int64_t)a->tv_sec * NSEC_PER_SEC + a->tv_nsec; |
| 85 | } |
| 86 | |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 87 | static struct wl_list child_process_list; |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 88 | static struct weston_compositor *segv_compositor; |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 89 | |
| 90 | static int |
| 91 | sigchld_handler(int signal_number, void *data) |
| 92 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 93 | struct weston_process *p; |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 94 | int status; |
| 95 | pid_t pid; |
| 96 | |
Pekka Paalanen | 23ade62 | 2014-08-27 13:31:26 +0300 | [diff] [blame] | 97 | while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { |
| 98 | wl_list_for_each(p, &child_process_list, link) { |
| 99 | if (p->pid == pid) |
| 100 | break; |
| 101 | } |
Bill Spitzak | 027b962 | 2012-03-17 15:22:03 -0700 | [diff] [blame] | 102 | |
Pekka Paalanen | 23ade62 | 2014-08-27 13:31:26 +0300 | [diff] [blame] | 103 | if (&p->link == &child_process_list) { |
| 104 | weston_log("unknown child process exited\n"); |
| 105 | continue; |
| 106 | } |
| 107 | |
| 108 | wl_list_remove(&p->link); |
| 109 | p->cleanup(p, status); |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 110 | } |
| 111 | |
Pekka Paalanen | 23ade62 | 2014-08-27 13:31:26 +0300 | [diff] [blame] | 112 | if (pid < 0 && errno != ECHILD) |
| 113 | weston_log("waitpid error %m\n"); |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 114 | |
| 115 | return 1; |
| 116 | } |
| 117 | |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 118 | static void |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 119 | weston_output_transform_scale_init(struct weston_output *output, |
| 120 | uint32_t transform, uint32_t scale); |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 121 | |
Rob Bradford | 27b1793 | 2013-06-26 18:08:46 +0100 | [diff] [blame] | 122 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 123 | weston_compositor_build_view_list(struct weston_compositor *compositor); |
Rob Bradford | 27b1793 | 2013-06-26 18:08:46 +0100 | [diff] [blame] | 124 | |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 125 | static void weston_mode_switch_finish(struct weston_output *output, |
| 126 | int mode_changed, |
| 127 | int scale_changed) |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 128 | { |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 129 | struct weston_seat *seat; |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 130 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 131 | pixman_region32_t old_output_region; |
Derek Foreman | 41bdc27 | 2014-11-05 13:26:57 -0600 | [diff] [blame] | 132 | int version; |
Alexander Larsson | 355748e | 2013-05-28 16:23:38 +0200 | [diff] [blame] | 133 | |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 134 | pixman_region32_init(&old_output_region); |
| 135 | pixman_region32_copy(&old_output_region, &output->region); |
| 136 | |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 137 | /* Update output region and transformation matrix */ |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 138 | weston_output_transform_scale_init(output, output->transform, output->current_scale); |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 139 | |
| 140 | pixman_region32_init(&output->previous_damage); |
| 141 | pixman_region32_init_rect(&output->region, output->x, output->y, |
| 142 | output->width, output->height); |
| 143 | |
| 144 | weston_output_update_matrix(output); |
| 145 | |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 146 | /* If a pointer falls outside the outputs new geometry, move it to its |
| 147 | * lower-right corner */ |
| 148 | wl_list_for_each(seat, &output->compositor->seat_list, link) { |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 149 | struct weston_pointer *pointer = seat->pointer; |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 150 | int32_t x, y; |
| 151 | |
| 152 | if (!pointer) |
| 153 | continue; |
| 154 | |
| 155 | x = wl_fixed_to_int(pointer->x); |
| 156 | y = wl_fixed_to_int(pointer->y); |
| 157 | |
| 158 | if (!pixman_region32_contains_point(&old_output_region, |
| 159 | x, y, NULL) || |
| 160 | pixman_region32_contains_point(&output->region, |
| 161 | x, y, NULL)) |
| 162 | continue; |
| 163 | |
| 164 | if (x >= output->x + output->width) |
| 165 | x = output->x + output->width - 1; |
| 166 | if (y >= output->y + output->height) |
| 167 | y = output->y + output->height - 1; |
| 168 | |
| 169 | pointer->x = wl_fixed_from_int(x); |
| 170 | pointer->y = wl_fixed_from_int(y); |
| 171 | } |
| 172 | |
| 173 | pixman_region32_fini(&old_output_region); |
| 174 | |
Derek Foreman | dd4cd33 | 2014-11-10 10:29:59 -0600 | [diff] [blame] | 175 | if (!mode_changed && !scale_changed) |
| 176 | return; |
| 177 | |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 178 | /* notify clients of the changes */ |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 179 | wl_resource_for_each(resource, &output->resource_list) { |
| 180 | if (mode_changed) { |
| 181 | wl_output_send_mode(resource, |
| 182 | output->current_mode->flags, |
| 183 | output->current_mode->width, |
| 184 | output->current_mode->height, |
| 185 | output->current_mode->refresh); |
| 186 | } |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 187 | |
Derek Foreman | 41bdc27 | 2014-11-05 13:26:57 -0600 | [diff] [blame] | 188 | version = wl_resource_get_version(resource); |
| 189 | if (version >= WL_OUTPUT_SCALE_SINCE_VERSION && scale_changed) |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 190 | wl_output_send_scale(resource, output->current_scale); |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 191 | |
Derek Foreman | 41bdc27 | 2014-11-05 13:26:57 -0600 | [diff] [blame] | 192 | if (version >= WL_OUTPUT_DONE_SINCE_VERSION) |
| 193 | wl_output_send_done(resource); |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | |
| 197 | WL_EXPORT int |
| 198 | weston_output_mode_set_native(struct weston_output *output, |
| 199 | struct weston_mode *mode, |
| 200 | int32_t scale) |
| 201 | { |
| 202 | int ret; |
| 203 | int mode_changed = 0, scale_changed = 0; |
| 204 | |
| 205 | if (!output->switch_mode) |
| 206 | return -1; |
| 207 | |
| 208 | if (!output->original_mode) { |
| 209 | mode_changed = 1; |
| 210 | ret = output->switch_mode(output, mode); |
| 211 | if (ret < 0) |
| 212 | return ret; |
| 213 | if (output->current_scale != scale) { |
| 214 | scale_changed = 1; |
| 215 | output->current_scale = scale; |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 219 | output->native_mode = mode; |
| 220 | output->native_scale = scale; |
| 221 | |
| 222 | weston_mode_switch_finish(output, mode_changed, scale_changed); |
| 223 | |
| 224 | return 0; |
| 225 | } |
| 226 | |
| 227 | WL_EXPORT int |
| 228 | weston_output_mode_switch_to_native(struct weston_output *output) |
| 229 | { |
| 230 | int ret; |
| 231 | int mode_changed = 0, scale_changed = 0; |
| 232 | |
| 233 | if (!output->switch_mode) |
| 234 | return -1; |
| 235 | |
| 236 | if (!output->original_mode) { |
| 237 | weston_log("already in the native mode\n"); |
| 238 | return -1; |
| 239 | } |
| 240 | /* the non fullscreen clients haven't seen a mode set since we |
| 241 | * switched into a temporary, so we need to notify them if the |
| 242 | * mode at that time is different from the native mode now. |
| 243 | */ |
| 244 | mode_changed = (output->original_mode != output->native_mode); |
| 245 | scale_changed = (output->original_scale != output->native_scale); |
| 246 | |
| 247 | ret = output->switch_mode(output, output->native_mode); |
| 248 | if (ret < 0) |
| 249 | return ret; |
| 250 | |
| 251 | output->current_scale = output->native_scale; |
| 252 | |
| 253 | output->original_mode = NULL; |
| 254 | output->original_scale = 0; |
| 255 | |
| 256 | weston_mode_switch_finish(output, mode_changed, scale_changed); |
| 257 | |
| 258 | return 0; |
| 259 | } |
| 260 | |
| 261 | WL_EXPORT int |
| 262 | weston_output_mode_switch_to_temporary(struct weston_output *output, |
| 263 | struct weston_mode *mode, |
| 264 | int32_t scale) |
| 265 | { |
| 266 | int ret; |
| 267 | |
| 268 | if (!output->switch_mode) |
| 269 | return -1; |
| 270 | |
| 271 | /* original_mode is the last mode non full screen clients have seen, |
| 272 | * so we shouldn't change it if we already have one set. |
| 273 | */ |
| 274 | if (!output->original_mode) { |
| 275 | output->original_mode = output->native_mode; |
| 276 | output->original_scale = output->native_scale; |
| 277 | } |
| 278 | ret = output->switch_mode(output, mode); |
| 279 | if (ret < 0) |
| 280 | return ret; |
| 281 | |
| 282 | output->current_scale = scale; |
| 283 | |
| 284 | weston_mode_switch_finish(output, 0, 0); |
| 285 | |
| 286 | return 0; |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 287 | } |
| 288 | |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 289 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 290 | weston_watch_process(struct weston_process *process) |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 291 | { |
| 292 | wl_list_insert(&child_process_list, &process->link); |
| 293 | } |
| 294 | |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 295 | static void |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 296 | child_client_exec(int sockfd, const char *path) |
| 297 | { |
Kristian Høgsberg | d42b0c9 | 2011-12-08 10:19:40 -0500 | [diff] [blame] | 298 | int clientfd; |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 299 | char s[32]; |
Pekka Paalanen | c47ddfd | 2011-12-08 10:44:56 +0200 | [diff] [blame] | 300 | sigset_t allsigs; |
| 301 | |
| 302 | /* do not give our signal mask to the new process */ |
| 303 | sigfillset(&allsigs); |
| 304 | sigprocmask(SIG_UNBLOCK, &allsigs, NULL); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 305 | |
Alexandru DAMIAN | 840a421 | 2013-09-25 14:47:47 +0100 | [diff] [blame] | 306 | /* Launch clients as the user. Do not lauch clients with wrong euid.*/ |
| 307 | if (seteuid(getuid()) == -1) { |
| 308 | weston_log("compositor: failed seteuid\n"); |
| 309 | return; |
| 310 | } |
Kristian Høgsberg | eb76484 | 2012-01-31 22:17:25 -0500 | [diff] [blame] | 311 | |
Kristian Høgsberg | d42b0c9 | 2011-12-08 10:19:40 -0500 | [diff] [blame] | 312 | /* SOCK_CLOEXEC closes both ends, so we dup the fd to get a |
| 313 | * non-CLOEXEC fd to pass through exec. */ |
| 314 | clientfd = dup(sockfd); |
| 315 | if (clientfd == -1) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 316 | weston_log("compositor: dup failed: %m\n"); |
Kristian Høgsberg | d42b0c9 | 2011-12-08 10:19:40 -0500 | [diff] [blame] | 317 | return; |
| 318 | } |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 319 | |
Kristian Høgsberg | d42b0c9 | 2011-12-08 10:19:40 -0500 | [diff] [blame] | 320 | snprintf(s, sizeof s, "%d", clientfd); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 321 | setenv("WAYLAND_SOCKET", s, 1); |
| 322 | |
| 323 | if (execl(path, path, NULL) < 0) |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 324 | weston_log("compositor: executing '%s' failed: %m\n", |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 325 | path); |
| 326 | } |
| 327 | |
| 328 | WL_EXPORT struct wl_client * |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 329 | weston_client_launch(struct weston_compositor *compositor, |
| 330 | struct weston_process *proc, |
| 331 | const char *path, |
| 332 | weston_process_cleanup_func_t cleanup) |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 333 | { |
| 334 | int sv[2]; |
| 335 | pid_t pid; |
| 336 | struct wl_client *client; |
| 337 | |
Pekka Paalanen | df1fd36 | 2012-08-06 14:57:03 +0300 | [diff] [blame] | 338 | weston_log("launching '%s'\n", path); |
| 339 | |
Pekka Paalanen | 51aaf64 | 2012-05-30 15:53:41 +0300 | [diff] [blame] | 340 | if (os_socketpair_cloexec(AF_UNIX, SOCK_STREAM, 0, sv) < 0) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 341 | weston_log("weston_client_launch: " |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 342 | "socketpair failed while launching '%s': %m\n", |
| 343 | path); |
| 344 | return NULL; |
| 345 | } |
| 346 | |
| 347 | pid = fork(); |
| 348 | if (pid == -1) { |
| 349 | close(sv[0]); |
| 350 | close(sv[1]); |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 351 | weston_log("weston_client_launch: " |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 352 | "fork failed while launching '%s': %m\n", path); |
| 353 | return NULL; |
| 354 | } |
| 355 | |
| 356 | if (pid == 0) { |
| 357 | child_client_exec(sv[1], path); |
U. Artie Eoff | 3b64d62 | 2013-06-03 16:22:31 -0700 | [diff] [blame] | 358 | _exit(-1); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | close(sv[1]); |
| 362 | |
| 363 | client = wl_client_create(compositor->wl_display, sv[0]); |
| 364 | if (!client) { |
| 365 | close(sv[0]); |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 366 | weston_log("weston_client_launch: " |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 367 | "wl_client_create failed while launching '%s'.\n", |
| 368 | path); |
| 369 | return NULL; |
| 370 | } |
| 371 | |
| 372 | proc->pid = pid; |
| 373 | proc->cleanup = cleanup; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 374 | weston_watch_process(proc); |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 375 | |
| 376 | return client; |
| 377 | } |
| 378 | |
Pekka Paalanen | 9c1ac7b | 2014-08-27 12:03:38 +0300 | [diff] [blame] | 379 | struct process_info { |
| 380 | struct weston_process proc; |
| 381 | char *path; |
| 382 | }; |
| 383 | |
| 384 | static void |
| 385 | process_handle_sigchld(struct weston_process *process, int status) |
| 386 | { |
| 387 | struct process_info *pinfo = |
| 388 | container_of(process, struct process_info, proc); |
| 389 | |
| 390 | /* |
| 391 | * There are no guarantees whether this runs before or after |
| 392 | * the wl_client destructor. |
| 393 | */ |
| 394 | |
| 395 | if (WIFEXITED(status)) { |
| 396 | weston_log("%s exited with status %d\n", pinfo->path, |
| 397 | WEXITSTATUS(status)); |
| 398 | } else if (WIFSIGNALED(status)) { |
| 399 | weston_log("%s died on signal %d\n", pinfo->path, |
| 400 | WTERMSIG(status)); |
| 401 | } else { |
| 402 | weston_log("%s disappeared\n", pinfo->path); |
| 403 | } |
| 404 | |
| 405 | free(pinfo->path); |
| 406 | free(pinfo); |
| 407 | } |
| 408 | |
| 409 | WL_EXPORT struct wl_client * |
| 410 | weston_client_start(struct weston_compositor *compositor, const char *path) |
| 411 | { |
| 412 | struct process_info *pinfo; |
| 413 | struct wl_client *client; |
| 414 | |
| 415 | pinfo = zalloc(sizeof *pinfo); |
| 416 | if (!pinfo) |
| 417 | return NULL; |
| 418 | |
| 419 | pinfo->path = strdup(path); |
| 420 | if (!pinfo->path) |
| 421 | goto out_free; |
| 422 | |
| 423 | client = weston_client_launch(compositor, &pinfo->proc, path, |
| 424 | process_handle_sigchld); |
| 425 | if (!client) |
| 426 | goto out_str; |
| 427 | |
| 428 | return client; |
| 429 | |
| 430 | out_str: |
| 431 | free(pinfo->path); |
| 432 | |
| 433 | out_free: |
| 434 | free(pinfo); |
| 435 | |
| 436 | return NULL; |
| 437 | } |
| 438 | |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 439 | static void |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 440 | region_init_infinite(pixman_region32_t *region) |
| 441 | { |
| 442 | pixman_region32_init_rect(region, INT32_MIN, INT32_MIN, |
| 443 | UINT32_MAX, UINT32_MAX); |
| 444 | } |
| 445 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 446 | static struct weston_subsurface * |
| 447 | weston_surface_to_subsurface(struct weston_surface *surface); |
| 448 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 449 | WL_EXPORT struct weston_view * |
| 450 | weston_view_create(struct weston_surface *surface) |
| 451 | { |
| 452 | struct weston_view *view; |
| 453 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 454 | view = zalloc(sizeof *view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 455 | if (view == NULL) |
| 456 | return NULL; |
| 457 | |
| 458 | view->surface = surface; |
| 459 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 460 | /* Assign to surface */ |
| 461 | wl_list_insert(&surface->views, &view->surface_link); |
| 462 | |
| 463 | wl_signal_init(&view->destroy_signal); |
| 464 | wl_list_init(&view->link); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 465 | wl_list_init(&view->layer_link.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 466 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 467 | pixman_region32_init(&view->clip); |
| 468 | |
| 469 | view->alpha = 1.0; |
| 470 | pixman_region32_init(&view->transform.opaque); |
| 471 | |
| 472 | wl_list_init(&view->geometry.transformation_list); |
| 473 | wl_list_insert(&view->geometry.transformation_list, |
| 474 | &view->transform.position.link); |
| 475 | weston_matrix_init(&view->transform.position.matrix); |
| 476 | wl_list_init(&view->geometry.child_list); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 477 | pixman_region32_init(&view->geometry.scissor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 478 | pixman_region32_init(&view->transform.boundingbox); |
| 479 | view->transform.dirty = 1; |
| 480 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 481 | return view; |
| 482 | } |
| 483 | |
Jason Ekstrand | 108865d | 2014-06-26 10:04:49 -0700 | [diff] [blame] | 484 | struct weston_frame_callback { |
| 485 | struct wl_resource *resource; |
| 486 | struct wl_list link; |
| 487 | }; |
| 488 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 489 | struct weston_presentation_feedback { |
| 490 | struct wl_resource *resource; |
| 491 | |
| 492 | /* XXX: could use just wl_resource_get_link() instead */ |
| 493 | struct wl_list link; |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 494 | |
| 495 | /* The per-surface feedback flags */ |
| 496 | uint32_t psf_flags; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 497 | }; |
| 498 | |
| 499 | static void |
| 500 | weston_presentation_feedback_discard( |
| 501 | struct weston_presentation_feedback *feedback) |
| 502 | { |
| 503 | presentation_feedback_send_discarded(feedback->resource); |
| 504 | wl_resource_destroy(feedback->resource); |
| 505 | } |
| 506 | |
| 507 | static void |
| 508 | weston_presentation_feedback_discard_list(struct wl_list *list) |
| 509 | { |
| 510 | struct weston_presentation_feedback *feedback, *tmp; |
| 511 | |
| 512 | wl_list_for_each_safe(feedback, tmp, list, link) |
| 513 | weston_presentation_feedback_discard(feedback); |
| 514 | } |
| 515 | |
| 516 | static void |
| 517 | weston_presentation_feedback_present( |
| 518 | struct weston_presentation_feedback *feedback, |
| 519 | struct weston_output *output, |
| 520 | uint32_t refresh_nsec, |
| 521 | const struct timespec *ts, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 522 | uint64_t seq, |
| 523 | uint32_t flags) |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 524 | { |
| 525 | struct wl_client *client = wl_resource_get_client(feedback->resource); |
| 526 | struct wl_resource *o; |
| 527 | uint64_t secs; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 528 | |
| 529 | wl_resource_for_each(o, &output->resource_list) { |
| 530 | if (wl_resource_get_client(o) != client) |
| 531 | continue; |
| 532 | |
| 533 | presentation_feedback_send_sync_output(feedback->resource, o); |
| 534 | } |
| 535 | |
| 536 | secs = ts->tv_sec; |
| 537 | presentation_feedback_send_presented(feedback->resource, |
| 538 | secs >> 32, secs & 0xffffffff, |
| 539 | ts->tv_nsec, |
| 540 | refresh_nsec, |
| 541 | seq >> 32, seq & 0xffffffff, |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 542 | flags | feedback->psf_flags); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 543 | wl_resource_destroy(feedback->resource); |
| 544 | } |
| 545 | |
| 546 | static void |
| 547 | weston_presentation_feedback_present_list(struct wl_list *list, |
| 548 | struct weston_output *output, |
| 549 | uint32_t refresh_nsec, |
| 550 | const struct timespec *ts, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 551 | uint64_t seq, |
| 552 | uint32_t flags) |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 553 | { |
| 554 | struct weston_presentation_feedback *feedback, *tmp; |
| 555 | |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 556 | assert(!(flags & PRESENTATION_FEEDBACK_INVALID) || |
| 557 | wl_list_empty(list)); |
| 558 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 559 | wl_list_for_each_safe(feedback, tmp, list, link) |
| 560 | weston_presentation_feedback_present(feedback, output, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 561 | refresh_nsec, ts, seq, |
| 562 | flags); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 563 | } |
| 564 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 565 | static void |
| 566 | surface_state_handle_buffer_destroy(struct wl_listener *listener, void *data) |
| 567 | { |
| 568 | struct weston_surface_state *state = |
| 569 | container_of(listener, struct weston_surface_state, |
| 570 | buffer_destroy_listener); |
| 571 | |
| 572 | state->buffer = NULL; |
| 573 | } |
| 574 | |
| 575 | static void |
| 576 | weston_surface_state_init(struct weston_surface_state *state) |
| 577 | { |
| 578 | state->newly_attached = 0; |
| 579 | state->buffer = NULL; |
| 580 | state->buffer_destroy_listener.notify = |
| 581 | surface_state_handle_buffer_destroy; |
| 582 | state->sx = 0; |
| 583 | state->sy = 0; |
| 584 | |
| 585 | pixman_region32_init(&state->damage); |
| 586 | pixman_region32_init(&state->opaque); |
| 587 | region_init_infinite(&state->input); |
| 588 | |
| 589 | wl_list_init(&state->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 590 | wl_list_init(&state->feedback_list); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 591 | |
| 592 | state->buffer_viewport.buffer.transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 593 | state->buffer_viewport.buffer.scale = 1; |
| 594 | state->buffer_viewport.buffer.src_width = wl_fixed_from_int(-1); |
| 595 | state->buffer_viewport.surface.width = -1; |
| 596 | state->buffer_viewport.changed = 0; |
| 597 | } |
| 598 | |
| 599 | static void |
| 600 | weston_surface_state_fini(struct weston_surface_state *state) |
| 601 | { |
| 602 | struct weston_frame_callback *cb, *next; |
| 603 | |
| 604 | wl_list_for_each_safe(cb, next, |
| 605 | &state->frame_callback_list, link) |
| 606 | wl_resource_destroy(cb->resource); |
| 607 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 608 | weston_presentation_feedback_discard_list(&state->feedback_list); |
| 609 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 610 | pixman_region32_fini(&state->input); |
| 611 | pixman_region32_fini(&state->opaque); |
| 612 | pixman_region32_fini(&state->damage); |
| 613 | |
| 614 | if (state->buffer) |
| 615 | wl_list_remove(&state->buffer_destroy_listener.link); |
| 616 | state->buffer = NULL; |
| 617 | } |
| 618 | |
| 619 | static void |
| 620 | weston_surface_state_set_buffer(struct weston_surface_state *state, |
| 621 | struct weston_buffer *buffer) |
| 622 | { |
| 623 | if (state->buffer == buffer) |
| 624 | return; |
| 625 | |
| 626 | if (state->buffer) |
| 627 | wl_list_remove(&state->buffer_destroy_listener.link); |
| 628 | state->buffer = buffer; |
| 629 | if (state->buffer) |
| 630 | wl_signal_add(&state->buffer->destroy_signal, |
| 631 | &state->buffer_destroy_listener); |
| 632 | } |
| 633 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 634 | WL_EXPORT struct weston_surface * |
Kristian Høgsberg | 18c9300 | 2012-01-27 11:58:31 -0500 | [diff] [blame] | 635 | weston_surface_create(struct weston_compositor *compositor) |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 636 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 637 | struct weston_surface *surface; |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 638 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 639 | surface = zalloc(sizeof *surface); |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 640 | if (surface == NULL) |
| 641 | return NULL; |
| 642 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 643 | wl_signal_init(&surface->destroy_signal); |
| 644 | |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 645 | surface->compositor = compositor; |
Giulio Camuffo | 13b85bd | 2013-08-13 23:10:14 +0200 | [diff] [blame] | 646 | surface->ref_count = 1; |
Kristian Høgsberg | 27803c6 | 2010-06-06 22:23:21 -0400 | [diff] [blame] | 647 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 648 | surface->buffer_viewport.buffer.transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 649 | surface->buffer_viewport.buffer.scale = 1; |
Pekka Paalanen | f0cad48 | 2014-03-14 14:38:16 +0200 | [diff] [blame] | 650 | surface->buffer_viewport.buffer.src_width = wl_fixed_from_int(-1); |
| 651 | surface->buffer_viewport.surface.width = -1; |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 652 | |
| 653 | weston_surface_state_init(&surface->pending); |
| 654 | |
Kristian Høgsberg | 20300ba | 2011-06-23 20:29:12 -0400 | [diff] [blame] | 655 | pixman_region32_init(&surface->damage); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 656 | pixman_region32_init(&surface->opaque); |
Pekka Paalanen | 8ec4ab6 | 2012-10-10 12:49:32 +0300 | [diff] [blame] | 657 | region_init_infinite(&surface->input); |
Kristian Høgsberg | 20300ba | 2011-06-23 20:29:12 -0400 | [diff] [blame] | 658 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 659 | wl_list_init(&surface->views); |
| 660 | |
| 661 | wl_list_init(&surface->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 662 | wl_list_init(&surface->feedback_list); |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 663 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 664 | wl_list_init(&surface->subsurface_list); |
| 665 | wl_list_init(&surface->subsurface_list_pending); |
| 666 | |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 667 | weston_matrix_init(&surface->buffer_to_surface_matrix); |
| 668 | weston_matrix_init(&surface->surface_to_buffer_matrix); |
| 669 | |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 670 | return surface; |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 671 | } |
| 672 | |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 673 | WL_EXPORT void |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 674 | weston_surface_set_color(struct weston_surface *surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 675 | float red, float green, float blue, float alpha) |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 676 | { |
John Kåre Alsaker | 878f449 | 2012-11-13 19:10:23 +0100 | [diff] [blame] | 677 | surface->compositor->renderer->surface_set_color(surface, red, green, blue, alpha); |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 678 | } |
| 679 | |
Kristian Høgsberg | e4c1a5f | 2012-06-18 13:17:32 -0400 | [diff] [blame] | 680 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 681 | weston_view_to_global_float(struct weston_view *view, |
| 682 | float sx, float sy, float *x, float *y) |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 683 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 684 | if (view->transform.enabled) { |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 685 | struct weston_vector v = { { sx, sy, 0.0f, 1.0f } }; |
| 686 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 687 | weston_matrix_transform(&view->transform.matrix, &v); |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 688 | |
| 689 | if (fabsf(v.f[3]) < 1e-6) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 690 | weston_log("warning: numerical instability in " |
Scott Moreau | 088c62e | 2013-02-11 04:45:38 -0700 | [diff] [blame] | 691 | "%s(), divisor = %g\n", __func__, |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 692 | v.f[3]); |
| 693 | *x = 0; |
| 694 | *y = 0; |
| 695 | return; |
| 696 | } |
| 697 | |
| 698 | *x = v.f[0] / v.f[3]; |
| 699 | *y = v.f[1] / v.f[3]; |
| 700 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 701 | *x = sx + view->geometry.x; |
| 702 | *y = sy + view->geometry.y; |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 703 | } |
| 704 | } |
| 705 | |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 706 | WL_EXPORT void |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 707 | weston_transformed_coord(int width, int height, |
| 708 | enum wl_output_transform transform, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 709 | int32_t scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 710 | float sx, float sy, float *bx, float *by) |
| 711 | { |
| 712 | switch (transform) { |
| 713 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 714 | default: |
| 715 | *bx = sx; |
| 716 | *by = sy; |
| 717 | break; |
| 718 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 719 | *bx = width - sx; |
| 720 | *by = sy; |
| 721 | break; |
| 722 | case WL_OUTPUT_TRANSFORM_90: |
| 723 | *bx = height - sy; |
| 724 | *by = sx; |
| 725 | break; |
| 726 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 727 | *bx = height - sy; |
| 728 | *by = width - sx; |
| 729 | break; |
| 730 | case WL_OUTPUT_TRANSFORM_180: |
| 731 | *bx = width - sx; |
| 732 | *by = height - sy; |
| 733 | break; |
| 734 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 735 | *bx = sx; |
| 736 | *by = height - sy; |
| 737 | break; |
| 738 | case WL_OUTPUT_TRANSFORM_270: |
| 739 | *bx = sy; |
| 740 | *by = width - sx; |
| 741 | break; |
| 742 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 743 | *bx = sy; |
| 744 | *by = sx; |
| 745 | break; |
| 746 | } |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 747 | |
| 748 | *bx *= scale; |
| 749 | *by *= scale; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | WL_EXPORT pixman_box32_t |
| 753 | weston_transformed_rect(int width, int height, |
| 754 | enum wl_output_transform transform, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 755 | int32_t scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 756 | pixman_box32_t rect) |
| 757 | { |
| 758 | float x1, x2, y1, y2; |
| 759 | |
| 760 | pixman_box32_t ret; |
| 761 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 762 | weston_transformed_coord(width, height, transform, scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 763 | rect.x1, rect.y1, &x1, &y1); |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 764 | weston_transformed_coord(width, height, transform, scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 765 | rect.x2, rect.y2, &x2, &y2); |
| 766 | |
| 767 | if (x1 <= x2) { |
| 768 | ret.x1 = x1; |
| 769 | ret.x2 = x2; |
| 770 | } else { |
| 771 | ret.x1 = x2; |
| 772 | ret.x2 = x1; |
| 773 | } |
| 774 | |
| 775 | if (y1 <= y2) { |
| 776 | ret.y1 = y1; |
| 777 | ret.y2 = y2; |
| 778 | } else { |
| 779 | ret.y1 = y2; |
| 780 | ret.y2 = y1; |
| 781 | } |
| 782 | |
| 783 | return ret; |
| 784 | } |
| 785 | |
| 786 | WL_EXPORT void |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 787 | weston_transformed_region(int width, int height, |
| 788 | enum wl_output_transform transform, |
| 789 | int32_t scale, |
| 790 | pixman_region32_t *src, pixman_region32_t *dest) |
| 791 | { |
| 792 | pixman_box32_t *src_rects, *dest_rects; |
| 793 | int nrects, i; |
| 794 | |
| 795 | if (transform == WL_OUTPUT_TRANSFORM_NORMAL && scale == 1) { |
| 796 | if (src != dest) |
| 797 | pixman_region32_copy(dest, src); |
| 798 | return; |
| 799 | } |
| 800 | |
| 801 | src_rects = pixman_region32_rectangles(src, &nrects); |
| 802 | dest_rects = malloc(nrects * sizeof(*dest_rects)); |
| 803 | if (!dest_rects) |
| 804 | return; |
| 805 | |
| 806 | if (transform == WL_OUTPUT_TRANSFORM_NORMAL) { |
| 807 | memcpy(dest_rects, src_rects, nrects * sizeof(*dest_rects)); |
| 808 | } else { |
| 809 | for (i = 0; i < nrects; i++) { |
| 810 | switch (transform) { |
| 811 | default: |
| 812 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 813 | dest_rects[i].x1 = src_rects[i].x1; |
| 814 | dest_rects[i].y1 = src_rects[i].y1; |
| 815 | dest_rects[i].x2 = src_rects[i].x2; |
| 816 | dest_rects[i].y2 = src_rects[i].y2; |
| 817 | break; |
| 818 | case WL_OUTPUT_TRANSFORM_90: |
| 819 | dest_rects[i].x1 = height - src_rects[i].y2; |
| 820 | dest_rects[i].y1 = src_rects[i].x1; |
| 821 | dest_rects[i].x2 = height - src_rects[i].y1; |
| 822 | dest_rects[i].y2 = src_rects[i].x2; |
| 823 | break; |
| 824 | case WL_OUTPUT_TRANSFORM_180: |
| 825 | dest_rects[i].x1 = width - src_rects[i].x2; |
| 826 | dest_rects[i].y1 = height - src_rects[i].y2; |
| 827 | dest_rects[i].x2 = width - src_rects[i].x1; |
| 828 | dest_rects[i].y2 = height - src_rects[i].y1; |
| 829 | break; |
| 830 | case WL_OUTPUT_TRANSFORM_270: |
| 831 | dest_rects[i].x1 = src_rects[i].y1; |
| 832 | dest_rects[i].y1 = width - src_rects[i].x2; |
| 833 | dest_rects[i].x2 = src_rects[i].y2; |
| 834 | dest_rects[i].y2 = width - src_rects[i].x1; |
| 835 | break; |
| 836 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 837 | dest_rects[i].x1 = width - src_rects[i].x2; |
| 838 | dest_rects[i].y1 = src_rects[i].y1; |
| 839 | dest_rects[i].x2 = width - src_rects[i].x1; |
| 840 | dest_rects[i].y2 = src_rects[i].y2; |
| 841 | break; |
| 842 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 843 | dest_rects[i].x1 = height - src_rects[i].y2; |
| 844 | dest_rects[i].y1 = width - src_rects[i].x2; |
| 845 | dest_rects[i].x2 = height - src_rects[i].y1; |
| 846 | dest_rects[i].y2 = width - src_rects[i].x1; |
| 847 | break; |
| 848 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 849 | dest_rects[i].x1 = src_rects[i].x1; |
| 850 | dest_rects[i].y1 = height - src_rects[i].y2; |
| 851 | dest_rects[i].x2 = src_rects[i].x2; |
| 852 | dest_rects[i].y2 = height - src_rects[i].y1; |
| 853 | break; |
| 854 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 855 | dest_rects[i].x1 = src_rects[i].y1; |
| 856 | dest_rects[i].y1 = src_rects[i].x1; |
| 857 | dest_rects[i].x2 = src_rects[i].y2; |
| 858 | dest_rects[i].y2 = src_rects[i].x2; |
| 859 | break; |
| 860 | } |
| 861 | } |
| 862 | } |
| 863 | |
| 864 | if (scale != 1) { |
| 865 | for (i = 0; i < nrects; i++) { |
| 866 | dest_rects[i].x1 *= scale; |
| 867 | dest_rects[i].x2 *= scale; |
| 868 | dest_rects[i].y1 *= scale; |
| 869 | dest_rects[i].y2 *= scale; |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | pixman_region32_clear(dest); |
| 874 | pixman_region32_init_rects(dest, dest_rects, nrects); |
| 875 | free(dest_rects); |
| 876 | } |
| 877 | |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 878 | static void |
| 879 | scaler_surface_to_buffer(struct weston_surface *surface, |
| 880 | float sx, float sy, float *bx, float *by) |
| 881 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 882 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 883 | double src_width, src_height; |
| 884 | double src_x, src_y; |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 885 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 886 | if (vp->buffer.src_width == wl_fixed_from_int(-1)) { |
| 887 | if (vp->surface.width == -1) { |
| 888 | *bx = sx; |
| 889 | *by = sy; |
| 890 | return; |
| 891 | } |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 892 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 893 | src_x = 0.0; |
| 894 | src_y = 0.0; |
| 895 | src_width = surface->width_from_buffer; |
| 896 | src_height = surface->height_from_buffer; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 897 | } else { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 898 | src_x = wl_fixed_to_double(vp->buffer.src_x); |
| 899 | src_y = wl_fixed_to_double(vp->buffer.src_y); |
| 900 | src_width = wl_fixed_to_double(vp->buffer.src_width); |
| 901 | src_height = wl_fixed_to_double(vp->buffer.src_height); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 902 | } |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 903 | |
| 904 | *bx = sx * src_width / surface->width + src_x; |
| 905 | *by = sy * src_height / surface->height + src_y; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 906 | } |
| 907 | |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 908 | WL_EXPORT void |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 909 | weston_surface_to_buffer_float(struct weston_surface *surface, |
| 910 | float sx, float sy, float *bx, float *by) |
| 911 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 912 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
| 913 | |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 914 | /* first transform coordinates if the scaler is set */ |
| 915 | scaler_surface_to_buffer(surface, sx, sy, bx, by); |
| 916 | |
Jason Ekstrand | d0cebc3 | 2014-04-21 20:56:46 -0500 | [diff] [blame] | 917 | weston_transformed_coord(surface->width_from_buffer, |
| 918 | surface->height_from_buffer, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 919 | vp->buffer.transform, vp->buffer.scale, |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 920 | *bx, *by, bx, by); |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 921 | } |
| 922 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 923 | WL_EXPORT void |
| 924 | weston_surface_to_buffer(struct weston_surface *surface, |
| 925 | int sx, int sy, int *bx, int *by) |
| 926 | { |
| 927 | float bxf, byf; |
| 928 | |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 929 | weston_surface_to_buffer_float(surface, |
| 930 | sx, sy, &bxf, &byf); |
| 931 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 932 | *bx = floorf(bxf); |
| 933 | *by = floorf(byf); |
| 934 | } |
| 935 | |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 936 | WL_EXPORT pixman_box32_t |
| 937 | weston_surface_to_buffer_rect(struct weston_surface *surface, |
| 938 | pixman_box32_t rect) |
| 939 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 940 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 941 | float xf, yf; |
| 942 | |
| 943 | /* first transform box coordinates if the scaler is set */ |
| 944 | scaler_surface_to_buffer(surface, rect.x1, rect.y1, &xf, &yf); |
| 945 | rect.x1 = floorf(xf); |
| 946 | rect.y1 = floorf(yf); |
| 947 | |
| 948 | scaler_surface_to_buffer(surface, rect.x2, rect.y2, &xf, &yf); |
| 949 | rect.x2 = floorf(xf); |
| 950 | rect.y2 = floorf(yf); |
| 951 | |
Jason Ekstrand | d0cebc3 | 2014-04-21 20:56:46 -0500 | [diff] [blame] | 952 | return weston_transformed_rect(surface->width_from_buffer, |
| 953 | surface->height_from_buffer, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 954 | vp->buffer.transform, vp->buffer.scale, |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 955 | rect); |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 956 | } |
| 957 | |
Pekka Paalanen | e54e31c | 2015-03-04 14:23:28 +0200 | [diff] [blame] | 958 | /** Transform a region from surface coordinates to buffer coordinates |
| 959 | * |
| 960 | * \param surface The surface to fetch wl_viewport and buffer transformation |
| 961 | * from. |
| 962 | * \param surface_region[in] The region in surface coordinates. |
| 963 | * \param buffer_region[out] The region converted to buffer coordinates. |
| 964 | * |
| 965 | * Buffer_region must be init'd, but will be completely overwritten. |
| 966 | * |
| 967 | * Viewport and buffer transformations can only do translation, scaling, |
| 968 | * and rotations in 90-degree steps. Therefore the only loss in the |
| 969 | * conversion is coordinate flooring (rounding). |
| 970 | */ |
| 971 | WL_EXPORT void |
| 972 | weston_surface_to_buffer_region(struct weston_surface *surface, |
| 973 | pixman_region32_t *surface_region, |
| 974 | pixman_region32_t *buffer_region) |
| 975 | { |
| 976 | pixman_box32_t *src_rects, *dest_rects; |
| 977 | int nrects, i; |
| 978 | |
| 979 | src_rects = pixman_region32_rectangles(surface_region, &nrects); |
| 980 | dest_rects = malloc(nrects * sizeof(*dest_rects)); |
| 981 | if (!dest_rects) |
| 982 | return; |
| 983 | |
| 984 | for (i = 0; i < nrects; i++) { |
| 985 | dest_rects[i] = weston_surface_to_buffer_rect(surface, |
| 986 | src_rects[i]); |
| 987 | } |
| 988 | |
| 989 | pixman_region32_fini(buffer_region); |
| 990 | pixman_region32_init_rects(buffer_region, dest_rects, nrects); |
| 991 | free(dest_rects); |
| 992 | } |
| 993 | |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 994 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 995 | weston_view_move_to_plane(struct weston_view *view, |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 996 | struct weston_plane *plane) |
| 997 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 998 | if (view->plane == plane) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 999 | return; |
| 1000 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1001 | weston_view_damage_below(view); |
| 1002 | view->plane = plane; |
| 1003 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1004 | } |
| 1005 | |
Pekka Paalanen | 51723d5 | 2015-02-17 13:10:01 +0200 | [diff] [blame] | 1006 | /** Inflict damage on the plane where the view is visible. |
| 1007 | * |
| 1008 | * \param view The view that causes the damage. |
| 1009 | * |
| 1010 | * If the view is currently on a plane (including the primary plane), |
| 1011 | * take the view's boundingbox, subtract all the opaque views that cover it, |
| 1012 | * and add the remaining region as damage to the plane. This corresponds |
| 1013 | * to the damage inflicted to the plane if this view disappeared. |
| 1014 | * |
| 1015 | * A repaint is scheduled for this view. |
| 1016 | * |
| 1017 | * The region of all opaque views covering this view is stored in |
| 1018 | * weston_view::clip and updated by view_accumulate_damage() during |
| 1019 | * weston_output_repaint(). Specifically, that region matches the |
| 1020 | * scenegraph as it was last painted. |
| 1021 | */ |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1022 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1023 | weston_view_damage_below(struct weston_view *view) |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 1024 | { |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 1025 | pixman_region32_t damage; |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 1026 | |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 1027 | pixman_region32_init(&damage); |
Pekka Paalanen | 25c0ca5 | 2015-02-19 11:15:33 +0200 | [diff] [blame] | 1028 | pixman_region32_subtract(&damage, &view->transform.boundingbox, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1029 | &view->clip); |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 1030 | if (view->plane) |
| 1031 | pixman_region32_union(&view->plane->damage, |
| 1032 | &view->plane->damage, &damage); |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 1033 | pixman_region32_fini(&damage); |
Kristian Høgsberg | a3a784a | 2013-11-13 21:33:43 -0800 | [diff] [blame] | 1034 | weston_view_schedule_repaint(view); |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 1035 | } |
| 1036 | |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1037 | static void |
| 1038 | weston_surface_update_output_mask(struct weston_surface *es, uint32_t mask) |
| 1039 | { |
| 1040 | uint32_t different = es->output_mask ^ mask; |
| 1041 | uint32_t entered = mask & different; |
| 1042 | uint32_t left = es->output_mask & different; |
| 1043 | struct weston_output *output; |
| 1044 | struct wl_resource *resource = NULL; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1045 | struct wl_client *client; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1046 | |
| 1047 | es->output_mask = mask; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1048 | if (es->resource == NULL) |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1049 | return; |
| 1050 | if (different == 0) |
| 1051 | return; |
| 1052 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1053 | client = wl_resource_get_client(es->resource); |
| 1054 | |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1055 | wl_list_for_each(output, &es->compositor->output_list, link) { |
| 1056 | if (1 << output->id & different) |
| 1057 | resource = |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 1058 | wl_resource_find_for_client(&output->resource_list, |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1059 | client); |
| 1060 | if (resource == NULL) |
| 1061 | continue; |
| 1062 | if (1 << output->id & entered) |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1063 | wl_surface_send_enter(es->resource, resource); |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1064 | if (1 << output->id & left) |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1065 | wl_surface_send_leave(es->resource, resource); |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1066 | } |
| 1067 | } |
| 1068 | |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 1069 | |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1070 | static void |
| 1071 | weston_surface_assign_output(struct weston_surface *es) |
| 1072 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1073 | struct weston_output *new_output; |
| 1074 | struct weston_view *view; |
| 1075 | pixman_region32_t region; |
| 1076 | uint32_t max, area, mask; |
| 1077 | pixman_box32_t *e; |
| 1078 | |
| 1079 | new_output = NULL; |
| 1080 | max = 0; |
| 1081 | mask = 0; |
| 1082 | pixman_region32_init(®ion); |
| 1083 | wl_list_for_each(view, &es->views, surface_link) { |
| 1084 | if (!view->output) |
| 1085 | continue; |
| 1086 | |
| 1087 | pixman_region32_intersect(®ion, &view->transform.boundingbox, |
| 1088 | &view->output->region); |
| 1089 | |
| 1090 | e = pixman_region32_extents(®ion); |
| 1091 | area = (e->x2 - e->x1) * (e->y2 - e->y1); |
| 1092 | |
| 1093 | mask |= view->output_mask; |
| 1094 | |
| 1095 | if (area >= max) { |
| 1096 | new_output = view->output; |
| 1097 | max = area; |
| 1098 | } |
| 1099 | } |
| 1100 | pixman_region32_fini(®ion); |
| 1101 | |
| 1102 | es->output = new_output; |
| 1103 | weston_surface_update_output_mask(es, mask); |
| 1104 | } |
| 1105 | |
| 1106 | static void |
| 1107 | weston_view_assign_output(struct weston_view *ev) |
| 1108 | { |
| 1109 | struct weston_compositor *ec = ev->surface->compositor; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1110 | struct weston_output *output, *new_output; |
| 1111 | pixman_region32_t region; |
| 1112 | uint32_t max, area, mask; |
| 1113 | pixman_box32_t *e; |
| 1114 | |
| 1115 | new_output = NULL; |
| 1116 | max = 0; |
| 1117 | mask = 0; |
| 1118 | pixman_region32_init(®ion); |
| 1119 | wl_list_for_each(output, &ec->output_list, link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1120 | pixman_region32_intersect(®ion, &ev->transform.boundingbox, |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1121 | &output->region); |
| 1122 | |
| 1123 | e = pixman_region32_extents(®ion); |
| 1124 | area = (e->x2 - e->x1) * (e->y2 - e->y1); |
| 1125 | |
| 1126 | if (area > 0) |
| 1127 | mask |= 1 << output->id; |
| 1128 | |
| 1129 | if (area >= max) { |
| 1130 | new_output = output; |
| 1131 | max = area; |
| 1132 | } |
| 1133 | } |
| 1134 | pixman_region32_fini(®ion); |
| 1135 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1136 | ev->output = new_output; |
| 1137 | ev->output_mask = mask; |
| 1138 | |
| 1139 | weston_surface_assign_output(ev->surface); |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1140 | } |
| 1141 | |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 1142 | static void |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1143 | weston_view_to_view_map(struct weston_view *from, struct weston_view *to, |
| 1144 | int from_x, int from_y, int *to_x, int *to_y) |
| 1145 | { |
| 1146 | float x, y; |
| 1147 | |
| 1148 | weston_view_to_global_float(from, from_x, from_y, &x, &y); |
| 1149 | weston_view_from_global_float(to, x, y, &x, &y); |
| 1150 | |
| 1151 | *to_x = round(x); |
| 1152 | *to_y = round(y); |
| 1153 | } |
| 1154 | |
| 1155 | static void |
| 1156 | weston_view_transfer_scissor(struct weston_view *from, struct weston_view *to) |
| 1157 | { |
| 1158 | pixman_box32_t *a; |
| 1159 | pixman_box32_t b; |
| 1160 | |
| 1161 | a = pixman_region32_extents(&from->geometry.scissor); |
| 1162 | |
| 1163 | weston_view_to_view_map(from, to, a->x1, a->y1, &b.x1, &b.y1); |
| 1164 | weston_view_to_view_map(from, to, a->x2, a->y2, &b.x2, &b.y2); |
| 1165 | |
| 1166 | pixman_region32_fini(&to->geometry.scissor); |
| 1167 | pixman_region32_init_with_extents(&to->geometry.scissor, &b); |
| 1168 | } |
| 1169 | |
| 1170 | static void |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 1171 | view_compute_bbox(struct weston_view *view, const pixman_box32_t *inbox, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1172 | pixman_region32_t *bbox) |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1173 | { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1174 | float min_x = HUGE_VALF, min_y = HUGE_VALF; |
| 1175 | float max_x = -HUGE_VALF, max_y = -HUGE_VALF; |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1176 | int32_t s[4][2] = { |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 1177 | { inbox->x1, inbox->y1 }, |
| 1178 | { inbox->x1, inbox->y2 }, |
| 1179 | { inbox->x2, inbox->y1 }, |
| 1180 | { inbox->x2, inbox->y2 }, |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1181 | }; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1182 | float int_x, int_y; |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1183 | int i; |
| 1184 | |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 1185 | if (inbox->x1 == inbox->x2 || inbox->y1 == inbox->y2) { |
Pekka Paalanen | 7c7d464 | 2012-09-04 13:55:44 +0300 | [diff] [blame] | 1186 | /* avoid rounding empty bbox to 1x1 */ |
| 1187 | pixman_region32_init(bbox); |
| 1188 | return; |
| 1189 | } |
| 1190 | |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1191 | for (i = 0; i < 4; ++i) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1192 | float x, y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1193 | weston_view_to_global_float(view, s[i][0], s[i][1], &x, &y); |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1194 | if (x < min_x) |
| 1195 | min_x = x; |
| 1196 | if (x > max_x) |
| 1197 | max_x = x; |
| 1198 | if (y < min_y) |
| 1199 | min_y = y; |
| 1200 | if (y > max_y) |
| 1201 | max_y = y; |
| 1202 | } |
| 1203 | |
Pekka Paalanen | 219b982 | 2012-02-08 15:38:37 +0200 | [diff] [blame] | 1204 | int_x = floorf(min_x); |
| 1205 | int_y = floorf(min_y); |
| 1206 | pixman_region32_init_rect(bbox, int_x, int_y, |
| 1207 | ceilf(max_x) - int_x, ceilf(max_y) - int_y); |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1208 | } |
| 1209 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1210 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1211 | weston_view_update_transform_disable(struct weston_view *view) |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1212 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1213 | view->transform.enabled = 0; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1214 | |
Pekka Paalanen | cc2f868 | 2012-02-13 10:34:04 +0200 | [diff] [blame] | 1215 | /* round off fractions when not transformed */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1216 | view->geometry.x = roundf(view->geometry.x); |
| 1217 | view->geometry.y = roundf(view->geometry.y); |
Pekka Paalanen | cc2f868 | 2012-02-13 10:34:04 +0200 | [diff] [blame] | 1218 | |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1219 | /* Otherwise identity matrix, but with x and y translation. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1220 | view->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE; |
| 1221 | view->transform.position.matrix.d[12] = view->geometry.x; |
| 1222 | view->transform.position.matrix.d[13] = view->geometry.y; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1223 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1224 | view->transform.matrix = view->transform.position.matrix; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1225 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1226 | view->transform.inverse = view->transform.position.matrix; |
| 1227 | view->transform.inverse.d[12] = -view->geometry.x; |
| 1228 | view->transform.inverse.d[13] = -view->geometry.y; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1229 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1230 | pixman_region32_init_rect(&view->transform.boundingbox, |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1231 | 0, 0, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1232 | view->surface->width, |
| 1233 | view->surface->height); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1234 | if (view->geometry.scissor_enabled) |
| 1235 | pixman_region32_intersect(&view->transform.boundingbox, |
| 1236 | &view->transform.boundingbox, |
| 1237 | &view->geometry.scissor); |
| 1238 | |
| 1239 | pixman_region32_translate(&view->transform.boundingbox, |
| 1240 | view->geometry.x, view->geometry.y); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1241 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1242 | if (view->alpha == 1.0) { |
| 1243 | pixman_region32_copy(&view->transform.opaque, |
| 1244 | &view->surface->opaque); |
| 1245 | pixman_region32_translate(&view->transform.opaque, |
| 1246 | view->geometry.x, |
| 1247 | view->geometry.y); |
Kristian Høgsberg | 3b4af20 | 2012-02-28 09:19:39 -0500 | [diff] [blame] | 1248 | } |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1249 | } |
| 1250 | |
| 1251 | static int |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1252 | weston_view_update_transform_enable(struct weston_view *view) |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1253 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1254 | struct weston_view *parent = view->geometry.parent; |
| 1255 | struct weston_matrix *matrix = &view->transform.matrix; |
| 1256 | struct weston_matrix *inverse = &view->transform.inverse; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1257 | struct weston_transform *tform; |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1258 | pixman_region32_t surfregion; |
| 1259 | const pixman_box32_t *surfbox; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1260 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1261 | view->transform.enabled = 1; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1262 | |
| 1263 | /* Otherwise identity matrix, but with x and y translation. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1264 | view->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE; |
| 1265 | view->transform.position.matrix.d[12] = view->geometry.x; |
| 1266 | view->transform.position.matrix.d[13] = view->geometry.y; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1267 | |
| 1268 | weston_matrix_init(matrix); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1269 | wl_list_for_each(tform, &view->geometry.transformation_list, link) |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1270 | weston_matrix_multiply(matrix, &tform->matrix); |
| 1271 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1272 | if (parent) |
| 1273 | weston_matrix_multiply(matrix, &parent->transform.matrix); |
| 1274 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1275 | if (weston_matrix_invert(inverse, matrix) < 0) { |
| 1276 | /* Oops, bad total transformation, not invertible */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1277 | weston_log("error: weston_view %p" |
| 1278 | " transformation not invertible.\n", view); |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1279 | return -1; |
| 1280 | } |
| 1281 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1282 | pixman_region32_init_rect(&surfregion, 0, 0, |
| 1283 | view->surface->width, view->surface->height); |
| 1284 | if (view->geometry.scissor_enabled) |
| 1285 | pixman_region32_intersect(&surfregion, &surfregion, |
| 1286 | &view->geometry.scissor); |
| 1287 | surfbox = pixman_region32_extents(&surfregion); |
| 1288 | |
| 1289 | view_compute_bbox(view, surfbox, &view->transform.boundingbox); |
| 1290 | pixman_region32_fini(&surfregion); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1291 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1292 | return 0; |
| 1293 | } |
| 1294 | |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1295 | static struct weston_layer * |
| 1296 | get_view_layer(struct weston_view *view) |
| 1297 | { |
| 1298 | if (view->parent_view) |
| 1299 | return get_view_layer(view->parent_view); |
| 1300 | return view->layer_link.layer; |
| 1301 | } |
| 1302 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1303 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1304 | weston_view_update_transform(struct weston_view *view) |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1305 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1306 | struct weston_view *parent = view->geometry.parent; |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1307 | struct weston_layer *layer; |
| 1308 | pixman_region32_t mask; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1309 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1310 | if (!view->transform.dirty) |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1311 | return; |
| 1312 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1313 | if (parent) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1314 | weston_view_update_transform(parent); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1315 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1316 | view->transform.dirty = 0; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1317 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1318 | weston_view_damage_below(view); |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 1319 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1320 | pixman_region32_fini(&view->transform.boundingbox); |
| 1321 | pixman_region32_fini(&view->transform.opaque); |
| 1322 | pixman_region32_init(&view->transform.opaque); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1323 | |
Pekka Paalanen | cd40362 | 2012-01-25 13:37:39 +0200 | [diff] [blame] | 1324 | /* transform.position is always in transformation_list */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1325 | if (view->geometry.transformation_list.next == |
| 1326 | &view->transform.position.link && |
| 1327 | view->geometry.transformation_list.prev == |
| 1328 | &view->transform.position.link && |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1329 | !parent) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1330 | weston_view_update_transform_disable(view); |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1331 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1332 | if (weston_view_update_transform_enable(view) < 0) |
| 1333 | weston_view_update_transform_disable(view); |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1334 | } |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 1335 | |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1336 | layer = get_view_layer(view); |
| 1337 | if (layer) { |
| 1338 | pixman_region32_init_with_extents(&mask, &layer->mask); |
Pekka Paalanen | 25c0ca5 | 2015-02-19 11:15:33 +0200 | [diff] [blame] | 1339 | pixman_region32_intersect(&view->transform.boundingbox, |
| 1340 | &view->transform.boundingbox, &mask); |
Pekka Paalanen | 8844bf2 | 2015-02-18 16:30:47 +0200 | [diff] [blame] | 1341 | pixman_region32_intersect(&view->transform.opaque, |
| 1342 | &view->transform.opaque, &mask); |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1343 | pixman_region32_fini(&mask); |
| 1344 | } |
| 1345 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1346 | if (parent) { |
| 1347 | if (parent->geometry.scissor_enabled) { |
| 1348 | view->geometry.scissor_enabled = true; |
| 1349 | weston_view_transfer_scissor(parent, view); |
| 1350 | } else { |
| 1351 | view->geometry.scissor_enabled = false; |
| 1352 | } |
| 1353 | } |
| 1354 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1355 | weston_view_damage_below(view); |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 1356 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1357 | weston_view_assign_output(view); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 1358 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1359 | wl_signal_emit(&view->surface->compositor->transform_signal, |
| 1360 | view->surface); |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1361 | } |
| 1362 | |
Pekka Paalanen | ddae03c | 2012-02-06 14:54:20 +0200 | [diff] [blame] | 1363 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1364 | weston_view_geometry_dirty(struct weston_view *view) |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 1365 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1366 | struct weston_view *child; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1367 | |
| 1368 | /* |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1369 | * The invariant: if view->geometry.dirty, then all views |
| 1370 | * in view->geometry.child_list have geometry.dirty too. |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1371 | * Corollary: if not parent->geometry.dirty, then all ancestors |
| 1372 | * are not dirty. |
| 1373 | */ |
| 1374 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1375 | if (view->transform.dirty) |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1376 | return; |
| 1377 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1378 | view->transform.dirty = 1; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1379 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1380 | wl_list_for_each(child, &view->geometry.child_list, |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1381 | geometry.parent_link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1382 | weston_view_geometry_dirty(child); |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1386 | weston_view_to_global_fixed(struct weston_view *view, |
| 1387 | wl_fixed_t vx, wl_fixed_t vy, |
| 1388 | wl_fixed_t *x, wl_fixed_t *y) |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1389 | { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1390 | float xf, yf; |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1391 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1392 | weston_view_to_global_float(view, |
| 1393 | wl_fixed_to_double(vx), |
| 1394 | wl_fixed_to_double(vy), |
| 1395 | &xf, &yf); |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1396 | *x = wl_fixed_from_double(xf); |
| 1397 | *y = wl_fixed_from_double(yf); |
| 1398 | } |
| 1399 | |
Kristian Høgsberg | ecf6ede | 2012-09-05 21:59:35 -0400 | [diff] [blame] | 1400 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1401 | weston_view_from_global_float(struct weston_view *view, |
| 1402 | float x, float y, float *vx, float *vy) |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1403 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1404 | if (view->transform.enabled) { |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1405 | struct weston_vector v = { { x, y, 0.0f, 1.0f } }; |
| 1406 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1407 | weston_matrix_transform(&view->transform.inverse, &v); |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1408 | |
| 1409 | if (fabsf(v.f[3]) < 1e-6) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1410 | weston_log("warning: numerical instability in " |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1411 | "weston_view_from_global(), divisor = %g\n", |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1412 | v.f[3]); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1413 | *vx = 0; |
| 1414 | *vy = 0; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1415 | return; |
| 1416 | } |
| 1417 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1418 | *vx = v.f[0] / v.f[3]; |
| 1419 | *vy = v.f[1] / v.f[3]; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1420 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1421 | *vx = x - view->geometry.x; |
| 1422 | *vy = y - view->geometry.y; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1423 | } |
| 1424 | } |
| 1425 | |
| 1426 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1427 | weston_view_from_global_fixed(struct weston_view *view, |
| 1428 | wl_fixed_t x, wl_fixed_t y, |
| 1429 | wl_fixed_t *vx, wl_fixed_t *vy) |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1430 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1431 | float vxf, vyf; |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1432 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1433 | weston_view_from_global_float(view, |
| 1434 | wl_fixed_to_double(x), |
| 1435 | wl_fixed_to_double(y), |
| 1436 | &vxf, &vyf); |
| 1437 | *vx = wl_fixed_from_double(vxf); |
| 1438 | *vy = wl_fixed_from_double(vyf); |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1442 | weston_view_from_global(struct weston_view *view, |
| 1443 | int32_t x, int32_t y, int32_t *vx, int32_t *vy) |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1444 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1445 | float vxf, vyf; |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1446 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1447 | weston_view_from_global_float(view, x, y, &vxf, &vyf); |
| 1448 | *vx = floorf(vxf); |
| 1449 | *vy = floorf(vyf); |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1450 | } |
| 1451 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1452 | WL_EXPORT void |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1453 | weston_surface_schedule_repaint(struct weston_surface *surface) |
| 1454 | { |
| 1455 | struct weston_output *output; |
| 1456 | |
| 1457 | wl_list_for_each(output, &surface->compositor->output_list, link) |
| 1458 | if (surface->output_mask & (1 << output->id)) |
| 1459 | weston_output_schedule_repaint(output); |
| 1460 | } |
| 1461 | |
| 1462 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1463 | weston_view_schedule_repaint(struct weston_view *view) |
| 1464 | { |
| 1465 | struct weston_output *output; |
| 1466 | |
| 1467 | wl_list_for_each(output, &view->surface->compositor->output_list, link) |
| 1468 | if (view->output_mask & (1 << output->id)) |
| 1469 | weston_output_schedule_repaint(output); |
| 1470 | } |
| 1471 | |
Pekka Paalanen | e508ce6 | 2015-02-19 13:59:55 +0200 | [diff] [blame] | 1472 | /** |
| 1473 | * XXX: This function does it the wrong way. |
| 1474 | * surface->damage is the damage from the client, and causes |
| 1475 | * surface_flush_damage() to copy pixels. No window management action can |
| 1476 | * cause damage to the client-provided content, warranting re-upload! |
| 1477 | * |
| 1478 | * Instead of surface->damage, this function should record the damage |
| 1479 | * with all the views for this surface to avoid extraneous texture |
| 1480 | * uploads. |
| 1481 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1482 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1483 | weston_surface_damage(struct weston_surface *surface) |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 1484 | { |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1485 | pixman_region32_union_rect(&surface->damage, &surface->damage, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1486 | 0, 0, surface->width, |
| 1487 | surface->height); |
Pekka Paalanen | 2267d45 | 2012-01-26 13:12:45 +0200 | [diff] [blame] | 1488 | |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1489 | weston_surface_schedule_repaint(surface); |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 1490 | } |
| 1491 | |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 1492 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1493 | weston_view_set_position(struct weston_view *view, float x, float y) |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1494 | { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1495 | if (view->geometry.x == x && view->geometry.y == y) |
| 1496 | return; |
| 1497 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1498 | view->geometry.x = x; |
| 1499 | view->geometry.y = y; |
| 1500 | weston_view_geometry_dirty(view); |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1501 | } |
| 1502 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1503 | static void |
| 1504 | transform_parent_handle_parent_destroy(struct wl_listener *listener, |
| 1505 | void *data) |
| 1506 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1507 | struct weston_view *view = |
| 1508 | container_of(listener, struct weston_view, |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1509 | geometry.parent_destroy_listener); |
| 1510 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1511 | weston_view_set_transform_parent(view, NULL); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1515 | weston_view_set_transform_parent(struct weston_view *view, |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1516 | struct weston_view *parent) |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1517 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1518 | if (view->geometry.parent) { |
| 1519 | wl_list_remove(&view->geometry.parent_destroy_listener.link); |
| 1520 | wl_list_remove(&view->geometry.parent_link); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1521 | |
| 1522 | if (!parent) |
| 1523 | view->geometry.scissor_enabled = false; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1524 | } |
| 1525 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1526 | view->geometry.parent = parent; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1527 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1528 | view->geometry.parent_destroy_listener.notify = |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1529 | transform_parent_handle_parent_destroy; |
| 1530 | if (parent) { |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1531 | wl_signal_add(&parent->destroy_signal, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1532 | &view->geometry.parent_destroy_listener); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1533 | wl_list_insert(&parent->geometry.child_list, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1534 | &view->geometry.parent_link); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1535 | } |
| 1536 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1537 | weston_view_geometry_dirty(view); |
| 1538 | } |
| 1539 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1540 | /** Set a clip mask rectangle on a view |
| 1541 | * |
| 1542 | * \param view The view to set the clip mask on. |
| 1543 | * \param x Top-left corner X coordinate of the clip rectangle. |
| 1544 | * \param y Top-left corner Y coordinate of the clip rectangle. |
| 1545 | * \param width Width of the clip rectangle, non-negative. |
| 1546 | * \param height Height of the clip rectangle, non-negative. |
| 1547 | * |
| 1548 | * A shell may set a clip mask rectangle on a view. Everything outside |
| 1549 | * the rectangle is cut away for input and output purposes: it is |
| 1550 | * not drawn and cannot be hit by hit-test based input like pointer |
| 1551 | * motion or touch-downs. Everything inside the rectangle will behave |
| 1552 | * normally. Clients are unaware of clipping. |
| 1553 | * |
| 1554 | * The rectangle is set in the surface local coordinates. Setting a clip |
| 1555 | * mask rectangle does not affect the view position, the view is positioned |
| 1556 | * as it would be without a clip. The clip also does not change |
| 1557 | * weston_surface::width,height. |
| 1558 | * |
| 1559 | * The clip mask rectangle is part of transformation inheritance |
| 1560 | * (weston_view_set_transform_parent()). A clip set in the root of the |
| 1561 | * transformation inheritance tree will affect all views in the tree. |
| 1562 | * A clip can be set only on the root view. Attempting to set a clip |
| 1563 | * on view that has a transformation parent will fail. Assigning a parent |
| 1564 | * to a view that has a clip set will cause the clip to be forgotten. |
| 1565 | * |
| 1566 | * Because the clip mask is an axis-aligned rectangle, it poses restrictions |
| 1567 | * on the additional transformations in the child views. These transformations |
| 1568 | * may not rotate the coordinate axes, i.e., only translation and scaling |
| 1569 | * are allowed. Violating this restriction causes the clipping to malfunction. |
| 1570 | * Furthermore, using scaling may cause rounding errors in child clipping. |
| 1571 | * |
| 1572 | * The clip mask rectangle is not automatically adjusted based on |
| 1573 | * wl_surface.attach dx and dy arguments. |
| 1574 | * |
| 1575 | * A clip mask rectangle can be set only if the compositor capability |
| 1576 | * WESTON_CAP_VIEW_CLIP_MASK is present. |
| 1577 | * |
| 1578 | * This function sets the clip mask rectangle and schedules a repaint for |
| 1579 | * the view. |
| 1580 | */ |
| 1581 | WL_EXPORT void |
| 1582 | weston_view_set_mask(struct weston_view *view, |
| 1583 | int x, int y, int width, int height) |
| 1584 | { |
| 1585 | struct weston_compositor *compositor = view->surface->compositor; |
| 1586 | |
| 1587 | if (!(compositor->capabilities & WESTON_CAP_VIEW_CLIP_MASK)) { |
| 1588 | weston_log("%s not allowed without capability!\n", __func__); |
| 1589 | return; |
| 1590 | } |
| 1591 | |
| 1592 | if (view->geometry.parent) { |
| 1593 | weston_log("view %p has a parent, clip forbidden!\n", view); |
| 1594 | return; |
| 1595 | } |
| 1596 | |
| 1597 | if (width < 0 || height < 0) { |
| 1598 | weston_log("%s: illegal args %d, %d, %d, %d\n", __func__, |
| 1599 | x, y, width, height); |
| 1600 | return; |
| 1601 | } |
| 1602 | |
| 1603 | pixman_region32_fini(&view->geometry.scissor); |
| 1604 | pixman_region32_init_rect(&view->geometry.scissor, x, y, width, height); |
| 1605 | view->geometry.scissor_enabled = true; |
| 1606 | weston_view_geometry_dirty(view); |
| 1607 | weston_view_schedule_repaint(view); |
| 1608 | } |
| 1609 | |
| 1610 | /** Remove the clip mask from a view |
| 1611 | * |
| 1612 | * \param view The view to remove the clip mask from. |
| 1613 | * |
| 1614 | * Removed the clip mask rectangle and schedules a repaint. |
| 1615 | * |
| 1616 | * \sa weston_view_set_mask |
| 1617 | */ |
| 1618 | WL_EXPORT void |
| 1619 | weston_view_set_mask_infinite(struct weston_view *view) |
| 1620 | { |
| 1621 | view->geometry.scissor_enabled = false; |
| 1622 | weston_view_geometry_dirty(view); |
| 1623 | weston_view_schedule_repaint(view); |
| 1624 | } |
| 1625 | |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 1626 | WL_EXPORT bool |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1627 | weston_view_is_mapped(struct weston_view *view) |
| 1628 | { |
| 1629 | if (view->output) |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 1630 | return true; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1631 | else |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 1632 | return false; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1633 | } |
| 1634 | |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 1635 | WL_EXPORT bool |
Ander Conselvan de Oliveira | b8ab14f | 2012-03-27 17:36:36 +0300 | [diff] [blame] | 1636 | weston_surface_is_mapped(struct weston_surface *surface) |
| 1637 | { |
| 1638 | if (surface->output) |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 1639 | return true; |
Ander Conselvan de Oliveira | b8ab14f | 2012-03-27 17:36:36 +0300 | [diff] [blame] | 1640 | else |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 1641 | return false; |
Ander Conselvan de Oliveira | b8ab14f | 2012-03-27 17:36:36 +0300 | [diff] [blame] | 1642 | } |
| 1643 | |
Pekka Paalanen | da75ee1 | 2013-11-26 18:19:43 +0100 | [diff] [blame] | 1644 | static void |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 1645 | surface_set_size(struct weston_surface *surface, int32_t width, int32_t height) |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1646 | { |
| 1647 | struct weston_view *view; |
| 1648 | |
| 1649 | if (surface->width == width && surface->height == height) |
| 1650 | return; |
| 1651 | |
| 1652 | surface->width = width; |
| 1653 | surface->height = height; |
| 1654 | |
| 1655 | wl_list_for_each(view, &surface->views, surface_link) |
| 1656 | weston_view_geometry_dirty(view); |
| 1657 | } |
| 1658 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 1659 | WL_EXPORT void |
| 1660 | weston_surface_set_size(struct weston_surface *surface, |
| 1661 | int32_t width, int32_t height) |
| 1662 | { |
| 1663 | assert(!surface->resource); |
| 1664 | surface_set_size(surface, width, height); |
| 1665 | } |
| 1666 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1667 | static int |
| 1668 | fixed_round_up_to_int(wl_fixed_t f) |
| 1669 | { |
| 1670 | return wl_fixed_to_int(wl_fixed_from_int(1) - 1 + f); |
| 1671 | } |
| 1672 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1673 | static void |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1674 | weston_surface_calculate_size_from_buffer(struct weston_surface *surface) |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1675 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 1676 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Pekka Paalanen | da75ee1 | 2013-11-26 18:19:43 +0100 | [diff] [blame] | 1677 | int32_t width, height; |
| 1678 | |
| 1679 | if (!surface->buffer_ref.buffer) { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1680 | surface->width_from_buffer = 0; |
| 1681 | surface->height_from_buffer = 0; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 1682 | return; |
| 1683 | } |
| 1684 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 1685 | switch (vp->buffer.transform) { |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1686 | case WL_OUTPUT_TRANSFORM_90: |
| 1687 | case WL_OUTPUT_TRANSFORM_270: |
| 1688 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 1689 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1690 | width = surface->buffer_ref.buffer->height / vp->buffer.scale; |
| 1691 | height = surface->buffer_ref.buffer->width / vp->buffer.scale; |
Pekka Paalanen | da75ee1 | 2013-11-26 18:19:43 +0100 | [diff] [blame] | 1692 | break; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1693 | default: |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1694 | width = surface->buffer_ref.buffer->width / vp->buffer.scale; |
| 1695 | height = surface->buffer_ref.buffer->height / vp->buffer.scale; |
Pekka Paalanen | da75ee1 | 2013-11-26 18:19:43 +0100 | [diff] [blame] | 1696 | break; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1697 | } |
Pekka Paalanen | da75ee1 | 2013-11-26 18:19:43 +0100 | [diff] [blame] | 1698 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1699 | surface->width_from_buffer = width; |
| 1700 | surface->height_from_buffer = height; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1701 | } |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1702 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1703 | static void |
| 1704 | weston_surface_update_size(struct weston_surface *surface) |
| 1705 | { |
| 1706 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
| 1707 | int32_t width, height; |
| 1708 | |
| 1709 | width = surface->width_from_buffer; |
| 1710 | height = surface->height_from_buffer; |
| 1711 | |
| 1712 | if (width != 0 && vp->surface.width != -1) { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1713 | surface_set_size(surface, |
| 1714 | vp->surface.width, vp->surface.height); |
| 1715 | return; |
| 1716 | } |
| 1717 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1718 | if (width != 0 && vp->buffer.src_width != wl_fixed_from_int(-1)) { |
Pekka Paalanen | e931721 | 2014-04-04 14:22:13 +0300 | [diff] [blame] | 1719 | int32_t w = fixed_round_up_to_int(vp->buffer.src_width); |
| 1720 | int32_t h = fixed_round_up_to_int(vp->buffer.src_height); |
| 1721 | |
| 1722 | surface_set_size(surface, w ?: 1, h ?: 1); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1723 | return; |
| 1724 | } |
| 1725 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 1726 | surface_set_size(surface, width, height); |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1727 | } |
| 1728 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1729 | WL_EXPORT uint32_t |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1730 | weston_compositor_get_time(void) |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 1731 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1732 | struct timeval tv; |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 1733 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1734 | gettimeofday(&tv, NULL); |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 1735 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1736 | return tv.tv_sec * 1000 + tv.tv_usec / 1000; |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 1737 | } |
| 1738 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1739 | WL_EXPORT struct weston_view * |
| 1740 | weston_compositor_pick_view(struct weston_compositor *compositor, |
| 1741 | wl_fixed_t x, wl_fixed_t y, |
| 1742 | wl_fixed_t *vx, wl_fixed_t *vy) |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 1743 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1744 | struct weston_view *view; |
Pekka Paalanen | fc22a52 | 2015-02-18 15:08:29 +0200 | [diff] [blame] | 1745 | wl_fixed_t view_x, view_y; |
| 1746 | int view_ix, view_iy; |
| 1747 | int ix = wl_fixed_to_int(x); |
| 1748 | int iy = wl_fixed_to_int(y); |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 1749 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1750 | wl_list_for_each(view, &compositor->view_list, link) { |
Pekka Paalanen | fc22a52 | 2015-02-18 15:08:29 +0200 | [diff] [blame] | 1751 | if (!pixman_region32_contains_point( |
| 1752 | &view->transform.boundingbox, ix, iy, NULL)) |
| 1753 | continue; |
| 1754 | |
| 1755 | weston_view_from_global_fixed(view, x, y, &view_x, &view_y); |
| 1756 | view_ix = wl_fixed_to_int(view_x); |
| 1757 | view_iy = wl_fixed_to_int(view_y); |
| 1758 | |
| 1759 | if (!pixman_region32_contains_point(&view->surface->input, |
| 1760 | view_ix, view_iy, NULL)) |
| 1761 | continue; |
| 1762 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1763 | if (view->geometry.scissor_enabled && |
| 1764 | !pixman_region32_contains_point(&view->geometry.scissor, |
| 1765 | view_ix, view_iy, NULL)) |
| 1766 | continue; |
| 1767 | |
Pekka Paalanen | fc22a52 | 2015-02-18 15:08:29 +0200 | [diff] [blame] | 1768 | *vx = view_x; |
| 1769 | *vy = view_y; |
| 1770 | return view; |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | return NULL; |
| 1774 | } |
| 1775 | |
| 1776 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1777 | weston_compositor_repick(struct weston_compositor *compositor) |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 1778 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1779 | struct weston_seat *seat; |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 1780 | |
Kristian Høgsberg | 10ddd97 | 2013-10-22 12:40:54 -0700 | [diff] [blame] | 1781 | if (!compositor->session_active) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1782 | return; |
| 1783 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1784 | wl_list_for_each(seat, &compositor->seat_list, link) |
Kristian Høgsberg | a71e8b2 | 2013-05-06 21:51:21 -0400 | [diff] [blame] | 1785 | weston_seat_repick(seat); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 1786 | } |
| 1787 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1788 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1789 | weston_view_unmap(struct weston_view *view) |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 1790 | { |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 1791 | struct weston_seat *seat; |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 1792 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1793 | if (!weston_view_is_mapped(view)) |
| 1794 | return; |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 1795 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1796 | weston_view_damage_below(view); |
| 1797 | view->output = NULL; |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 1798 | view->plane = NULL; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1799 | weston_layer_entry_remove(&view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1800 | wl_list_remove(&view->link); |
| 1801 | wl_list_init(&view->link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1802 | view->output_mask = 0; |
| 1803 | weston_surface_assign_output(view->surface); |
| 1804 | |
| 1805 | if (weston_surface_is_mapped(view->surface)) |
| 1806 | return; |
| 1807 | |
| 1808 | wl_list_for_each(seat, &view->surface->compositor->seat_list, link) { |
| 1809 | if (seat->keyboard && seat->keyboard->focus == view->surface) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1810 | weston_keyboard_set_focus(seat->keyboard, NULL); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1811 | if (seat->pointer && seat->pointer->focus == view) |
Kristian Høgsberg | e314875 | 2013-05-06 23:19:49 -0400 | [diff] [blame] | 1812 | weston_pointer_set_focus(seat->pointer, |
Kristian Høgsberg | 02bbabb | 2013-05-06 22:15:05 -0400 | [diff] [blame] | 1813 | NULL, |
| 1814 | wl_fixed_from_int(0), |
| 1815 | wl_fixed_from_int(0)); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1816 | if (seat->touch && seat->touch->focus == view) |
Michael Fu | a2bb791 | 2013-07-23 15:51:06 +0800 | [diff] [blame] | 1817 | weston_touch_set_focus(seat, NULL); |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 1818 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1819 | } |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 1820 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1821 | WL_EXPORT void |
| 1822 | weston_surface_unmap(struct weston_surface *surface) |
| 1823 | { |
| 1824 | struct weston_view *view; |
| 1825 | |
| 1826 | wl_list_for_each(view, &surface->views, surface_link) |
| 1827 | weston_view_unmap(view); |
| 1828 | surface->output = NULL; |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 1829 | } |
| 1830 | |
Pekka Paalanen | 3c9b802 | 2014-03-14 14:38:13 +0200 | [diff] [blame] | 1831 | static void |
| 1832 | weston_surface_reset_pending_buffer(struct weston_surface *surface) |
| 1833 | { |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 1834 | weston_surface_state_set_buffer(&surface->pending, NULL); |
Pekka Paalanen | 3c9b802 | 2014-03-14 14:38:13 +0200 | [diff] [blame] | 1835 | surface->pending.sx = 0; |
| 1836 | surface->pending.sy = 0; |
| 1837 | surface->pending.newly_attached = 0; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1838 | surface->pending.buffer_viewport.changed = 0; |
Pekka Paalanen | 3c9b802 | 2014-03-14 14:38:13 +0200 | [diff] [blame] | 1839 | } |
| 1840 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1841 | WL_EXPORT void |
| 1842 | weston_view_destroy(struct weston_view *view) |
| 1843 | { |
| 1844 | wl_signal_emit(&view->destroy_signal, view); |
| 1845 | |
| 1846 | assert(wl_list_empty(&view->geometry.child_list)); |
| 1847 | |
| 1848 | if (weston_view_is_mapped(view)) { |
| 1849 | weston_view_unmap(view); |
| 1850 | weston_compositor_build_view_list(view->surface->compositor); |
| 1851 | } |
| 1852 | |
| 1853 | wl_list_remove(&view->link); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1854 | weston_layer_entry_remove(&view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1855 | |
| 1856 | pixman_region32_fini(&view->clip); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1857 | pixman_region32_fini(&view->geometry.scissor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1858 | pixman_region32_fini(&view->transform.boundingbox); |
Pekka Paalanen | 8844bf2 | 2015-02-18 16:30:47 +0200 | [diff] [blame] | 1859 | pixman_region32_fini(&view->transform.opaque); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1860 | |
| 1861 | weston_view_set_transform_parent(view, NULL); |
| 1862 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1863 | wl_list_remove(&view->surface_link); |
| 1864 | |
| 1865 | free(view); |
| 1866 | } |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1867 | |
| 1868 | WL_EXPORT void |
| 1869 | weston_surface_destroy(struct weston_surface *surface) |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 1870 | { |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 1871 | struct weston_frame_callback *cb, *next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1872 | struct weston_view *ev, *nv; |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 1873 | |
Giulio Camuffo | 13b85bd | 2013-08-13 23:10:14 +0200 | [diff] [blame] | 1874 | if (--surface->ref_count > 0) |
| 1875 | return; |
| 1876 | |
| 1877 | wl_signal_emit(&surface->destroy_signal, &surface->resource); |
| 1878 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1879 | assert(wl_list_empty(&surface->subsurface_list_pending)); |
| 1880 | assert(wl_list_empty(&surface->subsurface_list)); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1881 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1882 | wl_list_for_each_safe(ev, nv, &surface->views, surface_link) |
| 1883 | weston_view_destroy(ev); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 1884 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 1885 | weston_surface_state_fini(&surface->pending); |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1886 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1887 | weston_buffer_reference(&surface->buffer_ref, NULL); |
Kristian Høgsberg | 3f8f39c | 2009-09-18 17:05:13 -0400 | [diff] [blame] | 1888 | |
Pekka Paalanen | 402ae6d | 2012-01-03 10:23:24 +0200 | [diff] [blame] | 1889 | pixman_region32_fini(&surface->damage); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1890 | pixman_region32_fini(&surface->opaque); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 1891 | pixman_region32_fini(&surface->input); |
Pekka Paalanen | 402ae6d | 2012-01-03 10:23:24 +0200 | [diff] [blame] | 1892 | |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 1893 | wl_list_for_each_safe(cb, next, &surface->frame_callback_list, link) |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 1894 | wl_resource_destroy(cb->resource); |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 1895 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 1896 | weston_presentation_feedback_discard_list(&surface->feedback_list); |
| 1897 | |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 1898 | free(surface); |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 1899 | } |
| 1900 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1901 | static void |
| 1902 | destroy_surface(struct wl_resource *resource) |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 1903 | { |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1904 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 1905 | |
Giulio Camuffo | 0d37974 | 2013-11-15 22:06:15 +0100 | [diff] [blame] | 1906 | /* Set the resource to NULL, since we don't want to leave a |
| 1907 | * dangling pointer if the surface was refcounted and survives |
| 1908 | * the weston_surface_destroy() call. */ |
| 1909 | surface->resource = NULL; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1910 | weston_surface_destroy(surface); |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 1911 | } |
| 1912 | |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 1913 | static void |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1914 | weston_buffer_destroy_handler(struct wl_listener *listener, void *data) |
| 1915 | { |
| 1916 | struct weston_buffer *buffer = |
| 1917 | container_of(listener, struct weston_buffer, destroy_listener); |
| 1918 | |
| 1919 | wl_signal_emit(&buffer->destroy_signal, buffer); |
| 1920 | free(buffer); |
| 1921 | } |
| 1922 | |
Giulio Camuffo | e058cd1 | 2013-12-12 14:14:29 +0100 | [diff] [blame] | 1923 | WL_EXPORT struct weston_buffer * |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1924 | weston_buffer_from_resource(struct wl_resource *resource) |
| 1925 | { |
| 1926 | struct weston_buffer *buffer; |
| 1927 | struct wl_listener *listener; |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 1928 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1929 | listener = wl_resource_get_destroy_listener(resource, |
| 1930 | weston_buffer_destroy_handler); |
| 1931 | |
Kristian Høgsberg | 08b58c7 | 2013-08-15 12:26:42 -0700 | [diff] [blame] | 1932 | if (listener) |
| 1933 | return container_of(listener, struct weston_buffer, |
| 1934 | destroy_listener); |
| 1935 | |
| 1936 | buffer = zalloc(sizeof *buffer); |
| 1937 | if (buffer == NULL) |
| 1938 | return NULL; |
| 1939 | |
| 1940 | buffer->resource = resource; |
| 1941 | wl_signal_init(&buffer->destroy_signal); |
| 1942 | buffer->destroy_listener.notify = weston_buffer_destroy_handler; |
Stanislav Vorobiov | bfbb8e5 | 2013-08-29 11:36:44 +0400 | [diff] [blame] | 1943 | buffer->y_inverted = 1; |
Kristian Høgsberg | 08b58c7 | 2013-08-15 12:26:42 -0700 | [diff] [blame] | 1944 | wl_resource_add_destroy_listener(resource, &buffer->destroy_listener); |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 1945 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1946 | return buffer; |
| 1947 | } |
| 1948 | |
| 1949 | static void |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1950 | weston_buffer_reference_handle_destroy(struct wl_listener *listener, |
| 1951 | void *data) |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 1952 | { |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1953 | struct weston_buffer_reference *ref = |
| 1954 | container_of(listener, struct weston_buffer_reference, |
| 1955 | destroy_listener); |
| 1956 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1957 | assert((struct weston_buffer *)data == ref->buffer); |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1958 | ref->buffer = NULL; |
| 1959 | } |
| 1960 | |
| 1961 | WL_EXPORT void |
| 1962 | weston_buffer_reference(struct weston_buffer_reference *ref, |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1963 | struct weston_buffer *buffer) |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1964 | { |
| 1965 | if (ref->buffer && buffer != ref->buffer) { |
Kristian Høgsberg | 2034780 | 2013-03-04 12:07:46 -0500 | [diff] [blame] | 1966 | ref->buffer->busy_count--; |
| 1967 | if (ref->buffer->busy_count == 0) { |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1968 | assert(wl_resource_get_client(ref->buffer->resource)); |
| 1969 | wl_resource_queue_event(ref->buffer->resource, |
Kristian Høgsberg | 2034780 | 2013-03-04 12:07:46 -0500 | [diff] [blame] | 1970 | WL_BUFFER_RELEASE); |
| 1971 | } |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1972 | wl_list_remove(&ref->destroy_listener.link); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 1973 | } |
| 1974 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1975 | if (buffer && buffer != ref->buffer) { |
Kristian Høgsberg | b7b77e6 | 2012-09-05 22:38:18 -0400 | [diff] [blame] | 1976 | buffer->busy_count++; |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1977 | wl_signal_add(&buffer->destroy_signal, |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1978 | &ref->destroy_listener); |
Pekka Paalanen | a6421c4 | 2012-12-04 15:58:10 +0200 | [diff] [blame] | 1979 | } |
| 1980 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1981 | ref->buffer = buffer; |
| 1982 | ref->destroy_listener.notify = weston_buffer_reference_handle_destroy; |
| 1983 | } |
| 1984 | |
| 1985 | static void |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1986 | weston_surface_attach(struct weston_surface *surface, |
| 1987 | struct weston_buffer *buffer) |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1988 | { |
| 1989 | weston_buffer_reference(&surface->buffer_ref, buffer); |
| 1990 | |
Pekka Paalanen | a6421c4 | 2012-12-04 15:58:10 +0200 | [diff] [blame] | 1991 | if (!buffer) { |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1992 | if (weston_surface_is_mapped(surface)) |
| 1993 | weston_surface_unmap(surface); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 1994 | } |
| 1995 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1996 | surface->compositor->renderer->attach(surface, buffer); |
Pekka Paalanen | bb2f3f2 | 2014-03-14 14:38:11 +0200 | [diff] [blame] | 1997 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1998 | weston_surface_calculate_size_from_buffer(surface); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 1999 | weston_presentation_feedback_discard_list(&surface->feedback_list); |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 2000 | } |
| 2001 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2002 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2003 | weston_compositor_damage_all(struct weston_compositor *compositor) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2004 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2005 | struct weston_output *output; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2006 | |
| 2007 | wl_list_for_each(output, &compositor->output_list, link) |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2008 | weston_output_damage(output); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2009 | } |
| 2010 | |
Kristian Høgsberg | 9f404b7 | 2012-01-26 00:11:01 -0500 | [diff] [blame] | 2011 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2012 | weston_output_damage(struct weston_output *output) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2013 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2014 | struct weston_compositor *compositor = output->compositor; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2015 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 2016 | pixman_region32_union(&compositor->primary_plane.damage, |
| 2017 | &compositor->primary_plane.damage, |
| 2018 | &output->region); |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2019 | weston_output_schedule_repaint(output); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2020 | } |
| 2021 | |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame] | 2022 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2023 | surface_flush_damage(struct weston_surface *surface) |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2024 | { |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2025 | if (surface->buffer_ref.buffer && |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2026 | wl_shm_buffer_get(surface->buffer_ref.buffer->resource)) |
Kristian Høgsberg | fa1be02 | 2012-09-05 22:49:55 -0400 | [diff] [blame] | 2027 | surface->compositor->renderer->flush_damage(surface); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2028 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2029 | if (weston_timeline_enabled_ && |
| 2030 | pixman_region32_not_empty(&surface->damage)) |
| 2031 | TL_POINT("core_flush_damage", TLP_SURFACE(surface), |
| 2032 | TLP_OUTPUT(surface->output), TLP_END); |
| 2033 | |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 2034 | pixman_region32_clear(&surface->damage); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2035 | } |
| 2036 | |
| 2037 | static void |
| 2038 | view_accumulate_damage(struct weston_view *view, |
| 2039 | pixman_region32_t *opaque) |
| 2040 | { |
| 2041 | pixman_region32_t damage; |
| 2042 | |
| 2043 | pixman_region32_init(&damage); |
| 2044 | if (view->transform.enabled) { |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2045 | pixman_box32_t *extents; |
| 2046 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2047 | extents = pixman_region32_extents(&view->surface->damage); |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 2048 | view_compute_bbox(view, extents, &damage); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2049 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2050 | pixman_region32_copy(&damage, &view->surface->damage); |
| 2051 | pixman_region32_translate(&damage, |
Pekka Paalanen | 502f5e0 | 2015-02-23 14:08:25 +0200 | [diff] [blame] | 2052 | view->geometry.x, view->geometry.y); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2053 | } |
| 2054 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 2055 | pixman_region32_intersect(&damage, &damage, |
| 2056 | &view->transform.boundingbox); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2057 | pixman_region32_subtract(&damage, &damage, opaque); |
| 2058 | pixman_region32_union(&view->plane->damage, |
| 2059 | &view->plane->damage, &damage); |
| 2060 | pixman_region32_fini(&damage); |
| 2061 | pixman_region32_copy(&view->clip, opaque); |
Pekka Paalanen | 8844bf2 | 2015-02-18 16:30:47 +0200 | [diff] [blame] | 2062 | pixman_region32_union(opaque, opaque, &view->transform.opaque); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2063 | } |
| 2064 | |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 2065 | static void |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2066 | compositor_accumulate_damage(struct weston_compositor *ec) |
| 2067 | { |
| 2068 | struct weston_plane *plane; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2069 | struct weston_view *ev; |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2070 | pixman_region32_t opaque, clip; |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2071 | |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2072 | pixman_region32_init(&clip); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2073 | |
| 2074 | wl_list_for_each(plane, &ec->plane_list, link) { |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2075 | pixman_region32_copy(&plane->clip, &clip); |
| 2076 | |
| 2077 | pixman_region32_init(&opaque); |
| 2078 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2079 | wl_list_for_each(ev, &ec->view_list, link) { |
| 2080 | if (ev->plane != plane) |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2081 | continue; |
| 2082 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2083 | view_accumulate_damage(ev, &opaque); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2084 | } |
| 2085 | |
| 2086 | pixman_region32_union(&clip, &clip, &opaque); |
| 2087 | pixman_region32_fini(&opaque); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2088 | } |
| 2089 | |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2090 | pixman_region32_fini(&clip); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2091 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2092 | wl_list_for_each(ev, &ec->view_list, link) |
| 2093 | ev->surface->touched = 0; |
| 2094 | |
| 2095 | wl_list_for_each(ev, &ec->view_list, link) { |
| 2096 | if (ev->surface->touched) |
| 2097 | continue; |
| 2098 | ev->surface->touched = 1; |
| 2099 | |
| 2100 | surface_flush_damage(ev->surface); |
| 2101 | |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2102 | /* Both the renderer and the backend have seen the buffer |
| 2103 | * by now. If renderer needs the buffer, it has its own |
| 2104 | * reference set. If the backend wants to keep the buffer |
| 2105 | * around for migrating the surface into a non-primary plane |
| 2106 | * later, keep_buffer is true. Otherwise, drop the core |
| 2107 | * reference now, and allow early buffer release. This enables |
| 2108 | * clients to use single-buffering. |
| 2109 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2110 | if (!ev->surface->keep_buffer) |
| 2111 | weston_buffer_reference(&ev->surface->buffer_ref, NULL); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2112 | } |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2113 | } |
| 2114 | |
| 2115 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2116 | surface_stash_subsurface_views(struct weston_surface *surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2117 | { |
| 2118 | struct weston_subsurface *sub; |
| 2119 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2120 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2121 | if (sub->surface == surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2122 | continue; |
| 2123 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2124 | wl_list_insert_list(&sub->unused_views, &sub->surface->views); |
| 2125 | wl_list_init(&sub->surface->views); |
| 2126 | |
| 2127 | surface_stash_subsurface_views(sub->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2128 | } |
| 2129 | } |
| 2130 | |
| 2131 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2132 | surface_free_unused_subsurface_views(struct weston_surface *surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2133 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2134 | struct weston_subsurface *sub; |
| 2135 | struct weston_view *view, *nv; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2136 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2137 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
| 2138 | if (sub->surface == surface) |
| 2139 | continue; |
| 2140 | |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 2141 | wl_list_for_each_safe(view, nv, &sub->unused_views, surface_link) { |
| 2142 | weston_view_unmap (view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2143 | weston_view_destroy(view); |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 2144 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2145 | |
| 2146 | surface_free_unused_subsurface_views(sub->surface); |
| 2147 | } |
| 2148 | } |
| 2149 | |
| 2150 | static void |
| 2151 | view_list_add_subsurface_view(struct weston_compositor *compositor, |
| 2152 | struct weston_subsurface *sub, |
| 2153 | struct weston_view *parent) |
| 2154 | { |
| 2155 | struct weston_subsurface *child; |
| 2156 | struct weston_view *view = NULL, *iv; |
| 2157 | |
Pekka Paalanen | 661de3a | 2014-07-28 12:49:24 +0300 | [diff] [blame] | 2158 | if (!weston_surface_is_mapped(sub->surface)) |
| 2159 | return; |
| 2160 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2161 | wl_list_for_each(iv, &sub->unused_views, surface_link) { |
| 2162 | if (iv->geometry.parent == parent) { |
| 2163 | view = iv; |
| 2164 | break; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2165 | } |
| 2166 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2167 | |
| 2168 | if (view) { |
| 2169 | /* Put it back in the surface's list of views */ |
| 2170 | wl_list_remove(&view->surface_link); |
| 2171 | wl_list_insert(&sub->surface->views, &view->surface_link); |
| 2172 | } else { |
| 2173 | view = weston_view_create(sub->surface); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2174 | weston_view_set_position(view, |
| 2175 | sub->position.x, |
| 2176 | sub->position.y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2177 | weston_view_set_transform_parent(view, parent); |
| 2178 | } |
| 2179 | |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 2180 | view->parent_view = parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2181 | weston_view_update_transform(view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2182 | |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2183 | if (wl_list_empty(&sub->surface->subsurface_list)) { |
| 2184 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 2185 | return; |
| 2186 | } |
| 2187 | |
| 2188 | wl_list_for_each(child, &sub->surface->subsurface_list, parent_link) { |
| 2189 | if (child->surface == sub->surface) |
| 2190 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 2191 | else |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2192 | view_list_add_subsurface_view(compositor, child, view); |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2193 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2194 | } |
| 2195 | |
| 2196 | static void |
| 2197 | view_list_add(struct weston_compositor *compositor, |
| 2198 | struct weston_view *view) |
| 2199 | { |
| 2200 | struct weston_subsurface *sub; |
| 2201 | |
| 2202 | weston_view_update_transform(view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2203 | |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2204 | if (wl_list_empty(&view->surface->subsurface_list)) { |
| 2205 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 2206 | return; |
| 2207 | } |
| 2208 | |
| 2209 | wl_list_for_each(sub, &view->surface->subsurface_list, parent_link) { |
| 2210 | if (sub->surface == view->surface) |
| 2211 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 2212 | else |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2213 | view_list_add_subsurface_view(compositor, sub, view); |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2214 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2215 | } |
| 2216 | |
| 2217 | static void |
| 2218 | weston_compositor_build_view_list(struct weston_compositor *compositor) |
| 2219 | { |
| 2220 | struct weston_view *view; |
| 2221 | struct weston_layer *layer; |
| 2222 | |
| 2223 | wl_list_for_each(layer, &compositor->layer_list, link) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2224 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2225 | surface_stash_subsurface_views(view->surface); |
| 2226 | |
| 2227 | wl_list_init(&compositor->view_list); |
| 2228 | wl_list_for_each(layer, &compositor->layer_list, link) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2229 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2230 | view_list_add(compositor, view); |
| 2231 | } |
| 2232 | } |
| 2233 | |
| 2234 | wl_list_for_each(layer, &compositor->layer_list, link) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2235 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2236 | surface_free_unused_subsurface_views(view->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2237 | } |
| 2238 | |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2239 | static void |
| 2240 | weston_output_take_feedback_list(struct weston_output *output, |
| 2241 | struct weston_surface *surface) |
| 2242 | { |
| 2243 | struct weston_view *view; |
| 2244 | struct weston_presentation_feedback *feedback; |
| 2245 | uint32_t flags = 0xffffffff; |
| 2246 | |
| 2247 | if (wl_list_empty(&surface->feedback_list)) |
| 2248 | return; |
| 2249 | |
| 2250 | /* All views must have the flag for the flag to survive. */ |
| 2251 | wl_list_for_each(view, &surface->views, surface_link) { |
| 2252 | /* ignore views that are not on this output at all */ |
| 2253 | if (view->output_mask & (1u << output->id)) |
| 2254 | flags &= view->psf_flags; |
| 2255 | } |
| 2256 | |
| 2257 | wl_list_for_each(feedback, &surface->feedback_list, link) |
| 2258 | feedback->psf_flags = flags; |
| 2259 | |
| 2260 | wl_list_insert_list(&output->feedback_list, &surface->feedback_list); |
| 2261 | wl_list_init(&surface->feedback_list); |
| 2262 | } |
| 2263 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2264 | static int |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 2265 | weston_output_repaint(struct weston_output *output) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2266 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2267 | struct weston_compositor *ec = output->compositor; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2268 | struct weston_view *ev; |
Kristian Høgsberg | 30c018b | 2012-01-26 08:40:37 -0500 | [diff] [blame] | 2269 | struct weston_animation *animation, *next; |
| 2270 | struct weston_frame_callback *cb, *cnext; |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 2271 | struct wl_list frame_callback_list; |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2272 | pixman_region32_t output_damage; |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2273 | int r; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 2274 | |
Ander Conselvan de Oliveira | e1e2352 | 2013-12-13 22:10:55 +0200 | [diff] [blame] | 2275 | if (output->destroying) |
| 2276 | return 0; |
| 2277 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2278 | TL_POINT("core_repaint_begin", TLP_OUTPUT(output), TLP_END); |
| 2279 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2280 | /* Rebuild the surface list and update surface transforms up front. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2281 | weston_compositor_build_view_list(ec); |
Pekka Paalanen | 15d60ef | 2012-01-27 14:38:33 +0200 | [diff] [blame] | 2282 | |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2283 | if (output->assign_planes && !output->disable_planes) { |
Jesse Barnes | 5308a5e | 2012-02-09 13:12:57 -0800 | [diff] [blame] | 2284 | output->assign_planes(output); |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2285 | } else { |
| 2286 | wl_list_for_each(ev, &ec->view_list, link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2287 | weston_view_move_to_plane(ev, &ec->primary_plane); |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2288 | ev->psf_flags = 0; |
| 2289 | } |
| 2290 | } |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 2291 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2292 | wl_list_init(&frame_callback_list); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2293 | wl_list_for_each(ev, &ec->view_list, link) { |
| 2294 | /* Note: This operation is safe to do multiple times on the |
| 2295 | * same surface. |
| 2296 | */ |
| 2297 | if (ev->surface->output == output) { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2298 | wl_list_insert_list(&frame_callback_list, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2299 | &ev->surface->frame_callback_list); |
| 2300 | wl_list_init(&ev->surface->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2301 | |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2302 | weston_output_take_feedback_list(output, ev->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2303 | } |
| 2304 | } |
| 2305 | |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2306 | compositor_accumulate_damage(ec); |
Kristian Høgsberg | 53df1d8 | 2011-06-23 21:11:19 -0400 | [diff] [blame] | 2307 | |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 2308 | pixman_region32_init(&output_damage); |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 2309 | pixman_region32_intersect(&output_damage, |
| 2310 | &ec->primary_plane.damage, &output->region); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2311 | pixman_region32_subtract(&output_damage, |
| 2312 | &output_damage, &ec->primary_plane.clip); |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 2313 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2314 | if (output->dirty) |
| 2315 | weston_output_update_matrix(output); |
| 2316 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2317 | r = output->repaint(output, &output_damage); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2318 | |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 2319 | pixman_region32_fini(&output_damage); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 2320 | |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2321 | output->repaint_needed = 0; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 2322 | |
Kristian Høgsberg | aa6019e | 2012-03-11 16:35:16 -0400 | [diff] [blame] | 2323 | weston_compositor_repick(ec); |
| 2324 | wl_event_loop_dispatch(ec->input_loop, 0); |
| 2325 | |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 2326 | wl_list_for_each_safe(cb, cnext, &frame_callback_list, link) { |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 2327 | wl_callback_send_done(cb->resource, output->frame_time); |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 2328 | wl_resource_destroy(cb->resource); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 2329 | } |
| 2330 | |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 2331 | wl_list_for_each_safe(animation, next, &output->animation_list, link) { |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 2332 | animation->frame_counter++; |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 2333 | animation->frame(animation, output, output->frame_time); |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 2334 | } |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2335 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2336 | TL_POINT("core_repaint_posted", TLP_OUTPUT(output), TLP_END); |
| 2337 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2338 | return r; |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2339 | } |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 2340 | |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2341 | static int |
| 2342 | weston_compositor_read_input(int fd, uint32_t mask, void *data) |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2343 | { |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2344 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | 34f80ff | 2012-01-18 11:50:31 -0500 | [diff] [blame] | 2345 | |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2346 | wl_event_loop_dispatch(compositor->input_loop, 0); |
| 2347 | |
| 2348 | return 1; |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2349 | } |
| 2350 | |
Pekka Paalanen | 8291979 | 2014-05-21 13:51:49 +0300 | [diff] [blame] | 2351 | static void |
| 2352 | weston_output_schedule_repaint_reset(struct weston_output *output) |
| 2353 | { |
| 2354 | struct weston_compositor *compositor = output->compositor; |
| 2355 | struct wl_event_loop *loop; |
| 2356 | int fd; |
| 2357 | |
| 2358 | output->repaint_scheduled = 0; |
| 2359 | TL_POINT("core_repaint_exit_loop", TLP_OUTPUT(output), TLP_END); |
| 2360 | |
| 2361 | if (compositor->input_loop_source) |
| 2362 | return; |
| 2363 | |
| 2364 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 2365 | fd = wl_event_loop_get_fd(compositor->input_loop); |
| 2366 | compositor->input_loop_source = |
| 2367 | wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE, |
| 2368 | weston_compositor_read_input, compositor); |
| 2369 | } |
| 2370 | |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2371 | static int |
| 2372 | output_repaint_timer_handler(void *data) |
| 2373 | { |
| 2374 | struct weston_output *output = data; |
| 2375 | struct weston_compositor *compositor = output->compositor; |
| 2376 | |
| 2377 | if (output->repaint_needed && |
| 2378 | compositor->state != WESTON_COMPOSITOR_SLEEPING && |
| 2379 | compositor->state != WESTON_COMPOSITOR_OFFSCREEN && |
| 2380 | weston_output_repaint(output) == 0) |
| 2381 | return 0; |
| 2382 | |
| 2383 | weston_output_schedule_repaint_reset(output); |
| 2384 | |
| 2385 | return 0; |
| 2386 | } |
| 2387 | |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2388 | WL_EXPORT void |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 2389 | weston_output_finish_frame(struct weston_output *output, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 2390 | const struct timespec *stamp, |
| 2391 | uint32_t presented_flags) |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2392 | { |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2393 | struct weston_compositor *compositor = output->compositor; |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2394 | int32_t refresh_nsec; |
| 2395 | struct timespec now; |
| 2396 | struct timespec gone; |
| 2397 | int msec; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2398 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2399 | TL_POINT("core_repaint_finished", TLP_OUTPUT(output), |
| 2400 | TLP_VBLANK(stamp), TLP_END); |
| 2401 | |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2402 | refresh_nsec = 1000000000000LL / output->current_mode->refresh; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2403 | weston_presentation_feedback_present_list(&output->feedback_list, |
| 2404 | output, refresh_nsec, stamp, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 2405 | output->msc, |
| 2406 | presented_flags); |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2407 | |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 2408 | output->frame_time = stamp->tv_sec * 1000 + stamp->tv_nsec / 1000000; |
Kristian Høgsberg | 991810c | 2013-10-16 11:10:12 -0700 | [diff] [blame] | 2409 | |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2410 | weston_compositor_read_presentation_clock(compositor, &now); |
| 2411 | timespec_sub(&gone, &now, stamp); |
| 2412 | msec = (refresh_nsec - timespec_to_nsec(&gone)) / 1000000; /* floor */ |
| 2413 | msec -= compositor->repaint_msec; |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2414 | |
Pekka Paalanen | 8fd4de4 | 2015-03-19 12:27:29 +0200 | [diff] [blame^] | 2415 | if (msec < -1000 || msec > 1000) { |
| 2416 | static bool warned; |
| 2417 | |
| 2418 | if (!warned) |
| 2419 | weston_log("Warning: computed repaint delay is " |
| 2420 | "insane: %d msec\n", msec); |
| 2421 | warned = true; |
| 2422 | |
| 2423 | msec = 0; |
| 2424 | } |
| 2425 | |
| 2426 | if (msec < 1) |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2427 | output_repaint_timer_handler(output); |
| 2428 | else |
| 2429 | wl_event_source_timer_update(output->repaint_timer, msec); |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2430 | } |
| 2431 | |
| 2432 | static void |
| 2433 | idle_repaint(void *data) |
| 2434 | { |
| 2435 | struct weston_output *output = data; |
| 2436 | |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 2437 | output->start_repaint_loop(output); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2438 | } |
| 2439 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2440 | WL_EXPORT void |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2441 | weston_layer_entry_insert(struct weston_layer_entry *list, |
| 2442 | struct weston_layer_entry *entry) |
| 2443 | { |
| 2444 | wl_list_insert(&list->link, &entry->link); |
| 2445 | entry->layer = list->layer; |
| 2446 | } |
| 2447 | |
| 2448 | WL_EXPORT void |
| 2449 | weston_layer_entry_remove(struct weston_layer_entry *entry) |
| 2450 | { |
| 2451 | wl_list_remove(&entry->link); |
| 2452 | wl_list_init(&entry->link); |
| 2453 | entry->layer = NULL; |
| 2454 | } |
| 2455 | |
| 2456 | WL_EXPORT void |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2457 | weston_layer_init(struct weston_layer *layer, struct wl_list *below) |
| 2458 | { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2459 | wl_list_init(&layer->view_list.link); |
| 2460 | layer->view_list.layer = layer; |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 2461 | weston_layer_set_mask_infinite(layer); |
Jonas Ådahl | e3cddce | 2012-06-13 00:01:22 +0200 | [diff] [blame] | 2462 | if (below != NULL) |
| 2463 | wl_list_insert(below, &layer->link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2464 | } |
| 2465 | |
| 2466 | WL_EXPORT void |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 2467 | weston_layer_set_mask(struct weston_layer *layer, |
| 2468 | int x, int y, int width, int height) |
| 2469 | { |
| 2470 | struct weston_view *view; |
| 2471 | |
| 2472 | layer->mask.x1 = x; |
| 2473 | layer->mask.x2 = x + width; |
| 2474 | layer->mask.y1 = y; |
| 2475 | layer->mask.y2 = y + height; |
| 2476 | |
| 2477 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
| 2478 | weston_view_geometry_dirty(view); |
| 2479 | } |
| 2480 | } |
| 2481 | |
| 2482 | WL_EXPORT void |
| 2483 | weston_layer_set_mask_infinite(struct weston_layer *layer) |
| 2484 | { |
| 2485 | weston_layer_set_mask(layer, INT32_MIN, INT32_MIN, |
| 2486 | UINT32_MAX, UINT32_MAX); |
| 2487 | } |
| 2488 | |
| 2489 | WL_EXPORT void |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2490 | weston_output_schedule_repaint(struct weston_output *output) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2491 | { |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2492 | struct weston_compositor *compositor = output->compositor; |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2493 | struct wl_event_loop *loop; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 2494 | |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 2495 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING || |
| 2496 | compositor->state == WESTON_COMPOSITOR_OFFSCREEN) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2497 | return; |
| 2498 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2499 | if (!output->repaint_needed) |
| 2500 | TL_POINT("core_repaint_req", TLP_OUTPUT(output), TLP_END); |
| 2501 | |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2502 | loop = wl_display_get_event_loop(compositor->wl_display); |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2503 | output->repaint_needed = 1; |
| 2504 | if (output->repaint_scheduled) |
| 2505 | return; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 2506 | |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2507 | wl_event_loop_add_idle(loop, idle_repaint, output); |
| 2508 | output->repaint_scheduled = 1; |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2509 | TL_POINT("core_repaint_enter_loop", TLP_OUTPUT(output), TLP_END); |
| 2510 | |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2511 | |
| 2512 | if (compositor->input_loop_source) { |
| 2513 | wl_event_source_remove(compositor->input_loop_source); |
| 2514 | compositor->input_loop_source = NULL; |
| 2515 | } |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2516 | } |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 2517 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2518 | WL_EXPORT void |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2519 | weston_compositor_schedule_repaint(struct weston_compositor *compositor) |
| 2520 | { |
| 2521 | struct weston_output *output; |
| 2522 | |
| 2523 | wl_list_for_each(output, &compositor->output_list, link) |
| 2524 | weston_output_schedule_repaint(output); |
| 2525 | } |
| 2526 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 2527 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 2528 | surface_destroy(struct wl_client *client, struct wl_resource *resource) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 2529 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2530 | wl_resource_destroy(resource); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 2531 | } |
| 2532 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 2533 | static void |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2534 | surface_attach(struct wl_client *client, |
| 2535 | struct wl_resource *resource, |
| 2536 | struct wl_resource *buffer_resource, int32_t sx, int32_t sy) |
| 2537 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2538 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2539 | struct weston_buffer *buffer = NULL; |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2540 | |
Kristian Høgsberg | ab19f93 | 2013-08-20 11:30:54 -0700 | [diff] [blame] | 2541 | if (buffer_resource) { |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2542 | buffer = weston_buffer_from_resource(buffer_resource); |
Kristian Høgsberg | ab19f93 | 2013-08-20 11:30:54 -0700 | [diff] [blame] | 2543 | if (buffer == NULL) { |
| 2544 | wl_client_post_no_memory(client); |
| 2545 | return; |
| 2546 | } |
Kristian Høgsberg | 08b58c7 | 2013-08-15 12:26:42 -0700 | [diff] [blame] | 2547 | } |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 2548 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2549 | /* Attach, attach, without commit in between does not send |
| 2550 | * wl_buffer.release. */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2551 | weston_surface_state_set_buffer(&surface->pending, buffer); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2552 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2553 | surface->pending.sx = sx; |
| 2554 | surface->pending.sy = sy; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2555 | surface->pending.newly_attached = 1; |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 2556 | } |
| 2557 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 2558 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2559 | surface_damage(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 2560 | struct wl_resource *resource, |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2561 | 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] | 2562 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2563 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 9d69f8e | 2010-09-03 14:46:38 -0400 | [diff] [blame] | 2564 | |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 2565 | pixman_region32_union_rect(&surface->pending.damage, |
| 2566 | &surface->pending.damage, |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2567 | x, y, width, height); |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 2568 | } |
| 2569 | |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2570 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 2571 | destroy_frame_callback(struct wl_resource *resource) |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2572 | { |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 2573 | struct weston_frame_callback *cb = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 2574 | |
| 2575 | wl_list_remove(&cb->link); |
Pekka Paalanen | 8c19645 | 2011-11-15 11:45:42 +0200 | [diff] [blame] | 2576 | free(cb); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2577 | } |
| 2578 | |
| 2579 | static void |
| 2580 | surface_frame(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 2581 | struct wl_resource *resource, uint32_t callback) |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2582 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2583 | struct weston_frame_callback *cb; |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2584 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2585 | |
| 2586 | cb = malloc(sizeof *cb); |
| 2587 | if (cb == NULL) { |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 2588 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2589 | return; |
| 2590 | } |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 2591 | |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 2592 | cb->resource = wl_resource_create(client, &wl_callback_interface, 1, |
| 2593 | callback); |
| 2594 | if (cb->resource == NULL) { |
| 2595 | free(cb); |
| 2596 | wl_resource_post_no_memory(resource); |
| 2597 | return; |
| 2598 | } |
| 2599 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 2600 | wl_resource_set_implementation(cb->resource, NULL, cb, |
| 2601 | destroy_frame_callback); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2602 | |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 2603 | wl_list_insert(surface->pending.frame_callback_list.prev, &cb->link); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2604 | } |
| 2605 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2606 | static void |
| 2607 | surface_set_opaque_region(struct wl_client *client, |
| 2608 | struct wl_resource *resource, |
| 2609 | struct wl_resource *region_resource) |
| 2610 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2611 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2612 | struct weston_region *region; |
| 2613 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2614 | if (region_resource) { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 2615 | region = wl_resource_get_user_data(region_resource); |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 2616 | pixman_region32_copy(&surface->pending.opaque, |
| 2617 | ®ion->region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2618 | } else { |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 2619 | pixman_region32_clear(&surface->pending.opaque); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2620 | } |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2621 | } |
| 2622 | |
| 2623 | static void |
| 2624 | surface_set_input_region(struct wl_client *client, |
| 2625 | struct wl_resource *resource, |
| 2626 | struct wl_resource *region_resource) |
| 2627 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2628 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 010f98b | 2012-02-23 17:30:45 -0500 | [diff] [blame] | 2629 | struct weston_region *region; |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2630 | |
| 2631 | if (region_resource) { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 2632 | region = wl_resource_get_user_data(region_resource); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 2633 | pixman_region32_copy(&surface->pending.input, |
| 2634 | ®ion->region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2635 | } else { |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 2636 | pixman_region32_fini(&surface->pending.input); |
| 2637 | region_init_infinite(&surface->pending.input); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2638 | } |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2639 | } |
| 2640 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2641 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2642 | weston_surface_commit_subsurface_order(struct weston_surface *surface) |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2643 | { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2644 | struct weston_subsurface *sub; |
| 2645 | |
| 2646 | wl_list_for_each_reverse(sub, &surface->subsurface_list_pending, |
| 2647 | parent_link_pending) { |
| 2648 | wl_list_remove(&sub->parent_link); |
| 2649 | wl_list_insert(&surface->subsurface_list, &sub->parent_link); |
| 2650 | } |
| 2651 | } |
| 2652 | |
| 2653 | static void |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 2654 | weston_surface_build_buffer_matrix(struct weston_surface *surface, |
| 2655 | struct weston_matrix *matrix) |
| 2656 | { |
| 2657 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
| 2658 | double src_width, src_height, dest_width, dest_height; |
| 2659 | |
| 2660 | weston_matrix_init(matrix); |
| 2661 | |
| 2662 | if (vp->buffer.src_width == wl_fixed_from_int(-1)) { |
| 2663 | src_width = surface->width_from_buffer; |
| 2664 | src_height = surface->height_from_buffer; |
| 2665 | } else { |
| 2666 | src_width = wl_fixed_to_double(vp->buffer.src_width); |
| 2667 | src_height = wl_fixed_to_double(vp->buffer.src_height); |
| 2668 | } |
| 2669 | |
| 2670 | if (vp->surface.width == -1) { |
| 2671 | dest_width = src_width; |
| 2672 | dest_height = src_height; |
| 2673 | } else { |
| 2674 | dest_width = vp->surface.width; |
| 2675 | dest_height = vp->surface.height; |
| 2676 | } |
| 2677 | |
| 2678 | if (src_width != dest_width || src_height != dest_height) |
| 2679 | weston_matrix_scale(matrix, |
| 2680 | src_width / dest_width, |
| 2681 | src_height / dest_height, 1); |
| 2682 | |
| 2683 | if (vp->buffer.src_width != wl_fixed_from_int(-1)) |
| 2684 | weston_matrix_translate(matrix, |
| 2685 | wl_fixed_to_double(vp->buffer.src_x), |
| 2686 | wl_fixed_to_double(vp->buffer.src_y), |
| 2687 | 0); |
| 2688 | |
| 2689 | switch (vp->buffer.transform) { |
| 2690 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 2691 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 2692 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 2693 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 2694 | weston_matrix_scale(matrix, -1, 1, 1); |
| 2695 | weston_matrix_translate(matrix, |
| 2696 | surface->width_from_buffer, 0, 0); |
| 2697 | break; |
| 2698 | } |
| 2699 | |
| 2700 | switch (vp->buffer.transform) { |
| 2701 | default: |
| 2702 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 2703 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 2704 | break; |
| 2705 | case WL_OUTPUT_TRANSFORM_90: |
| 2706 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 2707 | weston_matrix_rotate_xy(matrix, 0, 1); |
| 2708 | weston_matrix_translate(matrix, |
| 2709 | surface->height_from_buffer, 0, 0); |
| 2710 | break; |
| 2711 | case WL_OUTPUT_TRANSFORM_180: |
| 2712 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 2713 | weston_matrix_rotate_xy(matrix, -1, 0); |
| 2714 | weston_matrix_translate(matrix, |
| 2715 | surface->width_from_buffer, |
| 2716 | surface->height_from_buffer, 0); |
| 2717 | break; |
| 2718 | case WL_OUTPUT_TRANSFORM_270: |
| 2719 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 2720 | weston_matrix_rotate_xy(matrix, 0, -1); |
| 2721 | weston_matrix_translate(matrix, |
| 2722 | 0, surface->width_from_buffer, 0); |
| 2723 | break; |
| 2724 | } |
| 2725 | |
| 2726 | weston_matrix_scale(matrix, vp->buffer.scale, vp->buffer.scale, 1); |
| 2727 | } |
| 2728 | |
| 2729 | static void |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2730 | weston_surface_commit_state(struct weston_surface *surface, |
| 2731 | struct weston_surface_state *state) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2732 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2733 | struct weston_view *view; |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 2734 | pixman_region32_t opaque; |
| 2735 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 2736 | /* wl_surface.set_buffer_transform */ |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 2737 | /* wl_surface.set_buffer_scale */ |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 2738 | /* wl_viewport.set */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2739 | surface->buffer_viewport = state->buffer_viewport; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 2740 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2741 | /* wl_surface.attach */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2742 | if (state->newly_attached) |
| 2743 | weston_surface_attach(surface, state->buffer); |
| 2744 | weston_surface_state_set_buffer(state, NULL); |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2745 | |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 2746 | weston_surface_build_buffer_matrix(surface, |
| 2747 | &surface->surface_to_buffer_matrix); |
| 2748 | weston_matrix_invert(&surface->buffer_to_surface_matrix, |
| 2749 | &surface->surface_to_buffer_matrix); |
| 2750 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2751 | if (state->newly_attached || state->buffer_viewport.changed) { |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 2752 | weston_surface_update_size(surface); |
| 2753 | if (surface->configure) |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2754 | surface->configure(surface, state->sx, state->sy); |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 2755 | } |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2756 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2757 | state->sx = 0; |
| 2758 | state->sy = 0; |
| 2759 | state->newly_attached = 0; |
| 2760 | state->buffer_viewport.changed = 0; |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 2761 | |
| 2762 | /* wl_surface.damage */ |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2763 | if (weston_timeline_enabled_ && |
| 2764 | pixman_region32_not_empty(&state->damage)) |
| 2765 | TL_POINT("core_commit_damage", TLP_SURFACE(surface), TLP_END); |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 2766 | pixman_region32_union(&surface->damage, &surface->damage, |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2767 | &state->damage); |
Kristian Høgsberg | 4d0214c | 2012-11-08 11:36:02 -0500 | [diff] [blame] | 2768 | pixman_region32_intersect_rect(&surface->damage, &surface->damage, |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 2769 | 0, 0, surface->width, surface->height); |
Jason Ekstrand | f83a0d4 | 2014-09-06 09:01:28 -0700 | [diff] [blame] | 2770 | pixman_region32_clear(&state->damage); |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 2771 | |
| 2772 | /* wl_surface.set_opaque_region */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2773 | pixman_region32_init(&opaque); |
| 2774 | pixman_region32_intersect_rect(&opaque, &state->opaque, |
| 2775 | 0, 0, surface->width, surface->height); |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 2776 | |
| 2777 | if (!pixman_region32_equal(&opaque, &surface->opaque)) { |
| 2778 | pixman_region32_copy(&surface->opaque, &opaque); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2779 | wl_list_for_each(view, &surface->views, surface_link) |
| 2780 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 2781 | } |
| 2782 | |
| 2783 | pixman_region32_fini(&opaque); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 2784 | |
| 2785 | /* wl_surface.set_input_region */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2786 | pixman_region32_intersect_rect(&surface->input, &state->input, |
| 2787 | 0, 0, surface->width, surface->height); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 2788 | |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 2789 | /* wl_surface.frame */ |
| 2790 | wl_list_insert_list(&surface->frame_callback_list, |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2791 | &state->frame_callback_list); |
| 2792 | wl_list_init(&state->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2793 | |
| 2794 | /* XXX: |
| 2795 | * What should happen with a feedback request, if there |
| 2796 | * is no wl_buffer attached for this commit? |
| 2797 | */ |
| 2798 | |
| 2799 | /* presentation.feedback */ |
| 2800 | wl_list_insert_list(&surface->feedback_list, |
| 2801 | &state->feedback_list); |
| 2802 | wl_list_init(&state->feedback_list); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2803 | } |
| 2804 | |
| 2805 | static void |
| 2806 | weston_surface_commit(struct weston_surface *surface) |
| 2807 | { |
| 2808 | weston_surface_commit_state(surface, &surface->pending); |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 2809 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2810 | weston_surface_commit_subsurface_order(surface); |
| 2811 | |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 2812 | weston_surface_schedule_repaint(surface); |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2813 | } |
| 2814 | |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 2815 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2816 | weston_subsurface_commit(struct weston_subsurface *sub); |
| 2817 | |
| 2818 | static void |
| 2819 | weston_subsurface_parent_commit(struct weston_subsurface *sub, |
| 2820 | int parent_is_synchronized); |
| 2821 | |
| 2822 | static void |
| 2823 | surface_commit(struct wl_client *client, struct wl_resource *resource) |
| 2824 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2825 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2826 | struct weston_subsurface *sub = weston_surface_to_subsurface(surface); |
| 2827 | |
| 2828 | if (sub) { |
| 2829 | weston_subsurface_commit(sub); |
| 2830 | return; |
| 2831 | } |
| 2832 | |
| 2833 | weston_surface_commit(surface); |
| 2834 | |
| 2835 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
| 2836 | if (sub->surface != surface) |
| 2837 | weston_subsurface_parent_commit(sub, 0); |
| 2838 | } |
| 2839 | } |
| 2840 | |
| 2841 | static void |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 2842 | surface_set_buffer_transform(struct wl_client *client, |
| 2843 | struct wl_resource *resource, int transform) |
| 2844 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2845 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 2846 | |
Jonny Lamb | a55f139 | 2014-05-30 12:07:15 +0200 | [diff] [blame] | 2847 | /* if wl_output.transform grows more members this will need to be updated. */ |
| 2848 | if (transform < 0 || |
| 2849 | transform > WL_OUTPUT_TRANSFORM_FLIPPED_270) { |
| 2850 | wl_resource_post_error(resource, |
| 2851 | WL_SURFACE_ERROR_INVALID_TRANSFORM, |
| 2852 | "buffer transform must be a valid transform " |
| 2853 | "('%d' specified)", transform); |
| 2854 | return; |
| 2855 | } |
| 2856 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 2857 | surface->pending.buffer_viewport.buffer.transform = transform; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 2858 | surface->pending.buffer_viewport.changed = 1; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 2859 | } |
| 2860 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 2861 | static void |
| 2862 | surface_set_buffer_scale(struct wl_client *client, |
| 2863 | struct wl_resource *resource, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 2864 | int32_t scale) |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 2865 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2866 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 2867 | |
Jonny Lamb | a55f139 | 2014-05-30 12:07:15 +0200 | [diff] [blame] | 2868 | if (scale < 1) { |
| 2869 | wl_resource_post_error(resource, |
| 2870 | WL_SURFACE_ERROR_INVALID_SCALE, |
| 2871 | "buffer scale must be at least one " |
| 2872 | "('%d' specified)", scale); |
| 2873 | return; |
| 2874 | } |
| 2875 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 2876 | surface->pending.buffer_viewport.buffer.scale = scale; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 2877 | surface->pending.buffer_viewport.changed = 1; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 2878 | } |
| 2879 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 2880 | static const struct wl_surface_interface surface_interface = { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2881 | surface_destroy, |
| 2882 | surface_attach, |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2883 | surface_damage, |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2884 | surface_frame, |
| 2885 | surface_set_opaque_region, |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2886 | surface_set_input_region, |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 2887 | surface_commit, |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 2888 | surface_set_buffer_transform, |
| 2889 | surface_set_buffer_scale |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2890 | }; |
| 2891 | |
| 2892 | static void |
| 2893 | compositor_create_surface(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 2894 | struct wl_resource *resource, uint32_t id) |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2895 | { |
Kristian Høgsberg | c2d7042 | 2013-06-25 15:34:33 -0400 | [diff] [blame] | 2896 | struct weston_compositor *ec = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2897 | struct weston_surface *surface; |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2898 | |
Kristian Høgsberg | 18c9300 | 2012-01-27 11:58:31 -0500 | [diff] [blame] | 2899 | surface = weston_surface_create(ec); |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 2900 | if (surface == NULL) { |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 2901 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2902 | return; |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 2903 | } |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2904 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 2905 | surface->resource = |
| 2906 | wl_resource_create(client, &wl_surface_interface, |
| 2907 | wl_resource_get_version(resource), id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 2908 | if (surface->resource == NULL) { |
| 2909 | weston_surface_destroy(surface); |
| 2910 | wl_resource_post_no_memory(resource); |
| 2911 | return; |
| 2912 | } |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 2913 | wl_resource_set_implementation(surface->resource, &surface_interface, |
| 2914 | surface, destroy_surface); |
Kristian Høgsberg | f03a04a | 2014-04-06 22:04:50 -0700 | [diff] [blame] | 2915 | |
| 2916 | wl_signal_emit(&ec->create_surface_signal, surface); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2917 | } |
| 2918 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2919 | static void |
| 2920 | destroy_region(struct wl_resource *resource) |
| 2921 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 2922 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2923 | |
| 2924 | pixman_region32_fini(®ion->region); |
| 2925 | free(region); |
| 2926 | } |
| 2927 | |
| 2928 | static void |
| 2929 | region_destroy(struct wl_client *client, struct wl_resource *resource) |
| 2930 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2931 | wl_resource_destroy(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2932 | } |
| 2933 | |
| 2934 | static void |
| 2935 | region_add(struct wl_client *client, struct wl_resource *resource, |
| 2936 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 2937 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 2938 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2939 | |
| 2940 | pixman_region32_union_rect(®ion->region, ®ion->region, |
| 2941 | x, y, width, height); |
| 2942 | } |
| 2943 | |
| 2944 | static void |
| 2945 | region_subtract(struct wl_client *client, struct wl_resource *resource, |
| 2946 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 2947 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 2948 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2949 | pixman_region32_t rect; |
| 2950 | |
| 2951 | pixman_region32_init_rect(&rect, x, y, width, height); |
| 2952 | pixman_region32_subtract(®ion->region, ®ion->region, &rect); |
| 2953 | pixman_region32_fini(&rect); |
| 2954 | } |
| 2955 | |
| 2956 | static const struct wl_region_interface region_interface = { |
| 2957 | region_destroy, |
| 2958 | region_add, |
| 2959 | region_subtract |
| 2960 | }; |
| 2961 | |
| 2962 | static void |
| 2963 | compositor_create_region(struct wl_client *client, |
| 2964 | struct wl_resource *resource, uint32_t id) |
| 2965 | { |
| 2966 | struct weston_region *region; |
| 2967 | |
| 2968 | region = malloc(sizeof *region); |
| 2969 | if (region == NULL) { |
| 2970 | wl_resource_post_no_memory(resource); |
| 2971 | return; |
| 2972 | } |
| 2973 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2974 | pixman_region32_init(®ion->region); |
| 2975 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 2976 | region->resource = |
| 2977 | wl_resource_create(client, &wl_region_interface, 1, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 2978 | if (region->resource == NULL) { |
| 2979 | free(region); |
| 2980 | wl_resource_post_no_memory(resource); |
| 2981 | return; |
| 2982 | } |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 2983 | wl_resource_set_implementation(region->resource, ®ion_interface, |
| 2984 | region, destroy_region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2985 | } |
| 2986 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 2987 | static const struct wl_compositor_interface compositor_interface = { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2988 | compositor_create_surface, |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2989 | compositor_create_region |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2990 | }; |
| 2991 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 2992 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2993 | weston_subsurface_commit_from_cache(struct weston_subsurface *sub) |
| 2994 | { |
| 2995 | struct weston_surface *surface = sub->surface; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2996 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2997 | weston_surface_commit_state(surface, &sub->cached); |
| 2998 | weston_buffer_reference(&sub->cached_buffer_ref, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2999 | |
| 3000 | weston_surface_commit_subsurface_order(surface); |
| 3001 | |
| 3002 | weston_surface_schedule_repaint(surface); |
| 3003 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3004 | sub->has_cached_data = 0; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3005 | } |
| 3006 | |
| 3007 | static void |
| 3008 | weston_subsurface_commit_to_cache(struct weston_subsurface *sub) |
| 3009 | { |
| 3010 | struct weston_surface *surface = sub->surface; |
| 3011 | |
| 3012 | /* |
| 3013 | * If this commit would cause the surface to move by the |
| 3014 | * attach(dx, dy) parameters, the old damage region must be |
| 3015 | * translated to correspond to the new surface coordinate system |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 3016 | * original_mode. |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3017 | */ |
| 3018 | pixman_region32_translate(&sub->cached.damage, |
| 3019 | -surface->pending.sx, -surface->pending.sy); |
| 3020 | pixman_region32_union(&sub->cached.damage, &sub->cached.damage, |
| 3021 | &surface->pending.damage); |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 3022 | pixman_region32_clear(&surface->pending.damage); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3023 | |
| 3024 | if (surface->pending.newly_attached) { |
| 3025 | sub->cached.newly_attached = 1; |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3026 | weston_surface_state_set_buffer(&sub->cached, |
| 3027 | surface->pending.buffer); |
| 3028 | weston_buffer_reference(&sub->cached_buffer_ref, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3029 | surface->pending.buffer); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3030 | weston_presentation_feedback_discard_list( |
| 3031 | &sub->cached.feedback_list); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3032 | } |
| 3033 | sub->cached.sx += surface->pending.sx; |
| 3034 | sub->cached.sy += surface->pending.sy; |
Pekka Paalanen | 260ba38 | 2014-03-14 14:38:12 +0200 | [diff] [blame] | 3035 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3036 | sub->cached.buffer_viewport.changed |= |
| 3037 | surface->pending.buffer_viewport.changed; |
| 3038 | sub->cached.buffer_viewport.buffer = |
| 3039 | surface->pending.buffer_viewport.buffer; |
| 3040 | sub->cached.buffer_viewport.surface = |
| 3041 | surface->pending.buffer_viewport.surface; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3042 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3043 | weston_surface_reset_pending_buffer(surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3044 | |
| 3045 | pixman_region32_copy(&sub->cached.opaque, &surface->pending.opaque); |
| 3046 | |
| 3047 | pixman_region32_copy(&sub->cached.input, &surface->pending.input); |
| 3048 | |
| 3049 | wl_list_insert_list(&sub->cached.frame_callback_list, |
| 3050 | &surface->pending.frame_callback_list); |
| 3051 | wl_list_init(&surface->pending.frame_callback_list); |
| 3052 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3053 | wl_list_insert_list(&sub->cached.feedback_list, |
| 3054 | &surface->pending.feedback_list); |
| 3055 | wl_list_init(&surface->pending.feedback_list); |
| 3056 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3057 | sub->has_cached_data = 1; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3058 | } |
| 3059 | |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 3060 | static bool |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3061 | weston_subsurface_is_synchronized(struct weston_subsurface *sub) |
| 3062 | { |
| 3063 | while (sub) { |
| 3064 | if (sub->synchronized) |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 3065 | return true; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3066 | |
| 3067 | if (!sub->parent) |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 3068 | return false; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3069 | |
| 3070 | sub = weston_surface_to_subsurface(sub->parent); |
| 3071 | } |
| 3072 | |
Carlos Olmedo Escobar | 61a9bf5 | 2014-11-04 14:38:39 +0100 | [diff] [blame] | 3073 | return false; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3074 | } |
| 3075 | |
| 3076 | static void |
| 3077 | weston_subsurface_commit(struct weston_subsurface *sub) |
| 3078 | { |
| 3079 | struct weston_surface *surface = sub->surface; |
| 3080 | struct weston_subsurface *tmp; |
| 3081 | |
| 3082 | /* Recursive check for effectively synchronized. */ |
| 3083 | if (weston_subsurface_is_synchronized(sub)) { |
| 3084 | weston_subsurface_commit_to_cache(sub); |
| 3085 | } else { |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3086 | if (sub->has_cached_data) { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3087 | /* flush accumulated state from cache */ |
| 3088 | weston_subsurface_commit_to_cache(sub); |
| 3089 | weston_subsurface_commit_from_cache(sub); |
| 3090 | } else { |
| 3091 | weston_surface_commit(surface); |
| 3092 | } |
| 3093 | |
| 3094 | wl_list_for_each(tmp, &surface->subsurface_list, parent_link) { |
| 3095 | if (tmp->surface != surface) |
| 3096 | weston_subsurface_parent_commit(tmp, 0); |
| 3097 | } |
| 3098 | } |
| 3099 | } |
| 3100 | |
| 3101 | static void |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3102 | weston_subsurface_synchronized_commit(struct weston_subsurface *sub) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3103 | { |
| 3104 | struct weston_surface *surface = sub->surface; |
| 3105 | struct weston_subsurface *tmp; |
| 3106 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3107 | /* From now on, commit_from_cache the whole sub-tree, regardless of |
| 3108 | * the synchronized mode of each child. This sub-surface or some |
| 3109 | * of its ancestors were synchronized, so we are synchronized |
| 3110 | * all the way down. |
| 3111 | */ |
| 3112 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3113 | if (sub->has_cached_data) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3114 | weston_subsurface_commit_from_cache(sub); |
| 3115 | |
| 3116 | wl_list_for_each(tmp, &surface->subsurface_list, parent_link) { |
| 3117 | if (tmp->surface != surface) |
| 3118 | weston_subsurface_parent_commit(tmp, 1); |
| 3119 | } |
| 3120 | } |
| 3121 | |
| 3122 | static void |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3123 | weston_subsurface_parent_commit(struct weston_subsurface *sub, |
| 3124 | int parent_is_synchronized) |
| 3125 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3126 | struct weston_view *view; |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3127 | if (sub->position.set) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3128 | wl_list_for_each(view, &sub->surface->views, surface_link) |
| 3129 | weston_view_set_position(view, |
| 3130 | sub->position.x, |
| 3131 | sub->position.y); |
| 3132 | |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3133 | sub->position.set = 0; |
| 3134 | } |
| 3135 | |
| 3136 | if (parent_is_synchronized || sub->synchronized) |
| 3137 | weston_subsurface_synchronized_commit(sub); |
| 3138 | } |
| 3139 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3140 | static int |
| 3141 | subsurface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 3142 | { |
| 3143 | return snprintf(buf, len, "sub-surface"); |
| 3144 | } |
| 3145 | |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3146 | static void |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3147 | subsurface_configure(struct weston_surface *surface, int32_t dx, int32_t dy) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3148 | { |
| 3149 | struct weston_compositor *compositor = surface->compositor; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3150 | struct weston_view *view; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3151 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3152 | wl_list_for_each(view, &surface->views, surface_link) |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3153 | weston_view_set_position(view, |
| 3154 | view->geometry.x + dx, |
| 3155 | view->geometry.y + dy); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3156 | |
| 3157 | /* No need to check parent mappedness, because if parent is not |
| 3158 | * mapped, parent is not in a visible layer, so this sub-surface |
| 3159 | * will not be drawn either. |
| 3160 | */ |
| 3161 | if (!weston_surface_is_mapped(surface)) { |
Pekka Paalanen | eb3cf22 | 2014-06-30 11:52:07 +0300 | [diff] [blame] | 3162 | struct weston_output *output; |
| 3163 | |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 3164 | /* Cannot call weston_view_update_transform(), |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3165 | * because that would call it also for the parent surface, |
| 3166 | * which might not be mapped yet. That would lead to |
| 3167 | * inconsistent state, where the window could never be |
| 3168 | * mapped. |
| 3169 | * |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 3170 | * Instead just assign any output, to make |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3171 | * weston_surface_is_mapped() return true, so that when the |
| 3172 | * parent surface does get mapped, this one will get |
Pekka Paalanen | eb3cf22 | 2014-06-30 11:52:07 +0300 | [diff] [blame] | 3173 | * included, too. See view_list_add(). |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3174 | */ |
| 3175 | assert(!wl_list_empty(&compositor->output_list)); |
Pekka Paalanen | eb3cf22 | 2014-06-30 11:52:07 +0300 | [diff] [blame] | 3176 | output = container_of(compositor->output_list.next, |
| 3177 | struct weston_output, link); |
| 3178 | |
| 3179 | surface->output = output; |
| 3180 | weston_surface_update_output_mask(surface, 1 << output->id); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3181 | } |
| 3182 | } |
| 3183 | |
| 3184 | static struct weston_subsurface * |
| 3185 | weston_surface_to_subsurface(struct weston_surface *surface) |
| 3186 | { |
| 3187 | if (surface->configure == subsurface_configure) |
| 3188 | return surface->configure_private; |
| 3189 | |
| 3190 | return NULL; |
| 3191 | } |
| 3192 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3193 | WL_EXPORT struct weston_surface * |
| 3194 | weston_surface_get_main_surface(struct weston_surface *surface) |
| 3195 | { |
| 3196 | struct weston_subsurface *sub; |
| 3197 | |
| 3198 | while (surface && (sub = weston_surface_to_subsurface(surface))) |
| 3199 | surface = sub->parent; |
| 3200 | |
| 3201 | return surface; |
| 3202 | } |
| 3203 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3204 | WL_EXPORT int |
| 3205 | weston_surface_set_role(struct weston_surface *surface, |
| 3206 | const char *role_name, |
| 3207 | struct wl_resource *error_resource, |
| 3208 | uint32_t error_code) |
| 3209 | { |
| 3210 | assert(role_name); |
| 3211 | |
| 3212 | if (surface->role_name == NULL || |
| 3213 | surface->role_name == role_name || |
| 3214 | strcmp(surface->role_name, role_name) == 0) { |
| 3215 | surface->role_name = role_name; |
| 3216 | |
| 3217 | return 0; |
| 3218 | } |
| 3219 | |
| 3220 | wl_resource_post_error(error_resource, error_code, |
| 3221 | "Cannot assign role %s to wl_surface@%d," |
| 3222 | " already has role %s\n", |
| 3223 | role_name, |
| 3224 | wl_resource_get_id(surface->resource), |
| 3225 | surface->role_name); |
| 3226 | return -1; |
| 3227 | } |
| 3228 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3229 | WL_EXPORT void |
| 3230 | weston_surface_set_label_func(struct weston_surface *surface, |
| 3231 | int (*desc)(struct weston_surface *, |
| 3232 | char *, size_t)) |
| 3233 | { |
| 3234 | surface->get_label = desc; |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3235 | surface->timeline.force_refresh = 1; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3236 | } |
| 3237 | |
Pekka Paalanen | c647ed7 | 2015-02-09 13:16:57 +0200 | [diff] [blame] | 3238 | /** Get the size of surface contents |
| 3239 | * |
| 3240 | * \param surface The surface to query. |
| 3241 | * \param width Returns the width of raw contents. |
| 3242 | * \param height Returns the height of raw contents. |
| 3243 | * |
| 3244 | * Retrieves the raw surface content size in pixels for the given surface. |
| 3245 | * This is the whole content size in buffer pixels. If the surface |
| 3246 | * has no content or the renderer does not implement this feature, |
| 3247 | * zeroes are returned. |
| 3248 | * |
| 3249 | * This function is used to determine the buffer size needed for |
| 3250 | * a weston_surface_copy_content() call. |
| 3251 | */ |
| 3252 | WL_EXPORT void |
| 3253 | weston_surface_get_content_size(struct weston_surface *surface, |
| 3254 | int *width, int *height) |
| 3255 | { |
| 3256 | struct weston_renderer *rer = surface->compositor->renderer; |
| 3257 | |
| 3258 | if (!rer->surface_get_content_size) { |
| 3259 | *width = 0; |
| 3260 | *height = 0; |
| 3261 | return; |
| 3262 | } |
| 3263 | |
| 3264 | rer->surface_get_content_size(surface, width, height); |
| 3265 | } |
| 3266 | |
| 3267 | /** Copy surface contents to system memory. |
| 3268 | * |
| 3269 | * \param surface The surface to copy from. |
| 3270 | * \param target Pointer to the target memory buffer. |
| 3271 | * \param size Size of the target buffer in bytes. |
| 3272 | * \param src_x X location on contents to copy from. |
| 3273 | * \param src_y Y location on contents to copy from. |
| 3274 | * \param width Width in pixels of the area to copy. |
| 3275 | * \param height Height in pixels of the area to copy. |
| 3276 | * \return 0 for success, -1 for failure. |
| 3277 | * |
| 3278 | * Surface contents are maintained by the renderer. They can be in a |
| 3279 | * reserved weston_buffer or as a copy, e.g. a GL texture, or something |
| 3280 | * else. |
| 3281 | * |
| 3282 | * Surface contents are copied into memory pointed to by target, |
| 3283 | * which has size bytes of space available. The target memory |
| 3284 | * may be larger than needed, but being smaller returns an error. |
| 3285 | * The extra bytes in target may or may not be written; their content is |
| 3286 | * unspecified. Size must be large enough to hold the image. |
| 3287 | * |
| 3288 | * The image in the target memory will be arranged in rows from |
| 3289 | * top to bottom, and pixels on a row from left to right. The pixel |
| 3290 | * format is PIXMAN_a8b8g8r8, 4 bytes per pixel, and stride is exactly |
| 3291 | * width * 4. |
| 3292 | * |
| 3293 | * Parameters src_x and src_y define the upper-left corner in buffer |
| 3294 | * coordinates (pixels) to copy from. Parameters width and height |
| 3295 | * define the size of the area to copy in pixels. |
| 3296 | * |
| 3297 | * The rectangle defined by src_x, src_y, width, height must fit in |
| 3298 | * the surface contents. Otherwise an error is returned. |
| 3299 | * |
| 3300 | * Use surface_get_data_size to determine the content size; the |
| 3301 | * needed target buffer size and rectangle limits. |
| 3302 | * |
| 3303 | * CURRENT IMPLEMENTATION RESTRICTIONS: |
| 3304 | * - the machine must be little-endian due to Pixman formats. |
| 3305 | * |
| 3306 | * NOTE: Pixman formats are premultiplied. |
| 3307 | */ |
| 3308 | WL_EXPORT int |
| 3309 | weston_surface_copy_content(struct weston_surface *surface, |
| 3310 | void *target, size_t size, |
| 3311 | int src_x, int src_y, |
| 3312 | int width, int height) |
| 3313 | { |
| 3314 | struct weston_renderer *rer = surface->compositor->renderer; |
| 3315 | int cw, ch; |
| 3316 | const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */ |
| 3317 | |
| 3318 | if (!rer->surface_copy_content) |
| 3319 | return -1; |
| 3320 | |
| 3321 | weston_surface_get_content_size(surface, &cw, &ch); |
| 3322 | |
| 3323 | if (src_x < 0 || src_y < 0) |
| 3324 | return -1; |
| 3325 | |
| 3326 | if (width <= 0 || height <= 0) |
| 3327 | return -1; |
| 3328 | |
| 3329 | if (src_x + width > cw || src_y + height > ch) |
| 3330 | return -1; |
| 3331 | |
| 3332 | if (width * bytespp * height > size) |
| 3333 | return -1; |
| 3334 | |
| 3335 | return rer->surface_copy_content(surface, target, size, |
| 3336 | src_x, src_y, width, height); |
| 3337 | } |
| 3338 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3339 | static void |
| 3340 | subsurface_set_position(struct wl_client *client, |
| 3341 | struct wl_resource *resource, int32_t x, int32_t y) |
| 3342 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 3343 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3344 | |
| 3345 | if (!sub) |
| 3346 | return; |
| 3347 | |
| 3348 | sub->position.x = x; |
| 3349 | sub->position.y = y; |
| 3350 | sub->position.set = 1; |
| 3351 | } |
| 3352 | |
| 3353 | static struct weston_subsurface * |
| 3354 | subsurface_from_surface(struct weston_surface *surface) |
| 3355 | { |
| 3356 | struct weston_subsurface *sub; |
| 3357 | |
| 3358 | sub = weston_surface_to_subsurface(surface); |
| 3359 | if (sub) |
| 3360 | return sub; |
| 3361 | |
| 3362 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) |
| 3363 | if (sub->surface == surface) |
| 3364 | return sub; |
| 3365 | |
| 3366 | return NULL; |
| 3367 | } |
| 3368 | |
| 3369 | static struct weston_subsurface * |
| 3370 | subsurface_sibling_check(struct weston_subsurface *sub, |
| 3371 | struct weston_surface *surface, |
| 3372 | const char *request) |
| 3373 | { |
| 3374 | struct weston_subsurface *sibling; |
| 3375 | |
| 3376 | sibling = subsurface_from_surface(surface); |
| 3377 | |
| 3378 | if (!sibling) { |
| 3379 | wl_resource_post_error(sub->resource, |
| 3380 | WL_SUBSURFACE_ERROR_BAD_SURFACE, |
| 3381 | "%s: wl_surface@%d is not a parent or sibling", |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3382 | request, wl_resource_get_id(surface->resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3383 | return NULL; |
| 3384 | } |
| 3385 | |
| 3386 | if (sibling->parent != sub->parent) { |
| 3387 | wl_resource_post_error(sub->resource, |
| 3388 | WL_SUBSURFACE_ERROR_BAD_SURFACE, |
| 3389 | "%s: wl_surface@%d has a different parent", |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3390 | request, wl_resource_get_id(surface->resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3391 | return NULL; |
| 3392 | } |
| 3393 | |
| 3394 | return sibling; |
| 3395 | } |
| 3396 | |
| 3397 | static void |
| 3398 | subsurface_place_above(struct wl_client *client, |
| 3399 | struct wl_resource *resource, |
| 3400 | struct wl_resource *sibling_resource) |
| 3401 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 3402 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3403 | struct weston_surface *surface = |
| 3404 | wl_resource_get_user_data(sibling_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3405 | struct weston_subsurface *sibling; |
| 3406 | |
| 3407 | if (!sub) |
| 3408 | return; |
| 3409 | |
| 3410 | sibling = subsurface_sibling_check(sub, surface, "place_above"); |
| 3411 | if (!sibling) |
| 3412 | return; |
| 3413 | |
| 3414 | wl_list_remove(&sub->parent_link_pending); |
| 3415 | wl_list_insert(sibling->parent_link_pending.prev, |
| 3416 | &sub->parent_link_pending); |
| 3417 | } |
| 3418 | |
| 3419 | static void |
| 3420 | subsurface_place_below(struct wl_client *client, |
| 3421 | struct wl_resource *resource, |
| 3422 | struct wl_resource *sibling_resource) |
| 3423 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 3424 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3425 | struct weston_surface *surface = |
| 3426 | wl_resource_get_user_data(sibling_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3427 | struct weston_subsurface *sibling; |
| 3428 | |
| 3429 | if (!sub) |
| 3430 | return; |
| 3431 | |
| 3432 | sibling = subsurface_sibling_check(sub, surface, "place_below"); |
| 3433 | if (!sibling) |
| 3434 | return; |
| 3435 | |
| 3436 | wl_list_remove(&sub->parent_link_pending); |
| 3437 | wl_list_insert(&sibling->parent_link_pending, |
| 3438 | &sub->parent_link_pending); |
| 3439 | } |
| 3440 | |
| 3441 | static void |
| 3442 | subsurface_set_sync(struct wl_client *client, struct wl_resource *resource) |
| 3443 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 3444 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3445 | |
| 3446 | if (sub) |
| 3447 | sub->synchronized = 1; |
| 3448 | } |
| 3449 | |
| 3450 | static void |
| 3451 | subsurface_set_desync(struct wl_client *client, struct wl_resource *resource) |
| 3452 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 3453 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3454 | |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3455 | if (sub && sub->synchronized) { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3456 | sub->synchronized = 0; |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3457 | |
| 3458 | /* If sub became effectively desynchronized, flush. */ |
| 3459 | if (!weston_subsurface_is_synchronized(sub)) |
| 3460 | weston_subsurface_synchronized_commit(sub); |
| 3461 | } |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3462 | } |
| 3463 | |
| 3464 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3465 | weston_subsurface_unlink_parent(struct weston_subsurface *sub) |
| 3466 | { |
| 3467 | wl_list_remove(&sub->parent_link); |
| 3468 | wl_list_remove(&sub->parent_link_pending); |
| 3469 | wl_list_remove(&sub->parent_destroy_listener.link); |
| 3470 | sub->parent = NULL; |
| 3471 | } |
| 3472 | |
| 3473 | static void |
| 3474 | weston_subsurface_destroy(struct weston_subsurface *sub); |
| 3475 | |
| 3476 | static void |
| 3477 | subsurface_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 3478 | { |
| 3479 | struct weston_subsurface *sub = |
| 3480 | container_of(listener, struct weston_subsurface, |
| 3481 | surface_destroy_listener); |
| 3482 | assert(data == &sub->surface->resource); |
| 3483 | |
| 3484 | /* The protocol object (wl_resource) is left inert. */ |
| 3485 | if (sub->resource) |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 3486 | wl_resource_set_user_data(sub->resource, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3487 | |
| 3488 | weston_subsurface_destroy(sub); |
| 3489 | } |
| 3490 | |
| 3491 | static void |
| 3492 | subsurface_handle_parent_destroy(struct wl_listener *listener, void *data) |
| 3493 | { |
| 3494 | struct weston_subsurface *sub = |
| 3495 | container_of(listener, struct weston_subsurface, |
| 3496 | parent_destroy_listener); |
| 3497 | assert(data == &sub->parent->resource); |
| 3498 | assert(sub->surface != sub->parent); |
| 3499 | |
| 3500 | if (weston_surface_is_mapped(sub->surface)) |
| 3501 | weston_surface_unmap(sub->surface); |
| 3502 | |
| 3503 | weston_subsurface_unlink_parent(sub); |
| 3504 | } |
| 3505 | |
| 3506 | static void |
| 3507 | subsurface_resource_destroy(struct wl_resource *resource) |
| 3508 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 3509 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3510 | |
| 3511 | if (sub) |
| 3512 | weston_subsurface_destroy(sub); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3513 | } |
| 3514 | |
| 3515 | static void |
| 3516 | subsurface_destroy(struct wl_client *client, struct wl_resource *resource) |
| 3517 | { |
| 3518 | wl_resource_destroy(resource); |
| 3519 | } |
| 3520 | |
| 3521 | static void |
| 3522 | weston_subsurface_link_parent(struct weston_subsurface *sub, |
| 3523 | struct weston_surface *parent) |
| 3524 | { |
| 3525 | sub->parent = parent; |
| 3526 | sub->parent_destroy_listener.notify = subsurface_handle_parent_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3527 | wl_signal_add(&parent->destroy_signal, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3528 | &sub->parent_destroy_listener); |
| 3529 | |
| 3530 | wl_list_insert(&parent->subsurface_list, &sub->parent_link); |
| 3531 | wl_list_insert(&parent->subsurface_list_pending, |
| 3532 | &sub->parent_link_pending); |
| 3533 | } |
| 3534 | |
| 3535 | static void |
| 3536 | weston_subsurface_link_surface(struct weston_subsurface *sub, |
| 3537 | struct weston_surface *surface) |
| 3538 | { |
| 3539 | sub->surface = surface; |
| 3540 | sub->surface_destroy_listener.notify = |
| 3541 | subsurface_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3542 | wl_signal_add(&surface->destroy_signal, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3543 | &sub->surface_destroy_listener); |
| 3544 | } |
| 3545 | |
| 3546 | static void |
| 3547 | weston_subsurface_destroy(struct weston_subsurface *sub) |
| 3548 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3549 | struct weston_view *view, *next; |
| 3550 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3551 | assert(sub->surface); |
| 3552 | |
| 3553 | if (sub->resource) { |
| 3554 | assert(weston_surface_to_subsurface(sub->surface) == sub); |
| 3555 | assert(sub->parent_destroy_listener.notify == |
| 3556 | subsurface_handle_parent_destroy); |
| 3557 | |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 3558 | wl_list_for_each_safe(view, next, &sub->surface->views, surface_link) { |
| 3559 | weston_view_unmap(view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3560 | weston_view_destroy(view); |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 3561 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3562 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3563 | if (sub->parent) |
| 3564 | weston_subsurface_unlink_parent(sub); |
| 3565 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3566 | weston_surface_state_fini(&sub->cached); |
| 3567 | weston_buffer_reference(&sub->cached_buffer_ref, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3568 | |
| 3569 | sub->surface->configure = NULL; |
| 3570 | sub->surface->configure_private = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3571 | weston_surface_set_label_func(sub->surface, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3572 | } else { |
| 3573 | /* the dummy weston_subsurface for the parent itself */ |
| 3574 | assert(sub->parent_destroy_listener.notify == NULL); |
| 3575 | wl_list_remove(&sub->parent_link); |
| 3576 | wl_list_remove(&sub->parent_link_pending); |
| 3577 | } |
| 3578 | |
| 3579 | wl_list_remove(&sub->surface_destroy_listener.link); |
| 3580 | free(sub); |
| 3581 | } |
| 3582 | |
| 3583 | static const struct wl_subsurface_interface subsurface_implementation = { |
| 3584 | subsurface_destroy, |
| 3585 | subsurface_set_position, |
| 3586 | subsurface_place_above, |
| 3587 | subsurface_place_below, |
| 3588 | subsurface_set_sync, |
| 3589 | subsurface_set_desync |
| 3590 | }; |
| 3591 | |
| 3592 | static struct weston_subsurface * |
| 3593 | weston_subsurface_create(uint32_t id, struct weston_surface *surface, |
| 3594 | struct weston_surface *parent) |
| 3595 | { |
| 3596 | struct weston_subsurface *sub; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3597 | struct wl_client *client = wl_resource_get_client(surface->resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3598 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 3599 | sub = zalloc(sizeof *sub); |
| 3600 | if (sub == NULL) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3601 | return NULL; |
| 3602 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3603 | wl_list_init(&sub->unused_views); |
| 3604 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3605 | sub->resource = |
| 3606 | wl_resource_create(client, &wl_subsurface_interface, 1, id); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3607 | if (!sub->resource) { |
| 3608 | free(sub); |
| 3609 | return NULL; |
| 3610 | } |
| 3611 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3612 | wl_resource_set_implementation(sub->resource, |
| 3613 | &subsurface_implementation, |
| 3614 | sub, subsurface_resource_destroy); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3615 | weston_subsurface_link_surface(sub, surface); |
| 3616 | weston_subsurface_link_parent(sub, parent); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3617 | weston_surface_state_init(&sub->cached); |
| 3618 | sub->cached_buffer_ref.buffer = NULL; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3619 | sub->synchronized = 1; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3620 | |
| 3621 | return sub; |
| 3622 | } |
| 3623 | |
| 3624 | /* Create a dummy subsurface for having the parent itself in its |
| 3625 | * sub-surface lists. Makes stacking order manipulation easy. |
| 3626 | */ |
| 3627 | static struct weston_subsurface * |
| 3628 | weston_subsurface_create_for_parent(struct weston_surface *parent) |
| 3629 | { |
| 3630 | struct weston_subsurface *sub; |
| 3631 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 3632 | sub = zalloc(sizeof *sub); |
| 3633 | if (sub == NULL) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3634 | return NULL; |
| 3635 | |
| 3636 | weston_subsurface_link_surface(sub, parent); |
| 3637 | sub->parent = parent; |
| 3638 | wl_list_insert(&parent->subsurface_list, &sub->parent_link); |
| 3639 | wl_list_insert(&parent->subsurface_list_pending, |
| 3640 | &sub->parent_link_pending); |
| 3641 | |
| 3642 | return sub; |
| 3643 | } |
| 3644 | |
| 3645 | static void |
| 3646 | subcompositor_get_subsurface(struct wl_client *client, |
| 3647 | struct wl_resource *resource, |
| 3648 | uint32_t id, |
| 3649 | struct wl_resource *surface_resource, |
| 3650 | struct wl_resource *parent_resource) |
| 3651 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3652 | struct weston_surface *surface = |
| 3653 | wl_resource_get_user_data(surface_resource); |
| 3654 | struct weston_surface *parent = |
| 3655 | wl_resource_get_user_data(parent_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3656 | struct weston_subsurface *sub; |
| 3657 | static const char where[] = "get_subsurface: wl_subsurface@"; |
| 3658 | |
| 3659 | if (surface == parent) { |
| 3660 | wl_resource_post_error(resource, |
| 3661 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 3662 | "%s%d: wl_surface@%d cannot be its own parent", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 3663 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3664 | return; |
| 3665 | } |
| 3666 | |
| 3667 | if (weston_surface_to_subsurface(surface)) { |
| 3668 | wl_resource_post_error(resource, |
| 3669 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 3670 | "%s%d: wl_surface@%d is already a sub-surface", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 3671 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3672 | return; |
| 3673 | } |
| 3674 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3675 | if (weston_surface_set_role(surface, "wl_subsurface", resource, |
| 3676 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE) < 0) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3677 | return; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3678 | |
Pekka Paalanen | 86c8ca0 | 2013-05-17 16:46:07 +0300 | [diff] [blame] | 3679 | if (weston_surface_get_main_surface(parent) == surface) { |
| 3680 | wl_resource_post_error(resource, |
| 3681 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 3682 | "%s%d: wl_surface@%d is an ancestor of parent", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 3683 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | 86c8ca0 | 2013-05-17 16:46:07 +0300 | [diff] [blame] | 3684 | return; |
| 3685 | } |
| 3686 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3687 | /* make sure the parent is in its own list */ |
| 3688 | if (wl_list_empty(&parent->subsurface_list)) { |
| 3689 | if (!weston_subsurface_create_for_parent(parent)) { |
| 3690 | wl_resource_post_no_memory(resource); |
| 3691 | return; |
| 3692 | } |
| 3693 | } |
| 3694 | |
| 3695 | sub = weston_subsurface_create(id, surface, parent); |
| 3696 | if (!sub) { |
| 3697 | wl_resource_post_no_memory(resource); |
| 3698 | return; |
| 3699 | } |
| 3700 | |
| 3701 | surface->configure = subsurface_configure; |
| 3702 | surface->configure_private = sub; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3703 | weston_surface_set_label_func(surface, subsurface_get_label); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3704 | } |
| 3705 | |
| 3706 | static void |
| 3707 | subcompositor_destroy(struct wl_client *client, struct wl_resource *resource) |
| 3708 | { |
| 3709 | wl_resource_destroy(resource); |
| 3710 | } |
| 3711 | |
| 3712 | static const struct wl_subcompositor_interface subcompositor_interface = { |
| 3713 | subcompositor_destroy, |
| 3714 | subcompositor_get_subsurface |
| 3715 | }; |
| 3716 | |
| 3717 | static void |
| 3718 | bind_subcompositor(struct wl_client *client, |
| 3719 | void *data, uint32_t version, uint32_t id) |
| 3720 | { |
| 3721 | struct weston_compositor *compositor = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3722 | struct wl_resource *resource; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3723 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3724 | resource = |
| 3725 | wl_resource_create(client, &wl_subcompositor_interface, 1, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 3726 | if (resource == NULL) { |
| 3727 | wl_client_post_no_memory(client); |
| 3728 | return; |
| 3729 | } |
| 3730 | wl_resource_set_implementation(resource, &subcompositor_interface, |
| 3731 | compositor, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3732 | } |
| 3733 | |
| 3734 | static void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3735 | weston_compositor_dpms(struct weston_compositor *compositor, |
| 3736 | enum dpms_enum state) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3737 | { |
| 3738 | struct weston_output *output; |
| 3739 | |
| 3740 | wl_list_for_each(output, &compositor->output_list, link) |
| 3741 | if (output->set_dpms) |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3742 | output->set_dpms(output, state); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3743 | } |
| 3744 | |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3745 | WL_EXPORT void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3746 | weston_compositor_wake(struct weston_compositor *compositor) |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3747 | { |
Neil Roberts | 8b62e20 | 2013-09-30 13:14:47 +0100 | [diff] [blame] | 3748 | uint32_t old_state = compositor->state; |
| 3749 | |
| 3750 | /* The state needs to be changed before emitting the wake |
| 3751 | * signal because that may try to schedule a repaint which |
| 3752 | * will not work if the compositor is still sleeping */ |
| 3753 | compositor->state = WESTON_COMPOSITOR_ACTIVE; |
| 3754 | |
| 3755 | switch (old_state) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3756 | case WESTON_COMPOSITOR_SLEEPING: |
| 3757 | weston_compositor_dpms(compositor, WESTON_DPMS_ON); |
| 3758 | /* fall through */ |
| 3759 | case WESTON_COMPOSITOR_IDLE: |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 3760 | case WESTON_COMPOSITOR_OFFSCREEN: |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 3761 | wl_signal_emit(&compositor->wake_signal, compositor); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3762 | /* fall through */ |
| 3763 | default: |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3764 | wl_event_source_timer_update(compositor->idle_source, |
| 3765 | compositor->idle_time * 1000); |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 3766 | } |
| 3767 | } |
| 3768 | |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3769 | WL_EXPORT void |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 3770 | weston_compositor_offscreen(struct weston_compositor *compositor) |
| 3771 | { |
| 3772 | switch (compositor->state) { |
| 3773 | case WESTON_COMPOSITOR_OFFSCREEN: |
| 3774 | return; |
| 3775 | case WESTON_COMPOSITOR_SLEEPING: |
| 3776 | weston_compositor_dpms(compositor, WESTON_DPMS_ON); |
| 3777 | /* fall through */ |
| 3778 | default: |
| 3779 | compositor->state = WESTON_COMPOSITOR_OFFSCREEN; |
| 3780 | wl_event_source_timer_update(compositor->idle_source, 0); |
| 3781 | } |
| 3782 | } |
| 3783 | |
| 3784 | WL_EXPORT void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3785 | weston_compositor_sleep(struct weston_compositor *compositor) |
| 3786 | { |
| 3787 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING) |
| 3788 | return; |
| 3789 | |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 3790 | wl_event_source_timer_update(compositor->idle_source, 0); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 3791 | compositor->state = WESTON_COMPOSITOR_SLEEPING; |
| 3792 | weston_compositor_dpms(compositor, WESTON_DPMS_OFF); |
| 3793 | } |
| 3794 | |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 3795 | static int |
| 3796 | idle_handler(void *data) |
| 3797 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3798 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 3799 | |
| 3800 | if (compositor->idle_inhibit) |
| 3801 | return 1; |
| 3802 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 3803 | compositor->state = WESTON_COMPOSITOR_IDLE; |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 3804 | wl_signal_emit(&compositor->idle_signal, compositor); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 3805 | |
| 3806 | return 1; |
| 3807 | } |
| 3808 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 3809 | WL_EXPORT void |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 3810 | weston_plane_init(struct weston_plane *plane, |
| 3811 | struct weston_compositor *ec, |
| 3812 | int32_t x, int32_t y) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 3813 | { |
| 3814 | pixman_region32_init(&plane->damage); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 3815 | pixman_region32_init(&plane->clip); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 3816 | plane->x = x; |
| 3817 | plane->y = y; |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 3818 | plane->compositor = ec; |
Ander Conselvan de Oliveira | 3c36bf3 | 2013-07-05 16:05:26 +0300 | [diff] [blame] | 3819 | |
| 3820 | /* Init the link so that the call to wl_list_remove() when releasing |
| 3821 | * the plane without ever stacking doesn't lead to a crash */ |
| 3822 | wl_list_init(&plane->link); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 3823 | } |
| 3824 | |
| 3825 | WL_EXPORT void |
| 3826 | weston_plane_release(struct weston_plane *plane) |
| 3827 | { |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 3828 | struct weston_view *view; |
| 3829 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 3830 | pixman_region32_fini(&plane->damage); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 3831 | pixman_region32_fini(&plane->clip); |
Ander Conselvan de Oliveira | 3c36bf3 | 2013-07-05 16:05:26 +0300 | [diff] [blame] | 3832 | |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 3833 | wl_list_for_each(view, &plane->compositor->view_list, link) { |
| 3834 | if (view->plane == plane) |
| 3835 | view->plane = NULL; |
| 3836 | } |
| 3837 | |
Ander Conselvan de Oliveira | 3c36bf3 | 2013-07-05 16:05:26 +0300 | [diff] [blame] | 3838 | wl_list_remove(&plane->link); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 3839 | } |
| 3840 | |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 3841 | WL_EXPORT void |
| 3842 | weston_compositor_stack_plane(struct weston_compositor *ec, |
| 3843 | struct weston_plane *plane, |
| 3844 | struct weston_plane *above) |
| 3845 | { |
| 3846 | if (above) |
| 3847 | wl_list_insert(above->link.prev, &plane->link); |
| 3848 | else |
| 3849 | wl_list_insert(&ec->plane_list, &plane->link); |
| 3850 | } |
| 3851 | |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 3852 | static void unbind_resource(struct wl_resource *resource) |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 3853 | { |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3854 | wl_list_remove(wl_resource_get_link(resource)); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 3855 | } |
| 3856 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 3857 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 3858 | bind_output(struct wl_client *client, |
| 3859 | void *data, uint32_t version, uint32_t id) |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 3860 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3861 | struct weston_output *output = data; |
| 3862 | struct weston_mode *mode; |
Kristian Høgsberg | fd07fb7 | 2011-08-29 15:03:09 -0400 | [diff] [blame] | 3863 | struct wl_resource *resource; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 3864 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3865 | resource = wl_resource_create(client, &wl_output_interface, |
| 3866 | MIN(version, 2), id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 3867 | if (resource == NULL) { |
| 3868 | wl_client_post_no_memory(client); |
| 3869 | return; |
| 3870 | } |
Kristian Høgsberg | fd07fb7 | 2011-08-29 15:03:09 -0400 | [diff] [blame] | 3871 | |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 3872 | wl_list_insert(&output->resource_list, wl_resource_get_link(resource)); |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3873 | wl_resource_set_implementation(resource, NULL, data, unbind_resource); |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 3874 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3875 | wl_output_send_geometry(resource, |
| 3876 | output->x, |
| 3877 | output->y, |
| 3878 | output->mm_width, |
| 3879 | output->mm_height, |
| 3880 | output->subpixel, |
Kristian Høgsberg | 0e69647 | 2012-07-22 15:49:57 -0400 | [diff] [blame] | 3881 | output->make, output->model, |
Kristian Høgsberg | 05890dc | 2012-08-10 10:09:20 -0400 | [diff] [blame] | 3882 | output->transform); |
Jasper St. Pierre | 0013a29 | 2014-08-07 16:43:11 -0400 | [diff] [blame] | 3883 | if (version >= WL_OUTPUT_SCALE_SINCE_VERSION) |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3884 | wl_output_send_scale(resource, |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 3885 | output->current_scale); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 3886 | |
| 3887 | wl_list_for_each (mode, &output->mode_list, link) { |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 3888 | wl_output_send_mode(resource, |
| 3889 | mode->flags, |
| 3890 | mode->width, |
| 3891 | mode->height, |
| 3892 | mode->refresh); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 3893 | } |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3894 | |
Jasper St. Pierre | 0013a29 | 2014-08-07 16:43:11 -0400 | [diff] [blame] | 3895 | if (version >= WL_OUTPUT_DONE_SINCE_VERSION) |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3896 | wl_output_send_done(resource); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 3897 | } |
| 3898 | |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 3899 | /* Move other outputs when one is removed so the space remains contiguos. */ |
| 3900 | static void |
| 3901 | weston_compositor_remove_output(struct weston_compositor *compositor, |
| 3902 | struct weston_output *remove_output) |
| 3903 | { |
| 3904 | struct weston_output *output; |
| 3905 | int offset = 0; |
| 3906 | |
| 3907 | wl_list_for_each(output, &compositor->output_list, link) { |
| 3908 | if (output == remove_output) { |
| 3909 | offset = output->width; |
| 3910 | continue; |
| 3911 | } |
| 3912 | |
| 3913 | if (offset > 0) { |
| 3914 | weston_output_move(output, |
| 3915 | output->x - offset, output->y); |
| 3916 | output->dirty = 1; |
| 3917 | } |
| 3918 | } |
| 3919 | } |
| 3920 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3921 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3922 | weston_output_destroy(struct weston_output *output) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 3923 | { |
Giulio Camuffo | 00535ce | 2014-09-06 16:18:02 +0300 | [diff] [blame] | 3924 | struct wl_resource *resource; |
| 3925 | |
Ander Conselvan de Oliveira | e1e2352 | 2013-12-13 22:10:55 +0200 | [diff] [blame] | 3926 | output->destroying = 1; |
| 3927 | |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 3928 | wl_event_source_remove(output->repaint_timer); |
| 3929 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3930 | weston_presentation_feedback_discard_list(&output->feedback_list); |
| 3931 | |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 3932 | weston_compositor_remove_output(output->compositor, output); |
Ander Conselvan de Oliveira | f749fc3 | 2013-12-13 22:10:50 +0200 | [diff] [blame] | 3933 | wl_list_remove(&output->link); |
| 3934 | |
Ander Conselvan de Oliveira | f84327a | 2014-01-29 18:47:51 +0200 | [diff] [blame] | 3935 | wl_signal_emit(&output->compositor->output_destroyed_signal, output); |
Richard Hughes | 64ddde1 | 2013-05-01 21:52:10 +0100 | [diff] [blame] | 3936 | wl_signal_emit(&output->destroy_signal, output); |
| 3937 | |
Richard Hughes | afe690c | 2013-05-02 10:10:04 +0100 | [diff] [blame] | 3938 | free(output->name); |
Kristian Høgsberg | e75cb7f | 2011-06-21 15:27:41 -0400 | [diff] [blame] | 3939 | pixman_region32_fini(&output->region); |
Ander Conselvan de Oliveira | b8fcca9 | 2012-11-16 17:23:52 +0200 | [diff] [blame] | 3940 | pixman_region32_fini(&output->previous_damage); |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 3941 | output->compositor->output_id_pool &= ~(1 << output->id); |
Benjamin Franzke | b687940 | 2012-04-10 18:28:54 +0200 | [diff] [blame] | 3942 | |
Giulio Camuffo | 00535ce | 2014-09-06 16:18:02 +0300 | [diff] [blame] | 3943 | wl_resource_for_each(resource, &output->resource_list) { |
| 3944 | wl_resource_set_destructor(resource, NULL); |
| 3945 | } |
| 3946 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 3947 | wl_global_destroy(output->global); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 3948 | } |
| 3949 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 3950 | WL_EXPORT void |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3951 | weston_output_update_matrix(struct weston_output *output) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 3952 | { |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 3953 | float magnification; |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 3954 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3955 | weston_matrix_init(&output->matrix); |
Jason Ekstrand | fb23df7 | 2014-10-16 10:55:21 -0500 | [diff] [blame] | 3956 | weston_matrix_translate(&output->matrix, -output->x, -output->y, 0); |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 3957 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3958 | if (output->zoom.active) { |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 3959 | magnification = 1 / (1 - output->zoom.spring_z.current); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3960 | weston_output_update_zoom(output); |
Neil Roberts | 1e40a7e | 2014-04-25 13:19:37 +0100 | [diff] [blame] | 3961 | weston_matrix_translate(&output->matrix, -output->zoom.trans_x, |
Jason Ekstrand | fb23df7 | 2014-10-16 10:55:21 -0500 | [diff] [blame] | 3962 | -output->zoom.trans_y, 0); |
Neil Roberts | 1e40a7e | 2014-04-25 13:19:37 +0100 | [diff] [blame] | 3963 | weston_matrix_scale(&output->matrix, magnification, |
| 3964 | magnification, 1.0); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 3965 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 3966 | |
Jason Ekstrand | fb23df7 | 2014-10-16 10:55:21 -0500 | [diff] [blame] | 3967 | switch (output->transform) { |
| 3968 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 3969 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 3970 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 3971 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 3972 | weston_matrix_translate(&output->matrix, -output->width, 0, 0); |
| 3973 | weston_matrix_scale(&output->matrix, -1, 1, 1); |
| 3974 | break; |
| 3975 | } |
| 3976 | |
| 3977 | switch (output->transform) { |
| 3978 | default: |
| 3979 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 3980 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 3981 | break; |
| 3982 | case WL_OUTPUT_TRANSFORM_90: |
| 3983 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 3984 | weston_matrix_translate(&output->matrix, 0, -output->height, 0); |
| 3985 | weston_matrix_rotate_xy(&output->matrix, 0, 1); |
| 3986 | break; |
| 3987 | case WL_OUTPUT_TRANSFORM_180: |
| 3988 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 3989 | weston_matrix_translate(&output->matrix, |
| 3990 | -output->width, -output->height, 0); |
| 3991 | weston_matrix_rotate_xy(&output->matrix, -1, 0); |
| 3992 | break; |
| 3993 | case WL_OUTPUT_TRANSFORM_270: |
| 3994 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 3995 | weston_matrix_translate(&output->matrix, -output->width, 0, 0); |
| 3996 | weston_matrix_rotate_xy(&output->matrix, 0, -1); |
| 3997 | break; |
| 3998 | } |
| 3999 | |
| 4000 | if (output->current_scale != 1) |
| 4001 | weston_matrix_scale(&output->matrix, |
| 4002 | output->current_scale, |
| 4003 | output->current_scale, 1); |
Neil Roberts | 6c3b01f | 2014-05-06 19:04:15 +0100 | [diff] [blame] | 4004 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4005 | output->dirty = 0; |
| 4006 | } |
| 4007 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4008 | static void |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 4009 | weston_output_transform_scale_init(struct weston_output *output, uint32_t transform, uint32_t scale) |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4010 | { |
| 4011 | output->transform = transform; |
| 4012 | |
| 4013 | switch (transform) { |
| 4014 | case WL_OUTPUT_TRANSFORM_90: |
| 4015 | case WL_OUTPUT_TRANSFORM_270: |
| 4016 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 4017 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 4018 | /* Swap width and height */ |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 4019 | output->width = output->current_mode->height; |
| 4020 | output->height = output->current_mode->width; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4021 | break; |
| 4022 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 4023 | case WL_OUTPUT_TRANSFORM_180: |
| 4024 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 4025 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 4026 | output->width = output->current_mode->width; |
| 4027 | output->height = output->current_mode->height; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4028 | break; |
| 4029 | default: |
| 4030 | break; |
| 4031 | } |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4032 | |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 4033 | output->native_scale = output->current_scale = scale; |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 4034 | output->width /= scale; |
| 4035 | output->height /= scale; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 4036 | } |
| 4037 | |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 4038 | static void |
| 4039 | weston_output_init_geometry(struct weston_output *output, int x, int y) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4040 | { |
| 4041 | output->x = x; |
| 4042 | output->y = y; |
| 4043 | |
Ander Conselvan de Oliveira | b8fcca9 | 2012-11-16 17:23:52 +0200 | [diff] [blame] | 4044 | pixman_region32_init(&output->previous_damage); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4045 | pixman_region32_init_rect(&output->region, x, y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4046 | output->width, |
| 4047 | output->height); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 4048 | } |
| 4049 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 4050 | WL_EXPORT void |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 4051 | weston_output_move(struct weston_output *output, int x, int y) |
| 4052 | { |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 4053 | struct wl_resource *resource; |
| 4054 | |
| 4055 | output->move_x = x - output->x; |
| 4056 | output->move_y = y - output->y; |
| 4057 | |
| 4058 | if (output->move_x == 0 && output->move_y == 0) |
| 4059 | return; |
| 4060 | |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 4061 | weston_output_init_geometry(output, x, y); |
| 4062 | |
| 4063 | output->dirty = 1; |
| 4064 | |
| 4065 | /* Move views on this output. */ |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4066 | wl_signal_emit(&output->compositor->output_moved_signal, output); |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 4067 | |
| 4068 | /* Notify clients of the change for output position. */ |
Quanxian Wang | b2c8636 | 2014-03-14 09:16:25 +0800 | [diff] [blame] | 4069 | wl_resource_for_each(resource, &output->resource_list) { |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 4070 | wl_output_send_geometry(resource, |
| 4071 | output->x, |
| 4072 | output->y, |
| 4073 | output->mm_width, |
| 4074 | output->mm_height, |
| 4075 | output->subpixel, |
| 4076 | output->make, |
| 4077 | output->model, |
| 4078 | output->transform); |
Quanxian Wang | b2c8636 | 2014-03-14 09:16:25 +0800 | [diff] [blame] | 4079 | |
| 4080 | if (wl_resource_get_version(resource) >= 2) |
| 4081 | wl_output_send_done(resource); |
| 4082 | } |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 4083 | } |
| 4084 | |
| 4085 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4086 | weston_output_init(struct weston_output *output, struct weston_compositor *c, |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 4087 | int x, int y, int mm_width, int mm_height, uint32_t transform, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 4088 | int32_t scale) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 4089 | { |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 4090 | struct wl_event_loop *loop; |
| 4091 | |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 4092 | output->compositor = c; |
| 4093 | output->x = x; |
| 4094 | output->y = y; |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 4095 | output->mm_width = mm_width; |
| 4096 | output->mm_height = mm_height; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4097 | output->dirty = 1; |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 4098 | output->original_scale = scale; |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4099 | |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 4100 | weston_output_transform_scale_init(output, transform, scale); |
Scott Moreau | 429490d | 2012-06-17 18:10:59 -0600 | [diff] [blame] | 4101 | weston_output_init_zoom(output); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 4102 | |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 4103 | weston_output_init_geometry(output, x, y); |
Benjamin Franzke | 78db848 | 2012-04-10 18:35:33 +0200 | [diff] [blame] | 4104 | weston_output_damage(output); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 4105 | |
Kristian Høgsberg | 5fb70bf | 2012-05-24 12:29:46 -0400 | [diff] [blame] | 4106 | wl_signal_init(&output->frame_signal); |
Richard Hughes | 64ddde1 | 2013-05-01 21:52:10 +0100 | [diff] [blame] | 4107 | wl_signal_init(&output->destroy_signal); |
Scott Moreau | 9d1b112 | 2012-06-08 19:40:53 -0600 | [diff] [blame] | 4108 | wl_list_init(&output->animation_list); |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 4109 | wl_list_init(&output->resource_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 4110 | wl_list_init(&output->feedback_list); |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 4111 | |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 4112 | loop = wl_display_get_event_loop(c->wl_display); |
| 4113 | output->repaint_timer = wl_event_loop_add_timer(loop, |
| 4114 | output_repaint_timer_handler, output); |
| 4115 | |
Casey Dahlin | 58ba137 | 2012-04-19 22:50:08 -0400 | [diff] [blame] | 4116 | output->id = ffs(~output->compositor->output_id_pool) - 1; |
| 4117 | output->compositor->output_id_pool |= 1 << output->id; |
| 4118 | |
Benjamin Franzke | b687940 | 2012-04-10 18:28:54 +0200 | [diff] [blame] | 4119 | output->global = |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 4120 | wl_global_create(c->wl_display, &wl_output_interface, 2, |
| 4121 | output, bind_output); |
Richard Hughes | 59d5da7 | 2013-05-01 21:52:11 +0100 | [diff] [blame] | 4122 | wl_signal_emit(&c->output_created_signal, output); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 4123 | } |
| 4124 | |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 4125 | WL_EXPORT void |
| 4126 | weston_output_transform_coordinate(struct weston_output *output, |
Jason Ekstrand | b6a3cc7 | 2013-10-27 22:25:00 -0500 | [diff] [blame] | 4127 | wl_fixed_t device_x, wl_fixed_t device_y, |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 4128 | wl_fixed_t *x, wl_fixed_t *y) |
| 4129 | { |
Derek Foreman | 0f67941 | 2014-10-02 13:41:17 -0500 | [diff] [blame] | 4130 | struct weston_vector p = { { |
| 4131 | wl_fixed_to_double(device_x), |
| 4132 | wl_fixed_to_double(device_y), |
| 4133 | 0.0, |
| 4134 | 1.0 } }; |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 4135 | |
Derek Foreman | 0f67941 | 2014-10-02 13:41:17 -0500 | [diff] [blame] | 4136 | weston_matrix_transform(&output->matrix, &p); |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 4137 | |
Derek Foreman | 0f67941 | 2014-10-02 13:41:17 -0500 | [diff] [blame] | 4138 | *x = wl_fixed_from_double(p.f[0] / p.f[3]); |
| 4139 | *y = wl_fixed_from_double(p.f[1] / p.f[3]); |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 4140 | } |
| 4141 | |
Benjamin Franzke | 315b3dc | 2011-03-08 11:32:57 +0100 | [diff] [blame] | 4142 | static void |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 4143 | destroy_viewport(struct wl_resource *resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 4144 | { |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 4145 | struct weston_surface *surface = |
| 4146 | wl_resource_get_user_data(resource); |
| 4147 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 4148 | surface->viewport_resource = NULL; |
Pekka Paalanen | f0cad48 | 2014-03-14 14:38:16 +0200 | [diff] [blame] | 4149 | surface->pending.buffer_viewport.buffer.src_width = |
| 4150 | wl_fixed_from_int(-1); |
| 4151 | surface->pending.buffer_viewport.surface.width = -1; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 4152 | surface->pending.buffer_viewport.changed = 1; |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 4153 | } |
| 4154 | |
| 4155 | static void |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 4156 | viewport_destroy(struct wl_client *client, |
| 4157 | struct wl_resource *resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 4158 | { |
| 4159 | wl_resource_destroy(resource); |
| 4160 | } |
| 4161 | |
| 4162 | static void |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 4163 | viewport_set(struct wl_client *client, |
| 4164 | struct wl_resource *resource, |
| 4165 | wl_fixed_t src_x, |
| 4166 | wl_fixed_t src_y, |
| 4167 | wl_fixed_t src_width, |
| 4168 | wl_fixed_t src_height, |
| 4169 | int32_t dst_width, |
| 4170 | int32_t dst_height) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 4171 | { |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 4172 | struct weston_surface *surface = |
| 4173 | wl_resource_get_user_data(resource); |
| 4174 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 4175 | assert(surface->viewport_resource != NULL); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 4176 | |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 4177 | if (wl_fixed_to_double(src_width) < 0 || |
| 4178 | wl_fixed_to_double(src_height) < 0) { |
| 4179 | wl_resource_post_error(resource, |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 4180 | WL_VIEWPORT_ERROR_BAD_VALUE, |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 4181 | "source dimensions must be non-negative (%fx%f)", |
| 4182 | wl_fixed_to_double(src_width), |
| 4183 | wl_fixed_to_double(src_height)); |
| 4184 | return; |
| 4185 | } |
| 4186 | |
| 4187 | if (dst_width <= 0 || dst_height <= 0) { |
| 4188 | wl_resource_post_error(resource, |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 4189 | WL_VIEWPORT_ERROR_BAD_VALUE, |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 4190 | "destination dimensions must be positive (%dx%d)", |
| 4191 | dst_width, dst_height); |
| 4192 | return; |
| 4193 | } |
| 4194 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 4195 | surface->pending.buffer_viewport.buffer.src_x = src_x; |
| 4196 | surface->pending.buffer_viewport.buffer.src_y = src_y; |
| 4197 | surface->pending.buffer_viewport.buffer.src_width = src_width; |
| 4198 | surface->pending.buffer_viewport.buffer.src_height = src_height; |
| 4199 | surface->pending.buffer_viewport.surface.width = dst_width; |
| 4200 | surface->pending.buffer_viewport.surface.height = dst_height; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 4201 | surface->pending.buffer_viewport.changed = 1; |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 4202 | } |
| 4203 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 4204 | static void |
| 4205 | viewport_set_source(struct wl_client *client, |
| 4206 | struct wl_resource *resource, |
| 4207 | wl_fixed_t src_x, |
| 4208 | wl_fixed_t src_y, |
| 4209 | wl_fixed_t src_width, |
| 4210 | wl_fixed_t src_height) |
| 4211 | { |
| 4212 | struct weston_surface *surface = |
| 4213 | wl_resource_get_user_data(resource); |
| 4214 | |
| 4215 | assert(surface->viewport_resource != NULL); |
| 4216 | |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 4217 | if (src_width == wl_fixed_from_int(-1) && |
| 4218 | src_height == wl_fixed_from_int(-1)) { |
| 4219 | /* unset source size */ |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 4220 | surface->pending.buffer_viewport.buffer.src_width = |
| 4221 | wl_fixed_from_int(-1); |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 4222 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 4223 | return; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 4224 | } |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 4225 | |
| 4226 | if (src_width <= 0 || src_height <= 0) { |
| 4227 | wl_resource_post_error(resource, |
| 4228 | WL_VIEWPORT_ERROR_BAD_VALUE, |
| 4229 | "source size must be positive (%fx%f)", |
| 4230 | wl_fixed_to_double(src_width), |
| 4231 | wl_fixed_to_double(src_height)); |
| 4232 | return; |
| 4233 | } |
| 4234 | |
| 4235 | surface->pending.buffer_viewport.buffer.src_x = src_x; |
| 4236 | surface->pending.buffer_viewport.buffer.src_y = src_y; |
| 4237 | surface->pending.buffer_viewport.buffer.src_width = src_width; |
| 4238 | surface->pending.buffer_viewport.buffer.src_height = src_height; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 4239 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 4240 | } |
| 4241 | |
| 4242 | static void |
| 4243 | viewport_set_destination(struct wl_client *client, |
| 4244 | struct wl_resource *resource, |
| 4245 | int32_t dst_width, |
| 4246 | int32_t dst_height) |
| 4247 | { |
| 4248 | struct weston_surface *surface = |
| 4249 | wl_resource_get_user_data(resource); |
| 4250 | |
| 4251 | assert(surface->viewport_resource != NULL); |
| 4252 | |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 4253 | if (dst_width == -1 && dst_height == -1) { |
| 4254 | /* unset destination size */ |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 4255 | surface->pending.buffer_viewport.surface.width = -1; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 4256 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 4257 | return; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 4258 | } |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 4259 | |
| 4260 | if (dst_width <= 0 || dst_height <= 0) { |
| 4261 | wl_resource_post_error(resource, |
| 4262 | WL_VIEWPORT_ERROR_BAD_VALUE, |
| 4263 | "destination size must be positive (%dx%d)", |
| 4264 | dst_width, dst_height); |
| 4265 | return; |
| 4266 | } |
| 4267 | |
| 4268 | surface->pending.buffer_viewport.surface.width = dst_width; |
| 4269 | surface->pending.buffer_viewport.surface.height = dst_height; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 4270 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 4271 | } |
| 4272 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 4273 | static const struct wl_viewport_interface viewport_interface = { |
| 4274 | viewport_destroy, |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 4275 | viewport_set, |
| 4276 | viewport_set_source, |
| 4277 | viewport_set_destination |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 4278 | }; |
| 4279 | |
| 4280 | static void |
| 4281 | scaler_destroy(struct wl_client *client, |
| 4282 | struct wl_resource *resource) |
| 4283 | { |
| 4284 | wl_resource_destroy(resource); |
| 4285 | } |
| 4286 | |
| 4287 | static void |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 4288 | scaler_get_viewport(struct wl_client *client, |
| 4289 | struct wl_resource *scaler, |
| 4290 | uint32_t id, |
| 4291 | struct wl_resource *surface_resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 4292 | { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 4293 | int version = wl_resource_get_version(scaler); |
| 4294 | struct weston_surface *surface = |
| 4295 | wl_resource_get_user_data(surface_resource); |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 4296 | struct wl_resource *resource; |
| 4297 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 4298 | if (surface->viewport_resource) { |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 4299 | wl_resource_post_error(scaler, |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 4300 | WL_SCALER_ERROR_VIEWPORT_EXISTS, |
| 4301 | "a viewport for that surface already exists"); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 4302 | return; |
| 4303 | } |
| 4304 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 4305 | resource = wl_resource_create(client, &wl_viewport_interface, |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 4306 | version, id); |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 4307 | if (resource == NULL) { |
| 4308 | wl_client_post_no_memory(client); |
| 4309 | return; |
| 4310 | } |
| 4311 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 4312 | wl_resource_set_implementation(resource, &viewport_interface, |
| 4313 | surface, destroy_viewport); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 4314 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 4315 | surface->viewport_resource = resource; |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 4316 | } |
| 4317 | |
| 4318 | static const struct wl_scaler_interface scaler_interface = { |
| 4319 | scaler_destroy, |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 4320 | scaler_get_viewport |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 4321 | }; |
| 4322 | |
| 4323 | static void |
| 4324 | bind_scaler(struct wl_client *client, |
| 4325 | void *data, uint32_t version, uint32_t id) |
| 4326 | { |
| 4327 | struct wl_resource *resource; |
| 4328 | |
| 4329 | resource = wl_resource_create(client, &wl_scaler_interface, |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 4330 | MIN(version, 2), id); |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 4331 | if (resource == NULL) { |
| 4332 | wl_client_post_no_memory(client); |
| 4333 | return; |
| 4334 | } |
| 4335 | |
| 4336 | wl_resource_set_implementation(resource, &scaler_interface, |
| 4337 | NULL, NULL); |
| 4338 | } |
| 4339 | |
| 4340 | static void |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 4341 | destroy_presentation_feedback(struct wl_resource *feedback_resource) |
| 4342 | { |
| 4343 | struct weston_presentation_feedback *feedback; |
| 4344 | |
| 4345 | feedback = wl_resource_get_user_data(feedback_resource); |
| 4346 | |
| 4347 | wl_list_remove(&feedback->link); |
| 4348 | free(feedback); |
| 4349 | } |
| 4350 | |
| 4351 | static void |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 4352 | presentation_destroy(struct wl_client *client, struct wl_resource *resource) |
| 4353 | { |
| 4354 | wl_resource_destroy(resource); |
| 4355 | } |
| 4356 | |
| 4357 | static void |
| 4358 | presentation_feedback(struct wl_client *client, |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 4359 | struct wl_resource *presentation_resource, |
| 4360 | struct wl_resource *surface_resource, |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 4361 | uint32_t callback) |
| 4362 | { |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 4363 | struct weston_surface *surface; |
| 4364 | struct weston_presentation_feedback *feedback; |
| 4365 | |
| 4366 | surface = wl_resource_get_user_data(surface_resource); |
| 4367 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 4368 | feedback = zalloc(sizeof *feedback); |
| 4369 | if (feedback == NULL) |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 4370 | goto err_calloc; |
| 4371 | |
| 4372 | feedback->resource = wl_resource_create(client, |
| 4373 | &presentation_feedback_interface, |
| 4374 | 1, callback); |
| 4375 | if (!feedback->resource) |
| 4376 | goto err_create; |
| 4377 | |
| 4378 | wl_resource_set_implementation(feedback->resource, NULL, feedback, |
| 4379 | destroy_presentation_feedback); |
| 4380 | |
| 4381 | wl_list_insert(&surface->pending.feedback_list, &feedback->link); |
| 4382 | |
| 4383 | return; |
| 4384 | |
| 4385 | err_create: |
| 4386 | free(feedback); |
| 4387 | |
| 4388 | err_calloc: |
| 4389 | wl_client_post_no_memory(client); |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 4390 | } |
| 4391 | |
| 4392 | static const struct presentation_interface presentation_implementation = { |
| 4393 | presentation_destroy, |
| 4394 | presentation_feedback |
| 4395 | }; |
| 4396 | |
| 4397 | static void |
| 4398 | bind_presentation(struct wl_client *client, |
| 4399 | void *data, uint32_t version, uint32_t id) |
| 4400 | { |
| 4401 | struct weston_compositor *compositor = data; |
| 4402 | struct wl_resource *resource; |
| 4403 | |
| 4404 | resource = wl_resource_create(client, &presentation_interface, |
| 4405 | MIN(version, 1), id); |
| 4406 | if (resource == NULL) { |
| 4407 | wl_client_post_no_memory(client); |
| 4408 | return; |
| 4409 | } |
| 4410 | |
| 4411 | wl_resource_set_implementation(resource, &presentation_implementation, |
| 4412 | compositor, NULL); |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 4413 | presentation_send_clock_id(resource, compositor->presentation_clock); |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 4414 | } |
| 4415 | |
| 4416 | static void |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 4417 | compositor_bind(struct wl_client *client, |
| 4418 | void *data, uint32_t version, uint32_t id) |
| 4419 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4420 | struct weston_compositor *compositor = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4421 | struct wl_resource *resource; |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 4422 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4423 | resource = wl_resource_create(client, &wl_compositor_interface, |
| 4424 | MIN(version, 3), id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 4425 | if (resource == NULL) { |
| 4426 | wl_client_post_no_memory(client); |
| 4427 | return; |
| 4428 | } |
| 4429 | |
| 4430 | wl_resource_set_implementation(resource, &compositor_interface, |
| 4431 | compositor, NULL); |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 4432 | } |
| 4433 | |
Kristian Høgsberg | fc9c5e0 | 2012-06-08 16:45:33 -0400 | [diff] [blame] | 4434 | static void |
Martin Minarik | f12c287 | 2012-06-11 00:57:39 +0200 | [diff] [blame] | 4435 | log_uname(void) |
| 4436 | { |
| 4437 | struct utsname usys; |
| 4438 | |
| 4439 | uname(&usys); |
| 4440 | |
| 4441 | weston_log("OS: %s, %s, %s, %s\n", usys.sysname, usys.release, |
| 4442 | usys.version, usys.machine); |
| 4443 | } |
| 4444 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 4445 | WL_EXPORT int |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 4446 | weston_environment_get_fd(const char *env) |
| 4447 | { |
| 4448 | char *e, *end; |
| 4449 | int fd, flags; |
| 4450 | |
| 4451 | e = getenv(env); |
| 4452 | if (!e) |
| 4453 | return -1; |
| 4454 | fd = strtol(e, &end, 0); |
| 4455 | if (*end != '\0') |
| 4456 | return -1; |
| 4457 | |
| 4458 | flags = fcntl(fd, F_GETFD); |
| 4459 | if (flags == -1) |
| 4460 | return -1; |
| 4461 | |
| 4462 | fcntl(fd, F_SETFD, flags | FD_CLOEXEC); |
| 4463 | unsetenv(env); |
| 4464 | |
| 4465 | return fd; |
| 4466 | } |
| 4467 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 4468 | static void |
| 4469 | timeline_key_binding_handler(struct weston_seat *seat, uint32_t time, |
| 4470 | uint32_t key, void *data) |
| 4471 | { |
| 4472 | struct weston_compositor *compositor = data; |
| 4473 | |
| 4474 | if (weston_timeline_enabled_) |
| 4475 | weston_timeline_close(); |
| 4476 | else |
| 4477 | weston_timeline_open(compositor); |
| 4478 | } |
| 4479 | |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 4480 | WL_EXPORT int |
Daniel Stone | baf4359 | 2012-06-01 11:11:10 -0400 | [diff] [blame] | 4481 | weston_compositor_init(struct weston_compositor *ec, |
| 4482 | struct wl_display *display, |
Kristian Høgsberg | 4172f66 | 2013-02-20 15:27:49 -0500 | [diff] [blame] | 4483 | int *argc, char *argv[], |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 4484 | struct weston_config *config) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 4485 | { |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 4486 | struct wl_event_loop *loop; |
Daniel Stone | e2ef43a | 2012-06-01 12:14:05 +0100 | [diff] [blame] | 4487 | struct xkb_rule_names xkb_names; |
Kristian Høgsberg | 6a04791 | 2013-05-23 15:56:29 -0400 | [diff] [blame] | 4488 | struct weston_config_section *s; |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 4489 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 4490 | ec->config = config; |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 4491 | ec->wl_display = display; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 4492 | wl_signal_init(&ec->destroy_signal); |
Kristian Høgsberg | f03a04a | 2014-04-06 22:04:50 -0700 | [diff] [blame] | 4493 | wl_signal_init(&ec->create_surface_signal); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 4494 | wl_signal_init(&ec->activate_signal); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 4495 | wl_signal_init(&ec->transform_signal); |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 4496 | wl_signal_init(&ec->kill_signal); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4497 | wl_signal_init(&ec->idle_signal); |
| 4498 | wl_signal_init(&ec->wake_signal); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 4499 | wl_signal_init(&ec->show_input_panel_signal); |
| 4500 | wl_signal_init(&ec->hide_input_panel_signal); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 4501 | wl_signal_init(&ec->update_input_panel_signal); |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 4502 | wl_signal_init(&ec->seat_created_signal); |
Richard Hughes | 59d5da7 | 2013-05-01 21:52:11 +0100 | [diff] [blame] | 4503 | wl_signal_init(&ec->output_created_signal); |
Ander Conselvan de Oliveira | f84327a | 2014-01-29 18:47:51 +0200 | [diff] [blame] | 4504 | wl_signal_init(&ec->output_destroyed_signal); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4505 | wl_signal_init(&ec->output_moved_signal); |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 4506 | wl_signal_init(&ec->session_signal); |
| 4507 | ec->session_active = 1; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 4508 | |
Casey Dahlin | 58ba137 | 2012-04-19 22:50:08 -0400 | [diff] [blame] | 4509 | ec->output_id_pool = 0; |
| 4510 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 4511 | if (!wl_global_create(display, &wl_compositor_interface, 3, |
| 4512 | ec, compositor_bind)) |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 4513 | return -1; |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 4514 | |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 4515 | if (!wl_global_create(display, &wl_subcompositor_interface, 1, |
| 4516 | ec, bind_subcompositor)) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4517 | return -1; |
| 4518 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 4519 | if (!wl_global_create(ec->wl_display, &wl_scaler_interface, 2, |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 4520 | ec, bind_scaler)) |
| 4521 | return -1; |
| 4522 | |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 4523 | if (!wl_global_create(ec->wl_display, &presentation_interface, 1, |
| 4524 | ec, bind_presentation)) |
| 4525 | return -1; |
| 4526 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4527 | wl_list_init(&ec->view_list); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 4528 | wl_list_init(&ec->plane_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 4529 | wl_list_init(&ec->layer_list); |
| 4530 | wl_list_init(&ec->seat_list); |
| 4531 | wl_list_init(&ec->output_list); |
| 4532 | wl_list_init(&ec->key_binding_list); |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 4533 | wl_list_init(&ec->modifier_binding_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 4534 | wl_list_init(&ec->button_binding_list); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4535 | wl_list_init(&ec->touch_binding_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 4536 | wl_list_init(&ec->axis_binding_list); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 4537 | wl_list_init(&ec->debug_binding_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 4538 | |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 4539 | weston_plane_init(&ec->primary_plane, ec, 0, 0); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 4540 | weston_compositor_stack_plane(ec, &ec->primary_plane, NULL); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4541 | |
Kristian Høgsberg | 6a04791 | 2013-05-23 15:56:29 -0400 | [diff] [blame] | 4542 | s = weston_config_get_section(ec->config, "keyboard", NULL, NULL); |
| 4543 | weston_config_section_get_string(s, "keymap_rules", |
| 4544 | (char **) &xkb_names.rules, NULL); |
| 4545 | weston_config_section_get_string(s, "keymap_model", |
| 4546 | (char **) &xkb_names.model, NULL); |
| 4547 | weston_config_section_get_string(s, "keymap_layout", |
| 4548 | (char **) &xkb_names.layout, NULL); |
| 4549 | weston_config_section_get_string(s, "keymap_variant", |
| 4550 | (char **) &xkb_names.variant, NULL); |
| 4551 | weston_config_section_get_string(s, "keymap_options", |
| 4552 | (char **) &xkb_names.options, NULL); |
Rob Bradford | 382ff46 | 2013-06-24 16:52:45 +0100 | [diff] [blame] | 4553 | |
Kristian Høgsberg | 2f07ef6 | 2013-02-16 14:29:24 -0500 | [diff] [blame] | 4554 | if (weston_compositor_xkb_init(ec, &xkb_names) < 0) |
| 4555 | return -1; |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 4556 | |
Jonny Lamb | 66a41a0 | 2014-08-12 14:58:25 +0200 | [diff] [blame] | 4557 | weston_config_section_get_int(s, "repeat-rate", |
| 4558 | &ec->kb_repeat_rate, 40); |
| 4559 | weston_config_section_get_int(s, "repeat-delay", |
| 4560 | &ec->kb_repeat_delay, 400); |
| 4561 | |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 4562 | text_backend_init(ec); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 4563 | |
| 4564 | wl_data_device_manager_init(ec->wl_display); |
| 4565 | |
Kristian Høgsberg | 9629fe3 | 2012-03-26 15:56:39 -0400 | [diff] [blame] | 4566 | wl_display_init_shm(display); |
Kristian Høgsberg | b5819dc | 2011-04-25 15:08:20 -0400 | [diff] [blame] | 4567 | |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 4568 | loop = wl_display_get_event_loop(ec->wl_display); |
| 4569 | ec->idle_source = wl_event_loop_add_timer(loop, idle_handler, ec); |
| 4570 | wl_event_source_timer_update(ec->idle_source, ec->idle_time * 1000); |
| 4571 | |
| 4572 | ec->input_loop = wl_event_loop_create(); |
| 4573 | |
Kristian Høgsberg | 861a50c | 2012-09-05 22:02:22 -0400 | [diff] [blame] | 4574 | weston_layer_init(&ec->fade_layer, &ec->layer_list); |
| 4575 | weston_layer_init(&ec->cursor_layer, &ec->fade_layer.link); |
| 4576 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 4577 | weston_compositor_add_debug_binding(ec, KEY_T, |
| 4578 | timeline_key_binding_handler, ec); |
| 4579 | |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 4580 | s = weston_config_get_section(ec->config, "core", NULL, NULL); |
| 4581 | weston_config_section_get_int(s, "repaint-window", &ec->repaint_msec, |
| 4582 | DEFAULT_REPAINT_WINDOW); |
| 4583 | if (ec->repaint_msec < -10 || ec->repaint_msec > 1000) { |
| 4584 | weston_log("Invalid repaint_window value in config: %d\n", |
| 4585 | ec->repaint_msec); |
| 4586 | ec->repaint_msec = DEFAULT_REPAINT_WINDOW; |
| 4587 | } |
| 4588 | weston_log("Output repaint window is %d ms maximum.\n", |
| 4589 | ec->repaint_msec); |
| 4590 | |
Kristian Høgsberg | 861a50c | 2012-09-05 22:02:22 -0400 | [diff] [blame] | 4591 | weston_compositor_schedule_repaint(ec); |
| 4592 | |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 4593 | return 0; |
| 4594 | } |
| 4595 | |
Benjamin Franzke | b826302 | 2011-08-30 11:32:47 +0200 | [diff] [blame] | 4596 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4597 | weston_compositor_shutdown(struct weston_compositor *ec) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 4598 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4599 | struct weston_output *output, *next; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 4600 | |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 4601 | wl_event_source_remove(ec->idle_source); |
Jonas Ådahl | c97af92 | 2012-03-28 22:36:09 +0200 | [diff] [blame] | 4602 | if (ec->input_loop_source) |
| 4603 | wl_event_source_remove(ec->input_loop_source); |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 4604 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 4605 | /* Destroy all outputs associated with this compositor */ |
Tiago Vignatti | b303a1d | 2011-12-18 22:27:40 +0200 | [diff] [blame] | 4606 | wl_list_for_each_safe(output, next, &ec->output_list, link) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 4607 | output->destroy(output); |
Pekka Paalanen | 4738f3b | 2012-01-02 15:47:07 +0200 | [diff] [blame] | 4608 | |
Ander Conselvan de Oliveira | 1853676 | 2013-12-20 21:07:00 +0200 | [diff] [blame] | 4609 | if (ec->renderer) |
| 4610 | ec->renderer->destroy(ec); |
| 4611 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4612 | weston_binding_list_destroy_all(&ec->key_binding_list); |
| 4613 | weston_binding_list_destroy_all(&ec->button_binding_list); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 4614 | weston_binding_list_destroy_all(&ec->touch_binding_list); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 4615 | weston_binding_list_destroy_all(&ec->axis_binding_list); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 4616 | weston_binding_list_destroy_all(&ec->debug_binding_list); |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 4617 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4618 | weston_plane_release(&ec->primary_plane); |
| 4619 | |
Jonas Ådahl | c97af92 | 2012-03-28 22:36:09 +0200 | [diff] [blame] | 4620 | wl_event_loop_destroy(ec->input_loop); |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 4621 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 4622 | weston_config_destroy(ec->config); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 4623 | } |
| 4624 | |
Kristian Høgsberg | af4f2aa | 2013-02-15 20:53:20 -0500 | [diff] [blame] | 4625 | WL_EXPORT void |
Frederic Plourde | c336f06 | 2014-10-29 14:44:33 -0400 | [diff] [blame] | 4626 | weston_compositor_exit_with_code(struct weston_compositor *compositor, |
| 4627 | int exit_code) |
| 4628 | { |
Pekka Paalanen | f5ef88f | 2014-11-18 15:57:04 +0200 | [diff] [blame] | 4629 | if (compositor->exit_code == EXIT_SUCCESS) |
| 4630 | compositor->exit_code = exit_code; |
| 4631 | |
Frederic Plourde | c336f06 | 2014-10-29 14:44:33 -0400 | [diff] [blame] | 4632 | wl_display_terminate(compositor->wl_display); |
| 4633 | } |
| 4634 | |
| 4635 | WL_EXPORT void |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 4636 | weston_compositor_set_default_pointer_grab(struct weston_compositor *ec, |
| 4637 | const struct weston_pointer_grab_interface *interface) |
| 4638 | { |
| 4639 | struct weston_seat *seat; |
| 4640 | |
| 4641 | ec->default_pointer_grab = interface; |
| 4642 | wl_list_for_each(seat, &ec->seat_list, link) { |
| 4643 | if (seat->pointer) { |
| 4644 | weston_pointer_set_default_grab(seat->pointer, |
| 4645 | interface); |
| 4646 | } |
| 4647 | } |
| 4648 | } |
| 4649 | |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 4650 | WL_EXPORT int |
| 4651 | weston_compositor_set_presentation_clock(struct weston_compositor *compositor, |
| 4652 | clockid_t clk_id) |
| 4653 | { |
| 4654 | struct timespec ts; |
| 4655 | |
| 4656 | if (clock_gettime(clk_id, &ts) < 0) |
| 4657 | return -1; |
| 4658 | |
| 4659 | compositor->presentation_clock = clk_id; |
| 4660 | |
| 4661 | return 0; |
| 4662 | } |
| 4663 | |
| 4664 | /* |
| 4665 | * For choosing the software clock, when the display hardware or API |
| 4666 | * does not expose a compatible presentation timestamp. |
| 4667 | */ |
| 4668 | WL_EXPORT int |
| 4669 | weston_compositor_set_presentation_clock_software( |
| 4670 | struct weston_compositor *compositor) |
| 4671 | { |
| 4672 | /* In order of preference */ |
| 4673 | static const clockid_t clocks[] = { |
| 4674 | CLOCK_MONOTONIC_RAW, /* no jumps, no crawling */ |
| 4675 | CLOCK_MONOTONIC_COARSE, /* no jumps, may crawl, fast & coarse */ |
| 4676 | CLOCK_MONOTONIC, /* no jumps, may crawl */ |
| 4677 | CLOCK_REALTIME_COARSE, /* may jump and crawl, fast & coarse */ |
| 4678 | CLOCK_REALTIME /* may jump and crawl */ |
| 4679 | }; |
| 4680 | unsigned i; |
| 4681 | |
| 4682 | for (i = 0; i < ARRAY_LENGTH(clocks); i++) |
| 4683 | if (weston_compositor_set_presentation_clock(compositor, |
| 4684 | clocks[i]) == 0) |
| 4685 | return 0; |
| 4686 | |
| 4687 | weston_log("Error: no suitable presentation clock available.\n"); |
| 4688 | |
| 4689 | return -1; |
| 4690 | } |
| 4691 | |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 4692 | /** Read the current time from the Presentation clock |
| 4693 | * |
| 4694 | * \param compositor |
| 4695 | * \param ts[out] The current time. |
| 4696 | * |
| 4697 | * \note Reading the current time in user space is always imprecise to some |
| 4698 | * degree. |
| 4699 | * |
| 4700 | * This function is never meant to fail. If reading the clock does fail, |
| 4701 | * an error message is logged and a zero time is returned. Callers are not |
| 4702 | * supposed to detect or react to failures. |
| 4703 | */ |
| 4704 | WL_EXPORT void |
| 4705 | weston_compositor_read_presentation_clock( |
| 4706 | const struct weston_compositor *compositor, |
| 4707 | struct timespec *ts) |
| 4708 | { |
| 4709 | static bool warned; |
| 4710 | int ret; |
| 4711 | |
| 4712 | ret = clock_gettime(compositor->presentation_clock, ts); |
| 4713 | if (ret < 0) { |
| 4714 | ts->tv_sec = 0; |
| 4715 | ts->tv_nsec = 0; |
| 4716 | |
| 4717 | if (!warned) |
| 4718 | weston_log("Error: failure to read " |
| 4719 | "the presentation clock %#x: '%m' (%d)\n", |
| 4720 | compositor->presentation_clock, errno); |
| 4721 | warned = true; |
| 4722 | } |
| 4723 | } |
| 4724 | |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 4725 | WL_EXPORT void |
Kristian Høgsberg | af4f2aa | 2013-02-15 20:53:20 -0500 | [diff] [blame] | 4726 | weston_version(int *major, int *minor, int *micro) |
| 4727 | { |
| 4728 | *major = WESTON_VERSION_MAJOR; |
| 4729 | *minor = WESTON_VERSION_MINOR; |
| 4730 | *micro = WESTON_VERSION_MICRO; |
| 4731 | } |
| 4732 | |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 4733 | static const char * |
| 4734 | clock_name(clockid_t clk_id) |
| 4735 | { |
| 4736 | static const char *names[] = { |
| 4737 | [CLOCK_REALTIME] = "CLOCK_REALTIME", |
| 4738 | [CLOCK_MONOTONIC] = "CLOCK_MONOTONIC", |
| 4739 | [CLOCK_MONOTONIC_RAW] = "CLOCK_MONOTONIC_RAW", |
| 4740 | [CLOCK_REALTIME_COARSE] = "CLOCK_REALTIME_COARSE", |
| 4741 | [CLOCK_MONOTONIC_COARSE] = "CLOCK_MONOTONIC_COARSE", |
| 4742 | [CLOCK_BOOTTIME] = "CLOCK_BOOTTIME", |
| 4743 | }; |
| 4744 | |
| 4745 | if (clk_id < 0 || (unsigned)clk_id >= ARRAY_LENGTH(names)) |
| 4746 | return "unknown"; |
| 4747 | |
| 4748 | return names[clk_id]; |
| 4749 | } |
| 4750 | |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 4751 | static const struct { |
Pekka Paalanen | 4fc5dd0 | 2013-05-22 18:03:05 +0300 | [diff] [blame] | 4752 | uint32_t bit; /* enum weston_capability */ |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 4753 | const char *desc; |
| 4754 | } capability_strings[] = { |
| 4755 | { WESTON_CAP_ROTATION_ANY, "arbitrary surface rotation:" }, |
Pekka Paalanen | 4fc5dd0 | 2013-05-22 18:03:05 +0300 | [diff] [blame] | 4756 | { WESTON_CAP_CAPTURE_YFLIP, "screen capture uses y-flip:" }, |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 4757 | }; |
| 4758 | |
| 4759 | static void |
| 4760 | weston_compositor_log_capabilities(struct weston_compositor *compositor) |
| 4761 | { |
| 4762 | unsigned i; |
| 4763 | int yes; |
| 4764 | |
| 4765 | weston_log("Compositor capabilities:\n"); |
| 4766 | for (i = 0; i < ARRAY_LENGTH(capability_strings); i++) { |
| 4767 | yes = compositor->capabilities & capability_strings[i].bit; |
| 4768 | weston_log_continue(STAMP_SPACE "%s %s\n", |
| 4769 | capability_strings[i].desc, |
| 4770 | yes ? "yes" : "no"); |
| 4771 | } |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 4772 | |
| 4773 | weston_log_continue(STAMP_SPACE "presentation clock: %s, id %d\n", |
| 4774 | clock_name(compositor->presentation_clock), |
| 4775 | compositor->presentation_clock); |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 4776 | } |
| 4777 | |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 4778 | static int on_term_signal(int signal_number, void *data) |
Kristian Høgsberg | 50dc698 | 2010-12-01 16:43:56 -0500 | [diff] [blame] | 4779 | { |
Kristian Høgsberg | 6bded3f | 2011-08-12 14:55:07 -0400 | [diff] [blame] | 4780 | struct wl_display *display = data; |
Kristian Høgsberg | 50dc698 | 2010-12-01 16:43:56 -0500 | [diff] [blame] | 4781 | |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 4782 | weston_log("caught signal %d\n", signal_number); |
Kristian Høgsberg | 6bded3f | 2011-08-12 14:55:07 -0400 | [diff] [blame] | 4783 | wl_display_terminate(display); |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 4784 | |
| 4785 | return 1; |
Kristian Høgsberg | 50dc698 | 2010-12-01 16:43:56 -0500 | [diff] [blame] | 4786 | } |
| 4787 | |
Marcin Slusarz | 554a0da | 2013-02-18 13:27:22 -0500 | [diff] [blame] | 4788 | #ifdef HAVE_LIBUNWIND |
| 4789 | |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 4790 | static void |
Marcin Slusarz | 554a0da | 2013-02-18 13:27:22 -0500 | [diff] [blame] | 4791 | print_backtrace(void) |
| 4792 | { |
| 4793 | unw_cursor_t cursor; |
| 4794 | unw_context_t context; |
| 4795 | unw_word_t off; |
| 4796 | unw_proc_info_t pip; |
| 4797 | int ret, i = 0; |
| 4798 | char procname[256]; |
| 4799 | const char *filename; |
| 4800 | Dl_info dlinfo; |
| 4801 | |
| 4802 | pip.unwind_info = NULL; |
| 4803 | ret = unw_getcontext(&context); |
| 4804 | if (ret) { |
| 4805 | weston_log("unw_getcontext: %d\n", ret); |
| 4806 | return; |
| 4807 | } |
| 4808 | |
| 4809 | ret = unw_init_local(&cursor, &context); |
| 4810 | if (ret) { |
| 4811 | weston_log("unw_init_local: %d\n", ret); |
| 4812 | return; |
| 4813 | } |
| 4814 | |
| 4815 | ret = unw_step(&cursor); |
| 4816 | while (ret > 0) { |
| 4817 | ret = unw_get_proc_info(&cursor, &pip); |
| 4818 | if (ret) { |
| 4819 | weston_log("unw_get_proc_info: %d\n", ret); |
| 4820 | break; |
| 4821 | } |
| 4822 | |
| 4823 | ret = unw_get_proc_name(&cursor, procname, 256, &off); |
| 4824 | if (ret && ret != -UNW_ENOMEM) { |
| 4825 | if (ret != -UNW_EUNSPEC) |
| 4826 | weston_log("unw_get_proc_name: %d\n", ret); |
| 4827 | procname[0] = '?'; |
| 4828 | procname[1] = 0; |
| 4829 | } |
| 4830 | |
| 4831 | if (dladdr((void *)(pip.start_ip + off), &dlinfo) && dlinfo.dli_fname && |
| 4832 | *dlinfo.dli_fname) |
| 4833 | filename = dlinfo.dli_fname; |
| 4834 | else |
| 4835 | filename = "?"; |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 4836 | |
Marcin Slusarz | 554a0da | 2013-02-18 13:27:22 -0500 | [diff] [blame] | 4837 | weston_log("%u: %s (%s%s+0x%x) [%p]\n", i++, filename, procname, |
| 4838 | ret == -UNW_ENOMEM ? "..." : "", (int)off, (void *)(pip.start_ip + off)); |
| 4839 | |
| 4840 | ret = unw_step(&cursor); |
| 4841 | if (ret < 0) |
| 4842 | weston_log("unw_step: %d\n", ret); |
| 4843 | } |
| 4844 | } |
| 4845 | |
| 4846 | #else |
| 4847 | |
| 4848 | static void |
| 4849 | print_backtrace(void) |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 4850 | { |
| 4851 | void *buffer[32]; |
| 4852 | int i, count; |
| 4853 | Dl_info info; |
| 4854 | |
Marcin Slusarz | 554a0da | 2013-02-18 13:27:22 -0500 | [diff] [blame] | 4855 | count = backtrace(buffer, ARRAY_LENGTH(buffer)); |
| 4856 | for (i = 0; i < count; i++) { |
| 4857 | dladdr(buffer[i], &info); |
| 4858 | weston_log(" [%016lx] %s (%s)\n", |
| 4859 | (long) buffer[i], |
| 4860 | info.dli_sname ? info.dli_sname : "--", |
| 4861 | info.dli_fname); |
| 4862 | } |
| 4863 | } |
| 4864 | |
| 4865 | #endif |
| 4866 | |
| 4867 | static void |
Peter Maatman | e5b42e4 | 2013-03-27 22:38:53 +0100 | [diff] [blame] | 4868 | on_caught_signal(int s, siginfo_t *siginfo, void *context) |
Marcin Slusarz | 554a0da | 2013-02-18 13:27:22 -0500 | [diff] [blame] | 4869 | { |
Peter Maatman | e5b42e4 | 2013-03-27 22:38:53 +0100 | [diff] [blame] | 4870 | /* This signal handler will do a best-effort backtrace, and |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 4871 | * then call the backend restore function, which will switch |
| 4872 | * back to the vt we launched from or ungrab X etc and then |
| 4873 | * raise SIGTRAP. If we run weston under gdb from X or a |
Peter Maatman | e5b42e4 | 2013-03-27 22:38:53 +0100 | [diff] [blame] | 4874 | * different vt, and tell gdb "handle *s* nostop", this |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 4875 | * will allow weston to switch back to gdb on crash and then |
Peter Maatman | e5b42e4 | 2013-03-27 22:38:53 +0100 | [diff] [blame] | 4876 | * gdb will catch the crash with SIGTRAP.*/ |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 4877 | |
Peter Maatman | e5b42e4 | 2013-03-27 22:38:53 +0100 | [diff] [blame] | 4878 | weston_log("caught signal: %d\n", s); |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 4879 | |
Marcin Slusarz | 554a0da | 2013-02-18 13:27:22 -0500 | [diff] [blame] | 4880 | print_backtrace(); |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 4881 | |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 4882 | segv_compositor->restore(segv_compositor); |
| 4883 | |
| 4884 | raise(SIGTRAP); |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 4885 | } |
| 4886 | |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 4887 | WL_EXPORT void * |
| 4888 | weston_load_module(const char *name, const char *entrypoint) |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 4889 | { |
| 4890 | char path[PATH_MAX]; |
| 4891 | void *module, *init; |
| 4892 | |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 4893 | if (name == NULL) |
| 4894 | return NULL; |
| 4895 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 4896 | if (name[0] != '/') |
Chad Versace | bf38190 | 2012-05-23 23:42:15 -0700 | [diff] [blame] | 4897 | snprintf(path, sizeof path, "%s/%s", MODULEDIR, name); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 4898 | else |
Benjamin Franzke | b7acce6 | 2011-05-06 23:19:22 +0200 | [diff] [blame] | 4899 | snprintf(path, sizeof path, "%s", name); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 4900 | |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 4901 | module = dlopen(path, RTLD_NOW | RTLD_NOLOAD); |
| 4902 | if (module) { |
| 4903 | weston_log("Module '%s' already loaded\n", path); |
| 4904 | dlclose(module); |
| 4905 | return NULL; |
| 4906 | } |
| 4907 | |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 4908 | weston_log("Loading module '%s'\n", path); |
Kristian Høgsberg | 1acd9f8 | 2012-07-26 11:39:26 -0400 | [diff] [blame] | 4909 | module = dlopen(path, RTLD_NOW); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 4910 | if (!module) { |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 4911 | weston_log("Failed to load module: %s\n", dlerror()); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 4912 | return NULL; |
| 4913 | } |
| 4914 | |
| 4915 | init = dlsym(module, entrypoint); |
| 4916 | if (!init) { |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 4917 | weston_log("Failed to lookup init function: %s\n", dlerror()); |
Rob Bradford | c9e64ab | 2012-12-05 18:47:10 +0000 | [diff] [blame] | 4918 | dlclose(module); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 4919 | return NULL; |
| 4920 | } |
| 4921 | |
| 4922 | return init; |
| 4923 | } |
| 4924 | |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 4925 | static int |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 4926 | load_modules(struct weston_compositor *ec, const char *modules, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 4927 | int *argc, char *argv[]) |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 4928 | { |
| 4929 | const char *p, *end; |
| 4930 | char buffer[256]; |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 4931 | int (*module_init)(struct weston_compositor *ec, |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 4932 | int *argc, char *argv[]); |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 4933 | |
| 4934 | if (modules == NULL) |
| 4935 | return 0; |
| 4936 | |
| 4937 | p = modules; |
| 4938 | while (*p) { |
| 4939 | end = strchrnul(p, ','); |
| 4940 | snprintf(buffer, sizeof buffer, "%.*s", (int) (end - p), p); |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 4941 | module_init = weston_load_module(buffer, "module_init"); |
Ondřej Majerech | 01e98b6 | 2014-12-06 02:49:17 +0100 | [diff] [blame] | 4942 | if (!module_init) |
| 4943 | return -1; |
| 4944 | if (module_init(ec, argc, argv) < 0) |
| 4945 | return -1; |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 4946 | p = end; |
| 4947 | while (*p == ',') |
| 4948 | p++; |
| 4949 | |
| 4950 | } |
| 4951 | |
| 4952 | return 0; |
| 4953 | } |
| 4954 | |
Pekka Paalanen | 78a0b57 | 2012-06-06 16:59:44 +0300 | [diff] [blame] | 4955 | static const char xdg_error_message[] = |
Martin Minarik | 37032f8 | 2012-06-18 20:15:18 +0200 | [diff] [blame] | 4956 | "fatal: environment variable XDG_RUNTIME_DIR is not set.\n"; |
| 4957 | |
| 4958 | static const char xdg_wrong_message[] = |
| 4959 | "fatal: environment variable XDG_RUNTIME_DIR\n" |
| 4960 | "is set to \"%s\", which is not a directory.\n"; |
| 4961 | |
| 4962 | static const char xdg_wrong_mode_message[] = |
| 4963 | "warning: XDG_RUNTIME_DIR \"%s\" is not configured\n" |
Guillem Jover | 32b793c | 2014-01-31 20:41:21 +0100 | [diff] [blame] | 4964 | "correctly. Unix access mode must be 0700 (current mode is %o),\n" |
| 4965 | "and must be owned by the user (current owner is UID %d).\n"; |
Martin Minarik | 37032f8 | 2012-06-18 20:15:18 +0200 | [diff] [blame] | 4966 | |
| 4967 | static const char xdg_detail_message[] = |
Pekka Paalanen | 78a0b57 | 2012-06-06 16:59:44 +0300 | [diff] [blame] | 4968 | "Refer to your distribution on how to get it, or\n" |
| 4969 | "http://www.freedesktop.org/wiki/Specifications/basedir-spec\n" |
| 4970 | "on how to implement it.\n"; |
| 4971 | |
Martin Minarik | 37032f8 | 2012-06-18 20:15:18 +0200 | [diff] [blame] | 4972 | static void |
| 4973 | verify_xdg_runtime_dir(void) |
| 4974 | { |
| 4975 | char *dir = getenv("XDG_RUNTIME_DIR"); |
| 4976 | struct stat s; |
| 4977 | |
| 4978 | if (!dir) { |
| 4979 | weston_log(xdg_error_message); |
| 4980 | weston_log_continue(xdg_detail_message); |
| 4981 | exit(EXIT_FAILURE); |
| 4982 | } |
| 4983 | |
| 4984 | if (stat(dir, &s) || !S_ISDIR(s.st_mode)) { |
| 4985 | weston_log(xdg_wrong_message, dir); |
| 4986 | weston_log_continue(xdg_detail_message); |
| 4987 | exit(EXIT_FAILURE); |
| 4988 | } |
| 4989 | |
| 4990 | if ((s.st_mode & 0777) != 0700 || s.st_uid != getuid()) { |
| 4991 | weston_log(xdg_wrong_mode_message, |
| 4992 | dir, s.st_mode & 0777, s.st_uid); |
| 4993 | weston_log_continue(xdg_detail_message); |
| 4994 | } |
| 4995 | } |
| 4996 | |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 4997 | static int |
| 4998 | usage(int error_code) |
| 4999 | { |
| 5000 | fprintf(stderr, |
| 5001 | "Usage: weston [OPTIONS]\n\n" |
| 5002 | "This is weston version " VERSION ", the Wayland reference compositor.\n" |
| 5003 | "Weston supports multiple backends, and depending on which backend is in use\n" |
| 5004 | "different options will be accepted.\n\n" |
| 5005 | |
| 5006 | |
| 5007 | "Core options:\n\n" |
Scott Moreau | 1224514 | 2012-08-29 15:15:58 -0600 | [diff] [blame] | 5008 | " --version\t\tPrint weston version\n" |
Bryce Harrington | 32297c9 | 2014-10-23 15:25:04 -0700 | [diff] [blame] | 5009 | " -B, --backend=MODULE\tBackend module, one of\n" |
| 5010 | #if defined(BUILD_DRM_COMPOSITOR) |
| 5011 | "\t\t\t\tdrm-backend.so\n" |
| 5012 | #endif |
| 5013 | #if defined(BUILD_FBDEV_COMPOSITOR) |
Pekka Paalanen | 86b70e1 | 2014-11-11 14:10:46 +0200 | [diff] [blame] | 5014 | "\t\t\t\tfbdev-backend.so\n" |
Bryce Harrington | 32297c9 | 2014-10-23 15:25:04 -0700 | [diff] [blame] | 5015 | #endif |
| 5016 | #if defined(BUILD_X11_COMPOSITOR) |
| 5017 | "\t\t\t\tx11-backend.so\n" |
| 5018 | #endif |
| 5019 | #if defined(BUILD_WAYLAND_COMPOSITOR) |
| 5020 | "\t\t\t\twayland-backend.so\n" |
| 5021 | #endif |
| 5022 | #if defined(BUILD_RDP_COMPOSITOR) |
| 5023 | "\t\t\t\trdp-backend.so\n" |
| 5024 | #endif |
| 5025 | #if defined(BUILD_RPI_COMPOSITOR) && defined(HAVE_BCM_HOST) |
| 5026 | "\t\t\t\trpi-backend.so\n" |
| 5027 | #endif |
Jason Ekstrand | a985da4 | 2013-08-22 17:28:03 -0500 | [diff] [blame] | 5028 | " --shell=MODULE\tShell module, defaults to desktop-shell.so\n" |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 5029 | " -S, --socket=NAME\tName of socket to listen on\n" |
| 5030 | " -i, --idle-time=SECS\tIdle time in seconds\n" |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 5031 | " --modules\t\tLoad the comma-separated list of modules\n" |
Bryce Harrington | b8b25bd | 2014-10-23 14:44:36 -0700 | [diff] [blame] | 5032 | " --log=FILE\t\tLog to the given file\n" |
Pekka Paalanen | 588bee1 | 2014-05-07 16:26:25 +0300 | [diff] [blame] | 5033 | " --no-config\t\tDo not read weston.ini\n" |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 5034 | " -h, --help\t\tThis help message\n\n"); |
| 5035 | |
Bryce Harrington | 8eb95c4 | 2014-10-23 15:25:03 -0700 | [diff] [blame] | 5036 | #if defined(BUILD_DRM_COMPOSITOR) |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 5037 | fprintf(stderr, |
| 5038 | "Options for drm-backend.so:\n\n" |
| 5039 | " --connector=ID\tBring up only this connector\n" |
| 5040 | " --seat=SEAT\t\tThe seat that weston should run on\n" |
| 5041 | " --tty=TTY\t\tThe tty to use\n" |
Ander Conselvan de Oliveira | 23e72b8 | 2013-01-25 15:13:06 +0200 | [diff] [blame] | 5042 | " --use-pixman\t\tUse the pixman (CPU) renderer\n" |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 5043 | " --current-mode\tPrefer current KMS mode over EDID preferred mode\n\n"); |
Bryce Harrington | 8eb95c4 | 2014-10-23 15:25:03 -0700 | [diff] [blame] | 5044 | #endif |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 5045 | |
Bryce Harrington | 8eb95c4 | 2014-10-23 15:25:03 -0700 | [diff] [blame] | 5046 | #if defined(BUILD_FBDEV_COMPOSITOR) |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 5047 | fprintf(stderr, |
Philipp Brüschweiler | e14560e | 2013-03-30 15:18:49 +0100 | [diff] [blame] | 5048 | "Options for fbdev-backend.so:\n\n" |
| 5049 | " --tty=TTY\t\tThe tty to use\n" |
| 5050 | " --device=DEVICE\tThe framebuffer device to use\n\n"); |
Bryce Harrington | 8eb95c4 | 2014-10-23 15:25:03 -0700 | [diff] [blame] | 5051 | #endif |
Philipp Brüschweiler | e14560e | 2013-03-30 15:18:49 +0100 | [diff] [blame] | 5052 | |
Bryce Harrington | 8eb95c4 | 2014-10-23 15:25:03 -0700 | [diff] [blame] | 5053 | #if defined(BUILD_X11_COMPOSITOR) |
Philipp Brüschweiler | e14560e | 2013-03-30 15:18:49 +0100 | [diff] [blame] | 5054 | fprintf(stderr, |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 5055 | "Options for x11-backend.so:\n\n" |
| 5056 | " --width=WIDTH\t\tWidth of X window\n" |
| 5057 | " --height=HEIGHT\tHeight of X window\n" |
| 5058 | " --fullscreen\t\tRun in fullscreen mode\n" |
Kristian Høgsberg | efaca34 | 2013-01-07 15:52:44 -0500 | [diff] [blame] | 5059 | " --use-pixman\t\tUse the pixman (CPU) renderer\n" |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 5060 | " --output-count=COUNT\tCreate multiple outputs\n" |
| 5061 | " --no-input\t\tDont create input devices\n\n"); |
Bryce Harrington | 8eb95c4 | 2014-10-23 15:25:03 -0700 | [diff] [blame] | 5062 | #endif |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 5063 | |
Bryce Harrington | 8eb95c4 | 2014-10-23 15:25:03 -0700 | [diff] [blame] | 5064 | #if defined(BUILD_WAYLAND_COMPOSITOR) |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 5065 | fprintf(stderr, |
| 5066 | "Options for wayland-backend.so:\n\n" |
| 5067 | " --width=WIDTH\t\tWidth of Wayland surface\n" |
| 5068 | " --height=HEIGHT\tHeight of Wayland surface\n" |
Bryce Harrington | b8b25bd | 2014-10-23 14:44:36 -0700 | [diff] [blame] | 5069 | " --scale=SCALE\t\tScale factor of output\n" |
Jason Ekstrand | 5ea0480 | 2013-11-07 20:13:33 -0600 | [diff] [blame] | 5070 | " --fullscreen\t\tRun in fullscreen mode\n" |
Jason Ekstrand | ff2fd46 | 2013-10-27 22:24:58 -0500 | [diff] [blame] | 5071 | " --use-pixman\t\tUse the pixman (CPU) renderer\n" |
Jason Ekstrand | 48ce421 | 2013-10-27 22:25:02 -0500 | [diff] [blame] | 5072 | " --output-count=COUNT\tCreate multiple outputs\n" |
Jason Ekstrand | e4ca8b0 | 2014-04-02 19:53:55 -0500 | [diff] [blame] | 5073 | " --sprawl\t\tCreate one fullscreen output for every parent output\n" |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 5074 | " --display=DISPLAY\tWayland display to connect to\n\n"); |
Bryce Harrington | 8eb95c4 | 2014-10-23 15:25:03 -0700 | [diff] [blame] | 5075 | #endif |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 5076 | |
Pekka Paalanen | e31e053 | 2013-05-22 18:03:07 +0300 | [diff] [blame] | 5077 | #if defined(BUILD_RPI_COMPOSITOR) && defined(HAVE_BCM_HOST) |
| 5078 | fprintf(stderr, |
| 5079 | "Options for rpi-backend.so:\n\n" |
| 5080 | " --tty=TTY\t\tThe tty to use\n" |
| 5081 | " --single-buffer\tUse single-buffered Dispmanx elements.\n" |
| 5082 | " --transform=TR\tThe output transformation, TR is one of:\n" |
| 5083 | "\tnormal 90 180 270 flipped flipped-90 flipped-180 flipped-270\n" |
Tomeu Vizoso | e4f7b92 | 2013-12-02 17:18:58 +0100 | [diff] [blame] | 5084 | " --opaque-regions\tEnable support for opaque regions, can be " |
| 5085 | "very slow without support in the GPU firmware.\n" |
Pekka Paalanen | e31e053 | 2013-05-22 18:03:07 +0300 | [diff] [blame] | 5086 | "\n"); |
| 5087 | #endif |
| 5088 | |
Hardening | c077a84 | 2013-07-08 00:51:35 +0200 | [diff] [blame] | 5089 | #if defined(BUILD_RDP_COMPOSITOR) |
Bryce Harrington | 59fe423 | 2014-10-23 14:44:34 -0700 | [diff] [blame] | 5090 | fprintf(stderr, |
| 5091 | "Options for rdp-backend.so:\n\n" |
| 5092 | " --width=WIDTH\t\tWidth of desktop\n" |
| 5093 | " --height=HEIGHT\tHeight of desktop\n" |
| 5094 | " --env-socket=SOCKET\tUse that socket as peer connection\n" |
| 5095 | " --address=ADDR\tThe address to bind\n" |
Bryce Harrington | f5b34ae | 2014-10-23 14:44:35 -0700 | [diff] [blame] | 5096 | " --port=PORT\t\tThe port to listen on\n" |
Bryce Harrington | 59fe423 | 2014-10-23 14:44:34 -0700 | [diff] [blame] | 5097 | " --no-clients-resize\tThe RDP peers will be forced to the size of the desktop\n" |
| 5098 | " --rdp4-key=FILE\tThe file containing the key for RDP4 encryption\n" |
| 5099 | " --rdp-tls-cert=FILE\tThe file containing the certificate for TLS encryption\n" |
| 5100 | " --rdp-tls-key=FILE\tThe file containing the private key for TLS encryption\n" |
| 5101 | "\n"); |
Hardening | c077a84 | 2013-07-08 00:51:35 +0200 | [diff] [blame] | 5102 | #endif |
| 5103 | |
Bryce Harrington | 3e3b59e | 2014-11-19 15:06:19 -0800 | [diff] [blame] | 5104 | #if defined(BUILD_HEADLESS_COMPOSITOR) |
| 5105 | fprintf(stderr, |
| 5106 | "Options for headless-backend.so:\n\n" |
| 5107 | " --width=WIDTH\t\tWidth of memory surface\n" |
| 5108 | " --height=HEIGHT\tHeight of memory surface\n" |
| 5109 | " --transform=TR\tThe output transformation, TR is one of:\n" |
| 5110 | "\tnormal 90 180 270 flipped flipped-90 flipped-180 flipped-270\n" |
| 5111 | " --use-pixman\t\tUse the pixman (CPU) renderer (default: no rendering)\n\n"); |
| 5112 | #endif |
| 5113 | |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 5114 | exit(error_code); |
| 5115 | } |
| 5116 | |
Peter Maatman | e5b42e4 | 2013-03-27 22:38:53 +0100 | [diff] [blame] | 5117 | static void |
| 5118 | catch_signals(void) |
| 5119 | { |
| 5120 | struct sigaction action; |
| 5121 | |
| 5122 | action.sa_flags = SA_SIGINFO | SA_RESETHAND; |
| 5123 | action.sa_sigaction = on_caught_signal; |
| 5124 | sigemptyset(&action.sa_mask); |
| 5125 | sigaction(SIGSEGV, &action, NULL); |
| 5126 | sigaction(SIGABRT, &action, NULL); |
| 5127 | } |
| 5128 | |
Jason Ekstrand | 923bfe6 | 2014-04-02 19:53:58 -0500 | [diff] [blame] | 5129 | static void |
| 5130 | handle_primary_client_destroyed(struct wl_listener *listener, void *data) |
| 5131 | { |
| 5132 | struct wl_client *client = data; |
| 5133 | |
| 5134 | weston_log("Primary client died. Closing...\n"); |
| 5135 | |
| 5136 | wl_display_terminate(wl_client_get_display(client)); |
| 5137 | } |
| 5138 | |
Ryo Munakata | d8deff6 | 2014-09-06 07:32:05 +0900 | [diff] [blame] | 5139 | static char * |
| 5140 | weston_choose_default_backend(void) |
| 5141 | { |
| 5142 | char *backend = NULL; |
| 5143 | |
| 5144 | if (getenv("WAYLAND_DISPLAY") || getenv("WAYLAND_SOCKET")) |
| 5145 | backend = strdup("wayland-backend.so"); |
| 5146 | else if (getenv("DISPLAY")) |
| 5147 | backend = strdup("x11-backend.so"); |
| 5148 | else |
| 5149 | backend = strdup(WESTON_NATIVE_BACKEND); |
| 5150 | |
| 5151 | return backend; |
| 5152 | } |
| 5153 | |
| 5154 | static int |
| 5155 | weston_create_listening_socket(struct wl_display *display, const char *socket_name) |
| 5156 | { |
| 5157 | if (socket_name) { |
| 5158 | if (wl_display_add_socket(display, socket_name)) { |
| 5159 | weston_log("fatal: failed to add socket: %m\n"); |
| 5160 | return -1; |
| 5161 | } |
| 5162 | } else { |
| 5163 | socket_name = wl_display_add_socket_auto(display); |
| 5164 | if (!socket_name) { |
| 5165 | weston_log("fatal: failed to add socket: %m\n"); |
| 5166 | return -1; |
| 5167 | } |
| 5168 | } |
| 5169 | |
| 5170 | setenv("WAYLAND_DISPLAY", socket_name, 1); |
| 5171 | |
| 5172 | return 0; |
| 5173 | } |
| 5174 | |
Derek Foreman | 64a3df0 | 2014-10-23 12:24:18 -0500 | [diff] [blame] | 5175 | static const struct { const char *name; uint32_t token; } transforms[] = { |
| 5176 | { "normal", WL_OUTPUT_TRANSFORM_NORMAL }, |
| 5177 | { "90", WL_OUTPUT_TRANSFORM_90 }, |
| 5178 | { "180", WL_OUTPUT_TRANSFORM_180 }, |
| 5179 | { "270", WL_OUTPUT_TRANSFORM_270 }, |
| 5180 | { "flipped", WL_OUTPUT_TRANSFORM_FLIPPED }, |
| 5181 | { "flipped-90", WL_OUTPUT_TRANSFORM_FLIPPED_90 }, |
| 5182 | { "flipped-180", WL_OUTPUT_TRANSFORM_FLIPPED_180 }, |
| 5183 | { "flipped-270", WL_OUTPUT_TRANSFORM_FLIPPED_270 }, |
| 5184 | }; |
| 5185 | |
| 5186 | WL_EXPORT int |
| 5187 | weston_parse_transform(const char *transform, uint32_t *out) |
| 5188 | { |
| 5189 | unsigned int i; |
| 5190 | |
| 5191 | for (i = 0; i < ARRAY_LENGTH(transforms); i++) |
| 5192 | if (strcmp(transforms[i].name, transform) == 0) { |
| 5193 | *out = transforms[i].token; |
| 5194 | return 0; |
| 5195 | } |
| 5196 | |
| 5197 | *out = WL_OUTPUT_TRANSFORM_NORMAL; |
| 5198 | return -1; |
| 5199 | } |
| 5200 | |
| 5201 | WL_EXPORT const char * |
| 5202 | weston_transform_to_string(uint32_t output_transform) |
| 5203 | { |
| 5204 | unsigned int i; |
| 5205 | |
| 5206 | for (i = 0; i < ARRAY_LENGTH(transforms); i++) |
| 5207 | if (transforms[i].token == output_transform) |
| 5208 | return transforms[i].name; |
| 5209 | |
| 5210 | return "<illegal value>"; |
| 5211 | } |
| 5212 | |
| 5213 | |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 5214 | int main(int argc, char *argv[]) |
| 5215 | { |
Pekka Paalanen | 3ab7269 | 2012-06-08 17:27:28 +0300 | [diff] [blame] | 5216 | int ret = EXIT_SUCCESS; |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 5217 | struct wl_display *display; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5218 | struct weston_compositor *ec; |
Pekka Paalanen | 51c769f | 2012-01-02 16:03:26 +0200 | [diff] [blame] | 5219 | struct wl_event_source *signals[4]; |
Kristian Høgsberg | 50dc698 | 2010-12-01 16:43:56 -0500 | [diff] [blame] | 5220 | struct wl_event_loop *loop; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5221 | struct weston_compositor |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 5222 | *(*backend_init)(struct wl_display *display, |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 5223 | int *argc, char *argv[], |
| 5224 | struct weston_config *config); |
Jason Ekstrand | 923bfe6 | 2014-04-02 19:53:58 -0500 | [diff] [blame] | 5225 | int i, fd; |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 5226 | char *backend = NULL; |
Jason Ekstrand | a985da4 | 2013-08-22 17:28:03 -0500 | [diff] [blame] | 5227 | char *shell = NULL; |
Ondřej Majerech | 03db71c | 2014-09-11 15:53:15 +0200 | [diff] [blame] | 5228 | char *modules = NULL; |
| 5229 | char *option_modules = NULL; |
Martin Minarik | 19e6f26 | 2012-06-07 13:08:46 +0200 | [diff] [blame] | 5230 | char *log = NULL; |
Jason Ekstrand | 923bfe6 | 2014-04-02 19:53:58 -0500 | [diff] [blame] | 5231 | char *server_socket = NULL, *end; |
Frederic Plourde | 4a84c83 | 2014-10-30 15:06:34 -0400 | [diff] [blame] | 5232 | int32_t idle_time = -1; |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 5233 | int32_t help = 0; |
Ryo Munakata | 03faed2 | 2014-09-06 07:32:51 +0900 | [diff] [blame] | 5234 | char *socket_name = NULL; |
Scott Moreau | 1224514 | 2012-08-29 15:15:58 -0600 | [diff] [blame] | 5235 | int32_t version = 0; |
Pekka Paalanen | 588bee1 | 2014-05-07 16:26:25 +0300 | [diff] [blame] | 5236 | int32_t noconfig = 0; |
Giulio Camuffo | de7e2b3 | 2014-08-28 19:44:10 +0300 | [diff] [blame] | 5237 | int32_t numlock_on; |
Pekka Paalanen | 588bee1 | 2014-05-07 16:26:25 +0300 | [diff] [blame] | 5238 | struct weston_config *config = NULL; |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 5239 | struct weston_config_section *section; |
Jason Ekstrand | 923bfe6 | 2014-04-02 19:53:58 -0500 | [diff] [blame] | 5240 | struct wl_client *primary_client; |
| 5241 | struct wl_listener primary_client_destroyed; |
Giulio Camuffo | de7e2b3 | 2014-08-28 19:44:10 +0300 | [diff] [blame] | 5242 | struct weston_seat *seat; |
Kristian Høgsberg | d34912c | 2011-05-02 10:36:04 -0400 | [diff] [blame] | 5243 | |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 5244 | const struct weston_option core_options[] = { |
Ryo Munakata | 03faed2 | 2014-09-06 07:32:51 +0900 | [diff] [blame] | 5245 | { WESTON_OPTION_STRING, "backend", 'B', &backend }, |
| 5246 | { WESTON_OPTION_STRING, "shell", 0, &shell }, |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 5247 | { WESTON_OPTION_STRING, "socket", 'S', &socket_name }, |
| 5248 | { WESTON_OPTION_INTEGER, "idle-time", 'i', &idle_time }, |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 5249 | { WESTON_OPTION_STRING, "modules", 0, &option_modules }, |
Martin Minarik | 19e6f26 | 2012-06-07 13:08:46 +0200 | [diff] [blame] | 5250 | { WESTON_OPTION_STRING, "log", 0, &log }, |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 5251 | { WESTON_OPTION_BOOLEAN, "help", 'h', &help }, |
Scott Moreau | 1224514 | 2012-08-29 15:15:58 -0600 | [diff] [blame] | 5252 | { WESTON_OPTION_BOOLEAN, "version", 0, &version }, |
Pekka Paalanen | 588bee1 | 2014-05-07 16:26:25 +0300 | [diff] [blame] | 5253 | { WESTON_OPTION_BOOLEAN, "no-config", 0, &noconfig }, |
Kristian Høgsberg | d34912c | 2011-05-02 10:36:04 -0400 | [diff] [blame] | 5254 | }; |
Kristian Høgsberg | d653126 | 2008-12-12 11:06:18 -0500 | [diff] [blame] | 5255 | |
Kristian Høgsberg | 4172f66 | 2013-02-20 15:27:49 -0500 | [diff] [blame] | 5256 | parse_options(core_options, ARRAY_LENGTH(core_options), &argc, argv); |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 5257 | |
Kristian Høgsberg | 572c2ff | 2012-07-30 15:41:14 -0400 | [diff] [blame] | 5258 | if (help) |
| 5259 | usage(EXIT_SUCCESS); |
| 5260 | |
Scott Moreau | 1224514 | 2012-08-29 15:15:58 -0600 | [diff] [blame] | 5261 | if (version) { |
| 5262 | printf(PACKAGE_STRING "\n"); |
| 5263 | return EXIT_SUCCESS; |
| 5264 | } |
| 5265 | |
Rafal Mielniczuk | 6e0a7d8 | 2012-06-09 15:10:28 +0200 | [diff] [blame] | 5266 | weston_log_file_open(log); |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 5267 | |
Pekka Paalanen | bce4c2b | 2012-06-11 14:04:21 +0300 | [diff] [blame] | 5268 | weston_log("%s\n" |
| 5269 | STAMP_SPACE "%s\n" |
| 5270 | STAMP_SPACE "Bug reports to: %s\n" |
| 5271 | STAMP_SPACE "Build: %s\n", |
| 5272 | PACKAGE_STRING, PACKAGE_URL, PACKAGE_BUGREPORT, |
Kristian Høgsberg | 23cf9eb | 2012-06-11 12:06:30 -0400 | [diff] [blame] | 5273 | BUILD_ID); |
Pekka Paalanen | 7f4d1a3 | 2012-06-11 14:06:03 +0300 | [diff] [blame] | 5274 | log_uname(); |
Kristian Høgsberg | a411c8b | 2012-06-08 16:16:52 -0400 | [diff] [blame] | 5275 | |
Martin Minarik | 37032f8 | 2012-06-18 20:15:18 +0200 | [diff] [blame] | 5276 | verify_xdg_runtime_dir(); |
| 5277 | |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 5278 | display = wl_display_create(); |
| 5279 | |
Tiago Vignatti | 2116b89 | 2011-08-08 05:52:59 -0700 | [diff] [blame] | 5280 | loop = wl_display_get_event_loop(display); |
Pekka Paalanen | 51c769f | 2012-01-02 16:03:26 +0200 | [diff] [blame] | 5281 | signals[0] = wl_event_loop_add_signal(loop, SIGTERM, on_term_signal, |
| 5282 | display); |
| 5283 | signals[1] = wl_event_loop_add_signal(loop, SIGINT, on_term_signal, |
| 5284 | display); |
| 5285 | signals[2] = wl_event_loop_add_signal(loop, SIGQUIT, on_term_signal, |
| 5286 | display); |
Tiago Vignatti | 2116b89 | 2011-08-08 05:52:59 -0700 | [diff] [blame] | 5287 | |
| 5288 | wl_list_init(&child_process_list); |
Pekka Paalanen | 51c769f | 2012-01-02 16:03:26 +0200 | [diff] [blame] | 5289 | signals[3] = wl_event_loop_add_signal(loop, SIGCHLD, sigchld_handler, |
| 5290 | NULL); |
Kristian Høgsberg | a941022 | 2011-01-14 17:22:35 -0500 | [diff] [blame] | 5291 | |
Srivardhan Hebbar | ba2a36d | 2014-05-27 14:30:59 +0530 | [diff] [blame] | 5292 | if (!signals[0] || !signals[1] || !signals[2] || !signals[3]) { |
| 5293 | ret = EXIT_FAILURE; |
| 5294 | goto out_signals; |
| 5295 | } |
| 5296 | |
Pekka Paalanen | 588bee1 | 2014-05-07 16:26:25 +0300 | [diff] [blame] | 5297 | if (noconfig == 0) |
| 5298 | config = weston_config_parse("weston.ini"); |
Lubomir Rintel | ba44c6b | 2013-11-15 14:18:15 +0100 | [diff] [blame] | 5299 | if (config != NULL) { |
| 5300 | weston_log("Using config file '%s'\n", |
| 5301 | weston_config_get_full_path(config)); |
| 5302 | } else { |
| 5303 | weston_log("Starting with no config file.\n"); |
| 5304 | } |
| 5305 | section = weston_config_get_section(config, "core", NULL, NULL); |
| 5306 | |
Ryo Munakata | 03faed2 | 2014-09-06 07:32:51 +0900 | [diff] [blame] | 5307 | if (!backend) { |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 5308 | weston_config_section_get_string(section, "backend", &backend, |
| 5309 | NULL); |
Ryo Munakata | 03faed2 | 2014-09-06 07:32:51 +0900 | [diff] [blame] | 5310 | if (!backend) |
| 5311 | backend = weston_choose_default_backend(); |
| 5312 | } |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 5313 | |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 5314 | backend_init = weston_load_module(backend, "backend_init"); |
Srivardhan Hebbar | ba2a36d | 2014-05-27 14:30:59 +0530 | [diff] [blame] | 5315 | if (!backend_init) { |
| 5316 | ret = EXIT_FAILURE; |
| 5317 | goto out_signals; |
| 5318 | } |
Kristian Høgsberg | a941022 | 2011-01-14 17:22:35 -0500 | [diff] [blame] | 5319 | |
Kristian Høgsberg | 14e438c | 2013-05-26 21:48:14 -0400 | [diff] [blame] | 5320 | ec = backend_init(display, &argc, argv, config); |
Kristian Høgsberg | 841883b | 2008-12-05 11:19:56 -0500 | [diff] [blame] | 5321 | if (ec == NULL) { |
Pekka Paalanen | 3361639 | 2012-07-30 16:56:57 +0300 | [diff] [blame] | 5322 | weston_log("fatal: failed to create compositor\n"); |
Srivardhan Hebbar | ba2a36d | 2014-05-27 14:30:59 +0530 | [diff] [blame] | 5323 | ret = EXIT_FAILURE; |
| 5324 | goto out_signals; |
Kristian Høgsberg | 841883b | 2008-12-05 11:19:56 -0500 | [diff] [blame] | 5325 | } |
Kristian Høgsberg | 61a8251 | 2010-10-26 11:26:44 -0400 | [diff] [blame] | 5326 | |
Peter Maatman | e5b42e4 | 2013-03-27 22:38:53 +0100 | [diff] [blame] | 5327 | catch_signals(); |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 5328 | segv_compositor = ec; |
| 5329 | |
Frederic Plourde | 4a84c83 | 2014-10-30 15:06:34 -0400 | [diff] [blame] | 5330 | if (idle_time < 0) |
| 5331 | weston_config_section_get_int(section, "idle-time", &idle_time, -1); |
| 5332 | if (idle_time < 0) |
| 5333 | idle_time = 300; /* default idle timeout, in seconds */ |
Kristian Høgsberg | bcacef1 | 2012-03-11 21:05:57 -0400 | [diff] [blame] | 5334 | ec->idle_time = idle_time; |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 5335 | ec->default_pointer_grab = NULL; |
Frederic Plourde | c336f06 | 2014-10-29 14:44:33 -0400 | [diff] [blame] | 5336 | ec->exit_code = EXIT_SUCCESS; |
Pekka Paalanen | 7296e79 | 2011-12-07 16:22:00 +0200 | [diff] [blame] | 5337 | |
Kristian Høgsberg | cb4685b | 2013-02-20 15:37:49 -0500 | [diff] [blame] | 5338 | for (i = 1; i < argc; i++) |
| 5339 | weston_log("fatal: unhandled option: %s\n", argv[i]); |
| 5340 | if (argc > 1) { |
| 5341 | ret = EXIT_FAILURE; |
| 5342 | goto out; |
| 5343 | } |
| 5344 | |
Pekka Paalanen | 7bb6510 | 2013-05-22 18:03:04 +0300 | [diff] [blame] | 5345 | weston_compositor_log_capabilities(ec); |
| 5346 | |
Jason Ekstrand | 923bfe6 | 2014-04-02 19:53:58 -0500 | [diff] [blame] | 5347 | server_socket = getenv("WAYLAND_SERVER_SOCKET"); |
| 5348 | if (server_socket) { |
| 5349 | weston_log("Running with single client\n"); |
| 5350 | fd = strtol(server_socket, &end, 0); |
| 5351 | if (*end != '\0') |
| 5352 | fd = -1; |
| 5353 | } else { |
| 5354 | fd = -1; |
| 5355 | } |
| 5356 | |
| 5357 | if (fd != -1) { |
| 5358 | primary_client = wl_client_create(display, fd); |
| 5359 | if (!primary_client) { |
| 5360 | weston_log("fatal: failed to add client: %m\n"); |
| 5361 | ret = EXIT_FAILURE; |
| 5362 | goto out; |
| 5363 | } |
| 5364 | primary_client_destroyed.notify = |
| 5365 | handle_primary_client_destroyed; |
| 5366 | wl_client_add_destroy_listener(primary_client, |
| 5367 | &primary_client_destroyed); |
Ryo Munakata | d8deff6 | 2014-09-06 07:32:05 +0900 | [diff] [blame] | 5368 | } else if (weston_create_listening_socket(display, socket_name)) { |
| 5369 | ret = EXIT_FAILURE; |
| 5370 | goto out; |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 5371 | } |
| 5372 | |
Ryo Munakata | 03faed2 | 2014-09-06 07:32:51 +0900 | [diff] [blame] | 5373 | if (!shell) |
Jasper St. Pierre | e2f0f84 | 2014-07-17 13:55:44 -0400 | [diff] [blame] | 5374 | weston_config_section_get_string(section, "shell", &shell, |
| 5375 | "desktop-shell.so"); |
| 5376 | |
Ryo Munakata | 03faed2 | 2014-09-06 07:32:51 +0900 | [diff] [blame] | 5377 | if (load_modules(ec, shell, &argc, argv) < 0) |
Jasper St. Pierre | e2f0f84 | 2014-07-17 13:55:44 -0400 | [diff] [blame] | 5378 | goto out; |
Jasper St. Pierre | e2f0f84 | 2014-07-17 13:55:44 -0400 | [diff] [blame] | 5379 | |
| 5380 | weston_config_section_get_string(section, "modules", &modules, ""); |
Ryo Munakata | 03faed2 | 2014-09-06 07:32:51 +0900 | [diff] [blame] | 5381 | if (load_modules(ec, modules, &argc, argv) < 0) |
Jasper St. Pierre | e2f0f84 | 2014-07-17 13:55:44 -0400 | [diff] [blame] | 5382 | goto out; |
Jasper St. Pierre | e2f0f84 | 2014-07-17 13:55:44 -0400 | [diff] [blame] | 5383 | |
| 5384 | if (load_modules(ec, option_modules, &argc, argv) < 0) |
| 5385 | goto out; |
| 5386 | |
Giulio Camuffo | de7e2b3 | 2014-08-28 19:44:10 +0300 | [diff] [blame] | 5387 | section = weston_config_get_section(config, "keyboard", NULL, NULL); |
| 5388 | weston_config_section_get_bool(section, "numlock-on", &numlock_on, 0); |
| 5389 | if (numlock_on) { |
| 5390 | wl_list_for_each(seat, &ec->seat_list, link) { |
| 5391 | if (seat->keyboard) |
| 5392 | weston_keyboard_set_locks(seat->keyboard, |
| 5393 | WESTON_NUM_LOCK, |
| 5394 | WESTON_NUM_LOCK); |
| 5395 | } |
| 5396 | } |
| 5397 | |
Pekka Paalanen | c0444e3 | 2012-01-05 16:28:21 +0200 | [diff] [blame] | 5398 | weston_compositor_wake(ec); |
Kristian Høgsberg | 122912c | 2008-12-05 11:13:50 -0500 | [diff] [blame] | 5399 | |
Kristian Høgsberg | 7b884bc | 2012-07-31 14:32:01 -0400 | [diff] [blame] | 5400 | wl_display_run(display); |
| 5401 | |
Frederic Plourde | c336f06 | 2014-10-29 14:44:33 -0400 | [diff] [blame] | 5402 | /* Allow for setting return exit code after |
| 5403 | * wl_display_run returns normally. This is |
| 5404 | * useful for devs/testers and automated tests |
| 5405 | * that want to indicate failure status to |
| 5406 | * testing infrastructure above |
| 5407 | */ |
| 5408 | ret = ec->exit_code; |
| 5409 | |
Ryo Munakata | 03faed2 | 2014-09-06 07:32:51 +0900 | [diff] [blame] | 5410 | out: |
Pekka Paalanen | 0135abe | 2012-01-03 10:01:20 +0200 | [diff] [blame] | 5411 | /* prevent further rendering while shutting down */ |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 5412 | ec->state = WESTON_COMPOSITOR_OFFSCREEN; |
Pekka Paalanen | 0135abe | 2012-01-03 10:01:20 +0200 | [diff] [blame] | 5413 | |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5414 | wl_signal_emit(&ec->destroy_signal, ec); |
Pekka Paalanen | 3c64723 | 2011-12-22 13:43:43 +0200 | [diff] [blame] | 5415 | |
Daniel Stone | 855028f | 2012-05-01 20:37:10 +0100 | [diff] [blame] | 5416 | weston_compositor_xkb_destroy(ec); |
| 5417 | |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 5418 | ec->destroy(ec); |
Srivardhan Hebbar | ba2a36d | 2014-05-27 14:30:59 +0530 | [diff] [blame] | 5419 | |
| 5420 | out_signals: |
| 5421 | for (i = ARRAY_LENGTH(signals) - 1; i >= 0; i--) |
| 5422 | if (signals[i]) |
| 5423 | wl_event_source_remove(signals[i]); |
| 5424 | |
Tiago Vignatti | 9e2be08 | 2011-12-19 00:04:46 +0200 | [diff] [blame] | 5425 | wl_display_destroy(display); |
Kristian Høgsberg | caa6442 | 2010-12-01 16:52:15 -0500 | [diff] [blame] | 5426 | |
Martin Minarik | 19e6f26 | 2012-06-07 13:08:46 +0200 | [diff] [blame] | 5427 | weston_log_file_close(); |
| 5428 | |
Ryo Munakata | 03faed2 | 2014-09-06 07:32:51 +0900 | [diff] [blame] | 5429 | free(backend); |
| 5430 | free(shell); |
| 5431 | free(socket_name); |
| 5432 | free(option_modules); |
| 5433 | free(log); |
| 5434 | free(modules); |
| 5435 | |
Pekka Paalanen | 3ab7269 | 2012-06-08 17:27:28 +0300 | [diff] [blame] | 5436 | return ret; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 5437 | } |