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 | 1a4f87d | 2021-04-30 14:48:52 +0300 | [diff] [blame] | 4 | * Copyright © 2012-2018, 2021 Collabora, Ltd. |
Pekka Paalanen | 925788f | 2018-04-19 14:20:01 +0300 | [diff] [blame] | 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" |
Alexandros Frantzis | fa48c5e | 2020-07-09 17:31:34 +0300 | [diff] [blame] | 71 | #include "shared/signal.h" |
Kristian Høgsberg | a411c8b | 2012-06-08 16:16:52 -0400 | [diff] [blame] | 72 | #include "git-version.h" |
Pekka Paalanen | cda1488 | 2019-04-04 15:41:02 +0300 | [diff] [blame] | 73 | #include <libweston/version.h> |
Pekka Paalanen | 27b377f | 2019-03-29 17:07:34 +0200 | [diff] [blame] | 74 | #include <libweston/plugin-registry.h> |
Marius Vlad | 00a6e01 | 2018-11-20 17:52:31 +0200 | [diff] [blame] | 75 | #include "pixel-formats.h" |
Marius Vlad | 63ef078 | 2019-07-16 23:34:14 +0300 | [diff] [blame] | 76 | #include "backend.h" |
Marius Vlad | a72e371 | 2019-07-10 13:46:39 +0300 | [diff] [blame] | 77 | #include "libweston-internal.h" |
Pekka Paalanen | 90a5ffa | 2021-02-25 12:03:28 +0200 | [diff] [blame] | 78 | #include "color.h" |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 79 | |
Marius Vlad | 4e03629 | 2019-07-09 00:36:20 +0300 | [diff] [blame] | 80 | #include "weston-log-internal.h" |
| 81 | |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 82 | #include "../aml-weston/aml-compositor.c" |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 83 | /** |
| 84 | * \defgroup head Head |
| 85 | * \defgroup output Output |
| 86 | * \defgroup compositor Compositor |
| 87 | */ |
| 88 | |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 89 | #define DEFAULT_REPAINT_WINDOW 7 /* milliseconds */ |
| 90 | |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 91 | static void |
Pekka Paalanen | d72bad2 | 2017-03-29 17:01:41 +0300 | [diff] [blame] | 92 | weston_output_update_matrix(struct weston_output *output); |
| 93 | |
| 94 | static void |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 95 | weston_output_transform_scale_init(struct weston_output *output, |
| 96 | uint32_t transform, uint32_t scale); |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 97 | |
Rob Bradford | 27b1793 | 2013-06-26 18:08:46 +0100 | [diff] [blame] | 98 | static void |
Pekka Paalanen | 1a4f87d | 2021-04-30 14:48:52 +0300 | [diff] [blame] | 99 | weston_compositor_build_view_list(struct weston_compositor *compositor, |
| 100 | struct weston_output *output); |
Rob Bradford | 27b1793 | 2013-06-26 18:08:46 +0100 | [diff] [blame] | 101 | |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 102 | static char * |
| 103 | weston_output_create_heads_string(struct weston_output *output); |
| 104 | |
Pekka Paalanen | 1a4f87d | 2021-04-30 14:48:52 +0300 | [diff] [blame] | 105 | static struct weston_paint_node * |
| 106 | weston_paint_node_create(struct weston_surface *surface, |
| 107 | struct weston_view *view, |
| 108 | struct weston_output *output) |
| 109 | { |
| 110 | struct weston_paint_node *pnode; |
Pekka Paalanen | 90a5ffa | 2021-02-25 12:03:28 +0200 | [diff] [blame] | 111 | struct weston_paint_node *existing_node; |
Pekka Paalanen | 1a4f87d | 2021-04-30 14:48:52 +0300 | [diff] [blame] | 112 | |
| 113 | assert(view->surface == surface); |
| 114 | |
| 115 | pnode = zalloc(sizeof *pnode); |
| 116 | if (!pnode) |
| 117 | return NULL; |
| 118 | |
Pekka Paalanen | 90a5ffa | 2021-02-25 12:03:28 +0200 | [diff] [blame] | 119 | /* |
| 120 | * Invariant: all paint nodes with the same surface+output have the |
| 121 | * same surf_xform state. |
| 122 | */ |
Pekka Paalanen | 26b04f0 | 2022-01-24 13:09:01 +0200 | [diff] [blame] | 123 | wl_list_for_each(existing_node, &surface->paint_node_list, surface_link) { |
Pekka Paalanen | 90a5ffa | 2021-02-25 12:03:28 +0200 | [diff] [blame] | 124 | assert(existing_node->surface == surface); |
| 125 | if (existing_node->output != output) |
| 126 | continue; |
| 127 | |
| 128 | weston_surface_color_transform_copy(&pnode->surf_xform, |
| 129 | &existing_node->surf_xform); |
| 130 | pnode->surf_xform_valid = existing_node->surf_xform_valid; |
| 131 | break; |
| 132 | } |
| 133 | |
Pekka Paalanen | 1a4f87d | 2021-04-30 14:48:52 +0300 | [diff] [blame] | 134 | pnode->surface = surface; |
| 135 | wl_list_insert(&surface->paint_node_list, &pnode->surface_link); |
| 136 | |
| 137 | pnode->view = view; |
| 138 | wl_list_insert(&view->paint_node_list, &pnode->view_link); |
| 139 | |
| 140 | pnode->output = output; |
| 141 | wl_list_insert(&output->paint_node_list, &pnode->output_link); |
| 142 | |
Pekka Paalanen | 2fddc53 | 2021-04-30 17:41:29 +0300 | [diff] [blame] | 143 | wl_list_init(&pnode->z_order_link); |
| 144 | |
Pekka Paalanen | 1a4f87d | 2021-04-30 14:48:52 +0300 | [diff] [blame] | 145 | return pnode; |
| 146 | } |
| 147 | |
| 148 | static void |
| 149 | weston_paint_node_destroy(struct weston_paint_node *pnode) |
| 150 | { |
| 151 | assert(pnode->view->surface == pnode->surface); |
| 152 | wl_list_remove(&pnode->surface_link); |
| 153 | wl_list_remove(&pnode->view_link); |
| 154 | wl_list_remove(&pnode->output_link); |
Pekka Paalanen | 2fddc53 | 2021-04-30 17:41:29 +0300 | [diff] [blame] | 155 | wl_list_remove(&pnode->z_order_link); |
Pekka Paalanen | 90a5ffa | 2021-02-25 12:03:28 +0200 | [diff] [blame] | 156 | assert(pnode->surf_xform_valid || !pnode->surf_xform.transform); |
| 157 | weston_surface_color_transform_fini(&pnode->surf_xform); |
Pekka Paalanen | 1a4f87d | 2021-04-30 14:48:52 +0300 | [diff] [blame] | 158 | free(pnode); |
| 159 | } |
| 160 | |
Pekka Paalanen | 6528c03 | 2017-03-28 15:27:10 +0300 | [diff] [blame] | 161 | /** Send wl_output events for mode and scale changes |
| 162 | * |
| 163 | * \param head Send on all resources bound to this head. |
| 164 | * \param mode_changed If true, send the current mode. |
| 165 | * \param scale_changed If true, send the current scale. |
| 166 | */ |
| 167 | static void |
| 168 | weston_mode_switch_send_events(struct weston_head *head, |
| 169 | bool mode_changed, bool scale_changed) |
| 170 | { |
| 171 | struct weston_output *output = head->output; |
| 172 | struct wl_resource *resource; |
| 173 | int version; |
| 174 | |
| 175 | wl_resource_for_each(resource, &head->resource_list) { |
| 176 | if (mode_changed) { |
| 177 | wl_output_send_mode(resource, |
| 178 | output->current_mode->flags, |
| 179 | output->current_mode->width, |
| 180 | output->current_mode->height, |
| 181 | output->current_mode->refresh); |
| 182 | } |
| 183 | |
| 184 | version = wl_resource_get_version(resource); |
| 185 | if (version >= WL_OUTPUT_SCALE_SINCE_VERSION && scale_changed) |
| 186 | wl_output_send_scale(resource, output->current_scale); |
| 187 | |
| 188 | if (version >= WL_OUTPUT_DONE_SINCE_VERSION) |
| 189 | wl_output_send_done(resource); |
| 190 | } |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 191 | wl_resource_for_each(resource, &head->xdg_output_resource_list) { |
| 192 | zxdg_output_v1_send_logical_position(resource, |
| 193 | output->x, |
| 194 | output->y); |
| 195 | zxdg_output_v1_send_logical_size(resource, |
| 196 | output->width, |
| 197 | output->height); |
| 198 | zxdg_output_v1_send_done(resource); |
| 199 | } |
Pekka Paalanen | 6528c03 | 2017-03-28 15:27:10 +0300 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | static void |
| 203 | weston_mode_switch_finish(struct weston_output *output, |
| 204 | int mode_changed, int scale_changed) |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 205 | { |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 206 | struct weston_seat *seat; |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 207 | struct weston_head *head; |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 208 | pixman_region32_t old_output_region; |
Alexander Larsson | 355748e | 2013-05-28 16:23:38 +0200 | [diff] [blame] | 209 | |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 210 | pixman_region32_init(&old_output_region); |
| 211 | pixman_region32_copy(&old_output_region, &output->region); |
| 212 | |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 213 | /* Update output region and transformation matrix */ |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 214 | 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] | 215 | |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 216 | pixman_region32_init_rect(&output->region, output->x, output->y, |
| 217 | output->width, output->height); |
| 218 | |
| 219 | weston_output_update_matrix(output); |
| 220 | |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 221 | /* If a pointer falls outside the outputs new geometry, move it to its |
| 222 | * lower-right corner */ |
| 223 | wl_list_for_each(seat, &output->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 224 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 225 | int32_t x, y; |
| 226 | |
| 227 | if (!pointer) |
| 228 | continue; |
| 229 | |
| 230 | x = wl_fixed_to_int(pointer->x); |
| 231 | y = wl_fixed_to_int(pointer->y); |
| 232 | |
| 233 | if (!pixman_region32_contains_point(&old_output_region, |
| 234 | x, y, NULL) || |
| 235 | pixman_region32_contains_point(&output->region, |
| 236 | x, y, NULL)) |
| 237 | continue; |
| 238 | |
| 239 | if (x >= output->x + output->width) |
| 240 | x = output->x + output->width - 1; |
| 241 | if (y >= output->y + output->height) |
| 242 | y = output->y + output->height - 1; |
| 243 | |
| 244 | pointer->x = wl_fixed_from_int(x); |
| 245 | pointer->y = wl_fixed_from_int(y); |
| 246 | } |
| 247 | |
| 248 | pixman_region32_fini(&old_output_region); |
| 249 | |
Derek Foreman | dd4cd33 | 2014-11-10 10:29:59 -0600 | [diff] [blame] | 250 | if (!mode_changed && !scale_changed) |
| 251 | return; |
| 252 | |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 253 | /* notify clients of the changes */ |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 254 | wl_list_for_each(head, &output->head_list, output_link) |
| 255 | weston_mode_switch_send_events(head, |
| 256 | mode_changed, scale_changed); |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 257 | } |
| 258 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 259 | static void |
| 260 | weston_compositor_reflow_outputs(struct weston_compositor *compositor, |
| 261 | struct weston_output *resized_output, int delta_width); |
| 262 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 263 | /** |
| 264 | * \ingroup output |
| 265 | */ |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 266 | WL_EXPORT int |
| 267 | weston_output_mode_set_native(struct weston_output *output, |
| 268 | struct weston_mode *mode, |
| 269 | int32_t scale) |
| 270 | { |
| 271 | int ret; |
| 272 | int mode_changed = 0, scale_changed = 0; |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 273 | int32_t old_width; |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 274 | |
| 275 | if (!output->switch_mode) |
| 276 | return -1; |
| 277 | |
| 278 | if (!output->original_mode) { |
| 279 | mode_changed = 1; |
| 280 | ret = output->switch_mode(output, mode); |
| 281 | if (ret < 0) |
| 282 | return ret; |
| 283 | if (output->current_scale != scale) { |
| 284 | scale_changed = 1; |
| 285 | output->current_scale = scale; |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 286 | } |
| 287 | } |
| 288 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 289 | old_width = output->width; |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 290 | output->native_mode = mode; |
| 291 | output->native_scale = scale; |
| 292 | |
| 293 | weston_mode_switch_finish(output, mode_changed, scale_changed); |
| 294 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 295 | if (mode_changed || scale_changed) { |
| 296 | weston_compositor_reflow_outputs(output->compositor, output, output->width - old_width); |
| 297 | |
| 298 | wl_signal_emit(&output->compositor->output_resized_signal, output); |
| 299 | } |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 300 | return 0; |
| 301 | } |
| 302 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 303 | /** |
| 304 | * \ingroup output |
| 305 | */ |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 306 | WL_EXPORT int |
| 307 | weston_output_mode_switch_to_native(struct weston_output *output) |
| 308 | { |
| 309 | int ret; |
| 310 | int mode_changed = 0, scale_changed = 0; |
| 311 | |
| 312 | if (!output->switch_mode) |
| 313 | return -1; |
| 314 | |
| 315 | if (!output->original_mode) { |
| 316 | weston_log("already in the native mode\n"); |
| 317 | return -1; |
| 318 | } |
| 319 | /* the non fullscreen clients haven't seen a mode set since we |
| 320 | * switched into a temporary, so we need to notify them if the |
| 321 | * mode at that time is different from the native mode now. |
| 322 | */ |
| 323 | mode_changed = (output->original_mode != output->native_mode); |
| 324 | scale_changed = (output->original_scale != output->native_scale); |
| 325 | |
| 326 | ret = output->switch_mode(output, output->native_mode); |
| 327 | if (ret < 0) |
| 328 | return ret; |
| 329 | |
| 330 | output->current_scale = output->native_scale; |
| 331 | |
| 332 | output->original_mode = NULL; |
| 333 | output->original_scale = 0; |
| 334 | |
| 335 | weston_mode_switch_finish(output, mode_changed, scale_changed); |
| 336 | |
| 337 | return 0; |
| 338 | } |
| 339 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 340 | /** |
| 341 | * \ingroup output |
| 342 | */ |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 343 | WL_EXPORT int |
| 344 | weston_output_mode_switch_to_temporary(struct weston_output *output, |
| 345 | struct weston_mode *mode, |
| 346 | int32_t scale) |
| 347 | { |
| 348 | int ret; |
| 349 | |
| 350 | if (!output->switch_mode) |
| 351 | return -1; |
| 352 | |
| 353 | /* original_mode is the last mode non full screen clients have seen, |
| 354 | * so we shouldn't change it if we already have one set. |
| 355 | */ |
| 356 | if (!output->original_mode) { |
| 357 | output->original_mode = output->native_mode; |
| 358 | output->original_scale = output->native_scale; |
| 359 | } |
| 360 | ret = output->switch_mode(output, mode); |
| 361 | if (ret < 0) |
| 362 | return ret; |
| 363 | |
| 364 | output->current_scale = scale; |
| 365 | |
| 366 | weston_mode_switch_finish(output, 0, 0); |
| 367 | |
| 368 | return 0; |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 369 | } |
| 370 | |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 371 | static void |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 372 | region_init_infinite(pixman_region32_t *region) |
| 373 | { |
| 374 | pixman_region32_init_rect(region, INT32_MIN, INT32_MIN, |
| 375 | UINT32_MAX, UINT32_MAX); |
| 376 | } |
| 377 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 378 | static struct weston_subsurface * |
| 379 | weston_surface_to_subsurface(struct weston_surface *surface); |
| 380 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 381 | WL_EXPORT struct weston_view * |
| 382 | weston_view_create(struct weston_surface *surface) |
| 383 | { |
| 384 | struct weston_view *view; |
| 385 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 386 | view = zalloc(sizeof *view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 387 | if (view == NULL) |
| 388 | return NULL; |
| 389 | |
| 390 | view->surface = surface; |
Daniel Stone | fb4869d | 2016-12-09 16:27:54 +0000 | [diff] [blame] | 391 | view->plane = &surface->compositor->primary_plane; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 392 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 393 | /* Assign to surface */ |
| 394 | wl_list_insert(&surface->views, &view->surface_link); |
| 395 | |
| 396 | wl_signal_init(&view->destroy_signal); |
| 397 | wl_list_init(&view->link); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 398 | wl_list_init(&view->layer_link.link); |
Pekka Paalanen | 1a4f87d | 2021-04-30 14:48:52 +0300 | [diff] [blame] | 399 | wl_list_init(&view->paint_node_list); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 400 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 401 | pixman_region32_init(&view->clip); |
| 402 | |
| 403 | view->alpha = 1.0; |
leng.fang | dbaf6fa | 2024-06-20 19:31:04 +0800 | [diff] [blame] | 404 | view->visible = true; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 405 | pixman_region32_init(&view->transform.opaque); |
| 406 | |
| 407 | wl_list_init(&view->geometry.transformation_list); |
| 408 | wl_list_insert(&view->geometry.transformation_list, |
| 409 | &view->transform.position.link); |
| 410 | weston_matrix_init(&view->transform.position.matrix); |
| 411 | wl_list_init(&view->geometry.child_list); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 412 | pixman_region32_init(&view->geometry.scissor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 413 | pixman_region32_init(&view->transform.boundingbox); |
| 414 | view->transform.dirty = 1; |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 415 | #ifdef MESON_VIDEO_PLAN_SUPPORT |
| 416 | pixman_region32_init(&view->transform.transparent); |
| 417 | #endif |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 418 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 419 | return view; |
| 420 | } |
| 421 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 422 | struct weston_presentation_feedback { |
| 423 | struct wl_resource *resource; |
| 424 | |
| 425 | /* XXX: could use just wl_resource_get_link() instead */ |
| 426 | struct wl_list link; |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 427 | |
| 428 | /* The per-surface feedback flags */ |
| 429 | uint32_t psf_flags; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 430 | }; |
| 431 | |
| 432 | static void |
| 433 | weston_presentation_feedback_discard( |
| 434 | struct weston_presentation_feedback *feedback) |
| 435 | { |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 436 | wp_presentation_feedback_send_discarded(feedback->resource); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 437 | wl_resource_destroy(feedback->resource); |
| 438 | } |
| 439 | |
| 440 | static void |
| 441 | weston_presentation_feedback_discard_list(struct wl_list *list) |
| 442 | { |
| 443 | struct weston_presentation_feedback *feedback, *tmp; |
| 444 | |
| 445 | wl_list_for_each_safe(feedback, tmp, list, link) |
| 446 | weston_presentation_feedback_discard(feedback); |
| 447 | } |
| 448 | |
| 449 | static void |
| 450 | weston_presentation_feedback_present( |
| 451 | struct weston_presentation_feedback *feedback, |
| 452 | struct weston_output *output, |
| 453 | uint32_t refresh_nsec, |
| 454 | const struct timespec *ts, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 455 | uint64_t seq, |
| 456 | uint32_t flags) |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 457 | { |
| 458 | struct wl_client *client = wl_resource_get_client(feedback->resource); |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 459 | struct weston_head *head; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 460 | struct wl_resource *o; |
Alexandros Frantzis | 10d708d | 2017-12-13 13:27:54 +0200 | [diff] [blame] | 461 | uint32_t tv_sec_hi; |
| 462 | uint32_t tv_sec_lo; |
| 463 | uint32_t tv_nsec; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 464 | bool done = false; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 465 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 466 | wl_list_for_each(head, &output->head_list, output_link) { |
| 467 | wl_resource_for_each(o, &head->resource_list) { |
| 468 | if (wl_resource_get_client(o) != client) |
| 469 | continue; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 470 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 471 | wp_presentation_feedback_send_sync_output(feedback->resource, o); |
| 472 | done = true; |
| 473 | } |
| 474 | |
| 475 | /* For clone mode, send it for just one wl_output global, |
| 476 | * they are all equivalent anyway. |
| 477 | */ |
| 478 | if (done) |
| 479 | break; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 480 | } |
| 481 | |
Alexandros Frantzis | 10d708d | 2017-12-13 13:27:54 +0200 | [diff] [blame] | 482 | timespec_to_proto(ts, &tv_sec_hi, &tv_sec_lo, &tv_nsec); |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 483 | wp_presentation_feedback_send_presented(feedback->resource, |
Alexandros Frantzis | 10d708d | 2017-12-13 13:27:54 +0200 | [diff] [blame] | 484 | tv_sec_hi, tv_sec_lo, tv_nsec, |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 485 | refresh_nsec, |
| 486 | seq >> 32, seq & 0xffffffff, |
| 487 | flags | feedback->psf_flags); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 488 | wl_resource_destroy(feedback->resource); |
| 489 | } |
| 490 | |
| 491 | static void |
| 492 | weston_presentation_feedback_present_list(struct wl_list *list, |
| 493 | struct weston_output *output, |
| 494 | uint32_t refresh_nsec, |
| 495 | const struct timespec *ts, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 496 | uint64_t seq, |
| 497 | uint32_t flags) |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 498 | { |
| 499 | struct weston_presentation_feedback *feedback, *tmp; |
| 500 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 501 | assert(!(flags & WP_PRESENTATION_FEEDBACK_INVALID) || |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 502 | wl_list_empty(list)); |
| 503 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 504 | wl_list_for_each_safe(feedback, tmp, list, link) |
| 505 | weston_presentation_feedback_present(feedback, output, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 506 | refresh_nsec, ts, seq, |
| 507 | flags); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 508 | } |
| 509 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 510 | static void |
| 511 | surface_state_handle_buffer_destroy(struct wl_listener *listener, void *data) |
| 512 | { |
| 513 | struct weston_surface_state *state = |
| 514 | container_of(listener, struct weston_surface_state, |
| 515 | buffer_destroy_listener); |
| 516 | |
| 517 | state->buffer = NULL; |
| 518 | } |
| 519 | |
| 520 | static void |
| 521 | weston_surface_state_init(struct weston_surface_state *state) |
| 522 | { |
| 523 | state->newly_attached = 0; |
| 524 | state->buffer = NULL; |
| 525 | state->buffer_destroy_listener.notify = |
| 526 | surface_state_handle_buffer_destroy; |
| 527 | state->sx = 0; |
| 528 | state->sy = 0; |
| 529 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 530 | pixman_region32_init(&state->damage_surface); |
| 531 | pixman_region32_init(&state->damage_buffer); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 532 | pixman_region32_init(&state->opaque); |
| 533 | region_init_infinite(&state->input); |
| 534 | |
| 535 | wl_list_init(&state->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 536 | wl_list_init(&state->feedback_list); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 537 | |
| 538 | state->buffer_viewport.buffer.transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 539 | state->buffer_viewport.buffer.scale = 1; |
| 540 | state->buffer_viewport.buffer.src_width = wl_fixed_from_int(-1); |
| 541 | state->buffer_viewport.surface.width = -1; |
| 542 | state->buffer_viewport.changed = 0; |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 543 | |
| 544 | state->acquire_fence_fd = -1; |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 545 | |
| 546 | state->desired_protection = WESTON_HDCP_DISABLE; |
Ankit Nautiyal | 5cfe03c | 2019-03-28 15:05:42 +0530 | [diff] [blame] | 547 | state->protection_mode = WESTON_SURFACE_PROTECTION_MODE_RELAXED; |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | static void |
| 551 | weston_surface_state_fini(struct weston_surface_state *state) |
| 552 | { |
Vlad Zahorodnii | c2b9747 | 2021-07-29 11:16:51 +0300 | [diff] [blame] | 553 | struct wl_resource *cb, *next; |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 554 | |
Vlad Zahorodnii | c2b9747 | 2021-07-29 11:16:51 +0300 | [diff] [blame] | 555 | wl_resource_for_each_safe(cb, next, &state->frame_callback_list) |
| 556 | wl_resource_destroy(cb); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 557 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 558 | weston_presentation_feedback_discard_list(&state->feedback_list); |
| 559 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 560 | pixman_region32_fini(&state->input); |
| 561 | pixman_region32_fini(&state->opaque); |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 562 | pixman_region32_fini(&state->damage_surface); |
| 563 | pixman_region32_fini(&state->damage_buffer); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 564 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 565 | state->buffer = NULL; |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 566 | |
| 567 | fd_clear(&state->acquire_fence_fd); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 568 | weston_buffer_release_reference(&state->buffer_release_ref, NULL); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 569 | } |
| 570 | |
| 571 | static void |
| 572 | weston_surface_state_set_buffer(struct weston_surface_state *state, |
| 573 | struct weston_buffer *buffer) |
| 574 | { |
| 575 | if (state->buffer == buffer) |
| 576 | return; |
| 577 | |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 578 | /*if (state->buffer) |
| 579 | wl_list_remove(&state->buffer_destroy_listener.link);*/ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 580 | state->buffer = buffer; |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 581 | /*if (state->buffer) |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 582 | wl_signal_add(&state->buffer->destroy_signal, |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 583 | &state->buffer_destroy_listener);*/ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 584 | } |
| 585 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 586 | WL_EXPORT struct weston_surface * |
Kristian Høgsberg | 18c9300 | 2012-01-27 11:58:31 -0500 | [diff] [blame] | 587 | weston_surface_create(struct weston_compositor *compositor) |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 588 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 589 | struct weston_surface *surface; |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 590 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 591 | surface = zalloc(sizeof *surface); |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 592 | if (surface == NULL) |
| 593 | return NULL; |
| 594 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 595 | wl_signal_init(&surface->destroy_signal); |
Jonas Ådahl | 5d9ca27 | 2016-07-22 17:48:03 +0800 | [diff] [blame] | 596 | wl_signal_init(&surface->commit_signal); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 597 | |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 598 | surface->compositor = compositor; |
Giulio Camuffo | 13b85bd | 2013-08-13 23:10:14 +0200 | [diff] [blame] | 599 | surface->ref_count = 1; |
leng.fang | dbaf6fa | 2024-06-20 19:31:04 +0800 | [diff] [blame] | 600 | surface->surface_id = compositor->next_surface_id++; |
Kristian Høgsberg | 27803c6 | 2010-06-06 22:23:21 -0400 | [diff] [blame] | 601 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 602 | surface->buffer_viewport.buffer.transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 603 | surface->buffer_viewport.buffer.scale = 1; |
Pekka Paalanen | f0cad48 | 2014-03-14 14:38:16 +0200 | [diff] [blame] | 604 | surface->buffer_viewport.buffer.src_width = wl_fixed_from_int(-1); |
| 605 | surface->buffer_viewport.surface.width = -1; |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 606 | |
| 607 | weston_surface_state_init(&surface->pending); |
| 608 | |
Kristian Høgsberg | 20300ba | 2011-06-23 20:29:12 -0400 | [diff] [blame] | 609 | pixman_region32_init(&surface->damage); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 610 | pixman_region32_init(&surface->opaque); |
Pekka Paalanen | 8ec4ab6 | 2012-10-10 12:49:32 +0300 | [diff] [blame] | 611 | region_init_infinite(&surface->input); |
Kristian Høgsberg | 20300ba | 2011-06-23 20:29:12 -0400 | [diff] [blame] | 612 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 613 | wl_list_init(&surface->views); |
Pekka Paalanen | 1a4f87d | 2021-04-30 14:48:52 +0300 | [diff] [blame] | 614 | wl_list_init(&surface->paint_node_list); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 615 | |
| 616 | wl_list_init(&surface->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 617 | wl_list_init(&surface->feedback_list); |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 618 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 619 | wl_list_init(&surface->subsurface_list); |
| 620 | wl_list_init(&surface->subsurface_list_pending); |
| 621 | |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 622 | weston_matrix_init(&surface->buffer_to_surface_matrix); |
| 623 | weston_matrix_init(&surface->surface_to_buffer_matrix); |
| 624 | |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 625 | wl_list_init(&surface->pointer_constraints); |
| 626 | |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 627 | surface->acquire_fence_fd = -1; |
| 628 | |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 629 | surface->desired_protection = WESTON_HDCP_DISABLE; |
Ankit Nautiyal | 5cfe03c | 2019-03-28 15:05:42 +0530 | [diff] [blame] | 630 | surface->current_protection = WESTON_HDCP_DISABLE; |
| 631 | surface->protection_mode = WESTON_SURFACE_PROTECTION_MODE_RELAXED; |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 632 | |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 633 | weston_init_video_surface_info(surface); |
limin.tian | 531dd23 | 2025-01-07 12:09:27 +0000 | [diff] [blame] | 634 | WESTON_LOGI(COMMON_LOG, "%p \n", surface); |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 635 | |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 636 | return surface; |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 637 | } |
| 638 | |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 639 | WL_EXPORT void |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 640 | weston_surface_set_color(struct weston_surface *surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 641 | float red, float green, float blue, float alpha) |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 642 | { |
John Kåre Alsaker | 878f449 | 2012-11-13 19:10:23 +0100 | [diff] [blame] | 643 | surface->compositor->renderer->surface_set_color(surface, red, green, blue, alpha); |
Philipp Zabel | 195dade | 2018-09-03 19:44:59 +0200 | [diff] [blame] | 644 | surface->is_opaque = !(alpha < 1.0); |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 645 | } |
| 646 | |
Kristian Høgsberg | e4c1a5f | 2012-06-18 13:17:32 -0400 | [diff] [blame] | 647 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 648 | weston_view_to_global_float(struct weston_view *view, |
| 649 | float sx, float sy, float *x, float *y) |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 650 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 651 | if (view->transform.enabled) { |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 652 | struct weston_vector v = { { sx, sy, 0.0f, 1.0f } }; |
| 653 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 654 | weston_matrix_transform(&view->transform.matrix, &v); |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 655 | |
| 656 | if (fabsf(v.f[3]) < 1e-6) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 657 | weston_log("warning: numerical instability in " |
Scott Moreau | 088c62e | 2013-02-11 04:45:38 -0700 | [diff] [blame] | 658 | "%s(), divisor = %g\n", __func__, |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 659 | v.f[3]); |
| 660 | *x = 0; |
| 661 | *y = 0; |
| 662 | return; |
| 663 | } |
| 664 | |
| 665 | *x = v.f[0] / v.f[3]; |
| 666 | *y = v.f[1] / v.f[3]; |
| 667 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 668 | *x = sx + view->geometry.x; |
| 669 | *y = sy + view->geometry.y; |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 670 | } |
| 671 | } |
| 672 | |
Pekka Paalanen | 0df4477 | 2020-02-14 14:50:03 +0200 | [diff] [blame] | 673 | /** Transform a point to buffer coordinates |
| 674 | * |
| 675 | * \param width Surface width. |
| 676 | * \param height Surface height. |
| 677 | * \param transform Buffer transform. |
| 678 | * \param scale Buffer scale. |
| 679 | * \param sx Surface x coordinate of a point. |
| 680 | * \param sy Surface y coordinate of a point. |
| 681 | * \param[out] bx Buffer x coordinate of the point. |
| 682 | * \param[out] by Buffer Y coordinate of the point. |
| 683 | * |
| 684 | * Converts the given surface-local coordinates to buffer coordinates |
| 685 | * according to the given buffer transform and scale. |
| 686 | * This ignores wp_viewport. |
| 687 | * |
| 688 | * The given width and height must be the result of inverse scaled and |
| 689 | * inverse transformed buffer size. |
| 690 | */ |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 691 | WL_EXPORT void |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 692 | weston_transformed_coord(int width, int height, |
| 693 | enum wl_output_transform transform, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 694 | int32_t scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 695 | float sx, float sy, float *bx, float *by) |
| 696 | { |
| 697 | switch (transform) { |
| 698 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 699 | default: |
| 700 | *bx = sx; |
| 701 | *by = sy; |
| 702 | break; |
| 703 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 704 | *bx = width - sx; |
| 705 | *by = sy; |
| 706 | break; |
| 707 | case WL_OUTPUT_TRANSFORM_90: |
Pekka Paalanen | 8060d82 | 2020-02-06 15:27:54 +0200 | [diff] [blame] | 708 | *bx = sy; |
| 709 | *by = width - sx; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 710 | break; |
| 711 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
Pekka Paalanen | 8060d82 | 2020-02-06 15:27:54 +0200 | [diff] [blame] | 712 | *bx = sy; |
| 713 | *by = sx; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 714 | break; |
| 715 | case WL_OUTPUT_TRANSFORM_180: |
| 716 | *bx = width - sx; |
| 717 | *by = height - sy; |
| 718 | break; |
| 719 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 720 | *bx = sx; |
| 721 | *by = height - sy; |
| 722 | break; |
| 723 | case WL_OUTPUT_TRANSFORM_270: |
Pekka Paalanen | 8060d82 | 2020-02-06 15:27:54 +0200 | [diff] [blame] | 724 | *bx = height - sy; |
| 725 | *by = sx; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 726 | break; |
| 727 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
Pekka Paalanen | 8060d82 | 2020-02-06 15:27:54 +0200 | [diff] [blame] | 728 | *bx = height - sy; |
| 729 | *by = width - sx; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 730 | break; |
| 731 | } |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 732 | |
| 733 | *bx *= scale; |
| 734 | *by *= scale; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 735 | } |
| 736 | |
Pekka Paalanen | 0df4477 | 2020-02-14 14:50:03 +0200 | [diff] [blame] | 737 | /** Transform a rectangle to buffer coordinates |
| 738 | * |
| 739 | * \param width Surface width. |
| 740 | * \param height Surface height. |
| 741 | * \param transform Buffer transform. |
| 742 | * \param scale Buffer scale. |
| 743 | * \param rect Rectangle in surface coordinates. |
| 744 | * \return Rectangle in buffer coordinates. |
| 745 | * |
| 746 | * Converts the given surface-local rectangle to buffer coordinates |
| 747 | * according to the given buffer transform and scale. The resulting |
| 748 | * rectangle is guaranteed to be well-formed. |
| 749 | * This ignores wp_viewport. |
| 750 | * |
| 751 | * The given width and height must be the result of inverse scaled and |
| 752 | * inverse transformed buffer size. |
| 753 | */ |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 754 | WL_EXPORT pixman_box32_t |
| 755 | weston_transformed_rect(int width, int height, |
| 756 | enum wl_output_transform transform, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 757 | int32_t scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 758 | pixman_box32_t rect) |
| 759 | { |
| 760 | float x1, x2, y1, y2; |
| 761 | |
| 762 | pixman_box32_t ret; |
| 763 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 764 | weston_transformed_coord(width, height, transform, scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 765 | rect.x1, rect.y1, &x1, &y1); |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 766 | weston_transformed_coord(width, height, transform, scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 767 | rect.x2, rect.y2, &x2, &y2); |
| 768 | |
| 769 | if (x1 <= x2) { |
| 770 | ret.x1 = x1; |
| 771 | ret.x2 = x2; |
| 772 | } else { |
| 773 | ret.x1 = x2; |
| 774 | ret.x2 = x1; |
| 775 | } |
| 776 | |
| 777 | if (y1 <= y2) { |
| 778 | ret.y1 = y1; |
| 779 | ret.y2 = y2; |
| 780 | } else { |
| 781 | ret.y1 = y2; |
| 782 | ret.y2 = y1; |
| 783 | } |
| 784 | |
| 785 | return ret; |
| 786 | } |
| 787 | |
Derek Foreman | bc9a61c | 2015-11-18 16:32:30 -0600 | [diff] [blame] | 788 | /** Transform a region by a matrix, restricted to axis-aligned transformations |
| 789 | * |
| 790 | * Warning: This function does not work for projective, affine, or matrices |
| 791 | * that encode arbitrary rotations. Only 90-degree step rotations are |
| 792 | * supported. |
| 793 | */ |
| 794 | WL_EXPORT void |
| 795 | weston_matrix_transform_region(pixman_region32_t *dest, |
| 796 | struct weston_matrix *matrix, |
| 797 | pixman_region32_t *src) |
| 798 | { |
| 799 | pixman_box32_t *src_rects, *dest_rects; |
| 800 | int nrects, i; |
| 801 | |
| 802 | src_rects = pixman_region32_rectangles(src, &nrects); |
| 803 | dest_rects = malloc(nrects * sizeof(*dest_rects)); |
| 804 | if (!dest_rects) |
| 805 | return; |
| 806 | |
| 807 | for (i = 0; i < nrects; i++) { |
| 808 | struct weston_vector vec1 = {{ |
| 809 | src_rects[i].x1, src_rects[i].y1, 0, 1 |
| 810 | }}; |
| 811 | weston_matrix_transform(matrix, &vec1); |
| 812 | vec1.f[0] /= vec1.f[3]; |
| 813 | vec1.f[1] /= vec1.f[3]; |
| 814 | |
| 815 | struct weston_vector vec2 = {{ |
| 816 | src_rects[i].x2, src_rects[i].y2, 0, 1 |
| 817 | }}; |
| 818 | weston_matrix_transform(matrix, &vec2); |
| 819 | vec2.f[0] /= vec2.f[3]; |
| 820 | vec2.f[1] /= vec2.f[3]; |
| 821 | |
| 822 | if (vec1.f[0] < vec2.f[0]) { |
| 823 | dest_rects[i].x1 = floor(vec1.f[0]); |
| 824 | dest_rects[i].x2 = ceil(vec2.f[0]); |
| 825 | } else { |
| 826 | dest_rects[i].x1 = floor(vec2.f[0]); |
| 827 | dest_rects[i].x2 = ceil(vec1.f[0]); |
| 828 | } |
| 829 | |
Derek Foreman | bc9a61c | 2015-11-18 16:32:30 -0600 | [diff] [blame] | 830 | if (vec1.f[1] < vec2.f[1]) { |
| 831 | dest_rects[i].y1 = floor(vec1.f[1]); |
| 832 | dest_rects[i].y2 = ceil(vec2.f[1]); |
| 833 | } else { |
| 834 | dest_rects[i].y1 = floor(vec2.f[1]); |
| 835 | dest_rects[i].y2 = ceil(vec1.f[1]); |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | pixman_region32_clear(dest); |
| 840 | pixman_region32_init_rects(dest, dest_rects, nrects); |
| 841 | free(dest_rects); |
| 842 | } |
| 843 | |
Pekka Paalanen | 0df4477 | 2020-02-14 14:50:03 +0200 | [diff] [blame] | 844 | /** Transform a region to buffer coordinates |
| 845 | * |
| 846 | * \param width Surface width. |
| 847 | * \param height Surface height. |
| 848 | * \param transform Buffer transform. |
| 849 | * \param scale Buffer scale. |
| 850 | * \param[in] src Region in surface coordinates. |
| 851 | * \param[out] dest Resulting region in buffer coordinates. |
| 852 | * |
| 853 | * Converts the given surface-local region to buffer coordinates |
| 854 | * according to the given buffer transform and scale. |
| 855 | * This ignores wp_viewport. |
| 856 | * |
| 857 | * The given width and height must be the result of inverse scaled and |
| 858 | * inverse transformed buffer size. |
| 859 | * |
| 860 | * src and dest are allowed to point to the same memory for in-place conversion. |
| 861 | */ |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 862 | WL_EXPORT void |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 863 | weston_transformed_region(int width, int height, |
| 864 | enum wl_output_transform transform, |
| 865 | int32_t scale, |
| 866 | pixman_region32_t *src, pixman_region32_t *dest) |
| 867 | { |
| 868 | pixman_box32_t *src_rects, *dest_rects; |
| 869 | int nrects, i; |
| 870 | |
| 871 | if (transform == WL_OUTPUT_TRANSFORM_NORMAL && scale == 1) { |
| 872 | if (src != dest) |
| 873 | pixman_region32_copy(dest, src); |
| 874 | return; |
| 875 | } |
| 876 | |
| 877 | src_rects = pixman_region32_rectangles(src, &nrects); |
| 878 | dest_rects = malloc(nrects * sizeof(*dest_rects)); |
| 879 | if (!dest_rects) |
| 880 | return; |
| 881 | |
| 882 | if (transform == WL_OUTPUT_TRANSFORM_NORMAL) { |
| 883 | memcpy(dest_rects, src_rects, nrects * sizeof(*dest_rects)); |
| 884 | } else { |
| 885 | for (i = 0; i < nrects; i++) { |
| 886 | switch (transform) { |
| 887 | default: |
| 888 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 889 | dest_rects[i].x1 = src_rects[i].x1; |
| 890 | dest_rects[i].y1 = src_rects[i].y1; |
| 891 | dest_rects[i].x2 = src_rects[i].x2; |
| 892 | dest_rects[i].y2 = src_rects[i].y2; |
| 893 | break; |
| 894 | case WL_OUTPUT_TRANSFORM_90: |
Pekka Paalanen | 8060d82 | 2020-02-06 15:27:54 +0200 | [diff] [blame] | 895 | dest_rects[i].x1 = src_rects[i].y1; |
| 896 | dest_rects[i].y1 = width - src_rects[i].x2; |
| 897 | dest_rects[i].x2 = src_rects[i].y2; |
| 898 | dest_rects[i].y2 = width - src_rects[i].x1; |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 899 | break; |
| 900 | case WL_OUTPUT_TRANSFORM_180: |
| 901 | dest_rects[i].x1 = width - src_rects[i].x2; |
| 902 | dest_rects[i].y1 = height - src_rects[i].y2; |
| 903 | dest_rects[i].x2 = width - src_rects[i].x1; |
| 904 | dest_rects[i].y2 = height - src_rects[i].y1; |
| 905 | break; |
| 906 | case WL_OUTPUT_TRANSFORM_270: |
Pekka Paalanen | 8060d82 | 2020-02-06 15:27:54 +0200 | [diff] [blame] | 907 | dest_rects[i].x1 = height - src_rects[i].y2; |
| 908 | dest_rects[i].y1 = src_rects[i].x1; |
| 909 | dest_rects[i].x2 = height - src_rects[i].y1; |
| 910 | dest_rects[i].y2 = src_rects[i].x2; |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 911 | break; |
| 912 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 913 | dest_rects[i].x1 = width - src_rects[i].x2; |
| 914 | dest_rects[i].y1 = src_rects[i].y1; |
| 915 | dest_rects[i].x2 = width - src_rects[i].x1; |
| 916 | dest_rects[i].y2 = src_rects[i].y2; |
| 917 | break; |
| 918 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
Pekka Paalanen | 8060d82 | 2020-02-06 15:27:54 +0200 | [diff] [blame] | 919 | dest_rects[i].x1 = src_rects[i].y1; |
| 920 | dest_rects[i].y1 = src_rects[i].x1; |
| 921 | dest_rects[i].x2 = src_rects[i].y2; |
| 922 | dest_rects[i].y2 = src_rects[i].x2; |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 923 | break; |
| 924 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 925 | dest_rects[i].x1 = src_rects[i].x1; |
| 926 | dest_rects[i].y1 = height - src_rects[i].y2; |
| 927 | dest_rects[i].x2 = src_rects[i].x2; |
| 928 | dest_rects[i].y2 = height - src_rects[i].y1; |
| 929 | break; |
| 930 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
Pekka Paalanen | 8060d82 | 2020-02-06 15:27:54 +0200 | [diff] [blame] | 931 | dest_rects[i].x1 = height - src_rects[i].y2; |
| 932 | dest_rects[i].y1 = width - src_rects[i].x2; |
| 933 | dest_rects[i].x2 = height - src_rects[i].y1; |
| 934 | dest_rects[i].y2 = width - src_rects[i].x1; |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 935 | break; |
| 936 | } |
| 937 | } |
| 938 | } |
| 939 | |
| 940 | if (scale != 1) { |
| 941 | for (i = 0; i < nrects; i++) { |
| 942 | dest_rects[i].x1 *= scale; |
| 943 | dest_rects[i].x2 *= scale; |
| 944 | dest_rects[i].y1 *= scale; |
| 945 | dest_rects[i].y2 *= scale; |
| 946 | } |
| 947 | } |
| 948 | |
| 949 | pixman_region32_clear(dest); |
| 950 | pixman_region32_init_rects(dest, dest_rects, nrects); |
| 951 | free(dest_rects); |
| 952 | } |
| 953 | |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 954 | static void |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 955 | viewport_surface_to_buffer(struct weston_surface *surface, |
| 956 | float sx, float sy, float *bx, float *by) |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 957 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 958 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 959 | double src_width, src_height; |
| 960 | double src_x, src_y; |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 961 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 962 | if (vp->buffer.src_width == wl_fixed_from_int(-1)) { |
| 963 | if (vp->surface.width == -1) { |
| 964 | *bx = sx; |
| 965 | *by = sy; |
| 966 | return; |
| 967 | } |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 968 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 969 | src_x = 0.0; |
| 970 | src_y = 0.0; |
| 971 | src_width = surface->width_from_buffer; |
| 972 | src_height = surface->height_from_buffer; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 973 | } else { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 974 | src_x = wl_fixed_to_double(vp->buffer.src_x); |
| 975 | src_y = wl_fixed_to_double(vp->buffer.src_y); |
| 976 | src_width = wl_fixed_to_double(vp->buffer.src_width); |
| 977 | src_height = wl_fixed_to_double(vp->buffer.src_height); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 978 | } |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 979 | |
| 980 | *bx = sx * src_width / surface->width + src_x; |
| 981 | *by = sy * src_height / surface->height + src_y; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 982 | } |
| 983 | |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 984 | WL_EXPORT void |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 985 | weston_surface_to_buffer_float(struct weston_surface *surface, |
| 986 | float sx, float sy, float *bx, float *by) |
| 987 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 988 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
| 989 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 990 | /* first transform coordinates if the viewport is set */ |
| 991 | viewport_surface_to_buffer(surface, sx, sy, bx, by); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 992 | |
Jason Ekstrand | d0cebc3 | 2014-04-21 20:56:46 -0500 | [diff] [blame] | 993 | weston_transformed_coord(surface->width_from_buffer, |
| 994 | surface->height_from_buffer, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 995 | vp->buffer.transform, vp->buffer.scale, |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 996 | *bx, *by, bx, by); |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 997 | } |
| 998 | |
Derek Foreman | 9973967 | 2015-12-03 16:38:11 -0600 | [diff] [blame] | 999 | /** Transform a rectangle from surface coordinates to buffer coordinates |
| 1000 | * |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 1001 | * \param surface The surface to fetch wp_viewport and buffer transformation |
Derek Foreman | 9973967 | 2015-12-03 16:38:11 -0600 | [diff] [blame] | 1002 | * from. |
| 1003 | * \param rect The rectangle to transform. |
| 1004 | * \return The transformed rectangle. |
| 1005 | * |
| 1006 | * Viewport and buffer transformations can only do translation, scaling, |
| 1007 | * and rotations in 90-degree steps. Therefore the only loss in the |
| 1008 | * conversion is coordinate rounding. |
| 1009 | * |
| 1010 | * However, some coordinate rounding takes place as an intermediate |
| 1011 | * step before the buffer scale factor is applied, so the rectangle |
| 1012 | * boundary may not be exactly as expected. |
| 1013 | * |
| 1014 | * This is OK for damage tracking since a little extra coverage is |
| 1015 | * not a problem. |
| 1016 | */ |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 1017 | WL_EXPORT pixman_box32_t |
| 1018 | weston_surface_to_buffer_rect(struct weston_surface *surface, |
| 1019 | pixman_box32_t rect) |
| 1020 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 1021 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 1022 | float xf, yf; |
| 1023 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 1024 | /* first transform box coordinates if the viewport is set */ |
| 1025 | viewport_surface_to_buffer(surface, rect.x1, rect.y1, &xf, &yf); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 1026 | rect.x1 = floorf(xf); |
| 1027 | rect.y1 = floorf(yf); |
| 1028 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 1029 | viewport_surface_to_buffer(surface, rect.x2, rect.y2, &xf, &yf); |
Derek Foreman | e2e15ac | 2015-12-01 13:00:43 -0600 | [diff] [blame] | 1030 | rect.x2 = ceilf(xf); |
| 1031 | rect.y2 = ceilf(yf); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 1032 | |
Jason Ekstrand | d0cebc3 | 2014-04-21 20:56:46 -0500 | [diff] [blame] | 1033 | return weston_transformed_rect(surface->width_from_buffer, |
| 1034 | surface->height_from_buffer, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 1035 | vp->buffer.transform, vp->buffer.scale, |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 1036 | rect); |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 1037 | } |
| 1038 | |
Pekka Paalanen | e54e31c | 2015-03-04 14:23:28 +0200 | [diff] [blame] | 1039 | /** Transform a region from surface coordinates to buffer coordinates |
| 1040 | * |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 1041 | * \param surface The surface to fetch wp_viewport and buffer transformation |
Pekka Paalanen | e54e31c | 2015-03-04 14:23:28 +0200 | [diff] [blame] | 1042 | * from. |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 1043 | * \param[in] surface_region The region in surface coordinates. |
| 1044 | * \param[out] buffer_region The region converted to buffer coordinates. |
Pekka Paalanen | e54e31c | 2015-03-04 14:23:28 +0200 | [diff] [blame] | 1045 | * |
| 1046 | * Buffer_region must be init'd, but will be completely overwritten. |
| 1047 | * |
| 1048 | * Viewport and buffer transformations can only do translation, scaling, |
| 1049 | * and rotations in 90-degree steps. Therefore the only loss in the |
Derek Foreman | 9973967 | 2015-12-03 16:38:11 -0600 | [diff] [blame] | 1050 | * conversion is from the coordinate rounding that takes place in |
| 1051 | * \ref weston_surface_to_buffer_rect. |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 1052 | * |
Pekka Paalanen | e54e31c | 2015-03-04 14:23:28 +0200 | [diff] [blame] | 1053 | */ |
| 1054 | WL_EXPORT void |
| 1055 | weston_surface_to_buffer_region(struct weston_surface *surface, |
| 1056 | pixman_region32_t *surface_region, |
| 1057 | pixman_region32_t *buffer_region) |
| 1058 | { |
| 1059 | pixman_box32_t *src_rects, *dest_rects; |
| 1060 | int nrects, i; |
| 1061 | |
| 1062 | src_rects = pixman_region32_rectangles(surface_region, &nrects); |
| 1063 | dest_rects = malloc(nrects * sizeof(*dest_rects)); |
| 1064 | if (!dest_rects) |
| 1065 | return; |
| 1066 | |
| 1067 | for (i = 0; i < nrects; i++) { |
| 1068 | dest_rects[i] = weston_surface_to_buffer_rect(surface, |
| 1069 | src_rects[i]); |
| 1070 | } |
| 1071 | |
| 1072 | pixman_region32_fini(buffer_region); |
| 1073 | pixman_region32_init_rects(buffer_region, dest_rects, nrects); |
| 1074 | free(dest_rects); |
| 1075 | } |
| 1076 | |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 1077 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1078 | weston_view_move_to_plane(struct weston_view *view, |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1079 | struct weston_plane *plane) |
| 1080 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1081 | if (view->plane == plane) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1082 | return; |
| 1083 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1084 | weston_view_damage_below(view); |
| 1085 | view->plane = plane; |
| 1086 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1087 | } |
| 1088 | |
Pekka Paalanen | 51723d5 | 2015-02-17 13:10:01 +0200 | [diff] [blame] | 1089 | /** Inflict damage on the plane where the view is visible. |
| 1090 | * |
| 1091 | * \param view The view that causes the damage. |
| 1092 | * |
| 1093 | * If the view is currently on a plane (including the primary plane), |
| 1094 | * take the view's boundingbox, subtract all the opaque views that cover it, |
| 1095 | * and add the remaining region as damage to the plane. This corresponds |
| 1096 | * to the damage inflicted to the plane if this view disappeared. |
| 1097 | * |
| 1098 | * A repaint is scheduled for this view. |
| 1099 | * |
| 1100 | * The region of all opaque views covering this view is stored in |
| 1101 | * weston_view::clip and updated by view_accumulate_damage() during |
| 1102 | * weston_output_repaint(). Specifically, that region matches the |
| 1103 | * scenegraph as it was last painted. |
| 1104 | */ |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 1105 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1106 | weston_view_damage_below(struct weston_view *view) |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 1107 | { |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 1108 | pixman_region32_t damage; |
limin.tian | 230ec58 | 2024-07-30 09:35:17 +0000 | [diff] [blame] | 1109 | if (!view->surface->is_video_surface && !(view->alpha == 0.0)) { |
| 1110 | pixman_region32_init(&damage); |
| 1111 | pixman_region32_subtract(&damage, &view->transform.boundingbox, |
| 1112 | &view->clip); |
| 1113 | if (view->plane) |
| 1114 | pixman_region32_union(&view->plane->damage, |
| 1115 | &view->plane->damage, &damage); |
| 1116 | pixman_region32_fini(&damage); |
| 1117 | } |
Kristian Høgsberg | a3a784a | 2013-11-13 21:33:43 -0800 | [diff] [blame] | 1118 | weston_view_schedule_repaint(view); |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 1119 | } |
| 1120 | |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1121 | /** Send wl_surface.enter/leave events |
| 1122 | * |
| 1123 | * \param surface The surface. |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 1124 | * \param head A head of the entered/left output. |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1125 | * \param enter True if entered. |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 1126 | * \param leave True if left. |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1127 | * |
| 1128 | * Send the enter/leave events for all protocol objects bound to the given |
| 1129 | * output by the client owning the surface. |
| 1130 | */ |
| 1131 | static void |
| 1132 | weston_surface_send_enter_leave(struct weston_surface *surface, |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 1133 | struct weston_head *head, |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1134 | bool enter, |
| 1135 | bool leave) |
| 1136 | { |
| 1137 | struct wl_resource *wloutput; |
| 1138 | struct wl_client *client; |
| 1139 | |
| 1140 | assert(enter != leave); |
| 1141 | |
| 1142 | client = wl_resource_get_client(surface->resource); |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 1143 | wl_resource_for_each(wloutput, &head->resource_list) { |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1144 | if (wl_resource_get_client(wloutput) != client) |
| 1145 | continue; |
| 1146 | |
| 1147 | if (enter) |
| 1148 | wl_surface_send_enter(surface->resource, wloutput); |
| 1149 | if (leave) |
| 1150 | wl_surface_send_leave(surface->resource, wloutput); |
| 1151 | } |
| 1152 | } |
| 1153 | |
Ankit Nautiyal | f74c35b | 2019-04-03 19:21:58 +0530 | [diff] [blame] | 1154 | static void |
| 1155 | weston_surface_compute_protection(struct protected_surface *psurface) |
| 1156 | { |
| 1157 | enum weston_hdcp_protection min_protection; |
| 1158 | bool min_protection_valid = false; |
| 1159 | struct weston_surface *surface = psurface->surface; |
| 1160 | struct weston_output *output; |
| 1161 | |
| 1162 | wl_list_for_each(output, &surface->compositor->output_list, link) |
| 1163 | if (surface->output_mask & (1u << output->id)) { |
Ankit Nautiyal | 4fd3813 | 2019-07-08 15:12:19 +0530 | [diff] [blame] | 1164 | /* |
| 1165 | * If the content-protection is enabled with protection |
| 1166 | * mode as RELAXED for a surface, and if |
| 1167 | * content-recording features like: screen-shooter, |
| 1168 | * recorder, screen-sharing, etc are on, then notify the |
| 1169 | * client, that the protection is disabled. |
| 1170 | * |
| 1171 | * Note: If the protection mode is ENFORCED then there |
| 1172 | * is no need to bother the client as the renderer takes |
| 1173 | * care of censoring the visibility of the protected |
| 1174 | * content. |
| 1175 | */ |
| 1176 | |
| 1177 | if (output->disable_planes > 0 && |
| 1178 | surface->protection_mode == WESTON_SURFACE_PROTECTION_MODE_RELAXED) { |
| 1179 | min_protection = WESTON_HDCP_DISABLE; |
| 1180 | min_protection_valid = true; |
| 1181 | break; |
| 1182 | } |
Ankit Nautiyal | f74c35b | 2019-04-03 19:21:58 +0530 | [diff] [blame] | 1183 | if (!min_protection_valid) { |
| 1184 | min_protection = output->current_protection; |
| 1185 | min_protection_valid = true; |
| 1186 | } |
| 1187 | if (output->current_protection < min_protection) |
| 1188 | min_protection = output->current_protection; |
| 1189 | } |
| 1190 | if (!min_protection_valid) |
| 1191 | min_protection = WESTON_HDCP_DISABLE; |
| 1192 | |
| 1193 | surface->current_protection = min_protection; |
Ankit Nautiyal | 4fd3813 | 2019-07-08 15:12:19 +0530 | [diff] [blame] | 1194 | |
| 1195 | weston_protected_surface_send_event(psurface, surface->current_protection); |
Ankit Nautiyal | f74c35b | 2019-04-03 19:21:58 +0530 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | static void |
| 1199 | notify_surface_protection_change(void *data) |
| 1200 | { |
| 1201 | struct weston_compositor *compositor = data; |
| 1202 | struct content_protection *cp; |
| 1203 | struct protected_surface *psurface; |
| 1204 | |
| 1205 | cp = compositor->content_protection; |
| 1206 | cp->surface_protection_update = NULL; |
| 1207 | |
| 1208 | /* Notify the clients, whose surfaces are changed */ |
| 1209 | wl_list_for_each(psurface, &cp->protected_list, link) |
| 1210 | if (psurface && psurface->surface) |
| 1211 | weston_surface_compute_protection(psurface); |
| 1212 | } |
| 1213 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1214 | /** |
Ankit Nautiyal | faa5ab4 | 2019-07-08 13:23:24 +0530 | [diff] [blame] | 1215 | * \param compositor weston_compositor |
| 1216 | * |
| 1217 | * Schedule an idle task to notify surface about the update in protection, |
| 1218 | * if not already scheduled. |
| 1219 | */ |
| 1220 | static void |
| 1221 | weston_schedule_surface_protection_update(struct weston_compositor *compositor) |
| 1222 | { |
| 1223 | struct content_protection *cp = compositor->content_protection; |
| 1224 | struct wl_event_loop *loop; |
| 1225 | |
| 1226 | if (!cp || cp->surface_protection_update) |
| 1227 | return; |
| 1228 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 1229 | cp->surface_protection_update = wl_event_loop_add_idle(loop, |
| 1230 | notify_surface_protection_change, |
| 1231 | compositor); |
| 1232 | } |
| 1233 | |
| 1234 | /** |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1235 | * \param es The surface |
| 1236 | * \param mask The new set of outputs for the surface |
| 1237 | * |
| 1238 | * Sets the surface's set of outputs to the ones specified by |
| 1239 | * the new output mask provided. Identifies the outputs that |
| 1240 | * have changed, the posts enter and leave events for these |
| 1241 | * outputs as appropriate. |
| 1242 | */ |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1243 | static void |
| 1244 | weston_surface_update_output_mask(struct weston_surface *es, uint32_t mask) |
| 1245 | { |
| 1246 | uint32_t different = es->output_mask ^ mask; |
| 1247 | uint32_t entered = mask & different; |
| 1248 | uint32_t left = es->output_mask & different; |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1249 | uint32_t output_bit; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1250 | struct weston_output *output; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 1251 | struct weston_head *head; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1252 | |
| 1253 | es->output_mask = mask; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1254 | if (es->resource == NULL) |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1255 | return; |
| 1256 | if (different == 0) |
| 1257 | return; |
| 1258 | |
| 1259 | wl_list_for_each(output, &es->compositor->output_list, link) { |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1260 | output_bit = 1u << output->id; |
| 1261 | if (!(output_bit & different)) |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1262 | continue; |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1263 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 1264 | wl_list_for_each(head, &output->head_list, output_link) { |
| 1265 | weston_surface_send_enter_leave(es, head, |
| 1266 | output_bit & entered, |
| 1267 | output_bit & left); |
| 1268 | } |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1269 | } |
Ankit Nautiyal | f74c35b | 2019-04-03 19:21:58 +0530 | [diff] [blame] | 1270 | /* |
| 1271 | * Change in surfaces' output mask might trigger a change in its |
| 1272 | * protection. |
| 1273 | */ |
Ankit Nautiyal | faa5ab4 | 2019-07-08 13:23:24 +0530 | [diff] [blame] | 1274 | weston_schedule_surface_protection_update(es->compositor); |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1275 | } |
| 1276 | |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 1277 | static void |
| 1278 | notify_view_output_destroy(struct wl_listener *listener, void *data) |
| 1279 | { |
| 1280 | struct weston_view *view = |
| 1281 | container_of(listener, |
| 1282 | struct weston_view, output_destroy_listener); |
| 1283 | |
| 1284 | view->output = NULL; |
| 1285 | view->output_destroy_listener.notify = NULL; |
| 1286 | } |
| 1287 | |
| 1288 | /** Set the primary output of the view |
| 1289 | * |
| 1290 | * \param view The view whose primary output to set |
| 1291 | * \param output The new primary output for the view |
| 1292 | * |
| 1293 | * Set \a output to be the primary output of the \a view. |
| 1294 | * |
| 1295 | * Notice that the assignment may be temporary; the primary output could be |
| 1296 | * automatically changed. Hence, one cannot rely on the value persisting. |
| 1297 | * |
| 1298 | * Passing NULL as /a output will set the primary output to NULL. |
| 1299 | */ |
| 1300 | WL_EXPORT void |
| 1301 | weston_view_set_output(struct weston_view *view, struct weston_output *output) |
| 1302 | { |
| 1303 | if (view->output_destroy_listener.notify) { |
| 1304 | wl_list_remove(&view->output_destroy_listener.link); |
| 1305 | view->output_destroy_listener.notify = NULL; |
| 1306 | } |
| 1307 | view->output = output; |
| 1308 | if (output) { |
| 1309 | view->output_destroy_listener.notify = |
| 1310 | notify_view_output_destroy; |
| 1311 | wl_signal_add(&output->destroy_signal, |
| 1312 | &view->output_destroy_listener); |
| 1313 | } |
| 1314 | } |
| 1315 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1316 | /** Recalculate which output(s) the surface has views displayed on |
| 1317 | * |
| 1318 | * \param es The surface to remap to outputs |
| 1319 | * |
| 1320 | * Finds the output that is showing the largest amount of one |
| 1321 | * of the surface's various views. This output becomes the |
Pekka Paalanen | 130ae6e | 2016-03-30 14:33:33 +0300 | [diff] [blame] | 1322 | * surface's primary output for vsync and frame callback purposes. |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1323 | * |
Pekka Paalanen | 130ae6e | 2016-03-30 14:33:33 +0300 | [diff] [blame] | 1324 | * Also notes all outputs of all of the surface's views |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1325 | * in the output_mask for the surface. |
| 1326 | */ |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1327 | static void |
| 1328 | weston_surface_assign_output(struct weston_surface *es) |
| 1329 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1330 | struct weston_output *new_output; |
| 1331 | struct weston_view *view; |
| 1332 | pixman_region32_t region; |
| 1333 | uint32_t max, area, mask; |
| 1334 | pixman_box32_t *e; |
| 1335 | |
| 1336 | new_output = NULL; |
| 1337 | max = 0; |
| 1338 | mask = 0; |
| 1339 | pixman_region32_init(®ion); |
| 1340 | wl_list_for_each(view, &es->views, surface_link) { |
| 1341 | if (!view->output) |
| 1342 | continue; |
| 1343 | |
| 1344 | pixman_region32_intersect(®ion, &view->transform.boundingbox, |
| 1345 | &view->output->region); |
| 1346 | |
| 1347 | e = pixman_region32_extents(®ion); |
| 1348 | area = (e->x2 - e->x1) * (e->y2 - e->y1); |
| 1349 | |
| 1350 | mask |= view->output_mask; |
| 1351 | |
| 1352 | if (area >= max) { |
| 1353 | new_output = view->output; |
| 1354 | max = area; |
| 1355 | } |
| 1356 | } |
| 1357 | pixman_region32_fini(®ion); |
| 1358 | |
| 1359 | es->output = new_output; |
| 1360 | weston_surface_update_output_mask(es, mask); |
| 1361 | } |
| 1362 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1363 | /** Recalculate which output(s) the view is displayed on |
| 1364 | * |
| 1365 | * \param ev The view to remap to outputs |
| 1366 | * |
| 1367 | * Identifies the set of outputs that the view is visible on, |
| 1368 | * noting them into the output_mask. The output that the view |
Pekka Paalanen | 130ae6e | 2016-03-30 14:33:33 +0300 | [diff] [blame] | 1369 | * is most visible on is set as the view's primary output. |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1370 | * |
| 1371 | * Also does the same for the view's surface. See |
| 1372 | * weston_surface_assign_output(). |
| 1373 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1374 | static void |
| 1375 | weston_view_assign_output(struct weston_view *ev) |
| 1376 | { |
| 1377 | struct weston_compositor *ec = ev->surface->compositor; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1378 | struct weston_output *output, *new_output; |
| 1379 | pixman_region32_t region; |
| 1380 | uint32_t max, area, mask; |
| 1381 | pixman_box32_t *e; |
| 1382 | |
| 1383 | new_output = NULL; |
| 1384 | max = 0; |
| 1385 | mask = 0; |
| 1386 | pixman_region32_init(®ion); |
| 1387 | wl_list_for_each(output, &ec->output_list, link) { |
Giulio Camuffo | 2f2a70c | 2015-07-12 10:52:32 +0300 | [diff] [blame] | 1388 | if (output->destroying) |
| 1389 | continue; |
| 1390 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1391 | pixman_region32_intersect(®ion, &ev->transform.boundingbox, |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1392 | &output->region); |
| 1393 | |
| 1394 | e = pixman_region32_extents(®ion); |
| 1395 | area = (e->x2 - e->x1) * (e->y2 - e->y1); |
| 1396 | |
| 1397 | if (area > 0) |
Bryce Harrington | 89324ce | 2015-12-23 18:38:07 -0800 | [diff] [blame] | 1398 | mask |= 1u << output->id; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1399 | |
| 1400 | if (area >= max) { |
| 1401 | new_output = output; |
| 1402 | max = area; |
| 1403 | } |
| 1404 | } |
| 1405 | pixman_region32_fini(®ion); |
| 1406 | |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 1407 | weston_view_set_output(ev, new_output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1408 | ev->output_mask = mask; |
| 1409 | |
| 1410 | weston_surface_assign_output(ev->surface); |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1411 | } |
| 1412 | |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 1413 | static void |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1414 | weston_view_to_view_map(struct weston_view *from, struct weston_view *to, |
| 1415 | int from_x, int from_y, int *to_x, int *to_y) |
| 1416 | { |
| 1417 | float x, y; |
| 1418 | |
| 1419 | weston_view_to_global_float(from, from_x, from_y, &x, &y); |
| 1420 | weston_view_from_global_float(to, x, y, &x, &y); |
| 1421 | |
| 1422 | *to_x = round(x); |
| 1423 | *to_y = round(y); |
| 1424 | } |
| 1425 | |
| 1426 | static void |
| 1427 | weston_view_transfer_scissor(struct weston_view *from, struct weston_view *to) |
| 1428 | { |
| 1429 | pixman_box32_t *a; |
| 1430 | pixman_box32_t b; |
| 1431 | |
| 1432 | a = pixman_region32_extents(&from->geometry.scissor); |
| 1433 | |
| 1434 | weston_view_to_view_map(from, to, a->x1, a->y1, &b.x1, &b.y1); |
| 1435 | weston_view_to_view_map(from, to, a->x2, a->y2, &b.x2, &b.y2); |
| 1436 | |
| 1437 | pixman_region32_fini(&to->geometry.scissor); |
| 1438 | pixman_region32_init_with_extents(&to->geometry.scissor, &b); |
| 1439 | } |
| 1440 | |
| 1441 | static void |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 1442 | view_compute_bbox(struct weston_view *view, const pixman_box32_t *inbox, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1443 | pixman_region32_t *bbox) |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1444 | { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1445 | float min_x = HUGE_VALF, min_y = HUGE_VALF; |
| 1446 | float max_x = -HUGE_VALF, max_y = -HUGE_VALF; |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1447 | int32_t s[4][2] = { |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 1448 | { inbox->x1, inbox->y1 }, |
| 1449 | { inbox->x1, inbox->y2 }, |
| 1450 | { inbox->x2, inbox->y1 }, |
| 1451 | { inbox->x2, inbox->y2 }, |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1452 | }; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1453 | float int_x, int_y; |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1454 | int i; |
| 1455 | |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 1456 | if (inbox->x1 == inbox->x2 || inbox->y1 == inbox->y2) { |
Pekka Paalanen | 7c7d464 | 2012-09-04 13:55:44 +0300 | [diff] [blame] | 1457 | /* avoid rounding empty bbox to 1x1 */ |
| 1458 | pixman_region32_init(bbox); |
| 1459 | return; |
| 1460 | } |
| 1461 | |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1462 | for (i = 0; i < 4; ++i) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1463 | float x, y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1464 | 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] | 1465 | if (x < min_x) |
| 1466 | min_x = x; |
| 1467 | if (x > max_x) |
| 1468 | max_x = x; |
| 1469 | if (y < min_y) |
| 1470 | min_y = y; |
| 1471 | if (y > max_y) |
| 1472 | max_y = y; |
| 1473 | } |
| 1474 | |
Pekka Paalanen | 219b982 | 2012-02-08 15:38:37 +0200 | [diff] [blame] | 1475 | int_x = floorf(min_x); |
| 1476 | int_y = floorf(min_y); |
| 1477 | pixman_region32_init_rect(bbox, int_x, int_y, |
| 1478 | ceilf(max_x) - int_x, ceilf(max_y) - int_y); |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1479 | } |
| 1480 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1481 | static void |
Michael Olbrich | cb04f98 | 2020-06-08 10:22:32 +0200 | [diff] [blame] | 1482 | weston_view_update_transform_scissor(struct weston_view *view, |
| 1483 | pixman_region32_t *region) |
| 1484 | { |
| 1485 | struct weston_view *parent = view->geometry.parent; |
| 1486 | |
| 1487 | if (parent) { |
| 1488 | if (parent->geometry.scissor_enabled) { |
| 1489 | view->geometry.scissor_enabled = true; |
| 1490 | weston_view_transfer_scissor(parent, view); |
| 1491 | } else { |
| 1492 | view->geometry.scissor_enabled = false; |
| 1493 | } |
| 1494 | } |
| 1495 | |
| 1496 | if (view->geometry.scissor_enabled) |
| 1497 | pixman_region32_intersect(region, region, |
| 1498 | &view->geometry.scissor); |
| 1499 | } |
| 1500 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1501 | weston_view_update_transform_disable(struct weston_view *view) |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1502 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1503 | view->transform.enabled = 0; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1504 | |
Pekka Paalanen | cc2f868 | 2012-02-13 10:34:04 +0200 | [diff] [blame] | 1505 | /* round off fractions when not transformed */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1506 | view->geometry.x = roundf(view->geometry.x); |
| 1507 | view->geometry.y = roundf(view->geometry.y); |
Pekka Paalanen | cc2f868 | 2012-02-13 10:34:04 +0200 | [diff] [blame] | 1508 | |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1509 | /* Otherwise identity matrix, but with x and y translation. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1510 | view->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE; |
| 1511 | view->transform.position.matrix.d[12] = view->geometry.x; |
| 1512 | view->transform.position.matrix.d[13] = view->geometry.y; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1513 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1514 | view->transform.matrix = view->transform.position.matrix; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1515 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1516 | view->transform.inverse = view->transform.position.matrix; |
| 1517 | view->transform.inverse.d[12] = -view->geometry.x; |
| 1518 | view->transform.inverse.d[13] = -view->geometry.y; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1519 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1520 | pixman_region32_init_rect(&view->transform.boundingbox, |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1521 | 0, 0, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1522 | view->surface->width, |
| 1523 | view->surface->height); |
Michael Olbrich | cb04f98 | 2020-06-08 10:22:32 +0200 | [diff] [blame] | 1524 | |
| 1525 | weston_view_update_transform_scissor(view, &view->transform.boundingbox); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1526 | |
| 1527 | pixman_region32_translate(&view->transform.boundingbox, |
| 1528 | view->geometry.x, view->geometry.y); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1529 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1530 | if (view->alpha == 1.0) { |
| 1531 | pixman_region32_copy(&view->transform.opaque, |
| 1532 | &view->surface->opaque); |
Derek Foreman | 713f023 | 2022-01-12 16:30:26 -0600 | [diff] [blame] | 1533 | if (view->geometry.scissor_enabled) |
| 1534 | pixman_region32_intersect(&view->transform.opaque, |
| 1535 | &view->transform.opaque, |
| 1536 | &view->geometry.scissor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1537 | pixman_region32_translate(&view->transform.opaque, |
| 1538 | view->geometry.x, |
| 1539 | view->geometry.y); |
Kristian Høgsberg | 3b4af20 | 2012-02-28 09:19:39 -0500 | [diff] [blame] | 1540 | } |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1541 | } |
| 1542 | |
| 1543 | static int |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1544 | weston_view_update_transform_enable(struct weston_view *view) |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1545 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1546 | struct weston_view *parent = view->geometry.parent; |
| 1547 | struct weston_matrix *matrix = &view->transform.matrix; |
| 1548 | struct weston_matrix *inverse = &view->transform.inverse; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1549 | struct weston_transform *tform; |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1550 | pixman_region32_t surfregion; |
| 1551 | const pixman_box32_t *surfbox; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1552 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1553 | view->transform.enabled = 1; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1554 | |
| 1555 | /* Otherwise identity matrix, but with x and y translation. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1556 | view->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE; |
| 1557 | view->transform.position.matrix.d[12] = view->geometry.x; |
| 1558 | view->transform.position.matrix.d[13] = view->geometry.y; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1559 | |
| 1560 | weston_matrix_init(matrix); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1561 | wl_list_for_each(tform, &view->geometry.transformation_list, link) |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1562 | weston_matrix_multiply(matrix, &tform->matrix); |
| 1563 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1564 | if (parent) |
| 1565 | weston_matrix_multiply(matrix, &parent->transform.matrix); |
| 1566 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1567 | if (weston_matrix_invert(inverse, matrix) < 0) { |
| 1568 | /* Oops, bad total transformation, not invertible */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1569 | weston_log("error: weston_view %p" |
| 1570 | " transformation not invertible.\n", view); |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1571 | return -1; |
| 1572 | } |
| 1573 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1574 | pixman_region32_init_rect(&surfregion, 0, 0, |
| 1575 | view->surface->width, view->surface->height); |
Michael Olbrich | cb04f98 | 2020-06-08 10:22:32 +0200 | [diff] [blame] | 1576 | |
| 1577 | weston_view_update_transform_scissor(view, &surfregion); |
| 1578 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1579 | surfbox = pixman_region32_extents(&surfregion); |
| 1580 | |
| 1581 | view_compute_bbox(view, surfbox, &view->transform.boundingbox); |
| 1582 | pixman_region32_fini(&surfregion); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1583 | |
Michael Olbrich | 0e4f097 | 2020-08-19 11:31:03 +0200 | [diff] [blame] | 1584 | if (view->alpha == 1.0 && |
| 1585 | matrix->type == WESTON_MATRIX_TRANSFORM_TRANSLATE) { |
| 1586 | pixman_region32_copy(&view->transform.opaque, |
| 1587 | &view->surface->opaque); |
Derek Foreman | 713f023 | 2022-01-12 16:30:26 -0600 | [diff] [blame] | 1588 | if (view->geometry.scissor_enabled) |
| 1589 | pixman_region32_intersect(&view->transform.opaque, |
| 1590 | &view->transform.opaque, |
| 1591 | &view->geometry.scissor); |
Michael Olbrich | 0e4f097 | 2020-08-19 11:31:03 +0200 | [diff] [blame] | 1592 | pixman_region32_translate(&view->transform.opaque, |
| 1593 | matrix->d[12], |
| 1594 | matrix->d[13]); |
| 1595 | } |
| 1596 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1597 | return 0; |
| 1598 | } |
| 1599 | |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1600 | static struct weston_layer * |
| 1601 | get_view_layer(struct weston_view *view) |
| 1602 | { |
| 1603 | if (view->parent_view) |
| 1604 | return get_view_layer(view->parent_view); |
| 1605 | return view->layer_link.layer; |
| 1606 | } |
| 1607 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1608 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1609 | weston_view_update_transform(struct weston_view *view) |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1610 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1611 | struct weston_view *parent = view->geometry.parent; |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1612 | struct weston_layer *layer; |
| 1613 | pixman_region32_t mask; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1614 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1615 | if (!view->transform.dirty) |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1616 | return; |
| 1617 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1618 | if (parent) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1619 | weston_view_update_transform(parent); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1620 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1621 | view->transform.dirty = 0; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1622 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1623 | weston_view_damage_below(view); |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 1624 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1625 | pixman_region32_fini(&view->transform.boundingbox); |
| 1626 | pixman_region32_fini(&view->transform.opaque); |
| 1627 | pixman_region32_init(&view->transform.opaque); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1628 | |
Pekka Paalanen | cd40362 | 2012-01-25 13:37:39 +0200 | [diff] [blame] | 1629 | /* transform.position is always in transformation_list */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1630 | if (view->geometry.transformation_list.next == |
| 1631 | &view->transform.position.link && |
| 1632 | view->geometry.transformation_list.prev == |
| 1633 | &view->transform.position.link && |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1634 | !parent) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1635 | weston_view_update_transform_disable(view); |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1636 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1637 | if (weston_view_update_transform_enable(view) < 0) |
| 1638 | weston_view_update_transform_disable(view); |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1639 | } |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 1640 | |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1641 | layer = get_view_layer(view); |
| 1642 | if (layer) { |
| 1643 | pixman_region32_init_with_extents(&mask, &layer->mask); |
Pekka Paalanen | 25c0ca5 | 2015-02-19 11:15:33 +0200 | [diff] [blame] | 1644 | pixman_region32_intersect(&view->transform.boundingbox, |
| 1645 | &view->transform.boundingbox, &mask); |
Pekka Paalanen | 8844bf2 | 2015-02-18 16:30:47 +0200 | [diff] [blame] | 1646 | pixman_region32_intersect(&view->transform.opaque, |
| 1647 | &view->transform.opaque, &mask); |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1648 | pixman_region32_fini(&mask); |
| 1649 | } |
| 1650 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1651 | weston_view_damage_below(view); |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 1652 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1653 | weston_view_assign_output(view); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 1654 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1655 | wl_signal_emit(&view->surface->compositor->transform_signal, |
| 1656 | view->surface); |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1657 | } |
| 1658 | |
Pekka Paalanen | ddae03c | 2012-02-06 14:54:20 +0200 | [diff] [blame] | 1659 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1660 | weston_view_geometry_dirty(struct weston_view *view) |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 1661 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1662 | struct weston_view *child; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1663 | |
| 1664 | /* |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1665 | * The invariant: if view->geometry.dirty, then all views |
| 1666 | * in view->geometry.child_list have geometry.dirty too. |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1667 | * Corollary: if not parent->geometry.dirty, then all ancestors |
| 1668 | * are not dirty. |
| 1669 | */ |
| 1670 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1671 | if (view->transform.dirty) |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1672 | return; |
| 1673 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1674 | view->transform.dirty = 1; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1675 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1676 | wl_list_for_each(child, &view->geometry.child_list, |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1677 | geometry.parent_link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1678 | weston_view_geometry_dirty(child); |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 1679 | } |
| 1680 | |
| 1681 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1682 | weston_view_to_global_fixed(struct weston_view *view, |
| 1683 | wl_fixed_t vx, wl_fixed_t vy, |
| 1684 | wl_fixed_t *x, wl_fixed_t *y) |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1685 | { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1686 | float xf, yf; |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1687 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1688 | weston_view_to_global_float(view, |
| 1689 | wl_fixed_to_double(vx), |
| 1690 | wl_fixed_to_double(vy), |
| 1691 | &xf, &yf); |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1692 | *x = wl_fixed_from_double(xf); |
| 1693 | *y = wl_fixed_from_double(yf); |
| 1694 | } |
| 1695 | |
Kristian Høgsberg | ecf6ede | 2012-09-05 21:59:35 -0400 | [diff] [blame] | 1696 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1697 | weston_view_from_global_float(struct weston_view *view, |
| 1698 | float x, float y, float *vx, float *vy) |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1699 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1700 | if (view->transform.enabled) { |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1701 | struct weston_vector v = { { x, y, 0.0f, 1.0f } }; |
| 1702 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1703 | weston_matrix_transform(&view->transform.inverse, &v); |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1704 | |
| 1705 | if (fabsf(v.f[3]) < 1e-6) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1706 | weston_log("warning: numerical instability in " |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1707 | "weston_view_from_global(), divisor = %g\n", |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1708 | v.f[3]); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1709 | *vx = 0; |
| 1710 | *vy = 0; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1711 | return; |
| 1712 | } |
| 1713 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1714 | *vx = v.f[0] / v.f[3]; |
| 1715 | *vy = v.f[1] / v.f[3]; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1716 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1717 | *vx = x - view->geometry.x; |
| 1718 | *vy = y - view->geometry.y; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1719 | } |
| 1720 | } |
| 1721 | |
| 1722 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1723 | weston_view_from_global_fixed(struct weston_view *view, |
| 1724 | wl_fixed_t x, wl_fixed_t y, |
| 1725 | wl_fixed_t *vx, wl_fixed_t *vy) |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1726 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1727 | float vxf, vyf; |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1728 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1729 | weston_view_from_global_float(view, |
| 1730 | wl_fixed_to_double(x), |
| 1731 | wl_fixed_to_double(y), |
| 1732 | &vxf, &vyf); |
| 1733 | *vx = wl_fixed_from_double(vxf); |
| 1734 | *vy = wl_fixed_from_double(vyf); |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1735 | } |
| 1736 | |
| 1737 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1738 | weston_view_from_global(struct weston_view *view, |
| 1739 | int32_t x, int32_t y, int32_t *vx, int32_t *vy) |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1740 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1741 | float vxf, vyf; |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1742 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1743 | weston_view_from_global_float(view, x, y, &vxf, &vyf); |
| 1744 | *vx = floorf(vxf); |
| 1745 | *vy = floorf(vyf); |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1746 | } |
| 1747 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1748 | /** |
| 1749 | * \param surface The surface to be repainted |
| 1750 | * |
| 1751 | * Marks the output(s) that the surface is shown on as needing to be |
| 1752 | * repainted. See weston_output_schedule_repaint(). |
| 1753 | */ |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1754 | WL_EXPORT void |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1755 | weston_surface_schedule_repaint(struct weston_surface *surface) |
| 1756 | { |
| 1757 | struct weston_output *output; |
| 1758 | |
| 1759 | wl_list_for_each(output, &surface->compositor->output_list, link) |
Bryce Harrington | 89324ce | 2015-12-23 18:38:07 -0800 | [diff] [blame] | 1760 | if (surface->output_mask & (1u << output->id)) |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1761 | weston_output_schedule_repaint(output); |
| 1762 | } |
| 1763 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1764 | /** |
| 1765 | * \param view The view to be repainted |
| 1766 | * |
| 1767 | * Marks the output(s) that the view is shown on as needing to be |
| 1768 | * repainted. See weston_output_schedule_repaint(). |
| 1769 | */ |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1770 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1771 | weston_view_schedule_repaint(struct weston_view *view) |
| 1772 | { |
| 1773 | struct weston_output *output; |
| 1774 | |
| 1775 | wl_list_for_each(output, &view->surface->compositor->output_list, link) |
Bryce Harrington | 89324ce | 2015-12-23 18:38:07 -0800 | [diff] [blame] | 1776 | if (view->output_mask & (1u << output->id)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1777 | weston_output_schedule_repaint(output); |
| 1778 | } |
| 1779 | |
Pekka Paalanen | e508ce6 | 2015-02-19 13:59:55 +0200 | [diff] [blame] | 1780 | /** |
| 1781 | * XXX: This function does it the wrong way. |
| 1782 | * surface->damage is the damage from the client, and causes |
| 1783 | * surface_flush_damage() to copy pixels. No window management action can |
| 1784 | * cause damage to the client-provided content, warranting re-upload! |
| 1785 | * |
| 1786 | * Instead of surface->damage, this function should record the damage |
| 1787 | * with all the views for this surface to avoid extraneous texture |
| 1788 | * uploads. |
| 1789 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1790 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1791 | weston_surface_damage(struct weston_surface *surface) |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 1792 | { |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1793 | pixman_region32_union_rect(&surface->damage, &surface->damage, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1794 | 0, 0, surface->width, |
| 1795 | surface->height); |
Pekka Paalanen | 2267d45 | 2012-01-26 13:12:45 +0200 | [diff] [blame] | 1796 | |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1797 | weston_surface_schedule_repaint(surface); |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 1798 | } |
| 1799 | |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 1800 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1801 | weston_view_set_position(struct weston_view *view, float x, float y) |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1802 | { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1803 | if (view->geometry.x == x && view->geometry.y == y) |
| 1804 | return; |
| 1805 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1806 | view->geometry.x = x; |
| 1807 | view->geometry.y = y; |
| 1808 | weston_view_geometry_dirty(view); |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1809 | } |
| 1810 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1811 | static void |
| 1812 | transform_parent_handle_parent_destroy(struct wl_listener *listener, |
| 1813 | void *data) |
| 1814 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1815 | struct weston_view *view = |
| 1816 | container_of(listener, struct weston_view, |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1817 | geometry.parent_destroy_listener); |
| 1818 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1819 | weston_view_set_transform_parent(view, NULL); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1820 | } |
| 1821 | |
| 1822 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1823 | weston_view_set_transform_parent(struct weston_view *view, |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1824 | struct weston_view *parent) |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1825 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1826 | if (view->geometry.parent) { |
| 1827 | wl_list_remove(&view->geometry.parent_destroy_listener.link); |
| 1828 | wl_list_remove(&view->geometry.parent_link); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1829 | |
| 1830 | if (!parent) |
| 1831 | view->geometry.scissor_enabled = false; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1832 | } |
| 1833 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1834 | view->geometry.parent = parent; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1835 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1836 | view->geometry.parent_destroy_listener.notify = |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1837 | transform_parent_handle_parent_destroy; |
| 1838 | if (parent) { |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1839 | wl_signal_add(&parent->destroy_signal, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1840 | &view->geometry.parent_destroy_listener); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1841 | wl_list_insert(&parent->geometry.child_list, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1842 | &view->geometry.parent_link); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1843 | } |
| 1844 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1845 | weston_view_geometry_dirty(view); |
| 1846 | } |
| 1847 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1848 | /** Set a clip mask rectangle on a view |
| 1849 | * |
| 1850 | * \param view The view to set the clip mask on. |
| 1851 | * \param x Top-left corner X coordinate of the clip rectangle. |
| 1852 | * \param y Top-left corner Y coordinate of the clip rectangle. |
| 1853 | * \param width Width of the clip rectangle, non-negative. |
| 1854 | * \param height Height of the clip rectangle, non-negative. |
| 1855 | * |
| 1856 | * A shell may set a clip mask rectangle on a view. Everything outside |
| 1857 | * the rectangle is cut away for input and output purposes: it is |
| 1858 | * not drawn and cannot be hit by hit-test based input like pointer |
| 1859 | * motion or touch-downs. Everything inside the rectangle will behave |
| 1860 | * normally. Clients are unaware of clipping. |
| 1861 | * |
Yong Bakos | 4c72e29 | 2016-04-28 11:59:10 -0500 | [diff] [blame] | 1862 | * The rectangle is set in surface-local coordinates. Setting a clip |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1863 | * mask rectangle does not affect the view position, the view is positioned |
| 1864 | * as it would be without a clip. The clip also does not change |
| 1865 | * weston_surface::width,height. |
| 1866 | * |
| 1867 | * The clip mask rectangle is part of transformation inheritance |
| 1868 | * (weston_view_set_transform_parent()). A clip set in the root of the |
| 1869 | * transformation inheritance tree will affect all views in the tree. |
| 1870 | * A clip can be set only on the root view. Attempting to set a clip |
| 1871 | * on view that has a transformation parent will fail. Assigning a parent |
| 1872 | * to a view that has a clip set will cause the clip to be forgotten. |
| 1873 | * |
| 1874 | * Because the clip mask is an axis-aligned rectangle, it poses restrictions |
| 1875 | * on the additional transformations in the child views. These transformations |
| 1876 | * may not rotate the coordinate axes, i.e., only translation and scaling |
| 1877 | * are allowed. Violating this restriction causes the clipping to malfunction. |
| 1878 | * Furthermore, using scaling may cause rounding errors in child clipping. |
| 1879 | * |
| 1880 | * The clip mask rectangle is not automatically adjusted based on |
| 1881 | * wl_surface.attach dx and dy arguments. |
| 1882 | * |
| 1883 | * A clip mask rectangle can be set only if the compositor capability |
| 1884 | * WESTON_CAP_VIEW_CLIP_MASK is present. |
| 1885 | * |
| 1886 | * This function sets the clip mask rectangle and schedules a repaint for |
| 1887 | * the view. |
| 1888 | */ |
| 1889 | WL_EXPORT void |
| 1890 | weston_view_set_mask(struct weston_view *view, |
| 1891 | int x, int y, int width, int height) |
| 1892 | { |
| 1893 | struct weston_compositor *compositor = view->surface->compositor; |
| 1894 | |
| 1895 | if (!(compositor->capabilities & WESTON_CAP_VIEW_CLIP_MASK)) { |
| 1896 | weston_log("%s not allowed without capability!\n", __func__); |
| 1897 | return; |
| 1898 | } |
| 1899 | |
| 1900 | if (view->geometry.parent) { |
| 1901 | weston_log("view %p has a parent, clip forbidden!\n", view); |
| 1902 | return; |
| 1903 | } |
| 1904 | |
| 1905 | if (width < 0 || height < 0) { |
| 1906 | weston_log("%s: illegal args %d, %d, %d, %d\n", __func__, |
| 1907 | x, y, width, height); |
| 1908 | return; |
| 1909 | } |
| 1910 | |
| 1911 | pixman_region32_fini(&view->geometry.scissor); |
| 1912 | pixman_region32_init_rect(&view->geometry.scissor, x, y, width, height); |
| 1913 | view->geometry.scissor_enabled = true; |
| 1914 | weston_view_geometry_dirty(view); |
| 1915 | weston_view_schedule_repaint(view); |
| 1916 | } |
| 1917 | |
| 1918 | /** Remove the clip mask from a view |
| 1919 | * |
| 1920 | * \param view The view to remove the clip mask from. |
| 1921 | * |
| 1922 | * Removed the clip mask rectangle and schedules a repaint. |
| 1923 | * |
| 1924 | * \sa weston_view_set_mask |
| 1925 | */ |
| 1926 | WL_EXPORT void |
| 1927 | weston_view_set_mask_infinite(struct weston_view *view) |
| 1928 | { |
| 1929 | view->geometry.scissor_enabled = false; |
| 1930 | weston_view_geometry_dirty(view); |
| 1931 | weston_view_schedule_repaint(view); |
| 1932 | } |
| 1933 | |
Armin Krezović | 0da12b8 | 2016-06-30 06:04:33 +0200 | [diff] [blame] | 1934 | /* Check if view should be displayed |
| 1935 | * |
| 1936 | * The indicator is set manually when assigning |
| 1937 | * a view to a surface. |
| 1938 | * |
| 1939 | * This needs reworking. See the thread starting at: |
| 1940 | * |
| 1941 | * https://lists.freedesktop.org/archives/wayland-devel/2016-June/029656.html |
| 1942 | */ |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 1943 | WL_EXPORT bool |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1944 | weston_view_is_mapped(struct weston_view *view) |
| 1945 | { |
Armin Krezović | 0da12b8 | 2016-06-30 06:04:33 +0200 | [diff] [blame] | 1946 | return view->is_mapped; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1947 | } |
| 1948 | |
Philipp Zabel | 70decd5 | 2018-09-03 20:11:15 +0200 | [diff] [blame] | 1949 | /* Check if view is opaque in specified region |
| 1950 | * |
| 1951 | * \param view The view to check for opacity. |
| 1952 | * \param region The region to check for opacity, in view coordinates. |
| 1953 | * |
| 1954 | * Returns true if the view is opaque in the specified region, because view |
| 1955 | * alpha is 1.0 and either the opaque region set by the client contains the |
| 1956 | * specified region, or the buffer pixel format or solid color is opaque. |
| 1957 | */ |
| 1958 | WL_EXPORT bool |
| 1959 | weston_view_is_opaque(struct weston_view *ev, pixman_region32_t *region) |
| 1960 | { |
| 1961 | pixman_region32_t r; |
| 1962 | bool ret = false; |
| 1963 | |
| 1964 | if (ev->alpha < 1.0) |
| 1965 | return false; |
| 1966 | |
| 1967 | if (ev->surface->is_opaque) |
| 1968 | return true; |
| 1969 | |
Marius Vlad | 67b382c | 2020-08-21 13:57:54 +0300 | [diff] [blame] | 1970 | if (ev->transform.dirty) |
Philipp Zabel | 70decd5 | 2018-09-03 20:11:15 +0200 | [diff] [blame] | 1971 | return false; |
Philipp Zabel | 70decd5 | 2018-09-03 20:11:15 +0200 | [diff] [blame] | 1972 | |
| 1973 | pixman_region32_init(&r); |
| 1974 | pixman_region32_subtract(&r, region, &ev->transform.opaque); |
| 1975 | |
| 1976 | if (!pixman_region32_not_empty(&r)) |
| 1977 | ret = true; |
| 1978 | |
| 1979 | pixman_region32_fini(&r); |
| 1980 | |
| 1981 | return ret; |
| 1982 | } |
| 1983 | |
Marius Vlad | 5f6bee4 | 2019-09-11 16:41:04 +0300 | [diff] [blame] | 1984 | /** Check if the view has a valid buffer available |
| 1985 | * |
| 1986 | * @param ev The view to check if it has a valid buffer. |
| 1987 | * |
| 1988 | * Returns true if the view has a valid buffer or false otherwise. |
| 1989 | */ |
| 1990 | WL_EXPORT bool |
| 1991 | weston_view_has_valid_buffer(struct weston_view *ev) |
| 1992 | { |
| 1993 | return ev->surface->buffer_ref.buffer != NULL; |
| 1994 | } |
| 1995 | |
Marius Vlad | 47e3d1e | 2019-09-11 16:53:08 +0300 | [diff] [blame] | 1996 | /** Check if the view matches the entire output |
| 1997 | * |
| 1998 | * @param ev The view to check. |
| 1999 | * @param output The output to check against. |
| 2000 | * |
| 2001 | * Returns true if the view does indeed matches the entire output. |
| 2002 | */ |
| 2003 | WL_EXPORT bool |
| 2004 | weston_view_matches_output_entirely(struct weston_view *ev, |
| 2005 | struct weston_output *output) |
| 2006 | { |
| 2007 | pixman_box32_t *extents = |
| 2008 | pixman_region32_extents(&ev->transform.boundingbox); |
| 2009 | |
| 2010 | if (extents->x1 != output->x || |
| 2011 | extents->y1 != output->y || |
| 2012 | extents->x2 != output->x + output->width || |
| 2013 | extents->y2 != output->y + output->height) |
| 2014 | return false; |
| 2015 | |
| 2016 | return true; |
| 2017 | } |
| 2018 | |
Pekka Paalanen | 1a4f87d | 2021-04-30 14:48:52 +0300 | [diff] [blame] | 2019 | /** Find paint node for the given view and output |
| 2020 | */ |
| 2021 | WL_EXPORT struct weston_paint_node * |
| 2022 | weston_view_find_paint_node(struct weston_view *view, |
| 2023 | struct weston_output *output) |
| 2024 | { |
| 2025 | struct weston_paint_node *pnode; |
| 2026 | |
| 2027 | wl_list_for_each(pnode, &view->paint_node_list, view_link) { |
| 2028 | assert(pnode->surface == view->surface); |
| 2029 | if (pnode->output == output) |
| 2030 | return pnode; |
| 2031 | } |
| 2032 | |
| 2033 | return NULL; |
| 2034 | } |
| 2035 | |
Armin Krezović | 0da12b8 | 2016-06-30 06:04:33 +0200 | [diff] [blame] | 2036 | /* Check if a surface has a view assigned to it |
| 2037 | * |
| 2038 | * The indicator is set manually when mapping |
| 2039 | * a surface and creating a view for it. |
| 2040 | * |
| 2041 | * This needs to go. See the thread starting at: |
| 2042 | * |
| 2043 | * https://lists.freedesktop.org/archives/wayland-devel/2016-June/029656.html |
| 2044 | * |
| 2045 | */ |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 2046 | WL_EXPORT bool |
Ander Conselvan de Oliveira | b8ab14f | 2012-03-27 17:36:36 +0300 | [diff] [blame] | 2047 | weston_surface_is_mapped(struct weston_surface *surface) |
| 2048 | { |
Armin Krezović | 0da12b8 | 2016-06-30 06:04:33 +0200 | [diff] [blame] | 2049 | return surface->is_mapped; |
Ander Conselvan de Oliveira | b8ab14f | 2012-03-27 17:36:36 +0300 | [diff] [blame] | 2050 | } |
| 2051 | |
Pekka Paalanen | da75ee1 | 2013-11-26 18:19:43 +0100 | [diff] [blame] | 2052 | static void |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 2053 | 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] | 2054 | { |
| 2055 | struct weston_view *view; |
| 2056 | |
| 2057 | if (surface->width == width && surface->height == height) |
| 2058 | return; |
| 2059 | |
| 2060 | surface->width = width; |
| 2061 | surface->height = height; |
| 2062 | |
| 2063 | wl_list_for_each(view, &surface->views, surface_link) |
| 2064 | weston_view_geometry_dirty(view); |
| 2065 | } |
| 2066 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 2067 | WL_EXPORT void |
| 2068 | weston_surface_set_size(struct weston_surface *surface, |
| 2069 | int32_t width, int32_t height) |
| 2070 | { |
| 2071 | assert(!surface->resource); |
| 2072 | surface_set_size(surface, width, height); |
| 2073 | } |
| 2074 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 2075 | static int |
| 2076 | fixed_round_up_to_int(wl_fixed_t f) |
| 2077 | { |
| 2078 | return wl_fixed_to_int(wl_fixed_from_int(1) - 1 + f); |
| 2079 | } |
| 2080 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2081 | static void |
Pekka Paalanen | 59987fa | 2016-04-26 15:50:59 +0300 | [diff] [blame] | 2082 | convert_size_by_transform_scale(int32_t *width_out, int32_t *height_out, |
| 2083 | int32_t width, int32_t height, |
| 2084 | uint32_t transform, |
| 2085 | int32_t scale) |
| 2086 | { |
| 2087 | assert(scale > 0); |
| 2088 | |
| 2089 | switch (transform) { |
| 2090 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 2091 | case WL_OUTPUT_TRANSFORM_180: |
| 2092 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 2093 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 2094 | *width_out = width / scale; |
| 2095 | *height_out = height / scale; |
| 2096 | break; |
| 2097 | case WL_OUTPUT_TRANSFORM_90: |
| 2098 | case WL_OUTPUT_TRANSFORM_270: |
| 2099 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 2100 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 2101 | *width_out = height / scale; |
| 2102 | *height_out = width / scale; |
| 2103 | break; |
| 2104 | default: |
| 2105 | assert(0 && "invalid transform"); |
| 2106 | } |
| 2107 | } |
| 2108 | |
| 2109 | static void |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 2110 | weston_surface_calculate_size_from_buffer(struct weston_surface *surface) |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 2111 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 2112 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Pekka Paalanen | da75ee1 | 2013-11-26 18:19:43 +0100 | [diff] [blame] | 2113 | |
| 2114 | if (!surface->buffer_ref.buffer) { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 2115 | surface->width_from_buffer = 0; |
| 2116 | surface->height_from_buffer = 0; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 2117 | return; |
| 2118 | } |
| 2119 | |
Pekka Paalanen | 59987fa | 2016-04-26 15:50:59 +0300 | [diff] [blame] | 2120 | convert_size_by_transform_scale(&surface->width_from_buffer, |
| 2121 | &surface->height_from_buffer, |
| 2122 | surface->buffer_ref.buffer->width, |
| 2123 | surface->buffer_ref.buffer->height, |
| 2124 | vp->buffer.transform, |
| 2125 | vp->buffer.scale); |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 2126 | } |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 2127 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 2128 | static void |
| 2129 | weston_surface_update_size(struct weston_surface *surface) |
| 2130 | { |
| 2131 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
| 2132 | int32_t width, height; |
| 2133 | |
| 2134 | width = surface->width_from_buffer; |
| 2135 | height = surface->height_from_buffer; |
| 2136 | |
| 2137 | if (width != 0 && vp->surface.width != -1) { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 2138 | surface_set_size(surface, |
| 2139 | vp->surface.width, vp->surface.height); |
| 2140 | return; |
| 2141 | } |
| 2142 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 2143 | if (width != 0 && vp->buffer.src_width != wl_fixed_from_int(-1)) { |
Pekka Paalanen | e931721 | 2014-04-04 14:22:13 +0300 | [diff] [blame] | 2144 | int32_t w = fixed_round_up_to_int(vp->buffer.src_width); |
| 2145 | int32_t h = fixed_round_up_to_int(vp->buffer.src_height); |
| 2146 | |
| 2147 | surface_set_size(surface, w ?: 1, h ?: 1); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 2148 | return; |
| 2149 | } |
| 2150 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 2151 | surface_set_size(surface, width, height); |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 2152 | } |
| 2153 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 2154 | /** weston_compositor_get_time |
| 2155 | * \ingroup compositor |
| 2156 | */ |
Alexandros Frantzis | 409b01f | 2017-11-16 18:21:01 +0200 | [diff] [blame] | 2157 | WL_EXPORT void |
| 2158 | weston_compositor_get_time(struct timespec *time) |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 2159 | { |
limin.tian | c616dad | 2024-07-15 11:35:38 +0000 | [diff] [blame] | 2160 | clock_gettime(CLOCK_MONOTONIC, time); |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 2161 | } |
| 2162 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 2163 | /** weston_compositor_pick_view |
| 2164 | * \ingroup compositor |
| 2165 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2166 | WL_EXPORT struct weston_view * |
| 2167 | weston_compositor_pick_view(struct weston_compositor *compositor, |
| 2168 | wl_fixed_t x, wl_fixed_t y, |
| 2169 | wl_fixed_t *vx, wl_fixed_t *vy) |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 2170 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2171 | struct weston_view *view; |
Pekka Paalanen | fc22a52 | 2015-02-18 15:08:29 +0200 | [diff] [blame] | 2172 | wl_fixed_t view_x, view_y; |
| 2173 | int view_ix, view_iy; |
| 2174 | int ix = wl_fixed_to_int(x); |
| 2175 | int iy = wl_fixed_to_int(y); |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 2176 | |
Pekka Paalanen | 6551c09 | 2021-05-03 16:09:45 +0300 | [diff] [blame] | 2177 | /* Can't use paint node list: occlusion by input regions, not opaque. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2178 | wl_list_for_each(view, &compositor->view_list, link) { |
Pekka Paalanen | fc22a52 | 2015-02-18 15:08:29 +0200 | [diff] [blame] | 2179 | if (!pixman_region32_contains_point( |
| 2180 | &view->transform.boundingbox, ix, iy, NULL)) |
| 2181 | continue; |
| 2182 | |
| 2183 | weston_view_from_global_fixed(view, x, y, &view_x, &view_y); |
| 2184 | view_ix = wl_fixed_to_int(view_x); |
| 2185 | view_iy = wl_fixed_to_int(view_y); |
| 2186 | |
| 2187 | if (!pixman_region32_contains_point(&view->surface->input, |
| 2188 | view_ix, view_iy, NULL)) |
| 2189 | continue; |
| 2190 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 2191 | if (view->geometry.scissor_enabled && |
| 2192 | !pixman_region32_contains_point(&view->geometry.scissor, |
| 2193 | view_ix, view_iy, NULL)) |
| 2194 | continue; |
| 2195 | |
Pekka Paalanen | fc22a52 | 2015-02-18 15:08:29 +0200 | [diff] [blame] | 2196 | *vx = view_x; |
| 2197 | *vy = view_y; |
| 2198 | return view; |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 2199 | } |
| 2200 | |
Derek Foreman | f9318d1 | 2015-05-11 15:40:11 -0500 | [diff] [blame] | 2201 | *vx = wl_fixed_from_int(-1000000); |
| 2202 | *vy = wl_fixed_from_int(-1000000); |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 2203 | return NULL; |
| 2204 | } |
| 2205 | |
| 2206 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2207 | weston_compositor_repick(struct weston_compositor *compositor) |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 2208 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2209 | struct weston_seat *seat; |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 2210 | |
Kristian Høgsberg | 10ddd97 | 2013-10-22 12:40:54 -0700 | [diff] [blame] | 2211 | if (!compositor->session_active) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 2212 | return; |
| 2213 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 2214 | wl_list_for_each(seat, &compositor->seat_list, link) |
Kristian Høgsberg | a71e8b2 | 2013-05-06 21:51:21 -0400 | [diff] [blame] | 2215 | weston_seat_repick(seat); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 2216 | } |
| 2217 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 2218 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2219 | weston_view_unmap(struct weston_view *view) |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 2220 | { |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 2221 | struct weston_seat *seat; |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 2222 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2223 | if (!weston_view_is_mapped(view)) |
| 2224 | return; |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 2225 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2226 | weston_view_damage_below(view); |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 2227 | weston_view_set_output(view, NULL); |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 2228 | view->plane = NULL; |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 2229 | view->is_mapped = false; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2230 | weston_layer_entry_remove(&view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2231 | wl_list_remove(&view->link); |
| 2232 | wl_list_init(&view->link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2233 | view->output_mask = 0; |
| 2234 | weston_surface_assign_output(view->surface); |
| 2235 | |
| 2236 | if (weston_surface_is_mapped(view->surface)) |
| 2237 | return; |
| 2238 | |
| 2239 | wl_list_for_each(seat, &view->surface->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2240 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 2241 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 2242 | struct weston_keyboard *keyboard = |
| 2243 | weston_seat_get_keyboard(seat); |
| 2244 | |
| 2245 | if (keyboard && keyboard->focus == view->surface) |
| 2246 | weston_keyboard_set_focus(keyboard, NULL); |
| 2247 | if (pointer && pointer->focus == view) |
Derek Foreman | f9318d1 | 2015-05-11 15:40:11 -0500 | [diff] [blame] | 2248 | weston_pointer_clear_focus(pointer); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 2249 | if (touch && touch->focus == view) |
| 2250 | weston_touch_set_focus(touch, NULL); |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 2251 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2252 | } |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 2253 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2254 | WL_EXPORT void |
| 2255 | weston_surface_unmap(struct weston_surface *surface) |
| 2256 | { |
| 2257 | struct weston_view *view; |
| 2258 | |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 2259 | surface->is_mapped = false; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2260 | wl_list_for_each(view, &surface->views, surface_link) |
| 2261 | weston_view_unmap(view); |
| 2262 | surface->output = NULL; |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 2263 | } |
| 2264 | |
Pekka Paalanen | 3c9b802 | 2014-03-14 14:38:13 +0200 | [diff] [blame] | 2265 | static void |
| 2266 | weston_surface_reset_pending_buffer(struct weston_surface *surface) |
| 2267 | { |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2268 | weston_surface_state_set_buffer(&surface->pending, NULL); |
Pekka Paalanen | 3c9b802 | 2014-03-14 14:38:13 +0200 | [diff] [blame] | 2269 | surface->pending.sx = 0; |
| 2270 | surface->pending.sy = 0; |
| 2271 | surface->pending.newly_attached = 0; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 2272 | surface->pending.buffer_viewport.changed = 0; |
Pekka Paalanen | 3c9b802 | 2014-03-14 14:38:13 +0200 | [diff] [blame] | 2273 | } |
| 2274 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2275 | WL_EXPORT void |
| 2276 | weston_view_destroy(struct weston_view *view) |
| 2277 | { |
Pekka Paalanen | 1a4f87d | 2021-04-30 14:48:52 +0300 | [diff] [blame] | 2278 | struct weston_paint_node *pnode, *pntmp; |
Marius Vlad | f2452d6 | 2021-12-09 14:07:21 +0200 | [diff] [blame] | 2279 | weston_signal_emit_mutable(&view->destroy_signal, view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2280 | |
| 2281 | assert(wl_list_empty(&view->geometry.child_list)); |
| 2282 | |
| 2283 | if (weston_view_is_mapped(view)) { |
| 2284 | weston_view_unmap(view); |
Pekka Paalanen | 1a4f87d | 2021-04-30 14:48:52 +0300 | [diff] [blame] | 2285 | weston_compositor_build_view_list(view->surface->compositor, |
| 2286 | NULL); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2287 | } |
| 2288 | |
Pekka Paalanen | 1a4f87d | 2021-04-30 14:48:52 +0300 | [diff] [blame] | 2289 | wl_list_for_each_safe(pnode, pntmp, &view->paint_node_list, view_link) |
| 2290 | weston_paint_node_destroy(pnode); |
| 2291 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2292 | wl_list_remove(&view->link); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2293 | weston_layer_entry_remove(&view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2294 | |
| 2295 | pixman_region32_fini(&view->clip); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 2296 | pixman_region32_fini(&view->geometry.scissor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2297 | pixman_region32_fini(&view->transform.boundingbox); |
Pekka Paalanen | 8844bf2 | 2015-02-18 16:30:47 +0200 | [diff] [blame] | 2298 | pixman_region32_fini(&view->transform.opaque); |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 2299 | #ifdef MESON_VIDEO_PLAN_SUPPORT |
| 2300 | pixman_region32_fini(&view->transform.transparent); |
| 2301 | #endif |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2302 | |
| 2303 | weston_view_set_transform_parent(view, NULL); |
Pekka Paalanen | 944fae8 | 2018-05-22 13:15:58 +0300 | [diff] [blame] | 2304 | weston_view_set_output(view, NULL); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2305 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2306 | wl_list_remove(&view->surface_link); |
| 2307 | |
| 2308 | free(view); |
| 2309 | } |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2310 | |
| 2311 | WL_EXPORT void |
| 2312 | weston_surface_destroy(struct weston_surface *surface) |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 2313 | { |
limin.tian | a0140a7 | 2024-10-12 07:28:49 +0000 | [diff] [blame] | 2314 | weston_log("\n weston_surface_destroy :%p output:%p name :%s \n", surface, surface->output, surface->name); |
Vlad Zahorodnii | c2b9747 | 2021-07-29 11:16:51 +0300 | [diff] [blame] | 2315 | struct wl_resource *cb, *next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2316 | struct weston_view *ev, *nv; |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 2317 | struct weston_pointer_constraint *constraint, *next_constraint; |
Pekka Paalanen | 1a4f87d | 2021-04-30 14:48:52 +0300 | [diff] [blame] | 2318 | struct weston_paint_node *pnode, *pntmp; |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 2319 | |
Giulio Camuffo | 13b85bd | 2013-08-13 23:10:14 +0200 | [diff] [blame] | 2320 | if (--surface->ref_count > 0) |
| 2321 | return; |
| 2322 | |
Pekka Paalanen | 08d3fb7 | 2015-04-17 14:00:24 +0300 | [diff] [blame] | 2323 | assert(surface->resource == NULL); |
| 2324 | |
Alexandros Frantzis | fa48c5e | 2020-07-09 17:31:34 +0300 | [diff] [blame] | 2325 | weston_signal_emit_mutable(&surface->destroy_signal, surface); |
Giulio Camuffo | 13b85bd | 2013-08-13 23:10:14 +0200 | [diff] [blame] | 2326 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2327 | assert(wl_list_empty(&surface->subsurface_list_pending)); |
| 2328 | assert(wl_list_empty(&surface->subsurface_list)); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 2329 | |
Leandro Ribeiro | 8eb8414 | 2021-01-18 19:36:48 -0300 | [diff] [blame] | 2330 | if (surface->dmabuf_feedback) |
| 2331 | weston_dmabuf_feedback_destroy(surface->dmabuf_feedback); |
| 2332 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2333 | wl_list_for_each_safe(ev, nv, &surface->views, surface_link) |
| 2334 | weston_view_destroy(ev); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 2335 | |
Pekka Paalanen | 1a4f87d | 2021-04-30 14:48:52 +0300 | [diff] [blame] | 2336 | wl_list_for_each_safe(pnode, pntmp, |
| 2337 | &surface->paint_node_list, surface_link) { |
| 2338 | weston_paint_node_destroy(pnode); |
| 2339 | } |
| 2340 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2341 | weston_surface_state_fini(&surface->pending); |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2342 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2343 | weston_buffer_reference(&surface->buffer_ref, NULL); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2344 | weston_buffer_release_reference(&surface->buffer_release_ref, NULL); |
Kristian Høgsberg | 3f8f39c | 2009-09-18 17:05:13 -0400 | [diff] [blame] | 2345 | |
Pekka Paalanen | 402ae6d | 2012-01-03 10:23:24 +0200 | [diff] [blame] | 2346 | pixman_region32_fini(&surface->damage); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2347 | pixman_region32_fini(&surface->opaque); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 2348 | pixman_region32_fini(&surface->input); |
Pekka Paalanen | 402ae6d | 2012-01-03 10:23:24 +0200 | [diff] [blame] | 2349 | |
Vlad Zahorodnii | c2b9747 | 2021-07-29 11:16:51 +0300 | [diff] [blame] | 2350 | wl_resource_for_each_safe(cb, next, &surface->frame_callback_list) |
| 2351 | wl_resource_destroy(cb); |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 2352 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2353 | weston_presentation_feedback_discard_list(&surface->feedback_list); |
| 2354 | |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 2355 | wl_list_for_each_safe(constraint, next_constraint, |
| 2356 | &surface->pointer_constraints, |
| 2357 | link) |
| 2358 | weston_pointer_constraint_destroy(constraint); |
| 2359 | |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2360 | fd_clear(&surface->acquire_fence_fd); |
| 2361 | |
limin.tian | a0140a7 | 2024-10-12 07:28:49 +0000 | [diff] [blame] | 2362 | weston_set_appstate_by_appname(surface->compositor, surface->name, 0); |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 2363 | weston_clear_video_surface_info(surface); |
leng.fang | dbaf6fa | 2024-06-20 19:31:04 +0800 | [diff] [blame] | 2364 | weston_surface_destroy_info_for_surface(surface); |
limin.tian | 531dd23 | 2025-01-07 12:09:27 +0000 | [diff] [blame] | 2365 | weston_log("weston_surface_destroy :%p output:%p name :%s \n", surface, surface->output, surface->name); |
leng.fang | dbaf6fa | 2024-06-20 19:31:04 +0800 | [diff] [blame] | 2366 | |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 2367 | free(surface); |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 2368 | } |
| 2369 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2370 | static void |
| 2371 | destroy_surface(struct wl_resource *resource) |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 2372 | { |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2373 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 2374 | |
Pekka Paalanen | 08d3fb7 | 2015-04-17 14:00:24 +0300 | [diff] [blame] | 2375 | assert(surface); |
| 2376 | |
Giulio Camuffo | 0d37974 | 2013-11-15 22:06:15 +0100 | [diff] [blame] | 2377 | /* Set the resource to NULL, since we don't want to leave a |
| 2378 | * dangling pointer if the surface was refcounted and survives |
| 2379 | * the weston_surface_destroy() call. */ |
| 2380 | surface->resource = NULL; |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 2381 | |
| 2382 | if (surface->viewport_resource) |
| 2383 | wl_resource_set_user_data(surface->viewport_resource, NULL); |
| 2384 | |
Alexandros Frantzis | 27d7c39 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2385 | if (surface->synchronization_resource) { |
| 2386 | wl_resource_set_user_data(surface->synchronization_resource, |
| 2387 | NULL); |
| 2388 | } |
| 2389 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2390 | weston_surface_destroy(surface); |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 2391 | } |
| 2392 | |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 2393 | static void |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2394 | weston_buffer_destroy_handler(struct wl_listener *listener, void *data) |
| 2395 | { |
| 2396 | struct weston_buffer *buffer = |
| 2397 | container_of(listener, struct weston_buffer, destroy_listener); |
| 2398 | |
limin.tian | 531dd23 | 2025-01-07 12:09:27 +0000 | [diff] [blame] | 2399 | weston_log("weston_buffer_destroy_handler buffer:%p\n",buffer); |
Marius Vlad | f2452d6 | 2021-12-09 14:07:21 +0200 | [diff] [blame] | 2400 | weston_signal_emit_mutable(&buffer->destroy_signal, buffer); |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2401 | free(buffer); |
| 2402 | } |
| 2403 | |
Giulio Camuffo | e058cd1 | 2013-12-12 14:14:29 +0100 | [diff] [blame] | 2404 | WL_EXPORT struct weston_buffer * |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2405 | weston_buffer_from_resource(struct wl_resource *resource) |
| 2406 | { |
| 2407 | struct weston_buffer *buffer; |
| 2408 | struct wl_listener *listener; |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 2409 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2410 | listener = wl_resource_get_destroy_listener(resource, |
| 2411 | weston_buffer_destroy_handler); |
| 2412 | |
Kristian Høgsberg | 08b58c7 | 2013-08-15 12:26:42 -0700 | [diff] [blame] | 2413 | if (listener) |
| 2414 | return container_of(listener, struct weston_buffer, |
| 2415 | destroy_listener); |
| 2416 | |
| 2417 | buffer = zalloc(sizeof *buffer); |
| 2418 | if (buffer == NULL) |
| 2419 | return NULL; |
| 2420 | |
| 2421 | buffer->resource = resource; |
| 2422 | wl_signal_init(&buffer->destroy_signal); |
| 2423 | buffer->destroy_listener.notify = weston_buffer_destroy_handler; |
Stanislav Vorobiov | bfbb8e5 | 2013-08-29 11:36:44 +0400 | [diff] [blame] | 2424 | buffer->y_inverted = 1; |
Kristian Høgsberg | 08b58c7 | 2013-08-15 12:26:42 -0700 | [diff] [blame] | 2425 | wl_resource_add_destroy_listener(resource, &buffer->destroy_listener); |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 2426 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2427 | return buffer; |
| 2428 | } |
| 2429 | |
| 2430 | static void |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2431 | weston_buffer_reference_handle_destroy(struct wl_listener *listener, |
| 2432 | void *data) |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 2433 | { |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2434 | struct weston_buffer_reference *ref = |
| 2435 | container_of(listener, struct weston_buffer_reference, |
| 2436 | destroy_listener); |
| 2437 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2438 | assert((struct weston_buffer *)data == ref->buffer); |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2439 | ref->buffer = NULL; |
| 2440 | } |
| 2441 | |
| 2442 | WL_EXPORT void |
| 2443 | weston_buffer_reference(struct weston_buffer_reference *ref, |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2444 | struct weston_buffer *buffer) |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2445 | { |
| 2446 | if (ref->buffer && buffer != ref->buffer) { |
Kristian Høgsberg | 2034780 | 2013-03-04 12:07:46 -0500 | [diff] [blame] | 2447 | ref->buffer->busy_count--; |
| 2448 | if (ref->buffer->busy_count == 0) { |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2449 | assert(wl_resource_get_client(ref->buffer->resource)); |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 2450 | buffer_send_release(ref); |
Kristian Høgsberg | 2034780 | 2013-03-04 12:07:46 -0500 | [diff] [blame] | 2451 | } |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2452 | wl_list_remove(&ref->destroy_listener.link); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2453 | } |
| 2454 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2455 | if (buffer && buffer != ref->buffer) { |
Kristian Høgsberg | b7b77e6 | 2012-09-05 22:38:18 -0400 | [diff] [blame] | 2456 | buffer->busy_count++; |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2457 | wl_signal_add(&buffer->destroy_signal, |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2458 | &ref->destroy_listener); |
Pekka Paalanen | a6421c4 | 2012-12-04 15:58:10 +0200 | [diff] [blame] | 2459 | } |
| 2460 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2461 | ref->buffer = buffer; |
| 2462 | ref->destroy_listener.notify = weston_buffer_reference_handle_destroy; |
| 2463 | } |
| 2464 | |
| 2465 | static void |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2466 | weston_buffer_release_reference_handle_destroy(struct wl_listener *listener, |
| 2467 | void *data) |
| 2468 | { |
| 2469 | struct weston_buffer_release_reference *ref = |
| 2470 | container_of(listener, struct weston_buffer_release_reference, |
| 2471 | destroy_listener); |
| 2472 | |
| 2473 | assert((struct wl_resource *)data == ref->buffer_release->resource); |
| 2474 | ref->buffer_release = NULL; |
| 2475 | } |
| 2476 | |
| 2477 | static void |
| 2478 | weston_buffer_release_destroy(struct weston_buffer_release *buffer_release) |
| 2479 | { |
| 2480 | struct wl_resource *resource = buffer_release->resource; |
| 2481 | int release_fence_fd = buffer_release->fence_fd; |
| 2482 | |
| 2483 | if (release_fence_fd >= 0) { |
| 2484 | zwp_linux_buffer_release_v1_send_fenced_release( |
| 2485 | resource, release_fence_fd); |
| 2486 | } else { |
| 2487 | zwp_linux_buffer_release_v1_send_immediate_release( |
| 2488 | resource); |
| 2489 | } |
| 2490 | |
| 2491 | wl_resource_destroy(resource); |
| 2492 | } |
| 2493 | |
| 2494 | WL_EXPORT void |
| 2495 | weston_buffer_release_reference(struct weston_buffer_release_reference *ref, |
| 2496 | struct weston_buffer_release *buffer_release) |
| 2497 | { |
| 2498 | if (buffer_release == ref->buffer_release) |
| 2499 | return; |
| 2500 | |
| 2501 | if (ref->buffer_release) { |
| 2502 | ref->buffer_release->ref_count--; |
| 2503 | wl_list_remove(&ref->destroy_listener.link); |
| 2504 | if (ref->buffer_release->ref_count == 0) |
| 2505 | weston_buffer_release_destroy(ref->buffer_release); |
| 2506 | } |
| 2507 | |
| 2508 | if (buffer_release) { |
| 2509 | buffer_release->ref_count++; |
| 2510 | wl_resource_add_destroy_listener(buffer_release->resource, |
| 2511 | &ref->destroy_listener); |
| 2512 | } |
| 2513 | |
| 2514 | ref->buffer_release = buffer_release; |
| 2515 | ref->destroy_listener.notify = |
| 2516 | weston_buffer_release_reference_handle_destroy; |
| 2517 | } |
| 2518 | |
| 2519 | WL_EXPORT void |
| 2520 | weston_buffer_release_move(struct weston_buffer_release_reference *dest, |
| 2521 | struct weston_buffer_release_reference *src) |
| 2522 | { |
| 2523 | weston_buffer_release_reference(dest, src->buffer_release); |
| 2524 | weston_buffer_release_reference(src, NULL); |
| 2525 | } |
| 2526 | |
| 2527 | static void |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2528 | weston_surface_attach(struct weston_surface *surface, |
| 2529 | struct weston_buffer *buffer) |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2530 | { |
| 2531 | weston_buffer_reference(&surface->buffer_ref, buffer); |
| 2532 | |
Pekka Paalanen | a6421c4 | 2012-12-04 15:58:10 +0200 | [diff] [blame] | 2533 | if (!buffer) { |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2534 | if (weston_surface_is_mapped(surface)) |
| 2535 | weston_surface_unmap(surface); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2536 | } |
| 2537 | |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 2538 | weston_video_surface_attach(surface, buffer); |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2539 | surface->compositor->renderer->attach(surface, buffer); |
Pekka Paalanen | bb2f3f2 | 2014-03-14 14:38:11 +0200 | [diff] [blame] | 2540 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 2541 | weston_surface_calculate_size_from_buffer(surface); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2542 | weston_presentation_feedback_discard_list(&surface->feedback_list); |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 2543 | } |
| 2544 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 2545 | /** weston_compositor_damage_all |
| 2546 | * \ingroup compositor |
| 2547 | */ |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2548 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2549 | weston_compositor_damage_all(struct weston_compositor *compositor) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2550 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2551 | struct weston_output *output; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2552 | |
| 2553 | wl_list_for_each(output, &compositor->output_list, link) |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2554 | weston_output_damage(output); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2555 | } |
| 2556 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 2557 | /** |
| 2558 | * \ingroup output |
| 2559 | */ |
Kristian Høgsberg | 9f404b7 | 2012-01-26 00:11:01 -0500 | [diff] [blame] | 2560 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2561 | weston_output_damage(struct weston_output *output) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2562 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2563 | struct weston_compositor *compositor = output->compositor; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2564 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 2565 | pixman_region32_union(&compositor->primary_plane.damage, |
| 2566 | &compositor->primary_plane.damage, |
| 2567 | &output->region); |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2568 | weston_output_schedule_repaint(output); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2569 | } |
| 2570 | |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame] | 2571 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2572 | surface_flush_damage(struct weston_surface *surface) |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2573 | { |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2574 | if (surface->buffer_ref.buffer && |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2575 | wl_shm_buffer_get(surface->buffer_ref.buffer->resource)) |
Kristian Høgsberg | fa1be02 | 2012-09-05 22:49:55 -0400 | [diff] [blame] | 2576 | surface->compositor->renderer->flush_damage(surface); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2577 | |
Marius Vlad | 2a1b786 | 2019-09-05 13:12:18 +0300 | [diff] [blame] | 2578 | if (pixman_region32_not_empty(&surface->damage)) |
Marius Vlad | 3203ff6 | 2019-09-05 14:56:12 +0300 | [diff] [blame] | 2579 | TL_POINT(surface->compositor, "core_flush_damage", TLP_SURFACE(surface), |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2580 | TLP_OUTPUT(surface->output), TLP_END); |
| 2581 | |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 2582 | pixman_region32_clear(&surface->damage); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2583 | } |
| 2584 | |
| 2585 | static void |
| 2586 | view_accumulate_damage(struct weston_view *view, |
| 2587 | pixman_region32_t *opaque) |
| 2588 | { |
| 2589 | pixman_region32_t damage; |
| 2590 | |
| 2591 | pixman_region32_init(&damage); |
| 2592 | if (view->transform.enabled) { |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2593 | pixman_box32_t *extents; |
| 2594 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2595 | extents = pixman_region32_extents(&view->surface->damage); |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 2596 | view_compute_bbox(view, extents, &damage); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2597 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2598 | pixman_region32_copy(&damage, &view->surface->damage); |
| 2599 | pixman_region32_translate(&damage, |
Pekka Paalanen | 502f5e0 | 2015-02-23 14:08:25 +0200 | [diff] [blame] | 2600 | view->geometry.x, view->geometry.y); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2601 | } |
| 2602 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 2603 | pixman_region32_intersect(&damage, &damage, |
| 2604 | &view->transform.boundingbox); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2605 | pixman_region32_subtract(&damage, &damage, opaque); |
| 2606 | pixman_region32_union(&view->plane->damage, |
| 2607 | &view->plane->damage, &damage); |
| 2608 | pixman_region32_fini(&damage); |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 2609 | #if MESON_VIDEO_PLAN_SUPPORT |
| 2610 | pixman_region32_union(&view->clip, &view->clip, opaque); |
| 2611 | #else |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2612 | pixman_region32_copy(&view->clip, opaque); |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 2613 | #endif |
Pekka Paalanen | 8844bf2 | 2015-02-18 16:30:47 +0200 | [diff] [blame] | 2614 | pixman_region32_union(opaque, opaque, &view->transform.opaque); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2615 | } |
| 2616 | |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 2617 | static void |
Michael Olbrich | c5ea495 | 2020-08-11 12:42:35 +0200 | [diff] [blame] | 2618 | output_accumulate_damage(struct weston_output *output) |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2619 | { |
Michael Olbrich | c5ea495 | 2020-08-11 12:42:35 +0200 | [diff] [blame] | 2620 | struct weston_compositor *ec = output->compositor; |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2621 | struct weston_plane *plane; |
Pekka Paalanen | 20ab6f8 | 2021-05-03 14:06:55 +0300 | [diff] [blame] | 2622 | struct weston_paint_node *pnode; |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2623 | pixman_region32_t opaque, clip; |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2624 | |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2625 | pixman_region32_init(&clip); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2626 | |
| 2627 | wl_list_for_each(plane, &ec->plane_list, link) { |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2628 | pixman_region32_copy(&plane->clip, &clip); |
| 2629 | |
| 2630 | pixman_region32_init(&opaque); |
| 2631 | |
Pekka Paalanen | 20ab6f8 | 2021-05-03 14:06:55 +0300 | [diff] [blame] | 2632 | wl_list_for_each(pnode, &output->paint_node_z_order_list, |
| 2633 | z_order_link) { |
| 2634 | if (pnode->view->plane != plane) |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2635 | continue; |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 2636 | #if MESON_VIDEO_PLAN_SUPPORT |
| 2637 | // meson platform video plane is below primary plane.(but the zpos may hight then primary plane. |
| 2638 | // Avoid video plane region make the primary plane be occlude. |
| 2639 | |
| 2640 | // We assume the overlay plane only have one surface, on weston just primary plane support glrender compositor. |
| 2641 | if (!pnode->view->surface->is_video_surface) |
| 2642 | #endif |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2643 | |
Pekka Paalanen | 20ab6f8 | 2021-05-03 14:06:55 +0300 | [diff] [blame] | 2644 | view_accumulate_damage(pnode->view, &opaque); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2645 | } |
| 2646 | |
| 2647 | pixman_region32_union(&clip, &clip, &opaque); |
| 2648 | pixman_region32_fini(&opaque); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2649 | } |
| 2650 | |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2651 | pixman_region32_fini(&clip); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2652 | |
Pekka Paalanen | 20ab6f8 | 2021-05-03 14:06:55 +0300 | [diff] [blame] | 2653 | wl_list_for_each(pnode, &output->paint_node_z_order_list, |
| 2654 | z_order_link) { |
| 2655 | pnode->surface->touched = false; |
| 2656 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2657 | |
Pekka Paalanen | 20ab6f8 | 2021-05-03 14:06:55 +0300 | [diff] [blame] | 2658 | wl_list_for_each(pnode, &output->paint_node_z_order_list, |
| 2659 | z_order_link) { |
Michael Olbrich | c5ea495 | 2020-08-11 12:42:35 +0200 | [diff] [blame] | 2660 | /* Ignore views not visible on the current output */ |
Pekka Paalanen | 20ab6f8 | 2021-05-03 14:06:55 +0300 | [diff] [blame] | 2661 | /* TODO: turn this into assert once z_order_list is pruned. */ |
| 2662 | if (!(pnode->view->output_mask & (1u << output->id))) |
Michael Olbrich | c5ea495 | 2020-08-11 12:42:35 +0200 | [diff] [blame] | 2663 | continue; |
Pekka Paalanen | 20ab6f8 | 2021-05-03 14:06:55 +0300 | [diff] [blame] | 2664 | if (pnode->surface->touched) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2665 | continue; |
Pekka Paalanen | 20ab6f8 | 2021-05-03 14:06:55 +0300 | [diff] [blame] | 2666 | pnode->surface->touched = true; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2667 | |
Pekka Paalanen | 20ab6f8 | 2021-05-03 14:06:55 +0300 | [diff] [blame] | 2668 | surface_flush_damage(pnode->surface); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2669 | |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2670 | /* Both the renderer and the backend have seen the buffer |
| 2671 | * by now. If renderer needs the buffer, it has its own |
| 2672 | * reference set. If the backend wants to keep the buffer |
| 2673 | * around for migrating the surface into a non-primary plane |
| 2674 | * later, keep_buffer is true. Otherwise, drop the core |
| 2675 | * reference now, and allow early buffer release. This enables |
| 2676 | * clients to use single-buffering. |
| 2677 | */ |
Pekka Paalanen | 20ab6f8 | 2021-05-03 14:06:55 +0300 | [diff] [blame] | 2678 | if (!pnode->surface->keep_buffer) { |
| 2679 | weston_buffer_reference(&pnode->surface->buffer_ref, NULL); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2680 | weston_buffer_release_reference( |
Pekka Paalanen | 20ab6f8 | 2021-05-03 14:06:55 +0300 | [diff] [blame] | 2681 | &pnode->surface->buffer_release_ref, NULL); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2682 | } |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2683 | } |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2684 | } |
| 2685 | |
| 2686 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2687 | surface_stash_subsurface_views(struct weston_surface *surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2688 | { |
| 2689 | struct weston_subsurface *sub; |
| 2690 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2691 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2692 | if (sub->surface == surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2693 | continue; |
| 2694 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2695 | wl_list_insert_list(&sub->unused_views, &sub->surface->views); |
| 2696 | wl_list_init(&sub->surface->views); |
| 2697 | |
| 2698 | surface_stash_subsurface_views(sub->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2699 | } |
| 2700 | } |
| 2701 | |
| 2702 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2703 | surface_free_unused_subsurface_views(struct weston_surface *surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2704 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2705 | struct weston_subsurface *sub; |
| 2706 | struct weston_view *view, *nv; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2707 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2708 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
| 2709 | if (sub->surface == surface) |
| 2710 | continue; |
| 2711 | |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 2712 | wl_list_for_each_safe(view, nv, &sub->unused_views, surface_link) { |
| 2713 | weston_view_unmap (view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2714 | weston_view_destroy(view); |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 2715 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2716 | |
| 2717 | surface_free_unused_subsurface_views(sub->surface); |
| 2718 | } |
| 2719 | } |
| 2720 | |
Pekka Paalanen | 1a4f87d | 2021-04-30 14:48:52 +0300 | [diff] [blame] | 2721 | static struct weston_paint_node * |
| 2722 | view_ensure_paint_node(struct weston_view *view, struct weston_output *output) |
| 2723 | { |
| 2724 | struct weston_paint_node *pnode; |
| 2725 | |
| 2726 | if (!output) |
| 2727 | return NULL; |
| 2728 | |
| 2729 | pnode = weston_view_find_paint_node(view, output); |
| 2730 | if (pnode) |
| 2731 | return pnode; |
| 2732 | |
| 2733 | return weston_paint_node_create(view->surface, view, output); |
| 2734 | } |
| 2735 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2736 | static void |
Pekka Paalanen | 2fddc53 | 2021-04-30 17:41:29 +0300 | [diff] [blame] | 2737 | add_to_z_order_list(struct weston_output *output, |
| 2738 | struct weston_paint_node *pnode) |
| 2739 | { |
| 2740 | if (!pnode) |
| 2741 | return; |
limin.tian | 230ec58 | 2024-07-30 09:35:17 +0000 | [diff] [blame] | 2742 | if (pnode->view && pnode->view->surface && pnode->view->surface->invisible) |
| 2743 | return; |
Pekka Paalanen | 2fddc53 | 2021-04-30 17:41:29 +0300 | [diff] [blame] | 2744 | wl_list_remove(&pnode->z_order_link); |
| 2745 | wl_list_insert(output->paint_node_z_order_list.prev, |
| 2746 | &pnode->z_order_link); |
Pekka Paalanen | 90a5ffa | 2021-02-25 12:03:28 +0200 | [diff] [blame] | 2747 | |
| 2748 | /* |
| 2749 | * Building weston_output::paint_node_z_order_list ensures all |
| 2750 | * necessary color transform objects are installed. |
| 2751 | */ |
| 2752 | weston_paint_node_ensure_color_transform(pnode); |
Pekka Paalanen | 2fddc53 | 2021-04-30 17:41:29 +0300 | [diff] [blame] | 2753 | } |
| 2754 | |
| 2755 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2756 | view_list_add_subsurface_view(struct weston_compositor *compositor, |
| 2757 | struct weston_subsurface *sub, |
Pekka Paalanen | 1a4f87d | 2021-04-30 14:48:52 +0300 | [diff] [blame] | 2758 | struct weston_view *parent, |
| 2759 | struct weston_output *output) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2760 | { |
| 2761 | struct weston_subsurface *child; |
| 2762 | struct weston_view *view = NULL, *iv; |
Pekka Paalanen | 2fddc53 | 2021-04-30 17:41:29 +0300 | [diff] [blame] | 2763 | struct weston_paint_node *pnode; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2764 | |
Pekka Paalanen | 661de3a | 2014-07-28 12:49:24 +0300 | [diff] [blame] | 2765 | if (!weston_surface_is_mapped(sub->surface)) |
| 2766 | return; |
| 2767 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2768 | wl_list_for_each(iv, &sub->unused_views, surface_link) { |
| 2769 | if (iv->geometry.parent == parent) { |
| 2770 | view = iv; |
| 2771 | break; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2772 | } |
| 2773 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2774 | |
| 2775 | if (view) { |
| 2776 | /* Put it back in the surface's list of views */ |
| 2777 | wl_list_remove(&view->surface_link); |
| 2778 | wl_list_insert(&sub->surface->views, &view->surface_link); |
| 2779 | } else { |
| 2780 | view = weston_view_create(sub->surface); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2781 | weston_view_set_position(view, |
| 2782 | sub->position.x, |
| 2783 | sub->position.y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2784 | weston_view_set_transform_parent(view, parent); |
| 2785 | } |
| 2786 | |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 2787 | view->parent_view = parent; |
limin.tian | ce0f9d7 | 2024-08-06 06:30:57 +0000 | [diff] [blame] | 2788 | weston_update_subsurface_position(sub, view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2789 | weston_view_update_transform(view); |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 2790 | view->is_mapped = true; |
Pekka Paalanen | 2fddc53 | 2021-04-30 17:41:29 +0300 | [diff] [blame] | 2791 | pnode = view_ensure_paint_node(view, output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2792 | |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2793 | if (wl_list_empty(&sub->surface->subsurface_list)) { |
| 2794 | wl_list_insert(compositor->view_list.prev, &view->link); |
Pekka Paalanen | 2fddc53 | 2021-04-30 17:41:29 +0300 | [diff] [blame] | 2795 | add_to_z_order_list(output, pnode); |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2796 | return; |
| 2797 | } |
| 2798 | |
| 2799 | wl_list_for_each(child, &sub->surface->subsurface_list, parent_link) { |
Pekka Paalanen | 2fddc53 | 2021-04-30 17:41:29 +0300 | [diff] [blame] | 2800 | if (child->surface == sub->surface) { |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2801 | wl_list_insert(compositor->view_list.prev, &view->link); |
Pekka Paalanen | 2fddc53 | 2021-04-30 17:41:29 +0300 | [diff] [blame] | 2802 | add_to_z_order_list(output, pnode); |
| 2803 | } else { |
Pekka Paalanen | 1a4f87d | 2021-04-30 14:48:52 +0300 | [diff] [blame] | 2804 | view_list_add_subsurface_view(compositor, child, view, output); |
Pekka Paalanen | 2fddc53 | 2021-04-30 17:41:29 +0300 | [diff] [blame] | 2805 | } |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2806 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2807 | } |
| 2808 | |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 2809 | /* This recursively adds the sub-surfaces for a view, relying on the |
| 2810 | * sub-surface order. Thus, if a client restacks the sub-surfaces, that |
| 2811 | * change first happens to the sub-surface list, and then automatically |
| 2812 | * propagates here. See weston_surface_damage_subsurfaces() for how the |
| 2813 | * sub-surfaces receive damage when the client changes the state. |
| 2814 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2815 | static void |
| 2816 | view_list_add(struct weston_compositor *compositor, |
Pekka Paalanen | 1a4f87d | 2021-04-30 14:48:52 +0300 | [diff] [blame] | 2817 | struct weston_view *view, |
| 2818 | struct weston_output *output) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2819 | { |
Pekka Paalanen | 2fddc53 | 2021-04-30 17:41:29 +0300 | [diff] [blame] | 2820 | struct weston_paint_node *pnode; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2821 | struct weston_subsurface *sub; |
| 2822 | |
leng.fang | a0f2092 | 2024-10-11 17:23:59 +0800 | [diff] [blame] | 2823 | if (!weston_compositor_get_view_visible(view)) |
leng.fang | dbaf6fa | 2024-06-20 19:31:04 +0800 | [diff] [blame] | 2824 | return; |
| 2825 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2826 | weston_view_update_transform(view); |
Pekka Paalanen | 2fddc53 | 2021-04-30 17:41:29 +0300 | [diff] [blame] | 2827 | pnode = view_ensure_paint_node(view, output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2828 | |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2829 | if (wl_list_empty(&view->surface->subsurface_list)) { |
| 2830 | wl_list_insert(compositor->view_list.prev, &view->link); |
Pekka Paalanen | 2fddc53 | 2021-04-30 17:41:29 +0300 | [diff] [blame] | 2831 | add_to_z_order_list(output, pnode); |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2832 | return; |
| 2833 | } |
| 2834 | |
| 2835 | wl_list_for_each(sub, &view->surface->subsurface_list, parent_link) { |
Pekka Paalanen | 2fddc53 | 2021-04-30 17:41:29 +0300 | [diff] [blame] | 2836 | if (sub->surface == view->surface) { |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2837 | wl_list_insert(compositor->view_list.prev, &view->link); |
Pekka Paalanen | 2fddc53 | 2021-04-30 17:41:29 +0300 | [diff] [blame] | 2838 | add_to_z_order_list(output, pnode); |
| 2839 | } else { |
Pekka Paalanen | 1a4f87d | 2021-04-30 14:48:52 +0300 | [diff] [blame] | 2840 | view_list_add_subsurface_view(compositor, sub, view, output); |
Pekka Paalanen | 2fddc53 | 2021-04-30 17:41:29 +0300 | [diff] [blame] | 2841 | } |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2842 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2843 | } |
| 2844 | |
| 2845 | static void |
Pekka Paalanen | 1a4f87d | 2021-04-30 14:48:52 +0300 | [diff] [blame] | 2846 | weston_compositor_build_view_list(struct weston_compositor *compositor, |
| 2847 | struct weston_output *output) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2848 | { |
Loïc Yhuel | 267b16e | 2019-09-17 20:14:56 +0200 | [diff] [blame] | 2849 | struct weston_view *view, *tmp; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2850 | struct weston_layer *layer; |
| 2851 | |
Pekka Paalanen | 2fddc53 | 2021-04-30 17:41:29 +0300 | [diff] [blame] | 2852 | if (output) { |
| 2853 | wl_list_remove(&output->paint_node_z_order_list); |
| 2854 | wl_list_init(&output->paint_node_z_order_list); |
| 2855 | } |
| 2856 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2857 | wl_list_for_each(layer, &compositor->layer_list, link) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2858 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2859 | surface_stash_subsurface_views(view->surface); |
| 2860 | |
Dongjin Kim | f3b1188 | 2025-05-14 03:49:08 +0000 | [diff] [blame] | 2861 | if (!compositor->disable_simpleshell) |
| 2862 | weston_compositor_build_view_list_by_zorder(compositor); |
Loïc Yhuel | 267b16e | 2019-09-17 20:14:56 +0200 | [diff] [blame] | 2863 | wl_list_for_each_safe(view, tmp, &compositor->view_list, link) |
| 2864 | wl_list_init(&view->link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2865 | wl_list_init(&compositor->view_list); |
Loïc Yhuel | 267b16e | 2019-09-17 20:14:56 +0200 | [diff] [blame] | 2866 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2867 | wl_list_for_each(layer, &compositor->layer_list, link) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2868 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
Pekka Paalanen | 1a4f87d | 2021-04-30 14:48:52 +0300 | [diff] [blame] | 2869 | view_list_add(compositor, view, output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2870 | } |
| 2871 | } |
| 2872 | |
| 2873 | wl_list_for_each(layer, &compositor->layer_list, link) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2874 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2875 | surface_free_unused_subsurface_views(view->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2876 | } |
| 2877 | |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2878 | static void |
| 2879 | weston_output_take_feedback_list(struct weston_output *output, |
| 2880 | struct weston_surface *surface) |
| 2881 | { |
| 2882 | struct weston_view *view; |
| 2883 | struct weston_presentation_feedback *feedback; |
| 2884 | uint32_t flags = 0xffffffff; |
| 2885 | |
| 2886 | if (wl_list_empty(&surface->feedback_list)) |
| 2887 | return; |
| 2888 | |
| 2889 | /* All views must have the flag for the flag to survive. */ |
| 2890 | wl_list_for_each(view, &surface->views, surface_link) { |
| 2891 | /* ignore views that are not on this output at all */ |
| 2892 | if (view->output_mask & (1u << output->id)) |
| 2893 | flags &= view->psf_flags; |
| 2894 | } |
| 2895 | |
| 2896 | wl_list_for_each(feedback, &surface->feedback_list, link) |
| 2897 | feedback->psf_flags = flags; |
| 2898 | |
| 2899 | wl_list_insert_list(&output->feedback_list, &surface->feedback_list); |
| 2900 | wl_list_init(&surface->feedback_list); |
| 2901 | } |
| 2902 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2903 | static int |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2904 | weston_output_repaint(struct weston_output *output, void *repaint_data) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2905 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2906 | struct weston_compositor *ec = output->compositor; |
Pekka Paalanen | 6d6b367 | 2021-05-03 14:06:55 +0300 | [diff] [blame] | 2907 | struct weston_paint_node *pnode; |
Kristian Høgsberg | 30c018b | 2012-01-26 08:40:37 -0500 | [diff] [blame] | 2908 | struct weston_animation *animation, *next; |
Vlad Zahorodnii | c2b9747 | 2021-07-29 11:16:51 +0300 | [diff] [blame] | 2909 | struct wl_resource *cb, *cnext; |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 2910 | struct wl_list frame_callback_list; |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2911 | pixman_region32_t output_damage; |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2912 | int r; |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 2913 | uint32_t frame_time_msec; |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 2914 | enum weston_hdcp_protection highest_requested = WESTON_HDCP_DISABLE; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 2915 | |
Ander Conselvan de Oliveira | e1e2352 | 2013-12-13 22:10:55 +0200 | [diff] [blame] | 2916 | if (output->destroying) |
| 2917 | return 0; |
| 2918 | |
Marius Vlad | 3203ff6 | 2019-09-05 14:56:12 +0300 | [diff] [blame] | 2919 | TL_POINT(ec, "core_repaint_begin", TLP_OUTPUT(output), TLP_END); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2920 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2921 | /* Rebuild the surface list and update surface transforms up front. */ |
Pekka Paalanen | 1a4f87d | 2021-04-30 14:48:52 +0300 | [diff] [blame] | 2922 | weston_compositor_build_view_list(ec, output); |
Pekka Paalanen | 15d60ef | 2012-01-27 14:38:33 +0200 | [diff] [blame] | 2923 | |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 2924 | /* Find the highest protection desired for an output */ |
Pekka Paalanen | 6d6b367 | 2021-05-03 14:06:55 +0300 | [diff] [blame] | 2925 | wl_list_for_each(pnode, &output->paint_node_z_order_list, |
| 2926 | z_order_link) { |
| 2927 | /* TODO: turn this into assert once z_order_list is pruned. */ |
| 2928 | if ((pnode->surface->output_mask & (1u << output->id)) == 0) |
| 2929 | continue; |
| 2930 | |
| 2931 | /* |
| 2932 | * The desired_protection of the output should be the |
| 2933 | * maximum of the desired_protection of the surfaces, |
| 2934 | * that are displayed on that output, to avoid |
| 2935 | * reducing the protection for existing surfaces. |
| 2936 | */ |
| 2937 | if (pnode->surface->desired_protection > highest_requested) |
| 2938 | highest_requested = pnode->surface->desired_protection; |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 2939 | } |
| 2940 | |
| 2941 | output->desired_protection = highest_requested; |
| 2942 | |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2943 | if (output->assign_planes && !output->disable_planes) { |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2944 | output->assign_planes(output, repaint_data); |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2945 | } else { |
Pekka Paalanen | 6d6b367 | 2021-05-03 14:06:55 +0300 | [diff] [blame] | 2946 | wl_list_for_each(pnode, &output->paint_node_z_order_list, |
| 2947 | z_order_link) { |
| 2948 | weston_view_move_to_plane(pnode->view, &ec->primary_plane); |
| 2949 | pnode->view->psf_flags = 0; |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2950 | } |
| 2951 | } |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 2952 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2953 | wl_list_init(&frame_callback_list); |
Pekka Paalanen | 6d6b367 | 2021-05-03 14:06:55 +0300 | [diff] [blame] | 2954 | wl_list_for_each(pnode, &output->paint_node_z_order_list, |
| 2955 | z_order_link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2956 | /* Note: This operation is safe to do multiple times on the |
| 2957 | * same surface. |
| 2958 | */ |
Pekka Paalanen | 6d6b367 | 2021-05-03 14:06:55 +0300 | [diff] [blame] | 2959 | if (pnode->surface->output == output) { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2960 | wl_list_insert_list(&frame_callback_list, |
Pekka Paalanen | 6d6b367 | 2021-05-03 14:06:55 +0300 | [diff] [blame] | 2961 | &pnode->surface->frame_callback_list); |
| 2962 | wl_list_init(&pnode->surface->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2963 | |
Pekka Paalanen | 6d6b367 | 2021-05-03 14:06:55 +0300 | [diff] [blame] | 2964 | weston_output_take_feedback_list(output, pnode->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2965 | } |
| 2966 | } |
| 2967 | |
Michael Olbrich | c5ea495 | 2020-08-11 12:42:35 +0200 | [diff] [blame] | 2968 | output_accumulate_damage(output); |
Kristian Høgsberg | 53df1d8 | 2011-06-23 21:11:19 -0400 | [diff] [blame] | 2969 | |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 2970 | pixman_region32_init(&output_damage); |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 2971 | pixman_region32_intersect(&output_damage, |
| 2972 | &ec->primary_plane.damage, &output->region); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2973 | pixman_region32_subtract(&output_damage, |
| 2974 | &output_damage, &ec->primary_plane.clip); |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 2975 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2976 | if (output->dirty) |
| 2977 | weston_output_update_matrix(output); |
| 2978 | |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2979 | r = output->repaint(output, &output_damage, repaint_data); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2980 | |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 2981 | pixman_region32_fini(&output_damage); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 2982 | |
Daniel Stone | 09a97e2 | 2017-03-01 11:34:06 +0000 | [diff] [blame] | 2983 | output->repaint_needed = false; |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2984 | if (r == 0) |
| 2985 | output->repaint_status = REPAINT_AWAITING_COMPLETION; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 2986 | |
Kristian Høgsberg | aa6019e | 2012-03-11 16:35:16 -0400 | [diff] [blame] | 2987 | weston_compositor_repick(ec); |
Kristian Høgsberg | aa6019e | 2012-03-11 16:35:16 -0400 | [diff] [blame] | 2988 | |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 2989 | frame_time_msec = timespec_to_msec(&output->frame_time); |
limin.tian | 531dd23 | 2025-01-07 12:09:27 +0000 | [diff] [blame] | 2990 | WESTON_LOGD(COMMON_LOG, "send callback\n"); |
Vlad Zahorodnii | c2b9747 | 2021-07-29 11:16:51 +0300 | [diff] [blame] | 2991 | wl_resource_for_each_safe(cb, cnext, &frame_callback_list) { |
| 2992 | wl_callback_send_done(cb, frame_time_msec); |
| 2993 | wl_resource_destroy(cb); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 2994 | } |
| 2995 | |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 2996 | wl_list_for_each_safe(animation, next, &output->animation_list, link) { |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 2997 | animation->frame_counter++; |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 2998 | animation->frame(animation, output, &output->frame_time); |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 2999 | } |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 3000 | |
Marius Vlad | 3203ff6 | 2019-09-05 14:56:12 +0300 | [diff] [blame] | 3001 | TL_POINT(ec, "core_repaint_posted", TLP_OUTPUT(output), TLP_END); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3002 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 3003 | return r; |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 3004 | } |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 3005 | |
Pekka Paalanen | 8291979 | 2014-05-21 13:51:49 +0300 | [diff] [blame] | 3006 | static void |
| 3007 | weston_output_schedule_repaint_reset(struct weston_output *output) |
| 3008 | { |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 3009 | output->repaint_status = REPAINT_NOT_SCHEDULED; |
Marius Vlad | 3203ff6 | 2019-09-05 14:56:12 +0300 | [diff] [blame] | 3010 | TL_POINT(output->compositor, "core_repaint_exit_loop", |
| 3011 | TLP_OUTPUT(output), TLP_END); |
Pekka Paalanen | 8291979 | 2014-05-21 13:51:49 +0300 | [diff] [blame] | 3012 | } |
| 3013 | |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 3014 | static int |
| 3015 | weston_output_maybe_repaint(struct weston_output *output, struct timespec *now, |
| 3016 | void *repaint_data) |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 3017 | { |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 3018 | struct weston_compositor *compositor = output->compositor; |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 3019 | int ret = 0; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 3020 | int64_t msec_to_repaint; |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 3021 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 3022 | /* We're not ready yet; come back to make a decision later. */ |
| 3023 | if (output->repaint_status != REPAINT_SCHEDULED) |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 3024 | return ret; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 3025 | |
| 3026 | msec_to_repaint = timespec_sub_to_msec(&output->next_repaint, now); |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 3027 | if (msec_to_repaint > 1) { |
limin.tian | 531dd23 | 2025-01-07 12:09:27 +0000 | [diff] [blame] | 3028 | WESTON_LOGD(COMMON_LOG, "msec_to_repaint > 1\n"); |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 3029 | return ret; |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 3030 | } |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 3031 | |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 3032 | /* If we're sleeping, drop the repaint machinery entirely; we will |
| 3033 | * explicitly repaint all outputs when we come back. */ |
| 3034 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING || |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 3035 | compositor->state == WESTON_COMPOSITOR_OFFSCREEN) { |
limin.tian | 531dd23 | 2025-01-07 12:09:27 +0000 | [diff] [blame] | 3036 | WESTON_LOGD(COMMON_LOG, "state:%d\n", compositor->state); |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 3037 | goto err; |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 3038 | } |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 3039 | /* We don't actually need to repaint this output; drop it from |
| 3040 | * repaint until something causes damage. */ |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 3041 | if (!output->repaint_needed) { |
limin.tian | 531dd23 | 2025-01-07 12:09:27 +0000 | [diff] [blame] | 3042 | WESTON_LOGD(COMMON_LOG, "repaint not needed\n"); |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 3043 | goto err; |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 3044 | } |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 3045 | |
| 3046 | /* If repaint fails, we aren't going to get weston_output_finish_frame |
| 3047 | * to trigger a new repaint, so drop it from repaint and hope |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 3048 | * something schedules a successful repaint later. As repainting may |
| 3049 | * take some time, re-read our clock as a courtesy to the next |
| 3050 | * output. */ |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 3051 | ret = weston_output_repaint(output, repaint_data); |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 3052 | weston_compositor_read_presentation_clock(compositor, now); |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 3053 | if (ret != 0) { |
limin.tian | 531dd23 | 2025-01-07 12:09:27 +0000 | [diff] [blame] | 3054 | WESTON_LOGD(COMMON_LOG, "fail\n"); |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 3055 | goto err; |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 3056 | } |
Tomohito Esaki | 7f4d9ff | 2018-06-05 10:37:06 +0900 | [diff] [blame] | 3057 | output->repainted = true; |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 3058 | return ret; |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 3059 | |
| 3060 | err: |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 3061 | weston_output_schedule_repaint_reset(output); |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 3062 | return ret; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 3063 | } |
| 3064 | |
| 3065 | static void |
| 3066 | output_repaint_timer_arm(struct weston_compositor *compositor) |
| 3067 | { |
| 3068 | struct weston_output *output; |
| 3069 | bool any_should_repaint = false; |
| 3070 | struct timespec now; |
Sergi Granell | b4c0886 | 2017-03-18 13:01:15 +0100 | [diff] [blame] | 3071 | int64_t msec_to_next = INT64_MAX; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 3072 | |
| 3073 | weston_compositor_read_presentation_clock(compositor, &now); |
| 3074 | |
| 3075 | wl_list_for_each(output, &compositor->output_list, link) { |
| 3076 | int64_t msec_to_this; |
| 3077 | |
| 3078 | if (output->repaint_status != REPAINT_SCHEDULED) |
| 3079 | continue; |
| 3080 | |
| 3081 | msec_to_this = timespec_sub_to_msec(&output->next_repaint, |
| 3082 | &now); |
| 3083 | if (!any_should_repaint || msec_to_this < msec_to_next) |
| 3084 | msec_to_next = msec_to_this; |
| 3085 | |
| 3086 | any_should_repaint = true; |
| 3087 | } |
| 3088 | |
| 3089 | if (!any_should_repaint) |
| 3090 | return; |
| 3091 | |
| 3092 | /* Even if we should repaint immediately, add the minimum 1 ms delay. |
| 3093 | * This is a workaround to allow coalescing multiple output repaints |
| 3094 | * particularly from weston_output_finish_frame() |
| 3095 | * into the same call, which would not happen if we called |
| 3096 | * output_repaint_timer_handler() directly. |
| 3097 | */ |
| 3098 | if (msec_to_next < 1) |
| 3099 | msec_to_next = 1; |
| 3100 | |
| 3101 | wl_event_source_timer_update(compositor->repaint_timer, msec_to_next); |
| 3102 | } |
| 3103 | |
| 3104 | static int |
| 3105 | output_repaint_timer_handler(void *data) |
| 3106 | { |
| 3107 | struct weston_compositor *compositor = data; |
| 3108 | struct weston_output *output; |
| 3109 | struct timespec now; |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 3110 | void *repaint_data = NULL; |
Emre Ucan | e479ed8 | 2018-03-20 15:29:40 +0100 | [diff] [blame] | 3111 | int ret = 0; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 3112 | |
| 3113 | weston_compositor_read_presentation_clock(compositor, &now); |
Pekka Paalanen | 1ed2cad | 2021-02-10 12:33:03 +0200 | [diff] [blame] | 3114 | compositor->last_repaint_start = now; |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 3115 | |
| 3116 | if (compositor->backend->repaint_begin) |
| 3117 | repaint_data = compositor->backend->repaint_begin(compositor); |
| 3118 | |
| 3119 | wl_list_for_each(output, &compositor->output_list, link) { |
| 3120 | ret = weston_output_maybe_repaint(output, &now, repaint_data); |
| 3121 | if (ret) |
| 3122 | break; |
| 3123 | } |
| 3124 | |
| 3125 | if (ret == 0) { |
Tomohito Esaki | 09bfcd6 | 2018-06-05 10:37:05 +0900 | [diff] [blame] | 3126 | if (compositor->backend->repaint_flush) |
Antonio Borneo | c90fccc | 2019-06-30 15:51:10 +0200 | [diff] [blame] | 3127 | ret = compositor->backend->repaint_flush(compositor, |
| 3128 | repaint_data); |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 3129 | } else { |
Antonio Borneo | c90fccc | 2019-06-30 15:51:10 +0200 | [diff] [blame] | 3130 | if (compositor->backend->repaint_cancel) |
| 3131 | compositor->backend->repaint_cancel(compositor, |
| 3132 | repaint_data); |
| 3133 | } |
| 3134 | |
| 3135 | if (ret != 0) { |
Tomohito Esaki | 7f4d9ff | 2018-06-05 10:37:06 +0900 | [diff] [blame] | 3136 | wl_list_for_each(output, &compositor->output_list, link) { |
| 3137 | if (output->repainted) |
| 3138 | weston_output_schedule_repaint_reset(output); |
| 3139 | } |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 3140 | } |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 3141 | |
Tomohito Esaki | ddaf95c | 2018-07-10 11:47:15 +0900 | [diff] [blame] | 3142 | wl_list_for_each(output, &compositor->output_list, link) |
| 3143 | output->repainted = false; |
| 3144 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 3145 | output_repaint_timer_arm(compositor); |
| 3146 | |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 3147 | return 0; |
| 3148 | } |
| 3149 | |
Pekka Paalanen | 50aa3a7 | 2020-05-28 11:34:04 +0300 | [diff] [blame] | 3150 | /** Convert a presentation timestamp to another clock domain |
| 3151 | * |
| 3152 | * \param compositor The compositor defines the presentation clock domain. |
| 3153 | * \param presentation_stamp The timestamp in presentation clock domain. |
| 3154 | * \param presentation_now Current time in presentation clock domain. |
| 3155 | * \param target_clock Defines the target clock domain. |
| 3156 | * |
| 3157 | * This approximation relies on presentation_stamp to be close to current time. |
| 3158 | * The further it is from current time and the bigger the speed difference |
| 3159 | * between the two clock domains, the bigger the conversion error. |
| 3160 | * |
| 3161 | * Conversion error due to system load is biased and unbounded. |
| 3162 | */ |
| 3163 | static struct timespec |
| 3164 | convert_presentation_time_now(struct weston_compositor *compositor, |
| 3165 | const struct timespec *presentation_stamp, |
| 3166 | const struct timespec *presentation_now, |
| 3167 | clockid_t target_clock) |
| 3168 | { |
| 3169 | struct timespec target_now = {}; |
| 3170 | struct timespec target_stamp; |
| 3171 | int64_t delta_ns; |
| 3172 | |
| 3173 | if (compositor->presentation_clock == target_clock) |
| 3174 | return *presentation_stamp; |
| 3175 | |
| 3176 | clock_gettime(target_clock, &target_now); |
| 3177 | delta_ns = timespec_sub_to_nsec(presentation_stamp, presentation_now); |
| 3178 | timespec_add_nsec(&target_stamp, &target_now, delta_ns); |
| 3179 | |
| 3180 | return target_stamp; |
| 3181 | } |
| 3182 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 3183 | /** |
| 3184 | * \ingroup output |
| 3185 | */ |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 3186 | WL_EXPORT void |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 3187 | weston_output_finish_frame(struct weston_output *output, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 3188 | const struct timespec *stamp, |
| 3189 | uint32_t presented_flags) |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 3190 | { |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 3191 | struct weston_compositor *compositor = output->compositor; |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 3192 | int32_t refresh_nsec; |
| 3193 | struct timespec now; |
Pekka Paalanen | 50aa3a7 | 2020-05-28 11:34:04 +0300 | [diff] [blame] | 3194 | struct timespec vblank_monotonic; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 3195 | int64_t msec_rel; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3196 | |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 3197 | assert(output->repaint_status == REPAINT_AWAITING_COMPLETION); |
Pekka Paalanen | 98b4e20 | 2021-05-10 11:33:23 +0300 | [diff] [blame] | 3198 | |
| 3199 | /* |
| 3200 | * If timestamp of latest vblank is given, it must always go forwards. |
| 3201 | * If not given, INVALID flag must be set. |
| 3202 | */ |
| 3203 | if (stamp) |
| 3204 | assert(timespec_sub_to_nsec(stamp, &output->frame_time) >= 0); |
| 3205 | else |
| 3206 | assert(presented_flags & WP_PRESENTATION_FEEDBACK_INVALID); |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 3207 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 3208 | weston_compositor_read_presentation_clock(compositor, &now); |
| 3209 | |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 3210 | /* If we haven't been supplied any timestamp at all, we don't have a |
| 3211 | * timebase to work against, so any delay just wastes time. Push a |
| 3212 | * repaint as soon as possible so we can get on with it. */ |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 3213 | if (!stamp) { |
| 3214 | output->next_repaint = now; |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 3215 | goto out; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 3216 | } |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 3217 | |
Pekka Paalanen | 50aa3a7 | 2020-05-28 11:34:04 +0300 | [diff] [blame] | 3218 | vblank_monotonic = convert_presentation_time_now(compositor, |
| 3219 | stamp, &now, |
| 3220 | CLOCK_MONOTONIC); |
Marius Vlad | 3203ff6 | 2019-09-05 14:56:12 +0300 | [diff] [blame] | 3221 | TL_POINT(compositor, "core_repaint_finished", TLP_OUTPUT(output), |
Pekka Paalanen | 50aa3a7 | 2020-05-28 11:34:04 +0300 | [diff] [blame] | 3222 | TLP_VBLANK(&vblank_monotonic), TLP_END); |
Marius Vlad | df9278a | 2018-03-06 18:56:23 +0200 | [diff] [blame] | 3223 | |
Pekka Paalanen | d7894d0 | 2015-07-03 15:08:53 +0300 | [diff] [blame] | 3224 | refresh_nsec = millihz_to_nsec(output->current_mode->refresh); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3225 | weston_presentation_feedback_present_list(&output->feedback_list, |
| 3226 | output, refresh_nsec, stamp, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 3227 | output->msc, |
| 3228 | presented_flags); |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 3229 | |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 3230 | output->frame_time = *stamp; |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 3231 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 3232 | timespec_add_nsec(&output->next_repaint, stamp, refresh_nsec); |
| 3233 | timespec_add_msec(&output->next_repaint, &output->next_repaint, |
| 3234 | -compositor->repaint_msec); |
| 3235 | msec_rel = timespec_sub_to_msec(&output->next_repaint, &now); |
Daniel Stone | 84aff5c | 2017-03-01 11:34:04 +0000 | [diff] [blame] | 3236 | |
| 3237 | if (msec_rel < -1000 || msec_rel > 1000) { |
Pekka Paalanen | 8fd4de4 | 2015-03-19 12:27:29 +0200 | [diff] [blame] | 3238 | static bool warned; |
| 3239 | |
| 3240 | if (!warned) |
| 3241 | weston_log("Warning: computed repaint delay is " |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 3242 | "insane: %lld msec\n", (long long) msec_rel); |
Pekka Paalanen | 8fd4de4 | 2015-03-19 12:27:29 +0200 | [diff] [blame] | 3243 | warned = true; |
| 3244 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 3245 | output->next_repaint = now; |
Pekka Paalanen | 8fd4de4 | 2015-03-19 12:27:29 +0200 | [diff] [blame] | 3246 | } |
| 3247 | |
Mario Kleiner | b7df04e | 2015-06-21 21:25:15 +0200 | [diff] [blame] | 3248 | /* Called from restart_repaint_loop and restart happens already after |
| 3249 | * the deadline given by repaint_msec? In that case we delay until |
| 3250 | * the deadline of the next frame, to give clients a more predictable |
| 3251 | * timing of the repaint cycle to lock on. */ |
Daniel Stone | eca5cca | 2017-02-28 21:53:51 +0000 | [diff] [blame] | 3252 | if (presented_flags == WP_PRESENTATION_FEEDBACK_INVALID && |
| 3253 | msec_rel < 0) { |
| 3254 | while (timespec_sub_to_nsec(&output->next_repaint, &now) < 0) { |
| 3255 | timespec_add_nsec(&output->next_repaint, |
| 3256 | &output->next_repaint, |
| 3257 | refresh_nsec); |
| 3258 | } |
| 3259 | } |
Mario Kleiner | b7df04e | 2015-06-21 21:25:15 +0200 | [diff] [blame] | 3260 | |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 3261 | out: |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 3262 | output->repaint_status = REPAINT_SCHEDULED; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 3263 | output_repaint_timer_arm(compositor); |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 3264 | } |
| 3265 | |
nerdopolis | d2a320d | 2021-08-23 21:29:42 -0400 | [diff] [blame] | 3266 | |
| 3267 | WL_EXPORT void |
| 3268 | weston_output_repaint_failed(struct weston_output *output) |
| 3269 | { |
| 3270 | weston_log("Clearing repaint status.\n"); |
| 3271 | assert(output->repaint_status == REPAINT_AWAITING_COMPLETION); |
| 3272 | output->repaint_status = REPAINT_NOT_SCHEDULED; |
| 3273 | } |
| 3274 | |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 3275 | static void |
| 3276 | idle_repaint(void *data) |
| 3277 | { |
| 3278 | struct weston_output *output = data; |
Antonio Borneo | c90fccc | 2019-06-30 15:51:10 +0200 | [diff] [blame] | 3279 | int ret; |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 3280 | assert(output->repaint_status == REPAINT_BEGIN_FROM_IDLE); |
| 3281 | output->repaint_status = REPAINT_AWAITING_COMPLETION; |
Pekka Paalanen | dcbcfc7 | 2017-10-26 14:33:59 +0300 | [diff] [blame] | 3282 | output->idle_repaint_source = NULL; |
Antonio Borneo | c90fccc | 2019-06-30 15:51:10 +0200 | [diff] [blame] | 3283 | ret = output->start_repaint_loop(output); |
| 3284 | if (ret != 0) |
| 3285 | weston_output_schedule_repaint_reset(output); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 3286 | } |
| 3287 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3288 | WL_EXPORT void |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3289 | weston_layer_entry_insert(struct weston_layer_entry *list, |
| 3290 | struct weston_layer_entry *entry) |
| 3291 | { |
| 3292 | wl_list_insert(&list->link, &entry->link); |
| 3293 | entry->layer = list->layer; |
| 3294 | } |
| 3295 | |
| 3296 | WL_EXPORT void |
| 3297 | weston_layer_entry_remove(struct weston_layer_entry *entry) |
| 3298 | { |
| 3299 | wl_list_remove(&entry->link); |
| 3300 | wl_list_init(&entry->link); |
| 3301 | entry->layer = NULL; |
| 3302 | } |
| 3303 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 3304 | |
| 3305 | /** Initialize the weston_layer struct. |
| 3306 | * |
| 3307 | * \param compositor The compositor instance |
| 3308 | * \param layer The layer to initialize |
| 3309 | */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3310 | WL_EXPORT void |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 3311 | weston_layer_init(struct weston_layer *layer, |
| 3312 | struct weston_compositor *compositor) |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3313 | { |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 3314 | layer->compositor = compositor; |
| 3315 | wl_list_init(&layer->link); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 3316 | wl_list_init(&layer->view_list.link); |
| 3317 | layer->view_list.layer = layer; |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 3318 | weston_layer_set_mask_infinite(layer); |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 3319 | } |
| 3320 | |
Pekka Paalanen | 8740037 | 2021-05-14 14:29:40 +0300 | [diff] [blame] | 3321 | /** Finalize the weston_layer struct. |
| 3322 | * |
| 3323 | * \param layer The layer to finalize. |
| 3324 | */ |
| 3325 | WL_EXPORT void |
| 3326 | weston_layer_fini(struct weston_layer *layer) |
| 3327 | { |
| 3328 | wl_list_remove(&layer->link); |
| 3329 | |
| 3330 | if (!wl_list_empty(&layer->view_list.link)) |
| 3331 | weston_log("BUG: finalizing a layer with views still on it.\n"); |
| 3332 | |
| 3333 | wl_list_remove(&layer->view_list.link); |
| 3334 | } |
| 3335 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 3336 | /** Sets the position of the layer in the layer list. The layer will be placed |
| 3337 | * below any layer with the same position value, if any. |
| 3338 | * This function is safe to call if the layer is already on the list, but the |
| 3339 | * layer may be moved below other layers at the same position, if any. |
| 3340 | * |
| 3341 | * \param layer The layer to modify |
| 3342 | * \param position The position the layer will be placed at |
| 3343 | */ |
| 3344 | WL_EXPORT void |
| 3345 | weston_layer_set_position(struct weston_layer *layer, |
| 3346 | enum weston_layer_position position) |
| 3347 | { |
| 3348 | struct weston_layer *below; |
| 3349 | |
| 3350 | wl_list_remove(&layer->link); |
| 3351 | |
| 3352 | /* layer_list is ordered from top to bottom, the last layer being the |
| 3353 | * background with the smallest position value */ |
| 3354 | |
| 3355 | layer->position = position; |
| 3356 | wl_list_for_each_reverse(below, &layer->compositor->layer_list, link) { |
| 3357 | if (below->position >= layer->position) { |
| 3358 | wl_list_insert(&below->link, &layer->link); |
| 3359 | return; |
| 3360 | } |
| 3361 | } |
| 3362 | wl_list_insert(&layer->compositor->layer_list, &layer->link); |
| 3363 | } |
| 3364 | |
| 3365 | /** Hide a layer by taking it off the layer list. |
| 3366 | * This function is safe to call if the layer is not on the list. |
| 3367 | * |
| 3368 | * \param layer The layer to hide |
| 3369 | */ |
| 3370 | WL_EXPORT void |
| 3371 | weston_layer_unset_position(struct weston_layer *layer) |
| 3372 | { |
| 3373 | wl_list_remove(&layer->link); |
| 3374 | wl_list_init(&layer->link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 3375 | } |
| 3376 | |
| 3377 | WL_EXPORT void |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 3378 | weston_layer_set_mask(struct weston_layer *layer, |
| 3379 | int x, int y, int width, int height) |
| 3380 | { |
| 3381 | struct weston_view *view; |
| 3382 | |
| 3383 | layer->mask.x1 = x; |
| 3384 | layer->mask.x2 = x + width; |
| 3385 | layer->mask.y1 = y; |
| 3386 | layer->mask.y2 = y + height; |
| 3387 | |
| 3388 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
| 3389 | weston_view_geometry_dirty(view); |
| 3390 | } |
| 3391 | } |
| 3392 | |
| 3393 | WL_EXPORT void |
| 3394 | weston_layer_set_mask_infinite(struct weston_layer *layer) |
| 3395 | { |
Adam Jackson | 3c3f3b1 | 2019-10-16 16:02:59 -0400 | [diff] [blame] | 3396 | struct weston_view *view; |
| 3397 | |
| 3398 | layer->mask.x1 = INT32_MIN; |
| 3399 | layer->mask.x2 = INT32_MAX; |
| 3400 | layer->mask.y1 = INT32_MIN; |
| 3401 | layer->mask.y2 = INT32_MAX; |
| 3402 | |
| 3403 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
| 3404 | weston_view_geometry_dirty(view); |
| 3405 | } |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 3406 | } |
| 3407 | |
Daniel Stone | 3b77563 | 2018-07-20 08:38:25 +0100 | [diff] [blame] | 3408 | WL_EXPORT bool |
| 3409 | weston_layer_mask_is_infinite(struct weston_layer *layer) |
| 3410 | { |
| 3411 | return layer->mask.x1 == INT32_MIN && |
| 3412 | layer->mask.y1 == INT32_MIN && |
Adam Jackson | 3c3f3b1 | 2019-10-16 16:02:59 -0400 | [diff] [blame] | 3413 | layer->mask.x2 == INT32_MAX && |
| 3414 | layer->mask.y2 == INT32_MAX; |
Daniel Stone | 3b77563 | 2018-07-20 08:38:25 +0100 | [diff] [blame] | 3415 | } |
| 3416 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 3417 | /** |
| 3418 | * \ingroup output |
| 3419 | */ |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 3420 | WL_EXPORT void |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 3421 | weston_output_schedule_repaint(struct weston_output *output) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 3422 | { |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 3423 | struct weston_compositor *compositor = output->compositor; |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 3424 | struct wl_event_loop *loop; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 3425 | |
Bryce Harrington | 08976ac | 2016-08-30 12:05:16 -0700 | [diff] [blame] | 3426 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING || |
| 3427 | compositor->state == WESTON_COMPOSITOR_OFFSCREEN) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 3428 | return; |
| 3429 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3430 | if (!output->repaint_needed) |
Marius Vlad | 3203ff6 | 2019-09-05 14:56:12 +0300 | [diff] [blame] | 3431 | TL_POINT(compositor, "core_repaint_req", TLP_OUTPUT(output), TLP_END); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3432 | |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 3433 | loop = wl_display_get_event_loop(compositor->wl_display); |
Daniel Stone | 09a97e2 | 2017-03-01 11:34:06 +0000 | [diff] [blame] | 3434 | output->repaint_needed = true; |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 3435 | |
| 3436 | /* If we already have a repaint scheduled for our idle handler, |
| 3437 | * no need to set it again. If the repaint has been called but |
| 3438 | * not finished, then weston_output_finish_frame() will notice |
| 3439 | * that a repaint is needed and schedule one. */ |
| 3440 | if (output->repaint_status != REPAINT_NOT_SCHEDULED) |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 3441 | return; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 3442 | |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 3443 | output->repaint_status = REPAINT_BEGIN_FROM_IDLE; |
Pekka Paalanen | dcbcfc7 | 2017-10-26 14:33:59 +0300 | [diff] [blame] | 3444 | assert(!output->idle_repaint_source); |
| 3445 | output->idle_repaint_source = wl_event_loop_add_idle(loop, idle_repaint, |
| 3446 | output); |
Marius Vlad | 3203ff6 | 2019-09-05 14:56:12 +0300 | [diff] [blame] | 3447 | TL_POINT(compositor, "core_repaint_enter_loop", TLP_OUTPUT(output), TLP_END); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 3448 | } |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 3449 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 3450 | /** weston_compositor_schedule_repaint |
| 3451 | * \ingroup compositor |
| 3452 | */ |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 3453 | WL_EXPORT void |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 3454 | weston_compositor_schedule_repaint(struct weston_compositor *compositor) |
| 3455 | { |
| 3456 | struct weston_output *output; |
| 3457 | |
| 3458 | wl_list_for_each(output, &compositor->output_list, link) |
| 3459 | weston_output_schedule_repaint(output); |
| 3460 | } |
| 3461 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 3462 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 3463 | surface_destroy(struct wl_client *client, struct wl_resource *resource) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 3464 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3465 | wl_resource_destroy(resource); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 3466 | } |
| 3467 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 3468 | static void |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 3469 | surface_attach(struct wl_client *client, |
| 3470 | struct wl_resource *resource, |
| 3471 | struct wl_resource *buffer_resource, int32_t sx, int32_t sy) |
| 3472 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3473 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 3474 | struct weston_buffer *buffer = NULL; |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 3475 | |
Kristian Høgsberg | ab19f93 | 2013-08-20 11:30:54 -0700 | [diff] [blame] | 3476 | if (buffer_resource) { |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 3477 | buffer = weston_buffer_from_resource(buffer_resource); |
Kristian Høgsberg | ab19f93 | 2013-08-20 11:30:54 -0700 | [diff] [blame] | 3478 | if (buffer == NULL) { |
| 3479 | wl_client_post_no_memory(client); |
| 3480 | return; |
| 3481 | } |
limin.tian | 4733ccf | 2024-08-14 08:48:55 +0000 | [diff] [blame] | 3482 | buffer->surface = surface; |
| 3483 | buffer->attach = buffer->attach+1; |
limin.tian | 7049276 | 2024-08-23 02:02:12 +0000 | [diff] [blame] | 3484 | buffer->ec = surface->compositor; |
limin.tian | bf71b4c | 2024-08-27 09:09:34 +0000 | [diff] [blame] | 3485 | if (surface) { |
| 3486 | buffer->enable_display_time = surface->enable_display_time; |
| 3487 | } |
Kristian Høgsberg | 08b58c7 | 2013-08-15 12:26:42 -0700 | [diff] [blame] | 3488 | } |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 3489 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 3490 | /* Attach, attach, without commit in between does not send |
| 3491 | * wl_buffer.release. */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3492 | weston_surface_state_set_buffer(&surface->pending, buffer); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 3493 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3494 | surface->pending.sx = sx; |
| 3495 | surface->pending.sy = sy; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3496 | surface->pending.newly_attached = 1; |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 3497 | } |
| 3498 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 3499 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3500 | surface_damage(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 3501 | struct wl_resource *resource, |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3502 | 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] | 3503 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3504 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 9d69f8e | 2010-09-03 14:46:38 -0400 | [diff] [blame] | 3505 | |
Derek Foreman | 57e92ed | 2015-11-17 14:11:35 -0600 | [diff] [blame] | 3506 | if (width <= 0 || height <= 0) |
| 3507 | return; |
| 3508 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3509 | pixman_region32_union_rect(&surface->pending.damage_surface, |
| 3510 | &surface->pending.damage_surface, |
| 3511 | x, y, width, height); |
| 3512 | } |
| 3513 | |
| 3514 | static void |
| 3515 | surface_damage_buffer(struct wl_client *client, |
| 3516 | struct wl_resource *resource, |
| 3517 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 3518 | { |
| 3519 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
| 3520 | |
| 3521 | if (width <= 0 || height <= 0) |
| 3522 | return; |
| 3523 | |
| 3524 | pixman_region32_union_rect(&surface->pending.damage_buffer, |
| 3525 | &surface->pending.damage_buffer, |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 3526 | x, y, width, height); |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 3527 | } |
| 3528 | |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3529 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 3530 | destroy_frame_callback(struct wl_resource *resource) |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3531 | { |
Vlad Zahorodnii | c2b9747 | 2021-07-29 11:16:51 +0300 | [diff] [blame] | 3532 | wl_list_remove(wl_resource_get_link(resource)); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3533 | } |
| 3534 | |
| 3535 | static void |
| 3536 | surface_frame(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 3537 | struct wl_resource *resource, uint32_t callback) |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3538 | { |
Vlad Zahorodnii | c2b9747 | 2021-07-29 11:16:51 +0300 | [diff] [blame] | 3539 | struct wl_resource *cb; |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3540 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3541 | |
Vlad Zahorodnii | c2b9747 | 2021-07-29 11:16:51 +0300 | [diff] [blame] | 3542 | cb = wl_resource_create(client, &wl_callback_interface, 1, callback); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3543 | if (cb == NULL) { |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 3544 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3545 | return; |
| 3546 | } |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 3547 | |
Vlad Zahorodnii | c2b9747 | 2021-07-29 11:16:51 +0300 | [diff] [blame] | 3548 | wl_resource_set_implementation(cb, NULL, NULL, |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3549 | destroy_frame_callback); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3550 | |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 3551 | wl_list_init(&surface->pending.frame_callback_list); |
Vlad Zahorodnii | c2b9747 | 2021-07-29 11:16:51 +0300 | [diff] [blame] | 3552 | wl_list_insert(surface->pending.frame_callback_list.prev, |
| 3553 | wl_resource_get_link(cb)); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3554 | } |
| 3555 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3556 | static void |
| 3557 | surface_set_opaque_region(struct wl_client *client, |
| 3558 | struct wl_resource *resource, |
| 3559 | struct wl_resource *region_resource) |
| 3560 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3561 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3562 | struct weston_region *region; |
| 3563 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3564 | if (region_resource) { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 3565 | region = wl_resource_get_user_data(region_resource); |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 3566 | pixman_region32_copy(&surface->pending.opaque, |
| 3567 | ®ion->region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3568 | } else { |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 3569 | pixman_region32_clear(&surface->pending.opaque); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3570 | } |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3571 | } |
| 3572 | |
| 3573 | static void |
| 3574 | surface_set_input_region(struct wl_client *client, |
| 3575 | struct wl_resource *resource, |
| 3576 | struct wl_resource *region_resource) |
| 3577 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3578 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 010f98b | 2012-02-23 17:30:45 -0500 | [diff] [blame] | 3579 | struct weston_region *region; |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3580 | |
| 3581 | if (region_resource) { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 3582 | region = wl_resource_get_user_data(region_resource); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3583 | pixman_region32_copy(&surface->pending.input, |
| 3584 | ®ion->region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3585 | } else { |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3586 | pixman_region32_fini(&surface->pending.input); |
| 3587 | region_init_infinite(&surface->pending.input); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3588 | } |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3589 | } |
| 3590 | |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 3591 | /* Cause damage to this sub-surface and all its children. |
| 3592 | * |
| 3593 | * This is useful when there are state changes that need an implicit |
| 3594 | * damage, e.g. a z-order change. |
| 3595 | */ |
| 3596 | static void |
| 3597 | weston_surface_damage_subsurfaces(struct weston_subsurface *sub) |
| 3598 | { |
| 3599 | struct weston_subsurface *child; |
| 3600 | |
| 3601 | weston_surface_damage(sub->surface); |
| 3602 | sub->reordered = false; |
| 3603 | |
| 3604 | wl_list_for_each(child, &sub->surface->subsurface_list, parent_link) |
| 3605 | if (child != sub) |
| 3606 | weston_surface_damage_subsurfaces(child); |
| 3607 | } |
| 3608 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3609 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3610 | weston_surface_commit_subsurface_order(struct weston_surface *surface) |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3611 | { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3612 | struct weston_subsurface *sub; |
| 3613 | |
| 3614 | wl_list_for_each_reverse(sub, &surface->subsurface_list_pending, |
| 3615 | parent_link_pending) { |
| 3616 | wl_list_remove(&sub->parent_link); |
| 3617 | wl_list_insert(&surface->subsurface_list, &sub->parent_link); |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 3618 | |
| 3619 | if (sub->reordered) |
| 3620 | weston_surface_damage_subsurfaces(sub); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3621 | } |
| 3622 | } |
| 3623 | |
| 3624 | static void |
Pekka Paalanen | 04baea5 | 2016-04-26 15:50:58 +0300 | [diff] [blame] | 3625 | weston_surface_build_buffer_matrix(const struct weston_surface *surface, |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 3626 | struct weston_matrix *matrix) |
| 3627 | { |
Pekka Paalanen | 04baea5 | 2016-04-26 15:50:58 +0300 | [diff] [blame] | 3628 | const struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 3629 | double src_width, src_height, dest_width, dest_height; |
| 3630 | |
| 3631 | weston_matrix_init(matrix); |
| 3632 | |
| 3633 | if (vp->buffer.src_width == wl_fixed_from_int(-1)) { |
| 3634 | src_width = surface->width_from_buffer; |
| 3635 | src_height = surface->height_from_buffer; |
| 3636 | } else { |
| 3637 | src_width = wl_fixed_to_double(vp->buffer.src_width); |
| 3638 | src_height = wl_fixed_to_double(vp->buffer.src_height); |
| 3639 | } |
| 3640 | |
| 3641 | if (vp->surface.width == -1) { |
| 3642 | dest_width = src_width; |
| 3643 | dest_height = src_height; |
| 3644 | } else { |
| 3645 | dest_width = vp->surface.width; |
| 3646 | dest_height = vp->surface.height; |
| 3647 | } |
| 3648 | |
| 3649 | if (src_width != dest_width || src_height != dest_height) |
| 3650 | weston_matrix_scale(matrix, |
| 3651 | src_width / dest_width, |
| 3652 | src_height / dest_height, 1); |
| 3653 | |
| 3654 | if (vp->buffer.src_width != wl_fixed_from_int(-1)) |
| 3655 | weston_matrix_translate(matrix, |
| 3656 | wl_fixed_to_double(vp->buffer.src_x), |
| 3657 | wl_fixed_to_double(vp->buffer.src_y), |
| 3658 | 0); |
| 3659 | |
| 3660 | switch (vp->buffer.transform) { |
| 3661 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 3662 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 3663 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 3664 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 3665 | weston_matrix_scale(matrix, -1, 1, 1); |
| 3666 | weston_matrix_translate(matrix, |
| 3667 | surface->width_from_buffer, 0, 0); |
| 3668 | break; |
| 3669 | } |
| 3670 | |
| 3671 | switch (vp->buffer.transform) { |
| 3672 | default: |
| 3673 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 3674 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 3675 | break; |
| 3676 | case WL_OUTPUT_TRANSFORM_90: |
| 3677 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
Pekka Paalanen | 8060d82 | 2020-02-06 15:27:54 +0200 | [diff] [blame] | 3678 | weston_matrix_rotate_xy(matrix, 0, -1); |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 3679 | weston_matrix_translate(matrix, |
Pekka Paalanen | 8060d82 | 2020-02-06 15:27:54 +0200 | [diff] [blame] | 3680 | 0, surface->width_from_buffer, 0); |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 3681 | break; |
| 3682 | case WL_OUTPUT_TRANSFORM_180: |
| 3683 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 3684 | weston_matrix_rotate_xy(matrix, -1, 0); |
| 3685 | weston_matrix_translate(matrix, |
| 3686 | surface->width_from_buffer, |
| 3687 | surface->height_from_buffer, 0); |
| 3688 | break; |
| 3689 | case WL_OUTPUT_TRANSFORM_270: |
| 3690 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
Pekka Paalanen | 8060d82 | 2020-02-06 15:27:54 +0200 | [diff] [blame] | 3691 | weston_matrix_rotate_xy(matrix, 0, 1); |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 3692 | weston_matrix_translate(matrix, |
Pekka Paalanen | 8060d82 | 2020-02-06 15:27:54 +0200 | [diff] [blame] | 3693 | surface->height_from_buffer, 0, 0); |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 3694 | break; |
| 3695 | } |
| 3696 | |
| 3697 | weston_matrix_scale(matrix, vp->buffer.scale, vp->buffer.scale, 1); |
| 3698 | } |
| 3699 | |
Pekka Paalanen | d9aae9c | 2016-04-26 13:46:38 +0300 | [diff] [blame] | 3700 | /** |
| 3701 | * Compute a + b > c while being safe to overflows. |
| 3702 | */ |
| 3703 | static bool |
| 3704 | fixed_sum_gt(wl_fixed_t a, wl_fixed_t b, wl_fixed_t c) |
| 3705 | { |
| 3706 | return (int64_t)a + (int64_t)b > (int64_t)c; |
| 3707 | } |
| 3708 | |
| 3709 | static bool |
| 3710 | weston_surface_is_pending_viewport_source_valid( |
| 3711 | const struct weston_surface *surface) |
| 3712 | { |
| 3713 | const struct weston_surface_state *pend = &surface->pending; |
| 3714 | const struct weston_buffer_viewport *vp = &pend->buffer_viewport; |
| 3715 | int width_from_buffer = 0; |
| 3716 | int height_from_buffer = 0; |
| 3717 | wl_fixed_t w; |
| 3718 | wl_fixed_t h; |
| 3719 | |
| 3720 | /* If viewport source rect is not set, it is always ok. */ |
| 3721 | if (vp->buffer.src_width == wl_fixed_from_int(-1)) |
| 3722 | return true; |
| 3723 | |
| 3724 | if (pend->newly_attached) { |
| 3725 | if (pend->buffer) { |
| 3726 | convert_size_by_transform_scale(&width_from_buffer, |
| 3727 | &height_from_buffer, |
| 3728 | pend->buffer->width, |
| 3729 | pend->buffer->height, |
| 3730 | vp->buffer.transform, |
| 3731 | vp->buffer.scale); |
| 3732 | } else { |
| 3733 | /* No buffer: viewport is irrelevant. */ |
| 3734 | return true; |
| 3735 | } |
| 3736 | } else { |
| 3737 | width_from_buffer = surface->width_from_buffer; |
| 3738 | height_from_buffer = surface->height_from_buffer; |
| 3739 | } |
| 3740 | |
| 3741 | assert((width_from_buffer == 0) == (height_from_buffer == 0)); |
| 3742 | assert(width_from_buffer >= 0 && height_from_buffer >= 0); |
| 3743 | |
| 3744 | /* No buffer: viewport is irrelevant. */ |
| 3745 | if (width_from_buffer == 0 || height_from_buffer == 0) |
| 3746 | return true; |
| 3747 | |
| 3748 | /* overflow checks for wl_fixed_from_int() */ |
| 3749 | if (width_from_buffer > wl_fixed_to_int(INT32_MAX)) |
| 3750 | return false; |
| 3751 | if (height_from_buffer > wl_fixed_to_int(INT32_MAX)) |
| 3752 | return false; |
| 3753 | |
| 3754 | w = wl_fixed_from_int(width_from_buffer); |
| 3755 | h = wl_fixed_from_int(height_from_buffer); |
| 3756 | |
| 3757 | if (fixed_sum_gt(vp->buffer.src_x, vp->buffer.src_width, w)) |
| 3758 | return false; |
| 3759 | if (fixed_sum_gt(vp->buffer.src_y, vp->buffer.src_height, h)) |
| 3760 | return false; |
| 3761 | |
| 3762 | return true; |
| 3763 | } |
| 3764 | |
Pekka Paalanen | bb32ccc | 2016-04-26 14:28:28 +0300 | [diff] [blame] | 3765 | static bool |
| 3766 | fixed_is_integer(wl_fixed_t v) |
| 3767 | { |
| 3768 | return (v & 0xff) == 0; |
| 3769 | } |
| 3770 | |
| 3771 | static bool |
| 3772 | weston_surface_is_pending_viewport_dst_size_int( |
| 3773 | const struct weston_surface *surface) |
| 3774 | { |
| 3775 | const struct weston_buffer_viewport *vp = |
| 3776 | &surface->pending.buffer_viewport; |
| 3777 | |
| 3778 | if (vp->surface.width != -1) { |
| 3779 | assert(vp->surface.width > 0 && vp->surface.height > 0); |
| 3780 | return true; |
| 3781 | } |
| 3782 | |
| 3783 | return fixed_is_integer(vp->buffer.src_width) && |
| 3784 | fixed_is_integer(vp->buffer.src_height); |
| 3785 | } |
| 3786 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3787 | /* Translate pending damage in buffer co-ordinates to surface |
| 3788 | * co-ordinates and union it with a pixman_region32_t. |
| 3789 | * This should only be called after the buffer is attached. |
| 3790 | */ |
| 3791 | static void |
| 3792 | apply_damage_buffer(pixman_region32_t *dest, |
| 3793 | struct weston_surface *surface, |
| 3794 | struct weston_surface_state *state) |
| 3795 | { |
| 3796 | struct weston_buffer *buffer = surface->buffer_ref.buffer; |
| 3797 | |
| 3798 | /* wl_surface.damage_buffer needs to be clipped to the buffer, |
| 3799 | * translated into surface co-ordinates and unioned with |
| 3800 | * any other surface damage. |
| 3801 | * None of this makes sense if there is no buffer though. |
| 3802 | */ |
| 3803 | if (buffer && pixman_region32_not_empty(&state->damage_buffer)) { |
| 3804 | pixman_region32_t buffer_damage; |
| 3805 | |
| 3806 | pixman_region32_intersect_rect(&state->damage_buffer, |
| 3807 | &state->damage_buffer, |
| 3808 | 0, 0, buffer->width, |
| 3809 | buffer->height); |
| 3810 | pixman_region32_init(&buffer_damage); |
| 3811 | weston_matrix_transform_region(&buffer_damage, |
| 3812 | &surface->buffer_to_surface_matrix, |
| 3813 | &state->damage_buffer); |
| 3814 | pixman_region32_union(dest, dest, &buffer_damage); |
| 3815 | pixman_region32_fini(&buffer_damage); |
| 3816 | } |
| 3817 | /* We should clear this on commit even if there was no buffer */ |
| 3818 | pixman_region32_clear(&state->damage_buffer); |
| 3819 | } |
| 3820 | |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 3821 | static void |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 3822 | weston_surface_set_desired_protection(struct weston_surface *surface, |
| 3823 | enum weston_hdcp_protection protection) |
| 3824 | { |
| 3825 | if (surface->desired_protection == protection) |
| 3826 | return; |
| 3827 | surface->desired_protection = protection; |
| 3828 | weston_surface_damage(surface); |
| 3829 | } |
| 3830 | |
| 3831 | static void |
Ankit Nautiyal | 5cfe03c | 2019-03-28 15:05:42 +0530 | [diff] [blame] | 3832 | weston_surface_set_protection_mode(struct weston_surface *surface, |
| 3833 | enum weston_surface_protection_mode p_mode) |
| 3834 | { |
| 3835 | struct content_protection *cp = surface->compositor->content_protection; |
| 3836 | struct protected_surface *psurface; |
| 3837 | |
| 3838 | surface->protection_mode = p_mode; |
| 3839 | wl_list_for_each(psurface, &cp->protected_list, link) { |
| 3840 | if (!psurface || psurface->surface != surface) |
| 3841 | continue; |
| 3842 | weston_protected_surface_send_event(psurface, |
| 3843 | surface->current_protection); |
| 3844 | } |
| 3845 | } |
| 3846 | |
| 3847 | static void |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3848 | weston_surface_commit_state(struct weston_surface *surface, |
| 3849 | struct weston_surface_state *state) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3850 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3851 | struct weston_view *view; |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 3852 | pixman_region32_t opaque; |
| 3853 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3854 | /* wl_surface.set_buffer_transform */ |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3855 | /* wl_surface.set_buffer_scale */ |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 3856 | /* wp_viewport.set_source */ |
| 3857 | /* wp_viewport.set_destination */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3858 | surface->buffer_viewport = state->buffer_viewport; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3859 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3860 | /* wl_surface.attach */ |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3861 | if (state->newly_attached) { |
| 3862 | /* zwp_surface_synchronization_v1.set_acquire_fence */ |
| 3863 | fd_move(&surface->acquire_fence_fd, |
| 3864 | &state->acquire_fence_fd); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3865 | /* zwp_surface_synchronization_v1.get_release */ |
| 3866 | weston_buffer_release_move(&surface->buffer_release_ref, |
| 3867 | &state->buffer_release_ref); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3868 | weston_surface_attach(surface, state->buffer); |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3869 | } |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3870 | weston_surface_state_set_buffer(state, NULL); |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3871 | assert(state->acquire_fence_fd == -1); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3872 | assert(state->buffer_release_ref.buffer_release == NULL); |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3873 | |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 3874 | weston_surface_build_buffer_matrix(surface, |
| 3875 | &surface->surface_to_buffer_matrix); |
| 3876 | weston_matrix_invert(&surface->buffer_to_surface_matrix, |
| 3877 | &surface->surface_to_buffer_matrix); |
| 3878 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3879 | if (state->newly_attached || state->buffer_viewport.changed) { |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3880 | weston_surface_update_size(surface); |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3881 | if (surface->committed) |
| 3882 | surface->committed(surface, state->sx, state->sy); |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3883 | } |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3884 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3885 | state->sx = 0; |
| 3886 | state->sy = 0; |
| 3887 | state->newly_attached = 0; |
| 3888 | state->buffer_viewport.changed = 0; |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 3889 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3890 | /* wl_surface.damage and wl_surface.damage_buffer */ |
Marius Vlad | 2a1b786 | 2019-09-05 13:12:18 +0300 | [diff] [blame] | 3891 | if (pixman_region32_not_empty(&state->damage_surface) || |
| 3892 | pixman_region32_not_empty(&state->damage_buffer)) |
Marius Vlad | 3203ff6 | 2019-09-05 14:56:12 +0300 | [diff] [blame] | 3893 | TL_POINT(surface->compositor, "core_commit_damage", TLP_SURFACE(surface), TLP_END); |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3894 | |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 3895 | pixman_region32_union(&surface->damage, &surface->damage, |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3896 | &state->damage_surface); |
| 3897 | |
| 3898 | apply_damage_buffer(&surface->damage, surface, state); |
| 3899 | |
Kristian Høgsberg | 4d0214c | 2012-11-08 11:36:02 -0500 | [diff] [blame] | 3900 | pixman_region32_intersect_rect(&surface->damage, &surface->damage, |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 3901 | 0, 0, surface->width, surface->height); |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3902 | pixman_region32_clear(&state->damage_surface); |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 3903 | |
| 3904 | /* wl_surface.set_opaque_region */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3905 | pixman_region32_init(&opaque); |
| 3906 | pixman_region32_intersect_rect(&opaque, &state->opaque, |
| 3907 | 0, 0, surface->width, surface->height); |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 3908 | |
| 3909 | if (!pixman_region32_equal(&opaque, &surface->opaque)) { |
| 3910 | pixman_region32_copy(&surface->opaque, &opaque); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3911 | wl_list_for_each(view, &surface->views, surface_link) |
| 3912 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 3913 | } |
| 3914 | |
| 3915 | pixman_region32_fini(&opaque); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3916 | |
| 3917 | /* wl_surface.set_input_region */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3918 | pixman_region32_intersect_rect(&surface->input, &state->input, |
| 3919 | 0, 0, surface->width, surface->height); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3920 | |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 3921 | /* wl_surface.frame */ |
| 3922 | wl_list_insert_list(&surface->frame_callback_list, |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3923 | &state->frame_callback_list); |
| 3924 | wl_list_init(&state->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3925 | |
| 3926 | /* XXX: |
| 3927 | * What should happen with a feedback request, if there |
| 3928 | * is no wl_buffer attached for this commit? |
| 3929 | */ |
| 3930 | |
| 3931 | /* presentation.feedback */ |
| 3932 | wl_list_insert_list(&surface->feedback_list, |
| 3933 | &state->feedback_list); |
| 3934 | wl_list_init(&state->feedback_list); |
Jonas Ådahl | 5d9ca27 | 2016-07-22 17:48:03 +0800 | [diff] [blame] | 3935 | |
Ankit Nautiyal | 5cfe03c | 2019-03-28 15:05:42 +0530 | [diff] [blame] | 3936 | /* weston_protected_surface.enforced/relaxed */ |
| 3937 | if (surface->protection_mode != state->protection_mode) |
| 3938 | weston_surface_set_protection_mode(surface, |
| 3939 | state->protection_mode); |
| 3940 | |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 3941 | /* weston_protected_surface.set_type */ |
| 3942 | weston_surface_set_desired_protection(surface, state->desired_protection); |
| 3943 | |
Jonas Ådahl | 5d9ca27 | 2016-07-22 17:48:03 +0800 | [diff] [blame] | 3944 | wl_signal_emit(&surface->commit_signal, surface); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3945 | } |
| 3946 | |
| 3947 | static void |
| 3948 | weston_surface_commit(struct weston_surface *surface) |
| 3949 | { |
| 3950 | weston_surface_commit_state(surface, &surface->pending); |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 3951 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3952 | weston_surface_commit_subsurface_order(surface); |
| 3953 | |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3954 | weston_surface_schedule_repaint(surface); |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3955 | } |
| 3956 | |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3957 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3958 | weston_subsurface_commit(struct weston_subsurface *sub); |
| 3959 | |
| 3960 | static void |
| 3961 | weston_subsurface_parent_commit(struct weston_subsurface *sub, |
| 3962 | int parent_is_synchronized); |
| 3963 | |
| 3964 | static void |
| 3965 | surface_commit(struct wl_client *client, struct wl_resource *resource) |
| 3966 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3967 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3968 | struct weston_subsurface *sub = weston_surface_to_subsurface(surface); |
| 3969 | |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 3970 | weston_surface_commit_time(surface); |
Pekka Paalanen | d9aae9c | 2016-04-26 13:46:38 +0300 | [diff] [blame] | 3971 | if (!weston_surface_is_pending_viewport_source_valid(surface)) { |
| 3972 | assert(surface->viewport_resource); |
| 3973 | |
| 3974 | wl_resource_post_error(surface->viewport_resource, |
| 3975 | WP_VIEWPORT_ERROR_OUT_OF_BUFFER, |
| 3976 | "wl_surface@%d has viewport source outside buffer", |
| 3977 | wl_resource_get_id(resource)); |
| 3978 | return; |
| 3979 | } |
| 3980 | |
Pekka Paalanen | bb32ccc | 2016-04-26 14:28:28 +0300 | [diff] [blame] | 3981 | if (!weston_surface_is_pending_viewport_dst_size_int(surface)) { |
| 3982 | assert(surface->viewport_resource); |
| 3983 | |
| 3984 | wl_resource_post_error(surface->viewport_resource, |
| 3985 | WP_VIEWPORT_ERROR_BAD_SIZE, |
| 3986 | "wl_surface@%d viewport dst size not integer", |
| 3987 | wl_resource_get_id(resource)); |
| 3988 | return; |
| 3989 | } |
| 3990 | |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3991 | if (surface->pending.acquire_fence_fd >= 0) { |
| 3992 | assert(surface->synchronization_resource); |
| 3993 | |
| 3994 | if (!surface->pending.buffer) { |
| 3995 | fd_clear(&surface->pending.acquire_fence_fd); |
| 3996 | wl_resource_post_error(surface->synchronization_resource, |
| 3997 | ZWP_LINUX_SURFACE_SYNCHRONIZATION_V1_ERROR_NO_BUFFER, |
| 3998 | "wl_surface@%"PRIu32" no buffer for synchronization", |
| 3999 | wl_resource_get_id(resource)); |
| 4000 | return; |
| 4001 | } |
| 4002 | |
| 4003 | /* We support fences for both wp_linux_dmabuf and opaque EGL |
| 4004 | * buffers, as mandated by minor version 2 of the |
| 4005 | * zwp_linux_explicit_synchronization_v1 protocol. Since |
| 4006 | * renderers that support fences currently only support these |
| 4007 | * two buffer types plus SHM buffers, we can just check for the |
| 4008 | * SHM buffer case here. |
| 4009 | */ |
| 4010 | if (wl_shm_buffer_get(surface->pending.buffer->resource)) { |
| 4011 | fd_clear(&surface->pending.acquire_fence_fd); |
| 4012 | wl_resource_post_error(surface->synchronization_resource, |
| 4013 | ZWP_LINUX_SURFACE_SYNCHRONIZATION_V1_ERROR_UNSUPPORTED_BUFFER, |
| 4014 | "wl_surface@%"PRIu32" unsupported buffer for synchronization", |
| 4015 | wl_resource_get_id(resource)); |
| 4016 | return; |
| 4017 | } |
| 4018 | } |
| 4019 | |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 4020 | if (surface->pending.buffer_release_ref.buffer_release && |
| 4021 | !surface->pending.buffer) { |
| 4022 | assert(surface->synchronization_resource); |
| 4023 | |
| 4024 | wl_resource_post_error(surface->synchronization_resource, |
| 4025 | ZWP_LINUX_SURFACE_SYNCHRONIZATION_V1_ERROR_NO_BUFFER, |
| 4026 | "wl_surface@%"PRIu32" no buffer for synchronization", |
| 4027 | wl_resource_get_id(resource)); |
| 4028 | return; |
| 4029 | } |
| 4030 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4031 | if (sub) { |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 4032 | weston_video_subsurface_commit(surface, sub); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4033 | return; |
| 4034 | } |
| 4035 | |
| 4036 | weston_surface_commit(surface); |
| 4037 | |
| 4038 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
| 4039 | if (sub->surface != surface) |
| 4040 | weston_subsurface_parent_commit(sub, 0); |
| 4041 | } |
| 4042 | } |
| 4043 | |
| 4044 | static void |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4045 | surface_set_buffer_transform(struct wl_client *client, |
| 4046 | struct wl_resource *resource, int transform) |
| 4047 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4048 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4049 | |
Jonny Lamb | a55f139 | 2014-05-30 12:07:15 +0200 | [diff] [blame] | 4050 | /* if wl_output.transform grows more members this will need to be updated. */ |
| 4051 | if (transform < 0 || |
| 4052 | transform > WL_OUTPUT_TRANSFORM_FLIPPED_270) { |
| 4053 | wl_resource_post_error(resource, |
| 4054 | WL_SURFACE_ERROR_INVALID_TRANSFORM, |
| 4055 | "buffer transform must be a valid transform " |
| 4056 | "('%d' specified)", transform); |
| 4057 | return; |
| 4058 | } |
| 4059 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 4060 | surface->pending.buffer_viewport.buffer.transform = transform; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 4061 | surface->pending.buffer_viewport.changed = 1; |
limin.tian | 531dd23 | 2025-01-07 12:09:27 +0000 | [diff] [blame] | 4062 | weston_log("%s %d transform:%d\n", __FUNCTION__,__LINE__,transform); |
chen.wang1 | f06854b | 2024-09-26 11:26:04 +0000 | [diff] [blame] | 4063 | surface->video_transform = transform; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4064 | } |
| 4065 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 4066 | static void |
| 4067 | surface_set_buffer_scale(struct wl_client *client, |
| 4068 | struct wl_resource *resource, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 4069 | int32_t scale) |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 4070 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4071 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 4072 | |
Jonny Lamb | a55f139 | 2014-05-30 12:07:15 +0200 | [diff] [blame] | 4073 | if (scale < 1) { |
| 4074 | wl_resource_post_error(resource, |
| 4075 | WL_SURFACE_ERROR_INVALID_SCALE, |
| 4076 | "buffer scale must be at least one " |
| 4077 | "('%d' specified)", scale); |
| 4078 | return; |
| 4079 | } |
| 4080 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 4081 | surface->pending.buffer_viewport.buffer.scale = scale; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 4082 | surface->pending.buffer_viewport.changed = 1; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 4083 | } |
| 4084 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 4085 | static const struct wl_surface_interface surface_interface = { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 4086 | surface_destroy, |
| 4087 | surface_attach, |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 4088 | surface_damage, |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 4089 | surface_frame, |
| 4090 | surface_set_opaque_region, |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 4091 | surface_set_input_region, |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 4092 | surface_commit, |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 4093 | surface_set_buffer_transform, |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 4094 | surface_set_buffer_scale, |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 4095 | surface_damage_buffer, |
| 4096 | surface_set_video_plane, |
| 4097 | surface_set_pts, |
| 4098 | surface_keep_last_frame, |
limin.tian | c616dad | 2024-07-15 11:35:38 +0000 | [diff] [blame] | 4099 | surface_set_display_rate, |
| 4100 | surface_destroy_callback, |
limin.tian | 230ec58 | 2024-07-30 09:35:17 +0000 | [diff] [blame] | 4101 | surface_enable_ll_mode, |
chen.wang1 | d9c36b1 | 2024-08-05 11:45:27 +0000 | [diff] [blame] | 4102 | surface_set_invisible, |
limin.tian | bf71b4c | 2024-08-27 09:09:34 +0000 | [diff] [blame] | 4103 | surface_set_plane_mute, |
chen.wang1 | fdc0f56 | 2024-09-04 07:57:16 +0000 | [diff] [blame] | 4104 | surface_enable_display_time_callback, |
| 4105 | surface_set_video_zorder |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 4106 | }; |
| 4107 | |
Leandro Ribeiro | 8eb8414 | 2021-01-18 19:36:48 -0300 | [diff] [blame] | 4108 | static int |
| 4109 | create_surface_dmabuf_feedback(struct weston_compositor *ec, |
| 4110 | struct weston_surface *surface) |
| 4111 | { |
| 4112 | struct weston_dmabuf_feedback_tranche *tranche; |
| 4113 | dev_t main_device = ec->default_dmabuf_feedback->main_device; |
| 4114 | uint32_t flags = 0; |
| 4115 | |
| 4116 | surface->dmabuf_feedback = weston_dmabuf_feedback_create(main_device); |
| 4117 | if (!surface->dmabuf_feedback) |
| 4118 | return -1; |
| 4119 | |
| 4120 | tranche = weston_dmabuf_feedback_tranche_create(surface->dmabuf_feedback, |
| 4121 | ec->dmabuf_feedback_format_table, |
| 4122 | main_device, flags, |
| 4123 | RENDERER_PREF); |
| 4124 | if (!tranche) { |
| 4125 | weston_dmabuf_feedback_destroy(surface->dmabuf_feedback); |
| 4126 | surface->dmabuf_feedback = NULL; |
| 4127 | return -1; |
| 4128 | } |
| 4129 | |
| 4130 | return 0; |
| 4131 | } |
| 4132 | |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 4133 | static void |
| 4134 | compositor_create_surface(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 4135 | struct wl_resource *resource, uint32_t id) |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 4136 | { |
Kristian Høgsberg | c2d7042 | 2013-06-25 15:34:33 -0400 | [diff] [blame] | 4137 | struct weston_compositor *ec = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4138 | struct weston_surface *surface; |
Leandro Ribeiro | 8eb8414 | 2021-01-18 19:36:48 -0300 | [diff] [blame] | 4139 | int ret; |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 4140 | |
Kristian Høgsberg | 18c9300 | 2012-01-27 11:58:31 -0500 | [diff] [blame] | 4141 | surface = weston_surface_create(ec); |
Leandro Ribeiro | 8eb8414 | 2021-01-18 19:36:48 -0300 | [diff] [blame] | 4142 | if (surface == NULL) |
| 4143 | goto err; |
| 4144 | |
leng.fang | dbaf6fa | 2024-06-20 19:31:04 +0800 | [diff] [blame] | 4145 | weston_compositor_add_surface_id(ec, surface); |
| 4146 | |
Leandro Ribeiro | 8eb8414 | 2021-01-18 19:36:48 -0300 | [diff] [blame] | 4147 | if (ec->default_dmabuf_feedback) { |
| 4148 | ret = create_surface_dmabuf_feedback(ec, surface); |
| 4149 | if (ret < 0) |
| 4150 | goto err_dmabuf_feedback; |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 4151 | } |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 4152 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4153 | surface->resource = |
| 4154 | wl_resource_create(client, &wl_surface_interface, |
| 4155 | wl_resource_get_version(resource), id); |
Leandro Ribeiro | 8eb8414 | 2021-01-18 19:36:48 -0300 | [diff] [blame] | 4156 | if (surface->resource == NULL) |
| 4157 | goto err_dmabuf_feedback; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4158 | wl_resource_set_implementation(surface->resource, &surface_interface, |
| 4159 | surface, destroy_surface); |
Kristian Høgsberg | f03a04a | 2014-04-06 22:04:50 -0700 | [diff] [blame] | 4160 | |
| 4161 | wl_signal_emit(&ec->create_surface_signal, surface); |
Leandro Ribeiro | 8eb8414 | 2021-01-18 19:36:48 -0300 | [diff] [blame] | 4162 | |
| 4163 | return; |
| 4164 | |
| 4165 | err_dmabuf_feedback: |
| 4166 | weston_surface_destroy(surface); |
| 4167 | err: |
| 4168 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 4169 | } |
| 4170 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 4171 | static void |
| 4172 | destroy_region(struct wl_resource *resource) |
| 4173 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 4174 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 4175 | |
| 4176 | pixman_region32_fini(®ion->region); |
| 4177 | free(region); |
| 4178 | } |
| 4179 | |
| 4180 | static void |
| 4181 | region_destroy(struct wl_client *client, struct wl_resource *resource) |
| 4182 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 4183 | wl_resource_destroy(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 4184 | } |
| 4185 | |
| 4186 | static void |
| 4187 | region_add(struct wl_client *client, struct wl_resource *resource, |
| 4188 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 4189 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 4190 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 4191 | |
| 4192 | pixman_region32_union_rect(®ion->region, ®ion->region, |
| 4193 | x, y, width, height); |
| 4194 | } |
| 4195 | |
| 4196 | static void |
| 4197 | region_subtract(struct wl_client *client, struct wl_resource *resource, |
| 4198 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 4199 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 4200 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 4201 | pixman_region32_t rect; |
| 4202 | |
| 4203 | pixman_region32_init_rect(&rect, x, y, width, height); |
| 4204 | pixman_region32_subtract(®ion->region, ®ion->region, &rect); |
| 4205 | pixman_region32_fini(&rect); |
| 4206 | } |
| 4207 | |
| 4208 | static const struct wl_region_interface region_interface = { |
| 4209 | region_destroy, |
| 4210 | region_add, |
| 4211 | region_subtract |
| 4212 | }; |
| 4213 | |
| 4214 | static void |
| 4215 | compositor_create_region(struct wl_client *client, |
| 4216 | struct wl_resource *resource, uint32_t id) |
| 4217 | { |
| 4218 | struct weston_region *region; |
| 4219 | |
| 4220 | region = malloc(sizeof *region); |
| 4221 | if (region == NULL) { |
| 4222 | wl_resource_post_no_memory(resource); |
| 4223 | return; |
| 4224 | } |
| 4225 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 4226 | pixman_region32_init(®ion->region); |
| 4227 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4228 | region->resource = |
| 4229 | wl_resource_create(client, &wl_region_interface, 1, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 4230 | if (region->resource == NULL) { |
| 4231 | free(region); |
| 4232 | wl_resource_post_no_memory(resource); |
| 4233 | return; |
| 4234 | } |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4235 | wl_resource_set_implementation(region->resource, ®ion_interface, |
| 4236 | region, destroy_region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 4237 | } |
| 4238 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 4239 | static const struct wl_compositor_interface compositor_interface = { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 4240 | compositor_create_surface, |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 4241 | compositor_create_region |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 4242 | }; |
| 4243 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4244 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4245 | weston_subsurface_commit_from_cache(struct weston_subsurface *sub) |
| 4246 | { |
| 4247 | struct weston_surface *surface = sub->surface; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4248 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 4249 | weston_surface_commit_state(surface, &sub->cached); |
| 4250 | weston_buffer_reference(&sub->cached_buffer_ref, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4251 | |
| 4252 | weston_surface_commit_subsurface_order(surface); |
| 4253 | |
| 4254 | weston_surface_schedule_repaint(surface); |
| 4255 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 4256 | sub->has_cached_data = 0; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4257 | } |
| 4258 | |
| 4259 | static void |
| 4260 | weston_subsurface_commit_to_cache(struct weston_subsurface *sub) |
| 4261 | { |
| 4262 | struct weston_surface *surface = sub->surface; |
| 4263 | |
| 4264 | /* |
| 4265 | * If this commit would cause the surface to move by the |
| 4266 | * attach(dx, dy) parameters, the old damage region must be |
| 4267 | * translated to correspond to the new surface coordinate system |
Chris Michael | 062edf2 | 2015-11-26 11:30:00 -0500 | [diff] [blame] | 4268 | * origin. |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4269 | */ |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 4270 | pixman_region32_translate(&sub->cached.damage_surface, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4271 | -surface->pending.sx, -surface->pending.sy); |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 4272 | pixman_region32_union(&sub->cached.damage_surface, |
| 4273 | &sub->cached.damage_surface, |
| 4274 | &surface->pending.damage_surface); |
| 4275 | pixman_region32_clear(&surface->pending.damage_surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4276 | |
| 4277 | if (surface->pending.newly_attached) { |
| 4278 | sub->cached.newly_attached = 1; |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 4279 | weston_surface_state_set_buffer(&sub->cached, |
| 4280 | surface->pending.buffer); |
| 4281 | weston_buffer_reference(&sub->cached_buffer_ref, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4282 | surface->pending.buffer); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 4283 | weston_presentation_feedback_discard_list( |
| 4284 | &sub->cached.feedback_list); |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 4285 | /* zwp_surface_synchronization_v1.set_acquire_fence */ |
| 4286 | fd_move(&sub->cached.acquire_fence_fd, |
| 4287 | &surface->pending.acquire_fence_fd); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 4288 | /* zwp_surface_synchronization_v1.get_release */ |
| 4289 | weston_buffer_release_move(&sub->cached.buffer_release_ref, |
| 4290 | &surface->pending.buffer_release_ref); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4291 | } |
Ankit Nautiyal | 4b6e73d | 2019-03-26 13:37:12 +0530 | [diff] [blame] | 4292 | sub->cached.desired_protection = surface->pending.desired_protection; |
Ankit Nautiyal | 5cfe03c | 2019-03-28 15:05:42 +0530 | [diff] [blame] | 4293 | sub->cached.protection_mode = surface->pending.protection_mode; |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 4294 | assert(surface->pending.acquire_fence_fd == -1); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 4295 | assert(surface->pending.buffer_release_ref.buffer_release == NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4296 | sub->cached.sx += surface->pending.sx; |
| 4297 | sub->cached.sy += surface->pending.sy; |
Pekka Paalanen | 260ba38 | 2014-03-14 14:38:12 +0200 | [diff] [blame] | 4298 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 4299 | apply_damage_buffer(&sub->cached.damage_surface, surface, &surface->pending); |
| 4300 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 4301 | sub->cached.buffer_viewport.changed |= |
| 4302 | surface->pending.buffer_viewport.changed; |
| 4303 | sub->cached.buffer_viewport.buffer = |
| 4304 | surface->pending.buffer_viewport.buffer; |
| 4305 | sub->cached.buffer_viewport.surface = |
| 4306 | surface->pending.buffer_viewport.surface; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4307 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 4308 | weston_surface_reset_pending_buffer(surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4309 | |
| 4310 | pixman_region32_copy(&sub->cached.opaque, &surface->pending.opaque); |
| 4311 | |
| 4312 | pixman_region32_copy(&sub->cached.input, &surface->pending.input); |
| 4313 | |
| 4314 | wl_list_insert_list(&sub->cached.frame_callback_list, |
| 4315 | &surface->pending.frame_callback_list); |
| 4316 | wl_list_init(&surface->pending.frame_callback_list); |
| 4317 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 4318 | wl_list_insert_list(&sub->cached.feedback_list, |
| 4319 | &surface->pending.feedback_list); |
| 4320 | wl_list_init(&surface->pending.feedback_list); |
| 4321 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 4322 | sub->has_cached_data = 1; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4323 | } |
| 4324 | |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 4325 | static bool |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4326 | weston_subsurface_is_synchronized(struct weston_subsurface *sub) |
| 4327 | { |
| 4328 | while (sub) { |
| 4329 | if (sub->synchronized) |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 4330 | return true; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4331 | |
| 4332 | if (!sub->parent) |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 4333 | return false; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4334 | |
| 4335 | sub = weston_surface_to_subsurface(sub->parent); |
| 4336 | } |
| 4337 | |
Carlos Olmedo Escobar | 61a9bf5 | 2014-11-04 14:38:39 +0100 | [diff] [blame] | 4338 | return false; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4339 | } |
| 4340 | |
| 4341 | static void |
| 4342 | weston_subsurface_commit(struct weston_subsurface *sub) |
| 4343 | { |
| 4344 | struct weston_surface *surface = sub->surface; |
| 4345 | struct weston_subsurface *tmp; |
| 4346 | |
| 4347 | /* Recursive check for effectively synchronized. */ |
| 4348 | if (weston_subsurface_is_synchronized(sub)) { |
| 4349 | weston_subsurface_commit_to_cache(sub); |
| 4350 | } else { |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 4351 | if (sub->has_cached_data) { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4352 | /* flush accumulated state from cache */ |
| 4353 | weston_subsurface_commit_to_cache(sub); |
| 4354 | weston_subsurface_commit_from_cache(sub); |
| 4355 | } else { |
| 4356 | weston_surface_commit(surface); |
| 4357 | } |
| 4358 | |
| 4359 | wl_list_for_each(tmp, &surface->subsurface_list, parent_link) { |
| 4360 | if (tmp->surface != surface) |
| 4361 | weston_subsurface_parent_commit(tmp, 0); |
| 4362 | } |
| 4363 | } |
| 4364 | } |
| 4365 | |
| 4366 | static void |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 4367 | weston_subsurface_synchronized_commit(struct weston_subsurface *sub) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4368 | { |
| 4369 | struct weston_surface *surface = sub->surface; |
| 4370 | struct weston_subsurface *tmp; |
| 4371 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4372 | /* From now on, commit_from_cache the whole sub-tree, regardless of |
| 4373 | * the synchronized mode of each child. This sub-surface or some |
| 4374 | * of its ancestors were synchronized, so we are synchronized |
| 4375 | * all the way down. |
| 4376 | */ |
| 4377 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 4378 | if (sub->has_cached_data) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4379 | weston_subsurface_commit_from_cache(sub); |
| 4380 | |
| 4381 | wl_list_for_each(tmp, &surface->subsurface_list, parent_link) { |
| 4382 | if (tmp->surface != surface) |
| 4383 | weston_subsurface_parent_commit(tmp, 1); |
| 4384 | } |
| 4385 | } |
| 4386 | |
| 4387 | static void |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 4388 | weston_subsurface_parent_commit(struct weston_subsurface *sub, |
| 4389 | int parent_is_synchronized) |
| 4390 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4391 | struct weston_view *view; |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 4392 | if (sub->position.set) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4393 | wl_list_for_each(view, &sub->surface->views, surface_link) |
| 4394 | weston_view_set_position(view, |
| 4395 | sub->position.x, |
| 4396 | sub->position.y); |
| 4397 | |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 4398 | sub->position.set = 0; |
| 4399 | } |
| 4400 | |
| 4401 | if (parent_is_synchronized || sub->synchronized) |
| 4402 | weston_subsurface_synchronized_commit(sub); |
| 4403 | } |
| 4404 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4405 | static int |
| 4406 | subsurface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 4407 | { |
| 4408 | return snprintf(buf, len, "sub-surface"); |
| 4409 | } |
| 4410 | |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 4411 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 4412 | subsurface_committed(struct weston_surface *surface, int32_t dx, int32_t dy) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4413 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4414 | struct weston_view *view; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4415 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4416 | wl_list_for_each(view, &surface->views, surface_link) |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 4417 | weston_view_set_position(view, |
| 4418 | view->geometry.x + dx, |
| 4419 | view->geometry.y + dy); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4420 | |
| 4421 | /* No need to check parent mappedness, because if parent is not |
| 4422 | * mapped, parent is not in a visible layer, so this sub-surface |
| 4423 | * will not be drawn either. |
| 4424 | */ |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 4425 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4426 | if (!weston_surface_is_mapped(surface)) { |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 4427 | surface->is_mapped = true; |
Pekka Paalanen | eb3cf22 | 2014-06-30 11:52:07 +0300 | [diff] [blame] | 4428 | |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 4429 | /* Cannot call weston_view_update_transform(), |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4430 | * because that would call it also for the parent surface, |
| 4431 | * which might not be mapped yet. That would lead to |
| 4432 | * inconsistent state, where the window could never be |
| 4433 | * mapped. |
| 4434 | * |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 4435 | * Instead just force the is_mapped flag on, to make |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4436 | * weston_surface_is_mapped() return true, so that when the |
| 4437 | * parent surface does get mapped, this one will get |
Pekka Paalanen | eb3cf22 | 2014-06-30 11:52:07 +0300 | [diff] [blame] | 4438 | * included, too. See view_list_add(). |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4439 | */ |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4440 | } |
| 4441 | } |
| 4442 | |
| 4443 | static struct weston_subsurface * |
| 4444 | weston_surface_to_subsurface(struct weston_surface *surface) |
| 4445 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 4446 | if (surface->committed == subsurface_committed) |
| 4447 | return surface->committed_private; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4448 | |
| 4449 | return NULL; |
| 4450 | } |
| 4451 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 4452 | WL_EXPORT struct weston_surface * |
| 4453 | weston_surface_get_main_surface(struct weston_surface *surface) |
| 4454 | { |
| 4455 | struct weston_subsurface *sub; |
| 4456 | |
| 4457 | while (surface && (sub = weston_surface_to_subsurface(surface))) |
| 4458 | surface = sub->parent; |
| 4459 | |
| 4460 | return surface; |
| 4461 | } |
| 4462 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4463 | WL_EXPORT int |
| 4464 | weston_surface_set_role(struct weston_surface *surface, |
| 4465 | const char *role_name, |
| 4466 | struct wl_resource *error_resource, |
| 4467 | uint32_t error_code) |
| 4468 | { |
| 4469 | assert(role_name); |
| 4470 | |
| 4471 | if (surface->role_name == NULL || |
| 4472 | surface->role_name == role_name || |
| 4473 | strcmp(surface->role_name, role_name) == 0) { |
| 4474 | surface->role_name = role_name; |
| 4475 | |
| 4476 | return 0; |
| 4477 | } |
| 4478 | |
| 4479 | wl_resource_post_error(error_resource, error_code, |
| 4480 | "Cannot assign role %s to wl_surface@%d," |
| 4481 | " already has role %s\n", |
| 4482 | role_name, |
| 4483 | wl_resource_get_id(surface->resource), |
| 4484 | surface->role_name); |
| 4485 | return -1; |
| 4486 | } |
| 4487 | |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 4488 | WL_EXPORT const char * |
| 4489 | weston_surface_get_role(struct weston_surface *surface) |
| 4490 | { |
| 4491 | return surface->role_name; |
| 4492 | } |
| 4493 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4494 | WL_EXPORT void |
| 4495 | weston_surface_set_label_func(struct weston_surface *surface, |
| 4496 | int (*desc)(struct weston_surface *, |
| 4497 | char *, size_t)) |
| 4498 | { |
| 4499 | surface->get_label = desc; |
Marius Vlad | 5de9297 | 2019-10-15 13:25:41 +0300 | [diff] [blame] | 4500 | weston_timeline_refresh_subscription_objects(surface->compositor, |
| 4501 | surface); |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4502 | } |
| 4503 | |
Pekka Paalanen | c647ed7 | 2015-02-09 13:16:57 +0200 | [diff] [blame] | 4504 | /** Get the size of surface contents |
| 4505 | * |
| 4506 | * \param surface The surface to query. |
| 4507 | * \param width Returns the width of raw contents. |
| 4508 | * \param height Returns the height of raw contents. |
| 4509 | * |
| 4510 | * Retrieves the raw surface content size in pixels for the given surface. |
| 4511 | * This is the whole content size in buffer pixels. If the surface |
| 4512 | * has no content or the renderer does not implement this feature, |
| 4513 | * zeroes are returned. |
| 4514 | * |
| 4515 | * This function is used to determine the buffer size needed for |
| 4516 | * a weston_surface_copy_content() call. |
| 4517 | */ |
| 4518 | WL_EXPORT void |
| 4519 | weston_surface_get_content_size(struct weston_surface *surface, |
| 4520 | int *width, int *height) |
| 4521 | { |
| 4522 | struct weston_renderer *rer = surface->compositor->renderer; |
| 4523 | |
| 4524 | if (!rer->surface_get_content_size) { |
| 4525 | *width = 0; |
| 4526 | *height = 0; |
| 4527 | return; |
| 4528 | } |
| 4529 | |
| 4530 | rer->surface_get_content_size(surface, width, height); |
| 4531 | } |
| 4532 | |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 4533 | /** Get the bounding box of a surface and its subsurfaces |
| 4534 | * |
| 4535 | * \param surface The surface to query. |
| 4536 | * \return The bounding box relative to the surface origin. |
| 4537 | * |
| 4538 | */ |
| 4539 | WL_EXPORT struct weston_geometry |
| 4540 | weston_surface_get_bounding_box(struct weston_surface *surface) |
| 4541 | { |
| 4542 | pixman_region32_t region; |
| 4543 | pixman_box32_t *box; |
| 4544 | struct weston_subsurface *subsurface; |
| 4545 | |
| 4546 | pixman_region32_init_rect(®ion, |
| 4547 | 0, 0, |
| 4548 | surface->width, surface->height); |
| 4549 | |
| 4550 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) |
| 4551 | pixman_region32_union_rect(®ion, ®ion, |
| 4552 | subsurface->position.x, |
| 4553 | subsurface->position.y, |
| 4554 | subsurface->surface->width, |
| 4555 | subsurface->surface->height); |
| 4556 | |
| 4557 | box = pixman_region32_extents(®ion); |
| 4558 | struct weston_geometry geometry = { |
| 4559 | .x = box->x1, |
| 4560 | .y = box->y1, |
| 4561 | .width = box->x2 - box->x1, |
| 4562 | .height = box->y2 - box->y1, |
| 4563 | }; |
| 4564 | |
| 4565 | pixman_region32_fini(®ion); |
| 4566 | |
| 4567 | return geometry; |
| 4568 | } |
| 4569 | |
Pekka Paalanen | c647ed7 | 2015-02-09 13:16:57 +0200 | [diff] [blame] | 4570 | /** Copy surface contents to system memory. |
| 4571 | * |
| 4572 | * \param surface The surface to copy from. |
| 4573 | * \param target Pointer to the target memory buffer. |
| 4574 | * \param size Size of the target buffer in bytes. |
| 4575 | * \param src_x X location on contents to copy from. |
| 4576 | * \param src_y Y location on contents to copy from. |
| 4577 | * \param width Width in pixels of the area to copy. |
| 4578 | * \param height Height in pixels of the area to copy. |
| 4579 | * \return 0 for success, -1 for failure. |
| 4580 | * |
| 4581 | * Surface contents are maintained by the renderer. They can be in a |
| 4582 | * reserved weston_buffer or as a copy, e.g. a GL texture, or something |
| 4583 | * else. |
| 4584 | * |
| 4585 | * Surface contents are copied into memory pointed to by target, |
| 4586 | * which has size bytes of space available. The target memory |
| 4587 | * may be larger than needed, but being smaller returns an error. |
| 4588 | * The extra bytes in target may or may not be written; their content is |
| 4589 | * unspecified. Size must be large enough to hold the image. |
| 4590 | * |
| 4591 | * The image in the target memory will be arranged in rows from |
| 4592 | * top to bottom, and pixels on a row from left to right. The pixel |
| 4593 | * format is PIXMAN_a8b8g8r8, 4 bytes per pixel, and stride is exactly |
| 4594 | * width * 4. |
| 4595 | * |
| 4596 | * Parameters src_x and src_y define the upper-left corner in buffer |
| 4597 | * coordinates (pixels) to copy from. Parameters width and height |
| 4598 | * define the size of the area to copy in pixels. |
| 4599 | * |
| 4600 | * The rectangle defined by src_x, src_y, width, height must fit in |
| 4601 | * the surface contents. Otherwise an error is returned. |
| 4602 | * |
Changwoo Cho | f97d250 | 2017-08-05 00:30:47 +0900 | [diff] [blame] | 4603 | * Use weston_surface_get_content_size to determine the content size; the |
Pekka Paalanen | c647ed7 | 2015-02-09 13:16:57 +0200 | [diff] [blame] | 4604 | * needed target buffer size and rectangle limits. |
| 4605 | * |
| 4606 | * CURRENT IMPLEMENTATION RESTRICTIONS: |
| 4607 | * - the machine must be little-endian due to Pixman formats. |
| 4608 | * |
| 4609 | * NOTE: Pixman formats are premultiplied. |
| 4610 | */ |
| 4611 | WL_EXPORT int |
| 4612 | weston_surface_copy_content(struct weston_surface *surface, |
| 4613 | void *target, size_t size, |
| 4614 | int src_x, int src_y, |
| 4615 | int width, int height) |
| 4616 | { |
| 4617 | struct weston_renderer *rer = surface->compositor->renderer; |
| 4618 | int cw, ch; |
| 4619 | const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */ |
| 4620 | |
| 4621 | if (!rer->surface_copy_content) |
| 4622 | return -1; |
| 4623 | |
| 4624 | weston_surface_get_content_size(surface, &cw, &ch); |
| 4625 | |
| 4626 | if (src_x < 0 || src_y < 0) |
| 4627 | return -1; |
| 4628 | |
| 4629 | if (width <= 0 || height <= 0) |
| 4630 | return -1; |
| 4631 | |
| 4632 | if (src_x + width > cw || src_y + height > ch) |
| 4633 | return -1; |
| 4634 | |
| 4635 | if (width * bytespp * height > size) |
| 4636 | return -1; |
| 4637 | |
| 4638 | return rer->surface_copy_content(surface, target, size, |
| 4639 | src_x, src_y, width, height); |
| 4640 | } |
| 4641 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4642 | static void |
| 4643 | subsurface_set_position(struct wl_client *client, |
| 4644 | struct wl_resource *resource, int32_t x, int32_t y) |
| 4645 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4646 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4647 | |
| 4648 | if (!sub) |
| 4649 | return; |
limin.tian | 531dd23 | 2025-01-07 12:09:27 +0000 | [diff] [blame] | 4650 | WESTON_LOGI(VIDEO_LOG, "x:%d, y:%d\n", x,y); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4651 | sub->position.x = x; |
| 4652 | sub->position.y = y; |
| 4653 | sub->position.set = 1; |
| 4654 | } |
| 4655 | |
| 4656 | static struct weston_subsurface * |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 4657 | subsurface_find_sibling(struct weston_subsurface *sub, |
| 4658 | struct weston_surface *surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4659 | { |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 4660 | struct weston_surface *parent = sub->parent; |
| 4661 | struct weston_subsurface *sibling; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4662 | |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 4663 | wl_list_for_each(sibling, &parent->subsurface_list, parent_link) { |
| 4664 | if (sibling->surface == surface && sibling != sub) |
| 4665 | return sibling; |
| 4666 | } |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4667 | |
| 4668 | return NULL; |
| 4669 | } |
| 4670 | |
| 4671 | static struct weston_subsurface * |
| 4672 | subsurface_sibling_check(struct weston_subsurface *sub, |
| 4673 | struct weston_surface *surface, |
| 4674 | const char *request) |
| 4675 | { |
| 4676 | struct weston_subsurface *sibling; |
| 4677 | |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 4678 | sibling = subsurface_find_sibling(sub, surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4679 | if (!sibling) { |
| 4680 | wl_resource_post_error(sub->resource, |
| 4681 | WL_SUBSURFACE_ERROR_BAD_SURFACE, |
| 4682 | "%s: wl_surface@%d is not a parent or sibling", |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4683 | request, wl_resource_get_id(surface->resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4684 | return NULL; |
| 4685 | } |
| 4686 | |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 4687 | assert(sibling->parent == sub->parent); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4688 | |
| 4689 | return sibling; |
| 4690 | } |
| 4691 | |
| 4692 | static void |
| 4693 | subsurface_place_above(struct wl_client *client, |
| 4694 | struct wl_resource *resource, |
| 4695 | struct wl_resource *sibling_resource) |
| 4696 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4697 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4698 | struct weston_surface *surface = |
| 4699 | wl_resource_get_user_data(sibling_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4700 | struct weston_subsurface *sibling; |
| 4701 | |
| 4702 | if (!sub) |
| 4703 | return; |
| 4704 | |
| 4705 | sibling = subsurface_sibling_check(sub, surface, "place_above"); |
| 4706 | if (!sibling) |
| 4707 | return; |
| 4708 | |
| 4709 | wl_list_remove(&sub->parent_link_pending); |
| 4710 | wl_list_insert(sibling->parent_link_pending.prev, |
| 4711 | &sub->parent_link_pending); |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 4712 | |
| 4713 | sub->reordered = true; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4714 | } |
| 4715 | |
| 4716 | static void |
| 4717 | subsurface_place_below(struct wl_client *client, |
| 4718 | struct wl_resource *resource, |
| 4719 | struct wl_resource *sibling_resource) |
| 4720 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4721 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4722 | struct weston_surface *surface = |
| 4723 | wl_resource_get_user_data(sibling_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4724 | struct weston_subsurface *sibling; |
| 4725 | |
| 4726 | if (!sub) |
| 4727 | return; |
| 4728 | |
| 4729 | sibling = subsurface_sibling_check(sub, surface, "place_below"); |
| 4730 | if (!sibling) |
| 4731 | return; |
| 4732 | |
| 4733 | wl_list_remove(&sub->parent_link_pending); |
| 4734 | wl_list_insert(&sibling->parent_link_pending, |
| 4735 | &sub->parent_link_pending); |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 4736 | |
| 4737 | sub->reordered = true; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4738 | } |
| 4739 | |
| 4740 | static void |
| 4741 | subsurface_set_sync(struct wl_client *client, struct wl_resource *resource) |
| 4742 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4743 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4744 | |
| 4745 | if (sub) |
| 4746 | sub->synchronized = 1; |
| 4747 | } |
| 4748 | |
| 4749 | static void |
| 4750 | subsurface_set_desync(struct wl_client *client, struct wl_resource *resource) |
| 4751 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4752 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4753 | |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 4754 | if (sub && sub->synchronized) { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4755 | sub->synchronized = 0; |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 4756 | |
| 4757 | /* If sub became effectively desynchronized, flush. */ |
| 4758 | if (!weston_subsurface_is_synchronized(sub)) |
| 4759 | weston_subsurface_synchronized_commit(sub); |
| 4760 | } |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4761 | } |
| 4762 | |
| 4763 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4764 | weston_subsurface_unlink_parent(struct weston_subsurface *sub) |
| 4765 | { |
| 4766 | wl_list_remove(&sub->parent_link); |
| 4767 | wl_list_remove(&sub->parent_link_pending); |
| 4768 | wl_list_remove(&sub->parent_destroy_listener.link); |
| 4769 | sub->parent = NULL; |
| 4770 | } |
| 4771 | |
| 4772 | static void |
| 4773 | weston_subsurface_destroy(struct weston_subsurface *sub); |
| 4774 | |
| 4775 | static void |
| 4776 | subsurface_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 4777 | { |
| 4778 | struct weston_subsurface *sub = |
| 4779 | container_of(listener, struct weston_subsurface, |
| 4780 | surface_destroy_listener); |
Pekka Paalanen | ca79076 | 2015-04-17 14:23:38 +0300 | [diff] [blame] | 4781 | assert(data == sub->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4782 | |
| 4783 | /* The protocol object (wl_resource) is left inert. */ |
| 4784 | if (sub->resource) |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4785 | wl_resource_set_user_data(sub->resource, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4786 | |
| 4787 | weston_subsurface_destroy(sub); |
| 4788 | } |
| 4789 | |
| 4790 | static void |
| 4791 | subsurface_handle_parent_destroy(struct wl_listener *listener, void *data) |
| 4792 | { |
| 4793 | struct weston_subsurface *sub = |
| 4794 | container_of(listener, struct weston_subsurface, |
| 4795 | parent_destroy_listener); |
Pekka Paalanen | ca79076 | 2015-04-17 14:23:38 +0300 | [diff] [blame] | 4796 | assert(data == sub->parent); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4797 | assert(sub->surface != sub->parent); |
| 4798 | |
| 4799 | if (weston_surface_is_mapped(sub->surface)) |
| 4800 | weston_surface_unmap(sub->surface); |
| 4801 | |
| 4802 | weston_subsurface_unlink_parent(sub); |
| 4803 | } |
| 4804 | |
| 4805 | static void |
| 4806 | subsurface_resource_destroy(struct wl_resource *resource) |
| 4807 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4808 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4809 | |
| 4810 | if (sub) |
| 4811 | weston_subsurface_destroy(sub); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4812 | } |
| 4813 | |
| 4814 | static void |
| 4815 | subsurface_destroy(struct wl_client *client, struct wl_resource *resource) |
| 4816 | { |
| 4817 | wl_resource_destroy(resource); |
| 4818 | } |
| 4819 | |
| 4820 | static void |
| 4821 | weston_subsurface_link_parent(struct weston_subsurface *sub, |
| 4822 | struct weston_surface *parent) |
| 4823 | { |
| 4824 | sub->parent = parent; |
| 4825 | sub->parent_destroy_listener.notify = subsurface_handle_parent_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4826 | wl_signal_add(&parent->destroy_signal, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4827 | &sub->parent_destroy_listener); |
| 4828 | |
| 4829 | wl_list_insert(&parent->subsurface_list, &sub->parent_link); |
| 4830 | wl_list_insert(&parent->subsurface_list_pending, |
| 4831 | &sub->parent_link_pending); |
| 4832 | } |
| 4833 | |
| 4834 | static void |
| 4835 | weston_subsurface_link_surface(struct weston_subsurface *sub, |
| 4836 | struct weston_surface *surface) |
| 4837 | { |
| 4838 | sub->surface = surface; |
| 4839 | sub->surface_destroy_listener.notify = |
| 4840 | subsurface_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4841 | wl_signal_add(&surface->destroy_signal, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4842 | &sub->surface_destroy_listener); |
| 4843 | } |
| 4844 | |
| 4845 | static void |
| 4846 | weston_subsurface_destroy(struct weston_subsurface *sub) |
| 4847 | { |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 4848 | weston_log("\nweston_subsurface_destroy sub:%p ->%p\n", sub, sub->surface); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4849 | struct weston_view *view, *next; |
| 4850 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4851 | assert(sub->surface); |
| 4852 | |
| 4853 | if (sub->resource) { |
| 4854 | assert(weston_surface_to_subsurface(sub->surface) == sub); |
| 4855 | assert(sub->parent_destroy_listener.notify == |
| 4856 | subsurface_handle_parent_destroy); |
| 4857 | |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 4858 | wl_list_for_each_safe(view, next, &sub->surface->views, surface_link) { |
| 4859 | weston_view_unmap(view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4860 | weston_view_destroy(view); |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 4861 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4862 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4863 | if (sub->parent) |
| 4864 | weston_subsurface_unlink_parent(sub); |
| 4865 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 4866 | weston_surface_state_fini(&sub->cached); |
| 4867 | weston_buffer_reference(&sub->cached_buffer_ref, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4868 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 4869 | sub->surface->committed = NULL; |
| 4870 | sub->surface->committed_private = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4871 | weston_surface_set_label_func(sub->surface, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4872 | } else { |
| 4873 | /* the dummy weston_subsurface for the parent itself */ |
| 4874 | assert(sub->parent_destroy_listener.notify == NULL); |
| 4875 | wl_list_remove(&sub->parent_link); |
| 4876 | wl_list_remove(&sub->parent_link_pending); |
| 4877 | } |
| 4878 | |
| 4879 | wl_list_remove(&sub->surface_destroy_listener.link); |
| 4880 | free(sub); |
| 4881 | } |
| 4882 | |
| 4883 | static const struct wl_subsurface_interface subsurface_implementation = { |
| 4884 | subsurface_destroy, |
| 4885 | subsurface_set_position, |
| 4886 | subsurface_place_above, |
| 4887 | subsurface_place_below, |
| 4888 | subsurface_set_sync, |
| 4889 | subsurface_set_desync |
| 4890 | }; |
| 4891 | |
| 4892 | static struct weston_subsurface * |
| 4893 | weston_subsurface_create(uint32_t id, struct weston_surface *surface, |
| 4894 | struct weston_surface *parent) |
| 4895 | { |
| 4896 | struct weston_subsurface *sub; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4897 | struct wl_client *client = wl_resource_get_client(surface->resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4898 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 4899 | sub = zalloc(sizeof *sub); |
| 4900 | if (sub == NULL) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4901 | return NULL; |
| 4902 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4903 | wl_list_init(&sub->unused_views); |
| 4904 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4905 | sub->resource = |
| 4906 | wl_resource_create(client, &wl_subsurface_interface, 1, id); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4907 | if (!sub->resource) { |
| 4908 | free(sub); |
| 4909 | return NULL; |
| 4910 | } |
| 4911 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4912 | wl_resource_set_implementation(sub->resource, |
| 4913 | &subsurface_implementation, |
| 4914 | sub, subsurface_resource_destroy); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4915 | weston_subsurface_link_surface(sub, surface); |
| 4916 | weston_subsurface_link_parent(sub, parent); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 4917 | weston_surface_state_init(&sub->cached); |
| 4918 | sub->cached_buffer_ref.buffer = NULL; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4919 | sub->synchronized = 1; |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 4920 | weston_log("\n weston_subsurface_create :%p sub:%p\n",surface, sub ); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4921 | |
| 4922 | return sub; |
| 4923 | } |
| 4924 | |
| 4925 | /* Create a dummy subsurface for having the parent itself in its |
| 4926 | * sub-surface lists. Makes stacking order manipulation easy. |
| 4927 | */ |
| 4928 | static struct weston_subsurface * |
| 4929 | weston_subsurface_create_for_parent(struct weston_surface *parent) |
| 4930 | { |
| 4931 | struct weston_subsurface *sub; |
| 4932 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 4933 | sub = zalloc(sizeof *sub); |
| 4934 | if (sub == NULL) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4935 | return NULL; |
| 4936 | |
| 4937 | weston_subsurface_link_surface(sub, parent); |
| 4938 | sub->parent = parent; |
| 4939 | wl_list_insert(&parent->subsurface_list, &sub->parent_link); |
| 4940 | wl_list_insert(&parent->subsurface_list_pending, |
| 4941 | &sub->parent_link_pending); |
| 4942 | |
| 4943 | return sub; |
| 4944 | } |
| 4945 | |
| 4946 | static void |
| 4947 | subcompositor_get_subsurface(struct wl_client *client, |
| 4948 | struct wl_resource *resource, |
| 4949 | uint32_t id, |
| 4950 | struct wl_resource *surface_resource, |
| 4951 | struct wl_resource *parent_resource) |
| 4952 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4953 | struct weston_surface *surface = |
| 4954 | wl_resource_get_user_data(surface_resource); |
| 4955 | struct weston_surface *parent = |
| 4956 | wl_resource_get_user_data(parent_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4957 | struct weston_subsurface *sub; |
| 4958 | static const char where[] = "get_subsurface: wl_subsurface@"; |
| 4959 | |
| 4960 | if (surface == parent) { |
| 4961 | wl_resource_post_error(resource, |
| 4962 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 4963 | "%s%d: wl_surface@%d cannot be its own parent", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4964 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4965 | return; |
| 4966 | } |
| 4967 | |
| 4968 | if (weston_surface_to_subsurface(surface)) { |
| 4969 | wl_resource_post_error(resource, |
| 4970 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 4971 | "%s%d: wl_surface@%d is already a sub-surface", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4972 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4973 | return; |
| 4974 | } |
| 4975 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4976 | if (weston_surface_set_role(surface, "wl_subsurface", resource, |
| 4977 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE) < 0) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4978 | return; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4979 | |
Pekka Paalanen | 86c8ca0 | 2013-05-17 16:46:07 +0300 | [diff] [blame] | 4980 | if (weston_surface_get_main_surface(parent) == surface) { |
| 4981 | wl_resource_post_error(resource, |
| 4982 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 4983 | "%s%d: wl_surface@%d is an ancestor of parent", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4984 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | 86c8ca0 | 2013-05-17 16:46:07 +0300 | [diff] [blame] | 4985 | return; |
| 4986 | } |
| 4987 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4988 | /* make sure the parent is in its own list */ |
| 4989 | if (wl_list_empty(&parent->subsurface_list)) { |
| 4990 | if (!weston_subsurface_create_for_parent(parent)) { |
| 4991 | wl_resource_post_no_memory(resource); |
| 4992 | return; |
| 4993 | } |
| 4994 | } |
| 4995 | |
| 4996 | sub = weston_subsurface_create(id, surface, parent); |
| 4997 | if (!sub) { |
| 4998 | wl_resource_post_no_memory(resource); |
| 4999 | return; |
| 5000 | } |
| 5001 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 5002 | surface->committed = subsurface_committed; |
| 5003 | surface->committed_private = sub; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 5004 | weston_surface_set_label_func(surface, subsurface_get_label); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 5005 | } |
| 5006 | |
| 5007 | static void |
| 5008 | subcompositor_destroy(struct wl_client *client, struct wl_resource *resource) |
| 5009 | { |
| 5010 | wl_resource_destroy(resource); |
| 5011 | } |
| 5012 | |
| 5013 | static const struct wl_subcompositor_interface subcompositor_interface = { |
| 5014 | subcompositor_destroy, |
| 5015 | subcompositor_get_subsurface |
| 5016 | }; |
| 5017 | |
| 5018 | static void |
| 5019 | bind_subcompositor(struct wl_client *client, |
| 5020 | void *data, uint32_t version, uint32_t id) |
| 5021 | { |
| 5022 | struct weston_compositor *compositor = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5023 | struct wl_resource *resource; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 5024 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5025 | resource = |
| 5026 | wl_resource_create(client, &wl_subcompositor_interface, 1, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 5027 | if (resource == NULL) { |
| 5028 | wl_client_post_no_memory(client); |
| 5029 | return; |
| 5030 | } |
| 5031 | wl_resource_set_implementation(resource, &subcompositor_interface, |
| 5032 | compositor, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 5033 | } |
| 5034 | |
Bryce Harrington | 0795ece | 2016-08-30 12:04:26 -0700 | [diff] [blame] | 5035 | /** Set a DPMS mode on all of the compositor's outputs |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 5036 | * |
| 5037 | * \param compositor The compositor instance |
| 5038 | * \param state The DPMS state the outputs will be set to |
| 5039 | */ |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 5040 | static void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5041 | weston_compositor_dpms(struct weston_compositor *compositor, |
| 5042 | enum dpms_enum state) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5043 | { |
Emmanuel Gil Peyrot | eff793a | 2021-07-31 17:25:41 +0200 | [diff] [blame] | 5044 | struct weston_output *output; |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5045 | |
Emmanuel Gil Peyrot | eff793a | 2021-07-31 17:25:41 +0200 | [diff] [blame] | 5046 | wl_list_for_each(output, &compositor->output_list, link) |
Bryce Harrington | 08976ac | 2016-08-30 12:05:16 -0700 | [diff] [blame] | 5047 | if (output->set_dpms) |
| 5048 | output->set_dpms(output, state); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 5049 | } |
| 5050 | |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 5051 | /** Restores the compositor to active status |
| 5052 | * |
| 5053 | * \param compositor The compositor instance |
| 5054 | * |
| 5055 | * If the compositor was in a sleeping mode, all outputs are powered |
| 5056 | * back on via DPMS. Otherwise if the compositor was inactive |
| 5057 | * (idle/locked, offscreen, or sleeping) then the compositor's wake |
| 5058 | * signal will fire. |
| 5059 | * |
| 5060 | * Restarts the idle timer. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 5061 | * \ingroup compositor |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 5062 | */ |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 5063 | WL_EXPORT void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5064 | weston_compositor_wake(struct weston_compositor *compositor) |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 5065 | { |
Neil Roberts | 8b62e20 | 2013-09-30 13:14:47 +0100 | [diff] [blame] | 5066 | uint32_t old_state = compositor->state; |
| 5067 | |
| 5068 | /* The state needs to be changed before emitting the wake |
| 5069 | * signal because that may try to schedule a repaint which |
| 5070 | * will not work if the compositor is still sleeping */ |
| 5071 | compositor->state = WESTON_COMPOSITOR_ACTIVE; |
| 5072 | |
| 5073 | switch (old_state) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5074 | case WESTON_COMPOSITOR_SLEEPING: |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5075 | case WESTON_COMPOSITOR_IDLE: |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 5076 | case WESTON_COMPOSITOR_OFFSCREEN: |
Daniel Stone | 893b936 | 2016-11-08 15:47:09 +0000 | [diff] [blame] | 5077 | weston_compositor_dpms(compositor, WESTON_DPMS_ON); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5078 | wl_signal_emit(&compositor->wake_signal, compositor); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5079 | /* fall through */ |
| 5080 | default: |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5081 | wl_event_source_timer_update(compositor->idle_source, |
| 5082 | compositor->idle_time * 1000); |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 5083 | } |
| 5084 | } |
| 5085 | |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 5086 | /** Turns off rendering and frame events for the compositor. |
| 5087 | * |
| 5088 | * \param compositor The compositor instance |
| 5089 | * |
| 5090 | * This is used for example to prevent further rendering while the |
| 5091 | * compositor is shutting down. |
| 5092 | * |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 5093 | * Stops the idle timer. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 5094 | * |
| 5095 | * \ingroup compositor |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 5096 | */ |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5097 | WL_EXPORT void |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 5098 | weston_compositor_offscreen(struct weston_compositor *compositor) |
| 5099 | { |
| 5100 | switch (compositor->state) { |
| 5101 | case WESTON_COMPOSITOR_OFFSCREEN: |
| 5102 | return; |
| 5103 | case WESTON_COMPOSITOR_SLEEPING: |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 5104 | default: |
| 5105 | compositor->state = WESTON_COMPOSITOR_OFFSCREEN; |
| 5106 | wl_event_source_timer_update(compositor->idle_source, 0); |
| 5107 | } |
| 5108 | } |
| 5109 | |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 5110 | /** Powers down all attached output devices |
| 5111 | * |
| 5112 | * \param compositor The compositor instance |
| 5113 | * |
| 5114 | * Causes rendering to the outputs to cease, and no frame events to be |
| 5115 | * sent. Only powers down the outputs if the compositor is not already |
| 5116 | * in sleep mode. |
| 5117 | * |
| 5118 | * Stops the idle timer. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 5119 | * |
| 5120 | * \ingroup compositor |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 5121 | */ |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 5122 | WL_EXPORT void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5123 | weston_compositor_sleep(struct weston_compositor *compositor) |
| 5124 | { |
| 5125 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING) |
| 5126 | return; |
| 5127 | |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 5128 | wl_event_source_timer_update(compositor->idle_source, 0); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 5129 | compositor->state = WESTON_COMPOSITOR_SLEEPING; |
| 5130 | weston_compositor_dpms(compositor, WESTON_DPMS_OFF); |
| 5131 | } |
| 5132 | |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 5133 | /** Sets compositor to idle mode |
| 5134 | * |
| 5135 | * \param data The compositor instance |
| 5136 | * |
| 5137 | * This is called when the idle timer fires. Once the compositor is in |
| 5138 | * idle mode it requires a wake action (e.g. via |
| 5139 | * weston_compositor_wake()) to restore it. The compositor's |
| 5140 | * idle_signal will be triggered when the idle event occurs. |
| 5141 | * |
| 5142 | * Idleness can be inhibited by setting the compositor's idle_inhibit |
| 5143 | * property. |
| 5144 | */ |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 5145 | static int |
| 5146 | idle_handler(void *data) |
| 5147 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5148 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 5149 | |
| 5150 | if (compositor->idle_inhibit) |
| 5151 | return 1; |
| 5152 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 5153 | compositor->state = WESTON_COMPOSITOR_IDLE; |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5154 | wl_signal_emit(&compositor->idle_signal, compositor); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 5155 | |
| 5156 | return 1; |
| 5157 | } |
| 5158 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 5159 | WL_EXPORT void |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 5160 | weston_plane_init(struct weston_plane *plane, |
| 5161 | struct weston_compositor *ec, |
| 5162 | int32_t x, int32_t y) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 5163 | { |
| 5164 | pixman_region32_init(&plane->damage); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 5165 | pixman_region32_init(&plane->clip); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 5166 | plane->x = x; |
| 5167 | plane->y = y; |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 5168 | plane->compositor = ec; |
Ander Conselvan de Oliveira | 3c36bf3 | 2013-07-05 16:05:26 +0300 | [diff] [blame] | 5169 | |
| 5170 | /* Init the link so that the call to wl_list_remove() when releasing |
| 5171 | * the plane without ever stacking doesn't lead to a crash */ |
| 5172 | wl_list_init(&plane->link); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 5173 | } |
| 5174 | |
| 5175 | WL_EXPORT void |
| 5176 | weston_plane_release(struct weston_plane *plane) |
| 5177 | { |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 5178 | struct weston_view *view; |
| 5179 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 5180 | pixman_region32_fini(&plane->damage); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 5181 | pixman_region32_fini(&plane->clip); |
Ander Conselvan de Oliveira | 3c36bf3 | 2013-07-05 16:05:26 +0300 | [diff] [blame] | 5182 | |
Pekka Paalanen | 6551c09 | 2021-05-03 16:09:45 +0300 | [diff] [blame] | 5183 | /* |
| 5184 | * Can't use paint node list here, weston_plane is not specific to an |
| 5185 | * output. |
| 5186 | */ |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 5187 | wl_list_for_each(view, &plane->compositor->view_list, link) { |
| 5188 | if (view->plane == plane) |
| 5189 | view->plane = NULL; |
| 5190 | } |
| 5191 | |
Ander Conselvan de Oliveira | 3c36bf3 | 2013-07-05 16:05:26 +0300 | [diff] [blame] | 5192 | wl_list_remove(&plane->link); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 5193 | } |
| 5194 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 5195 | /** weston_compositor_stack_plane |
| 5196 | * \ingroup compositor |
| 5197 | */ |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 5198 | WL_EXPORT void |
| 5199 | weston_compositor_stack_plane(struct weston_compositor *ec, |
| 5200 | struct weston_plane *plane, |
| 5201 | struct weston_plane *above) |
| 5202 | { |
| 5203 | if (above) |
| 5204 | wl_list_insert(above->link.prev, &plane->link); |
| 5205 | else |
| 5206 | wl_list_insert(&ec->plane_list, &plane->link); |
| 5207 | } |
| 5208 | |
Quentin Glidic | 4ef719c | 2016-07-05 20:44:33 +0200 | [diff] [blame] | 5209 | static void |
| 5210 | output_release(struct wl_client *client, struct wl_resource *resource) |
| 5211 | { |
| 5212 | wl_resource_destroy(resource); |
| 5213 | } |
| 5214 | |
| 5215 | static const struct wl_output_interface output_interface = { |
| 5216 | output_release, |
| 5217 | }; |
| 5218 | |
| 5219 | |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 5220 | static void unbind_resource(struct wl_resource *resource) |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 5221 | { |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 5222 | wl_list_remove(wl_resource_get_link(resource)); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 5223 | } |
| 5224 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5225 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 5226 | bind_output(struct wl_client *client, |
| 5227 | void *data, uint32_t version, uint32_t id) |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 5228 | { |
Pekka Paalanen | 0534762 | 2017-03-27 12:24:34 +0300 | [diff] [blame] | 5229 | struct weston_head *head = data; |
| 5230 | struct weston_output *output = head->output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5231 | struct weston_mode *mode; |
Kristian Høgsberg | fd07fb7 | 2011-08-29 15:03:09 -0400 | [diff] [blame] | 5232 | struct wl_resource *resource; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 5233 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5234 | resource = wl_resource_create(client, &wl_output_interface, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 5235 | version, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 5236 | if (resource == NULL) { |
| 5237 | wl_client_post_no_memory(client); |
| 5238 | return; |
| 5239 | } |
Kristian Høgsberg | fd07fb7 | 2011-08-29 15:03:09 -0400 | [diff] [blame] | 5240 | |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 5241 | wl_list_insert(&head->resource_list, wl_resource_get_link(resource)); |
Pekka Paalanen | 055c113 | 2017-03-27 16:31:25 +0300 | [diff] [blame] | 5242 | wl_resource_set_implementation(resource, &output_interface, head, |
Pekka Paalanen | 0534762 | 2017-03-27 12:24:34 +0300 | [diff] [blame] | 5243 | unbind_resource); |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 5244 | |
Pekka Paalanen | 0534762 | 2017-03-27 12:24:34 +0300 | [diff] [blame] | 5245 | assert(output); |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 5246 | wl_output_send_geometry(resource, |
| 5247 | output->x, |
| 5248 | output->y, |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5249 | head->mm_width, |
| 5250 | head->mm_height, |
| 5251 | head->subpixel, |
| 5252 | head->make, head->model, |
Kristian Høgsberg | 05890dc | 2012-08-10 10:09:20 -0400 | [diff] [blame] | 5253 | output->transform); |
Jasper St. Pierre | 0013a29 | 2014-08-07 16:43:11 -0400 | [diff] [blame] | 5254 | if (version >= WL_OUTPUT_SCALE_SINCE_VERSION) |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 5255 | wl_output_send_scale(resource, |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 5256 | output->current_scale); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 5257 | |
| 5258 | wl_list_for_each (mode, &output->mode_list, link) { |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 5259 | wl_output_send_mode(resource, |
| 5260 | mode->flags, |
| 5261 | mode->width, |
| 5262 | mode->height, |
| 5263 | mode->refresh); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 5264 | } |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 5265 | struct drm_output *drm_output = to_drm_output(output); |
| 5266 | int crtc_index = drm_output->crtc->pipe; |
Dongjin Kim | 4995f4a | 2024-12-19 02:12:34 +0000 | [diff] [blame] | 5267 | #if 0 |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 5268 | if (version >= WL_OUTPUT_CRTC_INDEX_SINCE_VERSION) |
| 5269 | wl_output_send_crtc_index(resource, crtc_index); |
Dongjin Kim | 4995f4a | 2024-12-19 02:12:34 +0000 | [diff] [blame] | 5270 | #endif |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 5271 | |
Jasper St. Pierre | 0013a29 | 2014-08-07 16:43:11 -0400 | [diff] [blame] | 5272 | if (version >= WL_OUTPUT_DONE_SINCE_VERSION) |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 5273 | wl_output_send_done(resource); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 5274 | } |
| 5275 | |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 5276 | static void |
| 5277 | weston_head_add_global(struct weston_head *head) |
| 5278 | { |
| 5279 | head->global = wl_global_create(head->compositor->wl_display, |
| 5280 | &wl_output_interface, 3, |
| 5281 | head, bind_output); |
| 5282 | } |
| 5283 | |
Pekka Paalanen | d9dcc6d | 2017-12-04 15:28:13 +0200 | [diff] [blame] | 5284 | /** Remove the global wl_output protocol object |
| 5285 | * |
| 5286 | * \param head The head whose global to remove. |
| 5287 | * |
| 5288 | * Also orphans the wl_resources for this head (wl_output). |
| 5289 | */ |
| 5290 | static void |
| 5291 | weston_head_remove_global(struct weston_head *head) |
| 5292 | { |
| 5293 | struct wl_resource *resource, *tmp; |
| 5294 | |
| 5295 | if (head->global) |
| 5296 | wl_global_destroy(head->global); |
| 5297 | head->global = NULL; |
| 5298 | |
| 5299 | wl_resource_for_each_safe(resource, tmp, &head->resource_list) { |
| 5300 | unbind_resource(resource); |
| 5301 | wl_resource_set_destructor(resource, NULL); |
| 5302 | wl_resource_set_user_data(resource, NULL); |
| 5303 | } |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 5304 | |
| 5305 | wl_resource_for_each(resource, &head->xdg_output_resource_list) { |
| 5306 | /* It's sufficient to unset the destructor, then the list elements |
| 5307 | * won't be accessed. |
| 5308 | */ |
| 5309 | wl_resource_set_destructor(resource, NULL); |
| 5310 | } |
| 5311 | wl_list_init(&head->xdg_output_resource_list); |
Pekka Paalanen | d9dcc6d | 2017-12-04 15:28:13 +0200 | [diff] [blame] | 5312 | } |
| 5313 | |
Pekka Paalanen | 9ffb250 | 2017-03-27 15:14:32 +0300 | [diff] [blame] | 5314 | /** Get the backing object of wl_output |
| 5315 | * |
| 5316 | * \param resource A wl_output protocol object. |
| 5317 | * \return The backing object (user data) of a wl_resource representing a |
| 5318 | * wl_output protocol object. |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5319 | * |
| 5320 | * \ingroup head |
Pekka Paalanen | 9ffb250 | 2017-03-27 15:14:32 +0300 | [diff] [blame] | 5321 | */ |
Pekka Paalanen | 055c113 | 2017-03-27 16:31:25 +0300 | [diff] [blame] | 5322 | WL_EXPORT struct weston_head * |
| 5323 | weston_head_from_resource(struct wl_resource *resource) |
Pekka Paalanen | 9ffb250 | 2017-03-27 15:14:32 +0300 | [diff] [blame] | 5324 | { |
| 5325 | assert(wl_resource_instance_of(resource, &wl_output_interface, |
| 5326 | &output_interface)); |
| 5327 | |
| 5328 | return wl_resource_get_user_data(resource); |
| 5329 | } |
| 5330 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5331 | /** Initialize a pre-allocated weston_head |
| 5332 | * |
| 5333 | * \param head The head to initialize. |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 5334 | * \param name The head name, e.g. the connector name or equivalent. |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5335 | * |
| 5336 | * The head will be safe to attach, detach and release. |
| 5337 | * |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 5338 | * The name is used in logs, and can be used by compositors as a configuration |
| 5339 | * identifier. |
| 5340 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5341 | * \ingroup head |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5342 | * \internal |
| 5343 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5344 | WL_EXPORT void |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 5345 | weston_head_init(struct weston_head *head, const char *name) |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5346 | { |
| 5347 | /* Add some (in)sane defaults which can be used |
| 5348 | * for checking if an output was properly configured |
| 5349 | */ |
| 5350 | memset(head, 0, sizeof *head); |
| 5351 | |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 5352 | wl_list_init(&head->compositor_link); |
Pekka Paalanen | 2e1bedb | 2017-10-10 11:21:58 +0300 | [diff] [blame] | 5353 | wl_signal_init(&head->destroy_signal); |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5354 | wl_list_init(&head->output_link); |
| 5355 | wl_list_init(&head->resource_list); |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 5356 | wl_list_init(&head->xdg_output_resource_list); |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 5357 | head->name = strdup(name); |
Ankit Nautiyal | 4f64ff8 | 2019-04-03 18:44:35 +0530 | [diff] [blame] | 5358 | head->current_protection = WESTON_HDCP_DISABLE; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5359 | } |
| 5360 | |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 5361 | /** Send output heads changed signal |
| 5362 | * |
| 5363 | * \param output The output that changed. |
| 5364 | * |
| 5365 | * Notify that the enabled output gained and/or lost heads, or that the |
| 5366 | * associated heads may have changed their connection status. This does not |
| 5367 | * include cases where the output becomes enabled or disabled. The registered |
| 5368 | * callbacks are called after the change has successfully happened. |
| 5369 | * |
| 5370 | * If connection status change causes the compositor to attach or detach a head |
| 5371 | * to an enabled output, the registered callbacks may be called multiple times. |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 5372 | * |
| 5373 | * \ingroup output |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 5374 | */ |
| 5375 | static void |
| 5376 | weston_output_emit_heads_changed(struct weston_output *output) |
| 5377 | { |
| 5378 | wl_signal_emit(&output->compositor->output_heads_changed_signal, |
| 5379 | output); |
| 5380 | } |
| 5381 | |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5382 | /** Idle task for emitting heads_changed_signal */ |
| 5383 | static void |
| 5384 | weston_compositor_call_heads_changed(void *data) |
| 5385 | { |
| 5386 | struct weston_compositor *compositor = data; |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 5387 | struct weston_head *head; |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5388 | |
| 5389 | compositor->heads_changed_source = NULL; |
| 5390 | |
| 5391 | wl_signal_emit(&compositor->heads_changed_signal, compositor); |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 5392 | |
| 5393 | wl_list_for_each(head, &compositor->head_list, compositor_link) { |
| 5394 | if (head->output && head->output->enabled) |
| 5395 | weston_output_emit_heads_changed(head->output); |
| 5396 | } |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5397 | } |
| 5398 | |
| 5399 | /** Schedule a call on idle to heads_changed callback |
| 5400 | * |
| 5401 | * \param compositor The Compositor. |
| 5402 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 5403 | * \ingroup compositor |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5404 | * \internal |
| 5405 | */ |
| 5406 | static void |
| 5407 | weston_compositor_schedule_heads_changed(struct weston_compositor *compositor) |
| 5408 | { |
| 5409 | struct wl_event_loop *loop; |
| 5410 | |
| 5411 | if (compositor->heads_changed_source) |
| 5412 | return; |
| 5413 | |
| 5414 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 5415 | compositor->heads_changed_source = wl_event_loop_add_idle(loop, |
| 5416 | weston_compositor_call_heads_changed, compositor); |
| 5417 | } |
| 5418 | |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 5419 | /** Register a new head |
| 5420 | * |
| 5421 | * \param compositor The compositor. |
| 5422 | * \param head The head to register, must not be already registered. |
| 5423 | * |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5424 | * This signals the core that a new head has become available, leading to |
| 5425 | * heads_changed hook being called later. |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 5426 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 5427 | * \ingroup compositor |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 5428 | * \internal |
| 5429 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5430 | WL_EXPORT void |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 5431 | weston_compositor_add_head(struct weston_compositor *compositor, |
| 5432 | struct weston_head *head) |
| 5433 | { |
| 5434 | assert(wl_list_empty(&head->compositor_link)); |
| 5435 | assert(head->name); |
| 5436 | |
| 5437 | wl_list_insert(compositor->head_list.prev, &head->compositor_link); |
| 5438 | head->compositor = compositor; |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5439 | weston_compositor_schedule_heads_changed(compositor); |
| 5440 | } |
| 5441 | |
| 5442 | /** Adds a listener to be called when heads change |
| 5443 | * |
| 5444 | * \param compositor The compositor. |
| 5445 | * \param listener The listener to add. |
| 5446 | * |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 5447 | * The listener notify function argument is weston_compositor. |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5448 | * |
| 5449 | * The listener function will be called after heads are added or their |
| 5450 | * connection status has changed. Several changes may be accumulated into a |
| 5451 | * single call. The user is expected to iterate over the existing heads and |
| 5452 | * check their statuses to find out what changed. |
| 5453 | * |
| 5454 | * \sa weston_compositor_iterate_heads, weston_head_is_connected, |
| 5455 | * weston_head_is_enabled |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 5456 | * \ingroup compositor |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5457 | */ |
| 5458 | WL_EXPORT void |
| 5459 | weston_compositor_add_heads_changed_listener(struct weston_compositor *compositor, |
| 5460 | struct wl_listener *listener) |
| 5461 | { |
| 5462 | wl_signal_add(&compositor->heads_changed_signal, listener); |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 5463 | } |
| 5464 | |
| 5465 | /** Iterate over available heads |
| 5466 | * |
| 5467 | * \param compositor The compositor. |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 5468 | * \param iter The iterator, or NULL for start. |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 5469 | * \return The next available head in the list. |
| 5470 | * |
| 5471 | * Returns all available heads, regardless of being connected or enabled. |
| 5472 | * |
| 5473 | * You can iterate over all heads as follows: |
| 5474 | * \code |
| 5475 | * struct weston_head *head = NULL; |
| 5476 | * |
| 5477 | * while ((head = weston_compositor_iterate_heads(compositor, head))) { |
| 5478 | * ... |
| 5479 | * } |
| 5480 | * \endcode |
| 5481 | * |
| 5482 | * If you cause \c iter to be removed from the list, you cannot use it to |
| 5483 | * continue iterating. Removing any other item is safe. |
| 5484 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 5485 | * \ingroup compositor |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 5486 | */ |
| 5487 | WL_EXPORT struct weston_head * |
| 5488 | weston_compositor_iterate_heads(struct weston_compositor *compositor, |
| 5489 | struct weston_head *iter) |
| 5490 | { |
| 5491 | struct wl_list *list = &compositor->head_list; |
| 5492 | struct wl_list *node; |
| 5493 | |
| 5494 | assert(compositor); |
| 5495 | assert(!iter || iter->compositor == compositor); |
| 5496 | |
| 5497 | if (iter) |
| 5498 | node = iter->compositor_link.next; |
| 5499 | else |
| 5500 | node = list->next; |
| 5501 | |
| 5502 | assert(node); |
| 5503 | assert(!iter || node != &iter->compositor_link); |
| 5504 | |
| 5505 | if (node == list) |
| 5506 | return NULL; |
| 5507 | |
| 5508 | return container_of(node, struct weston_head, compositor_link); |
| 5509 | } |
| 5510 | |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5511 | /** Iterate over attached heads |
| 5512 | * |
| 5513 | * \param output The output whose heads to iterate. |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 5514 | * \param iter The iterator, or NULL for start. |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5515 | * \return The next attached head in the list. |
| 5516 | * |
| 5517 | * Returns all heads currently attached to the output. |
| 5518 | * |
| 5519 | * You can iterate over all heads as follows: |
| 5520 | * \code |
| 5521 | * struct weston_head *head = NULL; |
| 5522 | * |
| 5523 | * while ((head = weston_output_iterate_heads(output, head))) { |
| 5524 | * ... |
| 5525 | * } |
| 5526 | * \endcode |
| 5527 | * |
| 5528 | * If you cause \c iter to be removed from the list, you cannot use it to |
| 5529 | * continue iterating. Removing any other item is safe. |
| 5530 | * |
Maxime Roussin-Bélanger | 1d009c2 | 2020-12-17 17:10:13 -0500 | [diff] [blame] | 5531 | * \ingroup output |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5532 | */ |
| 5533 | WL_EXPORT struct weston_head * |
| 5534 | weston_output_iterate_heads(struct weston_output *output, |
| 5535 | struct weston_head *iter) |
| 5536 | { |
| 5537 | struct wl_list *list = &output->head_list; |
| 5538 | struct wl_list *node; |
| 5539 | |
| 5540 | assert(output); |
| 5541 | assert(!iter || iter->output == output); |
| 5542 | |
| 5543 | if (iter) |
| 5544 | node = iter->output_link.next; |
| 5545 | else |
| 5546 | node = list->next; |
| 5547 | |
| 5548 | assert(node); |
| 5549 | assert(!iter || node != &iter->output_link); |
| 5550 | |
| 5551 | if (node == list) |
| 5552 | return NULL; |
| 5553 | |
| 5554 | return container_of(node, struct weston_head, output_link); |
| 5555 | } |
| 5556 | |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 5557 | /** Attach a head to an output |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5558 | * |
| 5559 | * \param output The output to attach to. |
| 5560 | * \param head The head that is not yet attached. |
| 5561 | * \return 0 on success, -1 on failure. |
| 5562 | * |
| 5563 | * Attaches the given head to the output. All heads of an output are clones |
| 5564 | * and share the resolution and timings. |
| 5565 | * |
| 5566 | * Cloning heads this way uses less resources than creating an output for |
| 5567 | * each head, but is not always possible due to environment, driver and hardware |
| 5568 | * limitations. |
| 5569 | * |
| 5570 | * On failure, the head remains unattached. Success of this function does not |
| 5571 | * guarantee the output configuration is actually valid. The final checks are |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 5572 | * made on weston_output_enable() unless the output was already enabled. |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5573 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 5574 | * \ingroup output |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5575 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5576 | WL_EXPORT int |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5577 | weston_output_attach_head(struct weston_output *output, |
| 5578 | struct weston_head *head) |
| 5579 | { |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 5580 | char *head_names; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5581 | |
| 5582 | if (!wl_list_empty(&head->output_link)) |
| 5583 | return -1; |
| 5584 | |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5585 | if (output->attach_head) { |
| 5586 | if (output->attach_head(output, head) < 0) |
| 5587 | return -1; |
| 5588 | } else if (!wl_list_empty(&output->head_list)) { |
| 5589 | /* No support for clones in the legacy path. */ |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5590 | return -1; |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5591 | } |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5592 | |
| 5593 | head->output = output; |
| 5594 | wl_list_insert(output->head_list.prev, &head->output_link); |
| 5595 | |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 5596 | if (output->enabled) { |
| 5597 | weston_head_add_global(head); |
| 5598 | |
| 5599 | head_names = weston_output_create_heads_string(output); |
| 5600 | weston_log("Output '%s' updated to have head(s) %s\n", |
| 5601 | output->name, head_names); |
| 5602 | free(head_names); |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 5603 | |
| 5604 | weston_output_emit_heads_changed(output); |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 5605 | } |
| 5606 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5607 | return 0; |
| 5608 | } |
| 5609 | |
| 5610 | /** Detach a head from its output |
| 5611 | * |
| 5612 | * \param head The head to detach. |
| 5613 | * |
| 5614 | * It is safe to detach a non-attached head. |
| 5615 | * |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5616 | * If the head is attached to an enabled output and the output will be left |
| 5617 | * with no heads, the output will be disabled. |
| 5618 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5619 | * \ingroup head |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5620 | * \sa weston_output_disable |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5621 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5622 | WL_EXPORT void |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5623 | weston_head_detach(struct weston_head *head) |
| 5624 | { |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5625 | struct weston_output *output = head->output; |
Pekka Paalanen | a010699 | 2017-12-08 16:11:17 +0200 | [diff] [blame] | 5626 | char *head_names; |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5627 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5628 | wl_list_remove(&head->output_link); |
| 5629 | wl_list_init(&head->output_link); |
| 5630 | head->output = NULL; |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5631 | |
| 5632 | if (!output) |
| 5633 | return; |
| 5634 | |
| 5635 | if (output->detach_head) |
| 5636 | output->detach_head(output, head); |
| 5637 | |
| 5638 | if (output->enabled) { |
| 5639 | weston_head_remove_global(head); |
| 5640 | |
Pekka Paalanen | a010699 | 2017-12-08 16:11:17 +0200 | [diff] [blame] | 5641 | if (wl_list_empty(&output->head_list)) { |
| 5642 | weston_log("Output '%s' no heads left, disabling.\n", |
| 5643 | output->name); |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5644 | weston_output_disable(output); |
Pekka Paalanen | a010699 | 2017-12-08 16:11:17 +0200 | [diff] [blame] | 5645 | } else { |
| 5646 | head_names = weston_output_create_heads_string(output); |
| 5647 | weston_log("Output '%s' updated to have head(s) %s\n", |
| 5648 | output->name, head_names); |
| 5649 | free(head_names); |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 5650 | |
| 5651 | weston_output_emit_heads_changed(output); |
Pekka Paalanen | a010699 | 2017-12-08 16:11:17 +0200 | [diff] [blame] | 5652 | } |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5653 | } |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5654 | } |
| 5655 | |
| 5656 | /** Destroy a head |
| 5657 | * |
| 5658 | * \param head The head to be released. |
| 5659 | * |
| 5660 | * Destroys the head. The caller is responsible for freeing the memory pointed |
| 5661 | * to by \c head. |
| 5662 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5663 | * \ingroup head |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5664 | * \internal |
| 5665 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5666 | WL_EXPORT void |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5667 | weston_head_release(struct weston_head *head) |
| 5668 | { |
Marius Vlad | f2452d6 | 2021-12-09 14:07:21 +0200 | [diff] [blame] | 5669 | weston_signal_emit_mutable(&head->destroy_signal, head); |
Pekka Paalanen | 2e1bedb | 2017-10-10 11:21:58 +0300 | [diff] [blame] | 5670 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5671 | weston_head_detach(head); |
Pekka Paalanen | 06f99ef | 2017-04-04 16:26:23 +0300 | [diff] [blame] | 5672 | |
| 5673 | free(head->make); |
| 5674 | free(head->model); |
| 5675 | free(head->serial_number); |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 5676 | free(head->name); |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 5677 | |
| 5678 | wl_list_remove(&head->compositor_link); |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5679 | } |
| 5680 | |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5681 | static void |
| 5682 | weston_head_set_device_changed(struct weston_head *head) |
| 5683 | { |
| 5684 | head->device_changed = true; |
| 5685 | |
| 5686 | if (head->compositor) |
| 5687 | weston_compositor_schedule_heads_changed(head->compositor); |
| 5688 | } |
| 5689 | |
| 5690 | /** String equal comparison with NULLs being equal */ |
| 5691 | static bool |
| 5692 | str_null_eq(const char *a, const char *b) |
| 5693 | { |
| 5694 | if (!a && !b) |
| 5695 | return true; |
| 5696 | |
| 5697 | if (!!a != !!b) |
| 5698 | return false; |
| 5699 | |
| 5700 | return strcmp(a, b) == 0; |
| 5701 | } |
| 5702 | |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5703 | /** Store monitor make, model and serial number |
| 5704 | * |
| 5705 | * \param head The head to modify. |
| 5706 | * \param make The monitor make. If EDID is available, the PNP ID. Otherwise |
| 5707 | * any string, or NULL for none. |
| 5708 | * \param model The monitor model or name, or a made-up string, or NULL for |
| 5709 | * none. |
| 5710 | * \param serialno The monitor serial number, a made-up string, or NULL for |
| 5711 | * none. |
| 5712 | * |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5713 | * This may set the device_changed flag. |
| 5714 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5715 | * \ingroup head |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5716 | * \internal |
| 5717 | */ |
| 5718 | WL_EXPORT void |
| 5719 | weston_head_set_monitor_strings(struct weston_head *head, |
| 5720 | const char *make, |
| 5721 | const char *model, |
| 5722 | const char *serialno) |
| 5723 | { |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5724 | if (str_null_eq(head->make, make) && |
| 5725 | str_null_eq(head->model, model) && |
| 5726 | str_null_eq(head->serial_number, serialno)) |
| 5727 | return; |
| 5728 | |
Pekka Paalanen | 06f99ef | 2017-04-04 16:26:23 +0300 | [diff] [blame] | 5729 | free(head->make); |
| 5730 | free(head->model); |
| 5731 | free(head->serial_number); |
| 5732 | |
| 5733 | head->make = make ? strdup(make) : NULL; |
| 5734 | head->model = model ? strdup(model) : NULL; |
| 5735 | head->serial_number = serialno ? strdup(serialno) : NULL; |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5736 | |
| 5737 | weston_head_set_device_changed(head); |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5738 | } |
| 5739 | |
Philipp Zabel | c18ffd3 | 2018-08-30 17:38:03 +0200 | [diff] [blame] | 5740 | /** Store display non-desktop status |
| 5741 | * |
| 5742 | * \param head The head to modify. |
| 5743 | * \param non_desktop Whether the head connects to a non-desktop display. |
| 5744 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5745 | * \ingroup head |
Philipp Zabel | c18ffd3 | 2018-08-30 17:38:03 +0200 | [diff] [blame] | 5746 | * \internal |
| 5747 | */ |
| 5748 | WL_EXPORT void |
| 5749 | weston_head_set_non_desktop(struct weston_head *head, bool non_desktop) |
| 5750 | { |
| 5751 | if (head->non_desktop == non_desktop) |
| 5752 | return; |
| 5753 | |
| 5754 | head->non_desktop = non_desktop; |
| 5755 | |
| 5756 | weston_head_set_device_changed(head); |
| 5757 | } |
| 5758 | |
Lucas Stach | a69cb71 | 2019-11-25 23:29:31 +0000 | [diff] [blame] | 5759 | /** Store display transformation |
| 5760 | * |
| 5761 | * \param head The head to modify. |
| 5762 | * \param transform The transformation to apply for this head |
| 5763 | * |
| 5764 | * This may set the device_changed flag. |
| 5765 | * |
| 5766 | * \ingroup head |
| 5767 | * \internal |
| 5768 | */ |
| 5769 | WL_EXPORT void |
| 5770 | weston_head_set_transform(struct weston_head *head, uint32_t transform) |
| 5771 | { |
| 5772 | if (head->transform == transform) |
| 5773 | return; |
| 5774 | |
| 5775 | head->transform = transform; |
| 5776 | |
| 5777 | weston_head_set_device_changed(head); |
| 5778 | } |
| 5779 | |
| 5780 | |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5781 | /** Store physical image size |
| 5782 | * |
| 5783 | * \param head The head to modify. |
| 5784 | * \param mm_width Image area width in millimeters. |
| 5785 | * \param mm_height Image area height in millimeters. |
| 5786 | * |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5787 | * This may set the device_changed flag. |
| 5788 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5789 | * \ingroup head |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5790 | * \internal |
| 5791 | */ |
| 5792 | WL_EXPORT void |
| 5793 | weston_head_set_physical_size(struct weston_head *head, |
| 5794 | int32_t mm_width, int32_t mm_height) |
| 5795 | { |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5796 | if (head->mm_width == mm_width && |
| 5797 | head->mm_height == mm_height) |
| 5798 | return; |
| 5799 | |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5800 | head->mm_width = mm_width; |
| 5801 | head->mm_height = mm_height; |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5802 | |
| 5803 | weston_head_set_device_changed(head); |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5804 | } |
| 5805 | |
| 5806 | /** Store monitor sub-pixel layout |
| 5807 | * |
| 5808 | * \param head The head to modify. |
| 5809 | * \param sp Sub-pixel layout. The possible values are: |
| 5810 | * - WL_OUTPUT_SUBPIXEL_UNKNOWN, |
| 5811 | * - WL_OUTPUT_SUBPIXEL_NONE, |
| 5812 | * - WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB, |
| 5813 | * - WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR, |
| 5814 | * - WL_OUTPUT_SUBPIXEL_VERTICAL_RGB, |
| 5815 | * - WL_OUTPUT_SUBPIXEL_VERTICAL_BGR |
| 5816 | * |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5817 | * This may set the device_changed flag. |
| 5818 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5819 | * \ingroup head |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5820 | * \internal |
| 5821 | */ |
| 5822 | WL_EXPORT void |
| 5823 | weston_head_set_subpixel(struct weston_head *head, |
| 5824 | enum wl_output_subpixel sp) |
| 5825 | { |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5826 | if (head->subpixel == sp) |
| 5827 | return; |
| 5828 | |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5829 | head->subpixel = sp; |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5830 | |
| 5831 | weston_head_set_device_changed(head); |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5832 | } |
| 5833 | |
| 5834 | /** Mark the monitor as internal |
| 5835 | * |
| 5836 | * This is used for embedded screens, like laptop panels. |
| 5837 | * |
| 5838 | * \param head The head to mark as internal. |
| 5839 | * |
| 5840 | * By default a head is external. The type is often inferred from the physical |
| 5841 | * connector type. |
| 5842 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5843 | * \ingroup head |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5844 | * \internal |
| 5845 | */ |
| 5846 | WL_EXPORT void |
| 5847 | weston_head_set_internal(struct weston_head *head) |
| 5848 | { |
| 5849 | head->connection_internal = true; |
| 5850 | } |
Pekka Paalanen | 9ffb250 | 2017-03-27 15:14:32 +0300 | [diff] [blame] | 5851 | |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5852 | /** Store connector status |
| 5853 | * |
| 5854 | * \param head The head to modify. |
| 5855 | * \param connected Whether the head is connected. |
| 5856 | * |
| 5857 | * Connectors are created as disconnected. This function can be used to |
| 5858 | * set the connector status. |
| 5859 | * |
| 5860 | * The status should be set to true when a physical connector is connected to |
| 5861 | * a video sink device like a monitor and to false when the connector is |
| 5862 | * disconnected. For nested backends, the connection status should reflect the |
| 5863 | * connection to the parent display server. |
| 5864 | * |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5865 | * 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] | 5866 | * hook and sets the device_changed flag. |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5867 | * |
| 5868 | * \sa weston_compositor_set_heads_changed_cb |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5869 | * \ingroup head |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5870 | * \internal |
| 5871 | */ |
| 5872 | WL_EXPORT void |
| 5873 | weston_head_set_connection_status(struct weston_head *head, bool connected) |
| 5874 | { |
limin.tian | aaaff78 | 2024-12-20 09:49:25 +0000 | [diff] [blame] | 5875 | if (head->connected == connected && !head->need_change) |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5876 | return; |
| 5877 | |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5878 | head->connected = connected; |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5879 | |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5880 | weston_head_set_device_changed(head); |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5881 | } |
| 5882 | |
Ankit Nautiyal | 4f64ff8 | 2019-04-03 18:44:35 +0530 | [diff] [blame] | 5883 | static void |
| 5884 | weston_output_compute_protection(struct weston_output *output) |
| 5885 | { |
| 5886 | struct weston_head *head; |
| 5887 | enum weston_hdcp_protection op_protection; |
| 5888 | bool op_protection_valid = false; |
Ankit Nautiyal | f74c35b | 2019-04-03 19:21:58 +0530 | [diff] [blame] | 5889 | struct weston_compositor *wc = output->compositor; |
Ankit Nautiyal | 4f64ff8 | 2019-04-03 18:44:35 +0530 | [diff] [blame] | 5890 | |
| 5891 | wl_list_for_each(head, &output->head_list, output_link) { |
| 5892 | if (!op_protection_valid) { |
| 5893 | op_protection = head->current_protection; |
| 5894 | op_protection_valid = true; |
| 5895 | } |
| 5896 | if (head->current_protection < op_protection) |
| 5897 | op_protection = head->current_protection; |
| 5898 | } |
| 5899 | |
| 5900 | if (!op_protection_valid) |
| 5901 | op_protection = WESTON_HDCP_DISABLE; |
| 5902 | |
Ankit Nautiyal | f74c35b | 2019-04-03 19:21:58 +0530 | [diff] [blame] | 5903 | if (output->current_protection != op_protection) { |
Ankit Nautiyal | 4f64ff8 | 2019-04-03 18:44:35 +0530 | [diff] [blame] | 5904 | output->current_protection = op_protection; |
Ankit Nautiyal | f74c35b | 2019-04-03 19:21:58 +0530 | [diff] [blame] | 5905 | weston_output_damage(output); |
Ankit Nautiyal | faa5ab4 | 2019-07-08 13:23:24 +0530 | [diff] [blame] | 5906 | weston_schedule_surface_protection_update(wc); |
Ankit Nautiyal | f74c35b | 2019-04-03 19:21:58 +0530 | [diff] [blame] | 5907 | } |
Ankit Nautiyal | 4f64ff8 | 2019-04-03 18:44:35 +0530 | [diff] [blame] | 5908 | } |
| 5909 | |
| 5910 | WL_EXPORT void |
| 5911 | weston_head_set_content_protection_status(struct weston_head *head, |
| 5912 | enum weston_hdcp_protection status) |
| 5913 | { |
| 5914 | head->current_protection = status; |
| 5915 | if (head->output) |
| 5916 | weston_output_compute_protection(head->output); |
| 5917 | } |
| 5918 | |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5919 | /** Is the head currently connected? |
| 5920 | * |
| 5921 | * \param head The head to query. |
| 5922 | * \return Connection status. |
| 5923 | * |
| 5924 | * Returns true if the head is physically connected to a monitor, or in |
| 5925 | * case of a nested backend returns true when there is a connection to the |
| 5926 | * parent display server. |
| 5927 | * |
| 5928 | * This is independent from the head being enabled. |
| 5929 | * |
| 5930 | * \sa weston_head_is_enabled |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5931 | * \ingroup head |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5932 | */ |
| 5933 | WL_EXPORT bool |
| 5934 | weston_head_is_connected(struct weston_head *head) |
| 5935 | { |
| 5936 | return head->connected; |
| 5937 | } |
| 5938 | |
Pekka Paalanen | 8e552fd | 2018-02-15 15:18:20 +0200 | [diff] [blame] | 5939 | /** Is the head currently enabled? |
| 5940 | * |
| 5941 | * \param head The head to query. |
| 5942 | * \return Video status. |
| 5943 | * |
| 5944 | * Returns true if the head is currently transmitting a video stream. |
| 5945 | * |
| 5946 | * This is independent of the head being connected. |
| 5947 | * |
| 5948 | * \sa weston_head_is_connected |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5949 | * \ingroup head |
Pekka Paalanen | 8e552fd | 2018-02-15 15:18:20 +0200 | [diff] [blame] | 5950 | */ |
| 5951 | WL_EXPORT bool |
| 5952 | weston_head_is_enabled(struct weston_head *head) |
| 5953 | { |
| 5954 | if (!head->output) |
| 5955 | return false; |
| 5956 | |
| 5957 | return head->output->enabled; |
| 5958 | } |
| 5959 | |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5960 | /** Has the device information changed? |
| 5961 | * |
| 5962 | * \param head The head to query. |
| 5963 | * \return True if the device information has changed since last reset. |
| 5964 | * |
| 5965 | * The information about the connected display device, e.g. a monitor, may |
| 5966 | * change without being disconnected in between. Changing information |
| 5967 | * causes a call to the heads_changed hook. |
| 5968 | * |
| 5969 | * The information includes make, model, serial number, physical size, |
| 5970 | * and sub-pixel type. The connection status is also included. |
| 5971 | * |
| 5972 | * \sa weston_head_reset_device_changed, weston_compositor_set_heads_changed_cb |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5973 | * \ingroup head |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5974 | */ |
| 5975 | WL_EXPORT bool |
| 5976 | weston_head_is_device_changed(struct weston_head *head) |
| 5977 | { |
| 5978 | return head->device_changed; |
| 5979 | } |
| 5980 | |
Philipp Zabel | c18ffd3 | 2018-08-30 17:38:03 +0200 | [diff] [blame] | 5981 | /** Does the head represent a non-desktop display? |
| 5982 | * |
| 5983 | * \param head The head to query. |
| 5984 | * \return True if the device is a non-desktop display. |
| 5985 | * |
| 5986 | * Non-desktop heads are not attached to outputs by default. |
| 5987 | * This stops weston from extending the desktop onto head mounted displays. |
| 5988 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5989 | * \ingroup head |
Philipp Zabel | c18ffd3 | 2018-08-30 17:38:03 +0200 | [diff] [blame] | 5990 | */ |
| 5991 | WL_EXPORT bool |
| 5992 | weston_head_is_non_desktop(struct weston_head *head) |
| 5993 | { |
| 5994 | return head->non_desktop; |
| 5995 | } |
| 5996 | |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5997 | /** Acknowledge device information change |
| 5998 | * |
| 5999 | * \param head The head to acknowledge. |
| 6000 | * |
| 6001 | * Clears the device changed flag on this head. When a compositor has processed |
| 6002 | * device information, it should call this to be able to notice further |
| 6003 | * changes. |
| 6004 | * |
| 6005 | * \sa weston_head_is_device_changed |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 6006 | * \ingroup head |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 6007 | */ |
| 6008 | WL_EXPORT void |
| 6009 | weston_head_reset_device_changed(struct weston_head *head) |
| 6010 | { |
| 6011 | head->device_changed = false; |
| 6012 | } |
| 6013 | |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 6014 | /** Get the name of a head |
| 6015 | * |
| 6016 | * \param head The head to query. |
| 6017 | * \return The head's name, not NULL. |
| 6018 | * |
| 6019 | * The name depends on the backend. The DRM backend uses connector names, |
| 6020 | * other backends may use hardcoded names or user-given names. |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 6021 | * |
| 6022 | * \ingroup head |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 6023 | */ |
| 6024 | WL_EXPORT const char * |
| 6025 | weston_head_get_name(struct weston_head *head) |
| 6026 | { |
| 6027 | return head->name; |
| 6028 | } |
| 6029 | |
| 6030 | /** Get the output the head is attached to |
| 6031 | * |
| 6032 | * \param head The head to query. |
| 6033 | * \return The output the head is attached to, or NULL if detached. |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 6034 | * \ingroup head |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 6035 | */ |
| 6036 | WL_EXPORT struct weston_output * |
| 6037 | weston_head_get_output(struct weston_head *head) |
| 6038 | { |
| 6039 | return head->output; |
| 6040 | } |
| 6041 | |
Lucas Stach | a69cb71 | 2019-11-25 23:29:31 +0000 | [diff] [blame] | 6042 | /** Get the head's native transformation |
| 6043 | * |
| 6044 | * \param head The head to query. |
| 6045 | * \return The head's native transform, as a WL_OUTPUT_TRANSFORM_* value |
| 6046 | * |
| 6047 | * A weston_head may have a 'native' transform provided by the backend. |
| 6048 | * Examples include panels which are physically rotated, where the rotation |
| 6049 | * is recorded and described as part of the system configuration. This call |
| 6050 | * will return any known native transform for the head. |
| 6051 | * |
| 6052 | * \ingroup head |
| 6053 | */ |
| 6054 | WL_EXPORT uint32_t |
| 6055 | weston_head_get_transform(struct weston_head *head) |
| 6056 | { |
| 6057 | return head->transform; |
| 6058 | } |
| 6059 | |
Pekka Paalanen | 2e1bedb | 2017-10-10 11:21:58 +0300 | [diff] [blame] | 6060 | /** Add destroy callback for a head |
| 6061 | * |
| 6062 | * \param head The head to watch for. |
| 6063 | * \param listener The listener to add. The \c notify member must be set. |
| 6064 | * |
| 6065 | * Heads may get destroyed for various reasons by the backends. If a head is |
| 6066 | * attached to an output, the compositor should listen for head destruction |
| 6067 | * and reconfigure or destroy the output if necessary. |
| 6068 | * |
| 6069 | * The destroy callbacks will be called on weston_head destruction before any |
| 6070 | * automatic detaching from an associated weston_output and before any |
| 6071 | * weston_head information is lost. |
| 6072 | * |
| 6073 | * The \c data argument to the notify callback is the weston_head being |
| 6074 | * destroyed. |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 6075 | * |
| 6076 | * \ingroup head |
Pekka Paalanen | 2e1bedb | 2017-10-10 11:21:58 +0300 | [diff] [blame] | 6077 | */ |
| 6078 | WL_EXPORT void |
| 6079 | weston_head_add_destroy_listener(struct weston_head *head, |
| 6080 | struct wl_listener *listener) |
| 6081 | { |
| 6082 | wl_signal_add(&head->destroy_signal, listener); |
| 6083 | } |
| 6084 | |
| 6085 | /** Look up destroy listener for a head |
| 6086 | * |
| 6087 | * \param head The head to query. |
| 6088 | * \param notify The notify function used used for the added destroy listener. |
| 6089 | * \return The listener, or NULL if not found. |
| 6090 | * |
| 6091 | * This looks up the previously added destroy listener struct based on the |
| 6092 | * notify function it has. The listener can be used to access user data |
| 6093 | * through \c container_of(). |
| 6094 | * |
| 6095 | * \sa wl_signal_get() |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 6096 | * \ingroup head |
Pekka Paalanen | 2e1bedb | 2017-10-10 11:21:58 +0300 | [diff] [blame] | 6097 | */ |
| 6098 | WL_EXPORT struct wl_listener * |
| 6099 | weston_head_get_destroy_listener(struct weston_head *head, |
| 6100 | wl_notify_func_t notify) |
| 6101 | { |
| 6102 | return wl_signal_get(&head->destroy_signal, notify); |
| 6103 | } |
| 6104 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 6105 | /* 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] | 6106 | static void |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 6107 | weston_compositor_reflow_outputs(struct weston_compositor *compositor, |
| 6108 | struct weston_output *resized_output, int delta_width) |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 6109 | { |
| 6110 | struct weston_output *output; |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 6111 | bool start_resizing = false; |
| 6112 | |
| 6113 | if (!delta_width) |
| 6114 | return; |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 6115 | |
| 6116 | wl_list_for_each(output, &compositor->output_list, link) { |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 6117 | if (output == resized_output) { |
| 6118 | start_resizing = true; |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 6119 | continue; |
| 6120 | } |
| 6121 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 6122 | if (start_resizing) { |
| 6123 | weston_output_move(output, output->x + delta_width, output->y); |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 6124 | output->dirty = 1; |
| 6125 | } |
| 6126 | } |
| 6127 | } |
| 6128 | |
Pekka Paalanen | 0692079 | 2020-12-08 15:22:36 +0200 | [diff] [blame] | 6129 | /** Transform a region in-place from global to output coordinates |
| 6130 | * |
| 6131 | * \param output The output that defines the transformation. |
| 6132 | * \param region The region to be transformed in-place. |
| 6133 | * |
| 6134 | * This takes a region in the global coordinate system, and takes into account |
| 6135 | * output position, transform and scale, and the zoom, and converts the region |
| 6136 | * into output pixel coordinates in the framebuffer. |
| 6137 | * |
| 6138 | * Uses floating-point operations if zoom is active, which may round to expand |
| 6139 | * the region. |
| 6140 | * |
| 6141 | * \internal |
| 6142 | * \ingroup output |
| 6143 | */ |
| 6144 | WL_EXPORT void |
| 6145 | weston_output_region_from_global(struct weston_output *output, |
| 6146 | pixman_region32_t *region) |
| 6147 | { |
| 6148 | if (output->zoom.active) { |
| 6149 | weston_matrix_transform_region(region, &output->matrix, region); |
| 6150 | } else { |
| 6151 | pixman_region32_translate(region, -output->x, -output->y); |
| 6152 | weston_transformed_region(output->width, output->height, |
| 6153 | output->transform, |
| 6154 | output->current_scale, |
| 6155 | region, region); |
| 6156 | } |
| 6157 | } |
| 6158 | |
Pekka Paalanen | d72bad2 | 2017-03-29 17:01:41 +0300 | [diff] [blame] | 6159 | static void |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 6160 | weston_output_update_matrix(struct weston_output *output) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 6161 | { |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 6162 | float magnification; |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 6163 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 6164 | weston_matrix_init(&output->matrix); |
Jason Ekstrand | fb23df7 | 2014-10-16 10:55:21 -0500 | [diff] [blame] | 6165 | weston_matrix_translate(&output->matrix, -output->x, -output->y, 0); |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 6166 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 6167 | if (output->zoom.active) { |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 6168 | magnification = 1 / (1 - output->zoom.spring_z.current); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6169 | weston_output_update_zoom(output); |
Neil Roberts | 1e40a7e | 2014-04-25 13:19:37 +0100 | [diff] [blame] | 6170 | weston_matrix_translate(&output->matrix, -output->zoom.trans_x, |
Jason Ekstrand | fb23df7 | 2014-10-16 10:55:21 -0500 | [diff] [blame] | 6171 | -output->zoom.trans_y, 0); |
Neil Roberts | 1e40a7e | 2014-04-25 13:19:37 +0100 | [diff] [blame] | 6172 | weston_matrix_scale(&output->matrix, magnification, |
| 6173 | magnification, 1.0); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 6174 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 6175 | |
Jason Ekstrand | fb23df7 | 2014-10-16 10:55:21 -0500 | [diff] [blame] | 6176 | switch (output->transform) { |
| 6177 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 6178 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 6179 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 6180 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 6181 | weston_matrix_translate(&output->matrix, -output->width, 0, 0); |
| 6182 | weston_matrix_scale(&output->matrix, -1, 1, 1); |
| 6183 | break; |
| 6184 | } |
| 6185 | |
| 6186 | switch (output->transform) { |
| 6187 | default: |
| 6188 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 6189 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 6190 | break; |
| 6191 | case WL_OUTPUT_TRANSFORM_90: |
| 6192 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
Pekka Paalanen | 8060d82 | 2020-02-06 15:27:54 +0200 | [diff] [blame] | 6193 | weston_matrix_translate(&output->matrix, -output->width, 0, 0); |
| 6194 | weston_matrix_rotate_xy(&output->matrix, 0, -1); |
Jason Ekstrand | fb23df7 | 2014-10-16 10:55:21 -0500 | [diff] [blame] | 6195 | break; |
| 6196 | case WL_OUTPUT_TRANSFORM_180: |
| 6197 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 6198 | weston_matrix_translate(&output->matrix, |
| 6199 | -output->width, -output->height, 0); |
| 6200 | weston_matrix_rotate_xy(&output->matrix, -1, 0); |
| 6201 | break; |
| 6202 | case WL_OUTPUT_TRANSFORM_270: |
| 6203 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
Pekka Paalanen | 8060d82 | 2020-02-06 15:27:54 +0200 | [diff] [blame] | 6204 | weston_matrix_translate(&output->matrix, 0, -output->height, 0); |
| 6205 | weston_matrix_rotate_xy(&output->matrix, 0, 1); |
Jason Ekstrand | fb23df7 | 2014-10-16 10:55:21 -0500 | [diff] [blame] | 6206 | break; |
| 6207 | } |
| 6208 | |
| 6209 | if (output->current_scale != 1) |
| 6210 | weston_matrix_scale(&output->matrix, |
| 6211 | output->current_scale, |
| 6212 | output->current_scale, 1); |
Neil Roberts | 6c3b01f | 2014-05-06 19:04:15 +0100 | [diff] [blame] | 6213 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 6214 | output->dirty = 0; |
Derek Foreman | c002321 | 2015-03-24 11:36:13 -0500 | [diff] [blame] | 6215 | |
| 6216 | weston_matrix_invert(&output->inverse_matrix, &output->matrix); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 6217 | } |
| 6218 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 6219 | static void |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 6220 | 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] | 6221 | { |
| 6222 | output->transform = transform; |
Pekka Paalanen | 59987fa | 2016-04-26 15:50:59 +0300 | [diff] [blame] | 6223 | output->native_scale = scale; |
| 6224 | output->current_scale = scale; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 6225 | |
Pekka Paalanen | 59987fa | 2016-04-26 15:50:59 +0300 | [diff] [blame] | 6226 | convert_size_by_transform_scale(&output->width, &output->height, |
| 6227 | output->current_mode->width, |
| 6228 | output->current_mode->height, |
| 6229 | transform, scale); |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 6230 | } |
| 6231 | |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 6232 | static void |
| 6233 | weston_output_init_geometry(struct weston_output *output, int x, int y) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 6234 | { |
| 6235 | output->x = x; |
| 6236 | output->y = y; |
| 6237 | |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 6238 | pixman_region32_fini(&output->region); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 6239 | pixman_region32_init_rect(&output->region, x, y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 6240 | output->width, |
| 6241 | output->height); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 6242 | } |
| 6243 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6244 | /** |
| 6245 | * \ingroup output |
| 6246 | */ |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6247 | WL_EXPORT void |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 6248 | weston_output_move(struct weston_output *output, int x, int y) |
| 6249 | { |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 6250 | struct weston_head *head; |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 6251 | struct wl_resource *resource; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 6252 | int ver; |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 6253 | |
| 6254 | output->move_x = x - output->x; |
| 6255 | output->move_y = y - output->y; |
| 6256 | |
| 6257 | if (output->move_x == 0 && output->move_y == 0) |
| 6258 | return; |
| 6259 | |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 6260 | weston_output_init_geometry(output, x, y); |
| 6261 | |
| 6262 | output->dirty = 1; |
| 6263 | |
| 6264 | /* Move views on this output. */ |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6265 | wl_signal_emit(&output->compositor->output_moved_signal, output); |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 6266 | |
| 6267 | /* Notify clients of the change for output position. */ |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 6268 | wl_list_for_each(head, &output->head_list, output_link) { |
| 6269 | wl_resource_for_each(resource, &head->resource_list) { |
| 6270 | wl_output_send_geometry(resource, |
| 6271 | output->x, |
| 6272 | output->y, |
| 6273 | head->mm_width, |
| 6274 | head->mm_height, |
| 6275 | head->subpixel, |
| 6276 | head->make, |
| 6277 | head->model, |
| 6278 | output->transform); |
Quanxian Wang | b2c8636 | 2014-03-14 09:16:25 +0800 | [diff] [blame] | 6279 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 6280 | ver = wl_resource_get_version(resource); |
| 6281 | if (ver >= WL_OUTPUT_DONE_SINCE_VERSION) |
| 6282 | wl_output_send_done(resource); |
| 6283 | } |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 6284 | |
| 6285 | wl_resource_for_each(resource, &head->xdg_output_resource_list) { |
| 6286 | zxdg_output_v1_send_logical_position(resource, |
| 6287 | output->x, |
| 6288 | output->y); |
| 6289 | zxdg_output_v1_send_done(resource); |
| 6290 | } |
Quanxian Wang | b2c8636 | 2014-03-14 09:16:25 +0800 | [diff] [blame] | 6291 | } |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 6292 | } |
| 6293 | |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 6294 | /** Signal that a pending output is taken into use. |
| 6295 | * |
| 6296 | * Removes the output from the pending list and adds it to the compositor's |
| 6297 | * list of enabled outputs. The output created signal is emitted. |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 6298 | * |
Pekka Paalanen | 2210ad0 | 2017-03-30 15:48:06 +0300 | [diff] [blame] | 6299 | * The output gets an internal ID assigned, and the wl_output global is |
| 6300 | * created. |
Pekka Paalanen | 3d2d497 | 2017-03-30 15:19:45 +0300 | [diff] [blame] | 6301 | * |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 6302 | * \param compositor The compositor instance. |
| 6303 | * \param output The output to be added. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6304 | * |
| 6305 | * \internal |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 6306 | * \ingroup compositor |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 6307 | */ |
Pekka Paalanen | f9681b5 | 2017-03-29 16:58:48 +0300 | [diff] [blame] | 6308 | static void |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 6309 | weston_compositor_add_output(struct weston_compositor *compositor, |
| 6310 | struct weston_output *output) |
| 6311 | { |
Armin Krezović | e540384 | 2016-08-05 15:28:29 +0200 | [diff] [blame] | 6312 | struct weston_view *view, *next; |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 6313 | struct weston_head *head; |
Armin Krezović | e540384 | 2016-08-05 15:28:29 +0200 | [diff] [blame] | 6314 | |
Pekka Paalanen | 7f340ff | 2017-03-30 14:56:22 +0300 | [diff] [blame] | 6315 | assert(!output->enabled); |
Pekka Paalanen | 3d2d497 | 2017-03-30 15:19:45 +0300 | [diff] [blame] | 6316 | |
| 6317 | /* Verify we haven't reached the limit of 32 available output IDs */ |
| 6318 | assert(ffs(~compositor->output_id_pool) > 0); |
| 6319 | |
| 6320 | /* Invert the output id pool and look for the lowest numbered |
| 6321 | * switch (the least significant bit). Take that bit's position |
| 6322 | * as our ID, and mark it used in the compositor's output_id_pool. |
| 6323 | */ |
| 6324 | output->id = ffs(~compositor->output_id_pool) - 1; |
| 6325 | compositor->output_id_pool |= 1u << output->id; |
| 6326 | |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 6327 | wl_list_remove(&output->link); |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 6328 | wl_list_insert(compositor->output_list.prev, &output->link); |
Pekka Paalanen | 7f340ff | 2017-03-30 14:56:22 +0300 | [diff] [blame] | 6329 | output->enabled = true; |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 6330 | |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 6331 | wl_list_for_each(head, &output->head_list, output_link) |
| 6332 | weston_head_add_global(head); |
Pekka Paalanen | 2210ad0 | 2017-03-30 15:48:06 +0300 | [diff] [blame] | 6333 | |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 6334 | wl_signal_emit(&compositor->output_created_signal, output); |
Armin Krezović | e540384 | 2016-08-05 15:28:29 +0200 | [diff] [blame] | 6335 | |
Pekka Paalanen | 6551c09 | 2021-05-03 16:09:45 +0300 | [diff] [blame] | 6336 | /* |
| 6337 | * Use view_list, as paint nodes have not been created for this |
| 6338 | * output yet. Any existing view might touch this new output. |
| 6339 | */ |
Armin Krezović | e540384 | 2016-08-05 15:28:29 +0200 | [diff] [blame] | 6340 | wl_list_for_each_safe(view, next, &compositor->view_list, link) |
| 6341 | weston_view_geometry_dirty(view); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 6342 | } |
| 6343 | |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6344 | /** Transform device coordinates into global coordinates |
| 6345 | * |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 6346 | * \param output the weston_output object |
| 6347 | * \param[in] device_x X coordinate in device units. |
| 6348 | * \param[in] device_y Y coordinate in device units. |
| 6349 | * \param[out] x X coordinate in the global space. |
| 6350 | * \param[out] y Y coordinate in the global space. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6351 | * |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 6352 | * Transforms coordinates from the device coordinate space (physical pixel |
| 6353 | * units) to the global coordinate space (logical pixel units). This takes |
| 6354 | * into account output transform and scale. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6355 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6356 | * \ingroup output |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6357 | * \internal |
| 6358 | */ |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 6359 | WL_EXPORT void |
| 6360 | weston_output_transform_coordinate(struct weston_output *output, |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 6361 | double device_x, double device_y, |
| 6362 | double *x, double *y) |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 6363 | { |
Derek Foreman | 0f67941 | 2014-10-02 13:41:17 -0500 | [diff] [blame] | 6364 | struct weston_vector p = { { |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 6365 | device_x, |
| 6366 | device_y, |
Derek Foreman | 0f67941 | 2014-10-02 13:41:17 -0500 | [diff] [blame] | 6367 | 0.0, |
| 6368 | 1.0 } }; |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 6369 | |
Derek Foreman | 67a18b9 | 2015-03-24 11:36:14 -0500 | [diff] [blame] | 6370 | weston_matrix_transform(&output->inverse_matrix, &p); |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 6371 | |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 6372 | *x = p.f[0] / p.f[3]; |
| 6373 | *y = p.f[1] / p.f[3]; |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 6374 | } |
| 6375 | |
Pekka Paalanen | 1d2eee2 | 2021-02-25 12:03:28 +0200 | [diff] [blame] | 6376 | static void |
| 6377 | weston_output_reset_color_transforms(struct weston_output *output) |
| 6378 | { |
Pekka Paalanen | cda3951 | 2021-03-22 17:32:07 +0200 | [diff] [blame] | 6379 | weston_color_transform_unref(output->from_sRGB_to_output); |
| 6380 | output->from_sRGB_to_output = NULL; |
Pekka Paalanen | 8fb23ed | 2021-03-23 13:40:43 +0200 | [diff] [blame] | 6381 | weston_color_transform_unref(output->from_sRGB_to_blend); |
| 6382 | output->from_sRGB_to_blend = NULL; |
Pekka Paalanen | 1d2eee2 | 2021-02-25 12:03:28 +0200 | [diff] [blame] | 6383 | weston_color_transform_unref(output->from_blend_to_output); |
| 6384 | output->from_blend_to_output = NULL; |
| 6385 | } |
| 6386 | |
Pekka Paalanen | 9a0aa37 | 2021-06-08 13:38:35 +0300 | [diff] [blame] | 6387 | static bool |
| 6388 | weston_output_set_color_transforms(struct weston_output *output) |
| 6389 | { |
| 6390 | struct weston_color_manager *cm = output->compositor->color_manager; |
| 6391 | struct weston_color_transform *blend_to_output = NULL; |
| 6392 | struct weston_color_transform *sRGB_to_output = NULL; |
| 6393 | struct weston_color_transform *sRGB_to_blend = NULL; |
| 6394 | bool ok; |
| 6395 | |
| 6396 | ok = cm->get_output_color_transform(cm, output, &blend_to_output); |
| 6397 | ok = ok && cm->get_sRGB_to_output_color_transform(cm, output, |
| 6398 | &sRGB_to_output); |
| 6399 | ok = ok && cm->get_sRGB_to_blend_color_transform(cm, output, |
| 6400 | &sRGB_to_blend); |
| 6401 | if (!ok) { |
| 6402 | weston_log("Creating color transformation for output \"%s\" failed.\n", |
| 6403 | output->name); |
| 6404 | weston_color_transform_unref(blend_to_output); |
| 6405 | weston_color_transform_unref(sRGB_to_output); |
| 6406 | weston_color_transform_unref(sRGB_to_blend); |
| 6407 | |
| 6408 | return false; |
| 6409 | } |
| 6410 | |
| 6411 | weston_output_reset_color_transforms(output); |
| 6412 | output->from_blend_to_output = blend_to_output; |
| 6413 | output->from_blend_to_output_by_backend = false; |
| 6414 | output->from_sRGB_to_output = sRGB_to_output; |
| 6415 | output->from_sRGB_to_blend = sRGB_to_blend; |
| 6416 | |
Pekka Paalanen | 9a9e6ce | 2021-06-08 14:17:44 +0300 | [diff] [blame] | 6417 | weston_log("Output '%s' using color profile: %s\n", output->name, |
| 6418 | weston_color_profile_get_description(output->color_profile)); |
| 6419 | |
Pekka Paalanen | 9a0aa37 | 2021-06-08 13:38:35 +0300 | [diff] [blame] | 6420 | return true; |
| 6421 | } |
| 6422 | |
Pekka Paalanen | e6ac4fc | 2017-03-29 16:07:34 +0300 | [diff] [blame] | 6423 | /** Removes output from compositor's list of enabled outputs |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6424 | * |
| 6425 | * \param output The weston_output object that is being removed. |
| 6426 | * |
Pekka Paalanen | e6ac4fc | 2017-03-29 16:07:34 +0300 | [diff] [blame] | 6427 | * The following happens: |
| 6428 | * |
Pekka Paalanen | 1a4f87d | 2021-04-30 14:48:52 +0300 | [diff] [blame] | 6429 | * - Destroys all paint nodes related to the output. |
| 6430 | * |
Pekka Paalanen | e6ac4fc | 2017-03-29 16:07:34 +0300 | [diff] [blame] | 6431 | * - The output assignments of all views in the current scenegraph are |
| 6432 | * recomputed. |
| 6433 | * |
Pekka Paalanen | 1d2eee2 | 2021-02-25 12:03:28 +0200 | [diff] [blame] | 6434 | * - Destroys output's color transforms. |
| 6435 | * |
Pekka Paalanen | e6ac4fc | 2017-03-29 16:07:34 +0300 | [diff] [blame] | 6436 | * - Presentation feedback is discarded. |
| 6437 | * |
| 6438 | * - Compositor is notified that outputs were changed and |
| 6439 | * applies the necessary changes to re-layout outputs. |
| 6440 | * |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 6441 | * - The output is put back in the pending outputs list. |
| 6442 | * |
Pekka Paalanen | e6ac4fc | 2017-03-29 16:07:34 +0300 | [diff] [blame] | 6443 | * - Signal is emitted to notify all users of the weston_output |
| 6444 | * object that the output is being destroyed. |
| 6445 | * |
| 6446 | * - wl_output protocol objects referencing this weston_output |
Pekka Paalanen | 2210ad0 | 2017-03-30 15:48:06 +0300 | [diff] [blame] | 6447 | * are made inert, and the wl_output global is removed. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6448 | * |
Pekka Paalanen | 3d2d497 | 2017-03-30 15:19:45 +0300 | [diff] [blame] | 6449 | * - The output's internal ID is released. |
| 6450 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 6451 | * \ingroup compositor |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6452 | * \internal |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6453 | */ |
| 6454 | static void |
| 6455 | weston_compositor_remove_output(struct weston_output *output) |
| 6456 | { |
Pekka Paalanen | bccda71 | 2017-03-29 16:16:04 +0300 | [diff] [blame] | 6457 | struct weston_compositor *compositor = output->compositor; |
Pekka Paalanen | 1a4f87d | 2021-04-30 14:48:52 +0300 | [diff] [blame] | 6458 | struct weston_paint_node *pnode, *pntmp; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6459 | struct weston_view *view; |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 6460 | struct weston_head *head; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6461 | |
| 6462 | assert(output->destroying); |
Pekka Paalanen | 7f340ff | 2017-03-30 14:56:22 +0300 | [diff] [blame] | 6463 | assert(output->enabled); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6464 | |
Pekka Paalanen | 1a4f87d | 2021-04-30 14:48:52 +0300 | [diff] [blame] | 6465 | wl_list_for_each_safe(pnode, pntmp, |
| 6466 | &output->paint_node_list, output_link) { |
| 6467 | weston_paint_node_destroy(pnode); |
| 6468 | } |
Pekka Paalanen | 2fddc53 | 2021-04-30 17:41:29 +0300 | [diff] [blame] | 6469 | assert(wl_list_empty(&output->paint_node_z_order_list)); |
Pekka Paalanen | 1a4f87d | 2021-04-30 14:48:52 +0300 | [diff] [blame] | 6470 | |
Pekka Paalanen | 6551c09 | 2021-05-03 16:09:45 +0300 | [diff] [blame] | 6471 | /* |
| 6472 | * Use view_list in case the output did not go through repaint |
| 6473 | * after a view came on it, lacking a paint node. Just to be sure. |
| 6474 | */ |
Pekka Paalanen | bccda71 | 2017-03-29 16:16:04 +0300 | [diff] [blame] | 6475 | wl_list_for_each(view, &compositor->view_list, link) { |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6476 | if (view->output_mask & (1u << output->id)) |
| 6477 | weston_view_assign_output(view); |
| 6478 | } |
| 6479 | |
Pekka Paalanen | 1d2eee2 | 2021-02-25 12:03:28 +0200 | [diff] [blame] | 6480 | weston_output_reset_color_transforms(output); |
| 6481 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6482 | weston_presentation_feedback_discard_list(&output->feedback_list); |
| 6483 | |
Pekka Paalanen | 9711fd9 | 2018-06-21 14:26:18 +0300 | [diff] [blame] | 6484 | weston_compositor_reflow_outputs(compositor, output, -output->width); |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 6485 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6486 | wl_list_remove(&output->link); |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 6487 | wl_list_insert(compositor->pending_output_list.prev, &output->link); |
Pekka Paalanen | 7f340ff | 2017-03-30 14:56:22 +0300 | [diff] [blame] | 6488 | output->enabled = false; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6489 | |
Marius Vlad | 2015dfc | 2021-12-02 11:15:15 +0200 | [diff] [blame] | 6490 | weston_signal_emit_mutable(&compositor->output_destroyed_signal, output); |
| 6491 | weston_signal_emit_mutable(&output->destroy_signal, output); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6492 | |
Pekka Paalanen | d9dcc6d | 2017-12-04 15:28:13 +0200 | [diff] [blame] | 6493 | wl_list_for_each(head, &output->head_list, output_link) |
| 6494 | weston_head_remove_global(head); |
Pekka Paalanen | 3d2d497 | 2017-03-30 15:19:45 +0300 | [diff] [blame] | 6495 | |
| 6496 | compositor->output_id_pool &= ~(1u << output->id); |
| 6497 | output->id = 0xffffffff; /* invalid */ |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6498 | } |
| 6499 | |
| 6500 | /** Sets the output scale for a given output. |
| 6501 | * |
| 6502 | * \param output The weston_output object that the scale is set for. |
| 6503 | * \param scale Scale factor for the given output. |
| 6504 | * |
| 6505 | * It only supports setting scale for an output that |
| 6506 | * is not enabled and it can only be ran once. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6507 | * |
Maxime Roussin-Bélanger | 1d009c2 | 2020-12-17 17:10:13 -0500 | [diff] [blame] | 6508 | * \ingroup output |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6509 | */ |
| 6510 | WL_EXPORT void |
| 6511 | weston_output_set_scale(struct weston_output *output, |
| 6512 | int32_t scale) |
| 6513 | { |
| 6514 | /* We can only set scale on a disabled output */ |
| 6515 | assert(!output->enabled); |
| 6516 | |
| 6517 | /* We only want to set scale once */ |
| 6518 | assert(!output->scale); |
| 6519 | |
| 6520 | output->scale = scale; |
| 6521 | } |
| 6522 | |
| 6523 | /** Sets the output transform for a given output. |
| 6524 | * |
| 6525 | * \param output The weston_output object that the transform is set for. |
| 6526 | * \param transform Transform value for the given output. |
| 6527 | * |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6528 | * Refer to wl_output::transform section located at |
| 6529 | * https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_output |
| 6530 | * for list of values that can be passed to this function. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6531 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6532 | * \ingroup output |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6533 | */ |
| 6534 | WL_EXPORT void |
| 6535 | weston_output_set_transform(struct weston_output *output, |
| 6536 | uint32_t transform) |
| 6537 | { |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 6538 | struct weston_pointer_motion_event ev; |
| 6539 | struct wl_resource *resource; |
| 6540 | struct weston_seat *seat; |
| 6541 | pixman_region32_t old_region; |
| 6542 | int mid_x, mid_y; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 6543 | struct weston_head *head; |
| 6544 | int ver; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6545 | |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 6546 | if (!output->enabled && output->transform == UINT32_MAX) { |
| 6547 | output->transform = transform; |
| 6548 | return; |
| 6549 | } |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6550 | |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 6551 | weston_output_transform_scale_init(output, transform, output->scale); |
| 6552 | |
| 6553 | pixman_region32_init(&old_region); |
| 6554 | pixman_region32_copy(&old_region, &output->region); |
| 6555 | |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 6556 | weston_output_init_geometry(output, output->x, output->y); |
| 6557 | |
| 6558 | output->dirty = 1; |
| 6559 | |
| 6560 | /* Notify clients of the change for output transform. */ |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 6561 | wl_list_for_each(head, &output->head_list, output_link) { |
| 6562 | wl_resource_for_each(resource, &head->resource_list) { |
| 6563 | wl_output_send_geometry(resource, |
| 6564 | output->x, |
| 6565 | output->y, |
| 6566 | head->mm_width, |
| 6567 | head->mm_height, |
| 6568 | head->subpixel, |
| 6569 | head->make, |
| 6570 | head->model, |
| 6571 | output->transform); |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 6572 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 6573 | ver = wl_resource_get_version(resource); |
| 6574 | if (ver >= WL_OUTPUT_DONE_SINCE_VERSION) |
| 6575 | wl_output_send_done(resource); |
| 6576 | } |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 6577 | wl_resource_for_each(resource, &head->xdg_output_resource_list) { |
| 6578 | zxdg_output_v1_send_logical_position(resource, |
| 6579 | output->x, |
| 6580 | output->y); |
| 6581 | zxdg_output_v1_send_logical_size(resource, |
| 6582 | output->width, |
| 6583 | output->height); |
| 6584 | zxdg_output_v1_send_done(resource); |
| 6585 | } |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 6586 | } |
| 6587 | |
| 6588 | /* we must ensure that pointers are inside output, otherwise they disappear */ |
| 6589 | mid_x = output->x + output->width / 2; |
| 6590 | mid_y = output->y + output->height / 2; |
| 6591 | |
| 6592 | ev.mask = WESTON_POINTER_MOTION_ABS; |
| 6593 | ev.x = wl_fixed_to_double(wl_fixed_from_int(mid_x)); |
| 6594 | ev.y = wl_fixed_to_double(wl_fixed_from_int(mid_y)); |
| 6595 | |
| 6596 | wl_list_for_each(seat, &output->compositor->seat_list, link) { |
| 6597 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 6598 | |
| 6599 | if (pointer && pixman_region32_contains_point(&old_region, |
| 6600 | wl_fixed_to_int(pointer->x), |
| 6601 | wl_fixed_to_int(pointer->y), |
| 6602 | NULL)) |
| 6603 | weston_pointer_move(pointer, &ev); |
| 6604 | } |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6605 | } |
| 6606 | |
Pekka Paalanen | 9a9e6ce | 2021-06-08 14:17:44 +0300 | [diff] [blame] | 6607 | /** Set output's color profile |
| 6608 | * |
| 6609 | * \param output The output to change. |
| 6610 | * \param cprof The color profile to set. Can be NULL for default sRGB profile. |
| 6611 | * \return True on success, or false on failure. |
| 6612 | * |
| 6613 | * Calling this function changes the color profile of the output. This causes |
| 6614 | * all existing weston_color_transform objects related to this output via |
| 6615 | * paint nodes to be unreferenced and later re-created on demand. |
| 6616 | * |
| 6617 | * This function may not be called from within weston_output_repaint(). |
| 6618 | * |
| 6619 | * On failure, nothing is changed. |
| 6620 | * |
| 6621 | * \ingroup output |
| 6622 | */ |
| 6623 | WL_EXPORT bool |
| 6624 | weston_output_set_color_profile(struct weston_output *output, |
| 6625 | struct weston_color_profile *cprof) |
| 6626 | { |
| 6627 | struct weston_color_profile *old; |
| 6628 | struct weston_paint_node *pnode; |
| 6629 | |
| 6630 | old = output->color_profile; |
| 6631 | output->color_profile = weston_color_profile_ref(cprof); |
| 6632 | |
| 6633 | if (output->enabled) { |
| 6634 | if (!weston_output_set_color_transforms(output)) { |
| 6635 | /* Failed, roll back */ |
| 6636 | weston_color_profile_unref(output->color_profile); |
| 6637 | output->color_profile = old; |
| 6638 | return false; |
| 6639 | } |
| 6640 | |
| 6641 | /* Remove outdated cached color transformations */ |
| 6642 | wl_list_for_each(pnode, &output->paint_node_list, output_link) { |
| 6643 | weston_surface_color_transform_fini(&pnode->surf_xform); |
| 6644 | pnode->surf_xform_valid = false; |
| 6645 | } |
| 6646 | } |
| 6647 | |
| 6648 | weston_color_profile_unref(old); |
| 6649 | |
| 6650 | return true; |
| 6651 | } |
| 6652 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6653 | /** Initializes a weston_output object with enough data so |
| 6654 | ** an output can be configured. |
| 6655 | * |
| 6656 | * \param output The weston_output object to initialize |
| 6657 | * \param compositor The compositor instance. |
Pekka Paalanen | 26ac2e1 | 2017-04-03 13:18:13 +0300 | [diff] [blame] | 6658 | * \param name Name for the output (the string is copied). |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6659 | * |
| 6660 | * Sets initial values for fields that are expected to be |
| 6661 | * configured either by compositors or backends. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6662 | * |
Pekka Paalanen | 26ac2e1 | 2017-04-03 13:18:13 +0300 | [diff] [blame] | 6663 | * The name is used in logs, and can be used by compositors as a configuration |
| 6664 | * identifier. |
| 6665 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6666 | * \ingroup output |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6667 | * \internal |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6668 | */ |
| 6669 | WL_EXPORT void |
Armin Krezović | 4008740 | 2016-09-30 14:11:12 +0200 | [diff] [blame] | 6670 | weston_output_init(struct weston_output *output, |
Pekka Paalanen | 26ac2e1 | 2017-04-03 13:18:13 +0300 | [diff] [blame] | 6671 | struct weston_compositor *compositor, |
| 6672 | const char *name) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6673 | { |
| 6674 | output->compositor = compositor; |
| 6675 | output->destroying = 0; |
Pekka Paalanen | 26ac2e1 | 2017-04-03 13:18:13 +0300 | [diff] [blame] | 6676 | output->name = strdup(name); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6677 | wl_list_init(&output->link); |
Pekka Paalanen | 37b7c6e | 2017-11-07 10:15:01 +0200 | [diff] [blame] | 6678 | wl_signal_init(&output->user_destroy_signal); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6679 | output->enabled = false; |
Ankit Nautiyal | 2690a77 | 2019-03-25 17:57:59 +0530 | [diff] [blame] | 6680 | output->desired_protection = WESTON_HDCP_DISABLE; |
Ankit Nautiyal | 2844f8e | 2019-04-03 10:14:59 +0530 | [diff] [blame] | 6681 | output->allow_protection = true; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6682 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 6683 | wl_list_init(&output->head_list); |
| 6684 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6685 | /* Add some (in)sane defaults which can be used |
| 6686 | * for checking if an output was properly configured |
| 6687 | */ |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6688 | output->scale = 0; |
| 6689 | /* Can't use -1 on uint32_t and 0 is valid enum value */ |
| 6690 | output->transform = UINT32_MAX; |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 6691 | |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 6692 | pixman_region32_init(&output->region); |
Pekka Paalanen | 4270414 | 2017-09-06 16:47:52 +0300 | [diff] [blame] | 6693 | wl_list_init(&output->mode_list); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6694 | } |
| 6695 | |
| 6696 | /** Adds weston_output object to pending output list. |
| 6697 | * |
| 6698 | * \param output The weston_output object to add |
| 6699 | * \param compositor The compositor instance. |
| 6700 | * |
Pekka Paalanen | ae6d35d | 2017-08-16 12:07:14 +0300 | [diff] [blame] | 6701 | * The opposite of this operation is built into weston_output_release(). |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6702 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 6703 | * \ingroup compositor |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6704 | * \internal |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6705 | */ |
| 6706 | WL_EXPORT void |
| 6707 | weston_compositor_add_pending_output(struct weston_output *output, |
| 6708 | struct weston_compositor *compositor) |
| 6709 | { |
Pekka Paalanen | e952a01 | 2017-03-29 17:14:00 +0300 | [diff] [blame] | 6710 | assert(output->disable); |
| 6711 | assert(output->enable); |
| 6712 | |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 6713 | wl_list_remove(&output->link); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6714 | wl_list_insert(compositor->pending_output_list.prev, &output->link); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6715 | } |
| 6716 | |
Pekka Paalanen | 3e8f201 | 2017-11-02 14:03:11 +0200 | [diff] [blame] | 6717 | /** Create a string with the attached heads' names. |
| 6718 | * |
| 6719 | * The string must be free()'d. |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6720 | * |
| 6721 | * \ingroup output |
Pekka Paalanen | 3e8f201 | 2017-11-02 14:03:11 +0200 | [diff] [blame] | 6722 | */ |
| 6723 | static char * |
| 6724 | weston_output_create_heads_string(struct weston_output *output) |
| 6725 | { |
| 6726 | FILE *fp; |
| 6727 | char *str = NULL; |
| 6728 | size_t size = 0; |
| 6729 | struct weston_head *head; |
| 6730 | const char *sep = ""; |
| 6731 | |
| 6732 | fp = open_memstream(&str, &size); |
| 6733 | if (!fp) |
| 6734 | return NULL; |
| 6735 | |
| 6736 | wl_list_for_each(head, &output->head_list, output_link) { |
| 6737 | fprintf(fp, "%s%s", sep, head->name); |
| 6738 | sep = ", "; |
| 6739 | } |
| 6740 | fclose(fp); |
| 6741 | |
| 6742 | return str; |
| 6743 | } |
| 6744 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6745 | /** Constructs a weston_output object that can be used by the compositor. |
| 6746 | * |
Pekka Paalanen | cc201e4 | 2017-03-30 15:11:25 +0300 | [diff] [blame] | 6747 | * \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] | 6748 | * be enabled already. Must have at least one head attached. |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6749 | * |
| 6750 | * Output coordinates are calculated and each new output is by default |
| 6751 | * assigned to the right of previous one. |
| 6752 | * |
| 6753 | * Sets up the transformation, zoom, and geometry of the output using |
| 6754 | * the properties that need to be configured by the compositor. |
| 6755 | * |
| 6756 | * Establishes a repaint timer for the output with the relevant display |
| 6757 | * object's event loop. See output_repaint_timer_handler(). |
| 6758 | * |
| 6759 | * The output is assigned an ID. Weston can support up to 32 distinct |
| 6760 | * outputs, with IDs numbered from 0-31; the compositor's output_id_pool |
| 6761 | * is referred to and used to find the first available ID number, and |
| 6762 | * then this ID is marked as used in output_id_pool. |
| 6763 | * |
| 6764 | * The output is also assigned a Wayland global with the wl_output |
| 6765 | * external interface. |
| 6766 | * |
| 6767 | * Backend specific function is called to set up the output output. |
| 6768 | * |
| 6769 | * Output is added to the compositor's output list |
| 6770 | * |
| 6771 | * If the backend specific function fails, the weston_output object |
| 6772 | * is returned to a state it was before calling this function and |
| 6773 | * is added to the compositor's pending_output_list in case it needs |
| 6774 | * to be reconfigured or just so it can be destroyed at shutdown. |
| 6775 | * |
| 6776 | * 0 is returned on success, -1 on failure. |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6777 | * |
| 6778 | * \ingroup output |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6779 | */ |
| 6780 | WL_EXPORT int |
| 6781 | weston_output_enable(struct weston_output *output) |
| 6782 | { |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 6783 | struct weston_compositor *c = output->compositor; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6784 | struct weston_output *iterator; |
Pekka Paalanen | ec25b0a | 2017-08-24 16:08:49 +0300 | [diff] [blame] | 6785 | struct weston_head *head; |
Pekka Paalanen | 3e8f201 | 2017-11-02 14:03:11 +0200 | [diff] [blame] | 6786 | char *head_names; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6787 | int x = 0, y = 0; |
| 6788 | |
Pekka Paalanen | cc201e4 | 2017-03-30 15:11:25 +0300 | [diff] [blame] | 6789 | if (output->enabled) { |
| 6790 | weston_log("Error: attempt to enable an enabled output '%s'\n", |
| 6791 | output->name); |
| 6792 | return -1; |
| 6793 | } |
| 6794 | |
Pekka Paalanen | ddce54d | 2017-08-23 16:00:21 +0300 | [diff] [blame] | 6795 | if (wl_list_empty(&output->head_list)) { |
| 6796 | weston_log("Error: cannot enable output '%s' without heads.\n", |
| 6797 | output->name); |
| 6798 | return -1; |
| 6799 | } |
| 6800 | |
Pekka Paalanen | 586e1ac | 2017-09-14 16:17:59 +0300 | [diff] [blame] | 6801 | if (wl_list_empty(&output->mode_list) || !output->current_mode) { |
| 6802 | weston_log("Error: no video mode for output '%s'.\n", |
| 6803 | output->name); |
| 6804 | return -1; |
| 6805 | } |
| 6806 | |
Pekka Paalanen | ec25b0a | 2017-08-24 16:08:49 +0300 | [diff] [blame] | 6807 | wl_list_for_each(head, &output->head_list, output_link) { |
| 6808 | assert(head->make); |
| 6809 | assert(head->model); |
| 6810 | } |
| 6811 | |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 6812 | iterator = container_of(c->output_list.prev, |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6813 | struct weston_output, link); |
| 6814 | |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 6815 | if (!wl_list_empty(&c->output_list)) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6816 | x = iterator->x + iterator->width; |
| 6817 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6818 | /* Make sure the scale is set up */ |
| 6819 | assert(output->scale); |
| 6820 | |
| 6821 | /* Make sure we have a transform set */ |
| 6822 | assert(output->transform != UINT32_MAX); |
| 6823 | |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 6824 | output->x = x; |
| 6825 | output->y = y; |
| 6826 | output->dirty = 1; |
| 6827 | output->original_scale = output->scale; |
| 6828 | |
Marius Vlad | 3a2f829 | 2019-11-04 17:53:46 +0200 | [diff] [blame] | 6829 | wl_signal_init(&output->frame_signal); |
| 6830 | wl_signal_init(&output->destroy_signal); |
| 6831 | |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 6832 | weston_output_transform_scale_init(output, output->transform, output->scale); |
| 6833 | weston_output_init_zoom(output); |
| 6834 | |
| 6835 | weston_output_init_geometry(output, x, y); |
| 6836 | weston_output_damage(output); |
| 6837 | |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 6838 | wl_list_init(&output->animation_list); |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 6839 | wl_list_init(&output->feedback_list); |
Pekka Paalanen | 1a4f87d | 2021-04-30 14:48:52 +0300 | [diff] [blame] | 6840 | wl_list_init(&output->paint_node_list); |
Pekka Paalanen | 2fddc53 | 2021-04-30 17:41:29 +0300 | [diff] [blame] | 6841 | wl_list_init(&output->paint_node_z_order_list); |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 6842 | |
Pekka Paalanen | 9a0aa37 | 2021-06-08 13:38:35 +0300 | [diff] [blame] | 6843 | if (!weston_output_set_color_transforms(output)) |
Pekka Paalanen | 1d2eee2 | 2021-02-25 12:03:28 +0200 | [diff] [blame] | 6844 | return -1; |
Pekka Paalanen | 1d2eee2 | 2021-02-25 12:03:28 +0200 | [diff] [blame] | 6845 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6846 | /* Enable the output (set up the crtc or create a |
| 6847 | * window representing the output, set up the |
| 6848 | * renderer, etc) |
| 6849 | */ |
| 6850 | if (output->enable(output) < 0) { |
| 6851 | weston_log("Enabling output \"%s\" failed.\n", output->name); |
Pekka Paalanen | 1d2eee2 | 2021-02-25 12:03:28 +0200 | [diff] [blame] | 6852 | weston_output_reset_color_transforms(output); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6853 | return -1; |
| 6854 | } |
| 6855 | |
| 6856 | weston_compositor_add_output(output->compositor, output); |
| 6857 | |
Pekka Paalanen | 3e8f201 | 2017-11-02 14:03:11 +0200 | [diff] [blame] | 6858 | head_names = weston_output_create_heads_string(output); |
| 6859 | weston_log("Output '%s' enabled with head(s) %s\n", |
| 6860 | output->name, head_names); |
| 6861 | free(head_names); |
| 6862 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6863 | return 0; |
| 6864 | } |
| 6865 | |
| 6866 | /** Converts a weston_output object to a pending output state, so it |
| 6867 | ** can be configured again or destroyed. |
| 6868 | * |
| 6869 | * \param output The weston_output object that needs to be disabled. |
| 6870 | * |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6871 | * Calls a backend specific function to disable an output, in case |
| 6872 | * such function exists. |
| 6873 | * |
Pekka Paalanen | c65df64 | 2017-03-29 15:45:46 +0300 | [diff] [blame] | 6874 | * The backend specific disable function may choose to postpone the disabling |
| 6875 | * by returning a negative value, in which case this function returns early. |
| 6876 | * In that case the backend will guarantee the output will be disabled soon |
| 6877 | * by the backend calling this function again. One must not attempt to re-enable |
| 6878 | * the output until that happens. |
| 6879 | * |
| 6880 | * 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] | 6881 | * from weston's output_list (see weston_compositor_remove_output()) |
| 6882 | * and is returned to a state it was before weston_output_enable() |
| 6883 | * was ran (see weston_output_enable_undo()). |
| 6884 | * |
Pekka Paalanen | c65df64 | 2017-03-29 15:45:46 +0300 | [diff] [blame] | 6885 | * See weston_output_init() for more information on the |
| 6886 | * state output is returned to. |
Pekka Paalanen | cc201e4 | 2017-03-30 15:11:25 +0300 | [diff] [blame] | 6887 | * |
| 6888 | * If the output has never been enabled yet, this function can still be |
| 6889 | * called to ensure that the output is actually turned off rather than left |
| 6890 | * in the state it was discovered in. |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6891 | * |
| 6892 | * \ingroup output |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6893 | */ |
| 6894 | WL_EXPORT void |
| 6895 | weston_output_disable(struct weston_output *output) |
| 6896 | { |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6897 | /* Should we rename this? */ |
| 6898 | output->destroying = 1; |
| 6899 | |
Pekka Paalanen | c65df64 | 2017-03-29 15:45:46 +0300 | [diff] [blame] | 6900 | /* Disable is called unconditionally also for not-enabled outputs, |
| 6901 | * because at compositor start-up, if there is an output that is |
| 6902 | * already on but the compositor wants to turn it off, we have to |
| 6903 | * forward the turn-off to the backend so it knows to do it. |
| 6904 | * The backend cannot initially turn off everything, because it |
| 6905 | * would cause unnecessary mode-sets for all outputs the compositor |
| 6906 | * wants to be on. |
| 6907 | */ |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6908 | if (output->disable(output) < 0) |
| 6909 | return; |
| 6910 | |
Pekka Paalanen | 2ec15eb | 2021-06-09 16:14:45 +0300 | [diff] [blame] | 6911 | if (output->enabled) { |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6912 | weston_compositor_remove_output(output); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6913 | |
Pekka Paalanen | 2ec15eb | 2021-06-09 16:14:45 +0300 | [diff] [blame] | 6914 | assert(wl_list_empty(&output->paint_node_list)); |
| 6915 | } |
| 6916 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6917 | output->destroying = 0; |
| 6918 | } |
| 6919 | |
Pekka Paalanen | 8a8dcac | 2017-08-17 17:29:36 +0300 | [diff] [blame] | 6920 | /** Forces a synchronous call to heads_changed hook |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6921 | * |
| 6922 | * \param compositor The compositor instance |
Pekka Paalanen | 8a8dcac | 2017-08-17 17:29:36 +0300 | [diff] [blame] | 6923 | * |
| 6924 | * If there are new or changed heads, calls the heads_changed hook and |
| 6925 | * returns after the hook returns. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 6926 | * |
| 6927 | * \ingroup compositor |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6928 | */ |
| 6929 | WL_EXPORT void |
Pekka Paalanen | 8a8dcac | 2017-08-17 17:29:36 +0300 | [diff] [blame] | 6930 | weston_compositor_flush_heads_changed(struct weston_compositor *compositor) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6931 | { |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 6932 | if (compositor->heads_changed_source) { |
| 6933 | wl_event_source_remove(compositor->heads_changed_source); |
| 6934 | weston_compositor_call_heads_changed(compositor); |
| 6935 | } |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6936 | } |
| 6937 | |
Pekka Paalanen | 37b7c6e | 2017-11-07 10:15:01 +0200 | [diff] [blame] | 6938 | /** Add destroy callback for an output |
| 6939 | * |
| 6940 | * \param output The output to watch. |
| 6941 | * \param listener The listener to add. The \c notify member must be set. |
| 6942 | * |
| 6943 | * The listener callback will be called when user destroys an output. This |
| 6944 | * may be delayed by a backend in some cases. The main purpose of the |
| 6945 | * listener is to allow hooking up custom data to the output. The custom data |
| 6946 | * can be fetched via weston_output_get_destroy_listener() followed by |
| 6947 | * container_of(). |
| 6948 | * |
| 6949 | * The \c data argument to the notify callback is the weston_output being |
| 6950 | * destroyed. |
| 6951 | * |
| 6952 | * @note This is for the final destruction of an output, not when it gets |
| 6953 | * 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] | 6954 | * |
Maxime Roussin-Bélanger | 1d009c2 | 2020-12-17 17:10:13 -0500 | [diff] [blame] | 6955 | * \ingroup output |
Pekka Paalanen | 37b7c6e | 2017-11-07 10:15:01 +0200 | [diff] [blame] | 6956 | */ |
| 6957 | WL_EXPORT void |
| 6958 | weston_output_add_destroy_listener(struct weston_output *output, |
| 6959 | struct wl_listener *listener) |
| 6960 | { |
| 6961 | wl_signal_add(&output->user_destroy_signal, listener); |
| 6962 | } |
| 6963 | |
| 6964 | /** Look up destroy listener for an output |
| 6965 | * |
| 6966 | * \param output The output to query. |
| 6967 | * \param notify The notify function used used for the added destroy listener. |
| 6968 | * \return The listener, or NULL if not found. |
| 6969 | * |
| 6970 | * This looks up the previously added destroy listener struct based on the |
| 6971 | * notify function it has. The listener can be used to access user data |
| 6972 | * through \c container_of(). |
| 6973 | * |
| 6974 | * \sa wl_signal_get() weston_output_add_destroy_listener() |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 6975 | * \ingroup output |
Pekka Paalanen | 37b7c6e | 2017-11-07 10:15:01 +0200 | [diff] [blame] | 6976 | */ |
| 6977 | WL_EXPORT struct wl_listener * |
| 6978 | weston_output_get_destroy_listener(struct weston_output *output, |
| 6979 | wl_notify_func_t notify) |
| 6980 | { |
| 6981 | return wl_signal_get(&output->user_destroy_signal, notify); |
| 6982 | } |
| 6983 | |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6984 | /** Uninitialize an output |
| 6985 | * |
| 6986 | * Removes the output from the list of enabled outputs if necessary, but |
| 6987 | * does not call the backend's output disable function. The output will no |
| 6988 | * longer be in the list of pending outputs either. |
| 6989 | * |
| 6990 | * All fields of weston_output become uninitialized, i.e. should not be used |
| 6991 | * anymore. The caller can free the memory after this. |
| 6992 | * |
Maxime Roussin-Bélanger | 1d009c2 | 2020-12-17 17:10:13 -0500 | [diff] [blame] | 6993 | * \ingroup output |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6994 | * \internal |
| 6995 | */ |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6996 | WL_EXPORT void |
Pekka Paalanen | ae6d35d | 2017-08-16 12:07:14 +0300 | [diff] [blame] | 6997 | weston_output_release(struct weston_output *output) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6998 | { |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 6999 | struct weston_head *head, *tmp; |
| 7000 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 7001 | output->destroying = 1; |
| 7002 | |
Marius Vlad | f2452d6 | 2021-12-09 14:07:21 +0200 | [diff] [blame] | 7003 | weston_signal_emit_mutable(&output->user_destroy_signal, output); |
Pekka Paalanen | 37b7c6e | 2017-11-07 10:15:01 +0200 | [diff] [blame] | 7004 | |
Pekka Paalanen | dcbcfc7 | 2017-10-26 14:33:59 +0300 | [diff] [blame] | 7005 | if (output->idle_repaint_source) |
| 7006 | wl_event_source_remove(output->idle_repaint_source); |
| 7007 | |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 7008 | if (output->enabled) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 7009 | weston_compositor_remove_output(output); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 7010 | |
Pekka Paalanen | 9a9e6ce | 2021-06-08 14:17:44 +0300 | [diff] [blame] | 7011 | weston_color_profile_unref(output->color_profile); |
| 7012 | |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 7013 | pixman_region32_fini(&output->region); |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 7014 | wl_list_remove(&output->link); |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 7015 | |
| 7016 | wl_list_for_each_safe(head, tmp, &output->head_list, output_link) |
| 7017 | weston_head_detach(head); |
| 7018 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 7019 | free(output->name); |
| 7020 | } |
| 7021 | |
Pekka Paalanen | 1ae9d08 | 2017-11-02 14:11:53 +0200 | [diff] [blame] | 7022 | /** Find an output by its given name |
| 7023 | * |
| 7024 | * \param compositor The compositor to search in. |
| 7025 | * \param name The output name to search for. |
| 7026 | * \return An existing output with the given name, or NULL if not found. |
| 7027 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7028 | * \ingroup compositor |
Pekka Paalanen | 1ae9d08 | 2017-11-02 14:11:53 +0200 | [diff] [blame] | 7029 | */ |
| 7030 | WL_EXPORT struct weston_output * |
| 7031 | weston_compositor_find_output_by_name(struct weston_compositor *compositor, |
| 7032 | const char *name) |
| 7033 | { |
| 7034 | struct weston_output *output; |
| 7035 | |
| 7036 | wl_list_for_each(output, &compositor->output_list, link) |
| 7037 | if (strcmp(output->name, name) == 0) |
| 7038 | return output; |
| 7039 | |
| 7040 | wl_list_for_each(output, &compositor->pending_output_list, link) |
| 7041 | if (strcmp(output->name, name) == 0) |
| 7042 | return output; |
| 7043 | |
| 7044 | return NULL; |
| 7045 | } |
| 7046 | |
| 7047 | /** Create a named output |
| 7048 | * |
| 7049 | * \param compositor The compositor. |
| 7050 | * \param name The name for the output. |
| 7051 | * \return A new \c weston_output, or NULL on failure. |
| 7052 | * |
| 7053 | * This creates a new weston_output that starts with no heads attached. |
| 7054 | * |
| 7055 | * An output must be configured and it must have at least one head before |
| 7056 | * it can be enabled. |
| 7057 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7058 | * \ingroup compositor |
Pekka Paalanen | 1ae9d08 | 2017-11-02 14:11:53 +0200 | [diff] [blame] | 7059 | */ |
| 7060 | WL_EXPORT struct weston_output * |
| 7061 | weston_compositor_create_output(struct weston_compositor *compositor, |
| 7062 | const char *name) |
| 7063 | { |
| 7064 | assert(compositor->backend->create_output); |
| 7065 | |
| 7066 | if (weston_compositor_find_output_by_name(compositor, name)) { |
| 7067 | weston_log("Warning: attempted to create an output with a " |
| 7068 | "duplicate name '%s'.\n", name); |
| 7069 | return NULL; |
| 7070 | } |
| 7071 | |
| 7072 | return compositor->backend->create_output(compositor, name); |
| 7073 | } |
| 7074 | |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 7075 | /** Create an output for an unused head |
| 7076 | * |
| 7077 | * \param compositor The compositor. |
| 7078 | * \param head The head to attach to the output. |
| 7079 | * \return A new \c weston_output, or NULL on failure. |
| 7080 | * |
| 7081 | * This creates a new weston_output that starts with the given head attached. |
| 7082 | * The output inherits the name of the head. The head must not be already |
| 7083 | * attached to another output. |
| 7084 | * |
| 7085 | * An output must be configured before it can be enabled. |
| 7086 | * |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7087 | * \ingroup compositor |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 7088 | */ |
| 7089 | WL_EXPORT struct weston_output * |
| 7090 | weston_compositor_create_output_with_head(struct weston_compositor *compositor, |
| 7091 | struct weston_head *head) |
| 7092 | { |
| 7093 | struct weston_output *output; |
| 7094 | |
Pekka Paalanen | 1ae9d08 | 2017-11-02 14:11:53 +0200 | [diff] [blame] | 7095 | output = weston_compositor_create_output(compositor, head->name); |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 7096 | if (!output) |
| 7097 | return NULL; |
| 7098 | |
| 7099 | if (weston_output_attach_head(output, head) < 0) { |
Pekka Paalanen | 42c0e14 | 2017-10-27 12:07:49 +0300 | [diff] [blame] | 7100 | weston_output_destroy(output); |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 7101 | return NULL; |
| 7102 | } |
| 7103 | |
| 7104 | return output; |
| 7105 | } |
| 7106 | |
| 7107 | /** Destroy an output |
| 7108 | * |
| 7109 | * \param output The output to destroy. |
| 7110 | * |
| 7111 | * The heads attached to the given output are detached and become unused again. |
| 7112 | * |
| 7113 | * It is not necessary to explicitly destroy all outputs at compositor exit. |
Leandro Ribeiro | ca640d5 | 2020-01-27 19:12:01 -0300 | [diff] [blame] | 7114 | * weston_compositor_destroy() will automatically destroy any remaining |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 7115 | * outputs. |
| 7116 | * |
Maxime Roussin-Bélanger | 1d009c2 | 2020-12-17 17:10:13 -0500 | [diff] [blame] | 7117 | * \ingroup output |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 7118 | */ |
| 7119 | WL_EXPORT void |
| 7120 | weston_output_destroy(struct weston_output *output) |
| 7121 | { |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 7122 | output->destroy(output); |
| 7123 | } |
| 7124 | |
Pekka Paalanen | cf0a476 | 2017-04-04 16:36:07 +0300 | [diff] [blame] | 7125 | /** When you need a head... |
| 7126 | * |
| 7127 | * This function is a hack, used until all code has been converted to become |
| 7128 | * multi-head aware. |
| 7129 | * |
| 7130 | * \param output The weston_output whose head to get. |
| 7131 | * \return The first head in the output's list. |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame] | 7132 | * |
Maxime Roussin-Bélanger | 1d009c2 | 2020-12-17 17:10:13 -0500 | [diff] [blame] | 7133 | * \ingroup output |
Pekka Paalanen | cf0a476 | 2017-04-04 16:36:07 +0300 | [diff] [blame] | 7134 | */ |
| 7135 | WL_EXPORT struct weston_head * |
| 7136 | weston_output_get_first_head(struct weston_output *output) |
| 7137 | { |
| 7138 | if (wl_list_empty(&output->head_list)) |
| 7139 | return NULL; |
| 7140 | |
| 7141 | return container_of(output->head_list.next, |
| 7142 | struct weston_head, output_link); |
| 7143 | } |
| 7144 | |
Ankit Nautiyal | 2844f8e | 2019-04-03 10:14:59 +0530 | [diff] [blame] | 7145 | /** Allow/Disallow content-protection support for an output |
| 7146 | * |
| 7147 | * This function sets the allow_protection member for an output. Setting of |
| 7148 | * this field will allow the compositor to attempt content-protection for this |
| 7149 | * output, for a backend that supports the content-protection protocol. |
| 7150 | * |
| 7151 | * \param output The weston_output for whom the content-protection is to be |
| 7152 | * allowed. |
| 7153 | * \param allow_protection The bool value which is to be set. |
| 7154 | */ |
| 7155 | WL_EXPORT void |
| 7156 | weston_output_allow_protection(struct weston_output *output, |
| 7157 | bool allow_protection) |
| 7158 | { |
| 7159 | output->allow_protection = allow_protection; |
| 7160 | } |
| 7161 | |
Benjamin Franzke | 315b3dc | 2011-03-08 11:32:57 +0100 | [diff] [blame] | 7162 | static void |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 7163 | xdg_output_unlist(struct wl_resource *resource) |
| 7164 | { |
| 7165 | wl_list_remove(wl_resource_get_link(resource)); |
| 7166 | } |
| 7167 | |
| 7168 | static void |
| 7169 | xdg_output_destroy(struct wl_client *client, struct wl_resource *resource) |
| 7170 | { |
| 7171 | wl_resource_destroy(resource); |
| 7172 | } |
| 7173 | |
| 7174 | static const struct zxdg_output_v1_interface xdg_output_interface = { |
| 7175 | xdg_output_destroy |
| 7176 | }; |
| 7177 | |
| 7178 | static void |
| 7179 | xdg_output_manager_destroy(struct wl_client *client, |
| 7180 | struct wl_resource *resource) |
| 7181 | { |
| 7182 | wl_resource_destroy(resource); |
| 7183 | } |
| 7184 | |
| 7185 | static void |
| 7186 | xdg_output_manager_get_xdg_output(struct wl_client *client, |
| 7187 | struct wl_resource *manager, |
| 7188 | uint32_t id, |
| 7189 | struct wl_resource *output_resource) |
| 7190 | { |
| 7191 | int version = wl_resource_get_version(manager); |
| 7192 | struct weston_head *head = wl_resource_get_user_data(output_resource); |
| 7193 | struct weston_output *output = head->output; |
| 7194 | struct wl_resource *resource; |
| 7195 | |
| 7196 | resource = wl_resource_create(client, &zxdg_output_v1_interface, |
| 7197 | version, id); |
| 7198 | if (resource == NULL) { |
| 7199 | wl_client_post_no_memory(client); |
| 7200 | return; |
| 7201 | } |
| 7202 | |
| 7203 | wl_list_insert(&head->xdg_output_resource_list, |
| 7204 | wl_resource_get_link(resource)); |
| 7205 | |
| 7206 | wl_resource_set_implementation(resource, &xdg_output_interface, |
| 7207 | NULL, xdg_output_unlist); |
| 7208 | |
| 7209 | zxdg_output_v1_send_logical_position(resource, output->x, output->y); |
| 7210 | zxdg_output_v1_send_logical_size(resource, |
| 7211 | output->width, |
| 7212 | output->height); |
| 7213 | if (version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION) |
| 7214 | zxdg_output_v1_send_name(resource, head->name); |
| 7215 | |
| 7216 | zxdg_output_v1_send_done(resource); |
| 7217 | } |
| 7218 | |
| 7219 | static const struct zxdg_output_manager_v1_interface xdg_output_manager_interface = { |
| 7220 | xdg_output_manager_destroy, |
| 7221 | xdg_output_manager_get_xdg_output |
| 7222 | }; |
| 7223 | |
| 7224 | static void |
| 7225 | bind_xdg_output_manager(struct wl_client *client, |
| 7226 | void *data, uint32_t version, uint32_t id) |
| 7227 | { |
| 7228 | struct wl_resource *resource; |
| 7229 | |
| 7230 | resource = wl_resource_create(client, &zxdg_output_manager_v1_interface, |
| 7231 | version, id); |
| 7232 | if (resource == NULL) { |
| 7233 | wl_client_post_no_memory(client); |
| 7234 | return; |
| 7235 | } |
| 7236 | |
| 7237 | wl_resource_set_implementation(resource, &xdg_output_manager_interface, |
| 7238 | NULL, NULL); |
| 7239 | } |
| 7240 | |
| 7241 | static void |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 7242 | destroy_viewport(struct wl_resource *resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 7243 | { |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 7244 | struct weston_surface *surface = |
| 7245 | wl_resource_get_user_data(resource); |
| 7246 | |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 7247 | if (!surface) |
| 7248 | return; |
| 7249 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 7250 | surface->viewport_resource = NULL; |
Pekka Paalanen | f0cad48 | 2014-03-14 14:38:16 +0200 | [diff] [blame] | 7251 | surface->pending.buffer_viewport.buffer.src_width = |
| 7252 | wl_fixed_from_int(-1); |
| 7253 | surface->pending.buffer_viewport.surface.width = -1; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 7254 | surface->pending.buffer_viewport.changed = 1; |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 7255 | } |
| 7256 | |
| 7257 | static void |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 7258 | viewport_destroy(struct wl_client *client, |
| 7259 | struct wl_resource *resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 7260 | { |
| 7261 | wl_resource_destroy(resource); |
| 7262 | } |
| 7263 | |
| 7264 | static void |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 7265 | viewport_set_source(struct wl_client *client, |
| 7266 | struct wl_resource *resource, |
| 7267 | wl_fixed_t src_x, |
| 7268 | wl_fixed_t src_y, |
| 7269 | wl_fixed_t src_width, |
| 7270 | wl_fixed_t src_height) |
| 7271 | { |
| 7272 | struct weston_surface *surface = |
| 7273 | wl_resource_get_user_data(resource); |
| 7274 | |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 7275 | if (!surface) { |
| 7276 | wl_resource_post_error(resource, |
| 7277 | WP_VIEWPORT_ERROR_NO_SURFACE, |
| 7278 | "wl_surface for this viewport is no longer exists"); |
| 7279 | return; |
| 7280 | } |
| 7281 | |
| 7282 | assert(surface->viewport_resource == resource); |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 7283 | assert(surface->resource); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 7284 | |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 7285 | if (src_width == wl_fixed_from_int(-1) && |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 7286 | src_height == wl_fixed_from_int(-1) && |
| 7287 | src_x == wl_fixed_from_int(-1) && |
| 7288 | src_y == wl_fixed_from_int(-1)) { |
| 7289 | /* unset source rect */ |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 7290 | surface->pending.buffer_viewport.buffer.src_width = |
| 7291 | wl_fixed_from_int(-1); |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 7292 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 7293 | return; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 7294 | } |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 7295 | |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 7296 | 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] | 7297 | wl_resource_post_error(resource, |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 7298 | WP_VIEWPORT_ERROR_BAD_VALUE, |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 7299 | "wl_surface@%d viewport source " |
| 7300 | "w=%f <= 0, h=%f <= 0, x=%f < 0, or y=%f < 0", |
| 7301 | wl_resource_get_id(surface->resource), |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 7302 | wl_fixed_to_double(src_width), |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 7303 | wl_fixed_to_double(src_height), |
| 7304 | wl_fixed_to_double(src_x), |
| 7305 | wl_fixed_to_double(src_y)); |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 7306 | return; |
| 7307 | } |
| 7308 | |
| 7309 | surface->pending.buffer_viewport.buffer.src_x = src_x; |
| 7310 | surface->pending.buffer_viewport.buffer.src_y = src_y; |
| 7311 | surface->pending.buffer_viewport.buffer.src_width = src_width; |
| 7312 | surface->pending.buffer_viewport.buffer.src_height = src_height; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 7313 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 7314 | } |
| 7315 | |
| 7316 | static void |
| 7317 | viewport_set_destination(struct wl_client *client, |
| 7318 | struct wl_resource *resource, |
| 7319 | int32_t dst_width, |
| 7320 | int32_t dst_height) |
| 7321 | { |
| 7322 | struct weston_surface *surface = |
| 7323 | wl_resource_get_user_data(resource); |
| 7324 | |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 7325 | if (!surface) { |
| 7326 | wl_resource_post_error(resource, |
| 7327 | WP_VIEWPORT_ERROR_NO_SURFACE, |
| 7328 | "wl_surface for this viewport no longer exists"); |
| 7329 | return; |
| 7330 | } |
limin.tian | 531dd23 | 2025-01-07 12:09:27 +0000 | [diff] [blame] | 7331 | WESTON_LOGI(COMMON_LOG, "w:%d h:%d\n", dst_width, dst_height); |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 7332 | assert(surface->viewport_resource == resource); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 7333 | |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 7334 | if (dst_width == -1 && dst_height == -1) { |
| 7335 | /* unset destination size */ |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 7336 | surface->pending.buffer_viewport.surface.width = -1; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 7337 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 7338 | return; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 7339 | } |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 7340 | |
| 7341 | if (dst_width <= 0 || dst_height <= 0) { |
| 7342 | wl_resource_post_error(resource, |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 7343 | WP_VIEWPORT_ERROR_BAD_VALUE, |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 7344 | "destination size must be positive (%dx%d)", |
| 7345 | dst_width, dst_height); |
| 7346 | return; |
| 7347 | } |
| 7348 | |
| 7349 | surface->pending.buffer_viewport.surface.width = dst_width; |
| 7350 | surface->pending.buffer_viewport.surface.height = dst_height; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 7351 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 7352 | } |
| 7353 | |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 7354 | static const struct wp_viewport_interface viewport_interface = { |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 7355 | viewport_destroy, |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 7356 | viewport_set_source, |
| 7357 | viewport_set_destination |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 7358 | }; |
| 7359 | |
| 7360 | static void |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 7361 | viewporter_destroy(struct wl_client *client, |
| 7362 | struct wl_resource *resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 7363 | { |
| 7364 | wl_resource_destroy(resource); |
| 7365 | } |
| 7366 | |
| 7367 | static void |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 7368 | viewporter_get_viewport(struct wl_client *client, |
| 7369 | struct wl_resource *viewporter, |
| 7370 | uint32_t id, |
| 7371 | struct wl_resource *surface_resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 7372 | { |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 7373 | int version = wl_resource_get_version(viewporter); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 7374 | struct weston_surface *surface = |
| 7375 | wl_resource_get_user_data(surface_resource); |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 7376 | struct wl_resource *resource; |
| 7377 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 7378 | if (surface->viewport_resource) { |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 7379 | wl_resource_post_error(viewporter, |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 7380 | WP_VIEWPORTER_ERROR_VIEWPORT_EXISTS, |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 7381 | "a viewport for that surface already exists"); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 7382 | return; |
| 7383 | } |
| 7384 | |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 7385 | resource = wl_resource_create(client, &wp_viewport_interface, |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 7386 | version, id); |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 7387 | if (resource == NULL) { |
| 7388 | wl_client_post_no_memory(client); |
| 7389 | return; |
| 7390 | } |
| 7391 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 7392 | wl_resource_set_implementation(resource, &viewport_interface, |
| 7393 | surface, destroy_viewport); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 7394 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 7395 | surface->viewport_resource = resource; |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 7396 | } |
| 7397 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 7398 | static const struct wp_viewporter_interface viewporter_interface = { |
| 7399 | viewporter_destroy, |
| 7400 | viewporter_get_viewport |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 7401 | }; |
| 7402 | |
| 7403 | static void |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 7404 | bind_viewporter(struct wl_client *client, |
| 7405 | void *data, uint32_t version, uint32_t id) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 7406 | { |
| 7407 | struct wl_resource *resource; |
| 7408 | |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 7409 | resource = wl_resource_create(client, &wp_viewporter_interface, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 7410 | version, id); |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 7411 | if (resource == NULL) { |
| 7412 | wl_client_post_no_memory(client); |
| 7413 | return; |
| 7414 | } |
| 7415 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 7416 | wl_resource_set_implementation(resource, &viewporter_interface, |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 7417 | NULL, NULL); |
| 7418 | } |
| 7419 | |
| 7420 | static void |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 7421 | destroy_presentation_feedback(struct wl_resource *feedback_resource) |
| 7422 | { |
| 7423 | struct weston_presentation_feedback *feedback; |
| 7424 | |
| 7425 | feedback = wl_resource_get_user_data(feedback_resource); |
| 7426 | |
| 7427 | wl_list_remove(&feedback->link); |
| 7428 | free(feedback); |
| 7429 | } |
| 7430 | |
| 7431 | static void |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 7432 | presentation_destroy(struct wl_client *client, struct wl_resource *resource) |
| 7433 | { |
| 7434 | wl_resource_destroy(resource); |
| 7435 | } |
| 7436 | |
| 7437 | static void |
| 7438 | presentation_feedback(struct wl_client *client, |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 7439 | struct wl_resource *presentation_resource, |
| 7440 | struct wl_resource *surface_resource, |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 7441 | uint32_t callback) |
| 7442 | { |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 7443 | struct weston_surface *surface; |
| 7444 | struct weston_presentation_feedback *feedback; |
| 7445 | |
| 7446 | surface = wl_resource_get_user_data(surface_resource); |
| 7447 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 7448 | feedback = zalloc(sizeof *feedback); |
| 7449 | if (feedback == NULL) |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 7450 | goto err_calloc; |
| 7451 | |
| 7452 | feedback->resource = wl_resource_create(client, |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 7453 | &wp_presentation_feedback_interface, |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 7454 | 1, callback); |
| 7455 | if (!feedback->resource) |
| 7456 | goto err_create; |
| 7457 | |
| 7458 | wl_resource_set_implementation(feedback->resource, NULL, feedback, |
| 7459 | destroy_presentation_feedback); |
| 7460 | |
| 7461 | wl_list_insert(&surface->pending.feedback_list, &feedback->link); |
| 7462 | |
| 7463 | return; |
| 7464 | |
| 7465 | err_create: |
| 7466 | free(feedback); |
| 7467 | |
| 7468 | err_calloc: |
| 7469 | wl_client_post_no_memory(client); |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 7470 | } |
| 7471 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 7472 | static const struct wp_presentation_interface presentation_implementation = { |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 7473 | presentation_destroy, |
| 7474 | presentation_feedback |
| 7475 | }; |
| 7476 | |
| 7477 | static void |
| 7478 | bind_presentation(struct wl_client *client, |
| 7479 | void *data, uint32_t version, uint32_t id) |
| 7480 | { |
| 7481 | struct weston_compositor *compositor = data; |
| 7482 | struct wl_resource *resource; |
| 7483 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 7484 | resource = wl_resource_create(client, &wp_presentation_interface, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 7485 | version, id); |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 7486 | if (resource == NULL) { |
| 7487 | wl_client_post_no_memory(client); |
| 7488 | return; |
| 7489 | } |
| 7490 | |
| 7491 | wl_resource_set_implementation(resource, &presentation_implementation, |
| 7492 | compositor, NULL); |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 7493 | wp_presentation_send_clock_id(resource, compositor->presentation_clock); |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 7494 | } |
| 7495 | |
| 7496 | static void |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 7497 | compositor_bind(struct wl_client *client, |
| 7498 | void *data, uint32_t version, uint32_t id) |
| 7499 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 7500 | struct weston_compositor *compositor = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 7501 | struct wl_resource *resource; |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 7502 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 7503 | resource = wl_resource_create(client, &wl_compositor_interface, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 7504 | version, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 7505 | if (resource == NULL) { |
| 7506 | wl_client_post_no_memory(client); |
| 7507 | return; |
| 7508 | } |
| 7509 | |
| 7510 | wl_resource_set_implementation(resource, &compositor_interface, |
| 7511 | compositor, NULL); |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 7512 | } |
| 7513 | |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7514 | static const char * |
| 7515 | output_repaint_status_text(struct weston_output *output) |
| 7516 | { |
| 7517 | switch (output->repaint_status) { |
| 7518 | case REPAINT_NOT_SCHEDULED: |
| 7519 | return "no repaint"; |
| 7520 | case REPAINT_BEGIN_FROM_IDLE: |
| 7521 | return "start_repaint_loop scheduled"; |
| 7522 | case REPAINT_SCHEDULED: |
| 7523 | return "repaint scheduled"; |
| 7524 | case REPAINT_AWAITING_COMPLETION: |
| 7525 | return "awaiting completion"; |
| 7526 | } |
| 7527 | |
| 7528 | assert(!"output_repaint_status_text missing enum"); |
| 7529 | return NULL; |
| 7530 | } |
| 7531 | |
| 7532 | static void |
| 7533 | debug_scene_view_print_buffer(FILE *fp, struct weston_view *view) |
| 7534 | { |
| 7535 | struct weston_buffer *buffer = view->surface->buffer_ref.buffer; |
| 7536 | struct wl_shm_buffer *shm; |
| 7537 | struct linux_dmabuf_buffer *dmabuf; |
Marius Vlad | 00a6e01 | 2018-11-20 17:52:31 +0200 | [diff] [blame] | 7538 | const struct pixel_format_info *pixel_info = NULL; |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7539 | |
| 7540 | if (!buffer) { |
| 7541 | fprintf(fp, "\t\t[buffer not available]\n"); |
| 7542 | return; |
| 7543 | } |
| 7544 | |
| 7545 | shm = wl_shm_buffer_get(buffer->resource); |
| 7546 | if (shm) { |
Marius Vlad | 00a6e01 | 2018-11-20 17:52:31 +0200 | [diff] [blame] | 7547 | uint32_t _format = wl_shm_buffer_get_format(shm); |
| 7548 | pixel_info = pixel_format_get_info_shm(_format); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7549 | fprintf(fp, "\t\tSHM buffer\n"); |
Marius Vlad | 00a6e01 | 2018-11-20 17:52:31 +0200 | [diff] [blame] | 7550 | fprintf(fp, "\t\t\tformat: 0x%lx %s\n", |
| 7551 | (unsigned long) _format, |
| 7552 | pixel_info ? pixel_info->drm_format_name : "UNKNOWN"); |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 7553 | #ifdef ENABLE_DRM_HELP |
| 7554 | debug_write_shm_buffer_to_file(view, shm); |
| 7555 | #endif |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7556 | return; |
| 7557 | } |
| 7558 | |
| 7559 | dmabuf = linux_dmabuf_buffer_get(buffer->resource); |
| 7560 | if (dmabuf) { |
Marius Vlad | 6f6fd26 | 2021-07-12 12:58:34 +0300 | [diff] [blame] | 7561 | uint64_t modifier = dmabuf->attributes.modifier[0]; |
| 7562 | char *modifier_name = pixel_format_get_modifier(modifier); |
Marius Vlad | 00a6e01 | 2018-11-20 17:52:31 +0200 | [diff] [blame] | 7563 | pixel_info = pixel_format_get_info(dmabuf->attributes.format); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7564 | fprintf(fp, "\t\tdmabuf buffer\n"); |
Marius Vlad | 00a6e01 | 2018-11-20 17:52:31 +0200 | [diff] [blame] | 7565 | fprintf(fp, "\t\t\tformat: 0x%lx %s\n", |
| 7566 | (unsigned long) dmabuf->attributes.format, |
| 7567 | pixel_info ? pixel_info->drm_format_name : "UNKNOWN"); |
Marius Vlad | 6f6fd26 | 2021-07-12 12:58:34 +0300 | [diff] [blame] | 7568 | |
| 7569 | fprintf(fp, "\t\t\tmodifier: %s\n", modifier_name ? modifier_name : |
| 7570 | "Failed to convert to a modifier name"); |
| 7571 | free(modifier_name); |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 7572 | #ifdef ENABLE_DRM_HELP |
| 7573 | debug_write_dma_buffer_to_file(view, dmabuf); |
| 7574 | #endif |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7575 | return; |
| 7576 | } |
| 7577 | |
Marius Vlad | 253ba9a | 2019-03-17 18:22:21 +0200 | [diff] [blame] | 7578 | fprintf(fp, "\t\tEGL buffer\n"); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7579 | } |
| 7580 | |
| 7581 | static void |
| 7582 | debug_scene_view_print(FILE *fp, struct weston_view *view, int view_idx) |
| 7583 | { |
| 7584 | struct weston_compositor *ec = view->surface->compositor; |
| 7585 | struct weston_output *output; |
| 7586 | char desc[512]; |
| 7587 | pixman_box32_t *box; |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 7588 | pixman_box32_t *opaque_surface_box; |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7589 | uint32_t surface_id = 0; |
| 7590 | pid_t pid = 0; |
| 7591 | |
| 7592 | if (view->surface->resource) { |
| 7593 | struct wl_resource *resource = view->surface->resource; |
| 7594 | wl_client_get_credentials(wl_resource_get_client(resource), |
Dongjin Kim | ba89f00 | 2024-09-30 17:49:36 +0900 | [diff] [blame] | 7595 | &pid, NULL, NULL); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7596 | surface_id = wl_resource_get_id(view->surface->resource); |
| 7597 | } |
| 7598 | |
| 7599 | if (!view->surface->get_label || |
| 7600 | view->surface->get_label(view->surface, desc, sizeof(desc)) < 0) { |
| 7601 | strcpy(desc, "[no description available]"); |
| 7602 | } |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 7603 | fprintf(fp, "\tView %d (role %s, PID %d, surface ID %u, %s, %p %p video surface:%d):\n", |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7604 | view_idx, view->surface->role_name, pid, surface_id, |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 7605 | desc, view, view->surface, view->surface->is_video_surface); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7606 | |
| 7607 | box = pixman_region32_extents(&view->transform.boundingbox); |
| 7608 | fprintf(fp, "\t\tposition: (%d, %d) -> (%d, %d)\n", |
| 7609 | box->x1, box->y1, box->x2, box->y2); |
| 7610 | box = pixman_region32_extents(&view->transform.opaque); |
| 7611 | |
Michael Olbrich | b7e5f10 | 2020-08-11 16:33:35 +0200 | [diff] [blame] | 7612 | if (weston_view_is_opaque(view, &view->transform.boundingbox)) { |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7613 | fprintf(fp, "\t\t[fully opaque]\n"); |
| 7614 | } else if (!pixman_region32_not_empty(&view->transform.opaque)) { |
| 7615 | fprintf(fp, "\t\t[not opaque]\n"); |
| 7616 | } else { |
| 7617 | fprintf(fp, "\t\t[opaque: (%d, %d) -> (%d, %d)]\n", |
| 7618 | box->x1, box->y1, box->x2, box->y2); |
| 7619 | } |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 7620 | opaque_surface_box = pixman_region32_extents(&view->surface->opaque); |
| 7621 | fprintf(fp, "\t\t[surface:%p opaque: (%d, %d) -> (%d, %d)]\n", |
| 7622 | view->surface, opaque_surface_box->x1, opaque_surface_box->y1, opaque_surface_box->x2, opaque_surface_box->y2); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7623 | |
| 7624 | if (view->alpha < 1.0) |
| 7625 | fprintf(fp, "\t\talpha: %f\n", view->alpha); |
| 7626 | |
| 7627 | if (view->output_mask != 0) { |
| 7628 | bool first_output = true; |
| 7629 | fprintf(fp, "\t\toutputs: "); |
| 7630 | wl_list_for_each(output, &ec->output_list, link) { |
| 7631 | if (!(view->output_mask & (1 << output->id))) |
| 7632 | continue; |
| 7633 | fprintf(fp, "%s%d (%s)%s", |
| 7634 | (first_output) ? "" : ", ", |
| 7635 | output->id, output->name, |
| 7636 | (view->output == output) ? " (primary)" : ""); |
| 7637 | first_output = false; |
| 7638 | } |
| 7639 | } else { |
| 7640 | fprintf(fp, "\t\t[no outputs]"); |
| 7641 | } |
| 7642 | |
| 7643 | fprintf(fp, "\n"); |
| 7644 | |
| 7645 | debug_scene_view_print_buffer(fp, view); |
| 7646 | } |
| 7647 | |
Marius Vlad | 433f4e7 | 2019-02-17 22:14:23 +0200 | [diff] [blame] | 7648 | static void |
| 7649 | debug_scene_view_print_tree(struct weston_view *view, |
Marius Vlad | a6acfa8 | 2019-03-17 18:10:09 +0200 | [diff] [blame] | 7650 | FILE *fp, int *view_idx) |
Marius Vlad | 433f4e7 | 2019-02-17 22:14:23 +0200 | [diff] [blame] | 7651 | { |
| 7652 | struct weston_subsurface *sub; |
| 7653 | struct weston_view *ev; |
| 7654 | |
| 7655 | /* |
| 7656 | * print the view first, then we recursively go on printing |
| 7657 | * sub-surfaces. We bail out once no more sub-surfaces are available. |
| 7658 | */ |
Marius Vlad | a6acfa8 | 2019-03-17 18:10:09 +0200 | [diff] [blame] | 7659 | debug_scene_view_print(fp, view, *view_idx); |
Marius Vlad | 433f4e7 | 2019-02-17 22:14:23 +0200 | [diff] [blame] | 7660 | |
| 7661 | /* no more sub-surfaces */ |
| 7662 | if (wl_list_empty(&view->surface->subsurface_list)) |
| 7663 | return; |
| 7664 | |
| 7665 | wl_list_for_each(sub, &view->surface->subsurface_list, parent_link) { |
| 7666 | wl_list_for_each(ev, &sub->surface->views, surface_link) { |
Michael Olbrich | ef5f323 | 2020-04-29 09:03:15 +0200 | [diff] [blame] | 7667 | /* only print the child views of the current view */ |
| 7668 | if (ev->parent_view != view) |
Marius Vlad | 433f4e7 | 2019-02-17 22:14:23 +0200 | [diff] [blame] | 7669 | continue; |
Marius Vlad | a6acfa8 | 2019-03-17 18:10:09 +0200 | [diff] [blame] | 7670 | |
| 7671 | (*view_idx)++; |
Marius Vlad | 433f4e7 | 2019-02-17 22:14:23 +0200 | [diff] [blame] | 7672 | debug_scene_view_print_tree(ev, fp, view_idx); |
| 7673 | } |
| 7674 | } |
| 7675 | } |
| 7676 | |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7677 | /** |
| 7678 | * Output information on how libweston is currently composing the scene |
| 7679 | * graph. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7680 | * |
| 7681 | * \ingroup compositor |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7682 | */ |
| 7683 | WL_EXPORT char * |
| 7684 | weston_compositor_print_scene_graph(struct weston_compositor *ec) |
| 7685 | { |
| 7686 | struct weston_output *output; |
| 7687 | struct weston_layer *layer; |
| 7688 | struct timespec now; |
| 7689 | int layer_idx = 0; |
| 7690 | FILE *fp; |
| 7691 | char *ret; |
| 7692 | size_t len; |
| 7693 | int err; |
| 7694 | |
| 7695 | fp = open_memstream(&ret, &len); |
| 7696 | assert(fp); |
| 7697 | |
| 7698 | weston_compositor_read_presentation_clock(ec, &now); |
| 7699 | fprintf(fp, "Weston scene graph at %ld.%09ld:\n\n", |
| 7700 | now.tv_sec, now.tv_nsec); |
| 7701 | |
| 7702 | wl_list_for_each(output, &ec->output_list, link) { |
| 7703 | struct weston_head *head; |
| 7704 | int head_idx = 0; |
| 7705 | |
| 7706 | fprintf(fp, "Output %d (%s):\n", output->id, output->name); |
| 7707 | assert(output->enabled); |
| 7708 | |
| 7709 | fprintf(fp, "\tposition: (%d, %d) -> (%d, %d)\n", |
| 7710 | output->x, output->y, |
| 7711 | output->x + output->width, |
| 7712 | output->y + output->height); |
| 7713 | fprintf(fp, "\tmode: %dx%d@%.3fHz\n", |
| 7714 | output->current_mode->width, |
| 7715 | output->current_mode->height, |
| 7716 | output->current_mode->refresh / 1000.0); |
| 7717 | fprintf(fp, "\tscale: %d\n", output->scale); |
| 7718 | |
| 7719 | fprintf(fp, "\trepaint status: %s\n", |
| 7720 | output_repaint_status_text(output)); |
| 7721 | if (output->repaint_status == REPAINT_SCHEDULED) |
| 7722 | fprintf(fp, "\tnext repaint: %ld.%09ld\n", |
| 7723 | output->next_repaint.tv_sec, |
| 7724 | output->next_repaint.tv_nsec); |
| 7725 | |
| 7726 | wl_list_for_each(head, &output->head_list, output_link) { |
| 7727 | fprintf(fp, "\tHead %d (%s): %sconnected\n", |
| 7728 | head_idx++, head->name, |
| 7729 | (head->connected) ? "" : "not "); |
| 7730 | } |
| 7731 | } |
| 7732 | |
| 7733 | fprintf(fp, "\n"); |
| 7734 | |
| 7735 | wl_list_for_each(layer, &ec->layer_list, link) { |
| 7736 | struct weston_view *view; |
| 7737 | int view_idx = 0; |
| 7738 | |
| 7739 | fprintf(fp, "Layer %d (pos 0x%lx):\n", layer_idx++, |
| 7740 | (unsigned long) layer->position); |
| 7741 | |
| 7742 | if (!weston_layer_mask_is_infinite(layer)) { |
| 7743 | fprintf(fp, "\t[mask: (%d, %d) -> (%d,%d)]\n\n", |
| 7744 | layer->mask.x1, layer->mask.y1, |
| 7745 | layer->mask.x2, layer->mask.y2); |
| 7746 | } |
| 7747 | |
Marius Vlad | a6acfa8 | 2019-03-17 18:10:09 +0200 | [diff] [blame] | 7748 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
| 7749 | debug_scene_view_print_tree(view, fp, &view_idx); |
| 7750 | view_idx++; |
| 7751 | } |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7752 | |
| 7753 | if (wl_list_empty(&layer->view_list.link)) |
| 7754 | fprintf(fp, "\t[no views]\n"); |
| 7755 | |
| 7756 | fprintf(fp, "\n"); |
| 7757 | } |
| 7758 | |
| 7759 | err = fclose(fp); |
| 7760 | assert(err == 0); |
| 7761 | |
| 7762 | return ret; |
| 7763 | } |
| 7764 | |
| 7765 | /** |
| 7766 | * Called when the 'scene-graph' debug scope is bound by a client. This |
| 7767 | * one-shot weston-debug scope prints the current scene graph when bound, |
| 7768 | * and then terminates the stream. |
| 7769 | */ |
| 7770 | static void |
Marius Vlad | dad882a | 2019-07-17 15:43:53 +0300 | [diff] [blame] | 7771 | debug_scene_graph_cb(struct weston_log_subscription *sub, void *data) |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7772 | { |
| 7773 | struct weston_compositor *ec = data; |
| 7774 | char *str = weston_compositor_print_scene_graph(ec); |
| 7775 | |
Marius Vlad | dad882a | 2019-07-17 15:43:53 +0300 | [diff] [blame] | 7776 | weston_log_subscription_printf(sub, "%s", str); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7777 | free(str); |
Marius Vlad | dad882a | 2019-07-17 15:43:53 +0300 | [diff] [blame] | 7778 | weston_log_subscription_complete(sub); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7779 | } |
| 7780 | |
Leandro Ribeiro | 32a5acd | 2020-10-19 16:06:22 -0300 | [diff] [blame] | 7781 | /** Retrieve testsuite data from compositor |
| 7782 | * |
| 7783 | * The testsuite data can be defined by the test suite of projects that uses |
| 7784 | * libweston and given to the compositor at the moment of its creation. This |
| 7785 | * function should be used when we need to retrieve the testsuite private data |
| 7786 | * from the compositor. |
| 7787 | * |
| 7788 | * \param ec The weston compositor. |
| 7789 | * \return The testsuite data. |
| 7790 | * |
| 7791 | * \ingroup compositor |
| 7792 | * \sa weston_compositor_test_data_init |
| 7793 | */ |
| 7794 | WL_EXPORT void * |
| 7795 | weston_compositor_get_test_data(struct weston_compositor *ec) |
| 7796 | { |
| 7797 | return ec->test_data.test_private_data; |
| 7798 | } |
| 7799 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7800 | /** Create the compositor. |
| 7801 | * |
| 7802 | * This functions creates and initializes a compositor instance. |
| 7803 | * |
| 7804 | * \param display The Wayland display to be used. |
| 7805 | * \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] | 7806 | * \param log_ctx A pointer to weston_debug_compositor |
Leandro Ribeiro | cdb7218 | 2020-11-06 11:24:22 -0300 | [diff] [blame] | 7807 | * \param test_data Optional testsuite data, or NULL. |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7808 | * using the \ref weston_compositor_get_user_data function. |
| 7809 | * \return The compositor instance on success or NULL on failure. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7810 | * |
| 7811 | * \ingroup compositor |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7812 | */ |
| 7813 | WL_EXPORT struct weston_compositor * |
Marius Vlad | 880b485 | 2019-04-07 17:07:58 +0300 | [diff] [blame] | 7814 | weston_compositor_create(struct wl_display *display, |
Leandro Ribeiro | cdb7218 | 2020-11-06 11:24:22 -0300 | [diff] [blame] | 7815 | struct weston_log_context *log_ctx, void *user_data, |
| 7816 | const struct weston_testsuite_data *test_data) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 7817 | { |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7818 | struct weston_compositor *ec; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 7819 | struct wl_event_loop *loop; |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 7820 | |
Leandro Ribeiro | bd9c0a6 | 2020-01-17 10:47:49 -0300 | [diff] [blame] | 7821 | if (!log_ctx) |
| 7822 | return NULL; |
| 7823 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7824 | ec = zalloc(sizeof *ec); |
| 7825 | if (!ec) |
| 7826 | return NULL; |
| 7827 | |
Leandro Ribeiro | cdb7218 | 2020-11-06 11:24:22 -0300 | [diff] [blame] | 7828 | if (test_data) |
| 7829 | ec->test_data = *test_data; |
| 7830 | |
Leandro Ribeiro | bd9c0a6 | 2020-01-17 10:47:49 -0300 | [diff] [blame] | 7831 | ec->weston_log_ctx = log_ctx; |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7832 | ec->wl_display = display; |
| 7833 | ec->user_data = user_data; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 7834 | wl_signal_init(&ec->destroy_signal); |
Kristian Høgsberg | f03a04a | 2014-04-06 22:04:50 -0700 | [diff] [blame] | 7835 | wl_signal_init(&ec->create_surface_signal); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 7836 | wl_signal_init(&ec->activate_signal); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 7837 | wl_signal_init(&ec->transform_signal); |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 7838 | wl_signal_init(&ec->kill_signal); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 7839 | wl_signal_init(&ec->idle_signal); |
| 7840 | wl_signal_init(&ec->wake_signal); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 7841 | wl_signal_init(&ec->show_input_panel_signal); |
| 7842 | wl_signal_init(&ec->hide_input_panel_signal); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 7843 | wl_signal_init(&ec->update_input_panel_signal); |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 7844 | wl_signal_init(&ec->seat_created_signal); |
Richard Hughes | 59d5da7 | 2013-05-01 21:52:11 +0100 | [diff] [blame] | 7845 | wl_signal_init(&ec->output_created_signal); |
Ander Conselvan de Oliveira | f84327a | 2014-01-29 18:47:51 +0200 | [diff] [blame] | 7846 | wl_signal_init(&ec->output_destroyed_signal); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 7847 | wl_signal_init(&ec->output_moved_signal); |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 7848 | wl_signal_init(&ec->output_resized_signal); |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 7849 | wl_signal_init(&ec->heads_changed_signal); |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 7850 | wl_signal_init(&ec->output_heads_changed_signal); |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 7851 | wl_signal_init(&ec->session_signal); |
Robert Beckett | c569bdc | 2019-07-10 16:40:12 +0100 | [diff] [blame] | 7852 | ec->session_active = true; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 7853 | |
Casey Dahlin | 58ba137 | 2012-04-19 22:50:08 -0400 | [diff] [blame] | 7854 | ec->output_id_pool = 0; |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 7855 | ec->repaint_msec = DEFAULT_REPAINT_WINDOW; |
Casey Dahlin | 58ba137 | 2012-04-19 22:50:08 -0400 | [diff] [blame] | 7856 | |
Jonas Ådahl | 94e2e2d | 2014-10-18 18:42:19 +0200 | [diff] [blame] | 7857 | ec->activate_serial = 1; |
| 7858 | |
Louis-Francis Ratté-Boulianne | c4689ff | 2017-11-28 20:42:47 -0500 | [diff] [blame] | 7859 | ec->touch_mode = WESTON_TOUCH_MODE_NORMAL; |
| 7860 | |
Ankit Nautiyal | 5cfe03c | 2019-03-28 15:05:42 +0530 | [diff] [blame] | 7861 | ec->content_protection = NULL; |
| 7862 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 7863 | if (!wl_global_create(ec->wl_display, &wl_compositor_interface, 4, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 7864 | ec, compositor_bind)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7865 | goto fail; |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 7866 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 7867 | if (!wl_global_create(ec->wl_display, &wl_subcompositor_interface, 1, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 7868 | ec, bind_subcompositor)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7869 | goto fail; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 7870 | |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 7871 | if (!wl_global_create(ec->wl_display, &wp_viewporter_interface, 1, |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 7872 | ec, bind_viewporter)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7873 | goto fail; |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 7874 | |
Roman Gilg | e97391c | 2019-03-29 13:01:06 +0100 | [diff] [blame] | 7875 | if (!wl_global_create(ec->wl_display, &zxdg_output_manager_v1_interface, 2, |
| 7876 | ec, bind_xdg_output_manager)) |
| 7877 | goto fail; |
| 7878 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 7879 | if (!wl_global_create(ec->wl_display, &wp_presentation_interface, 1, |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 7880 | ec, bind_presentation)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7881 | goto fail; |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 7882 | |
Jonas Ådahl | 30d61d8 | 2014-10-22 21:21:17 +0200 | [diff] [blame] | 7883 | if (weston_input_init(ec) != 0) |
| 7884 | goto fail; |
| 7885 | |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 7886 | if (aml_config_setup(ec) != 0 ) { |
| 7887 | weston_log("\n aml config fail\n"); |
| 7888 | } |
| 7889 | |
limin.tian | ff78906 | 2024-08-14 02:24:40 +0000 | [diff] [blame] | 7890 | if (aml_drm_config_setup(ec) != 0 ) { |
| 7891 | weston_log("\n aml drm config fail\n"); |
| 7892 | } |
| 7893 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 7894 | wl_list_init(&ec->view_list); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 7895 | wl_list_init(&ec->plane_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 7896 | wl_list_init(&ec->layer_list); |
| 7897 | wl_list_init(&ec->seat_list); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 7898 | wl_list_init(&ec->pending_output_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 7899 | wl_list_init(&ec->output_list); |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 7900 | wl_list_init(&ec->head_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 7901 | wl_list_init(&ec->key_binding_list); |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 7902 | wl_list_init(&ec->modifier_binding_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 7903 | wl_list_init(&ec->button_binding_list); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 7904 | wl_list_init(&ec->touch_binding_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 7905 | wl_list_init(&ec->axis_binding_list); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 7906 | wl_list_init(&ec->debug_binding_list); |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 7907 | wl_list_init(&ec->video_surface_list); |
leng.fang | dbaf6fa | 2024-06-20 19:31:04 +0800 | [diff] [blame] | 7908 | wl_list_init(&ec->surface_id_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 7909 | |
Pekka Paalanen | 827b5d2 | 2016-06-29 11:54:26 +0200 | [diff] [blame] | 7910 | wl_list_init(&ec->plugin_api_list); |
| 7911 | |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 7912 | weston_plane_init(&ec->primary_plane, ec, 0, 0); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 7913 | weston_compositor_stack_plane(ec, &ec->primary_plane, NULL); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 7914 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7915 | wl_data_device_manager_init(ec->wl_display); |
| 7916 | |
| 7917 | wl_display_init_shm(ec->wl_display); |
| 7918 | |
| 7919 | loop = wl_display_get_event_loop(ec->wl_display); |
| 7920 | ec->idle_source = wl_event_loop_add_timer(loop, idle_handler, ec); |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 7921 | ec->repaint_timer = |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 7922 | wl_event_loop_add_timer(loop, output_repaint_timer_handler_aml, |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 7923 | ec); |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 7924 | wl_event_source_timer_update(ec->repaint_timer, 16); |
leng.fang | bd0b883 | 2024-08-09 18:36:50 +0800 | [diff] [blame] | 7925 | weston_compositor_init_keytimer(ec, loop); |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7926 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 7927 | weston_layer_init(&ec->fade_layer, ec); |
| 7928 | weston_layer_init(&ec->cursor_layer, ec); |
| 7929 | |
| 7930 | weston_layer_set_position(&ec->fade_layer, WESTON_LAYER_POSITION_FADE); |
| 7931 | weston_layer_set_position(&ec->cursor_layer, |
| 7932 | WESTON_LAYER_POSITION_CURSOR); |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7933 | |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7934 | ec->debug_scene = |
Leandro Ribeiro | ce10019 | 2019-12-26 16:35:49 -0300 | [diff] [blame] | 7935 | weston_compositor_add_log_scope(ec, "scene-graph", |
| 7936 | "Scene graph details\n", |
| 7937 | debug_scene_graph_cb, NULL, |
| 7938 | ec); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7939 | |
Marius Vlad | da104eb | 2019-09-05 14:31:01 +0300 | [diff] [blame] | 7940 | ec->timeline = |
Leandro Ribeiro | ce10019 | 2019-12-26 16:35:49 -0300 | [diff] [blame] | 7941 | weston_compositor_add_log_scope(ec, "timeline", |
| 7942 | "Timeline event points\n", |
| 7943 | weston_timeline_create_subscription, |
| 7944 | weston_timeline_destroy_subscription, |
| 7945 | ec); |
leng.fang | 32af9fc | 2024-06-13 11:22:15 +0800 | [diff] [blame] | 7946 | weston_compositor_aml_init(ec); |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7947 | return ec; |
| 7948 | |
| 7949 | fail: |
| 7950 | free(ec); |
| 7951 | return NULL; |
| 7952 | } |
| 7953 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 7954 | /** weston_compositor_shutdown |
| 7955 | * \ingroup compositor |
| 7956 | */ |
Benjamin Franzke | b826302 | 2011-08-30 11:32:47 +0200 | [diff] [blame] | 7957 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 7958 | weston_compositor_shutdown(struct weston_compositor *ec) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 7959 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 7960 | struct weston_output *output, *next; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 7961 | |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 7962 | wl_event_source_remove(ec->idle_source); |
Lujin Wang | d4b46cd | 2019-08-12 12:03:29 -0700 | [diff] [blame] | 7963 | wl_event_source_remove(ec->repaint_timer); |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 7964 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 7965 | /* Destroy all outputs associated with this compositor */ |
Tiago Vignatti | b303a1d | 2011-12-18 22:27:40 +0200 | [diff] [blame] | 7966 | wl_list_for_each_safe(output, next, &ec->output_list, link) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 7967 | output->destroy(output); |
Pekka Paalanen | 4738f3b | 2012-01-02 15:47:07 +0200 | [diff] [blame] | 7968 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 7969 | /* Destroy all pending outputs associated with this compositor */ |
| 7970 | wl_list_for_each_safe(output, next, &ec->pending_output_list, link) |
| 7971 | output->destroy(output); |
| 7972 | |
Pekka Paalanen | 90a5ffa | 2021-02-25 12:03:28 +0200 | [diff] [blame] | 7973 | /* Color manager objects may have renderer hooks */ |
| 7974 | if (ec->color_manager) { |
| 7975 | ec->color_manager->destroy(ec->color_manager); |
| 7976 | ec->color_manager = NULL; |
| 7977 | } |
| 7978 | |
Ander Conselvan de Oliveira | 1853676 | 2013-12-20 21:07:00 +0200 | [diff] [blame] | 7979 | if (ec->renderer) |
| 7980 | ec->renderer->destroy(ec); |
| 7981 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 7982 | weston_binding_list_destroy_all(&ec->key_binding_list); |
Ryo Munakata | 27135af | 2015-07-17 13:07:42 +0900 | [diff] [blame] | 7983 | weston_binding_list_destroy_all(&ec->modifier_binding_list); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 7984 | weston_binding_list_destroy_all(&ec->button_binding_list); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 7985 | weston_binding_list_destroy_all(&ec->touch_binding_list); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 7986 | weston_binding_list_destroy_all(&ec->axis_binding_list); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 7987 | weston_binding_list_destroy_all(&ec->debug_binding_list); |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 7988 | |
leng.fang | dbaf6fa | 2024-06-20 19:31:04 +0800 | [diff] [blame] | 7989 | weston_compositor_clear_surface_id(ec); |
| 7990 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 7991 | weston_plane_release(&ec->primary_plane); |
Pekka Paalanen | 8740037 | 2021-05-14 14:29:40 +0300 | [diff] [blame] | 7992 | |
| 7993 | weston_layer_fini(&ec->fade_layer); |
| 7994 | weston_layer_fini(&ec->cursor_layer); |
| 7995 | |
| 7996 | if (!wl_list_empty(&ec->layer_list)) |
Dongjin Kim | ba89f00 | 2024-09-30 17:49:36 +0900 | [diff] [blame] | 7997 | weston_log("BUG: layer_list is not empty after shutdown. Calls to weston_layer_fini() are missing somewhere.\n"); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 7998 | } |
| 7999 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 8000 | /** weston_compositor_exit_with_code |
| 8001 | * \ingroup compositor |
| 8002 | */ |
Kristian Høgsberg | af4f2aa | 2013-02-15 20:53:20 -0500 | [diff] [blame] | 8003 | WL_EXPORT void |
Adam Jackson | 3c3f3b1 | 2019-10-16 16:02:59 -0400 | [diff] [blame] | 8004 | weston_compositor_exit_with_code(struct weston_compositor *compositor, |
Frederic Plourde | c336f06 | 2014-10-29 14:44:33 -0400 | [diff] [blame] | 8005 | int exit_code) |
| 8006 | { |
Pekka Paalanen | f5ef88f | 2014-11-18 15:57:04 +0200 | [diff] [blame] | 8007 | if (compositor->exit_code == EXIT_SUCCESS) |
| 8008 | compositor->exit_code = exit_code; |
| 8009 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 8010 | weston_compositor_exit(compositor); |
Frederic Plourde | c336f06 | 2014-10-29 14:44:33 -0400 | [diff] [blame] | 8011 | } |
| 8012 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 8013 | /** weston_compositor_set_default_pointer_grab |
| 8014 | * \ingroup compositor |
| 8015 | */ |
Frederic Plourde | c336f06 | 2014-10-29 14:44:33 -0400 | [diff] [blame] | 8016 | WL_EXPORT void |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 8017 | weston_compositor_set_default_pointer_grab(struct weston_compositor *ec, |
| 8018 | const struct weston_pointer_grab_interface *interface) |
| 8019 | { |
| 8020 | struct weston_seat *seat; |
| 8021 | |
| 8022 | ec->default_pointer_grab = interface; |
| 8023 | wl_list_for_each(seat, &ec->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 8024 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 8025 | |
| 8026 | if (pointer) |
| 8027 | weston_pointer_set_default_grab(pointer, interface); |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 8028 | } |
| 8029 | } |
| 8030 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 8031 | /** weston_compositor_set_presentation_clock |
| 8032 | * \ingroup compositor |
| 8033 | */ |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 8034 | WL_EXPORT int |
| 8035 | weston_compositor_set_presentation_clock(struct weston_compositor *compositor, |
| 8036 | clockid_t clk_id) |
| 8037 | { |
| 8038 | struct timespec ts; |
| 8039 | |
| 8040 | if (clock_gettime(clk_id, &ts) < 0) |
| 8041 | return -1; |
| 8042 | |
| 8043 | compositor->presentation_clock = clk_id; |
| 8044 | |
| 8045 | return 0; |
| 8046 | } |
| 8047 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 8048 | /** For choosing the software clock, when the display hardware or API |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 8049 | * does not expose a compatible presentation timestamp. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 8050 | * |
| 8051 | * \ingroup compositor |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 8052 | */ |
| 8053 | WL_EXPORT int |
| 8054 | weston_compositor_set_presentation_clock_software( |
| 8055 | struct weston_compositor *compositor) |
| 8056 | { |
| 8057 | /* In order of preference */ |
| 8058 | static const clockid_t clocks[] = { |
| 8059 | CLOCK_MONOTONIC_RAW, /* no jumps, no crawling */ |
| 8060 | CLOCK_MONOTONIC_COARSE, /* no jumps, may crawl, fast & coarse */ |
| 8061 | CLOCK_MONOTONIC, /* no jumps, may crawl */ |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 8062 | }; |
| 8063 | unsigned i; |
| 8064 | |
| 8065 | for (i = 0; i < ARRAY_LENGTH(clocks); i++) |
| 8066 | if (weston_compositor_set_presentation_clock(compositor, |
| 8067 | clocks[i]) == 0) |
| 8068 | return 0; |
| 8069 | |
| 8070 | weston_log("Error: no suitable presentation clock available.\n"); |
| 8071 | |
| 8072 | return -1; |
| 8073 | } |
| 8074 | |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 8075 | /** Read the current time from the Presentation clock |
| 8076 | * |
| 8077 | * \param compositor |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 8078 | * \param[out] ts The current time. |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 8079 | * |
| 8080 | * \note Reading the current time in user space is always imprecise to some |
| 8081 | * degree. |
| 8082 | * |
| 8083 | * This function is never meant to fail. If reading the clock does fail, |
| 8084 | * an error message is logged and a zero time is returned. Callers are not |
| 8085 | * supposed to detect or react to failures. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 8086 | * |
| 8087 | * \ingroup compositor |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 8088 | */ |
| 8089 | WL_EXPORT void |
| 8090 | weston_compositor_read_presentation_clock( |
| 8091 | const struct weston_compositor *compositor, |
| 8092 | struct timespec *ts) |
| 8093 | { |
| 8094 | static bool warned; |
| 8095 | int ret; |
| 8096 | |
| 8097 | ret = clock_gettime(compositor->presentation_clock, ts); |
| 8098 | if (ret < 0) { |
| 8099 | ts->tv_sec = 0; |
| 8100 | ts->tv_nsec = 0; |
| 8101 | |
| 8102 | if (!warned) |
| 8103 | weston_log("Error: failure to read " |
Antonio Borneo | 3957863 | 2019-04-26 23:57:31 +0200 | [diff] [blame] | 8104 | "the presentation clock %#x: '%s' (%d)\n", |
| 8105 | compositor->presentation_clock, |
| 8106 | strerror(errno), errno); |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 8107 | warned = true; |
| 8108 | } |
| 8109 | } |
| 8110 | |
Pekka Paalanen | 230f3b1 | 2014-09-29 14:18:40 -0400 | [diff] [blame] | 8111 | /** Import dmabuf buffer into current renderer |
| 8112 | * |
| 8113 | * \param compositor |
| 8114 | * \param buffer the dmabuf buffer to import |
| 8115 | * \return true on usable buffers, false otherwise |
| 8116 | * |
| 8117 | * This function tests that the linux_dmabuf_buffer is usable |
| 8118 | * for the current renderer. Returns false on unusable buffers. Usually |
| 8119 | * usability is tested by importing the dmabufs for composition. |
| 8120 | * |
| 8121 | * This hook is also used for detecting if the renderer supports |
| 8122 | * dmabufs at all. If the renderer hook is NULL, dmabufs are not |
| 8123 | * supported. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 8124 | * |
| 8125 | * \ingroup compositor |
| 8126 | */ |
Pekka Paalanen | 230f3b1 | 2014-09-29 14:18:40 -0400 | [diff] [blame] | 8127 | WL_EXPORT bool |
| 8128 | weston_compositor_import_dmabuf(struct weston_compositor *compositor, |
| 8129 | struct linux_dmabuf_buffer *buffer) |
| 8130 | { |
| 8131 | struct weston_renderer *renderer; |
| 8132 | |
| 8133 | renderer = compositor->renderer; |
| 8134 | |
| 8135 | if (renderer->import_dmabuf == NULL) |
| 8136 | return false; |
| 8137 | |
| 8138 | return renderer->import_dmabuf(compositor, buffer); |
| 8139 | } |
| 8140 | |
Marius Vlad | 5a70154 | 2019-11-16 20:26:52 +0200 | [diff] [blame] | 8141 | WL_EXPORT bool |
| 8142 | weston_compositor_dmabuf_can_scanout(struct weston_compositor *compositor, |
| 8143 | struct linux_dmabuf_buffer *buffer) |
| 8144 | { |
| 8145 | struct weston_backend *backend = compositor->backend; |
| 8146 | |
| 8147 | if (backend->can_scanout_dmabuf == NULL) |
| 8148 | return false; |
| 8149 | |
| 8150 | return backend->can_scanout_dmabuf(compositor, buffer); |
| 8151 | } |
| 8152 | |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 8153 | WL_EXPORT void |
Kristian Høgsberg | af4f2aa | 2013-02-15 20:53:20 -0500 | [diff] [blame] | 8154 | weston_version(int *major, int *minor, int *micro) |
| 8155 | { |
| 8156 | *major = WESTON_VERSION_MAJOR; |
| 8157 | *minor = WESTON_VERSION_MINOR; |
| 8158 | *micro = WESTON_VERSION_MICRO; |
| 8159 | } |
| 8160 | |
Daniel Stone | e03c111 | 2016-11-24 20:45:45 +0000 | [diff] [blame] | 8161 | /** |
| 8162 | * Attempts to find a module path from the module map specified in the |
| 8163 | * environment. If found, writes the full path into the path variable. |
| 8164 | * |
| 8165 | * The module map is a string in environment variable WESTON_MODULE_MAP, where |
| 8166 | * each entry is of the form "name=path" and entries are separated by |
| 8167 | * semicolons. Whitespace is significant. |
| 8168 | * |
| 8169 | * \param name The name to search for. |
| 8170 | * \param path Where the path is written to if found. |
| 8171 | * \param path_len Allocated bytes at \c path . |
| 8172 | * \returns The length of the string written to path on success, or 0 if the |
| 8173 | * module was not specified in the environment map or path_len was too small. |
| 8174 | */ |
| 8175 | WL_EXPORT size_t |
| 8176 | weston_module_path_from_env(const char *name, char *path, size_t path_len) |
| 8177 | { |
| 8178 | const char *mapping = getenv("WESTON_MODULE_MAP"); |
| 8179 | const char *end; |
| 8180 | const int name_len = strlen(name); |
| 8181 | |
| 8182 | if (!mapping) |
| 8183 | return 0; |
| 8184 | |
| 8185 | end = mapping + strlen(mapping); |
| 8186 | while (mapping < end && *mapping) { |
| 8187 | const char *filename, *next; |
| 8188 | |
| 8189 | /* early out: impossibly short string */ |
| 8190 | if (end - mapping < name_len + 1) |
| 8191 | return 0; |
| 8192 | |
| 8193 | filename = &mapping[name_len + 1]; |
| 8194 | next = strchrnul(mapping, ';'); |
| 8195 | |
| 8196 | if (strncmp(mapping, name, name_len) == 0 && |
| 8197 | mapping[name_len] == '=') { |
| 8198 | size_t file_len = next - filename; /* no trailing NUL */ |
| 8199 | if (file_len >= path_len) |
| 8200 | return 0; |
| 8201 | strncpy(path, filename, file_len); |
| 8202 | path[file_len] = '\0'; |
| 8203 | return file_len; |
| 8204 | } |
| 8205 | |
| 8206 | mapping = next + 1; |
| 8207 | } |
| 8208 | |
| 8209 | return 0; |
| 8210 | } |
| 8211 | |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 8212 | WL_EXPORT void * |
| 8213 | weston_load_module(const char *name, const char *entrypoint) |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 8214 | { |
| 8215 | char path[PATH_MAX]; |
| 8216 | void *module, *init; |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 8217 | size_t len; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 8218 | |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 8219 | if (name == NULL) |
| 8220 | return NULL; |
| 8221 | |
Derek Foreman | 3f86e50 | 2015-06-08 11:46:54 -0500 | [diff] [blame] | 8222 | if (name[0] != '/') { |
Daniel Stone | e03c111 | 2016-11-24 20:45:45 +0000 | [diff] [blame] | 8223 | len = weston_module_path_from_env(name, path, sizeof path); |
| 8224 | if (len == 0) |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 8225 | len = snprintf(path, sizeof path, "%s/%s", |
| 8226 | LIBWESTON_MODULEDIR, name); |
Derek Foreman | 3f86e50 | 2015-06-08 11:46:54 -0500 | [diff] [blame] | 8227 | } else { |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 8228 | len = snprintf(path, sizeof path, "%s", name); |
Derek Foreman | 3f86e50 | 2015-06-08 11:46:54 -0500 | [diff] [blame] | 8229 | } |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 8230 | |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 8231 | /* snprintf returns the length of the string it would've written, |
| 8232 | * _excluding_ the NUL byte. So even being equal to the size of |
| 8233 | * our buffer is an error here. */ |
| 8234 | if (len >= sizeof path) |
| 8235 | return NULL; |
| 8236 | |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 8237 | module = dlopen(path, RTLD_NOW | RTLD_NOLOAD); |
| 8238 | if (module) { |
| 8239 | weston_log("Module '%s' already loaded\n", path); |
Pekka Paalanen | f696ee9 | 2019-11-04 14:07:51 +0200 | [diff] [blame] | 8240 | } else { |
| 8241 | weston_log("Loading module '%s'\n", path); |
| 8242 | module = dlopen(path, RTLD_NOW); |
| 8243 | if (!module) { |
| 8244 | weston_log("Failed to load module: %s\n", dlerror()); |
| 8245 | return NULL; |
| 8246 | } |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 8247 | } |
| 8248 | |
| 8249 | init = dlsym(module, entrypoint); |
| 8250 | if (!init) { |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 8251 | weston_log("Failed to lookup init function: %s\n", dlerror()); |
Rob Bradford | c9e64ab | 2012-12-05 18:47:10 +0000 | [diff] [blame] | 8252 | dlclose(module); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 8253 | return NULL; |
| 8254 | } |
| 8255 | |
| 8256 | return init; |
| 8257 | } |
| 8258 | |
Pekka Paalanen | 6ffbba3 | 2019-11-06 12:59:32 +0200 | [diff] [blame] | 8259 | /** Add a compositor destroy listener only once |
| 8260 | * |
| 8261 | * \param compositor The compositor whose destroy to watch for. |
| 8262 | * \param listener The listener struct to initialize. |
| 8263 | * \param destroy_handler The callback when compositor is destroyed. |
| 8264 | * \return True if listener is added, or false if there already is a listener |
| 8265 | * with the given \c destroy_handler. |
| 8266 | * |
| 8267 | * This function does nothing and returns false if the given callback function |
| 8268 | * is already present in the weston_compositor destroy callbacks list. |
| 8269 | * Otherwise, this function initializes the given listener with the given |
| 8270 | * callback pointer and adds it to the compositor's destroy callbacks list. |
| 8271 | * |
| 8272 | * This can be used to ensure that plugin initialization is done only once |
| 8273 | * in case the same plugin is loaded multiple times. If this function returns |
| 8274 | * false, the plugin should be already initialized successfully. |
| 8275 | * |
| 8276 | * All plugins should register a destroy listener for cleaning up. Note, that |
| 8277 | * the plugin destruction order is not guaranteed: plugins that depend on other |
| 8278 | * plugins must be able to be torn down in arbitrary order. |
| 8279 | * |
Leandro Ribeiro | ca640d5 | 2020-01-27 19:12:01 -0300 | [diff] [blame] | 8280 | * \sa weston_compositor_destroy |
Pekka Paalanen | 6ffbba3 | 2019-11-06 12:59:32 +0200 | [diff] [blame] | 8281 | */ |
| 8282 | WL_EXPORT bool |
| 8283 | weston_compositor_add_destroy_listener_once(struct weston_compositor *compositor, |
| 8284 | struct wl_listener *listener, |
| 8285 | wl_notify_func_t destroy_handler) |
| 8286 | { |
| 8287 | if (wl_signal_get(&compositor->destroy_signal, destroy_handler)) |
| 8288 | return false; |
| 8289 | |
| 8290 | listener->notify = destroy_handler; |
| 8291 | wl_signal_add(&compositor->destroy_signal, listener); |
| 8292 | return true; |
| 8293 | } |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 8294 | |
Leandro Ribeiro | ca640d5 | 2020-01-27 19:12:01 -0300 | [diff] [blame] | 8295 | /** Destroys the compositor. |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 8296 | * |
Leandro Ribeiro | ca640d5 | 2020-01-27 19:12:01 -0300 | [diff] [blame] | 8297 | * This function cleans up the compositor state and then destroys it. |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 8298 | * |
Leandro Ribeiro | ca640d5 | 2020-01-27 19:12:01 -0300 | [diff] [blame] | 8299 | * @param compositor The compositor to be destroyed. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 8300 | * |
Marius Vlad | 284d534 | 2019-06-24 12:00:47 +0300 | [diff] [blame] | 8301 | * @ingroup compositor |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 8302 | */ |
| 8303 | WL_EXPORT void |
Leandro Ribeiro | ca640d5 | 2020-01-27 19:12:01 -0300 | [diff] [blame] | 8304 | weston_compositor_destroy(struct weston_compositor *compositor) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 8305 | { |
| 8306 | /* prevent further rendering while shutting down */ |
| 8307 | compositor->state = WESTON_COMPOSITOR_OFFSCREEN; |
| 8308 | |
Marius Vlad | f2452d6 | 2021-12-09 14:07:21 +0200 | [diff] [blame] | 8309 | weston_signal_emit_mutable(&compositor->destroy_signal, compositor); |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 8310 | |
| 8311 | weston_compositor_xkb_destroy(compositor); |
| 8312 | |
Giulio Camuffo | 2d24e64 | 2015-10-03 16:25:15 +0300 | [diff] [blame] | 8313 | if (compositor->backend) |
| 8314 | compositor->backend->destroy(compositor); |
Pekka Paalanen | 827b5d2 | 2016-06-29 11:54:26 +0200 | [diff] [blame] | 8315 | |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 8316 | /* The backend is responsible for destroying the heads. */ |
| 8317 | assert(wl_list_empty(&compositor->head_list)); |
| 8318 | |
Pekka Paalanen | 827b5d2 | 2016-06-29 11:54:26 +0200 | [diff] [blame] | 8319 | weston_plugin_api_destroy_list(compositor); |
| 8320 | |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 8321 | if (compositor->heads_changed_source) |
| 8322 | wl_event_source_remove(compositor->heads_changed_source); |
| 8323 | |
Leandro Ribeiro | f014964 | 2019-12-18 15:52:18 -0300 | [diff] [blame] | 8324 | weston_log_scope_destroy(compositor->debug_scene); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 8325 | compositor->debug_scene = NULL; |
Marius Vlad | da104eb | 2019-09-05 14:31:01 +0300 | [diff] [blame] | 8326 | |
Leandro Ribeiro | f014964 | 2019-12-18 15:52:18 -0300 | [diff] [blame] | 8327 | weston_log_scope_destroy(compositor->timeline); |
Marius Vlad | da104eb | 2019-09-05 14:31:01 +0300 | [diff] [blame] | 8328 | compositor->timeline = NULL; |
Pekka Paalanen | a5630ea | 2017-10-12 13:13:42 +0200 | [diff] [blame] | 8329 | |
Leandro Ribeiro | 8eb8414 | 2021-01-18 19:36:48 -0300 | [diff] [blame] | 8330 | if (compositor->default_dmabuf_feedback) { |
| 8331 | weston_dmabuf_feedback_destroy(compositor->default_dmabuf_feedback); |
| 8332 | weston_dmabuf_feedback_format_table_destroy(compositor->dmabuf_feedback_format_table); |
| 8333 | } |
| 8334 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 8335 | free(compositor); |
| 8336 | } |
| 8337 | |
| 8338 | /** Instruct the compositor to exit. |
| 8339 | * |
| 8340 | * This functions does not directly destroy the compositor object, it merely |
| 8341 | * command it to start the tear down process. It is not guaranteed that the |
| 8342 | * tear down will happen immediately. |
| 8343 | * |
| 8344 | * \param compositor The compositor to tear down. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 8345 | * |
| 8346 | * \ingroup compositor |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 8347 | */ |
| 8348 | WL_EXPORT void |
| 8349 | weston_compositor_exit(struct weston_compositor *compositor) |
| 8350 | { |
| 8351 | compositor->exit(compositor); |
| 8352 | } |
| 8353 | |
| 8354 | /** Return the user data stored in the compositor. |
| 8355 | * |
| 8356 | * This function returns the user data pointer set with user_data parameter |
| 8357 | * to the \ref weston_compositor_create function. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 8358 | * |
| 8359 | * \ingroup compositor |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 8360 | */ |
| 8361 | WL_EXPORT void * |
| 8362 | weston_compositor_get_user_data(struct weston_compositor *compositor) |
| 8363 | { |
| 8364 | return compositor->user_data; |
| 8365 | } |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 8366 | |
Pekka Paalanen | 50dbf38 | 2016-06-03 15:23:46 +0300 | [diff] [blame] | 8367 | static const char * const backend_map[] = { |
| 8368 | [WESTON_BACKEND_DRM] = "drm-backend.so", |
| 8369 | [WESTON_BACKEND_FBDEV] = "fbdev-backend.so", |
| 8370 | [WESTON_BACKEND_HEADLESS] = "headless-backend.so", |
| 8371 | [WESTON_BACKEND_RDP] = "rdp-backend.so", |
| 8372 | [WESTON_BACKEND_WAYLAND] = "wayland-backend.so", |
| 8373 | [WESTON_BACKEND_X11] = "x11-backend.so", |
| 8374 | }; |
| 8375 | |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 8376 | /** Load a backend into a weston_compositor |
| 8377 | * |
| 8378 | * A backend must be loaded to make a weston_compositor work. A backend |
| 8379 | * provides input and output capabilities, and determines the renderer to use. |
| 8380 | * |
| 8381 | * \param compositor A compositor that has not had a backend loaded yet. |
| 8382 | * \param backend Name of the backend file. |
| 8383 | * \param config_base A pointer to a backend-specific configuration |
| 8384 | * structure's 'base' member. |
| 8385 | * |
| 8386 | * \return 0 on success, or -1 on error. |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 8387 | * |
| 8388 | * \ingroup compositor |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 8389 | */ |
| 8390 | WL_EXPORT int |
| 8391 | weston_compositor_load_backend(struct weston_compositor *compositor, |
Pekka Paalanen | 50dbf38 | 2016-06-03 15:23:46 +0300 | [diff] [blame] | 8392 | enum weston_compositor_backend backend, |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 8393 | struct weston_backend_config *config_base) |
| 8394 | { |
| 8395 | int (*backend_init)(struct weston_compositor *c, |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 8396 | struct weston_backend_config *config_base); |
| 8397 | |
Pekka Paalanen | d7e3511 | 2017-08-29 17:04:12 +0300 | [diff] [blame] | 8398 | if (compositor->backend) { |
| 8399 | weston_log("Error: attempt to load a backend when one is already loaded\n"); |
| 8400 | return -1; |
| 8401 | } |
| 8402 | |
Quentin Glidic | 887c018 | 2016-07-10 11:00:53 +0200 | [diff] [blame] | 8403 | if (backend >= ARRAY_LENGTH(backend_map)) |
Pekka Paalanen | 50dbf38 | 2016-06-03 15:23:46 +0300 | [diff] [blame] | 8404 | return -1; |
| 8405 | |
Quentin Glidic | 23e1d6f | 2016-12-02 14:08:44 +0100 | [diff] [blame] | 8406 | backend_init = weston_load_module(backend_map[backend], "weston_backend_init"); |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 8407 | if (!backend_init) |
| 8408 | return -1; |
| 8409 | |
Pekka Paalanen | d7e3511 | 2017-08-29 17:04:12 +0300 | [diff] [blame] | 8410 | if (backend_init(compositor, config_base) < 0) { |
| 8411 | compositor->backend = NULL; |
| 8412 | return -1; |
| 8413 | } |
| 8414 | |
Pekka Paalanen | 90a5ffa | 2021-02-25 12:03:28 +0200 | [diff] [blame] | 8415 | if (!compositor->color_manager) { |
| 8416 | compositor->color_manager = |
| 8417 | weston_color_manager_noop_create(compositor); |
| 8418 | } |
| 8419 | |
| 8420 | if (!compositor->color_manager) |
| 8421 | return -1; |
| 8422 | |
| 8423 | if (!compositor->color_manager->init(compositor->color_manager)) |
| 8424 | return -1; |
| 8425 | |
| 8426 | weston_log("Color manager: %s\n", compositor->color_manager->name); |
| 8427 | |
Pekka Paalanen | d7e3511 | 2017-08-29 17:04:12 +0300 | [diff] [blame] | 8428 | return 0; |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 8429 | } |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 8430 | |
Marius Vlad | 9fdda7f | 2019-06-11 16:08:55 +0300 | [diff] [blame] | 8431 | /** weston_compositor_load_xwayland |
| 8432 | * \ingroup compositor |
| 8433 | */ |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 8434 | WL_EXPORT int |
| 8435 | weston_compositor_load_xwayland(struct weston_compositor *compositor) |
| 8436 | { |
Quentin Glidic | 3d7ca3b | 2016-12-02 14:20:35 +0100 | [diff] [blame] | 8437 | int (*module_init)(struct weston_compositor *ec); |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 8438 | |
Quentin Glidic | 3d7ca3b | 2016-12-02 14:20:35 +0100 | [diff] [blame] | 8439 | module_init = weston_load_module("xwayland.so", "weston_module_init"); |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 8440 | if (!module_init) |
| 8441 | return -1; |
Quentin Glidic | 3d7ca3b | 2016-12-02 14:20:35 +0100 | [diff] [blame] | 8442 | if (module_init(compositor) < 0) |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 8443 | return -1; |
| 8444 | return 0; |
| 8445 | } |
Vasilis Liaskovitis | 486b463 | 2018-10-10 16:14:55 +0200 | [diff] [blame] | 8446 | |
Pekka Paalanen | 5e79dd4 | 2021-03-29 14:11:49 +0300 | [diff] [blame] | 8447 | /** Load Little CMS color manager plugin |
| 8448 | * |
| 8449 | * Calling this function before loading any backend sets Little CMS |
| 8450 | * as the active color matching module (CMM) instead of the default no-op |
| 8451 | * color manager. |
| 8452 | * |
| 8453 | * \ingroup compositor |
| 8454 | */ |
| 8455 | WL_EXPORT int |
| 8456 | weston_compositor_load_color_manager(struct weston_compositor *compositor) |
| 8457 | { |
| 8458 | struct weston_color_manager * |
| 8459 | (*cm_create)(struct weston_compositor *compositor); |
| 8460 | |
| 8461 | if (compositor->color_manager) { |
| 8462 | weston_log("Error: Color manager '%s' is loaded, cannot load another.\n", |
| 8463 | compositor->color_manager->name); |
| 8464 | return -1; |
| 8465 | } |
| 8466 | |
| 8467 | cm_create = weston_load_module("color-lcms.so", "weston_color_manager_create"); |
| 8468 | if (!cm_create) { |
| 8469 | weston_log("Error: Could not load color-lcms.so.\n"); |
| 8470 | return -1; |
| 8471 | } |
| 8472 | |
| 8473 | compositor->color_manager = cm_create(compositor); |
| 8474 | if (!compositor->color_manager) { |
| 8475 | weston_log("Error: loading color-lcms.so failed.\n"); |
| 8476 | return -1; |
| 8477 | } |
| 8478 | |
| 8479 | return 0; |
| 8480 | } |
| 8481 | |
Vasilis Liaskovitis | 486b463 | 2018-10-10 16:14:55 +0200 | [diff] [blame] | 8482 | /** Resolve an internal compositor error by disconnecting the client. |
| 8483 | * |
| 8484 | * This function is used in cases when the wl_buffer turns out |
| 8485 | * unusable and there is no fallback path. |
| 8486 | * |
| 8487 | * It is possible the fault is caused by a compositor bug, the underlying |
| 8488 | * graphics stack bug or normal behaviour, or perhaps a client mistake. |
| 8489 | * In any case, the options are to either composite garbage or nothing, |
| 8490 | * or disconnect the client. This is a helper function for the latter. |
| 8491 | * |
| 8492 | * The error is sent as an INVALID_OBJECT error on the client's wl_display. |
| 8493 | * |
| 8494 | * \param buffer The weston buffer that is unusable. |
| 8495 | * \param msg A custom error message attached to the protocol error. |
| 8496 | */ |
| 8497 | WL_EXPORT void |
| 8498 | weston_buffer_send_server_error(struct weston_buffer *buffer, |
| 8499 | const char *msg) |
| 8500 | { |
| 8501 | struct wl_client *client; |
| 8502 | struct wl_resource *display_resource; |
| 8503 | uint32_t id; |
| 8504 | |
| 8505 | assert(buffer->resource); |
| 8506 | id = wl_resource_get_id(buffer->resource); |
| 8507 | client = wl_resource_get_client(buffer->resource); |
| 8508 | display_resource = wl_client_get_object(client, 1); |
| 8509 | |
| 8510 | assert(display_resource); |
| 8511 | wl_resource_post_error(display_resource, |
| 8512 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 8513 | "server error with " |
| 8514 | "wl_buffer@%u: %s", id, msg); |
| 8515 | } |
Ankit Nautiyal | 93dde24 | 2019-07-08 11:46:42 +0530 | [diff] [blame] | 8516 | |
| 8517 | WL_EXPORT void |
| 8518 | weston_output_disable_planes_incr(struct weston_output *output) |
| 8519 | { |
| 8520 | output->disable_planes++; |
Ankit Nautiyal | 4fd3813 | 2019-07-08 15:12:19 +0530 | [diff] [blame] | 8521 | /* |
| 8522 | * If disable_planes changes from 0 to non-zero, it means some type of |
| 8523 | * recording of content has started, and therefore protection level of |
| 8524 | * the protected surfaces must be updated to avoid the recording of |
| 8525 | * the protected content. |
| 8526 | */ |
| 8527 | if (output->disable_planes == 1) |
| 8528 | weston_schedule_surface_protection_update(output->compositor); |
Ankit Nautiyal | 93dde24 | 2019-07-08 11:46:42 +0530 | [diff] [blame] | 8529 | } |
| 8530 | |
| 8531 | WL_EXPORT void |
| 8532 | weston_output_disable_planes_decr(struct weston_output *output) |
| 8533 | { |
| 8534 | output->disable_planes--; |
Ankit Nautiyal | 4fd3813 | 2019-07-08 15:12:19 +0530 | [diff] [blame] | 8535 | /* |
| 8536 | * If disable_planes changes from non-zero to 0, it means no content |
| 8537 | * recording is going on any more, and the protected and surfaces can be |
| 8538 | * shown without any apprehensions about content being recorded. |
| 8539 | */ |
| 8540 | if (output->disable_planes == 0) |
| 8541 | weston_schedule_surface_protection_update(output->compositor); |
| 8542 | |
Ankit Nautiyal | 93dde24 | 2019-07-08 11:46:42 +0530 | [diff] [blame] | 8543 | } |