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 | 925788f | 2018-04-19 14:20:01 +0300 | [diff] [blame] | 4 | * Copyright © 2012-2018 Collabora, Ltd. |
| 5 | * Copyright © 2017, 2018 General Electric Company |
Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 6 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 7 | * Permission is hereby granted, free of charge, to any person obtaining |
| 8 | * a copy of this software and associated documentation files (the |
| 9 | * "Software"), to deal in the Software without restriction, including |
| 10 | * without limitation the rights to use, copy, modify, merge, publish, |
| 11 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 12 | * permit persons to whom the Software is furnished to do so, subject to |
| 13 | * the following conditions: |
Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 14 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 15 | * The above copyright notice and this permission notice (including the |
| 16 | * next paragraph) shall be included in all copies or substantial |
| 17 | * portions of the Software. |
| 18 | * |
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 20 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 22 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 23 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 24 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 25 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 26 | * SOFTWARE. |
Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 27 | */ |
| 28 | |
Kristian Høgsberg | a941022 | 2011-01-14 17:22:35 -0500 | [diff] [blame] | 29 | #include "config.h" |
| 30 | |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 31 | #include <fcntl.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 32 | #include <stdio.h> |
| 33 | #include <string.h> |
| 34 | #include <stdlib.h> |
| 35 | #include <stdint.h> |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 36 | #include <limits.h> |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 37 | #include <stdarg.h> |
Benjamin Franzke | 6f5fc69 | 2011-06-21 19:34:19 +0200 | [diff] [blame] | 38 | #include <assert.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 39 | #include <sys/ioctl.h> |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 40 | #include <sys/mman.h> |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 41 | #include <sys/wait.h> |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 42 | #include <sys/socket.h> |
Martin Minarik | f12c287 | 2012-06-11 00:57:39 +0200 | [diff] [blame] | 43 | #include <sys/utsname.h> |
Martin Minarik | 37032f8 | 2012-06-18 20:15:18 +0200 | [diff] [blame] | 44 | #include <sys/stat.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 45 | #include <unistd.h> |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 46 | #include <math.h> |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 47 | #include <linux/input.h> |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 48 | #include <dlfcn.h> |
Kristian Høgsberg | 8544903 | 2011-05-02 12:11:07 -0400 | [diff] [blame] | 49 | #include <signal.h> |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 50 | #include <setjmp.h> |
Kristian Høgsberg | a411c8b | 2012-06-08 16:16:52 -0400 | [diff] [blame] | 51 | #include <sys/time.h> |
| 52 | #include <time.h> |
Pekka Paalanen | 23ade62 | 2014-08-27 13:31:26 +0300 | [diff] [blame] | 53 | #include <errno.h> |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 54 | #include <inttypes.h> |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 55 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 56 | #include "timeline.h" |
| 57 | |
Pekka Paalanen | 3d5d947 | 2019-03-28 16:28:47 +0200 | [diff] [blame] | 58 | #include <libweston/libweston.h> |
Marius Vlad | f4f4c2b | 2019-04-29 13:27:47 +0300 | [diff] [blame] | 59 | #include <libweston/weston-debug.h> |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 60 | #include "linux-dmabuf.h" |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 61 | #include "viewporter-server-protocol.h" |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 62 | #include "presentation-time-server-protocol.h" |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 63 | #include "xdg-output-unstable-v1-server-protocol.h" |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 64 | #include "linux-explicit-synchronization-unstable-v1-server-protocol.h" |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 65 | #include "linux-explicit-synchronization.h" |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 66 | #include "shared/fd-util.h" |
Jon Cruz | 35b2eaa | 2015-06-15 15:37:08 -0700 | [diff] [blame] | 67 | #include "shared/helpers.h" |
Jon Cruz | 4678bab | 2015-06-15 15:37:07 -0700 | [diff] [blame] | 68 | #include "shared/os-compatibility.h" |
Bryce Harrington | 25a2bdd | 2016-08-03 17:40:52 -0700 | [diff] [blame] | 69 | #include "shared/string-helpers.h" |
Pekka Paalanen | aa21f62 | 2015-07-03 15:44:50 +0300 | [diff] [blame] | 70 | #include "shared/timespec-util.h" |
Kristian Høgsberg | a411c8b | 2012-06-08 16:16:52 -0400 | [diff] [blame] | 71 | #include "git-version.h" |
Pekka Paalanen | cda1488 | 2019-04-04 15:41:02 +0300 | [diff] [blame] | 72 | #include <libweston/version.h> |
Pekka Paalanen | 27b377f | 2019-03-29 17:07:34 +0200 | [diff] [blame] | 73 | #include <libweston/plugin-registry.h> |
Marius Vlad | 00a6e01 | 2018-11-20 17:52:31 +0200 | [diff] [blame] | 74 | #include "pixel-formats.h" |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 75 | |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 76 | /** |
| 77 | * \defgroup head Head |
| 78 | * \defgroup output Output |
| 79 | * \defgroup compositor Compositor |
| 80 | */ |
| 81 | |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 82 | #define DEFAULT_REPAINT_WINDOW 7 /* milliseconds */ |
| 83 | |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 84 | static void |
Pekka Paalanen | d72bad2 | 2017-03-29 17:01:41 +0300 | [diff] [blame] | 85 | weston_output_update_matrix(struct weston_output *output); |
| 86 | |
| 87 | static void |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 88 | weston_output_transform_scale_init(struct weston_output *output, |
| 89 | uint32_t transform, uint32_t scale); |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 90 | |
Rob Bradford | 27b1793 | 2013-06-26 18:08:46 +0100 | [diff] [blame] | 91 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 92 | weston_compositor_build_view_list(struct weston_compositor *compositor); |
Rob Bradford | 27b1793 | 2013-06-26 18:08:46 +0100 | [diff] [blame] | 93 | |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 94 | static char * |
| 95 | weston_output_create_heads_string(struct weston_output *output); |
| 96 | |
Pekka Paalanen | 6528c03 | 2017-03-28 15:27:10 +0300 | [diff] [blame] | 97 | /** Send wl_output events for mode and scale changes |
| 98 | * |
| 99 | * \param head Send on all resources bound to this head. |
| 100 | * \param mode_changed If true, send the current mode. |
| 101 | * \param scale_changed If true, send the current scale. |
| 102 | */ |
| 103 | static void |
| 104 | weston_mode_switch_send_events(struct weston_head *head, |
| 105 | bool mode_changed, bool scale_changed) |
| 106 | { |
| 107 | struct weston_output *output = head->output; |
| 108 | struct wl_resource *resource; |
| 109 | int version; |
| 110 | |
| 111 | wl_resource_for_each(resource, &head->resource_list) { |
| 112 | if (mode_changed) { |
| 113 | wl_output_send_mode(resource, |
| 114 | output->current_mode->flags, |
| 115 | output->current_mode->width, |
| 116 | output->current_mode->height, |
| 117 | output->current_mode->refresh); |
| 118 | } |
| 119 | |
| 120 | version = wl_resource_get_version(resource); |
| 121 | if (version >= WL_OUTPUT_SCALE_SINCE_VERSION && scale_changed) |
| 122 | wl_output_send_scale(resource, output->current_scale); |
| 123 | |
| 124 | if (version >= WL_OUTPUT_DONE_SINCE_VERSION) |
| 125 | wl_output_send_done(resource); |
| 126 | } |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 127 | wl_resource_for_each(resource, &head->xdg_output_resource_list) { |
| 128 | zxdg_output_v1_send_logical_position(resource, |
| 129 | output->x, |
| 130 | output->y); |
| 131 | zxdg_output_v1_send_logical_size(resource, |
| 132 | output->width, |
| 133 | output->height); |
| 134 | zxdg_output_v1_send_done(resource); |
| 135 | } |
Pekka Paalanen | 6528c03 | 2017-03-28 15:27:10 +0300 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | static void |
| 139 | weston_mode_switch_finish(struct weston_output *output, |
| 140 | int mode_changed, int scale_changed) |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 141 | { |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 142 | struct weston_seat *seat; |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 143 | struct weston_head *head; |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 144 | pixman_region32_t old_output_region; |
Alexander Larsson | 355748e | 2013-05-28 16:23:38 +0200 | [diff] [blame] | 145 | |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 146 | pixman_region32_init(&old_output_region); |
| 147 | pixman_region32_copy(&old_output_region, &output->region); |
| 148 | |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 149 | /* Update output region and transformation matrix */ |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 150 | 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] | 151 | |
| 152 | pixman_region32_init(&output->previous_damage); |
| 153 | pixman_region32_init_rect(&output->region, output->x, output->y, |
| 154 | output->width, output->height); |
| 155 | |
| 156 | weston_output_update_matrix(output); |
| 157 | |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 158 | /* If a pointer falls outside the outputs new geometry, move it to its |
| 159 | * lower-right corner */ |
| 160 | wl_list_for_each(seat, &output->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 161 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 162 | int32_t x, y; |
| 163 | |
| 164 | if (!pointer) |
| 165 | continue; |
| 166 | |
| 167 | x = wl_fixed_to_int(pointer->x); |
| 168 | y = wl_fixed_to_int(pointer->y); |
| 169 | |
| 170 | if (!pixman_region32_contains_point(&old_output_region, |
| 171 | x, y, NULL) || |
| 172 | pixman_region32_contains_point(&output->region, |
| 173 | x, y, NULL)) |
| 174 | continue; |
| 175 | |
| 176 | if (x >= output->x + output->width) |
| 177 | x = output->x + output->width - 1; |
| 178 | if (y >= output->y + output->height) |
| 179 | y = output->y + output->height - 1; |
| 180 | |
| 181 | pointer->x = wl_fixed_from_int(x); |
| 182 | pointer->y = wl_fixed_from_int(y); |
| 183 | } |
| 184 | |
| 185 | pixman_region32_fini(&old_output_region); |
| 186 | |
Derek Foreman | dd4cd33 | 2014-11-10 10:29:59 -0600 | [diff] [blame] | 187 | if (!mode_changed && !scale_changed) |
| 188 | return; |
| 189 | |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 190 | /* notify clients of the changes */ |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 191 | wl_list_for_each(head, &output->head_list, output_link) |
| 192 | weston_mode_switch_send_events(head, |
| 193 | mode_changed, scale_changed); |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 194 | } |
| 195 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 196 | static void |
| 197 | weston_compositor_reflow_outputs(struct weston_compositor *compositor, |
| 198 | struct weston_output *resized_output, int delta_width); |
| 199 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 200 | /** |
| 201 | * \ingroup output |
| 202 | */ |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 203 | WL_EXPORT int |
| 204 | weston_output_mode_set_native(struct weston_output *output, |
| 205 | struct weston_mode *mode, |
| 206 | int32_t scale) |
| 207 | { |
| 208 | int ret; |
| 209 | int mode_changed = 0, scale_changed = 0; |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 210 | int32_t old_width; |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 211 | |
| 212 | if (!output->switch_mode) |
| 213 | return -1; |
| 214 | |
| 215 | if (!output->original_mode) { |
| 216 | mode_changed = 1; |
| 217 | ret = output->switch_mode(output, mode); |
| 218 | if (ret < 0) |
| 219 | return ret; |
| 220 | if (output->current_scale != scale) { |
| 221 | scale_changed = 1; |
| 222 | output->current_scale = scale; |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 226 | old_width = output->width; |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 227 | output->native_mode = mode; |
| 228 | output->native_scale = scale; |
| 229 | |
| 230 | weston_mode_switch_finish(output, mode_changed, scale_changed); |
| 231 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 232 | if (mode_changed || scale_changed) { |
| 233 | weston_compositor_reflow_outputs(output->compositor, output, output->width - old_width); |
| 234 | |
| 235 | wl_signal_emit(&output->compositor->output_resized_signal, output); |
| 236 | } |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 237 | return 0; |
| 238 | } |
| 239 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 240 | /** |
| 241 | * \ingroup output |
| 242 | */ |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 243 | WL_EXPORT int |
| 244 | weston_output_mode_switch_to_native(struct weston_output *output) |
| 245 | { |
| 246 | int ret; |
| 247 | int mode_changed = 0, scale_changed = 0; |
| 248 | |
| 249 | if (!output->switch_mode) |
| 250 | return -1; |
| 251 | |
| 252 | if (!output->original_mode) { |
| 253 | weston_log("already in the native mode\n"); |
| 254 | return -1; |
| 255 | } |
| 256 | /* the non fullscreen clients haven't seen a mode set since we |
| 257 | * switched into a temporary, so we need to notify them if the |
| 258 | * mode at that time is different from the native mode now. |
| 259 | */ |
| 260 | mode_changed = (output->original_mode != output->native_mode); |
| 261 | scale_changed = (output->original_scale != output->native_scale); |
| 262 | |
| 263 | ret = output->switch_mode(output, output->native_mode); |
| 264 | if (ret < 0) |
| 265 | return ret; |
| 266 | |
| 267 | output->current_scale = output->native_scale; |
| 268 | |
| 269 | output->original_mode = NULL; |
| 270 | output->original_scale = 0; |
| 271 | |
| 272 | weston_mode_switch_finish(output, mode_changed, scale_changed); |
| 273 | |
| 274 | return 0; |
| 275 | } |
| 276 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 277 | /** |
| 278 | * \ingroup output |
| 279 | */ |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 280 | WL_EXPORT int |
| 281 | weston_output_mode_switch_to_temporary(struct weston_output *output, |
| 282 | struct weston_mode *mode, |
| 283 | int32_t scale) |
| 284 | { |
| 285 | int ret; |
| 286 | |
| 287 | if (!output->switch_mode) |
| 288 | return -1; |
| 289 | |
| 290 | /* original_mode is the last mode non full screen clients have seen, |
| 291 | * so we shouldn't change it if we already have one set. |
| 292 | */ |
| 293 | if (!output->original_mode) { |
| 294 | output->original_mode = output->native_mode; |
| 295 | output->original_scale = output->native_scale; |
| 296 | } |
| 297 | ret = output->switch_mode(output, mode); |
| 298 | if (ret < 0) |
| 299 | return ret; |
| 300 | |
| 301 | output->current_scale = scale; |
| 302 | |
| 303 | weston_mode_switch_finish(output, 0, 0); |
| 304 | |
| 305 | return 0; |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 306 | } |
| 307 | |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 308 | static void |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 309 | region_init_infinite(pixman_region32_t *region) |
| 310 | { |
| 311 | pixman_region32_init_rect(region, INT32_MIN, INT32_MIN, |
| 312 | UINT32_MAX, UINT32_MAX); |
| 313 | } |
| 314 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 315 | static struct weston_subsurface * |
| 316 | weston_surface_to_subsurface(struct weston_surface *surface); |
| 317 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 318 | WL_EXPORT struct weston_view * |
| 319 | weston_view_create(struct weston_surface *surface) |
| 320 | { |
| 321 | struct weston_view *view; |
| 322 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 323 | view = zalloc(sizeof *view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 324 | if (view == NULL) |
| 325 | return NULL; |
| 326 | |
| 327 | view->surface = surface; |
Daniel Stone | fb4869d | 2016-12-09 16:27:54 +0000 | [diff] [blame] | 328 | view->plane = &surface->compositor->primary_plane; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 329 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 330 | /* Assign to surface */ |
| 331 | wl_list_insert(&surface->views, &view->surface_link); |
| 332 | |
| 333 | wl_signal_init(&view->destroy_signal); |
| 334 | wl_list_init(&view->link); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 335 | wl_list_init(&view->layer_link.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 336 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 337 | pixman_region32_init(&view->clip); |
| 338 | |
| 339 | view->alpha = 1.0; |
| 340 | pixman_region32_init(&view->transform.opaque); |
| 341 | |
| 342 | wl_list_init(&view->geometry.transformation_list); |
| 343 | wl_list_insert(&view->geometry.transformation_list, |
| 344 | &view->transform.position.link); |
| 345 | weston_matrix_init(&view->transform.position.matrix); |
| 346 | wl_list_init(&view->geometry.child_list); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 347 | pixman_region32_init(&view->geometry.scissor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 348 | pixman_region32_init(&view->transform.boundingbox); |
| 349 | view->transform.dirty = 1; |
| 350 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 351 | return view; |
| 352 | } |
| 353 | |
Jason Ekstrand | 108865d | 2014-06-26 10:04:49 -0700 | [diff] [blame] | 354 | struct weston_frame_callback { |
| 355 | struct wl_resource *resource; |
| 356 | struct wl_list link; |
| 357 | }; |
| 358 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 359 | struct weston_presentation_feedback { |
| 360 | struct wl_resource *resource; |
| 361 | |
| 362 | /* XXX: could use just wl_resource_get_link() instead */ |
| 363 | struct wl_list link; |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 364 | |
| 365 | /* The per-surface feedback flags */ |
| 366 | uint32_t psf_flags; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 367 | }; |
| 368 | |
| 369 | static void |
| 370 | weston_presentation_feedback_discard( |
| 371 | struct weston_presentation_feedback *feedback) |
| 372 | { |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 373 | wp_presentation_feedback_send_discarded(feedback->resource); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 374 | wl_resource_destroy(feedback->resource); |
| 375 | } |
| 376 | |
| 377 | static void |
| 378 | weston_presentation_feedback_discard_list(struct wl_list *list) |
| 379 | { |
| 380 | struct weston_presentation_feedback *feedback, *tmp; |
| 381 | |
| 382 | wl_list_for_each_safe(feedback, tmp, list, link) |
| 383 | weston_presentation_feedback_discard(feedback); |
| 384 | } |
| 385 | |
| 386 | static void |
| 387 | weston_presentation_feedback_present( |
| 388 | struct weston_presentation_feedback *feedback, |
| 389 | struct weston_output *output, |
| 390 | uint32_t refresh_nsec, |
| 391 | const struct timespec *ts, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 392 | uint64_t seq, |
| 393 | uint32_t flags) |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 394 | { |
| 395 | struct wl_client *client = wl_resource_get_client(feedback->resource); |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 396 | struct weston_head *head; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 397 | struct wl_resource *o; |
Alexandros Frantzis | 10d708d | 2017-12-13 13:27:54 +0200 | [diff] [blame] | 398 | uint32_t tv_sec_hi; |
| 399 | uint32_t tv_sec_lo; |
| 400 | uint32_t tv_nsec; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 401 | bool done = false; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 402 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 403 | wl_list_for_each(head, &output->head_list, output_link) { |
| 404 | wl_resource_for_each(o, &head->resource_list) { |
| 405 | if (wl_resource_get_client(o) != client) |
| 406 | continue; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 407 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 408 | wp_presentation_feedback_send_sync_output(feedback->resource, o); |
| 409 | done = true; |
| 410 | } |
| 411 | |
| 412 | /* For clone mode, send it for just one wl_output global, |
| 413 | * they are all equivalent anyway. |
| 414 | */ |
| 415 | if (done) |
| 416 | break; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 417 | } |
| 418 | |
Alexandros Frantzis | 10d708d | 2017-12-13 13:27:54 +0200 | [diff] [blame] | 419 | timespec_to_proto(ts, &tv_sec_hi, &tv_sec_lo, &tv_nsec); |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 420 | wp_presentation_feedback_send_presented(feedback->resource, |
Alexandros Frantzis | 10d708d | 2017-12-13 13:27:54 +0200 | [diff] [blame] | 421 | tv_sec_hi, tv_sec_lo, tv_nsec, |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 422 | refresh_nsec, |
| 423 | seq >> 32, seq & 0xffffffff, |
| 424 | flags | feedback->psf_flags); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 425 | wl_resource_destroy(feedback->resource); |
| 426 | } |
| 427 | |
| 428 | static void |
| 429 | weston_presentation_feedback_present_list(struct wl_list *list, |
| 430 | struct weston_output *output, |
| 431 | uint32_t refresh_nsec, |
| 432 | const struct timespec *ts, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 433 | uint64_t seq, |
| 434 | uint32_t flags) |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 435 | { |
| 436 | struct weston_presentation_feedback *feedback, *tmp; |
| 437 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 438 | assert(!(flags & WP_PRESENTATION_FEEDBACK_INVALID) || |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 439 | wl_list_empty(list)); |
| 440 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 441 | wl_list_for_each_safe(feedback, tmp, list, link) |
| 442 | weston_presentation_feedback_present(feedback, output, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 443 | refresh_nsec, ts, seq, |
| 444 | flags); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 445 | } |
| 446 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 447 | static void |
| 448 | surface_state_handle_buffer_destroy(struct wl_listener *listener, void *data) |
| 449 | { |
| 450 | struct weston_surface_state *state = |
| 451 | container_of(listener, struct weston_surface_state, |
| 452 | buffer_destroy_listener); |
| 453 | |
| 454 | state->buffer = NULL; |
| 455 | } |
| 456 | |
| 457 | static void |
| 458 | weston_surface_state_init(struct weston_surface_state *state) |
| 459 | { |
| 460 | state->newly_attached = 0; |
| 461 | state->buffer = NULL; |
| 462 | state->buffer_destroy_listener.notify = |
| 463 | surface_state_handle_buffer_destroy; |
| 464 | state->sx = 0; |
| 465 | state->sy = 0; |
| 466 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 467 | pixman_region32_init(&state->damage_surface); |
| 468 | pixman_region32_init(&state->damage_buffer); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 469 | pixman_region32_init(&state->opaque); |
| 470 | region_init_infinite(&state->input); |
| 471 | |
| 472 | wl_list_init(&state->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 473 | wl_list_init(&state->feedback_list); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 474 | |
| 475 | state->buffer_viewport.buffer.transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 476 | state->buffer_viewport.buffer.scale = 1; |
| 477 | state->buffer_viewport.buffer.src_width = wl_fixed_from_int(-1); |
| 478 | state->buffer_viewport.surface.width = -1; |
| 479 | state->buffer_viewport.changed = 0; |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 480 | |
| 481 | state->acquire_fence_fd = -1; |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 482 | |
| 483 | state->desired_protection = WESTON_HDCP_DISABLE; |
Ankit Nautiyal | 5cfe03c | 2019-03-28 15:05:42 +0530 | [diff] [blame] | 484 | state->protection_mode = WESTON_SURFACE_PROTECTION_MODE_RELAXED; |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | static void |
| 488 | weston_surface_state_fini(struct weston_surface_state *state) |
| 489 | { |
| 490 | struct weston_frame_callback *cb, *next; |
| 491 | |
| 492 | wl_list_for_each_safe(cb, next, |
| 493 | &state->frame_callback_list, link) |
| 494 | wl_resource_destroy(cb->resource); |
| 495 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 496 | weston_presentation_feedback_discard_list(&state->feedback_list); |
| 497 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 498 | pixman_region32_fini(&state->input); |
| 499 | pixman_region32_fini(&state->opaque); |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 500 | pixman_region32_fini(&state->damage_surface); |
| 501 | pixman_region32_fini(&state->damage_buffer); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 502 | |
| 503 | if (state->buffer) |
| 504 | wl_list_remove(&state->buffer_destroy_listener.link); |
| 505 | state->buffer = NULL; |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 506 | |
| 507 | fd_clear(&state->acquire_fence_fd); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 508 | weston_buffer_release_reference(&state->buffer_release_ref, NULL); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | static void |
| 512 | weston_surface_state_set_buffer(struct weston_surface_state *state, |
| 513 | struct weston_buffer *buffer) |
| 514 | { |
| 515 | if (state->buffer == buffer) |
| 516 | return; |
| 517 | |
| 518 | if (state->buffer) |
| 519 | wl_list_remove(&state->buffer_destroy_listener.link); |
| 520 | state->buffer = buffer; |
| 521 | if (state->buffer) |
| 522 | wl_signal_add(&state->buffer->destroy_signal, |
| 523 | &state->buffer_destroy_listener); |
| 524 | } |
| 525 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 526 | WL_EXPORT struct weston_surface * |
Kristian Høgsberg | 18c9300 | 2012-01-27 11:58:31 -0500 | [diff] [blame] | 527 | weston_surface_create(struct weston_compositor *compositor) |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 528 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 529 | struct weston_surface *surface; |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 530 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 531 | surface = zalloc(sizeof *surface); |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 532 | if (surface == NULL) |
| 533 | return NULL; |
| 534 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 535 | wl_signal_init(&surface->destroy_signal); |
Jonas Ådahl | 5d9ca27 | 2016-07-22 17:48:03 +0800 | [diff] [blame] | 536 | wl_signal_init(&surface->commit_signal); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 537 | |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 538 | surface->compositor = compositor; |
Giulio Camuffo | 13b85bd | 2013-08-13 23:10:14 +0200 | [diff] [blame] | 539 | surface->ref_count = 1; |
Kristian Høgsberg | 27803c6 | 2010-06-06 22:23:21 -0400 | [diff] [blame] | 540 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 541 | surface->buffer_viewport.buffer.transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 542 | surface->buffer_viewport.buffer.scale = 1; |
Pekka Paalanen | f0cad48 | 2014-03-14 14:38:16 +0200 | [diff] [blame] | 543 | surface->buffer_viewport.buffer.src_width = wl_fixed_from_int(-1); |
| 544 | surface->buffer_viewport.surface.width = -1; |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 545 | |
| 546 | weston_surface_state_init(&surface->pending); |
| 547 | |
Kristian Høgsberg | 20300ba | 2011-06-23 20:29:12 -0400 | [diff] [blame] | 548 | pixman_region32_init(&surface->damage); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 549 | pixman_region32_init(&surface->opaque); |
Pekka Paalanen | 8ec4ab6 | 2012-10-10 12:49:32 +0300 | [diff] [blame] | 550 | region_init_infinite(&surface->input); |
Kristian Høgsberg | 20300ba | 2011-06-23 20:29:12 -0400 | [diff] [blame] | 551 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 552 | wl_list_init(&surface->views); |
| 553 | |
| 554 | wl_list_init(&surface->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 555 | wl_list_init(&surface->feedback_list); |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 556 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 557 | wl_list_init(&surface->subsurface_list); |
| 558 | wl_list_init(&surface->subsurface_list_pending); |
| 559 | |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 560 | weston_matrix_init(&surface->buffer_to_surface_matrix); |
| 561 | weston_matrix_init(&surface->surface_to_buffer_matrix); |
| 562 | |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 563 | wl_list_init(&surface->pointer_constraints); |
| 564 | |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 565 | surface->acquire_fence_fd = -1; |
| 566 | |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 567 | surface->desired_protection = WESTON_HDCP_DISABLE; |
Ankit Nautiyal | 5cfe03c | 2019-03-28 15:05:42 +0530 | [diff] [blame] | 568 | surface->current_protection = WESTON_HDCP_DISABLE; |
| 569 | surface->protection_mode = WESTON_SURFACE_PROTECTION_MODE_RELAXED; |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 570 | |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 571 | return surface; |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 572 | } |
| 573 | |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 574 | WL_EXPORT void |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 575 | weston_surface_set_color(struct weston_surface *surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 576 | float red, float green, float blue, float alpha) |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 577 | { |
John Kåre Alsaker | 878f449 | 2012-11-13 19:10:23 +0100 | [diff] [blame] | 578 | surface->compositor->renderer->surface_set_color(surface, red, green, blue, alpha); |
Philipp Zabel | 195dade | 2018-09-03 19:44:59 +0200 | [diff] [blame] | 579 | surface->is_opaque = !(alpha < 1.0); |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 580 | } |
| 581 | |
Kristian Høgsberg | e4c1a5f | 2012-06-18 13:17:32 -0400 | [diff] [blame] | 582 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 583 | weston_view_to_global_float(struct weston_view *view, |
| 584 | float sx, float sy, float *x, float *y) |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 585 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 586 | if (view->transform.enabled) { |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 587 | struct weston_vector v = { { sx, sy, 0.0f, 1.0f } }; |
| 588 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 589 | weston_matrix_transform(&view->transform.matrix, &v); |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 590 | |
| 591 | if (fabsf(v.f[3]) < 1e-6) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 592 | weston_log("warning: numerical instability in " |
Scott Moreau | 088c62e | 2013-02-11 04:45:38 -0700 | [diff] [blame] | 593 | "%s(), divisor = %g\n", __func__, |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 594 | v.f[3]); |
| 595 | *x = 0; |
| 596 | *y = 0; |
| 597 | return; |
| 598 | } |
| 599 | |
| 600 | *x = v.f[0] / v.f[3]; |
| 601 | *y = v.f[1] / v.f[3]; |
| 602 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 603 | *x = sx + view->geometry.x; |
| 604 | *y = sy + view->geometry.y; |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 605 | } |
| 606 | } |
| 607 | |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 608 | WL_EXPORT void |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 609 | weston_transformed_coord(int width, int height, |
| 610 | enum wl_output_transform transform, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 611 | int32_t scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 612 | float sx, float sy, float *bx, float *by) |
| 613 | { |
| 614 | switch (transform) { |
| 615 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 616 | default: |
| 617 | *bx = sx; |
| 618 | *by = sy; |
| 619 | break; |
| 620 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 621 | *bx = width - sx; |
| 622 | *by = sy; |
| 623 | break; |
| 624 | case WL_OUTPUT_TRANSFORM_90: |
| 625 | *bx = height - sy; |
| 626 | *by = sx; |
| 627 | break; |
| 628 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 629 | *bx = height - sy; |
| 630 | *by = width - sx; |
| 631 | break; |
| 632 | case WL_OUTPUT_TRANSFORM_180: |
| 633 | *bx = width - sx; |
| 634 | *by = height - sy; |
| 635 | break; |
| 636 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 637 | *bx = sx; |
| 638 | *by = height - sy; |
| 639 | break; |
| 640 | case WL_OUTPUT_TRANSFORM_270: |
| 641 | *bx = sy; |
| 642 | *by = width - sx; |
| 643 | break; |
| 644 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 645 | *bx = sy; |
| 646 | *by = sx; |
| 647 | break; |
| 648 | } |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 649 | |
| 650 | *bx *= scale; |
| 651 | *by *= scale; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | WL_EXPORT pixman_box32_t |
| 655 | weston_transformed_rect(int width, int height, |
| 656 | enum wl_output_transform transform, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 657 | int32_t scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 658 | pixman_box32_t rect) |
| 659 | { |
| 660 | float x1, x2, y1, y2; |
| 661 | |
| 662 | pixman_box32_t ret; |
| 663 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 664 | weston_transformed_coord(width, height, transform, scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 665 | rect.x1, rect.y1, &x1, &y1); |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 666 | weston_transformed_coord(width, height, transform, scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 667 | rect.x2, rect.y2, &x2, &y2); |
| 668 | |
| 669 | if (x1 <= x2) { |
| 670 | ret.x1 = x1; |
| 671 | ret.x2 = x2; |
| 672 | } else { |
| 673 | ret.x1 = x2; |
| 674 | ret.x2 = x1; |
| 675 | } |
| 676 | |
| 677 | if (y1 <= y2) { |
| 678 | ret.y1 = y1; |
| 679 | ret.y2 = y2; |
| 680 | } else { |
| 681 | ret.y1 = y2; |
| 682 | ret.y2 = y1; |
| 683 | } |
| 684 | |
| 685 | return ret; |
| 686 | } |
| 687 | |
Derek Foreman | bc9a61c | 2015-11-18 16:32:30 -0600 | [diff] [blame] | 688 | /** Transform a region by a matrix, restricted to axis-aligned transformations |
| 689 | * |
| 690 | * Warning: This function does not work for projective, affine, or matrices |
| 691 | * that encode arbitrary rotations. Only 90-degree step rotations are |
| 692 | * supported. |
| 693 | */ |
| 694 | WL_EXPORT void |
| 695 | weston_matrix_transform_region(pixman_region32_t *dest, |
| 696 | struct weston_matrix *matrix, |
| 697 | pixman_region32_t *src) |
| 698 | { |
| 699 | pixman_box32_t *src_rects, *dest_rects; |
| 700 | int nrects, i; |
| 701 | |
| 702 | src_rects = pixman_region32_rectangles(src, &nrects); |
| 703 | dest_rects = malloc(nrects * sizeof(*dest_rects)); |
| 704 | if (!dest_rects) |
| 705 | return; |
| 706 | |
| 707 | for (i = 0; i < nrects; i++) { |
| 708 | struct weston_vector vec1 = {{ |
| 709 | src_rects[i].x1, src_rects[i].y1, 0, 1 |
| 710 | }}; |
| 711 | weston_matrix_transform(matrix, &vec1); |
| 712 | vec1.f[0] /= vec1.f[3]; |
| 713 | vec1.f[1] /= vec1.f[3]; |
| 714 | |
| 715 | struct weston_vector vec2 = {{ |
| 716 | src_rects[i].x2, src_rects[i].y2, 0, 1 |
| 717 | }}; |
| 718 | weston_matrix_transform(matrix, &vec2); |
| 719 | vec2.f[0] /= vec2.f[3]; |
| 720 | vec2.f[1] /= vec2.f[3]; |
| 721 | |
| 722 | if (vec1.f[0] < vec2.f[0]) { |
| 723 | dest_rects[i].x1 = floor(vec1.f[0]); |
| 724 | dest_rects[i].x2 = ceil(vec2.f[0]); |
| 725 | } else { |
| 726 | dest_rects[i].x1 = floor(vec2.f[0]); |
| 727 | dest_rects[i].x2 = ceil(vec1.f[0]); |
| 728 | } |
| 729 | |
Derek Foreman | bc9a61c | 2015-11-18 16:32:30 -0600 | [diff] [blame] | 730 | if (vec1.f[1] < vec2.f[1]) { |
| 731 | dest_rects[i].y1 = floor(vec1.f[1]); |
| 732 | dest_rects[i].y2 = ceil(vec2.f[1]); |
| 733 | } else { |
| 734 | dest_rects[i].y1 = floor(vec2.f[1]); |
| 735 | dest_rects[i].y2 = ceil(vec1.f[1]); |
| 736 | } |
| 737 | } |
| 738 | |
| 739 | pixman_region32_clear(dest); |
| 740 | pixman_region32_init_rects(dest, dest_rects, nrects); |
| 741 | free(dest_rects); |
| 742 | } |
| 743 | |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 744 | WL_EXPORT void |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 745 | weston_transformed_region(int width, int height, |
| 746 | enum wl_output_transform transform, |
| 747 | int32_t scale, |
| 748 | pixman_region32_t *src, pixman_region32_t *dest) |
| 749 | { |
| 750 | pixman_box32_t *src_rects, *dest_rects; |
| 751 | int nrects, i; |
| 752 | |
| 753 | if (transform == WL_OUTPUT_TRANSFORM_NORMAL && scale == 1) { |
| 754 | if (src != dest) |
| 755 | pixman_region32_copy(dest, src); |
| 756 | return; |
| 757 | } |
| 758 | |
| 759 | src_rects = pixman_region32_rectangles(src, &nrects); |
| 760 | dest_rects = malloc(nrects * sizeof(*dest_rects)); |
| 761 | if (!dest_rects) |
| 762 | return; |
| 763 | |
| 764 | if (transform == WL_OUTPUT_TRANSFORM_NORMAL) { |
| 765 | memcpy(dest_rects, src_rects, nrects * sizeof(*dest_rects)); |
| 766 | } else { |
| 767 | for (i = 0; i < nrects; i++) { |
| 768 | switch (transform) { |
| 769 | default: |
| 770 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 771 | dest_rects[i].x1 = src_rects[i].x1; |
| 772 | dest_rects[i].y1 = src_rects[i].y1; |
| 773 | dest_rects[i].x2 = src_rects[i].x2; |
| 774 | dest_rects[i].y2 = src_rects[i].y2; |
| 775 | break; |
| 776 | case WL_OUTPUT_TRANSFORM_90: |
| 777 | dest_rects[i].x1 = height - src_rects[i].y2; |
| 778 | dest_rects[i].y1 = src_rects[i].x1; |
| 779 | dest_rects[i].x2 = height - src_rects[i].y1; |
| 780 | dest_rects[i].y2 = src_rects[i].x2; |
| 781 | break; |
| 782 | case WL_OUTPUT_TRANSFORM_180: |
| 783 | dest_rects[i].x1 = width - src_rects[i].x2; |
| 784 | dest_rects[i].y1 = height - src_rects[i].y2; |
| 785 | dest_rects[i].x2 = width - src_rects[i].x1; |
| 786 | dest_rects[i].y2 = height - src_rects[i].y1; |
| 787 | break; |
| 788 | case WL_OUTPUT_TRANSFORM_270: |
| 789 | dest_rects[i].x1 = src_rects[i].y1; |
| 790 | dest_rects[i].y1 = width - src_rects[i].x2; |
| 791 | dest_rects[i].x2 = src_rects[i].y2; |
| 792 | dest_rects[i].y2 = width - src_rects[i].x1; |
| 793 | break; |
| 794 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 795 | dest_rects[i].x1 = width - src_rects[i].x2; |
| 796 | dest_rects[i].y1 = src_rects[i].y1; |
| 797 | dest_rects[i].x2 = width - src_rects[i].x1; |
| 798 | dest_rects[i].y2 = src_rects[i].y2; |
| 799 | break; |
| 800 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 801 | dest_rects[i].x1 = height - src_rects[i].y2; |
| 802 | dest_rects[i].y1 = width - src_rects[i].x2; |
| 803 | dest_rects[i].x2 = height - src_rects[i].y1; |
| 804 | dest_rects[i].y2 = width - src_rects[i].x1; |
| 805 | break; |
| 806 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 807 | dest_rects[i].x1 = src_rects[i].x1; |
| 808 | dest_rects[i].y1 = height - src_rects[i].y2; |
| 809 | dest_rects[i].x2 = src_rects[i].x2; |
| 810 | dest_rects[i].y2 = height - src_rects[i].y1; |
| 811 | break; |
| 812 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 813 | dest_rects[i].x1 = src_rects[i].y1; |
| 814 | dest_rects[i].y1 = src_rects[i].x1; |
| 815 | dest_rects[i].x2 = src_rects[i].y2; |
| 816 | dest_rects[i].y2 = src_rects[i].x2; |
| 817 | break; |
| 818 | } |
| 819 | } |
| 820 | } |
| 821 | |
| 822 | if (scale != 1) { |
| 823 | for (i = 0; i < nrects; i++) { |
| 824 | dest_rects[i].x1 *= scale; |
| 825 | dest_rects[i].x2 *= scale; |
| 826 | dest_rects[i].y1 *= scale; |
| 827 | dest_rects[i].y2 *= scale; |
| 828 | } |
| 829 | } |
| 830 | |
| 831 | pixman_region32_clear(dest); |
| 832 | pixman_region32_init_rects(dest, dest_rects, nrects); |
| 833 | free(dest_rects); |
| 834 | } |
| 835 | |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 836 | static void |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 837 | viewport_surface_to_buffer(struct weston_surface *surface, |
| 838 | float sx, float sy, float *bx, float *by) |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 839 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 840 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 841 | double src_width, src_height; |
| 842 | double src_x, src_y; |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 843 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 844 | if (vp->buffer.src_width == wl_fixed_from_int(-1)) { |
| 845 | if (vp->surface.width == -1) { |
| 846 | *bx = sx; |
| 847 | *by = sy; |
| 848 | return; |
| 849 | } |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 850 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 851 | src_x = 0.0; |
| 852 | src_y = 0.0; |
| 853 | src_width = surface->width_from_buffer; |
| 854 | src_height = surface->height_from_buffer; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 855 | } else { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 856 | src_x = wl_fixed_to_double(vp->buffer.src_x); |
| 857 | src_y = wl_fixed_to_double(vp->buffer.src_y); |
| 858 | src_width = wl_fixed_to_double(vp->buffer.src_width); |
| 859 | src_height = wl_fixed_to_double(vp->buffer.src_height); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 860 | } |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 861 | |
| 862 | *bx = sx * src_width / surface->width + src_x; |
| 863 | *by = sy * src_height / surface->height + src_y; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 864 | } |
| 865 | |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 866 | WL_EXPORT void |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 867 | weston_surface_to_buffer_float(struct weston_surface *surface, |
| 868 | float sx, float sy, float *bx, float *by) |
| 869 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 870 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
| 871 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 872 | /* first transform coordinates if the viewport is set */ |
| 873 | viewport_surface_to_buffer(surface, sx, sy, bx, by); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 874 | |
Jason Ekstrand | d0cebc3 | 2014-04-21 20:56:46 -0500 | [diff] [blame] | 875 | weston_transformed_coord(surface->width_from_buffer, |
| 876 | surface->height_from_buffer, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 877 | vp->buffer.transform, vp->buffer.scale, |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 878 | *bx, *by, bx, by); |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 879 | } |
| 880 | |
Derek Foreman | 9973967 | 2015-12-03 16:38:11 -0600 | [diff] [blame] | 881 | /** Transform a rectangle from surface coordinates to buffer coordinates |
| 882 | * |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 883 | * \param surface The surface to fetch wp_viewport and buffer transformation |
Derek Foreman | 9973967 | 2015-12-03 16:38:11 -0600 | [diff] [blame] | 884 | * from. |
| 885 | * \param rect The rectangle to transform. |
| 886 | * \return The transformed rectangle. |
| 887 | * |
| 888 | * Viewport and buffer transformations can only do translation, scaling, |
| 889 | * and rotations in 90-degree steps. Therefore the only loss in the |
| 890 | * conversion is coordinate rounding. |
| 891 | * |
| 892 | * However, some coordinate rounding takes place as an intermediate |
| 893 | * step before the buffer scale factor is applied, so the rectangle |
| 894 | * boundary may not be exactly as expected. |
| 895 | * |
| 896 | * This is OK for damage tracking since a little extra coverage is |
| 897 | * not a problem. |
| 898 | */ |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 899 | WL_EXPORT pixman_box32_t |
| 900 | weston_surface_to_buffer_rect(struct weston_surface *surface, |
| 901 | pixman_box32_t rect) |
| 902 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 903 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 904 | float xf, yf; |
| 905 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 906 | /* first transform box coordinates if the viewport is set */ |
| 907 | viewport_surface_to_buffer(surface, rect.x1, rect.y1, &xf, &yf); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 908 | rect.x1 = floorf(xf); |
| 909 | rect.y1 = floorf(yf); |
| 910 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 911 | viewport_surface_to_buffer(surface, rect.x2, rect.y2, &xf, &yf); |
Derek Foreman | e2e15ac | 2015-12-01 13:00:43 -0600 | [diff] [blame] | 912 | rect.x2 = ceilf(xf); |
| 913 | rect.y2 = ceilf(yf); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 914 | |
Jason Ekstrand | d0cebc3 | 2014-04-21 20:56:46 -0500 | [diff] [blame] | 915 | return weston_transformed_rect(surface->width_from_buffer, |
| 916 | surface->height_from_buffer, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 917 | vp->buffer.transform, vp->buffer.scale, |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 918 | rect); |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 919 | } |
| 920 | |
Pekka Paalanen | e54e31c | 2015-03-04 14:23:28 +0200 | [diff] [blame] | 921 | /** Transform a region from surface coordinates to buffer coordinates |
| 922 | * |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 923 | * \param surface The surface to fetch wp_viewport and buffer transformation |
Pekka Paalanen | e54e31c | 2015-03-04 14:23:28 +0200 | [diff] [blame] | 924 | * from. |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 925 | * \param[in] surface_region The region in surface coordinates. |
| 926 | * \param[out] buffer_region The region converted to buffer coordinates. |
Pekka Paalanen | e54e31c | 2015-03-04 14:23:28 +0200 | [diff] [blame] | 927 | * |
| 928 | * Buffer_region must be init'd, but will be completely overwritten. |
| 929 | * |
| 930 | * Viewport and buffer transformations can only do translation, scaling, |
| 931 | * and rotations in 90-degree steps. Therefore the only loss in the |
Derek Foreman | 9973967 | 2015-12-03 16:38:11 -0600 | [diff] [blame] | 932 | * conversion is from the coordinate rounding that takes place in |
| 933 | * \ref weston_surface_to_buffer_rect. |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 934 | * |
Pekka Paalanen | e54e31c | 2015-03-04 14:23:28 +0200 | [diff] [blame] | 935 | */ |
| 936 | WL_EXPORT void |
| 937 | weston_surface_to_buffer_region(struct weston_surface *surface, |
| 938 | pixman_region32_t *surface_region, |
| 939 | pixman_region32_t *buffer_region) |
| 940 | { |
| 941 | pixman_box32_t *src_rects, *dest_rects; |
| 942 | int nrects, i; |
| 943 | |
| 944 | src_rects = pixman_region32_rectangles(surface_region, &nrects); |
| 945 | dest_rects = malloc(nrects * sizeof(*dest_rects)); |
| 946 | if (!dest_rects) |
| 947 | return; |
| 948 | |
| 949 | for (i = 0; i < nrects; i++) { |
| 950 | dest_rects[i] = weston_surface_to_buffer_rect(surface, |
| 951 | src_rects[i]); |
| 952 | } |
| 953 | |
| 954 | pixman_region32_fini(buffer_region); |
| 955 | pixman_region32_init_rects(buffer_region, dest_rects, nrects); |
| 956 | free(dest_rects); |
| 957 | } |
| 958 | |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 959 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 960 | weston_view_move_to_plane(struct weston_view *view, |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 961 | struct weston_plane *plane) |
| 962 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 963 | if (view->plane == plane) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 964 | return; |
| 965 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 966 | weston_view_damage_below(view); |
| 967 | view->plane = plane; |
| 968 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 969 | } |
| 970 | |
Pekka Paalanen | 51723d5 | 2015-02-17 13:10:01 +0200 | [diff] [blame] | 971 | /** Inflict damage on the plane where the view is visible. |
| 972 | * |
| 973 | * \param view The view that causes the damage. |
| 974 | * |
| 975 | * If the view is currently on a plane (including the primary plane), |
| 976 | * take the view's boundingbox, subtract all the opaque views that cover it, |
| 977 | * and add the remaining region as damage to the plane. This corresponds |
| 978 | * to the damage inflicted to the plane if this view disappeared. |
| 979 | * |
| 980 | * A repaint is scheduled for this view. |
| 981 | * |
| 982 | * The region of all opaque views covering this view is stored in |
| 983 | * weston_view::clip and updated by view_accumulate_damage() during |
| 984 | * weston_output_repaint(). Specifically, that region matches the |
| 985 | * scenegraph as it was last painted. |
| 986 | */ |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 987 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 988 | weston_view_damage_below(struct weston_view *view) |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 989 | { |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 990 | pixman_region32_t damage; |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 991 | |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 992 | pixman_region32_init(&damage); |
Pekka Paalanen | 25c0ca5 | 2015-02-19 11:15:33 +0200 | [diff] [blame] | 993 | pixman_region32_subtract(&damage, &view->transform.boundingbox, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 994 | &view->clip); |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 995 | if (view->plane) |
| 996 | pixman_region32_union(&view->plane->damage, |
| 997 | &view->plane->damage, &damage); |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 998 | pixman_region32_fini(&damage); |
Kristian Høgsberg | a3a784a | 2013-11-13 21:33:43 -0800 | [diff] [blame] | 999 | weston_view_schedule_repaint(view); |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 1000 | } |
| 1001 | |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1002 | /** Send wl_surface.enter/leave events |
| 1003 | * |
| 1004 | * \param surface The surface. |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 1005 | * \param head A head of the entered/left output. |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1006 | * \param enter True if entered. |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 1007 | * \param leave True if left. |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1008 | * |
| 1009 | * Send the enter/leave events for all protocol objects bound to the given |
| 1010 | * output by the client owning the surface. |
| 1011 | */ |
| 1012 | static void |
| 1013 | weston_surface_send_enter_leave(struct weston_surface *surface, |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 1014 | struct weston_head *head, |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1015 | bool enter, |
| 1016 | bool leave) |
| 1017 | { |
| 1018 | struct wl_resource *wloutput; |
| 1019 | struct wl_client *client; |
| 1020 | |
| 1021 | assert(enter != leave); |
| 1022 | |
| 1023 | client = wl_resource_get_client(surface->resource); |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 1024 | wl_resource_for_each(wloutput, &head->resource_list) { |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1025 | if (wl_resource_get_client(wloutput) != client) |
| 1026 | continue; |
| 1027 | |
| 1028 | if (enter) |
| 1029 | wl_surface_send_enter(surface->resource, wloutput); |
| 1030 | if (leave) |
| 1031 | wl_surface_send_leave(surface->resource, wloutput); |
| 1032 | } |
| 1033 | } |
| 1034 | |
Ankit Nautiyal | f74c35b | 2019-04-03 19:21:58 +0530 | [diff] [blame] | 1035 | static void |
| 1036 | weston_surface_compute_protection(struct protected_surface *psurface) |
| 1037 | { |
| 1038 | enum weston_hdcp_protection min_protection; |
| 1039 | bool min_protection_valid = false; |
| 1040 | struct weston_surface *surface = psurface->surface; |
| 1041 | struct weston_output *output; |
| 1042 | |
| 1043 | wl_list_for_each(output, &surface->compositor->output_list, link) |
| 1044 | if (surface->output_mask & (1u << output->id)) { |
| 1045 | if (!min_protection_valid) { |
| 1046 | min_protection = output->current_protection; |
| 1047 | min_protection_valid = true; |
| 1048 | } |
| 1049 | if (output->current_protection < min_protection) |
| 1050 | min_protection = output->current_protection; |
| 1051 | } |
| 1052 | if (!min_protection_valid) |
| 1053 | min_protection = WESTON_HDCP_DISABLE; |
| 1054 | |
| 1055 | surface->current_protection = min_protection; |
| 1056 | weston_protected_surface_send_event(psurface, |
| 1057 | surface->current_protection); |
| 1058 | } |
| 1059 | |
| 1060 | static void |
| 1061 | notify_surface_protection_change(void *data) |
| 1062 | { |
| 1063 | struct weston_compositor *compositor = data; |
| 1064 | struct content_protection *cp; |
| 1065 | struct protected_surface *psurface; |
| 1066 | |
| 1067 | cp = compositor->content_protection; |
| 1068 | cp->surface_protection_update = NULL; |
| 1069 | |
| 1070 | /* Notify the clients, whose surfaces are changed */ |
| 1071 | wl_list_for_each(psurface, &cp->protected_list, link) |
| 1072 | if (psurface && psurface->surface) |
| 1073 | weston_surface_compute_protection(psurface); |
| 1074 | } |
| 1075 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1076 | /** |
| 1077 | * \param es The surface |
| 1078 | * \param mask The new set of outputs for the surface |
| 1079 | * |
| 1080 | * Sets the surface's set of outputs to the ones specified by |
| 1081 | * the new output mask provided. Identifies the outputs that |
| 1082 | * have changed, the posts enter and leave events for these |
| 1083 | * outputs as appropriate. |
| 1084 | */ |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1085 | static void |
| 1086 | weston_surface_update_output_mask(struct weston_surface *es, uint32_t mask) |
| 1087 | { |
| 1088 | uint32_t different = es->output_mask ^ mask; |
| 1089 | uint32_t entered = mask & different; |
| 1090 | uint32_t left = es->output_mask & different; |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1091 | uint32_t output_bit; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1092 | struct weston_output *output; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 1093 | struct weston_head *head; |
Ankit Nautiyal | f74c35b | 2019-04-03 19:21:58 +0530 | [diff] [blame] | 1094 | struct content_protection *cp; |
| 1095 | struct wl_event_loop *loop; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1096 | |
| 1097 | es->output_mask = mask; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1098 | if (es->resource == NULL) |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1099 | return; |
| 1100 | if (different == 0) |
| 1101 | return; |
| 1102 | |
| 1103 | wl_list_for_each(output, &es->compositor->output_list, link) { |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1104 | output_bit = 1u << output->id; |
| 1105 | if (!(output_bit & different)) |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1106 | continue; |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1107 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 1108 | wl_list_for_each(head, &output->head_list, output_link) { |
| 1109 | weston_surface_send_enter_leave(es, head, |
| 1110 | output_bit & entered, |
| 1111 | output_bit & left); |
| 1112 | } |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1113 | } |
Ankit Nautiyal | f74c35b | 2019-04-03 19:21:58 +0530 | [diff] [blame] | 1114 | /* |
| 1115 | * Change in surfaces' output mask might trigger a change in its |
| 1116 | * protection. |
| 1117 | */ |
| 1118 | loop = wl_display_get_event_loop(es->compositor->wl_display); |
| 1119 | cp = es->compositor->content_protection; |
| 1120 | if (!cp || cp->surface_protection_update) |
| 1121 | return; |
| 1122 | cp->surface_protection_update = wl_event_loop_add_idle(loop, |
| 1123 | notify_surface_protection_change, |
| 1124 | es->compositor); |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1125 | } |
| 1126 | |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 1127 | static void |
| 1128 | notify_view_output_destroy(struct wl_listener *listener, void *data) |
| 1129 | { |
| 1130 | struct weston_view *view = |
| 1131 | container_of(listener, |
| 1132 | struct weston_view, output_destroy_listener); |
| 1133 | |
| 1134 | view->output = NULL; |
| 1135 | view->output_destroy_listener.notify = NULL; |
| 1136 | } |
| 1137 | |
| 1138 | /** Set the primary output of the view |
| 1139 | * |
| 1140 | * \param view The view whose primary output to set |
| 1141 | * \param output The new primary output for the view |
| 1142 | * |
| 1143 | * Set \a output to be the primary output of the \a view. |
| 1144 | * |
| 1145 | * Notice that the assignment may be temporary; the primary output could be |
| 1146 | * automatically changed. Hence, one cannot rely on the value persisting. |
| 1147 | * |
| 1148 | * Passing NULL as /a output will set the primary output to NULL. |
| 1149 | */ |
| 1150 | WL_EXPORT void |
| 1151 | weston_view_set_output(struct weston_view *view, struct weston_output *output) |
| 1152 | { |
| 1153 | if (view->output_destroy_listener.notify) { |
| 1154 | wl_list_remove(&view->output_destroy_listener.link); |
| 1155 | view->output_destroy_listener.notify = NULL; |
| 1156 | } |
| 1157 | view->output = output; |
| 1158 | if (output) { |
| 1159 | view->output_destroy_listener.notify = |
| 1160 | notify_view_output_destroy; |
| 1161 | wl_signal_add(&output->destroy_signal, |
| 1162 | &view->output_destroy_listener); |
| 1163 | } |
| 1164 | } |
| 1165 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1166 | /** Recalculate which output(s) the surface has views displayed on |
| 1167 | * |
| 1168 | * \param es The surface to remap to outputs |
| 1169 | * |
| 1170 | * Finds the output that is showing the largest amount of one |
| 1171 | * of the surface's various views. This output becomes the |
Pekka Paalanen | 130ae6e | 2016-03-30 14:33:33 +0300 | [diff] [blame] | 1172 | * surface's primary output for vsync and frame callback purposes. |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1173 | * |
Pekka Paalanen | 130ae6e | 2016-03-30 14:33:33 +0300 | [diff] [blame] | 1174 | * Also notes all outputs of all of the surface's views |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1175 | * in the output_mask for the surface. |
| 1176 | */ |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1177 | static void |
| 1178 | weston_surface_assign_output(struct weston_surface *es) |
| 1179 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1180 | struct weston_output *new_output; |
| 1181 | struct weston_view *view; |
| 1182 | pixman_region32_t region; |
| 1183 | uint32_t max, area, mask; |
| 1184 | pixman_box32_t *e; |
| 1185 | |
| 1186 | new_output = NULL; |
| 1187 | max = 0; |
| 1188 | mask = 0; |
| 1189 | pixman_region32_init(®ion); |
| 1190 | wl_list_for_each(view, &es->views, surface_link) { |
| 1191 | if (!view->output) |
| 1192 | continue; |
| 1193 | |
| 1194 | pixman_region32_intersect(®ion, &view->transform.boundingbox, |
| 1195 | &view->output->region); |
| 1196 | |
| 1197 | e = pixman_region32_extents(®ion); |
| 1198 | area = (e->x2 - e->x1) * (e->y2 - e->y1); |
| 1199 | |
| 1200 | mask |= view->output_mask; |
| 1201 | |
| 1202 | if (area >= max) { |
| 1203 | new_output = view->output; |
| 1204 | max = area; |
| 1205 | } |
| 1206 | } |
| 1207 | pixman_region32_fini(®ion); |
| 1208 | |
| 1209 | es->output = new_output; |
| 1210 | weston_surface_update_output_mask(es, mask); |
| 1211 | } |
| 1212 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1213 | /** Recalculate which output(s) the view is displayed on |
| 1214 | * |
| 1215 | * \param ev The view to remap to outputs |
| 1216 | * |
| 1217 | * Identifies the set of outputs that the view is visible on, |
| 1218 | * noting them into the output_mask. The output that the view |
Pekka Paalanen | 130ae6e | 2016-03-30 14:33:33 +0300 | [diff] [blame] | 1219 | * is most visible on is set as the view's primary output. |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1220 | * |
| 1221 | * Also does the same for the view's surface. See |
| 1222 | * weston_surface_assign_output(). |
| 1223 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1224 | static void |
| 1225 | weston_view_assign_output(struct weston_view *ev) |
| 1226 | { |
| 1227 | struct weston_compositor *ec = ev->surface->compositor; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1228 | struct weston_output *output, *new_output; |
| 1229 | pixman_region32_t region; |
| 1230 | uint32_t max, area, mask; |
| 1231 | pixman_box32_t *e; |
| 1232 | |
| 1233 | new_output = NULL; |
| 1234 | max = 0; |
| 1235 | mask = 0; |
| 1236 | pixman_region32_init(®ion); |
| 1237 | wl_list_for_each(output, &ec->output_list, link) { |
Giulio Camuffo | 2f2a70c | 2015-07-12 10:52:32 +0300 | [diff] [blame] | 1238 | if (output->destroying) |
| 1239 | continue; |
| 1240 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1241 | pixman_region32_intersect(®ion, &ev->transform.boundingbox, |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1242 | &output->region); |
| 1243 | |
| 1244 | e = pixman_region32_extents(®ion); |
| 1245 | area = (e->x2 - e->x1) * (e->y2 - e->y1); |
| 1246 | |
| 1247 | if (area > 0) |
Bryce Harrington | 89324ce | 2015-12-23 18:38:07 -0800 | [diff] [blame] | 1248 | mask |= 1u << output->id; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1249 | |
| 1250 | if (area >= max) { |
| 1251 | new_output = output; |
| 1252 | max = area; |
| 1253 | } |
| 1254 | } |
| 1255 | pixman_region32_fini(®ion); |
| 1256 | |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 1257 | weston_view_set_output(ev, new_output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1258 | ev->output_mask = mask; |
| 1259 | |
| 1260 | weston_surface_assign_output(ev->surface); |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1261 | } |
| 1262 | |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 1263 | static void |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1264 | weston_view_to_view_map(struct weston_view *from, struct weston_view *to, |
| 1265 | int from_x, int from_y, int *to_x, int *to_y) |
| 1266 | { |
| 1267 | float x, y; |
| 1268 | |
| 1269 | weston_view_to_global_float(from, from_x, from_y, &x, &y); |
| 1270 | weston_view_from_global_float(to, x, y, &x, &y); |
| 1271 | |
| 1272 | *to_x = round(x); |
| 1273 | *to_y = round(y); |
| 1274 | } |
| 1275 | |
| 1276 | static void |
| 1277 | weston_view_transfer_scissor(struct weston_view *from, struct weston_view *to) |
| 1278 | { |
| 1279 | pixman_box32_t *a; |
| 1280 | pixman_box32_t b; |
| 1281 | |
| 1282 | a = pixman_region32_extents(&from->geometry.scissor); |
| 1283 | |
| 1284 | weston_view_to_view_map(from, to, a->x1, a->y1, &b.x1, &b.y1); |
| 1285 | weston_view_to_view_map(from, to, a->x2, a->y2, &b.x2, &b.y2); |
| 1286 | |
| 1287 | pixman_region32_fini(&to->geometry.scissor); |
| 1288 | pixman_region32_init_with_extents(&to->geometry.scissor, &b); |
| 1289 | } |
| 1290 | |
| 1291 | static void |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 1292 | view_compute_bbox(struct weston_view *view, const pixman_box32_t *inbox, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1293 | pixman_region32_t *bbox) |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1294 | { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1295 | float min_x = HUGE_VALF, min_y = HUGE_VALF; |
| 1296 | float max_x = -HUGE_VALF, max_y = -HUGE_VALF; |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1297 | int32_t s[4][2] = { |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 1298 | { inbox->x1, inbox->y1 }, |
| 1299 | { inbox->x1, inbox->y2 }, |
| 1300 | { inbox->x2, inbox->y1 }, |
| 1301 | { inbox->x2, inbox->y2 }, |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1302 | }; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1303 | float int_x, int_y; |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1304 | int i; |
| 1305 | |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 1306 | if (inbox->x1 == inbox->x2 || inbox->y1 == inbox->y2) { |
Pekka Paalanen | 7c7d464 | 2012-09-04 13:55:44 +0300 | [diff] [blame] | 1307 | /* avoid rounding empty bbox to 1x1 */ |
| 1308 | pixman_region32_init(bbox); |
| 1309 | return; |
| 1310 | } |
| 1311 | |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1312 | for (i = 0; i < 4; ++i) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1313 | float x, y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1314 | 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] | 1315 | if (x < min_x) |
| 1316 | min_x = x; |
| 1317 | if (x > max_x) |
| 1318 | max_x = x; |
| 1319 | if (y < min_y) |
| 1320 | min_y = y; |
| 1321 | if (y > max_y) |
| 1322 | max_y = y; |
| 1323 | } |
| 1324 | |
Pekka Paalanen | 219b982 | 2012-02-08 15:38:37 +0200 | [diff] [blame] | 1325 | int_x = floorf(min_x); |
| 1326 | int_y = floorf(min_y); |
| 1327 | pixman_region32_init_rect(bbox, int_x, int_y, |
| 1328 | ceilf(max_x) - int_x, ceilf(max_y) - int_y); |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1329 | } |
| 1330 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1331 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1332 | weston_view_update_transform_disable(struct weston_view *view) |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1333 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1334 | view->transform.enabled = 0; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1335 | |
Pekka Paalanen | cc2f868 | 2012-02-13 10:34:04 +0200 | [diff] [blame] | 1336 | /* round off fractions when not transformed */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1337 | view->geometry.x = roundf(view->geometry.x); |
| 1338 | view->geometry.y = roundf(view->geometry.y); |
Pekka Paalanen | cc2f868 | 2012-02-13 10:34:04 +0200 | [diff] [blame] | 1339 | |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1340 | /* Otherwise identity matrix, but with x and y translation. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1341 | view->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE; |
| 1342 | view->transform.position.matrix.d[12] = view->geometry.x; |
| 1343 | view->transform.position.matrix.d[13] = view->geometry.y; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1344 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1345 | view->transform.matrix = view->transform.position.matrix; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1346 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1347 | view->transform.inverse = view->transform.position.matrix; |
| 1348 | view->transform.inverse.d[12] = -view->geometry.x; |
| 1349 | view->transform.inverse.d[13] = -view->geometry.y; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1350 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1351 | pixman_region32_init_rect(&view->transform.boundingbox, |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1352 | 0, 0, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1353 | view->surface->width, |
| 1354 | view->surface->height); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1355 | if (view->geometry.scissor_enabled) |
| 1356 | pixman_region32_intersect(&view->transform.boundingbox, |
| 1357 | &view->transform.boundingbox, |
| 1358 | &view->geometry.scissor); |
| 1359 | |
| 1360 | pixman_region32_translate(&view->transform.boundingbox, |
| 1361 | view->geometry.x, view->geometry.y); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1362 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1363 | if (view->alpha == 1.0) { |
| 1364 | pixman_region32_copy(&view->transform.opaque, |
| 1365 | &view->surface->opaque); |
| 1366 | pixman_region32_translate(&view->transform.opaque, |
| 1367 | view->geometry.x, |
| 1368 | view->geometry.y); |
Kristian Høgsberg | 3b4af20 | 2012-02-28 09:19:39 -0500 | [diff] [blame] | 1369 | } |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | static int |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1373 | weston_view_update_transform_enable(struct weston_view *view) |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1374 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1375 | struct weston_view *parent = view->geometry.parent; |
| 1376 | struct weston_matrix *matrix = &view->transform.matrix; |
| 1377 | struct weston_matrix *inverse = &view->transform.inverse; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1378 | struct weston_transform *tform; |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1379 | pixman_region32_t surfregion; |
| 1380 | const pixman_box32_t *surfbox; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1381 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1382 | view->transform.enabled = 1; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1383 | |
| 1384 | /* Otherwise identity matrix, but with x and y translation. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1385 | view->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE; |
| 1386 | view->transform.position.matrix.d[12] = view->geometry.x; |
| 1387 | view->transform.position.matrix.d[13] = view->geometry.y; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1388 | |
| 1389 | weston_matrix_init(matrix); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1390 | wl_list_for_each(tform, &view->geometry.transformation_list, link) |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1391 | weston_matrix_multiply(matrix, &tform->matrix); |
| 1392 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1393 | if (parent) |
| 1394 | weston_matrix_multiply(matrix, &parent->transform.matrix); |
| 1395 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1396 | if (weston_matrix_invert(inverse, matrix) < 0) { |
| 1397 | /* Oops, bad total transformation, not invertible */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1398 | weston_log("error: weston_view %p" |
| 1399 | " transformation not invertible.\n", view); |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1400 | return -1; |
| 1401 | } |
| 1402 | |
Giulio Camuffo | 148c199 | 2016-09-04 18:50:46 +0300 | [diff] [blame] | 1403 | if (view->alpha == 1.0 && |
| 1404 | matrix->type == WESTON_MATRIX_TRANSFORM_TRANSLATE) { |
| 1405 | pixman_region32_copy(&view->transform.opaque, |
| 1406 | &view->surface->opaque); |
| 1407 | pixman_region32_translate(&view->transform.opaque, |
| 1408 | matrix->d[12], |
| 1409 | matrix->d[13]); |
| 1410 | } |
| 1411 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1412 | pixman_region32_init_rect(&surfregion, 0, 0, |
| 1413 | view->surface->width, view->surface->height); |
| 1414 | if (view->geometry.scissor_enabled) |
| 1415 | pixman_region32_intersect(&surfregion, &surfregion, |
| 1416 | &view->geometry.scissor); |
| 1417 | surfbox = pixman_region32_extents(&surfregion); |
| 1418 | |
| 1419 | view_compute_bbox(view, surfbox, &view->transform.boundingbox); |
| 1420 | pixman_region32_fini(&surfregion); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1421 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1422 | return 0; |
| 1423 | } |
| 1424 | |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1425 | static struct weston_layer * |
| 1426 | get_view_layer(struct weston_view *view) |
| 1427 | { |
| 1428 | if (view->parent_view) |
| 1429 | return get_view_layer(view->parent_view); |
| 1430 | return view->layer_link.layer; |
| 1431 | } |
| 1432 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1433 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1434 | weston_view_update_transform(struct weston_view *view) |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1435 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1436 | struct weston_view *parent = view->geometry.parent; |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1437 | struct weston_layer *layer; |
| 1438 | pixman_region32_t mask; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1439 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1440 | if (!view->transform.dirty) |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1441 | return; |
| 1442 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1443 | if (parent) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1444 | weston_view_update_transform(parent); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1445 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1446 | view->transform.dirty = 0; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1447 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1448 | weston_view_damage_below(view); |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 1449 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1450 | pixman_region32_fini(&view->transform.boundingbox); |
| 1451 | pixman_region32_fini(&view->transform.opaque); |
| 1452 | pixman_region32_init(&view->transform.opaque); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1453 | |
Pekka Paalanen | cd40362 | 2012-01-25 13:37:39 +0200 | [diff] [blame] | 1454 | /* transform.position is always in transformation_list */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1455 | if (view->geometry.transformation_list.next == |
| 1456 | &view->transform.position.link && |
| 1457 | view->geometry.transformation_list.prev == |
| 1458 | &view->transform.position.link && |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1459 | !parent) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1460 | weston_view_update_transform_disable(view); |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1461 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1462 | if (weston_view_update_transform_enable(view) < 0) |
| 1463 | weston_view_update_transform_disable(view); |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1464 | } |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 1465 | |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1466 | layer = get_view_layer(view); |
| 1467 | if (layer) { |
| 1468 | pixman_region32_init_with_extents(&mask, &layer->mask); |
Pekka Paalanen | 25c0ca5 | 2015-02-19 11:15:33 +0200 | [diff] [blame] | 1469 | pixman_region32_intersect(&view->transform.boundingbox, |
| 1470 | &view->transform.boundingbox, &mask); |
Pekka Paalanen | 8844bf2 | 2015-02-18 16:30:47 +0200 | [diff] [blame] | 1471 | pixman_region32_intersect(&view->transform.opaque, |
| 1472 | &view->transform.opaque, &mask); |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1473 | pixman_region32_fini(&mask); |
| 1474 | } |
| 1475 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1476 | if (parent) { |
| 1477 | if (parent->geometry.scissor_enabled) { |
| 1478 | view->geometry.scissor_enabled = true; |
| 1479 | weston_view_transfer_scissor(parent, view); |
| 1480 | } else { |
| 1481 | view->geometry.scissor_enabled = false; |
| 1482 | } |
| 1483 | } |
| 1484 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1485 | weston_view_damage_below(view); |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 1486 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1487 | weston_view_assign_output(view); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 1488 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1489 | wl_signal_emit(&view->surface->compositor->transform_signal, |
| 1490 | view->surface); |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1491 | } |
| 1492 | |
Pekka Paalanen | ddae03c | 2012-02-06 14:54:20 +0200 | [diff] [blame] | 1493 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1494 | weston_view_geometry_dirty(struct weston_view *view) |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 1495 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1496 | struct weston_view *child; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1497 | |
| 1498 | /* |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1499 | * The invariant: if view->geometry.dirty, then all views |
| 1500 | * in view->geometry.child_list have geometry.dirty too. |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1501 | * Corollary: if not parent->geometry.dirty, then all ancestors |
| 1502 | * are not dirty. |
| 1503 | */ |
| 1504 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1505 | if (view->transform.dirty) |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1506 | return; |
| 1507 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1508 | view->transform.dirty = 1; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1509 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1510 | wl_list_for_each(child, &view->geometry.child_list, |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1511 | geometry.parent_link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1512 | weston_view_geometry_dirty(child); |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 1513 | } |
| 1514 | |
| 1515 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1516 | weston_view_to_global_fixed(struct weston_view *view, |
| 1517 | wl_fixed_t vx, wl_fixed_t vy, |
| 1518 | wl_fixed_t *x, wl_fixed_t *y) |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1519 | { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1520 | float xf, yf; |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1521 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1522 | weston_view_to_global_float(view, |
| 1523 | wl_fixed_to_double(vx), |
| 1524 | wl_fixed_to_double(vy), |
| 1525 | &xf, &yf); |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1526 | *x = wl_fixed_from_double(xf); |
| 1527 | *y = wl_fixed_from_double(yf); |
| 1528 | } |
| 1529 | |
Kristian Høgsberg | ecf6ede | 2012-09-05 21:59:35 -0400 | [diff] [blame] | 1530 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1531 | weston_view_from_global_float(struct weston_view *view, |
| 1532 | float x, float y, float *vx, float *vy) |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1533 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1534 | if (view->transform.enabled) { |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1535 | struct weston_vector v = { { x, y, 0.0f, 1.0f } }; |
| 1536 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1537 | weston_matrix_transform(&view->transform.inverse, &v); |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1538 | |
| 1539 | if (fabsf(v.f[3]) < 1e-6) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1540 | weston_log("warning: numerical instability in " |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1541 | "weston_view_from_global(), divisor = %g\n", |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1542 | v.f[3]); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1543 | *vx = 0; |
| 1544 | *vy = 0; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1545 | return; |
| 1546 | } |
| 1547 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1548 | *vx = v.f[0] / v.f[3]; |
| 1549 | *vy = v.f[1] / v.f[3]; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1550 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1551 | *vx = x - view->geometry.x; |
| 1552 | *vy = y - view->geometry.y; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1553 | } |
| 1554 | } |
| 1555 | |
| 1556 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1557 | weston_view_from_global_fixed(struct weston_view *view, |
| 1558 | wl_fixed_t x, wl_fixed_t y, |
| 1559 | wl_fixed_t *vx, wl_fixed_t *vy) |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1560 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1561 | float vxf, vyf; |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1562 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1563 | weston_view_from_global_float(view, |
| 1564 | wl_fixed_to_double(x), |
| 1565 | wl_fixed_to_double(y), |
| 1566 | &vxf, &vyf); |
| 1567 | *vx = wl_fixed_from_double(vxf); |
| 1568 | *vy = wl_fixed_from_double(vyf); |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1572 | weston_view_from_global(struct weston_view *view, |
| 1573 | int32_t x, int32_t y, int32_t *vx, int32_t *vy) |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1574 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1575 | float vxf, vyf; |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1576 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1577 | weston_view_from_global_float(view, x, y, &vxf, &vyf); |
| 1578 | *vx = floorf(vxf); |
| 1579 | *vy = floorf(vyf); |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1580 | } |
| 1581 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1582 | /** |
| 1583 | * \param surface The surface to be repainted |
| 1584 | * |
| 1585 | * Marks the output(s) that the surface is shown on as needing to be |
| 1586 | * repainted. See weston_output_schedule_repaint(). |
| 1587 | */ |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1588 | WL_EXPORT void |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1589 | weston_surface_schedule_repaint(struct weston_surface *surface) |
| 1590 | { |
| 1591 | struct weston_output *output; |
| 1592 | |
| 1593 | wl_list_for_each(output, &surface->compositor->output_list, link) |
Bryce Harrington | 89324ce | 2015-12-23 18:38:07 -0800 | [diff] [blame] | 1594 | if (surface->output_mask & (1u << output->id)) |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1595 | weston_output_schedule_repaint(output); |
| 1596 | } |
| 1597 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1598 | /** |
| 1599 | * \param view The view to be repainted |
| 1600 | * |
| 1601 | * Marks the output(s) that the view is shown on as needing to be |
| 1602 | * repainted. See weston_output_schedule_repaint(). |
| 1603 | */ |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1604 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1605 | weston_view_schedule_repaint(struct weston_view *view) |
| 1606 | { |
| 1607 | struct weston_output *output; |
| 1608 | |
| 1609 | wl_list_for_each(output, &view->surface->compositor->output_list, link) |
Bryce Harrington | 89324ce | 2015-12-23 18:38:07 -0800 | [diff] [blame] | 1610 | if (view->output_mask & (1u << output->id)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1611 | weston_output_schedule_repaint(output); |
| 1612 | } |
| 1613 | |
Pekka Paalanen | e508ce6 | 2015-02-19 13:59:55 +0200 | [diff] [blame] | 1614 | /** |
| 1615 | * XXX: This function does it the wrong way. |
| 1616 | * surface->damage is the damage from the client, and causes |
| 1617 | * surface_flush_damage() to copy pixels. No window management action can |
| 1618 | * cause damage to the client-provided content, warranting re-upload! |
| 1619 | * |
| 1620 | * Instead of surface->damage, this function should record the damage |
| 1621 | * with all the views for this surface to avoid extraneous texture |
| 1622 | * uploads. |
| 1623 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1624 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1625 | weston_surface_damage(struct weston_surface *surface) |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 1626 | { |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1627 | pixman_region32_union_rect(&surface->damage, &surface->damage, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1628 | 0, 0, surface->width, |
| 1629 | surface->height); |
Pekka Paalanen | 2267d45 | 2012-01-26 13:12:45 +0200 | [diff] [blame] | 1630 | |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1631 | weston_surface_schedule_repaint(surface); |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 1632 | } |
| 1633 | |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 1634 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1635 | weston_view_set_position(struct weston_view *view, float x, float y) |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1636 | { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1637 | if (view->geometry.x == x && view->geometry.y == y) |
| 1638 | return; |
| 1639 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1640 | view->geometry.x = x; |
| 1641 | view->geometry.y = y; |
| 1642 | weston_view_geometry_dirty(view); |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1643 | } |
| 1644 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1645 | static void |
| 1646 | transform_parent_handle_parent_destroy(struct wl_listener *listener, |
| 1647 | void *data) |
| 1648 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1649 | struct weston_view *view = |
| 1650 | container_of(listener, struct weston_view, |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1651 | geometry.parent_destroy_listener); |
| 1652 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1653 | weston_view_set_transform_parent(view, NULL); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1654 | } |
| 1655 | |
| 1656 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1657 | weston_view_set_transform_parent(struct weston_view *view, |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1658 | struct weston_view *parent) |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1659 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1660 | if (view->geometry.parent) { |
| 1661 | wl_list_remove(&view->geometry.parent_destroy_listener.link); |
| 1662 | wl_list_remove(&view->geometry.parent_link); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1663 | |
| 1664 | if (!parent) |
| 1665 | view->geometry.scissor_enabled = false; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1666 | } |
| 1667 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1668 | view->geometry.parent = parent; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1669 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1670 | view->geometry.parent_destroy_listener.notify = |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1671 | transform_parent_handle_parent_destroy; |
| 1672 | if (parent) { |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1673 | wl_signal_add(&parent->destroy_signal, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1674 | &view->geometry.parent_destroy_listener); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1675 | wl_list_insert(&parent->geometry.child_list, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1676 | &view->geometry.parent_link); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1677 | } |
| 1678 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1679 | weston_view_geometry_dirty(view); |
| 1680 | } |
| 1681 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1682 | /** Set a clip mask rectangle on a view |
| 1683 | * |
| 1684 | * \param view The view to set the clip mask on. |
| 1685 | * \param x Top-left corner X coordinate of the clip rectangle. |
| 1686 | * \param y Top-left corner Y coordinate of the clip rectangle. |
| 1687 | * \param width Width of the clip rectangle, non-negative. |
| 1688 | * \param height Height of the clip rectangle, non-negative. |
| 1689 | * |
| 1690 | * A shell may set a clip mask rectangle on a view. Everything outside |
| 1691 | * the rectangle is cut away for input and output purposes: it is |
| 1692 | * not drawn and cannot be hit by hit-test based input like pointer |
| 1693 | * motion or touch-downs. Everything inside the rectangle will behave |
| 1694 | * normally. Clients are unaware of clipping. |
| 1695 | * |
Yong Bakos | 4c72e29 | 2016-04-28 11:59:10 -0500 | [diff] [blame] | 1696 | * The rectangle is set in surface-local coordinates. Setting a clip |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1697 | * mask rectangle does not affect the view position, the view is positioned |
| 1698 | * as it would be without a clip. The clip also does not change |
| 1699 | * weston_surface::width,height. |
| 1700 | * |
| 1701 | * The clip mask rectangle is part of transformation inheritance |
| 1702 | * (weston_view_set_transform_parent()). A clip set in the root of the |
| 1703 | * transformation inheritance tree will affect all views in the tree. |
| 1704 | * A clip can be set only on the root view. Attempting to set a clip |
| 1705 | * on view that has a transformation parent will fail. Assigning a parent |
| 1706 | * to a view that has a clip set will cause the clip to be forgotten. |
| 1707 | * |
| 1708 | * Because the clip mask is an axis-aligned rectangle, it poses restrictions |
| 1709 | * on the additional transformations in the child views. These transformations |
| 1710 | * may not rotate the coordinate axes, i.e., only translation and scaling |
| 1711 | * are allowed. Violating this restriction causes the clipping to malfunction. |
| 1712 | * Furthermore, using scaling may cause rounding errors in child clipping. |
| 1713 | * |
| 1714 | * The clip mask rectangle is not automatically adjusted based on |
| 1715 | * wl_surface.attach dx and dy arguments. |
| 1716 | * |
| 1717 | * A clip mask rectangle can be set only if the compositor capability |
| 1718 | * WESTON_CAP_VIEW_CLIP_MASK is present. |
| 1719 | * |
| 1720 | * This function sets the clip mask rectangle and schedules a repaint for |
| 1721 | * the view. |
| 1722 | */ |
| 1723 | WL_EXPORT void |
| 1724 | weston_view_set_mask(struct weston_view *view, |
| 1725 | int x, int y, int width, int height) |
| 1726 | { |
| 1727 | struct weston_compositor *compositor = view->surface->compositor; |
| 1728 | |
| 1729 | if (!(compositor->capabilities & WESTON_CAP_VIEW_CLIP_MASK)) { |
| 1730 | weston_log("%s not allowed without capability!\n", __func__); |
| 1731 | return; |
| 1732 | } |
| 1733 | |
| 1734 | if (view->geometry.parent) { |
| 1735 | weston_log("view %p has a parent, clip forbidden!\n", view); |
| 1736 | return; |
| 1737 | } |
| 1738 | |
| 1739 | if (width < 0 || height < 0) { |
| 1740 | weston_log("%s: illegal args %d, %d, %d, %d\n", __func__, |
| 1741 | x, y, width, height); |
| 1742 | return; |
| 1743 | } |
| 1744 | |
| 1745 | pixman_region32_fini(&view->geometry.scissor); |
| 1746 | pixman_region32_init_rect(&view->geometry.scissor, x, y, width, height); |
| 1747 | view->geometry.scissor_enabled = true; |
| 1748 | weston_view_geometry_dirty(view); |
| 1749 | weston_view_schedule_repaint(view); |
| 1750 | } |
| 1751 | |
| 1752 | /** Remove the clip mask from a view |
| 1753 | * |
| 1754 | * \param view The view to remove the clip mask from. |
| 1755 | * |
| 1756 | * Removed the clip mask rectangle and schedules a repaint. |
| 1757 | * |
| 1758 | * \sa weston_view_set_mask |
| 1759 | */ |
| 1760 | WL_EXPORT void |
| 1761 | weston_view_set_mask_infinite(struct weston_view *view) |
| 1762 | { |
| 1763 | view->geometry.scissor_enabled = false; |
| 1764 | weston_view_geometry_dirty(view); |
| 1765 | weston_view_schedule_repaint(view); |
| 1766 | } |
| 1767 | |
Armin Krezović | 0da12b8 | 2016-06-30 06:04:33 +0200 | [diff] [blame] | 1768 | /* Check if view should be displayed |
| 1769 | * |
| 1770 | * The indicator is set manually when assigning |
| 1771 | * a view to a surface. |
| 1772 | * |
| 1773 | * This needs reworking. See the thread starting at: |
| 1774 | * |
| 1775 | * https://lists.freedesktop.org/archives/wayland-devel/2016-June/029656.html |
| 1776 | */ |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 1777 | WL_EXPORT bool |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1778 | weston_view_is_mapped(struct weston_view *view) |
| 1779 | { |
Armin Krezović | 0da12b8 | 2016-06-30 06:04:33 +0200 | [diff] [blame] | 1780 | return view->is_mapped; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1781 | } |
| 1782 | |
Philipp Zabel | 70decd5 | 2018-09-03 20:11:15 +0200 | [diff] [blame] | 1783 | /* Check if view is opaque in specified region |
| 1784 | * |
| 1785 | * \param view The view to check for opacity. |
| 1786 | * \param region The region to check for opacity, in view coordinates. |
| 1787 | * |
| 1788 | * Returns true if the view is opaque in the specified region, because view |
| 1789 | * alpha is 1.0 and either the opaque region set by the client contains the |
| 1790 | * specified region, or the buffer pixel format or solid color is opaque. |
| 1791 | */ |
| 1792 | WL_EXPORT bool |
| 1793 | weston_view_is_opaque(struct weston_view *ev, pixman_region32_t *region) |
| 1794 | { |
| 1795 | pixman_region32_t r; |
| 1796 | bool ret = false; |
| 1797 | |
| 1798 | if (ev->alpha < 1.0) |
| 1799 | return false; |
| 1800 | |
| 1801 | if (ev->surface->is_opaque) |
| 1802 | return true; |
| 1803 | |
| 1804 | if (ev->transform.dirty) { |
| 1805 | weston_log("%s: transform dirty", __func__); |
| 1806 | return false; |
| 1807 | } |
| 1808 | |
| 1809 | pixman_region32_init(&r); |
| 1810 | pixman_region32_subtract(&r, region, &ev->transform.opaque); |
| 1811 | |
| 1812 | if (!pixman_region32_not_empty(&r)) |
| 1813 | ret = true; |
| 1814 | |
| 1815 | pixman_region32_fini(&r); |
| 1816 | |
| 1817 | return ret; |
| 1818 | } |
| 1819 | |
Armin Krezović | 0da12b8 | 2016-06-30 06:04:33 +0200 | [diff] [blame] | 1820 | /* Check if a surface has a view assigned to it |
| 1821 | * |
| 1822 | * The indicator is set manually when mapping |
| 1823 | * a surface and creating a view for it. |
| 1824 | * |
| 1825 | * This needs to go. See the thread starting at: |
| 1826 | * |
| 1827 | * https://lists.freedesktop.org/archives/wayland-devel/2016-June/029656.html |
| 1828 | * |
| 1829 | */ |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 1830 | WL_EXPORT bool |
Ander Conselvan de Oliveira | b8ab14f | 2012-03-27 17:36:36 +0300 | [diff] [blame] | 1831 | weston_surface_is_mapped(struct weston_surface *surface) |
| 1832 | { |
Armin Krezović | 0da12b8 | 2016-06-30 06:04:33 +0200 | [diff] [blame] | 1833 | return surface->is_mapped; |
Ander Conselvan de Oliveira | b8ab14f | 2012-03-27 17:36:36 +0300 | [diff] [blame] | 1834 | } |
| 1835 | |
Pekka Paalanen | da75ee1 | 2013-11-26 18:19:43 +0100 | [diff] [blame] | 1836 | static void |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 1837 | 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] | 1838 | { |
| 1839 | struct weston_view *view; |
| 1840 | |
| 1841 | if (surface->width == width && surface->height == height) |
| 1842 | return; |
| 1843 | |
| 1844 | surface->width = width; |
| 1845 | surface->height = height; |
| 1846 | |
| 1847 | wl_list_for_each(view, &surface->views, surface_link) |
| 1848 | weston_view_geometry_dirty(view); |
| 1849 | } |
| 1850 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 1851 | WL_EXPORT void |
| 1852 | weston_surface_set_size(struct weston_surface *surface, |
| 1853 | int32_t width, int32_t height) |
| 1854 | { |
| 1855 | assert(!surface->resource); |
| 1856 | surface_set_size(surface, width, height); |
| 1857 | } |
| 1858 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1859 | static int |
| 1860 | fixed_round_up_to_int(wl_fixed_t f) |
| 1861 | { |
| 1862 | return wl_fixed_to_int(wl_fixed_from_int(1) - 1 + f); |
| 1863 | } |
| 1864 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1865 | static void |
Pekka Paalanen | 59987fa | 2016-04-26 15:50:59 +0300 | [diff] [blame] | 1866 | convert_size_by_transform_scale(int32_t *width_out, int32_t *height_out, |
| 1867 | int32_t width, int32_t height, |
| 1868 | uint32_t transform, |
| 1869 | int32_t scale) |
| 1870 | { |
| 1871 | assert(scale > 0); |
| 1872 | |
| 1873 | switch (transform) { |
| 1874 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 1875 | case WL_OUTPUT_TRANSFORM_180: |
| 1876 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 1877 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 1878 | *width_out = width / scale; |
| 1879 | *height_out = height / scale; |
| 1880 | break; |
| 1881 | case WL_OUTPUT_TRANSFORM_90: |
| 1882 | case WL_OUTPUT_TRANSFORM_270: |
| 1883 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 1884 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 1885 | *width_out = height / scale; |
| 1886 | *height_out = width / scale; |
| 1887 | break; |
| 1888 | default: |
| 1889 | assert(0 && "invalid transform"); |
| 1890 | } |
| 1891 | } |
| 1892 | |
| 1893 | static void |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1894 | weston_surface_calculate_size_from_buffer(struct weston_surface *surface) |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1895 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 1896 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Pekka Paalanen | da75ee1 | 2013-11-26 18:19:43 +0100 | [diff] [blame] | 1897 | |
| 1898 | if (!surface->buffer_ref.buffer) { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1899 | surface->width_from_buffer = 0; |
| 1900 | surface->height_from_buffer = 0; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 1901 | return; |
| 1902 | } |
| 1903 | |
Pekka Paalanen | 59987fa | 2016-04-26 15:50:59 +0300 | [diff] [blame] | 1904 | convert_size_by_transform_scale(&surface->width_from_buffer, |
| 1905 | &surface->height_from_buffer, |
| 1906 | surface->buffer_ref.buffer->width, |
| 1907 | surface->buffer_ref.buffer->height, |
| 1908 | vp->buffer.transform, |
| 1909 | vp->buffer.scale); |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1910 | } |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1911 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1912 | static void |
| 1913 | weston_surface_update_size(struct weston_surface *surface) |
| 1914 | { |
| 1915 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
| 1916 | int32_t width, height; |
| 1917 | |
| 1918 | width = surface->width_from_buffer; |
| 1919 | height = surface->height_from_buffer; |
| 1920 | |
| 1921 | if (width != 0 && vp->surface.width != -1) { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1922 | surface_set_size(surface, |
| 1923 | vp->surface.width, vp->surface.height); |
| 1924 | return; |
| 1925 | } |
| 1926 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1927 | if (width != 0 && vp->buffer.src_width != wl_fixed_from_int(-1)) { |
Pekka Paalanen | e931721 | 2014-04-04 14:22:13 +0300 | [diff] [blame] | 1928 | int32_t w = fixed_round_up_to_int(vp->buffer.src_width); |
| 1929 | int32_t h = fixed_round_up_to_int(vp->buffer.src_height); |
| 1930 | |
| 1931 | surface_set_size(surface, w ?: 1, h ?: 1); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1932 | return; |
| 1933 | } |
| 1934 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 1935 | surface_set_size(surface, width, height); |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1936 | } |
| 1937 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 1938 | /** weston_compositor_get_time |
| 1939 | * \ingroup compositor |
| 1940 | */ |
Alexandros Frantzis | 409b01f | 2017-11-16 18:21:01 +0200 | [diff] [blame] | 1941 | WL_EXPORT void |
| 1942 | weston_compositor_get_time(struct timespec *time) |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 1943 | { |
Alexandros Frantzis | 409b01f | 2017-11-16 18:21:01 +0200 | [diff] [blame] | 1944 | clock_gettime(CLOCK_REALTIME, time); |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 1945 | } |
| 1946 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 1947 | /** weston_compositor_pick_view |
| 1948 | * \ingroup compositor |
| 1949 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1950 | WL_EXPORT struct weston_view * |
| 1951 | weston_compositor_pick_view(struct weston_compositor *compositor, |
| 1952 | wl_fixed_t x, wl_fixed_t y, |
| 1953 | wl_fixed_t *vx, wl_fixed_t *vy) |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 1954 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1955 | struct weston_view *view; |
Pekka Paalanen | fc22a52 | 2015-02-18 15:08:29 +0200 | [diff] [blame] | 1956 | wl_fixed_t view_x, view_y; |
| 1957 | int view_ix, view_iy; |
| 1958 | int ix = wl_fixed_to_int(x); |
| 1959 | int iy = wl_fixed_to_int(y); |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 1960 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1961 | wl_list_for_each(view, &compositor->view_list, link) { |
Pekka Paalanen | fc22a52 | 2015-02-18 15:08:29 +0200 | [diff] [blame] | 1962 | if (!pixman_region32_contains_point( |
| 1963 | &view->transform.boundingbox, ix, iy, NULL)) |
| 1964 | continue; |
| 1965 | |
| 1966 | weston_view_from_global_fixed(view, x, y, &view_x, &view_y); |
| 1967 | view_ix = wl_fixed_to_int(view_x); |
| 1968 | view_iy = wl_fixed_to_int(view_y); |
| 1969 | |
| 1970 | if (!pixman_region32_contains_point(&view->surface->input, |
| 1971 | view_ix, view_iy, NULL)) |
| 1972 | continue; |
| 1973 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1974 | if (view->geometry.scissor_enabled && |
| 1975 | !pixman_region32_contains_point(&view->geometry.scissor, |
| 1976 | view_ix, view_iy, NULL)) |
| 1977 | continue; |
| 1978 | |
Pekka Paalanen | fc22a52 | 2015-02-18 15:08:29 +0200 | [diff] [blame] | 1979 | *vx = view_x; |
| 1980 | *vy = view_y; |
| 1981 | return view; |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 1982 | } |
| 1983 | |
Derek Foreman | f9318d1 | 2015-05-11 15:40:11 -0500 | [diff] [blame] | 1984 | *vx = wl_fixed_from_int(-1000000); |
| 1985 | *vy = wl_fixed_from_int(-1000000); |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 1986 | return NULL; |
| 1987 | } |
| 1988 | |
| 1989 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1990 | weston_compositor_repick(struct weston_compositor *compositor) |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 1991 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1992 | struct weston_seat *seat; |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 1993 | |
Kristian Høgsberg | 10ddd97 | 2013-10-22 12:40:54 -0700 | [diff] [blame] | 1994 | if (!compositor->session_active) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1995 | return; |
| 1996 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1997 | wl_list_for_each(seat, &compositor->seat_list, link) |
Kristian Høgsberg | a71e8b2 | 2013-05-06 21:51:21 -0400 | [diff] [blame] | 1998 | weston_seat_repick(seat); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 1999 | } |
| 2000 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2001 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2002 | weston_view_unmap(struct weston_view *view) |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 2003 | { |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 2004 | struct weston_seat *seat; |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 2005 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2006 | if (!weston_view_is_mapped(view)) |
| 2007 | return; |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 2008 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2009 | weston_view_damage_below(view); |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 2010 | weston_view_set_output(view, NULL); |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 2011 | view->plane = NULL; |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 2012 | view->is_mapped = false; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2013 | weston_layer_entry_remove(&view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2014 | wl_list_remove(&view->link); |
| 2015 | wl_list_init(&view->link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2016 | view->output_mask = 0; |
| 2017 | weston_surface_assign_output(view->surface); |
| 2018 | |
| 2019 | if (weston_surface_is_mapped(view->surface)) |
| 2020 | return; |
| 2021 | |
| 2022 | wl_list_for_each(seat, &view->surface->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2023 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 2024 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2025 | struct weston_keyboard *keyboard = |
| 2026 | weston_seat_get_keyboard(seat); |
| 2027 | |
| 2028 | if (keyboard && keyboard->focus == view->surface) |
| 2029 | weston_keyboard_set_focus(keyboard, NULL); |
| 2030 | if (pointer && pointer->focus == view) |
Derek Foreman | f9318d1 | 2015-05-11 15:40:11 -0500 | [diff] [blame] | 2031 | weston_pointer_clear_focus(pointer); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2032 | if (touch && touch->focus == view) |
| 2033 | weston_touch_set_focus(touch, NULL); |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 2034 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2035 | } |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 2036 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2037 | WL_EXPORT void |
| 2038 | weston_surface_unmap(struct weston_surface *surface) |
| 2039 | { |
| 2040 | struct weston_view *view; |
| 2041 | |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 2042 | surface->is_mapped = false; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2043 | wl_list_for_each(view, &surface->views, surface_link) |
| 2044 | weston_view_unmap(view); |
| 2045 | surface->output = NULL; |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 2046 | } |
| 2047 | |
Pekka Paalanen | 3c9b802 | 2014-03-14 14:38:13 +0200 | [diff] [blame] | 2048 | static void |
| 2049 | weston_surface_reset_pending_buffer(struct weston_surface *surface) |
| 2050 | { |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2051 | weston_surface_state_set_buffer(&surface->pending, NULL); |
Pekka Paalanen | 3c9b802 | 2014-03-14 14:38:13 +0200 | [diff] [blame] | 2052 | surface->pending.sx = 0; |
| 2053 | surface->pending.sy = 0; |
| 2054 | surface->pending.newly_attached = 0; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 2055 | surface->pending.buffer_viewport.changed = 0; |
Pekka Paalanen | 3c9b802 | 2014-03-14 14:38:13 +0200 | [diff] [blame] | 2056 | } |
| 2057 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2058 | WL_EXPORT void |
| 2059 | weston_view_destroy(struct weston_view *view) |
| 2060 | { |
| 2061 | wl_signal_emit(&view->destroy_signal, view); |
| 2062 | |
| 2063 | assert(wl_list_empty(&view->geometry.child_list)); |
| 2064 | |
| 2065 | if (weston_view_is_mapped(view)) { |
| 2066 | weston_view_unmap(view); |
| 2067 | weston_compositor_build_view_list(view->surface->compositor); |
| 2068 | } |
| 2069 | |
| 2070 | wl_list_remove(&view->link); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2071 | weston_layer_entry_remove(&view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2072 | |
| 2073 | pixman_region32_fini(&view->clip); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 2074 | pixman_region32_fini(&view->geometry.scissor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2075 | pixman_region32_fini(&view->transform.boundingbox); |
Pekka Paalanen | 8844bf2 | 2015-02-18 16:30:47 +0200 | [diff] [blame] | 2076 | pixman_region32_fini(&view->transform.opaque); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2077 | |
| 2078 | weston_view_set_transform_parent(view, NULL); |
Pekka Paalanen | 944fae8 | 2018-05-22 13:15:58 +0300 | [diff] [blame] | 2079 | weston_view_set_output(view, NULL); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2080 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2081 | wl_list_remove(&view->surface_link); |
| 2082 | |
| 2083 | free(view); |
| 2084 | } |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2085 | |
| 2086 | WL_EXPORT void |
| 2087 | weston_surface_destroy(struct weston_surface *surface) |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 2088 | { |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 2089 | struct weston_frame_callback *cb, *next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2090 | struct weston_view *ev, *nv; |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 2091 | struct weston_pointer_constraint *constraint, *next_constraint; |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 2092 | |
Giulio Camuffo | 13b85bd | 2013-08-13 23:10:14 +0200 | [diff] [blame] | 2093 | if (--surface->ref_count > 0) |
| 2094 | return; |
| 2095 | |
Pekka Paalanen | 08d3fb7 | 2015-04-17 14:00:24 +0300 | [diff] [blame] | 2096 | assert(surface->resource == NULL); |
| 2097 | |
Pekka Paalanen | ca79076 | 2015-04-17 14:23:38 +0300 | [diff] [blame] | 2098 | wl_signal_emit(&surface->destroy_signal, surface); |
Giulio Camuffo | 13b85bd | 2013-08-13 23:10:14 +0200 | [diff] [blame] | 2099 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2100 | assert(wl_list_empty(&surface->subsurface_list_pending)); |
| 2101 | assert(wl_list_empty(&surface->subsurface_list)); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 2102 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2103 | wl_list_for_each_safe(ev, nv, &surface->views, surface_link) |
| 2104 | weston_view_destroy(ev); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 2105 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2106 | weston_surface_state_fini(&surface->pending); |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2107 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2108 | weston_buffer_reference(&surface->buffer_ref, NULL); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2109 | weston_buffer_release_reference(&surface->buffer_release_ref, NULL); |
Kristian Høgsberg | 3f8f39c | 2009-09-18 17:05:13 -0400 | [diff] [blame] | 2110 | |
Pekka Paalanen | 402ae6d | 2012-01-03 10:23:24 +0200 | [diff] [blame] | 2111 | pixman_region32_fini(&surface->damage); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2112 | pixman_region32_fini(&surface->opaque); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 2113 | pixman_region32_fini(&surface->input); |
Pekka Paalanen | 402ae6d | 2012-01-03 10:23:24 +0200 | [diff] [blame] | 2114 | |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 2115 | wl_list_for_each_safe(cb, next, &surface->frame_callback_list, link) |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 2116 | wl_resource_destroy(cb->resource); |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 2117 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2118 | weston_presentation_feedback_discard_list(&surface->feedback_list); |
| 2119 | |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 2120 | wl_list_for_each_safe(constraint, next_constraint, |
| 2121 | &surface->pointer_constraints, |
| 2122 | link) |
| 2123 | weston_pointer_constraint_destroy(constraint); |
| 2124 | |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2125 | fd_clear(&surface->acquire_fence_fd); |
| 2126 | |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 2127 | free(surface); |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 2128 | } |
| 2129 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2130 | static void |
| 2131 | destroy_surface(struct wl_resource *resource) |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 2132 | { |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2133 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 2134 | |
Pekka Paalanen | 08d3fb7 | 2015-04-17 14:00:24 +0300 | [diff] [blame] | 2135 | assert(surface); |
| 2136 | |
Giulio Camuffo | 0d37974 | 2013-11-15 22:06:15 +0100 | [diff] [blame] | 2137 | /* Set the resource to NULL, since we don't want to leave a |
| 2138 | * dangling pointer if the surface was refcounted and survives |
| 2139 | * the weston_surface_destroy() call. */ |
| 2140 | surface->resource = NULL; |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 2141 | |
| 2142 | if (surface->viewport_resource) |
| 2143 | wl_resource_set_user_data(surface->viewport_resource, NULL); |
| 2144 | |
Alexandros Frantzis | 27d7c39 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2145 | if (surface->synchronization_resource) { |
| 2146 | wl_resource_set_user_data(surface->synchronization_resource, |
| 2147 | NULL); |
| 2148 | } |
| 2149 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2150 | weston_surface_destroy(surface); |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 2151 | } |
| 2152 | |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 2153 | static void |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2154 | weston_buffer_destroy_handler(struct wl_listener *listener, void *data) |
| 2155 | { |
| 2156 | struct weston_buffer *buffer = |
| 2157 | container_of(listener, struct weston_buffer, destroy_listener); |
| 2158 | |
| 2159 | wl_signal_emit(&buffer->destroy_signal, buffer); |
| 2160 | free(buffer); |
| 2161 | } |
| 2162 | |
Giulio Camuffo | e058cd1 | 2013-12-12 14:14:29 +0100 | [diff] [blame] | 2163 | WL_EXPORT struct weston_buffer * |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2164 | weston_buffer_from_resource(struct wl_resource *resource) |
| 2165 | { |
| 2166 | struct weston_buffer *buffer; |
| 2167 | struct wl_listener *listener; |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 2168 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2169 | listener = wl_resource_get_destroy_listener(resource, |
| 2170 | weston_buffer_destroy_handler); |
| 2171 | |
Kristian Høgsberg | 08b58c7 | 2013-08-15 12:26:42 -0700 | [diff] [blame] | 2172 | if (listener) |
| 2173 | return container_of(listener, struct weston_buffer, |
| 2174 | destroy_listener); |
| 2175 | |
| 2176 | buffer = zalloc(sizeof *buffer); |
| 2177 | if (buffer == NULL) |
| 2178 | return NULL; |
| 2179 | |
| 2180 | buffer->resource = resource; |
| 2181 | wl_signal_init(&buffer->destroy_signal); |
| 2182 | buffer->destroy_listener.notify = weston_buffer_destroy_handler; |
Stanislav Vorobiov | bfbb8e5 | 2013-08-29 11:36:44 +0400 | [diff] [blame] | 2183 | buffer->y_inverted = 1; |
Kristian Høgsberg | 08b58c7 | 2013-08-15 12:26:42 -0700 | [diff] [blame] | 2184 | wl_resource_add_destroy_listener(resource, &buffer->destroy_listener); |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 2185 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2186 | return buffer; |
| 2187 | } |
| 2188 | |
| 2189 | static void |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2190 | weston_buffer_reference_handle_destroy(struct wl_listener *listener, |
| 2191 | void *data) |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 2192 | { |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2193 | struct weston_buffer_reference *ref = |
| 2194 | container_of(listener, struct weston_buffer_reference, |
| 2195 | destroy_listener); |
| 2196 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2197 | assert((struct weston_buffer *)data == ref->buffer); |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2198 | ref->buffer = NULL; |
| 2199 | } |
| 2200 | |
| 2201 | WL_EXPORT void |
| 2202 | weston_buffer_reference(struct weston_buffer_reference *ref, |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2203 | struct weston_buffer *buffer) |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2204 | { |
| 2205 | if (ref->buffer && buffer != ref->buffer) { |
Kristian Høgsberg | 2034780 | 2013-03-04 12:07:46 -0500 | [diff] [blame] | 2206 | ref->buffer->busy_count--; |
| 2207 | if (ref->buffer->busy_count == 0) { |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2208 | assert(wl_resource_get_client(ref->buffer->resource)); |
Matt Hoosier | 3052bc7 | 2017-09-26 08:09:40 -0500 | [diff] [blame] | 2209 | wl_buffer_send_release(ref->buffer->resource); |
Kristian Høgsberg | 2034780 | 2013-03-04 12:07:46 -0500 | [diff] [blame] | 2210 | } |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2211 | wl_list_remove(&ref->destroy_listener.link); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2212 | } |
| 2213 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2214 | if (buffer && buffer != ref->buffer) { |
Kristian Høgsberg | b7b77e6 | 2012-09-05 22:38:18 -0400 | [diff] [blame] | 2215 | buffer->busy_count++; |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2216 | wl_signal_add(&buffer->destroy_signal, |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2217 | &ref->destroy_listener); |
Pekka Paalanen | a6421c4 | 2012-12-04 15:58:10 +0200 | [diff] [blame] | 2218 | } |
| 2219 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2220 | ref->buffer = buffer; |
| 2221 | ref->destroy_listener.notify = weston_buffer_reference_handle_destroy; |
| 2222 | } |
| 2223 | |
| 2224 | static void |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2225 | weston_buffer_release_reference_handle_destroy(struct wl_listener *listener, |
| 2226 | void *data) |
| 2227 | { |
| 2228 | struct weston_buffer_release_reference *ref = |
| 2229 | container_of(listener, struct weston_buffer_release_reference, |
| 2230 | destroy_listener); |
| 2231 | |
| 2232 | assert((struct wl_resource *)data == ref->buffer_release->resource); |
| 2233 | ref->buffer_release = NULL; |
| 2234 | } |
| 2235 | |
| 2236 | static void |
| 2237 | weston_buffer_release_destroy(struct weston_buffer_release *buffer_release) |
| 2238 | { |
| 2239 | struct wl_resource *resource = buffer_release->resource; |
| 2240 | int release_fence_fd = buffer_release->fence_fd; |
| 2241 | |
| 2242 | if (release_fence_fd >= 0) { |
| 2243 | zwp_linux_buffer_release_v1_send_fenced_release( |
| 2244 | resource, release_fence_fd); |
| 2245 | } else { |
| 2246 | zwp_linux_buffer_release_v1_send_immediate_release( |
| 2247 | resource); |
| 2248 | } |
| 2249 | |
| 2250 | wl_resource_destroy(resource); |
| 2251 | } |
| 2252 | |
| 2253 | WL_EXPORT void |
| 2254 | weston_buffer_release_reference(struct weston_buffer_release_reference *ref, |
| 2255 | struct weston_buffer_release *buffer_release) |
| 2256 | { |
| 2257 | if (buffer_release == ref->buffer_release) |
| 2258 | return; |
| 2259 | |
| 2260 | if (ref->buffer_release) { |
| 2261 | ref->buffer_release->ref_count--; |
| 2262 | wl_list_remove(&ref->destroy_listener.link); |
| 2263 | if (ref->buffer_release->ref_count == 0) |
| 2264 | weston_buffer_release_destroy(ref->buffer_release); |
| 2265 | } |
| 2266 | |
| 2267 | if (buffer_release) { |
| 2268 | buffer_release->ref_count++; |
| 2269 | wl_resource_add_destroy_listener(buffer_release->resource, |
| 2270 | &ref->destroy_listener); |
| 2271 | } |
| 2272 | |
| 2273 | ref->buffer_release = buffer_release; |
| 2274 | ref->destroy_listener.notify = |
| 2275 | weston_buffer_release_reference_handle_destroy; |
| 2276 | } |
| 2277 | |
| 2278 | WL_EXPORT void |
| 2279 | weston_buffer_release_move(struct weston_buffer_release_reference *dest, |
| 2280 | struct weston_buffer_release_reference *src) |
| 2281 | { |
| 2282 | weston_buffer_release_reference(dest, src->buffer_release); |
| 2283 | weston_buffer_release_reference(src, NULL); |
| 2284 | } |
| 2285 | |
| 2286 | static void |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2287 | weston_surface_attach(struct weston_surface *surface, |
| 2288 | struct weston_buffer *buffer) |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2289 | { |
| 2290 | weston_buffer_reference(&surface->buffer_ref, buffer); |
| 2291 | |
Pekka Paalanen | a6421c4 | 2012-12-04 15:58:10 +0200 | [diff] [blame] | 2292 | if (!buffer) { |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2293 | if (weston_surface_is_mapped(surface)) |
| 2294 | weston_surface_unmap(surface); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2295 | } |
| 2296 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2297 | surface->compositor->renderer->attach(surface, buffer); |
Pekka Paalanen | bb2f3f2 | 2014-03-14 14:38:11 +0200 | [diff] [blame] | 2298 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 2299 | weston_surface_calculate_size_from_buffer(surface); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2300 | weston_presentation_feedback_discard_list(&surface->feedback_list); |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 2301 | } |
| 2302 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 2303 | /** weston_compositor_damage_all |
| 2304 | * \ingroup compositor |
| 2305 | */ |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2306 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2307 | weston_compositor_damage_all(struct weston_compositor *compositor) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2308 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2309 | struct weston_output *output; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2310 | |
| 2311 | wl_list_for_each(output, &compositor->output_list, link) |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2312 | weston_output_damage(output); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2313 | } |
| 2314 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 2315 | /** |
| 2316 | * \ingroup output |
| 2317 | */ |
Kristian Høgsberg | 9f404b7 | 2012-01-26 00:11:01 -0500 | [diff] [blame] | 2318 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2319 | weston_output_damage(struct weston_output *output) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2320 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2321 | struct weston_compositor *compositor = output->compositor; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2322 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 2323 | pixman_region32_union(&compositor->primary_plane.damage, |
| 2324 | &compositor->primary_plane.damage, |
| 2325 | &output->region); |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2326 | weston_output_schedule_repaint(output); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2327 | } |
| 2328 | |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame] | 2329 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2330 | surface_flush_damage(struct weston_surface *surface) |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2331 | { |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2332 | if (surface->buffer_ref.buffer && |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2333 | wl_shm_buffer_get(surface->buffer_ref.buffer->resource)) |
Kristian Høgsberg | fa1be02 | 2012-09-05 22:49:55 -0400 | [diff] [blame] | 2334 | surface->compositor->renderer->flush_damage(surface); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2335 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2336 | if (weston_timeline_enabled_ && |
| 2337 | pixman_region32_not_empty(&surface->damage)) |
| 2338 | TL_POINT("core_flush_damage", TLP_SURFACE(surface), |
| 2339 | TLP_OUTPUT(surface->output), TLP_END); |
| 2340 | |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 2341 | pixman_region32_clear(&surface->damage); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2342 | } |
| 2343 | |
| 2344 | static void |
| 2345 | view_accumulate_damage(struct weston_view *view, |
| 2346 | pixman_region32_t *opaque) |
| 2347 | { |
| 2348 | pixman_region32_t damage; |
| 2349 | |
| 2350 | pixman_region32_init(&damage); |
| 2351 | if (view->transform.enabled) { |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2352 | pixman_box32_t *extents; |
| 2353 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2354 | extents = pixman_region32_extents(&view->surface->damage); |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 2355 | view_compute_bbox(view, extents, &damage); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2356 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2357 | pixman_region32_copy(&damage, &view->surface->damage); |
| 2358 | pixman_region32_translate(&damage, |
Pekka Paalanen | 502f5e0 | 2015-02-23 14:08:25 +0200 | [diff] [blame] | 2359 | view->geometry.x, view->geometry.y); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2360 | } |
| 2361 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 2362 | pixman_region32_intersect(&damage, &damage, |
| 2363 | &view->transform.boundingbox); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2364 | pixman_region32_subtract(&damage, &damage, opaque); |
| 2365 | pixman_region32_union(&view->plane->damage, |
| 2366 | &view->plane->damage, &damage); |
| 2367 | pixman_region32_fini(&damage); |
| 2368 | pixman_region32_copy(&view->clip, opaque); |
Pekka Paalanen | 8844bf2 | 2015-02-18 16:30:47 +0200 | [diff] [blame] | 2369 | pixman_region32_union(opaque, opaque, &view->transform.opaque); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2370 | } |
| 2371 | |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 2372 | static void |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2373 | compositor_accumulate_damage(struct weston_compositor *ec) |
| 2374 | { |
| 2375 | struct weston_plane *plane; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2376 | struct weston_view *ev; |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2377 | pixman_region32_t opaque, clip; |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2378 | |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2379 | pixman_region32_init(&clip); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2380 | |
| 2381 | wl_list_for_each(plane, &ec->plane_list, link) { |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2382 | pixman_region32_copy(&plane->clip, &clip); |
| 2383 | |
| 2384 | pixman_region32_init(&opaque); |
| 2385 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2386 | wl_list_for_each(ev, &ec->view_list, link) { |
| 2387 | if (ev->plane != plane) |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2388 | continue; |
| 2389 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2390 | view_accumulate_damage(ev, &opaque); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2391 | } |
| 2392 | |
| 2393 | pixman_region32_union(&clip, &clip, &opaque); |
| 2394 | pixman_region32_fini(&opaque); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2395 | } |
| 2396 | |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2397 | pixman_region32_fini(&clip); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2398 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2399 | wl_list_for_each(ev, &ec->view_list, link) |
Derek Foreman | 060cf11 | 2015-11-18 16:32:26 -0600 | [diff] [blame] | 2400 | ev->surface->touched = false; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2401 | |
| 2402 | wl_list_for_each(ev, &ec->view_list, link) { |
| 2403 | if (ev->surface->touched) |
| 2404 | continue; |
Derek Foreman | 060cf11 | 2015-11-18 16:32:26 -0600 | [diff] [blame] | 2405 | ev->surface->touched = true; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2406 | |
| 2407 | surface_flush_damage(ev->surface); |
| 2408 | |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2409 | /* Both the renderer and the backend have seen the buffer |
| 2410 | * by now. If renderer needs the buffer, it has its own |
| 2411 | * reference set. If the backend wants to keep the buffer |
| 2412 | * around for migrating the surface into a non-primary plane |
| 2413 | * later, keep_buffer is true. Otherwise, drop the core |
| 2414 | * reference now, and allow early buffer release. This enables |
| 2415 | * clients to use single-buffering. |
| 2416 | */ |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2417 | if (!ev->surface->keep_buffer) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2418 | weston_buffer_reference(&ev->surface->buffer_ref, NULL); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2419 | weston_buffer_release_reference( |
| 2420 | &ev->surface->buffer_release_ref, NULL); |
| 2421 | } |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2422 | } |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2426 | surface_stash_subsurface_views(struct weston_surface *surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2427 | { |
| 2428 | struct weston_subsurface *sub; |
| 2429 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2430 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2431 | if (sub->surface == surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2432 | continue; |
| 2433 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2434 | wl_list_insert_list(&sub->unused_views, &sub->surface->views); |
| 2435 | wl_list_init(&sub->surface->views); |
| 2436 | |
| 2437 | surface_stash_subsurface_views(sub->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2438 | } |
| 2439 | } |
| 2440 | |
| 2441 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2442 | surface_free_unused_subsurface_views(struct weston_surface *surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2443 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2444 | struct weston_subsurface *sub; |
| 2445 | struct weston_view *view, *nv; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2446 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2447 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
| 2448 | if (sub->surface == surface) |
| 2449 | continue; |
| 2450 | |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 2451 | wl_list_for_each_safe(view, nv, &sub->unused_views, surface_link) { |
| 2452 | weston_view_unmap (view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2453 | weston_view_destroy(view); |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 2454 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2455 | |
| 2456 | surface_free_unused_subsurface_views(sub->surface); |
| 2457 | } |
| 2458 | } |
| 2459 | |
| 2460 | static void |
| 2461 | view_list_add_subsurface_view(struct weston_compositor *compositor, |
| 2462 | struct weston_subsurface *sub, |
| 2463 | struct weston_view *parent) |
| 2464 | { |
| 2465 | struct weston_subsurface *child; |
| 2466 | struct weston_view *view = NULL, *iv; |
| 2467 | |
Pekka Paalanen | 661de3a | 2014-07-28 12:49:24 +0300 | [diff] [blame] | 2468 | if (!weston_surface_is_mapped(sub->surface)) |
| 2469 | return; |
| 2470 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2471 | wl_list_for_each(iv, &sub->unused_views, surface_link) { |
| 2472 | if (iv->geometry.parent == parent) { |
| 2473 | view = iv; |
| 2474 | break; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2475 | } |
| 2476 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2477 | |
| 2478 | if (view) { |
| 2479 | /* Put it back in the surface's list of views */ |
| 2480 | wl_list_remove(&view->surface_link); |
| 2481 | wl_list_insert(&sub->surface->views, &view->surface_link); |
| 2482 | } else { |
| 2483 | view = weston_view_create(sub->surface); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2484 | weston_view_set_position(view, |
| 2485 | sub->position.x, |
| 2486 | sub->position.y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2487 | weston_view_set_transform_parent(view, parent); |
| 2488 | } |
| 2489 | |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 2490 | view->parent_view = parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2491 | weston_view_update_transform(view); |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 2492 | view->is_mapped = true; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2493 | |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2494 | if (wl_list_empty(&sub->surface->subsurface_list)) { |
| 2495 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 2496 | return; |
| 2497 | } |
| 2498 | |
| 2499 | wl_list_for_each(child, &sub->surface->subsurface_list, parent_link) { |
| 2500 | if (child->surface == sub->surface) |
| 2501 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 2502 | else |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2503 | view_list_add_subsurface_view(compositor, child, view); |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2504 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2505 | } |
| 2506 | |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 2507 | /* This recursively adds the sub-surfaces for a view, relying on the |
| 2508 | * sub-surface order. Thus, if a client restacks the sub-surfaces, that |
| 2509 | * change first happens to the sub-surface list, and then automatically |
| 2510 | * propagates here. See weston_surface_damage_subsurfaces() for how the |
| 2511 | * sub-surfaces receive damage when the client changes the state. |
| 2512 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2513 | static void |
| 2514 | view_list_add(struct weston_compositor *compositor, |
| 2515 | struct weston_view *view) |
| 2516 | { |
| 2517 | struct weston_subsurface *sub; |
| 2518 | |
| 2519 | weston_view_update_transform(view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2520 | |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2521 | if (wl_list_empty(&view->surface->subsurface_list)) { |
| 2522 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 2523 | return; |
| 2524 | } |
| 2525 | |
| 2526 | wl_list_for_each(sub, &view->surface->subsurface_list, parent_link) { |
| 2527 | if (sub->surface == view->surface) |
| 2528 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 2529 | else |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2530 | view_list_add_subsurface_view(compositor, sub, view); |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2531 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2532 | } |
| 2533 | |
| 2534 | static void |
| 2535 | weston_compositor_build_view_list(struct weston_compositor *compositor) |
| 2536 | { |
| 2537 | struct weston_view *view; |
| 2538 | struct weston_layer *layer; |
| 2539 | |
| 2540 | wl_list_for_each(layer, &compositor->layer_list, link) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2541 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2542 | surface_stash_subsurface_views(view->surface); |
| 2543 | |
| 2544 | wl_list_init(&compositor->view_list); |
| 2545 | wl_list_for_each(layer, &compositor->layer_list, link) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2546 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2547 | view_list_add(compositor, view); |
| 2548 | } |
| 2549 | } |
| 2550 | |
| 2551 | wl_list_for_each(layer, &compositor->layer_list, link) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2552 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2553 | surface_free_unused_subsurface_views(view->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2554 | } |
| 2555 | |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2556 | static void |
| 2557 | weston_output_take_feedback_list(struct weston_output *output, |
| 2558 | struct weston_surface *surface) |
| 2559 | { |
| 2560 | struct weston_view *view; |
| 2561 | struct weston_presentation_feedback *feedback; |
| 2562 | uint32_t flags = 0xffffffff; |
| 2563 | |
| 2564 | if (wl_list_empty(&surface->feedback_list)) |
| 2565 | return; |
| 2566 | |
| 2567 | /* All views must have the flag for the flag to survive. */ |
| 2568 | wl_list_for_each(view, &surface->views, surface_link) { |
| 2569 | /* ignore views that are not on this output at all */ |
| 2570 | if (view->output_mask & (1u << output->id)) |
| 2571 | flags &= view->psf_flags; |
| 2572 | } |
| 2573 | |
| 2574 | wl_list_for_each(feedback, &surface->feedback_list, link) |
| 2575 | feedback->psf_flags = flags; |
| 2576 | |
| 2577 | wl_list_insert_list(&output->feedback_list, &surface->feedback_list); |
| 2578 | wl_list_init(&surface->feedback_list); |
| 2579 | } |
| 2580 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2581 | static int |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2582 | weston_output_repaint(struct weston_output *output, void *repaint_data) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2583 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2584 | struct weston_compositor *ec = output->compositor; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2585 | struct weston_view *ev; |
Kristian Høgsberg | 30c018b | 2012-01-26 08:40:37 -0500 | [diff] [blame] | 2586 | struct weston_animation *animation, *next; |
| 2587 | struct weston_frame_callback *cb, *cnext; |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 2588 | struct wl_list frame_callback_list; |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2589 | pixman_region32_t output_damage; |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2590 | int r; |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 2591 | uint32_t frame_time_msec; |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 2592 | enum weston_hdcp_protection highest_requested = WESTON_HDCP_DISABLE; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 2593 | |
Ander Conselvan de Oliveira | e1e2352 | 2013-12-13 22:10:55 +0200 | [diff] [blame] | 2594 | if (output->destroying) |
| 2595 | return 0; |
| 2596 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2597 | TL_POINT("core_repaint_begin", TLP_OUTPUT(output), TLP_END); |
| 2598 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2599 | /* Rebuild the surface list and update surface transforms up front. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2600 | weston_compositor_build_view_list(ec); |
Pekka Paalanen | 15d60ef | 2012-01-27 14:38:33 +0200 | [diff] [blame] | 2601 | |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 2602 | /* Find the highest protection desired for an output */ |
| 2603 | wl_list_for_each(ev, &ec->view_list, link) { |
| 2604 | if (ev->surface->output_mask & (1u << output->id)) { |
| 2605 | /* |
| 2606 | * The desired_protection of the output should be the |
| 2607 | * maximum of the desired_protection of the surfaces, |
| 2608 | * that are displayed on that output, to avoid |
| 2609 | * reducing the protection for existing surfaces. |
| 2610 | */ |
| 2611 | if (ev->surface->desired_protection > highest_requested) |
| 2612 | highest_requested = |
| 2613 | ev->surface->desired_protection; |
| 2614 | } |
| 2615 | } |
| 2616 | |
| 2617 | output->desired_protection = highest_requested; |
| 2618 | |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2619 | if (output->assign_planes && !output->disable_planes) { |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2620 | output->assign_planes(output, repaint_data); |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2621 | } else { |
| 2622 | wl_list_for_each(ev, &ec->view_list, link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2623 | weston_view_move_to_plane(ev, &ec->primary_plane); |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2624 | ev->psf_flags = 0; |
| 2625 | } |
| 2626 | } |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 2627 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2628 | wl_list_init(&frame_callback_list); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2629 | wl_list_for_each(ev, &ec->view_list, link) { |
| 2630 | /* Note: This operation is safe to do multiple times on the |
| 2631 | * same surface. |
| 2632 | */ |
| 2633 | if (ev->surface->output == output) { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2634 | wl_list_insert_list(&frame_callback_list, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2635 | &ev->surface->frame_callback_list); |
| 2636 | wl_list_init(&ev->surface->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2637 | |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2638 | weston_output_take_feedback_list(output, ev->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2639 | } |
| 2640 | } |
| 2641 | |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2642 | compositor_accumulate_damage(ec); |
Kristian Høgsberg | 53df1d8 | 2011-06-23 21:11:19 -0400 | [diff] [blame] | 2643 | |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 2644 | pixman_region32_init(&output_damage); |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 2645 | pixman_region32_intersect(&output_damage, |
| 2646 | &ec->primary_plane.damage, &output->region); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2647 | pixman_region32_subtract(&output_damage, |
| 2648 | &output_damage, &ec->primary_plane.clip); |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 2649 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2650 | if (output->dirty) |
| 2651 | weston_output_update_matrix(output); |
| 2652 | |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2653 | r = output->repaint(output, &output_damage, repaint_data); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2654 | |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 2655 | pixman_region32_fini(&output_damage); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 2656 | |
Daniel Stone | 09a97e2 | 2017-03-01 11:34:06 +0000 | [diff] [blame] | 2657 | output->repaint_needed = false; |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2658 | if (r == 0) |
| 2659 | output->repaint_status = REPAINT_AWAITING_COMPLETION; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 2660 | |
Kristian Høgsberg | aa6019e | 2012-03-11 16:35:16 -0400 | [diff] [blame] | 2661 | weston_compositor_repick(ec); |
Kristian Høgsberg | aa6019e | 2012-03-11 16:35:16 -0400 | [diff] [blame] | 2662 | |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 2663 | frame_time_msec = timespec_to_msec(&output->frame_time); |
| 2664 | |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 2665 | wl_list_for_each_safe(cb, cnext, &frame_callback_list, link) { |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 2666 | wl_callback_send_done(cb->resource, frame_time_msec); |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 2667 | wl_resource_destroy(cb->resource); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 2668 | } |
| 2669 | |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 2670 | wl_list_for_each_safe(animation, next, &output->animation_list, link) { |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 2671 | animation->frame_counter++; |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 2672 | animation->frame(animation, output, &output->frame_time); |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 2673 | } |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2674 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2675 | TL_POINT("core_repaint_posted", TLP_OUTPUT(output), TLP_END); |
| 2676 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2677 | return r; |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2678 | } |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 2679 | |
Pekka Paalanen | 8291979 | 2014-05-21 13:51:49 +0300 | [diff] [blame] | 2680 | static void |
| 2681 | weston_output_schedule_repaint_reset(struct weston_output *output) |
| 2682 | { |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2683 | output->repaint_status = REPAINT_NOT_SCHEDULED; |
Pekka Paalanen | 8291979 | 2014-05-21 13:51:49 +0300 | [diff] [blame] | 2684 | TL_POINT("core_repaint_exit_loop", TLP_OUTPUT(output), TLP_END); |
Pekka Paalanen | 8291979 | 2014-05-21 13:51:49 +0300 | [diff] [blame] | 2685 | } |
| 2686 | |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2687 | static int |
| 2688 | weston_output_maybe_repaint(struct weston_output *output, struct timespec *now, |
| 2689 | void *repaint_data) |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2690 | { |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2691 | struct weston_compositor *compositor = output->compositor; |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2692 | int ret = 0; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2693 | int64_t msec_to_repaint; |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2694 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2695 | /* We're not ready yet; come back to make a decision later. */ |
| 2696 | if (output->repaint_status != REPAINT_SCHEDULED) |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2697 | return ret; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2698 | |
| 2699 | msec_to_repaint = timespec_sub_to_msec(&output->next_repaint, now); |
| 2700 | if (msec_to_repaint > 1) |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2701 | return ret; |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2702 | |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 2703 | /* If we're sleeping, drop the repaint machinery entirely; we will |
| 2704 | * explicitly repaint all outputs when we come back. */ |
| 2705 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING || |
| 2706 | compositor->state == WESTON_COMPOSITOR_OFFSCREEN) |
| 2707 | goto err; |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2708 | |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 2709 | /* We don't actually need to repaint this output; drop it from |
| 2710 | * repaint until something causes damage. */ |
| 2711 | if (!output->repaint_needed) |
| 2712 | goto err; |
| 2713 | |
| 2714 | /* If repaint fails, we aren't going to get weston_output_finish_frame |
| 2715 | * to trigger a new repaint, so drop it from repaint and hope |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2716 | * something schedules a successful repaint later. As repainting may |
| 2717 | * take some time, re-read our clock as a courtesy to the next |
| 2718 | * output. */ |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2719 | ret = weston_output_repaint(output, repaint_data); |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2720 | weston_compositor_read_presentation_clock(compositor, now); |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 2721 | if (ret != 0) |
| 2722 | goto err; |
| 2723 | |
Tomohito Esaki | 7f4d9ff | 2018-06-05 10:37:06 +0900 | [diff] [blame] | 2724 | output->repainted = true; |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2725 | return ret; |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 2726 | |
| 2727 | err: |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2728 | weston_output_schedule_repaint_reset(output); |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2729 | return ret; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2730 | } |
| 2731 | |
| 2732 | static void |
| 2733 | output_repaint_timer_arm(struct weston_compositor *compositor) |
| 2734 | { |
| 2735 | struct weston_output *output; |
| 2736 | bool any_should_repaint = false; |
| 2737 | struct timespec now; |
Sergi Granell | b4c0886 | 2017-03-18 13:01:15 +0100 | [diff] [blame] | 2738 | int64_t msec_to_next = INT64_MAX; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2739 | |
| 2740 | weston_compositor_read_presentation_clock(compositor, &now); |
| 2741 | |
| 2742 | wl_list_for_each(output, &compositor->output_list, link) { |
| 2743 | int64_t msec_to_this; |
| 2744 | |
| 2745 | if (output->repaint_status != REPAINT_SCHEDULED) |
| 2746 | continue; |
| 2747 | |
| 2748 | msec_to_this = timespec_sub_to_msec(&output->next_repaint, |
| 2749 | &now); |
| 2750 | if (!any_should_repaint || msec_to_this < msec_to_next) |
| 2751 | msec_to_next = msec_to_this; |
| 2752 | |
| 2753 | any_should_repaint = true; |
| 2754 | } |
| 2755 | |
| 2756 | if (!any_should_repaint) |
| 2757 | return; |
| 2758 | |
| 2759 | /* Even if we should repaint immediately, add the minimum 1 ms delay. |
| 2760 | * This is a workaround to allow coalescing multiple output repaints |
| 2761 | * particularly from weston_output_finish_frame() |
| 2762 | * into the same call, which would not happen if we called |
| 2763 | * output_repaint_timer_handler() directly. |
| 2764 | */ |
| 2765 | if (msec_to_next < 1) |
| 2766 | msec_to_next = 1; |
| 2767 | |
| 2768 | wl_event_source_timer_update(compositor->repaint_timer, msec_to_next); |
| 2769 | } |
| 2770 | |
| 2771 | static int |
| 2772 | output_repaint_timer_handler(void *data) |
| 2773 | { |
| 2774 | struct weston_compositor *compositor = data; |
| 2775 | struct weston_output *output; |
| 2776 | struct timespec now; |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2777 | void *repaint_data = NULL; |
Emre Ucan | e479ed8 | 2018-03-20 15:29:40 +0100 | [diff] [blame] | 2778 | int ret = 0; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2779 | |
| 2780 | weston_compositor_read_presentation_clock(compositor, &now); |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2781 | |
| 2782 | if (compositor->backend->repaint_begin) |
| 2783 | repaint_data = compositor->backend->repaint_begin(compositor); |
| 2784 | |
| 2785 | wl_list_for_each(output, &compositor->output_list, link) { |
| 2786 | ret = weston_output_maybe_repaint(output, &now, repaint_data); |
| 2787 | if (ret) |
| 2788 | break; |
| 2789 | } |
| 2790 | |
| 2791 | if (ret == 0) { |
Tomohito Esaki | 09bfcd6 | 2018-06-05 10:37:05 +0900 | [diff] [blame] | 2792 | if (compositor->backend->repaint_flush) |
| 2793 | compositor->backend->repaint_flush(compositor, |
| 2794 | repaint_data); |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2795 | } else { |
Tomohito Esaki | 7f4d9ff | 2018-06-05 10:37:06 +0900 | [diff] [blame] | 2796 | wl_list_for_each(output, &compositor->output_list, link) { |
| 2797 | if (output->repainted) |
| 2798 | weston_output_schedule_repaint_reset(output); |
| 2799 | } |
| 2800 | |
Tomohito Esaki | 09bfcd6 | 2018-06-05 10:37:05 +0900 | [diff] [blame] | 2801 | if (compositor->backend->repaint_cancel) |
| 2802 | compositor->backend->repaint_cancel(compositor, |
| 2803 | repaint_data); |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2804 | } |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2805 | |
Tomohito Esaki | ddaf95c | 2018-07-10 11:47:15 +0900 | [diff] [blame] | 2806 | wl_list_for_each(output, &compositor->output_list, link) |
| 2807 | output->repainted = false; |
| 2808 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2809 | output_repaint_timer_arm(compositor); |
| 2810 | |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2811 | return 0; |
| 2812 | } |
| 2813 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 2814 | /** |
| 2815 | * \ingroup output |
| 2816 | */ |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2817 | WL_EXPORT void |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 2818 | weston_output_finish_frame(struct weston_output *output, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 2819 | const struct timespec *stamp, |
| 2820 | uint32_t presented_flags) |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2821 | { |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2822 | struct weston_compositor *compositor = output->compositor; |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2823 | int32_t refresh_nsec; |
| 2824 | struct timespec now; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2825 | int64_t msec_rel; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2826 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2827 | |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2828 | assert(output->repaint_status == REPAINT_AWAITING_COMPLETION); |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2829 | assert(stamp || (presented_flags & WP_PRESENTATION_FEEDBACK_INVALID)); |
| 2830 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2831 | weston_compositor_read_presentation_clock(compositor, &now); |
| 2832 | |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2833 | /* If we haven't been supplied any timestamp at all, we don't have a |
| 2834 | * timebase to work against, so any delay just wastes time. Push a |
| 2835 | * repaint as soon as possible so we can get on with it. */ |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2836 | if (!stamp) { |
| 2837 | output->next_repaint = now; |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2838 | goto out; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2839 | } |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2840 | |
Marius Vlad | df9278a | 2018-03-06 18:56:23 +0200 | [diff] [blame] | 2841 | TL_POINT("core_repaint_finished", TLP_OUTPUT(output), |
| 2842 | TLP_VBLANK(stamp), TLP_END); |
| 2843 | |
Pekka Paalanen | d7894d0 | 2015-07-03 15:08:53 +0300 | [diff] [blame] | 2844 | refresh_nsec = millihz_to_nsec(output->current_mode->refresh); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2845 | weston_presentation_feedback_present_list(&output->feedback_list, |
| 2846 | output, refresh_nsec, stamp, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 2847 | output->msc, |
| 2848 | presented_flags); |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2849 | |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 2850 | output->frame_time = *stamp; |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2851 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2852 | timespec_add_nsec(&output->next_repaint, stamp, refresh_nsec); |
| 2853 | timespec_add_msec(&output->next_repaint, &output->next_repaint, |
| 2854 | -compositor->repaint_msec); |
| 2855 | msec_rel = timespec_sub_to_msec(&output->next_repaint, &now); |
Daniel Stone | 84aff5c | 2017-03-01 11:34:04 +0000 | [diff] [blame] | 2856 | |
| 2857 | if (msec_rel < -1000 || msec_rel > 1000) { |
Pekka Paalanen | 8fd4de4 | 2015-03-19 12:27:29 +0200 | [diff] [blame] | 2858 | static bool warned; |
| 2859 | |
| 2860 | if (!warned) |
| 2861 | weston_log("Warning: computed repaint delay is " |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2862 | "insane: %lld msec\n", (long long) msec_rel); |
Pekka Paalanen | 8fd4de4 | 2015-03-19 12:27:29 +0200 | [diff] [blame] | 2863 | warned = true; |
| 2864 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2865 | output->next_repaint = now; |
Pekka Paalanen | 8fd4de4 | 2015-03-19 12:27:29 +0200 | [diff] [blame] | 2866 | } |
| 2867 | |
Mario Kleiner | b7df04e | 2015-06-21 21:25:15 +0200 | [diff] [blame] | 2868 | /* Called from restart_repaint_loop and restart happens already after |
| 2869 | * the deadline given by repaint_msec? In that case we delay until |
| 2870 | * the deadline of the next frame, to give clients a more predictable |
| 2871 | * timing of the repaint cycle to lock on. */ |
Daniel Stone | eca5cca | 2017-02-28 21:53:51 +0000 | [diff] [blame] | 2872 | if (presented_flags == WP_PRESENTATION_FEEDBACK_INVALID && |
| 2873 | msec_rel < 0) { |
| 2874 | while (timespec_sub_to_nsec(&output->next_repaint, &now) < 0) { |
| 2875 | timespec_add_nsec(&output->next_repaint, |
| 2876 | &output->next_repaint, |
| 2877 | refresh_nsec); |
| 2878 | } |
| 2879 | } |
Mario Kleiner | b7df04e | 2015-06-21 21:25:15 +0200 | [diff] [blame] | 2880 | |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2881 | out: |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2882 | output->repaint_status = REPAINT_SCHEDULED; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2883 | output_repaint_timer_arm(compositor); |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2884 | } |
| 2885 | |
| 2886 | static void |
| 2887 | idle_repaint(void *data) |
| 2888 | { |
| 2889 | struct weston_output *output = data; |
| 2890 | |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2891 | assert(output->repaint_status == REPAINT_BEGIN_FROM_IDLE); |
| 2892 | output->repaint_status = REPAINT_AWAITING_COMPLETION; |
Pekka Paalanen | dcbcfc7 | 2017-10-26 14:33:59 +0300 | [diff] [blame] | 2893 | output->idle_repaint_source = NULL; |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 2894 | output->start_repaint_loop(output); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2895 | } |
| 2896 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2897 | WL_EXPORT void |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2898 | weston_layer_entry_insert(struct weston_layer_entry *list, |
| 2899 | struct weston_layer_entry *entry) |
| 2900 | { |
| 2901 | wl_list_insert(&list->link, &entry->link); |
| 2902 | entry->layer = list->layer; |
| 2903 | } |
| 2904 | |
| 2905 | WL_EXPORT void |
| 2906 | weston_layer_entry_remove(struct weston_layer_entry *entry) |
| 2907 | { |
| 2908 | wl_list_remove(&entry->link); |
| 2909 | wl_list_init(&entry->link); |
| 2910 | entry->layer = NULL; |
| 2911 | } |
| 2912 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 2913 | |
| 2914 | /** Initialize the weston_layer struct. |
| 2915 | * |
| 2916 | * \param compositor The compositor instance |
| 2917 | * \param layer The layer to initialize |
| 2918 | */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2919 | WL_EXPORT void |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 2920 | weston_layer_init(struct weston_layer *layer, |
| 2921 | struct weston_compositor *compositor) |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2922 | { |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 2923 | layer->compositor = compositor; |
| 2924 | wl_list_init(&layer->link); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2925 | wl_list_init(&layer->view_list.link); |
| 2926 | layer->view_list.layer = layer; |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 2927 | weston_layer_set_mask_infinite(layer); |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 2928 | } |
| 2929 | |
| 2930 | /** Sets the position of the layer in the layer list. The layer will be placed |
| 2931 | * below any layer with the same position value, if any. |
| 2932 | * This function is safe to call if the layer is already on the list, but the |
| 2933 | * layer may be moved below other layers at the same position, if any. |
| 2934 | * |
| 2935 | * \param layer The layer to modify |
| 2936 | * \param position The position the layer will be placed at |
| 2937 | */ |
| 2938 | WL_EXPORT void |
| 2939 | weston_layer_set_position(struct weston_layer *layer, |
| 2940 | enum weston_layer_position position) |
| 2941 | { |
| 2942 | struct weston_layer *below; |
| 2943 | |
| 2944 | wl_list_remove(&layer->link); |
| 2945 | |
| 2946 | /* layer_list is ordered from top to bottom, the last layer being the |
| 2947 | * background with the smallest position value */ |
| 2948 | |
| 2949 | layer->position = position; |
| 2950 | wl_list_for_each_reverse(below, &layer->compositor->layer_list, link) { |
| 2951 | if (below->position >= layer->position) { |
| 2952 | wl_list_insert(&below->link, &layer->link); |
| 2953 | return; |
| 2954 | } |
| 2955 | } |
| 2956 | wl_list_insert(&layer->compositor->layer_list, &layer->link); |
| 2957 | } |
| 2958 | |
| 2959 | /** Hide a layer by taking it off the layer list. |
| 2960 | * This function is safe to call if the layer is not on the list. |
| 2961 | * |
| 2962 | * \param layer The layer to hide |
| 2963 | */ |
| 2964 | WL_EXPORT void |
| 2965 | weston_layer_unset_position(struct weston_layer *layer) |
| 2966 | { |
| 2967 | wl_list_remove(&layer->link); |
| 2968 | wl_list_init(&layer->link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2969 | } |
| 2970 | |
| 2971 | WL_EXPORT void |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 2972 | weston_layer_set_mask(struct weston_layer *layer, |
| 2973 | int x, int y, int width, int height) |
| 2974 | { |
| 2975 | struct weston_view *view; |
| 2976 | |
| 2977 | layer->mask.x1 = x; |
| 2978 | layer->mask.x2 = x + width; |
| 2979 | layer->mask.y1 = y; |
| 2980 | layer->mask.y2 = y + height; |
| 2981 | |
| 2982 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
| 2983 | weston_view_geometry_dirty(view); |
| 2984 | } |
| 2985 | } |
| 2986 | |
| 2987 | WL_EXPORT void |
| 2988 | weston_layer_set_mask_infinite(struct weston_layer *layer) |
| 2989 | { |
| 2990 | weston_layer_set_mask(layer, INT32_MIN, INT32_MIN, |
| 2991 | UINT32_MAX, UINT32_MAX); |
| 2992 | } |
| 2993 | |
Daniel Stone | 3b77563 | 2018-07-20 08:38:25 +0100 | [diff] [blame] | 2994 | WL_EXPORT bool |
| 2995 | weston_layer_mask_is_infinite(struct weston_layer *layer) |
| 2996 | { |
| 2997 | return layer->mask.x1 == INT32_MIN && |
| 2998 | layer->mask.y1 == INT32_MIN && |
| 2999 | layer->mask.x2 == INT32_MIN + UINT32_MAX && |
| 3000 | layer->mask.y2 == INT32_MIN + UINT32_MAX; |
| 3001 | } |
| 3002 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 3003 | /** |
| 3004 | * \ingroup output |
| 3005 | */ |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 3006 | WL_EXPORT void |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 3007 | weston_output_schedule_repaint(struct weston_output *output) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 3008 | { |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 3009 | struct weston_compositor *compositor = output->compositor; |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 3010 | struct wl_event_loop *loop; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 3011 | |
Bryce Harrington | 08976ac | 2016-08-30 12:05:16 -0700 | [diff] [blame] | 3012 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING || |
| 3013 | compositor->state == WESTON_COMPOSITOR_OFFSCREEN) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 3014 | return; |
| 3015 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3016 | if (!output->repaint_needed) |
| 3017 | TL_POINT("core_repaint_req", TLP_OUTPUT(output), TLP_END); |
| 3018 | |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 3019 | loop = wl_display_get_event_loop(compositor->wl_display); |
Daniel Stone | 09a97e2 | 2017-03-01 11:34:06 +0000 | [diff] [blame] | 3020 | output->repaint_needed = true; |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 3021 | |
| 3022 | /* If we already have a repaint scheduled for our idle handler, |
| 3023 | * no need to set it again. If the repaint has been called but |
| 3024 | * not finished, then weston_output_finish_frame() will notice |
| 3025 | * that a repaint is needed and schedule one. */ |
| 3026 | if (output->repaint_status != REPAINT_NOT_SCHEDULED) |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 3027 | return; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 3028 | |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 3029 | output->repaint_status = REPAINT_BEGIN_FROM_IDLE; |
Pekka Paalanen | dcbcfc7 | 2017-10-26 14:33:59 +0300 | [diff] [blame] | 3030 | assert(!output->idle_repaint_source); |
| 3031 | output->idle_repaint_source = wl_event_loop_add_idle(loop, idle_repaint, |
| 3032 | output); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3033 | TL_POINT("core_repaint_enter_loop", TLP_OUTPUT(output), TLP_END); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 3034 | } |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 3035 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 3036 | /** weston_compositor_schedule_repaint |
| 3037 | * \ingroup compositor |
| 3038 | */ |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3039 | WL_EXPORT void |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 3040 | weston_compositor_schedule_repaint(struct weston_compositor *compositor) |
| 3041 | { |
| 3042 | struct weston_output *output; |
| 3043 | |
| 3044 | wl_list_for_each(output, &compositor->output_list, link) |
| 3045 | weston_output_schedule_repaint(output); |
| 3046 | } |
| 3047 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 3048 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 3049 | surface_destroy(struct wl_client *client, struct wl_resource *resource) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 3050 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3051 | wl_resource_destroy(resource); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 3052 | } |
| 3053 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 3054 | static void |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 3055 | surface_attach(struct wl_client *client, |
| 3056 | struct wl_resource *resource, |
| 3057 | struct wl_resource *buffer_resource, int32_t sx, int32_t sy) |
| 3058 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3059 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 3060 | struct weston_buffer *buffer = NULL; |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 3061 | |
Kristian Høgsberg | ab19f93 | 2013-08-20 11:30:54 -0700 | [diff] [blame] | 3062 | if (buffer_resource) { |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 3063 | buffer = weston_buffer_from_resource(buffer_resource); |
Kristian Høgsberg | ab19f93 | 2013-08-20 11:30:54 -0700 | [diff] [blame] | 3064 | if (buffer == NULL) { |
| 3065 | wl_client_post_no_memory(client); |
| 3066 | return; |
| 3067 | } |
Kristian Høgsberg | 08b58c7 | 2013-08-15 12:26:42 -0700 | [diff] [blame] | 3068 | } |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 3069 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 3070 | /* Attach, attach, without commit in between does not send |
| 3071 | * wl_buffer.release. */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3072 | weston_surface_state_set_buffer(&surface->pending, buffer); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 3073 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3074 | surface->pending.sx = sx; |
| 3075 | surface->pending.sy = sy; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3076 | surface->pending.newly_attached = 1; |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 3077 | } |
| 3078 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 3079 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3080 | surface_damage(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 3081 | struct wl_resource *resource, |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3082 | 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] | 3083 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3084 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 9d69f8e | 2010-09-03 14:46:38 -0400 | [diff] [blame] | 3085 | |
Derek Foreman | 57e92ed | 2015-11-17 14:11:35 -0600 | [diff] [blame] | 3086 | if (width <= 0 || height <= 0) |
| 3087 | return; |
| 3088 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3089 | pixman_region32_union_rect(&surface->pending.damage_surface, |
| 3090 | &surface->pending.damage_surface, |
| 3091 | x, y, width, height); |
| 3092 | } |
| 3093 | |
| 3094 | static void |
| 3095 | surface_damage_buffer(struct wl_client *client, |
| 3096 | struct wl_resource *resource, |
| 3097 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 3098 | { |
| 3099 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
| 3100 | |
| 3101 | if (width <= 0 || height <= 0) |
| 3102 | return; |
| 3103 | |
| 3104 | pixman_region32_union_rect(&surface->pending.damage_buffer, |
| 3105 | &surface->pending.damage_buffer, |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 3106 | x, y, width, height); |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 3107 | } |
| 3108 | |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3109 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 3110 | destroy_frame_callback(struct wl_resource *resource) |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3111 | { |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 3112 | struct weston_frame_callback *cb = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 3113 | |
| 3114 | wl_list_remove(&cb->link); |
Pekka Paalanen | 8c19645 | 2011-11-15 11:45:42 +0200 | [diff] [blame] | 3115 | free(cb); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3116 | } |
| 3117 | |
| 3118 | static void |
| 3119 | surface_frame(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 3120 | struct wl_resource *resource, uint32_t callback) |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3121 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3122 | struct weston_frame_callback *cb; |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3123 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3124 | |
| 3125 | cb = malloc(sizeof *cb); |
| 3126 | if (cb == NULL) { |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 3127 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3128 | return; |
| 3129 | } |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 3130 | |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 3131 | cb->resource = wl_resource_create(client, &wl_callback_interface, 1, |
| 3132 | callback); |
| 3133 | if (cb->resource == NULL) { |
| 3134 | free(cb); |
| 3135 | wl_resource_post_no_memory(resource); |
| 3136 | return; |
| 3137 | } |
| 3138 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3139 | wl_resource_set_implementation(cb->resource, NULL, cb, |
| 3140 | destroy_frame_callback); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3141 | |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 3142 | wl_list_insert(surface->pending.frame_callback_list.prev, &cb->link); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3143 | } |
| 3144 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3145 | static void |
| 3146 | surface_set_opaque_region(struct wl_client *client, |
| 3147 | struct wl_resource *resource, |
| 3148 | struct wl_resource *region_resource) |
| 3149 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3150 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3151 | struct weston_region *region; |
| 3152 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3153 | if (region_resource) { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 3154 | region = wl_resource_get_user_data(region_resource); |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 3155 | pixman_region32_copy(&surface->pending.opaque, |
| 3156 | ®ion->region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3157 | } else { |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 3158 | pixman_region32_clear(&surface->pending.opaque); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3159 | } |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3160 | } |
| 3161 | |
| 3162 | static void |
| 3163 | surface_set_input_region(struct wl_client *client, |
| 3164 | struct wl_resource *resource, |
| 3165 | struct wl_resource *region_resource) |
| 3166 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3167 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 010f98b | 2012-02-23 17:30:45 -0500 | [diff] [blame] | 3168 | struct weston_region *region; |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3169 | |
| 3170 | if (region_resource) { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 3171 | region = wl_resource_get_user_data(region_resource); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3172 | pixman_region32_copy(&surface->pending.input, |
| 3173 | ®ion->region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3174 | } else { |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3175 | pixman_region32_fini(&surface->pending.input); |
| 3176 | region_init_infinite(&surface->pending.input); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3177 | } |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3178 | } |
| 3179 | |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 3180 | /* Cause damage to this sub-surface and all its children. |
| 3181 | * |
| 3182 | * This is useful when there are state changes that need an implicit |
| 3183 | * damage, e.g. a z-order change. |
| 3184 | */ |
| 3185 | static void |
| 3186 | weston_surface_damage_subsurfaces(struct weston_subsurface *sub) |
| 3187 | { |
| 3188 | struct weston_subsurface *child; |
| 3189 | |
| 3190 | weston_surface_damage(sub->surface); |
| 3191 | sub->reordered = false; |
| 3192 | |
| 3193 | wl_list_for_each(child, &sub->surface->subsurface_list, parent_link) |
| 3194 | if (child != sub) |
| 3195 | weston_surface_damage_subsurfaces(child); |
| 3196 | } |
| 3197 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3198 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3199 | weston_surface_commit_subsurface_order(struct weston_surface *surface) |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3200 | { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3201 | struct weston_subsurface *sub; |
| 3202 | |
| 3203 | wl_list_for_each_reverse(sub, &surface->subsurface_list_pending, |
| 3204 | parent_link_pending) { |
| 3205 | wl_list_remove(&sub->parent_link); |
| 3206 | wl_list_insert(&surface->subsurface_list, &sub->parent_link); |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 3207 | |
| 3208 | if (sub->reordered) |
| 3209 | weston_surface_damage_subsurfaces(sub); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3210 | } |
| 3211 | } |
| 3212 | |
| 3213 | static void |
Pekka Paalanen | 04baea5 | 2016-04-26 15:50:58 +0300 | [diff] [blame] | 3214 | weston_surface_build_buffer_matrix(const struct weston_surface *surface, |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 3215 | struct weston_matrix *matrix) |
| 3216 | { |
Pekka Paalanen | 04baea5 | 2016-04-26 15:50:58 +0300 | [diff] [blame] | 3217 | const struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 3218 | double src_width, src_height, dest_width, dest_height; |
| 3219 | |
| 3220 | weston_matrix_init(matrix); |
| 3221 | |
| 3222 | if (vp->buffer.src_width == wl_fixed_from_int(-1)) { |
| 3223 | src_width = surface->width_from_buffer; |
| 3224 | src_height = surface->height_from_buffer; |
| 3225 | } else { |
| 3226 | src_width = wl_fixed_to_double(vp->buffer.src_width); |
| 3227 | src_height = wl_fixed_to_double(vp->buffer.src_height); |
| 3228 | } |
| 3229 | |
| 3230 | if (vp->surface.width == -1) { |
| 3231 | dest_width = src_width; |
| 3232 | dest_height = src_height; |
| 3233 | } else { |
| 3234 | dest_width = vp->surface.width; |
| 3235 | dest_height = vp->surface.height; |
| 3236 | } |
| 3237 | |
| 3238 | if (src_width != dest_width || src_height != dest_height) |
| 3239 | weston_matrix_scale(matrix, |
| 3240 | src_width / dest_width, |
| 3241 | src_height / dest_height, 1); |
| 3242 | |
| 3243 | if (vp->buffer.src_width != wl_fixed_from_int(-1)) |
| 3244 | weston_matrix_translate(matrix, |
| 3245 | wl_fixed_to_double(vp->buffer.src_x), |
| 3246 | wl_fixed_to_double(vp->buffer.src_y), |
| 3247 | 0); |
| 3248 | |
| 3249 | switch (vp->buffer.transform) { |
| 3250 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 3251 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 3252 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 3253 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 3254 | weston_matrix_scale(matrix, -1, 1, 1); |
| 3255 | weston_matrix_translate(matrix, |
| 3256 | surface->width_from_buffer, 0, 0); |
| 3257 | break; |
| 3258 | } |
| 3259 | |
| 3260 | switch (vp->buffer.transform) { |
| 3261 | default: |
| 3262 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 3263 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 3264 | break; |
| 3265 | case WL_OUTPUT_TRANSFORM_90: |
| 3266 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 3267 | weston_matrix_rotate_xy(matrix, 0, 1); |
| 3268 | weston_matrix_translate(matrix, |
| 3269 | surface->height_from_buffer, 0, 0); |
| 3270 | break; |
| 3271 | case WL_OUTPUT_TRANSFORM_180: |
| 3272 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 3273 | weston_matrix_rotate_xy(matrix, -1, 0); |
| 3274 | weston_matrix_translate(matrix, |
| 3275 | surface->width_from_buffer, |
| 3276 | surface->height_from_buffer, 0); |
| 3277 | break; |
| 3278 | case WL_OUTPUT_TRANSFORM_270: |
| 3279 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 3280 | weston_matrix_rotate_xy(matrix, 0, -1); |
| 3281 | weston_matrix_translate(matrix, |
| 3282 | 0, surface->width_from_buffer, 0); |
| 3283 | break; |
| 3284 | } |
| 3285 | |
| 3286 | weston_matrix_scale(matrix, vp->buffer.scale, vp->buffer.scale, 1); |
| 3287 | } |
| 3288 | |
Pekka Paalanen | d9aae9c | 2016-04-26 13:46:38 +0300 | [diff] [blame] | 3289 | /** |
| 3290 | * Compute a + b > c while being safe to overflows. |
| 3291 | */ |
| 3292 | static bool |
| 3293 | fixed_sum_gt(wl_fixed_t a, wl_fixed_t b, wl_fixed_t c) |
| 3294 | { |
| 3295 | return (int64_t)a + (int64_t)b > (int64_t)c; |
| 3296 | } |
| 3297 | |
| 3298 | static bool |
| 3299 | weston_surface_is_pending_viewport_source_valid( |
| 3300 | const struct weston_surface *surface) |
| 3301 | { |
| 3302 | const struct weston_surface_state *pend = &surface->pending; |
| 3303 | const struct weston_buffer_viewport *vp = &pend->buffer_viewport; |
| 3304 | int width_from_buffer = 0; |
| 3305 | int height_from_buffer = 0; |
| 3306 | wl_fixed_t w; |
| 3307 | wl_fixed_t h; |
| 3308 | |
| 3309 | /* If viewport source rect is not set, it is always ok. */ |
| 3310 | if (vp->buffer.src_width == wl_fixed_from_int(-1)) |
| 3311 | return true; |
| 3312 | |
| 3313 | if (pend->newly_attached) { |
| 3314 | if (pend->buffer) { |
| 3315 | convert_size_by_transform_scale(&width_from_buffer, |
| 3316 | &height_from_buffer, |
| 3317 | pend->buffer->width, |
| 3318 | pend->buffer->height, |
| 3319 | vp->buffer.transform, |
| 3320 | vp->buffer.scale); |
| 3321 | } else { |
| 3322 | /* No buffer: viewport is irrelevant. */ |
| 3323 | return true; |
| 3324 | } |
| 3325 | } else { |
| 3326 | width_from_buffer = surface->width_from_buffer; |
| 3327 | height_from_buffer = surface->height_from_buffer; |
| 3328 | } |
| 3329 | |
| 3330 | assert((width_from_buffer == 0) == (height_from_buffer == 0)); |
| 3331 | assert(width_from_buffer >= 0 && height_from_buffer >= 0); |
| 3332 | |
| 3333 | /* No buffer: viewport is irrelevant. */ |
| 3334 | if (width_from_buffer == 0 || height_from_buffer == 0) |
| 3335 | return true; |
| 3336 | |
| 3337 | /* overflow checks for wl_fixed_from_int() */ |
| 3338 | if (width_from_buffer > wl_fixed_to_int(INT32_MAX)) |
| 3339 | return false; |
| 3340 | if (height_from_buffer > wl_fixed_to_int(INT32_MAX)) |
| 3341 | return false; |
| 3342 | |
| 3343 | w = wl_fixed_from_int(width_from_buffer); |
| 3344 | h = wl_fixed_from_int(height_from_buffer); |
| 3345 | |
| 3346 | if (fixed_sum_gt(vp->buffer.src_x, vp->buffer.src_width, w)) |
| 3347 | return false; |
| 3348 | if (fixed_sum_gt(vp->buffer.src_y, vp->buffer.src_height, h)) |
| 3349 | return false; |
| 3350 | |
| 3351 | return true; |
| 3352 | } |
| 3353 | |
Pekka Paalanen | bb32ccc | 2016-04-26 14:28:28 +0300 | [diff] [blame] | 3354 | static bool |
| 3355 | fixed_is_integer(wl_fixed_t v) |
| 3356 | { |
| 3357 | return (v & 0xff) == 0; |
| 3358 | } |
| 3359 | |
| 3360 | static bool |
| 3361 | weston_surface_is_pending_viewport_dst_size_int( |
| 3362 | const struct weston_surface *surface) |
| 3363 | { |
| 3364 | const struct weston_buffer_viewport *vp = |
| 3365 | &surface->pending.buffer_viewport; |
| 3366 | |
| 3367 | if (vp->surface.width != -1) { |
| 3368 | assert(vp->surface.width > 0 && vp->surface.height > 0); |
| 3369 | return true; |
| 3370 | } |
| 3371 | |
| 3372 | return fixed_is_integer(vp->buffer.src_width) && |
| 3373 | fixed_is_integer(vp->buffer.src_height); |
| 3374 | } |
| 3375 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3376 | /* Translate pending damage in buffer co-ordinates to surface |
| 3377 | * co-ordinates and union it with a pixman_region32_t. |
| 3378 | * This should only be called after the buffer is attached. |
| 3379 | */ |
| 3380 | static void |
| 3381 | apply_damage_buffer(pixman_region32_t *dest, |
| 3382 | struct weston_surface *surface, |
| 3383 | struct weston_surface_state *state) |
| 3384 | { |
| 3385 | struct weston_buffer *buffer = surface->buffer_ref.buffer; |
| 3386 | |
| 3387 | /* wl_surface.damage_buffer needs to be clipped to the buffer, |
| 3388 | * translated into surface co-ordinates and unioned with |
| 3389 | * any other surface damage. |
| 3390 | * None of this makes sense if there is no buffer though. |
| 3391 | */ |
| 3392 | if (buffer && pixman_region32_not_empty(&state->damage_buffer)) { |
| 3393 | pixman_region32_t buffer_damage; |
| 3394 | |
| 3395 | pixman_region32_intersect_rect(&state->damage_buffer, |
| 3396 | &state->damage_buffer, |
| 3397 | 0, 0, buffer->width, |
| 3398 | buffer->height); |
| 3399 | pixman_region32_init(&buffer_damage); |
| 3400 | weston_matrix_transform_region(&buffer_damage, |
| 3401 | &surface->buffer_to_surface_matrix, |
| 3402 | &state->damage_buffer); |
| 3403 | pixman_region32_union(dest, dest, &buffer_damage); |
| 3404 | pixman_region32_fini(&buffer_damage); |
| 3405 | } |
| 3406 | /* We should clear this on commit even if there was no buffer */ |
| 3407 | pixman_region32_clear(&state->damage_buffer); |
| 3408 | } |
| 3409 | |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 3410 | static void |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 3411 | weston_surface_set_desired_protection(struct weston_surface *surface, |
| 3412 | enum weston_hdcp_protection protection) |
| 3413 | { |
| 3414 | if (surface->desired_protection == protection) |
| 3415 | return; |
| 3416 | surface->desired_protection = protection; |
| 3417 | weston_surface_damage(surface); |
| 3418 | } |
| 3419 | |
| 3420 | static void |
Ankit Nautiyal | 5cfe03c | 2019-03-28 15:05:42 +0530 | [diff] [blame] | 3421 | weston_surface_set_protection_mode(struct weston_surface *surface, |
| 3422 | enum weston_surface_protection_mode p_mode) |
| 3423 | { |
| 3424 | struct content_protection *cp = surface->compositor->content_protection; |
| 3425 | struct protected_surface *psurface; |
| 3426 | |
| 3427 | surface->protection_mode = p_mode; |
| 3428 | wl_list_for_each(psurface, &cp->protected_list, link) { |
| 3429 | if (!psurface || psurface->surface != surface) |
| 3430 | continue; |
| 3431 | weston_protected_surface_send_event(psurface, |
| 3432 | surface->current_protection); |
| 3433 | } |
| 3434 | } |
| 3435 | |
| 3436 | static void |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3437 | weston_surface_commit_state(struct weston_surface *surface, |
| 3438 | struct weston_surface_state *state) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3439 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3440 | struct weston_view *view; |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 3441 | pixman_region32_t opaque; |
| 3442 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3443 | /* wl_surface.set_buffer_transform */ |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3444 | /* wl_surface.set_buffer_scale */ |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 3445 | /* wp_viewport.set_source */ |
| 3446 | /* wp_viewport.set_destination */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3447 | surface->buffer_viewport = state->buffer_viewport; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3448 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3449 | /* wl_surface.attach */ |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3450 | if (state->newly_attached) { |
| 3451 | /* zwp_surface_synchronization_v1.set_acquire_fence */ |
| 3452 | fd_move(&surface->acquire_fence_fd, |
| 3453 | &state->acquire_fence_fd); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3454 | /* zwp_surface_synchronization_v1.get_release */ |
| 3455 | weston_buffer_release_move(&surface->buffer_release_ref, |
| 3456 | &state->buffer_release_ref); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3457 | weston_surface_attach(surface, state->buffer); |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3458 | } |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3459 | weston_surface_state_set_buffer(state, NULL); |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3460 | assert(state->acquire_fence_fd == -1); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3461 | assert(state->buffer_release_ref.buffer_release == NULL); |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3462 | |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 3463 | weston_surface_build_buffer_matrix(surface, |
| 3464 | &surface->surface_to_buffer_matrix); |
| 3465 | weston_matrix_invert(&surface->buffer_to_surface_matrix, |
| 3466 | &surface->surface_to_buffer_matrix); |
| 3467 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3468 | if (state->newly_attached || state->buffer_viewport.changed) { |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3469 | weston_surface_update_size(surface); |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3470 | if (surface->committed) |
| 3471 | surface->committed(surface, state->sx, state->sy); |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3472 | } |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3473 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3474 | state->sx = 0; |
| 3475 | state->sy = 0; |
| 3476 | state->newly_attached = 0; |
| 3477 | state->buffer_viewport.changed = 0; |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 3478 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3479 | /* wl_surface.damage and wl_surface.damage_buffer */ |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3480 | if (weston_timeline_enabled_ && |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3481 | (pixman_region32_not_empty(&state->damage_surface) || |
| 3482 | pixman_region32_not_empty(&state->damage_buffer))) |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3483 | TL_POINT("core_commit_damage", TLP_SURFACE(surface), TLP_END); |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3484 | |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 3485 | pixman_region32_union(&surface->damage, &surface->damage, |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3486 | &state->damage_surface); |
| 3487 | |
| 3488 | apply_damage_buffer(&surface->damage, surface, state); |
| 3489 | |
Kristian Høgsberg | 4d0214c | 2012-11-08 11:36:02 -0500 | [diff] [blame] | 3490 | pixman_region32_intersect_rect(&surface->damage, &surface->damage, |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 3491 | 0, 0, surface->width, surface->height); |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3492 | pixman_region32_clear(&state->damage_surface); |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 3493 | |
| 3494 | /* wl_surface.set_opaque_region */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3495 | pixman_region32_init(&opaque); |
| 3496 | pixman_region32_intersect_rect(&opaque, &state->opaque, |
| 3497 | 0, 0, surface->width, surface->height); |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 3498 | |
| 3499 | if (!pixman_region32_equal(&opaque, &surface->opaque)) { |
| 3500 | pixman_region32_copy(&surface->opaque, &opaque); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3501 | wl_list_for_each(view, &surface->views, surface_link) |
| 3502 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 3503 | } |
| 3504 | |
| 3505 | pixman_region32_fini(&opaque); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3506 | |
| 3507 | /* wl_surface.set_input_region */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3508 | pixman_region32_intersect_rect(&surface->input, &state->input, |
| 3509 | 0, 0, surface->width, surface->height); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3510 | |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 3511 | /* wl_surface.frame */ |
| 3512 | wl_list_insert_list(&surface->frame_callback_list, |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3513 | &state->frame_callback_list); |
| 3514 | wl_list_init(&state->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3515 | |
| 3516 | /* XXX: |
| 3517 | * What should happen with a feedback request, if there |
| 3518 | * is no wl_buffer attached for this commit? |
| 3519 | */ |
| 3520 | |
| 3521 | /* presentation.feedback */ |
| 3522 | wl_list_insert_list(&surface->feedback_list, |
| 3523 | &state->feedback_list); |
| 3524 | wl_list_init(&state->feedback_list); |
Jonas Ådahl | 5d9ca27 | 2016-07-22 17:48:03 +0800 | [diff] [blame] | 3525 | |
Ankit Nautiyal | 5cfe03c | 2019-03-28 15:05:42 +0530 | [diff] [blame] | 3526 | /* weston_protected_surface.enforced/relaxed */ |
| 3527 | if (surface->protection_mode != state->protection_mode) |
| 3528 | weston_surface_set_protection_mode(surface, |
| 3529 | state->protection_mode); |
| 3530 | |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 3531 | /* weston_protected_surface.set_type */ |
| 3532 | weston_surface_set_desired_protection(surface, state->desired_protection); |
| 3533 | |
Jonas Ådahl | 5d9ca27 | 2016-07-22 17:48:03 +0800 | [diff] [blame] | 3534 | wl_signal_emit(&surface->commit_signal, surface); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3535 | } |
| 3536 | |
| 3537 | static void |
| 3538 | weston_surface_commit(struct weston_surface *surface) |
| 3539 | { |
| 3540 | weston_surface_commit_state(surface, &surface->pending); |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 3541 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3542 | weston_surface_commit_subsurface_order(surface); |
| 3543 | |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3544 | weston_surface_schedule_repaint(surface); |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3545 | } |
| 3546 | |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3547 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3548 | weston_subsurface_commit(struct weston_subsurface *sub); |
| 3549 | |
| 3550 | static void |
| 3551 | weston_subsurface_parent_commit(struct weston_subsurface *sub, |
| 3552 | int parent_is_synchronized); |
| 3553 | |
| 3554 | static void |
| 3555 | surface_commit(struct wl_client *client, struct wl_resource *resource) |
| 3556 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3557 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3558 | struct weston_subsurface *sub = weston_surface_to_subsurface(surface); |
| 3559 | |
Pekka Paalanen | d9aae9c | 2016-04-26 13:46:38 +0300 | [diff] [blame] | 3560 | if (!weston_surface_is_pending_viewport_source_valid(surface)) { |
| 3561 | assert(surface->viewport_resource); |
| 3562 | |
| 3563 | wl_resource_post_error(surface->viewport_resource, |
| 3564 | WP_VIEWPORT_ERROR_OUT_OF_BUFFER, |
| 3565 | "wl_surface@%d has viewport source outside buffer", |
| 3566 | wl_resource_get_id(resource)); |
| 3567 | return; |
| 3568 | } |
| 3569 | |
Pekka Paalanen | bb32ccc | 2016-04-26 14:28:28 +0300 | [diff] [blame] | 3570 | if (!weston_surface_is_pending_viewport_dst_size_int(surface)) { |
| 3571 | assert(surface->viewport_resource); |
| 3572 | |
| 3573 | wl_resource_post_error(surface->viewport_resource, |
| 3574 | WP_VIEWPORT_ERROR_BAD_SIZE, |
| 3575 | "wl_surface@%d viewport dst size not integer", |
| 3576 | wl_resource_get_id(resource)); |
| 3577 | return; |
| 3578 | } |
| 3579 | |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3580 | if (surface->pending.acquire_fence_fd >= 0) { |
| 3581 | assert(surface->synchronization_resource); |
| 3582 | |
| 3583 | if (!surface->pending.buffer) { |
| 3584 | fd_clear(&surface->pending.acquire_fence_fd); |
| 3585 | wl_resource_post_error(surface->synchronization_resource, |
| 3586 | ZWP_LINUX_SURFACE_SYNCHRONIZATION_V1_ERROR_NO_BUFFER, |
| 3587 | "wl_surface@%"PRIu32" no buffer for synchronization", |
| 3588 | wl_resource_get_id(resource)); |
| 3589 | return; |
| 3590 | } |
| 3591 | |
| 3592 | /* We support fences for both wp_linux_dmabuf and opaque EGL |
| 3593 | * buffers, as mandated by minor version 2 of the |
| 3594 | * zwp_linux_explicit_synchronization_v1 protocol. Since |
| 3595 | * renderers that support fences currently only support these |
| 3596 | * two buffer types plus SHM buffers, we can just check for the |
| 3597 | * SHM buffer case here. |
| 3598 | */ |
| 3599 | if (wl_shm_buffer_get(surface->pending.buffer->resource)) { |
| 3600 | fd_clear(&surface->pending.acquire_fence_fd); |
| 3601 | wl_resource_post_error(surface->synchronization_resource, |
| 3602 | ZWP_LINUX_SURFACE_SYNCHRONIZATION_V1_ERROR_UNSUPPORTED_BUFFER, |
| 3603 | "wl_surface@%"PRIu32" unsupported buffer for synchronization", |
| 3604 | wl_resource_get_id(resource)); |
| 3605 | return; |
| 3606 | } |
| 3607 | } |
| 3608 | |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3609 | if (surface->pending.buffer_release_ref.buffer_release && |
| 3610 | !surface->pending.buffer) { |
| 3611 | assert(surface->synchronization_resource); |
| 3612 | |
| 3613 | wl_resource_post_error(surface->synchronization_resource, |
| 3614 | ZWP_LINUX_SURFACE_SYNCHRONIZATION_V1_ERROR_NO_BUFFER, |
| 3615 | "wl_surface@%"PRIu32" no buffer for synchronization", |
| 3616 | wl_resource_get_id(resource)); |
| 3617 | return; |
| 3618 | } |
| 3619 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3620 | if (sub) { |
| 3621 | weston_subsurface_commit(sub); |
| 3622 | return; |
| 3623 | } |
| 3624 | |
| 3625 | weston_surface_commit(surface); |
| 3626 | |
| 3627 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
| 3628 | if (sub->surface != surface) |
| 3629 | weston_subsurface_parent_commit(sub, 0); |
| 3630 | } |
| 3631 | } |
| 3632 | |
| 3633 | static void |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3634 | surface_set_buffer_transform(struct wl_client *client, |
| 3635 | struct wl_resource *resource, int transform) |
| 3636 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3637 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3638 | |
Jonny Lamb | a55f139 | 2014-05-30 12:07:15 +0200 | [diff] [blame] | 3639 | /* if wl_output.transform grows more members this will need to be updated. */ |
| 3640 | if (transform < 0 || |
| 3641 | transform > WL_OUTPUT_TRANSFORM_FLIPPED_270) { |
| 3642 | wl_resource_post_error(resource, |
| 3643 | WL_SURFACE_ERROR_INVALID_TRANSFORM, |
| 3644 | "buffer transform must be a valid transform " |
| 3645 | "('%d' specified)", transform); |
| 3646 | return; |
| 3647 | } |
| 3648 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 3649 | surface->pending.buffer_viewport.buffer.transform = transform; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3650 | surface->pending.buffer_viewport.changed = 1; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3651 | } |
| 3652 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3653 | static void |
| 3654 | surface_set_buffer_scale(struct wl_client *client, |
| 3655 | struct wl_resource *resource, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 3656 | int32_t scale) |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3657 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3658 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3659 | |
Jonny Lamb | a55f139 | 2014-05-30 12:07:15 +0200 | [diff] [blame] | 3660 | if (scale < 1) { |
| 3661 | wl_resource_post_error(resource, |
| 3662 | WL_SURFACE_ERROR_INVALID_SCALE, |
| 3663 | "buffer scale must be at least one " |
| 3664 | "('%d' specified)", scale); |
| 3665 | return; |
| 3666 | } |
| 3667 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 3668 | surface->pending.buffer_viewport.buffer.scale = scale; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3669 | surface->pending.buffer_viewport.changed = 1; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3670 | } |
| 3671 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 3672 | static const struct wl_surface_interface surface_interface = { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3673 | surface_destroy, |
| 3674 | surface_attach, |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3675 | surface_damage, |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3676 | surface_frame, |
| 3677 | surface_set_opaque_region, |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3678 | surface_set_input_region, |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3679 | surface_commit, |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3680 | surface_set_buffer_transform, |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3681 | surface_set_buffer_scale, |
| 3682 | surface_damage_buffer |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3683 | }; |
| 3684 | |
| 3685 | static void |
| 3686 | compositor_create_surface(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 3687 | struct wl_resource *resource, uint32_t id) |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3688 | { |
Kristian Høgsberg | c2d7042 | 2013-06-25 15:34:33 -0400 | [diff] [blame] | 3689 | struct weston_compositor *ec = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3690 | struct weston_surface *surface; |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3691 | |
Kristian Høgsberg | 18c9300 | 2012-01-27 11:58:31 -0500 | [diff] [blame] | 3692 | surface = weston_surface_create(ec); |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 3693 | if (surface == NULL) { |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 3694 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3695 | return; |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 3696 | } |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3697 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3698 | surface->resource = |
| 3699 | wl_resource_create(client, &wl_surface_interface, |
| 3700 | wl_resource_get_version(resource), id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 3701 | if (surface->resource == NULL) { |
| 3702 | weston_surface_destroy(surface); |
| 3703 | wl_resource_post_no_memory(resource); |
| 3704 | return; |
| 3705 | } |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3706 | wl_resource_set_implementation(surface->resource, &surface_interface, |
| 3707 | surface, destroy_surface); |
Kristian Høgsberg | f03a04a | 2014-04-06 22:04:50 -0700 | [diff] [blame] | 3708 | |
| 3709 | wl_signal_emit(&ec->create_surface_signal, surface); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3710 | } |
| 3711 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3712 | static void |
| 3713 | destroy_region(struct wl_resource *resource) |
| 3714 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 3715 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3716 | |
| 3717 | pixman_region32_fini(®ion->region); |
| 3718 | free(region); |
| 3719 | } |
| 3720 | |
| 3721 | static void |
| 3722 | region_destroy(struct wl_client *client, struct wl_resource *resource) |
| 3723 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3724 | wl_resource_destroy(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3725 | } |
| 3726 | |
| 3727 | static void |
| 3728 | region_add(struct wl_client *client, struct wl_resource *resource, |
| 3729 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 3730 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 3731 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3732 | |
| 3733 | pixman_region32_union_rect(®ion->region, ®ion->region, |
| 3734 | x, y, width, height); |
| 3735 | } |
| 3736 | |
| 3737 | static void |
| 3738 | region_subtract(struct wl_client *client, struct wl_resource *resource, |
| 3739 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 3740 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 3741 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3742 | pixman_region32_t rect; |
| 3743 | |
| 3744 | pixman_region32_init_rect(&rect, x, y, width, height); |
| 3745 | pixman_region32_subtract(®ion->region, ®ion->region, &rect); |
| 3746 | pixman_region32_fini(&rect); |
| 3747 | } |
| 3748 | |
| 3749 | static const struct wl_region_interface region_interface = { |
| 3750 | region_destroy, |
| 3751 | region_add, |
| 3752 | region_subtract |
| 3753 | }; |
| 3754 | |
| 3755 | static void |
| 3756 | compositor_create_region(struct wl_client *client, |
| 3757 | struct wl_resource *resource, uint32_t id) |
| 3758 | { |
| 3759 | struct weston_region *region; |
| 3760 | |
| 3761 | region = malloc(sizeof *region); |
| 3762 | if (region == NULL) { |
| 3763 | wl_resource_post_no_memory(resource); |
| 3764 | return; |
| 3765 | } |
| 3766 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3767 | pixman_region32_init(®ion->region); |
| 3768 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3769 | region->resource = |
| 3770 | wl_resource_create(client, &wl_region_interface, 1, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 3771 | if (region->resource == NULL) { |
| 3772 | free(region); |
| 3773 | wl_resource_post_no_memory(resource); |
| 3774 | return; |
| 3775 | } |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3776 | wl_resource_set_implementation(region->resource, ®ion_interface, |
| 3777 | region, destroy_region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3778 | } |
| 3779 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 3780 | static const struct wl_compositor_interface compositor_interface = { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3781 | compositor_create_surface, |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3782 | compositor_create_region |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3783 | }; |
| 3784 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3785 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3786 | weston_subsurface_commit_from_cache(struct weston_subsurface *sub) |
| 3787 | { |
| 3788 | struct weston_surface *surface = sub->surface; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3789 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3790 | weston_surface_commit_state(surface, &sub->cached); |
| 3791 | weston_buffer_reference(&sub->cached_buffer_ref, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3792 | |
| 3793 | weston_surface_commit_subsurface_order(surface); |
| 3794 | |
| 3795 | weston_surface_schedule_repaint(surface); |
| 3796 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3797 | sub->has_cached_data = 0; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3798 | } |
| 3799 | |
| 3800 | static void |
| 3801 | weston_subsurface_commit_to_cache(struct weston_subsurface *sub) |
| 3802 | { |
| 3803 | struct weston_surface *surface = sub->surface; |
| 3804 | |
| 3805 | /* |
| 3806 | * If this commit would cause the surface to move by the |
| 3807 | * attach(dx, dy) parameters, the old damage region must be |
| 3808 | * translated to correspond to the new surface coordinate system |
Chris Michael | 062edf2 | 2015-11-26 11:30:00 -0500 | [diff] [blame] | 3809 | * origin. |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3810 | */ |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3811 | pixman_region32_translate(&sub->cached.damage_surface, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3812 | -surface->pending.sx, -surface->pending.sy); |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3813 | pixman_region32_union(&sub->cached.damage_surface, |
| 3814 | &sub->cached.damage_surface, |
| 3815 | &surface->pending.damage_surface); |
| 3816 | pixman_region32_clear(&surface->pending.damage_surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3817 | |
| 3818 | if (surface->pending.newly_attached) { |
| 3819 | sub->cached.newly_attached = 1; |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3820 | weston_surface_state_set_buffer(&sub->cached, |
| 3821 | surface->pending.buffer); |
| 3822 | weston_buffer_reference(&sub->cached_buffer_ref, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3823 | surface->pending.buffer); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3824 | weston_presentation_feedback_discard_list( |
| 3825 | &sub->cached.feedback_list); |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3826 | /* zwp_surface_synchronization_v1.set_acquire_fence */ |
| 3827 | fd_move(&sub->cached.acquire_fence_fd, |
| 3828 | &surface->pending.acquire_fence_fd); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3829 | /* zwp_surface_synchronization_v1.get_release */ |
| 3830 | weston_buffer_release_move(&sub->cached.buffer_release_ref, |
| 3831 | &surface->pending.buffer_release_ref); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3832 | } |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 3833 | sub->cached.desired_protection = surface->pending.desired_protection; |
Ankit Nautiyal | 5cfe03c | 2019-03-28 15:05:42 +0530 | [diff] [blame] | 3834 | sub->cached.protection_mode = surface->pending.protection_mode; |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3835 | assert(surface->pending.acquire_fence_fd == -1); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3836 | assert(surface->pending.buffer_release_ref.buffer_release == NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3837 | sub->cached.sx += surface->pending.sx; |
| 3838 | sub->cached.sy += surface->pending.sy; |
Pekka Paalanen | 260ba38 | 2014-03-14 14:38:12 +0200 | [diff] [blame] | 3839 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3840 | apply_damage_buffer(&sub->cached.damage_surface, surface, &surface->pending); |
| 3841 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3842 | sub->cached.buffer_viewport.changed |= |
| 3843 | surface->pending.buffer_viewport.changed; |
| 3844 | sub->cached.buffer_viewport.buffer = |
| 3845 | surface->pending.buffer_viewport.buffer; |
| 3846 | sub->cached.buffer_viewport.surface = |
| 3847 | surface->pending.buffer_viewport.surface; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3848 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3849 | weston_surface_reset_pending_buffer(surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3850 | |
| 3851 | pixman_region32_copy(&sub->cached.opaque, &surface->pending.opaque); |
| 3852 | |
| 3853 | pixman_region32_copy(&sub->cached.input, &surface->pending.input); |
| 3854 | |
| 3855 | wl_list_insert_list(&sub->cached.frame_callback_list, |
| 3856 | &surface->pending.frame_callback_list); |
| 3857 | wl_list_init(&surface->pending.frame_callback_list); |
| 3858 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3859 | wl_list_insert_list(&sub->cached.feedback_list, |
| 3860 | &surface->pending.feedback_list); |
| 3861 | wl_list_init(&surface->pending.feedback_list); |
| 3862 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3863 | sub->has_cached_data = 1; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3864 | } |
| 3865 | |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 3866 | static bool |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3867 | weston_subsurface_is_synchronized(struct weston_subsurface *sub) |
| 3868 | { |
| 3869 | while (sub) { |
| 3870 | if (sub->synchronized) |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 3871 | return true; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3872 | |
| 3873 | if (!sub->parent) |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 3874 | return false; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3875 | |
| 3876 | sub = weston_surface_to_subsurface(sub->parent); |
| 3877 | } |
| 3878 | |
Carlos Olmedo Escobar | 61a9bf5 | 2014-11-04 14:38:39 +0100 | [diff] [blame] | 3879 | return false; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3880 | } |
| 3881 | |
| 3882 | static void |
| 3883 | weston_subsurface_commit(struct weston_subsurface *sub) |
| 3884 | { |
| 3885 | struct weston_surface *surface = sub->surface; |
| 3886 | struct weston_subsurface *tmp; |
| 3887 | |
| 3888 | /* Recursive check for effectively synchronized. */ |
| 3889 | if (weston_subsurface_is_synchronized(sub)) { |
| 3890 | weston_subsurface_commit_to_cache(sub); |
| 3891 | } else { |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3892 | if (sub->has_cached_data) { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3893 | /* flush accumulated state from cache */ |
| 3894 | weston_subsurface_commit_to_cache(sub); |
| 3895 | weston_subsurface_commit_from_cache(sub); |
| 3896 | } else { |
| 3897 | weston_surface_commit(surface); |
| 3898 | } |
| 3899 | |
| 3900 | wl_list_for_each(tmp, &surface->subsurface_list, parent_link) { |
| 3901 | if (tmp->surface != surface) |
| 3902 | weston_subsurface_parent_commit(tmp, 0); |
| 3903 | } |
| 3904 | } |
| 3905 | } |
| 3906 | |
| 3907 | static void |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3908 | weston_subsurface_synchronized_commit(struct weston_subsurface *sub) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3909 | { |
| 3910 | struct weston_surface *surface = sub->surface; |
| 3911 | struct weston_subsurface *tmp; |
| 3912 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3913 | /* From now on, commit_from_cache the whole sub-tree, regardless of |
| 3914 | * the synchronized mode of each child. This sub-surface or some |
| 3915 | * of its ancestors were synchronized, so we are synchronized |
| 3916 | * all the way down. |
| 3917 | */ |
| 3918 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3919 | if (sub->has_cached_data) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3920 | weston_subsurface_commit_from_cache(sub); |
| 3921 | |
| 3922 | wl_list_for_each(tmp, &surface->subsurface_list, parent_link) { |
| 3923 | if (tmp->surface != surface) |
| 3924 | weston_subsurface_parent_commit(tmp, 1); |
| 3925 | } |
| 3926 | } |
| 3927 | |
| 3928 | static void |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3929 | weston_subsurface_parent_commit(struct weston_subsurface *sub, |
| 3930 | int parent_is_synchronized) |
| 3931 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3932 | struct weston_view *view; |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3933 | if (sub->position.set) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3934 | wl_list_for_each(view, &sub->surface->views, surface_link) |
| 3935 | weston_view_set_position(view, |
| 3936 | sub->position.x, |
| 3937 | sub->position.y); |
| 3938 | |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3939 | sub->position.set = 0; |
| 3940 | } |
| 3941 | |
| 3942 | if (parent_is_synchronized || sub->synchronized) |
| 3943 | weston_subsurface_synchronized_commit(sub); |
| 3944 | } |
| 3945 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3946 | static int |
| 3947 | subsurface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 3948 | { |
| 3949 | return snprintf(buf, len, "sub-surface"); |
| 3950 | } |
| 3951 | |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3952 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3953 | subsurface_committed(struct weston_surface *surface, int32_t dx, int32_t dy) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3954 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3955 | struct weston_view *view; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3956 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3957 | wl_list_for_each(view, &surface->views, surface_link) |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3958 | weston_view_set_position(view, |
| 3959 | view->geometry.x + dx, |
| 3960 | view->geometry.y + dy); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3961 | |
| 3962 | /* No need to check parent mappedness, because if parent is not |
| 3963 | * mapped, parent is not in a visible layer, so this sub-surface |
| 3964 | * will not be drawn either. |
| 3965 | */ |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 3966 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3967 | if (!weston_surface_is_mapped(surface)) { |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 3968 | surface->is_mapped = true; |
Pekka Paalanen | eb3cf22 | 2014-06-30 11:52:07 +0300 | [diff] [blame] | 3969 | |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 3970 | /* Cannot call weston_view_update_transform(), |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3971 | * because that would call it also for the parent surface, |
| 3972 | * which might not be mapped yet. That would lead to |
| 3973 | * inconsistent state, where the window could never be |
| 3974 | * mapped. |
| 3975 | * |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 3976 | * Instead just force the is_mapped flag on, to make |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3977 | * weston_surface_is_mapped() return true, so that when the |
| 3978 | * parent surface does get mapped, this one will get |
Pekka Paalanen | eb3cf22 | 2014-06-30 11:52:07 +0300 | [diff] [blame] | 3979 | * included, too. See view_list_add(). |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3980 | */ |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3981 | } |
| 3982 | } |
| 3983 | |
| 3984 | static struct weston_subsurface * |
| 3985 | weston_surface_to_subsurface(struct weston_surface *surface) |
| 3986 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3987 | if (surface->committed == subsurface_committed) |
| 3988 | return surface->committed_private; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3989 | |
| 3990 | return NULL; |
| 3991 | } |
| 3992 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3993 | WL_EXPORT struct weston_surface * |
| 3994 | weston_surface_get_main_surface(struct weston_surface *surface) |
| 3995 | { |
| 3996 | struct weston_subsurface *sub; |
| 3997 | |
| 3998 | while (surface && (sub = weston_surface_to_subsurface(surface))) |
| 3999 | surface = sub->parent; |
| 4000 | |
| 4001 | return surface; |
| 4002 | } |
| 4003 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4004 | WL_EXPORT int |
| 4005 | weston_surface_set_role(struct weston_surface *surface, |
| 4006 | const char *role_name, |
| 4007 | struct wl_resource *error_resource, |
| 4008 | uint32_t error_code) |
| 4009 | { |
| 4010 | assert(role_name); |
| 4011 | |
| 4012 | if (surface->role_name == NULL || |
| 4013 | surface->role_name == role_name || |
| 4014 | strcmp(surface->role_name, role_name) == 0) { |
| 4015 | surface->role_name = role_name; |
| 4016 | |
| 4017 | return 0; |
| 4018 | } |
| 4019 | |
| 4020 | wl_resource_post_error(error_resource, error_code, |
| 4021 | "Cannot assign role %s to wl_surface@%d," |
| 4022 | " already has role %s\n", |
| 4023 | role_name, |
| 4024 | wl_resource_get_id(surface->resource), |
| 4025 | surface->role_name); |
| 4026 | return -1; |
| 4027 | } |
| 4028 | |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 4029 | WL_EXPORT const char * |
| 4030 | weston_surface_get_role(struct weston_surface *surface) |
| 4031 | { |
| 4032 | return surface->role_name; |
| 4033 | } |
| 4034 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4035 | WL_EXPORT void |
| 4036 | weston_surface_set_label_func(struct weston_surface *surface, |
| 4037 | int (*desc)(struct weston_surface *, |
| 4038 | char *, size_t)) |
| 4039 | { |
| 4040 | surface->get_label = desc; |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 4041 | surface->timeline.force_refresh = 1; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4042 | } |
| 4043 | |
Pekka Paalanen | c647ed7 | 2015-02-09 13:16:57 +0200 | [diff] [blame] | 4044 | /** Get the size of surface contents |
| 4045 | * |
| 4046 | * \param surface The surface to query. |
| 4047 | * \param width Returns the width of raw contents. |
| 4048 | * \param height Returns the height of raw contents. |
| 4049 | * |
| 4050 | * Retrieves the raw surface content size in pixels for the given surface. |
| 4051 | * This is the whole content size in buffer pixels. If the surface |
| 4052 | * has no content or the renderer does not implement this feature, |
| 4053 | * zeroes are returned. |
| 4054 | * |
| 4055 | * This function is used to determine the buffer size needed for |
| 4056 | * a weston_surface_copy_content() call. |
| 4057 | */ |
| 4058 | WL_EXPORT void |
| 4059 | weston_surface_get_content_size(struct weston_surface *surface, |
| 4060 | int *width, int *height) |
| 4061 | { |
| 4062 | struct weston_renderer *rer = surface->compositor->renderer; |
| 4063 | |
| 4064 | if (!rer->surface_get_content_size) { |
| 4065 | *width = 0; |
| 4066 | *height = 0; |
| 4067 | return; |
| 4068 | } |
| 4069 | |
| 4070 | rer->surface_get_content_size(surface, width, height); |
| 4071 | } |
| 4072 | |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 4073 | /** Get the bounding box of a surface and its subsurfaces |
| 4074 | * |
| 4075 | * \param surface The surface to query. |
| 4076 | * \return The bounding box relative to the surface origin. |
| 4077 | * |
| 4078 | */ |
| 4079 | WL_EXPORT struct weston_geometry |
| 4080 | weston_surface_get_bounding_box(struct weston_surface *surface) |
| 4081 | { |
| 4082 | pixman_region32_t region; |
| 4083 | pixman_box32_t *box; |
| 4084 | struct weston_subsurface *subsurface; |
| 4085 | |
| 4086 | pixman_region32_init_rect(®ion, |
| 4087 | 0, 0, |
| 4088 | surface->width, surface->height); |
| 4089 | |
| 4090 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) |
| 4091 | pixman_region32_union_rect(®ion, ®ion, |
| 4092 | subsurface->position.x, |
| 4093 | subsurface->position.y, |
| 4094 | subsurface->surface->width, |
| 4095 | subsurface->surface->height); |
| 4096 | |
| 4097 | box = pixman_region32_extents(®ion); |
| 4098 | struct weston_geometry geometry = { |
| 4099 | .x = box->x1, |
| 4100 | .y = box->y1, |
| 4101 | .width = box->x2 - box->x1, |
| 4102 | .height = box->y2 - box->y1, |
| 4103 | }; |
| 4104 | |
| 4105 | pixman_region32_fini(®ion); |
| 4106 | |
| 4107 | return geometry; |
| 4108 | } |
| 4109 | |
Pekka Paalanen | c647ed7 | 2015-02-09 13:16:57 +0200 | [diff] [blame] | 4110 | /** Copy surface contents to system memory. |
| 4111 | * |
| 4112 | * \param surface The surface to copy from. |
| 4113 | * \param target Pointer to the target memory buffer. |
| 4114 | * \param size Size of the target buffer in bytes. |
| 4115 | * \param src_x X location on contents to copy from. |
| 4116 | * \param src_y Y location on contents to copy from. |
| 4117 | * \param width Width in pixels of the area to copy. |
| 4118 | * \param height Height in pixels of the area to copy. |
| 4119 | * \return 0 for success, -1 for failure. |
| 4120 | * |
| 4121 | * Surface contents are maintained by the renderer. They can be in a |
| 4122 | * reserved weston_buffer or as a copy, e.g. a GL texture, or something |
| 4123 | * else. |
| 4124 | * |
| 4125 | * Surface contents are copied into memory pointed to by target, |
| 4126 | * which has size bytes of space available. The target memory |
| 4127 | * may be larger than needed, but being smaller returns an error. |
| 4128 | * The extra bytes in target may or may not be written; their content is |
| 4129 | * unspecified. Size must be large enough to hold the image. |
| 4130 | * |
| 4131 | * The image in the target memory will be arranged in rows from |
| 4132 | * top to bottom, and pixels on a row from left to right. The pixel |
| 4133 | * format is PIXMAN_a8b8g8r8, 4 bytes per pixel, and stride is exactly |
| 4134 | * width * 4. |
| 4135 | * |
| 4136 | * Parameters src_x and src_y define the upper-left corner in buffer |
| 4137 | * coordinates (pixels) to copy from. Parameters width and height |
| 4138 | * define the size of the area to copy in pixels. |
| 4139 | * |
| 4140 | * The rectangle defined by src_x, src_y, width, height must fit in |
| 4141 | * the surface contents. Otherwise an error is returned. |
| 4142 | * |
Changwoo Cho | f97d250 | 2017-08-05 00:30:47 +0900 | [diff] [blame] | 4143 | * Use weston_surface_get_content_size to determine the content size; the |
Pekka Paalanen | c647ed7 | 2015-02-09 13:16:57 +0200 | [diff] [blame] | 4144 | * needed target buffer size and rectangle limits. |
| 4145 | * |
| 4146 | * CURRENT IMPLEMENTATION RESTRICTIONS: |
| 4147 | * - the machine must be little-endian due to Pixman formats. |
| 4148 | * |
| 4149 | * NOTE: Pixman formats are premultiplied. |
| 4150 | */ |
| 4151 | WL_EXPORT int |
| 4152 | weston_surface_copy_content(struct weston_surface *surface, |
| 4153 | void *target, size_t size, |
| 4154 | int src_x, int src_y, |
| 4155 | int width, int height) |
| 4156 | { |
| 4157 | struct weston_renderer *rer = surface->compositor->renderer; |
| 4158 | int cw, ch; |
| 4159 | const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */ |
| 4160 | |
| 4161 | if (!rer->surface_copy_content) |
| 4162 | return -1; |
| 4163 | |
| 4164 | weston_surface_get_content_size(surface, &cw, &ch); |
| 4165 | |
| 4166 | if (src_x < 0 || src_y < 0) |
| 4167 | return -1; |
| 4168 | |
| 4169 | if (width <= 0 || height <= 0) |
| 4170 | return -1; |
| 4171 | |
| 4172 | if (src_x + width > cw || src_y + height > ch) |
| 4173 | return -1; |
| 4174 | |
| 4175 | if (width * bytespp * height > size) |
| 4176 | return -1; |
| 4177 | |
| 4178 | return rer->surface_copy_content(surface, target, size, |
| 4179 | src_x, src_y, width, height); |
| 4180 | } |
| 4181 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4182 | static void |
| 4183 | subsurface_set_position(struct wl_client *client, |
| 4184 | struct wl_resource *resource, int32_t x, int32_t y) |
| 4185 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4186 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4187 | |
| 4188 | if (!sub) |
| 4189 | return; |
| 4190 | |
| 4191 | sub->position.x = x; |
| 4192 | sub->position.y = y; |
| 4193 | sub->position.set = 1; |
| 4194 | } |
| 4195 | |
| 4196 | static struct weston_subsurface * |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 4197 | subsurface_find_sibling(struct weston_subsurface *sub, |
| 4198 | struct weston_surface *surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4199 | { |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 4200 | struct weston_surface *parent = sub->parent; |
| 4201 | struct weston_subsurface *sibling; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4202 | |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 4203 | wl_list_for_each(sibling, &parent->subsurface_list, parent_link) { |
| 4204 | if (sibling->surface == surface && sibling != sub) |
| 4205 | return sibling; |
| 4206 | } |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4207 | |
| 4208 | return NULL; |
| 4209 | } |
| 4210 | |
| 4211 | static struct weston_subsurface * |
| 4212 | subsurface_sibling_check(struct weston_subsurface *sub, |
| 4213 | struct weston_surface *surface, |
| 4214 | const char *request) |
| 4215 | { |
| 4216 | struct weston_subsurface *sibling; |
| 4217 | |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 4218 | sibling = subsurface_find_sibling(sub, surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4219 | if (!sibling) { |
| 4220 | wl_resource_post_error(sub->resource, |
| 4221 | WL_SUBSURFACE_ERROR_BAD_SURFACE, |
| 4222 | "%s: wl_surface@%d is not a parent or sibling", |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4223 | request, wl_resource_get_id(surface->resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4224 | return NULL; |
| 4225 | } |
| 4226 | |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 4227 | assert(sibling->parent == sub->parent); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4228 | |
| 4229 | return sibling; |
| 4230 | } |
| 4231 | |
| 4232 | static void |
| 4233 | subsurface_place_above(struct wl_client *client, |
| 4234 | struct wl_resource *resource, |
| 4235 | struct wl_resource *sibling_resource) |
| 4236 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4237 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4238 | struct weston_surface *surface = |
| 4239 | wl_resource_get_user_data(sibling_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4240 | struct weston_subsurface *sibling; |
| 4241 | |
| 4242 | if (!sub) |
| 4243 | return; |
| 4244 | |
| 4245 | sibling = subsurface_sibling_check(sub, surface, "place_above"); |
| 4246 | if (!sibling) |
| 4247 | return; |
| 4248 | |
| 4249 | wl_list_remove(&sub->parent_link_pending); |
| 4250 | wl_list_insert(sibling->parent_link_pending.prev, |
| 4251 | &sub->parent_link_pending); |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 4252 | |
| 4253 | sub->reordered = true; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4254 | } |
| 4255 | |
| 4256 | static void |
| 4257 | subsurface_place_below(struct wl_client *client, |
| 4258 | struct wl_resource *resource, |
| 4259 | struct wl_resource *sibling_resource) |
| 4260 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4261 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4262 | struct weston_surface *surface = |
| 4263 | wl_resource_get_user_data(sibling_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4264 | struct weston_subsurface *sibling; |
| 4265 | |
| 4266 | if (!sub) |
| 4267 | return; |
| 4268 | |
| 4269 | sibling = subsurface_sibling_check(sub, surface, "place_below"); |
| 4270 | if (!sibling) |
| 4271 | return; |
| 4272 | |
| 4273 | wl_list_remove(&sub->parent_link_pending); |
| 4274 | wl_list_insert(&sibling->parent_link_pending, |
| 4275 | &sub->parent_link_pending); |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 4276 | |
| 4277 | sub->reordered = true; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4278 | } |
| 4279 | |
| 4280 | static void |
| 4281 | subsurface_set_sync(struct wl_client *client, struct wl_resource *resource) |
| 4282 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4283 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4284 | |
| 4285 | if (sub) |
| 4286 | sub->synchronized = 1; |
| 4287 | } |
| 4288 | |
| 4289 | static void |
| 4290 | subsurface_set_desync(struct wl_client *client, struct wl_resource *resource) |
| 4291 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4292 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4293 | |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 4294 | if (sub && sub->synchronized) { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4295 | sub->synchronized = 0; |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 4296 | |
| 4297 | /* If sub became effectively desynchronized, flush. */ |
| 4298 | if (!weston_subsurface_is_synchronized(sub)) |
| 4299 | weston_subsurface_synchronized_commit(sub); |
| 4300 | } |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4301 | } |
| 4302 | |
| 4303 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4304 | weston_subsurface_unlink_parent(struct weston_subsurface *sub) |
| 4305 | { |
| 4306 | wl_list_remove(&sub->parent_link); |
| 4307 | wl_list_remove(&sub->parent_link_pending); |
| 4308 | wl_list_remove(&sub->parent_destroy_listener.link); |
| 4309 | sub->parent = NULL; |
| 4310 | } |
| 4311 | |
| 4312 | static void |
| 4313 | weston_subsurface_destroy(struct weston_subsurface *sub); |
| 4314 | |
| 4315 | static void |
| 4316 | subsurface_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 4317 | { |
| 4318 | struct weston_subsurface *sub = |
| 4319 | container_of(listener, struct weston_subsurface, |
| 4320 | surface_destroy_listener); |
Pekka Paalanen | ca79076 | 2015-04-17 14:23:38 +0300 | [diff] [blame] | 4321 | assert(data == sub->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4322 | |
| 4323 | /* The protocol object (wl_resource) is left inert. */ |
| 4324 | if (sub->resource) |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4325 | wl_resource_set_user_data(sub->resource, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4326 | |
| 4327 | weston_subsurface_destroy(sub); |
| 4328 | } |
| 4329 | |
| 4330 | static void |
| 4331 | subsurface_handle_parent_destroy(struct wl_listener *listener, void *data) |
| 4332 | { |
| 4333 | struct weston_subsurface *sub = |
| 4334 | container_of(listener, struct weston_subsurface, |
| 4335 | parent_destroy_listener); |
Pekka Paalanen | ca79076 | 2015-04-17 14:23:38 +0300 | [diff] [blame] | 4336 | assert(data == sub->parent); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4337 | assert(sub->surface != sub->parent); |
| 4338 | |
| 4339 | if (weston_surface_is_mapped(sub->surface)) |
| 4340 | weston_surface_unmap(sub->surface); |
| 4341 | |
| 4342 | weston_subsurface_unlink_parent(sub); |
| 4343 | } |
| 4344 | |
| 4345 | static void |
| 4346 | subsurface_resource_destroy(struct wl_resource *resource) |
| 4347 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4348 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4349 | |
| 4350 | if (sub) |
| 4351 | weston_subsurface_destroy(sub); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4352 | } |
| 4353 | |
| 4354 | static void |
| 4355 | subsurface_destroy(struct wl_client *client, struct wl_resource *resource) |
| 4356 | { |
| 4357 | wl_resource_destroy(resource); |
| 4358 | } |
| 4359 | |
| 4360 | static void |
| 4361 | weston_subsurface_link_parent(struct weston_subsurface *sub, |
| 4362 | struct weston_surface *parent) |
| 4363 | { |
| 4364 | sub->parent = parent; |
| 4365 | sub->parent_destroy_listener.notify = subsurface_handle_parent_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4366 | wl_signal_add(&parent->destroy_signal, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4367 | &sub->parent_destroy_listener); |
| 4368 | |
| 4369 | wl_list_insert(&parent->subsurface_list, &sub->parent_link); |
| 4370 | wl_list_insert(&parent->subsurface_list_pending, |
| 4371 | &sub->parent_link_pending); |
| 4372 | } |
| 4373 | |
| 4374 | static void |
| 4375 | weston_subsurface_link_surface(struct weston_subsurface *sub, |
| 4376 | struct weston_surface *surface) |
| 4377 | { |
| 4378 | sub->surface = surface; |
| 4379 | sub->surface_destroy_listener.notify = |
| 4380 | subsurface_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4381 | wl_signal_add(&surface->destroy_signal, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4382 | &sub->surface_destroy_listener); |
| 4383 | } |
| 4384 | |
| 4385 | static void |
| 4386 | weston_subsurface_destroy(struct weston_subsurface *sub) |
| 4387 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4388 | struct weston_view *view, *next; |
| 4389 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4390 | assert(sub->surface); |
| 4391 | |
| 4392 | if (sub->resource) { |
| 4393 | assert(weston_surface_to_subsurface(sub->surface) == sub); |
| 4394 | assert(sub->parent_destroy_listener.notify == |
| 4395 | subsurface_handle_parent_destroy); |
| 4396 | |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 4397 | wl_list_for_each_safe(view, next, &sub->surface->views, surface_link) { |
| 4398 | weston_view_unmap(view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4399 | weston_view_destroy(view); |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 4400 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4401 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4402 | if (sub->parent) |
| 4403 | weston_subsurface_unlink_parent(sub); |
| 4404 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 4405 | weston_surface_state_fini(&sub->cached); |
| 4406 | weston_buffer_reference(&sub->cached_buffer_ref, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4407 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 4408 | sub->surface->committed = NULL; |
| 4409 | sub->surface->committed_private = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4410 | weston_surface_set_label_func(sub->surface, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4411 | } else { |
| 4412 | /* the dummy weston_subsurface for the parent itself */ |
| 4413 | assert(sub->parent_destroy_listener.notify == NULL); |
| 4414 | wl_list_remove(&sub->parent_link); |
| 4415 | wl_list_remove(&sub->parent_link_pending); |
| 4416 | } |
| 4417 | |
| 4418 | wl_list_remove(&sub->surface_destroy_listener.link); |
| 4419 | free(sub); |
| 4420 | } |
| 4421 | |
| 4422 | static const struct wl_subsurface_interface subsurface_implementation = { |
| 4423 | subsurface_destroy, |
| 4424 | subsurface_set_position, |
| 4425 | subsurface_place_above, |
| 4426 | subsurface_place_below, |
| 4427 | subsurface_set_sync, |
| 4428 | subsurface_set_desync |
| 4429 | }; |
| 4430 | |
| 4431 | static struct weston_subsurface * |
| 4432 | weston_subsurface_create(uint32_t id, struct weston_surface *surface, |
| 4433 | struct weston_surface *parent) |
| 4434 | { |
| 4435 | struct weston_subsurface *sub; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4436 | struct wl_client *client = wl_resource_get_client(surface->resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4437 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 4438 | sub = zalloc(sizeof *sub); |
| 4439 | if (sub == NULL) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4440 | return NULL; |
| 4441 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4442 | wl_list_init(&sub->unused_views); |
| 4443 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4444 | sub->resource = |
| 4445 | wl_resource_create(client, &wl_subsurface_interface, 1, id); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4446 | if (!sub->resource) { |
| 4447 | free(sub); |
| 4448 | return NULL; |
| 4449 | } |
| 4450 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4451 | wl_resource_set_implementation(sub->resource, |
| 4452 | &subsurface_implementation, |
| 4453 | sub, subsurface_resource_destroy); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4454 | weston_subsurface_link_surface(sub, surface); |
| 4455 | weston_subsurface_link_parent(sub, parent); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 4456 | weston_surface_state_init(&sub->cached); |
| 4457 | sub->cached_buffer_ref.buffer = NULL; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4458 | sub->synchronized = 1; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4459 | |
| 4460 | return sub; |
| 4461 | } |
| 4462 | |
| 4463 | /* Create a dummy subsurface for having the parent itself in its |
| 4464 | * sub-surface lists. Makes stacking order manipulation easy. |
| 4465 | */ |
| 4466 | static struct weston_subsurface * |
| 4467 | weston_subsurface_create_for_parent(struct weston_surface *parent) |
| 4468 | { |
| 4469 | struct weston_subsurface *sub; |
| 4470 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 4471 | sub = zalloc(sizeof *sub); |
| 4472 | if (sub == NULL) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4473 | return NULL; |
| 4474 | |
| 4475 | weston_subsurface_link_surface(sub, parent); |
| 4476 | sub->parent = parent; |
| 4477 | wl_list_insert(&parent->subsurface_list, &sub->parent_link); |
| 4478 | wl_list_insert(&parent->subsurface_list_pending, |
| 4479 | &sub->parent_link_pending); |
| 4480 | |
| 4481 | return sub; |
| 4482 | } |
| 4483 | |
| 4484 | static void |
| 4485 | subcompositor_get_subsurface(struct wl_client *client, |
| 4486 | struct wl_resource *resource, |
| 4487 | uint32_t id, |
| 4488 | struct wl_resource *surface_resource, |
| 4489 | struct wl_resource *parent_resource) |
| 4490 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4491 | struct weston_surface *surface = |
| 4492 | wl_resource_get_user_data(surface_resource); |
| 4493 | struct weston_surface *parent = |
| 4494 | wl_resource_get_user_data(parent_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4495 | struct weston_subsurface *sub; |
| 4496 | static const char where[] = "get_subsurface: wl_subsurface@"; |
| 4497 | |
| 4498 | if (surface == parent) { |
| 4499 | wl_resource_post_error(resource, |
| 4500 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 4501 | "%s%d: wl_surface@%d cannot be its own parent", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4502 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4503 | return; |
| 4504 | } |
| 4505 | |
| 4506 | if (weston_surface_to_subsurface(surface)) { |
| 4507 | wl_resource_post_error(resource, |
| 4508 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 4509 | "%s%d: wl_surface@%d is already a sub-surface", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4510 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4511 | return; |
| 4512 | } |
| 4513 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4514 | if (weston_surface_set_role(surface, "wl_subsurface", resource, |
| 4515 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE) < 0) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4516 | return; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4517 | |
Pekka Paalanen | 86c8ca0 | 2013-05-17 16:46:07 +0300 | [diff] [blame] | 4518 | if (weston_surface_get_main_surface(parent) == surface) { |
| 4519 | wl_resource_post_error(resource, |
| 4520 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 4521 | "%s%d: wl_surface@%d is an ancestor of parent", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4522 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | 86c8ca0 | 2013-05-17 16:46:07 +0300 | [diff] [blame] | 4523 | return; |
| 4524 | } |
| 4525 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4526 | /* make sure the parent is in its own list */ |
| 4527 | if (wl_list_empty(&parent->subsurface_list)) { |
| 4528 | if (!weston_subsurface_create_for_parent(parent)) { |
| 4529 | wl_resource_post_no_memory(resource); |
| 4530 | return; |
| 4531 | } |
| 4532 | } |
| 4533 | |
| 4534 | sub = weston_subsurface_create(id, surface, parent); |
| 4535 | if (!sub) { |
| 4536 | wl_resource_post_no_memory(resource); |
| 4537 | return; |
| 4538 | } |
| 4539 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 4540 | surface->committed = subsurface_committed; |
| 4541 | surface->committed_private = sub; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4542 | weston_surface_set_label_func(surface, subsurface_get_label); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4543 | } |
| 4544 | |
| 4545 | static void |
| 4546 | subcompositor_destroy(struct wl_client *client, struct wl_resource *resource) |
| 4547 | { |
| 4548 | wl_resource_destroy(resource); |
| 4549 | } |
| 4550 | |
| 4551 | static const struct wl_subcompositor_interface subcompositor_interface = { |
| 4552 | subcompositor_destroy, |
| 4553 | subcompositor_get_subsurface |
| 4554 | }; |
| 4555 | |
| 4556 | static void |
| 4557 | bind_subcompositor(struct wl_client *client, |
| 4558 | void *data, uint32_t version, uint32_t id) |
| 4559 | { |
| 4560 | struct weston_compositor *compositor = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4561 | struct wl_resource *resource; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4562 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4563 | resource = |
| 4564 | wl_resource_create(client, &wl_subcompositor_interface, 1, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 4565 | if (resource == NULL) { |
| 4566 | wl_client_post_no_memory(client); |
| 4567 | return; |
| 4568 | } |
| 4569 | wl_resource_set_implementation(resource, &subcompositor_interface, |
| 4570 | compositor, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4571 | } |
| 4572 | |
Bryce Harrington | 0795ece | 2016-08-30 12:04:26 -0700 | [diff] [blame] | 4573 | /** Set a DPMS mode on all of the compositor's outputs |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4574 | * |
| 4575 | * \param compositor The compositor instance |
| 4576 | * \param state The DPMS state the outputs will be set to |
| 4577 | */ |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4578 | static void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4579 | weston_compositor_dpms(struct weston_compositor *compositor, |
| 4580 | enum dpms_enum state) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4581 | { |
| 4582 | struct weston_output *output; |
| 4583 | |
Bryce Harrington | 08976ac | 2016-08-30 12:05:16 -0700 | [diff] [blame] | 4584 | wl_list_for_each(output, &compositor->output_list, link) |
| 4585 | if (output->set_dpms) |
| 4586 | output->set_dpms(output, state); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4587 | } |
| 4588 | |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4589 | /** Restores the compositor to active status |
| 4590 | * |
| 4591 | * \param compositor The compositor instance |
| 4592 | * |
| 4593 | * If the compositor was in a sleeping mode, all outputs are powered |
| 4594 | * back on via DPMS. Otherwise if the compositor was inactive |
| 4595 | * (idle/locked, offscreen, or sleeping) then the compositor's wake |
| 4596 | * signal will fire. |
| 4597 | * |
| 4598 | * Restarts the idle timer. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 4599 | * \ingroup compositor |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4600 | */ |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4601 | WL_EXPORT void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4602 | weston_compositor_wake(struct weston_compositor *compositor) |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4603 | { |
Neil Roberts | 8b62e20 | 2013-09-30 13:14:47 +0100 | [diff] [blame] | 4604 | uint32_t old_state = compositor->state; |
| 4605 | |
| 4606 | /* The state needs to be changed before emitting the wake |
| 4607 | * signal because that may try to schedule a repaint which |
| 4608 | * will not work if the compositor is still sleeping */ |
| 4609 | compositor->state = WESTON_COMPOSITOR_ACTIVE; |
| 4610 | |
| 4611 | switch (old_state) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4612 | case WESTON_COMPOSITOR_SLEEPING: |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4613 | case WESTON_COMPOSITOR_IDLE: |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4614 | case WESTON_COMPOSITOR_OFFSCREEN: |
Daniel Stone | 893b936 | 2016-11-08 15:47:09 +0000 | [diff] [blame] | 4615 | weston_compositor_dpms(compositor, WESTON_DPMS_ON); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4616 | wl_signal_emit(&compositor->wake_signal, compositor); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4617 | /* fall through */ |
| 4618 | default: |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4619 | wl_event_source_timer_update(compositor->idle_source, |
| 4620 | compositor->idle_time * 1000); |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4621 | } |
| 4622 | } |
| 4623 | |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4624 | /** Turns off rendering and frame events for the compositor. |
| 4625 | * |
| 4626 | * \param compositor The compositor instance |
| 4627 | * |
| 4628 | * This is used for example to prevent further rendering while the |
| 4629 | * compositor is shutting down. |
| 4630 | * |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4631 | * Stops the idle timer. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 4632 | * |
| 4633 | * \ingroup compositor |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4634 | */ |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4635 | WL_EXPORT void |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4636 | weston_compositor_offscreen(struct weston_compositor *compositor) |
| 4637 | { |
| 4638 | switch (compositor->state) { |
| 4639 | case WESTON_COMPOSITOR_OFFSCREEN: |
| 4640 | return; |
| 4641 | case WESTON_COMPOSITOR_SLEEPING: |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4642 | default: |
| 4643 | compositor->state = WESTON_COMPOSITOR_OFFSCREEN; |
| 4644 | wl_event_source_timer_update(compositor->idle_source, 0); |
| 4645 | } |
| 4646 | } |
| 4647 | |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4648 | /** Powers down all attached output devices |
| 4649 | * |
| 4650 | * \param compositor The compositor instance |
| 4651 | * |
| 4652 | * Causes rendering to the outputs to cease, and no frame events to be |
| 4653 | * sent. Only powers down the outputs if the compositor is not already |
| 4654 | * in sleep mode. |
| 4655 | * |
| 4656 | * Stops the idle timer. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 4657 | * |
| 4658 | * \ingroup compositor |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4659 | */ |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4660 | WL_EXPORT void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4661 | weston_compositor_sleep(struct weston_compositor *compositor) |
| 4662 | { |
| 4663 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING) |
| 4664 | return; |
| 4665 | |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4666 | wl_event_source_timer_update(compositor->idle_source, 0); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4667 | compositor->state = WESTON_COMPOSITOR_SLEEPING; |
| 4668 | weston_compositor_dpms(compositor, WESTON_DPMS_OFF); |
| 4669 | } |
| 4670 | |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4671 | /** Sets compositor to idle mode |
| 4672 | * |
| 4673 | * \param data The compositor instance |
| 4674 | * |
| 4675 | * This is called when the idle timer fires. Once the compositor is in |
| 4676 | * idle mode it requires a wake action (e.g. via |
| 4677 | * weston_compositor_wake()) to restore it. The compositor's |
| 4678 | * idle_signal will be triggered when the idle event occurs. |
| 4679 | * |
| 4680 | * Idleness can be inhibited by setting the compositor's idle_inhibit |
| 4681 | * property. |
| 4682 | */ |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 4683 | static int |
| 4684 | idle_handler(void *data) |
| 4685 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4686 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 4687 | |
| 4688 | if (compositor->idle_inhibit) |
| 4689 | return 1; |
| 4690 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4691 | compositor->state = WESTON_COMPOSITOR_IDLE; |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4692 | wl_signal_emit(&compositor->idle_signal, compositor); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 4693 | |
| 4694 | return 1; |
| 4695 | } |
| 4696 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4697 | WL_EXPORT void |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 4698 | weston_plane_init(struct weston_plane *plane, |
| 4699 | struct weston_compositor *ec, |
| 4700 | int32_t x, int32_t y) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4701 | { |
| 4702 | pixman_region32_init(&plane->damage); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 4703 | pixman_region32_init(&plane->clip); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4704 | plane->x = x; |
| 4705 | plane->y = y; |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 4706 | plane->compositor = ec; |
Ander Conselvan de Oliveira | 3c36bf3 | 2013-07-05 16:05:26 +0300 | [diff] [blame] | 4707 | |
| 4708 | /* Init the link so that the call to wl_list_remove() when releasing |
| 4709 | * the plane without ever stacking doesn't lead to a crash */ |
| 4710 | wl_list_init(&plane->link); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4711 | } |
| 4712 | |
| 4713 | WL_EXPORT void |
| 4714 | weston_plane_release(struct weston_plane *plane) |
| 4715 | { |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 4716 | struct weston_view *view; |
| 4717 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4718 | pixman_region32_fini(&plane->damage); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 4719 | pixman_region32_fini(&plane->clip); |
Ander Conselvan de Oliveira | 3c36bf3 | 2013-07-05 16:05:26 +0300 | [diff] [blame] | 4720 | |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 4721 | wl_list_for_each(view, &plane->compositor->view_list, link) { |
| 4722 | if (view->plane == plane) |
| 4723 | view->plane = NULL; |
| 4724 | } |
| 4725 | |
Ander Conselvan de Oliveira | 3c36bf3 | 2013-07-05 16:05:26 +0300 | [diff] [blame] | 4726 | wl_list_remove(&plane->link); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4727 | } |
| 4728 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 4729 | /** weston_compositor_stack_plane |
| 4730 | * \ingroup compositor |
| 4731 | */ |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 4732 | WL_EXPORT void |
| 4733 | weston_compositor_stack_plane(struct weston_compositor *ec, |
| 4734 | struct weston_plane *plane, |
| 4735 | struct weston_plane *above) |
| 4736 | { |
| 4737 | if (above) |
| 4738 | wl_list_insert(above->link.prev, &plane->link); |
| 4739 | else |
| 4740 | wl_list_insert(&ec->plane_list, &plane->link); |
| 4741 | } |
| 4742 | |
Quentin Glidic | 4ef719c | 2016-07-05 20:44:33 +0200 | [diff] [blame] | 4743 | static void |
| 4744 | output_release(struct wl_client *client, struct wl_resource *resource) |
| 4745 | { |
| 4746 | wl_resource_destroy(resource); |
| 4747 | } |
| 4748 | |
| 4749 | static const struct wl_output_interface output_interface = { |
| 4750 | output_release, |
| 4751 | }; |
| 4752 | |
| 4753 | |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 4754 | static void unbind_resource(struct wl_resource *resource) |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 4755 | { |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4756 | wl_list_remove(wl_resource_get_link(resource)); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 4757 | } |
| 4758 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4759 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4760 | bind_output(struct wl_client *client, |
| 4761 | void *data, uint32_t version, uint32_t id) |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 4762 | { |
Pekka Paalanen | 0534762 | 2017-03-27 12:24:34 +0300 | [diff] [blame] | 4763 | struct weston_head *head = data; |
| 4764 | struct weston_output *output = head->output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4765 | struct weston_mode *mode; |
Kristian Høgsberg | fd07fb7 | 2011-08-29 15:03:09 -0400 | [diff] [blame] | 4766 | struct wl_resource *resource; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 4767 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4768 | resource = wl_resource_create(client, &wl_output_interface, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 4769 | version, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 4770 | if (resource == NULL) { |
| 4771 | wl_client_post_no_memory(client); |
| 4772 | return; |
| 4773 | } |
Kristian Høgsberg | fd07fb7 | 2011-08-29 15:03:09 -0400 | [diff] [blame] | 4774 | |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 4775 | wl_list_insert(&head->resource_list, wl_resource_get_link(resource)); |
Pekka Paalanen | 055c113 | 2017-03-27 16:31:25 +0300 | [diff] [blame] | 4776 | wl_resource_set_implementation(resource, &output_interface, head, |
Pekka Paalanen | 0534762 | 2017-03-27 12:24:34 +0300 | [diff] [blame] | 4777 | unbind_resource); |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 4778 | |
Pekka Paalanen | 0534762 | 2017-03-27 12:24:34 +0300 | [diff] [blame] | 4779 | assert(output); |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4780 | wl_output_send_geometry(resource, |
| 4781 | output->x, |
| 4782 | output->y, |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 4783 | head->mm_width, |
| 4784 | head->mm_height, |
| 4785 | head->subpixel, |
| 4786 | head->make, head->model, |
Kristian Høgsberg | 05890dc | 2012-08-10 10:09:20 -0400 | [diff] [blame] | 4787 | output->transform); |
Jasper St. Pierre | 0013a29 | 2014-08-07 16:43:11 -0400 | [diff] [blame] | 4788 | if (version >= WL_OUTPUT_SCALE_SINCE_VERSION) |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 4789 | wl_output_send_scale(resource, |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 4790 | output->current_scale); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 4791 | |
| 4792 | wl_list_for_each (mode, &output->mode_list, link) { |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4793 | wl_output_send_mode(resource, |
| 4794 | mode->flags, |
| 4795 | mode->width, |
| 4796 | mode->height, |
| 4797 | mode->refresh); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 4798 | } |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 4799 | |
Jasper St. Pierre | 0013a29 | 2014-08-07 16:43:11 -0400 | [diff] [blame] | 4800 | if (version >= WL_OUTPUT_DONE_SINCE_VERSION) |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 4801 | wl_output_send_done(resource); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 4802 | } |
| 4803 | |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 4804 | static void |
| 4805 | weston_head_add_global(struct weston_head *head) |
| 4806 | { |
| 4807 | head->global = wl_global_create(head->compositor->wl_display, |
| 4808 | &wl_output_interface, 3, |
| 4809 | head, bind_output); |
| 4810 | } |
| 4811 | |
Pekka Paalanen | d9dcc6d | 2017-12-04 15:28:13 +0200 | [diff] [blame] | 4812 | /** Remove the global wl_output protocol object |
| 4813 | * |
| 4814 | * \param head The head whose global to remove. |
| 4815 | * |
| 4816 | * Also orphans the wl_resources for this head (wl_output). |
| 4817 | */ |
| 4818 | static void |
| 4819 | weston_head_remove_global(struct weston_head *head) |
| 4820 | { |
| 4821 | struct wl_resource *resource, *tmp; |
| 4822 | |
| 4823 | if (head->global) |
| 4824 | wl_global_destroy(head->global); |
| 4825 | head->global = NULL; |
| 4826 | |
| 4827 | wl_resource_for_each_safe(resource, tmp, &head->resource_list) { |
| 4828 | unbind_resource(resource); |
| 4829 | wl_resource_set_destructor(resource, NULL); |
| 4830 | wl_resource_set_user_data(resource, NULL); |
| 4831 | } |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 4832 | |
| 4833 | wl_resource_for_each(resource, &head->xdg_output_resource_list) { |
| 4834 | /* It's sufficient to unset the destructor, then the list elements |
| 4835 | * won't be accessed. |
| 4836 | */ |
| 4837 | wl_resource_set_destructor(resource, NULL); |
| 4838 | } |
| 4839 | wl_list_init(&head->xdg_output_resource_list); |
Pekka Paalanen | d9dcc6d | 2017-12-04 15:28:13 +0200 | [diff] [blame] | 4840 | } |
| 4841 | |
Pekka Paalanen | 9ffb250 | 2017-03-27 15:14:32 +0300 | [diff] [blame] | 4842 | /** Get the backing object of wl_output |
| 4843 | * |
| 4844 | * \param resource A wl_output protocol object. |
| 4845 | * \return The backing object (user data) of a wl_resource representing a |
| 4846 | * wl_output protocol object. |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 4847 | * |
| 4848 | * \ingroup head |
Pekka Paalanen | 9ffb250 | 2017-03-27 15:14:32 +0300 | [diff] [blame] | 4849 | */ |
Pekka Paalanen | 055c113 | 2017-03-27 16:31:25 +0300 | [diff] [blame] | 4850 | WL_EXPORT struct weston_head * |
| 4851 | weston_head_from_resource(struct wl_resource *resource) |
Pekka Paalanen | 9ffb250 | 2017-03-27 15:14:32 +0300 | [diff] [blame] | 4852 | { |
| 4853 | assert(wl_resource_instance_of(resource, &wl_output_interface, |
| 4854 | &output_interface)); |
| 4855 | |
| 4856 | return wl_resource_get_user_data(resource); |
| 4857 | } |
| 4858 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4859 | /** Initialize a pre-allocated weston_head |
| 4860 | * |
| 4861 | * \param head The head to initialize. |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 4862 | * \param name The head name, e.g. the connector name or equivalent. |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4863 | * |
| 4864 | * The head will be safe to attach, detach and release. |
| 4865 | * |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 4866 | * The name is used in logs, and can be used by compositors as a configuration |
| 4867 | * identifier. |
| 4868 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 4869 | * \ingroup head |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4870 | * \internal |
| 4871 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 4872 | WL_EXPORT void |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 4873 | weston_head_init(struct weston_head *head, const char *name) |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4874 | { |
| 4875 | /* Add some (in)sane defaults which can be used |
| 4876 | * for checking if an output was properly configured |
| 4877 | */ |
| 4878 | memset(head, 0, sizeof *head); |
| 4879 | |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 4880 | wl_list_init(&head->compositor_link); |
Pekka Paalanen | 2e1bedb | 2017-10-10 11:21:58 +0300 | [diff] [blame] | 4881 | wl_signal_init(&head->destroy_signal); |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4882 | wl_list_init(&head->output_link); |
| 4883 | wl_list_init(&head->resource_list); |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 4884 | wl_list_init(&head->xdg_output_resource_list); |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 4885 | head->name = strdup(name); |
Ankit Nautiyal | 4f64ff8 | 2019-04-03 18:44:35 +0530 | [diff] [blame] | 4886 | head->current_protection = WESTON_HDCP_DISABLE; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4887 | } |
| 4888 | |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 4889 | /** Send output heads changed signal |
| 4890 | * |
| 4891 | * \param output The output that changed. |
| 4892 | * |
| 4893 | * Notify that the enabled output gained and/or lost heads, or that the |
| 4894 | * associated heads may have changed their connection status. This does not |
| 4895 | * include cases where the output becomes enabled or disabled. The registered |
| 4896 | * callbacks are called after the change has successfully happened. |
| 4897 | * |
| 4898 | * If connection status change causes the compositor to attach or detach a head |
| 4899 | * to an enabled output, the registered callbacks may be called multiple times. |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 4900 | * |
| 4901 | * \ingroup output |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 4902 | */ |
| 4903 | static void |
| 4904 | weston_output_emit_heads_changed(struct weston_output *output) |
| 4905 | { |
| 4906 | wl_signal_emit(&output->compositor->output_heads_changed_signal, |
| 4907 | output); |
| 4908 | } |
| 4909 | |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4910 | /** Idle task for emitting heads_changed_signal */ |
| 4911 | static void |
| 4912 | weston_compositor_call_heads_changed(void *data) |
| 4913 | { |
| 4914 | struct weston_compositor *compositor = data; |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 4915 | struct weston_head *head; |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4916 | |
| 4917 | compositor->heads_changed_source = NULL; |
| 4918 | |
| 4919 | wl_signal_emit(&compositor->heads_changed_signal, compositor); |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 4920 | |
| 4921 | wl_list_for_each(head, &compositor->head_list, compositor_link) { |
| 4922 | if (head->output && head->output->enabled) |
| 4923 | weston_output_emit_heads_changed(head->output); |
| 4924 | } |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4925 | } |
| 4926 | |
| 4927 | /** Schedule a call on idle to heads_changed callback |
| 4928 | * |
| 4929 | * \param compositor The Compositor. |
| 4930 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 4931 | * \ingroup compositor |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4932 | * \internal |
| 4933 | */ |
| 4934 | static void |
| 4935 | weston_compositor_schedule_heads_changed(struct weston_compositor *compositor) |
| 4936 | { |
| 4937 | struct wl_event_loop *loop; |
| 4938 | |
| 4939 | if (compositor->heads_changed_source) |
| 4940 | return; |
| 4941 | |
| 4942 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 4943 | compositor->heads_changed_source = wl_event_loop_add_idle(loop, |
| 4944 | weston_compositor_call_heads_changed, compositor); |
| 4945 | } |
| 4946 | |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 4947 | /** Register a new head |
| 4948 | * |
| 4949 | * \param compositor The compositor. |
| 4950 | * \param head The head to register, must not be already registered. |
| 4951 | * |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4952 | * This signals the core that a new head has become available, leading to |
| 4953 | * heads_changed hook being called later. |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 4954 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 4955 | * \ingroup compositor |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 4956 | * \internal |
| 4957 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 4958 | WL_EXPORT void |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 4959 | weston_compositor_add_head(struct weston_compositor *compositor, |
| 4960 | struct weston_head *head) |
| 4961 | { |
| 4962 | assert(wl_list_empty(&head->compositor_link)); |
| 4963 | assert(head->name); |
| 4964 | |
| 4965 | wl_list_insert(compositor->head_list.prev, &head->compositor_link); |
| 4966 | head->compositor = compositor; |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4967 | weston_compositor_schedule_heads_changed(compositor); |
| 4968 | } |
| 4969 | |
| 4970 | /** Adds a listener to be called when heads change |
| 4971 | * |
| 4972 | * \param compositor The compositor. |
| 4973 | * \param listener The listener to add. |
| 4974 | * |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 4975 | * The listener notify function argument is weston_compositor. |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4976 | * |
| 4977 | * The listener function will be called after heads are added or their |
| 4978 | * connection status has changed. Several changes may be accumulated into a |
| 4979 | * single call. The user is expected to iterate over the existing heads and |
| 4980 | * check their statuses to find out what changed. |
| 4981 | * |
| 4982 | * \sa weston_compositor_iterate_heads, weston_head_is_connected, |
| 4983 | * weston_head_is_enabled |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 4984 | * \ingroup compositor |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4985 | */ |
| 4986 | WL_EXPORT void |
| 4987 | weston_compositor_add_heads_changed_listener(struct weston_compositor *compositor, |
| 4988 | struct wl_listener *listener) |
| 4989 | { |
| 4990 | wl_signal_add(&compositor->heads_changed_signal, listener); |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 4991 | } |
| 4992 | |
| 4993 | /** Iterate over available heads |
| 4994 | * |
| 4995 | * \param compositor The compositor. |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 4996 | * \param iter The iterator, or NULL for start. |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 4997 | * \return The next available head in the list. |
| 4998 | * |
| 4999 | * Returns all available heads, regardless of being connected or enabled. |
| 5000 | * |
| 5001 | * You can iterate over all heads as follows: |
| 5002 | * \code |
| 5003 | * struct weston_head *head = NULL; |
| 5004 | * |
| 5005 | * while ((head = weston_compositor_iterate_heads(compositor, head))) { |
| 5006 | * ... |
| 5007 | * } |
| 5008 | * \endcode |
| 5009 | * |
| 5010 | * If you cause \c iter to be removed from the list, you cannot use it to |
| 5011 | * continue iterating. Removing any other item is safe. |
| 5012 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 5013 | * \ingroup compositor |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 5014 | */ |
| 5015 | WL_EXPORT struct weston_head * |
| 5016 | weston_compositor_iterate_heads(struct weston_compositor *compositor, |
| 5017 | struct weston_head *iter) |
| 5018 | { |
| 5019 | struct wl_list *list = &compositor->head_list; |
| 5020 | struct wl_list *node; |
| 5021 | |
| 5022 | assert(compositor); |
| 5023 | assert(!iter || iter->compositor == compositor); |
| 5024 | |
| 5025 | if (iter) |
| 5026 | node = iter->compositor_link.next; |
| 5027 | else |
| 5028 | node = list->next; |
| 5029 | |
| 5030 | assert(node); |
| 5031 | assert(!iter || node != &iter->compositor_link); |
| 5032 | |
| 5033 | if (node == list) |
| 5034 | return NULL; |
| 5035 | |
| 5036 | return container_of(node, struct weston_head, compositor_link); |
| 5037 | } |
| 5038 | |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5039 | /** Iterate over attached heads |
| 5040 | * |
| 5041 | * \param output The output whose heads to iterate. |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 5042 | * \param iter The iterator, or NULL for start. |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5043 | * \return The next attached head in the list. |
| 5044 | * |
| 5045 | * Returns all heads currently attached to the output. |
| 5046 | * |
| 5047 | * You can iterate over all heads as follows: |
| 5048 | * \code |
| 5049 | * struct weston_head *head = NULL; |
| 5050 | * |
| 5051 | * while ((head = weston_output_iterate_heads(output, head))) { |
| 5052 | * ... |
| 5053 | * } |
| 5054 | * \endcode |
| 5055 | * |
| 5056 | * If you cause \c iter to be removed from the list, you cannot use it to |
| 5057 | * continue iterating. Removing any other item is safe. |
| 5058 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 5059 | * \ingroup ouput |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5060 | */ |
| 5061 | WL_EXPORT struct weston_head * |
| 5062 | weston_output_iterate_heads(struct weston_output *output, |
| 5063 | struct weston_head *iter) |
| 5064 | { |
| 5065 | struct wl_list *list = &output->head_list; |
| 5066 | struct wl_list *node; |
| 5067 | |
| 5068 | assert(output); |
| 5069 | assert(!iter || iter->output == output); |
| 5070 | |
| 5071 | if (iter) |
| 5072 | node = iter->output_link.next; |
| 5073 | else |
| 5074 | node = list->next; |
| 5075 | |
| 5076 | assert(node); |
| 5077 | assert(!iter || node != &iter->output_link); |
| 5078 | |
| 5079 | if (node == list) |
| 5080 | return NULL; |
| 5081 | |
| 5082 | return container_of(node, struct weston_head, output_link); |
| 5083 | } |
| 5084 | |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 5085 | /** Attach a head to an output |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5086 | * |
| 5087 | * \param output The output to attach to. |
| 5088 | * \param head The head that is not yet attached. |
| 5089 | * \return 0 on success, -1 on failure. |
| 5090 | * |
| 5091 | * Attaches the given head to the output. All heads of an output are clones |
| 5092 | * and share the resolution and timings. |
| 5093 | * |
| 5094 | * Cloning heads this way uses less resources than creating an output for |
| 5095 | * each head, but is not always possible due to environment, driver and hardware |
| 5096 | * limitations. |
| 5097 | * |
| 5098 | * On failure, the head remains unattached. Success of this function does not |
| 5099 | * guarantee the output configuration is actually valid. The final checks are |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 5100 | * made on weston_output_enable() unless the output was already enabled. |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5101 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 5102 | * \ingroup output |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5103 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5104 | WL_EXPORT int |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5105 | weston_output_attach_head(struct weston_output *output, |
| 5106 | struct weston_head *head) |
| 5107 | { |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 5108 | char *head_names; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5109 | |
| 5110 | if (!wl_list_empty(&head->output_link)) |
| 5111 | return -1; |
| 5112 | |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5113 | if (output->attach_head) { |
| 5114 | if (output->attach_head(output, head) < 0) |
| 5115 | return -1; |
| 5116 | } else if (!wl_list_empty(&output->head_list)) { |
| 5117 | /* No support for clones in the legacy path. */ |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5118 | return -1; |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5119 | } |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5120 | |
| 5121 | head->output = output; |
| 5122 | wl_list_insert(output->head_list.prev, &head->output_link); |
| 5123 | |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 5124 | if (output->enabled) { |
| 5125 | weston_head_add_global(head); |
| 5126 | |
| 5127 | head_names = weston_output_create_heads_string(output); |
| 5128 | weston_log("Output '%s' updated to have head(s) %s\n", |
| 5129 | output->name, head_names); |
| 5130 | free(head_names); |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 5131 | |
| 5132 | weston_output_emit_heads_changed(output); |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 5133 | } |
| 5134 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5135 | return 0; |
| 5136 | } |
| 5137 | |
| 5138 | /** Detach a head from its output |
| 5139 | * |
| 5140 | * \param head The head to detach. |
| 5141 | * |
| 5142 | * It is safe to detach a non-attached head. |
| 5143 | * |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5144 | * If the head is attached to an enabled output and the output will be left |
| 5145 | * with no heads, the output will be disabled. |
| 5146 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5147 | * \ingroup head |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5148 | * \sa weston_output_disable |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5149 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5150 | WL_EXPORT void |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5151 | weston_head_detach(struct weston_head *head) |
| 5152 | { |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5153 | struct weston_output *output = head->output; |
Pekka Paalanen | a010699 | 2017-12-08 16:11:17 +0200 | [diff] [blame] | 5154 | char *head_names; |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5155 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5156 | wl_list_remove(&head->output_link); |
| 5157 | wl_list_init(&head->output_link); |
| 5158 | head->output = NULL; |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5159 | |
| 5160 | if (!output) |
| 5161 | return; |
| 5162 | |
| 5163 | if (output->detach_head) |
| 5164 | output->detach_head(output, head); |
| 5165 | |
| 5166 | if (output->enabled) { |
| 5167 | weston_head_remove_global(head); |
| 5168 | |
Pekka Paalanen | a010699 | 2017-12-08 16:11:17 +0200 | [diff] [blame] | 5169 | if (wl_list_empty(&output->head_list)) { |
| 5170 | weston_log("Output '%s' no heads left, disabling.\n", |
| 5171 | output->name); |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5172 | weston_output_disable(output); |
Pekka Paalanen | a010699 | 2017-12-08 16:11:17 +0200 | [diff] [blame] | 5173 | } else { |
| 5174 | head_names = weston_output_create_heads_string(output); |
| 5175 | weston_log("Output '%s' updated to have head(s) %s\n", |
| 5176 | output->name, head_names); |
| 5177 | free(head_names); |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 5178 | |
| 5179 | weston_output_emit_heads_changed(output); |
Pekka Paalanen | a010699 | 2017-12-08 16:11:17 +0200 | [diff] [blame] | 5180 | } |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5181 | } |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5182 | } |
| 5183 | |
| 5184 | /** Destroy a head |
| 5185 | * |
| 5186 | * \param head The head to be released. |
| 5187 | * |
| 5188 | * Destroys the head. The caller is responsible for freeing the memory pointed |
| 5189 | * to by \c head. |
| 5190 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5191 | * \ingroup head |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5192 | * \internal |
| 5193 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5194 | WL_EXPORT void |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5195 | weston_head_release(struct weston_head *head) |
| 5196 | { |
Pekka Paalanen | 2e1bedb | 2017-10-10 11:21:58 +0300 | [diff] [blame] | 5197 | wl_signal_emit(&head->destroy_signal, head); |
| 5198 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5199 | weston_head_detach(head); |
Pekka Paalanen | 06f99ef | 2017-04-04 16:26:23 +0300 | [diff] [blame] | 5200 | |
| 5201 | free(head->make); |
| 5202 | free(head->model); |
| 5203 | free(head->serial_number); |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 5204 | free(head->name); |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 5205 | |
| 5206 | wl_list_remove(&head->compositor_link); |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5207 | } |
| 5208 | |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5209 | static void |
| 5210 | weston_head_set_device_changed(struct weston_head *head) |
| 5211 | { |
| 5212 | head->device_changed = true; |
| 5213 | |
| 5214 | if (head->compositor) |
| 5215 | weston_compositor_schedule_heads_changed(head->compositor); |
| 5216 | } |
| 5217 | |
| 5218 | /** String equal comparison with NULLs being equal */ |
| 5219 | static bool |
| 5220 | str_null_eq(const char *a, const char *b) |
| 5221 | { |
| 5222 | if (!a && !b) |
| 5223 | return true; |
| 5224 | |
| 5225 | if (!!a != !!b) |
| 5226 | return false; |
| 5227 | |
| 5228 | return strcmp(a, b) == 0; |
| 5229 | } |
| 5230 | |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5231 | /** Store monitor make, model and serial number |
| 5232 | * |
| 5233 | * \param head The head to modify. |
| 5234 | * \param make The monitor make. If EDID is available, the PNP ID. Otherwise |
| 5235 | * any string, or NULL for none. |
| 5236 | * \param model The monitor model or name, or a made-up string, or NULL for |
| 5237 | * none. |
| 5238 | * \param serialno The monitor serial number, a made-up string, or NULL for |
| 5239 | * none. |
| 5240 | * |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5241 | * This may set the device_changed flag. |
| 5242 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5243 | * \ingroup head |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5244 | * \internal |
| 5245 | */ |
| 5246 | WL_EXPORT void |
| 5247 | weston_head_set_monitor_strings(struct weston_head *head, |
| 5248 | const char *make, |
| 5249 | const char *model, |
| 5250 | const char *serialno) |
| 5251 | { |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5252 | if (str_null_eq(head->make, make) && |
| 5253 | str_null_eq(head->model, model) && |
| 5254 | str_null_eq(head->serial_number, serialno)) |
| 5255 | return; |
| 5256 | |
Pekka Paalanen | 06f99ef | 2017-04-04 16:26:23 +0300 | [diff] [blame] | 5257 | free(head->make); |
| 5258 | free(head->model); |
| 5259 | free(head->serial_number); |
| 5260 | |
| 5261 | head->make = make ? strdup(make) : NULL; |
| 5262 | head->model = model ? strdup(model) : NULL; |
| 5263 | head->serial_number = serialno ? strdup(serialno) : NULL; |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5264 | |
| 5265 | weston_head_set_device_changed(head); |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5266 | } |
| 5267 | |
Philipp Zabel | c18ffd3 | 2018-08-30 17:38:03 +0200 | [diff] [blame] | 5268 | /** Store display non-desktop status |
| 5269 | * |
| 5270 | * \param head The head to modify. |
| 5271 | * \param non_desktop Whether the head connects to a non-desktop display. |
| 5272 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5273 | * \ingroup head |
Philipp Zabel | c18ffd3 | 2018-08-30 17:38:03 +0200 | [diff] [blame] | 5274 | * \internal |
| 5275 | */ |
| 5276 | WL_EXPORT void |
| 5277 | weston_head_set_non_desktop(struct weston_head *head, bool non_desktop) |
| 5278 | { |
| 5279 | if (head->non_desktop == non_desktop) |
| 5280 | return; |
| 5281 | |
| 5282 | head->non_desktop = non_desktop; |
| 5283 | |
| 5284 | weston_head_set_device_changed(head); |
| 5285 | } |
| 5286 | |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5287 | /** Store physical image size |
| 5288 | * |
| 5289 | * \param head The head to modify. |
| 5290 | * \param mm_width Image area width in millimeters. |
| 5291 | * \param mm_height Image area height in millimeters. |
| 5292 | * |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5293 | * This may set the device_changed flag. |
| 5294 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5295 | * \ingroup head |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5296 | * \internal |
| 5297 | */ |
| 5298 | WL_EXPORT void |
| 5299 | weston_head_set_physical_size(struct weston_head *head, |
| 5300 | int32_t mm_width, int32_t mm_height) |
| 5301 | { |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5302 | if (head->mm_width == mm_width && |
| 5303 | head->mm_height == mm_height) |
| 5304 | return; |
| 5305 | |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5306 | head->mm_width = mm_width; |
| 5307 | head->mm_height = mm_height; |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5308 | |
| 5309 | weston_head_set_device_changed(head); |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5310 | } |
| 5311 | |
| 5312 | /** Store monitor sub-pixel layout |
| 5313 | * |
| 5314 | * \param head The head to modify. |
| 5315 | * \param sp Sub-pixel layout. The possible values are: |
| 5316 | * - WL_OUTPUT_SUBPIXEL_UNKNOWN, |
| 5317 | * - WL_OUTPUT_SUBPIXEL_NONE, |
| 5318 | * - WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB, |
| 5319 | * - WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR, |
| 5320 | * - WL_OUTPUT_SUBPIXEL_VERTICAL_RGB, |
| 5321 | * - WL_OUTPUT_SUBPIXEL_VERTICAL_BGR |
| 5322 | * |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5323 | * This may set the device_changed flag. |
| 5324 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5325 | * \ingroup head |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5326 | * \internal |
| 5327 | */ |
| 5328 | WL_EXPORT void |
| 5329 | weston_head_set_subpixel(struct weston_head *head, |
| 5330 | enum wl_output_subpixel sp) |
| 5331 | { |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5332 | if (head->subpixel == sp) |
| 5333 | return; |
| 5334 | |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5335 | head->subpixel = sp; |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5336 | |
| 5337 | weston_head_set_device_changed(head); |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5338 | } |
| 5339 | |
| 5340 | /** Mark the monitor as internal |
| 5341 | * |
| 5342 | * This is used for embedded screens, like laptop panels. |
| 5343 | * |
| 5344 | * \param head The head to mark as internal. |
| 5345 | * |
| 5346 | * By default a head is external. The type is often inferred from the physical |
| 5347 | * connector type. |
| 5348 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5349 | * \ingroup head |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5350 | * \internal |
| 5351 | */ |
| 5352 | WL_EXPORT void |
| 5353 | weston_head_set_internal(struct weston_head *head) |
| 5354 | { |
| 5355 | head->connection_internal = true; |
| 5356 | } |
Pekka Paalanen | 9ffb250 | 2017-03-27 15:14:32 +0300 | [diff] [blame] | 5357 | |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5358 | /** Store connector status |
| 5359 | * |
| 5360 | * \param head The head to modify. |
| 5361 | * \param connected Whether the head is connected. |
| 5362 | * |
| 5363 | * Connectors are created as disconnected. This function can be used to |
| 5364 | * set the connector status. |
| 5365 | * |
| 5366 | * The status should be set to true when a physical connector is connected to |
| 5367 | * a video sink device like a monitor and to false when the connector is |
| 5368 | * disconnected. For nested backends, the connection status should reflect the |
| 5369 | * connection to the parent display server. |
| 5370 | * |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5371 | * When the connection status changes, it schedules a call to the heads_changed |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5372 | * hook and sets the device_changed flag. |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5373 | * |
| 5374 | * \sa weston_compositor_set_heads_changed_cb |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5375 | * \ingroup head |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5376 | * \internal |
| 5377 | */ |
| 5378 | WL_EXPORT void |
| 5379 | weston_head_set_connection_status(struct weston_head *head, bool connected) |
| 5380 | { |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5381 | if (head->connected == connected) |
| 5382 | return; |
| 5383 | |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5384 | head->connected = connected; |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5385 | |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5386 | weston_head_set_device_changed(head); |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5387 | } |
| 5388 | |
Ankit Nautiyal | 4f64ff8 | 2019-04-03 18:44:35 +0530 | [diff] [blame] | 5389 | static void |
| 5390 | weston_output_compute_protection(struct weston_output *output) |
| 5391 | { |
| 5392 | struct weston_head *head; |
| 5393 | enum weston_hdcp_protection op_protection; |
| 5394 | bool op_protection_valid = false; |
Ankit Nautiyal | f74c35b | 2019-04-03 19:21:58 +0530 | [diff] [blame] | 5395 | struct weston_compositor *wc = output->compositor; |
| 5396 | struct content_protection *cp = wc->content_protection; |
| 5397 | |
| 5398 | if (!cp) |
| 5399 | return; |
Ankit Nautiyal | 4f64ff8 | 2019-04-03 18:44:35 +0530 | [diff] [blame] | 5400 | |
| 5401 | wl_list_for_each(head, &output->head_list, output_link) { |
| 5402 | if (!op_protection_valid) { |
| 5403 | op_protection = head->current_protection; |
| 5404 | op_protection_valid = true; |
| 5405 | } |
| 5406 | if (head->current_protection < op_protection) |
| 5407 | op_protection = head->current_protection; |
| 5408 | } |
| 5409 | |
| 5410 | if (!op_protection_valid) |
| 5411 | op_protection = WESTON_HDCP_DISABLE; |
| 5412 | |
Ankit Nautiyal | f74c35b | 2019-04-03 19:21:58 +0530 | [diff] [blame] | 5413 | if (output->current_protection != op_protection) { |
| 5414 | struct wl_event_loop *loop; |
| 5415 | |
Ankit Nautiyal | 4f64ff8 | 2019-04-03 18:44:35 +0530 | [diff] [blame] | 5416 | output->current_protection = op_protection; |
Ankit Nautiyal | f74c35b | 2019-04-03 19:21:58 +0530 | [diff] [blame] | 5417 | weston_output_damage(output); |
| 5418 | if (cp->surface_protection_update) |
| 5419 | return; |
| 5420 | loop = wl_display_get_event_loop(wc->wl_display); |
| 5421 | cp->surface_protection_update = wl_event_loop_add_idle(loop, |
| 5422 | notify_surface_protection_change, |
| 5423 | wc); |
| 5424 | } |
Ankit Nautiyal | 4f64ff8 | 2019-04-03 18:44:35 +0530 | [diff] [blame] | 5425 | } |
| 5426 | |
| 5427 | WL_EXPORT void |
| 5428 | weston_head_set_content_protection_status(struct weston_head *head, |
| 5429 | enum weston_hdcp_protection status) |
| 5430 | { |
| 5431 | head->current_protection = status; |
| 5432 | if (head->output) |
| 5433 | weston_output_compute_protection(head->output); |
| 5434 | } |
| 5435 | |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5436 | /** Is the head currently connected? |
| 5437 | * |
| 5438 | * \param head The head to query. |
| 5439 | * \return Connection status. |
| 5440 | * |
| 5441 | * Returns true if the head is physically connected to a monitor, or in |
| 5442 | * case of a nested backend returns true when there is a connection to the |
| 5443 | * parent display server. |
| 5444 | * |
| 5445 | * This is independent from the head being enabled. |
| 5446 | * |
| 5447 | * \sa weston_head_is_enabled |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5448 | * \ingroup head |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5449 | */ |
| 5450 | WL_EXPORT bool |
| 5451 | weston_head_is_connected(struct weston_head *head) |
| 5452 | { |
| 5453 | return head->connected; |
| 5454 | } |
| 5455 | |
Pekka Paalanen | 8e552fd | 2018-02-15 15:18:20 +0200 | [diff] [blame] | 5456 | /** Is the head currently enabled? |
| 5457 | * |
| 5458 | * \param head The head to query. |
| 5459 | * \return Video status. |
| 5460 | * |
| 5461 | * Returns true if the head is currently transmitting a video stream. |
| 5462 | * |
| 5463 | * This is independent of the head being connected. |
| 5464 | * |
| 5465 | * \sa weston_head_is_connected |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5466 | * \ingroup head |
Pekka Paalanen | 8e552fd | 2018-02-15 15:18:20 +0200 | [diff] [blame] | 5467 | */ |
| 5468 | WL_EXPORT bool |
| 5469 | weston_head_is_enabled(struct weston_head *head) |
| 5470 | { |
| 5471 | if (!head->output) |
| 5472 | return false; |
| 5473 | |
| 5474 | return head->output->enabled; |
| 5475 | } |
| 5476 | |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5477 | /** Has the device information changed? |
| 5478 | * |
| 5479 | * \param head The head to query. |
| 5480 | * \return True if the device information has changed since last reset. |
| 5481 | * |
| 5482 | * The information about the connected display device, e.g. a monitor, may |
| 5483 | * change without being disconnected in between. Changing information |
| 5484 | * causes a call to the heads_changed hook. |
| 5485 | * |
| 5486 | * The information includes make, model, serial number, physical size, |
| 5487 | * and sub-pixel type. The connection status is also included. |
| 5488 | * |
| 5489 | * \sa weston_head_reset_device_changed, weston_compositor_set_heads_changed_cb |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5490 | * \ingroup head |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5491 | */ |
| 5492 | WL_EXPORT bool |
| 5493 | weston_head_is_device_changed(struct weston_head *head) |
| 5494 | { |
| 5495 | return head->device_changed; |
| 5496 | } |
| 5497 | |
Philipp Zabel | c18ffd3 | 2018-08-30 17:38:03 +0200 | [diff] [blame] | 5498 | /** Does the head represent a non-desktop display? |
| 5499 | * |
| 5500 | * \param head The head to query. |
| 5501 | * \return True if the device is a non-desktop display. |
| 5502 | * |
| 5503 | * Non-desktop heads are not attached to outputs by default. |
| 5504 | * This stops weston from extending the desktop onto head mounted displays. |
| 5505 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5506 | * \ingroup head |
Philipp Zabel | c18ffd3 | 2018-08-30 17:38:03 +0200 | [diff] [blame] | 5507 | */ |
| 5508 | WL_EXPORT bool |
| 5509 | weston_head_is_non_desktop(struct weston_head *head) |
| 5510 | { |
| 5511 | return head->non_desktop; |
| 5512 | } |
| 5513 | |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5514 | /** Acknowledge device information change |
| 5515 | * |
| 5516 | * \param head The head to acknowledge. |
| 5517 | * |
| 5518 | * Clears the device changed flag on this head. When a compositor has processed |
| 5519 | * device information, it should call this to be able to notice further |
| 5520 | * changes. |
| 5521 | * |
| 5522 | * \sa weston_head_is_device_changed |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5523 | * \ingroup head |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5524 | */ |
| 5525 | WL_EXPORT void |
| 5526 | weston_head_reset_device_changed(struct weston_head *head) |
| 5527 | { |
| 5528 | head->device_changed = false; |
| 5529 | } |
| 5530 | |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5531 | /** Get the name of a head |
| 5532 | * |
| 5533 | * \param head The head to query. |
| 5534 | * \return The head's name, not NULL. |
| 5535 | * |
| 5536 | * The name depends on the backend. The DRM backend uses connector names, |
| 5537 | * other backends may use hardcoded names or user-given names. |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5538 | * |
| 5539 | * \ingroup head |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5540 | */ |
| 5541 | WL_EXPORT const char * |
| 5542 | weston_head_get_name(struct weston_head *head) |
| 5543 | { |
| 5544 | return head->name; |
| 5545 | } |
| 5546 | |
| 5547 | /** Get the output the head is attached to |
| 5548 | * |
| 5549 | * \param head The head to query. |
| 5550 | * \return The output the head is attached to, or NULL if detached. |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5551 | * \ingroup head |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5552 | */ |
| 5553 | WL_EXPORT struct weston_output * |
| 5554 | weston_head_get_output(struct weston_head *head) |
| 5555 | { |
| 5556 | return head->output; |
| 5557 | } |
| 5558 | |
Pekka Paalanen | 2e1bedb | 2017-10-10 11:21:58 +0300 | [diff] [blame] | 5559 | /** Add destroy callback for a head |
| 5560 | * |
| 5561 | * \param head The head to watch for. |
| 5562 | * \param listener The listener to add. The \c notify member must be set. |
| 5563 | * |
| 5564 | * Heads may get destroyed for various reasons by the backends. If a head is |
| 5565 | * attached to an output, the compositor should listen for head destruction |
| 5566 | * and reconfigure or destroy the output if necessary. |
| 5567 | * |
| 5568 | * The destroy callbacks will be called on weston_head destruction before any |
| 5569 | * automatic detaching from an associated weston_output and before any |
| 5570 | * weston_head information is lost. |
| 5571 | * |
| 5572 | * The \c data argument to the notify callback is the weston_head being |
| 5573 | * destroyed. |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5574 | * |
| 5575 | * \ingroup head |
Pekka Paalanen | 2e1bedb | 2017-10-10 11:21:58 +0300 | [diff] [blame] | 5576 | */ |
| 5577 | WL_EXPORT void |
| 5578 | weston_head_add_destroy_listener(struct weston_head *head, |
| 5579 | struct wl_listener *listener) |
| 5580 | { |
| 5581 | wl_signal_add(&head->destroy_signal, listener); |
| 5582 | } |
| 5583 | |
| 5584 | /** Look up destroy listener for a head |
| 5585 | * |
| 5586 | * \param head The head to query. |
| 5587 | * \param notify The notify function used used for the added destroy listener. |
| 5588 | * \return The listener, or NULL if not found. |
| 5589 | * |
| 5590 | * This looks up the previously added destroy listener struct based on the |
| 5591 | * notify function it has. The listener can be used to access user data |
| 5592 | * through \c container_of(). |
| 5593 | * |
| 5594 | * \sa wl_signal_get() |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5595 | * \ingroup head |
Pekka Paalanen | 2e1bedb | 2017-10-10 11:21:58 +0300 | [diff] [blame] | 5596 | */ |
| 5597 | WL_EXPORT struct wl_listener * |
| 5598 | weston_head_get_destroy_listener(struct weston_head *head, |
| 5599 | wl_notify_func_t notify) |
| 5600 | { |
| 5601 | return wl_signal_get(&head->destroy_signal, notify); |
| 5602 | } |
| 5603 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 5604 | /* Move other outputs when one is resized so the space remains contiguous. */ |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 5605 | static void |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 5606 | weston_compositor_reflow_outputs(struct weston_compositor *compositor, |
| 5607 | struct weston_output *resized_output, int delta_width) |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 5608 | { |
| 5609 | struct weston_output *output; |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 5610 | bool start_resizing = false; |
| 5611 | |
| 5612 | if (!delta_width) |
| 5613 | return; |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 5614 | |
| 5615 | wl_list_for_each(output, &compositor->output_list, link) { |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 5616 | if (output == resized_output) { |
| 5617 | start_resizing = true; |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 5618 | continue; |
| 5619 | } |
| 5620 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 5621 | if (start_resizing) { |
| 5622 | weston_output_move(output, output->x + delta_width, output->y); |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 5623 | output->dirty = 1; |
| 5624 | } |
| 5625 | } |
| 5626 | } |
| 5627 | |
Pekka Paalanen | d72bad2 | 2017-03-29 17:01:41 +0300 | [diff] [blame] | 5628 | static void |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5629 | weston_output_update_matrix(struct weston_output *output) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 5630 | { |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 5631 | float magnification; |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 5632 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5633 | weston_matrix_init(&output->matrix); |
Jason Ekstrand | fb23df7 | 2014-10-16 10:55:21 -0500 | [diff] [blame] | 5634 | weston_matrix_translate(&output->matrix, -output->x, -output->y, 0); |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 5635 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5636 | if (output->zoom.active) { |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 5637 | magnification = 1 / (1 - output->zoom.spring_z.current); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5638 | weston_output_update_zoom(output); |
Neil Roberts | 1e40a7e | 2014-04-25 13:19:37 +0100 | [diff] [blame] | 5639 | weston_matrix_translate(&output->matrix, -output->zoom.trans_x, |
Jason Ekstrand | fb23df7 | 2014-10-16 10:55:21 -0500 | [diff] [blame] | 5640 | -output->zoom.trans_y, 0); |
Neil Roberts | 1e40a7e | 2014-04-25 13:19:37 +0100 | [diff] [blame] | 5641 | weston_matrix_scale(&output->matrix, magnification, |
| 5642 | magnification, 1.0); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5643 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 5644 | |
Jason Ekstrand | fb23df7 | 2014-10-16 10:55:21 -0500 | [diff] [blame] | 5645 | switch (output->transform) { |
| 5646 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 5647 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 5648 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 5649 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 5650 | weston_matrix_translate(&output->matrix, -output->width, 0, 0); |
| 5651 | weston_matrix_scale(&output->matrix, -1, 1, 1); |
| 5652 | break; |
| 5653 | } |
| 5654 | |
| 5655 | switch (output->transform) { |
| 5656 | default: |
| 5657 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 5658 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 5659 | break; |
| 5660 | case WL_OUTPUT_TRANSFORM_90: |
| 5661 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 5662 | weston_matrix_translate(&output->matrix, 0, -output->height, 0); |
| 5663 | weston_matrix_rotate_xy(&output->matrix, 0, 1); |
| 5664 | break; |
| 5665 | case WL_OUTPUT_TRANSFORM_180: |
| 5666 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 5667 | weston_matrix_translate(&output->matrix, |
| 5668 | -output->width, -output->height, 0); |
| 5669 | weston_matrix_rotate_xy(&output->matrix, -1, 0); |
| 5670 | break; |
| 5671 | case WL_OUTPUT_TRANSFORM_270: |
| 5672 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 5673 | weston_matrix_translate(&output->matrix, -output->width, 0, 0); |
| 5674 | weston_matrix_rotate_xy(&output->matrix, 0, -1); |
| 5675 | break; |
| 5676 | } |
| 5677 | |
| 5678 | if (output->current_scale != 1) |
| 5679 | weston_matrix_scale(&output->matrix, |
| 5680 | output->current_scale, |
| 5681 | output->current_scale, 1); |
Neil Roberts | 6c3b01f | 2014-05-06 19:04:15 +0100 | [diff] [blame] | 5682 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5683 | output->dirty = 0; |
Derek Foreman | c002321 | 2015-03-24 11:36:13 -0500 | [diff] [blame] | 5684 | |
| 5685 | weston_matrix_invert(&output->inverse_matrix, &output->matrix); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5686 | } |
| 5687 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 5688 | static void |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 5689 | 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] | 5690 | { |
| 5691 | output->transform = transform; |
Pekka Paalanen | 59987fa | 2016-04-26 15:50:59 +0300 | [diff] [blame] | 5692 | output->native_scale = scale; |
| 5693 | output->current_scale = scale; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 5694 | |
Pekka Paalanen | 59987fa | 2016-04-26 15:50:59 +0300 | [diff] [blame] | 5695 | convert_size_by_transform_scale(&output->width, &output->height, |
| 5696 | output->current_mode->width, |
| 5697 | output->current_mode->height, |
| 5698 | transform, scale); |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 5699 | } |
| 5700 | |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5701 | static void |
| 5702 | weston_output_init_geometry(struct weston_output *output, int x, int y) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5703 | { |
| 5704 | output->x = x; |
| 5705 | output->y = y; |
| 5706 | |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 5707 | pixman_region32_fini(&output->previous_damage); |
Ander Conselvan de Oliveira | b8fcca9 | 2012-11-16 17:23:52 +0200 | [diff] [blame] | 5708 | pixman_region32_init(&output->previous_damage); |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 5709 | |
| 5710 | pixman_region32_fini(&output->region); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5711 | pixman_region32_init_rect(&output->region, x, y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 5712 | output->width, |
| 5713 | output->height); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 5714 | } |
| 5715 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 5716 | /** |
| 5717 | * \ingroup output |
| 5718 | */ |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5719 | WL_EXPORT void |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5720 | weston_output_move(struct weston_output *output, int x, int y) |
| 5721 | { |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5722 | struct weston_head *head; |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5723 | struct wl_resource *resource; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5724 | int ver; |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5725 | |
| 5726 | output->move_x = x - output->x; |
| 5727 | output->move_y = y - output->y; |
| 5728 | |
| 5729 | if (output->move_x == 0 && output->move_y == 0) |
| 5730 | return; |
| 5731 | |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5732 | weston_output_init_geometry(output, x, y); |
| 5733 | |
| 5734 | output->dirty = 1; |
| 5735 | |
| 5736 | /* Move views on this output. */ |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 5737 | wl_signal_emit(&output->compositor->output_moved_signal, output); |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5738 | |
| 5739 | /* Notify clients of the change for output position. */ |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5740 | wl_list_for_each(head, &output->head_list, output_link) { |
| 5741 | wl_resource_for_each(resource, &head->resource_list) { |
| 5742 | wl_output_send_geometry(resource, |
| 5743 | output->x, |
| 5744 | output->y, |
| 5745 | head->mm_width, |
| 5746 | head->mm_height, |
| 5747 | head->subpixel, |
| 5748 | head->make, |
| 5749 | head->model, |
| 5750 | output->transform); |
Quanxian Wang | b2c8636 | 2014-03-14 09:16:25 +0800 | [diff] [blame] | 5751 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5752 | ver = wl_resource_get_version(resource); |
| 5753 | if (ver >= WL_OUTPUT_DONE_SINCE_VERSION) |
| 5754 | wl_output_send_done(resource); |
| 5755 | } |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 5756 | |
| 5757 | wl_resource_for_each(resource, &head->xdg_output_resource_list) { |
| 5758 | zxdg_output_v1_send_logical_position(resource, |
| 5759 | output->x, |
| 5760 | output->y); |
| 5761 | zxdg_output_v1_send_done(resource); |
| 5762 | } |
Quanxian Wang | b2c8636 | 2014-03-14 09:16:25 +0800 | [diff] [blame] | 5763 | } |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5764 | } |
| 5765 | |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5766 | /** Signal that a pending output is taken into use. |
| 5767 | * |
| 5768 | * Removes the output from the pending list and adds it to the compositor's |
| 5769 | * list of enabled outputs. The output created signal is emitted. |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5770 | * |
Pekka Paalanen | 2210ad0 | 2017-03-30 15:48:06 +0300 | [diff] [blame] | 5771 | * The output gets an internal ID assigned, and the wl_output global is |
| 5772 | * created. |
Pekka Paalanen | 3d2d497 | 2017-03-30 15:19:45 +0300 | [diff] [blame] | 5773 | * |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5774 | * \param compositor The compositor instance. |
| 5775 | * \param output The output to be added. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5776 | * |
| 5777 | * \internal |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 5778 | * \ingroup compositor |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5779 | */ |
Pekka Paalanen | f9681b5 | 2017-03-29 16:58:48 +0300 | [diff] [blame] | 5780 | static void |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5781 | weston_compositor_add_output(struct weston_compositor *compositor, |
| 5782 | struct weston_output *output) |
| 5783 | { |
Armin Krezović | e540384 | 2016-08-05 15:28:29 +0200 | [diff] [blame] | 5784 | struct weston_view *view, *next; |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 5785 | struct weston_head *head; |
Armin Krezović | e540384 | 2016-08-05 15:28:29 +0200 | [diff] [blame] | 5786 | |
Pekka Paalanen | 7f340ff | 2017-03-30 14:56:22 +0300 | [diff] [blame] | 5787 | assert(!output->enabled); |
Pekka Paalanen | 3d2d497 | 2017-03-30 15:19:45 +0300 | [diff] [blame] | 5788 | |
| 5789 | /* Verify we haven't reached the limit of 32 available output IDs */ |
| 5790 | assert(ffs(~compositor->output_id_pool) > 0); |
| 5791 | |
| 5792 | /* Invert the output id pool and look for the lowest numbered |
| 5793 | * switch (the least significant bit). Take that bit's position |
| 5794 | * as our ID, and mark it used in the compositor's output_id_pool. |
| 5795 | */ |
| 5796 | output->id = ffs(~compositor->output_id_pool) - 1; |
| 5797 | compositor->output_id_pool |= 1u << output->id; |
| 5798 | |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5799 | wl_list_remove(&output->link); |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5800 | wl_list_insert(compositor->output_list.prev, &output->link); |
Pekka Paalanen | 7f340ff | 2017-03-30 14:56:22 +0300 | [diff] [blame] | 5801 | output->enabled = true; |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5802 | |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 5803 | wl_list_for_each(head, &output->head_list, output_link) |
| 5804 | weston_head_add_global(head); |
Pekka Paalanen | 2210ad0 | 2017-03-30 15:48:06 +0300 | [diff] [blame] | 5805 | |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5806 | wl_signal_emit(&compositor->output_created_signal, output); |
Armin Krezović | e540384 | 2016-08-05 15:28:29 +0200 | [diff] [blame] | 5807 | |
| 5808 | wl_list_for_each_safe(view, next, &compositor->view_list, link) |
| 5809 | weston_view_geometry_dirty(view); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 5810 | } |
| 5811 | |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5812 | /** Transform device coordinates into global coordinates |
| 5813 | * |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 5814 | * \param output the weston_output object |
| 5815 | * \param[in] device_x X coordinate in device units. |
| 5816 | * \param[in] device_y Y coordinate in device units. |
| 5817 | * \param[out] x X coordinate in the global space. |
| 5818 | * \param[out] y Y coordinate in the global space. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5819 | * |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 5820 | * Transforms coordinates from the device coordinate space (physical pixel |
| 5821 | * units) to the global coordinate space (logical pixel units). This takes |
| 5822 | * into account output transform and scale. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5823 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 5824 | * \ingroup output |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5825 | * \internal |
| 5826 | */ |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 5827 | WL_EXPORT void |
| 5828 | weston_output_transform_coordinate(struct weston_output *output, |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 5829 | double device_x, double device_y, |
| 5830 | double *x, double *y) |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 5831 | { |
Derek Foreman | 0f67941 | 2014-10-02 13:41:17 -0500 | [diff] [blame] | 5832 | struct weston_vector p = { { |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 5833 | device_x, |
| 5834 | device_y, |
Derek Foreman | 0f67941 | 2014-10-02 13:41:17 -0500 | [diff] [blame] | 5835 | 0.0, |
| 5836 | 1.0 } }; |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 5837 | |
Derek Foreman | 67a18b9 | 2015-03-24 11:36:14 -0500 | [diff] [blame] | 5838 | weston_matrix_transform(&output->inverse_matrix, &p); |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 5839 | |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 5840 | *x = p.f[0] / p.f[3]; |
| 5841 | *y = p.f[1] / p.f[3]; |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 5842 | } |
| 5843 | |
Pekka Paalanen | e6ac4fc | 2017-03-29 16:07:34 +0300 | [diff] [blame] | 5844 | /** Removes output from compositor's list of enabled outputs |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5845 | * |
| 5846 | * \param output The weston_output object that is being removed. |
| 5847 | * |
Pekka Paalanen | e6ac4fc | 2017-03-29 16:07:34 +0300 | [diff] [blame] | 5848 | * The following happens: |
| 5849 | * |
| 5850 | * - The output assignments of all views in the current scenegraph are |
| 5851 | * recomputed. |
| 5852 | * |
| 5853 | * - Presentation feedback is discarded. |
| 5854 | * |
| 5855 | * - Compositor is notified that outputs were changed and |
| 5856 | * applies the necessary changes to re-layout outputs. |
| 5857 | * |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5858 | * - The output is put back in the pending outputs list. |
| 5859 | * |
Pekka Paalanen | e6ac4fc | 2017-03-29 16:07:34 +0300 | [diff] [blame] | 5860 | * - Signal is emitted to notify all users of the weston_output |
| 5861 | * object that the output is being destroyed. |
| 5862 | * |
| 5863 | * - wl_output protocol objects referencing this weston_output |
Pekka Paalanen | 2210ad0 | 2017-03-30 15:48:06 +0300 | [diff] [blame] | 5864 | * are made inert, and the wl_output global is removed. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5865 | * |
Pekka Paalanen | 3d2d497 | 2017-03-30 15:19:45 +0300 | [diff] [blame] | 5866 | * - The output's internal ID is released. |
| 5867 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 5868 | * \ingroup compositor |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5869 | * \internal |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5870 | */ |
| 5871 | static void |
| 5872 | weston_compositor_remove_output(struct weston_output *output) |
| 5873 | { |
Pekka Paalanen | bccda71 | 2017-03-29 16:16:04 +0300 | [diff] [blame] | 5874 | struct weston_compositor *compositor = output->compositor; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5875 | struct weston_view *view; |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 5876 | struct weston_head *head; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5877 | |
| 5878 | assert(output->destroying); |
Pekka Paalanen | 7f340ff | 2017-03-30 14:56:22 +0300 | [diff] [blame] | 5879 | assert(output->enabled); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5880 | |
Pekka Paalanen | bccda71 | 2017-03-29 16:16:04 +0300 | [diff] [blame] | 5881 | wl_list_for_each(view, &compositor->view_list, link) { |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5882 | if (view->output_mask & (1u << output->id)) |
| 5883 | weston_view_assign_output(view); |
| 5884 | } |
| 5885 | |
| 5886 | weston_presentation_feedback_discard_list(&output->feedback_list); |
| 5887 | |
Pekka Paalanen | 9711fd9 | 2018-06-21 14:26:18 +0300 | [diff] [blame] | 5888 | weston_compositor_reflow_outputs(compositor, output, -output->width); |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5889 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5890 | wl_list_remove(&output->link); |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5891 | wl_list_insert(compositor->pending_output_list.prev, &output->link); |
Pekka Paalanen | 7f340ff | 2017-03-30 14:56:22 +0300 | [diff] [blame] | 5892 | output->enabled = false; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5893 | |
Pekka Paalanen | bccda71 | 2017-03-29 16:16:04 +0300 | [diff] [blame] | 5894 | wl_signal_emit(&compositor->output_destroyed_signal, output); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5895 | wl_signal_emit(&output->destroy_signal, output); |
| 5896 | |
Pekka Paalanen | d9dcc6d | 2017-12-04 15:28:13 +0200 | [diff] [blame] | 5897 | wl_list_for_each(head, &output->head_list, output_link) |
| 5898 | weston_head_remove_global(head); |
Pekka Paalanen | 3d2d497 | 2017-03-30 15:19:45 +0300 | [diff] [blame] | 5899 | |
| 5900 | compositor->output_id_pool &= ~(1u << output->id); |
| 5901 | output->id = 0xffffffff; /* invalid */ |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5902 | } |
| 5903 | |
| 5904 | /** Sets the output scale for a given output. |
| 5905 | * |
| 5906 | * \param output The weston_output object that the scale is set for. |
| 5907 | * \param scale Scale factor for the given output. |
| 5908 | * |
| 5909 | * It only supports setting scale for an output that |
| 5910 | * is not enabled and it can only be ran once. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5911 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 5912 | * \ingroup ouput |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5913 | */ |
| 5914 | WL_EXPORT void |
| 5915 | weston_output_set_scale(struct weston_output *output, |
| 5916 | int32_t scale) |
| 5917 | { |
| 5918 | /* We can only set scale on a disabled output */ |
| 5919 | assert(!output->enabled); |
| 5920 | |
| 5921 | /* We only want to set scale once */ |
| 5922 | assert(!output->scale); |
| 5923 | |
| 5924 | output->scale = scale; |
| 5925 | } |
| 5926 | |
| 5927 | /** Sets the output transform for a given output. |
| 5928 | * |
| 5929 | * \param output The weston_output object that the transform is set for. |
| 5930 | * \param transform Transform value for the given output. |
| 5931 | * |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5932 | * Refer to wl_output::transform section located at |
| 5933 | * https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_output |
| 5934 | * for list of values that can be passed to this function. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5935 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 5936 | * \ingroup output |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5937 | */ |
| 5938 | WL_EXPORT void |
| 5939 | weston_output_set_transform(struct weston_output *output, |
| 5940 | uint32_t transform) |
| 5941 | { |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 5942 | struct weston_pointer_motion_event ev; |
| 5943 | struct wl_resource *resource; |
| 5944 | struct weston_seat *seat; |
| 5945 | pixman_region32_t old_region; |
| 5946 | int mid_x, mid_y; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5947 | struct weston_head *head; |
| 5948 | int ver; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5949 | |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 5950 | if (!output->enabled && output->transform == UINT32_MAX) { |
| 5951 | output->transform = transform; |
| 5952 | return; |
| 5953 | } |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5954 | |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 5955 | weston_output_transform_scale_init(output, transform, output->scale); |
| 5956 | |
| 5957 | pixman_region32_init(&old_region); |
| 5958 | pixman_region32_copy(&old_region, &output->region); |
| 5959 | |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 5960 | weston_output_init_geometry(output, output->x, output->y); |
| 5961 | |
| 5962 | output->dirty = 1; |
| 5963 | |
| 5964 | /* Notify clients of the change for output transform. */ |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5965 | wl_list_for_each(head, &output->head_list, output_link) { |
| 5966 | wl_resource_for_each(resource, &head->resource_list) { |
| 5967 | wl_output_send_geometry(resource, |
| 5968 | output->x, |
| 5969 | output->y, |
| 5970 | head->mm_width, |
| 5971 | head->mm_height, |
| 5972 | head->subpixel, |
| 5973 | head->make, |
| 5974 | head->model, |
| 5975 | output->transform); |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 5976 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5977 | ver = wl_resource_get_version(resource); |
| 5978 | if (ver >= WL_OUTPUT_DONE_SINCE_VERSION) |
| 5979 | wl_output_send_done(resource); |
| 5980 | } |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 5981 | wl_resource_for_each(resource, &head->xdg_output_resource_list) { |
| 5982 | zxdg_output_v1_send_logical_position(resource, |
| 5983 | output->x, |
| 5984 | output->y); |
| 5985 | zxdg_output_v1_send_logical_size(resource, |
| 5986 | output->width, |
| 5987 | output->height); |
| 5988 | zxdg_output_v1_send_done(resource); |
| 5989 | } |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 5990 | } |
| 5991 | |
| 5992 | /* we must ensure that pointers are inside output, otherwise they disappear */ |
| 5993 | mid_x = output->x + output->width / 2; |
| 5994 | mid_y = output->y + output->height / 2; |
| 5995 | |
| 5996 | ev.mask = WESTON_POINTER_MOTION_ABS; |
| 5997 | ev.x = wl_fixed_to_double(wl_fixed_from_int(mid_x)); |
| 5998 | ev.y = wl_fixed_to_double(wl_fixed_from_int(mid_y)); |
| 5999 | |
| 6000 | wl_list_for_each(seat, &output->compositor->seat_list, link) { |
| 6001 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 6002 | |
| 6003 | if (pointer && pixman_region32_contains_point(&old_region, |
| 6004 | wl_fixed_to_int(pointer->x), |
| 6005 | wl_fixed_to_int(pointer->y), |
| 6006 | NULL)) |
| 6007 | weston_pointer_move(pointer, &ev); |
| 6008 | } |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6009 | } |
| 6010 | |
| 6011 | /** Initializes a weston_output object with enough data so |
| 6012 | ** an output can be configured. |
| 6013 | * |
| 6014 | * \param output The weston_output object to initialize |
| 6015 | * \param compositor The compositor instance. |
Pekka Paalanen | 26ac2e1 | 2017-04-03 13:18:13 +0300 | [diff] [blame] | 6016 | * \param name Name for the output (the string is copied). |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6017 | * |
| 6018 | * Sets initial values for fields that are expected to be |
| 6019 | * configured either by compositors or backends. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6020 | * |
Pekka Paalanen | 26ac2e1 | 2017-04-03 13:18:13 +0300 | [diff] [blame] | 6021 | * The name is used in logs, and can be used by compositors as a configuration |
| 6022 | * identifier. |
| 6023 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6024 | * \ingroup output |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6025 | * \internal |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6026 | */ |
| 6027 | WL_EXPORT void |
Armin Krezović | 4008740 | 2016-09-30 14:11:12 +0200 | [diff] [blame] | 6028 | weston_output_init(struct weston_output *output, |
Pekka Paalanen | 26ac2e1 | 2017-04-03 13:18:13 +0300 | [diff] [blame] | 6029 | struct weston_compositor *compositor, |
| 6030 | const char *name) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6031 | { |
| 6032 | output->compositor = compositor; |
| 6033 | output->destroying = 0; |
Pekka Paalanen | 26ac2e1 | 2017-04-03 13:18:13 +0300 | [diff] [blame] | 6034 | output->name = strdup(name); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6035 | wl_list_init(&output->link); |
Pekka Paalanen | 37b7c6e | 2017-11-07 10:15:01 +0200 | [diff] [blame] | 6036 | wl_signal_init(&output->user_destroy_signal); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6037 | output->enabled = false; |
Ankit Nautiyal | 2690a77 | 2019-03-25 17:57:59 +0530 | [diff] [blame] | 6038 | output->desired_protection = WESTON_HDCP_DISABLE; |
Ankit Nautiyal | 2844f8e | 2019-04-03 10:14:59 +0530 | [diff] [blame^] | 6039 | output->allow_protection = true; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6040 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 6041 | wl_list_init(&output->head_list); |
| 6042 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6043 | /* Add some (in)sane defaults which can be used |
| 6044 | * for checking if an output was properly configured |
| 6045 | */ |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6046 | output->scale = 0; |
| 6047 | /* Can't use -1 on uint32_t and 0 is valid enum value */ |
| 6048 | output->transform = UINT32_MAX; |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 6049 | |
| 6050 | pixman_region32_init(&output->previous_damage); |
| 6051 | pixman_region32_init(&output->region); |
Pekka Paalanen | 4270414 | 2017-09-06 16:47:52 +0300 | [diff] [blame] | 6052 | wl_list_init(&output->mode_list); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6053 | } |
| 6054 | |
| 6055 | /** Adds weston_output object to pending output list. |
| 6056 | * |
| 6057 | * \param output The weston_output object to add |
| 6058 | * \param compositor The compositor instance. |
| 6059 | * |
Pekka Paalanen | ae6d35d | 2017-08-16 12:07:14 +0300 | [diff] [blame] | 6060 | * The opposite of this operation is built into weston_output_release(). |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6061 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 6062 | * \ingroup compositor |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6063 | * \internal |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6064 | */ |
| 6065 | WL_EXPORT void |
| 6066 | weston_compositor_add_pending_output(struct weston_output *output, |
| 6067 | struct weston_compositor *compositor) |
| 6068 | { |
Pekka Paalanen | e952a01 | 2017-03-29 17:14:00 +0300 | [diff] [blame] | 6069 | assert(output->disable); |
| 6070 | assert(output->enable); |
| 6071 | |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 6072 | wl_list_remove(&output->link); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6073 | wl_list_insert(compositor->pending_output_list.prev, &output->link); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6074 | } |
| 6075 | |
Pekka Paalanen | 3e8f201 | 2017-11-02 14:03:11 +0200 | [diff] [blame] | 6076 | /** Create a string with the attached heads' names. |
| 6077 | * |
| 6078 | * The string must be free()'d. |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6079 | * |
| 6080 | * \ingroup output |
Pekka Paalanen | 3e8f201 | 2017-11-02 14:03:11 +0200 | [diff] [blame] | 6081 | */ |
| 6082 | static char * |
| 6083 | weston_output_create_heads_string(struct weston_output *output) |
| 6084 | { |
| 6085 | FILE *fp; |
| 6086 | char *str = NULL; |
| 6087 | size_t size = 0; |
| 6088 | struct weston_head *head; |
| 6089 | const char *sep = ""; |
| 6090 | |
| 6091 | fp = open_memstream(&str, &size); |
| 6092 | if (!fp) |
| 6093 | return NULL; |
| 6094 | |
| 6095 | wl_list_for_each(head, &output->head_list, output_link) { |
| 6096 | fprintf(fp, "%s%s", sep, head->name); |
| 6097 | sep = ", "; |
| 6098 | } |
| 6099 | fclose(fp); |
| 6100 | |
| 6101 | return str; |
| 6102 | } |
| 6103 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6104 | /** Constructs a weston_output object that can be used by the compositor. |
| 6105 | * |
Pekka Paalanen | cc201e4 | 2017-03-30 15:11:25 +0300 | [diff] [blame] | 6106 | * \param output The weston_output object that needs to be enabled. Must not |
Pekka Paalanen | ddce54d | 2017-08-23 16:00:21 +0300 | [diff] [blame] | 6107 | * be enabled already. Must have at least one head attached. |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6108 | * |
| 6109 | * Output coordinates are calculated and each new output is by default |
| 6110 | * assigned to the right of previous one. |
| 6111 | * |
| 6112 | * Sets up the transformation, zoom, and geometry of the output using |
| 6113 | * the properties that need to be configured by the compositor. |
| 6114 | * |
| 6115 | * Establishes a repaint timer for the output with the relevant display |
| 6116 | * object's event loop. See output_repaint_timer_handler(). |
| 6117 | * |
| 6118 | * The output is assigned an ID. Weston can support up to 32 distinct |
| 6119 | * outputs, with IDs numbered from 0-31; the compositor's output_id_pool |
| 6120 | * is referred to and used to find the first available ID number, and |
| 6121 | * then this ID is marked as used in output_id_pool. |
| 6122 | * |
| 6123 | * The output is also assigned a Wayland global with the wl_output |
| 6124 | * external interface. |
| 6125 | * |
| 6126 | * Backend specific function is called to set up the output output. |
| 6127 | * |
| 6128 | * Output is added to the compositor's output list |
| 6129 | * |
| 6130 | * If the backend specific function fails, the weston_output object |
| 6131 | * is returned to a state it was before calling this function and |
| 6132 | * is added to the compositor's pending_output_list in case it needs |
| 6133 | * to be reconfigured or just so it can be destroyed at shutdown. |
| 6134 | * |
| 6135 | * 0 is returned on success, -1 on failure. |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6136 | * |
| 6137 | * \ingroup output |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6138 | */ |
| 6139 | WL_EXPORT int |
| 6140 | weston_output_enable(struct weston_output *output) |
| 6141 | { |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 6142 | struct weston_compositor *c = output->compositor; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6143 | struct weston_output *iterator; |
Pekka Paalanen | ec25b0a | 2017-08-24 16:08:49 +0300 | [diff] [blame] | 6144 | struct weston_head *head; |
Pekka Paalanen | 3e8f201 | 2017-11-02 14:03:11 +0200 | [diff] [blame] | 6145 | char *head_names; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6146 | int x = 0, y = 0; |
| 6147 | |
Pekka Paalanen | cc201e4 | 2017-03-30 15:11:25 +0300 | [diff] [blame] | 6148 | if (output->enabled) { |
| 6149 | weston_log("Error: attempt to enable an enabled output '%s'\n", |
| 6150 | output->name); |
| 6151 | return -1; |
| 6152 | } |
| 6153 | |
Pekka Paalanen | ddce54d | 2017-08-23 16:00:21 +0300 | [diff] [blame] | 6154 | if (wl_list_empty(&output->head_list)) { |
| 6155 | weston_log("Error: cannot enable output '%s' without heads.\n", |
| 6156 | output->name); |
| 6157 | return -1; |
| 6158 | } |
| 6159 | |
Pekka Paalanen | 586e1ac | 2017-09-14 16:17:59 +0300 | [diff] [blame] | 6160 | if (wl_list_empty(&output->mode_list) || !output->current_mode) { |
| 6161 | weston_log("Error: no video mode for output '%s'.\n", |
| 6162 | output->name); |
| 6163 | return -1; |
| 6164 | } |
| 6165 | |
Pekka Paalanen | ec25b0a | 2017-08-24 16:08:49 +0300 | [diff] [blame] | 6166 | wl_list_for_each(head, &output->head_list, output_link) { |
| 6167 | assert(head->make); |
| 6168 | assert(head->model); |
| 6169 | } |
| 6170 | |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 6171 | iterator = container_of(c->output_list.prev, |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6172 | struct weston_output, link); |
| 6173 | |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 6174 | if (!wl_list_empty(&c->output_list)) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6175 | x = iterator->x + iterator->width; |
| 6176 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6177 | /* Make sure the scale is set up */ |
| 6178 | assert(output->scale); |
| 6179 | |
| 6180 | /* Make sure we have a transform set */ |
| 6181 | assert(output->transform != UINT32_MAX); |
| 6182 | |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 6183 | output->x = x; |
| 6184 | output->y = y; |
| 6185 | output->dirty = 1; |
| 6186 | output->original_scale = output->scale; |
| 6187 | |
| 6188 | weston_output_transform_scale_init(output, output->transform, output->scale); |
| 6189 | weston_output_init_zoom(output); |
| 6190 | |
| 6191 | weston_output_init_geometry(output, x, y); |
| 6192 | weston_output_damage(output); |
| 6193 | |
| 6194 | wl_signal_init(&output->frame_signal); |
| 6195 | wl_signal_init(&output->destroy_signal); |
| 6196 | wl_list_init(&output->animation_list); |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 6197 | wl_list_init(&output->feedback_list); |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 6198 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6199 | /* Enable the output (set up the crtc or create a |
| 6200 | * window representing the output, set up the |
| 6201 | * renderer, etc) |
| 6202 | */ |
| 6203 | if (output->enable(output) < 0) { |
| 6204 | weston_log("Enabling output \"%s\" failed.\n", output->name); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6205 | return -1; |
| 6206 | } |
| 6207 | |
| 6208 | weston_compositor_add_output(output->compositor, output); |
| 6209 | |
Pekka Paalanen | 3e8f201 | 2017-11-02 14:03:11 +0200 | [diff] [blame] | 6210 | head_names = weston_output_create_heads_string(output); |
| 6211 | weston_log("Output '%s' enabled with head(s) %s\n", |
| 6212 | output->name, head_names); |
| 6213 | free(head_names); |
| 6214 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6215 | return 0; |
| 6216 | } |
| 6217 | |
| 6218 | /** Converts a weston_output object to a pending output state, so it |
| 6219 | ** can be configured again or destroyed. |
| 6220 | * |
| 6221 | * \param output The weston_output object that needs to be disabled. |
| 6222 | * |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6223 | * Calls a backend specific function to disable an output, in case |
| 6224 | * such function exists. |
| 6225 | * |
Pekka Paalanen | c65df64 | 2017-03-29 15:45:46 +0300 | [diff] [blame] | 6226 | * The backend specific disable function may choose to postpone the disabling |
| 6227 | * by returning a negative value, in which case this function returns early. |
| 6228 | * In that case the backend will guarantee the output will be disabled soon |
| 6229 | * by the backend calling this function again. One must not attempt to re-enable |
| 6230 | * the output until that happens. |
| 6231 | * |
| 6232 | * Otherwise, if the output is being used by the compositor, it is removed |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6233 | * from weston's output_list (see weston_compositor_remove_output()) |
| 6234 | * and is returned to a state it was before weston_output_enable() |
| 6235 | * was ran (see weston_output_enable_undo()). |
| 6236 | * |
Pekka Paalanen | c65df64 | 2017-03-29 15:45:46 +0300 | [diff] [blame] | 6237 | * See weston_output_init() for more information on the |
| 6238 | * state output is returned to. |
Pekka Paalanen | cc201e4 | 2017-03-30 15:11:25 +0300 | [diff] [blame] | 6239 | * |
| 6240 | * If the output has never been enabled yet, this function can still be |
| 6241 | * called to ensure that the output is actually turned off rather than left |
| 6242 | * in the state it was discovered in. |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6243 | * |
| 6244 | * \ingroup output |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6245 | */ |
| 6246 | WL_EXPORT void |
| 6247 | weston_output_disable(struct weston_output *output) |
| 6248 | { |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6249 | /* Should we rename this? */ |
| 6250 | output->destroying = 1; |
| 6251 | |
Pekka Paalanen | c65df64 | 2017-03-29 15:45:46 +0300 | [diff] [blame] | 6252 | /* Disable is called unconditionally also for not-enabled outputs, |
| 6253 | * because at compositor start-up, if there is an output that is |
| 6254 | * already on but the compositor wants to turn it off, we have to |
| 6255 | * forward the turn-off to the backend so it knows to do it. |
| 6256 | * The backend cannot initially turn off everything, because it |
| 6257 | * would cause unnecessary mode-sets for all outputs the compositor |
| 6258 | * wants to be on. |
| 6259 | */ |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6260 | if (output->disable(output) < 0) |
| 6261 | return; |
| 6262 | |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 6263 | if (output->enabled) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6264 | weston_compositor_remove_output(output); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6265 | |
| 6266 | output->destroying = 0; |
| 6267 | } |
| 6268 | |
Pekka Paalanen | 8a8dcac | 2017-08-17 17:29:36 +0300 | [diff] [blame] | 6269 | /** Forces a synchronous call to heads_changed hook |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6270 | * |
| 6271 | * \param compositor The compositor instance |
Pekka Paalanen | 8a8dcac | 2017-08-17 17:29:36 +0300 | [diff] [blame] | 6272 | * |
| 6273 | * If there are new or changed heads, calls the heads_changed hook and |
| 6274 | * returns after the hook returns. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 6275 | * |
| 6276 | * \ingroup compositor |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6277 | */ |
| 6278 | WL_EXPORT void |
Pekka Paalanen | 8a8dcac | 2017-08-17 17:29:36 +0300 | [diff] [blame] | 6279 | weston_compositor_flush_heads_changed(struct weston_compositor *compositor) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6280 | { |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 6281 | if (compositor->heads_changed_source) { |
| 6282 | wl_event_source_remove(compositor->heads_changed_source); |
| 6283 | weston_compositor_call_heads_changed(compositor); |
| 6284 | } |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6285 | } |
| 6286 | |
Pekka Paalanen | 37b7c6e | 2017-11-07 10:15:01 +0200 | [diff] [blame] | 6287 | /** Add destroy callback for an output |
| 6288 | * |
| 6289 | * \param output The output to watch. |
| 6290 | * \param listener The listener to add. The \c notify member must be set. |
| 6291 | * |
| 6292 | * The listener callback will be called when user destroys an output. This |
| 6293 | * may be delayed by a backend in some cases. The main purpose of the |
| 6294 | * listener is to allow hooking up custom data to the output. The custom data |
| 6295 | * can be fetched via weston_output_get_destroy_listener() followed by |
| 6296 | * container_of(). |
| 6297 | * |
| 6298 | * The \c data argument to the notify callback is the weston_output being |
| 6299 | * destroyed. |
| 6300 | * |
| 6301 | * @note This is for the final destruction of an output, not when it gets |
| 6302 | * disabled. If you want to keep track of enabled outputs, this is not it. |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6303 | * |
| 6304 | * \ingroup ouput |
Pekka Paalanen | 37b7c6e | 2017-11-07 10:15:01 +0200 | [diff] [blame] | 6305 | */ |
| 6306 | WL_EXPORT void |
| 6307 | weston_output_add_destroy_listener(struct weston_output *output, |
| 6308 | struct wl_listener *listener) |
| 6309 | { |
| 6310 | wl_signal_add(&output->user_destroy_signal, listener); |
| 6311 | } |
| 6312 | |
| 6313 | /** Look up destroy listener for an output |
| 6314 | * |
| 6315 | * \param output The output to query. |
| 6316 | * \param notify The notify function used used for the added destroy listener. |
| 6317 | * \return The listener, or NULL if not found. |
| 6318 | * |
| 6319 | * This looks up the previously added destroy listener struct based on the |
| 6320 | * notify function it has. The listener can be used to access user data |
| 6321 | * through \c container_of(). |
| 6322 | * |
| 6323 | * \sa wl_signal_get() weston_output_add_destroy_listener() |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6324 | * \ingroup output |
Pekka Paalanen | 37b7c6e | 2017-11-07 10:15:01 +0200 | [diff] [blame] | 6325 | */ |
| 6326 | WL_EXPORT struct wl_listener * |
| 6327 | weston_output_get_destroy_listener(struct weston_output *output, |
| 6328 | wl_notify_func_t notify) |
| 6329 | { |
| 6330 | return wl_signal_get(&output->user_destroy_signal, notify); |
| 6331 | } |
| 6332 | |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6333 | /** Uninitialize an output |
| 6334 | * |
| 6335 | * Removes the output from the list of enabled outputs if necessary, but |
| 6336 | * does not call the backend's output disable function. The output will no |
| 6337 | * longer be in the list of pending outputs either. |
| 6338 | * |
| 6339 | * All fields of weston_output become uninitialized, i.e. should not be used |
| 6340 | * anymore. The caller can free the memory after this. |
| 6341 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6342 | * \ingroup ouput |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6343 | * \internal |
| 6344 | */ |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6345 | WL_EXPORT void |
Pekka Paalanen | ae6d35d | 2017-08-16 12:07:14 +0300 | [diff] [blame] | 6346 | weston_output_release(struct weston_output *output) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6347 | { |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 6348 | struct weston_head *head, *tmp; |
| 6349 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6350 | output->destroying = 1; |
| 6351 | |
Pekka Paalanen | 37b7c6e | 2017-11-07 10:15:01 +0200 | [diff] [blame] | 6352 | wl_signal_emit(&output->user_destroy_signal, output); |
| 6353 | |
Pekka Paalanen | dcbcfc7 | 2017-10-26 14:33:59 +0300 | [diff] [blame] | 6354 | if (output->idle_repaint_source) |
| 6355 | wl_event_source_remove(output->idle_repaint_source); |
| 6356 | |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 6357 | if (output->enabled) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6358 | weston_compositor_remove_output(output); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6359 | |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 6360 | pixman_region32_fini(&output->region); |
| 6361 | pixman_region32_fini(&output->previous_damage); |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 6362 | wl_list_remove(&output->link); |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 6363 | |
| 6364 | wl_list_for_each_safe(head, tmp, &output->head_list, output_link) |
| 6365 | weston_head_detach(head); |
| 6366 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6367 | free(output->name); |
| 6368 | } |
| 6369 | |
Pekka Paalanen | 1ae9d08 | 2017-11-02 14:11:53 +0200 | [diff] [blame] | 6370 | /** Find an output by its given name |
| 6371 | * |
| 6372 | * \param compositor The compositor to search in. |
| 6373 | * \param name The output name to search for. |
| 6374 | * \return An existing output with the given name, or NULL if not found. |
| 6375 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 6376 | * \ingroup compositor |
Pekka Paalanen | 1ae9d08 | 2017-11-02 14:11:53 +0200 | [diff] [blame] | 6377 | */ |
| 6378 | WL_EXPORT struct weston_output * |
| 6379 | weston_compositor_find_output_by_name(struct weston_compositor *compositor, |
| 6380 | const char *name) |
| 6381 | { |
| 6382 | struct weston_output *output; |
| 6383 | |
| 6384 | wl_list_for_each(output, &compositor->output_list, link) |
| 6385 | if (strcmp(output->name, name) == 0) |
| 6386 | return output; |
| 6387 | |
| 6388 | wl_list_for_each(output, &compositor->pending_output_list, link) |
| 6389 | if (strcmp(output->name, name) == 0) |
| 6390 | return output; |
| 6391 | |
| 6392 | return NULL; |
| 6393 | } |
| 6394 | |
| 6395 | /** Create a named output |
| 6396 | * |
| 6397 | * \param compositor The compositor. |
| 6398 | * \param name The name for the output. |
| 6399 | * \return A new \c weston_output, or NULL on failure. |
| 6400 | * |
| 6401 | * This creates a new weston_output that starts with no heads attached. |
| 6402 | * |
| 6403 | * An output must be configured and it must have at least one head before |
| 6404 | * it can be enabled. |
| 6405 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 6406 | * \ingroup compositor |
Pekka Paalanen | 1ae9d08 | 2017-11-02 14:11:53 +0200 | [diff] [blame] | 6407 | */ |
| 6408 | WL_EXPORT struct weston_output * |
| 6409 | weston_compositor_create_output(struct weston_compositor *compositor, |
| 6410 | const char *name) |
| 6411 | { |
| 6412 | assert(compositor->backend->create_output); |
| 6413 | |
| 6414 | if (weston_compositor_find_output_by_name(compositor, name)) { |
| 6415 | weston_log("Warning: attempted to create an output with a " |
| 6416 | "duplicate name '%s'.\n", name); |
| 6417 | return NULL; |
| 6418 | } |
| 6419 | |
| 6420 | return compositor->backend->create_output(compositor, name); |
| 6421 | } |
| 6422 | |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 6423 | /** Create an output for an unused head |
| 6424 | * |
| 6425 | * \param compositor The compositor. |
| 6426 | * \param head The head to attach to the output. |
| 6427 | * \return A new \c weston_output, or NULL on failure. |
| 6428 | * |
| 6429 | * This creates a new weston_output that starts with the given head attached. |
| 6430 | * The output inherits the name of the head. The head must not be already |
| 6431 | * attached to another output. |
| 6432 | * |
| 6433 | * An output must be configured before it can be enabled. |
| 6434 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 6435 | * \ingroup compositor |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 6436 | */ |
| 6437 | WL_EXPORT struct weston_output * |
| 6438 | weston_compositor_create_output_with_head(struct weston_compositor *compositor, |
| 6439 | struct weston_head *head) |
| 6440 | { |
| 6441 | struct weston_output *output; |
| 6442 | |
Pekka Paalanen | 1ae9d08 | 2017-11-02 14:11:53 +0200 | [diff] [blame] | 6443 | output = weston_compositor_create_output(compositor, head->name); |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 6444 | if (!output) |
| 6445 | return NULL; |
| 6446 | |
| 6447 | if (weston_output_attach_head(output, head) < 0) { |
Pekka Paalanen | 42c0e14 | 2017-10-27 12:07:49 +0300 | [diff] [blame] | 6448 | weston_output_destroy(output); |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 6449 | return NULL; |
| 6450 | } |
| 6451 | |
| 6452 | return output; |
| 6453 | } |
| 6454 | |
| 6455 | /** Destroy an output |
| 6456 | * |
| 6457 | * \param output The output to destroy. |
| 6458 | * |
| 6459 | * The heads attached to the given output are detached and become unused again. |
| 6460 | * |
| 6461 | * It is not necessary to explicitly destroy all outputs at compositor exit. |
| 6462 | * weston_compositor_destroy() will automatically destroy any remaining |
| 6463 | * outputs. |
| 6464 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6465 | * \ingroup ouput |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 6466 | */ |
| 6467 | WL_EXPORT void |
| 6468 | weston_output_destroy(struct weston_output *output) |
| 6469 | { |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 6470 | output->destroy(output); |
| 6471 | } |
| 6472 | |
Pekka Paalanen | cf0a476 | 2017-04-04 16:36:07 +0300 | [diff] [blame] | 6473 | /** When you need a head... |
| 6474 | * |
| 6475 | * This function is a hack, used until all code has been converted to become |
| 6476 | * multi-head aware. |
| 6477 | * |
| 6478 | * \param output The weston_output whose head to get. |
| 6479 | * \return The first head in the output's list. |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6480 | * |
| 6481 | * \ingroup ouput |
Pekka Paalanen | cf0a476 | 2017-04-04 16:36:07 +0300 | [diff] [blame] | 6482 | */ |
| 6483 | WL_EXPORT struct weston_head * |
| 6484 | weston_output_get_first_head(struct weston_output *output) |
| 6485 | { |
| 6486 | if (wl_list_empty(&output->head_list)) |
| 6487 | return NULL; |
| 6488 | |
| 6489 | return container_of(output->head_list.next, |
| 6490 | struct weston_head, output_link); |
| 6491 | } |
| 6492 | |
Ankit Nautiyal | 2844f8e | 2019-04-03 10:14:59 +0530 | [diff] [blame^] | 6493 | /** Allow/Disallow content-protection support for an output |
| 6494 | * |
| 6495 | * This function sets the allow_protection member for an output. Setting of |
| 6496 | * this field will allow the compositor to attempt content-protection for this |
| 6497 | * output, for a backend that supports the content-protection protocol. |
| 6498 | * |
| 6499 | * \param output The weston_output for whom the content-protection is to be |
| 6500 | * allowed. |
| 6501 | * \param allow_protection The bool value which is to be set. |
| 6502 | */ |
| 6503 | WL_EXPORT void |
| 6504 | weston_output_allow_protection(struct weston_output *output, |
| 6505 | bool allow_protection) |
| 6506 | { |
| 6507 | output->allow_protection = allow_protection; |
| 6508 | } |
| 6509 | |
Benjamin Franzke | 315b3dc | 2011-03-08 11:32:57 +0100 | [diff] [blame] | 6510 | static void |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 6511 | xdg_output_unlist(struct wl_resource *resource) |
| 6512 | { |
| 6513 | wl_list_remove(wl_resource_get_link(resource)); |
| 6514 | } |
| 6515 | |
| 6516 | static void |
| 6517 | xdg_output_destroy(struct wl_client *client, struct wl_resource *resource) |
| 6518 | { |
| 6519 | wl_resource_destroy(resource); |
| 6520 | } |
| 6521 | |
| 6522 | static const struct zxdg_output_v1_interface xdg_output_interface = { |
| 6523 | xdg_output_destroy |
| 6524 | }; |
| 6525 | |
| 6526 | static void |
| 6527 | xdg_output_manager_destroy(struct wl_client *client, |
| 6528 | struct wl_resource *resource) |
| 6529 | { |
| 6530 | wl_resource_destroy(resource); |
| 6531 | } |
| 6532 | |
| 6533 | static void |
| 6534 | xdg_output_manager_get_xdg_output(struct wl_client *client, |
| 6535 | struct wl_resource *manager, |
| 6536 | uint32_t id, |
| 6537 | struct wl_resource *output_resource) |
| 6538 | { |
| 6539 | int version = wl_resource_get_version(manager); |
| 6540 | struct weston_head *head = wl_resource_get_user_data(output_resource); |
| 6541 | struct weston_output *output = head->output; |
| 6542 | struct wl_resource *resource; |
| 6543 | |
| 6544 | resource = wl_resource_create(client, &zxdg_output_v1_interface, |
| 6545 | version, id); |
| 6546 | if (resource == NULL) { |
| 6547 | wl_client_post_no_memory(client); |
| 6548 | return; |
| 6549 | } |
| 6550 | |
| 6551 | wl_list_insert(&head->xdg_output_resource_list, |
| 6552 | wl_resource_get_link(resource)); |
| 6553 | |
| 6554 | wl_resource_set_implementation(resource, &xdg_output_interface, |
| 6555 | NULL, xdg_output_unlist); |
| 6556 | |
| 6557 | zxdg_output_v1_send_logical_position(resource, output->x, output->y); |
| 6558 | zxdg_output_v1_send_logical_size(resource, |
| 6559 | output->width, |
| 6560 | output->height); |
| 6561 | if (version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION) |
| 6562 | zxdg_output_v1_send_name(resource, head->name); |
| 6563 | |
| 6564 | zxdg_output_v1_send_done(resource); |
| 6565 | } |
| 6566 | |
| 6567 | static const struct zxdg_output_manager_v1_interface xdg_output_manager_interface = { |
| 6568 | xdg_output_manager_destroy, |
| 6569 | xdg_output_manager_get_xdg_output |
| 6570 | }; |
| 6571 | |
| 6572 | static void |
| 6573 | bind_xdg_output_manager(struct wl_client *client, |
| 6574 | void *data, uint32_t version, uint32_t id) |
| 6575 | { |
| 6576 | struct wl_resource *resource; |
| 6577 | |
| 6578 | resource = wl_resource_create(client, &zxdg_output_manager_v1_interface, |
| 6579 | version, id); |
| 6580 | if (resource == NULL) { |
| 6581 | wl_client_post_no_memory(client); |
| 6582 | return; |
| 6583 | } |
| 6584 | |
| 6585 | wl_resource_set_implementation(resource, &xdg_output_manager_interface, |
| 6586 | NULL, NULL); |
| 6587 | } |
| 6588 | |
| 6589 | static void |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6590 | destroy_viewport(struct wl_resource *resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6591 | { |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 6592 | struct weston_surface *surface = |
| 6593 | wl_resource_get_user_data(resource); |
| 6594 | |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 6595 | if (!surface) |
| 6596 | return; |
| 6597 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6598 | surface->viewport_resource = NULL; |
Pekka Paalanen | f0cad48 | 2014-03-14 14:38:16 +0200 | [diff] [blame] | 6599 | surface->pending.buffer_viewport.buffer.src_width = |
| 6600 | wl_fixed_from_int(-1); |
| 6601 | surface->pending.buffer_viewport.surface.width = -1; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 6602 | surface->pending.buffer_viewport.changed = 1; |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6603 | } |
| 6604 | |
| 6605 | static void |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6606 | viewport_destroy(struct wl_client *client, |
| 6607 | struct wl_resource *resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6608 | { |
| 6609 | wl_resource_destroy(resource); |
| 6610 | } |
| 6611 | |
| 6612 | static void |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6613 | viewport_set_source(struct wl_client *client, |
| 6614 | struct wl_resource *resource, |
| 6615 | wl_fixed_t src_x, |
| 6616 | wl_fixed_t src_y, |
| 6617 | wl_fixed_t src_width, |
| 6618 | wl_fixed_t src_height) |
| 6619 | { |
| 6620 | struct weston_surface *surface = |
| 6621 | wl_resource_get_user_data(resource); |
| 6622 | |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 6623 | if (!surface) { |
| 6624 | wl_resource_post_error(resource, |
| 6625 | WP_VIEWPORT_ERROR_NO_SURFACE, |
| 6626 | "wl_surface for this viewport is no longer exists"); |
| 6627 | return; |
| 6628 | } |
| 6629 | |
| 6630 | assert(surface->viewport_resource == resource); |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 6631 | assert(surface->resource); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6632 | |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6633 | if (src_width == wl_fixed_from_int(-1) && |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 6634 | src_height == wl_fixed_from_int(-1) && |
| 6635 | src_x == wl_fixed_from_int(-1) && |
| 6636 | src_y == wl_fixed_from_int(-1)) { |
| 6637 | /* unset source rect */ |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6638 | surface->pending.buffer_viewport.buffer.src_width = |
| 6639 | wl_fixed_from_int(-1); |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 6640 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6641 | return; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6642 | } |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6643 | |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 6644 | if (src_width <= 0 || src_height <= 0 || src_x < 0 || src_y < 0) { |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6645 | wl_resource_post_error(resource, |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 6646 | WP_VIEWPORT_ERROR_BAD_VALUE, |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 6647 | "wl_surface@%d viewport source " |
| 6648 | "w=%f <= 0, h=%f <= 0, x=%f < 0, or y=%f < 0", |
| 6649 | wl_resource_get_id(surface->resource), |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6650 | wl_fixed_to_double(src_width), |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 6651 | wl_fixed_to_double(src_height), |
| 6652 | wl_fixed_to_double(src_x), |
| 6653 | wl_fixed_to_double(src_y)); |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6654 | return; |
| 6655 | } |
| 6656 | |
| 6657 | surface->pending.buffer_viewport.buffer.src_x = src_x; |
| 6658 | surface->pending.buffer_viewport.buffer.src_y = src_y; |
| 6659 | surface->pending.buffer_viewport.buffer.src_width = src_width; |
| 6660 | surface->pending.buffer_viewport.buffer.src_height = src_height; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 6661 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6662 | } |
| 6663 | |
| 6664 | static void |
| 6665 | viewport_set_destination(struct wl_client *client, |
| 6666 | struct wl_resource *resource, |
| 6667 | int32_t dst_width, |
| 6668 | int32_t dst_height) |
| 6669 | { |
| 6670 | struct weston_surface *surface = |
| 6671 | wl_resource_get_user_data(resource); |
| 6672 | |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 6673 | if (!surface) { |
| 6674 | wl_resource_post_error(resource, |
| 6675 | WP_VIEWPORT_ERROR_NO_SURFACE, |
| 6676 | "wl_surface for this viewport no longer exists"); |
| 6677 | return; |
| 6678 | } |
| 6679 | |
| 6680 | assert(surface->viewport_resource == resource); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6681 | |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6682 | if (dst_width == -1 && dst_height == -1) { |
| 6683 | /* unset destination size */ |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6684 | surface->pending.buffer_viewport.surface.width = -1; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 6685 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6686 | return; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6687 | } |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6688 | |
| 6689 | if (dst_width <= 0 || dst_height <= 0) { |
| 6690 | wl_resource_post_error(resource, |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 6691 | WP_VIEWPORT_ERROR_BAD_VALUE, |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6692 | "destination size must be positive (%dx%d)", |
| 6693 | dst_width, dst_height); |
| 6694 | return; |
| 6695 | } |
| 6696 | |
| 6697 | surface->pending.buffer_viewport.surface.width = dst_width; |
| 6698 | surface->pending.buffer_viewport.surface.height = dst_height; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 6699 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6700 | } |
| 6701 | |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 6702 | static const struct wp_viewport_interface viewport_interface = { |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6703 | viewport_destroy, |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6704 | viewport_set_source, |
| 6705 | viewport_set_destination |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6706 | }; |
| 6707 | |
| 6708 | static void |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6709 | viewporter_destroy(struct wl_client *client, |
| 6710 | struct wl_resource *resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6711 | { |
| 6712 | wl_resource_destroy(resource); |
| 6713 | } |
| 6714 | |
| 6715 | static void |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6716 | viewporter_get_viewport(struct wl_client *client, |
| 6717 | struct wl_resource *viewporter, |
| 6718 | uint32_t id, |
| 6719 | struct wl_resource *surface_resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6720 | { |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6721 | int version = wl_resource_get_version(viewporter); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6722 | struct weston_surface *surface = |
| 6723 | wl_resource_get_user_data(surface_resource); |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6724 | struct wl_resource *resource; |
| 6725 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6726 | if (surface->viewport_resource) { |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6727 | wl_resource_post_error(viewporter, |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 6728 | WP_VIEWPORTER_ERROR_VIEWPORT_EXISTS, |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6729 | "a viewport for that surface already exists"); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 6730 | return; |
| 6731 | } |
| 6732 | |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 6733 | resource = wl_resource_create(client, &wp_viewport_interface, |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6734 | version, id); |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6735 | if (resource == NULL) { |
| 6736 | wl_client_post_no_memory(client); |
| 6737 | return; |
| 6738 | } |
| 6739 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6740 | wl_resource_set_implementation(resource, &viewport_interface, |
| 6741 | surface, destroy_viewport); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 6742 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6743 | surface->viewport_resource = resource; |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6744 | } |
| 6745 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6746 | static const struct wp_viewporter_interface viewporter_interface = { |
| 6747 | viewporter_destroy, |
| 6748 | viewporter_get_viewport |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6749 | }; |
| 6750 | |
| 6751 | static void |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6752 | bind_viewporter(struct wl_client *client, |
| 6753 | void *data, uint32_t version, uint32_t id) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6754 | { |
| 6755 | struct wl_resource *resource; |
| 6756 | |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 6757 | resource = wl_resource_create(client, &wp_viewporter_interface, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 6758 | version, id); |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6759 | if (resource == NULL) { |
| 6760 | wl_client_post_no_memory(client); |
| 6761 | return; |
| 6762 | } |
| 6763 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6764 | wl_resource_set_implementation(resource, &viewporter_interface, |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6765 | NULL, NULL); |
| 6766 | } |
| 6767 | |
| 6768 | static void |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 6769 | destroy_presentation_feedback(struct wl_resource *feedback_resource) |
| 6770 | { |
| 6771 | struct weston_presentation_feedback *feedback; |
| 6772 | |
| 6773 | feedback = wl_resource_get_user_data(feedback_resource); |
| 6774 | |
| 6775 | wl_list_remove(&feedback->link); |
| 6776 | free(feedback); |
| 6777 | } |
| 6778 | |
| 6779 | static void |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 6780 | presentation_destroy(struct wl_client *client, struct wl_resource *resource) |
| 6781 | { |
| 6782 | wl_resource_destroy(resource); |
| 6783 | } |
| 6784 | |
| 6785 | static void |
| 6786 | presentation_feedback(struct wl_client *client, |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 6787 | struct wl_resource *presentation_resource, |
| 6788 | struct wl_resource *surface_resource, |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 6789 | uint32_t callback) |
| 6790 | { |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 6791 | struct weston_surface *surface; |
| 6792 | struct weston_presentation_feedback *feedback; |
| 6793 | |
| 6794 | surface = wl_resource_get_user_data(surface_resource); |
| 6795 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 6796 | feedback = zalloc(sizeof *feedback); |
| 6797 | if (feedback == NULL) |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 6798 | goto err_calloc; |
| 6799 | |
| 6800 | feedback->resource = wl_resource_create(client, |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 6801 | &wp_presentation_feedback_interface, |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 6802 | 1, callback); |
| 6803 | if (!feedback->resource) |
| 6804 | goto err_create; |
| 6805 | |
| 6806 | wl_resource_set_implementation(feedback->resource, NULL, feedback, |
| 6807 | destroy_presentation_feedback); |
| 6808 | |
| 6809 | wl_list_insert(&surface->pending.feedback_list, &feedback->link); |
| 6810 | |
| 6811 | return; |
| 6812 | |
| 6813 | err_create: |
| 6814 | free(feedback); |
| 6815 | |
| 6816 | err_calloc: |
| 6817 | wl_client_post_no_memory(client); |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 6818 | } |
| 6819 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 6820 | static const struct wp_presentation_interface presentation_implementation = { |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 6821 | presentation_destroy, |
| 6822 | presentation_feedback |
| 6823 | }; |
| 6824 | |
| 6825 | static void |
| 6826 | bind_presentation(struct wl_client *client, |
| 6827 | void *data, uint32_t version, uint32_t id) |
| 6828 | { |
| 6829 | struct weston_compositor *compositor = data; |
| 6830 | struct wl_resource *resource; |
| 6831 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 6832 | resource = wl_resource_create(client, &wp_presentation_interface, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 6833 | version, id); |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 6834 | if (resource == NULL) { |
| 6835 | wl_client_post_no_memory(client); |
| 6836 | return; |
| 6837 | } |
| 6838 | |
| 6839 | wl_resource_set_implementation(resource, &presentation_implementation, |
| 6840 | compositor, NULL); |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 6841 | wp_presentation_send_clock_id(resource, compositor->presentation_clock); |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 6842 | } |
| 6843 | |
| 6844 | static void |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 6845 | compositor_bind(struct wl_client *client, |
| 6846 | void *data, uint32_t version, uint32_t id) |
| 6847 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 6848 | struct weston_compositor *compositor = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 6849 | struct wl_resource *resource; |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 6850 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 6851 | resource = wl_resource_create(client, &wl_compositor_interface, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 6852 | version, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 6853 | if (resource == NULL) { |
| 6854 | wl_client_post_no_memory(client); |
| 6855 | return; |
| 6856 | } |
| 6857 | |
| 6858 | wl_resource_set_implementation(resource, &compositor_interface, |
| 6859 | compositor, NULL); |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 6860 | } |
| 6861 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6862 | WL_EXPORT int |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 6863 | weston_environment_get_fd(const char *env) |
| 6864 | { |
Bryce Harrington | 25a2bdd | 2016-08-03 17:40:52 -0700 | [diff] [blame] | 6865 | char *e; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 6866 | int fd, flags; |
| 6867 | |
| 6868 | e = getenv(env); |
Bryce Harrington | 25a2bdd | 2016-08-03 17:40:52 -0700 | [diff] [blame] | 6869 | if (!e || !safe_strtoint(e, &fd)) |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 6870 | return -1; |
| 6871 | |
| 6872 | flags = fcntl(fd, F_GETFD); |
| 6873 | if (flags == -1) |
| 6874 | return -1; |
| 6875 | |
| 6876 | fcntl(fd, F_SETFD, flags | FD_CLOEXEC); |
| 6877 | unsetenv(env); |
| 6878 | |
| 6879 | return fd; |
| 6880 | } |
| 6881 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 6882 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 6883 | timeline_key_binding_handler(struct weston_keyboard *keyboard, |
| 6884 | const struct timespec *time, uint32_t key, |
| 6885 | void *data) |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 6886 | { |
| 6887 | struct weston_compositor *compositor = data; |
| 6888 | |
| 6889 | if (weston_timeline_enabled_) |
| 6890 | weston_timeline_close(); |
| 6891 | else |
| 6892 | weston_timeline_open(compositor); |
| 6893 | } |
| 6894 | |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6895 | static const char * |
| 6896 | output_repaint_status_text(struct weston_output *output) |
| 6897 | { |
| 6898 | switch (output->repaint_status) { |
| 6899 | case REPAINT_NOT_SCHEDULED: |
| 6900 | return "no repaint"; |
| 6901 | case REPAINT_BEGIN_FROM_IDLE: |
| 6902 | return "start_repaint_loop scheduled"; |
| 6903 | case REPAINT_SCHEDULED: |
| 6904 | return "repaint scheduled"; |
| 6905 | case REPAINT_AWAITING_COMPLETION: |
| 6906 | return "awaiting completion"; |
| 6907 | } |
| 6908 | |
| 6909 | assert(!"output_repaint_status_text missing enum"); |
| 6910 | return NULL; |
| 6911 | } |
| 6912 | |
| 6913 | static void |
| 6914 | debug_scene_view_print_buffer(FILE *fp, struct weston_view *view) |
| 6915 | { |
| 6916 | struct weston_buffer *buffer = view->surface->buffer_ref.buffer; |
| 6917 | struct wl_shm_buffer *shm; |
| 6918 | struct linux_dmabuf_buffer *dmabuf; |
Marius Vlad | 00a6e01 | 2018-11-20 17:52:31 +0200 | [diff] [blame] | 6919 | const struct pixel_format_info *pixel_info = NULL; |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6920 | |
| 6921 | if (!buffer) { |
| 6922 | fprintf(fp, "\t\t[buffer not available]\n"); |
| 6923 | return; |
| 6924 | } |
| 6925 | |
| 6926 | shm = wl_shm_buffer_get(buffer->resource); |
| 6927 | if (shm) { |
Marius Vlad | 00a6e01 | 2018-11-20 17:52:31 +0200 | [diff] [blame] | 6928 | uint32_t _format = wl_shm_buffer_get_format(shm); |
| 6929 | pixel_info = pixel_format_get_info_shm(_format); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6930 | fprintf(fp, "\t\tSHM buffer\n"); |
Marius Vlad | 00a6e01 | 2018-11-20 17:52:31 +0200 | [diff] [blame] | 6931 | fprintf(fp, "\t\t\tformat: 0x%lx %s\n", |
| 6932 | (unsigned long) _format, |
| 6933 | pixel_info ? pixel_info->drm_format_name : "UNKNOWN"); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6934 | return; |
| 6935 | } |
| 6936 | |
| 6937 | dmabuf = linux_dmabuf_buffer_get(buffer->resource); |
| 6938 | if (dmabuf) { |
Marius Vlad | 00a6e01 | 2018-11-20 17:52:31 +0200 | [diff] [blame] | 6939 | pixel_info = pixel_format_get_info(dmabuf->attributes.format); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6940 | fprintf(fp, "\t\tdmabuf buffer\n"); |
Marius Vlad | 00a6e01 | 2018-11-20 17:52:31 +0200 | [diff] [blame] | 6941 | fprintf(fp, "\t\t\tformat: 0x%lx %s\n", |
| 6942 | (unsigned long) dmabuf->attributes.format, |
| 6943 | pixel_info ? pixel_info->drm_format_name : "UNKNOWN"); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6944 | fprintf(fp, "\t\t\tmodifier: 0x%llx\n", |
| 6945 | (unsigned long long) dmabuf->attributes.modifier[0]); |
| 6946 | return; |
| 6947 | } |
| 6948 | |
Marius Vlad | 253ba9a | 2019-03-17 18:22:21 +0200 | [diff] [blame] | 6949 | fprintf(fp, "\t\tEGL buffer\n"); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6950 | } |
| 6951 | |
| 6952 | static void |
| 6953 | debug_scene_view_print(FILE *fp, struct weston_view *view, int view_idx) |
| 6954 | { |
| 6955 | struct weston_compositor *ec = view->surface->compositor; |
| 6956 | struct weston_output *output; |
| 6957 | char desc[512]; |
| 6958 | pixman_box32_t *box; |
| 6959 | uint32_t surface_id = 0; |
| 6960 | pid_t pid = 0; |
| 6961 | |
| 6962 | if (view->surface->resource) { |
| 6963 | struct wl_resource *resource = view->surface->resource; |
| 6964 | wl_client_get_credentials(wl_resource_get_client(resource), |
| 6965 | &pid, NULL, NULL); |
| 6966 | surface_id = wl_resource_get_id(view->surface->resource); |
| 6967 | } |
| 6968 | |
| 6969 | if (!view->surface->get_label || |
| 6970 | view->surface->get_label(view->surface, desc, sizeof(desc)) < 0) { |
| 6971 | strcpy(desc, "[no description available]"); |
| 6972 | } |
| 6973 | fprintf(fp, "\tView %d (role %s, PID %d, surface ID %u, %s, %p):\n", |
| 6974 | view_idx, view->surface->role_name, pid, surface_id, |
| 6975 | desc, view); |
| 6976 | |
| 6977 | box = pixman_region32_extents(&view->transform.boundingbox); |
| 6978 | fprintf(fp, "\t\tposition: (%d, %d) -> (%d, %d)\n", |
| 6979 | box->x1, box->y1, box->x2, box->y2); |
| 6980 | box = pixman_region32_extents(&view->transform.opaque); |
| 6981 | |
| 6982 | if (pixman_region32_equal(&view->transform.opaque, |
| 6983 | &view->transform.boundingbox)) { |
| 6984 | fprintf(fp, "\t\t[fully opaque]\n"); |
| 6985 | } else if (!pixman_region32_not_empty(&view->transform.opaque)) { |
| 6986 | fprintf(fp, "\t\t[not opaque]\n"); |
| 6987 | } else { |
| 6988 | fprintf(fp, "\t\t[opaque: (%d, %d) -> (%d, %d)]\n", |
| 6989 | box->x1, box->y1, box->x2, box->y2); |
| 6990 | } |
| 6991 | |
| 6992 | if (view->alpha < 1.0) |
| 6993 | fprintf(fp, "\t\talpha: %f\n", view->alpha); |
| 6994 | |
| 6995 | if (view->output_mask != 0) { |
| 6996 | bool first_output = true; |
| 6997 | fprintf(fp, "\t\toutputs: "); |
| 6998 | wl_list_for_each(output, &ec->output_list, link) { |
| 6999 | if (!(view->output_mask & (1 << output->id))) |
| 7000 | continue; |
| 7001 | fprintf(fp, "%s%d (%s)%s", |
| 7002 | (first_output) ? "" : ", ", |
| 7003 | output->id, output->name, |
| 7004 | (view->output == output) ? " (primary)" : ""); |
| 7005 | first_output = false; |
| 7006 | } |
| 7007 | } else { |
| 7008 | fprintf(fp, "\t\t[no outputs]"); |
| 7009 | } |
| 7010 | |
| 7011 | fprintf(fp, "\n"); |
| 7012 | |
| 7013 | debug_scene_view_print_buffer(fp, view); |
| 7014 | } |
| 7015 | |
Marius Vlad | 433f4e7 | 2019-02-17 22:14:23 +0200 | [diff] [blame] | 7016 | static void |
| 7017 | debug_scene_view_print_tree(struct weston_view *view, |
Marius Vlad | a6acfa8 | 2019-03-17 18:10:09 +0200 | [diff] [blame] | 7018 | FILE *fp, int *view_idx) |
Marius Vlad | 433f4e7 | 2019-02-17 22:14:23 +0200 | [diff] [blame] | 7019 | { |
| 7020 | struct weston_subsurface *sub; |
| 7021 | struct weston_view *ev; |
| 7022 | |
| 7023 | /* |
| 7024 | * print the view first, then we recursively go on printing |
| 7025 | * sub-surfaces. We bail out once no more sub-surfaces are available. |
| 7026 | */ |
Marius Vlad | a6acfa8 | 2019-03-17 18:10:09 +0200 | [diff] [blame] | 7027 | debug_scene_view_print(fp, view, *view_idx); |
Marius Vlad | 433f4e7 | 2019-02-17 22:14:23 +0200 | [diff] [blame] | 7028 | |
| 7029 | /* no more sub-surfaces */ |
| 7030 | if (wl_list_empty(&view->surface->subsurface_list)) |
| 7031 | return; |
| 7032 | |
| 7033 | wl_list_for_each(sub, &view->surface->subsurface_list, parent_link) { |
| 7034 | wl_list_for_each(ev, &sub->surface->views, surface_link) { |
| 7035 | /* do not print again the parent view */ |
| 7036 | if (view == ev) |
| 7037 | continue; |
Marius Vlad | a6acfa8 | 2019-03-17 18:10:09 +0200 | [diff] [blame] | 7038 | |
| 7039 | (*view_idx)++; |
Marius Vlad | 433f4e7 | 2019-02-17 22:14:23 +0200 | [diff] [blame] | 7040 | debug_scene_view_print_tree(ev, fp, view_idx); |
| 7041 | } |
| 7042 | } |
| 7043 | } |
| 7044 | |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7045 | /** |
| 7046 | * Output information on how libweston is currently composing the scene |
| 7047 | * graph. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7048 | * |
| 7049 | * \ingroup compositor |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7050 | */ |
| 7051 | WL_EXPORT char * |
| 7052 | weston_compositor_print_scene_graph(struct weston_compositor *ec) |
| 7053 | { |
| 7054 | struct weston_output *output; |
| 7055 | struct weston_layer *layer; |
| 7056 | struct timespec now; |
| 7057 | int layer_idx = 0; |
| 7058 | FILE *fp; |
| 7059 | char *ret; |
| 7060 | size_t len; |
| 7061 | int err; |
| 7062 | |
| 7063 | fp = open_memstream(&ret, &len); |
| 7064 | assert(fp); |
| 7065 | |
| 7066 | weston_compositor_read_presentation_clock(ec, &now); |
| 7067 | fprintf(fp, "Weston scene graph at %ld.%09ld:\n\n", |
| 7068 | now.tv_sec, now.tv_nsec); |
| 7069 | |
| 7070 | wl_list_for_each(output, &ec->output_list, link) { |
| 7071 | struct weston_head *head; |
| 7072 | int head_idx = 0; |
| 7073 | |
| 7074 | fprintf(fp, "Output %d (%s):\n", output->id, output->name); |
| 7075 | assert(output->enabled); |
| 7076 | |
| 7077 | fprintf(fp, "\tposition: (%d, %d) -> (%d, %d)\n", |
| 7078 | output->x, output->y, |
| 7079 | output->x + output->width, |
| 7080 | output->y + output->height); |
| 7081 | fprintf(fp, "\tmode: %dx%d@%.3fHz\n", |
| 7082 | output->current_mode->width, |
| 7083 | output->current_mode->height, |
| 7084 | output->current_mode->refresh / 1000.0); |
| 7085 | fprintf(fp, "\tscale: %d\n", output->scale); |
| 7086 | |
| 7087 | fprintf(fp, "\trepaint status: %s\n", |
| 7088 | output_repaint_status_text(output)); |
| 7089 | if (output->repaint_status == REPAINT_SCHEDULED) |
| 7090 | fprintf(fp, "\tnext repaint: %ld.%09ld\n", |
| 7091 | output->next_repaint.tv_sec, |
| 7092 | output->next_repaint.tv_nsec); |
| 7093 | |
| 7094 | wl_list_for_each(head, &output->head_list, output_link) { |
| 7095 | fprintf(fp, "\tHead %d (%s): %sconnected\n", |
| 7096 | head_idx++, head->name, |
| 7097 | (head->connected) ? "" : "not "); |
| 7098 | } |
| 7099 | } |
| 7100 | |
| 7101 | fprintf(fp, "\n"); |
| 7102 | |
| 7103 | wl_list_for_each(layer, &ec->layer_list, link) { |
| 7104 | struct weston_view *view; |
| 7105 | int view_idx = 0; |
| 7106 | |
| 7107 | fprintf(fp, "Layer %d (pos 0x%lx):\n", layer_idx++, |
| 7108 | (unsigned long) layer->position); |
| 7109 | |
| 7110 | if (!weston_layer_mask_is_infinite(layer)) { |
| 7111 | fprintf(fp, "\t[mask: (%d, %d) -> (%d,%d)]\n\n", |
| 7112 | layer->mask.x1, layer->mask.y1, |
| 7113 | layer->mask.x2, layer->mask.y2); |
| 7114 | } |
| 7115 | |
Marius Vlad | a6acfa8 | 2019-03-17 18:10:09 +0200 | [diff] [blame] | 7116 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
| 7117 | debug_scene_view_print_tree(view, fp, &view_idx); |
| 7118 | view_idx++; |
| 7119 | } |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7120 | |
| 7121 | if (wl_list_empty(&layer->view_list.link)) |
| 7122 | fprintf(fp, "\t[no views]\n"); |
| 7123 | |
| 7124 | fprintf(fp, "\n"); |
| 7125 | } |
| 7126 | |
| 7127 | err = fclose(fp); |
| 7128 | assert(err == 0); |
| 7129 | |
| 7130 | return ret; |
| 7131 | } |
| 7132 | |
| 7133 | /** |
| 7134 | * Called when the 'scene-graph' debug scope is bound by a client. This |
| 7135 | * one-shot weston-debug scope prints the current scene graph when bound, |
| 7136 | * and then terminates the stream. |
| 7137 | */ |
| 7138 | static void |
| 7139 | debug_scene_graph_cb(struct weston_debug_stream *stream, void *data) |
| 7140 | { |
| 7141 | struct weston_compositor *ec = data; |
| 7142 | char *str = weston_compositor_print_scene_graph(ec); |
| 7143 | |
| 7144 | weston_debug_stream_printf(stream, "%s", str); |
| 7145 | free(str); |
| 7146 | weston_debug_stream_complete(stream); |
| 7147 | } |
| 7148 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7149 | /** Create the compositor. |
| 7150 | * |
| 7151 | * This functions creates and initializes a compositor instance. |
| 7152 | * |
| 7153 | * \param display The Wayland display to be used. |
| 7154 | * \param user_data A pointer to an object that can later be retrieved |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 7155 | * \param log_ctx A pointer to weston_debug_compositor |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7156 | * using the \ref weston_compositor_get_user_data function. |
| 7157 | * \return The compositor instance on success or NULL on failure. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7158 | * |
| 7159 | * \ingroup compositor |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7160 | */ |
| 7161 | WL_EXPORT struct weston_compositor * |
Marius Vlad | 880b485 | 2019-04-07 17:07:58 +0300 | [diff] [blame] | 7162 | weston_compositor_create(struct wl_display *display, |
Marius Vlad | 3d7d978 | 2019-04-17 12:35:38 +0300 | [diff] [blame] | 7163 | struct weston_log_context *log_ctx, |
Marius Vlad | 880b485 | 2019-04-07 17:07:58 +0300 | [diff] [blame] | 7164 | void *user_data) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 7165 | { |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7166 | struct weston_compositor *ec; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 7167 | struct wl_event_loop *loop; |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 7168 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7169 | ec = zalloc(sizeof *ec); |
| 7170 | if (!ec) |
| 7171 | return NULL; |
| 7172 | |
| 7173 | ec->wl_display = display; |
| 7174 | ec->user_data = user_data; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 7175 | wl_signal_init(&ec->destroy_signal); |
Kristian Høgsberg | f03a04a | 2014-04-06 22:04:50 -0700 | [diff] [blame] | 7176 | wl_signal_init(&ec->create_surface_signal); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 7177 | wl_signal_init(&ec->activate_signal); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 7178 | wl_signal_init(&ec->transform_signal); |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 7179 | wl_signal_init(&ec->kill_signal); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 7180 | wl_signal_init(&ec->idle_signal); |
| 7181 | wl_signal_init(&ec->wake_signal); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 7182 | wl_signal_init(&ec->show_input_panel_signal); |
| 7183 | wl_signal_init(&ec->hide_input_panel_signal); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 7184 | wl_signal_init(&ec->update_input_panel_signal); |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 7185 | wl_signal_init(&ec->seat_created_signal); |
Richard Hughes | 59d5da7 | 2013-05-01 21:52:11 +0100 | [diff] [blame] | 7186 | wl_signal_init(&ec->output_created_signal); |
Ander Conselvan de Oliveira | f84327a | 2014-01-29 18:47:51 +0200 | [diff] [blame] | 7187 | wl_signal_init(&ec->output_destroyed_signal); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 7188 | wl_signal_init(&ec->output_moved_signal); |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 7189 | wl_signal_init(&ec->output_resized_signal); |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 7190 | wl_signal_init(&ec->heads_changed_signal); |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 7191 | wl_signal_init(&ec->output_heads_changed_signal); |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 7192 | wl_signal_init(&ec->session_signal); |
| 7193 | ec->session_active = 1; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 7194 | |
Casey Dahlin | 58ba137 | 2012-04-19 22:50:08 -0400 | [diff] [blame] | 7195 | ec->output_id_pool = 0; |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 7196 | ec->repaint_msec = DEFAULT_REPAINT_WINDOW; |
Casey Dahlin | 58ba137 | 2012-04-19 22:50:08 -0400 | [diff] [blame] | 7197 | |
Jonas Ådahl | 94e2e2d | 2014-10-18 18:42:19 +0200 | [diff] [blame] | 7198 | ec->activate_serial = 1; |
| 7199 | |
Louis-Francis Ratté-Boulianne | c4689ff | 2017-11-28 20:42:47 -0500 | [diff] [blame] | 7200 | ec->touch_mode = WESTON_TOUCH_MODE_NORMAL; |
| 7201 | |
Ankit Nautiyal | 5cfe03c | 2019-03-28 15:05:42 +0530 | [diff] [blame] | 7202 | ec->content_protection = NULL; |
| 7203 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 7204 | if (!wl_global_create(ec->wl_display, &wl_compositor_interface, 4, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 7205 | ec, compositor_bind)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7206 | goto fail; |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 7207 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 7208 | if (!wl_global_create(ec->wl_display, &wl_subcompositor_interface, 1, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 7209 | ec, bind_subcompositor)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7210 | goto fail; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 7211 | |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 7212 | if (!wl_global_create(ec->wl_display, &wp_viewporter_interface, 1, |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 7213 | ec, bind_viewporter)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7214 | goto fail; |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 7215 | |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 7216 | if (!wl_global_create(ec->wl_display, &zxdg_output_manager_v1_interface, 2, |
| 7217 | ec, bind_xdg_output_manager)) |
| 7218 | goto fail; |
| 7219 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 7220 | if (!wl_global_create(ec->wl_display, &wp_presentation_interface, 1, |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 7221 | ec, bind_presentation)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7222 | goto fail; |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 7223 | |
Marius Vlad | 3d7d978 | 2019-04-17 12:35:38 +0300 | [diff] [blame] | 7224 | if (weston_log_ctx_compositor_setup(ec, log_ctx) < 0) |
Pekka Paalanen | a5630ea | 2017-10-12 13:13:42 +0200 | [diff] [blame] | 7225 | goto fail; |
| 7226 | |
Jonas Ådahl | 30d61d8 | 2014-10-22 21:21:17 +0200 | [diff] [blame] | 7227 | if (weston_input_init(ec) != 0) |
| 7228 | goto fail; |
| 7229 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 7230 | wl_list_init(&ec->view_list); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 7231 | wl_list_init(&ec->plane_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 7232 | wl_list_init(&ec->layer_list); |
| 7233 | wl_list_init(&ec->seat_list); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 7234 | wl_list_init(&ec->pending_output_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 7235 | wl_list_init(&ec->output_list); |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 7236 | wl_list_init(&ec->head_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 7237 | wl_list_init(&ec->key_binding_list); |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 7238 | wl_list_init(&ec->modifier_binding_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 7239 | wl_list_init(&ec->button_binding_list); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 7240 | wl_list_init(&ec->touch_binding_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 7241 | wl_list_init(&ec->axis_binding_list); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 7242 | wl_list_init(&ec->debug_binding_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 7243 | |
Pekka Paalanen | 827b5d2 | 2016-06-29 11:54:26 +0200 | [diff] [blame] | 7244 | wl_list_init(&ec->plugin_api_list); |
| 7245 | |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 7246 | weston_plane_init(&ec->primary_plane, ec, 0, 0); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 7247 | weston_compositor_stack_plane(ec, &ec->primary_plane, NULL); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 7248 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7249 | wl_data_device_manager_init(ec->wl_display); |
| 7250 | |
| 7251 | wl_display_init_shm(ec->wl_display); |
| 7252 | |
| 7253 | loop = wl_display_get_event_loop(ec->wl_display); |
| 7254 | ec->idle_source = wl_event_loop_add_timer(loop, idle_handler, ec); |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 7255 | ec->repaint_timer = |
| 7256 | wl_event_loop_add_timer(loop, output_repaint_timer_handler, |
| 7257 | ec); |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7258 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 7259 | weston_layer_init(&ec->fade_layer, ec); |
| 7260 | weston_layer_init(&ec->cursor_layer, ec); |
| 7261 | |
| 7262 | weston_layer_set_position(&ec->fade_layer, WESTON_LAYER_POSITION_FADE); |
| 7263 | weston_layer_set_position(&ec->cursor_layer, |
| 7264 | WESTON_LAYER_POSITION_CURSOR); |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7265 | |
| 7266 | weston_compositor_add_debug_binding(ec, KEY_T, |
| 7267 | timeline_key_binding_handler, ec); |
| 7268 | |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7269 | ec->debug_scene = |
Marius Vlad | 7e4db95 | 2019-04-17 13:47:06 +0300 | [diff] [blame] | 7270 | weston_compositor_add_log_scope(ec->weston_log_ctx, "scene-graph", |
| 7271 | "Scene graph details\n", |
| 7272 | debug_scene_graph_cb, |
| 7273 | ec); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7274 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7275 | return ec; |
| 7276 | |
| 7277 | fail: |
| 7278 | free(ec); |
| 7279 | return NULL; |
| 7280 | } |
| 7281 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7282 | /** weston_compositor_shutdown |
| 7283 | * \ingroup compositor |
| 7284 | */ |
Benjamin Franzke | b826302 | 2011-08-30 11:32:47 +0200 | [diff] [blame] | 7285 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 7286 | weston_compositor_shutdown(struct weston_compositor *ec) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 7287 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 7288 | struct weston_output *output, *next; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 7289 | |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 7290 | wl_event_source_remove(ec->idle_source); |
| 7291 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 7292 | /* Destroy all outputs associated with this compositor */ |
Tiago Vignatti | b303a1d | 2011-12-18 22:27:40 +0200 | [diff] [blame] | 7293 | wl_list_for_each_safe(output, next, &ec->output_list, link) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 7294 | output->destroy(output); |
Pekka Paalanen | 4738f3b | 2012-01-02 15:47:07 +0200 | [diff] [blame] | 7295 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 7296 | /* Destroy all pending outputs associated with this compositor */ |
| 7297 | wl_list_for_each_safe(output, next, &ec->pending_output_list, link) |
| 7298 | output->destroy(output); |
| 7299 | |
Ander Conselvan de Oliveira | 1853676 | 2013-12-20 21:07:00 +0200 | [diff] [blame] | 7300 | if (ec->renderer) |
| 7301 | ec->renderer->destroy(ec); |
| 7302 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 7303 | weston_binding_list_destroy_all(&ec->key_binding_list); |
Ryo Munakata | 27135af | 2015-07-17 13:07:42 +0900 | [diff] [blame] | 7304 | weston_binding_list_destroy_all(&ec->modifier_binding_list); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 7305 | weston_binding_list_destroy_all(&ec->button_binding_list); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 7306 | weston_binding_list_destroy_all(&ec->touch_binding_list); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 7307 | weston_binding_list_destroy_all(&ec->axis_binding_list); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 7308 | weston_binding_list_destroy_all(&ec->debug_binding_list); |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 7309 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 7310 | weston_plane_release(&ec->primary_plane); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 7311 | } |
| 7312 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7313 | /** weston_compositor_exit_with_code |
| 7314 | * \ingroup compositor |
| 7315 | */ |
Kristian Høgsberg | af4f2aa | 2013-02-15 20:53:20 -0500 | [diff] [blame] | 7316 | WL_EXPORT void |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7317 | weston_compositor_exit_with_code(struct weston_compositor *compositor, |
Frederic Plourde | c336f06 | 2014-10-29 14:44:33 -0400 | [diff] [blame] | 7318 | int exit_code) |
| 7319 | { |
Pekka Paalanen | f5ef88f | 2014-11-18 15:57:04 +0200 | [diff] [blame] | 7320 | if (compositor->exit_code == EXIT_SUCCESS) |
| 7321 | compositor->exit_code = exit_code; |
| 7322 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7323 | weston_compositor_exit(compositor); |
Frederic Plourde | c336f06 | 2014-10-29 14:44:33 -0400 | [diff] [blame] | 7324 | } |
| 7325 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7326 | /** weston_compositor_set_default_pointer_grab |
| 7327 | * \ingroup compositor |
| 7328 | */ |
Frederic Plourde | c336f06 | 2014-10-29 14:44:33 -0400 | [diff] [blame] | 7329 | WL_EXPORT void |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 7330 | weston_compositor_set_default_pointer_grab(struct weston_compositor *ec, |
| 7331 | const struct weston_pointer_grab_interface *interface) |
| 7332 | { |
| 7333 | struct weston_seat *seat; |
| 7334 | |
| 7335 | ec->default_pointer_grab = interface; |
| 7336 | wl_list_for_each(seat, &ec->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 7337 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 7338 | |
| 7339 | if (pointer) |
| 7340 | weston_pointer_set_default_grab(pointer, interface); |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 7341 | } |
| 7342 | } |
| 7343 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7344 | /** weston_compositor_set_presentation_clock |
| 7345 | * \ingroup compositor |
| 7346 | */ |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 7347 | WL_EXPORT int |
| 7348 | weston_compositor_set_presentation_clock(struct weston_compositor *compositor, |
| 7349 | clockid_t clk_id) |
| 7350 | { |
| 7351 | struct timespec ts; |
| 7352 | |
| 7353 | if (clock_gettime(clk_id, &ts) < 0) |
| 7354 | return -1; |
| 7355 | |
| 7356 | compositor->presentation_clock = clk_id; |
| 7357 | |
| 7358 | return 0; |
| 7359 | } |
| 7360 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7361 | /** For choosing the software clock, when the display hardware or API |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 7362 | * does not expose a compatible presentation timestamp. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7363 | * |
| 7364 | * \ingroup compositor |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 7365 | */ |
| 7366 | WL_EXPORT int |
| 7367 | weston_compositor_set_presentation_clock_software( |
| 7368 | struct weston_compositor *compositor) |
| 7369 | { |
| 7370 | /* In order of preference */ |
| 7371 | static const clockid_t clocks[] = { |
| 7372 | CLOCK_MONOTONIC_RAW, /* no jumps, no crawling */ |
| 7373 | CLOCK_MONOTONIC_COARSE, /* no jumps, may crawl, fast & coarse */ |
| 7374 | CLOCK_MONOTONIC, /* no jumps, may crawl */ |
| 7375 | CLOCK_REALTIME_COARSE, /* may jump and crawl, fast & coarse */ |
| 7376 | CLOCK_REALTIME /* may jump and crawl */ |
| 7377 | }; |
| 7378 | unsigned i; |
| 7379 | |
| 7380 | for (i = 0; i < ARRAY_LENGTH(clocks); i++) |
| 7381 | if (weston_compositor_set_presentation_clock(compositor, |
| 7382 | clocks[i]) == 0) |
| 7383 | return 0; |
| 7384 | |
| 7385 | weston_log("Error: no suitable presentation clock available.\n"); |
| 7386 | |
| 7387 | return -1; |
| 7388 | } |
| 7389 | |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 7390 | /** Read the current time from the Presentation clock |
| 7391 | * |
| 7392 | * \param compositor |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 7393 | * \param[out] ts The current time. |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 7394 | * |
| 7395 | * \note Reading the current time in user space is always imprecise to some |
| 7396 | * degree. |
| 7397 | * |
| 7398 | * This function is never meant to fail. If reading the clock does fail, |
| 7399 | * an error message is logged and a zero time is returned. Callers are not |
| 7400 | * supposed to detect or react to failures. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7401 | * |
| 7402 | * \ingroup compositor |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 7403 | */ |
| 7404 | WL_EXPORT void |
| 7405 | weston_compositor_read_presentation_clock( |
| 7406 | const struct weston_compositor *compositor, |
| 7407 | struct timespec *ts) |
| 7408 | { |
| 7409 | static bool warned; |
| 7410 | int ret; |
| 7411 | |
| 7412 | ret = clock_gettime(compositor->presentation_clock, ts); |
| 7413 | if (ret < 0) { |
| 7414 | ts->tv_sec = 0; |
| 7415 | ts->tv_nsec = 0; |
| 7416 | |
| 7417 | if (!warned) |
| 7418 | weston_log("Error: failure to read " |
Antonio Borneo | 3957863 | 2019-04-26 23:57:31 +0200 | [diff] [blame] | 7419 | "the presentation clock %#x: '%s' (%d)\n", |
| 7420 | compositor->presentation_clock, |
| 7421 | strerror(errno), errno); |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 7422 | warned = true; |
| 7423 | } |
| 7424 | } |
| 7425 | |
Pekka Paalanen | 230f3b1 | 2014-09-29 14:18:40 -0400 | [diff] [blame] | 7426 | /** Import dmabuf buffer into current renderer |
| 7427 | * |
| 7428 | * \param compositor |
| 7429 | * \param buffer the dmabuf buffer to import |
| 7430 | * \return true on usable buffers, false otherwise |
| 7431 | * |
| 7432 | * This function tests that the linux_dmabuf_buffer is usable |
| 7433 | * for the current renderer. Returns false on unusable buffers. Usually |
| 7434 | * usability is tested by importing the dmabufs for composition. |
| 7435 | * |
| 7436 | * This hook is also used for detecting if the renderer supports |
| 7437 | * dmabufs at all. If the renderer hook is NULL, dmabufs are not |
| 7438 | * supported. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7439 | * |
| 7440 | * \ingroup compositor |
| 7441 | */ |
Pekka Paalanen | 230f3b1 | 2014-09-29 14:18:40 -0400 | [diff] [blame] | 7442 | WL_EXPORT bool |
| 7443 | weston_compositor_import_dmabuf(struct weston_compositor *compositor, |
| 7444 | struct linux_dmabuf_buffer *buffer) |
| 7445 | { |
| 7446 | struct weston_renderer *renderer; |
| 7447 | |
| 7448 | renderer = compositor->renderer; |
| 7449 | |
| 7450 | if (renderer->import_dmabuf == NULL) |
| 7451 | return false; |
| 7452 | |
| 7453 | return renderer->import_dmabuf(compositor, buffer); |
| 7454 | } |
| 7455 | |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 7456 | WL_EXPORT void |
Kristian Høgsberg | af4f2aa | 2013-02-15 20:53:20 -0500 | [diff] [blame] | 7457 | weston_version(int *major, int *minor, int *micro) |
| 7458 | { |
| 7459 | *major = WESTON_VERSION_MAJOR; |
| 7460 | *minor = WESTON_VERSION_MINOR; |
| 7461 | *micro = WESTON_VERSION_MICRO; |
| 7462 | } |
| 7463 | |
Daniel Stone | e03c111 | 2016-11-24 20:45:45 +0000 | [diff] [blame] | 7464 | /** |
| 7465 | * Attempts to find a module path from the module map specified in the |
| 7466 | * environment. If found, writes the full path into the path variable. |
| 7467 | * |
| 7468 | * The module map is a string in environment variable WESTON_MODULE_MAP, where |
| 7469 | * each entry is of the form "name=path" and entries are separated by |
| 7470 | * semicolons. Whitespace is significant. |
| 7471 | * |
| 7472 | * \param name The name to search for. |
| 7473 | * \param path Where the path is written to if found. |
| 7474 | * \param path_len Allocated bytes at \c path . |
| 7475 | * \returns The length of the string written to path on success, or 0 if the |
| 7476 | * module was not specified in the environment map or path_len was too small. |
| 7477 | */ |
| 7478 | WL_EXPORT size_t |
| 7479 | weston_module_path_from_env(const char *name, char *path, size_t path_len) |
| 7480 | { |
| 7481 | const char *mapping = getenv("WESTON_MODULE_MAP"); |
| 7482 | const char *end; |
| 7483 | const int name_len = strlen(name); |
| 7484 | |
| 7485 | if (!mapping) |
| 7486 | return 0; |
| 7487 | |
| 7488 | end = mapping + strlen(mapping); |
| 7489 | while (mapping < end && *mapping) { |
| 7490 | const char *filename, *next; |
| 7491 | |
| 7492 | /* early out: impossibly short string */ |
| 7493 | if (end - mapping < name_len + 1) |
| 7494 | return 0; |
| 7495 | |
| 7496 | filename = &mapping[name_len + 1]; |
| 7497 | next = strchrnul(mapping, ';'); |
| 7498 | |
| 7499 | if (strncmp(mapping, name, name_len) == 0 && |
| 7500 | mapping[name_len] == '=') { |
| 7501 | size_t file_len = next - filename; /* no trailing NUL */ |
| 7502 | if (file_len >= path_len) |
| 7503 | return 0; |
| 7504 | strncpy(path, filename, file_len); |
| 7505 | path[file_len] = '\0'; |
| 7506 | return file_len; |
| 7507 | } |
| 7508 | |
| 7509 | mapping = next + 1; |
| 7510 | } |
| 7511 | |
| 7512 | return 0; |
| 7513 | } |
| 7514 | |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 7515 | WL_EXPORT void * |
| 7516 | weston_load_module(const char *name, const char *entrypoint) |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 7517 | { |
| 7518 | char path[PATH_MAX]; |
| 7519 | void *module, *init; |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 7520 | size_t len; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 7521 | |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 7522 | if (name == NULL) |
| 7523 | return NULL; |
| 7524 | |
Derek Foreman | 3f86e50 | 2015-06-08 11:46:54 -0500 | [diff] [blame] | 7525 | if (name[0] != '/') { |
Daniel Stone | e03c111 | 2016-11-24 20:45:45 +0000 | [diff] [blame] | 7526 | len = weston_module_path_from_env(name, path, sizeof path); |
| 7527 | if (len == 0) |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 7528 | len = snprintf(path, sizeof path, "%s/%s", |
| 7529 | LIBWESTON_MODULEDIR, name); |
Derek Foreman | 3f86e50 | 2015-06-08 11:46:54 -0500 | [diff] [blame] | 7530 | } else { |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 7531 | len = snprintf(path, sizeof path, "%s", name); |
Derek Foreman | 3f86e50 | 2015-06-08 11:46:54 -0500 | [diff] [blame] | 7532 | } |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 7533 | |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 7534 | /* snprintf returns the length of the string it would've written, |
| 7535 | * _excluding_ the NUL byte. So even being equal to the size of |
| 7536 | * our buffer is an error here. */ |
| 7537 | if (len >= sizeof path) |
| 7538 | return NULL; |
| 7539 | |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 7540 | module = dlopen(path, RTLD_NOW | RTLD_NOLOAD); |
| 7541 | if (module) { |
| 7542 | weston_log("Module '%s' already loaded\n", path); |
| 7543 | dlclose(module); |
| 7544 | return NULL; |
| 7545 | } |
| 7546 | |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 7547 | weston_log("Loading module '%s'\n", path); |
Kristian Høgsberg | 1acd9f8 | 2012-07-26 11:39:26 -0400 | [diff] [blame] | 7548 | module = dlopen(path, RTLD_NOW); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 7549 | if (!module) { |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 7550 | weston_log("Failed to load module: %s\n", dlerror()); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 7551 | return NULL; |
| 7552 | } |
| 7553 | |
| 7554 | init = dlsym(module, entrypoint); |
| 7555 | if (!init) { |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 7556 | weston_log("Failed to lookup init function: %s\n", dlerror()); |
Rob Bradford | c9e64ab | 2012-12-05 18:47:10 +0000 | [diff] [blame] | 7557 | dlclose(module); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 7558 | return NULL; |
| 7559 | } |
| 7560 | |
| 7561 | return init; |
| 7562 | } |
| 7563 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7564 | |
| 7565 | /** Destroys the compositor. |
| 7566 | * |
| 7567 | * This function cleans up the compositor state and destroys it. |
| 7568 | * |
| 7569 | * \param compositor The compositor to be destroyed. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7570 | * |
| 7571 | * \ingroup compositor |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7572 | */ |
| 7573 | WL_EXPORT void |
| 7574 | weston_compositor_destroy(struct weston_compositor *compositor) |
| 7575 | { |
| 7576 | /* prevent further rendering while shutting down */ |
| 7577 | compositor->state = WESTON_COMPOSITOR_OFFSCREEN; |
| 7578 | |
| 7579 | wl_signal_emit(&compositor->destroy_signal, compositor); |
| 7580 | |
| 7581 | weston_compositor_xkb_destroy(compositor); |
| 7582 | |
Giulio Camuffo | 2d24e64 | 2015-10-03 16:25:15 +0300 | [diff] [blame] | 7583 | if (compositor->backend) |
| 7584 | compositor->backend->destroy(compositor); |
Pekka Paalanen | 827b5d2 | 2016-06-29 11:54:26 +0200 | [diff] [blame] | 7585 | |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 7586 | /* The backend is responsible for destroying the heads. */ |
| 7587 | assert(wl_list_empty(&compositor->head_list)); |
| 7588 | |
Pekka Paalanen | 827b5d2 | 2016-06-29 11:54:26 +0200 | [diff] [blame] | 7589 | weston_plugin_api_destroy_list(compositor); |
| 7590 | |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 7591 | if (compositor->heads_changed_source) |
| 7592 | wl_event_source_remove(compositor->heads_changed_source); |
| 7593 | |
Marius Vlad | 7e4db95 | 2019-04-17 13:47:06 +0300 | [diff] [blame] | 7594 | weston_compositor_log_scope_destroy(compositor->debug_scene); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7595 | compositor->debug_scene = NULL; |
Marius Vlad | 3d7d978 | 2019-04-17 12:35:38 +0300 | [diff] [blame] | 7596 | weston_log_ctx_compositor_destroy(compositor); |
Pekka Paalanen | a5630ea | 2017-10-12 13:13:42 +0200 | [diff] [blame] | 7597 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7598 | free(compositor); |
| 7599 | } |
| 7600 | |
| 7601 | /** Instruct the compositor to exit. |
| 7602 | * |
| 7603 | * This functions does not directly destroy the compositor object, it merely |
| 7604 | * command it to start the tear down process. It is not guaranteed that the |
| 7605 | * tear down will happen immediately. |
| 7606 | * |
| 7607 | * \param compositor The compositor to tear down. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7608 | * |
| 7609 | * \ingroup compositor |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7610 | */ |
| 7611 | WL_EXPORT void |
| 7612 | weston_compositor_exit(struct weston_compositor *compositor) |
| 7613 | { |
| 7614 | compositor->exit(compositor); |
| 7615 | } |
| 7616 | |
| 7617 | /** Return the user data stored in the compositor. |
| 7618 | * |
| 7619 | * This function returns the user data pointer set with user_data parameter |
| 7620 | * to the \ref weston_compositor_create function. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7621 | * |
| 7622 | * \ingroup compositor |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7623 | */ |
| 7624 | WL_EXPORT void * |
| 7625 | weston_compositor_get_user_data(struct weston_compositor *compositor) |
| 7626 | { |
| 7627 | return compositor->user_data; |
| 7628 | } |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 7629 | |
Pekka Paalanen | 50dbf38 | 2016-06-03 15:23:46 +0300 | [diff] [blame] | 7630 | static const char * const backend_map[] = { |
| 7631 | [WESTON_BACKEND_DRM] = "drm-backend.so", |
| 7632 | [WESTON_BACKEND_FBDEV] = "fbdev-backend.so", |
| 7633 | [WESTON_BACKEND_HEADLESS] = "headless-backend.so", |
| 7634 | [WESTON_BACKEND_RDP] = "rdp-backend.so", |
| 7635 | [WESTON_BACKEND_WAYLAND] = "wayland-backend.so", |
| 7636 | [WESTON_BACKEND_X11] = "x11-backend.so", |
| 7637 | }; |
| 7638 | |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 7639 | /** Load a backend into a weston_compositor |
| 7640 | * |
| 7641 | * A backend must be loaded to make a weston_compositor work. A backend |
| 7642 | * provides input and output capabilities, and determines the renderer to use. |
| 7643 | * |
| 7644 | * \param compositor A compositor that has not had a backend loaded yet. |
| 7645 | * \param backend Name of the backend file. |
| 7646 | * \param config_base A pointer to a backend-specific configuration |
| 7647 | * structure's 'base' member. |
| 7648 | * |
| 7649 | * \return 0 on success, or -1 on error. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7650 | * |
| 7651 | * \ingroup compositor |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 7652 | */ |
| 7653 | WL_EXPORT int |
| 7654 | weston_compositor_load_backend(struct weston_compositor *compositor, |
Pekka Paalanen | 50dbf38 | 2016-06-03 15:23:46 +0300 | [diff] [blame] | 7655 | enum weston_compositor_backend backend, |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 7656 | struct weston_backend_config *config_base) |
| 7657 | { |
| 7658 | int (*backend_init)(struct weston_compositor *c, |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 7659 | struct weston_backend_config *config_base); |
| 7660 | |
Pekka Paalanen | d7e3511 | 2017-08-29 17:04:12 +0300 | [diff] [blame] | 7661 | if (compositor->backend) { |
| 7662 | weston_log("Error: attempt to load a backend when one is already loaded\n"); |
| 7663 | return -1; |
| 7664 | } |
| 7665 | |
Quentin Glidic | 887c018 | 2016-07-10 11:00:53 +0200 | [diff] [blame] | 7666 | if (backend >= ARRAY_LENGTH(backend_map)) |
Pekka Paalanen | 50dbf38 | 2016-06-03 15:23:46 +0300 | [diff] [blame] | 7667 | return -1; |
| 7668 | |
Quentin Glidic | 23e1d6f | 2016-12-02 14:08:44 +0100 | [diff] [blame] | 7669 | backend_init = weston_load_module(backend_map[backend], "weston_backend_init"); |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 7670 | if (!backend_init) |
| 7671 | return -1; |
| 7672 | |
Pekka Paalanen | d7e3511 | 2017-08-29 17:04:12 +0300 | [diff] [blame] | 7673 | if (backend_init(compositor, config_base) < 0) { |
| 7674 | compositor->backend = NULL; |
| 7675 | return -1; |
| 7676 | } |
| 7677 | |
| 7678 | return 0; |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 7679 | } |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 7680 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7681 | /** weston_compositor_load_xwayland |
| 7682 | * \ingroup compositor |
| 7683 | */ |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 7684 | WL_EXPORT int |
| 7685 | weston_compositor_load_xwayland(struct weston_compositor *compositor) |
| 7686 | { |
Quentin Glidic | 3d7ca3b | 2016-12-02 14:20:35 +0100 | [diff] [blame] | 7687 | int (*module_init)(struct weston_compositor *ec); |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 7688 | |
Quentin Glidic | 3d7ca3b | 2016-12-02 14:20:35 +0100 | [diff] [blame] | 7689 | module_init = weston_load_module("xwayland.so", "weston_module_init"); |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 7690 | if (!module_init) |
| 7691 | return -1; |
Quentin Glidic | 3d7ca3b | 2016-12-02 14:20:35 +0100 | [diff] [blame] | 7692 | if (module_init(compositor) < 0) |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 7693 | return -1; |
| 7694 | return 0; |
| 7695 | } |
Vasilis Liaskovitis | 486b463 | 2018-10-10 16:14:55 +0200 | [diff] [blame] | 7696 | |
| 7697 | /** Resolve an internal compositor error by disconnecting the client. |
| 7698 | * |
| 7699 | * This function is used in cases when the wl_buffer turns out |
| 7700 | * unusable and there is no fallback path. |
| 7701 | * |
| 7702 | * It is possible the fault is caused by a compositor bug, the underlying |
| 7703 | * graphics stack bug or normal behaviour, or perhaps a client mistake. |
| 7704 | * In any case, the options are to either composite garbage or nothing, |
| 7705 | * or disconnect the client. This is a helper function for the latter. |
| 7706 | * |
| 7707 | * The error is sent as an INVALID_OBJECT error on the client's wl_display. |
| 7708 | * |
| 7709 | * \param buffer The weston buffer that is unusable. |
| 7710 | * \param msg A custom error message attached to the protocol error. |
| 7711 | */ |
| 7712 | WL_EXPORT void |
| 7713 | weston_buffer_send_server_error(struct weston_buffer *buffer, |
| 7714 | const char *msg) |
| 7715 | { |
| 7716 | struct wl_client *client; |
| 7717 | struct wl_resource *display_resource; |
| 7718 | uint32_t id; |
| 7719 | |
| 7720 | assert(buffer->resource); |
| 7721 | id = wl_resource_get_id(buffer->resource); |
| 7722 | client = wl_resource_get_client(buffer->resource); |
| 7723 | display_resource = wl_client_get_object(client, 1); |
| 7724 | |
| 7725 | assert(display_resource); |
| 7726 | wl_resource_post_error(display_resource, |
| 7727 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 7728 | "server error with " |
| 7729 | "wl_buffer@%u: %s", id, msg); |
| 7730 | } |