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 | c647ed7 | 2015-02-09 13:16:57 +0200 | [diff] [blame] | 4 | * Copyright © 2012-2015 Collabora, Ltd. |
Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 5 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 6 | * Permission is hereby granted, free of charge, to any person obtaining |
| 7 | * a copy of this software and associated documentation files (the |
| 8 | * "Software"), to deal in the Software without restriction, including |
| 9 | * without limitation the rights to use, copy, modify, merge, publish, |
| 10 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 11 | * permit persons to whom the Software is furnished to do so, subject to |
| 12 | * the following conditions: |
Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 13 | * |
Bryce Harrington | a0bbfea | 2015-06-11 15:35:43 -0700 | [diff] [blame] | 14 | * The above copyright notice and this permission notice (including the |
| 15 | * next paragraph) shall be included in all copies or substantial |
| 16 | * portions of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 19 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 21 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 22 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 23 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 24 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 25 | * SOFTWARE. |
Kristian Høgsberg | ffd710e | 2008-12-02 15:15:01 -0500 | [diff] [blame] | 26 | */ |
| 27 | |
Kristian Høgsberg | a941022 | 2011-01-14 17:22:35 -0500 | [diff] [blame] | 28 | #include "config.h" |
| 29 | |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 30 | #include <fcntl.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 31 | #include <stdio.h> |
| 32 | #include <string.h> |
| 33 | #include <stdlib.h> |
| 34 | #include <stdint.h> |
Benjamin Franzke | eefc36c | 2011-03-11 16:39:20 +0100 | [diff] [blame] | 35 | #include <limits.h> |
Kristian Høgsberg | 8d7ca6b | 2008-11-09 00:22:51 -0500 | [diff] [blame] | 36 | #include <stdarg.h> |
Benjamin Franzke | 6f5fc69 | 2011-06-21 19:34:19 +0200 | [diff] [blame] | 37 | #include <assert.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 38 | #include <sys/ioctl.h> |
Daniel Stone | b7452fe | 2012-06-01 12:14:06 +0100 | [diff] [blame] | 39 | #include <sys/mman.h> |
Kristian Høgsberg | 27da538 | 2011-06-21 17:32:25 -0400 | [diff] [blame] | 40 | #include <sys/wait.h> |
Pekka Paalanen | 409ef0a | 2011-12-02 15:30:21 +0200 | [diff] [blame] | 41 | #include <sys/socket.h> |
Martin Minarik | f12c287 | 2012-06-11 00:57:39 +0200 | [diff] [blame] | 42 | #include <sys/utsname.h> |
Martin Minarik | 37032f8 | 2012-06-18 20:15:18 +0200 | [diff] [blame] | 43 | #include <sys/stat.h> |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 44 | #include <unistd.h> |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 45 | #include <math.h> |
Kristian Høgsberg | fc783d4 | 2010-06-11 12:56:24 -0400 | [diff] [blame] | 46 | #include <linux/input.h> |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 47 | #include <dlfcn.h> |
Kristian Høgsberg | 8544903 | 2011-05-02 12:11:07 -0400 | [diff] [blame] | 48 | #include <signal.h> |
Kristian Høgsberg | 0690da6 | 2012-01-16 11:53:54 -0500 | [diff] [blame] | 49 | #include <setjmp.h> |
Kristian Høgsberg | a411c8b | 2012-06-08 16:16:52 -0400 | [diff] [blame] | 50 | #include <sys/time.h> |
| 51 | #include <time.h> |
Pekka Paalanen | 23ade62 | 2014-08-27 13:31:26 +0300 | [diff] [blame] | 52 | #include <errno.h> |
Kristian Høgsberg | 890bc05 | 2008-12-30 14:31:33 -0500 | [diff] [blame] | 53 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 54 | #include "timeline.h" |
| 55 | |
Kristian Høgsberg | 8286302 | 2010-06-04 21:52:02 -0400 | [diff] [blame] | 56 | #include "compositor.h" |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 57 | #include "viewporter-server-protocol.h" |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 58 | #include "presentation-time-server-protocol.h" |
Jon Cruz | 35b2eaa | 2015-06-15 15:37:08 -0700 | [diff] [blame] | 59 | #include "shared/helpers.h" |
Jon Cruz | 4678bab | 2015-06-15 15:37:07 -0700 | [diff] [blame] | 60 | #include "shared/os-compatibility.h" |
Bryce Harrington | 25a2bdd | 2016-08-03 17:40:52 -0700 | [diff] [blame] | 61 | #include "shared/string-helpers.h" |
Pekka Paalanen | aa21f62 | 2015-07-03 15:44:50 +0300 | [diff] [blame] | 62 | #include "shared/timespec-util.h" |
Kristian Høgsberg | a411c8b | 2012-06-08 16:16:52 -0400 | [diff] [blame] | 63 | #include "git-version.h" |
Kristian Høgsberg | af4f2aa | 2013-02-15 20:53:20 -0500 | [diff] [blame] | 64 | #include "version.h" |
Pekka Paalanen | 827b5d2 | 2016-06-29 11:54:26 +0200 | [diff] [blame] | 65 | #include "plugin-registry.h" |
Kristian Høgsberg | 5ee1a60 | 2008-12-11 23:18:45 -0500 | [diff] [blame] | 66 | |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 67 | #define DEFAULT_REPAINT_WINDOW 7 /* milliseconds */ |
| 68 | |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 69 | static void |
Pekka Paalanen | d72bad2 | 2017-03-29 17:01:41 +0300 | [diff] [blame] | 70 | weston_output_update_matrix(struct weston_output *output); |
| 71 | |
| 72 | static void |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 73 | weston_output_transform_scale_init(struct weston_output *output, |
| 74 | uint32_t transform, uint32_t scale); |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 75 | |
Rob Bradford | 27b1793 | 2013-06-26 18:08:46 +0100 | [diff] [blame] | 76 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 77 | weston_compositor_build_view_list(struct weston_compositor *compositor); |
Rob Bradford | 27b1793 | 2013-06-26 18:08:46 +0100 | [diff] [blame] | 78 | |
Pekka Paalanen | 6528c03 | 2017-03-28 15:27:10 +0300 | [diff] [blame] | 79 | /** Send wl_output events for mode and scale changes |
| 80 | * |
| 81 | * \param head Send on all resources bound to this head. |
| 82 | * \param mode_changed If true, send the current mode. |
| 83 | * \param scale_changed If true, send the current scale. |
| 84 | */ |
| 85 | static void |
| 86 | weston_mode_switch_send_events(struct weston_head *head, |
| 87 | bool mode_changed, bool scale_changed) |
| 88 | { |
| 89 | struct weston_output *output = head->output; |
| 90 | struct wl_resource *resource; |
| 91 | int version; |
| 92 | |
| 93 | wl_resource_for_each(resource, &head->resource_list) { |
| 94 | if (mode_changed) { |
| 95 | wl_output_send_mode(resource, |
| 96 | output->current_mode->flags, |
| 97 | output->current_mode->width, |
| 98 | output->current_mode->height, |
| 99 | output->current_mode->refresh); |
| 100 | } |
| 101 | |
| 102 | version = wl_resource_get_version(resource); |
| 103 | if (version >= WL_OUTPUT_SCALE_SINCE_VERSION && scale_changed) |
| 104 | wl_output_send_scale(resource, output->current_scale); |
| 105 | |
| 106 | if (version >= WL_OUTPUT_DONE_SINCE_VERSION) |
| 107 | wl_output_send_done(resource); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | static void |
| 112 | weston_mode_switch_finish(struct weston_output *output, |
| 113 | int mode_changed, int scale_changed) |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 114 | { |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 115 | struct weston_seat *seat; |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 116 | struct weston_head *head; |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 117 | pixman_region32_t old_output_region; |
Alexander Larsson | 355748e | 2013-05-28 16:23:38 +0200 | [diff] [blame] | 118 | |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 119 | pixman_region32_init(&old_output_region); |
| 120 | pixman_region32_copy(&old_output_region, &output->region); |
| 121 | |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 122 | /* Update output region and transformation matrix */ |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 123 | 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] | 124 | |
| 125 | pixman_region32_init(&output->previous_damage); |
| 126 | pixman_region32_init_rect(&output->region, output->x, output->y, |
| 127 | output->width, output->height); |
| 128 | |
| 129 | weston_output_update_matrix(output); |
| 130 | |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 131 | /* If a pointer falls outside the outputs new geometry, move it to its |
| 132 | * lower-right corner */ |
| 133 | wl_list_for_each(seat, &output->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 134 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 135 | int32_t x, y; |
| 136 | |
| 137 | if (!pointer) |
| 138 | continue; |
| 139 | |
| 140 | x = wl_fixed_to_int(pointer->x); |
| 141 | y = wl_fixed_to_int(pointer->y); |
| 142 | |
| 143 | if (!pixman_region32_contains_point(&old_output_region, |
| 144 | x, y, NULL) || |
| 145 | pixman_region32_contains_point(&output->region, |
| 146 | x, y, NULL)) |
| 147 | continue; |
| 148 | |
| 149 | if (x >= output->x + output->width) |
| 150 | x = output->x + output->width - 1; |
| 151 | if (y >= output->y + output->height) |
| 152 | y = output->y + output->height - 1; |
| 153 | |
| 154 | pointer->x = wl_fixed_from_int(x); |
| 155 | pointer->y = wl_fixed_from_int(y); |
| 156 | } |
| 157 | |
| 158 | pixman_region32_fini(&old_output_region); |
| 159 | |
Derek Foreman | dd4cd33 | 2014-11-10 10:29:59 -0600 | [diff] [blame] | 160 | if (!mode_changed && !scale_changed) |
| 161 | return; |
| 162 | |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 163 | /* notify clients of the changes */ |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 164 | wl_list_for_each(head, &output->head_list, output_link) |
| 165 | weston_mode_switch_send_events(head, |
| 166 | mode_changed, scale_changed); |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 167 | } |
| 168 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 169 | static void |
| 170 | weston_compositor_reflow_outputs(struct weston_compositor *compositor, |
| 171 | struct weston_output *resized_output, int delta_width); |
| 172 | |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 173 | WL_EXPORT int |
| 174 | weston_output_mode_set_native(struct weston_output *output, |
| 175 | struct weston_mode *mode, |
| 176 | int32_t scale) |
| 177 | { |
| 178 | int ret; |
| 179 | int mode_changed = 0, scale_changed = 0; |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 180 | int32_t old_width; |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 181 | |
| 182 | if (!output->switch_mode) |
| 183 | return -1; |
| 184 | |
| 185 | if (!output->original_mode) { |
| 186 | mode_changed = 1; |
| 187 | ret = output->switch_mode(output, mode); |
| 188 | if (ret < 0) |
| 189 | return ret; |
| 190 | if (output->current_scale != scale) { |
| 191 | scale_changed = 1; |
| 192 | output->current_scale = scale; |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 196 | old_width = output->width; |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 197 | output->native_mode = mode; |
| 198 | output->native_scale = scale; |
| 199 | |
| 200 | weston_mode_switch_finish(output, mode_changed, scale_changed); |
| 201 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 202 | if (mode_changed || scale_changed) { |
| 203 | weston_compositor_reflow_outputs(output->compositor, output, output->width - old_width); |
| 204 | |
| 205 | wl_signal_emit(&output->compositor->output_resized_signal, output); |
| 206 | } |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 207 | return 0; |
| 208 | } |
| 209 | |
| 210 | WL_EXPORT int |
| 211 | weston_output_mode_switch_to_native(struct weston_output *output) |
| 212 | { |
| 213 | int ret; |
| 214 | int mode_changed = 0, scale_changed = 0; |
| 215 | |
| 216 | if (!output->switch_mode) |
| 217 | return -1; |
| 218 | |
| 219 | if (!output->original_mode) { |
| 220 | weston_log("already in the native mode\n"); |
| 221 | return -1; |
| 222 | } |
| 223 | /* the non fullscreen clients haven't seen a mode set since we |
| 224 | * switched into a temporary, so we need to notify them if the |
| 225 | * mode at that time is different from the native mode now. |
| 226 | */ |
| 227 | mode_changed = (output->original_mode != output->native_mode); |
| 228 | scale_changed = (output->original_scale != output->native_scale); |
| 229 | |
| 230 | ret = output->switch_mode(output, output->native_mode); |
| 231 | if (ret < 0) |
| 232 | return ret; |
| 233 | |
| 234 | output->current_scale = output->native_scale; |
| 235 | |
| 236 | output->original_mode = NULL; |
| 237 | output->original_scale = 0; |
| 238 | |
| 239 | weston_mode_switch_finish(output, mode_changed, scale_changed); |
| 240 | |
| 241 | return 0; |
| 242 | } |
| 243 | |
| 244 | WL_EXPORT int |
| 245 | weston_output_mode_switch_to_temporary(struct weston_output *output, |
| 246 | struct weston_mode *mode, |
| 247 | int32_t scale) |
| 248 | { |
| 249 | int ret; |
| 250 | |
| 251 | if (!output->switch_mode) |
| 252 | return -1; |
| 253 | |
| 254 | /* original_mode is the last mode non full screen clients have seen, |
| 255 | * so we shouldn't change it if we already have one set. |
| 256 | */ |
| 257 | if (!output->original_mode) { |
| 258 | output->original_mode = output->native_mode; |
| 259 | output->original_scale = output->native_scale; |
| 260 | } |
| 261 | ret = output->switch_mode(output, mode); |
| 262 | if (ret < 0) |
| 263 | return ret; |
| 264 | |
| 265 | output->current_scale = scale; |
| 266 | |
| 267 | weston_mode_switch_finish(output, 0, 0); |
| 268 | |
| 269 | return 0; |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 270 | } |
| 271 | |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 272 | static void |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 273 | region_init_infinite(pixman_region32_t *region) |
| 274 | { |
| 275 | pixman_region32_init_rect(region, INT32_MIN, INT32_MIN, |
| 276 | UINT32_MAX, UINT32_MAX); |
| 277 | } |
| 278 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 279 | static struct weston_subsurface * |
| 280 | weston_surface_to_subsurface(struct weston_surface *surface); |
| 281 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 282 | WL_EXPORT struct weston_view * |
| 283 | weston_view_create(struct weston_surface *surface) |
| 284 | { |
| 285 | struct weston_view *view; |
| 286 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 287 | view = zalloc(sizeof *view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 288 | if (view == NULL) |
| 289 | return NULL; |
| 290 | |
| 291 | view->surface = surface; |
Daniel Stone | fb4869d | 2016-12-09 16:27:54 +0000 | [diff] [blame] | 292 | view->plane = &surface->compositor->primary_plane; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 293 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 294 | /* Assign to surface */ |
| 295 | wl_list_insert(&surface->views, &view->surface_link); |
| 296 | |
| 297 | wl_signal_init(&view->destroy_signal); |
| 298 | wl_list_init(&view->link); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 299 | wl_list_init(&view->layer_link.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 300 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 301 | pixman_region32_init(&view->clip); |
| 302 | |
| 303 | view->alpha = 1.0; |
| 304 | pixman_region32_init(&view->transform.opaque); |
| 305 | |
| 306 | wl_list_init(&view->geometry.transformation_list); |
| 307 | wl_list_insert(&view->geometry.transformation_list, |
| 308 | &view->transform.position.link); |
| 309 | weston_matrix_init(&view->transform.position.matrix); |
| 310 | wl_list_init(&view->geometry.child_list); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 311 | pixman_region32_init(&view->geometry.scissor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 312 | pixman_region32_init(&view->transform.boundingbox); |
| 313 | view->transform.dirty = 1; |
| 314 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 315 | return view; |
| 316 | } |
| 317 | |
Jason Ekstrand | 108865d | 2014-06-26 10:04:49 -0700 | [diff] [blame] | 318 | struct weston_frame_callback { |
| 319 | struct wl_resource *resource; |
| 320 | struct wl_list link; |
| 321 | }; |
| 322 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 323 | struct weston_presentation_feedback { |
| 324 | struct wl_resource *resource; |
| 325 | |
| 326 | /* XXX: could use just wl_resource_get_link() instead */ |
| 327 | struct wl_list link; |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 328 | |
| 329 | /* The per-surface feedback flags */ |
| 330 | uint32_t psf_flags; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 331 | }; |
| 332 | |
| 333 | static void |
| 334 | weston_presentation_feedback_discard( |
| 335 | struct weston_presentation_feedback *feedback) |
| 336 | { |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 337 | wp_presentation_feedback_send_discarded(feedback->resource); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 338 | wl_resource_destroy(feedback->resource); |
| 339 | } |
| 340 | |
| 341 | static void |
| 342 | weston_presentation_feedback_discard_list(struct wl_list *list) |
| 343 | { |
| 344 | struct weston_presentation_feedback *feedback, *tmp; |
| 345 | |
| 346 | wl_list_for_each_safe(feedback, tmp, list, link) |
| 347 | weston_presentation_feedback_discard(feedback); |
| 348 | } |
| 349 | |
| 350 | static void |
| 351 | weston_presentation_feedback_present( |
| 352 | struct weston_presentation_feedback *feedback, |
| 353 | struct weston_output *output, |
| 354 | uint32_t refresh_nsec, |
| 355 | const struct timespec *ts, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 356 | uint64_t seq, |
| 357 | uint32_t flags) |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 358 | { |
| 359 | struct wl_client *client = wl_resource_get_client(feedback->resource); |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 360 | struct weston_head *head; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 361 | struct wl_resource *o; |
Alexandros Frantzis | 10d708d | 2017-12-13 13:27:54 +0200 | [diff] [blame] | 362 | uint32_t tv_sec_hi; |
| 363 | uint32_t tv_sec_lo; |
| 364 | uint32_t tv_nsec; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 365 | bool done = false; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 366 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 367 | wl_list_for_each(head, &output->head_list, output_link) { |
| 368 | wl_resource_for_each(o, &head->resource_list) { |
| 369 | if (wl_resource_get_client(o) != client) |
| 370 | continue; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 371 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 372 | wp_presentation_feedback_send_sync_output(feedback->resource, o); |
| 373 | done = true; |
| 374 | } |
| 375 | |
| 376 | /* For clone mode, send it for just one wl_output global, |
| 377 | * they are all equivalent anyway. |
| 378 | */ |
| 379 | if (done) |
| 380 | break; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 381 | } |
| 382 | |
Alexandros Frantzis | 10d708d | 2017-12-13 13:27:54 +0200 | [diff] [blame] | 383 | timespec_to_proto(ts, &tv_sec_hi, &tv_sec_lo, &tv_nsec); |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 384 | wp_presentation_feedback_send_presented(feedback->resource, |
Alexandros Frantzis | 10d708d | 2017-12-13 13:27:54 +0200 | [diff] [blame] | 385 | tv_sec_hi, tv_sec_lo, tv_nsec, |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 386 | refresh_nsec, |
| 387 | seq >> 32, seq & 0xffffffff, |
| 388 | flags | feedback->psf_flags); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 389 | wl_resource_destroy(feedback->resource); |
| 390 | } |
| 391 | |
| 392 | static void |
| 393 | weston_presentation_feedback_present_list(struct wl_list *list, |
| 394 | struct weston_output *output, |
| 395 | uint32_t refresh_nsec, |
| 396 | const struct timespec *ts, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 397 | uint64_t seq, |
| 398 | uint32_t flags) |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 399 | { |
| 400 | struct weston_presentation_feedback *feedback, *tmp; |
| 401 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 402 | assert(!(flags & WP_PRESENTATION_FEEDBACK_INVALID) || |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 403 | wl_list_empty(list)); |
| 404 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 405 | wl_list_for_each_safe(feedback, tmp, list, link) |
| 406 | weston_presentation_feedback_present(feedback, output, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 407 | refresh_nsec, ts, seq, |
| 408 | flags); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 409 | } |
| 410 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 411 | static void |
| 412 | surface_state_handle_buffer_destroy(struct wl_listener *listener, void *data) |
| 413 | { |
| 414 | struct weston_surface_state *state = |
| 415 | container_of(listener, struct weston_surface_state, |
| 416 | buffer_destroy_listener); |
| 417 | |
| 418 | state->buffer = NULL; |
| 419 | } |
| 420 | |
| 421 | static void |
| 422 | weston_surface_state_init(struct weston_surface_state *state) |
| 423 | { |
| 424 | state->newly_attached = 0; |
| 425 | state->buffer = NULL; |
| 426 | state->buffer_destroy_listener.notify = |
| 427 | surface_state_handle_buffer_destroy; |
| 428 | state->sx = 0; |
| 429 | state->sy = 0; |
| 430 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 431 | pixman_region32_init(&state->damage_surface); |
| 432 | pixman_region32_init(&state->damage_buffer); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 433 | pixman_region32_init(&state->opaque); |
| 434 | region_init_infinite(&state->input); |
| 435 | |
| 436 | wl_list_init(&state->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 437 | wl_list_init(&state->feedback_list); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 438 | |
| 439 | state->buffer_viewport.buffer.transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 440 | state->buffer_viewport.buffer.scale = 1; |
| 441 | state->buffer_viewport.buffer.src_width = wl_fixed_from_int(-1); |
| 442 | state->buffer_viewport.surface.width = -1; |
| 443 | state->buffer_viewport.changed = 0; |
| 444 | } |
| 445 | |
| 446 | static void |
| 447 | weston_surface_state_fini(struct weston_surface_state *state) |
| 448 | { |
| 449 | struct weston_frame_callback *cb, *next; |
| 450 | |
| 451 | wl_list_for_each_safe(cb, next, |
| 452 | &state->frame_callback_list, link) |
| 453 | wl_resource_destroy(cb->resource); |
| 454 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 455 | weston_presentation_feedback_discard_list(&state->feedback_list); |
| 456 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 457 | pixman_region32_fini(&state->input); |
| 458 | pixman_region32_fini(&state->opaque); |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 459 | pixman_region32_fini(&state->damage_surface); |
| 460 | pixman_region32_fini(&state->damage_buffer); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 461 | |
| 462 | if (state->buffer) |
| 463 | wl_list_remove(&state->buffer_destroy_listener.link); |
| 464 | state->buffer = NULL; |
| 465 | } |
| 466 | |
| 467 | static void |
| 468 | weston_surface_state_set_buffer(struct weston_surface_state *state, |
| 469 | struct weston_buffer *buffer) |
| 470 | { |
| 471 | if (state->buffer == buffer) |
| 472 | return; |
| 473 | |
| 474 | if (state->buffer) |
| 475 | wl_list_remove(&state->buffer_destroy_listener.link); |
| 476 | state->buffer = buffer; |
| 477 | if (state->buffer) |
| 478 | wl_signal_add(&state->buffer->destroy_signal, |
| 479 | &state->buffer_destroy_listener); |
| 480 | } |
| 481 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 482 | WL_EXPORT struct weston_surface * |
Kristian Høgsberg | 18c9300 | 2012-01-27 11:58:31 -0500 | [diff] [blame] | 483 | weston_surface_create(struct weston_compositor *compositor) |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 484 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 485 | struct weston_surface *surface; |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 486 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 487 | surface = zalloc(sizeof *surface); |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 488 | if (surface == NULL) |
| 489 | return NULL; |
| 490 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 491 | wl_signal_init(&surface->destroy_signal); |
Jonas Ådahl | 5d9ca27 | 2016-07-22 17:48:03 +0800 | [diff] [blame] | 492 | wl_signal_init(&surface->commit_signal); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 493 | |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 494 | surface->compositor = compositor; |
Giulio Camuffo | 13b85bd | 2013-08-13 23:10:14 +0200 | [diff] [blame] | 495 | surface->ref_count = 1; |
Kristian Høgsberg | 27803c6 | 2010-06-06 22:23:21 -0400 | [diff] [blame] | 496 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 497 | surface->buffer_viewport.buffer.transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 498 | surface->buffer_viewport.buffer.scale = 1; |
Pekka Paalanen | f0cad48 | 2014-03-14 14:38:16 +0200 | [diff] [blame] | 499 | surface->buffer_viewport.buffer.src_width = wl_fixed_from_int(-1); |
| 500 | surface->buffer_viewport.surface.width = -1; |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 501 | |
| 502 | weston_surface_state_init(&surface->pending); |
| 503 | |
Kristian Høgsberg | 20300ba | 2011-06-23 20:29:12 -0400 | [diff] [blame] | 504 | pixman_region32_init(&surface->damage); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 505 | pixman_region32_init(&surface->opaque); |
Pekka Paalanen | 8ec4ab6 | 2012-10-10 12:49:32 +0300 | [diff] [blame] | 506 | region_init_infinite(&surface->input); |
Kristian Høgsberg | 20300ba | 2011-06-23 20:29:12 -0400 | [diff] [blame] | 507 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 508 | wl_list_init(&surface->views); |
| 509 | |
| 510 | wl_list_init(&surface->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 511 | wl_list_init(&surface->feedback_list); |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 512 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 513 | wl_list_init(&surface->subsurface_list); |
| 514 | wl_list_init(&surface->subsurface_list_pending); |
| 515 | |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 516 | weston_matrix_init(&surface->buffer_to_surface_matrix); |
| 517 | weston_matrix_init(&surface->surface_to_buffer_matrix); |
| 518 | |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 519 | wl_list_init(&surface->pointer_constraints); |
| 520 | |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 521 | return surface; |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 522 | } |
| 523 | |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 524 | WL_EXPORT void |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 525 | weston_surface_set_color(struct weston_surface *surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 526 | float red, float green, float blue, float alpha) |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 527 | { |
John Kåre Alsaker | 878f449 | 2012-11-13 19:10:23 +0100 | [diff] [blame] | 528 | surface->compositor->renderer->surface_set_color(surface, red, green, blue, alpha); |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 529 | } |
| 530 | |
Kristian Høgsberg | e4c1a5f | 2012-06-18 13:17:32 -0400 | [diff] [blame] | 531 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 532 | weston_view_to_global_float(struct weston_view *view, |
| 533 | float sx, float sy, float *x, float *y) |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 534 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 535 | if (view->transform.enabled) { |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 536 | struct weston_vector v = { { sx, sy, 0.0f, 1.0f } }; |
| 537 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 538 | weston_matrix_transform(&view->transform.matrix, &v); |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 539 | |
| 540 | if (fabsf(v.f[3]) < 1e-6) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 541 | weston_log("warning: numerical instability in " |
Scott Moreau | 088c62e | 2013-02-11 04:45:38 -0700 | [diff] [blame] | 542 | "%s(), divisor = %g\n", __func__, |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 543 | v.f[3]); |
| 544 | *x = 0; |
| 545 | *y = 0; |
| 546 | return; |
| 547 | } |
| 548 | |
| 549 | *x = v.f[0] / v.f[3]; |
| 550 | *y = v.f[1] / v.f[3]; |
| 551 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 552 | *x = sx + view->geometry.x; |
| 553 | *y = sy + view->geometry.y; |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 554 | } |
| 555 | } |
| 556 | |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 557 | WL_EXPORT void |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 558 | weston_transformed_coord(int width, int height, |
| 559 | enum wl_output_transform transform, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 560 | int32_t scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 561 | float sx, float sy, float *bx, float *by) |
| 562 | { |
| 563 | switch (transform) { |
| 564 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 565 | default: |
| 566 | *bx = sx; |
| 567 | *by = sy; |
| 568 | break; |
| 569 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 570 | *bx = width - sx; |
| 571 | *by = sy; |
| 572 | break; |
| 573 | case WL_OUTPUT_TRANSFORM_90: |
| 574 | *bx = height - sy; |
| 575 | *by = sx; |
| 576 | break; |
| 577 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 578 | *bx = height - sy; |
| 579 | *by = width - sx; |
| 580 | break; |
| 581 | case WL_OUTPUT_TRANSFORM_180: |
| 582 | *bx = width - sx; |
| 583 | *by = height - sy; |
| 584 | break; |
| 585 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 586 | *bx = sx; |
| 587 | *by = height - sy; |
| 588 | break; |
| 589 | case WL_OUTPUT_TRANSFORM_270: |
| 590 | *bx = sy; |
| 591 | *by = width - sx; |
| 592 | break; |
| 593 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 594 | *bx = sy; |
| 595 | *by = sx; |
| 596 | break; |
| 597 | } |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 598 | |
| 599 | *bx *= scale; |
| 600 | *by *= scale; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | WL_EXPORT pixman_box32_t |
| 604 | weston_transformed_rect(int width, int height, |
| 605 | enum wl_output_transform transform, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 606 | int32_t scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 607 | pixman_box32_t rect) |
| 608 | { |
| 609 | float x1, x2, y1, y2; |
| 610 | |
| 611 | pixman_box32_t ret; |
| 612 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 613 | weston_transformed_coord(width, height, transform, scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 614 | rect.x1, rect.y1, &x1, &y1); |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 615 | weston_transformed_coord(width, height, transform, scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 616 | rect.x2, rect.y2, &x2, &y2); |
| 617 | |
| 618 | if (x1 <= x2) { |
| 619 | ret.x1 = x1; |
| 620 | ret.x2 = x2; |
| 621 | } else { |
| 622 | ret.x1 = x2; |
| 623 | ret.x2 = x1; |
| 624 | } |
| 625 | |
| 626 | if (y1 <= y2) { |
| 627 | ret.y1 = y1; |
| 628 | ret.y2 = y2; |
| 629 | } else { |
| 630 | ret.y1 = y2; |
| 631 | ret.y2 = y1; |
| 632 | } |
| 633 | |
| 634 | return ret; |
| 635 | } |
| 636 | |
Derek Foreman | bc9a61c | 2015-11-18 16:32:30 -0600 | [diff] [blame] | 637 | /** Transform a region by a matrix, restricted to axis-aligned transformations |
| 638 | * |
| 639 | * Warning: This function does not work for projective, affine, or matrices |
| 640 | * that encode arbitrary rotations. Only 90-degree step rotations are |
| 641 | * supported. |
| 642 | */ |
| 643 | WL_EXPORT void |
| 644 | weston_matrix_transform_region(pixman_region32_t *dest, |
| 645 | struct weston_matrix *matrix, |
| 646 | pixman_region32_t *src) |
| 647 | { |
| 648 | pixman_box32_t *src_rects, *dest_rects; |
| 649 | int nrects, i; |
| 650 | |
| 651 | src_rects = pixman_region32_rectangles(src, &nrects); |
| 652 | dest_rects = malloc(nrects * sizeof(*dest_rects)); |
| 653 | if (!dest_rects) |
| 654 | return; |
| 655 | |
| 656 | for (i = 0; i < nrects; i++) { |
| 657 | struct weston_vector vec1 = {{ |
| 658 | src_rects[i].x1, src_rects[i].y1, 0, 1 |
| 659 | }}; |
| 660 | weston_matrix_transform(matrix, &vec1); |
| 661 | vec1.f[0] /= vec1.f[3]; |
| 662 | vec1.f[1] /= vec1.f[3]; |
| 663 | |
| 664 | struct weston_vector vec2 = {{ |
| 665 | src_rects[i].x2, src_rects[i].y2, 0, 1 |
| 666 | }}; |
| 667 | weston_matrix_transform(matrix, &vec2); |
| 668 | vec2.f[0] /= vec2.f[3]; |
| 669 | vec2.f[1] /= vec2.f[3]; |
| 670 | |
| 671 | if (vec1.f[0] < vec2.f[0]) { |
| 672 | dest_rects[i].x1 = floor(vec1.f[0]); |
| 673 | dest_rects[i].x2 = ceil(vec2.f[0]); |
| 674 | } else { |
| 675 | dest_rects[i].x1 = floor(vec2.f[0]); |
| 676 | dest_rects[i].x2 = ceil(vec1.f[0]); |
| 677 | } |
| 678 | |
Derek Foreman | bc9a61c | 2015-11-18 16:32:30 -0600 | [diff] [blame] | 679 | if (vec1.f[1] < vec2.f[1]) { |
| 680 | dest_rects[i].y1 = floor(vec1.f[1]); |
| 681 | dest_rects[i].y2 = ceil(vec2.f[1]); |
| 682 | } else { |
| 683 | dest_rects[i].y1 = floor(vec2.f[1]); |
| 684 | dest_rects[i].y2 = ceil(vec1.f[1]); |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | pixman_region32_clear(dest); |
| 689 | pixman_region32_init_rects(dest, dest_rects, nrects); |
| 690 | free(dest_rects); |
| 691 | } |
| 692 | |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 693 | WL_EXPORT void |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 694 | weston_transformed_region(int width, int height, |
| 695 | enum wl_output_transform transform, |
| 696 | int32_t scale, |
| 697 | pixman_region32_t *src, pixman_region32_t *dest) |
| 698 | { |
| 699 | pixman_box32_t *src_rects, *dest_rects; |
| 700 | int nrects, i; |
| 701 | |
| 702 | if (transform == WL_OUTPUT_TRANSFORM_NORMAL && scale == 1) { |
| 703 | if (src != dest) |
| 704 | pixman_region32_copy(dest, src); |
| 705 | return; |
| 706 | } |
| 707 | |
| 708 | src_rects = pixman_region32_rectangles(src, &nrects); |
| 709 | dest_rects = malloc(nrects * sizeof(*dest_rects)); |
| 710 | if (!dest_rects) |
| 711 | return; |
| 712 | |
| 713 | if (transform == WL_OUTPUT_TRANSFORM_NORMAL) { |
| 714 | memcpy(dest_rects, src_rects, nrects * sizeof(*dest_rects)); |
| 715 | } else { |
| 716 | for (i = 0; i < nrects; i++) { |
| 717 | switch (transform) { |
| 718 | default: |
| 719 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 720 | dest_rects[i].x1 = src_rects[i].x1; |
| 721 | dest_rects[i].y1 = src_rects[i].y1; |
| 722 | dest_rects[i].x2 = src_rects[i].x2; |
| 723 | dest_rects[i].y2 = src_rects[i].y2; |
| 724 | break; |
| 725 | case WL_OUTPUT_TRANSFORM_90: |
| 726 | dest_rects[i].x1 = height - src_rects[i].y2; |
| 727 | dest_rects[i].y1 = src_rects[i].x1; |
| 728 | dest_rects[i].x2 = height - src_rects[i].y1; |
| 729 | dest_rects[i].y2 = src_rects[i].x2; |
| 730 | break; |
| 731 | case WL_OUTPUT_TRANSFORM_180: |
| 732 | dest_rects[i].x1 = width - src_rects[i].x2; |
| 733 | dest_rects[i].y1 = height - src_rects[i].y2; |
| 734 | dest_rects[i].x2 = width - src_rects[i].x1; |
| 735 | dest_rects[i].y2 = height - src_rects[i].y1; |
| 736 | break; |
| 737 | case WL_OUTPUT_TRANSFORM_270: |
| 738 | dest_rects[i].x1 = src_rects[i].y1; |
| 739 | dest_rects[i].y1 = width - src_rects[i].x2; |
| 740 | dest_rects[i].x2 = src_rects[i].y2; |
| 741 | dest_rects[i].y2 = width - src_rects[i].x1; |
| 742 | break; |
| 743 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 744 | dest_rects[i].x1 = width - src_rects[i].x2; |
| 745 | dest_rects[i].y1 = src_rects[i].y1; |
| 746 | dest_rects[i].x2 = width - src_rects[i].x1; |
| 747 | dest_rects[i].y2 = src_rects[i].y2; |
| 748 | break; |
| 749 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 750 | dest_rects[i].x1 = height - src_rects[i].y2; |
| 751 | dest_rects[i].y1 = width - src_rects[i].x2; |
| 752 | dest_rects[i].x2 = height - src_rects[i].y1; |
| 753 | dest_rects[i].y2 = width - src_rects[i].x1; |
| 754 | break; |
| 755 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 756 | dest_rects[i].x1 = src_rects[i].x1; |
| 757 | dest_rects[i].y1 = height - src_rects[i].y2; |
| 758 | dest_rects[i].x2 = src_rects[i].x2; |
| 759 | dest_rects[i].y2 = height - src_rects[i].y1; |
| 760 | break; |
| 761 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 762 | dest_rects[i].x1 = src_rects[i].y1; |
| 763 | dest_rects[i].y1 = src_rects[i].x1; |
| 764 | dest_rects[i].x2 = src_rects[i].y2; |
| 765 | dest_rects[i].y2 = src_rects[i].x2; |
| 766 | break; |
| 767 | } |
| 768 | } |
| 769 | } |
| 770 | |
| 771 | if (scale != 1) { |
| 772 | for (i = 0; i < nrects; i++) { |
| 773 | dest_rects[i].x1 *= scale; |
| 774 | dest_rects[i].x2 *= scale; |
| 775 | dest_rects[i].y1 *= scale; |
| 776 | dest_rects[i].y2 *= scale; |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | pixman_region32_clear(dest); |
| 781 | pixman_region32_init_rects(dest, dest_rects, nrects); |
| 782 | free(dest_rects); |
| 783 | } |
| 784 | |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 785 | static void |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 786 | viewport_surface_to_buffer(struct weston_surface *surface, |
| 787 | float sx, float sy, float *bx, float *by) |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 788 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 789 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 790 | double src_width, src_height; |
| 791 | double src_x, src_y; |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 792 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 793 | if (vp->buffer.src_width == wl_fixed_from_int(-1)) { |
| 794 | if (vp->surface.width == -1) { |
| 795 | *bx = sx; |
| 796 | *by = sy; |
| 797 | return; |
| 798 | } |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 799 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 800 | src_x = 0.0; |
| 801 | src_y = 0.0; |
| 802 | src_width = surface->width_from_buffer; |
| 803 | src_height = surface->height_from_buffer; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 804 | } else { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 805 | src_x = wl_fixed_to_double(vp->buffer.src_x); |
| 806 | src_y = wl_fixed_to_double(vp->buffer.src_y); |
| 807 | src_width = wl_fixed_to_double(vp->buffer.src_width); |
| 808 | src_height = wl_fixed_to_double(vp->buffer.src_height); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 809 | } |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 810 | |
| 811 | *bx = sx * src_width / surface->width + src_x; |
| 812 | *by = sy * src_height / surface->height + src_y; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 813 | } |
| 814 | |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 815 | WL_EXPORT void |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 816 | weston_surface_to_buffer_float(struct weston_surface *surface, |
| 817 | float sx, float sy, float *bx, float *by) |
| 818 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 819 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
| 820 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 821 | /* first transform coordinates if the viewport is set */ |
| 822 | viewport_surface_to_buffer(surface, sx, sy, bx, by); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 823 | |
Jason Ekstrand | d0cebc3 | 2014-04-21 20:56:46 -0500 | [diff] [blame] | 824 | weston_transformed_coord(surface->width_from_buffer, |
| 825 | surface->height_from_buffer, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 826 | vp->buffer.transform, vp->buffer.scale, |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 827 | *bx, *by, bx, by); |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 828 | } |
| 829 | |
Derek Foreman | 9973967 | 2015-12-03 16:38:11 -0600 | [diff] [blame] | 830 | /** Transform a rectangle from surface coordinates to buffer coordinates |
| 831 | * |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 832 | * \param surface The surface to fetch wp_viewport and buffer transformation |
Derek Foreman | 9973967 | 2015-12-03 16:38:11 -0600 | [diff] [blame] | 833 | * from. |
| 834 | * \param rect The rectangle to transform. |
| 835 | * \return The transformed rectangle. |
| 836 | * |
| 837 | * Viewport and buffer transformations can only do translation, scaling, |
| 838 | * and rotations in 90-degree steps. Therefore the only loss in the |
| 839 | * conversion is coordinate rounding. |
| 840 | * |
| 841 | * However, some coordinate rounding takes place as an intermediate |
| 842 | * step before the buffer scale factor is applied, so the rectangle |
| 843 | * boundary may not be exactly as expected. |
| 844 | * |
| 845 | * This is OK for damage tracking since a little extra coverage is |
| 846 | * not a problem. |
| 847 | */ |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 848 | WL_EXPORT pixman_box32_t |
| 849 | weston_surface_to_buffer_rect(struct weston_surface *surface, |
| 850 | pixman_box32_t rect) |
| 851 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 852 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 853 | float xf, yf; |
| 854 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 855 | /* first transform box coordinates if the viewport is set */ |
| 856 | viewport_surface_to_buffer(surface, rect.x1, rect.y1, &xf, &yf); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 857 | rect.x1 = floorf(xf); |
| 858 | rect.y1 = floorf(yf); |
| 859 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 860 | viewport_surface_to_buffer(surface, rect.x2, rect.y2, &xf, &yf); |
Derek Foreman | e2e15ac | 2015-12-01 13:00:43 -0600 | [diff] [blame] | 861 | rect.x2 = ceilf(xf); |
| 862 | rect.y2 = ceilf(yf); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 863 | |
Jason Ekstrand | d0cebc3 | 2014-04-21 20:56:46 -0500 | [diff] [blame] | 864 | return weston_transformed_rect(surface->width_from_buffer, |
| 865 | surface->height_from_buffer, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 866 | vp->buffer.transform, vp->buffer.scale, |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 867 | rect); |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 868 | } |
| 869 | |
Pekka Paalanen | e54e31c | 2015-03-04 14:23:28 +0200 | [diff] [blame] | 870 | /** Transform a region from surface coordinates to buffer coordinates |
| 871 | * |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 872 | * \param surface The surface to fetch wp_viewport and buffer transformation |
Pekka Paalanen | e54e31c | 2015-03-04 14:23:28 +0200 | [diff] [blame] | 873 | * from. |
| 874 | * \param surface_region[in] The region in surface coordinates. |
| 875 | * \param buffer_region[out] The region converted to buffer coordinates. |
| 876 | * |
| 877 | * Buffer_region must be init'd, but will be completely overwritten. |
| 878 | * |
| 879 | * Viewport and buffer transformations can only do translation, scaling, |
| 880 | * and rotations in 90-degree steps. Therefore the only loss in the |
Derek Foreman | 9973967 | 2015-12-03 16:38:11 -0600 | [diff] [blame] | 881 | * conversion is from the coordinate rounding that takes place in |
| 882 | * \ref weston_surface_to_buffer_rect. |
Pekka Paalanen | e54e31c | 2015-03-04 14:23:28 +0200 | [diff] [blame] | 883 | */ |
| 884 | WL_EXPORT void |
| 885 | weston_surface_to_buffer_region(struct weston_surface *surface, |
| 886 | pixman_region32_t *surface_region, |
| 887 | pixman_region32_t *buffer_region) |
| 888 | { |
| 889 | pixman_box32_t *src_rects, *dest_rects; |
| 890 | int nrects, i; |
| 891 | |
| 892 | src_rects = pixman_region32_rectangles(surface_region, &nrects); |
| 893 | dest_rects = malloc(nrects * sizeof(*dest_rects)); |
| 894 | if (!dest_rects) |
| 895 | return; |
| 896 | |
| 897 | for (i = 0; i < nrects; i++) { |
| 898 | dest_rects[i] = weston_surface_to_buffer_rect(surface, |
| 899 | src_rects[i]); |
| 900 | } |
| 901 | |
| 902 | pixman_region32_fini(buffer_region); |
| 903 | pixman_region32_init_rects(buffer_region, dest_rects, nrects); |
| 904 | free(dest_rects); |
| 905 | } |
| 906 | |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 907 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 908 | weston_view_move_to_plane(struct weston_view *view, |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 909 | struct weston_plane *plane) |
| 910 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 911 | if (view->plane == plane) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 912 | return; |
| 913 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 914 | weston_view_damage_below(view); |
| 915 | view->plane = plane; |
| 916 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 917 | } |
| 918 | |
Pekka Paalanen | 51723d5 | 2015-02-17 13:10:01 +0200 | [diff] [blame] | 919 | /** Inflict damage on the plane where the view is visible. |
| 920 | * |
| 921 | * \param view The view that causes the damage. |
| 922 | * |
| 923 | * If the view is currently on a plane (including the primary plane), |
| 924 | * take the view's boundingbox, subtract all the opaque views that cover it, |
| 925 | * and add the remaining region as damage to the plane. This corresponds |
| 926 | * to the damage inflicted to the plane if this view disappeared. |
| 927 | * |
| 928 | * A repaint is scheduled for this view. |
| 929 | * |
| 930 | * The region of all opaque views covering this view is stored in |
| 931 | * weston_view::clip and updated by view_accumulate_damage() during |
| 932 | * weston_output_repaint(). Specifically, that region matches the |
| 933 | * scenegraph as it was last painted. |
| 934 | */ |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 935 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 936 | weston_view_damage_below(struct weston_view *view) |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 937 | { |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 938 | pixman_region32_t damage; |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 939 | |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 940 | pixman_region32_init(&damage); |
Pekka Paalanen | 25c0ca5 | 2015-02-19 11:15:33 +0200 | [diff] [blame] | 941 | pixman_region32_subtract(&damage, &view->transform.boundingbox, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 942 | &view->clip); |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 943 | if (view->plane) |
| 944 | pixman_region32_union(&view->plane->damage, |
| 945 | &view->plane->damage, &damage); |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 946 | pixman_region32_fini(&damage); |
Kristian Høgsberg | a3a784a | 2013-11-13 21:33:43 -0800 | [diff] [blame] | 947 | weston_view_schedule_repaint(view); |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 948 | } |
| 949 | |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 950 | /** Send wl_surface.enter/leave events |
| 951 | * |
| 952 | * \param surface The surface. |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 953 | * \param head A head of the entered/left output. |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 954 | * \param enter True if entered. |
| 955 | * \param left True if left. |
| 956 | * |
| 957 | * Send the enter/leave events for all protocol objects bound to the given |
| 958 | * output by the client owning the surface. |
| 959 | */ |
| 960 | static void |
| 961 | weston_surface_send_enter_leave(struct weston_surface *surface, |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 962 | struct weston_head *head, |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 963 | bool enter, |
| 964 | bool leave) |
| 965 | { |
| 966 | struct wl_resource *wloutput; |
| 967 | struct wl_client *client; |
| 968 | |
| 969 | assert(enter != leave); |
| 970 | |
| 971 | client = wl_resource_get_client(surface->resource); |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 972 | wl_resource_for_each(wloutput, &head->resource_list) { |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 973 | if (wl_resource_get_client(wloutput) != client) |
| 974 | continue; |
| 975 | |
| 976 | if (enter) |
| 977 | wl_surface_send_enter(surface->resource, wloutput); |
| 978 | if (leave) |
| 979 | wl_surface_send_leave(surface->resource, wloutput); |
| 980 | } |
| 981 | } |
| 982 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 983 | /** |
| 984 | * \param es The surface |
| 985 | * \param mask The new set of outputs for the surface |
| 986 | * |
| 987 | * Sets the surface's set of outputs to the ones specified by |
| 988 | * the new output mask provided. Identifies the outputs that |
| 989 | * have changed, the posts enter and leave events for these |
| 990 | * outputs as appropriate. |
| 991 | */ |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 992 | static void |
| 993 | weston_surface_update_output_mask(struct weston_surface *es, uint32_t mask) |
| 994 | { |
| 995 | uint32_t different = es->output_mask ^ mask; |
| 996 | uint32_t entered = mask & different; |
| 997 | uint32_t left = es->output_mask & different; |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 998 | uint32_t output_bit; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 999 | struct weston_output *output; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 1000 | struct weston_head *head; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1001 | |
| 1002 | es->output_mask = mask; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1003 | if (es->resource == NULL) |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1004 | return; |
| 1005 | if (different == 0) |
| 1006 | return; |
| 1007 | |
| 1008 | wl_list_for_each(output, &es->compositor->output_list, link) { |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1009 | output_bit = 1u << output->id; |
| 1010 | if (!(output_bit & different)) |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1011 | continue; |
Pekka Paalanen | 01e0068 | 2017-03-24 16:21:06 +0200 | [diff] [blame] | 1012 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 1013 | wl_list_for_each(head, &output->head_list, output_link) { |
| 1014 | weston_surface_send_enter_leave(es, head, |
| 1015 | output_bit & entered, |
| 1016 | output_bit & left); |
| 1017 | } |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1018 | } |
| 1019 | } |
| 1020 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1021 | /** Recalculate which output(s) the surface has views displayed on |
| 1022 | * |
| 1023 | * \param es The surface to remap to outputs |
| 1024 | * |
| 1025 | * Finds the output that is showing the largest amount of one |
| 1026 | * of the surface's various views. This output becomes the |
Pekka Paalanen | 130ae6e | 2016-03-30 14:33:33 +0300 | [diff] [blame] | 1027 | * surface's primary output for vsync and frame callback purposes. |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1028 | * |
Pekka Paalanen | 130ae6e | 2016-03-30 14:33:33 +0300 | [diff] [blame] | 1029 | * Also notes all outputs of all of the surface's views |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1030 | * in the output_mask for the surface. |
| 1031 | */ |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1032 | static void |
| 1033 | weston_surface_assign_output(struct weston_surface *es) |
| 1034 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1035 | struct weston_output *new_output; |
| 1036 | struct weston_view *view; |
| 1037 | pixman_region32_t region; |
| 1038 | uint32_t max, area, mask; |
| 1039 | pixman_box32_t *e; |
| 1040 | |
| 1041 | new_output = NULL; |
| 1042 | max = 0; |
| 1043 | mask = 0; |
| 1044 | pixman_region32_init(®ion); |
| 1045 | wl_list_for_each(view, &es->views, surface_link) { |
| 1046 | if (!view->output) |
| 1047 | continue; |
| 1048 | |
| 1049 | pixman_region32_intersect(®ion, &view->transform.boundingbox, |
| 1050 | &view->output->region); |
| 1051 | |
| 1052 | e = pixman_region32_extents(®ion); |
| 1053 | area = (e->x2 - e->x1) * (e->y2 - e->y1); |
| 1054 | |
| 1055 | mask |= view->output_mask; |
| 1056 | |
| 1057 | if (area >= max) { |
| 1058 | new_output = view->output; |
| 1059 | max = area; |
| 1060 | } |
| 1061 | } |
| 1062 | pixman_region32_fini(®ion); |
| 1063 | |
| 1064 | es->output = new_output; |
| 1065 | weston_surface_update_output_mask(es, mask); |
| 1066 | } |
| 1067 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1068 | /** Recalculate which output(s) the view is displayed on |
| 1069 | * |
| 1070 | * \param ev The view to remap to outputs |
| 1071 | * |
| 1072 | * Identifies the set of outputs that the view is visible on, |
| 1073 | * noting them into the output_mask. The output that the view |
Pekka Paalanen | 130ae6e | 2016-03-30 14:33:33 +0300 | [diff] [blame] | 1074 | * is most visible on is set as the view's primary output. |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1075 | * |
| 1076 | * Also does the same for the view's surface. See |
| 1077 | * weston_surface_assign_output(). |
| 1078 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1079 | static void |
| 1080 | weston_view_assign_output(struct weston_view *ev) |
| 1081 | { |
| 1082 | struct weston_compositor *ec = ev->surface->compositor; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1083 | struct weston_output *output, *new_output; |
| 1084 | pixman_region32_t region; |
| 1085 | uint32_t max, area, mask; |
| 1086 | pixman_box32_t *e; |
| 1087 | |
| 1088 | new_output = NULL; |
| 1089 | max = 0; |
| 1090 | mask = 0; |
| 1091 | pixman_region32_init(®ion); |
| 1092 | wl_list_for_each(output, &ec->output_list, link) { |
Giulio Camuffo | 2f2a70c | 2015-07-12 10:52:32 +0300 | [diff] [blame] | 1093 | if (output->destroying) |
| 1094 | continue; |
| 1095 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1096 | pixman_region32_intersect(®ion, &ev->transform.boundingbox, |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1097 | &output->region); |
| 1098 | |
| 1099 | e = pixman_region32_extents(®ion); |
| 1100 | area = (e->x2 - e->x1) * (e->y2 - e->y1); |
| 1101 | |
| 1102 | if (area > 0) |
Bryce Harrington | 89324ce | 2015-12-23 18:38:07 -0800 | [diff] [blame] | 1103 | mask |= 1u << output->id; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1104 | |
| 1105 | if (area >= max) { |
| 1106 | new_output = output; |
| 1107 | max = area; |
| 1108 | } |
| 1109 | } |
| 1110 | pixman_region32_fini(®ion); |
| 1111 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1112 | ev->output = new_output; |
| 1113 | ev->output_mask = mask; |
| 1114 | |
| 1115 | weston_surface_assign_output(ev->surface); |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1116 | } |
| 1117 | |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 1118 | static void |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1119 | weston_view_to_view_map(struct weston_view *from, struct weston_view *to, |
| 1120 | int from_x, int from_y, int *to_x, int *to_y) |
| 1121 | { |
| 1122 | float x, y; |
| 1123 | |
| 1124 | weston_view_to_global_float(from, from_x, from_y, &x, &y); |
| 1125 | weston_view_from_global_float(to, x, y, &x, &y); |
| 1126 | |
| 1127 | *to_x = round(x); |
| 1128 | *to_y = round(y); |
| 1129 | } |
| 1130 | |
| 1131 | static void |
| 1132 | weston_view_transfer_scissor(struct weston_view *from, struct weston_view *to) |
| 1133 | { |
| 1134 | pixman_box32_t *a; |
| 1135 | pixman_box32_t b; |
| 1136 | |
| 1137 | a = pixman_region32_extents(&from->geometry.scissor); |
| 1138 | |
| 1139 | weston_view_to_view_map(from, to, a->x1, a->y1, &b.x1, &b.y1); |
| 1140 | weston_view_to_view_map(from, to, a->x2, a->y2, &b.x2, &b.y2); |
| 1141 | |
| 1142 | pixman_region32_fini(&to->geometry.scissor); |
| 1143 | pixman_region32_init_with_extents(&to->geometry.scissor, &b); |
| 1144 | } |
| 1145 | |
| 1146 | static void |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 1147 | view_compute_bbox(struct weston_view *view, const pixman_box32_t *inbox, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1148 | pixman_region32_t *bbox) |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1149 | { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1150 | float min_x = HUGE_VALF, min_y = HUGE_VALF; |
| 1151 | float max_x = -HUGE_VALF, max_y = -HUGE_VALF; |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1152 | int32_t s[4][2] = { |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 1153 | { inbox->x1, inbox->y1 }, |
| 1154 | { inbox->x1, inbox->y2 }, |
| 1155 | { inbox->x2, inbox->y1 }, |
| 1156 | { inbox->x2, inbox->y2 }, |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1157 | }; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1158 | float int_x, int_y; |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1159 | int i; |
| 1160 | |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 1161 | if (inbox->x1 == inbox->x2 || inbox->y1 == inbox->y2) { |
Pekka Paalanen | 7c7d464 | 2012-09-04 13:55:44 +0300 | [diff] [blame] | 1162 | /* avoid rounding empty bbox to 1x1 */ |
| 1163 | pixman_region32_init(bbox); |
| 1164 | return; |
| 1165 | } |
| 1166 | |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1167 | for (i = 0; i < 4; ++i) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1168 | float x, y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1169 | 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] | 1170 | if (x < min_x) |
| 1171 | min_x = x; |
| 1172 | if (x > max_x) |
| 1173 | max_x = x; |
| 1174 | if (y < min_y) |
| 1175 | min_y = y; |
| 1176 | if (y > max_y) |
| 1177 | max_y = y; |
| 1178 | } |
| 1179 | |
Pekka Paalanen | 219b982 | 2012-02-08 15:38:37 +0200 | [diff] [blame] | 1180 | int_x = floorf(min_x); |
| 1181 | int_y = floorf(min_y); |
| 1182 | pixman_region32_init_rect(bbox, int_x, int_y, |
| 1183 | ceilf(max_x) - int_x, ceilf(max_y) - int_y); |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1184 | } |
| 1185 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1186 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1187 | weston_view_update_transform_disable(struct weston_view *view) |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1188 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1189 | view->transform.enabled = 0; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1190 | |
Pekka Paalanen | cc2f868 | 2012-02-13 10:34:04 +0200 | [diff] [blame] | 1191 | /* round off fractions when not transformed */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1192 | view->geometry.x = roundf(view->geometry.x); |
| 1193 | view->geometry.y = roundf(view->geometry.y); |
Pekka Paalanen | cc2f868 | 2012-02-13 10:34:04 +0200 | [diff] [blame] | 1194 | |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1195 | /* Otherwise identity matrix, but with x and y translation. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1196 | view->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE; |
| 1197 | view->transform.position.matrix.d[12] = view->geometry.x; |
| 1198 | view->transform.position.matrix.d[13] = view->geometry.y; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1199 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1200 | view->transform.matrix = view->transform.position.matrix; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1201 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1202 | view->transform.inverse = view->transform.position.matrix; |
| 1203 | view->transform.inverse.d[12] = -view->geometry.x; |
| 1204 | view->transform.inverse.d[13] = -view->geometry.y; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1205 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1206 | pixman_region32_init_rect(&view->transform.boundingbox, |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1207 | 0, 0, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1208 | view->surface->width, |
| 1209 | view->surface->height); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1210 | if (view->geometry.scissor_enabled) |
| 1211 | pixman_region32_intersect(&view->transform.boundingbox, |
| 1212 | &view->transform.boundingbox, |
| 1213 | &view->geometry.scissor); |
| 1214 | |
| 1215 | pixman_region32_translate(&view->transform.boundingbox, |
| 1216 | view->geometry.x, view->geometry.y); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1217 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1218 | if (view->alpha == 1.0) { |
| 1219 | pixman_region32_copy(&view->transform.opaque, |
| 1220 | &view->surface->opaque); |
| 1221 | pixman_region32_translate(&view->transform.opaque, |
| 1222 | view->geometry.x, |
| 1223 | view->geometry.y); |
Kristian Høgsberg | 3b4af20 | 2012-02-28 09:19:39 -0500 | [diff] [blame] | 1224 | } |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | static int |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1228 | weston_view_update_transform_enable(struct weston_view *view) |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1229 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1230 | struct weston_view *parent = view->geometry.parent; |
| 1231 | struct weston_matrix *matrix = &view->transform.matrix; |
| 1232 | struct weston_matrix *inverse = &view->transform.inverse; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1233 | struct weston_transform *tform; |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1234 | pixman_region32_t surfregion; |
| 1235 | const pixman_box32_t *surfbox; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1236 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1237 | view->transform.enabled = 1; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1238 | |
| 1239 | /* Otherwise identity matrix, but with x and y translation. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1240 | view->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE; |
| 1241 | view->transform.position.matrix.d[12] = view->geometry.x; |
| 1242 | view->transform.position.matrix.d[13] = view->geometry.y; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1243 | |
| 1244 | weston_matrix_init(matrix); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1245 | wl_list_for_each(tform, &view->geometry.transformation_list, link) |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1246 | weston_matrix_multiply(matrix, &tform->matrix); |
| 1247 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1248 | if (parent) |
| 1249 | weston_matrix_multiply(matrix, &parent->transform.matrix); |
| 1250 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1251 | if (weston_matrix_invert(inverse, matrix) < 0) { |
| 1252 | /* Oops, bad total transformation, not invertible */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1253 | weston_log("error: weston_view %p" |
| 1254 | " transformation not invertible.\n", view); |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1255 | return -1; |
| 1256 | } |
| 1257 | |
Giulio Camuffo | 148c199 | 2016-09-04 18:50:46 +0300 | [diff] [blame] | 1258 | if (view->alpha == 1.0 && |
| 1259 | matrix->type == WESTON_MATRIX_TRANSFORM_TRANSLATE) { |
| 1260 | pixman_region32_copy(&view->transform.opaque, |
| 1261 | &view->surface->opaque); |
| 1262 | pixman_region32_translate(&view->transform.opaque, |
| 1263 | matrix->d[12], |
| 1264 | matrix->d[13]); |
| 1265 | } |
| 1266 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1267 | pixman_region32_init_rect(&surfregion, 0, 0, |
| 1268 | view->surface->width, view->surface->height); |
| 1269 | if (view->geometry.scissor_enabled) |
| 1270 | pixman_region32_intersect(&surfregion, &surfregion, |
| 1271 | &view->geometry.scissor); |
| 1272 | surfbox = pixman_region32_extents(&surfregion); |
| 1273 | |
| 1274 | view_compute_bbox(view, surfbox, &view->transform.boundingbox); |
| 1275 | pixman_region32_fini(&surfregion); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1276 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1277 | return 0; |
| 1278 | } |
| 1279 | |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1280 | static struct weston_layer * |
| 1281 | get_view_layer(struct weston_view *view) |
| 1282 | { |
| 1283 | if (view->parent_view) |
| 1284 | return get_view_layer(view->parent_view); |
| 1285 | return view->layer_link.layer; |
| 1286 | } |
| 1287 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1288 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1289 | weston_view_update_transform(struct weston_view *view) |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1290 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1291 | struct weston_view *parent = view->geometry.parent; |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1292 | struct weston_layer *layer; |
| 1293 | pixman_region32_t mask; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1294 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1295 | if (!view->transform.dirty) |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1296 | return; |
| 1297 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1298 | if (parent) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1299 | weston_view_update_transform(parent); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1300 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1301 | view->transform.dirty = 0; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1302 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1303 | weston_view_damage_below(view); |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 1304 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1305 | pixman_region32_fini(&view->transform.boundingbox); |
| 1306 | pixman_region32_fini(&view->transform.opaque); |
| 1307 | pixman_region32_init(&view->transform.opaque); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1308 | |
Pekka Paalanen | cd40362 | 2012-01-25 13:37:39 +0200 | [diff] [blame] | 1309 | /* transform.position is always in transformation_list */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1310 | if (view->geometry.transformation_list.next == |
| 1311 | &view->transform.position.link && |
| 1312 | view->geometry.transformation_list.prev == |
| 1313 | &view->transform.position.link && |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1314 | !parent) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1315 | weston_view_update_transform_disable(view); |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1316 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1317 | if (weston_view_update_transform_enable(view) < 0) |
| 1318 | weston_view_update_transform_disable(view); |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1319 | } |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 1320 | |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1321 | layer = get_view_layer(view); |
| 1322 | if (layer) { |
| 1323 | pixman_region32_init_with_extents(&mask, &layer->mask); |
Pekka Paalanen | 25c0ca5 | 2015-02-19 11:15:33 +0200 | [diff] [blame] | 1324 | pixman_region32_intersect(&view->transform.boundingbox, |
| 1325 | &view->transform.boundingbox, &mask); |
Pekka Paalanen | 8844bf2 | 2015-02-18 16:30:47 +0200 | [diff] [blame] | 1326 | pixman_region32_intersect(&view->transform.opaque, |
| 1327 | &view->transform.opaque, &mask); |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1328 | pixman_region32_fini(&mask); |
| 1329 | } |
| 1330 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1331 | if (parent) { |
| 1332 | if (parent->geometry.scissor_enabled) { |
| 1333 | view->geometry.scissor_enabled = true; |
| 1334 | weston_view_transfer_scissor(parent, view); |
| 1335 | } else { |
| 1336 | view->geometry.scissor_enabled = false; |
| 1337 | } |
| 1338 | } |
| 1339 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1340 | weston_view_damage_below(view); |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 1341 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1342 | weston_view_assign_output(view); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 1343 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1344 | wl_signal_emit(&view->surface->compositor->transform_signal, |
| 1345 | view->surface); |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1346 | } |
| 1347 | |
Pekka Paalanen | ddae03c | 2012-02-06 14:54:20 +0200 | [diff] [blame] | 1348 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1349 | weston_view_geometry_dirty(struct weston_view *view) |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 1350 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1351 | struct weston_view *child; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1352 | |
| 1353 | /* |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1354 | * The invariant: if view->geometry.dirty, then all views |
| 1355 | * in view->geometry.child_list have geometry.dirty too. |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1356 | * Corollary: if not parent->geometry.dirty, then all ancestors |
| 1357 | * are not dirty. |
| 1358 | */ |
| 1359 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1360 | if (view->transform.dirty) |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1361 | return; |
| 1362 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1363 | view->transform.dirty = 1; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1364 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1365 | wl_list_for_each(child, &view->geometry.child_list, |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1366 | geometry.parent_link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1367 | weston_view_geometry_dirty(child); |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 1368 | } |
| 1369 | |
| 1370 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1371 | weston_view_to_global_fixed(struct weston_view *view, |
| 1372 | wl_fixed_t vx, wl_fixed_t vy, |
| 1373 | wl_fixed_t *x, wl_fixed_t *y) |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1374 | { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1375 | float xf, yf; |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1376 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1377 | weston_view_to_global_float(view, |
| 1378 | wl_fixed_to_double(vx), |
| 1379 | wl_fixed_to_double(vy), |
| 1380 | &xf, &yf); |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1381 | *x = wl_fixed_from_double(xf); |
| 1382 | *y = wl_fixed_from_double(yf); |
| 1383 | } |
| 1384 | |
Kristian Høgsberg | ecf6ede | 2012-09-05 21:59:35 -0400 | [diff] [blame] | 1385 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1386 | weston_view_from_global_float(struct weston_view *view, |
| 1387 | float x, float y, float *vx, float *vy) |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1388 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1389 | if (view->transform.enabled) { |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1390 | struct weston_vector v = { { x, y, 0.0f, 1.0f } }; |
| 1391 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1392 | weston_matrix_transform(&view->transform.inverse, &v); |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1393 | |
| 1394 | if (fabsf(v.f[3]) < 1e-6) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1395 | weston_log("warning: numerical instability in " |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1396 | "weston_view_from_global(), divisor = %g\n", |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1397 | v.f[3]); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1398 | *vx = 0; |
| 1399 | *vy = 0; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1400 | return; |
| 1401 | } |
| 1402 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1403 | *vx = v.f[0] / v.f[3]; |
| 1404 | *vy = v.f[1] / v.f[3]; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1405 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1406 | *vx = x - view->geometry.x; |
| 1407 | *vy = y - view->geometry.y; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1408 | } |
| 1409 | } |
| 1410 | |
| 1411 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1412 | weston_view_from_global_fixed(struct weston_view *view, |
| 1413 | wl_fixed_t x, wl_fixed_t y, |
| 1414 | wl_fixed_t *vx, wl_fixed_t *vy) |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1415 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1416 | float vxf, vyf; |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1417 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1418 | weston_view_from_global_float(view, |
| 1419 | wl_fixed_to_double(x), |
| 1420 | wl_fixed_to_double(y), |
| 1421 | &vxf, &vyf); |
| 1422 | *vx = wl_fixed_from_double(vxf); |
| 1423 | *vy = wl_fixed_from_double(vyf); |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1427 | weston_view_from_global(struct weston_view *view, |
| 1428 | int32_t x, int32_t y, int32_t *vx, int32_t *vy) |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1429 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1430 | float vxf, vyf; |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1431 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1432 | weston_view_from_global_float(view, x, y, &vxf, &vyf); |
| 1433 | *vx = floorf(vxf); |
| 1434 | *vy = floorf(vyf); |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1435 | } |
| 1436 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1437 | /** |
| 1438 | * \param surface The surface to be repainted |
| 1439 | * |
| 1440 | * Marks the output(s) that the surface is shown on as needing to be |
| 1441 | * repainted. See weston_output_schedule_repaint(). |
| 1442 | */ |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1443 | WL_EXPORT void |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1444 | weston_surface_schedule_repaint(struct weston_surface *surface) |
| 1445 | { |
| 1446 | struct weston_output *output; |
| 1447 | |
| 1448 | wl_list_for_each(output, &surface->compositor->output_list, link) |
Bryce Harrington | 89324ce | 2015-12-23 18:38:07 -0800 | [diff] [blame] | 1449 | if (surface->output_mask & (1u << output->id)) |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1450 | weston_output_schedule_repaint(output); |
| 1451 | } |
| 1452 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1453 | /** |
| 1454 | * \param view The view to be repainted |
| 1455 | * |
| 1456 | * Marks the output(s) that the view is shown on as needing to be |
| 1457 | * repainted. See weston_output_schedule_repaint(). |
| 1458 | */ |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1459 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1460 | weston_view_schedule_repaint(struct weston_view *view) |
| 1461 | { |
| 1462 | struct weston_output *output; |
| 1463 | |
| 1464 | wl_list_for_each(output, &view->surface->compositor->output_list, link) |
Bryce Harrington | 89324ce | 2015-12-23 18:38:07 -0800 | [diff] [blame] | 1465 | if (view->output_mask & (1u << output->id)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1466 | weston_output_schedule_repaint(output); |
| 1467 | } |
| 1468 | |
Pekka Paalanen | e508ce6 | 2015-02-19 13:59:55 +0200 | [diff] [blame] | 1469 | /** |
| 1470 | * XXX: This function does it the wrong way. |
| 1471 | * surface->damage is the damage from the client, and causes |
| 1472 | * surface_flush_damage() to copy pixels. No window management action can |
| 1473 | * cause damage to the client-provided content, warranting re-upload! |
| 1474 | * |
| 1475 | * Instead of surface->damage, this function should record the damage |
| 1476 | * with all the views for this surface to avoid extraneous texture |
| 1477 | * uploads. |
| 1478 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1479 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1480 | weston_surface_damage(struct weston_surface *surface) |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 1481 | { |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1482 | pixman_region32_union_rect(&surface->damage, &surface->damage, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1483 | 0, 0, surface->width, |
| 1484 | surface->height); |
Pekka Paalanen | 2267d45 | 2012-01-26 13:12:45 +0200 | [diff] [blame] | 1485 | |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1486 | weston_surface_schedule_repaint(surface); |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 1487 | } |
| 1488 | |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 1489 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1490 | weston_view_set_position(struct weston_view *view, float x, float y) |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1491 | { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1492 | if (view->geometry.x == x && view->geometry.y == y) |
| 1493 | return; |
| 1494 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1495 | view->geometry.x = x; |
| 1496 | view->geometry.y = y; |
| 1497 | weston_view_geometry_dirty(view); |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1498 | } |
| 1499 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1500 | static void |
| 1501 | transform_parent_handle_parent_destroy(struct wl_listener *listener, |
| 1502 | void *data) |
| 1503 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1504 | struct weston_view *view = |
| 1505 | container_of(listener, struct weston_view, |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1506 | geometry.parent_destroy_listener); |
| 1507 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1508 | weston_view_set_transform_parent(view, NULL); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1509 | } |
| 1510 | |
| 1511 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1512 | weston_view_set_transform_parent(struct weston_view *view, |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1513 | struct weston_view *parent) |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1514 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1515 | if (view->geometry.parent) { |
| 1516 | wl_list_remove(&view->geometry.parent_destroy_listener.link); |
| 1517 | wl_list_remove(&view->geometry.parent_link); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1518 | |
| 1519 | if (!parent) |
| 1520 | view->geometry.scissor_enabled = false; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1521 | } |
| 1522 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1523 | view->geometry.parent = parent; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1524 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1525 | view->geometry.parent_destroy_listener.notify = |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1526 | transform_parent_handle_parent_destroy; |
| 1527 | if (parent) { |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1528 | wl_signal_add(&parent->destroy_signal, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1529 | &view->geometry.parent_destroy_listener); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1530 | wl_list_insert(&parent->geometry.child_list, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1531 | &view->geometry.parent_link); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1532 | } |
| 1533 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1534 | weston_view_geometry_dirty(view); |
| 1535 | } |
| 1536 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1537 | /** Set a clip mask rectangle on a view |
| 1538 | * |
| 1539 | * \param view The view to set the clip mask on. |
| 1540 | * \param x Top-left corner X coordinate of the clip rectangle. |
| 1541 | * \param y Top-left corner Y coordinate of the clip rectangle. |
| 1542 | * \param width Width of the clip rectangle, non-negative. |
| 1543 | * \param height Height of the clip rectangle, non-negative. |
| 1544 | * |
| 1545 | * A shell may set a clip mask rectangle on a view. Everything outside |
| 1546 | * the rectangle is cut away for input and output purposes: it is |
| 1547 | * not drawn and cannot be hit by hit-test based input like pointer |
| 1548 | * motion or touch-downs. Everything inside the rectangle will behave |
| 1549 | * normally. Clients are unaware of clipping. |
| 1550 | * |
Yong Bakos | 4c72e29 | 2016-04-28 11:59:10 -0500 | [diff] [blame] | 1551 | * The rectangle is set in surface-local coordinates. Setting a clip |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1552 | * mask rectangle does not affect the view position, the view is positioned |
| 1553 | * as it would be without a clip. The clip also does not change |
| 1554 | * weston_surface::width,height. |
| 1555 | * |
| 1556 | * The clip mask rectangle is part of transformation inheritance |
| 1557 | * (weston_view_set_transform_parent()). A clip set in the root of the |
| 1558 | * transformation inheritance tree will affect all views in the tree. |
| 1559 | * A clip can be set only on the root view. Attempting to set a clip |
| 1560 | * on view that has a transformation parent will fail. Assigning a parent |
| 1561 | * to a view that has a clip set will cause the clip to be forgotten. |
| 1562 | * |
| 1563 | * Because the clip mask is an axis-aligned rectangle, it poses restrictions |
| 1564 | * on the additional transformations in the child views. These transformations |
| 1565 | * may not rotate the coordinate axes, i.e., only translation and scaling |
| 1566 | * are allowed. Violating this restriction causes the clipping to malfunction. |
| 1567 | * Furthermore, using scaling may cause rounding errors in child clipping. |
| 1568 | * |
| 1569 | * The clip mask rectangle is not automatically adjusted based on |
| 1570 | * wl_surface.attach dx and dy arguments. |
| 1571 | * |
| 1572 | * A clip mask rectangle can be set only if the compositor capability |
| 1573 | * WESTON_CAP_VIEW_CLIP_MASK is present. |
| 1574 | * |
| 1575 | * This function sets the clip mask rectangle and schedules a repaint for |
| 1576 | * the view. |
| 1577 | */ |
| 1578 | WL_EXPORT void |
| 1579 | weston_view_set_mask(struct weston_view *view, |
| 1580 | int x, int y, int width, int height) |
| 1581 | { |
| 1582 | struct weston_compositor *compositor = view->surface->compositor; |
| 1583 | |
| 1584 | if (!(compositor->capabilities & WESTON_CAP_VIEW_CLIP_MASK)) { |
| 1585 | weston_log("%s not allowed without capability!\n", __func__); |
| 1586 | return; |
| 1587 | } |
| 1588 | |
| 1589 | if (view->geometry.parent) { |
| 1590 | weston_log("view %p has a parent, clip forbidden!\n", view); |
| 1591 | return; |
| 1592 | } |
| 1593 | |
| 1594 | if (width < 0 || height < 0) { |
| 1595 | weston_log("%s: illegal args %d, %d, %d, %d\n", __func__, |
| 1596 | x, y, width, height); |
| 1597 | return; |
| 1598 | } |
| 1599 | |
| 1600 | pixman_region32_fini(&view->geometry.scissor); |
| 1601 | pixman_region32_init_rect(&view->geometry.scissor, x, y, width, height); |
| 1602 | view->geometry.scissor_enabled = true; |
| 1603 | weston_view_geometry_dirty(view); |
| 1604 | weston_view_schedule_repaint(view); |
| 1605 | } |
| 1606 | |
| 1607 | /** Remove the clip mask from a view |
| 1608 | * |
| 1609 | * \param view The view to remove the clip mask from. |
| 1610 | * |
| 1611 | * Removed the clip mask rectangle and schedules a repaint. |
| 1612 | * |
| 1613 | * \sa weston_view_set_mask |
| 1614 | */ |
| 1615 | WL_EXPORT void |
| 1616 | weston_view_set_mask_infinite(struct weston_view *view) |
| 1617 | { |
| 1618 | view->geometry.scissor_enabled = false; |
| 1619 | weston_view_geometry_dirty(view); |
| 1620 | weston_view_schedule_repaint(view); |
| 1621 | } |
| 1622 | |
Armin Krezović | 0da12b8 | 2016-06-30 06:04:33 +0200 | [diff] [blame] | 1623 | /* Check if view should be displayed |
| 1624 | * |
| 1625 | * The indicator is set manually when assigning |
| 1626 | * a view to a surface. |
| 1627 | * |
| 1628 | * This needs reworking. See the thread starting at: |
| 1629 | * |
| 1630 | * https://lists.freedesktop.org/archives/wayland-devel/2016-June/029656.html |
| 1631 | */ |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 1632 | WL_EXPORT bool |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1633 | weston_view_is_mapped(struct weston_view *view) |
| 1634 | { |
Armin Krezović | 0da12b8 | 2016-06-30 06:04:33 +0200 | [diff] [blame] | 1635 | return view->is_mapped; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1636 | } |
| 1637 | |
Armin Krezović | 0da12b8 | 2016-06-30 06:04:33 +0200 | [diff] [blame] | 1638 | /* Check if a surface has a view assigned to it |
| 1639 | * |
| 1640 | * The indicator is set manually when mapping |
| 1641 | * a surface and creating a view for it. |
| 1642 | * |
| 1643 | * This needs to go. See the thread starting at: |
| 1644 | * |
| 1645 | * https://lists.freedesktop.org/archives/wayland-devel/2016-June/029656.html |
| 1646 | * |
| 1647 | */ |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 1648 | WL_EXPORT bool |
Ander Conselvan de Oliveira | b8ab14f | 2012-03-27 17:36:36 +0300 | [diff] [blame] | 1649 | weston_surface_is_mapped(struct weston_surface *surface) |
| 1650 | { |
Armin Krezović | 0da12b8 | 2016-06-30 06:04:33 +0200 | [diff] [blame] | 1651 | return surface->is_mapped; |
Ander Conselvan de Oliveira | b8ab14f | 2012-03-27 17:36:36 +0300 | [diff] [blame] | 1652 | } |
| 1653 | |
Pekka Paalanen | da75ee1 | 2013-11-26 18:19:43 +0100 | [diff] [blame] | 1654 | static void |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 1655 | 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] | 1656 | { |
| 1657 | struct weston_view *view; |
| 1658 | |
| 1659 | if (surface->width == width && surface->height == height) |
| 1660 | return; |
| 1661 | |
| 1662 | surface->width = width; |
| 1663 | surface->height = height; |
| 1664 | |
| 1665 | wl_list_for_each(view, &surface->views, surface_link) |
| 1666 | weston_view_geometry_dirty(view); |
| 1667 | } |
| 1668 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 1669 | WL_EXPORT void |
| 1670 | weston_surface_set_size(struct weston_surface *surface, |
| 1671 | int32_t width, int32_t height) |
| 1672 | { |
| 1673 | assert(!surface->resource); |
| 1674 | surface_set_size(surface, width, height); |
| 1675 | } |
| 1676 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1677 | static int |
| 1678 | fixed_round_up_to_int(wl_fixed_t f) |
| 1679 | { |
| 1680 | return wl_fixed_to_int(wl_fixed_from_int(1) - 1 + f); |
| 1681 | } |
| 1682 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1683 | static void |
Pekka Paalanen | 59987fa | 2016-04-26 15:50:59 +0300 | [diff] [blame] | 1684 | convert_size_by_transform_scale(int32_t *width_out, int32_t *height_out, |
| 1685 | int32_t width, int32_t height, |
| 1686 | uint32_t transform, |
| 1687 | int32_t scale) |
| 1688 | { |
| 1689 | assert(scale > 0); |
| 1690 | |
| 1691 | switch (transform) { |
| 1692 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 1693 | case WL_OUTPUT_TRANSFORM_180: |
| 1694 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 1695 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 1696 | *width_out = width / scale; |
| 1697 | *height_out = height / scale; |
| 1698 | break; |
| 1699 | case WL_OUTPUT_TRANSFORM_90: |
| 1700 | case WL_OUTPUT_TRANSFORM_270: |
| 1701 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 1702 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 1703 | *width_out = height / scale; |
| 1704 | *height_out = width / scale; |
| 1705 | break; |
| 1706 | default: |
| 1707 | assert(0 && "invalid transform"); |
| 1708 | } |
| 1709 | } |
| 1710 | |
| 1711 | static void |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1712 | weston_surface_calculate_size_from_buffer(struct weston_surface *surface) |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1713 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 1714 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Pekka Paalanen | da75ee1 | 2013-11-26 18:19:43 +0100 | [diff] [blame] | 1715 | |
| 1716 | if (!surface->buffer_ref.buffer) { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1717 | surface->width_from_buffer = 0; |
| 1718 | surface->height_from_buffer = 0; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 1719 | return; |
| 1720 | } |
| 1721 | |
Pekka Paalanen | 59987fa | 2016-04-26 15:50:59 +0300 | [diff] [blame] | 1722 | convert_size_by_transform_scale(&surface->width_from_buffer, |
| 1723 | &surface->height_from_buffer, |
| 1724 | surface->buffer_ref.buffer->width, |
| 1725 | surface->buffer_ref.buffer->height, |
| 1726 | vp->buffer.transform, |
| 1727 | vp->buffer.scale); |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1728 | } |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1729 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1730 | static void |
| 1731 | weston_surface_update_size(struct weston_surface *surface) |
| 1732 | { |
| 1733 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
| 1734 | int32_t width, height; |
| 1735 | |
| 1736 | width = surface->width_from_buffer; |
| 1737 | height = surface->height_from_buffer; |
| 1738 | |
| 1739 | if (width != 0 && vp->surface.width != -1) { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1740 | surface_set_size(surface, |
| 1741 | vp->surface.width, vp->surface.height); |
| 1742 | return; |
| 1743 | } |
| 1744 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1745 | if (width != 0 && vp->buffer.src_width != wl_fixed_from_int(-1)) { |
Pekka Paalanen | e931721 | 2014-04-04 14:22:13 +0300 | [diff] [blame] | 1746 | int32_t w = fixed_round_up_to_int(vp->buffer.src_width); |
| 1747 | int32_t h = fixed_round_up_to_int(vp->buffer.src_height); |
| 1748 | |
| 1749 | surface_set_size(surface, w ?: 1, h ?: 1); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1750 | return; |
| 1751 | } |
| 1752 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 1753 | surface_set_size(surface, width, height); |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1754 | } |
| 1755 | |
Alexandros Frantzis | 409b01f | 2017-11-16 18:21:01 +0200 | [diff] [blame] | 1756 | WL_EXPORT void |
| 1757 | weston_compositor_get_time(struct timespec *time) |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 1758 | { |
Alexandros Frantzis | 409b01f | 2017-11-16 18:21:01 +0200 | [diff] [blame] | 1759 | clock_gettime(CLOCK_REALTIME, time); |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 1760 | } |
| 1761 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1762 | WL_EXPORT struct weston_view * |
| 1763 | weston_compositor_pick_view(struct weston_compositor *compositor, |
| 1764 | wl_fixed_t x, wl_fixed_t y, |
| 1765 | wl_fixed_t *vx, wl_fixed_t *vy) |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 1766 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1767 | struct weston_view *view; |
Pekka Paalanen | fc22a52 | 2015-02-18 15:08:29 +0200 | [diff] [blame] | 1768 | wl_fixed_t view_x, view_y; |
| 1769 | int view_ix, view_iy; |
| 1770 | int ix = wl_fixed_to_int(x); |
| 1771 | int iy = wl_fixed_to_int(y); |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 1772 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1773 | wl_list_for_each(view, &compositor->view_list, link) { |
Pekka Paalanen | fc22a52 | 2015-02-18 15:08:29 +0200 | [diff] [blame] | 1774 | if (!pixman_region32_contains_point( |
| 1775 | &view->transform.boundingbox, ix, iy, NULL)) |
| 1776 | continue; |
| 1777 | |
| 1778 | weston_view_from_global_fixed(view, x, y, &view_x, &view_y); |
| 1779 | view_ix = wl_fixed_to_int(view_x); |
| 1780 | view_iy = wl_fixed_to_int(view_y); |
| 1781 | |
| 1782 | if (!pixman_region32_contains_point(&view->surface->input, |
| 1783 | view_ix, view_iy, NULL)) |
| 1784 | continue; |
| 1785 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1786 | if (view->geometry.scissor_enabled && |
| 1787 | !pixman_region32_contains_point(&view->geometry.scissor, |
| 1788 | view_ix, view_iy, NULL)) |
| 1789 | continue; |
| 1790 | |
Pekka Paalanen | fc22a52 | 2015-02-18 15:08:29 +0200 | [diff] [blame] | 1791 | *vx = view_x; |
| 1792 | *vy = view_y; |
| 1793 | return view; |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 1794 | } |
| 1795 | |
Derek Foreman | f9318d1 | 2015-05-11 15:40:11 -0500 | [diff] [blame] | 1796 | *vx = wl_fixed_from_int(-1000000); |
| 1797 | *vy = wl_fixed_from_int(-1000000); |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 1798 | return NULL; |
| 1799 | } |
| 1800 | |
| 1801 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1802 | weston_compositor_repick(struct weston_compositor *compositor) |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 1803 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1804 | struct weston_seat *seat; |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 1805 | |
Kristian Høgsberg | 10ddd97 | 2013-10-22 12:40:54 -0700 | [diff] [blame] | 1806 | if (!compositor->session_active) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1807 | return; |
| 1808 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1809 | wl_list_for_each(seat, &compositor->seat_list, link) |
Kristian Høgsberg | a71e8b2 | 2013-05-06 21:51:21 -0400 | [diff] [blame] | 1810 | weston_seat_repick(seat); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 1811 | } |
| 1812 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1813 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1814 | weston_view_unmap(struct weston_view *view) |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 1815 | { |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 1816 | struct weston_seat *seat; |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 1817 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1818 | if (!weston_view_is_mapped(view)) |
| 1819 | return; |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 1820 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1821 | weston_view_damage_below(view); |
| 1822 | view->output = NULL; |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 1823 | view->plane = NULL; |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 1824 | view->is_mapped = false; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1825 | weston_layer_entry_remove(&view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1826 | wl_list_remove(&view->link); |
| 1827 | wl_list_init(&view->link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1828 | view->output_mask = 0; |
| 1829 | weston_surface_assign_output(view->surface); |
| 1830 | |
| 1831 | if (weston_surface_is_mapped(view->surface)) |
| 1832 | return; |
| 1833 | |
| 1834 | wl_list_for_each(seat, &view->surface->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1835 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 1836 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 1837 | struct weston_keyboard *keyboard = |
| 1838 | weston_seat_get_keyboard(seat); |
| 1839 | |
| 1840 | if (keyboard && keyboard->focus == view->surface) |
| 1841 | weston_keyboard_set_focus(keyboard, NULL); |
| 1842 | if (pointer && pointer->focus == view) |
Derek Foreman | f9318d1 | 2015-05-11 15:40:11 -0500 | [diff] [blame] | 1843 | weston_pointer_clear_focus(pointer); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1844 | if (touch && touch->focus == view) |
| 1845 | weston_touch_set_focus(touch, NULL); |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 1846 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1847 | } |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 1848 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1849 | WL_EXPORT void |
| 1850 | weston_surface_unmap(struct weston_surface *surface) |
| 1851 | { |
| 1852 | struct weston_view *view; |
| 1853 | |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 1854 | surface->is_mapped = false; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1855 | wl_list_for_each(view, &surface->views, surface_link) |
| 1856 | weston_view_unmap(view); |
| 1857 | surface->output = NULL; |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 1858 | } |
| 1859 | |
Pekka Paalanen | 3c9b802 | 2014-03-14 14:38:13 +0200 | [diff] [blame] | 1860 | static void |
| 1861 | weston_surface_reset_pending_buffer(struct weston_surface *surface) |
| 1862 | { |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 1863 | weston_surface_state_set_buffer(&surface->pending, NULL); |
Pekka Paalanen | 3c9b802 | 2014-03-14 14:38:13 +0200 | [diff] [blame] | 1864 | surface->pending.sx = 0; |
| 1865 | surface->pending.sy = 0; |
| 1866 | surface->pending.newly_attached = 0; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1867 | surface->pending.buffer_viewport.changed = 0; |
Pekka Paalanen | 3c9b802 | 2014-03-14 14:38:13 +0200 | [diff] [blame] | 1868 | } |
| 1869 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1870 | WL_EXPORT void |
| 1871 | weston_view_destroy(struct weston_view *view) |
| 1872 | { |
| 1873 | wl_signal_emit(&view->destroy_signal, view); |
| 1874 | |
| 1875 | assert(wl_list_empty(&view->geometry.child_list)); |
| 1876 | |
| 1877 | if (weston_view_is_mapped(view)) { |
| 1878 | weston_view_unmap(view); |
| 1879 | weston_compositor_build_view_list(view->surface->compositor); |
| 1880 | } |
| 1881 | |
| 1882 | wl_list_remove(&view->link); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1883 | weston_layer_entry_remove(&view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1884 | |
| 1885 | pixman_region32_fini(&view->clip); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1886 | pixman_region32_fini(&view->geometry.scissor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1887 | pixman_region32_fini(&view->transform.boundingbox); |
Pekka Paalanen | 8844bf2 | 2015-02-18 16:30:47 +0200 | [diff] [blame] | 1888 | pixman_region32_fini(&view->transform.opaque); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1889 | |
| 1890 | weston_view_set_transform_parent(view, NULL); |
| 1891 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1892 | wl_list_remove(&view->surface_link); |
| 1893 | |
| 1894 | free(view); |
| 1895 | } |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1896 | |
| 1897 | WL_EXPORT void |
| 1898 | weston_surface_destroy(struct weston_surface *surface) |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 1899 | { |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 1900 | struct weston_frame_callback *cb, *next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1901 | struct weston_view *ev, *nv; |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 1902 | struct weston_pointer_constraint *constraint, *next_constraint; |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 1903 | |
Giulio Camuffo | 13b85bd | 2013-08-13 23:10:14 +0200 | [diff] [blame] | 1904 | if (--surface->ref_count > 0) |
| 1905 | return; |
| 1906 | |
Pekka Paalanen | 08d3fb7 | 2015-04-17 14:00:24 +0300 | [diff] [blame] | 1907 | assert(surface->resource == NULL); |
| 1908 | |
Pekka Paalanen | ca79076 | 2015-04-17 14:23:38 +0300 | [diff] [blame] | 1909 | wl_signal_emit(&surface->destroy_signal, surface); |
Giulio Camuffo | 13b85bd | 2013-08-13 23:10:14 +0200 | [diff] [blame] | 1910 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1911 | assert(wl_list_empty(&surface->subsurface_list_pending)); |
| 1912 | assert(wl_list_empty(&surface->subsurface_list)); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1913 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1914 | wl_list_for_each_safe(ev, nv, &surface->views, surface_link) |
| 1915 | weston_view_destroy(ev); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 1916 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 1917 | weston_surface_state_fini(&surface->pending); |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1918 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1919 | weston_buffer_reference(&surface->buffer_ref, NULL); |
Kristian Høgsberg | 3f8f39c | 2009-09-18 17:05:13 -0400 | [diff] [blame] | 1920 | |
Pekka Paalanen | 402ae6d | 2012-01-03 10:23:24 +0200 | [diff] [blame] | 1921 | pixman_region32_fini(&surface->damage); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1922 | pixman_region32_fini(&surface->opaque); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 1923 | pixman_region32_fini(&surface->input); |
Pekka Paalanen | 402ae6d | 2012-01-03 10:23:24 +0200 | [diff] [blame] | 1924 | |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 1925 | wl_list_for_each_safe(cb, next, &surface->frame_callback_list, link) |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 1926 | wl_resource_destroy(cb->resource); |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 1927 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 1928 | weston_presentation_feedback_discard_list(&surface->feedback_list); |
| 1929 | |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 1930 | wl_list_for_each_safe(constraint, next_constraint, |
| 1931 | &surface->pointer_constraints, |
| 1932 | link) |
| 1933 | weston_pointer_constraint_destroy(constraint); |
| 1934 | |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 1935 | free(surface); |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 1936 | } |
| 1937 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1938 | static void |
| 1939 | destroy_surface(struct wl_resource *resource) |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 1940 | { |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1941 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 1942 | |
Pekka Paalanen | 08d3fb7 | 2015-04-17 14:00:24 +0300 | [diff] [blame] | 1943 | assert(surface); |
| 1944 | |
Giulio Camuffo | 0d37974 | 2013-11-15 22:06:15 +0100 | [diff] [blame] | 1945 | /* Set the resource to NULL, since we don't want to leave a |
| 1946 | * dangling pointer if the surface was refcounted and survives |
| 1947 | * the weston_surface_destroy() call. */ |
| 1948 | surface->resource = NULL; |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 1949 | |
| 1950 | if (surface->viewport_resource) |
| 1951 | wl_resource_set_user_data(surface->viewport_resource, NULL); |
| 1952 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1953 | weston_surface_destroy(surface); |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 1954 | } |
| 1955 | |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 1956 | static void |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1957 | weston_buffer_destroy_handler(struct wl_listener *listener, void *data) |
| 1958 | { |
| 1959 | struct weston_buffer *buffer = |
| 1960 | container_of(listener, struct weston_buffer, destroy_listener); |
| 1961 | |
| 1962 | wl_signal_emit(&buffer->destroy_signal, buffer); |
| 1963 | free(buffer); |
| 1964 | } |
| 1965 | |
Giulio Camuffo | e058cd1 | 2013-12-12 14:14:29 +0100 | [diff] [blame] | 1966 | WL_EXPORT struct weston_buffer * |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1967 | weston_buffer_from_resource(struct wl_resource *resource) |
| 1968 | { |
| 1969 | struct weston_buffer *buffer; |
| 1970 | struct wl_listener *listener; |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 1971 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1972 | listener = wl_resource_get_destroy_listener(resource, |
| 1973 | weston_buffer_destroy_handler); |
| 1974 | |
Kristian Høgsberg | 08b58c7 | 2013-08-15 12:26:42 -0700 | [diff] [blame] | 1975 | if (listener) |
| 1976 | return container_of(listener, struct weston_buffer, |
| 1977 | destroy_listener); |
| 1978 | |
| 1979 | buffer = zalloc(sizeof *buffer); |
| 1980 | if (buffer == NULL) |
| 1981 | return NULL; |
| 1982 | |
| 1983 | buffer->resource = resource; |
| 1984 | wl_signal_init(&buffer->destroy_signal); |
| 1985 | buffer->destroy_listener.notify = weston_buffer_destroy_handler; |
Stanislav Vorobiov | bfbb8e5 | 2013-08-29 11:36:44 +0400 | [diff] [blame] | 1986 | buffer->y_inverted = 1; |
Kristian Høgsberg | 08b58c7 | 2013-08-15 12:26:42 -0700 | [diff] [blame] | 1987 | wl_resource_add_destroy_listener(resource, &buffer->destroy_listener); |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 1988 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1989 | return buffer; |
| 1990 | } |
| 1991 | |
| 1992 | static void |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1993 | weston_buffer_reference_handle_destroy(struct wl_listener *listener, |
| 1994 | void *data) |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 1995 | { |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1996 | struct weston_buffer_reference *ref = |
| 1997 | container_of(listener, struct weston_buffer_reference, |
| 1998 | destroy_listener); |
| 1999 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2000 | assert((struct weston_buffer *)data == ref->buffer); |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2001 | ref->buffer = NULL; |
| 2002 | } |
| 2003 | |
| 2004 | WL_EXPORT void |
| 2005 | weston_buffer_reference(struct weston_buffer_reference *ref, |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2006 | struct weston_buffer *buffer) |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2007 | { |
| 2008 | if (ref->buffer && buffer != ref->buffer) { |
Kristian Høgsberg | 2034780 | 2013-03-04 12:07:46 -0500 | [diff] [blame] | 2009 | ref->buffer->busy_count--; |
| 2010 | if (ref->buffer->busy_count == 0) { |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2011 | assert(wl_resource_get_client(ref->buffer->resource)); |
Matt Hoosier | 3052bc7 | 2017-09-26 08:09:40 -0500 | [diff] [blame] | 2012 | wl_buffer_send_release(ref->buffer->resource); |
Kristian Høgsberg | 2034780 | 2013-03-04 12:07:46 -0500 | [diff] [blame] | 2013 | } |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2014 | wl_list_remove(&ref->destroy_listener.link); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2015 | } |
| 2016 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2017 | if (buffer && buffer != ref->buffer) { |
Kristian Høgsberg | b7b77e6 | 2012-09-05 22:38:18 -0400 | [diff] [blame] | 2018 | buffer->busy_count++; |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2019 | wl_signal_add(&buffer->destroy_signal, |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2020 | &ref->destroy_listener); |
Pekka Paalanen | a6421c4 | 2012-12-04 15:58:10 +0200 | [diff] [blame] | 2021 | } |
| 2022 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2023 | ref->buffer = buffer; |
| 2024 | ref->destroy_listener.notify = weston_buffer_reference_handle_destroy; |
| 2025 | } |
| 2026 | |
| 2027 | static void |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2028 | weston_surface_attach(struct weston_surface *surface, |
| 2029 | struct weston_buffer *buffer) |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2030 | { |
| 2031 | weston_buffer_reference(&surface->buffer_ref, buffer); |
| 2032 | |
Pekka Paalanen | a6421c4 | 2012-12-04 15:58:10 +0200 | [diff] [blame] | 2033 | if (!buffer) { |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2034 | if (weston_surface_is_mapped(surface)) |
| 2035 | weston_surface_unmap(surface); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2036 | } |
| 2037 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2038 | surface->compositor->renderer->attach(surface, buffer); |
Pekka Paalanen | bb2f3f2 | 2014-03-14 14:38:11 +0200 | [diff] [blame] | 2039 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 2040 | weston_surface_calculate_size_from_buffer(surface); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2041 | weston_presentation_feedback_discard_list(&surface->feedback_list); |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 2042 | } |
| 2043 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2044 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2045 | weston_compositor_damage_all(struct weston_compositor *compositor) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2046 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2047 | struct weston_output *output; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2048 | |
| 2049 | wl_list_for_each(output, &compositor->output_list, link) |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2050 | weston_output_damage(output); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2051 | } |
| 2052 | |
Kristian Høgsberg | 9f404b7 | 2012-01-26 00:11:01 -0500 | [diff] [blame] | 2053 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2054 | weston_output_damage(struct weston_output *output) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2055 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2056 | struct weston_compositor *compositor = output->compositor; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2057 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 2058 | pixman_region32_union(&compositor->primary_plane.damage, |
| 2059 | &compositor->primary_plane.damage, |
| 2060 | &output->region); |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2061 | weston_output_schedule_repaint(output); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2062 | } |
| 2063 | |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame] | 2064 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2065 | surface_flush_damage(struct weston_surface *surface) |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2066 | { |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2067 | if (surface->buffer_ref.buffer && |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2068 | wl_shm_buffer_get(surface->buffer_ref.buffer->resource)) |
Kristian Høgsberg | fa1be02 | 2012-09-05 22:49:55 -0400 | [diff] [blame] | 2069 | surface->compositor->renderer->flush_damage(surface); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2070 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2071 | if (weston_timeline_enabled_ && |
| 2072 | pixman_region32_not_empty(&surface->damage)) |
| 2073 | TL_POINT("core_flush_damage", TLP_SURFACE(surface), |
| 2074 | TLP_OUTPUT(surface->output), TLP_END); |
| 2075 | |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 2076 | pixman_region32_clear(&surface->damage); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2077 | } |
| 2078 | |
| 2079 | static void |
| 2080 | view_accumulate_damage(struct weston_view *view, |
| 2081 | pixman_region32_t *opaque) |
| 2082 | { |
| 2083 | pixman_region32_t damage; |
| 2084 | |
| 2085 | pixman_region32_init(&damage); |
| 2086 | if (view->transform.enabled) { |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2087 | pixman_box32_t *extents; |
| 2088 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2089 | extents = pixman_region32_extents(&view->surface->damage); |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 2090 | view_compute_bbox(view, extents, &damage); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2091 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2092 | pixman_region32_copy(&damage, &view->surface->damage); |
| 2093 | pixman_region32_translate(&damage, |
Pekka Paalanen | 502f5e0 | 2015-02-23 14:08:25 +0200 | [diff] [blame] | 2094 | view->geometry.x, view->geometry.y); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2095 | } |
| 2096 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 2097 | pixman_region32_intersect(&damage, &damage, |
| 2098 | &view->transform.boundingbox); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2099 | pixman_region32_subtract(&damage, &damage, opaque); |
| 2100 | pixman_region32_union(&view->plane->damage, |
| 2101 | &view->plane->damage, &damage); |
| 2102 | pixman_region32_fini(&damage); |
| 2103 | pixman_region32_copy(&view->clip, opaque); |
Pekka Paalanen | 8844bf2 | 2015-02-18 16:30:47 +0200 | [diff] [blame] | 2104 | pixman_region32_union(opaque, opaque, &view->transform.opaque); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2105 | } |
| 2106 | |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 2107 | static void |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2108 | compositor_accumulate_damage(struct weston_compositor *ec) |
| 2109 | { |
| 2110 | struct weston_plane *plane; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2111 | struct weston_view *ev; |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2112 | pixman_region32_t opaque, clip; |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2113 | |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2114 | pixman_region32_init(&clip); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2115 | |
| 2116 | wl_list_for_each(plane, &ec->plane_list, link) { |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2117 | pixman_region32_copy(&plane->clip, &clip); |
| 2118 | |
| 2119 | pixman_region32_init(&opaque); |
| 2120 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2121 | wl_list_for_each(ev, &ec->view_list, link) { |
| 2122 | if (ev->plane != plane) |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2123 | continue; |
| 2124 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2125 | view_accumulate_damage(ev, &opaque); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2126 | } |
| 2127 | |
| 2128 | pixman_region32_union(&clip, &clip, &opaque); |
| 2129 | pixman_region32_fini(&opaque); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2130 | } |
| 2131 | |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2132 | pixman_region32_fini(&clip); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2133 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2134 | wl_list_for_each(ev, &ec->view_list, link) |
Derek Foreman | 060cf11 | 2015-11-18 16:32:26 -0600 | [diff] [blame] | 2135 | ev->surface->touched = false; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2136 | |
| 2137 | wl_list_for_each(ev, &ec->view_list, link) { |
| 2138 | if (ev->surface->touched) |
| 2139 | continue; |
Derek Foreman | 060cf11 | 2015-11-18 16:32:26 -0600 | [diff] [blame] | 2140 | ev->surface->touched = true; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2141 | |
| 2142 | surface_flush_damage(ev->surface); |
| 2143 | |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2144 | /* Both the renderer and the backend have seen the buffer |
| 2145 | * by now. If renderer needs the buffer, it has its own |
| 2146 | * reference set. If the backend wants to keep the buffer |
| 2147 | * around for migrating the surface into a non-primary plane |
| 2148 | * later, keep_buffer is true. Otherwise, drop the core |
| 2149 | * reference now, and allow early buffer release. This enables |
| 2150 | * clients to use single-buffering. |
| 2151 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2152 | if (!ev->surface->keep_buffer) |
| 2153 | weston_buffer_reference(&ev->surface->buffer_ref, NULL); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2154 | } |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2155 | } |
| 2156 | |
| 2157 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2158 | surface_stash_subsurface_views(struct weston_surface *surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2159 | { |
| 2160 | struct weston_subsurface *sub; |
| 2161 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2162 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2163 | if (sub->surface == surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2164 | continue; |
| 2165 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2166 | wl_list_insert_list(&sub->unused_views, &sub->surface->views); |
| 2167 | wl_list_init(&sub->surface->views); |
| 2168 | |
| 2169 | surface_stash_subsurface_views(sub->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2170 | } |
| 2171 | } |
| 2172 | |
| 2173 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2174 | surface_free_unused_subsurface_views(struct weston_surface *surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2175 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2176 | struct weston_subsurface *sub; |
| 2177 | struct weston_view *view, *nv; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2178 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2179 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
| 2180 | if (sub->surface == surface) |
| 2181 | continue; |
| 2182 | |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 2183 | wl_list_for_each_safe(view, nv, &sub->unused_views, surface_link) { |
| 2184 | weston_view_unmap (view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2185 | weston_view_destroy(view); |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 2186 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2187 | |
| 2188 | surface_free_unused_subsurface_views(sub->surface); |
| 2189 | } |
| 2190 | } |
| 2191 | |
| 2192 | static void |
| 2193 | view_list_add_subsurface_view(struct weston_compositor *compositor, |
| 2194 | struct weston_subsurface *sub, |
| 2195 | struct weston_view *parent) |
| 2196 | { |
| 2197 | struct weston_subsurface *child; |
| 2198 | struct weston_view *view = NULL, *iv; |
| 2199 | |
Pekka Paalanen | 661de3a | 2014-07-28 12:49:24 +0300 | [diff] [blame] | 2200 | if (!weston_surface_is_mapped(sub->surface)) |
| 2201 | return; |
| 2202 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2203 | wl_list_for_each(iv, &sub->unused_views, surface_link) { |
| 2204 | if (iv->geometry.parent == parent) { |
| 2205 | view = iv; |
| 2206 | break; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2207 | } |
| 2208 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2209 | |
| 2210 | if (view) { |
| 2211 | /* Put it back in the surface's list of views */ |
| 2212 | wl_list_remove(&view->surface_link); |
| 2213 | wl_list_insert(&sub->surface->views, &view->surface_link); |
| 2214 | } else { |
| 2215 | view = weston_view_create(sub->surface); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2216 | weston_view_set_position(view, |
| 2217 | sub->position.x, |
| 2218 | sub->position.y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2219 | weston_view_set_transform_parent(view, parent); |
| 2220 | } |
| 2221 | |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 2222 | view->parent_view = parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2223 | weston_view_update_transform(view); |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 2224 | view->is_mapped = true; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2225 | |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2226 | if (wl_list_empty(&sub->surface->subsurface_list)) { |
| 2227 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 2228 | return; |
| 2229 | } |
| 2230 | |
| 2231 | wl_list_for_each(child, &sub->surface->subsurface_list, parent_link) { |
| 2232 | if (child->surface == sub->surface) |
| 2233 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 2234 | else |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2235 | view_list_add_subsurface_view(compositor, child, view); |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2236 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2237 | } |
| 2238 | |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 2239 | /* This recursively adds the sub-surfaces for a view, relying on the |
| 2240 | * sub-surface order. Thus, if a client restacks the sub-surfaces, that |
| 2241 | * change first happens to the sub-surface list, and then automatically |
| 2242 | * propagates here. See weston_surface_damage_subsurfaces() for how the |
| 2243 | * sub-surfaces receive damage when the client changes the state. |
| 2244 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2245 | static void |
| 2246 | view_list_add(struct weston_compositor *compositor, |
| 2247 | struct weston_view *view) |
| 2248 | { |
| 2249 | struct weston_subsurface *sub; |
| 2250 | |
| 2251 | weston_view_update_transform(view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2252 | |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2253 | if (wl_list_empty(&view->surface->subsurface_list)) { |
| 2254 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 2255 | return; |
| 2256 | } |
| 2257 | |
| 2258 | wl_list_for_each(sub, &view->surface->subsurface_list, parent_link) { |
| 2259 | if (sub->surface == view->surface) |
| 2260 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 2261 | else |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2262 | view_list_add_subsurface_view(compositor, sub, view); |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2263 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2264 | } |
| 2265 | |
| 2266 | static void |
| 2267 | weston_compositor_build_view_list(struct weston_compositor *compositor) |
| 2268 | { |
| 2269 | struct weston_view *view; |
| 2270 | struct weston_layer *layer; |
| 2271 | |
| 2272 | wl_list_for_each(layer, &compositor->layer_list, link) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2273 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2274 | surface_stash_subsurface_views(view->surface); |
| 2275 | |
| 2276 | wl_list_init(&compositor->view_list); |
| 2277 | wl_list_for_each(layer, &compositor->layer_list, link) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2278 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2279 | view_list_add(compositor, view); |
| 2280 | } |
| 2281 | } |
| 2282 | |
| 2283 | wl_list_for_each(layer, &compositor->layer_list, link) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2284 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2285 | surface_free_unused_subsurface_views(view->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2286 | } |
| 2287 | |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2288 | static void |
| 2289 | weston_output_take_feedback_list(struct weston_output *output, |
| 2290 | struct weston_surface *surface) |
| 2291 | { |
| 2292 | struct weston_view *view; |
| 2293 | struct weston_presentation_feedback *feedback; |
| 2294 | uint32_t flags = 0xffffffff; |
| 2295 | |
| 2296 | if (wl_list_empty(&surface->feedback_list)) |
| 2297 | return; |
| 2298 | |
| 2299 | /* All views must have the flag for the flag to survive. */ |
| 2300 | wl_list_for_each(view, &surface->views, surface_link) { |
| 2301 | /* ignore views that are not on this output at all */ |
| 2302 | if (view->output_mask & (1u << output->id)) |
| 2303 | flags &= view->psf_flags; |
| 2304 | } |
| 2305 | |
| 2306 | wl_list_for_each(feedback, &surface->feedback_list, link) |
| 2307 | feedback->psf_flags = flags; |
| 2308 | |
| 2309 | wl_list_insert_list(&output->feedback_list, &surface->feedback_list); |
| 2310 | wl_list_init(&surface->feedback_list); |
| 2311 | } |
| 2312 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2313 | static int |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2314 | weston_output_repaint(struct weston_output *output, void *repaint_data) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2315 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2316 | struct weston_compositor *ec = output->compositor; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2317 | struct weston_view *ev; |
Kristian Høgsberg | 30c018b | 2012-01-26 08:40:37 -0500 | [diff] [blame] | 2318 | struct weston_animation *animation, *next; |
| 2319 | struct weston_frame_callback *cb, *cnext; |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 2320 | struct wl_list frame_callback_list; |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2321 | pixman_region32_t output_damage; |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2322 | int r; |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 2323 | uint32_t frame_time_msec; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 2324 | |
Ander Conselvan de Oliveira | e1e2352 | 2013-12-13 22:10:55 +0200 | [diff] [blame] | 2325 | if (output->destroying) |
| 2326 | return 0; |
| 2327 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2328 | TL_POINT("core_repaint_begin", TLP_OUTPUT(output), TLP_END); |
| 2329 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2330 | /* Rebuild the surface list and update surface transforms up front. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2331 | weston_compositor_build_view_list(ec); |
Pekka Paalanen | 15d60ef | 2012-01-27 14:38:33 +0200 | [diff] [blame] | 2332 | |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2333 | if (output->assign_planes && !output->disable_planes) { |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2334 | output->assign_planes(output, repaint_data); |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2335 | } else { |
| 2336 | wl_list_for_each(ev, &ec->view_list, link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2337 | weston_view_move_to_plane(ev, &ec->primary_plane); |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2338 | ev->psf_flags = 0; |
| 2339 | } |
| 2340 | } |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 2341 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2342 | wl_list_init(&frame_callback_list); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2343 | wl_list_for_each(ev, &ec->view_list, link) { |
| 2344 | /* Note: This operation is safe to do multiple times on the |
| 2345 | * same surface. |
| 2346 | */ |
| 2347 | if (ev->surface->output == output) { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2348 | wl_list_insert_list(&frame_callback_list, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2349 | &ev->surface->frame_callback_list); |
| 2350 | wl_list_init(&ev->surface->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2351 | |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2352 | weston_output_take_feedback_list(output, ev->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2353 | } |
| 2354 | } |
| 2355 | |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2356 | compositor_accumulate_damage(ec); |
Kristian Høgsberg | 53df1d8 | 2011-06-23 21:11:19 -0400 | [diff] [blame] | 2357 | |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 2358 | pixman_region32_init(&output_damage); |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 2359 | pixman_region32_intersect(&output_damage, |
| 2360 | &ec->primary_plane.damage, &output->region); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2361 | pixman_region32_subtract(&output_damage, |
| 2362 | &output_damage, &ec->primary_plane.clip); |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 2363 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2364 | if (output->dirty) |
| 2365 | weston_output_update_matrix(output); |
| 2366 | |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2367 | r = output->repaint(output, &output_damage, repaint_data); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2368 | |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 2369 | pixman_region32_fini(&output_damage); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 2370 | |
Daniel Stone | 09a97e2 | 2017-03-01 11:34:06 +0000 | [diff] [blame] | 2371 | output->repaint_needed = false; |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2372 | if (r == 0) |
| 2373 | output->repaint_status = REPAINT_AWAITING_COMPLETION; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 2374 | |
Kristian Høgsberg | aa6019e | 2012-03-11 16:35:16 -0400 | [diff] [blame] | 2375 | weston_compositor_repick(ec); |
Kristian Høgsberg | aa6019e | 2012-03-11 16:35:16 -0400 | [diff] [blame] | 2376 | |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 2377 | frame_time_msec = timespec_to_msec(&output->frame_time); |
| 2378 | |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 2379 | wl_list_for_each_safe(cb, cnext, &frame_callback_list, link) { |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 2380 | wl_callback_send_done(cb->resource, frame_time_msec); |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 2381 | wl_resource_destroy(cb->resource); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 2382 | } |
| 2383 | |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 2384 | wl_list_for_each_safe(animation, next, &output->animation_list, link) { |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 2385 | animation->frame_counter++; |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 2386 | animation->frame(animation, output, &output->frame_time); |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 2387 | } |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2388 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2389 | TL_POINT("core_repaint_posted", TLP_OUTPUT(output), TLP_END); |
| 2390 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2391 | return r; |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2392 | } |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 2393 | |
Pekka Paalanen | 8291979 | 2014-05-21 13:51:49 +0300 | [diff] [blame] | 2394 | static void |
| 2395 | weston_output_schedule_repaint_reset(struct weston_output *output) |
| 2396 | { |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2397 | output->repaint_status = REPAINT_NOT_SCHEDULED; |
Pekka Paalanen | 8291979 | 2014-05-21 13:51:49 +0300 | [diff] [blame] | 2398 | TL_POINT("core_repaint_exit_loop", TLP_OUTPUT(output), TLP_END); |
Pekka Paalanen | 8291979 | 2014-05-21 13:51:49 +0300 | [diff] [blame] | 2399 | } |
| 2400 | |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2401 | static int |
| 2402 | weston_output_maybe_repaint(struct weston_output *output, struct timespec *now, |
| 2403 | void *repaint_data) |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2404 | { |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2405 | struct weston_compositor *compositor = output->compositor; |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2406 | int ret = 0; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2407 | int64_t msec_to_repaint; |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2408 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2409 | /* We're not ready yet; come back to make a decision later. */ |
| 2410 | if (output->repaint_status != REPAINT_SCHEDULED) |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2411 | return ret; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2412 | |
| 2413 | msec_to_repaint = timespec_sub_to_msec(&output->next_repaint, now); |
| 2414 | if (msec_to_repaint > 1) |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2415 | return ret; |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2416 | |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 2417 | /* If we're sleeping, drop the repaint machinery entirely; we will |
| 2418 | * explicitly repaint all outputs when we come back. */ |
| 2419 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING || |
| 2420 | compositor->state == WESTON_COMPOSITOR_OFFSCREEN) |
| 2421 | goto err; |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2422 | |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 2423 | /* We don't actually need to repaint this output; drop it from |
| 2424 | * repaint until something causes damage. */ |
| 2425 | if (!output->repaint_needed) |
| 2426 | goto err; |
| 2427 | |
| 2428 | /* If repaint fails, we aren't going to get weston_output_finish_frame |
| 2429 | * to trigger a new repaint, so drop it from repaint and hope |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2430 | * something schedules a successful repaint later. As repainting may |
| 2431 | * take some time, re-read our clock as a courtesy to the next |
| 2432 | * output. */ |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2433 | ret = weston_output_repaint(output, repaint_data); |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2434 | weston_compositor_read_presentation_clock(compositor, now); |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 2435 | if (ret != 0) |
| 2436 | goto err; |
| 2437 | |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2438 | return ret; |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 2439 | |
| 2440 | err: |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2441 | weston_output_schedule_repaint_reset(output); |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2442 | return ret; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2443 | } |
| 2444 | |
| 2445 | static void |
| 2446 | output_repaint_timer_arm(struct weston_compositor *compositor) |
| 2447 | { |
| 2448 | struct weston_output *output; |
| 2449 | bool any_should_repaint = false; |
| 2450 | struct timespec now; |
Sergi Granell | b4c0886 | 2017-03-18 13:01:15 +0100 | [diff] [blame] | 2451 | int64_t msec_to_next = INT64_MAX; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2452 | |
| 2453 | weston_compositor_read_presentation_clock(compositor, &now); |
| 2454 | |
| 2455 | wl_list_for_each(output, &compositor->output_list, link) { |
| 2456 | int64_t msec_to_this; |
| 2457 | |
| 2458 | if (output->repaint_status != REPAINT_SCHEDULED) |
| 2459 | continue; |
| 2460 | |
| 2461 | msec_to_this = timespec_sub_to_msec(&output->next_repaint, |
| 2462 | &now); |
| 2463 | if (!any_should_repaint || msec_to_this < msec_to_next) |
| 2464 | msec_to_next = msec_to_this; |
| 2465 | |
| 2466 | any_should_repaint = true; |
| 2467 | } |
| 2468 | |
| 2469 | if (!any_should_repaint) |
| 2470 | return; |
| 2471 | |
| 2472 | /* Even if we should repaint immediately, add the minimum 1 ms delay. |
| 2473 | * This is a workaround to allow coalescing multiple output repaints |
| 2474 | * particularly from weston_output_finish_frame() |
| 2475 | * into the same call, which would not happen if we called |
| 2476 | * output_repaint_timer_handler() directly. |
| 2477 | */ |
| 2478 | if (msec_to_next < 1) |
| 2479 | msec_to_next = 1; |
| 2480 | |
| 2481 | wl_event_source_timer_update(compositor->repaint_timer, msec_to_next); |
| 2482 | } |
| 2483 | |
| 2484 | static int |
| 2485 | output_repaint_timer_handler(void *data) |
| 2486 | { |
| 2487 | struct weston_compositor *compositor = data; |
| 2488 | struct weston_output *output; |
| 2489 | struct timespec now; |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2490 | void *repaint_data = NULL; |
Emre Ucan | e479ed8 | 2018-03-20 15:29:40 +0100 | [diff] [blame] | 2491 | int ret = 0; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2492 | |
| 2493 | weston_compositor_read_presentation_clock(compositor, &now); |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2494 | |
| 2495 | if (compositor->backend->repaint_begin) |
| 2496 | repaint_data = compositor->backend->repaint_begin(compositor); |
| 2497 | |
| 2498 | wl_list_for_each(output, &compositor->output_list, link) { |
| 2499 | ret = weston_output_maybe_repaint(output, &now, repaint_data); |
| 2500 | if (ret) |
| 2501 | break; |
| 2502 | } |
| 2503 | |
| 2504 | if (ret == 0) { |
| 2505 | if (compositor->backend->repaint_flush) |
| 2506 | compositor->backend->repaint_flush(compositor, |
| 2507 | repaint_data); |
| 2508 | } else { |
| 2509 | if (compositor->backend->repaint_cancel) |
| 2510 | compositor->backend->repaint_cancel(compositor, |
| 2511 | repaint_data); |
| 2512 | } |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2513 | |
| 2514 | output_repaint_timer_arm(compositor); |
| 2515 | |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2516 | return 0; |
| 2517 | } |
| 2518 | |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2519 | WL_EXPORT void |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 2520 | weston_output_finish_frame(struct weston_output *output, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 2521 | const struct timespec *stamp, |
| 2522 | uint32_t presented_flags) |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2523 | { |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2524 | struct weston_compositor *compositor = output->compositor; |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2525 | int32_t refresh_nsec; |
| 2526 | struct timespec now; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2527 | int64_t msec_rel; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2528 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2529 | |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2530 | assert(output->repaint_status == REPAINT_AWAITING_COMPLETION); |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2531 | assert(stamp || (presented_flags & WP_PRESENTATION_FEEDBACK_INVALID)); |
| 2532 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2533 | weston_compositor_read_presentation_clock(compositor, &now); |
| 2534 | |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2535 | /* If we haven't been supplied any timestamp at all, we don't have a |
| 2536 | * timebase to work against, so any delay just wastes time. Push a |
| 2537 | * repaint as soon as possible so we can get on with it. */ |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2538 | if (!stamp) { |
| 2539 | output->next_repaint = now; |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2540 | goto out; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2541 | } |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2542 | |
Marius Vlad | df9278a | 2018-03-06 18:56:23 +0200 | [diff] [blame] | 2543 | TL_POINT("core_repaint_finished", TLP_OUTPUT(output), |
| 2544 | TLP_VBLANK(stamp), TLP_END); |
| 2545 | |
Pekka Paalanen | d7894d0 | 2015-07-03 15:08:53 +0300 | [diff] [blame] | 2546 | refresh_nsec = millihz_to_nsec(output->current_mode->refresh); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2547 | weston_presentation_feedback_present_list(&output->feedback_list, |
| 2548 | output, refresh_nsec, stamp, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 2549 | output->msc, |
| 2550 | presented_flags); |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2551 | |
Alexandros Frantzis | e6ac2af | 2017-11-16 18:20:53 +0200 | [diff] [blame] | 2552 | output->frame_time = *stamp; |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2553 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2554 | timespec_add_nsec(&output->next_repaint, stamp, refresh_nsec); |
| 2555 | timespec_add_msec(&output->next_repaint, &output->next_repaint, |
| 2556 | -compositor->repaint_msec); |
| 2557 | msec_rel = timespec_sub_to_msec(&output->next_repaint, &now); |
Daniel Stone | 84aff5c | 2017-03-01 11:34:04 +0000 | [diff] [blame] | 2558 | |
| 2559 | if (msec_rel < -1000 || msec_rel > 1000) { |
Pekka Paalanen | 8fd4de4 | 2015-03-19 12:27:29 +0200 | [diff] [blame] | 2560 | static bool warned; |
| 2561 | |
| 2562 | if (!warned) |
| 2563 | weston_log("Warning: computed repaint delay is " |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2564 | "insane: %lld msec\n", (long long) msec_rel); |
Pekka Paalanen | 8fd4de4 | 2015-03-19 12:27:29 +0200 | [diff] [blame] | 2565 | warned = true; |
| 2566 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2567 | output->next_repaint = now; |
Pekka Paalanen | 8fd4de4 | 2015-03-19 12:27:29 +0200 | [diff] [blame] | 2568 | } |
| 2569 | |
Mario Kleiner | b7df04e | 2015-06-21 21:25:15 +0200 | [diff] [blame] | 2570 | /* Called from restart_repaint_loop and restart happens already after |
| 2571 | * the deadline given by repaint_msec? In that case we delay until |
| 2572 | * the deadline of the next frame, to give clients a more predictable |
| 2573 | * timing of the repaint cycle to lock on. */ |
Daniel Stone | eca5cca | 2017-02-28 21:53:51 +0000 | [diff] [blame] | 2574 | if (presented_flags == WP_PRESENTATION_FEEDBACK_INVALID && |
| 2575 | msec_rel < 0) { |
| 2576 | while (timespec_sub_to_nsec(&output->next_repaint, &now) < 0) { |
| 2577 | timespec_add_nsec(&output->next_repaint, |
| 2578 | &output->next_repaint, |
| 2579 | refresh_nsec); |
| 2580 | } |
| 2581 | } |
Mario Kleiner | b7df04e | 2015-06-21 21:25:15 +0200 | [diff] [blame] | 2582 | |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2583 | out: |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2584 | output->repaint_status = REPAINT_SCHEDULED; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2585 | output_repaint_timer_arm(compositor); |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2586 | } |
| 2587 | |
| 2588 | static void |
| 2589 | idle_repaint(void *data) |
| 2590 | { |
| 2591 | struct weston_output *output = data; |
| 2592 | |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2593 | assert(output->repaint_status == REPAINT_BEGIN_FROM_IDLE); |
| 2594 | output->repaint_status = REPAINT_AWAITING_COMPLETION; |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 2595 | output->start_repaint_loop(output); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2596 | } |
| 2597 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2598 | WL_EXPORT void |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2599 | weston_layer_entry_insert(struct weston_layer_entry *list, |
| 2600 | struct weston_layer_entry *entry) |
| 2601 | { |
| 2602 | wl_list_insert(&list->link, &entry->link); |
| 2603 | entry->layer = list->layer; |
| 2604 | } |
| 2605 | |
| 2606 | WL_EXPORT void |
| 2607 | weston_layer_entry_remove(struct weston_layer_entry *entry) |
| 2608 | { |
| 2609 | wl_list_remove(&entry->link); |
| 2610 | wl_list_init(&entry->link); |
| 2611 | entry->layer = NULL; |
| 2612 | } |
| 2613 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 2614 | |
| 2615 | /** Initialize the weston_layer struct. |
| 2616 | * |
| 2617 | * \param compositor The compositor instance |
| 2618 | * \param layer The layer to initialize |
| 2619 | */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2620 | WL_EXPORT void |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 2621 | weston_layer_init(struct weston_layer *layer, |
| 2622 | struct weston_compositor *compositor) |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2623 | { |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 2624 | layer->compositor = compositor; |
| 2625 | wl_list_init(&layer->link); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2626 | wl_list_init(&layer->view_list.link); |
| 2627 | layer->view_list.layer = layer; |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 2628 | weston_layer_set_mask_infinite(layer); |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 2629 | } |
| 2630 | |
| 2631 | /** Sets the position of the layer in the layer list. The layer will be placed |
| 2632 | * below any layer with the same position value, if any. |
| 2633 | * This function is safe to call if the layer is already on the list, but the |
| 2634 | * layer may be moved below other layers at the same position, if any. |
| 2635 | * |
| 2636 | * \param layer The layer to modify |
| 2637 | * \param position The position the layer will be placed at |
| 2638 | */ |
| 2639 | WL_EXPORT void |
| 2640 | weston_layer_set_position(struct weston_layer *layer, |
| 2641 | enum weston_layer_position position) |
| 2642 | { |
| 2643 | struct weston_layer *below; |
| 2644 | |
| 2645 | wl_list_remove(&layer->link); |
| 2646 | |
| 2647 | /* layer_list is ordered from top to bottom, the last layer being the |
| 2648 | * background with the smallest position value */ |
| 2649 | |
| 2650 | layer->position = position; |
| 2651 | wl_list_for_each_reverse(below, &layer->compositor->layer_list, link) { |
| 2652 | if (below->position >= layer->position) { |
| 2653 | wl_list_insert(&below->link, &layer->link); |
| 2654 | return; |
| 2655 | } |
| 2656 | } |
| 2657 | wl_list_insert(&layer->compositor->layer_list, &layer->link); |
| 2658 | } |
| 2659 | |
| 2660 | /** Hide a layer by taking it off the layer list. |
| 2661 | * This function is safe to call if the layer is not on the list. |
| 2662 | * |
| 2663 | * \param layer The layer to hide |
| 2664 | */ |
| 2665 | WL_EXPORT void |
| 2666 | weston_layer_unset_position(struct weston_layer *layer) |
| 2667 | { |
| 2668 | wl_list_remove(&layer->link); |
| 2669 | wl_list_init(&layer->link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2670 | } |
| 2671 | |
| 2672 | WL_EXPORT void |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 2673 | weston_layer_set_mask(struct weston_layer *layer, |
| 2674 | int x, int y, int width, int height) |
| 2675 | { |
| 2676 | struct weston_view *view; |
| 2677 | |
| 2678 | layer->mask.x1 = x; |
| 2679 | layer->mask.x2 = x + width; |
| 2680 | layer->mask.y1 = y; |
| 2681 | layer->mask.y2 = y + height; |
| 2682 | |
| 2683 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
| 2684 | weston_view_geometry_dirty(view); |
| 2685 | } |
| 2686 | } |
| 2687 | |
| 2688 | WL_EXPORT void |
| 2689 | weston_layer_set_mask_infinite(struct weston_layer *layer) |
| 2690 | { |
| 2691 | weston_layer_set_mask(layer, INT32_MIN, INT32_MIN, |
| 2692 | UINT32_MAX, UINT32_MAX); |
| 2693 | } |
| 2694 | |
| 2695 | WL_EXPORT void |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2696 | weston_output_schedule_repaint(struct weston_output *output) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2697 | { |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2698 | struct weston_compositor *compositor = output->compositor; |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2699 | struct wl_event_loop *loop; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 2700 | |
Bryce Harrington | 08976ac | 2016-08-30 12:05:16 -0700 | [diff] [blame] | 2701 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING || |
| 2702 | compositor->state == WESTON_COMPOSITOR_OFFSCREEN) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2703 | return; |
| 2704 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2705 | if (!output->repaint_needed) |
| 2706 | TL_POINT("core_repaint_req", TLP_OUTPUT(output), TLP_END); |
| 2707 | |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2708 | loop = wl_display_get_event_loop(compositor->wl_display); |
Daniel Stone | 09a97e2 | 2017-03-01 11:34:06 +0000 | [diff] [blame] | 2709 | output->repaint_needed = true; |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2710 | |
| 2711 | /* If we already have a repaint scheduled for our idle handler, |
| 2712 | * no need to set it again. If the repaint has been called but |
| 2713 | * not finished, then weston_output_finish_frame() will notice |
| 2714 | * that a repaint is needed and schedule one. */ |
| 2715 | if (output->repaint_status != REPAINT_NOT_SCHEDULED) |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2716 | return; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 2717 | |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2718 | output->repaint_status = REPAINT_BEGIN_FROM_IDLE; |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2719 | wl_event_loop_add_idle(loop, idle_repaint, output); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2720 | TL_POINT("core_repaint_enter_loop", TLP_OUTPUT(output), TLP_END); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2721 | } |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 2722 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2723 | WL_EXPORT void |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2724 | weston_compositor_schedule_repaint(struct weston_compositor *compositor) |
| 2725 | { |
| 2726 | struct weston_output *output; |
| 2727 | |
| 2728 | wl_list_for_each(output, &compositor->output_list, link) |
| 2729 | weston_output_schedule_repaint(output); |
| 2730 | } |
| 2731 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 2732 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 2733 | surface_destroy(struct wl_client *client, struct wl_resource *resource) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 2734 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2735 | wl_resource_destroy(resource); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 2736 | } |
| 2737 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 2738 | static void |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2739 | surface_attach(struct wl_client *client, |
| 2740 | struct wl_resource *resource, |
| 2741 | struct wl_resource *buffer_resource, int32_t sx, int32_t sy) |
| 2742 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2743 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2744 | struct weston_buffer *buffer = NULL; |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2745 | |
Kristian Høgsberg | ab19f93 | 2013-08-20 11:30:54 -0700 | [diff] [blame] | 2746 | if (buffer_resource) { |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2747 | buffer = weston_buffer_from_resource(buffer_resource); |
Kristian Høgsberg | ab19f93 | 2013-08-20 11:30:54 -0700 | [diff] [blame] | 2748 | if (buffer == NULL) { |
| 2749 | wl_client_post_no_memory(client); |
| 2750 | return; |
| 2751 | } |
Kristian Høgsberg | 08b58c7 | 2013-08-15 12:26:42 -0700 | [diff] [blame] | 2752 | } |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 2753 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2754 | /* Attach, attach, without commit in between does not send |
| 2755 | * wl_buffer.release. */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2756 | weston_surface_state_set_buffer(&surface->pending, buffer); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2757 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2758 | surface->pending.sx = sx; |
| 2759 | surface->pending.sy = sy; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2760 | surface->pending.newly_attached = 1; |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 2761 | } |
| 2762 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 2763 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2764 | surface_damage(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 2765 | struct wl_resource *resource, |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2766 | 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] | 2767 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2768 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 9d69f8e | 2010-09-03 14:46:38 -0400 | [diff] [blame] | 2769 | |
Derek Foreman | 57e92ed | 2015-11-17 14:11:35 -0600 | [diff] [blame] | 2770 | if (width <= 0 || height <= 0) |
| 2771 | return; |
| 2772 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 2773 | pixman_region32_union_rect(&surface->pending.damage_surface, |
| 2774 | &surface->pending.damage_surface, |
| 2775 | x, y, width, height); |
| 2776 | } |
| 2777 | |
| 2778 | static void |
| 2779 | surface_damage_buffer(struct wl_client *client, |
| 2780 | struct wl_resource *resource, |
| 2781 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 2782 | { |
| 2783 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
| 2784 | |
| 2785 | if (width <= 0 || height <= 0) |
| 2786 | return; |
| 2787 | |
| 2788 | pixman_region32_union_rect(&surface->pending.damage_buffer, |
| 2789 | &surface->pending.damage_buffer, |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2790 | x, y, width, height); |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 2791 | } |
| 2792 | |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2793 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 2794 | destroy_frame_callback(struct wl_resource *resource) |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2795 | { |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 2796 | struct weston_frame_callback *cb = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 2797 | |
| 2798 | wl_list_remove(&cb->link); |
Pekka Paalanen | 8c19645 | 2011-11-15 11:45:42 +0200 | [diff] [blame] | 2799 | free(cb); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2800 | } |
| 2801 | |
| 2802 | static void |
| 2803 | surface_frame(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 2804 | struct wl_resource *resource, uint32_t callback) |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2805 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2806 | struct weston_frame_callback *cb; |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2807 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2808 | |
| 2809 | cb = malloc(sizeof *cb); |
| 2810 | if (cb == NULL) { |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 2811 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2812 | return; |
| 2813 | } |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 2814 | |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 2815 | cb->resource = wl_resource_create(client, &wl_callback_interface, 1, |
| 2816 | callback); |
| 2817 | if (cb->resource == NULL) { |
| 2818 | free(cb); |
| 2819 | wl_resource_post_no_memory(resource); |
| 2820 | return; |
| 2821 | } |
| 2822 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 2823 | wl_resource_set_implementation(cb->resource, NULL, cb, |
| 2824 | destroy_frame_callback); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2825 | |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 2826 | wl_list_insert(surface->pending.frame_callback_list.prev, &cb->link); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2827 | } |
| 2828 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2829 | static void |
| 2830 | surface_set_opaque_region(struct wl_client *client, |
| 2831 | struct wl_resource *resource, |
| 2832 | struct wl_resource *region_resource) |
| 2833 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2834 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2835 | struct weston_region *region; |
| 2836 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2837 | if (region_resource) { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 2838 | region = wl_resource_get_user_data(region_resource); |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 2839 | pixman_region32_copy(&surface->pending.opaque, |
| 2840 | ®ion->region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2841 | } else { |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 2842 | pixman_region32_clear(&surface->pending.opaque); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2843 | } |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2844 | } |
| 2845 | |
| 2846 | static void |
| 2847 | surface_set_input_region(struct wl_client *client, |
| 2848 | struct wl_resource *resource, |
| 2849 | struct wl_resource *region_resource) |
| 2850 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2851 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 010f98b | 2012-02-23 17:30:45 -0500 | [diff] [blame] | 2852 | struct weston_region *region; |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2853 | |
| 2854 | if (region_resource) { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 2855 | region = wl_resource_get_user_data(region_resource); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 2856 | pixman_region32_copy(&surface->pending.input, |
| 2857 | ®ion->region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2858 | } else { |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 2859 | pixman_region32_fini(&surface->pending.input); |
| 2860 | region_init_infinite(&surface->pending.input); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2861 | } |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2862 | } |
| 2863 | |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 2864 | /* Cause damage to this sub-surface and all its children. |
| 2865 | * |
| 2866 | * This is useful when there are state changes that need an implicit |
| 2867 | * damage, e.g. a z-order change. |
| 2868 | */ |
| 2869 | static void |
| 2870 | weston_surface_damage_subsurfaces(struct weston_subsurface *sub) |
| 2871 | { |
| 2872 | struct weston_subsurface *child; |
| 2873 | |
| 2874 | weston_surface_damage(sub->surface); |
| 2875 | sub->reordered = false; |
| 2876 | |
| 2877 | wl_list_for_each(child, &sub->surface->subsurface_list, parent_link) |
| 2878 | if (child != sub) |
| 2879 | weston_surface_damage_subsurfaces(child); |
| 2880 | } |
| 2881 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2882 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2883 | weston_surface_commit_subsurface_order(struct weston_surface *surface) |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2884 | { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2885 | struct weston_subsurface *sub; |
| 2886 | |
| 2887 | wl_list_for_each_reverse(sub, &surface->subsurface_list_pending, |
| 2888 | parent_link_pending) { |
| 2889 | wl_list_remove(&sub->parent_link); |
| 2890 | wl_list_insert(&surface->subsurface_list, &sub->parent_link); |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 2891 | |
| 2892 | if (sub->reordered) |
| 2893 | weston_surface_damage_subsurfaces(sub); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2894 | } |
| 2895 | } |
| 2896 | |
| 2897 | static void |
Pekka Paalanen | 04baea5 | 2016-04-26 15:50:58 +0300 | [diff] [blame] | 2898 | weston_surface_build_buffer_matrix(const struct weston_surface *surface, |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 2899 | struct weston_matrix *matrix) |
| 2900 | { |
Pekka Paalanen | 04baea5 | 2016-04-26 15:50:58 +0300 | [diff] [blame] | 2901 | const struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 2902 | double src_width, src_height, dest_width, dest_height; |
| 2903 | |
| 2904 | weston_matrix_init(matrix); |
| 2905 | |
| 2906 | if (vp->buffer.src_width == wl_fixed_from_int(-1)) { |
| 2907 | src_width = surface->width_from_buffer; |
| 2908 | src_height = surface->height_from_buffer; |
| 2909 | } else { |
| 2910 | src_width = wl_fixed_to_double(vp->buffer.src_width); |
| 2911 | src_height = wl_fixed_to_double(vp->buffer.src_height); |
| 2912 | } |
| 2913 | |
| 2914 | if (vp->surface.width == -1) { |
| 2915 | dest_width = src_width; |
| 2916 | dest_height = src_height; |
| 2917 | } else { |
| 2918 | dest_width = vp->surface.width; |
| 2919 | dest_height = vp->surface.height; |
| 2920 | } |
| 2921 | |
| 2922 | if (src_width != dest_width || src_height != dest_height) |
| 2923 | weston_matrix_scale(matrix, |
| 2924 | src_width / dest_width, |
| 2925 | src_height / dest_height, 1); |
| 2926 | |
| 2927 | if (vp->buffer.src_width != wl_fixed_from_int(-1)) |
| 2928 | weston_matrix_translate(matrix, |
| 2929 | wl_fixed_to_double(vp->buffer.src_x), |
| 2930 | wl_fixed_to_double(vp->buffer.src_y), |
| 2931 | 0); |
| 2932 | |
| 2933 | switch (vp->buffer.transform) { |
| 2934 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 2935 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 2936 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 2937 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 2938 | weston_matrix_scale(matrix, -1, 1, 1); |
| 2939 | weston_matrix_translate(matrix, |
| 2940 | surface->width_from_buffer, 0, 0); |
| 2941 | break; |
| 2942 | } |
| 2943 | |
| 2944 | switch (vp->buffer.transform) { |
| 2945 | default: |
| 2946 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 2947 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 2948 | break; |
| 2949 | case WL_OUTPUT_TRANSFORM_90: |
| 2950 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 2951 | weston_matrix_rotate_xy(matrix, 0, 1); |
| 2952 | weston_matrix_translate(matrix, |
| 2953 | surface->height_from_buffer, 0, 0); |
| 2954 | break; |
| 2955 | case WL_OUTPUT_TRANSFORM_180: |
| 2956 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 2957 | weston_matrix_rotate_xy(matrix, -1, 0); |
| 2958 | weston_matrix_translate(matrix, |
| 2959 | surface->width_from_buffer, |
| 2960 | surface->height_from_buffer, 0); |
| 2961 | break; |
| 2962 | case WL_OUTPUT_TRANSFORM_270: |
| 2963 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 2964 | weston_matrix_rotate_xy(matrix, 0, -1); |
| 2965 | weston_matrix_translate(matrix, |
| 2966 | 0, surface->width_from_buffer, 0); |
| 2967 | break; |
| 2968 | } |
| 2969 | |
| 2970 | weston_matrix_scale(matrix, vp->buffer.scale, vp->buffer.scale, 1); |
| 2971 | } |
| 2972 | |
Pekka Paalanen | d9aae9c | 2016-04-26 13:46:38 +0300 | [diff] [blame] | 2973 | /** |
| 2974 | * Compute a + b > c while being safe to overflows. |
| 2975 | */ |
| 2976 | static bool |
| 2977 | fixed_sum_gt(wl_fixed_t a, wl_fixed_t b, wl_fixed_t c) |
| 2978 | { |
| 2979 | return (int64_t)a + (int64_t)b > (int64_t)c; |
| 2980 | } |
| 2981 | |
| 2982 | static bool |
| 2983 | weston_surface_is_pending_viewport_source_valid( |
| 2984 | const struct weston_surface *surface) |
| 2985 | { |
| 2986 | const struct weston_surface_state *pend = &surface->pending; |
| 2987 | const struct weston_buffer_viewport *vp = &pend->buffer_viewport; |
| 2988 | int width_from_buffer = 0; |
| 2989 | int height_from_buffer = 0; |
| 2990 | wl_fixed_t w; |
| 2991 | wl_fixed_t h; |
| 2992 | |
| 2993 | /* If viewport source rect is not set, it is always ok. */ |
| 2994 | if (vp->buffer.src_width == wl_fixed_from_int(-1)) |
| 2995 | return true; |
| 2996 | |
| 2997 | if (pend->newly_attached) { |
| 2998 | if (pend->buffer) { |
| 2999 | convert_size_by_transform_scale(&width_from_buffer, |
| 3000 | &height_from_buffer, |
| 3001 | pend->buffer->width, |
| 3002 | pend->buffer->height, |
| 3003 | vp->buffer.transform, |
| 3004 | vp->buffer.scale); |
| 3005 | } else { |
| 3006 | /* No buffer: viewport is irrelevant. */ |
| 3007 | return true; |
| 3008 | } |
| 3009 | } else { |
| 3010 | width_from_buffer = surface->width_from_buffer; |
| 3011 | height_from_buffer = surface->height_from_buffer; |
| 3012 | } |
| 3013 | |
| 3014 | assert((width_from_buffer == 0) == (height_from_buffer == 0)); |
| 3015 | assert(width_from_buffer >= 0 && height_from_buffer >= 0); |
| 3016 | |
| 3017 | /* No buffer: viewport is irrelevant. */ |
| 3018 | if (width_from_buffer == 0 || height_from_buffer == 0) |
| 3019 | return true; |
| 3020 | |
| 3021 | /* overflow checks for wl_fixed_from_int() */ |
| 3022 | if (width_from_buffer > wl_fixed_to_int(INT32_MAX)) |
| 3023 | return false; |
| 3024 | if (height_from_buffer > wl_fixed_to_int(INT32_MAX)) |
| 3025 | return false; |
| 3026 | |
| 3027 | w = wl_fixed_from_int(width_from_buffer); |
| 3028 | h = wl_fixed_from_int(height_from_buffer); |
| 3029 | |
| 3030 | if (fixed_sum_gt(vp->buffer.src_x, vp->buffer.src_width, w)) |
| 3031 | return false; |
| 3032 | if (fixed_sum_gt(vp->buffer.src_y, vp->buffer.src_height, h)) |
| 3033 | return false; |
| 3034 | |
| 3035 | return true; |
| 3036 | } |
| 3037 | |
Pekka Paalanen | bb32ccc | 2016-04-26 14:28:28 +0300 | [diff] [blame] | 3038 | static bool |
| 3039 | fixed_is_integer(wl_fixed_t v) |
| 3040 | { |
| 3041 | return (v & 0xff) == 0; |
| 3042 | } |
| 3043 | |
| 3044 | static bool |
| 3045 | weston_surface_is_pending_viewport_dst_size_int( |
| 3046 | const struct weston_surface *surface) |
| 3047 | { |
| 3048 | const struct weston_buffer_viewport *vp = |
| 3049 | &surface->pending.buffer_viewport; |
| 3050 | |
| 3051 | if (vp->surface.width != -1) { |
| 3052 | assert(vp->surface.width > 0 && vp->surface.height > 0); |
| 3053 | return true; |
| 3054 | } |
| 3055 | |
| 3056 | return fixed_is_integer(vp->buffer.src_width) && |
| 3057 | fixed_is_integer(vp->buffer.src_height); |
| 3058 | } |
| 3059 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3060 | /* Translate pending damage in buffer co-ordinates to surface |
| 3061 | * co-ordinates and union it with a pixman_region32_t. |
| 3062 | * This should only be called after the buffer is attached. |
| 3063 | */ |
| 3064 | static void |
| 3065 | apply_damage_buffer(pixman_region32_t *dest, |
| 3066 | struct weston_surface *surface, |
| 3067 | struct weston_surface_state *state) |
| 3068 | { |
| 3069 | struct weston_buffer *buffer = surface->buffer_ref.buffer; |
| 3070 | |
| 3071 | /* wl_surface.damage_buffer needs to be clipped to the buffer, |
| 3072 | * translated into surface co-ordinates and unioned with |
| 3073 | * any other surface damage. |
| 3074 | * None of this makes sense if there is no buffer though. |
| 3075 | */ |
| 3076 | if (buffer && pixman_region32_not_empty(&state->damage_buffer)) { |
| 3077 | pixman_region32_t buffer_damage; |
| 3078 | |
| 3079 | pixman_region32_intersect_rect(&state->damage_buffer, |
| 3080 | &state->damage_buffer, |
| 3081 | 0, 0, buffer->width, |
| 3082 | buffer->height); |
| 3083 | pixman_region32_init(&buffer_damage); |
| 3084 | weston_matrix_transform_region(&buffer_damage, |
| 3085 | &surface->buffer_to_surface_matrix, |
| 3086 | &state->damage_buffer); |
| 3087 | pixman_region32_union(dest, dest, &buffer_damage); |
| 3088 | pixman_region32_fini(&buffer_damage); |
| 3089 | } |
| 3090 | /* We should clear this on commit even if there was no buffer */ |
| 3091 | pixman_region32_clear(&state->damage_buffer); |
| 3092 | } |
| 3093 | |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 3094 | static void |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3095 | weston_surface_commit_state(struct weston_surface *surface, |
| 3096 | struct weston_surface_state *state) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3097 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3098 | struct weston_view *view; |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 3099 | pixman_region32_t opaque; |
| 3100 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3101 | /* wl_surface.set_buffer_transform */ |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3102 | /* wl_surface.set_buffer_scale */ |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 3103 | /* wp_viewport.set_source */ |
| 3104 | /* wp_viewport.set_destination */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3105 | surface->buffer_viewport = state->buffer_viewport; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3106 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3107 | /* wl_surface.attach */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3108 | if (state->newly_attached) |
| 3109 | weston_surface_attach(surface, state->buffer); |
| 3110 | weston_surface_state_set_buffer(state, NULL); |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3111 | |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 3112 | weston_surface_build_buffer_matrix(surface, |
| 3113 | &surface->surface_to_buffer_matrix); |
| 3114 | weston_matrix_invert(&surface->buffer_to_surface_matrix, |
| 3115 | &surface->surface_to_buffer_matrix); |
| 3116 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3117 | if (state->newly_attached || state->buffer_viewport.changed) { |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3118 | weston_surface_update_size(surface); |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3119 | if (surface->committed) |
| 3120 | surface->committed(surface, state->sx, state->sy); |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3121 | } |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3122 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3123 | state->sx = 0; |
| 3124 | state->sy = 0; |
| 3125 | state->newly_attached = 0; |
| 3126 | state->buffer_viewport.changed = 0; |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 3127 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3128 | /* wl_surface.damage and wl_surface.damage_buffer */ |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3129 | if (weston_timeline_enabled_ && |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3130 | (pixman_region32_not_empty(&state->damage_surface) || |
| 3131 | pixman_region32_not_empty(&state->damage_buffer))) |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3132 | TL_POINT("core_commit_damage", TLP_SURFACE(surface), TLP_END); |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3133 | |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 3134 | pixman_region32_union(&surface->damage, &surface->damage, |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3135 | &state->damage_surface); |
| 3136 | |
| 3137 | apply_damage_buffer(&surface->damage, surface, state); |
| 3138 | |
Kristian Høgsberg | 4d0214c | 2012-11-08 11:36:02 -0500 | [diff] [blame] | 3139 | pixman_region32_intersect_rect(&surface->damage, &surface->damage, |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 3140 | 0, 0, surface->width, surface->height); |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3141 | pixman_region32_clear(&state->damage_surface); |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 3142 | |
| 3143 | /* wl_surface.set_opaque_region */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3144 | pixman_region32_init(&opaque); |
| 3145 | pixman_region32_intersect_rect(&opaque, &state->opaque, |
| 3146 | 0, 0, surface->width, surface->height); |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 3147 | |
| 3148 | if (!pixman_region32_equal(&opaque, &surface->opaque)) { |
| 3149 | pixman_region32_copy(&surface->opaque, &opaque); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3150 | wl_list_for_each(view, &surface->views, surface_link) |
| 3151 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 3152 | } |
| 3153 | |
| 3154 | pixman_region32_fini(&opaque); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3155 | |
| 3156 | /* wl_surface.set_input_region */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3157 | pixman_region32_intersect_rect(&surface->input, &state->input, |
| 3158 | 0, 0, surface->width, surface->height); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3159 | |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 3160 | /* wl_surface.frame */ |
| 3161 | wl_list_insert_list(&surface->frame_callback_list, |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3162 | &state->frame_callback_list); |
| 3163 | wl_list_init(&state->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3164 | |
| 3165 | /* XXX: |
| 3166 | * What should happen with a feedback request, if there |
| 3167 | * is no wl_buffer attached for this commit? |
| 3168 | */ |
| 3169 | |
| 3170 | /* presentation.feedback */ |
| 3171 | wl_list_insert_list(&surface->feedback_list, |
| 3172 | &state->feedback_list); |
| 3173 | wl_list_init(&state->feedback_list); |
Jonas Ådahl | 5d9ca27 | 2016-07-22 17:48:03 +0800 | [diff] [blame] | 3174 | |
| 3175 | wl_signal_emit(&surface->commit_signal, surface); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3176 | } |
| 3177 | |
| 3178 | static void |
| 3179 | weston_surface_commit(struct weston_surface *surface) |
| 3180 | { |
| 3181 | weston_surface_commit_state(surface, &surface->pending); |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 3182 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3183 | weston_surface_commit_subsurface_order(surface); |
| 3184 | |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3185 | weston_surface_schedule_repaint(surface); |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3186 | } |
| 3187 | |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3188 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3189 | weston_subsurface_commit(struct weston_subsurface *sub); |
| 3190 | |
| 3191 | static void |
| 3192 | weston_subsurface_parent_commit(struct weston_subsurface *sub, |
| 3193 | int parent_is_synchronized); |
| 3194 | |
| 3195 | static void |
| 3196 | surface_commit(struct wl_client *client, struct wl_resource *resource) |
| 3197 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3198 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3199 | struct weston_subsurface *sub = weston_surface_to_subsurface(surface); |
| 3200 | |
Pekka Paalanen | d9aae9c | 2016-04-26 13:46:38 +0300 | [diff] [blame] | 3201 | if (!weston_surface_is_pending_viewport_source_valid(surface)) { |
| 3202 | assert(surface->viewport_resource); |
| 3203 | |
| 3204 | wl_resource_post_error(surface->viewport_resource, |
| 3205 | WP_VIEWPORT_ERROR_OUT_OF_BUFFER, |
| 3206 | "wl_surface@%d has viewport source outside buffer", |
| 3207 | wl_resource_get_id(resource)); |
| 3208 | return; |
| 3209 | } |
| 3210 | |
Pekka Paalanen | bb32ccc | 2016-04-26 14:28:28 +0300 | [diff] [blame] | 3211 | if (!weston_surface_is_pending_viewport_dst_size_int(surface)) { |
| 3212 | assert(surface->viewport_resource); |
| 3213 | |
| 3214 | wl_resource_post_error(surface->viewport_resource, |
| 3215 | WP_VIEWPORT_ERROR_BAD_SIZE, |
| 3216 | "wl_surface@%d viewport dst size not integer", |
| 3217 | wl_resource_get_id(resource)); |
| 3218 | return; |
| 3219 | } |
| 3220 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3221 | if (sub) { |
| 3222 | weston_subsurface_commit(sub); |
| 3223 | return; |
| 3224 | } |
| 3225 | |
| 3226 | weston_surface_commit(surface); |
| 3227 | |
| 3228 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
| 3229 | if (sub->surface != surface) |
| 3230 | weston_subsurface_parent_commit(sub, 0); |
| 3231 | } |
| 3232 | } |
| 3233 | |
| 3234 | static void |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3235 | surface_set_buffer_transform(struct wl_client *client, |
| 3236 | struct wl_resource *resource, int transform) |
| 3237 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3238 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3239 | |
Jonny Lamb | a55f139 | 2014-05-30 12:07:15 +0200 | [diff] [blame] | 3240 | /* if wl_output.transform grows more members this will need to be updated. */ |
| 3241 | if (transform < 0 || |
| 3242 | transform > WL_OUTPUT_TRANSFORM_FLIPPED_270) { |
| 3243 | wl_resource_post_error(resource, |
| 3244 | WL_SURFACE_ERROR_INVALID_TRANSFORM, |
| 3245 | "buffer transform must be a valid transform " |
| 3246 | "('%d' specified)", transform); |
| 3247 | return; |
| 3248 | } |
| 3249 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 3250 | surface->pending.buffer_viewport.buffer.transform = transform; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3251 | surface->pending.buffer_viewport.changed = 1; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3252 | } |
| 3253 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3254 | static void |
| 3255 | surface_set_buffer_scale(struct wl_client *client, |
| 3256 | struct wl_resource *resource, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 3257 | int32_t scale) |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3258 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3259 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3260 | |
Jonny Lamb | a55f139 | 2014-05-30 12:07:15 +0200 | [diff] [blame] | 3261 | if (scale < 1) { |
| 3262 | wl_resource_post_error(resource, |
| 3263 | WL_SURFACE_ERROR_INVALID_SCALE, |
| 3264 | "buffer scale must be at least one " |
| 3265 | "('%d' specified)", scale); |
| 3266 | return; |
| 3267 | } |
| 3268 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 3269 | surface->pending.buffer_viewport.buffer.scale = scale; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3270 | surface->pending.buffer_viewport.changed = 1; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3271 | } |
| 3272 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 3273 | static const struct wl_surface_interface surface_interface = { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3274 | surface_destroy, |
| 3275 | surface_attach, |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3276 | surface_damage, |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3277 | surface_frame, |
| 3278 | surface_set_opaque_region, |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3279 | surface_set_input_region, |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3280 | surface_commit, |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3281 | surface_set_buffer_transform, |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3282 | surface_set_buffer_scale, |
| 3283 | surface_damage_buffer |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3284 | }; |
| 3285 | |
| 3286 | static void |
| 3287 | compositor_create_surface(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 3288 | struct wl_resource *resource, uint32_t id) |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3289 | { |
Kristian Høgsberg | c2d7042 | 2013-06-25 15:34:33 -0400 | [diff] [blame] | 3290 | struct weston_compositor *ec = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3291 | struct weston_surface *surface; |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3292 | |
Kristian Høgsberg | 18c9300 | 2012-01-27 11:58:31 -0500 | [diff] [blame] | 3293 | surface = weston_surface_create(ec); |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 3294 | if (surface == NULL) { |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 3295 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3296 | return; |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 3297 | } |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3298 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3299 | surface->resource = |
| 3300 | wl_resource_create(client, &wl_surface_interface, |
| 3301 | wl_resource_get_version(resource), id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 3302 | if (surface->resource == NULL) { |
| 3303 | weston_surface_destroy(surface); |
| 3304 | wl_resource_post_no_memory(resource); |
| 3305 | return; |
| 3306 | } |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3307 | wl_resource_set_implementation(surface->resource, &surface_interface, |
| 3308 | surface, destroy_surface); |
Kristian Høgsberg | f03a04a | 2014-04-06 22:04:50 -0700 | [diff] [blame] | 3309 | |
| 3310 | wl_signal_emit(&ec->create_surface_signal, surface); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3311 | } |
| 3312 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3313 | static void |
| 3314 | destroy_region(struct wl_resource *resource) |
| 3315 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 3316 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3317 | |
| 3318 | pixman_region32_fini(®ion->region); |
| 3319 | free(region); |
| 3320 | } |
| 3321 | |
| 3322 | static void |
| 3323 | region_destroy(struct wl_client *client, struct wl_resource *resource) |
| 3324 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3325 | wl_resource_destroy(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3326 | } |
| 3327 | |
| 3328 | static void |
| 3329 | region_add(struct wl_client *client, struct wl_resource *resource, |
| 3330 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 3331 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 3332 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3333 | |
| 3334 | pixman_region32_union_rect(®ion->region, ®ion->region, |
| 3335 | x, y, width, height); |
| 3336 | } |
| 3337 | |
| 3338 | static void |
| 3339 | region_subtract(struct wl_client *client, struct wl_resource *resource, |
| 3340 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 3341 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 3342 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3343 | pixman_region32_t rect; |
| 3344 | |
| 3345 | pixman_region32_init_rect(&rect, x, y, width, height); |
| 3346 | pixman_region32_subtract(®ion->region, ®ion->region, &rect); |
| 3347 | pixman_region32_fini(&rect); |
| 3348 | } |
| 3349 | |
| 3350 | static const struct wl_region_interface region_interface = { |
| 3351 | region_destroy, |
| 3352 | region_add, |
| 3353 | region_subtract |
| 3354 | }; |
| 3355 | |
| 3356 | static void |
| 3357 | compositor_create_region(struct wl_client *client, |
| 3358 | struct wl_resource *resource, uint32_t id) |
| 3359 | { |
| 3360 | struct weston_region *region; |
| 3361 | |
| 3362 | region = malloc(sizeof *region); |
| 3363 | if (region == NULL) { |
| 3364 | wl_resource_post_no_memory(resource); |
| 3365 | return; |
| 3366 | } |
| 3367 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3368 | pixman_region32_init(®ion->region); |
| 3369 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3370 | region->resource = |
| 3371 | wl_resource_create(client, &wl_region_interface, 1, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 3372 | if (region->resource == NULL) { |
| 3373 | free(region); |
| 3374 | wl_resource_post_no_memory(resource); |
| 3375 | return; |
| 3376 | } |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3377 | wl_resource_set_implementation(region->resource, ®ion_interface, |
| 3378 | region, destroy_region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3379 | } |
| 3380 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 3381 | static const struct wl_compositor_interface compositor_interface = { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3382 | compositor_create_surface, |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3383 | compositor_create_region |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3384 | }; |
| 3385 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3386 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3387 | weston_subsurface_commit_from_cache(struct weston_subsurface *sub) |
| 3388 | { |
| 3389 | struct weston_surface *surface = sub->surface; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3390 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3391 | weston_surface_commit_state(surface, &sub->cached); |
| 3392 | weston_buffer_reference(&sub->cached_buffer_ref, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3393 | |
| 3394 | weston_surface_commit_subsurface_order(surface); |
| 3395 | |
| 3396 | weston_surface_schedule_repaint(surface); |
| 3397 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3398 | sub->has_cached_data = 0; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3399 | } |
| 3400 | |
| 3401 | static void |
| 3402 | weston_subsurface_commit_to_cache(struct weston_subsurface *sub) |
| 3403 | { |
| 3404 | struct weston_surface *surface = sub->surface; |
| 3405 | |
| 3406 | /* |
| 3407 | * If this commit would cause the surface to move by the |
| 3408 | * attach(dx, dy) parameters, the old damage region must be |
| 3409 | * translated to correspond to the new surface coordinate system |
Chris Michael | 062edf2 | 2015-11-26 11:30:00 -0500 | [diff] [blame] | 3410 | * origin. |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3411 | */ |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3412 | pixman_region32_translate(&sub->cached.damage_surface, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3413 | -surface->pending.sx, -surface->pending.sy); |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3414 | pixman_region32_union(&sub->cached.damage_surface, |
| 3415 | &sub->cached.damage_surface, |
| 3416 | &surface->pending.damage_surface); |
| 3417 | pixman_region32_clear(&surface->pending.damage_surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3418 | |
| 3419 | if (surface->pending.newly_attached) { |
| 3420 | sub->cached.newly_attached = 1; |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3421 | weston_surface_state_set_buffer(&sub->cached, |
| 3422 | surface->pending.buffer); |
| 3423 | weston_buffer_reference(&sub->cached_buffer_ref, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3424 | surface->pending.buffer); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3425 | weston_presentation_feedback_discard_list( |
| 3426 | &sub->cached.feedback_list); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3427 | } |
| 3428 | sub->cached.sx += surface->pending.sx; |
| 3429 | sub->cached.sy += surface->pending.sy; |
Pekka Paalanen | 260ba38 | 2014-03-14 14:38:12 +0200 | [diff] [blame] | 3430 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3431 | apply_damage_buffer(&sub->cached.damage_surface, surface, &surface->pending); |
| 3432 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3433 | sub->cached.buffer_viewport.changed |= |
| 3434 | surface->pending.buffer_viewport.changed; |
| 3435 | sub->cached.buffer_viewport.buffer = |
| 3436 | surface->pending.buffer_viewport.buffer; |
| 3437 | sub->cached.buffer_viewport.surface = |
| 3438 | surface->pending.buffer_viewport.surface; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3439 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3440 | weston_surface_reset_pending_buffer(surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3441 | |
| 3442 | pixman_region32_copy(&sub->cached.opaque, &surface->pending.opaque); |
| 3443 | |
| 3444 | pixman_region32_copy(&sub->cached.input, &surface->pending.input); |
| 3445 | |
| 3446 | wl_list_insert_list(&sub->cached.frame_callback_list, |
| 3447 | &surface->pending.frame_callback_list); |
| 3448 | wl_list_init(&surface->pending.frame_callback_list); |
| 3449 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3450 | wl_list_insert_list(&sub->cached.feedback_list, |
| 3451 | &surface->pending.feedback_list); |
| 3452 | wl_list_init(&surface->pending.feedback_list); |
| 3453 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3454 | sub->has_cached_data = 1; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3455 | } |
| 3456 | |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 3457 | static bool |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3458 | weston_subsurface_is_synchronized(struct weston_subsurface *sub) |
| 3459 | { |
| 3460 | while (sub) { |
| 3461 | if (sub->synchronized) |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 3462 | return true; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3463 | |
| 3464 | if (!sub->parent) |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 3465 | return false; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3466 | |
| 3467 | sub = weston_surface_to_subsurface(sub->parent); |
| 3468 | } |
| 3469 | |
Carlos Olmedo Escobar | 61a9bf5 | 2014-11-04 14:38:39 +0100 | [diff] [blame] | 3470 | return false; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3471 | } |
| 3472 | |
| 3473 | static void |
| 3474 | weston_subsurface_commit(struct weston_subsurface *sub) |
| 3475 | { |
| 3476 | struct weston_surface *surface = sub->surface; |
| 3477 | struct weston_subsurface *tmp; |
| 3478 | |
| 3479 | /* Recursive check for effectively synchronized. */ |
| 3480 | if (weston_subsurface_is_synchronized(sub)) { |
| 3481 | weston_subsurface_commit_to_cache(sub); |
| 3482 | } else { |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3483 | if (sub->has_cached_data) { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3484 | /* flush accumulated state from cache */ |
| 3485 | weston_subsurface_commit_to_cache(sub); |
| 3486 | weston_subsurface_commit_from_cache(sub); |
| 3487 | } else { |
| 3488 | weston_surface_commit(surface); |
| 3489 | } |
| 3490 | |
| 3491 | wl_list_for_each(tmp, &surface->subsurface_list, parent_link) { |
| 3492 | if (tmp->surface != surface) |
| 3493 | weston_subsurface_parent_commit(tmp, 0); |
| 3494 | } |
| 3495 | } |
| 3496 | } |
| 3497 | |
| 3498 | static void |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3499 | weston_subsurface_synchronized_commit(struct weston_subsurface *sub) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3500 | { |
| 3501 | struct weston_surface *surface = sub->surface; |
| 3502 | struct weston_subsurface *tmp; |
| 3503 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3504 | /* From now on, commit_from_cache the whole sub-tree, regardless of |
| 3505 | * the synchronized mode of each child. This sub-surface or some |
| 3506 | * of its ancestors were synchronized, so we are synchronized |
| 3507 | * all the way down. |
| 3508 | */ |
| 3509 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3510 | if (sub->has_cached_data) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3511 | weston_subsurface_commit_from_cache(sub); |
| 3512 | |
| 3513 | wl_list_for_each(tmp, &surface->subsurface_list, parent_link) { |
| 3514 | if (tmp->surface != surface) |
| 3515 | weston_subsurface_parent_commit(tmp, 1); |
| 3516 | } |
| 3517 | } |
| 3518 | |
| 3519 | static void |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3520 | weston_subsurface_parent_commit(struct weston_subsurface *sub, |
| 3521 | int parent_is_synchronized) |
| 3522 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3523 | struct weston_view *view; |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3524 | if (sub->position.set) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3525 | wl_list_for_each(view, &sub->surface->views, surface_link) |
| 3526 | weston_view_set_position(view, |
| 3527 | sub->position.x, |
| 3528 | sub->position.y); |
| 3529 | |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3530 | sub->position.set = 0; |
| 3531 | } |
| 3532 | |
| 3533 | if (parent_is_synchronized || sub->synchronized) |
| 3534 | weston_subsurface_synchronized_commit(sub); |
| 3535 | } |
| 3536 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3537 | static int |
| 3538 | subsurface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 3539 | { |
| 3540 | return snprintf(buf, len, "sub-surface"); |
| 3541 | } |
| 3542 | |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3543 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3544 | subsurface_committed(struct weston_surface *surface, int32_t dx, int32_t dy) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3545 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3546 | struct weston_view *view; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3547 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3548 | wl_list_for_each(view, &surface->views, surface_link) |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3549 | weston_view_set_position(view, |
| 3550 | view->geometry.x + dx, |
| 3551 | view->geometry.y + dy); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3552 | |
| 3553 | /* No need to check parent mappedness, because if parent is not |
| 3554 | * mapped, parent is not in a visible layer, so this sub-surface |
| 3555 | * will not be drawn either. |
| 3556 | */ |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 3557 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3558 | if (!weston_surface_is_mapped(surface)) { |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 3559 | surface->is_mapped = true; |
Pekka Paalanen | eb3cf22 | 2014-06-30 11:52:07 +0300 | [diff] [blame] | 3560 | |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 3561 | /* Cannot call weston_view_update_transform(), |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3562 | * because that would call it also for the parent surface, |
| 3563 | * which might not be mapped yet. That would lead to |
| 3564 | * inconsistent state, where the window could never be |
| 3565 | * mapped. |
| 3566 | * |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 3567 | * Instead just force the is_mapped flag on, to make |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3568 | * weston_surface_is_mapped() return true, so that when the |
| 3569 | * parent surface does get mapped, this one will get |
Pekka Paalanen | eb3cf22 | 2014-06-30 11:52:07 +0300 | [diff] [blame] | 3570 | * included, too. See view_list_add(). |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3571 | */ |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3572 | } |
| 3573 | } |
| 3574 | |
| 3575 | static struct weston_subsurface * |
| 3576 | weston_surface_to_subsurface(struct weston_surface *surface) |
| 3577 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3578 | if (surface->committed == subsurface_committed) |
| 3579 | return surface->committed_private; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3580 | |
| 3581 | return NULL; |
| 3582 | } |
| 3583 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3584 | WL_EXPORT struct weston_surface * |
| 3585 | weston_surface_get_main_surface(struct weston_surface *surface) |
| 3586 | { |
| 3587 | struct weston_subsurface *sub; |
| 3588 | |
| 3589 | while (surface && (sub = weston_surface_to_subsurface(surface))) |
| 3590 | surface = sub->parent; |
| 3591 | |
| 3592 | return surface; |
| 3593 | } |
| 3594 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3595 | WL_EXPORT int |
| 3596 | weston_surface_set_role(struct weston_surface *surface, |
| 3597 | const char *role_name, |
| 3598 | struct wl_resource *error_resource, |
| 3599 | uint32_t error_code) |
| 3600 | { |
| 3601 | assert(role_name); |
| 3602 | |
| 3603 | if (surface->role_name == NULL || |
| 3604 | surface->role_name == role_name || |
| 3605 | strcmp(surface->role_name, role_name) == 0) { |
| 3606 | surface->role_name = role_name; |
| 3607 | |
| 3608 | return 0; |
| 3609 | } |
| 3610 | |
| 3611 | wl_resource_post_error(error_resource, error_code, |
| 3612 | "Cannot assign role %s to wl_surface@%d," |
| 3613 | " already has role %s\n", |
| 3614 | role_name, |
| 3615 | wl_resource_get_id(surface->resource), |
| 3616 | surface->role_name); |
| 3617 | return -1; |
| 3618 | } |
| 3619 | |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 3620 | WL_EXPORT const char * |
| 3621 | weston_surface_get_role(struct weston_surface *surface) |
| 3622 | { |
| 3623 | return surface->role_name; |
| 3624 | } |
| 3625 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3626 | WL_EXPORT void |
| 3627 | weston_surface_set_label_func(struct weston_surface *surface, |
| 3628 | int (*desc)(struct weston_surface *, |
| 3629 | char *, size_t)) |
| 3630 | { |
| 3631 | surface->get_label = desc; |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3632 | surface->timeline.force_refresh = 1; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3633 | } |
| 3634 | |
Pekka Paalanen | c647ed7 | 2015-02-09 13:16:57 +0200 | [diff] [blame] | 3635 | /** Get the size of surface contents |
| 3636 | * |
| 3637 | * \param surface The surface to query. |
| 3638 | * \param width Returns the width of raw contents. |
| 3639 | * \param height Returns the height of raw contents. |
| 3640 | * |
| 3641 | * Retrieves the raw surface content size in pixels for the given surface. |
| 3642 | * This is the whole content size in buffer pixels. If the surface |
| 3643 | * has no content or the renderer does not implement this feature, |
| 3644 | * zeroes are returned. |
| 3645 | * |
| 3646 | * This function is used to determine the buffer size needed for |
| 3647 | * a weston_surface_copy_content() call. |
| 3648 | */ |
| 3649 | WL_EXPORT void |
| 3650 | weston_surface_get_content_size(struct weston_surface *surface, |
| 3651 | int *width, int *height) |
| 3652 | { |
| 3653 | struct weston_renderer *rer = surface->compositor->renderer; |
| 3654 | |
| 3655 | if (!rer->surface_get_content_size) { |
| 3656 | *width = 0; |
| 3657 | *height = 0; |
| 3658 | return; |
| 3659 | } |
| 3660 | |
| 3661 | rer->surface_get_content_size(surface, width, height); |
| 3662 | } |
| 3663 | |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 3664 | /** Get the bounding box of a surface and its subsurfaces |
| 3665 | * |
| 3666 | * \param surface The surface to query. |
| 3667 | * \return The bounding box relative to the surface origin. |
| 3668 | * |
| 3669 | */ |
| 3670 | WL_EXPORT struct weston_geometry |
| 3671 | weston_surface_get_bounding_box(struct weston_surface *surface) |
| 3672 | { |
| 3673 | pixman_region32_t region; |
| 3674 | pixman_box32_t *box; |
| 3675 | struct weston_subsurface *subsurface; |
| 3676 | |
| 3677 | pixman_region32_init_rect(®ion, |
| 3678 | 0, 0, |
| 3679 | surface->width, surface->height); |
| 3680 | |
| 3681 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) |
| 3682 | pixman_region32_union_rect(®ion, ®ion, |
| 3683 | subsurface->position.x, |
| 3684 | subsurface->position.y, |
| 3685 | subsurface->surface->width, |
| 3686 | subsurface->surface->height); |
| 3687 | |
| 3688 | box = pixman_region32_extents(®ion); |
| 3689 | struct weston_geometry geometry = { |
| 3690 | .x = box->x1, |
| 3691 | .y = box->y1, |
| 3692 | .width = box->x2 - box->x1, |
| 3693 | .height = box->y2 - box->y1, |
| 3694 | }; |
| 3695 | |
| 3696 | pixman_region32_fini(®ion); |
| 3697 | |
| 3698 | return geometry; |
| 3699 | } |
| 3700 | |
Pekka Paalanen | c647ed7 | 2015-02-09 13:16:57 +0200 | [diff] [blame] | 3701 | /** Copy surface contents to system memory. |
| 3702 | * |
| 3703 | * \param surface The surface to copy from. |
| 3704 | * \param target Pointer to the target memory buffer. |
| 3705 | * \param size Size of the target buffer in bytes. |
| 3706 | * \param src_x X location on contents to copy from. |
| 3707 | * \param src_y Y location on contents to copy from. |
| 3708 | * \param width Width in pixels of the area to copy. |
| 3709 | * \param height Height in pixels of the area to copy. |
| 3710 | * \return 0 for success, -1 for failure. |
| 3711 | * |
| 3712 | * Surface contents are maintained by the renderer. They can be in a |
| 3713 | * reserved weston_buffer or as a copy, e.g. a GL texture, or something |
| 3714 | * else. |
| 3715 | * |
| 3716 | * Surface contents are copied into memory pointed to by target, |
| 3717 | * which has size bytes of space available. The target memory |
| 3718 | * may be larger than needed, but being smaller returns an error. |
| 3719 | * The extra bytes in target may or may not be written; their content is |
| 3720 | * unspecified. Size must be large enough to hold the image. |
| 3721 | * |
| 3722 | * The image in the target memory will be arranged in rows from |
| 3723 | * top to bottom, and pixels on a row from left to right. The pixel |
| 3724 | * format is PIXMAN_a8b8g8r8, 4 bytes per pixel, and stride is exactly |
| 3725 | * width * 4. |
| 3726 | * |
| 3727 | * Parameters src_x and src_y define the upper-left corner in buffer |
| 3728 | * coordinates (pixels) to copy from. Parameters width and height |
| 3729 | * define the size of the area to copy in pixels. |
| 3730 | * |
| 3731 | * The rectangle defined by src_x, src_y, width, height must fit in |
| 3732 | * the surface contents. Otherwise an error is returned. |
| 3733 | * |
| 3734 | * Use surface_get_data_size to determine the content size; the |
| 3735 | * needed target buffer size and rectangle limits. |
| 3736 | * |
| 3737 | * CURRENT IMPLEMENTATION RESTRICTIONS: |
| 3738 | * - the machine must be little-endian due to Pixman formats. |
| 3739 | * |
| 3740 | * NOTE: Pixman formats are premultiplied. |
| 3741 | */ |
| 3742 | WL_EXPORT int |
| 3743 | weston_surface_copy_content(struct weston_surface *surface, |
| 3744 | void *target, size_t size, |
| 3745 | int src_x, int src_y, |
| 3746 | int width, int height) |
| 3747 | { |
| 3748 | struct weston_renderer *rer = surface->compositor->renderer; |
| 3749 | int cw, ch; |
| 3750 | const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */ |
| 3751 | |
| 3752 | if (!rer->surface_copy_content) |
| 3753 | return -1; |
| 3754 | |
| 3755 | weston_surface_get_content_size(surface, &cw, &ch); |
| 3756 | |
| 3757 | if (src_x < 0 || src_y < 0) |
| 3758 | return -1; |
| 3759 | |
| 3760 | if (width <= 0 || height <= 0) |
| 3761 | return -1; |
| 3762 | |
| 3763 | if (src_x + width > cw || src_y + height > ch) |
| 3764 | return -1; |
| 3765 | |
| 3766 | if (width * bytespp * height > size) |
| 3767 | return -1; |
| 3768 | |
| 3769 | return rer->surface_copy_content(surface, target, size, |
| 3770 | src_x, src_y, width, height); |
| 3771 | } |
| 3772 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3773 | static void |
| 3774 | subsurface_set_position(struct wl_client *client, |
| 3775 | struct wl_resource *resource, int32_t x, int32_t y) |
| 3776 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 3777 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3778 | |
| 3779 | if (!sub) |
| 3780 | return; |
| 3781 | |
| 3782 | sub->position.x = x; |
| 3783 | sub->position.y = y; |
| 3784 | sub->position.set = 1; |
| 3785 | } |
| 3786 | |
| 3787 | static struct weston_subsurface * |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 3788 | subsurface_find_sibling(struct weston_subsurface *sub, |
| 3789 | struct weston_surface *surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3790 | { |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 3791 | struct weston_surface *parent = sub->parent; |
| 3792 | struct weston_subsurface *sibling; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3793 | |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 3794 | wl_list_for_each(sibling, &parent->subsurface_list, parent_link) { |
| 3795 | if (sibling->surface == surface && sibling != sub) |
| 3796 | return sibling; |
| 3797 | } |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3798 | |
| 3799 | return NULL; |
| 3800 | } |
| 3801 | |
| 3802 | static struct weston_subsurface * |
| 3803 | subsurface_sibling_check(struct weston_subsurface *sub, |
| 3804 | struct weston_surface *surface, |
| 3805 | const char *request) |
| 3806 | { |
| 3807 | struct weston_subsurface *sibling; |
| 3808 | |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 3809 | sibling = subsurface_find_sibling(sub, surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3810 | if (!sibling) { |
| 3811 | wl_resource_post_error(sub->resource, |
| 3812 | WL_SUBSURFACE_ERROR_BAD_SURFACE, |
| 3813 | "%s: wl_surface@%d is not a parent or sibling", |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3814 | request, wl_resource_get_id(surface->resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3815 | return NULL; |
| 3816 | } |
| 3817 | |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 3818 | assert(sibling->parent == sub->parent); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3819 | |
| 3820 | return sibling; |
| 3821 | } |
| 3822 | |
| 3823 | static void |
| 3824 | subsurface_place_above(struct wl_client *client, |
| 3825 | struct wl_resource *resource, |
| 3826 | struct wl_resource *sibling_resource) |
| 3827 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 3828 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3829 | struct weston_surface *surface = |
| 3830 | wl_resource_get_user_data(sibling_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3831 | struct weston_subsurface *sibling; |
| 3832 | |
| 3833 | if (!sub) |
| 3834 | return; |
| 3835 | |
| 3836 | sibling = subsurface_sibling_check(sub, surface, "place_above"); |
| 3837 | if (!sibling) |
| 3838 | return; |
| 3839 | |
| 3840 | wl_list_remove(&sub->parent_link_pending); |
| 3841 | wl_list_insert(sibling->parent_link_pending.prev, |
| 3842 | &sub->parent_link_pending); |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 3843 | |
| 3844 | sub->reordered = true; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3845 | } |
| 3846 | |
| 3847 | static void |
| 3848 | subsurface_place_below(struct wl_client *client, |
| 3849 | struct wl_resource *resource, |
| 3850 | struct wl_resource *sibling_resource) |
| 3851 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 3852 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3853 | struct weston_surface *surface = |
| 3854 | wl_resource_get_user_data(sibling_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3855 | struct weston_subsurface *sibling; |
| 3856 | |
| 3857 | if (!sub) |
| 3858 | return; |
| 3859 | |
| 3860 | sibling = subsurface_sibling_check(sub, surface, "place_below"); |
| 3861 | if (!sibling) |
| 3862 | return; |
| 3863 | |
| 3864 | wl_list_remove(&sub->parent_link_pending); |
| 3865 | wl_list_insert(&sibling->parent_link_pending, |
| 3866 | &sub->parent_link_pending); |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 3867 | |
| 3868 | sub->reordered = true; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3869 | } |
| 3870 | |
| 3871 | static void |
| 3872 | subsurface_set_sync(struct wl_client *client, struct wl_resource *resource) |
| 3873 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 3874 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3875 | |
| 3876 | if (sub) |
| 3877 | sub->synchronized = 1; |
| 3878 | } |
| 3879 | |
| 3880 | static void |
| 3881 | subsurface_set_desync(struct wl_client *client, struct wl_resource *resource) |
| 3882 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 3883 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3884 | |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3885 | if (sub && sub->synchronized) { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3886 | sub->synchronized = 0; |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3887 | |
| 3888 | /* If sub became effectively desynchronized, flush. */ |
| 3889 | if (!weston_subsurface_is_synchronized(sub)) |
| 3890 | weston_subsurface_synchronized_commit(sub); |
| 3891 | } |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3892 | } |
| 3893 | |
| 3894 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3895 | weston_subsurface_unlink_parent(struct weston_subsurface *sub) |
| 3896 | { |
| 3897 | wl_list_remove(&sub->parent_link); |
| 3898 | wl_list_remove(&sub->parent_link_pending); |
| 3899 | wl_list_remove(&sub->parent_destroy_listener.link); |
| 3900 | sub->parent = NULL; |
| 3901 | } |
| 3902 | |
| 3903 | static void |
| 3904 | weston_subsurface_destroy(struct weston_subsurface *sub); |
| 3905 | |
| 3906 | static void |
| 3907 | subsurface_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 3908 | { |
| 3909 | struct weston_subsurface *sub = |
| 3910 | container_of(listener, struct weston_subsurface, |
| 3911 | surface_destroy_listener); |
Pekka Paalanen | ca79076 | 2015-04-17 14:23:38 +0300 | [diff] [blame] | 3912 | assert(data == sub->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3913 | |
| 3914 | /* The protocol object (wl_resource) is left inert. */ |
| 3915 | if (sub->resource) |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 3916 | wl_resource_set_user_data(sub->resource, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3917 | |
| 3918 | weston_subsurface_destroy(sub); |
| 3919 | } |
| 3920 | |
| 3921 | static void |
| 3922 | subsurface_handle_parent_destroy(struct wl_listener *listener, void *data) |
| 3923 | { |
| 3924 | struct weston_subsurface *sub = |
| 3925 | container_of(listener, struct weston_subsurface, |
| 3926 | parent_destroy_listener); |
Pekka Paalanen | ca79076 | 2015-04-17 14:23:38 +0300 | [diff] [blame] | 3927 | assert(data == sub->parent); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3928 | assert(sub->surface != sub->parent); |
| 3929 | |
| 3930 | if (weston_surface_is_mapped(sub->surface)) |
| 3931 | weston_surface_unmap(sub->surface); |
| 3932 | |
| 3933 | weston_subsurface_unlink_parent(sub); |
| 3934 | } |
| 3935 | |
| 3936 | static void |
| 3937 | subsurface_resource_destroy(struct wl_resource *resource) |
| 3938 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 3939 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3940 | |
| 3941 | if (sub) |
| 3942 | weston_subsurface_destroy(sub); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3943 | } |
| 3944 | |
| 3945 | static void |
| 3946 | subsurface_destroy(struct wl_client *client, struct wl_resource *resource) |
| 3947 | { |
| 3948 | wl_resource_destroy(resource); |
| 3949 | } |
| 3950 | |
| 3951 | static void |
| 3952 | weston_subsurface_link_parent(struct weston_subsurface *sub, |
| 3953 | struct weston_surface *parent) |
| 3954 | { |
| 3955 | sub->parent = parent; |
| 3956 | sub->parent_destroy_listener.notify = subsurface_handle_parent_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3957 | wl_signal_add(&parent->destroy_signal, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3958 | &sub->parent_destroy_listener); |
| 3959 | |
| 3960 | wl_list_insert(&parent->subsurface_list, &sub->parent_link); |
| 3961 | wl_list_insert(&parent->subsurface_list_pending, |
| 3962 | &sub->parent_link_pending); |
| 3963 | } |
| 3964 | |
| 3965 | static void |
| 3966 | weston_subsurface_link_surface(struct weston_subsurface *sub, |
| 3967 | struct weston_surface *surface) |
| 3968 | { |
| 3969 | sub->surface = surface; |
| 3970 | sub->surface_destroy_listener.notify = |
| 3971 | subsurface_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3972 | wl_signal_add(&surface->destroy_signal, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3973 | &sub->surface_destroy_listener); |
| 3974 | } |
| 3975 | |
| 3976 | static void |
| 3977 | weston_subsurface_destroy(struct weston_subsurface *sub) |
| 3978 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3979 | struct weston_view *view, *next; |
| 3980 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3981 | assert(sub->surface); |
| 3982 | |
| 3983 | if (sub->resource) { |
| 3984 | assert(weston_surface_to_subsurface(sub->surface) == sub); |
| 3985 | assert(sub->parent_destroy_listener.notify == |
| 3986 | subsurface_handle_parent_destroy); |
| 3987 | |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 3988 | wl_list_for_each_safe(view, next, &sub->surface->views, surface_link) { |
| 3989 | weston_view_unmap(view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3990 | weston_view_destroy(view); |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 3991 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3992 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3993 | if (sub->parent) |
| 3994 | weston_subsurface_unlink_parent(sub); |
| 3995 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3996 | weston_surface_state_fini(&sub->cached); |
| 3997 | weston_buffer_reference(&sub->cached_buffer_ref, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3998 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3999 | sub->surface->committed = NULL; |
| 4000 | sub->surface->committed_private = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4001 | weston_surface_set_label_func(sub->surface, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4002 | } else { |
| 4003 | /* the dummy weston_subsurface for the parent itself */ |
| 4004 | assert(sub->parent_destroy_listener.notify == NULL); |
| 4005 | wl_list_remove(&sub->parent_link); |
| 4006 | wl_list_remove(&sub->parent_link_pending); |
| 4007 | } |
| 4008 | |
| 4009 | wl_list_remove(&sub->surface_destroy_listener.link); |
| 4010 | free(sub); |
| 4011 | } |
| 4012 | |
| 4013 | static const struct wl_subsurface_interface subsurface_implementation = { |
| 4014 | subsurface_destroy, |
| 4015 | subsurface_set_position, |
| 4016 | subsurface_place_above, |
| 4017 | subsurface_place_below, |
| 4018 | subsurface_set_sync, |
| 4019 | subsurface_set_desync |
| 4020 | }; |
| 4021 | |
| 4022 | static struct weston_subsurface * |
| 4023 | weston_subsurface_create(uint32_t id, struct weston_surface *surface, |
| 4024 | struct weston_surface *parent) |
| 4025 | { |
| 4026 | struct weston_subsurface *sub; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 4027 | struct wl_client *client = wl_resource_get_client(surface->resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4028 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 4029 | sub = zalloc(sizeof *sub); |
| 4030 | if (sub == NULL) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4031 | return NULL; |
| 4032 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4033 | wl_list_init(&sub->unused_views); |
| 4034 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4035 | sub->resource = |
| 4036 | wl_resource_create(client, &wl_subsurface_interface, 1, id); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4037 | if (!sub->resource) { |
| 4038 | free(sub); |
| 4039 | return NULL; |
| 4040 | } |
| 4041 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4042 | wl_resource_set_implementation(sub->resource, |
| 4043 | &subsurface_implementation, |
| 4044 | sub, subsurface_resource_destroy); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4045 | weston_subsurface_link_surface(sub, surface); |
| 4046 | weston_subsurface_link_parent(sub, parent); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 4047 | weston_surface_state_init(&sub->cached); |
| 4048 | sub->cached_buffer_ref.buffer = NULL; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4049 | sub->synchronized = 1; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4050 | |
| 4051 | return sub; |
| 4052 | } |
| 4053 | |
| 4054 | /* Create a dummy subsurface for having the parent itself in its |
| 4055 | * sub-surface lists. Makes stacking order manipulation easy. |
| 4056 | */ |
| 4057 | static struct weston_subsurface * |
| 4058 | weston_subsurface_create_for_parent(struct weston_surface *parent) |
| 4059 | { |
| 4060 | struct weston_subsurface *sub; |
| 4061 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 4062 | sub = zalloc(sizeof *sub); |
| 4063 | if (sub == NULL) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4064 | return NULL; |
| 4065 | |
| 4066 | weston_subsurface_link_surface(sub, parent); |
| 4067 | sub->parent = parent; |
| 4068 | wl_list_insert(&parent->subsurface_list, &sub->parent_link); |
| 4069 | wl_list_insert(&parent->subsurface_list_pending, |
| 4070 | &sub->parent_link_pending); |
| 4071 | |
| 4072 | return sub; |
| 4073 | } |
| 4074 | |
| 4075 | static void |
| 4076 | subcompositor_get_subsurface(struct wl_client *client, |
| 4077 | struct wl_resource *resource, |
| 4078 | uint32_t id, |
| 4079 | struct wl_resource *surface_resource, |
| 4080 | struct wl_resource *parent_resource) |
| 4081 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4082 | struct weston_surface *surface = |
| 4083 | wl_resource_get_user_data(surface_resource); |
| 4084 | struct weston_surface *parent = |
| 4085 | wl_resource_get_user_data(parent_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4086 | struct weston_subsurface *sub; |
| 4087 | static const char where[] = "get_subsurface: wl_subsurface@"; |
| 4088 | |
| 4089 | if (surface == parent) { |
| 4090 | wl_resource_post_error(resource, |
| 4091 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 4092 | "%s%d: wl_surface@%d cannot be its own parent", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4093 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4094 | return; |
| 4095 | } |
| 4096 | |
| 4097 | if (weston_surface_to_subsurface(surface)) { |
| 4098 | wl_resource_post_error(resource, |
| 4099 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 4100 | "%s%d: wl_surface@%d is already a sub-surface", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4101 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4102 | return; |
| 4103 | } |
| 4104 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4105 | if (weston_surface_set_role(surface, "wl_subsurface", resource, |
| 4106 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE) < 0) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4107 | return; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4108 | |
Pekka Paalanen | 86c8ca0 | 2013-05-17 16:46:07 +0300 | [diff] [blame] | 4109 | if (weston_surface_get_main_surface(parent) == surface) { |
| 4110 | wl_resource_post_error(resource, |
| 4111 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 4112 | "%s%d: wl_surface@%d is an ancestor of parent", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4113 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | 86c8ca0 | 2013-05-17 16:46:07 +0300 | [diff] [blame] | 4114 | return; |
| 4115 | } |
| 4116 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4117 | /* make sure the parent is in its own list */ |
| 4118 | if (wl_list_empty(&parent->subsurface_list)) { |
| 4119 | if (!weston_subsurface_create_for_parent(parent)) { |
| 4120 | wl_resource_post_no_memory(resource); |
| 4121 | return; |
| 4122 | } |
| 4123 | } |
| 4124 | |
| 4125 | sub = weston_subsurface_create(id, surface, parent); |
| 4126 | if (!sub) { |
| 4127 | wl_resource_post_no_memory(resource); |
| 4128 | return; |
| 4129 | } |
| 4130 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 4131 | surface->committed = subsurface_committed; |
| 4132 | surface->committed_private = sub; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4133 | weston_surface_set_label_func(surface, subsurface_get_label); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4134 | } |
| 4135 | |
| 4136 | static void |
| 4137 | subcompositor_destroy(struct wl_client *client, struct wl_resource *resource) |
| 4138 | { |
| 4139 | wl_resource_destroy(resource); |
| 4140 | } |
| 4141 | |
| 4142 | static const struct wl_subcompositor_interface subcompositor_interface = { |
| 4143 | subcompositor_destroy, |
| 4144 | subcompositor_get_subsurface |
| 4145 | }; |
| 4146 | |
| 4147 | static void |
| 4148 | bind_subcompositor(struct wl_client *client, |
| 4149 | void *data, uint32_t version, uint32_t id) |
| 4150 | { |
| 4151 | struct weston_compositor *compositor = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4152 | struct wl_resource *resource; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4153 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4154 | resource = |
| 4155 | wl_resource_create(client, &wl_subcompositor_interface, 1, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 4156 | if (resource == NULL) { |
| 4157 | wl_client_post_no_memory(client); |
| 4158 | return; |
| 4159 | } |
| 4160 | wl_resource_set_implementation(resource, &subcompositor_interface, |
| 4161 | compositor, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4162 | } |
| 4163 | |
Bryce Harrington | 0795ece | 2016-08-30 12:04:26 -0700 | [diff] [blame] | 4164 | /** Set a DPMS mode on all of the compositor's outputs |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4165 | * |
| 4166 | * \param compositor The compositor instance |
| 4167 | * \param state The DPMS state the outputs will be set to |
| 4168 | */ |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4169 | static void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4170 | weston_compositor_dpms(struct weston_compositor *compositor, |
| 4171 | enum dpms_enum state) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4172 | { |
| 4173 | struct weston_output *output; |
| 4174 | |
Bryce Harrington | 08976ac | 2016-08-30 12:05:16 -0700 | [diff] [blame] | 4175 | wl_list_for_each(output, &compositor->output_list, link) |
| 4176 | if (output->set_dpms) |
| 4177 | output->set_dpms(output, state); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4178 | } |
| 4179 | |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4180 | /** Restores the compositor to active status |
| 4181 | * |
| 4182 | * \param compositor The compositor instance |
| 4183 | * |
| 4184 | * If the compositor was in a sleeping mode, all outputs are powered |
| 4185 | * back on via DPMS. Otherwise if the compositor was inactive |
| 4186 | * (idle/locked, offscreen, or sleeping) then the compositor's wake |
| 4187 | * signal will fire. |
| 4188 | * |
| 4189 | * Restarts the idle timer. |
| 4190 | */ |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4191 | WL_EXPORT void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4192 | weston_compositor_wake(struct weston_compositor *compositor) |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4193 | { |
Neil Roberts | 8b62e20 | 2013-09-30 13:14:47 +0100 | [diff] [blame] | 4194 | uint32_t old_state = compositor->state; |
| 4195 | |
| 4196 | /* The state needs to be changed before emitting the wake |
| 4197 | * signal because that may try to schedule a repaint which |
| 4198 | * will not work if the compositor is still sleeping */ |
| 4199 | compositor->state = WESTON_COMPOSITOR_ACTIVE; |
| 4200 | |
| 4201 | switch (old_state) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4202 | case WESTON_COMPOSITOR_SLEEPING: |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4203 | case WESTON_COMPOSITOR_IDLE: |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4204 | case WESTON_COMPOSITOR_OFFSCREEN: |
Daniel Stone | 893b936 | 2016-11-08 15:47:09 +0000 | [diff] [blame] | 4205 | weston_compositor_dpms(compositor, WESTON_DPMS_ON); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4206 | wl_signal_emit(&compositor->wake_signal, compositor); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4207 | /* fall through */ |
| 4208 | default: |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4209 | wl_event_source_timer_update(compositor->idle_source, |
| 4210 | compositor->idle_time * 1000); |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4211 | } |
| 4212 | } |
| 4213 | |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4214 | /** Turns off rendering and frame events for the compositor. |
| 4215 | * |
| 4216 | * \param compositor The compositor instance |
| 4217 | * |
| 4218 | * This is used for example to prevent further rendering while the |
| 4219 | * compositor is shutting down. |
| 4220 | * |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4221 | * Stops the idle timer. |
| 4222 | */ |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4223 | WL_EXPORT void |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4224 | weston_compositor_offscreen(struct weston_compositor *compositor) |
| 4225 | { |
| 4226 | switch (compositor->state) { |
| 4227 | case WESTON_COMPOSITOR_OFFSCREEN: |
| 4228 | return; |
| 4229 | case WESTON_COMPOSITOR_SLEEPING: |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4230 | default: |
| 4231 | compositor->state = WESTON_COMPOSITOR_OFFSCREEN; |
| 4232 | wl_event_source_timer_update(compositor->idle_source, 0); |
| 4233 | } |
| 4234 | } |
| 4235 | |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4236 | /** Powers down all attached output devices |
| 4237 | * |
| 4238 | * \param compositor The compositor instance |
| 4239 | * |
| 4240 | * Causes rendering to the outputs to cease, and no frame events to be |
| 4241 | * sent. Only powers down the outputs if the compositor is not already |
| 4242 | * in sleep mode. |
| 4243 | * |
| 4244 | * Stops the idle timer. |
| 4245 | */ |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4246 | WL_EXPORT void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4247 | weston_compositor_sleep(struct weston_compositor *compositor) |
| 4248 | { |
| 4249 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING) |
| 4250 | return; |
| 4251 | |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4252 | wl_event_source_timer_update(compositor->idle_source, 0); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4253 | compositor->state = WESTON_COMPOSITOR_SLEEPING; |
| 4254 | weston_compositor_dpms(compositor, WESTON_DPMS_OFF); |
| 4255 | } |
| 4256 | |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4257 | /** Sets compositor to idle mode |
| 4258 | * |
| 4259 | * \param data The compositor instance |
| 4260 | * |
| 4261 | * This is called when the idle timer fires. Once the compositor is in |
| 4262 | * idle mode it requires a wake action (e.g. via |
| 4263 | * weston_compositor_wake()) to restore it. The compositor's |
| 4264 | * idle_signal will be triggered when the idle event occurs. |
| 4265 | * |
| 4266 | * Idleness can be inhibited by setting the compositor's idle_inhibit |
| 4267 | * property. |
| 4268 | */ |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 4269 | static int |
| 4270 | idle_handler(void *data) |
| 4271 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4272 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 4273 | |
| 4274 | if (compositor->idle_inhibit) |
| 4275 | return 1; |
| 4276 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4277 | compositor->state = WESTON_COMPOSITOR_IDLE; |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4278 | wl_signal_emit(&compositor->idle_signal, compositor); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 4279 | |
| 4280 | return 1; |
| 4281 | } |
| 4282 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4283 | WL_EXPORT void |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 4284 | weston_plane_init(struct weston_plane *plane, |
| 4285 | struct weston_compositor *ec, |
| 4286 | int32_t x, int32_t y) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4287 | { |
| 4288 | pixman_region32_init(&plane->damage); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 4289 | pixman_region32_init(&plane->clip); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4290 | plane->x = x; |
| 4291 | plane->y = y; |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 4292 | plane->compositor = ec; |
Ander Conselvan de Oliveira | 3c36bf3 | 2013-07-05 16:05:26 +0300 | [diff] [blame] | 4293 | |
| 4294 | /* Init the link so that the call to wl_list_remove() when releasing |
| 4295 | * the plane without ever stacking doesn't lead to a crash */ |
| 4296 | wl_list_init(&plane->link); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4297 | } |
| 4298 | |
| 4299 | WL_EXPORT void |
| 4300 | weston_plane_release(struct weston_plane *plane) |
| 4301 | { |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 4302 | struct weston_view *view; |
| 4303 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4304 | pixman_region32_fini(&plane->damage); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 4305 | pixman_region32_fini(&plane->clip); |
Ander Conselvan de Oliveira | 3c36bf3 | 2013-07-05 16:05:26 +0300 | [diff] [blame] | 4306 | |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 4307 | wl_list_for_each(view, &plane->compositor->view_list, link) { |
| 4308 | if (view->plane == plane) |
| 4309 | view->plane = NULL; |
| 4310 | } |
| 4311 | |
Ander Conselvan de Oliveira | 3c36bf3 | 2013-07-05 16:05:26 +0300 | [diff] [blame] | 4312 | wl_list_remove(&plane->link); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4313 | } |
| 4314 | |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 4315 | WL_EXPORT void |
| 4316 | weston_compositor_stack_plane(struct weston_compositor *ec, |
| 4317 | struct weston_plane *plane, |
| 4318 | struct weston_plane *above) |
| 4319 | { |
| 4320 | if (above) |
| 4321 | wl_list_insert(above->link.prev, &plane->link); |
| 4322 | else |
| 4323 | wl_list_insert(&ec->plane_list, &plane->link); |
| 4324 | } |
| 4325 | |
Quentin Glidic | 4ef719c | 2016-07-05 20:44:33 +0200 | [diff] [blame] | 4326 | static void |
| 4327 | output_release(struct wl_client *client, struct wl_resource *resource) |
| 4328 | { |
| 4329 | wl_resource_destroy(resource); |
| 4330 | } |
| 4331 | |
| 4332 | static const struct wl_output_interface output_interface = { |
| 4333 | output_release, |
| 4334 | }; |
| 4335 | |
| 4336 | |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 4337 | static void unbind_resource(struct wl_resource *resource) |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 4338 | { |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4339 | wl_list_remove(wl_resource_get_link(resource)); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 4340 | } |
| 4341 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4342 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4343 | bind_output(struct wl_client *client, |
| 4344 | void *data, uint32_t version, uint32_t id) |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 4345 | { |
Pekka Paalanen | 0534762 | 2017-03-27 12:24:34 +0300 | [diff] [blame] | 4346 | struct weston_head *head = data; |
| 4347 | struct weston_output *output = head->output; |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4348 | struct weston_mode *mode; |
Kristian Høgsberg | fd07fb7 | 2011-08-29 15:03:09 -0400 | [diff] [blame] | 4349 | struct wl_resource *resource; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 4350 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4351 | resource = wl_resource_create(client, &wl_output_interface, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 4352 | version, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 4353 | if (resource == NULL) { |
| 4354 | wl_client_post_no_memory(client); |
| 4355 | return; |
| 4356 | } |
Kristian Høgsberg | fd07fb7 | 2011-08-29 15:03:09 -0400 | [diff] [blame] | 4357 | |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 4358 | wl_list_insert(&head->resource_list, wl_resource_get_link(resource)); |
Pekka Paalanen | 055c113 | 2017-03-27 16:31:25 +0300 | [diff] [blame] | 4359 | wl_resource_set_implementation(resource, &output_interface, head, |
Pekka Paalanen | 0534762 | 2017-03-27 12:24:34 +0300 | [diff] [blame] | 4360 | unbind_resource); |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 4361 | |
Pekka Paalanen | 0534762 | 2017-03-27 12:24:34 +0300 | [diff] [blame] | 4362 | assert(output); |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4363 | wl_output_send_geometry(resource, |
| 4364 | output->x, |
| 4365 | output->y, |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 4366 | head->mm_width, |
| 4367 | head->mm_height, |
| 4368 | head->subpixel, |
| 4369 | head->make, head->model, |
Kristian Høgsberg | 05890dc | 2012-08-10 10:09:20 -0400 | [diff] [blame] | 4370 | output->transform); |
Jasper St. Pierre | 0013a29 | 2014-08-07 16:43:11 -0400 | [diff] [blame] | 4371 | if (version >= WL_OUTPUT_SCALE_SINCE_VERSION) |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 4372 | wl_output_send_scale(resource, |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 4373 | output->current_scale); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 4374 | |
| 4375 | wl_list_for_each (mode, &output->mode_list, link) { |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4376 | wl_output_send_mode(resource, |
| 4377 | mode->flags, |
| 4378 | mode->width, |
| 4379 | mode->height, |
| 4380 | mode->refresh); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 4381 | } |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 4382 | |
Jasper St. Pierre | 0013a29 | 2014-08-07 16:43:11 -0400 | [diff] [blame] | 4383 | if (version >= WL_OUTPUT_DONE_SINCE_VERSION) |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 4384 | wl_output_send_done(resource); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 4385 | } |
| 4386 | |
Pekka Paalanen | d9dcc6d | 2017-12-04 15:28:13 +0200 | [diff] [blame] | 4387 | /** Remove the global wl_output protocol object |
| 4388 | * |
| 4389 | * \param head The head whose global to remove. |
| 4390 | * |
| 4391 | * Also orphans the wl_resources for this head (wl_output). |
| 4392 | */ |
| 4393 | static void |
| 4394 | weston_head_remove_global(struct weston_head *head) |
| 4395 | { |
| 4396 | struct wl_resource *resource, *tmp; |
| 4397 | |
| 4398 | if (head->global) |
| 4399 | wl_global_destroy(head->global); |
| 4400 | head->global = NULL; |
| 4401 | |
| 4402 | wl_resource_for_each_safe(resource, tmp, &head->resource_list) { |
| 4403 | unbind_resource(resource); |
| 4404 | wl_resource_set_destructor(resource, NULL); |
| 4405 | wl_resource_set_user_data(resource, NULL); |
| 4406 | } |
| 4407 | } |
| 4408 | |
Pekka Paalanen | 9ffb250 | 2017-03-27 15:14:32 +0300 | [diff] [blame] | 4409 | /** Get the backing object of wl_output |
| 4410 | * |
| 4411 | * \param resource A wl_output protocol object. |
| 4412 | * \return The backing object (user data) of a wl_resource representing a |
| 4413 | * wl_output protocol object. |
| 4414 | */ |
Pekka Paalanen | 055c113 | 2017-03-27 16:31:25 +0300 | [diff] [blame] | 4415 | WL_EXPORT struct weston_head * |
| 4416 | weston_head_from_resource(struct wl_resource *resource) |
Pekka Paalanen | 9ffb250 | 2017-03-27 15:14:32 +0300 | [diff] [blame] | 4417 | { |
| 4418 | assert(wl_resource_instance_of(resource, &wl_output_interface, |
| 4419 | &output_interface)); |
| 4420 | |
| 4421 | return wl_resource_get_user_data(resource); |
| 4422 | } |
| 4423 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4424 | /** Initialize a pre-allocated weston_head |
| 4425 | * |
| 4426 | * \param head The head to initialize. |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 4427 | * \param name The head name, e.g. the connector name or equivalent. |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4428 | * |
| 4429 | * The head will be safe to attach, detach and release. |
| 4430 | * |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 4431 | * The name is used in logs, and can be used by compositors as a configuration |
| 4432 | * identifier. |
| 4433 | * |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4434 | * \memberof weston_head |
| 4435 | * \internal |
| 4436 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame^] | 4437 | WL_EXPORT void |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 4438 | weston_head_init(struct weston_head *head, const char *name) |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4439 | { |
| 4440 | /* Add some (in)sane defaults which can be used |
| 4441 | * for checking if an output was properly configured |
| 4442 | */ |
| 4443 | memset(head, 0, sizeof *head); |
| 4444 | |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 4445 | wl_list_init(&head->compositor_link); |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4446 | wl_list_init(&head->output_link); |
| 4447 | wl_list_init(&head->resource_list); |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 4448 | head->name = strdup(name); |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4449 | } |
| 4450 | |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4451 | /** Idle task for emitting heads_changed_signal */ |
| 4452 | static void |
| 4453 | weston_compositor_call_heads_changed(void *data) |
| 4454 | { |
| 4455 | struct weston_compositor *compositor = data; |
| 4456 | |
| 4457 | compositor->heads_changed_source = NULL; |
| 4458 | |
| 4459 | wl_signal_emit(&compositor->heads_changed_signal, compositor); |
| 4460 | } |
| 4461 | |
| 4462 | /** Schedule a call on idle to heads_changed callback |
| 4463 | * |
| 4464 | * \param compositor The Compositor. |
| 4465 | * |
| 4466 | * \memberof weston_compositor |
| 4467 | * \internal |
| 4468 | */ |
| 4469 | static void |
| 4470 | weston_compositor_schedule_heads_changed(struct weston_compositor *compositor) |
| 4471 | { |
| 4472 | struct wl_event_loop *loop; |
| 4473 | |
| 4474 | if (compositor->heads_changed_source) |
| 4475 | return; |
| 4476 | |
| 4477 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 4478 | compositor->heads_changed_source = wl_event_loop_add_idle(loop, |
| 4479 | weston_compositor_call_heads_changed, compositor); |
| 4480 | } |
| 4481 | |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 4482 | /** Register a new head |
| 4483 | * |
| 4484 | * \param compositor The compositor. |
| 4485 | * \param head The head to register, must not be already registered. |
| 4486 | * |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4487 | * This signals the core that a new head has become available, leading to |
| 4488 | * heads_changed hook being called later. |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 4489 | * |
| 4490 | * \memberof weston_compositor |
| 4491 | * \internal |
| 4492 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame^] | 4493 | WL_EXPORT void |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 4494 | weston_compositor_add_head(struct weston_compositor *compositor, |
| 4495 | struct weston_head *head) |
| 4496 | { |
| 4497 | assert(wl_list_empty(&head->compositor_link)); |
| 4498 | assert(head->name); |
| 4499 | |
| 4500 | wl_list_insert(compositor->head_list.prev, &head->compositor_link); |
| 4501 | head->compositor = compositor; |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4502 | weston_compositor_schedule_heads_changed(compositor); |
| 4503 | } |
| 4504 | |
| 4505 | /** Adds a listener to be called when heads change |
| 4506 | * |
| 4507 | * \param compositor The compositor. |
| 4508 | * \param listener The listener to add. |
| 4509 | * |
| 4510 | * The listener notify function argument is the \var compositor. |
| 4511 | * |
| 4512 | * The listener function will be called after heads are added or their |
| 4513 | * connection status has changed. Several changes may be accumulated into a |
| 4514 | * single call. The user is expected to iterate over the existing heads and |
| 4515 | * check their statuses to find out what changed. |
| 4516 | * |
| 4517 | * \sa weston_compositor_iterate_heads, weston_head_is_connected, |
| 4518 | * weston_head_is_enabled |
| 4519 | * \memberof weston_compositor |
| 4520 | */ |
| 4521 | WL_EXPORT void |
| 4522 | weston_compositor_add_heads_changed_listener(struct weston_compositor *compositor, |
| 4523 | struct wl_listener *listener) |
| 4524 | { |
| 4525 | wl_signal_add(&compositor->heads_changed_signal, listener); |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 4526 | } |
| 4527 | |
| 4528 | /** Iterate over available heads |
| 4529 | * |
| 4530 | * \param compositor The compositor. |
| 4531 | * \param item The iterator, or NULL for start. |
| 4532 | * \return The next available head in the list. |
| 4533 | * |
| 4534 | * Returns all available heads, regardless of being connected or enabled. |
| 4535 | * |
| 4536 | * You can iterate over all heads as follows: |
| 4537 | * \code |
| 4538 | * struct weston_head *head = NULL; |
| 4539 | * |
| 4540 | * while ((head = weston_compositor_iterate_heads(compositor, head))) { |
| 4541 | * ... |
| 4542 | * } |
| 4543 | * \endcode |
| 4544 | * |
| 4545 | * If you cause \c iter to be removed from the list, you cannot use it to |
| 4546 | * continue iterating. Removing any other item is safe. |
| 4547 | * |
| 4548 | * \memberof weston_compositor |
| 4549 | */ |
| 4550 | WL_EXPORT struct weston_head * |
| 4551 | weston_compositor_iterate_heads(struct weston_compositor *compositor, |
| 4552 | struct weston_head *iter) |
| 4553 | { |
| 4554 | struct wl_list *list = &compositor->head_list; |
| 4555 | struct wl_list *node; |
| 4556 | |
| 4557 | assert(compositor); |
| 4558 | assert(!iter || iter->compositor == compositor); |
| 4559 | |
| 4560 | if (iter) |
| 4561 | node = iter->compositor_link.next; |
| 4562 | else |
| 4563 | node = list->next; |
| 4564 | |
| 4565 | assert(node); |
| 4566 | assert(!iter || node != &iter->compositor_link); |
| 4567 | |
| 4568 | if (node == list) |
| 4569 | return NULL; |
| 4570 | |
| 4571 | return container_of(node, struct weston_head, compositor_link); |
| 4572 | } |
| 4573 | |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame^] | 4574 | /** Iterate over attached heads |
| 4575 | * |
| 4576 | * \param output The output whose heads to iterate. |
| 4577 | * \param item The iterator, or NULL for start. |
| 4578 | * \return The next attached head in the list. |
| 4579 | * |
| 4580 | * Returns all heads currently attached to the output. |
| 4581 | * |
| 4582 | * You can iterate over all heads as follows: |
| 4583 | * \code |
| 4584 | * struct weston_head *head = NULL; |
| 4585 | * |
| 4586 | * while ((head = weston_output_iterate_heads(output, head))) { |
| 4587 | * ... |
| 4588 | * } |
| 4589 | * \endcode |
| 4590 | * |
| 4591 | * If you cause \c iter to be removed from the list, you cannot use it to |
| 4592 | * continue iterating. Removing any other item is safe. |
| 4593 | * |
| 4594 | * \memberof weston_compositor |
| 4595 | */ |
| 4596 | WL_EXPORT struct weston_head * |
| 4597 | weston_output_iterate_heads(struct weston_output *output, |
| 4598 | struct weston_head *iter) |
| 4599 | { |
| 4600 | struct wl_list *list = &output->head_list; |
| 4601 | struct wl_list *node; |
| 4602 | |
| 4603 | assert(output); |
| 4604 | assert(!iter || iter->output == output); |
| 4605 | |
| 4606 | if (iter) |
| 4607 | node = iter->output_link.next; |
| 4608 | else |
| 4609 | node = list->next; |
| 4610 | |
| 4611 | assert(node); |
| 4612 | assert(!iter || node != &iter->output_link); |
| 4613 | |
| 4614 | if (node == list) |
| 4615 | return NULL; |
| 4616 | |
| 4617 | return container_of(node, struct weston_head, output_link); |
| 4618 | } |
| 4619 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4620 | /** Attach a head to an inactive output |
| 4621 | * |
| 4622 | * \param output The output to attach to. |
| 4623 | * \param head The head that is not yet attached. |
| 4624 | * \return 0 on success, -1 on failure. |
| 4625 | * |
| 4626 | * Attaches the given head to the output. All heads of an output are clones |
| 4627 | * and share the resolution and timings. |
| 4628 | * |
| 4629 | * Cloning heads this way uses less resources than creating an output for |
| 4630 | * each head, but is not always possible due to environment, driver and hardware |
| 4631 | * limitations. |
| 4632 | * |
| 4633 | * On failure, the head remains unattached. Success of this function does not |
| 4634 | * guarantee the output configuration is actually valid. The final checks are |
| 4635 | * made on weston_output_enable(). |
| 4636 | * |
| 4637 | * \memberof weston_output |
| 4638 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame^] | 4639 | WL_EXPORT int |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4640 | weston_output_attach_head(struct weston_output *output, |
| 4641 | struct weston_head *head) |
| 4642 | { |
| 4643 | if (output->enabled) |
| 4644 | return -1; |
| 4645 | |
| 4646 | if (!wl_list_empty(&head->output_link)) |
| 4647 | return -1; |
| 4648 | |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame^] | 4649 | if (output->attach_head) { |
| 4650 | if (output->attach_head(output, head) < 0) |
| 4651 | return -1; |
| 4652 | } else if (!wl_list_empty(&output->head_list)) { |
| 4653 | /* No support for clones in the legacy path. */ |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4654 | return -1; |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame^] | 4655 | } |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4656 | |
| 4657 | head->output = output; |
| 4658 | wl_list_insert(output->head_list.prev, &head->output_link); |
| 4659 | |
| 4660 | return 0; |
| 4661 | } |
| 4662 | |
| 4663 | /** Detach a head from its output |
| 4664 | * |
| 4665 | * \param head The head to detach. |
| 4666 | * |
| 4667 | * It is safe to detach a non-attached head. |
| 4668 | * |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame^] | 4669 | * If the head is attached to an enabled output and the output will be left |
| 4670 | * with no heads, the output will be disabled. |
| 4671 | * |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4672 | * \memberof weston_head |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame^] | 4673 | * \sa weston_output_disable |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4674 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame^] | 4675 | WL_EXPORT void |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4676 | weston_head_detach(struct weston_head *head) |
| 4677 | { |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame^] | 4678 | struct weston_output *output = head->output; |
| 4679 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4680 | wl_list_remove(&head->output_link); |
| 4681 | wl_list_init(&head->output_link); |
| 4682 | head->output = NULL; |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame^] | 4683 | |
| 4684 | if (!output) |
| 4685 | return; |
| 4686 | |
| 4687 | if (output->detach_head) |
| 4688 | output->detach_head(output, head); |
| 4689 | |
| 4690 | if (output->enabled) { |
| 4691 | weston_head_remove_global(head); |
| 4692 | |
| 4693 | if (wl_list_empty(&output->head_list)) |
| 4694 | weston_output_disable(output); |
| 4695 | } |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4696 | } |
| 4697 | |
| 4698 | /** Destroy a head |
| 4699 | * |
| 4700 | * \param head The head to be released. |
| 4701 | * |
| 4702 | * Destroys the head. The caller is responsible for freeing the memory pointed |
| 4703 | * to by \c head. |
| 4704 | * |
| 4705 | * \memberof weston_head |
| 4706 | * \internal |
| 4707 | */ |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame^] | 4708 | WL_EXPORT void |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4709 | weston_head_release(struct weston_head *head) |
| 4710 | { |
| 4711 | weston_head_detach(head); |
Pekka Paalanen | 06f99ef | 2017-04-04 16:26:23 +0300 | [diff] [blame] | 4712 | |
| 4713 | free(head->make); |
| 4714 | free(head->model); |
| 4715 | free(head->serial_number); |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 4716 | free(head->name); |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 4717 | |
| 4718 | wl_list_remove(&head->compositor_link); |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 4719 | } |
| 4720 | |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 4721 | /** Store monitor make, model and serial number |
| 4722 | * |
| 4723 | * \param head The head to modify. |
| 4724 | * \param make The monitor make. If EDID is available, the PNP ID. Otherwise |
| 4725 | * any string, or NULL for none. |
| 4726 | * \param model The monitor model or name, or a made-up string, or NULL for |
| 4727 | * none. |
| 4728 | * \param serialno The monitor serial number, a made-up string, or NULL for |
| 4729 | * none. |
| 4730 | * |
| 4731 | * \memberof weston_head |
| 4732 | * \internal |
| 4733 | */ |
| 4734 | WL_EXPORT void |
| 4735 | weston_head_set_monitor_strings(struct weston_head *head, |
| 4736 | const char *make, |
| 4737 | const char *model, |
| 4738 | const char *serialno) |
| 4739 | { |
Pekka Paalanen | 06f99ef | 2017-04-04 16:26:23 +0300 | [diff] [blame] | 4740 | free(head->make); |
| 4741 | free(head->model); |
| 4742 | free(head->serial_number); |
| 4743 | |
| 4744 | head->make = make ? strdup(make) : NULL; |
| 4745 | head->model = model ? strdup(model) : NULL; |
| 4746 | head->serial_number = serialno ? strdup(serialno) : NULL; |
Pekka Paalanen | 01f6021 | 2017-03-24 15:39:24 +0200 | [diff] [blame] | 4747 | } |
| 4748 | |
| 4749 | /** Store physical image size |
| 4750 | * |
| 4751 | * \param head The head to modify. |
| 4752 | * \param mm_width Image area width in millimeters. |
| 4753 | * \param mm_height Image area height in millimeters. |
| 4754 | * |
| 4755 | * \memberof weston_head |
| 4756 | * \internal |
| 4757 | */ |
| 4758 | WL_EXPORT void |
| 4759 | weston_head_set_physical_size(struct weston_head *head, |
| 4760 | int32_t mm_width, int32_t mm_height) |
| 4761 | { |
| 4762 | head->mm_width = mm_width; |
| 4763 | head->mm_height = mm_height; |
| 4764 | } |
| 4765 | |
| 4766 | /** Store monitor sub-pixel layout |
| 4767 | * |
| 4768 | * \param head The head to modify. |
| 4769 | * \param sp Sub-pixel layout. The possible values are: |
| 4770 | * - WL_OUTPUT_SUBPIXEL_UNKNOWN, |
| 4771 | * - WL_OUTPUT_SUBPIXEL_NONE, |
| 4772 | * - WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB, |
| 4773 | * - WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR, |
| 4774 | * - WL_OUTPUT_SUBPIXEL_VERTICAL_RGB, |
| 4775 | * - WL_OUTPUT_SUBPIXEL_VERTICAL_BGR |
| 4776 | * |
| 4777 | * \memberof weston_head |
| 4778 | * \internal |
| 4779 | */ |
| 4780 | WL_EXPORT void |
| 4781 | weston_head_set_subpixel(struct weston_head *head, |
| 4782 | enum wl_output_subpixel sp) |
| 4783 | { |
| 4784 | head->subpixel = sp; |
| 4785 | } |
| 4786 | |
| 4787 | /** Mark the monitor as internal |
| 4788 | * |
| 4789 | * This is used for embedded screens, like laptop panels. |
| 4790 | * |
| 4791 | * \param head The head to mark as internal. |
| 4792 | * |
| 4793 | * By default a head is external. The type is often inferred from the physical |
| 4794 | * connector type. |
| 4795 | * |
| 4796 | * \memberof weston_head |
| 4797 | * \internal |
| 4798 | */ |
| 4799 | WL_EXPORT void |
| 4800 | weston_head_set_internal(struct weston_head *head) |
| 4801 | { |
| 4802 | head->connection_internal = true; |
| 4803 | } |
Pekka Paalanen | 9ffb250 | 2017-03-27 15:14:32 +0300 | [diff] [blame] | 4804 | |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 4805 | /** Store connector status |
| 4806 | * |
| 4807 | * \param head The head to modify. |
| 4808 | * \param connected Whether the head is connected. |
| 4809 | * |
| 4810 | * Connectors are created as disconnected. This function can be used to |
| 4811 | * set the connector status. |
| 4812 | * |
| 4813 | * The status should be set to true when a physical connector is connected to |
| 4814 | * a video sink device like a monitor and to false when the connector is |
| 4815 | * disconnected. For nested backends, the connection status should reflect the |
| 4816 | * connection to the parent display server. |
| 4817 | * |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4818 | * When the connection status changes, it schedules a call to the heads_changed |
| 4819 | * hook. |
| 4820 | * |
| 4821 | * \sa weston_compositor_set_heads_changed_cb |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 4822 | * \memberof weston_head |
| 4823 | * \internal |
| 4824 | */ |
| 4825 | WL_EXPORT void |
| 4826 | weston_head_set_connection_status(struct weston_head *head, bool connected) |
| 4827 | { |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4828 | if (head->connected == connected) |
| 4829 | return; |
| 4830 | |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 4831 | head->connected = connected; |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 4832 | |
| 4833 | if (head->compositor) |
| 4834 | weston_compositor_schedule_heads_changed(head->compositor); |
Pekka Paalanen | 7fe858b | 2017-08-14 15:45:14 +0300 | [diff] [blame] | 4835 | } |
| 4836 | |
| 4837 | /** Is the head currently connected? |
| 4838 | * |
| 4839 | * \param head The head to query. |
| 4840 | * \return Connection status. |
| 4841 | * |
| 4842 | * Returns true if the head is physically connected to a monitor, or in |
| 4843 | * case of a nested backend returns true when there is a connection to the |
| 4844 | * parent display server. |
| 4845 | * |
| 4846 | * This is independent from the head being enabled. |
| 4847 | * |
| 4848 | * \sa weston_head_is_enabled |
| 4849 | * \memberof weston_head |
| 4850 | */ |
| 4851 | WL_EXPORT bool |
| 4852 | weston_head_is_connected(struct weston_head *head) |
| 4853 | { |
| 4854 | return head->connected; |
| 4855 | } |
| 4856 | |
Pekka Paalanen | 8e552fd | 2018-02-15 15:18:20 +0200 | [diff] [blame] | 4857 | /** Is the head currently enabled? |
| 4858 | * |
| 4859 | * \param head The head to query. |
| 4860 | * \return Video status. |
| 4861 | * |
| 4862 | * Returns true if the head is currently transmitting a video stream. |
| 4863 | * |
| 4864 | * This is independent of the head being connected. |
| 4865 | * |
| 4866 | * \sa weston_head_is_connected |
| 4867 | * \memberof weston_head |
| 4868 | */ |
| 4869 | WL_EXPORT bool |
| 4870 | weston_head_is_enabled(struct weston_head *head) |
| 4871 | { |
| 4872 | if (!head->output) |
| 4873 | return false; |
| 4874 | |
| 4875 | return head->output->enabled; |
| 4876 | } |
| 4877 | |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame^] | 4878 | /** Get the name of a head |
| 4879 | * |
| 4880 | * \param head The head to query. |
| 4881 | * \return The head's name, not NULL. |
| 4882 | * |
| 4883 | * The name depends on the backend. The DRM backend uses connector names, |
| 4884 | * other backends may use hardcoded names or user-given names. |
| 4885 | */ |
| 4886 | WL_EXPORT const char * |
| 4887 | weston_head_get_name(struct weston_head *head) |
| 4888 | { |
| 4889 | return head->name; |
| 4890 | } |
| 4891 | |
| 4892 | /** Get the output the head is attached to |
| 4893 | * |
| 4894 | * \param head The head to query. |
| 4895 | * \return The output the head is attached to, or NULL if detached. |
| 4896 | */ |
| 4897 | WL_EXPORT struct weston_output * |
| 4898 | weston_head_get_output(struct weston_head *head) |
| 4899 | { |
| 4900 | return head->output; |
| 4901 | } |
| 4902 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 4903 | /* 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] | 4904 | static void |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 4905 | weston_compositor_reflow_outputs(struct weston_compositor *compositor, |
| 4906 | struct weston_output *resized_output, int delta_width) |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 4907 | { |
| 4908 | struct weston_output *output; |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 4909 | bool start_resizing = false; |
| 4910 | |
| 4911 | if (!delta_width) |
| 4912 | return; |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 4913 | |
| 4914 | wl_list_for_each(output, &compositor->output_list, link) { |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 4915 | if (output == resized_output) { |
| 4916 | start_resizing = true; |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 4917 | continue; |
| 4918 | } |
| 4919 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 4920 | if (start_resizing) { |
| 4921 | weston_output_move(output, output->x + delta_width, output->y); |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 4922 | output->dirty = 1; |
| 4923 | } |
| 4924 | } |
| 4925 | } |
| 4926 | |
Pekka Paalanen | d72bad2 | 2017-03-29 17:01:41 +0300 | [diff] [blame] | 4927 | static void |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4928 | weston_output_update_matrix(struct weston_output *output) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 4929 | { |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 4930 | float magnification; |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 4931 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4932 | weston_matrix_init(&output->matrix); |
Jason Ekstrand | fb23df7 | 2014-10-16 10:55:21 -0500 | [diff] [blame] | 4933 | weston_matrix_translate(&output->matrix, -output->x, -output->y, 0); |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4934 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4935 | if (output->zoom.active) { |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4936 | magnification = 1 / (1 - output->zoom.spring_z.current); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4937 | weston_output_update_zoom(output); |
Neil Roberts | 1e40a7e | 2014-04-25 13:19:37 +0100 | [diff] [blame] | 4938 | weston_matrix_translate(&output->matrix, -output->zoom.trans_x, |
Jason Ekstrand | fb23df7 | 2014-10-16 10:55:21 -0500 | [diff] [blame] | 4939 | -output->zoom.trans_y, 0); |
Neil Roberts | 1e40a7e | 2014-04-25 13:19:37 +0100 | [diff] [blame] | 4940 | weston_matrix_scale(&output->matrix, magnification, |
| 4941 | magnification, 1.0); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4942 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 4943 | |
Jason Ekstrand | fb23df7 | 2014-10-16 10:55:21 -0500 | [diff] [blame] | 4944 | switch (output->transform) { |
| 4945 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 4946 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 4947 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 4948 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 4949 | weston_matrix_translate(&output->matrix, -output->width, 0, 0); |
| 4950 | weston_matrix_scale(&output->matrix, -1, 1, 1); |
| 4951 | break; |
| 4952 | } |
| 4953 | |
| 4954 | switch (output->transform) { |
| 4955 | default: |
| 4956 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 4957 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 4958 | break; |
| 4959 | case WL_OUTPUT_TRANSFORM_90: |
| 4960 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 4961 | weston_matrix_translate(&output->matrix, 0, -output->height, 0); |
| 4962 | weston_matrix_rotate_xy(&output->matrix, 0, 1); |
| 4963 | break; |
| 4964 | case WL_OUTPUT_TRANSFORM_180: |
| 4965 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 4966 | weston_matrix_translate(&output->matrix, |
| 4967 | -output->width, -output->height, 0); |
| 4968 | weston_matrix_rotate_xy(&output->matrix, -1, 0); |
| 4969 | break; |
| 4970 | case WL_OUTPUT_TRANSFORM_270: |
| 4971 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 4972 | weston_matrix_translate(&output->matrix, -output->width, 0, 0); |
| 4973 | weston_matrix_rotate_xy(&output->matrix, 0, -1); |
| 4974 | break; |
| 4975 | } |
| 4976 | |
| 4977 | if (output->current_scale != 1) |
| 4978 | weston_matrix_scale(&output->matrix, |
| 4979 | output->current_scale, |
| 4980 | output->current_scale, 1); |
Neil Roberts | 6c3b01f | 2014-05-06 19:04:15 +0100 | [diff] [blame] | 4981 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4982 | output->dirty = 0; |
Derek Foreman | c002321 | 2015-03-24 11:36:13 -0500 | [diff] [blame] | 4983 | |
| 4984 | weston_matrix_invert(&output->inverse_matrix, &output->matrix); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4985 | } |
| 4986 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4987 | static void |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 4988 | 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] | 4989 | { |
| 4990 | output->transform = transform; |
Pekka Paalanen | 59987fa | 2016-04-26 15:50:59 +0300 | [diff] [blame] | 4991 | output->native_scale = scale; |
| 4992 | output->current_scale = scale; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4993 | |
Pekka Paalanen | 59987fa | 2016-04-26 15:50:59 +0300 | [diff] [blame] | 4994 | convert_size_by_transform_scale(&output->width, &output->height, |
| 4995 | output->current_mode->width, |
| 4996 | output->current_mode->height, |
| 4997 | transform, scale); |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 4998 | } |
| 4999 | |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5000 | static void |
| 5001 | weston_output_init_geometry(struct weston_output *output, int x, int y) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5002 | { |
| 5003 | output->x = x; |
| 5004 | output->y = y; |
| 5005 | |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 5006 | pixman_region32_fini(&output->previous_damage); |
Ander Conselvan de Oliveira | b8fcca9 | 2012-11-16 17:23:52 +0200 | [diff] [blame] | 5007 | pixman_region32_init(&output->previous_damage); |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 5008 | |
| 5009 | pixman_region32_fini(&output->region); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 5010 | pixman_region32_init_rect(&output->region, x, y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 5011 | output->width, |
| 5012 | output->height); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 5013 | } |
| 5014 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5015 | WL_EXPORT void |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5016 | weston_output_move(struct weston_output *output, int x, int y) |
| 5017 | { |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5018 | struct weston_head *head; |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5019 | struct wl_resource *resource; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5020 | int ver; |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5021 | |
| 5022 | output->move_x = x - output->x; |
| 5023 | output->move_y = y - output->y; |
| 5024 | |
| 5025 | if (output->move_x == 0 && output->move_y == 0) |
| 5026 | return; |
| 5027 | |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5028 | weston_output_init_geometry(output, x, y); |
| 5029 | |
| 5030 | output->dirty = 1; |
| 5031 | |
| 5032 | /* Move views on this output. */ |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 5033 | wl_signal_emit(&output->compositor->output_moved_signal, output); |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5034 | |
| 5035 | /* Notify clients of the change for output position. */ |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5036 | wl_list_for_each(head, &output->head_list, output_link) { |
| 5037 | wl_resource_for_each(resource, &head->resource_list) { |
| 5038 | wl_output_send_geometry(resource, |
| 5039 | output->x, |
| 5040 | output->y, |
| 5041 | head->mm_width, |
| 5042 | head->mm_height, |
| 5043 | head->subpixel, |
| 5044 | head->make, |
| 5045 | head->model, |
| 5046 | output->transform); |
Quanxian Wang | b2c8636 | 2014-03-14 09:16:25 +0800 | [diff] [blame] | 5047 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5048 | ver = wl_resource_get_version(resource); |
| 5049 | if (ver >= WL_OUTPUT_DONE_SINCE_VERSION) |
| 5050 | wl_output_send_done(resource); |
| 5051 | } |
Quanxian Wang | b2c8636 | 2014-03-14 09:16:25 +0800 | [diff] [blame] | 5052 | } |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 5053 | } |
| 5054 | |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5055 | /** Signal that a pending output is taken into use. |
| 5056 | * |
| 5057 | * Removes the output from the pending list and adds it to the compositor's |
| 5058 | * list of enabled outputs. The output created signal is emitted. |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5059 | * |
Pekka Paalanen | 2210ad0 | 2017-03-30 15:48:06 +0300 | [diff] [blame] | 5060 | * The output gets an internal ID assigned, and the wl_output global is |
| 5061 | * created. |
Pekka Paalanen | 3d2d497 | 2017-03-30 15:19:45 +0300 | [diff] [blame] | 5062 | * |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5063 | * \param compositor The compositor instance. |
| 5064 | * \param output The output to be added. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5065 | * |
| 5066 | * \internal |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5067 | */ |
Pekka Paalanen | f9681b5 | 2017-03-29 16:58:48 +0300 | [diff] [blame] | 5068 | static void |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5069 | weston_compositor_add_output(struct weston_compositor *compositor, |
| 5070 | struct weston_output *output) |
| 5071 | { |
Armin Krezović | e540384 | 2016-08-05 15:28:29 +0200 | [diff] [blame] | 5072 | struct weston_view *view, *next; |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 5073 | struct weston_head *head; |
Armin Krezović | e540384 | 2016-08-05 15:28:29 +0200 | [diff] [blame] | 5074 | |
Pekka Paalanen | 7f340ff | 2017-03-30 14:56:22 +0300 | [diff] [blame] | 5075 | assert(!output->enabled); |
Pekka Paalanen | 3d2d497 | 2017-03-30 15:19:45 +0300 | [diff] [blame] | 5076 | |
| 5077 | /* Verify we haven't reached the limit of 32 available output IDs */ |
| 5078 | assert(ffs(~compositor->output_id_pool) > 0); |
| 5079 | |
| 5080 | /* Invert the output id pool and look for the lowest numbered |
| 5081 | * switch (the least significant bit). Take that bit's position |
| 5082 | * as our ID, and mark it used in the compositor's output_id_pool. |
| 5083 | */ |
| 5084 | output->id = ffs(~compositor->output_id_pool) - 1; |
| 5085 | compositor->output_id_pool |= 1u << output->id; |
| 5086 | |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5087 | wl_list_remove(&output->link); |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5088 | wl_list_insert(compositor->output_list.prev, &output->link); |
Pekka Paalanen | 7f340ff | 2017-03-30 14:56:22 +0300 | [diff] [blame] | 5089 | output->enabled = true; |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5090 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5091 | wl_list_for_each(head, &output->head_list, output_link) { |
| 5092 | head->global = wl_global_create(compositor->wl_display, |
| 5093 | &wl_output_interface, 3, |
| 5094 | head, bind_output); |
| 5095 | } |
Pekka Paalanen | 2210ad0 | 2017-03-30 15:48:06 +0300 | [diff] [blame] | 5096 | |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 5097 | wl_signal_emit(&compositor->output_created_signal, output); |
Armin Krezović | e540384 | 2016-08-05 15:28:29 +0200 | [diff] [blame] | 5098 | |
| 5099 | wl_list_for_each_safe(view, next, &compositor->view_list, link) |
| 5100 | weston_view_geometry_dirty(view); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 5101 | } |
| 5102 | |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5103 | /** Transform device coordinates into global coordinates |
| 5104 | * |
| 5105 | * \param device_x[in] X coordinate in device units. |
| 5106 | * \param device_y[in] Y coordinate in device units. |
| 5107 | * \param x[out] X coordinate in the global space. |
| 5108 | * \param y[out] Y coordinate in the global space. |
| 5109 | * |
| 5110 | * Transforms coordinates from the device coordinate space |
| 5111 | * (physical pixel units) to the global coordinate space (logical pixel units). |
| 5112 | * This takes into account output transform and scale. |
| 5113 | * |
| 5114 | * \memberof weston_output |
| 5115 | * \internal |
| 5116 | */ |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 5117 | WL_EXPORT void |
| 5118 | weston_output_transform_coordinate(struct weston_output *output, |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 5119 | double device_x, double device_y, |
| 5120 | double *x, double *y) |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 5121 | { |
Derek Foreman | 0f67941 | 2014-10-02 13:41:17 -0500 | [diff] [blame] | 5122 | struct weston_vector p = { { |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 5123 | device_x, |
| 5124 | device_y, |
Derek Foreman | 0f67941 | 2014-10-02 13:41:17 -0500 | [diff] [blame] | 5125 | 0.0, |
| 5126 | 1.0 } }; |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 5127 | |
Derek Foreman | 67a18b9 | 2015-03-24 11:36:14 -0500 | [diff] [blame] | 5128 | weston_matrix_transform(&output->inverse_matrix, &p); |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 5129 | |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 5130 | *x = p.f[0] / p.f[3]; |
| 5131 | *y = p.f[1] / p.f[3]; |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 5132 | } |
| 5133 | |
Pekka Paalanen | e6ac4fc | 2017-03-29 16:07:34 +0300 | [diff] [blame] | 5134 | /** Removes output from compositor's list of enabled outputs |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5135 | * |
| 5136 | * \param output The weston_output object that is being removed. |
| 5137 | * |
Pekka Paalanen | e6ac4fc | 2017-03-29 16:07:34 +0300 | [diff] [blame] | 5138 | * The following happens: |
| 5139 | * |
| 5140 | * - The output assignments of all views in the current scenegraph are |
| 5141 | * recomputed. |
| 5142 | * |
| 5143 | * - Presentation feedback is discarded. |
| 5144 | * |
| 5145 | * - Compositor is notified that outputs were changed and |
| 5146 | * applies the necessary changes to re-layout outputs. |
| 5147 | * |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5148 | * - The output is put back in the pending outputs list. |
| 5149 | * |
Pekka Paalanen | e6ac4fc | 2017-03-29 16:07:34 +0300 | [diff] [blame] | 5150 | * - Signal is emitted to notify all users of the weston_output |
| 5151 | * object that the output is being destroyed. |
| 5152 | * |
| 5153 | * - wl_output protocol objects referencing this weston_output |
Pekka Paalanen | 2210ad0 | 2017-03-30 15:48:06 +0300 | [diff] [blame] | 5154 | * are made inert, and the wl_output global is removed. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5155 | * |
Pekka Paalanen | 3d2d497 | 2017-03-30 15:19:45 +0300 | [diff] [blame] | 5156 | * - The output's internal ID is released. |
| 5157 | * |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5158 | * \memberof weston_output |
| 5159 | * \internal |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5160 | */ |
| 5161 | static void |
| 5162 | weston_compositor_remove_output(struct weston_output *output) |
| 5163 | { |
Pekka Paalanen | bccda71 | 2017-03-29 16:16:04 +0300 | [diff] [blame] | 5164 | struct weston_compositor *compositor = output->compositor; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5165 | struct weston_view *view; |
Pekka Paalanen | 1b9bf59 | 2017-03-27 12:15:38 +0300 | [diff] [blame] | 5166 | struct weston_head *head; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5167 | |
| 5168 | assert(output->destroying); |
Pekka Paalanen | 7f340ff | 2017-03-30 14:56:22 +0300 | [diff] [blame] | 5169 | assert(output->enabled); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5170 | |
Pekka Paalanen | bccda71 | 2017-03-29 16:16:04 +0300 | [diff] [blame] | 5171 | wl_list_for_each(view, &compositor->view_list, link) { |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5172 | if (view->output_mask & (1u << output->id)) |
| 5173 | weston_view_assign_output(view); |
| 5174 | } |
| 5175 | |
| 5176 | weston_presentation_feedback_discard_list(&output->feedback_list); |
| 5177 | |
Pekka Paalanen | bccda71 | 2017-03-29 16:16:04 +0300 | [diff] [blame] | 5178 | weston_compositor_reflow_outputs(compositor, output, output->width); |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5179 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5180 | wl_list_remove(&output->link); |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5181 | wl_list_insert(compositor->pending_output_list.prev, &output->link); |
Pekka Paalanen | 7f340ff | 2017-03-30 14:56:22 +0300 | [diff] [blame] | 5182 | output->enabled = false; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5183 | |
Pekka Paalanen | bccda71 | 2017-03-29 16:16:04 +0300 | [diff] [blame] | 5184 | wl_signal_emit(&compositor->output_destroyed_signal, output); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5185 | wl_signal_emit(&output->destroy_signal, output); |
| 5186 | |
Pekka Paalanen | d9dcc6d | 2017-12-04 15:28:13 +0200 | [diff] [blame] | 5187 | wl_list_for_each(head, &output->head_list, output_link) |
| 5188 | weston_head_remove_global(head); |
Pekka Paalanen | 3d2d497 | 2017-03-30 15:19:45 +0300 | [diff] [blame] | 5189 | |
| 5190 | compositor->output_id_pool &= ~(1u << output->id); |
| 5191 | output->id = 0xffffffff; /* invalid */ |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5192 | } |
| 5193 | |
| 5194 | /** Sets the output scale for a given output. |
| 5195 | * |
| 5196 | * \param output The weston_output object that the scale is set for. |
| 5197 | * \param scale Scale factor for the given output. |
| 5198 | * |
| 5199 | * It only supports setting scale for an output that |
| 5200 | * is not enabled and it can only be ran once. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5201 | * |
| 5202 | * \memberof weston_output |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5203 | */ |
| 5204 | WL_EXPORT void |
| 5205 | weston_output_set_scale(struct weston_output *output, |
| 5206 | int32_t scale) |
| 5207 | { |
| 5208 | /* We can only set scale on a disabled output */ |
| 5209 | assert(!output->enabled); |
| 5210 | |
| 5211 | /* We only want to set scale once */ |
| 5212 | assert(!output->scale); |
| 5213 | |
| 5214 | output->scale = scale; |
| 5215 | } |
| 5216 | |
| 5217 | /** Sets the output transform for a given output. |
| 5218 | * |
| 5219 | * \param output The weston_output object that the transform is set for. |
| 5220 | * \param transform Transform value for the given output. |
| 5221 | * |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5222 | * Refer to wl_output::transform section located at |
| 5223 | * https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_output |
| 5224 | * for list of values that can be passed to this function. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5225 | * |
| 5226 | * \memberof weston_output |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5227 | */ |
| 5228 | WL_EXPORT void |
| 5229 | weston_output_set_transform(struct weston_output *output, |
| 5230 | uint32_t transform) |
| 5231 | { |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 5232 | struct weston_pointer_motion_event ev; |
| 5233 | struct wl_resource *resource; |
| 5234 | struct weston_seat *seat; |
| 5235 | pixman_region32_t old_region; |
| 5236 | int mid_x, mid_y; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5237 | struct weston_head *head; |
| 5238 | int ver; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5239 | |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 5240 | if (!output->enabled && output->transform == UINT32_MAX) { |
| 5241 | output->transform = transform; |
| 5242 | return; |
| 5243 | } |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5244 | |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 5245 | weston_output_transform_scale_init(output, transform, output->scale); |
| 5246 | |
| 5247 | pixman_region32_init(&old_region); |
| 5248 | pixman_region32_copy(&old_region, &output->region); |
| 5249 | |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 5250 | weston_output_init_geometry(output, output->x, output->y); |
| 5251 | |
| 5252 | output->dirty = 1; |
| 5253 | |
| 5254 | /* Notify clients of the change for output transform. */ |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5255 | wl_list_for_each(head, &output->head_list, output_link) { |
| 5256 | wl_resource_for_each(resource, &head->resource_list) { |
| 5257 | wl_output_send_geometry(resource, |
| 5258 | output->x, |
| 5259 | output->y, |
| 5260 | head->mm_width, |
| 5261 | head->mm_height, |
| 5262 | head->subpixel, |
| 5263 | head->make, |
| 5264 | head->model, |
| 5265 | output->transform); |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 5266 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5267 | ver = wl_resource_get_version(resource); |
| 5268 | if (ver >= WL_OUTPUT_DONE_SINCE_VERSION) |
| 5269 | wl_output_send_done(resource); |
| 5270 | } |
Ilia Bozhinov | 8564a0d | 2017-06-25 12:21:39 +0000 | [diff] [blame] | 5271 | } |
| 5272 | |
| 5273 | /* we must ensure that pointers are inside output, otherwise they disappear */ |
| 5274 | mid_x = output->x + output->width / 2; |
| 5275 | mid_y = output->y + output->height / 2; |
| 5276 | |
| 5277 | ev.mask = WESTON_POINTER_MOTION_ABS; |
| 5278 | ev.x = wl_fixed_to_double(wl_fixed_from_int(mid_x)); |
| 5279 | ev.y = wl_fixed_to_double(wl_fixed_from_int(mid_y)); |
| 5280 | |
| 5281 | wl_list_for_each(seat, &output->compositor->seat_list, link) { |
| 5282 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 5283 | |
| 5284 | if (pointer && pixman_region32_contains_point(&old_region, |
| 5285 | wl_fixed_to_int(pointer->x), |
| 5286 | wl_fixed_to_int(pointer->y), |
| 5287 | NULL)) |
| 5288 | weston_pointer_move(pointer, &ev); |
| 5289 | } |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5290 | } |
| 5291 | |
| 5292 | /** Initializes a weston_output object with enough data so |
| 5293 | ** an output can be configured. |
| 5294 | * |
| 5295 | * \param output The weston_output object to initialize |
| 5296 | * \param compositor The compositor instance. |
Pekka Paalanen | 26ac2e1 | 2017-04-03 13:18:13 +0300 | [diff] [blame] | 5297 | * \param name Name for the output (the string is copied). |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5298 | * |
| 5299 | * Sets initial values for fields that are expected to be |
| 5300 | * configured either by compositors or backends. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5301 | * |
Pekka Paalanen | 26ac2e1 | 2017-04-03 13:18:13 +0300 | [diff] [blame] | 5302 | * The name is used in logs, and can be used by compositors as a configuration |
| 5303 | * identifier. |
| 5304 | * |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5305 | * \memberof weston_output |
| 5306 | * \internal |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5307 | */ |
| 5308 | WL_EXPORT void |
Armin Krezović | 4008740 | 2016-09-30 14:11:12 +0200 | [diff] [blame] | 5309 | weston_output_init(struct weston_output *output, |
Pekka Paalanen | 26ac2e1 | 2017-04-03 13:18:13 +0300 | [diff] [blame] | 5310 | struct weston_compositor *compositor, |
| 5311 | const char *name) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5312 | { |
| 5313 | output->compositor = compositor; |
| 5314 | output->destroying = 0; |
Pekka Paalanen | 26ac2e1 | 2017-04-03 13:18:13 +0300 | [diff] [blame] | 5315 | output->name = strdup(name); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5316 | wl_list_init(&output->link); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5317 | output->enabled = false; |
| 5318 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5319 | wl_list_init(&output->head_list); |
| 5320 | |
Pekka Paalanen | 9b02e47 | 2017-08-14 14:43:13 +0300 | [diff] [blame] | 5321 | weston_head_init(&output->head, name); |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame^] | 5322 | output->head.allocator_output = output; |
| 5323 | if (!compositor->backend->create_output) { |
| 5324 | weston_head_set_connection_status(&output->head, true); |
| 5325 | weston_compositor_add_head(compositor, &output->head); |
| 5326 | } |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5327 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5328 | /* Add some (in)sane defaults which can be used |
| 5329 | * for checking if an output was properly configured |
| 5330 | */ |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5331 | output->scale = 0; |
| 5332 | /* Can't use -1 on uint32_t and 0 is valid enum value */ |
| 5333 | output->transform = UINT32_MAX; |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 5334 | |
| 5335 | pixman_region32_init(&output->previous_damage); |
| 5336 | pixman_region32_init(&output->region); |
Pekka Paalanen | 4270414 | 2017-09-06 16:47:52 +0300 | [diff] [blame] | 5337 | wl_list_init(&output->mode_list); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5338 | } |
| 5339 | |
| 5340 | /** Adds weston_output object to pending output list. |
| 5341 | * |
| 5342 | * \param output The weston_output object to add |
| 5343 | * \param compositor The compositor instance. |
| 5344 | * |
| 5345 | * Also notifies the compositor that an output is pending for |
| 5346 | * configuration. |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5347 | * |
Pekka Paalanen | ae6d35d | 2017-08-16 12:07:14 +0300 | [diff] [blame] | 5348 | * The opposite of this operation is built into weston_output_release(). |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5349 | * |
| 5350 | * \memberof weston_output |
| 5351 | * \internal |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5352 | */ |
| 5353 | WL_EXPORT void |
| 5354 | weston_compositor_add_pending_output(struct weston_output *output, |
| 5355 | struct weston_compositor *compositor) |
| 5356 | { |
Pekka Paalanen | e952a01 | 2017-03-29 17:14:00 +0300 | [diff] [blame] | 5357 | assert(output->disable); |
| 5358 | assert(output->enable); |
| 5359 | |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5360 | wl_list_remove(&output->link); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5361 | wl_list_insert(compositor->pending_output_list.prev, &output->link); |
| 5362 | wl_signal_emit(&compositor->output_pending_signal, output); |
| 5363 | } |
| 5364 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5365 | /** Constructs a weston_output object that can be used by the compositor. |
| 5366 | * |
Pekka Paalanen | cc201e4 | 2017-03-30 15:11:25 +0300 | [diff] [blame] | 5367 | * \param output The weston_output object that needs to be enabled. Must not |
| 5368 | * be enabled already. |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5369 | * |
| 5370 | * Output coordinates are calculated and each new output is by default |
| 5371 | * assigned to the right of previous one. |
| 5372 | * |
| 5373 | * Sets up the transformation, zoom, and geometry of the output using |
| 5374 | * the properties that need to be configured by the compositor. |
| 5375 | * |
| 5376 | * Establishes a repaint timer for the output with the relevant display |
| 5377 | * object's event loop. See output_repaint_timer_handler(). |
| 5378 | * |
| 5379 | * The output is assigned an ID. Weston can support up to 32 distinct |
| 5380 | * outputs, with IDs numbered from 0-31; the compositor's output_id_pool |
| 5381 | * is referred to and used to find the first available ID number, and |
| 5382 | * then this ID is marked as used in output_id_pool. |
| 5383 | * |
| 5384 | * The output is also assigned a Wayland global with the wl_output |
| 5385 | * external interface. |
| 5386 | * |
| 5387 | * Backend specific function is called to set up the output output. |
| 5388 | * |
| 5389 | * Output is added to the compositor's output list |
| 5390 | * |
| 5391 | * If the backend specific function fails, the weston_output object |
| 5392 | * is returned to a state it was before calling this function and |
| 5393 | * is added to the compositor's pending_output_list in case it needs |
| 5394 | * to be reconfigured or just so it can be destroyed at shutdown. |
| 5395 | * |
| 5396 | * 0 is returned on success, -1 on failure. |
| 5397 | */ |
| 5398 | WL_EXPORT int |
| 5399 | weston_output_enable(struct weston_output *output) |
| 5400 | { |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 5401 | struct weston_compositor *c = output->compositor; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5402 | struct weston_output *iterator; |
| 5403 | int x = 0, y = 0; |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5404 | int ret; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5405 | |
Pekka Paalanen | cc201e4 | 2017-03-30 15:11:25 +0300 | [diff] [blame] | 5406 | if (output->enabled) { |
| 5407 | weston_log("Error: attempt to enable an enabled output '%s'\n", |
| 5408 | output->name); |
| 5409 | return -1; |
| 5410 | } |
| 5411 | |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 5412 | iterator = container_of(c->output_list.prev, |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5413 | struct weston_output, link); |
| 5414 | |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 5415 | if (!wl_list_empty(&c->output_list)) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5416 | x = iterator->x + iterator->width; |
| 5417 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5418 | /* Make sure the scale is set up */ |
| 5419 | assert(output->scale); |
| 5420 | |
| 5421 | /* Make sure we have a transform set */ |
| 5422 | assert(output->transform != UINT32_MAX); |
| 5423 | |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 5424 | output->x = x; |
| 5425 | output->y = y; |
| 5426 | output->dirty = 1; |
| 5427 | output->original_scale = output->scale; |
| 5428 | |
| 5429 | weston_output_transform_scale_init(output, output->transform, output->scale); |
| 5430 | weston_output_init_zoom(output); |
| 5431 | |
| 5432 | weston_output_init_geometry(output, x, y); |
| 5433 | weston_output_damage(output); |
| 5434 | |
| 5435 | wl_signal_init(&output->frame_signal); |
| 5436 | wl_signal_init(&output->destroy_signal); |
| 5437 | wl_list_init(&output->animation_list); |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 5438 | wl_list_init(&output->feedback_list); |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 5439 | |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5440 | /* XXX: Temporary until all backends are converted. */ |
| 5441 | if (wl_list_empty(&output->head_list)) { |
| 5442 | ret = weston_output_attach_head(output, &output->head); |
| 5443 | assert(ret == 0); |
| 5444 | } |
| 5445 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5446 | /* Enable the output (set up the crtc or create a |
| 5447 | * window representing the output, set up the |
| 5448 | * renderer, etc) |
| 5449 | */ |
| 5450 | if (output->enable(output) < 0) { |
| 5451 | weston_log("Enabling output \"%s\" failed.\n", output->name); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5452 | return -1; |
| 5453 | } |
| 5454 | |
| 5455 | weston_compositor_add_output(output->compositor, output); |
| 5456 | |
| 5457 | return 0; |
| 5458 | } |
| 5459 | |
| 5460 | /** Converts a weston_output object to a pending output state, so it |
| 5461 | ** can be configured again or destroyed. |
| 5462 | * |
| 5463 | * \param output The weston_output object that needs to be disabled. |
| 5464 | * |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5465 | * Calls a backend specific function to disable an output, in case |
| 5466 | * such function exists. |
| 5467 | * |
Pekka Paalanen | c65df64 | 2017-03-29 15:45:46 +0300 | [diff] [blame] | 5468 | * The backend specific disable function may choose to postpone the disabling |
| 5469 | * by returning a negative value, in which case this function returns early. |
| 5470 | * In that case the backend will guarantee the output will be disabled soon |
| 5471 | * by the backend calling this function again. One must not attempt to re-enable |
| 5472 | * the output until that happens. |
| 5473 | * |
| 5474 | * 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] | 5475 | * from weston's output_list (see weston_compositor_remove_output()) |
| 5476 | * and is returned to a state it was before weston_output_enable() |
| 5477 | * was ran (see weston_output_enable_undo()). |
| 5478 | * |
Pekka Paalanen | c65df64 | 2017-03-29 15:45:46 +0300 | [diff] [blame] | 5479 | * See weston_output_init() for more information on the |
| 5480 | * state output is returned to. |
Pekka Paalanen | cc201e4 | 2017-03-30 15:11:25 +0300 | [diff] [blame] | 5481 | * |
| 5482 | * If the output has never been enabled yet, this function can still be |
| 5483 | * called to ensure that the output is actually turned off rather than left |
| 5484 | * in the state it was discovered in. |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5485 | */ |
| 5486 | WL_EXPORT void |
| 5487 | weston_output_disable(struct weston_output *output) |
| 5488 | { |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5489 | /* Should we rename this? */ |
| 5490 | output->destroying = 1; |
| 5491 | |
Pekka Paalanen | c65df64 | 2017-03-29 15:45:46 +0300 | [diff] [blame] | 5492 | /* Disable is called unconditionally also for not-enabled outputs, |
| 5493 | * because at compositor start-up, if there is an output that is |
| 5494 | * already on but the compositor wants to turn it off, we have to |
| 5495 | * forward the turn-off to the backend so it knows to do it. |
| 5496 | * The backend cannot initially turn off everything, because it |
| 5497 | * would cause unnecessary mode-sets for all outputs the compositor |
| 5498 | * wants to be on. |
| 5499 | */ |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5500 | if (output->disable(output) < 0) |
| 5501 | return; |
| 5502 | |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 5503 | if (output->enabled) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5504 | weston_compositor_remove_output(output); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5505 | |
| 5506 | output->destroying = 0; |
| 5507 | } |
| 5508 | |
| 5509 | /** Emits a signal to indicate that there are outputs waiting to be configured. |
| 5510 | * |
| 5511 | * \param compositor The compositor instance |
| 5512 | */ |
| 5513 | WL_EXPORT void |
| 5514 | weston_pending_output_coldplug(struct weston_compositor *compositor) |
| 5515 | { |
| 5516 | struct weston_output *output, *next; |
| 5517 | |
| 5518 | wl_list_for_each_safe(output, next, &compositor->pending_output_list, link) |
| 5519 | wl_signal_emit(&compositor->output_pending_signal, output); |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5520 | |
| 5521 | /* Execute the heads changed callback manually to ensure it is |
| 5522 | * processed before any plugins get their start-up idle tasks ran. |
| 5523 | * This ensures the plugins see all the initial outputs. |
| 5524 | */ |
| 5525 | if (compositor->heads_changed_source) { |
| 5526 | wl_event_source_remove(compositor->heads_changed_source); |
| 5527 | weston_compositor_call_heads_changed(compositor); |
| 5528 | } |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5529 | } |
| 5530 | |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 5531 | /** Uninitialize an output |
| 5532 | * |
| 5533 | * Removes the output from the list of enabled outputs if necessary, but |
| 5534 | * does not call the backend's output disable function. The output will no |
| 5535 | * longer be in the list of pending outputs either. |
| 5536 | * |
| 5537 | * All fields of weston_output become uninitialized, i.e. should not be used |
| 5538 | * anymore. The caller can free the memory after this. |
| 5539 | * |
| 5540 | * \memberof weston_output |
| 5541 | * \internal |
| 5542 | */ |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5543 | WL_EXPORT void |
Pekka Paalanen | ae6d35d | 2017-08-16 12:07:14 +0300 | [diff] [blame] | 5544 | weston_output_release(struct weston_output *output) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5545 | { |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5546 | struct weston_head *head, *tmp; |
| 5547 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5548 | output->destroying = 1; |
| 5549 | |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 5550 | if (output->enabled) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5551 | weston_compositor_remove_output(output); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5552 | |
Pekka Paalanen | 4b582c7 | 2017-03-30 16:04:58 +0300 | [diff] [blame] | 5553 | pixman_region32_fini(&output->region); |
| 5554 | pixman_region32_fini(&output->previous_damage); |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 5555 | wl_list_remove(&output->link); |
Pekka Paalanen | 7cdbabe | 2017-03-28 16:27:25 +0300 | [diff] [blame] | 5556 | |
| 5557 | wl_list_for_each_safe(head, tmp, &output->head_list, output_link) |
| 5558 | weston_head_detach(head); |
| 5559 | |
| 5560 | weston_head_release(&output->head); |
| 5561 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5562 | free(output->name); |
| 5563 | } |
| 5564 | |
Pekka Paalanen | 992a8cb | 2017-08-16 10:39:17 +0300 | [diff] [blame^] | 5565 | /** Create an output for an unused head |
| 5566 | * |
| 5567 | * \param compositor The compositor. |
| 5568 | * \param head The head to attach to the output. |
| 5569 | * \return A new \c weston_output, or NULL on failure. |
| 5570 | * |
| 5571 | * This creates a new weston_output that starts with the given head attached. |
| 5572 | * The output inherits the name of the head. The head must not be already |
| 5573 | * attached to another output. |
| 5574 | * |
| 5575 | * An output must be configured before it can be enabled. |
| 5576 | * |
| 5577 | * \memberof weston_compositor |
| 5578 | */ |
| 5579 | WL_EXPORT struct weston_output * |
| 5580 | weston_compositor_create_output_with_head(struct weston_compositor *compositor, |
| 5581 | struct weston_head *head) |
| 5582 | { |
| 5583 | struct weston_output *output; |
| 5584 | |
| 5585 | if (head->allocator_output) { |
| 5586 | /* XXX: compatibility path to be removed after all converted */ |
| 5587 | output = head->allocator_output; |
| 5588 | } else { |
| 5589 | assert(compositor->backend->create_output); |
| 5590 | output = compositor->backend->create_output(compositor, |
| 5591 | head->name); |
| 5592 | } |
| 5593 | |
| 5594 | if (!output) |
| 5595 | return NULL; |
| 5596 | |
| 5597 | if (weston_output_attach_head(output, head) < 0) { |
| 5598 | if (!head->allocator_output) |
| 5599 | output->destroy(output); |
| 5600 | |
| 5601 | return NULL; |
| 5602 | } |
| 5603 | |
| 5604 | return output; |
| 5605 | } |
| 5606 | |
| 5607 | /** Destroy an output |
| 5608 | * |
| 5609 | * \param output The output to destroy. |
| 5610 | * |
| 5611 | * The heads attached to the given output are detached and become unused again. |
| 5612 | * |
| 5613 | * It is not necessary to explicitly destroy all outputs at compositor exit. |
| 5614 | * weston_compositor_destroy() will automatically destroy any remaining |
| 5615 | * outputs. |
| 5616 | * |
| 5617 | * \memberof weston_output |
| 5618 | */ |
| 5619 | WL_EXPORT void |
| 5620 | weston_output_destroy(struct weston_output *output) |
| 5621 | { |
| 5622 | struct weston_head *head; |
| 5623 | |
| 5624 | /* XXX: compatibility path to be removed after all converted */ |
| 5625 | head = weston_output_get_first_head(output); |
| 5626 | if (head->allocator_output) { |
| 5627 | /* The old design: backend is responsible for destroying the |
| 5628 | * output, so just undo create_output_with_head() |
| 5629 | */ |
| 5630 | weston_head_detach(head); |
| 5631 | return; |
| 5632 | } |
| 5633 | |
| 5634 | output->destroy(output); |
| 5635 | } |
| 5636 | |
Pekka Paalanen | cf0a476 | 2017-04-04 16:36:07 +0300 | [diff] [blame] | 5637 | /** When you need a head... |
| 5638 | * |
| 5639 | * This function is a hack, used until all code has been converted to become |
| 5640 | * multi-head aware. |
| 5641 | * |
| 5642 | * \param output The weston_output whose head to get. |
| 5643 | * \return The first head in the output's list. |
| 5644 | */ |
| 5645 | WL_EXPORT struct weston_head * |
| 5646 | weston_output_get_first_head(struct weston_output *output) |
| 5647 | { |
| 5648 | if (wl_list_empty(&output->head_list)) |
| 5649 | return NULL; |
| 5650 | |
| 5651 | return container_of(output->head_list.next, |
| 5652 | struct weston_head, output_link); |
| 5653 | } |
| 5654 | |
Benjamin Franzke | 315b3dc | 2011-03-08 11:32:57 +0100 | [diff] [blame] | 5655 | static void |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 5656 | destroy_viewport(struct wl_resource *resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 5657 | { |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 5658 | struct weston_surface *surface = |
| 5659 | wl_resource_get_user_data(resource); |
| 5660 | |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 5661 | if (!surface) |
| 5662 | return; |
| 5663 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 5664 | surface->viewport_resource = NULL; |
Pekka Paalanen | f0cad48 | 2014-03-14 14:38:16 +0200 | [diff] [blame] | 5665 | surface->pending.buffer_viewport.buffer.src_width = |
| 5666 | wl_fixed_from_int(-1); |
| 5667 | surface->pending.buffer_viewport.surface.width = -1; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 5668 | surface->pending.buffer_viewport.changed = 1; |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 5669 | } |
| 5670 | |
| 5671 | static void |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 5672 | viewport_destroy(struct wl_client *client, |
| 5673 | struct wl_resource *resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 5674 | { |
| 5675 | wl_resource_destroy(resource); |
| 5676 | } |
| 5677 | |
| 5678 | static void |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 5679 | viewport_set_source(struct wl_client *client, |
| 5680 | struct wl_resource *resource, |
| 5681 | wl_fixed_t src_x, |
| 5682 | wl_fixed_t src_y, |
| 5683 | wl_fixed_t src_width, |
| 5684 | wl_fixed_t src_height) |
| 5685 | { |
| 5686 | struct weston_surface *surface = |
| 5687 | wl_resource_get_user_data(resource); |
| 5688 | |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 5689 | if (!surface) { |
| 5690 | wl_resource_post_error(resource, |
| 5691 | WP_VIEWPORT_ERROR_NO_SURFACE, |
| 5692 | "wl_surface for this viewport is no longer exists"); |
| 5693 | return; |
| 5694 | } |
| 5695 | |
| 5696 | assert(surface->viewport_resource == resource); |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 5697 | assert(surface->resource); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 5698 | |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 5699 | if (src_width == wl_fixed_from_int(-1) && |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 5700 | src_height == wl_fixed_from_int(-1) && |
| 5701 | src_x == wl_fixed_from_int(-1) && |
| 5702 | src_y == wl_fixed_from_int(-1)) { |
| 5703 | /* unset source rect */ |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 5704 | surface->pending.buffer_viewport.buffer.src_width = |
| 5705 | wl_fixed_from_int(-1); |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 5706 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 5707 | return; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 5708 | } |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 5709 | |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 5710 | 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] | 5711 | wl_resource_post_error(resource, |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 5712 | WP_VIEWPORT_ERROR_BAD_VALUE, |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 5713 | "wl_surface@%d viewport source " |
| 5714 | "w=%f <= 0, h=%f <= 0, x=%f < 0, or y=%f < 0", |
| 5715 | wl_resource_get_id(surface->resource), |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 5716 | wl_fixed_to_double(src_width), |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 5717 | wl_fixed_to_double(src_height), |
| 5718 | wl_fixed_to_double(src_x), |
| 5719 | wl_fixed_to_double(src_y)); |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 5720 | return; |
| 5721 | } |
| 5722 | |
| 5723 | surface->pending.buffer_viewport.buffer.src_x = src_x; |
| 5724 | surface->pending.buffer_viewport.buffer.src_y = src_y; |
| 5725 | surface->pending.buffer_viewport.buffer.src_width = src_width; |
| 5726 | surface->pending.buffer_viewport.buffer.src_height = src_height; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 5727 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 5728 | } |
| 5729 | |
| 5730 | static void |
| 5731 | viewport_set_destination(struct wl_client *client, |
| 5732 | struct wl_resource *resource, |
| 5733 | int32_t dst_width, |
| 5734 | int32_t dst_height) |
| 5735 | { |
| 5736 | struct weston_surface *surface = |
| 5737 | wl_resource_get_user_data(resource); |
| 5738 | |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 5739 | if (!surface) { |
| 5740 | wl_resource_post_error(resource, |
| 5741 | WP_VIEWPORT_ERROR_NO_SURFACE, |
| 5742 | "wl_surface for this viewport no longer exists"); |
| 5743 | return; |
| 5744 | } |
| 5745 | |
| 5746 | assert(surface->viewport_resource == resource); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 5747 | |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 5748 | if (dst_width == -1 && dst_height == -1) { |
| 5749 | /* unset destination size */ |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 5750 | surface->pending.buffer_viewport.surface.width = -1; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 5751 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 5752 | return; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 5753 | } |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 5754 | |
| 5755 | if (dst_width <= 0 || dst_height <= 0) { |
| 5756 | wl_resource_post_error(resource, |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 5757 | WP_VIEWPORT_ERROR_BAD_VALUE, |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 5758 | "destination size must be positive (%dx%d)", |
| 5759 | dst_width, dst_height); |
| 5760 | return; |
| 5761 | } |
| 5762 | |
| 5763 | surface->pending.buffer_viewport.surface.width = dst_width; |
| 5764 | surface->pending.buffer_viewport.surface.height = dst_height; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 5765 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 5766 | } |
| 5767 | |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 5768 | static const struct wp_viewport_interface viewport_interface = { |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 5769 | viewport_destroy, |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 5770 | viewport_set_source, |
| 5771 | viewport_set_destination |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 5772 | }; |
| 5773 | |
| 5774 | static void |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 5775 | viewporter_destroy(struct wl_client *client, |
| 5776 | struct wl_resource *resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 5777 | { |
| 5778 | wl_resource_destroy(resource); |
| 5779 | } |
| 5780 | |
| 5781 | static void |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 5782 | viewporter_get_viewport(struct wl_client *client, |
| 5783 | struct wl_resource *viewporter, |
| 5784 | uint32_t id, |
| 5785 | struct wl_resource *surface_resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 5786 | { |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 5787 | int version = wl_resource_get_version(viewporter); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 5788 | struct weston_surface *surface = |
| 5789 | wl_resource_get_user_data(surface_resource); |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 5790 | struct wl_resource *resource; |
| 5791 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 5792 | if (surface->viewport_resource) { |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 5793 | wl_resource_post_error(viewporter, |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 5794 | WP_VIEWPORTER_ERROR_VIEWPORT_EXISTS, |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 5795 | "a viewport for that surface already exists"); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 5796 | return; |
| 5797 | } |
| 5798 | |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 5799 | resource = wl_resource_create(client, &wp_viewport_interface, |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 5800 | version, id); |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 5801 | if (resource == NULL) { |
| 5802 | wl_client_post_no_memory(client); |
| 5803 | return; |
| 5804 | } |
| 5805 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 5806 | wl_resource_set_implementation(resource, &viewport_interface, |
| 5807 | surface, destroy_viewport); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 5808 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 5809 | surface->viewport_resource = resource; |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 5810 | } |
| 5811 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 5812 | static const struct wp_viewporter_interface viewporter_interface = { |
| 5813 | viewporter_destroy, |
| 5814 | viewporter_get_viewport |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 5815 | }; |
| 5816 | |
| 5817 | static void |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 5818 | bind_viewporter(struct wl_client *client, |
| 5819 | void *data, uint32_t version, uint32_t id) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 5820 | { |
| 5821 | struct wl_resource *resource; |
| 5822 | |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 5823 | resource = wl_resource_create(client, &wp_viewporter_interface, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 5824 | version, id); |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 5825 | if (resource == NULL) { |
| 5826 | wl_client_post_no_memory(client); |
| 5827 | return; |
| 5828 | } |
| 5829 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 5830 | wl_resource_set_implementation(resource, &viewporter_interface, |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 5831 | NULL, NULL); |
| 5832 | } |
| 5833 | |
| 5834 | static void |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 5835 | destroy_presentation_feedback(struct wl_resource *feedback_resource) |
| 5836 | { |
| 5837 | struct weston_presentation_feedback *feedback; |
| 5838 | |
| 5839 | feedback = wl_resource_get_user_data(feedback_resource); |
| 5840 | |
| 5841 | wl_list_remove(&feedback->link); |
| 5842 | free(feedback); |
| 5843 | } |
| 5844 | |
| 5845 | static void |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 5846 | presentation_destroy(struct wl_client *client, struct wl_resource *resource) |
| 5847 | { |
| 5848 | wl_resource_destroy(resource); |
| 5849 | } |
| 5850 | |
| 5851 | static void |
| 5852 | presentation_feedback(struct wl_client *client, |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 5853 | struct wl_resource *presentation_resource, |
| 5854 | struct wl_resource *surface_resource, |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 5855 | uint32_t callback) |
| 5856 | { |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 5857 | struct weston_surface *surface; |
| 5858 | struct weston_presentation_feedback *feedback; |
| 5859 | |
| 5860 | surface = wl_resource_get_user_data(surface_resource); |
| 5861 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 5862 | feedback = zalloc(sizeof *feedback); |
| 5863 | if (feedback == NULL) |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 5864 | goto err_calloc; |
| 5865 | |
| 5866 | feedback->resource = wl_resource_create(client, |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 5867 | &wp_presentation_feedback_interface, |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 5868 | 1, callback); |
| 5869 | if (!feedback->resource) |
| 5870 | goto err_create; |
| 5871 | |
| 5872 | wl_resource_set_implementation(feedback->resource, NULL, feedback, |
| 5873 | destroy_presentation_feedback); |
| 5874 | |
| 5875 | wl_list_insert(&surface->pending.feedback_list, &feedback->link); |
| 5876 | |
| 5877 | return; |
| 5878 | |
| 5879 | err_create: |
| 5880 | free(feedback); |
| 5881 | |
| 5882 | err_calloc: |
| 5883 | wl_client_post_no_memory(client); |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 5884 | } |
| 5885 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 5886 | static const struct wp_presentation_interface presentation_implementation = { |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 5887 | presentation_destroy, |
| 5888 | presentation_feedback |
| 5889 | }; |
| 5890 | |
| 5891 | static void |
| 5892 | bind_presentation(struct wl_client *client, |
| 5893 | void *data, uint32_t version, uint32_t id) |
| 5894 | { |
| 5895 | struct weston_compositor *compositor = data; |
| 5896 | struct wl_resource *resource; |
| 5897 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 5898 | resource = wl_resource_create(client, &wp_presentation_interface, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 5899 | version, id); |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 5900 | if (resource == NULL) { |
| 5901 | wl_client_post_no_memory(client); |
| 5902 | return; |
| 5903 | } |
| 5904 | |
| 5905 | wl_resource_set_implementation(resource, &presentation_implementation, |
| 5906 | compositor, NULL); |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 5907 | wp_presentation_send_clock_id(resource, compositor->presentation_clock); |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 5908 | } |
| 5909 | |
| 5910 | static void |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 5911 | compositor_bind(struct wl_client *client, |
| 5912 | void *data, uint32_t version, uint32_t id) |
| 5913 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5914 | struct weston_compositor *compositor = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5915 | struct wl_resource *resource; |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 5916 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5917 | resource = wl_resource_create(client, &wl_compositor_interface, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 5918 | version, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 5919 | if (resource == NULL) { |
| 5920 | wl_client_post_no_memory(client); |
| 5921 | return; |
| 5922 | } |
| 5923 | |
| 5924 | wl_resource_set_implementation(resource, &compositor_interface, |
| 5925 | compositor, NULL); |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 5926 | } |
| 5927 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5928 | WL_EXPORT int |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 5929 | weston_environment_get_fd(const char *env) |
| 5930 | { |
Bryce Harrington | 25a2bdd | 2016-08-03 17:40:52 -0700 | [diff] [blame] | 5931 | char *e; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 5932 | int fd, flags; |
| 5933 | |
| 5934 | e = getenv(env); |
Bryce Harrington | 25a2bdd | 2016-08-03 17:40:52 -0700 | [diff] [blame] | 5935 | if (!e || !safe_strtoint(e, &fd)) |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 5936 | return -1; |
| 5937 | |
| 5938 | flags = fcntl(fd, F_GETFD); |
| 5939 | if (flags == -1) |
| 5940 | return -1; |
| 5941 | |
| 5942 | fcntl(fd, F_SETFD, flags | FD_CLOEXEC); |
| 5943 | unsetenv(env); |
| 5944 | |
| 5945 | return fd; |
| 5946 | } |
| 5947 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 5948 | static void |
Alexandros Frantzis | 47e79c8 | 2017-11-16 18:20:57 +0200 | [diff] [blame] | 5949 | timeline_key_binding_handler(struct weston_keyboard *keyboard, |
| 5950 | const struct timespec *time, uint32_t key, |
| 5951 | void *data) |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 5952 | { |
| 5953 | struct weston_compositor *compositor = data; |
| 5954 | |
| 5955 | if (weston_timeline_enabled_) |
| 5956 | weston_timeline_close(); |
| 5957 | else |
| 5958 | weston_timeline_open(compositor); |
| 5959 | } |
| 5960 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 5961 | /** Create the compositor. |
| 5962 | * |
| 5963 | * This functions creates and initializes a compositor instance. |
| 5964 | * |
| 5965 | * \param display The Wayland display to be used. |
| 5966 | * \param user_data A pointer to an object that can later be retrieved |
| 5967 | * using the \ref weston_compositor_get_user_data function. |
| 5968 | * \return The compositor instance on success or NULL on failure. |
| 5969 | */ |
| 5970 | WL_EXPORT struct weston_compositor * |
| 5971 | weston_compositor_create(struct wl_display *display, void *user_data) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 5972 | { |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 5973 | struct weston_compositor *ec; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 5974 | struct wl_event_loop *loop; |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 5975 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 5976 | ec = zalloc(sizeof *ec); |
| 5977 | if (!ec) |
| 5978 | return NULL; |
| 5979 | |
| 5980 | ec->wl_display = display; |
| 5981 | ec->user_data = user_data; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5982 | wl_signal_init(&ec->destroy_signal); |
Kristian Høgsberg | f03a04a | 2014-04-06 22:04:50 -0700 | [diff] [blame] | 5983 | wl_signal_init(&ec->create_surface_signal); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5984 | wl_signal_init(&ec->activate_signal); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 5985 | wl_signal_init(&ec->transform_signal); |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5986 | wl_signal_init(&ec->kill_signal); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5987 | wl_signal_init(&ec->idle_signal); |
| 5988 | wl_signal_init(&ec->wake_signal); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5989 | wl_signal_init(&ec->show_input_panel_signal); |
| 5990 | wl_signal_init(&ec->hide_input_panel_signal); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5991 | wl_signal_init(&ec->update_input_panel_signal); |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 5992 | wl_signal_init(&ec->seat_created_signal); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5993 | wl_signal_init(&ec->output_pending_signal); |
Richard Hughes | 59d5da7 | 2013-05-01 21:52:11 +0100 | [diff] [blame] | 5994 | wl_signal_init(&ec->output_created_signal); |
Ander Conselvan de Oliveira | f84327a | 2014-01-29 18:47:51 +0200 | [diff] [blame] | 5995 | wl_signal_init(&ec->output_destroyed_signal); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 5996 | wl_signal_init(&ec->output_moved_signal); |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 5997 | wl_signal_init(&ec->output_resized_signal); |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 5998 | wl_signal_init(&ec->heads_changed_signal); |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 5999 | wl_signal_init(&ec->session_signal); |
| 6000 | ec->session_active = 1; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 6001 | |
Casey Dahlin | 58ba137 | 2012-04-19 22:50:08 -0400 | [diff] [blame] | 6002 | ec->output_id_pool = 0; |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 6003 | ec->repaint_msec = DEFAULT_REPAINT_WINDOW; |
Casey Dahlin | 58ba137 | 2012-04-19 22:50:08 -0400 | [diff] [blame] | 6004 | |
Jonas Ådahl | 94e2e2d | 2014-10-18 18:42:19 +0200 | [diff] [blame] | 6005 | ec->activate_serial = 1; |
| 6006 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 6007 | if (!wl_global_create(ec->wl_display, &wl_compositor_interface, 4, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6008 | ec, compositor_bind)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 6009 | goto fail; |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 6010 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 6011 | if (!wl_global_create(ec->wl_display, &wl_subcompositor_interface, 1, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 6012 | ec, bind_subcompositor)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 6013 | goto fail; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 6014 | |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 6015 | if (!wl_global_create(ec->wl_display, &wp_viewporter_interface, 1, |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 6016 | ec, bind_viewporter)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 6017 | goto fail; |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 6018 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 6019 | if (!wl_global_create(ec->wl_display, &wp_presentation_interface, 1, |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 6020 | ec, bind_presentation)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 6021 | goto fail; |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 6022 | |
Jonas Ådahl | 30d61d8 | 2014-10-22 21:21:17 +0200 | [diff] [blame] | 6023 | if (weston_input_init(ec) != 0) |
| 6024 | goto fail; |
| 6025 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 6026 | wl_list_init(&ec->view_list); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 6027 | wl_list_init(&ec->plane_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 6028 | wl_list_init(&ec->layer_list); |
| 6029 | wl_list_init(&ec->seat_list); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6030 | wl_list_init(&ec->pending_output_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 6031 | wl_list_init(&ec->output_list); |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 6032 | wl_list_init(&ec->head_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 6033 | wl_list_init(&ec->key_binding_list); |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 6034 | wl_list_init(&ec->modifier_binding_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 6035 | wl_list_init(&ec->button_binding_list); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 6036 | wl_list_init(&ec->touch_binding_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 6037 | wl_list_init(&ec->axis_binding_list); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6038 | wl_list_init(&ec->debug_binding_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 6039 | |
Pekka Paalanen | 827b5d2 | 2016-06-29 11:54:26 +0200 | [diff] [blame] | 6040 | wl_list_init(&ec->plugin_api_list); |
| 6041 | |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 6042 | weston_plane_init(&ec->primary_plane, ec, 0, 0); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 6043 | weston_compositor_stack_plane(ec, &ec->primary_plane, NULL); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 6044 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 6045 | wl_data_device_manager_init(ec->wl_display); |
| 6046 | |
| 6047 | wl_display_init_shm(ec->wl_display); |
| 6048 | |
| 6049 | loop = wl_display_get_event_loop(ec->wl_display); |
| 6050 | ec->idle_source = wl_event_loop_add_timer(loop, idle_handler, ec); |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 6051 | ec->repaint_timer = |
| 6052 | wl_event_loop_add_timer(loop, output_repaint_timer_handler, |
| 6053 | ec); |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 6054 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 6055 | weston_layer_init(&ec->fade_layer, ec); |
| 6056 | weston_layer_init(&ec->cursor_layer, ec); |
| 6057 | |
| 6058 | weston_layer_set_position(&ec->fade_layer, WESTON_LAYER_POSITION_FADE); |
| 6059 | weston_layer_set_position(&ec->cursor_layer, |
| 6060 | WESTON_LAYER_POSITION_CURSOR); |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 6061 | |
| 6062 | weston_compositor_add_debug_binding(ec, KEY_T, |
| 6063 | timeline_key_binding_handler, ec); |
| 6064 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 6065 | return ec; |
| 6066 | |
| 6067 | fail: |
| 6068 | free(ec); |
| 6069 | return NULL; |
| 6070 | } |
| 6071 | |
Benjamin Franzke | b826302 | 2011-08-30 11:32:47 +0200 | [diff] [blame] | 6072 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 6073 | weston_compositor_shutdown(struct weston_compositor *ec) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 6074 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 6075 | struct weston_output *output, *next; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 6076 | |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 6077 | wl_event_source_remove(ec->idle_source); |
| 6078 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 6079 | /* Destroy all outputs associated with this compositor */ |
Tiago Vignatti | b303a1d | 2011-12-18 22:27:40 +0200 | [diff] [blame] | 6080 | wl_list_for_each_safe(output, next, &ec->output_list, link) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 6081 | output->destroy(output); |
Pekka Paalanen | 4738f3b | 2012-01-02 15:47:07 +0200 | [diff] [blame] | 6082 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 6083 | /* Destroy all pending outputs associated with this compositor */ |
| 6084 | wl_list_for_each_safe(output, next, &ec->pending_output_list, link) |
| 6085 | output->destroy(output); |
| 6086 | |
Ander Conselvan de Oliveira | 1853676 | 2013-12-20 21:07:00 +0200 | [diff] [blame] | 6087 | if (ec->renderer) |
| 6088 | ec->renderer->destroy(ec); |
| 6089 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6090 | weston_binding_list_destroy_all(&ec->key_binding_list); |
Ryo Munakata | 27135af | 2015-07-17 13:07:42 +0900 | [diff] [blame] | 6091 | weston_binding_list_destroy_all(&ec->modifier_binding_list); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6092 | weston_binding_list_destroy_all(&ec->button_binding_list); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 6093 | weston_binding_list_destroy_all(&ec->touch_binding_list); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 6094 | weston_binding_list_destroy_all(&ec->axis_binding_list); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 6095 | weston_binding_list_destroy_all(&ec->debug_binding_list); |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 6096 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 6097 | weston_plane_release(&ec->primary_plane); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 6098 | } |
| 6099 | |
Kristian Høgsberg | af4f2aa | 2013-02-15 20:53:20 -0500 | [diff] [blame] | 6100 | WL_EXPORT void |
Frederic Plourde | c336f06 | 2014-10-29 14:44:33 -0400 | [diff] [blame] | 6101 | weston_compositor_exit_with_code(struct weston_compositor *compositor, |
| 6102 | int exit_code) |
| 6103 | { |
Pekka Paalanen | f5ef88f | 2014-11-18 15:57:04 +0200 | [diff] [blame] | 6104 | if (compositor->exit_code == EXIT_SUCCESS) |
| 6105 | compositor->exit_code = exit_code; |
| 6106 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 6107 | weston_compositor_exit(compositor); |
Frederic Plourde | c336f06 | 2014-10-29 14:44:33 -0400 | [diff] [blame] | 6108 | } |
| 6109 | |
| 6110 | WL_EXPORT void |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 6111 | weston_compositor_set_default_pointer_grab(struct weston_compositor *ec, |
| 6112 | const struct weston_pointer_grab_interface *interface) |
| 6113 | { |
| 6114 | struct weston_seat *seat; |
| 6115 | |
| 6116 | ec->default_pointer_grab = interface; |
| 6117 | wl_list_for_each(seat, &ec->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 6118 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 6119 | |
| 6120 | if (pointer) |
| 6121 | weston_pointer_set_default_grab(pointer, interface); |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 6122 | } |
| 6123 | } |
| 6124 | |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 6125 | WL_EXPORT int |
| 6126 | weston_compositor_set_presentation_clock(struct weston_compositor *compositor, |
| 6127 | clockid_t clk_id) |
| 6128 | { |
| 6129 | struct timespec ts; |
| 6130 | |
| 6131 | if (clock_gettime(clk_id, &ts) < 0) |
| 6132 | return -1; |
| 6133 | |
| 6134 | compositor->presentation_clock = clk_id; |
| 6135 | |
| 6136 | return 0; |
| 6137 | } |
| 6138 | |
| 6139 | /* |
| 6140 | * For choosing the software clock, when the display hardware or API |
| 6141 | * does not expose a compatible presentation timestamp. |
| 6142 | */ |
| 6143 | WL_EXPORT int |
| 6144 | weston_compositor_set_presentation_clock_software( |
| 6145 | struct weston_compositor *compositor) |
| 6146 | { |
| 6147 | /* In order of preference */ |
| 6148 | static const clockid_t clocks[] = { |
| 6149 | CLOCK_MONOTONIC_RAW, /* no jumps, no crawling */ |
| 6150 | CLOCK_MONOTONIC_COARSE, /* no jumps, may crawl, fast & coarse */ |
| 6151 | CLOCK_MONOTONIC, /* no jumps, may crawl */ |
| 6152 | CLOCK_REALTIME_COARSE, /* may jump and crawl, fast & coarse */ |
| 6153 | CLOCK_REALTIME /* may jump and crawl */ |
| 6154 | }; |
| 6155 | unsigned i; |
| 6156 | |
| 6157 | for (i = 0; i < ARRAY_LENGTH(clocks); i++) |
| 6158 | if (weston_compositor_set_presentation_clock(compositor, |
| 6159 | clocks[i]) == 0) |
| 6160 | return 0; |
| 6161 | |
| 6162 | weston_log("Error: no suitable presentation clock available.\n"); |
| 6163 | |
| 6164 | return -1; |
| 6165 | } |
| 6166 | |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 6167 | /** Read the current time from the Presentation clock |
| 6168 | * |
| 6169 | * \param compositor |
| 6170 | * \param ts[out] The current time. |
| 6171 | * |
| 6172 | * \note Reading the current time in user space is always imprecise to some |
| 6173 | * degree. |
| 6174 | * |
| 6175 | * This function is never meant to fail. If reading the clock does fail, |
| 6176 | * an error message is logged and a zero time is returned. Callers are not |
| 6177 | * supposed to detect or react to failures. |
| 6178 | */ |
| 6179 | WL_EXPORT void |
| 6180 | weston_compositor_read_presentation_clock( |
| 6181 | const struct weston_compositor *compositor, |
| 6182 | struct timespec *ts) |
| 6183 | { |
| 6184 | static bool warned; |
| 6185 | int ret; |
| 6186 | |
| 6187 | ret = clock_gettime(compositor->presentation_clock, ts); |
| 6188 | if (ret < 0) { |
| 6189 | ts->tv_sec = 0; |
| 6190 | ts->tv_nsec = 0; |
| 6191 | |
| 6192 | if (!warned) |
| 6193 | weston_log("Error: failure to read " |
| 6194 | "the presentation clock %#x: '%m' (%d)\n", |
| 6195 | compositor->presentation_clock, errno); |
| 6196 | warned = true; |
| 6197 | } |
| 6198 | } |
| 6199 | |
Pekka Paalanen | 230f3b1 | 2014-09-29 14:18:40 -0400 | [diff] [blame] | 6200 | /** Import dmabuf buffer into current renderer |
| 6201 | * |
| 6202 | * \param compositor |
| 6203 | * \param buffer the dmabuf buffer to import |
| 6204 | * \return true on usable buffers, false otherwise |
| 6205 | * |
| 6206 | * This function tests that the linux_dmabuf_buffer is usable |
| 6207 | * for the current renderer. Returns false on unusable buffers. Usually |
| 6208 | * usability is tested by importing the dmabufs for composition. |
| 6209 | * |
| 6210 | * This hook is also used for detecting if the renderer supports |
| 6211 | * dmabufs at all. If the renderer hook is NULL, dmabufs are not |
| 6212 | * supported. |
| 6213 | * */ |
| 6214 | WL_EXPORT bool |
| 6215 | weston_compositor_import_dmabuf(struct weston_compositor *compositor, |
| 6216 | struct linux_dmabuf_buffer *buffer) |
| 6217 | { |
| 6218 | struct weston_renderer *renderer; |
| 6219 | |
| 6220 | renderer = compositor->renderer; |
| 6221 | |
| 6222 | if (renderer->import_dmabuf == NULL) |
| 6223 | return false; |
| 6224 | |
| 6225 | return renderer->import_dmabuf(compositor, buffer); |
| 6226 | } |
| 6227 | |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 6228 | WL_EXPORT void |
Kristian Høgsberg | af4f2aa | 2013-02-15 20:53:20 -0500 | [diff] [blame] | 6229 | weston_version(int *major, int *minor, int *micro) |
| 6230 | { |
| 6231 | *major = WESTON_VERSION_MAJOR; |
| 6232 | *minor = WESTON_VERSION_MINOR; |
| 6233 | *micro = WESTON_VERSION_MICRO; |
| 6234 | } |
| 6235 | |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 6236 | WL_EXPORT void * |
| 6237 | weston_load_module(const char *name, const char *entrypoint) |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6238 | { |
Derek Foreman | 3f86e50 | 2015-06-08 11:46:54 -0500 | [diff] [blame] | 6239 | const char *builddir = getenv("WESTON_BUILD_DIR"); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6240 | char path[PATH_MAX]; |
| 6241 | void *module, *init; |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 6242 | size_t len; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6243 | |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 6244 | if (name == NULL) |
| 6245 | return NULL; |
| 6246 | |
Derek Foreman | 3f86e50 | 2015-06-08 11:46:54 -0500 | [diff] [blame] | 6247 | if (name[0] != '/') { |
| 6248 | if (builddir) |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 6249 | len = snprintf(path, sizeof path, "%s/.libs/%s", |
| 6250 | builddir, name); |
Derek Foreman | 3f86e50 | 2015-06-08 11:46:54 -0500 | [diff] [blame] | 6251 | else |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 6252 | len = snprintf(path, sizeof path, "%s/%s", |
| 6253 | LIBWESTON_MODULEDIR, name); |
Derek Foreman | 3f86e50 | 2015-06-08 11:46:54 -0500 | [diff] [blame] | 6254 | } else { |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 6255 | len = snprintf(path, sizeof path, "%s", name); |
Derek Foreman | 3f86e50 | 2015-06-08 11:46:54 -0500 | [diff] [blame] | 6256 | } |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6257 | |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 6258 | /* snprintf returns the length of the string it would've written, |
| 6259 | * _excluding_ the NUL byte. So even being equal to the size of |
| 6260 | * our buffer is an error here. */ |
| 6261 | if (len >= sizeof path) |
| 6262 | return NULL; |
| 6263 | |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 6264 | module = dlopen(path, RTLD_NOW | RTLD_NOLOAD); |
| 6265 | if (module) { |
| 6266 | weston_log("Module '%s' already loaded\n", path); |
| 6267 | dlclose(module); |
| 6268 | return NULL; |
| 6269 | } |
| 6270 | |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 6271 | weston_log("Loading module '%s'\n", path); |
Kristian Høgsberg | 1acd9f8 | 2012-07-26 11:39:26 -0400 | [diff] [blame] | 6272 | module = dlopen(path, RTLD_NOW); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6273 | if (!module) { |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 6274 | weston_log("Failed to load module: %s\n", dlerror()); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6275 | return NULL; |
| 6276 | } |
| 6277 | |
| 6278 | init = dlsym(module, entrypoint); |
| 6279 | if (!init) { |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 6280 | weston_log("Failed to lookup init function: %s\n", dlerror()); |
Rob Bradford | c9e64ab | 2012-12-05 18:47:10 +0000 | [diff] [blame] | 6281 | dlclose(module); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 6282 | return NULL; |
| 6283 | } |
| 6284 | |
| 6285 | return init; |
| 6286 | } |
| 6287 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 6288 | |
| 6289 | /** Destroys the compositor. |
| 6290 | * |
| 6291 | * This function cleans up the compositor state and destroys it. |
| 6292 | * |
| 6293 | * \param compositor The compositor to be destroyed. |
| 6294 | */ |
| 6295 | WL_EXPORT void |
| 6296 | weston_compositor_destroy(struct weston_compositor *compositor) |
| 6297 | { |
| 6298 | /* prevent further rendering while shutting down */ |
| 6299 | compositor->state = WESTON_COMPOSITOR_OFFSCREEN; |
| 6300 | |
| 6301 | wl_signal_emit(&compositor->destroy_signal, compositor); |
| 6302 | |
| 6303 | weston_compositor_xkb_destroy(compositor); |
| 6304 | |
Giulio Camuffo | 2d24e64 | 2015-10-03 16:25:15 +0300 | [diff] [blame] | 6305 | if (compositor->backend) |
| 6306 | compositor->backend->destroy(compositor); |
Pekka Paalanen | 827b5d2 | 2016-06-29 11:54:26 +0200 | [diff] [blame] | 6307 | |
Pekka Paalanen | 1adcbac | 2017-08-14 16:05:35 +0300 | [diff] [blame] | 6308 | /* The backend is responsible for destroying the heads. */ |
| 6309 | assert(wl_list_empty(&compositor->head_list)); |
| 6310 | |
Pekka Paalanen | 827b5d2 | 2016-06-29 11:54:26 +0200 | [diff] [blame] | 6311 | weston_plugin_api_destroy_list(compositor); |
| 6312 | |
Pekka Paalanen | 37e6c9e | 2017-08-15 13:00:02 +0300 | [diff] [blame] | 6313 | if (compositor->heads_changed_source) |
| 6314 | wl_event_source_remove(compositor->heads_changed_source); |
| 6315 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 6316 | free(compositor); |
| 6317 | } |
| 6318 | |
| 6319 | /** Instruct the compositor to exit. |
| 6320 | * |
| 6321 | * This functions does not directly destroy the compositor object, it merely |
| 6322 | * command it to start the tear down process. It is not guaranteed that the |
| 6323 | * tear down will happen immediately. |
| 6324 | * |
| 6325 | * \param compositor The compositor to tear down. |
| 6326 | */ |
| 6327 | WL_EXPORT void |
| 6328 | weston_compositor_exit(struct weston_compositor *compositor) |
| 6329 | { |
| 6330 | compositor->exit(compositor); |
| 6331 | } |
| 6332 | |
| 6333 | /** Return the user data stored in the compositor. |
| 6334 | * |
| 6335 | * This function returns the user data pointer set with user_data parameter |
| 6336 | * to the \ref weston_compositor_create function. |
| 6337 | */ |
| 6338 | WL_EXPORT void * |
| 6339 | weston_compositor_get_user_data(struct weston_compositor *compositor) |
| 6340 | { |
| 6341 | return compositor->user_data; |
| 6342 | } |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 6343 | |
Pekka Paalanen | 50dbf38 | 2016-06-03 15:23:46 +0300 | [diff] [blame] | 6344 | static const char * const backend_map[] = { |
| 6345 | [WESTON_BACKEND_DRM] = "drm-backend.so", |
| 6346 | [WESTON_BACKEND_FBDEV] = "fbdev-backend.so", |
| 6347 | [WESTON_BACKEND_HEADLESS] = "headless-backend.so", |
| 6348 | [WESTON_BACKEND_RDP] = "rdp-backend.so", |
| 6349 | [WESTON_BACKEND_WAYLAND] = "wayland-backend.so", |
| 6350 | [WESTON_BACKEND_X11] = "x11-backend.so", |
| 6351 | }; |
| 6352 | |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 6353 | /** Load a backend into a weston_compositor |
| 6354 | * |
| 6355 | * A backend must be loaded to make a weston_compositor work. A backend |
| 6356 | * provides input and output capabilities, and determines the renderer to use. |
| 6357 | * |
| 6358 | * \param compositor A compositor that has not had a backend loaded yet. |
| 6359 | * \param backend Name of the backend file. |
| 6360 | * \param config_base A pointer to a backend-specific configuration |
| 6361 | * structure's 'base' member. |
| 6362 | * |
| 6363 | * \return 0 on success, or -1 on error. |
| 6364 | */ |
| 6365 | WL_EXPORT int |
| 6366 | weston_compositor_load_backend(struct weston_compositor *compositor, |
Pekka Paalanen | 50dbf38 | 2016-06-03 15:23:46 +0300 | [diff] [blame] | 6367 | enum weston_compositor_backend backend, |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 6368 | struct weston_backend_config *config_base) |
| 6369 | { |
| 6370 | int (*backend_init)(struct weston_compositor *c, |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 6371 | struct weston_backend_config *config_base); |
| 6372 | |
Pekka Paalanen | d7e3511 | 2017-08-29 17:04:12 +0300 | [diff] [blame] | 6373 | if (compositor->backend) { |
| 6374 | weston_log("Error: attempt to load a backend when one is already loaded\n"); |
| 6375 | return -1; |
| 6376 | } |
| 6377 | |
Quentin Glidic | 887c018 | 2016-07-10 11:00:53 +0200 | [diff] [blame] | 6378 | if (backend >= ARRAY_LENGTH(backend_map)) |
Pekka Paalanen | 50dbf38 | 2016-06-03 15:23:46 +0300 | [diff] [blame] | 6379 | return -1; |
| 6380 | |
Quentin Glidic | 23e1d6f | 2016-12-02 14:08:44 +0100 | [diff] [blame] | 6381 | backend_init = weston_load_module(backend_map[backend], "weston_backend_init"); |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 6382 | if (!backend_init) |
| 6383 | return -1; |
| 6384 | |
Pekka Paalanen | d7e3511 | 2017-08-29 17:04:12 +0300 | [diff] [blame] | 6385 | if (backend_init(compositor, config_base) < 0) { |
| 6386 | compositor->backend = NULL; |
| 6387 | return -1; |
| 6388 | } |
| 6389 | |
| 6390 | return 0; |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 6391 | } |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 6392 | |
| 6393 | WL_EXPORT int |
| 6394 | weston_compositor_load_xwayland(struct weston_compositor *compositor) |
| 6395 | { |
Quentin Glidic | 3d7ca3b | 2016-12-02 14:20:35 +0100 | [diff] [blame] | 6396 | int (*module_init)(struct weston_compositor *ec); |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 6397 | |
Quentin Glidic | 3d7ca3b | 2016-12-02 14:20:35 +0100 | [diff] [blame] | 6398 | module_init = weston_load_module("xwayland.so", "weston_module_init"); |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 6399 | if (!module_init) |
| 6400 | return -1; |
Quentin Glidic | 3d7ca3b | 2016-12-02 14:20:35 +0100 | [diff] [blame] | 6401 | if (module_init(compositor) < 0) |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 6402 | return -1; |
| 6403 | return 0; |
| 6404 | } |