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