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 | c901e89 | 2019-06-21 22:49:18 +0300 | [diff] [blame] | 59 | #include <libweston/weston-log.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" |
Marius Vlad | 63ef078 | 2019-07-16 23:34:14 +0300 | [diff] [blame] | 75 | #include "backend.h" |
Marius Vlad | a72e371 | 2019-07-10 13:46:39 +0300 | [diff] [blame] | 76 | #include "libweston-internal.h" |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 77 | |
Marius Vlad | 4e03629 | 2019-07-09 00:36:20 +0300 | [diff] [blame] | 78 | #include "weston-log-internal.h" |
| 79 | |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 80 | /** |
| 81 | * \defgroup head Head |
| 82 | * \defgroup output Output |
| 83 | * \defgroup compositor Compositor |
| 84 | */ |
| 85 | |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 86 | #define DEFAULT_REPAINT_WINDOW 7 /* milliseconds */ |
| 87 | |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 88 | static void |
Pekka Paalanen | d72bad2 | 2017-03-29 17:01:41 +0300 | [diff] [blame] | 89 | weston_output_update_matrix(struct weston_output *output); |
| 90 | |
| 91 | static void |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 92 | weston_output_transform_scale_init(struct weston_output *output, |
| 93 | uint32_t transform, uint32_t scale); |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 94 | |
Rob Bradford | 27b1793 | 2013-06-26 18:08:46 +0100 | [diff] [blame] | 95 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 96 | weston_compositor_build_view_list(struct weston_compositor *compositor); |
Rob Bradford | 27b1793 | 2013-06-26 18:08:46 +0100 | [diff] [blame] | 97 | |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 98 | static char * |
| 99 | weston_output_create_heads_string(struct weston_output *output); |
| 100 | |
Pekka Paalanen | 6528c03 | 2017-03-28 15:27:10 +0300 | [diff] [blame] | 101 | /** Send wl_output events for mode and scale changes |
| 102 | * |
| 103 | * \param head Send on all resources bound to this head. |
| 104 | * \param mode_changed If true, send the current mode. |
| 105 | * \param scale_changed If true, send the current scale. |
| 106 | */ |
| 107 | static void |
| 108 | weston_mode_switch_send_events(struct weston_head *head, |
| 109 | bool mode_changed, bool scale_changed) |
| 110 | { |
| 111 | struct weston_output *output = head->output; |
| 112 | struct wl_resource *resource; |
| 113 | int version; |
| 114 | |
| 115 | wl_resource_for_each(resource, &head->resource_list) { |
| 116 | if (mode_changed) { |
| 117 | wl_output_send_mode(resource, |
| 118 | output->current_mode->flags, |
| 119 | output->current_mode->width, |
| 120 | output->current_mode->height, |
| 121 | output->current_mode->refresh); |
| 122 | } |
| 123 | |
| 124 | version = wl_resource_get_version(resource); |
| 125 | if (version >= WL_OUTPUT_SCALE_SINCE_VERSION && scale_changed) |
| 126 | wl_output_send_scale(resource, output->current_scale); |
| 127 | |
| 128 | if (version >= WL_OUTPUT_DONE_SINCE_VERSION) |
| 129 | wl_output_send_done(resource); |
| 130 | } |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 131 | wl_resource_for_each(resource, &head->xdg_output_resource_list) { |
| 132 | zxdg_output_v1_send_logical_position(resource, |
| 133 | output->x, |
| 134 | output->y); |
| 135 | zxdg_output_v1_send_logical_size(resource, |
| 136 | output->width, |
| 137 | output->height); |
| 138 | zxdg_output_v1_send_done(resource); |
| 139 | } |
Pekka Paalanen | 6528c03 | 2017-03-28 15:27:10 +0300 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | static void |
| 143 | weston_mode_switch_finish(struct weston_output *output, |
| 144 | int mode_changed, int scale_changed) |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 145 | { |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 146 | struct weston_seat *seat; |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 147 | struct weston_head *head; |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 148 | pixman_region32_t old_output_region; |
Alexander Larsson | 355748e | 2013-05-28 16:23:38 +0200 | [diff] [blame] | 149 | |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 150 | pixman_region32_init(&old_output_region); |
| 151 | pixman_region32_copy(&old_output_region, &output->region); |
| 152 | |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 153 | /* Update output region and transformation matrix */ |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 154 | 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] | 155 | |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 156 | pixman_region32_init_rect(&output->region, output->x, output->y, |
| 157 | output->width, output->height); |
| 158 | |
| 159 | weston_output_update_matrix(output); |
| 160 | |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 161 | /* If a pointer falls outside the outputs new geometry, move it to its |
| 162 | * lower-right corner */ |
| 163 | wl_list_for_each(seat, &output->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 164 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 165 | int32_t x, y; |
| 166 | |
| 167 | if (!pointer) |
| 168 | continue; |
| 169 | |
| 170 | x = wl_fixed_to_int(pointer->x); |
| 171 | y = wl_fixed_to_int(pointer->y); |
| 172 | |
| 173 | if (!pixman_region32_contains_point(&old_output_region, |
| 174 | x, y, NULL) || |
| 175 | pixman_region32_contains_point(&output->region, |
| 176 | x, y, NULL)) |
| 177 | continue; |
| 178 | |
| 179 | if (x >= output->x + output->width) |
| 180 | x = output->x + output->width - 1; |
| 181 | if (y >= output->y + output->height) |
| 182 | y = output->y + output->height - 1; |
| 183 | |
| 184 | pointer->x = wl_fixed_from_int(x); |
| 185 | pointer->y = wl_fixed_from_int(y); |
| 186 | } |
| 187 | |
| 188 | pixman_region32_fini(&old_output_region); |
| 189 | |
Derek Foreman | dd4cd33 | 2014-11-10 10:29:59 -0600 | [diff] [blame] | 190 | if (!mode_changed && !scale_changed) |
| 191 | return; |
| 192 | |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 193 | /* notify clients of the changes */ |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 194 | wl_list_for_each(head, &output->head_list, output_link) |
| 195 | weston_mode_switch_send_events(head, |
| 196 | mode_changed, scale_changed); |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 197 | } |
| 198 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 199 | static void |
| 200 | weston_compositor_reflow_outputs(struct weston_compositor *compositor, |
| 201 | struct weston_output *resized_output, int delta_width); |
| 202 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 203 | /** |
| 204 | * \ingroup output |
| 205 | */ |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 206 | WL_EXPORT int |
| 207 | weston_output_mode_set_native(struct weston_output *output, |
| 208 | struct weston_mode *mode, |
| 209 | int32_t scale) |
| 210 | { |
| 211 | int ret; |
| 212 | int mode_changed = 0, scale_changed = 0; |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 213 | int32_t old_width; |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 214 | |
| 215 | if (!output->switch_mode) |
| 216 | return -1; |
| 217 | |
| 218 | if (!output->original_mode) { |
| 219 | mode_changed = 1; |
| 220 | ret = output->switch_mode(output, mode); |
| 221 | if (ret < 0) |
| 222 | return ret; |
| 223 | if (output->current_scale != scale) { |
| 224 | scale_changed = 1; |
| 225 | output->current_scale = scale; |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 229 | old_width = output->width; |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 230 | output->native_mode = mode; |
| 231 | output->native_scale = scale; |
| 232 | |
| 233 | weston_mode_switch_finish(output, mode_changed, scale_changed); |
| 234 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 235 | if (mode_changed || scale_changed) { |
| 236 | weston_compositor_reflow_outputs(output->compositor, output, output->width - old_width); |
| 237 | |
| 238 | wl_signal_emit(&output->compositor->output_resized_signal, output); |
| 239 | } |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 240 | return 0; |
| 241 | } |
| 242 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 243 | /** |
| 244 | * \ingroup output |
| 245 | */ |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 246 | WL_EXPORT int |
| 247 | weston_output_mode_switch_to_native(struct weston_output *output) |
| 248 | { |
| 249 | int ret; |
| 250 | int mode_changed = 0, scale_changed = 0; |
| 251 | |
| 252 | if (!output->switch_mode) |
| 253 | return -1; |
| 254 | |
| 255 | if (!output->original_mode) { |
| 256 | weston_log("already in the native mode\n"); |
| 257 | return -1; |
| 258 | } |
| 259 | /* the non fullscreen clients haven't seen a mode set since we |
| 260 | * switched into a temporary, so we need to notify them if the |
| 261 | * mode at that time is different from the native mode now. |
| 262 | */ |
| 263 | mode_changed = (output->original_mode != output->native_mode); |
| 264 | scale_changed = (output->original_scale != output->native_scale); |
| 265 | |
| 266 | ret = output->switch_mode(output, output->native_mode); |
| 267 | if (ret < 0) |
| 268 | return ret; |
| 269 | |
| 270 | output->current_scale = output->native_scale; |
| 271 | |
| 272 | output->original_mode = NULL; |
| 273 | output->original_scale = 0; |
| 274 | |
| 275 | weston_mode_switch_finish(output, mode_changed, scale_changed); |
| 276 | |
| 277 | return 0; |
| 278 | } |
| 279 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 280 | /** |
| 281 | * \ingroup output |
| 282 | */ |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 283 | WL_EXPORT int |
| 284 | weston_output_mode_switch_to_temporary(struct weston_output *output, |
| 285 | struct weston_mode *mode, |
| 286 | int32_t scale) |
| 287 | { |
| 288 | int ret; |
| 289 | |
| 290 | if (!output->switch_mode) |
| 291 | return -1; |
| 292 | |
| 293 | /* original_mode is the last mode non full screen clients have seen, |
| 294 | * so we shouldn't change it if we already have one set. |
| 295 | */ |
| 296 | if (!output->original_mode) { |
| 297 | output->original_mode = output->native_mode; |
| 298 | output->original_scale = output->native_scale; |
| 299 | } |
| 300 | ret = output->switch_mode(output, mode); |
| 301 | if (ret < 0) |
| 302 | return ret; |
| 303 | |
| 304 | output->current_scale = scale; |
| 305 | |
| 306 | weston_mode_switch_finish(output, 0, 0); |
| 307 | |
| 308 | return 0; |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 309 | } |
| 310 | |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 311 | static void |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 312 | region_init_infinite(pixman_region32_t *region) |
| 313 | { |
| 314 | pixman_region32_init_rect(region, INT32_MIN, INT32_MIN, |
| 315 | UINT32_MAX, UINT32_MAX); |
| 316 | } |
| 317 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 318 | static struct weston_subsurface * |
| 319 | weston_surface_to_subsurface(struct weston_surface *surface); |
| 320 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 321 | WL_EXPORT struct weston_view * |
| 322 | weston_view_create(struct weston_surface *surface) |
| 323 | { |
| 324 | struct weston_view *view; |
| 325 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 326 | view = zalloc(sizeof *view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 327 | if (view == NULL) |
| 328 | return NULL; |
| 329 | |
| 330 | view->surface = surface; |
Daniel Stone | fb4869d | 2016-12-09 16:27:54 +0000 | [diff] [blame] | 331 | view->plane = &surface->compositor->primary_plane; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 332 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 333 | /* Assign to surface */ |
| 334 | wl_list_insert(&surface->views, &view->surface_link); |
| 335 | |
| 336 | wl_signal_init(&view->destroy_signal); |
| 337 | wl_list_init(&view->link); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 338 | wl_list_init(&view->layer_link.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 339 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 340 | pixman_region32_init(&view->clip); |
| 341 | |
| 342 | view->alpha = 1.0; |
| 343 | pixman_region32_init(&view->transform.opaque); |
| 344 | |
| 345 | wl_list_init(&view->geometry.transformation_list); |
| 346 | wl_list_insert(&view->geometry.transformation_list, |
| 347 | &view->transform.position.link); |
| 348 | weston_matrix_init(&view->transform.position.matrix); |
| 349 | wl_list_init(&view->geometry.child_list); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 350 | pixman_region32_init(&view->geometry.scissor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 351 | pixman_region32_init(&view->transform.boundingbox); |
| 352 | view->transform.dirty = 1; |
| 353 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 354 | return view; |
| 355 | } |
| 356 | |
Jason Ekstrand | 108865d | 2014-06-26 10:04:49 -0700 | [diff] [blame] | 357 | struct weston_frame_callback { |
| 358 | struct wl_resource *resource; |
| 359 | struct wl_list link; |
| 360 | }; |
| 361 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 362 | struct weston_presentation_feedback { |
| 363 | struct wl_resource *resource; |
| 364 | |
| 365 | /* XXX: could use just wl_resource_get_link() instead */ |
| 366 | struct wl_list link; |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 367 | |
| 368 | /* The per-surface feedback flags */ |
| 369 | uint32_t psf_flags; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 370 | }; |
| 371 | |
| 372 | static void |
| 373 | weston_presentation_feedback_discard( |
| 374 | struct weston_presentation_feedback *feedback) |
| 375 | { |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 376 | wp_presentation_feedback_send_discarded(feedback->resource); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 377 | wl_resource_destroy(feedback->resource); |
| 378 | } |
| 379 | |
| 380 | static void |
| 381 | weston_presentation_feedback_discard_list(struct wl_list *list) |
| 382 | { |
| 383 | struct weston_presentation_feedback *feedback, *tmp; |
| 384 | |
| 385 | wl_list_for_each_safe(feedback, tmp, list, link) |
| 386 | weston_presentation_feedback_discard(feedback); |
| 387 | } |
| 388 | |
| 389 | static void |
| 390 | weston_presentation_feedback_present( |
| 391 | struct weston_presentation_feedback *feedback, |
| 392 | struct weston_output *output, |
| 393 | uint32_t refresh_nsec, |
| 394 | const struct timespec *ts, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 395 | uint64_t seq, |
| 396 | uint32_t flags) |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 397 | { |
| 398 | struct wl_client *client = wl_resource_get_client(feedback->resource); |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 399 | struct weston_head *head; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 400 | struct wl_resource *o; |
Alexandros Frantzis | 10d708d | 2017-12-13 13:27:54 +0200 | [diff] [blame] | 401 | uint32_t tv_sec_hi; |
| 402 | uint32_t tv_sec_lo; |
| 403 | uint32_t tv_nsec; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 404 | bool done = false; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 405 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 406 | wl_list_for_each(head, &output->head_list, output_link) { |
| 407 | wl_resource_for_each(o, &head->resource_list) { |
| 408 | if (wl_resource_get_client(o) != client) |
| 409 | continue; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 410 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 411 | wp_presentation_feedback_send_sync_output(feedback->resource, o); |
| 412 | done = true; |
| 413 | } |
| 414 | |
| 415 | /* For clone mode, send it for just one wl_output global, |
| 416 | * they are all equivalent anyway. |
| 417 | */ |
| 418 | if (done) |
| 419 | break; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 420 | } |
| 421 | |
Alexandros Frantzis | 10d708d | 2017-12-13 13:27:54 +0200 | [diff] [blame] | 422 | timespec_to_proto(ts, &tv_sec_hi, &tv_sec_lo, &tv_nsec); |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 423 | wp_presentation_feedback_send_presented(feedback->resource, |
Alexandros Frantzis | 10d708d | 2017-12-13 13:27:54 +0200 | [diff] [blame] | 424 | tv_sec_hi, tv_sec_lo, tv_nsec, |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 425 | refresh_nsec, |
| 426 | seq >> 32, seq & 0xffffffff, |
| 427 | flags | feedback->psf_flags); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 428 | wl_resource_destroy(feedback->resource); |
| 429 | } |
| 430 | |
| 431 | static void |
| 432 | weston_presentation_feedback_present_list(struct wl_list *list, |
| 433 | struct weston_output *output, |
| 434 | uint32_t refresh_nsec, |
| 435 | const struct timespec *ts, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 436 | uint64_t seq, |
| 437 | uint32_t flags) |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 438 | { |
| 439 | struct weston_presentation_feedback *feedback, *tmp; |
| 440 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 441 | assert(!(flags & WP_PRESENTATION_FEEDBACK_INVALID) || |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 442 | wl_list_empty(list)); |
| 443 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 444 | wl_list_for_each_safe(feedback, tmp, list, link) |
| 445 | weston_presentation_feedback_present(feedback, output, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 446 | refresh_nsec, ts, seq, |
| 447 | flags); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 448 | } |
| 449 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 450 | static void |
| 451 | surface_state_handle_buffer_destroy(struct wl_listener *listener, void *data) |
| 452 | { |
| 453 | struct weston_surface_state *state = |
| 454 | container_of(listener, struct weston_surface_state, |
| 455 | buffer_destroy_listener); |
| 456 | |
| 457 | state->buffer = NULL; |
| 458 | } |
| 459 | |
| 460 | static void |
| 461 | weston_surface_state_init(struct weston_surface_state *state) |
| 462 | { |
| 463 | state->newly_attached = 0; |
| 464 | state->buffer = NULL; |
| 465 | state->buffer_destroy_listener.notify = |
| 466 | surface_state_handle_buffer_destroy; |
| 467 | state->sx = 0; |
| 468 | state->sy = 0; |
| 469 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 470 | pixman_region32_init(&state->damage_surface); |
| 471 | pixman_region32_init(&state->damage_buffer); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 472 | pixman_region32_init(&state->opaque); |
| 473 | region_init_infinite(&state->input); |
| 474 | |
| 475 | wl_list_init(&state->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 476 | wl_list_init(&state->feedback_list); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 477 | |
| 478 | state->buffer_viewport.buffer.transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 479 | state->buffer_viewport.buffer.scale = 1; |
| 480 | state->buffer_viewport.buffer.src_width = wl_fixed_from_int(-1); |
| 481 | state->buffer_viewport.surface.width = -1; |
| 482 | state->buffer_viewport.changed = 0; |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 483 | |
| 484 | state->acquire_fence_fd = -1; |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 485 | |
| 486 | state->desired_protection = WESTON_HDCP_DISABLE; |
Ankit Nautiyal | 5cfe03c | 2019-03-28 15:05:42 +0530 | [diff] [blame] | 487 | state->protection_mode = WESTON_SURFACE_PROTECTION_MODE_RELAXED; |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 488 | } |
| 489 | |
| 490 | static void |
| 491 | weston_surface_state_fini(struct weston_surface_state *state) |
| 492 | { |
| 493 | struct weston_frame_callback *cb, *next; |
| 494 | |
| 495 | wl_list_for_each_safe(cb, next, |
| 496 | &state->frame_callback_list, link) |
| 497 | wl_resource_destroy(cb->resource); |
| 498 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 499 | weston_presentation_feedback_discard_list(&state->feedback_list); |
| 500 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 501 | pixman_region32_fini(&state->input); |
| 502 | pixman_region32_fini(&state->opaque); |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 503 | pixman_region32_fini(&state->damage_surface); |
| 504 | pixman_region32_fini(&state->damage_buffer); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 505 | |
| 506 | if (state->buffer) |
| 507 | wl_list_remove(&state->buffer_destroy_listener.link); |
| 508 | state->buffer = NULL; |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 509 | |
| 510 | fd_clear(&state->acquire_fence_fd); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 511 | weston_buffer_release_reference(&state->buffer_release_ref, NULL); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | static void |
| 515 | weston_surface_state_set_buffer(struct weston_surface_state *state, |
| 516 | struct weston_buffer *buffer) |
| 517 | { |
| 518 | if (state->buffer == buffer) |
| 519 | return; |
| 520 | |
| 521 | if (state->buffer) |
| 522 | wl_list_remove(&state->buffer_destroy_listener.link); |
| 523 | state->buffer = buffer; |
| 524 | if (state->buffer) |
| 525 | wl_signal_add(&state->buffer->destroy_signal, |
| 526 | &state->buffer_destroy_listener); |
| 527 | } |
| 528 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 529 | WL_EXPORT struct weston_surface * |
Kristian Høgsberg | 18c9300 | 2012-01-27 11:58:31 -0500 | [diff] [blame] | 530 | weston_surface_create(struct weston_compositor *compositor) |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 531 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 532 | struct weston_surface *surface; |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 533 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 534 | surface = zalloc(sizeof *surface); |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 535 | if (surface == NULL) |
| 536 | return NULL; |
| 537 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 538 | wl_signal_init(&surface->destroy_signal); |
Jonas Ådahl | 5d9ca27 | 2016-07-22 17:48:03 +0800 | [diff] [blame] | 539 | wl_signal_init(&surface->commit_signal); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 540 | |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 541 | surface->compositor = compositor; |
Giulio Camuffo | 13b85bd | 2013-08-13 23:10:14 +0200 | [diff] [blame] | 542 | surface->ref_count = 1; |
Kristian Høgsberg | 27803c6 | 2010-06-06 22:23:21 -0400 | [diff] [blame] | 543 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 544 | surface->buffer_viewport.buffer.transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 545 | surface->buffer_viewport.buffer.scale = 1; |
Pekka Paalanen | f0cad48 | 2014-03-14 14:38:16 +0200 | [diff] [blame] | 546 | surface->buffer_viewport.buffer.src_width = wl_fixed_from_int(-1); |
| 547 | surface->buffer_viewport.surface.width = -1; |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 548 | |
| 549 | weston_surface_state_init(&surface->pending); |
| 550 | |
Kristian Høgsberg | 20300ba | 2011-06-23 20:29:12 -0400 | [diff] [blame] | 551 | pixman_region32_init(&surface->damage); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 552 | pixman_region32_init(&surface->opaque); |
Pekka Paalanen | 8ec4ab6 | 2012-10-10 12:49:32 +0300 | [diff] [blame] | 553 | region_init_infinite(&surface->input); |
Kristian Høgsberg | 20300ba | 2011-06-23 20:29:12 -0400 | [diff] [blame] | 554 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 555 | wl_list_init(&surface->views); |
| 556 | |
| 557 | wl_list_init(&surface->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 558 | wl_list_init(&surface->feedback_list); |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 559 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 560 | wl_list_init(&surface->subsurface_list); |
| 561 | wl_list_init(&surface->subsurface_list_pending); |
| 562 | |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 563 | weston_matrix_init(&surface->buffer_to_surface_matrix); |
| 564 | weston_matrix_init(&surface->surface_to_buffer_matrix); |
| 565 | |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 566 | wl_list_init(&surface->pointer_constraints); |
| 567 | |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 568 | surface->acquire_fence_fd = -1; |
| 569 | |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 570 | surface->desired_protection = WESTON_HDCP_DISABLE; |
Ankit Nautiyal | 5cfe03c | 2019-03-28 15:05:42 +0530 | [diff] [blame] | 571 | surface->current_protection = WESTON_HDCP_DISABLE; |
| 572 | surface->protection_mode = WESTON_SURFACE_PROTECTION_MODE_RELAXED; |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 573 | |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 574 | return surface; |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 575 | } |
| 576 | |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 577 | WL_EXPORT void |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 578 | weston_surface_set_color(struct weston_surface *surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 579 | float red, float green, float blue, float alpha) |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 580 | { |
John Kåre Alsaker | 878f449 | 2012-11-13 19:10:23 +0100 | [diff] [blame] | 581 | surface->compositor->renderer->surface_set_color(surface, red, green, blue, alpha); |
Philipp Zabel | 195dade | 2018-09-03 19:44:59 +0200 | [diff] [blame] | 582 | surface->is_opaque = !(alpha < 1.0); |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 583 | } |
| 584 | |
Kristian Høgsberg | e4c1a5f | 2012-06-18 13:17:32 -0400 | [diff] [blame] | 585 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 586 | weston_view_to_global_float(struct weston_view *view, |
| 587 | float sx, float sy, float *x, float *y) |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 588 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 589 | if (view->transform.enabled) { |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 590 | struct weston_vector v = { { sx, sy, 0.0f, 1.0f } }; |
| 591 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 592 | weston_matrix_transform(&view->transform.matrix, &v); |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 593 | |
| 594 | if (fabsf(v.f[3]) < 1e-6) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 595 | weston_log("warning: numerical instability in " |
Scott Moreau | 088c62e | 2013-02-11 04:45:38 -0700 | [diff] [blame] | 596 | "%s(), divisor = %g\n", __func__, |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 597 | v.f[3]); |
| 598 | *x = 0; |
| 599 | *y = 0; |
| 600 | return; |
| 601 | } |
| 602 | |
| 603 | *x = v.f[0] / v.f[3]; |
| 604 | *y = v.f[1] / v.f[3]; |
| 605 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 606 | *x = sx + view->geometry.x; |
| 607 | *y = sy + view->geometry.y; |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 608 | } |
| 609 | } |
| 610 | |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 611 | WL_EXPORT void |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 612 | weston_transformed_coord(int width, int height, |
| 613 | enum wl_output_transform transform, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 614 | int32_t scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 615 | float sx, float sy, float *bx, float *by) |
| 616 | { |
| 617 | switch (transform) { |
| 618 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 619 | default: |
| 620 | *bx = sx; |
| 621 | *by = sy; |
| 622 | break; |
| 623 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 624 | *bx = width - sx; |
| 625 | *by = sy; |
| 626 | break; |
| 627 | case WL_OUTPUT_TRANSFORM_90: |
| 628 | *bx = height - sy; |
| 629 | *by = sx; |
| 630 | break; |
| 631 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 632 | *bx = height - sy; |
| 633 | *by = width - sx; |
| 634 | break; |
| 635 | case WL_OUTPUT_TRANSFORM_180: |
| 636 | *bx = width - sx; |
| 637 | *by = height - sy; |
| 638 | break; |
| 639 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 640 | *bx = sx; |
| 641 | *by = height - sy; |
| 642 | break; |
| 643 | case WL_OUTPUT_TRANSFORM_270: |
| 644 | *bx = sy; |
| 645 | *by = width - sx; |
| 646 | break; |
| 647 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 648 | *bx = sy; |
| 649 | *by = sx; |
| 650 | break; |
| 651 | } |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 652 | |
| 653 | *bx *= scale; |
| 654 | *by *= scale; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | WL_EXPORT pixman_box32_t |
| 658 | weston_transformed_rect(int width, int height, |
| 659 | enum wl_output_transform transform, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 660 | int32_t scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 661 | pixman_box32_t rect) |
| 662 | { |
| 663 | float x1, x2, y1, y2; |
| 664 | |
| 665 | pixman_box32_t ret; |
| 666 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 667 | weston_transformed_coord(width, height, transform, scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 668 | rect.x1, rect.y1, &x1, &y1); |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 669 | weston_transformed_coord(width, height, transform, scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 670 | rect.x2, rect.y2, &x2, &y2); |
| 671 | |
| 672 | if (x1 <= x2) { |
| 673 | ret.x1 = x1; |
| 674 | ret.x2 = x2; |
| 675 | } else { |
| 676 | ret.x1 = x2; |
| 677 | ret.x2 = x1; |
| 678 | } |
| 679 | |
| 680 | if (y1 <= y2) { |
| 681 | ret.y1 = y1; |
| 682 | ret.y2 = y2; |
| 683 | } else { |
| 684 | ret.y1 = y2; |
| 685 | ret.y2 = y1; |
| 686 | } |
| 687 | |
| 688 | return ret; |
| 689 | } |
| 690 | |
Derek Foreman | bc9a61c | 2015-11-18 16:32:30 -0600 | [diff] [blame] | 691 | /** Transform a region by a matrix, restricted to axis-aligned transformations |
| 692 | * |
| 693 | * Warning: This function does not work for projective, affine, or matrices |
| 694 | * that encode arbitrary rotations. Only 90-degree step rotations are |
| 695 | * supported. |
| 696 | */ |
| 697 | WL_EXPORT void |
| 698 | weston_matrix_transform_region(pixman_region32_t *dest, |
| 699 | struct weston_matrix *matrix, |
| 700 | pixman_region32_t *src) |
| 701 | { |
| 702 | pixman_box32_t *src_rects, *dest_rects; |
| 703 | int nrects, i; |
| 704 | |
| 705 | src_rects = pixman_region32_rectangles(src, &nrects); |
| 706 | dest_rects = malloc(nrects * sizeof(*dest_rects)); |
| 707 | if (!dest_rects) |
| 708 | return; |
| 709 | |
| 710 | for (i = 0; i < nrects; i++) { |
| 711 | struct weston_vector vec1 = {{ |
| 712 | src_rects[i].x1, src_rects[i].y1, 0, 1 |
| 713 | }}; |
| 714 | weston_matrix_transform(matrix, &vec1); |
| 715 | vec1.f[0] /= vec1.f[3]; |
| 716 | vec1.f[1] /= vec1.f[3]; |
| 717 | |
| 718 | struct weston_vector vec2 = {{ |
| 719 | src_rects[i].x2, src_rects[i].y2, 0, 1 |
| 720 | }}; |
| 721 | weston_matrix_transform(matrix, &vec2); |
| 722 | vec2.f[0] /= vec2.f[3]; |
| 723 | vec2.f[1] /= vec2.f[3]; |
| 724 | |
| 725 | if (vec1.f[0] < vec2.f[0]) { |
| 726 | dest_rects[i].x1 = floor(vec1.f[0]); |
| 727 | dest_rects[i].x2 = ceil(vec2.f[0]); |
| 728 | } else { |
| 729 | dest_rects[i].x1 = floor(vec2.f[0]); |
| 730 | dest_rects[i].x2 = ceil(vec1.f[0]); |
| 731 | } |
| 732 | |
Derek Foreman | bc9a61c | 2015-11-18 16:32:30 -0600 | [diff] [blame] | 733 | if (vec1.f[1] < vec2.f[1]) { |
| 734 | dest_rects[i].y1 = floor(vec1.f[1]); |
| 735 | dest_rects[i].y2 = ceil(vec2.f[1]); |
| 736 | } else { |
| 737 | dest_rects[i].y1 = floor(vec2.f[1]); |
| 738 | dest_rects[i].y2 = ceil(vec1.f[1]); |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | pixman_region32_clear(dest); |
| 743 | pixman_region32_init_rects(dest, dest_rects, nrects); |
| 744 | free(dest_rects); |
| 745 | } |
| 746 | |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 747 | WL_EXPORT void |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 748 | weston_transformed_region(int width, int height, |
| 749 | enum wl_output_transform transform, |
| 750 | int32_t scale, |
| 751 | pixman_region32_t *src, pixman_region32_t *dest) |
| 752 | { |
| 753 | pixman_box32_t *src_rects, *dest_rects; |
| 754 | int nrects, i; |
| 755 | |
| 756 | if (transform == WL_OUTPUT_TRANSFORM_NORMAL && scale == 1) { |
| 757 | if (src != dest) |
| 758 | pixman_region32_copy(dest, src); |
| 759 | return; |
| 760 | } |
| 761 | |
| 762 | src_rects = pixman_region32_rectangles(src, &nrects); |
| 763 | dest_rects = malloc(nrects * sizeof(*dest_rects)); |
| 764 | if (!dest_rects) |
| 765 | return; |
| 766 | |
| 767 | if (transform == WL_OUTPUT_TRANSFORM_NORMAL) { |
| 768 | memcpy(dest_rects, src_rects, nrects * sizeof(*dest_rects)); |
| 769 | } else { |
| 770 | for (i = 0; i < nrects; i++) { |
| 771 | switch (transform) { |
| 772 | default: |
| 773 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 774 | dest_rects[i].x1 = src_rects[i].x1; |
| 775 | dest_rects[i].y1 = src_rects[i].y1; |
| 776 | dest_rects[i].x2 = src_rects[i].x2; |
| 777 | dest_rects[i].y2 = src_rects[i].y2; |
| 778 | break; |
| 779 | case WL_OUTPUT_TRANSFORM_90: |
| 780 | dest_rects[i].x1 = height - src_rects[i].y2; |
| 781 | dest_rects[i].y1 = src_rects[i].x1; |
| 782 | dest_rects[i].x2 = height - src_rects[i].y1; |
| 783 | dest_rects[i].y2 = src_rects[i].x2; |
| 784 | break; |
| 785 | case WL_OUTPUT_TRANSFORM_180: |
| 786 | dest_rects[i].x1 = width - src_rects[i].x2; |
| 787 | dest_rects[i].y1 = height - src_rects[i].y2; |
| 788 | dest_rects[i].x2 = width - src_rects[i].x1; |
| 789 | dest_rects[i].y2 = height - src_rects[i].y1; |
| 790 | break; |
| 791 | case WL_OUTPUT_TRANSFORM_270: |
| 792 | dest_rects[i].x1 = src_rects[i].y1; |
| 793 | dest_rects[i].y1 = width - src_rects[i].x2; |
| 794 | dest_rects[i].x2 = src_rects[i].y2; |
| 795 | dest_rects[i].y2 = width - src_rects[i].x1; |
| 796 | break; |
| 797 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 798 | dest_rects[i].x1 = width - src_rects[i].x2; |
| 799 | dest_rects[i].y1 = src_rects[i].y1; |
| 800 | dest_rects[i].x2 = width - src_rects[i].x1; |
| 801 | dest_rects[i].y2 = src_rects[i].y2; |
| 802 | break; |
| 803 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 804 | dest_rects[i].x1 = height - src_rects[i].y2; |
| 805 | dest_rects[i].y1 = width - src_rects[i].x2; |
| 806 | dest_rects[i].x2 = height - src_rects[i].y1; |
| 807 | dest_rects[i].y2 = width - src_rects[i].x1; |
| 808 | break; |
| 809 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 810 | dest_rects[i].x1 = src_rects[i].x1; |
| 811 | dest_rects[i].y1 = height - src_rects[i].y2; |
| 812 | dest_rects[i].x2 = src_rects[i].x2; |
| 813 | dest_rects[i].y2 = height - src_rects[i].y1; |
| 814 | break; |
| 815 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 816 | dest_rects[i].x1 = src_rects[i].y1; |
| 817 | dest_rects[i].y1 = src_rects[i].x1; |
| 818 | dest_rects[i].x2 = src_rects[i].y2; |
| 819 | dest_rects[i].y2 = src_rects[i].x2; |
| 820 | break; |
| 821 | } |
| 822 | } |
| 823 | } |
| 824 | |
| 825 | if (scale != 1) { |
| 826 | for (i = 0; i < nrects; i++) { |
| 827 | dest_rects[i].x1 *= scale; |
| 828 | dest_rects[i].x2 *= scale; |
| 829 | dest_rects[i].y1 *= scale; |
| 830 | dest_rects[i].y2 *= scale; |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | pixman_region32_clear(dest); |
| 835 | pixman_region32_init_rects(dest, dest_rects, nrects); |
| 836 | free(dest_rects); |
| 837 | } |
| 838 | |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 839 | static void |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 840 | viewport_surface_to_buffer(struct weston_surface *surface, |
| 841 | float sx, float sy, float *bx, float *by) |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 842 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 843 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 844 | double src_width, src_height; |
| 845 | double src_x, src_y; |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 846 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 847 | if (vp->buffer.src_width == wl_fixed_from_int(-1)) { |
| 848 | if (vp->surface.width == -1) { |
| 849 | *bx = sx; |
| 850 | *by = sy; |
| 851 | return; |
| 852 | } |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 853 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 854 | src_x = 0.0; |
| 855 | src_y = 0.0; |
| 856 | src_width = surface->width_from_buffer; |
| 857 | src_height = surface->height_from_buffer; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 858 | } else { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 859 | src_x = wl_fixed_to_double(vp->buffer.src_x); |
| 860 | src_y = wl_fixed_to_double(vp->buffer.src_y); |
| 861 | src_width = wl_fixed_to_double(vp->buffer.src_width); |
| 862 | src_height = wl_fixed_to_double(vp->buffer.src_height); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 863 | } |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 864 | |
| 865 | *bx = sx * src_width / surface->width + src_x; |
| 866 | *by = sy * src_height / surface->height + src_y; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 867 | } |
| 868 | |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 869 | WL_EXPORT void |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 870 | weston_surface_to_buffer_float(struct weston_surface *surface, |
| 871 | float sx, float sy, float *bx, float *by) |
| 872 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 873 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
| 874 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 875 | /* first transform coordinates if the viewport is set */ |
| 876 | viewport_surface_to_buffer(surface, sx, sy, bx, by); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 877 | |
Jason Ekstrand | d0cebc3 | 2014-04-21 20:56:46 -0500 | [diff] [blame] | 878 | weston_transformed_coord(surface->width_from_buffer, |
| 879 | surface->height_from_buffer, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 880 | vp->buffer.transform, vp->buffer.scale, |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 881 | *bx, *by, bx, by); |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 882 | } |
| 883 | |
Derek Foreman | 9973967 | 2015-12-03 16:38:11 -0600 | [diff] [blame] | 884 | /** Transform a rectangle from surface coordinates to buffer coordinates |
| 885 | * |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 886 | * \param surface The surface to fetch wp_viewport and buffer transformation |
Derek Foreman | 9973967 | 2015-12-03 16:38:11 -0600 | [diff] [blame] | 887 | * from. |
| 888 | * \param rect The rectangle to transform. |
| 889 | * \return The transformed rectangle. |
| 890 | * |
| 891 | * Viewport and buffer transformations can only do translation, scaling, |
| 892 | * and rotations in 90-degree steps. Therefore the only loss in the |
| 893 | * conversion is coordinate rounding. |
| 894 | * |
| 895 | * However, some coordinate rounding takes place as an intermediate |
| 896 | * step before the buffer scale factor is applied, so the rectangle |
| 897 | * boundary may not be exactly as expected. |
| 898 | * |
| 899 | * This is OK for damage tracking since a little extra coverage is |
| 900 | * not a problem. |
| 901 | */ |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 902 | WL_EXPORT pixman_box32_t |
| 903 | weston_surface_to_buffer_rect(struct weston_surface *surface, |
| 904 | pixman_box32_t rect) |
| 905 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 906 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 907 | float xf, yf; |
| 908 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 909 | /* first transform box coordinates if the viewport is set */ |
| 910 | viewport_surface_to_buffer(surface, rect.x1, rect.y1, &xf, &yf); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 911 | rect.x1 = floorf(xf); |
| 912 | rect.y1 = floorf(yf); |
| 913 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 914 | viewport_surface_to_buffer(surface, rect.x2, rect.y2, &xf, &yf); |
Derek Foreman | e2e15ac | 2015-12-01 13:00:43 -0600 | [diff] [blame] | 915 | rect.x2 = ceilf(xf); |
| 916 | rect.y2 = ceilf(yf); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 917 | |
Jason Ekstrand | d0cebc3 | 2014-04-21 20:56:46 -0500 | [diff] [blame] | 918 | return weston_transformed_rect(surface->width_from_buffer, |
| 919 | surface->height_from_buffer, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 920 | vp->buffer.transform, vp->buffer.scale, |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 921 | rect); |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 922 | } |
| 923 | |
Pekka Paalanen | e54e31c | 2015-03-04 14:23:28 +0200 | [diff] [blame] | 924 | /** Transform a region from surface coordinates to buffer coordinates |
| 925 | * |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 926 | * \param surface The surface to fetch wp_viewport and buffer transformation |
Pekka Paalanen | e54e31c | 2015-03-04 14:23:28 +0200 | [diff] [blame] | 927 | * from. |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 928 | * \param[in] surface_region The region in surface coordinates. |
| 929 | * \param[out] buffer_region The region converted to buffer coordinates. |
Pekka Paalanen | e54e31c | 2015-03-04 14:23:28 +0200 | [diff] [blame] | 930 | * |
| 931 | * Buffer_region must be init'd, but will be completely overwritten. |
| 932 | * |
| 933 | * Viewport and buffer transformations can only do translation, scaling, |
| 934 | * and rotations in 90-degree steps. Therefore the only loss in the |
Derek Foreman | 9973967 | 2015-12-03 16:38:11 -0600 | [diff] [blame] | 935 | * conversion is from the coordinate rounding that takes place in |
| 936 | * \ref weston_surface_to_buffer_rect. |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 937 | * |
Pekka Paalanen | e54e31c | 2015-03-04 14:23:28 +0200 | [diff] [blame] | 938 | */ |
| 939 | WL_EXPORT void |
| 940 | weston_surface_to_buffer_region(struct weston_surface *surface, |
| 941 | pixman_region32_t *surface_region, |
| 942 | pixman_region32_t *buffer_region) |
| 943 | { |
| 944 | pixman_box32_t *src_rects, *dest_rects; |
| 945 | int nrects, i; |
| 946 | |
| 947 | src_rects = pixman_region32_rectangles(surface_region, &nrects); |
| 948 | dest_rects = malloc(nrects * sizeof(*dest_rects)); |
| 949 | if (!dest_rects) |
| 950 | return; |
| 951 | |
| 952 | for (i = 0; i < nrects; i++) { |
| 953 | dest_rects[i] = weston_surface_to_buffer_rect(surface, |
| 954 | src_rects[i]); |
| 955 | } |
| 956 | |
| 957 | pixman_region32_fini(buffer_region); |
| 958 | pixman_region32_init_rects(buffer_region, dest_rects, nrects); |
| 959 | free(dest_rects); |
| 960 | } |
| 961 | |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 962 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 963 | weston_view_move_to_plane(struct weston_view *view, |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 964 | struct weston_plane *plane) |
| 965 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 966 | if (view->plane == plane) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 967 | return; |
| 968 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 969 | weston_view_damage_below(view); |
| 970 | view->plane = plane; |
| 971 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 972 | } |
| 973 | |
Pekka Paalanen | 51723d5 | 2015-02-17 13:10:01 +0200 | [diff] [blame] | 974 | /** Inflict damage on the plane where the view is visible. |
| 975 | * |
| 976 | * \param view The view that causes the damage. |
| 977 | * |
| 978 | * If the view is currently on a plane (including the primary plane), |
| 979 | * take the view's boundingbox, subtract all the opaque views that cover it, |
| 980 | * and add the remaining region as damage to the plane. This corresponds |
| 981 | * to the damage inflicted to the plane if this view disappeared. |
| 982 | * |
| 983 | * A repaint is scheduled for this view. |
| 984 | * |
| 985 | * The region of all opaque views covering this view is stored in |
| 986 | * weston_view::clip and updated by view_accumulate_damage() during |
| 987 | * weston_output_repaint(). Specifically, that region matches the |
| 988 | * scenegraph as it was last painted. |
| 989 | */ |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 990 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 991 | weston_view_damage_below(struct weston_view *view) |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 992 | { |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 993 | pixman_region32_t damage; |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 994 | |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 995 | pixman_region32_init(&damage); |
Pekka Paalanen | 25c0ca5 | 2015-02-19 11:15:33 +0200 | [diff] [blame] | 996 | pixman_region32_subtract(&damage, &view->transform.boundingbox, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 997 | &view->clip); |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 998 | if (view->plane) |
| 999 | pixman_region32_union(&view->plane->damage, |
| 1000 | &view->plane->damage, &damage); |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 1001 | pixman_region32_fini(&damage); |
Kristian Høgsberg | a3a784a | 2013-11-13 21:33:43 -0800 | [diff] [blame] | 1002 | weston_view_schedule_repaint(view); |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 1003 | } |
| 1004 | |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1005 | /** Send wl_surface.enter/leave events |
| 1006 | * |
| 1007 | * \param surface The surface. |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 1008 | * \param head A head of the entered/left output. |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1009 | * \param enter True if entered. |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 1010 | * \param leave True if left. |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1011 | * |
| 1012 | * Send the enter/leave events for all protocol objects bound to the given |
| 1013 | * output by the client owning the surface. |
| 1014 | */ |
| 1015 | static void |
| 1016 | weston_surface_send_enter_leave(struct weston_surface *surface, |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 1017 | struct weston_head *head, |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1018 | bool enter, |
| 1019 | bool leave) |
| 1020 | { |
| 1021 | struct wl_resource *wloutput; |
| 1022 | struct wl_client *client; |
| 1023 | |
| 1024 | assert(enter != leave); |
| 1025 | |
| 1026 | client = wl_resource_get_client(surface->resource); |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 1027 | wl_resource_for_each(wloutput, &head->resource_list) { |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1028 | if (wl_resource_get_client(wloutput) != client) |
| 1029 | continue; |
| 1030 | |
| 1031 | if (enter) |
| 1032 | wl_surface_send_enter(surface->resource, wloutput); |
| 1033 | if (leave) |
| 1034 | wl_surface_send_leave(surface->resource, wloutput); |
| 1035 | } |
| 1036 | } |
| 1037 | |
Ankit Nautiyal | f74c35b | 2019-04-03 19:21:58 +0530 | [diff] [blame] | 1038 | static void |
| 1039 | weston_surface_compute_protection(struct protected_surface *psurface) |
| 1040 | { |
| 1041 | enum weston_hdcp_protection min_protection; |
| 1042 | bool min_protection_valid = false; |
| 1043 | struct weston_surface *surface = psurface->surface; |
| 1044 | struct weston_output *output; |
| 1045 | |
| 1046 | wl_list_for_each(output, &surface->compositor->output_list, link) |
| 1047 | if (surface->output_mask & (1u << output->id)) { |
Ankit Nautiyal | 4fd3813 | 2019-07-08 15:12:19 +0530 | [diff] [blame] | 1048 | /* |
| 1049 | * If the content-protection is enabled with protection |
| 1050 | * mode as RELAXED for a surface, and if |
| 1051 | * content-recording features like: screen-shooter, |
| 1052 | * recorder, screen-sharing, etc are on, then notify the |
| 1053 | * client, that the protection is disabled. |
| 1054 | * |
| 1055 | * Note: If the protection mode is ENFORCED then there |
| 1056 | * is no need to bother the client as the renderer takes |
| 1057 | * care of censoring the visibility of the protected |
| 1058 | * content. |
| 1059 | */ |
| 1060 | |
| 1061 | if (output->disable_planes > 0 && |
| 1062 | surface->protection_mode == WESTON_SURFACE_PROTECTION_MODE_RELAXED) { |
| 1063 | min_protection = WESTON_HDCP_DISABLE; |
| 1064 | min_protection_valid = true; |
| 1065 | break; |
| 1066 | } |
Ankit Nautiyal | f74c35b | 2019-04-03 19:21:58 +0530 | [diff] [blame] | 1067 | if (!min_protection_valid) { |
| 1068 | min_protection = output->current_protection; |
| 1069 | min_protection_valid = true; |
| 1070 | } |
| 1071 | if (output->current_protection < min_protection) |
| 1072 | min_protection = output->current_protection; |
| 1073 | } |
| 1074 | if (!min_protection_valid) |
| 1075 | min_protection = WESTON_HDCP_DISABLE; |
| 1076 | |
| 1077 | surface->current_protection = min_protection; |
Ankit Nautiyal | 4fd3813 | 2019-07-08 15:12:19 +0530 | [diff] [blame] | 1078 | |
| 1079 | weston_protected_surface_send_event(psurface, surface->current_protection); |
Ankit Nautiyal | f74c35b | 2019-04-03 19:21:58 +0530 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | static void |
| 1083 | notify_surface_protection_change(void *data) |
| 1084 | { |
| 1085 | struct weston_compositor *compositor = data; |
| 1086 | struct content_protection *cp; |
| 1087 | struct protected_surface *psurface; |
| 1088 | |
| 1089 | cp = compositor->content_protection; |
| 1090 | cp->surface_protection_update = NULL; |
| 1091 | |
| 1092 | /* Notify the clients, whose surfaces are changed */ |
| 1093 | wl_list_for_each(psurface, &cp->protected_list, link) |
| 1094 | if (psurface && psurface->surface) |
| 1095 | weston_surface_compute_protection(psurface); |
| 1096 | } |
| 1097 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1098 | /** |
Ankit Nautiyal | faa5ab4 | 2019-07-08 13:23:24 +0530 | [diff] [blame] | 1099 | * \param compositor weston_compositor |
| 1100 | * |
| 1101 | * Schedule an idle task to notify surface about the update in protection, |
| 1102 | * if not already scheduled. |
| 1103 | */ |
| 1104 | static void |
| 1105 | weston_schedule_surface_protection_update(struct weston_compositor *compositor) |
| 1106 | { |
| 1107 | struct content_protection *cp = compositor->content_protection; |
| 1108 | struct wl_event_loop *loop; |
| 1109 | |
| 1110 | if (!cp || cp->surface_protection_update) |
| 1111 | return; |
| 1112 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 1113 | cp->surface_protection_update = wl_event_loop_add_idle(loop, |
| 1114 | notify_surface_protection_change, |
| 1115 | compositor); |
| 1116 | } |
| 1117 | |
| 1118 | /** |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1119 | * \param es The surface |
| 1120 | * \param mask The new set of outputs for the surface |
| 1121 | * |
| 1122 | * Sets the surface's set of outputs to the ones specified by |
| 1123 | * the new output mask provided. Identifies the outputs that |
| 1124 | * have changed, the posts enter and leave events for these |
| 1125 | * outputs as appropriate. |
| 1126 | */ |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1127 | static void |
| 1128 | weston_surface_update_output_mask(struct weston_surface *es, uint32_t mask) |
| 1129 | { |
| 1130 | uint32_t different = es->output_mask ^ mask; |
| 1131 | uint32_t entered = mask & different; |
| 1132 | uint32_t left = es->output_mask & different; |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1133 | uint32_t output_bit; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1134 | struct weston_output *output; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 1135 | struct weston_head *head; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1136 | |
| 1137 | es->output_mask = mask; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1138 | if (es->resource == NULL) |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1139 | return; |
| 1140 | if (different == 0) |
| 1141 | return; |
| 1142 | |
| 1143 | wl_list_for_each(output, &es->compositor->output_list, link) { |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1144 | output_bit = 1u << output->id; |
| 1145 | if (!(output_bit & different)) |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1146 | continue; |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1147 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 1148 | wl_list_for_each(head, &output->head_list, output_link) { |
| 1149 | weston_surface_send_enter_leave(es, head, |
| 1150 | output_bit & entered, |
| 1151 | output_bit & left); |
| 1152 | } |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1153 | } |
Ankit Nautiyal | f74c35b | 2019-04-03 19:21:58 +0530 | [diff] [blame] | 1154 | /* |
| 1155 | * Change in surfaces' output mask might trigger a change in its |
| 1156 | * protection. |
| 1157 | */ |
Ankit Nautiyal | faa5ab4 | 2019-07-08 13:23:24 +0530 | [diff] [blame] | 1158 | weston_schedule_surface_protection_update(es->compositor); |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1159 | } |
| 1160 | |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 1161 | static void |
| 1162 | notify_view_output_destroy(struct wl_listener *listener, void *data) |
| 1163 | { |
| 1164 | struct weston_view *view = |
| 1165 | container_of(listener, |
| 1166 | struct weston_view, output_destroy_listener); |
| 1167 | |
| 1168 | view->output = NULL; |
| 1169 | view->output_destroy_listener.notify = NULL; |
| 1170 | } |
| 1171 | |
| 1172 | /** Set the primary output of the view |
| 1173 | * |
| 1174 | * \param view The view whose primary output to set |
| 1175 | * \param output The new primary output for the view |
| 1176 | * |
| 1177 | * Set \a output to be the primary output of the \a view. |
| 1178 | * |
| 1179 | * Notice that the assignment may be temporary; the primary output could be |
| 1180 | * automatically changed. Hence, one cannot rely on the value persisting. |
| 1181 | * |
| 1182 | * Passing NULL as /a output will set the primary output to NULL. |
| 1183 | */ |
| 1184 | WL_EXPORT void |
| 1185 | weston_view_set_output(struct weston_view *view, struct weston_output *output) |
| 1186 | { |
| 1187 | if (view->output_destroy_listener.notify) { |
| 1188 | wl_list_remove(&view->output_destroy_listener.link); |
| 1189 | view->output_destroy_listener.notify = NULL; |
| 1190 | } |
| 1191 | view->output = output; |
| 1192 | if (output) { |
| 1193 | view->output_destroy_listener.notify = |
| 1194 | notify_view_output_destroy; |
| 1195 | wl_signal_add(&output->destroy_signal, |
| 1196 | &view->output_destroy_listener); |
| 1197 | } |
| 1198 | } |
| 1199 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1200 | /** Recalculate which output(s) the surface has views displayed on |
| 1201 | * |
| 1202 | * \param es The surface to remap to outputs |
| 1203 | * |
| 1204 | * Finds the output that is showing the largest amount of one |
| 1205 | * of the surface's various views. This output becomes the |
Pekka Paalanen | 130ae6e | 2016-03-30 14:33:33 +0300 | [diff] [blame] | 1206 | * surface's primary output for vsync and frame callback purposes. |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1207 | * |
Pekka Paalanen | 130ae6e | 2016-03-30 14:33:33 +0300 | [diff] [blame] | 1208 | * Also notes all outputs of all of the surface's views |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1209 | * in the output_mask for the surface. |
| 1210 | */ |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1211 | static void |
| 1212 | weston_surface_assign_output(struct weston_surface *es) |
| 1213 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1214 | struct weston_output *new_output; |
| 1215 | struct weston_view *view; |
| 1216 | pixman_region32_t region; |
| 1217 | uint32_t max, area, mask; |
| 1218 | pixman_box32_t *e; |
| 1219 | |
| 1220 | new_output = NULL; |
| 1221 | max = 0; |
| 1222 | mask = 0; |
| 1223 | pixman_region32_init(®ion); |
| 1224 | wl_list_for_each(view, &es->views, surface_link) { |
| 1225 | if (!view->output) |
| 1226 | continue; |
| 1227 | |
| 1228 | pixman_region32_intersect(®ion, &view->transform.boundingbox, |
| 1229 | &view->output->region); |
| 1230 | |
| 1231 | e = pixman_region32_extents(®ion); |
| 1232 | area = (e->x2 - e->x1) * (e->y2 - e->y1); |
| 1233 | |
| 1234 | mask |= view->output_mask; |
| 1235 | |
| 1236 | if (area >= max) { |
| 1237 | new_output = view->output; |
| 1238 | max = area; |
| 1239 | } |
| 1240 | } |
| 1241 | pixman_region32_fini(®ion); |
| 1242 | |
| 1243 | es->output = new_output; |
| 1244 | weston_surface_update_output_mask(es, mask); |
| 1245 | } |
| 1246 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1247 | /** Recalculate which output(s) the view is displayed on |
| 1248 | * |
| 1249 | * \param ev The view to remap to outputs |
| 1250 | * |
| 1251 | * Identifies the set of outputs that the view is visible on, |
| 1252 | * noting them into the output_mask. The output that the view |
Pekka Paalanen | 130ae6e | 2016-03-30 14:33:33 +0300 | [diff] [blame] | 1253 | * is most visible on is set as the view's primary output. |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1254 | * |
| 1255 | * Also does the same for the view's surface. See |
| 1256 | * weston_surface_assign_output(). |
| 1257 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1258 | static void |
| 1259 | weston_view_assign_output(struct weston_view *ev) |
| 1260 | { |
| 1261 | struct weston_compositor *ec = ev->surface->compositor; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1262 | struct weston_output *output, *new_output; |
| 1263 | pixman_region32_t region; |
| 1264 | uint32_t max, area, mask; |
| 1265 | pixman_box32_t *e; |
| 1266 | |
| 1267 | new_output = NULL; |
| 1268 | max = 0; |
| 1269 | mask = 0; |
| 1270 | pixman_region32_init(®ion); |
| 1271 | wl_list_for_each(output, &ec->output_list, link) { |
Giulio Camuffo | 2f2a70c | 2015-07-12 10:52:32 +0300 | [diff] [blame] | 1272 | if (output->destroying) |
| 1273 | continue; |
| 1274 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1275 | pixman_region32_intersect(®ion, &ev->transform.boundingbox, |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1276 | &output->region); |
| 1277 | |
| 1278 | e = pixman_region32_extents(®ion); |
| 1279 | area = (e->x2 - e->x1) * (e->y2 - e->y1); |
| 1280 | |
| 1281 | if (area > 0) |
Bryce Harrington | 89324ce | 2015-12-23 18:38:07 -0800 | [diff] [blame] | 1282 | mask |= 1u << output->id; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1283 | |
| 1284 | if (area >= max) { |
| 1285 | new_output = output; |
| 1286 | max = area; |
| 1287 | } |
| 1288 | } |
| 1289 | pixman_region32_fini(®ion); |
| 1290 | |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 1291 | weston_view_set_output(ev, new_output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1292 | ev->output_mask = mask; |
| 1293 | |
| 1294 | weston_surface_assign_output(ev->surface); |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1295 | } |
| 1296 | |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 1297 | static void |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1298 | weston_view_to_view_map(struct weston_view *from, struct weston_view *to, |
| 1299 | int from_x, int from_y, int *to_x, int *to_y) |
| 1300 | { |
| 1301 | float x, y; |
| 1302 | |
| 1303 | weston_view_to_global_float(from, from_x, from_y, &x, &y); |
| 1304 | weston_view_from_global_float(to, x, y, &x, &y); |
| 1305 | |
| 1306 | *to_x = round(x); |
| 1307 | *to_y = round(y); |
| 1308 | } |
| 1309 | |
| 1310 | static void |
| 1311 | weston_view_transfer_scissor(struct weston_view *from, struct weston_view *to) |
| 1312 | { |
| 1313 | pixman_box32_t *a; |
| 1314 | pixman_box32_t b; |
| 1315 | |
| 1316 | a = pixman_region32_extents(&from->geometry.scissor); |
| 1317 | |
| 1318 | weston_view_to_view_map(from, to, a->x1, a->y1, &b.x1, &b.y1); |
| 1319 | weston_view_to_view_map(from, to, a->x2, a->y2, &b.x2, &b.y2); |
| 1320 | |
| 1321 | pixman_region32_fini(&to->geometry.scissor); |
| 1322 | pixman_region32_init_with_extents(&to->geometry.scissor, &b); |
| 1323 | } |
| 1324 | |
| 1325 | static void |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 1326 | view_compute_bbox(struct weston_view *view, const pixman_box32_t *inbox, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1327 | pixman_region32_t *bbox) |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1328 | { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1329 | float min_x = HUGE_VALF, min_y = HUGE_VALF; |
| 1330 | float max_x = -HUGE_VALF, max_y = -HUGE_VALF; |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1331 | int32_t s[4][2] = { |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 1332 | { inbox->x1, inbox->y1 }, |
| 1333 | { inbox->x1, inbox->y2 }, |
| 1334 | { inbox->x2, inbox->y1 }, |
| 1335 | { inbox->x2, inbox->y2 }, |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1336 | }; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1337 | float int_x, int_y; |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1338 | int i; |
| 1339 | |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 1340 | if (inbox->x1 == inbox->x2 || inbox->y1 == inbox->y2) { |
Pekka Paalanen | 7c7d464 | 2012-09-04 13:55:44 +0300 | [diff] [blame] | 1341 | /* avoid rounding empty bbox to 1x1 */ |
| 1342 | pixman_region32_init(bbox); |
| 1343 | return; |
| 1344 | } |
| 1345 | |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1346 | for (i = 0; i < 4; ++i) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1347 | float x, y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1348 | 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] | 1349 | if (x < min_x) |
| 1350 | min_x = x; |
| 1351 | if (x > max_x) |
| 1352 | max_x = x; |
| 1353 | if (y < min_y) |
| 1354 | min_y = y; |
| 1355 | if (y > max_y) |
| 1356 | max_y = y; |
| 1357 | } |
| 1358 | |
Pekka Paalanen | 219b982 | 2012-02-08 15:38:37 +0200 | [diff] [blame] | 1359 | int_x = floorf(min_x); |
| 1360 | int_y = floorf(min_y); |
| 1361 | pixman_region32_init_rect(bbox, int_x, int_y, |
| 1362 | ceilf(max_x) - int_x, ceilf(max_y) - int_y); |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1363 | } |
| 1364 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1365 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1366 | weston_view_update_transform_disable(struct weston_view *view) |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1367 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1368 | view->transform.enabled = 0; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1369 | |
Pekka Paalanen | cc2f868 | 2012-02-13 10:34:04 +0200 | [diff] [blame] | 1370 | /* round off fractions when not transformed */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1371 | view->geometry.x = roundf(view->geometry.x); |
| 1372 | view->geometry.y = roundf(view->geometry.y); |
Pekka Paalanen | cc2f868 | 2012-02-13 10:34:04 +0200 | [diff] [blame] | 1373 | |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1374 | /* Otherwise identity matrix, but with x and y translation. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1375 | view->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE; |
| 1376 | view->transform.position.matrix.d[12] = view->geometry.x; |
| 1377 | view->transform.position.matrix.d[13] = view->geometry.y; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1378 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1379 | view->transform.matrix = view->transform.position.matrix; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1380 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1381 | view->transform.inverse = view->transform.position.matrix; |
| 1382 | view->transform.inverse.d[12] = -view->geometry.x; |
| 1383 | view->transform.inverse.d[13] = -view->geometry.y; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1384 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1385 | pixman_region32_init_rect(&view->transform.boundingbox, |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1386 | 0, 0, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1387 | view->surface->width, |
| 1388 | view->surface->height); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1389 | if (view->geometry.scissor_enabled) |
| 1390 | pixman_region32_intersect(&view->transform.boundingbox, |
| 1391 | &view->transform.boundingbox, |
| 1392 | &view->geometry.scissor); |
| 1393 | |
| 1394 | pixman_region32_translate(&view->transform.boundingbox, |
| 1395 | view->geometry.x, view->geometry.y); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1396 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1397 | if (view->alpha == 1.0) { |
| 1398 | pixman_region32_copy(&view->transform.opaque, |
| 1399 | &view->surface->opaque); |
| 1400 | pixman_region32_translate(&view->transform.opaque, |
| 1401 | view->geometry.x, |
| 1402 | view->geometry.y); |
Kristian Høgsberg | 3b4af20 | 2012-02-28 09:19:39 -0500 | [diff] [blame] | 1403 | } |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1404 | } |
| 1405 | |
| 1406 | static int |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1407 | weston_view_update_transform_enable(struct weston_view *view) |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1408 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1409 | struct weston_view *parent = view->geometry.parent; |
| 1410 | struct weston_matrix *matrix = &view->transform.matrix; |
| 1411 | struct weston_matrix *inverse = &view->transform.inverse; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1412 | struct weston_transform *tform; |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1413 | pixman_region32_t surfregion; |
| 1414 | const pixman_box32_t *surfbox; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1415 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1416 | view->transform.enabled = 1; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1417 | |
| 1418 | /* Otherwise identity matrix, but with x and y translation. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1419 | view->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE; |
| 1420 | view->transform.position.matrix.d[12] = view->geometry.x; |
| 1421 | view->transform.position.matrix.d[13] = view->geometry.y; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1422 | |
| 1423 | weston_matrix_init(matrix); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1424 | wl_list_for_each(tform, &view->geometry.transformation_list, link) |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1425 | weston_matrix_multiply(matrix, &tform->matrix); |
| 1426 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1427 | if (parent) |
| 1428 | weston_matrix_multiply(matrix, &parent->transform.matrix); |
| 1429 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1430 | if (weston_matrix_invert(inverse, matrix) < 0) { |
| 1431 | /* Oops, bad total transformation, not invertible */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1432 | weston_log("error: weston_view %p" |
| 1433 | " transformation not invertible.\n", view); |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1434 | return -1; |
| 1435 | } |
| 1436 | |
Giulio Camuffo | 148c199 | 2016-09-04 18:50:46 +0300 | [diff] [blame] | 1437 | if (view->alpha == 1.0 && |
| 1438 | matrix->type == WESTON_MATRIX_TRANSFORM_TRANSLATE) { |
| 1439 | pixman_region32_copy(&view->transform.opaque, |
| 1440 | &view->surface->opaque); |
| 1441 | pixman_region32_translate(&view->transform.opaque, |
| 1442 | matrix->d[12], |
| 1443 | matrix->d[13]); |
| 1444 | } |
| 1445 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1446 | pixman_region32_init_rect(&surfregion, 0, 0, |
| 1447 | view->surface->width, view->surface->height); |
| 1448 | if (view->geometry.scissor_enabled) |
| 1449 | pixman_region32_intersect(&surfregion, &surfregion, |
| 1450 | &view->geometry.scissor); |
| 1451 | surfbox = pixman_region32_extents(&surfregion); |
| 1452 | |
| 1453 | view_compute_bbox(view, surfbox, &view->transform.boundingbox); |
| 1454 | pixman_region32_fini(&surfregion); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1455 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1456 | return 0; |
| 1457 | } |
| 1458 | |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1459 | static struct weston_layer * |
| 1460 | get_view_layer(struct weston_view *view) |
| 1461 | { |
| 1462 | if (view->parent_view) |
| 1463 | return get_view_layer(view->parent_view); |
| 1464 | return view->layer_link.layer; |
| 1465 | } |
| 1466 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1467 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1468 | weston_view_update_transform(struct weston_view *view) |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1469 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1470 | struct weston_view *parent = view->geometry.parent; |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1471 | struct weston_layer *layer; |
| 1472 | pixman_region32_t mask; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1473 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1474 | if (!view->transform.dirty) |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1475 | return; |
| 1476 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1477 | if (parent) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1478 | weston_view_update_transform(parent); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1479 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1480 | view->transform.dirty = 0; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1481 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1482 | weston_view_damage_below(view); |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 1483 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1484 | pixman_region32_fini(&view->transform.boundingbox); |
| 1485 | pixman_region32_fini(&view->transform.opaque); |
| 1486 | pixman_region32_init(&view->transform.opaque); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1487 | |
Pekka Paalanen | cd40362 | 2012-01-25 13:37:39 +0200 | [diff] [blame] | 1488 | /* transform.position is always in transformation_list */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1489 | if (view->geometry.transformation_list.next == |
| 1490 | &view->transform.position.link && |
| 1491 | view->geometry.transformation_list.prev == |
| 1492 | &view->transform.position.link && |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1493 | !parent) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1494 | weston_view_update_transform_disable(view); |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1495 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1496 | if (weston_view_update_transform_enable(view) < 0) |
| 1497 | weston_view_update_transform_disable(view); |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1498 | } |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 1499 | |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1500 | layer = get_view_layer(view); |
| 1501 | if (layer) { |
| 1502 | pixman_region32_init_with_extents(&mask, &layer->mask); |
Pekka Paalanen | 25c0ca5 | 2015-02-19 11:15:33 +0200 | [diff] [blame] | 1503 | pixman_region32_intersect(&view->transform.boundingbox, |
| 1504 | &view->transform.boundingbox, &mask); |
Pekka Paalanen | 8844bf2 | 2015-02-18 16:30:47 +0200 | [diff] [blame] | 1505 | pixman_region32_intersect(&view->transform.opaque, |
| 1506 | &view->transform.opaque, &mask); |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1507 | pixman_region32_fini(&mask); |
| 1508 | } |
| 1509 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1510 | if (parent) { |
| 1511 | if (parent->geometry.scissor_enabled) { |
| 1512 | view->geometry.scissor_enabled = true; |
| 1513 | weston_view_transfer_scissor(parent, view); |
| 1514 | } else { |
| 1515 | view->geometry.scissor_enabled = false; |
| 1516 | } |
| 1517 | } |
| 1518 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1519 | weston_view_damage_below(view); |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 1520 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1521 | weston_view_assign_output(view); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 1522 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1523 | wl_signal_emit(&view->surface->compositor->transform_signal, |
| 1524 | view->surface); |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1525 | } |
| 1526 | |
Pekka Paalanen | ddae03c | 2012-02-06 14:54:20 +0200 | [diff] [blame] | 1527 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1528 | weston_view_geometry_dirty(struct weston_view *view) |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 1529 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1530 | struct weston_view *child; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1531 | |
| 1532 | /* |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1533 | * The invariant: if view->geometry.dirty, then all views |
| 1534 | * in view->geometry.child_list have geometry.dirty too. |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1535 | * Corollary: if not parent->geometry.dirty, then all ancestors |
| 1536 | * are not dirty. |
| 1537 | */ |
| 1538 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1539 | if (view->transform.dirty) |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1540 | return; |
| 1541 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1542 | view->transform.dirty = 1; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1543 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1544 | wl_list_for_each(child, &view->geometry.child_list, |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1545 | geometry.parent_link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1546 | weston_view_geometry_dirty(child); |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 1547 | } |
| 1548 | |
| 1549 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1550 | weston_view_to_global_fixed(struct weston_view *view, |
| 1551 | wl_fixed_t vx, wl_fixed_t vy, |
| 1552 | wl_fixed_t *x, wl_fixed_t *y) |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1553 | { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1554 | float xf, yf; |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1555 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1556 | weston_view_to_global_float(view, |
| 1557 | wl_fixed_to_double(vx), |
| 1558 | wl_fixed_to_double(vy), |
| 1559 | &xf, &yf); |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1560 | *x = wl_fixed_from_double(xf); |
| 1561 | *y = wl_fixed_from_double(yf); |
| 1562 | } |
| 1563 | |
Kristian Høgsberg | ecf6ede | 2012-09-05 21:59:35 -0400 | [diff] [blame] | 1564 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1565 | weston_view_from_global_float(struct weston_view *view, |
| 1566 | float x, float y, float *vx, float *vy) |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1567 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1568 | if (view->transform.enabled) { |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1569 | struct weston_vector v = { { x, y, 0.0f, 1.0f } }; |
| 1570 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1571 | weston_matrix_transform(&view->transform.inverse, &v); |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1572 | |
| 1573 | if (fabsf(v.f[3]) < 1e-6) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1574 | weston_log("warning: numerical instability in " |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1575 | "weston_view_from_global(), divisor = %g\n", |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1576 | v.f[3]); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1577 | *vx = 0; |
| 1578 | *vy = 0; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1579 | return; |
| 1580 | } |
| 1581 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1582 | *vx = v.f[0] / v.f[3]; |
| 1583 | *vy = v.f[1] / v.f[3]; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1584 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1585 | *vx = x - view->geometry.x; |
| 1586 | *vy = y - view->geometry.y; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1587 | } |
| 1588 | } |
| 1589 | |
| 1590 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1591 | weston_view_from_global_fixed(struct weston_view *view, |
| 1592 | wl_fixed_t x, wl_fixed_t y, |
| 1593 | wl_fixed_t *vx, wl_fixed_t *vy) |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1594 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1595 | float vxf, vyf; |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1596 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1597 | weston_view_from_global_float(view, |
| 1598 | wl_fixed_to_double(x), |
| 1599 | wl_fixed_to_double(y), |
| 1600 | &vxf, &vyf); |
| 1601 | *vx = wl_fixed_from_double(vxf); |
| 1602 | *vy = wl_fixed_from_double(vyf); |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1606 | weston_view_from_global(struct weston_view *view, |
| 1607 | int32_t x, int32_t y, int32_t *vx, int32_t *vy) |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1608 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1609 | float vxf, vyf; |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1610 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1611 | weston_view_from_global_float(view, x, y, &vxf, &vyf); |
| 1612 | *vx = floorf(vxf); |
| 1613 | *vy = floorf(vyf); |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1614 | } |
| 1615 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1616 | /** |
| 1617 | * \param surface The surface to be repainted |
| 1618 | * |
| 1619 | * Marks the output(s) that the surface is shown on as needing to be |
| 1620 | * repainted. See weston_output_schedule_repaint(). |
| 1621 | */ |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1622 | WL_EXPORT void |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1623 | weston_surface_schedule_repaint(struct weston_surface *surface) |
| 1624 | { |
| 1625 | struct weston_output *output; |
| 1626 | |
| 1627 | wl_list_for_each(output, &surface->compositor->output_list, link) |
Bryce Harrington | 89324ce | 2015-12-23 18:38:07 -0800 | [diff] [blame] | 1628 | if (surface->output_mask & (1u << output->id)) |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1629 | weston_output_schedule_repaint(output); |
| 1630 | } |
| 1631 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1632 | /** |
| 1633 | * \param view The view to be repainted |
| 1634 | * |
| 1635 | * Marks the output(s) that the view is shown on as needing to be |
| 1636 | * repainted. See weston_output_schedule_repaint(). |
| 1637 | */ |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1638 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1639 | weston_view_schedule_repaint(struct weston_view *view) |
| 1640 | { |
| 1641 | struct weston_output *output; |
| 1642 | |
| 1643 | wl_list_for_each(output, &view->surface->compositor->output_list, link) |
Bryce Harrington | 89324ce | 2015-12-23 18:38:07 -0800 | [diff] [blame] | 1644 | if (view->output_mask & (1u << output->id)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1645 | weston_output_schedule_repaint(output); |
| 1646 | } |
| 1647 | |
Pekka Paalanen | e508ce6 | 2015-02-19 13:59:55 +0200 | [diff] [blame] | 1648 | /** |
| 1649 | * XXX: This function does it the wrong way. |
| 1650 | * surface->damage is the damage from the client, and causes |
| 1651 | * surface_flush_damage() to copy pixels. No window management action can |
| 1652 | * cause damage to the client-provided content, warranting re-upload! |
| 1653 | * |
| 1654 | * Instead of surface->damage, this function should record the damage |
| 1655 | * with all the views for this surface to avoid extraneous texture |
| 1656 | * uploads. |
| 1657 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1658 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1659 | weston_surface_damage(struct weston_surface *surface) |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 1660 | { |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1661 | pixman_region32_union_rect(&surface->damage, &surface->damage, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1662 | 0, 0, surface->width, |
| 1663 | surface->height); |
Pekka Paalanen | 2267d45 | 2012-01-26 13:12:45 +0200 | [diff] [blame] | 1664 | |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1665 | weston_surface_schedule_repaint(surface); |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 1666 | } |
| 1667 | |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 1668 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1669 | weston_view_set_position(struct weston_view *view, float x, float y) |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1670 | { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1671 | if (view->geometry.x == x && view->geometry.y == y) |
| 1672 | return; |
| 1673 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1674 | view->geometry.x = x; |
| 1675 | view->geometry.y = y; |
| 1676 | weston_view_geometry_dirty(view); |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1677 | } |
| 1678 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1679 | static void |
| 1680 | transform_parent_handle_parent_destroy(struct wl_listener *listener, |
| 1681 | void *data) |
| 1682 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1683 | struct weston_view *view = |
| 1684 | container_of(listener, struct weston_view, |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1685 | geometry.parent_destroy_listener); |
| 1686 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1687 | weston_view_set_transform_parent(view, NULL); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1688 | } |
| 1689 | |
| 1690 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1691 | weston_view_set_transform_parent(struct weston_view *view, |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1692 | struct weston_view *parent) |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1693 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1694 | if (view->geometry.parent) { |
| 1695 | wl_list_remove(&view->geometry.parent_destroy_listener.link); |
| 1696 | wl_list_remove(&view->geometry.parent_link); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1697 | |
| 1698 | if (!parent) |
| 1699 | view->geometry.scissor_enabled = false; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1700 | } |
| 1701 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1702 | view->geometry.parent = parent; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1703 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1704 | view->geometry.parent_destroy_listener.notify = |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1705 | transform_parent_handle_parent_destroy; |
| 1706 | if (parent) { |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1707 | wl_signal_add(&parent->destroy_signal, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1708 | &view->geometry.parent_destroy_listener); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1709 | wl_list_insert(&parent->geometry.child_list, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1710 | &view->geometry.parent_link); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1711 | } |
| 1712 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1713 | weston_view_geometry_dirty(view); |
| 1714 | } |
| 1715 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1716 | /** Set a clip mask rectangle on a view |
| 1717 | * |
| 1718 | * \param view The view to set the clip mask on. |
| 1719 | * \param x Top-left corner X coordinate of the clip rectangle. |
| 1720 | * \param y Top-left corner Y coordinate of the clip rectangle. |
| 1721 | * \param width Width of the clip rectangle, non-negative. |
| 1722 | * \param height Height of the clip rectangle, non-negative. |
| 1723 | * |
| 1724 | * A shell may set a clip mask rectangle on a view. Everything outside |
| 1725 | * the rectangle is cut away for input and output purposes: it is |
| 1726 | * not drawn and cannot be hit by hit-test based input like pointer |
| 1727 | * motion or touch-downs. Everything inside the rectangle will behave |
| 1728 | * normally. Clients are unaware of clipping. |
| 1729 | * |
Yong Bakos | 4c72e29 | 2016-04-28 11:59:10 -0500 | [diff] [blame] | 1730 | * The rectangle is set in surface-local coordinates. Setting a clip |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1731 | * mask rectangle does not affect the view position, the view is positioned |
| 1732 | * as it would be without a clip. The clip also does not change |
| 1733 | * weston_surface::width,height. |
| 1734 | * |
| 1735 | * The clip mask rectangle is part of transformation inheritance |
| 1736 | * (weston_view_set_transform_parent()). A clip set in the root of the |
| 1737 | * transformation inheritance tree will affect all views in the tree. |
| 1738 | * A clip can be set only on the root view. Attempting to set a clip |
| 1739 | * on view that has a transformation parent will fail. Assigning a parent |
| 1740 | * to a view that has a clip set will cause the clip to be forgotten. |
| 1741 | * |
| 1742 | * Because the clip mask is an axis-aligned rectangle, it poses restrictions |
| 1743 | * on the additional transformations in the child views. These transformations |
| 1744 | * may not rotate the coordinate axes, i.e., only translation and scaling |
| 1745 | * are allowed. Violating this restriction causes the clipping to malfunction. |
| 1746 | * Furthermore, using scaling may cause rounding errors in child clipping. |
| 1747 | * |
| 1748 | * The clip mask rectangle is not automatically adjusted based on |
| 1749 | * wl_surface.attach dx and dy arguments. |
| 1750 | * |
| 1751 | * A clip mask rectangle can be set only if the compositor capability |
| 1752 | * WESTON_CAP_VIEW_CLIP_MASK is present. |
| 1753 | * |
| 1754 | * This function sets the clip mask rectangle and schedules a repaint for |
| 1755 | * the view. |
| 1756 | */ |
| 1757 | WL_EXPORT void |
| 1758 | weston_view_set_mask(struct weston_view *view, |
| 1759 | int x, int y, int width, int height) |
| 1760 | { |
| 1761 | struct weston_compositor *compositor = view->surface->compositor; |
| 1762 | |
| 1763 | if (!(compositor->capabilities & WESTON_CAP_VIEW_CLIP_MASK)) { |
| 1764 | weston_log("%s not allowed without capability!\n", __func__); |
| 1765 | return; |
| 1766 | } |
| 1767 | |
| 1768 | if (view->geometry.parent) { |
| 1769 | weston_log("view %p has a parent, clip forbidden!\n", view); |
| 1770 | return; |
| 1771 | } |
| 1772 | |
| 1773 | if (width < 0 || height < 0) { |
| 1774 | weston_log("%s: illegal args %d, %d, %d, %d\n", __func__, |
| 1775 | x, y, width, height); |
| 1776 | return; |
| 1777 | } |
| 1778 | |
| 1779 | pixman_region32_fini(&view->geometry.scissor); |
| 1780 | pixman_region32_init_rect(&view->geometry.scissor, x, y, width, height); |
| 1781 | view->geometry.scissor_enabled = true; |
| 1782 | weston_view_geometry_dirty(view); |
| 1783 | weston_view_schedule_repaint(view); |
| 1784 | } |
| 1785 | |
| 1786 | /** Remove the clip mask from a view |
| 1787 | * |
| 1788 | * \param view The view to remove the clip mask from. |
| 1789 | * |
| 1790 | * Removed the clip mask rectangle and schedules a repaint. |
| 1791 | * |
| 1792 | * \sa weston_view_set_mask |
| 1793 | */ |
| 1794 | WL_EXPORT void |
| 1795 | weston_view_set_mask_infinite(struct weston_view *view) |
| 1796 | { |
| 1797 | view->geometry.scissor_enabled = false; |
| 1798 | weston_view_geometry_dirty(view); |
| 1799 | weston_view_schedule_repaint(view); |
| 1800 | } |
| 1801 | |
Armin Krezović | 0da12b8 | 2016-06-30 06:04:33 +0200 | [diff] [blame] | 1802 | /* Check if view should be displayed |
| 1803 | * |
| 1804 | * The indicator is set manually when assigning |
| 1805 | * a view to a surface. |
| 1806 | * |
| 1807 | * This needs reworking. See the thread starting at: |
| 1808 | * |
| 1809 | * https://lists.freedesktop.org/archives/wayland-devel/2016-June/029656.html |
| 1810 | */ |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 1811 | WL_EXPORT bool |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1812 | weston_view_is_mapped(struct weston_view *view) |
| 1813 | { |
Armin Krezović | 0da12b8 | 2016-06-30 06:04:33 +0200 | [diff] [blame] | 1814 | return view->is_mapped; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1815 | } |
| 1816 | |
Philipp Zabel | 70decd5 | 2018-09-03 20:11:15 +0200 | [diff] [blame] | 1817 | /* Check if view is opaque in specified region |
| 1818 | * |
| 1819 | * \param view The view to check for opacity. |
| 1820 | * \param region The region to check for opacity, in view coordinates. |
| 1821 | * |
| 1822 | * Returns true if the view is opaque in the specified region, because view |
| 1823 | * alpha is 1.0 and either the opaque region set by the client contains the |
| 1824 | * specified region, or the buffer pixel format or solid color is opaque. |
| 1825 | */ |
| 1826 | WL_EXPORT bool |
| 1827 | weston_view_is_opaque(struct weston_view *ev, pixman_region32_t *region) |
| 1828 | { |
| 1829 | pixman_region32_t r; |
| 1830 | bool ret = false; |
| 1831 | |
| 1832 | if (ev->alpha < 1.0) |
| 1833 | return false; |
| 1834 | |
| 1835 | if (ev->surface->is_opaque) |
| 1836 | return true; |
| 1837 | |
| 1838 | if (ev->transform.dirty) { |
| 1839 | weston_log("%s: transform dirty", __func__); |
| 1840 | return false; |
| 1841 | } |
| 1842 | |
| 1843 | pixman_region32_init(&r); |
| 1844 | pixman_region32_subtract(&r, region, &ev->transform.opaque); |
| 1845 | |
| 1846 | if (!pixman_region32_not_empty(&r)) |
| 1847 | ret = true; |
| 1848 | |
| 1849 | pixman_region32_fini(&r); |
| 1850 | |
| 1851 | return ret; |
| 1852 | } |
| 1853 | |
Marius Vlad | 5f6bee4 | 2019-09-11 16:41:04 +0300 | [diff] [blame] | 1854 | /** Check if the view has a valid buffer available |
| 1855 | * |
| 1856 | * @param ev The view to check if it has a valid buffer. |
| 1857 | * |
| 1858 | * Returns true if the view has a valid buffer or false otherwise. |
| 1859 | */ |
| 1860 | WL_EXPORT bool |
| 1861 | weston_view_has_valid_buffer(struct weston_view *ev) |
| 1862 | { |
| 1863 | return ev->surface->buffer_ref.buffer != NULL; |
| 1864 | } |
| 1865 | |
Marius Vlad | 47e3d1e | 2019-09-11 16:53:08 +0300 | [diff] [blame] | 1866 | /** Check if the view matches the entire output |
| 1867 | * |
| 1868 | * @param ev The view to check. |
| 1869 | * @param output The output to check against. |
| 1870 | * |
| 1871 | * Returns true if the view does indeed matches the entire output. |
| 1872 | */ |
| 1873 | WL_EXPORT bool |
| 1874 | weston_view_matches_output_entirely(struct weston_view *ev, |
| 1875 | struct weston_output *output) |
| 1876 | { |
| 1877 | pixman_box32_t *extents = |
| 1878 | pixman_region32_extents(&ev->transform.boundingbox); |
| 1879 | |
| 1880 | if (extents->x1 != output->x || |
| 1881 | extents->y1 != output->y || |
| 1882 | extents->x2 != output->x + output->width || |
| 1883 | extents->y2 != output->y + output->height) |
| 1884 | return false; |
| 1885 | |
| 1886 | return true; |
| 1887 | } |
| 1888 | |
Armin Krezović | 0da12b8 | 2016-06-30 06:04:33 +0200 | [diff] [blame] | 1889 | /* Check if a surface has a view assigned to it |
| 1890 | * |
| 1891 | * The indicator is set manually when mapping |
| 1892 | * a surface and creating a view for it. |
| 1893 | * |
| 1894 | * This needs to go. See the thread starting at: |
| 1895 | * |
| 1896 | * https://lists.freedesktop.org/archives/wayland-devel/2016-June/029656.html |
| 1897 | * |
| 1898 | */ |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 1899 | WL_EXPORT bool |
Ander Conselvan de Oliveira | b8ab14f | 2012-03-27 17:36:36 +0300 | [diff] [blame] | 1900 | weston_surface_is_mapped(struct weston_surface *surface) |
| 1901 | { |
Armin Krezović | 0da12b8 | 2016-06-30 06:04:33 +0200 | [diff] [blame] | 1902 | return surface->is_mapped; |
Ander Conselvan de Oliveira | b8ab14f | 2012-03-27 17:36:36 +0300 | [diff] [blame] | 1903 | } |
| 1904 | |
Pekka Paalanen | da75ee1 | 2013-11-26 18:19:43 +0100 | [diff] [blame] | 1905 | static void |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 1906 | 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] | 1907 | { |
| 1908 | struct weston_view *view; |
| 1909 | |
| 1910 | if (surface->width == width && surface->height == height) |
| 1911 | return; |
| 1912 | |
| 1913 | surface->width = width; |
| 1914 | surface->height = height; |
| 1915 | |
| 1916 | wl_list_for_each(view, &surface->views, surface_link) |
| 1917 | weston_view_geometry_dirty(view); |
| 1918 | } |
| 1919 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 1920 | WL_EXPORT void |
| 1921 | weston_surface_set_size(struct weston_surface *surface, |
| 1922 | int32_t width, int32_t height) |
| 1923 | { |
| 1924 | assert(!surface->resource); |
| 1925 | surface_set_size(surface, width, height); |
| 1926 | } |
| 1927 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1928 | static int |
| 1929 | fixed_round_up_to_int(wl_fixed_t f) |
| 1930 | { |
| 1931 | return wl_fixed_to_int(wl_fixed_from_int(1) - 1 + f); |
| 1932 | } |
| 1933 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1934 | static void |
Pekka Paalanen | 59987fa | 2016-04-26 15:50:59 +0300 | [diff] [blame] | 1935 | convert_size_by_transform_scale(int32_t *width_out, int32_t *height_out, |
| 1936 | int32_t width, int32_t height, |
| 1937 | uint32_t transform, |
| 1938 | int32_t scale) |
| 1939 | { |
| 1940 | assert(scale > 0); |
| 1941 | |
| 1942 | switch (transform) { |
| 1943 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 1944 | case WL_OUTPUT_TRANSFORM_180: |
| 1945 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 1946 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 1947 | *width_out = width / scale; |
| 1948 | *height_out = height / scale; |
| 1949 | break; |
| 1950 | case WL_OUTPUT_TRANSFORM_90: |
| 1951 | case WL_OUTPUT_TRANSFORM_270: |
| 1952 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 1953 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 1954 | *width_out = height / scale; |
| 1955 | *height_out = width / scale; |
| 1956 | break; |
| 1957 | default: |
| 1958 | assert(0 && "invalid transform"); |
| 1959 | } |
| 1960 | } |
| 1961 | |
| 1962 | static void |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1963 | weston_surface_calculate_size_from_buffer(struct weston_surface *surface) |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1964 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 1965 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Pekka Paalanen | da75ee1 | 2013-11-26 18:19:43 +0100 | [diff] [blame] | 1966 | |
| 1967 | if (!surface->buffer_ref.buffer) { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1968 | surface->width_from_buffer = 0; |
| 1969 | surface->height_from_buffer = 0; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 1970 | return; |
| 1971 | } |
| 1972 | |
Pekka Paalanen | 59987fa | 2016-04-26 15:50:59 +0300 | [diff] [blame] | 1973 | convert_size_by_transform_scale(&surface->width_from_buffer, |
| 1974 | &surface->height_from_buffer, |
| 1975 | surface->buffer_ref.buffer->width, |
| 1976 | surface->buffer_ref.buffer->height, |
| 1977 | vp->buffer.transform, |
| 1978 | vp->buffer.scale); |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1979 | } |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1980 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1981 | static void |
| 1982 | weston_surface_update_size(struct weston_surface *surface) |
| 1983 | { |
| 1984 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
| 1985 | int32_t width, height; |
| 1986 | |
| 1987 | width = surface->width_from_buffer; |
| 1988 | height = surface->height_from_buffer; |
| 1989 | |
| 1990 | if (width != 0 && vp->surface.width != -1) { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1991 | surface_set_size(surface, |
| 1992 | vp->surface.width, vp->surface.height); |
| 1993 | return; |
| 1994 | } |
| 1995 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1996 | if (width != 0 && vp->buffer.src_width != wl_fixed_from_int(-1)) { |
Pekka Paalanen | e931721 | 2014-04-04 14:22:13 +0300 | [diff] [blame] | 1997 | int32_t w = fixed_round_up_to_int(vp->buffer.src_width); |
| 1998 | int32_t h = fixed_round_up_to_int(vp->buffer.src_height); |
| 1999 | |
| 2000 | surface_set_size(surface, w ?: 1, h ?: 1); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 2001 | return; |
| 2002 | } |
| 2003 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 2004 | surface_set_size(surface, width, height); |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 2005 | } |
| 2006 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 2007 | /** weston_compositor_get_time |
| 2008 | * \ingroup compositor |
| 2009 | */ |
Alexandros Frantzis | 409b01f | 2017-11-16 18:21:01 +0200 | [diff] [blame] | 2010 | WL_EXPORT void |
| 2011 | weston_compositor_get_time(struct timespec *time) |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 2012 | { |
Alexandros Frantzis | 409b01f | 2017-11-16 18:21:01 +0200 | [diff] [blame] | 2013 | clock_gettime(CLOCK_REALTIME, time); |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 2014 | } |
| 2015 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 2016 | /** weston_compositor_pick_view |
| 2017 | * \ingroup compositor |
| 2018 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2019 | WL_EXPORT struct weston_view * |
| 2020 | weston_compositor_pick_view(struct weston_compositor *compositor, |
| 2021 | wl_fixed_t x, wl_fixed_t y, |
| 2022 | wl_fixed_t *vx, wl_fixed_t *vy) |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 2023 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2024 | struct weston_view *view; |
Pekka Paalanen | fc22a52 | 2015-02-18 15:08:29 +0200 | [diff] [blame] | 2025 | wl_fixed_t view_x, view_y; |
| 2026 | int view_ix, view_iy; |
| 2027 | int ix = wl_fixed_to_int(x); |
| 2028 | int iy = wl_fixed_to_int(y); |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 2029 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2030 | wl_list_for_each(view, &compositor->view_list, link) { |
Pekka Paalanen | fc22a52 | 2015-02-18 15:08:29 +0200 | [diff] [blame] | 2031 | if (!pixman_region32_contains_point( |
| 2032 | &view->transform.boundingbox, ix, iy, NULL)) |
| 2033 | continue; |
| 2034 | |
| 2035 | weston_view_from_global_fixed(view, x, y, &view_x, &view_y); |
| 2036 | view_ix = wl_fixed_to_int(view_x); |
| 2037 | view_iy = wl_fixed_to_int(view_y); |
| 2038 | |
| 2039 | if (!pixman_region32_contains_point(&view->surface->input, |
| 2040 | view_ix, view_iy, NULL)) |
| 2041 | continue; |
| 2042 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 2043 | if (view->geometry.scissor_enabled && |
| 2044 | !pixman_region32_contains_point(&view->geometry.scissor, |
| 2045 | view_ix, view_iy, NULL)) |
| 2046 | continue; |
| 2047 | |
Pekka Paalanen | fc22a52 | 2015-02-18 15:08:29 +0200 | [diff] [blame] | 2048 | *vx = view_x; |
| 2049 | *vy = view_y; |
| 2050 | return view; |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 2051 | } |
| 2052 | |
Derek Foreman | f9318d1 | 2015-05-11 15:40:11 -0500 | [diff] [blame] | 2053 | *vx = wl_fixed_from_int(-1000000); |
| 2054 | *vy = wl_fixed_from_int(-1000000); |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 2055 | return NULL; |
| 2056 | } |
| 2057 | |
| 2058 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2059 | weston_compositor_repick(struct weston_compositor *compositor) |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 2060 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2061 | struct weston_seat *seat; |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 2062 | |
Kristian Høgsberg | 10ddd97 | 2013-10-22 12:40:54 -0700 | [diff] [blame] | 2063 | if (!compositor->session_active) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 2064 | return; |
| 2065 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2066 | wl_list_for_each(seat, &compositor->seat_list, link) |
Kristian Høgsberg | a71e8b2 | 2013-05-06 21:51:21 -0400 | [diff] [blame] | 2067 | weston_seat_repick(seat); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 2068 | } |
| 2069 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2070 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2071 | weston_view_unmap(struct weston_view *view) |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 2072 | { |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 2073 | struct weston_seat *seat; |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 2074 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2075 | if (!weston_view_is_mapped(view)) |
| 2076 | return; |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 2077 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2078 | weston_view_damage_below(view); |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 2079 | weston_view_set_output(view, NULL); |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 2080 | view->plane = NULL; |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 2081 | view->is_mapped = false; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2082 | weston_layer_entry_remove(&view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2083 | wl_list_remove(&view->link); |
| 2084 | wl_list_init(&view->link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2085 | view->output_mask = 0; |
| 2086 | weston_surface_assign_output(view->surface); |
| 2087 | |
| 2088 | if (weston_surface_is_mapped(view->surface)) |
| 2089 | return; |
| 2090 | |
| 2091 | wl_list_for_each(seat, &view->surface->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2092 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 2093 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2094 | struct weston_keyboard *keyboard = |
| 2095 | weston_seat_get_keyboard(seat); |
| 2096 | |
| 2097 | if (keyboard && keyboard->focus == view->surface) |
| 2098 | weston_keyboard_set_focus(keyboard, NULL); |
| 2099 | if (pointer && pointer->focus == view) |
Derek Foreman | f9318d1 | 2015-05-11 15:40:11 -0500 | [diff] [blame] | 2100 | weston_pointer_clear_focus(pointer); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2101 | if (touch && touch->focus == view) |
| 2102 | weston_touch_set_focus(touch, NULL); |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 2103 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2104 | } |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 2105 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2106 | WL_EXPORT void |
| 2107 | weston_surface_unmap(struct weston_surface *surface) |
| 2108 | { |
| 2109 | struct weston_view *view; |
| 2110 | |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 2111 | surface->is_mapped = false; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2112 | wl_list_for_each(view, &surface->views, surface_link) |
| 2113 | weston_view_unmap(view); |
| 2114 | surface->output = NULL; |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 2115 | } |
| 2116 | |
Pekka Paalanen | 3c9b802 | 2014-03-14 14:38:13 +0200 | [diff] [blame] | 2117 | static void |
| 2118 | weston_surface_reset_pending_buffer(struct weston_surface *surface) |
| 2119 | { |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2120 | weston_surface_state_set_buffer(&surface->pending, NULL); |
Pekka Paalanen | 3c9b802 | 2014-03-14 14:38:13 +0200 | [diff] [blame] | 2121 | surface->pending.sx = 0; |
| 2122 | surface->pending.sy = 0; |
| 2123 | surface->pending.newly_attached = 0; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 2124 | surface->pending.buffer_viewport.changed = 0; |
Pekka Paalanen | 3c9b802 | 2014-03-14 14:38:13 +0200 | [diff] [blame] | 2125 | } |
| 2126 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2127 | WL_EXPORT void |
| 2128 | weston_view_destroy(struct weston_view *view) |
| 2129 | { |
| 2130 | wl_signal_emit(&view->destroy_signal, view); |
| 2131 | |
| 2132 | assert(wl_list_empty(&view->geometry.child_list)); |
| 2133 | |
| 2134 | if (weston_view_is_mapped(view)) { |
| 2135 | weston_view_unmap(view); |
| 2136 | weston_compositor_build_view_list(view->surface->compositor); |
| 2137 | } |
| 2138 | |
| 2139 | wl_list_remove(&view->link); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2140 | weston_layer_entry_remove(&view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2141 | |
| 2142 | pixman_region32_fini(&view->clip); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 2143 | pixman_region32_fini(&view->geometry.scissor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2144 | pixman_region32_fini(&view->transform.boundingbox); |
Pekka Paalanen | 8844bf2 | 2015-02-18 16:30:47 +0200 | [diff] [blame] | 2145 | pixman_region32_fini(&view->transform.opaque); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2146 | |
| 2147 | weston_view_set_transform_parent(view, NULL); |
Pekka Paalanen | 944fae8 | 2018-05-22 13:15:58 +0300 | [diff] [blame] | 2148 | weston_view_set_output(view, NULL); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2149 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2150 | wl_list_remove(&view->surface_link); |
| 2151 | |
| 2152 | free(view); |
| 2153 | } |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2154 | |
| 2155 | WL_EXPORT void |
| 2156 | weston_surface_destroy(struct weston_surface *surface) |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 2157 | { |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 2158 | struct weston_frame_callback *cb, *next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2159 | struct weston_view *ev, *nv; |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 2160 | struct weston_pointer_constraint *constraint, *next_constraint; |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 2161 | |
Giulio Camuffo | 13b85bd | 2013-08-13 23:10:14 +0200 | [diff] [blame] | 2162 | if (--surface->ref_count > 0) |
| 2163 | return; |
| 2164 | |
Pekka Paalanen | 08d3fb7 | 2015-04-17 14:00:24 +0300 | [diff] [blame] | 2165 | assert(surface->resource == NULL); |
| 2166 | |
Pekka Paalanen | ca79076 | 2015-04-17 14:23:38 +0300 | [diff] [blame] | 2167 | wl_signal_emit(&surface->destroy_signal, surface); |
Giulio Camuffo | 13b85bd | 2013-08-13 23:10:14 +0200 | [diff] [blame] | 2168 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2169 | assert(wl_list_empty(&surface->subsurface_list_pending)); |
| 2170 | assert(wl_list_empty(&surface->subsurface_list)); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 2171 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2172 | wl_list_for_each_safe(ev, nv, &surface->views, surface_link) |
| 2173 | weston_view_destroy(ev); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 2174 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2175 | weston_surface_state_fini(&surface->pending); |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2176 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2177 | weston_buffer_reference(&surface->buffer_ref, NULL); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2178 | weston_buffer_release_reference(&surface->buffer_release_ref, NULL); |
Kristian Høgsberg | 3f8f39c | 2009-09-18 17:05:13 -0400 | [diff] [blame] | 2179 | |
Pekka Paalanen | 402ae6d | 2012-01-03 10:23:24 +0200 | [diff] [blame] | 2180 | pixman_region32_fini(&surface->damage); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2181 | pixman_region32_fini(&surface->opaque); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 2182 | pixman_region32_fini(&surface->input); |
Pekka Paalanen | 402ae6d | 2012-01-03 10:23:24 +0200 | [diff] [blame] | 2183 | |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 2184 | wl_list_for_each_safe(cb, next, &surface->frame_callback_list, link) |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 2185 | wl_resource_destroy(cb->resource); |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 2186 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2187 | weston_presentation_feedback_discard_list(&surface->feedback_list); |
| 2188 | |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 2189 | wl_list_for_each_safe(constraint, next_constraint, |
| 2190 | &surface->pointer_constraints, |
| 2191 | link) |
| 2192 | weston_pointer_constraint_destroy(constraint); |
| 2193 | |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2194 | fd_clear(&surface->acquire_fence_fd); |
| 2195 | |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 2196 | free(surface); |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 2197 | } |
| 2198 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2199 | static void |
| 2200 | destroy_surface(struct wl_resource *resource) |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 2201 | { |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2202 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 2203 | |
Pekka Paalanen | 08d3fb7 | 2015-04-17 14:00:24 +0300 | [diff] [blame] | 2204 | assert(surface); |
| 2205 | |
Giulio Camuffo | 0d37974 | 2013-11-15 22:06:15 +0100 | [diff] [blame] | 2206 | /* Set the resource to NULL, since we don't want to leave a |
| 2207 | * dangling pointer if the surface was refcounted and survives |
| 2208 | * the weston_surface_destroy() call. */ |
| 2209 | surface->resource = NULL; |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 2210 | |
| 2211 | if (surface->viewport_resource) |
| 2212 | wl_resource_set_user_data(surface->viewport_resource, NULL); |
| 2213 | |
Alexandros Frantzis | 27d7c39 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2214 | if (surface->synchronization_resource) { |
| 2215 | wl_resource_set_user_data(surface->synchronization_resource, |
| 2216 | NULL); |
| 2217 | } |
| 2218 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2219 | weston_surface_destroy(surface); |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 2220 | } |
| 2221 | |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 2222 | static void |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2223 | weston_buffer_destroy_handler(struct wl_listener *listener, void *data) |
| 2224 | { |
| 2225 | struct weston_buffer *buffer = |
| 2226 | container_of(listener, struct weston_buffer, destroy_listener); |
| 2227 | |
| 2228 | wl_signal_emit(&buffer->destroy_signal, buffer); |
| 2229 | free(buffer); |
| 2230 | } |
| 2231 | |
Giulio Camuffo | e058cd1 | 2013-12-12 14:14:29 +0100 | [diff] [blame] | 2232 | WL_EXPORT struct weston_buffer * |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2233 | weston_buffer_from_resource(struct wl_resource *resource) |
| 2234 | { |
| 2235 | struct weston_buffer *buffer; |
| 2236 | struct wl_listener *listener; |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 2237 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2238 | listener = wl_resource_get_destroy_listener(resource, |
| 2239 | weston_buffer_destroy_handler); |
| 2240 | |
Kristian Høgsberg | 08b58c7 | 2013-08-15 12:26:42 -0700 | [diff] [blame] | 2241 | if (listener) |
| 2242 | return container_of(listener, struct weston_buffer, |
| 2243 | destroy_listener); |
| 2244 | |
| 2245 | buffer = zalloc(sizeof *buffer); |
| 2246 | if (buffer == NULL) |
| 2247 | return NULL; |
| 2248 | |
| 2249 | buffer->resource = resource; |
| 2250 | wl_signal_init(&buffer->destroy_signal); |
| 2251 | buffer->destroy_listener.notify = weston_buffer_destroy_handler; |
Stanislav Vorobiov | bfbb8e5 | 2013-08-29 11:36:44 +0400 | [diff] [blame] | 2252 | buffer->y_inverted = 1; |
Kristian Høgsberg | 08b58c7 | 2013-08-15 12:26:42 -0700 | [diff] [blame] | 2253 | wl_resource_add_destroy_listener(resource, &buffer->destroy_listener); |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 2254 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2255 | return buffer; |
| 2256 | } |
| 2257 | |
| 2258 | static void |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2259 | weston_buffer_reference_handle_destroy(struct wl_listener *listener, |
| 2260 | void *data) |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 2261 | { |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2262 | struct weston_buffer_reference *ref = |
| 2263 | container_of(listener, struct weston_buffer_reference, |
| 2264 | destroy_listener); |
| 2265 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2266 | assert((struct weston_buffer *)data == ref->buffer); |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2267 | ref->buffer = NULL; |
| 2268 | } |
| 2269 | |
| 2270 | WL_EXPORT void |
| 2271 | weston_buffer_reference(struct weston_buffer_reference *ref, |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2272 | struct weston_buffer *buffer) |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2273 | { |
| 2274 | if (ref->buffer && buffer != ref->buffer) { |
Kristian Høgsberg | 2034780 | 2013-03-04 12:07:46 -0500 | [diff] [blame] | 2275 | ref->buffer->busy_count--; |
| 2276 | if (ref->buffer->busy_count == 0) { |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2277 | assert(wl_resource_get_client(ref->buffer->resource)); |
Matt Hoosier | 3052bc7 | 2017-09-26 08:09:40 -0500 | [diff] [blame] | 2278 | wl_buffer_send_release(ref->buffer->resource); |
Kristian Høgsberg | 2034780 | 2013-03-04 12:07:46 -0500 | [diff] [blame] | 2279 | } |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2280 | wl_list_remove(&ref->destroy_listener.link); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2281 | } |
| 2282 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2283 | if (buffer && buffer != ref->buffer) { |
Kristian Høgsberg | b7b77e6 | 2012-09-05 22:38:18 -0400 | [diff] [blame] | 2284 | buffer->busy_count++; |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2285 | wl_signal_add(&buffer->destroy_signal, |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2286 | &ref->destroy_listener); |
Pekka Paalanen | a6421c4 | 2012-12-04 15:58:10 +0200 | [diff] [blame] | 2287 | } |
| 2288 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2289 | ref->buffer = buffer; |
| 2290 | ref->destroy_listener.notify = weston_buffer_reference_handle_destroy; |
| 2291 | } |
| 2292 | |
| 2293 | static void |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2294 | weston_buffer_release_reference_handle_destroy(struct wl_listener *listener, |
| 2295 | void *data) |
| 2296 | { |
| 2297 | struct weston_buffer_release_reference *ref = |
| 2298 | container_of(listener, struct weston_buffer_release_reference, |
| 2299 | destroy_listener); |
| 2300 | |
| 2301 | assert((struct wl_resource *)data == ref->buffer_release->resource); |
| 2302 | ref->buffer_release = NULL; |
| 2303 | } |
| 2304 | |
| 2305 | static void |
| 2306 | weston_buffer_release_destroy(struct weston_buffer_release *buffer_release) |
| 2307 | { |
| 2308 | struct wl_resource *resource = buffer_release->resource; |
| 2309 | int release_fence_fd = buffer_release->fence_fd; |
| 2310 | |
| 2311 | if (release_fence_fd >= 0) { |
| 2312 | zwp_linux_buffer_release_v1_send_fenced_release( |
| 2313 | resource, release_fence_fd); |
| 2314 | } else { |
| 2315 | zwp_linux_buffer_release_v1_send_immediate_release( |
| 2316 | resource); |
| 2317 | } |
| 2318 | |
| 2319 | wl_resource_destroy(resource); |
| 2320 | } |
| 2321 | |
| 2322 | WL_EXPORT void |
| 2323 | weston_buffer_release_reference(struct weston_buffer_release_reference *ref, |
| 2324 | struct weston_buffer_release *buffer_release) |
| 2325 | { |
| 2326 | if (buffer_release == ref->buffer_release) |
| 2327 | return; |
| 2328 | |
| 2329 | if (ref->buffer_release) { |
| 2330 | ref->buffer_release->ref_count--; |
| 2331 | wl_list_remove(&ref->destroy_listener.link); |
| 2332 | if (ref->buffer_release->ref_count == 0) |
| 2333 | weston_buffer_release_destroy(ref->buffer_release); |
| 2334 | } |
| 2335 | |
| 2336 | if (buffer_release) { |
| 2337 | buffer_release->ref_count++; |
| 2338 | wl_resource_add_destroy_listener(buffer_release->resource, |
| 2339 | &ref->destroy_listener); |
| 2340 | } |
| 2341 | |
| 2342 | ref->buffer_release = buffer_release; |
| 2343 | ref->destroy_listener.notify = |
| 2344 | weston_buffer_release_reference_handle_destroy; |
| 2345 | } |
| 2346 | |
| 2347 | WL_EXPORT void |
| 2348 | weston_buffer_release_move(struct weston_buffer_release_reference *dest, |
| 2349 | struct weston_buffer_release_reference *src) |
| 2350 | { |
| 2351 | weston_buffer_release_reference(dest, src->buffer_release); |
| 2352 | weston_buffer_release_reference(src, NULL); |
| 2353 | } |
| 2354 | |
| 2355 | static void |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2356 | weston_surface_attach(struct weston_surface *surface, |
| 2357 | struct weston_buffer *buffer) |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2358 | { |
| 2359 | weston_buffer_reference(&surface->buffer_ref, buffer); |
| 2360 | |
Pekka Paalanen | a6421c4 | 2012-12-04 15:58:10 +0200 | [diff] [blame] | 2361 | if (!buffer) { |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2362 | if (weston_surface_is_mapped(surface)) |
| 2363 | weston_surface_unmap(surface); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2364 | } |
| 2365 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2366 | surface->compositor->renderer->attach(surface, buffer); |
Pekka Paalanen | bb2f3f2 | 2014-03-14 14:38:11 +0200 | [diff] [blame] | 2367 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 2368 | weston_surface_calculate_size_from_buffer(surface); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2369 | weston_presentation_feedback_discard_list(&surface->feedback_list); |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 2370 | } |
| 2371 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 2372 | /** weston_compositor_damage_all |
| 2373 | * \ingroup compositor |
| 2374 | */ |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2375 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2376 | weston_compositor_damage_all(struct weston_compositor *compositor) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2377 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2378 | struct weston_output *output; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2379 | |
| 2380 | wl_list_for_each(output, &compositor->output_list, link) |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2381 | weston_output_damage(output); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2382 | } |
| 2383 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 2384 | /** |
| 2385 | * \ingroup output |
| 2386 | */ |
Kristian Høgsberg | 9f404b7 | 2012-01-26 00:11:01 -0500 | [diff] [blame] | 2387 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2388 | weston_output_damage(struct weston_output *output) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2389 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2390 | struct weston_compositor *compositor = output->compositor; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2391 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 2392 | pixman_region32_union(&compositor->primary_plane.damage, |
| 2393 | &compositor->primary_plane.damage, |
| 2394 | &output->region); |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2395 | weston_output_schedule_repaint(output); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2396 | } |
| 2397 | |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame] | 2398 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2399 | surface_flush_damage(struct weston_surface *surface) |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2400 | { |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2401 | if (surface->buffer_ref.buffer && |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2402 | wl_shm_buffer_get(surface->buffer_ref.buffer->resource)) |
Kristian Høgsberg | fa1be02 | 2012-09-05 22:49:55 -0400 | [diff] [blame] | 2403 | surface->compositor->renderer->flush_damage(surface); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2404 | |
Marius Vlad | 2a1b786 | 2019-09-05 13:12:18 +0300 | [diff] [blame] | 2405 | if (pixman_region32_not_empty(&surface->damage)) |
Marius Vlad | 3203ff6 | 2019-09-05 14:56:12 +0300 | [diff] [blame] | 2406 | TL_POINT(surface->compositor, "core_flush_damage", TLP_SURFACE(surface), |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2407 | TLP_OUTPUT(surface->output), TLP_END); |
| 2408 | |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 2409 | pixman_region32_clear(&surface->damage); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2410 | } |
| 2411 | |
| 2412 | static void |
| 2413 | view_accumulate_damage(struct weston_view *view, |
| 2414 | pixman_region32_t *opaque) |
| 2415 | { |
| 2416 | pixman_region32_t damage; |
| 2417 | |
| 2418 | pixman_region32_init(&damage); |
| 2419 | if (view->transform.enabled) { |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2420 | pixman_box32_t *extents; |
| 2421 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2422 | extents = pixman_region32_extents(&view->surface->damage); |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 2423 | view_compute_bbox(view, extents, &damage); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2424 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2425 | pixman_region32_copy(&damage, &view->surface->damage); |
| 2426 | pixman_region32_translate(&damage, |
Pekka Paalanen | 502f5e0 | 2015-02-23 14:08:25 +0200 | [diff] [blame] | 2427 | view->geometry.x, view->geometry.y); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2428 | } |
| 2429 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 2430 | pixman_region32_intersect(&damage, &damage, |
| 2431 | &view->transform.boundingbox); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2432 | pixman_region32_subtract(&damage, &damage, opaque); |
| 2433 | pixman_region32_union(&view->plane->damage, |
| 2434 | &view->plane->damage, &damage); |
| 2435 | pixman_region32_fini(&damage); |
| 2436 | pixman_region32_copy(&view->clip, opaque); |
Pekka Paalanen | 8844bf2 | 2015-02-18 16:30:47 +0200 | [diff] [blame] | 2437 | pixman_region32_union(opaque, opaque, &view->transform.opaque); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2438 | } |
| 2439 | |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 2440 | static void |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2441 | compositor_accumulate_damage(struct weston_compositor *ec) |
| 2442 | { |
| 2443 | struct weston_plane *plane; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2444 | struct weston_view *ev; |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2445 | pixman_region32_t opaque, clip; |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2446 | |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2447 | pixman_region32_init(&clip); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2448 | |
| 2449 | wl_list_for_each(plane, &ec->plane_list, link) { |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2450 | pixman_region32_copy(&plane->clip, &clip); |
| 2451 | |
| 2452 | pixman_region32_init(&opaque); |
| 2453 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2454 | wl_list_for_each(ev, &ec->view_list, link) { |
| 2455 | if (ev->plane != plane) |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2456 | continue; |
| 2457 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2458 | view_accumulate_damage(ev, &opaque); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2459 | } |
| 2460 | |
| 2461 | pixman_region32_union(&clip, &clip, &opaque); |
| 2462 | pixman_region32_fini(&opaque); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2463 | } |
| 2464 | |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2465 | pixman_region32_fini(&clip); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2466 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2467 | wl_list_for_each(ev, &ec->view_list, link) |
Derek Foreman | 060cf11 | 2015-11-18 16:32:26 -0600 | [diff] [blame] | 2468 | ev->surface->touched = false; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2469 | |
| 2470 | wl_list_for_each(ev, &ec->view_list, link) { |
| 2471 | if (ev->surface->touched) |
| 2472 | continue; |
Derek Foreman | 060cf11 | 2015-11-18 16:32:26 -0600 | [diff] [blame] | 2473 | ev->surface->touched = true; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2474 | |
| 2475 | surface_flush_damage(ev->surface); |
| 2476 | |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2477 | /* Both the renderer and the backend have seen the buffer |
| 2478 | * by now. If renderer needs the buffer, it has its own |
| 2479 | * reference set. If the backend wants to keep the buffer |
| 2480 | * around for migrating the surface into a non-primary plane |
| 2481 | * later, keep_buffer is true. Otherwise, drop the core |
| 2482 | * reference now, and allow early buffer release. This enables |
| 2483 | * clients to use single-buffering. |
| 2484 | */ |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2485 | if (!ev->surface->keep_buffer) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2486 | weston_buffer_reference(&ev->surface->buffer_ref, NULL); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2487 | weston_buffer_release_reference( |
| 2488 | &ev->surface->buffer_release_ref, NULL); |
| 2489 | } |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2490 | } |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2491 | } |
| 2492 | |
| 2493 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2494 | surface_stash_subsurface_views(struct weston_surface *surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2495 | { |
| 2496 | struct weston_subsurface *sub; |
| 2497 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2498 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2499 | if (sub->surface == surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2500 | continue; |
| 2501 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2502 | wl_list_insert_list(&sub->unused_views, &sub->surface->views); |
| 2503 | wl_list_init(&sub->surface->views); |
| 2504 | |
| 2505 | surface_stash_subsurface_views(sub->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2506 | } |
| 2507 | } |
| 2508 | |
| 2509 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2510 | surface_free_unused_subsurface_views(struct weston_surface *surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2511 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2512 | struct weston_subsurface *sub; |
| 2513 | struct weston_view *view, *nv; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2514 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2515 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
| 2516 | if (sub->surface == surface) |
| 2517 | continue; |
| 2518 | |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 2519 | wl_list_for_each_safe(view, nv, &sub->unused_views, surface_link) { |
| 2520 | weston_view_unmap (view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2521 | weston_view_destroy(view); |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 2522 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2523 | |
| 2524 | surface_free_unused_subsurface_views(sub->surface); |
| 2525 | } |
| 2526 | } |
| 2527 | |
| 2528 | static void |
| 2529 | view_list_add_subsurface_view(struct weston_compositor *compositor, |
| 2530 | struct weston_subsurface *sub, |
| 2531 | struct weston_view *parent) |
| 2532 | { |
| 2533 | struct weston_subsurface *child; |
| 2534 | struct weston_view *view = NULL, *iv; |
| 2535 | |
Pekka Paalanen | 661de3a | 2014-07-28 12:49:24 +0300 | [diff] [blame] | 2536 | if (!weston_surface_is_mapped(sub->surface)) |
| 2537 | return; |
| 2538 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2539 | wl_list_for_each(iv, &sub->unused_views, surface_link) { |
| 2540 | if (iv->geometry.parent == parent) { |
| 2541 | view = iv; |
| 2542 | break; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2543 | } |
| 2544 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2545 | |
| 2546 | if (view) { |
| 2547 | /* Put it back in the surface's list of views */ |
| 2548 | wl_list_remove(&view->surface_link); |
| 2549 | wl_list_insert(&sub->surface->views, &view->surface_link); |
| 2550 | } else { |
| 2551 | view = weston_view_create(sub->surface); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2552 | weston_view_set_position(view, |
| 2553 | sub->position.x, |
| 2554 | sub->position.y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2555 | weston_view_set_transform_parent(view, parent); |
| 2556 | } |
| 2557 | |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 2558 | view->parent_view = parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2559 | weston_view_update_transform(view); |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 2560 | view->is_mapped = true; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2561 | |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2562 | if (wl_list_empty(&sub->surface->subsurface_list)) { |
| 2563 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 2564 | return; |
| 2565 | } |
| 2566 | |
| 2567 | wl_list_for_each(child, &sub->surface->subsurface_list, parent_link) { |
| 2568 | if (child->surface == sub->surface) |
| 2569 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 2570 | else |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2571 | view_list_add_subsurface_view(compositor, child, view); |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2572 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2573 | } |
| 2574 | |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 2575 | /* This recursively adds the sub-surfaces for a view, relying on the |
| 2576 | * sub-surface order. Thus, if a client restacks the sub-surfaces, that |
| 2577 | * change first happens to the sub-surface list, and then automatically |
| 2578 | * propagates here. See weston_surface_damage_subsurfaces() for how the |
| 2579 | * sub-surfaces receive damage when the client changes the state. |
| 2580 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2581 | static void |
| 2582 | view_list_add(struct weston_compositor *compositor, |
| 2583 | struct weston_view *view) |
| 2584 | { |
| 2585 | struct weston_subsurface *sub; |
| 2586 | |
| 2587 | weston_view_update_transform(view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2588 | |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2589 | if (wl_list_empty(&view->surface->subsurface_list)) { |
| 2590 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 2591 | return; |
| 2592 | } |
| 2593 | |
| 2594 | wl_list_for_each(sub, &view->surface->subsurface_list, parent_link) { |
| 2595 | if (sub->surface == view->surface) |
| 2596 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 2597 | else |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2598 | view_list_add_subsurface_view(compositor, sub, view); |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2599 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2600 | } |
| 2601 | |
| 2602 | static void |
| 2603 | weston_compositor_build_view_list(struct weston_compositor *compositor) |
| 2604 | { |
Loïc Yhuel | 267b16e | 2019-09-17 20:14:56 +0200 | [diff] [blame] | 2605 | struct weston_view *view, *tmp; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2606 | struct weston_layer *layer; |
| 2607 | |
| 2608 | wl_list_for_each(layer, &compositor->layer_list, link) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2609 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2610 | surface_stash_subsurface_views(view->surface); |
| 2611 | |
Loïc Yhuel | 267b16e | 2019-09-17 20:14:56 +0200 | [diff] [blame] | 2612 | wl_list_for_each_safe(view, tmp, &compositor->view_list, link) |
| 2613 | wl_list_init(&view->link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2614 | wl_list_init(&compositor->view_list); |
Loïc Yhuel | 267b16e | 2019-09-17 20:14:56 +0200 | [diff] [blame] | 2615 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2616 | wl_list_for_each(layer, &compositor->layer_list, link) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2617 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2618 | view_list_add(compositor, view); |
| 2619 | } |
| 2620 | } |
| 2621 | |
| 2622 | wl_list_for_each(layer, &compositor->layer_list, link) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2623 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2624 | surface_free_unused_subsurface_views(view->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2625 | } |
| 2626 | |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2627 | static void |
| 2628 | weston_output_take_feedback_list(struct weston_output *output, |
| 2629 | struct weston_surface *surface) |
| 2630 | { |
| 2631 | struct weston_view *view; |
| 2632 | struct weston_presentation_feedback *feedback; |
| 2633 | uint32_t flags = 0xffffffff; |
| 2634 | |
| 2635 | if (wl_list_empty(&surface->feedback_list)) |
| 2636 | return; |
| 2637 | |
| 2638 | /* All views must have the flag for the flag to survive. */ |
| 2639 | wl_list_for_each(view, &surface->views, surface_link) { |
| 2640 | /* ignore views that are not on this output at all */ |
| 2641 | if (view->output_mask & (1u << output->id)) |
| 2642 | flags &= view->psf_flags; |
| 2643 | } |
| 2644 | |
| 2645 | wl_list_for_each(feedback, &surface->feedback_list, link) |
| 2646 | feedback->psf_flags = flags; |
| 2647 | |
| 2648 | wl_list_insert_list(&output->feedback_list, &surface->feedback_list); |
| 2649 | wl_list_init(&surface->feedback_list); |
| 2650 | } |
| 2651 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2652 | static int |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2653 | weston_output_repaint(struct weston_output *output, void *repaint_data) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2654 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2655 | struct weston_compositor *ec = output->compositor; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2656 | struct weston_view *ev; |
Kristian Høgsberg | 30c018b | 2012-01-26 08:40:37 -0500 | [diff] [blame] | 2657 | struct weston_animation *animation, *next; |
| 2658 | struct weston_frame_callback *cb, *cnext; |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 2659 | struct wl_list frame_callback_list; |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2660 | pixman_region32_t output_damage; |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2661 | int r; |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 2662 | uint32_t frame_time_msec; |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 2663 | enum weston_hdcp_protection highest_requested = WESTON_HDCP_DISABLE; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 2664 | |
Ander Conselvan de Oliveira | e1e2352 | 2013-12-13 22:10:55 +0200 | [diff] [blame] | 2665 | if (output->destroying) |
| 2666 | return 0; |
| 2667 | |
Marius Vlad | 3203ff6 | 2019-09-05 14:56:12 +0300 | [diff] [blame] | 2668 | TL_POINT(ec, "core_repaint_begin", TLP_OUTPUT(output), TLP_END); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2669 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2670 | /* Rebuild the surface list and update surface transforms up front. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2671 | weston_compositor_build_view_list(ec); |
Pekka Paalanen | 15d60ef | 2012-01-27 14:38:33 +0200 | [diff] [blame] | 2672 | |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 2673 | /* Find the highest protection desired for an output */ |
| 2674 | wl_list_for_each(ev, &ec->view_list, link) { |
| 2675 | if (ev->surface->output_mask & (1u << output->id)) { |
| 2676 | /* |
| 2677 | * The desired_protection of the output should be the |
| 2678 | * maximum of the desired_protection of the surfaces, |
| 2679 | * that are displayed on that output, to avoid |
| 2680 | * reducing the protection for existing surfaces. |
| 2681 | */ |
| 2682 | if (ev->surface->desired_protection > highest_requested) |
| 2683 | highest_requested = |
| 2684 | ev->surface->desired_protection; |
| 2685 | } |
| 2686 | } |
| 2687 | |
| 2688 | output->desired_protection = highest_requested; |
| 2689 | |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2690 | if (output->assign_planes && !output->disable_planes) { |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2691 | output->assign_planes(output, repaint_data); |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2692 | } else { |
| 2693 | wl_list_for_each(ev, &ec->view_list, link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2694 | weston_view_move_to_plane(ev, &ec->primary_plane); |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2695 | ev->psf_flags = 0; |
| 2696 | } |
| 2697 | } |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 2698 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2699 | wl_list_init(&frame_callback_list); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2700 | wl_list_for_each(ev, &ec->view_list, link) { |
| 2701 | /* Note: This operation is safe to do multiple times on the |
| 2702 | * same surface. |
| 2703 | */ |
| 2704 | if (ev->surface->output == output) { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2705 | wl_list_insert_list(&frame_callback_list, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2706 | &ev->surface->frame_callback_list); |
| 2707 | wl_list_init(&ev->surface->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2708 | |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2709 | weston_output_take_feedback_list(output, ev->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2710 | } |
| 2711 | } |
| 2712 | |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2713 | compositor_accumulate_damage(ec); |
Kristian Høgsberg | 53df1d8 | 2011-06-23 21:11:19 -0400 | [diff] [blame] | 2714 | |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 2715 | pixman_region32_init(&output_damage); |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 2716 | pixman_region32_intersect(&output_damage, |
| 2717 | &ec->primary_plane.damage, &output->region); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2718 | pixman_region32_subtract(&output_damage, |
| 2719 | &output_damage, &ec->primary_plane.clip); |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 2720 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2721 | if (output->dirty) |
| 2722 | weston_output_update_matrix(output); |
| 2723 | |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2724 | r = output->repaint(output, &output_damage, repaint_data); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2725 | |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 2726 | pixman_region32_fini(&output_damage); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 2727 | |
Daniel Stone | 09a97e2 | 2017-03-01 11:34:06 +0000 | [diff] [blame] | 2728 | output->repaint_needed = false; |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2729 | if (r == 0) |
| 2730 | output->repaint_status = REPAINT_AWAITING_COMPLETION; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 2731 | |
Kristian Høgsberg | aa6019e | 2012-03-11 16:35:16 -0400 | [diff] [blame] | 2732 | weston_compositor_repick(ec); |
Kristian Høgsberg | aa6019e | 2012-03-11 16:35:16 -0400 | [diff] [blame] | 2733 | |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 2734 | frame_time_msec = timespec_to_msec(&output->frame_time); |
| 2735 | |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 2736 | wl_list_for_each_safe(cb, cnext, &frame_callback_list, link) { |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 2737 | wl_callback_send_done(cb->resource, frame_time_msec); |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 2738 | wl_resource_destroy(cb->resource); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 2739 | } |
| 2740 | |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 2741 | wl_list_for_each_safe(animation, next, &output->animation_list, link) { |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 2742 | animation->frame_counter++; |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 2743 | animation->frame(animation, output, &output->frame_time); |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 2744 | } |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2745 | |
Marius Vlad | 3203ff6 | 2019-09-05 14:56:12 +0300 | [diff] [blame] | 2746 | TL_POINT(ec, "core_repaint_posted", TLP_OUTPUT(output), TLP_END); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2747 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2748 | return r; |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2749 | } |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 2750 | |
Pekka Paalanen | 8291979 | 2014-05-21 13:51:49 +0300 | [diff] [blame] | 2751 | static void |
| 2752 | weston_output_schedule_repaint_reset(struct weston_output *output) |
| 2753 | { |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2754 | output->repaint_status = REPAINT_NOT_SCHEDULED; |
Marius Vlad | 3203ff6 | 2019-09-05 14:56:12 +0300 | [diff] [blame] | 2755 | TL_POINT(output->compositor, "core_repaint_exit_loop", |
| 2756 | TLP_OUTPUT(output), TLP_END); |
Pekka Paalanen | 8291979 | 2014-05-21 13:51:49 +0300 | [diff] [blame] | 2757 | } |
| 2758 | |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2759 | static int |
| 2760 | weston_output_maybe_repaint(struct weston_output *output, struct timespec *now, |
| 2761 | void *repaint_data) |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2762 | { |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2763 | struct weston_compositor *compositor = output->compositor; |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2764 | int ret = 0; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2765 | int64_t msec_to_repaint; |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2766 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2767 | /* We're not ready yet; come back to make a decision later. */ |
| 2768 | if (output->repaint_status != REPAINT_SCHEDULED) |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2769 | return ret; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2770 | |
| 2771 | msec_to_repaint = timespec_sub_to_msec(&output->next_repaint, now); |
| 2772 | if (msec_to_repaint > 1) |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2773 | return ret; |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2774 | |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 2775 | /* If we're sleeping, drop the repaint machinery entirely; we will |
| 2776 | * explicitly repaint all outputs when we come back. */ |
| 2777 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING || |
| 2778 | compositor->state == WESTON_COMPOSITOR_OFFSCREEN) |
| 2779 | goto err; |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2780 | |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 2781 | /* We don't actually need to repaint this output; drop it from |
| 2782 | * repaint until something causes damage. */ |
| 2783 | if (!output->repaint_needed) |
| 2784 | goto err; |
| 2785 | |
| 2786 | /* If repaint fails, we aren't going to get weston_output_finish_frame |
| 2787 | * to trigger a new repaint, so drop it from repaint and hope |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2788 | * something schedules a successful repaint later. As repainting may |
| 2789 | * take some time, re-read our clock as a courtesy to the next |
| 2790 | * output. */ |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2791 | ret = weston_output_repaint(output, repaint_data); |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2792 | weston_compositor_read_presentation_clock(compositor, now); |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 2793 | if (ret != 0) |
| 2794 | goto err; |
| 2795 | |
Tomohito Esaki | 7f4d9ff | 2018-06-05 10:37:06 +0900 | [diff] [blame] | 2796 | output->repainted = true; |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2797 | return ret; |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 2798 | |
| 2799 | err: |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2800 | weston_output_schedule_repaint_reset(output); |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2801 | return ret; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2802 | } |
| 2803 | |
| 2804 | static void |
| 2805 | output_repaint_timer_arm(struct weston_compositor *compositor) |
| 2806 | { |
| 2807 | struct weston_output *output; |
| 2808 | bool any_should_repaint = false; |
| 2809 | struct timespec now; |
Sergi Granell | b4c0886 | 2017-03-18 13:01:15 +0100 | [diff] [blame] | 2810 | int64_t msec_to_next = INT64_MAX; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2811 | |
| 2812 | weston_compositor_read_presentation_clock(compositor, &now); |
| 2813 | |
| 2814 | wl_list_for_each(output, &compositor->output_list, link) { |
| 2815 | int64_t msec_to_this; |
| 2816 | |
| 2817 | if (output->repaint_status != REPAINT_SCHEDULED) |
| 2818 | continue; |
| 2819 | |
| 2820 | msec_to_this = timespec_sub_to_msec(&output->next_repaint, |
| 2821 | &now); |
| 2822 | if (!any_should_repaint || msec_to_this < msec_to_next) |
| 2823 | msec_to_next = msec_to_this; |
| 2824 | |
| 2825 | any_should_repaint = true; |
| 2826 | } |
| 2827 | |
| 2828 | if (!any_should_repaint) |
| 2829 | return; |
| 2830 | |
| 2831 | /* Even if we should repaint immediately, add the minimum 1 ms delay. |
| 2832 | * This is a workaround to allow coalescing multiple output repaints |
| 2833 | * particularly from weston_output_finish_frame() |
| 2834 | * into the same call, which would not happen if we called |
| 2835 | * output_repaint_timer_handler() directly. |
| 2836 | */ |
| 2837 | if (msec_to_next < 1) |
| 2838 | msec_to_next = 1; |
| 2839 | |
| 2840 | wl_event_source_timer_update(compositor->repaint_timer, msec_to_next); |
| 2841 | } |
| 2842 | |
| 2843 | static int |
| 2844 | output_repaint_timer_handler(void *data) |
| 2845 | { |
| 2846 | struct weston_compositor *compositor = data; |
| 2847 | struct weston_output *output; |
| 2848 | struct timespec now; |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2849 | void *repaint_data = NULL; |
Emre Ucan | e479ed8 | 2018-03-20 15:29:40 +0100 | [diff] [blame] | 2850 | int ret = 0; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2851 | |
| 2852 | weston_compositor_read_presentation_clock(compositor, &now); |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2853 | |
| 2854 | if (compositor->backend->repaint_begin) |
| 2855 | repaint_data = compositor->backend->repaint_begin(compositor); |
| 2856 | |
| 2857 | wl_list_for_each(output, &compositor->output_list, link) { |
| 2858 | ret = weston_output_maybe_repaint(output, &now, repaint_data); |
| 2859 | if (ret) |
| 2860 | break; |
| 2861 | } |
| 2862 | |
| 2863 | if (ret == 0) { |
Tomohito Esaki | 09bfcd6 | 2018-06-05 10:37:05 +0900 | [diff] [blame] | 2864 | if (compositor->backend->repaint_flush) |
Antonio Borneo | c90fccc | 2019-06-30 15:51:10 +0200 | [diff] [blame] | 2865 | ret = compositor->backend->repaint_flush(compositor, |
| 2866 | repaint_data); |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2867 | } else { |
Antonio Borneo | c90fccc | 2019-06-30 15:51:10 +0200 | [diff] [blame] | 2868 | if (compositor->backend->repaint_cancel) |
| 2869 | compositor->backend->repaint_cancel(compositor, |
| 2870 | repaint_data); |
| 2871 | } |
| 2872 | |
| 2873 | if (ret != 0) { |
Tomohito Esaki | 7f4d9ff | 2018-06-05 10:37:06 +0900 | [diff] [blame] | 2874 | wl_list_for_each(output, &compositor->output_list, link) { |
| 2875 | if (output->repainted) |
| 2876 | weston_output_schedule_repaint_reset(output); |
| 2877 | } |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2878 | } |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2879 | |
Tomohito Esaki | ddaf95c | 2018-07-10 11:47:15 +0900 | [diff] [blame] | 2880 | wl_list_for_each(output, &compositor->output_list, link) |
| 2881 | output->repainted = false; |
| 2882 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2883 | output_repaint_timer_arm(compositor); |
| 2884 | |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2885 | return 0; |
| 2886 | } |
| 2887 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 2888 | /** |
| 2889 | * \ingroup output |
| 2890 | */ |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2891 | WL_EXPORT void |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 2892 | weston_output_finish_frame(struct weston_output *output, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 2893 | const struct timespec *stamp, |
| 2894 | uint32_t presented_flags) |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2895 | { |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2896 | struct weston_compositor *compositor = output->compositor; |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2897 | int32_t refresh_nsec; |
| 2898 | struct timespec now; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2899 | int64_t msec_rel; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2900 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2901 | |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2902 | assert(output->repaint_status == REPAINT_AWAITING_COMPLETION); |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2903 | assert(stamp || (presented_flags & WP_PRESENTATION_FEEDBACK_INVALID)); |
| 2904 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2905 | weston_compositor_read_presentation_clock(compositor, &now); |
| 2906 | |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2907 | /* If we haven't been supplied any timestamp at all, we don't have a |
| 2908 | * timebase to work against, so any delay just wastes time. Push a |
| 2909 | * repaint as soon as possible so we can get on with it. */ |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2910 | if (!stamp) { |
| 2911 | output->next_repaint = now; |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2912 | goto out; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2913 | } |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2914 | |
Marius Vlad | 3203ff6 | 2019-09-05 14:56:12 +0300 | [diff] [blame] | 2915 | TL_POINT(compositor, "core_repaint_finished", TLP_OUTPUT(output), |
Marius Vlad | df9278a | 2018-03-06 18:56:23 +0200 | [diff] [blame] | 2916 | TLP_VBLANK(stamp), TLP_END); |
| 2917 | |
Pekka Paalanen | d7894d0 | 2015-07-03 15:08:53 +0300 | [diff] [blame] | 2918 | refresh_nsec = millihz_to_nsec(output->current_mode->refresh); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2919 | weston_presentation_feedback_present_list(&output->feedback_list, |
| 2920 | output, refresh_nsec, stamp, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 2921 | output->msc, |
| 2922 | presented_flags); |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2923 | |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 2924 | output->frame_time = *stamp; |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2925 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2926 | timespec_add_nsec(&output->next_repaint, stamp, refresh_nsec); |
| 2927 | timespec_add_msec(&output->next_repaint, &output->next_repaint, |
| 2928 | -compositor->repaint_msec); |
| 2929 | msec_rel = timespec_sub_to_msec(&output->next_repaint, &now); |
Daniel Stone | 84aff5c | 2017-03-01 11:34:04 +0000 | [diff] [blame] | 2930 | |
| 2931 | if (msec_rel < -1000 || msec_rel > 1000) { |
Pekka Paalanen | 8fd4de4 | 2015-03-19 12:27:29 +0200 | [diff] [blame] | 2932 | static bool warned; |
| 2933 | |
| 2934 | if (!warned) |
| 2935 | weston_log("Warning: computed repaint delay is " |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2936 | "insane: %lld msec\n", (long long) msec_rel); |
Pekka Paalanen | 8fd4de4 | 2015-03-19 12:27:29 +0200 | [diff] [blame] | 2937 | warned = true; |
| 2938 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2939 | output->next_repaint = now; |
Pekka Paalanen | 8fd4de4 | 2015-03-19 12:27:29 +0200 | [diff] [blame] | 2940 | } |
| 2941 | |
Mario Kleiner | b7df04e | 2015-06-21 21:25:15 +0200 | [diff] [blame] | 2942 | /* Called from restart_repaint_loop and restart happens already after |
| 2943 | * the deadline given by repaint_msec? In that case we delay until |
| 2944 | * the deadline of the next frame, to give clients a more predictable |
| 2945 | * timing of the repaint cycle to lock on. */ |
Daniel Stone | eca5cca | 2017-02-28 21:53:51 +0000 | [diff] [blame] | 2946 | if (presented_flags == WP_PRESENTATION_FEEDBACK_INVALID && |
| 2947 | msec_rel < 0) { |
| 2948 | while (timespec_sub_to_nsec(&output->next_repaint, &now) < 0) { |
| 2949 | timespec_add_nsec(&output->next_repaint, |
| 2950 | &output->next_repaint, |
| 2951 | refresh_nsec); |
| 2952 | } |
| 2953 | } |
Mario Kleiner | b7df04e | 2015-06-21 21:25:15 +0200 | [diff] [blame] | 2954 | |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2955 | out: |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2956 | output->repaint_status = REPAINT_SCHEDULED; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2957 | output_repaint_timer_arm(compositor); |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2958 | } |
| 2959 | |
| 2960 | static void |
| 2961 | idle_repaint(void *data) |
| 2962 | { |
| 2963 | struct weston_output *output = data; |
Antonio Borneo | c90fccc | 2019-06-30 15:51:10 +0200 | [diff] [blame] | 2964 | int ret; |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2965 | |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2966 | assert(output->repaint_status == REPAINT_BEGIN_FROM_IDLE); |
| 2967 | output->repaint_status = REPAINT_AWAITING_COMPLETION; |
Pekka Paalanen | dcbcfc7 | 2017-10-26 14:33:59 +0300 | [diff] [blame] | 2968 | output->idle_repaint_source = NULL; |
Antonio Borneo | c90fccc | 2019-06-30 15:51:10 +0200 | [diff] [blame] | 2969 | ret = output->start_repaint_loop(output); |
| 2970 | if (ret != 0) |
| 2971 | weston_output_schedule_repaint_reset(output); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2972 | } |
| 2973 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2974 | WL_EXPORT void |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2975 | weston_layer_entry_insert(struct weston_layer_entry *list, |
| 2976 | struct weston_layer_entry *entry) |
| 2977 | { |
| 2978 | wl_list_insert(&list->link, &entry->link); |
| 2979 | entry->layer = list->layer; |
| 2980 | } |
| 2981 | |
| 2982 | WL_EXPORT void |
| 2983 | weston_layer_entry_remove(struct weston_layer_entry *entry) |
| 2984 | { |
| 2985 | wl_list_remove(&entry->link); |
| 2986 | wl_list_init(&entry->link); |
| 2987 | entry->layer = NULL; |
| 2988 | } |
| 2989 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 2990 | |
| 2991 | /** Initialize the weston_layer struct. |
| 2992 | * |
| 2993 | * \param compositor The compositor instance |
| 2994 | * \param layer The layer to initialize |
| 2995 | */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2996 | WL_EXPORT void |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 2997 | weston_layer_init(struct weston_layer *layer, |
| 2998 | struct weston_compositor *compositor) |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2999 | { |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 3000 | layer->compositor = compositor; |
| 3001 | wl_list_init(&layer->link); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3002 | wl_list_init(&layer->view_list.link); |
| 3003 | layer->view_list.layer = layer; |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 3004 | weston_layer_set_mask_infinite(layer); |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 3005 | } |
| 3006 | |
| 3007 | /** Sets the position of the layer in the layer list. The layer will be placed |
| 3008 | * below any layer with the same position value, if any. |
| 3009 | * This function is safe to call if the layer is already on the list, but the |
| 3010 | * layer may be moved below other layers at the same position, if any. |
| 3011 | * |
| 3012 | * \param layer The layer to modify |
| 3013 | * \param position The position the layer will be placed at |
| 3014 | */ |
| 3015 | WL_EXPORT void |
| 3016 | weston_layer_set_position(struct weston_layer *layer, |
| 3017 | enum weston_layer_position position) |
| 3018 | { |
| 3019 | struct weston_layer *below; |
| 3020 | |
| 3021 | wl_list_remove(&layer->link); |
| 3022 | |
| 3023 | /* layer_list is ordered from top to bottom, the last layer being the |
| 3024 | * background with the smallest position value */ |
| 3025 | |
| 3026 | layer->position = position; |
| 3027 | wl_list_for_each_reverse(below, &layer->compositor->layer_list, link) { |
| 3028 | if (below->position >= layer->position) { |
| 3029 | wl_list_insert(&below->link, &layer->link); |
| 3030 | return; |
| 3031 | } |
| 3032 | } |
| 3033 | wl_list_insert(&layer->compositor->layer_list, &layer->link); |
| 3034 | } |
| 3035 | |
| 3036 | /** Hide a layer by taking it off the layer list. |
| 3037 | * This function is safe to call if the layer is not on the list. |
| 3038 | * |
| 3039 | * \param layer The layer to hide |
| 3040 | */ |
| 3041 | WL_EXPORT void |
| 3042 | weston_layer_unset_position(struct weston_layer *layer) |
| 3043 | { |
| 3044 | wl_list_remove(&layer->link); |
| 3045 | wl_list_init(&layer->link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3046 | } |
| 3047 | |
| 3048 | WL_EXPORT void |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 3049 | weston_layer_set_mask(struct weston_layer *layer, |
| 3050 | int x, int y, int width, int height) |
| 3051 | { |
| 3052 | struct weston_view *view; |
| 3053 | |
| 3054 | layer->mask.x1 = x; |
| 3055 | layer->mask.x2 = x + width; |
| 3056 | layer->mask.y1 = y; |
| 3057 | layer->mask.y2 = y + height; |
| 3058 | |
| 3059 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
| 3060 | weston_view_geometry_dirty(view); |
| 3061 | } |
| 3062 | } |
| 3063 | |
| 3064 | WL_EXPORT void |
| 3065 | weston_layer_set_mask_infinite(struct weston_layer *layer) |
| 3066 | { |
Adam Jackson | 3c3f3b1 | 2019-10-16 16:02:59 -0400 | [diff] [blame] | 3067 | struct weston_view *view; |
| 3068 | |
| 3069 | layer->mask.x1 = INT32_MIN; |
| 3070 | layer->mask.x2 = INT32_MAX; |
| 3071 | layer->mask.y1 = INT32_MIN; |
| 3072 | layer->mask.y2 = INT32_MAX; |
| 3073 | |
| 3074 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
| 3075 | weston_view_geometry_dirty(view); |
| 3076 | } |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 3077 | } |
| 3078 | |
Daniel Stone | 3b77563 | 2018-07-20 08:38:25 +0100 | [diff] [blame] | 3079 | WL_EXPORT bool |
| 3080 | weston_layer_mask_is_infinite(struct weston_layer *layer) |
| 3081 | { |
| 3082 | return layer->mask.x1 == INT32_MIN && |
| 3083 | layer->mask.y1 == INT32_MIN && |
Adam Jackson | 3c3f3b1 | 2019-10-16 16:02:59 -0400 | [diff] [blame] | 3084 | layer->mask.x2 == INT32_MAX && |
| 3085 | layer->mask.y2 == INT32_MAX; |
Daniel Stone | 3b77563 | 2018-07-20 08:38:25 +0100 | [diff] [blame] | 3086 | } |
| 3087 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 3088 | /** |
| 3089 | * \ingroup output |
| 3090 | */ |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 3091 | WL_EXPORT void |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 3092 | weston_output_schedule_repaint(struct weston_output *output) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 3093 | { |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 3094 | struct weston_compositor *compositor = output->compositor; |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 3095 | struct wl_event_loop *loop; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 3096 | |
Bryce Harrington | 08976ac | 2016-08-30 12:05:16 -0700 | [diff] [blame] | 3097 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING || |
| 3098 | compositor->state == WESTON_COMPOSITOR_OFFSCREEN) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 3099 | return; |
| 3100 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3101 | if (!output->repaint_needed) |
Marius Vlad | 3203ff6 | 2019-09-05 14:56:12 +0300 | [diff] [blame] | 3102 | TL_POINT(compositor, "core_repaint_req", TLP_OUTPUT(output), TLP_END); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3103 | |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 3104 | loop = wl_display_get_event_loop(compositor->wl_display); |
Daniel Stone | 09a97e2 | 2017-03-01 11:34:06 +0000 | [diff] [blame] | 3105 | output->repaint_needed = true; |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 3106 | |
| 3107 | /* If we already have a repaint scheduled for our idle handler, |
| 3108 | * no need to set it again. If the repaint has been called but |
| 3109 | * not finished, then weston_output_finish_frame() will notice |
| 3110 | * that a repaint is needed and schedule one. */ |
| 3111 | if (output->repaint_status != REPAINT_NOT_SCHEDULED) |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 3112 | return; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 3113 | |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 3114 | output->repaint_status = REPAINT_BEGIN_FROM_IDLE; |
Pekka Paalanen | dcbcfc7 | 2017-10-26 14:33:59 +0300 | [diff] [blame] | 3115 | assert(!output->idle_repaint_source); |
| 3116 | output->idle_repaint_source = wl_event_loop_add_idle(loop, idle_repaint, |
| 3117 | output); |
Marius Vlad | 3203ff6 | 2019-09-05 14:56:12 +0300 | [diff] [blame] | 3118 | TL_POINT(compositor, "core_repaint_enter_loop", TLP_OUTPUT(output), TLP_END); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 3119 | } |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 3120 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 3121 | /** weston_compositor_schedule_repaint |
| 3122 | * \ingroup compositor |
| 3123 | */ |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3124 | WL_EXPORT void |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 3125 | weston_compositor_schedule_repaint(struct weston_compositor *compositor) |
| 3126 | { |
| 3127 | struct weston_output *output; |
| 3128 | |
| 3129 | wl_list_for_each(output, &compositor->output_list, link) |
| 3130 | weston_output_schedule_repaint(output); |
| 3131 | } |
| 3132 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 3133 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 3134 | surface_destroy(struct wl_client *client, struct wl_resource *resource) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 3135 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3136 | wl_resource_destroy(resource); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 3137 | } |
| 3138 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 3139 | static void |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 3140 | surface_attach(struct wl_client *client, |
| 3141 | struct wl_resource *resource, |
| 3142 | struct wl_resource *buffer_resource, int32_t sx, int32_t sy) |
| 3143 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3144 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 3145 | struct weston_buffer *buffer = NULL; |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 3146 | |
Kristian Høgsberg | ab19f93 | 2013-08-20 11:30:54 -0700 | [diff] [blame] | 3147 | if (buffer_resource) { |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 3148 | buffer = weston_buffer_from_resource(buffer_resource); |
Kristian Høgsberg | ab19f93 | 2013-08-20 11:30:54 -0700 | [diff] [blame] | 3149 | if (buffer == NULL) { |
| 3150 | wl_client_post_no_memory(client); |
| 3151 | return; |
| 3152 | } |
Kristian Høgsberg | 08b58c7 | 2013-08-15 12:26:42 -0700 | [diff] [blame] | 3153 | } |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 3154 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 3155 | /* Attach, attach, without commit in between does not send |
| 3156 | * wl_buffer.release. */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3157 | weston_surface_state_set_buffer(&surface->pending, buffer); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 3158 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3159 | surface->pending.sx = sx; |
| 3160 | surface->pending.sy = sy; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3161 | surface->pending.newly_attached = 1; |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 3162 | } |
| 3163 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 3164 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3165 | surface_damage(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 3166 | struct wl_resource *resource, |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3167 | 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] | 3168 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3169 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 9d69f8e | 2010-09-03 14:46:38 -0400 | [diff] [blame] | 3170 | |
Derek Foreman | 57e92ed | 2015-11-17 14:11:35 -0600 | [diff] [blame] | 3171 | if (width <= 0 || height <= 0) |
| 3172 | return; |
| 3173 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3174 | pixman_region32_union_rect(&surface->pending.damage_surface, |
| 3175 | &surface->pending.damage_surface, |
| 3176 | x, y, width, height); |
| 3177 | } |
| 3178 | |
| 3179 | static void |
| 3180 | surface_damage_buffer(struct wl_client *client, |
| 3181 | struct wl_resource *resource, |
| 3182 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 3183 | { |
| 3184 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
| 3185 | |
| 3186 | if (width <= 0 || height <= 0) |
| 3187 | return; |
| 3188 | |
| 3189 | pixman_region32_union_rect(&surface->pending.damage_buffer, |
| 3190 | &surface->pending.damage_buffer, |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 3191 | x, y, width, height); |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 3192 | } |
| 3193 | |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3194 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 3195 | destroy_frame_callback(struct wl_resource *resource) |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3196 | { |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 3197 | struct weston_frame_callback *cb = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 3198 | |
| 3199 | wl_list_remove(&cb->link); |
Pekka Paalanen | 8c19645 | 2011-11-15 11:45:42 +0200 | [diff] [blame] | 3200 | free(cb); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3201 | } |
| 3202 | |
| 3203 | static void |
| 3204 | surface_frame(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 3205 | struct wl_resource *resource, uint32_t callback) |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3206 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3207 | struct weston_frame_callback *cb; |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3208 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3209 | |
| 3210 | cb = malloc(sizeof *cb); |
| 3211 | if (cb == NULL) { |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 3212 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3213 | return; |
| 3214 | } |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 3215 | |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 3216 | cb->resource = wl_resource_create(client, &wl_callback_interface, 1, |
| 3217 | callback); |
| 3218 | if (cb->resource == NULL) { |
| 3219 | free(cb); |
| 3220 | wl_resource_post_no_memory(resource); |
| 3221 | return; |
| 3222 | } |
| 3223 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3224 | wl_resource_set_implementation(cb->resource, NULL, cb, |
| 3225 | destroy_frame_callback); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3226 | |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 3227 | wl_list_insert(surface->pending.frame_callback_list.prev, &cb->link); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3228 | } |
| 3229 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3230 | static void |
| 3231 | surface_set_opaque_region(struct wl_client *client, |
| 3232 | struct wl_resource *resource, |
| 3233 | struct wl_resource *region_resource) |
| 3234 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3235 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3236 | struct weston_region *region; |
| 3237 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3238 | if (region_resource) { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 3239 | region = wl_resource_get_user_data(region_resource); |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 3240 | pixman_region32_copy(&surface->pending.opaque, |
| 3241 | ®ion->region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3242 | } else { |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 3243 | pixman_region32_clear(&surface->pending.opaque); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3244 | } |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3245 | } |
| 3246 | |
| 3247 | static void |
| 3248 | surface_set_input_region(struct wl_client *client, |
| 3249 | struct wl_resource *resource, |
| 3250 | struct wl_resource *region_resource) |
| 3251 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3252 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 010f98b | 2012-02-23 17:30:45 -0500 | [diff] [blame] | 3253 | struct weston_region *region; |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3254 | |
| 3255 | if (region_resource) { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 3256 | region = wl_resource_get_user_data(region_resource); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3257 | pixman_region32_copy(&surface->pending.input, |
| 3258 | ®ion->region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3259 | } else { |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3260 | pixman_region32_fini(&surface->pending.input); |
| 3261 | region_init_infinite(&surface->pending.input); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3262 | } |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3263 | } |
| 3264 | |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 3265 | /* Cause damage to this sub-surface and all its children. |
| 3266 | * |
| 3267 | * This is useful when there are state changes that need an implicit |
| 3268 | * damage, e.g. a z-order change. |
| 3269 | */ |
| 3270 | static void |
| 3271 | weston_surface_damage_subsurfaces(struct weston_subsurface *sub) |
| 3272 | { |
| 3273 | struct weston_subsurface *child; |
| 3274 | |
| 3275 | weston_surface_damage(sub->surface); |
| 3276 | sub->reordered = false; |
| 3277 | |
| 3278 | wl_list_for_each(child, &sub->surface->subsurface_list, parent_link) |
| 3279 | if (child != sub) |
| 3280 | weston_surface_damage_subsurfaces(child); |
| 3281 | } |
| 3282 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3283 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3284 | weston_surface_commit_subsurface_order(struct weston_surface *surface) |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3285 | { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3286 | struct weston_subsurface *sub; |
| 3287 | |
| 3288 | wl_list_for_each_reverse(sub, &surface->subsurface_list_pending, |
| 3289 | parent_link_pending) { |
| 3290 | wl_list_remove(&sub->parent_link); |
| 3291 | wl_list_insert(&surface->subsurface_list, &sub->parent_link); |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 3292 | |
| 3293 | if (sub->reordered) |
| 3294 | weston_surface_damage_subsurfaces(sub); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3295 | } |
| 3296 | } |
| 3297 | |
| 3298 | static void |
Pekka Paalanen | 04baea5 | 2016-04-26 15:50:58 +0300 | [diff] [blame] | 3299 | weston_surface_build_buffer_matrix(const struct weston_surface *surface, |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 3300 | struct weston_matrix *matrix) |
| 3301 | { |
Pekka Paalanen | 04baea5 | 2016-04-26 15:50:58 +0300 | [diff] [blame] | 3302 | const struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 3303 | double src_width, src_height, dest_width, dest_height; |
| 3304 | |
| 3305 | weston_matrix_init(matrix); |
| 3306 | |
| 3307 | if (vp->buffer.src_width == wl_fixed_from_int(-1)) { |
| 3308 | src_width = surface->width_from_buffer; |
| 3309 | src_height = surface->height_from_buffer; |
| 3310 | } else { |
| 3311 | src_width = wl_fixed_to_double(vp->buffer.src_width); |
| 3312 | src_height = wl_fixed_to_double(vp->buffer.src_height); |
| 3313 | } |
| 3314 | |
| 3315 | if (vp->surface.width == -1) { |
| 3316 | dest_width = src_width; |
| 3317 | dest_height = src_height; |
| 3318 | } else { |
| 3319 | dest_width = vp->surface.width; |
| 3320 | dest_height = vp->surface.height; |
| 3321 | } |
| 3322 | |
| 3323 | if (src_width != dest_width || src_height != dest_height) |
| 3324 | weston_matrix_scale(matrix, |
| 3325 | src_width / dest_width, |
| 3326 | src_height / dest_height, 1); |
| 3327 | |
| 3328 | if (vp->buffer.src_width != wl_fixed_from_int(-1)) |
| 3329 | weston_matrix_translate(matrix, |
| 3330 | wl_fixed_to_double(vp->buffer.src_x), |
| 3331 | wl_fixed_to_double(vp->buffer.src_y), |
| 3332 | 0); |
| 3333 | |
| 3334 | switch (vp->buffer.transform) { |
| 3335 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 3336 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 3337 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 3338 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 3339 | weston_matrix_scale(matrix, -1, 1, 1); |
| 3340 | weston_matrix_translate(matrix, |
| 3341 | surface->width_from_buffer, 0, 0); |
| 3342 | break; |
| 3343 | } |
| 3344 | |
| 3345 | switch (vp->buffer.transform) { |
| 3346 | default: |
| 3347 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 3348 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 3349 | break; |
| 3350 | case WL_OUTPUT_TRANSFORM_90: |
| 3351 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 3352 | weston_matrix_rotate_xy(matrix, 0, 1); |
| 3353 | weston_matrix_translate(matrix, |
| 3354 | surface->height_from_buffer, 0, 0); |
| 3355 | break; |
| 3356 | case WL_OUTPUT_TRANSFORM_180: |
| 3357 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 3358 | weston_matrix_rotate_xy(matrix, -1, 0); |
| 3359 | weston_matrix_translate(matrix, |
| 3360 | surface->width_from_buffer, |
| 3361 | surface->height_from_buffer, 0); |
| 3362 | break; |
| 3363 | case WL_OUTPUT_TRANSFORM_270: |
| 3364 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 3365 | weston_matrix_rotate_xy(matrix, 0, -1); |
| 3366 | weston_matrix_translate(matrix, |
| 3367 | 0, surface->width_from_buffer, 0); |
| 3368 | break; |
| 3369 | } |
| 3370 | |
| 3371 | weston_matrix_scale(matrix, vp->buffer.scale, vp->buffer.scale, 1); |
| 3372 | } |
| 3373 | |
Pekka Paalanen | d9aae9c | 2016-04-26 13:46:38 +0300 | [diff] [blame] | 3374 | /** |
| 3375 | * Compute a + b > c while being safe to overflows. |
| 3376 | */ |
| 3377 | static bool |
| 3378 | fixed_sum_gt(wl_fixed_t a, wl_fixed_t b, wl_fixed_t c) |
| 3379 | { |
| 3380 | return (int64_t)a + (int64_t)b > (int64_t)c; |
| 3381 | } |
| 3382 | |
| 3383 | static bool |
| 3384 | weston_surface_is_pending_viewport_source_valid( |
| 3385 | const struct weston_surface *surface) |
| 3386 | { |
| 3387 | const struct weston_surface_state *pend = &surface->pending; |
| 3388 | const struct weston_buffer_viewport *vp = &pend->buffer_viewport; |
| 3389 | int width_from_buffer = 0; |
| 3390 | int height_from_buffer = 0; |
| 3391 | wl_fixed_t w; |
| 3392 | wl_fixed_t h; |
| 3393 | |
| 3394 | /* If viewport source rect is not set, it is always ok. */ |
| 3395 | if (vp->buffer.src_width == wl_fixed_from_int(-1)) |
| 3396 | return true; |
| 3397 | |
| 3398 | if (pend->newly_attached) { |
| 3399 | if (pend->buffer) { |
| 3400 | convert_size_by_transform_scale(&width_from_buffer, |
| 3401 | &height_from_buffer, |
| 3402 | pend->buffer->width, |
| 3403 | pend->buffer->height, |
| 3404 | vp->buffer.transform, |
| 3405 | vp->buffer.scale); |
| 3406 | } else { |
| 3407 | /* No buffer: viewport is irrelevant. */ |
| 3408 | return true; |
| 3409 | } |
| 3410 | } else { |
| 3411 | width_from_buffer = surface->width_from_buffer; |
| 3412 | height_from_buffer = surface->height_from_buffer; |
| 3413 | } |
| 3414 | |
| 3415 | assert((width_from_buffer == 0) == (height_from_buffer == 0)); |
| 3416 | assert(width_from_buffer >= 0 && height_from_buffer >= 0); |
| 3417 | |
| 3418 | /* No buffer: viewport is irrelevant. */ |
| 3419 | if (width_from_buffer == 0 || height_from_buffer == 0) |
| 3420 | return true; |
| 3421 | |
| 3422 | /* overflow checks for wl_fixed_from_int() */ |
| 3423 | if (width_from_buffer > wl_fixed_to_int(INT32_MAX)) |
| 3424 | return false; |
| 3425 | if (height_from_buffer > wl_fixed_to_int(INT32_MAX)) |
| 3426 | return false; |
| 3427 | |
| 3428 | w = wl_fixed_from_int(width_from_buffer); |
| 3429 | h = wl_fixed_from_int(height_from_buffer); |
| 3430 | |
| 3431 | if (fixed_sum_gt(vp->buffer.src_x, vp->buffer.src_width, w)) |
| 3432 | return false; |
| 3433 | if (fixed_sum_gt(vp->buffer.src_y, vp->buffer.src_height, h)) |
| 3434 | return false; |
| 3435 | |
| 3436 | return true; |
| 3437 | } |
| 3438 | |
Pekka Paalanen | bb32ccc | 2016-04-26 14:28:28 +0300 | [diff] [blame] | 3439 | static bool |
| 3440 | fixed_is_integer(wl_fixed_t v) |
| 3441 | { |
| 3442 | return (v & 0xff) == 0; |
| 3443 | } |
| 3444 | |
| 3445 | static bool |
| 3446 | weston_surface_is_pending_viewport_dst_size_int( |
| 3447 | const struct weston_surface *surface) |
| 3448 | { |
| 3449 | const struct weston_buffer_viewport *vp = |
| 3450 | &surface->pending.buffer_viewport; |
| 3451 | |
| 3452 | if (vp->surface.width != -1) { |
| 3453 | assert(vp->surface.width > 0 && vp->surface.height > 0); |
| 3454 | return true; |
| 3455 | } |
| 3456 | |
| 3457 | return fixed_is_integer(vp->buffer.src_width) && |
| 3458 | fixed_is_integer(vp->buffer.src_height); |
| 3459 | } |
| 3460 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3461 | /* Translate pending damage in buffer co-ordinates to surface |
| 3462 | * co-ordinates and union it with a pixman_region32_t. |
| 3463 | * This should only be called after the buffer is attached. |
| 3464 | */ |
| 3465 | static void |
| 3466 | apply_damage_buffer(pixman_region32_t *dest, |
| 3467 | struct weston_surface *surface, |
| 3468 | struct weston_surface_state *state) |
| 3469 | { |
| 3470 | struct weston_buffer *buffer = surface->buffer_ref.buffer; |
| 3471 | |
| 3472 | /* wl_surface.damage_buffer needs to be clipped to the buffer, |
| 3473 | * translated into surface co-ordinates and unioned with |
| 3474 | * any other surface damage. |
| 3475 | * None of this makes sense if there is no buffer though. |
| 3476 | */ |
| 3477 | if (buffer && pixman_region32_not_empty(&state->damage_buffer)) { |
| 3478 | pixman_region32_t buffer_damage; |
| 3479 | |
| 3480 | pixman_region32_intersect_rect(&state->damage_buffer, |
| 3481 | &state->damage_buffer, |
| 3482 | 0, 0, buffer->width, |
| 3483 | buffer->height); |
| 3484 | pixman_region32_init(&buffer_damage); |
| 3485 | weston_matrix_transform_region(&buffer_damage, |
| 3486 | &surface->buffer_to_surface_matrix, |
| 3487 | &state->damage_buffer); |
| 3488 | pixman_region32_union(dest, dest, &buffer_damage); |
| 3489 | pixman_region32_fini(&buffer_damage); |
| 3490 | } |
| 3491 | /* We should clear this on commit even if there was no buffer */ |
| 3492 | pixman_region32_clear(&state->damage_buffer); |
| 3493 | } |
| 3494 | |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 3495 | static void |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 3496 | weston_surface_set_desired_protection(struct weston_surface *surface, |
| 3497 | enum weston_hdcp_protection protection) |
| 3498 | { |
| 3499 | if (surface->desired_protection == protection) |
| 3500 | return; |
| 3501 | surface->desired_protection = protection; |
| 3502 | weston_surface_damage(surface); |
| 3503 | } |
| 3504 | |
| 3505 | static void |
Ankit Nautiyal | 5cfe03c | 2019-03-28 15:05:42 +0530 | [diff] [blame] | 3506 | weston_surface_set_protection_mode(struct weston_surface *surface, |
| 3507 | enum weston_surface_protection_mode p_mode) |
| 3508 | { |
| 3509 | struct content_protection *cp = surface->compositor->content_protection; |
| 3510 | struct protected_surface *psurface; |
| 3511 | |
| 3512 | surface->protection_mode = p_mode; |
| 3513 | wl_list_for_each(psurface, &cp->protected_list, link) { |
| 3514 | if (!psurface || psurface->surface != surface) |
| 3515 | continue; |
| 3516 | weston_protected_surface_send_event(psurface, |
| 3517 | surface->current_protection); |
| 3518 | } |
| 3519 | } |
| 3520 | |
| 3521 | static void |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3522 | weston_surface_commit_state(struct weston_surface *surface, |
| 3523 | struct weston_surface_state *state) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3524 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3525 | struct weston_view *view; |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 3526 | pixman_region32_t opaque; |
| 3527 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3528 | /* wl_surface.set_buffer_transform */ |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3529 | /* wl_surface.set_buffer_scale */ |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 3530 | /* wp_viewport.set_source */ |
| 3531 | /* wp_viewport.set_destination */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3532 | surface->buffer_viewport = state->buffer_viewport; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3533 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3534 | /* wl_surface.attach */ |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3535 | if (state->newly_attached) { |
| 3536 | /* zwp_surface_synchronization_v1.set_acquire_fence */ |
| 3537 | fd_move(&surface->acquire_fence_fd, |
| 3538 | &state->acquire_fence_fd); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3539 | /* zwp_surface_synchronization_v1.get_release */ |
| 3540 | weston_buffer_release_move(&surface->buffer_release_ref, |
| 3541 | &state->buffer_release_ref); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3542 | weston_surface_attach(surface, state->buffer); |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3543 | } |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3544 | weston_surface_state_set_buffer(state, NULL); |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3545 | assert(state->acquire_fence_fd == -1); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3546 | assert(state->buffer_release_ref.buffer_release == NULL); |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3547 | |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 3548 | weston_surface_build_buffer_matrix(surface, |
| 3549 | &surface->surface_to_buffer_matrix); |
| 3550 | weston_matrix_invert(&surface->buffer_to_surface_matrix, |
| 3551 | &surface->surface_to_buffer_matrix); |
| 3552 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3553 | if (state->newly_attached || state->buffer_viewport.changed) { |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3554 | weston_surface_update_size(surface); |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3555 | if (surface->committed) |
| 3556 | surface->committed(surface, state->sx, state->sy); |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3557 | } |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3558 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3559 | state->sx = 0; |
| 3560 | state->sy = 0; |
| 3561 | state->newly_attached = 0; |
| 3562 | state->buffer_viewport.changed = 0; |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 3563 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3564 | /* wl_surface.damage and wl_surface.damage_buffer */ |
Marius Vlad | 2a1b786 | 2019-09-05 13:12:18 +0300 | [diff] [blame] | 3565 | if (pixman_region32_not_empty(&state->damage_surface) || |
| 3566 | pixman_region32_not_empty(&state->damage_buffer)) |
Marius Vlad | 3203ff6 | 2019-09-05 14:56:12 +0300 | [diff] [blame] | 3567 | TL_POINT(surface->compositor, "core_commit_damage", TLP_SURFACE(surface), TLP_END); |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3568 | |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 3569 | pixman_region32_union(&surface->damage, &surface->damage, |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3570 | &state->damage_surface); |
| 3571 | |
| 3572 | apply_damage_buffer(&surface->damage, surface, state); |
| 3573 | |
Kristian Høgsberg | 4d0214c | 2012-11-08 11:36:02 -0500 | [diff] [blame] | 3574 | pixman_region32_intersect_rect(&surface->damage, &surface->damage, |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 3575 | 0, 0, surface->width, surface->height); |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3576 | pixman_region32_clear(&state->damage_surface); |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 3577 | |
| 3578 | /* wl_surface.set_opaque_region */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3579 | pixman_region32_init(&opaque); |
| 3580 | pixman_region32_intersect_rect(&opaque, &state->opaque, |
| 3581 | 0, 0, surface->width, surface->height); |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 3582 | |
| 3583 | if (!pixman_region32_equal(&opaque, &surface->opaque)) { |
| 3584 | pixman_region32_copy(&surface->opaque, &opaque); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3585 | wl_list_for_each(view, &surface->views, surface_link) |
| 3586 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 3587 | } |
| 3588 | |
| 3589 | pixman_region32_fini(&opaque); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3590 | |
| 3591 | /* wl_surface.set_input_region */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3592 | pixman_region32_intersect_rect(&surface->input, &state->input, |
| 3593 | 0, 0, surface->width, surface->height); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3594 | |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 3595 | /* wl_surface.frame */ |
| 3596 | wl_list_insert_list(&surface->frame_callback_list, |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3597 | &state->frame_callback_list); |
| 3598 | wl_list_init(&state->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3599 | |
| 3600 | /* XXX: |
| 3601 | * What should happen with a feedback request, if there |
| 3602 | * is no wl_buffer attached for this commit? |
| 3603 | */ |
| 3604 | |
| 3605 | /* presentation.feedback */ |
| 3606 | wl_list_insert_list(&surface->feedback_list, |
| 3607 | &state->feedback_list); |
| 3608 | wl_list_init(&state->feedback_list); |
Jonas Ådahl | 5d9ca27 | 2016-07-22 17:48:03 +0800 | [diff] [blame] | 3609 | |
Ankit Nautiyal | 5cfe03c | 2019-03-28 15:05:42 +0530 | [diff] [blame] | 3610 | /* weston_protected_surface.enforced/relaxed */ |
| 3611 | if (surface->protection_mode != state->protection_mode) |
| 3612 | weston_surface_set_protection_mode(surface, |
| 3613 | state->protection_mode); |
| 3614 | |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 3615 | /* weston_protected_surface.set_type */ |
| 3616 | weston_surface_set_desired_protection(surface, state->desired_protection); |
| 3617 | |
Jonas Ådahl | 5d9ca27 | 2016-07-22 17:48:03 +0800 | [diff] [blame] | 3618 | wl_signal_emit(&surface->commit_signal, surface); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3619 | } |
| 3620 | |
| 3621 | static void |
| 3622 | weston_surface_commit(struct weston_surface *surface) |
| 3623 | { |
| 3624 | weston_surface_commit_state(surface, &surface->pending); |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 3625 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3626 | weston_surface_commit_subsurface_order(surface); |
| 3627 | |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3628 | weston_surface_schedule_repaint(surface); |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3629 | } |
| 3630 | |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3631 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3632 | weston_subsurface_commit(struct weston_subsurface *sub); |
| 3633 | |
| 3634 | static void |
| 3635 | weston_subsurface_parent_commit(struct weston_subsurface *sub, |
| 3636 | int parent_is_synchronized); |
| 3637 | |
| 3638 | static void |
| 3639 | surface_commit(struct wl_client *client, struct wl_resource *resource) |
| 3640 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3641 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3642 | struct weston_subsurface *sub = weston_surface_to_subsurface(surface); |
| 3643 | |
Pekka Paalanen | d9aae9c | 2016-04-26 13:46:38 +0300 | [diff] [blame] | 3644 | if (!weston_surface_is_pending_viewport_source_valid(surface)) { |
| 3645 | assert(surface->viewport_resource); |
| 3646 | |
| 3647 | wl_resource_post_error(surface->viewport_resource, |
| 3648 | WP_VIEWPORT_ERROR_OUT_OF_BUFFER, |
| 3649 | "wl_surface@%d has viewport source outside buffer", |
| 3650 | wl_resource_get_id(resource)); |
| 3651 | return; |
| 3652 | } |
| 3653 | |
Pekka Paalanen | bb32ccc | 2016-04-26 14:28:28 +0300 | [diff] [blame] | 3654 | if (!weston_surface_is_pending_viewport_dst_size_int(surface)) { |
| 3655 | assert(surface->viewport_resource); |
| 3656 | |
| 3657 | wl_resource_post_error(surface->viewport_resource, |
| 3658 | WP_VIEWPORT_ERROR_BAD_SIZE, |
| 3659 | "wl_surface@%d viewport dst size not integer", |
| 3660 | wl_resource_get_id(resource)); |
| 3661 | return; |
| 3662 | } |
| 3663 | |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3664 | if (surface->pending.acquire_fence_fd >= 0) { |
| 3665 | assert(surface->synchronization_resource); |
| 3666 | |
| 3667 | if (!surface->pending.buffer) { |
| 3668 | fd_clear(&surface->pending.acquire_fence_fd); |
| 3669 | wl_resource_post_error(surface->synchronization_resource, |
| 3670 | ZWP_LINUX_SURFACE_SYNCHRONIZATION_V1_ERROR_NO_BUFFER, |
| 3671 | "wl_surface@%"PRIu32" no buffer for synchronization", |
| 3672 | wl_resource_get_id(resource)); |
| 3673 | return; |
| 3674 | } |
| 3675 | |
| 3676 | /* We support fences for both wp_linux_dmabuf and opaque EGL |
| 3677 | * buffers, as mandated by minor version 2 of the |
| 3678 | * zwp_linux_explicit_synchronization_v1 protocol. Since |
| 3679 | * renderers that support fences currently only support these |
| 3680 | * two buffer types plus SHM buffers, we can just check for the |
| 3681 | * SHM buffer case here. |
| 3682 | */ |
| 3683 | if (wl_shm_buffer_get(surface->pending.buffer->resource)) { |
| 3684 | fd_clear(&surface->pending.acquire_fence_fd); |
| 3685 | wl_resource_post_error(surface->synchronization_resource, |
| 3686 | ZWP_LINUX_SURFACE_SYNCHRONIZATION_V1_ERROR_UNSUPPORTED_BUFFER, |
| 3687 | "wl_surface@%"PRIu32" unsupported buffer for synchronization", |
| 3688 | wl_resource_get_id(resource)); |
| 3689 | return; |
| 3690 | } |
| 3691 | } |
| 3692 | |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3693 | if (surface->pending.buffer_release_ref.buffer_release && |
| 3694 | !surface->pending.buffer) { |
| 3695 | assert(surface->synchronization_resource); |
| 3696 | |
| 3697 | wl_resource_post_error(surface->synchronization_resource, |
| 3698 | ZWP_LINUX_SURFACE_SYNCHRONIZATION_V1_ERROR_NO_BUFFER, |
| 3699 | "wl_surface@%"PRIu32" no buffer for synchronization", |
| 3700 | wl_resource_get_id(resource)); |
| 3701 | return; |
| 3702 | } |
| 3703 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3704 | if (sub) { |
| 3705 | weston_subsurface_commit(sub); |
| 3706 | return; |
| 3707 | } |
| 3708 | |
| 3709 | weston_surface_commit(surface); |
| 3710 | |
| 3711 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
| 3712 | if (sub->surface != surface) |
| 3713 | weston_subsurface_parent_commit(sub, 0); |
| 3714 | } |
| 3715 | } |
| 3716 | |
| 3717 | static void |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3718 | surface_set_buffer_transform(struct wl_client *client, |
| 3719 | struct wl_resource *resource, int transform) |
| 3720 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3721 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3722 | |
Jonny Lamb | a55f139 | 2014-05-30 12:07:15 +0200 | [diff] [blame] | 3723 | /* if wl_output.transform grows more members this will need to be updated. */ |
| 3724 | if (transform < 0 || |
| 3725 | transform > WL_OUTPUT_TRANSFORM_FLIPPED_270) { |
| 3726 | wl_resource_post_error(resource, |
| 3727 | WL_SURFACE_ERROR_INVALID_TRANSFORM, |
| 3728 | "buffer transform must be a valid transform " |
| 3729 | "('%d' specified)", transform); |
| 3730 | return; |
| 3731 | } |
| 3732 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 3733 | surface->pending.buffer_viewport.buffer.transform = transform; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3734 | surface->pending.buffer_viewport.changed = 1; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3735 | } |
| 3736 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3737 | static void |
| 3738 | surface_set_buffer_scale(struct wl_client *client, |
| 3739 | struct wl_resource *resource, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 3740 | int32_t scale) |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3741 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3742 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3743 | |
Jonny Lamb | a55f139 | 2014-05-30 12:07:15 +0200 | [diff] [blame] | 3744 | if (scale < 1) { |
| 3745 | wl_resource_post_error(resource, |
| 3746 | WL_SURFACE_ERROR_INVALID_SCALE, |
| 3747 | "buffer scale must be at least one " |
| 3748 | "('%d' specified)", scale); |
| 3749 | return; |
| 3750 | } |
| 3751 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 3752 | surface->pending.buffer_viewport.buffer.scale = scale; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3753 | surface->pending.buffer_viewport.changed = 1; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3754 | } |
| 3755 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 3756 | static const struct wl_surface_interface surface_interface = { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3757 | surface_destroy, |
| 3758 | surface_attach, |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3759 | surface_damage, |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3760 | surface_frame, |
| 3761 | surface_set_opaque_region, |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3762 | surface_set_input_region, |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3763 | surface_commit, |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3764 | surface_set_buffer_transform, |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3765 | surface_set_buffer_scale, |
| 3766 | surface_damage_buffer |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3767 | }; |
| 3768 | |
| 3769 | static void |
| 3770 | compositor_create_surface(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 3771 | struct wl_resource *resource, uint32_t id) |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3772 | { |
Kristian Høgsberg | c2d7042 | 2013-06-25 15:34:33 -0400 | [diff] [blame] | 3773 | struct weston_compositor *ec = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3774 | struct weston_surface *surface; |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3775 | |
Kristian Høgsberg | 18c9300 | 2012-01-27 11:58:31 -0500 | [diff] [blame] | 3776 | surface = weston_surface_create(ec); |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 3777 | if (surface == NULL) { |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 3778 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3779 | return; |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 3780 | } |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3781 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3782 | surface->resource = |
| 3783 | wl_resource_create(client, &wl_surface_interface, |
| 3784 | wl_resource_get_version(resource), id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 3785 | if (surface->resource == NULL) { |
| 3786 | weston_surface_destroy(surface); |
| 3787 | wl_resource_post_no_memory(resource); |
| 3788 | return; |
| 3789 | } |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3790 | wl_resource_set_implementation(surface->resource, &surface_interface, |
| 3791 | surface, destroy_surface); |
Kristian Høgsberg | f03a04a | 2014-04-06 22:04:50 -0700 | [diff] [blame] | 3792 | |
| 3793 | wl_signal_emit(&ec->create_surface_signal, surface); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3794 | } |
| 3795 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3796 | static void |
| 3797 | destroy_region(struct wl_resource *resource) |
| 3798 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 3799 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3800 | |
| 3801 | pixman_region32_fini(®ion->region); |
| 3802 | free(region); |
| 3803 | } |
| 3804 | |
| 3805 | static void |
| 3806 | region_destroy(struct wl_client *client, struct wl_resource *resource) |
| 3807 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3808 | wl_resource_destroy(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3809 | } |
| 3810 | |
| 3811 | static void |
| 3812 | region_add(struct wl_client *client, struct wl_resource *resource, |
| 3813 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 3814 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 3815 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3816 | |
| 3817 | pixman_region32_union_rect(®ion->region, ®ion->region, |
| 3818 | x, y, width, height); |
| 3819 | } |
| 3820 | |
| 3821 | static void |
| 3822 | region_subtract(struct wl_client *client, struct wl_resource *resource, |
| 3823 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 3824 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 3825 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3826 | pixman_region32_t rect; |
| 3827 | |
| 3828 | pixman_region32_init_rect(&rect, x, y, width, height); |
| 3829 | pixman_region32_subtract(®ion->region, ®ion->region, &rect); |
| 3830 | pixman_region32_fini(&rect); |
| 3831 | } |
| 3832 | |
| 3833 | static const struct wl_region_interface region_interface = { |
| 3834 | region_destroy, |
| 3835 | region_add, |
| 3836 | region_subtract |
| 3837 | }; |
| 3838 | |
| 3839 | static void |
| 3840 | compositor_create_region(struct wl_client *client, |
| 3841 | struct wl_resource *resource, uint32_t id) |
| 3842 | { |
| 3843 | struct weston_region *region; |
| 3844 | |
| 3845 | region = malloc(sizeof *region); |
| 3846 | if (region == NULL) { |
| 3847 | wl_resource_post_no_memory(resource); |
| 3848 | return; |
| 3849 | } |
| 3850 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3851 | pixman_region32_init(®ion->region); |
| 3852 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3853 | region->resource = |
| 3854 | wl_resource_create(client, &wl_region_interface, 1, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 3855 | if (region->resource == NULL) { |
| 3856 | free(region); |
| 3857 | wl_resource_post_no_memory(resource); |
| 3858 | return; |
| 3859 | } |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3860 | wl_resource_set_implementation(region->resource, ®ion_interface, |
| 3861 | region, destroy_region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3862 | } |
| 3863 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 3864 | static const struct wl_compositor_interface compositor_interface = { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3865 | compositor_create_surface, |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3866 | compositor_create_region |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3867 | }; |
| 3868 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3869 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3870 | weston_subsurface_commit_from_cache(struct weston_subsurface *sub) |
| 3871 | { |
| 3872 | struct weston_surface *surface = sub->surface; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3873 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3874 | weston_surface_commit_state(surface, &sub->cached); |
| 3875 | weston_buffer_reference(&sub->cached_buffer_ref, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3876 | |
| 3877 | weston_surface_commit_subsurface_order(surface); |
| 3878 | |
| 3879 | weston_surface_schedule_repaint(surface); |
| 3880 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3881 | sub->has_cached_data = 0; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3882 | } |
| 3883 | |
| 3884 | static void |
| 3885 | weston_subsurface_commit_to_cache(struct weston_subsurface *sub) |
| 3886 | { |
| 3887 | struct weston_surface *surface = sub->surface; |
| 3888 | |
| 3889 | /* |
| 3890 | * If this commit would cause the surface to move by the |
| 3891 | * attach(dx, dy) parameters, the old damage region must be |
| 3892 | * translated to correspond to the new surface coordinate system |
Chris Michael | 062edf2 | 2015-11-26 11:30:00 -0500 | [diff] [blame] | 3893 | * origin. |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3894 | */ |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3895 | pixman_region32_translate(&sub->cached.damage_surface, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3896 | -surface->pending.sx, -surface->pending.sy); |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3897 | pixman_region32_union(&sub->cached.damage_surface, |
| 3898 | &sub->cached.damage_surface, |
| 3899 | &surface->pending.damage_surface); |
| 3900 | pixman_region32_clear(&surface->pending.damage_surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3901 | |
| 3902 | if (surface->pending.newly_attached) { |
| 3903 | sub->cached.newly_attached = 1; |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3904 | weston_surface_state_set_buffer(&sub->cached, |
| 3905 | surface->pending.buffer); |
| 3906 | weston_buffer_reference(&sub->cached_buffer_ref, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3907 | surface->pending.buffer); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3908 | weston_presentation_feedback_discard_list( |
| 3909 | &sub->cached.feedback_list); |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3910 | /* zwp_surface_synchronization_v1.set_acquire_fence */ |
| 3911 | fd_move(&sub->cached.acquire_fence_fd, |
| 3912 | &surface->pending.acquire_fence_fd); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3913 | /* zwp_surface_synchronization_v1.get_release */ |
| 3914 | weston_buffer_release_move(&sub->cached.buffer_release_ref, |
| 3915 | &surface->pending.buffer_release_ref); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3916 | } |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 3917 | sub->cached.desired_protection = surface->pending.desired_protection; |
Ankit Nautiyal | 5cfe03c | 2019-03-28 15:05:42 +0530 | [diff] [blame] | 3918 | sub->cached.protection_mode = surface->pending.protection_mode; |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3919 | assert(surface->pending.acquire_fence_fd == -1); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3920 | assert(surface->pending.buffer_release_ref.buffer_release == NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3921 | sub->cached.sx += surface->pending.sx; |
| 3922 | sub->cached.sy += surface->pending.sy; |
Pekka Paalanen | 260ba38 | 2014-03-14 14:38:12 +0200 | [diff] [blame] | 3923 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3924 | apply_damage_buffer(&sub->cached.damage_surface, surface, &surface->pending); |
| 3925 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3926 | sub->cached.buffer_viewport.changed |= |
| 3927 | surface->pending.buffer_viewport.changed; |
| 3928 | sub->cached.buffer_viewport.buffer = |
| 3929 | surface->pending.buffer_viewport.buffer; |
| 3930 | sub->cached.buffer_viewport.surface = |
| 3931 | surface->pending.buffer_viewport.surface; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3932 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3933 | weston_surface_reset_pending_buffer(surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3934 | |
| 3935 | pixman_region32_copy(&sub->cached.opaque, &surface->pending.opaque); |
| 3936 | |
| 3937 | pixman_region32_copy(&sub->cached.input, &surface->pending.input); |
| 3938 | |
| 3939 | wl_list_insert_list(&sub->cached.frame_callback_list, |
| 3940 | &surface->pending.frame_callback_list); |
| 3941 | wl_list_init(&surface->pending.frame_callback_list); |
| 3942 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3943 | wl_list_insert_list(&sub->cached.feedback_list, |
| 3944 | &surface->pending.feedback_list); |
| 3945 | wl_list_init(&surface->pending.feedback_list); |
| 3946 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3947 | sub->has_cached_data = 1; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3948 | } |
| 3949 | |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 3950 | static bool |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3951 | weston_subsurface_is_synchronized(struct weston_subsurface *sub) |
| 3952 | { |
| 3953 | while (sub) { |
| 3954 | if (sub->synchronized) |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 3955 | return true; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3956 | |
| 3957 | if (!sub->parent) |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 3958 | return false; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3959 | |
| 3960 | sub = weston_surface_to_subsurface(sub->parent); |
| 3961 | } |
| 3962 | |
Carlos Olmedo Escobar | 61a9bf5 | 2014-11-04 14:38:39 +0100 | [diff] [blame] | 3963 | return false; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3964 | } |
| 3965 | |
| 3966 | static void |
| 3967 | weston_subsurface_commit(struct weston_subsurface *sub) |
| 3968 | { |
| 3969 | struct weston_surface *surface = sub->surface; |
| 3970 | struct weston_subsurface *tmp; |
| 3971 | |
| 3972 | /* Recursive check for effectively synchronized. */ |
| 3973 | if (weston_subsurface_is_synchronized(sub)) { |
| 3974 | weston_subsurface_commit_to_cache(sub); |
| 3975 | } else { |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3976 | if (sub->has_cached_data) { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3977 | /* flush accumulated state from cache */ |
| 3978 | weston_subsurface_commit_to_cache(sub); |
| 3979 | weston_subsurface_commit_from_cache(sub); |
| 3980 | } else { |
| 3981 | weston_surface_commit(surface); |
| 3982 | } |
| 3983 | |
| 3984 | wl_list_for_each(tmp, &surface->subsurface_list, parent_link) { |
| 3985 | if (tmp->surface != surface) |
| 3986 | weston_subsurface_parent_commit(tmp, 0); |
| 3987 | } |
| 3988 | } |
| 3989 | } |
| 3990 | |
| 3991 | static void |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3992 | weston_subsurface_synchronized_commit(struct weston_subsurface *sub) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3993 | { |
| 3994 | struct weston_surface *surface = sub->surface; |
| 3995 | struct weston_subsurface *tmp; |
| 3996 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3997 | /* From now on, commit_from_cache the whole sub-tree, regardless of |
| 3998 | * the synchronized mode of each child. This sub-surface or some |
| 3999 | * of its ancestors were synchronized, so we are synchronized |
| 4000 | * all the way down. |
| 4001 | */ |
| 4002 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 4003 | if (sub->has_cached_data) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4004 | weston_subsurface_commit_from_cache(sub); |
| 4005 | |
| 4006 | wl_list_for_each(tmp, &surface->subsurface_list, parent_link) { |
| 4007 | if (tmp->surface != surface) |
| 4008 | weston_subsurface_parent_commit(tmp, 1); |
| 4009 | } |
| 4010 | } |
| 4011 | |
| 4012 | static void |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 4013 | weston_subsurface_parent_commit(struct weston_subsurface *sub, |
| 4014 | int parent_is_synchronized) |
| 4015 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4016 | struct weston_view *view; |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 4017 | if (sub->position.set) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4018 | wl_list_for_each(view, &sub->surface->views, surface_link) |
| 4019 | weston_view_set_position(view, |
| 4020 | sub->position.x, |
| 4021 | sub->position.y); |
| 4022 | |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 4023 | sub->position.set = 0; |
| 4024 | } |
| 4025 | |
| 4026 | if (parent_is_synchronized || sub->synchronized) |
| 4027 | weston_subsurface_synchronized_commit(sub); |
| 4028 | } |
| 4029 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4030 | static int |
| 4031 | subsurface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4032 | { |
| 4033 | return snprintf(buf, len, "sub-surface"); |
| 4034 | } |
| 4035 | |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 4036 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 4037 | subsurface_committed(struct weston_surface *surface, int32_t dx, int32_t dy) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4038 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4039 | struct weston_view *view; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4040 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4041 | wl_list_for_each(view, &surface->views, surface_link) |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4042 | weston_view_set_position(view, |
| 4043 | view->geometry.x + dx, |
| 4044 | view->geometry.y + dy); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4045 | |
| 4046 | /* No need to check parent mappedness, because if parent is not |
| 4047 | * mapped, parent is not in a visible layer, so this sub-surface |
| 4048 | * will not be drawn either. |
| 4049 | */ |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 4050 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4051 | if (!weston_surface_is_mapped(surface)) { |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 4052 | surface->is_mapped = true; |
Pekka Paalanen | eb3cf22 | 2014-06-30 11:52:07 +0300 | [diff] [blame] | 4053 | |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 4054 | /* Cannot call weston_view_update_transform(), |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4055 | * because that would call it also for the parent surface, |
| 4056 | * which might not be mapped yet. That would lead to |
| 4057 | * inconsistent state, where the window could never be |
| 4058 | * mapped. |
| 4059 | * |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 4060 | * Instead just force the is_mapped flag on, to make |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4061 | * weston_surface_is_mapped() return true, so that when the |
| 4062 | * parent surface does get mapped, this one will get |
Pekka Paalanen | eb3cf22 | 2014-06-30 11:52:07 +0300 | [diff] [blame] | 4063 | * included, too. See view_list_add(). |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4064 | */ |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4065 | } |
| 4066 | } |
| 4067 | |
| 4068 | static struct weston_subsurface * |
| 4069 | weston_surface_to_subsurface(struct weston_surface *surface) |
| 4070 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 4071 | if (surface->committed == subsurface_committed) |
| 4072 | return surface->committed_private; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4073 | |
| 4074 | return NULL; |
| 4075 | } |
| 4076 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4077 | WL_EXPORT struct weston_surface * |
| 4078 | weston_surface_get_main_surface(struct weston_surface *surface) |
| 4079 | { |
| 4080 | struct weston_subsurface *sub; |
| 4081 | |
| 4082 | while (surface && (sub = weston_surface_to_subsurface(surface))) |
| 4083 | surface = sub->parent; |
| 4084 | |
| 4085 | return surface; |
| 4086 | } |
| 4087 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4088 | WL_EXPORT int |
| 4089 | weston_surface_set_role(struct weston_surface *surface, |
| 4090 | const char *role_name, |
| 4091 | struct wl_resource *error_resource, |
| 4092 | uint32_t error_code) |
| 4093 | { |
| 4094 | assert(role_name); |
| 4095 | |
| 4096 | if (surface->role_name == NULL || |
| 4097 | surface->role_name == role_name || |
| 4098 | strcmp(surface->role_name, role_name) == 0) { |
| 4099 | surface->role_name = role_name; |
| 4100 | |
| 4101 | return 0; |
| 4102 | } |
| 4103 | |
| 4104 | wl_resource_post_error(error_resource, error_code, |
| 4105 | "Cannot assign role %s to wl_surface@%d," |
| 4106 | " already has role %s\n", |
| 4107 | role_name, |
| 4108 | wl_resource_get_id(surface->resource), |
| 4109 | surface->role_name); |
| 4110 | return -1; |
| 4111 | } |
| 4112 | |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 4113 | WL_EXPORT const char * |
| 4114 | weston_surface_get_role(struct weston_surface *surface) |
| 4115 | { |
| 4116 | return surface->role_name; |
| 4117 | } |
| 4118 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4119 | WL_EXPORT void |
| 4120 | weston_surface_set_label_func(struct weston_surface *surface, |
| 4121 | int (*desc)(struct weston_surface *, |
| 4122 | char *, size_t)) |
| 4123 | { |
| 4124 | surface->get_label = desc; |
Marius Vlad | 5de9297 | 2019-10-15 13:25:41 +0300 | [diff] [blame] | 4125 | weston_timeline_refresh_subscription_objects(surface->compositor, |
| 4126 | surface); |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4127 | } |
| 4128 | |
Pekka Paalanen | c647ed7 | 2015-02-09 13:16:57 +0200 | [diff] [blame] | 4129 | /** Get the size of surface contents |
| 4130 | * |
| 4131 | * \param surface The surface to query. |
| 4132 | * \param width Returns the width of raw contents. |
| 4133 | * \param height Returns the height of raw contents. |
| 4134 | * |
| 4135 | * Retrieves the raw surface content size in pixels for the given surface. |
| 4136 | * This is the whole content size in buffer pixels. If the surface |
| 4137 | * has no content or the renderer does not implement this feature, |
| 4138 | * zeroes are returned. |
| 4139 | * |
| 4140 | * This function is used to determine the buffer size needed for |
| 4141 | * a weston_surface_copy_content() call. |
| 4142 | */ |
| 4143 | WL_EXPORT void |
| 4144 | weston_surface_get_content_size(struct weston_surface *surface, |
| 4145 | int *width, int *height) |
| 4146 | { |
| 4147 | struct weston_renderer *rer = surface->compositor->renderer; |
| 4148 | |
| 4149 | if (!rer->surface_get_content_size) { |
| 4150 | *width = 0; |
| 4151 | *height = 0; |
| 4152 | return; |
| 4153 | } |
| 4154 | |
| 4155 | rer->surface_get_content_size(surface, width, height); |
| 4156 | } |
| 4157 | |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 4158 | /** Get the bounding box of a surface and its subsurfaces |
| 4159 | * |
| 4160 | * \param surface The surface to query. |
| 4161 | * \return The bounding box relative to the surface origin. |
| 4162 | * |
| 4163 | */ |
| 4164 | WL_EXPORT struct weston_geometry |
| 4165 | weston_surface_get_bounding_box(struct weston_surface *surface) |
| 4166 | { |
| 4167 | pixman_region32_t region; |
| 4168 | pixman_box32_t *box; |
| 4169 | struct weston_subsurface *subsurface; |
| 4170 | |
| 4171 | pixman_region32_init_rect(®ion, |
| 4172 | 0, 0, |
| 4173 | surface->width, surface->height); |
| 4174 | |
| 4175 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) |
| 4176 | pixman_region32_union_rect(®ion, ®ion, |
| 4177 | subsurface->position.x, |
| 4178 | subsurface->position.y, |
| 4179 | subsurface->surface->width, |
| 4180 | subsurface->surface->height); |
| 4181 | |
| 4182 | box = pixman_region32_extents(®ion); |
| 4183 | struct weston_geometry geometry = { |
| 4184 | .x = box->x1, |
| 4185 | .y = box->y1, |
| 4186 | .width = box->x2 - box->x1, |
| 4187 | .height = box->y2 - box->y1, |
| 4188 | }; |
| 4189 | |
| 4190 | pixman_region32_fini(®ion); |
| 4191 | |
| 4192 | return geometry; |
| 4193 | } |
| 4194 | |
Pekka Paalanen | c647ed7 | 2015-02-09 13:16:57 +0200 | [diff] [blame] | 4195 | /** Copy surface contents to system memory. |
| 4196 | * |
| 4197 | * \param surface The surface to copy from. |
| 4198 | * \param target Pointer to the target memory buffer. |
| 4199 | * \param size Size of the target buffer in bytes. |
| 4200 | * \param src_x X location on contents to copy from. |
| 4201 | * \param src_y Y location on contents to copy from. |
| 4202 | * \param width Width in pixels of the area to copy. |
| 4203 | * \param height Height in pixels of the area to copy. |
| 4204 | * \return 0 for success, -1 for failure. |
| 4205 | * |
| 4206 | * Surface contents are maintained by the renderer. They can be in a |
| 4207 | * reserved weston_buffer or as a copy, e.g. a GL texture, or something |
| 4208 | * else. |
| 4209 | * |
| 4210 | * Surface contents are copied into memory pointed to by target, |
| 4211 | * which has size bytes of space available. The target memory |
| 4212 | * may be larger than needed, but being smaller returns an error. |
| 4213 | * The extra bytes in target may or may not be written; their content is |
| 4214 | * unspecified. Size must be large enough to hold the image. |
| 4215 | * |
| 4216 | * The image in the target memory will be arranged in rows from |
| 4217 | * top to bottom, and pixels on a row from left to right. The pixel |
| 4218 | * format is PIXMAN_a8b8g8r8, 4 bytes per pixel, and stride is exactly |
| 4219 | * width * 4. |
| 4220 | * |
| 4221 | * Parameters src_x and src_y define the upper-left corner in buffer |
| 4222 | * coordinates (pixels) to copy from. Parameters width and height |
| 4223 | * define the size of the area to copy in pixels. |
| 4224 | * |
| 4225 | * The rectangle defined by src_x, src_y, width, height must fit in |
| 4226 | * the surface contents. Otherwise an error is returned. |
| 4227 | * |
Changwoo Cho | f97d250 | 2017-08-05 00:30:47 +0900 | [diff] [blame] | 4228 | * Use weston_surface_get_content_size to determine the content size; the |
Pekka Paalanen | c647ed7 | 2015-02-09 13:16:57 +0200 | [diff] [blame] | 4229 | * needed target buffer size and rectangle limits. |
| 4230 | * |
| 4231 | * CURRENT IMPLEMENTATION RESTRICTIONS: |
| 4232 | * - the machine must be little-endian due to Pixman formats. |
| 4233 | * |
| 4234 | * NOTE: Pixman formats are premultiplied. |
| 4235 | */ |
| 4236 | WL_EXPORT int |
| 4237 | weston_surface_copy_content(struct weston_surface *surface, |
| 4238 | void *target, size_t size, |
| 4239 | int src_x, int src_y, |
| 4240 | int width, int height) |
| 4241 | { |
| 4242 | struct weston_renderer *rer = surface->compositor->renderer; |
| 4243 | int cw, ch; |
| 4244 | const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */ |
| 4245 | |
| 4246 | if (!rer->surface_copy_content) |
| 4247 | return -1; |
| 4248 | |
| 4249 | weston_surface_get_content_size(surface, &cw, &ch); |
| 4250 | |
| 4251 | if (src_x < 0 || src_y < 0) |
| 4252 | return -1; |
| 4253 | |
| 4254 | if (width <= 0 || height <= 0) |
| 4255 | return -1; |
| 4256 | |
| 4257 | if (src_x + width > cw || src_y + height > ch) |
| 4258 | return -1; |
| 4259 | |
| 4260 | if (width * bytespp * height > size) |
| 4261 | return -1; |
| 4262 | |
| 4263 | return rer->surface_copy_content(surface, target, size, |
| 4264 | src_x, src_y, width, height); |
| 4265 | } |
| 4266 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4267 | static void |
| 4268 | subsurface_set_position(struct wl_client *client, |
| 4269 | struct wl_resource *resource, int32_t x, int32_t y) |
| 4270 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4271 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4272 | |
| 4273 | if (!sub) |
| 4274 | return; |
| 4275 | |
| 4276 | sub->position.x = x; |
| 4277 | sub->position.y = y; |
| 4278 | sub->position.set = 1; |
| 4279 | } |
| 4280 | |
| 4281 | static struct weston_subsurface * |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 4282 | subsurface_find_sibling(struct weston_subsurface *sub, |
| 4283 | struct weston_surface *surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4284 | { |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 4285 | struct weston_surface *parent = sub->parent; |
| 4286 | struct weston_subsurface *sibling; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4287 | |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 4288 | wl_list_for_each(sibling, &parent->subsurface_list, parent_link) { |
| 4289 | if (sibling->surface == surface && sibling != sub) |
| 4290 | return sibling; |
| 4291 | } |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4292 | |
| 4293 | return NULL; |
| 4294 | } |
| 4295 | |
| 4296 | static struct weston_subsurface * |
| 4297 | subsurface_sibling_check(struct weston_subsurface *sub, |
| 4298 | struct weston_surface *surface, |
| 4299 | const char *request) |
| 4300 | { |
| 4301 | struct weston_subsurface *sibling; |
| 4302 | |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 4303 | sibling = subsurface_find_sibling(sub, surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4304 | if (!sibling) { |
| 4305 | wl_resource_post_error(sub->resource, |
| 4306 | WL_SUBSURFACE_ERROR_BAD_SURFACE, |
| 4307 | "%s: wl_surface@%d is not a parent or sibling", |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4308 | request, wl_resource_get_id(surface->resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4309 | return NULL; |
| 4310 | } |
| 4311 | |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 4312 | assert(sibling->parent == sub->parent); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4313 | |
| 4314 | return sibling; |
| 4315 | } |
| 4316 | |
| 4317 | static void |
| 4318 | subsurface_place_above(struct wl_client *client, |
| 4319 | struct wl_resource *resource, |
| 4320 | struct wl_resource *sibling_resource) |
| 4321 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4322 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4323 | struct weston_surface *surface = |
| 4324 | wl_resource_get_user_data(sibling_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4325 | struct weston_subsurface *sibling; |
| 4326 | |
| 4327 | if (!sub) |
| 4328 | return; |
| 4329 | |
| 4330 | sibling = subsurface_sibling_check(sub, surface, "place_above"); |
| 4331 | if (!sibling) |
| 4332 | return; |
| 4333 | |
| 4334 | wl_list_remove(&sub->parent_link_pending); |
| 4335 | wl_list_insert(sibling->parent_link_pending.prev, |
| 4336 | &sub->parent_link_pending); |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 4337 | |
| 4338 | sub->reordered = true; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4339 | } |
| 4340 | |
| 4341 | static void |
| 4342 | subsurface_place_below(struct wl_client *client, |
| 4343 | struct wl_resource *resource, |
| 4344 | struct wl_resource *sibling_resource) |
| 4345 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4346 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4347 | struct weston_surface *surface = |
| 4348 | wl_resource_get_user_data(sibling_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4349 | struct weston_subsurface *sibling; |
| 4350 | |
| 4351 | if (!sub) |
| 4352 | return; |
| 4353 | |
| 4354 | sibling = subsurface_sibling_check(sub, surface, "place_below"); |
| 4355 | if (!sibling) |
| 4356 | return; |
| 4357 | |
| 4358 | wl_list_remove(&sub->parent_link_pending); |
| 4359 | wl_list_insert(&sibling->parent_link_pending, |
| 4360 | &sub->parent_link_pending); |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 4361 | |
| 4362 | sub->reordered = true; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4363 | } |
| 4364 | |
| 4365 | static void |
| 4366 | subsurface_set_sync(struct wl_client *client, struct wl_resource *resource) |
| 4367 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4368 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4369 | |
| 4370 | if (sub) |
| 4371 | sub->synchronized = 1; |
| 4372 | } |
| 4373 | |
| 4374 | static void |
| 4375 | subsurface_set_desync(struct wl_client *client, struct wl_resource *resource) |
| 4376 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4377 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4378 | |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 4379 | if (sub && sub->synchronized) { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4380 | sub->synchronized = 0; |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 4381 | |
| 4382 | /* If sub became effectively desynchronized, flush. */ |
| 4383 | if (!weston_subsurface_is_synchronized(sub)) |
| 4384 | weston_subsurface_synchronized_commit(sub); |
| 4385 | } |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4386 | } |
| 4387 | |
| 4388 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4389 | weston_subsurface_unlink_parent(struct weston_subsurface *sub) |
| 4390 | { |
| 4391 | wl_list_remove(&sub->parent_link); |
| 4392 | wl_list_remove(&sub->parent_link_pending); |
| 4393 | wl_list_remove(&sub->parent_destroy_listener.link); |
| 4394 | sub->parent = NULL; |
| 4395 | } |
| 4396 | |
| 4397 | static void |
| 4398 | weston_subsurface_destroy(struct weston_subsurface *sub); |
| 4399 | |
| 4400 | static void |
| 4401 | subsurface_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 4402 | { |
| 4403 | struct weston_subsurface *sub = |
| 4404 | container_of(listener, struct weston_subsurface, |
| 4405 | surface_destroy_listener); |
Pekka Paalanen | ca79076 | 2015-04-17 14:23:38 +0300 | [diff] [blame] | 4406 | assert(data == sub->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4407 | |
| 4408 | /* The protocol object (wl_resource) is left inert. */ |
| 4409 | if (sub->resource) |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4410 | wl_resource_set_user_data(sub->resource, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4411 | |
| 4412 | weston_subsurface_destroy(sub); |
| 4413 | } |
| 4414 | |
| 4415 | static void |
| 4416 | subsurface_handle_parent_destroy(struct wl_listener *listener, void *data) |
| 4417 | { |
| 4418 | struct weston_subsurface *sub = |
| 4419 | container_of(listener, struct weston_subsurface, |
| 4420 | parent_destroy_listener); |
Pekka Paalanen | ca79076 | 2015-04-17 14:23:38 +0300 | [diff] [blame] | 4421 | assert(data == sub->parent); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4422 | assert(sub->surface != sub->parent); |
| 4423 | |
| 4424 | if (weston_surface_is_mapped(sub->surface)) |
| 4425 | weston_surface_unmap(sub->surface); |
| 4426 | |
| 4427 | weston_subsurface_unlink_parent(sub); |
| 4428 | } |
| 4429 | |
| 4430 | static void |
| 4431 | subsurface_resource_destroy(struct wl_resource *resource) |
| 4432 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4433 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4434 | |
| 4435 | if (sub) |
| 4436 | weston_subsurface_destroy(sub); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4437 | } |
| 4438 | |
| 4439 | static void |
| 4440 | subsurface_destroy(struct wl_client *client, struct wl_resource *resource) |
| 4441 | { |
| 4442 | wl_resource_destroy(resource); |
| 4443 | } |
| 4444 | |
| 4445 | static void |
| 4446 | weston_subsurface_link_parent(struct weston_subsurface *sub, |
| 4447 | struct weston_surface *parent) |
| 4448 | { |
| 4449 | sub->parent = parent; |
| 4450 | sub->parent_destroy_listener.notify = subsurface_handle_parent_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4451 | wl_signal_add(&parent->destroy_signal, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4452 | &sub->parent_destroy_listener); |
| 4453 | |
| 4454 | wl_list_insert(&parent->subsurface_list, &sub->parent_link); |
| 4455 | wl_list_insert(&parent->subsurface_list_pending, |
| 4456 | &sub->parent_link_pending); |
| 4457 | } |
| 4458 | |
| 4459 | static void |
| 4460 | weston_subsurface_link_surface(struct weston_subsurface *sub, |
| 4461 | struct weston_surface *surface) |
| 4462 | { |
| 4463 | sub->surface = surface; |
| 4464 | sub->surface_destroy_listener.notify = |
| 4465 | subsurface_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4466 | wl_signal_add(&surface->destroy_signal, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4467 | &sub->surface_destroy_listener); |
| 4468 | } |
| 4469 | |
| 4470 | static void |
| 4471 | weston_subsurface_destroy(struct weston_subsurface *sub) |
| 4472 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4473 | struct weston_view *view, *next; |
| 4474 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4475 | assert(sub->surface); |
| 4476 | |
| 4477 | if (sub->resource) { |
| 4478 | assert(weston_surface_to_subsurface(sub->surface) == sub); |
| 4479 | assert(sub->parent_destroy_listener.notify == |
| 4480 | subsurface_handle_parent_destroy); |
| 4481 | |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 4482 | wl_list_for_each_safe(view, next, &sub->surface->views, surface_link) { |
| 4483 | weston_view_unmap(view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4484 | weston_view_destroy(view); |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 4485 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4486 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4487 | if (sub->parent) |
| 4488 | weston_subsurface_unlink_parent(sub); |
| 4489 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 4490 | weston_surface_state_fini(&sub->cached); |
| 4491 | weston_buffer_reference(&sub->cached_buffer_ref, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4492 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 4493 | sub->surface->committed = NULL; |
| 4494 | sub->surface->committed_private = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4495 | weston_surface_set_label_func(sub->surface, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4496 | } else { |
| 4497 | /* the dummy weston_subsurface for the parent itself */ |
| 4498 | assert(sub->parent_destroy_listener.notify == NULL); |
| 4499 | wl_list_remove(&sub->parent_link); |
| 4500 | wl_list_remove(&sub->parent_link_pending); |
| 4501 | } |
| 4502 | |
| 4503 | wl_list_remove(&sub->surface_destroy_listener.link); |
| 4504 | free(sub); |
| 4505 | } |
| 4506 | |
| 4507 | static const struct wl_subsurface_interface subsurface_implementation = { |
| 4508 | subsurface_destroy, |
| 4509 | subsurface_set_position, |
| 4510 | subsurface_place_above, |
| 4511 | subsurface_place_below, |
| 4512 | subsurface_set_sync, |
| 4513 | subsurface_set_desync |
| 4514 | }; |
| 4515 | |
| 4516 | static struct weston_subsurface * |
| 4517 | weston_subsurface_create(uint32_t id, struct weston_surface *surface, |
| 4518 | struct weston_surface *parent) |
| 4519 | { |
| 4520 | struct weston_subsurface *sub; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4521 | struct wl_client *client = wl_resource_get_client(surface->resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4522 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 4523 | sub = zalloc(sizeof *sub); |
| 4524 | if (sub == NULL) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4525 | return NULL; |
| 4526 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4527 | wl_list_init(&sub->unused_views); |
| 4528 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4529 | sub->resource = |
| 4530 | wl_resource_create(client, &wl_subsurface_interface, 1, id); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4531 | if (!sub->resource) { |
| 4532 | free(sub); |
| 4533 | return NULL; |
| 4534 | } |
| 4535 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4536 | wl_resource_set_implementation(sub->resource, |
| 4537 | &subsurface_implementation, |
| 4538 | sub, subsurface_resource_destroy); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4539 | weston_subsurface_link_surface(sub, surface); |
| 4540 | weston_subsurface_link_parent(sub, parent); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 4541 | weston_surface_state_init(&sub->cached); |
| 4542 | sub->cached_buffer_ref.buffer = NULL; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4543 | sub->synchronized = 1; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4544 | |
| 4545 | return sub; |
| 4546 | } |
| 4547 | |
| 4548 | /* Create a dummy subsurface for having the parent itself in its |
| 4549 | * sub-surface lists. Makes stacking order manipulation easy. |
| 4550 | */ |
| 4551 | static struct weston_subsurface * |
| 4552 | weston_subsurface_create_for_parent(struct weston_surface *parent) |
| 4553 | { |
| 4554 | struct weston_subsurface *sub; |
| 4555 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 4556 | sub = zalloc(sizeof *sub); |
| 4557 | if (sub == NULL) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4558 | return NULL; |
| 4559 | |
| 4560 | weston_subsurface_link_surface(sub, parent); |
| 4561 | sub->parent = parent; |
| 4562 | wl_list_insert(&parent->subsurface_list, &sub->parent_link); |
| 4563 | wl_list_insert(&parent->subsurface_list_pending, |
| 4564 | &sub->parent_link_pending); |
| 4565 | |
| 4566 | return sub; |
| 4567 | } |
| 4568 | |
| 4569 | static void |
| 4570 | subcompositor_get_subsurface(struct wl_client *client, |
| 4571 | struct wl_resource *resource, |
| 4572 | uint32_t id, |
| 4573 | struct wl_resource *surface_resource, |
| 4574 | struct wl_resource *parent_resource) |
| 4575 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4576 | struct weston_surface *surface = |
| 4577 | wl_resource_get_user_data(surface_resource); |
| 4578 | struct weston_surface *parent = |
| 4579 | wl_resource_get_user_data(parent_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4580 | struct weston_subsurface *sub; |
| 4581 | static const char where[] = "get_subsurface: wl_subsurface@"; |
| 4582 | |
| 4583 | if (surface == parent) { |
| 4584 | wl_resource_post_error(resource, |
| 4585 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 4586 | "%s%d: wl_surface@%d cannot be its own parent", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4587 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4588 | return; |
| 4589 | } |
| 4590 | |
| 4591 | if (weston_surface_to_subsurface(surface)) { |
| 4592 | wl_resource_post_error(resource, |
| 4593 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 4594 | "%s%d: wl_surface@%d is already a sub-surface", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4595 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4596 | return; |
| 4597 | } |
| 4598 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4599 | if (weston_surface_set_role(surface, "wl_subsurface", resource, |
| 4600 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE) < 0) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4601 | return; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4602 | |
Pekka Paalanen | 86c8ca0 | 2013-05-17 16:46:07 +0300 | [diff] [blame] | 4603 | if (weston_surface_get_main_surface(parent) == surface) { |
| 4604 | wl_resource_post_error(resource, |
| 4605 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 4606 | "%s%d: wl_surface@%d is an ancestor of parent", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4607 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | 86c8ca0 | 2013-05-17 16:46:07 +0300 | [diff] [blame] | 4608 | return; |
| 4609 | } |
| 4610 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4611 | /* make sure the parent is in its own list */ |
| 4612 | if (wl_list_empty(&parent->subsurface_list)) { |
| 4613 | if (!weston_subsurface_create_for_parent(parent)) { |
| 4614 | wl_resource_post_no_memory(resource); |
| 4615 | return; |
| 4616 | } |
| 4617 | } |
| 4618 | |
| 4619 | sub = weston_subsurface_create(id, surface, parent); |
| 4620 | if (!sub) { |
| 4621 | wl_resource_post_no_memory(resource); |
| 4622 | return; |
| 4623 | } |
| 4624 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 4625 | surface->committed = subsurface_committed; |
| 4626 | surface->committed_private = sub; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4627 | weston_surface_set_label_func(surface, subsurface_get_label); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4628 | } |
| 4629 | |
| 4630 | static void |
| 4631 | subcompositor_destroy(struct wl_client *client, struct wl_resource *resource) |
| 4632 | { |
| 4633 | wl_resource_destroy(resource); |
| 4634 | } |
| 4635 | |
| 4636 | static const struct wl_subcompositor_interface subcompositor_interface = { |
| 4637 | subcompositor_destroy, |
| 4638 | subcompositor_get_subsurface |
| 4639 | }; |
| 4640 | |
| 4641 | static void |
| 4642 | bind_subcompositor(struct wl_client *client, |
| 4643 | void *data, uint32_t version, uint32_t id) |
| 4644 | { |
| 4645 | struct weston_compositor *compositor = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4646 | struct wl_resource *resource; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4647 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4648 | resource = |
| 4649 | wl_resource_create(client, &wl_subcompositor_interface, 1, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 4650 | if (resource == NULL) { |
| 4651 | wl_client_post_no_memory(client); |
| 4652 | return; |
| 4653 | } |
| 4654 | wl_resource_set_implementation(resource, &subcompositor_interface, |
| 4655 | compositor, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4656 | } |
| 4657 | |
Bryce Harrington | 0795ece | 2016-08-30 12:04:26 -0700 | [diff] [blame] | 4658 | /** Set a DPMS mode on all of the compositor's outputs |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4659 | * |
| 4660 | * \param compositor The compositor instance |
| 4661 | * \param state The DPMS state the outputs will be set to |
| 4662 | */ |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4663 | static void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4664 | weston_compositor_dpms(struct weston_compositor *compositor, |
| 4665 | enum dpms_enum state) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4666 | { |
| 4667 | struct weston_output *output; |
| 4668 | |
Bryce Harrington | 08976ac | 2016-08-30 12:05:16 -0700 | [diff] [blame] | 4669 | wl_list_for_each(output, &compositor->output_list, link) |
| 4670 | if (output->set_dpms) |
| 4671 | output->set_dpms(output, state); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4672 | } |
| 4673 | |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4674 | /** Restores the compositor to active status |
| 4675 | * |
| 4676 | * \param compositor The compositor instance |
| 4677 | * |
| 4678 | * If the compositor was in a sleeping mode, all outputs are powered |
| 4679 | * back on via DPMS. Otherwise if the compositor was inactive |
| 4680 | * (idle/locked, offscreen, or sleeping) then the compositor's wake |
| 4681 | * signal will fire. |
| 4682 | * |
| 4683 | * Restarts the idle timer. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 4684 | * \ingroup compositor |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4685 | */ |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4686 | WL_EXPORT void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4687 | weston_compositor_wake(struct weston_compositor *compositor) |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4688 | { |
Neil Roberts | 8b62e20 | 2013-09-30 13:14:47 +0100 | [diff] [blame] | 4689 | uint32_t old_state = compositor->state; |
| 4690 | |
| 4691 | /* The state needs to be changed before emitting the wake |
| 4692 | * signal because that may try to schedule a repaint which |
| 4693 | * will not work if the compositor is still sleeping */ |
| 4694 | compositor->state = WESTON_COMPOSITOR_ACTIVE; |
| 4695 | |
| 4696 | switch (old_state) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4697 | case WESTON_COMPOSITOR_SLEEPING: |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4698 | case WESTON_COMPOSITOR_IDLE: |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4699 | case WESTON_COMPOSITOR_OFFSCREEN: |
Daniel Stone | 893b936 | 2016-11-08 15:47:09 +0000 | [diff] [blame] | 4700 | weston_compositor_dpms(compositor, WESTON_DPMS_ON); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4701 | wl_signal_emit(&compositor->wake_signal, compositor); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4702 | /* fall through */ |
| 4703 | default: |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4704 | wl_event_source_timer_update(compositor->idle_source, |
| 4705 | compositor->idle_time * 1000); |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4706 | } |
| 4707 | } |
| 4708 | |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4709 | /** Turns off rendering and frame events for the compositor. |
| 4710 | * |
| 4711 | * \param compositor The compositor instance |
| 4712 | * |
| 4713 | * This is used for example to prevent further rendering while the |
| 4714 | * compositor is shutting down. |
| 4715 | * |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4716 | * Stops the idle timer. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 4717 | * |
| 4718 | * \ingroup compositor |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4719 | */ |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4720 | WL_EXPORT void |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4721 | weston_compositor_offscreen(struct weston_compositor *compositor) |
| 4722 | { |
| 4723 | switch (compositor->state) { |
| 4724 | case WESTON_COMPOSITOR_OFFSCREEN: |
| 4725 | return; |
| 4726 | case WESTON_COMPOSITOR_SLEEPING: |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4727 | default: |
| 4728 | compositor->state = WESTON_COMPOSITOR_OFFSCREEN; |
| 4729 | wl_event_source_timer_update(compositor->idle_source, 0); |
| 4730 | } |
| 4731 | } |
| 4732 | |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4733 | /** Powers down all attached output devices |
| 4734 | * |
| 4735 | * \param compositor The compositor instance |
| 4736 | * |
| 4737 | * Causes rendering to the outputs to cease, and no frame events to be |
| 4738 | * sent. Only powers down the outputs if the compositor is not already |
| 4739 | * in sleep mode. |
| 4740 | * |
| 4741 | * Stops the idle timer. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 4742 | * |
| 4743 | * \ingroup compositor |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4744 | */ |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4745 | WL_EXPORT void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4746 | weston_compositor_sleep(struct weston_compositor *compositor) |
| 4747 | { |
| 4748 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING) |
| 4749 | return; |
| 4750 | |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4751 | wl_event_source_timer_update(compositor->idle_source, 0); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4752 | compositor->state = WESTON_COMPOSITOR_SLEEPING; |
| 4753 | weston_compositor_dpms(compositor, WESTON_DPMS_OFF); |
| 4754 | } |
| 4755 | |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4756 | /** Sets compositor to idle mode |
| 4757 | * |
| 4758 | * \param data The compositor instance |
| 4759 | * |
| 4760 | * This is called when the idle timer fires. Once the compositor is in |
| 4761 | * idle mode it requires a wake action (e.g. via |
| 4762 | * weston_compositor_wake()) to restore it. The compositor's |
| 4763 | * idle_signal will be triggered when the idle event occurs. |
| 4764 | * |
| 4765 | * Idleness can be inhibited by setting the compositor's idle_inhibit |
| 4766 | * property. |
| 4767 | */ |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 4768 | static int |
| 4769 | idle_handler(void *data) |
| 4770 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4771 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 4772 | |
| 4773 | if (compositor->idle_inhibit) |
| 4774 | return 1; |
| 4775 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4776 | compositor->state = WESTON_COMPOSITOR_IDLE; |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4777 | wl_signal_emit(&compositor->idle_signal, compositor); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 4778 | |
| 4779 | return 1; |
| 4780 | } |
| 4781 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4782 | WL_EXPORT void |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 4783 | weston_plane_init(struct weston_plane *plane, |
| 4784 | struct weston_compositor *ec, |
| 4785 | int32_t x, int32_t y) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4786 | { |
| 4787 | pixman_region32_init(&plane->damage); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 4788 | pixman_region32_init(&plane->clip); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4789 | plane->x = x; |
| 4790 | plane->y = y; |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 4791 | plane->compositor = ec; |
Ander Conselvan de Oliveira | 3c36bf3 | 2013-07-05 16:05:26 +0300 | [diff] [blame] | 4792 | |
| 4793 | /* Init the link so that the call to wl_list_remove() when releasing |
| 4794 | * the plane without ever stacking doesn't lead to a crash */ |
| 4795 | wl_list_init(&plane->link); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4796 | } |
| 4797 | |
| 4798 | WL_EXPORT void |
| 4799 | weston_plane_release(struct weston_plane *plane) |
| 4800 | { |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 4801 | struct weston_view *view; |
| 4802 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4803 | pixman_region32_fini(&plane->damage); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 4804 | pixman_region32_fini(&plane->clip); |
Ander Conselvan de Oliveira | 3c36bf3 | 2013-07-05 16:05:26 +0300 | [diff] [blame] | 4805 | |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 4806 | wl_list_for_each(view, &plane->compositor->view_list, link) { |
| 4807 | if (view->plane == plane) |
| 4808 | view->plane = NULL; |
| 4809 | } |
| 4810 | |
Ander Conselvan de Oliveira | 3c36bf3 | 2013-07-05 16:05:26 +0300 | [diff] [blame] | 4811 | wl_list_remove(&plane->link); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4812 | } |
| 4813 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 4814 | /** weston_compositor_stack_plane |
| 4815 | * \ingroup compositor |
| 4816 | */ |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 4817 | WL_EXPORT void |
| 4818 | weston_compositor_stack_plane(struct weston_compositor *ec, |
| 4819 | struct weston_plane *plane, |
| 4820 | struct weston_plane *above) |
| 4821 | { |
| 4822 | if (above) |
| 4823 | wl_list_insert(above->link.prev, &plane->link); |
| 4824 | else |
| 4825 | wl_list_insert(&ec->plane_list, &plane->link); |
| 4826 | } |
| 4827 | |
Quentin Glidic | 4ef719c | 2016-07-05 20:44:33 +0200 | [diff] [blame] | 4828 | static void |
| 4829 | output_release(struct wl_client *client, struct wl_resource *resource) |
| 4830 | { |
| 4831 | wl_resource_destroy(resource); |
| 4832 | } |
| 4833 | |
| 4834 | static const struct wl_output_interface output_interface = { |
| 4835 | output_release, |
| 4836 | }; |
| 4837 | |
| 4838 | |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 4839 | static void unbind_resource(struct wl_resource *resource) |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 4840 | { |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4841 | wl_list_remove(wl_resource_get_link(resource)); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 4842 | } |
| 4843 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4844 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4845 | bind_output(struct wl_client *client, |
| 4846 | void *data, uint32_t version, uint32_t id) |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 4847 | { |
Pekka Paalanen | 0534762 | 2017-03-27 12:24:34 +0300 | [diff] [blame] | 4848 | struct weston_head *head = data; |
| 4849 | struct weston_output *output = head->output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4850 | struct weston_mode *mode; |
Kristian Høgsberg | fd07fb7 | 2011-08-29 15:03:09 -0400 | [diff] [blame] | 4851 | struct wl_resource *resource; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 4852 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4853 | resource = wl_resource_create(client, &wl_output_interface, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 4854 | version, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 4855 | if (resource == NULL) { |
| 4856 | wl_client_post_no_memory(client); |
| 4857 | return; |
| 4858 | } |
Kristian Høgsberg | fd07fb7 | 2011-08-29 15:03:09 -0400 | [diff] [blame] | 4859 | |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 4860 | wl_list_insert(&head->resource_list, wl_resource_get_link(resource)); |
Pekka Paalanen | 055c113 | 2017-03-27 16:31:25 +0300 | [diff] [blame] | 4861 | wl_resource_set_implementation(resource, &output_interface, head, |
Pekka Paalanen | 0534762 | 2017-03-27 12:24:34 +0300 | [diff] [blame] | 4862 | unbind_resource); |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 4863 | |
Pekka Paalanen | 0534762 | 2017-03-27 12:24:34 +0300 | [diff] [blame] | 4864 | assert(output); |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4865 | wl_output_send_geometry(resource, |
| 4866 | output->x, |
| 4867 | output->y, |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 4868 | head->mm_width, |
| 4869 | head->mm_height, |
| 4870 | head->subpixel, |
| 4871 | head->make, head->model, |
Kristian Høgsberg | 05890dc | 2012-08-10 10:09:20 -0400 | [diff] [blame] | 4872 | output->transform); |
Jasper St. Pierre | 0013a29 | 2014-08-07 16:43:11 -0400 | [diff] [blame] | 4873 | if (version >= WL_OUTPUT_SCALE_SINCE_VERSION) |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 4874 | wl_output_send_scale(resource, |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 4875 | output->current_scale); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 4876 | |
| 4877 | wl_list_for_each (mode, &output->mode_list, link) { |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4878 | wl_output_send_mode(resource, |
| 4879 | mode->flags, |
| 4880 | mode->width, |
| 4881 | mode->height, |
| 4882 | mode->refresh); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 4883 | } |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 4884 | |
Jasper St. Pierre | 0013a29 | 2014-08-07 16:43:11 -0400 | [diff] [blame] | 4885 | if (version >= WL_OUTPUT_DONE_SINCE_VERSION) |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 4886 | wl_output_send_done(resource); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 4887 | } |
| 4888 | |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 4889 | static void |
| 4890 | weston_head_add_global(struct weston_head *head) |
| 4891 | { |
| 4892 | head->global = wl_global_create(head->compositor->wl_display, |
| 4893 | &wl_output_interface, 3, |
| 4894 | head, bind_output); |
| 4895 | } |
| 4896 | |
Pekka Paalanen | d9dcc6d | 2017-12-04 15:28:13 +0200 | [diff] [blame] | 4897 | /** Remove the global wl_output protocol object |
| 4898 | * |
| 4899 | * \param head The head whose global to remove. |
| 4900 | * |
| 4901 | * Also orphans the wl_resources for this head (wl_output). |
| 4902 | */ |
| 4903 | static void |
| 4904 | weston_head_remove_global(struct weston_head *head) |
| 4905 | { |
| 4906 | struct wl_resource *resource, *tmp; |
| 4907 | |
| 4908 | if (head->global) |
| 4909 | wl_global_destroy(head->global); |
| 4910 | head->global = NULL; |
| 4911 | |
| 4912 | wl_resource_for_each_safe(resource, tmp, &head->resource_list) { |
| 4913 | unbind_resource(resource); |
| 4914 | wl_resource_set_destructor(resource, NULL); |
| 4915 | wl_resource_set_user_data(resource, NULL); |
| 4916 | } |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 4917 | |
| 4918 | wl_resource_for_each(resource, &head->xdg_output_resource_list) { |
| 4919 | /* It's sufficient to unset the destructor, then the list elements |
| 4920 | * won't be accessed. |
| 4921 | */ |
| 4922 | wl_resource_set_destructor(resource, NULL); |
| 4923 | } |
| 4924 | wl_list_init(&head->xdg_output_resource_list); |
Pekka Paalanen | d9dcc6d | 2017-12-04 15:28:13 +0200 | [diff] [blame] | 4925 | } |
| 4926 | |
Pekka Paalanen | 9ffb250 | 2017-03-27 15:14:32 +0300 | [diff] [blame] | 4927 | /** Get the backing object of wl_output |
| 4928 | * |
| 4929 | * \param resource A wl_output protocol object. |
| 4930 | * \return The backing object (user data) of a wl_resource representing a |
| 4931 | * wl_output protocol object. |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 4932 | * |
| 4933 | * \ingroup head |
Pekka Paalanen | 9ffb250 | 2017-03-27 15:14:32 +0300 | [diff] [blame] | 4934 | */ |
Pekka Paalanen | 055c113 | 2017-03-27 16:31:25 +0300 | [diff] [blame] | 4935 | WL_EXPORT struct weston_head * |
| 4936 | weston_head_from_resource(struct wl_resource *resource) |
Pekka Paalanen | 9ffb250 | 2017-03-27 15:14:32 +0300 | [diff] [blame] | 4937 | { |
| 4938 | assert(wl_resource_instance_of(resource, &wl_output_interface, |
| 4939 | &output_interface)); |
| 4940 | |
| 4941 | return wl_resource_get_user_data(resource); |
| 4942 | } |
| 4943 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4944 | /** Initialize a pre-allocated weston_head |
| 4945 | * |
| 4946 | * \param head The head to initialize. |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 4947 | * \param name The head name, e.g. the connector name or equivalent. |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4948 | * |
| 4949 | * The head will be safe to attach, detach and release. |
| 4950 | * |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 4951 | * The name is used in logs, and can be used by compositors as a configuration |
| 4952 | * identifier. |
| 4953 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 4954 | * \ingroup head |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4955 | * \internal |
| 4956 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 4957 | WL_EXPORT void |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 4958 | weston_head_init(struct weston_head *head, const char *name) |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4959 | { |
| 4960 | /* Add some (in)sane defaults which can be used |
| 4961 | * for checking if an output was properly configured |
| 4962 | */ |
| 4963 | memset(head, 0, sizeof *head); |
| 4964 | |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 4965 | wl_list_init(&head->compositor_link); |
Pekka Paalanen | 2e1bedb | 2017-10-10 11:21:58 +0300 | [diff] [blame] | 4966 | wl_signal_init(&head->destroy_signal); |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4967 | wl_list_init(&head->output_link); |
| 4968 | wl_list_init(&head->resource_list); |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 4969 | wl_list_init(&head->xdg_output_resource_list); |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 4970 | head->name = strdup(name); |
Ankit Nautiyal | 4f64ff8 | 2019-04-03 18:44:35 +0530 | [diff] [blame] | 4971 | head->current_protection = WESTON_HDCP_DISABLE; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4972 | } |
| 4973 | |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 4974 | /** Send output heads changed signal |
| 4975 | * |
| 4976 | * \param output The output that changed. |
| 4977 | * |
| 4978 | * Notify that the enabled output gained and/or lost heads, or that the |
| 4979 | * associated heads may have changed their connection status. This does not |
| 4980 | * include cases where the output becomes enabled or disabled. The registered |
| 4981 | * callbacks are called after the change has successfully happened. |
| 4982 | * |
| 4983 | * If connection status change causes the compositor to attach or detach a head |
| 4984 | * to an enabled output, the registered callbacks may be called multiple times. |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 4985 | * |
| 4986 | * \ingroup output |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 4987 | */ |
| 4988 | static void |
| 4989 | weston_output_emit_heads_changed(struct weston_output *output) |
| 4990 | { |
| 4991 | wl_signal_emit(&output->compositor->output_heads_changed_signal, |
| 4992 | output); |
| 4993 | } |
| 4994 | |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4995 | /** Idle task for emitting heads_changed_signal */ |
| 4996 | static void |
| 4997 | weston_compositor_call_heads_changed(void *data) |
| 4998 | { |
| 4999 | struct weston_compositor *compositor = data; |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 5000 | struct weston_head *head; |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5001 | |
| 5002 | compositor->heads_changed_source = NULL; |
| 5003 | |
| 5004 | wl_signal_emit(&compositor->heads_changed_signal, compositor); |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 5005 | |
| 5006 | wl_list_for_each(head, &compositor->head_list, compositor_link) { |
| 5007 | if (head->output && head->output->enabled) |
| 5008 | weston_output_emit_heads_changed(head->output); |
| 5009 | } |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5010 | } |
| 5011 | |
| 5012 | /** Schedule a call on idle to heads_changed callback |
| 5013 | * |
| 5014 | * \param compositor The Compositor. |
| 5015 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 5016 | * \ingroup compositor |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5017 | * \internal |
| 5018 | */ |
| 5019 | static void |
| 5020 | weston_compositor_schedule_heads_changed(struct weston_compositor *compositor) |
| 5021 | { |
| 5022 | struct wl_event_loop *loop; |
| 5023 | |
| 5024 | if (compositor->heads_changed_source) |
| 5025 | return; |
| 5026 | |
| 5027 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 5028 | compositor->heads_changed_source = wl_event_loop_add_idle(loop, |
| 5029 | weston_compositor_call_heads_changed, compositor); |
| 5030 | } |
| 5031 | |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 5032 | /** Register a new head |
| 5033 | * |
| 5034 | * \param compositor The compositor. |
| 5035 | * \param head The head to register, must not be already registered. |
| 5036 | * |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5037 | * This signals the core that a new head has become available, leading to |
| 5038 | * heads_changed hook being called later. |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 5039 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 5040 | * \ingroup compositor |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 5041 | * \internal |
| 5042 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5043 | WL_EXPORT void |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 5044 | weston_compositor_add_head(struct weston_compositor *compositor, |
| 5045 | struct weston_head *head) |
| 5046 | { |
| 5047 | assert(wl_list_empty(&head->compositor_link)); |
| 5048 | assert(head->name); |
| 5049 | |
| 5050 | wl_list_insert(compositor->head_list.prev, &head->compositor_link); |
| 5051 | head->compositor = compositor; |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5052 | weston_compositor_schedule_heads_changed(compositor); |
| 5053 | } |
| 5054 | |
| 5055 | /** Adds a listener to be called when heads change |
| 5056 | * |
| 5057 | * \param compositor The compositor. |
| 5058 | * \param listener The listener to add. |
| 5059 | * |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 5060 | * The listener notify function argument is weston_compositor. |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5061 | * |
| 5062 | * The listener function will be called after heads are added or their |
| 5063 | * connection status has changed. Several changes may be accumulated into a |
| 5064 | * single call. The user is expected to iterate over the existing heads and |
| 5065 | * check their statuses to find out what changed. |
| 5066 | * |
| 5067 | * \sa weston_compositor_iterate_heads, weston_head_is_connected, |
| 5068 | * weston_head_is_enabled |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 5069 | * \ingroup compositor |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5070 | */ |
| 5071 | WL_EXPORT void |
| 5072 | weston_compositor_add_heads_changed_listener(struct weston_compositor *compositor, |
| 5073 | struct wl_listener *listener) |
| 5074 | { |
| 5075 | wl_signal_add(&compositor->heads_changed_signal, listener); |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 5076 | } |
| 5077 | |
| 5078 | /** Iterate over available heads |
| 5079 | * |
| 5080 | * \param compositor The compositor. |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 5081 | * \param iter The iterator, or NULL for start. |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 5082 | * \return The next available head in the list. |
| 5083 | * |
| 5084 | * Returns all available heads, regardless of being connected or enabled. |
| 5085 | * |
| 5086 | * You can iterate over all heads as follows: |
| 5087 | * \code |
| 5088 | * struct weston_head *head = NULL; |
| 5089 | * |
| 5090 | * while ((head = weston_compositor_iterate_heads(compositor, head))) { |
| 5091 | * ... |
| 5092 | * } |
| 5093 | * \endcode |
| 5094 | * |
| 5095 | * If you cause \c iter to be removed from the list, you cannot use it to |
| 5096 | * continue iterating. Removing any other item is safe. |
| 5097 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 5098 | * \ingroup compositor |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 5099 | */ |
| 5100 | WL_EXPORT struct weston_head * |
| 5101 | weston_compositor_iterate_heads(struct weston_compositor *compositor, |
| 5102 | struct weston_head *iter) |
| 5103 | { |
| 5104 | struct wl_list *list = &compositor->head_list; |
| 5105 | struct wl_list *node; |
| 5106 | |
| 5107 | assert(compositor); |
| 5108 | assert(!iter || iter->compositor == compositor); |
| 5109 | |
| 5110 | if (iter) |
| 5111 | node = iter->compositor_link.next; |
| 5112 | else |
| 5113 | node = list->next; |
| 5114 | |
| 5115 | assert(node); |
| 5116 | assert(!iter || node != &iter->compositor_link); |
| 5117 | |
| 5118 | if (node == list) |
| 5119 | return NULL; |
| 5120 | |
| 5121 | return container_of(node, struct weston_head, compositor_link); |
| 5122 | } |
| 5123 | |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5124 | /** Iterate over attached heads |
| 5125 | * |
| 5126 | * \param output The output whose heads to iterate. |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 5127 | * \param iter The iterator, or NULL for start. |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5128 | * \return The next attached head in the list. |
| 5129 | * |
| 5130 | * Returns all heads currently attached to the output. |
| 5131 | * |
| 5132 | * You can iterate over all heads as follows: |
| 5133 | * \code |
| 5134 | * struct weston_head *head = NULL; |
| 5135 | * |
| 5136 | * while ((head = weston_output_iterate_heads(output, head))) { |
| 5137 | * ... |
| 5138 | * } |
| 5139 | * \endcode |
| 5140 | * |
| 5141 | * If you cause \c iter to be removed from the list, you cannot use it to |
| 5142 | * continue iterating. Removing any other item is safe. |
| 5143 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 5144 | * \ingroup ouput |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5145 | */ |
| 5146 | WL_EXPORT struct weston_head * |
| 5147 | weston_output_iterate_heads(struct weston_output *output, |
| 5148 | struct weston_head *iter) |
| 5149 | { |
| 5150 | struct wl_list *list = &output->head_list; |
| 5151 | struct wl_list *node; |
| 5152 | |
| 5153 | assert(output); |
| 5154 | assert(!iter || iter->output == output); |
| 5155 | |
| 5156 | if (iter) |
| 5157 | node = iter->output_link.next; |
| 5158 | else |
| 5159 | node = list->next; |
| 5160 | |
| 5161 | assert(node); |
| 5162 | assert(!iter || node != &iter->output_link); |
| 5163 | |
| 5164 | if (node == list) |
| 5165 | return NULL; |
| 5166 | |
| 5167 | return container_of(node, struct weston_head, output_link); |
| 5168 | } |
| 5169 | |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 5170 | /** Attach a head to an output |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5171 | * |
| 5172 | * \param output The output to attach to. |
| 5173 | * \param head The head that is not yet attached. |
| 5174 | * \return 0 on success, -1 on failure. |
| 5175 | * |
| 5176 | * Attaches the given head to the output. All heads of an output are clones |
| 5177 | * and share the resolution and timings. |
| 5178 | * |
| 5179 | * Cloning heads this way uses less resources than creating an output for |
| 5180 | * each head, but is not always possible due to environment, driver and hardware |
| 5181 | * limitations. |
| 5182 | * |
| 5183 | * On failure, the head remains unattached. Success of this function does not |
| 5184 | * guarantee the output configuration is actually valid. The final checks are |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 5185 | * made on weston_output_enable() unless the output was already enabled. |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5186 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 5187 | * \ingroup output |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5188 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5189 | WL_EXPORT int |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5190 | weston_output_attach_head(struct weston_output *output, |
| 5191 | struct weston_head *head) |
| 5192 | { |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 5193 | char *head_names; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5194 | |
| 5195 | if (!wl_list_empty(&head->output_link)) |
| 5196 | return -1; |
| 5197 | |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5198 | if (output->attach_head) { |
| 5199 | if (output->attach_head(output, head) < 0) |
| 5200 | return -1; |
| 5201 | } else if (!wl_list_empty(&output->head_list)) { |
| 5202 | /* No support for clones in the legacy path. */ |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5203 | return -1; |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5204 | } |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5205 | |
| 5206 | head->output = output; |
| 5207 | wl_list_insert(output->head_list.prev, &head->output_link); |
| 5208 | |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 5209 | if (output->enabled) { |
| 5210 | weston_head_add_global(head); |
| 5211 | |
| 5212 | head_names = weston_output_create_heads_string(output); |
| 5213 | weston_log("Output '%s' updated to have head(s) %s\n", |
| 5214 | output->name, head_names); |
| 5215 | free(head_names); |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 5216 | |
| 5217 | weston_output_emit_heads_changed(output); |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 5218 | } |
| 5219 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5220 | return 0; |
| 5221 | } |
| 5222 | |
| 5223 | /** Detach a head from its output |
| 5224 | * |
| 5225 | * \param head The head to detach. |
| 5226 | * |
| 5227 | * It is safe to detach a non-attached head. |
| 5228 | * |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5229 | * If the head is attached to an enabled output and the output will be left |
| 5230 | * with no heads, the output will be disabled. |
| 5231 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5232 | * \ingroup head |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5233 | * \sa weston_output_disable |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5234 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5235 | WL_EXPORT void |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5236 | weston_head_detach(struct weston_head *head) |
| 5237 | { |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5238 | struct weston_output *output = head->output; |
Pekka Paalanen | a010699 | 2017-12-08 16:11:17 +0200 | [diff] [blame] | 5239 | char *head_names; |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5240 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5241 | wl_list_remove(&head->output_link); |
| 5242 | wl_list_init(&head->output_link); |
| 5243 | head->output = NULL; |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5244 | |
| 5245 | if (!output) |
| 5246 | return; |
| 5247 | |
| 5248 | if (output->detach_head) |
| 5249 | output->detach_head(output, head); |
| 5250 | |
| 5251 | if (output->enabled) { |
| 5252 | weston_head_remove_global(head); |
| 5253 | |
Pekka Paalanen | a010699 | 2017-12-08 16:11:17 +0200 | [diff] [blame] | 5254 | if (wl_list_empty(&output->head_list)) { |
| 5255 | weston_log("Output '%s' no heads left, disabling.\n", |
| 5256 | output->name); |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5257 | weston_output_disable(output); |
Pekka Paalanen | a010699 | 2017-12-08 16:11:17 +0200 | [diff] [blame] | 5258 | } else { |
| 5259 | head_names = weston_output_create_heads_string(output); |
| 5260 | weston_log("Output '%s' updated to have head(s) %s\n", |
| 5261 | output->name, head_names); |
| 5262 | free(head_names); |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 5263 | |
| 5264 | weston_output_emit_heads_changed(output); |
Pekka Paalanen | a010699 | 2017-12-08 16:11:17 +0200 | [diff] [blame] | 5265 | } |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5266 | } |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5267 | } |
| 5268 | |
| 5269 | /** Destroy a head |
| 5270 | * |
| 5271 | * \param head The head to be released. |
| 5272 | * |
| 5273 | * Destroys the head. The caller is responsible for freeing the memory pointed |
| 5274 | * to by \c head. |
| 5275 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5276 | * \ingroup head |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5277 | * \internal |
| 5278 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5279 | WL_EXPORT void |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5280 | weston_head_release(struct weston_head *head) |
| 5281 | { |
Pekka Paalanen | 2e1bedb | 2017-10-10 11:21:58 +0300 | [diff] [blame] | 5282 | wl_signal_emit(&head->destroy_signal, head); |
| 5283 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5284 | weston_head_detach(head); |
Pekka Paalanen | 06f99ef | 2017-04-04 16:26:23 +0300 | [diff] [blame] | 5285 | |
| 5286 | free(head->make); |
| 5287 | free(head->model); |
| 5288 | free(head->serial_number); |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 5289 | free(head->name); |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 5290 | |
| 5291 | wl_list_remove(&head->compositor_link); |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5292 | } |
| 5293 | |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5294 | static void |
| 5295 | weston_head_set_device_changed(struct weston_head *head) |
| 5296 | { |
| 5297 | head->device_changed = true; |
| 5298 | |
| 5299 | if (head->compositor) |
| 5300 | weston_compositor_schedule_heads_changed(head->compositor); |
| 5301 | } |
| 5302 | |
| 5303 | /** String equal comparison with NULLs being equal */ |
| 5304 | static bool |
| 5305 | str_null_eq(const char *a, const char *b) |
| 5306 | { |
| 5307 | if (!a && !b) |
| 5308 | return true; |
| 5309 | |
| 5310 | if (!!a != !!b) |
| 5311 | return false; |
| 5312 | |
| 5313 | return strcmp(a, b) == 0; |
| 5314 | } |
| 5315 | |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5316 | /** Store monitor make, model and serial number |
| 5317 | * |
| 5318 | * \param head The head to modify. |
| 5319 | * \param make The monitor make. If EDID is available, the PNP ID. Otherwise |
| 5320 | * any string, or NULL for none. |
| 5321 | * \param model The monitor model or name, or a made-up string, or NULL for |
| 5322 | * none. |
| 5323 | * \param serialno The monitor serial number, a made-up string, or NULL for |
| 5324 | * none. |
| 5325 | * |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5326 | * This may set the device_changed flag. |
| 5327 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5328 | * \ingroup head |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5329 | * \internal |
| 5330 | */ |
| 5331 | WL_EXPORT void |
| 5332 | weston_head_set_monitor_strings(struct weston_head *head, |
| 5333 | const char *make, |
| 5334 | const char *model, |
| 5335 | const char *serialno) |
| 5336 | { |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5337 | if (str_null_eq(head->make, make) && |
| 5338 | str_null_eq(head->model, model) && |
| 5339 | str_null_eq(head->serial_number, serialno)) |
| 5340 | return; |
| 5341 | |
Pekka Paalanen | 06f99ef | 2017-04-04 16:26:23 +0300 | [diff] [blame] | 5342 | free(head->make); |
| 5343 | free(head->model); |
| 5344 | free(head->serial_number); |
| 5345 | |
| 5346 | head->make = make ? strdup(make) : NULL; |
| 5347 | head->model = model ? strdup(model) : NULL; |
| 5348 | head->serial_number = serialno ? strdup(serialno) : NULL; |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5349 | |
| 5350 | weston_head_set_device_changed(head); |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5351 | } |
| 5352 | |
Philipp Zabel | c18ffd3 | 2018-08-30 17:38:03 +0200 | [diff] [blame] | 5353 | /** Store display non-desktop status |
| 5354 | * |
| 5355 | * \param head The head to modify. |
| 5356 | * \param non_desktop Whether the head connects to a non-desktop display. |
| 5357 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5358 | * \ingroup head |
Philipp Zabel | c18ffd3 | 2018-08-30 17:38:03 +0200 | [diff] [blame] | 5359 | * \internal |
| 5360 | */ |
| 5361 | WL_EXPORT void |
| 5362 | weston_head_set_non_desktop(struct weston_head *head, bool non_desktop) |
| 5363 | { |
| 5364 | if (head->non_desktop == non_desktop) |
| 5365 | return; |
| 5366 | |
| 5367 | head->non_desktop = non_desktop; |
| 5368 | |
| 5369 | weston_head_set_device_changed(head); |
| 5370 | } |
| 5371 | |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5372 | /** Store physical image size |
| 5373 | * |
| 5374 | * \param head The head to modify. |
| 5375 | * \param mm_width Image area width in millimeters. |
| 5376 | * \param mm_height Image area height in millimeters. |
| 5377 | * |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5378 | * This may set the device_changed flag. |
| 5379 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5380 | * \ingroup head |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5381 | * \internal |
| 5382 | */ |
| 5383 | WL_EXPORT void |
| 5384 | weston_head_set_physical_size(struct weston_head *head, |
| 5385 | int32_t mm_width, int32_t mm_height) |
| 5386 | { |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5387 | if (head->mm_width == mm_width && |
| 5388 | head->mm_height == mm_height) |
| 5389 | return; |
| 5390 | |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5391 | head->mm_width = mm_width; |
| 5392 | head->mm_height = mm_height; |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5393 | |
| 5394 | weston_head_set_device_changed(head); |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5395 | } |
| 5396 | |
| 5397 | /** Store monitor sub-pixel layout |
| 5398 | * |
| 5399 | * \param head The head to modify. |
| 5400 | * \param sp Sub-pixel layout. The possible values are: |
| 5401 | * - WL_OUTPUT_SUBPIXEL_UNKNOWN, |
| 5402 | * - WL_OUTPUT_SUBPIXEL_NONE, |
| 5403 | * - WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB, |
| 5404 | * - WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR, |
| 5405 | * - WL_OUTPUT_SUBPIXEL_VERTICAL_RGB, |
| 5406 | * - WL_OUTPUT_SUBPIXEL_VERTICAL_BGR |
| 5407 | * |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5408 | * This may set the device_changed flag. |
| 5409 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5410 | * \ingroup head |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5411 | * \internal |
| 5412 | */ |
| 5413 | WL_EXPORT void |
| 5414 | weston_head_set_subpixel(struct weston_head *head, |
| 5415 | enum wl_output_subpixel sp) |
| 5416 | { |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5417 | if (head->subpixel == sp) |
| 5418 | return; |
| 5419 | |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5420 | head->subpixel = sp; |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5421 | |
| 5422 | weston_head_set_device_changed(head); |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5423 | } |
| 5424 | |
| 5425 | /** Mark the monitor as internal |
| 5426 | * |
| 5427 | * This is used for embedded screens, like laptop panels. |
| 5428 | * |
| 5429 | * \param head The head to mark as internal. |
| 5430 | * |
| 5431 | * By default a head is external. The type is often inferred from the physical |
| 5432 | * connector type. |
| 5433 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5434 | * \ingroup head |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5435 | * \internal |
| 5436 | */ |
| 5437 | WL_EXPORT void |
| 5438 | weston_head_set_internal(struct weston_head *head) |
| 5439 | { |
| 5440 | head->connection_internal = true; |
| 5441 | } |
Pekka Paalanen | 9ffb250 | 2017-03-27 15:14:32 +0300 | [diff] [blame] | 5442 | |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5443 | /** Store connector status |
| 5444 | * |
| 5445 | * \param head The head to modify. |
| 5446 | * \param connected Whether the head is connected. |
| 5447 | * |
| 5448 | * Connectors are created as disconnected. This function can be used to |
| 5449 | * set the connector status. |
| 5450 | * |
| 5451 | * The status should be set to true when a physical connector is connected to |
| 5452 | * a video sink device like a monitor and to false when the connector is |
| 5453 | * disconnected. For nested backends, the connection status should reflect the |
| 5454 | * connection to the parent display server. |
| 5455 | * |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5456 | * 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] | 5457 | * hook and sets the device_changed flag. |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5458 | * |
| 5459 | * \sa weston_compositor_set_heads_changed_cb |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5460 | * \ingroup head |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5461 | * \internal |
| 5462 | */ |
| 5463 | WL_EXPORT void |
| 5464 | weston_head_set_connection_status(struct weston_head *head, bool connected) |
| 5465 | { |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5466 | if (head->connected == connected) |
| 5467 | return; |
| 5468 | |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5469 | head->connected = connected; |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5470 | |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5471 | weston_head_set_device_changed(head); |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5472 | } |
| 5473 | |
Ankit Nautiyal | 4f64ff8 | 2019-04-03 18:44:35 +0530 | [diff] [blame] | 5474 | static void |
| 5475 | weston_output_compute_protection(struct weston_output *output) |
| 5476 | { |
| 5477 | struct weston_head *head; |
| 5478 | enum weston_hdcp_protection op_protection; |
| 5479 | bool op_protection_valid = false; |
Ankit Nautiyal | f74c35b | 2019-04-03 19:21:58 +0530 | [diff] [blame] | 5480 | struct weston_compositor *wc = output->compositor; |
Ankit Nautiyal | 4f64ff8 | 2019-04-03 18:44:35 +0530 | [diff] [blame] | 5481 | |
| 5482 | wl_list_for_each(head, &output->head_list, output_link) { |
| 5483 | if (!op_protection_valid) { |
| 5484 | op_protection = head->current_protection; |
| 5485 | op_protection_valid = true; |
| 5486 | } |
| 5487 | if (head->current_protection < op_protection) |
| 5488 | op_protection = head->current_protection; |
| 5489 | } |
| 5490 | |
| 5491 | if (!op_protection_valid) |
| 5492 | op_protection = WESTON_HDCP_DISABLE; |
| 5493 | |
Ankit Nautiyal | f74c35b | 2019-04-03 19:21:58 +0530 | [diff] [blame] | 5494 | if (output->current_protection != op_protection) { |
Ankit Nautiyal | 4f64ff8 | 2019-04-03 18:44:35 +0530 | [diff] [blame] | 5495 | output->current_protection = op_protection; |
Ankit Nautiyal | f74c35b | 2019-04-03 19:21:58 +0530 | [diff] [blame] | 5496 | weston_output_damage(output); |
Ankit Nautiyal | faa5ab4 | 2019-07-08 13:23:24 +0530 | [diff] [blame] | 5497 | weston_schedule_surface_protection_update(wc); |
Ankit Nautiyal | f74c35b | 2019-04-03 19:21:58 +0530 | [diff] [blame] | 5498 | } |
Ankit Nautiyal | 4f64ff8 | 2019-04-03 18:44:35 +0530 | [diff] [blame] | 5499 | } |
| 5500 | |
| 5501 | WL_EXPORT void |
| 5502 | weston_head_set_content_protection_status(struct weston_head *head, |
| 5503 | enum weston_hdcp_protection status) |
| 5504 | { |
| 5505 | head->current_protection = status; |
| 5506 | if (head->output) |
| 5507 | weston_output_compute_protection(head->output); |
| 5508 | } |
| 5509 | |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5510 | /** Is the head currently connected? |
| 5511 | * |
| 5512 | * \param head The head to query. |
| 5513 | * \return Connection status. |
| 5514 | * |
| 5515 | * Returns true if the head is physically connected to a monitor, or in |
| 5516 | * case of a nested backend returns true when there is a connection to the |
| 5517 | * parent display server. |
| 5518 | * |
| 5519 | * This is independent from the head being enabled. |
| 5520 | * |
| 5521 | * \sa weston_head_is_enabled |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5522 | * \ingroup head |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5523 | */ |
| 5524 | WL_EXPORT bool |
| 5525 | weston_head_is_connected(struct weston_head *head) |
| 5526 | { |
| 5527 | return head->connected; |
| 5528 | } |
| 5529 | |
Pekka Paalanen | 8e552fd | 2018-02-15 15:18:20 +0200 | [diff] [blame] | 5530 | /** Is the head currently enabled? |
| 5531 | * |
| 5532 | * \param head The head to query. |
| 5533 | * \return Video status. |
| 5534 | * |
| 5535 | * Returns true if the head is currently transmitting a video stream. |
| 5536 | * |
| 5537 | * This is independent of the head being connected. |
| 5538 | * |
| 5539 | * \sa weston_head_is_connected |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5540 | * \ingroup head |
Pekka Paalanen | 8e552fd | 2018-02-15 15:18:20 +0200 | [diff] [blame] | 5541 | */ |
| 5542 | WL_EXPORT bool |
| 5543 | weston_head_is_enabled(struct weston_head *head) |
| 5544 | { |
| 5545 | if (!head->output) |
| 5546 | return false; |
| 5547 | |
| 5548 | return head->output->enabled; |
| 5549 | } |
| 5550 | |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5551 | /** Has the device information changed? |
| 5552 | * |
| 5553 | * \param head The head to query. |
| 5554 | * \return True if the device information has changed since last reset. |
| 5555 | * |
| 5556 | * The information about the connected display device, e.g. a monitor, may |
| 5557 | * change without being disconnected in between. Changing information |
| 5558 | * causes a call to the heads_changed hook. |
| 5559 | * |
| 5560 | * The information includes make, model, serial number, physical size, |
| 5561 | * and sub-pixel type. The connection status is also included. |
| 5562 | * |
| 5563 | * \sa weston_head_reset_device_changed, weston_compositor_set_heads_changed_cb |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5564 | * \ingroup head |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5565 | */ |
| 5566 | WL_EXPORT bool |
| 5567 | weston_head_is_device_changed(struct weston_head *head) |
| 5568 | { |
| 5569 | return head->device_changed; |
| 5570 | } |
| 5571 | |
Philipp Zabel | c18ffd3 | 2018-08-30 17:38:03 +0200 | [diff] [blame] | 5572 | /** Does the head represent a non-desktop display? |
| 5573 | * |
| 5574 | * \param head The head to query. |
| 5575 | * \return True if the device is a non-desktop display. |
| 5576 | * |
| 5577 | * Non-desktop heads are not attached to outputs by default. |
| 5578 | * This stops weston from extending the desktop onto head mounted displays. |
| 5579 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5580 | * \ingroup head |
Philipp Zabel | c18ffd3 | 2018-08-30 17:38:03 +0200 | [diff] [blame] | 5581 | */ |
| 5582 | WL_EXPORT bool |
| 5583 | weston_head_is_non_desktop(struct weston_head *head) |
| 5584 | { |
| 5585 | return head->non_desktop; |
| 5586 | } |
| 5587 | |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5588 | /** Acknowledge device information change |
| 5589 | * |
| 5590 | * \param head The head to acknowledge. |
| 5591 | * |
| 5592 | * Clears the device changed flag on this head. When a compositor has processed |
| 5593 | * device information, it should call this to be able to notice further |
| 5594 | * changes. |
| 5595 | * |
| 5596 | * \sa weston_head_is_device_changed |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5597 | * \ingroup head |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5598 | */ |
| 5599 | WL_EXPORT void |
| 5600 | weston_head_reset_device_changed(struct weston_head *head) |
| 5601 | { |
| 5602 | head->device_changed = false; |
| 5603 | } |
| 5604 | |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5605 | /** Get the name of a head |
| 5606 | * |
| 5607 | * \param head The head to query. |
| 5608 | * \return The head's name, not NULL. |
| 5609 | * |
| 5610 | * The name depends on the backend. The DRM backend uses connector names, |
| 5611 | * other backends may use hardcoded names or user-given names. |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5612 | * |
| 5613 | * \ingroup head |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5614 | */ |
| 5615 | WL_EXPORT const char * |
| 5616 | weston_head_get_name(struct weston_head *head) |
| 5617 | { |
| 5618 | return head->name; |
| 5619 | } |
| 5620 | |
| 5621 | /** Get the output the head is attached to |
| 5622 | * |
| 5623 | * \param head The head to query. |
| 5624 | * \return The output the head is attached to, or NULL if detached. |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5625 | * \ingroup head |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5626 | */ |
| 5627 | WL_EXPORT struct weston_output * |
| 5628 | weston_head_get_output(struct weston_head *head) |
| 5629 | { |
| 5630 | return head->output; |
| 5631 | } |
| 5632 | |
Pekka Paalanen | 2e1bedb | 2017-10-10 11:21:58 +0300 | [diff] [blame] | 5633 | /** Add destroy callback for a head |
| 5634 | * |
| 5635 | * \param head The head to watch for. |
| 5636 | * \param listener The listener to add. The \c notify member must be set. |
| 5637 | * |
| 5638 | * Heads may get destroyed for various reasons by the backends. If a head is |
| 5639 | * attached to an output, the compositor should listen for head destruction |
| 5640 | * and reconfigure or destroy the output if necessary. |
| 5641 | * |
| 5642 | * The destroy callbacks will be called on weston_head destruction before any |
| 5643 | * automatic detaching from an associated weston_output and before any |
| 5644 | * weston_head information is lost. |
| 5645 | * |
| 5646 | * The \c data argument to the notify callback is the weston_head being |
| 5647 | * destroyed. |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5648 | * |
| 5649 | * \ingroup head |
Pekka Paalanen | 2e1bedb | 2017-10-10 11:21:58 +0300 | [diff] [blame] | 5650 | */ |
| 5651 | WL_EXPORT void |
| 5652 | weston_head_add_destroy_listener(struct weston_head *head, |
| 5653 | struct wl_listener *listener) |
| 5654 | { |
| 5655 | wl_signal_add(&head->destroy_signal, listener); |
| 5656 | } |
| 5657 | |
| 5658 | /** Look up destroy listener for a head |
| 5659 | * |
| 5660 | * \param head The head to query. |
| 5661 | * \param notify The notify function used used for the added destroy listener. |
| 5662 | * \return The listener, or NULL if not found. |
| 5663 | * |
| 5664 | * This looks up the previously added destroy listener struct based on the |
| 5665 | * notify function it has. The listener can be used to access user data |
| 5666 | * through \c container_of(). |
| 5667 | * |
| 5668 | * \sa wl_signal_get() |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5669 | * \ingroup head |
Pekka Paalanen | 2e1bedb | 2017-10-10 11:21:58 +0300 | [diff] [blame] | 5670 | */ |
| 5671 | WL_EXPORT struct wl_listener * |
| 5672 | weston_head_get_destroy_listener(struct weston_head *head, |
| 5673 | wl_notify_func_t notify) |
| 5674 | { |
| 5675 | return wl_signal_get(&head->destroy_signal, notify); |
| 5676 | } |
| 5677 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 5678 | /* 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] | 5679 | static void |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 5680 | weston_compositor_reflow_outputs(struct weston_compositor *compositor, |
| 5681 | struct weston_output *resized_output, int delta_width) |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 5682 | { |
| 5683 | struct weston_output *output; |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 5684 | bool start_resizing = false; |
| 5685 | |
| 5686 | if (!delta_width) |
| 5687 | return; |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 5688 | |
| 5689 | wl_list_for_each(output, &compositor->output_list, link) { |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 5690 | if (output == resized_output) { |
| 5691 | start_resizing = true; |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 5692 | continue; |
| 5693 | } |
| 5694 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 5695 | if (start_resizing) { |
| 5696 | weston_output_move(output, output->x + delta_width, output->y); |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 5697 | output->dirty = 1; |
| 5698 | } |
| 5699 | } |
| 5700 | } |
| 5701 | |
Pekka Paalanen | d72bad2 | 2017-03-29 17:01:41 +0300 | [diff] [blame] | 5702 | static void |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5703 | weston_output_update_matrix(struct weston_output *output) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 5704 | { |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 5705 | float magnification; |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 5706 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5707 | weston_matrix_init(&output->matrix); |
Jason Ekstrand | fb23df7 | 2014-10-16 10:55:21 -0500 | [diff] [blame] | 5708 | weston_matrix_translate(&output->matrix, -output->x, -output->y, 0); |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 5709 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5710 | if (output->zoom.active) { |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 5711 | magnification = 1 / (1 - output->zoom.spring_z.current); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5712 | weston_output_update_zoom(output); |
Neil Roberts | 1e40a7e | 2014-04-25 13:19:37 +0100 | [diff] [blame] | 5713 | weston_matrix_translate(&output->matrix, -output->zoom.trans_x, |
Jason Ekstrand | fb23df7 | 2014-10-16 10:55:21 -0500 | [diff] [blame] | 5714 | -output->zoom.trans_y, 0); |
Neil Roberts | 1e40a7e | 2014-04-25 13:19:37 +0100 | [diff] [blame] | 5715 | weston_matrix_scale(&output->matrix, magnification, |
| 5716 | magnification, 1.0); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5717 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 5718 | |
Jason Ekstrand | fb23df7 | 2014-10-16 10:55:21 -0500 | [diff] [blame] | 5719 | switch (output->transform) { |
| 5720 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 5721 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 5722 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 5723 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 5724 | weston_matrix_translate(&output->matrix, -output->width, 0, 0); |
| 5725 | weston_matrix_scale(&output->matrix, -1, 1, 1); |
| 5726 | break; |
| 5727 | } |
| 5728 | |
| 5729 | switch (output->transform) { |
| 5730 | default: |
| 5731 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 5732 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 5733 | break; |
| 5734 | case WL_OUTPUT_TRANSFORM_90: |
| 5735 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 5736 | weston_matrix_translate(&output->matrix, 0, -output->height, 0); |
| 5737 | weston_matrix_rotate_xy(&output->matrix, 0, 1); |
| 5738 | break; |
| 5739 | case WL_OUTPUT_TRANSFORM_180: |
| 5740 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 5741 | weston_matrix_translate(&output->matrix, |
| 5742 | -output->width, -output->height, 0); |
| 5743 | weston_matrix_rotate_xy(&output->matrix, -1, 0); |
| 5744 | break; |
| 5745 | case WL_OUTPUT_TRANSFORM_270: |
| 5746 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 5747 | weston_matrix_translate(&output->matrix, -output->width, 0, 0); |
| 5748 | weston_matrix_rotate_xy(&output->matrix, 0, -1); |
| 5749 | break; |
| 5750 | } |
| 5751 | |
| 5752 | if (output->current_scale != 1) |
| 5753 | weston_matrix_scale(&output->matrix, |
| 5754 | output->current_scale, |
| 5755 | output->current_scale, 1); |
Neil Roberts | 6c3b01f | 2014-05-06 19:04:15 +0100 | [diff] [blame] | 5756 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5757 | output->dirty = 0; |
Derek Foreman | c002321 | 2015-03-24 11:36:13 -0500 | [diff] [blame] | 5758 | |
| 5759 | weston_matrix_invert(&output->inverse_matrix, &output->matrix); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5760 | } |
| 5761 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 5762 | static void |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 5763 | 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] | 5764 | { |
| 5765 | output->transform = transform; |
Pekka Paalanen | 59987fa | 2016-04-26 15:50:59 +0300 | [diff] [blame] | 5766 | output->native_scale = scale; |
| 5767 | output->current_scale = scale; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 5768 | |
Pekka Paalanen | 59987fa | 2016-04-26 15:50:59 +0300 | [diff] [blame] | 5769 | convert_size_by_transform_scale(&output->width, &output->height, |
| 5770 | output->current_mode->width, |
| 5771 | output->current_mode->height, |
| 5772 | transform, scale); |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 5773 | } |
| 5774 | |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5775 | static void |
| 5776 | weston_output_init_geometry(struct weston_output *output, int x, int y) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5777 | { |
| 5778 | output->x = x; |
| 5779 | output->y = y; |
| 5780 | |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 5781 | pixman_region32_fini(&output->region); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5782 | pixman_region32_init_rect(&output->region, x, y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 5783 | output->width, |
| 5784 | output->height); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 5785 | } |
| 5786 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 5787 | /** |
| 5788 | * \ingroup output |
| 5789 | */ |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5790 | WL_EXPORT void |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5791 | weston_output_move(struct weston_output *output, int x, int y) |
| 5792 | { |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5793 | struct weston_head *head; |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5794 | struct wl_resource *resource; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5795 | int ver; |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5796 | |
| 5797 | output->move_x = x - output->x; |
| 5798 | output->move_y = y - output->y; |
| 5799 | |
| 5800 | if (output->move_x == 0 && output->move_y == 0) |
| 5801 | return; |
| 5802 | |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5803 | weston_output_init_geometry(output, x, y); |
| 5804 | |
| 5805 | output->dirty = 1; |
| 5806 | |
| 5807 | /* Move views on this output. */ |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 5808 | wl_signal_emit(&output->compositor->output_moved_signal, output); |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5809 | |
| 5810 | /* Notify clients of the change for output position. */ |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5811 | wl_list_for_each(head, &output->head_list, output_link) { |
| 5812 | wl_resource_for_each(resource, &head->resource_list) { |
| 5813 | wl_output_send_geometry(resource, |
| 5814 | output->x, |
| 5815 | output->y, |
| 5816 | head->mm_width, |
| 5817 | head->mm_height, |
| 5818 | head->subpixel, |
| 5819 | head->make, |
| 5820 | head->model, |
| 5821 | output->transform); |
Quanxian Wang | b2c8636 | 2014-03-14 09:16:25 +0800 | [diff] [blame] | 5822 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5823 | ver = wl_resource_get_version(resource); |
| 5824 | if (ver >= WL_OUTPUT_DONE_SINCE_VERSION) |
| 5825 | wl_output_send_done(resource); |
| 5826 | } |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 5827 | |
| 5828 | wl_resource_for_each(resource, &head->xdg_output_resource_list) { |
| 5829 | zxdg_output_v1_send_logical_position(resource, |
| 5830 | output->x, |
| 5831 | output->y); |
| 5832 | zxdg_output_v1_send_done(resource); |
| 5833 | } |
Quanxian Wang | b2c8636 | 2014-03-14 09:16:25 +0800 | [diff] [blame] | 5834 | } |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5835 | } |
| 5836 | |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5837 | /** Signal that a pending output is taken into use. |
| 5838 | * |
| 5839 | * Removes the output from the pending list and adds it to the compositor's |
| 5840 | * list of enabled outputs. The output created signal is emitted. |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5841 | * |
Pekka Paalanen | 2210ad0 | 2017-03-30 15:48:06 +0300 | [diff] [blame] | 5842 | * The output gets an internal ID assigned, and the wl_output global is |
| 5843 | * created. |
Pekka Paalanen | 3d2d497 | 2017-03-30 15:19:45 +0300 | [diff] [blame] | 5844 | * |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5845 | * \param compositor The compositor instance. |
| 5846 | * \param output The output to be added. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5847 | * |
| 5848 | * \internal |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 5849 | * \ingroup compositor |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5850 | */ |
Pekka Paalanen | f9681b5 | 2017-03-29 16:58:48 +0300 | [diff] [blame] | 5851 | static void |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5852 | weston_compositor_add_output(struct weston_compositor *compositor, |
| 5853 | struct weston_output *output) |
| 5854 | { |
Armin Krezović | e540384 | 2016-08-05 15:28:29 +0200 | [diff] [blame] | 5855 | struct weston_view *view, *next; |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 5856 | struct weston_head *head; |
Armin Krezović | e540384 | 2016-08-05 15:28:29 +0200 | [diff] [blame] | 5857 | |
Pekka Paalanen | 7f340ff | 2017-03-30 14:56:22 +0300 | [diff] [blame] | 5858 | assert(!output->enabled); |
Pekka Paalanen | 3d2d497 | 2017-03-30 15:19:45 +0300 | [diff] [blame] | 5859 | |
| 5860 | /* Verify we haven't reached the limit of 32 available output IDs */ |
| 5861 | assert(ffs(~compositor->output_id_pool) > 0); |
| 5862 | |
| 5863 | /* Invert the output id pool and look for the lowest numbered |
| 5864 | * switch (the least significant bit). Take that bit's position |
| 5865 | * as our ID, and mark it used in the compositor's output_id_pool. |
| 5866 | */ |
| 5867 | output->id = ffs(~compositor->output_id_pool) - 1; |
| 5868 | compositor->output_id_pool |= 1u << output->id; |
| 5869 | |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5870 | wl_list_remove(&output->link); |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5871 | wl_list_insert(compositor->output_list.prev, &output->link); |
Pekka Paalanen | 7f340ff | 2017-03-30 14:56:22 +0300 | [diff] [blame] | 5872 | output->enabled = true; |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5873 | |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 5874 | wl_list_for_each(head, &output->head_list, output_link) |
| 5875 | weston_head_add_global(head); |
Pekka Paalanen | 2210ad0 | 2017-03-30 15:48:06 +0300 | [diff] [blame] | 5876 | |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5877 | wl_signal_emit(&compositor->output_created_signal, output); |
Armin Krezović | e540384 | 2016-08-05 15:28:29 +0200 | [diff] [blame] | 5878 | |
| 5879 | wl_list_for_each_safe(view, next, &compositor->view_list, link) |
| 5880 | weston_view_geometry_dirty(view); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 5881 | } |
| 5882 | |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5883 | /** Transform device coordinates into global coordinates |
| 5884 | * |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 5885 | * \param output the weston_output object |
| 5886 | * \param[in] device_x X coordinate in device units. |
| 5887 | * \param[in] device_y Y coordinate in device units. |
| 5888 | * \param[out] x X coordinate in the global space. |
| 5889 | * \param[out] y Y coordinate in the global space. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5890 | * |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 5891 | * Transforms coordinates from the device coordinate space (physical pixel |
| 5892 | * units) to the global coordinate space (logical pixel units). This takes |
| 5893 | * into account output transform and scale. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5894 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 5895 | * \ingroup output |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5896 | * \internal |
| 5897 | */ |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 5898 | WL_EXPORT void |
| 5899 | weston_output_transform_coordinate(struct weston_output *output, |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 5900 | double device_x, double device_y, |
| 5901 | double *x, double *y) |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 5902 | { |
Derek Foreman | 0f67941 | 2014-10-02 13:41:17 -0500 | [diff] [blame] | 5903 | struct weston_vector p = { { |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 5904 | device_x, |
| 5905 | device_y, |
Derek Foreman | 0f67941 | 2014-10-02 13:41:17 -0500 | [diff] [blame] | 5906 | 0.0, |
| 5907 | 1.0 } }; |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 5908 | |
Derek Foreman | 67a18b9 | 2015-03-24 11:36:14 -0500 | [diff] [blame] | 5909 | weston_matrix_transform(&output->inverse_matrix, &p); |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 5910 | |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 5911 | *x = p.f[0] / p.f[3]; |
| 5912 | *y = p.f[1] / p.f[3]; |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 5913 | } |
| 5914 | |
Pekka Paalanen | e6ac4fc | 2017-03-29 16:07:34 +0300 | [diff] [blame] | 5915 | /** Removes output from compositor's list of enabled outputs |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5916 | * |
| 5917 | * \param output The weston_output object that is being removed. |
| 5918 | * |
Pekka Paalanen | e6ac4fc | 2017-03-29 16:07:34 +0300 | [diff] [blame] | 5919 | * The following happens: |
| 5920 | * |
| 5921 | * - The output assignments of all views in the current scenegraph are |
| 5922 | * recomputed. |
| 5923 | * |
| 5924 | * - Presentation feedback is discarded. |
| 5925 | * |
| 5926 | * - Compositor is notified that outputs were changed and |
| 5927 | * applies the necessary changes to re-layout outputs. |
| 5928 | * |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5929 | * - The output is put back in the pending outputs list. |
| 5930 | * |
Pekka Paalanen | e6ac4fc | 2017-03-29 16:07:34 +0300 | [diff] [blame] | 5931 | * - Signal is emitted to notify all users of the weston_output |
| 5932 | * object that the output is being destroyed. |
| 5933 | * |
| 5934 | * - wl_output protocol objects referencing this weston_output |
Pekka Paalanen | 2210ad0 | 2017-03-30 15:48:06 +0300 | [diff] [blame] | 5935 | * are made inert, and the wl_output global is removed. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5936 | * |
Pekka Paalanen | 3d2d497 | 2017-03-30 15:19:45 +0300 | [diff] [blame] | 5937 | * - The output's internal ID is released. |
| 5938 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 5939 | * \ingroup compositor |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5940 | * \internal |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5941 | */ |
| 5942 | static void |
| 5943 | weston_compositor_remove_output(struct weston_output *output) |
| 5944 | { |
Pekka Paalanen | bccda71 | 2017-03-29 16:16:04 +0300 | [diff] [blame] | 5945 | struct weston_compositor *compositor = output->compositor; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5946 | struct weston_view *view; |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 5947 | struct weston_head *head; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5948 | |
| 5949 | assert(output->destroying); |
Pekka Paalanen | 7f340ff | 2017-03-30 14:56:22 +0300 | [diff] [blame] | 5950 | assert(output->enabled); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5951 | |
Pekka Paalanen | bccda71 | 2017-03-29 16:16:04 +0300 | [diff] [blame] | 5952 | wl_list_for_each(view, &compositor->view_list, link) { |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5953 | if (view->output_mask & (1u << output->id)) |
| 5954 | weston_view_assign_output(view); |
| 5955 | } |
| 5956 | |
| 5957 | weston_presentation_feedback_discard_list(&output->feedback_list); |
| 5958 | |
Pekka Paalanen | 9711fd9 | 2018-06-21 14:26:18 +0300 | [diff] [blame] | 5959 | weston_compositor_reflow_outputs(compositor, output, -output->width); |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5960 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5961 | wl_list_remove(&output->link); |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5962 | wl_list_insert(compositor->pending_output_list.prev, &output->link); |
Pekka Paalanen | 7f340ff | 2017-03-30 14:56:22 +0300 | [diff] [blame] | 5963 | output->enabled = false; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5964 | |
Pekka Paalanen | bccda71 | 2017-03-29 16:16:04 +0300 | [diff] [blame] | 5965 | wl_signal_emit(&compositor->output_destroyed_signal, output); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5966 | wl_signal_emit(&output->destroy_signal, output); |
| 5967 | |
Pekka Paalanen | d9dcc6d | 2017-12-04 15:28:13 +0200 | [diff] [blame] | 5968 | wl_list_for_each(head, &output->head_list, output_link) |
| 5969 | weston_head_remove_global(head); |
Pekka Paalanen | 3d2d497 | 2017-03-30 15:19:45 +0300 | [diff] [blame] | 5970 | |
| 5971 | compositor->output_id_pool &= ~(1u << output->id); |
| 5972 | output->id = 0xffffffff; /* invalid */ |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5973 | } |
| 5974 | |
| 5975 | /** Sets the output scale for a given output. |
| 5976 | * |
| 5977 | * \param output The weston_output object that the scale is set for. |
| 5978 | * \param scale Scale factor for the given output. |
| 5979 | * |
| 5980 | * It only supports setting scale for an output that |
| 5981 | * is not enabled and it can only be ran once. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5982 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 5983 | * \ingroup ouput |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5984 | */ |
| 5985 | WL_EXPORT void |
| 5986 | weston_output_set_scale(struct weston_output *output, |
| 5987 | int32_t scale) |
| 5988 | { |
| 5989 | /* We can only set scale on a disabled output */ |
| 5990 | assert(!output->enabled); |
| 5991 | |
| 5992 | /* We only want to set scale once */ |
| 5993 | assert(!output->scale); |
| 5994 | |
| 5995 | output->scale = scale; |
| 5996 | } |
| 5997 | |
| 5998 | /** Sets the output transform for a given output. |
| 5999 | * |
| 6000 | * \param output The weston_output object that the transform is set for. |
| 6001 | * \param transform Transform value for the given output. |
| 6002 | * |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6003 | * Refer to wl_output::transform section located at |
| 6004 | * https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_output |
| 6005 | * for list of values that can be passed to this function. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6006 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6007 | * \ingroup output |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6008 | */ |
| 6009 | WL_EXPORT void |
| 6010 | weston_output_set_transform(struct weston_output *output, |
| 6011 | uint32_t transform) |
| 6012 | { |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 6013 | struct weston_pointer_motion_event ev; |
| 6014 | struct wl_resource *resource; |
| 6015 | struct weston_seat *seat; |
| 6016 | pixman_region32_t old_region; |
| 6017 | int mid_x, mid_y; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 6018 | struct weston_head *head; |
| 6019 | int ver; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6020 | |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 6021 | if (!output->enabled && output->transform == UINT32_MAX) { |
| 6022 | output->transform = transform; |
| 6023 | return; |
| 6024 | } |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6025 | |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 6026 | weston_output_transform_scale_init(output, transform, output->scale); |
| 6027 | |
| 6028 | pixman_region32_init(&old_region); |
| 6029 | pixman_region32_copy(&old_region, &output->region); |
| 6030 | |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 6031 | weston_output_init_geometry(output, output->x, output->y); |
| 6032 | |
| 6033 | output->dirty = 1; |
| 6034 | |
| 6035 | /* Notify clients of the change for output transform. */ |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 6036 | wl_list_for_each(head, &output->head_list, output_link) { |
| 6037 | wl_resource_for_each(resource, &head->resource_list) { |
| 6038 | wl_output_send_geometry(resource, |
| 6039 | output->x, |
| 6040 | output->y, |
| 6041 | head->mm_width, |
| 6042 | head->mm_height, |
| 6043 | head->subpixel, |
| 6044 | head->make, |
| 6045 | head->model, |
| 6046 | output->transform); |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 6047 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 6048 | ver = wl_resource_get_version(resource); |
| 6049 | if (ver >= WL_OUTPUT_DONE_SINCE_VERSION) |
| 6050 | wl_output_send_done(resource); |
| 6051 | } |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 6052 | wl_resource_for_each(resource, &head->xdg_output_resource_list) { |
| 6053 | zxdg_output_v1_send_logical_position(resource, |
| 6054 | output->x, |
| 6055 | output->y); |
| 6056 | zxdg_output_v1_send_logical_size(resource, |
| 6057 | output->width, |
| 6058 | output->height); |
| 6059 | zxdg_output_v1_send_done(resource); |
| 6060 | } |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 6061 | } |
| 6062 | |
| 6063 | /* we must ensure that pointers are inside output, otherwise they disappear */ |
| 6064 | mid_x = output->x + output->width / 2; |
| 6065 | mid_y = output->y + output->height / 2; |
| 6066 | |
| 6067 | ev.mask = WESTON_POINTER_MOTION_ABS; |
| 6068 | ev.x = wl_fixed_to_double(wl_fixed_from_int(mid_x)); |
| 6069 | ev.y = wl_fixed_to_double(wl_fixed_from_int(mid_y)); |
| 6070 | |
| 6071 | wl_list_for_each(seat, &output->compositor->seat_list, link) { |
| 6072 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 6073 | |
| 6074 | if (pointer && pixman_region32_contains_point(&old_region, |
| 6075 | wl_fixed_to_int(pointer->x), |
| 6076 | wl_fixed_to_int(pointer->y), |
| 6077 | NULL)) |
| 6078 | weston_pointer_move(pointer, &ev); |
| 6079 | } |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6080 | } |
| 6081 | |
| 6082 | /** Initializes a weston_output object with enough data so |
| 6083 | ** an output can be configured. |
| 6084 | * |
| 6085 | * \param output The weston_output object to initialize |
| 6086 | * \param compositor The compositor instance. |
Pekka Paalanen | 26ac2e1 | 2017-04-03 13:18:13 +0300 | [diff] [blame] | 6087 | * \param name Name for the output (the string is copied). |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6088 | * |
| 6089 | * Sets initial values for fields that are expected to be |
| 6090 | * configured either by compositors or backends. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6091 | * |
Pekka Paalanen | 26ac2e1 | 2017-04-03 13:18:13 +0300 | [diff] [blame] | 6092 | * The name is used in logs, and can be used by compositors as a configuration |
| 6093 | * identifier. |
| 6094 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6095 | * \ingroup output |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6096 | * \internal |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6097 | */ |
| 6098 | WL_EXPORT void |
Armin Krezović | 4008740 | 2016-09-30 14:11:12 +0200 | [diff] [blame] | 6099 | weston_output_init(struct weston_output *output, |
Pekka Paalanen | 26ac2e1 | 2017-04-03 13:18:13 +0300 | [diff] [blame] | 6100 | struct weston_compositor *compositor, |
| 6101 | const char *name) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6102 | { |
| 6103 | output->compositor = compositor; |
| 6104 | output->destroying = 0; |
Pekka Paalanen | 26ac2e1 | 2017-04-03 13:18:13 +0300 | [diff] [blame] | 6105 | output->name = strdup(name); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6106 | wl_list_init(&output->link); |
Pekka Paalanen | 37b7c6e | 2017-11-07 10:15:01 +0200 | [diff] [blame] | 6107 | wl_signal_init(&output->user_destroy_signal); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6108 | output->enabled = false; |
Ankit Nautiyal | 2690a77 | 2019-03-25 17:57:59 +0530 | [diff] [blame] | 6109 | output->desired_protection = WESTON_HDCP_DISABLE; |
Ankit Nautiyal | 2844f8e | 2019-04-03 10:14:59 +0530 | [diff] [blame] | 6110 | output->allow_protection = true; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6111 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 6112 | wl_list_init(&output->head_list); |
| 6113 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6114 | /* Add some (in)sane defaults which can be used |
| 6115 | * for checking if an output was properly configured |
| 6116 | */ |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6117 | output->scale = 0; |
| 6118 | /* Can't use -1 on uint32_t and 0 is valid enum value */ |
| 6119 | output->transform = UINT32_MAX; |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 6120 | |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 6121 | pixman_region32_init(&output->region); |
Pekka Paalanen | 4270414 | 2017-09-06 16:47:52 +0300 | [diff] [blame] | 6122 | wl_list_init(&output->mode_list); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6123 | } |
| 6124 | |
| 6125 | /** Adds weston_output object to pending output list. |
| 6126 | * |
| 6127 | * \param output The weston_output object to add |
| 6128 | * \param compositor The compositor instance. |
| 6129 | * |
Pekka Paalanen | ae6d35d | 2017-08-16 12:07:14 +0300 | [diff] [blame] | 6130 | * The opposite of this operation is built into weston_output_release(). |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6131 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 6132 | * \ingroup compositor |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6133 | * \internal |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6134 | */ |
| 6135 | WL_EXPORT void |
| 6136 | weston_compositor_add_pending_output(struct weston_output *output, |
| 6137 | struct weston_compositor *compositor) |
| 6138 | { |
Pekka Paalanen | e952a01 | 2017-03-29 17:14:00 +0300 | [diff] [blame] | 6139 | assert(output->disable); |
| 6140 | assert(output->enable); |
| 6141 | |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 6142 | wl_list_remove(&output->link); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6143 | wl_list_insert(compositor->pending_output_list.prev, &output->link); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6144 | } |
| 6145 | |
Pekka Paalanen | 3e8f201 | 2017-11-02 14:03:11 +0200 | [diff] [blame] | 6146 | /** Create a string with the attached heads' names. |
| 6147 | * |
| 6148 | * The string must be free()'d. |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6149 | * |
| 6150 | * \ingroup output |
Pekka Paalanen | 3e8f201 | 2017-11-02 14:03:11 +0200 | [diff] [blame] | 6151 | */ |
| 6152 | static char * |
| 6153 | weston_output_create_heads_string(struct weston_output *output) |
| 6154 | { |
| 6155 | FILE *fp; |
| 6156 | char *str = NULL; |
| 6157 | size_t size = 0; |
| 6158 | struct weston_head *head; |
| 6159 | const char *sep = ""; |
| 6160 | |
| 6161 | fp = open_memstream(&str, &size); |
| 6162 | if (!fp) |
| 6163 | return NULL; |
| 6164 | |
| 6165 | wl_list_for_each(head, &output->head_list, output_link) { |
| 6166 | fprintf(fp, "%s%s", sep, head->name); |
| 6167 | sep = ", "; |
| 6168 | } |
| 6169 | fclose(fp); |
| 6170 | |
| 6171 | return str; |
| 6172 | } |
| 6173 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6174 | /** Constructs a weston_output object that can be used by the compositor. |
| 6175 | * |
Pekka Paalanen | cc201e4 | 2017-03-30 15:11:25 +0300 | [diff] [blame] | 6176 | * \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] | 6177 | * be enabled already. Must have at least one head attached. |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6178 | * |
| 6179 | * Output coordinates are calculated and each new output is by default |
| 6180 | * assigned to the right of previous one. |
| 6181 | * |
| 6182 | * Sets up the transformation, zoom, and geometry of the output using |
| 6183 | * the properties that need to be configured by the compositor. |
| 6184 | * |
| 6185 | * Establishes a repaint timer for the output with the relevant display |
| 6186 | * object's event loop. See output_repaint_timer_handler(). |
| 6187 | * |
| 6188 | * The output is assigned an ID. Weston can support up to 32 distinct |
| 6189 | * outputs, with IDs numbered from 0-31; the compositor's output_id_pool |
| 6190 | * is referred to and used to find the first available ID number, and |
| 6191 | * then this ID is marked as used in output_id_pool. |
| 6192 | * |
| 6193 | * The output is also assigned a Wayland global with the wl_output |
| 6194 | * external interface. |
| 6195 | * |
| 6196 | * Backend specific function is called to set up the output output. |
| 6197 | * |
| 6198 | * Output is added to the compositor's output list |
| 6199 | * |
| 6200 | * If the backend specific function fails, the weston_output object |
| 6201 | * is returned to a state it was before calling this function and |
| 6202 | * is added to the compositor's pending_output_list in case it needs |
| 6203 | * to be reconfigured or just so it can be destroyed at shutdown. |
| 6204 | * |
| 6205 | * 0 is returned on success, -1 on failure. |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6206 | * |
| 6207 | * \ingroup output |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6208 | */ |
| 6209 | WL_EXPORT int |
| 6210 | weston_output_enable(struct weston_output *output) |
| 6211 | { |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 6212 | struct weston_compositor *c = output->compositor; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6213 | struct weston_output *iterator; |
Pekka Paalanen | ec25b0a | 2017-08-24 16:08:49 +0300 | [diff] [blame] | 6214 | struct weston_head *head; |
Pekka Paalanen | 3e8f201 | 2017-11-02 14:03:11 +0200 | [diff] [blame] | 6215 | char *head_names; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6216 | int x = 0, y = 0; |
| 6217 | |
Pekka Paalanen | cc201e4 | 2017-03-30 15:11:25 +0300 | [diff] [blame] | 6218 | if (output->enabled) { |
| 6219 | weston_log("Error: attempt to enable an enabled output '%s'\n", |
| 6220 | output->name); |
| 6221 | return -1; |
| 6222 | } |
| 6223 | |
Pekka Paalanen | ddce54d | 2017-08-23 16:00:21 +0300 | [diff] [blame] | 6224 | if (wl_list_empty(&output->head_list)) { |
| 6225 | weston_log("Error: cannot enable output '%s' without heads.\n", |
| 6226 | output->name); |
| 6227 | return -1; |
| 6228 | } |
| 6229 | |
Pekka Paalanen | 586e1ac | 2017-09-14 16:17:59 +0300 | [diff] [blame] | 6230 | if (wl_list_empty(&output->mode_list) || !output->current_mode) { |
| 6231 | weston_log("Error: no video mode for output '%s'.\n", |
| 6232 | output->name); |
| 6233 | return -1; |
| 6234 | } |
| 6235 | |
Pekka Paalanen | ec25b0a | 2017-08-24 16:08:49 +0300 | [diff] [blame] | 6236 | wl_list_for_each(head, &output->head_list, output_link) { |
| 6237 | assert(head->make); |
| 6238 | assert(head->model); |
| 6239 | } |
| 6240 | |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 6241 | iterator = container_of(c->output_list.prev, |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6242 | struct weston_output, link); |
| 6243 | |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 6244 | if (!wl_list_empty(&c->output_list)) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6245 | x = iterator->x + iterator->width; |
| 6246 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6247 | /* Make sure the scale is set up */ |
| 6248 | assert(output->scale); |
| 6249 | |
| 6250 | /* Make sure we have a transform set */ |
| 6251 | assert(output->transform != UINT32_MAX); |
| 6252 | |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 6253 | output->x = x; |
| 6254 | output->y = y; |
| 6255 | output->dirty = 1; |
| 6256 | output->original_scale = output->scale; |
| 6257 | |
Marius Vlad | 3a2f829 | 2019-11-04 17:53:46 +0200 | [diff] [blame] | 6258 | wl_signal_init(&output->frame_signal); |
| 6259 | wl_signal_init(&output->destroy_signal); |
| 6260 | |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 6261 | weston_output_transform_scale_init(output, output->transform, output->scale); |
| 6262 | weston_output_init_zoom(output); |
| 6263 | |
| 6264 | weston_output_init_geometry(output, x, y); |
| 6265 | weston_output_damage(output); |
| 6266 | |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 6267 | wl_list_init(&output->animation_list); |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 6268 | wl_list_init(&output->feedback_list); |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 6269 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6270 | /* Enable the output (set up the crtc or create a |
| 6271 | * window representing the output, set up the |
| 6272 | * renderer, etc) |
| 6273 | */ |
| 6274 | if (output->enable(output) < 0) { |
| 6275 | weston_log("Enabling output \"%s\" failed.\n", output->name); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6276 | return -1; |
| 6277 | } |
| 6278 | |
| 6279 | weston_compositor_add_output(output->compositor, output); |
| 6280 | |
Pekka Paalanen | 3e8f201 | 2017-11-02 14:03:11 +0200 | [diff] [blame] | 6281 | head_names = weston_output_create_heads_string(output); |
| 6282 | weston_log("Output '%s' enabled with head(s) %s\n", |
| 6283 | output->name, head_names); |
| 6284 | free(head_names); |
| 6285 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6286 | return 0; |
| 6287 | } |
| 6288 | |
| 6289 | /** Converts a weston_output object to a pending output state, so it |
| 6290 | ** can be configured again or destroyed. |
| 6291 | * |
| 6292 | * \param output The weston_output object that needs to be disabled. |
| 6293 | * |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6294 | * Calls a backend specific function to disable an output, in case |
| 6295 | * such function exists. |
| 6296 | * |
Pekka Paalanen | c65df64 | 2017-03-29 15:45:46 +0300 | [diff] [blame] | 6297 | * The backend specific disable function may choose to postpone the disabling |
| 6298 | * by returning a negative value, in which case this function returns early. |
| 6299 | * In that case the backend will guarantee the output will be disabled soon |
| 6300 | * by the backend calling this function again. One must not attempt to re-enable |
| 6301 | * the output until that happens. |
| 6302 | * |
| 6303 | * 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] | 6304 | * from weston's output_list (see weston_compositor_remove_output()) |
| 6305 | * and is returned to a state it was before weston_output_enable() |
| 6306 | * was ran (see weston_output_enable_undo()). |
| 6307 | * |
Pekka Paalanen | c65df64 | 2017-03-29 15:45:46 +0300 | [diff] [blame] | 6308 | * See weston_output_init() for more information on the |
| 6309 | * state output is returned to. |
Pekka Paalanen | cc201e4 | 2017-03-30 15:11:25 +0300 | [diff] [blame] | 6310 | * |
| 6311 | * If the output has never been enabled yet, this function can still be |
| 6312 | * called to ensure that the output is actually turned off rather than left |
| 6313 | * in the state it was discovered in. |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6314 | * |
| 6315 | * \ingroup output |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6316 | */ |
| 6317 | WL_EXPORT void |
| 6318 | weston_output_disable(struct weston_output *output) |
| 6319 | { |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6320 | /* Should we rename this? */ |
| 6321 | output->destroying = 1; |
| 6322 | |
Pekka Paalanen | c65df64 | 2017-03-29 15:45:46 +0300 | [diff] [blame] | 6323 | /* Disable is called unconditionally also for not-enabled outputs, |
| 6324 | * because at compositor start-up, if there is an output that is |
| 6325 | * already on but the compositor wants to turn it off, we have to |
| 6326 | * forward the turn-off to the backend so it knows to do it. |
| 6327 | * The backend cannot initially turn off everything, because it |
| 6328 | * would cause unnecessary mode-sets for all outputs the compositor |
| 6329 | * wants to be on. |
| 6330 | */ |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6331 | if (output->disable(output) < 0) |
| 6332 | return; |
| 6333 | |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 6334 | if (output->enabled) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6335 | weston_compositor_remove_output(output); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6336 | |
| 6337 | output->destroying = 0; |
| 6338 | } |
| 6339 | |
Pekka Paalanen | 8a8dcac | 2017-08-17 17:29:36 +0300 | [diff] [blame] | 6340 | /** Forces a synchronous call to heads_changed hook |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6341 | * |
| 6342 | * \param compositor The compositor instance |
Pekka Paalanen | 8a8dcac | 2017-08-17 17:29:36 +0300 | [diff] [blame] | 6343 | * |
| 6344 | * If there are new or changed heads, calls the heads_changed hook and |
| 6345 | * returns after the hook returns. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 6346 | * |
| 6347 | * \ingroup compositor |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6348 | */ |
| 6349 | WL_EXPORT void |
Pekka Paalanen | 8a8dcac | 2017-08-17 17:29:36 +0300 | [diff] [blame] | 6350 | weston_compositor_flush_heads_changed(struct weston_compositor *compositor) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6351 | { |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 6352 | if (compositor->heads_changed_source) { |
| 6353 | wl_event_source_remove(compositor->heads_changed_source); |
| 6354 | weston_compositor_call_heads_changed(compositor); |
| 6355 | } |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6356 | } |
| 6357 | |
Pekka Paalanen | 37b7c6e | 2017-11-07 10:15:01 +0200 | [diff] [blame] | 6358 | /** Add destroy callback for an output |
| 6359 | * |
| 6360 | * \param output The output to watch. |
| 6361 | * \param listener The listener to add. The \c notify member must be set. |
| 6362 | * |
| 6363 | * The listener callback will be called when user destroys an output. This |
| 6364 | * may be delayed by a backend in some cases. The main purpose of the |
| 6365 | * listener is to allow hooking up custom data to the output. The custom data |
| 6366 | * can be fetched via weston_output_get_destroy_listener() followed by |
| 6367 | * container_of(). |
| 6368 | * |
| 6369 | * The \c data argument to the notify callback is the weston_output being |
| 6370 | * destroyed. |
| 6371 | * |
| 6372 | * @note This is for the final destruction of an output, not when it gets |
| 6373 | * 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] | 6374 | * |
| 6375 | * \ingroup ouput |
Pekka Paalanen | 37b7c6e | 2017-11-07 10:15:01 +0200 | [diff] [blame] | 6376 | */ |
| 6377 | WL_EXPORT void |
| 6378 | weston_output_add_destroy_listener(struct weston_output *output, |
| 6379 | struct wl_listener *listener) |
| 6380 | { |
| 6381 | wl_signal_add(&output->user_destroy_signal, listener); |
| 6382 | } |
| 6383 | |
| 6384 | /** Look up destroy listener for an output |
| 6385 | * |
| 6386 | * \param output The output to query. |
| 6387 | * \param notify The notify function used used for the added destroy listener. |
| 6388 | * \return The listener, or NULL if not found. |
| 6389 | * |
| 6390 | * This looks up the previously added destroy listener struct based on the |
| 6391 | * notify function it has. The listener can be used to access user data |
| 6392 | * through \c container_of(). |
| 6393 | * |
| 6394 | * \sa wl_signal_get() weston_output_add_destroy_listener() |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6395 | * \ingroup output |
Pekka Paalanen | 37b7c6e | 2017-11-07 10:15:01 +0200 | [diff] [blame] | 6396 | */ |
| 6397 | WL_EXPORT struct wl_listener * |
| 6398 | weston_output_get_destroy_listener(struct weston_output *output, |
| 6399 | wl_notify_func_t notify) |
| 6400 | { |
| 6401 | return wl_signal_get(&output->user_destroy_signal, notify); |
| 6402 | } |
| 6403 | |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6404 | /** Uninitialize an output |
| 6405 | * |
| 6406 | * Removes the output from the list of enabled outputs if necessary, but |
| 6407 | * does not call the backend's output disable function. The output will no |
| 6408 | * longer be in the list of pending outputs either. |
| 6409 | * |
| 6410 | * All fields of weston_output become uninitialized, i.e. should not be used |
| 6411 | * anymore. The caller can free the memory after this. |
| 6412 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6413 | * \ingroup ouput |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6414 | * \internal |
| 6415 | */ |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6416 | WL_EXPORT void |
Pekka Paalanen | ae6d35d | 2017-08-16 12:07:14 +0300 | [diff] [blame] | 6417 | weston_output_release(struct weston_output *output) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6418 | { |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 6419 | struct weston_head *head, *tmp; |
| 6420 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6421 | output->destroying = 1; |
| 6422 | |
Pekka Paalanen | 37b7c6e | 2017-11-07 10:15:01 +0200 | [diff] [blame] | 6423 | wl_signal_emit(&output->user_destroy_signal, output); |
| 6424 | |
Pekka Paalanen | dcbcfc7 | 2017-10-26 14:33:59 +0300 | [diff] [blame] | 6425 | if (output->idle_repaint_source) |
| 6426 | wl_event_source_remove(output->idle_repaint_source); |
| 6427 | |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 6428 | if (output->enabled) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6429 | weston_compositor_remove_output(output); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6430 | |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 6431 | pixman_region32_fini(&output->region); |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 6432 | wl_list_remove(&output->link); |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 6433 | |
| 6434 | wl_list_for_each_safe(head, tmp, &output->head_list, output_link) |
| 6435 | weston_head_detach(head); |
| 6436 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6437 | free(output->name); |
| 6438 | } |
| 6439 | |
Pekka Paalanen | 1ae9d08 | 2017-11-02 14:11:53 +0200 | [diff] [blame] | 6440 | /** Find an output by its given name |
| 6441 | * |
| 6442 | * \param compositor The compositor to search in. |
| 6443 | * \param name The output name to search for. |
| 6444 | * \return An existing output with the given name, or NULL if not found. |
| 6445 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 6446 | * \ingroup compositor |
Pekka Paalanen | 1ae9d08 | 2017-11-02 14:11:53 +0200 | [diff] [blame] | 6447 | */ |
| 6448 | WL_EXPORT struct weston_output * |
| 6449 | weston_compositor_find_output_by_name(struct weston_compositor *compositor, |
| 6450 | const char *name) |
| 6451 | { |
| 6452 | struct weston_output *output; |
| 6453 | |
| 6454 | wl_list_for_each(output, &compositor->output_list, link) |
| 6455 | if (strcmp(output->name, name) == 0) |
| 6456 | return output; |
| 6457 | |
| 6458 | wl_list_for_each(output, &compositor->pending_output_list, link) |
| 6459 | if (strcmp(output->name, name) == 0) |
| 6460 | return output; |
| 6461 | |
| 6462 | return NULL; |
| 6463 | } |
| 6464 | |
| 6465 | /** Create a named output |
| 6466 | * |
| 6467 | * \param compositor The compositor. |
| 6468 | * \param name The name for the output. |
| 6469 | * \return A new \c weston_output, or NULL on failure. |
| 6470 | * |
| 6471 | * This creates a new weston_output that starts with no heads attached. |
| 6472 | * |
| 6473 | * An output must be configured and it must have at least one head before |
| 6474 | * it can be enabled. |
| 6475 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 6476 | * \ingroup compositor |
Pekka Paalanen | 1ae9d08 | 2017-11-02 14:11:53 +0200 | [diff] [blame] | 6477 | */ |
| 6478 | WL_EXPORT struct weston_output * |
| 6479 | weston_compositor_create_output(struct weston_compositor *compositor, |
| 6480 | const char *name) |
| 6481 | { |
| 6482 | assert(compositor->backend->create_output); |
| 6483 | |
| 6484 | if (weston_compositor_find_output_by_name(compositor, name)) { |
| 6485 | weston_log("Warning: attempted to create an output with a " |
| 6486 | "duplicate name '%s'.\n", name); |
| 6487 | return NULL; |
| 6488 | } |
| 6489 | |
| 6490 | return compositor->backend->create_output(compositor, name); |
| 6491 | } |
| 6492 | |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 6493 | /** Create an output for an unused head |
| 6494 | * |
| 6495 | * \param compositor The compositor. |
| 6496 | * \param head The head to attach to the output. |
| 6497 | * \return A new \c weston_output, or NULL on failure. |
| 6498 | * |
| 6499 | * This creates a new weston_output that starts with the given head attached. |
| 6500 | * The output inherits the name of the head. The head must not be already |
| 6501 | * attached to another output. |
| 6502 | * |
| 6503 | * An output must be configured before it can be enabled. |
| 6504 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 6505 | * \ingroup compositor |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 6506 | */ |
| 6507 | WL_EXPORT struct weston_output * |
| 6508 | weston_compositor_create_output_with_head(struct weston_compositor *compositor, |
| 6509 | struct weston_head *head) |
| 6510 | { |
| 6511 | struct weston_output *output; |
| 6512 | |
Pekka Paalanen | 1ae9d08 | 2017-11-02 14:11:53 +0200 | [diff] [blame] | 6513 | output = weston_compositor_create_output(compositor, head->name); |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 6514 | if (!output) |
| 6515 | return NULL; |
| 6516 | |
| 6517 | if (weston_output_attach_head(output, head) < 0) { |
Pekka Paalanen | 42c0e14 | 2017-10-27 12:07:49 +0300 | [diff] [blame] | 6518 | weston_output_destroy(output); |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 6519 | return NULL; |
| 6520 | } |
| 6521 | |
| 6522 | return output; |
| 6523 | } |
| 6524 | |
| 6525 | /** Destroy an output |
| 6526 | * |
| 6527 | * \param output The output to destroy. |
| 6528 | * |
| 6529 | * The heads attached to the given output are detached and become unused again. |
| 6530 | * |
| 6531 | * It is not necessary to explicitly destroy all outputs at compositor exit. |
Marius Vlad | 413cda5 | 2019-08-23 17:42:40 +0300 | [diff] [blame] | 6532 | * weston_compositor_tear_down() will automatically destroy any remaining |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 6533 | * outputs. |
| 6534 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6535 | * \ingroup ouput |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 6536 | */ |
| 6537 | WL_EXPORT void |
| 6538 | weston_output_destroy(struct weston_output *output) |
| 6539 | { |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 6540 | output->destroy(output); |
| 6541 | } |
| 6542 | |
Pekka Paalanen | cf0a476 | 2017-04-04 16:36:07 +0300 | [diff] [blame] | 6543 | /** When you need a head... |
| 6544 | * |
| 6545 | * This function is a hack, used until all code has been converted to become |
| 6546 | * multi-head aware. |
| 6547 | * |
| 6548 | * \param output The weston_output whose head to get. |
| 6549 | * \return The first head in the output's list. |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6550 | * |
| 6551 | * \ingroup ouput |
Pekka Paalanen | cf0a476 | 2017-04-04 16:36:07 +0300 | [diff] [blame] | 6552 | */ |
| 6553 | WL_EXPORT struct weston_head * |
| 6554 | weston_output_get_first_head(struct weston_output *output) |
| 6555 | { |
| 6556 | if (wl_list_empty(&output->head_list)) |
| 6557 | return NULL; |
| 6558 | |
| 6559 | return container_of(output->head_list.next, |
| 6560 | struct weston_head, output_link); |
| 6561 | } |
| 6562 | |
Ankit Nautiyal | 2844f8e | 2019-04-03 10:14:59 +0530 | [diff] [blame] | 6563 | /** Allow/Disallow content-protection support for an output |
| 6564 | * |
| 6565 | * This function sets the allow_protection member for an output. Setting of |
| 6566 | * this field will allow the compositor to attempt content-protection for this |
| 6567 | * output, for a backend that supports the content-protection protocol. |
| 6568 | * |
| 6569 | * \param output The weston_output for whom the content-protection is to be |
| 6570 | * allowed. |
| 6571 | * \param allow_protection The bool value which is to be set. |
| 6572 | */ |
| 6573 | WL_EXPORT void |
| 6574 | weston_output_allow_protection(struct weston_output *output, |
| 6575 | bool allow_protection) |
| 6576 | { |
| 6577 | output->allow_protection = allow_protection; |
| 6578 | } |
| 6579 | |
Benjamin Franzke | 315b3dc | 2011-03-08 11:32:57 +0100 | [diff] [blame] | 6580 | static void |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 6581 | xdg_output_unlist(struct wl_resource *resource) |
| 6582 | { |
| 6583 | wl_list_remove(wl_resource_get_link(resource)); |
| 6584 | } |
| 6585 | |
| 6586 | static void |
| 6587 | xdg_output_destroy(struct wl_client *client, struct wl_resource *resource) |
| 6588 | { |
| 6589 | wl_resource_destroy(resource); |
| 6590 | } |
| 6591 | |
| 6592 | static const struct zxdg_output_v1_interface xdg_output_interface = { |
| 6593 | xdg_output_destroy |
| 6594 | }; |
| 6595 | |
| 6596 | static void |
| 6597 | xdg_output_manager_destroy(struct wl_client *client, |
| 6598 | struct wl_resource *resource) |
| 6599 | { |
| 6600 | wl_resource_destroy(resource); |
| 6601 | } |
| 6602 | |
| 6603 | static void |
| 6604 | xdg_output_manager_get_xdg_output(struct wl_client *client, |
| 6605 | struct wl_resource *manager, |
| 6606 | uint32_t id, |
| 6607 | struct wl_resource *output_resource) |
| 6608 | { |
| 6609 | int version = wl_resource_get_version(manager); |
| 6610 | struct weston_head *head = wl_resource_get_user_data(output_resource); |
| 6611 | struct weston_output *output = head->output; |
| 6612 | struct wl_resource *resource; |
| 6613 | |
| 6614 | resource = wl_resource_create(client, &zxdg_output_v1_interface, |
| 6615 | version, id); |
| 6616 | if (resource == NULL) { |
| 6617 | wl_client_post_no_memory(client); |
| 6618 | return; |
| 6619 | } |
| 6620 | |
| 6621 | wl_list_insert(&head->xdg_output_resource_list, |
| 6622 | wl_resource_get_link(resource)); |
| 6623 | |
| 6624 | wl_resource_set_implementation(resource, &xdg_output_interface, |
| 6625 | NULL, xdg_output_unlist); |
| 6626 | |
| 6627 | zxdg_output_v1_send_logical_position(resource, output->x, output->y); |
| 6628 | zxdg_output_v1_send_logical_size(resource, |
| 6629 | output->width, |
| 6630 | output->height); |
| 6631 | if (version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION) |
| 6632 | zxdg_output_v1_send_name(resource, head->name); |
| 6633 | |
| 6634 | zxdg_output_v1_send_done(resource); |
| 6635 | } |
| 6636 | |
| 6637 | static const struct zxdg_output_manager_v1_interface xdg_output_manager_interface = { |
| 6638 | xdg_output_manager_destroy, |
| 6639 | xdg_output_manager_get_xdg_output |
| 6640 | }; |
| 6641 | |
| 6642 | static void |
| 6643 | bind_xdg_output_manager(struct wl_client *client, |
| 6644 | void *data, uint32_t version, uint32_t id) |
| 6645 | { |
| 6646 | struct wl_resource *resource; |
| 6647 | |
| 6648 | resource = wl_resource_create(client, &zxdg_output_manager_v1_interface, |
| 6649 | version, id); |
| 6650 | if (resource == NULL) { |
| 6651 | wl_client_post_no_memory(client); |
| 6652 | return; |
| 6653 | } |
| 6654 | |
| 6655 | wl_resource_set_implementation(resource, &xdg_output_manager_interface, |
| 6656 | NULL, NULL); |
| 6657 | } |
| 6658 | |
| 6659 | static void |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6660 | destroy_viewport(struct wl_resource *resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6661 | { |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 6662 | struct weston_surface *surface = |
| 6663 | wl_resource_get_user_data(resource); |
| 6664 | |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 6665 | if (!surface) |
| 6666 | return; |
| 6667 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6668 | surface->viewport_resource = NULL; |
Pekka Paalanen | f0cad48 | 2014-03-14 14:38:16 +0200 | [diff] [blame] | 6669 | surface->pending.buffer_viewport.buffer.src_width = |
| 6670 | wl_fixed_from_int(-1); |
| 6671 | surface->pending.buffer_viewport.surface.width = -1; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 6672 | surface->pending.buffer_viewport.changed = 1; |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6673 | } |
| 6674 | |
| 6675 | static void |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6676 | viewport_destroy(struct wl_client *client, |
| 6677 | struct wl_resource *resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6678 | { |
| 6679 | wl_resource_destroy(resource); |
| 6680 | } |
| 6681 | |
| 6682 | static void |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6683 | viewport_set_source(struct wl_client *client, |
| 6684 | struct wl_resource *resource, |
| 6685 | wl_fixed_t src_x, |
| 6686 | wl_fixed_t src_y, |
| 6687 | wl_fixed_t src_width, |
| 6688 | wl_fixed_t src_height) |
| 6689 | { |
| 6690 | struct weston_surface *surface = |
| 6691 | wl_resource_get_user_data(resource); |
| 6692 | |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 6693 | if (!surface) { |
| 6694 | wl_resource_post_error(resource, |
| 6695 | WP_VIEWPORT_ERROR_NO_SURFACE, |
| 6696 | "wl_surface for this viewport is no longer exists"); |
| 6697 | return; |
| 6698 | } |
| 6699 | |
| 6700 | assert(surface->viewport_resource == resource); |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 6701 | assert(surface->resource); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6702 | |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6703 | if (src_width == wl_fixed_from_int(-1) && |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 6704 | src_height == wl_fixed_from_int(-1) && |
| 6705 | src_x == wl_fixed_from_int(-1) && |
| 6706 | src_y == wl_fixed_from_int(-1)) { |
| 6707 | /* unset source rect */ |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6708 | surface->pending.buffer_viewport.buffer.src_width = |
| 6709 | wl_fixed_from_int(-1); |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 6710 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6711 | return; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6712 | } |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6713 | |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 6714 | 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] | 6715 | wl_resource_post_error(resource, |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 6716 | WP_VIEWPORT_ERROR_BAD_VALUE, |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 6717 | "wl_surface@%d viewport source " |
| 6718 | "w=%f <= 0, h=%f <= 0, x=%f < 0, or y=%f < 0", |
| 6719 | wl_resource_get_id(surface->resource), |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6720 | wl_fixed_to_double(src_width), |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 6721 | wl_fixed_to_double(src_height), |
| 6722 | wl_fixed_to_double(src_x), |
| 6723 | wl_fixed_to_double(src_y)); |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6724 | return; |
| 6725 | } |
| 6726 | |
| 6727 | surface->pending.buffer_viewport.buffer.src_x = src_x; |
| 6728 | surface->pending.buffer_viewport.buffer.src_y = src_y; |
| 6729 | surface->pending.buffer_viewport.buffer.src_width = src_width; |
| 6730 | surface->pending.buffer_viewport.buffer.src_height = src_height; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 6731 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6732 | } |
| 6733 | |
| 6734 | static void |
| 6735 | viewport_set_destination(struct wl_client *client, |
| 6736 | struct wl_resource *resource, |
| 6737 | int32_t dst_width, |
| 6738 | int32_t dst_height) |
| 6739 | { |
| 6740 | struct weston_surface *surface = |
| 6741 | wl_resource_get_user_data(resource); |
| 6742 | |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 6743 | if (!surface) { |
| 6744 | wl_resource_post_error(resource, |
| 6745 | WP_VIEWPORT_ERROR_NO_SURFACE, |
| 6746 | "wl_surface for this viewport no longer exists"); |
| 6747 | return; |
| 6748 | } |
| 6749 | |
| 6750 | assert(surface->viewport_resource == resource); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6751 | |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6752 | if (dst_width == -1 && dst_height == -1) { |
| 6753 | /* unset destination size */ |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6754 | surface->pending.buffer_viewport.surface.width = -1; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 6755 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6756 | return; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6757 | } |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6758 | |
| 6759 | if (dst_width <= 0 || dst_height <= 0) { |
| 6760 | wl_resource_post_error(resource, |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 6761 | WP_VIEWPORT_ERROR_BAD_VALUE, |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6762 | "destination size must be positive (%dx%d)", |
| 6763 | dst_width, dst_height); |
| 6764 | return; |
| 6765 | } |
| 6766 | |
| 6767 | surface->pending.buffer_viewport.surface.width = dst_width; |
| 6768 | surface->pending.buffer_viewport.surface.height = dst_height; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 6769 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6770 | } |
| 6771 | |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 6772 | static const struct wp_viewport_interface viewport_interface = { |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6773 | viewport_destroy, |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6774 | viewport_set_source, |
| 6775 | viewport_set_destination |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6776 | }; |
| 6777 | |
| 6778 | static void |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6779 | viewporter_destroy(struct wl_client *client, |
| 6780 | struct wl_resource *resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6781 | { |
| 6782 | wl_resource_destroy(resource); |
| 6783 | } |
| 6784 | |
| 6785 | static void |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6786 | viewporter_get_viewport(struct wl_client *client, |
| 6787 | struct wl_resource *viewporter, |
| 6788 | uint32_t id, |
| 6789 | struct wl_resource *surface_resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6790 | { |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6791 | int version = wl_resource_get_version(viewporter); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6792 | struct weston_surface *surface = |
| 6793 | wl_resource_get_user_data(surface_resource); |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6794 | struct wl_resource *resource; |
| 6795 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6796 | if (surface->viewport_resource) { |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6797 | wl_resource_post_error(viewporter, |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 6798 | WP_VIEWPORTER_ERROR_VIEWPORT_EXISTS, |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6799 | "a viewport for that surface already exists"); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 6800 | return; |
| 6801 | } |
| 6802 | |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 6803 | resource = wl_resource_create(client, &wp_viewport_interface, |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6804 | version, id); |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6805 | if (resource == NULL) { |
| 6806 | wl_client_post_no_memory(client); |
| 6807 | return; |
| 6808 | } |
| 6809 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6810 | wl_resource_set_implementation(resource, &viewport_interface, |
| 6811 | surface, destroy_viewport); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 6812 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6813 | surface->viewport_resource = resource; |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6814 | } |
| 6815 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6816 | static const struct wp_viewporter_interface viewporter_interface = { |
| 6817 | viewporter_destroy, |
| 6818 | viewporter_get_viewport |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6819 | }; |
| 6820 | |
| 6821 | static void |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6822 | bind_viewporter(struct wl_client *client, |
| 6823 | void *data, uint32_t version, uint32_t id) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6824 | { |
| 6825 | struct wl_resource *resource; |
| 6826 | |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 6827 | resource = wl_resource_create(client, &wp_viewporter_interface, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 6828 | version, id); |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6829 | if (resource == NULL) { |
| 6830 | wl_client_post_no_memory(client); |
| 6831 | return; |
| 6832 | } |
| 6833 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6834 | wl_resource_set_implementation(resource, &viewporter_interface, |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6835 | NULL, NULL); |
| 6836 | } |
| 6837 | |
| 6838 | static void |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 6839 | destroy_presentation_feedback(struct wl_resource *feedback_resource) |
| 6840 | { |
| 6841 | struct weston_presentation_feedback *feedback; |
| 6842 | |
| 6843 | feedback = wl_resource_get_user_data(feedback_resource); |
| 6844 | |
| 6845 | wl_list_remove(&feedback->link); |
| 6846 | free(feedback); |
| 6847 | } |
| 6848 | |
| 6849 | static void |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 6850 | presentation_destroy(struct wl_client *client, struct wl_resource *resource) |
| 6851 | { |
| 6852 | wl_resource_destroy(resource); |
| 6853 | } |
| 6854 | |
| 6855 | static void |
| 6856 | presentation_feedback(struct wl_client *client, |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 6857 | struct wl_resource *presentation_resource, |
| 6858 | struct wl_resource *surface_resource, |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 6859 | uint32_t callback) |
| 6860 | { |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 6861 | struct weston_surface *surface; |
| 6862 | struct weston_presentation_feedback *feedback; |
| 6863 | |
| 6864 | surface = wl_resource_get_user_data(surface_resource); |
| 6865 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 6866 | feedback = zalloc(sizeof *feedback); |
| 6867 | if (feedback == NULL) |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 6868 | goto err_calloc; |
| 6869 | |
| 6870 | feedback->resource = wl_resource_create(client, |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 6871 | &wp_presentation_feedback_interface, |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 6872 | 1, callback); |
| 6873 | if (!feedback->resource) |
| 6874 | goto err_create; |
| 6875 | |
| 6876 | wl_resource_set_implementation(feedback->resource, NULL, feedback, |
| 6877 | destroy_presentation_feedback); |
| 6878 | |
| 6879 | wl_list_insert(&surface->pending.feedback_list, &feedback->link); |
| 6880 | |
| 6881 | return; |
| 6882 | |
| 6883 | err_create: |
| 6884 | free(feedback); |
| 6885 | |
| 6886 | err_calloc: |
| 6887 | wl_client_post_no_memory(client); |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 6888 | } |
| 6889 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 6890 | static const struct wp_presentation_interface presentation_implementation = { |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 6891 | presentation_destroy, |
| 6892 | presentation_feedback |
| 6893 | }; |
| 6894 | |
| 6895 | static void |
| 6896 | bind_presentation(struct wl_client *client, |
| 6897 | void *data, uint32_t version, uint32_t id) |
| 6898 | { |
| 6899 | struct weston_compositor *compositor = data; |
| 6900 | struct wl_resource *resource; |
| 6901 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 6902 | resource = wl_resource_create(client, &wp_presentation_interface, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 6903 | version, id); |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 6904 | if (resource == NULL) { |
| 6905 | wl_client_post_no_memory(client); |
| 6906 | return; |
| 6907 | } |
| 6908 | |
| 6909 | wl_resource_set_implementation(resource, &presentation_implementation, |
| 6910 | compositor, NULL); |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 6911 | wp_presentation_send_clock_id(resource, compositor->presentation_clock); |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 6912 | } |
| 6913 | |
| 6914 | static void |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 6915 | compositor_bind(struct wl_client *client, |
| 6916 | void *data, uint32_t version, uint32_t id) |
| 6917 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 6918 | struct weston_compositor *compositor = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 6919 | struct wl_resource *resource; |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 6920 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 6921 | resource = wl_resource_create(client, &wl_compositor_interface, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 6922 | version, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 6923 | if (resource == NULL) { |
| 6924 | wl_client_post_no_memory(client); |
| 6925 | return; |
| 6926 | } |
| 6927 | |
| 6928 | wl_resource_set_implementation(resource, &compositor_interface, |
| 6929 | compositor, NULL); |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 6930 | } |
| 6931 | |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6932 | static const char * |
| 6933 | output_repaint_status_text(struct weston_output *output) |
| 6934 | { |
| 6935 | switch (output->repaint_status) { |
| 6936 | case REPAINT_NOT_SCHEDULED: |
| 6937 | return "no repaint"; |
| 6938 | case REPAINT_BEGIN_FROM_IDLE: |
| 6939 | return "start_repaint_loop scheduled"; |
| 6940 | case REPAINT_SCHEDULED: |
| 6941 | return "repaint scheduled"; |
| 6942 | case REPAINT_AWAITING_COMPLETION: |
| 6943 | return "awaiting completion"; |
| 6944 | } |
| 6945 | |
| 6946 | assert(!"output_repaint_status_text missing enum"); |
| 6947 | return NULL; |
| 6948 | } |
| 6949 | |
| 6950 | static void |
| 6951 | debug_scene_view_print_buffer(FILE *fp, struct weston_view *view) |
| 6952 | { |
| 6953 | struct weston_buffer *buffer = view->surface->buffer_ref.buffer; |
| 6954 | struct wl_shm_buffer *shm; |
| 6955 | struct linux_dmabuf_buffer *dmabuf; |
Marius Vlad | 00a6e01 | 2018-11-20 17:52:31 +0200 | [diff] [blame] | 6956 | const struct pixel_format_info *pixel_info = NULL; |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6957 | |
| 6958 | if (!buffer) { |
| 6959 | fprintf(fp, "\t\t[buffer not available]\n"); |
| 6960 | return; |
| 6961 | } |
| 6962 | |
| 6963 | shm = wl_shm_buffer_get(buffer->resource); |
| 6964 | if (shm) { |
Marius Vlad | 00a6e01 | 2018-11-20 17:52:31 +0200 | [diff] [blame] | 6965 | uint32_t _format = wl_shm_buffer_get_format(shm); |
| 6966 | pixel_info = pixel_format_get_info_shm(_format); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6967 | fprintf(fp, "\t\tSHM buffer\n"); |
Marius Vlad | 00a6e01 | 2018-11-20 17:52:31 +0200 | [diff] [blame] | 6968 | fprintf(fp, "\t\t\tformat: 0x%lx %s\n", |
| 6969 | (unsigned long) _format, |
| 6970 | pixel_info ? pixel_info->drm_format_name : "UNKNOWN"); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6971 | return; |
| 6972 | } |
| 6973 | |
| 6974 | dmabuf = linux_dmabuf_buffer_get(buffer->resource); |
| 6975 | if (dmabuf) { |
Marius Vlad | 00a6e01 | 2018-11-20 17:52:31 +0200 | [diff] [blame] | 6976 | pixel_info = pixel_format_get_info(dmabuf->attributes.format); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6977 | fprintf(fp, "\t\tdmabuf buffer\n"); |
Marius Vlad | 00a6e01 | 2018-11-20 17:52:31 +0200 | [diff] [blame] | 6978 | fprintf(fp, "\t\t\tformat: 0x%lx %s\n", |
| 6979 | (unsigned long) dmabuf->attributes.format, |
| 6980 | pixel_info ? pixel_info->drm_format_name : "UNKNOWN"); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6981 | fprintf(fp, "\t\t\tmodifier: 0x%llx\n", |
| 6982 | (unsigned long long) dmabuf->attributes.modifier[0]); |
| 6983 | return; |
| 6984 | } |
| 6985 | |
Marius Vlad | 253ba9a | 2019-03-17 18:22:21 +0200 | [diff] [blame] | 6986 | fprintf(fp, "\t\tEGL buffer\n"); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6987 | } |
| 6988 | |
| 6989 | static void |
| 6990 | debug_scene_view_print(FILE *fp, struct weston_view *view, int view_idx) |
| 6991 | { |
| 6992 | struct weston_compositor *ec = view->surface->compositor; |
| 6993 | struct weston_output *output; |
| 6994 | char desc[512]; |
| 6995 | pixman_box32_t *box; |
| 6996 | uint32_t surface_id = 0; |
| 6997 | pid_t pid = 0; |
| 6998 | |
| 6999 | if (view->surface->resource) { |
| 7000 | struct wl_resource *resource = view->surface->resource; |
| 7001 | wl_client_get_credentials(wl_resource_get_client(resource), |
| 7002 | &pid, NULL, NULL); |
| 7003 | surface_id = wl_resource_get_id(view->surface->resource); |
| 7004 | } |
| 7005 | |
| 7006 | if (!view->surface->get_label || |
| 7007 | view->surface->get_label(view->surface, desc, sizeof(desc)) < 0) { |
| 7008 | strcpy(desc, "[no description available]"); |
| 7009 | } |
| 7010 | fprintf(fp, "\tView %d (role %s, PID %d, surface ID %u, %s, %p):\n", |
| 7011 | view_idx, view->surface->role_name, pid, surface_id, |
| 7012 | desc, view); |
| 7013 | |
| 7014 | box = pixman_region32_extents(&view->transform.boundingbox); |
| 7015 | fprintf(fp, "\t\tposition: (%d, %d) -> (%d, %d)\n", |
| 7016 | box->x1, box->y1, box->x2, box->y2); |
| 7017 | box = pixman_region32_extents(&view->transform.opaque); |
| 7018 | |
| 7019 | if (pixman_region32_equal(&view->transform.opaque, |
| 7020 | &view->transform.boundingbox)) { |
| 7021 | fprintf(fp, "\t\t[fully opaque]\n"); |
| 7022 | } else if (!pixman_region32_not_empty(&view->transform.opaque)) { |
| 7023 | fprintf(fp, "\t\t[not opaque]\n"); |
| 7024 | } else { |
| 7025 | fprintf(fp, "\t\t[opaque: (%d, %d) -> (%d, %d)]\n", |
| 7026 | box->x1, box->y1, box->x2, box->y2); |
| 7027 | } |
| 7028 | |
| 7029 | if (view->alpha < 1.0) |
| 7030 | fprintf(fp, "\t\talpha: %f\n", view->alpha); |
| 7031 | |
| 7032 | if (view->output_mask != 0) { |
| 7033 | bool first_output = true; |
| 7034 | fprintf(fp, "\t\toutputs: "); |
| 7035 | wl_list_for_each(output, &ec->output_list, link) { |
| 7036 | if (!(view->output_mask & (1 << output->id))) |
| 7037 | continue; |
| 7038 | fprintf(fp, "%s%d (%s)%s", |
| 7039 | (first_output) ? "" : ", ", |
| 7040 | output->id, output->name, |
| 7041 | (view->output == output) ? " (primary)" : ""); |
| 7042 | first_output = false; |
| 7043 | } |
| 7044 | } else { |
| 7045 | fprintf(fp, "\t\t[no outputs]"); |
| 7046 | } |
| 7047 | |
| 7048 | fprintf(fp, "\n"); |
| 7049 | |
| 7050 | debug_scene_view_print_buffer(fp, view); |
| 7051 | } |
| 7052 | |
Marius Vlad | 433f4e7 | 2019-02-17 22:14:23 +0200 | [diff] [blame] | 7053 | static void |
| 7054 | debug_scene_view_print_tree(struct weston_view *view, |
Marius Vlad | a6acfa8 | 2019-03-17 18:10:09 +0200 | [diff] [blame] | 7055 | FILE *fp, int *view_idx) |
Marius Vlad | 433f4e7 | 2019-02-17 22:14:23 +0200 | [diff] [blame] | 7056 | { |
| 7057 | struct weston_subsurface *sub; |
| 7058 | struct weston_view *ev; |
| 7059 | |
| 7060 | /* |
| 7061 | * print the view first, then we recursively go on printing |
| 7062 | * sub-surfaces. We bail out once no more sub-surfaces are available. |
| 7063 | */ |
Marius Vlad | a6acfa8 | 2019-03-17 18:10:09 +0200 | [diff] [blame] | 7064 | debug_scene_view_print(fp, view, *view_idx); |
Marius Vlad | 433f4e7 | 2019-02-17 22:14:23 +0200 | [diff] [blame] | 7065 | |
| 7066 | /* no more sub-surfaces */ |
| 7067 | if (wl_list_empty(&view->surface->subsurface_list)) |
| 7068 | return; |
| 7069 | |
| 7070 | wl_list_for_each(sub, &view->surface->subsurface_list, parent_link) { |
| 7071 | wl_list_for_each(ev, &sub->surface->views, surface_link) { |
| 7072 | /* do not print again the parent view */ |
| 7073 | if (view == ev) |
| 7074 | continue; |
Marius Vlad | a6acfa8 | 2019-03-17 18:10:09 +0200 | [diff] [blame] | 7075 | |
| 7076 | (*view_idx)++; |
Marius Vlad | 433f4e7 | 2019-02-17 22:14:23 +0200 | [diff] [blame] | 7077 | debug_scene_view_print_tree(ev, fp, view_idx); |
| 7078 | } |
| 7079 | } |
| 7080 | } |
| 7081 | |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7082 | /** |
| 7083 | * Output information on how libweston is currently composing the scene |
| 7084 | * graph. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7085 | * |
| 7086 | * \ingroup compositor |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7087 | */ |
| 7088 | WL_EXPORT char * |
| 7089 | weston_compositor_print_scene_graph(struct weston_compositor *ec) |
| 7090 | { |
| 7091 | struct weston_output *output; |
| 7092 | struct weston_layer *layer; |
| 7093 | struct timespec now; |
| 7094 | int layer_idx = 0; |
| 7095 | FILE *fp; |
| 7096 | char *ret; |
| 7097 | size_t len; |
| 7098 | int err; |
| 7099 | |
| 7100 | fp = open_memstream(&ret, &len); |
| 7101 | assert(fp); |
| 7102 | |
| 7103 | weston_compositor_read_presentation_clock(ec, &now); |
| 7104 | fprintf(fp, "Weston scene graph at %ld.%09ld:\n\n", |
| 7105 | now.tv_sec, now.tv_nsec); |
| 7106 | |
| 7107 | wl_list_for_each(output, &ec->output_list, link) { |
| 7108 | struct weston_head *head; |
| 7109 | int head_idx = 0; |
| 7110 | |
| 7111 | fprintf(fp, "Output %d (%s):\n", output->id, output->name); |
| 7112 | assert(output->enabled); |
| 7113 | |
| 7114 | fprintf(fp, "\tposition: (%d, %d) -> (%d, %d)\n", |
| 7115 | output->x, output->y, |
| 7116 | output->x + output->width, |
| 7117 | output->y + output->height); |
| 7118 | fprintf(fp, "\tmode: %dx%d@%.3fHz\n", |
| 7119 | output->current_mode->width, |
| 7120 | output->current_mode->height, |
| 7121 | output->current_mode->refresh / 1000.0); |
| 7122 | fprintf(fp, "\tscale: %d\n", output->scale); |
| 7123 | |
| 7124 | fprintf(fp, "\trepaint status: %s\n", |
| 7125 | output_repaint_status_text(output)); |
| 7126 | if (output->repaint_status == REPAINT_SCHEDULED) |
| 7127 | fprintf(fp, "\tnext repaint: %ld.%09ld\n", |
| 7128 | output->next_repaint.tv_sec, |
| 7129 | output->next_repaint.tv_nsec); |
| 7130 | |
| 7131 | wl_list_for_each(head, &output->head_list, output_link) { |
| 7132 | fprintf(fp, "\tHead %d (%s): %sconnected\n", |
| 7133 | head_idx++, head->name, |
| 7134 | (head->connected) ? "" : "not "); |
| 7135 | } |
| 7136 | } |
| 7137 | |
| 7138 | fprintf(fp, "\n"); |
| 7139 | |
| 7140 | wl_list_for_each(layer, &ec->layer_list, link) { |
| 7141 | struct weston_view *view; |
| 7142 | int view_idx = 0; |
| 7143 | |
| 7144 | fprintf(fp, "Layer %d (pos 0x%lx):\n", layer_idx++, |
| 7145 | (unsigned long) layer->position); |
| 7146 | |
| 7147 | if (!weston_layer_mask_is_infinite(layer)) { |
| 7148 | fprintf(fp, "\t[mask: (%d, %d) -> (%d,%d)]\n\n", |
| 7149 | layer->mask.x1, layer->mask.y1, |
| 7150 | layer->mask.x2, layer->mask.y2); |
| 7151 | } |
| 7152 | |
Marius Vlad | a6acfa8 | 2019-03-17 18:10:09 +0200 | [diff] [blame] | 7153 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
| 7154 | debug_scene_view_print_tree(view, fp, &view_idx); |
| 7155 | view_idx++; |
| 7156 | } |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7157 | |
| 7158 | if (wl_list_empty(&layer->view_list.link)) |
| 7159 | fprintf(fp, "\t[no views]\n"); |
| 7160 | |
| 7161 | fprintf(fp, "\n"); |
| 7162 | } |
| 7163 | |
| 7164 | err = fclose(fp); |
| 7165 | assert(err == 0); |
| 7166 | |
| 7167 | return ret; |
| 7168 | } |
| 7169 | |
| 7170 | /** |
| 7171 | * Called when the 'scene-graph' debug scope is bound by a client. This |
| 7172 | * one-shot weston-debug scope prints the current scene graph when bound, |
| 7173 | * and then terminates the stream. |
| 7174 | */ |
| 7175 | static void |
Marius Vlad | dad882a | 2019-07-17 15:43:53 +0300 | [diff] [blame] | 7176 | debug_scene_graph_cb(struct weston_log_subscription *sub, void *data) |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7177 | { |
| 7178 | struct weston_compositor *ec = data; |
| 7179 | char *str = weston_compositor_print_scene_graph(ec); |
| 7180 | |
Marius Vlad | dad882a | 2019-07-17 15:43:53 +0300 | [diff] [blame] | 7181 | weston_log_subscription_printf(sub, "%s", str); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7182 | free(str); |
Marius Vlad | dad882a | 2019-07-17 15:43:53 +0300 | [diff] [blame] | 7183 | weston_log_subscription_complete(sub); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7184 | } |
| 7185 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7186 | /** Create the compositor. |
| 7187 | * |
| 7188 | * This functions creates and initializes a compositor instance. |
| 7189 | * |
| 7190 | * \param display The Wayland display to be used. |
| 7191 | * \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] | 7192 | * \param log_ctx A pointer to weston_debug_compositor |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7193 | * using the \ref weston_compositor_get_user_data function. |
| 7194 | * \return The compositor instance on success or NULL on failure. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7195 | * |
| 7196 | * \ingroup compositor |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7197 | */ |
| 7198 | WL_EXPORT struct weston_compositor * |
Marius Vlad | 880b485 | 2019-04-07 17:07:58 +0300 | [diff] [blame] | 7199 | weston_compositor_create(struct wl_display *display, |
Marius Vlad | 3d7d978 | 2019-04-17 12:35:38 +0300 | [diff] [blame] | 7200 | struct weston_log_context *log_ctx, |
Marius Vlad | 880b485 | 2019-04-07 17:07:58 +0300 | [diff] [blame] | 7201 | void *user_data) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 7202 | { |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7203 | struct weston_compositor *ec; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 7204 | struct wl_event_loop *loop; |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 7205 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7206 | ec = zalloc(sizeof *ec); |
| 7207 | if (!ec) |
| 7208 | return NULL; |
| 7209 | |
| 7210 | ec->wl_display = display; |
| 7211 | ec->user_data = user_data; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 7212 | wl_signal_init(&ec->destroy_signal); |
Kristian Høgsberg | f03a04a | 2014-04-06 22:04:50 -0700 | [diff] [blame] | 7213 | wl_signal_init(&ec->create_surface_signal); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 7214 | wl_signal_init(&ec->activate_signal); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 7215 | wl_signal_init(&ec->transform_signal); |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 7216 | wl_signal_init(&ec->kill_signal); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 7217 | wl_signal_init(&ec->idle_signal); |
| 7218 | wl_signal_init(&ec->wake_signal); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 7219 | wl_signal_init(&ec->show_input_panel_signal); |
| 7220 | wl_signal_init(&ec->hide_input_panel_signal); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 7221 | wl_signal_init(&ec->update_input_panel_signal); |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 7222 | wl_signal_init(&ec->seat_created_signal); |
Richard Hughes | 59d5da7 | 2013-05-01 21:52:11 +0100 | [diff] [blame] | 7223 | wl_signal_init(&ec->output_created_signal); |
Ander Conselvan de Oliveira | f84327a | 2014-01-29 18:47:51 +0200 | [diff] [blame] | 7224 | wl_signal_init(&ec->output_destroyed_signal); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 7225 | wl_signal_init(&ec->output_moved_signal); |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 7226 | wl_signal_init(&ec->output_resized_signal); |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 7227 | wl_signal_init(&ec->heads_changed_signal); |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 7228 | wl_signal_init(&ec->output_heads_changed_signal); |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 7229 | wl_signal_init(&ec->session_signal); |
Robert Beckett | c569bdc | 2019-07-10 16:40:12 +0100 | [diff] [blame] | 7230 | ec->session_active = true; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 7231 | |
Casey Dahlin | 58ba137 | 2012-04-19 22:50:08 -0400 | [diff] [blame] | 7232 | ec->output_id_pool = 0; |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 7233 | ec->repaint_msec = DEFAULT_REPAINT_WINDOW; |
Casey Dahlin | 58ba137 | 2012-04-19 22:50:08 -0400 | [diff] [blame] | 7234 | |
Jonas Ådahl | 94e2e2d | 2014-10-18 18:42:19 +0200 | [diff] [blame] | 7235 | ec->activate_serial = 1; |
| 7236 | |
Louis-Francis Ratté-Boulianne | c4689ff | 2017-11-28 20:42:47 -0500 | [diff] [blame] | 7237 | ec->touch_mode = WESTON_TOUCH_MODE_NORMAL; |
| 7238 | |
Ankit Nautiyal | 5cfe03c | 2019-03-28 15:05:42 +0530 | [diff] [blame] | 7239 | ec->content_protection = NULL; |
| 7240 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 7241 | if (!wl_global_create(ec->wl_display, &wl_compositor_interface, 4, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 7242 | ec, compositor_bind)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7243 | goto fail; |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 7244 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 7245 | if (!wl_global_create(ec->wl_display, &wl_subcompositor_interface, 1, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 7246 | ec, bind_subcompositor)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7247 | goto fail; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 7248 | |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 7249 | if (!wl_global_create(ec->wl_display, &wp_viewporter_interface, 1, |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 7250 | ec, bind_viewporter)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7251 | goto fail; |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 7252 | |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 7253 | if (!wl_global_create(ec->wl_display, &zxdg_output_manager_v1_interface, 2, |
| 7254 | ec, bind_xdg_output_manager)) |
| 7255 | goto fail; |
| 7256 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 7257 | if (!wl_global_create(ec->wl_display, &wp_presentation_interface, 1, |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 7258 | ec, bind_presentation)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7259 | goto fail; |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 7260 | |
Marius Vlad | 3d7d978 | 2019-04-17 12:35:38 +0300 | [diff] [blame] | 7261 | if (weston_log_ctx_compositor_setup(ec, log_ctx) < 0) |
Pekka Paalanen | a5630ea | 2017-10-12 13:13:42 +0200 | [diff] [blame] | 7262 | goto fail; |
| 7263 | |
Jonas Ådahl | 30d61d8 | 2014-10-22 21:21:17 +0200 | [diff] [blame] | 7264 | if (weston_input_init(ec) != 0) |
| 7265 | goto fail; |
| 7266 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 7267 | wl_list_init(&ec->view_list); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 7268 | wl_list_init(&ec->plane_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 7269 | wl_list_init(&ec->layer_list); |
| 7270 | wl_list_init(&ec->seat_list); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 7271 | wl_list_init(&ec->pending_output_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 7272 | wl_list_init(&ec->output_list); |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 7273 | wl_list_init(&ec->head_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 7274 | wl_list_init(&ec->key_binding_list); |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 7275 | wl_list_init(&ec->modifier_binding_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 7276 | wl_list_init(&ec->button_binding_list); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 7277 | wl_list_init(&ec->touch_binding_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 7278 | wl_list_init(&ec->axis_binding_list); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 7279 | wl_list_init(&ec->debug_binding_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 7280 | |
Pekka Paalanen | 827b5d2 | 2016-06-29 11:54:26 +0200 | [diff] [blame] | 7281 | wl_list_init(&ec->plugin_api_list); |
| 7282 | |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 7283 | weston_plane_init(&ec->primary_plane, ec, 0, 0); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 7284 | weston_compositor_stack_plane(ec, &ec->primary_plane, NULL); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 7285 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7286 | wl_data_device_manager_init(ec->wl_display); |
| 7287 | |
| 7288 | wl_display_init_shm(ec->wl_display); |
| 7289 | |
| 7290 | loop = wl_display_get_event_loop(ec->wl_display); |
| 7291 | ec->idle_source = wl_event_loop_add_timer(loop, idle_handler, ec); |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 7292 | ec->repaint_timer = |
| 7293 | wl_event_loop_add_timer(loop, output_repaint_timer_handler, |
| 7294 | ec); |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7295 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 7296 | weston_layer_init(&ec->fade_layer, ec); |
| 7297 | weston_layer_init(&ec->cursor_layer, ec); |
| 7298 | |
| 7299 | weston_layer_set_position(&ec->fade_layer, WESTON_LAYER_POSITION_FADE); |
| 7300 | weston_layer_set_position(&ec->cursor_layer, |
| 7301 | WESTON_LAYER_POSITION_CURSOR); |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7302 | |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7303 | ec->debug_scene = |
Leandro Ribeiro | ce10019 | 2019-12-26 16:35:49 -0300 | [diff] [blame^] | 7304 | weston_compositor_add_log_scope(ec, "scene-graph", |
| 7305 | "Scene graph details\n", |
| 7306 | debug_scene_graph_cb, NULL, |
| 7307 | ec); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7308 | |
Marius Vlad | da104eb | 2019-09-05 14:31:01 +0300 | [diff] [blame] | 7309 | ec->timeline = |
Leandro Ribeiro | ce10019 | 2019-12-26 16:35:49 -0300 | [diff] [blame^] | 7310 | weston_compositor_add_log_scope(ec, "timeline", |
| 7311 | "Timeline event points\n", |
| 7312 | weston_timeline_create_subscription, |
| 7313 | weston_timeline_destroy_subscription, |
| 7314 | ec); |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7315 | return ec; |
| 7316 | |
| 7317 | fail: |
| 7318 | free(ec); |
| 7319 | return NULL; |
| 7320 | } |
| 7321 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7322 | /** weston_compositor_shutdown |
| 7323 | * \ingroup compositor |
| 7324 | */ |
Benjamin Franzke | b826302 | 2011-08-30 11:32:47 +0200 | [diff] [blame] | 7325 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 7326 | weston_compositor_shutdown(struct weston_compositor *ec) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 7327 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 7328 | struct weston_output *output, *next; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 7329 | |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 7330 | wl_event_source_remove(ec->idle_source); |
| 7331 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 7332 | /* Destroy all outputs associated with this compositor */ |
Tiago Vignatti | b303a1d | 2011-12-18 22:27:40 +0200 | [diff] [blame] | 7333 | wl_list_for_each_safe(output, next, &ec->output_list, link) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 7334 | output->destroy(output); |
Pekka Paalanen | 4738f3b | 2012-01-02 15:47:07 +0200 | [diff] [blame] | 7335 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 7336 | /* Destroy all pending outputs associated with this compositor */ |
| 7337 | wl_list_for_each_safe(output, next, &ec->pending_output_list, link) |
| 7338 | output->destroy(output); |
| 7339 | |
Ander Conselvan de Oliveira | 1853676 | 2013-12-20 21:07:00 +0200 | [diff] [blame] | 7340 | if (ec->renderer) |
| 7341 | ec->renderer->destroy(ec); |
| 7342 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 7343 | weston_binding_list_destroy_all(&ec->key_binding_list); |
Ryo Munakata | 27135af | 2015-07-17 13:07:42 +0900 | [diff] [blame] | 7344 | weston_binding_list_destroy_all(&ec->modifier_binding_list); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 7345 | weston_binding_list_destroy_all(&ec->button_binding_list); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 7346 | weston_binding_list_destroy_all(&ec->touch_binding_list); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 7347 | weston_binding_list_destroy_all(&ec->axis_binding_list); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 7348 | weston_binding_list_destroy_all(&ec->debug_binding_list); |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 7349 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 7350 | weston_plane_release(&ec->primary_plane); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 7351 | } |
| 7352 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7353 | /** weston_compositor_exit_with_code |
| 7354 | * \ingroup compositor |
| 7355 | */ |
Kristian Høgsberg | af4f2aa | 2013-02-15 20:53:20 -0500 | [diff] [blame] | 7356 | WL_EXPORT void |
Adam Jackson | 3c3f3b1 | 2019-10-16 16:02:59 -0400 | [diff] [blame] | 7357 | weston_compositor_exit_with_code(struct weston_compositor *compositor, |
Frederic Plourde | c336f06 | 2014-10-29 14:44:33 -0400 | [diff] [blame] | 7358 | int exit_code) |
| 7359 | { |
Pekka Paalanen | f5ef88f | 2014-11-18 15:57:04 +0200 | [diff] [blame] | 7360 | if (compositor->exit_code == EXIT_SUCCESS) |
| 7361 | compositor->exit_code = exit_code; |
| 7362 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7363 | weston_compositor_exit(compositor); |
Frederic Plourde | c336f06 | 2014-10-29 14:44:33 -0400 | [diff] [blame] | 7364 | } |
| 7365 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7366 | /** weston_compositor_set_default_pointer_grab |
| 7367 | * \ingroup compositor |
| 7368 | */ |
Frederic Plourde | c336f06 | 2014-10-29 14:44:33 -0400 | [diff] [blame] | 7369 | WL_EXPORT void |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 7370 | weston_compositor_set_default_pointer_grab(struct weston_compositor *ec, |
| 7371 | const struct weston_pointer_grab_interface *interface) |
| 7372 | { |
| 7373 | struct weston_seat *seat; |
| 7374 | |
| 7375 | ec->default_pointer_grab = interface; |
| 7376 | wl_list_for_each(seat, &ec->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 7377 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 7378 | |
| 7379 | if (pointer) |
| 7380 | weston_pointer_set_default_grab(pointer, interface); |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 7381 | } |
| 7382 | } |
| 7383 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7384 | /** weston_compositor_set_presentation_clock |
| 7385 | * \ingroup compositor |
| 7386 | */ |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 7387 | WL_EXPORT int |
| 7388 | weston_compositor_set_presentation_clock(struct weston_compositor *compositor, |
| 7389 | clockid_t clk_id) |
| 7390 | { |
| 7391 | struct timespec ts; |
| 7392 | |
| 7393 | if (clock_gettime(clk_id, &ts) < 0) |
| 7394 | return -1; |
| 7395 | |
| 7396 | compositor->presentation_clock = clk_id; |
| 7397 | |
| 7398 | return 0; |
| 7399 | } |
| 7400 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7401 | /** For choosing the software clock, when the display hardware or API |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 7402 | * does not expose a compatible presentation timestamp. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7403 | * |
| 7404 | * \ingroup compositor |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 7405 | */ |
| 7406 | WL_EXPORT int |
| 7407 | weston_compositor_set_presentation_clock_software( |
| 7408 | struct weston_compositor *compositor) |
| 7409 | { |
| 7410 | /* In order of preference */ |
| 7411 | static const clockid_t clocks[] = { |
| 7412 | CLOCK_MONOTONIC_RAW, /* no jumps, no crawling */ |
| 7413 | CLOCK_MONOTONIC_COARSE, /* no jumps, may crawl, fast & coarse */ |
| 7414 | CLOCK_MONOTONIC, /* no jumps, may crawl */ |
| 7415 | CLOCK_REALTIME_COARSE, /* may jump and crawl, fast & coarse */ |
| 7416 | CLOCK_REALTIME /* may jump and crawl */ |
| 7417 | }; |
| 7418 | unsigned i; |
| 7419 | |
| 7420 | for (i = 0; i < ARRAY_LENGTH(clocks); i++) |
| 7421 | if (weston_compositor_set_presentation_clock(compositor, |
| 7422 | clocks[i]) == 0) |
| 7423 | return 0; |
| 7424 | |
| 7425 | weston_log("Error: no suitable presentation clock available.\n"); |
| 7426 | |
| 7427 | return -1; |
| 7428 | } |
| 7429 | |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 7430 | /** Read the current time from the Presentation clock |
| 7431 | * |
| 7432 | * \param compositor |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 7433 | * \param[out] ts The current time. |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 7434 | * |
| 7435 | * \note Reading the current time in user space is always imprecise to some |
| 7436 | * degree. |
| 7437 | * |
| 7438 | * This function is never meant to fail. If reading the clock does fail, |
| 7439 | * an error message is logged and a zero time is returned. Callers are not |
| 7440 | * supposed to detect or react to failures. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7441 | * |
| 7442 | * \ingroup compositor |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 7443 | */ |
| 7444 | WL_EXPORT void |
| 7445 | weston_compositor_read_presentation_clock( |
| 7446 | const struct weston_compositor *compositor, |
| 7447 | struct timespec *ts) |
| 7448 | { |
| 7449 | static bool warned; |
| 7450 | int ret; |
| 7451 | |
| 7452 | ret = clock_gettime(compositor->presentation_clock, ts); |
| 7453 | if (ret < 0) { |
| 7454 | ts->tv_sec = 0; |
| 7455 | ts->tv_nsec = 0; |
| 7456 | |
| 7457 | if (!warned) |
| 7458 | weston_log("Error: failure to read " |
Antonio Borneo | 3957863 | 2019-04-26 23:57:31 +0200 | [diff] [blame] | 7459 | "the presentation clock %#x: '%s' (%d)\n", |
| 7460 | compositor->presentation_clock, |
| 7461 | strerror(errno), errno); |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 7462 | warned = true; |
| 7463 | } |
| 7464 | } |
| 7465 | |
Pekka Paalanen | 230f3b1 | 2014-09-29 14:18:40 -0400 | [diff] [blame] | 7466 | /** Import dmabuf buffer into current renderer |
| 7467 | * |
| 7468 | * \param compositor |
| 7469 | * \param buffer the dmabuf buffer to import |
| 7470 | * \return true on usable buffers, false otherwise |
| 7471 | * |
| 7472 | * This function tests that the linux_dmabuf_buffer is usable |
| 7473 | * for the current renderer. Returns false on unusable buffers. Usually |
| 7474 | * usability is tested by importing the dmabufs for composition. |
| 7475 | * |
| 7476 | * This hook is also used for detecting if the renderer supports |
| 7477 | * dmabufs at all. If the renderer hook is NULL, dmabufs are not |
| 7478 | * supported. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7479 | * |
| 7480 | * \ingroup compositor |
| 7481 | */ |
Pekka Paalanen | 230f3b1 | 2014-09-29 14:18:40 -0400 | [diff] [blame] | 7482 | WL_EXPORT bool |
| 7483 | weston_compositor_import_dmabuf(struct weston_compositor *compositor, |
| 7484 | struct linux_dmabuf_buffer *buffer) |
| 7485 | { |
| 7486 | struct weston_renderer *renderer; |
| 7487 | |
| 7488 | renderer = compositor->renderer; |
| 7489 | |
| 7490 | if (renderer->import_dmabuf == NULL) |
| 7491 | return false; |
| 7492 | |
| 7493 | return renderer->import_dmabuf(compositor, buffer); |
| 7494 | } |
| 7495 | |
Marius Vlad | 5a70154 | 2019-11-16 20:26:52 +0200 | [diff] [blame] | 7496 | WL_EXPORT bool |
| 7497 | weston_compositor_dmabuf_can_scanout(struct weston_compositor *compositor, |
| 7498 | struct linux_dmabuf_buffer *buffer) |
| 7499 | { |
| 7500 | struct weston_backend *backend = compositor->backend; |
| 7501 | |
| 7502 | if (backend->can_scanout_dmabuf == NULL) |
| 7503 | return false; |
| 7504 | |
| 7505 | return backend->can_scanout_dmabuf(compositor, buffer); |
| 7506 | } |
| 7507 | |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 7508 | WL_EXPORT void |
Kristian Høgsberg | af4f2aa | 2013-02-15 20:53:20 -0500 | [diff] [blame] | 7509 | weston_version(int *major, int *minor, int *micro) |
| 7510 | { |
| 7511 | *major = WESTON_VERSION_MAJOR; |
| 7512 | *minor = WESTON_VERSION_MINOR; |
| 7513 | *micro = WESTON_VERSION_MICRO; |
| 7514 | } |
| 7515 | |
Daniel Stone | e03c111 | 2016-11-24 20:45:45 +0000 | [diff] [blame] | 7516 | /** |
| 7517 | * Attempts to find a module path from the module map specified in the |
| 7518 | * environment. If found, writes the full path into the path variable. |
| 7519 | * |
| 7520 | * The module map is a string in environment variable WESTON_MODULE_MAP, where |
| 7521 | * each entry is of the form "name=path" and entries are separated by |
| 7522 | * semicolons. Whitespace is significant. |
| 7523 | * |
| 7524 | * \param name The name to search for. |
| 7525 | * \param path Where the path is written to if found. |
| 7526 | * \param path_len Allocated bytes at \c path . |
| 7527 | * \returns The length of the string written to path on success, or 0 if the |
| 7528 | * module was not specified in the environment map or path_len was too small. |
| 7529 | */ |
| 7530 | WL_EXPORT size_t |
| 7531 | weston_module_path_from_env(const char *name, char *path, size_t path_len) |
| 7532 | { |
| 7533 | const char *mapping = getenv("WESTON_MODULE_MAP"); |
| 7534 | const char *end; |
| 7535 | const int name_len = strlen(name); |
| 7536 | |
| 7537 | if (!mapping) |
| 7538 | return 0; |
| 7539 | |
| 7540 | end = mapping + strlen(mapping); |
| 7541 | while (mapping < end && *mapping) { |
| 7542 | const char *filename, *next; |
| 7543 | |
| 7544 | /* early out: impossibly short string */ |
| 7545 | if (end - mapping < name_len + 1) |
| 7546 | return 0; |
| 7547 | |
| 7548 | filename = &mapping[name_len + 1]; |
| 7549 | next = strchrnul(mapping, ';'); |
| 7550 | |
| 7551 | if (strncmp(mapping, name, name_len) == 0 && |
| 7552 | mapping[name_len] == '=') { |
| 7553 | size_t file_len = next - filename; /* no trailing NUL */ |
| 7554 | if (file_len >= path_len) |
| 7555 | return 0; |
| 7556 | strncpy(path, filename, file_len); |
| 7557 | path[file_len] = '\0'; |
| 7558 | return file_len; |
| 7559 | } |
| 7560 | |
| 7561 | mapping = next + 1; |
| 7562 | } |
| 7563 | |
| 7564 | return 0; |
| 7565 | } |
| 7566 | |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 7567 | WL_EXPORT void * |
| 7568 | weston_load_module(const char *name, const char *entrypoint) |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 7569 | { |
| 7570 | char path[PATH_MAX]; |
| 7571 | void *module, *init; |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 7572 | size_t len; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 7573 | |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 7574 | if (name == NULL) |
| 7575 | return NULL; |
| 7576 | |
Derek Foreman | 3f86e50 | 2015-06-08 11:46:54 -0500 | [diff] [blame] | 7577 | if (name[0] != '/') { |
Daniel Stone | e03c111 | 2016-11-24 20:45:45 +0000 | [diff] [blame] | 7578 | len = weston_module_path_from_env(name, path, sizeof path); |
| 7579 | if (len == 0) |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 7580 | len = snprintf(path, sizeof path, "%s/%s", |
| 7581 | LIBWESTON_MODULEDIR, name); |
Derek Foreman | 3f86e50 | 2015-06-08 11:46:54 -0500 | [diff] [blame] | 7582 | } else { |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 7583 | len = snprintf(path, sizeof path, "%s", name); |
Derek Foreman | 3f86e50 | 2015-06-08 11:46:54 -0500 | [diff] [blame] | 7584 | } |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 7585 | |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 7586 | /* snprintf returns the length of the string it would've written, |
| 7587 | * _excluding_ the NUL byte. So even being equal to the size of |
| 7588 | * our buffer is an error here. */ |
| 7589 | if (len >= sizeof path) |
| 7590 | return NULL; |
| 7591 | |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 7592 | module = dlopen(path, RTLD_NOW | RTLD_NOLOAD); |
| 7593 | if (module) { |
| 7594 | weston_log("Module '%s' already loaded\n", path); |
Pekka Paalanen | f696ee9 | 2019-11-04 14:07:51 +0200 | [diff] [blame] | 7595 | } else { |
| 7596 | weston_log("Loading module '%s'\n", path); |
| 7597 | module = dlopen(path, RTLD_NOW); |
| 7598 | if (!module) { |
| 7599 | weston_log("Failed to load module: %s\n", dlerror()); |
| 7600 | return NULL; |
| 7601 | } |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 7602 | } |
| 7603 | |
| 7604 | init = dlsym(module, entrypoint); |
| 7605 | if (!init) { |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 7606 | weston_log("Failed to lookup init function: %s\n", dlerror()); |
Rob Bradford | c9e64ab | 2012-12-05 18:47:10 +0000 | [diff] [blame] | 7607 | dlclose(module); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 7608 | return NULL; |
| 7609 | } |
| 7610 | |
| 7611 | return init; |
| 7612 | } |
| 7613 | |
Pekka Paalanen | 6ffbba3 | 2019-11-06 12:59:32 +0200 | [diff] [blame] | 7614 | /** Add a compositor destroy listener only once |
| 7615 | * |
| 7616 | * \param compositor The compositor whose destroy to watch for. |
| 7617 | * \param listener The listener struct to initialize. |
| 7618 | * \param destroy_handler The callback when compositor is destroyed. |
| 7619 | * \return True if listener is added, or false if there already is a listener |
| 7620 | * with the given \c destroy_handler. |
| 7621 | * |
| 7622 | * This function does nothing and returns false if the given callback function |
| 7623 | * is already present in the weston_compositor destroy callbacks list. |
| 7624 | * Otherwise, this function initializes the given listener with the given |
| 7625 | * callback pointer and adds it to the compositor's destroy callbacks list. |
| 7626 | * |
| 7627 | * This can be used to ensure that plugin initialization is done only once |
| 7628 | * in case the same plugin is loaded multiple times. If this function returns |
| 7629 | * false, the plugin should be already initialized successfully. |
| 7630 | * |
| 7631 | * All plugins should register a destroy listener for cleaning up. Note, that |
| 7632 | * the plugin destruction order is not guaranteed: plugins that depend on other |
| 7633 | * plugins must be able to be torn down in arbitrary order. |
| 7634 | * |
| 7635 | * \sa weston_compositor_tear_down, weston_compositor_destroy |
| 7636 | */ |
| 7637 | WL_EXPORT bool |
| 7638 | weston_compositor_add_destroy_listener_once(struct weston_compositor *compositor, |
| 7639 | struct wl_listener *listener, |
| 7640 | wl_notify_func_t destroy_handler) |
| 7641 | { |
| 7642 | if (wl_signal_get(&compositor->destroy_signal, destroy_handler)) |
| 7643 | return false; |
| 7644 | |
| 7645 | listener->notify = destroy_handler; |
| 7646 | wl_signal_add(&compositor->destroy_signal, listener); |
| 7647 | return true; |
| 7648 | } |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7649 | |
Marius Vlad | 284d534 | 2019-06-24 12:00:47 +0300 | [diff] [blame] | 7650 | /** Tear down the compositor. |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7651 | * |
Marius Vlad | 284d534 | 2019-06-24 12:00:47 +0300 | [diff] [blame] | 7652 | * This function cleans up the compositor state. While the compositor state has |
| 7653 | * been cleaned do note that **only** weston_compositor_destroy() can be called |
| 7654 | * afterwards, in order to destroy the compositor instance. |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7655 | * |
Marius Vlad | 284d534 | 2019-06-24 12:00:47 +0300 | [diff] [blame] | 7656 | * @param compositor The compositor to be tear-down/cleaned. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7657 | * |
Marius Vlad | 284d534 | 2019-06-24 12:00:47 +0300 | [diff] [blame] | 7658 | * @ingroup compositor |
| 7659 | * @sa weston_compositor_destroy |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7660 | */ |
| 7661 | WL_EXPORT void |
Marius Vlad | 284d534 | 2019-06-24 12:00:47 +0300 | [diff] [blame] | 7662 | weston_compositor_tear_down(struct weston_compositor *compositor) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7663 | { |
| 7664 | /* prevent further rendering while shutting down */ |
| 7665 | compositor->state = WESTON_COMPOSITOR_OFFSCREEN; |
| 7666 | |
| 7667 | wl_signal_emit(&compositor->destroy_signal, compositor); |
| 7668 | |
| 7669 | weston_compositor_xkb_destroy(compositor); |
| 7670 | |
Giulio Camuffo | 2d24e64 | 2015-10-03 16:25:15 +0300 | [diff] [blame] | 7671 | if (compositor->backend) |
| 7672 | compositor->backend->destroy(compositor); |
Pekka Paalanen | 827b5d2 | 2016-06-29 11:54:26 +0200 | [diff] [blame] | 7673 | |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 7674 | /* The backend is responsible for destroying the heads. */ |
| 7675 | assert(wl_list_empty(&compositor->head_list)); |
| 7676 | |
Pekka Paalanen | 827b5d2 | 2016-06-29 11:54:26 +0200 | [diff] [blame] | 7677 | weston_plugin_api_destroy_list(compositor); |
| 7678 | |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 7679 | if (compositor->heads_changed_source) |
| 7680 | wl_event_source_remove(compositor->heads_changed_source); |
| 7681 | |
Leandro Ribeiro | f014964 | 2019-12-18 15:52:18 -0300 | [diff] [blame] | 7682 | weston_log_scope_destroy(compositor->debug_scene); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7683 | compositor->debug_scene = NULL; |
Marius Vlad | da104eb | 2019-09-05 14:31:01 +0300 | [diff] [blame] | 7684 | |
Leandro Ribeiro | f014964 | 2019-12-18 15:52:18 -0300 | [diff] [blame] | 7685 | weston_log_scope_destroy(compositor->timeline); |
Marius Vlad | da104eb | 2019-09-05 14:31:01 +0300 | [diff] [blame] | 7686 | compositor->timeline = NULL; |
Marius Vlad | 284d534 | 2019-06-24 12:00:47 +0300 | [diff] [blame] | 7687 | } |
Pekka Paalanen | a5630ea | 2017-10-12 13:13:42 +0200 | [diff] [blame] | 7688 | |
Marius Vlad | 284d534 | 2019-06-24 12:00:47 +0300 | [diff] [blame] | 7689 | /** Destroys the compositor. |
| 7690 | * |
| 7691 | * This function destroys the compositor. **Do not** call this before |
| 7692 | * calling weston_compositor_tear_down() |
| 7693 | * |
| 7694 | * @param compositor The compositor to be destroyed. |
| 7695 | * @ingroup compositor |
| 7696 | * @sa weston_compositor_tear_down() |
| 7697 | */ |
| 7698 | WL_EXPORT void |
| 7699 | weston_compositor_destroy(struct weston_compositor *compositor) |
| 7700 | { |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7701 | free(compositor); |
| 7702 | } |
| 7703 | |
| 7704 | /** Instruct the compositor to exit. |
| 7705 | * |
| 7706 | * This functions does not directly destroy the compositor object, it merely |
| 7707 | * command it to start the tear down process. It is not guaranteed that the |
| 7708 | * tear down will happen immediately. |
| 7709 | * |
| 7710 | * \param compositor The compositor to tear down. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7711 | * |
| 7712 | * \ingroup compositor |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7713 | */ |
| 7714 | WL_EXPORT void |
| 7715 | weston_compositor_exit(struct weston_compositor *compositor) |
| 7716 | { |
| 7717 | compositor->exit(compositor); |
| 7718 | } |
| 7719 | |
| 7720 | /** Return the user data stored in the compositor. |
| 7721 | * |
| 7722 | * This function returns the user data pointer set with user_data parameter |
| 7723 | * to the \ref weston_compositor_create function. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7724 | * |
| 7725 | * \ingroup compositor |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7726 | */ |
| 7727 | WL_EXPORT void * |
| 7728 | weston_compositor_get_user_data(struct weston_compositor *compositor) |
| 7729 | { |
| 7730 | return compositor->user_data; |
| 7731 | } |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 7732 | |
Pekka Paalanen | 50dbf38 | 2016-06-03 15:23:46 +0300 | [diff] [blame] | 7733 | static const char * const backend_map[] = { |
| 7734 | [WESTON_BACKEND_DRM] = "drm-backend.so", |
| 7735 | [WESTON_BACKEND_FBDEV] = "fbdev-backend.so", |
| 7736 | [WESTON_BACKEND_HEADLESS] = "headless-backend.so", |
| 7737 | [WESTON_BACKEND_RDP] = "rdp-backend.so", |
| 7738 | [WESTON_BACKEND_WAYLAND] = "wayland-backend.so", |
| 7739 | [WESTON_BACKEND_X11] = "x11-backend.so", |
| 7740 | }; |
| 7741 | |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 7742 | /** Load a backend into a weston_compositor |
| 7743 | * |
| 7744 | * A backend must be loaded to make a weston_compositor work. A backend |
| 7745 | * provides input and output capabilities, and determines the renderer to use. |
| 7746 | * |
| 7747 | * \param compositor A compositor that has not had a backend loaded yet. |
| 7748 | * \param backend Name of the backend file. |
| 7749 | * \param config_base A pointer to a backend-specific configuration |
| 7750 | * structure's 'base' member. |
| 7751 | * |
| 7752 | * \return 0 on success, or -1 on error. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7753 | * |
| 7754 | * \ingroup compositor |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 7755 | */ |
| 7756 | WL_EXPORT int |
| 7757 | weston_compositor_load_backend(struct weston_compositor *compositor, |
Pekka Paalanen | 50dbf38 | 2016-06-03 15:23:46 +0300 | [diff] [blame] | 7758 | enum weston_compositor_backend backend, |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 7759 | struct weston_backend_config *config_base) |
| 7760 | { |
| 7761 | int (*backend_init)(struct weston_compositor *c, |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 7762 | struct weston_backend_config *config_base); |
| 7763 | |
Pekka Paalanen | d7e3511 | 2017-08-29 17:04:12 +0300 | [diff] [blame] | 7764 | if (compositor->backend) { |
| 7765 | weston_log("Error: attempt to load a backend when one is already loaded\n"); |
| 7766 | return -1; |
| 7767 | } |
| 7768 | |
Quentin Glidic | 887c018 | 2016-07-10 11:00:53 +0200 | [diff] [blame] | 7769 | if (backend >= ARRAY_LENGTH(backend_map)) |
Pekka Paalanen | 50dbf38 | 2016-06-03 15:23:46 +0300 | [diff] [blame] | 7770 | return -1; |
| 7771 | |
Quentin Glidic | 23e1d6f | 2016-12-02 14:08:44 +0100 | [diff] [blame] | 7772 | backend_init = weston_load_module(backend_map[backend], "weston_backend_init"); |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 7773 | if (!backend_init) |
| 7774 | return -1; |
| 7775 | |
Pekka Paalanen | d7e3511 | 2017-08-29 17:04:12 +0300 | [diff] [blame] | 7776 | if (backend_init(compositor, config_base) < 0) { |
| 7777 | compositor->backend = NULL; |
| 7778 | return -1; |
| 7779 | } |
| 7780 | |
| 7781 | return 0; |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 7782 | } |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 7783 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7784 | /** weston_compositor_load_xwayland |
| 7785 | * \ingroup compositor |
| 7786 | */ |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 7787 | WL_EXPORT int |
| 7788 | weston_compositor_load_xwayland(struct weston_compositor *compositor) |
| 7789 | { |
Quentin Glidic | 3d7ca3b | 2016-12-02 14:20:35 +0100 | [diff] [blame] | 7790 | int (*module_init)(struct weston_compositor *ec); |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 7791 | |
Quentin Glidic | 3d7ca3b | 2016-12-02 14:20:35 +0100 | [diff] [blame] | 7792 | module_init = weston_load_module("xwayland.so", "weston_module_init"); |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 7793 | if (!module_init) |
| 7794 | return -1; |
Quentin Glidic | 3d7ca3b | 2016-12-02 14:20:35 +0100 | [diff] [blame] | 7795 | if (module_init(compositor) < 0) |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 7796 | return -1; |
| 7797 | return 0; |
| 7798 | } |
Vasilis Liaskovitis | 486b463 | 2018-10-10 16:14:55 +0200 | [diff] [blame] | 7799 | |
| 7800 | /** Resolve an internal compositor error by disconnecting the client. |
| 7801 | * |
| 7802 | * This function is used in cases when the wl_buffer turns out |
| 7803 | * unusable and there is no fallback path. |
| 7804 | * |
| 7805 | * It is possible the fault is caused by a compositor bug, the underlying |
| 7806 | * graphics stack bug or normal behaviour, or perhaps a client mistake. |
| 7807 | * In any case, the options are to either composite garbage or nothing, |
| 7808 | * or disconnect the client. This is a helper function for the latter. |
| 7809 | * |
| 7810 | * The error is sent as an INVALID_OBJECT error on the client's wl_display. |
| 7811 | * |
| 7812 | * \param buffer The weston buffer that is unusable. |
| 7813 | * \param msg A custom error message attached to the protocol error. |
| 7814 | */ |
| 7815 | WL_EXPORT void |
| 7816 | weston_buffer_send_server_error(struct weston_buffer *buffer, |
| 7817 | const char *msg) |
| 7818 | { |
| 7819 | struct wl_client *client; |
| 7820 | struct wl_resource *display_resource; |
| 7821 | uint32_t id; |
| 7822 | |
| 7823 | assert(buffer->resource); |
| 7824 | id = wl_resource_get_id(buffer->resource); |
| 7825 | client = wl_resource_get_client(buffer->resource); |
| 7826 | display_resource = wl_client_get_object(client, 1); |
| 7827 | |
| 7828 | assert(display_resource); |
| 7829 | wl_resource_post_error(display_resource, |
| 7830 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 7831 | "server error with " |
| 7832 | "wl_buffer@%u: %s", id, msg); |
| 7833 | } |
Ankit Nautiyal | 93dde24 | 2019-07-08 11:46:42 +0530 | [diff] [blame] | 7834 | |
| 7835 | WL_EXPORT void |
| 7836 | weston_output_disable_planes_incr(struct weston_output *output) |
| 7837 | { |
| 7838 | output->disable_planes++; |
Ankit Nautiyal | 4fd3813 | 2019-07-08 15:12:19 +0530 | [diff] [blame] | 7839 | /* |
| 7840 | * If disable_planes changes from 0 to non-zero, it means some type of |
| 7841 | * recording of content has started, and therefore protection level of |
| 7842 | * the protected surfaces must be updated to avoid the recording of |
| 7843 | * the protected content. |
| 7844 | */ |
| 7845 | if (output->disable_planes == 1) |
| 7846 | weston_schedule_surface_protection_update(output->compositor); |
Ankit Nautiyal | 93dde24 | 2019-07-08 11:46:42 +0530 | [diff] [blame] | 7847 | } |
| 7848 | |
| 7849 | WL_EXPORT void |
| 7850 | weston_output_disable_planes_decr(struct weston_output *output) |
| 7851 | { |
| 7852 | output->disable_planes--; |
Ankit Nautiyal | 4fd3813 | 2019-07-08 15:12:19 +0530 | [diff] [blame] | 7853 | /* |
| 7854 | * If disable_planes changes from non-zero to 0, it means no content |
| 7855 | * recording is going on any more, and the protected and surfaces can be |
| 7856 | * shown without any apprehensions about content being recorded. |
| 7857 | */ |
| 7858 | if (output->disable_planes == 0) |
| 7859 | weston_schedule_surface_protection_update(output->compositor); |
| 7860 | |
Ankit Nautiyal | 93dde24 | 2019-07-08 11:46:42 +0530 | [diff] [blame] | 7861 | } |