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