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