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 | |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 79 | static void weston_mode_switch_finish(struct weston_output *output, |
| 80 | int mode_changed, |
| 81 | int scale_changed) |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 82 | { |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 83 | struct weston_seat *seat; |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 84 | struct wl_resource *resource; |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 85 | pixman_region32_t old_output_region; |
Derek Foreman | 41bdc27 | 2014-11-05 13:26:57 -0600 | [diff] [blame] | 86 | int version; |
Alexander Larsson | 355748e | 2013-05-28 16:23:38 +0200 | [diff] [blame] | 87 | |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 88 | pixman_region32_init(&old_output_region); |
| 89 | pixman_region32_copy(&old_output_region, &output->region); |
| 90 | |
Ander Conselvan de Oliveira | 5c38ef4 | 2012-12-14 13:37:25 -0200 | [diff] [blame] | 91 | /* Update output region and transformation matrix */ |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 92 | 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] | 93 | |
| 94 | pixman_region32_init(&output->previous_damage); |
| 95 | pixman_region32_init_rect(&output->region, output->x, output->y, |
| 96 | output->width, output->height); |
| 97 | |
| 98 | weston_output_update_matrix(output); |
| 99 | |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 100 | /* If a pointer falls outside the outputs new geometry, move it to its |
| 101 | * lower-right corner */ |
| 102 | wl_list_for_each(seat, &output->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 103 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
Ander Conselvan de Oliveira | 2bbb2b8 | 2012-12-14 13:37:26 -0200 | [diff] [blame] | 104 | int32_t x, y; |
| 105 | |
| 106 | if (!pointer) |
| 107 | continue; |
| 108 | |
| 109 | x = wl_fixed_to_int(pointer->x); |
| 110 | y = wl_fixed_to_int(pointer->y); |
| 111 | |
| 112 | if (!pixman_region32_contains_point(&old_output_region, |
| 113 | x, y, NULL) || |
| 114 | pixman_region32_contains_point(&output->region, |
| 115 | x, y, NULL)) |
| 116 | continue; |
| 117 | |
| 118 | if (x >= output->x + output->width) |
| 119 | x = output->x + output->width - 1; |
| 120 | if (y >= output->y + output->height) |
| 121 | y = output->y + output->height - 1; |
| 122 | |
| 123 | pointer->x = wl_fixed_from_int(x); |
| 124 | pointer->y = wl_fixed_from_int(y); |
| 125 | } |
| 126 | |
| 127 | pixman_region32_fini(&old_output_region); |
| 128 | |
Derek Foreman | dd4cd33 | 2014-11-10 10:29:59 -0600 | [diff] [blame] | 129 | if (!mode_changed && !scale_changed) |
| 130 | return; |
| 131 | |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 132 | /* notify clients of the changes */ |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 133 | wl_resource_for_each(resource, &output->resource_list) { |
| 134 | if (mode_changed) { |
| 135 | wl_output_send_mode(resource, |
| 136 | output->current_mode->flags, |
| 137 | output->current_mode->width, |
| 138 | output->current_mode->height, |
| 139 | output->current_mode->refresh); |
| 140 | } |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 141 | |
Derek Foreman | 41bdc27 | 2014-11-05 13:26:57 -0600 | [diff] [blame] | 142 | version = wl_resource_get_version(resource); |
| 143 | if (version >= WL_OUTPUT_SCALE_SINCE_VERSION && scale_changed) |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 144 | wl_output_send_scale(resource, output->current_scale); |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 145 | |
Derek Foreman | 41bdc27 | 2014-11-05 13:26:57 -0600 | [diff] [blame] | 146 | if (version >= WL_OUTPUT_DONE_SINCE_VERSION) |
| 147 | wl_output_send_done(resource); |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 151 | |
| 152 | static void |
| 153 | weston_compositor_reflow_outputs(struct weston_compositor *compositor, |
| 154 | struct weston_output *resized_output, int delta_width); |
| 155 | |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 156 | WL_EXPORT int |
| 157 | weston_output_mode_set_native(struct weston_output *output, |
| 158 | struct weston_mode *mode, |
| 159 | int32_t scale) |
| 160 | { |
| 161 | int ret; |
| 162 | int mode_changed = 0, scale_changed = 0; |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 163 | int32_t old_width; |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 164 | |
| 165 | if (!output->switch_mode) |
| 166 | return -1; |
| 167 | |
| 168 | if (!output->original_mode) { |
| 169 | mode_changed = 1; |
| 170 | ret = output->switch_mode(output, mode); |
| 171 | if (ret < 0) |
| 172 | return ret; |
| 173 | if (output->current_scale != scale) { |
| 174 | scale_changed = 1; |
| 175 | output->current_scale = scale; |
Hardening | 57388e4 | 2013-09-18 23:56:36 +0200 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 179 | old_width = output->width; |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 180 | output->native_mode = mode; |
| 181 | output->native_scale = scale; |
| 182 | |
| 183 | weston_mode_switch_finish(output, mode_changed, scale_changed); |
| 184 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 185 | if (mode_changed || scale_changed) { |
| 186 | weston_compositor_reflow_outputs(output->compositor, output, output->width - old_width); |
| 187 | |
| 188 | wl_signal_emit(&output->compositor->output_resized_signal, output); |
| 189 | } |
Derek Foreman | 6ae7bc9 | 2014-11-04 10:47:33 -0600 | [diff] [blame] | 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | WL_EXPORT int |
| 194 | weston_output_mode_switch_to_native(struct weston_output *output) |
| 195 | { |
| 196 | int ret; |
| 197 | int mode_changed = 0, scale_changed = 0; |
| 198 | |
| 199 | if (!output->switch_mode) |
| 200 | return -1; |
| 201 | |
| 202 | if (!output->original_mode) { |
| 203 | weston_log("already in the native mode\n"); |
| 204 | return -1; |
| 205 | } |
| 206 | /* the non fullscreen clients haven't seen a mode set since we |
| 207 | * switched into a temporary, so we need to notify them if the |
| 208 | * mode at that time is different from the native mode now. |
| 209 | */ |
| 210 | mode_changed = (output->original_mode != output->native_mode); |
| 211 | scale_changed = (output->original_scale != output->native_scale); |
| 212 | |
| 213 | ret = output->switch_mode(output, output->native_mode); |
| 214 | if (ret < 0) |
| 215 | return ret; |
| 216 | |
| 217 | output->current_scale = output->native_scale; |
| 218 | |
| 219 | output->original_mode = NULL; |
| 220 | output->original_scale = 0; |
| 221 | |
| 222 | weston_mode_switch_finish(output, mode_changed, scale_changed); |
| 223 | |
| 224 | return 0; |
| 225 | } |
| 226 | |
| 227 | WL_EXPORT int |
| 228 | weston_output_mode_switch_to_temporary(struct weston_output *output, |
| 229 | struct weston_mode *mode, |
| 230 | int32_t scale) |
| 231 | { |
| 232 | int ret; |
| 233 | |
| 234 | if (!output->switch_mode) |
| 235 | return -1; |
| 236 | |
| 237 | /* original_mode is the last mode non full screen clients have seen, |
| 238 | * so we shouldn't change it if we already have one set. |
| 239 | */ |
| 240 | if (!output->original_mode) { |
| 241 | output->original_mode = output->native_mode; |
| 242 | output->original_scale = output->native_scale; |
| 243 | } |
| 244 | ret = output->switch_mode(output, mode); |
| 245 | if (ret < 0) |
| 246 | return ret; |
| 247 | |
| 248 | output->current_scale = scale; |
| 249 | |
| 250 | weston_mode_switch_finish(output, 0, 0); |
| 251 | |
| 252 | return 0; |
Alex Wu | 2dda604 | 2012-04-17 17:20:47 +0800 | [diff] [blame] | 253 | } |
| 254 | |
Benjamin Franzke | 0628626 | 2011-05-06 19:12:33 +0200 | [diff] [blame] | 255 | static void |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 256 | region_init_infinite(pixman_region32_t *region) |
| 257 | { |
| 258 | pixman_region32_init_rect(region, INT32_MIN, INT32_MIN, |
| 259 | UINT32_MAX, UINT32_MAX); |
| 260 | } |
| 261 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 262 | static struct weston_subsurface * |
| 263 | weston_surface_to_subsurface(struct weston_surface *surface); |
| 264 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 265 | WL_EXPORT struct weston_view * |
| 266 | weston_view_create(struct weston_surface *surface) |
| 267 | { |
| 268 | struct weston_view *view; |
| 269 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 270 | view = zalloc(sizeof *view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 271 | if (view == NULL) |
| 272 | return NULL; |
| 273 | |
| 274 | view->surface = surface; |
Daniel Stone | fb4869d | 2016-12-09 16:27:54 +0000 | [diff] [blame] | 275 | view->plane = &surface->compositor->primary_plane; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 276 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 277 | /* Assign to surface */ |
| 278 | wl_list_insert(&surface->views, &view->surface_link); |
| 279 | |
| 280 | wl_signal_init(&view->destroy_signal); |
| 281 | wl_list_init(&view->link); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 282 | wl_list_init(&view->layer_link.link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 283 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 284 | pixman_region32_init(&view->clip); |
| 285 | |
| 286 | view->alpha = 1.0; |
| 287 | pixman_region32_init(&view->transform.opaque); |
| 288 | |
| 289 | wl_list_init(&view->geometry.transformation_list); |
| 290 | wl_list_insert(&view->geometry.transformation_list, |
| 291 | &view->transform.position.link); |
| 292 | weston_matrix_init(&view->transform.position.matrix); |
| 293 | wl_list_init(&view->geometry.child_list); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 294 | pixman_region32_init(&view->geometry.scissor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 295 | pixman_region32_init(&view->transform.boundingbox); |
| 296 | view->transform.dirty = 1; |
| 297 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 298 | return view; |
| 299 | } |
| 300 | |
Jason Ekstrand | 108865d | 2014-06-26 10:04:49 -0700 | [diff] [blame] | 301 | struct weston_frame_callback { |
| 302 | struct wl_resource *resource; |
| 303 | struct wl_list link; |
| 304 | }; |
| 305 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 306 | struct weston_presentation_feedback { |
| 307 | struct wl_resource *resource; |
| 308 | |
| 309 | /* XXX: could use just wl_resource_get_link() instead */ |
| 310 | struct wl_list link; |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 311 | |
| 312 | /* The per-surface feedback flags */ |
| 313 | uint32_t psf_flags; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 314 | }; |
| 315 | |
| 316 | static void |
| 317 | weston_presentation_feedback_discard( |
| 318 | struct weston_presentation_feedback *feedback) |
| 319 | { |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 320 | wp_presentation_feedback_send_discarded(feedback->resource); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 321 | wl_resource_destroy(feedback->resource); |
| 322 | } |
| 323 | |
| 324 | static void |
| 325 | weston_presentation_feedback_discard_list(struct wl_list *list) |
| 326 | { |
| 327 | struct weston_presentation_feedback *feedback, *tmp; |
| 328 | |
| 329 | wl_list_for_each_safe(feedback, tmp, list, link) |
| 330 | weston_presentation_feedback_discard(feedback); |
| 331 | } |
| 332 | |
| 333 | static void |
| 334 | weston_presentation_feedback_present( |
| 335 | struct weston_presentation_feedback *feedback, |
| 336 | struct weston_output *output, |
| 337 | uint32_t refresh_nsec, |
| 338 | const struct timespec *ts, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 339 | uint64_t seq, |
| 340 | uint32_t flags) |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 341 | { |
| 342 | struct wl_client *client = wl_resource_get_client(feedback->resource); |
| 343 | struct wl_resource *o; |
| 344 | uint64_t secs; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 345 | |
| 346 | wl_resource_for_each(o, &output->resource_list) { |
| 347 | if (wl_resource_get_client(o) != client) |
| 348 | continue; |
| 349 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 350 | wp_presentation_feedback_send_sync_output(feedback->resource, o); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | secs = ts->tv_sec; |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 354 | wp_presentation_feedback_send_presented(feedback->resource, |
| 355 | secs >> 32, secs & 0xffffffff, |
| 356 | ts->tv_nsec, |
| 357 | refresh_nsec, |
| 358 | seq >> 32, seq & 0xffffffff, |
| 359 | flags | feedback->psf_flags); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 360 | wl_resource_destroy(feedback->resource); |
| 361 | } |
| 362 | |
| 363 | static void |
| 364 | weston_presentation_feedback_present_list(struct wl_list *list, |
| 365 | struct weston_output *output, |
| 366 | uint32_t refresh_nsec, |
| 367 | const struct timespec *ts, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 368 | uint64_t seq, |
| 369 | uint32_t flags) |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 370 | { |
| 371 | struct weston_presentation_feedback *feedback, *tmp; |
| 372 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 373 | assert(!(flags & WP_PRESENTATION_FEEDBACK_INVALID) || |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 374 | wl_list_empty(list)); |
| 375 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 376 | wl_list_for_each_safe(feedback, tmp, list, link) |
| 377 | weston_presentation_feedback_present(feedback, output, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 378 | refresh_nsec, ts, seq, |
| 379 | flags); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 380 | } |
| 381 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 382 | static void |
| 383 | surface_state_handle_buffer_destroy(struct wl_listener *listener, void *data) |
| 384 | { |
| 385 | struct weston_surface_state *state = |
| 386 | container_of(listener, struct weston_surface_state, |
| 387 | buffer_destroy_listener); |
| 388 | |
| 389 | state->buffer = NULL; |
| 390 | } |
| 391 | |
| 392 | static void |
| 393 | weston_surface_state_init(struct weston_surface_state *state) |
| 394 | { |
| 395 | state->newly_attached = 0; |
| 396 | state->buffer = NULL; |
| 397 | state->buffer_destroy_listener.notify = |
| 398 | surface_state_handle_buffer_destroy; |
| 399 | state->sx = 0; |
| 400 | state->sy = 0; |
| 401 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 402 | pixman_region32_init(&state->damage_surface); |
| 403 | pixman_region32_init(&state->damage_buffer); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 404 | pixman_region32_init(&state->opaque); |
| 405 | region_init_infinite(&state->input); |
| 406 | |
| 407 | wl_list_init(&state->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 408 | wl_list_init(&state->feedback_list); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 409 | |
| 410 | state->buffer_viewport.buffer.transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 411 | state->buffer_viewport.buffer.scale = 1; |
| 412 | state->buffer_viewport.buffer.src_width = wl_fixed_from_int(-1); |
| 413 | state->buffer_viewport.surface.width = -1; |
| 414 | state->buffer_viewport.changed = 0; |
| 415 | } |
| 416 | |
| 417 | static void |
| 418 | weston_surface_state_fini(struct weston_surface_state *state) |
| 419 | { |
| 420 | struct weston_frame_callback *cb, *next; |
| 421 | |
| 422 | wl_list_for_each_safe(cb, next, |
| 423 | &state->frame_callback_list, link) |
| 424 | wl_resource_destroy(cb->resource); |
| 425 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 426 | weston_presentation_feedback_discard_list(&state->feedback_list); |
| 427 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 428 | pixman_region32_fini(&state->input); |
| 429 | pixman_region32_fini(&state->opaque); |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 430 | pixman_region32_fini(&state->damage_surface); |
| 431 | pixman_region32_fini(&state->damage_buffer); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 432 | |
| 433 | if (state->buffer) |
| 434 | wl_list_remove(&state->buffer_destroy_listener.link); |
| 435 | state->buffer = NULL; |
| 436 | } |
| 437 | |
| 438 | static void |
| 439 | weston_surface_state_set_buffer(struct weston_surface_state *state, |
| 440 | struct weston_buffer *buffer) |
| 441 | { |
| 442 | if (state->buffer == buffer) |
| 443 | return; |
| 444 | |
| 445 | if (state->buffer) |
| 446 | wl_list_remove(&state->buffer_destroy_listener.link); |
| 447 | state->buffer = buffer; |
| 448 | if (state->buffer) |
| 449 | wl_signal_add(&state->buffer->destroy_signal, |
| 450 | &state->buffer_destroy_listener); |
| 451 | } |
| 452 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 453 | WL_EXPORT struct weston_surface * |
Kristian Høgsberg | 18c9300 | 2012-01-27 11:58:31 -0500 | [diff] [blame] | 454 | weston_surface_create(struct weston_compositor *compositor) |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 455 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 456 | struct weston_surface *surface; |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 457 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 458 | surface = zalloc(sizeof *surface); |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 459 | if (surface == NULL) |
| 460 | return NULL; |
| 461 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 462 | wl_signal_init(&surface->destroy_signal); |
Jonas Ådahl | 5d9ca27 | 2016-07-22 17:48:03 +0800 | [diff] [blame] | 463 | wl_signal_init(&surface->commit_signal); |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 464 | |
Kristian Høgsberg | 1a208d5 | 2009-02-10 14:20:26 -0500 | [diff] [blame] | 465 | surface->compositor = compositor; |
Giulio Camuffo | 13b85bd | 2013-08-13 23:10:14 +0200 | [diff] [blame] | 466 | surface->ref_count = 1; |
Kristian Høgsberg | 27803c6 | 2010-06-06 22:23:21 -0400 | [diff] [blame] | 467 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 468 | surface->buffer_viewport.buffer.transform = WL_OUTPUT_TRANSFORM_NORMAL; |
| 469 | surface->buffer_viewport.buffer.scale = 1; |
Pekka Paalanen | f0cad48 | 2014-03-14 14:38:16 +0200 | [diff] [blame] | 470 | surface->buffer_viewport.buffer.src_width = wl_fixed_from_int(-1); |
| 471 | surface->buffer_viewport.surface.width = -1; |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 472 | |
| 473 | weston_surface_state_init(&surface->pending); |
| 474 | |
Kristian Høgsberg | 20300ba | 2011-06-23 20:29:12 -0400 | [diff] [blame] | 475 | pixman_region32_init(&surface->damage); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 476 | pixman_region32_init(&surface->opaque); |
Pekka Paalanen | 8ec4ab6 | 2012-10-10 12:49:32 +0300 | [diff] [blame] | 477 | region_init_infinite(&surface->input); |
Kristian Høgsberg | 20300ba | 2011-06-23 20:29:12 -0400 | [diff] [blame] | 478 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 479 | wl_list_init(&surface->views); |
| 480 | |
| 481 | wl_list_init(&surface->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 482 | wl_list_init(&surface->feedback_list); |
Kristian Høgsberg | 1e4b86a | 2008-11-23 23:41:08 -0500 | [diff] [blame] | 483 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 484 | wl_list_init(&surface->subsurface_list); |
| 485 | wl_list_init(&surface->subsurface_list_pending); |
| 486 | |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 487 | weston_matrix_init(&surface->buffer_to_surface_matrix); |
| 488 | weston_matrix_init(&surface->surface_to_buffer_matrix); |
| 489 | |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 490 | wl_list_init(&surface->pointer_constraints); |
| 491 | |
Kristian Høgsberg | 77fb167 | 2010-08-16 10:38:29 -0400 | [diff] [blame] | 492 | return surface; |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 493 | } |
| 494 | |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 495 | WL_EXPORT void |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 496 | weston_surface_set_color(struct weston_surface *surface, |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 497 | float red, float green, float blue, float alpha) |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 498 | { |
John Kåre Alsaker | 878f449 | 2012-11-13 19:10:23 +0100 | [diff] [blame] | 499 | surface->compositor->renderer->surface_set_color(surface, red, green, blue, alpha); |
Kristian Høgsberg | bbeefb0 | 2012-01-26 10:00:23 -0500 | [diff] [blame] | 500 | } |
| 501 | |
Kristian Høgsberg | e4c1a5f | 2012-06-18 13:17:32 -0400 | [diff] [blame] | 502 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 503 | weston_view_to_global_float(struct weston_view *view, |
| 504 | float sx, float sy, float *x, float *y) |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 505 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 506 | if (view->transform.enabled) { |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 507 | struct weston_vector v = { { sx, sy, 0.0f, 1.0f } }; |
| 508 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 509 | weston_matrix_transform(&view->transform.matrix, &v); |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 510 | |
| 511 | if (fabsf(v.f[3]) < 1e-6) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 512 | weston_log("warning: numerical instability in " |
Scott Moreau | 088c62e | 2013-02-11 04:45:38 -0700 | [diff] [blame] | 513 | "%s(), divisor = %g\n", __func__, |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 514 | v.f[3]); |
| 515 | *x = 0; |
| 516 | *y = 0; |
| 517 | return; |
| 518 | } |
| 519 | |
| 520 | *x = v.f[0] / v.f[3]; |
| 521 | *y = v.f[1] / v.f[3]; |
| 522 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 523 | *x = sx + view->geometry.x; |
| 524 | *y = sy + view->geometry.y; |
Pekka Paalanen | ece8a01 | 2012-02-08 15:23:15 +0200 | [diff] [blame] | 525 | } |
| 526 | } |
| 527 | |
Kristian Høgsberg | d8bf90c | 2012-02-23 23:03:14 -0500 | [diff] [blame] | 528 | WL_EXPORT void |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 529 | weston_transformed_coord(int width, int height, |
| 530 | enum wl_output_transform transform, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 531 | int32_t scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 532 | float sx, float sy, float *bx, float *by) |
| 533 | { |
| 534 | switch (transform) { |
| 535 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 536 | default: |
| 537 | *bx = sx; |
| 538 | *by = sy; |
| 539 | break; |
| 540 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 541 | *bx = width - sx; |
| 542 | *by = sy; |
| 543 | break; |
| 544 | case WL_OUTPUT_TRANSFORM_90: |
| 545 | *bx = height - sy; |
| 546 | *by = sx; |
| 547 | break; |
| 548 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 549 | *bx = height - sy; |
| 550 | *by = width - sx; |
| 551 | break; |
| 552 | case WL_OUTPUT_TRANSFORM_180: |
| 553 | *bx = width - sx; |
| 554 | *by = height - sy; |
| 555 | break; |
| 556 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 557 | *bx = sx; |
| 558 | *by = height - sy; |
| 559 | break; |
| 560 | case WL_OUTPUT_TRANSFORM_270: |
| 561 | *bx = sy; |
| 562 | *by = width - sx; |
| 563 | break; |
| 564 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 565 | *bx = sy; |
| 566 | *by = sx; |
| 567 | break; |
| 568 | } |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 569 | |
| 570 | *bx *= scale; |
| 571 | *by *= scale; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 572 | } |
| 573 | |
| 574 | WL_EXPORT pixman_box32_t |
| 575 | weston_transformed_rect(int width, int height, |
| 576 | enum wl_output_transform transform, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 577 | int32_t scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 578 | pixman_box32_t rect) |
| 579 | { |
| 580 | float x1, x2, y1, y2; |
| 581 | |
| 582 | pixman_box32_t ret; |
| 583 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 584 | weston_transformed_coord(width, height, transform, scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 585 | rect.x1, rect.y1, &x1, &y1); |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 586 | weston_transformed_coord(width, height, transform, scale, |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 587 | rect.x2, rect.y2, &x2, &y2); |
| 588 | |
| 589 | if (x1 <= x2) { |
| 590 | ret.x1 = x1; |
| 591 | ret.x2 = x2; |
| 592 | } else { |
| 593 | ret.x1 = x2; |
| 594 | ret.x2 = x1; |
| 595 | } |
| 596 | |
| 597 | if (y1 <= y2) { |
| 598 | ret.y1 = y1; |
| 599 | ret.y2 = y2; |
| 600 | } else { |
| 601 | ret.y1 = y2; |
| 602 | ret.y2 = y1; |
| 603 | } |
| 604 | |
| 605 | return ret; |
| 606 | } |
| 607 | |
Derek Foreman | bc9a61c | 2015-11-18 16:32:30 -0600 | [diff] [blame] | 608 | /** Transform a region by a matrix, restricted to axis-aligned transformations |
| 609 | * |
| 610 | * Warning: This function does not work for projective, affine, or matrices |
| 611 | * that encode arbitrary rotations. Only 90-degree step rotations are |
| 612 | * supported. |
| 613 | */ |
| 614 | WL_EXPORT void |
| 615 | weston_matrix_transform_region(pixman_region32_t *dest, |
| 616 | struct weston_matrix *matrix, |
| 617 | pixman_region32_t *src) |
| 618 | { |
| 619 | pixman_box32_t *src_rects, *dest_rects; |
| 620 | int nrects, i; |
| 621 | |
| 622 | src_rects = pixman_region32_rectangles(src, &nrects); |
| 623 | dest_rects = malloc(nrects * sizeof(*dest_rects)); |
| 624 | if (!dest_rects) |
| 625 | return; |
| 626 | |
| 627 | for (i = 0; i < nrects; i++) { |
| 628 | struct weston_vector vec1 = {{ |
| 629 | src_rects[i].x1, src_rects[i].y1, 0, 1 |
| 630 | }}; |
| 631 | weston_matrix_transform(matrix, &vec1); |
| 632 | vec1.f[0] /= vec1.f[3]; |
| 633 | vec1.f[1] /= vec1.f[3]; |
| 634 | |
| 635 | struct weston_vector vec2 = {{ |
| 636 | src_rects[i].x2, src_rects[i].y2, 0, 1 |
| 637 | }}; |
| 638 | weston_matrix_transform(matrix, &vec2); |
| 639 | vec2.f[0] /= vec2.f[3]; |
| 640 | vec2.f[1] /= vec2.f[3]; |
| 641 | |
| 642 | if (vec1.f[0] < vec2.f[0]) { |
| 643 | dest_rects[i].x1 = floor(vec1.f[0]); |
| 644 | dest_rects[i].x2 = ceil(vec2.f[0]); |
| 645 | } else { |
| 646 | dest_rects[i].x1 = floor(vec2.f[0]); |
| 647 | dest_rects[i].x2 = ceil(vec1.f[0]); |
| 648 | } |
| 649 | |
Derek Foreman | bc9a61c | 2015-11-18 16:32:30 -0600 | [diff] [blame] | 650 | if (vec1.f[1] < vec2.f[1]) { |
| 651 | dest_rects[i].y1 = floor(vec1.f[1]); |
| 652 | dest_rects[i].y2 = ceil(vec2.f[1]); |
| 653 | } else { |
| 654 | dest_rects[i].y1 = floor(vec2.f[1]); |
| 655 | dest_rects[i].y2 = ceil(vec1.f[1]); |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | pixman_region32_clear(dest); |
| 660 | pixman_region32_init_rects(dest, dest_rects, nrects); |
| 661 | free(dest_rects); |
| 662 | } |
| 663 | |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 664 | WL_EXPORT void |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 665 | weston_transformed_region(int width, int height, |
| 666 | enum wl_output_transform transform, |
| 667 | int32_t scale, |
| 668 | pixman_region32_t *src, pixman_region32_t *dest) |
| 669 | { |
| 670 | pixman_box32_t *src_rects, *dest_rects; |
| 671 | int nrects, i; |
| 672 | |
| 673 | if (transform == WL_OUTPUT_TRANSFORM_NORMAL && scale == 1) { |
| 674 | if (src != dest) |
| 675 | pixman_region32_copy(dest, src); |
| 676 | return; |
| 677 | } |
| 678 | |
| 679 | src_rects = pixman_region32_rectangles(src, &nrects); |
| 680 | dest_rects = malloc(nrects * sizeof(*dest_rects)); |
| 681 | if (!dest_rects) |
| 682 | return; |
| 683 | |
| 684 | if (transform == WL_OUTPUT_TRANSFORM_NORMAL) { |
| 685 | memcpy(dest_rects, src_rects, nrects * sizeof(*dest_rects)); |
| 686 | } else { |
| 687 | for (i = 0; i < nrects; i++) { |
| 688 | switch (transform) { |
| 689 | default: |
| 690 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 691 | dest_rects[i].x1 = src_rects[i].x1; |
| 692 | dest_rects[i].y1 = src_rects[i].y1; |
| 693 | dest_rects[i].x2 = src_rects[i].x2; |
| 694 | dest_rects[i].y2 = src_rects[i].y2; |
| 695 | break; |
| 696 | case WL_OUTPUT_TRANSFORM_90: |
| 697 | dest_rects[i].x1 = height - src_rects[i].y2; |
| 698 | dest_rects[i].y1 = src_rects[i].x1; |
| 699 | dest_rects[i].x2 = height - src_rects[i].y1; |
| 700 | dest_rects[i].y2 = src_rects[i].x2; |
| 701 | break; |
| 702 | case WL_OUTPUT_TRANSFORM_180: |
| 703 | dest_rects[i].x1 = width - src_rects[i].x2; |
| 704 | dest_rects[i].y1 = height - src_rects[i].y2; |
| 705 | dest_rects[i].x2 = width - src_rects[i].x1; |
| 706 | dest_rects[i].y2 = height - src_rects[i].y1; |
| 707 | break; |
| 708 | case WL_OUTPUT_TRANSFORM_270: |
| 709 | dest_rects[i].x1 = src_rects[i].y1; |
| 710 | dest_rects[i].y1 = width - src_rects[i].x2; |
| 711 | dest_rects[i].x2 = src_rects[i].y2; |
| 712 | dest_rects[i].y2 = width - src_rects[i].x1; |
| 713 | break; |
| 714 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 715 | dest_rects[i].x1 = width - src_rects[i].x2; |
| 716 | dest_rects[i].y1 = src_rects[i].y1; |
| 717 | dest_rects[i].x2 = width - src_rects[i].x1; |
| 718 | dest_rects[i].y2 = src_rects[i].y2; |
| 719 | break; |
| 720 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 721 | dest_rects[i].x1 = height - src_rects[i].y2; |
| 722 | dest_rects[i].y1 = width - src_rects[i].x2; |
| 723 | dest_rects[i].x2 = height - src_rects[i].y1; |
| 724 | dest_rects[i].y2 = width - src_rects[i].x1; |
| 725 | break; |
| 726 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 727 | dest_rects[i].x1 = src_rects[i].x1; |
| 728 | dest_rects[i].y1 = height - src_rects[i].y2; |
| 729 | dest_rects[i].x2 = src_rects[i].x2; |
| 730 | dest_rects[i].y2 = height - src_rects[i].y1; |
| 731 | break; |
| 732 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 733 | dest_rects[i].x1 = src_rects[i].y1; |
| 734 | dest_rects[i].y1 = src_rects[i].x1; |
| 735 | dest_rects[i].x2 = src_rects[i].y2; |
| 736 | dest_rects[i].y2 = src_rects[i].x2; |
| 737 | break; |
| 738 | } |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | if (scale != 1) { |
| 743 | for (i = 0; i < nrects; i++) { |
| 744 | dest_rects[i].x1 *= scale; |
| 745 | dest_rects[i].x2 *= scale; |
| 746 | dest_rects[i].y1 *= scale; |
| 747 | dest_rects[i].y2 *= scale; |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | pixman_region32_clear(dest); |
| 752 | pixman_region32_init_rects(dest, dest_rects, nrects); |
| 753 | free(dest_rects); |
| 754 | } |
| 755 | |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 756 | static void |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 757 | viewport_surface_to_buffer(struct weston_surface *surface, |
| 758 | float sx, float sy, float *bx, float *by) |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 759 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 760 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 761 | double src_width, src_height; |
| 762 | double src_x, src_y; |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 763 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 764 | if (vp->buffer.src_width == wl_fixed_from_int(-1)) { |
| 765 | if (vp->surface.width == -1) { |
| 766 | *bx = sx; |
| 767 | *by = sy; |
| 768 | return; |
| 769 | } |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 770 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 771 | src_x = 0.0; |
| 772 | src_y = 0.0; |
| 773 | src_width = surface->width_from_buffer; |
| 774 | src_height = surface->height_from_buffer; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 775 | } else { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 776 | src_x = wl_fixed_to_double(vp->buffer.src_x); |
| 777 | src_y = wl_fixed_to_double(vp->buffer.src_y); |
| 778 | src_width = wl_fixed_to_double(vp->buffer.src_width); |
| 779 | src_height = wl_fixed_to_double(vp->buffer.src_height); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 780 | } |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 781 | |
| 782 | *bx = sx * src_width / surface->width + src_x; |
| 783 | *by = sy * src_height / surface->height + src_y; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 784 | } |
| 785 | |
Jason Ekstrand | 33ff636 | 2013-10-27 22:25:01 -0500 | [diff] [blame] | 786 | WL_EXPORT void |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 787 | weston_surface_to_buffer_float(struct weston_surface *surface, |
| 788 | float sx, float sy, float *bx, float *by) |
| 789 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 790 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
| 791 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 792 | /* first transform coordinates if the viewport is set */ |
| 793 | viewport_surface_to_buffer(surface, sx, sy, bx, by); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 794 | |
Jason Ekstrand | d0cebc3 | 2014-04-21 20:56:46 -0500 | [diff] [blame] | 795 | weston_transformed_coord(surface->width_from_buffer, |
| 796 | surface->height_from_buffer, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 797 | vp->buffer.transform, vp->buffer.scale, |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 798 | *bx, *by, bx, by); |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 799 | } |
| 800 | |
Derek Foreman | 9973967 | 2015-12-03 16:38:11 -0600 | [diff] [blame] | 801 | /** Transform a rectangle from surface coordinates to buffer coordinates |
| 802 | * |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 803 | * \param surface The surface to fetch wp_viewport and buffer transformation |
Derek Foreman | 9973967 | 2015-12-03 16:38:11 -0600 | [diff] [blame] | 804 | * from. |
| 805 | * \param rect The rectangle to transform. |
| 806 | * \return The transformed rectangle. |
| 807 | * |
| 808 | * Viewport and buffer transformations can only do translation, scaling, |
| 809 | * and rotations in 90-degree steps. Therefore the only loss in the |
| 810 | * conversion is coordinate rounding. |
| 811 | * |
| 812 | * However, some coordinate rounding takes place as an intermediate |
| 813 | * step before the buffer scale factor is applied, so the rectangle |
| 814 | * boundary may not be exactly as expected. |
| 815 | * |
| 816 | * This is OK for damage tracking since a little extra coverage is |
| 817 | * not a problem. |
| 818 | */ |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 819 | WL_EXPORT pixman_box32_t |
| 820 | weston_surface_to_buffer_rect(struct weston_surface *surface, |
| 821 | pixman_box32_t rect) |
| 822 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 823 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 824 | float xf, yf; |
| 825 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 826 | /* first transform box coordinates if the viewport is set */ |
| 827 | viewport_surface_to_buffer(surface, rect.x1, rect.y1, &xf, &yf); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 828 | rect.x1 = floorf(xf); |
| 829 | rect.y1 = floorf(yf); |
| 830 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 831 | viewport_surface_to_buffer(surface, rect.x2, rect.y2, &xf, &yf); |
Derek Foreman | e2e15ac | 2015-12-01 13:00:43 -0600 | [diff] [blame] | 832 | rect.x2 = ceilf(xf); |
| 833 | rect.y2 = ceilf(yf); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 834 | |
Jason Ekstrand | d0cebc3 | 2014-04-21 20:56:46 -0500 | [diff] [blame] | 835 | return weston_transformed_rect(surface->width_from_buffer, |
| 836 | surface->height_from_buffer, |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 837 | vp->buffer.transform, vp->buffer.scale, |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 838 | rect); |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 839 | } |
| 840 | |
Pekka Paalanen | e54e31c | 2015-03-04 14:23:28 +0200 | [diff] [blame] | 841 | /** Transform a region from surface coordinates to buffer coordinates |
| 842 | * |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 843 | * \param surface The surface to fetch wp_viewport and buffer transformation |
Pekka Paalanen | e54e31c | 2015-03-04 14:23:28 +0200 | [diff] [blame] | 844 | * from. |
| 845 | * \param surface_region[in] The region in surface coordinates. |
| 846 | * \param buffer_region[out] The region converted to buffer coordinates. |
| 847 | * |
| 848 | * Buffer_region must be init'd, but will be completely overwritten. |
| 849 | * |
| 850 | * Viewport and buffer transformations can only do translation, scaling, |
| 851 | * and rotations in 90-degree steps. Therefore the only loss in the |
Derek Foreman | 9973967 | 2015-12-03 16:38:11 -0600 | [diff] [blame] | 852 | * conversion is from the coordinate rounding that takes place in |
| 853 | * \ref weston_surface_to_buffer_rect. |
Pekka Paalanen | e54e31c | 2015-03-04 14:23:28 +0200 | [diff] [blame] | 854 | */ |
| 855 | WL_EXPORT void |
| 856 | weston_surface_to_buffer_region(struct weston_surface *surface, |
| 857 | pixman_region32_t *surface_region, |
| 858 | pixman_region32_t *buffer_region) |
| 859 | { |
| 860 | pixman_box32_t *src_rects, *dest_rects; |
| 861 | int nrects, i; |
| 862 | |
| 863 | src_rects = pixman_region32_rectangles(surface_region, &nrects); |
| 864 | dest_rects = malloc(nrects * sizeof(*dest_rects)); |
| 865 | if (!dest_rects) |
| 866 | return; |
| 867 | |
| 868 | for (i = 0; i < nrects; i++) { |
| 869 | dest_rects[i] = weston_surface_to_buffer_rect(surface, |
| 870 | src_rects[i]); |
| 871 | } |
| 872 | |
| 873 | pixman_region32_fini(buffer_region); |
| 874 | pixman_region32_init_rects(buffer_region, dest_rects, nrects); |
| 875 | free(dest_rects); |
| 876 | } |
| 877 | |
Ander Conselvan de Oliveira | 0396ba2 | 2012-11-28 17:10:26 +0200 | [diff] [blame] | 878 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 879 | weston_view_move_to_plane(struct weston_view *view, |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 880 | struct weston_plane *plane) |
| 881 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 882 | if (view->plane == plane) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 883 | return; |
| 884 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 885 | weston_view_damage_below(view); |
| 886 | view->plane = plane; |
| 887 | weston_surface_damage(view->surface); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 888 | } |
| 889 | |
Pekka Paalanen | 51723d5 | 2015-02-17 13:10:01 +0200 | [diff] [blame] | 890 | /** Inflict damage on the plane where the view is visible. |
| 891 | * |
| 892 | * \param view The view that causes the damage. |
| 893 | * |
| 894 | * If the view is currently on a plane (including the primary plane), |
| 895 | * take the view's boundingbox, subtract all the opaque views that cover it, |
| 896 | * and add the remaining region as damage to the plane. This corresponds |
| 897 | * to the damage inflicted to the plane if this view disappeared. |
| 898 | * |
| 899 | * A repaint is scheduled for this view. |
| 900 | * |
| 901 | * The region of all opaque views covering this view is stored in |
| 902 | * weston_view::clip and updated by view_accumulate_damage() during |
| 903 | * weston_output_repaint(). Specifically, that region matches the |
| 904 | * scenegraph as it was last painted. |
| 905 | */ |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 906 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 907 | weston_view_damage_below(struct weston_view *view) |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 908 | { |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 909 | pixman_region32_t damage; |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 910 | |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 911 | pixman_region32_init(&damage); |
Pekka Paalanen | 25c0ca5 | 2015-02-19 11:15:33 +0200 | [diff] [blame] | 912 | pixman_region32_subtract(&damage, &view->transform.boundingbox, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 913 | &view->clip); |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 914 | if (view->plane) |
| 915 | pixman_region32_union(&view->plane->damage, |
| 916 | &view->plane->damage, &damage); |
Kristian Høgsberg | 1e83212 | 2012-02-28 22:47:14 -0500 | [diff] [blame] | 917 | pixman_region32_fini(&damage); |
Kristian Høgsberg | a3a784a | 2013-11-13 21:33:43 -0800 | [diff] [blame] | 918 | weston_view_schedule_repaint(view); |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 919 | } |
| 920 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 921 | /** |
| 922 | * \param es The surface |
| 923 | * \param mask The new set of outputs for the surface |
| 924 | * |
| 925 | * Sets the surface's set of outputs to the ones specified by |
| 926 | * the new output mask provided. Identifies the outputs that |
| 927 | * have changed, the posts enter and leave events for these |
| 928 | * outputs as appropriate. |
| 929 | */ |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 930 | static void |
| 931 | weston_surface_update_output_mask(struct weston_surface *es, uint32_t mask) |
| 932 | { |
| 933 | uint32_t different = es->output_mask ^ mask; |
| 934 | uint32_t entered = mask & different; |
| 935 | uint32_t left = es->output_mask & different; |
| 936 | struct weston_output *output; |
| 937 | struct wl_resource *resource = NULL; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 938 | struct wl_client *client; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 939 | |
| 940 | es->output_mask = mask; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 941 | if (es->resource == NULL) |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 942 | return; |
| 943 | if (different == 0) |
| 944 | return; |
| 945 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 946 | client = wl_resource_get_client(es->resource); |
| 947 | |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 948 | wl_list_for_each(output, &es->compositor->output_list, link) { |
Bryce Harrington | 89324ce | 2015-12-23 18:38:07 -0800 | [diff] [blame] | 949 | if (1u << output->id & different) |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 950 | resource = |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 951 | wl_resource_find_for_client(&output->resource_list, |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 952 | client); |
| 953 | if (resource == NULL) |
| 954 | continue; |
Bryce Harrington | 89324ce | 2015-12-23 18:38:07 -0800 | [diff] [blame] | 955 | if (1u << output->id & entered) |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 956 | wl_surface_send_enter(es->resource, resource); |
Bryce Harrington | 89324ce | 2015-12-23 18:38:07 -0800 | [diff] [blame] | 957 | if (1u << output->id & left) |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 958 | wl_surface_send_leave(es->resource, resource); |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 959 | } |
| 960 | } |
| 961 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 962 | /** Recalculate which output(s) the surface has views displayed on |
| 963 | * |
| 964 | * \param es The surface to remap to outputs |
| 965 | * |
| 966 | * Finds the output that is showing the largest amount of one |
| 967 | * of the surface's various views. This output becomes the |
Pekka Paalanen | 130ae6e | 2016-03-30 14:33:33 +0300 | [diff] [blame] | 968 | * surface's primary output for vsync and frame callback purposes. |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 969 | * |
Pekka Paalanen | 130ae6e | 2016-03-30 14:33:33 +0300 | [diff] [blame] | 970 | * Also notes all outputs of all of the surface's views |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 971 | * in the output_mask for the surface. |
| 972 | */ |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 973 | static void |
| 974 | weston_surface_assign_output(struct weston_surface *es) |
| 975 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 976 | struct weston_output *new_output; |
| 977 | struct weston_view *view; |
| 978 | pixman_region32_t region; |
| 979 | uint32_t max, area, mask; |
| 980 | pixman_box32_t *e; |
| 981 | |
| 982 | new_output = NULL; |
| 983 | max = 0; |
| 984 | mask = 0; |
| 985 | pixman_region32_init(®ion); |
| 986 | wl_list_for_each(view, &es->views, surface_link) { |
| 987 | if (!view->output) |
| 988 | continue; |
| 989 | |
| 990 | pixman_region32_intersect(®ion, &view->transform.boundingbox, |
| 991 | &view->output->region); |
| 992 | |
| 993 | e = pixman_region32_extents(®ion); |
| 994 | area = (e->x2 - e->x1) * (e->y2 - e->y1); |
| 995 | |
| 996 | mask |= view->output_mask; |
| 997 | |
| 998 | if (area >= max) { |
| 999 | new_output = view->output; |
| 1000 | max = area; |
| 1001 | } |
| 1002 | } |
| 1003 | pixman_region32_fini(®ion); |
| 1004 | |
| 1005 | es->output = new_output; |
| 1006 | weston_surface_update_output_mask(es, mask); |
| 1007 | } |
| 1008 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1009 | /** Recalculate which output(s) the view is displayed on |
| 1010 | * |
| 1011 | * \param ev The view to remap to outputs |
| 1012 | * |
| 1013 | * Identifies the set of outputs that the view is visible on, |
| 1014 | * noting them into the output_mask. The output that the view |
Pekka Paalanen | 130ae6e | 2016-03-30 14:33:33 +0300 | [diff] [blame] | 1015 | * is most visible on is set as the view's primary output. |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1016 | * |
| 1017 | * Also does the same for the view's surface. See |
| 1018 | * weston_surface_assign_output(). |
| 1019 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1020 | static void |
| 1021 | weston_view_assign_output(struct weston_view *ev) |
| 1022 | { |
| 1023 | struct weston_compositor *ec = ev->surface->compositor; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1024 | struct weston_output *output, *new_output; |
| 1025 | pixman_region32_t region; |
| 1026 | uint32_t max, area, mask; |
| 1027 | pixman_box32_t *e; |
| 1028 | |
| 1029 | new_output = NULL; |
| 1030 | max = 0; |
| 1031 | mask = 0; |
| 1032 | pixman_region32_init(®ion); |
| 1033 | wl_list_for_each(output, &ec->output_list, link) { |
Giulio Camuffo | 2f2a70c | 2015-07-12 10:52:32 +0300 | [diff] [blame] | 1034 | if (output->destroying) |
| 1035 | continue; |
| 1036 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1037 | pixman_region32_intersect(®ion, &ev->transform.boundingbox, |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1038 | &output->region); |
| 1039 | |
| 1040 | e = pixman_region32_extents(®ion); |
| 1041 | area = (e->x2 - e->x1) * (e->y2 - e->y1); |
| 1042 | |
| 1043 | if (area > 0) |
Bryce Harrington | 89324ce | 2015-12-23 18:38:07 -0800 | [diff] [blame] | 1044 | mask |= 1u << output->id; |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1045 | |
| 1046 | if (area >= max) { |
| 1047 | new_output = output; |
| 1048 | max = area; |
| 1049 | } |
| 1050 | } |
| 1051 | pixman_region32_fini(®ion); |
| 1052 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1053 | ev->output = new_output; |
| 1054 | ev->output_mask = mask; |
| 1055 | |
| 1056 | weston_surface_assign_output(ev->surface); |
Kristian Høgsberg | b9af479 | 2012-09-25 14:48:04 -0400 | [diff] [blame] | 1057 | } |
| 1058 | |
Pekka Paalanen | 9abf393 | 2012-02-08 14:49:37 +0200 | [diff] [blame] | 1059 | static void |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1060 | weston_view_to_view_map(struct weston_view *from, struct weston_view *to, |
| 1061 | int from_x, int from_y, int *to_x, int *to_y) |
| 1062 | { |
| 1063 | float x, y; |
| 1064 | |
| 1065 | weston_view_to_global_float(from, from_x, from_y, &x, &y); |
| 1066 | weston_view_from_global_float(to, x, y, &x, &y); |
| 1067 | |
| 1068 | *to_x = round(x); |
| 1069 | *to_y = round(y); |
| 1070 | } |
| 1071 | |
| 1072 | static void |
| 1073 | weston_view_transfer_scissor(struct weston_view *from, struct weston_view *to) |
| 1074 | { |
| 1075 | pixman_box32_t *a; |
| 1076 | pixman_box32_t b; |
| 1077 | |
| 1078 | a = pixman_region32_extents(&from->geometry.scissor); |
| 1079 | |
| 1080 | weston_view_to_view_map(from, to, a->x1, a->y1, &b.x1, &b.y1); |
| 1081 | weston_view_to_view_map(from, to, a->x2, a->y2, &b.x2, &b.y2); |
| 1082 | |
| 1083 | pixman_region32_fini(&to->geometry.scissor); |
| 1084 | pixman_region32_init_with_extents(&to->geometry.scissor, &b); |
| 1085 | } |
| 1086 | |
| 1087 | static void |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 1088 | view_compute_bbox(struct weston_view *view, const pixman_box32_t *inbox, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1089 | pixman_region32_t *bbox) |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1090 | { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1091 | float min_x = HUGE_VALF, min_y = HUGE_VALF; |
| 1092 | float max_x = -HUGE_VALF, max_y = -HUGE_VALF; |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1093 | int32_t s[4][2] = { |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 1094 | { inbox->x1, inbox->y1 }, |
| 1095 | { inbox->x1, inbox->y2 }, |
| 1096 | { inbox->x2, inbox->y1 }, |
| 1097 | { inbox->x2, inbox->y2 }, |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1098 | }; |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1099 | float int_x, int_y; |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1100 | int i; |
| 1101 | |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 1102 | if (inbox->x1 == inbox->x2 || inbox->y1 == inbox->y2) { |
Pekka Paalanen | 7c7d464 | 2012-09-04 13:55:44 +0300 | [diff] [blame] | 1103 | /* avoid rounding empty bbox to 1x1 */ |
| 1104 | pixman_region32_init(bbox); |
| 1105 | return; |
| 1106 | } |
| 1107 | |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1108 | for (i = 0; i < 4; ++i) { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1109 | float x, y; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1110 | 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] | 1111 | if (x < min_x) |
| 1112 | min_x = x; |
| 1113 | if (x > max_x) |
| 1114 | max_x = x; |
| 1115 | if (y < min_y) |
| 1116 | min_y = y; |
| 1117 | if (y > max_y) |
| 1118 | max_y = y; |
| 1119 | } |
| 1120 | |
Pekka Paalanen | 219b982 | 2012-02-08 15:38:37 +0200 | [diff] [blame] | 1121 | int_x = floorf(min_x); |
| 1122 | int_y = floorf(min_y); |
| 1123 | pixman_region32_init_rect(bbox, int_x, int_y, |
| 1124 | ceilf(max_x) - int_x, ceilf(max_y) - int_y); |
Pekka Paalanen | 6720d8f | 2012-01-25 15:17:40 +0200 | [diff] [blame] | 1125 | } |
| 1126 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1127 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1128 | weston_view_update_transform_disable(struct weston_view *view) |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1129 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1130 | view->transform.enabled = 0; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1131 | |
Pekka Paalanen | cc2f868 | 2012-02-13 10:34:04 +0200 | [diff] [blame] | 1132 | /* round off fractions when not transformed */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1133 | view->geometry.x = roundf(view->geometry.x); |
| 1134 | view->geometry.y = roundf(view->geometry.y); |
Pekka Paalanen | cc2f868 | 2012-02-13 10:34:04 +0200 | [diff] [blame] | 1135 | |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1136 | /* Otherwise identity matrix, but with x and y translation. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1137 | view->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE; |
| 1138 | view->transform.position.matrix.d[12] = view->geometry.x; |
| 1139 | view->transform.position.matrix.d[13] = view->geometry.y; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1140 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1141 | view->transform.matrix = view->transform.position.matrix; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1142 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1143 | view->transform.inverse = view->transform.position.matrix; |
| 1144 | view->transform.inverse.d[12] = -view->geometry.x; |
| 1145 | view->transform.inverse.d[13] = -view->geometry.y; |
Kristian Høgsberg | c1e6c8a | 2013-02-19 17:04:50 -0500 | [diff] [blame] | 1146 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1147 | pixman_region32_init_rect(&view->transform.boundingbox, |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1148 | 0, 0, |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1149 | view->surface->width, |
| 1150 | view->surface->height); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1151 | if (view->geometry.scissor_enabled) |
| 1152 | pixman_region32_intersect(&view->transform.boundingbox, |
| 1153 | &view->transform.boundingbox, |
| 1154 | &view->geometry.scissor); |
| 1155 | |
| 1156 | pixman_region32_translate(&view->transform.boundingbox, |
| 1157 | view->geometry.x, view->geometry.y); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1158 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1159 | if (view->alpha == 1.0) { |
| 1160 | pixman_region32_copy(&view->transform.opaque, |
| 1161 | &view->surface->opaque); |
| 1162 | pixman_region32_translate(&view->transform.opaque, |
| 1163 | view->geometry.x, |
| 1164 | view->geometry.y); |
Kristian Høgsberg | 3b4af20 | 2012-02-28 09:19:39 -0500 | [diff] [blame] | 1165 | } |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1166 | } |
| 1167 | |
| 1168 | static int |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1169 | weston_view_update_transform_enable(struct weston_view *view) |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1170 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1171 | struct weston_view *parent = view->geometry.parent; |
| 1172 | struct weston_matrix *matrix = &view->transform.matrix; |
| 1173 | struct weston_matrix *inverse = &view->transform.inverse; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1174 | struct weston_transform *tform; |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1175 | pixman_region32_t surfregion; |
| 1176 | const pixman_box32_t *surfbox; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1177 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1178 | view->transform.enabled = 1; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1179 | |
| 1180 | /* Otherwise identity matrix, but with x and y translation. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1181 | view->transform.position.matrix.type = WESTON_MATRIX_TRANSFORM_TRANSLATE; |
| 1182 | view->transform.position.matrix.d[12] = view->geometry.x; |
| 1183 | view->transform.position.matrix.d[13] = view->geometry.y; |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1184 | |
| 1185 | weston_matrix_init(matrix); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1186 | wl_list_for_each(tform, &view->geometry.transformation_list, link) |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1187 | weston_matrix_multiply(matrix, &tform->matrix); |
| 1188 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1189 | if (parent) |
| 1190 | weston_matrix_multiply(matrix, &parent->transform.matrix); |
| 1191 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1192 | if (weston_matrix_invert(inverse, matrix) < 0) { |
| 1193 | /* Oops, bad total transformation, not invertible */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1194 | weston_log("error: weston_view %p" |
| 1195 | " transformation not invertible.\n", view); |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1196 | return -1; |
| 1197 | } |
| 1198 | |
Giulio Camuffo | 148c199 | 2016-09-04 18:50:46 +0300 | [diff] [blame] | 1199 | if (view->alpha == 1.0 && |
| 1200 | matrix->type == WESTON_MATRIX_TRANSFORM_TRANSLATE) { |
| 1201 | pixman_region32_copy(&view->transform.opaque, |
| 1202 | &view->surface->opaque); |
| 1203 | pixman_region32_translate(&view->transform.opaque, |
| 1204 | matrix->d[12], |
| 1205 | matrix->d[13]); |
| 1206 | } |
| 1207 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1208 | pixman_region32_init_rect(&surfregion, 0, 0, |
| 1209 | view->surface->width, view->surface->height); |
| 1210 | if (view->geometry.scissor_enabled) |
| 1211 | pixman_region32_intersect(&surfregion, &surfregion, |
| 1212 | &view->geometry.scissor); |
| 1213 | surfbox = pixman_region32_extents(&surfregion); |
| 1214 | |
| 1215 | view_compute_bbox(view, surfbox, &view->transform.boundingbox); |
| 1216 | pixman_region32_fini(&surfregion); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1217 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1218 | return 0; |
| 1219 | } |
| 1220 | |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1221 | static struct weston_layer * |
| 1222 | get_view_layer(struct weston_view *view) |
| 1223 | { |
| 1224 | if (view->parent_view) |
| 1225 | return get_view_layer(view->parent_view); |
| 1226 | return view->layer_link.layer; |
| 1227 | } |
| 1228 | |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1229 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1230 | weston_view_update_transform(struct weston_view *view) |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1231 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1232 | struct weston_view *parent = view->geometry.parent; |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1233 | struct weston_layer *layer; |
| 1234 | pixman_region32_t mask; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1235 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1236 | if (!view->transform.dirty) |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1237 | return; |
| 1238 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1239 | if (parent) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1240 | weston_view_update_transform(parent); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1241 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1242 | view->transform.dirty = 0; |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1243 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1244 | weston_view_damage_below(view); |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 1245 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1246 | pixman_region32_fini(&view->transform.boundingbox); |
| 1247 | pixman_region32_fini(&view->transform.opaque); |
| 1248 | pixman_region32_init(&view->transform.opaque); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1249 | |
Pekka Paalanen | cd40362 | 2012-01-25 13:37:39 +0200 | [diff] [blame] | 1250 | /* transform.position is always in transformation_list */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1251 | if (view->geometry.transformation_list.next == |
| 1252 | &view->transform.position.link && |
| 1253 | view->geometry.transformation_list.prev == |
| 1254 | &view->transform.position.link && |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1255 | !parent) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1256 | weston_view_update_transform_disable(view); |
Pekka Paalanen | 80fb08d | 2012-02-08 15:14:17 +0200 | [diff] [blame] | 1257 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1258 | if (weston_view_update_transform_enable(view) < 0) |
| 1259 | weston_view_update_transform_disable(view); |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1260 | } |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 1261 | |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1262 | layer = get_view_layer(view); |
| 1263 | if (layer) { |
| 1264 | pixman_region32_init_with_extents(&mask, &layer->mask); |
Pekka Paalanen | 25c0ca5 | 2015-02-19 11:15:33 +0200 | [diff] [blame] | 1265 | pixman_region32_intersect(&view->transform.boundingbox, |
| 1266 | &view->transform.boundingbox, &mask); |
Pekka Paalanen | 8844bf2 | 2015-02-18 16:30:47 +0200 | [diff] [blame] | 1267 | pixman_region32_intersect(&view->transform.opaque, |
| 1268 | &view->transform.opaque, &mask); |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 1269 | pixman_region32_fini(&mask); |
| 1270 | } |
| 1271 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1272 | if (parent) { |
| 1273 | if (parent->geometry.scissor_enabled) { |
| 1274 | view->geometry.scissor_enabled = true; |
| 1275 | weston_view_transfer_scissor(parent, view); |
| 1276 | } else { |
| 1277 | view->geometry.scissor_enabled = false; |
| 1278 | } |
| 1279 | } |
| 1280 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1281 | weston_view_damage_below(view); |
Pekka Paalanen | 9651678 | 2012-02-09 15:32:15 +0200 | [diff] [blame] | 1282 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1283 | weston_view_assign_output(view); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 1284 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1285 | wl_signal_emit(&view->surface->compositor->transform_signal, |
| 1286 | view->surface); |
Pekka Paalanen | 2a5cecc | 2012-01-20 14:24:25 +0200 | [diff] [blame] | 1287 | } |
| 1288 | |
Pekka Paalanen | ddae03c | 2012-02-06 14:54:20 +0200 | [diff] [blame] | 1289 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1290 | weston_view_geometry_dirty(struct weston_view *view) |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 1291 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1292 | struct weston_view *child; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1293 | |
| 1294 | /* |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1295 | * The invariant: if view->geometry.dirty, then all views |
| 1296 | * in view->geometry.child_list have geometry.dirty too. |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1297 | * Corollary: if not parent->geometry.dirty, then all ancestors |
| 1298 | * are not dirty. |
| 1299 | */ |
| 1300 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1301 | if (view->transform.dirty) |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1302 | return; |
| 1303 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1304 | view->transform.dirty = 1; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1305 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1306 | wl_list_for_each(child, &view->geometry.child_list, |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1307 | geometry.parent_link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1308 | weston_view_geometry_dirty(child); |
Pekka Paalanen | c3ce738 | 2013-03-08 14:56:49 +0200 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1312 | weston_view_to_global_fixed(struct weston_view *view, |
| 1313 | wl_fixed_t vx, wl_fixed_t vy, |
| 1314 | wl_fixed_t *x, wl_fixed_t *y) |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1315 | { |
John Kåre Alsaker | 490d02a | 2012-09-30 02:57:21 +0200 | [diff] [blame] | 1316 | float xf, yf; |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1317 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1318 | weston_view_to_global_float(view, |
| 1319 | wl_fixed_to_double(vx), |
| 1320 | wl_fixed_to_double(vy), |
| 1321 | &xf, &yf); |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1322 | *x = wl_fixed_from_double(xf); |
| 1323 | *y = wl_fixed_from_double(yf); |
| 1324 | } |
| 1325 | |
Kristian Høgsberg | ecf6ede | 2012-09-05 21:59:35 -0400 | [diff] [blame] | 1326 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1327 | weston_view_from_global_float(struct weston_view *view, |
| 1328 | float x, float y, float *vx, float *vy) |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1329 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1330 | if (view->transform.enabled) { |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1331 | struct weston_vector v = { { x, y, 0.0f, 1.0f } }; |
| 1332 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1333 | weston_matrix_transform(&view->transform.inverse, &v); |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1334 | |
| 1335 | if (fabsf(v.f[3]) < 1e-6) { |
Martin Minarik | 6d11836 | 2012-06-07 18:01:59 +0200 | [diff] [blame] | 1336 | weston_log("warning: numerical instability in " |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1337 | "weston_view_from_global(), divisor = %g\n", |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1338 | v.f[3]); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1339 | *vx = 0; |
| 1340 | *vy = 0; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1341 | return; |
| 1342 | } |
| 1343 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1344 | *vx = v.f[0] / v.f[3]; |
| 1345 | *vy = v.f[1] / v.f[3]; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1346 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1347 | *vx = x - view->geometry.x; |
| 1348 | *vy = y - view->geometry.y; |
Pekka Paalanen | e0f3cb2 | 2012-01-24 09:59:29 +0200 | [diff] [blame] | 1349 | } |
| 1350 | } |
| 1351 | |
| 1352 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1353 | weston_view_from_global_fixed(struct weston_view *view, |
| 1354 | wl_fixed_t x, wl_fixed_t y, |
| 1355 | wl_fixed_t *vx, wl_fixed_t *vy) |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1356 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1357 | float vxf, vyf; |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1358 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1359 | weston_view_from_global_float(view, |
| 1360 | wl_fixed_to_double(x), |
| 1361 | wl_fixed_to_double(y), |
| 1362 | &vxf, &vyf); |
| 1363 | *vx = wl_fixed_from_double(vxf); |
| 1364 | *vy = wl_fixed_from_double(vyf); |
Daniel Stone | bd3489b | 2012-05-08 17:17:53 +0100 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1368 | weston_view_from_global(struct weston_view *view, |
| 1369 | int32_t x, int32_t y, int32_t *vx, int32_t *vy) |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1370 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1371 | float vxf, vyf; |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1372 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1373 | weston_view_from_global_float(view, x, y, &vxf, &vyf); |
| 1374 | *vx = floorf(vxf); |
| 1375 | *vy = floorf(vyf); |
Pekka Paalanen | 0e151bb | 2012-01-24 14:47:37 +0200 | [diff] [blame] | 1376 | } |
| 1377 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1378 | /** |
| 1379 | * \param surface The surface to be repainted |
| 1380 | * |
| 1381 | * Marks the output(s) that the surface is shown on as needing to be |
| 1382 | * repainted. See weston_output_schedule_repaint(). |
| 1383 | */ |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1384 | WL_EXPORT void |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1385 | weston_surface_schedule_repaint(struct weston_surface *surface) |
| 1386 | { |
| 1387 | struct weston_output *output; |
| 1388 | |
| 1389 | wl_list_for_each(output, &surface->compositor->output_list, link) |
Bryce Harrington | 89324ce | 2015-12-23 18:38:07 -0800 | [diff] [blame] | 1390 | if (surface->output_mask & (1u << output->id)) |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1391 | weston_output_schedule_repaint(output); |
| 1392 | } |
| 1393 | |
Bryce Harrington | 3f650b8 | 2015-12-23 11:01:58 -0800 | [diff] [blame] | 1394 | /** |
| 1395 | * \param view The view to be repainted |
| 1396 | * |
| 1397 | * Marks the output(s) that the view is shown on as needing to be |
| 1398 | * repainted. See weston_output_schedule_repaint(). |
| 1399 | */ |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1400 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1401 | weston_view_schedule_repaint(struct weston_view *view) |
| 1402 | { |
| 1403 | struct weston_output *output; |
| 1404 | |
| 1405 | wl_list_for_each(output, &view->surface->compositor->output_list, link) |
Bryce Harrington | 89324ce | 2015-12-23 18:38:07 -0800 | [diff] [blame] | 1406 | if (view->output_mask & (1u << output->id)) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1407 | weston_output_schedule_repaint(output); |
| 1408 | } |
| 1409 | |
Pekka Paalanen | e508ce6 | 2015-02-19 13:59:55 +0200 | [diff] [blame] | 1410 | /** |
| 1411 | * XXX: This function does it the wrong way. |
| 1412 | * surface->damage is the damage from the client, and causes |
| 1413 | * surface_flush_damage() to copy pixels. No window management action can |
| 1414 | * cause damage to the client-provided content, warranting re-upload! |
| 1415 | * |
| 1416 | * Instead of surface->damage, this function should record the damage |
| 1417 | * with all the views for this surface to avoid extraneous texture |
| 1418 | * uploads. |
| 1419 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1420 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1421 | weston_surface_damage(struct weston_surface *surface) |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 1422 | { |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 1423 | pixman_region32_union_rect(&surface->damage, &surface->damage, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1424 | 0, 0, surface->width, |
| 1425 | surface->height); |
Pekka Paalanen | 2267d45 | 2012-01-26 13:12:45 +0200 | [diff] [blame] | 1426 | |
Kristian Høgsberg | 9823870 | 2012-08-03 16:29:12 -0400 | [diff] [blame] | 1427 | weston_surface_schedule_repaint(surface); |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 1428 | } |
| 1429 | |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 1430 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1431 | weston_view_set_position(struct weston_view *view, float x, float y) |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1432 | { |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1433 | if (view->geometry.x == x && view->geometry.y == y) |
| 1434 | return; |
| 1435 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1436 | view->geometry.x = x; |
| 1437 | view->geometry.y = y; |
| 1438 | weston_view_geometry_dirty(view); |
Pekka Paalanen | 8fb8d3b | 2012-02-13 13:03:59 +0200 | [diff] [blame] | 1439 | } |
| 1440 | |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1441 | static void |
| 1442 | transform_parent_handle_parent_destroy(struct wl_listener *listener, |
| 1443 | void *data) |
| 1444 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1445 | struct weston_view *view = |
| 1446 | container_of(listener, struct weston_view, |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1447 | geometry.parent_destroy_listener); |
| 1448 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1449 | weston_view_set_transform_parent(view, NULL); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1450 | } |
| 1451 | |
| 1452 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1453 | weston_view_set_transform_parent(struct weston_view *view, |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1454 | struct weston_view *parent) |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1455 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1456 | if (view->geometry.parent) { |
| 1457 | wl_list_remove(&view->geometry.parent_destroy_listener.link); |
| 1458 | wl_list_remove(&view->geometry.parent_link); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1459 | |
| 1460 | if (!parent) |
| 1461 | view->geometry.scissor_enabled = false; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1462 | } |
| 1463 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1464 | view->geometry.parent = parent; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1465 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1466 | view->geometry.parent_destroy_listener.notify = |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1467 | transform_parent_handle_parent_destroy; |
| 1468 | if (parent) { |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1469 | wl_signal_add(&parent->destroy_signal, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1470 | &view->geometry.parent_destroy_listener); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1471 | wl_list_insert(&parent->geometry.child_list, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1472 | &view->geometry.parent_link); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1473 | } |
| 1474 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1475 | weston_view_geometry_dirty(view); |
| 1476 | } |
| 1477 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1478 | /** Set a clip mask rectangle on a view |
| 1479 | * |
| 1480 | * \param view The view to set the clip mask on. |
| 1481 | * \param x Top-left corner X coordinate of the clip rectangle. |
| 1482 | * \param y Top-left corner Y coordinate of the clip rectangle. |
| 1483 | * \param width Width of the clip rectangle, non-negative. |
| 1484 | * \param height Height of the clip rectangle, non-negative. |
| 1485 | * |
| 1486 | * A shell may set a clip mask rectangle on a view. Everything outside |
| 1487 | * the rectangle is cut away for input and output purposes: it is |
| 1488 | * not drawn and cannot be hit by hit-test based input like pointer |
| 1489 | * motion or touch-downs. Everything inside the rectangle will behave |
| 1490 | * normally. Clients are unaware of clipping. |
| 1491 | * |
Yong Bakos | 4c72e29 | 2016-04-28 11:59:10 -0500 | [diff] [blame] | 1492 | * The rectangle is set in surface-local coordinates. Setting a clip |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1493 | * mask rectangle does not affect the view position, the view is positioned |
| 1494 | * as it would be without a clip. The clip also does not change |
| 1495 | * weston_surface::width,height. |
| 1496 | * |
| 1497 | * The clip mask rectangle is part of transformation inheritance |
| 1498 | * (weston_view_set_transform_parent()). A clip set in the root of the |
| 1499 | * transformation inheritance tree will affect all views in the tree. |
| 1500 | * A clip can be set only on the root view. Attempting to set a clip |
| 1501 | * on view that has a transformation parent will fail. Assigning a parent |
| 1502 | * to a view that has a clip set will cause the clip to be forgotten. |
| 1503 | * |
| 1504 | * Because the clip mask is an axis-aligned rectangle, it poses restrictions |
| 1505 | * on the additional transformations in the child views. These transformations |
| 1506 | * may not rotate the coordinate axes, i.e., only translation and scaling |
| 1507 | * are allowed. Violating this restriction causes the clipping to malfunction. |
| 1508 | * Furthermore, using scaling may cause rounding errors in child clipping. |
| 1509 | * |
| 1510 | * The clip mask rectangle is not automatically adjusted based on |
| 1511 | * wl_surface.attach dx and dy arguments. |
| 1512 | * |
| 1513 | * A clip mask rectangle can be set only if the compositor capability |
| 1514 | * WESTON_CAP_VIEW_CLIP_MASK is present. |
| 1515 | * |
| 1516 | * This function sets the clip mask rectangle and schedules a repaint for |
| 1517 | * the view. |
| 1518 | */ |
| 1519 | WL_EXPORT void |
| 1520 | weston_view_set_mask(struct weston_view *view, |
| 1521 | int x, int y, int width, int height) |
| 1522 | { |
| 1523 | struct weston_compositor *compositor = view->surface->compositor; |
| 1524 | |
| 1525 | if (!(compositor->capabilities & WESTON_CAP_VIEW_CLIP_MASK)) { |
| 1526 | weston_log("%s not allowed without capability!\n", __func__); |
| 1527 | return; |
| 1528 | } |
| 1529 | |
| 1530 | if (view->geometry.parent) { |
| 1531 | weston_log("view %p has a parent, clip forbidden!\n", view); |
| 1532 | return; |
| 1533 | } |
| 1534 | |
| 1535 | if (width < 0 || height < 0) { |
| 1536 | weston_log("%s: illegal args %d, %d, %d, %d\n", __func__, |
| 1537 | x, y, width, height); |
| 1538 | return; |
| 1539 | } |
| 1540 | |
| 1541 | pixman_region32_fini(&view->geometry.scissor); |
| 1542 | pixman_region32_init_rect(&view->geometry.scissor, x, y, width, height); |
| 1543 | view->geometry.scissor_enabled = true; |
| 1544 | weston_view_geometry_dirty(view); |
| 1545 | weston_view_schedule_repaint(view); |
| 1546 | } |
| 1547 | |
| 1548 | /** Remove the clip mask from a view |
| 1549 | * |
| 1550 | * \param view The view to remove the clip mask from. |
| 1551 | * |
| 1552 | * Removed the clip mask rectangle and schedules a repaint. |
| 1553 | * |
| 1554 | * \sa weston_view_set_mask |
| 1555 | */ |
| 1556 | WL_EXPORT void |
| 1557 | weston_view_set_mask_infinite(struct weston_view *view) |
| 1558 | { |
| 1559 | view->geometry.scissor_enabled = false; |
| 1560 | weston_view_geometry_dirty(view); |
| 1561 | weston_view_schedule_repaint(view); |
| 1562 | } |
| 1563 | |
Armin Krezović | 0da12b8 | 2016-06-30 06:04:33 +0200 | [diff] [blame] | 1564 | /* Check if view should be displayed |
| 1565 | * |
| 1566 | * The indicator is set manually when assigning |
| 1567 | * a view to a surface. |
| 1568 | * |
| 1569 | * This needs reworking. See the thread starting at: |
| 1570 | * |
| 1571 | * https://lists.freedesktop.org/archives/wayland-devel/2016-June/029656.html |
| 1572 | */ |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 1573 | WL_EXPORT bool |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1574 | weston_view_is_mapped(struct weston_view *view) |
| 1575 | { |
Armin Krezović | 0da12b8 | 2016-06-30 06:04:33 +0200 | [diff] [blame] | 1576 | return view->is_mapped; |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1577 | } |
| 1578 | |
Armin Krezović | 0da12b8 | 2016-06-30 06:04:33 +0200 | [diff] [blame] | 1579 | /* Check if a surface has a view assigned to it |
| 1580 | * |
| 1581 | * The indicator is set manually when mapping |
| 1582 | * a surface and creating a view for it. |
| 1583 | * |
| 1584 | * This needs to go. See the thread starting at: |
| 1585 | * |
| 1586 | * https://lists.freedesktop.org/archives/wayland-devel/2016-June/029656.html |
| 1587 | * |
| 1588 | */ |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 1589 | WL_EXPORT bool |
Ander Conselvan de Oliveira | b8ab14f | 2012-03-27 17:36:36 +0300 | [diff] [blame] | 1590 | weston_surface_is_mapped(struct weston_surface *surface) |
| 1591 | { |
Armin Krezović | 0da12b8 | 2016-06-30 06:04:33 +0200 | [diff] [blame] | 1592 | return surface->is_mapped; |
Ander Conselvan de Oliveira | b8ab14f | 2012-03-27 17:36:36 +0300 | [diff] [blame] | 1593 | } |
| 1594 | |
Pekka Paalanen | da75ee1 | 2013-11-26 18:19:43 +0100 | [diff] [blame] | 1595 | static void |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 1596 | 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] | 1597 | { |
| 1598 | struct weston_view *view; |
| 1599 | |
| 1600 | if (surface->width == width && surface->height == height) |
| 1601 | return; |
| 1602 | |
| 1603 | surface->width = width; |
| 1604 | surface->height = height; |
| 1605 | |
| 1606 | wl_list_for_each(view, &surface->views, surface_link) |
| 1607 | weston_view_geometry_dirty(view); |
| 1608 | } |
| 1609 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 1610 | WL_EXPORT void |
| 1611 | weston_surface_set_size(struct weston_surface *surface, |
| 1612 | int32_t width, int32_t height) |
| 1613 | { |
| 1614 | assert(!surface->resource); |
| 1615 | surface_set_size(surface, width, height); |
| 1616 | } |
| 1617 | |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1618 | static int |
| 1619 | fixed_round_up_to_int(wl_fixed_t f) |
| 1620 | { |
| 1621 | return wl_fixed_to_int(wl_fixed_from_int(1) - 1 + f); |
| 1622 | } |
| 1623 | |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 1624 | static void |
Pekka Paalanen | 59987fa | 2016-04-26 15:50:59 +0300 | [diff] [blame] | 1625 | convert_size_by_transform_scale(int32_t *width_out, int32_t *height_out, |
| 1626 | int32_t width, int32_t height, |
| 1627 | uint32_t transform, |
| 1628 | int32_t scale) |
| 1629 | { |
| 1630 | assert(scale > 0); |
| 1631 | |
| 1632 | switch (transform) { |
| 1633 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 1634 | case WL_OUTPUT_TRANSFORM_180: |
| 1635 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 1636 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 1637 | *width_out = width / scale; |
| 1638 | *height_out = height / scale; |
| 1639 | break; |
| 1640 | case WL_OUTPUT_TRANSFORM_90: |
| 1641 | case WL_OUTPUT_TRANSFORM_270: |
| 1642 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 1643 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 1644 | *width_out = height / scale; |
| 1645 | *height_out = width / scale; |
| 1646 | break; |
| 1647 | default: |
| 1648 | assert(0 && "invalid transform"); |
| 1649 | } |
| 1650 | } |
| 1651 | |
| 1652 | static void |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1653 | weston_surface_calculate_size_from_buffer(struct weston_surface *surface) |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1654 | { |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 1655 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Pekka Paalanen | da75ee1 | 2013-11-26 18:19:43 +0100 | [diff] [blame] | 1656 | |
| 1657 | if (!surface->buffer_ref.buffer) { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1658 | surface->width_from_buffer = 0; |
| 1659 | surface->height_from_buffer = 0; |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 1660 | return; |
| 1661 | } |
| 1662 | |
Pekka Paalanen | 59987fa | 2016-04-26 15:50:59 +0300 | [diff] [blame] | 1663 | convert_size_by_transform_scale(&surface->width_from_buffer, |
| 1664 | &surface->height_from_buffer, |
| 1665 | surface->buffer_ref.buffer->width, |
| 1666 | surface->buffer_ref.buffer->height, |
| 1667 | vp->buffer.transform, |
| 1668 | vp->buffer.scale); |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1669 | } |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1670 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1671 | static void |
| 1672 | weston_surface_update_size(struct weston_surface *surface) |
| 1673 | { |
| 1674 | struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
| 1675 | int32_t width, height; |
| 1676 | |
| 1677 | width = surface->width_from_buffer; |
| 1678 | height = surface->height_from_buffer; |
| 1679 | |
| 1680 | if (width != 0 && vp->surface.width != -1) { |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1681 | surface_set_size(surface, |
| 1682 | vp->surface.width, vp->surface.height); |
| 1683 | return; |
| 1684 | } |
| 1685 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1686 | if (width != 0 && vp->buffer.src_width != wl_fixed_from_int(-1)) { |
Pekka Paalanen | e931721 | 2014-04-04 14:22:13 +0300 | [diff] [blame] | 1687 | int32_t w = fixed_round_up_to_int(vp->buffer.src_width); |
| 1688 | int32_t h = fixed_round_up_to_int(vp->buffer.src_height); |
| 1689 | |
| 1690 | surface_set_size(surface, w ?: 1, h ?: 1); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 1691 | return; |
| 1692 | } |
| 1693 | |
Jason Ekstrand | 5c11a33 | 2013-12-04 20:32:03 -0600 | [diff] [blame] | 1694 | surface_set_size(surface, width, height); |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 1695 | } |
| 1696 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 1697 | WL_EXPORT uint32_t |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1698 | weston_compositor_get_time(void) |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 1699 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1700 | struct timeval tv; |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 1701 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1702 | gettimeofday(&tv, NULL); |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 1703 | |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 1704 | return tv.tv_sec * 1000 + tv.tv_usec / 1000; |
Kristian Høgsberg | 7132a9a | 2010-12-06 21:41:10 -0500 | [diff] [blame] | 1705 | } |
| 1706 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1707 | WL_EXPORT struct weston_view * |
| 1708 | weston_compositor_pick_view(struct weston_compositor *compositor, |
| 1709 | wl_fixed_t x, wl_fixed_t y, |
| 1710 | wl_fixed_t *vx, wl_fixed_t *vy) |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 1711 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1712 | struct weston_view *view; |
Pekka Paalanen | fc22a52 | 2015-02-18 15:08:29 +0200 | [diff] [blame] | 1713 | wl_fixed_t view_x, view_y; |
| 1714 | int view_ix, view_iy; |
| 1715 | int ix = wl_fixed_to_int(x); |
| 1716 | int iy = wl_fixed_to_int(y); |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 1717 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1718 | wl_list_for_each(view, &compositor->view_list, link) { |
Pekka Paalanen | fc22a52 | 2015-02-18 15:08:29 +0200 | [diff] [blame] | 1719 | if (!pixman_region32_contains_point( |
| 1720 | &view->transform.boundingbox, ix, iy, NULL)) |
| 1721 | continue; |
| 1722 | |
| 1723 | weston_view_from_global_fixed(view, x, y, &view_x, &view_y); |
| 1724 | view_ix = wl_fixed_to_int(view_x); |
| 1725 | view_iy = wl_fixed_to_int(view_y); |
| 1726 | |
| 1727 | if (!pixman_region32_contains_point(&view->surface->input, |
| 1728 | view_ix, view_iy, NULL)) |
| 1729 | continue; |
| 1730 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1731 | if (view->geometry.scissor_enabled && |
| 1732 | !pixman_region32_contains_point(&view->geometry.scissor, |
| 1733 | view_ix, view_iy, NULL)) |
| 1734 | continue; |
| 1735 | |
Pekka Paalanen | fc22a52 | 2015-02-18 15:08:29 +0200 | [diff] [blame] | 1736 | *vx = view_x; |
| 1737 | *vy = view_y; |
| 1738 | return view; |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 1739 | } |
| 1740 | |
Derek Foreman | f9318d1 | 2015-05-11 15:40:11 -0500 | [diff] [blame] | 1741 | *vx = wl_fixed_from_int(-1000000); |
| 1742 | *vy = wl_fixed_from_int(-1000000); |
Tiago Vignatti | 9d39352 | 2012-02-10 16:26:19 +0200 | [diff] [blame] | 1743 | return NULL; |
| 1744 | } |
| 1745 | |
| 1746 | static void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1747 | weston_compositor_repick(struct weston_compositor *compositor) |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 1748 | { |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1749 | struct weston_seat *seat; |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 1750 | |
Kristian Høgsberg | 10ddd97 | 2013-10-22 12:40:54 -0700 | [diff] [blame] | 1751 | if (!compositor->session_active) |
Kristian Høgsberg | 1ec0c31 | 2011-11-15 16:39:55 -0500 | [diff] [blame] | 1752 | return; |
| 1753 | |
Daniel Stone | 37816df | 2012-05-16 18:45:18 +0100 | [diff] [blame] | 1754 | wl_list_for_each(seat, &compositor->seat_list, link) |
Kristian Høgsberg | a71e8b2 | 2013-05-06 21:51:21 -0400 | [diff] [blame] | 1755 | weston_seat_repick(seat); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 1756 | } |
| 1757 | |
Kristian Høgsberg | af7b1ff | 2012-06-26 21:19:23 -0400 | [diff] [blame] | 1758 | WL_EXPORT void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1759 | weston_view_unmap(struct weston_view *view) |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 1760 | { |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 1761 | struct weston_seat *seat; |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 1762 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1763 | if (!weston_view_is_mapped(view)) |
| 1764 | return; |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 1765 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1766 | weston_view_damage_below(view); |
| 1767 | view->output = NULL; |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 1768 | view->plane = NULL; |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 1769 | view->is_mapped = false; |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1770 | weston_layer_entry_remove(&view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1771 | wl_list_remove(&view->link); |
| 1772 | wl_list_init(&view->link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1773 | view->output_mask = 0; |
| 1774 | weston_surface_assign_output(view->surface); |
| 1775 | |
| 1776 | if (weston_surface_is_mapped(view->surface)) |
| 1777 | return; |
| 1778 | |
| 1779 | wl_list_for_each(seat, &view->surface->compositor->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1780 | struct weston_touch *touch = weston_seat_get_touch(seat); |
| 1781 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 1782 | struct weston_keyboard *keyboard = |
| 1783 | weston_seat_get_keyboard(seat); |
| 1784 | |
| 1785 | if (keyboard && keyboard->focus == view->surface) |
| 1786 | weston_keyboard_set_focus(keyboard, NULL); |
| 1787 | if (pointer && pointer->focus == view) |
Derek Foreman | f9318d1 | 2015-05-11 15:40:11 -0500 | [diff] [blame] | 1788 | weston_pointer_clear_focus(pointer); |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 1789 | if (touch && touch->focus == view) |
| 1790 | weston_touch_set_focus(touch, NULL); |
Daniel Stone | 4dab5db | 2012-05-30 16:31:53 +0100 | [diff] [blame] | 1791 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1792 | } |
Kristian Høgsberg | 867dec7 | 2012-03-01 17:09:37 -0500 | [diff] [blame] | 1793 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1794 | WL_EXPORT void |
| 1795 | weston_surface_unmap(struct weston_surface *surface) |
| 1796 | { |
| 1797 | struct weston_view *view; |
| 1798 | |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 1799 | surface->is_mapped = false; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1800 | wl_list_for_each(view, &surface->views, surface_link) |
| 1801 | weston_view_unmap(view); |
| 1802 | surface->output = NULL; |
Kristian Høgsberg | 3b5ea3b | 2012-02-17 12:43:56 -0500 | [diff] [blame] | 1803 | } |
| 1804 | |
Pekka Paalanen | 3c9b802 | 2014-03-14 14:38:13 +0200 | [diff] [blame] | 1805 | static void |
| 1806 | weston_surface_reset_pending_buffer(struct weston_surface *surface) |
| 1807 | { |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 1808 | weston_surface_state_set_buffer(&surface->pending, NULL); |
Pekka Paalanen | 3c9b802 | 2014-03-14 14:38:13 +0200 | [diff] [blame] | 1809 | surface->pending.sx = 0; |
| 1810 | surface->pending.sy = 0; |
| 1811 | surface->pending.newly_attached = 0; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1812 | surface->pending.buffer_viewport.changed = 0; |
Pekka Paalanen | 3c9b802 | 2014-03-14 14:38:13 +0200 | [diff] [blame] | 1813 | } |
| 1814 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1815 | WL_EXPORT void |
| 1816 | weston_view_destroy(struct weston_view *view) |
| 1817 | { |
| 1818 | wl_signal_emit(&view->destroy_signal, view); |
| 1819 | |
| 1820 | assert(wl_list_empty(&view->geometry.child_list)); |
| 1821 | |
| 1822 | if (weston_view_is_mapped(view)) { |
| 1823 | weston_view_unmap(view); |
| 1824 | weston_compositor_build_view_list(view->surface->compositor); |
| 1825 | } |
| 1826 | |
| 1827 | wl_list_remove(&view->link); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 1828 | weston_layer_entry_remove(&view->layer_link); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1829 | |
| 1830 | pixman_region32_fini(&view->clip); |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 1831 | pixman_region32_fini(&view->geometry.scissor); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1832 | pixman_region32_fini(&view->transform.boundingbox); |
Pekka Paalanen | 8844bf2 | 2015-02-18 16:30:47 +0200 | [diff] [blame] | 1833 | pixman_region32_fini(&view->transform.opaque); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1834 | |
| 1835 | weston_view_set_transform_parent(view, NULL); |
| 1836 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1837 | wl_list_remove(&view->surface_link); |
| 1838 | |
| 1839 | free(view); |
| 1840 | } |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1841 | |
| 1842 | WL_EXPORT void |
| 1843 | weston_surface_destroy(struct weston_surface *surface) |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 1844 | { |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 1845 | struct weston_frame_callback *cb, *next; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1846 | struct weston_view *ev, *nv; |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 1847 | struct weston_pointer_constraint *constraint, *next_constraint; |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 1848 | |
Giulio Camuffo | 13b85bd | 2013-08-13 23:10:14 +0200 | [diff] [blame] | 1849 | if (--surface->ref_count > 0) |
| 1850 | return; |
| 1851 | |
Pekka Paalanen | 08d3fb7 | 2015-04-17 14:00:24 +0300 | [diff] [blame] | 1852 | assert(surface->resource == NULL); |
| 1853 | |
Pekka Paalanen | ca79076 | 2015-04-17 14:23:38 +0300 | [diff] [blame] | 1854 | wl_signal_emit(&surface->destroy_signal, surface); |
Giulio Camuffo | 13b85bd | 2013-08-13 23:10:14 +0200 | [diff] [blame] | 1855 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 1856 | assert(wl_list_empty(&surface->subsurface_list_pending)); |
| 1857 | assert(wl_list_empty(&surface->subsurface_list)); |
Pekka Paalanen | 483243f | 2013-03-08 14:56:50 +0200 | [diff] [blame] | 1858 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 1859 | wl_list_for_each_safe(ev, nv, &surface->views, surface_link) |
| 1860 | weston_view_destroy(ev); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 1861 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 1862 | weston_surface_state_fini(&surface->pending); |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1863 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1864 | weston_buffer_reference(&surface->buffer_ref, NULL); |
Kristian Høgsberg | 3f8f39c | 2009-09-18 17:05:13 -0400 | [diff] [blame] | 1865 | |
Pekka Paalanen | 402ae6d | 2012-01-03 10:23:24 +0200 | [diff] [blame] | 1866 | pixman_region32_fini(&surface->damage); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 1867 | pixman_region32_fini(&surface->opaque); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 1868 | pixman_region32_fini(&surface->input); |
Pekka Paalanen | 402ae6d | 2012-01-03 10:23:24 +0200 | [diff] [blame] | 1869 | |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 1870 | wl_list_for_each_safe(cb, next, &surface->frame_callback_list, link) |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 1871 | wl_resource_destroy(cb->resource); |
Kristian Høgsberg | 1e51fec | 2012-07-22 11:33:14 -0400 | [diff] [blame] | 1872 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 1873 | weston_presentation_feedback_discard_list(&surface->feedback_list); |
| 1874 | |
Jonas Ådahl | d3414f2 | 2016-07-22 17:56:31 +0800 | [diff] [blame] | 1875 | wl_list_for_each_safe(constraint, next_constraint, |
| 1876 | &surface->pointer_constraints, |
| 1877 | link) |
| 1878 | weston_pointer_constraint_destroy(constraint); |
| 1879 | |
Kristian Høgsberg | 4fa4873 | 2009-03-10 23:17:00 -0400 | [diff] [blame] | 1880 | free(surface); |
Kristian Høgsberg | 5487982 | 2008-11-23 17:07:32 -0500 | [diff] [blame] | 1881 | } |
| 1882 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1883 | static void |
| 1884 | destroy_surface(struct wl_resource *resource) |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 1885 | { |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1886 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 1887 | |
Pekka Paalanen | 08d3fb7 | 2015-04-17 14:00:24 +0300 | [diff] [blame] | 1888 | assert(surface); |
| 1889 | |
Giulio Camuffo | 0d37974 | 2013-11-15 22:06:15 +0100 | [diff] [blame] | 1890 | /* Set the resource to NULL, since we don't want to leave a |
| 1891 | * dangling pointer if the surface was refcounted and survives |
| 1892 | * the weston_surface_destroy() call. */ |
| 1893 | surface->resource = NULL; |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 1894 | |
| 1895 | if (surface->viewport_resource) |
| 1896 | wl_resource_set_user_data(surface->viewport_resource, NULL); |
| 1897 | |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 1898 | weston_surface_destroy(surface); |
Alex Wu | 8811bf9 | 2012-02-28 18:07:54 +0800 | [diff] [blame] | 1899 | } |
| 1900 | |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 1901 | static void |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1902 | weston_buffer_destroy_handler(struct wl_listener *listener, void *data) |
| 1903 | { |
| 1904 | struct weston_buffer *buffer = |
| 1905 | container_of(listener, struct weston_buffer, destroy_listener); |
| 1906 | |
| 1907 | wl_signal_emit(&buffer->destroy_signal, buffer); |
| 1908 | free(buffer); |
| 1909 | } |
| 1910 | |
Giulio Camuffo | e058cd1 | 2013-12-12 14:14:29 +0100 | [diff] [blame] | 1911 | WL_EXPORT struct weston_buffer * |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1912 | weston_buffer_from_resource(struct wl_resource *resource) |
| 1913 | { |
| 1914 | struct weston_buffer *buffer; |
| 1915 | struct wl_listener *listener; |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 1916 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1917 | listener = wl_resource_get_destroy_listener(resource, |
| 1918 | weston_buffer_destroy_handler); |
| 1919 | |
Kristian Høgsberg | 08b58c7 | 2013-08-15 12:26:42 -0700 | [diff] [blame] | 1920 | if (listener) |
| 1921 | return container_of(listener, struct weston_buffer, |
| 1922 | destroy_listener); |
| 1923 | |
| 1924 | buffer = zalloc(sizeof *buffer); |
| 1925 | if (buffer == NULL) |
| 1926 | return NULL; |
| 1927 | |
| 1928 | buffer->resource = resource; |
| 1929 | wl_signal_init(&buffer->destroy_signal); |
| 1930 | buffer->destroy_listener.notify = weston_buffer_destroy_handler; |
Stanislav Vorobiov | bfbb8e5 | 2013-08-29 11:36:44 +0400 | [diff] [blame] | 1931 | buffer->y_inverted = 1; |
Kristian Høgsberg | 08b58c7 | 2013-08-15 12:26:42 -0700 | [diff] [blame] | 1932 | wl_resource_add_destroy_listener(resource, &buffer->destroy_listener); |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 1933 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1934 | return buffer; |
| 1935 | } |
| 1936 | |
| 1937 | static void |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1938 | weston_buffer_reference_handle_destroy(struct wl_listener *listener, |
| 1939 | void *data) |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 1940 | { |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1941 | struct weston_buffer_reference *ref = |
| 1942 | container_of(listener, struct weston_buffer_reference, |
| 1943 | destroy_listener); |
| 1944 | |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1945 | assert((struct weston_buffer *)data == ref->buffer); |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1946 | ref->buffer = NULL; |
| 1947 | } |
| 1948 | |
| 1949 | WL_EXPORT void |
| 1950 | weston_buffer_reference(struct weston_buffer_reference *ref, |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1951 | struct weston_buffer *buffer) |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1952 | { |
| 1953 | if (ref->buffer && buffer != ref->buffer) { |
Kristian Høgsberg | 2034780 | 2013-03-04 12:07:46 -0500 | [diff] [blame] | 1954 | ref->buffer->busy_count--; |
| 1955 | if (ref->buffer->busy_count == 0) { |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1956 | assert(wl_resource_get_client(ref->buffer->resource)); |
| 1957 | wl_resource_queue_event(ref->buffer->resource, |
Kristian Høgsberg | 2034780 | 2013-03-04 12:07:46 -0500 | [diff] [blame] | 1958 | WL_BUFFER_RELEASE); |
| 1959 | } |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1960 | wl_list_remove(&ref->destroy_listener.link); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 1961 | } |
| 1962 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1963 | if (buffer && buffer != ref->buffer) { |
Kristian Høgsberg | b7b77e6 | 2012-09-05 22:38:18 -0400 | [diff] [blame] | 1964 | buffer->busy_count++; |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1965 | wl_signal_add(&buffer->destroy_signal, |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1966 | &ref->destroy_listener); |
Pekka Paalanen | a6421c4 | 2012-12-04 15:58:10 +0200 | [diff] [blame] | 1967 | } |
| 1968 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1969 | ref->buffer = buffer; |
| 1970 | ref->destroy_listener.notify = weston_buffer_reference_handle_destroy; |
| 1971 | } |
| 1972 | |
| 1973 | static void |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 1974 | weston_surface_attach(struct weston_surface *surface, |
| 1975 | struct weston_buffer *buffer) |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 1976 | { |
| 1977 | weston_buffer_reference(&surface->buffer_ref, buffer); |
| 1978 | |
Pekka Paalanen | a6421c4 | 2012-12-04 15:58:10 +0200 | [diff] [blame] | 1979 | if (!buffer) { |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1980 | if (weston_surface_is_mapped(surface)) |
| 1981 | weston_surface_unmap(surface); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 1982 | } |
| 1983 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 1984 | surface->compositor->renderer->attach(surface, buffer); |
Pekka Paalanen | bb2f3f2 | 2014-03-14 14:38:11 +0200 | [diff] [blame] | 1985 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 1986 | weston_surface_calculate_size_from_buffer(surface); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 1987 | weston_presentation_feedback_discard_list(&surface->feedback_list); |
Benjamin Franzke | faa0a9d | 2011-02-21 16:24:53 +0100 | [diff] [blame] | 1988 | } |
| 1989 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 1990 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1991 | weston_compositor_damage_all(struct weston_compositor *compositor) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1992 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1993 | struct weston_output *output; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1994 | |
| 1995 | wl_list_for_each(output, &compositor->output_list, link) |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 1996 | weston_output_damage(output); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 1997 | } |
| 1998 | |
Kristian Høgsberg | 9f404b7 | 2012-01-26 00:11:01 -0500 | [diff] [blame] | 1999 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2000 | weston_output_damage(struct weston_output *output) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2001 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2002 | struct weston_compositor *compositor = output->compositor; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2003 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 2004 | pixman_region32_union(&compositor->primary_plane.damage, |
| 2005 | &compositor->primary_plane.damage, |
| 2006 | &output->region); |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2007 | weston_output_schedule_repaint(output); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2008 | } |
| 2009 | |
Kristian Høgsberg | 01f941b | 2009-05-27 17:47:15 -0400 | [diff] [blame] | 2010 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2011 | surface_flush_damage(struct weston_surface *surface) |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2012 | { |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2013 | if (surface->buffer_ref.buffer && |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2014 | wl_shm_buffer_get(surface->buffer_ref.buffer->resource)) |
Kristian Høgsberg | fa1be02 | 2012-09-05 22:49:55 -0400 | [diff] [blame] | 2015 | surface->compositor->renderer->flush_damage(surface); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2016 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2017 | if (weston_timeline_enabled_ && |
| 2018 | pixman_region32_not_empty(&surface->damage)) |
| 2019 | TL_POINT("core_flush_damage", TLP_SURFACE(surface), |
| 2020 | TLP_OUTPUT(surface->output), TLP_END); |
| 2021 | |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 2022 | pixman_region32_clear(&surface->damage); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2023 | } |
| 2024 | |
| 2025 | static void |
| 2026 | view_accumulate_damage(struct weston_view *view, |
| 2027 | pixman_region32_t *opaque) |
| 2028 | { |
| 2029 | pixman_region32_t damage; |
| 2030 | |
| 2031 | pixman_region32_init(&damage); |
| 2032 | if (view->transform.enabled) { |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2033 | pixman_box32_t *extents; |
| 2034 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2035 | extents = pixman_region32_extents(&view->surface->damage); |
Pekka Paalanen | c7d7fdf | 2015-02-23 12:27:00 +0200 | [diff] [blame] | 2036 | view_compute_bbox(view, extents, &damage); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2037 | } else { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2038 | pixman_region32_copy(&damage, &view->surface->damage); |
| 2039 | pixman_region32_translate(&damage, |
Pekka Paalanen | 502f5e0 | 2015-02-23 14:08:25 +0200 | [diff] [blame] | 2040 | view->geometry.x, view->geometry.y); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2041 | } |
| 2042 | |
Pekka Paalanen | 380adf5 | 2015-02-16 14:39:11 +0200 | [diff] [blame] | 2043 | pixman_region32_intersect(&damage, &damage, |
| 2044 | &view->transform.boundingbox); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2045 | pixman_region32_subtract(&damage, &damage, opaque); |
| 2046 | pixman_region32_union(&view->plane->damage, |
| 2047 | &view->plane->damage, &damage); |
| 2048 | pixman_region32_fini(&damage); |
| 2049 | pixman_region32_copy(&view->clip, opaque); |
Pekka Paalanen | 8844bf2 | 2015-02-18 16:30:47 +0200 | [diff] [blame] | 2050 | pixman_region32_union(opaque, opaque, &view->transform.opaque); |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2051 | } |
| 2052 | |
Kristian Høgsberg | cce1aec | 2011-04-22 15:38:14 -0400 | [diff] [blame] | 2053 | static void |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2054 | compositor_accumulate_damage(struct weston_compositor *ec) |
| 2055 | { |
| 2056 | struct weston_plane *plane; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2057 | struct weston_view *ev; |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2058 | pixman_region32_t opaque, clip; |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2059 | |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2060 | pixman_region32_init(&clip); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2061 | |
| 2062 | wl_list_for_each(plane, &ec->plane_list, link) { |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2063 | pixman_region32_copy(&plane->clip, &clip); |
| 2064 | |
| 2065 | pixman_region32_init(&opaque); |
| 2066 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2067 | wl_list_for_each(ev, &ec->view_list, link) { |
| 2068 | if (ev->plane != plane) |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2069 | continue; |
| 2070 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2071 | view_accumulate_damage(ev, &opaque); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2072 | } |
| 2073 | |
| 2074 | pixman_region32_union(&clip, &clip, &opaque); |
| 2075 | pixman_region32_fini(&opaque); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2076 | } |
| 2077 | |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2078 | pixman_region32_fini(&clip); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2079 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2080 | wl_list_for_each(ev, &ec->view_list, link) |
Derek Foreman | 060cf11 | 2015-11-18 16:32:26 -0600 | [diff] [blame] | 2081 | ev->surface->touched = false; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2082 | |
| 2083 | wl_list_for_each(ev, &ec->view_list, link) { |
| 2084 | if (ev->surface->touched) |
| 2085 | continue; |
Derek Foreman | 060cf11 | 2015-11-18 16:32:26 -0600 | [diff] [blame] | 2086 | ev->surface->touched = true; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2087 | |
| 2088 | surface_flush_damage(ev->surface); |
| 2089 | |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2090 | /* Both the renderer and the backend have seen the buffer |
| 2091 | * by now. If renderer needs the buffer, it has its own |
| 2092 | * reference set. If the backend wants to keep the buffer |
| 2093 | * around for migrating the surface into a non-primary plane |
| 2094 | * later, keep_buffer is true. Otherwise, drop the core |
| 2095 | * reference now, and allow early buffer release. This enables |
| 2096 | * clients to use single-buffering. |
| 2097 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2098 | if (!ev->surface->keep_buffer) |
| 2099 | weston_buffer_reference(&ev->surface->buffer_ref, NULL); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2100 | } |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2104 | surface_stash_subsurface_views(struct weston_surface *surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2105 | { |
| 2106 | struct weston_subsurface *sub; |
| 2107 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2108 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2109 | if (sub->surface == surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2110 | continue; |
| 2111 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2112 | wl_list_insert_list(&sub->unused_views, &sub->surface->views); |
| 2113 | wl_list_init(&sub->surface->views); |
| 2114 | |
| 2115 | surface_stash_subsurface_views(sub->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2116 | } |
| 2117 | } |
| 2118 | |
| 2119 | static void |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2120 | surface_free_unused_subsurface_views(struct weston_surface *surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2121 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2122 | struct weston_subsurface *sub; |
| 2123 | struct weston_view *view, *nv; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2124 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2125 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
| 2126 | if (sub->surface == surface) |
| 2127 | continue; |
| 2128 | |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 2129 | wl_list_for_each_safe(view, nv, &sub->unused_views, surface_link) { |
| 2130 | weston_view_unmap (view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2131 | weston_view_destroy(view); |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 2132 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2133 | |
| 2134 | surface_free_unused_subsurface_views(sub->surface); |
| 2135 | } |
| 2136 | } |
| 2137 | |
| 2138 | static void |
| 2139 | view_list_add_subsurface_view(struct weston_compositor *compositor, |
| 2140 | struct weston_subsurface *sub, |
| 2141 | struct weston_view *parent) |
| 2142 | { |
| 2143 | struct weston_subsurface *child; |
| 2144 | struct weston_view *view = NULL, *iv; |
| 2145 | |
Pekka Paalanen | 661de3a | 2014-07-28 12:49:24 +0300 | [diff] [blame] | 2146 | if (!weston_surface_is_mapped(sub->surface)) |
| 2147 | return; |
| 2148 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2149 | wl_list_for_each(iv, &sub->unused_views, surface_link) { |
| 2150 | if (iv->geometry.parent == parent) { |
| 2151 | view = iv; |
| 2152 | break; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2153 | } |
| 2154 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2155 | |
| 2156 | if (view) { |
| 2157 | /* Put it back in the surface's list of views */ |
| 2158 | wl_list_remove(&view->surface_link); |
| 2159 | wl_list_insert(&sub->surface->views, &view->surface_link); |
| 2160 | } else { |
| 2161 | view = weston_view_create(sub->surface); |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 2162 | weston_view_set_position(view, |
| 2163 | sub->position.x, |
| 2164 | sub->position.y); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2165 | weston_view_set_transform_parent(view, parent); |
| 2166 | } |
| 2167 | |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 2168 | view->parent_view = parent; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2169 | weston_view_update_transform(view); |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 2170 | view->is_mapped = true; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2171 | |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2172 | if (wl_list_empty(&sub->surface->subsurface_list)) { |
| 2173 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 2174 | return; |
| 2175 | } |
| 2176 | |
| 2177 | wl_list_for_each(child, &sub->surface->subsurface_list, parent_link) { |
| 2178 | if (child->surface == sub->surface) |
| 2179 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 2180 | else |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2181 | view_list_add_subsurface_view(compositor, child, view); |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2182 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2183 | } |
| 2184 | |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 2185 | /* This recursively adds the sub-surfaces for a view, relying on the |
| 2186 | * sub-surface order. Thus, if a client restacks the sub-surfaces, that |
| 2187 | * change first happens to the sub-surface list, and then automatically |
| 2188 | * propagates here. See weston_surface_damage_subsurfaces() for how the |
| 2189 | * sub-surfaces receive damage when the client changes the state. |
| 2190 | */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2191 | static void |
| 2192 | view_list_add(struct weston_compositor *compositor, |
| 2193 | struct weston_view *view) |
| 2194 | { |
| 2195 | struct weston_subsurface *sub; |
| 2196 | |
| 2197 | weston_view_update_transform(view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2198 | |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2199 | if (wl_list_empty(&view->surface->subsurface_list)) { |
| 2200 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 2201 | return; |
| 2202 | } |
| 2203 | |
| 2204 | wl_list_for_each(sub, &view->surface->subsurface_list, parent_link) { |
| 2205 | if (sub->surface == view->surface) |
| 2206 | wl_list_insert(compositor->view_list.prev, &view->link); |
| 2207 | else |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2208 | view_list_add_subsurface_view(compositor, sub, view); |
Pekka Paalanen | b188e91 | 2013-11-19 14:03:35 +0200 | [diff] [blame] | 2209 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2210 | } |
| 2211 | |
| 2212 | static void |
| 2213 | weston_compositor_build_view_list(struct weston_compositor *compositor) |
| 2214 | { |
| 2215 | struct weston_view *view; |
| 2216 | struct weston_layer *layer; |
| 2217 | |
| 2218 | wl_list_for_each(layer, &compositor->layer_list, link) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2219 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2220 | surface_stash_subsurface_views(view->surface); |
| 2221 | |
| 2222 | wl_list_init(&compositor->view_list); |
| 2223 | wl_list_for_each(layer, &compositor->layer_list, link) { |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2224 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2225 | view_list_add(compositor, view); |
| 2226 | } |
| 2227 | } |
| 2228 | |
| 2229 | wl_list_for_each(layer, &compositor->layer_list, link) |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2230 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2231 | surface_free_unused_subsurface_views(view->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2232 | } |
| 2233 | |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2234 | static void |
| 2235 | weston_output_take_feedback_list(struct weston_output *output, |
| 2236 | struct weston_surface *surface) |
| 2237 | { |
| 2238 | struct weston_view *view; |
| 2239 | struct weston_presentation_feedback *feedback; |
| 2240 | uint32_t flags = 0xffffffff; |
| 2241 | |
| 2242 | if (wl_list_empty(&surface->feedback_list)) |
| 2243 | return; |
| 2244 | |
| 2245 | /* All views must have the flag for the flag to survive. */ |
| 2246 | wl_list_for_each(view, &surface->views, surface_link) { |
| 2247 | /* ignore views that are not on this output at all */ |
| 2248 | if (view->output_mask & (1u << output->id)) |
| 2249 | flags &= view->psf_flags; |
| 2250 | } |
| 2251 | |
| 2252 | wl_list_for_each(feedback, &surface->feedback_list, link) |
| 2253 | feedback->psf_flags = flags; |
| 2254 | |
| 2255 | wl_list_insert_list(&output->feedback_list, &surface->feedback_list); |
| 2256 | wl_list_init(&surface->feedback_list); |
| 2257 | } |
| 2258 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2259 | static int |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2260 | weston_output_repaint(struct weston_output *output, void *repaint_data) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2261 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2262 | struct weston_compositor *ec = output->compositor; |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2263 | struct weston_view *ev; |
Kristian Høgsberg | 30c018b | 2012-01-26 08:40:37 -0500 | [diff] [blame] | 2264 | struct weston_animation *animation, *next; |
| 2265 | struct weston_frame_callback *cb, *cnext; |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 2266 | struct wl_list frame_callback_list; |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2267 | pixman_region32_t output_damage; |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2268 | int r; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 2269 | |
Ander Conselvan de Oliveira | e1e2352 | 2013-12-13 22:10:55 +0200 | [diff] [blame] | 2270 | if (output->destroying) |
| 2271 | return 0; |
| 2272 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2273 | TL_POINT("core_repaint_begin", TLP_OUTPUT(output), TLP_END); |
| 2274 | |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2275 | /* Rebuild the surface list and update surface transforms up front. */ |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2276 | weston_compositor_build_view_list(ec); |
Pekka Paalanen | 15d60ef | 2012-01-27 14:38:33 +0200 | [diff] [blame] | 2277 | |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2278 | if (output->assign_planes && !output->disable_planes) { |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2279 | output->assign_planes(output, repaint_data); |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2280 | } else { |
| 2281 | wl_list_for_each(ev, &ec->view_list, link) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2282 | weston_view_move_to_plane(ev, &ec->primary_plane); |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2283 | ev->psf_flags = 0; |
| 2284 | } |
| 2285 | } |
Kristian Høgsberg | 79af73e | 2012-08-03 15:45:23 -0400 | [diff] [blame] | 2286 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2287 | wl_list_init(&frame_callback_list); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2288 | wl_list_for_each(ev, &ec->view_list, link) { |
| 2289 | /* Note: This operation is safe to do multiple times on the |
| 2290 | * same surface. |
| 2291 | */ |
| 2292 | if (ev->surface->output == output) { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2293 | wl_list_insert_list(&frame_callback_list, |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 2294 | &ev->surface->frame_callback_list); |
| 2295 | wl_list_init(&ev->surface->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2296 | |
Pekka Paalanen | bf0e031 | 2014-12-17 16:20:41 +0200 | [diff] [blame] | 2297 | weston_output_take_feedback_list(output, ev->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2298 | } |
| 2299 | } |
| 2300 | |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 2301 | compositor_accumulate_damage(ec); |
Kristian Høgsberg | 53df1d8 | 2011-06-23 21:11:19 -0400 | [diff] [blame] | 2302 | |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 2303 | pixman_region32_init(&output_damage); |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 2304 | pixman_region32_intersect(&output_damage, |
| 2305 | &ec->primary_plane.damage, &output->region); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 2306 | pixman_region32_subtract(&output_damage, |
| 2307 | &output_damage, &ec->primary_plane.clip); |
Ander Conselvan de Oliveira | 4f52173 | 2012-08-15 14:02:05 -0400 | [diff] [blame] | 2308 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 2309 | if (output->dirty) |
| 2310 | weston_output_update_matrix(output); |
| 2311 | |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2312 | r = output->repaint(output, &output_damage, repaint_data); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2313 | |
Kristian Høgsberg | 6ddcdae | 2012-02-28 22:31:58 -0500 | [diff] [blame] | 2314 | pixman_region32_fini(&output_damage); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 2315 | |
Daniel Stone | 09a97e2 | 2017-03-01 11:34:06 +0000 | [diff] [blame] | 2316 | output->repaint_needed = false; |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2317 | if (r == 0) |
| 2318 | output->repaint_status = REPAINT_AWAITING_COMPLETION; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 2319 | |
Kristian Høgsberg | aa6019e | 2012-03-11 16:35:16 -0400 | [diff] [blame] | 2320 | weston_compositor_repick(ec); |
Kristian Høgsberg | aa6019e | 2012-03-11 16:35:16 -0400 | [diff] [blame] | 2321 | |
Jonas Ådahl | db77376 | 2012-06-13 00:01:21 +0200 | [diff] [blame] | 2322 | wl_list_for_each_safe(cb, cnext, &frame_callback_list, link) { |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 2323 | wl_callback_send_done(cb->resource, output->frame_time); |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 2324 | wl_resource_destroy(cb->resource); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 2325 | } |
| 2326 | |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 2327 | wl_list_for_each_safe(animation, next, &output->animation_list, link) { |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 2328 | animation->frame_counter++; |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 2329 | animation->frame(animation, output, output->frame_time); |
Scott Moreau | d64cf21 | 2012-06-08 19:40:54 -0600 | [diff] [blame] | 2330 | } |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2331 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2332 | TL_POINT("core_repaint_posted", TLP_OUTPUT(output), TLP_END); |
| 2333 | |
David Herrmann | 1edf44c | 2013-10-22 17:11:26 +0200 | [diff] [blame] | 2334 | return r; |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2335 | } |
Kristian Høgsberg | b186847 | 2011-04-22 12:27:57 -0400 | [diff] [blame] | 2336 | |
Pekka Paalanen | 8291979 | 2014-05-21 13:51:49 +0300 | [diff] [blame] | 2337 | static void |
| 2338 | weston_output_schedule_repaint_reset(struct weston_output *output) |
| 2339 | { |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2340 | output->repaint_status = REPAINT_NOT_SCHEDULED; |
Pekka Paalanen | 8291979 | 2014-05-21 13:51:49 +0300 | [diff] [blame] | 2341 | TL_POINT("core_repaint_exit_loop", TLP_OUTPUT(output), TLP_END); |
Pekka Paalanen | 8291979 | 2014-05-21 13:51:49 +0300 | [diff] [blame] | 2342 | } |
| 2343 | |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2344 | static int |
| 2345 | weston_output_maybe_repaint(struct weston_output *output, struct timespec *now, |
| 2346 | void *repaint_data) |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2347 | { |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2348 | struct weston_compositor *compositor = output->compositor; |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2349 | int ret = 0; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2350 | int64_t msec_to_repaint; |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2351 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2352 | /* We're not ready yet; come back to make a decision later. */ |
| 2353 | if (output->repaint_status != REPAINT_SCHEDULED) |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2354 | return ret; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2355 | |
| 2356 | msec_to_repaint = timespec_sub_to_msec(&output->next_repaint, now); |
| 2357 | if (msec_to_repaint > 1) |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2358 | return ret; |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2359 | |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 2360 | /* If we're sleeping, drop the repaint machinery entirely; we will |
| 2361 | * explicitly repaint all outputs when we come back. */ |
| 2362 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING || |
| 2363 | compositor->state == WESTON_COMPOSITOR_OFFSCREEN) |
| 2364 | goto err; |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2365 | |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 2366 | /* We don't actually need to repaint this output; drop it from |
| 2367 | * repaint until something causes damage. */ |
| 2368 | if (!output->repaint_needed) |
| 2369 | goto err; |
| 2370 | |
| 2371 | /* If repaint fails, we aren't going to get weston_output_finish_frame |
| 2372 | * to trigger a new repaint, so drop it from repaint and hope |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2373 | * something schedules a successful repaint later. As repainting may |
| 2374 | * take some time, re-read our clock as a courtesy to the next |
| 2375 | * output. */ |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2376 | ret = weston_output_repaint(output, repaint_data); |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2377 | weston_compositor_read_presentation_clock(compositor, now); |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 2378 | if (ret != 0) |
| 2379 | goto err; |
| 2380 | |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2381 | return ret; |
Daniel Stone | cd1a1c3 | 2017-01-16 15:38:54 +0000 | [diff] [blame] | 2382 | |
| 2383 | err: |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2384 | weston_output_schedule_repaint_reset(output); |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2385 | return ret; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2386 | } |
| 2387 | |
| 2388 | static void |
| 2389 | output_repaint_timer_arm(struct weston_compositor *compositor) |
| 2390 | { |
| 2391 | struct weston_output *output; |
| 2392 | bool any_should_repaint = false; |
| 2393 | struct timespec now; |
Sergi Granell | b4c0886 | 2017-03-18 13:01:15 +0100 | [diff] [blame] | 2394 | int64_t msec_to_next = INT64_MAX; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2395 | |
| 2396 | weston_compositor_read_presentation_clock(compositor, &now); |
| 2397 | |
| 2398 | wl_list_for_each(output, &compositor->output_list, link) { |
| 2399 | int64_t msec_to_this; |
| 2400 | |
| 2401 | if (output->repaint_status != REPAINT_SCHEDULED) |
| 2402 | continue; |
| 2403 | |
| 2404 | msec_to_this = timespec_sub_to_msec(&output->next_repaint, |
| 2405 | &now); |
| 2406 | if (!any_should_repaint || msec_to_this < msec_to_next) |
| 2407 | msec_to_next = msec_to_this; |
| 2408 | |
| 2409 | any_should_repaint = true; |
| 2410 | } |
| 2411 | |
| 2412 | if (!any_should_repaint) |
| 2413 | return; |
| 2414 | |
| 2415 | /* Even if we should repaint immediately, add the minimum 1 ms delay. |
| 2416 | * This is a workaround to allow coalescing multiple output repaints |
| 2417 | * particularly from weston_output_finish_frame() |
| 2418 | * into the same call, which would not happen if we called |
| 2419 | * output_repaint_timer_handler() directly. |
| 2420 | */ |
| 2421 | if (msec_to_next < 1) |
| 2422 | msec_to_next = 1; |
| 2423 | |
| 2424 | wl_event_source_timer_update(compositor->repaint_timer, msec_to_next); |
| 2425 | } |
| 2426 | |
| 2427 | static int |
| 2428 | output_repaint_timer_handler(void *data) |
| 2429 | { |
| 2430 | struct weston_compositor *compositor = data; |
| 2431 | struct weston_output *output; |
| 2432 | struct timespec now; |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2433 | void *repaint_data = NULL; |
| 2434 | int ret; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2435 | |
| 2436 | weston_compositor_read_presentation_clock(compositor, &now); |
Daniel Stone | b1f166d | 2017-03-01 11:34:10 +0000 | [diff] [blame] | 2437 | |
| 2438 | if (compositor->backend->repaint_begin) |
| 2439 | repaint_data = compositor->backend->repaint_begin(compositor); |
| 2440 | |
| 2441 | wl_list_for_each(output, &compositor->output_list, link) { |
| 2442 | ret = weston_output_maybe_repaint(output, &now, repaint_data); |
| 2443 | if (ret) |
| 2444 | break; |
| 2445 | } |
| 2446 | |
| 2447 | if (ret == 0) { |
| 2448 | if (compositor->backend->repaint_flush) |
| 2449 | compositor->backend->repaint_flush(compositor, |
| 2450 | repaint_data); |
| 2451 | } else { |
| 2452 | if (compositor->backend->repaint_cancel) |
| 2453 | compositor->backend->repaint_cancel(compositor, |
| 2454 | repaint_data); |
| 2455 | } |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2456 | |
| 2457 | output_repaint_timer_arm(compositor); |
| 2458 | |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2459 | return 0; |
| 2460 | } |
| 2461 | |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2462 | WL_EXPORT void |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 2463 | weston_output_finish_frame(struct weston_output *output, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 2464 | const struct timespec *stamp, |
| 2465 | uint32_t presented_flags) |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2466 | { |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2467 | struct weston_compositor *compositor = output->compositor; |
Pekka Paalanen | 0513a95 | 2014-05-21 16:17:27 +0300 | [diff] [blame] | 2468 | int32_t refresh_nsec; |
| 2469 | struct timespec now; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2470 | int64_t msec_rel; |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2471 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2472 | TL_POINT("core_repaint_finished", TLP_OUTPUT(output), |
| 2473 | TLP_VBLANK(stamp), TLP_END); |
| 2474 | |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2475 | assert(output->repaint_status == REPAINT_AWAITING_COMPLETION); |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2476 | assert(stamp || (presented_flags & WP_PRESENTATION_FEEDBACK_INVALID)); |
| 2477 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2478 | weston_compositor_read_presentation_clock(compositor, &now); |
| 2479 | |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2480 | /* If we haven't been supplied any timestamp at all, we don't have a |
| 2481 | * timebase to work against, so any delay just wastes time. Push a |
| 2482 | * repaint as soon as possible so we can get on with it. */ |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2483 | if (!stamp) { |
| 2484 | output->next_repaint = now; |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2485 | goto out; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2486 | } |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2487 | |
Pekka Paalanen | d7894d0 | 2015-07-03 15:08:53 +0300 | [diff] [blame] | 2488 | refresh_nsec = millihz_to_nsec(output->current_mode->refresh); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 2489 | weston_presentation_feedback_present_list(&output->feedback_list, |
| 2490 | output, refresh_nsec, stamp, |
Pekka Paalanen | 363aa7b | 2014-12-17 16:20:40 +0200 | [diff] [blame] | 2491 | output->msc, |
| 2492 | presented_flags); |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2493 | |
Daniel Stone | 37ad7e3 | 2017-03-01 11:34:02 +0000 | [diff] [blame] | 2494 | output->frame_time = timespec_to_msec(stamp); |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2495 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2496 | timespec_add_nsec(&output->next_repaint, stamp, refresh_nsec); |
| 2497 | timespec_add_msec(&output->next_repaint, &output->next_repaint, |
| 2498 | -compositor->repaint_msec); |
| 2499 | msec_rel = timespec_sub_to_msec(&output->next_repaint, &now); |
Daniel Stone | 84aff5c | 2017-03-01 11:34:04 +0000 | [diff] [blame] | 2500 | |
| 2501 | if (msec_rel < -1000 || msec_rel > 1000) { |
Pekka Paalanen | 8fd4de4 | 2015-03-19 12:27:29 +0200 | [diff] [blame] | 2502 | static bool warned; |
| 2503 | |
| 2504 | if (!warned) |
| 2505 | weston_log("Warning: computed repaint delay is " |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2506 | "insane: %lld msec\n", (long long) msec_rel); |
Pekka Paalanen | 8fd4de4 | 2015-03-19 12:27:29 +0200 | [diff] [blame] | 2507 | warned = true; |
| 2508 | |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2509 | output->next_repaint = now; |
Pekka Paalanen | 8fd4de4 | 2015-03-19 12:27:29 +0200 | [diff] [blame] | 2510 | } |
| 2511 | |
Mario Kleiner | b7df04e | 2015-06-21 21:25:15 +0200 | [diff] [blame] | 2512 | /* Called from restart_repaint_loop and restart happens already after |
| 2513 | * the deadline given by repaint_msec? In that case we delay until |
| 2514 | * the deadline of the next frame, to give clients a more predictable |
| 2515 | * timing of the repaint cycle to lock on. */ |
Daniel Stone | eca5cca | 2017-02-28 21:53:51 +0000 | [diff] [blame] | 2516 | if (presented_flags == WP_PRESENTATION_FEEDBACK_INVALID && |
| 2517 | msec_rel < 0) { |
| 2518 | while (timespec_sub_to_nsec(&output->next_repaint, &now) < 0) { |
| 2519 | timespec_add_nsec(&output->next_repaint, |
| 2520 | &output->next_repaint, |
| 2521 | refresh_nsec); |
| 2522 | } |
| 2523 | } |
Mario Kleiner | b7df04e | 2015-06-21 21:25:15 +0200 | [diff] [blame] | 2524 | |
Daniel Stone | 3615ce1 | 2017-03-01 11:34:05 +0000 | [diff] [blame] | 2525 | out: |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2526 | output->repaint_status = REPAINT_SCHEDULED; |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 2527 | output_repaint_timer_arm(compositor); |
Kristian Høgsberg | 7dbf5e2 | 2012-03-05 19:50:08 -0500 | [diff] [blame] | 2528 | } |
| 2529 | |
| 2530 | static void |
| 2531 | idle_repaint(void *data) |
| 2532 | { |
| 2533 | struct weston_output *output = data; |
| 2534 | |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2535 | assert(output->repaint_status == REPAINT_BEGIN_FROM_IDLE); |
| 2536 | output->repaint_status = REPAINT_AWAITING_COMPLETION; |
Jonas Ådahl | e5a1225 | 2013-04-05 23:07:11 +0200 | [diff] [blame] | 2537 | output->start_repaint_loop(output); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2538 | } |
| 2539 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2540 | WL_EXPORT void |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2541 | weston_layer_entry_insert(struct weston_layer_entry *list, |
| 2542 | struct weston_layer_entry *entry) |
| 2543 | { |
| 2544 | wl_list_insert(&list->link, &entry->link); |
| 2545 | entry->layer = list->layer; |
| 2546 | } |
| 2547 | |
| 2548 | WL_EXPORT void |
| 2549 | weston_layer_entry_remove(struct weston_layer_entry *entry) |
| 2550 | { |
| 2551 | wl_list_remove(&entry->link); |
| 2552 | wl_list_init(&entry->link); |
| 2553 | entry->layer = NULL; |
| 2554 | } |
| 2555 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 2556 | |
| 2557 | /** Initialize the weston_layer struct. |
| 2558 | * |
| 2559 | * \param compositor The compositor instance |
| 2560 | * \param layer The layer to initialize |
| 2561 | */ |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2562 | WL_EXPORT void |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 2563 | weston_layer_init(struct weston_layer *layer, |
| 2564 | struct weston_compositor *compositor) |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2565 | { |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 2566 | layer->compositor = compositor; |
| 2567 | wl_list_init(&layer->link); |
Giulio Camuffo | 412e6a5 | 2014-07-09 22:12:56 +0300 | [diff] [blame] | 2568 | wl_list_init(&layer->view_list.link); |
| 2569 | layer->view_list.layer = layer; |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 2570 | weston_layer_set_mask_infinite(layer); |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 2571 | } |
| 2572 | |
| 2573 | /** Sets the position of the layer in the layer list. The layer will be placed |
| 2574 | * below any layer with the same position value, if any. |
| 2575 | * This function is safe to call if the layer is already on the list, but the |
| 2576 | * layer may be moved below other layers at the same position, if any. |
| 2577 | * |
| 2578 | * \param layer The layer to modify |
| 2579 | * \param position The position the layer will be placed at |
| 2580 | */ |
| 2581 | WL_EXPORT void |
| 2582 | weston_layer_set_position(struct weston_layer *layer, |
| 2583 | enum weston_layer_position position) |
| 2584 | { |
| 2585 | struct weston_layer *below; |
| 2586 | |
| 2587 | wl_list_remove(&layer->link); |
| 2588 | |
| 2589 | /* layer_list is ordered from top to bottom, the last layer being the |
| 2590 | * background with the smallest position value */ |
| 2591 | |
| 2592 | layer->position = position; |
| 2593 | wl_list_for_each_reverse(below, &layer->compositor->layer_list, link) { |
| 2594 | if (below->position >= layer->position) { |
| 2595 | wl_list_insert(&below->link, &layer->link); |
| 2596 | return; |
| 2597 | } |
| 2598 | } |
| 2599 | wl_list_insert(&layer->compositor->layer_list, &layer->link); |
| 2600 | } |
| 2601 | |
| 2602 | /** Hide a layer by taking it off the layer list. |
| 2603 | * This function is safe to call if the layer is not on the list. |
| 2604 | * |
| 2605 | * \param layer The layer to hide |
| 2606 | */ |
| 2607 | WL_EXPORT void |
| 2608 | weston_layer_unset_position(struct weston_layer *layer) |
| 2609 | { |
| 2610 | wl_list_remove(&layer->link); |
| 2611 | wl_list_init(&layer->link); |
Kristian Høgsberg | 3be2ce9 | 2012-02-29 12:42:35 -0500 | [diff] [blame] | 2612 | } |
| 2613 | |
| 2614 | WL_EXPORT void |
Giulio Camuffo | 95ec0f9 | 2014-07-09 22:12:57 +0300 | [diff] [blame] | 2615 | weston_layer_set_mask(struct weston_layer *layer, |
| 2616 | int x, int y, int width, int height) |
| 2617 | { |
| 2618 | struct weston_view *view; |
| 2619 | |
| 2620 | layer->mask.x1 = x; |
| 2621 | layer->mask.x2 = x + width; |
| 2622 | layer->mask.y1 = y; |
| 2623 | layer->mask.y2 = y + height; |
| 2624 | |
| 2625 | wl_list_for_each(view, &layer->view_list.link, layer_link.link) { |
| 2626 | weston_view_geometry_dirty(view); |
| 2627 | } |
| 2628 | } |
| 2629 | |
| 2630 | WL_EXPORT void |
| 2631 | weston_layer_set_mask_infinite(struct weston_layer *layer) |
| 2632 | { |
| 2633 | weston_layer_set_mask(layer, INT32_MIN, INT32_MIN, |
| 2634 | UINT32_MAX, UINT32_MAX); |
| 2635 | } |
| 2636 | |
| 2637 | WL_EXPORT void |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2638 | weston_output_schedule_repaint(struct weston_output *output) |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2639 | { |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2640 | struct weston_compositor *compositor = output->compositor; |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2641 | struct wl_event_loop *loop; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 2642 | |
Bryce Harrington | 08976ac | 2016-08-30 12:05:16 -0700 | [diff] [blame] | 2643 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING || |
| 2644 | compositor->state == WESTON_COMPOSITOR_OFFSCREEN) |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 2645 | return; |
| 2646 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2647 | if (!output->repaint_needed) |
| 2648 | TL_POINT("core_repaint_req", TLP_OUTPUT(output), TLP_END); |
| 2649 | |
Kristian Høgsberg | ef04414 | 2011-06-21 15:02:12 -0400 | [diff] [blame] | 2650 | loop = wl_display_get_event_loop(compositor->wl_display); |
Daniel Stone | 09a97e2 | 2017-03-01 11:34:06 +0000 | [diff] [blame] | 2651 | output->repaint_needed = true; |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2652 | |
| 2653 | /* If we already have a repaint scheduled for our idle handler, |
| 2654 | * no need to set it again. If the repaint has been called but |
| 2655 | * not finished, then weston_output_finish_frame() will notice |
| 2656 | * that a repaint is needed and schedule one. */ |
| 2657 | if (output->repaint_status != REPAINT_NOT_SCHEDULED) |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2658 | return; |
Benjamin Franzke | ec4d342 | 2011-03-14 12:07:26 +0100 | [diff] [blame] | 2659 | |
Daniel Stone | 05df8c1 | 2017-03-03 16:59:42 +0000 | [diff] [blame] | 2660 | output->repaint_status = REPAINT_BEGIN_FROM_IDLE; |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2661 | wl_event_loop_add_idle(loop, idle_repaint, output); |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 2662 | TL_POINT("core_repaint_enter_loop", TLP_OUTPUT(output), TLP_END); |
Kristian Høgsberg | ef7a9ca | 2008-10-11 21:21:39 -0400 | [diff] [blame] | 2663 | } |
Kristian Høgsberg | 5c8c328 | 2009-02-09 15:17:46 -0500 | [diff] [blame] | 2664 | |
Kristian Høgsberg | 02ec0a5 | 2011-04-23 13:04:11 -0400 | [diff] [blame] | 2665 | WL_EXPORT void |
Kristian Høgsberg | 49952d1 | 2012-06-20 00:35:59 -0400 | [diff] [blame] | 2666 | weston_compositor_schedule_repaint(struct weston_compositor *compositor) |
| 2667 | { |
| 2668 | struct weston_output *output; |
| 2669 | |
| 2670 | wl_list_for_each(output, &compositor->output_list, link) |
| 2671 | weston_output_schedule_repaint(output); |
| 2672 | } |
| 2673 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 2674 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 2675 | surface_destroy(struct wl_client *client, struct wl_resource *resource) |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 2676 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 2677 | wl_resource_destroy(resource); |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 2678 | } |
| 2679 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 2680 | static void |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2681 | surface_attach(struct wl_client *client, |
| 2682 | struct wl_resource *resource, |
| 2683 | struct wl_resource *buffer_resource, int32_t sx, int32_t sy) |
| 2684 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2685 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2686 | struct weston_buffer *buffer = NULL; |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2687 | |
Kristian Høgsberg | ab19f93 | 2013-08-20 11:30:54 -0700 | [diff] [blame] | 2688 | if (buffer_resource) { |
Jason Ekstrand | 6bd6294 | 2013-06-20 20:38:23 -0500 | [diff] [blame] | 2689 | buffer = weston_buffer_from_resource(buffer_resource); |
Kristian Høgsberg | ab19f93 | 2013-08-20 11:30:54 -0700 | [diff] [blame] | 2690 | if (buffer == NULL) { |
| 2691 | wl_client_post_no_memory(client); |
| 2692 | return; |
| 2693 | } |
Kristian Høgsberg | 08b58c7 | 2013-08-15 12:26:42 -0700 | [diff] [blame] | 2694 | } |
Kristian Høgsberg | a691aee | 2011-06-23 21:43:50 -0400 | [diff] [blame] | 2695 | |
Pekka Paalanen | de685b8 | 2012-12-04 15:58:12 +0200 | [diff] [blame] | 2696 | /* Attach, attach, without commit in between does not send |
| 2697 | * wl_buffer.release. */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 2698 | weston_surface_state_set_buffer(&surface->pending, buffer); |
Ander Conselvan de Oliveira | e11683a | 2012-03-27 17:36:40 +0300 | [diff] [blame] | 2699 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2700 | surface->pending.sx = sx; |
| 2701 | surface->pending.sy = sy; |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 2702 | surface->pending.newly_attached = 1; |
Kristian Høgsberg | f921289 | 2008-10-11 18:40:23 -0400 | [diff] [blame] | 2703 | } |
| 2704 | |
Kristian Høgsberg | 5503bf8 | 2008-11-06 10:38:17 -0500 | [diff] [blame] | 2705 | static void |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2706 | surface_damage(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 2707 | struct wl_resource *resource, |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 2708 | 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] | 2709 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2710 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 9d69f8e | 2010-09-03 14:46:38 -0400 | [diff] [blame] | 2711 | |
Derek Foreman | 57e92ed | 2015-11-17 14:11:35 -0600 | [diff] [blame] | 2712 | if (width <= 0 || height <= 0) |
| 2713 | return; |
| 2714 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 2715 | pixman_region32_union_rect(&surface->pending.damage_surface, |
| 2716 | &surface->pending.damage_surface, |
| 2717 | x, y, width, height); |
| 2718 | } |
| 2719 | |
| 2720 | static void |
| 2721 | surface_damage_buffer(struct wl_client *client, |
| 2722 | struct wl_resource *resource, |
| 2723 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 2724 | { |
| 2725 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
| 2726 | |
| 2727 | if (width <= 0 || height <= 0) |
| 2728 | return; |
| 2729 | |
| 2730 | pixman_region32_union_rect(&surface->pending.damage_buffer, |
| 2731 | &surface->pending.damage_buffer, |
Kristian Høgsberg | 460a79b | 2012-06-18 15:09:11 -0400 | [diff] [blame] | 2732 | x, y, width, height); |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 2733 | } |
| 2734 | |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2735 | static void |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 2736 | destroy_frame_callback(struct wl_resource *resource) |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2737 | { |
Jason Ekstrand | fbbbec8 | 2013-06-14 10:07:57 -0500 | [diff] [blame] | 2738 | struct weston_frame_callback *cb = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 2739 | |
| 2740 | wl_list_remove(&cb->link); |
Pekka Paalanen | 8c19645 | 2011-11-15 11:45:42 +0200 | [diff] [blame] | 2741 | free(cb); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2742 | } |
| 2743 | |
| 2744 | static void |
| 2745 | surface_frame(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 2746 | struct wl_resource *resource, uint32_t callback) |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2747 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 2748 | struct weston_frame_callback *cb; |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2749 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2750 | |
| 2751 | cb = malloc(sizeof *cb); |
| 2752 | if (cb == NULL) { |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 2753 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2754 | return; |
| 2755 | } |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 2756 | |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 2757 | cb->resource = wl_resource_create(client, &wl_callback_interface, 1, |
| 2758 | callback); |
| 2759 | if (cb->resource == NULL) { |
| 2760 | free(cb); |
| 2761 | wl_resource_post_no_memory(resource); |
| 2762 | return; |
| 2763 | } |
| 2764 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 2765 | wl_resource_set_implementation(cb->resource, NULL, cb, |
| 2766 | destroy_frame_callback); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2767 | |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 2768 | wl_list_insert(surface->pending.frame_callback_list.prev, &cb->link); |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 2769 | } |
| 2770 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2771 | static void |
| 2772 | surface_set_opaque_region(struct wl_client *client, |
| 2773 | struct wl_resource *resource, |
| 2774 | struct wl_resource *region_resource) |
| 2775 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2776 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2777 | struct weston_region *region; |
| 2778 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2779 | if (region_resource) { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 2780 | region = wl_resource_get_user_data(region_resource); |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 2781 | pixman_region32_copy(&surface->pending.opaque, |
| 2782 | ®ion->region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2783 | } else { |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 2784 | pixman_region32_clear(&surface->pending.opaque); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2785 | } |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2786 | } |
| 2787 | |
| 2788 | static void |
| 2789 | surface_set_input_region(struct wl_client *client, |
| 2790 | struct wl_resource *resource, |
| 2791 | struct wl_resource *region_resource) |
| 2792 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 2793 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 010f98b | 2012-02-23 17:30:45 -0500 | [diff] [blame] | 2794 | struct weston_region *region; |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2795 | |
| 2796 | if (region_resource) { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 2797 | region = wl_resource_get_user_data(region_resource); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 2798 | pixman_region32_copy(&surface->pending.input, |
| 2799 | ®ion->region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2800 | } else { |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 2801 | pixman_region32_fini(&surface->pending.input); |
| 2802 | region_init_infinite(&surface->pending.input); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2803 | } |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 2804 | } |
| 2805 | |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 2806 | /* Cause damage to this sub-surface and all its children. |
| 2807 | * |
| 2808 | * This is useful when there are state changes that need an implicit |
| 2809 | * damage, e.g. a z-order change. |
| 2810 | */ |
| 2811 | static void |
| 2812 | weston_surface_damage_subsurfaces(struct weston_subsurface *sub) |
| 2813 | { |
| 2814 | struct weston_subsurface *child; |
| 2815 | |
| 2816 | weston_surface_damage(sub->surface); |
| 2817 | sub->reordered = false; |
| 2818 | |
| 2819 | wl_list_for_each(child, &sub->surface->subsurface_list, parent_link) |
| 2820 | if (child != sub) |
| 2821 | weston_surface_damage_subsurfaces(child); |
| 2822 | } |
| 2823 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2824 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2825 | weston_surface_commit_subsurface_order(struct weston_surface *surface) |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 2826 | { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2827 | struct weston_subsurface *sub; |
| 2828 | |
| 2829 | wl_list_for_each_reverse(sub, &surface->subsurface_list_pending, |
| 2830 | parent_link_pending) { |
| 2831 | wl_list_remove(&sub->parent_link); |
| 2832 | wl_list_insert(&surface->subsurface_list, &sub->parent_link); |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 2833 | |
| 2834 | if (sub->reordered) |
| 2835 | weston_surface_damage_subsurfaces(sub); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 2836 | } |
| 2837 | } |
| 2838 | |
| 2839 | static void |
Pekka Paalanen | 04baea5 | 2016-04-26 15:50:58 +0300 | [diff] [blame] | 2840 | weston_surface_build_buffer_matrix(const struct weston_surface *surface, |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 2841 | struct weston_matrix *matrix) |
| 2842 | { |
Pekka Paalanen | 04baea5 | 2016-04-26 15:50:58 +0300 | [diff] [blame] | 2843 | const struct weston_buffer_viewport *vp = &surface->buffer_viewport; |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 2844 | double src_width, src_height, dest_width, dest_height; |
| 2845 | |
| 2846 | weston_matrix_init(matrix); |
| 2847 | |
| 2848 | if (vp->buffer.src_width == wl_fixed_from_int(-1)) { |
| 2849 | src_width = surface->width_from_buffer; |
| 2850 | src_height = surface->height_from_buffer; |
| 2851 | } else { |
| 2852 | src_width = wl_fixed_to_double(vp->buffer.src_width); |
| 2853 | src_height = wl_fixed_to_double(vp->buffer.src_height); |
| 2854 | } |
| 2855 | |
| 2856 | if (vp->surface.width == -1) { |
| 2857 | dest_width = src_width; |
| 2858 | dest_height = src_height; |
| 2859 | } else { |
| 2860 | dest_width = vp->surface.width; |
| 2861 | dest_height = vp->surface.height; |
| 2862 | } |
| 2863 | |
| 2864 | if (src_width != dest_width || src_height != dest_height) |
| 2865 | weston_matrix_scale(matrix, |
| 2866 | src_width / dest_width, |
| 2867 | src_height / dest_height, 1); |
| 2868 | |
| 2869 | if (vp->buffer.src_width != wl_fixed_from_int(-1)) |
| 2870 | weston_matrix_translate(matrix, |
| 2871 | wl_fixed_to_double(vp->buffer.src_x), |
| 2872 | wl_fixed_to_double(vp->buffer.src_y), |
| 2873 | 0); |
| 2874 | |
| 2875 | switch (vp->buffer.transform) { |
| 2876 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 2877 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 2878 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 2879 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 2880 | weston_matrix_scale(matrix, -1, 1, 1); |
| 2881 | weston_matrix_translate(matrix, |
| 2882 | surface->width_from_buffer, 0, 0); |
| 2883 | break; |
| 2884 | } |
| 2885 | |
| 2886 | switch (vp->buffer.transform) { |
| 2887 | default: |
| 2888 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 2889 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 2890 | break; |
| 2891 | case WL_OUTPUT_TRANSFORM_90: |
| 2892 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 2893 | weston_matrix_rotate_xy(matrix, 0, 1); |
| 2894 | weston_matrix_translate(matrix, |
| 2895 | surface->height_from_buffer, 0, 0); |
| 2896 | break; |
| 2897 | case WL_OUTPUT_TRANSFORM_180: |
| 2898 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 2899 | weston_matrix_rotate_xy(matrix, -1, 0); |
| 2900 | weston_matrix_translate(matrix, |
| 2901 | surface->width_from_buffer, |
| 2902 | surface->height_from_buffer, 0); |
| 2903 | break; |
| 2904 | case WL_OUTPUT_TRANSFORM_270: |
| 2905 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 2906 | weston_matrix_rotate_xy(matrix, 0, -1); |
| 2907 | weston_matrix_translate(matrix, |
| 2908 | 0, surface->width_from_buffer, 0); |
| 2909 | break; |
| 2910 | } |
| 2911 | |
| 2912 | weston_matrix_scale(matrix, vp->buffer.scale, vp->buffer.scale, 1); |
| 2913 | } |
| 2914 | |
Pekka Paalanen | d9aae9c | 2016-04-26 13:46:38 +0300 | [diff] [blame] | 2915 | /** |
| 2916 | * Compute a + b > c while being safe to overflows. |
| 2917 | */ |
| 2918 | static bool |
| 2919 | fixed_sum_gt(wl_fixed_t a, wl_fixed_t b, wl_fixed_t c) |
| 2920 | { |
| 2921 | return (int64_t)a + (int64_t)b > (int64_t)c; |
| 2922 | } |
| 2923 | |
| 2924 | static bool |
| 2925 | weston_surface_is_pending_viewport_source_valid( |
| 2926 | const struct weston_surface *surface) |
| 2927 | { |
| 2928 | const struct weston_surface_state *pend = &surface->pending; |
| 2929 | const struct weston_buffer_viewport *vp = &pend->buffer_viewport; |
| 2930 | int width_from_buffer = 0; |
| 2931 | int height_from_buffer = 0; |
| 2932 | wl_fixed_t w; |
| 2933 | wl_fixed_t h; |
| 2934 | |
| 2935 | /* If viewport source rect is not set, it is always ok. */ |
| 2936 | if (vp->buffer.src_width == wl_fixed_from_int(-1)) |
| 2937 | return true; |
| 2938 | |
| 2939 | if (pend->newly_attached) { |
| 2940 | if (pend->buffer) { |
| 2941 | convert_size_by_transform_scale(&width_from_buffer, |
| 2942 | &height_from_buffer, |
| 2943 | pend->buffer->width, |
| 2944 | pend->buffer->height, |
| 2945 | vp->buffer.transform, |
| 2946 | vp->buffer.scale); |
| 2947 | } else { |
| 2948 | /* No buffer: viewport is irrelevant. */ |
| 2949 | return true; |
| 2950 | } |
| 2951 | } else { |
| 2952 | width_from_buffer = surface->width_from_buffer; |
| 2953 | height_from_buffer = surface->height_from_buffer; |
| 2954 | } |
| 2955 | |
| 2956 | assert((width_from_buffer == 0) == (height_from_buffer == 0)); |
| 2957 | assert(width_from_buffer >= 0 && height_from_buffer >= 0); |
| 2958 | |
| 2959 | /* No buffer: viewport is irrelevant. */ |
| 2960 | if (width_from_buffer == 0 || height_from_buffer == 0) |
| 2961 | return true; |
| 2962 | |
| 2963 | /* overflow checks for wl_fixed_from_int() */ |
| 2964 | if (width_from_buffer > wl_fixed_to_int(INT32_MAX)) |
| 2965 | return false; |
| 2966 | if (height_from_buffer > wl_fixed_to_int(INT32_MAX)) |
| 2967 | return false; |
| 2968 | |
| 2969 | w = wl_fixed_from_int(width_from_buffer); |
| 2970 | h = wl_fixed_from_int(height_from_buffer); |
| 2971 | |
| 2972 | if (fixed_sum_gt(vp->buffer.src_x, vp->buffer.src_width, w)) |
| 2973 | return false; |
| 2974 | if (fixed_sum_gt(vp->buffer.src_y, vp->buffer.src_height, h)) |
| 2975 | return false; |
| 2976 | |
| 2977 | return true; |
| 2978 | } |
| 2979 | |
Pekka Paalanen | bb32ccc | 2016-04-26 14:28:28 +0300 | [diff] [blame] | 2980 | static bool |
| 2981 | fixed_is_integer(wl_fixed_t v) |
| 2982 | { |
| 2983 | return (v & 0xff) == 0; |
| 2984 | } |
| 2985 | |
| 2986 | static bool |
| 2987 | weston_surface_is_pending_viewport_dst_size_int( |
| 2988 | const struct weston_surface *surface) |
| 2989 | { |
| 2990 | const struct weston_buffer_viewport *vp = |
| 2991 | &surface->pending.buffer_viewport; |
| 2992 | |
| 2993 | if (vp->surface.width != -1) { |
| 2994 | assert(vp->surface.width > 0 && vp->surface.height > 0); |
| 2995 | return true; |
| 2996 | } |
| 2997 | |
| 2998 | return fixed_is_integer(vp->buffer.src_width) && |
| 2999 | fixed_is_integer(vp->buffer.src_height); |
| 3000 | } |
| 3001 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3002 | /* Translate pending damage in buffer co-ordinates to surface |
| 3003 | * co-ordinates and union it with a pixman_region32_t. |
| 3004 | * This should only be called after the buffer is attached. |
| 3005 | */ |
| 3006 | static void |
| 3007 | apply_damage_buffer(pixman_region32_t *dest, |
| 3008 | struct weston_surface *surface, |
| 3009 | struct weston_surface_state *state) |
| 3010 | { |
| 3011 | struct weston_buffer *buffer = surface->buffer_ref.buffer; |
| 3012 | |
| 3013 | /* wl_surface.damage_buffer needs to be clipped to the buffer, |
| 3014 | * translated into surface co-ordinates and unioned with |
| 3015 | * any other surface damage. |
| 3016 | * None of this makes sense if there is no buffer though. |
| 3017 | */ |
| 3018 | if (buffer && pixman_region32_not_empty(&state->damage_buffer)) { |
| 3019 | pixman_region32_t buffer_damage; |
| 3020 | |
| 3021 | pixman_region32_intersect_rect(&state->damage_buffer, |
| 3022 | &state->damage_buffer, |
| 3023 | 0, 0, buffer->width, |
| 3024 | buffer->height); |
| 3025 | pixman_region32_init(&buffer_damage); |
| 3026 | weston_matrix_transform_region(&buffer_damage, |
| 3027 | &surface->buffer_to_surface_matrix, |
| 3028 | &state->damage_buffer); |
| 3029 | pixman_region32_union(dest, dest, &buffer_damage); |
| 3030 | pixman_region32_fini(&buffer_damage); |
| 3031 | } |
| 3032 | /* We should clear this on commit even if there was no buffer */ |
| 3033 | pixman_region32_clear(&state->damage_buffer); |
| 3034 | } |
| 3035 | |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 3036 | static void |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3037 | weston_surface_commit_state(struct weston_surface *surface, |
| 3038 | struct weston_surface_state *state) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3039 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3040 | struct weston_view *view; |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 3041 | pixman_region32_t opaque; |
| 3042 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3043 | /* wl_surface.set_buffer_transform */ |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3044 | /* wl_surface.set_buffer_scale */ |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 3045 | /* wp_viewport.set_source */ |
| 3046 | /* wp_viewport.set_destination */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3047 | surface->buffer_viewport = state->buffer_viewport; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3048 | |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3049 | /* wl_surface.attach */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3050 | if (state->newly_attached) |
| 3051 | weston_surface_attach(surface, state->buffer); |
| 3052 | weston_surface_state_set_buffer(state, NULL); |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3053 | |
Jason Ekstrand | 1e05904 | 2014-10-16 10:55:19 -0500 | [diff] [blame] | 3054 | weston_surface_build_buffer_matrix(surface, |
| 3055 | &surface->surface_to_buffer_matrix); |
| 3056 | weston_matrix_invert(&surface->buffer_to_surface_matrix, |
| 3057 | &surface->surface_to_buffer_matrix); |
| 3058 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3059 | if (state->newly_attached || state->buffer_viewport.changed) { |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3060 | weston_surface_update_size(surface); |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3061 | if (surface->committed) |
| 3062 | surface->committed(surface, state->sx, state->sy); |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3063 | } |
Giulio Camuffo | 184df50 | 2013-02-21 11:29:21 +0100 | [diff] [blame] | 3064 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3065 | state->sx = 0; |
| 3066 | state->sy = 0; |
| 3067 | state->newly_attached = 0; |
| 3068 | state->buffer_viewport.changed = 0; |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 3069 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3070 | /* wl_surface.damage and wl_surface.damage_buffer */ |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3071 | if (weston_timeline_enabled_ && |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3072 | (pixman_region32_not_empty(&state->damage_surface) || |
| 3073 | pixman_region32_not_empty(&state->damage_buffer))) |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3074 | TL_POINT("core_commit_damage", TLP_SURFACE(surface), TLP_END); |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3075 | |
Pekka Paalanen | 8e15918 | 2012-10-10 12:49:25 +0300 | [diff] [blame] | 3076 | pixman_region32_union(&surface->damage, &surface->damage, |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3077 | &state->damage_surface); |
| 3078 | |
| 3079 | apply_damage_buffer(&surface->damage, surface, state); |
| 3080 | |
Kristian Høgsberg | 4d0214c | 2012-11-08 11:36:02 -0500 | [diff] [blame] | 3081 | pixman_region32_intersect_rect(&surface->damage, &surface->damage, |
Jason Ekstrand | ef54008 | 2014-06-26 10:37:36 -0700 | [diff] [blame] | 3082 | 0, 0, surface->width, surface->height); |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3083 | pixman_region32_clear(&state->damage_surface); |
Pekka Paalanen | 512dde8 | 2012-10-10 12:49:27 +0300 | [diff] [blame] | 3084 | |
| 3085 | /* wl_surface.set_opaque_region */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3086 | pixman_region32_init(&opaque); |
| 3087 | pixman_region32_intersect_rect(&opaque, &state->opaque, |
| 3088 | 0, 0, surface->width, surface->height); |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 3089 | |
| 3090 | if (!pixman_region32_equal(&opaque, &surface->opaque)) { |
| 3091 | pixman_region32_copy(&surface->opaque, &opaque); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3092 | wl_list_for_each(view, &surface->views, surface_link) |
| 3093 | weston_view_geometry_dirty(view); |
Ander Conselvan de Oliveira | 5df8eca | 2012-10-30 17:44:01 +0200 | [diff] [blame] | 3094 | } |
| 3095 | |
| 3096 | pixman_region32_fini(&opaque); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3097 | |
| 3098 | /* wl_surface.set_input_region */ |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3099 | pixman_region32_intersect_rect(&surface->input, &state->input, |
| 3100 | 0, 0, surface->width, surface->height); |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3101 | |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 3102 | /* wl_surface.frame */ |
| 3103 | wl_list_insert_list(&surface->frame_callback_list, |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3104 | &state->frame_callback_list); |
| 3105 | wl_list_init(&state->frame_callback_list); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3106 | |
| 3107 | /* XXX: |
| 3108 | * What should happen with a feedback request, if there |
| 3109 | * is no wl_buffer attached for this commit? |
| 3110 | */ |
| 3111 | |
| 3112 | /* presentation.feedback */ |
| 3113 | wl_list_insert_list(&surface->feedback_list, |
| 3114 | &state->feedback_list); |
| 3115 | wl_list_init(&state->feedback_list); |
Jonas Ådahl | 5d9ca27 | 2016-07-22 17:48:03 +0800 | [diff] [blame] | 3116 | |
| 3117 | wl_signal_emit(&surface->commit_signal, surface); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3118 | } |
| 3119 | |
| 3120 | static void |
| 3121 | weston_surface_commit(struct weston_surface *surface) |
| 3122 | { |
| 3123 | weston_surface_commit_state(surface, &surface->pending); |
Pekka Paalanen | bc10638 | 2012-10-10 12:49:31 +0300 | [diff] [blame] | 3124 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3125 | weston_surface_commit_subsurface_order(surface); |
| 3126 | |
Pekka Paalanen | 0cbd3b5 | 2012-10-10 12:49:28 +0300 | [diff] [blame] | 3127 | weston_surface_schedule_repaint(surface); |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3128 | } |
| 3129 | |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3130 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3131 | weston_subsurface_commit(struct weston_subsurface *sub); |
| 3132 | |
| 3133 | static void |
| 3134 | weston_subsurface_parent_commit(struct weston_subsurface *sub, |
| 3135 | int parent_is_synchronized); |
| 3136 | |
| 3137 | static void |
| 3138 | surface_commit(struct wl_client *client, struct wl_resource *resource) |
| 3139 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3140 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3141 | struct weston_subsurface *sub = weston_surface_to_subsurface(surface); |
| 3142 | |
Pekka Paalanen | d9aae9c | 2016-04-26 13:46:38 +0300 | [diff] [blame] | 3143 | if (!weston_surface_is_pending_viewport_source_valid(surface)) { |
| 3144 | assert(surface->viewport_resource); |
| 3145 | |
| 3146 | wl_resource_post_error(surface->viewport_resource, |
| 3147 | WP_VIEWPORT_ERROR_OUT_OF_BUFFER, |
| 3148 | "wl_surface@%d has viewport source outside buffer", |
| 3149 | wl_resource_get_id(resource)); |
| 3150 | return; |
| 3151 | } |
| 3152 | |
Pekka Paalanen | bb32ccc | 2016-04-26 14:28:28 +0300 | [diff] [blame] | 3153 | if (!weston_surface_is_pending_viewport_dst_size_int(surface)) { |
| 3154 | assert(surface->viewport_resource); |
| 3155 | |
| 3156 | wl_resource_post_error(surface->viewport_resource, |
| 3157 | WP_VIEWPORT_ERROR_BAD_SIZE, |
| 3158 | "wl_surface@%d viewport dst size not integer", |
| 3159 | wl_resource_get_id(resource)); |
| 3160 | return; |
| 3161 | } |
| 3162 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3163 | if (sub) { |
| 3164 | weston_subsurface_commit(sub); |
| 3165 | return; |
| 3166 | } |
| 3167 | |
| 3168 | weston_surface_commit(surface); |
| 3169 | |
| 3170 | wl_list_for_each(sub, &surface->subsurface_list, parent_link) { |
| 3171 | if (sub->surface != surface) |
| 3172 | weston_subsurface_parent_commit(sub, 0); |
| 3173 | } |
| 3174 | } |
| 3175 | |
| 3176 | static void |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3177 | surface_set_buffer_transform(struct wl_client *client, |
| 3178 | struct wl_resource *resource, int transform) |
| 3179 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3180 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3181 | |
Jonny Lamb | a55f139 | 2014-05-30 12:07:15 +0200 | [diff] [blame] | 3182 | /* if wl_output.transform grows more members this will need to be updated. */ |
| 3183 | if (transform < 0 || |
| 3184 | transform > WL_OUTPUT_TRANSFORM_FLIPPED_270) { |
| 3185 | wl_resource_post_error(resource, |
| 3186 | WL_SURFACE_ERROR_INVALID_TRANSFORM, |
| 3187 | "buffer transform must be a valid transform " |
| 3188 | "('%d' specified)", transform); |
| 3189 | return; |
| 3190 | } |
| 3191 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 3192 | surface->pending.buffer_viewport.buffer.transform = transform; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3193 | surface->pending.buffer_viewport.changed = 1; |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3194 | } |
| 3195 | |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3196 | static void |
| 3197 | surface_set_buffer_scale(struct wl_client *client, |
| 3198 | struct wl_resource *resource, |
Alexander Larsson | edddbd1 | 2013-05-24 13:09:43 +0200 | [diff] [blame] | 3199 | int32_t scale) |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3200 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3201 | struct weston_surface *surface = wl_resource_get_user_data(resource); |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3202 | |
Jonny Lamb | a55f139 | 2014-05-30 12:07:15 +0200 | [diff] [blame] | 3203 | if (scale < 1) { |
| 3204 | wl_resource_post_error(resource, |
| 3205 | WL_SURFACE_ERROR_INVALID_SCALE, |
| 3206 | "buffer scale must be at least one " |
| 3207 | "('%d' specified)", scale); |
| 3208 | return; |
| 3209 | } |
| 3210 | |
Pekka Paalanen | 952b6c8 | 2014-03-14 14:38:15 +0200 | [diff] [blame] | 3211 | surface->pending.buffer_viewport.buffer.scale = scale; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3212 | surface->pending.buffer_viewport.changed = 1; |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3213 | } |
| 3214 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 3215 | static const struct wl_surface_interface surface_interface = { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3216 | surface_destroy, |
| 3217 | surface_attach, |
Kristian Høgsberg | 3341820 | 2011-08-16 23:01:28 -0400 | [diff] [blame] | 3218 | surface_damage, |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3219 | surface_frame, |
| 3220 | surface_set_opaque_region, |
Pekka Paalanen | 5df44de | 2012-10-10 12:49:23 +0300 | [diff] [blame] | 3221 | surface_set_input_region, |
Ander Conselvan de Oliveira | 012b4c7 | 2012-11-27 17:03:42 +0200 | [diff] [blame] | 3222 | surface_commit, |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 3223 | surface_set_buffer_transform, |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3224 | surface_set_buffer_scale, |
| 3225 | surface_damage_buffer |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3226 | }; |
| 3227 | |
| 3228 | static void |
| 3229 | compositor_create_surface(struct wl_client *client, |
Kristian Høgsberg | 904055a | 2011-08-18 17:55:30 -0400 | [diff] [blame] | 3230 | struct wl_resource *resource, uint32_t id) |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3231 | { |
Kristian Høgsberg | c2d7042 | 2013-06-25 15:34:33 -0400 | [diff] [blame] | 3232 | struct weston_compositor *ec = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 3233 | struct weston_surface *surface; |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3234 | |
Kristian Høgsberg | 18c9300 | 2012-01-27 11:58:31 -0500 | [diff] [blame] | 3235 | surface = weston_surface_create(ec); |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 3236 | if (surface == NULL) { |
Kristian Høgsberg | 9ebcf94 | 2011-09-01 09:54:57 -0400 | [diff] [blame] | 3237 | wl_resource_post_no_memory(resource); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3238 | return; |
Kristian Høgsberg | 5fcd0aa | 2010-08-09 14:43:33 -0400 | [diff] [blame] | 3239 | } |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3240 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3241 | surface->resource = |
| 3242 | wl_resource_create(client, &wl_surface_interface, |
| 3243 | wl_resource_get_version(resource), id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 3244 | if (surface->resource == NULL) { |
| 3245 | weston_surface_destroy(surface); |
| 3246 | wl_resource_post_no_memory(resource); |
| 3247 | return; |
| 3248 | } |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3249 | wl_resource_set_implementation(surface->resource, &surface_interface, |
| 3250 | surface, destroy_surface); |
Kristian Høgsberg | f03a04a | 2014-04-06 22:04:50 -0700 | [diff] [blame] | 3251 | |
| 3252 | wl_signal_emit(&ec->create_surface_signal, surface); |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3253 | } |
| 3254 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3255 | static void |
| 3256 | destroy_region(struct wl_resource *resource) |
| 3257 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 3258 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3259 | |
| 3260 | pixman_region32_fini(®ion->region); |
| 3261 | free(region); |
| 3262 | } |
| 3263 | |
| 3264 | static void |
| 3265 | region_destroy(struct wl_client *client, struct wl_resource *resource) |
| 3266 | { |
Kristian Høgsberg | eae5de7 | 2012-04-11 22:42:15 -0400 | [diff] [blame] | 3267 | wl_resource_destroy(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3268 | } |
| 3269 | |
| 3270 | static void |
| 3271 | region_add(struct wl_client *client, struct wl_resource *resource, |
| 3272 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 3273 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 3274 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3275 | |
| 3276 | pixman_region32_union_rect(®ion->region, ®ion->region, |
| 3277 | x, y, width, height); |
| 3278 | } |
| 3279 | |
| 3280 | static void |
| 3281 | region_subtract(struct wl_client *client, struct wl_resource *resource, |
| 3282 | int32_t x, int32_t y, int32_t width, int32_t height) |
| 3283 | { |
Jason Ekstrand | 8895efc | 2013-06-14 10:07:56 -0500 | [diff] [blame] | 3284 | struct weston_region *region = wl_resource_get_user_data(resource); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3285 | pixman_region32_t rect; |
| 3286 | |
| 3287 | pixman_region32_init_rect(&rect, x, y, width, height); |
| 3288 | pixman_region32_subtract(®ion->region, ®ion->region, &rect); |
| 3289 | pixman_region32_fini(&rect); |
| 3290 | } |
| 3291 | |
| 3292 | static const struct wl_region_interface region_interface = { |
| 3293 | region_destroy, |
| 3294 | region_add, |
| 3295 | region_subtract |
| 3296 | }; |
| 3297 | |
| 3298 | static void |
| 3299 | compositor_create_region(struct wl_client *client, |
| 3300 | struct wl_resource *resource, uint32_t id) |
| 3301 | { |
| 3302 | struct weston_region *region; |
| 3303 | |
| 3304 | region = malloc(sizeof *region); |
| 3305 | if (region == NULL) { |
| 3306 | wl_resource_post_no_memory(resource); |
| 3307 | return; |
| 3308 | } |
| 3309 | |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3310 | pixman_region32_init(®ion->region); |
| 3311 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3312 | region->resource = |
| 3313 | wl_resource_create(client, &wl_region_interface, 1, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 3314 | if (region->resource == NULL) { |
| 3315 | free(region); |
| 3316 | wl_resource_post_no_memory(resource); |
| 3317 | return; |
| 3318 | } |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3319 | wl_resource_set_implementation(region->resource, ®ion_interface, |
| 3320 | region, destroy_region); |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3321 | } |
| 3322 | |
Kristian Høgsberg | 875ab9e | 2012-03-30 11:52:39 -0400 | [diff] [blame] | 3323 | static const struct wl_compositor_interface compositor_interface = { |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3324 | compositor_create_surface, |
Kristian Høgsberg | 5e7e6f2 | 2012-02-23 16:11:59 -0500 | [diff] [blame] | 3325 | compositor_create_region |
Kristian Høgsberg | d2412e2 | 2008-12-15 20:35:24 -0500 | [diff] [blame] | 3326 | }; |
| 3327 | |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 3328 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3329 | weston_subsurface_commit_from_cache(struct weston_subsurface *sub) |
| 3330 | { |
| 3331 | struct weston_surface *surface = sub->surface; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3332 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3333 | weston_surface_commit_state(surface, &sub->cached); |
| 3334 | weston_buffer_reference(&sub->cached_buffer_ref, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3335 | |
| 3336 | weston_surface_commit_subsurface_order(surface); |
| 3337 | |
| 3338 | weston_surface_schedule_repaint(surface); |
| 3339 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3340 | sub->has_cached_data = 0; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3341 | } |
| 3342 | |
| 3343 | static void |
| 3344 | weston_subsurface_commit_to_cache(struct weston_subsurface *sub) |
| 3345 | { |
| 3346 | struct weston_surface *surface = sub->surface; |
| 3347 | |
| 3348 | /* |
| 3349 | * If this commit would cause the surface to move by the |
| 3350 | * attach(dx, dy) parameters, the old damage region must be |
| 3351 | * translated to correspond to the new surface coordinate system |
Chris Michael | 062edf2 | 2015-11-26 11:30:00 -0500 | [diff] [blame] | 3352 | * origin. |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3353 | */ |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3354 | pixman_region32_translate(&sub->cached.damage_surface, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3355 | -surface->pending.sx, -surface->pending.sy); |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3356 | pixman_region32_union(&sub->cached.damage_surface, |
| 3357 | &sub->cached.damage_surface, |
| 3358 | &surface->pending.damage_surface); |
| 3359 | pixman_region32_clear(&surface->pending.damage_surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3360 | |
| 3361 | if (surface->pending.newly_attached) { |
| 3362 | sub->cached.newly_attached = 1; |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3363 | weston_surface_state_set_buffer(&sub->cached, |
| 3364 | surface->pending.buffer); |
| 3365 | weston_buffer_reference(&sub->cached_buffer_ref, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3366 | surface->pending.buffer); |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3367 | weston_presentation_feedback_discard_list( |
| 3368 | &sub->cached.feedback_list); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3369 | } |
| 3370 | sub->cached.sx += surface->pending.sx; |
| 3371 | sub->cached.sy += surface->pending.sy; |
Pekka Paalanen | 260ba38 | 2014-03-14 14:38:12 +0200 | [diff] [blame] | 3372 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 3373 | apply_damage_buffer(&sub->cached.damage_surface, surface, &surface->pending); |
| 3374 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3375 | sub->cached.buffer_viewport.changed |= |
| 3376 | surface->pending.buffer_viewport.changed; |
| 3377 | sub->cached.buffer_viewport.buffer = |
| 3378 | surface->pending.buffer_viewport.buffer; |
| 3379 | sub->cached.buffer_viewport.surface = |
| 3380 | surface->pending.buffer_viewport.surface; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3381 | |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 3382 | weston_surface_reset_pending_buffer(surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3383 | |
| 3384 | pixman_region32_copy(&sub->cached.opaque, &surface->pending.opaque); |
| 3385 | |
| 3386 | pixman_region32_copy(&sub->cached.input, &surface->pending.input); |
| 3387 | |
| 3388 | wl_list_insert_list(&sub->cached.frame_callback_list, |
| 3389 | &surface->pending.frame_callback_list); |
| 3390 | wl_list_init(&surface->pending.frame_callback_list); |
| 3391 | |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 3392 | wl_list_insert_list(&sub->cached.feedback_list, |
| 3393 | &surface->pending.feedback_list); |
| 3394 | wl_list_init(&surface->pending.feedback_list); |
| 3395 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3396 | sub->has_cached_data = 1; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3397 | } |
| 3398 | |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 3399 | static bool |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3400 | weston_subsurface_is_synchronized(struct weston_subsurface *sub) |
| 3401 | { |
| 3402 | while (sub) { |
| 3403 | if (sub->synchronized) |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 3404 | return true; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3405 | |
| 3406 | if (!sub->parent) |
Derek Foreman | 280e7dd | 2014-10-03 13:13:42 -0500 | [diff] [blame] | 3407 | return false; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3408 | |
| 3409 | sub = weston_surface_to_subsurface(sub->parent); |
| 3410 | } |
| 3411 | |
Carlos Olmedo Escobar | 61a9bf5 | 2014-11-04 14:38:39 +0100 | [diff] [blame] | 3412 | return false; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3413 | } |
| 3414 | |
| 3415 | static void |
| 3416 | weston_subsurface_commit(struct weston_subsurface *sub) |
| 3417 | { |
| 3418 | struct weston_surface *surface = sub->surface; |
| 3419 | struct weston_subsurface *tmp; |
| 3420 | |
| 3421 | /* Recursive check for effectively synchronized. */ |
| 3422 | if (weston_subsurface_is_synchronized(sub)) { |
| 3423 | weston_subsurface_commit_to_cache(sub); |
| 3424 | } else { |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3425 | if (sub->has_cached_data) { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3426 | /* flush accumulated state from cache */ |
| 3427 | weston_subsurface_commit_to_cache(sub); |
| 3428 | weston_subsurface_commit_from_cache(sub); |
| 3429 | } else { |
| 3430 | weston_surface_commit(surface); |
| 3431 | } |
| 3432 | |
| 3433 | wl_list_for_each(tmp, &surface->subsurface_list, parent_link) { |
| 3434 | if (tmp->surface != surface) |
| 3435 | weston_subsurface_parent_commit(tmp, 0); |
| 3436 | } |
| 3437 | } |
| 3438 | } |
| 3439 | |
| 3440 | static void |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3441 | weston_subsurface_synchronized_commit(struct weston_subsurface *sub) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3442 | { |
| 3443 | struct weston_surface *surface = sub->surface; |
| 3444 | struct weston_subsurface *tmp; |
| 3445 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3446 | /* From now on, commit_from_cache the whole sub-tree, regardless of |
| 3447 | * the synchronized mode of each child. This sub-surface or some |
| 3448 | * of its ancestors were synchronized, so we are synchronized |
| 3449 | * all the way down. |
| 3450 | */ |
| 3451 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3452 | if (sub->has_cached_data) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3453 | weston_subsurface_commit_from_cache(sub); |
| 3454 | |
| 3455 | wl_list_for_each(tmp, &surface->subsurface_list, parent_link) { |
| 3456 | if (tmp->surface != surface) |
| 3457 | weston_subsurface_parent_commit(tmp, 1); |
| 3458 | } |
| 3459 | } |
| 3460 | |
| 3461 | static void |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3462 | weston_subsurface_parent_commit(struct weston_subsurface *sub, |
| 3463 | int parent_is_synchronized) |
| 3464 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3465 | struct weston_view *view; |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3466 | if (sub->position.set) { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3467 | wl_list_for_each(view, &sub->surface->views, surface_link) |
| 3468 | weston_view_set_position(view, |
| 3469 | sub->position.x, |
| 3470 | sub->position.y); |
| 3471 | |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3472 | sub->position.set = 0; |
| 3473 | } |
| 3474 | |
| 3475 | if (parent_is_synchronized || sub->synchronized) |
| 3476 | weston_subsurface_synchronized_commit(sub); |
| 3477 | } |
| 3478 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3479 | static int |
| 3480 | subsurface_get_label(struct weston_surface *surface, char *buf, size_t len) |
| 3481 | { |
| 3482 | return snprintf(buf, len, "sub-surface"); |
| 3483 | } |
| 3484 | |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3485 | static void |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3486 | subsurface_committed(struct weston_surface *surface, int32_t dx, int32_t dy) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3487 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3488 | struct weston_view *view; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3489 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3490 | wl_list_for_each(view, &surface->views, surface_link) |
Jason Ekstrand | 918f2dd | 2013-12-02 21:01:53 -0600 | [diff] [blame] | 3491 | weston_view_set_position(view, |
| 3492 | view->geometry.x + dx, |
| 3493 | view->geometry.y + dy); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3494 | |
| 3495 | /* No need to check parent mappedness, because if parent is not |
| 3496 | * mapped, parent is not in a visible layer, so this sub-surface |
| 3497 | * will not be drawn either. |
| 3498 | */ |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 3499 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3500 | if (!weston_surface_is_mapped(surface)) { |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 3501 | surface->is_mapped = true; |
Pekka Paalanen | eb3cf22 | 2014-06-30 11:52:07 +0300 | [diff] [blame] | 3502 | |
Derek Foreman | 4b1a0a1 | 2014-09-10 15:37:33 -0500 | [diff] [blame] | 3503 | /* Cannot call weston_view_update_transform(), |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3504 | * because that would call it also for the parent surface, |
| 3505 | * which might not be mapped yet. That would lead to |
| 3506 | * inconsistent state, where the window could never be |
| 3507 | * mapped. |
| 3508 | * |
Armin Krezović | f8486c3 | 2016-06-30 06:04:28 +0200 | [diff] [blame] | 3509 | * Instead just force the is_mapped flag on, to make |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3510 | * weston_surface_is_mapped() return true, so that when the |
| 3511 | * parent surface does get mapped, this one will get |
Pekka Paalanen | eb3cf22 | 2014-06-30 11:52:07 +0300 | [diff] [blame] | 3512 | * included, too. See view_list_add(). |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3513 | */ |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3514 | } |
| 3515 | } |
| 3516 | |
| 3517 | static struct weston_subsurface * |
| 3518 | weston_surface_to_subsurface(struct weston_surface *surface) |
| 3519 | { |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3520 | if (surface->committed == subsurface_committed) |
| 3521 | return surface->committed_private; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3522 | |
| 3523 | return NULL; |
| 3524 | } |
| 3525 | |
Pekka Paalanen | 01388e2 | 2013-04-25 13:57:44 +0300 | [diff] [blame] | 3526 | WL_EXPORT struct weston_surface * |
| 3527 | weston_surface_get_main_surface(struct weston_surface *surface) |
| 3528 | { |
| 3529 | struct weston_subsurface *sub; |
| 3530 | |
| 3531 | while (surface && (sub = weston_surface_to_subsurface(surface))) |
| 3532 | surface = sub->parent; |
| 3533 | |
| 3534 | return surface; |
| 3535 | } |
| 3536 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 3537 | WL_EXPORT int |
| 3538 | weston_surface_set_role(struct weston_surface *surface, |
| 3539 | const char *role_name, |
| 3540 | struct wl_resource *error_resource, |
| 3541 | uint32_t error_code) |
| 3542 | { |
| 3543 | assert(role_name); |
| 3544 | |
| 3545 | if (surface->role_name == NULL || |
| 3546 | surface->role_name == role_name || |
| 3547 | strcmp(surface->role_name, role_name) == 0) { |
| 3548 | surface->role_name = role_name; |
| 3549 | |
| 3550 | return 0; |
| 3551 | } |
| 3552 | |
| 3553 | wl_resource_post_error(error_resource, error_code, |
| 3554 | "Cannot assign role %s to wl_surface@%d," |
| 3555 | " already has role %s\n", |
| 3556 | role_name, |
| 3557 | wl_resource_get_id(surface->resource), |
| 3558 | surface->role_name); |
| 3559 | return -1; |
| 3560 | } |
| 3561 | |
Quentin Glidic | 9c5dd7e | 2016-08-12 10:41:37 +0200 | [diff] [blame] | 3562 | WL_EXPORT const char * |
| 3563 | weston_surface_get_role(struct weston_surface *surface) |
| 3564 | { |
| 3565 | return surface->role_name; |
| 3566 | } |
| 3567 | |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3568 | WL_EXPORT void |
| 3569 | weston_surface_set_label_func(struct weston_surface *surface, |
| 3570 | int (*desc)(struct weston_surface *, |
| 3571 | char *, size_t)) |
| 3572 | { |
| 3573 | surface->get_label = desc; |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 3574 | surface->timeline.force_refresh = 1; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3575 | } |
| 3576 | |
Pekka Paalanen | c647ed7 | 2015-02-09 13:16:57 +0200 | [diff] [blame] | 3577 | /** Get the size of surface contents |
| 3578 | * |
| 3579 | * \param surface The surface to query. |
| 3580 | * \param width Returns the width of raw contents. |
| 3581 | * \param height Returns the height of raw contents. |
| 3582 | * |
| 3583 | * Retrieves the raw surface content size in pixels for the given surface. |
| 3584 | * This is the whole content size in buffer pixels. If the surface |
| 3585 | * has no content or the renderer does not implement this feature, |
| 3586 | * zeroes are returned. |
| 3587 | * |
| 3588 | * This function is used to determine the buffer size needed for |
| 3589 | * a weston_surface_copy_content() call. |
| 3590 | */ |
| 3591 | WL_EXPORT void |
| 3592 | weston_surface_get_content_size(struct weston_surface *surface, |
| 3593 | int *width, int *height) |
| 3594 | { |
| 3595 | struct weston_renderer *rer = surface->compositor->renderer; |
| 3596 | |
| 3597 | if (!rer->surface_get_content_size) { |
| 3598 | *width = 0; |
| 3599 | *height = 0; |
| 3600 | return; |
| 3601 | } |
| 3602 | |
| 3603 | rer->surface_get_content_size(surface, width, height); |
| 3604 | } |
| 3605 | |
Quentin Glidic | 248dd10 | 2016-08-12 10:41:34 +0200 | [diff] [blame] | 3606 | /** Get the bounding box of a surface and its subsurfaces |
| 3607 | * |
| 3608 | * \param surface The surface to query. |
| 3609 | * \return The bounding box relative to the surface origin. |
| 3610 | * |
| 3611 | */ |
| 3612 | WL_EXPORT struct weston_geometry |
| 3613 | weston_surface_get_bounding_box(struct weston_surface *surface) |
| 3614 | { |
| 3615 | pixman_region32_t region; |
| 3616 | pixman_box32_t *box; |
| 3617 | struct weston_subsurface *subsurface; |
| 3618 | |
| 3619 | pixman_region32_init_rect(®ion, |
| 3620 | 0, 0, |
| 3621 | surface->width, surface->height); |
| 3622 | |
| 3623 | wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) |
| 3624 | pixman_region32_union_rect(®ion, ®ion, |
| 3625 | subsurface->position.x, |
| 3626 | subsurface->position.y, |
| 3627 | subsurface->surface->width, |
| 3628 | subsurface->surface->height); |
| 3629 | |
| 3630 | box = pixman_region32_extents(®ion); |
| 3631 | struct weston_geometry geometry = { |
| 3632 | .x = box->x1, |
| 3633 | .y = box->y1, |
| 3634 | .width = box->x2 - box->x1, |
| 3635 | .height = box->y2 - box->y1, |
| 3636 | }; |
| 3637 | |
| 3638 | pixman_region32_fini(®ion); |
| 3639 | |
| 3640 | return geometry; |
| 3641 | } |
| 3642 | |
Pekka Paalanen | c647ed7 | 2015-02-09 13:16:57 +0200 | [diff] [blame] | 3643 | /** Copy surface contents to system memory. |
| 3644 | * |
| 3645 | * \param surface The surface to copy from. |
| 3646 | * \param target Pointer to the target memory buffer. |
| 3647 | * \param size Size of the target buffer in bytes. |
| 3648 | * \param src_x X location on contents to copy from. |
| 3649 | * \param src_y Y location on contents to copy from. |
| 3650 | * \param width Width in pixels of the area to copy. |
| 3651 | * \param height Height in pixels of the area to copy. |
| 3652 | * \return 0 for success, -1 for failure. |
| 3653 | * |
| 3654 | * Surface contents are maintained by the renderer. They can be in a |
| 3655 | * reserved weston_buffer or as a copy, e.g. a GL texture, or something |
| 3656 | * else. |
| 3657 | * |
| 3658 | * Surface contents are copied into memory pointed to by target, |
| 3659 | * which has size bytes of space available. The target memory |
| 3660 | * may be larger than needed, but being smaller returns an error. |
| 3661 | * The extra bytes in target may or may not be written; their content is |
| 3662 | * unspecified. Size must be large enough to hold the image. |
| 3663 | * |
| 3664 | * The image in the target memory will be arranged in rows from |
| 3665 | * top to bottom, and pixels on a row from left to right. The pixel |
| 3666 | * format is PIXMAN_a8b8g8r8, 4 bytes per pixel, and stride is exactly |
| 3667 | * width * 4. |
| 3668 | * |
| 3669 | * Parameters src_x and src_y define the upper-left corner in buffer |
| 3670 | * coordinates (pixels) to copy from. Parameters width and height |
| 3671 | * define the size of the area to copy in pixels. |
| 3672 | * |
| 3673 | * The rectangle defined by src_x, src_y, width, height must fit in |
| 3674 | * the surface contents. Otherwise an error is returned. |
| 3675 | * |
| 3676 | * Use surface_get_data_size to determine the content size; the |
| 3677 | * needed target buffer size and rectangle limits. |
| 3678 | * |
| 3679 | * CURRENT IMPLEMENTATION RESTRICTIONS: |
| 3680 | * - the machine must be little-endian due to Pixman formats. |
| 3681 | * |
| 3682 | * NOTE: Pixman formats are premultiplied. |
| 3683 | */ |
| 3684 | WL_EXPORT int |
| 3685 | weston_surface_copy_content(struct weston_surface *surface, |
| 3686 | void *target, size_t size, |
| 3687 | int src_x, int src_y, |
| 3688 | int width, int height) |
| 3689 | { |
| 3690 | struct weston_renderer *rer = surface->compositor->renderer; |
| 3691 | int cw, ch; |
| 3692 | const size_t bytespp = 4; /* PIXMAN_a8b8g8r8 */ |
| 3693 | |
| 3694 | if (!rer->surface_copy_content) |
| 3695 | return -1; |
| 3696 | |
| 3697 | weston_surface_get_content_size(surface, &cw, &ch); |
| 3698 | |
| 3699 | if (src_x < 0 || src_y < 0) |
| 3700 | return -1; |
| 3701 | |
| 3702 | if (width <= 0 || height <= 0) |
| 3703 | return -1; |
| 3704 | |
| 3705 | if (src_x + width > cw || src_y + height > ch) |
| 3706 | return -1; |
| 3707 | |
| 3708 | if (width * bytespp * height > size) |
| 3709 | return -1; |
| 3710 | |
| 3711 | return rer->surface_copy_content(surface, target, size, |
| 3712 | src_x, src_y, width, height); |
| 3713 | } |
| 3714 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3715 | static void |
| 3716 | subsurface_set_position(struct wl_client *client, |
| 3717 | struct wl_resource *resource, int32_t x, int32_t y) |
| 3718 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 3719 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3720 | |
| 3721 | if (!sub) |
| 3722 | return; |
| 3723 | |
| 3724 | sub->position.x = x; |
| 3725 | sub->position.y = y; |
| 3726 | sub->position.set = 1; |
| 3727 | } |
| 3728 | |
| 3729 | static struct weston_subsurface * |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 3730 | subsurface_find_sibling(struct weston_subsurface *sub, |
| 3731 | struct weston_surface *surface) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3732 | { |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 3733 | struct weston_surface *parent = sub->parent; |
| 3734 | struct weston_subsurface *sibling; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3735 | |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 3736 | wl_list_for_each(sibling, &parent->subsurface_list, parent_link) { |
| 3737 | if (sibling->surface == surface && sibling != sub) |
| 3738 | return sibling; |
| 3739 | } |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3740 | |
| 3741 | return NULL; |
| 3742 | } |
| 3743 | |
| 3744 | static struct weston_subsurface * |
| 3745 | subsurface_sibling_check(struct weston_subsurface *sub, |
| 3746 | struct weston_surface *surface, |
| 3747 | const char *request) |
| 3748 | { |
| 3749 | struct weston_subsurface *sibling; |
| 3750 | |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 3751 | sibling = subsurface_find_sibling(sub, surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3752 | if (!sibling) { |
| 3753 | wl_resource_post_error(sub->resource, |
| 3754 | WL_SUBSURFACE_ERROR_BAD_SURFACE, |
| 3755 | "%s: wl_surface@%d is not a parent or sibling", |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3756 | request, wl_resource_get_id(surface->resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3757 | return NULL; |
| 3758 | } |
| 3759 | |
Arnaud Vrac | b8c16c9 | 2016-06-08 18:37:57 +0200 | [diff] [blame] | 3760 | assert(sibling->parent == sub->parent); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3761 | |
| 3762 | return sibling; |
| 3763 | } |
| 3764 | |
| 3765 | static void |
| 3766 | subsurface_place_above(struct wl_client *client, |
| 3767 | struct wl_resource *resource, |
| 3768 | struct wl_resource *sibling_resource) |
| 3769 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 3770 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3771 | struct weston_surface *surface = |
| 3772 | wl_resource_get_user_data(sibling_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3773 | struct weston_subsurface *sibling; |
| 3774 | |
| 3775 | if (!sub) |
| 3776 | return; |
| 3777 | |
| 3778 | sibling = subsurface_sibling_check(sub, surface, "place_above"); |
| 3779 | if (!sibling) |
| 3780 | return; |
| 3781 | |
| 3782 | wl_list_remove(&sub->parent_link_pending); |
| 3783 | wl_list_insert(sibling->parent_link_pending.prev, |
| 3784 | &sub->parent_link_pending); |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 3785 | |
| 3786 | sub->reordered = true; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3787 | } |
| 3788 | |
| 3789 | static void |
| 3790 | subsurface_place_below(struct wl_client *client, |
| 3791 | struct wl_resource *resource, |
| 3792 | struct wl_resource *sibling_resource) |
| 3793 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 3794 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 3795 | struct weston_surface *surface = |
| 3796 | wl_resource_get_user_data(sibling_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3797 | struct weston_subsurface *sibling; |
| 3798 | |
| 3799 | if (!sub) |
| 3800 | return; |
| 3801 | |
| 3802 | sibling = subsurface_sibling_check(sub, surface, "place_below"); |
| 3803 | if (!sibling) |
| 3804 | return; |
| 3805 | |
| 3806 | wl_list_remove(&sub->parent_link_pending); |
| 3807 | wl_list_insert(&sibling->parent_link_pending, |
| 3808 | &sub->parent_link_pending); |
Emilio Pozuelo Monfort | 4f3cad7 | 2017-01-27 17:30:29 +0100 | [diff] [blame] | 3809 | |
| 3810 | sub->reordered = true; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3811 | } |
| 3812 | |
| 3813 | static void |
| 3814 | subsurface_set_sync(struct wl_client *client, struct wl_resource *resource) |
| 3815 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 3816 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3817 | |
| 3818 | if (sub) |
| 3819 | sub->synchronized = 1; |
| 3820 | } |
| 3821 | |
| 3822 | static void |
| 3823 | subsurface_set_desync(struct wl_client *client, struct wl_resource *resource) |
| 3824 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 3825 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3826 | |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3827 | if (sub && sub->synchronized) { |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3828 | sub->synchronized = 0; |
Pekka Paalanen | 16abf6a | 2013-05-17 16:46:05 +0300 | [diff] [blame] | 3829 | |
| 3830 | /* If sub became effectively desynchronized, flush. */ |
| 3831 | if (!weston_subsurface_is_synchronized(sub)) |
| 3832 | weston_subsurface_synchronized_commit(sub); |
| 3833 | } |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3834 | } |
| 3835 | |
| 3836 | static void |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3837 | weston_subsurface_unlink_parent(struct weston_subsurface *sub) |
| 3838 | { |
| 3839 | wl_list_remove(&sub->parent_link); |
| 3840 | wl_list_remove(&sub->parent_link_pending); |
| 3841 | wl_list_remove(&sub->parent_destroy_listener.link); |
| 3842 | sub->parent = NULL; |
| 3843 | } |
| 3844 | |
| 3845 | static void |
| 3846 | weston_subsurface_destroy(struct weston_subsurface *sub); |
| 3847 | |
| 3848 | static void |
| 3849 | subsurface_handle_surface_destroy(struct wl_listener *listener, void *data) |
| 3850 | { |
| 3851 | struct weston_subsurface *sub = |
| 3852 | container_of(listener, struct weston_subsurface, |
| 3853 | surface_destroy_listener); |
Pekka Paalanen | ca79076 | 2015-04-17 14:23:38 +0300 | [diff] [blame] | 3854 | assert(data == sub->surface); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3855 | |
| 3856 | /* The protocol object (wl_resource) is left inert. */ |
| 3857 | if (sub->resource) |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 3858 | wl_resource_set_user_data(sub->resource, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3859 | |
| 3860 | weston_subsurface_destroy(sub); |
| 3861 | } |
| 3862 | |
| 3863 | static void |
| 3864 | subsurface_handle_parent_destroy(struct wl_listener *listener, void *data) |
| 3865 | { |
| 3866 | struct weston_subsurface *sub = |
| 3867 | container_of(listener, struct weston_subsurface, |
| 3868 | parent_destroy_listener); |
Pekka Paalanen | ca79076 | 2015-04-17 14:23:38 +0300 | [diff] [blame] | 3869 | assert(data == sub->parent); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3870 | assert(sub->surface != sub->parent); |
| 3871 | |
| 3872 | if (weston_surface_is_mapped(sub->surface)) |
| 3873 | weston_surface_unmap(sub->surface); |
| 3874 | |
| 3875 | weston_subsurface_unlink_parent(sub); |
| 3876 | } |
| 3877 | |
| 3878 | static void |
| 3879 | subsurface_resource_destroy(struct wl_resource *resource) |
| 3880 | { |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 3881 | struct weston_subsurface *sub = wl_resource_get_user_data(resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3882 | |
| 3883 | if (sub) |
| 3884 | weston_subsurface_destroy(sub); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3885 | } |
| 3886 | |
| 3887 | static void |
| 3888 | subsurface_destroy(struct wl_client *client, struct wl_resource *resource) |
| 3889 | { |
| 3890 | wl_resource_destroy(resource); |
| 3891 | } |
| 3892 | |
| 3893 | static void |
| 3894 | weston_subsurface_link_parent(struct weston_subsurface *sub, |
| 3895 | struct weston_surface *parent) |
| 3896 | { |
| 3897 | sub->parent = parent; |
| 3898 | sub->parent_destroy_listener.notify = subsurface_handle_parent_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3899 | wl_signal_add(&parent->destroy_signal, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3900 | &sub->parent_destroy_listener); |
| 3901 | |
| 3902 | wl_list_insert(&parent->subsurface_list, &sub->parent_link); |
| 3903 | wl_list_insert(&parent->subsurface_list_pending, |
| 3904 | &sub->parent_link_pending); |
| 3905 | } |
| 3906 | |
| 3907 | static void |
| 3908 | weston_subsurface_link_surface(struct weston_subsurface *sub, |
| 3909 | struct weston_surface *surface) |
| 3910 | { |
| 3911 | sub->surface = surface; |
| 3912 | sub->surface_destroy_listener.notify = |
| 3913 | subsurface_handle_surface_destroy; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3914 | wl_signal_add(&surface->destroy_signal, |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3915 | &sub->surface_destroy_listener); |
| 3916 | } |
| 3917 | |
| 3918 | static void |
| 3919 | weston_subsurface_destroy(struct weston_subsurface *sub) |
| 3920 | { |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3921 | struct weston_view *view, *next; |
| 3922 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3923 | assert(sub->surface); |
| 3924 | |
| 3925 | if (sub->resource) { |
| 3926 | assert(weston_surface_to_subsurface(sub->surface) == sub); |
| 3927 | assert(sub->parent_destroy_listener.notify == |
| 3928 | subsurface_handle_parent_destroy); |
| 3929 | |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 3930 | wl_list_for_each_safe(view, next, &sub->surface->views, surface_link) { |
| 3931 | weston_view_unmap(view); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3932 | weston_view_destroy(view); |
George Kiagiadakis | ed04d38 | 2014-06-13 18:10:26 +0200 | [diff] [blame] | 3933 | } |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3934 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3935 | if (sub->parent) |
| 3936 | weston_subsurface_unlink_parent(sub); |
| 3937 | |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3938 | weston_surface_state_fini(&sub->cached); |
| 3939 | weston_buffer_reference(&sub->cached_buffer_ref, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3940 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 3941 | sub->surface->committed = NULL; |
| 3942 | sub->surface->committed_private = NULL; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 3943 | weston_surface_set_label_func(sub->surface, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3944 | } else { |
| 3945 | /* the dummy weston_subsurface for the parent itself */ |
| 3946 | assert(sub->parent_destroy_listener.notify == NULL); |
| 3947 | wl_list_remove(&sub->parent_link); |
| 3948 | wl_list_remove(&sub->parent_link_pending); |
| 3949 | } |
| 3950 | |
| 3951 | wl_list_remove(&sub->surface_destroy_listener.link); |
| 3952 | free(sub); |
| 3953 | } |
| 3954 | |
| 3955 | static const struct wl_subsurface_interface subsurface_implementation = { |
| 3956 | subsurface_destroy, |
| 3957 | subsurface_set_position, |
| 3958 | subsurface_place_above, |
| 3959 | subsurface_place_below, |
| 3960 | subsurface_set_sync, |
| 3961 | subsurface_set_desync |
| 3962 | }; |
| 3963 | |
| 3964 | static struct weston_subsurface * |
| 3965 | weston_subsurface_create(uint32_t id, struct weston_surface *surface, |
| 3966 | struct weston_surface *parent) |
| 3967 | { |
| 3968 | struct weston_subsurface *sub; |
Jason Ekstrand | 26ed73c | 2013-06-06 22:34:41 -0500 | [diff] [blame] | 3969 | struct wl_client *client = wl_resource_get_client(surface->resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3970 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 3971 | sub = zalloc(sizeof *sub); |
| 3972 | if (sub == NULL) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3973 | return NULL; |
| 3974 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 3975 | wl_list_init(&sub->unused_views); |
| 3976 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3977 | sub->resource = |
| 3978 | wl_resource_create(client, &wl_subsurface_interface, 1, id); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3979 | if (!sub->resource) { |
| 3980 | free(sub); |
| 3981 | return NULL; |
| 3982 | } |
| 3983 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 3984 | wl_resource_set_implementation(sub->resource, |
| 3985 | &subsurface_implementation, |
| 3986 | sub, subsurface_resource_destroy); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3987 | weston_subsurface_link_surface(sub, surface); |
| 3988 | weston_subsurface_link_parent(sub, parent); |
Jason Ekstrand | 7b98207 | 2014-05-20 14:33:03 -0500 | [diff] [blame] | 3989 | weston_surface_state_init(&sub->cached); |
| 3990 | sub->cached_buffer_ref.buffer = NULL; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3991 | sub->synchronized = 1; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 3992 | |
| 3993 | return sub; |
| 3994 | } |
| 3995 | |
| 3996 | /* Create a dummy subsurface for having the parent itself in its |
| 3997 | * sub-surface lists. Makes stacking order manipulation easy. |
| 3998 | */ |
| 3999 | static struct weston_subsurface * |
| 4000 | weston_subsurface_create_for_parent(struct weston_surface *parent) |
| 4001 | { |
| 4002 | struct weston_subsurface *sub; |
| 4003 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 4004 | sub = zalloc(sizeof *sub); |
| 4005 | if (sub == NULL) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4006 | return NULL; |
| 4007 | |
| 4008 | weston_subsurface_link_surface(sub, parent); |
| 4009 | sub->parent = parent; |
| 4010 | wl_list_insert(&parent->subsurface_list, &sub->parent_link); |
| 4011 | wl_list_insert(&parent->subsurface_list_pending, |
| 4012 | &sub->parent_link_pending); |
| 4013 | |
| 4014 | return sub; |
| 4015 | } |
| 4016 | |
| 4017 | static void |
| 4018 | subcompositor_get_subsurface(struct wl_client *client, |
| 4019 | struct wl_resource *resource, |
| 4020 | uint32_t id, |
| 4021 | struct wl_resource *surface_resource, |
| 4022 | struct wl_resource *parent_resource) |
| 4023 | { |
Jason Ekstrand | 0f2ef7e | 2013-06-14 10:07:53 -0500 | [diff] [blame] | 4024 | struct weston_surface *surface = |
| 4025 | wl_resource_get_user_data(surface_resource); |
| 4026 | struct weston_surface *parent = |
| 4027 | wl_resource_get_user_data(parent_resource); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4028 | struct weston_subsurface *sub; |
| 4029 | static const char where[] = "get_subsurface: wl_subsurface@"; |
| 4030 | |
| 4031 | if (surface == parent) { |
| 4032 | wl_resource_post_error(resource, |
| 4033 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 4034 | "%s%d: wl_surface@%d cannot be its own parent", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4035 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4036 | return; |
| 4037 | } |
| 4038 | |
| 4039 | if (weston_surface_to_subsurface(surface)) { |
| 4040 | wl_resource_post_error(resource, |
| 4041 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 4042 | "%s%d: wl_surface@%d is already a sub-surface", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4043 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4044 | return; |
| 4045 | } |
| 4046 | |
Pekka Paalanen | 50b6747 | 2014-10-01 15:02:41 +0300 | [diff] [blame] | 4047 | if (weston_surface_set_role(surface, "wl_subsurface", resource, |
| 4048 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE) < 0) |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4049 | return; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4050 | |
Pekka Paalanen | 86c8ca0 | 2013-05-17 16:46:07 +0300 | [diff] [blame] | 4051 | if (weston_surface_get_main_surface(parent) == surface) { |
| 4052 | wl_resource_post_error(resource, |
| 4053 | WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE, |
| 4054 | "%s%d: wl_surface@%d is an ancestor of parent", |
Jason Ekstrand | 0bd587e | 2013-06-14 10:08:02 -0500 | [diff] [blame] | 4055 | where, id, wl_resource_get_id(surface_resource)); |
Pekka Paalanen | 86c8ca0 | 2013-05-17 16:46:07 +0300 | [diff] [blame] | 4056 | return; |
| 4057 | } |
| 4058 | |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4059 | /* make sure the parent is in its own list */ |
| 4060 | if (wl_list_empty(&parent->subsurface_list)) { |
| 4061 | if (!weston_subsurface_create_for_parent(parent)) { |
| 4062 | wl_resource_post_no_memory(resource); |
| 4063 | return; |
| 4064 | } |
| 4065 | } |
| 4066 | |
| 4067 | sub = weston_subsurface_create(id, surface, parent); |
| 4068 | if (!sub) { |
| 4069 | wl_resource_post_no_memory(resource); |
| 4070 | return; |
| 4071 | } |
| 4072 | |
Quentin Glidic | 2edc3d5 | 2016-08-12 10:41:33 +0200 | [diff] [blame] | 4073 | surface->committed = subsurface_committed; |
| 4074 | surface->committed_private = sub; |
Pekka Paalanen | 8274d90 | 2014-08-06 19:36:51 +0300 | [diff] [blame] | 4075 | weston_surface_set_label_func(surface, subsurface_get_label); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4076 | } |
| 4077 | |
| 4078 | static void |
| 4079 | subcompositor_destroy(struct wl_client *client, struct wl_resource *resource) |
| 4080 | { |
| 4081 | wl_resource_destroy(resource); |
| 4082 | } |
| 4083 | |
| 4084 | static const struct wl_subcompositor_interface subcompositor_interface = { |
| 4085 | subcompositor_destroy, |
| 4086 | subcompositor_get_subsurface |
| 4087 | }; |
| 4088 | |
| 4089 | static void |
| 4090 | bind_subcompositor(struct wl_client *client, |
| 4091 | void *data, uint32_t version, uint32_t id) |
| 4092 | { |
| 4093 | struct weston_compositor *compositor = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4094 | struct wl_resource *resource; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4095 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4096 | resource = |
| 4097 | wl_resource_create(client, &wl_subcompositor_interface, 1, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 4098 | if (resource == NULL) { |
| 4099 | wl_client_post_no_memory(client); |
| 4100 | return; |
| 4101 | } |
| 4102 | wl_resource_set_implementation(resource, &subcompositor_interface, |
| 4103 | compositor, NULL); |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4104 | } |
| 4105 | |
Bryce Harrington | 0795ece | 2016-08-30 12:04:26 -0700 | [diff] [blame] | 4106 | /** Set a DPMS mode on all of the compositor's outputs |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4107 | * |
| 4108 | * \param compositor The compositor instance |
| 4109 | * \param state The DPMS state the outputs will be set to |
| 4110 | */ |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 4111 | static void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4112 | weston_compositor_dpms(struct weston_compositor *compositor, |
| 4113 | enum dpms_enum state) |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4114 | { |
| 4115 | struct weston_output *output; |
| 4116 | |
Bryce Harrington | 08976ac | 2016-08-30 12:05:16 -0700 | [diff] [blame] | 4117 | wl_list_for_each(output, &compositor->output_list, link) |
| 4118 | if (output->set_dpms) |
| 4119 | output->set_dpms(output, state); |
Tiago Vignatti | 8e53c7f | 2012-02-29 19:53:50 +0200 | [diff] [blame] | 4120 | } |
| 4121 | |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4122 | /** Restores the compositor to active status |
| 4123 | * |
| 4124 | * \param compositor The compositor instance |
| 4125 | * |
| 4126 | * If the compositor was in a sleeping mode, all outputs are powered |
| 4127 | * back on via DPMS. Otherwise if the compositor was inactive |
| 4128 | * (idle/locked, offscreen, or sleeping) then the compositor's wake |
| 4129 | * signal will fire. |
| 4130 | * |
| 4131 | * Restarts the idle timer. |
| 4132 | */ |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4133 | WL_EXPORT void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4134 | weston_compositor_wake(struct weston_compositor *compositor) |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4135 | { |
Neil Roberts | 8b62e20 | 2013-09-30 13:14:47 +0100 | [diff] [blame] | 4136 | uint32_t old_state = compositor->state; |
| 4137 | |
| 4138 | /* The state needs to be changed before emitting the wake |
| 4139 | * signal because that may try to schedule a repaint which |
| 4140 | * will not work if the compositor is still sleeping */ |
| 4141 | compositor->state = WESTON_COMPOSITOR_ACTIVE; |
| 4142 | |
| 4143 | switch (old_state) { |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4144 | case WESTON_COMPOSITOR_SLEEPING: |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4145 | case WESTON_COMPOSITOR_IDLE: |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4146 | case WESTON_COMPOSITOR_OFFSCREEN: |
Daniel Stone | 893b936 | 2016-11-08 15:47:09 +0000 | [diff] [blame] | 4147 | weston_compositor_dpms(compositor, WESTON_DPMS_ON); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4148 | wl_signal_emit(&compositor->wake_signal, compositor); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4149 | /* fall through */ |
| 4150 | default: |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4151 | wl_event_source_timer_update(compositor->idle_source, |
| 4152 | compositor->idle_time * 1000); |
Kristian Høgsberg | af867cc | 2011-11-15 13:34:49 +0200 | [diff] [blame] | 4153 | } |
| 4154 | } |
| 4155 | |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4156 | /** Turns off rendering and frame events for the compositor. |
| 4157 | * |
| 4158 | * \param compositor The compositor instance |
| 4159 | * |
| 4160 | * This is used for example to prevent further rendering while the |
| 4161 | * compositor is shutting down. |
| 4162 | * |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4163 | * Stops the idle timer. |
| 4164 | */ |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4165 | WL_EXPORT void |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4166 | weston_compositor_offscreen(struct weston_compositor *compositor) |
| 4167 | { |
| 4168 | switch (compositor->state) { |
| 4169 | case WESTON_COMPOSITOR_OFFSCREEN: |
| 4170 | return; |
| 4171 | case WESTON_COMPOSITOR_SLEEPING: |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4172 | default: |
| 4173 | compositor->state = WESTON_COMPOSITOR_OFFSCREEN; |
| 4174 | wl_event_source_timer_update(compositor->idle_source, 0); |
| 4175 | } |
| 4176 | } |
| 4177 | |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4178 | /** Powers down all attached output devices |
| 4179 | * |
| 4180 | * \param compositor The compositor instance |
| 4181 | * |
| 4182 | * Causes rendering to the outputs to cease, and no frame events to be |
| 4183 | * sent. Only powers down the outputs if the compositor is not already |
| 4184 | * in sleep mode. |
| 4185 | * |
| 4186 | * Stops the idle timer. |
| 4187 | */ |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4188 | WL_EXPORT void |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4189 | weston_compositor_sleep(struct weston_compositor *compositor) |
| 4190 | { |
| 4191 | if (compositor->state == WESTON_COMPOSITOR_SLEEPING) |
| 4192 | return; |
| 4193 | |
Philipp Brüschweiler | 57edf7f | 2013-03-29 13:01:56 +0100 | [diff] [blame] | 4194 | wl_event_source_timer_update(compositor->idle_source, 0); |
Ander Conselvan de Oliveira | 87524b6 | 2013-02-21 18:35:22 +0200 | [diff] [blame] | 4195 | compositor->state = WESTON_COMPOSITOR_SLEEPING; |
| 4196 | weston_compositor_dpms(compositor, WESTON_DPMS_OFF); |
| 4197 | } |
| 4198 | |
Bryce Harrington | c9626a3 | 2015-12-11 13:11:38 -0800 | [diff] [blame] | 4199 | /** Sets compositor to idle mode |
| 4200 | * |
| 4201 | * \param data The compositor instance |
| 4202 | * |
| 4203 | * This is called when the idle timer fires. Once the compositor is in |
| 4204 | * idle mode it requires a wake action (e.g. via |
| 4205 | * weston_compositor_wake()) to restore it. The compositor's |
| 4206 | * idle_signal will be triggered when the idle event occurs. |
| 4207 | * |
| 4208 | * Idleness can be inhibited by setting the compositor's idle_inhibit |
| 4209 | * property. |
| 4210 | */ |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 4211 | static int |
| 4212 | idle_handler(void *data) |
| 4213 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4214 | struct weston_compositor *compositor = data; |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 4215 | |
| 4216 | if (compositor->idle_inhibit) |
| 4217 | return 1; |
| 4218 | |
Ander Conselvan de Oliveira | 19d10ef | 2013-02-21 18:35:20 +0200 | [diff] [blame] | 4219 | compositor->state = WESTON_COMPOSITOR_IDLE; |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 4220 | wl_signal_emit(&compositor->idle_signal, compositor); |
Kristian Høgsberg | e10a5d9 | 2011-04-22 14:01:18 -0400 | [diff] [blame] | 4221 | |
| 4222 | return 1; |
| 4223 | } |
| 4224 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4225 | WL_EXPORT void |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 4226 | weston_plane_init(struct weston_plane *plane, |
| 4227 | struct weston_compositor *ec, |
| 4228 | int32_t x, int32_t y) |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4229 | { |
| 4230 | pixman_region32_init(&plane->damage); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 4231 | pixman_region32_init(&plane->clip); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4232 | plane->x = x; |
| 4233 | plane->y = y; |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 4234 | plane->compositor = ec; |
Ander Conselvan de Oliveira | 3c36bf3 | 2013-07-05 16:05:26 +0300 | [diff] [blame] | 4235 | |
| 4236 | /* Init the link so that the call to wl_list_remove() when releasing |
| 4237 | * the plane without ever stacking doesn't lead to a crash */ |
| 4238 | wl_list_init(&plane->link); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4239 | } |
| 4240 | |
| 4241 | WL_EXPORT void |
| 4242 | weston_plane_release(struct weston_plane *plane) |
| 4243 | { |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 4244 | struct weston_view *view; |
| 4245 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4246 | pixman_region32_fini(&plane->damage); |
Ander Conselvan de Oliveira | e1bd5a0 | 2013-03-05 17:30:29 +0200 | [diff] [blame] | 4247 | pixman_region32_fini(&plane->clip); |
Ander Conselvan de Oliveira | 3c36bf3 | 2013-07-05 16:05:26 +0300 | [diff] [blame] | 4248 | |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 4249 | wl_list_for_each(view, &plane->compositor->view_list, link) { |
| 4250 | if (view->plane == plane) |
| 4251 | view->plane = NULL; |
| 4252 | } |
| 4253 | |
Ander Conselvan de Oliveira | 3c36bf3 | 2013-07-05 16:05:26 +0300 | [diff] [blame] | 4254 | wl_list_remove(&plane->link); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 4255 | } |
| 4256 | |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 4257 | WL_EXPORT void |
| 4258 | weston_compositor_stack_plane(struct weston_compositor *ec, |
| 4259 | struct weston_plane *plane, |
| 4260 | struct weston_plane *above) |
| 4261 | { |
| 4262 | if (above) |
| 4263 | wl_list_insert(above->link.prev, &plane->link); |
| 4264 | else |
| 4265 | wl_list_insert(&ec->plane_list, &plane->link); |
| 4266 | } |
| 4267 | |
Quentin Glidic | 4ef719c | 2016-07-05 20:44:33 +0200 | [diff] [blame] | 4268 | static void |
| 4269 | output_release(struct wl_client *client, struct wl_resource *resource) |
| 4270 | { |
| 4271 | wl_resource_destroy(resource); |
| 4272 | } |
| 4273 | |
| 4274 | static const struct wl_output_interface output_interface = { |
| 4275 | output_release, |
| 4276 | }; |
| 4277 | |
| 4278 | |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 4279 | static void unbind_resource(struct wl_resource *resource) |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 4280 | { |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4281 | wl_list_remove(wl_resource_get_link(resource)); |
Kristian Høgsberg | d2baf1f | 2011-10-11 22:20:37 -0400 | [diff] [blame] | 4282 | } |
| 4283 | |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4284 | static void |
Kristian Høgsberg | 97d44aa | 2011-08-26 17:21:20 -0400 | [diff] [blame] | 4285 | bind_output(struct wl_client *client, |
| 4286 | void *data, uint32_t version, uint32_t id) |
Kristian Høgsberg | bf9541f | 2008-11-25 12:10:09 -0500 | [diff] [blame] | 4287 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4288 | struct weston_output *output = data; |
| 4289 | struct weston_mode *mode; |
Kristian Høgsberg | fd07fb7 | 2011-08-29 15:03:09 -0400 | [diff] [blame] | 4290 | struct wl_resource *resource; |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 4291 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 4292 | resource = wl_resource_create(client, &wl_output_interface, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 4293 | version, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 4294 | if (resource == NULL) { |
| 4295 | wl_client_post_no_memory(client); |
| 4296 | return; |
| 4297 | } |
Kristian Høgsberg | fd07fb7 | 2011-08-29 15:03:09 -0400 | [diff] [blame] | 4298 | |
Jason Ekstrand | a0d2dde | 2013-06-14 10:08:01 -0500 | [diff] [blame] | 4299 | wl_list_insert(&output->resource_list, wl_resource_get_link(resource)); |
Quentin Glidic | 4ef719c | 2016-07-05 20:44:33 +0200 | [diff] [blame] | 4300 | wl_resource_set_implementation(resource, &output_interface, data, unbind_resource); |
Casey Dahlin | 9074db5 | 2012-04-19 22:50:09 -0400 | [diff] [blame] | 4301 | |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4302 | wl_output_send_geometry(resource, |
| 4303 | output->x, |
| 4304 | output->y, |
| 4305 | output->mm_width, |
| 4306 | output->mm_height, |
| 4307 | output->subpixel, |
Kristian Høgsberg | 0e69647 | 2012-07-22 15:49:57 -0400 | [diff] [blame] | 4308 | output->make, output->model, |
Kristian Høgsberg | 05890dc | 2012-08-10 10:09:20 -0400 | [diff] [blame] | 4309 | output->transform); |
Jasper St. Pierre | 0013a29 | 2014-08-07 16:43:11 -0400 | [diff] [blame] | 4310 | if (version >= WL_OUTPUT_SCALE_SINCE_VERSION) |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 4311 | wl_output_send_scale(resource, |
Hardening | ff39efa | 2013-09-18 23:56:35 +0200 | [diff] [blame] | 4312 | output->current_scale); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 4313 | |
| 4314 | wl_list_for_each (mode, &output->mode_list, link) { |
Kristian Høgsberg | 0b5cd0c | 2012-03-04 21:57:37 -0500 | [diff] [blame] | 4315 | wl_output_send_mode(resource, |
| 4316 | mode->flags, |
| 4317 | mode->width, |
| 4318 | mode->height, |
| 4319 | mode->refresh); |
Kristian Høgsberg | 8f0ce05 | 2011-06-21 11:16:58 -0400 | [diff] [blame] | 4320 | } |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 4321 | |
Jasper St. Pierre | 0013a29 | 2014-08-07 16:43:11 -0400 | [diff] [blame] | 4322 | if (version >= WL_OUTPUT_DONE_SINCE_VERSION) |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 4323 | wl_output_send_done(resource); |
Kristian Høgsberg | 81ce09a | 2008-12-31 16:18:42 -0500 | [diff] [blame] | 4324 | } |
| 4325 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 4326 | /* 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] | 4327 | static void |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 4328 | weston_compositor_reflow_outputs(struct weston_compositor *compositor, |
| 4329 | struct weston_output *resized_output, int delta_width) |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 4330 | { |
| 4331 | struct weston_output *output; |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 4332 | bool start_resizing = false; |
| 4333 | |
| 4334 | if (!delta_width) |
| 4335 | return; |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 4336 | |
| 4337 | wl_list_for_each(output, &compositor->output_list, link) { |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 4338 | if (output == resized_output) { |
| 4339 | start_resizing = true; |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 4340 | continue; |
| 4341 | } |
| 4342 | |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 4343 | if (start_resizing) { |
| 4344 | weston_output_move(output, output->x + delta_width, output->y); |
Zhang, Xiong Y | a4b54c0 | 2013-12-13 22:10:51 +0200 | [diff] [blame] | 4345 | output->dirty = 1; |
| 4346 | } |
| 4347 | } |
| 4348 | } |
| 4349 | |
Pekka Paalanen | d72bad2 | 2017-03-29 17:01:41 +0300 | [diff] [blame] | 4350 | static void |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4351 | weston_output_update_matrix(struct weston_output *output) |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 4352 | { |
Scott Moreau | 850ca42 | 2012-05-21 15:21:25 -0600 | [diff] [blame] | 4353 | float magnification; |
Kristian Høgsberg | 31bd6c7 | 2011-02-13 13:00:51 -0500 | [diff] [blame] | 4354 | |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 4355 | weston_matrix_init(&output->matrix); |
Jason Ekstrand | fb23df7 | 2014-10-16 10:55:21 -0500 | [diff] [blame] | 4356 | weston_matrix_translate(&output->matrix, -output->x, -output->y, 0); |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4357 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4358 | if (output->zoom.active) { |
Scott Moreau | e660398 | 2012-06-11 13:07:51 -0600 | [diff] [blame] | 4359 | magnification = 1 / (1 - output->zoom.spring_z.current); |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 4360 | weston_output_update_zoom(output); |
Neil Roberts | 1e40a7e | 2014-04-25 13:19:37 +0100 | [diff] [blame] | 4361 | weston_matrix_translate(&output->matrix, -output->zoom.trans_x, |
Jason Ekstrand | fb23df7 | 2014-10-16 10:55:21 -0500 | [diff] [blame] | 4362 | -output->zoom.trans_y, 0); |
Neil Roberts | 1e40a7e | 2014-04-25 13:19:37 +0100 | [diff] [blame] | 4363 | weston_matrix_scale(&output->matrix, magnification, |
| 4364 | magnification, 1.0); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4365 | } |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 4366 | |
Jason Ekstrand | fb23df7 | 2014-10-16 10:55:21 -0500 | [diff] [blame] | 4367 | switch (output->transform) { |
| 4368 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 4369 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 4370 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 4371 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 4372 | weston_matrix_translate(&output->matrix, -output->width, 0, 0); |
| 4373 | weston_matrix_scale(&output->matrix, -1, 1, 1); |
| 4374 | break; |
| 4375 | } |
| 4376 | |
| 4377 | switch (output->transform) { |
| 4378 | default: |
| 4379 | case WL_OUTPUT_TRANSFORM_NORMAL: |
| 4380 | case WL_OUTPUT_TRANSFORM_FLIPPED: |
| 4381 | break; |
| 4382 | case WL_OUTPUT_TRANSFORM_90: |
| 4383 | case WL_OUTPUT_TRANSFORM_FLIPPED_90: |
| 4384 | weston_matrix_translate(&output->matrix, 0, -output->height, 0); |
| 4385 | weston_matrix_rotate_xy(&output->matrix, 0, 1); |
| 4386 | break; |
| 4387 | case WL_OUTPUT_TRANSFORM_180: |
| 4388 | case WL_OUTPUT_TRANSFORM_FLIPPED_180: |
| 4389 | weston_matrix_translate(&output->matrix, |
| 4390 | -output->width, -output->height, 0); |
| 4391 | weston_matrix_rotate_xy(&output->matrix, -1, 0); |
| 4392 | break; |
| 4393 | case WL_OUTPUT_TRANSFORM_270: |
| 4394 | case WL_OUTPUT_TRANSFORM_FLIPPED_270: |
| 4395 | weston_matrix_translate(&output->matrix, -output->width, 0, 0); |
| 4396 | weston_matrix_rotate_xy(&output->matrix, 0, -1); |
| 4397 | break; |
| 4398 | } |
| 4399 | |
| 4400 | if (output->current_scale != 1) |
| 4401 | weston_matrix_scale(&output->matrix, |
| 4402 | output->current_scale, |
| 4403 | output->current_scale, 1); |
Neil Roberts | 6c3b01f | 2014-05-06 19:04:15 +0100 | [diff] [blame] | 4404 | |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4405 | output->dirty = 0; |
Derek Foreman | c002321 | 2015-03-24 11:36:13 -0500 | [diff] [blame] | 4406 | |
| 4407 | weston_matrix_invert(&output->inverse_matrix, &output->matrix); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4408 | } |
| 4409 | |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4410 | static void |
Alexander Larsson | 0b13506 | 2013-05-28 16:23:36 +0200 | [diff] [blame] | 4411 | 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] | 4412 | { |
| 4413 | output->transform = transform; |
Pekka Paalanen | 59987fa | 2016-04-26 15:50:59 +0300 | [diff] [blame] | 4414 | output->native_scale = scale; |
| 4415 | output->current_scale = scale; |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4416 | |
Pekka Paalanen | 59987fa | 2016-04-26 15:50:59 +0300 | [diff] [blame] | 4417 | convert_size_by_transform_scale(&output->width, &output->height, |
| 4418 | output->current_mode->width, |
| 4419 | output->current_mode->height, |
| 4420 | transform, scale); |
Alexander Larsson | 4ea9552 | 2013-05-22 14:41:37 +0200 | [diff] [blame] | 4421 | } |
| 4422 | |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 4423 | static void |
| 4424 | weston_output_init_geometry(struct weston_output *output, int x, int y) |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4425 | { |
| 4426 | output->x = x; |
| 4427 | output->y = y; |
| 4428 | |
Ander Conselvan de Oliveira | b8fcca9 | 2012-11-16 17:23:52 +0200 | [diff] [blame] | 4429 | pixman_region32_init(&output->previous_damage); |
Scott Moreau | ccbf29d | 2012-02-22 14:21:41 -0700 | [diff] [blame] | 4430 | pixman_region32_init_rect(&output->region, x, y, |
Scott Moreau | 1bad5db | 2012-08-18 01:04:05 -0600 | [diff] [blame] | 4431 | output->width, |
| 4432 | output->height); |
Benjamin Franzke | 9c26ff3 | 2011-03-15 15:08:41 +0100 | [diff] [blame] | 4433 | } |
| 4434 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 4435 | WL_EXPORT void |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 4436 | weston_output_move(struct weston_output *output, int x, int y) |
| 4437 | { |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 4438 | struct wl_resource *resource; |
| 4439 | |
| 4440 | output->move_x = x - output->x; |
| 4441 | output->move_y = y - output->y; |
| 4442 | |
| 4443 | if (output->move_x == 0 && output->move_y == 0) |
| 4444 | return; |
| 4445 | |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 4446 | weston_output_init_geometry(output, x, y); |
| 4447 | |
| 4448 | output->dirty = 1; |
| 4449 | |
| 4450 | /* Move views on this output. */ |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 4451 | wl_signal_emit(&output->compositor->output_moved_signal, output); |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 4452 | |
| 4453 | /* Notify clients of the change for output position. */ |
Quanxian Wang | b2c8636 | 2014-03-14 09:16:25 +0800 | [diff] [blame] | 4454 | wl_resource_for_each(resource, &output->resource_list) { |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 4455 | wl_output_send_geometry(resource, |
| 4456 | output->x, |
| 4457 | output->y, |
| 4458 | output->mm_width, |
| 4459 | output->mm_height, |
| 4460 | output->subpixel, |
| 4461 | output->make, |
| 4462 | output->model, |
| 4463 | output->transform); |
Quanxian Wang | b2c8636 | 2014-03-14 09:16:25 +0800 | [diff] [blame] | 4464 | |
FORT David | 8a12069 | 2016-04-26 23:34:06 +0200 | [diff] [blame] | 4465 | if (wl_resource_get_version(resource) >= WL_OUTPUT_DONE_SINCE_VERSION) |
Quanxian Wang | b2c8636 | 2014-03-14 09:16:25 +0800 | [diff] [blame] | 4466 | wl_output_send_done(resource); |
| 4467 | } |
Zhang, Xiong Y | f301241 | 2013-12-13 22:10:53 +0200 | [diff] [blame] | 4468 | } |
| 4469 | |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 4470 | /** Signal that a pending output is taken into use. |
| 4471 | * |
| 4472 | * Removes the output from the pending list and adds it to the compositor's |
| 4473 | * list of enabled outputs. The output created signal is emitted. |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 4474 | * |
| 4475 | * \param compositor The compositor instance. |
| 4476 | * \param output The output to be added. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 4477 | * |
| 4478 | * \internal |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 4479 | */ |
Pekka Paalanen | f9681b5 | 2017-03-29 16:58:48 +0300 | [diff] [blame] | 4480 | static void |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 4481 | weston_compositor_add_output(struct weston_compositor *compositor, |
| 4482 | struct weston_output *output) |
| 4483 | { |
Armin Krezović | e540384 | 2016-08-05 15:28:29 +0200 | [diff] [blame] | 4484 | struct weston_view *view, *next; |
| 4485 | |
Pekka Paalanen | 7f340ff | 2017-03-30 14:56:22 +0300 | [diff] [blame] | 4486 | assert(!output->enabled); |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 4487 | wl_list_remove(&output->link); |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 4488 | wl_list_insert(compositor->output_list.prev, &output->link); |
Pekka Paalanen | 7f340ff | 2017-03-30 14:56:22 +0300 | [diff] [blame] | 4489 | output->enabled = true; |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 4490 | |
Giulio Camuffo | b114715 | 2015-05-06 21:41:57 +0300 | [diff] [blame] | 4491 | wl_signal_emit(&compositor->output_created_signal, output); |
Armin Krezović | e540384 | 2016-08-05 15:28:29 +0200 | [diff] [blame] | 4492 | |
| 4493 | wl_list_for_each_safe(view, next, &compositor->view_list, link) |
| 4494 | weston_view_geometry_dirty(view); |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 4495 | } |
| 4496 | |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 4497 | /** Transform device coordinates into global coordinates |
| 4498 | * |
| 4499 | * \param device_x[in] X coordinate in device units. |
| 4500 | * \param device_y[in] Y coordinate in device units. |
| 4501 | * \param x[out] X coordinate in the global space. |
| 4502 | * \param y[out] Y coordinate in the global space. |
| 4503 | * |
| 4504 | * Transforms coordinates from the device coordinate space |
| 4505 | * (physical pixel units) to the global coordinate space (logical pixel units). |
| 4506 | * This takes into account output transform and scale. |
| 4507 | * |
| 4508 | * \memberof weston_output |
| 4509 | * \internal |
| 4510 | */ |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 4511 | WL_EXPORT void |
| 4512 | weston_output_transform_coordinate(struct weston_output *output, |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 4513 | double device_x, double device_y, |
| 4514 | double *x, double *y) |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 4515 | { |
Derek Foreman | 0f67941 | 2014-10-02 13:41:17 -0500 | [diff] [blame] | 4516 | struct weston_vector p = { { |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 4517 | device_x, |
| 4518 | device_y, |
Derek Foreman | 0f67941 | 2014-10-02 13:41:17 -0500 | [diff] [blame] | 4519 | 0.0, |
| 4520 | 1.0 } }; |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 4521 | |
Derek Foreman | 67a18b9 | 2015-03-24 11:36:14 -0500 | [diff] [blame] | 4522 | weston_matrix_transform(&output->inverse_matrix, &p); |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 4523 | |
Giulio Camuffo | 90a6fc6 | 2016-03-22 17:44:54 +0200 | [diff] [blame] | 4524 | *x = p.f[0] / p.f[3]; |
| 4525 | *y = p.f[1] / p.f[3]; |
Kristian Høgsberg | 98c774f | 2013-07-22 14:33:42 -0700 | [diff] [blame] | 4526 | } |
| 4527 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4528 | /** Undoes changes to an output done by weston_output_enable() |
| 4529 | * |
| 4530 | * \param output The weston_output object that needs the changes undone. |
| 4531 | * |
| 4532 | * Removes the repaint timer. |
| 4533 | * Destroys the Wayland global assigned to the output. |
| 4534 | * Destroys pixman regions allocated to the output. |
| 4535 | * Deallocates output's ID and updates compositor's output_id_pool. |
| 4536 | */ |
| 4537 | static void |
| 4538 | weston_output_enable_undo(struct weston_output *output) |
| 4539 | { |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4540 | wl_global_destroy(output->global); |
| 4541 | |
| 4542 | pixman_region32_fini(&output->region); |
| 4543 | pixman_region32_fini(&output->previous_damage); |
| 4544 | output->compositor->output_id_pool &= ~(1u << output->id); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4545 | } |
| 4546 | |
Pekka Paalanen | e6ac4fc | 2017-03-29 16:07:34 +0300 | [diff] [blame] | 4547 | /** Removes output from compositor's list of enabled outputs |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4548 | * |
| 4549 | * \param output The weston_output object that is being removed. |
| 4550 | * |
Pekka Paalanen | e6ac4fc | 2017-03-29 16:07:34 +0300 | [diff] [blame] | 4551 | * The following happens: |
| 4552 | * |
| 4553 | * - The output assignments of all views in the current scenegraph are |
| 4554 | * recomputed. |
| 4555 | * |
| 4556 | * - Presentation feedback is discarded. |
| 4557 | * |
| 4558 | * - Compositor is notified that outputs were changed and |
| 4559 | * applies the necessary changes to re-layout outputs. |
| 4560 | * |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 4561 | * - The output is put back in the pending outputs list. |
| 4562 | * |
Pekka Paalanen | e6ac4fc | 2017-03-29 16:07:34 +0300 | [diff] [blame] | 4563 | * - Signal is emitted to notify all users of the weston_output |
| 4564 | * object that the output is being destroyed. |
| 4565 | * |
| 4566 | * - wl_output protocol objects referencing this weston_output |
| 4567 | * are made inert. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 4568 | * |
| 4569 | * \memberof weston_output |
| 4570 | * \internal |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4571 | */ |
| 4572 | static void |
| 4573 | weston_compositor_remove_output(struct weston_output *output) |
| 4574 | { |
Pekka Paalanen | bccda71 | 2017-03-29 16:16:04 +0300 | [diff] [blame] | 4575 | struct weston_compositor *compositor = output->compositor; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4576 | struct wl_resource *resource; |
| 4577 | struct weston_view *view; |
| 4578 | |
| 4579 | assert(output->destroying); |
Pekka Paalanen | 7f340ff | 2017-03-30 14:56:22 +0300 | [diff] [blame] | 4580 | assert(output->enabled); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4581 | |
Pekka Paalanen | bccda71 | 2017-03-29 16:16:04 +0300 | [diff] [blame] | 4582 | wl_list_for_each(view, &compositor->view_list, link) { |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4583 | if (view->output_mask & (1u << output->id)) |
| 4584 | weston_view_assign_output(view); |
| 4585 | } |
| 4586 | |
| 4587 | weston_presentation_feedback_discard_list(&output->feedback_list); |
| 4588 | |
Pekka Paalanen | bccda71 | 2017-03-29 16:16:04 +0300 | [diff] [blame] | 4589 | weston_compositor_reflow_outputs(compositor, output, output->width); |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 4590 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4591 | wl_list_remove(&output->link); |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 4592 | wl_list_insert(compositor->pending_output_list.prev, &output->link); |
Pekka Paalanen | 7f340ff | 2017-03-30 14:56:22 +0300 | [diff] [blame] | 4593 | output->enabled = false; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4594 | |
Pekka Paalanen | bccda71 | 2017-03-29 16:16:04 +0300 | [diff] [blame] | 4595 | wl_signal_emit(&compositor->output_destroyed_signal, output); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4596 | wl_signal_emit(&output->destroy_signal, output); |
| 4597 | |
| 4598 | wl_resource_for_each(resource, &output->resource_list) { |
| 4599 | wl_resource_set_destructor(resource, NULL); |
| 4600 | } |
| 4601 | } |
| 4602 | |
| 4603 | /** Sets the output scale for a given output. |
| 4604 | * |
| 4605 | * \param output The weston_output object that the scale is set for. |
| 4606 | * \param scale Scale factor for the given output. |
| 4607 | * |
| 4608 | * It only supports setting scale for an output that |
| 4609 | * is not enabled and it can only be ran once. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 4610 | * |
| 4611 | * \memberof weston_output |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4612 | */ |
| 4613 | WL_EXPORT void |
| 4614 | weston_output_set_scale(struct weston_output *output, |
| 4615 | int32_t scale) |
| 4616 | { |
| 4617 | /* We can only set scale on a disabled output */ |
| 4618 | assert(!output->enabled); |
| 4619 | |
| 4620 | /* We only want to set scale once */ |
| 4621 | assert(!output->scale); |
| 4622 | |
| 4623 | output->scale = scale; |
| 4624 | } |
| 4625 | |
| 4626 | /** Sets the output transform for a given output. |
| 4627 | * |
| 4628 | * \param output The weston_output object that the transform is set for. |
| 4629 | * \param transform Transform value for the given output. |
| 4630 | * |
| 4631 | * It only supports setting transform for an output that is |
| 4632 | * not enabled and it can only be ran once. |
| 4633 | * |
| 4634 | * Refer to wl_output::transform section located at |
| 4635 | * https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_output |
| 4636 | * for list of values that can be passed to this function. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 4637 | * |
| 4638 | * \memberof weston_output |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4639 | */ |
| 4640 | WL_EXPORT void |
| 4641 | weston_output_set_transform(struct weston_output *output, |
| 4642 | uint32_t transform) |
| 4643 | { |
| 4644 | /* We can only set transform on a disabled output */ |
| 4645 | assert(!output->enabled); |
| 4646 | |
| 4647 | /* We only want to set transform once */ |
| 4648 | assert(output->transform == UINT32_MAX); |
| 4649 | |
| 4650 | output->transform = transform; |
| 4651 | } |
| 4652 | |
| 4653 | /** Initializes a weston_output object with enough data so |
| 4654 | ** an output can be configured. |
| 4655 | * |
| 4656 | * \param output The weston_output object to initialize |
| 4657 | * \param compositor The compositor instance. |
| 4658 | * |
| 4659 | * Sets initial values for fields that are expected to be |
| 4660 | * configured either by compositors or backends. |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 4661 | * |
| 4662 | * \memberof weston_output |
| 4663 | * \internal |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4664 | */ |
| 4665 | WL_EXPORT void |
Armin Krezović | 4008740 | 2016-09-30 14:11:12 +0200 | [diff] [blame] | 4666 | weston_output_init(struct weston_output *output, |
| 4667 | struct weston_compositor *compositor) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4668 | { |
| 4669 | output->compositor = compositor; |
| 4670 | output->destroying = 0; |
| 4671 | |
| 4672 | /* Backends must set output->name */ |
| 4673 | assert(output->name); |
| 4674 | |
| 4675 | wl_list_init(&output->link); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4676 | output->enabled = false; |
| 4677 | |
| 4678 | /* Add some (in)sane defaults which can be used |
| 4679 | * for checking if an output was properly configured |
| 4680 | */ |
| 4681 | output->mm_width = 0; |
| 4682 | output->mm_height = 0; |
| 4683 | output->scale = 0; |
| 4684 | /* Can't use -1 on uint32_t and 0 is valid enum value */ |
| 4685 | output->transform = UINT32_MAX; |
| 4686 | } |
| 4687 | |
| 4688 | /** Adds weston_output object to pending output list. |
| 4689 | * |
| 4690 | * \param output The weston_output object to add |
| 4691 | * \param compositor The compositor instance. |
| 4692 | * |
| 4693 | * Also notifies the compositor that an output is pending for |
| 4694 | * configuration. |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 4695 | * |
| 4696 | * The opposite of this operation is built into weston_output_destroy(). |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 4697 | * |
| 4698 | * \memberof weston_output |
| 4699 | * \internal |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4700 | */ |
| 4701 | WL_EXPORT void |
| 4702 | weston_compositor_add_pending_output(struct weston_output *output, |
| 4703 | struct weston_compositor *compositor) |
| 4704 | { |
Pekka Paalanen | e952a01 | 2017-03-29 17:14:00 +0300 | [diff] [blame] | 4705 | assert(output->disable); |
| 4706 | assert(output->enable); |
| 4707 | |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 4708 | wl_list_remove(&output->link); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4709 | wl_list_insert(compositor->pending_output_list.prev, &output->link); |
| 4710 | wl_signal_emit(&compositor->output_pending_signal, output); |
| 4711 | } |
| 4712 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4713 | /** Constructs a weston_output object that can be used by the compositor. |
| 4714 | * |
Pekka Paalanen | cc201e4 | 2017-03-30 15:11:25 +0300 | [diff] [blame^] | 4715 | * \param output The weston_output object that needs to be enabled. Must not |
| 4716 | * be enabled already. |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4717 | * |
| 4718 | * Output coordinates are calculated and each new output is by default |
| 4719 | * assigned to the right of previous one. |
| 4720 | * |
| 4721 | * Sets up the transformation, zoom, and geometry of the output using |
| 4722 | * the properties that need to be configured by the compositor. |
| 4723 | * |
| 4724 | * Establishes a repaint timer for the output with the relevant display |
| 4725 | * object's event loop. See output_repaint_timer_handler(). |
| 4726 | * |
| 4727 | * The output is assigned an ID. Weston can support up to 32 distinct |
| 4728 | * outputs, with IDs numbered from 0-31; the compositor's output_id_pool |
| 4729 | * is referred to and used to find the first available ID number, and |
| 4730 | * then this ID is marked as used in output_id_pool. |
| 4731 | * |
| 4732 | * The output is also assigned a Wayland global with the wl_output |
| 4733 | * external interface. |
| 4734 | * |
| 4735 | * Backend specific function is called to set up the output output. |
| 4736 | * |
| 4737 | * Output is added to the compositor's output list |
| 4738 | * |
| 4739 | * If the backend specific function fails, the weston_output object |
| 4740 | * is returned to a state it was before calling this function and |
| 4741 | * is added to the compositor's pending_output_list in case it needs |
| 4742 | * to be reconfigured or just so it can be destroyed at shutdown. |
| 4743 | * |
| 4744 | * 0 is returned on success, -1 on failure. |
| 4745 | */ |
| 4746 | WL_EXPORT int |
| 4747 | weston_output_enable(struct weston_output *output) |
| 4748 | { |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 4749 | struct weston_compositor *c = output->compositor; |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4750 | struct weston_output *iterator; |
| 4751 | int x = 0, y = 0; |
| 4752 | |
Pekka Paalanen | cc201e4 | 2017-03-30 15:11:25 +0300 | [diff] [blame^] | 4753 | if (output->enabled) { |
| 4754 | weston_log("Error: attempt to enable an enabled output '%s'\n", |
| 4755 | output->name); |
| 4756 | return -1; |
| 4757 | } |
| 4758 | |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 4759 | iterator = container_of(c->output_list.prev, |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4760 | struct weston_output, link); |
| 4761 | |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 4762 | if (!wl_list_empty(&c->output_list)) |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4763 | x = iterator->x + iterator->width; |
| 4764 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4765 | /* Make sure the scale is set up */ |
| 4766 | assert(output->scale); |
| 4767 | |
| 4768 | /* Make sure we have a transform set */ |
| 4769 | assert(output->transform != UINT32_MAX); |
| 4770 | |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 4771 | /* Verify we haven't reached the limit of 32 available output IDs */ |
| 4772 | assert(ffs(~c->output_id_pool) > 0); |
| 4773 | |
| 4774 | output->x = x; |
| 4775 | output->y = y; |
| 4776 | output->dirty = 1; |
| 4777 | output->original_scale = output->scale; |
| 4778 | |
| 4779 | weston_output_transform_scale_init(output, output->transform, output->scale); |
| 4780 | weston_output_init_zoom(output); |
| 4781 | |
| 4782 | weston_output_init_geometry(output, x, y); |
| 4783 | weston_output_damage(output); |
| 4784 | |
| 4785 | wl_signal_init(&output->frame_signal); |
| 4786 | wl_signal_init(&output->destroy_signal); |
| 4787 | wl_list_init(&output->animation_list); |
| 4788 | wl_list_init(&output->resource_list); |
| 4789 | wl_list_init(&output->feedback_list); |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 4790 | |
Armin Krezović | 782f5df | 2016-09-30 14:11:11 +0200 | [diff] [blame] | 4791 | /* Invert the output id pool and look for the lowest numbered |
| 4792 | * switch (the least significant bit). Take that bit's position |
| 4793 | * as our ID, and mark it used in the compositor's output_id_pool. |
| 4794 | */ |
| 4795 | output->id = ffs(~output->compositor->output_id_pool) - 1; |
| 4796 | output->compositor->output_id_pool |= 1u << output->id; |
| 4797 | |
| 4798 | output->global = |
| 4799 | wl_global_create(c->wl_display, &wl_output_interface, 3, |
| 4800 | output, bind_output); |
| 4801 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4802 | /* Enable the output (set up the crtc or create a |
| 4803 | * window representing the output, set up the |
| 4804 | * renderer, etc) |
| 4805 | */ |
| 4806 | if (output->enable(output) < 0) { |
| 4807 | weston_log("Enabling output \"%s\" failed.\n", output->name); |
| 4808 | |
| 4809 | weston_output_enable_undo(output); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4810 | return -1; |
| 4811 | } |
| 4812 | |
| 4813 | weston_compositor_add_output(output->compositor, output); |
| 4814 | |
| 4815 | return 0; |
| 4816 | } |
| 4817 | |
| 4818 | /** Converts a weston_output object to a pending output state, so it |
| 4819 | ** can be configured again or destroyed. |
| 4820 | * |
| 4821 | * \param output The weston_output object that needs to be disabled. |
| 4822 | * |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4823 | * Calls a backend specific function to disable an output, in case |
| 4824 | * such function exists. |
| 4825 | * |
Pekka Paalanen | c65df64 | 2017-03-29 15:45:46 +0300 | [diff] [blame] | 4826 | * The backend specific disable function may choose to postpone the disabling |
| 4827 | * by returning a negative value, in which case this function returns early. |
| 4828 | * In that case the backend will guarantee the output will be disabled soon |
| 4829 | * by the backend calling this function again. One must not attempt to re-enable |
| 4830 | * the output until that happens. |
| 4831 | * |
| 4832 | * 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] | 4833 | * from weston's output_list (see weston_compositor_remove_output()) |
| 4834 | * and is returned to a state it was before weston_output_enable() |
| 4835 | * was ran (see weston_output_enable_undo()). |
| 4836 | * |
Pekka Paalanen | c65df64 | 2017-03-29 15:45:46 +0300 | [diff] [blame] | 4837 | * See weston_output_init() for more information on the |
| 4838 | * state output is returned to. |
Pekka Paalanen | cc201e4 | 2017-03-30 15:11:25 +0300 | [diff] [blame^] | 4839 | * |
| 4840 | * If the output has never been enabled yet, this function can still be |
| 4841 | * called to ensure that the output is actually turned off rather than left |
| 4842 | * in the state it was discovered in. |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4843 | */ |
| 4844 | WL_EXPORT void |
| 4845 | weston_output_disable(struct weston_output *output) |
| 4846 | { |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4847 | /* Should we rename this? */ |
| 4848 | output->destroying = 1; |
| 4849 | |
Pekka Paalanen | c65df64 | 2017-03-29 15:45:46 +0300 | [diff] [blame] | 4850 | /* Disable is called unconditionally also for not-enabled outputs, |
| 4851 | * because at compositor start-up, if there is an output that is |
| 4852 | * already on but the compositor wants to turn it off, we have to |
| 4853 | * forward the turn-off to the backend so it knows to do it. |
| 4854 | * The backend cannot initially turn off everything, because it |
| 4855 | * would cause unnecessary mode-sets for all outputs the compositor |
| 4856 | * wants to be on. |
| 4857 | */ |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4858 | if (output->disable(output) < 0) |
| 4859 | return; |
| 4860 | |
| 4861 | if (output->enabled) { |
| 4862 | weston_compositor_remove_output(output); |
| 4863 | weston_output_enable_undo(output); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4864 | } |
| 4865 | |
| 4866 | output->destroying = 0; |
| 4867 | } |
| 4868 | |
| 4869 | /** Emits a signal to indicate that there are outputs waiting to be configured. |
| 4870 | * |
| 4871 | * \param compositor The compositor instance |
| 4872 | */ |
| 4873 | WL_EXPORT void |
| 4874 | weston_pending_output_coldplug(struct weston_compositor *compositor) |
| 4875 | { |
| 4876 | struct weston_output *output, *next; |
| 4877 | |
| 4878 | wl_list_for_each_safe(output, next, &compositor->pending_output_list, link) |
| 4879 | wl_signal_emit(&compositor->output_pending_signal, output); |
| 4880 | } |
| 4881 | |
Pekka Paalanen | ee16ea9 | 2017-03-29 16:53:50 +0300 | [diff] [blame] | 4882 | /** Uninitialize an output |
| 4883 | * |
| 4884 | * Removes the output from the list of enabled outputs if necessary, but |
| 4885 | * does not call the backend's output disable function. The output will no |
| 4886 | * longer be in the list of pending outputs either. |
| 4887 | * |
| 4888 | * All fields of weston_output become uninitialized, i.e. should not be used |
| 4889 | * anymore. The caller can free the memory after this. |
| 4890 | * |
| 4891 | * \memberof weston_output |
| 4892 | * \internal |
| 4893 | */ |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4894 | WL_EXPORT void |
| 4895 | weston_output_destroy(struct weston_output *output) |
| 4896 | { |
| 4897 | output->destroying = 1; |
| 4898 | |
| 4899 | if (output->enabled) { |
| 4900 | weston_compositor_remove_output(output); |
| 4901 | weston_output_enable_undo(output); |
| 4902 | } |
| 4903 | |
Pekka Paalanen | f0ca796 | 2017-03-29 16:20:19 +0300 | [diff] [blame] | 4904 | wl_list_remove(&output->link); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 4905 | free(output->name); |
| 4906 | } |
| 4907 | |
Benjamin Franzke | 315b3dc | 2011-03-08 11:32:57 +0100 | [diff] [blame] | 4908 | static void |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 4909 | destroy_viewport(struct wl_resource *resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 4910 | { |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 4911 | struct weston_surface *surface = |
| 4912 | wl_resource_get_user_data(resource); |
| 4913 | |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 4914 | if (!surface) |
| 4915 | return; |
| 4916 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 4917 | surface->viewport_resource = NULL; |
Pekka Paalanen | f0cad48 | 2014-03-14 14:38:16 +0200 | [diff] [blame] | 4918 | surface->pending.buffer_viewport.buffer.src_width = |
| 4919 | wl_fixed_from_int(-1); |
| 4920 | surface->pending.buffer_viewport.surface.width = -1; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 4921 | surface->pending.buffer_viewport.changed = 1; |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 4922 | } |
| 4923 | |
| 4924 | static void |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 4925 | viewport_destroy(struct wl_client *client, |
| 4926 | struct wl_resource *resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 4927 | { |
| 4928 | wl_resource_destroy(resource); |
| 4929 | } |
| 4930 | |
| 4931 | static void |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 4932 | viewport_set_source(struct wl_client *client, |
| 4933 | struct wl_resource *resource, |
| 4934 | wl_fixed_t src_x, |
| 4935 | wl_fixed_t src_y, |
| 4936 | wl_fixed_t src_width, |
| 4937 | wl_fixed_t src_height) |
| 4938 | { |
| 4939 | struct weston_surface *surface = |
| 4940 | wl_resource_get_user_data(resource); |
| 4941 | |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 4942 | if (!surface) { |
| 4943 | wl_resource_post_error(resource, |
| 4944 | WP_VIEWPORT_ERROR_NO_SURFACE, |
| 4945 | "wl_surface for this viewport is no longer exists"); |
| 4946 | return; |
| 4947 | } |
| 4948 | |
| 4949 | assert(surface->viewport_resource == resource); |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 4950 | assert(surface->resource); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 4951 | |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 4952 | if (src_width == wl_fixed_from_int(-1) && |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 4953 | src_height == wl_fixed_from_int(-1) && |
| 4954 | src_x == wl_fixed_from_int(-1) && |
| 4955 | src_y == wl_fixed_from_int(-1)) { |
| 4956 | /* unset source rect */ |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 4957 | surface->pending.buffer_viewport.buffer.src_width = |
| 4958 | wl_fixed_from_int(-1); |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 4959 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 4960 | return; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 4961 | } |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 4962 | |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 4963 | 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] | 4964 | wl_resource_post_error(resource, |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 4965 | WP_VIEWPORT_ERROR_BAD_VALUE, |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 4966 | "wl_surface@%d viewport source " |
| 4967 | "w=%f <= 0, h=%f <= 0, x=%f < 0, or y=%f < 0", |
| 4968 | wl_resource_get_id(surface->resource), |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 4969 | wl_fixed_to_double(src_width), |
Pekka Paalanen | 201769a | 2016-04-26 14:42:11 +0300 | [diff] [blame] | 4970 | wl_fixed_to_double(src_height), |
| 4971 | wl_fixed_to_double(src_x), |
| 4972 | wl_fixed_to_double(src_y)); |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 4973 | return; |
| 4974 | } |
| 4975 | |
| 4976 | surface->pending.buffer_viewport.buffer.src_x = src_x; |
| 4977 | surface->pending.buffer_viewport.buffer.src_y = src_y; |
| 4978 | surface->pending.buffer_viewport.buffer.src_width = src_width; |
| 4979 | surface->pending.buffer_viewport.buffer.src_height = src_height; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 4980 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 4981 | } |
| 4982 | |
| 4983 | static void |
| 4984 | viewport_set_destination(struct wl_client *client, |
| 4985 | struct wl_resource *resource, |
| 4986 | int32_t dst_width, |
| 4987 | int32_t dst_height) |
| 4988 | { |
| 4989 | struct weston_surface *surface = |
| 4990 | wl_resource_get_user_data(resource); |
| 4991 | |
Pekka Paalanen | 4826f87 | 2016-04-22 14:14:38 +0300 | [diff] [blame] | 4992 | if (!surface) { |
| 4993 | wl_resource_post_error(resource, |
| 4994 | WP_VIEWPORT_ERROR_NO_SURFACE, |
| 4995 | "wl_surface for this viewport no longer exists"); |
| 4996 | return; |
| 4997 | } |
| 4998 | |
| 4999 | assert(surface->viewport_resource == resource); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 5000 | |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 5001 | if (dst_width == -1 && dst_height == -1) { |
| 5002 | /* unset destination size */ |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 5003 | surface->pending.buffer_viewport.surface.width = -1; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 5004 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 5005 | return; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 5006 | } |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 5007 | |
| 5008 | if (dst_width <= 0 || dst_height <= 0) { |
| 5009 | wl_resource_post_error(resource, |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 5010 | WP_VIEWPORT_ERROR_BAD_VALUE, |
Pekka Paalanen | 2c8b5f5 | 2014-04-04 14:22:12 +0300 | [diff] [blame] | 5011 | "destination size must be positive (%dx%d)", |
| 5012 | dst_width, dst_height); |
| 5013 | return; |
| 5014 | } |
| 5015 | |
| 5016 | surface->pending.buffer_viewport.surface.width = dst_width; |
| 5017 | surface->pending.buffer_viewport.surface.height = dst_height; |
George Kiagiadakis | 8f9e87f | 2014-06-13 18:14:20 +0200 | [diff] [blame] | 5018 | surface->pending.buffer_viewport.changed = 1; |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 5019 | } |
| 5020 | |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 5021 | static const struct wp_viewport_interface viewport_interface = { |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 5022 | viewport_destroy, |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 5023 | viewport_set_source, |
| 5024 | viewport_set_destination |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 5025 | }; |
| 5026 | |
| 5027 | static void |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 5028 | viewporter_destroy(struct wl_client *client, |
| 5029 | struct wl_resource *resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 5030 | { |
| 5031 | wl_resource_destroy(resource); |
| 5032 | } |
| 5033 | |
| 5034 | static void |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 5035 | viewporter_get_viewport(struct wl_client *client, |
| 5036 | struct wl_resource *viewporter, |
| 5037 | uint32_t id, |
| 5038 | struct wl_resource *surface_resource) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 5039 | { |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 5040 | int version = wl_resource_get_version(viewporter); |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 5041 | struct weston_surface *surface = |
| 5042 | wl_resource_get_user_data(surface_resource); |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 5043 | struct wl_resource *resource; |
| 5044 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 5045 | if (surface->viewport_resource) { |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 5046 | wl_resource_post_error(viewporter, |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 5047 | WP_VIEWPORTER_ERROR_VIEWPORT_EXISTS, |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 5048 | "a viewport for that surface already exists"); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 5049 | return; |
| 5050 | } |
| 5051 | |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 5052 | resource = wl_resource_create(client, &wp_viewport_interface, |
Pekka Paalanen | 0b4c535 | 2014-03-14 14:38:17 +0200 | [diff] [blame] | 5053 | version, id); |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 5054 | if (resource == NULL) { |
| 5055 | wl_client_post_no_memory(client); |
| 5056 | return; |
| 5057 | } |
| 5058 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 5059 | wl_resource_set_implementation(resource, &viewport_interface, |
| 5060 | surface, destroy_viewport); |
Jonny Lamb | 7413076 | 2013-11-26 18:19:46 +0100 | [diff] [blame] | 5061 | |
Pekka Paalanen | b0420ae | 2014-01-08 15:39:17 +0200 | [diff] [blame] | 5062 | surface->viewport_resource = resource; |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 5063 | } |
| 5064 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 5065 | static const struct wp_viewporter_interface viewporter_interface = { |
| 5066 | viewporter_destroy, |
| 5067 | viewporter_get_viewport |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 5068 | }; |
| 5069 | |
| 5070 | static void |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 5071 | bind_viewporter(struct wl_client *client, |
| 5072 | void *data, uint32_t version, uint32_t id) |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 5073 | { |
| 5074 | struct wl_resource *resource; |
| 5075 | |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 5076 | resource = wl_resource_create(client, &wp_viewporter_interface, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 5077 | version, id); |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 5078 | if (resource == NULL) { |
| 5079 | wl_client_post_no_memory(client); |
| 5080 | return; |
| 5081 | } |
| 5082 | |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 5083 | wl_resource_set_implementation(resource, &viewporter_interface, |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 5084 | NULL, NULL); |
| 5085 | } |
| 5086 | |
| 5087 | static void |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 5088 | destroy_presentation_feedback(struct wl_resource *feedback_resource) |
| 5089 | { |
| 5090 | struct weston_presentation_feedback *feedback; |
| 5091 | |
| 5092 | feedback = wl_resource_get_user_data(feedback_resource); |
| 5093 | |
| 5094 | wl_list_remove(&feedback->link); |
| 5095 | free(feedback); |
| 5096 | } |
| 5097 | |
| 5098 | static void |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 5099 | presentation_destroy(struct wl_client *client, struct wl_resource *resource) |
| 5100 | { |
| 5101 | wl_resource_destroy(resource); |
| 5102 | } |
| 5103 | |
| 5104 | static void |
| 5105 | presentation_feedback(struct wl_client *client, |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 5106 | struct wl_resource *presentation_resource, |
| 5107 | struct wl_resource *surface_resource, |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 5108 | uint32_t callback) |
| 5109 | { |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 5110 | struct weston_surface *surface; |
| 5111 | struct weston_presentation_feedback *feedback; |
| 5112 | |
| 5113 | surface = wl_resource_get_user_data(surface_resource); |
| 5114 | |
Bryce Harrington | de16d89 | 2014-11-20 22:21:57 -0800 | [diff] [blame] | 5115 | feedback = zalloc(sizeof *feedback); |
| 5116 | if (feedback == NULL) |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 5117 | goto err_calloc; |
| 5118 | |
| 5119 | feedback->resource = wl_resource_create(client, |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 5120 | &wp_presentation_feedback_interface, |
Pekka Paalanen | 133e439 | 2014-09-23 22:08:46 -0400 | [diff] [blame] | 5121 | 1, callback); |
| 5122 | if (!feedback->resource) |
| 5123 | goto err_create; |
| 5124 | |
| 5125 | wl_resource_set_implementation(feedback->resource, NULL, feedback, |
| 5126 | destroy_presentation_feedback); |
| 5127 | |
| 5128 | wl_list_insert(&surface->pending.feedback_list, &feedback->link); |
| 5129 | |
| 5130 | return; |
| 5131 | |
| 5132 | err_create: |
| 5133 | free(feedback); |
| 5134 | |
| 5135 | err_calloc: |
| 5136 | wl_client_post_no_memory(client); |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 5137 | } |
| 5138 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 5139 | static const struct wp_presentation_interface presentation_implementation = { |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 5140 | presentation_destroy, |
| 5141 | presentation_feedback |
| 5142 | }; |
| 5143 | |
| 5144 | static void |
| 5145 | bind_presentation(struct wl_client *client, |
| 5146 | void *data, uint32_t version, uint32_t id) |
| 5147 | { |
| 5148 | struct weston_compositor *compositor = data; |
| 5149 | struct wl_resource *resource; |
| 5150 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 5151 | resource = wl_resource_create(client, &wp_presentation_interface, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 5152 | version, id); |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 5153 | if (resource == NULL) { |
| 5154 | wl_client_post_no_memory(client); |
| 5155 | return; |
| 5156 | } |
| 5157 | |
| 5158 | wl_resource_set_implementation(resource, &presentation_implementation, |
| 5159 | compositor, NULL); |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 5160 | wp_presentation_send_clock_id(resource, compositor->presentation_clock); |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 5161 | } |
| 5162 | |
| 5163 | static void |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 5164 | compositor_bind(struct wl_client *client, |
| 5165 | void *data, uint32_t version, uint32_t id) |
| 5166 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5167 | struct weston_compositor *compositor = data; |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5168 | struct wl_resource *resource; |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 5169 | |
Jason Ekstrand | a85118c | 2013-06-27 20:17:02 -0500 | [diff] [blame] | 5170 | resource = wl_resource_create(client, &wl_compositor_interface, |
Derek Foreman | 1909c10 | 2015-11-26 14:17:47 -0600 | [diff] [blame] | 5171 | version, id); |
Kristian Høgsberg | 0ff7908 | 2013-08-06 16:46:25 -0700 | [diff] [blame] | 5172 | if (resource == NULL) { |
| 5173 | wl_client_post_no_memory(client); |
| 5174 | return; |
| 5175 | } |
| 5176 | |
| 5177 | wl_resource_set_implementation(resource, &compositor_interface, |
| 5178 | compositor, NULL); |
Kristian Høgsberg | a887312 | 2011-11-23 10:39:34 -0500 | [diff] [blame] | 5179 | } |
| 5180 | |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5181 | WL_EXPORT int |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 5182 | weston_environment_get_fd(const char *env) |
| 5183 | { |
Bryce Harrington | 25a2bdd | 2016-08-03 17:40:52 -0700 | [diff] [blame] | 5184 | char *e; |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 5185 | int fd, flags; |
| 5186 | |
| 5187 | e = getenv(env); |
Bryce Harrington | 25a2bdd | 2016-08-03 17:40:52 -0700 | [diff] [blame] | 5188 | if (!e || !safe_strtoint(e, &fd)) |
Ander Conselvan de Oliveira | cbdebc2 | 2013-02-21 18:35:16 +0200 | [diff] [blame] | 5189 | return -1; |
| 5190 | |
| 5191 | flags = fcntl(fd, F_GETFD); |
| 5192 | if (flags == -1) |
| 5193 | return -1; |
| 5194 | |
| 5195 | fcntl(fd, F_SETFD, flags | FD_CLOEXEC); |
| 5196 | unsetenv(env); |
| 5197 | |
| 5198 | return fd; |
| 5199 | } |
| 5200 | |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 5201 | static void |
Derek Foreman | 8ae2db5 | 2015-07-15 13:00:36 -0500 | [diff] [blame] | 5202 | timeline_key_binding_handler(struct weston_keyboard *keyboard, uint32_t time, |
Pekka Paalanen | b502654 | 2014-11-12 15:09:24 +0200 | [diff] [blame] | 5203 | uint32_t key, void *data) |
| 5204 | { |
| 5205 | struct weston_compositor *compositor = data; |
| 5206 | |
| 5207 | if (weston_timeline_enabled_) |
| 5208 | weston_timeline_close(); |
| 5209 | else |
| 5210 | weston_timeline_open(compositor); |
| 5211 | } |
| 5212 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 5213 | /** Create the compositor. |
| 5214 | * |
| 5215 | * This functions creates and initializes a compositor instance. |
| 5216 | * |
| 5217 | * \param display The Wayland display to be used. |
| 5218 | * \param user_data A pointer to an object that can later be retrieved |
| 5219 | * using the \ref weston_compositor_get_user_data function. |
| 5220 | * \return The compositor instance on success or NULL on failure. |
| 5221 | */ |
| 5222 | WL_EXPORT struct weston_compositor * |
| 5223 | weston_compositor_create(struct wl_display *display, void *user_data) |
Kristian Høgsberg | ce5325d | 2010-06-14 11:54:00 -0400 | [diff] [blame] | 5224 | { |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 5225 | struct weston_compositor *ec; |
Kristian Høgsberg | fbdbbdc | 2008-11-28 17:06:06 -0500 | [diff] [blame] | 5226 | struct wl_event_loop *loop; |
Ossama Othman | a50e6e4 | 2013-05-14 09:48:26 -0700 | [diff] [blame] | 5227 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 5228 | ec = zalloc(sizeof *ec); |
| 5229 | if (!ec) |
| 5230 | return NULL; |
| 5231 | |
| 5232 | ec->wl_display = display; |
| 5233 | ec->user_data = user_data; |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5234 | wl_signal_init(&ec->destroy_signal); |
Kristian Høgsberg | f03a04a | 2014-04-06 22:04:50 -0700 | [diff] [blame] | 5235 | wl_signal_init(&ec->create_surface_signal); |
Kristian Høgsberg | 02e79dc | 2012-04-12 09:55:26 -0400 | [diff] [blame] | 5236 | wl_signal_init(&ec->activate_signal); |
Tiago Vignatti | fb2adba | 2013-06-12 15:43:21 -0300 | [diff] [blame] | 5237 | wl_signal_init(&ec->transform_signal); |
Tiago Vignatti | 1d01b01 | 2012-09-27 17:48:36 +0300 | [diff] [blame] | 5238 | wl_signal_init(&ec->kill_signal); |
Ander Conselvan de Oliveira | a457563 | 2013-02-21 18:35:23 +0200 | [diff] [blame] | 5239 | wl_signal_init(&ec->idle_signal); |
| 5240 | wl_signal_init(&ec->wake_signal); |
Jan Arne Petersen | 42feced | 2012-06-21 21:52:17 +0200 | [diff] [blame] | 5241 | wl_signal_init(&ec->show_input_panel_signal); |
| 5242 | wl_signal_init(&ec->hide_input_panel_signal); |
Jan Arne Petersen | 14da96b | 2013-04-18 16:47:28 +0200 | [diff] [blame] | 5243 | wl_signal_init(&ec->update_input_panel_signal); |
Jan Arne Petersen | 674fd1d | 2012-11-18 19:06:42 +0100 | [diff] [blame] | 5244 | wl_signal_init(&ec->seat_created_signal); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5245 | wl_signal_init(&ec->output_pending_signal); |
Richard Hughes | 59d5da7 | 2013-05-01 21:52:11 +0100 | [diff] [blame] | 5246 | wl_signal_init(&ec->output_created_signal); |
Ander Conselvan de Oliveira | f84327a | 2014-01-29 18:47:51 +0200 | [diff] [blame] | 5247 | wl_signal_init(&ec->output_destroyed_signal); |
Ander Conselvan de Oliveira | a8a9baf | 2014-01-29 18:47:52 +0200 | [diff] [blame] | 5248 | wl_signal_init(&ec->output_moved_signal); |
David Fort | 0de859e | 2016-05-27 23:22:57 +0200 | [diff] [blame] | 5249 | wl_signal_init(&ec->output_resized_signal); |
Kristian Høgsberg | 61741a2 | 2013-09-17 16:02:57 -0700 | [diff] [blame] | 5250 | wl_signal_init(&ec->session_signal); |
| 5251 | ec->session_active = 1; |
Kristian Høgsberg | 16eb675 | 2008-10-08 22:51:32 -0400 | [diff] [blame] | 5252 | |
Casey Dahlin | 58ba137 | 2012-04-19 22:50:08 -0400 | [diff] [blame] | 5253 | ec->output_id_pool = 0; |
Giulio Camuffo | bab996e | 2014-10-12 00:24:25 +0300 | [diff] [blame] | 5254 | ec->repaint_msec = DEFAULT_REPAINT_WINDOW; |
Casey Dahlin | 58ba137 | 2012-04-19 22:50:08 -0400 | [diff] [blame] | 5255 | |
Jonas Ådahl | 94e2e2d | 2014-10-18 18:42:19 +0200 | [diff] [blame] | 5256 | ec->activate_serial = 1; |
| 5257 | |
Derek Foreman | 152254b | 2015-11-26 14:17:48 -0600 | [diff] [blame] | 5258 | if (!wl_global_create(ec->wl_display, &wl_compositor_interface, 4, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5259 | ec, compositor_bind)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 5260 | goto fail; |
Kristian Høgsberg | ee02ca6 | 2008-12-21 23:37:12 -0500 | [diff] [blame] | 5261 | |
Giulio Camuffo | 954f183 | 2014-10-11 18:27:30 +0300 | [diff] [blame] | 5262 | if (!wl_global_create(ec->wl_display, &wl_subcompositor_interface, 1, |
Kristian Høgsberg | 919cddb | 2013-07-08 19:03:57 -0400 | [diff] [blame] | 5263 | ec, bind_subcompositor)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 5264 | goto fail; |
Pekka Paalanen | e67858b | 2013-04-25 13:57:42 +0300 | [diff] [blame] | 5265 | |
Pekka Paalanen | e95ad5c | 2016-04-15 14:47:08 +0300 | [diff] [blame] | 5266 | if (!wl_global_create(ec->wl_display, &wp_viewporter_interface, 1, |
Pekka Paalanen | 9c5a0d9 | 2016-04-15 16:42:49 +0300 | [diff] [blame] | 5267 | ec, bind_viewporter)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 5268 | goto fail; |
Jonny Lamb | 8ae3590 | 2013-11-26 18:19:45 +0100 | [diff] [blame] | 5269 | |
Pekka Paalanen | b00c79b | 2016-02-18 16:53:27 +0200 | [diff] [blame] | 5270 | if (!wl_global_create(ec->wl_display, &wp_presentation_interface, 1, |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 5271 | ec, bind_presentation)) |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 5272 | goto fail; |
Pekka Paalanen | 31f7d78 | 2014-09-23 22:08:43 -0400 | [diff] [blame] | 5273 | |
Jonas Ådahl | 30d61d8 | 2014-10-22 21:21:17 +0200 | [diff] [blame] | 5274 | if (weston_input_init(ec) != 0) |
| 5275 | goto fail; |
| 5276 | |
Jason Ekstrand | a7af704 | 2013-10-12 22:38:11 -0500 | [diff] [blame] | 5277 | wl_list_init(&ec->view_list); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 5278 | wl_list_init(&ec->plane_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 5279 | wl_list_init(&ec->layer_list); |
| 5280 | wl_list_init(&ec->seat_list); |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5281 | wl_list_init(&ec->pending_output_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 5282 | wl_list_init(&ec->output_list); |
| 5283 | wl_list_init(&ec->key_binding_list); |
Daniel Stone | 96d47c0 | 2013-11-19 11:37:12 +0100 | [diff] [blame] | 5284 | wl_list_init(&ec->modifier_binding_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 5285 | wl_list_init(&ec->button_binding_list); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5286 | wl_list_init(&ec->touch_binding_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 5287 | wl_list_init(&ec->axis_binding_list); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5288 | wl_list_init(&ec->debug_binding_list); |
Daniel Stone | 725c2c3 | 2012-06-22 14:04:36 +0100 | [diff] [blame] | 5289 | |
Pekka Paalanen | 827b5d2 | 2016-06-29 11:54:26 +0200 | [diff] [blame] | 5290 | wl_list_init(&ec->plugin_api_list); |
| 5291 | |
Xiong Zhang | 9711653 | 2013-10-23 13:58:31 +0800 | [diff] [blame] | 5292 | weston_plane_init(&ec->primary_plane, ec, 0, 0); |
Ander Conselvan de Oliveira | 8ad1982 | 2013-03-05 17:30:27 +0200 | [diff] [blame] | 5293 | weston_compositor_stack_plane(ec, &ec->primary_plane, NULL); |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 5294 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 5295 | wl_data_device_manager_init(ec->wl_display); |
| 5296 | |
| 5297 | wl_display_init_shm(ec->wl_display); |
| 5298 | |
| 5299 | loop = wl_display_get_event_loop(ec->wl_display); |
| 5300 | ec->idle_source = wl_event_loop_add_timer(loop, idle_handler, ec); |
Daniel Stone | 6847b85 | 2017-03-01 11:34:08 +0000 | [diff] [blame] | 5301 | ec->repaint_timer = |
| 5302 | wl_event_loop_add_timer(loop, output_repaint_timer_handler, |
| 5303 | ec); |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 5304 | |
Quentin Glidic | 8268157 | 2016-12-17 13:40:51 +0100 | [diff] [blame] | 5305 | weston_layer_init(&ec->fade_layer, ec); |
| 5306 | weston_layer_init(&ec->cursor_layer, ec); |
| 5307 | |
| 5308 | weston_layer_set_position(&ec->fade_layer, WESTON_LAYER_POSITION_FADE); |
| 5309 | weston_layer_set_position(&ec->cursor_layer, |
| 5310 | WESTON_LAYER_POSITION_CURSOR); |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 5311 | |
| 5312 | weston_compositor_add_debug_binding(ec, KEY_T, |
| 5313 | timeline_key_binding_handler, ec); |
| 5314 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 5315 | return ec; |
| 5316 | |
| 5317 | fail: |
| 5318 | free(ec); |
| 5319 | return NULL; |
| 5320 | } |
| 5321 | |
Benjamin Franzke | b826302 | 2011-08-30 11:32:47 +0200 | [diff] [blame] | 5322 | WL_EXPORT void |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5323 | weston_compositor_shutdown(struct weston_compositor *ec) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 5324 | { |
Kristian Høgsberg | 8334bc1 | 2012-01-03 10:29:47 -0500 | [diff] [blame] | 5325 | struct weston_output *output, *next; |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 5326 | |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 5327 | wl_event_source_remove(ec->idle_source); |
| 5328 | |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 5329 | /* Destroy all outputs associated with this compositor */ |
Tiago Vignatti | b303a1d | 2011-12-18 22:27:40 +0200 | [diff] [blame] | 5330 | wl_list_for_each_safe(output, next, &ec->output_list, link) |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 5331 | output->destroy(output); |
Pekka Paalanen | 4738f3b | 2012-01-02 15:47:07 +0200 | [diff] [blame] | 5332 | |
Armin Krezović | a01ab6d | 2016-09-30 14:11:02 +0200 | [diff] [blame] | 5333 | /* Destroy all pending outputs associated with this compositor */ |
| 5334 | wl_list_for_each_safe(output, next, &ec->pending_output_list, link) |
| 5335 | output->destroy(output); |
| 5336 | |
Ander Conselvan de Oliveira | 1853676 | 2013-12-20 21:07:00 +0200 | [diff] [blame] | 5337 | if (ec->renderer) |
| 5338 | ec->renderer->destroy(ec); |
| 5339 | |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5340 | weston_binding_list_destroy_all(&ec->key_binding_list); |
Ryo Munakata | 27135af | 2015-07-17 13:07:42 +0900 | [diff] [blame] | 5341 | weston_binding_list_destroy_all(&ec->modifier_binding_list); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5342 | weston_binding_list_destroy_all(&ec->button_binding_list); |
Neil Roberts | a28c693 | 2013-10-03 16:43:04 +0100 | [diff] [blame] | 5343 | weston_binding_list_destroy_all(&ec->touch_binding_list); |
Daniel Stone | 325fc2d | 2012-05-30 16:31:58 +0100 | [diff] [blame] | 5344 | weston_binding_list_destroy_all(&ec->axis_binding_list); |
Ander Conselvan de Oliveira | c509d2b | 2012-11-08 17:20:45 +0200 | [diff] [blame] | 5345 | weston_binding_list_destroy_all(&ec->debug_binding_list); |
Pekka Paalanen | d1591ae | 2012-01-02 16:06:56 +0200 | [diff] [blame] | 5346 | |
Kristian Høgsberg | 65a11e1 | 2012-08-03 11:30:18 -0400 | [diff] [blame] | 5347 | weston_plane_release(&ec->primary_plane); |
Matt Roper | 361d2ad | 2011-08-29 13:52:23 -0700 | [diff] [blame] | 5348 | } |
| 5349 | |
Kristian Høgsberg | af4f2aa | 2013-02-15 20:53:20 -0500 | [diff] [blame] | 5350 | WL_EXPORT void |
Frederic Plourde | c336f06 | 2014-10-29 14:44:33 -0400 | [diff] [blame] | 5351 | weston_compositor_exit_with_code(struct weston_compositor *compositor, |
| 5352 | int exit_code) |
| 5353 | { |
Pekka Paalanen | f5ef88f | 2014-11-18 15:57:04 +0200 | [diff] [blame] | 5354 | if (compositor->exit_code == EXIT_SUCCESS) |
| 5355 | compositor->exit_code = exit_code; |
| 5356 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 5357 | weston_compositor_exit(compositor); |
Frederic Plourde | c336f06 | 2014-10-29 14:44:33 -0400 | [diff] [blame] | 5358 | } |
| 5359 | |
| 5360 | WL_EXPORT void |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 5361 | weston_compositor_set_default_pointer_grab(struct weston_compositor *ec, |
| 5362 | const struct weston_pointer_grab_interface *interface) |
| 5363 | { |
| 5364 | struct weston_seat *seat; |
| 5365 | |
| 5366 | ec->default_pointer_grab = interface; |
| 5367 | wl_list_for_each(seat, &ec->seat_list, link) { |
Derek Foreman | 1281a36 | 2015-07-31 16:55:32 -0500 | [diff] [blame] | 5368 | struct weston_pointer *pointer = weston_seat_get_pointer(seat); |
| 5369 | |
| 5370 | if (pointer) |
| 5371 | weston_pointer_set_default_grab(pointer, interface); |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 5372 | } |
| 5373 | } |
| 5374 | |
Pekka Paalanen | b5eedad | 2014-09-23 22:08:45 -0400 | [diff] [blame] | 5375 | WL_EXPORT int |
| 5376 | weston_compositor_set_presentation_clock(struct weston_compositor *compositor, |
| 5377 | clockid_t clk_id) |
| 5378 | { |
| 5379 | struct timespec ts; |
| 5380 | |
| 5381 | if (clock_gettime(clk_id, &ts) < 0) |
| 5382 | return -1; |
| 5383 | |
| 5384 | compositor->presentation_clock = clk_id; |
| 5385 | |
| 5386 | return 0; |
| 5387 | } |
| 5388 | |
| 5389 | /* |
| 5390 | * For choosing the software clock, when the display hardware or API |
| 5391 | * does not expose a compatible presentation timestamp. |
| 5392 | */ |
| 5393 | WL_EXPORT int |
| 5394 | weston_compositor_set_presentation_clock_software( |
| 5395 | struct weston_compositor *compositor) |
| 5396 | { |
| 5397 | /* In order of preference */ |
| 5398 | static const clockid_t clocks[] = { |
| 5399 | CLOCK_MONOTONIC_RAW, /* no jumps, no crawling */ |
| 5400 | CLOCK_MONOTONIC_COARSE, /* no jumps, may crawl, fast & coarse */ |
| 5401 | CLOCK_MONOTONIC, /* no jumps, may crawl */ |
| 5402 | CLOCK_REALTIME_COARSE, /* may jump and crawl, fast & coarse */ |
| 5403 | CLOCK_REALTIME /* may jump and crawl */ |
| 5404 | }; |
| 5405 | unsigned i; |
| 5406 | |
| 5407 | for (i = 0; i < ARRAY_LENGTH(clocks); i++) |
| 5408 | if (weston_compositor_set_presentation_clock(compositor, |
| 5409 | clocks[i]) == 0) |
| 5410 | return 0; |
| 5411 | |
| 5412 | weston_log("Error: no suitable presentation clock available.\n"); |
| 5413 | |
| 5414 | return -1; |
| 5415 | } |
| 5416 | |
Pekka Paalanen | 662f384 | 2015-03-18 12:17:26 +0200 | [diff] [blame] | 5417 | /** Read the current time from the Presentation clock |
| 5418 | * |
| 5419 | * \param compositor |
| 5420 | * \param ts[out] The current time. |
| 5421 | * |
| 5422 | * \note Reading the current time in user space is always imprecise to some |
| 5423 | * degree. |
| 5424 | * |
| 5425 | * This function is never meant to fail. If reading the clock does fail, |
| 5426 | * an error message is logged and a zero time is returned. Callers are not |
| 5427 | * supposed to detect or react to failures. |
| 5428 | */ |
| 5429 | WL_EXPORT void |
| 5430 | weston_compositor_read_presentation_clock( |
| 5431 | const struct weston_compositor *compositor, |
| 5432 | struct timespec *ts) |
| 5433 | { |
| 5434 | static bool warned; |
| 5435 | int ret; |
| 5436 | |
| 5437 | ret = clock_gettime(compositor->presentation_clock, ts); |
| 5438 | if (ret < 0) { |
| 5439 | ts->tv_sec = 0; |
| 5440 | ts->tv_nsec = 0; |
| 5441 | |
| 5442 | if (!warned) |
| 5443 | weston_log("Error: failure to read " |
| 5444 | "the presentation clock %#x: '%m' (%d)\n", |
| 5445 | compositor->presentation_clock, errno); |
| 5446 | warned = true; |
| 5447 | } |
| 5448 | } |
| 5449 | |
Pekka Paalanen | 230f3b1 | 2014-09-29 14:18:40 -0400 | [diff] [blame] | 5450 | /** Import dmabuf buffer into current renderer |
| 5451 | * |
| 5452 | * \param compositor |
| 5453 | * \param buffer the dmabuf buffer to import |
| 5454 | * \return true on usable buffers, false otherwise |
| 5455 | * |
| 5456 | * This function tests that the linux_dmabuf_buffer is usable |
| 5457 | * for the current renderer. Returns false on unusable buffers. Usually |
| 5458 | * usability is tested by importing the dmabufs for composition. |
| 5459 | * |
| 5460 | * This hook is also used for detecting if the renderer supports |
| 5461 | * dmabufs at all. If the renderer hook is NULL, dmabufs are not |
| 5462 | * supported. |
| 5463 | * */ |
| 5464 | WL_EXPORT bool |
| 5465 | weston_compositor_import_dmabuf(struct weston_compositor *compositor, |
| 5466 | struct linux_dmabuf_buffer *buffer) |
| 5467 | { |
| 5468 | struct weston_renderer *renderer; |
| 5469 | |
| 5470 | renderer = compositor->renderer; |
| 5471 | |
| 5472 | if (renderer->import_dmabuf == NULL) |
| 5473 | return false; |
| 5474 | |
| 5475 | return renderer->import_dmabuf(compositor, buffer); |
| 5476 | } |
| 5477 | |
Giulio Camuffo | cdb4d29 | 2013-11-14 23:42:53 +0100 | [diff] [blame] | 5478 | WL_EXPORT void |
Kristian Høgsberg | af4f2aa | 2013-02-15 20:53:20 -0500 | [diff] [blame] | 5479 | weston_version(int *major, int *minor, int *micro) |
| 5480 | { |
| 5481 | *major = WESTON_VERSION_MAJOR; |
| 5482 | *minor = WESTON_VERSION_MINOR; |
| 5483 | *micro = WESTON_VERSION_MICRO; |
| 5484 | } |
| 5485 | |
Ander Conselvan de Oliveira | 97f2952 | 2013-10-14 15:57:11 +0300 | [diff] [blame] | 5486 | WL_EXPORT void * |
| 5487 | weston_load_module(const char *name, const char *entrypoint) |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5488 | { |
Derek Foreman | 3f86e50 | 2015-06-08 11:46:54 -0500 | [diff] [blame] | 5489 | const char *builddir = getenv("WESTON_BUILD_DIR"); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5490 | char path[PATH_MAX]; |
| 5491 | void *module, *init; |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 5492 | size_t len; |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5493 | |
U. Artie Eoff | 2e2384a | 2014-01-17 13:19:01 -0800 | [diff] [blame] | 5494 | if (name == NULL) |
| 5495 | return NULL; |
| 5496 | |
Derek Foreman | 3f86e50 | 2015-06-08 11:46:54 -0500 | [diff] [blame] | 5497 | if (name[0] != '/') { |
| 5498 | if (builddir) |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 5499 | len = snprintf(path, sizeof path, "%s/.libs/%s", |
| 5500 | builddir, name); |
Derek Foreman | 3f86e50 | 2015-06-08 11:46:54 -0500 | [diff] [blame] | 5501 | else |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 5502 | len = snprintf(path, sizeof path, "%s/%s", |
| 5503 | LIBWESTON_MODULEDIR, name); |
Derek Foreman | 3f86e50 | 2015-06-08 11:46:54 -0500 | [diff] [blame] | 5504 | } else { |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 5505 | len = snprintf(path, sizeof path, "%s", name); |
Derek Foreman | 3f86e50 | 2015-06-08 11:46:54 -0500 | [diff] [blame] | 5506 | } |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5507 | |
Daniel Stone | beb97e5 | 2016-11-28 12:13:54 +0000 | [diff] [blame] | 5508 | /* snprintf returns the length of the string it would've written, |
| 5509 | * _excluding_ the NUL byte. So even being equal to the size of |
| 5510 | * our buffer is an error here. */ |
| 5511 | if (len >= sizeof path) |
| 5512 | return NULL; |
| 5513 | |
Kristian Høgsberg | a6813d2 | 2012-09-12 12:21:01 -0400 | [diff] [blame] | 5514 | module = dlopen(path, RTLD_NOW | RTLD_NOLOAD); |
| 5515 | if (module) { |
| 5516 | weston_log("Module '%s' already loaded\n", path); |
| 5517 | dlclose(module); |
| 5518 | return NULL; |
| 5519 | } |
| 5520 | |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 5521 | weston_log("Loading module '%s'\n", path); |
Kristian Høgsberg | 1acd9f8 | 2012-07-26 11:39:26 -0400 | [diff] [blame] | 5522 | module = dlopen(path, RTLD_NOW); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5523 | if (!module) { |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 5524 | weston_log("Failed to load module: %s\n", dlerror()); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5525 | return NULL; |
| 5526 | } |
| 5527 | |
| 5528 | init = dlsym(module, entrypoint); |
| 5529 | if (!init) { |
Pekka Paalanen | 1b3c1ea | 2012-06-11 14:06:04 +0300 | [diff] [blame] | 5530 | weston_log("Failed to lookup init function: %s\n", dlerror()); |
Rob Bradford | c9e64ab | 2012-12-05 18:47:10 +0000 | [diff] [blame] | 5531 | dlclose(module); |
Kristian Høgsberg | 1c56218 | 2011-05-02 22:09:20 -0400 | [diff] [blame] | 5532 | return NULL; |
| 5533 | } |
| 5534 | |
| 5535 | return init; |
| 5536 | } |
| 5537 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 5538 | |
| 5539 | /** Destroys the compositor. |
| 5540 | * |
| 5541 | * This function cleans up the compositor state and destroys it. |
| 5542 | * |
| 5543 | * \param compositor The compositor to be destroyed. |
| 5544 | */ |
| 5545 | WL_EXPORT void |
| 5546 | weston_compositor_destroy(struct weston_compositor *compositor) |
| 5547 | { |
| 5548 | /* prevent further rendering while shutting down */ |
| 5549 | compositor->state = WESTON_COMPOSITOR_OFFSCREEN; |
| 5550 | |
| 5551 | wl_signal_emit(&compositor->destroy_signal, compositor); |
| 5552 | |
| 5553 | weston_compositor_xkb_destroy(compositor); |
| 5554 | |
Giulio Camuffo | 2d24e64 | 2015-10-03 16:25:15 +0300 | [diff] [blame] | 5555 | if (compositor->backend) |
| 5556 | compositor->backend->destroy(compositor); |
Pekka Paalanen | 827b5d2 | 2016-06-29 11:54:26 +0200 | [diff] [blame] | 5557 | |
| 5558 | weston_plugin_api_destroy_list(compositor); |
| 5559 | |
Giulio Camuffo | 459137b | 2014-10-11 23:56:24 +0300 | [diff] [blame] | 5560 | free(compositor); |
| 5561 | } |
| 5562 | |
| 5563 | /** Instruct the compositor to exit. |
| 5564 | * |
| 5565 | * This functions does not directly destroy the compositor object, it merely |
| 5566 | * command it to start the tear down process. It is not guaranteed that the |
| 5567 | * tear down will happen immediately. |
| 5568 | * |
| 5569 | * \param compositor The compositor to tear down. |
| 5570 | */ |
| 5571 | WL_EXPORT void |
| 5572 | weston_compositor_exit(struct weston_compositor *compositor) |
| 5573 | { |
| 5574 | compositor->exit(compositor); |
| 5575 | } |
| 5576 | |
| 5577 | /** Return the user data stored in the compositor. |
| 5578 | * |
| 5579 | * This function returns the user data pointer set with user_data parameter |
| 5580 | * to the \ref weston_compositor_create function. |
| 5581 | */ |
| 5582 | WL_EXPORT void * |
| 5583 | weston_compositor_get_user_data(struct weston_compositor *compositor) |
| 5584 | { |
| 5585 | return compositor->user_data; |
| 5586 | } |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 5587 | |
Pekka Paalanen | 50dbf38 | 2016-06-03 15:23:46 +0300 | [diff] [blame] | 5588 | static const char * const backend_map[] = { |
| 5589 | [WESTON_BACKEND_DRM] = "drm-backend.so", |
| 5590 | [WESTON_BACKEND_FBDEV] = "fbdev-backend.so", |
| 5591 | [WESTON_BACKEND_HEADLESS] = "headless-backend.so", |
| 5592 | [WESTON_BACKEND_RDP] = "rdp-backend.so", |
| 5593 | [WESTON_BACKEND_WAYLAND] = "wayland-backend.so", |
| 5594 | [WESTON_BACKEND_X11] = "x11-backend.so", |
| 5595 | }; |
| 5596 | |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 5597 | /** Load a backend into a weston_compositor |
| 5598 | * |
| 5599 | * A backend must be loaded to make a weston_compositor work. A backend |
| 5600 | * provides input and output capabilities, and determines the renderer to use. |
| 5601 | * |
| 5602 | * \param compositor A compositor that has not had a backend loaded yet. |
| 5603 | * \param backend Name of the backend file. |
| 5604 | * \param config_base A pointer to a backend-specific configuration |
| 5605 | * structure's 'base' member. |
| 5606 | * |
| 5607 | * \return 0 on success, or -1 on error. |
| 5608 | */ |
| 5609 | WL_EXPORT int |
| 5610 | weston_compositor_load_backend(struct weston_compositor *compositor, |
Pekka Paalanen | 50dbf38 | 2016-06-03 15:23:46 +0300 | [diff] [blame] | 5611 | enum weston_compositor_backend backend, |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 5612 | struct weston_backend_config *config_base) |
| 5613 | { |
| 5614 | int (*backend_init)(struct weston_compositor *c, |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 5615 | struct weston_backend_config *config_base); |
| 5616 | |
Quentin Glidic | 887c018 | 2016-07-10 11:00:53 +0200 | [diff] [blame] | 5617 | if (backend >= ARRAY_LENGTH(backend_map)) |
Pekka Paalanen | 50dbf38 | 2016-06-03 15:23:46 +0300 | [diff] [blame] | 5618 | return -1; |
| 5619 | |
Quentin Glidic | 23e1d6f | 2016-12-02 14:08:44 +0100 | [diff] [blame] | 5620 | backend_init = weston_load_module(backend_map[backend], "weston_backend_init"); |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 5621 | if (!backend_init) |
| 5622 | return -1; |
| 5623 | |
Pekka Paalanen | a256c5e | 2016-06-03 14:56:18 +0300 | [diff] [blame] | 5624 | return backend_init(compositor, config_base); |
Pekka Paalanen | dd18673 | 2016-06-03 14:49:54 +0300 | [diff] [blame] | 5625 | } |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 5626 | |
| 5627 | WL_EXPORT int |
| 5628 | weston_compositor_load_xwayland(struct weston_compositor *compositor) |
| 5629 | { |
Quentin Glidic | 3d7ca3b | 2016-12-02 14:20:35 +0100 | [diff] [blame] | 5630 | int (*module_init)(struct weston_compositor *ec); |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 5631 | |
Quentin Glidic | 3d7ca3b | 2016-12-02 14:20:35 +0100 | [diff] [blame] | 5632 | module_init = weston_load_module("xwayland.so", "weston_module_init"); |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 5633 | if (!module_init) |
| 5634 | return -1; |
Quentin Glidic | 3d7ca3b | 2016-12-02 14:20:35 +0100 | [diff] [blame] | 5635 | if (module_init(compositor) < 0) |
Giulio Camuffo | 9c764df | 2016-06-29 11:54:27 +0200 | [diff] [blame] | 5636 | return -1; |
| 5637 | return 0; |
| 5638 | } |