Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 1 | /* |
Kristian Høgsberg | 96aa7da | 2011-09-15 15:43:14 -0400 | [diff] [blame] | 2 | * Copyright © 2010-2011 Intel Corporation |
| 3 | * Copyright © 2008-2011 Kristian Høgsberg |
Pekka Paalanen | 925788f | 2018-04-19 14:20:01 +0300 | [diff] [blame] | 4 | * Copyright © 2012-2018 Collabora, Ltd. |
| 5 | * Copyright © 2017, 2018 General Electric Company |
Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 6 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 7 | * Permission is hereby granted, free of charge, to any person obtaining |
| 8 | * a copy of this software and associated documentation files (the |
| 9 | * "Software"), to deal in the Software without restriction, including |
| 10 | * without limitation the rights to use, copy, modify, merge, publish, |
| 11 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 12 | * permit persons to whom the Software is furnished to do so, subject to |
| 13 | * the following conditions: |
Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 14 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 15 | * The above copyright notice and this permission notice (including the |
| 16 | * next paragraph) shall be included in all copies or substantial |
| 17 | * portions of the Software. |
| 18 | * |
| 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 20 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 22 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 23 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 24 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 25 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 26 | * SOFTWARE. |
Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 27 | */ |
| 28 | |
Kristian Høgsberg | a941022 | 2011-01-14 17:22:35 -0500 | [diff] [blame] | 29 | #include "config.h" |
| 30 | |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 31 | #include <fcntl.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 32 | #include <stdio.h> |
| 33 | #include <string.h> |
| 34 | #include <stdlib.h> |
| 35 | #include <stdint.h> |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 36 | #include <limits.h> |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 37 | #include <stdarg.h> |
Benjamin Franzke | 6f5fc69 | 2011-06-21 19:34:19 +0200 | [diff] [blame] | 38 | #include <assert.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 39 | #include <sys/ioctl.h> |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 40 | #include <sys/mman.h> |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 41 | #include <sys/wait.h> |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 42 | #include <sys/socket.h> |
Martin Minarik | f12c287 | 2012-06-11 00:57:39 +0200 | [diff] [blame] | 43 | #include <sys/utsname.h> |
Martin Minarik | 37032f8 | 2012-06-18 20:15:18 +0200 | [diff] [blame] | 44 | #include <sys/stat.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 45 | #include <unistd.h> |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 46 | #include <math.h> |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 47 | #include <linux/input.h> |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 48 | #include <dlfcn.h> |
Kristian Høgsberg | 8544903 | 2011-05-02 12:11:07 -0400 | [diff] [blame] | 49 | #include <signal.h> |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 50 | #include <setjmp.h> |
Kristian Høgsberg | a411c8b | 2012-06-08 16:16:52 -0400 | [diff] [blame] | 51 | #include <sys/time.h> |
| 52 | #include <time.h> |
Pekka Paalanen | 23ade62 | 2014-08-27 13:31:26 +0300 | [diff] [blame] | 53 | #include <errno.h> |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 54 | #include <inttypes.h> |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 55 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 56 | #include "timeline.h" |
| 57 | |
Pekka Paalanen | 3d5d947 | 2019-03-28 16:28:47 +0200 | [diff] [blame] | 58 | #include <libweston/libweston.h> |
Marius Vlad | f4f4c2b | 2019-04-29 13:27:47 +0300 | [diff] [blame] | 59 | #include <libweston/weston-debug.h> |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 60 | #include "linux-dmabuf.h" |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 61 | #include "viewporter-server-protocol.h" |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 62 | #include "presentation-time-server-protocol.h" |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 63 | #include "linux-explicit-synchronization-unstable-v1-server-protocol.h" |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 64 | #include "linux-explicit-synchronization.h" |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 65 | #include "shared/fd-util.h" |
Jon Cruz | 35b2eaa | 2015-06-15 15:37:08 -0700 | [diff] [blame] | 66 | #include "shared/helpers.h" |
Jon Cruz | 4678bab | 2015-06-15 15:37:07 -0700 | [diff] [blame] | 67 | #include "shared/os-compatibility.h" |
Bryce Harrington | 25a2bdd | 2016-08-03 17:40:52 -0700 | [diff] [blame] | 68 | #include "shared/string-helpers.h" |
Pekka Paalanen | aa21f62 | 2015-07-03 15:44:50 +0300 | [diff] [blame] | 69 | #include "shared/timespec-util.h" |
Kristian Høgsberg | a411c8b | 2012-06-08 16:16:52 -0400 | [diff] [blame] | 70 | #include "git-version.h" |
Pekka Paalanen | cda1488 | 2019-04-04 15:41:02 +0300 | [diff] [blame] | 71 | #include <libweston/version.h> |
Pekka Paalanen | 27b377f | 2019-03-29 17:07:34 +0200 | [diff] [blame] | 72 | #include <libweston/plugin-registry.h> |
Marius Vlad | 00a6e01 | 2018-11-20 17:52:31 +0200 | [diff] [blame] | 73 | #include "pixel-formats.h" |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 74 | |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 75 | /** |
| 76 | * \defgroup head Head |
| 77 | * \defgroup output Output |
| 78 | * \defgroup compositor Compositor |
| 79 | */ |
| 80 | |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 81 | #define DEFAULT_REPAINT_WINDOW 7 /* milliseconds */ |
| 82 | |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 83 | static void |
Pekka Paalanen | d72bad2 | 2017-03-29 17:01:41 +0300 | [diff] [blame] | 84 | weston_output_update_matrix(struct weston_output *output); |
| 85 | |
| 86 | static void |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 87 | weston_output_transform_scale_init(struct weston_output *output, |
| 88 | uint32_t transform, uint32_t scale); |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 89 | |
Rob Bradford | 27b1793 | 2013-06-26 18:08:46 +0100 | [diff] [blame] | 90 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 91 | weston_compositor_build_view_list(struct weston_compositor *compositor); |
Rob Bradford | 27b1793 | 2013-06-26 18:08:46 +0100 | [diff] [blame] | 92 | |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 93 | static char * |
| 94 | weston_output_create_heads_string(struct weston_output *output); |
| 95 | |
Pekka Paalanen | 6528c03 | 2017-03-28 15:27:10 +0300 | [diff] [blame] | 96 | /** Send wl_output events for mode and scale changes |
| 97 | * |
| 98 | * \param head Send on all resources bound to this head. |
| 99 | * \param mode_changed If true, send the current mode. |
| 100 | * \param scale_changed If true, send the current scale. |
| 101 | */ |
| 102 | static void |
| 103 | weston_mode_switch_send_events(struct weston_head *head, |
| 104 | bool mode_changed, bool scale_changed) |
| 105 | { |
| 106 | struct weston_output *output = head->output; |
| 107 | struct wl_resource *resource; |
| 108 | int version; |
| 109 | |
| 110 | wl_resource_for_each(resource, &head->resource_list) { |
| 111 | if (mode_changed) { |
| 112 | wl_output_send_mode(resource, |
| 113 | output->current_mode->flags, |
| 114 | output->current_mode->width, |
| 115 | output->current_mode->height, |
| 116 | output->current_mode->refresh); |
| 117 | } |
| 118 | |
| 119 | version = wl_resource_get_version(resource); |
| 120 | if (version >= WL_OUTPUT_SCALE_SINCE_VERSION && scale_changed) |
| 121 | wl_output_send_scale(resource, output->current_scale); |
| 122 | |
| 123 | if (version >= WL_OUTPUT_DONE_SINCE_VERSION) |
| 124 | wl_output_send_done(resource); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | static void |
| 129 | weston_mode_switch_finish(struct weston_output *output, |
| 130 | int mode_changed, int scale_changed) |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 131 | { |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 132 | struct weston_seat *seat; |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 133 | struct weston_head *head; |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 134 | pixman_region32_t old_output_region; |
Alexander Larsson | 355748e | 2013-05-28 16:23:38 +0200 | [diff] [blame] | 135 | |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 136 | pixman_region32_init(&old_output_region); |
| 137 | pixman_region32_copy(&old_output_region, &output->region); |
| 138 | |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 139 | /* Update output region and transformation matrix */ |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 140 | 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] | 141 | |
| 142 | pixman_region32_init(&output->previous_damage); |
| 143 | pixman_region32_init_rect(&output->region, output->x, output->y, |
| 144 | output->width, output->height); |
| 145 | |
| 146 | weston_output_update_matrix(output); |
| 147 | |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 148 | /* If a pointer falls outside the outputs new geometry, move it to its |
| 149 | * lower-right corner */ |
| 150 | wl_list_for_each(seat, &output->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 151 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 152 | int32_t x, y; |
| 153 | |
| 154 | if (!pointer) |
| 155 | continue; |
| 156 | |
| 157 | x = wl_fixed_to_int(pointer->x); |
| 158 | y = wl_fixed_to_int(pointer->y); |
| 159 | |
| 160 | if (!pixman_region32_contains_point(&old_output_region, |
| 161 | x, y, NULL) || |
| 162 | pixman_region32_contains_point(&output->region, |
| 163 | x, y, NULL)) |
| 164 | continue; |
| 165 | |
| 166 | if (x >= output->x + output->width) |
| 167 | x = output->x + output->width - 1; |
| 168 | if (y >= output->y + output->height) |
| 169 | y = output->y + output->height - 1; |
| 170 | |
| 171 | pointer->x = wl_fixed_from_int(x); |
| 172 | pointer->y = wl_fixed_from_int(y); |
| 173 | } |
| 174 | |
| 175 | pixman_region32_fini(&old_output_region); |
| 176 | |
Derek Foreman | dd4cd33 | 2014-11-10 10:29:59 -0600 | [diff] [blame] | 177 | if (!mode_changed && !scale_changed) |
| 178 | return; |
| 179 | |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 180 | /* notify clients of the changes */ |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 181 | wl_list_for_each(head, &output->head_list, output_link) |
| 182 | weston_mode_switch_send_events(head, |
| 183 | mode_changed, scale_changed); |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 184 | } |
| 185 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 186 | static void |
| 187 | weston_compositor_reflow_outputs(struct weston_compositor *compositor, |
| 188 | struct weston_output *resized_output, int delta_width); |
| 189 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame^] | 190 | /** |
| 191 | * \ingroup output |
| 192 | */ |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 193 | WL_EXPORT int |
| 194 | weston_output_mode_set_native(struct weston_output *output, |
| 195 | struct weston_mode *mode, |
| 196 | int32_t scale) |
| 197 | { |
| 198 | int ret; |
| 199 | int mode_changed = 0, scale_changed = 0; |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 200 | int32_t old_width; |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 201 | |
| 202 | if (!output->switch_mode) |
| 203 | return -1; |
| 204 | |
| 205 | if (!output->original_mode) { |
| 206 | mode_changed = 1; |
| 207 | ret = output->switch_mode(output, mode); |
| 208 | if (ret < 0) |
| 209 | return ret; |
| 210 | if (output->current_scale != scale) { |
| 211 | scale_changed = 1; |
| 212 | output->current_scale = scale; |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 213 | } |
| 214 | } |
| 215 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 216 | old_width = output->width; |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 217 | output->native_mode = mode; |
| 218 | output->native_scale = scale; |
| 219 | |
| 220 | weston_mode_switch_finish(output, mode_changed, scale_changed); |
| 221 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 222 | if (mode_changed || scale_changed) { |
| 223 | weston_compositor_reflow_outputs(output->compositor, output, output->width - old_width); |
| 224 | |
| 225 | wl_signal_emit(&output->compositor->output_resized_signal, output); |
| 226 | } |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 227 | return 0; |
| 228 | } |
| 229 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame^] | 230 | /** |
| 231 | * \ingroup output |
| 232 | */ |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 233 | WL_EXPORT int |
| 234 | weston_output_mode_switch_to_native(struct weston_output *output) |
| 235 | { |
| 236 | int ret; |
| 237 | int mode_changed = 0, scale_changed = 0; |
| 238 | |
| 239 | if (!output->switch_mode) |
| 240 | return -1; |
| 241 | |
| 242 | if (!output->original_mode) { |
| 243 | weston_log("already in the native mode\n"); |
| 244 | return -1; |
| 245 | } |
| 246 | /* the non fullscreen clients haven't seen a mode set since we |
| 247 | * switched into a temporary, so we need to notify them if the |
| 248 | * mode at that time is different from the native mode now. |
| 249 | */ |
| 250 | mode_changed = (output->original_mode != output->native_mode); |
| 251 | scale_changed = (output->original_scale != output->native_scale); |
| 252 | |
| 253 | ret = output->switch_mode(output, output->native_mode); |
| 254 | if (ret < 0) |
| 255 | return ret; |
| 256 | |
| 257 | output->current_scale = output->native_scale; |
| 258 | |
| 259 | output->original_mode = NULL; |
| 260 | output->original_scale = 0; |
| 261 | |
| 262 | weston_mode_switch_finish(output, mode_changed, scale_changed); |
| 263 | |
| 264 | return 0; |
| 265 | } |
| 266 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame^] | 267 | /** |
| 268 | * \ingroup output |
| 269 | */ |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 270 | WL_EXPORT int |
| 271 | weston_output_mode_switch_to_temporary(struct weston_output *output, |
| 272 | struct weston_mode *mode, |
| 273 | int32_t scale) |
| 274 | { |
| 275 | int ret; |
| 276 | |
| 277 | if (!output->switch_mode) |
| 278 | return -1; |
| 279 | |
| 280 | /* original_mode is the last mode non full screen clients have seen, |
| 281 | * so we shouldn't change it if we already have one set. |
| 282 | */ |
| 283 | if (!output->original_mode) { |
| 284 | output->original_mode = output->native_mode; |
| 285 | output->original_scale = output->native_scale; |
| 286 | } |
| 287 | ret = output->switch_mode(output, mode); |
| 288 | if (ret < 0) |
| 289 | return ret; |
| 290 | |
| 291 | output->current_scale = scale; |
| 292 | |
| 293 | weston_mode_switch_finish(output, 0, 0); |
| 294 | |
| 295 | return 0; |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 296 | } |
| 297 | |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 298 | static void |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 299 | region_init_infinite(pixman_region32_t *region) |
| 300 | { |
| 301 | pixman_region32_init_rect(region, INT32_MIN, INT32_MIN, |
| 302 | UINT32_MAX, UINT32_MAX); |
| 303 | } |
| 304 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 305 | static struct weston_subsurface * |
| 306 | weston_surface_to_subsurface(struct weston_surface *surface); |
| 307 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 308 | WL_EXPORT struct weston_view * |
| 309 | weston_view_create(struct weston_surface *surface) |
| 310 | { |
| 311 | struct weston_view *view; |
| 312 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 313 | view = zalloc(sizeof *view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 314 | if (view == NULL) |
| 315 | return NULL; |
| 316 | |
| 317 | view->surface = surface; |
Daniel Stone | fb4869d | 2016-12-09 16:27:54 +0000 | [diff] [blame] | 318 | view->plane = &surface->compositor->primary_plane; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 319 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 320 | /* Assign to surface */ |
| 321 | wl_list_insert(&surface->views, &view->surface_link); |
| 322 | |
| 323 | wl_signal_init(&view->destroy_signal); |
| 324 | wl_list_init(&view->link); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 325 | wl_list_init(&view->layer_link.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 326 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 327 | pixman_region32_init(&view->clip); |
| 328 | |
| 329 | view->alpha = 1.0; |
| 330 | pixman_region32_init(&view->transform.opaque); |
| 331 | |
| 332 | wl_list_init(&view->geometry.transformation_list); |
| 333 | wl_list_insert(&view->geometry.transformation_list, |
| 334 | &view->transform.position.link); |
| 335 | weston_matrix_init(&view->transform.position.matrix); |
| 336 | wl_list_init(&view->geometry.child_list); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 337 | pixman_region32_init(&view->geometry.scissor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 338 | pixman_region32_init(&view->transform.boundingbox); |
| 339 | view->transform.dirty = 1; |
| 340 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 341 | return view; |
| 342 | } |
| 343 | |
Jason Ekstrand | 108865d | 2014-06-26 10:04:49 -0700 | [diff] [blame] | 344 | struct weston_frame_callback { |
| 345 | struct wl_resource *resource; |
| 346 | struct wl_list link; |
| 347 | }; |
| 348 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 349 | struct weston_presentation_feedback { |
| 350 | struct wl_resource *resource; |
| 351 | |
| 352 | /* XXX: could use just wl_resource_get_link() instead */ |
| 353 | struct wl_list link; |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 354 | |
| 355 | /* The per-surface feedback flags */ |
| 356 | uint32_t psf_flags; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 357 | }; |
| 358 | |
| 359 | static void |
| 360 | weston_presentation_feedback_discard( |
| 361 | struct weston_presentation_feedback *feedback) |
| 362 | { |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 363 | wp_presentation_feedback_send_discarded(feedback->resource); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 364 | wl_resource_destroy(feedback->resource); |
| 365 | } |
| 366 | |
| 367 | static void |
| 368 | weston_presentation_feedback_discard_list(struct wl_list *list) |
| 369 | { |
| 370 | struct weston_presentation_feedback *feedback, *tmp; |
| 371 | |
| 372 | wl_list_for_each_safe(feedback, tmp, list, link) |
| 373 | weston_presentation_feedback_discard(feedback); |
| 374 | } |
| 375 | |
| 376 | static void |
| 377 | weston_presentation_feedback_present( |
| 378 | struct weston_presentation_feedback *feedback, |
| 379 | struct weston_output *output, |
| 380 | uint32_t refresh_nsec, |
| 381 | const struct timespec *ts, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 382 | uint64_t seq, |
| 383 | uint32_t flags) |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 384 | { |
| 385 | struct wl_client *client = wl_resource_get_client(feedback->resource); |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 386 | struct weston_head *head; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 387 | struct wl_resource *o; |
Alexandros Frantzis | 10d708d | 2017-12-13 13:27:54 +0200 | [diff] [blame] | 388 | uint32_t tv_sec_hi; |
| 389 | uint32_t tv_sec_lo; |
| 390 | uint32_t tv_nsec; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 391 | bool done = false; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 392 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 393 | wl_list_for_each(head, &output->head_list, output_link) { |
| 394 | wl_resource_for_each(o, &head->resource_list) { |
| 395 | if (wl_resource_get_client(o) != client) |
| 396 | continue; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 397 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 398 | wp_presentation_feedback_send_sync_output(feedback->resource, o); |
| 399 | done = true; |
| 400 | } |
| 401 | |
| 402 | /* For clone mode, send it for just one wl_output global, |
| 403 | * they are all equivalent anyway. |
| 404 | */ |
| 405 | if (done) |
| 406 | break; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 407 | } |
| 408 | |
Alexandros Frantzis | 10d708d | 2017-12-13 13:27:54 +0200 | [diff] [blame] | 409 | timespec_to_proto(ts, &tv_sec_hi, &tv_sec_lo, &tv_nsec); |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 410 | wp_presentation_feedback_send_presented(feedback->resource, |
Alexandros Frantzis | 10d708d | 2017-12-13 13:27:54 +0200 | [diff] [blame] | 411 | tv_sec_hi, tv_sec_lo, tv_nsec, |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 412 | refresh_nsec, |
| 413 | seq >> 32, seq & 0xffffffff, |
| 414 | flags | feedback->psf_flags); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 415 | wl_resource_destroy(feedback->resource); |
| 416 | } |
| 417 | |
| 418 | static void |
| 419 | weston_presentation_feedback_present_list(struct wl_list *list, |
| 420 | struct weston_output *output, |
| 421 | uint32_t refresh_nsec, |
| 422 | const struct timespec *ts, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 423 | uint64_t seq, |
| 424 | uint32_t flags) |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 425 | { |
| 426 | struct weston_presentation_feedback *feedback, *tmp; |
| 427 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 428 | assert(!(flags & WP_PRESENTATION_FEEDBACK_INVALID) || |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 429 | wl_list_empty(list)); |
| 430 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 431 | wl_list_for_each_safe(feedback, tmp, list, link) |
| 432 | weston_presentation_feedback_present(feedback, output, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 433 | refresh_nsec, ts, seq, |
| 434 | flags); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 435 | } |
| 436 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 437 | static void |
| 438 | surface_state_handle_buffer_destroy(struct wl_listener *listener, void *data) |
| 439 | { |
| 440 | struct weston_surface_state *state = |
| 441 | container_of(listener, struct weston_surface_state, |
| 442 | buffer_destroy_listener); |
| 443 | |
| 444 | state->buffer = NULL; |
| 445 | } |
| 446 | |
| 447 | static void |
| 448 | weston_surface_state_init(struct weston_surface_state *state) |
| 449 | { |
| 450 | state->newly_attached = 0; |
| 451 | state->buffer = NULL; |
| 452 | state->buffer_destroy_listener.notify = |
| 453 | surface_state_handle_buffer_destroy; |
| 454 | state->sx = 0; |
| 455 | state->sy = 0; |
| 456 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 457 | pixman_region32_init(&state->damage_surface); |
| 458 | pixman_region32_init(&state->damage_buffer); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 459 | pixman_region32_init(&state->opaque); |
| 460 | region_init_infinite(&state->input); |
| 461 | |
| 462 | wl_list_init(&state->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 463 | wl_list_init(&state->feedback_list); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 464 | |
| 465 | state->buffer_viewport.buffer.transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 466 | state->buffer_viewport.buffer.scale = 1; |
| 467 | state->buffer_viewport.buffer.src_width = wl_fixed_from_int(-1); |
| 468 | state->buffer_viewport.surface.width = -1; |
| 469 | state->buffer_viewport.changed = 0; |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 470 | |
| 471 | state->acquire_fence_fd = -1; |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | static void |
| 475 | weston_surface_state_fini(struct weston_surface_state *state) |
| 476 | { |
| 477 | struct weston_frame_callback *cb, *next; |
| 478 | |
| 479 | wl_list_for_each_safe(cb, next, |
| 480 | &state->frame_callback_list, link) |
| 481 | wl_resource_destroy(cb->resource); |
| 482 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 483 | weston_presentation_feedback_discard_list(&state->feedback_list); |
| 484 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 485 | pixman_region32_fini(&state->input); |
| 486 | pixman_region32_fini(&state->opaque); |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 487 | pixman_region32_fini(&state->damage_surface); |
| 488 | pixman_region32_fini(&state->damage_buffer); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 489 | |
| 490 | if (state->buffer) |
| 491 | wl_list_remove(&state->buffer_destroy_listener.link); |
| 492 | state->buffer = NULL; |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 493 | |
| 494 | fd_clear(&state->acquire_fence_fd); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 495 | weston_buffer_release_reference(&state->buffer_release_ref, NULL); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | static void |
| 499 | weston_surface_state_set_buffer(struct weston_surface_state *state, |
| 500 | struct weston_buffer *buffer) |
| 501 | { |
| 502 | if (state->buffer == buffer) |
| 503 | return; |
| 504 | |
| 505 | if (state->buffer) |
| 506 | wl_list_remove(&state->buffer_destroy_listener.link); |
| 507 | state->buffer = buffer; |
| 508 | if (state->buffer) |
| 509 | wl_signal_add(&state->buffer->destroy_signal, |
| 510 | &state->buffer_destroy_listener); |
| 511 | } |
| 512 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 513 | WL_EXPORT struct weston_surface * |
Kristian Høgsberg | 18c9300 | 2012-01-27 11:58:31 -0500 | [diff] [blame] | 514 | weston_surface_create(struct weston_compositor *compositor) |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 515 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 516 | struct weston_surface *surface; |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 517 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 518 | surface = zalloc(sizeof *surface); |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 519 | if (surface == NULL) |
| 520 | return NULL; |
| 521 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 522 | wl_signal_init(&surface->destroy_signal); |
Jonas Ådahl | 5d9ca27 | 2016-07-22 17:48:03 +0800 | [diff] [blame] | 523 | wl_signal_init(&surface->commit_signal); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 524 | |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 525 | surface->compositor = compositor; |
Giulio Camuffo | 13b85bd | 2013-08-13 23:10:14 +0200 | [diff] [blame] | 526 | surface->ref_count = 1; |
Kristian Høgsberg | 27803c6 | 2010-06-06 22:23:21 -0400 | [diff] [blame] | 527 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 528 | surface->buffer_viewport.buffer.transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 529 | surface->buffer_viewport.buffer.scale = 1; |
Pekka Paalanen | f0cad48 | 2014-03-14 14:38:16 +0200 | [diff] [blame] | 530 | surface->buffer_viewport.buffer.src_width = wl_fixed_from_int(-1); |
| 531 | surface->buffer_viewport.surface.width = -1; |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 532 | |
| 533 | weston_surface_state_init(&surface->pending); |
| 534 | |
Kristian Høgsberg | 20300ba | 2011-06-23 20:29:12 -0400 | [diff] [blame] | 535 | pixman_region32_init(&surface->damage); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 536 | pixman_region32_init(&surface->opaque); |
Pekka Paalanen | 8ec4ab6 | 2012-10-10 12:49:32 +0300 | [diff] [blame] | 537 | region_init_infinite(&surface->input); |
Kristian Høgsberg | 20300ba | 2011-06-23 20:29:12 -0400 | [diff] [blame] | 538 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 539 | wl_list_init(&surface->views); |
| 540 | |
| 541 | wl_list_init(&surface->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 542 | wl_list_init(&surface->feedback_list); |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 543 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 544 | wl_list_init(&surface->subsurface_list); |
| 545 | wl_list_init(&surface->subsurface_list_pending); |
| 546 | |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 547 | weston_matrix_init(&surface->buffer_to_surface_matrix); |
| 548 | weston_matrix_init(&surface->surface_to_buffer_matrix); |
| 549 | |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 550 | wl_list_init(&surface->pointer_constraints); |
| 551 | |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 552 | surface->acquire_fence_fd = -1; |
| 553 | |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 554 | return surface; |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 555 | } |
| 556 | |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 557 | WL_EXPORT void |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 558 | weston_surface_set_color(struct weston_surface *surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 559 | float red, float green, float blue, float alpha) |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 560 | { |
John Kåre Alsaker | 878f449 | 2012-11-13 19:10:23 +0100 | [diff] [blame] | 561 | surface->compositor->renderer->surface_set_color(surface, red, green, blue, alpha); |
Philipp Zabel | 195dade | 2018-09-03 19:44:59 +0200 | [diff] [blame] | 562 | surface->is_opaque = !(alpha < 1.0); |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 563 | } |
| 564 | |
Kristian Høgsberg | e4c1a5f | 2012-06-18 13:17:32 -0400 | [diff] [blame] | 565 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 566 | weston_view_to_global_float(struct weston_view *view, |
| 567 | float sx, float sy, float *x, float *y) |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 568 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 569 | if (view->transform.enabled) { |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 570 | struct weston_vector v = { { sx, sy, 0.0f, 1.0f } }; |
| 571 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 572 | weston_matrix_transform(&view->transform.matrix, &v); |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 573 | |
| 574 | if (fabsf(v.f[3]) < 1e-6) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 575 | weston_log("warning: numerical instability in " |
Scott Moreau | 088c62e | 2013-02-11 04:45:38 -0700 | [diff] [blame] | 576 | "%s(), divisor = %g\n", __func__, |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 577 | v.f[3]); |
| 578 | *x = 0; |
| 579 | *y = 0; |
| 580 | return; |
| 581 | } |
| 582 | |
| 583 | *x = v.f[0] / v.f[3]; |
| 584 | *y = v.f[1] / v.f[3]; |
| 585 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 586 | *x = sx + view->geometry.x; |
| 587 | *y = sy + view->geometry.y; |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 588 | } |
| 589 | } |
| 590 | |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 591 | WL_EXPORT void |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 592 | weston_transformed_coord(int width, int height, |
| 593 | enum wl_output_transform transform, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 594 | int32_t scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 595 | float sx, float sy, float *bx, float *by) |
| 596 | { |
| 597 | switch (transform) { |
| 598 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 599 | default: |
| 600 | *bx = sx; |
| 601 | *by = sy; |
| 602 | break; |
| 603 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 604 | *bx = width - sx; |
| 605 | *by = sy; |
| 606 | break; |
| 607 | case WL_OUTPUT_TRANSFORM_90: |
| 608 | *bx = height - sy; |
| 609 | *by = sx; |
| 610 | break; |
| 611 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 612 | *bx = height - sy; |
| 613 | *by = width - sx; |
| 614 | break; |
| 615 | case WL_OUTPUT_TRANSFORM_180: |
| 616 | *bx = width - sx; |
| 617 | *by = height - sy; |
| 618 | break; |
| 619 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 620 | *bx = sx; |
| 621 | *by = height - sy; |
| 622 | break; |
| 623 | case WL_OUTPUT_TRANSFORM_270: |
| 624 | *bx = sy; |
| 625 | *by = width - sx; |
| 626 | break; |
| 627 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 628 | *bx = sy; |
| 629 | *by = sx; |
| 630 | break; |
| 631 | } |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 632 | |
| 633 | *bx *= scale; |
| 634 | *by *= scale; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | WL_EXPORT pixman_box32_t |
| 638 | weston_transformed_rect(int width, int height, |
| 639 | enum wl_output_transform transform, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 640 | int32_t scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 641 | pixman_box32_t rect) |
| 642 | { |
| 643 | float x1, x2, y1, y2; |
| 644 | |
| 645 | pixman_box32_t ret; |
| 646 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 647 | weston_transformed_coord(width, height, transform, scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 648 | rect.x1, rect.y1, &x1, &y1); |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 649 | weston_transformed_coord(width, height, transform, scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 650 | rect.x2, rect.y2, &x2, &y2); |
| 651 | |
| 652 | if (x1 <= x2) { |
| 653 | ret.x1 = x1; |
| 654 | ret.x2 = x2; |
| 655 | } else { |
| 656 | ret.x1 = x2; |
| 657 | ret.x2 = x1; |
| 658 | } |
| 659 | |
| 660 | if (y1 <= y2) { |
| 661 | ret.y1 = y1; |
| 662 | ret.y2 = y2; |
| 663 | } else { |
| 664 | ret.y1 = y2; |
| 665 | ret.y2 = y1; |
| 666 | } |
| 667 | |
| 668 | return ret; |
| 669 | } |
| 670 | |
Derek Foreman | bc9a61c | 2015-11-18 16:32:30 -0600 | [diff] [blame] | 671 | /** Transform a region by a matrix, restricted to axis-aligned transformations |
| 672 | * |
| 673 | * Warning: This function does not work for projective, affine, or matrices |
| 674 | * that encode arbitrary rotations. Only 90-degree step rotations are |
| 675 | * supported. |
| 676 | */ |
| 677 | WL_EXPORT void |
| 678 | weston_matrix_transform_region(pixman_region32_t *dest, |
| 679 | struct weston_matrix *matrix, |
| 680 | pixman_region32_t *src) |
| 681 | { |
| 682 | pixman_box32_t *src_rects, *dest_rects; |
| 683 | int nrects, i; |
| 684 | |
| 685 | src_rects = pixman_region32_rectangles(src, &nrects); |
| 686 | dest_rects = malloc(nrects * sizeof(*dest_rects)); |
| 687 | if (!dest_rects) |
| 688 | return; |
| 689 | |
| 690 | for (i = 0; i < nrects; i++) { |
| 691 | struct weston_vector vec1 = {{ |
| 692 | src_rects[i].x1, src_rects[i].y1, 0, 1 |
| 693 | }}; |
| 694 | weston_matrix_transform(matrix, &vec1); |
| 695 | vec1.f[0] /= vec1.f[3]; |
| 696 | vec1.f[1] /= vec1.f[3]; |
| 697 | |
| 698 | struct weston_vector vec2 = {{ |
| 699 | src_rects[i].x2, src_rects[i].y2, 0, 1 |
| 700 | }}; |
| 701 | weston_matrix_transform(matrix, &vec2); |
| 702 | vec2.f[0] /= vec2.f[3]; |
| 703 | vec2.f[1] /= vec2.f[3]; |
| 704 | |
| 705 | if (vec1.f[0] < vec2.f[0]) { |
| 706 | dest_rects[i].x1 = floor(vec1.f[0]); |
| 707 | dest_rects[i].x2 = ceil(vec2.f[0]); |
| 708 | } else { |
| 709 | dest_rects[i].x1 = floor(vec2.f[0]); |
| 710 | dest_rects[i].x2 = ceil(vec1.f[0]); |
| 711 | } |
| 712 | |
Derek Foreman | bc9a61c | 2015-11-18 16:32:30 -0600 | [diff] [blame] | 713 | if (vec1.f[1] < vec2.f[1]) { |
| 714 | dest_rects[i].y1 = floor(vec1.f[1]); |
| 715 | dest_rects[i].y2 = ceil(vec2.f[1]); |
| 716 | } else { |
| 717 | dest_rects[i].y1 = floor(vec2.f[1]); |
| 718 | dest_rects[i].y2 = ceil(vec1.f[1]); |
| 719 | } |
| 720 | } |
| 721 | |
| 722 | pixman_region32_clear(dest); |
| 723 | pixman_region32_init_rects(dest, dest_rects, nrects); |
| 724 | free(dest_rects); |
| 725 | } |
| 726 | |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 727 | WL_EXPORT void |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 728 | weston_transformed_region(int width, int height, |
| 729 | enum wl_output_transform transform, |
| 730 | int32_t scale, |
| 731 | pixman_region32_t *src, pixman_region32_t *dest) |
| 732 | { |
| 733 | pixman_box32_t *src_rects, *dest_rects; |
| 734 | int nrects, i; |
| 735 | |
| 736 | if (transform == WL_OUTPUT_TRANSFORM_NORMAL && scale == 1) { |
| 737 | if (src != dest) |
| 738 | pixman_region32_copy(dest, src); |
| 739 | return; |
| 740 | } |
| 741 | |
| 742 | src_rects = pixman_region32_rectangles(src, &nrects); |
| 743 | dest_rects = malloc(nrects * sizeof(*dest_rects)); |
| 744 | if (!dest_rects) |
| 745 | return; |
| 746 | |
| 747 | if (transform == WL_OUTPUT_TRANSFORM_NORMAL) { |
| 748 | memcpy(dest_rects, src_rects, nrects * sizeof(*dest_rects)); |
| 749 | } else { |
| 750 | for (i = 0; i < nrects; i++) { |
| 751 | switch (transform) { |
| 752 | default: |
| 753 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 754 | dest_rects[i].x1 = src_rects[i].x1; |
| 755 | dest_rects[i].y1 = src_rects[i].y1; |
| 756 | dest_rects[i].x2 = src_rects[i].x2; |
| 757 | dest_rects[i].y2 = src_rects[i].y2; |
| 758 | break; |
| 759 | case WL_OUTPUT_TRANSFORM_90: |
| 760 | dest_rects[i].x1 = height - src_rects[i].y2; |
| 761 | dest_rects[i].y1 = src_rects[i].x1; |
| 762 | dest_rects[i].x2 = height - src_rects[i].y1; |
| 763 | dest_rects[i].y2 = src_rects[i].x2; |
| 764 | break; |
| 765 | case WL_OUTPUT_TRANSFORM_180: |
| 766 | dest_rects[i].x1 = width - src_rects[i].x2; |
| 767 | dest_rects[i].y1 = height - src_rects[i].y2; |
| 768 | dest_rects[i].x2 = width - src_rects[i].x1; |
| 769 | dest_rects[i].y2 = height - src_rects[i].y1; |
| 770 | break; |
| 771 | case WL_OUTPUT_TRANSFORM_270: |
| 772 | dest_rects[i].x1 = src_rects[i].y1; |
| 773 | dest_rects[i].y1 = width - src_rects[i].x2; |
| 774 | dest_rects[i].x2 = src_rects[i].y2; |
| 775 | dest_rects[i].y2 = width - src_rects[i].x1; |
| 776 | break; |
| 777 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 778 | dest_rects[i].x1 = width - src_rects[i].x2; |
| 779 | dest_rects[i].y1 = src_rects[i].y1; |
| 780 | dest_rects[i].x2 = width - src_rects[i].x1; |
| 781 | dest_rects[i].y2 = src_rects[i].y2; |
| 782 | break; |
| 783 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 784 | dest_rects[i].x1 = height - src_rects[i].y2; |
| 785 | dest_rects[i].y1 = width - src_rects[i].x2; |
| 786 | dest_rects[i].x2 = height - src_rects[i].y1; |
| 787 | dest_rects[i].y2 = width - src_rects[i].x1; |
| 788 | break; |
| 789 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 790 | dest_rects[i].x1 = src_rects[i].x1; |
| 791 | dest_rects[i].y1 = height - src_rects[i].y2; |
| 792 | dest_rects[i].x2 = src_rects[i].x2; |
| 793 | dest_rects[i].y2 = height - src_rects[i].y1; |
| 794 | break; |
| 795 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 796 | dest_rects[i].x1 = src_rects[i].y1; |
| 797 | dest_rects[i].y1 = src_rects[i].x1; |
| 798 | dest_rects[i].x2 = src_rects[i].y2; |
| 799 | dest_rects[i].y2 = src_rects[i].x2; |
| 800 | break; |
| 801 | } |
| 802 | } |
| 803 | } |
| 804 | |
| 805 | if (scale != 1) { |
| 806 | for (i = 0; i < nrects; i++) { |
| 807 | dest_rects[i].x1 *= scale; |
| 808 | dest_rects[i].x2 *= scale; |
| 809 | dest_rects[i].y1 *= scale; |
| 810 | dest_rects[i].y2 *= scale; |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | pixman_region32_clear(dest); |
| 815 | pixman_region32_init_rects(dest, dest_rects, nrects); |
| 816 | free(dest_rects); |
| 817 | } |
| 818 | |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 819 | static void |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 820 | viewport_surface_to_buffer(struct weston_surface *surface, |
| 821 | float sx, float sy, float *bx, float *by) |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 822 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 823 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 824 | double src_width, src_height; |
| 825 | double src_x, src_y; |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 826 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 827 | if (vp->buffer.src_width == wl_fixed_from_int(-1)) { |
| 828 | if (vp->surface.width == -1) { |
| 829 | *bx = sx; |
| 830 | *by = sy; |
| 831 | return; |
| 832 | } |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 833 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 834 | src_x = 0.0; |
| 835 | src_y = 0.0; |
| 836 | src_width = surface->width_from_buffer; |
| 837 | src_height = surface->height_from_buffer; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 838 | } else { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 839 | src_x = wl_fixed_to_double(vp->buffer.src_x); |
| 840 | src_y = wl_fixed_to_double(vp->buffer.src_y); |
| 841 | src_width = wl_fixed_to_double(vp->buffer.src_width); |
| 842 | src_height = wl_fixed_to_double(vp->buffer.src_height); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 843 | } |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 844 | |
| 845 | *bx = sx * src_width / surface->width + src_x; |
| 846 | *by = sy * src_height / surface->height + src_y; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 847 | } |
| 848 | |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 849 | WL_EXPORT void |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 850 | weston_surface_to_buffer_float(struct weston_surface *surface, |
| 851 | float sx, float sy, float *bx, float *by) |
| 852 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 853 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
| 854 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 855 | /* first transform coordinates if the viewport is set */ |
| 856 | viewport_surface_to_buffer(surface, sx, sy, bx, by); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 857 | |
Jason Ekstrand | d0cebc3 | 2014-04-21 20:56:46 -0500 | [diff] [blame] | 858 | weston_transformed_coord(surface->width_from_buffer, |
| 859 | surface->height_from_buffer, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 860 | vp->buffer.transform, vp->buffer.scale, |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 861 | *bx, *by, bx, by); |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 862 | } |
| 863 | |
Derek Foreman | 9973967 | 2015-12-03 16:38:11 -0600 | [diff] [blame] | 864 | /** Transform a rectangle from surface coordinates to buffer coordinates |
| 865 | * |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 866 | * \param surface The surface to fetch wp_viewport and buffer transformation |
Derek Foreman | 9973967 | 2015-12-03 16:38:11 -0600 | [diff] [blame] | 867 | * from. |
| 868 | * \param rect The rectangle to transform. |
| 869 | * \return The transformed rectangle. |
| 870 | * |
| 871 | * Viewport and buffer transformations can only do translation, scaling, |
| 872 | * and rotations in 90-degree steps. Therefore the only loss in the |
| 873 | * conversion is coordinate rounding. |
| 874 | * |
| 875 | * However, some coordinate rounding takes place as an intermediate |
| 876 | * step before the buffer scale factor is applied, so the rectangle |
| 877 | * boundary may not be exactly as expected. |
| 878 | * |
| 879 | * This is OK for damage tracking since a little extra coverage is |
| 880 | * not a problem. |
| 881 | */ |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 882 | WL_EXPORT pixman_box32_t |
| 883 | weston_surface_to_buffer_rect(struct weston_surface *surface, |
| 884 | pixman_box32_t rect) |
| 885 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 886 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 887 | float xf, yf; |
| 888 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 889 | /* first transform box coordinates if the viewport is set */ |
| 890 | viewport_surface_to_buffer(surface, rect.x1, rect.y1, &xf, &yf); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 891 | rect.x1 = floorf(xf); |
| 892 | rect.y1 = floorf(yf); |
| 893 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 894 | viewport_surface_to_buffer(surface, rect.x2, rect.y2, &xf, &yf); |
Derek Foreman | e2e15ac | 2015-12-01 13:00:43 -0600 | [diff] [blame] | 895 | rect.x2 = ceilf(xf); |
| 896 | rect.y2 = ceilf(yf); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 897 | |
Jason Ekstrand | d0cebc3 | 2014-04-21 20:56:46 -0500 | [diff] [blame] | 898 | return weston_transformed_rect(surface->width_from_buffer, |
| 899 | surface->height_from_buffer, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 900 | vp->buffer.transform, vp->buffer.scale, |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 901 | rect); |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 902 | } |
| 903 | |
Pekka Paalanen | e54e31c | 2015-03-04 14:23:28 +0200 | [diff] [blame] | 904 | /** Transform a region from surface coordinates to buffer coordinates |
| 905 | * |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 906 | * \param surface The surface to fetch wp_viewport and buffer transformation |
Pekka Paalanen | e54e31c | 2015-03-04 14:23:28 +0200 | [diff] [blame] | 907 | * from. |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 908 | * \param[in] surface_region The region in surface coordinates. |
| 909 | * \param[out] buffer_region The region converted to buffer coordinates. |
Pekka Paalanen | e54e31c | 2015-03-04 14:23:28 +0200 | [diff] [blame] | 910 | * |
| 911 | * Buffer_region must be init'd, but will be completely overwritten. |
| 912 | * |
| 913 | * Viewport and buffer transformations can only do translation, scaling, |
| 914 | * and rotations in 90-degree steps. Therefore the only loss in the |
Derek Foreman | 9973967 | 2015-12-03 16:38:11 -0600 | [diff] [blame] | 915 | * conversion is from the coordinate rounding that takes place in |
| 916 | * \ref weston_surface_to_buffer_rect. |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 917 | * |
Pekka Paalanen | e54e31c | 2015-03-04 14:23:28 +0200 | [diff] [blame] | 918 | */ |
| 919 | WL_EXPORT void |
| 920 | weston_surface_to_buffer_region(struct weston_surface *surface, |
| 921 | pixman_region32_t *surface_region, |
| 922 | pixman_region32_t *buffer_region) |
| 923 | { |
| 924 | pixman_box32_t *src_rects, *dest_rects; |
| 925 | int nrects, i; |
| 926 | |
| 927 | src_rects = pixman_region32_rectangles(surface_region, &nrects); |
| 928 | dest_rects = malloc(nrects * sizeof(*dest_rects)); |
| 929 | if (!dest_rects) |
| 930 | return; |
| 931 | |
| 932 | for (i = 0; i < nrects; i++) { |
| 933 | dest_rects[i] = weston_surface_to_buffer_rect(surface, |
| 934 | src_rects[i]); |
| 935 | } |
| 936 | |
| 937 | pixman_region32_fini(buffer_region); |
| 938 | pixman_region32_init_rects(buffer_region, dest_rects, nrects); |
| 939 | free(dest_rects); |
| 940 | } |
| 941 | |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 942 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 943 | weston_view_move_to_plane(struct weston_view *view, |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 944 | struct weston_plane *plane) |
| 945 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 946 | if (view->plane == plane) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 947 | return; |
| 948 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 949 | weston_view_damage_below(view); |
| 950 | view->plane = plane; |
| 951 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 952 | } |
| 953 | |
Pekka Paalanen | 51723d5 | 2015-02-17 13:10:01 +0200 | [diff] [blame] | 954 | /** Inflict damage on the plane where the view is visible. |
| 955 | * |
| 956 | * \param view The view that causes the damage. |
| 957 | * |
| 958 | * If the view is currently on a plane (including the primary plane), |
| 959 | * take the view's boundingbox, subtract all the opaque views that cover it, |
| 960 | * and add the remaining region as damage to the plane. This corresponds |
| 961 | * to the damage inflicted to the plane if this view disappeared. |
| 962 | * |
| 963 | * A repaint is scheduled for this view. |
| 964 | * |
| 965 | * The region of all opaque views covering this view is stored in |
| 966 | * weston_view::clip and updated by view_accumulate_damage() during |
| 967 | * weston_output_repaint(). Specifically, that region matches the |
| 968 | * scenegraph as it was last painted. |
| 969 | */ |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 970 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 971 | weston_view_damage_below(struct weston_view *view) |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 972 | { |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 973 | pixman_region32_t damage; |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 974 | |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 975 | pixman_region32_init(&damage); |
Pekka Paalanen | 25c0ca5 | 2015-02-19 11:15:33 +0200 | [diff] [blame] | 976 | pixman_region32_subtract(&damage, &view->transform.boundingbox, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 977 | &view->clip); |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 978 | if (view->plane) |
| 979 | pixman_region32_union(&view->plane->damage, |
| 980 | &view->plane->damage, &damage); |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 981 | pixman_region32_fini(&damage); |
Kristian Høgsberg | a3a784a | 2013-11-13 21:33:43 -0800 | [diff] [blame] | 982 | weston_view_schedule_repaint(view); |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 983 | } |
| 984 | |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 985 | /** Send wl_surface.enter/leave events |
| 986 | * |
| 987 | * \param surface The surface. |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 988 | * \param head A head of the entered/left output. |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 989 | * \param enter True if entered. |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 990 | * \param leave True if left. |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 991 | * |
| 992 | * Send the enter/leave events for all protocol objects bound to the given |
| 993 | * output by the client owning the surface. |
| 994 | */ |
| 995 | static void |
| 996 | weston_surface_send_enter_leave(struct weston_surface *surface, |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 997 | struct weston_head *head, |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 998 | bool enter, |
| 999 | bool leave) |
| 1000 | { |
| 1001 | struct wl_resource *wloutput; |
| 1002 | struct wl_client *client; |
| 1003 | |
| 1004 | assert(enter != leave); |
| 1005 | |
| 1006 | client = wl_resource_get_client(surface->resource); |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 1007 | wl_resource_for_each(wloutput, &head->resource_list) { |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1008 | if (wl_resource_get_client(wloutput) != client) |
| 1009 | continue; |
| 1010 | |
| 1011 | if (enter) |
| 1012 | wl_surface_send_enter(surface->resource, wloutput); |
| 1013 | if (leave) |
| 1014 | wl_surface_send_leave(surface->resource, wloutput); |
| 1015 | } |
| 1016 | } |
| 1017 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1018 | /** |
| 1019 | * \param es The surface |
| 1020 | * \param mask The new set of outputs for the surface |
| 1021 | * |
| 1022 | * Sets the surface's set of outputs to the ones specified by |
| 1023 | * the new output mask provided. Identifies the outputs that |
| 1024 | * have changed, the posts enter and leave events for these |
| 1025 | * outputs as appropriate. |
| 1026 | */ |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1027 | static void |
| 1028 | weston_surface_update_output_mask(struct weston_surface *es, uint32_t mask) |
| 1029 | { |
| 1030 | uint32_t different = es->output_mask ^ mask; |
| 1031 | uint32_t entered = mask & different; |
| 1032 | uint32_t left = es->output_mask & different; |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1033 | uint32_t output_bit; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1034 | struct weston_output *output; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 1035 | struct weston_head *head; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1036 | |
| 1037 | es->output_mask = mask; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1038 | if (es->resource == NULL) |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1039 | return; |
| 1040 | if (different == 0) |
| 1041 | return; |
| 1042 | |
| 1043 | wl_list_for_each(output, &es->compositor->output_list, link) { |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1044 | output_bit = 1u << output->id; |
| 1045 | if (!(output_bit & different)) |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1046 | continue; |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1047 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 1048 | wl_list_for_each(head, &output->head_list, output_link) { |
| 1049 | weston_surface_send_enter_leave(es, head, |
| 1050 | output_bit & entered, |
| 1051 | output_bit & left); |
| 1052 | } |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1053 | } |
| 1054 | } |
| 1055 | |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 1056 | static void |
| 1057 | notify_view_output_destroy(struct wl_listener *listener, void *data) |
| 1058 | { |
| 1059 | struct weston_view *view = |
| 1060 | container_of(listener, |
| 1061 | struct weston_view, output_destroy_listener); |
| 1062 | |
| 1063 | view->output = NULL; |
| 1064 | view->output_destroy_listener.notify = NULL; |
| 1065 | } |
| 1066 | |
| 1067 | /** Set the primary output of the view |
| 1068 | * |
| 1069 | * \param view The view whose primary output to set |
| 1070 | * \param output The new primary output for the view |
| 1071 | * |
| 1072 | * Set \a output to be the primary output of the \a view. |
| 1073 | * |
| 1074 | * Notice that the assignment may be temporary; the primary output could be |
| 1075 | * automatically changed. Hence, one cannot rely on the value persisting. |
| 1076 | * |
| 1077 | * Passing NULL as /a output will set the primary output to NULL. |
| 1078 | */ |
| 1079 | WL_EXPORT void |
| 1080 | weston_view_set_output(struct weston_view *view, struct weston_output *output) |
| 1081 | { |
| 1082 | if (view->output_destroy_listener.notify) { |
| 1083 | wl_list_remove(&view->output_destroy_listener.link); |
| 1084 | view->output_destroy_listener.notify = NULL; |
| 1085 | } |
| 1086 | view->output = output; |
| 1087 | if (output) { |
| 1088 | view->output_destroy_listener.notify = |
| 1089 | notify_view_output_destroy; |
| 1090 | wl_signal_add(&output->destroy_signal, |
| 1091 | &view->output_destroy_listener); |
| 1092 | } |
| 1093 | } |
| 1094 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1095 | /** Recalculate which output(s) the surface has views displayed on |
| 1096 | * |
| 1097 | * \param es The surface to remap to outputs |
| 1098 | * |
| 1099 | * Finds the output that is showing the largest amount of one |
| 1100 | * of the surface's various views. This output becomes the |
Pekka Paalanen | 130ae6e | 2016-03-30 14:33:33 +0300 | [diff] [blame] | 1101 | * surface's primary output for vsync and frame callback purposes. |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1102 | * |
Pekka Paalanen | 130ae6e | 2016-03-30 14:33:33 +0300 | [diff] [blame] | 1103 | * Also notes all outputs of all of the surface's views |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1104 | * in the output_mask for the surface. |
| 1105 | */ |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1106 | static void |
| 1107 | weston_surface_assign_output(struct weston_surface *es) |
| 1108 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1109 | struct weston_output *new_output; |
| 1110 | struct weston_view *view; |
| 1111 | pixman_region32_t region; |
| 1112 | uint32_t max, area, mask; |
| 1113 | pixman_box32_t *e; |
| 1114 | |
| 1115 | new_output = NULL; |
| 1116 | max = 0; |
| 1117 | mask = 0; |
| 1118 | pixman_region32_init(®ion); |
| 1119 | wl_list_for_each(view, &es->views, surface_link) { |
| 1120 | if (!view->output) |
| 1121 | continue; |
| 1122 | |
| 1123 | pixman_region32_intersect(®ion, &view->transform.boundingbox, |
| 1124 | &view->output->region); |
| 1125 | |
| 1126 | e = pixman_region32_extents(®ion); |
| 1127 | area = (e->x2 - e->x1) * (e->y2 - e->y1); |
| 1128 | |
| 1129 | mask |= view->output_mask; |
| 1130 | |
| 1131 | if (area >= max) { |
| 1132 | new_output = view->output; |
| 1133 | max = area; |
| 1134 | } |
| 1135 | } |
| 1136 | pixman_region32_fini(®ion); |
| 1137 | |
| 1138 | es->output = new_output; |
| 1139 | weston_surface_update_output_mask(es, mask); |
| 1140 | } |
| 1141 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1142 | /** Recalculate which output(s) the view is displayed on |
| 1143 | * |
| 1144 | * \param ev The view to remap to outputs |
| 1145 | * |
| 1146 | * Identifies the set of outputs that the view is visible on, |
| 1147 | * noting them into the output_mask. The output that the view |
Pekka Paalanen | 130ae6e | 2016-03-30 14:33:33 +0300 | [diff] [blame] | 1148 | * is most visible on is set as the view's primary output. |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1149 | * |
| 1150 | * Also does the same for the view's surface. See |
| 1151 | * weston_surface_assign_output(). |
| 1152 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1153 | static void |
| 1154 | weston_view_assign_output(struct weston_view *ev) |
| 1155 | { |
| 1156 | struct weston_compositor *ec = ev->surface->compositor; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1157 | struct weston_output *output, *new_output; |
| 1158 | pixman_region32_t region; |
| 1159 | uint32_t max, area, mask; |
| 1160 | pixman_box32_t *e; |
| 1161 | |
| 1162 | new_output = NULL; |
| 1163 | max = 0; |
| 1164 | mask = 0; |
| 1165 | pixman_region32_init(®ion); |
| 1166 | wl_list_for_each(output, &ec->output_list, link) { |
Giulio Camuffo | 2f2a70c | 2015-07-12 10:52:32 +0300 | [diff] [blame] | 1167 | if (output->destroying) |
| 1168 | continue; |
| 1169 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1170 | pixman_region32_intersect(®ion, &ev->transform.boundingbox, |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1171 | &output->region); |
| 1172 | |
| 1173 | e = pixman_region32_extents(®ion); |
| 1174 | area = (e->x2 - e->x1) * (e->y2 - e->y1); |
| 1175 | |
| 1176 | if (area > 0) |
Bryce Harrington | 89324ce | 2015-12-23 18:38:07 -0800 | [diff] [blame] | 1177 | mask |= 1u << output->id; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1178 | |
| 1179 | if (area >= max) { |
| 1180 | new_output = output; |
| 1181 | max = area; |
| 1182 | } |
| 1183 | } |
| 1184 | pixman_region32_fini(®ion); |
| 1185 | |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 1186 | weston_view_set_output(ev, new_output); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1187 | ev->output_mask = mask; |
| 1188 | |
| 1189 | weston_surface_assign_output(ev->surface); |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1190 | } |
| 1191 | |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 1192 | static void |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1193 | weston_view_to_view_map(struct weston_view *from, struct weston_view *to, |
| 1194 | int from_x, int from_y, int *to_x, int *to_y) |
| 1195 | { |
| 1196 | float x, y; |
| 1197 | |
| 1198 | weston_view_to_global_float(from, from_x, from_y, &x, &y); |
| 1199 | weston_view_from_global_float(to, x, y, &x, &y); |
| 1200 | |
| 1201 | *to_x = round(x); |
| 1202 | *to_y = round(y); |
| 1203 | } |
| 1204 | |
| 1205 | static void |
| 1206 | weston_view_transfer_scissor(struct weston_view *from, struct weston_view *to) |
| 1207 | { |
| 1208 | pixman_box32_t *a; |
| 1209 | pixman_box32_t b; |
| 1210 | |
| 1211 | a = pixman_region32_extents(&from->geometry.scissor); |
| 1212 | |
| 1213 | weston_view_to_view_map(from, to, a->x1, a->y1, &b.x1, &b.y1); |
| 1214 | weston_view_to_view_map(from, to, a->x2, a->y2, &b.x2, &b.y2); |
| 1215 | |
| 1216 | pixman_region32_fini(&to->geometry.scissor); |
| 1217 | pixman_region32_init_with_extents(&to->geometry.scissor, &b); |
| 1218 | } |
| 1219 | |
| 1220 | static void |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 1221 | view_compute_bbox(struct weston_view *view, const pixman_box32_t *inbox, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1222 | pixman_region32_t *bbox) |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1223 | { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1224 | float min_x = HUGE_VALF, min_y = HUGE_VALF; |
| 1225 | float max_x = -HUGE_VALF, max_y = -HUGE_VALF; |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1226 | int32_t s[4][2] = { |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 1227 | { inbox->x1, inbox->y1 }, |
| 1228 | { inbox->x1, inbox->y2 }, |
| 1229 | { inbox->x2, inbox->y1 }, |
| 1230 | { inbox->x2, inbox->y2 }, |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1231 | }; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1232 | float int_x, int_y; |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1233 | int i; |
| 1234 | |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 1235 | if (inbox->x1 == inbox->x2 || inbox->y1 == inbox->y2) { |
Pekka Paalanen | 7c7d464 | 2012-09-04 13:55:44 +0300 | [diff] [blame] | 1236 | /* avoid rounding empty bbox to 1x1 */ |
| 1237 | pixman_region32_init(bbox); |
| 1238 | return; |
| 1239 | } |
| 1240 | |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1241 | for (i = 0; i < 4; ++i) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1242 | float x, y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1243 | 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] | 1244 | if (x < min_x) |
| 1245 | min_x = x; |
| 1246 | if (x > max_x) |
| 1247 | max_x = x; |
| 1248 | if (y < min_y) |
| 1249 | min_y = y; |
| 1250 | if (y > max_y) |
| 1251 | max_y = y; |
| 1252 | } |
| 1253 | |
Pekka Paalanen | 219b982 | 2012-02-08 15:38:37 +0200 | [diff] [blame] | 1254 | int_x = floorf(min_x); |
| 1255 | int_y = floorf(min_y); |
| 1256 | pixman_region32_init_rect(bbox, int_x, int_y, |
| 1257 | ceilf(max_x) - int_x, ceilf(max_y) - int_y); |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1258 | } |
| 1259 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1260 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1261 | weston_view_update_transform_disable(struct weston_view *view) |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1262 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1263 | view->transform.enabled = 0; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1264 | |
Pekka Paalanen | cc2f868 | 2012-02-13 10:34:04 +0200 | [diff] [blame] | 1265 | /* round off fractions when not transformed */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1266 | view->geometry.x = roundf(view->geometry.x); |
| 1267 | view->geometry.y = roundf(view->geometry.y); |
Pekka Paalanen | cc2f868 | 2012-02-13 10:34:04 +0200 | [diff] [blame] | 1268 | |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1269 | /* Otherwise identity matrix, but with x and y translation. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1270 | view->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE; |
| 1271 | view->transform.position.matrix.d[12] = view->geometry.x; |
| 1272 | view->transform.position.matrix.d[13] = view->geometry.y; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1273 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1274 | view->transform.matrix = view->transform.position.matrix; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1275 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1276 | view->transform.inverse = view->transform.position.matrix; |
| 1277 | view->transform.inverse.d[12] = -view->geometry.x; |
| 1278 | view->transform.inverse.d[13] = -view->geometry.y; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1279 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1280 | pixman_region32_init_rect(&view->transform.boundingbox, |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1281 | 0, 0, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1282 | view->surface->width, |
| 1283 | view->surface->height); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1284 | if (view->geometry.scissor_enabled) |
| 1285 | pixman_region32_intersect(&view->transform.boundingbox, |
| 1286 | &view->transform.boundingbox, |
| 1287 | &view->geometry.scissor); |
| 1288 | |
| 1289 | pixman_region32_translate(&view->transform.boundingbox, |
| 1290 | view->geometry.x, view->geometry.y); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1291 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1292 | if (view->alpha == 1.0) { |
| 1293 | pixman_region32_copy(&view->transform.opaque, |
| 1294 | &view->surface->opaque); |
| 1295 | pixman_region32_translate(&view->transform.opaque, |
| 1296 | view->geometry.x, |
| 1297 | view->geometry.y); |
Kristian Høgsberg | 3b4af20 | 2012-02-28 09:19:39 -0500 | [diff] [blame] | 1298 | } |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1299 | } |
| 1300 | |
| 1301 | static int |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1302 | weston_view_update_transform_enable(struct weston_view *view) |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1303 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1304 | struct weston_view *parent = view->geometry.parent; |
| 1305 | struct weston_matrix *matrix = &view->transform.matrix; |
| 1306 | struct weston_matrix *inverse = &view->transform.inverse; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1307 | struct weston_transform *tform; |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1308 | pixman_region32_t surfregion; |
| 1309 | const pixman_box32_t *surfbox; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1310 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1311 | view->transform.enabled = 1; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1312 | |
| 1313 | /* Otherwise identity matrix, but with x and y translation. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1314 | view->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE; |
| 1315 | view->transform.position.matrix.d[12] = view->geometry.x; |
| 1316 | view->transform.position.matrix.d[13] = view->geometry.y; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1317 | |
| 1318 | weston_matrix_init(matrix); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1319 | wl_list_for_each(tform, &view->geometry.transformation_list, link) |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1320 | weston_matrix_multiply(matrix, &tform->matrix); |
| 1321 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1322 | if (parent) |
| 1323 | weston_matrix_multiply(matrix, &parent->transform.matrix); |
| 1324 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1325 | if (weston_matrix_invert(inverse, matrix) < 0) { |
| 1326 | /* Oops, bad total transformation, not invertible */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1327 | weston_log("error: weston_view %p" |
| 1328 | " transformation not invertible.\n", view); |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1329 | return -1; |
| 1330 | } |
| 1331 | |
Giulio Camuffo | 148c199 | 2016-09-04 18:50:46 +0300 | [diff] [blame] | 1332 | if (view->alpha == 1.0 && |
| 1333 | matrix->type == WESTON_MATRIX_TRANSFORM_TRANSLATE) { |
| 1334 | pixman_region32_copy(&view->transform.opaque, |
| 1335 | &view->surface->opaque); |
| 1336 | pixman_region32_translate(&view->transform.opaque, |
| 1337 | matrix->d[12], |
| 1338 | matrix->d[13]); |
| 1339 | } |
| 1340 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1341 | pixman_region32_init_rect(&surfregion, 0, 0, |
| 1342 | view->surface->width, view->surface->height); |
| 1343 | if (view->geometry.scissor_enabled) |
| 1344 | pixman_region32_intersect(&surfregion, &surfregion, |
| 1345 | &view->geometry.scissor); |
| 1346 | surfbox = pixman_region32_extents(&surfregion); |
| 1347 | |
| 1348 | view_compute_bbox(view, surfbox, &view->transform.boundingbox); |
| 1349 | pixman_region32_fini(&surfregion); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1350 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1351 | return 0; |
| 1352 | } |
| 1353 | |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1354 | static struct weston_layer * |
| 1355 | get_view_layer(struct weston_view *view) |
| 1356 | { |
| 1357 | if (view->parent_view) |
| 1358 | return get_view_layer(view->parent_view); |
| 1359 | return view->layer_link.layer; |
| 1360 | } |
| 1361 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1362 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1363 | weston_view_update_transform(struct weston_view *view) |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1364 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1365 | struct weston_view *parent = view->geometry.parent; |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1366 | struct weston_layer *layer; |
| 1367 | pixman_region32_t mask; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1368 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1369 | if (!view->transform.dirty) |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1370 | return; |
| 1371 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1372 | if (parent) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1373 | weston_view_update_transform(parent); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1374 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1375 | view->transform.dirty = 0; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1376 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1377 | weston_view_damage_below(view); |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 1378 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1379 | pixman_region32_fini(&view->transform.boundingbox); |
| 1380 | pixman_region32_fini(&view->transform.opaque); |
| 1381 | pixman_region32_init(&view->transform.opaque); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1382 | |
Pekka Paalanen | cd40362 | 2012-01-25 13:37:39 +0200 | [diff] [blame] | 1383 | /* transform.position is always in transformation_list */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1384 | if (view->geometry.transformation_list.next == |
| 1385 | &view->transform.position.link && |
| 1386 | view->geometry.transformation_list.prev == |
| 1387 | &view->transform.position.link && |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1388 | !parent) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1389 | weston_view_update_transform_disable(view); |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1390 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1391 | if (weston_view_update_transform_enable(view) < 0) |
| 1392 | weston_view_update_transform_disable(view); |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1393 | } |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 1394 | |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1395 | layer = get_view_layer(view); |
| 1396 | if (layer) { |
| 1397 | pixman_region32_init_with_extents(&mask, &layer->mask); |
Pekka Paalanen | 25c0ca5 | 2015-02-19 11:15:33 +0200 | [diff] [blame] | 1398 | pixman_region32_intersect(&view->transform.boundingbox, |
| 1399 | &view->transform.boundingbox, &mask); |
Pekka Paalanen | 8844bf2 | 2015-02-18 16:30:47 +0200 | [diff] [blame] | 1400 | pixman_region32_intersect(&view->transform.opaque, |
| 1401 | &view->transform.opaque, &mask); |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1402 | pixman_region32_fini(&mask); |
| 1403 | } |
| 1404 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1405 | if (parent) { |
| 1406 | if (parent->geometry.scissor_enabled) { |
| 1407 | view->geometry.scissor_enabled = true; |
| 1408 | weston_view_transfer_scissor(parent, view); |
| 1409 | } else { |
| 1410 | view->geometry.scissor_enabled = false; |
| 1411 | } |
| 1412 | } |
| 1413 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1414 | weston_view_damage_below(view); |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 1415 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1416 | weston_view_assign_output(view); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 1417 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1418 | wl_signal_emit(&view->surface->compositor->transform_signal, |
| 1419 | view->surface); |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1420 | } |
| 1421 | |
Pekka Paalanen | ddae03c | 2012-02-06 14:54:20 +0200 | [diff] [blame] | 1422 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1423 | weston_view_geometry_dirty(struct weston_view *view) |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 1424 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1425 | struct weston_view *child; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1426 | |
| 1427 | /* |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1428 | * The invariant: if view->geometry.dirty, then all views |
| 1429 | * in view->geometry.child_list have geometry.dirty too. |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1430 | * Corollary: if not parent->geometry.dirty, then all ancestors |
| 1431 | * are not dirty. |
| 1432 | */ |
| 1433 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1434 | if (view->transform.dirty) |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1435 | return; |
| 1436 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1437 | view->transform.dirty = 1; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1438 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1439 | wl_list_for_each(child, &view->geometry.child_list, |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1440 | geometry.parent_link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1441 | weston_view_geometry_dirty(child); |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 1442 | } |
| 1443 | |
| 1444 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1445 | weston_view_to_global_fixed(struct weston_view *view, |
| 1446 | wl_fixed_t vx, wl_fixed_t vy, |
| 1447 | wl_fixed_t *x, wl_fixed_t *y) |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1448 | { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1449 | float xf, yf; |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1450 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1451 | weston_view_to_global_float(view, |
| 1452 | wl_fixed_to_double(vx), |
| 1453 | wl_fixed_to_double(vy), |
| 1454 | &xf, &yf); |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1455 | *x = wl_fixed_from_double(xf); |
| 1456 | *y = wl_fixed_from_double(yf); |
| 1457 | } |
| 1458 | |
Kristian Høgsberg | ecf6ede | 2012-09-05 21:59:35 -0400 | [diff] [blame] | 1459 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1460 | weston_view_from_global_float(struct weston_view *view, |
| 1461 | float x, float y, float *vx, float *vy) |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1462 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1463 | if (view->transform.enabled) { |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1464 | struct weston_vector v = { { x, y, 0.0f, 1.0f } }; |
| 1465 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1466 | weston_matrix_transform(&view->transform.inverse, &v); |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1467 | |
| 1468 | if (fabsf(v.f[3]) < 1e-6) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1469 | weston_log("warning: numerical instability in " |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1470 | "weston_view_from_global(), divisor = %g\n", |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1471 | v.f[3]); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1472 | *vx = 0; |
| 1473 | *vy = 0; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1474 | return; |
| 1475 | } |
| 1476 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1477 | *vx = v.f[0] / v.f[3]; |
| 1478 | *vy = v.f[1] / v.f[3]; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1479 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1480 | *vx = x - view->geometry.x; |
| 1481 | *vy = y - view->geometry.y; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1482 | } |
| 1483 | } |
| 1484 | |
| 1485 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1486 | weston_view_from_global_fixed(struct weston_view *view, |
| 1487 | wl_fixed_t x, wl_fixed_t y, |
| 1488 | wl_fixed_t *vx, wl_fixed_t *vy) |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1489 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1490 | float vxf, vyf; |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1491 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1492 | weston_view_from_global_float(view, |
| 1493 | wl_fixed_to_double(x), |
| 1494 | wl_fixed_to_double(y), |
| 1495 | &vxf, &vyf); |
| 1496 | *vx = wl_fixed_from_double(vxf); |
| 1497 | *vy = wl_fixed_from_double(vyf); |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1501 | weston_view_from_global(struct weston_view *view, |
| 1502 | int32_t x, int32_t y, int32_t *vx, int32_t *vy) |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1503 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1504 | float vxf, vyf; |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1505 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1506 | weston_view_from_global_float(view, x, y, &vxf, &vyf); |
| 1507 | *vx = floorf(vxf); |
| 1508 | *vy = floorf(vyf); |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1509 | } |
| 1510 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1511 | /** |
| 1512 | * \param surface The surface to be repainted |
| 1513 | * |
| 1514 | * Marks the output(s) that the surface is shown on as needing to be |
| 1515 | * repainted. See weston_output_schedule_repaint(). |
| 1516 | */ |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1517 | WL_EXPORT void |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1518 | weston_surface_schedule_repaint(struct weston_surface *surface) |
| 1519 | { |
| 1520 | struct weston_output *output; |
| 1521 | |
| 1522 | wl_list_for_each(output, &surface->compositor->output_list, link) |
Bryce Harrington | 89324ce | 2015-12-23 18:38:07 -0800 | [diff] [blame] | 1523 | if (surface->output_mask & (1u << output->id)) |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1524 | weston_output_schedule_repaint(output); |
| 1525 | } |
| 1526 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1527 | /** |
| 1528 | * \param view The view to be repainted |
| 1529 | * |
| 1530 | * Marks the output(s) that the view is shown on as needing to be |
| 1531 | * repainted. See weston_output_schedule_repaint(). |
| 1532 | */ |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1533 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1534 | weston_view_schedule_repaint(struct weston_view *view) |
| 1535 | { |
| 1536 | struct weston_output *output; |
| 1537 | |
| 1538 | wl_list_for_each(output, &view->surface->compositor->output_list, link) |
Bryce Harrington | 89324ce | 2015-12-23 18:38:07 -0800 | [diff] [blame] | 1539 | if (view->output_mask & (1u << output->id)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1540 | weston_output_schedule_repaint(output); |
| 1541 | } |
| 1542 | |
Pekka Paalanen | e508ce6 | 2015-02-19 13:59:55 +0200 | [diff] [blame] | 1543 | /** |
| 1544 | * XXX: This function does it the wrong way. |
| 1545 | * surface->damage is the damage from the client, and causes |
| 1546 | * surface_flush_damage() to copy pixels. No window management action can |
| 1547 | * cause damage to the client-provided content, warranting re-upload! |
| 1548 | * |
| 1549 | * Instead of surface->damage, this function should record the damage |
| 1550 | * with all the views for this surface to avoid extraneous texture |
| 1551 | * uploads. |
| 1552 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1553 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1554 | weston_surface_damage(struct weston_surface *surface) |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 1555 | { |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1556 | pixman_region32_union_rect(&surface->damage, &surface->damage, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1557 | 0, 0, surface->width, |
| 1558 | surface->height); |
Pekka Paalanen | 2267d45 | 2012-01-26 13:12:45 +0200 | [diff] [blame] | 1559 | |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1560 | weston_surface_schedule_repaint(surface); |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 1561 | } |
| 1562 | |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 1563 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1564 | weston_view_set_position(struct weston_view *view, float x, float y) |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1565 | { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1566 | if (view->geometry.x == x && view->geometry.y == y) |
| 1567 | return; |
| 1568 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1569 | view->geometry.x = x; |
| 1570 | view->geometry.y = y; |
| 1571 | weston_view_geometry_dirty(view); |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1572 | } |
| 1573 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1574 | static void |
| 1575 | transform_parent_handle_parent_destroy(struct wl_listener *listener, |
| 1576 | void *data) |
| 1577 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1578 | struct weston_view *view = |
| 1579 | container_of(listener, struct weston_view, |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1580 | geometry.parent_destroy_listener); |
| 1581 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1582 | weston_view_set_transform_parent(view, NULL); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1583 | } |
| 1584 | |
| 1585 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1586 | weston_view_set_transform_parent(struct weston_view *view, |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1587 | struct weston_view *parent) |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1588 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1589 | if (view->geometry.parent) { |
| 1590 | wl_list_remove(&view->geometry.parent_destroy_listener.link); |
| 1591 | wl_list_remove(&view->geometry.parent_link); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1592 | |
| 1593 | if (!parent) |
| 1594 | view->geometry.scissor_enabled = false; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1595 | } |
| 1596 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1597 | view->geometry.parent = parent; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1598 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1599 | view->geometry.parent_destroy_listener.notify = |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1600 | transform_parent_handle_parent_destroy; |
| 1601 | if (parent) { |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1602 | wl_signal_add(&parent->destroy_signal, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1603 | &view->geometry.parent_destroy_listener); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1604 | wl_list_insert(&parent->geometry.child_list, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1605 | &view->geometry.parent_link); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1606 | } |
| 1607 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1608 | weston_view_geometry_dirty(view); |
| 1609 | } |
| 1610 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1611 | /** Set a clip mask rectangle on a view |
| 1612 | * |
| 1613 | * \param view The view to set the clip mask on. |
| 1614 | * \param x Top-left corner X coordinate of the clip rectangle. |
| 1615 | * \param y Top-left corner Y coordinate of the clip rectangle. |
| 1616 | * \param width Width of the clip rectangle, non-negative. |
| 1617 | * \param height Height of the clip rectangle, non-negative. |
| 1618 | * |
| 1619 | * A shell may set a clip mask rectangle on a view. Everything outside |
| 1620 | * the rectangle is cut away for input and output purposes: it is |
| 1621 | * not drawn and cannot be hit by hit-test based input like pointer |
| 1622 | * motion or touch-downs. Everything inside the rectangle will behave |
| 1623 | * normally. Clients are unaware of clipping. |
| 1624 | * |
Yong Bakos | 4c72e29 | 2016-04-28 11:59:10 -0500 | [diff] [blame] | 1625 | * The rectangle is set in surface-local coordinates. Setting a clip |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1626 | * mask rectangle does not affect the view position, the view is positioned |
| 1627 | * as it would be without a clip. The clip also does not change |
| 1628 | * weston_surface::width,height. |
| 1629 | * |
| 1630 | * The clip mask rectangle is part of transformation inheritance |
| 1631 | * (weston_view_set_transform_parent()). A clip set in the root of the |
| 1632 | * transformation inheritance tree will affect all views in the tree. |
| 1633 | * A clip can be set only on the root view. Attempting to set a clip |
| 1634 | * on view that has a transformation parent will fail. Assigning a parent |
| 1635 | * to a view that has a clip set will cause the clip to be forgotten. |
| 1636 | * |
| 1637 | * Because the clip mask is an axis-aligned rectangle, it poses restrictions |
| 1638 | * on the additional transformations in the child views. These transformations |
| 1639 | * may not rotate the coordinate axes, i.e., only translation and scaling |
| 1640 | * are allowed. Violating this restriction causes the clipping to malfunction. |
| 1641 | * Furthermore, using scaling may cause rounding errors in child clipping. |
| 1642 | * |
| 1643 | * The clip mask rectangle is not automatically adjusted based on |
| 1644 | * wl_surface.attach dx and dy arguments. |
| 1645 | * |
| 1646 | * A clip mask rectangle can be set only if the compositor capability |
| 1647 | * WESTON_CAP_VIEW_CLIP_MASK is present. |
| 1648 | * |
| 1649 | * This function sets the clip mask rectangle and schedules a repaint for |
| 1650 | * the view. |
| 1651 | */ |
| 1652 | WL_EXPORT void |
| 1653 | weston_view_set_mask(struct weston_view *view, |
| 1654 | int x, int y, int width, int height) |
| 1655 | { |
| 1656 | struct weston_compositor *compositor = view->surface->compositor; |
| 1657 | |
| 1658 | if (!(compositor->capabilities & WESTON_CAP_VIEW_CLIP_MASK)) { |
| 1659 | weston_log("%s not allowed without capability!\n", __func__); |
| 1660 | return; |
| 1661 | } |
| 1662 | |
| 1663 | if (view->geometry.parent) { |
| 1664 | weston_log("view %p has a parent, clip forbidden!\n", view); |
| 1665 | return; |
| 1666 | } |
| 1667 | |
| 1668 | if (width < 0 || height < 0) { |
| 1669 | weston_log("%s: illegal args %d, %d, %d, %d\n", __func__, |
| 1670 | x, y, width, height); |
| 1671 | return; |
| 1672 | } |
| 1673 | |
| 1674 | pixman_region32_fini(&view->geometry.scissor); |
| 1675 | pixman_region32_init_rect(&view->geometry.scissor, x, y, width, height); |
| 1676 | view->geometry.scissor_enabled = true; |
| 1677 | weston_view_geometry_dirty(view); |
| 1678 | weston_view_schedule_repaint(view); |
| 1679 | } |
| 1680 | |
| 1681 | /** Remove the clip mask from a view |
| 1682 | * |
| 1683 | * \param view The view to remove the clip mask from. |
| 1684 | * |
| 1685 | * Removed the clip mask rectangle and schedules a repaint. |
| 1686 | * |
| 1687 | * \sa weston_view_set_mask |
| 1688 | */ |
| 1689 | WL_EXPORT void |
| 1690 | weston_view_set_mask_infinite(struct weston_view *view) |
| 1691 | { |
| 1692 | view->geometry.scissor_enabled = false; |
| 1693 | weston_view_geometry_dirty(view); |
| 1694 | weston_view_schedule_repaint(view); |
| 1695 | } |
| 1696 | |
Armin Krezović | 0da12b8 | 2016-06-30 06:04:33 +0200 | [diff] [blame] | 1697 | /* Check if view should be displayed |
| 1698 | * |
| 1699 | * The indicator is set manually when assigning |
| 1700 | * a view to a surface. |
| 1701 | * |
| 1702 | * This needs reworking. See the thread starting at: |
| 1703 | * |
| 1704 | * https://lists.freedesktop.org/archives/wayland-devel/2016-June/029656.html |
| 1705 | */ |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 1706 | WL_EXPORT bool |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1707 | weston_view_is_mapped(struct weston_view *view) |
| 1708 | { |
Armin Krezović | 0da12b8 | 2016-06-30 06:04:33 +0200 | [diff] [blame] | 1709 | return view->is_mapped; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1710 | } |
| 1711 | |
Philipp Zabel | 70decd5 | 2018-09-03 20:11:15 +0200 | [diff] [blame] | 1712 | /* Check if view is opaque in specified region |
| 1713 | * |
| 1714 | * \param view The view to check for opacity. |
| 1715 | * \param region The region to check for opacity, in view coordinates. |
| 1716 | * |
| 1717 | * Returns true if the view is opaque in the specified region, because view |
| 1718 | * alpha is 1.0 and either the opaque region set by the client contains the |
| 1719 | * specified region, or the buffer pixel format or solid color is opaque. |
| 1720 | */ |
| 1721 | WL_EXPORT bool |
| 1722 | weston_view_is_opaque(struct weston_view *ev, pixman_region32_t *region) |
| 1723 | { |
| 1724 | pixman_region32_t r; |
| 1725 | bool ret = false; |
| 1726 | |
| 1727 | if (ev->alpha < 1.0) |
| 1728 | return false; |
| 1729 | |
| 1730 | if (ev->surface->is_opaque) |
| 1731 | return true; |
| 1732 | |
| 1733 | if (ev->transform.dirty) { |
| 1734 | weston_log("%s: transform dirty", __func__); |
| 1735 | return false; |
| 1736 | } |
| 1737 | |
| 1738 | pixman_region32_init(&r); |
| 1739 | pixman_region32_subtract(&r, region, &ev->transform.opaque); |
| 1740 | |
| 1741 | if (!pixman_region32_not_empty(&r)) |
| 1742 | ret = true; |
| 1743 | |
| 1744 | pixman_region32_fini(&r); |
| 1745 | |
| 1746 | return ret; |
| 1747 | } |
| 1748 | |
Armin Krezović | 0da12b8 | 2016-06-30 06:04:33 +0200 | [diff] [blame] | 1749 | /* Check if a surface has a view assigned to it |
| 1750 | * |
| 1751 | * The indicator is set manually when mapping |
| 1752 | * a surface and creating a view for it. |
| 1753 | * |
| 1754 | * This needs to go. See the thread starting at: |
| 1755 | * |
| 1756 | * https://lists.freedesktop.org/archives/wayland-devel/2016-June/029656.html |
| 1757 | * |
| 1758 | */ |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 1759 | WL_EXPORT bool |
Ander Conselvan de Oliveira | b8ab14f | 2012-03-27 17:36:36 +0300 | [diff] [blame] | 1760 | weston_surface_is_mapped(struct weston_surface *surface) |
| 1761 | { |
Armin Krezović | 0da12b8 | 2016-06-30 06:04:33 +0200 | [diff] [blame] | 1762 | return surface->is_mapped; |
Ander Conselvan de Oliveira | b8ab14f | 2012-03-27 17:36:36 +0300 | [diff] [blame] | 1763 | } |
| 1764 | |
Pekka Paalanen | da75ee1 | 2013-11-26 18:19:43 +0100 | [diff] [blame] | 1765 | static void |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 1766 | 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] | 1767 | { |
| 1768 | struct weston_view *view; |
| 1769 | |
| 1770 | if (surface->width == width && surface->height == height) |
| 1771 | return; |
| 1772 | |
| 1773 | surface->width = width; |
| 1774 | surface->height = height; |
| 1775 | |
| 1776 | wl_list_for_each(view, &surface->views, surface_link) |
| 1777 | weston_view_geometry_dirty(view); |
| 1778 | } |
| 1779 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 1780 | WL_EXPORT void |
| 1781 | weston_surface_set_size(struct weston_surface *surface, |
| 1782 | int32_t width, int32_t height) |
| 1783 | { |
| 1784 | assert(!surface->resource); |
| 1785 | surface_set_size(surface, width, height); |
| 1786 | } |
| 1787 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1788 | static int |
| 1789 | fixed_round_up_to_int(wl_fixed_t f) |
| 1790 | { |
| 1791 | return wl_fixed_to_int(wl_fixed_from_int(1) - 1 + f); |
| 1792 | } |
| 1793 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1794 | static void |
Pekka Paalanen | 59987fa | 2016-04-26 15:50:59 +0300 | [diff] [blame] | 1795 | convert_size_by_transform_scale(int32_t *width_out, int32_t *height_out, |
| 1796 | int32_t width, int32_t height, |
| 1797 | uint32_t transform, |
| 1798 | int32_t scale) |
| 1799 | { |
| 1800 | assert(scale > 0); |
| 1801 | |
| 1802 | switch (transform) { |
| 1803 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 1804 | case WL_OUTPUT_TRANSFORM_180: |
| 1805 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 1806 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 1807 | *width_out = width / scale; |
| 1808 | *height_out = height / scale; |
| 1809 | break; |
| 1810 | case WL_OUTPUT_TRANSFORM_90: |
| 1811 | case WL_OUTPUT_TRANSFORM_270: |
| 1812 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 1813 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 1814 | *width_out = height / scale; |
| 1815 | *height_out = width / scale; |
| 1816 | break; |
| 1817 | default: |
| 1818 | assert(0 && "invalid transform"); |
| 1819 | } |
| 1820 | } |
| 1821 | |
| 1822 | static void |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1823 | weston_surface_calculate_size_from_buffer(struct weston_surface *surface) |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1824 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 1825 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Pekka Paalanen | da75ee1 | 2013-11-26 18:19:43 +0100 | [diff] [blame] | 1826 | |
| 1827 | if (!surface->buffer_ref.buffer) { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1828 | surface->width_from_buffer = 0; |
| 1829 | surface->height_from_buffer = 0; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 1830 | return; |
| 1831 | } |
| 1832 | |
Pekka Paalanen | 59987fa | 2016-04-26 15:50:59 +0300 | [diff] [blame] | 1833 | convert_size_by_transform_scale(&surface->width_from_buffer, |
| 1834 | &surface->height_from_buffer, |
| 1835 | surface->buffer_ref.buffer->width, |
| 1836 | surface->buffer_ref.buffer->height, |
| 1837 | vp->buffer.transform, |
| 1838 | vp->buffer.scale); |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1839 | } |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1840 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1841 | static void |
| 1842 | weston_surface_update_size(struct weston_surface *surface) |
| 1843 | { |
| 1844 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
| 1845 | int32_t width, height; |
| 1846 | |
| 1847 | width = surface->width_from_buffer; |
| 1848 | height = surface->height_from_buffer; |
| 1849 | |
| 1850 | if (width != 0 && vp->surface.width != -1) { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1851 | surface_set_size(surface, |
| 1852 | vp->surface.width, vp->surface.height); |
| 1853 | return; |
| 1854 | } |
| 1855 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1856 | if (width != 0 && vp->buffer.src_width != wl_fixed_from_int(-1)) { |
Pekka Paalanen | e931721 | 2014-04-04 14:22:13 +0300 | [diff] [blame] | 1857 | int32_t w = fixed_round_up_to_int(vp->buffer.src_width); |
| 1858 | int32_t h = fixed_round_up_to_int(vp->buffer.src_height); |
| 1859 | |
| 1860 | surface_set_size(surface, w ?: 1, h ?: 1); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1861 | return; |
| 1862 | } |
| 1863 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 1864 | surface_set_size(surface, width, height); |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1865 | } |
| 1866 | |
Alexandros Frantzis | 409b01f | 2017-11-16 18:21:01 +0200 | [diff] [blame] | 1867 | WL_EXPORT void |
| 1868 | weston_compositor_get_time(struct timespec *time) |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 1869 | { |
Alexandros Frantzis | 409b01f | 2017-11-16 18:21:01 +0200 | [diff] [blame] | 1870 | clock_gettime(CLOCK_REALTIME, time); |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 1871 | } |
| 1872 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1873 | WL_EXPORT struct weston_view * |
| 1874 | weston_compositor_pick_view(struct weston_compositor *compositor, |
| 1875 | wl_fixed_t x, wl_fixed_t y, |
| 1876 | wl_fixed_t *vx, wl_fixed_t *vy) |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 1877 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1878 | struct weston_view *view; |
Pekka Paalanen | fc22a52 | 2015-02-18 15:08:29 +0200 | [diff] [blame] | 1879 | wl_fixed_t view_x, view_y; |
| 1880 | int view_ix, view_iy; |
| 1881 | int ix = wl_fixed_to_int(x); |
| 1882 | int iy = wl_fixed_to_int(y); |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 1883 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1884 | wl_list_for_each(view, &compositor->view_list, link) { |
Pekka Paalanen | fc22a52 | 2015-02-18 15:08:29 +0200 | [diff] [blame] | 1885 | if (!pixman_region32_contains_point( |
| 1886 | &view->transform.boundingbox, ix, iy, NULL)) |
| 1887 | continue; |
| 1888 | |
| 1889 | weston_view_from_global_fixed(view, x, y, &view_x, &view_y); |
| 1890 | view_ix = wl_fixed_to_int(view_x); |
| 1891 | view_iy = wl_fixed_to_int(view_y); |
| 1892 | |
| 1893 | if (!pixman_region32_contains_point(&view->surface->input, |
| 1894 | view_ix, view_iy, NULL)) |
| 1895 | continue; |
| 1896 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1897 | if (view->geometry.scissor_enabled && |
| 1898 | !pixman_region32_contains_point(&view->geometry.scissor, |
| 1899 | view_ix, view_iy, NULL)) |
| 1900 | continue; |
| 1901 | |
Pekka Paalanen | fc22a52 | 2015-02-18 15:08:29 +0200 | [diff] [blame] | 1902 | *vx = view_x; |
| 1903 | *vy = view_y; |
| 1904 | return view; |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 1905 | } |
| 1906 | |
Derek Foreman | f9318d1 | 2015-05-11 15:40:11 -0500 | [diff] [blame] | 1907 | *vx = wl_fixed_from_int(-1000000); |
| 1908 | *vy = wl_fixed_from_int(-1000000); |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 1909 | return NULL; |
| 1910 | } |
| 1911 | |
| 1912 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1913 | weston_compositor_repick(struct weston_compositor *compositor) |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 1914 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1915 | struct weston_seat *seat; |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 1916 | |
Kristian Høgsberg | 10ddd97 | 2013-10-22 12:40:54 -0700 | [diff] [blame] | 1917 | if (!compositor->session_active) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1918 | return; |
| 1919 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1920 | wl_list_for_each(seat, &compositor->seat_list, link) |
Kristian Høgsberg | a71e8b2 | 2013-05-06 21:51:21 -0400 | [diff] [blame] | 1921 | weston_seat_repick(seat); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 1922 | } |
| 1923 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1924 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1925 | weston_view_unmap(struct weston_view *view) |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 1926 | { |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 1927 | struct weston_seat *seat; |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 1928 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1929 | if (!weston_view_is_mapped(view)) |
| 1930 | return; |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 1931 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1932 | weston_view_damage_below(view); |
Semi Malinen | e7a52fb | 2018-04-26 11:08:10 +0200 | [diff] [blame] | 1933 | weston_view_set_output(view, NULL); |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 1934 | view->plane = NULL; |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 1935 | view->is_mapped = false; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1936 | weston_layer_entry_remove(&view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1937 | wl_list_remove(&view->link); |
| 1938 | wl_list_init(&view->link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1939 | view->output_mask = 0; |
| 1940 | weston_surface_assign_output(view->surface); |
| 1941 | |
| 1942 | if (weston_surface_is_mapped(view->surface)) |
| 1943 | return; |
| 1944 | |
| 1945 | wl_list_for_each(seat, &view->surface->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1946 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 1947 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 1948 | struct weston_keyboard *keyboard = |
| 1949 | weston_seat_get_keyboard(seat); |
| 1950 | |
| 1951 | if (keyboard && keyboard->focus == view->surface) |
| 1952 | weston_keyboard_set_focus(keyboard, NULL); |
| 1953 | if (pointer && pointer->focus == view) |
Derek Foreman | f9318d1 | 2015-05-11 15:40:11 -0500 | [diff] [blame] | 1954 | weston_pointer_clear_focus(pointer); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1955 | if (touch && touch->focus == view) |
| 1956 | weston_touch_set_focus(touch, NULL); |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 1957 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1958 | } |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 1959 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1960 | WL_EXPORT void |
| 1961 | weston_surface_unmap(struct weston_surface *surface) |
| 1962 | { |
| 1963 | struct weston_view *view; |
| 1964 | |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 1965 | surface->is_mapped = false; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1966 | wl_list_for_each(view, &surface->views, surface_link) |
| 1967 | weston_view_unmap(view); |
| 1968 | surface->output = NULL; |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 1969 | } |
| 1970 | |
Pekka Paalanen | 3c9b802 | 2014-03-14 14:38:13 +0200 | [diff] [blame] | 1971 | static void |
| 1972 | weston_surface_reset_pending_buffer(struct weston_surface *surface) |
| 1973 | { |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 1974 | weston_surface_state_set_buffer(&surface->pending, NULL); |
Pekka Paalanen | 3c9b802 | 2014-03-14 14:38:13 +0200 | [diff] [blame] | 1975 | surface->pending.sx = 0; |
| 1976 | surface->pending.sy = 0; |
| 1977 | surface->pending.newly_attached = 0; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1978 | surface->pending.buffer_viewport.changed = 0; |
Pekka Paalanen | 3c9b802 | 2014-03-14 14:38:13 +0200 | [diff] [blame] | 1979 | } |
| 1980 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1981 | WL_EXPORT void |
| 1982 | weston_view_destroy(struct weston_view *view) |
| 1983 | { |
| 1984 | wl_signal_emit(&view->destroy_signal, view); |
| 1985 | |
| 1986 | assert(wl_list_empty(&view->geometry.child_list)); |
| 1987 | |
| 1988 | if (weston_view_is_mapped(view)) { |
| 1989 | weston_view_unmap(view); |
| 1990 | weston_compositor_build_view_list(view->surface->compositor); |
| 1991 | } |
| 1992 | |
| 1993 | wl_list_remove(&view->link); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1994 | weston_layer_entry_remove(&view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1995 | |
| 1996 | pixman_region32_fini(&view->clip); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1997 | pixman_region32_fini(&view->geometry.scissor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1998 | pixman_region32_fini(&view->transform.boundingbox); |
Pekka Paalanen | 8844bf2 | 2015-02-18 16:30:47 +0200 | [diff] [blame] | 1999 | pixman_region32_fini(&view->transform.opaque); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2000 | |
| 2001 | weston_view_set_transform_parent(view, NULL); |
Pekka Paalanen | 944fae8 | 2018-05-22 13:15:58 +0300 | [diff] [blame] | 2002 | weston_view_set_output(view, NULL); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2003 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2004 | wl_list_remove(&view->surface_link); |
| 2005 | |
| 2006 | free(view); |
| 2007 | } |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2008 | |
| 2009 | WL_EXPORT void |
| 2010 | weston_surface_destroy(struct weston_surface *surface) |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 2011 | { |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 2012 | struct weston_frame_callback *cb, *next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2013 | struct weston_view *ev, *nv; |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 2014 | struct weston_pointer_constraint *constraint, *next_constraint; |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 2015 | |
Giulio Camuffo | 13b85bd | 2013-08-13 23:10:14 +0200 | [diff] [blame] | 2016 | if (--surface->ref_count > 0) |
| 2017 | return; |
| 2018 | |
Pekka Paalanen | 08d3fb7 | 2015-04-17 14:00:24 +0300 | [diff] [blame] | 2019 | assert(surface->resource == NULL); |
| 2020 | |
Pekka Paalanen | ca79076 | 2015-04-17 14:23:38 +0300 | [diff] [blame] | 2021 | wl_signal_emit(&surface->destroy_signal, surface); |
Giulio Camuffo | 13b85bd | 2013-08-13 23:10:14 +0200 | [diff] [blame] | 2022 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2023 | assert(wl_list_empty(&surface->subsurface_list_pending)); |
| 2024 | assert(wl_list_empty(&surface->subsurface_list)); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 2025 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2026 | wl_list_for_each_safe(ev, nv, &surface->views, surface_link) |
| 2027 | weston_view_destroy(ev); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 2028 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2029 | weston_surface_state_fini(&surface->pending); |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2030 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2031 | weston_buffer_reference(&surface->buffer_ref, NULL); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2032 | weston_buffer_release_reference(&surface->buffer_release_ref, NULL); |
Kristian Høgsberg | 3f8f39c | 2009-09-18 17:05:13 -0400 | [diff] [blame] | 2033 | |
Pekka Paalanen | 402ae6d | 2012-01-03 10:23:24 +0200 | [diff] [blame] | 2034 | pixman_region32_fini(&surface->damage); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2035 | pixman_region32_fini(&surface->opaque); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 2036 | pixman_region32_fini(&surface->input); |
Pekka Paalanen | 402ae6d | 2012-01-03 10:23:24 +0200 | [diff] [blame] | 2037 | |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 2038 | wl_list_for_each_safe(cb, next, &surface->frame_callback_list, link) |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 2039 | wl_resource_destroy(cb->resource); |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 2040 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2041 | weston_presentation_feedback_discard_list(&surface->feedback_list); |
| 2042 | |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 2043 | wl_list_for_each_safe(constraint, next_constraint, |
| 2044 | &surface->pointer_constraints, |
| 2045 | link) |
| 2046 | weston_pointer_constraint_destroy(constraint); |
| 2047 | |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2048 | fd_clear(&surface->acquire_fence_fd); |
| 2049 | |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 2050 | free(surface); |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 2051 | } |
| 2052 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2053 | static void |
| 2054 | destroy_surface(struct wl_resource *resource) |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 2055 | { |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2056 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 2057 | |
Pekka Paalanen | 08d3fb7 | 2015-04-17 14:00:24 +0300 | [diff] [blame] | 2058 | assert(surface); |
| 2059 | |
Giulio Camuffo | 0d37974 | 2013-11-15 22:06:15 +0100 | [diff] [blame] | 2060 | /* Set the resource to NULL, since we don't want to leave a |
| 2061 | * dangling pointer if the surface was refcounted and survives |
| 2062 | * the weston_surface_destroy() call. */ |
| 2063 | surface->resource = NULL; |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 2064 | |
| 2065 | if (surface->viewport_resource) |
| 2066 | wl_resource_set_user_data(surface->viewport_resource, NULL); |
| 2067 | |
Alexandros Frantzis | 27d7c39 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2068 | if (surface->synchronization_resource) { |
| 2069 | wl_resource_set_user_data(surface->synchronization_resource, |
| 2070 | NULL); |
| 2071 | } |
| 2072 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 2073 | weston_surface_destroy(surface); |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 2074 | } |
| 2075 | |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 2076 | static void |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2077 | weston_buffer_destroy_handler(struct wl_listener *listener, void *data) |
| 2078 | { |
| 2079 | struct weston_buffer *buffer = |
| 2080 | container_of(listener, struct weston_buffer, destroy_listener); |
| 2081 | |
| 2082 | wl_signal_emit(&buffer->destroy_signal, buffer); |
| 2083 | free(buffer); |
| 2084 | } |
| 2085 | |
Giulio Camuffo | e058cd1 | 2013-12-12 14:14:29 +0100 | [diff] [blame] | 2086 | WL_EXPORT struct weston_buffer * |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2087 | weston_buffer_from_resource(struct wl_resource *resource) |
| 2088 | { |
| 2089 | struct weston_buffer *buffer; |
| 2090 | struct wl_listener *listener; |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 2091 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2092 | listener = wl_resource_get_destroy_listener(resource, |
| 2093 | weston_buffer_destroy_handler); |
| 2094 | |
Kristian Høgsberg | 08b58c7 | 2013-08-15 12:26:42 -0700 | [diff] [blame] | 2095 | if (listener) |
| 2096 | return container_of(listener, struct weston_buffer, |
| 2097 | destroy_listener); |
| 2098 | |
| 2099 | buffer = zalloc(sizeof *buffer); |
| 2100 | if (buffer == NULL) |
| 2101 | return NULL; |
| 2102 | |
| 2103 | buffer->resource = resource; |
| 2104 | wl_signal_init(&buffer->destroy_signal); |
| 2105 | buffer->destroy_listener.notify = weston_buffer_destroy_handler; |
Stanislav Vorobiov | bfbb8e5 | 2013-08-29 11:36:44 +0400 | [diff] [blame] | 2106 | buffer->y_inverted = 1; |
Kristian Høgsberg | 08b58c7 | 2013-08-15 12:26:42 -0700 | [diff] [blame] | 2107 | wl_resource_add_destroy_listener(resource, &buffer->destroy_listener); |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 2108 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2109 | return buffer; |
| 2110 | } |
| 2111 | |
| 2112 | static void |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2113 | weston_buffer_reference_handle_destroy(struct wl_listener *listener, |
| 2114 | void *data) |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 2115 | { |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2116 | struct weston_buffer_reference *ref = |
| 2117 | container_of(listener, struct weston_buffer_reference, |
| 2118 | destroy_listener); |
| 2119 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2120 | assert((struct weston_buffer *)data == ref->buffer); |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2121 | ref->buffer = NULL; |
| 2122 | } |
| 2123 | |
| 2124 | WL_EXPORT void |
| 2125 | weston_buffer_reference(struct weston_buffer_reference *ref, |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2126 | struct weston_buffer *buffer) |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2127 | { |
| 2128 | if (ref->buffer && buffer != ref->buffer) { |
Kristian Høgsberg | 2034780 | 2013-03-04 12:07:46 -0500 | [diff] [blame] | 2129 | ref->buffer->busy_count--; |
| 2130 | if (ref->buffer->busy_count == 0) { |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2131 | assert(wl_resource_get_client(ref->buffer->resource)); |
Matt Hoosier | 3052bc7 | 2017-09-26 08:09:40 -0500 | [diff] [blame] | 2132 | wl_buffer_send_release(ref->buffer->resource); |
Kristian Høgsberg | 2034780 | 2013-03-04 12:07:46 -0500 | [diff] [blame] | 2133 | } |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2134 | wl_list_remove(&ref->destroy_listener.link); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2135 | } |
| 2136 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2137 | if (buffer && buffer != ref->buffer) { |
Kristian Høgsberg | b7b77e6 | 2012-09-05 22:38:18 -0400 | [diff] [blame] | 2138 | buffer->busy_count++; |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2139 | wl_signal_add(&buffer->destroy_signal, |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2140 | &ref->destroy_listener); |
Pekka Paalanen | a6421c4 | 2012-12-04 15:58:10 +0200 | [diff] [blame] | 2141 | } |
| 2142 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2143 | ref->buffer = buffer; |
| 2144 | ref->destroy_listener.notify = weston_buffer_reference_handle_destroy; |
| 2145 | } |
| 2146 | |
| 2147 | static void |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2148 | weston_buffer_release_reference_handle_destroy(struct wl_listener *listener, |
| 2149 | void *data) |
| 2150 | { |
| 2151 | struct weston_buffer_release_reference *ref = |
| 2152 | container_of(listener, struct weston_buffer_release_reference, |
| 2153 | destroy_listener); |
| 2154 | |
| 2155 | assert((struct wl_resource *)data == ref->buffer_release->resource); |
| 2156 | ref->buffer_release = NULL; |
| 2157 | } |
| 2158 | |
| 2159 | static void |
| 2160 | weston_buffer_release_destroy(struct weston_buffer_release *buffer_release) |
| 2161 | { |
| 2162 | struct wl_resource *resource = buffer_release->resource; |
| 2163 | int release_fence_fd = buffer_release->fence_fd; |
| 2164 | |
| 2165 | if (release_fence_fd >= 0) { |
| 2166 | zwp_linux_buffer_release_v1_send_fenced_release( |
| 2167 | resource, release_fence_fd); |
| 2168 | } else { |
| 2169 | zwp_linux_buffer_release_v1_send_immediate_release( |
| 2170 | resource); |
| 2171 | } |
| 2172 | |
| 2173 | wl_resource_destroy(resource); |
| 2174 | } |
| 2175 | |
| 2176 | WL_EXPORT void |
| 2177 | weston_buffer_release_reference(struct weston_buffer_release_reference *ref, |
| 2178 | struct weston_buffer_release *buffer_release) |
| 2179 | { |
| 2180 | if (buffer_release == ref->buffer_release) |
| 2181 | return; |
| 2182 | |
| 2183 | if (ref->buffer_release) { |
| 2184 | ref->buffer_release->ref_count--; |
| 2185 | wl_list_remove(&ref->destroy_listener.link); |
| 2186 | if (ref->buffer_release->ref_count == 0) |
| 2187 | weston_buffer_release_destroy(ref->buffer_release); |
| 2188 | } |
| 2189 | |
| 2190 | if (buffer_release) { |
| 2191 | buffer_release->ref_count++; |
| 2192 | wl_resource_add_destroy_listener(buffer_release->resource, |
| 2193 | &ref->destroy_listener); |
| 2194 | } |
| 2195 | |
| 2196 | ref->buffer_release = buffer_release; |
| 2197 | ref->destroy_listener.notify = |
| 2198 | weston_buffer_release_reference_handle_destroy; |
| 2199 | } |
| 2200 | |
| 2201 | WL_EXPORT void |
| 2202 | weston_buffer_release_move(struct weston_buffer_release_reference *dest, |
| 2203 | struct weston_buffer_release_reference *src) |
| 2204 | { |
| 2205 | weston_buffer_release_reference(dest, src->buffer_release); |
| 2206 | weston_buffer_release_reference(src, NULL); |
| 2207 | } |
| 2208 | |
| 2209 | static void |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2210 | weston_surface_attach(struct weston_surface *surface, |
| 2211 | struct weston_buffer *buffer) |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2212 | { |
| 2213 | weston_buffer_reference(&surface->buffer_ref, buffer); |
| 2214 | |
Pekka Paalanen | a6421c4 | 2012-12-04 15:58:10 +0200 | [diff] [blame] | 2215 | if (!buffer) { |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2216 | if (weston_surface_is_mapped(surface)) |
| 2217 | weston_surface_unmap(surface); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2218 | } |
| 2219 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2220 | surface->compositor->renderer->attach(surface, buffer); |
Pekka Paalanen | bb2f3f2 | 2014-03-14 14:38:11 +0200 | [diff] [blame] | 2221 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 2222 | weston_surface_calculate_size_from_buffer(surface); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2223 | weston_presentation_feedback_discard_list(&surface->feedback_list); |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 2224 | } |
| 2225 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2226 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2227 | weston_compositor_damage_all(struct weston_compositor *compositor) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2228 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2229 | struct weston_output *output; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2230 | |
| 2231 | wl_list_for_each(output, &compositor->output_list, link) |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2232 | weston_output_damage(output); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2233 | } |
| 2234 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame^] | 2235 | /** |
| 2236 | * \ingroup output |
| 2237 | */ |
Kristian Høgsberg | 9f404b7 | 2012-01-26 00:11:01 -0500 | [diff] [blame] | 2238 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2239 | weston_output_damage(struct weston_output *output) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2240 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2241 | struct weston_compositor *compositor = output->compositor; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2242 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 2243 | pixman_region32_union(&compositor->primary_plane.damage, |
| 2244 | &compositor->primary_plane.damage, |
| 2245 | &output->region); |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2246 | weston_output_schedule_repaint(output); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2247 | } |
| 2248 | |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame] | 2249 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2250 | surface_flush_damage(struct weston_surface *surface) |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2251 | { |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2252 | if (surface->buffer_ref.buffer && |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2253 | wl_shm_buffer_get(surface->buffer_ref.buffer->resource)) |
Kristian Høgsberg | fa1be02 | 2012-09-05 22:49:55 -0400 | [diff] [blame] | 2254 | surface->compositor->renderer->flush_damage(surface); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2255 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2256 | if (weston_timeline_enabled_ && |
| 2257 | pixman_region32_not_empty(&surface->damage)) |
| 2258 | TL_POINT("core_flush_damage", TLP_SURFACE(surface), |
| 2259 | TLP_OUTPUT(surface->output), TLP_END); |
| 2260 | |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 2261 | pixman_region32_clear(&surface->damage); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2262 | } |
| 2263 | |
| 2264 | static void |
| 2265 | view_accumulate_damage(struct weston_view *view, |
| 2266 | pixman_region32_t *opaque) |
| 2267 | { |
| 2268 | pixman_region32_t damage; |
| 2269 | |
| 2270 | pixman_region32_init(&damage); |
| 2271 | if (view->transform.enabled) { |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2272 | pixman_box32_t *extents; |
| 2273 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2274 | extents = pixman_region32_extents(&view->surface->damage); |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 2275 | view_compute_bbox(view, extents, &damage); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2276 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2277 | pixman_region32_copy(&damage, &view->surface->damage); |
| 2278 | pixman_region32_translate(&damage, |
Pekka Paalanen | 502f5e0 | 2015-02-23 14:08:25 +0200 | [diff] [blame] | 2279 | view->geometry.x, view->geometry.y); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2280 | } |
| 2281 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 2282 | pixman_region32_intersect(&damage, &damage, |
| 2283 | &view->transform.boundingbox); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2284 | pixman_region32_subtract(&damage, &damage, opaque); |
| 2285 | pixman_region32_union(&view->plane->damage, |
| 2286 | &view->plane->damage, &damage); |
| 2287 | pixman_region32_fini(&damage); |
| 2288 | pixman_region32_copy(&view->clip, opaque); |
Pekka Paalanen | 8844bf2 | 2015-02-18 16:30:47 +0200 | [diff] [blame] | 2289 | pixman_region32_union(opaque, opaque, &view->transform.opaque); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2290 | } |
| 2291 | |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 2292 | static void |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2293 | compositor_accumulate_damage(struct weston_compositor *ec) |
| 2294 | { |
| 2295 | struct weston_plane *plane; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2296 | struct weston_view *ev; |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2297 | pixman_region32_t opaque, clip; |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2298 | |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2299 | pixman_region32_init(&clip); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2300 | |
| 2301 | wl_list_for_each(plane, &ec->plane_list, link) { |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2302 | pixman_region32_copy(&plane->clip, &clip); |
| 2303 | |
| 2304 | pixman_region32_init(&opaque); |
| 2305 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2306 | wl_list_for_each(ev, &ec->view_list, link) { |
| 2307 | if (ev->plane != plane) |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2308 | continue; |
| 2309 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2310 | view_accumulate_damage(ev, &opaque); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2311 | } |
| 2312 | |
| 2313 | pixman_region32_union(&clip, &clip, &opaque); |
| 2314 | pixman_region32_fini(&opaque); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2315 | } |
| 2316 | |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2317 | pixman_region32_fini(&clip); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2318 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2319 | wl_list_for_each(ev, &ec->view_list, link) |
Derek Foreman | 060cf11 | 2015-11-18 16:32:26 -0600 | [diff] [blame] | 2320 | ev->surface->touched = false; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2321 | |
| 2322 | wl_list_for_each(ev, &ec->view_list, link) { |
| 2323 | if (ev->surface->touched) |
| 2324 | continue; |
Derek Foreman | 060cf11 | 2015-11-18 16:32:26 -0600 | [diff] [blame] | 2325 | ev->surface->touched = true; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2326 | |
| 2327 | surface_flush_damage(ev->surface); |
| 2328 | |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2329 | /* Both the renderer and the backend have seen the buffer |
| 2330 | * by now. If renderer needs the buffer, it has its own |
| 2331 | * reference set. If the backend wants to keep the buffer |
| 2332 | * around for migrating the surface into a non-primary plane |
| 2333 | * later, keep_buffer is true. Otherwise, drop the core |
| 2334 | * reference now, and allow early buffer release. This enables |
| 2335 | * clients to use single-buffering. |
| 2336 | */ |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2337 | if (!ev->surface->keep_buffer) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2338 | weston_buffer_reference(&ev->surface->buffer_ref, NULL); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 2339 | weston_buffer_release_reference( |
| 2340 | &ev->surface->buffer_release_ref, NULL); |
| 2341 | } |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2342 | } |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2343 | } |
| 2344 | |
| 2345 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2346 | surface_stash_subsurface_views(struct weston_surface *surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2347 | { |
| 2348 | struct weston_subsurface *sub; |
| 2349 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2350 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2351 | if (sub->surface == surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2352 | continue; |
| 2353 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2354 | wl_list_insert_list(&sub->unused_views, &sub->surface->views); |
| 2355 | wl_list_init(&sub->surface->views); |
| 2356 | |
| 2357 | surface_stash_subsurface_views(sub->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2358 | } |
| 2359 | } |
| 2360 | |
| 2361 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2362 | surface_free_unused_subsurface_views(struct weston_surface *surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2363 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2364 | struct weston_subsurface *sub; |
| 2365 | struct weston_view *view, *nv; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2366 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2367 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
| 2368 | if (sub->surface == surface) |
| 2369 | continue; |
| 2370 | |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 2371 | wl_list_for_each_safe(view, nv, &sub->unused_views, surface_link) { |
| 2372 | weston_view_unmap (view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2373 | weston_view_destroy(view); |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 2374 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2375 | |
| 2376 | surface_free_unused_subsurface_views(sub->surface); |
| 2377 | } |
| 2378 | } |
| 2379 | |
| 2380 | static void |
| 2381 | view_list_add_subsurface_view(struct weston_compositor *compositor, |
| 2382 | struct weston_subsurface *sub, |
| 2383 | struct weston_view *parent) |
| 2384 | { |
| 2385 | struct weston_subsurface *child; |
| 2386 | struct weston_view *view = NULL, *iv; |
| 2387 | |
Pekka Paalanen | 661de3a | 2014-07-28 12:49:24 +0300 | [diff] [blame] | 2388 | if (!weston_surface_is_mapped(sub->surface)) |
| 2389 | return; |
| 2390 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2391 | wl_list_for_each(iv, &sub->unused_views, surface_link) { |
| 2392 | if (iv->geometry.parent == parent) { |
| 2393 | view = iv; |
| 2394 | break; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2395 | } |
| 2396 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2397 | |
| 2398 | if (view) { |
| 2399 | /* Put it back in the surface's list of views */ |
| 2400 | wl_list_remove(&view->surface_link); |
| 2401 | wl_list_insert(&sub->surface->views, &view->surface_link); |
| 2402 | } else { |
| 2403 | view = weston_view_create(sub->surface); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2404 | weston_view_set_position(view, |
| 2405 | sub->position.x, |
| 2406 | sub->position.y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2407 | weston_view_set_transform_parent(view, parent); |
| 2408 | } |
| 2409 | |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 2410 | view->parent_view = parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2411 | weston_view_update_transform(view); |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 2412 | view->is_mapped = true; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2413 | |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2414 | if (wl_list_empty(&sub->surface->subsurface_list)) { |
| 2415 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 2416 | return; |
| 2417 | } |
| 2418 | |
| 2419 | wl_list_for_each(child, &sub->surface->subsurface_list, parent_link) { |
| 2420 | if (child->surface == sub->surface) |
| 2421 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 2422 | else |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2423 | view_list_add_subsurface_view(compositor, child, view); |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2424 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2425 | } |
| 2426 | |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 2427 | /* This recursively adds the sub-surfaces for a view, relying on the |
| 2428 | * sub-surface order. Thus, if a client restacks the sub-surfaces, that |
| 2429 | * change first happens to the sub-surface list, and then automatically |
| 2430 | * propagates here. See weston_surface_damage_subsurfaces() for how the |
| 2431 | * sub-surfaces receive damage when the client changes the state. |
| 2432 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2433 | static void |
| 2434 | view_list_add(struct weston_compositor *compositor, |
| 2435 | struct weston_view *view) |
| 2436 | { |
| 2437 | struct weston_subsurface *sub; |
| 2438 | |
| 2439 | weston_view_update_transform(view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2440 | |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2441 | if (wl_list_empty(&view->surface->subsurface_list)) { |
| 2442 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 2443 | return; |
| 2444 | } |
| 2445 | |
| 2446 | wl_list_for_each(sub, &view->surface->subsurface_list, parent_link) { |
| 2447 | if (sub->surface == view->surface) |
| 2448 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 2449 | else |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2450 | view_list_add_subsurface_view(compositor, sub, view); |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2451 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2452 | } |
| 2453 | |
| 2454 | static void |
| 2455 | weston_compositor_build_view_list(struct weston_compositor *compositor) |
| 2456 | { |
| 2457 | struct weston_view *view; |
| 2458 | struct weston_layer *layer; |
| 2459 | |
| 2460 | wl_list_for_each(layer, &compositor->layer_list, link) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2461 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2462 | surface_stash_subsurface_views(view->surface); |
| 2463 | |
| 2464 | wl_list_init(&compositor->view_list); |
| 2465 | wl_list_for_each(layer, &compositor->layer_list, link) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2466 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2467 | view_list_add(compositor, view); |
| 2468 | } |
| 2469 | } |
| 2470 | |
| 2471 | wl_list_for_each(layer, &compositor->layer_list, link) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2472 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2473 | surface_free_unused_subsurface_views(view->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2474 | } |
| 2475 | |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2476 | static void |
| 2477 | weston_output_take_feedback_list(struct weston_output *output, |
| 2478 | struct weston_surface *surface) |
| 2479 | { |
| 2480 | struct weston_view *view; |
| 2481 | struct weston_presentation_feedback *feedback; |
| 2482 | uint32_t flags = 0xffffffff; |
| 2483 | |
| 2484 | if (wl_list_empty(&surface->feedback_list)) |
| 2485 | return; |
| 2486 | |
| 2487 | /* All views must have the flag for the flag to survive. */ |
| 2488 | wl_list_for_each(view, &surface->views, surface_link) { |
| 2489 | /* ignore views that are not on this output at all */ |
| 2490 | if (view->output_mask & (1u << output->id)) |
| 2491 | flags &= view->psf_flags; |
| 2492 | } |
| 2493 | |
| 2494 | wl_list_for_each(feedback, &surface->feedback_list, link) |
| 2495 | feedback->psf_flags = flags; |
| 2496 | |
| 2497 | wl_list_insert_list(&output->feedback_list, &surface->feedback_list); |
| 2498 | wl_list_init(&surface->feedback_list); |
| 2499 | } |
| 2500 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2501 | static int |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2502 | weston_output_repaint(struct weston_output *output, void *repaint_data) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2503 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2504 | struct weston_compositor *ec = output->compositor; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2505 | struct weston_view *ev; |
Kristian Høgsberg | 30c018b | 2012-01-26 08:40:37 -0500 | [diff] [blame] | 2506 | struct weston_animation *animation, *next; |
| 2507 | struct weston_frame_callback *cb, *cnext; |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 2508 | struct wl_list frame_callback_list; |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2509 | pixman_region32_t output_damage; |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2510 | int r; |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 2511 | uint32_t frame_time_msec; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 2512 | |
Ander Conselvan de Oliveira | e1e2352 | 2013-12-13 22:10:55 +0200 | [diff] [blame] | 2513 | if (output->destroying) |
| 2514 | return 0; |
| 2515 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2516 | TL_POINT("core_repaint_begin", TLP_OUTPUT(output), TLP_END); |
| 2517 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2518 | /* Rebuild the surface list and update surface transforms up front. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2519 | weston_compositor_build_view_list(ec); |
Pekka Paalanen | 15d60ef | 2012-01-27 14:38:33 +0200 | [diff] [blame] | 2520 | |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2521 | if (output->assign_planes && !output->disable_planes) { |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2522 | output->assign_planes(output, repaint_data); |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2523 | } else { |
| 2524 | wl_list_for_each(ev, &ec->view_list, link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2525 | weston_view_move_to_plane(ev, &ec->primary_plane); |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2526 | ev->psf_flags = 0; |
| 2527 | } |
| 2528 | } |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 2529 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2530 | wl_list_init(&frame_callback_list); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2531 | wl_list_for_each(ev, &ec->view_list, link) { |
| 2532 | /* Note: This operation is safe to do multiple times on the |
| 2533 | * same surface. |
| 2534 | */ |
| 2535 | if (ev->surface->output == output) { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2536 | wl_list_insert_list(&frame_callback_list, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2537 | &ev->surface->frame_callback_list); |
| 2538 | wl_list_init(&ev->surface->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2539 | |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2540 | weston_output_take_feedback_list(output, ev->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2541 | } |
| 2542 | } |
| 2543 | |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2544 | compositor_accumulate_damage(ec); |
Kristian Høgsberg | 53df1d8 | 2011-06-23 21:11:19 -0400 | [diff] [blame] | 2545 | |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 2546 | pixman_region32_init(&output_damage); |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 2547 | pixman_region32_intersect(&output_damage, |
| 2548 | &ec->primary_plane.damage, &output->region); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2549 | pixman_region32_subtract(&output_damage, |
| 2550 | &output_damage, &ec->primary_plane.clip); |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 2551 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2552 | if (output->dirty) |
| 2553 | weston_output_update_matrix(output); |
| 2554 | |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2555 | r = output->repaint(output, &output_damage, repaint_data); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2556 | |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 2557 | pixman_region32_fini(&output_damage); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 2558 | |
Daniel Stone | 09a97e2 | 2017-03-01 11:34:06 +0000 | [diff] [blame] | 2559 | output->repaint_needed = false; |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2560 | if (r == 0) |
| 2561 | output->repaint_status = REPAINT_AWAITING_COMPLETION; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 2562 | |
Kristian Høgsberg | aa6019e | 2012-03-11 16:35:16 -0400 | [diff] [blame] | 2563 | weston_compositor_repick(ec); |
Kristian Høgsberg | aa6019e | 2012-03-11 16:35:16 -0400 | [diff] [blame] | 2564 | |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 2565 | frame_time_msec = timespec_to_msec(&output->frame_time); |
| 2566 | |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 2567 | wl_list_for_each_safe(cb, cnext, &frame_callback_list, link) { |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 2568 | wl_callback_send_done(cb->resource, frame_time_msec); |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 2569 | wl_resource_destroy(cb->resource); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 2570 | } |
| 2571 | |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 2572 | wl_list_for_each_safe(animation, next, &output->animation_list, link) { |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 2573 | animation->frame_counter++; |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 2574 | animation->frame(animation, output, &output->frame_time); |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 2575 | } |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2576 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2577 | TL_POINT("core_repaint_posted", TLP_OUTPUT(output), TLP_END); |
| 2578 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2579 | return r; |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2580 | } |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 2581 | |
Pekka Paalanen | 8291979 | 2014-05-21 13:51:49 +0300 | [diff] [blame] | 2582 | static void |
| 2583 | weston_output_schedule_repaint_reset(struct weston_output *output) |
| 2584 | { |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2585 | output->repaint_status = REPAINT_NOT_SCHEDULED; |
Pekka Paalanen | 8291979 | 2014-05-21 13:51:49 +0300 | [diff] [blame] | 2586 | TL_POINT("core_repaint_exit_loop", TLP_OUTPUT(output), TLP_END); |
Pekka Paalanen | 8291979 | 2014-05-21 13:51:49 +0300 | [diff] [blame] | 2587 | } |
| 2588 | |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2589 | static int |
| 2590 | weston_output_maybe_repaint(struct weston_output *output, struct timespec *now, |
| 2591 | void *repaint_data) |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2592 | { |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2593 | struct weston_compositor *compositor = output->compositor; |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2594 | int ret = 0; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2595 | int64_t msec_to_repaint; |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2596 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2597 | /* We're not ready yet; come back to make a decision later. */ |
| 2598 | if (output->repaint_status != REPAINT_SCHEDULED) |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2599 | return ret; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2600 | |
| 2601 | msec_to_repaint = timespec_sub_to_msec(&output->next_repaint, now); |
| 2602 | if (msec_to_repaint > 1) |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2603 | return ret; |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2604 | |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 2605 | /* If we're sleeping, drop the repaint machinery entirely; we will |
| 2606 | * explicitly repaint all outputs when we come back. */ |
| 2607 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING || |
| 2608 | compositor->state == WESTON_COMPOSITOR_OFFSCREEN) |
| 2609 | goto err; |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2610 | |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 2611 | /* We don't actually need to repaint this output; drop it from |
| 2612 | * repaint until something causes damage. */ |
| 2613 | if (!output->repaint_needed) |
| 2614 | goto err; |
| 2615 | |
| 2616 | /* If repaint fails, we aren't going to get weston_output_finish_frame |
| 2617 | * to trigger a new repaint, so drop it from repaint and hope |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2618 | * something schedules a successful repaint later. As repainting may |
| 2619 | * take some time, re-read our clock as a courtesy to the next |
| 2620 | * output. */ |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2621 | ret = weston_output_repaint(output, repaint_data); |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2622 | weston_compositor_read_presentation_clock(compositor, now); |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 2623 | if (ret != 0) |
| 2624 | goto err; |
| 2625 | |
Tomohito Esaki | 7f4d9ff | 2018-06-05 10:37:06 +0900 | [diff] [blame] | 2626 | output->repainted = true; |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2627 | return ret; |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 2628 | |
| 2629 | err: |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2630 | weston_output_schedule_repaint_reset(output); |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2631 | return ret; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2632 | } |
| 2633 | |
| 2634 | static void |
| 2635 | output_repaint_timer_arm(struct weston_compositor *compositor) |
| 2636 | { |
| 2637 | struct weston_output *output; |
| 2638 | bool any_should_repaint = false; |
| 2639 | struct timespec now; |
Sergi Granell | b4c0886 | 2017-03-18 13:01:15 +0100 | [diff] [blame] | 2640 | int64_t msec_to_next = INT64_MAX; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2641 | |
| 2642 | weston_compositor_read_presentation_clock(compositor, &now); |
| 2643 | |
| 2644 | wl_list_for_each(output, &compositor->output_list, link) { |
| 2645 | int64_t msec_to_this; |
| 2646 | |
| 2647 | if (output->repaint_status != REPAINT_SCHEDULED) |
| 2648 | continue; |
| 2649 | |
| 2650 | msec_to_this = timespec_sub_to_msec(&output->next_repaint, |
| 2651 | &now); |
| 2652 | if (!any_should_repaint || msec_to_this < msec_to_next) |
| 2653 | msec_to_next = msec_to_this; |
| 2654 | |
| 2655 | any_should_repaint = true; |
| 2656 | } |
| 2657 | |
| 2658 | if (!any_should_repaint) |
| 2659 | return; |
| 2660 | |
| 2661 | /* Even if we should repaint immediately, add the minimum 1 ms delay. |
| 2662 | * This is a workaround to allow coalescing multiple output repaints |
| 2663 | * particularly from weston_output_finish_frame() |
| 2664 | * into the same call, which would not happen if we called |
| 2665 | * output_repaint_timer_handler() directly. |
| 2666 | */ |
| 2667 | if (msec_to_next < 1) |
| 2668 | msec_to_next = 1; |
| 2669 | |
| 2670 | wl_event_source_timer_update(compositor->repaint_timer, msec_to_next); |
| 2671 | } |
| 2672 | |
| 2673 | static int |
| 2674 | output_repaint_timer_handler(void *data) |
| 2675 | { |
| 2676 | struct weston_compositor *compositor = data; |
| 2677 | struct weston_output *output; |
| 2678 | struct timespec now; |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2679 | void *repaint_data = NULL; |
Emre Ucan | e479ed8 | 2018-03-20 15:29:40 +0100 | [diff] [blame] | 2680 | int ret = 0; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2681 | |
| 2682 | weston_compositor_read_presentation_clock(compositor, &now); |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2683 | |
| 2684 | if (compositor->backend->repaint_begin) |
| 2685 | repaint_data = compositor->backend->repaint_begin(compositor); |
| 2686 | |
| 2687 | wl_list_for_each(output, &compositor->output_list, link) { |
| 2688 | ret = weston_output_maybe_repaint(output, &now, repaint_data); |
| 2689 | if (ret) |
| 2690 | break; |
| 2691 | } |
| 2692 | |
| 2693 | if (ret == 0) { |
Tomohito Esaki | 09bfcd6 | 2018-06-05 10:37:05 +0900 | [diff] [blame] | 2694 | if (compositor->backend->repaint_flush) |
| 2695 | compositor->backend->repaint_flush(compositor, |
| 2696 | repaint_data); |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2697 | } else { |
Tomohito Esaki | 7f4d9ff | 2018-06-05 10:37:06 +0900 | [diff] [blame] | 2698 | wl_list_for_each(output, &compositor->output_list, link) { |
| 2699 | if (output->repainted) |
| 2700 | weston_output_schedule_repaint_reset(output); |
| 2701 | } |
| 2702 | |
Tomohito Esaki | 09bfcd6 | 2018-06-05 10:37:05 +0900 | [diff] [blame] | 2703 | if (compositor->backend->repaint_cancel) |
| 2704 | compositor->backend->repaint_cancel(compositor, |
| 2705 | repaint_data); |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2706 | } |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2707 | |
Tomohito Esaki | ddaf95c | 2018-07-10 11:47:15 +0900 | [diff] [blame] | 2708 | wl_list_for_each(output, &compositor->output_list, link) |
| 2709 | output->repainted = false; |
| 2710 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2711 | output_repaint_timer_arm(compositor); |
| 2712 | |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2713 | return 0; |
| 2714 | } |
| 2715 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame^] | 2716 | /** |
| 2717 | * \ingroup output |
| 2718 | */ |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2719 | WL_EXPORT void |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 2720 | weston_output_finish_frame(struct weston_output *output, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 2721 | const struct timespec *stamp, |
| 2722 | uint32_t presented_flags) |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2723 | { |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2724 | struct weston_compositor *compositor = output->compositor; |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2725 | int32_t refresh_nsec; |
| 2726 | struct timespec now; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2727 | int64_t msec_rel; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2728 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2729 | |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2730 | assert(output->repaint_status == REPAINT_AWAITING_COMPLETION); |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2731 | assert(stamp || (presented_flags & WP_PRESENTATION_FEEDBACK_INVALID)); |
| 2732 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2733 | weston_compositor_read_presentation_clock(compositor, &now); |
| 2734 | |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2735 | /* If we haven't been supplied any timestamp at all, we don't have a |
| 2736 | * timebase to work against, so any delay just wastes time. Push a |
| 2737 | * repaint as soon as possible so we can get on with it. */ |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2738 | if (!stamp) { |
| 2739 | output->next_repaint = now; |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2740 | goto out; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2741 | } |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2742 | |
Marius Vlad | df9278a | 2018-03-06 18:56:23 +0200 | [diff] [blame] | 2743 | TL_POINT("core_repaint_finished", TLP_OUTPUT(output), |
| 2744 | TLP_VBLANK(stamp), TLP_END); |
| 2745 | |
Pekka Paalanen | d7894d0 | 2015-07-03 15:08:53 +0300 | [diff] [blame] | 2746 | refresh_nsec = millihz_to_nsec(output->current_mode->refresh); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2747 | weston_presentation_feedback_present_list(&output->feedback_list, |
| 2748 | output, refresh_nsec, stamp, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 2749 | output->msc, |
| 2750 | presented_flags); |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2751 | |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 2752 | output->frame_time = *stamp; |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2753 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2754 | timespec_add_nsec(&output->next_repaint, stamp, refresh_nsec); |
| 2755 | timespec_add_msec(&output->next_repaint, &output->next_repaint, |
| 2756 | -compositor->repaint_msec); |
| 2757 | msec_rel = timespec_sub_to_msec(&output->next_repaint, &now); |
Daniel Stone | 84aff5c | 2017-03-01 11:34:04 +0000 | [diff] [blame] | 2758 | |
| 2759 | if (msec_rel < -1000 || msec_rel > 1000) { |
Pekka Paalanen | 8fd4de4 | 2015-03-19 12:27:29 +0200 | [diff] [blame] | 2760 | static bool warned; |
| 2761 | |
| 2762 | if (!warned) |
| 2763 | weston_log("Warning: computed repaint delay is " |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2764 | "insane: %lld msec\n", (long long) msec_rel); |
Pekka Paalanen | 8fd4de4 | 2015-03-19 12:27:29 +0200 | [diff] [blame] | 2765 | warned = true; |
| 2766 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2767 | output->next_repaint = now; |
Pekka Paalanen | 8fd4de4 | 2015-03-19 12:27:29 +0200 | [diff] [blame] | 2768 | } |
| 2769 | |
Mario Kleiner | b7df04e | 2015-06-21 21:25:15 +0200 | [diff] [blame] | 2770 | /* Called from restart_repaint_loop and restart happens already after |
| 2771 | * the deadline given by repaint_msec? In that case we delay until |
| 2772 | * the deadline of the next frame, to give clients a more predictable |
| 2773 | * timing of the repaint cycle to lock on. */ |
Daniel Stone | eca5cca | 2017-02-28 21:53:51 +0000 | [diff] [blame] | 2774 | if (presented_flags == WP_PRESENTATION_FEEDBACK_INVALID && |
| 2775 | msec_rel < 0) { |
| 2776 | while (timespec_sub_to_nsec(&output->next_repaint, &now) < 0) { |
| 2777 | timespec_add_nsec(&output->next_repaint, |
| 2778 | &output->next_repaint, |
| 2779 | refresh_nsec); |
| 2780 | } |
| 2781 | } |
Mario Kleiner | b7df04e | 2015-06-21 21:25:15 +0200 | [diff] [blame] | 2782 | |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2783 | out: |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2784 | output->repaint_status = REPAINT_SCHEDULED; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2785 | output_repaint_timer_arm(compositor); |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2786 | } |
| 2787 | |
| 2788 | static void |
| 2789 | idle_repaint(void *data) |
| 2790 | { |
| 2791 | struct weston_output *output = data; |
| 2792 | |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2793 | assert(output->repaint_status == REPAINT_BEGIN_FROM_IDLE); |
| 2794 | output->repaint_status = REPAINT_AWAITING_COMPLETION; |
Pekka Paalanen | dcbcfc7 | 2017-10-26 14:33:59 +0300 | [diff] [blame] | 2795 | output->idle_repaint_source = NULL; |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 2796 | output->start_repaint_loop(output); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2797 | } |
| 2798 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2799 | WL_EXPORT void |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2800 | weston_layer_entry_insert(struct weston_layer_entry *list, |
| 2801 | struct weston_layer_entry *entry) |
| 2802 | { |
| 2803 | wl_list_insert(&list->link, &entry->link); |
| 2804 | entry->layer = list->layer; |
| 2805 | } |
| 2806 | |
| 2807 | WL_EXPORT void |
| 2808 | weston_layer_entry_remove(struct weston_layer_entry *entry) |
| 2809 | { |
| 2810 | wl_list_remove(&entry->link); |
| 2811 | wl_list_init(&entry->link); |
| 2812 | entry->layer = NULL; |
| 2813 | } |
| 2814 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 2815 | |
| 2816 | /** Initialize the weston_layer struct. |
| 2817 | * |
| 2818 | * \param compositor The compositor instance |
| 2819 | * \param layer The layer to initialize |
| 2820 | */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2821 | WL_EXPORT void |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 2822 | weston_layer_init(struct weston_layer *layer, |
| 2823 | struct weston_compositor *compositor) |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2824 | { |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 2825 | layer->compositor = compositor; |
| 2826 | wl_list_init(&layer->link); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2827 | wl_list_init(&layer->view_list.link); |
| 2828 | layer->view_list.layer = layer; |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 2829 | weston_layer_set_mask_infinite(layer); |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 2830 | } |
| 2831 | |
| 2832 | /** Sets the position of the layer in the layer list. The layer will be placed |
| 2833 | * below any layer with the same position value, if any. |
| 2834 | * This function is safe to call if the layer is already on the list, but the |
| 2835 | * layer may be moved below other layers at the same position, if any. |
| 2836 | * |
| 2837 | * \param layer The layer to modify |
| 2838 | * \param position The position the layer will be placed at |
| 2839 | */ |
| 2840 | WL_EXPORT void |
| 2841 | weston_layer_set_position(struct weston_layer *layer, |
| 2842 | enum weston_layer_position position) |
| 2843 | { |
| 2844 | struct weston_layer *below; |
| 2845 | |
| 2846 | wl_list_remove(&layer->link); |
| 2847 | |
| 2848 | /* layer_list is ordered from top to bottom, the last layer being the |
| 2849 | * background with the smallest position value */ |
| 2850 | |
| 2851 | layer->position = position; |
| 2852 | wl_list_for_each_reverse(below, &layer->compositor->layer_list, link) { |
| 2853 | if (below->position >= layer->position) { |
| 2854 | wl_list_insert(&below->link, &layer->link); |
| 2855 | return; |
| 2856 | } |
| 2857 | } |
| 2858 | wl_list_insert(&layer->compositor->layer_list, &layer->link); |
| 2859 | } |
| 2860 | |
| 2861 | /** Hide a layer by taking it off the layer list. |
| 2862 | * This function is safe to call if the layer is not on the list. |
| 2863 | * |
| 2864 | * \param layer The layer to hide |
| 2865 | */ |
| 2866 | WL_EXPORT void |
| 2867 | weston_layer_unset_position(struct weston_layer *layer) |
| 2868 | { |
| 2869 | wl_list_remove(&layer->link); |
| 2870 | wl_list_init(&layer->link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2871 | } |
| 2872 | |
| 2873 | WL_EXPORT void |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 2874 | weston_layer_set_mask(struct weston_layer *layer, |
| 2875 | int x, int y, int width, int height) |
| 2876 | { |
| 2877 | struct weston_view *view; |
| 2878 | |
| 2879 | layer->mask.x1 = x; |
| 2880 | layer->mask.x2 = x + width; |
| 2881 | layer->mask.y1 = y; |
| 2882 | layer->mask.y2 = y + height; |
| 2883 | |
| 2884 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
| 2885 | weston_view_geometry_dirty(view); |
| 2886 | } |
| 2887 | } |
| 2888 | |
| 2889 | WL_EXPORT void |
| 2890 | weston_layer_set_mask_infinite(struct weston_layer *layer) |
| 2891 | { |
| 2892 | weston_layer_set_mask(layer, INT32_MIN, INT32_MIN, |
| 2893 | UINT32_MAX, UINT32_MAX); |
| 2894 | } |
| 2895 | |
Daniel Stone | 3b77563 | 2018-07-20 08:38:25 +0100 | [diff] [blame] | 2896 | WL_EXPORT bool |
| 2897 | weston_layer_mask_is_infinite(struct weston_layer *layer) |
| 2898 | { |
| 2899 | return layer->mask.x1 == INT32_MIN && |
| 2900 | layer->mask.y1 == INT32_MIN && |
| 2901 | layer->mask.x2 == INT32_MIN + UINT32_MAX && |
| 2902 | layer->mask.y2 == INT32_MIN + UINT32_MAX; |
| 2903 | } |
| 2904 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame^] | 2905 | /** |
| 2906 | * \ingroup output |
| 2907 | */ |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 2908 | WL_EXPORT void |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2909 | weston_output_schedule_repaint(struct weston_output *output) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2910 | { |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2911 | struct weston_compositor *compositor = output->compositor; |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2912 | struct wl_event_loop *loop; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 2913 | |
Bryce Harrington | 08976ac | 2016-08-30 12:05:16 -0700 | [diff] [blame] | 2914 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING || |
| 2915 | compositor->state == WESTON_COMPOSITOR_OFFSCREEN) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2916 | return; |
| 2917 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2918 | if (!output->repaint_needed) |
| 2919 | TL_POINT("core_repaint_req", TLP_OUTPUT(output), TLP_END); |
| 2920 | |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2921 | loop = wl_display_get_event_loop(compositor->wl_display); |
Daniel Stone | 09a97e2 | 2017-03-01 11:34:06 +0000 | [diff] [blame] | 2922 | output->repaint_needed = true; |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2923 | |
| 2924 | /* If we already have a repaint scheduled for our idle handler, |
| 2925 | * no need to set it again. If the repaint has been called but |
| 2926 | * not finished, then weston_output_finish_frame() will notice |
| 2927 | * that a repaint is needed and schedule one. */ |
| 2928 | if (output->repaint_status != REPAINT_NOT_SCHEDULED) |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2929 | return; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 2930 | |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2931 | output->repaint_status = REPAINT_BEGIN_FROM_IDLE; |
Pekka Paalanen | dcbcfc7 | 2017-10-26 14:33:59 +0300 | [diff] [blame] | 2932 | assert(!output->idle_repaint_source); |
| 2933 | output->idle_repaint_source = wl_event_loop_add_idle(loop, idle_repaint, |
| 2934 | output); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2935 | TL_POINT("core_repaint_enter_loop", TLP_OUTPUT(output), TLP_END); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2936 | } |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 2937 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2938 | WL_EXPORT void |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2939 | weston_compositor_schedule_repaint(struct weston_compositor *compositor) |
| 2940 | { |
| 2941 | struct weston_output *output; |
| 2942 | |
| 2943 | wl_list_for_each(output, &compositor->output_list, link) |
| 2944 | weston_output_schedule_repaint(output); |
| 2945 | } |
| 2946 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 2947 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 2948 | surface_destroy(struct wl_client *client, struct wl_resource *resource) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 2949 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2950 | wl_resource_destroy(resource); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 2951 | } |
| 2952 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 2953 | static void |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2954 | surface_attach(struct wl_client *client, |
| 2955 | struct wl_resource *resource, |
| 2956 | struct wl_resource *buffer_resource, int32_t sx, int32_t sy) |
| 2957 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2958 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2959 | struct weston_buffer *buffer = NULL; |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2960 | |
Kristian Høgsberg | ab19f93 | 2013-08-20 11:30:54 -0700 | [diff] [blame] | 2961 | if (buffer_resource) { |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2962 | buffer = weston_buffer_from_resource(buffer_resource); |
Kristian Høgsberg | ab19f93 | 2013-08-20 11:30:54 -0700 | [diff] [blame] | 2963 | if (buffer == NULL) { |
| 2964 | wl_client_post_no_memory(client); |
| 2965 | return; |
| 2966 | } |
Kristian Høgsberg | 08b58c7 | 2013-08-15 12:26:42 -0700 | [diff] [blame] | 2967 | } |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 2968 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2969 | /* Attach, attach, without commit in between does not send |
| 2970 | * wl_buffer.release. */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2971 | weston_surface_state_set_buffer(&surface->pending, buffer); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2972 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2973 | surface->pending.sx = sx; |
| 2974 | surface->pending.sy = sy; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2975 | surface->pending.newly_attached = 1; |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 2976 | } |
| 2977 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 2978 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2979 | surface_damage(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 2980 | struct wl_resource *resource, |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2981 | 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] | 2982 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2983 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 9d69f8e | 2010-09-03 14:46:38 -0400 | [diff] [blame] | 2984 | |
Derek Foreman | 57e92ed | 2015-11-17 14:11:35 -0600 | [diff] [blame] | 2985 | if (width <= 0 || height <= 0) |
| 2986 | return; |
| 2987 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 2988 | pixman_region32_union_rect(&surface->pending.damage_surface, |
| 2989 | &surface->pending.damage_surface, |
| 2990 | x, y, width, height); |
| 2991 | } |
| 2992 | |
| 2993 | static void |
| 2994 | surface_damage_buffer(struct wl_client *client, |
| 2995 | struct wl_resource *resource, |
| 2996 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 2997 | { |
| 2998 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
| 2999 | |
| 3000 | if (width <= 0 || height <= 0) |
| 3001 | return; |
| 3002 | |
| 3003 | pixman_region32_union_rect(&surface->pending.damage_buffer, |
| 3004 | &surface->pending.damage_buffer, |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 3005 | x, y, width, height); |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 3006 | } |
| 3007 | |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3008 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 3009 | destroy_frame_callback(struct wl_resource *resource) |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3010 | { |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 3011 | struct weston_frame_callback *cb = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 3012 | |
| 3013 | wl_list_remove(&cb->link); |
Pekka Paalanen | 8c19645 | 2011-11-15 11:45:42 +0200 | [diff] [blame] | 3014 | free(cb); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3015 | } |
| 3016 | |
| 3017 | static void |
| 3018 | surface_frame(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 3019 | struct wl_resource *resource, uint32_t callback) |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3020 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3021 | struct weston_frame_callback *cb; |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3022 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3023 | |
| 3024 | cb = malloc(sizeof *cb); |
| 3025 | if (cb == NULL) { |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 3026 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3027 | return; |
| 3028 | } |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 3029 | |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 3030 | cb->resource = wl_resource_create(client, &wl_callback_interface, 1, |
| 3031 | callback); |
| 3032 | if (cb->resource == NULL) { |
| 3033 | free(cb); |
| 3034 | wl_resource_post_no_memory(resource); |
| 3035 | return; |
| 3036 | } |
| 3037 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3038 | wl_resource_set_implementation(cb->resource, NULL, cb, |
| 3039 | destroy_frame_callback); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3040 | |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 3041 | wl_list_insert(surface->pending.frame_callback_list.prev, &cb->link); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3042 | } |
| 3043 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3044 | static void |
| 3045 | surface_set_opaque_region(struct wl_client *client, |
| 3046 | struct wl_resource *resource, |
| 3047 | struct wl_resource *region_resource) |
| 3048 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3049 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3050 | struct weston_region *region; |
| 3051 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3052 | if (region_resource) { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 3053 | region = wl_resource_get_user_data(region_resource); |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 3054 | pixman_region32_copy(&surface->pending.opaque, |
| 3055 | ®ion->region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3056 | } else { |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 3057 | pixman_region32_clear(&surface->pending.opaque); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3058 | } |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3059 | } |
| 3060 | |
| 3061 | static void |
| 3062 | surface_set_input_region(struct wl_client *client, |
| 3063 | struct wl_resource *resource, |
| 3064 | struct wl_resource *region_resource) |
| 3065 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3066 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 010f98b | 2012-02-23 17:30:45 -0500 | [diff] [blame] | 3067 | struct weston_region *region; |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3068 | |
| 3069 | if (region_resource) { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 3070 | region = wl_resource_get_user_data(region_resource); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3071 | pixman_region32_copy(&surface->pending.input, |
| 3072 | ®ion->region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3073 | } else { |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3074 | pixman_region32_fini(&surface->pending.input); |
| 3075 | region_init_infinite(&surface->pending.input); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3076 | } |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3077 | } |
| 3078 | |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 3079 | /* Cause damage to this sub-surface and all its children. |
| 3080 | * |
| 3081 | * This is useful when there are state changes that need an implicit |
| 3082 | * damage, e.g. a z-order change. |
| 3083 | */ |
| 3084 | static void |
| 3085 | weston_surface_damage_subsurfaces(struct weston_subsurface *sub) |
| 3086 | { |
| 3087 | struct weston_subsurface *child; |
| 3088 | |
| 3089 | weston_surface_damage(sub->surface); |
| 3090 | sub->reordered = false; |
| 3091 | |
| 3092 | wl_list_for_each(child, &sub->surface->subsurface_list, parent_link) |
| 3093 | if (child != sub) |
| 3094 | weston_surface_damage_subsurfaces(child); |
| 3095 | } |
| 3096 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3097 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3098 | weston_surface_commit_subsurface_order(struct weston_surface *surface) |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3099 | { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3100 | struct weston_subsurface *sub; |
| 3101 | |
| 3102 | wl_list_for_each_reverse(sub, &surface->subsurface_list_pending, |
| 3103 | parent_link_pending) { |
| 3104 | wl_list_remove(&sub->parent_link); |
| 3105 | wl_list_insert(&surface->subsurface_list, &sub->parent_link); |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 3106 | |
| 3107 | if (sub->reordered) |
| 3108 | weston_surface_damage_subsurfaces(sub); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3109 | } |
| 3110 | } |
| 3111 | |
| 3112 | static void |
Pekka Paalanen | 04baea5 | 2016-04-26 15:50:58 +0300 | [diff] [blame] | 3113 | weston_surface_build_buffer_matrix(const struct weston_surface *surface, |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 3114 | struct weston_matrix *matrix) |
| 3115 | { |
Pekka Paalanen | 04baea5 | 2016-04-26 15:50:58 +0300 | [diff] [blame] | 3116 | const struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 3117 | double src_width, src_height, dest_width, dest_height; |
| 3118 | |
| 3119 | weston_matrix_init(matrix); |
| 3120 | |
| 3121 | if (vp->buffer.src_width == wl_fixed_from_int(-1)) { |
| 3122 | src_width = surface->width_from_buffer; |
| 3123 | src_height = surface->height_from_buffer; |
| 3124 | } else { |
| 3125 | src_width = wl_fixed_to_double(vp->buffer.src_width); |
| 3126 | src_height = wl_fixed_to_double(vp->buffer.src_height); |
| 3127 | } |
| 3128 | |
| 3129 | if (vp->surface.width == -1) { |
| 3130 | dest_width = src_width; |
| 3131 | dest_height = src_height; |
| 3132 | } else { |
| 3133 | dest_width = vp->surface.width; |
| 3134 | dest_height = vp->surface.height; |
| 3135 | } |
| 3136 | |
| 3137 | if (src_width != dest_width || src_height != dest_height) |
| 3138 | weston_matrix_scale(matrix, |
| 3139 | src_width / dest_width, |
| 3140 | src_height / dest_height, 1); |
| 3141 | |
| 3142 | if (vp->buffer.src_width != wl_fixed_from_int(-1)) |
| 3143 | weston_matrix_translate(matrix, |
| 3144 | wl_fixed_to_double(vp->buffer.src_x), |
| 3145 | wl_fixed_to_double(vp->buffer.src_y), |
| 3146 | 0); |
| 3147 | |
| 3148 | switch (vp->buffer.transform) { |
| 3149 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 3150 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 3151 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 3152 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 3153 | weston_matrix_scale(matrix, -1, 1, 1); |
| 3154 | weston_matrix_translate(matrix, |
| 3155 | surface->width_from_buffer, 0, 0); |
| 3156 | break; |
| 3157 | } |
| 3158 | |
| 3159 | switch (vp->buffer.transform) { |
| 3160 | default: |
| 3161 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 3162 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 3163 | break; |
| 3164 | case WL_OUTPUT_TRANSFORM_90: |
| 3165 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 3166 | weston_matrix_rotate_xy(matrix, 0, 1); |
| 3167 | weston_matrix_translate(matrix, |
| 3168 | surface->height_from_buffer, 0, 0); |
| 3169 | break; |
| 3170 | case WL_OUTPUT_TRANSFORM_180: |
| 3171 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 3172 | weston_matrix_rotate_xy(matrix, -1, 0); |
| 3173 | weston_matrix_translate(matrix, |
| 3174 | surface->width_from_buffer, |
| 3175 | surface->height_from_buffer, 0); |
| 3176 | break; |
| 3177 | case WL_OUTPUT_TRANSFORM_270: |
| 3178 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 3179 | weston_matrix_rotate_xy(matrix, 0, -1); |
| 3180 | weston_matrix_translate(matrix, |
| 3181 | 0, surface->width_from_buffer, 0); |
| 3182 | break; |
| 3183 | } |
| 3184 | |
| 3185 | weston_matrix_scale(matrix, vp->buffer.scale, vp->buffer.scale, 1); |
| 3186 | } |
| 3187 | |
Pekka Paalanen | d9aae9c | 2016-04-26 13:46:38 +0300 | [diff] [blame] | 3188 | /** |
| 3189 | * Compute a + b > c while being safe to overflows. |
| 3190 | */ |
| 3191 | static bool |
| 3192 | fixed_sum_gt(wl_fixed_t a, wl_fixed_t b, wl_fixed_t c) |
| 3193 | { |
| 3194 | return (int64_t)a + (int64_t)b > (int64_t)c; |
| 3195 | } |
| 3196 | |
| 3197 | static bool |
| 3198 | weston_surface_is_pending_viewport_source_valid( |
| 3199 | const struct weston_surface *surface) |
| 3200 | { |
| 3201 | const struct weston_surface_state *pend = &surface->pending; |
| 3202 | const struct weston_buffer_viewport *vp = &pend->buffer_viewport; |
| 3203 | int width_from_buffer = 0; |
| 3204 | int height_from_buffer = 0; |
| 3205 | wl_fixed_t w; |
| 3206 | wl_fixed_t h; |
| 3207 | |
| 3208 | /* If viewport source rect is not set, it is always ok. */ |
| 3209 | if (vp->buffer.src_width == wl_fixed_from_int(-1)) |
| 3210 | return true; |
| 3211 | |
| 3212 | if (pend->newly_attached) { |
| 3213 | if (pend->buffer) { |
| 3214 | convert_size_by_transform_scale(&width_from_buffer, |
| 3215 | &height_from_buffer, |
| 3216 | pend->buffer->width, |
| 3217 | pend->buffer->height, |
| 3218 | vp->buffer.transform, |
| 3219 | vp->buffer.scale); |
| 3220 | } else { |
| 3221 | /* No buffer: viewport is irrelevant. */ |
| 3222 | return true; |
| 3223 | } |
| 3224 | } else { |
| 3225 | width_from_buffer = surface->width_from_buffer; |
| 3226 | height_from_buffer = surface->height_from_buffer; |
| 3227 | } |
| 3228 | |
| 3229 | assert((width_from_buffer == 0) == (height_from_buffer == 0)); |
| 3230 | assert(width_from_buffer >= 0 && height_from_buffer >= 0); |
| 3231 | |
| 3232 | /* No buffer: viewport is irrelevant. */ |
| 3233 | if (width_from_buffer == 0 || height_from_buffer == 0) |
| 3234 | return true; |
| 3235 | |
| 3236 | /* overflow checks for wl_fixed_from_int() */ |
| 3237 | if (width_from_buffer > wl_fixed_to_int(INT32_MAX)) |
| 3238 | return false; |
| 3239 | if (height_from_buffer > wl_fixed_to_int(INT32_MAX)) |
| 3240 | return false; |
| 3241 | |
| 3242 | w = wl_fixed_from_int(width_from_buffer); |
| 3243 | h = wl_fixed_from_int(height_from_buffer); |
| 3244 | |
| 3245 | if (fixed_sum_gt(vp->buffer.src_x, vp->buffer.src_width, w)) |
| 3246 | return false; |
| 3247 | if (fixed_sum_gt(vp->buffer.src_y, vp->buffer.src_height, h)) |
| 3248 | return false; |
| 3249 | |
| 3250 | return true; |
| 3251 | } |
| 3252 | |
Pekka Paalanen | bb32ccc | 2016-04-26 14:28:28 +0300 | [diff] [blame] | 3253 | static bool |
| 3254 | fixed_is_integer(wl_fixed_t v) |
| 3255 | { |
| 3256 | return (v & 0xff) == 0; |
| 3257 | } |
| 3258 | |
| 3259 | static bool |
| 3260 | weston_surface_is_pending_viewport_dst_size_int( |
| 3261 | const struct weston_surface *surface) |
| 3262 | { |
| 3263 | const struct weston_buffer_viewport *vp = |
| 3264 | &surface->pending.buffer_viewport; |
| 3265 | |
| 3266 | if (vp->surface.width != -1) { |
| 3267 | assert(vp->surface.width > 0 && vp->surface.height > 0); |
| 3268 | return true; |
| 3269 | } |
| 3270 | |
| 3271 | return fixed_is_integer(vp->buffer.src_width) && |
| 3272 | fixed_is_integer(vp->buffer.src_height); |
| 3273 | } |
| 3274 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3275 | /* Translate pending damage in buffer co-ordinates to surface |
| 3276 | * co-ordinates and union it with a pixman_region32_t. |
| 3277 | * This should only be called after the buffer is attached. |
| 3278 | */ |
| 3279 | static void |
| 3280 | apply_damage_buffer(pixman_region32_t *dest, |
| 3281 | struct weston_surface *surface, |
| 3282 | struct weston_surface_state *state) |
| 3283 | { |
| 3284 | struct weston_buffer *buffer = surface->buffer_ref.buffer; |
| 3285 | |
| 3286 | /* wl_surface.damage_buffer needs to be clipped to the buffer, |
| 3287 | * translated into surface co-ordinates and unioned with |
| 3288 | * any other surface damage. |
| 3289 | * None of this makes sense if there is no buffer though. |
| 3290 | */ |
| 3291 | if (buffer && pixman_region32_not_empty(&state->damage_buffer)) { |
| 3292 | pixman_region32_t buffer_damage; |
| 3293 | |
| 3294 | pixman_region32_intersect_rect(&state->damage_buffer, |
| 3295 | &state->damage_buffer, |
| 3296 | 0, 0, buffer->width, |
| 3297 | buffer->height); |
| 3298 | pixman_region32_init(&buffer_damage); |
| 3299 | weston_matrix_transform_region(&buffer_damage, |
| 3300 | &surface->buffer_to_surface_matrix, |
| 3301 | &state->damage_buffer); |
| 3302 | pixman_region32_union(dest, dest, &buffer_damage); |
| 3303 | pixman_region32_fini(&buffer_damage); |
| 3304 | } |
| 3305 | /* We should clear this on commit even if there was no buffer */ |
| 3306 | pixman_region32_clear(&state->damage_buffer); |
| 3307 | } |
| 3308 | |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 3309 | static void |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3310 | weston_surface_commit_state(struct weston_surface *surface, |
| 3311 | struct weston_surface_state *state) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3312 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3313 | struct weston_view *view; |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 3314 | pixman_region32_t opaque; |
| 3315 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3316 | /* wl_surface.set_buffer_transform */ |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3317 | /* wl_surface.set_buffer_scale */ |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 3318 | /* wp_viewport.set_source */ |
| 3319 | /* wp_viewport.set_destination */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3320 | surface->buffer_viewport = state->buffer_viewport; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3321 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3322 | /* wl_surface.attach */ |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3323 | if (state->newly_attached) { |
| 3324 | /* zwp_surface_synchronization_v1.set_acquire_fence */ |
| 3325 | fd_move(&surface->acquire_fence_fd, |
| 3326 | &state->acquire_fence_fd); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3327 | /* zwp_surface_synchronization_v1.get_release */ |
| 3328 | weston_buffer_release_move(&surface->buffer_release_ref, |
| 3329 | &state->buffer_release_ref); |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3330 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3331 | weston_surface_attach(surface, state->buffer); |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3332 | } |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3333 | weston_surface_state_set_buffer(state, NULL); |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3334 | assert(state->acquire_fence_fd == -1); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3335 | assert(state->buffer_release_ref.buffer_release == NULL); |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3336 | |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 3337 | weston_surface_build_buffer_matrix(surface, |
| 3338 | &surface->surface_to_buffer_matrix); |
| 3339 | weston_matrix_invert(&surface->buffer_to_surface_matrix, |
| 3340 | &surface->surface_to_buffer_matrix); |
| 3341 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3342 | if (state->newly_attached || state->buffer_viewport.changed) { |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3343 | weston_surface_update_size(surface); |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3344 | if (surface->committed) |
| 3345 | surface->committed(surface, state->sx, state->sy); |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3346 | } |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3347 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3348 | state->sx = 0; |
| 3349 | state->sy = 0; |
| 3350 | state->newly_attached = 0; |
| 3351 | state->buffer_viewport.changed = 0; |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 3352 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3353 | /* wl_surface.damage and wl_surface.damage_buffer */ |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3354 | if (weston_timeline_enabled_ && |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3355 | (pixman_region32_not_empty(&state->damage_surface) || |
| 3356 | pixman_region32_not_empty(&state->damage_buffer))) |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3357 | TL_POINT("core_commit_damage", TLP_SURFACE(surface), TLP_END); |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3358 | |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 3359 | pixman_region32_union(&surface->damage, &surface->damage, |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3360 | &state->damage_surface); |
| 3361 | |
| 3362 | apply_damage_buffer(&surface->damage, surface, state); |
| 3363 | |
Kristian Høgsberg | 4d0214c | 2012-11-08 11:36:02 -0500 | [diff] [blame] | 3364 | pixman_region32_intersect_rect(&surface->damage, &surface->damage, |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 3365 | 0, 0, surface->width, surface->height); |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3366 | pixman_region32_clear(&state->damage_surface); |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 3367 | |
| 3368 | /* wl_surface.set_opaque_region */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3369 | pixman_region32_init(&opaque); |
| 3370 | pixman_region32_intersect_rect(&opaque, &state->opaque, |
| 3371 | 0, 0, surface->width, surface->height); |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 3372 | |
| 3373 | if (!pixman_region32_equal(&opaque, &surface->opaque)) { |
| 3374 | pixman_region32_copy(&surface->opaque, &opaque); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3375 | wl_list_for_each(view, &surface->views, surface_link) |
| 3376 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 3377 | } |
| 3378 | |
| 3379 | pixman_region32_fini(&opaque); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3380 | |
| 3381 | /* wl_surface.set_input_region */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3382 | pixman_region32_intersect_rect(&surface->input, &state->input, |
| 3383 | 0, 0, surface->width, surface->height); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3384 | |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 3385 | /* wl_surface.frame */ |
| 3386 | wl_list_insert_list(&surface->frame_callback_list, |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3387 | &state->frame_callback_list); |
| 3388 | wl_list_init(&state->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3389 | |
| 3390 | /* XXX: |
| 3391 | * What should happen with a feedback request, if there |
| 3392 | * is no wl_buffer attached for this commit? |
| 3393 | */ |
| 3394 | |
| 3395 | /* presentation.feedback */ |
| 3396 | wl_list_insert_list(&surface->feedback_list, |
| 3397 | &state->feedback_list); |
| 3398 | wl_list_init(&state->feedback_list); |
Jonas Ådahl | 5d9ca27 | 2016-07-22 17:48:03 +0800 | [diff] [blame] | 3399 | |
| 3400 | wl_signal_emit(&surface->commit_signal, surface); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3401 | } |
| 3402 | |
| 3403 | static void |
| 3404 | weston_surface_commit(struct weston_surface *surface) |
| 3405 | { |
| 3406 | weston_surface_commit_state(surface, &surface->pending); |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 3407 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3408 | weston_surface_commit_subsurface_order(surface); |
| 3409 | |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3410 | weston_surface_schedule_repaint(surface); |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3411 | } |
| 3412 | |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3413 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3414 | weston_subsurface_commit(struct weston_subsurface *sub); |
| 3415 | |
| 3416 | static void |
| 3417 | weston_subsurface_parent_commit(struct weston_subsurface *sub, |
| 3418 | int parent_is_synchronized); |
| 3419 | |
| 3420 | static void |
| 3421 | surface_commit(struct wl_client *client, struct wl_resource *resource) |
| 3422 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3423 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3424 | struct weston_subsurface *sub = weston_surface_to_subsurface(surface); |
| 3425 | |
Pekka Paalanen | d9aae9c | 2016-04-26 13:46:38 +0300 | [diff] [blame] | 3426 | if (!weston_surface_is_pending_viewport_source_valid(surface)) { |
| 3427 | assert(surface->viewport_resource); |
| 3428 | |
| 3429 | wl_resource_post_error(surface->viewport_resource, |
| 3430 | WP_VIEWPORT_ERROR_OUT_OF_BUFFER, |
| 3431 | "wl_surface@%d has viewport source outside buffer", |
| 3432 | wl_resource_get_id(resource)); |
| 3433 | return; |
| 3434 | } |
| 3435 | |
Pekka Paalanen | bb32ccc | 2016-04-26 14:28:28 +0300 | [diff] [blame] | 3436 | if (!weston_surface_is_pending_viewport_dst_size_int(surface)) { |
| 3437 | assert(surface->viewport_resource); |
| 3438 | |
| 3439 | wl_resource_post_error(surface->viewport_resource, |
| 3440 | WP_VIEWPORT_ERROR_BAD_SIZE, |
| 3441 | "wl_surface@%d viewport dst size not integer", |
| 3442 | wl_resource_get_id(resource)); |
| 3443 | return; |
| 3444 | } |
| 3445 | |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3446 | if (surface->pending.acquire_fence_fd >= 0) { |
| 3447 | assert(surface->synchronization_resource); |
| 3448 | |
| 3449 | if (!surface->pending.buffer) { |
| 3450 | fd_clear(&surface->pending.acquire_fence_fd); |
| 3451 | wl_resource_post_error(surface->synchronization_resource, |
| 3452 | ZWP_LINUX_SURFACE_SYNCHRONIZATION_V1_ERROR_NO_BUFFER, |
| 3453 | "wl_surface@%"PRIu32" no buffer for synchronization", |
| 3454 | wl_resource_get_id(resource)); |
| 3455 | return; |
| 3456 | } |
| 3457 | |
| 3458 | /* We support fences for both wp_linux_dmabuf and opaque EGL |
| 3459 | * buffers, as mandated by minor version 2 of the |
| 3460 | * zwp_linux_explicit_synchronization_v1 protocol. Since |
| 3461 | * renderers that support fences currently only support these |
| 3462 | * two buffer types plus SHM buffers, we can just check for the |
| 3463 | * SHM buffer case here. |
| 3464 | */ |
| 3465 | if (wl_shm_buffer_get(surface->pending.buffer->resource)) { |
| 3466 | fd_clear(&surface->pending.acquire_fence_fd); |
| 3467 | wl_resource_post_error(surface->synchronization_resource, |
| 3468 | ZWP_LINUX_SURFACE_SYNCHRONIZATION_V1_ERROR_UNSUPPORTED_BUFFER, |
| 3469 | "wl_surface@%"PRIu32" unsupported buffer for synchronization", |
| 3470 | wl_resource_get_id(resource)); |
| 3471 | return; |
| 3472 | } |
| 3473 | } |
| 3474 | |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3475 | if (surface->pending.buffer_release_ref.buffer_release && |
| 3476 | !surface->pending.buffer) { |
| 3477 | assert(surface->synchronization_resource); |
| 3478 | |
| 3479 | wl_resource_post_error(surface->synchronization_resource, |
| 3480 | ZWP_LINUX_SURFACE_SYNCHRONIZATION_V1_ERROR_NO_BUFFER, |
| 3481 | "wl_surface@%"PRIu32" no buffer for synchronization", |
| 3482 | wl_resource_get_id(resource)); |
| 3483 | return; |
| 3484 | } |
| 3485 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3486 | if (sub) { |
| 3487 | weston_subsurface_commit(sub); |
| 3488 | return; |
| 3489 | } |
| 3490 | |
| 3491 | weston_surface_commit(surface); |
| 3492 | |
| 3493 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
| 3494 | if (sub->surface != surface) |
| 3495 | weston_subsurface_parent_commit(sub, 0); |
| 3496 | } |
| 3497 | } |
| 3498 | |
| 3499 | static void |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3500 | surface_set_buffer_transform(struct wl_client *client, |
| 3501 | struct wl_resource *resource, int transform) |
| 3502 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3503 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3504 | |
Jonny Lamb | a55f139 | 2014-05-30 12:07:15 +0200 | [diff] [blame] | 3505 | /* if wl_output.transform grows more members this will need to be updated. */ |
| 3506 | if (transform < 0 || |
| 3507 | transform > WL_OUTPUT_TRANSFORM_FLIPPED_270) { |
| 3508 | wl_resource_post_error(resource, |
| 3509 | WL_SURFACE_ERROR_INVALID_TRANSFORM, |
| 3510 | "buffer transform must be a valid transform " |
| 3511 | "('%d' specified)", transform); |
| 3512 | return; |
| 3513 | } |
| 3514 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 3515 | surface->pending.buffer_viewport.buffer.transform = transform; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3516 | surface->pending.buffer_viewport.changed = 1; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3517 | } |
| 3518 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3519 | static void |
| 3520 | surface_set_buffer_scale(struct wl_client *client, |
| 3521 | struct wl_resource *resource, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 3522 | int32_t scale) |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3523 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3524 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3525 | |
Jonny Lamb | a55f139 | 2014-05-30 12:07:15 +0200 | [diff] [blame] | 3526 | if (scale < 1) { |
| 3527 | wl_resource_post_error(resource, |
| 3528 | WL_SURFACE_ERROR_INVALID_SCALE, |
| 3529 | "buffer scale must be at least one " |
| 3530 | "('%d' specified)", scale); |
| 3531 | return; |
| 3532 | } |
| 3533 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 3534 | surface->pending.buffer_viewport.buffer.scale = scale; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3535 | surface->pending.buffer_viewport.changed = 1; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3536 | } |
| 3537 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 3538 | static const struct wl_surface_interface surface_interface = { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3539 | surface_destroy, |
| 3540 | surface_attach, |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3541 | surface_damage, |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3542 | surface_frame, |
| 3543 | surface_set_opaque_region, |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3544 | surface_set_input_region, |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3545 | surface_commit, |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3546 | surface_set_buffer_transform, |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3547 | surface_set_buffer_scale, |
| 3548 | surface_damage_buffer |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3549 | }; |
| 3550 | |
| 3551 | static void |
| 3552 | compositor_create_surface(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 3553 | struct wl_resource *resource, uint32_t id) |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3554 | { |
Kristian Høgsberg | c2d7042 | 2013-06-25 15:34:33 -0400 | [diff] [blame] | 3555 | struct weston_compositor *ec = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3556 | struct weston_surface *surface; |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3557 | |
Kristian Høgsberg | 18c9300 | 2012-01-27 11:58:31 -0500 | [diff] [blame] | 3558 | surface = weston_surface_create(ec); |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 3559 | if (surface == NULL) { |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 3560 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3561 | return; |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 3562 | } |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3563 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3564 | surface->resource = |
| 3565 | wl_resource_create(client, &wl_surface_interface, |
| 3566 | wl_resource_get_version(resource), id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 3567 | if (surface->resource == NULL) { |
| 3568 | weston_surface_destroy(surface); |
| 3569 | wl_resource_post_no_memory(resource); |
| 3570 | return; |
| 3571 | } |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3572 | wl_resource_set_implementation(surface->resource, &surface_interface, |
| 3573 | surface, destroy_surface); |
Kristian Høgsberg | f03a04a | 2014-04-06 22:04:50 -0700 | [diff] [blame] | 3574 | |
| 3575 | wl_signal_emit(&ec->create_surface_signal, surface); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3576 | } |
| 3577 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3578 | static void |
| 3579 | destroy_region(struct wl_resource *resource) |
| 3580 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 3581 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3582 | |
| 3583 | pixman_region32_fini(®ion->region); |
| 3584 | free(region); |
| 3585 | } |
| 3586 | |
| 3587 | static void |
| 3588 | region_destroy(struct wl_client *client, struct wl_resource *resource) |
| 3589 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3590 | wl_resource_destroy(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3591 | } |
| 3592 | |
| 3593 | static void |
| 3594 | region_add(struct wl_client *client, struct wl_resource *resource, |
| 3595 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 3596 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 3597 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3598 | |
| 3599 | pixman_region32_union_rect(®ion->region, ®ion->region, |
| 3600 | x, y, width, height); |
| 3601 | } |
| 3602 | |
| 3603 | static void |
| 3604 | region_subtract(struct wl_client *client, struct wl_resource *resource, |
| 3605 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 3606 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 3607 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3608 | pixman_region32_t rect; |
| 3609 | |
| 3610 | pixman_region32_init_rect(&rect, x, y, width, height); |
| 3611 | pixman_region32_subtract(®ion->region, ®ion->region, &rect); |
| 3612 | pixman_region32_fini(&rect); |
| 3613 | } |
| 3614 | |
| 3615 | static const struct wl_region_interface region_interface = { |
| 3616 | region_destroy, |
| 3617 | region_add, |
| 3618 | region_subtract |
| 3619 | }; |
| 3620 | |
| 3621 | static void |
| 3622 | compositor_create_region(struct wl_client *client, |
| 3623 | struct wl_resource *resource, uint32_t id) |
| 3624 | { |
| 3625 | struct weston_region *region; |
| 3626 | |
| 3627 | region = malloc(sizeof *region); |
| 3628 | if (region == NULL) { |
| 3629 | wl_resource_post_no_memory(resource); |
| 3630 | return; |
| 3631 | } |
| 3632 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3633 | pixman_region32_init(®ion->region); |
| 3634 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3635 | region->resource = |
| 3636 | wl_resource_create(client, &wl_region_interface, 1, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 3637 | if (region->resource == NULL) { |
| 3638 | free(region); |
| 3639 | wl_resource_post_no_memory(resource); |
| 3640 | return; |
| 3641 | } |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3642 | wl_resource_set_implementation(region->resource, ®ion_interface, |
| 3643 | region, destroy_region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3644 | } |
| 3645 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 3646 | static const struct wl_compositor_interface compositor_interface = { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3647 | compositor_create_surface, |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3648 | compositor_create_region |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3649 | }; |
| 3650 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3651 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3652 | weston_subsurface_commit_from_cache(struct weston_subsurface *sub) |
| 3653 | { |
| 3654 | struct weston_surface *surface = sub->surface; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3655 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3656 | weston_surface_commit_state(surface, &sub->cached); |
| 3657 | weston_buffer_reference(&sub->cached_buffer_ref, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3658 | |
| 3659 | weston_surface_commit_subsurface_order(surface); |
| 3660 | |
| 3661 | weston_surface_schedule_repaint(surface); |
| 3662 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3663 | sub->has_cached_data = 0; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3664 | } |
| 3665 | |
| 3666 | static void |
| 3667 | weston_subsurface_commit_to_cache(struct weston_subsurface *sub) |
| 3668 | { |
| 3669 | struct weston_surface *surface = sub->surface; |
| 3670 | |
| 3671 | /* |
| 3672 | * If this commit would cause the surface to move by the |
| 3673 | * attach(dx, dy) parameters, the old damage region must be |
| 3674 | * translated to correspond to the new surface coordinate system |
Chris Michael | 062edf2 | 2015-11-26 11:30:00 -0500 | [diff] [blame] | 3675 | * origin. |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3676 | */ |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3677 | pixman_region32_translate(&sub->cached.damage_surface, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3678 | -surface->pending.sx, -surface->pending.sy); |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3679 | pixman_region32_union(&sub->cached.damage_surface, |
| 3680 | &sub->cached.damage_surface, |
| 3681 | &surface->pending.damage_surface); |
| 3682 | pixman_region32_clear(&surface->pending.damage_surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3683 | |
| 3684 | if (surface->pending.newly_attached) { |
| 3685 | sub->cached.newly_attached = 1; |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3686 | weston_surface_state_set_buffer(&sub->cached, |
| 3687 | surface->pending.buffer); |
| 3688 | weston_buffer_reference(&sub->cached_buffer_ref, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3689 | surface->pending.buffer); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3690 | weston_presentation_feedback_discard_list( |
| 3691 | &sub->cached.feedback_list); |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3692 | /* zwp_surface_synchronization_v1.set_acquire_fence */ |
| 3693 | fd_move(&sub->cached.acquire_fence_fd, |
| 3694 | &surface->pending.acquire_fence_fd); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3695 | /* zwp_surface_synchronization_v1.get_release */ |
| 3696 | weston_buffer_release_move(&sub->cached.buffer_release_ref, |
| 3697 | &surface->pending.buffer_release_ref); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3698 | } |
Alexandros Frantzis | acff29b | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3699 | assert(surface->pending.acquire_fence_fd == -1); |
Alexandros Frantzis | 6762967 | 2018-10-19 12:14:11 +0300 | [diff] [blame] | 3700 | assert(surface->pending.buffer_release_ref.buffer_release == NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3701 | sub->cached.sx += surface->pending.sx; |
| 3702 | sub->cached.sy += surface->pending.sy; |
Pekka Paalanen | 260ba38 | 2014-03-14 14:38:12 +0200 | [diff] [blame] | 3703 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3704 | apply_damage_buffer(&sub->cached.damage_surface, surface, &surface->pending); |
| 3705 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3706 | sub->cached.buffer_viewport.changed |= |
| 3707 | surface->pending.buffer_viewport.changed; |
| 3708 | sub->cached.buffer_viewport.buffer = |
| 3709 | surface->pending.buffer_viewport.buffer; |
| 3710 | sub->cached.buffer_viewport.surface = |
| 3711 | surface->pending.buffer_viewport.surface; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3712 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3713 | weston_surface_reset_pending_buffer(surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3714 | |
| 3715 | pixman_region32_copy(&sub->cached.opaque, &surface->pending.opaque); |
| 3716 | |
| 3717 | pixman_region32_copy(&sub->cached.input, &surface->pending.input); |
| 3718 | |
| 3719 | wl_list_insert_list(&sub->cached.frame_callback_list, |
| 3720 | &surface->pending.frame_callback_list); |
| 3721 | wl_list_init(&surface->pending.frame_callback_list); |
| 3722 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3723 | wl_list_insert_list(&sub->cached.feedback_list, |
| 3724 | &surface->pending.feedback_list); |
| 3725 | wl_list_init(&surface->pending.feedback_list); |
| 3726 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3727 | sub->has_cached_data = 1; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3728 | } |
| 3729 | |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 3730 | static bool |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3731 | weston_subsurface_is_synchronized(struct weston_subsurface *sub) |
| 3732 | { |
| 3733 | while (sub) { |
| 3734 | if (sub->synchronized) |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 3735 | return true; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3736 | |
| 3737 | if (!sub->parent) |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 3738 | return false; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3739 | |
| 3740 | sub = weston_surface_to_subsurface(sub->parent); |
| 3741 | } |
| 3742 | |
Carlos Olmedo Escobar | 61a9bf5 | 2014-11-04 14:38:39 +0100 | [diff] [blame] | 3743 | return false; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3744 | } |
| 3745 | |
| 3746 | static void |
| 3747 | weston_subsurface_commit(struct weston_subsurface *sub) |
| 3748 | { |
| 3749 | struct weston_surface *surface = sub->surface; |
| 3750 | struct weston_subsurface *tmp; |
| 3751 | |
| 3752 | /* Recursive check for effectively synchronized. */ |
| 3753 | if (weston_subsurface_is_synchronized(sub)) { |
| 3754 | weston_subsurface_commit_to_cache(sub); |
| 3755 | } else { |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3756 | if (sub->has_cached_data) { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3757 | /* flush accumulated state from cache */ |
| 3758 | weston_subsurface_commit_to_cache(sub); |
| 3759 | weston_subsurface_commit_from_cache(sub); |
| 3760 | } else { |
| 3761 | weston_surface_commit(surface); |
| 3762 | } |
| 3763 | |
| 3764 | wl_list_for_each(tmp, &surface->subsurface_list, parent_link) { |
| 3765 | if (tmp->surface != surface) |
| 3766 | weston_subsurface_parent_commit(tmp, 0); |
| 3767 | } |
| 3768 | } |
| 3769 | } |
| 3770 | |
| 3771 | static void |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3772 | weston_subsurface_synchronized_commit(struct weston_subsurface *sub) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3773 | { |
| 3774 | struct weston_surface *surface = sub->surface; |
| 3775 | struct weston_subsurface *tmp; |
| 3776 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3777 | /* From now on, commit_from_cache the whole sub-tree, regardless of |
| 3778 | * the synchronized mode of each child. This sub-surface or some |
| 3779 | * of its ancestors were synchronized, so we are synchronized |
| 3780 | * all the way down. |
| 3781 | */ |
| 3782 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3783 | if (sub->has_cached_data) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3784 | weston_subsurface_commit_from_cache(sub); |
| 3785 | |
| 3786 | wl_list_for_each(tmp, &surface->subsurface_list, parent_link) { |
| 3787 | if (tmp->surface != surface) |
| 3788 | weston_subsurface_parent_commit(tmp, 1); |
| 3789 | } |
| 3790 | } |
| 3791 | |
| 3792 | static void |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3793 | weston_subsurface_parent_commit(struct weston_subsurface *sub, |
| 3794 | int parent_is_synchronized) |
| 3795 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3796 | struct weston_view *view; |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3797 | if (sub->position.set) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3798 | wl_list_for_each(view, &sub->surface->views, surface_link) |
| 3799 | weston_view_set_position(view, |
| 3800 | sub->position.x, |
| 3801 | sub->position.y); |
| 3802 | |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3803 | sub->position.set = 0; |
| 3804 | } |
| 3805 | |
| 3806 | if (parent_is_synchronized || sub->synchronized) |
| 3807 | weston_subsurface_synchronized_commit(sub); |
| 3808 | } |
| 3809 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3810 | static int |
| 3811 | subsurface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 3812 | { |
| 3813 | return snprintf(buf, len, "sub-surface"); |
| 3814 | } |
| 3815 | |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3816 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3817 | subsurface_committed(struct weston_surface *surface, int32_t dx, int32_t dy) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3818 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3819 | struct weston_view *view; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3820 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3821 | wl_list_for_each(view, &surface->views, surface_link) |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3822 | weston_view_set_position(view, |
| 3823 | view->geometry.x + dx, |
| 3824 | view->geometry.y + dy); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3825 | |
| 3826 | /* No need to check parent mappedness, because if parent is not |
| 3827 | * mapped, parent is not in a visible layer, so this sub-surface |
| 3828 | * will not be drawn either. |
| 3829 | */ |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 3830 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3831 | if (!weston_surface_is_mapped(surface)) { |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 3832 | surface->is_mapped = true; |
Pekka Paalanen | eb3cf22 | 2014-06-30 11:52:07 +0300 | [diff] [blame] | 3833 | |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 3834 | /* Cannot call weston_view_update_transform(), |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3835 | * because that would call it also for the parent surface, |
| 3836 | * which might not be mapped yet. That would lead to |
| 3837 | * inconsistent state, where the window could never be |
| 3838 | * mapped. |
| 3839 | * |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 3840 | * Instead just force the is_mapped flag on, to make |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3841 | * weston_surface_is_mapped() return true, so that when the |
| 3842 | * parent surface does get mapped, this one will get |
Pekka Paalanen | eb3cf22 | 2014-06-30 11:52:07 +0300 | [diff] [blame] | 3843 | * included, too. See view_list_add(). |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3844 | */ |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3845 | } |
| 3846 | } |
| 3847 | |
| 3848 | static struct weston_subsurface * |
| 3849 | weston_surface_to_subsurface(struct weston_surface *surface) |
| 3850 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3851 | if (surface->committed == subsurface_committed) |
| 3852 | return surface->committed_private; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3853 | |
| 3854 | return NULL; |
| 3855 | } |
| 3856 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3857 | WL_EXPORT struct weston_surface * |
| 3858 | weston_surface_get_main_surface(struct weston_surface *surface) |
| 3859 | { |
| 3860 | struct weston_subsurface *sub; |
| 3861 | |
| 3862 | while (surface && (sub = weston_surface_to_subsurface(surface))) |
| 3863 | surface = sub->parent; |
| 3864 | |
| 3865 | return surface; |
| 3866 | } |
| 3867 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3868 | WL_EXPORT int |
| 3869 | weston_surface_set_role(struct weston_surface *surface, |
| 3870 | const char *role_name, |
| 3871 | struct wl_resource *error_resource, |
| 3872 | uint32_t error_code) |
| 3873 | { |
| 3874 | assert(role_name); |
| 3875 | |
| 3876 | if (surface->role_name == NULL || |
| 3877 | surface->role_name == role_name || |
| 3878 | strcmp(surface->role_name, role_name) == 0) { |
| 3879 | surface->role_name = role_name; |
| 3880 | |
| 3881 | return 0; |
| 3882 | } |
| 3883 | |
| 3884 | wl_resource_post_error(error_resource, error_code, |
| 3885 | "Cannot assign role %s to wl_surface@%d," |
| 3886 | " already has role %s\n", |
| 3887 | role_name, |
| 3888 | wl_resource_get_id(surface->resource), |
| 3889 | surface->role_name); |
| 3890 | return -1; |
| 3891 | } |
| 3892 | |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 3893 | WL_EXPORT const char * |
| 3894 | weston_surface_get_role(struct weston_surface *surface) |
| 3895 | { |
| 3896 | return surface->role_name; |
| 3897 | } |
| 3898 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3899 | WL_EXPORT void |
| 3900 | weston_surface_set_label_func(struct weston_surface *surface, |
| 3901 | int (*desc)(struct weston_surface *, |
| 3902 | char *, size_t)) |
| 3903 | { |
| 3904 | surface->get_label = desc; |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3905 | surface->timeline.force_refresh = 1; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3906 | } |
| 3907 | |
Pekka Paalanen | c647ed7 | 2015-02-09 13:16:57 +0200 | [diff] [blame] | 3908 | /** Get the size of surface contents |
| 3909 | * |
| 3910 | * \param surface The surface to query. |
| 3911 | * \param width Returns the width of raw contents. |
| 3912 | * \param height Returns the height of raw contents. |
| 3913 | * |
| 3914 | * Retrieves the raw surface content size in pixels for the given surface. |
| 3915 | * This is the whole content size in buffer pixels. If the surface |
| 3916 | * has no content or the renderer does not implement this feature, |
| 3917 | * zeroes are returned. |
| 3918 | * |
| 3919 | * This function is used to determine the buffer size needed for |
| 3920 | * a weston_surface_copy_content() call. |
| 3921 | */ |
| 3922 | WL_EXPORT void |
| 3923 | weston_surface_get_content_size(struct weston_surface *surface, |
| 3924 | int *width, int *height) |
| 3925 | { |
| 3926 | struct weston_renderer *rer = surface->compositor->renderer; |
| 3927 | |
| 3928 | if (!rer->surface_get_content_size) { |
| 3929 | *width = 0; |
| 3930 | *height = 0; |
| 3931 | return; |
| 3932 | } |
| 3933 | |
| 3934 | rer->surface_get_content_size(surface, width, height); |
| 3935 | } |
| 3936 | |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 3937 | /** Get the bounding box of a surface and its subsurfaces |
| 3938 | * |
| 3939 | * \param surface The surface to query. |
| 3940 | * \return The bounding box relative to the surface origin. |
| 3941 | * |
| 3942 | */ |
| 3943 | WL_EXPORT struct weston_geometry |
| 3944 | weston_surface_get_bounding_box(struct weston_surface *surface) |
| 3945 | { |
| 3946 | pixman_region32_t region; |
| 3947 | pixman_box32_t *box; |
| 3948 | struct weston_subsurface *subsurface; |
| 3949 | |
| 3950 | pixman_region32_init_rect(®ion, |
| 3951 | 0, 0, |
| 3952 | surface->width, surface->height); |
| 3953 | |
| 3954 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) |
| 3955 | pixman_region32_union_rect(®ion, ®ion, |
| 3956 | subsurface->position.x, |
| 3957 | subsurface->position.y, |
| 3958 | subsurface->surface->width, |
| 3959 | subsurface->surface->height); |
| 3960 | |
| 3961 | box = pixman_region32_extents(®ion); |
| 3962 | struct weston_geometry geometry = { |
| 3963 | .x = box->x1, |
| 3964 | .y = box->y1, |
| 3965 | .width = box->x2 - box->x1, |
| 3966 | .height = box->y2 - box->y1, |
| 3967 | }; |
| 3968 | |
| 3969 | pixman_region32_fini(®ion); |
| 3970 | |
| 3971 | return geometry; |
| 3972 | } |
| 3973 | |
Pekka Paalanen | c647ed7 | 2015-02-09 13:16:57 +0200 | [diff] [blame] | 3974 | /** Copy surface contents to system memory. |
| 3975 | * |
| 3976 | * \param surface The surface to copy from. |
| 3977 | * \param target Pointer to the target memory buffer. |
| 3978 | * \param size Size of the target buffer in bytes. |
| 3979 | * \param src_x X location on contents to copy from. |
| 3980 | * \param src_y Y location on contents to copy from. |
| 3981 | * \param width Width in pixels of the area to copy. |
| 3982 | * \param height Height in pixels of the area to copy. |
| 3983 | * \return 0 for success, -1 for failure. |
| 3984 | * |
| 3985 | * Surface contents are maintained by the renderer. They can be in a |
| 3986 | * reserved weston_buffer or as a copy, e.g. a GL texture, or something |
| 3987 | * else. |
| 3988 | * |
| 3989 | * Surface contents are copied into memory pointed to by target, |
| 3990 | * which has size bytes of space available. The target memory |
| 3991 | * may be larger than needed, but being smaller returns an error. |
| 3992 | * The extra bytes in target may or may not be written; their content is |
| 3993 | * unspecified. Size must be large enough to hold the image. |
| 3994 | * |
| 3995 | * The image in the target memory will be arranged in rows from |
| 3996 | * top to bottom, and pixels on a row from left to right. The pixel |
| 3997 | * format is PIXMAN_a8b8g8r8, 4 bytes per pixel, and stride is exactly |
| 3998 | * width * 4. |
| 3999 | * |
| 4000 | * Parameters src_x and src_y define the upper-left corner in buffer |
| 4001 | * coordinates (pixels) to copy from. Parameters width and height |
| 4002 | * define the size of the area to copy in pixels. |
| 4003 | * |
| 4004 | * The rectangle defined by src_x, src_y, width, height must fit in |
| 4005 | * the surface contents. Otherwise an error is returned. |
| 4006 | * |
Changwoo Cho | f97d250 | 2017-08-05 00:30:47 +0900 | [diff] [blame] | 4007 | * Use weston_surface_get_content_size to determine the content size; the |
Pekka Paalanen | c647ed7 | 2015-02-09 13:16:57 +0200 | [diff] [blame] | 4008 | * needed target buffer size and rectangle limits. |
| 4009 | * |
| 4010 | * CURRENT IMPLEMENTATION RESTRICTIONS: |
| 4011 | * - the machine must be little-endian due to Pixman formats. |
| 4012 | * |
| 4013 | * NOTE: Pixman formats are premultiplied. |
| 4014 | */ |
| 4015 | WL_EXPORT int |
| 4016 | weston_surface_copy_content(struct weston_surface *surface, |
| 4017 | void *target, size_t size, |
| 4018 | int src_x, int src_y, |
| 4019 | int width, int height) |
| 4020 | { |
| 4021 | struct weston_renderer *rer = surface->compositor->renderer; |
| 4022 | int cw, ch; |
| 4023 | const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */ |
| 4024 | |
| 4025 | if (!rer->surface_copy_content) |
| 4026 | return -1; |
| 4027 | |
| 4028 | weston_surface_get_content_size(surface, &cw, &ch); |
| 4029 | |
| 4030 | if (src_x < 0 || src_y < 0) |
| 4031 | return -1; |
| 4032 | |
| 4033 | if (width <= 0 || height <= 0) |
| 4034 | return -1; |
| 4035 | |
| 4036 | if (src_x + width > cw || src_y + height > ch) |
| 4037 | return -1; |
| 4038 | |
| 4039 | if (width * bytespp * height > size) |
| 4040 | return -1; |
| 4041 | |
| 4042 | return rer->surface_copy_content(surface, target, size, |
| 4043 | src_x, src_y, width, height); |
| 4044 | } |
| 4045 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4046 | static void |
| 4047 | subsurface_set_position(struct wl_client *client, |
| 4048 | struct wl_resource *resource, int32_t x, int32_t y) |
| 4049 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4050 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4051 | |
| 4052 | if (!sub) |
| 4053 | return; |
| 4054 | |
| 4055 | sub->position.x = x; |
| 4056 | sub->position.y = y; |
| 4057 | sub->position.set = 1; |
| 4058 | } |
| 4059 | |
| 4060 | static struct weston_subsurface * |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 4061 | subsurface_find_sibling(struct weston_subsurface *sub, |
| 4062 | struct weston_surface *surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4063 | { |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 4064 | struct weston_surface *parent = sub->parent; |
| 4065 | struct weston_subsurface *sibling; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4066 | |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 4067 | wl_list_for_each(sibling, &parent->subsurface_list, parent_link) { |
| 4068 | if (sibling->surface == surface && sibling != sub) |
| 4069 | return sibling; |
| 4070 | } |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4071 | |
| 4072 | return NULL; |
| 4073 | } |
| 4074 | |
| 4075 | static struct weston_subsurface * |
| 4076 | subsurface_sibling_check(struct weston_subsurface *sub, |
| 4077 | struct weston_surface *surface, |
| 4078 | const char *request) |
| 4079 | { |
| 4080 | struct weston_subsurface *sibling; |
| 4081 | |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 4082 | sibling = subsurface_find_sibling(sub, surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4083 | if (!sibling) { |
| 4084 | wl_resource_post_error(sub->resource, |
| 4085 | WL_SUBSURFACE_ERROR_BAD_SURFACE, |
| 4086 | "%s: wl_surface@%d is not a parent or sibling", |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4087 | request, wl_resource_get_id(surface->resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4088 | return NULL; |
| 4089 | } |
| 4090 | |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 4091 | assert(sibling->parent == sub->parent); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4092 | |
| 4093 | return sibling; |
| 4094 | } |
| 4095 | |
| 4096 | static void |
| 4097 | subsurface_place_above(struct wl_client *client, |
| 4098 | struct wl_resource *resource, |
| 4099 | struct wl_resource *sibling_resource) |
| 4100 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4101 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4102 | struct weston_surface *surface = |
| 4103 | wl_resource_get_user_data(sibling_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4104 | struct weston_subsurface *sibling; |
| 4105 | |
| 4106 | if (!sub) |
| 4107 | return; |
| 4108 | |
| 4109 | sibling = subsurface_sibling_check(sub, surface, "place_above"); |
| 4110 | if (!sibling) |
| 4111 | return; |
| 4112 | |
| 4113 | wl_list_remove(&sub->parent_link_pending); |
| 4114 | wl_list_insert(sibling->parent_link_pending.prev, |
| 4115 | &sub->parent_link_pending); |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 4116 | |
| 4117 | sub->reordered = true; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4118 | } |
| 4119 | |
| 4120 | static void |
| 4121 | subsurface_place_below(struct wl_client *client, |
| 4122 | struct wl_resource *resource, |
| 4123 | struct wl_resource *sibling_resource) |
| 4124 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4125 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4126 | struct weston_surface *surface = |
| 4127 | wl_resource_get_user_data(sibling_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4128 | struct weston_subsurface *sibling; |
| 4129 | |
| 4130 | if (!sub) |
| 4131 | return; |
| 4132 | |
| 4133 | sibling = subsurface_sibling_check(sub, surface, "place_below"); |
| 4134 | if (!sibling) |
| 4135 | return; |
| 4136 | |
| 4137 | wl_list_remove(&sub->parent_link_pending); |
| 4138 | wl_list_insert(&sibling->parent_link_pending, |
| 4139 | &sub->parent_link_pending); |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 4140 | |
| 4141 | sub->reordered = true; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4142 | } |
| 4143 | |
| 4144 | static void |
| 4145 | subsurface_set_sync(struct wl_client *client, struct wl_resource *resource) |
| 4146 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4147 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4148 | |
| 4149 | if (sub) |
| 4150 | sub->synchronized = 1; |
| 4151 | } |
| 4152 | |
| 4153 | static void |
| 4154 | subsurface_set_desync(struct wl_client *client, struct wl_resource *resource) |
| 4155 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4156 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4157 | |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 4158 | if (sub && sub->synchronized) { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4159 | sub->synchronized = 0; |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 4160 | |
| 4161 | /* If sub became effectively desynchronized, flush. */ |
| 4162 | if (!weston_subsurface_is_synchronized(sub)) |
| 4163 | weston_subsurface_synchronized_commit(sub); |
| 4164 | } |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4165 | } |
| 4166 | |
| 4167 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4168 | weston_subsurface_unlink_parent(struct weston_subsurface *sub) |
| 4169 | { |
| 4170 | wl_list_remove(&sub->parent_link); |
| 4171 | wl_list_remove(&sub->parent_link_pending); |
| 4172 | wl_list_remove(&sub->parent_destroy_listener.link); |
| 4173 | sub->parent = NULL; |
| 4174 | } |
| 4175 | |
| 4176 | static void |
| 4177 | weston_subsurface_destroy(struct weston_subsurface *sub); |
| 4178 | |
| 4179 | static void |
| 4180 | subsurface_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 4181 | { |
| 4182 | struct weston_subsurface *sub = |
| 4183 | container_of(listener, struct weston_subsurface, |
| 4184 | surface_destroy_listener); |
Pekka Paalanen | ca79076 | 2015-04-17 14:23:38 +0300 | [diff] [blame] | 4185 | assert(data == sub->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4186 | |
| 4187 | /* The protocol object (wl_resource) is left inert. */ |
| 4188 | if (sub->resource) |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4189 | wl_resource_set_user_data(sub->resource, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4190 | |
| 4191 | weston_subsurface_destroy(sub); |
| 4192 | } |
| 4193 | |
| 4194 | static void |
| 4195 | subsurface_handle_parent_destroy(struct wl_listener *listener, void *data) |
| 4196 | { |
| 4197 | struct weston_subsurface *sub = |
| 4198 | container_of(listener, struct weston_subsurface, |
| 4199 | parent_destroy_listener); |
Pekka Paalanen | ca79076 | 2015-04-17 14:23:38 +0300 | [diff] [blame] | 4200 | assert(data == sub->parent); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4201 | assert(sub->surface != sub->parent); |
| 4202 | |
| 4203 | if (weston_surface_is_mapped(sub->surface)) |
| 4204 | weston_surface_unmap(sub->surface); |
| 4205 | |
| 4206 | weston_subsurface_unlink_parent(sub); |
| 4207 | } |
| 4208 | |
| 4209 | static void |
| 4210 | subsurface_resource_destroy(struct wl_resource *resource) |
| 4211 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4212 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4213 | |
| 4214 | if (sub) |
| 4215 | weston_subsurface_destroy(sub); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4216 | } |
| 4217 | |
| 4218 | static void |
| 4219 | subsurface_destroy(struct wl_client *client, struct wl_resource *resource) |
| 4220 | { |
| 4221 | wl_resource_destroy(resource); |
| 4222 | } |
| 4223 | |
| 4224 | static void |
| 4225 | weston_subsurface_link_parent(struct weston_subsurface *sub, |
| 4226 | struct weston_surface *parent) |
| 4227 | { |
| 4228 | sub->parent = parent; |
| 4229 | sub->parent_destroy_listener.notify = subsurface_handle_parent_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4230 | wl_signal_add(&parent->destroy_signal, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4231 | &sub->parent_destroy_listener); |
| 4232 | |
| 4233 | wl_list_insert(&parent->subsurface_list, &sub->parent_link); |
| 4234 | wl_list_insert(&parent->subsurface_list_pending, |
| 4235 | &sub->parent_link_pending); |
| 4236 | } |
| 4237 | |
| 4238 | static void |
| 4239 | weston_subsurface_link_surface(struct weston_subsurface *sub, |
| 4240 | struct weston_surface *surface) |
| 4241 | { |
| 4242 | sub->surface = surface; |
| 4243 | sub->surface_destroy_listener.notify = |
| 4244 | subsurface_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4245 | wl_signal_add(&surface->destroy_signal, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4246 | &sub->surface_destroy_listener); |
| 4247 | } |
| 4248 | |
| 4249 | static void |
| 4250 | weston_subsurface_destroy(struct weston_subsurface *sub) |
| 4251 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4252 | struct weston_view *view, *next; |
| 4253 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4254 | assert(sub->surface); |
| 4255 | |
| 4256 | if (sub->resource) { |
| 4257 | assert(weston_surface_to_subsurface(sub->surface) == sub); |
| 4258 | assert(sub->parent_destroy_listener.notify == |
| 4259 | subsurface_handle_parent_destroy); |
| 4260 | |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 4261 | wl_list_for_each_safe(view, next, &sub->surface->views, surface_link) { |
| 4262 | weston_view_unmap(view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4263 | weston_view_destroy(view); |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 4264 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4265 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4266 | if (sub->parent) |
| 4267 | weston_subsurface_unlink_parent(sub); |
| 4268 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 4269 | weston_surface_state_fini(&sub->cached); |
| 4270 | weston_buffer_reference(&sub->cached_buffer_ref, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4271 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 4272 | sub->surface->committed = NULL; |
| 4273 | sub->surface->committed_private = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4274 | weston_surface_set_label_func(sub->surface, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4275 | } else { |
| 4276 | /* the dummy weston_subsurface for the parent itself */ |
| 4277 | assert(sub->parent_destroy_listener.notify == NULL); |
| 4278 | wl_list_remove(&sub->parent_link); |
| 4279 | wl_list_remove(&sub->parent_link_pending); |
| 4280 | } |
| 4281 | |
| 4282 | wl_list_remove(&sub->surface_destroy_listener.link); |
| 4283 | free(sub); |
| 4284 | } |
| 4285 | |
| 4286 | static const struct wl_subsurface_interface subsurface_implementation = { |
| 4287 | subsurface_destroy, |
| 4288 | subsurface_set_position, |
| 4289 | subsurface_place_above, |
| 4290 | subsurface_place_below, |
| 4291 | subsurface_set_sync, |
| 4292 | subsurface_set_desync |
| 4293 | }; |
| 4294 | |
| 4295 | static struct weston_subsurface * |
| 4296 | weston_subsurface_create(uint32_t id, struct weston_surface *surface, |
| 4297 | struct weston_surface *parent) |
| 4298 | { |
| 4299 | struct weston_subsurface *sub; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4300 | struct wl_client *client = wl_resource_get_client(surface->resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4301 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 4302 | sub = zalloc(sizeof *sub); |
| 4303 | if (sub == NULL) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4304 | return NULL; |
| 4305 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4306 | wl_list_init(&sub->unused_views); |
| 4307 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4308 | sub->resource = |
| 4309 | wl_resource_create(client, &wl_subsurface_interface, 1, id); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4310 | if (!sub->resource) { |
| 4311 | free(sub); |
| 4312 | return NULL; |
| 4313 | } |
| 4314 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4315 | wl_resource_set_implementation(sub->resource, |
| 4316 | &subsurface_implementation, |
| 4317 | sub, subsurface_resource_destroy); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4318 | weston_subsurface_link_surface(sub, surface); |
| 4319 | weston_subsurface_link_parent(sub, parent); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 4320 | weston_surface_state_init(&sub->cached); |
| 4321 | sub->cached_buffer_ref.buffer = NULL; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4322 | sub->synchronized = 1; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4323 | |
| 4324 | return sub; |
| 4325 | } |
| 4326 | |
| 4327 | /* Create a dummy subsurface for having the parent itself in its |
| 4328 | * sub-surface lists. Makes stacking order manipulation easy. |
| 4329 | */ |
| 4330 | static struct weston_subsurface * |
| 4331 | weston_subsurface_create_for_parent(struct weston_surface *parent) |
| 4332 | { |
| 4333 | struct weston_subsurface *sub; |
| 4334 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 4335 | sub = zalloc(sizeof *sub); |
| 4336 | if (sub == NULL) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4337 | return NULL; |
| 4338 | |
| 4339 | weston_subsurface_link_surface(sub, parent); |
| 4340 | sub->parent = parent; |
| 4341 | wl_list_insert(&parent->subsurface_list, &sub->parent_link); |
| 4342 | wl_list_insert(&parent->subsurface_list_pending, |
| 4343 | &sub->parent_link_pending); |
| 4344 | |
| 4345 | return sub; |
| 4346 | } |
| 4347 | |
| 4348 | static void |
| 4349 | subcompositor_get_subsurface(struct wl_client *client, |
| 4350 | struct wl_resource *resource, |
| 4351 | uint32_t id, |
| 4352 | struct wl_resource *surface_resource, |
| 4353 | struct wl_resource *parent_resource) |
| 4354 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4355 | struct weston_surface *surface = |
| 4356 | wl_resource_get_user_data(surface_resource); |
| 4357 | struct weston_surface *parent = |
| 4358 | wl_resource_get_user_data(parent_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4359 | struct weston_subsurface *sub; |
| 4360 | static const char where[] = "get_subsurface: wl_subsurface@"; |
| 4361 | |
| 4362 | if (surface == parent) { |
| 4363 | wl_resource_post_error(resource, |
| 4364 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 4365 | "%s%d: wl_surface@%d cannot be its own parent", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4366 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4367 | return; |
| 4368 | } |
| 4369 | |
| 4370 | if (weston_surface_to_subsurface(surface)) { |
| 4371 | wl_resource_post_error(resource, |
| 4372 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 4373 | "%s%d: wl_surface@%d is already a sub-surface", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4374 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4375 | return; |
| 4376 | } |
| 4377 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4378 | if (weston_surface_set_role(surface, "wl_subsurface", resource, |
| 4379 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE) < 0) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4380 | return; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4381 | |
Pekka Paalanen | 86c8ca0 | 2013-05-17 16:46:07 +0300 | [diff] [blame] | 4382 | if (weston_surface_get_main_surface(parent) == surface) { |
| 4383 | wl_resource_post_error(resource, |
| 4384 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 4385 | "%s%d: wl_surface@%d is an ancestor of parent", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4386 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | 86c8ca0 | 2013-05-17 16:46:07 +0300 | [diff] [blame] | 4387 | return; |
| 4388 | } |
| 4389 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4390 | /* make sure the parent is in its own list */ |
| 4391 | if (wl_list_empty(&parent->subsurface_list)) { |
| 4392 | if (!weston_subsurface_create_for_parent(parent)) { |
| 4393 | wl_resource_post_no_memory(resource); |
| 4394 | return; |
| 4395 | } |
| 4396 | } |
| 4397 | |
| 4398 | sub = weston_subsurface_create(id, surface, parent); |
| 4399 | if (!sub) { |
| 4400 | wl_resource_post_no_memory(resource); |
| 4401 | return; |
| 4402 | } |
| 4403 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 4404 | surface->committed = subsurface_committed; |
| 4405 | surface->committed_private = sub; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4406 | weston_surface_set_label_func(surface, subsurface_get_label); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4407 | } |
| 4408 | |
| 4409 | static void |
| 4410 | subcompositor_destroy(struct wl_client *client, struct wl_resource *resource) |
| 4411 | { |
| 4412 | wl_resource_destroy(resource); |
| 4413 | } |
| 4414 | |
| 4415 | static const struct wl_subcompositor_interface subcompositor_interface = { |
| 4416 | subcompositor_destroy, |
| 4417 | subcompositor_get_subsurface |
| 4418 | }; |
| 4419 | |
| 4420 | static void |
| 4421 | bind_subcompositor(struct wl_client *client, |
| 4422 | void *data, uint32_t version, uint32_t id) |
| 4423 | { |
| 4424 | struct weston_compositor *compositor = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4425 | struct wl_resource *resource; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4426 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4427 | resource = |
| 4428 | wl_resource_create(client, &wl_subcompositor_interface, 1, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 4429 | if (resource == NULL) { |
| 4430 | wl_client_post_no_memory(client); |
| 4431 | return; |
| 4432 | } |
| 4433 | wl_resource_set_implementation(resource, &subcompositor_interface, |
| 4434 | compositor, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4435 | } |
| 4436 | |
Bryce Harrington | 0795ece | 2016-08-30 12:04:26 -0700 | [diff] [blame] | 4437 | /** Set a DPMS mode on all of the compositor's outputs |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4438 | * |
| 4439 | * \param compositor The compositor instance |
| 4440 | * \param state The DPMS state the outputs will be set to |
| 4441 | */ |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4442 | static void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4443 | weston_compositor_dpms(struct weston_compositor *compositor, |
| 4444 | enum dpms_enum state) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4445 | { |
| 4446 | struct weston_output *output; |
| 4447 | |
Bryce Harrington | 08976ac | 2016-08-30 12:05:16 -0700 | [diff] [blame] | 4448 | wl_list_for_each(output, &compositor->output_list, link) |
| 4449 | if (output->set_dpms) |
| 4450 | output->set_dpms(output, state); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4451 | } |
| 4452 | |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4453 | /** Restores the compositor to active status |
| 4454 | * |
| 4455 | * \param compositor The compositor instance |
| 4456 | * |
| 4457 | * If the compositor was in a sleeping mode, all outputs are powered |
| 4458 | * back on via DPMS. Otherwise if the compositor was inactive |
| 4459 | * (idle/locked, offscreen, or sleeping) then the compositor's wake |
| 4460 | * signal will fire. |
| 4461 | * |
| 4462 | * Restarts the idle timer. |
| 4463 | */ |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4464 | WL_EXPORT void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4465 | weston_compositor_wake(struct weston_compositor *compositor) |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4466 | { |
Neil Roberts | 8b62e20 | 2013-09-30 13:14:47 +0100 | [diff] [blame] | 4467 | uint32_t old_state = compositor->state; |
| 4468 | |
| 4469 | /* The state needs to be changed before emitting the wake |
| 4470 | * signal because that may try to schedule a repaint which |
| 4471 | * will not work if the compositor is still sleeping */ |
| 4472 | compositor->state = WESTON_COMPOSITOR_ACTIVE; |
| 4473 | |
| 4474 | switch (old_state) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4475 | case WESTON_COMPOSITOR_SLEEPING: |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4476 | case WESTON_COMPOSITOR_IDLE: |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4477 | case WESTON_COMPOSITOR_OFFSCREEN: |
Daniel Stone | 893b936 | 2016-11-08 15:47:09 +0000 | [diff] [blame] | 4478 | weston_compositor_dpms(compositor, WESTON_DPMS_ON); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4479 | wl_signal_emit(&compositor->wake_signal, compositor); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4480 | /* fall through */ |
| 4481 | default: |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4482 | wl_event_source_timer_update(compositor->idle_source, |
| 4483 | compositor->idle_time * 1000); |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4484 | } |
| 4485 | } |
| 4486 | |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4487 | /** Turns off rendering and frame events for the compositor. |
| 4488 | * |
| 4489 | * \param compositor The compositor instance |
| 4490 | * |
| 4491 | * This is used for example to prevent further rendering while the |
| 4492 | * compositor is shutting down. |
| 4493 | * |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4494 | * Stops the idle timer. |
| 4495 | */ |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4496 | WL_EXPORT void |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4497 | weston_compositor_offscreen(struct weston_compositor *compositor) |
| 4498 | { |
| 4499 | switch (compositor->state) { |
| 4500 | case WESTON_COMPOSITOR_OFFSCREEN: |
| 4501 | return; |
| 4502 | case WESTON_COMPOSITOR_SLEEPING: |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4503 | default: |
| 4504 | compositor->state = WESTON_COMPOSITOR_OFFSCREEN; |
| 4505 | wl_event_source_timer_update(compositor->idle_source, 0); |
| 4506 | } |
| 4507 | } |
| 4508 | |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4509 | /** Powers down all attached output devices |
| 4510 | * |
| 4511 | * \param compositor The compositor instance |
| 4512 | * |
| 4513 | * Causes rendering to the outputs to cease, and no frame events to be |
| 4514 | * sent. Only powers down the outputs if the compositor is not already |
| 4515 | * in sleep mode. |
| 4516 | * |
| 4517 | * Stops the idle timer. |
| 4518 | */ |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4519 | WL_EXPORT void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4520 | weston_compositor_sleep(struct weston_compositor *compositor) |
| 4521 | { |
| 4522 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING) |
| 4523 | return; |
| 4524 | |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4525 | wl_event_source_timer_update(compositor->idle_source, 0); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4526 | compositor->state = WESTON_COMPOSITOR_SLEEPING; |
| 4527 | weston_compositor_dpms(compositor, WESTON_DPMS_OFF); |
| 4528 | } |
| 4529 | |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4530 | /** Sets compositor to idle mode |
| 4531 | * |
| 4532 | * \param data The compositor instance |
| 4533 | * |
| 4534 | * This is called when the idle timer fires. Once the compositor is in |
| 4535 | * idle mode it requires a wake action (e.g. via |
| 4536 | * weston_compositor_wake()) to restore it. The compositor's |
| 4537 | * idle_signal will be triggered when the idle event occurs. |
| 4538 | * |
| 4539 | * Idleness can be inhibited by setting the compositor's idle_inhibit |
| 4540 | * property. |
| 4541 | */ |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 4542 | static int |
| 4543 | idle_handler(void *data) |
| 4544 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4545 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 4546 | |
| 4547 | if (compositor->idle_inhibit) |
| 4548 | return 1; |
| 4549 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4550 | compositor->state = WESTON_COMPOSITOR_IDLE; |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4551 | wl_signal_emit(&compositor->idle_signal, compositor); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 4552 | |
| 4553 | return 1; |
| 4554 | } |
| 4555 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4556 | WL_EXPORT void |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 4557 | weston_plane_init(struct weston_plane *plane, |
| 4558 | struct weston_compositor *ec, |
| 4559 | int32_t x, int32_t y) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4560 | { |
| 4561 | pixman_region32_init(&plane->damage); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 4562 | pixman_region32_init(&plane->clip); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4563 | plane->x = x; |
| 4564 | plane->y = y; |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 4565 | plane->compositor = ec; |
Ander Conselvan de Oliveira | 3c36bf3 | 2013-07-05 16:05:26 +0300 | [diff] [blame] | 4566 | |
| 4567 | /* Init the link so that the call to wl_list_remove() when releasing |
| 4568 | * the plane without ever stacking doesn't lead to a crash */ |
| 4569 | wl_list_init(&plane->link); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4570 | } |
| 4571 | |
| 4572 | WL_EXPORT void |
| 4573 | weston_plane_release(struct weston_plane *plane) |
| 4574 | { |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 4575 | struct weston_view *view; |
| 4576 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4577 | pixman_region32_fini(&plane->damage); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 4578 | pixman_region32_fini(&plane->clip); |
Ander Conselvan de Oliveira | 3c36bf3 | 2013-07-05 16:05:26 +0300 | [diff] [blame] | 4579 | |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 4580 | wl_list_for_each(view, &plane->compositor->view_list, link) { |
| 4581 | if (view->plane == plane) |
| 4582 | view->plane = NULL; |
| 4583 | } |
| 4584 | |
Ander Conselvan de Oliveira | 3c36bf3 | 2013-07-05 16:05:26 +0300 | [diff] [blame] | 4585 | wl_list_remove(&plane->link); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4586 | } |
| 4587 | |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 4588 | WL_EXPORT void |
| 4589 | weston_compositor_stack_plane(struct weston_compositor *ec, |
| 4590 | struct weston_plane *plane, |
| 4591 | struct weston_plane *above) |
| 4592 | { |
| 4593 | if (above) |
| 4594 | wl_list_insert(above->link.prev, &plane->link); |
| 4595 | else |
| 4596 | wl_list_insert(&ec->plane_list, &plane->link); |
| 4597 | } |
| 4598 | |
Quentin Glidic | 4ef719c | 2016-07-05 20:44:33 +0200 | [diff] [blame] | 4599 | static void |
| 4600 | output_release(struct wl_client *client, struct wl_resource *resource) |
| 4601 | { |
| 4602 | wl_resource_destroy(resource); |
| 4603 | } |
| 4604 | |
| 4605 | static const struct wl_output_interface output_interface = { |
| 4606 | output_release, |
| 4607 | }; |
| 4608 | |
| 4609 | |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 4610 | static void unbind_resource(struct wl_resource *resource) |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 4611 | { |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4612 | wl_list_remove(wl_resource_get_link(resource)); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 4613 | } |
| 4614 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4615 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4616 | bind_output(struct wl_client *client, |
| 4617 | void *data, uint32_t version, uint32_t id) |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 4618 | { |
Pekka Paalanen | 0534762 | 2017-03-27 12:24:34 +0300 | [diff] [blame] | 4619 | struct weston_head *head = data; |
| 4620 | struct weston_output *output = head->output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4621 | struct weston_mode *mode; |
Kristian Høgsberg | fd07fb7 | 2011-08-29 15:03:09 -0400 | [diff] [blame] | 4622 | struct wl_resource *resource; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 4623 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4624 | resource = wl_resource_create(client, &wl_output_interface, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 4625 | version, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 4626 | if (resource == NULL) { |
| 4627 | wl_client_post_no_memory(client); |
| 4628 | return; |
| 4629 | } |
Kristian Høgsberg | fd07fb7 | 2011-08-29 15:03:09 -0400 | [diff] [blame] | 4630 | |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 4631 | wl_list_insert(&head->resource_list, wl_resource_get_link(resource)); |
Pekka Paalanen | 055c113 | 2017-03-27 16:31:25 +0300 | [diff] [blame] | 4632 | wl_resource_set_implementation(resource, &output_interface, head, |
Pekka Paalanen | 0534762 | 2017-03-27 12:24:34 +0300 | [diff] [blame] | 4633 | unbind_resource); |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 4634 | |
Pekka Paalanen | 0534762 | 2017-03-27 12:24:34 +0300 | [diff] [blame] | 4635 | assert(output); |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4636 | wl_output_send_geometry(resource, |
| 4637 | output->x, |
| 4638 | output->y, |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 4639 | head->mm_width, |
| 4640 | head->mm_height, |
| 4641 | head->subpixel, |
| 4642 | head->make, head->model, |
Kristian Høgsberg | 05890dc | 2012-08-10 10:09:20 -0400 | [diff] [blame] | 4643 | output->transform); |
Jasper St. Pierre | 0013a29 | 2014-08-07 16:43:11 -0400 | [diff] [blame] | 4644 | if (version >= WL_OUTPUT_SCALE_SINCE_VERSION) |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 4645 | wl_output_send_scale(resource, |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 4646 | output->current_scale); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 4647 | |
| 4648 | wl_list_for_each (mode, &output->mode_list, link) { |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4649 | wl_output_send_mode(resource, |
| 4650 | mode->flags, |
| 4651 | mode->width, |
| 4652 | mode->height, |
| 4653 | mode->refresh); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 4654 | } |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 4655 | |
Jasper St. Pierre | 0013a29 | 2014-08-07 16:43:11 -0400 | [diff] [blame] | 4656 | if (version >= WL_OUTPUT_DONE_SINCE_VERSION) |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 4657 | wl_output_send_done(resource); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 4658 | } |
| 4659 | |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 4660 | static void |
| 4661 | weston_head_add_global(struct weston_head *head) |
| 4662 | { |
| 4663 | head->global = wl_global_create(head->compositor->wl_display, |
| 4664 | &wl_output_interface, 3, |
| 4665 | head, bind_output); |
| 4666 | } |
| 4667 | |
Pekka Paalanen | d9dcc6d | 2017-12-04 15:28:13 +0200 | [diff] [blame] | 4668 | /** Remove the global wl_output protocol object |
| 4669 | * |
| 4670 | * \param head The head whose global to remove. |
| 4671 | * |
| 4672 | * Also orphans the wl_resources for this head (wl_output). |
| 4673 | */ |
| 4674 | static void |
| 4675 | weston_head_remove_global(struct weston_head *head) |
| 4676 | { |
| 4677 | struct wl_resource *resource, *tmp; |
| 4678 | |
| 4679 | if (head->global) |
| 4680 | wl_global_destroy(head->global); |
| 4681 | head->global = NULL; |
| 4682 | |
| 4683 | wl_resource_for_each_safe(resource, tmp, &head->resource_list) { |
| 4684 | unbind_resource(resource); |
| 4685 | wl_resource_set_destructor(resource, NULL); |
| 4686 | wl_resource_set_user_data(resource, NULL); |
| 4687 | } |
| 4688 | } |
| 4689 | |
Pekka Paalanen | 9ffb250 | 2017-03-27 15:14:32 +0300 | [diff] [blame] | 4690 | /** Get the backing object of wl_output |
| 4691 | * |
| 4692 | * \param resource A wl_output protocol object. |
| 4693 | * \return The backing object (user data) of a wl_resource representing a |
| 4694 | * wl_output protocol object. |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 4695 | * |
| 4696 | * \ingroup head |
Pekka Paalanen | 9ffb250 | 2017-03-27 15:14:32 +0300 | [diff] [blame] | 4697 | */ |
Pekka Paalanen | 055c113 | 2017-03-27 16:31:25 +0300 | [diff] [blame] | 4698 | WL_EXPORT struct weston_head * |
| 4699 | weston_head_from_resource(struct wl_resource *resource) |
Pekka Paalanen | 9ffb250 | 2017-03-27 15:14:32 +0300 | [diff] [blame] | 4700 | { |
| 4701 | assert(wl_resource_instance_of(resource, &wl_output_interface, |
| 4702 | &output_interface)); |
| 4703 | |
| 4704 | return wl_resource_get_user_data(resource); |
| 4705 | } |
| 4706 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4707 | /** Initialize a pre-allocated weston_head |
| 4708 | * |
| 4709 | * \param head The head to initialize. |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 4710 | * \param name The head name, e.g. the connector name or equivalent. |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4711 | * |
| 4712 | * The head will be safe to attach, detach and release. |
| 4713 | * |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 4714 | * The name is used in logs, and can be used by compositors as a configuration |
| 4715 | * identifier. |
| 4716 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 4717 | * \ingroup head |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4718 | * \internal |
| 4719 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 4720 | WL_EXPORT void |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 4721 | weston_head_init(struct weston_head *head, const char *name) |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4722 | { |
| 4723 | /* Add some (in)sane defaults which can be used |
| 4724 | * for checking if an output was properly configured |
| 4725 | */ |
| 4726 | memset(head, 0, sizeof *head); |
| 4727 | |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 4728 | wl_list_init(&head->compositor_link); |
Pekka Paalanen | 2e1bedb | 2017-10-10 11:21:58 +0300 | [diff] [blame] | 4729 | wl_signal_init(&head->destroy_signal); |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4730 | wl_list_init(&head->output_link); |
| 4731 | wl_list_init(&head->resource_list); |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 4732 | head->name = strdup(name); |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4733 | } |
| 4734 | |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 4735 | /** Send output heads changed signal |
| 4736 | * |
| 4737 | * \param output The output that changed. |
| 4738 | * |
| 4739 | * Notify that the enabled output gained and/or lost heads, or that the |
| 4740 | * associated heads may have changed their connection status. This does not |
| 4741 | * include cases where the output becomes enabled or disabled. The registered |
| 4742 | * callbacks are called after the change has successfully happened. |
| 4743 | * |
| 4744 | * If connection status change causes the compositor to attach or detach a head |
| 4745 | * to an enabled output, the registered callbacks may be called multiple times. |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame^] | 4746 | * |
| 4747 | * \ingroup output |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 4748 | */ |
| 4749 | static void |
| 4750 | weston_output_emit_heads_changed(struct weston_output *output) |
| 4751 | { |
| 4752 | wl_signal_emit(&output->compositor->output_heads_changed_signal, |
| 4753 | output); |
| 4754 | } |
| 4755 | |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4756 | /** Idle task for emitting heads_changed_signal */ |
| 4757 | static void |
| 4758 | weston_compositor_call_heads_changed(void *data) |
| 4759 | { |
| 4760 | struct weston_compositor *compositor = data; |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 4761 | struct weston_head *head; |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4762 | |
| 4763 | compositor->heads_changed_source = NULL; |
| 4764 | |
| 4765 | wl_signal_emit(&compositor->heads_changed_signal, compositor); |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 4766 | |
| 4767 | wl_list_for_each(head, &compositor->head_list, compositor_link) { |
| 4768 | if (head->output && head->output->enabled) |
| 4769 | weston_output_emit_heads_changed(head->output); |
| 4770 | } |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4771 | } |
| 4772 | |
| 4773 | /** Schedule a call on idle to heads_changed callback |
| 4774 | * |
| 4775 | * \param compositor The Compositor. |
| 4776 | * |
| 4777 | * \memberof weston_compositor |
| 4778 | * \internal |
| 4779 | */ |
| 4780 | static void |
| 4781 | weston_compositor_schedule_heads_changed(struct weston_compositor *compositor) |
| 4782 | { |
| 4783 | struct wl_event_loop *loop; |
| 4784 | |
| 4785 | if (compositor->heads_changed_source) |
| 4786 | return; |
| 4787 | |
| 4788 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 4789 | compositor->heads_changed_source = wl_event_loop_add_idle(loop, |
| 4790 | weston_compositor_call_heads_changed, compositor); |
| 4791 | } |
| 4792 | |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 4793 | /** Register a new head |
| 4794 | * |
| 4795 | * \param compositor The compositor. |
| 4796 | * \param head The head to register, must not be already registered. |
| 4797 | * |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4798 | * This signals the core that a new head has become available, leading to |
| 4799 | * heads_changed hook being called later. |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 4800 | * |
| 4801 | * \memberof weston_compositor |
| 4802 | * \internal |
| 4803 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 4804 | WL_EXPORT void |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 4805 | weston_compositor_add_head(struct weston_compositor *compositor, |
| 4806 | struct weston_head *head) |
| 4807 | { |
| 4808 | assert(wl_list_empty(&head->compositor_link)); |
| 4809 | assert(head->name); |
| 4810 | |
| 4811 | wl_list_insert(compositor->head_list.prev, &head->compositor_link); |
| 4812 | head->compositor = compositor; |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4813 | weston_compositor_schedule_heads_changed(compositor); |
| 4814 | } |
| 4815 | |
| 4816 | /** Adds a listener to be called when heads change |
| 4817 | * |
| 4818 | * \param compositor The compositor. |
| 4819 | * \param listener The listener to add. |
| 4820 | * |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 4821 | * The listener notify function argument is weston_compositor. |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4822 | * |
| 4823 | * The listener function will be called after heads are added or their |
| 4824 | * connection status has changed. Several changes may be accumulated into a |
| 4825 | * single call. The user is expected to iterate over the existing heads and |
| 4826 | * check their statuses to find out what changed. |
| 4827 | * |
| 4828 | * \sa weston_compositor_iterate_heads, weston_head_is_connected, |
| 4829 | * weston_head_is_enabled |
| 4830 | * \memberof weston_compositor |
| 4831 | */ |
| 4832 | WL_EXPORT void |
| 4833 | weston_compositor_add_heads_changed_listener(struct weston_compositor *compositor, |
| 4834 | struct wl_listener *listener) |
| 4835 | { |
| 4836 | wl_signal_add(&compositor->heads_changed_signal, listener); |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 4837 | } |
| 4838 | |
| 4839 | /** Iterate over available heads |
| 4840 | * |
| 4841 | * \param compositor The compositor. |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 4842 | * \param iter The iterator, or NULL for start. |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 4843 | * \return The next available head in the list. |
| 4844 | * |
| 4845 | * Returns all available heads, regardless of being connected or enabled. |
| 4846 | * |
| 4847 | * You can iterate over all heads as follows: |
| 4848 | * \code |
| 4849 | * struct weston_head *head = NULL; |
| 4850 | * |
| 4851 | * while ((head = weston_compositor_iterate_heads(compositor, head))) { |
| 4852 | * ... |
| 4853 | * } |
| 4854 | * \endcode |
| 4855 | * |
| 4856 | * If you cause \c iter to be removed from the list, you cannot use it to |
| 4857 | * continue iterating. Removing any other item is safe. |
| 4858 | * |
| 4859 | * \memberof weston_compositor |
| 4860 | */ |
| 4861 | WL_EXPORT struct weston_head * |
| 4862 | weston_compositor_iterate_heads(struct weston_compositor *compositor, |
| 4863 | struct weston_head *iter) |
| 4864 | { |
| 4865 | struct wl_list *list = &compositor->head_list; |
| 4866 | struct wl_list *node; |
| 4867 | |
| 4868 | assert(compositor); |
| 4869 | assert(!iter || iter->compositor == compositor); |
| 4870 | |
| 4871 | if (iter) |
| 4872 | node = iter->compositor_link.next; |
| 4873 | else |
| 4874 | node = list->next; |
| 4875 | |
| 4876 | assert(node); |
| 4877 | assert(!iter || node != &iter->compositor_link); |
| 4878 | |
| 4879 | if (node == list) |
| 4880 | return NULL; |
| 4881 | |
| 4882 | return container_of(node, struct weston_head, compositor_link); |
| 4883 | } |
| 4884 | |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 4885 | /** Iterate over attached heads |
| 4886 | * |
| 4887 | * \param output The output whose heads to iterate. |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 4888 | * \param iter The iterator, or NULL for start. |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 4889 | * \return The next attached head in the list. |
| 4890 | * |
| 4891 | * Returns all heads currently attached to the output. |
| 4892 | * |
| 4893 | * You can iterate over all heads as follows: |
| 4894 | * \code |
| 4895 | * struct weston_head *head = NULL; |
| 4896 | * |
| 4897 | * while ((head = weston_output_iterate_heads(output, head))) { |
| 4898 | * ... |
| 4899 | * } |
| 4900 | * \endcode |
| 4901 | * |
| 4902 | * If you cause \c iter to be removed from the list, you cannot use it to |
| 4903 | * continue iterating. Removing any other item is safe. |
| 4904 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame^] | 4905 | * \ingroup ouput |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 4906 | */ |
| 4907 | WL_EXPORT struct weston_head * |
| 4908 | weston_output_iterate_heads(struct weston_output *output, |
| 4909 | struct weston_head *iter) |
| 4910 | { |
| 4911 | struct wl_list *list = &output->head_list; |
| 4912 | struct wl_list *node; |
| 4913 | |
| 4914 | assert(output); |
| 4915 | assert(!iter || iter->output == output); |
| 4916 | |
| 4917 | if (iter) |
| 4918 | node = iter->output_link.next; |
| 4919 | else |
| 4920 | node = list->next; |
| 4921 | |
| 4922 | assert(node); |
| 4923 | assert(!iter || node != &iter->output_link); |
| 4924 | |
| 4925 | if (node == list) |
| 4926 | return NULL; |
| 4927 | |
| 4928 | return container_of(node, struct weston_head, output_link); |
| 4929 | } |
| 4930 | |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 4931 | /** Attach a head to an output |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4932 | * |
| 4933 | * \param output The output to attach to. |
| 4934 | * \param head The head that is not yet attached. |
| 4935 | * \return 0 on success, -1 on failure. |
| 4936 | * |
| 4937 | * Attaches the given head to the output. All heads of an output are clones |
| 4938 | * and share the resolution and timings. |
| 4939 | * |
| 4940 | * Cloning heads this way uses less resources than creating an output for |
| 4941 | * each head, but is not always possible due to environment, driver and hardware |
| 4942 | * limitations. |
| 4943 | * |
| 4944 | * On failure, the head remains unattached. Success of this function does not |
| 4945 | * guarantee the output configuration is actually valid. The final checks are |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 4946 | * made on weston_output_enable() unless the output was already enabled. |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4947 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame^] | 4948 | * \ingroup output |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4949 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 4950 | WL_EXPORT int |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4951 | weston_output_attach_head(struct weston_output *output, |
| 4952 | struct weston_head *head) |
| 4953 | { |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 4954 | char *head_names; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4955 | |
| 4956 | if (!wl_list_empty(&head->output_link)) |
| 4957 | return -1; |
| 4958 | |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 4959 | if (output->attach_head) { |
| 4960 | if (output->attach_head(output, head) < 0) |
| 4961 | return -1; |
| 4962 | } else if (!wl_list_empty(&output->head_list)) { |
| 4963 | /* No support for clones in the legacy path. */ |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4964 | return -1; |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 4965 | } |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4966 | |
| 4967 | head->output = output; |
| 4968 | wl_list_insert(output->head_list.prev, &head->output_link); |
| 4969 | |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 4970 | if (output->enabled) { |
| 4971 | weston_head_add_global(head); |
| 4972 | |
| 4973 | head_names = weston_output_create_heads_string(output); |
| 4974 | weston_log("Output '%s' updated to have head(s) %s\n", |
| 4975 | output->name, head_names); |
| 4976 | free(head_names); |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 4977 | |
| 4978 | weston_output_emit_heads_changed(output); |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 4979 | } |
| 4980 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4981 | return 0; |
| 4982 | } |
| 4983 | |
| 4984 | /** Detach a head from its output |
| 4985 | * |
| 4986 | * \param head The head to detach. |
| 4987 | * |
| 4988 | * It is safe to detach a non-attached head. |
| 4989 | * |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 4990 | * If the head is attached to an enabled output and the output will be left |
| 4991 | * with no heads, the output will be disabled. |
| 4992 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 4993 | * \ingroup head |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 4994 | * \sa weston_output_disable |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4995 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 4996 | WL_EXPORT void |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4997 | weston_head_detach(struct weston_head *head) |
| 4998 | { |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 4999 | struct weston_output *output = head->output; |
Pekka Paalanen | a010699 | 2017-12-08 16:11:17 +0200 | [diff] [blame] | 5000 | char *head_names; |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5001 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5002 | wl_list_remove(&head->output_link); |
| 5003 | wl_list_init(&head->output_link); |
| 5004 | head->output = NULL; |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5005 | |
| 5006 | if (!output) |
| 5007 | return; |
| 5008 | |
| 5009 | if (output->detach_head) |
| 5010 | output->detach_head(output, head); |
| 5011 | |
| 5012 | if (output->enabled) { |
| 5013 | weston_head_remove_global(head); |
| 5014 | |
Pekka Paalanen | a010699 | 2017-12-08 16:11:17 +0200 | [diff] [blame] | 5015 | if (wl_list_empty(&output->head_list)) { |
| 5016 | weston_log("Output '%s' no heads left, disabling.\n", |
| 5017 | output->name); |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5018 | weston_output_disable(output); |
Pekka Paalanen | a010699 | 2017-12-08 16:11:17 +0200 | [diff] [blame] | 5019 | } else { |
| 5020 | head_names = weston_output_create_heads_string(output); |
| 5021 | weston_log("Output '%s' updated to have head(s) %s\n", |
| 5022 | output->name, head_names); |
| 5023 | free(head_names); |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 5024 | |
| 5025 | weston_output_emit_heads_changed(output); |
Pekka Paalanen | a010699 | 2017-12-08 16:11:17 +0200 | [diff] [blame] | 5026 | } |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5027 | } |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5028 | } |
| 5029 | |
| 5030 | /** Destroy a head |
| 5031 | * |
| 5032 | * \param head The head to be released. |
| 5033 | * |
| 5034 | * Destroys the head. The caller is responsible for freeing the memory pointed |
| 5035 | * to by \c head. |
| 5036 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5037 | * \ingroup head |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5038 | * \internal |
| 5039 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5040 | WL_EXPORT void |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5041 | weston_head_release(struct weston_head *head) |
| 5042 | { |
Pekka Paalanen | 2e1bedb | 2017-10-10 11:21:58 +0300 | [diff] [blame] | 5043 | wl_signal_emit(&head->destroy_signal, head); |
| 5044 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5045 | weston_head_detach(head); |
Pekka Paalanen | 06f99ef | 2017-04-04 16:26:23 +0300 | [diff] [blame] | 5046 | |
| 5047 | free(head->make); |
| 5048 | free(head->model); |
| 5049 | free(head->serial_number); |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 5050 | free(head->name); |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 5051 | |
| 5052 | wl_list_remove(&head->compositor_link); |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5053 | } |
| 5054 | |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5055 | static void |
| 5056 | weston_head_set_device_changed(struct weston_head *head) |
| 5057 | { |
| 5058 | head->device_changed = true; |
| 5059 | |
| 5060 | if (head->compositor) |
| 5061 | weston_compositor_schedule_heads_changed(head->compositor); |
| 5062 | } |
| 5063 | |
| 5064 | /** String equal comparison with NULLs being equal */ |
| 5065 | static bool |
| 5066 | str_null_eq(const char *a, const char *b) |
| 5067 | { |
| 5068 | if (!a && !b) |
| 5069 | return true; |
| 5070 | |
| 5071 | if (!!a != !!b) |
| 5072 | return false; |
| 5073 | |
| 5074 | return strcmp(a, b) == 0; |
| 5075 | } |
| 5076 | |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5077 | /** Store monitor make, model and serial number |
| 5078 | * |
| 5079 | * \param head The head to modify. |
| 5080 | * \param make The monitor make. If EDID is available, the PNP ID. Otherwise |
| 5081 | * any string, or NULL for none. |
| 5082 | * \param model The monitor model or name, or a made-up string, or NULL for |
| 5083 | * none. |
| 5084 | * \param serialno The monitor serial number, a made-up string, or NULL for |
| 5085 | * none. |
| 5086 | * |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5087 | * This may set the device_changed flag. |
| 5088 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5089 | * \ingroup head |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5090 | * \internal |
| 5091 | */ |
| 5092 | WL_EXPORT void |
| 5093 | weston_head_set_monitor_strings(struct weston_head *head, |
| 5094 | const char *make, |
| 5095 | const char *model, |
| 5096 | const char *serialno) |
| 5097 | { |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5098 | if (str_null_eq(head->make, make) && |
| 5099 | str_null_eq(head->model, model) && |
| 5100 | str_null_eq(head->serial_number, serialno)) |
| 5101 | return; |
| 5102 | |
Pekka Paalanen | 06f99ef | 2017-04-04 16:26:23 +0300 | [diff] [blame] | 5103 | free(head->make); |
| 5104 | free(head->model); |
| 5105 | free(head->serial_number); |
| 5106 | |
| 5107 | head->make = make ? strdup(make) : NULL; |
| 5108 | head->model = model ? strdup(model) : NULL; |
| 5109 | head->serial_number = serialno ? strdup(serialno) : NULL; |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5110 | |
| 5111 | weston_head_set_device_changed(head); |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5112 | } |
| 5113 | |
Philipp Zabel | c18ffd3 | 2018-08-30 17:38:03 +0200 | [diff] [blame] | 5114 | /** Store display non-desktop status |
| 5115 | * |
| 5116 | * \param head The head to modify. |
| 5117 | * \param non_desktop Whether the head connects to a non-desktop display. |
| 5118 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5119 | * \ingroup head |
Philipp Zabel | c18ffd3 | 2018-08-30 17:38:03 +0200 | [diff] [blame] | 5120 | * \internal |
| 5121 | */ |
| 5122 | WL_EXPORT void |
| 5123 | weston_head_set_non_desktop(struct weston_head *head, bool non_desktop) |
| 5124 | { |
| 5125 | if (head->non_desktop == non_desktop) |
| 5126 | return; |
| 5127 | |
| 5128 | head->non_desktop = non_desktop; |
| 5129 | |
| 5130 | weston_head_set_device_changed(head); |
| 5131 | } |
| 5132 | |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5133 | /** Store physical image size |
| 5134 | * |
| 5135 | * \param head The head to modify. |
| 5136 | * \param mm_width Image area width in millimeters. |
| 5137 | * \param mm_height Image area height in millimeters. |
| 5138 | * |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5139 | * This may set the device_changed flag. |
| 5140 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5141 | * \ingroup head |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5142 | * \internal |
| 5143 | */ |
| 5144 | WL_EXPORT void |
| 5145 | weston_head_set_physical_size(struct weston_head *head, |
| 5146 | int32_t mm_width, int32_t mm_height) |
| 5147 | { |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5148 | if (head->mm_width == mm_width && |
| 5149 | head->mm_height == mm_height) |
| 5150 | return; |
| 5151 | |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5152 | head->mm_width = mm_width; |
| 5153 | head->mm_height = mm_height; |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5154 | |
| 5155 | weston_head_set_device_changed(head); |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5156 | } |
| 5157 | |
| 5158 | /** Store monitor sub-pixel layout |
| 5159 | * |
| 5160 | * \param head The head to modify. |
| 5161 | * \param sp Sub-pixel layout. The possible values are: |
| 5162 | * - WL_OUTPUT_SUBPIXEL_UNKNOWN, |
| 5163 | * - WL_OUTPUT_SUBPIXEL_NONE, |
| 5164 | * - WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB, |
| 5165 | * - WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR, |
| 5166 | * - WL_OUTPUT_SUBPIXEL_VERTICAL_RGB, |
| 5167 | * - WL_OUTPUT_SUBPIXEL_VERTICAL_BGR |
| 5168 | * |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5169 | * This may set the device_changed flag. |
| 5170 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5171 | * \ingroup head |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5172 | * \internal |
| 5173 | */ |
| 5174 | WL_EXPORT void |
| 5175 | weston_head_set_subpixel(struct weston_head *head, |
| 5176 | enum wl_output_subpixel sp) |
| 5177 | { |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5178 | if (head->subpixel == sp) |
| 5179 | return; |
| 5180 | |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5181 | head->subpixel = sp; |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5182 | |
| 5183 | weston_head_set_device_changed(head); |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5184 | } |
| 5185 | |
| 5186 | /** Mark the monitor as internal |
| 5187 | * |
| 5188 | * This is used for embedded screens, like laptop panels. |
| 5189 | * |
| 5190 | * \param head The head to mark as internal. |
| 5191 | * |
| 5192 | * By default a head is external. The type is often inferred from the physical |
| 5193 | * connector type. |
| 5194 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5195 | * \ingroup head |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 5196 | * \internal |
| 5197 | */ |
| 5198 | WL_EXPORT void |
| 5199 | weston_head_set_internal(struct weston_head *head) |
| 5200 | { |
| 5201 | head->connection_internal = true; |
| 5202 | } |
Pekka Paalanen | 9ffb250 | 2017-03-27 15:14:32 +0300 | [diff] [blame] | 5203 | |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5204 | /** Store connector status |
| 5205 | * |
| 5206 | * \param head The head to modify. |
| 5207 | * \param connected Whether the head is connected. |
| 5208 | * |
| 5209 | * Connectors are created as disconnected. This function can be used to |
| 5210 | * set the connector status. |
| 5211 | * |
| 5212 | * The status should be set to true when a physical connector is connected to |
| 5213 | * a video sink device like a monitor and to false when the connector is |
| 5214 | * disconnected. For nested backends, the connection status should reflect the |
| 5215 | * connection to the parent display server. |
| 5216 | * |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5217 | * 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] | 5218 | * hook and sets the device_changed flag. |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5219 | * |
| 5220 | * \sa weston_compositor_set_heads_changed_cb |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5221 | * \ingroup head |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5222 | * \internal |
| 5223 | */ |
| 5224 | WL_EXPORT void |
| 5225 | weston_head_set_connection_status(struct weston_head *head, bool connected) |
| 5226 | { |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5227 | if (head->connected == connected) |
| 5228 | return; |
| 5229 | |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5230 | head->connected = connected; |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5231 | |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5232 | weston_head_set_device_changed(head); |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5233 | } |
| 5234 | |
| 5235 | /** Is the head currently connected? |
| 5236 | * |
| 5237 | * \param head The head to query. |
| 5238 | * \return Connection status. |
| 5239 | * |
| 5240 | * Returns true if the head is physically connected to a monitor, or in |
| 5241 | * case of a nested backend returns true when there is a connection to the |
| 5242 | * parent display server. |
| 5243 | * |
| 5244 | * This is independent from the head being enabled. |
| 5245 | * |
| 5246 | * \sa weston_head_is_enabled |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5247 | * \ingroup head |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 5248 | */ |
| 5249 | WL_EXPORT bool |
| 5250 | weston_head_is_connected(struct weston_head *head) |
| 5251 | { |
| 5252 | return head->connected; |
| 5253 | } |
| 5254 | |
Pekka Paalanen | 8e552fd | 2018-02-15 15:18:20 +0200 | [diff] [blame] | 5255 | /** Is the head currently enabled? |
| 5256 | * |
| 5257 | * \param head The head to query. |
| 5258 | * \return Video status. |
| 5259 | * |
| 5260 | * Returns true if the head is currently transmitting a video stream. |
| 5261 | * |
| 5262 | * This is independent of the head being connected. |
| 5263 | * |
| 5264 | * \sa weston_head_is_connected |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5265 | * \ingroup head |
Pekka Paalanen | 8e552fd | 2018-02-15 15:18:20 +0200 | [diff] [blame] | 5266 | */ |
| 5267 | WL_EXPORT bool |
| 5268 | weston_head_is_enabled(struct weston_head *head) |
| 5269 | { |
| 5270 | if (!head->output) |
| 5271 | return false; |
| 5272 | |
| 5273 | return head->output->enabled; |
| 5274 | } |
| 5275 | |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5276 | /** Has the device information changed? |
| 5277 | * |
| 5278 | * \param head The head to query. |
| 5279 | * \return True if the device information has changed since last reset. |
| 5280 | * |
| 5281 | * The information about the connected display device, e.g. a monitor, may |
| 5282 | * change without being disconnected in between. Changing information |
| 5283 | * causes a call to the heads_changed hook. |
| 5284 | * |
| 5285 | * The information includes make, model, serial number, physical size, |
| 5286 | * and sub-pixel type. The connection status is also included. |
| 5287 | * |
| 5288 | * \sa weston_head_reset_device_changed, weston_compositor_set_heads_changed_cb |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5289 | * \ingroup head |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5290 | */ |
| 5291 | WL_EXPORT bool |
| 5292 | weston_head_is_device_changed(struct weston_head *head) |
| 5293 | { |
| 5294 | return head->device_changed; |
| 5295 | } |
| 5296 | |
Philipp Zabel | c18ffd3 | 2018-08-30 17:38:03 +0200 | [diff] [blame] | 5297 | /** Does the head represent a non-desktop display? |
| 5298 | * |
| 5299 | * \param head The head to query. |
| 5300 | * \return True if the device is a non-desktop display. |
| 5301 | * |
| 5302 | * Non-desktop heads are not attached to outputs by default. |
| 5303 | * This stops weston from extending the desktop onto head mounted displays. |
| 5304 | * |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5305 | * \ingroup head |
Philipp Zabel | c18ffd3 | 2018-08-30 17:38:03 +0200 | [diff] [blame] | 5306 | */ |
| 5307 | WL_EXPORT bool |
| 5308 | weston_head_is_non_desktop(struct weston_head *head) |
| 5309 | { |
| 5310 | return head->non_desktop; |
| 5311 | } |
| 5312 | |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5313 | /** Acknowledge device information change |
| 5314 | * |
| 5315 | * \param head The head to acknowledge. |
| 5316 | * |
| 5317 | * Clears the device changed flag on this head. When a compositor has processed |
| 5318 | * device information, it should call this to be able to notice further |
| 5319 | * changes. |
| 5320 | * |
| 5321 | * \sa weston_head_is_device_changed |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5322 | * \ingroup head |
Pekka Paalanen | e19970f | 2017-08-28 14:11:02 +0300 | [diff] [blame] | 5323 | */ |
| 5324 | WL_EXPORT void |
| 5325 | weston_head_reset_device_changed(struct weston_head *head) |
| 5326 | { |
| 5327 | head->device_changed = false; |
| 5328 | } |
| 5329 | |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5330 | /** Get the name of a head |
| 5331 | * |
| 5332 | * \param head The head to query. |
| 5333 | * \return The head's name, not NULL. |
| 5334 | * |
| 5335 | * The name depends on the backend. The DRM backend uses connector names, |
| 5336 | * other backends may use hardcoded names or user-given names. |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5337 | * |
| 5338 | * \ingroup head |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5339 | */ |
| 5340 | WL_EXPORT const char * |
| 5341 | weston_head_get_name(struct weston_head *head) |
| 5342 | { |
| 5343 | return head->name; |
| 5344 | } |
| 5345 | |
| 5346 | /** Get the output the head is attached to |
| 5347 | * |
| 5348 | * \param head The head to query. |
| 5349 | * \return The output the head is attached to, or NULL if detached. |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5350 | * \ingroup head |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 5351 | */ |
| 5352 | WL_EXPORT struct weston_output * |
| 5353 | weston_head_get_output(struct weston_head *head) |
| 5354 | { |
| 5355 | return head->output; |
| 5356 | } |
| 5357 | |
Pekka Paalanen | 2e1bedb | 2017-10-10 11:21:58 +0300 | [diff] [blame] | 5358 | /** Add destroy callback for a head |
| 5359 | * |
| 5360 | * \param head The head to watch for. |
| 5361 | * \param listener The listener to add. The \c notify member must be set. |
| 5362 | * |
| 5363 | * Heads may get destroyed for various reasons by the backends. If a head is |
| 5364 | * attached to an output, the compositor should listen for head destruction |
| 5365 | * and reconfigure or destroy the output if necessary. |
| 5366 | * |
| 5367 | * The destroy callbacks will be called on weston_head destruction before any |
| 5368 | * automatic detaching from an associated weston_output and before any |
| 5369 | * weston_head information is lost. |
| 5370 | * |
| 5371 | * The \c data argument to the notify callback is the weston_head being |
| 5372 | * destroyed. |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5373 | * |
| 5374 | * \ingroup head |
Pekka Paalanen | 2e1bedb | 2017-10-10 11:21:58 +0300 | [diff] [blame] | 5375 | */ |
| 5376 | WL_EXPORT void |
| 5377 | weston_head_add_destroy_listener(struct weston_head *head, |
| 5378 | struct wl_listener *listener) |
| 5379 | { |
| 5380 | wl_signal_add(&head->destroy_signal, listener); |
| 5381 | } |
| 5382 | |
| 5383 | /** Look up destroy listener for a head |
| 5384 | * |
| 5385 | * \param head The head to query. |
| 5386 | * \param notify The notify function used used for the added destroy listener. |
| 5387 | * \return The listener, or NULL if not found. |
| 5388 | * |
| 5389 | * This looks up the previously added destroy listener struct based on the |
| 5390 | * notify function it has. The listener can be used to access user data |
| 5391 | * through \c container_of(). |
| 5392 | * |
| 5393 | * \sa wl_signal_get() |
Marius Vlad | 78984ee | 2019-06-11 00:05:08 +0300 | [diff] [blame] | 5394 | * \ingroup head |
Pekka Paalanen | 2e1bedb | 2017-10-10 11:21:58 +0300 | [diff] [blame] | 5395 | */ |
| 5396 | WL_EXPORT struct wl_listener * |
| 5397 | weston_head_get_destroy_listener(struct weston_head *head, |
| 5398 | wl_notify_func_t notify) |
| 5399 | { |
| 5400 | return wl_signal_get(&head->destroy_signal, notify); |
| 5401 | } |
| 5402 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 5403 | /* 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] | 5404 | static void |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 5405 | weston_compositor_reflow_outputs(struct weston_compositor *compositor, |
| 5406 | struct weston_output *resized_output, int delta_width) |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 5407 | { |
| 5408 | struct weston_output *output; |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 5409 | bool start_resizing = false; |
| 5410 | |
| 5411 | if (!delta_width) |
| 5412 | return; |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 5413 | |
| 5414 | wl_list_for_each(output, &compositor->output_list, link) { |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 5415 | if (output == resized_output) { |
| 5416 | start_resizing = true; |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 5417 | continue; |
| 5418 | } |
| 5419 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 5420 | if (start_resizing) { |
| 5421 | weston_output_move(output, output->x + delta_width, output->y); |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 5422 | output->dirty = 1; |
| 5423 | } |
| 5424 | } |
| 5425 | } |
| 5426 | |
Pekka Paalanen | d72bad2 | 2017-03-29 17:01:41 +0300 | [diff] [blame] | 5427 | static void |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5428 | weston_output_update_matrix(struct weston_output *output) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 5429 | { |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 5430 | float magnification; |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 5431 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5432 | weston_matrix_init(&output->matrix); |
Jason Ekstrand | fb23df7 | 2014-10-16 10:55:21 -0500 | [diff] [blame] | 5433 | weston_matrix_translate(&output->matrix, -output->x, -output->y, 0); |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 5434 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5435 | if (output->zoom.active) { |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 5436 | magnification = 1 / (1 - output->zoom.spring_z.current); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5437 | weston_output_update_zoom(output); |
Neil Roberts | 1e40a7e | 2014-04-25 13:19:37 +0100 | [diff] [blame] | 5438 | weston_matrix_translate(&output->matrix, -output->zoom.trans_x, |
Jason Ekstrand | fb23df7 | 2014-10-16 10:55:21 -0500 | [diff] [blame] | 5439 | -output->zoom.trans_y, 0); |
Neil Roberts | 1e40a7e | 2014-04-25 13:19:37 +0100 | [diff] [blame] | 5440 | weston_matrix_scale(&output->matrix, magnification, |
| 5441 | magnification, 1.0); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5442 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 5443 | |
Jason Ekstrand | fb23df7 | 2014-10-16 10:55:21 -0500 | [diff] [blame] | 5444 | switch (output->transform) { |
| 5445 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 5446 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 5447 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 5448 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 5449 | weston_matrix_translate(&output->matrix, -output->width, 0, 0); |
| 5450 | weston_matrix_scale(&output->matrix, -1, 1, 1); |
| 5451 | break; |
| 5452 | } |
| 5453 | |
| 5454 | switch (output->transform) { |
| 5455 | default: |
| 5456 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 5457 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 5458 | break; |
| 5459 | case WL_OUTPUT_TRANSFORM_90: |
| 5460 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 5461 | weston_matrix_translate(&output->matrix, 0, -output->height, 0); |
| 5462 | weston_matrix_rotate_xy(&output->matrix, 0, 1); |
| 5463 | break; |
| 5464 | case WL_OUTPUT_TRANSFORM_180: |
| 5465 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 5466 | weston_matrix_translate(&output->matrix, |
| 5467 | -output->width, -output->height, 0); |
| 5468 | weston_matrix_rotate_xy(&output->matrix, -1, 0); |
| 5469 | break; |
| 5470 | case WL_OUTPUT_TRANSFORM_270: |
| 5471 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 5472 | weston_matrix_translate(&output->matrix, -output->width, 0, 0); |
| 5473 | weston_matrix_rotate_xy(&output->matrix, 0, -1); |
| 5474 | break; |
| 5475 | } |
| 5476 | |
| 5477 | if (output->current_scale != 1) |
| 5478 | weston_matrix_scale(&output->matrix, |
| 5479 | output->current_scale, |
| 5480 | output->current_scale, 1); |
Neil Roberts | 6c3b01f | 2014-05-06 19:04:15 +0100 | [diff] [blame] | 5481 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5482 | output->dirty = 0; |
Derek Foreman | c002321 | 2015-03-24 11:36:13 -0500 | [diff] [blame] | 5483 | |
| 5484 | weston_matrix_invert(&output->inverse_matrix, &output->matrix); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5485 | } |
| 5486 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 5487 | static void |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 5488 | 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] | 5489 | { |
| 5490 | output->transform = transform; |
Pekka Paalanen | 59987fa | 2016-04-26 15:50:59 +0300 | [diff] [blame] | 5491 | output->native_scale = scale; |
| 5492 | output->current_scale = scale; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 5493 | |
Pekka Paalanen | 59987fa | 2016-04-26 15:50:59 +0300 | [diff] [blame] | 5494 | convert_size_by_transform_scale(&output->width, &output->height, |
| 5495 | output->current_mode->width, |
| 5496 | output->current_mode->height, |
| 5497 | transform, scale); |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 5498 | } |
| 5499 | |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5500 | static void |
| 5501 | weston_output_init_geometry(struct weston_output *output, int x, int y) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5502 | { |
| 5503 | output->x = x; |
| 5504 | output->y = y; |
| 5505 | |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 5506 | pixman_region32_fini(&output->previous_damage); |
Ander Conselvan de Oliveira | b8fcca9 | 2012-11-16 17:23:52 +0200 | [diff] [blame] | 5507 | pixman_region32_init(&output->previous_damage); |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 5508 | |
| 5509 | pixman_region32_fini(&output->region); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5510 | pixman_region32_init_rect(&output->region, x, y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 5511 | output->width, |
| 5512 | output->height); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 5513 | } |
| 5514 | |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame^] | 5515 | /** |
| 5516 | * \ingroup output |
| 5517 | */ |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5518 | WL_EXPORT void |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5519 | weston_output_move(struct weston_output *output, int x, int y) |
| 5520 | { |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5521 | struct weston_head *head; |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5522 | struct wl_resource *resource; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5523 | int ver; |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5524 | |
| 5525 | output->move_x = x - output->x; |
| 5526 | output->move_y = y - output->y; |
| 5527 | |
| 5528 | if (output->move_x == 0 && output->move_y == 0) |
| 5529 | return; |
| 5530 | |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5531 | weston_output_init_geometry(output, x, y); |
| 5532 | |
| 5533 | output->dirty = 1; |
| 5534 | |
| 5535 | /* Move views on this output. */ |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 5536 | wl_signal_emit(&output->compositor->output_moved_signal, output); |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5537 | |
| 5538 | /* Notify clients of the change for output position. */ |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5539 | wl_list_for_each(head, &output->head_list, output_link) { |
| 5540 | wl_resource_for_each(resource, &head->resource_list) { |
| 5541 | wl_output_send_geometry(resource, |
| 5542 | output->x, |
| 5543 | output->y, |
| 5544 | head->mm_width, |
| 5545 | head->mm_height, |
| 5546 | head->subpixel, |
| 5547 | head->make, |
| 5548 | head->model, |
| 5549 | output->transform); |
Quanxian Wang | b2c8636 | 2014-03-14 09:16:25 +0800 | [diff] [blame] | 5550 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5551 | ver = wl_resource_get_version(resource); |
| 5552 | if (ver >= WL_OUTPUT_DONE_SINCE_VERSION) |
| 5553 | wl_output_send_done(resource); |
| 5554 | } |
Quanxian Wang | b2c8636 | 2014-03-14 09:16:25 +0800 | [diff] [blame] | 5555 | } |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5556 | } |
| 5557 | |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5558 | /** Signal that a pending output is taken into use. |
| 5559 | * |
| 5560 | * Removes the output from the pending list and adds it to the compositor's |
| 5561 | * list of enabled outputs. The output created signal is emitted. |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5562 | * |
Pekka Paalanen | 2210ad0 | 2017-03-30 15:48:06 +0300 | [diff] [blame] | 5563 | * The output gets an internal ID assigned, and the wl_output global is |
| 5564 | * created. |
Pekka Paalanen | 3d2d497 | 2017-03-30 15:19:45 +0300 | [diff] [blame] | 5565 | * |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5566 | * \param compositor The compositor instance. |
| 5567 | * \param output The output to be added. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5568 | * |
| 5569 | * \internal |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5570 | */ |
Pekka Paalanen | f9681b5 | 2017-03-29 16:58:48 +0300 | [diff] [blame] | 5571 | static void |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5572 | weston_compositor_add_output(struct weston_compositor *compositor, |
| 5573 | struct weston_output *output) |
| 5574 | { |
Armin Krezović | e540384 | 2016-08-05 15:28:29 +0200 | [diff] [blame] | 5575 | struct weston_view *view, *next; |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 5576 | struct weston_head *head; |
Armin Krezović | e540384 | 2016-08-05 15:28:29 +0200 | [diff] [blame] | 5577 | |
Pekka Paalanen | 7f340ff | 2017-03-30 14:56:22 +0300 | [diff] [blame] | 5578 | assert(!output->enabled); |
Pekka Paalanen | 3d2d497 | 2017-03-30 15:19:45 +0300 | [diff] [blame] | 5579 | |
| 5580 | /* Verify we haven't reached the limit of 32 available output IDs */ |
| 5581 | assert(ffs(~compositor->output_id_pool) > 0); |
| 5582 | |
| 5583 | /* Invert the output id pool and look for the lowest numbered |
| 5584 | * switch (the least significant bit). Take that bit's position |
| 5585 | * as our ID, and mark it used in the compositor's output_id_pool. |
| 5586 | */ |
| 5587 | output->id = ffs(~compositor->output_id_pool) - 1; |
| 5588 | compositor->output_id_pool |= 1u << output->id; |
| 5589 | |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5590 | wl_list_remove(&output->link); |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5591 | wl_list_insert(compositor->output_list.prev, &output->link); |
Pekka Paalanen | 7f340ff | 2017-03-30 14:56:22 +0300 | [diff] [blame] | 5592 | output->enabled = true; |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5593 | |
Pekka Paalanen | dcac351 | 2017-12-08 14:13:34 +0200 | [diff] [blame] | 5594 | wl_list_for_each(head, &output->head_list, output_link) |
| 5595 | weston_head_add_global(head); |
Pekka Paalanen | 2210ad0 | 2017-03-30 15:48:06 +0300 | [diff] [blame] | 5596 | |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5597 | wl_signal_emit(&compositor->output_created_signal, output); |
Armin Krezović | e540384 | 2016-08-05 15:28:29 +0200 | [diff] [blame] | 5598 | |
| 5599 | wl_list_for_each_safe(view, next, &compositor->view_list, link) |
| 5600 | weston_view_geometry_dirty(view); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 5601 | } |
| 5602 | |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5603 | /** Transform device coordinates into global coordinates |
| 5604 | * |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 5605 | * \param output the weston_output object |
| 5606 | * \param[in] device_x X coordinate in device units. |
| 5607 | * \param[in] device_y Y coordinate in device units. |
| 5608 | * \param[out] x X coordinate in the global space. |
| 5609 | * \param[out] y Y coordinate in the global space. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5610 | * |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 5611 | * Transforms coordinates from the device coordinate space (physical pixel |
| 5612 | * units) to the global coordinate space (logical pixel units). This takes |
| 5613 | * into account output transform and scale. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5614 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame^] | 5615 | * \ingroup output |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5616 | * \internal |
| 5617 | */ |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 5618 | WL_EXPORT void |
| 5619 | weston_output_transform_coordinate(struct weston_output *output, |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 5620 | double device_x, double device_y, |
| 5621 | double *x, double *y) |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 5622 | { |
Derek Foreman | 0f67941 | 2014-10-02 13:41:17 -0500 | [diff] [blame] | 5623 | struct weston_vector p = { { |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 5624 | device_x, |
| 5625 | device_y, |
Derek Foreman | 0f67941 | 2014-10-02 13:41:17 -0500 | [diff] [blame] | 5626 | 0.0, |
| 5627 | 1.0 } }; |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 5628 | |
Derek Foreman | 67a18b9 | 2015-03-24 11:36:14 -0500 | [diff] [blame] | 5629 | weston_matrix_transform(&output->inverse_matrix, &p); |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 5630 | |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 5631 | *x = p.f[0] / p.f[3]; |
| 5632 | *y = p.f[1] / p.f[3]; |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 5633 | } |
| 5634 | |
Pekka Paalanen | e6ac4fc | 2017-03-29 16:07:34 +0300 | [diff] [blame] | 5635 | /** Removes output from compositor's list of enabled outputs |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5636 | * |
| 5637 | * \param output The weston_output object that is being removed. |
| 5638 | * |
Pekka Paalanen | e6ac4fc | 2017-03-29 16:07:34 +0300 | [diff] [blame] | 5639 | * The following happens: |
| 5640 | * |
| 5641 | * - The output assignments of all views in the current scenegraph are |
| 5642 | * recomputed. |
| 5643 | * |
| 5644 | * - Presentation feedback is discarded. |
| 5645 | * |
| 5646 | * - Compositor is notified that outputs were changed and |
| 5647 | * applies the necessary changes to re-layout outputs. |
| 5648 | * |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5649 | * - The output is put back in the pending outputs list. |
| 5650 | * |
Pekka Paalanen | e6ac4fc | 2017-03-29 16:07:34 +0300 | [diff] [blame] | 5651 | * - Signal is emitted to notify all users of the weston_output |
| 5652 | * object that the output is being destroyed. |
| 5653 | * |
| 5654 | * - wl_output protocol objects referencing this weston_output |
Pekka Paalanen | 2210ad0 | 2017-03-30 15:48:06 +0300 | [diff] [blame] | 5655 | * are made inert, and the wl_output global is removed. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5656 | * |
Pekka Paalanen | 3d2d497 | 2017-03-30 15:19:45 +0300 | [diff] [blame] | 5657 | * - The output's internal ID is released. |
| 5658 | * |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5659 | * \memberof weston_output |
| 5660 | * \internal |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5661 | */ |
| 5662 | static void |
| 5663 | weston_compositor_remove_output(struct weston_output *output) |
| 5664 | { |
Pekka Paalanen | bccda71 | 2017-03-29 16:16:04 +0300 | [diff] [blame] | 5665 | struct weston_compositor *compositor = output->compositor; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5666 | struct weston_view *view; |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 5667 | struct weston_head *head; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5668 | |
| 5669 | assert(output->destroying); |
Pekka Paalanen | 7f340ff | 2017-03-30 14:56:22 +0300 | [diff] [blame] | 5670 | assert(output->enabled); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5671 | |
Pekka Paalanen | bccda71 | 2017-03-29 16:16:04 +0300 | [diff] [blame] | 5672 | wl_list_for_each(view, &compositor->view_list, link) { |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5673 | if (view->output_mask & (1u << output->id)) |
| 5674 | weston_view_assign_output(view); |
| 5675 | } |
| 5676 | |
| 5677 | weston_presentation_feedback_discard_list(&output->feedback_list); |
| 5678 | |
Pekka Paalanen | 9711fd9 | 2018-06-21 14:26:18 +0300 | [diff] [blame] | 5679 | weston_compositor_reflow_outputs(compositor, output, -output->width); |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5680 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5681 | wl_list_remove(&output->link); |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5682 | wl_list_insert(compositor->pending_output_list.prev, &output->link); |
Pekka Paalanen | 7f340ff | 2017-03-30 14:56:22 +0300 | [diff] [blame] | 5683 | output->enabled = false; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5684 | |
Pekka Paalanen | bccda71 | 2017-03-29 16:16:04 +0300 | [diff] [blame] | 5685 | wl_signal_emit(&compositor->output_destroyed_signal, output); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5686 | wl_signal_emit(&output->destroy_signal, output); |
| 5687 | |
Pekka Paalanen | d9dcc6d | 2017-12-04 15:28:13 +0200 | [diff] [blame] | 5688 | wl_list_for_each(head, &output->head_list, output_link) |
| 5689 | weston_head_remove_global(head); |
Pekka Paalanen | 3d2d497 | 2017-03-30 15:19:45 +0300 | [diff] [blame] | 5690 | |
| 5691 | compositor->output_id_pool &= ~(1u << output->id); |
| 5692 | output->id = 0xffffffff; /* invalid */ |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5693 | } |
| 5694 | |
| 5695 | /** Sets the output scale for a given output. |
| 5696 | * |
| 5697 | * \param output The weston_output object that the scale is set for. |
| 5698 | * \param scale Scale factor for the given output. |
| 5699 | * |
| 5700 | * It only supports setting scale for an output that |
| 5701 | * is not enabled and it can only be ran once. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5702 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame^] | 5703 | * \ingroup ouput |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5704 | */ |
| 5705 | WL_EXPORT void |
| 5706 | weston_output_set_scale(struct weston_output *output, |
| 5707 | int32_t scale) |
| 5708 | { |
| 5709 | /* We can only set scale on a disabled output */ |
| 5710 | assert(!output->enabled); |
| 5711 | |
| 5712 | /* We only want to set scale once */ |
| 5713 | assert(!output->scale); |
| 5714 | |
| 5715 | output->scale = scale; |
| 5716 | } |
| 5717 | |
| 5718 | /** Sets the output transform for a given output. |
| 5719 | * |
| 5720 | * \param output The weston_output object that the transform is set for. |
| 5721 | * \param transform Transform value for the given output. |
| 5722 | * |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5723 | * Refer to wl_output::transform section located at |
| 5724 | * https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_output |
| 5725 | * for list of values that can be passed to this function. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5726 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame^] | 5727 | * \ingroup output |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5728 | */ |
| 5729 | WL_EXPORT void |
| 5730 | weston_output_set_transform(struct weston_output *output, |
| 5731 | uint32_t transform) |
| 5732 | { |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 5733 | struct weston_pointer_motion_event ev; |
| 5734 | struct wl_resource *resource; |
| 5735 | struct weston_seat *seat; |
| 5736 | pixman_region32_t old_region; |
| 5737 | int mid_x, mid_y; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5738 | struct weston_head *head; |
| 5739 | int ver; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5740 | |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 5741 | if (!output->enabled && output->transform == UINT32_MAX) { |
| 5742 | output->transform = transform; |
| 5743 | return; |
| 5744 | } |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5745 | |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 5746 | weston_output_transform_scale_init(output, transform, output->scale); |
| 5747 | |
| 5748 | pixman_region32_init(&old_region); |
| 5749 | pixman_region32_copy(&old_region, &output->region); |
| 5750 | |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 5751 | weston_output_init_geometry(output, output->x, output->y); |
| 5752 | |
| 5753 | output->dirty = 1; |
| 5754 | |
| 5755 | /* Notify clients of the change for output transform. */ |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5756 | wl_list_for_each(head, &output->head_list, output_link) { |
| 5757 | wl_resource_for_each(resource, &head->resource_list) { |
| 5758 | wl_output_send_geometry(resource, |
| 5759 | output->x, |
| 5760 | output->y, |
| 5761 | head->mm_width, |
| 5762 | head->mm_height, |
| 5763 | head->subpixel, |
| 5764 | head->make, |
| 5765 | head->model, |
| 5766 | output->transform); |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 5767 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5768 | ver = wl_resource_get_version(resource); |
| 5769 | if (ver >= WL_OUTPUT_DONE_SINCE_VERSION) |
| 5770 | wl_output_send_done(resource); |
| 5771 | } |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 5772 | } |
| 5773 | |
| 5774 | /* we must ensure that pointers are inside output, otherwise they disappear */ |
| 5775 | mid_x = output->x + output->width / 2; |
| 5776 | mid_y = output->y + output->height / 2; |
| 5777 | |
| 5778 | ev.mask = WESTON_POINTER_MOTION_ABS; |
| 5779 | ev.x = wl_fixed_to_double(wl_fixed_from_int(mid_x)); |
| 5780 | ev.y = wl_fixed_to_double(wl_fixed_from_int(mid_y)); |
| 5781 | |
| 5782 | wl_list_for_each(seat, &output->compositor->seat_list, link) { |
| 5783 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 5784 | |
| 5785 | if (pointer && pixman_region32_contains_point(&old_region, |
| 5786 | wl_fixed_to_int(pointer->x), |
| 5787 | wl_fixed_to_int(pointer->y), |
| 5788 | NULL)) |
| 5789 | weston_pointer_move(pointer, &ev); |
| 5790 | } |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5791 | } |
| 5792 | |
| 5793 | /** Initializes a weston_output object with enough data so |
| 5794 | ** an output can be configured. |
| 5795 | * |
| 5796 | * \param output The weston_output object to initialize |
| 5797 | * \param compositor The compositor instance. |
Pekka Paalanen | 26ac2e1 | 2017-04-03 13:18:13 +0300 | [diff] [blame] | 5798 | * \param name Name for the output (the string is copied). |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5799 | * |
| 5800 | * Sets initial values for fields that are expected to be |
| 5801 | * configured either by compositors or backends. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5802 | * |
Pekka Paalanen | 26ac2e1 | 2017-04-03 13:18:13 +0300 | [diff] [blame] | 5803 | * The name is used in logs, and can be used by compositors as a configuration |
| 5804 | * identifier. |
| 5805 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame^] | 5806 | * \ingroup output |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5807 | * \internal |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5808 | */ |
| 5809 | WL_EXPORT void |
Armin Krezović | 4008740 | 2016-09-30 14:11:12 +0200 | [diff] [blame] | 5810 | weston_output_init(struct weston_output *output, |
Pekka Paalanen | 26ac2e1 | 2017-04-03 13:18:13 +0300 | [diff] [blame] | 5811 | struct weston_compositor *compositor, |
| 5812 | const char *name) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5813 | { |
| 5814 | output->compositor = compositor; |
| 5815 | output->destroying = 0; |
Pekka Paalanen | 26ac2e1 | 2017-04-03 13:18:13 +0300 | [diff] [blame] | 5816 | output->name = strdup(name); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5817 | wl_list_init(&output->link); |
Pekka Paalanen | 37b7c6e | 2017-11-07 10:15:01 +0200 | [diff] [blame] | 5818 | wl_signal_init(&output->user_destroy_signal); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5819 | output->enabled = false; |
| 5820 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5821 | wl_list_init(&output->head_list); |
| 5822 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5823 | /* Add some (in)sane defaults which can be used |
| 5824 | * for checking if an output was properly configured |
| 5825 | */ |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5826 | output->scale = 0; |
| 5827 | /* Can't use -1 on uint32_t and 0 is valid enum value */ |
| 5828 | output->transform = UINT32_MAX; |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 5829 | |
| 5830 | pixman_region32_init(&output->previous_damage); |
| 5831 | pixman_region32_init(&output->region); |
Pekka Paalanen | 4270414 | 2017-09-06 16:47:52 +0300 | [diff] [blame] | 5832 | wl_list_init(&output->mode_list); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5833 | } |
| 5834 | |
| 5835 | /** Adds weston_output object to pending output list. |
| 5836 | * |
| 5837 | * \param output The weston_output object to add |
| 5838 | * \param compositor The compositor instance. |
| 5839 | * |
Pekka Paalanen | ae6d35d | 2017-08-16 12:07:14 +0300 | [diff] [blame] | 5840 | * The opposite of this operation is built into weston_output_release(). |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5841 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame^] | 5842 | * \ingroup output |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5843 | * \internal |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5844 | */ |
| 5845 | WL_EXPORT void |
| 5846 | weston_compositor_add_pending_output(struct weston_output *output, |
| 5847 | struct weston_compositor *compositor) |
| 5848 | { |
Pekka Paalanen | e952a01 | 2017-03-29 17:14:00 +0300 | [diff] [blame] | 5849 | assert(output->disable); |
| 5850 | assert(output->enable); |
| 5851 | |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5852 | wl_list_remove(&output->link); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5853 | wl_list_insert(compositor->pending_output_list.prev, &output->link); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5854 | } |
| 5855 | |
Pekka Paalanen | 3e8f201 | 2017-11-02 14:03:11 +0200 | [diff] [blame] | 5856 | /** Create a string with the attached heads' names. |
| 5857 | * |
| 5858 | * The string must be free()'d. |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame^] | 5859 | * |
| 5860 | * \ingroup output |
Pekka Paalanen | 3e8f201 | 2017-11-02 14:03:11 +0200 | [diff] [blame] | 5861 | */ |
| 5862 | static char * |
| 5863 | weston_output_create_heads_string(struct weston_output *output) |
| 5864 | { |
| 5865 | FILE *fp; |
| 5866 | char *str = NULL; |
| 5867 | size_t size = 0; |
| 5868 | struct weston_head *head; |
| 5869 | const char *sep = ""; |
| 5870 | |
| 5871 | fp = open_memstream(&str, &size); |
| 5872 | if (!fp) |
| 5873 | return NULL; |
| 5874 | |
| 5875 | wl_list_for_each(head, &output->head_list, output_link) { |
| 5876 | fprintf(fp, "%s%s", sep, head->name); |
| 5877 | sep = ", "; |
| 5878 | } |
| 5879 | fclose(fp); |
| 5880 | |
| 5881 | return str; |
| 5882 | } |
| 5883 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5884 | /** Constructs a weston_output object that can be used by the compositor. |
| 5885 | * |
Pekka Paalanen | cc201e4 | 2017-03-30 15:11:25 +0300 | [diff] [blame] | 5886 | * \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] | 5887 | * be enabled already. Must have at least one head attached. |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5888 | * |
| 5889 | * Output coordinates are calculated and each new output is by default |
| 5890 | * assigned to the right of previous one. |
| 5891 | * |
| 5892 | * Sets up the transformation, zoom, and geometry of the output using |
| 5893 | * the properties that need to be configured by the compositor. |
| 5894 | * |
| 5895 | * Establishes a repaint timer for the output with the relevant display |
| 5896 | * object's event loop. See output_repaint_timer_handler(). |
| 5897 | * |
| 5898 | * The output is assigned an ID. Weston can support up to 32 distinct |
| 5899 | * outputs, with IDs numbered from 0-31; the compositor's output_id_pool |
| 5900 | * is referred to and used to find the first available ID number, and |
| 5901 | * then this ID is marked as used in output_id_pool. |
| 5902 | * |
| 5903 | * The output is also assigned a Wayland global with the wl_output |
| 5904 | * external interface. |
| 5905 | * |
| 5906 | * Backend specific function is called to set up the output output. |
| 5907 | * |
| 5908 | * Output is added to the compositor's output list |
| 5909 | * |
| 5910 | * If the backend specific function fails, the weston_output object |
| 5911 | * is returned to a state it was before calling this function and |
| 5912 | * is added to the compositor's pending_output_list in case it needs |
| 5913 | * to be reconfigured or just so it can be destroyed at shutdown. |
| 5914 | * |
| 5915 | * 0 is returned on success, -1 on failure. |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame^] | 5916 | * |
| 5917 | * \ingroup output |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5918 | */ |
| 5919 | WL_EXPORT int |
| 5920 | weston_output_enable(struct weston_output *output) |
| 5921 | { |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 5922 | struct weston_compositor *c = output->compositor; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5923 | struct weston_output *iterator; |
Pekka Paalanen | ec25b0a | 2017-08-24 16:08:49 +0300 | [diff] [blame] | 5924 | struct weston_head *head; |
Pekka Paalanen | 3e8f201 | 2017-11-02 14:03:11 +0200 | [diff] [blame] | 5925 | char *head_names; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5926 | int x = 0, y = 0; |
| 5927 | |
Pekka Paalanen | cc201e4 | 2017-03-30 15:11:25 +0300 | [diff] [blame] | 5928 | if (output->enabled) { |
| 5929 | weston_log("Error: attempt to enable an enabled output '%s'\n", |
| 5930 | output->name); |
| 5931 | return -1; |
| 5932 | } |
| 5933 | |
Pekka Paalanen | ddce54d | 2017-08-23 16:00:21 +0300 | [diff] [blame] | 5934 | if (wl_list_empty(&output->head_list)) { |
| 5935 | weston_log("Error: cannot enable output '%s' without heads.\n", |
| 5936 | output->name); |
| 5937 | return -1; |
| 5938 | } |
| 5939 | |
Pekka Paalanen | 586e1ac | 2017-09-14 16:17:59 +0300 | [diff] [blame] | 5940 | if (wl_list_empty(&output->mode_list) || !output->current_mode) { |
| 5941 | weston_log("Error: no video mode for output '%s'.\n", |
| 5942 | output->name); |
| 5943 | return -1; |
| 5944 | } |
| 5945 | |
Pekka Paalanen | ec25b0a | 2017-08-24 16:08:49 +0300 | [diff] [blame] | 5946 | wl_list_for_each(head, &output->head_list, output_link) { |
| 5947 | assert(head->make); |
| 5948 | assert(head->model); |
| 5949 | } |
| 5950 | |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 5951 | iterator = container_of(c->output_list.prev, |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5952 | struct weston_output, link); |
| 5953 | |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 5954 | if (!wl_list_empty(&c->output_list)) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5955 | x = iterator->x + iterator->width; |
| 5956 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5957 | /* Make sure the scale is set up */ |
| 5958 | assert(output->scale); |
| 5959 | |
| 5960 | /* Make sure we have a transform set */ |
| 5961 | assert(output->transform != UINT32_MAX); |
| 5962 | |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 5963 | output->x = x; |
| 5964 | output->y = y; |
| 5965 | output->dirty = 1; |
| 5966 | output->original_scale = output->scale; |
| 5967 | |
| 5968 | weston_output_transform_scale_init(output, output->transform, output->scale); |
| 5969 | weston_output_init_zoom(output); |
| 5970 | |
| 5971 | weston_output_init_geometry(output, x, y); |
| 5972 | weston_output_damage(output); |
| 5973 | |
| 5974 | wl_signal_init(&output->frame_signal); |
| 5975 | wl_signal_init(&output->destroy_signal); |
| 5976 | wl_list_init(&output->animation_list); |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 5977 | wl_list_init(&output->feedback_list); |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 5978 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5979 | /* Enable the output (set up the crtc or create a |
| 5980 | * window representing the output, set up the |
| 5981 | * renderer, etc) |
| 5982 | */ |
| 5983 | if (output->enable(output) < 0) { |
| 5984 | weston_log("Enabling output \"%s\" failed.\n", output->name); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5985 | return -1; |
| 5986 | } |
| 5987 | |
| 5988 | weston_compositor_add_output(output->compositor, output); |
| 5989 | |
Pekka Paalanen | 3e8f201 | 2017-11-02 14:03:11 +0200 | [diff] [blame] | 5990 | head_names = weston_output_create_heads_string(output); |
| 5991 | weston_log("Output '%s' enabled with head(s) %s\n", |
| 5992 | output->name, head_names); |
| 5993 | free(head_names); |
| 5994 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5995 | return 0; |
| 5996 | } |
| 5997 | |
| 5998 | /** Converts a weston_output object to a pending output state, so it |
| 5999 | ** can be configured again or destroyed. |
| 6000 | * |
| 6001 | * \param output The weston_output object that needs to be disabled. |
| 6002 | * |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6003 | * Calls a backend specific function to disable an output, in case |
| 6004 | * such function exists. |
| 6005 | * |
Pekka Paalanen | c65df64 | 2017-03-29 15:45:46 +0300 | [diff] [blame] | 6006 | * The backend specific disable function may choose to postpone the disabling |
| 6007 | * by returning a negative value, in which case this function returns early. |
| 6008 | * In that case the backend will guarantee the output will be disabled soon |
| 6009 | * by the backend calling this function again. One must not attempt to re-enable |
| 6010 | * the output until that happens. |
| 6011 | * |
| 6012 | * 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] | 6013 | * from weston's output_list (see weston_compositor_remove_output()) |
| 6014 | * and is returned to a state it was before weston_output_enable() |
| 6015 | * was ran (see weston_output_enable_undo()). |
| 6016 | * |
Pekka Paalanen | c65df64 | 2017-03-29 15:45:46 +0300 | [diff] [blame] | 6017 | * See weston_output_init() for more information on the |
| 6018 | * state output is returned to. |
Pekka Paalanen | cc201e4 | 2017-03-30 15:11:25 +0300 | [diff] [blame] | 6019 | * |
| 6020 | * If the output has never been enabled yet, this function can still be |
| 6021 | * called to ensure that the output is actually turned off rather than left |
| 6022 | * in the state it was discovered in. |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame^] | 6023 | * |
| 6024 | * \ingroup output |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6025 | */ |
| 6026 | WL_EXPORT void |
| 6027 | weston_output_disable(struct weston_output *output) |
| 6028 | { |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6029 | /* Should we rename this? */ |
| 6030 | output->destroying = 1; |
| 6031 | |
Pekka Paalanen | c65df64 | 2017-03-29 15:45:46 +0300 | [diff] [blame] | 6032 | /* Disable is called unconditionally also for not-enabled outputs, |
| 6033 | * because at compositor start-up, if there is an output that is |
| 6034 | * already on but the compositor wants to turn it off, we have to |
| 6035 | * forward the turn-off to the backend so it knows to do it. |
| 6036 | * The backend cannot initially turn off everything, because it |
| 6037 | * would cause unnecessary mode-sets for all outputs the compositor |
| 6038 | * wants to be on. |
| 6039 | */ |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6040 | if (output->disable(output) < 0) |
| 6041 | return; |
| 6042 | |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 6043 | if (output->enabled) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6044 | weston_compositor_remove_output(output); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6045 | |
| 6046 | output->destroying = 0; |
| 6047 | } |
| 6048 | |
Pekka Paalanen | 8a8dcac | 2017-08-17 17:29:36 +0300 | [diff] [blame] | 6049 | /** Forces a synchronous call to heads_changed hook |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6050 | * |
| 6051 | * \param compositor The compositor instance |
Pekka Paalanen | 8a8dcac | 2017-08-17 17:29:36 +0300 | [diff] [blame] | 6052 | * |
| 6053 | * If there are new or changed heads, calls the heads_changed hook and |
| 6054 | * returns after the hook returns. |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6055 | */ |
| 6056 | WL_EXPORT void |
Pekka Paalanen | 8a8dcac | 2017-08-17 17:29:36 +0300 | [diff] [blame] | 6057 | weston_compositor_flush_heads_changed(struct weston_compositor *compositor) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6058 | { |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 6059 | if (compositor->heads_changed_source) { |
| 6060 | wl_event_source_remove(compositor->heads_changed_source); |
| 6061 | weston_compositor_call_heads_changed(compositor); |
| 6062 | } |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6063 | } |
| 6064 | |
Pekka Paalanen | 37b7c6e | 2017-11-07 10:15:01 +0200 | [diff] [blame] | 6065 | /** Add destroy callback for an output |
| 6066 | * |
| 6067 | * \param output The output to watch. |
| 6068 | * \param listener The listener to add. The \c notify member must be set. |
| 6069 | * |
| 6070 | * The listener callback will be called when user destroys an output. This |
| 6071 | * may be delayed by a backend in some cases. The main purpose of the |
| 6072 | * listener is to allow hooking up custom data to the output. The custom data |
| 6073 | * can be fetched via weston_output_get_destroy_listener() followed by |
| 6074 | * container_of(). |
| 6075 | * |
| 6076 | * The \c data argument to the notify callback is the weston_output being |
| 6077 | * destroyed. |
| 6078 | * |
| 6079 | * @note This is for the final destruction of an output, not when it gets |
| 6080 | * 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^] | 6081 | * |
| 6082 | * \ingroup ouput |
Pekka Paalanen | 37b7c6e | 2017-11-07 10:15:01 +0200 | [diff] [blame] | 6083 | */ |
| 6084 | WL_EXPORT void |
| 6085 | weston_output_add_destroy_listener(struct weston_output *output, |
| 6086 | struct wl_listener *listener) |
| 6087 | { |
| 6088 | wl_signal_add(&output->user_destroy_signal, listener); |
| 6089 | } |
| 6090 | |
| 6091 | /** Look up destroy listener for an output |
| 6092 | * |
| 6093 | * \param output The output to query. |
| 6094 | * \param notify The notify function used used for the added destroy listener. |
| 6095 | * \return The listener, or NULL if not found. |
| 6096 | * |
| 6097 | * This looks up the previously added destroy listener struct based on the |
| 6098 | * notify function it has. The listener can be used to access user data |
| 6099 | * through \c container_of(). |
| 6100 | * |
| 6101 | * \sa wl_signal_get() weston_output_add_destroy_listener() |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame^] | 6102 | * \ingroup output |
Pekka Paalanen | 37b7c6e | 2017-11-07 10:15:01 +0200 | [diff] [blame] | 6103 | */ |
| 6104 | WL_EXPORT struct wl_listener * |
| 6105 | weston_output_get_destroy_listener(struct weston_output *output, |
| 6106 | wl_notify_func_t notify) |
| 6107 | { |
| 6108 | return wl_signal_get(&output->user_destroy_signal, notify); |
| 6109 | } |
| 6110 | |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6111 | /** Uninitialize an output |
| 6112 | * |
| 6113 | * Removes the output from the list of enabled outputs if necessary, but |
| 6114 | * does not call the backend's output disable function. The output will no |
| 6115 | * longer be in the list of pending outputs either. |
| 6116 | * |
| 6117 | * All fields of weston_output become uninitialized, i.e. should not be used |
| 6118 | * anymore. The caller can free the memory after this. |
| 6119 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame^] | 6120 | * \ingroup ouput |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 6121 | * \internal |
| 6122 | */ |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6123 | WL_EXPORT void |
Pekka Paalanen | ae6d35d | 2017-08-16 12:07:14 +0300 | [diff] [blame] | 6124 | weston_output_release(struct weston_output *output) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6125 | { |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 6126 | struct weston_head *head, *tmp; |
| 6127 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6128 | output->destroying = 1; |
| 6129 | |
Pekka Paalanen | 37b7c6e | 2017-11-07 10:15:01 +0200 | [diff] [blame] | 6130 | wl_signal_emit(&output->user_destroy_signal, output); |
| 6131 | |
Pekka Paalanen | dcbcfc7 | 2017-10-26 14:33:59 +0300 | [diff] [blame] | 6132 | if (output->idle_repaint_source) |
| 6133 | wl_event_source_remove(output->idle_repaint_source); |
| 6134 | |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 6135 | if (output->enabled) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6136 | weston_compositor_remove_output(output); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6137 | |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 6138 | pixman_region32_fini(&output->region); |
| 6139 | pixman_region32_fini(&output->previous_damage); |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 6140 | wl_list_remove(&output->link); |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 6141 | |
| 6142 | wl_list_for_each_safe(head, tmp, &output->head_list, output_link) |
| 6143 | weston_head_detach(head); |
| 6144 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6145 | free(output->name); |
| 6146 | } |
| 6147 | |
Pekka Paalanen | 1ae9d08 | 2017-11-02 14:11:53 +0200 | [diff] [blame] | 6148 | /** Find an output by its given name |
| 6149 | * |
| 6150 | * \param compositor The compositor to search in. |
| 6151 | * \param name The output name to search for. |
| 6152 | * \return An existing output with the given name, or NULL if not found. |
| 6153 | * |
| 6154 | * \memberof weston_compositor |
| 6155 | */ |
| 6156 | WL_EXPORT struct weston_output * |
| 6157 | weston_compositor_find_output_by_name(struct weston_compositor *compositor, |
| 6158 | const char *name) |
| 6159 | { |
| 6160 | struct weston_output *output; |
| 6161 | |
| 6162 | wl_list_for_each(output, &compositor->output_list, link) |
| 6163 | if (strcmp(output->name, name) == 0) |
| 6164 | return output; |
| 6165 | |
| 6166 | wl_list_for_each(output, &compositor->pending_output_list, link) |
| 6167 | if (strcmp(output->name, name) == 0) |
| 6168 | return output; |
| 6169 | |
| 6170 | return NULL; |
| 6171 | } |
| 6172 | |
| 6173 | /** Create a named output |
| 6174 | * |
| 6175 | * \param compositor The compositor. |
| 6176 | * \param name The name for the output. |
| 6177 | * \return A new \c weston_output, or NULL on failure. |
| 6178 | * |
| 6179 | * This creates a new weston_output that starts with no heads attached. |
| 6180 | * |
| 6181 | * An output must be configured and it must have at least one head before |
| 6182 | * it can be enabled. |
| 6183 | * |
| 6184 | * \memberof weston_compositor |
| 6185 | */ |
| 6186 | WL_EXPORT struct weston_output * |
| 6187 | weston_compositor_create_output(struct weston_compositor *compositor, |
| 6188 | const char *name) |
| 6189 | { |
| 6190 | assert(compositor->backend->create_output); |
| 6191 | |
| 6192 | if (weston_compositor_find_output_by_name(compositor, name)) { |
| 6193 | weston_log("Warning: attempted to create an output with a " |
| 6194 | "duplicate name '%s'.\n", name); |
| 6195 | return NULL; |
| 6196 | } |
| 6197 | |
| 6198 | return compositor->backend->create_output(compositor, name); |
| 6199 | } |
| 6200 | |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 6201 | /** Create an output for an unused head |
| 6202 | * |
| 6203 | * \param compositor The compositor. |
| 6204 | * \param head The head to attach to the output. |
| 6205 | * \return A new \c weston_output, or NULL on failure. |
| 6206 | * |
| 6207 | * This creates a new weston_output that starts with the given head attached. |
| 6208 | * The output inherits the name of the head. The head must not be already |
| 6209 | * attached to another output. |
| 6210 | * |
| 6211 | * An output must be configured before it can be enabled. |
| 6212 | * |
| 6213 | * \memberof weston_compositor |
| 6214 | */ |
| 6215 | WL_EXPORT struct weston_output * |
| 6216 | weston_compositor_create_output_with_head(struct weston_compositor *compositor, |
| 6217 | struct weston_head *head) |
| 6218 | { |
| 6219 | struct weston_output *output; |
| 6220 | |
Pekka Paalanen | 1ae9d08 | 2017-11-02 14:11:53 +0200 | [diff] [blame] | 6221 | output = weston_compositor_create_output(compositor, head->name); |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 6222 | if (!output) |
| 6223 | return NULL; |
| 6224 | |
| 6225 | if (weston_output_attach_head(output, head) < 0) { |
Pekka Paalanen | 42c0e14 | 2017-10-27 12:07:49 +0300 | [diff] [blame] | 6226 | weston_output_destroy(output); |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 6227 | return NULL; |
| 6228 | } |
| 6229 | |
| 6230 | return output; |
| 6231 | } |
| 6232 | |
| 6233 | /** Destroy an output |
| 6234 | * |
| 6235 | * \param output The output to destroy. |
| 6236 | * |
| 6237 | * The heads attached to the given output are detached and become unused again. |
| 6238 | * |
| 6239 | * It is not necessary to explicitly destroy all outputs at compositor exit. |
| 6240 | * weston_compositor_destroy() will automatically destroy any remaining |
| 6241 | * outputs. |
| 6242 | * |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame^] | 6243 | * \ingroup ouput |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 6244 | */ |
| 6245 | WL_EXPORT void |
| 6246 | weston_output_destroy(struct weston_output *output) |
| 6247 | { |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame] | 6248 | output->destroy(output); |
| 6249 | } |
| 6250 | |
Pekka Paalanen | cf0a476 | 2017-04-04 16:36:07 +0300 | [diff] [blame] | 6251 | /** When you need a head... |
| 6252 | * |
| 6253 | * This function is a hack, used until all code has been converted to become |
| 6254 | * multi-head aware. |
| 6255 | * |
| 6256 | * \param output The weston_output whose head to get. |
| 6257 | * \return The first head in the output's list. |
Marius Vlad | 55d8736 | 2019-06-11 01:15:35 +0300 | [diff] [blame^] | 6258 | * |
| 6259 | * \ingroup ouput |
Pekka Paalanen | cf0a476 | 2017-04-04 16:36:07 +0300 | [diff] [blame] | 6260 | */ |
| 6261 | WL_EXPORT struct weston_head * |
| 6262 | weston_output_get_first_head(struct weston_output *output) |
| 6263 | { |
| 6264 | if (wl_list_empty(&output->head_list)) |
| 6265 | return NULL; |
| 6266 | |
| 6267 | return container_of(output->head_list.next, |
| 6268 | struct weston_head, output_link); |
| 6269 | } |
| 6270 | |
Benjamin Franzke | 315b3dc | 2011-03-08 11:32:57 +0100 | [diff] [blame] | 6271 | static void |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6272 | destroy_viewport(struct wl_resource *resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6273 | { |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 6274 | struct weston_surface *surface = |
| 6275 | wl_resource_get_user_data(resource); |
| 6276 | |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 6277 | if (!surface) |
| 6278 | return; |
| 6279 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6280 | surface->viewport_resource = NULL; |
Pekka Paalanen | f0cad48 | 2014-03-14 14:38:16 +0200 | [diff] [blame] | 6281 | surface->pending.buffer_viewport.buffer.src_width = |
| 6282 | wl_fixed_from_int(-1); |
| 6283 | surface->pending.buffer_viewport.surface.width = -1; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 6284 | surface->pending.buffer_viewport.changed = 1; |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6285 | } |
| 6286 | |
| 6287 | static void |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6288 | viewport_destroy(struct wl_client *client, |
| 6289 | struct wl_resource *resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6290 | { |
| 6291 | wl_resource_destroy(resource); |
| 6292 | } |
| 6293 | |
| 6294 | static void |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6295 | viewport_set_source(struct wl_client *client, |
| 6296 | struct wl_resource *resource, |
| 6297 | wl_fixed_t src_x, |
| 6298 | wl_fixed_t src_y, |
| 6299 | wl_fixed_t src_width, |
| 6300 | wl_fixed_t src_height) |
| 6301 | { |
| 6302 | struct weston_surface *surface = |
| 6303 | wl_resource_get_user_data(resource); |
| 6304 | |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 6305 | if (!surface) { |
| 6306 | wl_resource_post_error(resource, |
| 6307 | WP_VIEWPORT_ERROR_NO_SURFACE, |
| 6308 | "wl_surface for this viewport is no longer exists"); |
| 6309 | return; |
| 6310 | } |
| 6311 | |
| 6312 | assert(surface->viewport_resource == resource); |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 6313 | assert(surface->resource); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6314 | |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6315 | if (src_width == wl_fixed_from_int(-1) && |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 6316 | src_height == wl_fixed_from_int(-1) && |
| 6317 | src_x == wl_fixed_from_int(-1) && |
| 6318 | src_y == wl_fixed_from_int(-1)) { |
| 6319 | /* unset source rect */ |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6320 | surface->pending.buffer_viewport.buffer.src_width = |
| 6321 | wl_fixed_from_int(-1); |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 6322 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6323 | return; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6324 | } |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6325 | |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 6326 | 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] | 6327 | wl_resource_post_error(resource, |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 6328 | WP_VIEWPORT_ERROR_BAD_VALUE, |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 6329 | "wl_surface@%d viewport source " |
| 6330 | "w=%f <= 0, h=%f <= 0, x=%f < 0, or y=%f < 0", |
| 6331 | wl_resource_get_id(surface->resource), |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6332 | wl_fixed_to_double(src_width), |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 6333 | wl_fixed_to_double(src_height), |
| 6334 | wl_fixed_to_double(src_x), |
| 6335 | wl_fixed_to_double(src_y)); |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6336 | return; |
| 6337 | } |
| 6338 | |
| 6339 | surface->pending.buffer_viewport.buffer.src_x = src_x; |
| 6340 | surface->pending.buffer_viewport.buffer.src_y = src_y; |
| 6341 | surface->pending.buffer_viewport.buffer.src_width = src_width; |
| 6342 | surface->pending.buffer_viewport.buffer.src_height = src_height; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 6343 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6344 | } |
| 6345 | |
| 6346 | static void |
| 6347 | viewport_set_destination(struct wl_client *client, |
| 6348 | struct wl_resource *resource, |
| 6349 | int32_t dst_width, |
| 6350 | int32_t dst_height) |
| 6351 | { |
| 6352 | struct weston_surface *surface = |
| 6353 | wl_resource_get_user_data(resource); |
| 6354 | |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 6355 | if (!surface) { |
| 6356 | wl_resource_post_error(resource, |
| 6357 | WP_VIEWPORT_ERROR_NO_SURFACE, |
| 6358 | "wl_surface for this viewport no longer exists"); |
| 6359 | return; |
| 6360 | } |
| 6361 | |
| 6362 | assert(surface->viewport_resource == resource); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6363 | |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6364 | if (dst_width == -1 && dst_height == -1) { |
| 6365 | /* unset destination size */ |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6366 | surface->pending.buffer_viewport.surface.width = -1; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 6367 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6368 | return; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6369 | } |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6370 | |
| 6371 | if (dst_width <= 0 || dst_height <= 0) { |
| 6372 | wl_resource_post_error(resource, |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 6373 | WP_VIEWPORT_ERROR_BAD_VALUE, |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 6374 | "destination size must be positive (%dx%d)", |
| 6375 | dst_width, dst_height); |
| 6376 | return; |
| 6377 | } |
| 6378 | |
| 6379 | surface->pending.buffer_viewport.surface.width = dst_width; |
| 6380 | surface->pending.buffer_viewport.surface.height = dst_height; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 6381 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6382 | } |
| 6383 | |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 6384 | static const struct wp_viewport_interface viewport_interface = { |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6385 | viewport_destroy, |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6386 | viewport_set_source, |
| 6387 | viewport_set_destination |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6388 | }; |
| 6389 | |
| 6390 | static void |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6391 | viewporter_destroy(struct wl_client *client, |
| 6392 | struct wl_resource *resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6393 | { |
| 6394 | wl_resource_destroy(resource); |
| 6395 | } |
| 6396 | |
| 6397 | static void |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6398 | viewporter_get_viewport(struct wl_client *client, |
| 6399 | struct wl_resource *viewporter, |
| 6400 | uint32_t id, |
| 6401 | struct wl_resource *surface_resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6402 | { |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6403 | int version = wl_resource_get_version(viewporter); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6404 | struct weston_surface *surface = |
| 6405 | wl_resource_get_user_data(surface_resource); |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6406 | struct wl_resource *resource; |
| 6407 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6408 | if (surface->viewport_resource) { |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6409 | wl_resource_post_error(viewporter, |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 6410 | WP_VIEWPORTER_ERROR_VIEWPORT_EXISTS, |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6411 | "a viewport for that surface already exists"); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 6412 | return; |
| 6413 | } |
| 6414 | |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 6415 | resource = wl_resource_create(client, &wp_viewport_interface, |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 6416 | version, id); |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6417 | if (resource == NULL) { |
| 6418 | wl_client_post_no_memory(client); |
| 6419 | return; |
| 6420 | } |
| 6421 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6422 | wl_resource_set_implementation(resource, &viewport_interface, |
| 6423 | surface, destroy_viewport); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 6424 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 6425 | surface->viewport_resource = resource; |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6426 | } |
| 6427 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6428 | static const struct wp_viewporter_interface viewporter_interface = { |
| 6429 | viewporter_destroy, |
| 6430 | viewporter_get_viewport |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6431 | }; |
| 6432 | |
| 6433 | static void |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6434 | bind_viewporter(struct wl_client *client, |
| 6435 | void *data, uint32_t version, uint32_t id) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6436 | { |
| 6437 | struct wl_resource *resource; |
| 6438 | |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 6439 | resource = wl_resource_create(client, &wp_viewporter_interface, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 6440 | version, id); |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6441 | if (resource == NULL) { |
| 6442 | wl_client_post_no_memory(client); |
| 6443 | return; |
| 6444 | } |
| 6445 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6446 | wl_resource_set_implementation(resource, &viewporter_interface, |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6447 | NULL, NULL); |
| 6448 | } |
| 6449 | |
| 6450 | static void |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 6451 | destroy_presentation_feedback(struct wl_resource *feedback_resource) |
| 6452 | { |
| 6453 | struct weston_presentation_feedback *feedback; |
| 6454 | |
| 6455 | feedback = wl_resource_get_user_data(feedback_resource); |
| 6456 | |
| 6457 | wl_list_remove(&feedback->link); |
| 6458 | free(feedback); |
| 6459 | } |
| 6460 | |
| 6461 | static void |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 6462 | presentation_destroy(struct wl_client *client, struct wl_resource *resource) |
| 6463 | { |
| 6464 | wl_resource_destroy(resource); |
| 6465 | } |
| 6466 | |
| 6467 | static void |
| 6468 | presentation_feedback(struct wl_client *client, |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 6469 | struct wl_resource *presentation_resource, |
| 6470 | struct wl_resource *surface_resource, |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 6471 | uint32_t callback) |
| 6472 | { |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 6473 | struct weston_surface *surface; |
| 6474 | struct weston_presentation_feedback *feedback; |
| 6475 | |
| 6476 | surface = wl_resource_get_user_data(surface_resource); |
| 6477 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 6478 | feedback = zalloc(sizeof *feedback); |
| 6479 | if (feedback == NULL) |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 6480 | goto err_calloc; |
| 6481 | |
| 6482 | feedback->resource = wl_resource_create(client, |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 6483 | &wp_presentation_feedback_interface, |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 6484 | 1, callback); |
| 6485 | if (!feedback->resource) |
| 6486 | goto err_create; |
| 6487 | |
| 6488 | wl_resource_set_implementation(feedback->resource, NULL, feedback, |
| 6489 | destroy_presentation_feedback); |
| 6490 | |
| 6491 | wl_list_insert(&surface->pending.feedback_list, &feedback->link); |
| 6492 | |
| 6493 | return; |
| 6494 | |
| 6495 | err_create: |
| 6496 | free(feedback); |
| 6497 | |
| 6498 | err_calloc: |
| 6499 | wl_client_post_no_memory(client); |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 6500 | } |
| 6501 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 6502 | static const struct wp_presentation_interface presentation_implementation = { |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 6503 | presentation_destroy, |
| 6504 | presentation_feedback |
| 6505 | }; |
| 6506 | |
| 6507 | static void |
| 6508 | bind_presentation(struct wl_client *client, |
| 6509 | void *data, uint32_t version, uint32_t id) |
| 6510 | { |
| 6511 | struct weston_compositor *compositor = data; |
| 6512 | struct wl_resource *resource; |
| 6513 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 6514 | resource = wl_resource_create(client, &wp_presentation_interface, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 6515 | version, id); |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 6516 | if (resource == NULL) { |
| 6517 | wl_client_post_no_memory(client); |
| 6518 | return; |
| 6519 | } |
| 6520 | |
| 6521 | wl_resource_set_implementation(resource, &presentation_implementation, |
| 6522 | compositor, NULL); |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 6523 | wp_presentation_send_clock_id(resource, compositor->presentation_clock); |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 6524 | } |
| 6525 | |
| 6526 | static void |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 6527 | compositor_bind(struct wl_client *client, |
| 6528 | void *data, uint32_t version, uint32_t id) |
| 6529 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 6530 | struct weston_compositor *compositor = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 6531 | struct wl_resource *resource; |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 6532 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 6533 | resource = wl_resource_create(client, &wl_compositor_interface, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 6534 | version, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 6535 | if (resource == NULL) { |
| 6536 | wl_client_post_no_memory(client); |
| 6537 | return; |
| 6538 | } |
| 6539 | |
| 6540 | wl_resource_set_implementation(resource, &compositor_interface, |
| 6541 | compositor, NULL); |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 6542 | } |
| 6543 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6544 | WL_EXPORT int |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 6545 | weston_environment_get_fd(const char *env) |
| 6546 | { |
Bryce Harrington | 25a2bdd | 2016-08-03 17:40:52 -0700 | [diff] [blame] | 6547 | char *e; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 6548 | int fd, flags; |
| 6549 | |
| 6550 | e = getenv(env); |
Bryce Harrington | 25a2bdd | 2016-08-03 17:40:52 -0700 | [diff] [blame] | 6551 | if (!e || !safe_strtoint(e, &fd)) |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 6552 | return -1; |
| 6553 | |
| 6554 | flags = fcntl(fd, F_GETFD); |
| 6555 | if (flags == -1) |
| 6556 | return -1; |
| 6557 | |
| 6558 | fcntl(fd, F_SETFD, flags | FD_CLOEXEC); |
| 6559 | unsetenv(env); |
| 6560 | |
| 6561 | return fd; |
| 6562 | } |
| 6563 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 6564 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 6565 | timeline_key_binding_handler(struct weston_keyboard *keyboard, |
| 6566 | const struct timespec *time, uint32_t key, |
| 6567 | void *data) |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 6568 | { |
| 6569 | struct weston_compositor *compositor = data; |
| 6570 | |
| 6571 | if (weston_timeline_enabled_) |
| 6572 | weston_timeline_close(); |
| 6573 | else |
| 6574 | weston_timeline_open(compositor); |
| 6575 | } |
| 6576 | |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6577 | static const char * |
| 6578 | output_repaint_status_text(struct weston_output *output) |
| 6579 | { |
| 6580 | switch (output->repaint_status) { |
| 6581 | case REPAINT_NOT_SCHEDULED: |
| 6582 | return "no repaint"; |
| 6583 | case REPAINT_BEGIN_FROM_IDLE: |
| 6584 | return "start_repaint_loop scheduled"; |
| 6585 | case REPAINT_SCHEDULED: |
| 6586 | return "repaint scheduled"; |
| 6587 | case REPAINT_AWAITING_COMPLETION: |
| 6588 | return "awaiting completion"; |
| 6589 | } |
| 6590 | |
| 6591 | assert(!"output_repaint_status_text missing enum"); |
| 6592 | return NULL; |
| 6593 | } |
| 6594 | |
| 6595 | static void |
| 6596 | debug_scene_view_print_buffer(FILE *fp, struct weston_view *view) |
| 6597 | { |
| 6598 | struct weston_buffer *buffer = view->surface->buffer_ref.buffer; |
| 6599 | struct wl_shm_buffer *shm; |
| 6600 | struct linux_dmabuf_buffer *dmabuf; |
Marius Vlad | 00a6e01 | 2018-11-20 17:52:31 +0200 | [diff] [blame] | 6601 | const struct pixel_format_info *pixel_info = NULL; |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6602 | |
| 6603 | if (!buffer) { |
| 6604 | fprintf(fp, "\t\t[buffer not available]\n"); |
| 6605 | return; |
| 6606 | } |
| 6607 | |
| 6608 | shm = wl_shm_buffer_get(buffer->resource); |
| 6609 | if (shm) { |
Marius Vlad | 00a6e01 | 2018-11-20 17:52:31 +0200 | [diff] [blame] | 6610 | uint32_t _format = wl_shm_buffer_get_format(shm); |
| 6611 | pixel_info = pixel_format_get_info_shm(_format); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6612 | fprintf(fp, "\t\tSHM buffer\n"); |
Marius Vlad | 00a6e01 | 2018-11-20 17:52:31 +0200 | [diff] [blame] | 6613 | fprintf(fp, "\t\t\tformat: 0x%lx %s\n", |
| 6614 | (unsigned long) _format, |
| 6615 | pixel_info ? pixel_info->drm_format_name : "UNKNOWN"); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6616 | return; |
| 6617 | } |
| 6618 | |
| 6619 | dmabuf = linux_dmabuf_buffer_get(buffer->resource); |
| 6620 | if (dmabuf) { |
Marius Vlad | 00a6e01 | 2018-11-20 17:52:31 +0200 | [diff] [blame] | 6621 | pixel_info = pixel_format_get_info(dmabuf->attributes.format); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6622 | fprintf(fp, "\t\tdmabuf buffer\n"); |
Marius Vlad | 00a6e01 | 2018-11-20 17:52:31 +0200 | [diff] [blame] | 6623 | fprintf(fp, "\t\t\tformat: 0x%lx %s\n", |
| 6624 | (unsigned long) dmabuf->attributes.format, |
| 6625 | pixel_info ? pixel_info->drm_format_name : "UNKNOWN"); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6626 | fprintf(fp, "\t\t\tmodifier: 0x%llx\n", |
| 6627 | (unsigned long long) dmabuf->attributes.modifier[0]); |
| 6628 | return; |
| 6629 | } |
| 6630 | |
Marius Vlad | 253ba9a | 2019-03-17 18:22:21 +0200 | [diff] [blame] | 6631 | fprintf(fp, "\t\tEGL buffer\n"); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6632 | } |
| 6633 | |
| 6634 | static void |
| 6635 | debug_scene_view_print(FILE *fp, struct weston_view *view, int view_idx) |
| 6636 | { |
| 6637 | struct weston_compositor *ec = view->surface->compositor; |
| 6638 | struct weston_output *output; |
| 6639 | char desc[512]; |
| 6640 | pixman_box32_t *box; |
| 6641 | uint32_t surface_id = 0; |
| 6642 | pid_t pid = 0; |
| 6643 | |
| 6644 | if (view->surface->resource) { |
| 6645 | struct wl_resource *resource = view->surface->resource; |
| 6646 | wl_client_get_credentials(wl_resource_get_client(resource), |
| 6647 | &pid, NULL, NULL); |
| 6648 | surface_id = wl_resource_get_id(view->surface->resource); |
| 6649 | } |
| 6650 | |
| 6651 | if (!view->surface->get_label || |
| 6652 | view->surface->get_label(view->surface, desc, sizeof(desc)) < 0) { |
| 6653 | strcpy(desc, "[no description available]"); |
| 6654 | } |
| 6655 | fprintf(fp, "\tView %d (role %s, PID %d, surface ID %u, %s, %p):\n", |
| 6656 | view_idx, view->surface->role_name, pid, surface_id, |
| 6657 | desc, view); |
| 6658 | |
| 6659 | box = pixman_region32_extents(&view->transform.boundingbox); |
| 6660 | fprintf(fp, "\t\tposition: (%d, %d) -> (%d, %d)\n", |
| 6661 | box->x1, box->y1, box->x2, box->y2); |
| 6662 | box = pixman_region32_extents(&view->transform.opaque); |
| 6663 | |
| 6664 | if (pixman_region32_equal(&view->transform.opaque, |
| 6665 | &view->transform.boundingbox)) { |
| 6666 | fprintf(fp, "\t\t[fully opaque]\n"); |
| 6667 | } else if (!pixman_region32_not_empty(&view->transform.opaque)) { |
| 6668 | fprintf(fp, "\t\t[not opaque]\n"); |
| 6669 | } else { |
| 6670 | fprintf(fp, "\t\t[opaque: (%d, %d) -> (%d, %d)]\n", |
| 6671 | box->x1, box->y1, box->x2, box->y2); |
| 6672 | } |
| 6673 | |
| 6674 | if (view->alpha < 1.0) |
| 6675 | fprintf(fp, "\t\talpha: %f\n", view->alpha); |
| 6676 | |
| 6677 | if (view->output_mask != 0) { |
| 6678 | bool first_output = true; |
| 6679 | fprintf(fp, "\t\toutputs: "); |
| 6680 | wl_list_for_each(output, &ec->output_list, link) { |
| 6681 | if (!(view->output_mask & (1 << output->id))) |
| 6682 | continue; |
| 6683 | fprintf(fp, "%s%d (%s)%s", |
| 6684 | (first_output) ? "" : ", ", |
| 6685 | output->id, output->name, |
| 6686 | (view->output == output) ? " (primary)" : ""); |
| 6687 | first_output = false; |
| 6688 | } |
| 6689 | } else { |
| 6690 | fprintf(fp, "\t\t[no outputs]"); |
| 6691 | } |
| 6692 | |
| 6693 | fprintf(fp, "\n"); |
| 6694 | |
| 6695 | debug_scene_view_print_buffer(fp, view); |
| 6696 | } |
| 6697 | |
Marius Vlad | 433f4e7 | 2019-02-17 22:14:23 +0200 | [diff] [blame] | 6698 | static void |
| 6699 | debug_scene_view_print_tree(struct weston_view *view, |
Marius Vlad | a6acfa8 | 2019-03-17 18:10:09 +0200 | [diff] [blame] | 6700 | FILE *fp, int *view_idx) |
Marius Vlad | 433f4e7 | 2019-02-17 22:14:23 +0200 | [diff] [blame] | 6701 | { |
| 6702 | struct weston_subsurface *sub; |
| 6703 | struct weston_view *ev; |
| 6704 | |
| 6705 | /* |
| 6706 | * print the view first, then we recursively go on printing |
| 6707 | * sub-surfaces. We bail out once no more sub-surfaces are available. |
| 6708 | */ |
Marius Vlad | a6acfa8 | 2019-03-17 18:10:09 +0200 | [diff] [blame] | 6709 | debug_scene_view_print(fp, view, *view_idx); |
Marius Vlad | 433f4e7 | 2019-02-17 22:14:23 +0200 | [diff] [blame] | 6710 | |
| 6711 | /* no more sub-surfaces */ |
| 6712 | if (wl_list_empty(&view->surface->subsurface_list)) |
| 6713 | return; |
| 6714 | |
| 6715 | wl_list_for_each(sub, &view->surface->subsurface_list, parent_link) { |
| 6716 | wl_list_for_each(ev, &sub->surface->views, surface_link) { |
| 6717 | /* do not print again the parent view */ |
| 6718 | if (view == ev) |
| 6719 | continue; |
Marius Vlad | a6acfa8 | 2019-03-17 18:10:09 +0200 | [diff] [blame] | 6720 | |
| 6721 | (*view_idx)++; |
Marius Vlad | 433f4e7 | 2019-02-17 22:14:23 +0200 | [diff] [blame] | 6722 | debug_scene_view_print_tree(ev, fp, view_idx); |
| 6723 | } |
| 6724 | } |
| 6725 | } |
| 6726 | |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6727 | /** |
| 6728 | * Output information on how libweston is currently composing the scene |
| 6729 | * graph. |
| 6730 | */ |
| 6731 | WL_EXPORT char * |
| 6732 | weston_compositor_print_scene_graph(struct weston_compositor *ec) |
| 6733 | { |
| 6734 | struct weston_output *output; |
| 6735 | struct weston_layer *layer; |
| 6736 | struct timespec now; |
| 6737 | int layer_idx = 0; |
| 6738 | FILE *fp; |
| 6739 | char *ret; |
| 6740 | size_t len; |
| 6741 | int err; |
| 6742 | |
| 6743 | fp = open_memstream(&ret, &len); |
| 6744 | assert(fp); |
| 6745 | |
| 6746 | weston_compositor_read_presentation_clock(ec, &now); |
| 6747 | fprintf(fp, "Weston scene graph at %ld.%09ld:\n\n", |
| 6748 | now.tv_sec, now.tv_nsec); |
| 6749 | |
| 6750 | wl_list_for_each(output, &ec->output_list, link) { |
| 6751 | struct weston_head *head; |
| 6752 | int head_idx = 0; |
| 6753 | |
| 6754 | fprintf(fp, "Output %d (%s):\n", output->id, output->name); |
| 6755 | assert(output->enabled); |
| 6756 | |
| 6757 | fprintf(fp, "\tposition: (%d, %d) -> (%d, %d)\n", |
| 6758 | output->x, output->y, |
| 6759 | output->x + output->width, |
| 6760 | output->y + output->height); |
| 6761 | fprintf(fp, "\tmode: %dx%d@%.3fHz\n", |
| 6762 | output->current_mode->width, |
| 6763 | output->current_mode->height, |
| 6764 | output->current_mode->refresh / 1000.0); |
| 6765 | fprintf(fp, "\tscale: %d\n", output->scale); |
| 6766 | |
| 6767 | fprintf(fp, "\trepaint status: %s\n", |
| 6768 | output_repaint_status_text(output)); |
| 6769 | if (output->repaint_status == REPAINT_SCHEDULED) |
| 6770 | fprintf(fp, "\tnext repaint: %ld.%09ld\n", |
| 6771 | output->next_repaint.tv_sec, |
| 6772 | output->next_repaint.tv_nsec); |
| 6773 | |
| 6774 | wl_list_for_each(head, &output->head_list, output_link) { |
| 6775 | fprintf(fp, "\tHead %d (%s): %sconnected\n", |
| 6776 | head_idx++, head->name, |
| 6777 | (head->connected) ? "" : "not "); |
| 6778 | } |
| 6779 | } |
| 6780 | |
| 6781 | fprintf(fp, "\n"); |
| 6782 | |
| 6783 | wl_list_for_each(layer, &ec->layer_list, link) { |
| 6784 | struct weston_view *view; |
| 6785 | int view_idx = 0; |
| 6786 | |
| 6787 | fprintf(fp, "Layer %d (pos 0x%lx):\n", layer_idx++, |
| 6788 | (unsigned long) layer->position); |
| 6789 | |
| 6790 | if (!weston_layer_mask_is_infinite(layer)) { |
| 6791 | fprintf(fp, "\t[mask: (%d, %d) -> (%d,%d)]\n\n", |
| 6792 | layer->mask.x1, layer->mask.y1, |
| 6793 | layer->mask.x2, layer->mask.y2); |
| 6794 | } |
| 6795 | |
Marius Vlad | a6acfa8 | 2019-03-17 18:10:09 +0200 | [diff] [blame] | 6796 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
| 6797 | debug_scene_view_print_tree(view, fp, &view_idx); |
| 6798 | view_idx++; |
| 6799 | } |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6800 | |
| 6801 | if (wl_list_empty(&layer->view_list.link)) |
| 6802 | fprintf(fp, "\t[no views]\n"); |
| 6803 | |
| 6804 | fprintf(fp, "\n"); |
| 6805 | } |
| 6806 | |
| 6807 | err = fclose(fp); |
| 6808 | assert(err == 0); |
| 6809 | |
| 6810 | return ret; |
| 6811 | } |
| 6812 | |
| 6813 | /** |
| 6814 | * Called when the 'scene-graph' debug scope is bound by a client. This |
| 6815 | * one-shot weston-debug scope prints the current scene graph when bound, |
| 6816 | * and then terminates the stream. |
| 6817 | */ |
| 6818 | static void |
| 6819 | debug_scene_graph_cb(struct weston_debug_stream *stream, void *data) |
| 6820 | { |
| 6821 | struct weston_compositor *ec = data; |
| 6822 | char *str = weston_compositor_print_scene_graph(ec); |
| 6823 | |
| 6824 | weston_debug_stream_printf(stream, "%s", str); |
| 6825 | free(str); |
| 6826 | weston_debug_stream_complete(stream); |
| 6827 | } |
| 6828 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 6829 | /** Create the compositor. |
| 6830 | * |
| 6831 | * This functions creates and initializes a compositor instance. |
| 6832 | * |
| 6833 | * \param display The Wayland display to be used. |
| 6834 | * \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] | 6835 | * \param log_ctx A pointer to weston_debug_compositor |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 6836 | * using the \ref weston_compositor_get_user_data function. |
| 6837 | * \return The compositor instance on success or NULL on failure. |
| 6838 | */ |
| 6839 | WL_EXPORT struct weston_compositor * |
Marius Vlad | 880b485 | 2019-04-07 17:07:58 +0300 | [diff] [blame] | 6840 | weston_compositor_create(struct wl_display *display, |
Marius Vlad | 3d7d978 | 2019-04-17 12:35:38 +0300 | [diff] [blame] | 6841 | struct weston_log_context *log_ctx, |
Marius Vlad | 880b485 | 2019-04-07 17:07:58 +0300 | [diff] [blame] | 6842 | void *user_data) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 6843 | { |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 6844 | struct weston_compositor *ec; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 6845 | struct wl_event_loop *loop; |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 6846 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 6847 | ec = zalloc(sizeof *ec); |
| 6848 | if (!ec) |
| 6849 | return NULL; |
| 6850 | |
| 6851 | ec->wl_display = display; |
| 6852 | ec->user_data = user_data; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6853 | wl_signal_init(&ec->destroy_signal); |
Kristian Høgsberg | f03a04a | 2014-04-06 22:04:50 -0700 | [diff] [blame] | 6854 | wl_signal_init(&ec->create_surface_signal); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 6855 | wl_signal_init(&ec->activate_signal); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 6856 | wl_signal_init(&ec->transform_signal); |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 6857 | wl_signal_init(&ec->kill_signal); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 6858 | wl_signal_init(&ec->idle_signal); |
| 6859 | wl_signal_init(&ec->wake_signal); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 6860 | wl_signal_init(&ec->show_input_panel_signal); |
| 6861 | wl_signal_init(&ec->hide_input_panel_signal); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 6862 | wl_signal_init(&ec->update_input_panel_signal); |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 6863 | wl_signal_init(&ec->seat_created_signal); |
Richard Hughes | 59d5da7 | 2013-05-01 21:52:11 +0100 | [diff] [blame] | 6864 | wl_signal_init(&ec->output_created_signal); |
Ander Conselvan de Oliveira | f84327a | 2014-01-29 18:47:51 +0200 | [diff] [blame] | 6865 | wl_signal_init(&ec->output_destroyed_signal); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 6866 | wl_signal_init(&ec->output_moved_signal); |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 6867 | wl_signal_init(&ec->output_resized_signal); |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 6868 | wl_signal_init(&ec->heads_changed_signal); |
Pekka Paalanen | 8dc6db8 | 2018-03-20 13:29:40 +0200 | [diff] [blame] | 6869 | wl_signal_init(&ec->output_heads_changed_signal); |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 6870 | wl_signal_init(&ec->session_signal); |
| 6871 | ec->session_active = 1; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 6872 | |
Casey Dahlin | 58ba137 | 2012-04-19 22:50:08 -0400 | [diff] [blame] | 6873 | ec->output_id_pool = 0; |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 6874 | ec->repaint_msec = DEFAULT_REPAINT_WINDOW; |
Casey Dahlin | 58ba137 | 2012-04-19 22:50:08 -0400 | [diff] [blame] | 6875 | |
Jonas Ådahl | 94e2e2d | 2014-10-18 18:42:19 +0200 | [diff] [blame] | 6876 | ec->activate_serial = 1; |
| 6877 | |
Louis-Francis Ratté-Boulianne | c4689ff | 2017-11-28 20:42:47 -0500 | [diff] [blame] | 6878 | ec->touch_mode = WESTON_TOUCH_MODE_NORMAL; |
| 6879 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 6880 | if (!wl_global_create(ec->wl_display, &wl_compositor_interface, 4, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6881 | ec, compositor_bind)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 6882 | goto fail; |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 6883 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 6884 | if (!wl_global_create(ec->wl_display, &wl_subcompositor_interface, 1, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6885 | ec, bind_subcompositor)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 6886 | goto fail; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 6887 | |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 6888 | if (!wl_global_create(ec->wl_display, &wp_viewporter_interface, 1, |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6889 | ec, bind_viewporter)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 6890 | goto fail; |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6891 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 6892 | if (!wl_global_create(ec->wl_display, &wp_presentation_interface, 1, |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 6893 | ec, bind_presentation)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 6894 | goto fail; |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 6895 | |
Marius Vlad | 3d7d978 | 2019-04-17 12:35:38 +0300 | [diff] [blame] | 6896 | if (weston_log_ctx_compositor_setup(ec, log_ctx) < 0) |
Pekka Paalanen | a5630ea | 2017-10-12 13:13:42 +0200 | [diff] [blame] | 6897 | goto fail; |
| 6898 | |
Jonas Ådahl | 30d61d8 | 2014-10-22 21:21:17 +0200 | [diff] [blame] | 6899 | if (weston_input_init(ec) != 0) |
| 6900 | goto fail; |
| 6901 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6902 | wl_list_init(&ec->view_list); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 6903 | wl_list_init(&ec->plane_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 6904 | wl_list_init(&ec->layer_list); |
| 6905 | wl_list_init(&ec->seat_list); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6906 | wl_list_init(&ec->pending_output_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 6907 | wl_list_init(&ec->output_list); |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 6908 | wl_list_init(&ec->head_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 6909 | wl_list_init(&ec->key_binding_list); |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 6910 | wl_list_init(&ec->modifier_binding_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 6911 | wl_list_init(&ec->button_binding_list); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 6912 | wl_list_init(&ec->touch_binding_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 6913 | wl_list_init(&ec->axis_binding_list); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6914 | wl_list_init(&ec->debug_binding_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 6915 | |
Pekka Paalanen | 827b5d2 | 2016-06-29 11:54:26 +0200 | [diff] [blame] | 6916 | wl_list_init(&ec->plugin_api_list); |
| 6917 | |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 6918 | weston_plane_init(&ec->primary_plane, ec, 0, 0); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 6919 | weston_compositor_stack_plane(ec, &ec->primary_plane, NULL); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 6920 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 6921 | wl_data_device_manager_init(ec->wl_display); |
| 6922 | |
| 6923 | wl_display_init_shm(ec->wl_display); |
| 6924 | |
| 6925 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6926 | ec->idle_source = wl_event_loop_add_timer(loop, idle_handler, ec); |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 6927 | ec->repaint_timer = |
| 6928 | wl_event_loop_add_timer(loop, output_repaint_timer_handler, |
| 6929 | ec); |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 6930 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 6931 | weston_layer_init(&ec->fade_layer, ec); |
| 6932 | weston_layer_init(&ec->cursor_layer, ec); |
| 6933 | |
| 6934 | weston_layer_set_position(&ec->fade_layer, WESTON_LAYER_POSITION_FADE); |
| 6935 | weston_layer_set_position(&ec->cursor_layer, |
| 6936 | WESTON_LAYER_POSITION_CURSOR); |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 6937 | |
| 6938 | weston_compositor_add_debug_binding(ec, KEY_T, |
| 6939 | timeline_key_binding_handler, ec); |
| 6940 | |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6941 | ec->debug_scene = |
Marius Vlad | 7e4db95 | 2019-04-17 13:47:06 +0300 | [diff] [blame] | 6942 | weston_compositor_add_log_scope(ec->weston_log_ctx, "scene-graph", |
| 6943 | "Scene graph details\n", |
| 6944 | debug_scene_graph_cb, |
| 6945 | ec); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 6946 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 6947 | return ec; |
| 6948 | |
| 6949 | fail: |
| 6950 | free(ec); |
| 6951 | return NULL; |
| 6952 | } |
| 6953 | |
Benjamin Franzke | b826302 | 2011-08-30 11:32:47 +0200 | [diff] [blame] | 6954 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 6955 | weston_compositor_shutdown(struct weston_compositor *ec) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 6956 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 6957 | struct weston_output *output, *next; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 6958 | |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 6959 | wl_event_source_remove(ec->idle_source); |
| 6960 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 6961 | /* Destroy all outputs associated with this compositor */ |
Tiago Vignatti | b303a1d | 2011-12-18 22:27:40 +0200 | [diff] [blame] | 6962 | wl_list_for_each_safe(output, next, &ec->output_list, link) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 6963 | output->destroy(output); |
Pekka Paalanen | 4738f3b | 2012-01-02 15:47:07 +0200 | [diff] [blame] | 6964 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6965 | /* Destroy all pending outputs associated with this compositor */ |
| 6966 | wl_list_for_each_safe(output, next, &ec->pending_output_list, link) |
| 6967 | output->destroy(output); |
| 6968 | |
Ander Conselvan de Oliveira | 1853676 | 2013-12-20 21:07:00 +0200 | [diff] [blame] | 6969 | if (ec->renderer) |
| 6970 | ec->renderer->destroy(ec); |
| 6971 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6972 | weston_binding_list_destroy_all(&ec->key_binding_list); |
Ryo Munakata | 27135af | 2015-07-17 13:07:42 +0900 | [diff] [blame] | 6973 | weston_binding_list_destroy_all(&ec->modifier_binding_list); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6974 | weston_binding_list_destroy_all(&ec->button_binding_list); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 6975 | weston_binding_list_destroy_all(&ec->touch_binding_list); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6976 | weston_binding_list_destroy_all(&ec->axis_binding_list); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6977 | weston_binding_list_destroy_all(&ec->debug_binding_list); |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 6978 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 6979 | weston_plane_release(&ec->primary_plane); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 6980 | } |
| 6981 | |
Kristian Høgsberg | af4f2aa | 2013-02-15 20:53:20 -0500 | [diff] [blame] | 6982 | WL_EXPORT void |
Frederic Plourde | c336f06 | 2014-10-29 14:44:33 -0400 | [diff] [blame] | 6983 | weston_compositor_exit_with_code(struct weston_compositor *compositor, |
| 6984 | int exit_code) |
| 6985 | { |
Pekka Paalanen | f5ef88f | 2014-11-18 15:57:04 +0200 | [diff] [blame] | 6986 | if (compositor->exit_code == EXIT_SUCCESS) |
| 6987 | compositor->exit_code = exit_code; |
| 6988 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 6989 | weston_compositor_exit(compositor); |
Frederic Plourde | c336f06 | 2014-10-29 14:44:33 -0400 | [diff] [blame] | 6990 | } |
| 6991 | |
| 6992 | WL_EXPORT void |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 6993 | weston_compositor_set_default_pointer_grab(struct weston_compositor *ec, |
| 6994 | const struct weston_pointer_grab_interface *interface) |
| 6995 | { |
| 6996 | struct weston_seat *seat; |
| 6997 | |
| 6998 | ec->default_pointer_grab = interface; |
| 6999 | wl_list_for_each(seat, &ec->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 7000 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 7001 | |
| 7002 | if (pointer) |
| 7003 | weston_pointer_set_default_grab(pointer, interface); |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 7004 | } |
| 7005 | } |
| 7006 | |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 7007 | WL_EXPORT int |
| 7008 | weston_compositor_set_presentation_clock(struct weston_compositor *compositor, |
| 7009 | clockid_t clk_id) |
| 7010 | { |
| 7011 | struct timespec ts; |
| 7012 | |
| 7013 | if (clock_gettime(clk_id, &ts) < 0) |
| 7014 | return -1; |
| 7015 | |
| 7016 | compositor->presentation_clock = clk_id; |
| 7017 | |
| 7018 | return 0; |
| 7019 | } |
| 7020 | |
| 7021 | /* |
| 7022 | * For choosing the software clock, when the display hardware or API |
| 7023 | * does not expose a compatible presentation timestamp. |
| 7024 | */ |
| 7025 | WL_EXPORT int |
| 7026 | weston_compositor_set_presentation_clock_software( |
| 7027 | struct weston_compositor *compositor) |
| 7028 | { |
| 7029 | /* In order of preference */ |
| 7030 | static const clockid_t clocks[] = { |
| 7031 | CLOCK_MONOTONIC_RAW, /* no jumps, no crawling */ |
| 7032 | CLOCK_MONOTONIC_COARSE, /* no jumps, may crawl, fast & coarse */ |
| 7033 | CLOCK_MONOTONIC, /* no jumps, may crawl */ |
| 7034 | CLOCK_REALTIME_COARSE, /* may jump and crawl, fast & coarse */ |
| 7035 | CLOCK_REALTIME /* may jump and crawl */ |
| 7036 | }; |
| 7037 | unsigned i; |
| 7038 | |
| 7039 | for (i = 0; i < ARRAY_LENGTH(clocks); i++) |
| 7040 | if (weston_compositor_set_presentation_clock(compositor, |
| 7041 | clocks[i]) == 0) |
| 7042 | return 0; |
| 7043 | |
| 7044 | weston_log("Error: no suitable presentation clock available.\n"); |
| 7045 | |
| 7046 | return -1; |
| 7047 | } |
| 7048 | |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 7049 | /** Read the current time from the Presentation clock |
| 7050 | * |
| 7051 | * \param compositor |
Marius Vlad | a2dace2 | 2019-06-12 16:05:44 +0300 | [diff] [blame] | 7052 | * \param[out] ts The current time. |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 7053 | * |
| 7054 | * \note Reading the current time in user space is always imprecise to some |
| 7055 | * degree. |
| 7056 | * |
| 7057 | * This function is never meant to fail. If reading the clock does fail, |
| 7058 | * an error message is logged and a zero time is returned. Callers are not |
| 7059 | * supposed to detect or react to failures. |
| 7060 | */ |
| 7061 | WL_EXPORT void |
| 7062 | weston_compositor_read_presentation_clock( |
| 7063 | const struct weston_compositor *compositor, |
| 7064 | struct timespec *ts) |
| 7065 | { |
| 7066 | static bool warned; |
| 7067 | int ret; |
| 7068 | |
| 7069 | ret = clock_gettime(compositor->presentation_clock, ts); |
| 7070 | if (ret < 0) { |
| 7071 | ts->tv_sec = 0; |
| 7072 | ts->tv_nsec = 0; |
| 7073 | |
| 7074 | if (!warned) |
| 7075 | weston_log("Error: failure to read " |
Antonio Borneo | 3957863 | 2019-04-26 23:57:31 +0200 | [diff] [blame] | 7076 | "the presentation clock %#x: '%s' (%d)\n", |
| 7077 | compositor->presentation_clock, |
| 7078 | strerror(errno), errno); |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 7079 | warned = true; |
| 7080 | } |
| 7081 | } |
| 7082 | |
Pekka Paalanen | 230f3b1 | 2014-09-29 14:18:40 -0400 | [diff] [blame] | 7083 | /** Import dmabuf buffer into current renderer |
| 7084 | * |
| 7085 | * \param compositor |
| 7086 | * \param buffer the dmabuf buffer to import |
| 7087 | * \return true on usable buffers, false otherwise |
| 7088 | * |
| 7089 | * This function tests that the linux_dmabuf_buffer is usable |
| 7090 | * for the current renderer. Returns false on unusable buffers. Usually |
| 7091 | * usability is tested by importing the dmabufs for composition. |
| 7092 | * |
| 7093 | * This hook is also used for detecting if the renderer supports |
| 7094 | * dmabufs at all. If the renderer hook is NULL, dmabufs are not |
| 7095 | * supported. |
| 7096 | * */ |
| 7097 | WL_EXPORT bool |
| 7098 | weston_compositor_import_dmabuf(struct weston_compositor *compositor, |
| 7099 | struct linux_dmabuf_buffer *buffer) |
| 7100 | { |
| 7101 | struct weston_renderer *renderer; |
| 7102 | |
| 7103 | renderer = compositor->renderer; |
| 7104 | |
| 7105 | if (renderer->import_dmabuf == NULL) |
| 7106 | return false; |
| 7107 | |
| 7108 | return renderer->import_dmabuf(compositor, buffer); |
| 7109 | } |
| 7110 | |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 7111 | WL_EXPORT void |
Kristian Høgsberg | af4f2aa | 2013-02-15 20:53:20 -0500 | [diff] [blame] | 7112 | weston_version(int *major, int *minor, int *micro) |
| 7113 | { |
| 7114 | *major = WESTON_VERSION_MAJOR; |
| 7115 | *minor = WESTON_VERSION_MINOR; |
| 7116 | *micro = WESTON_VERSION_MICRO; |
| 7117 | } |
| 7118 | |
Daniel Stone | e03c111 | 2016-11-24 20:45:45 +0000 | [diff] [blame] | 7119 | /** |
| 7120 | * Attempts to find a module path from the module map specified in the |
| 7121 | * environment. If found, writes the full path into the path variable. |
| 7122 | * |
| 7123 | * The module map is a string in environment variable WESTON_MODULE_MAP, where |
| 7124 | * each entry is of the form "name=path" and entries are separated by |
| 7125 | * semicolons. Whitespace is significant. |
| 7126 | * |
| 7127 | * \param name The name to search for. |
| 7128 | * \param path Where the path is written to if found. |
| 7129 | * \param path_len Allocated bytes at \c path . |
| 7130 | * \returns The length of the string written to path on success, or 0 if the |
| 7131 | * module was not specified in the environment map or path_len was too small. |
| 7132 | */ |
| 7133 | WL_EXPORT size_t |
| 7134 | weston_module_path_from_env(const char *name, char *path, size_t path_len) |
| 7135 | { |
| 7136 | const char *mapping = getenv("WESTON_MODULE_MAP"); |
| 7137 | const char *end; |
| 7138 | const int name_len = strlen(name); |
| 7139 | |
| 7140 | if (!mapping) |
| 7141 | return 0; |
| 7142 | |
| 7143 | end = mapping + strlen(mapping); |
| 7144 | while (mapping < end && *mapping) { |
| 7145 | const char *filename, *next; |
| 7146 | |
| 7147 | /* early out: impossibly short string */ |
| 7148 | if (end - mapping < name_len + 1) |
| 7149 | return 0; |
| 7150 | |
| 7151 | filename = &mapping[name_len + 1]; |
| 7152 | next = strchrnul(mapping, ';'); |
| 7153 | |
| 7154 | if (strncmp(mapping, name, name_len) == 0 && |
| 7155 | mapping[name_len] == '=') { |
| 7156 | size_t file_len = next - filename; /* no trailing NUL */ |
| 7157 | if (file_len >= path_len) |
| 7158 | return 0; |
| 7159 | strncpy(path, filename, file_len); |
| 7160 | path[file_len] = '\0'; |
| 7161 | return file_len; |
| 7162 | } |
| 7163 | |
| 7164 | mapping = next + 1; |
| 7165 | } |
| 7166 | |
| 7167 | return 0; |
| 7168 | } |
| 7169 | |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 7170 | WL_EXPORT void * |
| 7171 | weston_load_module(const char *name, const char *entrypoint) |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 7172 | { |
| 7173 | char path[PATH_MAX]; |
| 7174 | void *module, *init; |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 7175 | size_t len; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 7176 | |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 7177 | if (name == NULL) |
| 7178 | return NULL; |
| 7179 | |
Derek Foreman | 3f86e50 | 2015-06-08 11:46:54 -0500 | [diff] [blame] | 7180 | if (name[0] != '/') { |
Daniel Stone | e03c111 | 2016-11-24 20:45:45 +0000 | [diff] [blame] | 7181 | len = weston_module_path_from_env(name, path, sizeof path); |
| 7182 | if (len == 0) |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 7183 | len = snprintf(path, sizeof path, "%s/%s", |
| 7184 | LIBWESTON_MODULEDIR, name); |
Derek Foreman | 3f86e50 | 2015-06-08 11:46:54 -0500 | [diff] [blame] | 7185 | } else { |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 7186 | len = snprintf(path, sizeof path, "%s", name); |
Derek Foreman | 3f86e50 | 2015-06-08 11:46:54 -0500 | [diff] [blame] | 7187 | } |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 7188 | |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 7189 | /* snprintf returns the length of the string it would've written, |
| 7190 | * _excluding_ the NUL byte. So even being equal to the size of |
| 7191 | * our buffer is an error here. */ |
| 7192 | if (len >= sizeof path) |
| 7193 | return NULL; |
| 7194 | |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 7195 | module = dlopen(path, RTLD_NOW | RTLD_NOLOAD); |
| 7196 | if (module) { |
| 7197 | weston_log("Module '%s' already loaded\n", path); |
| 7198 | dlclose(module); |
| 7199 | return NULL; |
| 7200 | } |
| 7201 | |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 7202 | weston_log("Loading module '%s'\n", path); |
Kristian Høgsberg | 1acd9f8 | 2012-07-26 11:39:26 -0400 | [diff] [blame] | 7203 | module = dlopen(path, RTLD_NOW); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 7204 | if (!module) { |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 7205 | weston_log("Failed to load module: %s\n", dlerror()); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 7206 | return NULL; |
| 7207 | } |
| 7208 | |
| 7209 | init = dlsym(module, entrypoint); |
| 7210 | if (!init) { |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 7211 | weston_log("Failed to lookup init function: %s\n", dlerror()); |
Rob Bradford | c9e64ab | 2012-12-05 18:47:10 +0000 | [diff] [blame] | 7212 | dlclose(module); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 7213 | return NULL; |
| 7214 | } |
| 7215 | |
| 7216 | return init; |
| 7217 | } |
| 7218 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7219 | |
| 7220 | /** Destroys the compositor. |
| 7221 | * |
| 7222 | * This function cleans up the compositor state and destroys it. |
| 7223 | * |
| 7224 | * \param compositor The compositor to be destroyed. |
| 7225 | */ |
| 7226 | WL_EXPORT void |
| 7227 | weston_compositor_destroy(struct weston_compositor *compositor) |
| 7228 | { |
| 7229 | /* prevent further rendering while shutting down */ |
| 7230 | compositor->state = WESTON_COMPOSITOR_OFFSCREEN; |
| 7231 | |
| 7232 | wl_signal_emit(&compositor->destroy_signal, compositor); |
| 7233 | |
| 7234 | weston_compositor_xkb_destroy(compositor); |
| 7235 | |
Giulio Camuffo | 2d24e64 | 2015-10-03 16:25:15 +0300 | [diff] [blame] | 7236 | if (compositor->backend) |
| 7237 | compositor->backend->destroy(compositor); |
Pekka Paalanen | 827b5d2 | 2016-06-29 11:54:26 +0200 | [diff] [blame] | 7238 | |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 7239 | /* The backend is responsible for destroying the heads. */ |
| 7240 | assert(wl_list_empty(&compositor->head_list)); |
| 7241 | |
Pekka Paalanen | 827b5d2 | 2016-06-29 11:54:26 +0200 | [diff] [blame] | 7242 | weston_plugin_api_destroy_list(compositor); |
| 7243 | |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 7244 | if (compositor->heads_changed_source) |
| 7245 | wl_event_source_remove(compositor->heads_changed_source); |
| 7246 | |
Marius Vlad | 7e4db95 | 2019-04-17 13:47:06 +0300 | [diff] [blame] | 7247 | weston_compositor_log_scope_destroy(compositor->debug_scene); |
Daniel Stone | ce62cb3 | 2018-07-20 09:46:24 +0100 | [diff] [blame] | 7248 | compositor->debug_scene = NULL; |
Marius Vlad | 3d7d978 | 2019-04-17 12:35:38 +0300 | [diff] [blame] | 7249 | weston_log_ctx_compositor_destroy(compositor); |
Pekka Paalanen | a5630ea | 2017-10-12 13:13:42 +0200 | [diff] [blame] | 7250 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 7251 | free(compositor); |
| 7252 | } |
| 7253 | |
| 7254 | /** Instruct the compositor to exit. |
| 7255 | * |
| 7256 | * This functions does not directly destroy the compositor object, it merely |
| 7257 | * command it to start the tear down process. It is not guaranteed that the |
| 7258 | * tear down will happen immediately. |
| 7259 | * |
| 7260 | * \param compositor The compositor to tear down. |
| 7261 | */ |
| 7262 | WL_EXPORT void |
| 7263 | weston_compositor_exit(struct weston_compositor *compositor) |
| 7264 | { |
| 7265 | compositor->exit(compositor); |
| 7266 | } |
| 7267 | |
| 7268 | /** Return the user data stored in the compositor. |
| 7269 | * |
| 7270 | * This function returns the user data pointer set with user_data parameter |
| 7271 | * to the \ref weston_compositor_create function. |
| 7272 | */ |
| 7273 | WL_EXPORT void * |
| 7274 | weston_compositor_get_user_data(struct weston_compositor *compositor) |
| 7275 | { |
| 7276 | return compositor->user_data; |
| 7277 | } |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 7278 | |
Pekka Paalanen | 50dbf38 | 2016-06-03 15:23:46 +0300 | [diff] [blame] | 7279 | static const char * const backend_map[] = { |
| 7280 | [WESTON_BACKEND_DRM] = "drm-backend.so", |
| 7281 | [WESTON_BACKEND_FBDEV] = "fbdev-backend.so", |
| 7282 | [WESTON_BACKEND_HEADLESS] = "headless-backend.so", |
| 7283 | [WESTON_BACKEND_RDP] = "rdp-backend.so", |
| 7284 | [WESTON_BACKEND_WAYLAND] = "wayland-backend.so", |
| 7285 | [WESTON_BACKEND_X11] = "x11-backend.so", |
| 7286 | }; |
| 7287 | |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 7288 | /** Load a backend into a weston_compositor |
| 7289 | * |
| 7290 | * A backend must be loaded to make a weston_compositor work. A backend |
| 7291 | * provides input and output capabilities, and determines the renderer to use. |
| 7292 | * |
| 7293 | * \param compositor A compositor that has not had a backend loaded yet. |
| 7294 | * \param backend Name of the backend file. |
| 7295 | * \param config_base A pointer to a backend-specific configuration |
| 7296 | * structure's 'base' member. |
| 7297 | * |
| 7298 | * \return 0 on success, or -1 on error. |
| 7299 | */ |
| 7300 | WL_EXPORT int |
| 7301 | weston_compositor_load_backend(struct weston_compositor *compositor, |
Pekka Paalanen | 50dbf38 | 2016-06-03 15:23:46 +0300 | [diff] [blame] | 7302 | enum weston_compositor_backend backend, |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 7303 | struct weston_backend_config *config_base) |
| 7304 | { |
| 7305 | int (*backend_init)(struct weston_compositor *c, |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 7306 | struct weston_backend_config *config_base); |
| 7307 | |
Pekka Paalanen | d7e3511 | 2017-08-29 17:04:12 +0300 | [diff] [blame] | 7308 | if (compositor->backend) { |
| 7309 | weston_log("Error: attempt to load a backend when one is already loaded\n"); |
| 7310 | return -1; |
| 7311 | } |
| 7312 | |
Quentin Glidic | 887c018 | 2016-07-10 11:00:53 +0200 | [diff] [blame] | 7313 | if (backend >= ARRAY_LENGTH(backend_map)) |
Pekka Paalanen | 50dbf38 | 2016-06-03 15:23:46 +0300 | [diff] [blame] | 7314 | return -1; |
| 7315 | |
Quentin Glidic | 23e1d6f | 2016-12-02 14:08:44 +0100 | [diff] [blame] | 7316 | backend_init = weston_load_module(backend_map[backend], "weston_backend_init"); |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 7317 | if (!backend_init) |
| 7318 | return -1; |
| 7319 | |
Pekka Paalanen | d7e3511 | 2017-08-29 17:04:12 +0300 | [diff] [blame] | 7320 | if (backend_init(compositor, config_base) < 0) { |
| 7321 | compositor->backend = NULL; |
| 7322 | return -1; |
| 7323 | } |
| 7324 | |
| 7325 | return 0; |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 7326 | } |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 7327 | |
| 7328 | WL_EXPORT int |
| 7329 | weston_compositor_load_xwayland(struct weston_compositor *compositor) |
| 7330 | { |
Quentin Glidic | 3d7ca3b | 2016-12-02 14:20:35 +0100 | [diff] [blame] | 7331 | int (*module_init)(struct weston_compositor *ec); |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 7332 | |
Quentin Glidic | 3d7ca3b | 2016-12-02 14:20:35 +0100 | [diff] [blame] | 7333 | module_init = weston_load_module("xwayland.so", "weston_module_init"); |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 7334 | if (!module_init) |
| 7335 | return -1; |
Quentin Glidic | 3d7ca3b | 2016-12-02 14:20:35 +0100 | [diff] [blame] | 7336 | if (module_init(compositor) < 0) |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 7337 | return -1; |
| 7338 | return 0; |
| 7339 | } |
Vasilis Liaskovitis | 486b463 | 2018-10-10 16:14:55 +0200 | [diff] [blame] | 7340 | |
| 7341 | /** Resolve an internal compositor error by disconnecting the client. |
| 7342 | * |
| 7343 | * This function is used in cases when the wl_buffer turns out |
| 7344 | * unusable and there is no fallback path. |
| 7345 | * |
| 7346 | * It is possible the fault is caused by a compositor bug, the underlying |
| 7347 | * graphics stack bug or normal behaviour, or perhaps a client mistake. |
| 7348 | * In any case, the options are to either composite garbage or nothing, |
| 7349 | * or disconnect the client. This is a helper function for the latter. |
| 7350 | * |
| 7351 | * The error is sent as an INVALID_OBJECT error on the client's wl_display. |
| 7352 | * |
| 7353 | * \param buffer The weston buffer that is unusable. |
| 7354 | * \param msg A custom error message attached to the protocol error. |
| 7355 | */ |
| 7356 | WL_EXPORT void |
| 7357 | weston_buffer_send_server_error(struct weston_buffer *buffer, |
| 7358 | const char *msg) |
| 7359 | { |
| 7360 | struct wl_client *client; |
| 7361 | struct wl_resource *display_resource; |
| 7362 | uint32_t id; |
| 7363 | |
| 7364 | assert(buffer->resource); |
| 7365 | id = wl_resource_get_id(buffer->resource); |
| 7366 | client = wl_resource_get_client(buffer->resource); |
| 7367 | display_resource = wl_client_get_object(client, 1); |
| 7368 | |
| 7369 | assert(display_resource); |
| 7370 | wl_resource_post_error(display_resource, |
| 7371 | WL_DISPLAY_ERROR_INVALID_OBJECT, |
| 7372 | "server error with " |
| 7373 | "wl_buffer@%u: %s", id, msg); |
| 7374 | } |