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 | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 78 | /** |
| 79 | * \defgroup head Head |
| 80 | * \defgroup output Output |
| 81 | * \defgroup compositor Compositor |
| 82 | */ |
| 83 | |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 84 | #define DEFAULT_REPAINT_WINDOW 7 /* milliseconds */ |
| 85 | |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 86 | static void |
Pekka Paalanen | d72bad2 | 2017-03-29 17:01:41 +0300 | [diff] [blame] | 87 | weston_output_update_matrix(struct weston_output *output); |
| 88 | |
| 89 | static void |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 90 | weston_output_transform_scale_init(struct weston_output *output, |
| 91 | uint32_t transform, uint32_t scale); |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 92 | |
Rob Bradford | 27b1793 | 2013-06-26 18:08:46 +0100 | [diff] [blame] | 93 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 94 | weston_compositor_build_view_list(struct weston_compositor *compositor); |
Rob Bradford | 27b1793 | 2013-06-26 18:08:46 +0100 | [diff] [blame] | 95 | |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 96 | static char * |
| 97 | weston_output_create_heads_string(struct weston_output *output); |
| 98 | |
Pekka Paalanen | 6528c03 | 2017-03-28 15:27:10 +0300 | [diff] [blame] | 99 | /** Send wl_output events for mode and scale changes |
| 100 | * |
| 101 | * \param head Send on all resources bound to this head. |
| 102 | * \param mode_changed If true, send the current mode. |
| 103 | * \param scale_changed If true, send the current scale. |
| 104 | */ |
| 105 | static void |
| 106 | weston_mode_switch_send_events(struct weston_head *head, |
| 107 | bool mode_changed, bool scale_changed) |
| 108 | { |
| 109 | struct weston_output *output = head->output; |
| 110 | struct wl_resource *resource; |
| 111 | int version; |
| 112 | |
| 113 | wl_resource_for_each(resource, &head->resource_list) { |
| 114 | if (mode_changed) { |
| 115 | wl_output_send_mode(resource, |
| 116 | output->current_mode->flags, |
| 117 | output->current_mode->width, |
| 118 | output->current_mode->height, |
| 119 | output->current_mode->refresh); |
| 120 | } |
| 121 | |
| 122 | version = wl_resource_get_version(resource); |
| 123 | if (version >= WL_OUTPUT_SCALE_SINCE_VERSION && scale_changed) |
| 124 | wl_output_send_scale(resource, output->current_scale); |
| 125 | |
| 126 | if (version >= WL_OUTPUT_DONE_SINCE_VERSION) |
| 127 | wl_output_send_done(resource); |
| 128 | } |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 129 | wl_resource_for_each(resource, &head->xdg_output_resource_list) { |
| 130 | zxdg_output_v1_send_logical_position(resource, |
| 131 | output->x, |
| 132 | output->y); |
| 133 | zxdg_output_v1_send_logical_size(resource, |
| 134 | output->width, |
| 135 | output->height); |
| 136 | zxdg_output_v1_send_done(resource); |
| 137 | } |
Pekka Paalanen | 6528c03 | 2017-03-28 15:27:10 +0300 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | static void |
| 141 | weston_mode_switch_finish(struct weston_output *output, |
| 142 | int mode_changed, int scale_changed) |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 143 | { |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 144 | struct weston_seat *seat; |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 145 | struct weston_head *head; |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 146 | pixman_region32_t old_output_region; |
Alexander Larsson | 355748e | 2013-05-28 16:23:38 +0200 | [diff] [blame] | 147 | |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 148 | pixman_region32_init(&old_output_region); |
| 149 | pixman_region32_copy(&old_output_region, &output->region); |
| 150 | |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 151 | /* Update output region and transformation matrix */ |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 152 | 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] | 153 | |
| 154 | pixman_region32_init(&output->previous_damage); |
| 155 | pixman_region32_init_rect(&output->region, output->x, output->y, |
| 156 | output->width, output->height); |
| 157 | |
| 158 | weston_output_update_matrix(output); |
| 159 | |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 160 | /* If a pointer falls outside the outputs new geometry, move it to its |
| 161 | * lower-right corner */ |
| 162 | wl_list_for_each(seat, &output->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 163 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 164 | int32_t x, y; |
| 165 | |
| 166 | if (!pointer) |
| 167 | continue; |
| 168 | |
| 169 | x = wl_fixed_to_int(pointer->x); |
| 170 | y = wl_fixed_to_int(pointer->y); |
| 171 | |
| 172 | if (!pixman_region32_contains_point(&old_output_region, |
| 173 | x, y, NULL) || |
| 174 | pixman_region32_contains_point(&output->region, |
| 175 | x, y, NULL)) |
| 176 | continue; |
| 177 | |
| 178 | if (x >= output->x + output->width) |
| 179 | x = output->x + output->width - 1; |
| 180 | if (y >= output->y + output->height) |
| 181 | y = output->y + output->height - 1; |
| 182 | |
| 183 | pointer->x = wl_fixed_from_int(x); |
| 184 | pointer->y = wl_fixed_from_int(y); |
| 185 | } |
| 186 | |
| 187 | pixman_region32_fini(&old_output_region); |
| 188 | |
Derek Foreman | dd4cd33 | 2014-11-10 10:29:59 -0600 | [diff] [blame] | 189 | if (!mode_changed && !scale_changed) |
| 190 | return; |
| 191 | |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 192 | /* notify clients of the changes */ |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 193 | wl_list_for_each(head, &output->head_list, output_link) |
| 194 | weston_mode_switch_send_events(head, |
| 195 | mode_changed, scale_changed); |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 196 | } |
| 197 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 198 | static void |
| 199 | weston_compositor_reflow_outputs(struct weston_compositor *compositor, |
| 200 | struct weston_output *resized_output, int delta_width); |
| 201 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 202 | /** |
| 203 | * \ingroup output |
| 204 | */ |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 205 | WL_EXPORT int |
| 206 | weston_output_mode_set_native(struct weston_output *output, |
| 207 | struct weston_mode *mode, |
| 208 | int32_t scale) |
| 209 | { |
| 210 | int ret; |
| 211 | int mode_changed = 0, scale_changed = 0; |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 212 | int32_t old_width; |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 213 | |
| 214 | if (!output->switch_mode) |
| 215 | return -1; |
| 216 | |
| 217 | if (!output->original_mode) { |
| 218 | mode_changed = 1; |
| 219 | ret = output->switch_mode(output, mode); |
| 220 | if (ret < 0) |
| 221 | return ret; |
| 222 | if (output->current_scale != scale) { |
| 223 | scale_changed = 1; |
| 224 | output->current_scale = scale; |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 228 | old_width = output->width; |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 229 | output->native_mode = mode; |
| 230 | output->native_scale = scale; |
| 231 | |
| 232 | weston_mode_switch_finish(output, mode_changed, scale_changed); |
| 233 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 234 | if (mode_changed || scale_changed) { |
| 235 | weston_compositor_reflow_outputs(output->compositor, output, output->width - old_width); |
| 236 | |
| 237 | wl_signal_emit(&output->compositor->output_resized_signal, output); |
| 238 | } |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 239 | return 0; |
| 240 | } |
| 241 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 242 | /** |
| 243 | * \ingroup output |
| 244 | */ |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 245 | WL_EXPORT int |
| 246 | weston_output_mode_switch_to_native(struct weston_output *output) |
| 247 | { |
| 248 | int ret; |
| 249 | int mode_changed = 0, scale_changed = 0; |
| 250 | |
| 251 | if (!output->switch_mode) |
| 252 | return -1; |
| 253 | |
| 254 | if (!output->original_mode) { |
| 255 | weston_log("already in the native mode\n"); |
| 256 | return -1; |
| 257 | } |
| 258 | /* the non fullscreen clients haven't seen a mode set since we |
| 259 | * switched into a temporary, so we need to notify them if the |
| 260 | * mode at that time is different from the native mode now. |
| 261 | */ |
| 262 | mode_changed = (output->original_mode != output->native_mode); |
| 263 | scale_changed = (output->original_scale != output->native_scale); |
| 264 | |
| 265 | ret = output->switch_mode(output, output->native_mode); |
| 266 | if (ret < 0) |
| 267 | return ret; |
| 268 | |
| 269 | output->current_scale = output->native_scale; |
| 270 | |
| 271 | output->original_mode = NULL; |
| 272 | output->original_scale = 0; |
| 273 | |
| 274 | weston_mode_switch_finish(output, mode_changed, scale_changed); |
| 275 | |
| 276 | return 0; |
| 277 | } |
| 278 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 279 | /** |
| 280 | * \ingroup output |
| 281 | */ |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 282 | WL_EXPORT int |
| 283 | weston_output_mode_switch_to_temporary(struct weston_output *output, |
| 284 | struct weston_mode *mode, |
| 285 | int32_t scale) |
| 286 | { |
| 287 | int ret; |
| 288 | |
| 289 | if (!output->switch_mode) |
| 290 | return -1; |
| 291 | |
| 292 | /* original_mode is the last mode non full screen clients have seen, |
| 293 | * so we shouldn't change it if we already have one set. |
| 294 | */ |
| 295 | if (!output->original_mode) { |
| 296 | output->original_mode = output->native_mode; |
| 297 | output->original_scale = output->native_scale; |
| 298 | } |
| 299 | ret = output->switch_mode(output, mode); |
| 300 | if (ret < 0) |
| 301 | return ret; |
| 302 | |
| 303 | output->current_scale = scale; |
| 304 | |
| 305 | weston_mode_switch_finish(output, 0, 0); |
| 306 | |
| 307 | return 0; |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 308 | } |
| 309 | |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 310 | static void |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 311 | region_init_infinite(pixman_region32_t *region) |
| 312 | { |
| 313 | pixman_region32_init_rect(region, INT32_MIN, INT32_MIN, |
| 314 | UINT32_MAX, UINT32_MAX); |
| 315 | } |
| 316 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 317 | static struct weston_subsurface * |
| 318 | weston_surface_to_subsurface(struct weston_surface *surface); |
| 319 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 320 | WL_EXPORT struct weston_view * |
| 321 | weston_view_create(struct weston_surface *surface) |
| 322 | { |
| 323 | struct weston_view *view; |
| 324 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 325 | view = zalloc(sizeof *view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 326 | if (view == NULL) |
| 327 | return NULL; |
| 328 | |
| 329 | view->surface = surface; |
Daniel Stone | fb4869d | 2016-12-09 16:27:54 +0000 | [diff] [blame] | 330 | view->plane = &surface->compositor->primary_plane; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 331 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 332 | /* Assign to surface */ |
| 333 | wl_list_insert(&surface->views, &view->surface_link); |
| 334 | |
| 335 | wl_signal_init(&view->destroy_signal); |
| 336 | wl_list_init(&view->link); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 337 | wl_list_init(&view->layer_link.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 338 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 339 | pixman_region32_init(&view->clip); |
| 340 | |
| 341 | view->alpha = 1.0; |
| 342 | pixman_region32_init(&view->transform.opaque); |
| 343 | |
| 344 | wl_list_init(&view->geometry.transformation_list); |
| 345 | wl_list_insert(&view->geometry.transformation_list, |
| 346 | &view->transform.position.link); |
| 347 | weston_matrix_init(&view->transform.position.matrix); |
| 348 | wl_list_init(&view->geometry.child_list); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 349 | pixman_region32_init(&view->geometry.scissor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 350 | pixman_region32_init(&view->transform.boundingbox); |
| 351 | view->transform.dirty = 1; |
| 352 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 353 | return view; |
| 354 | } |
| 355 | |
Jason Ekstrand | 108865d | 2014-06-26 10:04:49 -0700 | [diff] [blame] | 356 | struct weston_frame_callback { |
| 357 | struct wl_resource *resource; |
| 358 | struct wl_list link; |
| 359 | }; |
| 360 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 361 | struct weston_presentation_feedback { |
| 362 | struct wl_resource *resource; |
| 363 | |
| 364 | /* XXX: could use just wl_resource_get_link() instead */ |
| 365 | struct wl_list link; |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 366 | |
| 367 | /* The per-surface feedback flags */ |
| 368 | uint32_t psf_flags; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 369 | }; |
| 370 | |
| 371 | static void |
| 372 | weston_presentation_feedback_discard( |
| 373 | struct weston_presentation_feedback *feedback) |
| 374 | { |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 375 | wp_presentation_feedback_send_discarded(feedback->resource); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 376 | wl_resource_destroy(feedback->resource); |
| 377 | } |
| 378 | |
| 379 | static void |
| 380 | weston_presentation_feedback_discard_list(struct wl_list *list) |
| 381 | { |
| 382 | struct weston_presentation_feedback *feedback, *tmp; |
| 383 | |
| 384 | wl_list_for_each_safe(feedback, tmp, list, link) |
| 385 | weston_presentation_feedback_discard(feedback); |
| 386 | } |
| 387 | |
| 388 | static void |
| 389 | weston_presentation_feedback_present( |
| 390 | struct weston_presentation_feedback *feedback, |
| 391 | struct weston_output *output, |
| 392 | uint32_t refresh_nsec, |
| 393 | const struct timespec *ts, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 394 | uint64_t seq, |
| 395 | uint32_t flags) |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 396 | { |
| 397 | struct wl_client *client = wl_resource_get_client(feedback->resource); |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 398 | struct weston_head *head; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 399 | struct wl_resource *o; |
Alexandros Frantzis | 10d708d | 2017-12-13 13:27:54 +0200 | [diff] [blame] | 400 | uint32_t tv_sec_hi; |
| 401 | uint32_t tv_sec_lo; |
| 402 | uint32_t tv_nsec; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 403 | bool done = false; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 404 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 405 | wl_list_for_each(head, &output->head_list, output_link) { |
| 406 | wl_resource_for_each(o, &head->resource_list) { |
| 407 | if (wl_resource_get_client(o) != client) |
| 408 | continue; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 409 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 410 | wp_presentation_feedback_send_sync_output(feedback->resource, o); |
| 411 | done = true; |
| 412 | } |
| 413 | |
| 414 | /* For clone mode, send it for just one wl_output global, |
| 415 | * they are all equivalent anyway. |
| 416 | */ |
| 417 | if (done) |
| 418 | break; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 419 | } |
| 420 | |
Alexandros Frantzis | 10d708d | 2017-12-13 13:27:54 +0200 | [diff] [blame] | 421 | timespec_to_proto(ts, &tv_sec_hi, &tv_sec_lo, &tv_nsec); |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 422 | wp_presentation_feedback_send_presented(feedback->resource, |
Alexandros Frantzis | 10d708d | 2017-12-13 13:27:54 +0200 | [diff] [blame] | 423 | tv_sec_hi, tv_sec_lo, tv_nsec, |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 424 | refresh_nsec, |
| 425 | seq >> 32, seq & 0xffffffff, |
| 426 | flags | feedback->psf_flags); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 427 | wl_resource_destroy(feedback->resource); |
| 428 | } |
| 429 | |
| 430 | static void |
| 431 | weston_presentation_feedback_present_list(struct wl_list *list, |
| 432 | struct weston_output *output, |
| 433 | uint32_t refresh_nsec, |
| 434 | const struct timespec *ts, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 435 | uint64_t seq, |
| 436 | uint32_t flags) |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 437 | { |
| 438 | struct weston_presentation_feedback *feedback, *tmp; |
| 439 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 440 | assert(!(flags & WP_PRESENTATION_FEEDBACK_INVALID) || |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 441 | wl_list_empty(list)); |
| 442 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 443 | wl_list_for_each_safe(feedback, tmp, list, link) |
| 444 | weston_presentation_feedback_present(feedback, output, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 445 | refresh_nsec, ts, seq, |
| 446 | flags); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 447 | } |
| 448 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 449 | static void |
| 450 | surface_state_handle_buffer_destroy(struct wl_listener *listener, void *data) |
| 451 | { |
| 452 | struct weston_surface_state *state = |
| 453 | container_of(listener, struct weston_surface_state, |
| 454 | buffer_destroy_listener); |
| 455 | |
| 456 | state->buffer = NULL; |
| 457 | } |
| 458 | |
| 459 | static void |
| 460 | weston_surface_state_init(struct weston_surface_state *state) |
| 461 | { |
| 462 | state->newly_attached = 0; |
| 463 | state->buffer = NULL; |
| 464 | state->buffer_destroy_listener.notify = |
| 465 | surface_state_handle_buffer_destroy; |
| 466 | state->sx = 0; |
| 467 | state->sy = 0; |
| 468 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 469 | pixman_region32_init(&state->damage_surface); |
| 470 | pixman_region32_init(&state->damage_buffer); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 471 | pixman_region32_init(&state->opaque); |
| 472 | region_init_infinite(&state->input); |
| 473 | |
| 474 | wl_list_init(&state->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 475 | wl_list_init(&state->feedback_list); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 476 | |
| 477 | state->buffer_viewport.buffer.transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 478 | state->buffer_viewport.buffer.scale = 1; |
| 479 | state->buffer_viewport.buffer.src_width = wl_fixed_from_int(-1); |
| 480 | state->buffer_viewport.surface.width = -1; |
| 481 | state->buffer_viewport.changed = 0; |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 482 | |
| 483 | state->acquire_fence_fd = -1; |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 484 | |
| 485 | state->desired_protection = WESTON_HDCP_DISABLE; |
Ankit Nautiyal | 5cfe03c | 2019-03-28 15:05:42 +0530 | [diff] [blame] | 486 | state->protection_mode = WESTON_SURFACE_PROTECTION_MODE_RELAXED; |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | static void |
| 490 | weston_surface_state_fini(struct weston_surface_state *state) |
| 491 | { |
| 492 | struct weston_frame_callback *cb, *next; |
| 493 | |
| 494 | wl_list_for_each_safe(cb, next, |
| 495 | &state->frame_callback_list, link) |
| 496 | wl_resource_destroy(cb->resource); |
| 497 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 498 | weston_presentation_feedback_discard_list(&state->feedback_list); |
| 499 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 500 | pixman_region32_fini(&state->input); |
| 501 | pixman_region32_fini(&state->opaque); |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 502 | pixman_region32_fini(&state->damage_surface); |
| 503 | pixman_region32_fini(&state->damage_buffer); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 504 | |
| 505 | if (state->buffer) |
| 506 | wl_list_remove(&state->buffer_destroy_listener.link); |
| 507 | state->buffer = NULL; |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 508 | |
| 509 | fd_clear(&state->acquire_fence_fd); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 510 | weston_buffer_release_reference(&state->buffer_release_ref, NULL); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | static void |
| 514 | weston_surface_state_set_buffer(struct weston_surface_state *state, |
| 515 | struct weston_buffer *buffer) |
| 516 | { |
| 517 | if (state->buffer == buffer) |
| 518 | return; |
| 519 | |
| 520 | if (state->buffer) |
| 521 | wl_list_remove(&state->buffer_destroy_listener.link); |
| 522 | state->buffer = buffer; |
| 523 | if (state->buffer) |
| 524 | wl_signal_add(&state->buffer->destroy_signal, |
| 525 | &state->buffer_destroy_listener); |
| 526 | } |
| 527 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 528 | WL_EXPORT struct weston_surface * |
Kristian Høgsberg | 18c9300 | 2012-01-27 11:58:31 -0500 | [diff] [blame] | 529 | weston_surface_create(struct weston_compositor *compositor) |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 530 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 531 | struct weston_surface *surface; |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 532 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 533 | surface = zalloc(sizeof *surface); |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 534 | if (surface == NULL) |
| 535 | return NULL; |
| 536 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 537 | wl_signal_init(&surface->destroy_signal); |
Jonas Ådahl | 5d9ca27 | 2016-07-22 17:48:03 +0800 | [diff] [blame] | 538 | wl_signal_init(&surface->commit_signal); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 539 | |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 540 | surface->compositor = compositor; |
Giulio Camuffo | 13b85bd | 2013-08-13 23:10:14 +0200 | [diff] [blame] | 541 | surface->ref_count = 1; |
Kristian Høgsberg | 27803c6 | 2010-06-06 22:23:21 -0400 | [diff] [blame] | 542 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 543 | surface->buffer_viewport.buffer.transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 544 | surface->buffer_viewport.buffer.scale = 1; |
Pekka Paalanen | f0cad48 | 2014-03-14 14:38:16 +0200 | [diff] [blame] | 545 | surface->buffer_viewport.buffer.src_width = wl_fixed_from_int(-1); |
| 546 | surface->buffer_viewport.surface.width = -1; |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 547 | |
| 548 | weston_surface_state_init(&surface->pending); |
| 549 | |
Kristian Høgsberg | 20300ba | 2011-06-23 20:29:12 -0400 | [diff] [blame] | 550 | pixman_region32_init(&surface->damage); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 551 | pixman_region32_init(&surface->opaque); |
Pekka Paalanen | 8ec4ab6 | 2012-10-10 12:49:32 +0300 | [diff] [blame] | 552 | region_init_infinite(&surface->input); |
Kristian Høgsberg | 20300ba | 2011-06-23 20:29:12 -0400 | [diff] [blame] | 553 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 554 | wl_list_init(&surface->views); |
| 555 | |
| 556 | wl_list_init(&surface->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 557 | wl_list_init(&surface->feedback_list); |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 558 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 559 | wl_list_init(&surface->subsurface_list); |
| 560 | wl_list_init(&surface->subsurface_list_pending); |
| 561 | |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 562 | weston_matrix_init(&surface->buffer_to_surface_matrix); |
| 563 | weston_matrix_init(&surface->surface_to_buffer_matrix); |
| 564 | |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 565 | wl_list_init(&surface->pointer_constraints); |
| 566 | |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 567 | surface->acquire_fence_fd = -1; |
| 568 | |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 569 | surface->desired_protection = WESTON_HDCP_DISABLE; |
Ankit Nautiyal | 5cfe03c | 2019-03-28 15:05:42 +0530 | [diff] [blame] | 570 | surface->current_protection = WESTON_HDCP_DISABLE; |
| 571 | surface->protection_mode = WESTON_SURFACE_PROTECTION_MODE_RELAXED; |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 572 | |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 573 | return surface; |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 574 | } |
| 575 | |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 576 | WL_EXPORT void |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 577 | weston_surface_set_color(struct weston_surface *surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 578 | float red, float green, float blue, float alpha) |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 579 | { |
John Kåre Alsaker | 878f449 | 2012-11-13 19:10:23 +0100 | [diff] [blame] | 580 | surface->compositor->renderer->surface_set_color(surface, red, green, blue, alpha); |
Philipp Zabel | 195dade | 2018-09-03 19:44:59 +0200 | [diff] [blame] | 581 | surface->is_opaque = !(alpha < 1.0); |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 582 | } |
| 583 | |
Kristian Høgsberg | e4c1a5f | 2012-06-18 13:17:32 -0400 | [diff] [blame] | 584 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 585 | weston_view_to_global_float(struct weston_view *view, |
| 586 | float sx, float sy, float *x, float *y) |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 587 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 588 | if (view->transform.enabled) { |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 589 | struct weston_vector v = { { sx, sy, 0.0f, 1.0f } }; |
| 590 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 591 | weston_matrix_transform(&view->transform.matrix, &v); |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 592 | |
| 593 | if (fabsf(v.f[3]) < 1e-6) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 594 | weston_log("warning: numerical instability in " |
Scott Moreau | 088c62e | 2013-02-11 04:45:38 -0700 | [diff] [blame] | 595 | "%s(), divisor = %g\n", __func__, |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 596 | v.f[3]); |
| 597 | *x = 0; |
| 598 | *y = 0; |
| 599 | return; |
| 600 | } |
| 601 | |
| 602 | *x = v.f[0] / v.f[3]; |
| 603 | *y = v.f[1] / v.f[3]; |
| 604 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 605 | *x = sx + view->geometry.x; |
| 606 | *y = sy + view->geometry.y; |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 607 | } |
| 608 | } |
| 609 | |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 610 | WL_EXPORT void |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 611 | weston_transformed_coord(int width, int height, |
| 612 | enum wl_output_transform transform, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 613 | int32_t scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 614 | float sx, float sy, float *bx, float *by) |
| 615 | { |
| 616 | switch (transform) { |
| 617 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 618 | default: |
| 619 | *bx = sx; |
| 620 | *by = sy; |
| 621 | break; |
| 622 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 623 | *bx = width - sx; |
| 624 | *by = sy; |
| 625 | break; |
| 626 | case WL_OUTPUT_TRANSFORM_90: |
| 627 | *bx = height - sy; |
| 628 | *by = sx; |
| 629 | break; |
| 630 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 631 | *bx = height - sy; |
| 632 | *by = width - sx; |
| 633 | break; |
| 634 | case WL_OUTPUT_TRANSFORM_180: |
| 635 | *bx = width - sx; |
| 636 | *by = height - sy; |
| 637 | break; |
| 638 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 639 | *bx = sx; |
| 640 | *by = height - sy; |
| 641 | break; |
| 642 | case WL_OUTPUT_TRANSFORM_270: |
| 643 | *bx = sy; |
| 644 | *by = width - sx; |
| 645 | break; |
| 646 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 647 | *bx = sy; |
| 648 | *by = sx; |
| 649 | break; |
| 650 | } |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 651 | |
| 652 | *bx *= scale; |
| 653 | *by *= scale; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | WL_EXPORT pixman_box32_t |
| 657 | weston_transformed_rect(int width, int height, |
| 658 | enum wl_output_transform transform, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 659 | int32_t scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 660 | pixman_box32_t rect) |
| 661 | { |
| 662 | float x1, x2, y1, y2; |
| 663 | |
| 664 | pixman_box32_t ret; |
| 665 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 666 | weston_transformed_coord(width, height, transform, scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 667 | rect.x1, rect.y1, &x1, &y1); |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 668 | weston_transformed_coord(width, height, transform, scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 669 | rect.x2, rect.y2, &x2, &y2); |
| 670 | |
| 671 | if (x1 <= x2) { |
| 672 | ret.x1 = x1; |
| 673 | ret.x2 = x2; |
| 674 | } else { |
| 675 | ret.x1 = x2; |
| 676 | ret.x2 = x1; |
| 677 | } |
| 678 | |
| 679 | if (y1 <= y2) { |
| 680 | ret.y1 = y1; |
| 681 | ret.y2 = y2; |
| 682 | } else { |
| 683 | ret.y1 = y2; |
| 684 | ret.y2 = y1; |
| 685 | } |
| 686 | |
| 687 | return ret; |
| 688 | } |
| 689 | |
Derek Foreman | bc9a61c | 2015-11-18 16:32:30 -0600 | [diff] [blame] | 690 | /** Transform a region by a matrix, restricted to axis-aligned transformations |
| 691 | * |
| 692 | * Warning: This function does not work for projective, affine, or matrices |
| 693 | * that encode arbitrary rotations. Only 90-degree step rotations are |
| 694 | * supported. |
| 695 | */ |
| 696 | WL_EXPORT void |
| 697 | weston_matrix_transform_region(pixman_region32_t *dest, |
| 698 | struct weston_matrix *matrix, |
| 699 | pixman_region32_t *src) |
| 700 | { |
| 701 | pixman_box32_t *src_rects, *dest_rects; |
| 702 | int nrects, i; |
| 703 | |
| 704 | src_rects = pixman_region32_rectangles(src, &nrects); |
| 705 | dest_rects = malloc(nrects * sizeof(*dest_rects)); |
| 706 | if (!dest_rects) |
| 707 | return; |
| 708 | |
| 709 | for (i = 0; i < nrects; i++) { |
| 710 | struct weston_vector vec1 = {{ |
| 711 | src_rects[i].x1, src_rects[i].y1, 0, 1 |
| 712 | }}; |
| 713 | weston_matrix_transform(matrix, &vec1); |
| 714 | vec1.f[0] /= vec1.f[3]; |
| 715 | vec1.f[1] /= vec1.f[3]; |
| 716 | |
| 717 | struct weston_vector vec2 = {{ |
| 718 | src_rects[i].x2, src_rects[i].y2, 0, 1 |
| 719 | }}; |
| 720 | weston_matrix_transform(matrix, &vec2); |
| 721 | vec2.f[0] /= vec2.f[3]; |
| 722 | vec2.f[1] /= vec2.f[3]; |
| 723 | |
| 724 | if (vec1.f[0] < vec2.f[0]) { |
| 725 | dest_rects[i].x1 = floor(vec1.f[0]); |
| 726 | dest_rects[i].x2 = ceil(vec2.f[0]); |
| 727 | } else { |
| 728 | dest_rects[i].x1 = floor(vec2.f[0]); |
| 729 | dest_rects[i].x2 = ceil(vec1.f[0]); |
| 730 | } |
| 731 | |
Derek Foreman | bc9a61c | 2015-11-18 16:32:30 -0600 | [diff] [blame] | 732 | if (vec1.f[1] < vec2.f[1]) { |
| 733 | dest_rects[i].y1 = floor(vec1.f[1]); |
| 734 | dest_rects[i].y2 = ceil(vec2.f[1]); |
| 735 | } else { |
| 736 | dest_rects[i].y1 = floor(vec2.f[1]); |
| 737 | dest_rects[i].y2 = ceil(vec1.f[1]); |
| 738 | } |
| 739 | } |
| 740 | |
| 741 | pixman_region32_clear(dest); |
| 742 | pixman_region32_init_rects(dest, dest_rects, nrects); |
| 743 | free(dest_rects); |
| 744 | } |
| 745 | |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 746 | WL_EXPORT void |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 747 | weston_transformed_region(int width, int height, |
| 748 | enum wl_output_transform transform, |
| 749 | int32_t scale, |
| 750 | pixman_region32_t *src, pixman_region32_t *dest) |
| 751 | { |
| 752 | pixman_box32_t *src_rects, *dest_rects; |
| 753 | int nrects, i; |
| 754 | |
| 755 | if (transform == WL_OUTPUT_TRANSFORM_NORMAL && scale == 1) { |
| 756 | if (src != dest) |
| 757 | pixman_region32_copy(dest, src); |
| 758 | return; |
| 759 | } |
| 760 | |
| 761 | src_rects = pixman_region32_rectangles(src, &nrects); |
| 762 | dest_rects = malloc(nrects * sizeof(*dest_rects)); |
| 763 | if (!dest_rects) |
| 764 | return; |
| 765 | |
| 766 | if (transform == WL_OUTPUT_TRANSFORM_NORMAL) { |
| 767 | memcpy(dest_rects, src_rects, nrects * sizeof(*dest_rects)); |
| 768 | } else { |
| 769 | for (i = 0; i < nrects; i++) { |
| 770 | switch (transform) { |
| 771 | default: |
| 772 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 773 | dest_rects[i].x1 = src_rects[i].x1; |
| 774 | dest_rects[i].y1 = src_rects[i].y1; |
| 775 | dest_rects[i].x2 = src_rects[i].x2; |
| 776 | dest_rects[i].y2 = src_rects[i].y2; |
| 777 | break; |
| 778 | case WL_OUTPUT_TRANSFORM_90: |
| 779 | dest_rects[i].x1 = height - src_rects[i].y2; |
| 780 | dest_rects[i].y1 = src_rects[i].x1; |
| 781 | dest_rects[i].x2 = height - src_rects[i].y1; |
| 782 | dest_rects[i].y2 = src_rects[i].x2; |
| 783 | break; |
| 784 | case WL_OUTPUT_TRANSFORM_180: |
| 785 | dest_rects[i].x1 = width - src_rects[i].x2; |
| 786 | dest_rects[i].y1 = height - src_rects[i].y2; |
| 787 | dest_rects[i].x2 = width - src_rects[i].x1; |
| 788 | dest_rects[i].y2 = height - src_rects[i].y1; |
| 789 | break; |
| 790 | case WL_OUTPUT_TRANSFORM_270: |
| 791 | dest_rects[i].x1 = src_rects[i].y1; |
| 792 | dest_rects[i].y1 = width - src_rects[i].x2; |
| 793 | dest_rects[i].x2 = src_rects[i].y2; |
| 794 | dest_rects[i].y2 = width - src_rects[i].x1; |
| 795 | break; |
| 796 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 797 | dest_rects[i].x1 = width - src_rects[i].x2; |
| 798 | dest_rects[i].y1 = src_rects[i].y1; |
| 799 | dest_rects[i].x2 = width - src_rects[i].x1; |
| 800 | dest_rects[i].y2 = src_rects[i].y2; |
| 801 | break; |
| 802 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 803 | dest_rects[i].x1 = height - src_rects[i].y2; |
| 804 | dest_rects[i].y1 = width - src_rects[i].x2; |
| 805 | dest_rects[i].x2 = height - src_rects[i].y1; |
| 806 | dest_rects[i].y2 = width - src_rects[i].x1; |
| 807 | break; |
| 808 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 809 | dest_rects[i].x1 = src_rects[i].x1; |
| 810 | dest_rects[i].y1 = height - src_rects[i].y2; |
| 811 | dest_rects[i].x2 = src_rects[i].x2; |
| 812 | dest_rects[i].y2 = height - src_rects[i].y1; |
| 813 | break; |
| 814 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 815 | dest_rects[i].x1 = src_rects[i].y1; |
| 816 | dest_rects[i].y1 = src_rects[i].x1; |
| 817 | dest_rects[i].x2 = src_rects[i].y2; |
| 818 | dest_rects[i].y2 = src_rects[i].x2; |
| 819 | break; |
| 820 | } |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | if (scale != 1) { |
| 825 | for (i = 0; i < nrects; i++) { |
| 826 | dest_rects[i].x1 *= scale; |
| 827 | dest_rects[i].x2 *= scale; |
| 828 | dest_rects[i].y1 *= scale; |
| 829 | dest_rects[i].y2 *= scale; |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | pixman_region32_clear(dest); |
| 834 | pixman_region32_init_rects(dest, dest_rects, nrects); |
| 835 | free(dest_rects); |
| 836 | } |
| 837 | |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 838 | static void |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 839 | viewport_surface_to_buffer(struct weston_surface *surface, |
| 840 | float sx, float sy, float *bx, float *by) |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 841 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 842 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 843 | double src_width, src_height; |
| 844 | double src_x, src_y; |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 845 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 846 | if (vp->buffer.src_width == wl_fixed_from_int(-1)) { |
| 847 | if (vp->surface.width == -1) { |
| 848 | *bx = sx; |
| 849 | *by = sy; |
| 850 | return; |
| 851 | } |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 852 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 853 | src_x = 0.0; |
| 854 | src_y = 0.0; |
| 855 | src_width = surface->width_from_buffer; |
| 856 | src_height = surface->height_from_buffer; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 857 | } else { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 858 | src_x = wl_fixed_to_double(vp->buffer.src_x); |
| 859 | src_y = wl_fixed_to_double(vp->buffer.src_y); |
| 860 | src_width = wl_fixed_to_double(vp->buffer.src_width); |
| 861 | src_height = wl_fixed_to_double(vp->buffer.src_height); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 862 | } |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 863 | |
| 864 | *bx = sx * src_width / surface->width + src_x; |
| 865 | *by = sy * src_height / surface->height + src_y; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 866 | } |
| 867 | |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 868 | WL_EXPORT void |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 869 | weston_surface_to_buffer_float(struct weston_surface *surface, |
| 870 | float sx, float sy, float *bx, float *by) |
| 871 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 872 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
| 873 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 874 | /* first transform coordinates if the viewport is set */ |
| 875 | viewport_surface_to_buffer(surface, sx, sy, bx, by); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 876 | |
Jason Ekstrand | d0cebc3 | 2014-04-21 20:56:46 -0500 | [diff] [blame] | 877 | weston_transformed_coord(surface->width_from_buffer, |
| 878 | surface->height_from_buffer, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 879 | vp->buffer.transform, vp->buffer.scale, |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 880 | *bx, *by, bx, by); |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 881 | } |
| 882 | |
Derek Foreman | 9973967 | 2015-12-03 16:38:11 -0600 | [diff] [blame] | 883 | /** Transform a rectangle from surface coordinates to buffer coordinates |
| 884 | * |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 885 | * \param surface The surface to fetch wp_viewport and buffer transformation |
Derek Foreman | 9973967 | 2015-12-03 16:38:11 -0600 | [diff] [blame] | 886 | * from. |
| 887 | * \param rect The rectangle to transform. |
| 888 | * \return The transformed rectangle. |
| 889 | * |
| 890 | * Viewport and buffer transformations can only do translation, scaling, |
| 891 | * and rotations in 90-degree steps. Therefore the only loss in the |
| 892 | * conversion is coordinate rounding. |
| 893 | * |
| 894 | * However, some coordinate rounding takes place as an intermediate |
| 895 | * step before the buffer scale factor is applied, so the rectangle |
| 896 | * boundary may not be exactly as expected. |
| 897 | * |
| 898 | * This is OK for damage tracking since a little extra coverage is |
| 899 | * not a problem. |
| 900 | */ |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 901 | WL_EXPORT pixman_box32_t |
| 902 | weston_surface_to_buffer_rect(struct weston_surface *surface, |
| 903 | pixman_box32_t rect) |
| 904 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 905 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 906 | float xf, yf; |
| 907 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 908 | /* first transform box coordinates if the viewport is set */ |
| 909 | viewport_surface_to_buffer(surface, rect.x1, rect.y1, &xf, &yf); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 910 | rect.x1 = floorf(xf); |
| 911 | rect.y1 = floorf(yf); |
| 912 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 913 | viewport_surface_to_buffer(surface, rect.x2, rect.y2, &xf, &yf); |
Derek Foreman | e2e15ac | 2015-12-01 13:00:43 -0600 | [diff] [blame] | 914 | rect.x2 = ceilf(xf); |
| 915 | rect.y2 = ceilf(yf); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 916 | |
Jason Ekstrand | d0cebc3 | 2014-04-21 20:56:46 -0500 | [diff] [blame] | 917 | return weston_transformed_rect(surface->width_from_buffer, |
| 918 | surface->height_from_buffer, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 919 | vp->buffer.transform, vp->buffer.scale, |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 920 | rect); |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 921 | } |
| 922 | |
Pekka Paalanen | e54e31c | 2015-03-04 14:23:28 +0200 | [diff] [blame] | 923 | /** Transform a region from surface coordinates to buffer coordinates |
| 924 | * |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 925 | * \param surface The surface to fetch wp_viewport and buffer transformation |
Pekka Paalanen | e54e31c | 2015-03-04 14:23:28 +0200 | [diff] [blame] | 926 | * from. |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 927 | * \param[in] surface_region The region in surface coordinates. |
| 928 | * \param[out] buffer_region The region converted to buffer coordinates. |
Pekka Paalanen | e54e31c | 2015-03-04 14:23:28 +0200 | [diff] [blame] | 929 | * |
| 930 | * Buffer_region must be init'd, but will be completely overwritten. |
| 931 | * |
| 932 | * Viewport and buffer transformations can only do translation, scaling, |
| 933 | * and rotations in 90-degree steps. Therefore the only loss in the |
Derek Foreman | 9973967 | 2015-12-03 16:38:11 -0600 | [diff] [blame] | 934 | * conversion is from the coordinate rounding that takes place in |
| 935 | * \ref weston_surface_to_buffer_rect. |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 936 | * |
Pekka Paalanen | e54e31c | 2015-03-04 14:23:28 +0200 | [diff] [blame] | 937 | */ |
| 938 | WL_EXPORT void |
| 939 | weston_surface_to_buffer_region(struct weston_surface *surface, |
| 940 | pixman_region32_t *surface_region, |
| 941 | pixman_region32_t *buffer_region) |
| 942 | { |
| 943 | pixman_box32_t *src_rects, *dest_rects; |
| 944 | int nrects, i; |
| 945 | |
| 946 | src_rects = pixman_region32_rectangles(surface_region, &nrects); |
| 947 | dest_rects = malloc(nrects * sizeof(*dest_rects)); |
| 948 | if (!dest_rects) |
| 949 | return; |
| 950 | |
| 951 | for (i = 0; i < nrects; i++) { |
| 952 | dest_rects[i] = weston_surface_to_buffer_rect(surface, |
| 953 | src_rects[i]); |
| 954 | } |
| 955 | |
| 956 | pixman_region32_fini(buffer_region); |
| 957 | pixman_region32_init_rects(buffer_region, dest_rects, nrects); |
| 958 | free(dest_rects); |
| 959 | } |
| 960 | |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 961 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 962 | weston_view_move_to_plane(struct weston_view *view, |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 963 | struct weston_plane *plane) |
| 964 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 965 | if (view->plane == plane) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 966 | return; |
| 967 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 968 | weston_view_damage_below(view); |
| 969 | view->plane = plane; |
| 970 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 971 | } |
| 972 | |
Pekka Paalanen | 51723d5 | 2015-02-17 13:10:01 +0200 | [diff] [blame] | 973 | /** Inflict damage on the plane where the view is visible. |
| 974 | * |
| 975 | * \param view The view that causes the damage. |
| 976 | * |
| 977 | * If the view is currently on a plane (including the primary plane), |
| 978 | * take the view's boundingbox, subtract all the opaque views that cover it, |
| 979 | * and add the remaining region as damage to the plane. This corresponds |
| 980 | * to the damage inflicted to the plane if this view disappeared. |
| 981 | * |
| 982 | * A repaint is scheduled for this view. |
| 983 | * |
| 984 | * The region of all opaque views covering this view is stored in |
| 985 | * weston_view::clip and updated by view_accumulate_damage() during |
| 986 | * weston_output_repaint(). Specifically, that region matches the |
| 987 | * scenegraph as it was last painted. |
| 988 | */ |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 989 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 990 | weston_view_damage_below(struct weston_view *view) |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 991 | { |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 992 | pixman_region32_t damage; |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 993 | |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 994 | pixman_region32_init(&damage); |
Pekka Paalanen | 25c0ca5 | 2015-02-19 11:15:33 +0200 | [diff] [blame] | 995 | pixman_region32_subtract(&damage, &view->transform.boundingbox, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 996 | &view->clip); |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 997 | if (view->plane) |
| 998 | pixman_region32_union(&view->plane->damage, |
| 999 | &view->plane->damage, &damage); |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 1000 | pixman_region32_fini(&damage); |
Kristian Høgsberg | a3a784a | 2013-11-13 21:33:43 -0800 | [diff] [blame] | 1001 | weston_view_schedule_repaint(view); |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 1002 | } |
| 1003 | |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1004 | /** Send wl_surface.enter/leave events |
| 1005 | * |
| 1006 | * \param surface The surface. |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 1007 | * \param head A head of the entered/left output. |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1008 | * \param enter True if entered. |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 1009 | * \param leave True if left. |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1010 | * |
| 1011 | * Send the enter/leave events for all protocol objects bound to the given |
| 1012 | * output by the client owning the surface. |
| 1013 | */ |
| 1014 | static void |
| 1015 | weston_surface_send_enter_leave(struct weston_surface *surface, |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 1016 | struct weston_head *head, |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1017 | bool enter, |
| 1018 | bool leave) |
| 1019 | { |
| 1020 | struct wl_resource *wloutput; |
| 1021 | struct wl_client *client; |
| 1022 | |
| 1023 | assert(enter != leave); |
| 1024 | |
| 1025 | client = wl_resource_get_client(surface->resource); |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 1026 | wl_resource_for_each(wloutput, &head->resource_list) { |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1027 | if (wl_resource_get_client(wloutput) != client) |
| 1028 | continue; |
| 1029 | |
| 1030 | if (enter) |
| 1031 | wl_surface_send_enter(surface->resource, wloutput); |
| 1032 | if (leave) |
| 1033 | wl_surface_send_leave(surface->resource, wloutput); |
| 1034 | } |
| 1035 | } |
| 1036 | |
Ankit Nautiyal | f74c35b | 2019-04-03 19:21:58 +0530 | [diff] [blame] | 1037 | static void |
| 1038 | weston_surface_compute_protection(struct protected_surface *psurface) |
| 1039 | { |
| 1040 | enum weston_hdcp_protection min_protection; |
| 1041 | bool min_protection_valid = false; |
| 1042 | struct weston_surface *surface = psurface->surface; |
| 1043 | struct weston_output *output; |
| 1044 | |
| 1045 | wl_list_for_each(output, &surface->compositor->output_list, link) |
| 1046 | if (surface->output_mask & (1u << output->id)) { |
| 1047 | if (!min_protection_valid) { |
| 1048 | min_protection = output->current_protection; |
| 1049 | min_protection_valid = true; |
| 1050 | } |
| 1051 | if (output->current_protection < min_protection) |
| 1052 | min_protection = output->current_protection; |
| 1053 | } |
| 1054 | if (!min_protection_valid) |
| 1055 | min_protection = WESTON_HDCP_DISABLE; |
| 1056 | |
| 1057 | surface->current_protection = min_protection; |
| 1058 | weston_protected_surface_send_event(psurface, |
| 1059 | surface->current_protection); |
| 1060 | } |
| 1061 | |
| 1062 | static void |
| 1063 | notify_surface_protection_change(void *data) |
| 1064 | { |
| 1065 | struct weston_compositor *compositor = data; |
| 1066 | struct content_protection *cp; |
| 1067 | struct protected_surface *psurface; |
| 1068 | |
| 1069 | cp = compositor->content_protection; |
| 1070 | cp->surface_protection_update = NULL; |
| 1071 | |
| 1072 | /* Notify the clients, whose surfaces are changed */ |
| 1073 | wl_list_for_each(psurface, &cp->protected_list, link) |
| 1074 | if (psurface && psurface->surface) |
| 1075 | weston_surface_compute_protection(psurface); |
| 1076 | } |
| 1077 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1078 | /** |
| 1079 | * \param es The surface |
| 1080 | * \param mask The new set of outputs for the surface |
| 1081 | * |
| 1082 | * Sets the surface's set of outputs to the ones specified by |
| 1083 | * the new output mask provided. Identifies the outputs that |
| 1084 | * have changed, the posts enter and leave events for these |
| 1085 | * outputs as appropriate. |
| 1086 | */ |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1087 | static void |
| 1088 | weston_surface_update_output_mask(struct weston_surface *es, uint32_t mask) |
| 1089 | { |
| 1090 | uint32_t different = es->output_mask ^ mask; |
| 1091 | uint32_t entered = mask & different; |
| 1092 | uint32_t left = es->output_mask & different; |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1093 | uint32_t output_bit; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1094 | struct weston_output *output; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 1095 | struct weston_head *head; |
Ankit Nautiyal | f74c35b | 2019-04-03 19:21:58 +0530 | [diff] [blame] | 1096 | struct content_protection *cp; |
| 1097 | struct wl_event_loop *loop; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1098 | |
| 1099 | es->output_mask = mask; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1100 | if (es->resource == NULL) |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1101 | return; |
| 1102 | if (different == 0) |
| 1103 | return; |
| 1104 | |
| 1105 | wl_list_for_each(output, &es->compositor->output_list, link) { |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1106 | output_bit = 1u << output->id; |
| 1107 | if (!(output_bit & different)) |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1108 | continue; |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1109 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 1110 | wl_list_for_each(head, &output->head_list, output_link) { |
| 1111 | weston_surface_send_enter_leave(es, head, |
| 1112 | output_bit & entered, |
| 1113 | output_bit & left); |
| 1114 | } |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1115 | } |
Ankit Nautiyal | f74c35b | 2019-04-03 19:21:58 +0530 | [diff] [blame] | 1116 | /* |
| 1117 | * Change in surfaces' output mask might trigger a change in its |
| 1118 | * protection. |
| 1119 | */ |
| 1120 | loop = wl_display_get_event_loop(es->compositor->wl_display); |
| 1121 | cp = es->compositor->content_protection; |
| 1122 | if (!cp || cp->surface_protection_update) |
| 1123 | return; |
| 1124 | cp->surface_protection_update = wl_event_loop_add_idle(loop, |
| 1125 | notify_surface_protection_change, |
| 1126 | es->compositor); |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1127 | } |
| 1128 | |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 1129 | static void |
| 1130 | notify_view_output_destroy(struct wl_listener *listener, void *data) |
| 1131 | { |
| 1132 | struct weston_view *view = |
| 1133 | container_of(listener, |
| 1134 | struct weston_view, output_destroy_listener); |
| 1135 | |
| 1136 | view->output = NULL; |
| 1137 | view->output_destroy_listener.notify = NULL; |
| 1138 | } |
| 1139 | |
| 1140 | /** Set the primary output of the view |
| 1141 | * |
| 1142 | * \param view The view whose primary output to set |
| 1143 | * \param output The new primary output for the view |
| 1144 | * |
| 1145 | * Set \a output to be the primary output of the \a view. |
| 1146 | * |
| 1147 | * Notice that the assignment may be temporary; the primary output could be |
| 1148 | * automatically changed. Hence, one cannot rely on the value persisting. |
| 1149 | * |
| 1150 | * Passing NULL as /a output will set the primary output to NULL. |
| 1151 | */ |
| 1152 | WL_EXPORT void |
| 1153 | weston_view_set_output(struct weston_view *view, struct weston_output *output) |
| 1154 | { |
| 1155 | if (view->output_destroy_listener.notify) { |
| 1156 | wl_list_remove(&view->output_destroy_listener.link); |
| 1157 | view->output_destroy_listener.notify = NULL; |
| 1158 | } |
| 1159 | view->output = output; |
| 1160 | if (output) { |
| 1161 | view->output_destroy_listener.notify = |
| 1162 | notify_view_output_destroy; |
| 1163 | wl_signal_add(&output->destroy_signal, |
| 1164 | &view->output_destroy_listener); |
| 1165 | } |
| 1166 | } |
| 1167 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1168 | /** Recalculate which output(s) the surface has views displayed on |
| 1169 | * |
| 1170 | * \param es The surface to remap to outputs |
| 1171 | * |
| 1172 | * Finds the output that is showing the largest amount of one |
| 1173 | * of the surface's various views. This output becomes the |
Pekka Paalanen | 130ae6e | 2016-03-30 14:33:33 +0300 | [diff] [blame] | 1174 | * surface's primary output for vsync and frame callback purposes. |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1175 | * |
Pekka Paalanen | 130ae6e | 2016-03-30 14:33:33 +0300 | [diff] [blame] | 1176 | * Also notes all outputs of all of the surface's views |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1177 | * in the output_mask for the surface. |
| 1178 | */ |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1179 | static void |
| 1180 | weston_surface_assign_output(struct weston_surface *es) |
| 1181 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1182 | struct weston_output *new_output; |
| 1183 | struct weston_view *view; |
| 1184 | pixman_region32_t region; |
| 1185 | uint32_t max, area, mask; |
| 1186 | pixman_box32_t *e; |
| 1187 | |
| 1188 | new_output = NULL; |
| 1189 | max = 0; |
| 1190 | mask = 0; |
| 1191 | pixman_region32_init(®ion); |
| 1192 | wl_list_for_each(view, &es->views, surface_link) { |
| 1193 | if (!view->output) |
| 1194 | continue; |
| 1195 | |
| 1196 | pixman_region32_intersect(®ion, &view->transform.boundingbox, |
| 1197 | &view->output->region); |
| 1198 | |
| 1199 | e = pixman_region32_extents(®ion); |
| 1200 | area = (e->x2 - e->x1) * (e->y2 - e->y1); |
| 1201 | |
| 1202 | mask |= view->output_mask; |
| 1203 | |
| 1204 | if (area >= max) { |
| 1205 | new_output = view->output; |
| 1206 | max = area; |
| 1207 | } |
| 1208 | } |
| 1209 | pixman_region32_fini(®ion); |
| 1210 | |
| 1211 | es->output = new_output; |
| 1212 | weston_surface_update_output_mask(es, mask); |
| 1213 | } |
| 1214 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1215 | /** Recalculate which output(s) the view is displayed on |
| 1216 | * |
| 1217 | * \param ev The view to remap to outputs |
| 1218 | * |
| 1219 | * Identifies the set of outputs that the view is visible on, |
| 1220 | * noting them into the output_mask. The output that the view |
Pekka Paalanen | 130ae6e | 2016-03-30 14:33:33 +0300 | [diff] [blame] | 1221 | * is most visible on is set as the view's primary output. |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1222 | * |
| 1223 | * Also does the same for the view's surface. See |
| 1224 | * weston_surface_assign_output(). |
| 1225 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1226 | static void |
| 1227 | weston_view_assign_output(struct weston_view *ev) |
| 1228 | { |
| 1229 | struct weston_compositor *ec = ev->surface->compositor; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1230 | struct weston_output *output, *new_output; |
| 1231 | pixman_region32_t region; |
| 1232 | uint32_t max, area, mask; |
| 1233 | pixman_box32_t *e; |
| 1234 | |
| 1235 | new_output = NULL; |
| 1236 | max = 0; |
| 1237 | mask = 0; |
| 1238 | pixman_region32_init(®ion); |
| 1239 | wl_list_for_each(output, &ec->output_list, link) { |
Giulio Camuffo | 2f2a70c | 2015-07-12 10:52:32 +0300 | [diff] [blame] | 1240 | if (output->destroying) |
| 1241 | continue; |
| 1242 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1243 | pixman_region32_intersect(®ion, &ev->transform.boundingbox, |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1244 | &output->region); |
| 1245 | |
| 1246 | e = pixman_region32_extents(®ion); |
| 1247 | area = (e->x2 - e->x1) * (e->y2 - e->y1); |
| 1248 | |
| 1249 | if (area > 0) |
Bryce Harrington | 89324ce | 2015-12-23 18:38:07 -0800 | [diff] [blame] | 1250 | mask |= 1u << output->id; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1251 | |
| 1252 | if (area >= max) { |
| 1253 | new_output = output; |
| 1254 | max = area; |
| 1255 | } |
| 1256 | } |
| 1257 | pixman_region32_fini(®ion); |
| 1258 | |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 1259 | weston_view_set_output(ev, new_output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1260 | ev->output_mask = mask; |
| 1261 | |
| 1262 | weston_surface_assign_output(ev->surface); |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1263 | } |
| 1264 | |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 1265 | static void |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1266 | weston_view_to_view_map(struct weston_view *from, struct weston_view *to, |
| 1267 | int from_x, int from_y, int *to_x, int *to_y) |
| 1268 | { |
| 1269 | float x, y; |
| 1270 | |
| 1271 | weston_view_to_global_float(from, from_x, from_y, &x, &y); |
| 1272 | weston_view_from_global_float(to, x, y, &x, &y); |
| 1273 | |
| 1274 | *to_x = round(x); |
| 1275 | *to_y = round(y); |
| 1276 | } |
| 1277 | |
| 1278 | static void |
| 1279 | weston_view_transfer_scissor(struct weston_view *from, struct weston_view *to) |
| 1280 | { |
| 1281 | pixman_box32_t *a; |
| 1282 | pixman_box32_t b; |
| 1283 | |
| 1284 | a = pixman_region32_extents(&from->geometry.scissor); |
| 1285 | |
| 1286 | weston_view_to_view_map(from, to, a->x1, a->y1, &b.x1, &b.y1); |
| 1287 | weston_view_to_view_map(from, to, a->x2, a->y2, &b.x2, &b.y2); |
| 1288 | |
| 1289 | pixman_region32_fini(&to->geometry.scissor); |
| 1290 | pixman_region32_init_with_extents(&to->geometry.scissor, &b); |
| 1291 | } |
| 1292 | |
| 1293 | static void |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 1294 | view_compute_bbox(struct weston_view *view, const pixman_box32_t *inbox, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1295 | pixman_region32_t *bbox) |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1296 | { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1297 | float min_x = HUGE_VALF, min_y = HUGE_VALF; |
| 1298 | float max_x = -HUGE_VALF, max_y = -HUGE_VALF; |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1299 | int32_t s[4][2] = { |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 1300 | { inbox->x1, inbox->y1 }, |
| 1301 | { inbox->x1, inbox->y2 }, |
| 1302 | { inbox->x2, inbox->y1 }, |
| 1303 | { inbox->x2, inbox->y2 }, |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1304 | }; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1305 | float int_x, int_y; |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1306 | int i; |
| 1307 | |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 1308 | if (inbox->x1 == inbox->x2 || inbox->y1 == inbox->y2) { |
Pekka Paalanen | 7c7d464 | 2012-09-04 13:55:44 +0300 | [diff] [blame] | 1309 | /* avoid rounding empty bbox to 1x1 */ |
| 1310 | pixman_region32_init(bbox); |
| 1311 | return; |
| 1312 | } |
| 1313 | |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1314 | for (i = 0; i < 4; ++i) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1315 | float x, y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1316 | 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] | 1317 | if (x < min_x) |
| 1318 | min_x = x; |
| 1319 | if (x > max_x) |
| 1320 | max_x = x; |
| 1321 | if (y < min_y) |
| 1322 | min_y = y; |
| 1323 | if (y > max_y) |
| 1324 | max_y = y; |
| 1325 | } |
| 1326 | |
Pekka Paalanen | 219b982 | 2012-02-08 15:38:37 +0200 | [diff] [blame] | 1327 | int_x = floorf(min_x); |
| 1328 | int_y = floorf(min_y); |
| 1329 | pixman_region32_init_rect(bbox, int_x, int_y, |
| 1330 | ceilf(max_x) - int_x, ceilf(max_y) - int_y); |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1331 | } |
| 1332 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1333 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1334 | weston_view_update_transform_disable(struct weston_view *view) |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1335 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1336 | view->transform.enabled = 0; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1337 | |
Pekka Paalanen | cc2f868 | 2012-02-13 10:34:04 +0200 | [diff] [blame] | 1338 | /* round off fractions when not transformed */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1339 | view->geometry.x = roundf(view->geometry.x); |
| 1340 | view->geometry.y = roundf(view->geometry.y); |
Pekka Paalanen | cc2f868 | 2012-02-13 10:34:04 +0200 | [diff] [blame] | 1341 | |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1342 | /* Otherwise identity matrix, but with x and y translation. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1343 | view->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE; |
| 1344 | view->transform.position.matrix.d[12] = view->geometry.x; |
| 1345 | view->transform.position.matrix.d[13] = view->geometry.y; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1346 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1347 | view->transform.matrix = view->transform.position.matrix; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1348 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1349 | view->transform.inverse = view->transform.position.matrix; |
| 1350 | view->transform.inverse.d[12] = -view->geometry.x; |
| 1351 | view->transform.inverse.d[13] = -view->geometry.y; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1352 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1353 | pixman_region32_init_rect(&view->transform.boundingbox, |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1354 | 0, 0, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1355 | view->surface->width, |
| 1356 | view->surface->height); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1357 | if (view->geometry.scissor_enabled) |
| 1358 | pixman_region32_intersect(&view->transform.boundingbox, |
| 1359 | &view->transform.boundingbox, |
| 1360 | &view->geometry.scissor); |
| 1361 | |
| 1362 | pixman_region32_translate(&view->transform.boundingbox, |
| 1363 | view->geometry.x, view->geometry.y); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1364 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1365 | if (view->alpha == 1.0) { |
| 1366 | pixman_region32_copy(&view->transform.opaque, |
| 1367 | &view->surface->opaque); |
| 1368 | pixman_region32_translate(&view->transform.opaque, |
| 1369 | view->geometry.x, |
| 1370 | view->geometry.y); |
Kristian Høgsberg | 3b4af20 | 2012-02-28 09:19:39 -0500 | [diff] [blame] | 1371 | } |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1372 | } |
| 1373 | |
| 1374 | static int |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1375 | weston_view_update_transform_enable(struct weston_view *view) |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1376 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1377 | struct weston_view *parent = view->geometry.parent; |
| 1378 | struct weston_matrix *matrix = &view->transform.matrix; |
| 1379 | struct weston_matrix *inverse = &view->transform.inverse; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1380 | struct weston_transform *tform; |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1381 | pixman_region32_t surfregion; |
| 1382 | const pixman_box32_t *surfbox; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1383 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1384 | view->transform.enabled = 1; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1385 | |
| 1386 | /* Otherwise identity matrix, but with x and y translation. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1387 | view->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE; |
| 1388 | view->transform.position.matrix.d[12] = view->geometry.x; |
| 1389 | view->transform.position.matrix.d[13] = view->geometry.y; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1390 | |
| 1391 | weston_matrix_init(matrix); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1392 | wl_list_for_each(tform, &view->geometry.transformation_list, link) |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1393 | weston_matrix_multiply(matrix, &tform->matrix); |
| 1394 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1395 | if (parent) |
| 1396 | weston_matrix_multiply(matrix, &parent->transform.matrix); |
| 1397 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1398 | if (weston_matrix_invert(inverse, matrix) < 0) { |
| 1399 | /* Oops, bad total transformation, not invertible */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1400 | weston_log("error: weston_view %p" |
| 1401 | " transformation not invertible.\n", view); |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1402 | return -1; |
| 1403 | } |
| 1404 | |
Giulio Camuffo | 148c199 | 2016-09-04 18:50:46 +0300 | [diff] [blame] | 1405 | if (view->alpha == 1.0 && |
| 1406 | matrix->type == WESTON_MATRIX_TRANSFORM_TRANSLATE) { |
| 1407 | pixman_region32_copy(&view->transform.opaque, |
| 1408 | &view->surface->opaque); |
| 1409 | pixman_region32_translate(&view->transform.opaque, |
| 1410 | matrix->d[12], |
| 1411 | matrix->d[13]); |
| 1412 | } |
| 1413 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1414 | pixman_region32_init_rect(&surfregion, 0, 0, |
| 1415 | view->surface->width, view->surface->height); |
| 1416 | if (view->geometry.scissor_enabled) |
| 1417 | pixman_region32_intersect(&surfregion, &surfregion, |
| 1418 | &view->geometry.scissor); |
| 1419 | surfbox = pixman_region32_extents(&surfregion); |
| 1420 | |
| 1421 | view_compute_bbox(view, surfbox, &view->transform.boundingbox); |
| 1422 | pixman_region32_fini(&surfregion); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1423 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1424 | return 0; |
| 1425 | } |
| 1426 | |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1427 | static struct weston_layer * |
| 1428 | get_view_layer(struct weston_view *view) |
| 1429 | { |
| 1430 | if (view->parent_view) |
| 1431 | return get_view_layer(view->parent_view); |
| 1432 | return view->layer_link.layer; |
| 1433 | } |
| 1434 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1435 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1436 | weston_view_update_transform(struct weston_view *view) |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1437 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1438 | struct weston_view *parent = view->geometry.parent; |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1439 | struct weston_layer *layer; |
| 1440 | pixman_region32_t mask; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1441 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1442 | if (!view->transform.dirty) |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1443 | return; |
| 1444 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1445 | if (parent) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1446 | weston_view_update_transform(parent); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1447 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1448 | view->transform.dirty = 0; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1449 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1450 | weston_view_damage_below(view); |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 1451 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1452 | pixman_region32_fini(&view->transform.boundingbox); |
| 1453 | pixman_region32_fini(&view->transform.opaque); |
| 1454 | pixman_region32_init(&view->transform.opaque); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1455 | |
Pekka Paalanen | cd40362 | 2012-01-25 13:37:39 +0200 | [diff] [blame] | 1456 | /* transform.position is always in transformation_list */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1457 | if (view->geometry.transformation_list.next == |
| 1458 | &view->transform.position.link && |
| 1459 | view->geometry.transformation_list.prev == |
| 1460 | &view->transform.position.link && |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1461 | !parent) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1462 | weston_view_update_transform_disable(view); |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1463 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1464 | if (weston_view_update_transform_enable(view) < 0) |
| 1465 | weston_view_update_transform_disable(view); |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1466 | } |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 1467 | |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1468 | layer = get_view_layer(view); |
| 1469 | if (layer) { |
| 1470 | pixman_region32_init_with_extents(&mask, &layer->mask); |
Pekka Paalanen | 25c0ca5 | 2015-02-19 11:15:33 +0200 | [diff] [blame] | 1471 | pixman_region32_intersect(&view->transform.boundingbox, |
| 1472 | &view->transform.boundingbox, &mask); |
Pekka Paalanen | 8844bf2 | 2015-02-18 16:30:47 +0200 | [diff] [blame] | 1473 | pixman_region32_intersect(&view->transform.opaque, |
| 1474 | &view->transform.opaque, &mask); |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1475 | pixman_region32_fini(&mask); |
| 1476 | } |
| 1477 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1478 | if (parent) { |
| 1479 | if (parent->geometry.scissor_enabled) { |
| 1480 | view->geometry.scissor_enabled = true; |
| 1481 | weston_view_transfer_scissor(parent, view); |
| 1482 | } else { |
| 1483 | view->geometry.scissor_enabled = false; |
| 1484 | } |
| 1485 | } |
| 1486 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1487 | weston_view_damage_below(view); |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 1488 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1489 | weston_view_assign_output(view); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 1490 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1491 | wl_signal_emit(&view->surface->compositor->transform_signal, |
| 1492 | view->surface); |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1493 | } |
| 1494 | |
Pekka Paalanen | ddae03c | 2012-02-06 14:54:20 +0200 | [diff] [blame] | 1495 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1496 | weston_view_geometry_dirty(struct weston_view *view) |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 1497 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1498 | struct weston_view *child; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1499 | |
| 1500 | /* |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1501 | * The invariant: if view->geometry.dirty, then all views |
| 1502 | * in view->geometry.child_list have geometry.dirty too. |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1503 | * Corollary: if not parent->geometry.dirty, then all ancestors |
| 1504 | * are not dirty. |
| 1505 | */ |
| 1506 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1507 | if (view->transform.dirty) |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1508 | return; |
| 1509 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1510 | view->transform.dirty = 1; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1511 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1512 | wl_list_for_each(child, &view->geometry.child_list, |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1513 | geometry.parent_link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1514 | weston_view_geometry_dirty(child); |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 1515 | } |
| 1516 | |
| 1517 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1518 | weston_view_to_global_fixed(struct weston_view *view, |
| 1519 | wl_fixed_t vx, wl_fixed_t vy, |
| 1520 | wl_fixed_t *x, wl_fixed_t *y) |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1521 | { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1522 | float xf, yf; |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1523 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1524 | weston_view_to_global_float(view, |
| 1525 | wl_fixed_to_double(vx), |
| 1526 | wl_fixed_to_double(vy), |
| 1527 | &xf, &yf); |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1528 | *x = wl_fixed_from_double(xf); |
| 1529 | *y = wl_fixed_from_double(yf); |
| 1530 | } |
| 1531 | |
Kristian Høgsberg | ecf6ede | 2012-09-05 21:59:35 -0400 | [diff] [blame] | 1532 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1533 | weston_view_from_global_float(struct weston_view *view, |
| 1534 | float x, float y, float *vx, float *vy) |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1535 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1536 | if (view->transform.enabled) { |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1537 | struct weston_vector v = { { x, y, 0.0f, 1.0f } }; |
| 1538 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1539 | weston_matrix_transform(&view->transform.inverse, &v); |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1540 | |
| 1541 | if (fabsf(v.f[3]) < 1e-6) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1542 | weston_log("warning: numerical instability in " |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1543 | "weston_view_from_global(), divisor = %g\n", |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1544 | v.f[3]); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1545 | *vx = 0; |
| 1546 | *vy = 0; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1547 | return; |
| 1548 | } |
| 1549 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1550 | *vx = v.f[0] / v.f[3]; |
| 1551 | *vy = v.f[1] / v.f[3]; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1552 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1553 | *vx = x - view->geometry.x; |
| 1554 | *vy = y - view->geometry.y; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1555 | } |
| 1556 | } |
| 1557 | |
| 1558 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1559 | weston_view_from_global_fixed(struct weston_view *view, |
| 1560 | wl_fixed_t x, wl_fixed_t y, |
| 1561 | wl_fixed_t *vx, wl_fixed_t *vy) |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1562 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1563 | float vxf, vyf; |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1564 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1565 | weston_view_from_global_float(view, |
| 1566 | wl_fixed_to_double(x), |
| 1567 | wl_fixed_to_double(y), |
| 1568 | &vxf, &vyf); |
| 1569 | *vx = wl_fixed_from_double(vxf); |
| 1570 | *vy = wl_fixed_from_double(vyf); |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1571 | } |
| 1572 | |
| 1573 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1574 | weston_view_from_global(struct weston_view *view, |
| 1575 | int32_t x, int32_t y, int32_t *vx, int32_t *vy) |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1576 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1577 | float vxf, vyf; |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1578 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1579 | weston_view_from_global_float(view, x, y, &vxf, &vyf); |
| 1580 | *vx = floorf(vxf); |
| 1581 | *vy = floorf(vyf); |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1582 | } |
| 1583 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1584 | /** |
| 1585 | * \param surface The surface to be repainted |
| 1586 | * |
| 1587 | * Marks the output(s) that the surface is shown on as needing to be |
| 1588 | * repainted. See weston_output_schedule_repaint(). |
| 1589 | */ |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1590 | WL_EXPORT void |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1591 | weston_surface_schedule_repaint(struct weston_surface *surface) |
| 1592 | { |
| 1593 | struct weston_output *output; |
| 1594 | |
| 1595 | wl_list_for_each(output, &surface->compositor->output_list, link) |
Bryce Harrington | 89324ce | 2015-12-23 18:38:07 -0800 | [diff] [blame] | 1596 | if (surface->output_mask & (1u << output->id)) |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1597 | weston_output_schedule_repaint(output); |
| 1598 | } |
| 1599 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1600 | /** |
| 1601 | * \param view The view to be repainted |
| 1602 | * |
| 1603 | * Marks the output(s) that the view is shown on as needing to be |
| 1604 | * repainted. See weston_output_schedule_repaint(). |
| 1605 | */ |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1606 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1607 | weston_view_schedule_repaint(struct weston_view *view) |
| 1608 | { |
| 1609 | struct weston_output *output; |
| 1610 | |
| 1611 | wl_list_for_each(output, &view->surface->compositor->output_list, link) |
Bryce Harrington | 89324ce | 2015-12-23 18:38:07 -0800 | [diff] [blame] | 1612 | if (view->output_mask & (1u << output->id)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1613 | weston_output_schedule_repaint(output); |
| 1614 | } |
| 1615 | |
Pekka Paalanen | e508ce6 | 2015-02-19 13:59:55 +0200 | [diff] [blame] | 1616 | /** |
| 1617 | * XXX: This function does it the wrong way. |
| 1618 | * surface->damage is the damage from the client, and causes |
| 1619 | * surface_flush_damage() to copy pixels. No window management action can |
| 1620 | * cause damage to the client-provided content, warranting re-upload! |
| 1621 | * |
| 1622 | * Instead of surface->damage, this function should record the damage |
| 1623 | * with all the views for this surface to avoid extraneous texture |
| 1624 | * uploads. |
| 1625 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1626 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1627 | weston_surface_damage(struct weston_surface *surface) |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 1628 | { |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1629 | pixman_region32_union_rect(&surface->damage, &surface->damage, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1630 | 0, 0, surface->width, |
| 1631 | surface->height); |
Pekka Paalanen | 2267d45 | 2012-01-26 13:12:45 +0200 | [diff] [blame] | 1632 | |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1633 | weston_surface_schedule_repaint(surface); |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 1634 | } |
| 1635 | |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 1636 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1637 | weston_view_set_position(struct weston_view *view, float x, float y) |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1638 | { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1639 | if (view->geometry.x == x && view->geometry.y == y) |
| 1640 | return; |
| 1641 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1642 | view->geometry.x = x; |
| 1643 | view->geometry.y = y; |
| 1644 | weston_view_geometry_dirty(view); |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1645 | } |
| 1646 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1647 | static void |
| 1648 | transform_parent_handle_parent_destroy(struct wl_listener *listener, |
| 1649 | void *data) |
| 1650 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1651 | struct weston_view *view = |
| 1652 | container_of(listener, struct weston_view, |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1653 | geometry.parent_destroy_listener); |
| 1654 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1655 | weston_view_set_transform_parent(view, NULL); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1656 | } |
| 1657 | |
| 1658 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1659 | weston_view_set_transform_parent(struct weston_view *view, |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1660 | struct weston_view *parent) |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1661 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1662 | if (view->geometry.parent) { |
| 1663 | wl_list_remove(&view->geometry.parent_destroy_listener.link); |
| 1664 | wl_list_remove(&view->geometry.parent_link); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1665 | |
| 1666 | if (!parent) |
| 1667 | view->geometry.scissor_enabled = false; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1668 | } |
| 1669 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1670 | view->geometry.parent = parent; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1671 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1672 | view->geometry.parent_destroy_listener.notify = |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1673 | transform_parent_handle_parent_destroy; |
| 1674 | if (parent) { |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1675 | wl_signal_add(&parent->destroy_signal, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1676 | &view->geometry.parent_destroy_listener); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1677 | wl_list_insert(&parent->geometry.child_list, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1678 | &view->geometry.parent_link); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1679 | } |
| 1680 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1681 | weston_view_geometry_dirty(view); |
| 1682 | } |
| 1683 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1684 | /** Set a clip mask rectangle on a view |
| 1685 | * |
| 1686 | * \param view The view to set the clip mask on. |
| 1687 | * \param x Top-left corner X coordinate of the clip rectangle. |
| 1688 | * \param y Top-left corner Y coordinate of the clip rectangle. |
| 1689 | * \param width Width of the clip rectangle, non-negative. |
| 1690 | * \param height Height of the clip rectangle, non-negative. |
| 1691 | * |
| 1692 | * A shell may set a clip mask rectangle on a view. Everything outside |
| 1693 | * the rectangle is cut away for input and output purposes: it is |
| 1694 | * not drawn and cannot be hit by hit-test based input like pointer |
| 1695 | * motion or touch-downs. Everything inside the rectangle will behave |
| 1696 | * normally. Clients are unaware of clipping. |
| 1697 | * |
Yong Bakos | 4c72e29 | 2016-04-28 11:59:10 -0500 | [diff] [blame] | 1698 | * The rectangle is set in surface-local coordinates. Setting a clip |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1699 | * mask rectangle does not affect the view position, the view is positioned |
| 1700 | * as it would be without a clip. The clip also does not change |
| 1701 | * weston_surface::width,height. |
| 1702 | * |
| 1703 | * The clip mask rectangle is part of transformation inheritance |
| 1704 | * (weston_view_set_transform_parent()). A clip set in the root of the |
| 1705 | * transformation inheritance tree will affect all views in the tree. |
| 1706 | * A clip can be set only on the root view. Attempting to set a clip |
| 1707 | * on view that has a transformation parent will fail. Assigning a parent |
| 1708 | * to a view that has a clip set will cause the clip to be forgotten. |
| 1709 | * |
| 1710 | * Because the clip mask is an axis-aligned rectangle, it poses restrictions |
| 1711 | * on the additional transformations in the child views. These transformations |
| 1712 | * may not rotate the coordinate axes, i.e., only translation and scaling |
| 1713 | * are allowed. Violating this restriction causes the clipping to malfunction. |
| 1714 | * Furthermore, using scaling may cause rounding errors in child clipping. |
| 1715 | * |
| 1716 | * The clip mask rectangle is not automatically adjusted based on |
| 1717 | * wl_surface.attach dx and dy arguments. |
| 1718 | * |
| 1719 | * A clip mask rectangle can be set only if the compositor capability |
| 1720 | * WESTON_CAP_VIEW_CLIP_MASK is present. |
| 1721 | * |
| 1722 | * This function sets the clip mask rectangle and schedules a repaint for |
| 1723 | * the view. |
| 1724 | */ |
| 1725 | WL_EXPORT void |
| 1726 | weston_view_set_mask(struct weston_view *view, |
| 1727 | int x, int y, int width, int height) |
| 1728 | { |
| 1729 | struct weston_compositor *compositor = view->surface->compositor; |
| 1730 | |
| 1731 | if (!(compositor->capabilities & WESTON_CAP_VIEW_CLIP_MASK)) { |
| 1732 | weston_log("%s not allowed without capability!\n", __func__); |
| 1733 | return; |
| 1734 | } |
| 1735 | |
| 1736 | if (view->geometry.parent) { |
| 1737 | weston_log("view %p has a parent, clip forbidden!\n", view); |
| 1738 | return; |
| 1739 | } |
| 1740 | |
| 1741 | if (width < 0 || height < 0) { |
| 1742 | weston_log("%s: illegal args %d, %d, %d, %d\n", __func__, |
| 1743 | x, y, width, height); |
| 1744 | return; |
| 1745 | } |
| 1746 | |
| 1747 | pixman_region32_fini(&view->geometry.scissor); |
| 1748 | pixman_region32_init_rect(&view->geometry.scissor, x, y, width, height); |
| 1749 | view->geometry.scissor_enabled = true; |
| 1750 | weston_view_geometry_dirty(view); |
| 1751 | weston_view_schedule_repaint(view); |
| 1752 | } |
| 1753 | |
| 1754 | /** Remove the clip mask from a view |
| 1755 | * |
| 1756 | * \param view The view to remove the clip mask from. |
| 1757 | * |
| 1758 | * Removed the clip mask rectangle and schedules a repaint. |
| 1759 | * |
| 1760 | * \sa weston_view_set_mask |
| 1761 | */ |
| 1762 | WL_EXPORT void |
| 1763 | weston_view_set_mask_infinite(struct weston_view *view) |
| 1764 | { |
| 1765 | view->geometry.scissor_enabled = false; |
| 1766 | weston_view_geometry_dirty(view); |
| 1767 | weston_view_schedule_repaint(view); |
| 1768 | } |
| 1769 | |
Armin Krezović | 0da12b8 | 2016-06-30 06:04:33 +0200 | [diff] [blame] | 1770 | /* Check if view should be displayed |
| 1771 | * |
| 1772 | * The indicator is set manually when assigning |
| 1773 | * a view to a surface. |
| 1774 | * |
| 1775 | * This needs reworking. See the thread starting at: |
| 1776 | * |
| 1777 | * https://lists.freedesktop.org/archives/wayland-devel/2016-June/029656.html |
| 1778 | */ |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 1779 | WL_EXPORT bool |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1780 | weston_view_is_mapped(struct weston_view *view) |
| 1781 | { |
Armin Krezović | 0da12b8 | 2016-06-30 06:04:33 +0200 | [diff] [blame] | 1782 | return view->is_mapped; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1783 | } |
| 1784 | |
Philipp Zabel | 70decd5 | 2018-09-03 20:11:15 +0200 | [diff] [blame] | 1785 | /* Check if view is opaque in specified region |
| 1786 | * |
| 1787 | * \param view The view to check for opacity. |
| 1788 | * \param region The region to check for opacity, in view coordinates. |
| 1789 | * |
| 1790 | * Returns true if the view is opaque in the specified region, because view |
| 1791 | * alpha is 1.0 and either the opaque region set by the client contains the |
| 1792 | * specified region, or the buffer pixel format or solid color is opaque. |
| 1793 | */ |
| 1794 | WL_EXPORT bool |
| 1795 | weston_view_is_opaque(struct weston_view *ev, pixman_region32_t *region) |
| 1796 | { |
| 1797 | pixman_region32_t r; |
| 1798 | bool ret = false; |
| 1799 | |
| 1800 | if (ev->alpha < 1.0) |
| 1801 | return false; |
| 1802 | |
| 1803 | if (ev->surface->is_opaque) |
| 1804 | return true; |
| 1805 | |
| 1806 | if (ev->transform.dirty) { |
| 1807 | weston_log("%s: transform dirty", __func__); |
| 1808 | return false; |
| 1809 | } |
| 1810 | |
| 1811 | pixman_region32_init(&r); |
| 1812 | pixman_region32_subtract(&r, region, &ev->transform.opaque); |
| 1813 | |
| 1814 | if (!pixman_region32_not_empty(&r)) |
| 1815 | ret = true; |
| 1816 | |
| 1817 | pixman_region32_fini(&r); |
| 1818 | |
| 1819 | return ret; |
| 1820 | } |
| 1821 | |
Armin Krezović | 0da12b8 | 2016-06-30 06:04:33 +0200 | [diff] [blame] | 1822 | /* Check if a surface has a view assigned to it |
| 1823 | * |
| 1824 | * The indicator is set manually when mapping |
| 1825 | * a surface and creating a view for it. |
| 1826 | * |
| 1827 | * This needs to go. See the thread starting at: |
| 1828 | * |
| 1829 | * https://lists.freedesktop.org/archives/wayland-devel/2016-June/029656.html |
| 1830 | * |
| 1831 | */ |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 1832 | WL_EXPORT bool |
Ander Conselvan de Oliveira | b8ab14f | 2012-03-27 17:36:36 +0300 | [diff] [blame] | 1833 | weston_surface_is_mapped(struct weston_surface *surface) |
| 1834 | { |
Armin Krezović | 0da12b8 | 2016-06-30 06:04:33 +0200 | [diff] [blame] | 1835 | return surface->is_mapped; |
Ander Conselvan de Oliveira | b8ab14f | 2012-03-27 17:36:36 +0300 | [diff] [blame] | 1836 | } |
| 1837 | |
Pekka Paalanen | da75ee1 | 2013-11-26 18:19:43 +0100 | [diff] [blame] | 1838 | static void |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 1839 | 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] | 1840 | { |
| 1841 | struct weston_view *view; |
| 1842 | |
| 1843 | if (surface->width == width && surface->height == height) |
| 1844 | return; |
| 1845 | |
| 1846 | surface->width = width; |
| 1847 | surface->height = height; |
| 1848 | |
| 1849 | wl_list_for_each(view, &surface->views, surface_link) |
| 1850 | weston_view_geometry_dirty(view); |
| 1851 | } |
| 1852 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 1853 | WL_EXPORT void |
| 1854 | weston_surface_set_size(struct weston_surface *surface, |
| 1855 | int32_t width, int32_t height) |
| 1856 | { |
| 1857 | assert(!surface->resource); |
| 1858 | surface_set_size(surface, width, height); |
| 1859 | } |
| 1860 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1861 | static int |
| 1862 | fixed_round_up_to_int(wl_fixed_t f) |
| 1863 | { |
| 1864 | return wl_fixed_to_int(wl_fixed_from_int(1) - 1 + f); |
| 1865 | } |
| 1866 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1867 | static void |
Pekka Paalanen | 59987fa | 2016-04-26 15:50:59 +0300 | [diff] [blame] | 1868 | convert_size_by_transform_scale(int32_t *width_out, int32_t *height_out, |
| 1869 | int32_t width, int32_t height, |
| 1870 | uint32_t transform, |
| 1871 | int32_t scale) |
| 1872 | { |
| 1873 | assert(scale > 0); |
| 1874 | |
| 1875 | switch (transform) { |
| 1876 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 1877 | case WL_OUTPUT_TRANSFORM_180: |
| 1878 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 1879 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 1880 | *width_out = width / scale; |
| 1881 | *height_out = height / scale; |
| 1882 | break; |
| 1883 | case WL_OUTPUT_TRANSFORM_90: |
| 1884 | case WL_OUTPUT_TRANSFORM_270: |
| 1885 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 1886 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 1887 | *width_out = height / scale; |
| 1888 | *height_out = width / scale; |
| 1889 | break; |
| 1890 | default: |
| 1891 | assert(0 && "invalid transform"); |
| 1892 | } |
| 1893 | } |
| 1894 | |
| 1895 | static void |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1896 | weston_surface_calculate_size_from_buffer(struct weston_surface *surface) |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1897 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 1898 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Pekka Paalanen | da75ee1 | 2013-11-26 18:19:43 +0100 | [diff] [blame] | 1899 | |
| 1900 | if (!surface->buffer_ref.buffer) { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1901 | surface->width_from_buffer = 0; |
| 1902 | surface->height_from_buffer = 0; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 1903 | return; |
| 1904 | } |
| 1905 | |
Pekka Paalanen | 59987fa | 2016-04-26 15:50:59 +0300 | [diff] [blame] | 1906 | convert_size_by_transform_scale(&surface->width_from_buffer, |
| 1907 | &surface->height_from_buffer, |
| 1908 | surface->buffer_ref.buffer->width, |
| 1909 | surface->buffer_ref.buffer->height, |
| 1910 | vp->buffer.transform, |
| 1911 | vp->buffer.scale); |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1912 | } |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1913 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1914 | static void |
| 1915 | weston_surface_update_size(struct weston_surface *surface) |
| 1916 | { |
| 1917 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
| 1918 | int32_t width, height; |
| 1919 | |
| 1920 | width = surface->width_from_buffer; |
| 1921 | height = surface->height_from_buffer; |
| 1922 | |
| 1923 | if (width != 0 && vp->surface.width != -1) { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1924 | surface_set_size(surface, |
| 1925 | vp->surface.width, vp->surface.height); |
| 1926 | return; |
| 1927 | } |
| 1928 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1929 | if (width != 0 && vp->buffer.src_width != wl_fixed_from_int(-1)) { |
Pekka Paalanen | e931721 | 2014-04-04 14:22:13 +0300 | [diff] [blame] | 1930 | int32_t w = fixed_round_up_to_int(vp->buffer.src_width); |
| 1931 | int32_t h = fixed_round_up_to_int(vp->buffer.src_height); |
| 1932 | |
| 1933 | surface_set_size(surface, w ?: 1, h ?: 1); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1934 | return; |
| 1935 | } |
| 1936 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 1937 | surface_set_size(surface, width, height); |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1938 | } |
| 1939 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 1940 | /** weston_compositor_get_time |
| 1941 | * \ingroup compositor |
| 1942 | */ |
Alexandros Frantzis | 409b01f | 2017-11-16 18:21:01 +0200 | [diff] [blame] | 1943 | WL_EXPORT void |
| 1944 | weston_compositor_get_time(struct timespec *time) |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 1945 | { |
Alexandros Frantzis | 409b01f | 2017-11-16 18:21:01 +0200 | [diff] [blame] | 1946 | clock_gettime(CLOCK_REALTIME, time); |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 1947 | } |
| 1948 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 1949 | /** weston_compositor_pick_view |
| 1950 | * \ingroup compositor |
| 1951 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1952 | WL_EXPORT struct weston_view * |
| 1953 | weston_compositor_pick_view(struct weston_compositor *compositor, |
| 1954 | wl_fixed_t x, wl_fixed_t y, |
| 1955 | wl_fixed_t *vx, wl_fixed_t *vy) |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 1956 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1957 | struct weston_view *view; |
Pekka Paalanen | fc22a52 | 2015-02-18 15:08:29 +0200 | [diff] [blame] | 1958 | wl_fixed_t view_x, view_y; |
| 1959 | int view_ix, view_iy; |
| 1960 | int ix = wl_fixed_to_int(x); |
| 1961 | int iy = wl_fixed_to_int(y); |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 1962 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1963 | wl_list_for_each(view, &compositor->view_list, link) { |
Pekka Paalanen | fc22a52 | 2015-02-18 15:08:29 +0200 | [diff] [blame] | 1964 | if (!pixman_region32_contains_point( |
| 1965 | &view->transform.boundingbox, ix, iy, NULL)) |
| 1966 | continue; |
| 1967 | |
| 1968 | weston_view_from_global_fixed(view, x, y, &view_x, &view_y); |
| 1969 | view_ix = wl_fixed_to_int(view_x); |
| 1970 | view_iy = wl_fixed_to_int(view_y); |
| 1971 | |
| 1972 | if (!pixman_region32_contains_point(&view->surface->input, |
| 1973 | view_ix, view_iy, NULL)) |
| 1974 | continue; |
| 1975 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1976 | if (view->geometry.scissor_enabled && |
| 1977 | !pixman_region32_contains_point(&view->geometry.scissor, |
| 1978 | view_ix, view_iy, NULL)) |
| 1979 | continue; |
| 1980 | |
Pekka Paalanen | fc22a52 | 2015-02-18 15:08:29 +0200 | [diff] [blame] | 1981 | *vx = view_x; |
| 1982 | *vy = view_y; |
| 1983 | return view; |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 1984 | } |
| 1985 | |
Derek Foreman | f9318d1 | 2015-05-11 15:40:11 -0500 | [diff] [blame] | 1986 | *vx = wl_fixed_from_int(-1000000); |
| 1987 | *vy = wl_fixed_from_int(-1000000); |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 1988 | return NULL; |
| 1989 | } |
| 1990 | |
| 1991 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1992 | weston_compositor_repick(struct weston_compositor *compositor) |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 1993 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1994 | struct weston_seat *seat; |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 1995 | |
Kristian Høgsberg | 10ddd97 | 2013-10-22 12:40:54 -0700 | [diff] [blame] | 1996 | if (!compositor->session_active) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1997 | return; |
| 1998 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1999 | wl_list_for_each(seat, &compositor->seat_list, link) |
Kristian Høgsberg | a71e8b2 | 2013-05-06 21:51:21 -0400 | [diff] [blame] | 2000 | weston_seat_repick(seat); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 2001 | } |
| 2002 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2003 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2004 | weston_view_unmap(struct weston_view *view) |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 2005 | { |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 2006 | struct weston_seat *seat; |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 2007 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2008 | if (!weston_view_is_mapped(view)) |
| 2009 | return; |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 2010 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2011 | weston_view_damage_below(view); |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 2012 | weston_view_set_output(view, NULL); |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 2013 | view->plane = NULL; |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 2014 | view->is_mapped = false; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2015 | weston_layer_entry_remove(&view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2016 | wl_list_remove(&view->link); |
| 2017 | wl_list_init(&view->link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2018 | view->output_mask = 0; |
| 2019 | weston_surface_assign_output(view->surface); |
| 2020 | |
| 2021 | if (weston_surface_is_mapped(view->surface)) |
| 2022 | return; |
| 2023 | |
| 2024 | wl_list_for_each(seat, &view->surface->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2025 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 2026 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2027 | struct weston_keyboard *keyboard = |
| 2028 | weston_seat_get_keyboard(seat); |
| 2029 | |
| 2030 | if (keyboard && keyboard->focus == view->surface) |
| 2031 | weston_keyboard_set_focus(keyboard, NULL); |
| 2032 | if (pointer && pointer->focus == view) |
Derek Foreman | f9318d1 | 2015-05-11 15:40:11 -0500 | [diff] [blame] | 2033 | weston_pointer_clear_focus(pointer); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2034 | if (touch && touch->focus == view) |
| 2035 | weston_touch_set_focus(touch, NULL); |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 2036 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2037 | } |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 2038 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2039 | WL_EXPORT void |
| 2040 | weston_surface_unmap(struct weston_surface *surface) |
| 2041 | { |
| 2042 | struct weston_view *view; |
| 2043 | |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 2044 | surface->is_mapped = false; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2045 | wl_list_for_each(view, &surface->views, surface_link) |
| 2046 | weston_view_unmap(view); |
| 2047 | surface->output = NULL; |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 2048 | } |
| 2049 | |
Pekka Paalanen | 3c9b802 | 2014-03-14 14:38:13 +0200 | [diff] [blame] | 2050 | static void |
| 2051 | weston_surface_reset_pending_buffer(struct weston_surface *surface) |
| 2052 | { |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2053 | weston_surface_state_set_buffer(&surface->pending, NULL); |
Pekka Paalanen | 3c9b802 | 2014-03-14 14:38:13 +0200 | [diff] [blame] | 2054 | surface->pending.sx = 0; |
| 2055 | surface->pending.sy = 0; |
| 2056 | surface->pending.newly_attached = 0; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 2057 | surface->pending.buffer_viewport.changed = 0; |
Pekka Paalanen | 3c9b802 | 2014-03-14 14:38:13 +0200 | [diff] [blame] | 2058 | } |
| 2059 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2060 | WL_EXPORT void |
| 2061 | weston_view_destroy(struct weston_view *view) |
| 2062 | { |
| 2063 | wl_signal_emit(&view->destroy_signal, view); |
| 2064 | |
| 2065 | assert(wl_list_empty(&view->geometry.child_list)); |
| 2066 | |
| 2067 | if (weston_view_is_mapped(view)) { |
| 2068 | weston_view_unmap(view); |
| 2069 | weston_compositor_build_view_list(view->surface->compositor); |
| 2070 | } |
| 2071 | |
| 2072 | wl_list_remove(&view->link); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2073 | weston_layer_entry_remove(&view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2074 | |
| 2075 | pixman_region32_fini(&view->clip); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 2076 | pixman_region32_fini(&view->geometry.scissor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2077 | pixman_region32_fini(&view->transform.boundingbox); |
Pekka Paalanen | 8844bf2 | 2015-02-18 16:30:47 +0200 | [diff] [blame] | 2078 | pixman_region32_fini(&view->transform.opaque); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2079 | |
| 2080 | weston_view_set_transform_parent(view, NULL); |
Pekka Paalanen | 944fae8 | 2018-05-22 13:15:58 +0300 | [diff] [blame] | 2081 | weston_view_set_output(view, NULL); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2082 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2083 | wl_list_remove(&view->surface_link); |
| 2084 | |
| 2085 | free(view); |
| 2086 | } |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2087 | |
| 2088 | WL_EXPORT void |
| 2089 | weston_surface_destroy(struct weston_surface *surface) |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 2090 | { |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 2091 | struct weston_frame_callback *cb, *next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2092 | struct weston_view *ev, *nv; |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 2093 | struct weston_pointer_constraint *constraint, *next_constraint; |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 2094 | |
Giulio Camuffo | 13b85bd | 2013-08-13 23:10:14 +0200 | [diff] [blame] | 2095 | if (--surface->ref_count > 0) |
| 2096 | return; |
| 2097 | |
Pekka Paalanen | 08d3fb7 | 2015-04-17 14:00:24 +0300 | [diff] [blame] | 2098 | assert(surface->resource == NULL); |
| 2099 | |
Pekka Paalanen | ca79076 | 2015-04-17 14:23:38 +0300 | [diff] [blame] | 2100 | wl_signal_emit(&surface->destroy_signal, surface); |
Giulio Camuffo | 13b85bd | 2013-08-13 23:10:14 +0200 | [diff] [blame] | 2101 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2102 | assert(wl_list_empty(&surface->subsurface_list_pending)); |
| 2103 | assert(wl_list_empty(&surface->subsurface_list)); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 2104 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2105 | wl_list_for_each_safe(ev, nv, &surface->views, surface_link) |
| 2106 | weston_view_destroy(ev); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 2107 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2108 | weston_surface_state_fini(&surface->pending); |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2109 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2110 | weston_buffer_reference(&surface->buffer_ref, NULL); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2111 | weston_buffer_release_reference(&surface->buffer_release_ref, NULL); |
Kristian Høgsberg | 3f8f39c | 2009-09-18 17:05:13 -0400 | [diff] [blame] | 2112 | |
Pekka Paalanen | 402ae6d | 2012-01-03 10:23:24 +0200 | [diff] [blame] | 2113 | pixman_region32_fini(&surface->damage); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2114 | pixman_region32_fini(&surface->opaque); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 2115 | pixman_region32_fini(&surface->input); |
Pekka Paalanen | 402ae6d | 2012-01-03 10:23:24 +0200 | [diff] [blame] | 2116 | |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 2117 | wl_list_for_each_safe(cb, next, &surface->frame_callback_list, link) |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 2118 | wl_resource_destroy(cb->resource); |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 2119 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2120 | weston_presentation_feedback_discard_list(&surface->feedback_list); |
| 2121 | |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 2122 | wl_list_for_each_safe(constraint, next_constraint, |
| 2123 | &surface->pointer_constraints, |
| 2124 | link) |
| 2125 | weston_pointer_constraint_destroy(constraint); |
| 2126 | |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2127 | fd_clear(&surface->acquire_fence_fd); |
| 2128 | |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 2129 | free(surface); |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 2130 | } |
| 2131 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2132 | static void |
| 2133 | destroy_surface(struct wl_resource *resource) |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 2134 | { |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2135 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 2136 | |
Pekka Paalanen | 08d3fb7 | 2015-04-17 14:00:24 +0300 | [diff] [blame] | 2137 | assert(surface); |
| 2138 | |
Giulio Camuffo | 0d37974 | 2013-11-15 22:06:15 +0100 | [diff] [blame] | 2139 | /* Set the resource to NULL, since we don't want to leave a |
| 2140 | * dangling pointer if the surface was refcounted and survives |
| 2141 | * the weston_surface_destroy() call. */ |
| 2142 | surface->resource = NULL; |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 2143 | |
| 2144 | if (surface->viewport_resource) |
| 2145 | wl_resource_set_user_data(surface->viewport_resource, NULL); |
| 2146 | |
Alexandros Frantzis | 27d7c39 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2147 | if (surface->synchronization_resource) { |
| 2148 | wl_resource_set_user_data(surface->synchronization_resource, |
| 2149 | NULL); |
| 2150 | } |
| 2151 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2152 | weston_surface_destroy(surface); |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 2153 | } |
| 2154 | |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 2155 | static void |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2156 | weston_buffer_destroy_handler(struct wl_listener *listener, void *data) |
| 2157 | { |
| 2158 | struct weston_buffer *buffer = |
| 2159 | container_of(listener, struct weston_buffer, destroy_listener); |
| 2160 | |
| 2161 | wl_signal_emit(&buffer->destroy_signal, buffer); |
| 2162 | free(buffer); |
| 2163 | } |
| 2164 | |
Giulio Camuffo | e058cd1 | 2013-12-12 14:14:29 +0100 | [diff] [blame] | 2165 | WL_EXPORT struct weston_buffer * |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2166 | weston_buffer_from_resource(struct wl_resource *resource) |
| 2167 | { |
| 2168 | struct weston_buffer *buffer; |
| 2169 | struct wl_listener *listener; |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 2170 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2171 | listener = wl_resource_get_destroy_listener(resource, |
| 2172 | weston_buffer_destroy_handler); |
| 2173 | |
Kristian Høgsberg | 08b58c7 | 2013-08-15 12:26:42 -0700 | [diff] [blame] | 2174 | if (listener) |
| 2175 | return container_of(listener, struct weston_buffer, |
| 2176 | destroy_listener); |
| 2177 | |
| 2178 | buffer = zalloc(sizeof *buffer); |
| 2179 | if (buffer == NULL) |
| 2180 | return NULL; |
| 2181 | |
| 2182 | buffer->resource = resource; |
| 2183 | wl_signal_init(&buffer->destroy_signal); |
| 2184 | buffer->destroy_listener.notify = weston_buffer_destroy_handler; |
Stanislav Vorobiov | bfbb8e5 | 2013-08-29 11:36:44 +0400 | [diff] [blame] | 2185 | buffer->y_inverted = 1; |
Kristian Høgsberg | 08b58c7 | 2013-08-15 12:26:42 -0700 | [diff] [blame] | 2186 | wl_resource_add_destroy_listener(resource, &buffer->destroy_listener); |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 2187 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2188 | return buffer; |
| 2189 | } |
| 2190 | |
| 2191 | static void |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2192 | weston_buffer_reference_handle_destroy(struct wl_listener *listener, |
| 2193 | void *data) |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 2194 | { |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2195 | struct weston_buffer_reference *ref = |
| 2196 | container_of(listener, struct weston_buffer_reference, |
| 2197 | destroy_listener); |
| 2198 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2199 | assert((struct weston_buffer *)data == ref->buffer); |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2200 | ref->buffer = NULL; |
| 2201 | } |
| 2202 | |
| 2203 | WL_EXPORT void |
| 2204 | weston_buffer_reference(struct weston_buffer_reference *ref, |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2205 | struct weston_buffer *buffer) |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2206 | { |
| 2207 | if (ref->buffer && buffer != ref->buffer) { |
Kristian Høgsberg | 2034780 | 2013-03-04 12:07:46 -0500 | [diff] [blame] | 2208 | ref->buffer->busy_count--; |
| 2209 | if (ref->buffer->busy_count == 0) { |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2210 | assert(wl_resource_get_client(ref->buffer->resource)); |
Matt Hoosier | 3052bc7 | 2017-09-26 08:09:40 -0500 | [diff] [blame] | 2211 | wl_buffer_send_release(ref->buffer->resource); |
Kristian Høgsberg | 2034780 | 2013-03-04 12:07:46 -0500 | [diff] [blame] | 2212 | } |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2213 | wl_list_remove(&ref->destroy_listener.link); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2214 | } |
| 2215 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2216 | if (buffer && buffer != ref->buffer) { |
Kristian Høgsberg | b7b77e6 | 2012-09-05 22:38:18 -0400 | [diff] [blame] | 2217 | buffer->busy_count++; |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2218 | wl_signal_add(&buffer->destroy_signal, |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2219 | &ref->destroy_listener); |
Pekka Paalanen | a6421c4 | 2012-12-04 15:58:10 +0200 | [diff] [blame] | 2220 | } |
| 2221 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2222 | ref->buffer = buffer; |
| 2223 | ref->destroy_listener.notify = weston_buffer_reference_handle_destroy; |
| 2224 | } |
| 2225 | |
| 2226 | static void |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2227 | weston_buffer_release_reference_handle_destroy(struct wl_listener *listener, |
| 2228 | void *data) |
| 2229 | { |
| 2230 | struct weston_buffer_release_reference *ref = |
| 2231 | container_of(listener, struct weston_buffer_release_reference, |
| 2232 | destroy_listener); |
| 2233 | |
| 2234 | assert((struct wl_resource *)data == ref->buffer_release->resource); |
| 2235 | ref->buffer_release = NULL; |
| 2236 | } |
| 2237 | |
| 2238 | static void |
| 2239 | weston_buffer_release_destroy(struct weston_buffer_release *buffer_release) |
| 2240 | { |
| 2241 | struct wl_resource *resource = buffer_release->resource; |
| 2242 | int release_fence_fd = buffer_release->fence_fd; |
| 2243 | |
| 2244 | if (release_fence_fd >= 0) { |
| 2245 | zwp_linux_buffer_release_v1_send_fenced_release( |
| 2246 | resource, release_fence_fd); |
| 2247 | } else { |
| 2248 | zwp_linux_buffer_release_v1_send_immediate_release( |
| 2249 | resource); |
| 2250 | } |
| 2251 | |
| 2252 | wl_resource_destroy(resource); |
| 2253 | } |
| 2254 | |
| 2255 | WL_EXPORT void |
| 2256 | weston_buffer_release_reference(struct weston_buffer_release_reference *ref, |
| 2257 | struct weston_buffer_release *buffer_release) |
| 2258 | { |
| 2259 | if (buffer_release == ref->buffer_release) |
| 2260 | return; |
| 2261 | |
| 2262 | if (ref->buffer_release) { |
| 2263 | ref->buffer_release->ref_count--; |
| 2264 | wl_list_remove(&ref->destroy_listener.link); |
| 2265 | if (ref->buffer_release->ref_count == 0) |
| 2266 | weston_buffer_release_destroy(ref->buffer_release); |
| 2267 | } |
| 2268 | |
| 2269 | if (buffer_release) { |
| 2270 | buffer_release->ref_count++; |
| 2271 | wl_resource_add_destroy_listener(buffer_release->resource, |
| 2272 | &ref->destroy_listener); |
| 2273 | } |
| 2274 | |
| 2275 | ref->buffer_release = buffer_release; |
| 2276 | ref->destroy_listener.notify = |
| 2277 | weston_buffer_release_reference_handle_destroy; |
| 2278 | } |
| 2279 | |
| 2280 | WL_EXPORT void |
| 2281 | weston_buffer_release_move(struct weston_buffer_release_reference *dest, |
| 2282 | struct weston_buffer_release_reference *src) |
| 2283 | { |
| 2284 | weston_buffer_release_reference(dest, src->buffer_release); |
| 2285 | weston_buffer_release_reference(src, NULL); |
| 2286 | } |
| 2287 | |
| 2288 | static void |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2289 | weston_surface_attach(struct weston_surface *surface, |
| 2290 | struct weston_buffer *buffer) |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2291 | { |
| 2292 | weston_buffer_reference(&surface->buffer_ref, buffer); |
| 2293 | |
Pekka Paalanen | a6421c4 | 2012-12-04 15:58:10 +0200 | [diff] [blame] | 2294 | if (!buffer) { |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2295 | if (weston_surface_is_mapped(surface)) |
| 2296 | weston_surface_unmap(surface); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2297 | } |
| 2298 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2299 | surface->compositor->renderer->attach(surface, buffer); |
Pekka Paalanen | bb2f3f2 | 2014-03-14 14:38:11 +0200 | [diff] [blame] | 2300 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 2301 | weston_surface_calculate_size_from_buffer(surface); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2302 | weston_presentation_feedback_discard_list(&surface->feedback_list); |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 2303 | } |
| 2304 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 2305 | /** weston_compositor_damage_all |
| 2306 | * \ingroup compositor |
| 2307 | */ |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2308 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2309 | weston_compositor_damage_all(struct weston_compositor *compositor) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2310 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2311 | struct weston_output *output; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2312 | |
| 2313 | wl_list_for_each(output, &compositor->output_list, link) |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2314 | weston_output_damage(output); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2315 | } |
| 2316 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 2317 | /** |
| 2318 | * \ingroup output |
| 2319 | */ |
Kristian Høgsberg | 9f404b7 | 2012-01-26 00:11:01 -0500 | [diff] [blame] | 2320 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2321 | weston_output_damage(struct weston_output *output) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2322 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2323 | struct weston_compositor *compositor = output->compositor; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2324 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 2325 | pixman_region32_union(&compositor->primary_plane.damage, |
| 2326 | &compositor->primary_plane.damage, |
| 2327 | &output->region); |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2328 | weston_output_schedule_repaint(output); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2329 | } |
| 2330 | |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame] | 2331 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2332 | surface_flush_damage(struct weston_surface *surface) |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2333 | { |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2334 | if (surface->buffer_ref.buffer && |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2335 | wl_shm_buffer_get(surface->buffer_ref.buffer->resource)) |
Kristian Høgsberg | fa1be02 | 2012-09-05 22:49:55 -0400 | [diff] [blame] | 2336 | surface->compositor->renderer->flush_damage(surface); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2337 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2338 | if (weston_timeline_enabled_ && |
| 2339 | pixman_region32_not_empty(&surface->damage)) |
| 2340 | TL_POINT("core_flush_damage", TLP_SURFACE(surface), |
| 2341 | TLP_OUTPUT(surface->output), TLP_END); |
| 2342 | |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 2343 | pixman_region32_clear(&surface->damage); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2344 | } |
| 2345 | |
| 2346 | static void |
| 2347 | view_accumulate_damage(struct weston_view *view, |
| 2348 | pixman_region32_t *opaque) |
| 2349 | { |
| 2350 | pixman_region32_t damage; |
| 2351 | |
| 2352 | pixman_region32_init(&damage); |
| 2353 | if (view->transform.enabled) { |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2354 | pixman_box32_t *extents; |
| 2355 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2356 | extents = pixman_region32_extents(&view->surface->damage); |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 2357 | view_compute_bbox(view, extents, &damage); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2358 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2359 | pixman_region32_copy(&damage, &view->surface->damage); |
| 2360 | pixman_region32_translate(&damage, |
Pekka Paalanen | 502f5e0 | 2015-02-23 14:08:25 +0200 | [diff] [blame] | 2361 | view->geometry.x, view->geometry.y); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2362 | } |
| 2363 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 2364 | pixman_region32_intersect(&damage, &damage, |
| 2365 | &view->transform.boundingbox); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2366 | pixman_region32_subtract(&damage, &damage, opaque); |
| 2367 | pixman_region32_union(&view->plane->damage, |
| 2368 | &view->plane->damage, &damage); |
| 2369 | pixman_region32_fini(&damage); |
| 2370 | pixman_region32_copy(&view->clip, opaque); |
Pekka Paalanen | 8844bf2 | 2015-02-18 16:30:47 +0200 | [diff] [blame] | 2371 | pixman_region32_union(opaque, opaque, &view->transform.opaque); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2372 | } |
| 2373 | |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 2374 | static void |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2375 | compositor_accumulate_damage(struct weston_compositor *ec) |
| 2376 | { |
| 2377 | struct weston_plane *plane; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2378 | struct weston_view *ev; |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2379 | pixman_region32_t opaque, clip; |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2380 | |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2381 | pixman_region32_init(&clip); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2382 | |
| 2383 | wl_list_for_each(plane, &ec->plane_list, link) { |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2384 | pixman_region32_copy(&plane->clip, &clip); |
| 2385 | |
| 2386 | pixman_region32_init(&opaque); |
| 2387 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2388 | wl_list_for_each(ev, &ec->view_list, link) { |
| 2389 | if (ev->plane != plane) |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2390 | continue; |
| 2391 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2392 | view_accumulate_damage(ev, &opaque); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2393 | } |
| 2394 | |
| 2395 | pixman_region32_union(&clip, &clip, &opaque); |
| 2396 | pixman_region32_fini(&opaque); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2397 | } |
| 2398 | |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2399 | pixman_region32_fini(&clip); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2400 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2401 | wl_list_for_each(ev, &ec->view_list, link) |
Derek Foreman | 060cf11 | 2015-11-18 16:32:26 -0600 | [diff] [blame] | 2402 | ev->surface->touched = false; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2403 | |
| 2404 | wl_list_for_each(ev, &ec->view_list, link) { |
| 2405 | if (ev->surface->touched) |
| 2406 | continue; |
Derek Foreman | 060cf11 | 2015-11-18 16:32:26 -0600 | [diff] [blame] | 2407 | ev->surface->touched = true; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2408 | |
| 2409 | surface_flush_damage(ev->surface); |
| 2410 | |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2411 | /* Both the renderer and the backend have seen the buffer |
| 2412 | * by now. If renderer needs the buffer, it has its own |
| 2413 | * reference set. If the backend wants to keep the buffer |
| 2414 | * around for migrating the surface into a non-primary plane |
| 2415 | * later, keep_buffer is true. Otherwise, drop the core |
| 2416 | * reference now, and allow early buffer release. This enables |
| 2417 | * clients to use single-buffering. |
| 2418 | */ |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2419 | if (!ev->surface->keep_buffer) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2420 | weston_buffer_reference(&ev->surface->buffer_ref, NULL); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2421 | weston_buffer_release_reference( |
| 2422 | &ev->surface->buffer_release_ref, NULL); |
| 2423 | } |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2424 | } |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2425 | } |
| 2426 | |
| 2427 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2428 | surface_stash_subsurface_views(struct weston_surface *surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2429 | { |
| 2430 | struct weston_subsurface *sub; |
| 2431 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2432 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2433 | if (sub->surface == surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2434 | continue; |
| 2435 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2436 | wl_list_insert_list(&sub->unused_views, &sub->surface->views); |
| 2437 | wl_list_init(&sub->surface->views); |
| 2438 | |
| 2439 | surface_stash_subsurface_views(sub->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2440 | } |
| 2441 | } |
| 2442 | |
| 2443 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2444 | surface_free_unused_subsurface_views(struct weston_surface *surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2445 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2446 | struct weston_subsurface *sub; |
| 2447 | struct weston_view *view, *nv; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2448 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2449 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
| 2450 | if (sub->surface == surface) |
| 2451 | continue; |
| 2452 | |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 2453 | wl_list_for_each_safe(view, nv, &sub->unused_views, surface_link) { |
| 2454 | weston_view_unmap (view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2455 | weston_view_destroy(view); |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 2456 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2457 | |
| 2458 | surface_free_unused_subsurface_views(sub->surface); |
| 2459 | } |
| 2460 | } |
| 2461 | |
| 2462 | static void |
| 2463 | view_list_add_subsurface_view(struct weston_compositor *compositor, |
| 2464 | struct weston_subsurface *sub, |
| 2465 | struct weston_view *parent) |
| 2466 | { |
| 2467 | struct weston_subsurface *child; |
| 2468 | struct weston_view *view = NULL, *iv; |
| 2469 | |
Pekka Paalanen | 661de3a | 2014-07-28 12:49:24 +0300 | [diff] [blame] | 2470 | if (!weston_surface_is_mapped(sub->surface)) |
| 2471 | return; |
| 2472 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2473 | wl_list_for_each(iv, &sub->unused_views, surface_link) { |
| 2474 | if (iv->geometry.parent == parent) { |
| 2475 | view = iv; |
| 2476 | break; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2477 | } |
| 2478 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2479 | |
| 2480 | if (view) { |
| 2481 | /* Put it back in the surface's list of views */ |
| 2482 | wl_list_remove(&view->surface_link); |
| 2483 | wl_list_insert(&sub->surface->views, &view->surface_link); |
| 2484 | } else { |
| 2485 | view = weston_view_create(sub->surface); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2486 | weston_view_set_position(view, |
| 2487 | sub->position.x, |
| 2488 | sub->position.y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2489 | weston_view_set_transform_parent(view, parent); |
| 2490 | } |
| 2491 | |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 2492 | view->parent_view = parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2493 | weston_view_update_transform(view); |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 2494 | view->is_mapped = true; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2495 | |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2496 | if (wl_list_empty(&sub->surface->subsurface_list)) { |
| 2497 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 2498 | return; |
| 2499 | } |
| 2500 | |
| 2501 | wl_list_for_each(child, &sub->surface->subsurface_list, parent_link) { |
| 2502 | if (child->surface == sub->surface) |
| 2503 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 2504 | else |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2505 | view_list_add_subsurface_view(compositor, child, view); |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2506 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2507 | } |
| 2508 | |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 2509 | /* This recursively adds the sub-surfaces for a view, relying on the |
| 2510 | * sub-surface order. Thus, if a client restacks the sub-surfaces, that |
| 2511 | * change first happens to the sub-surface list, and then automatically |
| 2512 | * propagates here. See weston_surface_damage_subsurfaces() for how the |
| 2513 | * sub-surfaces receive damage when the client changes the state. |
| 2514 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2515 | static void |
| 2516 | view_list_add(struct weston_compositor *compositor, |
| 2517 | struct weston_view *view) |
| 2518 | { |
| 2519 | struct weston_subsurface *sub; |
| 2520 | |
| 2521 | weston_view_update_transform(view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2522 | |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2523 | if (wl_list_empty(&view->surface->subsurface_list)) { |
| 2524 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 2525 | return; |
| 2526 | } |
| 2527 | |
| 2528 | wl_list_for_each(sub, &view->surface->subsurface_list, parent_link) { |
| 2529 | if (sub->surface == view->surface) |
| 2530 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 2531 | else |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2532 | view_list_add_subsurface_view(compositor, sub, view); |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2533 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2534 | } |
| 2535 | |
| 2536 | static void |
| 2537 | weston_compositor_build_view_list(struct weston_compositor *compositor) |
| 2538 | { |
| 2539 | struct weston_view *view; |
| 2540 | struct weston_layer *layer; |
| 2541 | |
| 2542 | wl_list_for_each(layer, &compositor->layer_list, link) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2543 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2544 | surface_stash_subsurface_views(view->surface); |
| 2545 | |
| 2546 | wl_list_init(&compositor->view_list); |
| 2547 | wl_list_for_each(layer, &compositor->layer_list, link) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2548 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2549 | view_list_add(compositor, view); |
| 2550 | } |
| 2551 | } |
| 2552 | |
| 2553 | wl_list_for_each(layer, &compositor->layer_list, link) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2554 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2555 | surface_free_unused_subsurface_views(view->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2556 | } |
| 2557 | |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2558 | static void |
| 2559 | weston_output_take_feedback_list(struct weston_output *output, |
| 2560 | struct weston_surface *surface) |
| 2561 | { |
| 2562 | struct weston_view *view; |
| 2563 | struct weston_presentation_feedback *feedback; |
| 2564 | uint32_t flags = 0xffffffff; |
| 2565 | |
| 2566 | if (wl_list_empty(&surface->feedback_list)) |
| 2567 | return; |
| 2568 | |
| 2569 | /* All views must have the flag for the flag to survive. */ |
| 2570 | wl_list_for_each(view, &surface->views, surface_link) { |
| 2571 | /* ignore views that are not on this output at all */ |
| 2572 | if (view->output_mask & (1u << output->id)) |
| 2573 | flags &= view->psf_flags; |
| 2574 | } |
| 2575 | |
| 2576 | wl_list_for_each(feedback, &surface->feedback_list, link) |
| 2577 | feedback->psf_flags = flags; |
| 2578 | |
| 2579 | wl_list_insert_list(&output->feedback_list, &surface->feedback_list); |
| 2580 | wl_list_init(&surface->feedback_list); |
| 2581 | } |
| 2582 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2583 | static int |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2584 | weston_output_repaint(struct weston_output *output, void *repaint_data) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2585 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2586 | struct weston_compositor *ec = output->compositor; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2587 | struct weston_view *ev; |
Kristian Høgsberg | 30c018b | 2012-01-26 08:40:37 -0500 | [diff] [blame] | 2588 | struct weston_animation *animation, *next; |
| 2589 | struct weston_frame_callback *cb, *cnext; |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 2590 | struct wl_list frame_callback_list; |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2591 | pixman_region32_t output_damage; |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2592 | int r; |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 2593 | uint32_t frame_time_msec; |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 2594 | enum weston_hdcp_protection highest_requested = WESTON_HDCP_DISABLE; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 2595 | |
Ander Conselvan de Oliveira | e1e2352 | 2013-12-13 22:10:55 +0200 | [diff] [blame] | 2596 | if (output->destroying) |
| 2597 | return 0; |
| 2598 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2599 | TL_POINT("core_repaint_begin", TLP_OUTPUT(output), TLP_END); |
| 2600 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2601 | /* Rebuild the surface list and update surface transforms up front. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2602 | weston_compositor_build_view_list(ec); |
Pekka Paalanen | 15d60ef | 2012-01-27 14:38:33 +0200 | [diff] [blame] | 2603 | |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 2604 | /* Find the highest protection desired for an output */ |
| 2605 | wl_list_for_each(ev, &ec->view_list, link) { |
| 2606 | if (ev->surface->output_mask & (1u << output->id)) { |
| 2607 | /* |
| 2608 | * The desired_protection of the output should be the |
| 2609 | * maximum of the desired_protection of the surfaces, |
| 2610 | * that are displayed on that output, to avoid |
| 2611 | * reducing the protection for existing surfaces. |
| 2612 | */ |
| 2613 | if (ev->surface->desired_protection > highest_requested) |
| 2614 | highest_requested = |
| 2615 | ev->surface->desired_protection; |
| 2616 | } |
| 2617 | } |
| 2618 | |
| 2619 | output->desired_protection = highest_requested; |
| 2620 | |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2621 | if (output->assign_planes && !output->disable_planes) { |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2622 | output->assign_planes(output, repaint_data); |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2623 | } else { |
| 2624 | wl_list_for_each(ev, &ec->view_list, link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2625 | weston_view_move_to_plane(ev, &ec->primary_plane); |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2626 | ev->psf_flags = 0; |
| 2627 | } |
| 2628 | } |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 2629 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2630 | wl_list_init(&frame_callback_list); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2631 | wl_list_for_each(ev, &ec->view_list, link) { |
| 2632 | /* Note: This operation is safe to do multiple times on the |
| 2633 | * same surface. |
| 2634 | */ |
| 2635 | if (ev->surface->output == output) { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2636 | wl_list_insert_list(&frame_callback_list, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2637 | &ev->surface->frame_callback_list); |
| 2638 | wl_list_init(&ev->surface->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2639 | |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2640 | weston_output_take_feedback_list(output, ev->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2641 | } |
| 2642 | } |
| 2643 | |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2644 | compositor_accumulate_damage(ec); |
Kristian Høgsberg | 53df1d8 | 2011-06-23 21:11:19 -0400 | [diff] [blame] | 2645 | |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 2646 | pixman_region32_init(&output_damage); |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 2647 | pixman_region32_intersect(&output_damage, |
| 2648 | &ec->primary_plane.damage, &output->region); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2649 | pixman_region32_subtract(&output_damage, |
| 2650 | &output_damage, &ec->primary_plane.clip); |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 2651 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2652 | if (output->dirty) |
| 2653 | weston_output_update_matrix(output); |
| 2654 | |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2655 | r = output->repaint(output, &output_damage, repaint_data); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2656 | |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 2657 | pixman_region32_fini(&output_damage); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 2658 | |
Daniel Stone | 09a97e2 | 2017-03-01 11:34:06 +0000 | [diff] [blame] | 2659 | output->repaint_needed = false; |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2660 | if (r == 0) |
| 2661 | output->repaint_status = REPAINT_AWAITING_COMPLETION; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 2662 | |
Kristian Høgsberg | aa6019e | 2012-03-11 16:35:16 -0400 | [diff] [blame] | 2663 | weston_compositor_repick(ec); |
Kristian Høgsberg | aa6019e | 2012-03-11 16:35:16 -0400 | [diff] [blame] | 2664 | |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 2665 | frame_time_msec = timespec_to_msec(&output->frame_time); |
| 2666 | |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 2667 | wl_list_for_each_safe(cb, cnext, &frame_callback_list, link) { |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 2668 | wl_callback_send_done(cb->resource, frame_time_msec); |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 2669 | wl_resource_destroy(cb->resource); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 2670 | } |
| 2671 | |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 2672 | wl_list_for_each_safe(animation, next, &output->animation_list, link) { |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 2673 | animation->frame_counter++; |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 2674 | animation->frame(animation, output, &output->frame_time); |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 2675 | } |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2676 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2677 | TL_POINT("core_repaint_posted", TLP_OUTPUT(output), TLP_END); |
| 2678 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2679 | return r; |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2680 | } |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 2681 | |
Pekka Paalanen | 8291979 | 2014-05-21 13:51:49 +0300 | [diff] [blame] | 2682 | static void |
| 2683 | weston_output_schedule_repaint_reset(struct weston_output *output) |
| 2684 | { |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2685 | output->repaint_status = REPAINT_NOT_SCHEDULED; |
Pekka Paalanen | 8291979 | 2014-05-21 13:51:49 +0300 | [diff] [blame] | 2686 | TL_POINT("core_repaint_exit_loop", TLP_OUTPUT(output), TLP_END); |
Pekka Paalanen | 8291979 | 2014-05-21 13:51:49 +0300 | [diff] [blame] | 2687 | } |
| 2688 | |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2689 | static int |
| 2690 | weston_output_maybe_repaint(struct weston_output *output, struct timespec *now, |
| 2691 | void *repaint_data) |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2692 | { |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2693 | struct weston_compositor *compositor = output->compositor; |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2694 | int ret = 0; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2695 | int64_t msec_to_repaint; |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2696 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2697 | /* We're not ready yet; come back to make a decision later. */ |
| 2698 | if (output->repaint_status != REPAINT_SCHEDULED) |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2699 | return ret; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2700 | |
| 2701 | msec_to_repaint = timespec_sub_to_msec(&output->next_repaint, now); |
| 2702 | if (msec_to_repaint > 1) |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2703 | return ret; |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2704 | |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 2705 | /* If we're sleeping, drop the repaint machinery entirely; we will |
| 2706 | * explicitly repaint all outputs when we come back. */ |
| 2707 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING || |
| 2708 | compositor->state == WESTON_COMPOSITOR_OFFSCREEN) |
| 2709 | goto err; |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2710 | |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 2711 | /* We don't actually need to repaint this output; drop it from |
| 2712 | * repaint until something causes damage. */ |
| 2713 | if (!output->repaint_needed) |
| 2714 | goto err; |
| 2715 | |
| 2716 | /* If repaint fails, we aren't going to get weston_output_finish_frame |
| 2717 | * to trigger a new repaint, so drop it from repaint and hope |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2718 | * something schedules a successful repaint later. As repainting may |
| 2719 | * take some time, re-read our clock as a courtesy to the next |
| 2720 | * output. */ |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2721 | ret = weston_output_repaint(output, repaint_data); |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2722 | weston_compositor_read_presentation_clock(compositor, now); |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 2723 | if (ret != 0) |
| 2724 | goto err; |
| 2725 | |
Tomohito Esaki | 7f4d9ff | 2018-06-05 10:37:06 +0900 | [diff] [blame] | 2726 | output->repainted = true; |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2727 | return ret; |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 2728 | |
| 2729 | err: |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2730 | weston_output_schedule_repaint_reset(output); |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2731 | return ret; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2732 | } |
| 2733 | |
| 2734 | static void |
| 2735 | output_repaint_timer_arm(struct weston_compositor *compositor) |
| 2736 | { |
| 2737 | struct weston_output *output; |
| 2738 | bool any_should_repaint = false; |
| 2739 | struct timespec now; |
Sergi Granell | b4c0886 | 2017-03-18 13:01:15 +0100 | [diff] [blame] | 2740 | int64_t msec_to_next = INT64_MAX; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2741 | |
| 2742 | weston_compositor_read_presentation_clock(compositor, &now); |
| 2743 | |
| 2744 | wl_list_for_each(output, &compositor->output_list, link) { |
| 2745 | int64_t msec_to_this; |
| 2746 | |
| 2747 | if (output->repaint_status != REPAINT_SCHEDULED) |
| 2748 | continue; |
| 2749 | |
| 2750 | msec_to_this = timespec_sub_to_msec(&output->next_repaint, |
| 2751 | &now); |
| 2752 | if (!any_should_repaint || msec_to_this < msec_to_next) |
| 2753 | msec_to_next = msec_to_this; |
| 2754 | |
| 2755 | any_should_repaint = true; |
| 2756 | } |
| 2757 | |
| 2758 | if (!any_should_repaint) |
| 2759 | return; |
| 2760 | |
| 2761 | /* Even if we should repaint immediately, add the minimum 1 ms delay. |
| 2762 | * This is a workaround to allow coalescing multiple output repaints |
| 2763 | * particularly from weston_output_finish_frame() |
| 2764 | * into the same call, which would not happen if we called |
| 2765 | * output_repaint_timer_handler() directly. |
| 2766 | */ |
| 2767 | if (msec_to_next < 1) |
| 2768 | msec_to_next = 1; |
| 2769 | |
| 2770 | wl_event_source_timer_update(compositor->repaint_timer, msec_to_next); |
| 2771 | } |
| 2772 | |
| 2773 | static int |
| 2774 | output_repaint_timer_handler(void *data) |
| 2775 | { |
| 2776 | struct weston_compositor *compositor = data; |
| 2777 | struct weston_output *output; |
| 2778 | struct timespec now; |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2779 | void *repaint_data = NULL; |
Emre Ucan | e479ed8 | 2018-03-20 15:29:40 +0100 | [diff] [blame] | 2780 | int ret = 0; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2781 | |
| 2782 | weston_compositor_read_presentation_clock(compositor, &now); |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2783 | |
| 2784 | if (compositor->backend->repaint_begin) |
| 2785 | repaint_data = compositor->backend->repaint_begin(compositor); |
| 2786 | |
| 2787 | wl_list_for_each(output, &compositor->output_list, link) { |
| 2788 | ret = weston_output_maybe_repaint(output, &now, repaint_data); |
| 2789 | if (ret) |
| 2790 | break; |
| 2791 | } |
| 2792 | |
| 2793 | if (ret == 0) { |
Tomohito Esaki | 09bfcd6 | 2018-06-05 10:37:05 +0900 | [diff] [blame] | 2794 | if (compositor->backend->repaint_flush) |
Antonio Borneo | c90fccc | 2019-06-30 15:51:10 +0200 | [diff] [blame] | 2795 | ret = compositor->backend->repaint_flush(compositor, |
| 2796 | repaint_data); |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2797 | } else { |
Antonio Borneo | c90fccc | 2019-06-30 15:51:10 +0200 | [diff] [blame] | 2798 | if (compositor->backend->repaint_cancel) |
| 2799 | compositor->backend->repaint_cancel(compositor, |
| 2800 | repaint_data); |
| 2801 | } |
| 2802 | |
| 2803 | if (ret != 0) { |
Tomohito Esaki | 7f4d9ff | 2018-06-05 10:37:06 +0900 | [diff] [blame] | 2804 | wl_list_for_each(output, &compositor->output_list, link) { |
| 2805 | if (output->repainted) |
| 2806 | weston_output_schedule_repaint_reset(output); |
| 2807 | } |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2808 | } |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2809 | |
Tomohito Esaki | ddaf95c | 2018-07-10 11:47:15 +0900 | [diff] [blame] | 2810 | wl_list_for_each(output, &compositor->output_list, link) |
| 2811 | output->repainted = false; |
| 2812 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2813 | output_repaint_timer_arm(compositor); |
| 2814 | |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2815 | return 0; |
| 2816 | } |
| 2817 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 2818 | /** |
| 2819 | * \ingroup output |
| 2820 | */ |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2821 | WL_EXPORT void |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 2822 | weston_output_finish_frame(struct weston_output *output, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 2823 | const struct timespec *stamp, |
| 2824 | uint32_t presented_flags) |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2825 | { |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2826 | struct weston_compositor *compositor = output->compositor; |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2827 | int32_t refresh_nsec; |
| 2828 | struct timespec now; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2829 | int64_t msec_rel; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2830 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2831 | |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2832 | assert(output->repaint_status == REPAINT_AWAITING_COMPLETION); |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2833 | assert(stamp || (presented_flags & WP_PRESENTATION_FEEDBACK_INVALID)); |
| 2834 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2835 | weston_compositor_read_presentation_clock(compositor, &now); |
| 2836 | |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2837 | /* If we haven't been supplied any timestamp at all, we don't have a |
| 2838 | * timebase to work against, so any delay just wastes time. Push a |
| 2839 | * repaint as soon as possible so we can get on with it. */ |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2840 | if (!stamp) { |
| 2841 | output->next_repaint = now; |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2842 | goto out; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2843 | } |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2844 | |
Marius Vlad | df9278a | 2018-03-06 18:56:23 +0200 | [diff] [blame] | 2845 | TL_POINT("core_repaint_finished", TLP_OUTPUT(output), |
| 2846 | TLP_VBLANK(stamp), TLP_END); |
| 2847 | |
Pekka Paalanen | d7894d0 | 2015-07-03 15:08:53 +0300 | [diff] [blame] | 2848 | refresh_nsec = millihz_to_nsec(output->current_mode->refresh); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2849 | weston_presentation_feedback_present_list(&output->feedback_list, |
| 2850 | output, refresh_nsec, stamp, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 2851 | output->msc, |
| 2852 | presented_flags); |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2853 | |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 2854 | output->frame_time = *stamp; |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2855 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2856 | timespec_add_nsec(&output->next_repaint, stamp, refresh_nsec); |
| 2857 | timespec_add_msec(&output->next_repaint, &output->next_repaint, |
| 2858 | -compositor->repaint_msec); |
| 2859 | msec_rel = timespec_sub_to_msec(&output->next_repaint, &now); |
Daniel Stone | 84aff5c | 2017-03-01 11:34:04 +0000 | [diff] [blame] | 2860 | |
| 2861 | if (msec_rel < -1000 || msec_rel > 1000) { |
Pekka Paalanen | 8fd4de4 | 2015-03-19 12:27:29 +0200 | [diff] [blame] | 2862 | static bool warned; |
| 2863 | |
| 2864 | if (!warned) |
| 2865 | weston_log("Warning: computed repaint delay is " |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2866 | "insane: %lld msec\n", (long long) msec_rel); |
Pekka Paalanen | 8fd4de4 | 2015-03-19 12:27:29 +0200 | [diff] [blame] | 2867 | warned = true; |
| 2868 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2869 | output->next_repaint = now; |
Pekka Paalanen | 8fd4de4 | 2015-03-19 12:27:29 +0200 | [diff] [blame] | 2870 | } |
| 2871 | |
Mario Kleiner | b7df04e | 2015-06-21 21:25:15 +0200 | [diff] [blame] | 2872 | /* Called from restart_repaint_loop and restart happens already after |
| 2873 | * the deadline given by repaint_msec? In that case we delay until |
| 2874 | * the deadline of the next frame, to give clients a more predictable |
| 2875 | * timing of the repaint cycle to lock on. */ |
Daniel Stone | eca5cca | 2017-02-28 21:53:51 +0000 | [diff] [blame] | 2876 | if (presented_flags == WP_PRESENTATION_FEEDBACK_INVALID && |
| 2877 | msec_rel < 0) { |
| 2878 | while (timespec_sub_to_nsec(&output->next_repaint, &now) < 0) { |
| 2879 | timespec_add_nsec(&output->next_repaint, |
| 2880 | &output->next_repaint, |
| 2881 | refresh_nsec); |
| 2882 | } |
| 2883 | } |
Mario Kleiner | b7df04e | 2015-06-21 21:25:15 +0200 | [diff] [blame] | 2884 | |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2885 | out: |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2886 | output->repaint_status = REPAINT_SCHEDULED; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2887 | output_repaint_timer_arm(compositor); |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2888 | } |
| 2889 | |
| 2890 | static void |
| 2891 | idle_repaint(void *data) |
| 2892 | { |
| 2893 | struct weston_output *output = data; |
Antonio Borneo | c90fccc | 2019-06-30 15:51:10 +0200 | [diff] [blame] | 2894 | int ret; |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2895 | |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2896 | assert(output->repaint_status == REPAINT_BEGIN_FROM_IDLE); |
| 2897 | output->repaint_status = REPAINT_AWAITING_COMPLETION; |
Pekka Paalanen | dcbcfc7 | 2017-10-26 14:33:59 +0300 | [diff] [blame] | 2898 | output->idle_repaint_source = NULL; |
Antonio Borneo | c90fccc | 2019-06-30 15:51:10 +0200 | [diff] [blame] | 2899 | ret = output->start_repaint_loop(output); |
| 2900 | if (ret != 0) |
| 2901 | weston_output_schedule_repaint_reset(output); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2902 | } |
| 2903 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2904 | WL_EXPORT void |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2905 | weston_layer_entry_insert(struct weston_layer_entry *list, |
| 2906 | struct weston_layer_entry *entry) |
| 2907 | { |
| 2908 | wl_list_insert(&list->link, &entry->link); |
| 2909 | entry->layer = list->layer; |
| 2910 | } |
| 2911 | |
| 2912 | WL_EXPORT void |
| 2913 | weston_layer_entry_remove(struct weston_layer_entry *entry) |
| 2914 | { |
| 2915 | wl_list_remove(&entry->link); |
| 2916 | wl_list_init(&entry->link); |
| 2917 | entry->layer = NULL; |
| 2918 | } |
| 2919 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 2920 | |
| 2921 | /** Initialize the weston_layer struct. |
| 2922 | * |
| 2923 | * \param compositor The compositor instance |
| 2924 | * \param layer The layer to initialize |
| 2925 | */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2926 | WL_EXPORT void |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 2927 | weston_layer_init(struct weston_layer *layer, |
| 2928 | struct weston_compositor *compositor) |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2929 | { |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 2930 | layer->compositor = compositor; |
| 2931 | wl_list_init(&layer->link); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2932 | wl_list_init(&layer->view_list.link); |
| 2933 | layer->view_list.layer = layer; |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 2934 | weston_layer_set_mask_infinite(layer); |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 2935 | } |
| 2936 | |
| 2937 | /** Sets the position of the layer in the layer list. The layer will be placed |
| 2938 | * below any layer with the same position value, if any. |
| 2939 | * This function is safe to call if the layer is already on the list, but the |
| 2940 | * layer may be moved below other layers at the same position, if any. |
| 2941 | * |
| 2942 | * \param layer The layer to modify |
| 2943 | * \param position The position the layer will be placed at |
| 2944 | */ |
| 2945 | WL_EXPORT void |
| 2946 | weston_layer_set_position(struct weston_layer *layer, |
| 2947 | enum weston_layer_position position) |
| 2948 | { |
| 2949 | struct weston_layer *below; |
| 2950 | |
| 2951 | wl_list_remove(&layer->link); |
| 2952 | |
| 2953 | /* layer_list is ordered from top to bottom, the last layer being the |
| 2954 | * background with the smallest position value */ |
| 2955 | |
| 2956 | layer->position = position; |
| 2957 | wl_list_for_each_reverse(below, &layer->compositor->layer_list, link) { |
| 2958 | if (below->position >= layer->position) { |
| 2959 | wl_list_insert(&below->link, &layer->link); |
| 2960 | return; |
| 2961 | } |
| 2962 | } |
| 2963 | wl_list_insert(&layer->compositor->layer_list, &layer->link); |
| 2964 | } |
| 2965 | |
| 2966 | /** Hide a layer by taking it off the layer list. |
| 2967 | * This function is safe to call if the layer is not on the list. |
| 2968 | * |
| 2969 | * \param layer The layer to hide |
| 2970 | */ |
| 2971 | WL_EXPORT void |
| 2972 | weston_layer_unset_position(struct weston_layer *layer) |
| 2973 | { |
| 2974 | wl_list_remove(&layer->link); |
| 2975 | wl_list_init(&layer->link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2976 | } |
| 2977 | |
| 2978 | WL_EXPORT void |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 2979 | weston_layer_set_mask(struct weston_layer *layer, |
| 2980 | int x, int y, int width, int height) |
| 2981 | { |
| 2982 | struct weston_view *view; |
| 2983 | |
| 2984 | layer->mask.x1 = x; |
| 2985 | layer->mask.x2 = x + width; |
| 2986 | layer->mask.y1 = y; |
| 2987 | layer->mask.y2 = y + height; |
| 2988 | |
| 2989 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
| 2990 | weston_view_geometry_dirty(view); |
| 2991 | } |
| 2992 | } |
| 2993 | |
| 2994 | WL_EXPORT void |
| 2995 | weston_layer_set_mask_infinite(struct weston_layer *layer) |
| 2996 | { |
| 2997 | weston_layer_set_mask(layer, INT32_MIN, INT32_MIN, |
| 2998 | UINT32_MAX, UINT32_MAX); |
| 2999 | } |
| 3000 | |
Daniel Stone | 3b77563 | 2018-07-20 08:38:25 +0100 | [diff] [blame] | 3001 | WL_EXPORT bool |
| 3002 | weston_layer_mask_is_infinite(struct weston_layer *layer) |
| 3003 | { |
| 3004 | return layer->mask.x1 == INT32_MIN && |
| 3005 | layer->mask.y1 == INT32_MIN && |
| 3006 | layer->mask.x2 == INT32_MIN + UINT32_MAX && |
| 3007 | layer->mask.y2 == INT32_MIN + UINT32_MAX; |
| 3008 | } |
| 3009 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 3010 | /** |
| 3011 | * \ingroup output |
| 3012 | */ |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 3013 | WL_EXPORT void |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 3014 | weston_output_schedule_repaint(struct weston_output *output) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 3015 | { |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 3016 | struct weston_compositor *compositor = output->compositor; |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 3017 | struct wl_event_loop *loop; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 3018 | |
Bryce Harrington | 08976ac | 2016-08-30 12:05:16 -0700 | [diff] [blame] | 3019 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING || |
| 3020 | compositor->state == WESTON_COMPOSITOR_OFFSCREEN) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 3021 | return; |
| 3022 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3023 | if (!output->repaint_needed) |
| 3024 | TL_POINT("core_repaint_req", TLP_OUTPUT(output), TLP_END); |
| 3025 | |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 3026 | loop = wl_display_get_event_loop(compositor->wl_display); |
Daniel Stone | 09a97e2 | 2017-03-01 11:34:06 +0000 | [diff] [blame] | 3027 | output->repaint_needed = true; |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 3028 | |
| 3029 | /* If we already have a repaint scheduled for our idle handler, |
| 3030 | * no need to set it again. If the repaint has been called but |
| 3031 | * not finished, then weston_output_finish_frame() will notice |
| 3032 | * that a repaint is needed and schedule one. */ |
| 3033 | if (output->repaint_status != REPAINT_NOT_SCHEDULED) |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 3034 | return; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 3035 | |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 3036 | output->repaint_status = REPAINT_BEGIN_FROM_IDLE; |
Pekka Paalanen | dcbcfc7 | 2017-10-26 14:33:59 +0300 | [diff] [blame] | 3037 | assert(!output->idle_repaint_source); |
| 3038 | output->idle_repaint_source = wl_event_loop_add_idle(loop, idle_repaint, |
| 3039 | output); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3040 | TL_POINT("core_repaint_enter_loop", TLP_OUTPUT(output), TLP_END); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 3041 | } |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 3042 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 3043 | /** weston_compositor_schedule_repaint |
| 3044 | * \ingroup compositor |
| 3045 | */ |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3046 | WL_EXPORT void |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 3047 | weston_compositor_schedule_repaint(struct weston_compositor *compositor) |
| 3048 | { |
| 3049 | struct weston_output *output; |
| 3050 | |
| 3051 | wl_list_for_each(output, &compositor->output_list, link) |
| 3052 | weston_output_schedule_repaint(output); |
| 3053 | } |
| 3054 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 3055 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 3056 | surface_destroy(struct wl_client *client, struct wl_resource *resource) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 3057 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3058 | wl_resource_destroy(resource); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 3059 | } |
| 3060 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 3061 | static void |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 3062 | surface_attach(struct wl_client *client, |
| 3063 | struct wl_resource *resource, |
| 3064 | struct wl_resource *buffer_resource, int32_t sx, int32_t sy) |
| 3065 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3066 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 3067 | struct weston_buffer *buffer = NULL; |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 3068 | |
Kristian Høgsberg | ab19f93 | 2013-08-20 11:30:54 -0700 | [diff] [blame] | 3069 | if (buffer_resource) { |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 3070 | buffer = weston_buffer_from_resource(buffer_resource); |
Kristian Høgsberg | ab19f93 | 2013-08-20 11:30:54 -0700 | [diff] [blame] | 3071 | if (buffer == NULL) { |
| 3072 | wl_client_post_no_memory(client); |
| 3073 | return; |
| 3074 | } |
Kristian Høgsberg | 08b58c7 | 2013-08-15 12:26:42 -0700 | [diff] [blame] | 3075 | } |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 3076 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 3077 | /* Attach, attach, without commit in between does not send |
| 3078 | * wl_buffer.release. */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3079 | weston_surface_state_set_buffer(&surface->pending, buffer); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 3080 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3081 | surface->pending.sx = sx; |
| 3082 | surface->pending.sy = sy; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3083 | surface->pending.newly_attached = 1; |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 3084 | } |
| 3085 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 3086 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3087 | surface_damage(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 3088 | struct wl_resource *resource, |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3089 | 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] | 3090 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3091 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 9d69f8e | 2010-09-03 14:46:38 -0400 | [diff] [blame] | 3092 | |
Derek Foreman | 57e92ed | 2015-11-17 14:11:35 -0600 | [diff] [blame] | 3093 | if (width <= 0 || height <= 0) |
| 3094 | return; |
| 3095 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3096 | pixman_region32_union_rect(&surface->pending.damage_surface, |
| 3097 | &surface->pending.damage_surface, |
| 3098 | x, y, width, height); |
| 3099 | } |
| 3100 | |
| 3101 | static void |
| 3102 | surface_damage_buffer(struct wl_client *client, |
| 3103 | struct wl_resource *resource, |
| 3104 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 3105 | { |
| 3106 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
| 3107 | |
| 3108 | if (width <= 0 || height <= 0) |
| 3109 | return; |
| 3110 | |
| 3111 | pixman_region32_union_rect(&surface->pending.damage_buffer, |
| 3112 | &surface->pending.damage_buffer, |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 3113 | x, y, width, height); |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 3114 | } |
| 3115 | |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3116 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 3117 | destroy_frame_callback(struct wl_resource *resource) |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3118 | { |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 3119 | struct weston_frame_callback *cb = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 3120 | |
| 3121 | wl_list_remove(&cb->link); |
Pekka Paalanen | 8c19645 | 2011-11-15 11:45:42 +0200 | [diff] [blame] | 3122 | free(cb); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3123 | } |
| 3124 | |
| 3125 | static void |
| 3126 | surface_frame(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 3127 | struct wl_resource *resource, uint32_t callback) |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3128 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3129 | struct weston_frame_callback *cb; |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3130 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3131 | |
| 3132 | cb = malloc(sizeof *cb); |
| 3133 | if (cb == NULL) { |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 3134 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3135 | return; |
| 3136 | } |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 3137 | |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 3138 | cb->resource = wl_resource_create(client, &wl_callback_interface, 1, |
| 3139 | callback); |
| 3140 | if (cb->resource == NULL) { |
| 3141 | free(cb); |
| 3142 | wl_resource_post_no_memory(resource); |
| 3143 | return; |
| 3144 | } |
| 3145 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3146 | wl_resource_set_implementation(cb->resource, NULL, cb, |
| 3147 | destroy_frame_callback); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3148 | |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 3149 | wl_list_insert(surface->pending.frame_callback_list.prev, &cb->link); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3150 | } |
| 3151 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3152 | static void |
| 3153 | surface_set_opaque_region(struct wl_client *client, |
| 3154 | struct wl_resource *resource, |
| 3155 | struct wl_resource *region_resource) |
| 3156 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3157 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3158 | struct weston_region *region; |
| 3159 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3160 | if (region_resource) { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 3161 | region = wl_resource_get_user_data(region_resource); |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 3162 | pixman_region32_copy(&surface->pending.opaque, |
| 3163 | ®ion->region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3164 | } else { |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 3165 | pixman_region32_clear(&surface->pending.opaque); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3166 | } |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3167 | } |
| 3168 | |
| 3169 | static void |
| 3170 | surface_set_input_region(struct wl_client *client, |
| 3171 | struct wl_resource *resource, |
| 3172 | struct wl_resource *region_resource) |
| 3173 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3174 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 010f98b | 2012-02-23 17:30:45 -0500 | [diff] [blame] | 3175 | struct weston_region *region; |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3176 | |
| 3177 | if (region_resource) { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 3178 | region = wl_resource_get_user_data(region_resource); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3179 | pixman_region32_copy(&surface->pending.input, |
| 3180 | ®ion->region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3181 | } else { |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3182 | pixman_region32_fini(&surface->pending.input); |
| 3183 | region_init_infinite(&surface->pending.input); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3184 | } |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3185 | } |
| 3186 | |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 3187 | /* Cause damage to this sub-surface and all its children. |
| 3188 | * |
| 3189 | * This is useful when there are state changes that need an implicit |
| 3190 | * damage, e.g. a z-order change. |
| 3191 | */ |
| 3192 | static void |
| 3193 | weston_surface_damage_subsurfaces(struct weston_subsurface *sub) |
| 3194 | { |
| 3195 | struct weston_subsurface *child; |
| 3196 | |
| 3197 | weston_surface_damage(sub->surface); |
| 3198 | sub->reordered = false; |
| 3199 | |
| 3200 | wl_list_for_each(child, &sub->surface->subsurface_list, parent_link) |
| 3201 | if (child != sub) |
| 3202 | weston_surface_damage_subsurfaces(child); |
| 3203 | } |
| 3204 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3205 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3206 | weston_surface_commit_subsurface_order(struct weston_surface *surface) |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3207 | { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3208 | struct weston_subsurface *sub; |
| 3209 | |
| 3210 | wl_list_for_each_reverse(sub, &surface->subsurface_list_pending, |
| 3211 | parent_link_pending) { |
| 3212 | wl_list_remove(&sub->parent_link); |
| 3213 | wl_list_insert(&surface->subsurface_list, &sub->parent_link); |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 3214 | |
| 3215 | if (sub->reordered) |
| 3216 | weston_surface_damage_subsurfaces(sub); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3217 | } |
| 3218 | } |
| 3219 | |
| 3220 | static void |
Pekka Paalanen | 04baea5 | 2016-04-26 15:50:58 +0300 | [diff] [blame] | 3221 | weston_surface_build_buffer_matrix(const struct weston_surface *surface, |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 3222 | struct weston_matrix *matrix) |
| 3223 | { |
Pekka Paalanen | 04baea5 | 2016-04-26 15:50:58 +0300 | [diff] [blame] | 3224 | const struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 3225 | double src_width, src_height, dest_width, dest_height; |
| 3226 | |
| 3227 | weston_matrix_init(matrix); |
| 3228 | |
| 3229 | if (vp->buffer.src_width == wl_fixed_from_int(-1)) { |
| 3230 | src_width = surface->width_from_buffer; |
| 3231 | src_height = surface->height_from_buffer; |
| 3232 | } else { |
| 3233 | src_width = wl_fixed_to_double(vp->buffer.src_width); |
| 3234 | src_height = wl_fixed_to_double(vp->buffer.src_height); |
| 3235 | } |
| 3236 | |
| 3237 | if (vp->surface.width == -1) { |
| 3238 | dest_width = src_width; |
| 3239 | dest_height = src_height; |
| 3240 | } else { |
| 3241 | dest_width = vp->surface.width; |
| 3242 | dest_height = vp->surface.height; |
| 3243 | } |
| 3244 | |
| 3245 | if (src_width != dest_width || src_height != dest_height) |
| 3246 | weston_matrix_scale(matrix, |
| 3247 | src_width / dest_width, |
| 3248 | src_height / dest_height, 1); |
| 3249 | |
| 3250 | if (vp->buffer.src_width != wl_fixed_from_int(-1)) |
| 3251 | weston_matrix_translate(matrix, |
| 3252 | wl_fixed_to_double(vp->buffer.src_x), |
| 3253 | wl_fixed_to_double(vp->buffer.src_y), |
| 3254 | 0); |
| 3255 | |
| 3256 | switch (vp->buffer.transform) { |
| 3257 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 3258 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 3259 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 3260 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 3261 | weston_matrix_scale(matrix, -1, 1, 1); |
| 3262 | weston_matrix_translate(matrix, |
| 3263 | surface->width_from_buffer, 0, 0); |
| 3264 | break; |
| 3265 | } |
| 3266 | |
| 3267 | switch (vp->buffer.transform) { |
| 3268 | default: |
| 3269 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 3270 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 3271 | break; |
| 3272 | case WL_OUTPUT_TRANSFORM_90: |
| 3273 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 3274 | weston_matrix_rotate_xy(matrix, 0, 1); |
| 3275 | weston_matrix_translate(matrix, |
| 3276 | surface->height_from_buffer, 0, 0); |
| 3277 | break; |
| 3278 | case WL_OUTPUT_TRANSFORM_180: |
| 3279 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 3280 | weston_matrix_rotate_xy(matrix, -1, 0); |
| 3281 | weston_matrix_translate(matrix, |
| 3282 | surface->width_from_buffer, |
| 3283 | surface->height_from_buffer, 0); |
| 3284 | break; |
| 3285 | case WL_OUTPUT_TRANSFORM_270: |
| 3286 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 3287 | weston_matrix_rotate_xy(matrix, 0, -1); |
| 3288 | weston_matrix_translate(matrix, |
| 3289 | 0, surface->width_from_buffer, 0); |
| 3290 | break; |
| 3291 | } |
| 3292 | |
| 3293 | weston_matrix_scale(matrix, vp->buffer.scale, vp->buffer.scale, 1); |
| 3294 | } |
| 3295 | |
Pekka Paalanen | d9aae9c | 2016-04-26 13:46:38 +0300 | [diff] [blame] | 3296 | /** |
| 3297 | * Compute a + b > c while being safe to overflows. |
| 3298 | */ |
| 3299 | static bool |
| 3300 | fixed_sum_gt(wl_fixed_t a, wl_fixed_t b, wl_fixed_t c) |
| 3301 | { |
| 3302 | return (int64_t)a + (int64_t)b > (int64_t)c; |
| 3303 | } |
| 3304 | |
| 3305 | static bool |
| 3306 | weston_surface_is_pending_viewport_source_valid( |
| 3307 | const struct weston_surface *surface) |
| 3308 | { |
| 3309 | const struct weston_surface_state *pend = &surface->pending; |
| 3310 | const struct weston_buffer_viewport *vp = &pend->buffer_viewport; |
| 3311 | int width_from_buffer = 0; |
| 3312 | int height_from_buffer = 0; |
| 3313 | wl_fixed_t w; |
| 3314 | wl_fixed_t h; |
| 3315 | |
| 3316 | /* If viewport source rect is not set, it is always ok. */ |
| 3317 | if (vp->buffer.src_width == wl_fixed_from_int(-1)) |
| 3318 | return true; |
| 3319 | |
| 3320 | if (pend->newly_attached) { |
| 3321 | if (pend->buffer) { |
| 3322 | convert_size_by_transform_scale(&width_from_buffer, |
| 3323 | &height_from_buffer, |
| 3324 | pend->buffer->width, |
| 3325 | pend->buffer->height, |
| 3326 | vp->buffer.transform, |
| 3327 | vp->buffer.scale); |
| 3328 | } else { |
| 3329 | /* No buffer: viewport is irrelevant. */ |
| 3330 | return true; |
| 3331 | } |
| 3332 | } else { |
| 3333 | width_from_buffer = surface->width_from_buffer; |
| 3334 | height_from_buffer = surface->height_from_buffer; |
| 3335 | } |
| 3336 | |
| 3337 | assert((width_from_buffer == 0) == (height_from_buffer == 0)); |
| 3338 | assert(width_from_buffer >= 0 && height_from_buffer >= 0); |
| 3339 | |
| 3340 | /* No buffer: viewport is irrelevant. */ |
| 3341 | if (width_from_buffer == 0 || height_from_buffer == 0) |
| 3342 | return true; |
| 3343 | |
| 3344 | /* overflow checks for wl_fixed_from_int() */ |
| 3345 | if (width_from_buffer > wl_fixed_to_int(INT32_MAX)) |
| 3346 | return false; |
| 3347 | if (height_from_buffer > wl_fixed_to_int(INT32_MAX)) |
| 3348 | return false; |
| 3349 | |
| 3350 | w = wl_fixed_from_int(width_from_buffer); |
| 3351 | h = wl_fixed_from_int(height_from_buffer); |
| 3352 | |
| 3353 | if (fixed_sum_gt(vp->buffer.src_x, vp->buffer.src_width, w)) |
| 3354 | return false; |
| 3355 | if (fixed_sum_gt(vp->buffer.src_y, vp->buffer.src_height, h)) |
| 3356 | return false; |
| 3357 | |
| 3358 | return true; |
| 3359 | } |
| 3360 | |
Pekka Paalanen | bb32ccc | 2016-04-26 14:28:28 +0300 | [diff] [blame] | 3361 | static bool |
| 3362 | fixed_is_integer(wl_fixed_t v) |
| 3363 | { |
| 3364 | return (v & 0xff) == 0; |
| 3365 | } |
| 3366 | |
| 3367 | static bool |
| 3368 | weston_surface_is_pending_viewport_dst_size_int( |
| 3369 | const struct weston_surface *surface) |
| 3370 | { |
| 3371 | const struct weston_buffer_viewport *vp = |
| 3372 | &surface->pending.buffer_viewport; |
| 3373 | |
| 3374 | if (vp->surface.width != -1) { |
| 3375 | assert(vp->surface.width > 0 && vp->surface.height > 0); |
| 3376 | return true; |
| 3377 | } |
| 3378 | |
| 3379 | return fixed_is_integer(vp->buffer.src_width) && |
| 3380 | fixed_is_integer(vp->buffer.src_height); |
| 3381 | } |
| 3382 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3383 | /* Translate pending damage in buffer co-ordinates to surface |
| 3384 | * co-ordinates and union it with a pixman_region32_t. |
| 3385 | * This should only be called after the buffer is attached. |
| 3386 | */ |
| 3387 | static void |
| 3388 | apply_damage_buffer(pixman_region32_t *dest, |
| 3389 | struct weston_surface *surface, |
| 3390 | struct weston_surface_state *state) |
| 3391 | { |
| 3392 | struct weston_buffer *buffer = surface->buffer_ref.buffer; |
| 3393 | |
| 3394 | /* wl_surface.damage_buffer needs to be clipped to the buffer, |
| 3395 | * translated into surface co-ordinates and unioned with |
| 3396 | * any other surface damage. |
| 3397 | * None of this makes sense if there is no buffer though. |
| 3398 | */ |
| 3399 | if (buffer && pixman_region32_not_empty(&state->damage_buffer)) { |
| 3400 | pixman_region32_t buffer_damage; |
| 3401 | |
| 3402 | pixman_region32_intersect_rect(&state->damage_buffer, |
| 3403 | &state->damage_buffer, |
| 3404 | 0, 0, buffer->width, |
| 3405 | buffer->height); |
| 3406 | pixman_region32_init(&buffer_damage); |
| 3407 | weston_matrix_transform_region(&buffer_damage, |
| 3408 | &surface->buffer_to_surface_matrix, |
| 3409 | &state->damage_buffer); |
| 3410 | pixman_region32_union(dest, dest, &buffer_damage); |
| 3411 | pixman_region32_fini(&buffer_damage); |
| 3412 | } |
| 3413 | /* We should clear this on commit even if there was no buffer */ |
| 3414 | pixman_region32_clear(&state->damage_buffer); |
| 3415 | } |
| 3416 | |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 3417 | static void |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 3418 | weston_surface_set_desired_protection(struct weston_surface *surface, |
| 3419 | enum weston_hdcp_protection protection) |
| 3420 | { |
| 3421 | if (surface->desired_protection == protection) |
| 3422 | return; |
| 3423 | surface->desired_protection = protection; |
| 3424 | weston_surface_damage(surface); |
| 3425 | } |
| 3426 | |
| 3427 | static void |
Ankit Nautiyal | 5cfe03c | 2019-03-28 15:05:42 +0530 | [diff] [blame] | 3428 | weston_surface_set_protection_mode(struct weston_surface *surface, |
| 3429 | enum weston_surface_protection_mode p_mode) |
| 3430 | { |
| 3431 | struct content_protection *cp = surface->compositor->content_protection; |
| 3432 | struct protected_surface *psurface; |
| 3433 | |
| 3434 | surface->protection_mode = p_mode; |
| 3435 | wl_list_for_each(psurface, &cp->protected_list, link) { |
| 3436 | if (!psurface || psurface->surface != surface) |
| 3437 | continue; |
| 3438 | weston_protected_surface_send_event(psurface, |
| 3439 | surface->current_protection); |
| 3440 | } |
| 3441 | } |
| 3442 | |
| 3443 | static void |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3444 | weston_surface_commit_state(struct weston_surface *surface, |
| 3445 | struct weston_surface_state *state) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3446 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3447 | struct weston_view *view; |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 3448 | pixman_region32_t opaque; |
| 3449 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3450 | /* wl_surface.set_buffer_transform */ |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3451 | /* wl_surface.set_buffer_scale */ |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 3452 | /* wp_viewport.set_source */ |
| 3453 | /* wp_viewport.set_destination */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3454 | surface->buffer_viewport = state->buffer_viewport; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3455 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3456 | /* wl_surface.attach */ |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3457 | if (state->newly_attached) { |
| 3458 | /* zwp_surface_synchronization_v1.set_acquire_fence */ |
| 3459 | fd_move(&surface->acquire_fence_fd, |
| 3460 | &state->acquire_fence_fd); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3461 | /* zwp_surface_synchronization_v1.get_release */ |
| 3462 | weston_buffer_release_move(&surface->buffer_release_ref, |
| 3463 | &state->buffer_release_ref); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3464 | weston_surface_attach(surface, state->buffer); |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3465 | } |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3466 | weston_surface_state_set_buffer(state, NULL); |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3467 | assert(state->acquire_fence_fd == -1); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3468 | assert(state->buffer_release_ref.buffer_release == NULL); |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3469 | |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 3470 | weston_surface_build_buffer_matrix(surface, |
| 3471 | &surface->surface_to_buffer_matrix); |
| 3472 | weston_matrix_invert(&surface->buffer_to_surface_matrix, |
| 3473 | &surface->surface_to_buffer_matrix); |
| 3474 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3475 | if (state->newly_attached || state->buffer_viewport.changed) { |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3476 | weston_surface_update_size(surface); |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3477 | if (surface->committed) |
| 3478 | surface->committed(surface, state->sx, state->sy); |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3479 | } |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3480 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3481 | state->sx = 0; |
| 3482 | state->sy = 0; |
| 3483 | state->newly_attached = 0; |
| 3484 | state->buffer_viewport.changed = 0; |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 3485 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3486 | /* wl_surface.damage and wl_surface.damage_buffer */ |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3487 | if (weston_timeline_enabled_ && |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3488 | (pixman_region32_not_empty(&state->damage_surface) || |
| 3489 | pixman_region32_not_empty(&state->damage_buffer))) |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3490 | TL_POINT("core_commit_damage", TLP_SURFACE(surface), TLP_END); |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3491 | |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 3492 | pixman_region32_union(&surface->damage, &surface->damage, |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3493 | &state->damage_surface); |
| 3494 | |
| 3495 | apply_damage_buffer(&surface->damage, surface, state); |
| 3496 | |
Kristian Høgsberg | 4d0214c | 2012-11-08 11:36:02 -0500 | [diff] [blame] | 3497 | pixman_region32_intersect_rect(&surface->damage, &surface->damage, |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 3498 | 0, 0, surface->width, surface->height); |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3499 | pixman_region32_clear(&state->damage_surface); |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 3500 | |
| 3501 | /* wl_surface.set_opaque_region */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3502 | pixman_region32_init(&opaque); |
| 3503 | pixman_region32_intersect_rect(&opaque, &state->opaque, |
| 3504 | 0, 0, surface->width, surface->height); |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 3505 | |
| 3506 | if (!pixman_region32_equal(&opaque, &surface->opaque)) { |
| 3507 | pixman_region32_copy(&surface->opaque, &opaque); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3508 | wl_list_for_each(view, &surface->views, surface_link) |
| 3509 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 3510 | } |
| 3511 | |
| 3512 | pixman_region32_fini(&opaque); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3513 | |
| 3514 | /* wl_surface.set_input_region */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3515 | pixman_region32_intersect_rect(&surface->input, &state->input, |
| 3516 | 0, 0, surface->width, surface->height); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3517 | |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 3518 | /* wl_surface.frame */ |
| 3519 | wl_list_insert_list(&surface->frame_callback_list, |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3520 | &state->frame_callback_list); |
| 3521 | wl_list_init(&state->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3522 | |
| 3523 | /* XXX: |
| 3524 | * What should happen with a feedback request, if there |
| 3525 | * is no wl_buffer attached for this commit? |
| 3526 | */ |
| 3527 | |
| 3528 | /* presentation.feedback */ |
| 3529 | wl_list_insert_list(&surface->feedback_list, |
| 3530 | &state->feedback_list); |
| 3531 | wl_list_init(&state->feedback_list); |
Jonas Ådahl | 5d9ca27 | 2016-07-22 17:48:03 +0800 | [diff] [blame] | 3532 | |
Ankit Nautiyal | 5cfe03c | 2019-03-28 15:05:42 +0530 | [diff] [blame] | 3533 | /* weston_protected_surface.enforced/relaxed */ |
| 3534 | if (surface->protection_mode != state->protection_mode) |
| 3535 | weston_surface_set_protection_mode(surface, |
| 3536 | state->protection_mode); |
| 3537 | |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 3538 | /* weston_protected_surface.set_type */ |
| 3539 | weston_surface_set_desired_protection(surface, state->desired_protection); |
| 3540 | |
Jonas Ådahl | 5d9ca27 | 2016-07-22 17:48:03 +0800 | [diff] [blame] | 3541 | wl_signal_emit(&surface->commit_signal, surface); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3542 | } |
| 3543 | |
| 3544 | static void |
| 3545 | weston_surface_commit(struct weston_surface *surface) |
| 3546 | { |
| 3547 | weston_surface_commit_state(surface, &surface->pending); |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 3548 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3549 | weston_surface_commit_subsurface_order(surface); |
| 3550 | |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3551 | weston_surface_schedule_repaint(surface); |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3552 | } |
| 3553 | |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3554 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3555 | weston_subsurface_commit(struct weston_subsurface *sub); |
| 3556 | |
| 3557 | static void |
| 3558 | weston_subsurface_parent_commit(struct weston_subsurface *sub, |
| 3559 | int parent_is_synchronized); |
| 3560 | |
| 3561 | static void |
| 3562 | surface_commit(struct wl_client *client, struct wl_resource *resource) |
| 3563 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3564 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3565 | struct weston_subsurface *sub = weston_surface_to_subsurface(surface); |
| 3566 | |
Pekka Paalanen | d9aae9c | 2016-04-26 13:46:38 +0300 | [diff] [blame] | 3567 | if (!weston_surface_is_pending_viewport_source_valid(surface)) { |
| 3568 | assert(surface->viewport_resource); |
| 3569 | |
| 3570 | wl_resource_post_error(surface->viewport_resource, |
| 3571 | WP_VIEWPORT_ERROR_OUT_OF_BUFFER, |
| 3572 | "wl_surface@%d has viewport source outside buffer", |
| 3573 | wl_resource_get_id(resource)); |
| 3574 | return; |
| 3575 | } |
| 3576 | |
Pekka Paalanen | bb32ccc | 2016-04-26 14:28:28 +0300 | [diff] [blame] | 3577 | if (!weston_surface_is_pending_viewport_dst_size_int(surface)) { |
| 3578 | assert(surface->viewport_resource); |
| 3579 | |
| 3580 | wl_resource_post_error(surface->viewport_resource, |
| 3581 | WP_VIEWPORT_ERROR_BAD_SIZE, |
| 3582 | "wl_surface@%d viewport dst size not integer", |
| 3583 | wl_resource_get_id(resource)); |
| 3584 | return; |
| 3585 | } |
| 3586 | |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3587 | if (surface->pending.acquire_fence_fd >= 0) { |
| 3588 | assert(surface->synchronization_resource); |
| 3589 | |
| 3590 | if (!surface->pending.buffer) { |
| 3591 | fd_clear(&surface->pending.acquire_fence_fd); |
| 3592 | wl_resource_post_error(surface->synchronization_resource, |
| 3593 | ZWP_LINUX_SURFACE_SYNCHRONIZATION_V1_ERROR_NO_BUFFER, |
| 3594 | "wl_surface@%"PRIu32" no buffer for synchronization", |
| 3595 | wl_resource_get_id(resource)); |
| 3596 | return; |
| 3597 | } |
| 3598 | |
| 3599 | /* We support fences for both wp_linux_dmabuf and opaque EGL |
| 3600 | * buffers, as mandated by minor version 2 of the |
| 3601 | * zwp_linux_explicit_synchronization_v1 protocol. Since |
| 3602 | * renderers that support fences currently only support these |
| 3603 | * two buffer types plus SHM buffers, we can just check for the |
| 3604 | * SHM buffer case here. |
| 3605 | */ |
| 3606 | if (wl_shm_buffer_get(surface->pending.buffer->resource)) { |
| 3607 | fd_clear(&surface->pending.acquire_fence_fd); |
| 3608 | wl_resource_post_error(surface->synchronization_resource, |
| 3609 | ZWP_LINUX_SURFACE_SYNCHRONIZATION_V1_ERROR_UNSUPPORTED_BUFFER, |
| 3610 | "wl_surface@%"PRIu32" unsupported buffer for synchronization", |
| 3611 | wl_resource_get_id(resource)); |
| 3612 | return; |
| 3613 | } |
| 3614 | } |
| 3615 | |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3616 | if (surface->pending.buffer_release_ref.buffer_release && |
| 3617 | !surface->pending.buffer) { |
| 3618 | assert(surface->synchronization_resource); |
| 3619 | |
| 3620 | wl_resource_post_error(surface->synchronization_resource, |
| 3621 | ZWP_LINUX_SURFACE_SYNCHRONIZATION_V1_ERROR_NO_BUFFER, |
| 3622 | "wl_surface@%"PRIu32" no buffer for synchronization", |
| 3623 | wl_resource_get_id(resource)); |
| 3624 | return; |
| 3625 | } |
| 3626 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3627 | if (sub) { |
| 3628 | weston_subsurface_commit(sub); |
| 3629 | return; |
| 3630 | } |
| 3631 | |
| 3632 | weston_surface_commit(surface); |
| 3633 | |
| 3634 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
| 3635 | if (sub->surface != surface) |
| 3636 | weston_subsurface_parent_commit(sub, 0); |
| 3637 | } |
| 3638 | } |
| 3639 | |
| 3640 | static void |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3641 | surface_set_buffer_transform(struct wl_client *client, |
| 3642 | struct wl_resource *resource, int transform) |
| 3643 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3644 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3645 | |
Jonny Lamb | a55f139 | 2014-05-30 12:07:15 +0200 | [diff] [blame] | 3646 | /* if wl_output.transform grows more members this will need to be updated. */ |
| 3647 | if (transform < 0 || |
| 3648 | transform > WL_OUTPUT_TRANSFORM_FLIPPED_270) { |
| 3649 | wl_resource_post_error(resource, |
| 3650 | WL_SURFACE_ERROR_INVALID_TRANSFORM, |
| 3651 | "buffer transform must be a valid transform " |
| 3652 | "('%d' specified)", transform); |
| 3653 | return; |
| 3654 | } |
| 3655 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 3656 | surface->pending.buffer_viewport.buffer.transform = transform; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3657 | surface->pending.buffer_viewport.changed = 1; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3658 | } |
| 3659 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3660 | static void |
| 3661 | surface_set_buffer_scale(struct wl_client *client, |
| 3662 | struct wl_resource *resource, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 3663 | int32_t scale) |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3664 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3665 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3666 | |
Jonny Lamb | a55f139 | 2014-05-30 12:07:15 +0200 | [diff] [blame] | 3667 | if (scale < 1) { |
| 3668 | wl_resource_post_error(resource, |
| 3669 | WL_SURFACE_ERROR_INVALID_SCALE, |
| 3670 | "buffer scale must be at least one " |
| 3671 | "('%d' specified)", scale); |
| 3672 | return; |
| 3673 | } |
| 3674 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 3675 | surface->pending.buffer_viewport.buffer.scale = scale; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3676 | surface->pending.buffer_viewport.changed = 1; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3677 | } |
| 3678 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 3679 | static const struct wl_surface_interface surface_interface = { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3680 | surface_destroy, |
| 3681 | surface_attach, |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3682 | surface_damage, |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3683 | surface_frame, |
| 3684 | surface_set_opaque_region, |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3685 | surface_set_input_region, |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3686 | surface_commit, |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3687 | surface_set_buffer_transform, |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3688 | surface_set_buffer_scale, |
| 3689 | surface_damage_buffer |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3690 | }; |
| 3691 | |
| 3692 | static void |
| 3693 | compositor_create_surface(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 3694 | struct wl_resource *resource, uint32_t id) |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3695 | { |
Kristian Høgsberg | c2d7042 | 2013-06-25 15:34:33 -0400 | [diff] [blame] | 3696 | struct weston_compositor *ec = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3697 | struct weston_surface *surface; |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3698 | |
Kristian Høgsberg | 18c9300 | 2012-01-27 11:58:31 -0500 | [diff] [blame] | 3699 | surface = weston_surface_create(ec); |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 3700 | if (surface == NULL) { |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 3701 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3702 | return; |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 3703 | } |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3704 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3705 | surface->resource = |
| 3706 | wl_resource_create(client, &wl_surface_interface, |
| 3707 | wl_resource_get_version(resource), id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 3708 | if (surface->resource == NULL) { |
| 3709 | weston_surface_destroy(surface); |
| 3710 | wl_resource_post_no_memory(resource); |
| 3711 | return; |
| 3712 | } |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3713 | wl_resource_set_implementation(surface->resource, &surface_interface, |
| 3714 | surface, destroy_surface); |
Kristian Høgsberg | f03a04a | 2014-04-06 22:04:50 -0700 | [diff] [blame] | 3715 | |
| 3716 | wl_signal_emit(&ec->create_surface_signal, surface); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3717 | } |
| 3718 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3719 | static void |
| 3720 | destroy_region(struct wl_resource *resource) |
| 3721 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 3722 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3723 | |
| 3724 | pixman_region32_fini(®ion->region); |
| 3725 | free(region); |
| 3726 | } |
| 3727 | |
| 3728 | static void |
| 3729 | region_destroy(struct wl_client *client, struct wl_resource *resource) |
| 3730 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3731 | wl_resource_destroy(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3732 | } |
| 3733 | |
| 3734 | static void |
| 3735 | region_add(struct wl_client *client, struct wl_resource *resource, |
| 3736 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 3737 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 3738 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3739 | |
| 3740 | pixman_region32_union_rect(®ion->region, ®ion->region, |
| 3741 | x, y, width, height); |
| 3742 | } |
| 3743 | |
| 3744 | static void |
| 3745 | region_subtract(struct wl_client *client, struct wl_resource *resource, |
| 3746 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 3747 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 3748 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3749 | pixman_region32_t rect; |
| 3750 | |
| 3751 | pixman_region32_init_rect(&rect, x, y, width, height); |
| 3752 | pixman_region32_subtract(®ion->region, ®ion->region, &rect); |
| 3753 | pixman_region32_fini(&rect); |
| 3754 | } |
| 3755 | |
| 3756 | static const struct wl_region_interface region_interface = { |
| 3757 | region_destroy, |
| 3758 | region_add, |
| 3759 | region_subtract |
| 3760 | }; |
| 3761 | |
| 3762 | static void |
| 3763 | compositor_create_region(struct wl_client *client, |
| 3764 | struct wl_resource *resource, uint32_t id) |
| 3765 | { |
| 3766 | struct weston_region *region; |
| 3767 | |
| 3768 | region = malloc(sizeof *region); |
| 3769 | if (region == NULL) { |
| 3770 | wl_resource_post_no_memory(resource); |
| 3771 | return; |
| 3772 | } |
| 3773 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3774 | pixman_region32_init(®ion->region); |
| 3775 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3776 | region->resource = |
| 3777 | wl_resource_create(client, &wl_region_interface, 1, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 3778 | if (region->resource == NULL) { |
| 3779 | free(region); |
| 3780 | wl_resource_post_no_memory(resource); |
| 3781 | return; |
| 3782 | } |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3783 | wl_resource_set_implementation(region->resource, ®ion_interface, |
| 3784 | region, destroy_region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3785 | } |
| 3786 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 3787 | static const struct wl_compositor_interface compositor_interface = { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3788 | compositor_create_surface, |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3789 | compositor_create_region |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3790 | }; |
| 3791 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3792 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3793 | weston_subsurface_commit_from_cache(struct weston_subsurface *sub) |
| 3794 | { |
| 3795 | struct weston_surface *surface = sub->surface; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3796 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3797 | weston_surface_commit_state(surface, &sub->cached); |
| 3798 | weston_buffer_reference(&sub->cached_buffer_ref, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3799 | |
| 3800 | weston_surface_commit_subsurface_order(surface); |
| 3801 | |
| 3802 | weston_surface_schedule_repaint(surface); |
| 3803 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3804 | sub->has_cached_data = 0; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3805 | } |
| 3806 | |
| 3807 | static void |
| 3808 | weston_subsurface_commit_to_cache(struct weston_subsurface *sub) |
| 3809 | { |
| 3810 | struct weston_surface *surface = sub->surface; |
| 3811 | |
| 3812 | /* |
| 3813 | * If this commit would cause the surface to move by the |
| 3814 | * attach(dx, dy) parameters, the old damage region must be |
| 3815 | * translated to correspond to the new surface coordinate system |
Chris Michael | 062edf2 | 2015-11-26 11:30:00 -0500 | [diff] [blame] | 3816 | * origin. |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3817 | */ |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3818 | pixman_region32_translate(&sub->cached.damage_surface, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3819 | -surface->pending.sx, -surface->pending.sy); |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3820 | pixman_region32_union(&sub->cached.damage_surface, |
| 3821 | &sub->cached.damage_surface, |
| 3822 | &surface->pending.damage_surface); |
| 3823 | pixman_region32_clear(&surface->pending.damage_surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3824 | |
| 3825 | if (surface->pending.newly_attached) { |
| 3826 | sub->cached.newly_attached = 1; |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3827 | weston_surface_state_set_buffer(&sub->cached, |
| 3828 | surface->pending.buffer); |
| 3829 | weston_buffer_reference(&sub->cached_buffer_ref, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3830 | surface->pending.buffer); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3831 | weston_presentation_feedback_discard_list( |
| 3832 | &sub->cached.feedback_list); |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3833 | /* zwp_surface_synchronization_v1.set_acquire_fence */ |
| 3834 | fd_move(&sub->cached.acquire_fence_fd, |
| 3835 | &surface->pending.acquire_fence_fd); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3836 | /* zwp_surface_synchronization_v1.get_release */ |
| 3837 | weston_buffer_release_move(&sub->cached.buffer_release_ref, |
| 3838 | &surface->pending.buffer_release_ref); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3839 | } |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 3840 | sub->cached.desired_protection = surface->pending.desired_protection; |
Ankit Nautiyal | 5cfe03c | 2019-03-28 15:05:42 +0530 | [diff] [blame] | 3841 | sub->cached.protection_mode = surface->pending.protection_mode; |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3842 | assert(surface->pending.acquire_fence_fd == -1); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3843 | assert(surface->pending.buffer_release_ref.buffer_release == NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3844 | sub->cached.sx += surface->pending.sx; |
| 3845 | sub->cached.sy += surface->pending.sy; |
Pekka Paalanen | 260ba38 | 2014-03-14 14:38:12 +0200 | [diff] [blame] | 3846 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3847 | apply_damage_buffer(&sub->cached.damage_surface, surface, &surface->pending); |
| 3848 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3849 | sub->cached.buffer_viewport.changed |= |
| 3850 | surface->pending.buffer_viewport.changed; |
| 3851 | sub->cached.buffer_viewport.buffer = |
| 3852 | surface->pending.buffer_viewport.buffer; |
| 3853 | sub->cached.buffer_viewport.surface = |
| 3854 | surface->pending.buffer_viewport.surface; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3855 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3856 | weston_surface_reset_pending_buffer(surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3857 | |
| 3858 | pixman_region32_copy(&sub->cached.opaque, &surface->pending.opaque); |
| 3859 | |
| 3860 | pixman_region32_copy(&sub->cached.input, &surface->pending.input); |
| 3861 | |
| 3862 | wl_list_insert_list(&sub->cached.frame_callback_list, |
| 3863 | &surface->pending.frame_callback_list); |
| 3864 | wl_list_init(&surface->pending.frame_callback_list); |
| 3865 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3866 | wl_list_insert_list(&sub->cached.feedback_list, |
| 3867 | &surface->pending.feedback_list); |
| 3868 | wl_list_init(&surface->pending.feedback_list); |
| 3869 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3870 | sub->has_cached_data = 1; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3871 | } |
| 3872 | |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 3873 | static bool |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3874 | weston_subsurface_is_synchronized(struct weston_subsurface *sub) |
| 3875 | { |
| 3876 | while (sub) { |
| 3877 | if (sub->synchronized) |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 3878 | return true; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3879 | |
| 3880 | if (!sub->parent) |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 3881 | return false; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3882 | |
| 3883 | sub = weston_surface_to_subsurface(sub->parent); |
| 3884 | } |
| 3885 | |
Carlos Olmedo Escobar | 61a9bf5 | 2014-11-04 14:38:39 +0100 | [diff] [blame] | 3886 | return false; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3887 | } |
| 3888 | |
| 3889 | static void |
| 3890 | weston_subsurface_commit(struct weston_subsurface *sub) |
| 3891 | { |
| 3892 | struct weston_surface *surface = sub->surface; |
| 3893 | struct weston_subsurface *tmp; |
| 3894 | |
| 3895 | /* Recursive check for effectively synchronized. */ |
| 3896 | if (weston_subsurface_is_synchronized(sub)) { |
| 3897 | weston_subsurface_commit_to_cache(sub); |
| 3898 | } else { |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3899 | if (sub->has_cached_data) { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3900 | /* flush accumulated state from cache */ |
| 3901 | weston_subsurface_commit_to_cache(sub); |
| 3902 | weston_subsurface_commit_from_cache(sub); |
| 3903 | } else { |
| 3904 | weston_surface_commit(surface); |
| 3905 | } |
| 3906 | |
| 3907 | wl_list_for_each(tmp, &surface->subsurface_list, parent_link) { |
| 3908 | if (tmp->surface != surface) |
| 3909 | weston_subsurface_parent_commit(tmp, 0); |
| 3910 | } |
| 3911 | } |
| 3912 | } |
| 3913 | |
| 3914 | static void |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3915 | weston_subsurface_synchronized_commit(struct weston_subsurface *sub) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3916 | { |
| 3917 | struct weston_surface *surface = sub->surface; |
| 3918 | struct weston_subsurface *tmp; |
| 3919 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3920 | /* From now on, commit_from_cache the whole sub-tree, regardless of |
| 3921 | * the synchronized mode of each child. This sub-surface or some |
| 3922 | * of its ancestors were synchronized, so we are synchronized |
| 3923 | * all the way down. |
| 3924 | */ |
| 3925 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3926 | if (sub->has_cached_data) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3927 | weston_subsurface_commit_from_cache(sub); |
| 3928 | |
| 3929 | wl_list_for_each(tmp, &surface->subsurface_list, parent_link) { |
| 3930 | if (tmp->surface != surface) |
| 3931 | weston_subsurface_parent_commit(tmp, 1); |
| 3932 | } |
| 3933 | } |
| 3934 | |
| 3935 | static void |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3936 | weston_subsurface_parent_commit(struct weston_subsurface *sub, |
| 3937 | int parent_is_synchronized) |
| 3938 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3939 | struct weston_view *view; |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3940 | if (sub->position.set) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3941 | wl_list_for_each(view, &sub->surface->views, surface_link) |
| 3942 | weston_view_set_position(view, |
| 3943 | sub->position.x, |
| 3944 | sub->position.y); |
| 3945 | |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3946 | sub->position.set = 0; |
| 3947 | } |
| 3948 | |
| 3949 | if (parent_is_synchronized || sub->synchronized) |
| 3950 | weston_subsurface_synchronized_commit(sub); |
| 3951 | } |
| 3952 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3953 | static int |
| 3954 | subsurface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 3955 | { |
| 3956 | return snprintf(buf, len, "sub-surface"); |
| 3957 | } |
| 3958 | |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3959 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3960 | subsurface_committed(struct weston_surface *surface, int32_t dx, int32_t dy) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3961 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3962 | struct weston_view *view; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3963 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3964 | wl_list_for_each(view, &surface->views, surface_link) |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3965 | weston_view_set_position(view, |
| 3966 | view->geometry.x + dx, |
| 3967 | view->geometry.y + dy); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3968 | |
| 3969 | /* No need to check parent mappedness, because if parent is not |
| 3970 | * mapped, parent is not in a visible layer, so this sub-surface |
| 3971 | * will not be drawn either. |
| 3972 | */ |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 3973 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3974 | if (!weston_surface_is_mapped(surface)) { |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 3975 | surface->is_mapped = true; |
Pekka Paalanen | eb3cf22 | 2014-06-30 11:52:07 +0300 | [diff] [blame] | 3976 | |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 3977 | /* Cannot call weston_view_update_transform(), |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3978 | * because that would call it also for the parent surface, |
| 3979 | * which might not be mapped yet. That would lead to |
| 3980 | * inconsistent state, where the window could never be |
| 3981 | * mapped. |
| 3982 | * |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 3983 | * Instead just force the is_mapped flag on, to make |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3984 | * weston_surface_is_mapped() return true, so that when the |
| 3985 | * parent surface does get mapped, this one will get |
Pekka Paalanen | eb3cf22 | 2014-06-30 11:52:07 +0300 | [diff] [blame] | 3986 | * included, too. See view_list_add(). |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3987 | */ |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3988 | } |
| 3989 | } |
| 3990 | |
| 3991 | static struct weston_subsurface * |
| 3992 | weston_surface_to_subsurface(struct weston_surface *surface) |
| 3993 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3994 | if (surface->committed == subsurface_committed) |
| 3995 | return surface->committed_private; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3996 | |
| 3997 | return NULL; |
| 3998 | } |
| 3999 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4000 | WL_EXPORT struct weston_surface * |
| 4001 | weston_surface_get_main_surface(struct weston_surface *surface) |
| 4002 | { |
| 4003 | struct weston_subsurface *sub; |
| 4004 | |
| 4005 | while (surface && (sub = weston_surface_to_subsurface(surface))) |
| 4006 | surface = sub->parent; |
| 4007 | |
| 4008 | return surface; |
| 4009 | } |
| 4010 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4011 | WL_EXPORT int |
| 4012 | weston_surface_set_role(struct weston_surface *surface, |
| 4013 | const char *role_name, |
| 4014 | struct wl_resource *error_resource, |
| 4015 | uint32_t error_code) |
| 4016 | { |
| 4017 | assert(role_name); |
| 4018 | |
| 4019 | if (surface->role_name == NULL || |
| 4020 | surface->role_name == role_name || |
| 4021 | strcmp(surface->role_name, role_name) == 0) { |
| 4022 | surface->role_name = role_name; |
| 4023 | |
| 4024 | return 0; |
| 4025 | } |
| 4026 | |
| 4027 | wl_resource_post_error(error_resource, error_code, |
| 4028 | "Cannot assign role %s to wl_surface@%d," |
| 4029 | " already has role %s\n", |
| 4030 | role_name, |
| 4031 | wl_resource_get_id(surface->resource), |
| 4032 | surface->role_name); |
| 4033 | return -1; |
| 4034 | } |
| 4035 | |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 4036 | WL_EXPORT const char * |
| 4037 | weston_surface_get_role(struct weston_surface *surface) |
| 4038 | { |
| 4039 | return surface->role_name; |
| 4040 | } |
| 4041 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4042 | WL_EXPORT void |
| 4043 | weston_surface_set_label_func(struct weston_surface *surface, |
| 4044 | int (*desc)(struct weston_surface *, |
| 4045 | char *, size_t)) |
| 4046 | { |
| 4047 | surface->get_label = desc; |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 4048 | surface->timeline.force_refresh = 1; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4049 | } |
| 4050 | |
Pekka Paalanen | c647ed7 | 2015-02-09 13:16:57 +0200 | [diff] [blame] | 4051 | /** Get the size of surface contents |
| 4052 | * |
| 4053 | * \param surface The surface to query. |
| 4054 | * \param width Returns the width of raw contents. |
| 4055 | * \param height Returns the height of raw contents. |
| 4056 | * |
| 4057 | * Retrieves the raw surface content size in pixels for the given surface. |
| 4058 | * This is the whole content size in buffer pixels. If the surface |
| 4059 | * has no content or the renderer does not implement this feature, |
| 4060 | * zeroes are returned. |
| 4061 | * |
| 4062 | * This function is used to determine the buffer size needed for |
| 4063 | * a weston_surface_copy_content() call. |
| 4064 | */ |
| 4065 | WL_EXPORT void |
| 4066 | weston_surface_get_content_size(struct weston_surface *surface, |
| 4067 | int *width, int *height) |
| 4068 | { |
| 4069 | struct weston_renderer *rer = surface->compositor->renderer; |
| 4070 | |
| 4071 | if (!rer->surface_get_content_size) { |
| 4072 | *width = 0; |
| 4073 | *height = 0; |
| 4074 | return; |
| 4075 | } |
| 4076 | |
| 4077 | rer->surface_get_content_size(surface, width, height); |
| 4078 | } |
| 4079 | |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 4080 | /** Get the bounding box of a surface and its subsurfaces |
| 4081 | * |
| 4082 | * \param surface The surface to query. |
| 4083 | * \return The bounding box relative to the surface origin. |
| 4084 | * |
| 4085 | */ |
| 4086 | WL_EXPORT struct weston_geometry |
| 4087 | weston_surface_get_bounding_box(struct weston_surface *surface) |
| 4088 | { |
| 4089 | pixman_region32_t region; |
| 4090 | pixman_box32_t *box; |
| 4091 | struct weston_subsurface *subsurface; |
| 4092 | |
| 4093 | pixman_region32_init_rect(®ion, |
| 4094 | 0, 0, |
| 4095 | surface->width, surface->height); |
| 4096 | |
| 4097 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) |
| 4098 | pixman_region32_union_rect(®ion, ®ion, |
| 4099 | subsurface->position.x, |
| 4100 | subsurface->position.y, |
| 4101 | subsurface->surface->width, |
| 4102 | subsurface->surface->height); |
| 4103 | |
| 4104 | box = pixman_region32_extents(®ion); |
| 4105 | struct weston_geometry geometry = { |
| 4106 | .x = box->x1, |
| 4107 | .y = box->y1, |
| 4108 | .width = box->x2 - box->x1, |
| 4109 | .height = box->y2 - box->y1, |
| 4110 | }; |
| 4111 | |
| 4112 | pixman_region32_fini(®ion); |
| 4113 | |
| 4114 | return geometry; |
| 4115 | } |
| 4116 | |
Pekka Paalanen | c647ed7 | 2015-02-09 13:16:57 +0200 | [diff] [blame] | 4117 | /** Copy surface contents to system memory. |
| 4118 | * |
| 4119 | * \param surface The surface to copy from. |
| 4120 | * \param target Pointer to the target memory buffer. |
| 4121 | * \param size Size of the target buffer in bytes. |
| 4122 | * \param src_x X location on contents to copy from. |
| 4123 | * \param src_y Y location on contents to copy from. |
| 4124 | * \param width Width in pixels of the area to copy. |
| 4125 | * \param height Height in pixels of the area to copy. |
| 4126 | * \return 0 for success, -1 for failure. |
| 4127 | * |
| 4128 | * Surface contents are maintained by the renderer. They can be in a |
| 4129 | * reserved weston_buffer or as a copy, e.g. a GL texture, or something |
| 4130 | * else. |
| 4131 | * |
| 4132 | * Surface contents are copied into memory pointed to by target, |
| 4133 | * which has size bytes of space available. The target memory |
| 4134 | * may be larger than needed, but being smaller returns an error. |
| 4135 | * The extra bytes in target may or may not be written; their content is |
| 4136 | * unspecified. Size must be large enough to hold the image. |
| 4137 | * |
| 4138 | * The image in the target memory will be arranged in rows from |
| 4139 | * top to bottom, and pixels on a row from left to right. The pixel |
| 4140 | * format is PIXMAN_a8b8g8r8, 4 bytes per pixel, and stride is exactly |
| 4141 | * width * 4. |
| 4142 | * |
| 4143 | * Parameters src_x and src_y define the upper-left corner in buffer |
| 4144 | * coordinates (pixels) to copy from. Parameters width and height |
| 4145 | * define the size of the area to copy in pixels. |
| 4146 | * |
| 4147 | * The rectangle defined by src_x, src_y, width, height must fit in |
| 4148 | * the surface contents. Otherwise an error is returned. |
| 4149 | * |
Changwoo Cho | f97d250 | 2017-08-05 00:30:47 +0900 | [diff] [blame] | 4150 | * Use weston_surface_get_content_size to determine the content size; the |
Pekka Paalanen | c647ed7 | 2015-02-09 13:16:57 +0200 | [diff] [blame] | 4151 | * needed target buffer size and rectangle limits. |
| 4152 | * |
| 4153 | * CURRENT IMPLEMENTATION RESTRICTIONS: |
| 4154 | * - the machine must be little-endian due to Pixman formats. |
| 4155 | * |
| 4156 | * NOTE: Pixman formats are premultiplied. |
| 4157 | */ |
| 4158 | WL_EXPORT int |
| 4159 | weston_surface_copy_content(struct weston_surface *surface, |
| 4160 | void *target, size_t size, |
| 4161 | int src_x, int src_y, |
| 4162 | int width, int height) |
| 4163 | { |
| 4164 | struct weston_renderer *rer = surface->compositor->renderer; |
| 4165 | int cw, ch; |
| 4166 | const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */ |
| 4167 | |
| 4168 | if (!rer->surface_copy_content) |
| 4169 | return -1; |
| 4170 | |
| 4171 | weston_surface_get_content_size(surface, &cw, &ch); |
| 4172 | |
| 4173 | if (src_x < 0 || src_y < 0) |
| 4174 | return -1; |
| 4175 | |
| 4176 | if (width <= 0 || height <= 0) |
| 4177 | return -1; |
| 4178 | |
| 4179 | if (src_x + width > cw || src_y + height > ch) |
| 4180 | return -1; |
| 4181 | |
| 4182 | if (width * bytespp * height > size) |
| 4183 | return -1; |
| 4184 | |
| 4185 | return rer->surface_copy_content(surface, target, size, |
| 4186 | src_x, src_y, width, height); |
| 4187 | } |
| 4188 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4189 | static void |
| 4190 | subsurface_set_position(struct wl_client *client, |
| 4191 | struct wl_resource *resource, int32_t x, int32_t y) |
| 4192 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4193 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4194 | |
| 4195 | if (!sub) |
| 4196 | return; |
| 4197 | |
| 4198 | sub->position.x = x; |
| 4199 | sub->position.y = y; |
| 4200 | sub->position.set = 1; |
| 4201 | } |
| 4202 | |
| 4203 | static struct weston_subsurface * |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 4204 | subsurface_find_sibling(struct weston_subsurface *sub, |
| 4205 | struct weston_surface *surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4206 | { |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 4207 | struct weston_surface *parent = sub->parent; |
| 4208 | struct weston_subsurface *sibling; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4209 | |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 4210 | wl_list_for_each(sibling, &parent->subsurface_list, parent_link) { |
| 4211 | if (sibling->surface == surface && sibling != sub) |
| 4212 | return sibling; |
| 4213 | } |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4214 | |
| 4215 | return NULL; |
| 4216 | } |
| 4217 | |
| 4218 | static struct weston_subsurface * |
| 4219 | subsurface_sibling_check(struct weston_subsurface *sub, |
| 4220 | struct weston_surface *surface, |
| 4221 | const char *request) |
| 4222 | { |
| 4223 | struct weston_subsurface *sibling; |
| 4224 | |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 4225 | sibling = subsurface_find_sibling(sub, surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4226 | if (!sibling) { |
| 4227 | wl_resource_post_error(sub->resource, |
| 4228 | WL_SUBSURFACE_ERROR_BAD_SURFACE, |
| 4229 | "%s: wl_surface@%d is not a parent or sibling", |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4230 | request, wl_resource_get_id(surface->resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4231 | return NULL; |
| 4232 | } |
| 4233 | |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 4234 | assert(sibling->parent == sub->parent); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4235 | |
| 4236 | return sibling; |
| 4237 | } |
| 4238 | |
| 4239 | static void |
| 4240 | subsurface_place_above(struct wl_client *client, |
| 4241 | struct wl_resource *resource, |
| 4242 | struct wl_resource *sibling_resource) |
| 4243 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4244 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4245 | struct weston_surface *surface = |
| 4246 | wl_resource_get_user_data(sibling_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4247 | struct weston_subsurface *sibling; |
| 4248 | |
| 4249 | if (!sub) |
| 4250 | return; |
| 4251 | |
| 4252 | sibling = subsurface_sibling_check(sub, surface, "place_above"); |
| 4253 | if (!sibling) |
| 4254 | return; |
| 4255 | |
| 4256 | wl_list_remove(&sub->parent_link_pending); |
| 4257 | wl_list_insert(sibling->parent_link_pending.prev, |
| 4258 | &sub->parent_link_pending); |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 4259 | |
| 4260 | sub->reordered = true; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4261 | } |
| 4262 | |
| 4263 | static void |
| 4264 | subsurface_place_below(struct wl_client *client, |
| 4265 | struct wl_resource *resource, |
| 4266 | struct wl_resource *sibling_resource) |
| 4267 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4268 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4269 | struct weston_surface *surface = |
| 4270 | wl_resource_get_user_data(sibling_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4271 | struct weston_subsurface *sibling; |
| 4272 | |
| 4273 | if (!sub) |
| 4274 | return; |
| 4275 | |
| 4276 | sibling = subsurface_sibling_check(sub, surface, "place_below"); |
| 4277 | if (!sibling) |
| 4278 | return; |
| 4279 | |
| 4280 | wl_list_remove(&sub->parent_link_pending); |
| 4281 | wl_list_insert(&sibling->parent_link_pending, |
| 4282 | &sub->parent_link_pending); |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 4283 | |
| 4284 | sub->reordered = true; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4285 | } |
| 4286 | |
| 4287 | static void |
| 4288 | subsurface_set_sync(struct wl_client *client, struct wl_resource *resource) |
| 4289 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4290 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4291 | |
| 4292 | if (sub) |
| 4293 | sub->synchronized = 1; |
| 4294 | } |
| 4295 | |
| 4296 | static void |
| 4297 | subsurface_set_desync(struct wl_client *client, struct wl_resource *resource) |
| 4298 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4299 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4300 | |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 4301 | if (sub && sub->synchronized) { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4302 | sub->synchronized = 0; |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 4303 | |
| 4304 | /* If sub became effectively desynchronized, flush. */ |
| 4305 | if (!weston_subsurface_is_synchronized(sub)) |
| 4306 | weston_subsurface_synchronized_commit(sub); |
| 4307 | } |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4308 | } |
| 4309 | |
| 4310 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4311 | weston_subsurface_unlink_parent(struct weston_subsurface *sub) |
| 4312 | { |
| 4313 | wl_list_remove(&sub->parent_link); |
| 4314 | wl_list_remove(&sub->parent_link_pending); |
| 4315 | wl_list_remove(&sub->parent_destroy_listener.link); |
| 4316 | sub->parent = NULL; |
| 4317 | } |
| 4318 | |
| 4319 | static void |
| 4320 | weston_subsurface_destroy(struct weston_subsurface *sub); |
| 4321 | |
| 4322 | static void |
| 4323 | subsurface_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 4324 | { |
| 4325 | struct weston_subsurface *sub = |
| 4326 | container_of(listener, struct weston_subsurface, |
| 4327 | surface_destroy_listener); |
Pekka Paalanen | ca79076 | 2015-04-17 14:23:38 +0300 | [diff] [blame] | 4328 | assert(data == sub->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4329 | |
| 4330 | /* The protocol object (wl_resource) is left inert. */ |
| 4331 | if (sub->resource) |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4332 | wl_resource_set_user_data(sub->resource, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4333 | |
| 4334 | weston_subsurface_destroy(sub); |
| 4335 | } |
| 4336 | |
| 4337 | static void |
| 4338 | subsurface_handle_parent_destroy(struct wl_listener *listener, void *data) |
| 4339 | { |
| 4340 | struct weston_subsurface *sub = |
| 4341 | container_of(listener, struct weston_subsurface, |
| 4342 | parent_destroy_listener); |
Pekka Paalanen | ca79076 | 2015-04-17 14:23:38 +0300 | [diff] [blame] | 4343 | assert(data == sub->parent); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4344 | assert(sub->surface != sub->parent); |
| 4345 | |
| 4346 | if (weston_surface_is_mapped(sub->surface)) |
| 4347 | weston_surface_unmap(sub->surface); |
| 4348 | |
| 4349 | weston_subsurface_unlink_parent(sub); |
| 4350 | } |
| 4351 | |
| 4352 | static void |
| 4353 | subsurface_resource_destroy(struct wl_resource *resource) |
| 4354 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4355 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4356 | |
| 4357 | if (sub) |
| 4358 | weston_subsurface_destroy(sub); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4359 | } |
| 4360 | |
| 4361 | static void |
| 4362 | subsurface_destroy(struct wl_client *client, struct wl_resource *resource) |
| 4363 | { |
| 4364 | wl_resource_destroy(resource); |
| 4365 | } |
| 4366 | |
| 4367 | static void |
| 4368 | weston_subsurface_link_parent(struct weston_subsurface *sub, |
| 4369 | struct weston_surface *parent) |
| 4370 | { |
| 4371 | sub->parent = parent; |
| 4372 | sub->parent_destroy_listener.notify = subsurface_handle_parent_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4373 | wl_signal_add(&parent->destroy_signal, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4374 | &sub->parent_destroy_listener); |
| 4375 | |
| 4376 | wl_list_insert(&parent->subsurface_list, &sub->parent_link); |
| 4377 | wl_list_insert(&parent->subsurface_list_pending, |
| 4378 | &sub->parent_link_pending); |
| 4379 | } |
| 4380 | |
| 4381 | static void |
| 4382 | weston_subsurface_link_surface(struct weston_subsurface *sub, |
| 4383 | struct weston_surface *surface) |
| 4384 | { |
| 4385 | sub->surface = surface; |
| 4386 | sub->surface_destroy_listener.notify = |
| 4387 | subsurface_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4388 | wl_signal_add(&surface->destroy_signal, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4389 | &sub->surface_destroy_listener); |
| 4390 | } |
| 4391 | |
| 4392 | static void |
| 4393 | weston_subsurface_destroy(struct weston_subsurface *sub) |
| 4394 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4395 | struct weston_view *view, *next; |
| 4396 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4397 | assert(sub->surface); |
| 4398 | |
| 4399 | if (sub->resource) { |
| 4400 | assert(weston_surface_to_subsurface(sub->surface) == sub); |
| 4401 | assert(sub->parent_destroy_listener.notify == |
| 4402 | subsurface_handle_parent_destroy); |
| 4403 | |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 4404 | wl_list_for_each_safe(view, next, &sub->surface->views, surface_link) { |
| 4405 | weston_view_unmap(view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4406 | weston_view_destroy(view); |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 4407 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4408 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4409 | if (sub->parent) |
| 4410 | weston_subsurface_unlink_parent(sub); |
| 4411 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 4412 | weston_surface_state_fini(&sub->cached); |
| 4413 | weston_buffer_reference(&sub->cached_buffer_ref, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4414 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 4415 | sub->surface->committed = NULL; |
| 4416 | sub->surface->committed_private = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4417 | weston_surface_set_label_func(sub->surface, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4418 | } else { |
| 4419 | /* the dummy weston_subsurface for the parent itself */ |
| 4420 | assert(sub->parent_destroy_listener.notify == NULL); |
| 4421 | wl_list_remove(&sub->parent_link); |
| 4422 | wl_list_remove(&sub->parent_link_pending); |
| 4423 | } |
| 4424 | |
| 4425 | wl_list_remove(&sub->surface_destroy_listener.link); |
| 4426 | free(sub); |
| 4427 | } |
| 4428 | |
| 4429 | static const struct wl_subsurface_interface subsurface_implementation = { |
| 4430 | subsurface_destroy, |
| 4431 | subsurface_set_position, |
| 4432 | subsurface_place_above, |
| 4433 | subsurface_place_below, |
| 4434 | subsurface_set_sync, |
| 4435 | subsurface_set_desync |
| 4436 | }; |
| 4437 | |
| 4438 | static struct weston_subsurface * |
| 4439 | weston_subsurface_create(uint32_t id, struct weston_surface *surface, |
| 4440 | struct weston_surface *parent) |
| 4441 | { |
| 4442 | struct weston_subsurface *sub; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4443 | struct wl_client *client = wl_resource_get_client(surface->resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4444 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 4445 | sub = zalloc(sizeof *sub); |
| 4446 | if (sub == NULL) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4447 | return NULL; |
| 4448 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4449 | wl_list_init(&sub->unused_views); |
| 4450 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4451 | sub->resource = |
| 4452 | wl_resource_create(client, &wl_subsurface_interface, 1, id); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4453 | if (!sub->resource) { |
| 4454 | free(sub); |
| 4455 | return NULL; |
| 4456 | } |
| 4457 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4458 | wl_resource_set_implementation(sub->resource, |
| 4459 | &subsurface_implementation, |
| 4460 | sub, subsurface_resource_destroy); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4461 | weston_subsurface_link_surface(sub, surface); |
| 4462 | weston_subsurface_link_parent(sub, parent); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 4463 | weston_surface_state_init(&sub->cached); |
| 4464 | sub->cached_buffer_ref.buffer = NULL; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4465 | sub->synchronized = 1; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4466 | |
| 4467 | return sub; |
| 4468 | } |
| 4469 | |
| 4470 | /* Create a dummy subsurface for having the parent itself in its |
| 4471 | * sub-surface lists. Makes stacking order manipulation easy. |
| 4472 | */ |
| 4473 | static struct weston_subsurface * |
| 4474 | weston_subsurface_create_for_parent(struct weston_surface *parent) |
| 4475 | { |
| 4476 | struct weston_subsurface *sub; |
| 4477 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 4478 | sub = zalloc(sizeof *sub); |
| 4479 | if (sub == NULL) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4480 | return NULL; |
| 4481 | |
| 4482 | weston_subsurface_link_surface(sub, parent); |
| 4483 | sub->parent = parent; |
| 4484 | wl_list_insert(&parent->subsurface_list, &sub->parent_link); |
| 4485 | wl_list_insert(&parent->subsurface_list_pending, |
| 4486 | &sub->parent_link_pending); |
| 4487 | |
| 4488 | return sub; |
| 4489 | } |
| 4490 | |
| 4491 | static void |
| 4492 | subcompositor_get_subsurface(struct wl_client *client, |
| 4493 | struct wl_resource *resource, |
| 4494 | uint32_t id, |
| 4495 | struct wl_resource *surface_resource, |
| 4496 | struct wl_resource *parent_resource) |
| 4497 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4498 | struct weston_surface *surface = |
| 4499 | wl_resource_get_user_data(surface_resource); |
| 4500 | struct weston_surface *parent = |
| 4501 | wl_resource_get_user_data(parent_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4502 | struct weston_subsurface *sub; |
| 4503 | static const char where[] = "get_subsurface: wl_subsurface@"; |
| 4504 | |
| 4505 | if (surface == parent) { |
| 4506 | wl_resource_post_error(resource, |
| 4507 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 4508 | "%s%d: wl_surface@%d cannot be its own parent", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4509 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4510 | return; |
| 4511 | } |
| 4512 | |
| 4513 | if (weston_surface_to_subsurface(surface)) { |
| 4514 | wl_resource_post_error(resource, |
| 4515 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 4516 | "%s%d: wl_surface@%d is already a sub-surface", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4517 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4518 | return; |
| 4519 | } |
| 4520 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4521 | if (weston_surface_set_role(surface, "wl_subsurface", resource, |
| 4522 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE) < 0) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4523 | return; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4524 | |
Pekka Paalanen | 86c8ca0 | 2013-05-17 16:46:07 +0300 | [diff] [blame] | 4525 | if (weston_surface_get_main_surface(parent) == surface) { |
| 4526 | wl_resource_post_error(resource, |
| 4527 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 4528 | "%s%d: wl_surface@%d is an ancestor of parent", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4529 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | 86c8ca0 | 2013-05-17 16:46:07 +0300 | [diff] [blame] | 4530 | return; |
| 4531 | } |
| 4532 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4533 | /* make sure the parent is in its own list */ |
| 4534 | if (wl_list_empty(&parent->subsurface_list)) { |
| 4535 | if (!weston_subsurface_create_for_parent(parent)) { |
| 4536 | wl_resource_post_no_memory(resource); |
| 4537 | return; |
| 4538 | } |
| 4539 | } |
| 4540 | |
| 4541 | sub = weston_subsurface_create(id, surface, parent); |
| 4542 | if (!sub) { |
| 4543 | wl_resource_post_no_memory(resource); |
| 4544 | return; |
| 4545 | } |
| 4546 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 4547 | surface->committed = subsurface_committed; |
| 4548 | surface->committed_private = sub; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4549 | weston_surface_set_label_func(surface, subsurface_get_label); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4550 | } |
| 4551 | |
| 4552 | static void |
| 4553 | subcompositor_destroy(struct wl_client *client, struct wl_resource *resource) |
| 4554 | { |
| 4555 | wl_resource_destroy(resource); |
| 4556 | } |
| 4557 | |
| 4558 | static const struct wl_subcompositor_interface subcompositor_interface = { |
| 4559 | subcompositor_destroy, |
| 4560 | subcompositor_get_subsurface |
| 4561 | }; |
| 4562 | |
| 4563 | static void |
| 4564 | bind_subcompositor(struct wl_client *client, |
| 4565 | void *data, uint32_t version, uint32_t id) |
| 4566 | { |
| 4567 | struct weston_compositor *compositor = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4568 | struct wl_resource *resource; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4569 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4570 | resource = |
| 4571 | wl_resource_create(client, &wl_subcompositor_interface, 1, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 4572 | if (resource == NULL) { |
| 4573 | wl_client_post_no_memory(client); |
| 4574 | return; |
| 4575 | } |
| 4576 | wl_resource_set_implementation(resource, &subcompositor_interface, |
| 4577 | compositor, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4578 | } |
| 4579 | |
Bryce Harrington | 0795ece | 2016-08-30 12:04:26 -0700 | [diff] [blame] | 4580 | /** Set a DPMS mode on all of the compositor's outputs |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4581 | * |
| 4582 | * \param compositor The compositor instance |
| 4583 | * \param state The DPMS state the outputs will be set to |
| 4584 | */ |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4585 | static void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4586 | weston_compositor_dpms(struct weston_compositor *compositor, |
| 4587 | enum dpms_enum state) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4588 | { |
| 4589 | struct weston_output *output; |
| 4590 | |
Bryce Harrington | 08976ac | 2016-08-30 12:05:16 -0700 | [diff] [blame] | 4591 | wl_list_for_each(output, &compositor->output_list, link) |
| 4592 | if (output->set_dpms) |
| 4593 | output->set_dpms(output, state); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4594 | } |
| 4595 | |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4596 | /** Restores the compositor to active status |
| 4597 | * |
| 4598 | * \param compositor The compositor instance |
| 4599 | * |
| 4600 | * If the compositor was in a sleeping mode, all outputs are powered |
| 4601 | * back on via DPMS. Otherwise if the compositor was inactive |
| 4602 | * (idle/locked, offscreen, or sleeping) then the compositor's wake |
| 4603 | * signal will fire. |
| 4604 | * |
| 4605 | * Restarts the idle timer. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 4606 | * \ingroup compositor |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4607 | */ |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4608 | WL_EXPORT void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4609 | weston_compositor_wake(struct weston_compositor *compositor) |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4610 | { |
Neil Roberts | 8b62e20 | 2013-09-30 13:14:47 +0100 | [diff] [blame] | 4611 | uint32_t old_state = compositor->state; |
| 4612 | |
| 4613 | /* The state needs to be changed before emitting the wake |
| 4614 | * signal because that may try to schedule a repaint which |
| 4615 | * will not work if the compositor is still sleeping */ |
| 4616 | compositor->state = WESTON_COMPOSITOR_ACTIVE; |
| 4617 | |
| 4618 | switch (old_state) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4619 | case WESTON_COMPOSITOR_SLEEPING: |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4620 | case WESTON_COMPOSITOR_IDLE: |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4621 | case WESTON_COMPOSITOR_OFFSCREEN: |
Daniel Stone | 893b936 | 2016-11-08 15:47:09 +0000 | [diff] [blame] | 4622 | weston_compositor_dpms(compositor, WESTON_DPMS_ON); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4623 | wl_signal_emit(&compositor->wake_signal, compositor); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4624 | /* fall through */ |
| 4625 | default: |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4626 | wl_event_source_timer_update(compositor->idle_source, |
| 4627 | compositor->idle_time * 1000); |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4628 | } |
| 4629 | } |
| 4630 | |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4631 | /** Turns off rendering and frame events for the compositor. |
| 4632 | * |
| 4633 | * \param compositor The compositor instance |
| 4634 | * |
| 4635 | * This is used for example to prevent further rendering while the |
| 4636 | * compositor is shutting down. |
| 4637 | * |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4638 | * Stops the idle timer. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 4639 | * |
| 4640 | * \ingroup compositor |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4641 | */ |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4642 | WL_EXPORT void |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4643 | weston_compositor_offscreen(struct weston_compositor *compositor) |
| 4644 | { |
| 4645 | switch (compositor->state) { |
| 4646 | case WESTON_COMPOSITOR_OFFSCREEN: |
| 4647 | return; |
| 4648 | case WESTON_COMPOSITOR_SLEEPING: |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4649 | default: |
| 4650 | compositor->state = WESTON_COMPOSITOR_OFFSCREEN; |
| 4651 | wl_event_source_timer_update(compositor->idle_source, 0); |
| 4652 | } |
| 4653 | } |
| 4654 | |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4655 | /** Powers down all attached output devices |
| 4656 | * |
| 4657 | * \param compositor The compositor instance |
| 4658 | * |
| 4659 | * Causes rendering to the outputs to cease, and no frame events to be |
| 4660 | * sent. Only powers down the outputs if the compositor is not already |
| 4661 | * in sleep mode. |
| 4662 | * |
| 4663 | * Stops the idle timer. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 4664 | * |
| 4665 | * \ingroup compositor |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4666 | */ |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4667 | WL_EXPORT void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4668 | weston_compositor_sleep(struct weston_compositor *compositor) |
| 4669 | { |
| 4670 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING) |
| 4671 | return; |
| 4672 | |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4673 | wl_event_source_timer_update(compositor->idle_source, 0); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4674 | compositor->state = WESTON_COMPOSITOR_SLEEPING; |
| 4675 | weston_compositor_dpms(compositor, WESTON_DPMS_OFF); |
| 4676 | } |
| 4677 | |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4678 | /** Sets compositor to idle mode |
| 4679 | * |
| 4680 | * \param data The compositor instance |
| 4681 | * |
| 4682 | * This is called when the idle timer fires. Once the compositor is in |
| 4683 | * idle mode it requires a wake action (e.g. via |
| 4684 | * weston_compositor_wake()) to restore it. The compositor's |
| 4685 | * idle_signal will be triggered when the idle event occurs. |
| 4686 | * |
| 4687 | * Idleness can be inhibited by setting the compositor's idle_inhibit |
| 4688 | * property. |
| 4689 | */ |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 4690 | static int |
| 4691 | idle_handler(void *data) |
| 4692 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4693 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 4694 | |
| 4695 | if (compositor->idle_inhibit) |
| 4696 | return 1; |
| 4697 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4698 | compositor->state = WESTON_COMPOSITOR_IDLE; |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4699 | wl_signal_emit(&compositor->idle_signal, compositor); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 4700 | |
| 4701 | return 1; |
| 4702 | } |
| 4703 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4704 | WL_EXPORT void |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 4705 | weston_plane_init(struct weston_plane *plane, |
| 4706 | struct weston_compositor *ec, |
| 4707 | int32_t x, int32_t y) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4708 | { |
| 4709 | pixman_region32_init(&plane->damage); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 4710 | pixman_region32_init(&plane->clip); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4711 | plane->x = x; |
| 4712 | plane->y = y; |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 4713 | plane->compositor = ec; |
Ander Conselvan de Oliveira | 3c36bf3 | 2013-07-05 16:05:26 +0300 | [diff] [blame] | 4714 | |
| 4715 | /* Init the link so that the call to wl_list_remove() when releasing |
| 4716 | * the plane without ever stacking doesn't lead to a crash */ |
| 4717 | wl_list_init(&plane->link); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4718 | } |
| 4719 | |
| 4720 | WL_EXPORT void |
| 4721 | weston_plane_release(struct weston_plane *plane) |
| 4722 | { |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 4723 | struct weston_view *view; |
| 4724 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4725 | pixman_region32_fini(&plane->damage); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 4726 | pixman_region32_fini(&plane->clip); |
Ander Conselvan de Oliveira | 3c36bf3 | 2013-07-05 16:05:26 +0300 | [diff] [blame] | 4727 | |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 4728 | wl_list_for_each(view, &plane->compositor->view_list, link) { |
| 4729 | if (view->plane == plane) |
| 4730 | view->plane = NULL; |
| 4731 | } |
| 4732 | |
Ander Conselvan de Oliveira | 3c36bf3 | 2013-07-05 16:05:26 +0300 | [diff] [blame] | 4733 | wl_list_remove(&plane->link); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4734 | } |
| 4735 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 4736 | /** weston_compositor_stack_plane |
| 4737 | * \ingroup compositor |
| 4738 | */ |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 4739 | WL_EXPORT void |
| 4740 | weston_compositor_stack_plane(struct weston_compositor *ec, |
| 4741 | struct weston_plane *plane, |
| 4742 | struct weston_plane *above) |
| 4743 | { |
| 4744 | if (above) |
| 4745 | wl_list_insert(above->link.prev, &plane->link); |
| 4746 | else |
| 4747 | wl_list_insert(&ec->plane_list, &plane->link); |
| 4748 | } |
| 4749 | |
Quentin Glidic | 4ef719c | 2016-07-05 20:44:33 +0200 | [diff] [blame] | 4750 | static void |
| 4751 | output_release(struct wl_client *client, struct wl_resource *resource) |
| 4752 | { |
| 4753 | wl_resource_destroy(resource); |
| 4754 | } |
| 4755 | |
| 4756 | static const struct wl_output_interface output_interface = { |
| 4757 | output_release, |
| 4758 | }; |
| 4759 | |
| 4760 | |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 4761 | static void unbind_resource(struct wl_resource *resource) |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 4762 | { |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4763 | wl_list_remove(wl_resource_get_link(resource)); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 4764 | } |
| 4765 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4766 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4767 | bind_output(struct wl_client *client, |
| 4768 | void *data, uint32_t version, uint32_t id) |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 4769 | { |
Pekka Paalanen | 0534762 | 2017-03-27 12:24:34 +0300 | [diff] [blame] | 4770 | struct weston_head *head = data; |
| 4771 | struct weston_output *output = head->output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4772 | struct weston_mode *mode; |
Kristian Høgsberg | fd07fb7 | 2011-08-29 15:03:09 -0400 | [diff] [blame] | 4773 | struct wl_resource *resource; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 4774 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4775 | resource = wl_resource_create(client, &wl_output_interface, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 4776 | version, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 4777 | if (resource == NULL) { |
| 4778 | wl_client_post_no_memory(client); |
| 4779 | return; |
| 4780 | } |
Kristian Høgsberg | fd07fb7 | 2011-08-29 15:03:09 -0400 | [diff] [blame] | 4781 | |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 4782 | wl_list_insert(&head->resource_list, wl_resource_get_link(resource)); |
Pekka Paalanen | 055c113 | 2017-03-27 16:31:25 +0300 | [diff] [blame] | 4783 | wl_resource_set_implementation(resource, &output_interface, head, |
Pekka Paalanen | 0534762 | 2017-03-27 12:24:34 +0300 | [diff] [blame] | 4784 | unbind_resource); |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 4785 | |
Pekka Paalanen | 0534762 | 2017-03-27 12:24:34 +0300 | [diff] [blame] | 4786 | assert(output); |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4787 | wl_output_send_geometry(resource, |
| 4788 | output->x, |
| 4789 | output->y, |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 4790 | head->mm_width, |
| 4791 | head->mm_height, |
| 4792 | head->subpixel, |
| 4793 | head->make, head->model, |
Kristian Høgsberg | 05890dc | 2012-08-10 10:09:20 -0400 | [diff] [blame] | 4794 | output->transform); |
Jasper St. Pierre | 0013a29 | 2014-08-07 16:43:11 -0400 | [diff] [blame] | 4795 | if (version >= WL_OUTPUT_SCALE_SINCE_VERSION) |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 4796 | wl_output_send_scale(resource, |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 4797 | output->current_scale); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 4798 | |
| 4799 | wl_list_for_each (mode, &output->mode_list, link) { |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4800 | wl_output_send_mode(resource, |
| 4801 | mode->flags, |
| 4802 | mode->width, |
| 4803 | mode->height, |
| 4804 | mode->refresh); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 4805 | } |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 4806 | |
Jasper St. Pierre | 0013a29 | 2014-08-07 16:43:11 -0400 | [diff] [blame] | 4807 | if (version >= WL_OUTPUT_DONE_SINCE_VERSION) |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 4808 | wl_output_send_done(resource); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 4809 | } |
| 4810 | |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 4811 | static void |
| 4812 | weston_head_add_global(struct weston_head *head) |
| 4813 | { |
| 4814 | head->global = wl_global_create(head->compositor->wl_display, |
| 4815 | &wl_output_interface, 3, |
| 4816 | head, bind_output); |
| 4817 | } |
| 4818 | |
Pekka Paalanen | d9dcc6d | 2017-12-04 15:28:13 +0200 | [diff] [blame] | 4819 | /** Remove the global wl_output protocol object |
| 4820 | * |
| 4821 | * \param head The head whose global to remove. |
| 4822 | * |
| 4823 | * Also orphans the wl_resources for this head (wl_output). |
| 4824 | */ |
| 4825 | static void |
| 4826 | weston_head_remove_global(struct weston_head *head) |
| 4827 | { |
| 4828 | struct wl_resource *resource, *tmp; |
| 4829 | |
| 4830 | if (head->global) |
| 4831 | wl_global_destroy(head->global); |
| 4832 | head->global = NULL; |
| 4833 | |
| 4834 | wl_resource_for_each_safe(resource, tmp, &head->resource_list) { |
| 4835 | unbind_resource(resource); |
| 4836 | wl_resource_set_destructor(resource, NULL); |
| 4837 | wl_resource_set_user_data(resource, NULL); |
| 4838 | } |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 4839 | |
| 4840 | wl_resource_for_each(resource, &head->xdg_output_resource_list) { |
| 4841 | /* It's sufficient to unset the destructor, then the list elements |
| 4842 | * won't be accessed. |
| 4843 | */ |
| 4844 | wl_resource_set_destructor(resource, NULL); |
| 4845 | } |
| 4846 | wl_list_init(&head->xdg_output_resource_list); |
Pekka Paalanen | d9dcc6d | 2017-12-04 15:28:13 +0200 | [diff] [blame] | 4847 | } |
| 4848 | |
Pekka Paalanen | 9ffb250 | 2017-03-27 15:14:32 +0300 | [diff] [blame] | 4849 | /** Get the backing object of wl_output |
| 4850 | * |
| 4851 | * \param resource A wl_output protocol object. |
| 4852 | * \return The backing object (user data) of a wl_resource representing a |
| 4853 | * wl_output protocol object. |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 4854 | * |
| 4855 | * \ingroup head |
Pekka Paalanen | 9ffb250 | 2017-03-27 15:14:32 +0300 | [diff] [blame] | 4856 | */ |
Pekka Paalanen | 055c113 | 2017-03-27 16:31:25 +0300 | [diff] [blame] | 4857 | WL_EXPORT struct weston_head * |
| 4858 | weston_head_from_resource(struct wl_resource *resource) |
Pekka Paalanen | 9ffb250 | 2017-03-27 15:14:32 +0300 | [diff] [blame] | 4859 | { |
| 4860 | assert(wl_resource_instance_of(resource, &wl_output_interface, |
| 4861 | &output_interface)); |
| 4862 | |
| 4863 | return wl_resource_get_user_data(resource); |
| 4864 | } |
| 4865 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4866 | /** Initialize a pre-allocated weston_head |
| 4867 | * |
| 4868 | * \param head The head to initialize. |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 4869 | * \param name The head name, e.g. the connector name or equivalent. |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4870 | * |
| 4871 | * The head will be safe to attach, detach and release. |
| 4872 | * |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 4873 | * The name is used in logs, and can be used by compositors as a configuration |
| 4874 | * identifier. |
| 4875 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 4876 | * \ingroup head |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4877 | * \internal |
| 4878 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 4879 | WL_EXPORT void |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 4880 | weston_head_init(struct weston_head *head, const char *name) |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4881 | { |
| 4882 | /* Add some (in)sane defaults which can be used |
| 4883 | * for checking if an output was properly configured |
| 4884 | */ |
| 4885 | memset(head, 0, sizeof *head); |
| 4886 | |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 4887 | wl_list_init(&head->compositor_link); |
Pekka Paalanen | 2e1bedb | 2017-10-10 11:21:58 +0300 | [diff] [blame] | 4888 | wl_signal_init(&head->destroy_signal); |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4889 | wl_list_init(&head->output_link); |
| 4890 | wl_list_init(&head->resource_list); |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 4891 | wl_list_init(&head->xdg_output_resource_list); |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 4892 | head->name = strdup(name); |
Ankit Nautiyal | 4f64ff8 | 2019-04-03 18:44:35 +0530 | [diff] [blame] | 4893 | head->current_protection = WESTON_HDCP_DISABLE; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4894 | } |
| 4895 | |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 4896 | /** Send output heads changed signal |
| 4897 | * |
| 4898 | * \param output The output that changed. |
| 4899 | * |
| 4900 | * Notify that the enabled output gained and/or lost heads, or that the |
| 4901 | * associated heads may have changed their connection status. This does not |
| 4902 | * include cases where the output becomes enabled or disabled. The registered |
| 4903 | * callbacks are called after the change has successfully happened. |
| 4904 | * |
| 4905 | * If connection status change causes the compositor to attach or detach a head |
| 4906 | * to an enabled output, the registered callbacks may be called multiple times. |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 4907 | * |
| 4908 | * \ingroup output |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 4909 | */ |
| 4910 | static void |
| 4911 | weston_output_emit_heads_changed(struct weston_output *output) |
| 4912 | { |
| 4913 | wl_signal_emit(&output->compositor->output_heads_changed_signal, |
| 4914 | output); |
| 4915 | } |
| 4916 | |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4917 | /** Idle task for emitting heads_changed_signal */ |
| 4918 | static void |
| 4919 | weston_compositor_call_heads_changed(void *data) |
| 4920 | { |
| 4921 | struct weston_compositor *compositor = data; |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 4922 | struct weston_head *head; |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4923 | |
| 4924 | compositor->heads_changed_source = NULL; |
| 4925 | |
| 4926 | wl_signal_emit(&compositor->heads_changed_signal, compositor); |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 4927 | |
| 4928 | wl_list_for_each(head, &compositor->head_list, compositor_link) { |
| 4929 | if (head->output && head->output->enabled) |
| 4930 | weston_output_emit_heads_changed(head->output); |
| 4931 | } |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4932 | } |
| 4933 | |
| 4934 | /** Schedule a call on idle to heads_changed callback |
| 4935 | * |
| 4936 | * \param compositor The Compositor. |
| 4937 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 4938 | * \ingroup compositor |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4939 | * \internal |
| 4940 | */ |
| 4941 | static void |
| 4942 | weston_compositor_schedule_heads_changed(struct weston_compositor *compositor) |
| 4943 | { |
| 4944 | struct wl_event_loop *loop; |
| 4945 | |
| 4946 | if (compositor->heads_changed_source) |
| 4947 | return; |
| 4948 | |
| 4949 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 4950 | compositor->heads_changed_source = wl_event_loop_add_idle(loop, |
| 4951 | weston_compositor_call_heads_changed, compositor); |
| 4952 | } |
| 4953 | |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 4954 | /** Register a new head |
| 4955 | * |
| 4956 | * \param compositor The compositor. |
| 4957 | * \param head The head to register, must not be already registered. |
| 4958 | * |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4959 | * This signals the core that a new head has become available, leading to |
| 4960 | * heads_changed hook being called later. |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 4961 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 4962 | * \ingroup compositor |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 4963 | * \internal |
| 4964 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 4965 | WL_EXPORT void |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 4966 | weston_compositor_add_head(struct weston_compositor *compositor, |
| 4967 | struct weston_head *head) |
| 4968 | { |
| 4969 | assert(wl_list_empty(&head->compositor_link)); |
| 4970 | assert(head->name); |
| 4971 | |
| 4972 | wl_list_insert(compositor->head_list.prev, &head->compositor_link); |
| 4973 | head->compositor = compositor; |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4974 | weston_compositor_schedule_heads_changed(compositor); |
| 4975 | } |
| 4976 | |
| 4977 | /** Adds a listener to be called when heads change |
| 4978 | * |
| 4979 | * \param compositor The compositor. |
| 4980 | * \param listener The listener to add. |
| 4981 | * |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 4982 | * The listener notify function argument is weston_compositor. |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4983 | * |
| 4984 | * The listener function will be called after heads are added or their |
| 4985 | * connection status has changed. Several changes may be accumulated into a |
| 4986 | * single call. The user is expected to iterate over the existing heads and |
| 4987 | * check their statuses to find out what changed. |
| 4988 | * |
| 4989 | * \sa weston_compositor_iterate_heads, weston_head_is_connected, |
| 4990 | * weston_head_is_enabled |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 4991 | * \ingroup compositor |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4992 | */ |
| 4993 | WL_EXPORT void |
| 4994 | weston_compositor_add_heads_changed_listener(struct weston_compositor *compositor, |
| 4995 | struct wl_listener *listener) |
| 4996 | { |
| 4997 | wl_signal_add(&compositor->heads_changed_signal, listener); |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 4998 | } |
| 4999 | |
| 5000 | /** Iterate over available heads |
| 5001 | * |
| 5002 | * \param compositor The compositor. |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 5003 | * \param iter The iterator, or NULL for start. |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 5004 | * \return The next available head in the list. |
| 5005 | * |
| 5006 | * Returns all available heads, regardless of being connected or enabled. |
| 5007 | * |
| 5008 | * You can iterate over all heads as follows: |
| 5009 | * \code |
| 5010 | * struct weston_head *head = NULL; |
| 5011 | * |
| 5012 | * while ((head = weston_compositor_iterate_heads(compositor, head))) { |
| 5013 | * ... |
| 5014 | * } |
| 5015 | * \endcode |
| 5016 | * |
| 5017 | * If you cause \c iter to be removed from the list, you cannot use it to |
| 5018 | * continue iterating. Removing any other item is safe. |
| 5019 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 5020 | * \ingroup compositor |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 5021 | */ |
| 5022 | WL_EXPORT struct weston_head * |
| 5023 | weston_compositor_iterate_heads(struct weston_compositor *compositor, |
| 5024 | struct weston_head *iter) |
| 5025 | { |
| 5026 | struct wl_list *list = &compositor->head_list; |
| 5027 | struct wl_list *node; |
| 5028 | |
| 5029 | assert(compositor); |
| 5030 | assert(!iter || iter->compositor == compositor); |
| 5031 | |
| 5032 | if (iter) |
| 5033 | node = iter->compositor_link.next; |
| 5034 | else |
| 5035 | node = list->next; |
| 5036 | |
| 5037 | assert(node); |
| 5038 | assert(!iter || node != &iter->compositor_link); |
| 5039 | |
| 5040 | if (node == list) |
| 5041 | return NULL; |
| 5042 | |
| 5043 | return container_of(node, struct weston_head, compositor_link); |
| 5044 | } |
| 5045 | |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5046 | /** Iterate over attached heads |
| 5047 | * |
| 5048 | * \param output The output whose heads to iterate. |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 5049 | * \param iter The iterator, or NULL for start. |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5050 | * \return The next attached head in the list. |
| 5051 | * |
| 5052 | * Returns all heads currently attached to the output. |
| 5053 | * |
| 5054 | * You can iterate over all heads as follows: |
| 5055 | * \code |
| 5056 | * struct weston_head *head = NULL; |
| 5057 | * |
| 5058 | * while ((head = weston_output_iterate_heads(output, head))) { |
| 5059 | * ... |
| 5060 | * } |
| 5061 | * \endcode |
| 5062 | * |
| 5063 | * If you cause \c iter to be removed from the list, you cannot use it to |
| 5064 | * continue iterating. Removing any other item is safe. |
| 5065 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 5066 | * \ingroup ouput |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5067 | */ |
| 5068 | WL_EXPORT struct weston_head * |
| 5069 | weston_output_iterate_heads(struct weston_output *output, |
| 5070 | struct weston_head *iter) |
| 5071 | { |
| 5072 | struct wl_list *list = &output->head_list; |
| 5073 | struct wl_list *node; |
| 5074 | |
| 5075 | assert(output); |
| 5076 | assert(!iter || iter->output == output); |
| 5077 | |
| 5078 | if (iter) |
| 5079 | node = iter->output_link.next; |
| 5080 | else |
| 5081 | node = list->next; |
| 5082 | |
| 5083 | assert(node); |
| 5084 | assert(!iter || node != &iter->output_link); |
| 5085 | |
| 5086 | if (node == list) |
| 5087 | return NULL; |
| 5088 | |
| 5089 | return container_of(node, struct weston_head, output_link); |
| 5090 | } |
| 5091 | |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 5092 | /** Attach a head to an output |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5093 | * |
| 5094 | * \param output The output to attach to. |
| 5095 | * \param head The head that is not yet attached. |
| 5096 | * \return 0 on success, -1 on failure. |
| 5097 | * |
| 5098 | * Attaches the given head to the output. All heads of an output are clones |
| 5099 | * and share the resolution and timings. |
| 5100 | * |
| 5101 | * Cloning heads this way uses less resources than creating an output for |
| 5102 | * each head, but is not always possible due to environment, driver and hardware |
| 5103 | * limitations. |
| 5104 | * |
| 5105 | * On failure, the head remains unattached. Success of this function does not |
| 5106 | * guarantee the output configuration is actually valid. The final checks are |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 5107 | * made on weston_output_enable() unless the output was already enabled. |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5108 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 5109 | * \ingroup output |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5110 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5111 | WL_EXPORT int |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5112 | weston_output_attach_head(struct weston_output *output, |
| 5113 | struct weston_head *head) |
| 5114 | { |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 5115 | char *head_names; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5116 | |
| 5117 | if (!wl_list_empty(&head->output_link)) |
| 5118 | return -1; |
| 5119 | |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5120 | if (output->attach_head) { |
| 5121 | if (output->attach_head(output, head) < 0) |
| 5122 | return -1; |
| 5123 | } else if (!wl_list_empty(&output->head_list)) { |
| 5124 | /* No support for clones in the legacy path. */ |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5125 | return -1; |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5126 | } |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5127 | |
| 5128 | head->output = output; |
| 5129 | wl_list_insert(output->head_list.prev, &head->output_link); |
| 5130 | |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 5131 | if (output->enabled) { |
| 5132 | weston_head_add_global(head); |
| 5133 | |
| 5134 | head_names = weston_output_create_heads_string(output); |
| 5135 | weston_log("Output '%s' updated to have head(s) %s\n", |
| 5136 | output->name, head_names); |
| 5137 | free(head_names); |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 5138 | |
| 5139 | weston_output_emit_heads_changed(output); |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 5140 | } |
| 5141 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5142 | return 0; |
| 5143 | } |
| 5144 | |
| 5145 | /** Detach a head from its output |
| 5146 | * |
| 5147 | * \param head The head to detach. |
| 5148 | * |
| 5149 | * It is safe to detach a non-attached head. |
| 5150 | * |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5151 | * If the head is attached to an enabled output and the output will be left |
| 5152 | * with no heads, the output will be disabled. |
| 5153 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5154 | * \ingroup head |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5155 | * \sa weston_output_disable |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5156 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5157 | WL_EXPORT void |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5158 | weston_head_detach(struct weston_head *head) |
| 5159 | { |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5160 | struct weston_output *output = head->output; |
Pekka Paalanen | a010699 | 2017-12-08 16:11:17 +0200 | [diff] [blame] | 5161 | char *head_names; |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5162 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5163 | wl_list_remove(&head->output_link); |
| 5164 | wl_list_init(&head->output_link); |
| 5165 | head->output = NULL; |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5166 | |
| 5167 | if (!output) |
| 5168 | return; |
| 5169 | |
| 5170 | if (output->detach_head) |
| 5171 | output->detach_head(output, head); |
| 5172 | |
| 5173 | if (output->enabled) { |
| 5174 | weston_head_remove_global(head); |
| 5175 | |
Pekka Paalanen | a010699 | 2017-12-08 16:11:17 +0200 | [diff] [blame] | 5176 | if (wl_list_empty(&output->head_list)) { |
| 5177 | weston_log("Output '%s' no heads left, disabling.\n", |
| 5178 | output->name); |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5179 | weston_output_disable(output); |
Pekka Paalanen | a010699 | 2017-12-08 16:11:17 +0200 | [diff] [blame] | 5180 | } else { |
| 5181 | head_names = weston_output_create_heads_string(output); |
| 5182 | weston_log("Output '%s' updated to have head(s) %s\n", |
| 5183 | output->name, head_names); |
| 5184 | free(head_names); |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 5185 | |
| 5186 | weston_output_emit_heads_changed(output); |
Pekka Paalanen | a010699 | 2017-12-08 16:11:17 +0200 | [diff] [blame] | 5187 | } |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5188 | } |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5189 | } |
| 5190 | |
| 5191 | /** Destroy a head |
| 5192 | * |
| 5193 | * \param head The head to be released. |
| 5194 | * |
| 5195 | * Destroys the head. The caller is responsible for freeing the memory pointed |
| 5196 | * to by \c head. |
| 5197 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5198 | * \ingroup head |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5199 | * \internal |
| 5200 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5201 | WL_EXPORT void |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5202 | weston_head_release(struct weston_head *head) |
| 5203 | { |
Pekka Paalanen | 2e1bedb | 2017-10-10 11:21:58 +0300 | [diff] [blame] | 5204 | wl_signal_emit(&head->destroy_signal, head); |
| 5205 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5206 | weston_head_detach(head); |
Pekka Paalanen | 06f99ef | 2017-04-04 16:26:23 +0300 | [diff] [blame] | 5207 | |
| 5208 | free(head->make); |
| 5209 | free(head->model); |
| 5210 | free(head->serial_number); |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 5211 | free(head->name); |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 5212 | |
| 5213 | wl_list_remove(&head->compositor_link); |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5214 | } |
| 5215 | |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5216 | static void |
| 5217 | weston_head_set_device_changed(struct weston_head *head) |
| 5218 | { |
| 5219 | head->device_changed = true; |
| 5220 | |
| 5221 | if (head->compositor) |
| 5222 | weston_compositor_schedule_heads_changed(head->compositor); |
| 5223 | } |
| 5224 | |
| 5225 | /** String equal comparison with NULLs being equal */ |
| 5226 | static bool |
| 5227 | str_null_eq(const char *a, const char *b) |
| 5228 | { |
| 5229 | if (!a && !b) |
| 5230 | return true; |
| 5231 | |
| 5232 | if (!!a != !!b) |
| 5233 | return false; |
| 5234 | |
| 5235 | return strcmp(a, b) == 0; |
| 5236 | } |
| 5237 | |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5238 | /** Store monitor make, model and serial number |
| 5239 | * |
| 5240 | * \param head The head to modify. |
| 5241 | * \param make The monitor make. If EDID is available, the PNP ID. Otherwise |
| 5242 | * any string, or NULL for none. |
| 5243 | * \param model The monitor model or name, or a made-up string, or NULL for |
| 5244 | * none. |
| 5245 | * \param serialno The monitor serial number, a made-up string, or NULL for |
| 5246 | * none. |
| 5247 | * |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5248 | * This may set the device_changed flag. |
| 5249 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5250 | * \ingroup head |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5251 | * \internal |
| 5252 | */ |
| 5253 | WL_EXPORT void |
| 5254 | weston_head_set_monitor_strings(struct weston_head *head, |
| 5255 | const char *make, |
| 5256 | const char *model, |
| 5257 | const char *serialno) |
| 5258 | { |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5259 | if (str_null_eq(head->make, make) && |
| 5260 | str_null_eq(head->model, model) && |
| 5261 | str_null_eq(head->serial_number, serialno)) |
| 5262 | return; |
| 5263 | |
Pekka Paalanen | 06f99ef | 2017-04-04 16:26:23 +0300 | [diff] [blame] | 5264 | free(head->make); |
| 5265 | free(head->model); |
| 5266 | free(head->serial_number); |
| 5267 | |
| 5268 | head->make = make ? strdup(make) : NULL; |
| 5269 | head->model = model ? strdup(model) : NULL; |
| 5270 | head->serial_number = serialno ? strdup(serialno) : NULL; |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5271 | |
| 5272 | weston_head_set_device_changed(head); |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5273 | } |
| 5274 | |
Philipp Zabel | c18ffd3 | 2018-08-30 17:38:03 +0200 | [diff] [blame] | 5275 | /** Store display non-desktop status |
| 5276 | * |
| 5277 | * \param head The head to modify. |
| 5278 | * \param non_desktop Whether the head connects to a non-desktop display. |
| 5279 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5280 | * \ingroup head |
Philipp Zabel | c18ffd3 | 2018-08-30 17:38:03 +0200 | [diff] [blame] | 5281 | * \internal |
| 5282 | */ |
| 5283 | WL_EXPORT void |
| 5284 | weston_head_set_non_desktop(struct weston_head *head, bool non_desktop) |
| 5285 | { |
| 5286 | if (head->non_desktop == non_desktop) |
| 5287 | return; |
| 5288 | |
| 5289 | head->non_desktop = non_desktop; |
| 5290 | |
| 5291 | weston_head_set_device_changed(head); |
| 5292 | } |
| 5293 | |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5294 | /** Store physical image size |
| 5295 | * |
| 5296 | * \param head The head to modify. |
| 5297 | * \param mm_width Image area width in millimeters. |
| 5298 | * \param mm_height Image area height in millimeters. |
| 5299 | * |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5300 | * This may set the device_changed flag. |
| 5301 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5302 | * \ingroup head |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5303 | * \internal |
| 5304 | */ |
| 5305 | WL_EXPORT void |
| 5306 | weston_head_set_physical_size(struct weston_head *head, |
| 5307 | int32_t mm_width, int32_t mm_height) |
| 5308 | { |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5309 | if (head->mm_width == mm_width && |
| 5310 | head->mm_height == mm_height) |
| 5311 | return; |
| 5312 | |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5313 | head->mm_width = mm_width; |
| 5314 | head->mm_height = mm_height; |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5315 | |
| 5316 | weston_head_set_device_changed(head); |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5317 | } |
| 5318 | |
| 5319 | /** Store monitor sub-pixel layout |
| 5320 | * |
| 5321 | * \param head The head to modify. |
| 5322 | * \param sp Sub-pixel layout. The possible values are: |
| 5323 | * - WL_OUTPUT_SUBPIXEL_UNKNOWN, |
| 5324 | * - WL_OUTPUT_SUBPIXEL_NONE, |
| 5325 | * - WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB, |
| 5326 | * - WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR, |
| 5327 | * - WL_OUTPUT_SUBPIXEL_VERTICAL_RGB, |
| 5328 | * - WL_OUTPUT_SUBPIXEL_VERTICAL_BGR |
| 5329 | * |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5330 | * This may set the device_changed flag. |
| 5331 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5332 | * \ingroup head |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5333 | * \internal |
| 5334 | */ |
| 5335 | WL_EXPORT void |
| 5336 | weston_head_set_subpixel(struct weston_head *head, |
| 5337 | enum wl_output_subpixel sp) |
| 5338 | { |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5339 | if (head->subpixel == sp) |
| 5340 | return; |
| 5341 | |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5342 | head->subpixel = sp; |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5343 | |
| 5344 | weston_head_set_device_changed(head); |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5345 | } |
| 5346 | |
| 5347 | /** Mark the monitor as internal |
| 5348 | * |
| 5349 | * This is used for embedded screens, like laptop panels. |
| 5350 | * |
| 5351 | * \param head The head to mark as internal. |
| 5352 | * |
| 5353 | * By default a head is external. The type is often inferred from the physical |
| 5354 | * connector type. |
| 5355 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5356 | * \ingroup head |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5357 | * \internal |
| 5358 | */ |
| 5359 | WL_EXPORT void |
| 5360 | weston_head_set_internal(struct weston_head *head) |
| 5361 | { |
| 5362 | head->connection_internal = true; |
| 5363 | } |
Pekka Paalanen | 9ffb250 | 2017-03-27 15:14:32 +0300 | [diff] [blame] | 5364 | |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5365 | /** Store connector status |
| 5366 | * |
| 5367 | * \param head The head to modify. |
| 5368 | * \param connected Whether the head is connected. |
| 5369 | * |
| 5370 | * Connectors are created as disconnected. This function can be used to |
| 5371 | * set the connector status. |
| 5372 | * |
| 5373 | * The status should be set to true when a physical connector is connected to |
| 5374 | * a video sink device like a monitor and to false when the connector is |
| 5375 | * disconnected. For nested backends, the connection status should reflect the |
| 5376 | * connection to the parent display server. |
| 5377 | * |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5378 | * 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] | 5379 | * hook and sets the device_changed flag. |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5380 | * |
| 5381 | * \sa weston_compositor_set_heads_changed_cb |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5382 | * \ingroup head |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5383 | * \internal |
| 5384 | */ |
| 5385 | WL_EXPORT void |
| 5386 | weston_head_set_connection_status(struct weston_head *head, bool connected) |
| 5387 | { |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5388 | if (head->connected == connected) |
| 5389 | return; |
| 5390 | |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5391 | head->connected = connected; |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5392 | |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5393 | weston_head_set_device_changed(head); |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5394 | } |
| 5395 | |
Ankit Nautiyal | 4f64ff8 | 2019-04-03 18:44:35 +0530 | [diff] [blame] | 5396 | static void |
| 5397 | weston_output_compute_protection(struct weston_output *output) |
| 5398 | { |
| 5399 | struct weston_head *head; |
| 5400 | enum weston_hdcp_protection op_protection; |
| 5401 | bool op_protection_valid = false; |
Ankit Nautiyal | f74c35b | 2019-04-03 19:21:58 +0530 | [diff] [blame] | 5402 | struct weston_compositor *wc = output->compositor; |
| 5403 | struct content_protection *cp = wc->content_protection; |
| 5404 | |
| 5405 | if (!cp) |
| 5406 | return; |
Ankit Nautiyal | 4f64ff8 | 2019-04-03 18:44:35 +0530 | [diff] [blame] | 5407 | |
| 5408 | wl_list_for_each(head, &output->head_list, output_link) { |
| 5409 | if (!op_protection_valid) { |
| 5410 | op_protection = head->current_protection; |
| 5411 | op_protection_valid = true; |
| 5412 | } |
| 5413 | if (head->current_protection < op_protection) |
| 5414 | op_protection = head->current_protection; |
| 5415 | } |
| 5416 | |
| 5417 | if (!op_protection_valid) |
| 5418 | op_protection = WESTON_HDCP_DISABLE; |
| 5419 | |
Ankit Nautiyal | f74c35b | 2019-04-03 19:21:58 +0530 | [diff] [blame] | 5420 | if (output->current_protection != op_protection) { |
| 5421 | struct wl_event_loop *loop; |
| 5422 | |
Ankit Nautiyal | 4f64ff8 | 2019-04-03 18:44:35 +0530 | [diff] [blame] | 5423 | output->current_protection = op_protection; |
Ankit Nautiyal | f74c35b | 2019-04-03 19:21:58 +0530 | [diff] [blame] | 5424 | weston_output_damage(output); |
| 5425 | if (cp->surface_protection_update) |
| 5426 | return; |
| 5427 | loop = wl_display_get_event_loop(wc->wl_display); |
| 5428 | cp->surface_protection_update = wl_event_loop_add_idle(loop, |
| 5429 | notify_surface_protection_change, |
| 5430 | wc); |
| 5431 | } |
Ankit Nautiyal | 4f64ff8 | 2019-04-03 18:44:35 +0530 | [diff] [blame] | 5432 | } |
| 5433 | |
| 5434 | WL_EXPORT void |
| 5435 | weston_head_set_content_protection_status(struct weston_head *head, |
| 5436 | enum weston_hdcp_protection status) |
| 5437 | { |
| 5438 | head->current_protection = status; |
| 5439 | if (head->output) |
| 5440 | weston_output_compute_protection(head->output); |
| 5441 | } |
| 5442 | |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5443 | /** Is the head currently connected? |
| 5444 | * |
| 5445 | * \param head The head to query. |
| 5446 | * \return Connection status. |
| 5447 | * |
| 5448 | * Returns true if the head is physically connected to a monitor, or in |
| 5449 | * case of a nested backend returns true when there is a connection to the |
| 5450 | * parent display server. |
| 5451 | * |
| 5452 | * This is independent from the head being enabled. |
| 5453 | * |
| 5454 | * \sa weston_head_is_enabled |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5455 | * \ingroup head |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5456 | */ |
| 5457 | WL_EXPORT bool |
| 5458 | weston_head_is_connected(struct weston_head *head) |
| 5459 | { |
| 5460 | return head->connected; |
| 5461 | } |
| 5462 | |
Pekka Paalanen | 8e552fd | 2018-02-15 15:18:20 +0200 | [diff] [blame] | 5463 | /** Is the head currently enabled? |
| 5464 | * |
| 5465 | * \param head The head to query. |
| 5466 | * \return Video status. |
| 5467 | * |
| 5468 | * Returns true if the head is currently transmitting a video stream. |
| 5469 | * |
| 5470 | * This is independent of the head being connected. |
| 5471 | * |
| 5472 | * \sa weston_head_is_connected |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5473 | * \ingroup head |
Pekka Paalanen | 8e552fd | 2018-02-15 15:18:20 +0200 | [diff] [blame] | 5474 | */ |
| 5475 | WL_EXPORT bool |
| 5476 | weston_head_is_enabled(struct weston_head *head) |
| 5477 | { |
| 5478 | if (!head->output) |
| 5479 | return false; |
| 5480 | |
| 5481 | return head->output->enabled; |
| 5482 | } |
| 5483 | |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5484 | /** Has the device information changed? |
| 5485 | * |
| 5486 | * \param head The head to query. |
| 5487 | * \return True if the device information has changed since last reset. |
| 5488 | * |
| 5489 | * The information about the connected display device, e.g. a monitor, may |
| 5490 | * change without being disconnected in between. Changing information |
| 5491 | * causes a call to the heads_changed hook. |
| 5492 | * |
| 5493 | * The information includes make, model, serial number, physical size, |
| 5494 | * and sub-pixel type. The connection status is also included. |
| 5495 | * |
| 5496 | * \sa weston_head_reset_device_changed, weston_compositor_set_heads_changed_cb |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5497 | * \ingroup head |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5498 | */ |
| 5499 | WL_EXPORT bool |
| 5500 | weston_head_is_device_changed(struct weston_head *head) |
| 5501 | { |
| 5502 | return head->device_changed; |
| 5503 | } |
| 5504 | |
Philipp Zabel | c18ffd3 | 2018-08-30 17:38:03 +0200 | [diff] [blame] | 5505 | /** Does the head represent a non-desktop display? |
| 5506 | * |
| 5507 | * \param head The head to query. |
| 5508 | * \return True if the device is a non-desktop display. |
| 5509 | * |
| 5510 | * Non-desktop heads are not attached to outputs by default. |
| 5511 | * This stops weston from extending the desktop onto head mounted displays. |
| 5512 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5513 | * \ingroup head |
Philipp Zabel | c18ffd3 | 2018-08-30 17:38:03 +0200 | [diff] [blame] | 5514 | */ |
| 5515 | WL_EXPORT bool |
| 5516 | weston_head_is_non_desktop(struct weston_head *head) |
| 5517 | { |
| 5518 | return head->non_desktop; |
| 5519 | } |
| 5520 | |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5521 | /** Acknowledge device information change |
| 5522 | * |
| 5523 | * \param head The head to acknowledge. |
| 5524 | * |
| 5525 | * Clears the device changed flag on this head. When a compositor has processed |
| 5526 | * device information, it should call this to be able to notice further |
| 5527 | * changes. |
| 5528 | * |
| 5529 | * \sa weston_head_is_device_changed |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5530 | * \ingroup head |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5531 | */ |
| 5532 | WL_EXPORT void |
| 5533 | weston_head_reset_device_changed(struct weston_head *head) |
| 5534 | { |
| 5535 | head->device_changed = false; |
| 5536 | } |
| 5537 | |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5538 | /** Get the name of a head |
| 5539 | * |
| 5540 | * \param head The head to query. |
| 5541 | * \return The head's name, not NULL. |
| 5542 | * |
| 5543 | * The name depends on the backend. The DRM backend uses connector names, |
| 5544 | * other backends may use hardcoded names or user-given names. |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5545 | * |
| 5546 | * \ingroup head |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5547 | */ |
| 5548 | WL_EXPORT const char * |
| 5549 | weston_head_get_name(struct weston_head *head) |
| 5550 | { |
| 5551 | return head->name; |
| 5552 | } |
| 5553 | |
| 5554 | /** Get the output the head is attached to |
| 5555 | * |
| 5556 | * \param head The head to query. |
| 5557 | * \return The output the head is attached to, or NULL if detached. |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5558 | * \ingroup head |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5559 | */ |
| 5560 | WL_EXPORT struct weston_output * |
| 5561 | weston_head_get_output(struct weston_head *head) |
| 5562 | { |
| 5563 | return head->output; |
| 5564 | } |
| 5565 | |
Pekka Paalanen | 2e1bedb | 2017-10-10 11:21:58 +0300 | [diff] [blame] | 5566 | /** Add destroy callback for a head |
| 5567 | * |
| 5568 | * \param head The head to watch for. |
| 5569 | * \param listener The listener to add. The \c notify member must be set. |
| 5570 | * |
| 5571 | * Heads may get destroyed for various reasons by the backends. If a head is |
| 5572 | * attached to an output, the compositor should listen for head destruction |
| 5573 | * and reconfigure or destroy the output if necessary. |
| 5574 | * |
| 5575 | * The destroy callbacks will be called on weston_head destruction before any |
| 5576 | * automatic detaching from an associated weston_output and before any |
| 5577 | * weston_head information is lost. |
| 5578 | * |
| 5579 | * The \c data argument to the notify callback is the weston_head being |
| 5580 | * destroyed. |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5581 | * |
| 5582 | * \ingroup head |
Pekka Paalanen | 2e1bedb | 2017-10-10 11:21:58 +0300 | [diff] [blame] | 5583 | */ |
| 5584 | WL_EXPORT void |
| 5585 | weston_head_add_destroy_listener(struct weston_head *head, |
| 5586 | struct wl_listener *listener) |
| 5587 | { |
| 5588 | wl_signal_add(&head->destroy_signal, listener); |
| 5589 | } |
| 5590 | |
| 5591 | /** Look up destroy listener for a head |
| 5592 | * |
| 5593 | * \param head The head to query. |
| 5594 | * \param notify The notify function used used for the added destroy listener. |
| 5595 | * \return The listener, or NULL if not found. |
| 5596 | * |
| 5597 | * This looks up the previously added destroy listener struct based on the |
| 5598 | * notify function it has. The listener can be used to access user data |
| 5599 | * through \c container_of(). |
| 5600 | * |
| 5601 | * \sa wl_signal_get() |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5602 | * \ingroup head |
Pekka Paalanen | 2e1bedb | 2017-10-10 11:21:58 +0300 | [diff] [blame] | 5603 | */ |
| 5604 | WL_EXPORT struct wl_listener * |
| 5605 | weston_head_get_destroy_listener(struct weston_head *head, |
| 5606 | wl_notify_func_t notify) |
| 5607 | { |
| 5608 | return wl_signal_get(&head->destroy_signal, notify); |
| 5609 | } |
| 5610 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 5611 | /* 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] | 5612 | static void |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 5613 | weston_compositor_reflow_outputs(struct weston_compositor *compositor, |
| 5614 | struct weston_output *resized_output, int delta_width) |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 5615 | { |
| 5616 | struct weston_output *output; |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 5617 | bool start_resizing = false; |
| 5618 | |
| 5619 | if (!delta_width) |
| 5620 | return; |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 5621 | |
| 5622 | wl_list_for_each(output, &compositor->output_list, link) { |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 5623 | if (output == resized_output) { |
| 5624 | start_resizing = true; |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 5625 | continue; |
| 5626 | } |
| 5627 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 5628 | if (start_resizing) { |
| 5629 | weston_output_move(output, output->x + delta_width, output->y); |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 5630 | output->dirty = 1; |
| 5631 | } |
| 5632 | } |
| 5633 | } |
| 5634 | |
Pekka Paalanen | d72bad2 | 2017-03-29 17:01:41 +0300 | [diff] [blame] | 5635 | static void |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5636 | weston_output_update_matrix(struct weston_output *output) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 5637 | { |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 5638 | float magnification; |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 5639 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5640 | weston_matrix_init(&output->matrix); |
Jason Ekstrand | fb23df7 | 2014-10-16 10:55:21 -0500 | [diff] [blame] | 5641 | weston_matrix_translate(&output->matrix, -output->x, -output->y, 0); |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 5642 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5643 | if (output->zoom.active) { |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 5644 | magnification = 1 / (1 - output->zoom.spring_z.current); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5645 | weston_output_update_zoom(output); |
Neil Roberts | 1e40a7e | 2014-04-25 13:19:37 +0100 | [diff] [blame] | 5646 | weston_matrix_translate(&output->matrix, -output->zoom.trans_x, |
Jason Ekstrand | fb23df7 | 2014-10-16 10:55:21 -0500 | [diff] [blame] | 5647 | -output->zoom.trans_y, 0); |
Neil Roberts | 1e40a7e | 2014-04-25 13:19:37 +0100 | [diff] [blame] | 5648 | weston_matrix_scale(&output->matrix, magnification, |
| 5649 | magnification, 1.0); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5650 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 5651 | |
Jason Ekstrand | fb23df7 | 2014-10-16 10:55:21 -0500 | [diff] [blame] | 5652 | switch (output->transform) { |
| 5653 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 5654 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 5655 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 5656 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 5657 | weston_matrix_translate(&output->matrix, -output->width, 0, 0); |
| 5658 | weston_matrix_scale(&output->matrix, -1, 1, 1); |
| 5659 | break; |
| 5660 | } |
| 5661 | |
| 5662 | switch (output->transform) { |
| 5663 | default: |
| 5664 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 5665 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 5666 | break; |
| 5667 | case WL_OUTPUT_TRANSFORM_90: |
| 5668 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 5669 | weston_matrix_translate(&output->matrix, 0, -output->height, 0); |
| 5670 | weston_matrix_rotate_xy(&output->matrix, 0, 1); |
| 5671 | break; |
| 5672 | case WL_OUTPUT_TRANSFORM_180: |
| 5673 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 5674 | weston_matrix_translate(&output->matrix, |
| 5675 | -output->width, -output->height, 0); |
| 5676 | weston_matrix_rotate_xy(&output->matrix, -1, 0); |
| 5677 | break; |
| 5678 | case WL_OUTPUT_TRANSFORM_270: |
| 5679 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 5680 | weston_matrix_translate(&output->matrix, -output->width, 0, 0); |
| 5681 | weston_matrix_rotate_xy(&output->matrix, 0, -1); |
| 5682 | break; |
| 5683 | } |
| 5684 | |
| 5685 | if (output->current_scale != 1) |
| 5686 | weston_matrix_scale(&output->matrix, |
| 5687 | output->current_scale, |
| 5688 | output->current_scale, 1); |
Neil Roberts | 6c3b01f | 2014-05-06 19:04:15 +0100 | [diff] [blame] | 5689 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5690 | output->dirty = 0; |
Derek Foreman | c002321 | 2015-03-24 11:36:13 -0500 | [diff] [blame] | 5691 | |
| 5692 | weston_matrix_invert(&output->inverse_matrix, &output->matrix); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5693 | } |
| 5694 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 5695 | static void |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 5696 | 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] | 5697 | { |
| 5698 | output->transform = transform; |
Pekka Paalanen | 59987fa | 2016-04-26 15:50:59 +0300 | [diff] [blame] | 5699 | output->native_scale = scale; |
| 5700 | output->current_scale = scale; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 5701 | |
Pekka Paalanen | 59987fa | 2016-04-26 15:50:59 +0300 | [diff] [blame] | 5702 | convert_size_by_transform_scale(&output->width, &output->height, |
| 5703 | output->current_mode->width, |
| 5704 | output->current_mode->height, |
| 5705 | transform, scale); |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 5706 | } |
| 5707 | |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5708 | static void |
| 5709 | weston_output_init_geometry(struct weston_output *output, int x, int y) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5710 | { |
| 5711 | output->x = x; |
| 5712 | output->y = y; |
| 5713 | |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 5714 | pixman_region32_fini(&output->previous_damage); |
Ander Conselvan de Oliveira | b8fcca9 | 2012-11-16 17:23:52 +0200 | [diff] [blame] | 5715 | pixman_region32_init(&output->previous_damage); |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 5716 | |
| 5717 | pixman_region32_fini(&output->region); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5718 | pixman_region32_init_rect(&output->region, x, y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 5719 | output->width, |
| 5720 | output->height); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 5721 | } |
| 5722 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 5723 | /** |
| 5724 | * \ingroup output |
| 5725 | */ |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5726 | WL_EXPORT void |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5727 | weston_output_move(struct weston_output *output, int x, int y) |
| 5728 | { |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5729 | struct weston_head *head; |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5730 | struct wl_resource *resource; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5731 | int ver; |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5732 | |
| 5733 | output->move_x = x - output->x; |
| 5734 | output->move_y = y - output->y; |
| 5735 | |
| 5736 | if (output->move_x == 0 && output->move_y == 0) |
| 5737 | return; |
| 5738 | |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5739 | weston_output_init_geometry(output, x, y); |
| 5740 | |
| 5741 | output->dirty = 1; |
| 5742 | |
| 5743 | /* Move views on this output. */ |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 5744 | wl_signal_emit(&output->compositor->output_moved_signal, output); |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5745 | |
| 5746 | /* Notify clients of the change for output position. */ |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5747 | wl_list_for_each(head, &output->head_list, output_link) { |
| 5748 | wl_resource_for_each(resource, &head->resource_list) { |
| 5749 | wl_output_send_geometry(resource, |
| 5750 | output->x, |
| 5751 | output->y, |
| 5752 | head->mm_width, |
| 5753 | head->mm_height, |
| 5754 | head->subpixel, |
| 5755 | head->make, |
| 5756 | head->model, |
| 5757 | output->transform); |
Quanxian Wang | b2c8636 | 2014-03-14 09:16:25 +0800 | [diff] [blame] | 5758 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5759 | ver = wl_resource_get_version(resource); |
| 5760 | if (ver >= WL_OUTPUT_DONE_SINCE_VERSION) |
| 5761 | wl_output_send_done(resource); |
| 5762 | } |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 5763 | |
| 5764 | wl_resource_for_each(resource, &head->xdg_output_resource_list) { |
| 5765 | zxdg_output_v1_send_logical_position(resource, |
| 5766 | output->x, |
| 5767 | output->y); |
| 5768 | zxdg_output_v1_send_done(resource); |
| 5769 | } |
Quanxian Wang | b2c8636 | 2014-03-14 09:16:25 +0800 | [diff] [blame] | 5770 | } |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5771 | } |
| 5772 | |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5773 | /** Signal that a pending output is taken into use. |
| 5774 | * |
| 5775 | * Removes the output from the pending list and adds it to the compositor's |
| 5776 | * list of enabled outputs. The output created signal is emitted. |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5777 | * |
Pekka Paalanen | 2210ad0 | 2017-03-30 15:48:06 +0300 | [diff] [blame] | 5778 | * The output gets an internal ID assigned, and the wl_output global is |
| 5779 | * created. |
Pekka Paalanen | 3d2d497 | 2017-03-30 15:19:45 +0300 | [diff] [blame] | 5780 | * |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5781 | * \param compositor The compositor instance. |
| 5782 | * \param output The output to be added. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5783 | * |
| 5784 | * \internal |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 5785 | * \ingroup compositor |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5786 | */ |
Pekka Paalanen | f9681b5 | 2017-03-29 16:58:48 +0300 | [diff] [blame] | 5787 | static void |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5788 | weston_compositor_add_output(struct weston_compositor *compositor, |
| 5789 | struct weston_output *output) |
| 5790 | { |
Armin Krezović | e540384 | 2016-08-05 15:28:29 +0200 | [diff] [blame] | 5791 | struct weston_view *view, *next; |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 5792 | struct weston_head *head; |
Armin Krezović | e540384 | 2016-08-05 15:28:29 +0200 | [diff] [blame] | 5793 | |
Pekka Paalanen | 7f340ff | 2017-03-30 14:56:22 +0300 | [diff] [blame] | 5794 | assert(!output->enabled); |
Pekka Paalanen | 3d2d497 | 2017-03-30 15:19:45 +0300 | [diff] [blame] | 5795 | |
| 5796 | /* Verify we haven't reached the limit of 32 available output IDs */ |
| 5797 | assert(ffs(~compositor->output_id_pool) > 0); |
| 5798 | |
| 5799 | /* Invert the output id pool and look for the lowest numbered |
| 5800 | * switch (the least significant bit). Take that bit's position |
| 5801 | * as our ID, and mark it used in the compositor's output_id_pool. |
| 5802 | */ |
| 5803 | output->id = ffs(~compositor->output_id_pool) - 1; |
| 5804 | compositor->output_id_pool |= 1u << output->id; |
| 5805 | |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5806 | wl_list_remove(&output->link); |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5807 | wl_list_insert(compositor->output_list.prev, &output->link); |
Pekka Paalanen | 7f340ff | 2017-03-30 14:56:22 +0300 | [diff] [blame] | 5808 | output->enabled = true; |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5809 | |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 5810 | wl_list_for_each(head, &output->head_list, output_link) |
| 5811 | weston_head_add_global(head); |
Pekka Paalanen | 2210ad0 | 2017-03-30 15:48:06 +0300 | [diff] [blame] | 5812 | |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5813 | wl_signal_emit(&compositor->output_created_signal, output); |
Armin Krezović | e540384 | 2016-08-05 15:28:29 +0200 | [diff] [blame] | 5814 | |
| 5815 | wl_list_for_each_safe(view, next, &compositor->view_list, link) |
| 5816 | weston_view_geometry_dirty(view); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 5817 | } |
| 5818 | |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5819 | /** Transform device coordinates into global coordinates |
| 5820 | * |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 5821 | * \param output the weston_output object |
| 5822 | * \param[in] device_x X coordinate in device units. |
| 5823 | * \param[in] device_y Y coordinate in device units. |
| 5824 | * \param[out] x X coordinate in the global space. |
| 5825 | * \param[out] y Y coordinate in the global space. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5826 | * |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 5827 | * Transforms coordinates from the device coordinate space (physical pixel |
| 5828 | * units) to the global coordinate space (logical pixel units). This takes |
| 5829 | * into account output transform and scale. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5830 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 5831 | * \ingroup output |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5832 | * \internal |
| 5833 | */ |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 5834 | WL_EXPORT void |
| 5835 | weston_output_transform_coordinate(struct weston_output *output, |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 5836 | double device_x, double device_y, |
| 5837 | double *x, double *y) |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 5838 | { |
Derek Foreman | 0f67941 | 2014-10-02 13:41:17 -0500 | [diff] [blame] | 5839 | struct weston_vector p = { { |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 5840 | device_x, |
| 5841 | device_y, |
Derek Foreman | 0f67941 | 2014-10-02 13:41:17 -0500 | [diff] [blame] | 5842 | 0.0, |
| 5843 | 1.0 } }; |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 5844 | |
Derek Foreman | 67a18b9 | 2015-03-24 11:36:14 -0500 | [diff] [blame] | 5845 | weston_matrix_transform(&output->inverse_matrix, &p); |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 5846 | |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 5847 | *x = p.f[0] / p.f[3]; |
| 5848 | *y = p.f[1] / p.f[3]; |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 5849 | } |
| 5850 | |
Pekka Paalanen | e6ac4fc | 2017-03-29 16:07:34 +0300 | [diff] [blame] | 5851 | /** Removes output from compositor's list of enabled outputs |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5852 | * |
| 5853 | * \param output The weston_output object that is being removed. |
| 5854 | * |
Pekka Paalanen | e6ac4fc | 2017-03-29 16:07:34 +0300 | [diff] [blame] | 5855 | * The following happens: |
| 5856 | * |
| 5857 | * - The output assignments of all views in the current scenegraph are |
| 5858 | * recomputed. |
| 5859 | * |
| 5860 | * - Presentation feedback is discarded. |
| 5861 | * |
| 5862 | * - Compositor is notified that outputs were changed and |
| 5863 | * applies the necessary changes to re-layout outputs. |
| 5864 | * |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5865 | * - The output is put back in the pending outputs list. |
| 5866 | * |
Pekka Paalanen | e6ac4fc | 2017-03-29 16:07:34 +0300 | [diff] [blame] | 5867 | * - Signal is emitted to notify all users of the weston_output |
| 5868 | * object that the output is being destroyed. |
| 5869 | * |
| 5870 | * - wl_output protocol objects referencing this weston_output |
Pekka Paalanen | 2210ad0 | 2017-03-30 15:48:06 +0300 | [diff] [blame] | 5871 | * are made inert, and the wl_output global is removed. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5872 | * |
Pekka Paalanen | 3d2d497 | 2017-03-30 15:19:45 +0300 | [diff] [blame] | 5873 | * - The output's internal ID is released. |
| 5874 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 5875 | * \ingroup compositor |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5876 | * \internal |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5877 | */ |
| 5878 | static void |
| 5879 | weston_compositor_remove_output(struct weston_output *output) |
| 5880 | { |
Pekka Paalanen | bccda71 | 2017-03-29 16:16:04 +0300 | [diff] [blame] | 5881 | struct weston_compositor *compositor = output->compositor; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5882 | struct weston_view *view; |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 5883 | struct weston_head *head; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5884 | |
| 5885 | assert(output->destroying); |
Pekka Paalanen | 7f340ff | 2017-03-30 14:56:22 +0300 | [diff] [blame] | 5886 | assert(output->enabled); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5887 | |
Pekka Paalanen | bccda71 | 2017-03-29 16:16:04 +0300 | [diff] [blame] | 5888 | wl_list_for_each(view, &compositor->view_list, link) { |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5889 | if (view->output_mask & (1u << output->id)) |
| 5890 | weston_view_assign_output(view); |
| 5891 | } |
| 5892 | |
| 5893 | weston_presentation_feedback_discard_list(&output->feedback_list); |
| 5894 | |
Pekka Paalanen | 9711fd9 | 2018-06-21 14:26:18 +0300 | [diff] [blame] | 5895 | weston_compositor_reflow_outputs(compositor, output, -output->width); |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5896 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5897 | wl_list_remove(&output->link); |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5898 | wl_list_insert(compositor->pending_output_list.prev, &output->link); |
Pekka Paalanen | 7f340ff | 2017-03-30 14:56:22 +0300 | [diff] [blame] | 5899 | output->enabled = false; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5900 | |
Pekka Paalanen | bccda71 | 2017-03-29 16:16:04 +0300 | [diff] [blame] | 5901 | wl_signal_emit(&compositor->output_destroyed_signal, output); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5902 | wl_signal_emit(&output->destroy_signal, output); |
| 5903 | |
Pekka Paalanen | d9dcc6d | 2017-12-04 15:28:13 +0200 | [diff] [blame] | 5904 | wl_list_for_each(head, &output->head_list, output_link) |
| 5905 | weston_head_remove_global(head); |
Pekka Paalanen | 3d2d497 | 2017-03-30 15:19:45 +0300 | [diff] [blame] | 5906 | |
| 5907 | compositor->output_id_pool &= ~(1u << output->id); |
| 5908 | output->id = 0xffffffff; /* invalid */ |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5909 | } |
| 5910 | |
| 5911 | /** Sets the output scale for a given output. |
| 5912 | * |
| 5913 | * \param output The weston_output object that the scale is set for. |
| 5914 | * \param scale Scale factor for the given output. |
| 5915 | * |
| 5916 | * It only supports setting scale for an output that |
| 5917 | * is not enabled and it can only be ran once. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5918 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 5919 | * \ingroup ouput |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5920 | */ |
| 5921 | WL_EXPORT void |
| 5922 | weston_output_set_scale(struct weston_output *output, |
| 5923 | int32_t scale) |
| 5924 | { |
| 5925 | /* We can only set scale on a disabled output */ |
| 5926 | assert(!output->enabled); |
| 5927 | |
| 5928 | /* We only want to set scale once */ |
| 5929 | assert(!output->scale); |
| 5930 | |
| 5931 | output->scale = scale; |
| 5932 | } |
| 5933 | |
| 5934 | /** Sets the output transform for a given output. |
| 5935 | * |
| 5936 | * \param output The weston_output object that the transform is set for. |
| 5937 | * \param transform Transform value for the given output. |
| 5938 | * |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5939 | * Refer to wl_output::transform section located at |
| 5940 | * https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_output |
| 5941 | * for list of values that can be passed to this function. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5942 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 5943 | * \ingroup output |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5944 | */ |
| 5945 | WL_EXPORT void |
| 5946 | weston_output_set_transform(struct weston_output *output, |
| 5947 | uint32_t transform) |
| 5948 | { |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 5949 | struct weston_pointer_motion_event ev; |
| 5950 | struct wl_resource *resource; |
| 5951 | struct weston_seat *seat; |
| 5952 | pixman_region32_t old_region; |
| 5953 | int mid_x, mid_y; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5954 | struct weston_head *head; |
| 5955 | int ver; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5956 | |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 5957 | if (!output->enabled && output->transform == UINT32_MAX) { |
| 5958 | output->transform = transform; |
| 5959 | return; |
| 5960 | } |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5961 | |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 5962 | weston_output_transform_scale_init(output, transform, output->scale); |
| 5963 | |
| 5964 | pixman_region32_init(&old_region); |
| 5965 | pixman_region32_copy(&old_region, &output->region); |
| 5966 | |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 5967 | weston_output_init_geometry(output, output->x, output->y); |
| 5968 | |
| 5969 | output->dirty = 1; |
| 5970 | |
| 5971 | /* Notify clients of the change for output transform. */ |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5972 | wl_list_for_each(head, &output->head_list, output_link) { |
| 5973 | wl_resource_for_each(resource, &head->resource_list) { |
| 5974 | wl_output_send_geometry(resource, |
| 5975 | output->x, |
| 5976 | output->y, |
| 5977 | head->mm_width, |
| 5978 | head->mm_height, |
| 5979 | head->subpixel, |
| 5980 | head->make, |
| 5981 | head->model, |
| 5982 | output->transform); |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 5983 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5984 | ver = wl_resource_get_version(resource); |
| 5985 | if (ver >= WL_OUTPUT_DONE_SINCE_VERSION) |
| 5986 | wl_output_send_done(resource); |
| 5987 | } |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 5988 | wl_resource_for_each(resource, &head->xdg_output_resource_list) { |
| 5989 | zxdg_output_v1_send_logical_position(resource, |
| 5990 | output->x, |
| 5991 | output->y); |
| 5992 | zxdg_output_v1_send_logical_size(resource, |
| 5993 | output->width, |
| 5994 | output->height); |
| 5995 | zxdg_output_v1_send_done(resource); |
| 5996 | } |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 5997 | } |
| 5998 | |
| 5999 | /* we must ensure that pointers are inside output, otherwise they disappear */ |
| 6000 | mid_x = output->x + output->width / 2; |
| 6001 | mid_y = output->y + output->height / 2; |
| 6002 | |
| 6003 | ev.mask = WESTON_POINTER_MOTION_ABS; |
| 6004 | ev.x = wl_fixed_to_double(wl_fixed_from_int(mid_x)); |
| 6005 | ev.y = wl_fixed_to_double(wl_fixed_from_int(mid_y)); |
| 6006 | |
| 6007 | wl_list_for_each(seat, &output->compositor->seat_list, link) { |
| 6008 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 6009 | |
| 6010 | if (pointer && pixman_region32_contains_point(&old_region, |
| 6011 | wl_fixed_to_int(pointer->x), |
| 6012 | wl_fixed_to_int(pointer->y), |
| 6013 | NULL)) |
| 6014 | weston_pointer_move(pointer, &ev); |
| 6015 | } |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6016 | } |
| 6017 | |
| 6018 | /** Initializes a weston_output object with enough data so |
| 6019 | ** an output can be configured. |
| 6020 | * |
| 6021 | * \param output The weston_output object to initialize |
| 6022 | * \param compositor The compositor instance. |
Pekka Paalanen | 26ac2e1 | 2017-04-03 13:18:13 +0300 | [diff] [blame] | 6023 | * \param name Name for the output (the string is copied). |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6024 | * |
| 6025 | * Sets initial values for fields that are expected to be |
| 6026 | * configured either by compositors or backends. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6027 | * |
Pekka Paalanen | 26ac2e1 | 2017-04-03 13:18:13 +0300 | [diff] [blame] | 6028 | * The name is used in logs, and can be used by compositors as a configuration |
| 6029 | * identifier. |
| 6030 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6031 | * \ingroup output |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6032 | * \internal |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6033 | */ |
| 6034 | WL_EXPORT void |
Armin Krezović | 4008740 | 2016-09-30 14:11:12 +0200 | [diff] [blame] | 6035 | weston_output_init(struct weston_output *output, |
Pekka Paalanen | 26ac2e1 | 2017-04-03 13:18:13 +0300 | [diff] [blame] | 6036 | struct weston_compositor *compositor, |
| 6037 | const char *name) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6038 | { |
| 6039 | output->compositor = compositor; |
| 6040 | output->destroying = 0; |
Pekka Paalanen | 26ac2e1 | 2017-04-03 13:18:13 +0300 | [diff] [blame] | 6041 | output->name = strdup(name); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6042 | wl_list_init(&output->link); |
Pekka Paalanen | 37b7c6e | 2017-11-07 10:15:01 +0200 | [diff] [blame] | 6043 | wl_signal_init(&output->user_destroy_signal); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6044 | output->enabled = false; |
Ankit Nautiyal | 2690a77 | 2019-03-25 17:57:59 +0530 | [diff] [blame] | 6045 | output->desired_protection = WESTON_HDCP_DISABLE; |
Ankit Nautiyal | 2844f8e | 2019-04-03 10:14:59 +0530 | [diff] [blame] | 6046 | output->allow_protection = true; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6047 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 6048 | wl_list_init(&output->head_list); |
| 6049 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6050 | /* Add some (in)sane defaults which can be used |
| 6051 | * for checking if an output was properly configured |
| 6052 | */ |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6053 | output->scale = 0; |
| 6054 | /* Can't use -1 on uint32_t and 0 is valid enum value */ |
| 6055 | output->transform = UINT32_MAX; |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 6056 | |
| 6057 | pixman_region32_init(&output->previous_damage); |
| 6058 | pixman_region32_init(&output->region); |
Pekka Paalanen | 4270414 | 2017-09-06 16:47:52 +0300 | [diff] [blame] | 6059 | wl_list_init(&output->mode_list); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6060 | } |
| 6061 | |
| 6062 | /** Adds weston_output object to pending output list. |
| 6063 | * |
| 6064 | * \param output The weston_output object to add |
| 6065 | * \param compositor The compositor instance. |
| 6066 | * |
Pekka Paalanen | ae6d35d | 2017-08-16 12:07:14 +0300 | [diff] [blame] | 6067 | * The opposite of this operation is built into weston_output_release(). |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6068 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 6069 | * \ingroup compositor |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6070 | * \internal |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6071 | */ |
| 6072 | WL_EXPORT void |
| 6073 | weston_compositor_add_pending_output(struct weston_output *output, |
| 6074 | struct weston_compositor *compositor) |
| 6075 | { |
Pekka Paalanen | e952a01 | 2017-03-29 17:14:00 +0300 | [diff] [blame] | 6076 | assert(output->disable); |
| 6077 | assert(output->enable); |
| 6078 | |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 6079 | wl_list_remove(&output->link); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6080 | wl_list_insert(compositor->pending_output_list.prev, &output->link); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6081 | } |
| 6082 | |
Pekka Paalanen | 3e8f201 | 2017-11-02 14:03:11 +0200 | [diff] [blame] | 6083 | /** Create a string with the attached heads' names. |
| 6084 | * |
| 6085 | * The string must be free()'d. |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6086 | * |
| 6087 | * \ingroup output |
Pekka Paalanen | 3e8f201 | 2017-11-02 14:03:11 +0200 | [diff] [blame] | 6088 | */ |
| 6089 | static char * |
| 6090 | weston_output_create_heads_string(struct weston_output *output) |
| 6091 | { |
| 6092 | FILE *fp; |
| 6093 | char *str = NULL; |
| 6094 | size_t size = 0; |
| 6095 | struct weston_head *head; |
| 6096 | const char *sep = ""; |
| 6097 | |
| 6098 | fp = open_memstream(&str, &size); |
| 6099 | if (!fp) |
| 6100 | return NULL; |
| 6101 | |
| 6102 | wl_list_for_each(head, &output->head_list, output_link) { |
| 6103 | fprintf(fp, "%s%s", sep, head->name); |
| 6104 | sep = ", "; |
| 6105 | } |
| 6106 | fclose(fp); |
| 6107 | |
| 6108 | return str; |
| 6109 | } |
| 6110 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6111 | /** Constructs a weston_output object that can be used by the compositor. |
| 6112 | * |
Pekka Paalanen | cc201e4 | 2017-03-30 15:11:25 +0300 | [diff] [blame] | 6113 | * \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] | 6114 | * be enabled already. Must have at least one head attached. |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6115 | * |
| 6116 | * Output coordinates are calculated and each new output is by default |
| 6117 | * assigned to the right of previous one. |
| 6118 | * |
| 6119 | * Sets up the transformation, zoom, and geometry of the output using |
| 6120 | * the properties that need to be configured by the compositor. |
| 6121 | * |
| 6122 | * Establishes a repaint timer for the output with the relevant display |
| 6123 | * object's event loop. See output_repaint_timer_handler(). |
| 6124 | * |
| 6125 | * The output is assigned an ID. Weston can support up to 32 distinct |
| 6126 | * outputs, with IDs numbered from 0-31; the compositor's output_id_pool |
| 6127 | * is referred to and used to find the first available ID number, and |
| 6128 | * then this ID is marked as used in output_id_pool. |
| 6129 | * |
| 6130 | * The output is also assigned a Wayland global with the wl_output |
| 6131 | * external interface. |
| 6132 | * |
| 6133 | * Backend specific function is called to set up the output output. |
| 6134 | * |
| 6135 | * Output is added to the compositor's output list |
| 6136 | * |
| 6137 | * If the backend specific function fails, the weston_output object |
| 6138 | * is returned to a state it was before calling this function and |
| 6139 | * is added to the compositor's pending_output_list in case it needs |
| 6140 | * to be reconfigured or just so it can be destroyed at shutdown. |
| 6141 | * |
| 6142 | * 0 is returned on success, -1 on failure. |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6143 | * |
| 6144 | * \ingroup output |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6145 | */ |
| 6146 | WL_EXPORT int |
| 6147 | weston_output_enable(struct weston_output *output) |
| 6148 | { |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 6149 | struct weston_compositor *c = output->compositor; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6150 | struct weston_output *iterator; |
Pekka Paalanen | ec25b0a | 2017-08-24 16:08:49 +0300 | [diff] [blame] | 6151 | struct weston_head *head; |
Pekka Paalanen | 3e8f201 | 2017-11-02 14:03:11 +0200 | [diff] [blame] | 6152 | char *head_names; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6153 | int x = 0, y = 0; |
| 6154 | |
Pekka Paalanen | cc201e4 | 2017-03-30 15:11:25 +0300 | [diff] [blame] | 6155 | if (output->enabled) { |
| 6156 | weston_log("Error: attempt to enable an enabled output '%s'\n", |
| 6157 | output->name); |
| 6158 | return -1; |
| 6159 | } |
| 6160 | |
Pekka Paalanen | ddce54d | 2017-08-23 16:00:21 +0300 | [diff] [blame] | 6161 | if (wl_list_empty(&output->head_list)) { |
| 6162 | weston_log("Error: cannot enable output '%s' without heads.\n", |
| 6163 | output->name); |
| 6164 | return -1; |
| 6165 | } |
| 6166 | |
Pekka Paalanen | 586e1ac | 2017-09-14 16:17:59 +0300 | [diff] [blame] | 6167 | if (wl_list_empty(&output->mode_list) || !output->current_mode) { |
| 6168 | weston_log("Error: no video mode for output '%s'.\n", |
| 6169 | output->name); |
| 6170 | return -1; |
| 6171 | } |
| 6172 | |
Pekka Paalanen | ec25b0a | 2017-08-24 16:08:49 +0300 | [diff] [blame] | 6173 | wl_list_for_each(head, &output->head_list, output_link) { |
| 6174 | assert(head->make); |
| 6175 | assert(head->model); |
| 6176 | } |
| 6177 | |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 6178 | iterator = container_of(c->output_list.prev, |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6179 | struct weston_output, link); |
| 6180 | |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 6181 | if (!wl_list_empty(&c->output_list)) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6182 | x = iterator->x + iterator->width; |
| 6183 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6184 | /* Make sure the scale is set up */ |
| 6185 | assert(output->scale); |
| 6186 | |
| 6187 | /* Make sure we have a transform set */ |
| 6188 | assert(output->transform != UINT32_MAX); |
| 6189 | |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 6190 | output->x = x; |
| 6191 | output->y = y; |
| 6192 | output->dirty = 1; |
| 6193 | output->original_scale = output->scale; |
| 6194 | |
| 6195 | weston_output_transform_scale_init(output, output->transform, output->scale); |
| 6196 | weston_output_init_zoom(output); |
| 6197 | |
| 6198 | weston_output_init_geometry(output, x, y); |
| 6199 | weston_output_damage(output); |
| 6200 | |
| 6201 | wl_signal_init(&output->frame_signal); |
| 6202 | wl_signal_init(&output->destroy_signal); |
| 6203 | wl_list_init(&output->animation_list); |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 6204 | wl_list_init(&output->feedback_list); |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 6205 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6206 | /* Enable the output (set up the crtc or create a |
| 6207 | * window representing the output, set up the |
| 6208 | * renderer, etc) |
| 6209 | */ |
| 6210 | if (output->enable(output) < 0) { |
| 6211 | weston_log("Enabling output \"%s\" failed.\n", output->name); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6212 | return -1; |
| 6213 | } |
| 6214 | |
| 6215 | weston_compositor_add_output(output->compositor, output); |
| 6216 | |
Pekka Paalanen | 3e8f201 | 2017-11-02 14:03:11 +0200 | [diff] [blame] | 6217 | head_names = weston_output_create_heads_string(output); |
| 6218 | weston_log("Output '%s' enabled with head(s) %s\n", |
| 6219 | output->name, head_names); |
| 6220 | free(head_names); |
| 6221 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6222 | return 0; |
| 6223 | } |
| 6224 | |
| 6225 | /** Converts a weston_output object to a pending output state, so it |
| 6226 | ** can be configured again or destroyed. |
| 6227 | * |
| 6228 | * \param output The weston_output object that needs to be disabled. |
| 6229 | * |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6230 | * Calls a backend specific function to disable an output, in case |
| 6231 | * such function exists. |
| 6232 | * |
Pekka Paalanen | c65df64 | 2017-03-29 15:45:46 +0300 | [diff] [blame] | 6233 | * The backend specific disable function may choose to postpone the disabling |
| 6234 | * by returning a negative value, in which case this function returns early. |
| 6235 | * In that case the backend will guarantee the output will be disabled soon |
| 6236 | * by the backend calling this function again. One must not attempt to re-enable |
| 6237 | * the output until that happens. |
| 6238 | * |
| 6239 | * 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] | 6240 | * from weston's output_list (see weston_compositor_remove_output()) |
| 6241 | * and is returned to a state it was before weston_output_enable() |
| 6242 | * was ran (see weston_output_enable_undo()). |
| 6243 | * |
Pekka Paalanen | c65df64 | 2017-03-29 15:45:46 +0300 | [diff] [blame] | 6244 | * See weston_output_init() for more information on the |
| 6245 | * state output is returned to. |
Pekka Paalanen | cc201e4 | 2017-03-30 15:11:25 +0300 | [diff] [blame] | 6246 | * |
| 6247 | * If the output has never been enabled yet, this function can still be |
| 6248 | * called to ensure that the output is actually turned off rather than left |
| 6249 | * in the state it was discovered in. |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6250 | * |
| 6251 | * \ingroup output |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6252 | */ |
| 6253 | WL_EXPORT void |
| 6254 | weston_output_disable(struct weston_output *output) |
| 6255 | { |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6256 | /* Should we rename this? */ |
| 6257 | output->destroying = 1; |
| 6258 | |
Pekka Paalanen | c65df64 | 2017-03-29 15:45:46 +0300 | [diff] [blame] | 6259 | /* Disable is called unconditionally also for not-enabled outputs, |
| 6260 | * because at compositor start-up, if there is an output that is |
| 6261 | * already on but the compositor wants to turn it off, we have to |
| 6262 | * forward the turn-off to the backend so it knows to do it. |
| 6263 | * The backend cannot initially turn off everything, because it |
| 6264 | * would cause unnecessary mode-sets for all outputs the compositor |
| 6265 | * wants to be on. |
| 6266 | */ |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6267 | if (output->disable(output) < 0) |
| 6268 | return; |
| 6269 | |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 6270 | if (output->enabled) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6271 | weston_compositor_remove_output(output); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6272 | |
| 6273 | output->destroying = 0; |
| 6274 | } |
| 6275 | |
Pekka Paalanen | 8a8dcac | 2017-08-17 17:29:36 +0300 | [diff] [blame] | 6276 | /** Forces a synchronous call to heads_changed hook |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6277 | * |
| 6278 | * \param compositor The compositor instance |
Pekka Paalanen | 8a8dcac | 2017-08-17 17:29:36 +0300 | [diff] [blame] | 6279 | * |
| 6280 | * If there are new or changed heads, calls the heads_changed hook and |
| 6281 | * returns after the hook returns. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 6282 | * |
| 6283 | * \ingroup compositor |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6284 | */ |
| 6285 | WL_EXPORT void |
Pekka Paalanen | 8a8dcac | 2017-08-17 17:29:36 +0300 | [diff] [blame] | 6286 | weston_compositor_flush_heads_changed(struct weston_compositor *compositor) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6287 | { |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 6288 | if (compositor->heads_changed_source) { |
| 6289 | wl_event_source_remove(compositor->heads_changed_source); |
| 6290 | weston_compositor_call_heads_changed(compositor); |
| 6291 | } |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6292 | } |
| 6293 | |
Pekka Paalanen | 37b7c6e | 2017-11-07 10:15:01 +0200 | [diff] [blame] | 6294 | /** Add destroy callback for an output |
| 6295 | * |
| 6296 | * \param output The output to watch. |
| 6297 | * \param listener The listener to add. The \c notify member must be set. |
| 6298 | * |
| 6299 | * The listener callback will be called when user destroys an output. This |
| 6300 | * may be delayed by a backend in some cases. The main purpose of the |
| 6301 | * listener is to allow hooking up custom data to the output. The custom data |
| 6302 | * can be fetched via weston_output_get_destroy_listener() followed by |
| 6303 | * container_of(). |
| 6304 | * |
| 6305 | * The \c data argument to the notify callback is the weston_output being |
| 6306 | * destroyed. |
| 6307 | * |
| 6308 | * @note This is for the final destruction of an output, not when it gets |
| 6309 | * 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] | 6310 | * |
| 6311 | * \ingroup ouput |
Pekka Paalanen | 37b7c6e | 2017-11-07 10:15:01 +0200 | [diff] [blame] | 6312 | */ |
| 6313 | WL_EXPORT void |
| 6314 | weston_output_add_destroy_listener(struct weston_output *output, |
| 6315 | struct wl_listener *listener) |
| 6316 | { |
| 6317 | wl_signal_add(&output->user_destroy_signal, listener); |
| 6318 | } |
| 6319 | |
| 6320 | /** Look up destroy listener for an output |
| 6321 | * |
| 6322 | * \param output The output to query. |
| 6323 | * \param notify The notify function used used for the added destroy listener. |
| 6324 | * \return The listener, or NULL if not found. |
| 6325 | * |
| 6326 | * This looks up the previously added destroy listener struct based on the |
| 6327 | * notify function it has. The listener can be used to access user data |
| 6328 | * through \c container_of(). |
| 6329 | * |
| 6330 | * \sa wl_signal_get() weston_output_add_destroy_listener() |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6331 | * \ingroup output |
Pekka Paalanen | 37b7c6e | 2017-11-07 10:15:01 +0200 | [diff] [blame] | 6332 | */ |
| 6333 | WL_EXPORT struct wl_listener * |
| 6334 | weston_output_get_destroy_listener(struct weston_output *output, |
| 6335 | wl_notify_func_t notify) |
| 6336 | { |
| 6337 | return wl_signal_get(&output->user_destroy_signal, notify); |
| 6338 | } |
| 6339 | |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6340 | /** Uninitialize an output |
| 6341 | * |
| 6342 | * Removes the output from the list of enabled outputs if necessary, but |
| 6343 | * does not call the backend's output disable function. The output will no |
| 6344 | * longer be in the list of pending outputs either. |
| 6345 | * |
| 6346 | * All fields of weston_output become uninitialized, i.e. should not be used |
| 6347 | * anymore. The caller can free the memory after this. |
| 6348 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6349 | * \ingroup ouput |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6350 | * \internal |
| 6351 | */ |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6352 | WL_EXPORT void |
Pekka Paalanen | ae6d35d | 2017-08-16 12:07:14 +0300 | [diff] [blame] | 6353 | weston_output_release(struct weston_output *output) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6354 | { |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 6355 | struct weston_head *head, *tmp; |
| 6356 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6357 | output->destroying = 1; |
| 6358 | |
Pekka Paalanen | 37b7c6e | 2017-11-07 10:15:01 +0200 | [diff] [blame] | 6359 | wl_signal_emit(&output->user_destroy_signal, output); |
| 6360 | |
Pekka Paalanen | dcbcfc7 | 2017-10-26 14:33:59 +0300 | [diff] [blame] | 6361 | if (output->idle_repaint_source) |
| 6362 | wl_event_source_remove(output->idle_repaint_source); |
| 6363 | |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 6364 | if (output->enabled) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6365 | weston_compositor_remove_output(output); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6366 | |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 6367 | pixman_region32_fini(&output->region); |
| 6368 | pixman_region32_fini(&output->previous_damage); |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 6369 | wl_list_remove(&output->link); |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 6370 | |
| 6371 | wl_list_for_each_safe(head, tmp, &output->head_list, output_link) |
| 6372 | weston_head_detach(head); |
| 6373 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6374 | free(output->name); |
| 6375 | } |
| 6376 | |
Pekka Paalanen | 1ae9d08 | 2017-11-02 14:11:53 +0200 | [diff] [blame] | 6377 | /** Find an output by its given name |
| 6378 | * |
| 6379 | * \param compositor The compositor to search in. |
| 6380 | * \param name The output name to search for. |
| 6381 | * \return An existing output with the given name, or NULL if not found. |
| 6382 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 6383 | * \ingroup compositor |
Pekka Paalanen | 1ae9d08 | 2017-11-02 14:11:53 +0200 | [diff] [blame] | 6384 | */ |
| 6385 | WL_EXPORT struct weston_output * |
| 6386 | weston_compositor_find_output_by_name(struct weston_compositor *compositor, |
| 6387 | const char *name) |
| 6388 | { |
| 6389 | struct weston_output *output; |
| 6390 | |
| 6391 | wl_list_for_each(output, &compositor->output_list, link) |
| 6392 | if (strcmp(output->name, name) == 0) |
| 6393 | return output; |
| 6394 | |
| 6395 | wl_list_for_each(output, &compositor->pending_output_list, link) |
| 6396 | if (strcmp(output->name, name) == 0) |
| 6397 | return output; |
| 6398 | |
| 6399 | return NULL; |
| 6400 | } |
| 6401 | |
| 6402 | /** Create a named output |
| 6403 | * |
| 6404 | * \param compositor The compositor. |
| 6405 | * \param name The name for the output. |
| 6406 | * \return A new \c weston_output, or NULL on failure. |
| 6407 | * |
| 6408 | * This creates a new weston_output that starts with no heads attached. |
| 6409 | * |
| 6410 | * An output must be configured and it must have at least one head before |
| 6411 | * it can be enabled. |
| 6412 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 6413 | * \ingroup compositor |
Pekka Paalanen | 1ae9d08 | 2017-11-02 14:11:53 +0200 | [diff] [blame] | 6414 | */ |
| 6415 | WL_EXPORT struct weston_output * |
| 6416 | weston_compositor_create_output(struct weston_compositor *compositor, |
| 6417 | const char *name) |
| 6418 | { |
| 6419 | assert(compositor->backend->create_output); |
| 6420 | |
| 6421 | if (weston_compositor_find_output_by_name(compositor, name)) { |
| 6422 | weston_log("Warning: attempted to create an output with a " |
| 6423 | "duplicate name '%s'.\n", name); |
| 6424 | return NULL; |
| 6425 | } |
| 6426 | |
| 6427 | return compositor->backend->create_output(compositor, name); |
| 6428 | } |
| 6429 | |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 6430 | /** Create an output for an unused head |
| 6431 | * |
| 6432 | * \param compositor The compositor. |
| 6433 | * \param head The head to attach to the output. |
| 6434 | * \return A new \c weston_output, or NULL on failure. |
| 6435 | * |
| 6436 | * This creates a new weston_output that starts with the given head attached. |
| 6437 | * The output inherits the name of the head. The head must not be already |
| 6438 | * attached to another output. |
| 6439 | * |
| 6440 | * An output must be configured before it can be enabled. |
| 6441 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 6442 | * \ingroup compositor |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 6443 | */ |
| 6444 | WL_EXPORT struct weston_output * |
| 6445 | weston_compositor_create_output_with_head(struct weston_compositor *compositor, |
| 6446 | struct weston_head *head) |
| 6447 | { |
| 6448 | struct weston_output *output; |
| 6449 | |
Pekka Paalanen | 1ae9d08 | 2017-11-02 14:11:53 +0200 | [diff] [blame] | 6450 | output = weston_compositor_create_output(compositor, head->name); |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 6451 | if (!output) |
| 6452 | return NULL; |
| 6453 | |
| 6454 | if (weston_output_attach_head(output, head) < 0) { |
Pekka Paalanen | 42c0e14 | 2017-10-27 12:07:49 +0300 | [diff] [blame] | 6455 | weston_output_destroy(output); |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 6456 | return NULL; |
| 6457 | } |
| 6458 | |
| 6459 | return output; |
| 6460 | } |
| 6461 | |
| 6462 | /** Destroy an output |
| 6463 | * |
| 6464 | * \param output The output to destroy. |
| 6465 | * |
| 6466 | * The heads attached to the given output are detached and become unused again. |
| 6467 | * |
| 6468 | * It is not necessary to explicitly destroy all outputs at compositor exit. |
| 6469 | * weston_compositor_destroy() will automatically destroy any remaining |
| 6470 | * outputs. |
| 6471 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6472 | * \ingroup ouput |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 6473 | */ |
| 6474 | WL_EXPORT void |
| 6475 | weston_output_destroy(struct weston_output *output) |
| 6476 | { |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 6477 | output->destroy(output); |
| 6478 | } |
| 6479 | |
Pekka Paalanen | cf0a476 | 2017-04-04 16:36:07 +0300 | [diff] [blame] | 6480 | /** When you need a head... |
| 6481 | * |
| 6482 | * This function is a hack, used until all code has been converted to become |
| 6483 | * multi-head aware. |
| 6484 | * |
| 6485 | * \param output The weston_output whose head to get. |
| 6486 | * \return The first head in the output's list. |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6487 | * |
| 6488 | * \ingroup ouput |
Pekka Paalanen | cf0a476 | 2017-04-04 16:36:07 +0300 | [diff] [blame] | 6489 | */ |
| 6490 | WL_EXPORT struct weston_head * |
| 6491 | weston_output_get_first_head(struct weston_output *output) |
| 6492 | { |
| 6493 | if (wl_list_empty(&output->head_list)) |
| 6494 | return NULL; |
| 6495 | |
| 6496 | return container_of(output->head_list.next, |
| 6497 | struct weston_head, output_link); |
| 6498 | } |
| 6499 | |
Ankit Nautiyal | 2844f8e | 2019-04-03 10:14:59 +0530 | [diff] [blame] | 6500 | /** Allow/Disallow content-protection support for an output |
| 6501 | * |
| 6502 | * This function sets the allow_protection member for an output. Setting of |
| 6503 | * this field will allow the compositor to attempt content-protection for this |
| 6504 | * output, for a backend that supports the content-protection protocol. |
| 6505 | * |
| 6506 | * \param output The weston_output for whom the content-protection is to be |
| 6507 | * allowed. |
| 6508 | * \param allow_protection The bool value which is to be set. |
| 6509 | */ |
| 6510 | WL_EXPORT void |
| 6511 | weston_output_allow_protection(struct weston_output *output, |
| 6512 | bool allow_protection) |
| 6513 | { |
| 6514 | output->allow_protection = allow_protection; |
| 6515 | } |
| 6516 | |
Benjamin Franzke | 315b3dc | 2011-03-08 11:32:57 +0100 | [diff] [blame] | 6517 | static void |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 6518 | xdg_output_unlist(struct wl_resource *resource) |
| 6519 | { |
| 6520 | wl_list_remove(wl_resource_get_link(resource)); |
| 6521 | } |
| 6522 | |
| 6523 | static void |
| 6524 | xdg_output_destroy(struct wl_client *client, struct wl_resource *resource) |
| 6525 | { |
| 6526 | wl_resource_destroy(resource); |
| 6527 | } |
| 6528 | |
| 6529 | static const struct zxdg_output_v1_interface xdg_output_interface = { |
| 6530 | xdg_output_destroy |
| 6531 | }; |
| 6532 | |
| 6533 | static void |
| 6534 | xdg_output_manager_destroy(struct wl_client *client, |
| 6535 | struct wl_resource *resource) |
| 6536 | { |
| 6537 | wl_resource_destroy(resource); |
| 6538 | } |
| 6539 | |
| 6540 | static void |
| 6541 | xdg_output_manager_get_xdg_output(struct wl_client *client, |
| 6542 | struct wl_resource *manager, |
| 6543 | uint32_t id, |
| 6544 | struct wl_resource *output_resource) |
| 6545 | { |
| 6546 | int version = wl_resource_get_version(manager); |
| 6547 | struct weston_head *head = wl_resource_get_user_data(output_resource); |
| 6548 | struct weston_output *output = head->output; |
| 6549 | struct wl_resource *resource; |
| 6550 | |
| 6551 | resource = wl_resource_create(client, &zxdg_output_v1_interface, |
| 6552 | version, id); |
| 6553 | if (resource == NULL) { |
| 6554 | wl_client_post_no_memory(client); |
| 6555 | return; |
| 6556 | } |
| 6557 | |
| 6558 | wl_list_insert(&head->xdg_output_resource_list, |
| 6559 | wl_resource_get_link(resource)); |
| 6560 | |
| 6561 | wl_resource_set_implementation(resource, &xdg_output_interface, |
| 6562 | NULL, xdg_output_unlist); |
| 6563 | |
| 6564 | zxdg_output_v1_send_logical_position(resource, output->x, output->y); |
| 6565 | zxdg_output_v1_send_logical_size(resource, |
| 6566 | output->width, |
| 6567 | output->height); |
| 6568 | if (version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION) |
| 6569 | zxdg_output_v1_send_name(resource, head->name); |
| 6570 | |
| 6571 | zxdg_output_v1_send_done(resource); |
| 6572 | } |
| 6573 | |
| 6574 | static const struct zxdg_output_manager_v1_interface xdg_output_manager_interface = { |
| 6575 | xdg_output_manager_destroy, |
| 6576 | xdg_output_manager_get_xdg_output |
| 6577 | }; |
| 6578 | |
| 6579 | static void |
| 6580 | bind_xdg_output_manager(struct wl_client *client, |
| 6581 | void *data, uint32_t version, uint32_t id) |
| 6582 | { |
| 6583 | struct wl_resource *resource; |
| 6584 | |
| 6585 | resource = wl_resource_create(client, &zxdg_output_manager_v1_interface, |
| 6586 | version, id); |
| 6587 | if (resource == NULL) { |
| 6588 | wl_client_post_no_memory(client); |
| 6589 | return; |
| 6590 | } |
| 6591 | |
| 6592 | wl_resource_set_implementation(resource, &xdg_output_manager_interface, |
| 6593 | NULL, NULL); |
| 6594 | } |
| 6595 | |
| 6596 | static void |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6597 | destroy_viewport(struct wl_resource *resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6598 | { |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 6599 | struct weston_surface *surface = |
| 6600 | wl_resource_get_user_data(resource); |
| 6601 | |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 6602 | if (!surface) |
| 6603 | return; |
| 6604 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6605 | surface->viewport_resource = NULL; |
Pekka Paalanen | f0cad48 | 2014-03-14 14:38:16 +0200 | [diff] [blame] | 6606 | surface->pending.buffer_viewport.buffer.src_width = |
| 6607 | wl_fixed_from_int(-1); |
| 6608 | surface->pending.buffer_viewport.surface.width = -1; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 6609 | surface->pending.buffer_viewport.changed = 1; |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6610 | } |
| 6611 | |
| 6612 | static void |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6613 | viewport_destroy(struct wl_client *client, |
| 6614 | struct wl_resource *resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6615 | { |
| 6616 | wl_resource_destroy(resource); |
| 6617 | } |
| 6618 | |
| 6619 | static void |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6620 | viewport_set_source(struct wl_client *client, |
| 6621 | struct wl_resource *resource, |
| 6622 | wl_fixed_t src_x, |
| 6623 | wl_fixed_t src_y, |
| 6624 | wl_fixed_t src_width, |
| 6625 | wl_fixed_t src_height) |
| 6626 | { |
| 6627 | struct weston_surface *surface = |
| 6628 | wl_resource_get_user_data(resource); |
| 6629 | |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 6630 | if (!surface) { |
| 6631 | wl_resource_post_error(resource, |
| 6632 | WP_VIEWPORT_ERROR_NO_SURFACE, |
| 6633 | "wl_surface for this viewport is no longer exists"); |
| 6634 | return; |
| 6635 | } |
| 6636 | |
| 6637 | assert(surface->viewport_resource == resource); |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 6638 | assert(surface->resource); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6639 | |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6640 | if (src_width == wl_fixed_from_int(-1) && |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 6641 | src_height == wl_fixed_from_int(-1) && |
| 6642 | src_x == wl_fixed_from_int(-1) && |
| 6643 | src_y == wl_fixed_from_int(-1)) { |
| 6644 | /* unset source rect */ |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6645 | surface->pending.buffer_viewport.buffer.src_width = |
| 6646 | wl_fixed_from_int(-1); |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 6647 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6648 | return; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6649 | } |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6650 | |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 6651 | 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] | 6652 | wl_resource_post_error(resource, |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 6653 | WP_VIEWPORT_ERROR_BAD_VALUE, |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 6654 | "wl_surface@%d viewport source " |
| 6655 | "w=%f <= 0, h=%f <= 0, x=%f < 0, or y=%f < 0", |
| 6656 | wl_resource_get_id(surface->resource), |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6657 | wl_fixed_to_double(src_width), |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 6658 | wl_fixed_to_double(src_height), |
| 6659 | wl_fixed_to_double(src_x), |
| 6660 | wl_fixed_to_double(src_y)); |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6661 | return; |
| 6662 | } |
| 6663 | |
| 6664 | surface->pending.buffer_viewport.buffer.src_x = src_x; |
| 6665 | surface->pending.buffer_viewport.buffer.src_y = src_y; |
| 6666 | surface->pending.buffer_viewport.buffer.src_width = src_width; |
| 6667 | surface->pending.buffer_viewport.buffer.src_height = src_height; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 6668 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6669 | } |
| 6670 | |
| 6671 | static void |
| 6672 | viewport_set_destination(struct wl_client *client, |
| 6673 | struct wl_resource *resource, |
| 6674 | int32_t dst_width, |
| 6675 | int32_t dst_height) |
| 6676 | { |
| 6677 | struct weston_surface *surface = |
| 6678 | wl_resource_get_user_data(resource); |
| 6679 | |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 6680 | if (!surface) { |
| 6681 | wl_resource_post_error(resource, |
| 6682 | WP_VIEWPORT_ERROR_NO_SURFACE, |
| 6683 | "wl_surface for this viewport no longer exists"); |
| 6684 | return; |
| 6685 | } |
| 6686 | |
| 6687 | assert(surface->viewport_resource == resource); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6688 | |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6689 | if (dst_width == -1 && dst_height == -1) { |
| 6690 | /* unset destination size */ |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6691 | surface->pending.buffer_viewport.surface.width = -1; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 6692 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6693 | return; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6694 | } |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6695 | |
| 6696 | if (dst_width <= 0 || dst_height <= 0) { |
| 6697 | wl_resource_post_error(resource, |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 6698 | WP_VIEWPORT_ERROR_BAD_VALUE, |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6699 | "destination size must be positive (%dx%d)", |
| 6700 | dst_width, dst_height); |
| 6701 | return; |
| 6702 | } |
| 6703 | |
| 6704 | surface->pending.buffer_viewport.surface.width = dst_width; |
| 6705 | surface->pending.buffer_viewport.surface.height = dst_height; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 6706 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6707 | } |
| 6708 | |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 6709 | static const struct wp_viewport_interface viewport_interface = { |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6710 | viewport_destroy, |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6711 | viewport_set_source, |
| 6712 | viewport_set_destination |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6713 | }; |
| 6714 | |
| 6715 | static void |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6716 | viewporter_destroy(struct wl_client *client, |
| 6717 | struct wl_resource *resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6718 | { |
| 6719 | wl_resource_destroy(resource); |
| 6720 | } |
| 6721 | |
| 6722 | static void |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6723 | viewporter_get_viewport(struct wl_client *client, |
| 6724 | struct wl_resource *viewporter, |
| 6725 | uint32_t id, |
| 6726 | struct wl_resource *surface_resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6727 | { |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6728 | int version = wl_resource_get_version(viewporter); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6729 | struct weston_surface *surface = |
| 6730 | wl_resource_get_user_data(surface_resource); |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6731 | struct wl_resource *resource; |
| 6732 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6733 | if (surface->viewport_resource) { |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6734 | wl_resource_post_error(viewporter, |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 6735 | WP_VIEWPORTER_ERROR_VIEWPORT_EXISTS, |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6736 | "a viewport for that surface already exists"); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 6737 | return; |
| 6738 | } |
| 6739 | |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 6740 | resource = wl_resource_create(client, &wp_viewport_interface, |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6741 | version, id); |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6742 | if (resource == NULL) { |
| 6743 | wl_client_post_no_memory(client); |
| 6744 | return; |
| 6745 | } |
| 6746 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6747 | wl_resource_set_implementation(resource, &viewport_interface, |
| 6748 | surface, destroy_viewport); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 6749 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6750 | surface->viewport_resource = resource; |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6751 | } |
| 6752 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6753 | static const struct wp_viewporter_interface viewporter_interface = { |
| 6754 | viewporter_destroy, |
| 6755 | viewporter_get_viewport |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6756 | }; |
| 6757 | |
| 6758 | static void |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6759 | bind_viewporter(struct wl_client *client, |
| 6760 | void *data, uint32_t version, uint32_t id) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6761 | { |
| 6762 | struct wl_resource *resource; |
| 6763 | |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 6764 | resource = wl_resource_create(client, &wp_viewporter_interface, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 6765 | version, id); |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6766 | if (resource == NULL) { |
| 6767 | wl_client_post_no_memory(client); |
| 6768 | return; |
| 6769 | } |
| 6770 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6771 | wl_resource_set_implementation(resource, &viewporter_interface, |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6772 | NULL, NULL); |
| 6773 | } |
| 6774 | |
| 6775 | static void |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 6776 | destroy_presentation_feedback(struct wl_resource *feedback_resource) |
| 6777 | { |
| 6778 | struct weston_presentation_feedback *feedback; |
| 6779 | |
| 6780 | feedback = wl_resource_get_user_data(feedback_resource); |
| 6781 | |
| 6782 | wl_list_remove(&feedback->link); |
| 6783 | free(feedback); |
| 6784 | } |
| 6785 | |
| 6786 | static void |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 6787 | presentation_destroy(struct wl_client *client, struct wl_resource *resource) |
| 6788 | { |
| 6789 | wl_resource_destroy(resource); |
| 6790 | } |
| 6791 | |
| 6792 | static void |
| 6793 | presentation_feedback(struct wl_client *client, |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 6794 | struct wl_resource *presentation_resource, |
| 6795 | struct wl_resource *surface_resource, |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 6796 | uint32_t callback) |
| 6797 | { |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 6798 | struct weston_surface *surface; |
| 6799 | struct weston_presentation_feedback *feedback; |
| 6800 | |
| 6801 | surface = wl_resource_get_user_data(surface_resource); |
| 6802 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 6803 | feedback = zalloc(sizeof *feedback); |
| 6804 | if (feedback == NULL) |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 6805 | goto err_calloc; |
| 6806 | |
| 6807 | feedback->resource = wl_resource_create(client, |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 6808 | &wp_presentation_feedback_interface, |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 6809 | 1, callback); |
| 6810 | if (!feedback->resource) |
| 6811 | goto err_create; |
| 6812 | |
| 6813 | wl_resource_set_implementation(feedback->resource, NULL, feedback, |
| 6814 | destroy_presentation_feedback); |
| 6815 | |
| 6816 | wl_list_insert(&surface->pending.feedback_list, &feedback->link); |
| 6817 | |
| 6818 | return; |
| 6819 | |
| 6820 | err_create: |
| 6821 | free(feedback); |
| 6822 | |
| 6823 | err_calloc: |
| 6824 | wl_client_post_no_memory(client); |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 6825 | } |
| 6826 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 6827 | static const struct wp_presentation_interface presentation_implementation = { |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 6828 | presentation_destroy, |
| 6829 | presentation_feedback |
| 6830 | }; |
| 6831 | |
| 6832 | static void |
| 6833 | bind_presentation(struct wl_client *client, |
| 6834 | void *data, uint32_t version, uint32_t id) |
| 6835 | { |
| 6836 | struct weston_compositor *compositor = data; |
| 6837 | struct wl_resource *resource; |
| 6838 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 6839 | resource = wl_resource_create(client, &wp_presentation_interface, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 6840 | version, id); |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 6841 | if (resource == NULL) { |
| 6842 | wl_client_post_no_memory(client); |
| 6843 | return; |
| 6844 | } |
| 6845 | |
| 6846 | wl_resource_set_implementation(resource, &presentation_implementation, |
| 6847 | compositor, NULL); |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 6848 | wp_presentation_send_clock_id(resource, compositor->presentation_clock); |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 6849 | } |
| 6850 | |
| 6851 | static void |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 6852 | compositor_bind(struct wl_client *client, |
| 6853 | void *data, uint32_t version, uint32_t id) |
| 6854 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 6855 | struct weston_compositor *compositor = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 6856 | struct wl_resource *resource; |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 6857 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 6858 | resource = wl_resource_create(client, &wl_compositor_interface, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 6859 | version, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 6860 | if (resource == NULL) { |
| 6861 | wl_client_post_no_memory(client); |
| 6862 | return; |
| 6863 | } |
| 6864 | |
| 6865 | wl_resource_set_implementation(resource, &compositor_interface, |
| 6866 | compositor, NULL); |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 6867 | } |
| 6868 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6869 | WL_EXPORT int |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 6870 | weston_environment_get_fd(const char *env) |
| 6871 | { |
Bryce Harrington | 25a2bdd | 2016-08-03 17:40:52 -0700 | [diff] [blame] | 6872 | char *e; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 6873 | int fd, flags; |
| 6874 | |
| 6875 | e = getenv(env); |
Bryce Harrington | 25a2bdd | 2016-08-03 17:40:52 -0700 | [diff] [blame] | 6876 | if (!e || !safe_strtoint(e, &fd)) |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 6877 | return -1; |
| 6878 | |
| 6879 | flags = fcntl(fd, F_GETFD); |
| 6880 | if (flags == -1) |
| 6881 | return -1; |
| 6882 | |
| 6883 | fcntl(fd, F_SETFD, flags | FD_CLOEXEC); |
| 6884 | unsetenv(env); |
| 6885 | |
| 6886 | return fd; |
| 6887 | } |
| 6888 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 6889 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 6890 | timeline_key_binding_handler(struct weston_keyboard *keyboard, |
| 6891 | const struct timespec *time, uint32_t key, |
| 6892 | void *data) |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 6893 | { |
| 6894 | struct weston_compositor *compositor = data; |
| 6895 | |
| 6896 | if (weston_timeline_enabled_) |
| 6897 | weston_timeline_close(); |
| 6898 | else |
| 6899 | weston_timeline_open(compositor); |
| 6900 | } |
| 6901 | |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6902 | static const char * |
| 6903 | output_repaint_status_text(struct weston_output *output) |
| 6904 | { |
| 6905 | switch (output->repaint_status) { |
| 6906 | case REPAINT_NOT_SCHEDULED: |
| 6907 | return "no repaint"; |
| 6908 | case REPAINT_BEGIN_FROM_IDLE: |
| 6909 | return "start_repaint_loop scheduled"; |
| 6910 | case REPAINT_SCHEDULED: |
| 6911 | return "repaint scheduled"; |
| 6912 | case REPAINT_AWAITING_COMPLETION: |
| 6913 | return "awaiting completion"; |
| 6914 | } |
| 6915 | |
| 6916 | assert(!"output_repaint_status_text missing enum"); |
| 6917 | return NULL; |
| 6918 | } |
| 6919 | |
| 6920 | static void |
| 6921 | debug_scene_view_print_buffer(FILE *fp, struct weston_view *view) |
| 6922 | { |
| 6923 | struct weston_buffer *buffer = view->surface->buffer_ref.buffer; |
| 6924 | struct wl_shm_buffer *shm; |
| 6925 | struct linux_dmabuf_buffer *dmabuf; |
Marius Vlad | 00a6e01 | 2018-11-20 17:52:31 +0200 | [diff] [blame] | 6926 | const struct pixel_format_info *pixel_info = NULL; |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6927 | |
| 6928 | if (!buffer) { |
| 6929 | fprintf(fp, "\t\t[buffer not available]\n"); |
| 6930 | return; |
| 6931 | } |
| 6932 | |
| 6933 | shm = wl_shm_buffer_get(buffer->resource); |
| 6934 | if (shm) { |
Marius Vlad | 00a6e01 | 2018-11-20 17:52:31 +0200 | [diff] [blame] | 6935 | uint32_t _format = wl_shm_buffer_get_format(shm); |
| 6936 | pixel_info = pixel_format_get_info_shm(_format); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6937 | fprintf(fp, "\t\tSHM buffer\n"); |
Marius Vlad | 00a6e01 | 2018-11-20 17:52:31 +0200 | [diff] [blame] | 6938 | fprintf(fp, "\t\t\tformat: 0x%lx %s\n", |
| 6939 | (unsigned long) _format, |
| 6940 | pixel_info ? pixel_info->drm_format_name : "UNKNOWN"); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6941 | return; |
| 6942 | } |
| 6943 | |
| 6944 | dmabuf = linux_dmabuf_buffer_get(buffer->resource); |
| 6945 | if (dmabuf) { |
Marius Vlad | 00a6e01 | 2018-11-20 17:52:31 +0200 | [diff] [blame] | 6946 | pixel_info = pixel_format_get_info(dmabuf->attributes.format); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6947 | fprintf(fp, "\t\tdmabuf buffer\n"); |
Marius Vlad | 00a6e01 | 2018-11-20 17:52:31 +0200 | [diff] [blame] | 6948 | fprintf(fp, "\t\t\tformat: 0x%lx %s\n", |
| 6949 | (unsigned long) dmabuf->attributes.format, |
| 6950 | pixel_info ? pixel_info->drm_format_name : "UNKNOWN"); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6951 | fprintf(fp, "\t\t\tmodifier: 0x%llx\n", |
| 6952 | (unsigned long long) dmabuf->attributes.modifier[0]); |
| 6953 | return; |
| 6954 | } |
| 6955 | |
Marius Vlad | 253ba9a | 2019-03-17 18:22:21 +0200 | [diff] [blame] | 6956 | fprintf(fp, "\t\tEGL buffer\n"); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6957 | } |
| 6958 | |
| 6959 | static void |
| 6960 | debug_scene_view_print(FILE *fp, struct weston_view *view, int view_idx) |
| 6961 | { |
| 6962 | struct weston_compositor *ec = view->surface->compositor; |
| 6963 | struct weston_output *output; |
| 6964 | char desc[512]; |
| 6965 | pixman_box32_t *box; |
| 6966 | uint32_t surface_id = 0; |
| 6967 | pid_t pid = 0; |
| 6968 | |
| 6969 | if (view->surface->resource) { |
| 6970 | struct wl_resource *resource = view->surface->resource; |
| 6971 | wl_client_get_credentials(wl_resource_get_client(resource), |
| 6972 | &pid, NULL, NULL); |
| 6973 | surface_id = wl_resource_get_id(view->surface->resource); |
| 6974 | } |
| 6975 | |
| 6976 | if (!view->surface->get_label || |
| 6977 | view->surface->get_label(view->surface, desc, sizeof(desc)) < 0) { |
| 6978 | strcpy(desc, "[no description available]"); |
| 6979 | } |
| 6980 | fprintf(fp, "\tView %d (role %s, PID %d, surface ID %u, %s, %p):\n", |
| 6981 | view_idx, view->surface->role_name, pid, surface_id, |
| 6982 | desc, view); |
| 6983 | |
| 6984 | box = pixman_region32_extents(&view->transform.boundingbox); |
| 6985 | fprintf(fp, "\t\tposition: (%d, %d) -> (%d, %d)\n", |
| 6986 | box->x1, box->y1, box->x2, box->y2); |
| 6987 | box = pixman_region32_extents(&view->transform.opaque); |
| 6988 | |
| 6989 | if (pixman_region32_equal(&view->transform.opaque, |
| 6990 | &view->transform.boundingbox)) { |
| 6991 | fprintf(fp, "\t\t[fully opaque]\n"); |
| 6992 | } else if (!pixman_region32_not_empty(&view->transform.opaque)) { |
| 6993 | fprintf(fp, "\t\t[not opaque]\n"); |
| 6994 | } else { |
| 6995 | fprintf(fp, "\t\t[opaque: (%d, %d) -> (%d, %d)]\n", |
| 6996 | box->x1, box->y1, box->x2, box->y2); |
| 6997 | } |
| 6998 | |
| 6999 | if (view->alpha < 1.0) |
| 7000 | fprintf(fp, "\t\talpha: %f\n", view->alpha); |
| 7001 | |
| 7002 | if (view->output_mask != 0) { |
| 7003 | bool first_output = true; |
| 7004 | fprintf(fp, "\t\toutputs: "); |
| 7005 | wl_list_for_each(output, &ec->output_list, link) { |
| 7006 | if (!(view->output_mask & (1 << output->id))) |
| 7007 | continue; |
| 7008 | fprintf(fp, "%s%d (%s)%s", |
| 7009 | (first_output) ? "" : ", ", |
| 7010 | output->id, output->name, |
| 7011 | (view->output == output) ? " (primary)" : ""); |
| 7012 | first_output = false; |
| 7013 | } |
| 7014 | } else { |
| 7015 | fprintf(fp, "\t\t[no outputs]"); |
| 7016 | } |
| 7017 | |
| 7018 | fprintf(fp, "\n"); |
| 7019 | |
| 7020 | debug_scene_view_print_buffer(fp, view); |
| 7021 | } |
| 7022 | |
Marius Vlad | 433f4e7 | 2019-02-17 22:14:23 +0200 | [diff] [blame] | 7023 | static void |
| 7024 | debug_scene_view_print_tree(struct weston_view *view, |
Marius Vlad | a6acfa8 | 2019-03-17 18:10:09 +0200 | [diff] [blame] | 7025 | FILE *fp, int *view_idx) |
Marius Vlad | 433f4e7 | 2019-02-17 22:14:23 +0200 | [diff] [blame] | 7026 | { |
| 7027 | struct weston_subsurface *sub; |
| 7028 | struct weston_view *ev; |
| 7029 | |
| 7030 | /* |
| 7031 | * print the view first, then we recursively go on printing |
| 7032 | * sub-surfaces. We bail out once no more sub-surfaces are available. |
| 7033 | */ |
Marius Vlad | a6acfa8 | 2019-03-17 18:10:09 +0200 | [diff] [blame] | 7034 | debug_scene_view_print(fp, view, *view_idx); |
Marius Vlad | 433f4e7 | 2019-02-17 22:14:23 +0200 | [diff] [blame] | 7035 | |
| 7036 | /* no more sub-surfaces */ |
| 7037 | if (wl_list_empty(&view->surface->subsurface_list)) |
| 7038 | return; |
| 7039 | |
| 7040 | wl_list_for_each(sub, &view->surface->subsurface_list, parent_link) { |
| 7041 | wl_list_for_each(ev, &sub->surface->views, surface_link) { |
| 7042 | /* do not print again the parent view */ |
| 7043 | if (view == ev) |
| 7044 | continue; |
Marius Vlad | a6acfa8 | 2019-03-17 18:10:09 +0200 | [diff] [blame] | 7045 | |
| 7046 | (*view_idx)++; |
Marius Vlad | 433f4e7 | 2019-02-17 22:14:23 +0200 | [diff] [blame] | 7047 | debug_scene_view_print_tree(ev, fp, view_idx); |
| 7048 | } |
| 7049 | } |
| 7050 | } |
| 7051 | |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7052 | /** |
| 7053 | * Output information on how libweston is currently composing the scene |
| 7054 | * graph. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7055 | * |
| 7056 | * \ingroup compositor |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7057 | */ |
| 7058 | WL_EXPORT char * |
| 7059 | weston_compositor_print_scene_graph(struct weston_compositor *ec) |
| 7060 | { |
| 7061 | struct weston_output *output; |
| 7062 | struct weston_layer *layer; |
| 7063 | struct timespec now; |
| 7064 | int layer_idx = 0; |
| 7065 | FILE *fp; |
| 7066 | char *ret; |
| 7067 | size_t len; |
| 7068 | int err; |
| 7069 | |
| 7070 | fp = open_memstream(&ret, &len); |
| 7071 | assert(fp); |
| 7072 | |
| 7073 | weston_compositor_read_presentation_clock(ec, &now); |
| 7074 | fprintf(fp, "Weston scene graph at %ld.%09ld:\n\n", |
| 7075 | now.tv_sec, now.tv_nsec); |
| 7076 | |
| 7077 | wl_list_for_each(output, &ec->output_list, link) { |
| 7078 | struct weston_head *head; |
| 7079 | int head_idx = 0; |
| 7080 | |
| 7081 | fprintf(fp, "Output %d (%s):\n", output->id, output->name); |
| 7082 | assert(output->enabled); |
| 7083 | |
| 7084 | fprintf(fp, "\tposition: (%d, %d) -> (%d, %d)\n", |
| 7085 | output->x, output->y, |
| 7086 | output->x + output->width, |
| 7087 | output->y + output->height); |
| 7088 | fprintf(fp, "\tmode: %dx%d@%.3fHz\n", |
| 7089 | output->current_mode->width, |
| 7090 | output->current_mode->height, |
| 7091 | output->current_mode->refresh / 1000.0); |
| 7092 | fprintf(fp, "\tscale: %d\n", output->scale); |
| 7093 | |
| 7094 | fprintf(fp, "\trepaint status: %s\n", |
| 7095 | output_repaint_status_text(output)); |
| 7096 | if (output->repaint_status == REPAINT_SCHEDULED) |
| 7097 | fprintf(fp, "\tnext repaint: %ld.%09ld\n", |
| 7098 | output->next_repaint.tv_sec, |
| 7099 | output->next_repaint.tv_nsec); |
| 7100 | |
| 7101 | wl_list_for_each(head, &output->head_list, output_link) { |
| 7102 | fprintf(fp, "\tHead %d (%s): %sconnected\n", |
| 7103 | head_idx++, head->name, |
| 7104 | (head->connected) ? "" : "not "); |
| 7105 | } |
| 7106 | } |
| 7107 | |
| 7108 | fprintf(fp, "\n"); |
| 7109 | |
| 7110 | wl_list_for_each(layer, &ec->layer_list, link) { |
| 7111 | struct weston_view *view; |
| 7112 | int view_idx = 0; |
| 7113 | |
| 7114 | fprintf(fp, "Layer %d (pos 0x%lx):\n", layer_idx++, |
| 7115 | (unsigned long) layer->position); |
| 7116 | |
| 7117 | if (!weston_layer_mask_is_infinite(layer)) { |
| 7118 | fprintf(fp, "\t[mask: (%d, %d) -> (%d,%d)]\n\n", |
| 7119 | layer->mask.x1, layer->mask.y1, |
| 7120 | layer->mask.x2, layer->mask.y2); |
| 7121 | } |
| 7122 | |
Marius Vlad | a6acfa8 | 2019-03-17 18:10:09 +0200 | [diff] [blame] | 7123 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
| 7124 | debug_scene_view_print_tree(view, fp, &view_idx); |
| 7125 | view_idx++; |
| 7126 | } |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7127 | |
| 7128 | if (wl_list_empty(&layer->view_list.link)) |
| 7129 | fprintf(fp, "\t[no views]\n"); |
| 7130 | |
| 7131 | fprintf(fp, "\n"); |
| 7132 | } |
| 7133 | |
| 7134 | err = fclose(fp); |
| 7135 | assert(err == 0); |
| 7136 | |
| 7137 | return ret; |
| 7138 | } |
| 7139 | |
| 7140 | /** |
| 7141 | * Called when the 'scene-graph' debug scope is bound by a client. This |
| 7142 | * one-shot weston-debug scope prints the current scene graph when bound, |
| 7143 | * and then terminates the stream. |
| 7144 | */ |
| 7145 | static void |
Marius Vlad | dad882a | 2019-07-17 15:43:53 +0300 | [diff] [blame] | 7146 | debug_scene_graph_cb(struct weston_log_subscription *sub, void *data) |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7147 | { |
| 7148 | struct weston_compositor *ec = data; |
| 7149 | char *str = weston_compositor_print_scene_graph(ec); |
| 7150 | |
Marius Vlad | dad882a | 2019-07-17 15:43:53 +0300 | [diff] [blame] | 7151 | weston_log_subscription_printf(sub, "%s", str); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7152 | free(str); |
Marius Vlad | dad882a | 2019-07-17 15:43:53 +0300 | [diff] [blame] | 7153 | weston_log_subscription_complete(sub); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7154 | } |
| 7155 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7156 | /** Create the compositor. |
| 7157 | * |
| 7158 | * This functions creates and initializes a compositor instance. |
| 7159 | * |
| 7160 | * \param display The Wayland display to be used. |
| 7161 | * \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] | 7162 | * \param log_ctx A pointer to weston_debug_compositor |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7163 | * using the \ref weston_compositor_get_user_data function. |
| 7164 | * \return The compositor instance on success or NULL on failure. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7165 | * |
| 7166 | * \ingroup compositor |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7167 | */ |
| 7168 | WL_EXPORT struct weston_compositor * |
Marius Vlad | 880b485 | 2019-04-07 17:07:58 +0300 | [diff] [blame] | 7169 | weston_compositor_create(struct wl_display *display, |
Marius Vlad | 3d7d978 | 2019-04-17 12:35:38 +0300 | [diff] [blame] | 7170 | struct weston_log_context *log_ctx, |
Marius Vlad | 880b485 | 2019-04-07 17:07:58 +0300 | [diff] [blame] | 7171 | void *user_data) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 7172 | { |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7173 | struct weston_compositor *ec; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 7174 | struct wl_event_loop *loop; |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 7175 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7176 | ec = zalloc(sizeof *ec); |
| 7177 | if (!ec) |
| 7178 | return NULL; |
| 7179 | |
| 7180 | ec->wl_display = display; |
| 7181 | ec->user_data = user_data; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 7182 | wl_signal_init(&ec->destroy_signal); |
Kristian Høgsberg | f03a04a | 2014-04-06 22:04:50 -0700 | [diff] [blame] | 7183 | wl_signal_init(&ec->create_surface_signal); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 7184 | wl_signal_init(&ec->activate_signal); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 7185 | wl_signal_init(&ec->transform_signal); |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 7186 | wl_signal_init(&ec->kill_signal); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 7187 | wl_signal_init(&ec->idle_signal); |
| 7188 | wl_signal_init(&ec->wake_signal); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 7189 | wl_signal_init(&ec->show_input_panel_signal); |
| 7190 | wl_signal_init(&ec->hide_input_panel_signal); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 7191 | wl_signal_init(&ec->update_input_panel_signal); |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 7192 | wl_signal_init(&ec->seat_created_signal); |
Richard Hughes | 59d5da7 | 2013-05-01 21:52:11 +0100 | [diff] [blame] | 7193 | wl_signal_init(&ec->output_created_signal); |
Ander Conselvan de Oliveira | f84327a | 2014-01-29 18:47:51 +0200 | [diff] [blame] | 7194 | wl_signal_init(&ec->output_destroyed_signal); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 7195 | wl_signal_init(&ec->output_moved_signal); |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 7196 | wl_signal_init(&ec->output_resized_signal); |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 7197 | wl_signal_init(&ec->heads_changed_signal); |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 7198 | wl_signal_init(&ec->output_heads_changed_signal); |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 7199 | wl_signal_init(&ec->session_signal); |
Robert Beckett | c569bdc | 2019-07-10 16:40:12 +0100 | [diff] [blame] | 7200 | ec->session_active = true; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 7201 | |
Casey Dahlin | 58ba137 | 2012-04-19 22:50:08 -0400 | [diff] [blame] | 7202 | ec->output_id_pool = 0; |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 7203 | ec->repaint_msec = DEFAULT_REPAINT_WINDOW; |
Casey Dahlin | 58ba137 | 2012-04-19 22:50:08 -0400 | [diff] [blame] | 7204 | |
Jonas Ådahl | 94e2e2d | 2014-10-18 18:42:19 +0200 | [diff] [blame] | 7205 | ec->activate_serial = 1; |
| 7206 | |
Louis-Francis Ratté-Boulianne | c4689ff | 2017-11-28 20:42:47 -0500 | [diff] [blame] | 7207 | ec->touch_mode = WESTON_TOUCH_MODE_NORMAL; |
| 7208 | |
Ankit Nautiyal | 5cfe03c | 2019-03-28 15:05:42 +0530 | [diff] [blame] | 7209 | ec->content_protection = NULL; |
| 7210 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 7211 | if (!wl_global_create(ec->wl_display, &wl_compositor_interface, 4, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 7212 | ec, compositor_bind)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7213 | goto fail; |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 7214 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 7215 | if (!wl_global_create(ec->wl_display, &wl_subcompositor_interface, 1, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 7216 | ec, bind_subcompositor)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7217 | goto fail; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 7218 | |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 7219 | if (!wl_global_create(ec->wl_display, &wp_viewporter_interface, 1, |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 7220 | ec, bind_viewporter)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7221 | goto fail; |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 7222 | |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 7223 | if (!wl_global_create(ec->wl_display, &zxdg_output_manager_v1_interface, 2, |
| 7224 | ec, bind_xdg_output_manager)) |
| 7225 | goto fail; |
| 7226 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 7227 | if (!wl_global_create(ec->wl_display, &wp_presentation_interface, 1, |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 7228 | ec, bind_presentation)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7229 | goto fail; |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 7230 | |
Marius Vlad | 3d7d978 | 2019-04-17 12:35:38 +0300 | [diff] [blame] | 7231 | if (weston_log_ctx_compositor_setup(ec, log_ctx) < 0) |
Pekka Paalanen | a5630ea | 2017-10-12 13:13:42 +0200 | [diff] [blame] | 7232 | goto fail; |
| 7233 | |
Jonas Ådahl | 30d61d8 | 2014-10-22 21:21:17 +0200 | [diff] [blame] | 7234 | if (weston_input_init(ec) != 0) |
| 7235 | goto fail; |
| 7236 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 7237 | wl_list_init(&ec->view_list); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 7238 | wl_list_init(&ec->plane_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 7239 | wl_list_init(&ec->layer_list); |
| 7240 | wl_list_init(&ec->seat_list); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 7241 | wl_list_init(&ec->pending_output_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 7242 | wl_list_init(&ec->output_list); |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 7243 | wl_list_init(&ec->head_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 7244 | wl_list_init(&ec->key_binding_list); |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 7245 | wl_list_init(&ec->modifier_binding_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 7246 | wl_list_init(&ec->button_binding_list); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 7247 | wl_list_init(&ec->touch_binding_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 7248 | wl_list_init(&ec->axis_binding_list); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 7249 | wl_list_init(&ec->debug_binding_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 7250 | |
Pekka Paalanen | 827b5d2 | 2016-06-29 11:54:26 +0200 | [diff] [blame] | 7251 | wl_list_init(&ec->plugin_api_list); |
| 7252 | |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 7253 | weston_plane_init(&ec->primary_plane, ec, 0, 0); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 7254 | weston_compositor_stack_plane(ec, &ec->primary_plane, NULL); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 7255 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7256 | wl_data_device_manager_init(ec->wl_display); |
| 7257 | |
| 7258 | wl_display_init_shm(ec->wl_display); |
| 7259 | |
| 7260 | loop = wl_display_get_event_loop(ec->wl_display); |
| 7261 | ec->idle_source = wl_event_loop_add_timer(loop, idle_handler, ec); |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 7262 | ec->repaint_timer = |
| 7263 | wl_event_loop_add_timer(loop, output_repaint_timer_handler, |
| 7264 | ec); |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7265 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 7266 | weston_layer_init(&ec->fade_layer, ec); |
| 7267 | weston_layer_init(&ec->cursor_layer, ec); |
| 7268 | |
| 7269 | weston_layer_set_position(&ec->fade_layer, WESTON_LAYER_POSITION_FADE); |
| 7270 | weston_layer_set_position(&ec->cursor_layer, |
| 7271 | WESTON_LAYER_POSITION_CURSOR); |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7272 | |
| 7273 | weston_compositor_add_debug_binding(ec, KEY_T, |
| 7274 | timeline_key_binding_handler, ec); |
| 7275 | |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7276 | ec->debug_scene = |
Marius Vlad | 7e4db95 | 2019-04-17 13:47:06 +0300 | [diff] [blame] | 7277 | weston_compositor_add_log_scope(ec->weston_log_ctx, "scene-graph", |
| 7278 | "Scene graph details\n", |
| 7279 | debug_scene_graph_cb, |
| 7280 | ec); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7281 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7282 | return ec; |
| 7283 | |
| 7284 | fail: |
| 7285 | free(ec); |
| 7286 | return NULL; |
| 7287 | } |
| 7288 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7289 | /** weston_compositor_shutdown |
| 7290 | * \ingroup compositor |
| 7291 | */ |
Benjamin Franzke | b826302 | 2011-08-30 11:32:47 +0200 | [diff] [blame] | 7292 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 7293 | weston_compositor_shutdown(struct weston_compositor *ec) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 7294 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 7295 | struct weston_output *output, *next; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 7296 | |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 7297 | wl_event_source_remove(ec->idle_source); |
| 7298 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 7299 | /* Destroy all outputs associated with this compositor */ |
Tiago Vignatti | b303a1d | 2011-12-18 22:27:40 +0200 | [diff] [blame] | 7300 | wl_list_for_each_safe(output, next, &ec->output_list, link) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 7301 | output->destroy(output); |
Pekka Paalanen | 4738f3b | 2012-01-02 15:47:07 +0200 | [diff] [blame] | 7302 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 7303 | /* Destroy all pending outputs associated with this compositor */ |
| 7304 | wl_list_for_each_safe(output, next, &ec->pending_output_list, link) |
| 7305 | output->destroy(output); |
| 7306 | |
Ander Conselvan de Oliveira | 1853676 | 2013-12-20 21:07:00 +0200 | [diff] [blame] | 7307 | if (ec->renderer) |
| 7308 | ec->renderer->destroy(ec); |
| 7309 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 7310 | weston_binding_list_destroy_all(&ec->key_binding_list); |
Ryo Munakata | 27135af | 2015-07-17 13:07:42 +0900 | [diff] [blame] | 7311 | weston_binding_list_destroy_all(&ec->modifier_binding_list); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 7312 | weston_binding_list_destroy_all(&ec->button_binding_list); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 7313 | weston_binding_list_destroy_all(&ec->touch_binding_list); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 7314 | weston_binding_list_destroy_all(&ec->axis_binding_list); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 7315 | weston_binding_list_destroy_all(&ec->debug_binding_list); |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 7316 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 7317 | weston_plane_release(&ec->primary_plane); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 7318 | } |
| 7319 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7320 | /** weston_compositor_exit_with_code |
| 7321 | * \ingroup compositor |
| 7322 | */ |
Kristian Høgsberg | af4f2aa | 2013-02-15 20:53:20 -0500 | [diff] [blame] | 7323 | WL_EXPORT void |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7324 | weston_compositor_exit_with_code(struct weston_compositor *compositor, |
Frederic Plourde | c336f06 | 2014-10-29 14:44:33 -0400 | [diff] [blame] | 7325 | int exit_code) |
| 7326 | { |
Pekka Paalanen | f5ef88f | 2014-11-18 15:57:04 +0200 | [diff] [blame] | 7327 | if (compositor->exit_code == EXIT_SUCCESS) |
| 7328 | compositor->exit_code = exit_code; |
| 7329 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7330 | weston_compositor_exit(compositor); |
Frederic Plourde | c336f06 | 2014-10-29 14:44:33 -0400 | [diff] [blame] | 7331 | } |
| 7332 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7333 | /** weston_compositor_set_default_pointer_grab |
| 7334 | * \ingroup compositor |
| 7335 | */ |
Frederic Plourde | c336f06 | 2014-10-29 14:44:33 -0400 | [diff] [blame] | 7336 | WL_EXPORT void |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 7337 | weston_compositor_set_default_pointer_grab(struct weston_compositor *ec, |
| 7338 | const struct weston_pointer_grab_interface *interface) |
| 7339 | { |
| 7340 | struct weston_seat *seat; |
| 7341 | |
| 7342 | ec->default_pointer_grab = interface; |
| 7343 | wl_list_for_each(seat, &ec->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 7344 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 7345 | |
| 7346 | if (pointer) |
| 7347 | weston_pointer_set_default_grab(pointer, interface); |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 7348 | } |
| 7349 | } |
| 7350 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7351 | /** weston_compositor_set_presentation_clock |
| 7352 | * \ingroup compositor |
| 7353 | */ |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 7354 | WL_EXPORT int |
| 7355 | weston_compositor_set_presentation_clock(struct weston_compositor *compositor, |
| 7356 | clockid_t clk_id) |
| 7357 | { |
| 7358 | struct timespec ts; |
| 7359 | |
| 7360 | if (clock_gettime(clk_id, &ts) < 0) |
| 7361 | return -1; |
| 7362 | |
| 7363 | compositor->presentation_clock = clk_id; |
| 7364 | |
| 7365 | return 0; |
| 7366 | } |
| 7367 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7368 | /** For choosing the software clock, when the display hardware or API |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 7369 | * does not expose a compatible presentation timestamp. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7370 | * |
| 7371 | * \ingroup compositor |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 7372 | */ |
| 7373 | WL_EXPORT int |
| 7374 | weston_compositor_set_presentation_clock_software( |
| 7375 | struct weston_compositor *compositor) |
| 7376 | { |
| 7377 | /* In order of preference */ |
| 7378 | static const clockid_t clocks[] = { |
| 7379 | CLOCK_MONOTONIC_RAW, /* no jumps, no crawling */ |
| 7380 | CLOCK_MONOTONIC_COARSE, /* no jumps, may crawl, fast & coarse */ |
| 7381 | CLOCK_MONOTONIC, /* no jumps, may crawl */ |
| 7382 | CLOCK_REALTIME_COARSE, /* may jump and crawl, fast & coarse */ |
| 7383 | CLOCK_REALTIME /* may jump and crawl */ |
| 7384 | }; |
| 7385 | unsigned i; |
| 7386 | |
| 7387 | for (i = 0; i < ARRAY_LENGTH(clocks); i++) |
| 7388 | if (weston_compositor_set_presentation_clock(compositor, |
| 7389 | clocks[i]) == 0) |
| 7390 | return 0; |
| 7391 | |
| 7392 | weston_log("Error: no suitable presentation clock available.\n"); |
| 7393 | |
| 7394 | return -1; |
| 7395 | } |
| 7396 | |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 7397 | /** Read the current time from the Presentation clock |
| 7398 | * |
| 7399 | * \param compositor |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 7400 | * \param[out] ts The current time. |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 7401 | * |
| 7402 | * \note Reading the current time in user space is always imprecise to some |
| 7403 | * degree. |
| 7404 | * |
| 7405 | * This function is never meant to fail. If reading the clock does fail, |
| 7406 | * an error message is logged and a zero time is returned. Callers are not |
| 7407 | * supposed to detect or react to failures. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7408 | * |
| 7409 | * \ingroup compositor |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 7410 | */ |
| 7411 | WL_EXPORT void |
| 7412 | weston_compositor_read_presentation_clock( |
| 7413 | const struct weston_compositor *compositor, |
| 7414 | struct timespec *ts) |
| 7415 | { |
| 7416 | static bool warned; |
| 7417 | int ret; |
| 7418 | |
| 7419 | ret = clock_gettime(compositor->presentation_clock, ts); |
| 7420 | if (ret < 0) { |
| 7421 | ts->tv_sec = 0; |
| 7422 | ts->tv_nsec = 0; |
| 7423 | |
| 7424 | if (!warned) |
| 7425 | weston_log("Error: failure to read " |
Antonio Borneo | 3957863 | 2019-04-26 23:57:31 +0200 | [diff] [blame] | 7426 | "the presentation clock %#x: '%s' (%d)\n", |
| 7427 | compositor->presentation_clock, |
| 7428 | strerror(errno), errno); |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 7429 | warned = true; |
| 7430 | } |
| 7431 | } |
| 7432 | |
Pekka Paalanen | 230f3b1 | 2014-09-29 14:18:40 -0400 | [diff] [blame] | 7433 | /** Import dmabuf buffer into current renderer |
| 7434 | * |
| 7435 | * \param compositor |
| 7436 | * \param buffer the dmabuf buffer to import |
| 7437 | * \return true on usable buffers, false otherwise |
| 7438 | * |
| 7439 | * This function tests that the linux_dmabuf_buffer is usable |
| 7440 | * for the current renderer. Returns false on unusable buffers. Usually |
| 7441 | * usability is tested by importing the dmabufs for composition. |
| 7442 | * |
| 7443 | * This hook is also used for detecting if the renderer supports |
| 7444 | * dmabufs at all. If the renderer hook is NULL, dmabufs are not |
| 7445 | * supported. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7446 | * |
| 7447 | * \ingroup compositor |
| 7448 | */ |
Pekka Paalanen | 230f3b1 | 2014-09-29 14:18:40 -0400 | [diff] [blame] | 7449 | WL_EXPORT bool |
| 7450 | weston_compositor_import_dmabuf(struct weston_compositor *compositor, |
| 7451 | struct linux_dmabuf_buffer *buffer) |
| 7452 | { |
| 7453 | struct weston_renderer *renderer; |
| 7454 | |
| 7455 | renderer = compositor->renderer; |
| 7456 | |
| 7457 | if (renderer->import_dmabuf == NULL) |
| 7458 | return false; |
| 7459 | |
| 7460 | return renderer->import_dmabuf(compositor, buffer); |
| 7461 | } |
| 7462 | |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 7463 | WL_EXPORT void |
Kristian Høgsberg | af4f2aa | 2013-02-15 20:53:20 -0500 | [diff] [blame] | 7464 | weston_version(int *major, int *minor, int *micro) |
| 7465 | { |
| 7466 | *major = WESTON_VERSION_MAJOR; |
| 7467 | *minor = WESTON_VERSION_MINOR; |
| 7468 | *micro = WESTON_VERSION_MICRO; |
| 7469 | } |
| 7470 | |
Daniel Stone | e03c111 | 2016-11-24 20:45:45 +0000 | [diff] [blame] | 7471 | /** |
| 7472 | * Attempts to find a module path from the module map specified in the |
| 7473 | * environment. If found, writes the full path into the path variable. |
| 7474 | * |
| 7475 | * The module map is a string in environment variable WESTON_MODULE_MAP, where |
| 7476 | * each entry is of the form "name=path" and entries are separated by |
| 7477 | * semicolons. Whitespace is significant. |
| 7478 | * |
| 7479 | * \param name The name to search for. |
| 7480 | * \param path Where the path is written to if found. |
| 7481 | * \param path_len Allocated bytes at \c path . |
| 7482 | * \returns The length of the string written to path on success, or 0 if the |
| 7483 | * module was not specified in the environment map or path_len was too small. |
| 7484 | */ |
| 7485 | WL_EXPORT size_t |
| 7486 | weston_module_path_from_env(const char *name, char *path, size_t path_len) |
| 7487 | { |
| 7488 | const char *mapping = getenv("WESTON_MODULE_MAP"); |
| 7489 | const char *end; |
| 7490 | const int name_len = strlen(name); |
| 7491 | |
| 7492 | if (!mapping) |
| 7493 | return 0; |
| 7494 | |
| 7495 | end = mapping + strlen(mapping); |
| 7496 | while (mapping < end && *mapping) { |
| 7497 | const char *filename, *next; |
| 7498 | |
| 7499 | /* early out: impossibly short string */ |
| 7500 | if (end - mapping < name_len + 1) |
| 7501 | return 0; |
| 7502 | |
| 7503 | filename = &mapping[name_len + 1]; |
| 7504 | next = strchrnul(mapping, ';'); |
| 7505 | |
| 7506 | if (strncmp(mapping, name, name_len) == 0 && |
| 7507 | mapping[name_len] == '=') { |
| 7508 | size_t file_len = next - filename; /* no trailing NUL */ |
| 7509 | if (file_len >= path_len) |
| 7510 | return 0; |
| 7511 | strncpy(path, filename, file_len); |
| 7512 | path[file_len] = '\0'; |
| 7513 | return file_len; |
| 7514 | } |
| 7515 | |
| 7516 | mapping = next + 1; |
| 7517 | } |
| 7518 | |
| 7519 | return 0; |
| 7520 | } |
| 7521 | |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 7522 | WL_EXPORT void * |
| 7523 | weston_load_module(const char *name, const char *entrypoint) |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 7524 | { |
| 7525 | char path[PATH_MAX]; |
| 7526 | void *module, *init; |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 7527 | size_t len; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 7528 | |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 7529 | if (name == NULL) |
| 7530 | return NULL; |
| 7531 | |
Derek Foreman | 3f86e50 | 2015-06-08 11:46:54 -0500 | [diff] [blame] | 7532 | if (name[0] != '/') { |
Daniel Stone | e03c111 | 2016-11-24 20:45:45 +0000 | [diff] [blame] | 7533 | len = weston_module_path_from_env(name, path, sizeof path); |
| 7534 | if (len == 0) |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 7535 | len = snprintf(path, sizeof path, "%s/%s", |
| 7536 | LIBWESTON_MODULEDIR, name); |
Derek Foreman | 3f86e50 | 2015-06-08 11:46:54 -0500 | [diff] [blame] | 7537 | } else { |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 7538 | len = snprintf(path, sizeof path, "%s", name); |
Derek Foreman | 3f86e50 | 2015-06-08 11:46:54 -0500 | [diff] [blame] | 7539 | } |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 7540 | |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 7541 | /* snprintf returns the length of the string it would've written, |
| 7542 | * _excluding_ the NUL byte. So even being equal to the size of |
| 7543 | * our buffer is an error here. */ |
| 7544 | if (len >= sizeof path) |
| 7545 | return NULL; |
| 7546 | |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 7547 | module = dlopen(path, RTLD_NOW | RTLD_NOLOAD); |
| 7548 | if (module) { |
| 7549 | weston_log("Module '%s' already loaded\n", path); |
| 7550 | dlclose(module); |
| 7551 | return NULL; |
| 7552 | } |
| 7553 | |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 7554 | weston_log("Loading module '%s'\n", path); |
Kristian Høgsberg | 1acd9f8 | 2012-07-26 11:39:26 -0400 | [diff] [blame] | 7555 | module = dlopen(path, RTLD_NOW); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 7556 | if (!module) { |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 7557 | weston_log("Failed to load module: %s\n", dlerror()); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 7558 | return NULL; |
| 7559 | } |
| 7560 | |
| 7561 | init = dlsym(module, entrypoint); |
| 7562 | if (!init) { |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 7563 | weston_log("Failed to lookup init function: %s\n", dlerror()); |
Rob Bradford | c9e64ab | 2012-12-05 18:47:10 +0000 | [diff] [blame] | 7564 | dlclose(module); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 7565 | return NULL; |
| 7566 | } |
| 7567 | |
| 7568 | return init; |
| 7569 | } |
| 7570 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7571 | |
Marius Vlad | 284d534 | 2019-06-24 12:00:47 +0300 | [diff] [blame^] | 7572 | /** Tear down the compositor. |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7573 | * |
Marius Vlad | 284d534 | 2019-06-24 12:00:47 +0300 | [diff] [blame^] | 7574 | * This function cleans up the compositor state. While the compositor state has |
| 7575 | * been cleaned do note that **only** weston_compositor_destroy() can be called |
| 7576 | * afterwards, in order to destroy the compositor instance. |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7577 | * |
Marius Vlad | 284d534 | 2019-06-24 12:00:47 +0300 | [diff] [blame^] | 7578 | * @param compositor The compositor to be tear-down/cleaned. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7579 | * |
Marius Vlad | 284d534 | 2019-06-24 12:00:47 +0300 | [diff] [blame^] | 7580 | * @ingroup compositor |
| 7581 | * @sa weston_compositor_destroy |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7582 | */ |
| 7583 | WL_EXPORT void |
Marius Vlad | 284d534 | 2019-06-24 12:00:47 +0300 | [diff] [blame^] | 7584 | weston_compositor_tear_down(struct weston_compositor *compositor) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7585 | { |
| 7586 | /* prevent further rendering while shutting down */ |
| 7587 | compositor->state = WESTON_COMPOSITOR_OFFSCREEN; |
| 7588 | |
| 7589 | wl_signal_emit(&compositor->destroy_signal, compositor); |
| 7590 | |
| 7591 | weston_compositor_xkb_destroy(compositor); |
| 7592 | |
Giulio Camuffo | 2d24e64 | 2015-10-03 16:25:15 +0300 | [diff] [blame] | 7593 | if (compositor->backend) |
| 7594 | compositor->backend->destroy(compositor); |
Pekka Paalanen | 827b5d2 | 2016-06-29 11:54:26 +0200 | [diff] [blame] | 7595 | |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 7596 | /* The backend is responsible for destroying the heads. */ |
| 7597 | assert(wl_list_empty(&compositor->head_list)); |
| 7598 | |
Pekka Paalanen | 827b5d2 | 2016-06-29 11:54:26 +0200 | [diff] [blame] | 7599 | weston_plugin_api_destroy_list(compositor); |
| 7600 | |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 7601 | if (compositor->heads_changed_source) |
| 7602 | wl_event_source_remove(compositor->heads_changed_source); |
| 7603 | |
Marius Vlad | 7e4db95 | 2019-04-17 13:47:06 +0300 | [diff] [blame] | 7604 | weston_compositor_log_scope_destroy(compositor->debug_scene); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7605 | compositor->debug_scene = NULL; |
Marius Vlad | 284d534 | 2019-06-24 12:00:47 +0300 | [diff] [blame^] | 7606 | } |
Pekka Paalanen | a5630ea | 2017-10-12 13:13:42 +0200 | [diff] [blame] | 7607 | |
Marius Vlad | 284d534 | 2019-06-24 12:00:47 +0300 | [diff] [blame^] | 7608 | /** Destroys the compositor. |
| 7609 | * |
| 7610 | * This function destroys the compositor. **Do not** call this before |
| 7611 | * calling weston_compositor_tear_down() |
| 7612 | * |
| 7613 | * @param compositor The compositor to be destroyed. |
| 7614 | * @ingroup compositor |
| 7615 | * @sa weston_compositor_tear_down() |
| 7616 | */ |
| 7617 | WL_EXPORT void |
| 7618 | weston_compositor_destroy(struct weston_compositor *compositor) |
| 7619 | { |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7620 | free(compositor); |
| 7621 | } |
| 7622 | |
| 7623 | /** Instruct the compositor to exit. |
| 7624 | * |
| 7625 | * This functions does not directly destroy the compositor object, it merely |
| 7626 | * command it to start the tear down process. It is not guaranteed that the |
| 7627 | * tear down will happen immediately. |
| 7628 | * |
| 7629 | * \param compositor The compositor to tear down. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7630 | * |
| 7631 | * \ingroup compositor |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7632 | */ |
| 7633 | WL_EXPORT void |
| 7634 | weston_compositor_exit(struct weston_compositor *compositor) |
| 7635 | { |
| 7636 | compositor->exit(compositor); |
| 7637 | } |
| 7638 | |
| 7639 | /** Return the user data stored in the compositor. |
| 7640 | * |
| 7641 | * This function returns the user data pointer set with user_data parameter |
| 7642 | * to the \ref weston_compositor_create function. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7643 | * |
| 7644 | * \ingroup compositor |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7645 | */ |
| 7646 | WL_EXPORT void * |
| 7647 | weston_compositor_get_user_data(struct weston_compositor *compositor) |
| 7648 | { |
| 7649 | return compositor->user_data; |
| 7650 | } |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 7651 | |
Pekka Paalanen | 50dbf38 | 2016-06-03 15:23:46 +0300 | [diff] [blame] | 7652 | static const char * const backend_map[] = { |
| 7653 | [WESTON_BACKEND_DRM] = "drm-backend.so", |
| 7654 | [WESTON_BACKEND_FBDEV] = "fbdev-backend.so", |
| 7655 | [WESTON_BACKEND_HEADLESS] = "headless-backend.so", |
| 7656 | [WESTON_BACKEND_RDP] = "rdp-backend.so", |
| 7657 | [WESTON_BACKEND_WAYLAND] = "wayland-backend.so", |
| 7658 | [WESTON_BACKEND_X11] = "x11-backend.so", |
| 7659 | }; |
| 7660 | |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 7661 | /** Load a backend into a weston_compositor |
| 7662 | * |
| 7663 | * A backend must be loaded to make a weston_compositor work. A backend |
| 7664 | * provides input and output capabilities, and determines the renderer to use. |
| 7665 | * |
| 7666 | * \param compositor A compositor that has not had a backend loaded yet. |
| 7667 | * \param backend Name of the backend file. |
| 7668 | * \param config_base A pointer to a backend-specific configuration |
| 7669 | * structure's 'base' member. |
| 7670 | * |
| 7671 | * \return 0 on success, or -1 on error. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7672 | * |
| 7673 | * \ingroup compositor |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 7674 | */ |
| 7675 | WL_EXPORT int |
| 7676 | weston_compositor_load_backend(struct weston_compositor *compositor, |
Pekka Paalanen | 50dbf38 | 2016-06-03 15:23:46 +0300 | [diff] [blame] | 7677 | enum weston_compositor_backend backend, |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 7678 | struct weston_backend_config *config_base) |
| 7679 | { |
| 7680 | int (*backend_init)(struct weston_compositor *c, |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 7681 | struct weston_backend_config *config_base); |
| 7682 | |
Pekka Paalanen | d7e3511 | 2017-08-29 17:04:12 +0300 | [diff] [blame] | 7683 | if (compositor->backend) { |
| 7684 | weston_log("Error: attempt to load a backend when one is already loaded\n"); |
| 7685 | return -1; |
| 7686 | } |
| 7687 | |
Quentin Glidic | 887c018 | 2016-07-10 11:00:53 +0200 | [diff] [blame] | 7688 | if (backend >= ARRAY_LENGTH(backend_map)) |
Pekka Paalanen | 50dbf38 | 2016-06-03 15:23:46 +0300 | [diff] [blame] | 7689 | return -1; |
| 7690 | |
Quentin Glidic | 23e1d6f | 2016-12-02 14:08:44 +0100 | [diff] [blame] | 7691 | backend_init = weston_load_module(backend_map[backend], "weston_backend_init"); |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 7692 | if (!backend_init) |
| 7693 | return -1; |
| 7694 | |
Pekka Paalanen | d7e3511 | 2017-08-29 17:04:12 +0300 | [diff] [blame] | 7695 | if (backend_init(compositor, config_base) < 0) { |
| 7696 | compositor->backend = NULL; |
| 7697 | return -1; |
| 7698 | } |
| 7699 | |
| 7700 | return 0; |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 7701 | } |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 7702 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7703 | /** weston_compositor_load_xwayland |
| 7704 | * \ingroup compositor |
| 7705 | */ |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 7706 | WL_EXPORT int |
| 7707 | weston_compositor_load_xwayland(struct weston_compositor *compositor) |
| 7708 | { |
Quentin Glidic | 3d7ca3b | 2016-12-02 14:20:35 +0100 | [diff] [blame] | 7709 | int (*module_init)(struct weston_compositor *ec); |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 7710 | |
Quentin Glidic | 3d7ca3b | 2016-12-02 14:20:35 +0100 | [diff] [blame] | 7711 | module_init = weston_load_module("xwayland.so", "weston_module_init"); |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 7712 | if (!module_init) |
| 7713 | return -1; |
Quentin Glidic | 3d7ca3b | 2016-12-02 14:20:35 +0100 | [diff] [blame] | 7714 | if (module_init(compositor) < 0) |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 7715 | return -1; |
| 7716 | return 0; |
| 7717 | } |
Vasilis Liaskovitis | 486b463 | 2018-10-10 16:14:55 +0200 | [diff] [blame] | 7718 | |
| 7719 | /** Resolve an internal compositor error by disconnecting the client. |
| 7720 | * |
| 7721 | * This function is used in cases when the wl_buffer turns out |
| 7722 | * unusable and there is no fallback path. |
| 7723 | * |
| 7724 | * It is possible the fault is caused by a compositor bug, the underlying |
| 7725 | * graphics stack bug or normal behaviour, or perhaps a client mistake. |
| 7726 | * In any case, the options are to either composite garbage or nothing, |
| 7727 | * or disconnect the client. This is a helper function for the latter. |
| 7728 | * |
| 7729 | * The error is sent as an INVALID_OBJECT error on the client's wl_display. |
| 7730 | * |
| 7731 | * \param buffer The weston buffer that is unusable. |
| 7732 | * \param msg A custom error message attached to the protocol error. |
| 7733 | */ |
| 7734 | WL_EXPORT void |
| 7735 | weston_buffer_send_server_error(struct weston_buffer *buffer, |
| 7736 | const char *msg) |
| 7737 | { |
| 7738 | struct wl_client *client; |
| 7739 | struct wl_resource *display_resource; |
| 7740 | uint32_t id; |
| 7741 | |
| 7742 | assert(buffer->resource); |
| 7743 | id = wl_resource_get_id(buffer->resource); |
| 7744 | client = wl_resource_get_client(buffer->resource); |
| 7745 | display_resource = wl_client_get_object(client, 1); |
| 7746 | |
| 7747 | assert(display_resource); |
| 7748 | wl_resource_post_error(display_resource, |
| 7749 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 7750 | "server error with " |
| 7751 | "wl_buffer@%u: %s", id, msg); |
| 7752 | } |