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