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