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